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