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