net/sfc: fix jumbo frame flag condition for MTU set
[dpdk.git] / lib / librte_cryptodev / rte_cryptodev.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2020 Intel Corporation.
3  */
4
5 #ifndef _RTE_CRYPTODEV_H_
6 #define _RTE_CRYPTODEV_H_
7
8 /**
9  * @file rte_cryptodev.h
10  *
11  * RTE Cryptographic Device APIs
12  *
13  * Defines RTE Crypto Device APIs for the provisioning of cipher and
14  * authentication operations.
15  */
16
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
21 #include "rte_kvargs.h"
22 #include "rte_crypto.h"
23 #include "rte_dev.h"
24 #include <rte_common.h>
25 #include <rte_config.h>
26 #include <rte_rcu_qsbr.h>
27
28 #include "rte_cryptodev_trace_fp.h"
29
30 extern const char **rte_cyptodev_names;
31
32 /* Logging Macros */
33
34 #define CDEV_LOG_ERR(...) \
35         RTE_LOG(ERR, CRYPTODEV, \
36                 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
37                         __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
38
39 #define CDEV_LOG_INFO(...) \
40         RTE_LOG(INFO, CRYPTODEV, \
41                 RTE_FMT(RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
42                         RTE_FMT_TAIL(__VA_ARGS__,)))
43
44 #define CDEV_LOG_DEBUG(...) \
45         RTE_LOG(DEBUG, CRYPTODEV, \
46                 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
47                         __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
48
49 #define CDEV_PMD_TRACE(...) \
50         RTE_LOG(DEBUG, CRYPTODEV, \
51                 RTE_FMT("[%s] %s: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
52                         dev, __func__, RTE_FMT_TAIL(__VA_ARGS__,)))
53
54 /**
55  * A macro that points to an offset from the start
56  * of the crypto operation structure (rte_crypto_op)
57  *
58  * The returned pointer is cast to type t.
59  *
60  * @param c
61  *   The crypto operation.
62  * @param o
63  *   The offset from the start of the crypto operation.
64  * @param t
65  *   The type to cast the result into.
66  */
67 #define rte_crypto_op_ctod_offset(c, t, o)      \
68         ((t)((char *)(c) + (o)))
69
70 /**
71  * A macro that returns the physical address that points
72  * to an offset from the start of the crypto operation
73  * (rte_crypto_op)
74  *
75  * @param c
76  *   The crypto operation.
77  * @param o
78  *   The offset from the start of the crypto operation
79  *   to calculate address from.
80  */
81 #define rte_crypto_op_ctophys_offset(c, o)      \
82         (rte_iova_t)((c)->phys_addr + (o))
83
84 /**
85  * Crypto parameters range description
86  */
87 struct rte_crypto_param_range {
88         uint16_t min;   /**< minimum size */
89         uint16_t max;   /**< maximum size */
90         uint16_t increment;
91         /**< if a range of sizes are supported,
92          * this parameter is used to indicate
93          * increments in byte size that are supported
94          * between the minimum and maximum
95          */
96 };
97
98 /**
99  * Symmetric Crypto Capability
100  */
101 struct rte_cryptodev_symmetric_capability {
102         enum rte_crypto_sym_xform_type xform_type;
103         /**< Transform type : Authentication / Cipher / AEAD */
104         RTE_STD_C11
105         union {
106                 struct {
107                         enum rte_crypto_auth_algorithm algo;
108                         /**< authentication algorithm */
109                         uint16_t block_size;
110                         /**< algorithm block size */
111                         struct rte_crypto_param_range key_size;
112                         /**< auth key size range */
113                         struct rte_crypto_param_range digest_size;
114                         /**< digest size range */
115                         struct rte_crypto_param_range aad_size;
116                         /**< Additional authentication data size range */
117                         struct rte_crypto_param_range iv_size;
118                         /**< Initialisation vector data size range */
119                 } auth;
120                 /**< Symmetric Authentication transform capabilities */
121                 struct {
122                         enum rte_crypto_cipher_algorithm algo;
123                         /**< cipher algorithm */
124                         uint16_t block_size;
125                         /**< algorithm block size */
126                         struct rte_crypto_param_range key_size;
127                         /**< cipher key size range */
128                         struct rte_crypto_param_range iv_size;
129                         /**< Initialisation vector data size range */
130                 } cipher;
131                 /**< Symmetric Cipher transform capabilities */
132                 struct {
133                         enum rte_crypto_aead_algorithm algo;
134                         /**< AEAD algorithm */
135                         uint16_t block_size;
136                         /**< algorithm block size */
137                         struct rte_crypto_param_range key_size;
138                         /**< AEAD key size range */
139                         struct rte_crypto_param_range digest_size;
140                         /**< digest size range */
141                         struct rte_crypto_param_range aad_size;
142                         /**< Additional authentication data size range */
143                         struct rte_crypto_param_range iv_size;
144                         /**< Initialisation vector data size range */
145                 } aead;
146         };
147 };
148
149 /**
150  * Asymmetric Xform Crypto Capability
151  *
152  */
153 struct rte_cryptodev_asymmetric_xform_capability {
154         enum rte_crypto_asym_xform_type xform_type;
155         /**< Transform type: RSA/MODEXP/DH/DSA/MODINV */
156
157         uint32_t op_types;
158         /**< bitmask for supported rte_crypto_asym_op_type */
159
160         __extension__
161         union {
162                 struct rte_crypto_param_range modlen;
163                 /**< Range of modulus length supported by modulus based xform.
164                  * Value 0 mean implementation default
165                  */
166         };
167 };
168
169 /**
170  * Asymmetric Crypto Capability
171  *
172  */
173 struct rte_cryptodev_asymmetric_capability {
174         struct rte_cryptodev_asymmetric_xform_capability xform_capa;
175 };
176
177
178 /** Structure used to capture a capability of a crypto device */
179 struct rte_cryptodev_capabilities {
180         enum rte_crypto_op_type op;
181         /**< Operation type */
182
183         RTE_STD_C11
184         union {
185                 struct rte_cryptodev_symmetric_capability sym;
186                 /**< Symmetric operation capability parameters */
187                 struct rte_cryptodev_asymmetric_capability asym;
188                 /**< Asymmetric operation capability parameters */
189         };
190 };
191
192 /** Structure used to describe crypto algorithms */
193 struct rte_cryptodev_sym_capability_idx {
194         enum rte_crypto_sym_xform_type type;
195         union {
196                 enum rte_crypto_cipher_algorithm cipher;
197                 enum rte_crypto_auth_algorithm auth;
198                 enum rte_crypto_aead_algorithm aead;
199         } algo;
200 };
201
202 /**
203  * Structure used to describe asymmetric crypto xforms
204  * Each xform maps to one asym algorithm.
205  *
206  */
207 struct rte_cryptodev_asym_capability_idx {
208         enum rte_crypto_asym_xform_type type;
209         /**< Asymmetric xform (algo) type */
210 };
211
212 /**
213  * Provide capabilities available for defined device and algorithm
214  *
215  * @param       dev_id          The identifier of the device.
216  * @param       idx             Description of crypto algorithms.
217  *
218  * @return
219  *   - Return description of the symmetric crypto capability if exist.
220  *   - Return NULL if the capability not exist.
221  */
222 const struct rte_cryptodev_symmetric_capability *
223 rte_cryptodev_sym_capability_get(uint8_t dev_id,
224                 const struct rte_cryptodev_sym_capability_idx *idx);
225
226 /**
227  *  Provide capabilities available for defined device and xform
228  *
229  * @param       dev_id          The identifier of the device.
230  * @param       idx             Description of asym crypto xform.
231  *
232  * @return
233  *   - Return description of the asymmetric crypto capability if exist.
234  *   - Return NULL if the capability not exist.
235  */
236 __rte_experimental
237 const struct rte_cryptodev_asymmetric_xform_capability *
238 rte_cryptodev_asym_capability_get(uint8_t dev_id,
239                 const struct rte_cryptodev_asym_capability_idx *idx);
240
241 /**
242  * Check if key size and initial vector are supported
243  * in crypto cipher capability
244  *
245  * @param       capability      Description of the symmetric crypto capability.
246  * @param       key_size        Cipher key size.
247  * @param       iv_size         Cipher initial vector size.
248  *
249  * @return
250  *   - Return 0 if the parameters are in range of the capability.
251  *   - Return -1 if the parameters are out of range of the capability.
252  */
253 int
254 rte_cryptodev_sym_capability_check_cipher(
255                 const struct rte_cryptodev_symmetric_capability *capability,
256                 uint16_t key_size, uint16_t iv_size);
257
258 /**
259  * Check if key size and initial vector are supported
260  * in crypto auth capability
261  *
262  * @param       capability      Description of the symmetric crypto capability.
263  * @param       key_size        Auth key size.
264  * @param       digest_size     Auth digest size.
265  * @param       iv_size         Auth initial vector size.
266  *
267  * @return
268  *   - Return 0 if the parameters are in range of the capability.
269  *   - Return -1 if the parameters are out of range of the capability.
270  */
271 int
272 rte_cryptodev_sym_capability_check_auth(
273                 const struct rte_cryptodev_symmetric_capability *capability,
274                 uint16_t key_size, uint16_t digest_size, uint16_t iv_size);
275
276 /**
277  * Check if key, digest, AAD and initial vector sizes are supported
278  * in crypto AEAD capability
279  *
280  * @param       capability      Description of the symmetric crypto capability.
281  * @param       key_size        AEAD key size.
282  * @param       digest_size     AEAD digest size.
283  * @param       aad_size        AEAD AAD size.
284  * @param       iv_size         AEAD IV size.
285  *
286  * @return
287  *   - Return 0 if the parameters are in range of the capability.
288  *   - Return -1 if the parameters are out of range of the capability.
289  */
290 int
291 rte_cryptodev_sym_capability_check_aead(
292                 const struct rte_cryptodev_symmetric_capability *capability,
293                 uint16_t key_size, uint16_t digest_size, uint16_t aad_size,
294                 uint16_t iv_size);
295
296 /**
297  * Check if op type is supported
298  *
299  * @param       capability      Description of the asymmetric crypto capability.
300  * @param       op_type         op type
301  *
302  * @return
303  *   - Return 1 if the op type is supported
304  *   - Return 0 if unsupported
305  */
306 __rte_experimental
307 int
308 rte_cryptodev_asym_xform_capability_check_optype(
309         const struct rte_cryptodev_asymmetric_xform_capability *capability,
310                 enum rte_crypto_asym_op_type op_type);
311
312 /**
313  * Check if modulus length is in supported range
314  *
315  * @param       capability      Description of the asymmetric crypto capability.
316  * @param       modlen          modulus length.
317  *
318  * @return
319  *   - Return 0 if the parameters are in range of the capability.
320  *   - Return -1 if the parameters are out of range of the capability.
321  */
322 __rte_experimental
323 int
324 rte_cryptodev_asym_xform_capability_check_modlen(
325         const struct rte_cryptodev_asymmetric_xform_capability *capability,
326                 uint16_t modlen);
327
328 /**
329  * Provide the cipher algorithm enum, given an algorithm string
330  *
331  * @param       algo_enum       A pointer to the cipher algorithm
332  *                              enum to be filled
333  * @param       algo_string     Authentication algo string
334  *
335  * @return
336  * - Return -1 if string is not valid
337  * - Return 0 is the string is valid
338  */
339 int
340 rte_cryptodev_get_cipher_algo_enum(enum rte_crypto_cipher_algorithm *algo_enum,
341                 const char *algo_string);
342
343 /**
344  * Provide the authentication algorithm enum, given an algorithm string
345  *
346  * @param       algo_enum       A pointer to the authentication algorithm
347  *                              enum to be filled
348  * @param       algo_string     Authentication algo string
349  *
350  * @return
351  * - Return -1 if string is not valid
352  * - Return 0 is the string is valid
353  */
354 int
355 rte_cryptodev_get_auth_algo_enum(enum rte_crypto_auth_algorithm *algo_enum,
356                 const char *algo_string);
357
358 /**
359  * Provide the AEAD algorithm enum, given an algorithm string
360  *
361  * @param       algo_enum       A pointer to the AEAD algorithm
362  *                              enum to be filled
363  * @param       algo_string     AEAD algorithm string
364  *
365  * @return
366  * - Return -1 if string is not valid
367  * - Return 0 is the string is valid
368  */
369 int
370 rte_cryptodev_get_aead_algo_enum(enum rte_crypto_aead_algorithm *algo_enum,
371                 const char *algo_string);
372
373 /**
374  * Provide the Asymmetric xform enum, given an xform string
375  *
376  * @param       xform_enum      A pointer to the xform type
377  *                              enum to be filled
378  * @param       xform_string    xform string
379  *
380  * @return
381  * - Return -1 if string is not valid
382  * - Return 0 if the string is valid
383  */
384 __rte_experimental
385 int
386 rte_cryptodev_asym_get_xform_enum(enum rte_crypto_asym_xform_type *xform_enum,
387                 const char *xform_string);
388
389
390 /** Macro used at end of crypto PMD list */
391 #define RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() \
392         { RTE_CRYPTO_OP_TYPE_UNDEFINED }
393
394
395 /**
396  * Crypto device supported feature flags
397  *
398  * Note:
399  * New features flags should be added to the end of the list
400  *
401  * Keep these flags synchronised with rte_cryptodev_get_feature_name()
402  */
403 #define RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO               (1ULL << 0)
404 /**< Symmetric crypto operations are supported */
405 #define RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO              (1ULL << 1)
406 /**< Asymmetric crypto operations are supported */
407 #define RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING         (1ULL << 2)
408 /**< Chaining symmetric crypto operations are supported */
409 #define RTE_CRYPTODEV_FF_CPU_SSE                        (1ULL << 3)
410 /**< Utilises CPU SIMD SSE instructions */
411 #define RTE_CRYPTODEV_FF_CPU_AVX                        (1ULL << 4)
412 /**< Utilises CPU SIMD AVX instructions */
413 #define RTE_CRYPTODEV_FF_CPU_AVX2                       (1ULL << 5)
414 /**< Utilises CPU SIMD AVX2 instructions */
415 #define RTE_CRYPTODEV_FF_CPU_AESNI                      (1ULL << 6)
416 /**< Utilises CPU AES-NI instructions */
417 #define RTE_CRYPTODEV_FF_HW_ACCELERATED                 (1ULL << 7)
418 /**< Operations are off-loaded to an
419  * external hardware accelerator
420  */
421 #define RTE_CRYPTODEV_FF_CPU_AVX512                     (1ULL << 8)
422 /**< Utilises CPU SIMD AVX512 instructions */
423 #define RTE_CRYPTODEV_FF_IN_PLACE_SGL                   (1ULL << 9)
424 /**< In-place Scatter-gather (SGL) buffers, with multiple segments,
425  * are supported
426  */
427 #define RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT             (1ULL << 10)
428 /**< Out-of-place Scatter-gather (SGL) buffers are
429  * supported in input and output
430  */
431 #define RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT              (1ULL << 11)
432 /**< Out-of-place Scatter-gather (SGL) buffers are supported
433  * in input, combined with linear buffers (LB), with a
434  * single segment in output
435  */
436 #define RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT              (1ULL << 12)
437 /**< Out-of-place Scatter-gather (SGL) buffers are supported
438  * in output, combined with linear buffers (LB) in input
439  */
440 #define RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT               (1ULL << 13)
441 /**< Out-of-place linear buffers (LB) are supported in input and output */
442 #define RTE_CRYPTODEV_FF_CPU_NEON                       (1ULL << 14)
443 /**< Utilises CPU NEON instructions */
444 #define RTE_CRYPTODEV_FF_CPU_ARM_CE                     (1ULL << 15)
445 /**< Utilises ARM CPU Cryptographic Extensions */
446 #define RTE_CRYPTODEV_FF_SECURITY                       (1ULL << 16)
447 /**< Support Security Protocol Processing */
448 #define RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP            (1ULL << 17)
449 /**< Support RSA Private Key OP with exponent */
450 #define RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT             (1ULL << 18)
451 /**< Support RSA Private Key OP with CRT (quintuple) Keys */
452 #define RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED               (1ULL << 19)
453 /**< Support encrypted-digest operations where digest is appended to data */
454 #define RTE_CRYPTODEV_FF_ASYM_SESSIONLESS               (1ULL << 20)
455 /**< Support asymmetric session-less operations */
456 #define RTE_CRYPTODEV_FF_SYM_CPU_CRYPTO                 (1ULL << 21)
457 /**< Support symmetric cpu-crypto processing */
458 #define RTE_CRYPTODEV_FF_SYM_SESSIONLESS                (1ULL << 22)
459 /**< Support symmetric session-less operations */
460 #define RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA          (1ULL << 23)
461 /**< Support operations on data which is not byte aligned */
462 #define RTE_CRYPTODEV_FF_SYM_RAW_DP                     (1ULL << 24)
463 /**< Support accelerator specific symmetric raw data-path APIs */
464
465 /**
466  * Get the name of a crypto device feature flag
467  *
468  * @param       flag    The mask describing the flag.
469  *
470  * @return
471  *   The name of this flag, or NULL if it's not a valid feature flag.
472  */
473
474 extern const char *
475 rte_cryptodev_get_feature_name(uint64_t flag);
476
477 /**  Crypto device information */
478 struct rte_cryptodev_info {
479         const char *driver_name;        /**< Driver name. */
480         uint8_t driver_id;              /**< Driver identifier */
481         struct rte_device *device;      /**< Generic device information. */
482
483         uint64_t feature_flags;
484         /**< Feature flags exposes HW/SW features for the given device */
485
486         const struct rte_cryptodev_capabilities *capabilities;
487         /**< Array of devices supported capabilities */
488
489         unsigned max_nb_queue_pairs;
490         /**< Maximum number of queues pairs supported by device. */
491
492         uint16_t min_mbuf_headroom_req;
493         /**< Minimum mbuf headroom required by device */
494
495         uint16_t min_mbuf_tailroom_req;
496         /**< Minimum mbuf tailroom required by device */
497
498         struct {
499                 unsigned max_nb_sessions;
500                 /**< Maximum number of sessions supported by device.
501                  * If 0, the device does not have any limitation in
502                  * number of sessions that can be used.
503                  */
504         } sym;
505 };
506
507 #define RTE_CRYPTODEV_DETACHED  (0)
508 #define RTE_CRYPTODEV_ATTACHED  (1)
509
510 /** Definitions of Crypto device event types */
511 enum rte_cryptodev_event_type {
512         RTE_CRYPTODEV_EVENT_UNKNOWN,    /**< unknown event type */
513         RTE_CRYPTODEV_EVENT_ERROR,      /**< error interrupt event */
514         RTE_CRYPTODEV_EVENT_MAX         /**< max value of this enum */
515 };
516
517 /** Crypto device queue pair configuration structure. */
518 struct rte_cryptodev_qp_conf {
519         uint32_t nb_descriptors; /**< Number of descriptors per queue pair */
520         struct rte_mempool *mp_session;
521         /**< The mempool for creating session in sessionless mode */
522         struct rte_mempool *mp_session_private;
523         /**< The mempool for creating sess private data in sessionless mode */
524 };
525
526 /**
527  * Function type used for processing crypto ops when enqueue/dequeue burst is
528  * called.
529  *
530  * The callback function is called on enqueue/dequeue burst immediately.
531  *
532  * @param       dev_id          The identifier of the device.
533  * @param       qp_id           The index of the queue pair on which ops are
534  *                              enqueued/dequeued. The value must be in the
535  *                              range [0, nb_queue_pairs - 1] previously
536  *                              supplied to *rte_cryptodev_configure*.
537  * @param       ops             The address of an array of *nb_ops* pointers
538  *                              to *rte_crypto_op* structures which contain
539  *                              the crypto operations to be processed.
540  * @param       nb_ops          The number of operations to process.
541  * @param       user_param      The arbitrary user parameter passed in by the
542  *                              application when the callback was originally
543  *                              registered.
544  * @return                      The number of ops to be enqueued to the
545  *                              crypto device.
546  */
547 typedef uint16_t (*rte_cryptodev_callback_fn)(uint16_t dev_id, uint16_t qp_id,
548                 struct rte_crypto_op **ops, uint16_t nb_ops, void *user_param);
549
550 /**
551  * Typedef for application callback function to be registered by application
552  * software for notification of device events
553  *
554  * @param       dev_id  Crypto device identifier
555  * @param       event   Crypto device event to register for notification of.
556  * @param       cb_arg  User specified parameter to be passed as to passed to
557  *                      users callback function.
558  */
559 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
560                 enum rte_cryptodev_event_type event, void *cb_arg);
561
562
563 /** Crypto Device statistics */
564 struct rte_cryptodev_stats {
565         uint64_t enqueued_count;
566         /**< Count of all operations enqueued */
567         uint64_t dequeued_count;
568         /**< Count of all operations dequeued */
569
570         uint64_t enqueue_err_count;
571         /**< Total error count on operations enqueued */
572         uint64_t dequeue_err_count;
573         /**< Total error count on operations dequeued */
574 };
575
576 #define RTE_CRYPTODEV_NAME_MAX_LEN      (64)
577 /**< Max length of name of crypto PMD */
578
579 /**
580  * Get the device identifier for the named crypto device.
581  *
582  * @param       name    device name to select the device structure.
583  *
584  * @return
585  *   - Returns crypto device identifier on success.
586  *   - Return -1 on failure to find named crypto device.
587  */
588 extern int
589 rte_cryptodev_get_dev_id(const char *name);
590
591 /**
592  * Get the crypto device name given a device identifier.
593  *
594  * @param dev_id
595  *   The identifier of the device
596  *
597  * @return
598  *   - Returns crypto device name.
599  *   - Returns NULL if crypto device is not present.
600  */
601 extern const char *
602 rte_cryptodev_name_get(uint8_t dev_id);
603
604 /**
605  * Get the total number of crypto devices that have been successfully
606  * initialised.
607  *
608  * @return
609  *   - The total number of usable crypto devices.
610  */
611 extern uint8_t
612 rte_cryptodev_count(void);
613
614 /**
615  * Get number of crypto device defined type.
616  *
617  * @param       driver_id       driver identifier.
618  *
619  * @return
620  *   Returns number of crypto device.
621  */
622 extern uint8_t
623 rte_cryptodev_device_count_by_driver(uint8_t driver_id);
624
625 /**
626  * Get number and identifiers of attached crypto devices that
627  * use the same crypto driver.
628  *
629  * @param       driver_name     driver name.
630  * @param       devices         output devices identifiers.
631  * @param       nb_devices      maximal number of devices.
632  *
633  * @return
634  *   Returns number of attached crypto device.
635  */
636 uint8_t
637 rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
638                 uint8_t nb_devices);
639 /*
640  * Return the NUMA socket to which a device is connected
641  *
642  * @param dev_id
643  *   The identifier of the device
644  * @return
645  *   The NUMA socket id to which the device is connected or
646  *   a default of zero if the socket could not be determined.
647  *   -1 if returned is the dev_id value is out of range.
648  */
649 extern int
650 rte_cryptodev_socket_id(uint8_t dev_id);
651
652 /** Crypto device configuration structure */
653 struct rte_cryptodev_config {
654         int socket_id;                  /**< Socket to allocate resources on */
655         uint16_t nb_queue_pairs;
656         /**< Number of queue pairs to configure on device */
657         uint64_t ff_disable;
658         /**< Feature flags to be disabled. Only the following features are
659          * allowed to be disabled,
660          *  - RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO
661          *  - RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO
662          *  - RTE_CRYTPODEV_FF_SECURITY
663          */
664 };
665
666 /**
667  * Configure a device.
668  *
669  * This function must be invoked first before any other function in the
670  * API. This function can also be re-invoked when a device is in the
671  * stopped state.
672  *
673  * @param       dev_id          The identifier of the device to configure.
674  * @param       config          The crypto device configuration structure.
675  *
676  * @return
677  *   - 0: Success, device configured.
678  *   - <0: Error code returned by the driver configuration function.
679  */
680 extern int
681 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
682
683 /**
684  * Start an device.
685  *
686  * The device start step is the last one and consists of setting the configured
687  * offload features and in starting the transmit and the receive units of the
688  * device.
689  * On success, all basic functions exported by the API (link status,
690  * receive/transmit, and so on) can be invoked.
691  *
692  * @param dev_id
693  *   The identifier of the device.
694  * @return
695  *   - 0: Success, device started.
696  *   - <0: Error code of the driver device start function.
697  */
698 extern int
699 rte_cryptodev_start(uint8_t dev_id);
700
701 /**
702  * Stop an device. The device can be restarted with a call to
703  * rte_cryptodev_start()
704  *
705  * @param       dev_id          The identifier of the device.
706  */
707 extern void
708 rte_cryptodev_stop(uint8_t dev_id);
709
710 /**
711  * Close an device. The device cannot be restarted!
712  *
713  * @param       dev_id          The identifier of the device.
714  *
715  * @return
716  *  - 0 on successfully closing device
717  *  - <0 on failure to close device
718  */
719 extern int
720 rte_cryptodev_close(uint8_t dev_id);
721
722 /**
723  * Allocate and set up a receive queue pair for a device.
724  *
725  *
726  * @param       dev_id          The identifier of the device.
727  * @param       queue_pair_id   The index of the queue pairs to set up. The
728  *                              value must be in the range [0, nb_queue_pair
729  *                              - 1] previously supplied to
730  *                              rte_cryptodev_configure().
731  * @param       qp_conf         The pointer to the configuration data to be
732  *                              used for the queue pair.
733  * @param       socket_id       The *socket_id* argument is the socket
734  *                              identifier in case of NUMA. The value can be
735  *                              *SOCKET_ID_ANY* if there is no NUMA constraint
736  *                              for the DMA memory allocated for the receive
737  *                              queue pair.
738  *
739  * @return
740  *   - 0: Success, queue pair correctly set up.
741  *   - <0: Queue pair configuration failed
742  */
743 extern int
744 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
745                 const struct rte_cryptodev_qp_conf *qp_conf, int socket_id);
746
747 /**
748  * Get the status of queue pairs setup on a specific crypto device
749  *
750  * @param       dev_id          Crypto device identifier.
751  * @param       queue_pair_id   The index of the queue pairs to set up. The
752  *                              value must be in the range [0, nb_queue_pair
753  *                              - 1] previously supplied to
754  *                              rte_cryptodev_configure().
755  * @return
756  *   - 0: qp was not configured
757  *       - 1: qp was configured
758  *       - -EINVAL: device was not configured
759  */
760 __rte_experimental
761 int
762 rte_cryptodev_get_qp_status(uint8_t dev_id, uint16_t queue_pair_id);
763
764 /**
765  * Get the number of queue pairs on a specific crypto device
766  *
767  * @param       dev_id          Crypto device identifier.
768  * @return
769  *   - The number of configured queue pairs.
770  */
771 extern uint16_t
772 rte_cryptodev_queue_pair_count(uint8_t dev_id);
773
774
775 /**
776  * Retrieve the general I/O statistics of a device.
777  *
778  * @param       dev_id          The identifier of the device.
779  * @param       stats           A pointer to a structure of type
780  *                              *rte_cryptodev_stats* to be filled with the
781  *                              values of device counters.
782  * @return
783  *   - Zero if successful.
784  *   - Non-zero otherwise.
785  */
786 extern int
787 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
788
789 /**
790  * Reset the general I/O statistics of a device.
791  *
792  * @param       dev_id          The identifier of the device.
793  */
794 extern void
795 rte_cryptodev_stats_reset(uint8_t dev_id);
796
797 /**
798  * Retrieve the contextual information of a device.
799  *
800  * @param       dev_id          The identifier of the device.
801  * @param       dev_info        A pointer to a structure of type
802  *                              *rte_cryptodev_info* to be filled with the
803  *                              contextual information of the device.
804  *
805  * @note The capabilities field of dev_info is set to point to the first
806  * element of an array of struct rte_cryptodev_capabilities. The element after
807  * the last valid element has it's op field set to
808  * RTE_CRYPTO_OP_TYPE_UNDEFINED.
809  */
810 extern void
811 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
812
813
814 /**
815  * Register a callback function for specific device id.
816  *
817  * @param       dev_id          Device id.
818  * @param       event           Event interested.
819  * @param       cb_fn           User supplied callback function to be called.
820  * @param       cb_arg          Pointer to the parameters for the registered
821  *                              callback.
822  *
823  * @return
824  *  - On success, zero.
825  *  - On failure, a negative value.
826  */
827 extern int
828 rte_cryptodev_callback_register(uint8_t dev_id,
829                 enum rte_cryptodev_event_type event,
830                 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
831
832 /**
833  * Unregister a callback function for specific device id.
834  *
835  * @param       dev_id          The device identifier.
836  * @param       event           Event interested.
837  * @param       cb_fn           User supplied callback function to be called.
838  * @param       cb_arg          Pointer to the parameters for the registered
839  *                              callback.
840  *
841  * @return
842  *  - On success, zero.
843  *  - On failure, a negative value.
844  */
845 extern int
846 rte_cryptodev_callback_unregister(uint8_t dev_id,
847                 enum rte_cryptodev_event_type event,
848                 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
849
850 typedef uint16_t (*dequeue_pkt_burst_t)(void *qp,
851                 struct rte_crypto_op **ops,     uint16_t nb_ops);
852 /**< Dequeue processed packets from queue pair of a device. */
853
854 typedef uint16_t (*enqueue_pkt_burst_t)(void *qp,
855                 struct rte_crypto_op **ops,     uint16_t nb_ops);
856 /**< Enqueue packets for processing on queue pair of a device. */
857
858
859
860
861 struct rte_cryptodev_callback;
862
863 /** Structure to keep track of registered callbacks */
864 TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
865
866 /**
867  * Structure used to hold information about the callbacks to be called for a
868  * queue pair on enqueue/dequeue.
869  */
870 struct rte_cryptodev_cb {
871         struct rte_cryptodev_cb *next;
872         /**< Pointer to next callback */
873         rte_cryptodev_callback_fn fn;
874         /**< Pointer to callback function */
875         void *arg;
876         /**< Pointer to argument */
877 };
878
879 /**
880  * @internal
881  * Structure used to hold information about the RCU for a queue pair.
882  */
883 struct rte_cryptodev_cb_rcu {
884         struct rte_cryptodev_cb *next;
885         /**< Pointer to next callback */
886         struct rte_rcu_qsbr *qsbr;
887         /**< RCU QSBR variable per queue pair */
888 };
889
890 /** The data structure associated with each crypto device. */
891 struct rte_cryptodev {
892         dequeue_pkt_burst_t dequeue_burst;
893         /**< Pointer to PMD receive function. */
894         enqueue_pkt_burst_t enqueue_burst;
895         /**< Pointer to PMD transmit function. */
896
897         struct rte_cryptodev_data *data;
898         /**< Pointer to device data */
899         struct rte_cryptodev_ops *dev_ops;
900         /**< Functions exported by PMD */
901         uint64_t feature_flags;
902         /**< Feature flags exposes HW/SW features for the given device */
903         struct rte_device *device;
904         /**< Backing device */
905
906         uint8_t driver_id;
907         /**< Crypto driver identifier*/
908
909         struct rte_cryptodev_cb_list link_intr_cbs;
910         /**< User application callback for interrupts if present */
911
912         void *security_ctx;
913         /**< Context for security ops */
914
915         __extension__
916         uint8_t attached : 1;
917         /**< Flag indicating the device is attached */
918
919         struct rte_cryptodev_cb_rcu *enq_cbs;
920         /**< User application callback for pre enqueue processing */
921
922         struct rte_cryptodev_cb_rcu *deq_cbs;
923         /**< User application callback for post dequeue processing */
924 } __rte_cache_aligned;
925
926 void *
927 rte_cryptodev_get_sec_ctx(uint8_t dev_id);
928
929 /**
930  *
931  * The data part, with no function pointers, associated with each device.
932  *
933  * This structure is safe to place in shared memory to be common among
934  * different processes in a multi-process configuration.
935  */
936 struct rte_cryptodev_data {
937         uint8_t dev_id;
938         /**< Device ID for this instance */
939         uint8_t socket_id;
940         /**< Socket ID where memory is allocated */
941         char name[RTE_CRYPTODEV_NAME_MAX_LEN];
942         /**< Unique identifier name */
943
944         __extension__
945         uint8_t dev_started : 1;
946         /**< Device state: STARTED(1)/STOPPED(0) */
947
948         struct rte_mempool *session_pool;
949         /**< Session memory pool */
950         void **queue_pairs;
951         /**< Array of pointers to queue pairs. */
952         uint16_t nb_queue_pairs;
953         /**< Number of device queue pairs. */
954
955         void *dev_private;
956         /**< PMD-specific private data */
957 } __rte_cache_aligned;
958
959 extern struct rte_cryptodev *rte_cryptodevs;
960 /**
961  *
962  * Dequeue a burst of processed crypto operations from a queue on the crypto
963  * device. The dequeued operation are stored in *rte_crypto_op* structures
964  * whose pointers are supplied in the *ops* array.
965  *
966  * The rte_cryptodev_dequeue_burst() function returns the number of ops
967  * actually dequeued, which is the number of *rte_crypto_op* data structures
968  * effectively supplied into the *ops* array.
969  *
970  * A return value equal to *nb_ops* indicates that the queue contained
971  * at least *nb_ops* operations, and this is likely to signify that other
972  * processed operations remain in the devices output queue. Applications
973  * implementing a "retrieve as many processed operations as possible" policy
974  * can check this specific case and keep invoking the
975  * rte_cryptodev_dequeue_burst() function until a value less than
976  * *nb_ops* is returned.
977  *
978  * The rte_cryptodev_dequeue_burst() function does not provide any error
979  * notification to avoid the corresponding overhead.
980  *
981  * @param       dev_id          The symmetric crypto device identifier
982  * @param       qp_id           The index of the queue pair from which to
983  *                              retrieve processed packets. The value must be
984  *                              in the range [0, nb_queue_pair - 1] previously
985  *                              supplied to rte_cryptodev_configure().
986  * @param       ops             The address of an array of pointers to
987  *                              *rte_crypto_op* structures that must be
988  *                              large enough to store *nb_ops* pointers in it.
989  * @param       nb_ops          The maximum number of operations to dequeue.
990  *
991  * @return
992  *   - The number of operations actually dequeued, which is the number
993  *   of pointers to *rte_crypto_op* structures effectively supplied to the
994  *   *ops* array.
995  */
996 static inline uint16_t
997 rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
998                 struct rte_crypto_op **ops, uint16_t nb_ops)
999 {
1000         struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
1001
1002         rte_cryptodev_trace_dequeue_burst(dev_id, qp_id, (void **)ops, nb_ops);
1003         nb_ops = (*dev->dequeue_burst)
1004                         (dev->data->queue_pairs[qp_id], ops, nb_ops);
1005 #ifdef RTE_CRYPTO_CALLBACKS
1006         if (unlikely(dev->deq_cbs != NULL)) {
1007                 struct rte_cryptodev_cb_rcu *list;
1008                 struct rte_cryptodev_cb *cb;
1009
1010                 /* __ATOMIC_RELEASE memory order was used when the
1011                  * call back was inserted into the list.
1012                  * Since there is a clear dependency between loading
1013                  * cb and cb->fn/cb->next, __ATOMIC_ACQUIRE memory order is
1014                  * not required.
1015                  */
1016                 list = &dev->deq_cbs[qp_id];
1017                 rte_rcu_qsbr_thread_online(list->qsbr, 0);
1018                 cb = __atomic_load_n(&list->next, __ATOMIC_RELAXED);
1019
1020                 while (cb != NULL) {
1021                         nb_ops = cb->fn(dev_id, qp_id, ops, nb_ops,
1022                                         cb->arg);
1023                         cb = cb->next;
1024                 };
1025
1026                 rte_rcu_qsbr_thread_offline(list->qsbr, 0);
1027         }
1028 #endif
1029         return nb_ops;
1030 }
1031
1032 /**
1033  * Enqueue a burst of operations for processing on a crypto device.
1034  *
1035  * The rte_cryptodev_enqueue_burst() function is invoked to place
1036  * crypto operations on the queue *qp_id* of the device designated by
1037  * its *dev_id*.
1038  *
1039  * The *nb_ops* parameter is the number of operations to process which are
1040  * supplied in the *ops* array of *rte_crypto_op* structures.
1041  *
1042  * The rte_cryptodev_enqueue_burst() function returns the number of
1043  * operations it actually enqueued for processing. A return value equal to
1044  * *nb_ops* means that all packets have been enqueued.
1045  *
1046  * @param       dev_id          The identifier of the device.
1047  * @param       qp_id           The index of the queue pair which packets are
1048  *                              to be enqueued for processing. The value
1049  *                              must be in the range [0, nb_queue_pairs - 1]
1050  *                              previously supplied to
1051  *                               *rte_cryptodev_configure*.
1052  * @param       ops             The address of an array of *nb_ops* pointers
1053  *                              to *rte_crypto_op* structures which contain
1054  *                              the crypto operations to be processed.
1055  * @param       nb_ops          The number of operations to process.
1056  *
1057  * @return
1058  * The number of operations actually enqueued on the crypto device. The return
1059  * value can be less than the value of the *nb_ops* parameter when the
1060  * crypto devices queue is full or if invalid parameters are specified in
1061  * a *rte_crypto_op*.
1062  */
1063 static inline uint16_t
1064 rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
1065                 struct rte_crypto_op **ops, uint16_t nb_ops)
1066 {
1067         struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
1068
1069 #ifdef RTE_CRYPTO_CALLBACKS
1070         if (unlikely(dev->enq_cbs != NULL)) {
1071                 struct rte_cryptodev_cb_rcu *list;
1072                 struct rte_cryptodev_cb *cb;
1073
1074                 /* __ATOMIC_RELEASE memory order was used when the
1075                  * call back was inserted into the list.
1076                  * Since there is a clear dependency between loading
1077                  * cb and cb->fn/cb->next, __ATOMIC_ACQUIRE memory order is
1078                  * not required.
1079                  */
1080                 list = &dev->enq_cbs[qp_id];
1081                 rte_rcu_qsbr_thread_online(list->qsbr, 0);
1082                 cb = __atomic_load_n(&list->next, __ATOMIC_RELAXED);
1083
1084                 while (cb != NULL) {
1085                         nb_ops = cb->fn(dev_id, qp_id, ops, nb_ops,
1086                                         cb->arg);
1087                         cb = cb->next;
1088                 };
1089
1090                 rte_rcu_qsbr_thread_offline(list->qsbr, 0);
1091         }
1092 #endif
1093
1094         rte_cryptodev_trace_enqueue_burst(dev_id, qp_id, (void **)ops, nb_ops);
1095         return (*dev->enqueue_burst)(
1096                         dev->data->queue_pairs[qp_id], ops, nb_ops);
1097 }
1098
1099
1100 /** Cryptodev symmetric crypto session
1101  * Each session is derived from a fixed xform chain. Therefore each session
1102  * has a fixed algo, key, op-type, digest_len etc.
1103  */
1104 struct rte_cryptodev_sym_session {
1105         uint64_t opaque_data;
1106         /**< Can be used for external metadata */
1107         uint16_t nb_drivers;
1108         /**< number of elements in sess_data array */
1109         uint16_t user_data_sz;
1110         /**< session user data will be placed after sess_data */
1111         __extension__ struct {
1112                 void *data;
1113                 uint16_t refcnt;
1114         } sess_data[0];
1115         /**< Driver specific session material, variable size */
1116 };
1117
1118 /** Cryptodev asymmetric crypto session */
1119 struct rte_cryptodev_asym_session {
1120         __extension__ void *sess_private_data[0];
1121         /**< Private asymmetric session material */
1122 };
1123
1124 /**
1125  * Create a symmetric session mempool.
1126  *
1127  * @param name
1128  *   The unique mempool name.
1129  * @param nb_elts
1130  *   The number of elements in the mempool.
1131  * @param elt_size
1132  *   The size of the element. This value will be ignored if it is smaller than
1133  *   the minimum session header size required for the system. For the user who
1134  *   want to use the same mempool for sym session and session private data it
1135  *   can be the maximum value of all existing devices' private data and session
1136  *   header sizes.
1137  * @param cache_size
1138  *   The number of per-lcore cache elements
1139  * @param priv_size
1140  *   The private data size of each session.
1141  * @param socket_id
1142  *   The *socket_id* argument is the socket identifier in the case of
1143  *   NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
1144  *   constraint for the reserved zone.
1145  *
1146  * @return
1147  *  - On success return size of the session
1148  *  - On failure returns 0
1149  */
1150 __rte_experimental
1151 struct rte_mempool *
1152 rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
1153         uint32_t elt_size, uint32_t cache_size, uint16_t priv_size,
1154         int socket_id);
1155
1156 /**
1157  * Create symmetric crypto session header (generic with no private data)
1158  *
1159  * @param   mempool    Symmetric session mempool to allocate session
1160  *                     objects from
1161  * @return
1162  *  - On success return pointer to sym-session
1163  *  - On failure returns NULL
1164  */
1165 struct rte_cryptodev_sym_session *
1166 rte_cryptodev_sym_session_create(struct rte_mempool *mempool);
1167
1168 /**
1169  * Create asymmetric crypto session header (generic with no private data)
1170  *
1171  * @param   mempool    mempool to allocate asymmetric session
1172  *                     objects from
1173  * @return
1174  *  - On success return pointer to asym-session
1175  *  - On failure returns NULL
1176  */
1177 __rte_experimental
1178 struct rte_cryptodev_asym_session *
1179 rte_cryptodev_asym_session_create(struct rte_mempool *mempool);
1180
1181 /**
1182  * Frees symmetric crypto session header, after checking that all
1183  * the device private data has been freed, returning it
1184  * to its original mempool.
1185  *
1186  * @param   sess     Session header to be freed.
1187  *
1188  * @return
1189  *  - 0 if successful.
1190  *  - -EINVAL if session is NULL.
1191  *  - -EBUSY if not all device private data has been freed.
1192  */
1193 int
1194 rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess);
1195
1196 /**
1197  * Frees asymmetric crypto session header, after checking that all
1198  * the device private data has been freed, returning it
1199  * to its original mempool.
1200  *
1201  * @param   sess     Session header to be freed.
1202  *
1203  * @return
1204  *  - 0 if successful.
1205  *  - -EINVAL if session is NULL.
1206  *  - -EBUSY if not all device private data has been freed.
1207  */
1208 __rte_experimental
1209 int
1210 rte_cryptodev_asym_session_free(struct rte_cryptodev_asym_session *sess);
1211
1212 /**
1213  * Fill out private data for the device id, based on its device type.
1214  *
1215  * @param   dev_id   ID of device that we want the session to be used on
1216  * @param   sess     Session where the private data will be attached to
1217  * @param   xforms   Symmetric crypto transform operations to apply on flow
1218  *                   processed with this session
1219  * @param   mempool  Mempool where the private data is allocated.
1220  *
1221  * @return
1222  *  - On success, zero.
1223  *  - -EINVAL if input parameters are invalid.
1224  *  - -ENOTSUP if crypto device does not support the crypto transform or
1225  *    does not support symmetric operations.
1226  *  - -ENOMEM if the private session could not be allocated.
1227  */
1228 int
1229 rte_cryptodev_sym_session_init(uint8_t dev_id,
1230                         struct rte_cryptodev_sym_session *sess,
1231                         struct rte_crypto_sym_xform *xforms,
1232                         struct rte_mempool *mempool);
1233
1234 /**
1235  * Initialize asymmetric session on a device with specific asymmetric xform
1236  *
1237  * @param   dev_id   ID of device that we want the session to be used on
1238  * @param   sess     Session to be set up on a device
1239  * @param   xforms   Asymmetric crypto transform operations to apply on flow
1240  *                   processed with this session
1241  * @param   mempool  Mempool to be used for internal allocation.
1242  *
1243  * @return
1244  *  - On success, zero.
1245  *  - -EINVAL if input parameters are invalid.
1246  *  - -ENOTSUP if crypto device does not support the crypto transform.
1247  *  - -ENOMEM if the private session could not be allocated.
1248  */
1249 __rte_experimental
1250 int
1251 rte_cryptodev_asym_session_init(uint8_t dev_id,
1252                         struct rte_cryptodev_asym_session *sess,
1253                         struct rte_crypto_asym_xform *xforms,
1254                         struct rte_mempool *mempool);
1255
1256 /**
1257  * Frees private data for the device id, based on its device type,
1258  * returning it to its mempool. It is the application's responsibility
1259  * to ensure that private session data is not cleared while there are
1260  * still in-flight operations using it.
1261  *
1262  * @param   dev_id   ID of device that uses the session.
1263  * @param   sess     Session containing the reference to the private data
1264  *
1265  * @return
1266  *  - 0 if successful.
1267  *  - -EINVAL if device is invalid or session is NULL.
1268  *  - -ENOTSUP if crypto device does not support symmetric operations.
1269  */
1270 int
1271 rte_cryptodev_sym_session_clear(uint8_t dev_id,
1272                         struct rte_cryptodev_sym_session *sess);
1273
1274 /**
1275  * Frees resources held by asymmetric session during rte_cryptodev_session_init
1276  *
1277  * @param   dev_id   ID of device that uses the asymmetric session.
1278  * @param   sess     Asymmetric session setup on device using
1279  *                                       rte_cryptodev_session_init
1280  * @return
1281  *  - 0 if successful.
1282  *  - -EINVAL if device is invalid or session is NULL.
1283  */
1284 __rte_experimental
1285 int
1286 rte_cryptodev_asym_session_clear(uint8_t dev_id,
1287                         struct rte_cryptodev_asym_session *sess);
1288
1289 /**
1290  * Get the size of the header session, for all registered drivers excluding
1291  * the user data size.
1292  *
1293  * @return
1294  *   Size of the symmetric header session.
1295  */
1296 unsigned int
1297 rte_cryptodev_sym_get_header_session_size(void);
1298
1299 /**
1300  * Get the size of the header session from created session.
1301  *
1302  * @param sess
1303  *   The sym cryptodev session pointer
1304  *
1305  * @return
1306  *   - If sess is not NULL, return the size of the header session including
1307  *   the private data size defined within sess.
1308  *   - If sess is NULL, return 0.
1309  */
1310 __rte_experimental
1311 unsigned int
1312 rte_cryptodev_sym_get_existing_header_session_size(
1313                 struct rte_cryptodev_sym_session *sess);
1314
1315 /**
1316  * Get the size of the asymmetric session header, for all registered drivers.
1317  *
1318  * @return
1319  *   Size of the asymmetric header session.
1320  */
1321 __rte_experimental
1322 unsigned int
1323 rte_cryptodev_asym_get_header_session_size(void);
1324
1325 /**
1326  * Get the size of the private symmetric session data
1327  * for a device.
1328  *
1329  * @param       dev_id          The device identifier.
1330  *
1331  * @return
1332  *   - Size of the private data, if successful
1333  *   - 0 if device is invalid or does not have private
1334  *   symmetric session
1335  */
1336 unsigned int
1337 rte_cryptodev_sym_get_private_session_size(uint8_t dev_id);
1338
1339 /**
1340  * Get the size of the private data for asymmetric session
1341  * on device
1342  *
1343  * @param       dev_id          The device identifier.
1344  *
1345  * @return
1346  *   - Size of the asymmetric private data, if successful
1347  *   - 0 if device is invalid or does not have private session
1348  */
1349 __rte_experimental
1350 unsigned int
1351 rte_cryptodev_asym_get_private_session_size(uint8_t dev_id);
1352
1353 /**
1354  * Provide driver identifier.
1355  *
1356  * @param name
1357  *   The pointer to a driver name.
1358  * @return
1359  *  The driver type identifier or -1 if no driver found
1360  */
1361 int rte_cryptodev_driver_id_get(const char *name);
1362
1363 /**
1364  * Provide driver name.
1365  *
1366  * @param driver_id
1367  *   The driver identifier.
1368  * @return
1369  *  The driver name or null if no driver found
1370  */
1371 const char *rte_cryptodev_driver_name_get(uint8_t driver_id);
1372
1373 /**
1374  * Store user data in a session.
1375  *
1376  * @param       sess            Session pointer allocated by
1377  *                              *rte_cryptodev_sym_session_create*.
1378  * @param       data            Pointer to the user data.
1379  * @param       size            Size of the user data.
1380  *
1381  * @return
1382  *  - On success, zero.
1383  *  - On failure, a negative value.
1384  */
1385 __rte_experimental
1386 int
1387 rte_cryptodev_sym_session_set_user_data(
1388                                         struct rte_cryptodev_sym_session *sess,
1389                                         void *data,
1390                                         uint16_t size);
1391
1392 /**
1393  * Get user data stored in a session.
1394  *
1395  * @param       sess            Session pointer allocated by
1396  *                              *rte_cryptodev_sym_session_create*.
1397  *
1398  * @return
1399  *  - On success return pointer to user data.
1400  *  - On failure returns NULL.
1401  */
1402 __rte_experimental
1403 void *
1404 rte_cryptodev_sym_session_get_user_data(
1405                                         struct rte_cryptodev_sym_session *sess);
1406
1407 /**
1408  * Perform actual crypto processing (encrypt/digest or auth/decrypt)
1409  * on user provided data.
1410  *
1411  * @param       dev_id  The device identifier.
1412  * @param       sess    Cryptodev session structure
1413  * @param       ofs     Start and stop offsets for auth and cipher operations
1414  * @param       vec     Vectorized operation descriptor
1415  *
1416  * @return
1417  *  - Returns number of successfully processed packets.
1418  */
1419 __rte_experimental
1420 uint32_t
1421 rte_cryptodev_sym_cpu_crypto_process(uint8_t dev_id,
1422         struct rte_cryptodev_sym_session *sess, union rte_crypto_sym_ofs ofs,
1423         struct rte_crypto_sym_vec *vec);
1424
1425 /**
1426  * Get the size of the raw data-path context buffer.
1427  *
1428  * @param       dev_id          The device identifier.
1429  *
1430  * @return
1431  *   - If the device supports raw data-path APIs, return the context size.
1432  *   - If the device does not support the APIs, return -1.
1433  */
1434 __rte_experimental
1435 int
1436 rte_cryptodev_get_raw_dp_ctx_size(uint8_t dev_id);
1437
1438 /**
1439  * Union of different crypto session types, including session-less xform
1440  * pointer.
1441  */
1442 union rte_cryptodev_session_ctx {
1443         struct rte_cryptodev_sym_session *crypto_sess;
1444         struct rte_crypto_sym_xform *xform;
1445         struct rte_security_session *sec_sess;
1446 };
1447
1448 /**
1449  * Enqueue a vectorized operation descriptor into the device queue but the
1450  * driver may or may not start processing until rte_cryptodev_raw_enqueue_done()
1451  * is called.
1452  *
1453  * @param       qp              Driver specific queue pair data.
1454  * @param       drv_ctx         Driver specific context data.
1455  * @param       vec             Vectorized operation descriptor.
1456  * @param       ofs             Start and stop offsets for auth and cipher
1457  *                              operations.
1458  * @param       user_data       The array of user data for dequeue later.
1459  * @param       enqueue_status  Driver written value to specify the
1460  *                              enqueue status. Possible values:
1461  *                              - 1: The number of operations returned are
1462  *                                   enqueued successfully.
1463  *                              - 0: The number of operations returned are
1464  *                                   cached into the queue but are not processed
1465  *                                   until rte_cryptodev_raw_enqueue_done() is
1466  *                                   called.
1467  *                              - negative integer: Error occurred.
1468  * @return
1469  *   - The number of operations in the descriptor successfully enqueued or
1470  *     cached into the queue but not enqueued yet, depends on the
1471  *     "enqueue_status" value.
1472  */
1473 typedef uint32_t (*cryptodev_sym_raw_enqueue_burst_t)(
1474         void *qp, uint8_t *drv_ctx, struct rte_crypto_sym_vec *vec,
1475         union rte_crypto_sym_ofs ofs, void *user_data[], int *enqueue_status);
1476
1477 /**
1478  * Enqueue single raw data vector into the device queue but the driver may or
1479  * may not start processing until rte_cryptodev_raw_enqueue_done() is called.
1480  *
1481  * @param       qp              Driver specific queue pair data.
1482  * @param       drv_ctx         Driver specific context data.
1483  * @param       data_vec        The buffer data vector.
1484  * @param       n_data_vecs     Number of buffer data vectors.
1485  * @param       ofs             Start and stop offsets for auth and cipher
1486  *                              operations.
1487  * @param       iv              IV virtual and IOVA addresses
1488  * @param       digest          digest virtual and IOVA addresses
1489  * @param       aad_or_auth_iv  AAD or auth IV virtual and IOVA addresses,
1490  *                              depends on the algorithm used.
1491  * @param       user_data       The user data.
1492  * @return
1493  *   - 1: The data vector is enqueued successfully.
1494  *   - 0: The data vector is cached into the queue but is not processed
1495  *        until rte_cryptodev_raw_enqueue_done() is called.
1496  *   - negative integer: failure.
1497  */
1498 typedef int (*cryptodev_sym_raw_enqueue_t)(
1499         void *qp, uint8_t *drv_ctx, struct rte_crypto_vec *data_vec,
1500         uint16_t n_data_vecs, union rte_crypto_sym_ofs ofs,
1501         struct rte_crypto_va_iova_ptr *iv,
1502         struct rte_crypto_va_iova_ptr *digest,
1503         struct rte_crypto_va_iova_ptr *aad_or_auth_iv,
1504         void *user_data);
1505
1506 /**
1507  * Inform the cryptodev queue pair to start processing or finish dequeuing all
1508  * enqueued/dequeued operations.
1509  *
1510  * @param       qp              Driver specific queue pair data.
1511  * @param       drv_ctx         Driver specific context data.
1512  * @param       n               The total number of processed operations.
1513  * @return
1514  *   - On success return 0.
1515  *   - On failure return negative integer.
1516  */
1517 typedef int (*cryptodev_sym_raw_operation_done_t)(void *qp, uint8_t *drv_ctx,
1518         uint32_t n);
1519
1520 /**
1521  * Typedef that the user provided for the driver to get the dequeue count.
1522  * The function may return a fixed number or the number parsed from the user
1523  * data stored in the first processed operation.
1524  *
1525  * @param       user_data       Dequeued user data.
1526  * @return
1527  *  - The number of operations to be dequeued.
1528  **/
1529 typedef uint32_t (*rte_cryptodev_raw_get_dequeue_count_t)(void *user_data);
1530
1531 /**
1532  * Typedef that the user provided to deal with post dequeue operation, such
1533  * as filling status.
1534  *
1535  * @param       user_data       Dequeued user data.
1536  * @param       index           Index number of the processed descriptor.
1537  * @param       is_op_success   Operation status provided by the driver.
1538  **/
1539 typedef void (*rte_cryptodev_raw_post_dequeue_t)(void *user_data,
1540         uint32_t index, uint8_t is_op_success);
1541
1542 /**
1543  * Dequeue a burst of symmetric crypto processing.
1544  *
1545  * @param       qp                      Driver specific queue pair data.
1546  * @param       drv_ctx                 Driver specific context data.
1547  * @param       get_dequeue_count       User provided callback function to
1548  *                                      obtain dequeue operation count.
1549  * @param       post_dequeue            User provided callback function to
1550  *                                      post-process a dequeued operation.
1551  * @param       out_user_data           User data pointer array to be retrieve
1552  *                                      from device queue. In case of
1553  *                                      *is_user_data_array* is set there
1554  *                                      should be enough room to store all
1555  *                                      user data.
1556  * @param       is_user_data_array      Set 1 if every dequeued user data will
1557  *                                      be written into out_user_data array.
1558  *                                      Set 0 if only the first user data will
1559  *                                      be written into out_user_data array.
1560  * @param       n_success               Driver written value to specific the
1561  *                                      total successful operations count.
1562  * @param       dequeue_status          Driver written value to specify the
1563  *                                      dequeue status. Possible values:
1564  *                                      - 1: Successfully dequeued the number
1565  *                                           of operations returned. The user
1566  *                                           data previously set during enqueue
1567  *                                           is stored in the "out_user_data".
1568  *                                      - 0: The number of operations returned
1569  *                                           are completed and the user data is
1570  *                                           stored in the "out_user_data", but
1571  *                                           they are not freed from the queue
1572  *                                           until
1573  *                                           rte_cryptodev_raw_dequeue_done()
1574  *                                           is called.
1575  *                                      - negative integer: Error occurred.
1576  * @return
1577  *   - The number of operations dequeued or completed but not freed from the
1578  *     queue, depends on "dequeue_status" value.
1579  */
1580 typedef uint32_t (*cryptodev_sym_raw_dequeue_burst_t)(void *qp,
1581         uint8_t *drv_ctx,
1582         rte_cryptodev_raw_get_dequeue_count_t get_dequeue_count,
1583         rte_cryptodev_raw_post_dequeue_t post_dequeue,
1584         void **out_user_data, uint8_t is_user_data_array,
1585         uint32_t *n_success, int *dequeue_status);
1586
1587 /**
1588  * Dequeue a symmetric crypto processing.
1589  *
1590  * @param       qp                      Driver specific queue pair data.
1591  * @param       drv_ctx                 Driver specific context data.
1592  * @param       dequeue_status          Driver written value to specify the
1593  *                                      dequeue status. Possible values:
1594  *                                      - 1: Successfully dequeued a operation.
1595  *                                           The user data is returned.
1596  *                                      - 0: The first operation in the queue
1597  *                                           is completed and the user data
1598  *                                           previously set during enqueue is
1599  *                                           returned, but it is not freed from
1600  *                                           the queue until
1601  *                                           rte_cryptodev_raw_dequeue_done() is
1602  *                                           called.
1603  *                                      - negative integer: Error occurred.
1604  * @param       op_status               Driver written value to specify
1605  *                                      operation status.
1606  * @return
1607  *   - The user data pointer retrieved from device queue or NULL if no
1608  *     operation is ready for dequeue.
1609  */
1610 typedef void * (*cryptodev_sym_raw_dequeue_t)(
1611                 void *qp, uint8_t *drv_ctx, int *dequeue_status,
1612                 enum rte_crypto_op_status *op_status);
1613
1614 /**
1615  * Context data for raw data-path API crypto process. The buffer of this
1616  * structure is to be allocated by the user application with the size equal
1617  * or bigger than rte_cryptodev_get_raw_dp_ctx_size() returned value.
1618  */
1619 struct rte_crypto_raw_dp_ctx {
1620         void *qp_data;
1621
1622         cryptodev_sym_raw_enqueue_t enqueue;
1623         cryptodev_sym_raw_enqueue_burst_t enqueue_burst;
1624         cryptodev_sym_raw_operation_done_t enqueue_done;
1625         cryptodev_sym_raw_dequeue_t dequeue;
1626         cryptodev_sym_raw_dequeue_burst_t dequeue_burst;
1627         cryptodev_sym_raw_operation_done_t dequeue_done;
1628
1629         /* Driver specific context data */
1630         __extension__ uint8_t drv_ctx_data[];
1631 };
1632
1633 /**
1634  * Configure raw data-path context data.
1635  *
1636  * NOTE:
1637  * After the context data is configured, the user should call
1638  * rte_cryptodev_raw_attach_session() before using it in
1639  * rte_cryptodev_raw_enqueue/dequeue function call.
1640  *
1641  * @param       dev_id          The device identifier.
1642  * @param       qp_id           The index of the queue pair from which to
1643  *                              retrieve processed packets. The value must be
1644  *                              in the range [0, nb_queue_pair - 1] previously
1645  *                              supplied to rte_cryptodev_configure().
1646  * @param       ctx             The raw data-path context data.
1647  * @param       sess_type       session type.
1648  * @param       session_ctx     Session context data.
1649  * @param       is_update       Set 0 if it is to initialize the ctx.
1650  *                              Set 1 if ctx is initialized and only to update
1651  *                              session context data.
1652  * @return
1653  *   - On success return 0.
1654  *   - On failure return negative integer.
1655  */
1656 __rte_experimental
1657 int
1658 rte_cryptodev_configure_raw_dp_ctx(uint8_t dev_id, uint16_t qp_id,
1659         struct rte_crypto_raw_dp_ctx *ctx,
1660         enum rte_crypto_op_sess_type sess_type,
1661         union rte_cryptodev_session_ctx session_ctx,
1662         uint8_t is_update);
1663
1664 /**
1665  * Enqueue a vectorized operation descriptor into the device queue but the
1666  * driver may or may not start processing until rte_cryptodev_raw_enqueue_done()
1667  * is called.
1668  *
1669  * @param       ctx             The initialized raw data-path context data.
1670  * @param       vec             Vectorized operation descriptor.
1671  * @param       ofs             Start and stop offsets for auth and cipher
1672  *                              operations.
1673  * @param       user_data       The array of user data for dequeue later.
1674  * @param       enqueue_status  Driver written value to specify the
1675  *                              enqueue status. Possible values:
1676  *                              - 1: The number of operations returned are
1677  *                                   enqueued successfully.
1678  *                              - 0: The number of operations returned are
1679  *                                   cached into the queue but are not processed
1680  *                                   until rte_cryptodev_raw_enqueue_done() is
1681  *                                   called.
1682  *                              - negative integer: Error occurred.
1683  * @return
1684  *   - The number of operations in the descriptor successfully enqueued or
1685  *     cached into the queue but not enqueued yet, depends on the
1686  *     "enqueue_status" value.
1687  */
1688 __rte_experimental
1689 uint32_t
1690 rte_cryptodev_raw_enqueue_burst(struct rte_crypto_raw_dp_ctx *ctx,
1691         struct rte_crypto_sym_vec *vec, union rte_crypto_sym_ofs ofs,
1692         void **user_data, int *enqueue_status);
1693
1694 /**
1695  * Enqueue single raw data vector into the device queue but the driver may or
1696  * may not start processing until rte_cryptodev_raw_enqueue_done() is called.
1697  *
1698  * @param       ctx             The initialized raw data-path context data.
1699  * @param       data_vec        The buffer data vector.
1700  * @param       n_data_vecs     Number of buffer data vectors.
1701  * @param       ofs             Start and stop offsets for auth and cipher
1702  *                              operations.
1703  * @param       iv              IV virtual and IOVA addresses
1704  * @param       digest          digest virtual and IOVA addresses
1705  * @param       aad_or_auth_iv  AAD or auth IV virtual and IOVA addresses,
1706  *                              depends on the algorithm used.
1707  * @param       user_data       The user data.
1708  * @return
1709  *   - 1: The data vector is enqueued successfully.
1710  *   - 0: The data vector is cached into the queue but is not processed
1711  *        until rte_cryptodev_raw_enqueue_done() is called.
1712  *   - negative integer: failure.
1713  */
1714 __rte_experimental
1715 static __rte_always_inline int
1716 rte_cryptodev_raw_enqueue(struct rte_crypto_raw_dp_ctx *ctx,
1717         struct rte_crypto_vec *data_vec, uint16_t n_data_vecs,
1718         union rte_crypto_sym_ofs ofs,
1719         struct rte_crypto_va_iova_ptr *iv,
1720         struct rte_crypto_va_iova_ptr *digest,
1721         struct rte_crypto_va_iova_ptr *aad_or_auth_iv,
1722         void *user_data)
1723 {
1724         return (*ctx->enqueue)(ctx->qp_data, ctx->drv_ctx_data, data_vec,
1725                 n_data_vecs, ofs, iv, digest, aad_or_auth_iv, user_data);
1726 }
1727
1728 /**
1729  * Start processing all enqueued operations from last
1730  * rte_cryptodev_configure_raw_dp_ctx() call.
1731  *
1732  * @param       ctx     The initialized raw data-path context data.
1733  * @param       n       The number of operations cached.
1734  * @return
1735  *   - On success return 0.
1736  *   - On failure return negative integer.
1737  */
1738 __rte_experimental
1739 int
1740 rte_cryptodev_raw_enqueue_done(struct rte_crypto_raw_dp_ctx *ctx,
1741                 uint32_t n);
1742
1743 /**
1744  * Dequeue a burst of symmetric crypto processing.
1745  *
1746  * @param       ctx                     The initialized raw data-path context
1747  *                                      data.
1748  * @param       get_dequeue_count       User provided callback function to
1749  *                                      obtain dequeue operation count.
1750  * @param       post_dequeue            User provided callback function to
1751  *                                      post-process a dequeued operation.
1752  * @param       out_user_data           User data pointer array to be retrieve
1753  *                                      from device queue. In case of
1754  *                                      *is_user_data_array* is set there
1755  *                                      should be enough room to store all
1756  *                                      user data.
1757  * @param       is_user_data_array      Set 1 if every dequeued user data will
1758  *                                      be written into out_user_data array.
1759  *                                      Set 0 if only the first user data will
1760  *                                      be written into out_user_data array.
1761  * @param       n_success               Driver written value to specific the
1762  *                                      total successful operations count.
1763  * @param       dequeue_status          Driver written value to specify the
1764  *                                      dequeue status. Possible values:
1765  *                                      - 1: Successfully dequeued the number
1766  *                                           of operations returned. The user
1767  *                                           data previously set during enqueue
1768  *                                           is stored in the "out_user_data".
1769  *                                      - 0: The number of operations returned
1770  *                                           are completed and the user data is
1771  *                                           stored in the "out_user_data", but
1772  *                                           they are not freed from the queue
1773  *                                           until
1774  *                                           rte_cryptodev_raw_dequeue_done()
1775  *                                           is called.
1776  *                                      - negative integer: Error occurred.
1777  * @return
1778  *   - The number of operations dequeued or completed but not freed from the
1779  *     queue, depends on "dequeue_status" value.
1780  */
1781 __rte_experimental
1782 uint32_t
1783 rte_cryptodev_raw_dequeue_burst(struct rte_crypto_raw_dp_ctx *ctx,
1784         rte_cryptodev_raw_get_dequeue_count_t get_dequeue_count,
1785         rte_cryptodev_raw_post_dequeue_t post_dequeue,
1786         void **out_user_data, uint8_t is_user_data_array,
1787         uint32_t *n_success, int *dequeue_status);
1788
1789 /**
1790  * Dequeue a symmetric crypto processing.
1791  *
1792  * @param       ctx                     The initialized raw data-path context
1793  *                                      data.
1794  * @param       dequeue_status          Driver written value to specify the
1795  *                                      dequeue status. Possible values:
1796  *                                      - 1: Successfully dequeued a operation.
1797  *                                           The user data is returned.
1798  *                                      - 0: The first operation in the queue
1799  *                                           is completed and the user data
1800  *                                           previously set during enqueue is
1801  *                                           returned, but it is not freed from
1802  *                                           the queue until
1803  *                                           rte_cryptodev_raw_dequeue_done() is
1804  *                                           called.
1805  *                                      - negative integer: Error occurred.
1806  * @param       op_status               Driver written value to specify
1807  *                                      operation status.
1808  * @return
1809  *   - The user data pointer retrieved from device queue or NULL if no
1810  *     operation is ready for dequeue.
1811  */
1812 __rte_experimental
1813 static __rte_always_inline void *
1814 rte_cryptodev_raw_dequeue(struct rte_crypto_raw_dp_ctx *ctx,
1815                 int *dequeue_status, enum rte_crypto_op_status *op_status)
1816 {
1817         return (*ctx->dequeue)(ctx->qp_data, ctx->drv_ctx_data, dequeue_status,
1818                         op_status);
1819 }
1820
1821 /**
1822  * Inform the queue pair dequeue operations is finished.
1823  *
1824  * @param       ctx     The initialized raw data-path context data.
1825  * @param       n       The number of operations.
1826  * @return
1827  *   - On success return 0.
1828  *   - On failure return negative integer.
1829  */
1830 __rte_experimental
1831 int
1832 rte_cryptodev_raw_dequeue_done(struct rte_crypto_raw_dp_ctx *ctx,
1833                 uint32_t n);
1834
1835 /**
1836  * Add a user callback for a given crypto device and queue pair which will be
1837  * called on crypto ops enqueue.
1838  *
1839  * This API configures a function to be called for each burst of crypto ops
1840  * received on a given crypto device queue pair. The return value is a pointer
1841  * that can be used later to remove the callback using
1842  * rte_cryptodev_remove_enq_callback().
1843  *
1844  * Callbacks registered by application would not survive
1845  * rte_cryptodev_configure() as it reinitializes the callback list.
1846  * It is user responsibility to remove all installed callbacks before
1847  * calling rte_cryptodev_configure() to avoid possible memory leakage.
1848  * Application is expected to call add API after rte_cryptodev_configure().
1849  *
1850  * Multiple functions can be registered per queue pair & they are called
1851  * in the order they were added. The API does not restrict on maximum number
1852  * of callbacks.
1853  *
1854  * @param       dev_id          The identifier of the device.
1855  * @param       qp_id           The index of the queue pair on which ops are
1856  *                              to be enqueued for processing. The value
1857  *                              must be in the range [0, nb_queue_pairs - 1]
1858  *                              previously supplied to
1859  *                              *rte_cryptodev_configure*.
1860  * @param       cb_fn           The callback function
1861  * @param       cb_arg          A generic pointer parameter which will be passed
1862  *                              to each invocation of the callback function on
1863  *                              this crypto device and queue pair.
1864  *
1865  * @return
1866  *  - NULL on error & rte_errno will contain the error code.
1867  *  - On success, a pointer value which can later be used to remove the
1868  *    callback.
1869  */
1870
1871 __rte_experimental
1872 struct rte_cryptodev_cb *
1873 rte_cryptodev_add_enq_callback(uint8_t dev_id,
1874                                uint16_t qp_id,
1875                                rte_cryptodev_callback_fn cb_fn,
1876                                void *cb_arg);
1877
1878 /**
1879  * Remove a user callback function for given crypto device and queue pair.
1880  *
1881  * This function is used to remove enqueue callbacks that were added to a
1882  * crypto device queue pair using rte_cryptodev_add_enq_callback().
1883  *
1884  *
1885  *
1886  * @param       dev_id          The identifier of the device.
1887  * @param       qp_id           The index of the queue pair on which ops are
1888  *                              to be enqueued. The value must be in the
1889  *                              range [0, nb_queue_pairs - 1] previously
1890  *                              supplied to *rte_cryptodev_configure*.
1891  * @param       cb              Pointer to user supplied callback created via
1892  *                              rte_cryptodev_add_enq_callback().
1893  *
1894  * @return
1895  *   -  0: Success. Callback was removed.
1896  *   - <0: The dev_id or the qp_id is out of range, or the callback
1897  *         is NULL or not found for the crypto device queue pair.
1898  */
1899
1900 __rte_experimental
1901 int rte_cryptodev_remove_enq_callback(uint8_t dev_id,
1902                                       uint16_t qp_id,
1903                                       struct rte_cryptodev_cb *cb);
1904
1905 /**
1906  * Add a user callback for a given crypto device and queue pair which will be
1907  * called on crypto ops dequeue.
1908  *
1909  * This API configures a function to be called for each burst of crypto ops
1910  * received on a given crypto device queue pair. The return value is a pointer
1911  * that can be used later to remove the callback using
1912  * rte_cryptodev_remove_deq_callback().
1913  *
1914  * Callbacks registered by application would not survive
1915  * rte_cryptodev_configure() as it reinitializes the callback list.
1916  * It is user responsibility to remove all installed callbacks before
1917  * calling rte_cryptodev_configure() to avoid possible memory leakage.
1918  * Application is expected to call add API after rte_cryptodev_configure().
1919  *
1920  * Multiple functions can be registered per queue pair & they are called
1921  * in the order they were added. The API does not restrict on maximum number
1922  * of callbacks.
1923  *
1924  * @param       dev_id          The identifier of the device.
1925  * @param       qp_id           The index of the queue pair on which ops are
1926  *                              to be dequeued. The value must be in the
1927  *                              range [0, nb_queue_pairs - 1] previously
1928  *                              supplied to *rte_cryptodev_configure*.
1929  * @param       cb_fn           The callback function
1930  * @param       cb_arg          A generic pointer parameter which will be passed
1931  *                              to each invocation of the callback function on
1932  *                              this crypto device and queue pair.
1933  *
1934  * @return
1935  *   - NULL on error & rte_errno will contain the error code.
1936  *   - On success, a pointer value which can later be used to remove the
1937  *     callback.
1938  */
1939
1940 __rte_experimental
1941 struct rte_cryptodev_cb *
1942 rte_cryptodev_add_deq_callback(uint8_t dev_id,
1943                                uint16_t qp_id,
1944                                rte_cryptodev_callback_fn cb_fn,
1945                                void *cb_arg);
1946
1947 /**
1948  * Remove a user callback function for given crypto device and queue pair.
1949  *
1950  * This function is used to remove dequeue callbacks that were added to a
1951  * crypto device queue pair using rte_cryptodev_add_deq_callback().
1952  *
1953  *
1954  *
1955  * @param       dev_id          The identifier of the device.
1956  * @param       qp_id           The index of the queue pair on which ops are
1957  *                              to be dequeued. The value must be in the
1958  *                              range [0, nb_queue_pairs - 1] previously
1959  *                              supplied to *rte_cryptodev_configure*.
1960  * @param       cb              Pointer to user supplied callback created via
1961  *                              rte_cryptodev_add_deq_callback().
1962  *
1963  * @return
1964  *   -  0: Success. Callback was removed.
1965  *   - <0: The dev_id or the qp_id is out of range, or the callback
1966  *         is NULL or not found for the crypto device queue pair.
1967  */
1968 __rte_experimental
1969 int rte_cryptodev_remove_deq_callback(uint8_t dev_id,
1970                                       uint16_t qp_id,
1971                                       struct rte_cryptodev_cb *cb);
1972
1973 #ifdef __cplusplus
1974 }
1975 #endif
1976
1977 #endif /* _RTE_CRYPTODEV_H_ */