1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2020 Intel Corporation
16 #include <rte_byteorder.h>
18 #include <rte_debug.h>
20 #include <rte_interrupts.h>
21 #include <rte_memory.h>
22 #include <rte_memcpy.h>
23 #include <rte_memzone.h>
24 #include <rte_launch.h>
25 #include <rte_tailq.h>
27 #include <rte_per_lcore.h>
28 #include <rte_lcore.h>
29 #include <rte_atomic.h>
30 #include <rte_branch_prediction.h>
31 #include <rte_common.h>
32 #include <rte_mempool.h>
33 #include <rte_malloc.h>
35 #include <rte_errno.h>
36 #include <rte_spinlock.h>
37 #include <rte_string_fns.h>
38 #include <rte_telemetry.h>
40 #include "rte_crypto.h"
41 #include "rte_cryptodev.h"
42 #include "cryptodev_pmd.h"
43 #include "rte_cryptodev_trace.h"
45 static uint8_t nb_drivers;
47 static struct rte_cryptodev rte_crypto_devices[RTE_CRYPTO_MAX_DEVS];
49 struct rte_cryptodev *rte_cryptodevs = rte_crypto_devices;
51 static struct rte_cryptodev_global cryptodev_globals = {
52 .devs = rte_crypto_devices,
57 /* Public fastpath APIs. */
58 struct rte_crypto_fp_ops rte_crypto_fp_ops[RTE_CRYPTO_MAX_DEVS];
60 /* spinlock for crypto device callbacks */
61 static rte_spinlock_t rte_cryptodev_cb_lock = RTE_SPINLOCK_INITIALIZER;
64 * The user application callback description.
66 * It contains callback address to be registered by user application,
67 * the pointer to the parameters for callback, and the event type.
69 struct rte_cryptodev_callback {
70 TAILQ_ENTRY(rte_cryptodev_callback) next; /**< Callbacks list */
71 rte_cryptodev_cb_fn cb_fn; /**< Callback address */
72 void *cb_arg; /**< Parameter for callback */
73 enum rte_cryptodev_event_type event; /**< Interrupt event type */
74 uint32_t active; /**< Callback is executing */
78 * The crypto cipher algorithm strings identifiers.
79 * It could be used in application command line.
82 rte_crypto_cipher_algorithm_strings[] = {
83 [RTE_CRYPTO_CIPHER_3DES_CBC] = "3des-cbc",
84 [RTE_CRYPTO_CIPHER_3DES_ECB] = "3des-ecb",
85 [RTE_CRYPTO_CIPHER_3DES_CTR] = "3des-ctr",
87 [RTE_CRYPTO_CIPHER_AES_CBC] = "aes-cbc",
88 [RTE_CRYPTO_CIPHER_AES_CTR] = "aes-ctr",
89 [RTE_CRYPTO_CIPHER_AES_DOCSISBPI] = "aes-docsisbpi",
90 [RTE_CRYPTO_CIPHER_AES_ECB] = "aes-ecb",
91 [RTE_CRYPTO_CIPHER_AES_F8] = "aes-f8",
92 [RTE_CRYPTO_CIPHER_AES_XTS] = "aes-xts",
94 [RTE_CRYPTO_CIPHER_ARC4] = "arc4",
96 [RTE_CRYPTO_CIPHER_DES_CBC] = "des-cbc",
97 [RTE_CRYPTO_CIPHER_DES_DOCSISBPI] = "des-docsisbpi",
99 [RTE_CRYPTO_CIPHER_NULL] = "null",
101 [RTE_CRYPTO_CIPHER_KASUMI_F8] = "kasumi-f8",
102 [RTE_CRYPTO_CIPHER_SNOW3G_UEA2] = "snow3g-uea2",
103 [RTE_CRYPTO_CIPHER_ZUC_EEA3] = "zuc-eea3"
107 * The crypto cipher operation strings identifiers.
108 * It could be used in application command line.
111 rte_crypto_cipher_operation_strings[] = {
112 [RTE_CRYPTO_CIPHER_OP_ENCRYPT] = "encrypt",
113 [RTE_CRYPTO_CIPHER_OP_DECRYPT] = "decrypt"
117 * The crypto auth algorithm strings identifiers.
118 * It could be used in application command line.
121 rte_crypto_auth_algorithm_strings[] = {
122 [RTE_CRYPTO_AUTH_AES_CBC_MAC] = "aes-cbc-mac",
123 [RTE_CRYPTO_AUTH_AES_CMAC] = "aes-cmac",
124 [RTE_CRYPTO_AUTH_AES_GMAC] = "aes-gmac",
125 [RTE_CRYPTO_AUTH_AES_XCBC_MAC] = "aes-xcbc-mac",
127 [RTE_CRYPTO_AUTH_MD5] = "md5",
128 [RTE_CRYPTO_AUTH_MD5_HMAC] = "md5-hmac",
130 [RTE_CRYPTO_AUTH_NULL] = "null",
132 [RTE_CRYPTO_AUTH_SHA1] = "sha1",
133 [RTE_CRYPTO_AUTH_SHA1_HMAC] = "sha1-hmac",
135 [RTE_CRYPTO_AUTH_SHA224] = "sha2-224",
136 [RTE_CRYPTO_AUTH_SHA224_HMAC] = "sha2-224-hmac",
137 [RTE_CRYPTO_AUTH_SHA256] = "sha2-256",
138 [RTE_CRYPTO_AUTH_SHA256_HMAC] = "sha2-256-hmac",
139 [RTE_CRYPTO_AUTH_SHA384] = "sha2-384",
140 [RTE_CRYPTO_AUTH_SHA384_HMAC] = "sha2-384-hmac",
141 [RTE_CRYPTO_AUTH_SHA512] = "sha2-512",
142 [RTE_CRYPTO_AUTH_SHA512_HMAC] = "sha2-512-hmac",
144 [RTE_CRYPTO_AUTH_KASUMI_F9] = "kasumi-f9",
145 [RTE_CRYPTO_AUTH_SNOW3G_UIA2] = "snow3g-uia2",
146 [RTE_CRYPTO_AUTH_ZUC_EIA3] = "zuc-eia3"
150 * The crypto AEAD algorithm strings identifiers.
151 * It could be used in application command line.
154 rte_crypto_aead_algorithm_strings[] = {
155 [RTE_CRYPTO_AEAD_AES_CCM] = "aes-ccm",
156 [RTE_CRYPTO_AEAD_AES_GCM] = "aes-gcm",
157 [RTE_CRYPTO_AEAD_CHACHA20_POLY1305] = "chacha20-poly1305"
161 * The crypto AEAD operation strings identifiers.
162 * It could be used in application command line.
165 rte_crypto_aead_operation_strings[] = {
166 [RTE_CRYPTO_AEAD_OP_ENCRYPT] = "encrypt",
167 [RTE_CRYPTO_AEAD_OP_DECRYPT] = "decrypt"
171 * Asymmetric crypto transform operation strings identifiers.
173 const char *rte_crypto_asym_xform_strings[] = {
174 [RTE_CRYPTO_ASYM_XFORM_NONE] = "none",
175 [RTE_CRYPTO_ASYM_XFORM_RSA] = "rsa",
176 [RTE_CRYPTO_ASYM_XFORM_MODEX] = "modexp",
177 [RTE_CRYPTO_ASYM_XFORM_MODINV] = "modinv",
178 [RTE_CRYPTO_ASYM_XFORM_DH] = "dh",
179 [RTE_CRYPTO_ASYM_XFORM_DSA] = "dsa",
180 [RTE_CRYPTO_ASYM_XFORM_ECDSA] = "ecdsa",
181 [RTE_CRYPTO_ASYM_XFORM_ECPM] = "ecpm",
185 * Asymmetric crypto operation strings identifiers.
187 const char *rte_crypto_asym_op_strings[] = {
188 [RTE_CRYPTO_ASYM_OP_ENCRYPT] = "encrypt",
189 [RTE_CRYPTO_ASYM_OP_DECRYPT] = "decrypt",
190 [RTE_CRYPTO_ASYM_OP_SIGN] = "sign",
191 [RTE_CRYPTO_ASYM_OP_VERIFY] = "verify",
192 [RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE] = "priv_key_generate",
193 [RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE] = "pub_key_generate",
194 [RTE_CRYPTO_ASYM_OP_SHARED_SECRET_COMPUTE] = "sharedsecret_compute",
198 * The private data structure stored in the session mempool private data.
200 struct rte_cryptodev_sym_session_pool_private_data {
202 /**< number of elements in sess_data array */
203 uint16_t user_data_sz;
204 /**< session user data will be placed after sess_data */
208 rte_cryptodev_get_cipher_algo_enum(enum rte_crypto_cipher_algorithm *algo_enum,
209 const char *algo_string)
213 for (i = 1; i < RTE_DIM(rte_crypto_cipher_algorithm_strings); i++) {
214 if (strcmp(algo_string, rte_crypto_cipher_algorithm_strings[i]) == 0) {
215 *algo_enum = (enum rte_crypto_cipher_algorithm) i;
225 rte_cryptodev_get_auth_algo_enum(enum rte_crypto_auth_algorithm *algo_enum,
226 const char *algo_string)
230 for (i = 1; i < RTE_DIM(rte_crypto_auth_algorithm_strings); i++) {
231 if (strcmp(algo_string, rte_crypto_auth_algorithm_strings[i]) == 0) {
232 *algo_enum = (enum rte_crypto_auth_algorithm) i;
242 rte_cryptodev_get_aead_algo_enum(enum rte_crypto_aead_algorithm *algo_enum,
243 const char *algo_string)
247 for (i = 1; i < RTE_DIM(rte_crypto_aead_algorithm_strings); i++) {
248 if (strcmp(algo_string, rte_crypto_aead_algorithm_strings[i]) == 0) {
249 *algo_enum = (enum rte_crypto_aead_algorithm) i;
259 rte_cryptodev_asym_get_xform_enum(enum rte_crypto_asym_xform_type *xform_enum,
260 const char *xform_string)
264 for (i = 1; i < RTE_DIM(rte_crypto_asym_xform_strings); i++) {
265 if (strcmp(xform_string,
266 rte_crypto_asym_xform_strings[i]) == 0) {
267 *xform_enum = (enum rte_crypto_asym_xform_type) i;
277 * The crypto auth operation strings identifiers.
278 * It could be used in application command line.
281 rte_crypto_auth_operation_strings[] = {
282 [RTE_CRYPTO_AUTH_OP_VERIFY] = "verify",
283 [RTE_CRYPTO_AUTH_OP_GENERATE] = "generate"
286 const struct rte_cryptodev_symmetric_capability *
287 rte_cryptodev_sym_capability_get(uint8_t dev_id,
288 const struct rte_cryptodev_sym_capability_idx *idx)
290 const struct rte_cryptodev_capabilities *capability;
291 struct rte_cryptodev_info dev_info;
294 rte_cryptodev_info_get(dev_id, &dev_info);
296 while ((capability = &dev_info.capabilities[i++])->op !=
297 RTE_CRYPTO_OP_TYPE_UNDEFINED) {
298 if (capability->op != RTE_CRYPTO_OP_TYPE_SYMMETRIC)
301 if (capability->sym.xform_type != idx->type)
304 if (idx->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
305 capability->sym.auth.algo == idx->algo.auth)
306 return &capability->sym;
308 if (idx->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
309 capability->sym.cipher.algo == idx->algo.cipher)
310 return &capability->sym;
312 if (idx->type == RTE_CRYPTO_SYM_XFORM_AEAD &&
313 capability->sym.aead.algo == idx->algo.aead)
314 return &capability->sym;
321 param_range_check(uint16_t size, const struct rte_crypto_param_range *range)
323 unsigned int next_size;
325 /* Check lower/upper bounds */
326 if (size < range->min)
329 if (size > range->max)
332 /* If range is actually only one value, size is correct */
333 if (range->increment == 0)
336 /* Check if value is one of the supported sizes */
337 for (next_size = range->min; next_size <= range->max;
338 next_size += range->increment)
339 if (size == next_size)
345 const struct rte_cryptodev_asymmetric_xform_capability *
346 rte_cryptodev_asym_capability_get(uint8_t dev_id,
347 const struct rte_cryptodev_asym_capability_idx *idx)
349 const struct rte_cryptodev_capabilities *capability;
350 struct rte_cryptodev_info dev_info;
353 memset(&dev_info, 0, sizeof(struct rte_cryptodev_info));
354 rte_cryptodev_info_get(dev_id, &dev_info);
356 while ((capability = &dev_info.capabilities[i++])->op !=
357 RTE_CRYPTO_OP_TYPE_UNDEFINED) {
358 if (capability->op != RTE_CRYPTO_OP_TYPE_ASYMMETRIC)
361 if (capability->asym.xform_capa.xform_type == idx->type)
362 return &capability->asym.xform_capa;
368 rte_cryptodev_sym_capability_check_cipher(
369 const struct rte_cryptodev_symmetric_capability *capability,
370 uint16_t key_size, uint16_t iv_size)
372 if (param_range_check(key_size, &capability->cipher.key_size) != 0)
375 if (param_range_check(iv_size, &capability->cipher.iv_size) != 0)
382 rte_cryptodev_sym_capability_check_auth(
383 const struct rte_cryptodev_symmetric_capability *capability,
384 uint16_t key_size, uint16_t digest_size, uint16_t iv_size)
386 if (param_range_check(key_size, &capability->auth.key_size) != 0)
389 if (param_range_check(digest_size, &capability->auth.digest_size) != 0)
392 if (param_range_check(iv_size, &capability->auth.iv_size) != 0)
399 rte_cryptodev_sym_capability_check_aead(
400 const struct rte_cryptodev_symmetric_capability *capability,
401 uint16_t key_size, uint16_t digest_size, uint16_t aad_size,
404 if (param_range_check(key_size, &capability->aead.key_size) != 0)
407 if (param_range_check(digest_size, &capability->aead.digest_size) != 0)
410 if (param_range_check(aad_size, &capability->aead.aad_size) != 0)
413 if (param_range_check(iv_size, &capability->aead.iv_size) != 0)
419 rte_cryptodev_asym_xform_capability_check_optype(
420 const struct rte_cryptodev_asymmetric_xform_capability *capability,
421 enum rte_crypto_asym_op_type op_type)
423 if (capability->op_types & (1 << op_type))
430 rte_cryptodev_asym_xform_capability_check_modlen(
431 const struct rte_cryptodev_asymmetric_xform_capability *capability,
434 /* no need to check for limits, if min or max = 0 */
435 if (capability->modlen.min != 0) {
436 if (modlen < capability->modlen.min)
440 if (capability->modlen.max != 0) {
441 if (modlen > capability->modlen.max)
445 /* in any case, check if given modlen is module increment */
446 if (capability->modlen.increment != 0) {
447 if (modlen % (capability->modlen.increment))
454 /* spinlock for crypto device enq callbacks */
455 static rte_spinlock_t rte_cryptodev_callback_lock = RTE_SPINLOCK_INITIALIZER;
458 cryptodev_cb_cleanup(struct rte_cryptodev *dev)
460 struct rte_cryptodev_cb_rcu *list;
461 struct rte_cryptodev_cb *cb, *next;
464 if (dev->enq_cbs == NULL && dev->deq_cbs == NULL)
467 for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
468 list = &dev->enq_cbs[qp_id];
476 rte_free(list->qsbr);
479 for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
480 list = &dev->deq_cbs[qp_id];
488 rte_free(list->qsbr);
491 rte_free(dev->enq_cbs);
493 rte_free(dev->deq_cbs);
498 cryptodev_cb_init(struct rte_cryptodev *dev)
500 struct rte_cryptodev_cb_rcu *list;
501 struct rte_rcu_qsbr *qsbr;
505 /* Max thread set to 1, as one DP thread accessing a queue-pair */
506 const uint32_t max_threads = 1;
508 dev->enq_cbs = rte_zmalloc(NULL,
509 sizeof(struct rte_cryptodev_cb_rcu) *
510 dev->data->nb_queue_pairs, 0);
511 if (dev->enq_cbs == NULL) {
512 CDEV_LOG_ERR("Failed to allocate memory for enq callbacks");
516 dev->deq_cbs = rte_zmalloc(NULL,
517 sizeof(struct rte_cryptodev_cb_rcu) *
518 dev->data->nb_queue_pairs, 0);
519 if (dev->deq_cbs == NULL) {
520 CDEV_LOG_ERR("Failed to allocate memory for deq callbacks");
521 rte_free(dev->enq_cbs);
525 /* Create RCU QSBR variable */
526 size = rte_rcu_qsbr_get_memsize(max_threads);
528 for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
529 list = &dev->enq_cbs[qp_id];
530 qsbr = rte_zmalloc(NULL, size, RTE_CACHE_LINE_SIZE);
532 CDEV_LOG_ERR("Failed to allocate memory for RCU on "
533 "queue_pair_id=%d", qp_id);
537 if (rte_rcu_qsbr_init(qsbr, max_threads)) {
538 CDEV_LOG_ERR("Failed to initialize for RCU on "
539 "queue_pair_id=%d", qp_id);
546 for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
547 list = &dev->deq_cbs[qp_id];
548 qsbr = rte_zmalloc(NULL, size, RTE_CACHE_LINE_SIZE);
550 CDEV_LOG_ERR("Failed to allocate memory for RCU on "
551 "queue_pair_id=%d", qp_id);
555 if (rte_rcu_qsbr_init(qsbr, max_threads)) {
556 CDEV_LOG_ERR("Failed to initialize for RCU on "
557 "queue_pair_id=%d", qp_id);
567 cryptodev_cb_cleanup(dev);
572 rte_cryptodev_get_feature_name(uint64_t flag)
575 case RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO:
576 return "SYMMETRIC_CRYPTO";
577 case RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO:
578 return "ASYMMETRIC_CRYPTO";
579 case RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING:
580 return "SYM_OPERATION_CHAINING";
581 case RTE_CRYPTODEV_FF_CPU_SSE:
583 case RTE_CRYPTODEV_FF_CPU_AVX:
585 case RTE_CRYPTODEV_FF_CPU_AVX2:
587 case RTE_CRYPTODEV_FF_CPU_AVX512:
589 case RTE_CRYPTODEV_FF_CPU_AESNI:
591 case RTE_CRYPTODEV_FF_HW_ACCELERATED:
592 return "HW_ACCELERATED";
593 case RTE_CRYPTODEV_FF_IN_PLACE_SGL:
594 return "IN_PLACE_SGL";
595 case RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT:
596 return "OOP_SGL_IN_SGL_OUT";
597 case RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT:
598 return "OOP_SGL_IN_LB_OUT";
599 case RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT:
600 return "OOP_LB_IN_SGL_OUT";
601 case RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT:
602 return "OOP_LB_IN_LB_OUT";
603 case RTE_CRYPTODEV_FF_CPU_NEON:
605 case RTE_CRYPTODEV_FF_CPU_ARM_CE:
607 case RTE_CRYPTODEV_FF_SECURITY:
608 return "SECURITY_PROTOCOL";
609 case RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP:
610 return "RSA_PRIV_OP_KEY_EXP";
611 case RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT:
612 return "RSA_PRIV_OP_KEY_QT";
613 case RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED:
614 return "DIGEST_ENCRYPTED";
615 case RTE_CRYPTODEV_FF_SYM_CPU_CRYPTO:
616 return "SYM_CPU_CRYPTO";
617 case RTE_CRYPTODEV_FF_ASYM_SESSIONLESS:
618 return "ASYM_SESSIONLESS";
619 case RTE_CRYPTODEV_FF_SYM_SESSIONLESS:
620 return "SYM_SESSIONLESS";
621 case RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA:
622 return "NON_BYTE_ALIGNED_DATA";
623 case RTE_CRYPTODEV_FF_CIPHER_MULTIPLE_DATA_UNITS:
624 return "CIPHER_MULTIPLE_DATA_UNITS";
625 case RTE_CRYPTODEV_FF_CIPHER_WRAPPED_KEY:
626 return "CIPHER_WRAPPED_KEY";
632 struct rte_cryptodev *
633 rte_cryptodev_pmd_get_dev(uint8_t dev_id)
635 return &cryptodev_globals.devs[dev_id];
638 struct rte_cryptodev *
639 rte_cryptodev_pmd_get_named_dev(const char *name)
641 struct rte_cryptodev *dev;
647 for (i = 0; i < RTE_CRYPTO_MAX_DEVS; i++) {
648 dev = &cryptodev_globals.devs[i];
650 if ((dev->attached == RTE_CRYPTODEV_ATTACHED) &&
651 (strcmp(dev->data->name, name) == 0))
658 static inline uint8_t
659 rte_cryptodev_is_valid_device_data(uint8_t dev_id)
661 if (dev_id >= RTE_CRYPTO_MAX_DEVS ||
662 rte_crypto_devices[dev_id].data == NULL)
669 rte_cryptodev_is_valid_dev(uint8_t dev_id)
671 struct rte_cryptodev *dev = NULL;
673 if (!rte_cryptodev_is_valid_device_data(dev_id))
676 dev = rte_cryptodev_pmd_get_dev(dev_id);
677 if (dev->attached != RTE_CRYPTODEV_ATTACHED)
685 rte_cryptodev_get_dev_id(const char *name)
692 for (i = 0; i < RTE_CRYPTO_MAX_DEVS; i++) {
693 if (!rte_cryptodev_is_valid_device_data(i))
695 if ((strcmp(cryptodev_globals.devs[i].data->name, name)
697 (cryptodev_globals.devs[i].attached ==
698 RTE_CRYPTODEV_ATTACHED))
706 rte_cryptodev_count(void)
708 return cryptodev_globals.nb_devs;
712 rte_cryptodev_device_count_by_driver(uint8_t driver_id)
714 uint8_t i, dev_count = 0;
716 for (i = 0; i < RTE_CRYPTO_MAX_DEVS; i++)
717 if (cryptodev_globals.devs[i].driver_id == driver_id &&
718 cryptodev_globals.devs[i].attached ==
719 RTE_CRYPTODEV_ATTACHED)
726 rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
729 uint8_t i, count = 0;
730 struct rte_cryptodev *devs = cryptodev_globals.devs;
732 for (i = 0; i < RTE_CRYPTO_MAX_DEVS && count < nb_devices; i++) {
733 if (!rte_cryptodev_is_valid_device_data(i))
736 if (devs[i].attached == RTE_CRYPTODEV_ATTACHED) {
739 cmp = strncmp(devs[i].device->driver->name,
741 strlen(driver_name) + 1);
744 devices[count++] = devs[i].data->dev_id;
752 rte_cryptodev_get_sec_ctx(uint8_t dev_id)
754 if (dev_id < RTE_CRYPTO_MAX_DEVS &&
755 (rte_crypto_devices[dev_id].feature_flags &
756 RTE_CRYPTODEV_FF_SECURITY))
757 return rte_crypto_devices[dev_id].security_ctx;
763 rte_cryptodev_socket_id(uint8_t dev_id)
765 struct rte_cryptodev *dev;
767 if (!rte_cryptodev_is_valid_dev(dev_id))
770 dev = rte_cryptodev_pmd_get_dev(dev_id);
772 return dev->data->socket_id;
776 rte_cryptodev_data_alloc(uint8_t dev_id, struct rte_cryptodev_data **data,
779 char mz_name[RTE_MEMZONE_NAMESIZE];
780 const struct rte_memzone *mz;
783 /* generate memzone name */
784 n = snprintf(mz_name, sizeof(mz_name), "rte_cryptodev_data_%u", dev_id);
785 if (n >= (int)sizeof(mz_name))
788 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
789 mz = rte_memzone_reserve(mz_name,
790 sizeof(struct rte_cryptodev_data),
792 CDEV_LOG_DEBUG("PRIMARY:reserved memzone for %s (%p)",
795 mz = rte_memzone_lookup(mz_name);
796 CDEV_LOG_DEBUG("SECONDARY:looked up memzone for %s (%p)",
804 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
805 memset(*data, 0, sizeof(struct rte_cryptodev_data));
811 rte_cryptodev_data_free(uint8_t dev_id, struct rte_cryptodev_data **data)
813 char mz_name[RTE_MEMZONE_NAMESIZE];
814 const struct rte_memzone *mz;
817 /* generate memzone name */
818 n = snprintf(mz_name, sizeof(mz_name), "rte_cryptodev_data_%u", dev_id);
819 if (n >= (int)sizeof(mz_name))
822 mz = rte_memzone_lookup(mz_name);
826 RTE_ASSERT(*data == mz->addr);
829 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
830 CDEV_LOG_DEBUG("PRIMARY:free memzone of %s (%p)",
832 return rte_memzone_free(mz);
834 CDEV_LOG_DEBUG("SECONDARY:don't free memzone of %s (%p)",
842 rte_cryptodev_find_free_device_index(void)
846 for (dev_id = 0; dev_id < RTE_CRYPTO_MAX_DEVS; dev_id++) {
847 if (rte_crypto_devices[dev_id].attached ==
848 RTE_CRYPTODEV_DETACHED)
851 return RTE_CRYPTO_MAX_DEVS;
854 struct rte_cryptodev *
855 rte_cryptodev_pmd_allocate(const char *name, int socket_id)
857 struct rte_cryptodev *cryptodev;
860 if (rte_cryptodev_pmd_get_named_dev(name) != NULL) {
861 CDEV_LOG_ERR("Crypto device with name %s already "
866 dev_id = rte_cryptodev_find_free_device_index();
867 if (dev_id == RTE_CRYPTO_MAX_DEVS) {
868 CDEV_LOG_ERR("Reached maximum number of crypto devices");
872 cryptodev = rte_cryptodev_pmd_get_dev(dev_id);
874 if (cryptodev->data == NULL) {
875 struct rte_cryptodev_data **cryptodev_data =
876 &cryptodev_globals.data[dev_id];
878 int retval = rte_cryptodev_data_alloc(dev_id, cryptodev_data,
881 if (retval < 0 || *cryptodev_data == NULL)
884 cryptodev->data = *cryptodev_data;
886 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
887 strlcpy(cryptodev->data->name, name,
888 RTE_CRYPTODEV_NAME_MAX_LEN);
890 cryptodev->data->dev_id = dev_id;
891 cryptodev->data->socket_id = socket_id;
892 cryptodev->data->dev_started = 0;
893 CDEV_LOG_DEBUG("PRIMARY:init data");
896 CDEV_LOG_DEBUG("Data for %s: dev_id %d, socket %d, started %d",
897 cryptodev->data->name,
898 cryptodev->data->dev_id,
899 cryptodev->data->socket_id,
900 cryptodev->data->dev_started);
902 /* init user callbacks */
903 TAILQ_INIT(&(cryptodev->link_intr_cbs));
905 cryptodev->attached = RTE_CRYPTODEV_ATTACHED;
907 cryptodev_globals.nb_devs++;
914 rte_cryptodev_pmd_release_device(struct rte_cryptodev *cryptodev)
919 if (cryptodev == NULL)
922 dev_id = cryptodev->data->dev_id;
924 cryptodev_fp_ops_reset(rte_crypto_fp_ops + dev_id);
926 /* Close device only if device operations have been set */
927 if (cryptodev->dev_ops) {
928 ret = rte_cryptodev_close(dev_id);
933 ret = rte_cryptodev_data_free(dev_id, &cryptodev_globals.data[dev_id]);
937 cryptodev->attached = RTE_CRYPTODEV_DETACHED;
938 cryptodev_globals.nb_devs--;
943 rte_cryptodev_queue_pair_count(uint8_t dev_id)
945 struct rte_cryptodev *dev;
947 if (!rte_cryptodev_is_valid_device_data(dev_id)) {
948 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
952 dev = &rte_crypto_devices[dev_id];
953 return dev->data->nb_queue_pairs;
957 rte_cryptodev_queue_pairs_config(struct rte_cryptodev *dev, uint16_t nb_qpairs,
960 struct rte_cryptodev_info dev_info;
964 if ((dev == NULL) || (nb_qpairs < 1)) {
965 CDEV_LOG_ERR("invalid param: dev %p, nb_queues %u",
970 CDEV_LOG_DEBUG("Setup %d queues pairs on device %u",
971 nb_qpairs, dev->data->dev_id);
973 memset(&dev_info, 0, sizeof(struct rte_cryptodev_info));
975 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
976 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
978 if (nb_qpairs > (dev_info.max_nb_queue_pairs)) {
979 CDEV_LOG_ERR("Invalid num queue_pairs (%u) for dev %u",
980 nb_qpairs, dev->data->dev_id);
984 if (dev->data->queue_pairs == NULL) { /* first time configuration */
985 dev->data->queue_pairs = rte_zmalloc_socket(
986 "cryptodev->queue_pairs",
987 sizeof(dev->data->queue_pairs[0]) *
988 dev_info.max_nb_queue_pairs,
989 RTE_CACHE_LINE_SIZE, socket_id);
991 if (dev->data->queue_pairs == NULL) {
992 dev->data->nb_queue_pairs = 0;
993 CDEV_LOG_ERR("failed to get memory for qp meta data, "
998 } else { /* re-configure */
1000 uint16_t old_nb_queues = dev->data->nb_queue_pairs;
1002 qp = dev->data->queue_pairs;
1004 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_pair_release,
1007 for (i = nb_qpairs; i < old_nb_queues; i++) {
1008 ret = (*dev->dev_ops->queue_pair_release)(dev, i);
1015 dev->data->nb_queue_pairs = nb_qpairs;
1020 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config)
1022 struct rte_cryptodev *dev;
1025 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1026 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
1030 dev = &rte_crypto_devices[dev_id];
1032 if (dev->data->dev_started) {
1034 "device %d must be stopped to allow configuration", dev_id);
1038 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
1040 rte_spinlock_lock(&rte_cryptodev_callback_lock);
1041 cryptodev_cb_cleanup(dev);
1042 rte_spinlock_unlock(&rte_cryptodev_callback_lock);
1044 /* Setup new number of queue pairs and reconfigure device. */
1045 diag = rte_cryptodev_queue_pairs_config(dev, config->nb_queue_pairs,
1048 CDEV_LOG_ERR("dev%d rte_crypto_dev_queue_pairs_config = %d",
1053 rte_spinlock_lock(&rte_cryptodev_callback_lock);
1054 diag = cryptodev_cb_init(dev);
1055 rte_spinlock_unlock(&rte_cryptodev_callback_lock);
1057 CDEV_LOG_ERR("Callback init failed for dev_id=%d", dev_id);
1061 rte_cryptodev_trace_configure(dev_id, config);
1062 return (*dev->dev_ops->dev_configure)(dev, config);
1066 rte_cryptodev_start(uint8_t dev_id)
1068 struct rte_cryptodev *dev;
1071 CDEV_LOG_DEBUG("Start dev_id=%" PRIu8, dev_id);
1073 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1074 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
1078 dev = &rte_crypto_devices[dev_id];
1080 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1082 if (dev->data->dev_started != 0) {
1083 CDEV_LOG_ERR("Device with dev_id=%" PRIu8 " already started",
1088 diag = (*dev->dev_ops->dev_start)(dev);
1089 /* expose selection of PMD fast-path functions */
1090 cryptodev_fp_ops_set(rte_crypto_fp_ops + dev_id, dev);
1092 rte_cryptodev_trace_start(dev_id, diag);
1094 dev->data->dev_started = 1;
1102 rte_cryptodev_stop(uint8_t dev_id)
1104 struct rte_cryptodev *dev;
1106 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1107 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
1111 dev = &rte_crypto_devices[dev_id];
1113 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1115 if (dev->data->dev_started == 0) {
1116 CDEV_LOG_ERR("Device with dev_id=%" PRIu8 " already stopped",
1121 /* point fast-path functions to dummy ones */
1122 cryptodev_fp_ops_reset(rte_crypto_fp_ops + dev_id);
1124 (*dev->dev_ops->dev_stop)(dev);
1125 rte_cryptodev_trace_stop(dev_id);
1126 dev->data->dev_started = 0;
1130 rte_cryptodev_close(uint8_t dev_id)
1132 struct rte_cryptodev *dev;
1135 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1136 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
1140 dev = &rte_crypto_devices[dev_id];
1142 /* Device must be stopped before it can be closed */
1143 if (dev->data->dev_started == 1) {
1144 CDEV_LOG_ERR("Device %u must be stopped before closing",
1149 /* We can't close the device if there are outstanding sessions in use */
1150 if (dev->data->session_pool != NULL) {
1151 if (!rte_mempool_full(dev->data->session_pool)) {
1152 CDEV_LOG_ERR("dev_id=%u close failed, session mempool "
1153 "has sessions still in use, free "
1154 "all sessions before calling close",
1160 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_close, -ENOTSUP);
1161 retval = (*dev->dev_ops->dev_close)(dev);
1162 rte_cryptodev_trace_close(dev_id, retval);
1171 rte_cryptodev_get_qp_status(uint8_t dev_id, uint16_t queue_pair_id)
1173 struct rte_cryptodev *dev;
1175 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1176 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
1180 dev = &rte_crypto_devices[dev_id];
1181 if (queue_pair_id >= dev->data->nb_queue_pairs) {
1182 CDEV_LOG_ERR("Invalid queue_pair_id=%d", queue_pair_id);
1185 void **qps = dev->data->queue_pairs;
1187 if (qps[queue_pair_id]) {
1188 CDEV_LOG_DEBUG("qp %d on dev %d is initialised",
1189 queue_pair_id, dev_id);
1193 CDEV_LOG_DEBUG("qp %d on dev %d is not initialised",
1194 queue_pair_id, dev_id);
1200 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
1201 const struct rte_cryptodev_qp_conf *qp_conf, int socket_id)
1204 struct rte_cryptodev *dev;
1206 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1207 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
1211 dev = &rte_crypto_devices[dev_id];
1212 if (queue_pair_id >= dev->data->nb_queue_pairs) {
1213 CDEV_LOG_ERR("Invalid queue_pair_id=%d", queue_pair_id);
1218 CDEV_LOG_ERR("qp_conf cannot be NULL\n");
1222 if ((qp_conf->mp_session && !qp_conf->mp_session_private) ||
1223 (!qp_conf->mp_session && qp_conf->mp_session_private)) {
1224 CDEV_LOG_ERR("Invalid mempools\n");
1228 if (qp_conf->mp_session) {
1229 struct rte_cryptodev_sym_session_pool_private_data *pool_priv;
1230 uint32_t obj_size = qp_conf->mp_session->elt_size;
1231 uint32_t obj_priv_size = qp_conf->mp_session_private->elt_size;
1232 struct rte_cryptodev_sym_session s = {0};
1234 pool_priv = rte_mempool_get_priv(qp_conf->mp_session);
1235 if (!pool_priv || qp_conf->mp_session->private_data_size <
1236 sizeof(*pool_priv)) {
1237 CDEV_LOG_ERR("Invalid mempool\n");
1241 s.nb_drivers = pool_priv->nb_drivers;
1242 s.user_data_sz = pool_priv->user_data_sz;
1244 if ((rte_cryptodev_sym_get_existing_header_session_size(&s) >
1245 obj_size) || (s.nb_drivers <= dev->driver_id) ||
1246 rte_cryptodev_sym_get_private_session_size(dev_id) >
1248 CDEV_LOG_ERR("Invalid mempool\n");
1253 if (dev->data->dev_started) {
1255 "device %d must be stopped to allow configuration", dev_id);
1259 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_pair_setup, -ENOTSUP);
1261 rte_cryptodev_trace_queue_pair_setup(dev_id, queue_pair_id, qp_conf);
1262 return (*dev->dev_ops->queue_pair_setup)(dev, queue_pair_id, qp_conf,
1266 struct rte_cryptodev_cb *
1267 rte_cryptodev_add_enq_callback(uint8_t dev_id,
1269 rte_cryptodev_callback_fn cb_fn,
1272 struct rte_cryptodev *dev;
1273 struct rte_cryptodev_cb_rcu *list;
1274 struct rte_cryptodev_cb *cb, *tail;
1277 CDEV_LOG_ERR("Callback is NULL on dev_id=%d", dev_id);
1282 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1283 CDEV_LOG_ERR("Invalid dev_id=%d", dev_id);
1288 dev = &rte_crypto_devices[dev_id];
1289 if (qp_id >= dev->data->nb_queue_pairs) {
1290 CDEV_LOG_ERR("Invalid queue_pair_id=%d", qp_id);
1295 cb = rte_zmalloc(NULL, sizeof(*cb), 0);
1297 CDEV_LOG_ERR("Failed to allocate memory for callback on "
1298 "dev=%d, queue_pair_id=%d", dev_id, qp_id);
1303 rte_spinlock_lock(&rte_cryptodev_callback_lock);
1308 /* Add the callbacks in fifo order. */
1309 list = &dev->enq_cbs[qp_id];
1315 /* Stores to cb->fn and cb->param should complete before
1316 * cb is visible to data plane.
1318 __atomic_store_n(&tail->next, cb, __ATOMIC_RELEASE);
1320 /* Stores to cb->fn and cb->param should complete before
1321 * cb is visible to data plane.
1323 __atomic_store_n(&list->next, cb, __ATOMIC_RELEASE);
1326 rte_spinlock_unlock(&rte_cryptodev_callback_lock);
1332 rte_cryptodev_remove_enq_callback(uint8_t dev_id,
1334 struct rte_cryptodev_cb *cb)
1336 struct rte_cryptodev *dev;
1337 struct rte_cryptodev_cb **prev_cb, *curr_cb;
1338 struct rte_cryptodev_cb_rcu *list;
1344 CDEV_LOG_ERR("Callback is NULL");
1348 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1349 CDEV_LOG_ERR("Invalid dev_id=%d", dev_id);
1353 dev = &rte_crypto_devices[dev_id];
1354 if (qp_id >= dev->data->nb_queue_pairs) {
1355 CDEV_LOG_ERR("Invalid queue_pair_id=%d", qp_id);
1359 rte_spinlock_lock(&rte_cryptodev_callback_lock);
1360 if (dev->enq_cbs == NULL) {
1361 CDEV_LOG_ERR("Callback not initialized");
1365 list = &dev->enq_cbs[qp_id];
1367 CDEV_LOG_ERR("Callback list is NULL");
1371 if (list->qsbr == NULL) {
1372 CDEV_LOG_ERR("Rcu qsbr is NULL");
1376 prev_cb = &list->next;
1377 for (; *prev_cb != NULL; prev_cb = &curr_cb->next) {
1379 if (curr_cb == cb) {
1380 /* Remove the user cb from the callback list. */
1381 __atomic_store_n(prev_cb, curr_cb->next,
1389 /* Call sync with invalid thread id as this is part of
1392 rte_rcu_qsbr_synchronize(list->qsbr, RTE_QSBR_THRID_INVALID);
1397 rte_spinlock_unlock(&rte_cryptodev_callback_lock);
1401 struct rte_cryptodev_cb *
1402 rte_cryptodev_add_deq_callback(uint8_t dev_id,
1404 rte_cryptodev_callback_fn cb_fn,
1407 struct rte_cryptodev *dev;
1408 struct rte_cryptodev_cb_rcu *list;
1409 struct rte_cryptodev_cb *cb, *tail;
1412 CDEV_LOG_ERR("Callback is NULL on dev_id=%d", dev_id);
1417 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1418 CDEV_LOG_ERR("Invalid dev_id=%d", dev_id);
1423 dev = &rte_crypto_devices[dev_id];
1424 if (qp_id >= dev->data->nb_queue_pairs) {
1425 CDEV_LOG_ERR("Invalid queue_pair_id=%d", qp_id);
1430 cb = rte_zmalloc(NULL, sizeof(*cb), 0);
1432 CDEV_LOG_ERR("Failed to allocate memory for callback on "
1433 "dev=%d, queue_pair_id=%d", dev_id, qp_id);
1438 rte_spinlock_lock(&rte_cryptodev_callback_lock);
1443 /* Add the callbacks in fifo order. */
1444 list = &dev->deq_cbs[qp_id];
1450 /* Stores to cb->fn and cb->param should complete before
1451 * cb is visible to data plane.
1453 __atomic_store_n(&tail->next, cb, __ATOMIC_RELEASE);
1455 /* Stores to cb->fn and cb->param should complete before
1456 * cb is visible to data plane.
1458 __atomic_store_n(&list->next, cb, __ATOMIC_RELEASE);
1461 rte_spinlock_unlock(&rte_cryptodev_callback_lock);
1467 rte_cryptodev_remove_deq_callback(uint8_t dev_id,
1469 struct rte_cryptodev_cb *cb)
1471 struct rte_cryptodev *dev;
1472 struct rte_cryptodev_cb **prev_cb, *curr_cb;
1473 struct rte_cryptodev_cb_rcu *list;
1479 CDEV_LOG_ERR("Callback is NULL");
1483 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1484 CDEV_LOG_ERR("Invalid dev_id=%d", dev_id);
1488 dev = &rte_crypto_devices[dev_id];
1489 if (qp_id >= dev->data->nb_queue_pairs) {
1490 CDEV_LOG_ERR("Invalid queue_pair_id=%d", qp_id);
1494 rte_spinlock_lock(&rte_cryptodev_callback_lock);
1495 if (dev->enq_cbs == NULL) {
1496 CDEV_LOG_ERR("Callback not initialized");
1500 list = &dev->deq_cbs[qp_id];
1502 CDEV_LOG_ERR("Callback list is NULL");
1506 if (list->qsbr == NULL) {
1507 CDEV_LOG_ERR("Rcu qsbr is NULL");
1511 prev_cb = &list->next;
1512 for (; *prev_cb != NULL; prev_cb = &curr_cb->next) {
1514 if (curr_cb == cb) {
1515 /* Remove the user cb from the callback list. */
1516 __atomic_store_n(prev_cb, curr_cb->next,
1524 /* Call sync with invalid thread id as this is part of
1527 rte_rcu_qsbr_synchronize(list->qsbr, RTE_QSBR_THRID_INVALID);
1532 rte_spinlock_unlock(&rte_cryptodev_callback_lock);
1537 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats)
1539 struct rte_cryptodev *dev;
1541 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1542 CDEV_LOG_ERR("Invalid dev_id=%d", dev_id);
1546 if (stats == NULL) {
1547 CDEV_LOG_ERR("Invalid stats ptr");
1551 dev = &rte_crypto_devices[dev_id];
1552 memset(stats, 0, sizeof(*stats));
1554 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1555 (*dev->dev_ops->stats_get)(dev, stats);
1560 rte_cryptodev_stats_reset(uint8_t dev_id)
1562 struct rte_cryptodev *dev;
1564 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1565 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
1569 dev = &rte_crypto_devices[dev_id];
1571 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1572 (*dev->dev_ops->stats_reset)(dev);
1576 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info)
1578 struct rte_cryptodev *dev;
1580 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1581 CDEV_LOG_ERR("Invalid dev_id=%d", dev_id);
1585 dev = &rte_crypto_devices[dev_id];
1587 memset(dev_info, 0, sizeof(struct rte_cryptodev_info));
1589 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1590 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1592 dev_info->driver_name = dev->device->driver->name;
1593 dev_info->device = dev->device;
1597 rte_cryptodev_callback_register(uint8_t dev_id,
1598 enum rte_cryptodev_event_type event,
1599 rte_cryptodev_cb_fn cb_fn, void *cb_arg)
1601 struct rte_cryptodev *dev;
1602 struct rte_cryptodev_callback *user_cb;
1607 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1608 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
1612 dev = &rte_crypto_devices[dev_id];
1613 rte_spinlock_lock(&rte_cryptodev_cb_lock);
1615 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
1616 if (user_cb->cb_fn == cb_fn &&
1617 user_cb->cb_arg == cb_arg &&
1618 user_cb->event == event) {
1623 /* create a new callback. */
1624 if (user_cb == NULL) {
1625 user_cb = rte_zmalloc("INTR_USER_CALLBACK",
1626 sizeof(struct rte_cryptodev_callback), 0);
1627 if (user_cb != NULL) {
1628 user_cb->cb_fn = cb_fn;
1629 user_cb->cb_arg = cb_arg;
1630 user_cb->event = event;
1631 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
1635 rte_spinlock_unlock(&rte_cryptodev_cb_lock);
1636 return (user_cb == NULL) ? -ENOMEM : 0;
1640 rte_cryptodev_callback_unregister(uint8_t dev_id,
1641 enum rte_cryptodev_event_type event,
1642 rte_cryptodev_cb_fn cb_fn, void *cb_arg)
1645 struct rte_cryptodev *dev;
1646 struct rte_cryptodev_callback *cb, *next;
1651 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1652 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
1656 dev = &rte_crypto_devices[dev_id];
1657 rte_spinlock_lock(&rte_cryptodev_cb_lock);
1660 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
1662 next = TAILQ_NEXT(cb, next);
1664 if (cb->cb_fn != cb_fn || cb->event != event ||
1665 (cb->cb_arg != (void *)-1 &&
1666 cb->cb_arg != cb_arg))
1670 * if this callback is not executing right now,
1673 if (cb->active == 0) {
1674 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
1681 rte_spinlock_unlock(&rte_cryptodev_cb_lock);
1686 rte_cryptodev_pmd_callback_process(struct rte_cryptodev *dev,
1687 enum rte_cryptodev_event_type event)
1689 struct rte_cryptodev_callback *cb_lst;
1690 struct rte_cryptodev_callback dev_cb;
1692 rte_spinlock_lock(&rte_cryptodev_cb_lock);
1693 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
1694 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
1698 rte_spinlock_unlock(&rte_cryptodev_cb_lock);
1699 dev_cb.cb_fn(dev->data->dev_id, dev_cb.event,
1701 rte_spinlock_lock(&rte_cryptodev_cb_lock);
1704 rte_spinlock_unlock(&rte_cryptodev_cb_lock);
1708 rte_cryptodev_sym_session_init(uint8_t dev_id,
1709 struct rte_cryptodev_sym_session *sess,
1710 struct rte_crypto_sym_xform *xforms,
1711 struct rte_mempool *mp)
1713 struct rte_cryptodev *dev;
1714 uint32_t sess_priv_sz = rte_cryptodev_sym_get_private_session_size(
1719 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1720 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
1724 dev = rte_cryptodev_pmd_get_dev(dev_id);
1726 if (sess == NULL || xforms == NULL || dev == NULL || mp == NULL)
1729 if (mp->elt_size < sess_priv_sz)
1732 index = dev->driver_id;
1733 if (index >= sess->nb_drivers)
1736 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->sym_session_configure, -ENOTSUP);
1738 if (sess->sess_data[index].refcnt == 0) {
1739 ret = dev->dev_ops->sym_session_configure(dev, xforms,
1743 "dev_id %d failed to configure session details",
1749 rte_cryptodev_trace_sym_session_init(dev_id, sess, xforms, mp);
1750 sess->sess_data[index].refcnt++;
1755 rte_cryptodev_asym_session_init(uint8_t dev_id,
1756 struct rte_cryptodev_asym_session *sess,
1757 struct rte_crypto_asym_xform *xforms,
1758 struct rte_mempool *mp)
1760 struct rte_cryptodev *dev;
1764 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1765 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
1769 dev = rte_cryptodev_pmd_get_dev(dev_id);
1771 if (sess == NULL || xforms == NULL || dev == NULL)
1774 index = dev->driver_id;
1776 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_configure,
1779 if (sess->sess_private_data[index] == NULL) {
1780 ret = dev->dev_ops->asym_session_configure(dev,
1785 "dev_id %d failed to configure session details",
1791 rte_cryptodev_trace_asym_session_init(dev_id, sess, xforms, mp);
1795 struct rte_mempool *
1796 rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
1797 uint32_t elt_size, uint32_t cache_size, uint16_t user_data_size,
1800 struct rte_mempool *mp;
1801 struct rte_cryptodev_sym_session_pool_private_data *pool_priv;
1804 obj_sz = rte_cryptodev_sym_get_header_session_size() + user_data_size;
1805 if (obj_sz > elt_size)
1806 CDEV_LOG_INFO("elt_size %u is expanded to %u\n", elt_size,
1811 mp = rte_mempool_create(name, nb_elts, obj_sz, cache_size,
1812 (uint32_t)(sizeof(*pool_priv)),
1813 NULL, NULL, NULL, NULL,
1816 CDEV_LOG_ERR("%s(name=%s) failed, rte_errno=%d\n",
1817 __func__, name, rte_errno);
1821 pool_priv = rte_mempool_get_priv(mp);
1823 CDEV_LOG_ERR("%s(name=%s) failed to get private data\n",
1825 rte_mempool_free(mp);
1829 pool_priv->nb_drivers = nb_drivers;
1830 pool_priv->user_data_sz = user_data_size;
1832 rte_cryptodev_trace_sym_session_pool_create(name, nb_elts,
1833 elt_size, cache_size, user_data_size, mp);
1838 rte_cryptodev_sym_session_data_size(struct rte_cryptodev_sym_session *sess)
1840 return (sizeof(sess->sess_data[0]) * sess->nb_drivers) +
1845 rte_cryptodev_sym_is_valid_session_pool(struct rte_mempool *mp)
1847 struct rte_cryptodev_sym_session_pool_private_data *pool_priv;
1852 pool_priv = rte_mempool_get_priv(mp);
1854 if (!pool_priv || mp->private_data_size < sizeof(*pool_priv) ||
1855 pool_priv->nb_drivers != nb_drivers ||
1857 rte_cryptodev_sym_get_header_session_size()
1858 + pool_priv->user_data_sz)
1864 struct rte_cryptodev_sym_session *
1865 rte_cryptodev_sym_session_create(struct rte_mempool *mp)
1867 struct rte_cryptodev_sym_session *sess;
1868 struct rte_cryptodev_sym_session_pool_private_data *pool_priv;
1870 if (!rte_cryptodev_sym_is_valid_session_pool(mp)) {
1871 CDEV_LOG_ERR("Invalid mempool\n");
1875 pool_priv = rte_mempool_get_priv(mp);
1877 /* Allocate a session structure from the session pool */
1878 if (rte_mempool_get(mp, (void **)&sess)) {
1879 CDEV_LOG_ERR("couldn't get object from session mempool");
1883 sess->nb_drivers = pool_priv->nb_drivers;
1884 sess->user_data_sz = pool_priv->user_data_sz;
1885 sess->opaque_data = 0;
1887 /* Clear device session pointer.
1888 * Include the flag indicating presence of user data
1890 memset(sess->sess_data, 0,
1891 rte_cryptodev_sym_session_data_size(sess));
1893 rte_cryptodev_trace_sym_session_create(mp, sess);
1897 struct rte_cryptodev_asym_session *
1898 rte_cryptodev_asym_session_create(struct rte_mempool *mp)
1900 struct rte_cryptodev_asym_session *sess;
1901 unsigned int session_size =
1902 rte_cryptodev_asym_get_header_session_size();
1905 CDEV_LOG_ERR("invalid mempool\n");
1909 /* Verify if provided mempool can hold elements big enough. */
1910 if (mp->elt_size < session_size) {
1912 "mempool elements too small to hold session objects");
1916 /* Allocate a session structure from the session pool */
1917 if (rte_mempool_get(mp, (void **)&sess)) {
1918 CDEV_LOG_ERR("couldn't get object from session mempool");
1922 /* Clear device session pointer.
1923 * Include the flag indicating presence of private data
1925 memset(sess, 0, session_size);
1927 rte_cryptodev_trace_asym_session_create(mp, sess);
1932 rte_cryptodev_sym_session_clear(uint8_t dev_id,
1933 struct rte_cryptodev_sym_session *sess)
1935 struct rte_cryptodev *dev;
1938 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1939 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
1943 dev = rte_cryptodev_pmd_get_dev(dev_id);
1945 if (dev == NULL || sess == NULL)
1948 driver_id = dev->driver_id;
1949 if (sess->sess_data[driver_id].refcnt == 0)
1951 if (--sess->sess_data[driver_id].refcnt != 0)
1954 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->sym_session_clear, -ENOTSUP);
1956 dev->dev_ops->sym_session_clear(dev, sess);
1958 rte_cryptodev_trace_sym_session_clear(dev_id, sess);
1963 rte_cryptodev_asym_session_clear(uint8_t dev_id,
1964 struct rte_cryptodev_asym_session *sess)
1966 struct rte_cryptodev *dev;
1968 if (!rte_cryptodev_is_valid_dev(dev_id)) {
1969 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
1973 dev = rte_cryptodev_pmd_get_dev(dev_id);
1975 if (dev == NULL || sess == NULL)
1978 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_clear, -ENOTSUP);
1980 dev->dev_ops->asym_session_clear(dev, sess);
1982 rte_cryptodev_trace_sym_session_clear(dev_id, sess);
1987 rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess)
1990 struct rte_mempool *sess_mp;
1995 /* Check that all device private data has been freed */
1996 for (i = 0; i < sess->nb_drivers; i++) {
1997 if (sess->sess_data[i].refcnt != 0)
2001 /* Return session to mempool */
2002 sess_mp = rte_mempool_from_obj(sess);
2003 rte_mempool_put(sess_mp, sess);
2005 rte_cryptodev_trace_sym_session_free(sess);
2010 rte_cryptodev_asym_session_free(struct rte_cryptodev_asym_session *sess)
2014 struct rte_mempool *sess_mp;
2019 /* Check that all device private data has been freed */
2020 for (i = 0; i < nb_drivers; i++) {
2021 sess_priv = get_asym_session_private_data(sess, i);
2022 if (sess_priv != NULL)
2026 /* Return session to mempool */
2027 sess_mp = rte_mempool_from_obj(sess);
2028 rte_mempool_put(sess_mp, sess);
2030 rte_cryptodev_trace_asym_session_free(sess);
2035 rte_cryptodev_sym_get_header_session_size(void)
2038 * Header contains pointers to the private data of all registered
2039 * drivers and all necessary information to ensure safely clear
2040 * or free al session.
2042 struct rte_cryptodev_sym_session s = {0};
2044 s.nb_drivers = nb_drivers;
2046 return (unsigned int)(sizeof(s) +
2047 rte_cryptodev_sym_session_data_size(&s));
2051 rte_cryptodev_sym_get_existing_header_session_size(
2052 struct rte_cryptodev_sym_session *sess)
2057 return (unsigned int)(sizeof(*sess) +
2058 rte_cryptodev_sym_session_data_size(sess));
2062 rte_cryptodev_asym_get_header_session_size(void)
2065 * Header contains pointers to the private data
2066 * of all registered drivers, and a flag which
2067 * indicates presence of private data
2069 return ((sizeof(void *) * nb_drivers) + sizeof(uint8_t));
2073 rte_cryptodev_sym_get_private_session_size(uint8_t dev_id)
2075 struct rte_cryptodev *dev;
2076 unsigned int priv_sess_size;
2078 if (!rte_cryptodev_is_valid_dev(dev_id))
2081 dev = rte_cryptodev_pmd_get_dev(dev_id);
2083 if (*dev->dev_ops->sym_session_get_size == NULL)
2086 priv_sess_size = (*dev->dev_ops->sym_session_get_size)(dev);
2088 return priv_sess_size;
2092 rte_cryptodev_asym_get_private_session_size(uint8_t dev_id)
2094 struct rte_cryptodev *dev;
2095 unsigned int header_size = sizeof(void *) * nb_drivers;
2096 unsigned int priv_sess_size;
2098 if (!rte_cryptodev_is_valid_dev(dev_id))
2101 dev = rte_cryptodev_pmd_get_dev(dev_id);
2103 if (*dev->dev_ops->asym_session_get_size == NULL)
2106 priv_sess_size = (*dev->dev_ops->asym_session_get_size)(dev);
2107 if (priv_sess_size < header_size)
2110 return priv_sess_size;
2115 rte_cryptodev_sym_session_set_user_data(
2116 struct rte_cryptodev_sym_session *sess,
2123 if (sess->user_data_sz < size)
2126 rte_memcpy(sess->sess_data + sess->nb_drivers, data, size);
2131 rte_cryptodev_sym_session_get_user_data(
2132 struct rte_cryptodev_sym_session *sess)
2134 if (sess == NULL || sess->user_data_sz == 0)
2137 return (void *)(sess->sess_data + sess->nb_drivers);
2141 sym_crypto_fill_status(struct rte_crypto_sym_vec *vec, int32_t errnum)
2144 for (i = 0; i < vec->num; i++)
2145 vec->status[i] = errnum;
2149 rte_cryptodev_sym_cpu_crypto_process(uint8_t dev_id,
2150 struct rte_cryptodev_sym_session *sess, union rte_crypto_sym_ofs ofs,
2151 struct rte_crypto_sym_vec *vec)
2153 struct rte_cryptodev *dev;
2155 if (!rte_cryptodev_is_valid_dev(dev_id)) {
2156 sym_crypto_fill_status(vec, EINVAL);
2160 dev = rte_cryptodev_pmd_get_dev(dev_id);
2162 if (*dev->dev_ops->sym_cpu_process == NULL ||
2163 !(dev->feature_flags & RTE_CRYPTODEV_FF_SYM_CPU_CRYPTO)) {
2164 sym_crypto_fill_status(vec, ENOTSUP);
2168 return dev->dev_ops->sym_cpu_process(dev, sess, ofs, vec);
2172 rte_cryptodev_get_raw_dp_ctx_size(uint8_t dev_id)
2174 struct rte_cryptodev *dev;
2175 int32_t size = sizeof(struct rte_crypto_raw_dp_ctx);
2178 if (!rte_cryptodev_is_valid_dev(dev_id))
2181 dev = rte_cryptodev_pmd_get_dev(dev_id);
2183 if (*dev->dev_ops->sym_get_raw_dp_ctx_size == NULL ||
2184 !(dev->feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP)) {
2188 priv_size = (*dev->dev_ops->sym_get_raw_dp_ctx_size)(dev);
2192 return RTE_ALIGN_CEIL((size + priv_size), 8);
2196 rte_cryptodev_configure_raw_dp_ctx(uint8_t dev_id, uint16_t qp_id,
2197 struct rte_crypto_raw_dp_ctx *ctx,
2198 enum rte_crypto_op_sess_type sess_type,
2199 union rte_cryptodev_session_ctx session_ctx,
2202 struct rte_cryptodev *dev;
2204 if (!rte_cryptodev_get_qp_status(dev_id, qp_id))
2207 dev = rte_cryptodev_pmd_get_dev(dev_id);
2208 if (!(dev->feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP)
2209 || dev->dev_ops->sym_configure_raw_dp_ctx == NULL)
2212 return (*dev->dev_ops->sym_configure_raw_dp_ctx)(dev, qp_id, ctx,
2213 sess_type, session_ctx, is_update);
2217 rte_cryptodev_raw_enqueue_burst(struct rte_crypto_raw_dp_ctx *ctx,
2218 struct rte_crypto_sym_vec *vec, union rte_crypto_sym_ofs ofs,
2219 void **user_data, int *enqueue_status)
2221 return (*ctx->enqueue_burst)(ctx->qp_data, ctx->drv_ctx_data, vec,
2222 ofs, user_data, enqueue_status);
2226 rte_cryptodev_raw_enqueue_done(struct rte_crypto_raw_dp_ctx *ctx,
2229 return (*ctx->enqueue_done)(ctx->qp_data, ctx->drv_ctx_data, n);
2233 rte_cryptodev_raw_dequeue_burst(struct rte_crypto_raw_dp_ctx *ctx,
2234 rte_cryptodev_raw_get_dequeue_count_t get_dequeue_count,
2235 uint32_t max_nb_to_dequeue,
2236 rte_cryptodev_raw_post_dequeue_t post_dequeue,
2237 void **out_user_data, uint8_t is_user_data_array,
2238 uint32_t *n_success_jobs, int *status)
2240 return (*ctx->dequeue_burst)(ctx->qp_data, ctx->drv_ctx_data,
2241 get_dequeue_count, max_nb_to_dequeue, post_dequeue,
2242 out_user_data, is_user_data_array, n_success_jobs, status);
2246 rte_cryptodev_raw_dequeue_done(struct rte_crypto_raw_dp_ctx *ctx,
2249 return (*ctx->dequeue_done)(ctx->qp_data, ctx->drv_ctx_data, n);
2252 /** Initialise rte_crypto_op mempool element */
2254 rte_crypto_op_init(struct rte_mempool *mempool,
2257 __rte_unused unsigned i)
2259 struct rte_crypto_op *op = _op_data;
2260 enum rte_crypto_op_type type = *(enum rte_crypto_op_type *)opaque_arg;
2262 memset(_op_data, 0, mempool->elt_size);
2264 __rte_crypto_op_reset(op, type);
2266 op->phys_addr = rte_mem_virt2iova(_op_data);
2267 op->mempool = mempool;
2271 struct rte_mempool *
2272 rte_crypto_op_pool_create(const char *name, enum rte_crypto_op_type type,
2273 unsigned nb_elts, unsigned cache_size, uint16_t priv_size,
2276 struct rte_crypto_op_pool_private *priv;
2278 unsigned elt_size = sizeof(struct rte_crypto_op) +
2281 if (type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
2282 elt_size += sizeof(struct rte_crypto_sym_op);
2283 } else if (type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
2284 elt_size += sizeof(struct rte_crypto_asym_op);
2285 } else if (type == RTE_CRYPTO_OP_TYPE_UNDEFINED) {
2286 elt_size += RTE_MAX(sizeof(struct rte_crypto_sym_op),
2287 sizeof(struct rte_crypto_asym_op));
2289 CDEV_LOG_ERR("Invalid op_type\n");
2293 /* lookup mempool in case already allocated */
2294 struct rte_mempool *mp = rte_mempool_lookup(name);
2297 priv = (struct rte_crypto_op_pool_private *)
2298 rte_mempool_get_priv(mp);
2300 if (mp->elt_size != elt_size ||
2301 mp->cache_size < cache_size ||
2302 mp->size < nb_elts ||
2303 priv->priv_size < priv_size) {
2305 CDEV_LOG_ERR("Mempool %s already exists but with "
2306 "incompatible parameters", name);
2312 mp = rte_mempool_create(
2317 sizeof(struct rte_crypto_op_pool_private),
2326 CDEV_LOG_ERR("Failed to create mempool %s", name);
2330 priv = (struct rte_crypto_op_pool_private *)
2331 rte_mempool_get_priv(mp);
2333 priv->priv_size = priv_size;
2340 rte_cryptodev_pmd_create_dev_name(char *name, const char *dev_name_prefix)
2342 struct rte_cryptodev *dev = NULL;
2348 for (i = 0; i < RTE_CRYPTO_MAX_DEVS; i++) {
2349 int ret = snprintf(name, RTE_CRYPTODEV_NAME_MAX_LEN,
2350 "%s_%u", dev_name_prefix, i);
2355 dev = rte_cryptodev_pmd_get_named_dev(name);
2363 TAILQ_HEAD(cryptodev_driver_list, cryptodev_driver);
2365 static struct cryptodev_driver_list cryptodev_driver_list =
2366 TAILQ_HEAD_INITIALIZER(cryptodev_driver_list);
2369 rte_cryptodev_driver_id_get(const char *name)
2371 struct cryptodev_driver *driver;
2372 const char *driver_name;
2375 RTE_LOG(DEBUG, CRYPTODEV, "name pointer NULL");
2379 TAILQ_FOREACH(driver, &cryptodev_driver_list, next) {
2380 driver_name = driver->driver->name;
2381 if (strncmp(driver_name, name, strlen(driver_name) + 1) == 0)
2388 rte_cryptodev_name_get(uint8_t dev_id)
2390 struct rte_cryptodev *dev;
2392 if (!rte_cryptodev_is_valid_device_data(dev_id)) {
2393 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
2397 dev = rte_cryptodev_pmd_get_dev(dev_id);
2401 return dev->data->name;
2405 rte_cryptodev_driver_name_get(uint8_t driver_id)
2407 struct cryptodev_driver *driver;
2409 TAILQ_FOREACH(driver, &cryptodev_driver_list, next)
2410 if (driver->id == driver_id)
2411 return driver->driver->name;
2416 rte_cryptodev_allocate_driver(struct cryptodev_driver *crypto_drv,
2417 const struct rte_driver *drv)
2419 crypto_drv->driver = drv;
2420 crypto_drv->id = nb_drivers;
2422 TAILQ_INSERT_TAIL(&cryptodev_driver_list, crypto_drv, next);
2424 return nb_drivers++;
2427 RTE_INIT(cryptodev_init_fp_ops)
2431 for (i = 0; i != RTE_DIM(rte_crypto_fp_ops); i++)
2432 cryptodev_fp_ops_reset(rte_crypto_fp_ops + i);
2436 cryptodev_handle_dev_list(const char *cmd __rte_unused,
2437 const char *params __rte_unused,
2438 struct rte_tel_data *d)
2442 if (rte_cryptodev_count() < 1)
2445 rte_tel_data_start_array(d, RTE_TEL_INT_VAL);
2446 for (dev_id = 0; dev_id < RTE_CRYPTO_MAX_DEVS; dev_id++)
2447 if (rte_cryptodev_is_valid_dev(dev_id))
2448 rte_tel_data_add_array_int(d, dev_id);
2454 cryptodev_handle_dev_info(const char *cmd __rte_unused,
2455 const char *params, struct rte_tel_data *d)
2457 struct rte_cryptodev_info cryptodev_info;
2461 if (params == NULL || strlen(params) == 0 || !isdigit(*params))
2464 dev_id = strtoul(params, &end_param, 0);
2465 if (*end_param != '\0')
2466 CDEV_LOG_ERR("Extra parameters passed to command, ignoring");
2467 if (!rte_cryptodev_is_valid_dev(dev_id))
2470 rte_cryptodev_info_get(dev_id, &cryptodev_info);
2472 rte_tel_data_start_dict(d);
2473 rte_tel_data_add_dict_string(d, "device_name",
2474 cryptodev_info.device->name);
2475 rte_tel_data_add_dict_int(d, "max_nb_queue_pairs",
2476 cryptodev_info.max_nb_queue_pairs);
2481 #define ADD_DICT_STAT(s) rte_tel_data_add_dict_u64(d, #s, cryptodev_stats.s)
2484 cryptodev_handle_dev_stats(const char *cmd __rte_unused,
2486 struct rte_tel_data *d)
2488 struct rte_cryptodev_stats cryptodev_stats;
2492 if (params == NULL || strlen(params) == 0 || !isdigit(*params))
2495 dev_id = strtoul(params, &end_param, 0);
2496 if (*end_param != '\0')
2497 CDEV_LOG_ERR("Extra parameters passed to command, ignoring");
2498 if (!rte_cryptodev_is_valid_dev(dev_id))
2501 ret = rte_cryptodev_stats_get(dev_id, &cryptodev_stats);
2505 rte_tel_data_start_dict(d);
2506 ADD_DICT_STAT(enqueued_count);
2507 ADD_DICT_STAT(dequeued_count);
2508 ADD_DICT_STAT(enqueue_err_count);
2509 ADD_DICT_STAT(dequeue_err_count);
2514 #define CRYPTO_CAPS_SZ \
2515 (RTE_ALIGN_CEIL(sizeof(struct rte_cryptodev_capabilities), \
2516 sizeof(uint64_t)) / \
2520 crypto_caps_array(struct rte_tel_data *d,
2521 const struct rte_cryptodev_capabilities *capabilities)
2523 const struct rte_cryptodev_capabilities *dev_caps;
2524 uint64_t caps_val[CRYPTO_CAPS_SZ];
2525 unsigned int i = 0, j;
2527 rte_tel_data_start_array(d, RTE_TEL_U64_VAL);
2529 while ((dev_caps = &capabilities[i++])->op !=
2530 RTE_CRYPTO_OP_TYPE_UNDEFINED) {
2531 memset(&caps_val, 0, CRYPTO_CAPS_SZ * sizeof(caps_val[0]));
2532 rte_memcpy(caps_val, dev_caps, sizeof(capabilities[0]));
2533 for (j = 0; j < CRYPTO_CAPS_SZ; j++)
2534 rte_tel_data_add_array_u64(d, caps_val[j]);
2541 cryptodev_handle_dev_caps(const char *cmd __rte_unused, const char *params,
2542 struct rte_tel_data *d)
2544 struct rte_cryptodev_info dev_info;
2545 struct rte_tel_data *crypto_caps;
2550 if (!params || strlen(params) == 0 || !isdigit(*params))
2553 dev_id = strtoul(params, &end_param, 0);
2554 if (*end_param != '\0')
2555 CDEV_LOG_ERR("Extra parameters passed to command, ignoring");
2556 if (!rte_cryptodev_is_valid_dev(dev_id))
2559 rte_tel_data_start_dict(d);
2560 crypto_caps = rte_tel_data_alloc();
2564 rte_cryptodev_info_get(dev_id, &dev_info);
2565 crypto_caps_n = crypto_caps_array(crypto_caps, dev_info.capabilities);
2566 rte_tel_data_add_dict_container(d, "crypto_caps", crypto_caps, 0);
2567 rte_tel_data_add_dict_int(d, "crypto_caps_n", crypto_caps_n);
2572 RTE_INIT(cryptodev_init_telemetry)
2574 rte_telemetry_register_cmd("/cryptodev/info", cryptodev_handle_dev_info,
2575 "Returns information for a cryptodev. Parameters: int dev_id");
2576 rte_telemetry_register_cmd("/cryptodev/list",
2577 cryptodev_handle_dev_list,
2578 "Returns list of available crypto devices by IDs. No parameters.");
2579 rte_telemetry_register_cmd("/cryptodev/stats",
2580 cryptodev_handle_dev_stats,
2581 "Returns the stats for a cryptodev. Parameters: int dev_id");
2582 rte_telemetry_register_cmd("/cryptodev/caps",
2583 cryptodev_handle_dev_caps,
2584 "Returns the capabilities for a cryptodev. Parameters: int dev_id");