DPDK  17.08.2
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_vdev.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_PMD_LOG_ERR(dev, ...) \
64  RTE_LOG(ERR, CRYPTODEV, \
65  RTE_FMT("[%s] %s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
66  dev, __func__, __LINE__, 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  (phys_addr_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 
365 extern const char *
366 rte_cryptodev_get_feature_name(uint64_t flag);
367 
370  const char *driver_name;
371  uint8_t driver_id;
374  uint64_t feature_flags;
379  unsigned max_nb_queue_pairs;
382  struct {
383  unsigned max_nb_sessions;
385  unsigned int max_nb_sessions_per_qp;
389  } sym;
390 };
391 
392 #define RTE_CRYPTODEV_DETACHED (0)
393 #define RTE_CRYPTODEV_ATTACHED (1)
394 
400 };
401 
404  uint32_t nb_descriptors;
405 };
406 
416 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
417  enum rte_cryptodev_event_type event, void *cb_arg);
418 
419 
422  uint64_t enqueued_count;
424  uint64_t dequeued_count;
427  uint64_t enqueue_err_count;
429  uint64_t dequeue_err_count;
431 };
432 
433 #define RTE_CRYPTODEV_NAME_MAX_LEN (64)
434 
449 __rte_deprecated
450 extern int
451 rte_cryptodev_create_vdev(const char *name, const char *args);
452 
462 extern int
463 rte_cryptodev_get_dev_id(const char *name);
464 
472 extern uint8_t
473 rte_cryptodev_count(void);
474 
483 extern uint8_t
484 rte_cryptodev_device_count_by_driver(uint8_t driver_id);
485 
497 uint8_t
498 rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
499  uint8_t nb_devices);
500 /*
501  * Return the NUMA socket to which a device is connected
502  *
503  * @param dev_id
504  * The identifier of the device
505  * @return
506  * The NUMA socket id to which the device is connected or
507  * a default of zero if the socket could not be determined.
508  * -1 if returned is the dev_id value is out of range.
509  */
510 extern int
511 rte_cryptodev_socket_id(uint8_t dev_id);
512 
515  int socket_id;
516  uint16_t nb_queue_pairs;
518 };
519 
534 extern int
535 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
536 
552 extern int
553 rte_cryptodev_start(uint8_t dev_id);
554 
561 extern void
562 rte_cryptodev_stop(uint8_t dev_id);
563 
573 extern int
574 rte_cryptodev_close(uint8_t dev_id);
575 
601 extern int
602 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
603  const struct rte_cryptodev_qp_conf *qp_conf, int socket_id,
604  struct rte_mempool *session_pool);
605 
620 extern int
621 rte_cryptodev_queue_pair_start(uint8_t dev_id, uint16_t queue_pair_id);
622 
636 extern int
637 rte_cryptodev_queue_pair_stop(uint8_t dev_id, uint16_t queue_pair_id);
638 
646 extern uint16_t
647 rte_cryptodev_queue_pair_count(uint8_t dev_id);
648 
649 
661 extern int
662 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
663 
669 extern void
670 rte_cryptodev_stats_reset(uint8_t dev_id);
671 
680 extern void
681 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
682 
683 
697 extern int
698 rte_cryptodev_callback_register(uint8_t dev_id,
699  enum rte_cryptodev_event_type event,
700  rte_cryptodev_cb_fn cb_fn, void *cb_arg);
701 
715 extern int
716 rte_cryptodev_callback_unregister(uint8_t dev_id,
717  enum rte_cryptodev_event_type event,
718  rte_cryptodev_cb_fn cb_fn, void *cb_arg);
719 
720 
721 typedef uint16_t (*dequeue_pkt_burst_t)(void *qp,
722  struct rte_crypto_op **ops, uint16_t nb_ops);
725 typedef uint16_t (*enqueue_pkt_burst_t)(void *qp,
726  struct rte_crypto_op **ops, uint16_t nb_ops);
732 struct rte_cryptodev_callback;
733 
735 TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
736 
748  uint64_t feature_flags;
753  uint8_t driver_id;
756  struct rte_cryptodev_cb_list link_intr_cbs;
759  __extension__
760  uint8_t attached : 1;
763 
772  uint8_t dev_id;
774  uint8_t socket_id;
779  __extension__
780  uint8_t dev_started : 1;
785  void **queue_pairs;
787  uint16_t nb_queue_pairs;
790  void *dev_private;
793 
794 extern struct rte_cryptodev *rte_cryptodevs;
831 static inline uint16_t
832 rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
833  struct rte_crypto_op **ops, uint16_t nb_ops)
834 {
835  struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
836 
837  nb_ops = (*dev->dequeue_burst)
838  (dev->data->queue_pairs[qp_id], ops, nb_ops);
839 
840  return nb_ops;
841 }
842 
874 static inline uint16_t
875 rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
876  struct rte_crypto_op **ops, uint16_t nb_ops)
877 {
878  struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
879 
880  return (*dev->enqueue_burst)(
881  dev->data->queue_pairs[qp_id], ops, nb_ops);
882 }
883 
884 
887  __extension__ void *sess_private_data[0];
889 };
890 
891 
903 
916 int
918 
934 int
935 rte_cryptodev_sym_session_init(uint8_t dev_id,
936  struct rte_cryptodev_sym_session *sess,
937  struct rte_crypto_sym_xform *xforms,
938  struct rte_mempool *mempool);
939 
951 int
952 rte_cryptodev_sym_session_clear(uint8_t dev_id,
953  struct rte_cryptodev_sym_session *sess);
954 
961 unsigned int
963 
973 unsigned int
975 
988 int
989 rte_cryptodev_queue_pair_attach_sym_session(uint8_t dev_id, uint16_t qp_id,
990  struct rte_cryptodev_sym_session *session);
991 
1004 int
1005 rte_cryptodev_queue_pair_detach_sym_session(uint8_t dev_id, uint16_t qp_id,
1006  struct rte_cryptodev_sym_session *session);
1007 
1016 int rte_cryptodev_driver_id_get(const char *name);
1017 
1026 const char *rte_cryptodev_driver_name_get(uint8_t driver_id);
1027 
1037 uint8_t rte_cryptodev_allocate_driver(const struct rte_driver *driver);
1038 
1039 
1040 #define RTE_PMD_REGISTER_CRYPTO_DRIVER(drv, driver_id)\
1041 RTE_INIT(init_ ##driver_id);\
1042 static void init_ ##driver_id(void)\
1043 {\
1044  driver_id = rte_cryptodev_allocate_driver(&(drv).driver);\
1045 }
1046 
1047 
1048 #ifdef __cplusplus
1049 }
1050 #endif
1051 
1052 #endif /* _RTE_CRYPTODEV_H_ */