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 /** Global structure used for maintaining state of allocated crypto devices */
60 struct rte_cryptodev_global {
61 struct rte_cryptodev *devs; /**< Device information array */
62 struct rte_cryptodev_data *data[RTE_CRYPTO_MAX_DEVS];
63 /**< Device private data */
64 uint8_t nb_devs; /**< Number of devices found */
65 uint8_t max_devs; /**< Max number of devices */
68 /** pointer to global crypto devices data structure. */
69 extern struct rte_cryptodev_global *rte_cryptodev_globals;
72 * Get the rte_cryptodev structure device pointer for the device. Assumes a
75 * @param dev_id Device ID value to select the device structure.
78 * - 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.
91 struct rte_cryptodev *
92 rte_cryptodev_pmd_get_named_dev(const char *name);
95 * Validate if the crypto device index is valid attached crypto device.
97 * @param dev_id Crypto device index.
100 * - If the device index is valid (1) or not (0).
103 rte_cryptodev_pmd_is_valid_dev(uint8_t dev_id);
106 * The pool of rte_cryptodev structures.
108 extern struct rte_cryptodev *rte_cryptodevs;
112 * Definitions of all functions exported by a driver through the
113 * the generic structure of type *crypto_dev_ops* supplied in the
114 * *rte_cryptodev* structure associated with a device.
118 * Function used to configure device.
120 * @param dev Crypto device pointer
121 * config Crypto device configurations
123 * @return Returns 0 on success
125 typedef int (*cryptodev_configure_t)(struct rte_cryptodev *dev,
126 struct rte_cryptodev_config *config);
129 * Function used to start a configured device.
131 * @param dev Crypto device pointer
133 * @return Returns 0 on success
135 typedef int (*cryptodev_start_t)(struct rte_cryptodev *dev);
138 * Function used to stop a configured device.
140 * @param dev Crypto device pointer
142 typedef void (*cryptodev_stop_t)(struct rte_cryptodev *dev);
145 * Function used to close a configured device.
147 * @param dev Crypto device pointer
150 * - EAGAIN if can't close as device is busy
152 typedef int (*cryptodev_close_t)(struct rte_cryptodev *dev);
156 * Function used to get statistics of a device.
158 * @param dev Crypto device pointer
159 * @param stats Pointer to crypto device stats structure to populate
161 typedef void (*cryptodev_stats_get_t)(struct rte_cryptodev *dev,
162 struct rte_cryptodev_stats *stats);
166 * Function used to reset statistics of a device.
168 * @param dev Crypto device pointer
170 typedef void (*cryptodev_stats_reset_t)(struct rte_cryptodev *dev);
174 * Function used to get specific information of a device.
176 * @param dev Crypto device pointer
178 typedef void (*cryptodev_info_get_t)(struct rte_cryptodev *dev,
179 struct rte_cryptodev_info *dev_info);
182 * Start queue pair of a device.
184 * @param dev Crypto device pointer
185 * @param qp_id Queue Pair Index
187 * @return Returns 0 on success.
189 typedef int (*cryptodev_queue_pair_start_t)(struct rte_cryptodev *dev,
193 * Stop 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_stop_t)(struct rte_cryptodev *dev,
204 * Setup a queue pair for a device.
206 * @param dev Crypto device pointer
207 * @param qp_id Queue Pair Index
208 * @param qp_conf Queue configuration structure
209 * @param socket_id Socket Index
211 * @return Returns 0 on success.
213 typedef int (*cryptodev_queue_pair_setup_t)(struct rte_cryptodev *dev,
214 uint16_t qp_id, const struct rte_cryptodev_qp_conf *qp_conf,
218 * Release memory resources allocated by given queue pair.
220 * @param dev Crypto device pointer
221 * @param qp_id Queue Pair Index
225 * - EAGAIN if can't close as device is busy
227 typedef int (*cryptodev_queue_pair_release_t)(struct rte_cryptodev *dev,
231 * Get number of available queue pairs of a device.
233 * @param dev Crypto device pointer
235 * @return Returns number of queue pairs on success.
237 typedef uint32_t (*cryptodev_queue_pair_count_t)(struct rte_cryptodev *dev);
240 * Create a session mempool to allocate sessions from
242 * @param dev Crypto device pointer
243 * @param nb_objs number of sessions objects in mempool
244 * @param obj_cache l-core object cache size, see *rte_ring_create*
245 * @param socket_id Socket Id to allocate mempool on.
248 * - On success returns a pointer to a rte_mempool
249 * - On failure returns a NULL pointer
251 typedef int (*cryptodev_sym_create_session_pool_t)(
252 struct rte_cryptodev *dev, unsigned nb_objs,
253 unsigned obj_cache_size, int socket_id);
257 * Get the size of a cryptodev session
259 * @param dev Crypto device pointer
262 * - On success returns the size of the session structure for device
263 * - On failure returns 0
265 typedef unsigned (*cryptodev_sym_get_session_private_size_t)(
266 struct rte_cryptodev *dev);
269 * Initialize a Crypto session on a device.
271 * @param dev Crypto device pointer
272 * @param xform Single or chain of crypto xforms
273 * @param priv_sess Pointer to cryptodev's private session structure
276 * - Returns private session structure on success.
277 * - Returns NULL on failure.
279 typedef void (*cryptodev_sym_initialize_session_t)(struct rte_mempool *mempool,
280 void *session_private);
283 * Configure a Crypto session on a device.
285 * @param dev Crypto device pointer
286 * @param xform Single or chain of crypto xforms
287 * @param priv_sess Pointer to cryptodev's private session structure
290 * - Returns private session structure on success.
291 * - Returns NULL on failure.
293 typedef void * (*cryptodev_sym_configure_session_t)(struct rte_cryptodev *dev,
294 struct rte_crypto_sym_xform *xform, void *session_private);
297 * Free Crypto session.
298 * @param session Cryptodev session structure to free
300 typedef void (*cryptodev_sym_free_session_t)(struct rte_cryptodev *dev,
301 void *session_private);
304 * Optional API for drivers to attach sessions with queue pair.
305 * @param dev Crypto device pointer
306 * @param qp_id queue pair id for attaching session
307 * @param priv_sess Pointer to cryptodev's private session structure
309 * - Return 0 on success
311 typedef int (*cryptodev_sym_queue_pair_attach_session_t)(
312 struct rte_cryptodev *dev,
314 void *session_private);
317 * Optional API for drivers to detach sessions from queue pair.
318 * @param dev Crypto device pointer
319 * @param qp_id queue pair id for detaching session
320 * @param priv_sess Pointer to cryptodev's private session structure
322 * - Return 0 on success
324 typedef int (*cryptodev_sym_queue_pair_detach_session_t)(
325 struct rte_cryptodev *dev,
327 void *session_private);
329 /** Crypto device operations function pointer table */
330 struct rte_cryptodev_ops {
331 cryptodev_configure_t dev_configure; /**< Configure device. */
332 cryptodev_start_t dev_start; /**< Start device. */
333 cryptodev_stop_t dev_stop; /**< Stop device. */
334 cryptodev_close_t dev_close; /**< Close device. */
336 cryptodev_info_get_t dev_infos_get; /**< Get device info. */
338 cryptodev_stats_get_t stats_get;
339 /**< Get device statistics. */
340 cryptodev_stats_reset_t stats_reset;
341 /**< Reset device statistics. */
343 cryptodev_queue_pair_setup_t queue_pair_setup;
344 /**< Set up a device queue pair. */
345 cryptodev_queue_pair_release_t queue_pair_release;
346 /**< Release a queue pair. */
347 cryptodev_queue_pair_start_t queue_pair_start;
348 /**< Start a queue pair. */
349 cryptodev_queue_pair_stop_t queue_pair_stop;
350 /**< Stop a queue pair. */
351 cryptodev_queue_pair_count_t queue_pair_count;
352 /**< Get count of the queue pairs. */
354 cryptodev_sym_get_session_private_size_t session_get_size;
355 /**< Return private session. */
356 cryptodev_sym_initialize_session_t session_initialize;
357 /**< Initialization function for private session data */
358 cryptodev_sym_configure_session_t session_configure;
359 /**< Configure a Crypto session. */
360 cryptodev_sym_free_session_t session_clear;
361 /**< Clear a Crypto sessions private data. */
362 cryptodev_sym_queue_pair_attach_session_t qp_attach_session;
363 /**< Attach session to queue pair. */
364 cryptodev_sym_queue_pair_attach_session_t qp_detach_session;
365 /**< Detach session from queue pair. */
370 * Function for internal use by dummy drivers primarily, e.g. ring-based
372 * Allocates a new cryptodev slot for an crypto device and returns the pointer
373 * to that slot for the driver to use.
375 * @param name Unique identifier name for each device
376 * @param socket_id Socket to allocate resources on.
378 * - Slot in the rte_dev_devices array for a new device;
380 struct rte_cryptodev *
381 rte_cryptodev_pmd_allocate(const char *name, int socket_id);
384 * Function for internal use by dummy drivers primarily, e.g. ring-based
386 * Release the specified cryptodev device.
389 * The *cryptodev* pointer is the address of the *rte_cryptodev* structure.
391 * - 0 on success, negative on error
394 rte_cryptodev_pmd_release_device(struct rte_cryptodev *cryptodev);
397 * Executes all the user application registered callbacks for the specific
400 * @param dev Pointer to cryptodev struct
401 * @param event Crypto device interrupt event type.
406 void rte_cryptodev_pmd_callback_process(struct rte_cryptodev *dev,
407 enum rte_cryptodev_event_type event);
411 * Create unique device name
414 rte_cryptodev_pmd_create_dev_name(char *name, const char *dev_name_prefix);
420 #endif /* _RTE_CRYPTODEV_PMD_H_ */