DPDK  18.08.1
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;
498 };
499 
509 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
510  enum rte_cryptodev_event_type event, void *cb_arg);
511 
512 
515  uint64_t enqueued_count;
517  uint64_t dequeued_count;
520  uint64_t enqueue_err_count;
522  uint64_t dequeue_err_count;
524 };
525 
526 #define RTE_CRYPTODEV_NAME_MAX_LEN (64)
527 
538 extern int
539 rte_cryptodev_get_dev_id(const char *name);
540 
551 extern const char *
552 rte_cryptodev_name_get(uint8_t dev_id);
553 
561 extern uint8_t
562 rte_cryptodev_count(void);
563 
572 extern uint8_t
573 rte_cryptodev_device_count_by_driver(uint8_t driver_id);
574 
586 uint8_t
587 rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
588  uint8_t nb_devices);
589 /*
590  * Return the NUMA socket to which a device is connected
591  *
592  * @param dev_id
593  * The identifier of the device
594  * @return
595  * The NUMA socket id to which the device is connected or
596  * a default of zero if the socket could not be determined.
597  * -1 if returned is the dev_id value is out of range.
598  */
599 extern int
600 rte_cryptodev_socket_id(uint8_t dev_id);
601 
604  int socket_id;
605  uint16_t nb_queue_pairs;
607 };
608 
623 extern int
624 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
625 
641 extern int
642 rte_cryptodev_start(uint8_t dev_id);
643 
650 extern void
651 rte_cryptodev_stop(uint8_t dev_id);
652 
662 extern int
663 rte_cryptodev_close(uint8_t dev_id);
664 
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  struct rte_mempool *session_pool);
694 
702 extern uint16_t
703 rte_cryptodev_queue_pair_count(uint8_t dev_id);
704 
705 
717 extern int
718 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
719 
725 extern void
726 rte_cryptodev_stats_reset(uint8_t dev_id);
727 
741 extern void
742 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
743 
744 
758 extern int
759 rte_cryptodev_callback_register(uint8_t dev_id,
760  enum rte_cryptodev_event_type event,
761  rte_cryptodev_cb_fn cb_fn, void *cb_arg);
762 
776 extern int
777 rte_cryptodev_callback_unregister(uint8_t dev_id,
778  enum rte_cryptodev_event_type event,
779  rte_cryptodev_cb_fn cb_fn, void *cb_arg);
780 
781 
782 typedef uint16_t (*dequeue_pkt_burst_t)(void *qp,
783  struct rte_crypto_op **ops, uint16_t nb_ops);
786 typedef uint16_t (*enqueue_pkt_burst_t)(void *qp,
787  struct rte_crypto_op **ops, uint16_t nb_ops);
793 struct rte_cryptodev_callback;
794 
796 TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
797 
809  uint64_t feature_flags;
814  uint8_t driver_id;
817  struct rte_cryptodev_cb_list link_intr_cbs;
820  void *security_ctx;
823  __extension__
824  uint8_t attached : 1;
827 
828 void *
829 rte_cryptodev_get_sec_ctx(uint8_t dev_id);
830 
839  uint8_t dev_id;
841  uint8_t socket_id;
846  __extension__
847  uint8_t dev_started : 1;
852  void **queue_pairs;
854  uint16_t nb_queue_pairs;
857  void *dev_private;
860 
861 extern struct rte_cryptodev *rte_cryptodevs;
898 static inline uint16_t
899 rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
900  struct rte_crypto_op **ops, uint16_t nb_ops)
901 {
902  struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
903 
904  nb_ops = (*dev->dequeue_burst)
905  (dev->data->queue_pairs[qp_id], ops, nb_ops);
906 
907  return nb_ops;
908 }
909 
941 static inline uint16_t
942 rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
943  struct rte_crypto_op **ops, uint16_t nb_ops)
944 {
945  struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
946 
947  return (*dev->enqueue_burst)(
948  dev->data->queue_pairs[qp_id], ops, nb_ops);
949 }
950 
951 
957  __extension__ void *sess_private_data[0];
959 };
960 
963  __extension__ void *sess_private_data[0];
965 };
966 
978 
988 struct rte_cryptodev_asym_session * __rte_experimental
990 
1003 int
1005 
1018 int __rte_experimental
1020 
1037 int
1038 rte_cryptodev_sym_session_init(uint8_t dev_id,
1039  struct rte_cryptodev_sym_session *sess,
1040  struct rte_crypto_sym_xform *xforms,
1041  struct rte_mempool *mempool);
1042 
1058 int __rte_experimental
1059 rte_cryptodev_asym_session_init(uint8_t dev_id,
1060  struct rte_cryptodev_asym_session *sess,
1061  struct rte_crypto_asym_xform *xforms,
1062  struct rte_mempool *mempool);
1063 
1078 int
1079 rte_cryptodev_sym_session_clear(uint8_t dev_id,
1080  struct rte_cryptodev_sym_session *sess);
1081 
1092 int __rte_experimental
1093 rte_cryptodev_asym_session_clear(uint8_t dev_id,
1094  struct rte_cryptodev_asym_session *sess);
1095 
1102 unsigned int
1104 
1111 unsigned int __rte_experimental
1113 
1125 unsigned int
1127 
1138 unsigned int __rte_experimental
1140 
1149 int rte_cryptodev_driver_id_get(const char *name);
1150 
1159 const char *rte_cryptodev_driver_name_get(uint8_t driver_id);
1160 
1173 int __rte_experimental
1175  struct rte_cryptodev_sym_session *sess,
1176  void *data,
1177  uint16_t size);
1178 
1189 void * __rte_experimental
1191  struct rte_cryptodev_sym_session *sess);
1192 
1193 #ifdef __cplusplus
1194 }
1195 #endif
1196 
1197 #endif /* _RTE_CRYPTODEV_H_ */