DPDK  19.02.0
rte_cryptodev_pmd.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2016 Intel Corporation.
3  */
4 
5 #ifndef _RTE_CRYPTODEV_PMD_H_
6 #define _RTE_CRYPTODEV_PMD_H_
7 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 #include <string.h>
21 
22 #include <rte_config.h>
23 #include <rte_dev.h>
24 #include <rte_malloc.h>
25 #include <rte_mbuf.h>
26 #include <rte_mempool.h>
27 #include <rte_log.h>
28 #include <rte_common.h>
29 
30 #include "rte_crypto.h"
31 #include "rte_cryptodev.h"
32 
33 
34 #define RTE_CRYPTODEV_PMD_DEFAULT_MAX_NB_QUEUE_PAIRS 8
35 
36 #define RTE_CRYPTODEV_PMD_NAME_ARG ("name")
37 #define RTE_CRYPTODEV_PMD_MAX_NB_QP_ARG ("max_nb_queue_pairs")
38 #define RTE_CRYPTODEV_PMD_SOCKET_ID_ARG ("socket_id")
39 
40 
41 static const char * const cryptodev_pmd_valid_params[] = {
42  RTE_CRYPTODEV_PMD_NAME_ARG,
43  RTE_CRYPTODEV_PMD_MAX_NB_QP_ARG,
44  RTE_CRYPTODEV_PMD_SOCKET_ID_ARG
45 };
46 
51 struct rte_cryptodev_pmd_init_params {
52  char name[RTE_CRYPTODEV_NAME_MAX_LEN];
53  size_t private_data_size;
54  int socket_id;
55  unsigned int max_nb_queue_pairs;
56 };
57 
60  struct rte_cryptodev *devs;
61  struct rte_cryptodev_data *data[RTE_CRYPTO_MAX_DEVS];
63  uint8_t nb_devs;
64  uint8_t max_devs;
65 };
66 
67 /* Cryptodev driver, containing the driver ID */
68 struct cryptodev_driver {
69  TAILQ_ENTRY(cryptodev_driver) next;
70  const struct rte_driver *driver;
71  uint8_t id;
72 };
73 
83 struct rte_cryptodev *
84 rte_cryptodev_pmd_get_dev(uint8_t dev_id);
85 
94 struct rte_cryptodev *
95 rte_cryptodev_pmd_get_named_dev(const char *name);
96 
105 unsigned int
106 rte_cryptodev_pmd_is_valid_dev(uint8_t dev_id);
107 
111 extern struct rte_cryptodev *rte_cryptodevs;
112 
113 
128 typedef int (*cryptodev_configure_t)(struct rte_cryptodev *dev,
129  struct rte_cryptodev_config *config);
130 
138 typedef int (*cryptodev_start_t)(struct rte_cryptodev *dev);
139 
145 typedef void (*cryptodev_stop_t)(struct rte_cryptodev *dev);
146 
155 typedef int (*cryptodev_close_t)(struct rte_cryptodev *dev);
156 
157 
164 typedef void (*cryptodev_stats_get_t)(struct rte_cryptodev *dev,
165  struct rte_cryptodev_stats *stats);
166 
167 
173 typedef void (*cryptodev_stats_reset_t)(struct rte_cryptodev *dev);
174 
175 
181 typedef void (*cryptodev_info_get_t)(struct rte_cryptodev *dev,
182  struct rte_cryptodev_info *dev_info);
183 
194 typedef int (*cryptodev_queue_pair_setup_t)(struct rte_cryptodev *dev,
195  uint16_t qp_id, const struct rte_cryptodev_qp_conf *qp_conf,
196  int socket_id);
197 
209  uint16_t qp_id);
210 
218 typedef uint32_t (*cryptodev_queue_pair_count_t)(struct rte_cryptodev *dev);
219 
233  struct rte_cryptodev *dev, unsigned nb_objs,
234  unsigned obj_cache_size, int socket_id);
235 
236 
247  struct rte_cryptodev *dev);
258  struct rte_cryptodev *dev);
259 
275  struct rte_crypto_sym_xform *xform,
276  struct rte_cryptodev_sym_session *session,
277  struct rte_mempool *mp);
293  struct rte_crypto_asym_xform *xform,
294  struct rte_cryptodev_asym_session *session,
295  struct rte_mempool *mp);
302 typedef void (*cryptodev_sym_free_session_t)(struct rte_cryptodev *dev,
303  struct rte_cryptodev_sym_session *sess);
310 typedef void (*cryptodev_asym_free_session_t)(struct rte_cryptodev *dev,
311  struct rte_cryptodev_asym_session *sess);
312 
346 };
347 
348 
360 struct rte_cryptodev *
361 rte_cryptodev_pmd_allocate(const char *name, int socket_id);
362 
373 extern int
375 
376 
394 int
395 rte_cryptodev_pmd_parse_input_args(
396  struct rte_cryptodev_pmd_init_params *params,
397  const char *args);
398 
413 struct rte_cryptodev *
414 rte_cryptodev_pmd_create(const char *name,
415  struct rte_device *device,
416  struct rte_cryptodev_pmd_init_params *params);
417 
430 int
431 rte_cryptodev_pmd_destroy(struct rte_cryptodev *cryptodev);
432 
444  enum rte_cryptodev_event_type event);
445 
450 int
451 rte_cryptodev_pmd_create_dev_name(char *name, const char *dev_name_prefix);
452 
465 uint8_t rte_cryptodev_allocate_driver(struct cryptodev_driver *crypto_drv,
466  const struct rte_driver *drv);
467 
468 
469 #define RTE_PMD_REGISTER_CRYPTO_DRIVER(crypto_drv, drv, driver_id)\
470 RTE_INIT(init_ ##driver_id)\
471 {\
472  driver_id = rte_cryptodev_allocate_driver(&crypto_drv, &(drv));\
473 }
474 
475 static inline void *
476 get_sym_session_private_data(const struct rte_cryptodev_sym_session *sess,
477  uint8_t driver_id) {
478  if (unlikely(sess->nb_drivers <= driver_id))
479  return NULL;
480 
481  return sess->sess_data[driver_id].data;
482 }
483 
484 static inline void
485 set_sym_session_private_data(struct rte_cryptodev_sym_session *sess,
486  uint8_t driver_id, void *private_data)
487 {
488  if (unlikely(sess->nb_drivers <= driver_id)) {
489  CDEV_LOG_ERR("Set private data for driver %u not allowed\n",
490  driver_id);
491  return;
492  }
493 
494  sess->sess_data[driver_id].data = private_data;
495 }
496 
497 static inline void *
498 get_asym_session_private_data(const struct rte_cryptodev_asym_session *sess,
499  uint8_t driver_id) {
500  return sess->sess_private_data[driver_id];
501 }
502 
503 static inline void
504 set_asym_session_private_data(struct rte_cryptodev_asym_session *sess,
505  uint8_t driver_id, void *private_data)
506 {
507  sess->sess_private_data[driver_id] = private_data;
508 }
509 
510 #ifdef __cplusplus
511 }
512 #endif
513 
514 #endif /* _RTE_CRYPTODEV_PMD_H_ */