1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2020 Intel Corporation.
5 #ifndef _RTE_CRYPTODEV_PMD_H_
6 #define _RTE_CRYPTODEV_PMD_H_
12 * These API are from crypto PMD only and user applications should not call
22 #include <rte_config.h>
24 #include <rte_malloc.h>
26 #include <rte_mempool.h>
28 #include <rte_common.h>
30 #include "rte_crypto.h"
31 #include "rte_cryptodev.h"
34 #define RTE_CRYPTODEV_PMD_DEFAULT_MAX_NB_QUEUE_PAIRS 8
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")
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,
50 * Initialisation parameters for crypto devices
52 struct rte_cryptodev_pmd_init_params {
53 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
54 size_t private_data_size;
56 unsigned int max_nb_queue_pairs;
59 /** Global structure used for maintaining state of allocated crypto devices */
60 struct rte_cryptodev_global {
61 struct rte_cryptodev *devs; /**< Device information array */
62 struct rte_cryptodev_data *data[RTE_CRYPTO_MAX_DEVS];
63 /**< Device private data */
64 uint8_t nb_devs; /**< Number of devices found */
67 /* Cryptodev driver, containing the driver ID */
68 struct cryptodev_driver {
69 TAILQ_ENTRY(cryptodev_driver) next; /**< Next in list. */
70 const struct rte_driver *driver;
75 * Get the rte_cryptodev structure device pointer for the device. Assumes a
78 * @param dev_id Device ID value to select the device structure.
81 * - The rte_cryptodev structure pointer for the given device ID.
83 struct rte_cryptodev *
84 rte_cryptodev_pmd_get_dev(uint8_t dev_id);
87 * Get the rte_cryptodev structure device pointer for the named device.
89 * @param name device name to select the device structure.
92 * - The rte_cryptodev structure pointer for the given device ID.
94 struct rte_cryptodev *
95 rte_cryptodev_pmd_get_named_dev(const char *name);
98 * The pool of rte_cryptodev structures.
100 extern struct rte_cryptodev *rte_cryptodevs;
104 * Definitions of all functions exported by a driver through the
105 * the generic structure of type *crypto_dev_ops* supplied in the
106 * *rte_cryptodev* structure associated with a device.
110 * Function used to configure device.
112 * @param dev Crypto device pointer
113 * @param config Crypto device configurations
115 * @return Returns 0 on success
117 typedef int (*cryptodev_configure_t)(struct rte_cryptodev *dev,
118 struct rte_cryptodev_config *config);
121 * Function used to start a configured device.
123 * @param dev Crypto device pointer
125 * @return Returns 0 on success
127 typedef int (*cryptodev_start_t)(struct rte_cryptodev *dev);
130 * Function used to stop a configured device.
132 * @param dev Crypto device pointer
134 typedef void (*cryptodev_stop_t)(struct rte_cryptodev *dev);
137 * Function used to close a configured device.
139 * @param dev Crypto device pointer
142 * - EAGAIN if can't close as device is busy
144 typedef int (*cryptodev_close_t)(struct rte_cryptodev *dev);
148 * Function used to get statistics of a device.
150 * @param dev Crypto device pointer
151 * @param stats Pointer to crypto device stats structure to populate
153 typedef void (*cryptodev_stats_get_t)(struct rte_cryptodev *dev,
154 struct rte_cryptodev_stats *stats);
158 * Function used to reset statistics of a device.
160 * @param dev Crypto device pointer
162 typedef void (*cryptodev_stats_reset_t)(struct rte_cryptodev *dev);
166 * Function used to get specific information of a device.
168 * @param dev Crypto device pointer
169 * @param dev_info Pointer to infos structure to populate
171 typedef void (*cryptodev_info_get_t)(struct rte_cryptodev *dev,
172 struct rte_cryptodev_info *dev_info);
175 * Setup a queue pair for a device.
177 * @param dev Crypto device pointer
178 * @param qp_id Queue Pair Index
179 * @param qp_conf Queue configuration structure
180 * @param socket_id Socket Index
182 * @return Returns 0 on success.
184 typedef int (*cryptodev_queue_pair_setup_t)(struct rte_cryptodev *dev,
185 uint16_t qp_id, const struct rte_cryptodev_qp_conf *qp_conf,
189 * Release memory resources allocated by given queue pair.
191 * @param dev Crypto device pointer
192 * @param qp_id Queue Pair Index
196 * - EAGAIN if can't close as device is busy
198 typedef int (*cryptodev_queue_pair_release_t)(struct rte_cryptodev *dev,
202 * Create a session mempool to allocate sessions from
204 * @param dev Crypto device pointer
205 * @param nb_objs number of sessions objects in mempool
206 * @param obj_cache_size l-core object cache size, see *rte_ring_create*
207 * @param socket_id Socket Id to allocate mempool on.
210 * - On success returns a pointer to a rte_mempool
211 * - On failure returns a NULL pointer
213 typedef int (*cryptodev_sym_create_session_pool_t)(
214 struct rte_cryptodev *dev, unsigned nb_objs,
215 unsigned obj_cache_size, int socket_id);
219 * Get the size of a cryptodev session
221 * @param dev Crypto device pointer
224 * - On success returns the size of the session structure for device
225 * - On failure returns 0
227 typedef unsigned (*cryptodev_sym_get_session_private_size_t)(
228 struct rte_cryptodev *dev);
230 * Get the size of a asymmetric cryptodev session
232 * @param dev Crypto device pointer
235 * - On success returns the size of the session structure for device
236 * - On failure returns 0
238 typedef unsigned int (*cryptodev_asym_get_session_private_size_t)(
239 struct rte_cryptodev *dev);
242 * Configure a Crypto session on a device.
244 * @param dev Crypto device pointer
245 * @param xform Single or chain of crypto xforms
246 * @param session Pointer to cryptodev's private session structure
247 * @param mp Mempool where the private session is allocated
250 * - Returns 0 if private session structure have been created successfully.
251 * - Returns -EINVAL if input parameters are invalid.
252 * - Returns -ENOTSUP if crypto device does not support the crypto transform.
253 * - Returns -ENOMEM if the private session could not be allocated.
255 typedef int (*cryptodev_sym_configure_session_t)(struct rte_cryptodev *dev,
256 struct rte_crypto_sym_xform *xform,
257 struct rte_cryptodev_sym_session *session,
258 struct rte_mempool *mp);
260 * Configure a Crypto asymmetric session on a device.
262 * @param dev Crypto device pointer
263 * @param xform Single or chain of crypto xforms
264 * @param session Pointer to cryptodev's private session structure
265 * @param mp Mempool where the private session is allocated
268 * - Returns 0 if private session structure have been created successfully.
269 * - Returns -EINVAL if input parameters are invalid.
270 * - Returns -ENOTSUP if crypto device does not support the crypto transform.
271 * - Returns -ENOMEM if the private session could not be allocated.
273 typedef int (*cryptodev_asym_configure_session_t)(struct rte_cryptodev *dev,
274 struct rte_crypto_asym_xform *xform,
275 struct rte_cryptodev_asym_session *session,
276 struct rte_mempool *mp);
278 * Free driver private session data.
280 * @param dev Crypto device pointer
281 * @param sess Cryptodev session structure
283 typedef void (*cryptodev_sym_free_session_t)(struct rte_cryptodev *dev,
284 struct rte_cryptodev_sym_session *sess);
286 * Free asymmetric session private data.
288 * @param dev Crypto device pointer
289 * @param sess Cryptodev session structure
291 typedef void (*cryptodev_asym_free_session_t)(struct rte_cryptodev *dev,
292 struct rte_cryptodev_asym_session *sess);
294 * Perform actual crypto processing (encrypt/digest or auth/decrypt)
295 * on user provided data.
297 * @param dev Crypto device pointer
298 * @param sess Cryptodev session structure
299 * @param ofs Start and stop offsets for auth and cipher operations
300 * @param vec Vectorized operation descriptor
303 * - Returns number of successfully processed packets.
306 typedef uint32_t (*cryptodev_sym_cpu_crypto_process_t)
307 (struct rte_cryptodev *dev, struct rte_cryptodev_sym_session *sess,
308 union rte_crypto_sym_ofs ofs, struct rte_crypto_sym_vec *vec);
311 * Typedef that the driver provided to get service context private date size.
313 * @param dev Crypto device pointer.
316 * - On success return the size of the device's service context private data.
317 * - On failure return negative integer.
319 typedef int (*cryptodev_sym_get_raw_dp_ctx_size_t)(struct rte_cryptodev *dev);
322 * Typedef that the driver provided to configure raw data-path context.
324 * @param dev Crypto device pointer.
325 * @param qp_id Crypto device queue pair index.
326 * @param ctx The raw data-path context data.
327 * @param sess_type session type.
328 * @param session_ctx Session context data. If NULL the driver
329 * shall only configure the drv_ctx_data in
330 * ctx buffer. Otherwise the driver shall only
331 * parse the session_ctx to set appropriate
332 * function pointers in ctx.
333 * @param is_update Set 0 if it is to initialize the ctx.
334 * Set 1 if ctx is initialized and only to update
335 * session context data.
337 * - On success return 0.
338 * - On failure return negative integer.
340 typedef int (*cryptodev_sym_configure_raw_dp_ctx_t)(
341 struct rte_cryptodev *dev, uint16_t qp_id,
342 struct rte_crypto_raw_dp_ctx *ctx,
343 enum rte_crypto_op_sess_type sess_type,
344 union rte_cryptodev_session_ctx session_ctx, uint8_t is_update);
346 /** Crypto device operations function pointer table */
347 struct rte_cryptodev_ops {
348 cryptodev_configure_t dev_configure; /**< Configure device. */
349 cryptodev_start_t dev_start; /**< Start device. */
350 cryptodev_stop_t dev_stop; /**< Stop device. */
351 cryptodev_close_t dev_close; /**< Close device. */
353 cryptodev_info_get_t dev_infos_get; /**< Get device info. */
355 cryptodev_stats_get_t stats_get;
356 /**< Get device statistics. */
357 cryptodev_stats_reset_t stats_reset;
358 /**< Reset device statistics. */
360 cryptodev_queue_pair_setup_t queue_pair_setup;
361 /**< Set up a device queue pair. */
362 cryptodev_queue_pair_release_t queue_pair_release;
363 /**< Release a queue pair. */
365 cryptodev_sym_get_session_private_size_t sym_session_get_size;
366 /**< Return private session. */
367 cryptodev_asym_get_session_private_size_t asym_session_get_size;
368 /**< Return asym session private size. */
369 cryptodev_sym_configure_session_t sym_session_configure;
370 /**< Configure a Crypto session. */
371 cryptodev_asym_configure_session_t asym_session_configure;
372 /**< Configure asymmetric Crypto session. */
373 cryptodev_sym_free_session_t sym_session_clear;
374 /**< Clear a Crypto sessions private data. */
375 cryptodev_asym_free_session_t asym_session_clear;
376 /**< Clear a Crypto sessions private data. */
378 cryptodev_sym_cpu_crypto_process_t sym_cpu_process;
379 /**< process input data synchronously (cpu-crypto). */
382 cryptodev_sym_get_raw_dp_ctx_size_t
383 sym_get_raw_dp_ctx_size;
384 /**< Get raw data path service context data size. */
385 cryptodev_sym_configure_raw_dp_ctx_t
386 sym_configure_raw_dp_ctx;
387 /**< Initialize raw data path context data. */
394 * Function for internal use by dummy drivers primarily, e.g. ring-based
396 * Allocates a new cryptodev slot for an crypto device and returns the pointer
397 * to that slot for the driver to use.
399 * @param name Unique identifier name for each device
400 * @param socket_id Socket to allocate resources on.
402 * - Slot in the rte_dev_devices array for a new device;
404 struct rte_cryptodev *
405 rte_cryptodev_pmd_allocate(const char *name, int socket_id);
408 * Function for internal use by dummy drivers primarily, e.g. ring-based
410 * Release the specified cryptodev device.
413 * The *cryptodev* pointer is the address of the *rte_cryptodev* structure.
415 * - 0 on success, negative on error
418 rte_cryptodev_pmd_release_device(struct rte_cryptodev *cryptodev);
424 * PMD assist function to parse initialisation arguments for crypto driver
425 * when creating a new crypto PMD device instance.
427 * PMD driver should set default values for that PMD before calling function,
428 * these default values will be over-written with successfully parsed values
431 * @param params parsed PMD initialisation parameters
432 * @param args input argument string to parse
439 rte_cryptodev_pmd_parse_input_args(
440 struct rte_cryptodev_pmd_init_params *params,
446 * PMD assist function to provide boiler plate code for crypto driver to create
447 * and allocate resources for a new crypto PMD device instance.
449 * @param name crypto device name.
450 * @param device base device instance
451 * @param params PMD initialisation parameters
454 * - crypto device instance on success
455 * - NULL on creation failure
457 struct rte_cryptodev *
458 rte_cryptodev_pmd_create(const char *name,
459 struct rte_device *device,
460 struct rte_cryptodev_pmd_init_params *params);
465 * PMD assist function to provide boiler plate code for crypto driver to
466 * destroy and free resources associated with a crypto PMD device instance.
468 * @param cryptodev crypto device handle.
475 rte_cryptodev_pmd_destroy(struct rte_cryptodev *cryptodev);
478 * Executes all the user application registered callbacks for the specific
481 * @param dev Pointer to cryptodev struct
482 * @param event Crypto device interrupt event type.
487 void rte_cryptodev_pmd_callback_process(struct rte_cryptodev *dev,
488 enum rte_cryptodev_event_type event);
492 * Create unique device name
495 rte_cryptodev_pmd_create_dev_name(char *name, const char *dev_name_prefix);
499 * Allocate Cryptodev driver.
502 * Pointer to cryptodev_driver.
504 * Pointer to rte_driver.
507 * The driver type identifier
509 uint8_t rte_cryptodev_allocate_driver(struct cryptodev_driver *crypto_drv,
510 const struct rte_driver *drv);
513 #define RTE_PMD_REGISTER_CRYPTO_DRIVER(crypto_drv, drv, driver_id)\
514 RTE_INIT(init_ ##driver_id)\
516 driver_id = rte_cryptodev_allocate_driver(&crypto_drv, &(drv));\
520 get_sym_session_private_data(const struct rte_cryptodev_sym_session *sess,
522 if (unlikely(sess->nb_drivers <= driver_id))
525 return sess->sess_data[driver_id].data;
529 set_sym_session_private_data(struct rte_cryptodev_sym_session *sess,
530 uint8_t driver_id, void *private_data)
532 if (unlikely(sess->nb_drivers <= driver_id)) {
533 CDEV_LOG_ERR("Set private data for driver %u not allowed\n",
538 sess->sess_data[driver_id].data = private_data;
542 get_asym_session_private_data(const struct rte_cryptodev_asym_session *sess,
544 return sess->sess_private_data[driver_id];
548 set_asym_session_private_data(struct rte_cryptodev_asym_session *sess,
549 uint8_t driver_id, void *private_data)
551 sess->sess_private_data[driver_id] = private_data;
558 #endif /* _RTE_CRYPTODEV_PMD_H_ */