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
8*a43e3969SBrian Dooley #ifdef __cplusplus
9*a43e3969SBrian Dooley extern "C" {
10*a43e3969SBrian Dooley #endif
11*a43e3969SBrian Dooley
12af668035SAkhil Goyal /** @file
13af668035SAkhil Goyal * RTE Crypto PMD APIs
14af668035SAkhil Goyal *
15af668035SAkhil Goyal * @note
16af668035SAkhil Goyal * These API are from crypto PMD only and user applications should not call
17af668035SAkhil Goyal * them directly.
18af668035SAkhil Goyal */
19af668035SAkhil Goyal
20af668035SAkhil Goyal #include <string.h>
21af668035SAkhil Goyal
22af668035SAkhil Goyal #include <rte_malloc.h>
23af668035SAkhil Goyal #include <rte_log.h>
24af668035SAkhil Goyal #include <rte_common.h>
25af668035SAkhil Goyal
26af668035SAkhil Goyal #include "rte_crypto.h"
27af668035SAkhil Goyal #include "rte_cryptodev.h"
28af668035SAkhil Goyal
29af668035SAkhil Goyal
30af668035SAkhil Goyal #define RTE_CRYPTODEV_PMD_DEFAULT_MAX_NB_QUEUE_PAIRS 8
31af668035SAkhil Goyal
32af668035SAkhil Goyal #define RTE_CRYPTODEV_PMD_NAME_ARG ("name")
33af668035SAkhil Goyal #define RTE_CRYPTODEV_PMD_MAX_NB_QP_ARG ("max_nb_queue_pairs")
34af668035SAkhil Goyal #define RTE_CRYPTODEV_PMD_SOCKET_ID_ARG ("socket_id")
35af668035SAkhil Goyal
36af668035SAkhil Goyal
37af668035SAkhil Goyal static const char * const cryptodev_pmd_valid_params[] = {
38af668035SAkhil Goyal RTE_CRYPTODEV_PMD_NAME_ARG,
39af668035SAkhil Goyal RTE_CRYPTODEV_PMD_MAX_NB_QP_ARG,
40af668035SAkhil Goyal RTE_CRYPTODEV_PMD_SOCKET_ID_ARG,
41af668035SAkhil Goyal NULL
42af668035SAkhil Goyal };
43af668035SAkhil Goyal
44af668035SAkhil Goyal /**
45af668035SAkhil Goyal * @internal
46af668035SAkhil Goyal * Initialisation parameters for crypto devices
47af668035SAkhil Goyal */
48af668035SAkhil Goyal struct rte_cryptodev_pmd_init_params {
49af668035SAkhil Goyal char name[RTE_CRYPTODEV_NAME_MAX_LEN];
50af668035SAkhil Goyal size_t private_data_size;
51af668035SAkhil Goyal int socket_id;
52af668035SAkhil Goyal unsigned int max_nb_queue_pairs;
53af668035SAkhil Goyal };
54af668035SAkhil Goyal
5592cb1309SAkhil Goyal /**
5692cb1309SAkhil Goyal * @internal
5792cb1309SAkhil Goyal * The data part, with no function pointers, associated with each device.
5892cb1309SAkhil Goyal *
5992cb1309SAkhil Goyal * This structure is safe to place in shared memory to be common among
6092cb1309SAkhil Goyal * different processes in a multi-process configuration.
6192cb1309SAkhil Goyal */
6292cb1309SAkhil Goyal struct rte_cryptodev_data {
6392cb1309SAkhil Goyal /** Device ID for this instance */
6492cb1309SAkhil Goyal uint8_t dev_id;
6592cb1309SAkhil Goyal /** Socket ID where memory is allocated */
6692cb1309SAkhil Goyal uint8_t socket_id;
6792cb1309SAkhil Goyal /** Unique identifier name */
6892cb1309SAkhil Goyal char name[RTE_CRYPTODEV_NAME_MAX_LEN];
6992cb1309SAkhil Goyal
7092cb1309SAkhil Goyal __extension__
7192cb1309SAkhil Goyal /** Device state: STARTED(1)/STOPPED(0) */
7292cb1309SAkhil Goyal uint8_t dev_started : 1;
7392cb1309SAkhil Goyal
7492cb1309SAkhil Goyal /** Session memory pool */
7592cb1309SAkhil Goyal struct rte_mempool *session_pool;
7692cb1309SAkhil Goyal /** Array of pointers to queue pairs. */
7792cb1309SAkhil Goyal void **queue_pairs;
7892cb1309SAkhil Goyal /** Number of device queue pairs. */
7992cb1309SAkhil Goyal uint16_t nb_queue_pairs;
8092cb1309SAkhil Goyal
8192cb1309SAkhil Goyal /** PMD-specific private data */
8292cb1309SAkhil Goyal void *dev_private;
8392cb1309SAkhil Goyal } __rte_cache_aligned;
8492cb1309SAkhil Goyal
8592cb1309SAkhil Goyal /** @internal The data structure associated with each crypto device. */
8692cb1309SAkhil Goyal struct rte_cryptodev {
8792cb1309SAkhil Goyal /** Pointer to PMD dequeue function. */
8892cb1309SAkhil Goyal dequeue_pkt_burst_t dequeue_burst;
8992cb1309SAkhil Goyal /** Pointer to PMD enqueue function. */
9092cb1309SAkhil Goyal enqueue_pkt_burst_t enqueue_burst;
9192cb1309SAkhil Goyal
9292cb1309SAkhil Goyal /** Pointer to device data */
9392cb1309SAkhil Goyal struct rte_cryptodev_data *data;
9492cb1309SAkhil Goyal /** Functions exported by PMD */
9592cb1309SAkhil Goyal struct rte_cryptodev_ops *dev_ops;
9692cb1309SAkhil Goyal /** Feature flags exposes HW/SW features for the given device */
9792cb1309SAkhil Goyal uint64_t feature_flags;
9892cb1309SAkhil Goyal /** Backing device */
9992cb1309SAkhil Goyal struct rte_device *device;
10092cb1309SAkhil Goyal
10192cb1309SAkhil Goyal /** Crypto driver identifier*/
10292cb1309SAkhil Goyal uint8_t driver_id;
10392cb1309SAkhil Goyal
10492cb1309SAkhil Goyal /** User application callback for interrupts if present */
10592cb1309SAkhil Goyal struct rte_cryptodev_cb_list link_intr_cbs;
10692cb1309SAkhil Goyal
10792cb1309SAkhil Goyal /** Context for security ops */
10892cb1309SAkhil Goyal void *security_ctx;
10992cb1309SAkhil Goyal
11092cb1309SAkhil Goyal __extension__
11192cb1309SAkhil Goyal /** Flag indicating the device is attached */
11292cb1309SAkhil Goyal uint8_t attached : 1;
11392cb1309SAkhil Goyal
11492cb1309SAkhil Goyal /** User application callback for pre enqueue processing */
11592cb1309SAkhil Goyal struct rte_cryptodev_cb_rcu *enq_cbs;
11692cb1309SAkhil Goyal /** User application callback for post dequeue processing */
11792cb1309SAkhil Goyal struct rte_cryptodev_cb_rcu *deq_cbs;
11892cb1309SAkhil Goyal } __rte_cache_aligned;
11992cb1309SAkhil Goyal
120af668035SAkhil Goyal /** Global structure used for maintaining state of allocated crypto devices */
121af668035SAkhil Goyal struct rte_cryptodev_global {
122af668035SAkhil Goyal struct rte_cryptodev *devs; /**< Device information array */
123af668035SAkhil Goyal struct rte_cryptodev_data *data[RTE_CRYPTO_MAX_DEVS];
124af668035SAkhil Goyal /**< Device private data */
125af668035SAkhil Goyal uint8_t nb_devs; /**< Number of devices found */
126af668035SAkhil Goyal };
127af668035SAkhil Goyal
128af668035SAkhil Goyal /* Cryptodev driver, containing the driver ID */
129af668035SAkhil Goyal struct cryptodev_driver {
130f1f6ebc0SWilliam Tu RTE_TAILQ_ENTRY(cryptodev_driver) next; /**< Next in list. */
131af668035SAkhil Goyal const struct rte_driver *driver;
132af668035SAkhil Goyal uint8_t id;
133af668035SAkhil Goyal };
134af668035SAkhil Goyal
135af668035SAkhil Goyal /**
136af668035SAkhil Goyal * Get the rte_cryptodev structure device pointer for the device. Assumes a
137af668035SAkhil Goyal * valid device index.
138af668035SAkhil Goyal *
139af668035SAkhil Goyal * @param dev_id Device ID value to select the device structure.
140af668035SAkhil Goyal *
141af668035SAkhil Goyal * @return
142af668035SAkhil Goyal * - The rte_cryptodev structure pointer for the given device ID.
143af668035SAkhil Goyal */
144af668035SAkhil Goyal __rte_internal
145af668035SAkhil Goyal struct rte_cryptodev *
146af668035SAkhil Goyal rte_cryptodev_pmd_get_dev(uint8_t dev_id);
147af668035SAkhil Goyal
148af668035SAkhil Goyal /**
149af668035SAkhil Goyal * Get the rte_cryptodev structure device pointer for the named device.
150af668035SAkhil Goyal *
151af668035SAkhil Goyal * @param name device name to select the device structure.
152af668035SAkhil Goyal *
153af668035SAkhil Goyal * @return
154af668035SAkhil Goyal * - The rte_cryptodev structure pointer for the given device ID.
155af668035SAkhil Goyal */
156af668035SAkhil Goyal __rte_internal
157af668035SAkhil Goyal struct rte_cryptodev *
158af668035SAkhil Goyal rte_cryptodev_pmd_get_named_dev(const char *name);
159af668035SAkhil Goyal
160af668035SAkhil Goyal /**
161af668035SAkhil Goyal * Definitions of all functions exported by a driver through the
162b53d106dSSean Morrissey * generic structure of type *crypto_dev_ops* supplied in the
163af668035SAkhil Goyal * *rte_cryptodev* structure associated with a device.
164af668035SAkhil Goyal */
165af668035SAkhil Goyal
166af668035SAkhil Goyal /**
167af668035SAkhil Goyal * Function used to configure device.
168af668035SAkhil Goyal *
169af668035SAkhil Goyal * @param dev Crypto device pointer
170af668035SAkhil Goyal * @param config Crypto device configurations
171af668035SAkhil Goyal *
172af668035SAkhil Goyal * @return Returns 0 on success
173af668035SAkhil Goyal */
174af668035SAkhil Goyal typedef int (*cryptodev_configure_t)(struct rte_cryptodev *dev,
175af668035SAkhil Goyal struct rte_cryptodev_config *config);
176af668035SAkhil Goyal
177af668035SAkhil Goyal /**
178af668035SAkhil Goyal * Function used to start a configured device.
179af668035SAkhil Goyal *
180af668035SAkhil Goyal * @param dev Crypto device pointer
181af668035SAkhil Goyal *
182af668035SAkhil Goyal * @return Returns 0 on success
183af668035SAkhil Goyal */
184af668035SAkhil Goyal typedef int (*cryptodev_start_t)(struct rte_cryptodev *dev);
185af668035SAkhil Goyal
186af668035SAkhil Goyal /**
187af668035SAkhil Goyal * Function used to stop a configured device.
188af668035SAkhil Goyal *
189af668035SAkhil Goyal * @param dev Crypto device pointer
190af668035SAkhil Goyal */
191af668035SAkhil Goyal typedef void (*cryptodev_stop_t)(struct rte_cryptodev *dev);
192af668035SAkhil Goyal
193af668035SAkhil Goyal /**
194af668035SAkhil Goyal * Function used to close a configured device.
195af668035SAkhil Goyal *
196af668035SAkhil Goyal * @param dev Crypto device pointer
197af668035SAkhil Goyal * @return
198af668035SAkhil Goyal * - 0 on success.
199af668035SAkhil Goyal * - EAGAIN if can't close as device is busy
200af668035SAkhil Goyal */
201af668035SAkhil Goyal typedef int (*cryptodev_close_t)(struct rte_cryptodev *dev);
202af668035SAkhil Goyal
203af668035SAkhil Goyal
204af668035SAkhil Goyal /**
205af668035SAkhil Goyal * Function used to get statistics of a device.
206af668035SAkhil Goyal *
207af668035SAkhil Goyal * @param dev Crypto device pointer
208af668035SAkhil Goyal * @param stats Pointer to crypto device stats structure to populate
209af668035SAkhil Goyal */
210af668035SAkhil Goyal typedef void (*cryptodev_stats_get_t)(struct rte_cryptodev *dev,
211af668035SAkhil Goyal struct rte_cryptodev_stats *stats);
212af668035SAkhil Goyal
213af668035SAkhil Goyal
214af668035SAkhil Goyal /**
215af668035SAkhil Goyal * Function used to reset statistics of a device.
216af668035SAkhil Goyal *
217af668035SAkhil Goyal * @param dev Crypto device pointer
218af668035SAkhil Goyal */
219af668035SAkhil Goyal typedef void (*cryptodev_stats_reset_t)(struct rte_cryptodev *dev);
220af668035SAkhil Goyal
221af668035SAkhil Goyal
222af668035SAkhil Goyal /**
223af668035SAkhil Goyal * Function used to get specific information of a device.
224af668035SAkhil Goyal *
225af668035SAkhil Goyal * @param dev Crypto device pointer
226af668035SAkhil Goyal * @param dev_info Pointer to infos structure to populate
227af668035SAkhil Goyal */
228af668035SAkhil Goyal typedef void (*cryptodev_info_get_t)(struct rte_cryptodev *dev,
229af668035SAkhil Goyal struct rte_cryptodev_info *dev_info);
230af668035SAkhil Goyal
231af668035SAkhil Goyal /**
232af668035SAkhil Goyal * Setup a queue pair for a device.
233af668035SAkhil Goyal *
234af668035SAkhil Goyal * @param dev Crypto device pointer
235af668035SAkhil Goyal * @param qp_id Queue Pair Index
236af668035SAkhil Goyal * @param qp_conf Queue configuration structure
237af668035SAkhil Goyal * @param socket_id Socket Index
238af668035SAkhil Goyal *
239af668035SAkhil Goyal * @return Returns 0 on success.
240af668035SAkhil Goyal */
241af668035SAkhil Goyal typedef int (*cryptodev_queue_pair_setup_t)(struct rte_cryptodev *dev,
242af668035SAkhil Goyal uint16_t qp_id, const struct rte_cryptodev_qp_conf *qp_conf,
243af668035SAkhil Goyal int socket_id);
244af668035SAkhil Goyal
245af668035SAkhil Goyal /**
246af668035SAkhil Goyal * Release memory resources allocated by given queue pair.
247af668035SAkhil Goyal *
248af668035SAkhil Goyal * @param dev Crypto device pointer
249af668035SAkhil Goyal * @param qp_id Queue Pair Index
250af668035SAkhil Goyal *
251af668035SAkhil Goyal * @return
252af668035SAkhil Goyal * - 0 on success.
253af668035SAkhil Goyal * - EAGAIN if can't close as device is busy
254af668035SAkhil Goyal */
255af668035SAkhil Goyal typedef int (*cryptodev_queue_pair_release_t)(struct rte_cryptodev *dev,
256af668035SAkhil Goyal uint16_t qp_id);
257af668035SAkhil Goyal
258af668035SAkhil Goyal /**
259af668035SAkhil Goyal * Create a session mempool to allocate sessions from
260af668035SAkhil Goyal *
261af668035SAkhil Goyal * @param dev Crypto device pointer
262af668035SAkhil Goyal * @param nb_objs number of sessions objects in mempool
263af668035SAkhil Goyal * @param obj_cache_size l-core object cache size, see *rte_ring_create*
264af668035SAkhil Goyal * @param socket_id Socket Id to allocate mempool on.
265af668035SAkhil Goyal *
266af668035SAkhil Goyal * @return
267af668035SAkhil Goyal * - On success returns a pointer to a rte_mempool
268af668035SAkhil Goyal * - On failure returns a NULL pointer
269af668035SAkhil Goyal */
270af668035SAkhil Goyal typedef int (*cryptodev_sym_create_session_pool_t)(
271af668035SAkhil Goyal struct rte_cryptodev *dev, unsigned nb_objs,
272af668035SAkhil Goyal unsigned obj_cache_size, int socket_id);
273af668035SAkhil Goyal
274af668035SAkhil Goyal
275af668035SAkhil Goyal /**
276af668035SAkhil Goyal * Get the size of a cryptodev session
277af668035SAkhil Goyal *
278af668035SAkhil Goyal * @param dev Crypto device pointer
279af668035SAkhil Goyal *
280af668035SAkhil Goyal * @return
281af668035SAkhil Goyal * - On success returns the size of the session structure for device
282af668035SAkhil Goyal * - On failure returns 0
283af668035SAkhil Goyal */
284af668035SAkhil Goyal typedef unsigned (*cryptodev_sym_get_session_private_size_t)(
285af668035SAkhil Goyal struct rte_cryptodev *dev);
286af668035SAkhil Goyal /**
287af668035SAkhil Goyal * Get the size of a asymmetric cryptodev session
288af668035SAkhil Goyal *
289af668035SAkhil Goyal * @param dev Crypto device pointer
290af668035SAkhil Goyal *
291af668035SAkhil Goyal * @return
292af668035SAkhil Goyal * - On success returns the size of the session structure for device
293af668035SAkhil Goyal * - On failure returns 0
294af668035SAkhil Goyal */
295af668035SAkhil Goyal typedef unsigned int (*cryptodev_asym_get_session_private_size_t)(
296af668035SAkhil Goyal struct rte_cryptodev *dev);
297af668035SAkhil Goyal
298af668035SAkhil Goyal /**
299af668035SAkhil Goyal * Configure a Crypto session on a device.
300af668035SAkhil Goyal *
301af668035SAkhil Goyal * @param dev Crypto device pointer
302af668035SAkhil Goyal * @param xform Single or chain of crypto xforms
303af668035SAkhil Goyal * @param session Pointer to cryptodev's private session structure
304af668035SAkhil Goyal * @param mp Mempool where the private session is allocated
305af668035SAkhil Goyal *
306af668035SAkhil Goyal * @return
307af668035SAkhil Goyal * - Returns 0 if private session structure have been created successfully.
308af668035SAkhil Goyal * - Returns -EINVAL if input parameters are invalid.
309af668035SAkhil Goyal * - Returns -ENOTSUP if crypto device does not support the crypto transform.
310af668035SAkhil Goyal * - Returns -ENOMEM if the private session could not be allocated.
311af668035SAkhil Goyal */
312af668035SAkhil Goyal typedef int (*cryptodev_sym_configure_session_t)(struct rte_cryptodev *dev,
313af668035SAkhil Goyal struct rte_crypto_sym_xform *xform,
314af668035SAkhil Goyal struct rte_cryptodev_sym_session *session,
315af668035SAkhil Goyal struct rte_mempool *mp);
316af668035SAkhil Goyal /**
317af668035SAkhil Goyal * Configure a Crypto asymmetric session on a device.
318af668035SAkhil Goyal *
319af668035SAkhil Goyal * @param dev Crypto device pointer
320af668035SAkhil Goyal * @param xform Single or chain of crypto xforms
321af668035SAkhil Goyal * @param session Pointer to cryptodev's private session structure
322af668035SAkhil Goyal *
323af668035SAkhil Goyal * @return
324af668035SAkhil Goyal * - Returns 0 if private session structure have been created successfully.
325af668035SAkhil Goyal * - Returns -EINVAL if input parameters are invalid.
326af668035SAkhil Goyal * - Returns -ENOTSUP if crypto device does not support the crypto transform.
327af668035SAkhil Goyal * - Returns -ENOMEM if the private session could not be allocated.
328af668035SAkhil Goyal */
329af668035SAkhil Goyal typedef int (*cryptodev_asym_configure_session_t)(struct rte_cryptodev *dev,
330af668035SAkhil Goyal struct rte_crypto_asym_xform *xform,
3311f1e4b7cSCiara Power struct rte_cryptodev_asym_session *session);
332af668035SAkhil Goyal /**
333af668035SAkhil Goyal * Free driver private session data.
334af668035SAkhil Goyal *
335af668035SAkhil Goyal * @param dev Crypto device pointer
336af668035SAkhil Goyal * @param sess Cryptodev session structure
337af668035SAkhil Goyal */
338af668035SAkhil Goyal typedef void (*cryptodev_sym_free_session_t)(struct rte_cryptodev *dev,
339af668035SAkhil Goyal struct rte_cryptodev_sym_session *sess);
340af668035SAkhil Goyal /**
3411f1e4b7cSCiara Power * Clear asymmetric session private data.
342af668035SAkhil Goyal *
343af668035SAkhil Goyal * @param dev Crypto device pointer
344af668035SAkhil Goyal * @param sess Cryptodev session structure
345af668035SAkhil Goyal */
3461f1e4b7cSCiara Power typedef void (*cryptodev_asym_clear_session_t)(struct rte_cryptodev *dev,
347af668035SAkhil Goyal struct rte_cryptodev_asym_session *sess);
348af668035SAkhil Goyal /**
349af668035SAkhil Goyal * Perform actual crypto processing (encrypt/digest or auth/decrypt)
350af668035SAkhil Goyal * on user provided data.
351af668035SAkhil Goyal *
352af668035SAkhil Goyal * @param dev Crypto device pointer
353af668035SAkhil Goyal * @param sess Cryptodev session structure
354af668035SAkhil Goyal * @param ofs Start and stop offsets for auth and cipher operations
355af668035SAkhil Goyal * @param vec Vectorized operation descriptor
356af668035SAkhil Goyal *
357af668035SAkhil Goyal * @return
358af668035SAkhil Goyal * - Returns number of successfully processed packets.
359af668035SAkhil Goyal *
360af668035SAkhil Goyal */
361af668035SAkhil Goyal typedef uint32_t (*cryptodev_sym_cpu_crypto_process_t)
362af668035SAkhil Goyal (struct rte_cryptodev *dev, struct rte_cryptodev_sym_session *sess,
363af668035SAkhil Goyal union rte_crypto_sym_ofs ofs, struct rte_crypto_sym_vec *vec);
364af668035SAkhil Goyal
365af668035SAkhil Goyal /**
366af668035SAkhil Goyal * Typedef that the driver provided to get service context private date size.
367af668035SAkhil Goyal *
368af668035SAkhil Goyal * @param dev Crypto device pointer.
369af668035SAkhil Goyal *
370af668035SAkhil Goyal * @return
371af668035SAkhil Goyal * - On success return the size of the device's service context private data.
372af668035SAkhil Goyal * - On failure return negative integer.
373af668035SAkhil Goyal */
374af668035SAkhil Goyal typedef int (*cryptodev_sym_get_raw_dp_ctx_size_t)(struct rte_cryptodev *dev);
375af668035SAkhil Goyal
376af668035SAkhil Goyal /**
377af668035SAkhil Goyal * Typedef that the driver provided to configure raw data-path context.
378af668035SAkhil Goyal *
379af668035SAkhil Goyal * @param dev Crypto device pointer.
380af668035SAkhil Goyal * @param qp_id Crypto device queue pair index.
381af668035SAkhil Goyal * @param ctx The raw data-path context data.
382af668035SAkhil Goyal * @param sess_type session type.
383af668035SAkhil Goyal * @param session_ctx Session context data. If NULL the driver
384af668035SAkhil Goyal * shall only configure the drv_ctx_data in
385af668035SAkhil Goyal * ctx buffer. Otherwise the driver shall only
386af668035SAkhil Goyal * parse the session_ctx to set appropriate
387af668035SAkhil Goyal * function pointers in ctx.
388af668035SAkhil Goyal * @param is_update Set 0 if it is to initialize the ctx.
389af668035SAkhil Goyal * Set 1 if ctx is initialized and only to update
390af668035SAkhil Goyal * session context data.
391af668035SAkhil Goyal * @return
392af668035SAkhil Goyal * - On success return 0.
393af668035SAkhil Goyal * - On failure return negative integer.
394af668035SAkhil Goyal */
395af668035SAkhil Goyal typedef int (*cryptodev_sym_configure_raw_dp_ctx_t)(
396af668035SAkhil Goyal struct rte_cryptodev *dev, uint16_t qp_id,
397af668035SAkhil Goyal struct rte_crypto_raw_dp_ctx *ctx,
398af668035SAkhil Goyal enum rte_crypto_op_sess_type sess_type,
399af668035SAkhil Goyal union rte_cryptodev_session_ctx session_ctx, uint8_t is_update);
400af668035SAkhil Goyal
401af668035SAkhil Goyal /** Crypto device operations function pointer table */
402af668035SAkhil Goyal struct rte_cryptodev_ops {
403af668035SAkhil Goyal cryptodev_configure_t dev_configure; /**< Configure device. */
404af668035SAkhil Goyal cryptodev_start_t dev_start; /**< Start device. */
405af668035SAkhil Goyal cryptodev_stop_t dev_stop; /**< Stop device. */
406af668035SAkhil Goyal cryptodev_close_t dev_close; /**< Close device. */
407af668035SAkhil Goyal
408af668035SAkhil Goyal cryptodev_info_get_t dev_infos_get; /**< Get device info. */
409af668035SAkhil Goyal
410af668035SAkhil Goyal cryptodev_stats_get_t stats_get;
411af668035SAkhil Goyal /**< Get device statistics. */
412af668035SAkhil Goyal cryptodev_stats_reset_t stats_reset;
413af668035SAkhil Goyal /**< Reset device statistics. */
414af668035SAkhil Goyal
415af668035SAkhil Goyal cryptodev_queue_pair_setup_t queue_pair_setup;
416af668035SAkhil Goyal /**< Set up a device queue pair. */
417af668035SAkhil Goyal cryptodev_queue_pair_release_t queue_pair_release;
418af668035SAkhil Goyal /**< Release a queue pair. */
419af668035SAkhil Goyal
420af668035SAkhil Goyal cryptodev_sym_get_session_private_size_t sym_session_get_size;
421af668035SAkhil Goyal /**< Return private session. */
422af668035SAkhil Goyal cryptodev_asym_get_session_private_size_t asym_session_get_size;
423af668035SAkhil Goyal /**< Return asym session private size. */
424af668035SAkhil Goyal cryptodev_sym_configure_session_t sym_session_configure;
425af668035SAkhil Goyal /**< Configure a Crypto session. */
426af668035SAkhil Goyal cryptodev_asym_configure_session_t asym_session_configure;
427af668035SAkhil Goyal /**< Configure asymmetric Crypto session. */
428af668035SAkhil Goyal cryptodev_sym_free_session_t sym_session_clear;
429af668035SAkhil Goyal /**< Clear a Crypto sessions private data. */
4301f1e4b7cSCiara Power cryptodev_asym_clear_session_t asym_session_clear;
431af668035SAkhil Goyal /**< Clear a Crypto sessions private data. */
432af668035SAkhil Goyal union {
433af668035SAkhil Goyal cryptodev_sym_cpu_crypto_process_t sym_cpu_process;
434af668035SAkhil Goyal /**< process input data synchronously (cpu-crypto). */
435af668035SAkhil Goyal __extension__
436af668035SAkhil Goyal struct {
437af668035SAkhil Goyal cryptodev_sym_get_raw_dp_ctx_size_t
438af668035SAkhil Goyal sym_get_raw_dp_ctx_size;
439af668035SAkhil Goyal /**< Get raw data path service context data size. */
440af668035SAkhil Goyal cryptodev_sym_configure_raw_dp_ctx_t
441af668035SAkhil Goyal sym_configure_raw_dp_ctx;
442af668035SAkhil Goyal /**< Initialize raw data path context data. */
443af668035SAkhil Goyal };
444af668035SAkhil Goyal };
445af668035SAkhil Goyal };
446af668035SAkhil Goyal
447af668035SAkhil Goyal
448af668035SAkhil Goyal /**
449af668035SAkhil Goyal * Function for internal use by dummy drivers primarily, e.g. ring-based
450af668035SAkhil Goyal * driver.
451af668035SAkhil Goyal * Allocates a new cryptodev slot for an crypto device and returns the pointer
452af668035SAkhil Goyal * to that slot for the driver to use.
453af668035SAkhil Goyal *
454af668035SAkhil Goyal * @param name Unique identifier name for each device
455af668035SAkhil Goyal * @param socket_id Socket to allocate resources on.
456af668035SAkhil Goyal * @return
457af668035SAkhil Goyal * - Slot in the rte_dev_devices array for a new device;
458af668035SAkhil Goyal */
459af668035SAkhil Goyal __rte_internal
460af668035SAkhil Goyal struct rte_cryptodev *
461af668035SAkhil Goyal rte_cryptodev_pmd_allocate(const char *name, int socket_id);
462af668035SAkhil Goyal
463af668035SAkhil Goyal /**
464af668035SAkhil Goyal * Function for internal use by dummy drivers primarily, e.g. ring-based
465af668035SAkhil Goyal * driver.
466af668035SAkhil Goyal * Release the specified cryptodev device.
467af668035SAkhil Goyal *
468af668035SAkhil Goyal * @param cryptodev
469af668035SAkhil Goyal * The *cryptodev* pointer is the address of the *rte_cryptodev* structure.
470af668035SAkhil Goyal * @return
471af668035SAkhil Goyal * - 0 on success, negative on error
472af668035SAkhil Goyal */
473af668035SAkhil Goyal __rte_internal
474af668035SAkhil Goyal extern int
475af668035SAkhil Goyal rte_cryptodev_pmd_release_device(struct rte_cryptodev *cryptodev);
476af668035SAkhil Goyal
477af668035SAkhil Goyal
478af668035SAkhil Goyal /**
479af668035SAkhil Goyal * @internal
480af668035SAkhil Goyal *
481af668035SAkhil Goyal * PMD assist function to parse initialisation arguments for crypto driver
482af668035SAkhil Goyal * when creating a new crypto PMD device instance.
483af668035SAkhil Goyal *
484f8dbaebbSSean Morrissey * PMD should set default values for that PMD before calling function,
485af668035SAkhil Goyal * these default values will be over-written with successfully parsed values
486af668035SAkhil Goyal * from args string.
487af668035SAkhil Goyal *
488af668035SAkhil Goyal * @param params parsed PMD initialisation parameters
489af668035SAkhil Goyal * @param args input argument string to parse
490af668035SAkhil Goyal *
491af668035SAkhil Goyal * @return
492af668035SAkhil Goyal * - 0 on success
493af668035SAkhil Goyal * - errno on failure
494af668035SAkhil Goyal */
495af668035SAkhil Goyal __rte_internal
496af668035SAkhil Goyal int
497af668035SAkhil Goyal rte_cryptodev_pmd_parse_input_args(
498af668035SAkhil Goyal struct rte_cryptodev_pmd_init_params *params,
499af668035SAkhil Goyal const char *args);
500af668035SAkhil Goyal
501af668035SAkhil Goyal /**
502af668035SAkhil Goyal * @internal
503af668035SAkhil Goyal *
504af668035SAkhil Goyal * PMD assist function to provide boiler plate code for crypto driver to create
505af668035SAkhil Goyal * and allocate resources for a new crypto PMD device instance.
506af668035SAkhil Goyal *
507af668035SAkhil Goyal * @param name crypto device name.
508af668035SAkhil Goyal * @param device base device instance
509af668035SAkhil Goyal * @param params PMD initialisation parameters
510af668035SAkhil Goyal *
511af668035SAkhil Goyal * @return
512af668035SAkhil Goyal * - crypto device instance on success
513af668035SAkhil Goyal * - NULL on creation failure
514af668035SAkhil Goyal */
515af668035SAkhil Goyal __rte_internal
516af668035SAkhil Goyal struct rte_cryptodev *
517af668035SAkhil Goyal rte_cryptodev_pmd_create(const char *name,
518af668035SAkhil Goyal struct rte_device *device,
519af668035SAkhil Goyal struct rte_cryptodev_pmd_init_params *params);
520af668035SAkhil Goyal
521af668035SAkhil Goyal /**
522af668035SAkhil Goyal * @internal
523af668035SAkhil Goyal *
524af668035SAkhil Goyal * PMD assist function to provide boiler plate code for crypto driver to
525af668035SAkhil Goyal * destroy and free resources associated with a crypto PMD device instance.
526af668035SAkhil Goyal *
527af668035SAkhil Goyal * @param cryptodev crypto device handle.
528af668035SAkhil Goyal *
529af668035SAkhil Goyal * @return
530af668035SAkhil Goyal * - 0 on success
531af668035SAkhil Goyal * - errno on failure
532af668035SAkhil Goyal */
533af668035SAkhil Goyal __rte_internal
534af668035SAkhil Goyal int
535af668035SAkhil Goyal rte_cryptodev_pmd_destroy(struct rte_cryptodev *cryptodev);
536af668035SAkhil Goyal
537af668035SAkhil Goyal /**
538af668035SAkhil Goyal * Executes all the user application registered callbacks for the specific
539af668035SAkhil Goyal * device.
540af668035SAkhil Goyal * *
541af668035SAkhil Goyal * @param dev Pointer to cryptodev struct
542af668035SAkhil Goyal * @param event Crypto device interrupt event type.
543af668035SAkhil Goyal *
544af668035SAkhil Goyal * @return
545af668035SAkhil Goyal * void
546af668035SAkhil Goyal */
547af668035SAkhil Goyal __rte_internal
548af668035SAkhil Goyal void rte_cryptodev_pmd_callback_process(struct rte_cryptodev *dev,
549af668035SAkhil Goyal enum rte_cryptodev_event_type event);
550af668035SAkhil Goyal
551af668035SAkhil Goyal /**
552af668035SAkhil Goyal * @internal
553af668035SAkhil Goyal * Create unique device name
554af668035SAkhil Goyal */
555af668035SAkhil Goyal __rte_internal
556af668035SAkhil Goyal int
557af668035SAkhil Goyal rte_cryptodev_pmd_create_dev_name(char *name, const char *dev_name_prefix);
558af668035SAkhil Goyal
559af668035SAkhil Goyal /**
560af668035SAkhil Goyal * @internal
561af668035SAkhil Goyal * Allocate Cryptodev driver.
562af668035SAkhil Goyal *
563af668035SAkhil Goyal * @param crypto_drv
564af668035SAkhil Goyal * Pointer to cryptodev_driver.
565af668035SAkhil Goyal * @param drv
566af668035SAkhil Goyal * Pointer to rte_driver.
567af668035SAkhil Goyal *
568af668035SAkhil Goyal * @return
569af668035SAkhil Goyal * The driver type identifier
570af668035SAkhil Goyal */
571af668035SAkhil Goyal __rte_internal
572af668035SAkhil Goyal uint8_t rte_cryptodev_allocate_driver(struct cryptodev_driver *crypto_drv,
573af668035SAkhil Goyal const struct rte_driver *drv);
574af668035SAkhil Goyal
57533cd3fd5SAkhil Goyal /**
57633cd3fd5SAkhil Goyal * @internal
57733cd3fd5SAkhil Goyal * This is the last step of device probing. It must be called after a
57833cd3fd5SAkhil Goyal * cryptodev is allocated and initialized successfully.
57933cd3fd5SAkhil Goyal *
58033cd3fd5SAkhil Goyal * @param dev Pointer to cryptodev struct
58133cd3fd5SAkhil Goyal *
58233cd3fd5SAkhil Goyal * @return
58333cd3fd5SAkhil Goyal * void
58433cd3fd5SAkhil Goyal */
58533cd3fd5SAkhil Goyal __rte_internal
58633cd3fd5SAkhil Goyal void
58733cd3fd5SAkhil Goyal rte_cryptodev_pmd_probing_finish(struct rte_cryptodev *dev);
588af668035SAkhil Goyal
589af668035SAkhil Goyal #define RTE_PMD_REGISTER_CRYPTO_DRIVER(crypto_drv, drv, driver_id)\
590af668035SAkhil Goyal RTE_INIT(init_ ##driver_id)\
591af668035SAkhil Goyal {\
592af668035SAkhil Goyal driver_id = rte_cryptodev_allocate_driver(&crypto_drv, &(drv));\
593af668035SAkhil Goyal }
594af668035SAkhil Goyal
5952fd66f75SAkhil Goyal /* Reset crypto device fastpath APIs to dummy values. */
5962fd66f75SAkhil Goyal __rte_internal
5972fd66f75SAkhil Goyal void
5982fd66f75SAkhil Goyal cryptodev_fp_ops_reset(struct rte_crypto_fp_ops *fp_ops);
5992fd66f75SAkhil Goyal
6002fd66f75SAkhil Goyal /* Setup crypto device fastpath APIs. */
6012fd66f75SAkhil Goyal __rte_internal
6022fd66f75SAkhil Goyal void
6032fd66f75SAkhil Goyal cryptodev_fp_ops_set(struct rte_crypto_fp_ops *fp_ops,
6042fd66f75SAkhil Goyal const struct rte_cryptodev *dev);
6052fd66f75SAkhil Goyal
606af668035SAkhil Goyal static inline void *
get_sym_session_private_data(const struct rte_cryptodev_sym_session * sess,uint8_t driver_id)607af668035SAkhil Goyal get_sym_session_private_data(const struct rte_cryptodev_sym_session *sess,
608af668035SAkhil Goyal uint8_t driver_id) {
609af668035SAkhil Goyal if (unlikely(sess->nb_drivers <= driver_id))
610af668035SAkhil Goyal return NULL;
611af668035SAkhil Goyal
612af668035SAkhil Goyal return sess->sess_data[driver_id].data;
613af668035SAkhil Goyal }
614af668035SAkhil Goyal
615af668035SAkhil Goyal static inline void
set_sym_session_private_data(struct rte_cryptodev_sym_session * sess,uint8_t driver_id,void * private_data)616af668035SAkhil Goyal set_sym_session_private_data(struct rte_cryptodev_sym_session *sess,
617af668035SAkhil Goyal uint8_t driver_id, void *private_data)
618af668035SAkhil Goyal {
619af668035SAkhil Goyal if (unlikely(sess->nb_drivers <= driver_id)) {
620af668035SAkhil Goyal CDEV_LOG_ERR("Set private data for driver %u not allowed\n",
621af668035SAkhil Goyal driver_id);
622af668035SAkhil Goyal return;
623af668035SAkhil Goyal }
624af668035SAkhil Goyal
625af668035SAkhil Goyal sess->sess_data[driver_id].data = private_data;
626af668035SAkhil Goyal }
627af668035SAkhil Goyal
628a29bb248SCiara Power /**
629a29bb248SCiara Power * @internal
630a29bb248SCiara Power * Cryptodev asymmetric crypto session.
631a29bb248SCiara Power */
632a29bb248SCiara Power RTE_STD_C11 struct rte_cryptodev_asym_session {
633a29bb248SCiara Power uint8_t driver_id;
634a29bb248SCiara Power /**< Session driver ID. */
635a29bb248SCiara Power uint16_t max_priv_data_sz;
636a29bb248SCiara Power /**< Size of private data used when creating mempool */
63792d55afeSCiara Power uint16_t user_data_sz;
63892d55afeSCiara Power /**< Session user data will be placed after sess_data */
63992d55afeSCiara Power uint8_t padding[3];
640a29bb248SCiara Power uint8_t sess_private_data[0];
641a29bb248SCiara Power };
642a29bb248SCiara Power
643*a43e3969SBrian Dooley #ifdef __cplusplus
644*a43e3969SBrian Dooley }
645*a43e3969SBrian Dooley #endif
646*a43e3969SBrian Dooley
647af668035SAkhil Goyal #endif /* _CRYPTODEV_PMD_H_ */
648