DPDK  19.08.2
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 
102  union {
103  struct {
106  uint16_t block_size;
116  } auth;
118  struct {
121  uint16_t block_size;
127  } cipher;
129  struct {
132  uint16_t block_size;
142  } aead;
143  };
144 };
145 
154  uint32_t op_types;
157  __extension__
158  union {
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 
462 extern const char *
463 rte_cryptodev_get_feature_name(uint64_t flag);
464 
467  const char *driver_name;
468  uint8_t driver_id;
469  struct rte_device *device;
471  uint64_t feature_flags;
486  struct {
487  unsigned max_nb_sessions;
492  } sym;
493 };
494 
495 #define RTE_CRYPTODEV_DETACHED (0)
496 #define RTE_CRYPTODEV_ATTACHED (1)
497 
503 };
504 
507  uint32_t nb_descriptors;
512 };
513 
523 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
524  enum rte_cryptodev_event_type event, void *cb_arg);
525 
526 
529  uint64_t enqueued_count;
531  uint64_t dequeued_count;
538 };
539 
540 #define RTE_CRYPTODEV_NAME_MAX_LEN (64)
541 
552 extern int
553 rte_cryptodev_get_dev_id(const char *name);
554 
565 extern const char *
566 rte_cryptodev_name_get(uint8_t dev_id);
567 
575 extern uint8_t
576 rte_cryptodev_count(void);
577 
586 extern uint8_t
587 rte_cryptodev_device_count_by_driver(uint8_t driver_id);
588 
600 uint8_t
601 rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
602  uint8_t nb_devices);
603 /*
604  * Return the NUMA socket to which a device is connected
605  *
606  * @param dev_id
607  * The identifier of the device
608  * @return
609  * The NUMA socket id to which the device is connected or
610  * a default of zero if the socket could not be determined.
611  * -1 if returned is the dev_id value is out of range.
612  */
613 extern int
614 rte_cryptodev_socket_id(uint8_t dev_id);
615 
618  int socket_id;
619  uint16_t nb_queue_pairs;
621  uint64_t ff_disable;
628 };
629 
644 extern int
645 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
646 
662 extern int
663 rte_cryptodev_start(uint8_t dev_id);
664 
671 extern void
672 rte_cryptodev_stop(uint8_t dev_id);
673 
683 extern int
684 rte_cryptodev_close(uint8_t dev_id);
685 
707 extern int
708 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
709  const struct rte_cryptodev_qp_conf *qp_conf, int socket_id);
710 
718 extern uint16_t
719 rte_cryptodev_queue_pair_count(uint8_t dev_id);
720 
721 
733 extern int
734 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
735 
741 extern void
742 rte_cryptodev_stats_reset(uint8_t dev_id);
743 
757 extern void
758 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
759 
760 
774 extern int
775 rte_cryptodev_callback_register(uint8_t dev_id,
776  enum rte_cryptodev_event_type event,
777  rte_cryptodev_cb_fn cb_fn, void *cb_arg);
778 
792 extern int
793 rte_cryptodev_callback_unregister(uint8_t dev_id,
794  enum rte_cryptodev_event_type event,
795  rte_cryptodev_cb_fn cb_fn, void *cb_arg);
796 
797 
798 typedef uint16_t (*dequeue_pkt_burst_t)(void *qp,
799  struct rte_crypto_op **ops, uint16_t nb_ops);
802 typedef uint16_t (*enqueue_pkt_burst_t)(void *qp,
803  struct rte_crypto_op **ops, uint16_t nb_ops);
809 struct rte_cryptodev_callback;
810 
812 TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
813 
825  uint64_t feature_flags;
830  uint8_t driver_id;
833  struct rte_cryptodev_cb_list link_intr_cbs;
839  __extension__
840  uint8_t attached : 1;
843 
844 void *
845 rte_cryptodev_get_sec_ctx(uint8_t dev_id);
846 
855  uint8_t dev_id;
857  uint8_t socket_id;
862  __extension__
863  uint8_t dev_started : 1;
868  void **queue_pairs;
870  uint16_t nb_queue_pairs;
873  void *dev_private;
876 
877 extern struct rte_cryptodev *rte_cryptodevs;
914 static inline uint16_t
915 rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
916  struct rte_crypto_op **ops, uint16_t nb_ops)
917 {
918  struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
919 
920  nb_ops = (*dev->dequeue_burst)
921  (dev->data->queue_pairs[qp_id], ops, nb_ops);
922 
923  return nb_ops;
924 }
925 
957 static inline uint16_t
958 rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
959  struct rte_crypto_op **ops, uint16_t nb_ops)
960 {
961  struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
962 
963  return (*dev->enqueue_burst)(
964  dev->data->queue_pairs[qp_id], ops, nb_ops);
965 }
966 
967 
973  uint64_t opaque_data;
975  uint16_t nb_drivers;
977  uint16_t user_data_sz;
979  __extension__ struct {
980  void *data;
981  uint16_t refcnt;
982  } sess_data[0];
984 };
985 
988  __extension__ void *sess_private_data[0];
990 };
991 
1018 __rte_experimental
1019 struct rte_mempool *
1020 rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
1021  uint32_t elt_size, uint32_t cache_size, uint16_t priv_size,
1022  int socket_id);
1023 
1035 
1045 __rte_experimental
1048 
1061 int
1063 
1076 __rte_experimental
1077 int
1079 
1096 int
1097 rte_cryptodev_sym_session_init(uint8_t dev_id,
1098  struct rte_cryptodev_sym_session *sess,
1099  struct rte_crypto_sym_xform *xforms,
1100  struct rte_mempool *mempool);
1101 
1117 __rte_experimental
1118 int
1119 rte_cryptodev_asym_session_init(uint8_t dev_id,
1120  struct rte_cryptodev_asym_session *sess,
1121  struct rte_crypto_asym_xform *xforms,
1122  struct rte_mempool *mempool);
1123 
1138 int
1139 rte_cryptodev_sym_session_clear(uint8_t dev_id,
1140  struct rte_cryptodev_sym_session *sess);
1141 
1152 __rte_experimental
1153 int
1154 rte_cryptodev_asym_session_clear(uint8_t dev_id,
1155  struct rte_cryptodev_asym_session *sess);
1156 
1164 unsigned int
1166 
1178 __rte_experimental
1179 unsigned int
1181  struct rte_cryptodev_sym_session *sess);
1182 
1189 __rte_experimental
1190 unsigned int
1192 
1204 unsigned int
1206 
1217 __rte_experimental
1218 unsigned int
1220 
1229 int rte_cryptodev_driver_id_get(const char *name);
1230 
1239 const char *rte_cryptodev_driver_name_get(uint8_t driver_id);
1240 
1253 __rte_experimental
1254 int
1256  struct rte_cryptodev_sym_session *sess,
1257  void *data,
1258  uint16_t size);
1259 
1270 __rte_experimental
1271 void *
1273  struct rte_cryptodev_sym_session *sess);
1274 
1275 #ifdef __cplusplus
1276 }
1277 #endif
1278 
1279 #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)
struct rte_cryptodev_symmetric_capability sym
__rte_experimental unsigned int rte_cryptodev_sym_get_existing_header_session_size(struct rte_cryptodev_sym_session *sess)
struct rte_cryptodev_symmetric_capability::@109::@111 auth
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)
enum rte_crypto_auth_algorithm algo
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
enum rte_crypto_asym_xform_type 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)
struct rte_crypto_param_range digest_size
uint64_t feature_flags
enum rte_crypto_op_type op
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:230
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)
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
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)
enum rte_crypto_asym_xform_type type
uint8_t driver_id
__extension__ void * sess_private_data[0]
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_cryptodev_symmetric_capability::@109::@112 cipher
struct rte_cryptodev_cb_list link_intr_cbs
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:233
__extension__ struct rte_cryptodev_sym_session::@120 sess_data[0]
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_cache_aligned
Definition: rte_memory.h:64
#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
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)
struct rte_crypto_param_range key_size
__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
struct rte_crypto_param_range aad_size
enum rte_crypto_sym_xform_type xform_type
Definition: rte_cryptodev.h:99
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:219
struct rte_crypto_param_range iv_size
struct rte_cryptodev * rte_cryptodevs
struct rte_cryptodev_asymmetric_capability asym
rte_crypto_aead_algorithm
rte_crypto_cipher_algorithm