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 static inline struct rte_cryptodev *
156 rte_cryptodev_pmd_get_dev(uint8_t dev_id)
158 return &rte_cryptodev_globals->devs[dev_id];
162 * Get the rte_cryptodev structure device pointer for the named device.
164 * @param name device name to select the device structure.
167 * - The rte_cryptodev structure pointer for the given device ID.
169 static inline struct rte_cryptodev *
170 rte_cryptodev_pmd_get_named_dev(const char *name)
172 struct rte_cryptodev *dev;
178 for (i = 0; i < rte_cryptodev_globals->max_devs; i++) {
179 dev = &rte_cryptodev_globals->devs[i];
181 if ((dev->attached == RTE_CRYPTODEV_ATTACHED) &&
182 (strcmp(dev->data->name, name) == 0))
190 * Validate if the crypto device index is valid attached crypto device.
192 * @param dev_id Crypto device index.
195 * - If the device index is valid (1) or not (0).
197 static inline unsigned
198 rte_cryptodev_pmd_is_valid_dev(uint8_t dev_id)
200 struct rte_cryptodev *dev = NULL;
202 if (dev_id >= rte_cryptodev_globals->nb_devs)
205 dev = rte_cryptodev_pmd_get_dev(dev_id);
206 if (dev->attached != RTE_CRYPTODEV_ATTACHED)
213 * The pool of rte_cryptodev structures.
215 extern struct rte_cryptodev *rte_cryptodevs;
219 * Definitions of all functions exported by a driver through the
220 * the generic structure of type *crypto_dev_ops* supplied in the
221 * *rte_cryptodev* structure associated with a device.
225 * Function used to configure device.
227 * @param dev Crypto device pointer
229 * @return Returns 0 on success
231 typedef int (*cryptodev_configure_t)(struct rte_cryptodev *dev);
234 * Function used to start a configured device.
236 * @param dev Crypto device pointer
238 * @return Returns 0 on success
240 typedef int (*cryptodev_start_t)(struct rte_cryptodev *dev);
243 * Function used to stop a configured device.
245 * @param dev Crypto device pointer
247 typedef void (*cryptodev_stop_t)(struct rte_cryptodev *dev);
250 * Function used to close a configured device.
252 * @param dev Crypto device pointer
255 * - EAGAIN if can't close as device is busy
257 typedef int (*cryptodev_close_t)(struct rte_cryptodev *dev);
261 * Function used to get statistics of a device.
263 * @param dev Crypto device pointer
264 * @param stats Pointer to crypto device stats structure to populate
266 typedef void (*cryptodev_stats_get_t)(struct rte_cryptodev *dev,
267 struct rte_cryptodev_stats *stats);
271 * Function used to reset statistics of a device.
273 * @param dev Crypto device pointer
275 typedef void (*cryptodev_stats_reset_t)(struct rte_cryptodev *dev);
279 * Function used to get specific information of a device.
281 * @param dev Crypto device pointer
283 typedef void (*cryptodev_info_get_t)(struct rte_cryptodev *dev,
284 struct rte_cryptodev_info *dev_info);
287 * Start queue pair of a device.
289 * @param dev Crypto device pointer
290 * @param qp_id Queue Pair Index
292 * @return Returns 0 on success.
294 typedef int (*cryptodev_queue_pair_start_t)(struct rte_cryptodev *dev,
298 * Stop queue pair of a device.
300 * @param dev Crypto device pointer
301 * @param qp_id Queue Pair Index
303 * @return Returns 0 on success.
305 typedef int (*cryptodev_queue_pair_stop_t)(struct rte_cryptodev *dev,
309 * Setup a queue pair for a device.
311 * @param dev Crypto device pointer
312 * @param qp_id Queue Pair Index
313 * @param qp_conf Queue configuration structure
314 * @param socket_id Socket Index
316 * @return Returns 0 on success.
318 typedef int (*cryptodev_queue_pair_setup_t)(struct rte_cryptodev *dev,
319 uint16_t qp_id, const struct rte_cryptodev_qp_conf *qp_conf,
323 * Release memory resources allocated by given queue pair.
325 * @param dev Crypto device pointer
326 * @param qp_id Queue Pair Index
330 * - EAGAIN if can't close as device is busy
332 typedef int (*cryptodev_queue_pair_release_t)(struct rte_cryptodev *dev,
336 * Get number of available queue pairs of a device.
338 * @param dev Crypto device pointer
340 * @return Returns number of queue pairs on success.
342 typedef uint32_t (*cryptodev_queue_pair_count_t)(struct rte_cryptodev *dev);
345 * Create a session mempool to allocate sessions from
347 * @param dev Crypto device pointer
348 * @param nb_objs number of sessions objects in mempool
349 * @param obj_cache l-core object cache size, see *rte_ring_create*
350 * @param socket_id Socket Id to allocate mempool on.
353 * - On success returns a pointer to a rte_mempool
354 * - On failure returns a NULL pointer
356 typedef int (*cryptodev_sym_create_session_pool_t)(
357 struct rte_cryptodev *dev, unsigned nb_objs,
358 unsigned obj_cache_size, int socket_id);
362 * Get the size of a cryptodev session
364 * @param dev Crypto device pointer
367 * - On success returns the size of the session structure for device
368 * - On failure returns 0
370 typedef unsigned (*cryptodev_sym_get_session_private_size_t)(
371 struct rte_cryptodev *dev);
374 * Initialize a Crypto session on a device.
376 * @param dev Crypto device pointer
377 * @param xform Single or chain of crypto xforms
378 * @param priv_sess Pointer to cryptodev's private session structure
381 * - Returns private session structure on success.
382 * - Returns NULL on failure.
384 typedef void (*cryptodev_sym_initialize_session_t)(struct rte_mempool *mempool,
385 void *session_private);
388 * Configure a Crypto session on a device.
390 * @param dev Crypto device pointer
391 * @param xform Single or chain of crypto xforms
392 * @param priv_sess Pointer to cryptodev's private session structure
395 * - Returns private session structure on success.
396 * - Returns NULL on failure.
398 typedef void * (*cryptodev_sym_configure_session_t)(struct rte_cryptodev *dev,
399 struct rte_crypto_sym_xform *xform, void *session_private);
402 * Free Crypto session.
403 * @param session Cryptodev session structure to free
405 typedef void (*cryptodev_sym_free_session_t)(struct rte_cryptodev *dev,
406 void *session_private);
409 /** Crypto device operations function pointer table */
410 struct rte_cryptodev_ops {
411 cryptodev_configure_t dev_configure; /**< Configure device. */
412 cryptodev_start_t dev_start; /**< Start device. */
413 cryptodev_stop_t dev_stop; /**< Stop device. */
414 cryptodev_close_t dev_close; /**< Close device. */
416 cryptodev_info_get_t dev_infos_get; /**< Get device info. */
418 cryptodev_stats_get_t stats_get;
419 /**< Get device statistics. */
420 cryptodev_stats_reset_t stats_reset;
421 /**< Reset device statistics. */
423 cryptodev_queue_pair_setup_t queue_pair_setup;
424 /**< Set up a device queue pair. */
425 cryptodev_queue_pair_release_t queue_pair_release;
426 /**< Release a queue pair. */
427 cryptodev_queue_pair_start_t queue_pair_start;
428 /**< Start a queue pair. */
429 cryptodev_queue_pair_stop_t queue_pair_stop;
430 /**< Stop a queue pair. */
431 cryptodev_queue_pair_count_t queue_pair_count;
432 /**< Get count of the queue pairs. */
434 cryptodev_sym_get_session_private_size_t session_get_size;
435 /**< Return private session. */
436 cryptodev_sym_initialize_session_t session_initialize;
437 /**< Initialization function for private session data */
438 cryptodev_sym_configure_session_t session_configure;
439 /**< Configure a Crypto session. */
440 cryptodev_sym_free_session_t session_clear;
441 /**< Clear a Crypto sessions private data. */
446 * Function for internal use by dummy drivers primarily, e.g. ring-based
448 * Allocates a new cryptodev slot for an crypto device and returns the pointer
449 * to that slot for the driver to use.
451 * @param name Unique identifier name for each device
452 * @param socket_id Socket to allocate resources on.
454 * - Slot in the rte_dev_devices array for a new device;
456 struct rte_cryptodev *
457 rte_cryptodev_pmd_allocate(const char *name, int socket_id);
460 * Creates a new virtual crypto device and returns the pointer
463 * @param name PMD type name
464 * @param dev_private_size Size of crypto PMDs private data
465 * @param socket_id Socket to allocate resources on.
468 * - Cryptodev pointer if device is successfully created.
469 * - NULL if device cannot be created.
471 struct rte_cryptodev *
472 rte_cryptodev_pmd_virtual_dev_init(const char *name, size_t dev_private_size,
477 * Function for internal use by dummy drivers primarily, e.g. ring-based
479 * Release the specified cryptodev device.
482 * The *cryptodev* pointer is the address of the *rte_cryptodev* structure.
484 * - 0 on success, negative on error
487 rte_cryptodev_pmd_release_device(struct rte_cryptodev *cryptodev);
490 * Executes all the user application registered callbacks for the specific
493 * @param dev Pointer to cryptodev struct
494 * @param event Crypto device interrupt event type.
499 void rte_cryptodev_pmd_callback_process(struct rte_cryptodev *dev,
500 enum rte_cryptodev_event_type event);
503 * Wrapper for use by pci drivers as a .probe function to attach to a crypto
506 int rte_cryptodev_pci_probe(struct rte_pci_driver *pci_drv,
507 struct rte_pci_device *pci_dev);
510 * Wrapper for use by pci drivers as a .remove function to detach a crypto
513 int rte_cryptodev_pci_remove(struct rte_pci_device *pci_dev);
519 #endif /* _RTE_CRYPTODEV_PMD_H_ */