xref: /dpdk/lib/cryptodev/cryptodev_pmd.h (revision 0a054e8dd5b0960eec4226821137aceb77a2bf22)
1af668035SAkhil Goyal /* SPDX-License-Identifier: BSD-3-Clause
2af668035SAkhil Goyal  * Copyright(c) 2015-2020 Intel Corporation.
3af668035SAkhil Goyal  */
4af668035SAkhil Goyal 
5af668035SAkhil Goyal #ifndef _CRYPTODEV_PMD_H_
6af668035SAkhil Goyal #define _CRYPTODEV_PMD_H_
7af668035SAkhil Goyal 
8af668035SAkhil Goyal /** @file
9af668035SAkhil Goyal  * RTE Crypto PMD APIs
10af668035SAkhil Goyal  *
11af668035SAkhil Goyal  * @note
12af668035SAkhil Goyal  * These API are from crypto PMD only and user applications should not call
13af668035SAkhil Goyal  * them directly.
14af668035SAkhil Goyal  */
15af668035SAkhil Goyal 
16af668035SAkhil Goyal #include <string.h>
17af668035SAkhil Goyal 
181acb7f54SDavid Marchand #include <dev_driver.h>
191094dd94SDavid Marchand #include <rte_compat.h>
20af668035SAkhil Goyal #include <rte_malloc.h>
21af668035SAkhil Goyal #include <rte_log.h>
22af668035SAkhil Goyal #include <rte_common.h>
23af668035SAkhil Goyal 
24af668035SAkhil Goyal #include "rte_crypto.h"
25af668035SAkhil Goyal #include "rte_cryptodev.h"
26af668035SAkhil Goyal 
27719834a6SMattias Rönnblom #ifdef __cplusplus
28719834a6SMattias Rönnblom extern "C" {
29719834a6SMattias Rönnblom #endif
30719834a6SMattias Rönnblom 
31af668035SAkhil Goyal 
32af668035SAkhil Goyal #define RTE_CRYPTODEV_PMD_DEFAULT_MAX_NB_QUEUE_PAIRS	8
33af668035SAkhil Goyal 
34af668035SAkhil Goyal #define RTE_CRYPTODEV_PMD_NAME_ARG			("name")
35af668035SAkhil Goyal #define RTE_CRYPTODEV_PMD_MAX_NB_QP_ARG			("max_nb_queue_pairs")
36af668035SAkhil Goyal #define RTE_CRYPTODEV_PMD_SOCKET_ID_ARG			("socket_id")
37af668035SAkhil Goyal 
38af668035SAkhil Goyal 
39af668035SAkhil Goyal static const char * const cryptodev_pmd_valid_params[] = {
40af668035SAkhil Goyal 	RTE_CRYPTODEV_PMD_NAME_ARG,
41af668035SAkhil Goyal 	RTE_CRYPTODEV_PMD_MAX_NB_QP_ARG,
42af668035SAkhil Goyal 	RTE_CRYPTODEV_PMD_SOCKET_ID_ARG,
43af668035SAkhil Goyal 	NULL
44af668035SAkhil Goyal };
45af668035SAkhil Goyal 
46af668035SAkhil Goyal /**
47af668035SAkhil Goyal  * @internal
48af668035SAkhil Goyal  * Initialisation parameters for crypto devices
49af668035SAkhil Goyal  */
50af668035SAkhil Goyal struct rte_cryptodev_pmd_init_params {
51af668035SAkhil Goyal 	char name[RTE_CRYPTODEV_NAME_MAX_LEN];
52af668035SAkhil Goyal 	size_t private_data_size;
53af668035SAkhil Goyal 	int socket_id;
54af668035SAkhil Goyal 	unsigned int max_nb_queue_pairs;
55af668035SAkhil Goyal };
56af668035SAkhil Goyal 
5792cb1309SAkhil Goyal /**
5892cb1309SAkhil Goyal  * @internal
5992cb1309SAkhil Goyal  * The data part, with no function pointers, associated with each device.
6092cb1309SAkhil Goyal  *
6192cb1309SAkhil Goyal  * This structure is safe to place in shared memory to be common among
6292cb1309SAkhil Goyal  * different processes in a multi-process configuration.
6392cb1309SAkhil Goyal  */
64c6552d9aSTyler Retzlaff struct __rte_cache_aligned rte_cryptodev_data {
6592cb1309SAkhil Goyal 	/** Device ID for this instance */
6692cb1309SAkhil Goyal 	uint8_t dev_id;
6792cb1309SAkhil Goyal 	/** Socket ID where memory is allocated */
68f31af82aSCiara Power 	int socket_id;
6992cb1309SAkhil Goyal 	/** Unique identifier name */
7092cb1309SAkhil Goyal 	char name[RTE_CRYPTODEV_NAME_MAX_LEN];
7192cb1309SAkhil Goyal 
7292cb1309SAkhil Goyal 	__extension__
7392cb1309SAkhil Goyal 	/** Device state: STARTED(1)/STOPPED(0) */
7492cb1309SAkhil Goyal 	uint8_t dev_started : 1;
7592cb1309SAkhil Goyal 
7692cb1309SAkhil Goyal 	/** Session memory pool */
7792cb1309SAkhil Goyal 	struct rte_mempool *session_pool;
7892cb1309SAkhil Goyal 	/** Array of pointers to queue pairs. */
7992cb1309SAkhil Goyal 	void **queue_pairs;
8092cb1309SAkhil Goyal 	/** Number of device queue pairs. */
8192cb1309SAkhil Goyal 	uint16_t nb_queue_pairs;
8292cb1309SAkhil Goyal 
8392cb1309SAkhil Goyal 	/** PMD-specific private data */
8492cb1309SAkhil Goyal 	void *dev_private;
85c6552d9aSTyler Retzlaff };
8692cb1309SAkhil Goyal 
8792cb1309SAkhil Goyal /** @internal The data structure associated with each crypto device. */
88c6552d9aSTyler Retzlaff struct __rte_cache_aligned rte_cryptodev {
8992cb1309SAkhil Goyal 	/** Pointer to PMD dequeue function. */
9092cb1309SAkhil Goyal 	dequeue_pkt_burst_t dequeue_burst;
9192cb1309SAkhil Goyal 	/** Pointer to PMD enqueue function. */
9292cb1309SAkhil Goyal 	enqueue_pkt_burst_t enqueue_burst;
9392cb1309SAkhil Goyal 
9492cb1309SAkhil Goyal 	/** Pointer to device data */
9592cb1309SAkhil Goyal 	struct rte_cryptodev_data *data;
9692cb1309SAkhil Goyal 	/** Functions exported by PMD */
9792cb1309SAkhil Goyal 	struct rte_cryptodev_ops *dev_ops;
9892cb1309SAkhil Goyal 	/** Feature flags exposes HW/SW features for the given device */
9992cb1309SAkhil Goyal 	uint64_t feature_flags;
10092cb1309SAkhil Goyal 	/** Backing device */
10192cb1309SAkhil Goyal 	struct rte_device *device;
10292cb1309SAkhil Goyal 
10392cb1309SAkhil Goyal 	/** Crypto driver identifier*/
10492cb1309SAkhil Goyal 	uint8_t driver_id;
10592cb1309SAkhil Goyal 
10692cb1309SAkhil Goyal 	/** User application callback for interrupts if present */
10792cb1309SAkhil Goyal 	struct rte_cryptodev_cb_list link_intr_cbs;
10892cb1309SAkhil Goyal 
10992cb1309SAkhil Goyal 	/** Context for security ops */
11092cb1309SAkhil Goyal 	void *security_ctx;
11192cb1309SAkhil Goyal 
11292cb1309SAkhil Goyal 	__extension__
11392cb1309SAkhil Goyal 	/** Flag indicating the device is attached */
11492cb1309SAkhil Goyal 	uint8_t attached : 1;
11592cb1309SAkhil Goyal 
11692cb1309SAkhil Goyal 	/** User application callback for pre enqueue processing */
11792cb1309SAkhil Goyal 	struct rte_cryptodev_cb_rcu *enq_cbs;
11892cb1309SAkhil Goyal 	/** User application callback for post dequeue processing */
11992cb1309SAkhil Goyal 	struct rte_cryptodev_cb_rcu *deq_cbs;
12023d6f76dSAkhil Goyal 	/** Pointer to PMD function to get used queue pair depth */
12123d6f76dSAkhil Goyal 	crypto_qp_depth_used_t qp_depth_used;
122c6552d9aSTyler Retzlaff };
12392cb1309SAkhil Goyal 
124af668035SAkhil Goyal /** Global structure used for maintaining state of allocated crypto devices */
125af668035SAkhil Goyal struct rte_cryptodev_global {
126af668035SAkhil Goyal 	struct rte_cryptodev *devs;	/**< Device information array */
127af668035SAkhil Goyal 	struct rte_cryptodev_data *data[RTE_CRYPTO_MAX_DEVS];
128af668035SAkhil Goyal 	/**< Device private data */
129af668035SAkhil Goyal 	uint8_t nb_devs;		/**< Number of devices found */
130af668035SAkhil Goyal };
131af668035SAkhil Goyal 
132af668035SAkhil Goyal /* Cryptodev driver, containing the driver ID */
133af668035SAkhil Goyal struct cryptodev_driver {
134f1f6ebc0SWilliam Tu 	RTE_TAILQ_ENTRY(cryptodev_driver) next; /**< Next in list. */
135af668035SAkhil Goyal 	const struct rte_driver *driver;
136af668035SAkhil Goyal 	uint8_t id;
137af668035SAkhil Goyal };
138af668035SAkhil Goyal 
1392a440d6aSAkhil Goyal /** Cryptodev symmetric crypto session
1402a440d6aSAkhil Goyal  * Each session is derived from a fixed xform chain. Therefore each session
1412a440d6aSAkhil Goyal  * has a fixed algo, key, op-type, digest_len etc.
1422a440d6aSAkhil Goyal  */
1432a440d6aSAkhil Goyal struct rte_cryptodev_sym_session {
1442a440d6aSAkhil Goyal 	uint64_t opaque_data;
1452a440d6aSAkhil Goyal 	/**< Can be used for external metadata */
1462a440d6aSAkhil Goyal 	uint32_t sess_data_sz;
1472a440d6aSAkhil Goyal 	/**< Pointer to the user data stored after sess data */
1482a440d6aSAkhil Goyal 	uint16_t user_data_sz;
1492a440d6aSAkhil Goyal 	/**< Session user data will be placed after sess data */
1502a440d6aSAkhil Goyal 	uint8_t driver_id;
1512a440d6aSAkhil Goyal 	/**< Driver id to get the session priv */
1522a440d6aSAkhil Goyal 	rte_iova_t driver_priv_data_iova;
1532a440d6aSAkhil Goyal 	/**< Session driver data IOVA address */
1542a440d6aSAkhil Goyal 
1558f6163e7STyler Retzlaff 	alignas(RTE_CACHE_LINE_MIN_SIZE)
1562a440d6aSAkhil Goyal 	/**< Second cache line - start of the driver session data */
1579ce70ed8SStephen Hemminger 	uint8_t driver_priv_data[];
1582a440d6aSAkhil Goyal 	/**< Driver specific session data, variable size */
1592a440d6aSAkhil Goyal };
1602a440d6aSAkhil Goyal 
1612a440d6aSAkhil Goyal /**
1622a440d6aSAkhil Goyal  * Helper macro to get driver private data
1632a440d6aSAkhil Goyal  */
1642a440d6aSAkhil Goyal #define CRYPTODEV_GET_SYM_SESS_PRIV(s) \
1652a440d6aSAkhil Goyal 	((void *)(((struct rte_cryptodev_sym_session *)s)->driver_priv_data))
1662a440d6aSAkhil Goyal #define CRYPTODEV_GET_SYM_SESS_PRIV_IOVA(s) \
1672a440d6aSAkhil Goyal 	(((struct rte_cryptodev_sym_session *)s)->driver_priv_data_iova)
1682a440d6aSAkhil Goyal 
1692a440d6aSAkhil Goyal 
170af668035SAkhil Goyal /**
171af668035SAkhil Goyal  * Get the rte_cryptodev structure device pointer for the device. Assumes a
172af668035SAkhil Goyal  * valid device index.
173af668035SAkhil Goyal  *
174af668035SAkhil Goyal  * @param	dev_id	Device ID value to select the device structure.
175af668035SAkhil Goyal  *
176af668035SAkhil Goyal  * @return
177af668035SAkhil Goyal  *   - The rte_cryptodev structure pointer for the given device ID.
178af668035SAkhil Goyal  */
179af668035SAkhil Goyal __rte_internal
180af668035SAkhil Goyal struct rte_cryptodev *
181af668035SAkhil Goyal rte_cryptodev_pmd_get_dev(uint8_t dev_id);
182af668035SAkhil Goyal 
183af668035SAkhil Goyal /**
184af668035SAkhil Goyal  * Get the rte_cryptodev structure device pointer for the named device.
185af668035SAkhil Goyal  *
186af668035SAkhil Goyal  * @param	name	device name to select the device structure.
187af668035SAkhil Goyal  *
188af668035SAkhil Goyal  * @return
189af668035SAkhil Goyal  *   - The rte_cryptodev structure pointer for the given device ID.
190af668035SAkhil Goyal  */
191af668035SAkhil Goyal __rte_internal
192af668035SAkhil Goyal struct rte_cryptodev *
193af668035SAkhil Goyal rte_cryptodev_pmd_get_named_dev(const char *name);
194af668035SAkhil Goyal 
195af668035SAkhil Goyal /**
196af668035SAkhil Goyal  * Definitions of all functions exported by a driver through the
197b53d106dSSean Morrissey  * generic structure of type *crypto_dev_ops* supplied in the
198af668035SAkhil Goyal  * *rte_cryptodev* structure associated with a device.
199af668035SAkhil Goyal  */
200af668035SAkhil Goyal 
201af668035SAkhil Goyal /**
202af668035SAkhil Goyal  *	Function used to configure device.
203af668035SAkhil Goyal  *
204af668035SAkhil Goyal  * @param	dev	Crypto device pointer
205af668035SAkhil Goyal  * @param	config	Crypto device configurations
206af668035SAkhil Goyal  *
207af668035SAkhil Goyal  * @return	Returns 0 on success
208af668035SAkhil Goyal  */
209af668035SAkhil Goyal typedef int (*cryptodev_configure_t)(struct rte_cryptodev *dev,
210af668035SAkhil Goyal 		struct rte_cryptodev_config *config);
211af668035SAkhil Goyal 
212af668035SAkhil Goyal /**
213af668035SAkhil Goyal  * Function used to start a configured device.
214af668035SAkhil Goyal  *
215af668035SAkhil Goyal  * @param	dev	Crypto device pointer
216af668035SAkhil Goyal  *
217af668035SAkhil Goyal  * @return	Returns 0 on success
218af668035SAkhil Goyal  */
219af668035SAkhil Goyal typedef int (*cryptodev_start_t)(struct rte_cryptodev *dev);
220af668035SAkhil Goyal 
221af668035SAkhil Goyal /**
222af668035SAkhil Goyal  * Function used to stop a configured device.
223af668035SAkhil Goyal  *
224af668035SAkhil Goyal  * @param	dev	Crypto device pointer
225af668035SAkhil Goyal  */
226af668035SAkhil Goyal typedef void (*cryptodev_stop_t)(struct rte_cryptodev *dev);
227af668035SAkhil Goyal 
228af668035SAkhil Goyal /**
229af668035SAkhil Goyal  * Function used to close a configured device.
230af668035SAkhil Goyal  *
231af668035SAkhil Goyal  * @param	dev	Crypto device pointer
232af668035SAkhil Goyal  * @return
233af668035SAkhil Goyal  * - 0 on success.
234af668035SAkhil Goyal  * - EAGAIN if can't close as device is busy
235af668035SAkhil Goyal  */
236af668035SAkhil Goyal typedef int (*cryptodev_close_t)(struct rte_cryptodev *dev);
237af668035SAkhil Goyal 
238af668035SAkhil Goyal 
239af668035SAkhil Goyal /**
240af668035SAkhil Goyal  * Function used to get statistics of a device.
241af668035SAkhil Goyal  *
242af668035SAkhil Goyal  * @param	dev	Crypto device pointer
243af668035SAkhil Goyal  * @param	stats	Pointer to crypto device stats structure to populate
244af668035SAkhil Goyal  */
245af668035SAkhil Goyal typedef void (*cryptodev_stats_get_t)(struct rte_cryptodev *dev,
246af668035SAkhil Goyal 				struct rte_cryptodev_stats *stats);
247af668035SAkhil Goyal 
248af668035SAkhil Goyal 
249af668035SAkhil Goyal /**
250af668035SAkhil Goyal  * Function used to reset statistics of a device.
251af668035SAkhil Goyal  *
252af668035SAkhil Goyal  * @param	dev	Crypto device pointer
253af668035SAkhil Goyal  */
254af668035SAkhil Goyal typedef void (*cryptodev_stats_reset_t)(struct rte_cryptodev *dev);
255af668035SAkhil Goyal 
256af668035SAkhil Goyal 
257af668035SAkhil Goyal /**
258af668035SAkhil Goyal  * Function used to get specific information of a device.
259af668035SAkhil Goyal  *
260af668035SAkhil Goyal  * @param	dev		Crypto device pointer
261af668035SAkhil Goyal  * @param	dev_info	Pointer to infos structure to populate
262af668035SAkhil Goyal  */
263af668035SAkhil Goyal typedef void (*cryptodev_info_get_t)(struct rte_cryptodev *dev,
264af668035SAkhil Goyal 				struct rte_cryptodev_info *dev_info);
265af668035SAkhil Goyal 
266af668035SAkhil Goyal /**
267af668035SAkhil Goyal  * Setup a queue pair for a device.
268af668035SAkhil Goyal  *
269af668035SAkhil Goyal  * @param	dev		Crypto device pointer
270af668035SAkhil Goyal  * @param	qp_id		Queue Pair Index
271af668035SAkhil Goyal  * @param	qp_conf		Queue configuration structure
272af668035SAkhil Goyal  * @param	socket_id	Socket Index
273af668035SAkhil Goyal  *
274af668035SAkhil Goyal  * @return	Returns 0 on success.
275af668035SAkhil Goyal  */
276af668035SAkhil Goyal typedef int (*cryptodev_queue_pair_setup_t)(struct rte_cryptodev *dev,
277af668035SAkhil Goyal 		uint16_t qp_id,	const struct rte_cryptodev_qp_conf *qp_conf,
278af668035SAkhil Goyal 		int socket_id);
279af668035SAkhil Goyal 
280af668035SAkhil Goyal /**
281af668035SAkhil Goyal  * Release memory resources allocated by given queue pair.
282af668035SAkhil Goyal  *
283af668035SAkhil Goyal  * @param	dev	Crypto device pointer
284af668035SAkhil Goyal  * @param	qp_id	Queue Pair Index
285af668035SAkhil Goyal  *
286af668035SAkhil Goyal  * @return
287af668035SAkhil Goyal  * - 0 on success.
288af668035SAkhil Goyal  * - EAGAIN if can't close as device is busy
289af668035SAkhil Goyal  */
290af668035SAkhil Goyal typedef int (*cryptodev_queue_pair_release_t)(struct rte_cryptodev *dev,
291af668035SAkhil Goyal 		uint16_t qp_id);
292af668035SAkhil Goyal 
293af668035SAkhil Goyal /**
294*0a054e8dSVidya Sagar Velumuri  * Reset or reconfigure a queue pair for a device.
295*0a054e8dSVidya Sagar Velumuri  *
296*0a054e8dSVidya Sagar Velumuri  * @param	dev		Crypto device pointer
297*0a054e8dSVidya Sagar Velumuri  * @param	qp_id		Queue pair index
298*0a054e8dSVidya Sagar Velumuri  * @param	qp_conf		Queue configuration structure
299*0a054e8dSVidya Sagar Velumuri  * @param	socket_id	Socket index
300*0a054e8dSVidya Sagar Velumuri  *
301*0a054e8dSVidya Sagar Velumuri  * @return
302*0a054e8dSVidya Sagar Velumuri  *  - 0: on success.
303*0a054e8dSVidya Sagar Velumuri  *  - ENOTSUP: if crypto device does not support the operation.
304*0a054e8dSVidya Sagar Velumuri  */
305*0a054e8dSVidya Sagar Velumuri typedef int (*cryptodev_queue_pair_reset_t)(struct rte_cryptodev *dev,
306*0a054e8dSVidya Sagar Velumuri 		uint16_t qp_id,	const struct rte_cryptodev_qp_conf *qp_conf,
307*0a054e8dSVidya Sagar Velumuri 		int socket_id);
308*0a054e8dSVidya Sagar Velumuri 
309*0a054e8dSVidya Sagar Velumuri /**
310af668035SAkhil Goyal  * Create a session mempool to allocate sessions from
311af668035SAkhil Goyal  *
312af668035SAkhil Goyal  * @param	dev		Crypto device pointer
313af668035SAkhil Goyal  * @param	nb_objs		number of sessions objects in mempool
314af668035SAkhil Goyal  * @param	obj_cache_size	l-core object cache size, see *rte_ring_create*
315af668035SAkhil Goyal  * @param	socket_id	Socket Id to allocate  mempool on.
316af668035SAkhil Goyal  *
317af668035SAkhil Goyal  * @return
318af668035SAkhil Goyal  * - On success returns a pointer to a rte_mempool
319af668035SAkhil Goyal  * - On failure returns a NULL pointer
320af668035SAkhil Goyal  */
321af668035SAkhil Goyal typedef int (*cryptodev_sym_create_session_pool_t)(
322af668035SAkhil Goyal 		struct rte_cryptodev *dev, unsigned nb_objs,
323af668035SAkhil Goyal 		unsigned obj_cache_size, int socket_id);
324af668035SAkhil Goyal 
325af668035SAkhil Goyal 
326af668035SAkhil Goyal /**
327af668035SAkhil Goyal  * Get the size of a cryptodev session
328af668035SAkhil Goyal  *
329af668035SAkhil Goyal  * @param	dev		Crypto device pointer
330af668035SAkhil Goyal  *
331af668035SAkhil Goyal  * @return
332af668035SAkhil Goyal  *  - On success returns the size of the session structure for device
333af668035SAkhil Goyal  *  - On failure returns 0
334af668035SAkhil Goyal  */
335af668035SAkhil Goyal typedef unsigned (*cryptodev_sym_get_session_private_size_t)(
336af668035SAkhil Goyal 		struct rte_cryptodev *dev);
337af668035SAkhil Goyal /**
338af668035SAkhil Goyal  * Get the size of a asymmetric cryptodev session
339af668035SAkhil Goyal  *
340af668035SAkhil Goyal  * @param	dev		Crypto device pointer
341af668035SAkhil Goyal  *
342af668035SAkhil Goyal  * @return
343af668035SAkhil Goyal  *  - On success returns the size of the session structure for device
344af668035SAkhil Goyal  *  - On failure returns 0
345af668035SAkhil Goyal  */
346af668035SAkhil Goyal typedef unsigned int (*cryptodev_asym_get_session_private_size_t)(
347af668035SAkhil Goyal 		struct rte_cryptodev *dev);
348af668035SAkhil Goyal 
349af668035SAkhil Goyal /**
350af668035SAkhil Goyal  * Configure a Crypto session on a device.
351af668035SAkhil Goyal  *
352af668035SAkhil Goyal  * @param	dev		Crypto device pointer
353af668035SAkhil Goyal  * @param	xform		Single or chain of crypto xforms
354af668035SAkhil Goyal  * @param	session		Pointer to cryptodev's private session structure
355af668035SAkhil Goyal  *
356af668035SAkhil Goyal  * @return
357af668035SAkhil Goyal  *  - Returns 0 if private session structure have been created successfully.
358af668035SAkhil Goyal  *  - Returns -EINVAL if input parameters are invalid.
359af668035SAkhil Goyal  *  - Returns -ENOTSUP if crypto device does not support the crypto transform.
360af668035SAkhil Goyal  *  - Returns -ENOMEM if the private session could not be allocated.
361af668035SAkhil Goyal  */
362af668035SAkhil Goyal typedef int (*cryptodev_sym_configure_session_t)(struct rte_cryptodev *dev,
363af668035SAkhil Goyal 		struct rte_crypto_sym_xform *xform,
364bdce2564SAkhil Goyal 		struct rte_cryptodev_sym_session *session);
365bdce2564SAkhil Goyal 
366af668035SAkhil Goyal /**
367af668035SAkhil Goyal  * Configure a Crypto asymmetric session on a device.
368af668035SAkhil Goyal  *
369af668035SAkhil Goyal  * @param	dev		Crypto device pointer
370af668035SAkhil Goyal  * @param	xform		Single or chain of crypto xforms
371af668035SAkhil Goyal  * @param	session		Pointer to cryptodev's private session structure
372af668035SAkhil Goyal  *
373af668035SAkhil Goyal  * @return
374af668035SAkhil Goyal  *  - Returns 0 if private session structure have been created successfully.
375af668035SAkhil Goyal  *  - Returns -EINVAL if input parameters are invalid.
376af668035SAkhil Goyal  *  - Returns -ENOTSUP if crypto device does not support the crypto transform.
377af668035SAkhil Goyal  *  - Returns -ENOMEM if the private session could not be allocated.
378af668035SAkhil Goyal  */
379af668035SAkhil Goyal typedef int (*cryptodev_asym_configure_session_t)(struct rte_cryptodev *dev,
380af668035SAkhil Goyal 		struct rte_crypto_asym_xform *xform,
3811f1e4b7cSCiara Power 		struct rte_cryptodev_asym_session *session);
382af668035SAkhil Goyal /**
383af668035SAkhil Goyal  * Free driver private session data.
384af668035SAkhil Goyal  *
385af668035SAkhil Goyal  * @param	dev		Crypto device pointer
386af668035SAkhil Goyal  * @param	sess		Cryptodev session structure
387af668035SAkhil Goyal  */
388af668035SAkhil Goyal typedef void (*cryptodev_sym_free_session_t)(struct rte_cryptodev *dev,
389af668035SAkhil Goyal 		struct rte_cryptodev_sym_session *sess);
390bdce2564SAkhil Goyal 
391af668035SAkhil Goyal /**
3921f1e4b7cSCiara Power  * Clear asymmetric session private data.
393af668035SAkhil Goyal  *
394af668035SAkhil Goyal  * @param	dev		Crypto device pointer
395af668035SAkhil Goyal  * @param	sess		Cryptodev session structure
396af668035SAkhil Goyal  */
3971f1e4b7cSCiara Power typedef void (*cryptodev_asym_clear_session_t)(struct rte_cryptodev *dev,
398af668035SAkhil Goyal 		struct rte_cryptodev_asym_session *sess);
399af668035SAkhil Goyal /**
400af668035SAkhil Goyal  * Perform actual crypto processing (encrypt/digest or auth/decrypt)
401af668035SAkhil Goyal  * on user provided data.
402af668035SAkhil Goyal  *
403af668035SAkhil Goyal  * @param	dev	Crypto device pointer
404af668035SAkhil Goyal  * @param	sess	Cryptodev session structure
405af668035SAkhil Goyal  * @param	ofs	Start and stop offsets for auth and cipher operations
406af668035SAkhil Goyal  * @param	vec	Vectorized operation descriptor
407af668035SAkhil Goyal  *
408af668035SAkhil Goyal  * @return
409af668035SAkhil Goyal  *  - Returns number of successfully processed packets.
410af668035SAkhil Goyal  */
411af668035SAkhil Goyal typedef uint32_t (*cryptodev_sym_cpu_crypto_process_t)
412af668035SAkhil Goyal 	(struct rte_cryptodev *dev, struct rte_cryptodev_sym_session *sess,
413af668035SAkhil Goyal 	union rte_crypto_sym_ofs ofs, struct rte_crypto_sym_vec *vec);
414af668035SAkhil Goyal 
415af668035SAkhil Goyal /**
416af668035SAkhil Goyal  * Typedef that the driver provided to get service context private date size.
417af668035SAkhil Goyal  *
418af668035SAkhil Goyal  * @param	dev	Crypto device pointer.
419af668035SAkhil Goyal  *
420af668035SAkhil Goyal  * @return
421af668035SAkhil Goyal  *   - On success return the size of the device's service context private data.
422af668035SAkhil Goyal  *   - On failure return negative integer.
423af668035SAkhil Goyal  */
424af668035SAkhil Goyal typedef int (*cryptodev_sym_get_raw_dp_ctx_size_t)(struct rte_cryptodev *dev);
425af668035SAkhil Goyal 
426af668035SAkhil Goyal /**
427af668035SAkhil Goyal  * Typedef that the driver provided to configure raw data-path context.
428af668035SAkhil Goyal  *
429af668035SAkhil Goyal  * @param	dev		Crypto device pointer.
430af668035SAkhil Goyal  * @param	qp_id		Crypto device queue pair index.
431af668035SAkhil Goyal  * @param	ctx		The raw data-path context data.
432af668035SAkhil Goyal  * @param	sess_type	session type.
433af668035SAkhil Goyal  * @param	session_ctx	Session context data. If NULL the driver
434af668035SAkhil Goyal  *				shall only configure the drv_ctx_data in
435af668035SAkhil Goyal  *				ctx buffer. Otherwise the driver shall only
436af668035SAkhil Goyal  *				parse the session_ctx to set appropriate
437af668035SAkhil Goyal  *				function pointers in ctx.
438af668035SAkhil Goyal  * @param	is_update	Set 0 if it is to initialize the ctx.
439af668035SAkhil Goyal  *				Set 1 if ctx is initialized and only to update
440af668035SAkhil Goyal  *				session context data.
441af668035SAkhil Goyal  * @return
442af668035SAkhil Goyal  *   - On success return 0.
443af668035SAkhil Goyal  *   - On failure return negative integer.
444af668035SAkhil Goyal  */
445af668035SAkhil Goyal typedef int (*cryptodev_sym_configure_raw_dp_ctx_t)(
446af668035SAkhil Goyal 	struct rte_cryptodev *dev, uint16_t qp_id,
447af668035SAkhil Goyal 	struct rte_crypto_raw_dp_ctx *ctx,
448af668035SAkhil Goyal 	enum rte_crypto_op_sess_type sess_type,
449af668035SAkhil Goyal 	union rte_cryptodev_session_ctx session_ctx, uint8_t is_update);
450af668035SAkhil Goyal 
451a7ddfa9cSVolodymyr Fialko /**
452a7ddfa9cSVolodymyr Fialko  * Typedef that the driver provided to set event crypto meta data.
453a7ddfa9cSVolodymyr Fialko  *
454a7ddfa9cSVolodymyr Fialko  * @param	dev		Crypto device pointer.
455a7ddfa9cSVolodymyr Fialko  * @param	sess		Crypto or security session.
456a7ddfa9cSVolodymyr Fialko  * @param	op_type		Operation type.
457a7ddfa9cSVolodymyr Fialko  * @param	sess_type	Session type.
458a7ddfa9cSVolodymyr Fialko  * @param	ev_mdata	Pointer to the event crypto meta data
459a7ddfa9cSVolodymyr Fialko  *				(aka *union rte_event_crypto_metadata*)
460a7ddfa9cSVolodymyr Fialko  * @return
461a7ddfa9cSVolodymyr Fialko  *   - On success return 0.
462a7ddfa9cSVolodymyr Fialko  *   - On failure return negative integer.
463a7ddfa9cSVolodymyr Fialko  */
464a7ddfa9cSVolodymyr Fialko typedef int (*cryptodev_session_event_mdata_set_t)(
465a7ddfa9cSVolodymyr Fialko 	struct rte_cryptodev *dev, void *sess,
466a7ddfa9cSVolodymyr Fialko 	enum rte_crypto_op_type op_type,
467a7ddfa9cSVolodymyr Fialko 	enum rte_crypto_op_sess_type sess_type,
468a7ddfa9cSVolodymyr Fialko 	void *ev_mdata);
469a7ddfa9cSVolodymyr Fialko 
470d43e6a01SSrujana Challa /**
471d43e6a01SSrujana Challa  * @internal Query queue pair error interrupt event.
472d43e6a01SSrujana Challa  * @see rte_cryptodev_queue_pair_event_error_query()
473d43e6a01SSrujana Challa  */
474d43e6a01SSrujana Challa typedef int (*cryptodev_queue_pair_event_error_query_t)(struct rte_cryptodev *dev,
475d43e6a01SSrujana Challa 					uint16_t qp_id);
476d43e6a01SSrujana Challa 
477af668035SAkhil Goyal /** Crypto device operations function pointer table */
478af668035SAkhil Goyal struct rte_cryptodev_ops {
479af668035SAkhil Goyal 	cryptodev_configure_t dev_configure;	/**< Configure device. */
480af668035SAkhil Goyal 	cryptodev_start_t dev_start;		/**< Start device. */
481af668035SAkhil Goyal 	cryptodev_stop_t dev_stop;		/**< Stop device. */
482af668035SAkhil Goyal 	cryptodev_close_t dev_close;		/**< Close device. */
483af668035SAkhil Goyal 
484af668035SAkhil Goyal 	cryptodev_info_get_t dev_infos_get;	/**< Get device info. */
485af668035SAkhil Goyal 
486af668035SAkhil Goyal 	cryptodev_stats_get_t stats_get;
487af668035SAkhil Goyal 	/**< Get device statistics. */
488af668035SAkhil Goyal 	cryptodev_stats_reset_t stats_reset;
489af668035SAkhil Goyal 	/**< Reset device statistics. */
490af668035SAkhil Goyal 
491af668035SAkhil Goyal 	cryptodev_queue_pair_setup_t queue_pair_setup;
492af668035SAkhil Goyal 	/**< Set up a device queue pair. */
493af668035SAkhil Goyal 	cryptodev_queue_pair_release_t queue_pair_release;
494af668035SAkhil Goyal 	/**< Release a queue pair. */
495*0a054e8dSVidya Sagar Velumuri 	cryptodev_queue_pair_reset_t queue_pair_reset;
496*0a054e8dSVidya Sagar Velumuri 	/**< Reset a queue pair. */
497af668035SAkhil Goyal 
498af668035SAkhil Goyal 	cryptodev_sym_get_session_private_size_t sym_session_get_size;
499af668035SAkhil Goyal 	/**< Return private session. */
500af668035SAkhil Goyal 	cryptodev_asym_get_session_private_size_t asym_session_get_size;
501af668035SAkhil Goyal 	/**< Return asym session private size. */
502af668035SAkhil Goyal 	cryptodev_sym_configure_session_t sym_session_configure;
503af668035SAkhil Goyal 	/**< Configure a Crypto session. */
504af668035SAkhil Goyal 	cryptodev_asym_configure_session_t asym_session_configure;
505af668035SAkhil Goyal 	/**< Configure asymmetric Crypto session. */
506af668035SAkhil Goyal 	cryptodev_sym_free_session_t sym_session_clear;
507af668035SAkhil Goyal 	/**< Clear a Crypto sessions private data. */
5081f1e4b7cSCiara Power 	cryptodev_asym_clear_session_t asym_session_clear;
509af668035SAkhil Goyal 	/**< Clear a Crypto sessions private data. */
510af668035SAkhil Goyal 	union {
511af668035SAkhil Goyal 		cryptodev_sym_cpu_crypto_process_t sym_cpu_process;
512af668035SAkhil Goyal 		/**< process input data synchronously (cpu-crypto). */
513af668035SAkhil Goyal 		__extension__
514af668035SAkhil Goyal 		struct {
515af668035SAkhil Goyal 			cryptodev_sym_get_raw_dp_ctx_size_t
516af668035SAkhil Goyal 				sym_get_raw_dp_ctx_size;
517af668035SAkhil Goyal 			/**< Get raw data path service context data size. */
518af668035SAkhil Goyal 			cryptodev_sym_configure_raw_dp_ctx_t
519af668035SAkhil Goyal 				sym_configure_raw_dp_ctx;
520af668035SAkhil Goyal 			/**< Initialize raw data path context data. */
521af668035SAkhil Goyal 		};
522af668035SAkhil Goyal 	};
523a7ddfa9cSVolodymyr Fialko 	cryptodev_session_event_mdata_set_t session_ev_mdata_set;
524a7ddfa9cSVolodymyr Fialko 	/**< Set a Crypto or Security session even meta data. */
525d43e6a01SSrujana Challa 	cryptodev_queue_pair_event_error_query_t queue_pair_event_error_query;
526d43e6a01SSrujana Challa 	/**< Query queue error interrupt event */
527af668035SAkhil Goyal };
528af668035SAkhil Goyal 
529af668035SAkhil Goyal 
530af668035SAkhil Goyal /**
531af668035SAkhil Goyal  * Function for internal use by dummy drivers primarily, e.g. ring-based
532af668035SAkhil Goyal  * driver.
533af668035SAkhil Goyal  * Allocates a new cryptodev slot for an crypto device and returns the pointer
534af668035SAkhil Goyal  * to that slot for the driver to use.
535af668035SAkhil Goyal  *
536af668035SAkhil Goyal  * @param	name		Unique identifier name for each device
537af668035SAkhil Goyal  * @param	socket_id	Socket to allocate resources on.
538af668035SAkhil Goyal  * @return
539af668035SAkhil Goyal  *   - Slot in the rte_dev_devices array for a new device;
540af668035SAkhil Goyal  */
541af668035SAkhil Goyal __rte_internal
542af668035SAkhil Goyal struct rte_cryptodev *
543af668035SAkhil Goyal rte_cryptodev_pmd_allocate(const char *name, int socket_id);
544af668035SAkhil Goyal 
545af668035SAkhil Goyal /**
546af668035SAkhil Goyal  * Function for internal use by dummy drivers primarily, e.g. ring-based
547af668035SAkhil Goyal  * driver.
548af668035SAkhil Goyal  * Release the specified cryptodev device.
549af668035SAkhil Goyal  *
550af668035SAkhil Goyal  * @param cryptodev
551af668035SAkhil Goyal  * The *cryptodev* pointer is the address of the *rte_cryptodev* structure.
552af668035SAkhil Goyal  * @return
553af668035SAkhil Goyal  *   - 0 on success, negative on error
554af668035SAkhil Goyal  */
555af668035SAkhil Goyal __rte_internal
55616bd1c62SThomas Monjalon int
557af668035SAkhil Goyal rte_cryptodev_pmd_release_device(struct rte_cryptodev *cryptodev);
558af668035SAkhil Goyal 
559af668035SAkhil Goyal 
560af668035SAkhil Goyal /**
561af668035SAkhil Goyal  * @internal
562af668035SAkhil Goyal  *
563af668035SAkhil Goyal  * PMD assist function to parse initialisation arguments for crypto driver
564af668035SAkhil Goyal  * when creating a new crypto PMD device instance.
565af668035SAkhil Goyal  *
566f8dbaebbSSean Morrissey  * PMD should set default values for that PMD before calling function,
567af668035SAkhil Goyal  * these default values will be over-written with successfully parsed values
568af668035SAkhil Goyal  * from args string.
569af668035SAkhil Goyal  *
570af668035SAkhil Goyal  * @param	params	parsed PMD initialisation parameters
571af668035SAkhil Goyal  * @param	args	input argument string to parse
572af668035SAkhil Goyal  *
573af668035SAkhil Goyal  * @return
574af668035SAkhil Goyal  *  - 0 on success
575af668035SAkhil Goyal  *  - errno on failure
576af668035SAkhil Goyal  */
577af668035SAkhil Goyal __rte_internal
578af668035SAkhil Goyal int
579af668035SAkhil Goyal rte_cryptodev_pmd_parse_input_args(
580af668035SAkhil Goyal 		struct rte_cryptodev_pmd_init_params *params,
581af668035SAkhil Goyal 		const char *args);
582af668035SAkhil Goyal 
583af668035SAkhil Goyal /**
584af668035SAkhil Goyal  * @internal
585af668035SAkhil Goyal  *
586af668035SAkhil Goyal  * PMD assist function to provide boiler plate code for crypto driver to create
587af668035SAkhil Goyal  * and allocate resources for a new crypto PMD device instance.
588af668035SAkhil Goyal  *
589af668035SAkhil Goyal  * @param	name	crypto device name.
590af668035SAkhil Goyal  * @param	device	base device instance
591af668035SAkhil Goyal  * @param	params	PMD initialisation parameters
592af668035SAkhil Goyal  *
593af668035SAkhil Goyal  * @return
594af668035SAkhil Goyal  *  - crypto device instance on success
595af668035SAkhil Goyal  *  - NULL on creation failure
596af668035SAkhil Goyal  */
597af668035SAkhil Goyal __rte_internal
598af668035SAkhil Goyal struct rte_cryptodev *
599af668035SAkhil Goyal rte_cryptodev_pmd_create(const char *name,
600af668035SAkhil Goyal 		struct rte_device *device,
601af668035SAkhil Goyal 		struct rte_cryptodev_pmd_init_params *params);
602af668035SAkhil Goyal 
603af668035SAkhil Goyal /**
604af668035SAkhil Goyal  * @internal
605af668035SAkhil Goyal  *
606af668035SAkhil Goyal  * PMD assist function to provide boiler plate code for crypto driver to
607af668035SAkhil Goyal  * destroy and free resources associated with a crypto PMD device instance.
608af668035SAkhil Goyal  *
609af668035SAkhil Goyal  * @param	cryptodev	crypto device handle.
610af668035SAkhil Goyal  *
611af668035SAkhil Goyal  * @return
612af668035SAkhil Goyal  *  - 0 on success
613af668035SAkhil Goyal  *  - errno on failure
614af668035SAkhil Goyal  */
615af668035SAkhil Goyal __rte_internal
616af668035SAkhil Goyal int
617af668035SAkhil Goyal rte_cryptodev_pmd_destroy(struct rte_cryptodev *cryptodev);
618af668035SAkhil Goyal 
619af668035SAkhil Goyal /**
620af668035SAkhil Goyal  * Executes all the user application registered callbacks for the specific
621af668035SAkhil Goyal  * device.
622af668035SAkhil Goyal  *  *
623af668035SAkhil Goyal  * @param	dev	Pointer to cryptodev struct
624af668035SAkhil Goyal  * @param	event	Crypto device interrupt event type.
625af668035SAkhil Goyal  *
626af668035SAkhil Goyal  * @return
627af668035SAkhil Goyal  *  void
628af668035SAkhil Goyal  */
629af668035SAkhil Goyal __rte_internal
630af668035SAkhil Goyal void rte_cryptodev_pmd_callback_process(struct rte_cryptodev *dev,
631af668035SAkhil Goyal 				enum rte_cryptodev_event_type event);
632af668035SAkhil Goyal 
633af668035SAkhil Goyal /**
634af668035SAkhil Goyal  * @internal
635af668035SAkhil Goyal  * Create unique device name
636af668035SAkhil Goyal  */
637af668035SAkhil Goyal __rte_internal
638af668035SAkhil Goyal int
639af668035SAkhil Goyal rte_cryptodev_pmd_create_dev_name(char *name, const char *dev_name_prefix);
640af668035SAkhil Goyal 
641af668035SAkhil Goyal /**
642af668035SAkhil Goyal  * @internal
643af668035SAkhil Goyal  * Allocate Cryptodev driver.
644af668035SAkhil Goyal  *
645af668035SAkhil Goyal  * @param crypto_drv
646af668035SAkhil Goyal  *   Pointer to cryptodev_driver.
647af668035SAkhil Goyal  * @param drv
648af668035SAkhil Goyal  *   Pointer to rte_driver.
649af668035SAkhil Goyal  *
650af668035SAkhil Goyal  * @return
651af668035SAkhil Goyal  *  The driver type identifier
652af668035SAkhil Goyal  */
653af668035SAkhil Goyal __rte_internal
654af668035SAkhil Goyal uint8_t rte_cryptodev_allocate_driver(struct cryptodev_driver *crypto_drv,
655af668035SAkhil Goyal 		const struct rte_driver *drv);
656af668035SAkhil Goyal 
65733cd3fd5SAkhil Goyal /**
65833cd3fd5SAkhil Goyal  * @internal
65933cd3fd5SAkhil Goyal  * This is the last step of device probing. It must be called after a
66033cd3fd5SAkhil Goyal  * cryptodev is allocated and initialized successfully.
66133cd3fd5SAkhil Goyal  *
66233cd3fd5SAkhil Goyal  * @param	dev	Pointer to cryptodev struct
66333cd3fd5SAkhil Goyal  *
66433cd3fd5SAkhil Goyal  * @return
66533cd3fd5SAkhil Goyal  *  void
66633cd3fd5SAkhil Goyal  */
66733cd3fd5SAkhil Goyal __rte_internal
66833cd3fd5SAkhil Goyal void
66933cd3fd5SAkhil Goyal rte_cryptodev_pmd_probing_finish(struct rte_cryptodev *dev);
670af668035SAkhil Goyal 
671af668035SAkhil Goyal #define RTE_PMD_REGISTER_CRYPTO_DRIVER(crypto_drv, drv, driver_id)\
672af668035SAkhil Goyal RTE_INIT(init_ ##driver_id)\
673af668035SAkhil Goyal {\
674af668035SAkhil Goyal 	driver_id = rte_cryptodev_allocate_driver(&crypto_drv, &(drv));\
675af668035SAkhil Goyal }
676af668035SAkhil Goyal 
6772fd66f75SAkhil Goyal /* Reset crypto device fastpath APIs to dummy values. */
6782fd66f75SAkhil Goyal __rte_internal
6792fd66f75SAkhil Goyal void
6802fd66f75SAkhil Goyal cryptodev_fp_ops_reset(struct rte_crypto_fp_ops *fp_ops);
6812fd66f75SAkhil Goyal 
6822fd66f75SAkhil Goyal /* Setup crypto device fastpath APIs. */
6832fd66f75SAkhil Goyal __rte_internal
6842fd66f75SAkhil Goyal void
6852fd66f75SAkhil Goyal cryptodev_fp_ops_set(struct rte_crypto_fp_ops *fp_ops,
6862fd66f75SAkhil Goyal 		     const struct rte_cryptodev *dev);
6872fd66f75SAkhil Goyal 
688a7ddfa9cSVolodymyr Fialko /**
689a7ddfa9cSVolodymyr Fialko  * Get session event meta data (aka *union rte_event_crypto_metadata*)
690a7ddfa9cSVolodymyr Fialko  *
691a7ddfa9cSVolodymyr Fialko  * @param	op            pointer to *rte_crypto_op* structure.
692a7ddfa9cSVolodymyr Fialko  *
693a7ddfa9cSVolodymyr Fialko  * @return
694a7ddfa9cSVolodymyr Fialko  *  - On success, pointer to event crypto metadata
695a7ddfa9cSVolodymyr Fialko  *  - On failure, NULL.
696a7ddfa9cSVolodymyr Fialko  */
697a7ddfa9cSVolodymyr Fialko __rte_internal
698a7ddfa9cSVolodymyr Fialko void *
699a7ddfa9cSVolodymyr Fialko rte_cryptodev_session_event_mdata_get(struct rte_crypto_op *op);
700a7ddfa9cSVolodymyr Fialko 
701a29bb248SCiara Power /**
702a29bb248SCiara Power  * @internal
703a29bb248SCiara Power  * Cryptodev asymmetric crypto session.
704a29bb248SCiara Power  */
705971d2b57STyler Retzlaff struct rte_cryptodev_asym_session {
706a29bb248SCiara Power 	uint8_t driver_id;
707a29bb248SCiara Power 	/**< Session driver ID. */
708a29bb248SCiara Power 	uint16_t max_priv_data_sz;
709a29bb248SCiara Power 	/**< Size of private data used when creating mempool */
71092d55afeSCiara Power 	uint16_t user_data_sz;
71192d55afeSCiara Power 	/**< Session user data will be placed after sess_data */
71292d55afeSCiara Power 	uint8_t padding[3];
713a7ddfa9cSVolodymyr Fialko 	void *event_mdata;
714a7ddfa9cSVolodymyr Fialko 	/**< Event metadata (aka *union rte_event_crypto_metadata*) */
715013b4c52SBruce Richardson 	uint8_t sess_private_data[];
716a29bb248SCiara Power };
717a29bb248SCiara Power 
718a43e3969SBrian Dooley #ifdef __cplusplus
719a43e3969SBrian Dooley }
720a43e3969SBrian Dooley #endif
721a43e3969SBrian Dooley 
722af668035SAkhil Goyal #endif /* _CRYPTODEV_PMD_H_ */
723