1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2020 Intel Corporation
15 #include <netinet/in.h>
17 #include <rte_byteorder.h>
19 #include <rte_debug.h>
21 #include <rte_interrupts.h>
22 #include <rte_memory.h>
23 #include <rte_memcpy.h>
24 #include <rte_memzone.h>
25 #include <rte_launch.h>
26 #include <rte_tailq.h>
28 #include <rte_per_lcore.h>
29 #include <rte_lcore.h>
30 #include <rte_atomic.h>
31 #include <rte_branch_prediction.h>
32 #include <rte_common.h>
33 #include <rte_mempool.h>
34 #include <rte_malloc.h>
36 #include <rte_errno.h>
37 #include <rte_spinlock.h>
38 #include <rte_string_fns.h>
40 #include "rte_crypto.h"
41 #include "rte_cryptodev.h"
42 #include "rte_cryptodev_pmd.h"
44 static uint8_t nb_drivers;
46 static struct rte_cryptodev rte_crypto_devices[RTE_CRYPTO_MAX_DEVS];
48 struct rte_cryptodev *rte_cryptodevs = rte_crypto_devices;
50 static struct rte_cryptodev_global cryptodev_globals = {
51 .devs = rte_crypto_devices,
56 /* spinlock for crypto device callbacks */
57 static rte_spinlock_t rte_cryptodev_cb_lock = RTE_SPINLOCK_INITIALIZER;
61 * The user application callback description.
63 * It contains callback address to be registered by user application,
64 * the pointer to the parameters for callback, and the event type.
66 struct rte_cryptodev_callback {
67 TAILQ_ENTRY(rte_cryptodev_callback) next; /**< Callbacks list */
68 rte_cryptodev_cb_fn cb_fn; /**< Callback address */
69 void *cb_arg; /**< Parameter for callback */
70 enum rte_cryptodev_event_type event; /**< Interrupt event type */
71 uint32_t active; /**< Callback is executing */
75 * The crypto cipher algorithm strings identifiers.
76 * It could be used in application command line.
79 rte_crypto_cipher_algorithm_strings[] = {
80 [RTE_CRYPTO_CIPHER_3DES_CBC] = "3des-cbc",
81 [RTE_CRYPTO_CIPHER_3DES_ECB] = "3des-ecb",
82 [RTE_CRYPTO_CIPHER_3DES_CTR] = "3des-ctr",
84 [RTE_CRYPTO_CIPHER_AES_CBC] = "aes-cbc",
85 [RTE_CRYPTO_CIPHER_AES_CTR] = "aes-ctr",
86 [RTE_CRYPTO_CIPHER_AES_DOCSISBPI] = "aes-docsisbpi",
87 [RTE_CRYPTO_CIPHER_AES_ECB] = "aes-ecb",
88 [RTE_CRYPTO_CIPHER_AES_F8] = "aes-f8",
89 [RTE_CRYPTO_CIPHER_AES_XTS] = "aes-xts",
91 [RTE_CRYPTO_CIPHER_ARC4] = "arc4",
93 [RTE_CRYPTO_CIPHER_DES_CBC] = "des-cbc",
94 [RTE_CRYPTO_CIPHER_DES_DOCSISBPI] = "des-docsisbpi",
96 [RTE_CRYPTO_CIPHER_NULL] = "null",
98 [RTE_CRYPTO_CIPHER_KASUMI_F8] = "kasumi-f8",
99 [RTE_CRYPTO_CIPHER_SNOW3G_UEA2] = "snow3g-uea2",
100 [RTE_CRYPTO_CIPHER_ZUC_EEA3] = "zuc-eea3"
104 * The crypto cipher operation strings identifiers.
105 * It could be used in application command line.
108 rte_crypto_cipher_operation_strings[] = {
109 [RTE_CRYPTO_CIPHER_OP_ENCRYPT] = "encrypt",
110 [RTE_CRYPTO_CIPHER_OP_DECRYPT] = "decrypt"
114 * The crypto auth algorithm strings identifiers.
115 * It could be used in application command line.
118 rte_crypto_auth_algorithm_strings[] = {
119 [RTE_CRYPTO_AUTH_AES_CBC_MAC] = "aes-cbc-mac",
120 [RTE_CRYPTO_AUTH_AES_CMAC] = "aes-cmac",
121 [RTE_CRYPTO_AUTH_AES_GMAC] = "aes-gmac",
122 [RTE_CRYPTO_AUTH_AES_XCBC_MAC] = "aes-xcbc-mac",
124 [RTE_CRYPTO_AUTH_MD5] = "md5",
125 [RTE_CRYPTO_AUTH_MD5_HMAC] = "md5-hmac",
127 [RTE_CRYPTO_AUTH_NULL] = "null",
129 [RTE_CRYPTO_AUTH_SHA1] = "sha1",
130 [RTE_CRYPTO_AUTH_SHA1_HMAC] = "sha1-hmac",
132 [RTE_CRYPTO_AUTH_SHA224] = "sha2-224",
133 [RTE_CRYPTO_AUTH_SHA224_HMAC] = "sha2-224-hmac",
134 [RTE_CRYPTO_AUTH_SHA256] = "sha2-256",
135 [RTE_CRYPTO_AUTH_SHA256_HMAC] = "sha2-256-hmac",
136 [RTE_CRYPTO_AUTH_SHA384] = "sha2-384",
137 [RTE_CRYPTO_AUTH_SHA384_HMAC] = "sha2-384-hmac",
138 [RTE_CRYPTO_AUTH_SHA512] = "sha2-512",
139 [RTE_CRYPTO_AUTH_SHA512_HMAC] = "sha2-512-hmac",
141 [RTE_CRYPTO_AUTH_KASUMI_F9] = "kasumi-f9",
142 [RTE_CRYPTO_AUTH_SNOW3G_UIA2] = "snow3g-uia2",
143 [RTE_CRYPTO_AUTH_ZUC_EIA3] = "zuc-eia3"
147 * The crypto AEAD algorithm strings identifiers.
148 * It could be used in application command line.
151 rte_crypto_aead_algorithm_strings[] = {
152 [RTE_CRYPTO_AEAD_AES_CCM] = "aes-ccm",
153 [RTE_CRYPTO_AEAD_AES_GCM] = "aes-gcm",
157 * The crypto AEAD operation strings identifiers.
158 * It could be used in application command line.
161 rte_crypto_aead_operation_strings[] = {
162 [RTE_CRYPTO_AEAD_OP_ENCRYPT] = "encrypt",
163 [RTE_CRYPTO_AEAD_OP_DECRYPT] = "decrypt"
167 * Asymmetric crypto transform operation strings identifiers.
169 const char *rte_crypto_asym_xform_strings[] = {
170 [RTE_CRYPTO_ASYM_XFORM_NONE] = "none",
171 [RTE_CRYPTO_ASYM_XFORM_RSA] = "rsa",
172 [RTE_CRYPTO_ASYM_XFORM_MODEX] = "modexp",
173 [RTE_CRYPTO_ASYM_XFORM_MODINV] = "modinv",
174 [RTE_CRYPTO_ASYM_XFORM_DH] = "dh",
175 [RTE_CRYPTO_ASYM_XFORM_DSA] = "dsa",
176 [RTE_CRYPTO_ASYM_XFORM_ECDSA] = "ecdsa",
177 [RTE_CRYPTO_ASYM_XFORM_ECPM] = "ecpm",
181 * Asymmetric crypto operation strings identifiers.
183 const char *rte_crypto_asym_op_strings[] = {
184 [RTE_CRYPTO_ASYM_OP_ENCRYPT] = "encrypt",
185 [RTE_CRYPTO_ASYM_OP_DECRYPT] = "decrypt",
186 [RTE_CRYPTO_ASYM_OP_SIGN] = "sign",
187 [RTE_CRYPTO_ASYM_OP_VERIFY] = "verify",
188 [RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE] = "priv_key_generate",
189 [RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE] = "pub_key_generate",
190 [RTE_CRYPTO_ASYM_OP_SHARED_SECRET_COMPUTE] = "sharedsecret_compute",
194 * The private data structure stored in the session mempool private data.
196 struct rte_cryptodev_sym_session_pool_private_data {
198 /**< number of elements in sess_data array */
199 uint16_t user_data_sz;
200 /**< session user data will be placed after sess_data */
204 rte_cryptodev_get_cipher_algo_enum(enum rte_crypto_cipher_algorithm *algo_enum,
205 const char *algo_string)
209 for (i = 1; i < RTE_DIM(rte_crypto_cipher_algorithm_strings); i++) {
210 if (strcmp(algo_string, rte_crypto_cipher_algorithm_strings[i]) == 0) {
211 *algo_enum = (enum rte_crypto_cipher_algorithm) i;
221 rte_cryptodev_get_auth_algo_enum(enum rte_crypto_auth_algorithm *algo_enum,
222 const char *algo_string)
226 for (i = 1; i < RTE_DIM(rte_crypto_auth_algorithm_strings); i++) {
227 if (strcmp(algo_string, rte_crypto_auth_algorithm_strings[i]) == 0) {
228 *algo_enum = (enum rte_crypto_auth_algorithm) i;
238 rte_cryptodev_get_aead_algo_enum(enum rte_crypto_aead_algorithm *algo_enum,
239 const char *algo_string)
243 for (i = 1; i < RTE_DIM(rte_crypto_aead_algorithm_strings); i++) {
244 if (strcmp(algo_string, rte_crypto_aead_algorithm_strings[i]) == 0) {
245 *algo_enum = (enum rte_crypto_aead_algorithm) i;
255 rte_cryptodev_asym_get_xform_enum(enum rte_crypto_asym_xform_type *xform_enum,
256 const char *xform_string)
260 for (i = 1; i < RTE_DIM(rte_crypto_asym_xform_strings); i++) {
261 if (strcmp(xform_string,
262 rte_crypto_asym_xform_strings[i]) == 0) {
263 *xform_enum = (enum rte_crypto_asym_xform_type) i;
273 * The crypto auth operation strings identifiers.
274 * It could be used in application command line.
277 rte_crypto_auth_operation_strings[] = {
278 [RTE_CRYPTO_AUTH_OP_VERIFY] = "verify",
279 [RTE_CRYPTO_AUTH_OP_GENERATE] = "generate"
282 const struct rte_cryptodev_symmetric_capability *
283 rte_cryptodev_sym_capability_get(uint8_t dev_id,
284 const struct rte_cryptodev_sym_capability_idx *idx)
286 const struct rte_cryptodev_capabilities *capability;
287 struct rte_cryptodev_info dev_info;
290 rte_cryptodev_info_get(dev_id, &dev_info);
292 while ((capability = &dev_info.capabilities[i++])->op !=
293 RTE_CRYPTO_OP_TYPE_UNDEFINED) {
294 if (capability->op != RTE_CRYPTO_OP_TYPE_SYMMETRIC)
297 if (capability->sym.xform_type != idx->type)
300 if (idx->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
301 capability->sym.auth.algo == idx->algo.auth)
302 return &capability->sym;
304 if (idx->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
305 capability->sym.cipher.algo == idx->algo.cipher)
306 return &capability->sym;
308 if (idx->type == RTE_CRYPTO_SYM_XFORM_AEAD &&
309 capability->sym.aead.algo == idx->algo.aead)
310 return &capability->sym;
318 param_range_check(uint16_t size, const struct rte_crypto_param_range *range)
320 unsigned int next_size;
322 /* Check lower/upper bounds */
323 if (size < range->min)
326 if (size > range->max)
329 /* If range is actually only one value, size is correct */
330 if (range->increment == 0)
333 /* Check if value is one of the supported sizes */
334 for (next_size = range->min; next_size <= range->max;
335 next_size += range->increment)
336 if (size == next_size)
342 const struct rte_cryptodev_asymmetric_xform_capability *
343 rte_cryptodev_asym_capability_get(uint8_t dev_id,
344 const struct rte_cryptodev_asym_capability_idx *idx)
346 const struct rte_cryptodev_capabilities *capability;
347 struct rte_cryptodev_info dev_info;
350 memset(&dev_info, 0, sizeof(struct rte_cryptodev_info));
351 rte_cryptodev_info_get(dev_id, &dev_info);
353 while ((capability = &dev_info.capabilities[i++])->op !=
354 RTE_CRYPTO_OP_TYPE_UNDEFINED) {
355 if (capability->op != RTE_CRYPTO_OP_TYPE_ASYMMETRIC)
358 if (capability->asym.xform_capa.xform_type == idx->type)
359 return &capability->asym.xform_capa;
365 rte_cryptodev_sym_capability_check_cipher(
366 const struct rte_cryptodev_symmetric_capability *capability,
367 uint16_t key_size, uint16_t iv_size)
369 if (param_range_check(key_size, &capability->cipher.key_size) != 0)
372 if (param_range_check(iv_size, &capability->cipher.iv_size) != 0)
379 rte_cryptodev_sym_capability_check_auth(
380 const struct rte_cryptodev_symmetric_capability *capability,
381 uint16_t key_size, uint16_t digest_size, uint16_t iv_size)
383 if (param_range_check(key_size, &capability->auth.key_size) != 0)
386 if (param_range_check(digest_size, &capability->auth.digest_size) != 0)
389 if (param_range_check(iv_size, &capability->auth.iv_size) != 0)
396 rte_cryptodev_sym_capability_check_aead(
397 const struct rte_cryptodev_symmetric_capability *capability,
398 uint16_t key_size, uint16_t digest_size, uint16_t aad_size,
401 if (param_range_check(key_size, &capability->aead.key_size) != 0)
404 if (param_range_check(digest_size, &capability->aead.digest_size) != 0)
407 if (param_range_check(aad_size, &capability->aead.aad_size) != 0)
410 if (param_range_check(iv_size, &capability->aead.iv_size) != 0)
416 rte_cryptodev_asym_xform_capability_check_optype(
417 const struct rte_cryptodev_asymmetric_xform_capability *capability,
418 enum rte_crypto_asym_op_type op_type)
420 if (capability->op_types & (1 << op_type))
427 rte_cryptodev_asym_xform_capability_check_modlen(
428 const struct rte_cryptodev_asymmetric_xform_capability *capability,
431 /* no need to check for limits, if min or max = 0 */
432 if (capability->modlen.min != 0) {
433 if (modlen < capability->modlen.min)
437 if (capability->modlen.max != 0) {
438 if (modlen > capability->modlen.max)
442 /* in any case, check if given modlen is module increment */
443 if (capability->modlen.increment != 0) {
444 if (modlen % (capability->modlen.increment))
453 rte_cryptodev_get_feature_name(uint64_t flag)
456 case RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO:
457 return "SYMMETRIC_CRYPTO";
458 case RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO:
459 return "ASYMMETRIC_CRYPTO";
460 case RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING:
461 return "SYM_OPERATION_CHAINING";
462 case RTE_CRYPTODEV_FF_CPU_SSE:
464 case RTE_CRYPTODEV_FF_CPU_AVX:
466 case RTE_CRYPTODEV_FF_CPU_AVX2:
468 case RTE_CRYPTODEV_FF_CPU_AVX512:
470 case RTE_CRYPTODEV_FF_CPU_AESNI:
472 case RTE_CRYPTODEV_FF_HW_ACCELERATED:
473 return "HW_ACCELERATED";
474 case RTE_CRYPTODEV_FF_IN_PLACE_SGL:
475 return "IN_PLACE_SGL";
476 case RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT:
477 return "OOP_SGL_IN_SGL_OUT";
478 case RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT:
479 return "OOP_SGL_IN_LB_OUT";
480 case RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT:
481 return "OOP_LB_IN_SGL_OUT";
482 case RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT:
483 return "OOP_LB_IN_LB_OUT";
484 case RTE_CRYPTODEV_FF_CPU_NEON:
486 case RTE_CRYPTODEV_FF_CPU_ARM_CE:
488 case RTE_CRYPTODEV_FF_SECURITY:
489 return "SECURITY_PROTOCOL";
490 case RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP:
491 return "RSA_PRIV_OP_KEY_EXP";
492 case RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT:
493 return "RSA_PRIV_OP_KEY_QT";
494 case RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED:
495 return "DIGEST_ENCRYPTED";
496 case RTE_CRYPTODEV_FF_SYM_CPU_CRYPTO:
497 return "SYM_CPU_CRYPTO";
503 struct rte_cryptodev *
504 rte_cryptodev_pmd_get_dev(uint8_t dev_id)
506 return &cryptodev_globals.devs[dev_id];
509 struct rte_cryptodev *
510 rte_cryptodev_pmd_get_named_dev(const char *name)
512 struct rte_cryptodev *dev;
518 for (i = 0; i < RTE_CRYPTO_MAX_DEVS; i++) {
519 dev = &cryptodev_globals.devs[i];
521 if ((dev->attached == RTE_CRYPTODEV_ATTACHED) &&
522 (strcmp(dev->data->name, name) == 0))
529 static inline uint8_t
530 rte_cryptodev_is_valid_device_data(uint8_t dev_id)
532 if (rte_crypto_devices[dev_id].data == NULL)
539 rte_cryptodev_pmd_is_valid_dev(uint8_t dev_id)
541 struct rte_cryptodev *dev = NULL;
543 if (!rte_cryptodev_is_valid_device_data(dev_id))
546 dev = rte_cryptodev_pmd_get_dev(dev_id);
547 if (dev->attached != RTE_CRYPTODEV_ATTACHED)
555 rte_cryptodev_get_dev_id(const char *name)
562 for (i = 0; i < RTE_CRYPTO_MAX_DEVS; i++) {
563 if (!rte_cryptodev_is_valid_device_data(i))
565 if ((strcmp(cryptodev_globals.devs[i].data->name, name)
567 (cryptodev_globals.devs[i].attached ==
568 RTE_CRYPTODEV_ATTACHED))
576 rte_cryptodev_count(void)
578 return cryptodev_globals.nb_devs;
582 rte_cryptodev_device_count_by_driver(uint8_t driver_id)
584 uint8_t i, dev_count = 0;
586 for (i = 0; i < RTE_CRYPTO_MAX_DEVS; i++)
587 if (cryptodev_globals.devs[i].driver_id == driver_id &&
588 cryptodev_globals.devs[i].attached ==
589 RTE_CRYPTODEV_ATTACHED)
596 rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
599 uint8_t i, count = 0;
600 struct rte_cryptodev *devs = cryptodev_globals.devs;
602 for (i = 0; i < RTE_CRYPTO_MAX_DEVS && count < nb_devices; i++) {
603 if (!rte_cryptodev_is_valid_device_data(i))
606 if (devs[i].attached == RTE_CRYPTODEV_ATTACHED) {
609 cmp = strncmp(devs[i].device->driver->name,
611 strlen(driver_name) + 1);
614 devices[count++] = devs[i].data->dev_id;
622 rte_cryptodev_get_sec_ctx(uint8_t dev_id)
624 if (rte_crypto_devices[dev_id].feature_flags &
625 RTE_CRYPTODEV_FF_SECURITY)
626 return rte_crypto_devices[dev_id].security_ctx;
632 rte_cryptodev_socket_id(uint8_t dev_id)
634 struct rte_cryptodev *dev;
636 if (!rte_cryptodev_pmd_is_valid_dev(dev_id))
639 dev = rte_cryptodev_pmd_get_dev(dev_id);
641 return dev->data->socket_id;
645 rte_cryptodev_data_alloc(uint8_t dev_id, struct rte_cryptodev_data **data,
648 char mz_name[RTE_MEMZONE_NAMESIZE];
649 const struct rte_memzone *mz;
652 /* generate memzone name */
653 n = snprintf(mz_name, sizeof(mz_name), "rte_cryptodev_data_%u", dev_id);
654 if (n >= (int)sizeof(mz_name))
657 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
658 mz = rte_memzone_reserve(mz_name,
659 sizeof(struct rte_cryptodev_data),
662 mz = rte_memzone_lookup(mz_name);
668 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
669 memset(*data, 0, sizeof(struct rte_cryptodev_data));
675 rte_cryptodev_data_free(uint8_t dev_id, struct rte_cryptodev_data **data)
677 char mz_name[RTE_MEMZONE_NAMESIZE];
678 const struct rte_memzone *mz;
681 /* generate memzone name */
682 n = snprintf(mz_name, sizeof(mz_name), "rte_cryptodev_data_%u", dev_id);
683 if (n >= (int)sizeof(mz_name))
686 mz = rte_memzone_lookup(mz_name);
690 RTE_ASSERT(*data == mz->addr);
693 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
694 return rte_memzone_free(mz);
700 rte_cryptodev_find_free_device_index(void)
704 for (dev_id = 0; dev_id < RTE_CRYPTO_MAX_DEVS; dev_id++) {
705 if (rte_crypto_devices[dev_id].attached ==
706 RTE_CRYPTODEV_DETACHED)
709 return RTE_CRYPTO_MAX_DEVS;
712 struct rte_cryptodev *
713 rte_cryptodev_pmd_allocate(const char *name, int socket_id)
715 struct rte_cryptodev *cryptodev;
718 if (rte_cryptodev_pmd_get_named_dev(name) != NULL) {
719 CDEV_LOG_ERR("Crypto device with name %s already "
724 dev_id = rte_cryptodev_find_free_device_index();
725 if (dev_id == RTE_CRYPTO_MAX_DEVS) {
726 CDEV_LOG_ERR("Reached maximum number of crypto devices");
730 cryptodev = rte_cryptodev_pmd_get_dev(dev_id);
732 if (cryptodev->data == NULL) {
733 struct rte_cryptodev_data **cryptodev_data =
734 &cryptodev_globals.data[dev_id];
736 int retval = rte_cryptodev_data_alloc(dev_id, cryptodev_data,
739 if (retval < 0 || *cryptodev_data == NULL)
742 cryptodev->data = *cryptodev_data;
744 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
745 strlcpy(cryptodev->data->name, name,
746 RTE_CRYPTODEV_NAME_MAX_LEN);
748 cryptodev->data->dev_id = dev_id;
749 cryptodev->data->socket_id = socket_id;
750 cryptodev->data->dev_started = 0;
753 /* init user callbacks */
754 TAILQ_INIT(&(cryptodev->link_intr_cbs));
756 cryptodev->attached = RTE_CRYPTODEV_ATTACHED;
758 cryptodev_globals.nb_devs++;
765 rte_cryptodev_pmd_release_device(struct rte_cryptodev *cryptodev)
770 if (cryptodev == NULL)
773 dev_id = cryptodev->data->dev_id;
775 /* Close device only if device operations have been set */
776 if (cryptodev->dev_ops) {
777 ret = rte_cryptodev_close(dev_id);
782 ret = rte_cryptodev_data_free(dev_id, &cryptodev_globals.data[dev_id]);
786 cryptodev->attached = RTE_CRYPTODEV_DETACHED;
787 cryptodev_globals.nb_devs--;
792 rte_cryptodev_queue_pair_count(uint8_t dev_id)
794 struct rte_cryptodev *dev;
796 dev = &rte_crypto_devices[dev_id];
797 return dev->data->nb_queue_pairs;
801 rte_cryptodev_queue_pairs_config(struct rte_cryptodev *dev, uint16_t nb_qpairs,
804 struct rte_cryptodev_info dev_info;
808 if ((dev == NULL) || (nb_qpairs < 1)) {
809 CDEV_LOG_ERR("invalid param: dev %p, nb_queues %u",
814 CDEV_LOG_DEBUG("Setup %d queues pairs on device %u",
815 nb_qpairs, dev->data->dev_id);
817 memset(&dev_info, 0, sizeof(struct rte_cryptodev_info));
819 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
820 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
822 if (nb_qpairs > (dev_info.max_nb_queue_pairs)) {
823 CDEV_LOG_ERR("Invalid num queue_pairs (%u) for dev %u",
824 nb_qpairs, dev->data->dev_id);
828 if (dev->data->queue_pairs == NULL) { /* first time configuration */
829 dev->data->queue_pairs = rte_zmalloc_socket(
830 "cryptodev->queue_pairs",
831 sizeof(dev->data->queue_pairs[0]) * nb_qpairs,
832 RTE_CACHE_LINE_SIZE, socket_id);
834 if (dev->data->queue_pairs == NULL) {
835 dev->data->nb_queue_pairs = 0;
836 CDEV_LOG_ERR("failed to get memory for qp meta data, "
841 } else { /* re-configure */
843 uint16_t old_nb_queues = dev->data->nb_queue_pairs;
845 qp = dev->data->queue_pairs;
847 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_pair_release,
850 for (i = nb_qpairs; i < old_nb_queues; i++) {
851 ret = (*dev->dev_ops->queue_pair_release)(dev, i);
856 qp = rte_realloc(qp, sizeof(qp[0]) * nb_qpairs,
857 RTE_CACHE_LINE_SIZE);
859 CDEV_LOG_ERR("failed to realloc qp meta data,"
860 " nb_queues %u", nb_qpairs);
864 if (nb_qpairs > old_nb_queues) {
865 uint16_t new_qs = nb_qpairs - old_nb_queues;
867 memset(qp + old_nb_queues, 0,
868 sizeof(qp[0]) * new_qs);
871 dev->data->queue_pairs = qp;
874 dev->data->nb_queue_pairs = nb_qpairs;
879 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config)
881 struct rte_cryptodev *dev;
884 if (!rte_cryptodev_pmd_is_valid_dev(dev_id)) {
885 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
889 dev = &rte_crypto_devices[dev_id];
891 if (dev->data->dev_started) {
893 "device %d must be stopped to allow configuration", dev_id);
897 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
899 /* Setup new number of queue pairs and reconfigure device. */
900 diag = rte_cryptodev_queue_pairs_config(dev, config->nb_queue_pairs,
903 CDEV_LOG_ERR("dev%d rte_crypto_dev_queue_pairs_config = %d",
908 return (*dev->dev_ops->dev_configure)(dev, config);
913 rte_cryptodev_start(uint8_t dev_id)
915 struct rte_cryptodev *dev;
918 CDEV_LOG_DEBUG("Start dev_id=%" PRIu8, dev_id);
920 if (!rte_cryptodev_pmd_is_valid_dev(dev_id)) {
921 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
925 dev = &rte_crypto_devices[dev_id];
927 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
929 if (dev->data->dev_started != 0) {
930 CDEV_LOG_ERR("Device with dev_id=%" PRIu8 " already started",
935 diag = (*dev->dev_ops->dev_start)(dev);
937 dev->data->dev_started = 1;
945 rte_cryptodev_stop(uint8_t dev_id)
947 struct rte_cryptodev *dev;
949 if (!rte_cryptodev_pmd_is_valid_dev(dev_id)) {
950 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
954 dev = &rte_crypto_devices[dev_id];
956 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
958 if (dev->data->dev_started == 0) {
959 CDEV_LOG_ERR("Device with dev_id=%" PRIu8 " already stopped",
964 (*dev->dev_ops->dev_stop)(dev);
965 dev->data->dev_started = 0;
969 rte_cryptodev_close(uint8_t dev_id)
971 struct rte_cryptodev *dev;
974 if (!rte_cryptodev_pmd_is_valid_dev(dev_id)) {
975 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
979 dev = &rte_crypto_devices[dev_id];
981 /* Device must be stopped before it can be closed */
982 if (dev->data->dev_started == 1) {
983 CDEV_LOG_ERR("Device %u must be stopped before closing",
988 /* We can't close the device if there are outstanding sessions in use */
989 if (dev->data->session_pool != NULL) {
990 if (!rte_mempool_full(dev->data->session_pool)) {
991 CDEV_LOG_ERR("dev_id=%u close failed, session mempool "
992 "has sessions still in use, free "
993 "all sessions before calling close",
999 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_close, -ENOTSUP);
1000 retval = (*dev->dev_ops->dev_close)(dev);
1009 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
1010 const struct rte_cryptodev_qp_conf *qp_conf, int socket_id)
1013 struct rte_cryptodev *dev;
1015 if (!rte_cryptodev_pmd_is_valid_dev(dev_id)) {
1016 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
1020 dev = &rte_crypto_devices[dev_id];
1021 if (queue_pair_id >= dev->data->nb_queue_pairs) {
1022 CDEV_LOG_ERR("Invalid queue_pair_id=%d", queue_pair_id);
1027 CDEV_LOG_ERR("qp_conf cannot be NULL\n");
1031 if ((qp_conf->mp_session && !qp_conf->mp_session_private) ||
1032 (!qp_conf->mp_session && qp_conf->mp_session_private)) {
1033 CDEV_LOG_ERR("Invalid mempools\n");
1037 if (qp_conf->mp_session) {
1038 struct rte_cryptodev_sym_session_pool_private_data *pool_priv;
1039 uint32_t obj_size = qp_conf->mp_session->elt_size;
1040 uint32_t obj_priv_size = qp_conf->mp_session_private->elt_size;
1041 struct rte_cryptodev_sym_session s = {0};
1043 pool_priv = rte_mempool_get_priv(qp_conf->mp_session);
1044 if (!pool_priv || qp_conf->mp_session->private_data_size <
1045 sizeof(*pool_priv)) {
1046 CDEV_LOG_ERR("Invalid mempool\n");
1050 s.nb_drivers = pool_priv->nb_drivers;
1051 s.user_data_sz = pool_priv->user_data_sz;
1053 if ((rte_cryptodev_sym_get_existing_header_session_size(&s) >
1054 obj_size) || (s.nb_drivers <= dev->driver_id) ||
1055 rte_cryptodev_sym_get_private_session_size(dev_id) >
1057 CDEV_LOG_ERR("Invalid mempool\n");
1062 if (dev->data->dev_started) {
1064 "device %d must be stopped to allow configuration", dev_id);
1068 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_pair_setup, -ENOTSUP);
1070 return (*dev->dev_ops->queue_pair_setup)(dev, queue_pair_id, qp_conf,
1076 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats)
1078 struct rte_cryptodev *dev;
1080 if (!rte_cryptodev_pmd_is_valid_dev(dev_id)) {
1081 CDEV_LOG_ERR("Invalid dev_id=%d", dev_id);
1085 if (stats == NULL) {
1086 CDEV_LOG_ERR("Invalid stats ptr");
1090 dev = &rte_crypto_devices[dev_id];
1091 memset(stats, 0, sizeof(*stats));
1093 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1094 (*dev->dev_ops->stats_get)(dev, stats);
1099 rte_cryptodev_stats_reset(uint8_t dev_id)
1101 struct rte_cryptodev *dev;
1103 if (!rte_cryptodev_pmd_is_valid_dev(dev_id)) {
1104 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
1108 dev = &rte_crypto_devices[dev_id];
1110 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1111 (*dev->dev_ops->stats_reset)(dev);
1116 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info)
1118 struct rte_cryptodev *dev;
1120 if (!rte_cryptodev_pmd_is_valid_dev(dev_id)) {
1121 CDEV_LOG_ERR("Invalid dev_id=%d", dev_id);
1125 dev = &rte_crypto_devices[dev_id];
1127 memset(dev_info, 0, sizeof(struct rte_cryptodev_info));
1129 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1130 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1132 dev_info->driver_name = dev->device->driver->name;
1133 dev_info->device = dev->device;
1138 rte_cryptodev_callback_register(uint8_t dev_id,
1139 enum rte_cryptodev_event_type event,
1140 rte_cryptodev_cb_fn cb_fn, void *cb_arg)
1142 struct rte_cryptodev *dev;
1143 struct rte_cryptodev_callback *user_cb;
1148 if (!rte_cryptodev_pmd_is_valid_dev(dev_id)) {
1149 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
1153 dev = &rte_crypto_devices[dev_id];
1154 rte_spinlock_lock(&rte_cryptodev_cb_lock);
1156 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
1157 if (user_cb->cb_fn == cb_fn &&
1158 user_cb->cb_arg == cb_arg &&
1159 user_cb->event == event) {
1164 /* create a new callback. */
1165 if (user_cb == NULL) {
1166 user_cb = rte_zmalloc("INTR_USER_CALLBACK",
1167 sizeof(struct rte_cryptodev_callback), 0);
1168 if (user_cb != NULL) {
1169 user_cb->cb_fn = cb_fn;
1170 user_cb->cb_arg = cb_arg;
1171 user_cb->event = event;
1172 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
1176 rte_spinlock_unlock(&rte_cryptodev_cb_lock);
1177 return (user_cb == NULL) ? -ENOMEM : 0;
1181 rte_cryptodev_callback_unregister(uint8_t dev_id,
1182 enum rte_cryptodev_event_type event,
1183 rte_cryptodev_cb_fn cb_fn, void *cb_arg)
1186 struct rte_cryptodev *dev;
1187 struct rte_cryptodev_callback *cb, *next;
1192 if (!rte_cryptodev_pmd_is_valid_dev(dev_id)) {
1193 CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
1197 dev = &rte_crypto_devices[dev_id];
1198 rte_spinlock_lock(&rte_cryptodev_cb_lock);
1201 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
1203 next = TAILQ_NEXT(cb, next);
1205 if (cb->cb_fn != cb_fn || cb->event != event ||
1206 (cb->cb_arg != (void *)-1 &&
1207 cb->cb_arg != cb_arg))
1211 * if this callback is not executing right now,
1214 if (cb->active == 0) {
1215 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
1222 rte_spinlock_unlock(&rte_cryptodev_cb_lock);
1227 rte_cryptodev_pmd_callback_process(struct rte_cryptodev *dev,
1228 enum rte_cryptodev_event_type event)
1230 struct rte_cryptodev_callback *cb_lst;
1231 struct rte_cryptodev_callback dev_cb;
1233 rte_spinlock_lock(&rte_cryptodev_cb_lock);
1234 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
1235 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
1239 rte_spinlock_unlock(&rte_cryptodev_cb_lock);
1240 dev_cb.cb_fn(dev->data->dev_id, dev_cb.event,
1242 rte_spinlock_lock(&rte_cryptodev_cb_lock);
1245 rte_spinlock_unlock(&rte_cryptodev_cb_lock);
1250 rte_cryptodev_sym_session_init(uint8_t dev_id,
1251 struct rte_cryptodev_sym_session *sess,
1252 struct rte_crypto_sym_xform *xforms,
1253 struct rte_mempool *mp)
1255 struct rte_cryptodev *dev;
1256 uint32_t sess_priv_sz = rte_cryptodev_sym_get_private_session_size(
1261 dev = rte_cryptodev_pmd_get_dev(dev_id);
1263 if (sess == NULL || xforms == NULL || dev == NULL)
1266 if (mp->elt_size < sess_priv_sz)
1269 index = dev->driver_id;
1270 if (index >= sess->nb_drivers)
1273 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->sym_session_configure, -ENOTSUP);
1275 if (sess->sess_data[index].refcnt == 0) {
1276 ret = dev->dev_ops->sym_session_configure(dev, xforms,
1280 "dev_id %d failed to configure session details",
1286 sess->sess_data[index].refcnt++;
1291 rte_cryptodev_asym_session_init(uint8_t dev_id,
1292 struct rte_cryptodev_asym_session *sess,
1293 struct rte_crypto_asym_xform *xforms,
1294 struct rte_mempool *mp)
1296 struct rte_cryptodev *dev;
1300 dev = rte_cryptodev_pmd_get_dev(dev_id);
1302 if (sess == NULL || xforms == NULL || dev == NULL)
1305 index = dev->driver_id;
1307 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_configure,
1310 if (sess->sess_private_data[index] == NULL) {
1311 ret = dev->dev_ops->asym_session_configure(dev,
1316 "dev_id %d failed to configure session details",
1325 struct rte_mempool *
1326 rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
1327 uint32_t elt_size, uint32_t cache_size, uint16_t user_data_size,
1330 struct rte_mempool *mp;
1331 struct rte_cryptodev_sym_session_pool_private_data *pool_priv;
1334 obj_sz = rte_cryptodev_sym_get_header_session_size() + user_data_size;
1335 if (obj_sz > elt_size)
1336 CDEV_LOG_INFO("elt_size %u is expanded to %u\n", elt_size,
1341 mp = rte_mempool_create(name, nb_elts, obj_sz, cache_size,
1342 (uint32_t)(sizeof(*pool_priv)),
1343 NULL, NULL, NULL, NULL,
1346 CDEV_LOG_ERR("%s(name=%s) failed, rte_errno=%d\n",
1347 __func__, name, rte_errno);
1351 pool_priv = rte_mempool_get_priv(mp);
1353 CDEV_LOG_ERR("%s(name=%s) failed to get private data\n",
1355 rte_mempool_free(mp);
1359 pool_priv->nb_drivers = nb_drivers;
1360 pool_priv->user_data_sz = user_data_size;
1366 rte_cryptodev_sym_session_data_size(struct rte_cryptodev_sym_session *sess)
1368 return (sizeof(sess->sess_data[0]) * sess->nb_drivers) +
1372 struct rte_cryptodev_sym_session *
1373 rte_cryptodev_sym_session_create(struct rte_mempool *mp)
1375 struct rte_cryptodev_sym_session *sess;
1376 struct rte_cryptodev_sym_session_pool_private_data *pool_priv;
1379 CDEV_LOG_ERR("Invalid mempool\n");
1383 pool_priv = rte_mempool_get_priv(mp);
1385 if (!pool_priv || mp->private_data_size < sizeof(*pool_priv)) {
1386 CDEV_LOG_ERR("Invalid mempool\n");
1390 /* Allocate a session structure from the session pool */
1391 if (rte_mempool_get(mp, (void **)&sess)) {
1392 CDEV_LOG_ERR("couldn't get object from session mempool");
1396 sess->nb_drivers = pool_priv->nb_drivers;
1397 sess->user_data_sz = pool_priv->user_data_sz;
1398 sess->opaque_data = 0;
1400 /* Clear device session pointer.
1401 * Include the flag indicating presence of user data
1403 memset(sess->sess_data, 0,
1404 rte_cryptodev_sym_session_data_size(sess));
1409 struct rte_cryptodev_asym_session *
1410 rte_cryptodev_asym_session_create(struct rte_mempool *mp)
1412 struct rte_cryptodev_asym_session *sess;
1414 /* Allocate a session structure from the session pool */
1415 if (rte_mempool_get(mp, (void **)&sess)) {
1416 CDEV_LOG_ERR("couldn't get object from session mempool");
1420 /* Clear device session pointer.
1421 * Include the flag indicating presence of private data
1423 memset(sess, 0, (sizeof(void *) * nb_drivers) + sizeof(uint8_t));
1429 rte_cryptodev_sym_session_clear(uint8_t dev_id,
1430 struct rte_cryptodev_sym_session *sess)
1432 struct rte_cryptodev *dev;
1435 dev = rte_cryptodev_pmd_get_dev(dev_id);
1437 if (dev == NULL || sess == NULL)
1440 driver_id = dev->driver_id;
1441 if (sess->sess_data[driver_id].refcnt == 0)
1443 if (--sess->sess_data[driver_id].refcnt != 0)
1446 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->sym_session_clear, -ENOTSUP);
1448 dev->dev_ops->sym_session_clear(dev, sess);
1454 rte_cryptodev_asym_session_clear(uint8_t dev_id,
1455 struct rte_cryptodev_asym_session *sess)
1457 struct rte_cryptodev *dev;
1459 dev = rte_cryptodev_pmd_get_dev(dev_id);
1461 if (dev == NULL || sess == NULL)
1464 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_clear, -ENOTSUP);
1466 dev->dev_ops->asym_session_clear(dev, sess);
1472 rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess)
1475 struct rte_mempool *sess_mp;
1480 /* Check that all device private data has been freed */
1481 for (i = 0; i < sess->nb_drivers; i++) {
1482 if (sess->sess_data[i].refcnt != 0)
1486 /* Return session to mempool */
1487 sess_mp = rte_mempool_from_obj(sess);
1488 rte_mempool_put(sess_mp, sess);
1494 rte_cryptodev_asym_session_free(struct rte_cryptodev_asym_session *sess)
1498 struct rte_mempool *sess_mp;
1503 /* Check that all device private data has been freed */
1504 for (i = 0; i < nb_drivers; i++) {
1505 sess_priv = get_asym_session_private_data(sess, i);
1506 if (sess_priv != NULL)
1510 /* Return session to mempool */
1511 sess_mp = rte_mempool_from_obj(sess);
1512 rte_mempool_put(sess_mp, sess);
1518 rte_cryptodev_sym_get_header_session_size(void)
1521 * Header contains pointers to the private data of all registered
1522 * drivers and all necessary information to ensure safely clear
1523 * or free al session.
1525 struct rte_cryptodev_sym_session s = {0};
1527 s.nb_drivers = nb_drivers;
1529 return (unsigned int)(sizeof(s) +
1530 rte_cryptodev_sym_session_data_size(&s));
1534 rte_cryptodev_sym_get_existing_header_session_size(
1535 struct rte_cryptodev_sym_session *sess)
1540 return (unsigned int)(sizeof(*sess) +
1541 rte_cryptodev_sym_session_data_size(sess));
1545 rte_cryptodev_asym_get_header_session_size(void)
1548 * Header contains pointers to the private data
1549 * of all registered drivers, and a flag which
1550 * indicates presence of private data
1552 return ((sizeof(void *) * nb_drivers) + sizeof(uint8_t));
1556 rte_cryptodev_sym_get_private_session_size(uint8_t dev_id)
1558 struct rte_cryptodev *dev;
1559 unsigned int priv_sess_size;
1561 if (!rte_cryptodev_pmd_is_valid_dev(dev_id))
1564 dev = rte_cryptodev_pmd_get_dev(dev_id);
1566 if (*dev->dev_ops->sym_session_get_size == NULL)
1569 priv_sess_size = (*dev->dev_ops->sym_session_get_size)(dev);
1571 return priv_sess_size;
1575 rte_cryptodev_asym_get_private_session_size(uint8_t dev_id)
1577 struct rte_cryptodev *dev;
1578 unsigned int header_size = sizeof(void *) * nb_drivers;
1579 unsigned int priv_sess_size;
1581 if (!rte_cryptodev_pmd_is_valid_dev(dev_id))
1584 dev = rte_cryptodev_pmd_get_dev(dev_id);
1586 if (*dev->dev_ops->asym_session_get_size == NULL)
1589 priv_sess_size = (*dev->dev_ops->asym_session_get_size)(dev);
1590 if (priv_sess_size < header_size)
1593 return priv_sess_size;
1598 rte_cryptodev_sym_session_set_user_data(
1599 struct rte_cryptodev_sym_session *sess,
1606 if (sess->user_data_sz < size)
1609 rte_memcpy(sess->sess_data + sess->nb_drivers, data, size);
1614 rte_cryptodev_sym_session_get_user_data(
1615 struct rte_cryptodev_sym_session *sess)
1617 if (sess == NULL || sess->user_data_sz == 0)
1620 return (void *)(sess->sess_data + sess->nb_drivers);
1624 sym_crypto_fill_status(struct rte_crypto_sym_vec *vec, int32_t errnum)
1627 for (i = 0; i < vec->num; i++)
1628 vec->status[i] = errnum;
1632 rte_cryptodev_sym_cpu_crypto_process(uint8_t dev_id,
1633 struct rte_cryptodev_sym_session *sess, union rte_crypto_sym_ofs ofs,
1634 struct rte_crypto_sym_vec *vec)
1636 struct rte_cryptodev *dev;
1638 if (!rte_cryptodev_pmd_is_valid_dev(dev_id)) {
1639 sym_crypto_fill_status(vec, EINVAL);
1643 dev = rte_cryptodev_pmd_get_dev(dev_id);
1645 if (*dev->dev_ops->sym_cpu_process == NULL ||
1646 !(dev->feature_flags & RTE_CRYPTODEV_FF_SYM_CPU_CRYPTO)) {
1647 sym_crypto_fill_status(vec, ENOTSUP);
1651 return dev->dev_ops->sym_cpu_process(dev, sess, ofs, vec);
1654 /** Initialise rte_crypto_op mempool element */
1656 rte_crypto_op_init(struct rte_mempool *mempool,
1659 __rte_unused unsigned i)
1661 struct rte_crypto_op *op = _op_data;
1662 enum rte_crypto_op_type type = *(enum rte_crypto_op_type *)opaque_arg;
1664 memset(_op_data, 0, mempool->elt_size);
1666 __rte_crypto_op_reset(op, type);
1668 op->phys_addr = rte_mem_virt2iova(_op_data);
1669 op->mempool = mempool;
1673 struct rte_mempool *
1674 rte_crypto_op_pool_create(const char *name, enum rte_crypto_op_type type,
1675 unsigned nb_elts, unsigned cache_size, uint16_t priv_size,
1678 struct rte_crypto_op_pool_private *priv;
1680 unsigned elt_size = sizeof(struct rte_crypto_op) +
1683 if (type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
1684 elt_size += sizeof(struct rte_crypto_sym_op);
1685 } else if (type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
1686 elt_size += sizeof(struct rte_crypto_asym_op);
1687 } else if (type == RTE_CRYPTO_OP_TYPE_UNDEFINED) {
1688 elt_size += RTE_MAX(sizeof(struct rte_crypto_sym_op),
1689 sizeof(struct rte_crypto_asym_op));
1691 CDEV_LOG_ERR("Invalid op_type\n");
1695 /* lookup mempool in case already allocated */
1696 struct rte_mempool *mp = rte_mempool_lookup(name);
1699 priv = (struct rte_crypto_op_pool_private *)
1700 rte_mempool_get_priv(mp);
1702 if (mp->elt_size != elt_size ||
1703 mp->cache_size < cache_size ||
1704 mp->size < nb_elts ||
1705 priv->priv_size < priv_size) {
1707 CDEV_LOG_ERR("Mempool %s already exists but with "
1708 "incompatible parameters", name);
1714 mp = rte_mempool_create(
1719 sizeof(struct rte_crypto_op_pool_private),
1728 CDEV_LOG_ERR("Failed to create mempool %s", name);
1732 priv = (struct rte_crypto_op_pool_private *)
1733 rte_mempool_get_priv(mp);
1735 priv->priv_size = priv_size;
1742 rte_cryptodev_pmd_create_dev_name(char *name, const char *dev_name_prefix)
1744 struct rte_cryptodev *dev = NULL;
1750 for (i = 0; i < RTE_CRYPTO_MAX_DEVS; i++) {
1751 int ret = snprintf(name, RTE_CRYPTODEV_NAME_MAX_LEN,
1752 "%s_%u", dev_name_prefix, i);
1757 dev = rte_cryptodev_pmd_get_named_dev(name);
1765 TAILQ_HEAD(cryptodev_driver_list, cryptodev_driver);
1767 static struct cryptodev_driver_list cryptodev_driver_list =
1768 TAILQ_HEAD_INITIALIZER(cryptodev_driver_list);
1771 rte_cryptodev_driver_id_get(const char *name)
1773 struct cryptodev_driver *driver;
1774 const char *driver_name;
1777 RTE_LOG(DEBUG, CRYPTODEV, "name pointer NULL");
1781 TAILQ_FOREACH(driver, &cryptodev_driver_list, next) {
1782 driver_name = driver->driver->name;
1783 if (strncmp(driver_name, name, strlen(driver_name) + 1) == 0)
1790 rte_cryptodev_name_get(uint8_t dev_id)
1792 struct rte_cryptodev *dev = rte_cryptodev_pmd_get_dev(dev_id);
1797 return dev->data->name;
1801 rte_cryptodev_driver_name_get(uint8_t driver_id)
1803 struct cryptodev_driver *driver;
1805 TAILQ_FOREACH(driver, &cryptodev_driver_list, next)
1806 if (driver->id == driver_id)
1807 return driver->driver->name;
1812 rte_cryptodev_allocate_driver(struct cryptodev_driver *crypto_drv,
1813 const struct rte_driver *drv)
1815 crypto_drv->driver = drv;
1816 crypto_drv->id = nb_drivers;
1818 TAILQ_INSERT_TAIL(&cryptodev_driver_list, crypto_drv, next);
1820 return nb_drivers++;