DPDK  16.11.11
rte_cryptodev.h
Go to the documentation of this file.
1 /*-
2  *
3  * Copyright(c) 2015-2016 Intel Corporation. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * * Neither the name of Intel Corporation nor the names of its
16  * contributors may be used to endorse or promote products derived
17  * from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _RTE_CRYPTODEV_H_
33 #define _RTE_CRYPTODEV_H_
34 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 #include "rte_kvargs.h"
49 #include "rte_crypto.h"
50 #include "rte_dev.h"
51 #include <rte_common.h>
52 
53 #define CRYPTODEV_NAME_NULL_PMD crypto_null
54 
55 #define CRYPTODEV_NAME_AESNI_MB_PMD crypto_aesni_mb
56 
57 #define CRYPTODEV_NAME_AESNI_GCM_PMD crypto_aesni_gcm
58 
59 #define CRYPTODEV_NAME_OPENSSL_PMD crypto_openssl
60 
61 #define CRYPTODEV_NAME_QAT_SYM_PMD crypto_qat
62 
63 #define CRYPTODEV_NAME_SNOW3G_PMD crypto_snow3g
64 
65 #define CRYPTODEV_NAME_KASUMI_PMD crypto_kasumi
66 
67 #define CRYPTODEV_NAME_ZUC_PMD crypto_zuc
68 
80 };
81 
82 extern const char **rte_cyptodev_names;
83 
84 /* Logging Macros */
85 
86 #define CDEV_LOG_ERR(...) \
87  RTE_LOG(ERR, CRYPTODEV, \
88  RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
89  __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
90 
91 #define CDEV_PMD_LOG_ERR(dev, ...) \
92  RTE_LOG(ERR, CRYPTODEV, \
93  RTE_FMT("[%s] %s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
94  dev, __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
95 
96 #ifdef RTE_LIBRTE_CRYPTODEV_DEBUG
97 #define CDEV_LOG_DEBUG(...) \
98  RTE_LOG(DEBUG, CRYPTODEV, \
99  RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
100  __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
101 
102 #define CDEV_PMD_TRACE(...) \
103  RTE_LOG(DEBUG, CRYPTODEV, \
104  RTE_FMT("[%s] %s: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
105  dev, __func__, RTE_FMT_TAIL(__VA_ARGS__,)))
106 
107 #else
108 #define CDEV_LOG_DEBUG(...) (void)0
109 #define CDEV_PMD_TRACE(...) (void)0
110 #endif
111 
119  union {
120  struct {
123  uint16_t block_size;
125  struct {
126  uint16_t min;
127  uint16_t max;
128  uint16_t increment;
133  } key_size;
135  struct {
136  uint16_t min;
137  uint16_t max;
138  uint16_t increment;
143  } digest_size;
145  struct {
146  uint16_t min;
147  uint16_t max;
148  uint16_t increment;
153  } aad_size;
155  } auth;
157  struct {
160  uint16_t block_size;
162  struct {
163  uint16_t min;
164  uint16_t max;
165  uint16_t increment;
170  } key_size;
172  struct {
173  uint16_t min;
174  uint16_t max;
175  uint16_t increment;
180  } iv_size;
182  } cipher;
184  };
185 };
186 
193  union {
196  };
197 };
198 
200 #define RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() \
201  { RTE_CRYPTO_OP_TYPE_UNDEFINED }
202 
203 
212 #define RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO (1ULL << 0)
213 
214 #define RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO (1ULL << 1)
215 
216 #define RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING (1ULL << 2)
217 
218 #define RTE_CRYPTODEV_FF_CPU_SSE (1ULL << 3)
219 
220 #define RTE_CRYPTODEV_FF_CPU_AVX (1ULL << 4)
221 
222 #define RTE_CRYPTODEV_FF_CPU_AVX2 (1ULL << 5)
223 
224 #define RTE_CRYPTODEV_FF_CPU_AESNI (1ULL << 6)
225 
226 #define RTE_CRYPTODEV_FF_HW_ACCELERATED (1ULL << 7)
227 
239 extern const char *
240 rte_cryptodev_get_feature_name(uint64_t flag);
241 
244  const char *driver_name;
248  uint64_t feature_flags;
256  struct {
257  unsigned max_nb_sessions;
259  } sym;
260 };
261 
262 #define RTE_CRYPTODEV_DETACHED (0)
263 #define RTE_CRYPTODEV_ATTACHED (1)
264 
270 };
271 
274  uint32_t nb_descriptors;
275 };
276 
286 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
287  enum rte_cryptodev_event_type event, void *cb_arg);
288 
289 
292  uint64_t enqueued_count;
294  uint64_t dequeued_count;
301 };
302 
303 #define RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_QUEUE_PAIRS 8
304 #define RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_SESSIONS 2048
305 
310 struct rte_crypto_vdev_init_params {
311  unsigned max_nb_queue_pairs;
312  unsigned max_nb_sessions;
313  uint8_t socket_id;
314 };
315 
327 int
329  struct rte_crypto_vdev_init_params *params,
330  const char *input_args);
331 
343 extern int
344 rte_cryptodev_create_vdev(const char *name, const char *args);
345 
355 extern int
356 rte_cryptodev_get_dev_id(const char *name);
357 
365 extern uint8_t
366 rte_cryptodev_count(void);
367 
368 extern uint8_t
369 rte_cryptodev_count_devtype(enum rte_cryptodev_type type);
370 /*
371  * Return the NUMA socket to which a device is connected
372  *
373  * @param dev_id
374  * The identifier of the device
375  * @return
376  * The NUMA socket id to which the device is connected or
377  * a default of zero if the socket could not be determined.
378  * -1 if returned is the dev_id value is out of range.
379  */
380 extern int
381 rte_cryptodev_socket_id(uint8_t dev_id);
382 
385  int socket_id;
386  uint16_t nb_queue_pairs;
389  struct {
390  uint32_t nb_objs;
391  uint32_t cache_size;
392  } session_mp;
393 };
394 
409 extern int
410 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
411 
427 extern int
428 rte_cryptodev_start(uint8_t dev_id);
429 
436 extern void
437 rte_cryptodev_stop(uint8_t dev_id);
438 
448 extern int
449 rte_cryptodev_close(uint8_t dev_id);
450 
474 extern int
475 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
476  const struct rte_cryptodev_qp_conf *qp_conf, int socket_id);
477 
492 extern int
493 rte_cryptodev_queue_pair_start(uint8_t dev_id, uint16_t queue_pair_id);
494 
508 extern int
509 rte_cryptodev_queue_pair_stop(uint8_t dev_id, uint16_t queue_pair_id);
510 
518 extern uint16_t
519 rte_cryptodev_queue_pair_count(uint8_t dev_id);
520 
521 
533 extern int
534 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
535 
541 extern void
542 rte_cryptodev_stats_reset(uint8_t dev_id);
543 
552 extern void
553 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
554 
555 
569 extern int
570 rte_cryptodev_callback_register(uint8_t dev_id,
571  enum rte_cryptodev_event_type event,
572  rte_cryptodev_cb_fn cb_fn, void *cb_arg);
573 
587 extern int
588 rte_cryptodev_callback_unregister(uint8_t dev_id,
589  enum rte_cryptodev_event_type event,
590  rte_cryptodev_cb_fn cb_fn, void *cb_arg);
591 
592 
593 typedef uint16_t (*dequeue_pkt_burst_t)(void *qp,
594  struct rte_crypto_op **ops, uint16_t nb_ops);
597 typedef uint16_t (*enqueue_pkt_burst_t)(void *qp,
598  struct rte_crypto_op **ops, uint16_t nb_ops);
604 struct rte_cryptodev_callback;
605 
607 TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
608 
622  uint64_t feature_flags;
630  struct rte_cryptodev_cb_list link_intr_cbs;
633  __extension__
634  uint8_t attached : 1;
637 
638 
639 #define RTE_CRYPTODEV_NAME_MAX_LEN (64)
640 
650  uint8_t dev_id;
652  uint8_t socket_id;
657  __extension__
658  uint8_t dev_started : 1;
663  void **queue_pairs;
665  uint16_t nb_queue_pairs;
668  void *dev_private;
671 
672 extern struct rte_cryptodev *rte_cryptodevs;
709 static inline uint16_t
710 rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
711  struct rte_crypto_op **ops, uint16_t nb_ops)
712 {
713  struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
714 
715  nb_ops = (*dev->dequeue_burst)
716  (dev->data->queue_pairs[qp_id], ops, nb_ops);
717 
718  return nb_ops;
719 }
720 
752 static inline uint16_t
753 rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
754  struct rte_crypto_op **ops, uint16_t nb_ops)
755 {
756  struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
757 
758  return (*dev->enqueue_burst)(
759  dev->data->queue_pairs[qp_id], ops, nb_ops);
760 }
761 
762 
766  struct {
767  uint8_t dev_id;
769  enum rte_cryptodev_type dev_type;
771  struct rte_mempool *mp;
773  } __rte_aligned(8);
776  __extension__ char _private[0];
778 };
779 
780 
802 extern struct rte_cryptodev_sym_session *
803 rte_cryptodev_sym_session_create(uint8_t dev_id,
804  struct rte_crypto_sym_xform *xform);
805 
817 extern struct rte_cryptodev_sym_session *
818 rte_cryptodev_sym_session_free(uint8_t dev_id,
819  struct rte_cryptodev_sym_session *session);
820 
821 
822 #ifdef __cplusplus
823 }
824 #endif
825 
826 #endif /* _RTE_CRYPTODEV_H_ */
struct rte_cryptodev_symmetric_capability::@26::@28::@30 key_size
void rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info)
struct rte_cryptodev_symmetric_capability sym
struct rte_pci_device * pci_dev
const char * rte_cryptodev_get_feature_name(uint64_t flag)
struct rte_cryptodev_symmetric_capability::@26::@28::@32 aad_size
struct rte_cryptodev_sym_session * rte_cryptodev_sym_session_free(uint8_t dev_id, struct rte_cryptodev_sym_session *session)
enum rte_crypto_auth_algorithm algo
int rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id, const struct rte_cryptodev_qp_conf *qp_conf, int socket_id)
int rte_cryptodev_queue_pair_start(uint8_t dev_id, uint16_t queue_pair_id)
static uint16_t rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, uint16_t nb_ops)
uint64_t feature_flags
enum rte_crypto_op_type op
struct rte_mempool * mp
TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback)
__extension__ uint8_t attached
struct rte_mempool * session_pool
uint64_t dequeue_err_count
dequeue_pkt_burst_t dequeue_burst
int rte_cryptodev_parse_vdev_init_params(struct rte_crypto_vdev_init_params *params, const char *input_args)
int rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config)
char name[RTE_CRYPTODEV_NAME_MAX_LEN]
int rte_cryptodev_callback_unregister(uint8_t dev_id, enum rte_cryptodev_event_type event, rte_cryptodev_cb_fn cb_fn, void *cb_arg)
const struct rte_cryptodev_capabilities * capabilities
void rte_cryptodev_stop(uint8_t dev_id)
const char * driver_name
int rte_cryptodev_close(uint8_t dev_id)
void(* rte_cryptodev_cb_fn)(uint8_t dev_id, enum rte_cryptodev_event_type event, void *cb_arg)
rte_cryptodev_type
Definition: rte_cryptodev.h:71
struct rte_cryptodev_symmetric_capability::@26::@29 cipher
int rte_cryptodev_callback_register(uint8_t dev_id, enum rte_cryptodev_event_type event, rte_cryptodev_cb_fn cb_fn, void *cb_arg)
struct rte_cryptodev_symmetric_capability::@26::@28::@31 digest_size
rte_crypto_op_type
Definition: rte_crypto.h:56
int rte_cryptodev_queue_pair_stop(uint8_t dev_id, uint16_t queue_pair_id)
#define RTE_CRYPTODEV_NAME_MAX_LEN
enqueue_pkt_burst_t enqueue_burst
static uint16_t rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, uint16_t nb_ops)
int rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats)
struct rte_cryptodev_data * data
struct rte_cryptodev_cb_list link_intr_cbs
struct rte_cryptodev_config::@38 session_mp
enum rte_cryptodev_type dev_type
uint8_t rte_cryptodev_count(void)
__extension__ uint8_t dev_started
struct rte_cryptodev_symmetric_capability::@26::@29::@34 iv_size
__extension__ char _private[0]
struct rte_cryptodev_ops * dev_ops
enum rte_cryptodev_type dev_type
#define RTE_STD_C11
Definition: rte_common.h:64
rte_crypto_auth_algorithm
rte_crypto_sym_xform_type
int rte_cryptodev_start(uint8_t dev_id)
uint16_t(* enqueue_pkt_burst_t)(void *qp, struct rte_crypto_op **ops, uint16_t nb_ops)
uint64_t enqueue_err_count
struct rte_cryptodev_sym_session * rte_cryptodev_sym_session_create(uint8_t dev_id, struct rte_crypto_sym_xform *xform)
uint16_t(* dequeue_pkt_burst_t)(void *qp, struct rte_crypto_op **ops, uint16_t nb_ops)
uint8_t dev_id
uint16_t rte_cryptodev_queue_pair_count(uint8_t dev_id)
#define __rte_cache_aligned
Definition: rte_memory.h:96
unsigned max_nb_sessions
rte_cryptodev_event_type
RTE_STD_C11 struct rte_cryptodev_sym_session::@39 __rte_aligned(8)
struct rte_cryptodev_symmetric_capability::@26::@28 auth
struct rte_pci_device * pci_dev
int rte_cryptodev_create_vdev(const char *name, const char *args)
const struct rte_cryptodev_driver * driver
enum rte_crypto_sym_xform_type xform_type
void rte_cryptodev_stats_reset(uint8_t dev_id)
int rte_cryptodev_get_dev_id(const char *name)
unsigned max_nb_queue_pairs
struct rte_cryptodev * rte_cryptodevs
rte_crypto_cipher_algorithm