DPDK  19.11.13
rte_cryptodev.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2017 Intel Corporation.
3  */
4 
5 #ifndef _RTE_CRYPTODEV_H_
6 #define _RTE_CRYPTODEV_H_
7 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 #include "rte_kvargs.h"
22 #include "rte_crypto.h"
23 #include "rte_dev.h"
24 #include <rte_common.h>
25 #include <rte_config.h>
26 
27 extern const char **rte_cyptodev_names;
28 
29 /* Logging Macros */
30 
31 #define CDEV_LOG_ERR(...) \
32  RTE_LOG(ERR, CRYPTODEV, \
33  RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
34  __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
35 
36 #define CDEV_LOG_INFO(...) \
37  RTE_LOG(INFO, CRYPTODEV, \
38  RTE_FMT(RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
39  RTE_FMT_TAIL(__VA_ARGS__,)))
40 
41 #define CDEV_LOG_DEBUG(...) \
42  RTE_LOG(DEBUG, CRYPTODEV, \
43  RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
44  __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
45 
46 #define CDEV_PMD_TRACE(...) \
47  RTE_LOG(DEBUG, CRYPTODEV, \
48  RTE_FMT("[%s] %s: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
49  dev, __func__, RTE_FMT_TAIL(__VA_ARGS__,)))
50 
64 #define rte_crypto_op_ctod_offset(c, t, o) \
65  ((t)((char *)(c) + (o)))
66 
78 #define rte_crypto_op_ctophys_offset(c, o) \
79  (rte_iova_t)((c)->phys_addr + (o))
80 
85  uint16_t min;
86  uint16_t max;
87  uint16_t increment;
93 };
94 
99  enum rte_crypto_sym_xform_type xform_type;
102  union {
103  struct {
106  uint16_t block_size;
108  struct rte_crypto_param_range key_size;
110  struct rte_crypto_param_range digest_size;
112  struct rte_crypto_param_range aad_size;
114  struct rte_crypto_param_range iv_size;
116  } auth;
118  struct {
121  uint16_t block_size;
123  struct rte_crypto_param_range key_size;
125  struct rte_crypto_param_range iv_size;
127  } cipher;
129  struct {
132  uint16_t block_size;
134  struct rte_crypto_param_range key_size;
136  struct rte_crypto_param_range digest_size;
138  struct rte_crypto_param_range aad_size;
140  struct rte_crypto_param_range iv_size;
142  } aead;
143  };
144 };
145 
151  enum rte_crypto_asym_xform_type xform_type;
154  uint32_t op_types;
157  __extension__
158  union {
159  struct rte_crypto_param_range modlen;
163  };
164 };
165 
172 };
173 
174 
181  union {
186  };
187 };
188 
191  enum rte_crypto_sym_xform_type type;
192  union {
193  enum rte_crypto_cipher_algorithm cipher;
194  enum rte_crypto_auth_algorithm auth;
195  enum rte_crypto_aead_algorithm aead;
196  } algo;
197 };
198 
207 };
208 
220 rte_cryptodev_sym_capability_get(uint8_t dev_id,
221  const struct rte_cryptodev_sym_capability_idx *idx);
222 
233 __rte_experimental
235 rte_cryptodev_asym_capability_get(uint8_t dev_id,
236  const struct rte_cryptodev_asym_capability_idx *idx);
237 
250 int
252  const struct rte_cryptodev_symmetric_capability *capability,
253  uint16_t key_size, uint16_t iv_size);
254 
268 int
270  const struct rte_cryptodev_symmetric_capability *capability,
271  uint16_t key_size, uint16_t digest_size, uint16_t iv_size);
272 
287 int
289  const struct rte_cryptodev_symmetric_capability *capability,
290  uint16_t key_size, uint16_t digest_size, uint16_t aad_size,
291  uint16_t iv_size);
292 
303 __rte_experimental
304 int
306  const struct rte_cryptodev_asymmetric_xform_capability *capability,
307  enum rte_crypto_asym_op_type op_type);
308 
319 __rte_experimental
320 int
322  const struct rte_cryptodev_asymmetric_xform_capability *capability,
323  uint16_t modlen);
324 
336 int
338  const char *algo_string);
339 
351 int
353  const char *algo_string);
354 
366 int
368  const char *algo_string);
369 
381 __rte_experimental
382 int
384  const char *xform_string);
385 
386 
388 #define RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() \
389  { RTE_CRYPTO_OP_TYPE_UNDEFINED }
390 
391 
400 #define RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO (1ULL << 0)
401 
402 #define RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO (1ULL << 1)
403 
404 #define RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING (1ULL << 2)
405 
406 #define RTE_CRYPTODEV_FF_CPU_SSE (1ULL << 3)
407 
408 #define RTE_CRYPTODEV_FF_CPU_AVX (1ULL << 4)
409 
410 #define RTE_CRYPTODEV_FF_CPU_AVX2 (1ULL << 5)
411 
412 #define RTE_CRYPTODEV_FF_CPU_AESNI (1ULL << 6)
413 
414 #define RTE_CRYPTODEV_FF_HW_ACCELERATED (1ULL << 7)
415 
418 #define RTE_CRYPTODEV_FF_CPU_AVX512 (1ULL << 8)
419 
420 #define RTE_CRYPTODEV_FF_IN_PLACE_SGL (1ULL << 9)
421 
424 #define RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT (1ULL << 10)
425 
428 #define RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT (1ULL << 11)
429 
433 #define RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT (1ULL << 12)
434 
437 #define RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT (1ULL << 13)
438 
439 #define RTE_CRYPTODEV_FF_CPU_NEON (1ULL << 14)
440 
441 #define RTE_CRYPTODEV_FF_CPU_ARM_CE (1ULL << 15)
442 
443 #define RTE_CRYPTODEV_FF_SECURITY (1ULL << 16)
444 
445 #define RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP (1ULL << 17)
446 
447 #define RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT (1ULL << 18)
448 
449 #define RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED (1ULL << 19)
450 
451 #define RTE_CRYPTODEV_FF_ASYM_SESSIONLESS (1ULL << 20)
452 
464 extern const char *
465 rte_cryptodev_get_feature_name(uint64_t flag);
466 
469  const char *driver_name;
470  uint8_t driver_id;
471  struct rte_device *device;
473  uint64_t feature_flags;
488  struct {
489  unsigned max_nb_sessions;
494  } sym;
495 };
496 
497 #define RTE_CRYPTODEV_DETACHED (0)
498 #define RTE_CRYPTODEV_ATTACHED (1)
499 
505 };
506 
509  uint32_t nb_descriptors;
514 };
515 
525 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
526  enum rte_cryptodev_event_type event, void *cb_arg);
527 
528 
531  uint64_t enqueued_count;
533  uint64_t dequeued_count;
540 };
541 
542 #define RTE_CRYPTODEV_NAME_MAX_LEN (64)
543 
554 extern int
555 rte_cryptodev_get_dev_id(const char *name);
556 
567 extern const char *
568 rte_cryptodev_name_get(uint8_t dev_id);
569 
577 extern uint8_t
578 rte_cryptodev_count(void);
579 
588 extern uint8_t
589 rte_cryptodev_device_count_by_driver(uint8_t driver_id);
590 
602 uint8_t
603 rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
604  uint8_t nb_devices);
605 /*
606  * Return the NUMA socket to which a device is connected
607  *
608  * @param dev_id
609  * The identifier of the device
610  * @return
611  * The NUMA socket id to which the device is connected or
612  * a default of zero if the socket could not be determined.
613  * -1 if returned is the dev_id value is out of range.
614  */
615 extern int
616 rte_cryptodev_socket_id(uint8_t dev_id);
617 
620  int socket_id;
621  uint16_t nb_queue_pairs;
623  uint64_t ff_disable;
630 };
631 
646 extern int
647 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
648 
664 extern int
665 rte_cryptodev_start(uint8_t dev_id);
666 
673 extern void
674 rte_cryptodev_stop(uint8_t dev_id);
675 
685 extern int
686 rte_cryptodev_close(uint8_t dev_id);
687 
709 extern int
710 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
711  const struct rte_cryptodev_qp_conf *qp_conf, int socket_id);
712 
720 extern uint16_t
721 rte_cryptodev_queue_pair_count(uint8_t dev_id);
722 
723 
735 extern int
736 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
737 
743 extern void
744 rte_cryptodev_stats_reset(uint8_t dev_id);
745 
759 extern void
760 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
761 
762 
776 extern int
777 rte_cryptodev_callback_register(uint8_t dev_id,
778  enum rte_cryptodev_event_type event,
779  rte_cryptodev_cb_fn cb_fn, void *cb_arg);
780 
794 extern int
795 rte_cryptodev_callback_unregister(uint8_t dev_id,
796  enum rte_cryptodev_event_type event,
797  rte_cryptodev_cb_fn cb_fn, void *cb_arg);
798 
799 
800 typedef uint16_t (*dequeue_pkt_burst_t)(void *qp,
801  struct rte_crypto_op **ops, uint16_t nb_ops);
804 typedef uint16_t (*enqueue_pkt_burst_t)(void *qp,
805  struct rte_crypto_op **ops, uint16_t nb_ops);
811 struct rte_cryptodev_callback;
812 
814 TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
815 
827  uint64_t feature_flags;
832  uint8_t driver_id;
835  struct rte_cryptodev_cb_list link_intr_cbs;
841  __extension__
842  uint8_t attached : 1;
845 
846 void *
847 rte_cryptodev_get_sec_ctx(uint8_t dev_id);
848 
857  uint8_t dev_id;
859  uint8_t socket_id;
864  __extension__
865  uint8_t dev_started : 1;
870  void **queue_pairs;
872  uint16_t nb_queue_pairs;
875  void *dev_private;
878 
879 extern struct rte_cryptodev *rte_cryptodevs;
916 static inline uint16_t
917 rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
918  struct rte_crypto_op **ops, uint16_t nb_ops)
919 {
920  struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
921 
922  nb_ops = (*dev->dequeue_burst)
923  (dev->data->queue_pairs[qp_id], ops, nb_ops);
924 
925  return nb_ops;
926 }
927 
959 static inline uint16_t
960 rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
961  struct rte_crypto_op **ops, uint16_t nb_ops)
962 {
963  struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
964 
965  return (*dev->enqueue_burst)(
966  dev->data->queue_pairs[qp_id], ops, nb_ops);
967 }
968 
969 
975  uint64_t opaque_data;
977  uint16_t nb_drivers;
979  uint16_t user_data_sz;
981  __extension__ struct {
982  void *data;
983  uint16_t refcnt;
984  } sess_data[0];
986 };
987 
990  __extension__ void *sess_private_data[0];
992 };
993 
1020 __rte_experimental
1021 struct rte_mempool *
1022 rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
1023  uint32_t elt_size, uint32_t cache_size, uint16_t priv_size,
1024  int socket_id);
1025 
1037 
1047 __rte_experimental
1050 
1063 int
1065 
1078 __rte_experimental
1079 int
1081 
1098 int
1099 rte_cryptodev_sym_session_init(uint8_t dev_id,
1100  struct rte_cryptodev_sym_session *sess,
1101  struct rte_crypto_sym_xform *xforms,
1102  struct rte_mempool *mempool);
1103 
1119 __rte_experimental
1120 int
1121 rte_cryptodev_asym_session_init(uint8_t dev_id,
1122  struct rte_cryptodev_asym_session *sess,
1123  struct rte_crypto_asym_xform *xforms,
1124  struct rte_mempool *mempool);
1125 
1140 int
1141 rte_cryptodev_sym_session_clear(uint8_t dev_id,
1142  struct rte_cryptodev_sym_session *sess);
1143 
1154 __rte_experimental
1155 int
1156 rte_cryptodev_asym_session_clear(uint8_t dev_id,
1157  struct rte_cryptodev_asym_session *sess);
1158 
1166 unsigned int
1168 
1180 __rte_experimental
1181 unsigned int
1183  struct rte_cryptodev_sym_session *sess);
1184 
1191 __rte_experimental
1192 unsigned int
1194 
1206 unsigned int
1208 
1219 __rte_experimental
1220 unsigned int
1222 
1231 int rte_cryptodev_driver_id_get(const char *name);
1232 
1241 const char *rte_cryptodev_driver_name_get(uint8_t driver_id);
1242 
1255 __rte_experimental
1256 int
1258  struct rte_cryptodev_sym_session *sess,
1259  void *data,
1260  uint16_t size);
1261 
1272 __rte_experimental
1273 void *
1275  struct rte_cryptodev_sym_session *sess);
1276 
1277 #ifdef __cplusplus
1278 }
1279 #endif
1280 
1281 #endif /* _RTE_CRYPTODEV_H_ */
int rte_cryptodev_get_cipher_algo_enum(enum rte_crypto_cipher_algorithm *algo_enum, const char *algo_string)
int rte_cryptodev_get_auth_algo_enum(enum rte_crypto_auth_algorithm *algo_enum, const char *algo_string)
struct rte_mempool * mp_session
void rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info)
__rte_experimental unsigned int rte_cryptodev_sym_get_existing_header_session_size(struct rte_cryptodev_sym_session *sess)
const char * rte_cryptodev_get_feature_name(uint64_t flag)
__rte_experimental unsigned int rte_cryptodev_asym_get_private_session_size(uint8_t dev_id)
void * security_ctx
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)
uint8_t rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices, uint8_t nb_devices)
rte_crypto_asym_xform_type
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
int rte_cryptodev_driver_id_get(const char *name)
int rte_cryptodev_sym_session_clear(uint8_t dev_id, struct rte_cryptodev_sym_session *sess)
TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback)
__extension__ uint8_t attached
__rte_experimental int rte_cryptodev_asym_get_xform_enum(enum rte_crypto_asym_xform_type *xform_enum, const char *xform_string)
int rte_cryptodev_sym_session_init(uint8_t dev_id, struct rte_cryptodev_sym_session *sess, struct rte_crypto_sym_xform *xforms, struct rte_mempool *mempool)
struct rte_mempool * session_pool
uint64_t dequeue_err_count
int rte_cryptodev_get_aead_algo_enum(enum rte_crypto_aead_algorithm *algo_enum, const char *algo_string)
uint32_t cache_size
Definition: rte_mempool.h:233
const struct rte_cryptodev_symmetric_capability * rte_cryptodev_sym_capability_get(uint8_t dev_id, const struct rte_cryptodev_sym_capability_idx *idx)
dequeue_pkt_burst_t dequeue_burst
int rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config)
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
rte_crypto_asym_op_type
void rte_cryptodev_stop(uint8_t dev_id)
const char * driver_name
int rte_cryptodev_close(uint8_t dev_id)
uint8_t driver_id
void(* rte_cryptodev_cb_fn)(uint8_t dev_id, enum rte_cryptodev_event_type event, void *cb_arg)
__rte_experimental int rte_cryptodev_sym_session_set_user_data(struct rte_cryptodev_sym_session *sess, void *data, uint16_t size)
int rte_cryptodev_sym_capability_check_aead(const struct rte_cryptodev_symmetric_capability *capability, uint16_t key_size, uint16_t digest_size, uint16_t aad_size, uint16_t iv_size)
unsigned int rte_cryptodev_sym_get_header_session_size(void)
const char * rte_cryptodev_driver_name_get(uint8_t driver_id)
int rte_cryptodev_callback_register(uint8_t dev_id, enum rte_cryptodev_event_type event, rte_cryptodev_cb_fn cb_fn, void *cb_arg)
uint16_t min_mbuf_tailroom_req
struct rte_cryptodev_sym_session * rte_cryptodev_sym_session_create(struct rte_mempool *mempool)
int rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess)
const char * rte_cryptodev_name_get(uint8_t dev_id)
__rte_experimental void * rte_cryptodev_sym_session_get_user_data(struct rte_cryptodev_sym_session *sess)
rte_crypto_op_type
Definition: rte_crypto.h:29
__rte_experimental const struct rte_cryptodev_asymmetric_xform_capability * rte_cryptodev_asym_capability_get(uint8_t dev_id, const struct rte_cryptodev_asym_capability_idx *idx)
#define RTE_CRYPTODEV_NAME_MAX_LEN
__rte_experimental int rte_cryptodev_asym_session_clear(uint8_t dev_id, struct rte_cryptodev_asym_session *sess)
__rte_experimental int rte_cryptodev_asym_session_free(struct rte_cryptodev_asym_session *sess)
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_sym_capability_check_cipher(const struct rte_cryptodev_symmetric_capability *capability, uint16_t key_size, uint16_t iv_size)
__rte_experimental int rte_cryptodev_asym_session_init(uint8_t dev_id, struct rte_cryptodev_asym_session *sess, struct rte_crypto_asym_xform *xforms, struct rte_mempool *mempool)
int rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats)
struct rte_cryptodev_data * data
struct rte_device * device
__rte_experimental struct rte_cryptodev_asym_session * rte_cryptodev_asym_session_create(struct rte_mempool *mempool)
uint32_t elt_size
Definition: rte_mempool.h:236
uint8_t rte_cryptodev_count(void)
__extension__ uint8_t dev_started
int rte_cryptodev_sym_capability_check_auth(const struct rte_cryptodev_symmetric_capability *capability, uint16_t key_size, uint16_t digest_size, uint16_t iv_size)
struct rte_cryptodev_ops * dev_ops
uint16_t min_mbuf_headroom_req
__rte_experimental unsigned int rte_cryptodev_asym_get_header_session_size(void)
unsigned int rte_cryptodev_sym_get_private_session_size(uint8_t dev_id)
__rte_experimental struct rte_mempool * rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts, uint32_t elt_size, uint32_t cache_size, uint16_t priv_size, int socket_id)
#define RTE_STD_C11
Definition: rte_common.h:40
rte_crypto_auth_algorithm
__rte_experimental int rte_cryptodev_asym_xform_capability_check_modlen(const struct rte_cryptodev_asymmetric_xform_capability *capability, uint16_t modlen)
rte_crypto_sym_xform_type
struct rte_mempool * mp_session_private
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
#define __rte_cache_aligned
Definition: rte_common.h:322
uint16_t(* dequeue_pkt_burst_t)(void *qp, struct rte_crypto_op **ops, uint16_t nb_ops)
struct rte_crypto_param_range modlen
uint16_t rte_cryptodev_queue_pair_count(uint8_t dev_id)
__rte_experimental int rte_cryptodev_asym_xform_capability_check_optype(const struct rte_cryptodev_asymmetric_xform_capability *capability, enum rte_crypto_asym_op_type op_type)
struct rte_device * device
unsigned max_nb_sessions
rte_cryptodev_event_type
void rte_cryptodev_stats_reset(uint8_t dev_id)
int rte_cryptodev_get_dev_id(const char *name)
unsigned max_nb_queue_pairs
uint8_t rte_cryptodev_device_count_by_driver(uint8_t driver_id)
char name[RTE_MEMZONE_NAMESIZE]
Definition: rte_mempool.h:222
struct rte_cryptodev * rte_cryptodevs
rte_crypto_aead_algorithm
rte_crypto_cipher_algorithm