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
50 #include <rte_malloc.h>
52 #include <rte_mempool.h>
54 #include <rte_common.h>
56 #include "rte_crypto.h"
57 #include "rte_cryptodev.h"
59 struct rte_cryptodev_session {
63 enum rte_cryptodev_type type;
64 struct rte_mempool *mp;
67 __extension__ char _private[0];
70 /** Global structure used for maintaining state of allocated crypto devices */
71 struct rte_cryptodev_global {
72 struct rte_cryptodev *devs; /**< Device information array */
73 struct rte_cryptodev_data *data[RTE_CRYPTO_MAX_DEVS];
74 /**< Device private data */
75 uint8_t nb_devs; /**< Number of devices found */
76 uint8_t max_devs; /**< Max number of devices */
79 /** pointer to global crypto devices data structure. */
80 extern struct rte_cryptodev_global *rte_cryptodev_globals;
83 * Get the rte_cryptodev structure device pointer for the device. Assumes a
86 * @param dev_id Device ID value to select the device structure.
89 * - The rte_cryptodev structure pointer for the given device ID.
91 struct rte_cryptodev *
92 rte_cryptodev_pmd_get_dev(uint8_t dev_id);
95 * Get the rte_cryptodev structure device pointer for the named device.
97 * @param name device name to select the device structure.
100 * - The rte_cryptodev structure pointer for the given device ID.
102 struct rte_cryptodev *
103 rte_cryptodev_pmd_get_named_dev(const char *name);
106 * Validate if the crypto device index is valid attached crypto device.
108 * @param dev_id Crypto device index.
111 * - If the device index is valid (1) or not (0).
114 rte_cryptodev_pmd_is_valid_dev(uint8_t dev_id);
117 * The pool of rte_cryptodev structures.
119 extern struct rte_cryptodev *rte_cryptodevs;
123 * Definitions of all functions exported by a driver through the
124 * the generic structure of type *crypto_dev_ops* supplied in the
125 * *rte_cryptodev* structure associated with a device.
129 * Function used to configure device.
131 * @param dev Crypto device pointer
132 * config Crypto device configurations
134 * @return Returns 0 on success
136 typedef int (*cryptodev_configure_t)(struct rte_cryptodev *dev,
137 struct rte_cryptodev_config *config);
140 * Function used to start a configured device.
142 * @param dev Crypto device pointer
144 * @return Returns 0 on success
146 typedef int (*cryptodev_start_t)(struct rte_cryptodev *dev);
149 * Function used to stop a configured device.
151 * @param dev Crypto device pointer
153 typedef void (*cryptodev_stop_t)(struct rte_cryptodev *dev);
156 * Function used to close a configured device.
158 * @param dev Crypto device pointer
161 * - EAGAIN if can't close as device is busy
163 typedef int (*cryptodev_close_t)(struct rte_cryptodev *dev);
167 * Function used to get statistics of a device.
169 * @param dev Crypto device pointer
170 * @param stats Pointer to crypto device stats structure to populate
172 typedef void (*cryptodev_stats_get_t)(struct rte_cryptodev *dev,
173 struct rte_cryptodev_stats *stats);
177 * Function used to reset statistics of a device.
179 * @param dev Crypto device pointer
181 typedef void (*cryptodev_stats_reset_t)(struct rte_cryptodev *dev);
185 * Function used to get specific information of a device.
187 * @param dev Crypto device pointer
189 typedef void (*cryptodev_info_get_t)(struct rte_cryptodev *dev,
190 struct rte_cryptodev_info *dev_info);
193 * Start queue pair of a device.
195 * @param dev Crypto device pointer
196 * @param qp_id Queue Pair Index
198 * @return Returns 0 on success.
200 typedef int (*cryptodev_queue_pair_start_t)(struct rte_cryptodev *dev,
204 * Stop queue pair of a device.
206 * @param dev Crypto device pointer
207 * @param qp_id Queue Pair Index
209 * @return Returns 0 on success.
211 typedef int (*cryptodev_queue_pair_stop_t)(struct rte_cryptodev *dev,
215 * Setup a queue pair for a device.
217 * @param dev Crypto device pointer
218 * @param qp_id Queue Pair Index
219 * @param qp_conf Queue configuration structure
220 * @param socket_id Socket Index
222 * @return Returns 0 on success.
224 typedef int (*cryptodev_queue_pair_setup_t)(struct rte_cryptodev *dev,
225 uint16_t qp_id, const struct rte_cryptodev_qp_conf *qp_conf,
229 * Release memory resources allocated by given queue pair.
231 * @param dev Crypto device pointer
232 * @param qp_id Queue Pair Index
236 * - EAGAIN if can't close as device is busy
238 typedef int (*cryptodev_queue_pair_release_t)(struct rte_cryptodev *dev,
242 * Get number of available queue pairs of a device.
244 * @param dev Crypto device pointer
246 * @return Returns number of queue pairs on success.
248 typedef uint32_t (*cryptodev_queue_pair_count_t)(struct rte_cryptodev *dev);
251 * Create a session mempool to allocate sessions from
253 * @param dev Crypto device pointer
254 * @param nb_objs number of sessions objects in mempool
255 * @param obj_cache l-core object cache size, see *rte_ring_create*
256 * @param socket_id Socket Id to allocate mempool on.
259 * - On success returns a pointer to a rte_mempool
260 * - On failure returns a NULL pointer
262 typedef int (*cryptodev_sym_create_session_pool_t)(
263 struct rte_cryptodev *dev, unsigned nb_objs,
264 unsigned obj_cache_size, int socket_id);
268 * Get the size of a cryptodev session
270 * @param dev Crypto device pointer
273 * - On success returns the size of the session structure for device
274 * - On failure returns 0
276 typedef unsigned (*cryptodev_sym_get_session_private_size_t)(
277 struct rte_cryptodev *dev);
280 * Initialize a Crypto session on a device.
282 * @param dev Crypto device pointer
283 * @param xform Single or chain of crypto xforms
284 * @param priv_sess Pointer to cryptodev's private session structure
287 * - Returns private session structure on success.
288 * - Returns NULL on failure.
290 typedef void (*cryptodev_sym_initialize_session_t)(struct rte_mempool *mempool,
291 void *session_private);
294 * Configure a Crypto session on a device.
296 * @param dev Crypto device pointer
297 * @param xform Single or chain of crypto xforms
298 * @param priv_sess Pointer to cryptodev's private session structure
301 * - Returns private session structure on success.
302 * - Returns NULL on failure.
304 typedef void * (*cryptodev_sym_configure_session_t)(struct rte_cryptodev *dev,
305 struct rte_crypto_sym_xform *xform, void *session_private);
308 * Free Crypto session.
309 * @param session Cryptodev session structure to free
311 typedef void (*cryptodev_sym_free_session_t)(struct rte_cryptodev *dev,
312 void *session_private);
315 * Optional API for drivers to attach sessions with queue pair.
316 * @param dev Crypto device pointer
317 * @param qp_id queue pair id for attaching session
318 * @param priv_sess Pointer to cryptodev's private session structure
320 * - Return 0 on success
322 typedef int (*cryptodev_sym_queue_pair_attach_session_t)(
323 struct rte_cryptodev *dev,
325 void *session_private);
328 * Optional API for drivers to detach sessions from queue pair.
329 * @param dev Crypto device pointer
330 * @param qp_id queue pair id for detaching session
331 * @param priv_sess Pointer to cryptodev's private session structure
333 * - Return 0 on success
335 typedef int (*cryptodev_sym_queue_pair_detach_session_t)(
336 struct rte_cryptodev *dev,
338 void *session_private);
340 /** Crypto device operations function pointer table */
341 struct rte_cryptodev_ops {
342 cryptodev_configure_t dev_configure; /**< Configure device. */
343 cryptodev_start_t dev_start; /**< Start device. */
344 cryptodev_stop_t dev_stop; /**< Stop device. */
345 cryptodev_close_t dev_close; /**< Close device. */
347 cryptodev_info_get_t dev_infos_get; /**< Get device info. */
349 cryptodev_stats_get_t stats_get;
350 /**< Get device statistics. */
351 cryptodev_stats_reset_t stats_reset;
352 /**< Reset device statistics. */
354 cryptodev_queue_pair_setup_t queue_pair_setup;
355 /**< Set up a device queue pair. */
356 cryptodev_queue_pair_release_t queue_pair_release;
357 /**< Release a queue pair. */
358 cryptodev_queue_pair_start_t queue_pair_start;
359 /**< Start a queue pair. */
360 cryptodev_queue_pair_stop_t queue_pair_stop;
361 /**< Stop a queue pair. */
362 cryptodev_queue_pair_count_t queue_pair_count;
363 /**< Get count of the queue pairs. */
365 cryptodev_sym_get_session_private_size_t session_get_size;
366 /**< Return private session. */
367 cryptodev_sym_initialize_session_t session_initialize;
368 /**< Initialization function for private session data */
369 cryptodev_sym_configure_session_t session_configure;
370 /**< Configure a Crypto session. */
371 cryptodev_sym_free_session_t session_clear;
372 /**< Clear a Crypto sessions private data. */
373 cryptodev_sym_queue_pair_attach_session_t qp_attach_session;
374 /**< Attach session to queue pair. */
375 cryptodev_sym_queue_pair_attach_session_t qp_detach_session;
376 /**< Detach session from queue pair. */
381 * Function for internal use by dummy drivers primarily, e.g. ring-based
383 * Allocates a new cryptodev slot for an crypto device and returns the pointer
384 * to that slot for the driver to use.
386 * @param name Unique identifier name for each device
387 * @param socket_id Socket to allocate resources on.
389 * - Slot in the rte_dev_devices array for a new device;
391 struct rte_cryptodev *
392 rte_cryptodev_pmd_allocate(const char *name, int socket_id);
395 * Function for internal use by dummy drivers primarily, e.g. ring-based
397 * Release the specified cryptodev device.
400 * The *cryptodev* pointer is the address of the *rte_cryptodev* structure.
402 * - 0 on success, negative on error
405 rte_cryptodev_pmd_release_device(struct rte_cryptodev *cryptodev);
408 * Executes all the user application registered callbacks for the specific
411 * @param dev Pointer to cryptodev struct
412 * @param event Crypto device interrupt event type.
417 void rte_cryptodev_pmd_callback_process(struct rte_cryptodev *dev,
418 enum rte_cryptodev_event_type event);
422 * Create unique device name
425 rte_cryptodev_pmd_create_dev_name(char *name, const char *dev_name_prefix);
431 #endif /* _RTE_CRYPTODEV_PMD_H_ */