DPDK  16.04.0
rte_cryptodev.h
Go to the documentation of this file.
1 /*-
2  *
3  * Copyright(c) 2015-2016 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 
52 #define CRYPTODEV_NAME_NULL_PMD ("cryptodev_null_pmd")
53 
54 #define CRYPTODEV_NAME_AESNI_MB_PMD ("cryptodev_aesni_mb_pmd")
55 
56 #define CRYPTODEV_NAME_AESNI_GCM_PMD ("cryptodev_aesni_gcm_pmd")
57 
58 #define CRYPTODEV_NAME_QAT_SYM_PMD ("cryptodev_qat_sym_pmd")
59 
60 #define CRYPTODEV_NAME_SNOW3G_PMD ("cryptodev_snow3g_pmd")
61 
70 };
71 
72 extern const char **rte_cyptodev_names;
73 
74 /* Logging Macros */
75 
76 #define CDEV_LOG_ERR(fmt, args...) \
77  RTE_LOG(ERR, CRYPTODEV, "%s() line %u: " fmt "\n", \
78  __func__, __LINE__, ## args)
79 
80 #define CDEV_PMD_LOG_ERR(dev, fmt, args...) \
81  RTE_LOG(ERR, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \
82  dev, __func__, __LINE__, ## args)
83 
84 #ifdef RTE_LIBRTE_CRYPTODEV_DEBUG
85 #define CDEV_LOG_DEBUG(fmt, args...) \
86  RTE_LOG(DEBUG, CRYPTODEV, "%s() line %u: " fmt "\n", \
87  __func__, __LINE__, ## args) \
88 
89 #define CDEV_PMD_TRACE(fmt, args...) \
90  RTE_LOG(DEBUG, CRYPTODEV, "[%s] %s: " fmt "\n", \
91  dev, __func__, ## args)
92 
93 #else
94 #define CDEV_LOG_DEBUG(fmt, args...)
95 #define CDEV_PMD_TRACE(fmt, args...)
96 #endif
97 
104  union {
105  struct {
108  uint16_t block_size;
110  struct {
111  uint16_t min;
112  uint16_t max;
113  uint16_t increment;
118  } key_size;
120  struct {
121  uint16_t min;
122  uint16_t max;
123  uint16_t increment;
128  } digest_size;
130  struct {
131  uint16_t min;
132  uint16_t max;
133  uint16_t increment;
138  } aad_size;
140  } auth;
142  struct {
145  uint16_t block_size;
147  struct {
148  uint16_t min;
149  uint16_t max;
150  uint16_t increment;
155  } key_size;
157  struct {
158  uint16_t min;
159  uint16_t max;
160  uint16_t increment;
165  } iv_size;
167  } cipher;
169  };
170 };
171 
177  union {
180  };
181 };
182 
184 #define RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() \
185  { RTE_CRYPTO_OP_TYPE_UNDEFINED }
186 
187 
196 #define RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO (1ULL << 0)
197 
198 #define RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO (1ULL << 1)
199 
200 #define RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING (1ULL << 2)
201 
202 #define RTE_CRYPTODEV_FF_CPU_SSE (1ULL << 3)
203 
204 #define RTE_CRYPTODEV_FF_CPU_AVX (1ULL << 4)
205 
206 #define RTE_CRYPTODEV_FF_CPU_AVX2 (1ULL << 5)
207 
208 #define RTE_CRYPTODEV_FF_CPU_AESNI (1ULL << 6)
209 
210 #define RTE_CRYPTODEV_FF_HW_ACCELERATED (1ULL << 7)
211 
223 extern const char *
224 rte_cryptodev_get_feature_name(uint64_t flag);
225 
228  const char *driver_name;
232  uint64_t feature_flags;
237  unsigned max_nb_queue_pairs;
240  struct {
241  unsigned max_nb_sessions;
243  } sym;
244 };
245 
246 #define RTE_CRYPTODEV_DETACHED (0)
247 #define RTE_CRYPTODEV_ATTACHED (1)
248 
254 };
255 
258  uint32_t nb_descriptors;
259 };
260 
270 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
271  enum rte_cryptodev_event_type event, void *cb_arg);
272 
273 
276  uint64_t enqueued_count;
278  uint64_t dequeued_count;
281  uint64_t enqueue_err_count;
283  uint64_t dequeue_err_count;
285 };
286 
287 #define RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_QUEUE_PAIRS 8
288 #define RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_SESSIONS 2048
289 
294 struct rte_crypto_vdev_init_params {
295  unsigned max_nb_queue_pairs;
296  unsigned max_nb_sessions;
297  uint8_t socket_id;
298 };
299 
300 #define RTE_CRYPTODEV_VDEV_MAX_NB_QP_ARG ("max_nb_queue_pairs")
301 #define RTE_CRYPTODEV_VDEV_MAX_NB_SESS_ARG ("max_nb_sessions")
302 #define RTE_CRYPTODEV_VDEV_SOCKET_ID ("socket_id")
303 
304 static const char *cryptodev_vdev_valid_params[] = {
305  RTE_CRYPTODEV_VDEV_MAX_NB_QP_ARG,
306  RTE_CRYPTODEV_VDEV_MAX_NB_SESS_ARG,
307  RTE_CRYPTODEV_VDEV_SOCKET_ID
308 };
309 
310 static inline uint8_t
311 number_of_sockets(void)
312 {
313  int sockets = 0;
314  int i;
315  const struct rte_memseg *ms = rte_eal_get_physmem_layout();
316 
317  for (i = 0; ((i < RTE_MAX_MEMSEG) && (ms[i].addr != NULL)); i++) {
318  if (sockets < ms[i].socket_id)
319  sockets = ms[i].socket_id;
320  }
321 
322  /* Number of sockets = maximum socket_id + 1 */
323  return ++sockets;
324 }
325 
327 static inline int
329  const char *value, void *extra_args)
330 {
331  int *i = (int *) extra_args;
332 
333  *i = atoi(value);
334  if (*i < 0) {
335  CDEV_LOG_ERR("Argument has to be positive.");
336  return -1;
337  }
338 
339  return 0;
340 }
341 
353 static inline int
354 rte_cryptodev_parse_vdev_init_params(struct rte_crypto_vdev_init_params *params,
355  const char *input_args)
356 {
357  struct rte_kvargs *kvlist;
358  int ret;
359 
360  if (params == NULL)
361  return -EINVAL;
362 
363  if (input_args) {
364  kvlist = rte_kvargs_parse(input_args,
365  cryptodev_vdev_valid_params);
366  if (kvlist == NULL)
367  return -1;
368 
369  ret = rte_kvargs_process(kvlist,
370  RTE_CRYPTODEV_VDEV_MAX_NB_QP_ARG,
372  &params->max_nb_queue_pairs);
373  if (ret < 0)
374  goto free_kvlist;
375 
376  ret = rte_kvargs_process(kvlist,
377  RTE_CRYPTODEV_VDEV_MAX_NB_SESS_ARG,
379  &params->max_nb_sessions);
380  if (ret < 0)
381  goto free_kvlist;
382 
383  ret = rte_kvargs_process(kvlist, RTE_CRYPTODEV_VDEV_SOCKET_ID,
385  &params->socket_id);
386  if (ret < 0)
387  goto free_kvlist;
388 
389  if (params->socket_id >= number_of_sockets()) {
390  CDEV_LOG_ERR("Invalid socket id specified to create "
391  "the virtual crypto device on");
392  goto free_kvlist;
393  }
394  }
395 
396  return 0;
397 
398 free_kvlist:
399  rte_kvargs_free(kvlist);
400  return ret;
401 }
402 
414 extern int
415 rte_cryptodev_create_vdev(const char *name, const char *args);
416 
426 extern int
427 rte_cryptodev_get_dev_id(const char *name);
428 
436 extern uint8_t
437 rte_cryptodev_count(void);
438 
439 extern uint8_t
440 rte_cryptodev_count_devtype(enum rte_cryptodev_type type);
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;
703  struct rte_cryptodev_cb_list link_intr_cbs;
706  uint8_t attached : 1;
709 
710 
711 #define RTE_CRYPTODEV_NAME_MAX_LEN (64)
712 
722  uint8_t dev_id;
724  uint8_t socket_id;
729  uint8_t dev_started : 1;
734  void **queue_pairs;
736  uint16_t nb_queue_pairs;
739  void *dev_private;
742 
743 extern struct rte_cryptodev *rte_cryptodevs;
780 static inline uint16_t
781 rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
782  struct rte_crypto_op **ops, uint16_t nb_ops)
783 {
784  struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
785 
786  nb_ops = (*dev->dequeue_burst)
787  (dev->data->queue_pairs[qp_id], ops, nb_ops);
788 
789  return nb_ops;
790 }
791 
823 static inline uint16_t
824 rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
825  struct rte_crypto_op **ops, uint16_t nb_ops)
826 {
827  struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
828 
829  return (*dev->enqueue_burst)(
830  dev->data->queue_pairs[qp_id], ops, nb_ops);
831 }
832 
833 
836  struct {
837  uint8_t dev_id;
839  enum rte_cryptodev_type dev_type;
841  struct rte_mempool *mp;
843  } __rte_aligned(8);
846  char _private[0];
848 };
850 
872 extern struct rte_cryptodev_sym_session *
873 rte_cryptodev_sym_session_create(uint8_t dev_id,
874  struct rte_crypto_sym_xform *xform);
875 
887 extern struct rte_cryptodev_sym_session *
888 rte_cryptodev_sym_session_free(uint8_t dev_id,
889  struct rte_cryptodev_sym_session *session);
890 
891 
892 #ifdef __cplusplus
893 }
894 #endif
895 
896 #endif /* _RTE_CRYPTODEV_H_ */