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 */
64 uint8_t max_devs; /**< Max number of devices */
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;
74 /** pointer to global crypto devices data structure. */
75 extern struct rte_cryptodev_global *rte_cryptodev_globals;
78 * Get the rte_cryptodev structure device pointer for the device. Assumes a
81 * @param dev_id Device ID value to select the device structure.
84 * - The rte_cryptodev structure pointer for the given device ID.
86 struct rte_cryptodev *
87 rte_cryptodev_pmd_get_dev(uint8_t dev_id);
90 * Get the rte_cryptodev structure device pointer for the named device.
92 * @param name device name to select the device structure.
95 * - The rte_cryptodev structure pointer for the given device ID.
97 struct rte_cryptodev *
98 rte_cryptodev_pmd_get_named_dev(const char *name);
101 * Validate if the crypto device index is valid attached crypto device.
103 * @param dev_id Crypto device index.
106 * - If the device index is valid (1) or not (0).
109 rte_cryptodev_pmd_is_valid_dev(uint8_t dev_id);
112 * The pool of rte_cryptodev structures.
114 extern struct rte_cryptodev *rte_cryptodevs;
118 * Definitions of all functions exported by a driver through the
119 * the generic structure of type *crypto_dev_ops* supplied in the
120 * *rte_cryptodev* structure associated with a device.
124 * Function used to configure device.
126 * @param dev Crypto device pointer
127 * config Crypto device configurations
129 * @return Returns 0 on success
131 typedef int (*cryptodev_configure_t)(struct rte_cryptodev *dev,
132 struct rte_cryptodev_config *config);
135 * Function used to start a configured device.
137 * @param dev Crypto device pointer
139 * @return Returns 0 on success
141 typedef int (*cryptodev_start_t)(struct rte_cryptodev *dev);
144 * Function used to stop a configured device.
146 * @param dev Crypto device pointer
148 typedef void (*cryptodev_stop_t)(struct rte_cryptodev *dev);
151 * Function used to close a configured device.
153 * @param dev Crypto device pointer
156 * - EAGAIN if can't close as device is busy
158 typedef int (*cryptodev_close_t)(struct rte_cryptodev *dev);
162 * Function used to get statistics of a device.
164 * @param dev Crypto device pointer
165 * @param stats Pointer to crypto device stats structure to populate
167 typedef void (*cryptodev_stats_get_t)(struct rte_cryptodev *dev,
168 struct rte_cryptodev_stats *stats);
172 * Function used to reset statistics of a device.
174 * @param dev Crypto device pointer
176 typedef void (*cryptodev_stats_reset_t)(struct rte_cryptodev *dev);
180 * Function used to get specific information of a device.
182 * @param dev Crypto device pointer
184 typedef void (*cryptodev_info_get_t)(struct rte_cryptodev *dev,
185 struct rte_cryptodev_info *dev_info);
188 * Setup a queue pair for a device.
190 * @param dev Crypto device pointer
191 * @param qp_id Queue Pair Index
192 * @param qp_conf Queue configuration structure
193 * @param socket_id Socket Index
194 * @param session_pool Pointer to device session mempool
196 * @return Returns 0 on success.
198 typedef int (*cryptodev_queue_pair_setup_t)(struct rte_cryptodev *dev,
199 uint16_t qp_id, const struct rte_cryptodev_qp_conf *qp_conf,
200 int socket_id, struct rte_mempool *session_pool);
203 * Release memory resources allocated by given queue pair.
205 * @param dev Crypto device pointer
206 * @param qp_id Queue Pair Index
210 * - EAGAIN if can't close as device is busy
212 typedef int (*cryptodev_queue_pair_release_t)(struct rte_cryptodev *dev,
216 * Get number of available queue pairs of a device.
218 * @param dev Crypto device pointer
220 * @return Returns number of queue pairs on success.
222 typedef uint32_t (*cryptodev_queue_pair_count_t)(struct rte_cryptodev *dev);
225 * Create a session mempool to allocate sessions from
227 * @param dev Crypto device pointer
228 * @param nb_objs number of sessions objects in mempool
229 * @param obj_cache l-core object cache size, see *rte_ring_create*
230 * @param socket_id Socket Id to allocate mempool on.
233 * - On success returns a pointer to a rte_mempool
234 * - On failure returns a NULL pointer
236 typedef int (*cryptodev_sym_create_session_pool_t)(
237 struct rte_cryptodev *dev, unsigned nb_objs,
238 unsigned obj_cache_size, int socket_id);
242 * Get the size of a cryptodev session
244 * @param dev Crypto device pointer
247 * - On success returns the size of the session structure for device
248 * - On failure returns 0
250 typedef unsigned (*cryptodev_sym_get_session_private_size_t)(
251 struct rte_cryptodev *dev);
254 * Configure a Crypto session on a device.
256 * @param dev Crypto device pointer
257 * @param xform Single or chain of crypto xforms
258 * @param priv_sess Pointer to cryptodev's private session structure
259 * @param mp Mempool where the private session is allocated
262 * - Returns 0 if private session structure have been created successfully.
263 * - Returns -EINVAL if input parameters are invalid.
264 * - Returns -ENOTSUP if crypto device does not support the crypto transform.
265 * - Returns -ENOMEM if the private session could not be allocated.
267 typedef int (*cryptodev_sym_configure_session_t)(struct rte_cryptodev *dev,
268 struct rte_crypto_sym_xform *xform,
269 struct rte_cryptodev_sym_session *session,
270 struct rte_mempool *mp);
273 * Free driver private session data.
275 * @param dev Crypto device pointer
276 * @param sess Cryptodev session structure
278 typedef void (*cryptodev_sym_free_session_t)(struct rte_cryptodev *dev,
279 struct rte_cryptodev_sym_session *sess);
281 /** Crypto device operations function pointer table */
282 struct rte_cryptodev_ops {
283 cryptodev_configure_t dev_configure; /**< Configure device. */
284 cryptodev_start_t dev_start; /**< Start device. */
285 cryptodev_stop_t dev_stop; /**< Stop device. */
286 cryptodev_close_t dev_close; /**< Close device. */
288 cryptodev_info_get_t dev_infos_get; /**< Get device info. */
290 cryptodev_stats_get_t stats_get;
291 /**< Get device statistics. */
292 cryptodev_stats_reset_t stats_reset;
293 /**< Reset device statistics. */
295 cryptodev_queue_pair_setup_t queue_pair_setup;
296 /**< Set up a device queue pair. */
297 cryptodev_queue_pair_release_t queue_pair_release;
298 /**< Release a queue pair. */
299 cryptodev_queue_pair_count_t queue_pair_count;
300 /**< Get count of the queue pairs. */
302 cryptodev_sym_get_session_private_size_t sym_session_get_size;
303 /**< Return private session. */
304 cryptodev_sym_configure_session_t sym_session_configure;
305 /**< Configure a Crypto session. */
306 cryptodev_sym_free_session_t sym_session_clear;
307 /**< Clear a Crypto sessions private data. */
312 * Function for internal use by dummy drivers primarily, e.g. ring-based
314 * Allocates a new cryptodev slot for an crypto device and returns the pointer
315 * to that slot for the driver to use.
317 * @param name Unique identifier name for each device
318 * @param socket_id Socket to allocate resources on.
320 * - Slot in the rte_dev_devices array for a new device;
322 struct rte_cryptodev *
323 rte_cryptodev_pmd_allocate(const char *name, int socket_id);
326 * Function for internal use by dummy drivers primarily, e.g. ring-based
328 * Release the specified cryptodev device.
331 * The *cryptodev* pointer is the address of the *rte_cryptodev* structure.
333 * - 0 on success, negative on error
336 rte_cryptodev_pmd_release_device(struct rte_cryptodev *cryptodev);
342 * PMD assist function to parse initialisation arguments for crypto driver
343 * when creating a new crypto PMD device instance.
345 * PMD driver should set default values for that PMD before calling function,
346 * these default values will be over-written with successfully parsed values
349 * @param params parsed PMD initialisation parameters
350 * @param args input argument string to parse
357 rte_cryptodev_pmd_parse_input_args(
358 struct rte_cryptodev_pmd_init_params *params,
364 * PMD assist function to provide boiler plate code for crypto driver to create
365 * and allocate resources for a new crypto PMD device instance.
367 * @param name crypto device name.
368 * @param device base device instance
369 * @param params PMD initialisation parameters
372 * - crypto device instance on success
373 * - NULL on creation failure
375 struct rte_cryptodev *
376 rte_cryptodev_pmd_create(const char *name,
377 struct rte_device *device,
378 struct rte_cryptodev_pmd_init_params *params);
383 * PMD assist function to provide boiler plate code for crypto driver to
384 * destroy and free resources associated with a crypto PMD device instance.
386 * @param cryptodev crypto device handle.
393 rte_cryptodev_pmd_destroy(struct rte_cryptodev *cryptodev);
396 * Executes all the user application registered callbacks for the specific
399 * @param dev Pointer to cryptodev struct
400 * @param event Crypto device interrupt event type.
405 void rte_cryptodev_pmd_callback_process(struct rte_cryptodev *dev,
406 enum rte_cryptodev_event_type event);
410 * Create unique device name
413 rte_cryptodev_pmd_create_dev_name(char *name, const char *dev_name_prefix);
417 * Allocate Cryptodev driver.
420 * Pointer to cryptodev_driver.
422 * Pointer to rte_driver.
425 * The driver type identifier
427 uint8_t rte_cryptodev_allocate_driver(struct cryptodev_driver *crypto_drv,
428 const struct rte_driver *drv);
431 #define RTE_PMD_REGISTER_CRYPTO_DRIVER(crypto_drv, drv, driver_id)\
432 RTE_INIT(init_ ##driver_id);\
433 static void init_ ##driver_id(void)\
435 driver_id = rte_cryptodev_allocate_driver(&crypto_drv, &(drv));\
439 get_sym_session_private_data(const struct rte_cryptodev_sym_session *sess,
441 return sess->sess_private_data[driver_id];
445 set_sym_session_private_data(struct rte_cryptodev_sym_session *sess,
446 uint8_t driver_id, void *private_data)
448 sess->sess_private_data[driver_id] = private_data;
455 #endif /* _RTE_CRYPTODEV_PMD_H_ */