DPDK  17.11.0
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 
53 extern const char **rte_cyptodev_names;
54 
55 /* Logging Macros */
56 
57 #define CDEV_LOG_ERR(...) \
58  RTE_LOG(ERR, CRYPTODEV, \
59  RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
60  __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
61 
62 #define CDEV_LOG_INFO(...) \
63  RTE_LOG(INFO, CRYPTODEV, \
64  RTE_FMT(RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
65  RTE_FMT_TAIL(__VA_ARGS__,)))
66 
67 #ifdef RTE_LIBRTE_CRYPTODEV_DEBUG
68 #define CDEV_LOG_DEBUG(...) \
69  RTE_LOG(DEBUG, CRYPTODEV, \
70  RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
71  __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
72 
73 #define CDEV_PMD_TRACE(...) \
74  RTE_LOG(DEBUG, CRYPTODEV, \
75  RTE_FMT("[%s] %s: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
76  dev, __func__, RTE_FMT_TAIL(__VA_ARGS__,)))
77 
78 #else
79 #define CDEV_LOG_DEBUG(...) (void)0
80 #define CDEV_PMD_TRACE(...) (void)0
81 #endif
82 
83 
84 
98 #define rte_crypto_op_ctod_offset(c, t, o) \
99  ((t)((char *)(c) + (o)))
100 
112 #define rte_crypto_op_ctophys_offset(c, o) \
113  (rte_iova_t)((c)->phys_addr + (o))
114 
119  uint16_t min;
120  uint16_t max;
121  uint16_t increment;
127 };
128 
136  union {
137  struct {
140  uint16_t block_size;
150  } auth;
152  struct {
155  uint16_t block_size;
161  } cipher;
163  struct {
166  uint16_t block_size;
176  } aead;
177  };
178 };
179 
186  union {
189  };
190 };
191 
194  enum rte_crypto_sym_xform_type type;
195  union {
196  enum rte_crypto_cipher_algorithm cipher;
197  enum rte_crypto_auth_algorithm auth;
198  enum rte_crypto_aead_algorithm aead;
199  } algo;
200 };
201 
213 rte_cryptodev_sym_capability_get(uint8_t dev_id,
214  const struct rte_cryptodev_sym_capability_idx *idx);
215 
228 int
230  const struct rte_cryptodev_symmetric_capability *capability,
231  uint16_t key_size, uint16_t iv_size);
232 
246 int
248  const struct rte_cryptodev_symmetric_capability *capability,
249  uint16_t key_size, uint16_t digest_size, uint16_t iv_size);
250 
265 int
267  const struct rte_cryptodev_symmetric_capability *capability,
268  uint16_t key_size, uint16_t digest_size, uint16_t aad_size,
269  uint16_t iv_size);
270 
282 int
284  const char *algo_string);
285 
297 int
299  const char *algo_string);
300 
312 int
314  const char *algo_string);
315 
317 #define RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() \
318  { RTE_CRYPTO_OP_TYPE_UNDEFINED }
319 
320 
329 #define RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO (1ULL << 0)
330 
331 #define RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO (1ULL << 1)
332 
333 #define RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING (1ULL << 2)
334 
335 #define RTE_CRYPTODEV_FF_CPU_SSE (1ULL << 3)
336 
337 #define RTE_CRYPTODEV_FF_CPU_AVX (1ULL << 4)
338 
339 #define RTE_CRYPTODEV_FF_CPU_AVX2 (1ULL << 5)
340 
341 #define RTE_CRYPTODEV_FF_CPU_AESNI (1ULL << 6)
342 
343 #define RTE_CRYPTODEV_FF_HW_ACCELERATED (1ULL << 7)
344 
345 #define RTE_CRYPTODEV_FF_CPU_AVX512 (1ULL << 8)
346 
347 #define RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER (1ULL << 9)
348 
349 #define RTE_CRYPTODEV_FF_CPU_NEON (1ULL << 10)
350 
351 #define RTE_CRYPTODEV_FF_CPU_ARM_CE (1ULL << 11)
352 
353 #define RTE_CRYPTODEV_FF_SECURITY (1ULL << 12)
354 
366 extern const char *
367 rte_cryptodev_get_feature_name(uint64_t flag);
368 
371  const char *driver_name;
372  uint8_t driver_id;
373  struct rte_pci_device *pci_dev;
375  uint64_t feature_flags;
383  struct {
384  unsigned max_nb_sessions;
390  } sym;
391 };
392 
393 #define RTE_CRYPTODEV_DETACHED (0)
394 #define RTE_CRYPTODEV_ATTACHED (1)
395 
401 };
402 
405  uint32_t nb_descriptors;
406 };
407 
417 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
418  enum rte_cryptodev_event_type event, void *cb_arg);
419 
420 
423  uint64_t enqueued_count;
425  uint64_t dequeued_count;
432 };
433 
434 #define RTE_CRYPTODEV_NAME_MAX_LEN (64)
435 
446 extern int
447 rte_cryptodev_get_dev_id(const char *name);
448 
459 extern const char *
460 rte_cryptodev_name_get(uint8_t dev_id);
461 
469 extern uint8_t
470 rte_cryptodev_count(void);
471 
480 extern uint8_t
481 rte_cryptodev_device_count_by_driver(uint8_t driver_id);
482 
494 uint8_t
495 rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
496  uint8_t nb_devices);
497 /*
498  * Return the NUMA socket to which a device is connected
499  *
500  * @param dev_id
501  * The identifier of the device
502  * @return
503  * The NUMA socket id to which the device is connected or
504  * a default of zero if the socket could not be determined.
505  * -1 if returned is the dev_id value is out of range.
506  */
507 extern int
508 rte_cryptodev_socket_id(uint8_t dev_id);
509 
512  int socket_id;
513  uint16_t nb_queue_pairs;
515 };
516 
531 extern int
532 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
533 
549 extern int
550 rte_cryptodev_start(uint8_t dev_id);
551 
558 extern void
559 rte_cryptodev_stop(uint8_t dev_id);
560 
570 extern int
571 rte_cryptodev_close(uint8_t dev_id);
572 
598 extern int
599 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
600  const struct rte_cryptodev_qp_conf *qp_conf, int socket_id,
601  struct rte_mempool *session_pool);
602 
617 extern int
618 rte_cryptodev_queue_pair_start(uint8_t dev_id, uint16_t queue_pair_id);
619 
633 extern int
634 rte_cryptodev_queue_pair_stop(uint8_t dev_id, uint16_t queue_pair_id);
635 
643 extern uint16_t
644 rte_cryptodev_queue_pair_count(uint8_t dev_id);
645 
646 
658 extern int
659 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
660 
666 extern void
667 rte_cryptodev_stats_reset(uint8_t dev_id);
668 
682 extern void
683 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
684 
685 
699 extern int
700 rte_cryptodev_callback_register(uint8_t dev_id,
701  enum rte_cryptodev_event_type event,
702  rte_cryptodev_cb_fn cb_fn, void *cb_arg);
703 
717 extern int
718 rte_cryptodev_callback_unregister(uint8_t dev_id,
719  enum rte_cryptodev_event_type event,
720  rte_cryptodev_cb_fn cb_fn, void *cb_arg);
721 
722 
723 typedef uint16_t (*dequeue_pkt_burst_t)(void *qp,
724  struct rte_crypto_op **ops, uint16_t nb_ops);
727 typedef uint16_t (*enqueue_pkt_burst_t)(void *qp,
728  struct rte_crypto_op **ops, uint16_t nb_ops);
734 struct rte_cryptodev_callback;
735 
737 TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
738 
750  uint64_t feature_flags;
755  uint8_t driver_id;
758  struct rte_cryptodev_cb_list link_intr_cbs;
764  __extension__
765  uint8_t attached : 1;
768 
769 void *
770 rte_cryptodev_get_sec_ctx(uint8_t dev_id);
771 
780  uint8_t dev_id;
782  uint8_t socket_id;
787  __extension__
788  uint8_t dev_started : 1;
793  void **queue_pairs;
795  uint16_t nb_queue_pairs;
798  void *dev_private;
801 
802 extern struct rte_cryptodev *rte_cryptodevs;
839 static inline uint16_t
840 rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
841  struct rte_crypto_op **ops, uint16_t nb_ops)
842 {
843  struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
844 
845  nb_ops = (*dev->dequeue_burst)
846  (dev->data->queue_pairs[qp_id], ops, nb_ops);
847 
848  return nb_ops;
849 }
850 
882 static inline uint16_t
883 rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
884  struct rte_crypto_op **ops, uint16_t nb_ops)
885 {
886  struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
887 
888  return (*dev->enqueue_burst)(
889  dev->data->queue_pairs[qp_id], ops, nb_ops);
890 }
891 
892 
895  __extension__ void *sess_private_data[0];
897 };
898 
899 
911 
924 int
926 
942 int
943 rte_cryptodev_sym_session_init(uint8_t dev_id,
944  struct rte_cryptodev_sym_session *sess,
945  struct rte_crypto_sym_xform *xforms,
946  struct rte_mempool *mempool);
947 
959 int
960 rte_cryptodev_sym_session_clear(uint8_t dev_id,
961  struct rte_cryptodev_sym_session *sess);
962 
969 unsigned int
971 
981 unsigned int
983 
996 int
997 rte_cryptodev_queue_pair_attach_sym_session(uint8_t dev_id, uint16_t qp_id,
998  struct rte_cryptodev_sym_session *session);
999 
1012 int
1013 rte_cryptodev_queue_pair_detach_sym_session(uint8_t dev_id, uint16_t qp_id,
1014  struct rte_cryptodev_sym_session *session);
1015 
1024 int rte_cryptodev_driver_id_get(const char *name);
1025 
1034 const char *rte_cryptodev_driver_name_get(uint8_t driver_id);
1035 
1036 #ifdef __cplusplus
1037 }
1038 #endif
1039 
1040 #endif /* _RTE_CRYPTODEV_H_ */
int rte_cryptodev_queue_pair_detach_sym_session(uint8_t dev_id, uint16_t qp_id, struct rte_cryptodev_sym_session *session)
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)
void rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info)
struct rte_cryptodev_symmetric_capability sym
__extension__ void * sess_private_data[0]
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, struct rte_mempool *session_pool)
const char * rte_cryptodev_get_feature_name(uint64_t flag)
int rte_cryptodev_queue_pair_attach_sym_session(uint8_t dev_id, uint16_t qp_id, struct rte_cryptodev_sym_session *session)
unsigned int max_nb_sessions_per_qp
enum rte_crypto_auth_algorithm algo
void * security_ctx
uint8_t rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices, uint8_t nb_devices)
int rte_cryptodev_queue_pair_start(uint8_t dev_id, uint16_t queue_pair_id)
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
unsigned int rte_cryptodev_get_private_session_size(uint8_t dev_id)
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_mbuf __rte_cache_aligned
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)
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
void rte_cryptodev_stop(uint8_t dev_id)
const char * driver_name
int rte_cryptodev_close(uint8_t dev_id)
uint8_t driver_id
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_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)
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:56
int rte_cryptodev_queue_pair_stop(uint8_t dev_id, uint16_t queue_pair_id)
#define RTE_CRYPTODEV_NAME_MAX_LEN
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_cb_list link_intr_cbs
void(* rte_cryptodev_cb_fn)(uint8_t dev_id, enum rte_cryptodev_event_type event, void *cb_arg)
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
#define RTE_STD_C11
Definition: rte_common.h:64
rte_crypto_auth_algorithm
rte_crypto_sym_xform_type
uint16_t(* dequeue_pkt_burst_t)(void *qp, struct rte_crypto_op **ops, uint16_t nb_ops)
struct rte_cryptodev_symmetric_capability::@50::@53 cipher
int rte_cryptodev_start(uint8_t dev_id)
uint64_t enqueue_err_count
uint16_t rte_cryptodev_queue_pair_count(uint8_t dev_id)
uint16_t(* enqueue_pkt_burst_t)(void *qp, struct rte_crypto_op **ops, uint16_t nb_ops)
struct rte_crypto_param_range key_size
struct rte_device * device
unsigned max_nb_sessions
rte_cryptodev_event_type
struct rte_cryptodev_symmetric_capability::@50::@52 auth
struct rte_crypto_param_range aad_size
struct rte_pci_device * pci_dev
enum rte_crypto_sym_xform_type xform_type
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)
struct rte_crypto_param_range iv_size
struct rte_cryptodev * rte_cryptodevs
rte_crypto_aead_algorithm
rte_crypto_cipher_algorithm