1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2016 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
49 * Initialisation parameters for crypto devices
51 struct rte_cryptodev_pmd_init_params {
52 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
53 size_t private_data_size;
55 unsigned int max_nb_queue_pairs;
58 /** Global structure used for maintaining state of allocated crypto devices */
59 struct rte_cryptodev_global {
60 struct rte_cryptodev *devs; /**< Device information array */
61 struct rte_cryptodev_data *data[RTE_CRYPTO_MAX_DEVS];
62 /**< Device private data */
63 uint8_t nb_devs; /**< Number of devices found */
66 /* Cryptodev driver, containing the driver ID */
67 struct cryptodev_driver {
68 TAILQ_ENTRY(cryptodev_driver) next; /**< Next in list. */
69 const struct rte_driver *driver;
74 * Get the rte_cryptodev structure device pointer for the device. Assumes a
77 * @param dev_id Device ID value to select the device structure.
80 * - The rte_cryptodev structure pointer for the given device ID.
82 struct rte_cryptodev *
83 rte_cryptodev_pmd_get_dev(uint8_t dev_id);
86 * Get the rte_cryptodev structure device pointer for the named device.
88 * @param name device name to select the device structure.
91 * - The rte_cryptodev structure pointer for the given device ID.
93 struct rte_cryptodev *
94 rte_cryptodev_pmd_get_named_dev(const char *name);
97 * Validate if the crypto device index is valid attached crypto device.
99 * @param dev_id Crypto device index.
102 * - If the device index is valid (1) or not (0).
105 rte_cryptodev_pmd_is_valid_dev(uint8_t dev_id);
108 * The pool of rte_cryptodev structures.
110 extern struct rte_cryptodev *rte_cryptodevs;
114 * Definitions of all functions exported by a driver through the
115 * the generic structure of type *crypto_dev_ops* supplied in the
116 * *rte_cryptodev* structure associated with a device.
120 * Function used to configure device.
122 * @param dev Crypto device pointer
123 * config Crypto device configurations
125 * @return Returns 0 on success
127 typedef int (*cryptodev_configure_t)(struct rte_cryptodev *dev,
128 struct rte_cryptodev_config *config);
131 * Function used to start a configured device.
133 * @param dev Crypto device pointer
135 * @return Returns 0 on success
137 typedef int (*cryptodev_start_t)(struct rte_cryptodev *dev);
140 * Function used to stop a configured device.
142 * @param dev Crypto device pointer
144 typedef void (*cryptodev_stop_t)(struct rte_cryptodev *dev);
147 * Function used to close a configured device.
149 * @param dev Crypto device pointer
152 * - EAGAIN if can't close as device is busy
154 typedef int (*cryptodev_close_t)(struct rte_cryptodev *dev);
158 * Function used to get statistics of a device.
160 * @param dev Crypto device pointer
161 * @param stats Pointer to crypto device stats structure to populate
163 typedef void (*cryptodev_stats_get_t)(struct rte_cryptodev *dev,
164 struct rte_cryptodev_stats *stats);
168 * Function used to reset statistics of a device.
170 * @param dev Crypto device pointer
172 typedef void (*cryptodev_stats_reset_t)(struct rte_cryptodev *dev);
176 * Function used to get specific information of a device.
178 * @param dev Crypto device pointer
180 typedef void (*cryptodev_info_get_t)(struct rte_cryptodev *dev,
181 struct rte_cryptodev_info *dev_info);
184 * Setup a queue pair for a device.
186 * @param dev Crypto device pointer
187 * @param qp_id Queue Pair Index
188 * @param qp_conf Queue configuration structure
189 * @param socket_id Socket Index
191 * @return Returns 0 on success.
193 typedef int (*cryptodev_queue_pair_setup_t)(struct rte_cryptodev *dev,
194 uint16_t qp_id, const struct rte_cryptodev_qp_conf *qp_conf,
198 * Release memory resources allocated by given queue pair.
200 * @param dev Crypto device pointer
201 * @param qp_id Queue Pair Index
205 * - EAGAIN if can't close as device is busy
207 typedef int (*cryptodev_queue_pair_release_t)(struct rte_cryptodev *dev,
211 * Get number of available queue pairs of a device.
213 * @param dev Crypto device pointer
215 * @return Returns number of queue pairs on success.
217 typedef uint32_t (*cryptodev_queue_pair_count_t)(struct rte_cryptodev *dev);
220 * Create a session mempool to allocate sessions from
222 * @param dev Crypto device pointer
223 * @param nb_objs number of sessions objects in mempool
224 * @param obj_cache l-core object cache size, see *rte_ring_create*
225 * @param socket_id Socket Id to allocate mempool on.
228 * - On success returns a pointer to a rte_mempool
229 * - On failure returns a NULL pointer
231 typedef int (*cryptodev_sym_create_session_pool_t)(
232 struct rte_cryptodev *dev, unsigned nb_objs,
233 unsigned obj_cache_size, int socket_id);
237 * Get the size of a cryptodev session
239 * @param dev Crypto device pointer
242 * - On success returns the size of the session structure for device
243 * - On failure returns 0
245 typedef unsigned (*cryptodev_sym_get_session_private_size_t)(
246 struct rte_cryptodev *dev);
248 * Get the size of a asymmetric cryptodev session
250 * @param dev Crypto device pointer
253 * - On success returns the size of the session structure for device
254 * - On failure returns 0
256 typedef unsigned int (*cryptodev_asym_get_session_private_size_t)(
257 struct rte_cryptodev *dev);
260 * Configure a Crypto session on a device.
262 * @param dev Crypto device pointer
263 * @param xform Single or chain of crypto xforms
264 * @param priv_sess 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_sym_configure_session_t)(struct rte_cryptodev *dev,
274 struct rte_crypto_sym_xform *xform,
275 struct rte_cryptodev_sym_session *session,
276 struct rte_mempool *mp);
278 * Configure a Crypto asymmetric session on a device.
280 * @param dev Crypto device pointer
281 * @param xform Single or chain of crypto xforms
282 * @param priv_sess Pointer to cryptodev's private session structure
283 * @param mp Mempool where the private session is allocated
286 * - Returns 0 if private session structure have been created successfully.
287 * - Returns -EINVAL if input parameters are invalid.
288 * - Returns -ENOTSUP if crypto device does not support the crypto transform.
289 * - Returns -ENOMEM if the private session could not be allocated.
291 typedef int (*cryptodev_asym_configure_session_t)(struct rte_cryptodev *dev,
292 struct rte_crypto_asym_xform *xform,
293 struct rte_cryptodev_asym_session *session,
294 struct rte_mempool *mp);
296 * Free driver private session data.
298 * @param dev Crypto device pointer
299 * @param sess Cryptodev session structure
301 typedef void (*cryptodev_sym_free_session_t)(struct rte_cryptodev *dev,
302 struct rte_cryptodev_sym_session *sess);
304 * Free asymmetric session private data.
306 * @param dev Crypto device pointer
307 * @param sess Cryptodev session structure
309 typedef void (*cryptodev_asym_free_session_t)(struct rte_cryptodev *dev,
310 struct rte_cryptodev_asym_session *sess);
312 /** Crypto device operations function pointer table */
313 struct rte_cryptodev_ops {
314 cryptodev_configure_t dev_configure; /**< Configure device. */
315 cryptodev_start_t dev_start; /**< Start device. */
316 cryptodev_stop_t dev_stop; /**< Stop device. */
317 cryptodev_close_t dev_close; /**< Close device. */
319 cryptodev_info_get_t dev_infos_get; /**< Get device info. */
321 cryptodev_stats_get_t stats_get;
322 /**< Get device statistics. */
323 cryptodev_stats_reset_t stats_reset;
324 /**< Reset device statistics. */
326 cryptodev_queue_pair_setup_t queue_pair_setup;
327 /**< Set up a device queue pair. */
328 cryptodev_queue_pair_release_t queue_pair_release;
329 /**< Release a queue pair. */
330 cryptodev_queue_pair_count_t queue_pair_count;
331 /**< Get count of the queue pairs. */
333 cryptodev_sym_get_session_private_size_t sym_session_get_size;
334 /**< Return private session. */
335 cryptodev_asym_get_session_private_size_t asym_session_get_size;
336 /**< Return asym session private size. */
337 cryptodev_sym_configure_session_t sym_session_configure;
338 /**< Configure a Crypto session. */
339 cryptodev_asym_configure_session_t asym_session_configure;
340 /**< Configure asymmetric Crypto session. */
341 cryptodev_sym_free_session_t sym_session_clear;
342 /**< Clear a Crypto sessions private data. */
343 cryptodev_asym_free_session_t asym_session_clear;
344 /**< Clear a Crypto sessions private data. */
349 * Function for internal use by dummy drivers primarily, e.g. ring-based
351 * Allocates a new cryptodev slot for an crypto device and returns the pointer
352 * to that slot for the driver to use.
354 * @param name Unique identifier name for each device
355 * @param socket_id Socket to allocate resources on.
357 * - Slot in the rte_dev_devices array for a new device;
359 struct rte_cryptodev *
360 rte_cryptodev_pmd_allocate(const char *name, int socket_id);
363 * Function for internal use by dummy drivers primarily, e.g. ring-based
365 * Release the specified cryptodev device.
368 * The *cryptodev* pointer is the address of the *rte_cryptodev* structure.
370 * - 0 on success, negative on error
373 rte_cryptodev_pmd_release_device(struct rte_cryptodev *cryptodev);
379 * PMD assist function to parse initialisation arguments for crypto driver
380 * when creating a new crypto PMD device instance.
382 * PMD driver should set default values for that PMD before calling function,
383 * these default values will be over-written with successfully parsed values
386 * @param params parsed PMD initialisation parameters
387 * @param args input argument string to parse
394 rte_cryptodev_pmd_parse_input_args(
395 struct rte_cryptodev_pmd_init_params *params,
401 * PMD assist function to provide boiler plate code for crypto driver to create
402 * and allocate resources for a new crypto PMD device instance.
404 * @param name crypto device name.
405 * @param device base device instance
406 * @param params PMD initialisation parameters
409 * - crypto device instance on success
410 * - NULL on creation failure
412 struct rte_cryptodev *
413 rte_cryptodev_pmd_create(const char *name,
414 struct rte_device *device,
415 struct rte_cryptodev_pmd_init_params *params);
420 * PMD assist function to provide boiler plate code for crypto driver to
421 * destroy and free resources associated with a crypto PMD device instance.
423 * @param cryptodev crypto device handle.
430 rte_cryptodev_pmd_destroy(struct rte_cryptodev *cryptodev);
433 * Executes all the user application registered callbacks for the specific
436 * @param dev Pointer to cryptodev struct
437 * @param event Crypto device interrupt event type.
442 void rte_cryptodev_pmd_callback_process(struct rte_cryptodev *dev,
443 enum rte_cryptodev_event_type event);
447 * Create unique device name
450 rte_cryptodev_pmd_create_dev_name(char *name, const char *dev_name_prefix);
454 * Allocate Cryptodev driver.
457 * Pointer to cryptodev_driver.
459 * Pointer to rte_driver.
462 * The driver type identifier
464 uint8_t rte_cryptodev_allocate_driver(struct cryptodev_driver *crypto_drv,
465 const struct rte_driver *drv);
468 #define RTE_PMD_REGISTER_CRYPTO_DRIVER(crypto_drv, drv, driver_id)\
469 RTE_INIT(init_ ##driver_id)\
471 driver_id = rte_cryptodev_allocate_driver(&crypto_drv, &(drv));\
475 get_sym_session_private_data(const struct rte_cryptodev_sym_session *sess,
477 if (unlikely(sess->nb_drivers <= driver_id))
480 return sess->sess_data[driver_id].data;
484 set_sym_session_private_data(struct rte_cryptodev_sym_session *sess,
485 uint8_t driver_id, void *private_data)
487 if (unlikely(sess->nb_drivers <= driver_id)) {
488 CDEV_LOG_ERR("Set private data for driver %u not allowed\n",
493 sess->sess_data[driver_id].data = private_data;
497 get_asym_session_private_data(const struct rte_cryptodev_asym_session *sess,
499 return sess->sess_private_data[driver_id];
503 set_asym_session_private_data(struct rte_cryptodev_asym_session *sess,
504 uint8_t driver_id, void *private_data)
506 sess->sess_private_data[driver_id] = private_data;
513 #endif /* _RTE_CRYPTODEV_PMD_H_ */