DPDK  18.05.1
rte_cryptodev.h
Go to the documentation of this file.
1 /*-
2  *
3  * Copyright(c) 2015-2017 Intel Corporation. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * * Neither the name of Intel Corporation nor the names of its
16  * contributors may be used to endorse or promote products derived
17  * from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _RTE_CRYPTODEV_H_
33 #define _RTE_CRYPTODEV_H_
34 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 #include "rte_kvargs.h"
49 #include "rte_crypto.h"
50 #include "rte_dev.h"
51 #include <rte_common.h>
52 #include <rte_config.h>
53 
54 extern const char **rte_cyptodev_names;
55 
56 /* Logging Macros */
57 
58 #define CDEV_LOG_ERR(...) \
59  RTE_LOG(ERR, CRYPTODEV, \
60  RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
61  __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
62 
63 #define CDEV_LOG_INFO(...) \
64  RTE_LOG(INFO, CRYPTODEV, \
65  RTE_FMT(RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
66  RTE_FMT_TAIL(__VA_ARGS__,)))
67 
68 #ifdef RTE_LIBRTE_CRYPTODEV_DEBUG
69 #define CDEV_LOG_DEBUG(...) \
70  RTE_LOG(DEBUG, CRYPTODEV, \
71  RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
72  __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
73 
74 #define CDEV_PMD_TRACE(...) \
75  RTE_LOG(DEBUG, CRYPTODEV, \
76  RTE_FMT("[%s] %s: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
77  dev, __func__, RTE_FMT_TAIL(__VA_ARGS__,)))
78 
79 #else
80 #define CDEV_LOG_DEBUG(...) (void)0
81 #define CDEV_PMD_TRACE(...) (void)0
82 #endif
83 
84 
85 
99 #define rte_crypto_op_ctod_offset(c, t, o) \
100  ((t)((char *)(c) + (o)))
101 
113 #define rte_crypto_op_ctophys_offset(c, o) \
114  (rte_iova_t)((c)->phys_addr + (o))
115 
120  uint16_t min;
121  uint16_t max;
122  uint16_t increment;
128 };
129 
137  union {
138  struct {
141  uint16_t block_size;
151  } auth;
153  struct {
156  uint16_t block_size;
162  } cipher;
164  struct {
167  uint16_t block_size;
177  } aead;
178  };
179 };
180 
187  union {
190  };
191 };
192 
195  enum rte_crypto_sym_xform_type type;
196  union {
197  enum rte_crypto_cipher_algorithm cipher;
198  enum rte_crypto_auth_algorithm auth;
199  enum rte_crypto_aead_algorithm aead;
200  } algo;
201 };
202 
214 rte_cryptodev_sym_capability_get(uint8_t dev_id,
215  const struct rte_cryptodev_sym_capability_idx *idx);
216 
229 int
231  const struct rte_cryptodev_symmetric_capability *capability,
232  uint16_t key_size, uint16_t iv_size);
233 
247 int
249  const struct rte_cryptodev_symmetric_capability *capability,
250  uint16_t key_size, uint16_t digest_size, uint16_t iv_size);
251 
266 int
268  const struct rte_cryptodev_symmetric_capability *capability,
269  uint16_t key_size, uint16_t digest_size, uint16_t aad_size,
270  uint16_t iv_size);
271 
283 int
285  const char *algo_string);
286 
298 int
300  const char *algo_string);
301 
313 int
315  const char *algo_string);
316 
318 #define RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() \
319  { RTE_CRYPTO_OP_TYPE_UNDEFINED }
320 
321 
330 #define RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO (1ULL << 0)
331 
332 #define RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO (1ULL << 1)
333 
334 #define RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING (1ULL << 2)
335 
336 #define RTE_CRYPTODEV_FF_CPU_SSE (1ULL << 3)
337 
338 #define RTE_CRYPTODEV_FF_CPU_AVX (1ULL << 4)
339 
340 #define RTE_CRYPTODEV_FF_CPU_AVX2 (1ULL << 5)
341 
342 #define RTE_CRYPTODEV_FF_CPU_AESNI (1ULL << 6)
343 
344 #define RTE_CRYPTODEV_FF_HW_ACCELERATED (1ULL << 7)
345 
346 #define RTE_CRYPTODEV_FF_CPU_AVX512 (1ULL << 8)
347 
348 #define RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER (1ULL << 9)
349 
350 #define RTE_CRYPTODEV_FF_CPU_NEON (1ULL << 10)
351 
352 #define RTE_CRYPTODEV_FF_CPU_ARM_CE (1ULL << 11)
353 
354 #define RTE_CRYPTODEV_FF_SECURITY (1ULL << 12)
355 
367 extern const char *
368 rte_cryptodev_get_feature_name(uint64_t flag);
369 
372  const char *driver_name;
373  uint8_t driver_id;
374  struct rte_pci_device *pci_dev;
376  uint64_t feature_flags;
382  unsigned max_nb_queue_pairs;
385  struct {
386  unsigned max_nb_sessions;
388  unsigned int max_nb_sessions_per_qp;
392  } sym;
393 };
394 
395 #define RTE_CRYPTODEV_DETACHED (0)
396 #define RTE_CRYPTODEV_ATTACHED (1)
397 
403 };
404 
407  uint32_t nb_descriptors;
408 };
409 
419 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
420  enum rte_cryptodev_event_type event, void *cb_arg);
421 
422 
425  uint64_t enqueued_count;
427  uint64_t dequeued_count;
430  uint64_t enqueue_err_count;
432  uint64_t dequeue_err_count;
434 };
435 
436 #define RTE_CRYPTODEV_NAME_MAX_LEN (64)
437 
448 extern int
449 rte_cryptodev_get_dev_id(const char *name);
450 
461 extern const char *
462 rte_cryptodev_name_get(uint8_t dev_id);
463 
471 extern uint8_t
472 rte_cryptodev_count(void);
473 
482 extern uint8_t
483 rte_cryptodev_device_count_by_driver(uint8_t driver_id);
484 
496 uint8_t
497 rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
498  uint8_t nb_devices);
499 /*
500  * Return the NUMA socket to which a device is connected
501  *
502  * @param dev_id
503  * The identifier of the device
504  * @return
505  * The NUMA socket id to which the device is connected or
506  * a default of zero if the socket could not be determined.
507  * -1 if returned is the dev_id value is out of range.
508  */
509 extern int
510 rte_cryptodev_socket_id(uint8_t dev_id);
511 
514  int socket_id;
515  uint16_t nb_queue_pairs;
517 };
518 
533 extern int
534 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
535 
551 extern int
552 rte_cryptodev_start(uint8_t dev_id);
553 
560 extern void
561 rte_cryptodev_stop(uint8_t dev_id);
562 
572 extern int
573 rte_cryptodev_close(uint8_t dev_id);
574 
600 extern int
601 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
602  const struct rte_cryptodev_qp_conf *qp_conf, int socket_id,
603  struct rte_mempool *session_pool);
604 
620 __rte_deprecated
621 extern int
622 rte_cryptodev_queue_pair_start(uint8_t dev_id, uint16_t queue_pair_id);
623 
638 __rte_deprecated
639 extern int
640 rte_cryptodev_queue_pair_stop(uint8_t dev_id, uint16_t queue_pair_id);
641 
649 extern uint16_t
650 rte_cryptodev_queue_pair_count(uint8_t dev_id);
651 
652 
664 extern int
665 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
666 
672 extern void
673 rte_cryptodev_stats_reset(uint8_t dev_id);
674 
688 extern void
689 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
690 
691 
705 extern int
706 rte_cryptodev_callback_register(uint8_t dev_id,
707  enum rte_cryptodev_event_type event,
708  rte_cryptodev_cb_fn cb_fn, void *cb_arg);
709 
723 extern int
724 rte_cryptodev_callback_unregister(uint8_t dev_id,
725  enum rte_cryptodev_event_type event,
726  rte_cryptodev_cb_fn cb_fn, void *cb_arg);
727 
728 
729 typedef uint16_t (*dequeue_pkt_burst_t)(void *qp,
730  struct rte_crypto_op **ops, uint16_t nb_ops);
733 typedef uint16_t (*enqueue_pkt_burst_t)(void *qp,
734  struct rte_crypto_op **ops, uint16_t nb_ops);
740 struct rte_cryptodev_callback;
741 
743 TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
744 
756  uint64_t feature_flags;
761  uint8_t driver_id;
764  struct rte_cryptodev_cb_list link_intr_cbs;
767  void *security_ctx;
770  __extension__
771  uint8_t attached : 1;
774 
775 void *
776 rte_cryptodev_get_sec_ctx(uint8_t dev_id);
777 
786  uint8_t dev_id;
788  uint8_t socket_id;
793  __extension__
794  uint8_t dev_started : 1;
799  void **queue_pairs;
801  uint16_t nb_queue_pairs;
804  void *dev_private;
807 
808 extern struct rte_cryptodev *rte_cryptodevs;
845 static inline uint16_t
846 rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
847  struct rte_crypto_op **ops, uint16_t nb_ops)
848 {
849  struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
850 
851  nb_ops = (*dev->dequeue_burst)
852  (dev->data->queue_pairs[qp_id], ops, nb_ops);
853 
854  return nb_ops;
855 }
856 
888 static inline uint16_t
889 rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
890  struct rte_crypto_op **ops, uint16_t nb_ops)
891 {
892  struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
893 
894  return (*dev->enqueue_burst)(
895  dev->data->queue_pairs[qp_id], ops, nb_ops);
896 }
897 
898 
904  __extension__ void *sess_private_data[0];
906 };
907 
908 
920 
933 int
935 
951 int
952 rte_cryptodev_sym_session_init(uint8_t dev_id,
953  struct rte_cryptodev_sym_session *sess,
954  struct rte_crypto_sym_xform *xforms,
955  struct rte_mempool *mempool);
956 
970 int
971 rte_cryptodev_sym_session_clear(uint8_t dev_id,
972  struct rte_cryptodev_sym_session *sess);
973 
981 __rte_deprecated
982 unsigned int
984 
995 __rte_deprecated
996 unsigned int
998 
1005 unsigned int
1007 
1019 unsigned int
1021 
1035 __rte_deprecated
1036 int
1037 rte_cryptodev_queue_pair_attach_sym_session(uint8_t dev_id, uint16_t qp_id,
1038  struct rte_cryptodev_sym_session *session);
1039 
1053 __rte_deprecated
1054 int
1055 rte_cryptodev_queue_pair_detach_sym_session(uint8_t dev_id, uint16_t qp_id,
1056  struct rte_cryptodev_sym_session *session);
1057 
1066 int rte_cryptodev_driver_id_get(const char *name);
1067 
1076 const char *rte_cryptodev_driver_name_get(uint8_t driver_id);
1077 
1090 int __rte_experimental
1092  struct rte_cryptodev_sym_session *sess,
1093  void *data,
1094  uint16_t size);
1095 
1106 void * __rte_experimental
1108  struct rte_cryptodev_sym_session *sess);
1109 
1110 #ifdef __cplusplus
1111 }
1112 #endif
1113 
1114 #endif /* _RTE_CRYPTODEV_H_ */