DPDK  17.05.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 
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 
73 #define CRYPTODEV_NAME_DPAA2_SEC_PMD cryptodev_dpaa2_sec_pmd
74 
89 };
90 
91 extern const char **rte_cyptodev_names;
92 
93 /* Logging Macros */
94 
95 #define CDEV_LOG_ERR(...) \
96  RTE_LOG(ERR, CRYPTODEV, \
97  RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
98  __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
99 
100 #define CDEV_PMD_LOG_ERR(dev, ...) \
101  RTE_LOG(ERR, CRYPTODEV, \
102  RTE_FMT("[%s] %s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
103  dev, __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
104 
105 #ifdef RTE_LIBRTE_CRYPTODEV_DEBUG
106 #define CDEV_LOG_DEBUG(...) \
107  RTE_LOG(DEBUG, CRYPTODEV, \
108  RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
109  __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
110 
111 #define CDEV_PMD_TRACE(...) \
112  RTE_LOG(DEBUG, CRYPTODEV, \
113  RTE_FMT("[%s] %s: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
114  dev, __func__, RTE_FMT_TAIL(__VA_ARGS__,)))
115 
116 #else
117 #define CDEV_LOG_DEBUG(...) (void)0
118 #define CDEV_PMD_TRACE(...) (void)0
119 #endif
120 
125  uint16_t min;
126  uint16_t max;
127  uint16_t increment;
133 };
134 
142  union {
143  struct {
146  uint16_t block_size;
154  } auth;
156  struct {
159  uint16_t block_size;
165  } cipher;
167  };
168 };
169 
176  union {
179  };
180 };
181 
184  enum rte_crypto_sym_xform_type type;
185  union {
186  enum rte_crypto_cipher_algorithm cipher;
187  enum rte_crypto_auth_algorithm auth;
188  } algo;
189 };
190 
203  const struct rte_cryptodev_sym_capability_idx *idx);
204 
217 int
219  const struct rte_cryptodev_symmetric_capability *capability,
220  uint16_t key_size, uint16_t iv_size);
221 
235 int
237  const struct rte_cryptodev_symmetric_capability *capability,
238  uint16_t key_size, uint16_t digest_size, uint16_t aad_size);
239 
251 int
253  const char *algo_string);
254 
266 int
268  const char *algo_string);
269 
271 #define RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() \
272  { RTE_CRYPTO_OP_TYPE_UNDEFINED }
273 
274 
283 #define RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO (1ULL << 0)
284 
285 #define RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO (1ULL << 1)
286 
287 #define RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING (1ULL << 2)
288 
289 #define RTE_CRYPTODEV_FF_CPU_SSE (1ULL << 3)
290 
291 #define RTE_CRYPTODEV_FF_CPU_AVX (1ULL << 4)
292 
293 #define RTE_CRYPTODEV_FF_CPU_AVX2 (1ULL << 5)
294 
295 #define RTE_CRYPTODEV_FF_CPU_AESNI (1ULL << 6)
296 
297 #define RTE_CRYPTODEV_FF_HW_ACCELERATED (1ULL << 7)
298 
299 #define RTE_CRYPTODEV_FF_CPU_AVX512 (1ULL << 8)
300 
301 #define RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER (1ULL << 9)
302 
303 #define RTE_CRYPTODEV_FF_CPU_NEON (1ULL << 10)
304 
305 #define RTE_CRYPTODEV_FF_CPU_ARM_CE (1ULL << 11)
306 
318 extern const char *
319 rte_cryptodev_get_feature_name(uint64_t flag);
320 
323  const char *driver_name;
327  uint64_t feature_flags;
332  unsigned max_nb_queue_pairs;
335  struct {
336  unsigned max_nb_sessions;
338  unsigned int max_nb_sessions_per_qp;
342  } sym;
343 };
344 
345 #define RTE_CRYPTODEV_DETACHED (0)
346 #define RTE_CRYPTODEV_ATTACHED (1)
347 
353 };
354 
357  uint32_t nb_descriptors;
358 };
359 
369 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
370  enum rte_cryptodev_event_type event, void *cb_arg);
371 
372 
375  uint64_t enqueued_count;
377  uint64_t dequeued_count;
380  uint64_t enqueue_err_count;
382  uint64_t dequeue_err_count;
384 };
385 
386 #define RTE_CRYPTODEV_NAME_MAX_LEN (64)
387 
388 #define RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_QUEUE_PAIRS 8
389 #define RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_SESSIONS 2048
390 
395 struct rte_crypto_vdev_init_params {
396  unsigned max_nb_queue_pairs;
397  unsigned max_nb_sessions;
398  uint8_t socket_id;
399  char name[RTE_CRYPTODEV_NAME_MAX_LEN];
400 };
401 
413 int
415  struct rte_crypto_vdev_init_params *params,
416  const char *input_args);
417 
429 extern int
430 rte_cryptodev_create_vdev(const char *name, const char *args);
431 
441 extern int
442 rte_cryptodev_get_dev_id(const char *name);
443 
451 extern uint8_t
452 rte_cryptodev_count(void);
453 
462 extern uint8_t
464 
476 uint8_t
477 rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
478  uint8_t nb_devices);
479 /*
480  * Return the NUMA socket to which a device is connected
481  *
482  * @param dev_id
483  * The identifier of the device
484  * @return
485  * The NUMA socket id to which the device is connected or
486  * a default of zero if the socket could not be determined.
487  * -1 if returned is the dev_id value is out of range.
488  */
489 extern int
490 rte_cryptodev_socket_id(uint8_t dev_id);
491 
494  int socket_id;
495  uint16_t nb_queue_pairs;
498  struct {
499  uint32_t nb_objs;
500  uint32_t cache_size;
501  } session_mp;
502 };
503 
518 extern int
519 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
520 
536 extern int
537 rte_cryptodev_start(uint8_t dev_id);
538 
545 extern void
546 rte_cryptodev_stop(uint8_t dev_id);
547 
557 extern int
558 rte_cryptodev_close(uint8_t dev_id);
559 
583 extern int
584 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
585  const struct rte_cryptodev_qp_conf *qp_conf, int socket_id);
586 
601 extern int
602 rte_cryptodev_queue_pair_start(uint8_t dev_id, uint16_t queue_pair_id);
603 
617 extern int
618 rte_cryptodev_queue_pair_stop(uint8_t dev_id, uint16_t queue_pair_id);
619 
627 extern uint16_t
628 rte_cryptodev_queue_pair_count(uint8_t dev_id);
629 
630 
642 extern int
643 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
644 
650 extern void
651 rte_cryptodev_stats_reset(uint8_t dev_id);
652 
661 extern void
662 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
663 
664 
678 extern int
679 rte_cryptodev_callback_register(uint8_t dev_id,
680  enum rte_cryptodev_event_type event,
681  rte_cryptodev_cb_fn cb_fn, void *cb_arg);
682 
696 extern int
697 rte_cryptodev_callback_unregister(uint8_t dev_id,
698  enum rte_cryptodev_event_type event,
699  rte_cryptodev_cb_fn cb_fn, void *cb_arg);
700 
701 
702 typedef uint16_t (*dequeue_pkt_burst_t)(void *qp,
703  struct rte_crypto_op **ops, uint16_t nb_ops);
706 typedef uint16_t (*enqueue_pkt_burst_t)(void *qp,
707  struct rte_crypto_op **ops, uint16_t nb_ops);
713 struct rte_cryptodev_callback;
714 
716 TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
717 
731  uint64_t feature_flags;
739  struct rte_cryptodev_cb_list link_intr_cbs;
742  __extension__
743  uint8_t attached : 1;
746 
755  uint8_t dev_id;
757  uint8_t socket_id;
762  __extension__
763  uint8_t dev_started : 1;
768  void **queue_pairs;
770  uint16_t nb_queue_pairs;
773  void *dev_private;
776 
777 extern struct rte_cryptodev *rte_cryptodevs;
814 static inline uint16_t
815 rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
816  struct rte_crypto_op **ops, uint16_t nb_ops)
817 {
818  struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
819 
820  nb_ops = (*dev->dequeue_burst)
821  (dev->data->queue_pairs[qp_id], ops, nb_ops);
822 
823  return nb_ops;
824 }
825 
857 static inline uint16_t
858 rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
859  struct rte_crypto_op **ops, uint16_t nb_ops)
860 {
861  struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
862 
863  return (*dev->enqueue_burst)(
864  dev->data->queue_pairs[qp_id], ops, nb_ops);
865 }
866 
867 
871  struct {
872  uint8_t dev_id;
874  enum rte_cryptodev_type dev_type;
876  struct rte_mempool *mp;
878  } __rte_aligned(8);
881  __extension__ char _private[0];
883 };
885 
907 extern struct rte_cryptodev_sym_session *
908 rte_cryptodev_sym_session_create(uint8_t dev_id,
909  struct rte_crypto_sym_xform *xform);
910 
922 extern struct rte_cryptodev_sym_session *
923 rte_cryptodev_sym_session_free(uint8_t dev_id,
924  struct rte_cryptodev_sym_session *session);
925 
937 int
939  struct rte_cryptodev_sym_session *session);
940 
952 int
954  struct rte_cryptodev_sym_session *session);
955 
956 
957 #ifdef __cplusplus
958 }
959 #endif
960 
961 #endif /* _RTE_CRYPTODEV_H_ */