1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2020 Intel Corporation
15 #include <rte_debug.h>
17 #include <rte_memory.h>
18 #include <rte_memcpy.h>
19 #include <rte_memzone.h>
21 #include <rte_common.h>
22 #include <rte_mempool.h>
23 #include <rte_malloc.h>
24 #include <rte_errno.h>
25 #include <rte_spinlock.h>
26 #include <rte_string_fns.h>
27 #include <rte_telemetry.h>
29 #include "rte_crypto.h"
30 #include "rte_cryptodev.h"
31 #include "cryptodev_pmd.h"
32 #include "rte_cryptodev_trace.h"
34 static uint8_t nb_drivers;
36 static struct rte_cryptodev rte_crypto_devices[RTE_CRYPTO_MAX_DEVS];
38 struct rte_cryptodev *rte_cryptodevs = rte_crypto_devices;
40 static struct rte_cryptodev_global cryptodev_globals = {
41 .devs = rte_crypto_devices,
46 /* Public fastpath APIs. */
47 struct rte_crypto_fp_ops rte_crypto_fp_ops[RTE_CRYPTO_MAX_DEVS];
49 /* spinlock for crypto device callbacks */
50 static rte_spinlock_t rte_cryptodev_cb_lock = RTE_SPINLOCK_INITIALIZER;
53 * The user application callback description.
55 * It contains callback address to be registered by user application,
56 * the pointer to the parameters for callback, and the event type.
58 struct rte_cryptodev_callback {
59 TAILQ_ENTRY(rte_cryptodev_callback) next; /**< Callbacks list */
60 rte_cryptodev_cb_fn cb_fn; /**< Callback address */
61 void *cb_arg; /**< Parameter for callback */
62 enum rte_cryptodev_event_type event; /**< Interrupt event type */
63 uint32_t active; /**< Callback is executing */
67 * The crypto cipher algorithm strings identifiers.
68 * It could be used in application command line.
71 rte_crypto_cipher_algorithm_strings[] = {
72 [RTE_CRYPTO_CIPHER_3DES_CBC] = "3des-cbc",
73 [RTE_CRYPTO_CIPHER_3DES_ECB] = "3des-ecb",
74 [RTE_CRYPTO_CIPHER_3DES_CTR] = "3des-ctr",
76 [RTE_CRYPTO_CIPHER_AES_CBC] = "aes-cbc",
77 [RTE_CRYPTO_CIPHER_AES_CTR] = "aes-ctr",
78 [RTE_CRYPTO_CIPHER_AES_DOCSISBPI] = "aes-docsisbpi",
79 [RTE_CRYPTO_CIPHER_AES_ECB] = "aes-ecb",
80 [RTE_CRYPTO_CIPHER_AES_F8] = "aes-f8",
81 [RTE_CRYPTO_CIPHER_AES_XTS] = "aes-xts",
83 [RTE_CRYPTO_CIPHER_ARC4] = "arc4",
85 [RTE_CRYPTO_CIPHER_DES_CBC] = "des-cbc",
86 [RTE_CRYPTO_CIPHER_DES_DOCSISBPI] = "des-docsisbpi",
88 [RTE_CRYPTO_CIPHER_NULL] = "null",
90 [RTE_CRYPTO_CIPHER_KASUMI_F8] = "kasumi-f8",
91 [RTE_CRYPTO_CIPHER_SNOW3G_UEA2] = "snow3g-uea2",
92 [RTE_CRYPTO_CIPHER_ZUC_EEA3] = "zuc-eea3"
96 * The crypto cipher operation strings identifiers.
97 * It could be used in application command line.
100 rte_crypto_cipher_operation_strings[] = {
101 [RTE_CRYPTO_CIPHER_OP_ENCRYPT] = "encrypt",
102 [RTE_CRYPTO_CIPHER_OP_DECRYPT] = "decrypt"
106 * The crypto auth algorithm strings identifiers.
107 * It could be used in application command line.
110 rte_crypto_auth_algorithm_strings[] = {
111 [RTE_CRYPTO_AUTH_AES_CBC_MAC] = "aes-cbc-mac",
112 [RTE_CRYPTO_AUTH_AES_CMAC] = "aes-cmac",
113 [RTE_CRYPTO_AUTH_AES_GMAC] = "aes-gmac",
114 [RTE_CRYPTO_AUTH_AES_XCBC_MAC] = "aes-xcbc-mac",
116 [RTE_CRYPTO_AUTH_MD5] = "md5",
117 [RTE_CRYPTO_AUTH_MD5_HMAC] = "md5-hmac",
119 [RTE_CRYPTO_AUTH_NULL] = "null",
121 [RTE_CRYPTO_AUTH_SHA1] = "sha1",
122 [RTE_CRYPTO_AUTH_SHA1_HMAC] = "sha1-hmac",
124 [RTE_CRYPTO_AUTH_SHA224] = "sha2-224",
125 [RTE_CRYPTO_AUTH_SHA224_HMAC] = "sha2-224-hmac",
126 [RTE_CRYPTO_AUTH_SHA256] = "sha2-256",
127 [RTE_CRYPTO_AUTH_SHA256_HMAC] = "sha2-256-hmac",
128 [RTE_CRYPTO_AUTH_SHA384] = "sha2-384",
129 [RTE_CRYPTO_AUTH_SHA384_HMAC] = "sha2-384-hmac",
130 [RTE_CRYPTO_AUTH_SHA512] = "sha2-512",
131 [RTE_CRYPTO_AUTH_SHA512_HMAC] = "sha2-512-hmac",
133 [RTE_CRYPTO_AUTH_KASUMI_F9] = "kasumi-f9",
134 [RTE_CRYPTO_AUTH_SNOW3G_UIA2] = "snow3g-uia2",
135 [RTE_CRYPTO_AUTH_ZUC_EIA3] = "zuc-eia3"
139 * The crypto AEAD algorithm strings identifiers.
140 * It could be used in application command line.
143 rte_crypto_aead_algorithm_strings[] = {
144 [RTE_CRYPTO_AEAD_AES_CCM] = "aes-ccm",
145 [RTE_CRYPTO_AEAD_AES_GCM] = "aes-gcm",
146 [RTE_CRYPTO_AEAD_CHACHA20_POLY1305] = "chacha20-poly1305"
150 * The crypto AEAD operation strings identifiers.
151 * It could be used in application command line.
154 rte_crypto_aead_operation_strings[] = {
155 [RTE_CRYPTO_AEAD_OP_ENCRYPT] = "encrypt",
156 [RTE_CRYPTO_AEAD_OP_DECRYPT] = "decrypt"
160 * Asymmetric crypto transform operation strings identifiers.
162 const char *rte_crypto_asym_xform_strings[] = {
163 [RTE_CRYPTO_ASYM_XFORM_NONE] = "none",
164 [RTE_CRYPTO_ASYM_XFORM_RSA] = "rsa",
165 [RTE_CRYPTO_ASYM_XFORM_MODEX] = "modexp",
166 [RTE_CRYPTO_ASYM_XFORM_MODINV] = "modinv",
167 [RTE_CRYPTO_ASYM_XFORM_DH] = "dh",
168 [RTE_CRYPTO_ASYM_XFORM_DSA] = "dsa",
169 [RTE_CRYPTO_ASYM_XFORM_ECDSA] = "ecdsa",
170 [RTE_CRYPTO_ASYM_XFORM_ECPM] = "ecpm",
174 * Asymmetric crypto operation strings identifiers.
176 const char *rte_crypto_asym_op_strings[] = {
177 [RTE_CRYPTO_ASYM_OP_ENCRYPT] = "encrypt",
178 [RTE_CRYPTO_ASYM_OP_DECRYPT] = "decrypt",
179 [RTE_CRYPTO_ASYM_OP_SIGN] = "sign",
180 [RTE_CRYPTO_ASYM_OP_VERIFY] = "verify",
181 [RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE] = "priv_key_generate",
182 [RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE] = "pub_key_generate",
183 [RTE_CRYPTO_ASYM_OP_SHARED_SECRET_COMPUTE] = "sharedsecret_compute",
187 * The private data structure stored in the sym session mempool private data.
189 struct rte_cryptodev_sym_session_pool_private_data {
191 /**< number of elements in sess_data array */
192 uint16_t user_data_sz;
193 /**< session user data will be placed after sess_data */
197 * The private data structure stored in the asym session mempool private data.
199 struct rte_cryptodev_asym_session_pool_private_data {
200 uint16_t max_priv_session_sz;
201 /**< Size of private session data used when creating mempool */
202 uint16_t user_data_sz;
203 /**< Session user data will be placed after sess_private_data */
207 rte_cryptodev_get_cipher_algo_enum(enum rte_crypto_cipher_algorithm *algo_enum,
208 const char *algo_string)
212 for (i = 1; i < RTE_DIM(rte_crypto_cipher_algorithm_strings); i++) {
213 if (strcmp(algo_string, rte_crypto_cipher_algorithm_strings[i]) == 0) {
214 *algo_enum = (enum rte_crypto_cipher_algorithm) i;
224 rte_cryptodev_get_auth_algo_enum(enum rte_crypto_auth_algorithm *algo_enum,
225 const char *algo_string)
229 for (i = 1; i < RTE_DIM(rte_crypto_auth_algorithm_strings); i++) {
230 if (strcmp(algo_string, rte_crypto_auth_algorithm_strings[i]) == 0) {
231 *algo_enum = (enum rte_crypto_auth_algorithm) i;
241 rte_cryptodev_get_aead_algo_enum(enum rte_crypto_aead_algorithm *algo_enum,
242 const char *algo_string)
246 for (i = 1; i < RTE_DIM(rte_crypto_aead_algorithm_strings); i++) {
247 if (strcmp(algo_string, rte_crypto_aead_algorithm_strings[i]) == 0) {
248 *algo_enum = (enum rte_crypto_aead_algorithm) i;
258 rte_cryptodev_asym_get_xform_enum(enum rte_crypto_asym_xform_type *xform_enum,
259 const char *xform_string)
263 for (i = 1; i < RTE_DIM(rte_crypto_asym_xform_strings); i++) {
264 if (strcmp(xform_string,
265 rte_crypto_asym_xform_strings[i]) == 0) {
266 *xform_enum = (enum rte_crypto_asym_xform_type) i;
276 * The crypto auth operation strings identifiers.
277 * It could be used in application command line.
280 rte_crypto_auth_operation_strings[] = {
281 [RTE_CRYPTO_AUTH_OP_VERIFY] = "verify",
282 [RTE_CRYPTO_AUTH_OP_GENERATE] = "generate"
285 const struct rte_cryptodev_symmetric_capability *
286 rte_cryptodev_sym_capability_get(uint8_t dev_id,
287 const struct rte_cryptodev_sym_capability_idx *idx)
289 const struct rte_cryptodev_capabilities *capability;
290 struct rte_cryptodev_info dev_info;
293 rte_cryptodev_info_get(dev_id, &dev_info);
295 while ((capability = &dev_info.capabilities[i++])->op !=
296 RTE_CRYPTO_OP_TYPE_UNDEFINED) {
297 if (capability->op != RTE_CRYPTO_OP_TYPE_SYMMETRIC)
300 if (capability->sym.xform_type != idx->type)
303 if (idx->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
304 capability->sym.auth.algo == idx->algo.auth)
305 return &capability->sym;
307 if (idx->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
308 capability->sym.cipher.algo == idx->algo.cipher)
309 return &capability->sym;
311 if (idx->type == RTE_CRYPTO_SYM_XFORM_AEAD &&
312 capability->sym.aead.algo == idx->algo.aead)
313 return &capability->sym;
320 param_range_check(uint16_t size, const struct rte_crypto_param_range *range)
322 unsigned int next_size;
324 /* Check lower/upper bounds */
325 if (size < range->min)
328 if (size > range->max)
331 /* If range is actually only one value, size is correct */
332 if (range->increment == 0)
335 /* Check if value is one of the supported sizes */
336 for (next_size = range->min; next_size <= range->max;
337 next_size += range->increment)
338 if (size == next_size)
344 const struct rte_cryptodev_asymmetric_xform_capability *
345 rte_cryptodev_asym_capability_get(uint8_t dev_id,
346 const struct rte_cryptodev_asym_capability_idx *idx)
348 const struct rte_cryptodev_capabilities *capability;
349 struct rte_cryptodev_info dev_info;
352 memset(&dev_info, 0, sizeof(struct rte_cryptodev_info));
353 rte_cryptodev_info_get(dev_id, &dev_info);
355 while ((capability = &dev_info.capabilities[i++])->op !=
356 RTE_CRYPTO_OP_TYPE_UNDEFINED) {
357 if (capability->op != RTE_CRYPTO_OP_TYPE_ASYMMETRIC)
360 if (capability->asym.xform_capa.xform_type == idx->type)
361 return &capability->asym.xform_capa;
367 rte_cryptodev_sym_capability_check_cipher(
368 const struct rte_cryptodev_symmetric_capability *capability,
369 uint16_t key_size, uint16_t iv_size)
371 if (param_range_check(key_size, &capability->cipher.key_size) != 0)
374 if (param_range_check(iv_size, &capability->cipher.iv_size) != 0)
381 rte_cryptodev_sym_capability_check_auth(
382 const struct rte_cryptodev_symmetric_capability *capability,
383 uint16_t key_size, uint16_t digest_size, uint16_t iv_size)
385 if (param_range_check(key_size, &capability->auth.key_size) != 0)
388 if (param_range_check(digest_size, &capability->auth.digest_size) != 0)
391 if (param_range_check(iv_size, &capability->auth.iv_size) != 0)
398 rte_cryptodev_sym_capability_check_aead(
399 const struct rte_cryptodev_symmetric_capability *capability,
400 uint16_t key_size, uint16_t digest_size, uint16_t aad_size,
403 if (param_range_check(key_size, &capability->aead.key_size) != 0)
406 if (param_range_check(digest_size, &capability->aead.digest_size) != 0)
409 if (param_range_check(aad_size, &capability->aead.aad_size) != 0)
412 if (param_range_check(iv_size, &capability->aead.iv_size) != 0)
418 rte_cryptodev_asym_xform_capability_check_optype(
419 const struct rte_cryptodev_asymmetric_xform_capability *capability,
420 enum rte_crypto_asym_op_type op_type)
422 if (capability->op_types & (1 << op_type))
429 rte_cryptodev_asym_xform_capability_check_modlen(
430 const struct rte_cryptodev_asymmetric_xform_capability *capability,
433 /* no need to check for limits, if min or max = 0 */
434 if (capability->modlen.min != 0) {
435 if (modlen < capability->modlen.min)
439 if (capability->modlen.max != 0) {
440 if (modlen > capability->modlen.max)
444 /* in any case, check if given modlen is module increment */
445 if (capability->modlen.increment != 0) {
446 if (modlen % (capability->modlen.increment))
453 /* spinlock for crypto device enq callbacks */
454 static rte_spinlock_t rte_cryptodev_callback_lock = RTE_SPINLOCK_INITIALIZER;
457 cryptodev_cb_cleanup(struct rte_cryptodev *dev)
459 struct rte_cryptodev_cb_rcu *list;
460 struct rte_cryptodev_cb *cb, *next;
463 if (dev->enq_cbs == NULL && dev->deq_cbs == NULL)
466 for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
467 list = &dev->enq_cbs[qp_id];
475 rte_free(list->qsbr);
478 for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
479 list = &dev->deq_cbs[qp_id];
487 rte_free(list->qsbr);
490 rte_free(dev->enq_cbs);
492 rte_free(dev->deq_cbs);
497 cryptodev_cb_init(struct rte_cryptodev *dev)
499 struct rte_cryptodev_cb_rcu *list;
500 struct rte_rcu_qsbr *qsbr;
504 /* Max thread set to 1, as one DP thread accessing a queue-pair */
505 const uint32_t max_threads = 1;
507 dev->enq_cbs = rte_zmalloc(NULL,
508 sizeof(struct rte_cryptodev_cb_rcu) *
509 dev->data->nb_queue_pairs, 0);
510 if (dev->enq_cbs == NULL) {
511 CDEV_LOG_ERR("Failed to allocate memory for enq callbacks");
515 dev->deq_cbs = rte_zmalloc(NULL,
516 sizeof(struct rte_cryptodev_cb_rcu) *
517 dev->data->nb_queue_pairs, 0);
518 if (dev->deq_cbs == NULL) {
519 CDEV_LOG_ERR("Failed to allocate memory for deq callbacks");
520 rte_free(dev->enq_cbs);
524 /* Create RCU QSBR variable */
525 size = rte_rcu_qsbr_get_memsize(max_threads);
527 for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
528 list = &dev->enq_cbs[qp_id];
529 qsbr = rte_zmalloc(NULL, size, RTE_CACHE_LINE_SIZE);
531 CDEV_LOG_ERR("Failed to allocate memory for RCU on "
532 "queue_pair_id=%d", qp_id);
536 if (rte_rcu_qsbr_init(qsbr, max_threads)) {
537 CDEV_LOG_ERR("Failed to initialize for RCU on "
538 "queue_pair_id=%d", qp_id);
545 for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
546 list = &dev->deq_cbs[qp_id];
547 qsbr = rte_zmalloc(NULL, size, RTE_CACHE_LINE_SIZE);
549 CDEV_LOG_ERR("Failed to allocate memory for RCU on "
550 "queue_pair_id=%d", qp_id);
554 if (rte_rcu_qsbr_init(qsbr, max_threads)) {
555 CDEV_LOG_ERR("Failed to initialize for RCU on "
556 "queue_pair_id=%d", qp_id);
566 cryptodev_cb_cleanup(dev);
571 rte_cryptodev_get_feature_name(uint64_t flag)
574 case RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO:
575 return "SYMMETRIC_CRYPTO";
576 case RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO:
577 return "ASYMMETRIC_CRYPTO";
578 case RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING:
579 return "SYM_OPERATION_CHAINING";
580 case RTE_CRYPTODEV_FF_CPU_SSE:
582 case RTE_CRYPTODEV_FF_CPU_AVX:
584 case RTE_CRYPTODEV_FF_CPU_AVX2:
586 case RTE_CRYPTODEV_FF_CPU_AVX512:
588 case RTE_CRYPTODEV_FF_CPU_AESNI:
590 case RTE_CRYPTODEV_FF_HW_ACCELERATED:
591 return "HW_ACCELERATED";
592 case RTE_CRYPTODEV_FF_IN_PLACE_SGL:
593 return "IN_PLACE_SGL";
594 case RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT:
595 return "OOP_SGL_IN_SGL_OUT";
596 case RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT:
597 return "OOP_SGL_IN_LB_OUT";
598 case RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT:
599 return "OOP_LB_IN_SGL_OUT";
600 case RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT:
601 return "OOP_LB_IN_LB_OUT";
602 case RTE_CRYPTODEV_FF_CPU_NEON:
604 case RTE_CRYPTODEV_FF_CPU_ARM_CE:
606 case RTE_CRYPTODEV_FF_SECURITY:
607 return "SECURITY_PROTOCOL";
608 case RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP:
609 return "RSA_PRIV_OP_KEY_EXP";
610 case RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT:
611 return "RSA_PRIV_OP_KEY_QT";
612 case RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED:
613 return "DIGEST_ENCRYPTED";
614 case RTE_CRYPTODEV_FF_SYM_CPU_CRYPTO:
615 return "SYM_CPU_CRYPTO";
616 case RTE_CRYPTODEV_FF_ASYM_SESSIONLESS:
617 return "ASYM_SESSIONLESS";
618 case RTE_CRYPTODEV_FF_SYM_SESSIONLESS:
619 return "SYM_SESSIONLESS";
620 case RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA:
621 return "NON_BYTE_ALIGNED_DATA";
622 case RTE_CRYPTODEV_FF_CIPHER_MULTIPLE_DATA_UNITS:
623 return "CIPHER_MULTIPLE_DATA_UNITS";
624 case RTE_CRYPTODEV_FF_CIPHER_WRAPPED_KEY:
625 return "CIPHER_WRAPPED_KEY";
631 struct rte_cryptodev *
632 rte_cryptodev_pmd_get_dev(uint8_t dev_id)
634 return &cryptodev_globals.devs[dev_id];
637 struct rte_cryptodev *
638 rte_cryptodev_pmd_get_named_dev(const char *name)
640 struct rte_cryptodev *dev;
646 for (i = 0; i < RTE_CRYPTO_MAX_DEVS; i++) {
647 dev = &cryptodev_globals.devs[i];
649 if ((dev->attached == RTE_CRYPTODEV_ATTACHED) &&
650 (strcmp(dev->data->name, name) == 0))
657 static inline uint8_t
658 rte_cryptodev_is_valid_device_data(uint8_t dev_id)
660 if (dev_id >= RTE_CRYPTO_MAX_DEVS ||
661 rte_crypto_devices[dev_id].data == NULL)
668 rte_cryptodev_is_valid_dev(uint8_t dev_id)
670 struct rte_cryptodev *dev = NULL;
672 if (!rte_cryptodev_is_valid_device_data(dev_id))
675 dev = rte_cryptodev_pmd_get_dev(dev_id);
676 if (dev->attached != RTE_CRYPTODEV_ATTACHED)
684 rte_cryptodev_get_dev_id(const char *name)
691 for (i = 0; i < RTE_CRYPTO_MAX_DEVS; i++) {
692 if (!rte_cryptodev_is_valid_device_data(i))
694 if ((strcmp(cryptodev_globals.devs[i].data->name, name)
696 (cryptodev_globals.devs[i].attached ==
697 RTE_CRYPTODEV_ATTACHED))
705 rte_cryptodev_count(void)
707 return cryptodev_globals.nb_devs;
711 rte_cryptodev_device_count_by_driver(uint8_t driver_id)
713 uint8_t i, dev_count = 0;
715 for (i = 0; i < RTE_CRYPTO_MAX_DEVS; i++)
716 if (cryptodev_globals.devs[i].driver_id == driver_id &&
717 cryptodev_globals.devs[i].attached ==
718 RTE_CRYPTODEV_ATTACHED)
725 rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
728 uint8_t i, count = 0;
729 struct rte_cryptodev *devs = cryptodev_globals.devs;
731 for (i = 0; i < RTE_CRYPTO_MAX_DEVS && count < nb_devices; i++) {
732 if (!rte_cryptodev_is_valid_device_data(i))
735 if (devs[i].attached == RTE_CRYPTODEV_ATTACHED) {
738 cmp = strncmp(devs[i].device->driver->name,
740 strlen(driver_name) + 1);
743 devices[count++] = devs[i].data->dev_id;
751 rte_cryptodev_get_sec_ctx(uint8_t dev_id)
753 if (dev_id < RTE_CRYPTO_MAX_DEVS &&
754 (rte_crypto_devices[dev_id].feature_flags &
755 RTE_CRYPTODEV_FF_SECURITY))
756 return rte_crypto_devices[dev_id].security_ctx;
762 rte_cryptodev_socket_id(uint8_t dev_id)
764 struct rte_cryptodev *dev;
766 if (!rte_cryptodev_is_valid_dev(dev_id))
769 dev = rte_cryptodev_pmd_get_dev(dev_id);
771 return dev->data->socket_id;
775 rte_cryptodev_data_alloc(uint8_t dev_id, struct rte_cryptodev_data **data,
778 char mz_name[RTE_MEMZONE_NAMESIZE];
779 const struct rte_memzone *mz;
782 /* generate memzone name */
783 n = snprintf(mz_name, sizeof(mz_name), "rte_cryptodev_data_%u", dev_id);
784 if (n >= (int)sizeof(mz_name))
787 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
788 mz = rte_memzone_reserve(mz_name,
789 sizeof(struct rte_cryptodev_data),
791 CDEV_LOG_DEBUG("PRIMARY:reserved memzone for %s (%p)",
794 mz = rte_memzone_lookup(mz_name);
795 CDEV_LOG_DEBUG("SECONDARY:looked up memzone for %s (%p)",
803 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
804 memset(*data, 0, sizeof(struct rte_cryptodev_data));
810 rte_cryptodev_data_free(uint8_t dev_id, struct rte_cryptodev_data **data)
812 char mz_name[RTE_MEMZONE_NAMESIZE];
813 const struct rte_memzone *mz;
816 /* generate memzone name */
817 n = snprintf(mz_name, sizeof(mz_name), "rte_cryptodev_data_%u", dev_id);
818 if (n >= (int)sizeof(mz_name))
821 mz = rte_memzone_lookup(mz_name);
825 RTE_ASSERT(*data == mz->addr);
828 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
829 CDEV_LOG_DEBUG("PRIMARY:free memzone of %s (%p)",
831 return rte_memzone_free(mz);
833 CDEV_LOG_DEBUG("SECONDARY:don't free memzone of %s (%p)",
841 rte_cryptodev_find_free_device_index(void)
845 for (dev_id = 0; dev_id < RTE_CRYPTO_MAX_DEVS; dev_id++) {
846 if (rte_crypto_devices[dev_id].attached ==
847 RTE_CRYPTODEV_DETACHED)
850 return RTE_CRYPTO_MAX_DEVS;
853 struct rte_cryptodev *
854 rte_cryptodev_pmd_allocate(const char *name, int socket_id)
856 struct rte_cryptodev *cryptodev;
859 if (rte_cryptodev_pmd_get_named_dev(name) != NULL) {
860 CDEV_LOG_ERR("Crypto device with name %s already "
865 dev_id = rte_cryptodev_find_free_device_index();
866 if (dev_id == RTE_CRYPTO_MAX_DEVS) {
867 CDEV_LOG_ERR("Reached maximum number of crypto devices");
871 cryptodev = rte_cryptodev_pmd_get_dev(dev_id);
873 if (cryptodev->data == NULL) {
874 struct rte_cryptodev_data **cryptodev_data =
875 &cryptodev_globals.data[dev_id];
877 int retval = rte_cryptodev_data_alloc(dev_id, cryptodev_data,
880 if (retval < 0 || *cryptodev_data == NULL)
883 cryptodev->data = *cryptodev_data;
885 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
886 strlcpy(cryptodev->data->name, name,
887 RTE_CRYPTODEV_NAME_MAX_LEN);
889 cryptodev->data->dev_id = dev_id;
890 cryptodev->data->socket_id = socket_id;
891 cryptodev->data->dev_started = 0;
892 CDEV_LOG_DEBUG("PRIMARY:init data");
895 CDEV_LOG_DEBUG("Data for %s: dev_id %d, socket %d, started %d",
896 cryptodev->data->name,
897 cryptodev->data->dev_id,
898 cryptodev->data->socket_id,
899 cryptodev->data->dev_started);
901 /* init user callbacks */
902 TAILQ_INIT(&(cryptodev->link_intr_cbs));
904 cryptodev->attached = RTE_CRYPTODEV_ATTACHED;
906 cryptodev_globals.nb_devs++;
913 rte_cryptodev_pmd_release_device(struct rte_cryptodev *cryptodev)
918 if (cryptodev == NULL)
921 dev_id = cryptodev->data->dev_id;
923 cryptodev_fp_ops_reset(rte_crypto_fp_ops + dev_id);
925 /* Close device only if device operations have been set */
926 if (cryptodev->dev_ops) {
927 ret = rte_cryptodev_close(dev_id);
932 ret = rte_cryptodev_data_free(dev_id, &cryptodev_globals.data[dev_id]);
936 cryptodev->attached = RTE_CRYPTODEV_DETACHED;
937 cryptodev_globals.nb_devs--;
942 rte_cryptodev_queue_pair_count(uint8_t dev_id)
944 struct rte_cryptodev *dev;
946 if (!rte_cryptodev_is_valid_device_data(dev_id)) {
947 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
951 dev = &rte_crypto_devices[dev_id];
952 return dev->data->nb_queue_pairs;
956 rte_cryptodev_queue_pairs_config(struct rte_cryptodev *dev, uint16_t nb_qpairs,
959 struct rte_cryptodev_info dev_info;
963 if ((dev == NULL) || (nb_qpairs < 1)) {
964 CDEV_LOG_ERR("invalid param: dev %p, nb_queues %u",
969 CDEV_LOG_DEBUG("Setup %d queues pairs on device %u",
970 nb_qpairs, dev->data->dev_id);
972 memset(&dev_info, 0, sizeof(struct rte_cryptodev_info));
974 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
975 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
977 if (nb_qpairs > (dev_info.max_nb_queue_pairs)) {
978 CDEV_LOG_ERR("Invalid num queue_pairs (%u) for dev %u",
979 nb_qpairs, dev->data->dev_id);
983 if (dev->data->queue_pairs == NULL) { /* first time configuration */
984 dev->data->queue_pairs = rte_zmalloc_socket(
985 "cryptodev->queue_pairs",
986 sizeof(dev->data->queue_pairs[0]) *
987 dev_info.max_nb_queue_pairs,
988 RTE_CACHE_LINE_SIZE, socket_id);
990 if (dev->data->queue_pairs == NULL) {
991 dev->data->nb_queue_pairs = 0;
992 CDEV_LOG_ERR("failed to get memory for qp meta data, "
997 } else { /* re-configure */
999 uint16_t old_nb_queues = dev->data->nb_queue_pairs;
1001 qp = dev->data->queue_pairs;
1003 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_pair_release,
1006 for (i = nb_qpairs; i < old_nb_queues; i++) {
1007 ret = (*dev->dev_ops->queue_pair_release)(dev, i);
1014 dev->data->nb_queue_pairs = nb_qpairs;
1019 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config)
1021 struct rte_cryptodev *dev;
1024 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1025 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
1029 dev = &rte_crypto_devices[dev_id];
1031 if (dev->data->dev_started) {
1033 "device %d must be stopped to allow configuration", dev_id);
1037 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
1039 rte_spinlock_lock(&rte_cryptodev_callback_lock);
1040 cryptodev_cb_cleanup(dev);
1041 rte_spinlock_unlock(&rte_cryptodev_callback_lock);
1043 /* Setup new number of queue pairs and reconfigure device. */
1044 diag = rte_cryptodev_queue_pairs_config(dev, config->nb_queue_pairs,
1047 CDEV_LOG_ERR("dev%d rte_crypto_dev_queue_pairs_config = %d",
1052 rte_spinlock_lock(&rte_cryptodev_callback_lock);
1053 diag = cryptodev_cb_init(dev);
1054 rte_spinlock_unlock(&rte_cryptodev_callback_lock);
1056 CDEV_LOG_ERR("Callback init failed for dev_id=%d", dev_id);
1060 rte_cryptodev_trace_configure(dev_id, config);
1061 return (*dev->dev_ops->dev_configure)(dev, config);
1065 rte_cryptodev_start(uint8_t dev_id)
1067 struct rte_cryptodev *dev;
1070 CDEV_LOG_DEBUG("Start dev_id=%" PRIu8, dev_id);
1072 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1073 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
1077 dev = &rte_crypto_devices[dev_id];
1079 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1081 if (dev->data->dev_started != 0) {
1082 CDEV_LOG_ERR("Device with dev_id=%" PRIu8 " already started",
1087 diag = (*dev->dev_ops->dev_start)(dev);
1088 /* expose selection of PMD fast-path functions */
1089 cryptodev_fp_ops_set(rte_crypto_fp_ops + dev_id, dev);
1091 rte_cryptodev_trace_start(dev_id, diag);
1093 dev->data->dev_started = 1;
1101 rte_cryptodev_stop(uint8_t dev_id)
1103 struct rte_cryptodev *dev;
1105 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1106 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
1110 dev = &rte_crypto_devices[dev_id];
1112 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1114 if (dev->data->dev_started == 0) {
1115 CDEV_LOG_ERR("Device with dev_id=%" PRIu8 " already stopped",
1120 /* point fast-path functions to dummy ones */
1121 cryptodev_fp_ops_reset(rte_crypto_fp_ops + dev_id);
1123 (*dev->dev_ops->dev_stop)(dev);
1124 rte_cryptodev_trace_stop(dev_id);
1125 dev->data->dev_started = 0;
1129 rte_cryptodev_close(uint8_t dev_id)
1131 struct rte_cryptodev *dev;
1134 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1135 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
1139 dev = &rte_crypto_devices[dev_id];
1141 /* Device must be stopped before it can be closed */
1142 if (dev->data->dev_started == 1) {
1143 CDEV_LOG_ERR("Device %u must be stopped before closing",
1148 /* We can't close the device if there are outstanding sessions in use */
1149 if (dev->data->session_pool != NULL) {
1150 if (!rte_mempool_full(dev->data->session_pool)) {
1151 CDEV_LOG_ERR("dev_id=%u close failed, session mempool "
1152 "has sessions still in use, free "
1153 "all sessions before calling close",
1159 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_close, -ENOTSUP);
1160 retval = (*dev->dev_ops->dev_close)(dev);
1161 rte_cryptodev_trace_close(dev_id, retval);
1170 rte_cryptodev_get_qp_status(uint8_t dev_id, uint16_t queue_pair_id)
1172 struct rte_cryptodev *dev;
1174 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1175 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
1179 dev = &rte_crypto_devices[dev_id];
1180 if (queue_pair_id >= dev->data->nb_queue_pairs) {
1181 CDEV_LOG_ERR("Invalid queue_pair_id=%d", queue_pair_id);
1184 void **qps = dev->data->queue_pairs;
1186 if (qps[queue_pair_id]) {
1187 CDEV_LOG_DEBUG("qp %d on dev %d is initialised",
1188 queue_pair_id, dev_id);
1192 CDEV_LOG_DEBUG("qp %d on dev %d is not initialised",
1193 queue_pair_id, dev_id);
1199 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
1200 const struct rte_cryptodev_qp_conf *qp_conf, int socket_id)
1203 struct rte_cryptodev *dev;
1205 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1206 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
1210 dev = &rte_crypto_devices[dev_id];
1211 if (queue_pair_id >= dev->data->nb_queue_pairs) {
1212 CDEV_LOG_ERR("Invalid queue_pair_id=%d", queue_pair_id);
1217 CDEV_LOG_ERR("qp_conf cannot be NULL\n");
1221 if ((qp_conf->mp_session && !qp_conf->mp_session_private) ||
1222 (!qp_conf->mp_session && qp_conf->mp_session_private)) {
1223 CDEV_LOG_ERR("Invalid mempools\n");
1227 if (qp_conf->mp_session) {
1228 struct rte_cryptodev_sym_session_pool_private_data *pool_priv;
1229 uint32_t obj_size = qp_conf->mp_session->elt_size;
1230 uint32_t obj_priv_size = qp_conf->mp_session_private->elt_size;
1231 struct rte_cryptodev_sym_session s = {0};
1233 pool_priv = rte_mempool_get_priv(qp_conf->mp_session);
1234 if (!pool_priv || qp_conf->mp_session->private_data_size <
1235 sizeof(*pool_priv)) {
1236 CDEV_LOG_ERR("Invalid mempool\n");
1240 s.nb_drivers = pool_priv->nb_drivers;
1241 s.user_data_sz = pool_priv->user_data_sz;
1243 if ((rte_cryptodev_sym_get_existing_header_session_size(&s) >
1244 obj_size) || (s.nb_drivers <= dev->driver_id) ||
1245 rte_cryptodev_sym_get_private_session_size(dev_id) >
1247 CDEV_LOG_ERR("Invalid mempool\n");
1252 if (dev->data->dev_started) {
1254 "device %d must be stopped to allow configuration", dev_id);
1258 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_pair_setup, -ENOTSUP);
1260 rte_cryptodev_trace_queue_pair_setup(dev_id, queue_pair_id, qp_conf);
1261 return (*dev->dev_ops->queue_pair_setup)(dev, queue_pair_id, qp_conf,
1265 struct rte_cryptodev_cb *
1266 rte_cryptodev_add_enq_callback(uint8_t dev_id,
1268 rte_cryptodev_callback_fn cb_fn,
1271 struct rte_cryptodev *dev;
1272 struct rte_cryptodev_cb_rcu *list;
1273 struct rte_cryptodev_cb *cb, *tail;
1276 CDEV_LOG_ERR("Callback is NULL on dev_id=%d", dev_id);
1281 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1282 CDEV_LOG_ERR("Invalid dev_id=%d", dev_id);
1287 dev = &rte_crypto_devices[dev_id];
1288 if (qp_id >= dev->data->nb_queue_pairs) {
1289 CDEV_LOG_ERR("Invalid queue_pair_id=%d", qp_id);
1294 cb = rte_zmalloc(NULL, sizeof(*cb), 0);
1296 CDEV_LOG_ERR("Failed to allocate memory for callback on "
1297 "dev=%d, queue_pair_id=%d", dev_id, qp_id);
1302 rte_spinlock_lock(&rte_cryptodev_callback_lock);
1307 /* Add the callbacks in fifo order. */
1308 list = &dev->enq_cbs[qp_id];
1314 /* Stores to cb->fn and cb->param should complete before
1315 * cb is visible to data plane.
1317 __atomic_store_n(&tail->next, cb, __ATOMIC_RELEASE);
1319 /* Stores to cb->fn and cb->param should complete before
1320 * cb is visible to data plane.
1322 __atomic_store_n(&list->next, cb, __ATOMIC_RELEASE);
1325 rte_spinlock_unlock(&rte_cryptodev_callback_lock);
1331 rte_cryptodev_remove_enq_callback(uint8_t dev_id,
1333 struct rte_cryptodev_cb *cb)
1335 struct rte_cryptodev *dev;
1336 struct rte_cryptodev_cb **prev_cb, *curr_cb;
1337 struct rte_cryptodev_cb_rcu *list;
1343 CDEV_LOG_ERR("Callback is NULL");
1347 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1348 CDEV_LOG_ERR("Invalid dev_id=%d", dev_id);
1352 dev = &rte_crypto_devices[dev_id];
1353 if (qp_id >= dev->data->nb_queue_pairs) {
1354 CDEV_LOG_ERR("Invalid queue_pair_id=%d", qp_id);
1358 rte_spinlock_lock(&rte_cryptodev_callback_lock);
1359 if (dev->enq_cbs == NULL) {
1360 CDEV_LOG_ERR("Callback not initialized");
1364 list = &dev->enq_cbs[qp_id];
1366 CDEV_LOG_ERR("Callback list is NULL");
1370 if (list->qsbr == NULL) {
1371 CDEV_LOG_ERR("Rcu qsbr is NULL");
1375 prev_cb = &list->next;
1376 for (; *prev_cb != NULL; prev_cb = &curr_cb->next) {
1378 if (curr_cb == cb) {
1379 /* Remove the user cb from the callback list. */
1380 __atomic_store_n(prev_cb, curr_cb->next,
1388 /* Call sync with invalid thread id as this is part of
1391 rte_rcu_qsbr_synchronize(list->qsbr, RTE_QSBR_THRID_INVALID);
1396 rte_spinlock_unlock(&rte_cryptodev_callback_lock);
1400 struct rte_cryptodev_cb *
1401 rte_cryptodev_add_deq_callback(uint8_t dev_id,
1403 rte_cryptodev_callback_fn cb_fn,
1406 struct rte_cryptodev *dev;
1407 struct rte_cryptodev_cb_rcu *list;
1408 struct rte_cryptodev_cb *cb, *tail;
1411 CDEV_LOG_ERR("Callback is NULL on dev_id=%d", dev_id);
1416 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1417 CDEV_LOG_ERR("Invalid dev_id=%d", dev_id);
1422 dev = &rte_crypto_devices[dev_id];
1423 if (qp_id >= dev->data->nb_queue_pairs) {
1424 CDEV_LOG_ERR("Invalid queue_pair_id=%d", qp_id);
1429 cb = rte_zmalloc(NULL, sizeof(*cb), 0);
1431 CDEV_LOG_ERR("Failed to allocate memory for callback on "
1432 "dev=%d, queue_pair_id=%d", dev_id, qp_id);
1437 rte_spinlock_lock(&rte_cryptodev_callback_lock);
1442 /* Add the callbacks in fifo order. */
1443 list = &dev->deq_cbs[qp_id];
1449 /* Stores to cb->fn and cb->param should complete before
1450 * cb is visible to data plane.
1452 __atomic_store_n(&tail->next, cb, __ATOMIC_RELEASE);
1454 /* Stores to cb->fn and cb->param should complete before
1455 * cb is visible to data plane.
1457 __atomic_store_n(&list->next, cb, __ATOMIC_RELEASE);
1460 rte_spinlock_unlock(&rte_cryptodev_callback_lock);
1466 rte_cryptodev_remove_deq_callback(uint8_t dev_id,
1468 struct rte_cryptodev_cb *cb)
1470 struct rte_cryptodev *dev;
1471 struct rte_cryptodev_cb **prev_cb, *curr_cb;
1472 struct rte_cryptodev_cb_rcu *list;
1478 CDEV_LOG_ERR("Callback is NULL");
1482 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1483 CDEV_LOG_ERR("Invalid dev_id=%d", dev_id);
1487 dev = &rte_crypto_devices[dev_id];
1488 if (qp_id >= dev->data->nb_queue_pairs) {
1489 CDEV_LOG_ERR("Invalid queue_pair_id=%d", qp_id);
1493 rte_spinlock_lock(&rte_cryptodev_callback_lock);
1494 if (dev->enq_cbs == NULL) {
1495 CDEV_LOG_ERR("Callback not initialized");
1499 list = &dev->deq_cbs[qp_id];
1501 CDEV_LOG_ERR("Callback list is NULL");
1505 if (list->qsbr == NULL) {
1506 CDEV_LOG_ERR("Rcu qsbr is NULL");
1510 prev_cb = &list->next;
1511 for (; *prev_cb != NULL; prev_cb = &curr_cb->next) {
1513 if (curr_cb == cb) {
1514 /* Remove the user cb from the callback list. */
1515 __atomic_store_n(prev_cb, curr_cb->next,
1523 /* Call sync with invalid thread id as this is part of
1526 rte_rcu_qsbr_synchronize(list->qsbr, RTE_QSBR_THRID_INVALID);
1531 rte_spinlock_unlock(&rte_cryptodev_callback_lock);
1536 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats)
1538 struct rte_cryptodev *dev;
1540 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1541 CDEV_LOG_ERR("Invalid dev_id=%d", dev_id);
1545 if (stats == NULL) {
1546 CDEV_LOG_ERR("Invalid stats ptr");
1550 dev = &rte_crypto_devices[dev_id];
1551 memset(stats, 0, sizeof(*stats));
1553 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1554 (*dev->dev_ops->stats_get)(dev, stats);
1559 rte_cryptodev_stats_reset(uint8_t dev_id)
1561 struct rte_cryptodev *dev;
1563 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1564 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
1568 dev = &rte_crypto_devices[dev_id];
1570 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1571 (*dev->dev_ops->stats_reset)(dev);
1575 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info)
1577 struct rte_cryptodev *dev;
1579 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1580 CDEV_LOG_ERR("Invalid dev_id=%d", dev_id);
1584 dev = &rte_crypto_devices[dev_id];
1586 memset(dev_info, 0, sizeof(struct rte_cryptodev_info));
1588 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1589 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1591 dev_info->driver_name = dev->device->driver->name;
1592 dev_info->device = dev->device;
1596 rte_cryptodev_callback_register(uint8_t dev_id,
1597 enum rte_cryptodev_event_type event,
1598 rte_cryptodev_cb_fn cb_fn, void *cb_arg)
1600 struct rte_cryptodev *dev;
1601 struct rte_cryptodev_callback *user_cb;
1606 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1607 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
1611 dev = &rte_crypto_devices[dev_id];
1612 rte_spinlock_lock(&rte_cryptodev_cb_lock);
1614 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
1615 if (user_cb->cb_fn == cb_fn &&
1616 user_cb->cb_arg == cb_arg &&
1617 user_cb->event == event) {
1622 /* create a new callback. */
1623 if (user_cb == NULL) {
1624 user_cb = rte_zmalloc("INTR_USER_CALLBACK",
1625 sizeof(struct rte_cryptodev_callback), 0);
1626 if (user_cb != NULL) {
1627 user_cb->cb_fn = cb_fn;
1628 user_cb->cb_arg = cb_arg;
1629 user_cb->event = event;
1630 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
1634 rte_spinlock_unlock(&rte_cryptodev_cb_lock);
1635 return (user_cb == NULL) ? -ENOMEM : 0;
1639 rte_cryptodev_callback_unregister(uint8_t dev_id,
1640 enum rte_cryptodev_event_type event,
1641 rte_cryptodev_cb_fn cb_fn, void *cb_arg)
1644 struct rte_cryptodev *dev;
1645 struct rte_cryptodev_callback *cb, *next;
1650 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1651 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
1655 dev = &rte_crypto_devices[dev_id];
1656 rte_spinlock_lock(&rte_cryptodev_cb_lock);
1659 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
1661 next = TAILQ_NEXT(cb, next);
1663 if (cb->cb_fn != cb_fn || cb->event != event ||
1664 (cb->cb_arg != (void *)-1 &&
1665 cb->cb_arg != cb_arg))
1669 * if this callback is not executing right now,
1672 if (cb->active == 0) {
1673 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
1680 rte_spinlock_unlock(&rte_cryptodev_cb_lock);
1685 rte_cryptodev_pmd_callback_process(struct rte_cryptodev *dev,
1686 enum rte_cryptodev_event_type event)
1688 struct rte_cryptodev_callback *cb_lst;
1689 struct rte_cryptodev_callback dev_cb;
1691 rte_spinlock_lock(&rte_cryptodev_cb_lock);
1692 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
1693 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
1697 rte_spinlock_unlock(&rte_cryptodev_cb_lock);
1698 dev_cb.cb_fn(dev->data->dev_id, dev_cb.event,
1700 rte_spinlock_lock(&rte_cryptodev_cb_lock);
1703 rte_spinlock_unlock(&rte_cryptodev_cb_lock);
1707 rte_cryptodev_sym_session_init(uint8_t dev_id,
1708 struct rte_cryptodev_sym_session *sess,
1709 struct rte_crypto_sym_xform *xforms,
1710 struct rte_mempool *mp)
1712 struct rte_cryptodev *dev;
1713 uint32_t sess_priv_sz = rte_cryptodev_sym_get_private_session_size(
1718 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1719 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
1723 dev = rte_cryptodev_pmd_get_dev(dev_id);
1725 if (sess == NULL || xforms == NULL || dev == NULL || mp == NULL)
1728 if (mp->elt_size < sess_priv_sz)
1731 index = dev->driver_id;
1732 if (index >= sess->nb_drivers)
1735 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->sym_session_configure, -ENOTSUP);
1737 if (sess->sess_data[index].refcnt == 0) {
1738 ret = dev->dev_ops->sym_session_configure(dev, xforms,
1742 "dev_id %d failed to configure session details",
1748 rte_cryptodev_trace_sym_session_init(dev_id, sess, xforms, mp);
1749 sess->sess_data[index].refcnt++;
1753 struct rte_mempool *
1754 rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
1755 uint32_t elt_size, uint32_t cache_size, uint16_t user_data_size,
1758 struct rte_mempool *mp;
1759 struct rte_cryptodev_sym_session_pool_private_data *pool_priv;
1762 obj_sz = rte_cryptodev_sym_get_header_session_size() + user_data_size;
1763 if (obj_sz > elt_size)
1764 CDEV_LOG_INFO("elt_size %u is expanded to %u\n", elt_size,
1769 mp = rte_mempool_create(name, nb_elts, obj_sz, cache_size,
1770 (uint32_t)(sizeof(*pool_priv)),
1771 NULL, NULL, NULL, NULL,
1774 CDEV_LOG_ERR("%s(name=%s) failed, rte_errno=%d\n",
1775 __func__, name, rte_errno);
1779 pool_priv = rte_mempool_get_priv(mp);
1781 CDEV_LOG_ERR("%s(name=%s) failed to get private data\n",
1783 rte_mempool_free(mp);
1787 pool_priv->nb_drivers = nb_drivers;
1788 pool_priv->user_data_sz = user_data_size;
1790 rte_cryptodev_trace_sym_session_pool_create(name, nb_elts,
1791 elt_size, cache_size, user_data_size, mp);
1795 struct rte_mempool *
1796 rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
1797 uint32_t cache_size, uint16_t user_data_size, int socket_id)
1799 struct rte_mempool *mp;
1800 struct rte_cryptodev_asym_session_pool_private_data *pool_priv;
1801 uint32_t obj_sz, obj_sz_aligned;
1803 unsigned int priv_sz, max_priv_sz = 0;
1805 for (dev_id = 0; dev_id < RTE_CRYPTO_MAX_DEVS; dev_id++)
1806 if (rte_cryptodev_is_valid_dev(dev_id)) {
1807 priv_sz = rte_cryptodev_asym_get_private_session_size(dev_id);
1808 if (priv_sz > max_priv_sz)
1809 max_priv_sz = priv_sz;
1811 if (max_priv_sz == 0) {
1812 CDEV_LOG_INFO("Could not set max private session size\n");
1816 obj_sz = rte_cryptodev_asym_get_header_session_size() + max_priv_sz +
1818 obj_sz_aligned = RTE_ALIGN_CEIL(obj_sz, RTE_CACHE_LINE_SIZE);
1820 mp = rte_mempool_create(name, nb_elts, obj_sz_aligned, cache_size,
1821 (uint32_t)(sizeof(*pool_priv)),
1822 NULL, NULL, NULL, NULL,
1825 CDEV_LOG_ERR("%s(name=%s) failed, rte_errno=%d\n",
1826 __func__, name, rte_errno);
1830 pool_priv = rte_mempool_get_priv(mp);
1832 CDEV_LOG_ERR("%s(name=%s) failed to get private data\n",
1834 rte_mempool_free(mp);
1837 pool_priv->max_priv_session_sz = max_priv_sz;
1838 pool_priv->user_data_sz = user_data_size;
1840 rte_cryptodev_trace_asym_session_pool_create(name, nb_elts,
1841 user_data_size, cache_size, mp);
1846 rte_cryptodev_sym_session_data_size(struct rte_cryptodev_sym_session *sess)
1848 return (sizeof(sess->sess_data[0]) * sess->nb_drivers) +
1853 rte_cryptodev_sym_is_valid_session_pool(struct rte_mempool *mp)
1855 struct rte_cryptodev_sym_session_pool_private_data *pool_priv;
1860 pool_priv = rte_mempool_get_priv(mp);
1862 if (!pool_priv || mp->private_data_size < sizeof(*pool_priv) ||
1863 pool_priv->nb_drivers != nb_drivers ||
1865 rte_cryptodev_sym_get_header_session_size()
1866 + pool_priv->user_data_sz)
1872 struct rte_cryptodev_sym_session *
1873 rte_cryptodev_sym_session_create(struct rte_mempool *mp)
1875 struct rte_cryptodev_sym_session *sess;
1876 struct rte_cryptodev_sym_session_pool_private_data *pool_priv;
1878 if (!rte_cryptodev_sym_is_valid_session_pool(mp)) {
1879 CDEV_LOG_ERR("Invalid mempool\n");
1883 pool_priv = rte_mempool_get_priv(mp);
1885 /* Allocate a session structure from the session pool */
1886 if (rte_mempool_get(mp, (void **)&sess)) {
1887 CDEV_LOG_ERR("couldn't get object from session mempool");
1891 sess->nb_drivers = pool_priv->nb_drivers;
1892 sess->user_data_sz = pool_priv->user_data_sz;
1893 sess->opaque_data = 0;
1895 /* Clear device session pointer.
1896 * Include the flag indicating presence of user data
1898 memset(sess->sess_data, 0,
1899 rte_cryptodev_sym_session_data_size(sess));
1901 rte_cryptodev_trace_sym_session_create(mp, sess);
1906 rte_cryptodev_asym_session_create(uint8_t dev_id,
1907 struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp,
1910 struct rte_cryptodev_asym_session *sess;
1911 uint32_t session_priv_data_sz;
1912 struct rte_cryptodev_asym_session_pool_private_data *pool_priv;
1913 unsigned int session_header_size =
1914 rte_cryptodev_asym_get_header_session_size();
1915 struct rte_cryptodev *dev;
1918 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1919 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
1923 dev = rte_cryptodev_pmd_get_dev(dev_id);
1929 CDEV_LOG_ERR("invalid mempool\n");
1933 session_priv_data_sz = rte_cryptodev_asym_get_private_session_size(
1935 pool_priv = rte_mempool_get_priv(mp);
1937 if (pool_priv->max_priv_session_sz < session_priv_data_sz) {
1939 "The private session data size used when creating the mempool is smaller than this device's private session data.");
1943 /* Verify if provided mempool can hold elements big enough. */
1944 if (mp->elt_size < session_header_size + session_priv_data_sz) {
1946 "mempool elements too small to hold session objects");
1950 /* Allocate a session structure from the session pool */
1951 if (rte_mempool_get(mp, session)) {
1952 CDEV_LOG_ERR("couldn't get object from session mempool");
1957 sess->driver_id = dev->driver_id;
1958 sess->user_data_sz = pool_priv->user_data_sz;
1959 sess->max_priv_data_sz = pool_priv->max_priv_session_sz;
1961 /* Clear device session pointer.*/
1962 memset(sess->sess_private_data, 0, session_priv_data_sz + sess->user_data_sz);
1964 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_configure, -ENOTSUP);
1966 if (sess->sess_private_data[0] == 0) {
1967 ret = dev->dev_ops->asym_session_configure(dev, xforms, sess);
1970 "dev_id %d failed to configure session details",
1976 rte_cryptodev_trace_asym_session_create(dev_id, xforms, mp, sess);
1981 rte_cryptodev_sym_session_clear(uint8_t dev_id,
1982 struct rte_cryptodev_sym_session *sess)
1984 struct rte_cryptodev *dev;
1987 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1988 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
1992 dev = rte_cryptodev_pmd_get_dev(dev_id);
1994 if (dev == NULL || sess == NULL)
1997 driver_id = dev->driver_id;
1998 if (sess->sess_data[driver_id].refcnt == 0)
2000 if (--sess->sess_data[driver_id].refcnt != 0)
2003 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->sym_session_clear, -ENOTSUP);
2005 dev->dev_ops->sym_session_clear(dev, sess);
2007 rte_cryptodev_trace_sym_session_clear(dev_id, sess);
2012 rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess)
2015 struct rte_mempool *sess_mp;
2020 /* Check that all device private data has been freed */
2021 for (i = 0; i < sess->nb_drivers; i++) {
2022 if (sess->sess_data[i].refcnt != 0)
2026 /* Return session to mempool */
2027 sess_mp = rte_mempool_from_obj(sess);
2028 rte_mempool_put(sess_mp, sess);
2030 rte_cryptodev_trace_sym_session_free(sess);
2035 rte_cryptodev_asym_session_free(uint8_t dev_id, void *sess)
2037 struct rte_mempool *sess_mp;
2038 struct rte_cryptodev *dev;
2040 if (!rte_cryptodev_is_valid_dev(dev_id)) {
2041 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
2045 dev = rte_cryptodev_pmd_get_dev(dev_id);
2047 if (dev == NULL || sess == NULL)
2050 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_clear, -ENOTSUP);
2052 dev->dev_ops->asym_session_clear(dev, sess);
2054 /* Return session to mempool */
2055 sess_mp = rte_mempool_from_obj(sess);
2056 rte_mempool_put(sess_mp, sess);
2058 rte_cryptodev_trace_asym_session_free(dev_id, sess);
2063 rte_cryptodev_sym_get_header_session_size(void)
2066 * Header contains pointers to the private data of all registered
2067 * drivers and all necessary information to ensure safely clear
2068 * or free al session.
2070 struct rte_cryptodev_sym_session s = {0};
2072 s.nb_drivers = nb_drivers;
2074 return (unsigned int)(sizeof(s) +
2075 rte_cryptodev_sym_session_data_size(&s));
2079 rte_cryptodev_sym_get_existing_header_session_size(
2080 struct rte_cryptodev_sym_session *sess)
2085 return (unsigned int)(sizeof(*sess) +
2086 rte_cryptodev_sym_session_data_size(sess));
2090 rte_cryptodev_asym_get_header_session_size(void)
2092 return sizeof(struct rte_cryptodev_asym_session);
2096 rte_cryptodev_sym_get_private_session_size(uint8_t dev_id)
2098 struct rte_cryptodev *dev;
2099 unsigned int priv_sess_size;
2101 if (!rte_cryptodev_is_valid_dev(dev_id))
2104 dev = rte_cryptodev_pmd_get_dev(dev_id);
2106 if (*dev->dev_ops->sym_session_get_size == NULL)
2109 priv_sess_size = (*dev->dev_ops->sym_session_get_size)(dev);
2111 return priv_sess_size;
2115 rte_cryptodev_asym_get_private_session_size(uint8_t dev_id)
2117 struct rte_cryptodev *dev;
2118 unsigned int priv_sess_size;
2120 if (!rte_cryptodev_is_valid_dev(dev_id))
2123 dev = rte_cryptodev_pmd_get_dev(dev_id);
2125 if (*dev->dev_ops->asym_session_get_size == NULL)
2128 priv_sess_size = (*dev->dev_ops->asym_session_get_size)(dev);
2130 return priv_sess_size;
2134 rte_cryptodev_sym_session_set_user_data(
2135 struct rte_cryptodev_sym_session *sess,
2142 if (sess->user_data_sz < size)
2145 rte_memcpy(sess->sess_data + sess->nb_drivers, data, size);
2150 rte_cryptodev_sym_session_get_user_data(
2151 struct rte_cryptodev_sym_session *sess)
2153 if (sess == NULL || sess->user_data_sz == 0)
2156 return (void *)(sess->sess_data + sess->nb_drivers);
2160 rte_cryptodev_asym_session_set_user_data(void *session, void *data, uint16_t size)
2162 struct rte_cryptodev_asym_session *sess = session;
2166 if (sess->user_data_sz < size)
2169 rte_memcpy(sess->sess_private_data +
2170 sess->max_priv_data_sz,
2176 rte_cryptodev_asym_session_get_user_data(void *session)
2178 struct rte_cryptodev_asym_session *sess = session;
2179 if (sess == NULL || sess->user_data_sz == 0)
2182 return (void *)(sess->sess_private_data +
2183 sess->max_priv_data_sz);
2187 sym_crypto_fill_status(struct rte_crypto_sym_vec *vec, int32_t errnum)
2190 for (i = 0; i < vec->num; i++)
2191 vec->status[i] = errnum;
2195 rte_cryptodev_sym_cpu_crypto_process(uint8_t dev_id,
2196 struct rte_cryptodev_sym_session *sess, union rte_crypto_sym_ofs ofs,
2197 struct rte_crypto_sym_vec *vec)
2199 struct rte_cryptodev *dev;
2201 if (!rte_cryptodev_is_valid_dev(dev_id)) {
2202 sym_crypto_fill_status(vec, EINVAL);
2206 dev = rte_cryptodev_pmd_get_dev(dev_id);
2208 if (*dev->dev_ops->sym_cpu_process == NULL ||
2209 !(dev->feature_flags & RTE_CRYPTODEV_FF_SYM_CPU_CRYPTO)) {
2210 sym_crypto_fill_status(vec, ENOTSUP);
2214 return dev->dev_ops->sym_cpu_process(dev, sess, ofs, vec);
2218 rte_cryptodev_get_raw_dp_ctx_size(uint8_t dev_id)
2220 struct rte_cryptodev *dev;
2221 int32_t size = sizeof(struct rte_crypto_raw_dp_ctx);
2224 if (!rte_cryptodev_is_valid_dev(dev_id))
2227 dev = rte_cryptodev_pmd_get_dev(dev_id);
2229 if (*dev->dev_ops->sym_get_raw_dp_ctx_size == NULL ||
2230 !(dev->feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP)) {
2234 priv_size = (*dev->dev_ops->sym_get_raw_dp_ctx_size)(dev);
2238 return RTE_ALIGN_CEIL((size + priv_size), 8);
2242 rte_cryptodev_configure_raw_dp_ctx(uint8_t dev_id, uint16_t qp_id,
2243 struct rte_crypto_raw_dp_ctx *ctx,
2244 enum rte_crypto_op_sess_type sess_type,
2245 union rte_cryptodev_session_ctx session_ctx,
2248 struct rte_cryptodev *dev;
2250 if (!rte_cryptodev_get_qp_status(dev_id, qp_id))
2253 dev = rte_cryptodev_pmd_get_dev(dev_id);
2254 if (!(dev->feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP)
2255 || dev->dev_ops->sym_configure_raw_dp_ctx == NULL)
2258 return (*dev->dev_ops->sym_configure_raw_dp_ctx)(dev, qp_id, ctx,
2259 sess_type, session_ctx, is_update);
2263 rte_cryptodev_raw_enqueue_burst(struct rte_crypto_raw_dp_ctx *ctx,
2264 struct rte_crypto_sym_vec *vec, union rte_crypto_sym_ofs ofs,
2265 void **user_data, int *enqueue_status)
2267 return (*ctx->enqueue_burst)(ctx->qp_data, ctx->drv_ctx_data, vec,
2268 ofs, user_data, enqueue_status);
2272 rte_cryptodev_raw_enqueue_done(struct rte_crypto_raw_dp_ctx *ctx,
2275 return (*ctx->enqueue_done)(ctx->qp_data, ctx->drv_ctx_data, n);
2279 rte_cryptodev_raw_dequeue_burst(struct rte_crypto_raw_dp_ctx *ctx,
2280 rte_cryptodev_raw_get_dequeue_count_t get_dequeue_count,
2281 uint32_t max_nb_to_dequeue,
2282 rte_cryptodev_raw_post_dequeue_t post_dequeue,
2283 void **out_user_data, uint8_t is_user_data_array,
2284 uint32_t *n_success_jobs, int *status)
2286 return (*ctx->dequeue_burst)(ctx->qp_data, ctx->drv_ctx_data,
2287 get_dequeue_count, max_nb_to_dequeue, post_dequeue,
2288 out_user_data, is_user_data_array, n_success_jobs, status);
2292 rte_cryptodev_raw_dequeue_done(struct rte_crypto_raw_dp_ctx *ctx,
2295 return (*ctx->dequeue_done)(ctx->qp_data, ctx->drv_ctx_data, n);
2298 /** Initialise rte_crypto_op mempool element */
2300 rte_crypto_op_init(struct rte_mempool *mempool,
2303 __rte_unused unsigned i)
2305 struct rte_crypto_op *op = _op_data;
2306 enum rte_crypto_op_type type = *(enum rte_crypto_op_type *)opaque_arg;
2308 memset(_op_data, 0, mempool->elt_size);
2310 __rte_crypto_op_reset(op, type);
2312 op->phys_addr = rte_mem_virt2iova(_op_data);
2313 op->mempool = mempool;
2317 struct rte_mempool *
2318 rte_crypto_op_pool_create(const char *name, enum rte_crypto_op_type type,
2319 unsigned nb_elts, unsigned cache_size, uint16_t priv_size,
2322 struct rte_crypto_op_pool_private *priv;
2324 unsigned elt_size = sizeof(struct rte_crypto_op) +
2327 if (type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
2328 elt_size += sizeof(struct rte_crypto_sym_op);
2329 } else if (type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
2330 elt_size += sizeof(struct rte_crypto_asym_op);
2331 } else if (type == RTE_CRYPTO_OP_TYPE_UNDEFINED) {
2332 elt_size += RTE_MAX(sizeof(struct rte_crypto_sym_op),
2333 sizeof(struct rte_crypto_asym_op));
2335 CDEV_LOG_ERR("Invalid op_type\n");
2339 /* lookup mempool in case already allocated */
2340 struct rte_mempool *mp = rte_mempool_lookup(name);
2343 priv = (struct rte_crypto_op_pool_private *)
2344 rte_mempool_get_priv(mp);
2346 if (mp->elt_size != elt_size ||
2347 mp->cache_size < cache_size ||
2348 mp->size < nb_elts ||
2349 priv->priv_size < priv_size) {
2351 CDEV_LOG_ERR("Mempool %s already exists but with "
2352 "incompatible parameters", name);
2358 mp = rte_mempool_create(
2363 sizeof(struct rte_crypto_op_pool_private),
2372 CDEV_LOG_ERR("Failed to create mempool %s", name);
2376 priv = (struct rte_crypto_op_pool_private *)
2377 rte_mempool_get_priv(mp);
2379 priv->priv_size = priv_size;
2386 rte_cryptodev_pmd_create_dev_name(char *name, const char *dev_name_prefix)
2388 struct rte_cryptodev *dev = NULL;
2394 for (i = 0; i < RTE_CRYPTO_MAX_DEVS; i++) {
2395 int ret = snprintf(name, RTE_CRYPTODEV_NAME_MAX_LEN,
2396 "%s_%u", dev_name_prefix, i);
2401 dev = rte_cryptodev_pmd_get_named_dev(name);
2409 TAILQ_HEAD(cryptodev_driver_list, cryptodev_driver);
2411 static struct cryptodev_driver_list cryptodev_driver_list =
2412 TAILQ_HEAD_INITIALIZER(cryptodev_driver_list);
2415 rte_cryptodev_driver_id_get(const char *name)
2417 struct cryptodev_driver *driver;
2418 const char *driver_name;
2421 RTE_LOG(DEBUG, CRYPTODEV, "name pointer NULL");
2425 TAILQ_FOREACH(driver, &cryptodev_driver_list, next) {
2426 driver_name = driver->driver->name;
2427 if (strncmp(driver_name, name, strlen(driver_name) + 1) == 0)
2434 rte_cryptodev_name_get(uint8_t dev_id)
2436 struct rte_cryptodev *dev;
2438 if (!rte_cryptodev_is_valid_device_data(dev_id)) {
2439 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
2443 dev = rte_cryptodev_pmd_get_dev(dev_id);
2447 return dev->data->name;
2451 rte_cryptodev_driver_name_get(uint8_t driver_id)
2453 struct cryptodev_driver *driver;
2455 TAILQ_FOREACH(driver, &cryptodev_driver_list, next)
2456 if (driver->id == driver_id)
2457 return driver->driver->name;
2462 rte_cryptodev_allocate_driver(struct cryptodev_driver *crypto_drv,
2463 const struct rte_driver *drv)
2465 crypto_drv->driver = drv;
2466 crypto_drv->id = nb_drivers;
2468 TAILQ_INSERT_TAIL(&cryptodev_driver_list, crypto_drv, next);
2470 return nb_drivers++;
2473 RTE_INIT(cryptodev_init_fp_ops)
2477 for (i = 0; i != RTE_DIM(rte_crypto_fp_ops); i++)
2478 cryptodev_fp_ops_reset(rte_crypto_fp_ops + i);
2482 cryptodev_handle_dev_list(const char *cmd __rte_unused,
2483 const char *params __rte_unused,
2484 struct rte_tel_data *d)
2488 if (rte_cryptodev_count() < 1)
2491 rte_tel_data_start_array(d, RTE_TEL_INT_VAL);
2492 for (dev_id = 0; dev_id < RTE_CRYPTO_MAX_DEVS; dev_id++)
2493 if (rte_cryptodev_is_valid_dev(dev_id))
2494 rte_tel_data_add_array_int(d, dev_id);
2500 cryptodev_handle_dev_info(const char *cmd __rte_unused,
2501 const char *params, struct rte_tel_data *d)
2503 struct rte_cryptodev_info cryptodev_info;
2507 if (params == NULL || strlen(params) == 0 || !isdigit(*params))
2510 dev_id = strtoul(params, &end_param, 0);
2511 if (*end_param != '\0')
2512 CDEV_LOG_ERR("Extra parameters passed to command, ignoring");
2513 if (!rte_cryptodev_is_valid_dev(dev_id))
2516 rte_cryptodev_info_get(dev_id, &cryptodev_info);
2518 rte_tel_data_start_dict(d);
2519 rte_tel_data_add_dict_string(d, "device_name",
2520 cryptodev_info.device->name);
2521 rte_tel_data_add_dict_int(d, "max_nb_queue_pairs",
2522 cryptodev_info.max_nb_queue_pairs);
2527 #define ADD_DICT_STAT(s) rte_tel_data_add_dict_u64(d, #s, cryptodev_stats.s)
2530 cryptodev_handle_dev_stats(const char *cmd __rte_unused,
2532 struct rte_tel_data *d)
2534 struct rte_cryptodev_stats cryptodev_stats;
2538 if (params == NULL || strlen(params) == 0 || !isdigit(*params))
2541 dev_id = strtoul(params, &end_param, 0);
2542 if (*end_param != '\0')
2543 CDEV_LOG_ERR("Extra parameters passed to command, ignoring");
2544 if (!rte_cryptodev_is_valid_dev(dev_id))
2547 ret = rte_cryptodev_stats_get(dev_id, &cryptodev_stats);
2551 rte_tel_data_start_dict(d);
2552 ADD_DICT_STAT(enqueued_count);
2553 ADD_DICT_STAT(dequeued_count);
2554 ADD_DICT_STAT(enqueue_err_count);
2555 ADD_DICT_STAT(dequeue_err_count);
2560 #define CRYPTO_CAPS_SZ \
2561 (RTE_ALIGN_CEIL(sizeof(struct rte_cryptodev_capabilities), \
2562 sizeof(uint64_t)) / \
2566 crypto_caps_array(struct rte_tel_data *d,
2567 const struct rte_cryptodev_capabilities *capabilities)
2569 const struct rte_cryptodev_capabilities *dev_caps;
2570 uint64_t caps_val[CRYPTO_CAPS_SZ];
2571 unsigned int i = 0, j;
2573 rte_tel_data_start_array(d, RTE_TEL_U64_VAL);
2575 while ((dev_caps = &capabilities[i++])->op !=
2576 RTE_CRYPTO_OP_TYPE_UNDEFINED) {
2577 memset(&caps_val, 0, CRYPTO_CAPS_SZ * sizeof(caps_val[0]));
2578 rte_memcpy(caps_val, dev_caps, sizeof(capabilities[0]));
2579 for (j = 0; j < CRYPTO_CAPS_SZ; j++)
2580 rte_tel_data_add_array_u64(d, caps_val[j]);
2587 cryptodev_handle_dev_caps(const char *cmd __rte_unused, const char *params,
2588 struct rte_tel_data *d)
2590 struct rte_cryptodev_info dev_info;
2591 struct rte_tel_data *crypto_caps;
2596 if (!params || strlen(params) == 0 || !isdigit(*params))
2599 dev_id = strtoul(params, &end_param, 0);
2600 if (*end_param != '\0')
2601 CDEV_LOG_ERR("Extra parameters passed to command, ignoring");
2602 if (!rte_cryptodev_is_valid_dev(dev_id))
2605 rte_tel_data_start_dict(d);
2606 crypto_caps = rte_tel_data_alloc();
2610 rte_cryptodev_info_get(dev_id, &dev_info);
2611 crypto_caps_n = crypto_caps_array(crypto_caps, dev_info.capabilities);
2612 rte_tel_data_add_dict_container(d, "crypto_caps", crypto_caps, 0);
2613 rte_tel_data_add_dict_int(d, "crypto_caps_n", crypto_caps_n);
2618 RTE_INIT(cryptodev_init_telemetry)
2620 rte_telemetry_register_cmd("/cryptodev/info", cryptodev_handle_dev_info,
2621 "Returns information for a cryptodev. Parameters: int dev_id");
2622 rte_telemetry_register_cmd("/cryptodev/list",
2623 cryptodev_handle_dev_list,
2624 "Returns list of available crypto devices by IDs. No parameters.");
2625 rte_telemetry_register_cmd("/cryptodev/stats",
2626 cryptodev_handle_dev_stats,
2627 "Returns the stats for a cryptodev. Parameters: int dev_id");
2628 rte_telemetry_register_cmd("/cryptodev/caps",
2629 cryptodev_handle_dev_caps,
2630 "Returns the capabilities for a cryptodev. Parameters: int dev_id");