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"
61 #ifdef RTE_LIBRTE_CRYPTODEV_DEBUG
62 #define RTE_PMD_DEBUG_TRACE(...) \
63 rte_pmd_debug_trace(__func__, __VA_ARGS__)
65 #define RTE_PMD_DEBUG_TRACE(...)
68 struct rte_cryptodev_session {
72 enum rte_cryptodev_type type;
73 struct rte_mempool *mp;
76 __extension__ char _private[0];
79 struct rte_cryptodev_driver;
82 * Initialisation function of a crypto driver invoked for each matching
83 * crypto PCI device detected during the PCI probing phase.
85 * @param drv The pointer to the [matching] crypto driver structure
86 * supplied by the PMD when it registered itself.
87 * @param dev The dev pointer is the address of the *rte_cryptodev*
88 * structure associated with the matching device and which
89 * has been [automatically] allocated in the
90 * *rte_crypto_devices* array.
93 * - 0: Success, the device is properly initialised by the driver.
94 * In particular, the driver MUST have set up the *dev_ops* pointer
95 * of the *dev* structure.
96 * - <0: Error code of the device initialisation failure.
98 typedef int (*cryptodev_init_t)(struct rte_cryptodev_driver *drv,
99 struct rte_cryptodev *dev);
102 * Finalisation function of a driver invoked for each matching
103 * PCI device detected during the PCI closing phase.
105 * @param drv The pointer to the [matching] driver structure supplied
106 * by the PMD when it registered itself.
107 * @param dev The dev pointer is the address of the *rte_cryptodev*
108 * structure associated with the matching device and which
109 * has been [automatically] allocated in the
110 * *rte_crypto_devices* array.
113 * - 0: Success, the device is properly finalised by the driver.
114 * In particular, the driver MUST free the *dev_ops* pointer
115 * of the *dev* structure.
116 * - <0: Error code of the device initialisation failure.
118 typedef int (*cryptodev_uninit_t)(const struct rte_cryptodev_driver *drv,
119 struct rte_cryptodev *dev);
122 * The structure associated with a PMD driver.
124 * Each driver acts as a PCI driver and is represented by a generic
125 * *crypto_driver* structure that holds:
127 * - An *rte_pci_driver* structure (which must be the first field).
129 * - The *cryptodev_init* function invoked for each matching PCI device.
131 * - The size of the private data to allocate for each matching device.
133 struct rte_cryptodev_driver {
134 struct rte_pci_driver pci_drv; /**< The PMD is also a PCI driver. */
135 unsigned dev_private_size; /**< Size of device private data. */
137 cryptodev_init_t cryptodev_init; /**< Device init function. */
138 cryptodev_uninit_t cryptodev_uninit; /**< Device uninit function. */
142 /** Global structure used for maintaining state of allocated crypto devices */
143 struct rte_cryptodev_global {
144 struct rte_cryptodev *devs; /**< Device information array */
145 struct rte_cryptodev_data *data[RTE_CRYPTO_MAX_DEVS];
146 /**< Device private data */
147 uint8_t nb_devs; /**< Number of devices found */
148 uint8_t max_devs; /**< Max number of devices */
151 /** pointer to global crypto devices data structure. */
152 extern struct rte_cryptodev_global *rte_cryptodev_globals;
155 * Get the rte_cryptodev structure device pointer for the device. Assumes a
156 * valid device index.
158 * @param dev_id Device ID value to select the device structure.
161 * - The rte_cryptodev structure pointer for the given device ID.
163 struct rte_cryptodev *
164 rte_cryptodev_pmd_get_dev(uint8_t dev_id);
167 * Get the rte_cryptodev structure device pointer for the named device.
169 * @param name device name to select the device structure.
172 * - The rte_cryptodev structure pointer for the given device ID.
174 struct rte_cryptodev *
175 rte_cryptodev_pmd_get_named_dev(const char *name);
178 * Validate if the crypto device index is valid attached crypto device.
180 * @param dev_id Crypto device index.
183 * - If the device index is valid (1) or not (0).
186 rte_cryptodev_pmd_is_valid_dev(uint8_t dev_id);
189 * The pool of rte_cryptodev structures.
191 extern struct rte_cryptodev *rte_cryptodevs;
195 * Definitions of all functions exported by a driver through the
196 * the generic structure of type *crypto_dev_ops* supplied in the
197 * *rte_cryptodev* structure associated with a device.
201 * Function used to configure device.
203 * @param dev Crypto device pointer
204 * config Crypto device configurations
206 * @return Returns 0 on success
208 typedef int (*cryptodev_configure_t)(struct rte_cryptodev *dev,
209 struct rte_cryptodev_config *config);
212 * Function used to start a configured device.
214 * @param dev Crypto device pointer
216 * @return Returns 0 on success
218 typedef int (*cryptodev_start_t)(struct rte_cryptodev *dev);
221 * Function used to stop a configured device.
223 * @param dev Crypto device pointer
225 typedef void (*cryptodev_stop_t)(struct rte_cryptodev *dev);
228 * Function used to close a configured device.
230 * @param dev Crypto device pointer
233 * - EAGAIN if can't close as device is busy
235 typedef int (*cryptodev_close_t)(struct rte_cryptodev *dev);
239 * Function used to get statistics of a device.
241 * @param dev Crypto device pointer
242 * @param stats Pointer to crypto device stats structure to populate
244 typedef void (*cryptodev_stats_get_t)(struct rte_cryptodev *dev,
245 struct rte_cryptodev_stats *stats);
249 * Function used to reset statistics of a device.
251 * @param dev Crypto device pointer
253 typedef void (*cryptodev_stats_reset_t)(struct rte_cryptodev *dev);
257 * Function used to get specific information of a device.
259 * @param dev Crypto device pointer
261 typedef void (*cryptodev_info_get_t)(struct rte_cryptodev *dev,
262 struct rte_cryptodev_info *dev_info);
265 * Start queue pair of a device.
267 * @param dev Crypto device pointer
268 * @param qp_id Queue Pair Index
270 * @return Returns 0 on success.
272 typedef int (*cryptodev_queue_pair_start_t)(struct rte_cryptodev *dev,
276 * Stop queue pair of a device.
278 * @param dev Crypto device pointer
279 * @param qp_id Queue Pair Index
281 * @return Returns 0 on success.
283 typedef int (*cryptodev_queue_pair_stop_t)(struct rte_cryptodev *dev,
287 * Setup a queue pair for a device.
289 * @param dev Crypto device pointer
290 * @param qp_id Queue Pair Index
291 * @param qp_conf Queue configuration structure
292 * @param socket_id Socket Index
294 * @return Returns 0 on success.
296 typedef int (*cryptodev_queue_pair_setup_t)(struct rte_cryptodev *dev,
297 uint16_t qp_id, const struct rte_cryptodev_qp_conf *qp_conf,
301 * Release memory resources allocated by given queue pair.
303 * @param dev Crypto device pointer
304 * @param qp_id Queue Pair Index
308 * - EAGAIN if can't close as device is busy
310 typedef int (*cryptodev_queue_pair_release_t)(struct rte_cryptodev *dev,
314 * Get number of available queue pairs of a device.
316 * @param dev Crypto device pointer
318 * @return Returns number of queue pairs on success.
320 typedef uint32_t (*cryptodev_queue_pair_count_t)(struct rte_cryptodev *dev);
323 * Create a session mempool to allocate sessions from
325 * @param dev Crypto device pointer
326 * @param nb_objs number of sessions objects in mempool
327 * @param obj_cache l-core object cache size, see *rte_ring_create*
328 * @param socket_id Socket Id to allocate mempool on.
331 * - On success returns a pointer to a rte_mempool
332 * - On failure returns a NULL pointer
334 typedef int (*cryptodev_sym_create_session_pool_t)(
335 struct rte_cryptodev *dev, unsigned nb_objs,
336 unsigned obj_cache_size, int socket_id);
340 * Get the size of a cryptodev session
342 * @param dev Crypto device pointer
345 * - On success returns the size of the session structure for device
346 * - On failure returns 0
348 typedef unsigned (*cryptodev_sym_get_session_private_size_t)(
349 struct rte_cryptodev *dev);
352 * Initialize a Crypto session on a device.
354 * @param dev Crypto device pointer
355 * @param xform Single or chain of crypto xforms
356 * @param priv_sess Pointer to cryptodev's private session structure
359 * - Returns private session structure on success.
360 * - Returns NULL on failure.
362 typedef void (*cryptodev_sym_initialize_session_t)(struct rte_mempool *mempool,
363 void *session_private);
366 * Configure a Crypto session on a device.
368 * @param dev Crypto device pointer
369 * @param xform Single or chain of crypto xforms
370 * @param priv_sess Pointer to cryptodev's private session structure
373 * - Returns private session structure on success.
374 * - Returns NULL on failure.
376 typedef void * (*cryptodev_sym_configure_session_t)(struct rte_cryptodev *dev,
377 struct rte_crypto_sym_xform *xform, void *session_private);
380 * Free Crypto session.
381 * @param session Cryptodev session structure to free
383 typedef void (*cryptodev_sym_free_session_t)(struct rte_cryptodev *dev,
384 void *session_private);
387 * Optional API for drivers to attach sessions with queue pair.
388 * @param dev Crypto device pointer
389 * @param qp_id queue pair id for attaching session
390 * @param priv_sess Pointer to cryptodev's private session structure
392 * - Return 0 on success
394 typedef int (*cryptodev_sym_queue_pair_attach_session_t)(
395 struct rte_cryptodev *dev,
397 void *session_private);
400 * Optional API for drivers to detach sessions from queue pair.
401 * @param dev Crypto device pointer
402 * @param qp_id queue pair id for detaching session
403 * @param priv_sess Pointer to cryptodev's private session structure
405 * - Return 0 on success
407 typedef int (*cryptodev_sym_queue_pair_detach_session_t)(
408 struct rte_cryptodev *dev,
410 void *session_private);
412 /** Crypto device operations function pointer table */
413 struct rte_cryptodev_ops {
414 cryptodev_configure_t dev_configure; /**< Configure device. */
415 cryptodev_start_t dev_start; /**< Start device. */
416 cryptodev_stop_t dev_stop; /**< Stop device. */
417 cryptodev_close_t dev_close; /**< Close device. */
419 cryptodev_info_get_t dev_infos_get; /**< Get device info. */
421 cryptodev_stats_get_t stats_get;
422 /**< Get device statistics. */
423 cryptodev_stats_reset_t stats_reset;
424 /**< Reset device statistics. */
426 cryptodev_queue_pair_setup_t queue_pair_setup;
427 /**< Set up a device queue pair. */
428 cryptodev_queue_pair_release_t queue_pair_release;
429 /**< Release a queue pair. */
430 cryptodev_queue_pair_start_t queue_pair_start;
431 /**< Start a queue pair. */
432 cryptodev_queue_pair_stop_t queue_pair_stop;
433 /**< Stop a queue pair. */
434 cryptodev_queue_pair_count_t queue_pair_count;
435 /**< Get count of the queue pairs. */
437 cryptodev_sym_get_session_private_size_t session_get_size;
438 /**< Return private session. */
439 cryptodev_sym_initialize_session_t session_initialize;
440 /**< Initialization function for private session data */
441 cryptodev_sym_configure_session_t session_configure;
442 /**< Configure a Crypto session. */
443 cryptodev_sym_free_session_t session_clear;
444 /**< Clear a Crypto sessions private data. */
445 cryptodev_sym_queue_pair_attach_session_t qp_attach_session;
446 /**< Attach session to queue pair. */
447 cryptodev_sym_queue_pair_attach_session_t qp_detach_session;
448 /**< Detach session from queue pair. */
453 * Function for internal use by dummy drivers primarily, e.g. ring-based
455 * Allocates a new cryptodev slot for an crypto device and returns the pointer
456 * to that slot for the driver to use.
458 * @param name Unique identifier name for each device
459 * @param socket_id Socket to allocate resources on.
461 * - Slot in the rte_dev_devices array for a new device;
463 struct rte_cryptodev *
464 rte_cryptodev_pmd_allocate(const char *name, int socket_id);
467 * Creates a new virtual crypto device and returns the pointer
470 * @param name PMD type name
471 * @param dev_private_size Size of crypto PMDs private data
472 * @param socket_id Socket to allocate resources on.
475 * - Cryptodev pointer if device is successfully created.
476 * - NULL if device cannot be created.
478 struct rte_cryptodev *
479 rte_cryptodev_pmd_virtual_dev_init(const char *name, size_t dev_private_size,
484 * Function for internal use by dummy drivers primarily, e.g. ring-based
486 * Release the specified cryptodev device.
489 * The *cryptodev* pointer is the address of the *rte_cryptodev* structure.
491 * - 0 on success, negative on error
494 rte_cryptodev_pmd_release_device(struct rte_cryptodev *cryptodev);
497 * Executes all the user application registered callbacks for the specific
500 * @param dev Pointer to cryptodev struct
501 * @param event Crypto device interrupt event type.
506 void rte_cryptodev_pmd_callback_process(struct rte_cryptodev *dev,
507 enum rte_cryptodev_event_type event);
510 * Wrapper for use by pci drivers as a .probe function to attach to a crypto
513 int rte_cryptodev_pci_probe(struct rte_pci_driver *pci_drv,
514 struct rte_pci_device *pci_dev);
517 * Wrapper for use by pci drivers as a .remove function to detach a crypto
520 int rte_cryptodev_pci_remove(struct rte_pci_device *pci_dev);
524 * Create unique device name
527 rte_cryptodev_pmd_create_dev_name(char *name, const char *dev_name_prefix);
533 #endif /* _RTE_CRYPTODEV_PMD_H_ */