1 /*-
2  *
3  *   Copyright(c) 2015-2016 Intel Corporation. All rights reserved.
4  *
5  *   Redistribution and use in source and binary forms, with or without
6  *   modification, are permitted provided that the following conditions
7  *   are met:
8  *
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
14  *       distribution.
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.
18  *
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.
30  */
31 
32 #ifndef _RTE_CRYPTODEV_H_
33 #define _RTE_CRYPTODEV_H_
34 
35 /**
36  * @file rte_cryptodev.h
37  *
38  * RTE Cryptographic Device APIs
39  *
40  * Defines RTE Crypto Device APIs for the provisioning of cipher and
41  * authentication operations.
42  */
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 #include "rte_kvargs.h"
49 #include "rte_crypto.h"
50 #include "rte_dev.h"
51 
52 #define CRYPTODEV_NAME_NULL_PMD		cryptodev_null_pmd
53 /**< Null crypto PMD device name */
54 #define CRYPTODEV_NAME_AESNI_MB_PMD	cryptodev_aesni_mb_pmd
55 /**< AES-NI Multi buffer PMD device name */
56 #define CRYPTODEV_NAME_AESNI_GCM_PMD	cryptodev_aesni_gcm_pmd
57 /**< AES-NI GCM PMD device name */
58 #define CRYPTODEV_NAME_QAT_SYM_PMD	cryptodev_qat_sym_pmd
59 /**< Intel QAT Symmetric Crypto PMD device name */
60 #define CRYPTODEV_NAME_SNOW3G_PMD	cryptodev_snow3g_pmd
61 /**< SNOW 3G PMD device name */
62 #define CRYPTODEV_NAME_KASUMI_PMD	cryptodev_kasumi_pmd
63 /**< KASUMI PMD device name */
64 
65 /** Crypto device type */
66 enum rte_cryptodev_type {
67 	RTE_CRYPTODEV_NULL_PMD = 1,	/**< Null crypto PMD */
68 	RTE_CRYPTODEV_AESNI_GCM_PMD,	/**< AES-NI GCM PMD */
69 	RTE_CRYPTODEV_AESNI_MB_PMD,	/**< AES-NI multi buffer PMD */
70 	RTE_CRYPTODEV_QAT_SYM_PMD,	/**< QAT PMD Symmetric Crypto */
71 	RTE_CRYPTODEV_SNOW3G_PMD,	/**< SNOW 3G PMD */
72 	RTE_CRYPTODEV_KASUMI_PMD,	/**< KASUMI PMD */
73 };
74 
75 extern const char **rte_cyptodev_names;
76 
77 /* Logging Macros */
78 
79 #define CDEV_LOG_ERR(fmt, args...)					\
80 		RTE_LOG(ERR, CRYPTODEV, "%s() line %u: " fmt "\n",	\
81 				__func__, __LINE__, ## args)
82 
83 #define CDEV_PMD_LOG_ERR(dev, fmt, args...)				\
84 		RTE_LOG(ERR, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \
85 				dev, __func__, __LINE__, ## args)
86 
87 #ifdef RTE_LIBRTE_CRYPTODEV_DEBUG
88 #define CDEV_LOG_DEBUG(fmt, args...)					\
89 		RTE_LOG(DEBUG, CRYPTODEV, "%s() line %u: " fmt "\n",	\
90 				__func__, __LINE__, ## args)		\
91 
92 #define CDEV_PMD_TRACE(fmt, args...)					\
93 		RTE_LOG(DEBUG, CRYPTODEV, "[%s] %s: " fmt "\n",		\
94 				dev, __func__, ## args)
95 
96 #else
97 #define CDEV_LOG_DEBUG(fmt, args...)
98 #define CDEV_PMD_TRACE(fmt, args...)
99 #endif
100 
101 /**
102  * Symmetric Crypto Capability
103  */
104 struct rte_cryptodev_symmetric_capability {
105 	enum rte_crypto_sym_xform_type xform_type;
106 	/**< Transform type : Authentication / Cipher */
107 	union {
108 		struct {
109 			enum rte_crypto_auth_algorithm algo;
110 			/**< authentication algorithm */
111 			uint16_t block_size;
112 			/**< algorithm block size */
113 			struct {
114 				uint16_t min;	/**< minimum key size */
115 				uint16_t max;	/**< maximum key size */
116 				uint16_t increment;
117 				/**< if a range of sizes are supported,
118 				 * this parameter is used to indicate
119 				 * increments in byte size that are supported
120 				 * between the minimum and maximum */
121 			} key_size;
122 			/**< auth key size range */
123 			struct {
124 				uint16_t min;	/**< minimum digest size */
125 				uint16_t max;	/**< maximum digest size */
126 				uint16_t increment;
127 				/**< if a range of sizes are supported,
128 				 * this parameter is used to indicate
129 				 * increments in byte size that are supported
130 				 * between the minimum and maximum */
131 			} digest_size;
132 			/**< digest size range */
133 			struct {
134 				uint16_t min;	/**< minimum aad size */
135 				uint16_t max;	/**< maximum aad size */
136 				uint16_t increment;
137 				/**< if a range of sizes are supported,
138 				 * this parameter is used to indicate
139 				 * increments in byte size that are supported
140 				 * between the minimum and maximum */
141 			} aad_size;
142 			/**< Additional authentication data size range */
143 		} auth;
144 		/**< Symmetric Authentication transform capabilities */
145 		struct {
146 			enum rte_crypto_cipher_algorithm algo;
147 			/**< cipher algorithm */
148 			uint16_t block_size;
149 			/**< algorithm block size */
150 			struct {
151 				uint16_t min;	/**< minimum key size */
152 				uint16_t max;	/**< maximum key size */
153 				uint16_t increment;
154 				/**< if a range of sizes are supported,
155 				 * this parameter is used to indicate
156 				 * increments in byte size that are supported
157 				 * between the minimum and maximum */
158 			} key_size;
159 			/**< cipher key size range */
160 			struct {
161 				uint16_t min;	/**< minimum iv size */
162 				uint16_t max;	/**< maximum iv size */
163 				uint16_t increment;
164 				/**< if a range of sizes are supported,
165 				 * this parameter is used to indicate
166 				 * increments in byte size that are supported
167 				 * between the minimum and maximum */
168 			} iv_size;
169 			/**< Initialisation vector data size range */
170 		} cipher;
171 		/**< Symmetric Cipher transform capabilities */
172 	};
173 };
174 
175 /** Structure used to capture a capability of a crypto device */
176 struct rte_cryptodev_capabilities {
177 	enum rte_crypto_op_type op;
178 	/**< Operation type */
179 
180 	union {
181 		struct rte_cryptodev_symmetric_capability sym;
182 		/**< Symmetric operation capability parameters */
183 	};
184 };
185 
186 /** Macro used at end of crypto PMD list */
187 #define RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() \
188 	{ RTE_CRYPTO_OP_TYPE_UNDEFINED }
189 
190 
191 /**
192  * Crypto device supported feature flags
193  *
194  * Note:
195  * New features flags should be added to the end of the list
196  *
197  * Keep these flags synchronised with rte_cryptodev_get_feature_name()
198  */
199 #define	RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO	(1ULL << 0)
200 /**< Symmetric crypto operations are supported */
201 #define	RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO	(1ULL << 1)
202 /**< Asymmetric crypto operations are supported */
203 #define	RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING	(1ULL << 2)
204 /**< Chaining symmetric crypto operations are supported */
205 #define	RTE_CRYPTODEV_FF_CPU_SSE		(1ULL << 3)
206 /**< Utilises CPU SIMD SSE instructions */
207 #define	RTE_CRYPTODEV_FF_CPU_AVX		(1ULL << 4)
208 /**< Utilises CPU SIMD AVX instructions */
209 #define	RTE_CRYPTODEV_FF_CPU_AVX2		(1ULL << 5)
210 /**< Utilises CPU SIMD AVX2 instructions */
211 #define	RTE_CRYPTODEV_FF_CPU_AESNI		(1ULL << 6)
212 /**< Utilises CPU AES-NI instructions */
213 #define	RTE_CRYPTODEV_FF_HW_ACCELERATED		(1ULL << 7)
214 /**< Operations are off-loaded to an external hardware accelerator */
215 
216 
217 /**
218  * Get the name of a crypto device feature flag
219  *
220  * @param	flag	The mask describing the flag.
221  *
222  * @return
223  *   The name of this flag, or NULL if it's not a valid feature flag.
224  */
225 
226 extern const char *
227 rte_cryptodev_get_feature_name(uint64_t flag);
228 
229 /**  Crypto device information */
230 struct rte_cryptodev_info {
231 	const char *driver_name;		/**< Driver name. */
232 	enum rte_cryptodev_type dev_type;	/**< Device type */
233 	struct rte_pci_device *pci_dev;		/**< PCI information. */
234 
235 	uint64_t feature_flags;			/**< Feature flags */
236 
237 	const struct rte_cryptodev_capabilities *capabilities;
238 	/**< Array of devices supported capabilities */
239 
240 	unsigned max_nb_queue_pairs;
241 	/**< Maximum number of queues pairs supported by device. */
242 
243 	struct {
244 		unsigned max_nb_sessions;
245 		/**< Maximum number of sessions supported by device. */
246 	} sym;
247 };
248 
249 #define RTE_CRYPTODEV_DETACHED  (0)
250 #define RTE_CRYPTODEV_ATTACHED  (1)
251 
252 /** Definitions of Crypto device event types */
253 enum rte_cryptodev_event_type {
254 	RTE_CRYPTODEV_EVENT_UNKNOWN,	/**< unknown event type */
255 	RTE_CRYPTODEV_EVENT_ERROR,	/**< error interrupt event */
256 	RTE_CRYPTODEV_EVENT_MAX		/**< max value of this enum */
257 };
258 
259 /** Crypto device queue pair configuration structure. */
260 struct rte_cryptodev_qp_conf {
261 	uint32_t nb_descriptors; /**< Number of descriptors per queue pair */
262 };
263 
264 /**
265  * Typedef for application callback function to be registered by application
266  * software for notification of device events
267  *
268  * @param	dev_id	Crypto device identifier
269  * @param	event	Crypto device event to register for notification of.
270  * @param	cb_arg	User specified parameter to be passed as to passed to
271  *			users callback function.
272  */
273 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
274 		enum rte_cryptodev_event_type event, void *cb_arg);
275 
276 
277 /** Crypto Device statistics */
278 struct rte_cryptodev_stats {
279 	uint64_t enqueued_count;
280 	/**< Count of all operations enqueued */
281 	uint64_t dequeued_count;
282 	/**< Count of all operations dequeued */
283 
284 	uint64_t enqueue_err_count;
285 	/**< Total error count on operations enqueued */
286 	uint64_t dequeue_err_count;
287 	/**< Total error count on operations dequeued */
288 };
289 
290 #define RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_QUEUE_PAIRS	8
291 #define RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_SESSIONS	2048
292 
293 /**
294  * @internal
295  * Initialisation parameters for virtual crypto devices
296  */
297 struct rte_crypto_vdev_init_params {
298 	unsigned max_nb_queue_pairs;
299 	unsigned max_nb_sessions;
300 	uint8_t socket_id;
301 };
302 
303 /**
304  * Parse virtual device initialisation parameters input arguments
305  * @internal
306  *
307  * @params	params		Initialisation parameters with defaults set.
308  * @params	input_args	Command line arguments
309  *
310  * @return
311  * 0 on successful parse
312  * <0 on failure to parse
313  */
314 int
315 rte_cryptodev_parse_vdev_init_params(
316 		struct rte_crypto_vdev_init_params *params,
317 		const char *input_args);
318 
319 /**
320  * Create a virtual crypto device
321  *
322  * @param	name	Cryptodev PMD name of device to be created.
323  * @param	args	Options arguments for device.
324  *
325  * @return
326  * - On successful creation of the cryptodev the device index is returned,
327  *   which will be between 0 and rte_cryptodev_count().
328  * - In the case of a failure, returns -1.
329  */
330 extern int
331 rte_cryptodev_create_vdev(const char *name, const char *args);
332 
333 /**
334  * Get the device identifier for the named crypto device.
335  *
336  * @param	name	device name to select the device structure.
337  *
338  * @return
339  *   - Returns crypto device identifier on success.
340  *   - Return -1 on failure to find named crypto device.
341  */
342 extern int
343 rte_cryptodev_get_dev_id(const char *name);
344 
345 /**
346  * Get the total number of crypto devices that have been successfully
347  * initialised.
348  *
349  * @return
350  *   - The total number of usable crypto devices.
351  */
352 extern uint8_t
353 rte_cryptodev_count(void);
354 
355 extern uint8_t
356 rte_cryptodev_count_devtype(enum rte_cryptodev_type type);
357 /*
358  * Return the NUMA socket to which a device is connected
359  *
360  * @param dev_id
361  *   The identifier of the device
362  * @return
363  *   The NUMA socket id to which the device is connected or
364  *   a default of zero if the socket could not be determined.
365  *   -1 if returned is the dev_id value is out of range.
366  */
367 extern int
368 rte_cryptodev_socket_id(uint8_t dev_id);
369 
370 /** Crypto device configuration structure */
371 struct rte_cryptodev_config {
372 	int socket_id;			/**< Socket to allocate resources on */
373 	uint16_t nb_queue_pairs;
374 	/**< Number of queue pairs to configure on device */
375 
376 	struct {
377 		uint32_t nb_objs;	/**< Number of objects in mempool */
378 		uint32_t cache_size;	/**< l-core object cache size */
379 	} session_mp;		/**< Session mempool configuration */
380 };
381 
382 /**
383  * Configure a device.
384  *
385  * This function must be invoked first before any other function in the
386  * API. This function can also be re-invoked when a device is in the
387  * stopped state.
388  *
389  * @param	dev_id		The identifier of the device to configure.
390  * @param	config		The crypto device configuration structure.
391  *
392  * @return
393  *   - 0: Success, device configured.
394  *   - <0: Error code returned by the driver configuration function.
395  */
396 extern int
397 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
398 
399 /**
400  * Start an device.
401  *
402  * The device start step is the last one and consists of setting the configured
403  * offload features and in starting the transmit and the receive units of the
404  * device.
405  * On success, all basic functions exported by the API (link status,
406  * receive/transmit, and so on) can be invoked.
407  *
408  * @param dev_id
409  *   The identifier of the device.
410  * @return
411  *   - 0: Success, device started.
412  *   - <0: Error code of the driver device start function.
413  */
414 extern int
415 rte_cryptodev_start(uint8_t dev_id);
416 
417 /**
418  * Stop an device. The device can be restarted with a call to
419  * rte_cryptodev_start()
420  *
421  * @param	dev_id		The identifier of the device.
422  */
423 extern void
424 rte_cryptodev_stop(uint8_t dev_id);
425 
426 /**
427  * Close an device. The device cannot be restarted!
428  *
429  * @param	dev_id		The identifier of the device.
430  *
431  * @return
432  *  - 0 on successfully closing device
433  *  - <0 on failure to close device
434  */
435 extern int
436 rte_cryptodev_close(uint8_t dev_id);
437 
438 /**
439  * Allocate and set up a receive queue pair for a device.
440  *
441  *
442  * @param	dev_id		The identifier of the device.
443  * @param	queue_pair_id	The index of the queue pairs to set up. The
444  *				value must be in the range [0, nb_queue_pair
445  *				- 1] previously supplied to
446  *				rte_cryptodev_configure().
447  * @param	qp_conf		The pointer to the configuration data to be
448  *				used for the queue pair. NULL value is
449  *				allowed, in which case default configuration
450  *				will be used.
451  * @param	socket_id	The *socket_id* argument is the socket
452  *				identifier in case of NUMA. The value can be
453  *				*SOCKET_ID_ANY* if there is no NUMA constraint
454  *				for the DMA memory allocated for the receive
455  *				queue pair.
456  *
457  * @return
458  *   - 0: Success, queue pair correctly set up.
459  *   - <0: Queue pair configuration failed
460  */
461 extern int
462 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
463 		const struct rte_cryptodev_qp_conf *qp_conf, int socket_id);
464 
465 /**
466  * Start a specified queue pair of a device. It is used
467  * when deferred_start flag of the specified queue is true.
468  *
469  * @param	dev_id		The identifier of the device
470  * @param	queue_pair_id	The index of the queue pair to start. The value
471  *				must be in the range [0, nb_queue_pair - 1]
472  *				previously supplied to
473  *				rte_crypto_dev_configure().
474  * @return
475  *   - 0: Success, the transmit queue is correctly set up.
476  *   - -EINVAL: The dev_id or the queue_id out of range.
477  *   - -ENOTSUP: The function not supported in PMD driver.
478  */
479 extern int
480 rte_cryptodev_queue_pair_start(uint8_t dev_id, uint16_t queue_pair_id);
481 
482 /**
483  * Stop specified queue pair of a device
484  *
485  * @param	dev_id		The identifier of the device
486  * @param	queue_pair_id	The index of the queue pair to stop. The value
487  *				must be in the range [0, nb_queue_pair - 1]
488  *				previously supplied to
489  *				rte_cryptodev_configure().
490  * @return
491  *   - 0: Success, the transmit queue is correctly set up.
492  *   - -EINVAL: The dev_id or the queue_id out of range.
493  *   - -ENOTSUP: The function not supported in PMD driver.
494  */
495 extern int
496 rte_cryptodev_queue_pair_stop(uint8_t dev_id, uint16_t queue_pair_id);
497 
498 /**
499  * Get the number of queue pairs on a specific crypto device
500  *
501  * @param	dev_id		Crypto device identifier.
502  * @return
503  *   - The number of configured queue pairs.
504  */
505 extern uint16_t
506 rte_cryptodev_queue_pair_count(uint8_t dev_id);
507 
508 
509 /**
510  * Retrieve the general I/O statistics of a device.
511  *
512  * @param	dev_id		The identifier of the device.
513  * @param	stats		A pointer to a structure of type
514  *				*rte_cryptodev_stats* to be filled with the
515  *				values of device counters.
516  * @return
517  *   - Zero if successful.
518  *   - Non-zero otherwise.
519  */
520 extern int
521 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
522 
523 /**
524  * Reset the general I/O statistics of a device.
525  *
526  * @param	dev_id		The identifier of the device.
527  */
528 extern void
529 rte_cryptodev_stats_reset(uint8_t dev_id);
530 
531 /**
532  * Retrieve the contextual information of a device.
533  *
534  * @param	dev_id		The identifier of the device.
535  * @param	dev_info	A pointer to a structure of type
536  *				*rte_cryptodev_info* to be filled with the
537  *				contextual information of the device.
538  */
539 extern void
540 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
541 
542 
543 /**
544  * Register a callback function for specific device id.
545  *
546  * @param	dev_id		Device id.
547  * @param	event		Event interested.
548  * @param	cb_fn		User supplied callback function to be called.
549  * @param	cb_arg		Pointer to the parameters for the registered
550  *				callback.
551  *
552  * @return
553  *  - On success, zero.
554  *  - On failure, a negative value.
555  */
556 extern int
557 rte_cryptodev_callback_register(uint8_t dev_id,
558 		enum rte_cryptodev_event_type event,
559 		rte_cryptodev_cb_fn cb_fn, void *cb_arg);
560 
561 /**
562  * Unregister a callback function for specific device id.
563  *
564  * @param	dev_id		The device identifier.
565  * @param	event		Event interested.
566  * @param	cb_fn		User supplied callback function to be called.
567  * @param	cb_arg		Pointer to the parameters for the registered
568  *				callback.
569  *
570  * @return
571  *  - On success, zero.
572  *  - On failure, a negative value.
573  */
574 extern int
575 rte_cryptodev_callback_unregister(uint8_t dev_id,
576 		enum rte_cryptodev_event_type event,
577 		rte_cryptodev_cb_fn cb_fn, void *cb_arg);
578 
579 
580 typedef uint16_t (*dequeue_pkt_burst_t)(void *qp,
581 		struct rte_crypto_op **ops,	uint16_t nb_ops);
582 /**< Dequeue processed packets from queue pair of a device. */
583 
584 typedef uint16_t (*enqueue_pkt_burst_t)(void *qp,
585 		struct rte_crypto_op **ops,	uint16_t nb_ops);
586 /**< Enqueue packets for processing on queue pair of a device. */
587 
588 
589 
590 
591 struct rte_cryptodev_callback;
592 
593 /** Structure to keep track of registered callbacks */
594 TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
595 
596 /** The data structure associated with each crypto device. */
597 struct rte_cryptodev {
598 	dequeue_pkt_burst_t dequeue_burst;
599 	/**< Pointer to PMD receive function. */
600 	enqueue_pkt_burst_t enqueue_burst;
601 	/**< Pointer to PMD transmit function. */
602 
603 	const struct rte_cryptodev_driver *driver;
604 	/**< Driver for this device */
605 	struct rte_cryptodev_data *data;
606 	/**< Pointer to device data */
607 	struct rte_cryptodev_ops *dev_ops;
608 	/**< Functions exported by PMD */
609 	uint64_t feature_flags;
610 	/**< Supported features */
611 	struct rte_pci_device *pci_dev;
612 	/**< PCI info. supplied by probing */
613 
614 	enum rte_cryptodev_type dev_type;
615 	/**< Crypto device type */
616 	enum pmd_type pmd_type;
617 	/**< PMD type - PDEV / VDEV */
618 
619 	struct rte_cryptodev_cb_list link_intr_cbs;
620 	/**< User application callback for interrupts if present */
621 
622 	uint8_t attached : 1;
623 	/**< Flag indicating the device is attached */
624 } __rte_cache_aligned;
625 
626 
627 #define RTE_CRYPTODEV_NAME_MAX_LEN	(64)
628 /**< Max length of name of crypto PMD */
629 
630 /**
631  *
632  * The data part, with no function pointers, associated with each device.
633  *
634  * This structure is safe to place in shared memory to be common among
635  * different processes in a multi-process configuration.
636  */
637 struct rte_cryptodev_data {
638 	uint8_t dev_id;
639 	/**< Device ID for this instance */
640 	uint8_t socket_id;
641 	/**< Socket ID where memory is allocated */
642 	char name[RTE_CRYPTODEV_NAME_MAX_LEN];
643 	/**< Unique identifier name */
644 
645 	uint8_t dev_started : 1;
646 	/**< Device state: STARTED(1)/STOPPED(0) */
647 
648 	struct rte_mempool *session_pool;
649 	/**< Session memory pool */
650 	void **queue_pairs;
651 	/**< Array of pointers to queue pairs. */
652 	uint16_t nb_queue_pairs;
653 	/**< Number of device queue pairs. */
654 
655 	void *dev_private;
656 	/**< PMD-specific private data */
657 } __rte_cache_aligned;
658 
659 extern struct rte_cryptodev *rte_cryptodevs;
660 /**
661  *
662  * Dequeue a burst of processed crypto operations from a queue on the crypto
663  * device. The dequeued operation are stored in *rte_crypto_op* structures
664  * whose pointers are supplied in the *ops* array.
665  *
666  * The rte_cryptodev_dequeue_burst() function returns the number of ops
667  * actually dequeued, which is the number of *rte_crypto_op* data structures
668  * effectively supplied into the *ops* array.
669  *
670  * A return value equal to *nb_ops* indicates that the queue contained
671  * at least *nb_ops* operations, and this is likely to signify that other
672  * processed operations remain in the devices output queue. Applications
673  * implementing a "retrieve as many processed operations as possible" policy
674  * can check this specific case and keep invoking the
675  * rte_cryptodev_dequeue_burst() function until a value less than
676  * *nb_ops* is returned.
677  *
678  * The rte_cryptodev_dequeue_burst() function does not provide any error
679  * notification to avoid the corresponding overhead.
680  *
681  * @param	dev_id		The symmetric crypto device identifier
682  * @param	qp_id		The index of the queue pair from which to
683  *				retrieve processed packets. The value must be
684  *				in the range [0, nb_queue_pair - 1] previously
685  *				supplied to rte_cryptodev_configure().
686  * @param	ops		The address of an array of pointers to
687  *				*rte_crypto_op* structures that must be
688  *				large enough to store *nb_ops* pointers in it.
689  * @param	nb_ops		The maximum number of operations to dequeue.
690  *
691  * @return
692  *   - The number of operations actually dequeued, which is the number
693  *   of pointers to *rte_crypto_op* structures effectively supplied to the
694  *   *ops* array.
695  */
696 static inline uint16_t
697 rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
698 		struct rte_crypto_op **ops, uint16_t nb_ops)
699 {
700 	struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
701 
702 	nb_ops = (*dev->dequeue_burst)
703 			(dev->data->queue_pairs[qp_id], ops, nb_ops);
704 
705 	return nb_ops;
706 }
707 
708 /**
709  * Enqueue a burst of operations for processing on a crypto device.
710  *
711  * The rte_cryptodev_enqueue_burst() function is invoked to place
712  * crypto operations on the queue *qp_id* of the device designated by
713  * its *dev_id*.
714  *
715  * The *nb_ops* parameter is the number of operations to process which are
716  * supplied in the *ops* array of *rte_crypto_op* structures.
717  *
718  * The rte_cryptodev_enqueue_burst() function returns the number of
719  * operations it actually enqueued for processing. A return value equal to
720  * *nb_ops* means that all packets have been enqueued.
721  *
722  * @param	dev_id		The identifier of the device.
723  * @param	qp_id		The index of the queue pair which packets are
724  *				to be enqueued for processing. The value
725  *				must be in the range [0, nb_queue_pairs - 1]
726  *				previously supplied to
727  *				 *rte_cryptodev_configure*.
728  * @param	ops		The address of an array of *nb_ops* pointers
729  *				to *rte_crypto_op* structures which contain
730  *				the crypto operations to be processed.
731  * @param	nb_ops		The number of operations to process.
732  *
733  * @return
734  * The number of operations actually enqueued on the crypto device. The return
735  * value can be less than the value of the *nb_ops* parameter when the
736  * crypto devices queue is full or if invalid parameters are specified in
737  * a *rte_crypto_op*.
738  */
739 static inline uint16_t
740 rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
741 		struct rte_crypto_op **ops, uint16_t nb_ops)
742 {
743 	struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
744 
745 	return (*dev->enqueue_burst)(
746 			dev->data->queue_pairs[qp_id], ops, nb_ops);
747 }
748 
749 
750 /** Cryptodev symmetric crypto session */
751 struct rte_cryptodev_sym_session {
752 	struct {
753 		uint8_t dev_id;
754 		/**< Device Id */
755 		enum rte_cryptodev_type dev_type;
756 		/** Crypto Device type session created on */
757 		struct rte_mempool *mp;
758 		/**< Mempool session allocated from */
759 	} __rte_aligned(8);
760 	/**< Public symmetric session details */
761 
762 	char _private[0];
763 	/**< Private session material */
764 };
765 
766 
767 /**
768  * Initialise a session for symmetric cryptographic operations.
769  *
770  * This function is used by the client to initialize immutable
771  * parameters of symmetric cryptographic operation.
772  * To perform the operation the rte_cryptodev_enqueue_burst function is
773  * used.  Each mbuf should contain a reference to the session
774  * pointer returned from this function contained within it's crypto_op if a
775  * session-based operation is being provisioned. Memory to contain the session
776  * information is allocated from within mempool managed by the cryptodev.
777  *
778  * The rte_cryptodev_session_free must be called to free allocated
779  * memory when the session is no longer required.
780  *
781  * @param	dev_id		The device identifier.
782  * @param	xform		Crypto transform chain.
783 
784  *
785  * @return
786  *  Pointer to the created session or NULL
787  */
788 extern struct rte_cryptodev_sym_session *
789 rte_cryptodev_sym_session_create(uint8_t dev_id,
790 		struct rte_crypto_sym_xform *xform);
791 
792 /**
793  * Free the memory associated with a previously allocated session.
794  *
795  * @param	dev_id		The device identifier.
796  * @param	session		Session pointer previously allocated by
797  *				*rte_cryptodev_sym_session_create*.
798  *
799  * @return
800  *   NULL on successful freeing of session.
801  *   Session pointer on failure to free session.
802  */
803 extern struct rte_cryptodev_sym_session *
804 rte_cryptodev_sym_session_free(uint8_t dev_id,
805 		struct rte_cryptodev_sym_session *session);
806 
807 
808 #ifdef __cplusplus
809 }
810 #endif
811 
812 #endif /* _RTE_CRYPTODEV_H_ */
813