DPDK  20.11.0
rte_cryptodev_pmd.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2020 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  NULL
46 };
47 
52 struct rte_cryptodev_pmd_init_params {
53  char name[RTE_CRYPTODEV_NAME_MAX_LEN];
54  size_t private_data_size;
55  int socket_id;
56  unsigned int max_nb_queue_pairs;
57 };
58 
61  struct rte_cryptodev *devs;
62  struct rte_cryptodev_data *data[RTE_CRYPTO_MAX_DEVS];
64  uint8_t nb_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 *
96 
105 unsigned int
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 
224  struct rte_cryptodev *dev, unsigned nb_objs,
225  unsigned obj_cache_size, int socket_id);
226 
227 
238  struct rte_cryptodev *dev);
249  struct rte_cryptodev *dev);
250 
266  struct rte_crypto_sym_xform *xform,
267  struct rte_cryptodev_sym_session *session,
268  struct rte_mempool *mp);
284  struct rte_crypto_asym_xform *xform,
285  struct rte_cryptodev_asym_session *session,
286  struct rte_mempool *mp);
293 typedef void (*cryptodev_sym_free_session_t)(struct rte_cryptodev *dev,
294  struct rte_cryptodev_sym_session *sess);
301 typedef void (*cryptodev_asym_free_session_t)(struct rte_cryptodev *dev,
302  struct rte_cryptodev_asym_session *sess);
317  (struct rte_cryptodev *dev, struct rte_cryptodev_sym_session *sess,
318  union rte_crypto_sym_ofs ofs, struct rte_crypto_sym_vec *vec);
319 
330 
352  struct rte_cryptodev *dev, uint16_t qp_id,
353  struct rte_crypto_raw_dp_ctx *ctx,
354  enum rte_crypto_op_sess_type sess_type,
355  union rte_cryptodev_session_ctx session_ctx, uint8_t is_update);
356 
388  union {
391  __extension__
392  struct {
399  };
400  };
401 };
402 
403 
415 struct rte_cryptodev *
416 rte_cryptodev_pmd_allocate(const char *name, int socket_id);
417 
428 extern int
430 
431 
449 int
450 rte_cryptodev_pmd_parse_input_args(
451  struct rte_cryptodev_pmd_init_params *params,
452  const char *args);
453 
468 struct rte_cryptodev *
469 rte_cryptodev_pmd_create(const char *name,
470  struct rte_device *device,
471  struct rte_cryptodev_pmd_init_params *params);
472 
485 int
486 rte_cryptodev_pmd_destroy(struct rte_cryptodev *cryptodev);
487 
499  enum rte_cryptodev_event_type event);
500 
505 int
506 rte_cryptodev_pmd_create_dev_name(char *name, const char *dev_name_prefix);
507 
520 uint8_t rte_cryptodev_allocate_driver(struct cryptodev_driver *crypto_drv,
521  const struct rte_driver *drv);
522 
523 
524 #define RTE_PMD_REGISTER_CRYPTO_DRIVER(crypto_drv, drv, driver_id)\
525 RTE_INIT(init_ ##driver_id)\
526 {\
527  driver_id = rte_cryptodev_allocate_driver(&crypto_drv, &(drv));\
528 }
529 
530 static inline void *
531 get_sym_session_private_data(const struct rte_cryptodev_sym_session *sess,
532  uint8_t driver_id) {
533  if (unlikely(sess->nb_drivers <= driver_id))
534  return NULL;
535 
536  return sess->sess_data[driver_id].data;
537 }
538 
539 static inline void
540 set_sym_session_private_data(struct rte_cryptodev_sym_session *sess,
541  uint8_t driver_id, void *private_data)
542 {
543  if (unlikely(sess->nb_drivers <= driver_id)) {
544  CDEV_LOG_ERR("Set private data for driver %u not allowed\n",
545  driver_id);
546  return;
547  }
548 
549  sess->sess_data[driver_id].data = private_data;
550 }
551 
552 static inline void *
553 get_asym_session_private_data(const struct rte_cryptodev_asym_session *sess,
554  uint8_t driver_id) {
555  return sess->sess_private_data[driver_id];
556 }
557 
558 static inline void
559 set_asym_session_private_data(struct rte_cryptodev_asym_session *sess,
560  uint8_t driver_id, void *private_data)
561 {
562  sess->sess_private_data[driver_id] = private_data;
563 }
564 
565 #ifdef __cplusplus
566 }
567 #endif
568 
569 #endif /* _RTE_CRYPTODEV_PMD_H_ */
cryptodev_sym_free_session_t
void(* cryptodev_sym_free_session_t)(struct rte_cryptodev *dev, struct rte_cryptodev_sym_session *sess)
Definition: rte_cryptodev_pmd.h:293
cryptodev_info_get_t
void(* cryptodev_info_get_t)(struct rte_cryptodev *dev, struct rte_cryptodev_info *dev_info)
Definition: rte_cryptodev_pmd.h:181
rte_cryptodev_ops::queue_pair_setup
cryptodev_queue_pair_setup_t queue_pair_setup
Definition: rte_cryptodev_pmd.h:371
rte_crypto_raw_dp_ctx
Definition: rte_cryptodev.h:1517
cryptodev_sym_configure_raw_dp_ctx_t
int(* cryptodev_sym_configure_raw_dp_ctx_t)(struct rte_cryptodev *dev, uint16_t qp_id, struct rte_crypto_raw_dp_ctx *ctx, enum rte_crypto_op_sess_type sess_type, union rte_cryptodev_session_ctx session_ctx, uint8_t is_update)
Definition: rte_cryptodev_pmd.h:351
rte_cryptodev_info
Definition: rte_cryptodev.h:477
rte_driver
Definition: rte_dev.h:77
rte_cryptodev_pmd_release_device
int rte_cryptodev_pmd_release_device(struct rte_cryptodev *cryptodev)
cryptodev_stop_t
void(* cryptodev_stop_t)(struct rte_cryptodev *dev)
Definition: rte_cryptodev_pmd.h:145
rte_cryptodev_ops::asym_session_get_size
cryptodev_asym_get_session_private_size_t asym_session_get_size
Definition: rte_cryptodev_pmd.h:378
rte_malloc.h
rte_cryptodev_ops::queue_pair_release
cryptodev_queue_pair_release_t queue_pair_release
Definition: rte_cryptodev_pmd.h:373
rte_crypto_sym_ofs
Definition: rte_crypto_sym.h:98
unlikely
#define unlikely(x)
Definition: rte_branch_prediction.h:38
rte_crypto.h
rte_cryptodev
Definition: rte_cryptodev.h:843
rte_cryptodev_ops::dev_configure
cryptodev_configure_t dev_configure
Definition: rte_cryptodev_pmd.h:359
rte_cryptodev_global::nb_devs
uint8_t nb_devs
Definition: rte_cryptodev_pmd.h:64
rte_log.h
cryptodev_asym_free_session_t
void(* cryptodev_asym_free_session_t)(struct rte_cryptodev *dev, struct rte_cryptodev_asym_session *sess)
Definition: rte_cryptodev_pmd.h:301
rte_cryptodev_sym_session::nb_drivers
uint16_t nb_drivers
Definition: rte_cryptodev.h:1005
rte_cryptodev_global::data
struct rte_cryptodev_data * data[RTE_CRYPTO_MAX_DEVS]
Definition: rte_cryptodev_pmd.h:62
RTE_CRYPTODEV_NAME_MAX_LEN
#define RTE_CRYPTODEV_NAME_MAX_LEN
Definition: rte_cryptodev.h:551
rte_cryptodev.h
rte_crypto_op_sess_type
rte_crypto_op_sess_type
Definition: rte_crypto.h:62
rte_cryptodev_ops::dev_close
cryptodev_close_t dev_close
Definition: rte_cryptodev_pmd.h:362
rte_cryptodev_ops::stats_get
cryptodev_stats_get_t stats_get
Definition: rte_cryptodev_pmd.h:366
rte_cryptodev_qp_conf
Definition: rte_cryptodev.h:517
rte_cryptodev_ops::asym_session_clear
cryptodev_asym_free_session_t asym_session_clear
Definition: rte_cryptodev_pmd.h:386
rte_cryptodev_ops::sym_get_raw_dp_ctx_size
cryptodev_sym_get_raw_dp_ctx_size_t sym_get_raw_dp_ctx_size
Definition: rte_cryptodev_pmd.h:394
cryptodev_sym_configure_session_t
int(* cryptodev_sym_configure_session_t)(struct rte_cryptodev *dev, struct rte_crypto_sym_xform *xform, struct rte_cryptodev_sym_session *session, struct rte_mempool *mp)
Definition: rte_cryptodev_pmd.h:265
rte_cryptodev_pmd_callback_process
void rte_cryptodev_pmd_callback_process(struct rte_cryptodev *dev, enum rte_cryptodev_event_type event)
rte_cryptodev_ops::stats_reset
cryptodev_stats_reset_t stats_reset
Definition: rte_cryptodev_pmd.h:368
rte_cryptodev_global::devs
struct rte_cryptodev * devs
Definition: rte_cryptodev_pmd.h:61
rte_crypto_sym_vec
Definition: rte_crypto_sym.h:68
rte_cryptodev_global
Definition: rte_cryptodev_pmd.h:60
cryptodev_sym_cpu_crypto_process_t
uint32_t(* cryptodev_sym_cpu_crypto_process_t)(struct rte_cryptodev *dev, struct rte_cryptodev_sym_session *sess, union rte_crypto_sym_ofs ofs, struct rte_crypto_sym_vec *vec)
Definition: rte_cryptodev_pmd.h:317
rte_cryptodev_pmd_allocate
struct rte_cryptodev * rte_cryptodev_pmd_allocate(const char *name, int socket_id)
rte_cryptodev_pmd_is_valid_dev
unsigned int rte_cryptodev_pmd_is_valid_dev(uint8_t dev_id)
rte_cryptodev_event_type
rte_cryptodev_event_type
Definition: rte_cryptodev.h:510
rte_cryptodev_pmd_get_named_dev
struct rte_cryptodev * rte_cryptodev_pmd_get_named_dev(const char *name)
rte_common.h
cryptodev_queue_pair_setup_t
int(* cryptodev_queue_pair_setup_t)(struct rte_cryptodev *dev, uint16_t qp_id, const struct rte_cryptodev_qp_conf *qp_conf, int socket_id)
Definition: rte_cryptodev_pmd.h:194
rte_cryptodev_pmd_get_dev
struct rte_cryptodev * rte_cryptodev_pmd_get_dev(uint8_t dev_id)
cryptodev_close_t
int(* cryptodev_close_t)(struct rte_cryptodev *dev)
Definition: rte_cryptodev_pmd.h:155
cryptodev_configure_t
int(* cryptodev_configure_t)(struct rte_cryptodev *dev, struct rte_cryptodev_config *config)
Definition: rte_cryptodev_pmd.h:128
rte_cryptodev_asym_session
Definition: rte_cryptodev.h:1017
rte_cryptodev_ops::dev_infos_get
cryptodev_info_get_t dev_infos_get
Definition: rte_cryptodev_pmd.h:364
rte_crypto_sym_xform
Definition: rte_crypto_sym.h:543
rte_cryptodev_ops::dev_start
cryptodev_start_t dev_start
Definition: rte_cryptodev_pmd.h:360
rte_cryptodev_sym_session::sess_data
__extension__ struct rte_cryptodev_sym_session::@146 sess_data[0]
rte_mempool
Definition: rte_mempool.h:207
rte_cryptodev::device
struct rte_device * device
Definition: rte_cryptodev.h:855
rte_cryptodev_ops::asym_session_configure
cryptodev_asym_configure_session_t asym_session_configure
Definition: rte_cryptodev_pmd.h:382
cryptodev_queue_pair_release_t
int(* cryptodev_queue_pair_release_t)(struct rte_cryptodev *dev, uint16_t qp_id)
Definition: rte_cryptodev_pmd.h:208
rte_cryptodev_sym_session
Definition: rte_cryptodev.h:1002
cryptodev_sym_get_session_private_size_t
unsigned(* cryptodev_sym_get_session_private_size_t)(struct rte_cryptodev *dev)
Definition: rte_cryptodev_pmd.h:237
rte_mempool.h
cryptodev_stats_get_t
void(* cryptodev_stats_get_t)(struct rte_cryptodev *dev, struct rte_cryptodev_stats *stats)
Definition: rte_cryptodev_pmd.h:164
rte_cryptodev_ops::sym_cpu_process
cryptodev_sym_cpu_crypto_process_t sym_cpu_process
Definition: rte_cryptodev_pmd.h:389
cryptodev_stats_reset_t
void(* cryptodev_stats_reset_t)(struct rte_cryptodev *dev)
Definition: rte_cryptodev_pmd.h:173
rte_cryptodev_stats
Definition: rte_cryptodev.h:539
rte_mbuf.h
rte_cryptodev_ops::sym_session_get_size
cryptodev_sym_get_session_private_size_t sym_session_get_size
Definition: rte_cryptodev_pmd.h:376
cryptodev_sym_get_raw_dp_ctx_size_t
int(* cryptodev_sym_get_raw_dp_ctx_size_t)(struct rte_cryptodev *dev)
Definition: rte_cryptodev_pmd.h:329
cryptodev_asym_configure_session_t
int(* cryptodev_asym_configure_session_t)(struct rte_cryptodev *dev, struct rte_crypto_asym_xform *xform, struct rte_cryptodev_asym_session *session, struct rte_mempool *mp)
Definition: rte_cryptodev_pmd.h:283
rte_cryptodevs
struct rte_cryptodev * rte_cryptodevs
rte_cryptodev_ops::dev_stop
cryptodev_stop_t dev_stop
Definition: rte_cryptodev_pmd.h:361
rte_cryptodev_ops::sym_configure_raw_dp_ctx
cryptodev_sym_configure_raw_dp_ctx_t sym_configure_raw_dp_ctx
Definition: rte_cryptodev_pmd.h:397
cryptodev_start_t
int(* cryptodev_start_t)(struct rte_cryptodev *dev)
Definition: rte_cryptodev_pmd.h:138
cryptodev_sym_create_session_pool_t
int(* cryptodev_sym_create_session_pool_t)(struct rte_cryptodev *dev, unsigned nb_objs, unsigned obj_cache_size, int socket_id)
Definition: rte_cryptodev_pmd.h:223
rte_cryptodev_ops::sym_session_clear
cryptodev_sym_free_session_t sym_session_clear
Definition: rte_cryptodev_pmd.h:384
rte_cryptodev_ops
Definition: rte_cryptodev_pmd.h:358
rte_device
Definition: rte_dev.h:92
rte_cryptodev_ops::sym_session_configure
cryptodev_sym_configure_session_t sym_session_configure
Definition: rte_cryptodev_pmd.h:380
rte_cryptodev_session_ctx
Definition: rte_cryptodev.h:1340
rte_cryptodev_config
Definition: rte_cryptodev.h:628
rte_crypto_asym_xform
Definition: rte_crypto_asym.h:400
rte_cryptodev_data
Definition: rte_cryptodev.h:882
rte_cryptodev::driver_id
uint8_t driver_id
Definition: rte_cryptodev.h:858
cryptodev_asym_get_session_private_size_t
unsigned int(* cryptodev_asym_get_session_private_size_t)(struct rte_cryptodev *dev)
Definition: rte_cryptodev_pmd.h:248
rte_cryptodev_asym_session::sess_private_data
__extension__ void * sess_private_data[0]
Definition: rte_cryptodev.h:1018
rte_dev.h