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 * Definitions of all functions exported by a driver through the
97 * the generic structure of type *crypto_dev_ops* supplied in the
98 * *rte_cryptodev* structure associated with a device.
102 * Function used to configure device.
104 * @param dev Crypto device pointer
105 * @param config Crypto device configurations
107 * @return Returns 0 on success
109 typedef int (*cryptodev_configure_t)(struct rte_cryptodev *dev,
110 struct rte_cryptodev_config *config);
113 * Function used to start a configured device.
115 * @param dev Crypto device pointer
117 * @return Returns 0 on success
119 typedef int (*cryptodev_start_t)(struct rte_cryptodev *dev);
122 * Function used to stop a configured device.
124 * @param dev Crypto device pointer
126 typedef void (*cryptodev_stop_t)(struct rte_cryptodev *dev);
129 * Function used to close a configured device.
131 * @param dev Crypto device pointer
134 * - EAGAIN if can't close as device is busy
136 typedef int (*cryptodev_close_t)(struct rte_cryptodev *dev);
140 * Function used to get statistics of a device.
142 * @param dev Crypto device pointer
143 * @param stats Pointer to crypto device stats structure to populate
145 typedef void (*cryptodev_stats_get_t)(struct rte_cryptodev *dev,
146 struct rte_cryptodev_stats *stats);
150 * Function used to reset statistics of a device.
152 * @param dev Crypto device pointer
154 typedef void (*cryptodev_stats_reset_t)(struct rte_cryptodev *dev);
158 * Function used to get specific information of a device.
160 * @param dev Crypto device pointer
161 * @param dev_info Pointer to infos structure to populate
163 typedef void (*cryptodev_info_get_t)(struct rte_cryptodev *dev,
164 struct rte_cryptodev_info *dev_info);
167 * Setup a queue pair for a device.
169 * @param dev Crypto device pointer
170 * @param qp_id Queue Pair Index
171 * @param qp_conf Queue configuration structure
172 * @param socket_id Socket Index
174 * @return Returns 0 on success.
176 typedef int (*cryptodev_queue_pair_setup_t)(struct rte_cryptodev *dev,
177 uint16_t qp_id, const struct rte_cryptodev_qp_conf *qp_conf,
181 * Release memory resources allocated by given queue pair.
183 * @param dev Crypto device pointer
184 * @param qp_id Queue Pair Index
188 * - EAGAIN if can't close as device is busy
190 typedef int (*cryptodev_queue_pair_release_t)(struct rte_cryptodev *dev,
194 * Create a session mempool to allocate sessions from
196 * @param dev Crypto device pointer
197 * @param nb_objs number of sessions objects in mempool
198 * @param obj_cache_size l-core object cache size, see *rte_ring_create*
199 * @param socket_id Socket Id to allocate mempool on.
202 * - On success returns a pointer to a rte_mempool
203 * - On failure returns a NULL pointer
205 typedef int (*cryptodev_sym_create_session_pool_t)(
206 struct rte_cryptodev *dev, unsigned nb_objs,
207 unsigned obj_cache_size, int socket_id);
211 * Get the size of a cryptodev session
213 * @param dev Crypto device pointer
216 * - On success returns the size of the session structure for device
217 * - On failure returns 0
219 typedef unsigned (*cryptodev_sym_get_session_private_size_t)(
220 struct rte_cryptodev *dev);
222 * Get the size of a asymmetric cryptodev session
224 * @param dev Crypto device pointer
227 * - On success returns the size of the session structure for device
228 * - On failure returns 0
230 typedef unsigned int (*cryptodev_asym_get_session_private_size_t)(
231 struct rte_cryptodev *dev);
234 * Configure a Crypto session on a device.
236 * @param dev Crypto device pointer
237 * @param xform Single or chain of crypto xforms
238 * @param session Pointer to cryptodev's private session structure
239 * @param mp Mempool where the private session is allocated
242 * - Returns 0 if private session structure have been created successfully.
243 * - Returns -EINVAL if input parameters are invalid.
244 * - Returns -ENOTSUP if crypto device does not support the crypto transform.
245 * - Returns -ENOMEM if the private session could not be allocated.
247 typedef int (*cryptodev_sym_configure_session_t)(struct rte_cryptodev *dev,
248 struct rte_crypto_sym_xform *xform,
249 struct rte_cryptodev_sym_session *session,
250 struct rte_mempool *mp);
252 * Configure a Crypto asymmetric session on a device.
254 * @param dev Crypto device pointer
255 * @param xform Single or chain of crypto xforms
256 * @param session Pointer to cryptodev's private session structure
257 * @param mp Mempool where the private session is allocated
260 * - Returns 0 if private session structure have been created successfully.
261 * - Returns -EINVAL if input parameters are invalid.
262 * - Returns -ENOTSUP if crypto device does not support the crypto transform.
263 * - Returns -ENOMEM if the private session could not be allocated.
265 typedef int (*cryptodev_asym_configure_session_t)(struct rte_cryptodev *dev,
266 struct rte_crypto_asym_xform *xform,
267 struct rte_cryptodev_asym_session *session,
268 struct rte_mempool *mp);
270 * Free driver private session data.
272 * @param dev Crypto device pointer
273 * @param sess Cryptodev session structure
275 typedef void (*cryptodev_sym_free_session_t)(struct rte_cryptodev *dev,
276 struct rte_cryptodev_sym_session *sess);
278 * Free asymmetric session private data.
280 * @param dev Crypto device pointer
281 * @param sess Cryptodev session structure
283 typedef void (*cryptodev_asym_free_session_t)(struct rte_cryptodev *dev,
284 struct rte_cryptodev_asym_session *sess);
286 * Perform actual crypto processing (encrypt/digest or auth/decrypt)
287 * on user provided data.
289 * @param dev Crypto device pointer
290 * @param sess Cryptodev session structure
291 * @param ofs Start and stop offsets for auth and cipher operations
292 * @param vec Vectorized operation descriptor
295 * - Returns number of successfully processed packets.
298 typedef uint32_t (*cryptodev_sym_cpu_crypto_process_t)
299 (struct rte_cryptodev *dev, struct rte_cryptodev_sym_session *sess,
300 union rte_crypto_sym_ofs ofs, struct rte_crypto_sym_vec *vec);
303 * Typedef that the driver provided to get service context private date size.
305 * @param dev Crypto device pointer.
308 * - On success return the size of the device's service context private data.
309 * - On failure return negative integer.
311 typedef int (*cryptodev_sym_get_raw_dp_ctx_size_t)(struct rte_cryptodev *dev);
314 * Typedef that the driver provided to configure raw data-path context.
316 * @param dev Crypto device pointer.
317 * @param qp_id Crypto device queue pair index.
318 * @param ctx The raw data-path context data.
319 * @param sess_type session type.
320 * @param session_ctx Session context data. If NULL the driver
321 * shall only configure the drv_ctx_data in
322 * ctx buffer. Otherwise the driver shall only
323 * parse the session_ctx to set appropriate
324 * function pointers in ctx.
325 * @param is_update Set 0 if it is to initialize the ctx.
326 * Set 1 if ctx is initialized and only to update
327 * session context data.
329 * - On success return 0.
330 * - On failure return negative integer.
332 typedef int (*cryptodev_sym_configure_raw_dp_ctx_t)(
333 struct rte_cryptodev *dev, uint16_t qp_id,
334 struct rte_crypto_raw_dp_ctx *ctx,
335 enum rte_crypto_op_sess_type sess_type,
336 union rte_cryptodev_session_ctx session_ctx, uint8_t is_update);
338 /** Crypto device operations function pointer table */
339 struct rte_cryptodev_ops {
340 cryptodev_configure_t dev_configure; /**< Configure device. */
341 cryptodev_start_t dev_start; /**< Start device. */
342 cryptodev_stop_t dev_stop; /**< Stop device. */
343 cryptodev_close_t dev_close; /**< Close device. */
345 cryptodev_info_get_t dev_infos_get; /**< Get device info. */
347 cryptodev_stats_get_t stats_get;
348 /**< Get device statistics. */
349 cryptodev_stats_reset_t stats_reset;
350 /**< Reset device statistics. */
352 cryptodev_queue_pair_setup_t queue_pair_setup;
353 /**< Set up a device queue pair. */
354 cryptodev_queue_pair_release_t queue_pair_release;
355 /**< Release a queue pair. */
357 cryptodev_sym_get_session_private_size_t sym_session_get_size;
358 /**< Return private session. */
359 cryptodev_asym_get_session_private_size_t asym_session_get_size;
360 /**< Return asym session private size. */
361 cryptodev_sym_configure_session_t sym_session_configure;
362 /**< Configure a Crypto session. */
363 cryptodev_asym_configure_session_t asym_session_configure;
364 /**< Configure asymmetric Crypto session. */
365 cryptodev_sym_free_session_t sym_session_clear;
366 /**< Clear a Crypto sessions private data. */
367 cryptodev_asym_free_session_t asym_session_clear;
368 /**< Clear a Crypto sessions private data. */
370 cryptodev_sym_cpu_crypto_process_t sym_cpu_process;
371 /**< process input data synchronously (cpu-crypto). */
374 cryptodev_sym_get_raw_dp_ctx_size_t
375 sym_get_raw_dp_ctx_size;
376 /**< Get raw data path service context data size. */
377 cryptodev_sym_configure_raw_dp_ctx_t
378 sym_configure_raw_dp_ctx;
379 /**< Initialize raw data path context data. */
386 * Function for internal use by dummy drivers primarily, e.g. ring-based
388 * Allocates a new cryptodev slot for an crypto device and returns the pointer
389 * to that slot for the driver to use.
391 * @param name Unique identifier name for each device
392 * @param socket_id Socket to allocate resources on.
394 * - Slot in the rte_dev_devices array for a new device;
397 struct rte_cryptodev *
398 rte_cryptodev_pmd_allocate(const char *name, int socket_id);
401 * Function for internal use by dummy drivers primarily, e.g. ring-based
403 * Release the specified cryptodev device.
406 * The *cryptodev* pointer is the address of the *rte_cryptodev* structure.
408 * - 0 on success, negative on error
412 rte_cryptodev_pmd_release_device(struct rte_cryptodev *cryptodev);
418 * PMD assist function to parse initialisation arguments for crypto driver
419 * when creating a new crypto PMD device instance.
421 * PMD driver should set default values for that PMD before calling function,
422 * these default values will be over-written with successfully parsed values
425 * @param params parsed PMD initialisation parameters
426 * @param args input argument string to parse
434 rte_cryptodev_pmd_parse_input_args(
435 struct rte_cryptodev_pmd_init_params *params,
441 * PMD assist function to provide boiler plate code for crypto driver to create
442 * and allocate resources for a new crypto PMD device instance.
444 * @param name crypto device name.
445 * @param device base device instance
446 * @param params PMD initialisation parameters
449 * - crypto device instance on success
450 * - NULL on creation failure
453 struct rte_cryptodev *
454 rte_cryptodev_pmd_create(const char *name,
455 struct rte_device *device,
456 struct rte_cryptodev_pmd_init_params *params);
461 * PMD assist function to provide boiler plate code for crypto driver to
462 * destroy and free resources associated with a crypto PMD device instance.
464 * @param cryptodev crypto device handle.
472 rte_cryptodev_pmd_destroy(struct rte_cryptodev *cryptodev);
475 * Executes all the user application registered callbacks for the specific
478 * @param dev Pointer to cryptodev struct
479 * @param event Crypto device interrupt event type.
485 void rte_cryptodev_pmd_callback_process(struct rte_cryptodev *dev,
486 enum rte_cryptodev_event_type event);
490 * Create unique device name
494 rte_cryptodev_pmd_create_dev_name(char *name, const char *dev_name_prefix);
498 * Allocate Cryptodev driver.
501 * Pointer to cryptodev_driver.
503 * Pointer to rte_driver.
506 * 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));\
519 /* Reset crypto device fastpath APIs to dummy values. */
522 cryptodev_fp_ops_reset(struct rte_crypto_fp_ops *fp_ops);
524 /* Setup crypto device fastpath APIs. */
527 cryptodev_fp_ops_set(struct rte_crypto_fp_ops *fp_ops,
528 const struct rte_cryptodev *dev);
531 get_sym_session_private_data(const struct rte_cryptodev_sym_session *sess,
533 if (unlikely(sess->nb_drivers <= driver_id))
536 return sess->sess_data[driver_id].data;
540 set_sym_session_private_data(struct rte_cryptodev_sym_session *sess,
541 uint8_t driver_id, void *private_data)
543 if (unlikely(sess->nb_drivers <= driver_id)) {
544 CDEV_LOG_ERR("Set private data for driver %u not allowed\n",
549 sess->sess_data[driver_id].data = private_data;
553 get_asym_session_private_data(const struct rte_cryptodev_asym_session *sess,
555 return sess->sess_private_data[driver_id];
559 set_asym_session_private_data(struct rte_cryptodev_asym_session *sess,
560 uint8_t driver_id, void *private_data)
562 sess->sess_private_data[driver_id] = private_data;
565 #endif /* _CRYPTODEV_PMD_H_ */