DPDK  17.02.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 
53 #define CRYPTODEV_NAME_NULL_PMD crypto_null
54 
55 #define CRYPTODEV_NAME_AESNI_MB_PMD crypto_aesni_mb
56 
57 #define CRYPTODEV_NAME_AESNI_GCM_PMD crypto_aesni_gcm
58 
59 #define CRYPTODEV_NAME_OPENSSL_PMD crypto_openssl
60 
61 #define CRYPTODEV_NAME_QAT_SYM_PMD crypto_qat
62 
63 #define CRYPTODEV_NAME_SNOW3G_PMD crypto_snow3g
64 
65 #define CRYPTODEV_NAME_KASUMI_PMD crypto_kasumi
66 
67 #define CRYPTODEV_NAME_ZUC_PMD crypto_zuc
68 
69 #define CRYPTODEV_NAME_ARMV8_PMD crypto_armv8
70 
71 #define CRYPTODEV_NAME_SCHEDULER_PMD crypto_scheduler
72 
86 };
87 
88 extern const char **rte_cyptodev_names;
89 
90 /* Logging Macros */
91 
92 #define CDEV_LOG_ERR(...) \
93  RTE_LOG(ERR, CRYPTODEV, \
94  RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
95  __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
96 
97 #define CDEV_PMD_LOG_ERR(dev, ...) \
98  RTE_LOG(ERR, CRYPTODEV, \
99  RTE_FMT("[%s] %s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
100  dev, __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
101 
102 #ifdef RTE_LIBRTE_CRYPTODEV_DEBUG
103 #define CDEV_LOG_DEBUG(...) \
104  RTE_LOG(DEBUG, CRYPTODEV, \
105  RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
106  __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
107 
108 #define CDEV_PMD_TRACE(...) \
109  RTE_LOG(DEBUG, CRYPTODEV, \
110  RTE_FMT("[%s] %s: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
111  dev, __func__, RTE_FMT_TAIL(__VA_ARGS__,)))
112 
113 #else
114 #define CDEV_LOG_DEBUG(...) (void)0
115 #define CDEV_PMD_TRACE(...) (void)0
116 #endif
117 
122  uint16_t min;
123  uint16_t max;
124  uint16_t increment;
130 };
131 
139  union {
140  struct {
143  uint16_t block_size;
151  } auth;
153  struct {
156  uint16_t block_size;
162  } cipher;
164  };
165 };
166 
173  union {
176  };
177 };
178 
181  enum rte_crypto_sym_xform_type type;
182  union {
183  enum rte_crypto_cipher_algorithm cipher;
184  enum rte_crypto_auth_algorithm auth;
185  } algo;
186 };
187 
200  const struct rte_cryptodev_sym_capability_idx *idx);
201 
214 int
216  const struct rte_cryptodev_symmetric_capability *capability,
217  uint16_t key_size, uint16_t iv_size);
218 
232 int
234  const struct rte_cryptodev_symmetric_capability *capability,
235  uint16_t key_size, uint16_t digest_size, uint16_t aad_size);
236 
238 #define RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() \
239  { RTE_CRYPTO_OP_TYPE_UNDEFINED }
240 
241 
250 #define RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO (1ULL << 0)
251 
252 #define RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO (1ULL << 1)
253 
254 #define RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING (1ULL << 2)
255 
256 #define RTE_CRYPTODEV_FF_CPU_SSE (1ULL << 3)
257 
258 #define RTE_CRYPTODEV_FF_CPU_AVX (1ULL << 4)
259 
260 #define RTE_CRYPTODEV_FF_CPU_AVX2 (1ULL << 5)
261 
262 #define RTE_CRYPTODEV_FF_CPU_AESNI (1ULL << 6)
263 
264 #define RTE_CRYPTODEV_FF_HW_ACCELERATED (1ULL << 7)
265 
266 #define RTE_CRYPTODEV_FF_CPU_AVX512 (1ULL << 8)
267 
268 #define RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER (1ULL << 9)
269 
270 #define RTE_CRYPTODEV_FF_CPU_NEON (1ULL << 10)
271 
272 #define RTE_CRYPTODEV_FF_CPU_ARM_CE (1ULL << 11)
273 
285 extern const char *
286 rte_cryptodev_get_feature_name(uint64_t flag);
287 
290  const char *driver_name;
294  uint64_t feature_flags;
299  unsigned max_nb_queue_pairs;
302  struct {
303  unsigned max_nb_sessions;
305  } sym;
306 };
307 
308 #define RTE_CRYPTODEV_DETACHED (0)
309 #define RTE_CRYPTODEV_ATTACHED (1)
310 
316 };
317 
320  uint32_t nb_descriptors;
321 };
322 
332 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
333  enum rte_cryptodev_event_type event, void *cb_arg);
334 
335 
338  uint64_t enqueued_count;
340  uint64_t dequeued_count;
343  uint64_t enqueue_err_count;
345  uint64_t dequeue_err_count;
347 };
348 
349 #define RTE_CRYPTODEV_NAME_MAX_LEN (64)
350 
351 #define RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_QUEUE_PAIRS 8
352 #define RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_SESSIONS 2048
353 
358 struct rte_crypto_vdev_init_params {
359  unsigned max_nb_queue_pairs;
360  unsigned max_nb_sessions;
361  uint8_t socket_id;
362  char name[RTE_CRYPTODEV_NAME_MAX_LEN];
363 };
364 
376 int
378  struct rte_crypto_vdev_init_params *params,
379  const char *input_args);
380 
392 extern int
393 rte_cryptodev_create_vdev(const char *name, const char *args);
394 
404 extern int
405 rte_cryptodev_get_dev_id(const char *name);
406 
414 extern uint8_t
415 rte_cryptodev_count(void);
416 
425 extern uint8_t
427 
438 uint8_t
439 rte_cryptodev_devices_get(const char *dev_name, uint8_t *devices,
440  uint8_t nb_devices);
441 /*
442  * Return the NUMA socket to which a device is connected
443  *
444  * @param dev_id
445  * The identifier of the device
446  * @return
447  * The NUMA socket id to which the device is connected or
448  * a default of zero if the socket could not be determined.
449  * -1 if returned is the dev_id value is out of range.
450  */
451 extern int
452 rte_cryptodev_socket_id(uint8_t dev_id);
453 
456  int socket_id;
457  uint16_t nb_queue_pairs;
460  struct {
461  uint32_t nb_objs;
462  uint32_t cache_size;
463  } session_mp;
464 };
465 
480 extern int
481 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
482 
498 extern int
499 rte_cryptodev_start(uint8_t dev_id);
500 
507 extern void
508 rte_cryptodev_stop(uint8_t dev_id);
509 
519 extern int
520 rte_cryptodev_close(uint8_t dev_id);
521 
545 extern int
546 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
547  const struct rte_cryptodev_qp_conf *qp_conf, int socket_id);
548 
563 extern int
564 rte_cryptodev_queue_pair_start(uint8_t dev_id, uint16_t queue_pair_id);
565 
579 extern int
580 rte_cryptodev_queue_pair_stop(uint8_t dev_id, uint16_t queue_pair_id);
581 
589 extern uint16_t
590 rte_cryptodev_queue_pair_count(uint8_t dev_id);
591 
592 
604 extern int
605 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
606 
612 extern void
613 rte_cryptodev_stats_reset(uint8_t dev_id);
614 
623 extern void
624 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
625 
626 
640 extern int
641 rte_cryptodev_callback_register(uint8_t dev_id,
642  enum rte_cryptodev_event_type event,
643  rte_cryptodev_cb_fn cb_fn, void *cb_arg);
644 
658 extern int
659 rte_cryptodev_callback_unregister(uint8_t dev_id,
660  enum rte_cryptodev_event_type event,
661  rte_cryptodev_cb_fn cb_fn, void *cb_arg);
662 
663 
664 typedef uint16_t (*dequeue_pkt_burst_t)(void *qp,
665  struct rte_crypto_op **ops, uint16_t nb_ops);
668 typedef uint16_t (*enqueue_pkt_burst_t)(void *qp,
669  struct rte_crypto_op **ops, uint16_t nb_ops);
675 struct rte_cryptodev_callback;
676 
678 TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
679 
693  uint64_t feature_flags;
701  struct rte_cryptodev_cb_list link_intr_cbs;
704  __extension__
705  uint8_t attached : 1;
708 
717  uint8_t dev_id;
719  uint8_t socket_id;
724  __extension__
725  uint8_t dev_started : 1;
730  void **queue_pairs;
732  uint16_t nb_queue_pairs;
735  void *dev_private;
738 
739 extern struct rte_cryptodev *rte_cryptodevs;
776 static inline uint16_t
777 rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
778  struct rte_crypto_op **ops, uint16_t nb_ops)
779 {
780  struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
781 
782  nb_ops = (*dev->dequeue_burst)
783  (dev->data->queue_pairs[qp_id], ops, nb_ops);
784 
785  return nb_ops;
786 }
787 
819 static inline uint16_t
820 rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
821  struct rte_crypto_op **ops, uint16_t nb_ops)
822 {
823  struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
824 
825  return (*dev->enqueue_burst)(
826  dev->data->queue_pairs[qp_id], ops, nb_ops);
827 }
828 
829 
833  struct {
834  uint8_t dev_id;
836  enum rte_cryptodev_type dev_type;
838  struct rte_mempool *mp;
840  } __rte_aligned(8);
843  __extension__ char _private[0];
845 };
847 
869 extern struct rte_cryptodev_sym_session *
870 rte_cryptodev_sym_session_create(uint8_t dev_id,
871  struct rte_crypto_sym_xform *xform);
872 
884 extern struct rte_cryptodev_sym_session *
885 rte_cryptodev_sym_session_free(uint8_t dev_id,
886  struct rte_cryptodev_sym_session *session);
887 
888 
889 #ifdef __cplusplus
890 }
891 #endif
892 
893 #endif /* _RTE_CRYPTODEV_H_ */