1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2020 Intel Corporation.
5 #ifndef _CRYPTODEV_PMD_H_
6 #define _CRYPTODEV_PMD_H_
12 * These API are from crypto PMD only and user applications should not call
18 #include <rte_config.h>
20 #include <rte_malloc.h>
22 #include <rte_mempool.h>
24 #include <rte_common.h>
26 #include "rte_crypto.h"
27 #include "rte_cryptodev.h"
30 #define RTE_CRYPTODEV_PMD_DEFAULT_MAX_NB_QUEUE_PAIRS 8
32 #define RTE_CRYPTODEV_PMD_NAME_ARG ("name")
33 #define RTE_CRYPTODEV_PMD_MAX_NB_QP_ARG ("max_nb_queue_pairs")
34 #define RTE_CRYPTODEV_PMD_SOCKET_ID_ARG ("socket_id")
37 static const char * const cryptodev_pmd_valid_params[] = {
38 RTE_CRYPTODEV_PMD_NAME_ARG,
39 RTE_CRYPTODEV_PMD_MAX_NB_QP_ARG,
40 RTE_CRYPTODEV_PMD_SOCKET_ID_ARG,
46 * Initialisation parameters for crypto devices
48 struct rte_cryptodev_pmd_init_params {
49 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
50 size_t private_data_size;
52 unsigned int max_nb_queue_pairs;
55 /** Global structure used for maintaining state of allocated crypto devices */
56 struct rte_cryptodev_global {
57 struct rte_cryptodev *devs; /**< Device information array */
58 struct rte_cryptodev_data *data[RTE_CRYPTO_MAX_DEVS];
59 /**< Device private data */
60 uint8_t nb_devs; /**< Number of devices found */
63 /* Cryptodev driver, containing the driver ID */
64 struct cryptodev_driver {
65 RTE_TAILQ_ENTRY(cryptodev_driver) next; /**< Next in list. */
66 const struct rte_driver *driver;
71 * Get the rte_cryptodev structure device pointer for the device. Assumes a
74 * @param dev_id Device ID value to select the device structure.
77 * - The rte_cryptodev structure pointer for the given device ID.
80 struct rte_cryptodev *
81 rte_cryptodev_pmd_get_dev(uint8_t dev_id);
84 * Get the rte_cryptodev structure device pointer for the named device.
86 * @param name device name to select the device structure.
89 * - The rte_cryptodev structure pointer for the given device ID.
92 struct rte_cryptodev *
93 rte_cryptodev_pmd_get_named_dev(const char *name);
96 * The pool of rte_cryptodev structures.
98 extern struct rte_cryptodev *rte_cryptodevs;
102 * Definitions of all functions exported by a driver through the
103 * the generic structure of type *crypto_dev_ops* supplied in the
104 * *rte_cryptodev* structure associated with a device.
108 * Function used to configure device.
110 * @param dev Crypto device pointer
111 * @param config Crypto device configurations
113 * @return Returns 0 on success
115 typedef int (*cryptodev_configure_t)(struct rte_cryptodev *dev,
116 struct rte_cryptodev_config *config);
119 * Function used to start a configured device.
121 * @param dev Crypto device pointer
123 * @return Returns 0 on success
125 typedef int (*cryptodev_start_t)(struct rte_cryptodev *dev);
128 * Function used to stop a configured device.
130 * @param dev Crypto device pointer
132 typedef void (*cryptodev_stop_t)(struct rte_cryptodev *dev);
135 * Function used to close a configured device.
137 * @param dev Crypto device pointer
140 * - EAGAIN if can't close as device is busy
142 typedef int (*cryptodev_close_t)(struct rte_cryptodev *dev);
146 * Function used to get statistics of a device.
148 * @param dev Crypto device pointer
149 * @param stats Pointer to crypto device stats structure to populate
151 typedef void (*cryptodev_stats_get_t)(struct rte_cryptodev *dev,
152 struct rte_cryptodev_stats *stats);
156 * Function used to reset statistics of a device.
158 * @param dev Crypto device pointer
160 typedef void (*cryptodev_stats_reset_t)(struct rte_cryptodev *dev);
164 * Function used to get specific information of a device.
166 * @param dev Crypto device pointer
167 * @param dev_info Pointer to infos structure to populate
169 typedef void (*cryptodev_info_get_t)(struct rte_cryptodev *dev,
170 struct rte_cryptodev_info *dev_info);
173 * Setup a queue pair for a device.
175 * @param dev Crypto device pointer
176 * @param qp_id Queue Pair Index
177 * @param qp_conf Queue configuration structure
178 * @param socket_id Socket Index
180 * @return Returns 0 on success.
182 typedef int (*cryptodev_queue_pair_setup_t)(struct rte_cryptodev *dev,
183 uint16_t qp_id, const struct rte_cryptodev_qp_conf *qp_conf,
187 * Release memory resources allocated by given queue pair.
189 * @param dev Crypto device pointer
190 * @param qp_id Queue Pair Index
194 * - EAGAIN if can't close as device is busy
196 typedef int (*cryptodev_queue_pair_release_t)(struct rte_cryptodev *dev,
200 * Create a session mempool to allocate sessions from
202 * @param dev Crypto device pointer
203 * @param nb_objs number of sessions objects in mempool
204 * @param obj_cache_size l-core object cache size, see *rte_ring_create*
205 * @param socket_id Socket Id to allocate mempool on.
208 * - On success returns a pointer to a rte_mempool
209 * - On failure returns a NULL pointer
211 typedef int (*cryptodev_sym_create_session_pool_t)(
212 struct rte_cryptodev *dev, unsigned nb_objs,
213 unsigned obj_cache_size, int socket_id);
217 * Get the size of a cryptodev session
219 * @param dev Crypto device pointer
222 * - On success returns the size of the session structure for device
223 * - On failure returns 0
225 typedef unsigned (*cryptodev_sym_get_session_private_size_t)(
226 struct rte_cryptodev *dev);
228 * Get the size of a asymmetric cryptodev session
230 * @param dev Crypto device pointer
233 * - On success returns the size of the session structure for device
234 * - On failure returns 0
236 typedef unsigned int (*cryptodev_asym_get_session_private_size_t)(
237 struct rte_cryptodev *dev);
240 * Configure a Crypto session on a device.
242 * @param dev Crypto device pointer
243 * @param xform Single or chain of crypto xforms
244 * @param session Pointer to cryptodev's private session structure
245 * @param mp Mempool where the private session is allocated
248 * - Returns 0 if private session structure have been created successfully.
249 * - Returns -EINVAL if input parameters are invalid.
250 * - Returns -ENOTSUP if crypto device does not support the crypto transform.
251 * - Returns -ENOMEM if the private session could not be allocated.
253 typedef int (*cryptodev_sym_configure_session_t)(struct rte_cryptodev *dev,
254 struct rte_crypto_sym_xform *xform,
255 struct rte_cryptodev_sym_session *session,
256 struct rte_mempool *mp);
258 * Configure a Crypto asymmetric session on a device.
260 * @param dev Crypto device pointer
261 * @param xform Single or chain of crypto xforms
262 * @param session Pointer to cryptodev's private session structure
263 * @param mp Mempool where the private session is allocated
266 * - Returns 0 if private session structure have been created successfully.
267 * - Returns -EINVAL if input parameters are invalid.
268 * - Returns -ENOTSUP if crypto device does not support the crypto transform.
269 * - Returns -ENOMEM if the private session could not be allocated.
271 typedef int (*cryptodev_asym_configure_session_t)(struct rte_cryptodev *dev,
272 struct rte_crypto_asym_xform *xform,
273 struct rte_cryptodev_asym_session *session,
274 struct rte_mempool *mp);
276 * Free driver private session data.
278 * @param dev Crypto device pointer
279 * @param sess Cryptodev session structure
281 typedef void (*cryptodev_sym_free_session_t)(struct rte_cryptodev *dev,
282 struct rte_cryptodev_sym_session *sess);
284 * Free asymmetric session private data.
286 * @param dev Crypto device pointer
287 * @param sess Cryptodev session structure
289 typedef void (*cryptodev_asym_free_session_t)(struct rte_cryptodev *dev,
290 struct rte_cryptodev_asym_session *sess);
292 * Perform actual crypto processing (encrypt/digest or auth/decrypt)
293 * on user provided data.
295 * @param dev Crypto device pointer
296 * @param sess Cryptodev session structure
297 * @param ofs Start and stop offsets for auth and cipher operations
298 * @param vec Vectorized operation descriptor
301 * - Returns number of successfully processed packets.
304 typedef uint32_t (*cryptodev_sym_cpu_crypto_process_t)
305 (struct rte_cryptodev *dev, struct rte_cryptodev_sym_session *sess,
306 union rte_crypto_sym_ofs ofs, struct rte_crypto_sym_vec *vec);
309 * Typedef that the driver provided to get service context private date size.
311 * @param dev Crypto device pointer.
314 * - On success return the size of the device's service context private data.
315 * - On failure return negative integer.
317 typedef int (*cryptodev_sym_get_raw_dp_ctx_size_t)(struct rte_cryptodev *dev);
320 * Typedef that the driver provided to configure raw data-path context.
322 * @param dev Crypto device pointer.
323 * @param qp_id Crypto device queue pair index.
324 * @param ctx The raw data-path context data.
325 * @param sess_type session type.
326 * @param session_ctx Session context data. If NULL the driver
327 * shall only configure the drv_ctx_data in
328 * ctx buffer. Otherwise the driver shall only
329 * parse the session_ctx to set appropriate
330 * function pointers in ctx.
331 * @param is_update Set 0 if it is to initialize the ctx.
332 * Set 1 if ctx is initialized and only to update
333 * session context data.
335 * - On success return 0.
336 * - On failure return negative integer.
338 typedef int (*cryptodev_sym_configure_raw_dp_ctx_t)(
339 struct rte_cryptodev *dev, uint16_t qp_id,
340 struct rte_crypto_raw_dp_ctx *ctx,
341 enum rte_crypto_op_sess_type sess_type,
342 union rte_cryptodev_session_ctx session_ctx, uint8_t is_update);
344 /** Crypto device operations function pointer table */
345 struct rte_cryptodev_ops {
346 cryptodev_configure_t dev_configure; /**< Configure device. */
347 cryptodev_start_t dev_start; /**< Start device. */
348 cryptodev_stop_t dev_stop; /**< Stop device. */
349 cryptodev_close_t dev_close; /**< Close device. */
351 cryptodev_info_get_t dev_infos_get; /**< Get device info. */
353 cryptodev_stats_get_t stats_get;
354 /**< Get device statistics. */
355 cryptodev_stats_reset_t stats_reset;
356 /**< Reset device statistics. */
358 cryptodev_queue_pair_setup_t queue_pair_setup;
359 /**< Set up a device queue pair. */
360 cryptodev_queue_pair_release_t queue_pair_release;
361 /**< Release a queue pair. */
363 cryptodev_sym_get_session_private_size_t sym_session_get_size;
364 /**< Return private session. */
365 cryptodev_asym_get_session_private_size_t asym_session_get_size;
366 /**< Return asym session private size. */
367 cryptodev_sym_configure_session_t sym_session_configure;
368 /**< Configure a Crypto session. */
369 cryptodev_asym_configure_session_t asym_session_configure;
370 /**< Configure asymmetric Crypto session. */
371 cryptodev_sym_free_session_t sym_session_clear;
372 /**< Clear a Crypto sessions private data. */
373 cryptodev_asym_free_session_t asym_session_clear;
374 /**< Clear a Crypto sessions private data. */
376 cryptodev_sym_cpu_crypto_process_t sym_cpu_process;
377 /**< process input data synchronously (cpu-crypto). */
380 cryptodev_sym_get_raw_dp_ctx_size_t
381 sym_get_raw_dp_ctx_size;
382 /**< Get raw data path service context data size. */
383 cryptodev_sym_configure_raw_dp_ctx_t
384 sym_configure_raw_dp_ctx;
385 /**< Initialize raw data path context data. */
392 * Function for internal use by dummy drivers primarily, e.g. ring-based
394 * Allocates a new cryptodev slot for an crypto device and returns the pointer
395 * to that slot for the driver to use.
397 * @param name Unique identifier name for each device
398 * @param socket_id Socket to allocate resources on.
400 * - Slot in the rte_dev_devices array for a new device;
403 struct rte_cryptodev *
404 rte_cryptodev_pmd_allocate(const char *name, int socket_id);
407 * Function for internal use by dummy drivers primarily, e.g. ring-based
409 * Release the specified cryptodev device.
412 * The *cryptodev* pointer is the address of the *rte_cryptodev* structure.
414 * - 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
440 rte_cryptodev_pmd_parse_input_args(
441 struct rte_cryptodev_pmd_init_params *params,
447 * PMD assist function to provide boiler plate code for crypto driver to create
448 * and allocate resources for a new crypto PMD device instance.
450 * @param name crypto device name.
451 * @param device base device instance
452 * @param params PMD initialisation parameters
455 * - crypto device instance on success
456 * - NULL on creation failure
459 struct rte_cryptodev *
460 rte_cryptodev_pmd_create(const char *name,
461 struct rte_device *device,
462 struct rte_cryptodev_pmd_init_params *params);
467 * PMD assist function to provide boiler plate code for crypto driver to
468 * destroy and free resources associated with a crypto PMD device instance.
470 * @param cryptodev crypto device handle.
478 rte_cryptodev_pmd_destroy(struct rte_cryptodev *cryptodev);
481 * Executes all the user application registered callbacks for the specific
484 * @param dev Pointer to cryptodev struct
485 * @param event Crypto device interrupt event type.
491 void rte_cryptodev_pmd_callback_process(struct rte_cryptodev *dev,
492 enum rte_cryptodev_event_type event);
496 * Create unique device name
500 rte_cryptodev_pmd_create_dev_name(char *name, const char *dev_name_prefix);
504 * Allocate Cryptodev driver.
507 * Pointer to cryptodev_driver.
509 * Pointer to rte_driver.
512 * The driver type identifier
515 uint8_t rte_cryptodev_allocate_driver(struct cryptodev_driver *crypto_drv,
516 const struct rte_driver *drv);
519 #define RTE_PMD_REGISTER_CRYPTO_DRIVER(crypto_drv, drv, driver_id)\
520 RTE_INIT(init_ ##driver_id)\
522 driver_id = rte_cryptodev_allocate_driver(&crypto_drv, &(drv));\
526 get_sym_session_private_data(const struct rte_cryptodev_sym_session *sess,
528 if (unlikely(sess->nb_drivers <= driver_id))
531 return sess->sess_data[driver_id].data;
535 set_sym_session_private_data(struct rte_cryptodev_sym_session *sess,
536 uint8_t driver_id, void *private_data)
538 if (unlikely(sess->nb_drivers <= driver_id)) {
539 CDEV_LOG_ERR("Set private data for driver %u not allowed\n",
544 sess->sess_data[driver_id].data = private_data;
548 get_asym_session_private_data(const struct rte_cryptodev_asym_session *sess,
550 return sess->sess_private_data[driver_id];
554 set_asym_session_private_data(struct rte_cryptodev_asym_session *sess,
555 uint8_t driver_id, void *private_data)
557 sess->sess_private_data[driver_id] = private_data;
560 #endif /* _CRYPTODEV_PMD_H_ */