DPDK  19.02.0
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 
452 extern const char *
453 rte_cryptodev_get_feature_name(uint64_t flag);
454 
457  const char *driver_name;
458  uint8_t driver_id;
459  struct rte_device *device;
461  uint64_t feature_flags;
467  unsigned max_nb_queue_pairs;
470  uint16_t min_mbuf_headroom_req;
473  uint16_t min_mbuf_tailroom_req;
476  struct {
477  unsigned max_nb_sessions;
482  } sym;
483 };
484 
485 #define RTE_CRYPTODEV_DETACHED (0)
486 #define RTE_CRYPTODEV_ATTACHED (1)
487 
493 };
494 
497  uint32_t nb_descriptors;
502 };
503 
513 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
514  enum rte_cryptodev_event_type event, void *cb_arg);
515 
516 
519  uint64_t enqueued_count;
521  uint64_t dequeued_count;
524  uint64_t enqueue_err_count;
526  uint64_t dequeue_err_count;
528 };
529 
530 #define RTE_CRYPTODEV_NAME_MAX_LEN (64)
531 
542 extern int
543 rte_cryptodev_get_dev_id(const char *name);
544 
555 extern const char *
556 rte_cryptodev_name_get(uint8_t dev_id);
557 
565 extern uint8_t
566 rte_cryptodev_count(void);
567 
576 extern uint8_t
577 rte_cryptodev_device_count_by_driver(uint8_t driver_id);
578 
590 uint8_t
591 rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
592  uint8_t nb_devices);
593 /*
594  * Return the NUMA socket to which a device is connected
595  *
596  * @param dev_id
597  * The identifier of the device
598  * @return
599  * The NUMA socket id to which the device is connected or
600  * a default of zero if the socket could not be determined.
601  * -1 if returned is the dev_id value is out of range.
602  */
603 extern int
604 rte_cryptodev_socket_id(uint8_t dev_id);
605 
608  int socket_id;
609  uint16_t nb_queue_pairs;
611 };
612 
627 extern int
628 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
629 
645 extern int
646 rte_cryptodev_start(uint8_t dev_id);
647 
654 extern void
655 rte_cryptodev_stop(uint8_t dev_id);
656 
666 extern int
667 rte_cryptodev_close(uint8_t dev_id);
668 
690 extern int
691 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
692  const struct rte_cryptodev_qp_conf *qp_conf, int socket_id);
693 
701 extern uint16_t
702 rte_cryptodev_queue_pair_count(uint8_t dev_id);
703 
704 
716 extern int
717 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
718 
724 extern void
725 rte_cryptodev_stats_reset(uint8_t dev_id);
726 
740 extern void
741 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
742 
743 
757 extern int
758 rte_cryptodev_callback_register(uint8_t dev_id,
759  enum rte_cryptodev_event_type event,
760  rte_cryptodev_cb_fn cb_fn, void *cb_arg);
761 
775 extern int
776 rte_cryptodev_callback_unregister(uint8_t dev_id,
777  enum rte_cryptodev_event_type event,
778  rte_cryptodev_cb_fn cb_fn, void *cb_arg);
779 
780 
781 typedef uint16_t (*dequeue_pkt_burst_t)(void *qp,
782  struct rte_crypto_op **ops, uint16_t nb_ops);
785 typedef uint16_t (*enqueue_pkt_burst_t)(void *qp,
786  struct rte_crypto_op **ops, uint16_t nb_ops);
792 struct rte_cryptodev_callback;
793 
795 TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
796 
808  uint64_t feature_flags;
813  uint8_t driver_id;
816  struct rte_cryptodev_cb_list link_intr_cbs;
819  void *security_ctx;
822  __extension__
823  uint8_t attached : 1;
826 
827 void *
828 rte_cryptodev_get_sec_ctx(uint8_t dev_id);
829 
838  uint8_t dev_id;
840  uint8_t socket_id;
845  __extension__
846  uint8_t dev_started : 1;
851  void **queue_pairs;
853  uint16_t nb_queue_pairs;
856  void *dev_private;
859 
860 extern struct rte_cryptodev *rte_cryptodevs;
897 static inline uint16_t
898 rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
899  struct rte_crypto_op **ops, uint16_t nb_ops)
900 {
901  struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
902 
903  nb_ops = (*dev->dequeue_burst)
904  (dev->data->queue_pairs[qp_id], ops, nb_ops);
905 
906  return nb_ops;
907 }
908 
940 static inline uint16_t
941 rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
942  struct rte_crypto_op **ops, uint16_t nb_ops)
943 {
944  struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
945 
946  return (*dev->enqueue_burst)(
947  dev->data->queue_pairs[qp_id], ops, nb_ops);
948 }
949 
950 
956  uint64_t opaque_data;
958  uint16_t nb_drivers;
960  uint16_t user_data_sz;
962  __extension__ struct {
963  void *data;
964  uint16_t refcnt;
965  } sess_data[0];
967 };
968 
971  __extension__ void *sess_private_data[0];
973 };
974 
1001 struct rte_mempool * __rte_experimental
1002 rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
1003  uint32_t elt_size, uint32_t cache_size, uint16_t priv_size,
1004  int socket_id);
1005 
1017 
1027 struct rte_cryptodev_asym_session * __rte_experimental
1029 
1042 int
1044 
1057 int __rte_experimental
1059 
1076 int
1077 rte_cryptodev_sym_session_init(uint8_t dev_id,
1078  struct rte_cryptodev_sym_session *sess,
1079  struct rte_crypto_sym_xform *xforms,
1080  struct rte_mempool *mempool);
1081 
1097 int __rte_experimental
1098 rte_cryptodev_asym_session_init(uint8_t dev_id,
1099  struct rte_cryptodev_asym_session *sess,
1100  struct rte_crypto_asym_xform *xforms,
1101  struct rte_mempool *mempool);
1102 
1117 int
1118 rte_cryptodev_sym_session_clear(uint8_t dev_id,
1119  struct rte_cryptodev_sym_session *sess);
1120 
1131 int __rte_experimental
1132 rte_cryptodev_asym_session_clear(uint8_t dev_id,
1133  struct rte_cryptodev_asym_session *sess);
1134 
1142 unsigned int
1144 
1156 unsigned int __rte_experimental
1158  struct rte_cryptodev_sym_session *sess);
1159 
1166 unsigned int __rte_experimental
1168 
1180 unsigned int
1182 
1193 unsigned int __rte_experimental
1195 
1204 int rte_cryptodev_driver_id_get(const char *name);
1205 
1214 const char *rte_cryptodev_driver_name_get(uint8_t driver_id);
1215 
1228 int __rte_experimental
1230  struct rte_cryptodev_sym_session *sess,
1231  void *data,
1232  uint16_t size);
1233 
1244 void * __rte_experimental
1246  struct rte_cryptodev_sym_session *sess);
1247 
1248 #ifdef __cplusplus
1249 }
1250 #endif
1251 
1252 #endif /* _RTE_CRYPTODEV_H_ */