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 /* Cryptodev driver, containing the driver ID */
69 struct cryptodev_driver {
70 TAILQ_ENTRY(cryptodev_driver) next; /**< Next in list. */
71 const struct rte_driver *driver;
75 /** pointer to global crypto devices data structure. */
76 extern struct rte_cryptodev_global *rte_cryptodev_globals;
79 * Get the rte_cryptodev structure device pointer for the device. Assumes a
82 * @param dev_id Device ID value to select the device structure.
85 * - The rte_cryptodev structure pointer for the given device ID.
87 struct rte_cryptodev *
88 rte_cryptodev_pmd_get_dev(uint8_t dev_id);
91 * Get the rte_cryptodev structure device pointer for the named device.
93 * @param name device name to select the device structure.
96 * - The rte_cryptodev structure pointer for the given device ID.
98 struct rte_cryptodev *
99 rte_cryptodev_pmd_get_named_dev(const char *name);
102 * Validate if the crypto device index is valid attached crypto device.
104 * @param dev_id Crypto device index.
107 * - If the device index is valid (1) or not (0).
110 rte_cryptodev_pmd_is_valid_dev(uint8_t dev_id);
113 * The pool of rte_cryptodev structures.
115 extern struct rte_cryptodev *rte_cryptodevs;
119 * Definitions of all functions exported by a driver through the
120 * the generic structure of type *crypto_dev_ops* supplied in the
121 * *rte_cryptodev* structure associated with a device.
125 * Function used to configure device.
127 * @param dev Crypto device pointer
128 * config Crypto device configurations
130 * @return Returns 0 on success
132 typedef int (*cryptodev_configure_t)(struct rte_cryptodev *dev,
133 struct rte_cryptodev_config *config);
136 * Function used to start a configured device.
138 * @param dev Crypto device pointer
140 * @return Returns 0 on success
142 typedef int (*cryptodev_start_t)(struct rte_cryptodev *dev);
145 * Function used to stop a configured device.
147 * @param dev Crypto device pointer
149 typedef void (*cryptodev_stop_t)(struct rte_cryptodev *dev);
152 * Function used to close a configured device.
154 * @param dev Crypto device pointer
157 * - EAGAIN if can't close as device is busy
159 typedef int (*cryptodev_close_t)(struct rte_cryptodev *dev);
163 * Function used to get statistics of a device.
165 * @param dev Crypto device pointer
166 * @param stats Pointer to crypto device stats structure to populate
168 typedef void (*cryptodev_stats_get_t)(struct rte_cryptodev *dev,
169 struct rte_cryptodev_stats *stats);
173 * Function used to reset statistics of a device.
175 * @param dev Crypto device pointer
177 typedef void (*cryptodev_stats_reset_t)(struct rte_cryptodev *dev);
181 * Function used to get specific information of a device.
183 * @param dev Crypto device pointer
185 typedef void (*cryptodev_info_get_t)(struct rte_cryptodev *dev,
186 struct rte_cryptodev_info *dev_info);
189 * Start queue pair of a device.
191 * @param dev Crypto device pointer
192 * @param qp_id Queue Pair Index
194 * @return Returns 0 on success.
196 typedef int (*cryptodev_queue_pair_start_t)(struct rte_cryptodev *dev,
200 * Stop queue pair of a device.
202 * @param dev Crypto device pointer
203 * @param qp_id Queue Pair Index
205 * @return Returns 0 on success.
207 typedef int (*cryptodev_queue_pair_stop_t)(struct rte_cryptodev *dev,
211 * Setup a queue pair for a device.
213 * @param dev Crypto device pointer
214 * @param qp_id Queue Pair Index
215 * @param qp_conf Queue configuration structure
216 * @param socket_id Socket Index
217 * @param session_pool Pointer to device session mempool
219 * @return Returns 0 on success.
221 typedef int (*cryptodev_queue_pair_setup_t)(struct rte_cryptodev *dev,
222 uint16_t qp_id, const struct rte_cryptodev_qp_conf *qp_conf,
223 int socket_id, struct rte_mempool *session_pool);
226 * Release memory resources allocated by given queue pair.
228 * @param dev Crypto device pointer
229 * @param qp_id Queue Pair Index
233 * - EAGAIN if can't close as device is busy
235 typedef int (*cryptodev_queue_pair_release_t)(struct rte_cryptodev *dev,
239 * Get number of available queue pairs of a device.
241 * @param dev Crypto device pointer
243 * @return Returns number of queue pairs on success.
245 typedef uint32_t (*cryptodev_queue_pair_count_t)(struct rte_cryptodev *dev);
248 * Create a session mempool to allocate sessions from
250 * @param dev Crypto device pointer
251 * @param nb_objs number of sessions objects in mempool
252 * @param obj_cache l-core object cache size, see *rte_ring_create*
253 * @param socket_id Socket Id to allocate mempool on.
256 * - On success returns a pointer to a rte_mempool
257 * - On failure returns a NULL pointer
259 typedef int (*cryptodev_sym_create_session_pool_t)(
260 struct rte_cryptodev *dev, unsigned nb_objs,
261 unsigned obj_cache_size, int socket_id);
265 * Get the size of a cryptodev session
267 * @param dev Crypto device pointer
270 * - On success returns the size of the session structure for device
271 * - On failure returns 0
273 typedef unsigned (*cryptodev_sym_get_session_private_size_t)(
274 struct rte_cryptodev *dev);
277 * Configure a Crypto session on a device.
279 * @param dev Crypto device pointer
280 * @param xform Single or chain of crypto xforms
281 * @param priv_sess Pointer to cryptodev's private session structure
282 * @param mp Mempool where the private session is allocated
285 * - Returns 0 if private session structure have been created successfully.
286 * - Returns -EINVAL if input parameters are invalid.
287 * - Returns -ENOTSUP if crypto device does not support the crypto transform.
288 * - Returns -ENOMEM if the private session could not be allocated.
290 typedef int (*cryptodev_sym_configure_session_t)(struct rte_cryptodev *dev,
291 struct rte_crypto_sym_xform *xform,
292 struct rte_cryptodev_sym_session *session,
293 struct rte_mempool *mp);
296 * Free driver private session data.
298 * @param dev Crypto device pointer
299 * @param sess Cryptodev session structure
301 typedef void (*cryptodev_sym_free_session_t)(struct rte_cryptodev *dev,
302 struct rte_cryptodev_sym_session *sess);
305 * Optional API for drivers to attach sessions with queue pair.
306 * @param dev Crypto device pointer
307 * @param qp_id queue pair id for attaching session
308 * @param priv_sess Pointer to cryptodev's private session structure
310 * - Return 0 on success
312 typedef int (*cryptodev_sym_queue_pair_attach_session_t)(
313 struct rte_cryptodev *dev,
315 void *session_private);
318 * Optional API for drivers to detach sessions from queue pair.
319 * @param dev Crypto device pointer
320 * @param qp_id queue pair id for detaching session
321 * @param priv_sess Pointer to cryptodev's private session structure
323 * - Return 0 on success
325 typedef int (*cryptodev_sym_queue_pair_detach_session_t)(
326 struct rte_cryptodev *dev,
328 void *session_private);
330 /** Crypto device operations function pointer table */
331 struct rte_cryptodev_ops {
332 cryptodev_configure_t dev_configure; /**< Configure device. */
333 cryptodev_start_t dev_start; /**< Start device. */
334 cryptodev_stop_t dev_stop; /**< Stop device. */
335 cryptodev_close_t dev_close; /**< Close device. */
337 cryptodev_info_get_t dev_infos_get; /**< Get device info. */
339 cryptodev_stats_get_t stats_get;
340 /**< Get device statistics. */
341 cryptodev_stats_reset_t stats_reset;
342 /**< Reset device statistics. */
344 cryptodev_queue_pair_setup_t queue_pair_setup;
345 /**< Set up a device queue pair. */
346 cryptodev_queue_pair_release_t queue_pair_release;
347 /**< Release a queue pair. */
348 cryptodev_queue_pair_start_t queue_pair_start;
349 /**< Start a queue pair. */
350 cryptodev_queue_pair_stop_t queue_pair_stop;
351 /**< Stop a queue pair. */
352 cryptodev_queue_pair_count_t queue_pair_count;
353 /**< Get count of the queue pairs. */
355 cryptodev_sym_get_session_private_size_t session_get_size;
356 /**< Return private session. */
357 cryptodev_sym_configure_session_t session_configure;
358 /**< Configure a Crypto session. */
359 cryptodev_sym_free_session_t session_clear;
360 /**< Clear a Crypto sessions private data. */
361 cryptodev_sym_queue_pair_attach_session_t qp_attach_session;
362 /**< Attach session to queue pair. */
363 cryptodev_sym_queue_pair_attach_session_t qp_detach_session;
364 /**< Detach session from queue pair. */
369 * Function for internal use by dummy drivers primarily, e.g. ring-based
371 * Allocates a new cryptodev slot for an crypto device and returns the pointer
372 * to that slot for the driver to use.
374 * @param name Unique identifier name for each device
375 * @param socket_id Socket to allocate resources on.
377 * - Slot in the rte_dev_devices array for a new device;
379 struct rte_cryptodev *
380 rte_cryptodev_pmd_allocate(const char *name, int socket_id);
383 * Function for internal use by dummy drivers primarily, e.g. ring-based
385 * Release the specified cryptodev device.
388 * The *cryptodev* pointer is the address of the *rte_cryptodev* structure.
390 * - 0 on success, negative on error
393 rte_cryptodev_pmd_release_device(struct rte_cryptodev *cryptodev);
396 * Executes all the user application registered callbacks for the specific
399 * @param dev Pointer to cryptodev struct
400 * @param event Crypto device interrupt event type.
405 void rte_cryptodev_pmd_callback_process(struct rte_cryptodev *dev,
406 enum rte_cryptodev_event_type event);
410 * Create unique device name
413 rte_cryptodev_pmd_create_dev_name(char *name, const char *dev_name_prefix);
417 * Allocate Cryptodev driver.
420 * Pointer to cryptodev_driver.
422 * Pointer to rte_driver.
425 * The driver type identifier
427 uint8_t rte_cryptodev_allocate_driver(struct cryptodev_driver *crypto_drv,
428 const struct rte_driver *drv);
431 #define RTE_PMD_REGISTER_CRYPTO_DRIVER(crypto_drv, drv, driver_id)\
432 RTE_INIT(init_ ##driver_id);\
433 static void init_ ##driver_id(void)\
435 driver_id = rte_cryptodev_allocate_driver(&crypto_drv, &(drv).driver);\
439 get_session_private_data(const struct rte_cryptodev_sym_session *sess,
441 return sess->sess_private_data[driver_id];
445 set_session_private_data(struct rte_cryptodev_sym_session *sess,
446 uint8_t driver_id, void *private_data)
448 sess->sess_private_data[driver_id] = private_data;
455 #endif /* _RTE_CRYPTODEV_PMD_H_ */