DPDK  19.08.0-rc0
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 const struct rte_cryptodev_asymmetric_xform_capability * __rte_experimental
234 rte_cryptodev_asym_capability_get(uint8_t dev_id,
235  const struct rte_cryptodev_asym_capability_idx *idx);
236 
249 int
251  const struct rte_cryptodev_symmetric_capability *capability,
252  uint16_t key_size, uint16_t iv_size);
253 
267 int
269  const struct rte_cryptodev_symmetric_capability *capability,
270  uint16_t key_size, uint16_t digest_size, uint16_t iv_size);
271 
286 int
288  const struct rte_cryptodev_symmetric_capability *capability,
289  uint16_t key_size, uint16_t digest_size, uint16_t aad_size,
290  uint16_t iv_size);
291 
302 int __rte_experimental
304  const struct rte_cryptodev_asymmetric_xform_capability *capability,
305  enum rte_crypto_asym_op_type op_type);
306 
317 int __rte_experimental
319  const struct rte_cryptodev_asymmetric_xform_capability *capability,
320  uint16_t modlen);
321 
333 int
335  const char *algo_string);
336 
348 int
350  const char *algo_string);
351 
363 int
365  const char *algo_string);
366 
378 int __rte_experimental
380  const char *xform_string);
381 
382 
384 #define RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() \
385  { RTE_CRYPTO_OP_TYPE_UNDEFINED }
386 
387 
396 #define RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO (1ULL << 0)
397 
398 #define RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO (1ULL << 1)
399 
400 #define RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING (1ULL << 2)
401 
402 #define RTE_CRYPTODEV_FF_CPU_SSE (1ULL << 3)
403 
404 #define RTE_CRYPTODEV_FF_CPU_AVX (1ULL << 4)
405 
406 #define RTE_CRYPTODEV_FF_CPU_AVX2 (1ULL << 5)
407 
408 #define RTE_CRYPTODEV_FF_CPU_AESNI (1ULL << 6)
409 
410 #define RTE_CRYPTODEV_FF_HW_ACCELERATED (1ULL << 7)
411 
414 #define RTE_CRYPTODEV_FF_CPU_AVX512 (1ULL << 8)
415 
416 #define RTE_CRYPTODEV_FF_IN_PLACE_SGL (1ULL << 9)
417 
420 #define RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT (1ULL << 10)
421 
424 #define RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT (1ULL << 11)
425 
429 #define RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT (1ULL << 12)
430 
433 #define RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT (1ULL << 13)
434 
435 #define RTE_CRYPTODEV_FF_CPU_NEON (1ULL << 14)
436 
437 #define RTE_CRYPTODEV_FF_CPU_ARM_CE (1ULL << 15)
438 
439 #define RTE_CRYPTODEV_FF_SECURITY (1ULL << 16)
440 
441 #define RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP (1ULL << 17)
442 
443 #define RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT (1ULL << 18)
444 
456 extern const char *
457 rte_cryptodev_get_feature_name(uint64_t flag);
458 
461  const char *driver_name;
462  uint8_t driver_id;
463  struct rte_device *device;
465  uint64_t feature_flags;
480  struct {
481  unsigned max_nb_sessions;
486  } sym;
487 };
488 
489 #define RTE_CRYPTODEV_DETACHED (0)
490 #define RTE_CRYPTODEV_ATTACHED (1)
491 
497 };
498 
501  uint32_t nb_descriptors;
506 };
507 
517 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
518  enum rte_cryptodev_event_type event, void *cb_arg);
519 
520 
523  uint64_t enqueued_count;
525  uint64_t dequeued_count;
532 };
533 
534 #define RTE_CRYPTODEV_NAME_MAX_LEN (64)
535 
546 extern int
547 rte_cryptodev_get_dev_id(const char *name);
548 
559 extern const char *
560 rte_cryptodev_name_get(uint8_t dev_id);
561 
569 extern uint8_t
570 rte_cryptodev_count(void);
571 
580 extern uint8_t
581 rte_cryptodev_device_count_by_driver(uint8_t driver_id);
582 
594 uint8_t
595 rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
596  uint8_t nb_devices);
597 /*
598  * Return the NUMA socket to which a device is connected
599  *
600  * @param dev_id
601  * The identifier of the device
602  * @return
603  * The NUMA socket id to which the device is connected or
604  * a default of zero if the socket could not be determined.
605  * -1 if returned is the dev_id value is out of range.
606  */
607 extern int
608 rte_cryptodev_socket_id(uint8_t dev_id);
609 
612  int socket_id;
613  uint16_t nb_queue_pairs;
615 };
616 
631 extern int
632 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
633 
649 extern int
650 rte_cryptodev_start(uint8_t dev_id);
651 
658 extern void
659 rte_cryptodev_stop(uint8_t dev_id);
660 
670 extern int
671 rte_cryptodev_close(uint8_t dev_id);
672 
694 extern int
695 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
696  const struct rte_cryptodev_qp_conf *qp_conf, int socket_id);
697 
705 extern uint16_t
706 rte_cryptodev_queue_pair_count(uint8_t dev_id);
707 
708 
720 extern int
721 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
722 
728 extern void
729 rte_cryptodev_stats_reset(uint8_t dev_id);
730 
744 extern void
745 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
746 
747 
761 extern int
762 rte_cryptodev_callback_register(uint8_t dev_id,
763  enum rte_cryptodev_event_type event,
764  rte_cryptodev_cb_fn cb_fn, void *cb_arg);
765 
779 extern int
780 rte_cryptodev_callback_unregister(uint8_t dev_id,
781  enum rte_cryptodev_event_type event,
782  rte_cryptodev_cb_fn cb_fn, void *cb_arg);
783 
784 
785 typedef uint16_t (*dequeue_pkt_burst_t)(void *qp,
786  struct rte_crypto_op **ops, uint16_t nb_ops);
789 typedef uint16_t (*enqueue_pkt_burst_t)(void *qp,
790  struct rte_crypto_op **ops, uint16_t nb_ops);
796 struct rte_cryptodev_callback;
797 
799 TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
800 
812  uint64_t feature_flags;
817  uint8_t driver_id;
820  struct rte_cryptodev_cb_list link_intr_cbs;
826  __extension__
827  uint8_t attached : 1;
830 
831 void *
832 rte_cryptodev_get_sec_ctx(uint8_t dev_id);
833 
842  uint8_t dev_id;
844  uint8_t socket_id;
849  __extension__
850  uint8_t dev_started : 1;
855  void **queue_pairs;
857  uint16_t nb_queue_pairs;
860  void *dev_private;
863 
864 extern struct rte_cryptodev *rte_cryptodevs;
901 static inline uint16_t
902 rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
903  struct rte_crypto_op **ops, uint16_t nb_ops)
904 {
905  struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
906 
907  nb_ops = (*dev->dequeue_burst)
908  (dev->data->queue_pairs[qp_id], ops, nb_ops);
909 
910  return nb_ops;
911 }
912 
944 static inline uint16_t
945 rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
946  struct rte_crypto_op **ops, uint16_t nb_ops)
947 {
948  struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
949 
950  return (*dev->enqueue_burst)(
951  dev->data->queue_pairs[qp_id], ops, nb_ops);
952 }
953 
954 
960  uint64_t opaque_data;
962  uint16_t nb_drivers;
964  uint16_t user_data_sz;
966  __extension__ struct {
967  void *data;
968  uint16_t refcnt;
969  } sess_data[0];
971 };
972 
975  __extension__ void *sess_private_data[0];
977 };
978 
1005 struct rte_mempool * __rte_experimental
1006 rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
1007  uint32_t elt_size, uint32_t cache_size, uint16_t priv_size,
1008  int socket_id);
1009 
1021 
1031 struct rte_cryptodev_asym_session * __rte_experimental
1033 
1046 int
1048 
1061 int __rte_experimental
1063 
1080 int
1081 rte_cryptodev_sym_session_init(uint8_t dev_id,
1082  struct rte_cryptodev_sym_session *sess,
1083  struct rte_crypto_sym_xform *xforms,
1084  struct rte_mempool *mempool);
1085 
1101 int __rte_experimental
1102 rte_cryptodev_asym_session_init(uint8_t dev_id,
1103  struct rte_cryptodev_asym_session *sess,
1104  struct rte_crypto_asym_xform *xforms,
1105  struct rte_mempool *mempool);
1106 
1121 int
1122 rte_cryptodev_sym_session_clear(uint8_t dev_id,
1123  struct rte_cryptodev_sym_session *sess);
1124 
1135 int __rte_experimental
1136 rte_cryptodev_asym_session_clear(uint8_t dev_id,
1137  struct rte_cryptodev_asym_session *sess);
1138 
1146 unsigned int
1148 
1160 unsigned int __rte_experimental
1162  struct rte_cryptodev_sym_session *sess);
1163 
1170 unsigned int __rte_experimental
1172 
1184 unsigned int
1186 
1197 unsigned int __rte_experimental
1199 
1208 int rte_cryptodev_driver_id_get(const char *name);
1209 
1218 const char *rte_cryptodev_driver_name_get(uint8_t driver_id);
1219 
1232 int __rte_experimental
1234  struct rte_cryptodev_sym_session *sess,
1235  void *data,
1236  uint16_t size);
1237 
1248 void * __rte_experimental
1250  struct rte_cryptodev_sym_session *sess);
1251 
1252 #ifdef __cplusplus
1253 }
1254 #endif
1255 
1256 #endif /* _RTE_CRYPTODEV_H_ */
int __rte_experimental rte_cryptodev_asym_get_xform_enum(enum rte_crypto_asym_xform_type *xform_enum, const char *xform_string)
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
const char * rte_cryptodev_get_feature_name(uint64_t flag)
const struct rte_cryptodev_asymmetric_xform_capability *__rte_experimental rte_cryptodev_asym_capability_get(uint8_t dev_id, const struct rte_cryptodev_asym_capability_idx *idx)
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)
struct rte_cryptodev_symmetric_capability::@101::@103 auth
unsigned int __rte_experimental rte_cryptodev_sym_get_existing_header_session_size(struct rte_cryptodev_sym_session *sess)
TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback)
__extension__ uint8_t attached
int __rte_experimental rte_cryptodev_asym_xform_capability_check_modlen(const struct rte_cryptodev_asymmetric_xform_capability *capability, uint16_t modlen)
__extension__ struct rte_cryptodev_sym_session::@112 sess_data[0]
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)
struct rte_mempool *__rte_experimental 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)
enum rte_crypto_asym_xform_type type
uint8_t driver_id
__extension__ void * sess_private_data[0]
int __rte_experimental rte_cryptodev_sym_session_set_user_data(struct rte_cryptodev_sym_session *sess, void *data, uint16_t size)
void(* rte_cryptodev_cb_fn)(uint8_t dev_id, enum rte_cryptodev_event_type event, void *cb_arg)
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_experimental rte_cryptodev_asym_get_header_session_size(void)
void *__rte_experimental rte_cryptodev_sym_session_get_user_data(struct rte_cryptodev_sym_session *sess)
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
int __rte_experimental 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)
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_crypto_op_type
Definition: rte_crypto.h:29
#define RTE_CRYPTODEV_NAME_MAX_LEN
int __rte_experimental rte_cryptodev_asym_session_clear(uint8_t dev_id, 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)
int rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats)
struct rte_cryptodev_data * data
struct rte_cryptodev_asym_session *__rte_experimental rte_cryptodev_asym_session_create(struct rte_mempool *mempool)
struct rte_cryptodev_cb_list link_intr_cbs
struct rte_device * device
uint32_t elt_size
Definition: rte_mempool.h:233
uint8_t rte_cryptodev_count(void)
struct rte_cryptodev_symmetric_capability::@101::@104 cipher
__extension__ uint8_t dev_started
unsigned int __rte_experimental rte_cryptodev_asym_get_private_session_size(uint8_t dev_id)
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
unsigned int rte_cryptodev_sym_get_private_session_size(uint8_t dev_id)
#define __rte_cache_aligned
Definition: rte_memory.h:66
#define RTE_STD_C11
Definition: rte_common.h:40
rte_crypto_auth_algorithm
rte_crypto_sym_xform_type
struct rte_mempool * mp_session_private
int __rte_experimental rte_cryptodev_asym_session_free(struct rte_cryptodev_asym_session *sess)
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
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
int __rte_experimental rte_cryptodev_asym_xform_capability_check_optype(const struct rte_cryptodev_asymmetric_xform_capability *capability, enum rte_crypto_asym_op_type op_type)
rte_crypto_cipher_algorithm