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