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"
60 #define RTE_CRYPTODEV_PMD_DEFAULT_MAX_NB_QUEUE_PAIRS 8
61 #define RTE_CRYPTODEV_PMD_DEFAULT_MAX_NB_SESSIONS 2048
63 #define RTE_CRYPTODEV_PMD_NAME_ARG ("name")
64 #define RTE_CRYPTODEV_PMD_MAX_NB_QP_ARG ("max_nb_queue_pairs")
65 #define RTE_CRYPTODEV_PMD_MAX_NB_SESS_ARG ("max_nb_sessions")
66 #define RTE_CRYPTODEV_PMD_SOCKET_ID_ARG ("socket_id")
69 static const char * const cryptodev_pmd_valid_params[] = {
70 RTE_CRYPTODEV_PMD_NAME_ARG,
71 RTE_CRYPTODEV_PMD_MAX_NB_QP_ARG,
72 RTE_CRYPTODEV_PMD_MAX_NB_SESS_ARG,
73 RTE_CRYPTODEV_PMD_SOCKET_ID_ARG
78 * Initialisation parameters for crypto devices
80 struct rte_cryptodev_pmd_init_params {
81 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
82 size_t private_data_size;
84 unsigned int max_nb_queue_pairs;
85 unsigned int max_nb_sessions;
88 /** Global structure used for maintaining state of allocated crypto devices */
89 struct rte_cryptodev_global {
90 struct rte_cryptodev *devs; /**< Device information array */
91 struct rte_cryptodev_data *data[RTE_CRYPTO_MAX_DEVS];
92 /**< Device private data */
93 uint8_t nb_devs; /**< Number of devices found */
94 uint8_t max_devs; /**< Max number of devices */
97 /* Cryptodev driver, containing the driver ID */
98 struct cryptodev_driver {
99 TAILQ_ENTRY(cryptodev_driver) next; /**< Next in list. */
100 const struct rte_driver *driver;
104 /** pointer to global crypto devices data structure. */
105 extern struct rte_cryptodev_global *rte_cryptodev_globals;
108 * Get the rte_cryptodev structure device pointer for the device. Assumes a
109 * valid device index.
111 * @param dev_id Device ID value to select the device structure.
114 * - The rte_cryptodev structure pointer for the given device ID.
116 struct rte_cryptodev *
117 rte_cryptodev_pmd_get_dev(uint8_t dev_id);
120 * Get the rte_cryptodev structure device pointer for the named device.
122 * @param name device name to select the device structure.
125 * - The rte_cryptodev structure pointer for the given device ID.
127 struct rte_cryptodev *
128 rte_cryptodev_pmd_get_named_dev(const char *name);
131 * Validate if the crypto device index is valid attached crypto device.
133 * @param dev_id Crypto device index.
136 * - If the device index is valid (1) or not (0).
139 rte_cryptodev_pmd_is_valid_dev(uint8_t dev_id);
142 * The pool of rte_cryptodev structures.
144 extern struct rte_cryptodev *rte_cryptodevs;
148 * Definitions of all functions exported by a driver through the
149 * the generic structure of type *crypto_dev_ops* supplied in the
150 * *rte_cryptodev* structure associated with a device.
154 * Function used to configure device.
156 * @param dev Crypto device pointer
157 * config Crypto device configurations
159 * @return Returns 0 on success
161 typedef int (*cryptodev_configure_t)(struct rte_cryptodev *dev,
162 struct rte_cryptodev_config *config);
165 * Function used to start a configured device.
167 * @param dev Crypto device pointer
169 * @return Returns 0 on success
171 typedef int (*cryptodev_start_t)(struct rte_cryptodev *dev);
174 * Function used to stop a configured device.
176 * @param dev Crypto device pointer
178 typedef void (*cryptodev_stop_t)(struct rte_cryptodev *dev);
181 * Function used to close a configured device.
183 * @param dev Crypto device pointer
186 * - EAGAIN if can't close as device is busy
188 typedef int (*cryptodev_close_t)(struct rte_cryptodev *dev);
192 * Function used to get statistics of a device.
194 * @param dev Crypto device pointer
195 * @param stats Pointer to crypto device stats structure to populate
197 typedef void (*cryptodev_stats_get_t)(struct rte_cryptodev *dev,
198 struct rte_cryptodev_stats *stats);
202 * Function used to reset statistics of a device.
204 * @param dev Crypto device pointer
206 typedef void (*cryptodev_stats_reset_t)(struct rte_cryptodev *dev);
210 * Function used to get specific information of a device.
212 * @param dev Crypto device pointer
214 typedef void (*cryptodev_info_get_t)(struct rte_cryptodev *dev,
215 struct rte_cryptodev_info *dev_info);
218 * Start queue pair of a device.
220 * @param dev Crypto device pointer
221 * @param qp_id Queue Pair Index
223 * @return Returns 0 on success.
225 typedef int (*cryptodev_queue_pair_start_t)(struct rte_cryptodev *dev,
229 * Stop queue pair of a device.
231 * @param dev Crypto device pointer
232 * @param qp_id Queue Pair Index
234 * @return Returns 0 on success.
236 typedef int (*cryptodev_queue_pair_stop_t)(struct rte_cryptodev *dev,
240 * Setup a queue pair for a device.
242 * @param dev Crypto device pointer
243 * @param qp_id Queue Pair Index
244 * @param qp_conf Queue configuration structure
245 * @param socket_id Socket Index
246 * @param session_pool Pointer to device session mempool
248 * @return Returns 0 on success.
250 typedef int (*cryptodev_queue_pair_setup_t)(struct rte_cryptodev *dev,
251 uint16_t qp_id, const struct rte_cryptodev_qp_conf *qp_conf,
252 int socket_id, struct rte_mempool *session_pool);
255 * Release memory resources allocated by given queue pair.
257 * @param dev Crypto device pointer
258 * @param qp_id Queue Pair Index
262 * - EAGAIN if can't close as device is busy
264 typedef int (*cryptodev_queue_pair_release_t)(struct rte_cryptodev *dev,
268 * Get number of available queue pairs of a device.
270 * @param dev Crypto device pointer
272 * @return Returns number of queue pairs on success.
274 typedef uint32_t (*cryptodev_queue_pair_count_t)(struct rte_cryptodev *dev);
277 * Create a session mempool to allocate sessions from
279 * @param dev Crypto device pointer
280 * @param nb_objs number of sessions objects in mempool
281 * @param obj_cache l-core object cache size, see *rte_ring_create*
282 * @param socket_id Socket Id to allocate mempool on.
285 * - On success returns a pointer to a rte_mempool
286 * - On failure returns a NULL pointer
288 typedef int (*cryptodev_sym_create_session_pool_t)(
289 struct rte_cryptodev *dev, unsigned nb_objs,
290 unsigned obj_cache_size, int socket_id);
294 * Get the size of a cryptodev session
296 * @param dev Crypto device pointer
299 * - On success returns the size of the session structure for device
300 * - On failure returns 0
302 typedef unsigned (*cryptodev_sym_get_session_private_size_t)(
303 struct rte_cryptodev *dev);
306 * Configure a Crypto session on a device.
308 * @param dev Crypto device pointer
309 * @param xform Single or chain of crypto xforms
310 * @param priv_sess Pointer to cryptodev's private session structure
311 * @param mp Mempool where the private session is allocated
314 * - Returns 0 if private session structure have been created successfully.
315 * - Returns -EINVAL if input parameters are invalid.
316 * - Returns -ENOTSUP if crypto device does not support the crypto transform.
317 * - Returns -ENOMEM if the private session could not be allocated.
319 typedef int (*cryptodev_sym_configure_session_t)(struct rte_cryptodev *dev,
320 struct rte_crypto_sym_xform *xform,
321 struct rte_cryptodev_sym_session *session,
322 struct rte_mempool *mp);
325 * Free driver private session data.
327 * @param dev Crypto device pointer
328 * @param sess Cryptodev session structure
330 typedef void (*cryptodev_sym_free_session_t)(struct rte_cryptodev *dev,
331 struct rte_cryptodev_sym_session *sess);
334 * Optional API for drivers to attach sessions with queue pair.
335 * @param dev Crypto device pointer
336 * @param qp_id queue pair id for attaching session
337 * @param priv_sess Pointer to cryptodev's private session structure
339 * - Return 0 on success
341 typedef int (*cryptodev_sym_queue_pair_attach_session_t)(
342 struct rte_cryptodev *dev,
344 void *session_private);
347 * Optional API for drivers to detach sessions from queue pair.
348 * @param dev Crypto device pointer
349 * @param qp_id queue pair id for detaching session
350 * @param priv_sess Pointer to cryptodev's private session structure
352 * - Return 0 on success
354 typedef int (*cryptodev_sym_queue_pair_detach_session_t)(
355 struct rte_cryptodev *dev,
357 void *session_private);
359 /** Crypto device operations function pointer table */
360 struct rte_cryptodev_ops {
361 cryptodev_configure_t dev_configure; /**< Configure device. */
362 cryptodev_start_t dev_start; /**< Start device. */
363 cryptodev_stop_t dev_stop; /**< Stop device. */
364 cryptodev_close_t dev_close; /**< Close device. */
366 cryptodev_info_get_t dev_infos_get; /**< Get device info. */
368 cryptodev_stats_get_t stats_get;
369 /**< Get device statistics. */
370 cryptodev_stats_reset_t stats_reset;
371 /**< Reset device statistics. */
373 cryptodev_queue_pair_setup_t queue_pair_setup;
374 /**< Set up a device queue pair. */
375 cryptodev_queue_pair_release_t queue_pair_release;
376 /**< Release a queue pair. */
377 cryptodev_queue_pair_start_t queue_pair_start;
378 /**< Start a queue pair. */
379 cryptodev_queue_pair_stop_t queue_pair_stop;
380 /**< Stop a queue pair. */
381 cryptodev_queue_pair_count_t queue_pair_count;
382 /**< Get count of the queue pairs. */
384 cryptodev_sym_get_session_private_size_t session_get_size;
385 /**< Return private session. */
386 cryptodev_sym_configure_session_t session_configure;
387 /**< Configure a Crypto session. */
388 cryptodev_sym_free_session_t session_clear;
389 /**< Clear a Crypto sessions private data. */
390 cryptodev_sym_queue_pair_attach_session_t qp_attach_session;
391 /**< Attach session to queue pair. */
392 cryptodev_sym_queue_pair_attach_session_t qp_detach_session;
393 /**< Detach session from queue pair. */
398 * Function for internal use by dummy drivers primarily, e.g. ring-based
400 * Allocates a new cryptodev slot for an crypto device and returns the pointer
401 * to that slot for the driver to use.
403 * @param name Unique identifier name for each device
404 * @param socket_id Socket to allocate resources on.
406 * - Slot in the rte_dev_devices array for a new device;
408 struct rte_cryptodev *
409 rte_cryptodev_pmd_allocate(const char *name, int socket_id);
412 * Function for internal use by dummy drivers primarily, e.g. ring-based
414 * Release the specified cryptodev device.
417 * The *cryptodev* pointer is the address of the *rte_cryptodev* structure.
419 * - 0 on success, negative on error
422 rte_cryptodev_pmd_release_device(struct rte_cryptodev *cryptodev);
428 * PMD assist function to parse initialisation arguments for crypto driver
429 * when creating a new crypto PMD device instance.
431 * PMD driver should set default values for that PMD before calling function,
432 * these default values will be over-written with successfully parsed values
435 * @param params parsed PMD initialisation parameters
436 * @param args input argument string to parse
443 rte_cryptodev_pmd_parse_input_args(
444 struct rte_cryptodev_pmd_init_params *params,
450 * PMD assist function to provide boiler plate code for crypto driver to create
451 * and allocate resources for a new crypto PMD device instance.
453 * @param name crypto device name.
454 * @param device base device instance
455 * @param params PMD initialisation parameters
458 * - crypto device instance on success
459 * - NULL on creation failure
461 struct rte_cryptodev *
462 rte_cryptodev_pmd_create(const char *name,
463 struct rte_device *device,
464 struct rte_cryptodev_pmd_init_params *params);
469 * PMD assist function to provide boiler plate code for crypto driver to
470 * destroy and free resources associated with a crypto PMD device instance.
472 * @param cryptodev crypto device handle.
479 rte_cryptodev_pmd_destroy(struct rte_cryptodev *cryptodev);
482 * Executes all the user application registered callbacks for the specific
485 * @param dev Pointer to cryptodev struct
486 * @param event Crypto device interrupt event type.
491 void rte_cryptodev_pmd_callback_process(struct rte_cryptodev *dev,
492 enum rte_cryptodev_event_type event);
496 * Create unique device name
499 rte_cryptodev_pmd_create_dev_name(char *name, const char *dev_name_prefix);
503 * Allocate Cryptodev driver.
506 * Pointer to cryptodev_driver.
508 * Pointer to rte_driver.
511 * The driver type identifier
513 uint8_t rte_cryptodev_allocate_driver(struct cryptodev_driver *crypto_drv,
514 const struct rte_driver *drv);
517 #define RTE_PMD_REGISTER_CRYPTO_DRIVER(crypto_drv, drv, driver_id)\
518 RTE_INIT(init_ ##driver_id);\
519 static void init_ ##driver_id(void)\
521 driver_id = rte_cryptodev_allocate_driver(&crypto_drv, &(drv).driver);\
525 get_session_private_data(const struct rte_cryptodev_sym_session *sess,
527 return sess->sess_private_data[driver_id];
531 set_session_private_data(struct rte_cryptodev_sym_session *sess,
532 uint8_t driver_id, void *private_data)
534 sess->sess_private_data[driver_id] = private_data;
541 #endif /* _RTE_CRYPTODEV_PMD_H_ */