3 * Copyright(c) 2015-2016 Intel Corporation. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
15 * * Neither the name of Intel Corporation nor the names of its
16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #ifndef _RTE_CRYPTODEV_PMD_H_
33 #define _RTE_CRYPTODEV_PMD_H_
39 * These API are from crypto PMD only and user applications should not call
51 #include <rte_malloc.h>
53 #include <rte_mempool.h>
55 #include <rte_common.h>
57 #include "rte_crypto.h"
58 #include "rte_cryptodev.h"
60 struct rte_cryptodev_session {
64 enum rte_cryptodev_type type;
65 struct rte_mempool *mp;
68 __extension__ char _private[0];
71 struct rte_cryptodev_driver;
74 * Initialisation function of a crypto driver invoked for each matching
75 * crypto PCI device detected during the PCI probing phase.
77 * @param drv The pointer to the [matching] crypto driver structure
78 * supplied by the PMD when it registered itself.
79 * @param dev The dev pointer is the address of the *rte_cryptodev*
80 * structure associated with the matching device and which
81 * has been [automatically] allocated in the
82 * *rte_crypto_devices* array.
85 * - 0: Success, the device is properly initialised by the driver.
86 * In particular, the driver MUST have set up the *dev_ops* pointer
87 * of the *dev* structure.
88 * - <0: Error code of the device initialisation failure.
90 typedef int (*cryptodev_init_t)(struct rte_cryptodev_driver *drv,
91 struct rte_cryptodev *dev);
94 * Finalisation function of a driver invoked for each matching
95 * PCI device detected during the PCI closing phase.
97 * @param drv The pointer to the [matching] driver structure supplied
98 * by the PMD when it registered itself.
99 * @param dev The dev pointer is the address of the *rte_cryptodev*
100 * structure associated with the matching device and which
101 * has been [automatically] allocated in the
102 * *rte_crypto_devices* array.
105 * - 0: Success, the device is properly finalised by the driver.
106 * In particular, the driver MUST free the *dev_ops* pointer
107 * of the *dev* structure.
108 * - <0: Error code of the device initialisation failure.
110 typedef int (*cryptodev_uninit_t)(const struct rte_cryptodev_driver *drv,
111 struct rte_cryptodev *dev);
114 * The structure associated with a PMD driver.
116 * Each driver acts as a PCI driver and is represented by a generic
117 * *crypto_driver* structure that holds:
119 * - An *rte_pci_driver* structure (which must be the first field).
121 * - The *cryptodev_init* function invoked for each matching PCI device.
123 * - The size of the private data to allocate for each matching device.
125 struct rte_cryptodev_driver {
126 struct rte_pci_driver pci_drv; /**< The PMD is also a PCI driver. */
127 unsigned dev_private_size; /**< Size of device private data. */
129 cryptodev_init_t cryptodev_init; /**< Device init function. */
130 cryptodev_uninit_t cryptodev_uninit; /**< Device uninit function. */
134 /** Global structure used for maintaining state of allocated crypto devices */
135 struct rte_cryptodev_global {
136 struct rte_cryptodev *devs; /**< Device information array */
137 struct rte_cryptodev_data *data[RTE_CRYPTO_MAX_DEVS];
138 /**< Device private data */
139 uint8_t nb_devs; /**< Number of devices found */
140 uint8_t max_devs; /**< Max number of devices */
143 /** pointer to global crypto devices data structure. */
144 extern struct rte_cryptodev_global *rte_cryptodev_globals;
147 * Get the rte_cryptodev structure device pointer for the device. Assumes a
148 * valid device index.
150 * @param dev_id Device ID value to select the device structure.
153 * - The rte_cryptodev structure pointer for the given device ID.
155 struct rte_cryptodev *
156 rte_cryptodev_pmd_get_dev(uint8_t dev_id);
159 * Get the rte_cryptodev structure device pointer for the named device.
161 * @param name device name to select the device structure.
164 * - The rte_cryptodev structure pointer for the given device ID.
166 struct rte_cryptodev *
167 rte_cryptodev_pmd_get_named_dev(const char *name);
170 * Validate if the crypto device index is valid attached crypto device.
172 * @param dev_id Crypto device index.
175 * - If the device index is valid (1) or not (0).
178 rte_cryptodev_pmd_is_valid_dev(uint8_t dev_id);
181 * The pool of rte_cryptodev structures.
183 extern struct rte_cryptodev *rte_cryptodevs;
187 * Definitions of all functions exported by a driver through the
188 * the generic structure of type *crypto_dev_ops* supplied in the
189 * *rte_cryptodev* structure associated with a device.
193 * Function used to configure device.
195 * @param dev Crypto device pointer
196 * config Crypto device configurations
198 * @return Returns 0 on success
200 typedef int (*cryptodev_configure_t)(struct rte_cryptodev *dev,
201 struct rte_cryptodev_config *config);
204 * Function used to start a configured device.
206 * @param dev Crypto device pointer
208 * @return Returns 0 on success
210 typedef int (*cryptodev_start_t)(struct rte_cryptodev *dev);
213 * Function used to stop a configured device.
215 * @param dev Crypto device pointer
217 typedef void (*cryptodev_stop_t)(struct rte_cryptodev *dev);
220 * Function used to close a configured device.
222 * @param dev Crypto device pointer
225 * - EAGAIN if can't close as device is busy
227 typedef int (*cryptodev_close_t)(struct rte_cryptodev *dev);
231 * Function used to get statistics of a device.
233 * @param dev Crypto device pointer
234 * @param stats Pointer to crypto device stats structure to populate
236 typedef void (*cryptodev_stats_get_t)(struct rte_cryptodev *dev,
237 struct rte_cryptodev_stats *stats);
241 * Function used to reset statistics of a device.
243 * @param dev Crypto device pointer
245 typedef void (*cryptodev_stats_reset_t)(struct rte_cryptodev *dev);
249 * Function used to get specific information of a device.
251 * @param dev Crypto device pointer
253 typedef void (*cryptodev_info_get_t)(struct rte_cryptodev *dev,
254 struct rte_cryptodev_info *dev_info);
257 * Start queue pair of a device.
259 * @param dev Crypto device pointer
260 * @param qp_id Queue Pair Index
262 * @return Returns 0 on success.
264 typedef int (*cryptodev_queue_pair_start_t)(struct rte_cryptodev *dev,
268 * Stop queue pair of a device.
270 * @param dev Crypto device pointer
271 * @param qp_id Queue Pair Index
273 * @return Returns 0 on success.
275 typedef int (*cryptodev_queue_pair_stop_t)(struct rte_cryptodev *dev,
279 * Setup a queue pair for a device.
281 * @param dev Crypto device pointer
282 * @param qp_id Queue Pair Index
283 * @param qp_conf Queue configuration structure
284 * @param socket_id Socket Index
286 * @return Returns 0 on success.
288 typedef int (*cryptodev_queue_pair_setup_t)(struct rte_cryptodev *dev,
289 uint16_t qp_id, const struct rte_cryptodev_qp_conf *qp_conf,
293 * Release memory resources allocated by given queue pair.
295 * @param dev Crypto device pointer
296 * @param qp_id Queue Pair Index
300 * - EAGAIN if can't close as device is busy
302 typedef int (*cryptodev_queue_pair_release_t)(struct rte_cryptodev *dev,
306 * Get number of available queue pairs of a device.
308 * @param dev Crypto device pointer
310 * @return Returns number of queue pairs on success.
312 typedef uint32_t (*cryptodev_queue_pair_count_t)(struct rte_cryptodev *dev);
315 * Create a session mempool to allocate sessions from
317 * @param dev Crypto device pointer
318 * @param nb_objs number of sessions objects in mempool
319 * @param obj_cache l-core object cache size, see *rte_ring_create*
320 * @param socket_id Socket Id to allocate mempool on.
323 * - On success returns a pointer to a rte_mempool
324 * - On failure returns a NULL pointer
326 typedef int (*cryptodev_sym_create_session_pool_t)(
327 struct rte_cryptodev *dev, unsigned nb_objs,
328 unsigned obj_cache_size, int socket_id);
332 * Get the size of a cryptodev session
334 * @param dev Crypto device pointer
337 * - On success returns the size of the session structure for device
338 * - On failure returns 0
340 typedef unsigned (*cryptodev_sym_get_session_private_size_t)(
341 struct rte_cryptodev *dev);
344 * Initialize a Crypto session on a device.
346 * @param dev Crypto device pointer
347 * @param xform Single or chain of crypto xforms
348 * @param priv_sess Pointer to cryptodev's private session structure
351 * - Returns private session structure on success.
352 * - Returns NULL on failure.
354 typedef void (*cryptodev_sym_initialize_session_t)(struct rte_mempool *mempool,
355 void *session_private);
358 * Configure a Crypto session on a device.
360 * @param dev Crypto device pointer
361 * @param xform Single or chain of crypto xforms
362 * @param priv_sess Pointer to cryptodev's private session structure
365 * - Returns private session structure on success.
366 * - Returns NULL on failure.
368 typedef void * (*cryptodev_sym_configure_session_t)(struct rte_cryptodev *dev,
369 struct rte_crypto_sym_xform *xform, void *session_private);
372 * Free Crypto session.
373 * @param session Cryptodev session structure to free
375 typedef void (*cryptodev_sym_free_session_t)(struct rte_cryptodev *dev,
376 void *session_private);
379 * Optional API for drivers to attach sessions with queue pair.
380 * @param dev Crypto device pointer
381 * @param qp_id queue pair id for attaching session
382 * @param priv_sess Pointer to cryptodev's private session structure
384 * - Return 0 on success
386 typedef int (*cryptodev_sym_queue_pair_attach_session_t)(
387 struct rte_cryptodev *dev,
389 void *session_private);
392 * Optional API for drivers to detach sessions from queue pair.
393 * @param dev Crypto device pointer
394 * @param qp_id queue pair id for detaching session
395 * @param priv_sess Pointer to cryptodev's private session structure
397 * - Return 0 on success
399 typedef int (*cryptodev_sym_queue_pair_detach_session_t)(
400 struct rte_cryptodev *dev,
402 void *session_private);
404 /** Crypto device operations function pointer table */
405 struct rte_cryptodev_ops {
406 cryptodev_configure_t dev_configure; /**< Configure device. */
407 cryptodev_start_t dev_start; /**< Start device. */
408 cryptodev_stop_t dev_stop; /**< Stop device. */
409 cryptodev_close_t dev_close; /**< Close device. */
411 cryptodev_info_get_t dev_infos_get; /**< Get device info. */
413 cryptodev_stats_get_t stats_get;
414 /**< Get device statistics. */
415 cryptodev_stats_reset_t stats_reset;
416 /**< Reset device statistics. */
418 cryptodev_queue_pair_setup_t queue_pair_setup;
419 /**< Set up a device queue pair. */
420 cryptodev_queue_pair_release_t queue_pair_release;
421 /**< Release a queue pair. */
422 cryptodev_queue_pair_start_t queue_pair_start;
423 /**< Start a queue pair. */
424 cryptodev_queue_pair_stop_t queue_pair_stop;
425 /**< Stop a queue pair. */
426 cryptodev_queue_pair_count_t queue_pair_count;
427 /**< Get count of the queue pairs. */
429 cryptodev_sym_get_session_private_size_t session_get_size;
430 /**< Return private session. */
431 cryptodev_sym_initialize_session_t session_initialize;
432 /**< Initialization function for private session data */
433 cryptodev_sym_configure_session_t session_configure;
434 /**< Configure a Crypto session. */
435 cryptodev_sym_free_session_t session_clear;
436 /**< Clear a Crypto sessions private data. */
437 cryptodev_sym_queue_pair_attach_session_t qp_attach_session;
438 /**< Attach session to queue pair. */
439 cryptodev_sym_queue_pair_attach_session_t qp_detach_session;
440 /**< Detach session from queue pair. */
445 * Function for internal use by dummy drivers primarily, e.g. ring-based
447 * Allocates a new cryptodev slot for an crypto device and returns the pointer
448 * to that slot for the driver to use.
450 * @param name Unique identifier name for each device
451 * @param socket_id Socket to allocate resources on.
453 * - Slot in the rte_dev_devices array for a new device;
455 struct rte_cryptodev *
456 rte_cryptodev_pmd_allocate(const char *name, int socket_id);
459 * Creates a new virtual crypto device and returns the pointer
462 * @param name PMD type name
463 * @param dev_private_size Size of crypto PMDs private data
464 * @param socket_id Socket to allocate resources on.
467 * - Cryptodev pointer if device is successfully created.
468 * - NULL if device cannot be created.
470 struct rte_cryptodev *
471 rte_cryptodev_pmd_virtual_dev_init(const char *name, size_t dev_private_size,
476 * Function for internal use by dummy drivers primarily, e.g. ring-based
478 * Release the specified cryptodev device.
481 * The *cryptodev* pointer is the address of the *rte_cryptodev* structure.
483 * - 0 on success, negative on error
486 rte_cryptodev_pmd_release_device(struct rte_cryptodev *cryptodev);
489 * Executes all the user application registered callbacks for the specific
492 * @param dev Pointer to cryptodev struct
493 * @param event Crypto device interrupt event type.
498 void rte_cryptodev_pmd_callback_process(struct rte_cryptodev *dev,
499 enum rte_cryptodev_event_type event);
502 * Wrapper for use by pci drivers as a .probe function to attach to a crypto
505 int rte_cryptodev_pci_probe(struct rte_pci_driver *pci_drv,
506 struct rte_pci_device *pci_dev);
509 * Wrapper for use by pci drivers as a .remove function to detach a crypto
512 int rte_cryptodev_pci_remove(struct rte_pci_device *pci_dev);
516 * Create unique device name
519 rte_cryptodev_pmd_create_dev_name(char *name, const char *dev_name_prefix);
525 #endif /* _RTE_CRYPTODEV_PMD_H_ */