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
49 #include <rte_config.h>
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 #define RTE_CRYPTODEV_PMD_DEFAULT_MAX_NB_QUEUE_PAIRS 8
62 #define RTE_CRYPTODEV_PMD_DEFAULT_MAX_NB_SESSIONS 2048
64 #define RTE_CRYPTODEV_PMD_NAME_ARG ("name")
65 #define RTE_CRYPTODEV_PMD_MAX_NB_QP_ARG ("max_nb_queue_pairs")
66 #define RTE_CRYPTODEV_PMD_MAX_NB_SESS_ARG ("max_nb_sessions")
67 #define RTE_CRYPTODEV_PMD_SOCKET_ID_ARG ("socket_id")
70 static const char * const cryptodev_pmd_valid_params[] = {
71 RTE_CRYPTODEV_PMD_NAME_ARG,
72 RTE_CRYPTODEV_PMD_MAX_NB_QP_ARG,
73 RTE_CRYPTODEV_PMD_MAX_NB_SESS_ARG,
74 RTE_CRYPTODEV_PMD_SOCKET_ID_ARG
79 * Initialisation parameters for crypto devices
81 struct rte_cryptodev_pmd_init_params {
82 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
83 size_t private_data_size;
85 unsigned int max_nb_queue_pairs;
86 unsigned int max_nb_sessions;
89 /** Global structure used for maintaining state of allocated crypto devices */
90 struct rte_cryptodev_global {
91 struct rte_cryptodev *devs; /**< Device information array */
92 struct rte_cryptodev_data *data[RTE_CRYPTO_MAX_DEVS];
93 /**< Device private data */
94 uint8_t nb_devs; /**< Number of devices found */
95 uint8_t max_devs; /**< Max number of devices */
98 /* Cryptodev driver, containing the driver ID */
99 struct cryptodev_driver {
100 TAILQ_ENTRY(cryptodev_driver) next; /**< Next in list. */
101 const struct rte_driver *driver;
105 /** pointer to global crypto devices data structure. */
106 extern struct rte_cryptodev_global *rte_cryptodev_globals;
109 * Get the rte_cryptodev structure device pointer for the device. Assumes a
110 * valid device index.
112 * @param dev_id Device ID value to select the device structure.
115 * - The rte_cryptodev structure pointer for the given device ID.
117 struct rte_cryptodev *
118 rte_cryptodev_pmd_get_dev(uint8_t dev_id);
121 * Get the rte_cryptodev structure device pointer for the named device.
123 * @param name device name to select the device structure.
126 * - The rte_cryptodev structure pointer for the given device ID.
128 struct rte_cryptodev *
129 rte_cryptodev_pmd_get_named_dev(const char *name);
132 * Validate if the crypto device index is valid attached crypto device.
134 * @param dev_id Crypto device index.
137 * - If the device index is valid (1) or not (0).
140 rte_cryptodev_pmd_is_valid_dev(uint8_t dev_id);
143 * The pool of rte_cryptodev structures.
145 extern struct rte_cryptodev *rte_cryptodevs;
149 * Definitions of all functions exported by a driver through the
150 * the generic structure of type *crypto_dev_ops* supplied in the
151 * *rte_cryptodev* structure associated with a device.
155 * Function used to configure device.
157 * @param dev Crypto device pointer
158 * config Crypto device configurations
160 * @return Returns 0 on success
162 typedef int (*cryptodev_configure_t)(struct rte_cryptodev *dev,
163 struct rte_cryptodev_config *config);
166 * Function used to start a configured device.
168 * @param dev Crypto device pointer
170 * @return Returns 0 on success
172 typedef int (*cryptodev_start_t)(struct rte_cryptodev *dev);
175 * Function used to stop a configured device.
177 * @param dev Crypto device pointer
179 typedef void (*cryptodev_stop_t)(struct rte_cryptodev *dev);
182 * Function used to close a configured device.
184 * @param dev Crypto device pointer
187 * - EAGAIN if can't close as device is busy
189 typedef int (*cryptodev_close_t)(struct rte_cryptodev *dev);
193 * Function used to get statistics of a device.
195 * @param dev Crypto device pointer
196 * @param stats Pointer to crypto device stats structure to populate
198 typedef void (*cryptodev_stats_get_t)(struct rte_cryptodev *dev,
199 struct rte_cryptodev_stats *stats);
203 * Function used to reset statistics of a device.
205 * @param dev Crypto device pointer
207 typedef void (*cryptodev_stats_reset_t)(struct rte_cryptodev *dev);
211 * Function used to get specific information of a device.
213 * @param dev Crypto device pointer
215 typedef void (*cryptodev_info_get_t)(struct rte_cryptodev *dev,
216 struct rte_cryptodev_info *dev_info);
219 * Start queue pair of a device.
221 * @param dev Crypto device pointer
222 * @param qp_id Queue Pair Index
224 * @return Returns 0 on success.
226 typedef int (*cryptodev_queue_pair_start_t)(struct rte_cryptodev *dev,
230 * Stop queue pair of a device.
232 * @param dev Crypto device pointer
233 * @param qp_id Queue Pair Index
235 * @return Returns 0 on success.
237 typedef int (*cryptodev_queue_pair_stop_t)(struct rte_cryptodev *dev,
241 * Setup a queue pair for a device.
243 * @param dev Crypto device pointer
244 * @param qp_id Queue Pair Index
245 * @param qp_conf Queue configuration structure
246 * @param socket_id Socket Index
247 * @param session_pool Pointer to device session mempool
249 * @return Returns 0 on success.
251 typedef int (*cryptodev_queue_pair_setup_t)(struct rte_cryptodev *dev,
252 uint16_t qp_id, const struct rte_cryptodev_qp_conf *qp_conf,
253 int socket_id, struct rte_mempool *session_pool);
256 * Release memory resources allocated by given queue pair.
258 * @param dev Crypto device pointer
259 * @param qp_id Queue Pair Index
263 * - EAGAIN if can't close as device is busy
265 typedef int (*cryptodev_queue_pair_release_t)(struct rte_cryptodev *dev,
269 * Get number of available queue pairs of a device.
271 * @param dev Crypto device pointer
273 * @return Returns number of queue pairs on success.
275 typedef uint32_t (*cryptodev_queue_pair_count_t)(struct rte_cryptodev *dev);
278 * Create a session mempool to allocate sessions from
280 * @param dev Crypto device pointer
281 * @param nb_objs number of sessions objects in mempool
282 * @param obj_cache l-core object cache size, see *rte_ring_create*
283 * @param socket_id Socket Id to allocate mempool on.
286 * - On success returns a pointer to a rte_mempool
287 * - On failure returns a NULL pointer
289 typedef int (*cryptodev_sym_create_session_pool_t)(
290 struct rte_cryptodev *dev, unsigned nb_objs,
291 unsigned obj_cache_size, int socket_id);
295 * Get the size of a cryptodev session
297 * @param dev Crypto device pointer
300 * - On success returns the size of the session structure for device
301 * - On failure returns 0
303 typedef unsigned (*cryptodev_sym_get_session_private_size_t)(
304 struct rte_cryptodev *dev);
307 * Configure a Crypto session on a device.
309 * @param dev Crypto device pointer
310 * @param xform Single or chain of crypto xforms
311 * @param priv_sess Pointer to cryptodev's private session structure
312 * @param mp Mempool where the private session is allocated
315 * - Returns 0 if private session structure have been created successfully.
316 * - Returns -EINVAL if input parameters are invalid.
317 * - Returns -ENOTSUP if crypto device does not support the crypto transform.
318 * - Returns -ENOMEM if the private session could not be allocated.
320 typedef int (*cryptodev_sym_configure_session_t)(struct rte_cryptodev *dev,
321 struct rte_crypto_sym_xform *xform,
322 struct rte_cryptodev_sym_session *session,
323 struct rte_mempool *mp);
326 * Free driver private session data.
328 * @param dev Crypto device pointer
329 * @param sess Cryptodev session structure
331 typedef void (*cryptodev_sym_free_session_t)(struct rte_cryptodev *dev,
332 struct rte_cryptodev_sym_session *sess);
335 * Optional API for drivers to attach sessions with queue pair.
336 * @param dev Crypto device pointer
337 * @param qp_id queue pair id for attaching session
338 * @param priv_sess Pointer to cryptodev's private session structure
340 * - Return 0 on success
342 typedef int (*cryptodev_sym_queue_pair_attach_session_t)(
343 struct rte_cryptodev *dev,
345 void *session_private);
348 * Optional API for drivers to detach sessions from queue pair.
349 * @param dev Crypto device pointer
350 * @param qp_id queue pair id for detaching session
351 * @param priv_sess Pointer to cryptodev's private session structure
353 * - Return 0 on success
355 typedef int (*cryptodev_sym_queue_pair_detach_session_t)(
356 struct rte_cryptodev *dev,
358 void *session_private);
360 /** Crypto device operations function pointer table */
361 struct rte_cryptodev_ops {
362 cryptodev_configure_t dev_configure; /**< Configure device. */
363 cryptodev_start_t dev_start; /**< Start device. */
364 cryptodev_stop_t dev_stop; /**< Stop device. */
365 cryptodev_close_t dev_close; /**< Close device. */
367 cryptodev_info_get_t dev_infos_get; /**< Get device info. */
369 cryptodev_stats_get_t stats_get;
370 /**< Get device statistics. */
371 cryptodev_stats_reset_t stats_reset;
372 /**< Reset device statistics. */
374 cryptodev_queue_pair_setup_t queue_pair_setup;
375 /**< Set up a device queue pair. */
376 cryptodev_queue_pair_release_t queue_pair_release;
377 /**< Release a queue pair. */
378 cryptodev_queue_pair_start_t queue_pair_start;
379 /**< Start a queue pair. */
380 cryptodev_queue_pair_stop_t queue_pair_stop;
381 /**< Stop a queue pair. */
382 cryptodev_queue_pair_count_t queue_pair_count;
383 /**< Get count of the queue pairs. */
385 cryptodev_sym_get_session_private_size_t session_get_size;
386 /**< Return private session. */
387 cryptodev_sym_configure_session_t session_configure;
388 /**< Configure a Crypto session. */
389 cryptodev_sym_free_session_t session_clear;
390 /**< Clear a Crypto sessions private data. */
391 cryptodev_sym_queue_pair_attach_session_t qp_attach_session;
392 /**< Attach session to queue pair. */
393 cryptodev_sym_queue_pair_detach_session_t qp_detach_session;
394 /**< Detach session from queue pair. */
399 * Function for internal use by dummy drivers primarily, e.g. ring-based
401 * Allocates a new cryptodev slot for an crypto device and returns the pointer
402 * to that slot for the driver to use.
404 * @param name Unique identifier name for each device
405 * @param socket_id Socket to allocate resources on.
407 * - Slot in the rte_dev_devices array for a new device;
409 struct rte_cryptodev *
410 rte_cryptodev_pmd_allocate(const char *name, int socket_id);
413 * Function for internal use by dummy drivers primarily, e.g. ring-based
415 * Release the specified cryptodev device.
418 * The *cryptodev* pointer is the address of the *rte_cryptodev* structure.
420 * - 0 on success, negative on error
423 rte_cryptodev_pmd_release_device(struct rte_cryptodev *cryptodev);
429 * PMD assist function to parse initialisation arguments for crypto driver
430 * when creating a new crypto PMD device instance.
432 * PMD driver should set default values for that PMD before calling function,
433 * these default values will be over-written with successfully parsed values
436 * @param params parsed PMD initialisation parameters
437 * @param args input argument string to parse
444 rte_cryptodev_pmd_parse_input_args(
445 struct rte_cryptodev_pmd_init_params *params,
451 * PMD assist function to provide boiler plate code for crypto driver to create
452 * and allocate resources for a new crypto PMD device instance.
454 * @param name crypto device name.
455 * @param device base device instance
456 * @param params PMD initialisation parameters
459 * - crypto device instance on success
460 * - NULL on creation failure
462 struct rte_cryptodev *
463 rte_cryptodev_pmd_create(const char *name,
464 struct rte_device *device,
465 struct rte_cryptodev_pmd_init_params *params);
470 * PMD assist function to provide boiler plate code for crypto driver to
471 * destroy and free resources associated with a crypto PMD device instance.
473 * @param cryptodev crypto device handle.
480 rte_cryptodev_pmd_destroy(struct rte_cryptodev *cryptodev);
483 * Executes all the user application registered callbacks for the specific
486 * @param dev Pointer to cryptodev struct
487 * @param event Crypto device interrupt event type.
492 void rte_cryptodev_pmd_callback_process(struct rte_cryptodev *dev,
493 enum rte_cryptodev_event_type event);
497 * Create unique device name
500 rte_cryptodev_pmd_create_dev_name(char *name, const char *dev_name_prefix);
504 * Allocate Cryptodev driver.
507 * Pointer to cryptodev_driver.
509 * Pointer to rte_driver.
512 * The driver type identifier
514 uint8_t rte_cryptodev_allocate_driver(struct cryptodev_driver *crypto_drv,
515 const struct rte_driver *drv);
518 #define RTE_PMD_REGISTER_CRYPTO_DRIVER(crypto_drv, drv, driver_id)\
519 RTE_INIT(init_ ##driver_id);\
520 static void init_ ##driver_id(void)\
522 driver_id = rte_cryptodev_allocate_driver(&crypto_drv, &(drv).driver);\
526 get_session_private_data(const struct rte_cryptodev_sym_session *sess,
528 return sess->sess_private_data[driver_id];
532 set_session_private_data(struct rte_cryptodev_sym_session *sess,
533 uint8_t driver_id, void *private_data)
535 sess->sess_private_data[driver_id] = private_data;
542 #endif /* _RTE_CRYPTODEV_PMD_H_ */