From 168b9e76f9168fa3d2c79b3931215597976111c4 Mon Sep 17 00:00:00 2001 From: Pablo de Lara Date: Tue, 18 Apr 2017 15:34:20 +0100 Subject: [PATCH] drivers/crypto: do not create unique name internally Crypto devices of the same type could be initialized with the same name, since internally this name was suffixed with an index. Since commit ("vdev: make virtual bus use its device struct"), this is not allowed anymore. Therefore, there is no need to create an unique name at device initialization. Signed-off-by: Pablo de Lara Acked-by: Fan Zhang --- drivers/crypto/aesni_gcm/aesni_gcm_pmd.c | 20 +++++++----------- drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c | 20 +++++++----------- drivers/crypto/armv8/rte_armv8_pmd.c | 21 +++++++------------ drivers/crypto/kasumi/rte_kasumi_pmd.c | 18 ++++++---------- drivers/crypto/null/null_crypto_pmd.c | 19 ++++++----------- drivers/crypto/openssl/rte_openssl_pmd.c | 20 +++++++----------- drivers/crypto/scheduler/scheduler_pmd.c | 24 +++++++--------------- drivers/crypto/snow3g/rte_snow3g_pmd.c | 18 ++++++---------- drivers/crypto/zuc/rte_zuc_pmd.c | 20 +++++++----------- 9 files changed, 60 insertions(+), 120 deletions(-) diff --git a/drivers/crypto/aesni_gcm/aesni_gcm_pmd.c b/drivers/crypto/aesni_gcm/aesni_gcm_pmd.c index f4dd1ae0b9..101ef98bfe 100644 --- a/drivers/crypto/aesni_gcm/aesni_gcm_pmd.c +++ b/drivers/crypto/aesni_gcm/aesni_gcm_pmd.c @@ -432,22 +432,16 @@ aesni_gcm_pmd_enqueue_burst(void *queue_pair, static int aesni_gcm_remove(struct rte_vdev_device *vdev); static int -aesni_gcm_create(struct rte_vdev_device *vdev, - struct rte_crypto_vdev_init_params *init_params) +aesni_gcm_create(const char *name, + struct rte_vdev_device *vdev, + struct rte_crypto_vdev_init_params *init_params) { struct rte_cryptodev *dev; struct aesni_gcm_private *internals; - if (init_params->name[0] == '\0') { - int ret = rte_cryptodev_pmd_create_dev_name( - init_params->name, - RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); - - if (ret < 0) { - GCM_LOG_ERR("failed to create unique name"); - return ret; - } - } + if (init_params->name[0] == '\0') + snprintf(init_params->name, sizeof(init_params->name), + "%s", name); /* Check CPU for support for AES instruction set */ if (!rte_cpu_get_flag_enabled(RTE_CPUFLAG_AES)) { @@ -516,7 +510,7 @@ aesni_gcm_probe(struct rte_vdev_device *vdev) RTE_LOG(INFO, PMD, " Max number of sessions = %d\n", init_params.max_nb_sessions); - return aesni_gcm_create(vdev, &init_params); + return aesni_gcm_create(name, vdev, &init_params); } static int diff --git a/drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c b/drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c index 88b691e8ff..45b25c9d59 100644 --- a/drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c +++ b/drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c @@ -672,23 +672,17 @@ aesni_mb_pmd_dequeue_burst(void *queue_pair, struct rte_crypto_op **ops, static int cryptodev_aesni_mb_remove(struct rte_vdev_device *vdev); static int -cryptodev_aesni_mb_create(struct rte_vdev_device *vdev, - struct rte_crypto_vdev_init_params *init_params) +cryptodev_aesni_mb_create(const char *name, + struct rte_vdev_device *vdev, + struct rte_crypto_vdev_init_params *init_params) { struct rte_cryptodev *dev; struct aesni_mb_private *internals; enum aesni_mb_vector_mode vector_mode; - if (init_params->name[0] == '\0') { - int ret = rte_cryptodev_pmd_create_dev_name( - init_params->name, - RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); - - if (ret < 0) { - MB_LOG_ERR("failed to create unique name"); - return ret; - } - } + if (init_params->name[0] == '\0') + snprintf(init_params->name, sizeof(init_params->name), + "%s", name); /* Check CPU for supported vector instruction set */ if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512F)) @@ -783,7 +777,7 @@ cryptodev_aesni_mb_probe(struct rte_vdev_device *vdev) RTE_LOG(INFO, PMD, " Max number of sessions = %d\n", init_params.max_nb_sessions); - return cryptodev_aesni_mb_create(vdev, &init_params); + return cryptodev_aesni_mb_create(name, vdev, &init_params); } static int diff --git a/drivers/crypto/armv8/rte_armv8_pmd.c b/drivers/crypto/armv8/rte_armv8_pmd.c index a8af4a3dfb..3d603a5ac3 100644 --- a/drivers/crypto/armv8/rte_armv8_pmd.c +++ b/drivers/crypto/armv8/rte_armv8_pmd.c @@ -773,12 +773,12 @@ armv8_crypto_pmd_dequeue_burst(void *queue_pair, struct rte_crypto_op **ops, /** Create ARMv8 crypto device */ static int -cryptodev_armv8_crypto_create(struct rte_vdev_device *vdev, - struct rte_crypto_vdev_init_params *init_params) +cryptodev_armv8_crypto_create(const char *name, + struct rte_vdev_device *vdev, + struct rte_crypto_vdev_init_params *init_params) { struct rte_cryptodev *dev; struct armv8_crypto_private *internals; - int ret; /* Check CPU for support for AES instruction set */ if (!rte_cpu_get_flag_enabled(RTE_CPUFLAG_AES)) { @@ -802,16 +802,9 @@ cryptodev_armv8_crypto_create(struct rte_vdev_device *vdev, return -EFAULT; } - if (init_params->name[0] == '\0') { - ret = rte_cryptodev_pmd_create_dev_name( - init_params->name, - RTE_STR(CRYPTODEV_NAME_ARMV8_PMD)); - - if (ret < 0) { - ARMV8_CRYPTO_LOG_ERR("failed to create unique name"); - return ret; - } - } + if (init_params->name[0] == '\0') + snprintf(init_params->name, sizeof(init_params->name), + "%s", name); dev = rte_cryptodev_pmd_virtual_dev_init(init_params->name, sizeof(struct armv8_crypto_private), @@ -880,7 +873,7 @@ cryptodev_armv8_crypto_init(struct rte_vdev_device *vdev) RTE_LOG(INFO, PMD, " Max number of sessions = %d\n", init_params.max_nb_sessions); - return cryptodev_armv8_crypto_create(vdev, &init_params); + return cryptodev_armv8_crypto_create(name, vdev, &init_params); } /** Uninitialise ARMv8 crypto device */ diff --git a/drivers/crypto/kasumi/rte_kasumi_pmd.c b/drivers/crypto/kasumi/rte_kasumi_pmd.c index b4476e8881..9da9e89763 100644 --- a/drivers/crypto/kasumi/rte_kasumi_pmd.c +++ b/drivers/crypto/kasumi/rte_kasumi_pmd.c @@ -551,23 +551,17 @@ kasumi_pmd_dequeue_burst(void *queue_pair, static int cryptodev_kasumi_remove(struct rte_vdev_device *vdev); static int -cryptodev_kasumi_create(struct rte_vdev_device *vdev, +cryptodev_kasumi_create(const char *name, + struct rte_vdev_device *vdev, struct rte_crypto_vdev_init_params *init_params) { struct rte_cryptodev *dev; struct kasumi_private *internals; uint64_t cpu_flags = 0; - if (init_params->name[0] == '\0') { - int ret = rte_cryptodev_pmd_create_dev_name( - init_params->name, - RTE_STR(CRYPTODEV_NAME_KASUMI_PMD)); - - if (ret < 0) { - KASUMI_LOG_ERR("failed to create unique name"); - return ret; - } - } + if (init_params->name[0] == '\0') + snprintf(init_params->name, sizeof(init_params->name), + "%s", name); /* Check CPU for supported vector instruction set */ if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX)) @@ -640,7 +634,7 @@ cryptodev_kasumi_probe(struct rte_vdev_device *vdev) RTE_LOG(INFO, PMD, " Max number of sessions = %d\n", init_params.max_nb_sessions); - return cryptodev_kasumi_create(vdev, &init_params); + return cryptodev_kasumi_create(name, vdev, &init_params); } static int diff --git a/drivers/crypto/null/null_crypto_pmd.c b/drivers/crypto/null/null_crypto_pmd.c index 3d131cae17..023450a311 100644 --- a/drivers/crypto/null/null_crypto_pmd.c +++ b/drivers/crypto/null/null_crypto_pmd.c @@ -165,22 +165,15 @@ static int cryptodev_null_remove(const char *name); /** Create crypto device */ static int -cryptodev_null_create(struct rte_crypto_vdev_init_params *init_params) +cryptodev_null_create(const char *name, + struct rte_crypto_vdev_init_params *init_params) { struct rte_cryptodev *dev; struct null_crypto_private *internals; - if (init_params->name[0] == '\0') { - int ret = rte_cryptodev_pmd_create_dev_name( - init_params->name, - RTE_STR(CRYPTODEV_NAME_NULL_PMD)); - - if (ret < 0) { - NULL_CRYPTO_LOG_ERR("failed to create unique " - "name"); - return ret; - } - } + if (init_params->name[0] == '\0') + snprintf(init_params->name, sizeof(init_params->name), + "%s", name); dev = rte_cryptodev_pmd_virtual_dev_init(init_params->name, sizeof(struct null_crypto_private), @@ -242,7 +235,7 @@ cryptodev_null_probe(struct rte_vdev_device *dev) RTE_LOG(INFO, PMD, " Max number of sessions = %d\n", init_params.max_nb_sessions); - return cryptodev_null_create(&init_params); + return cryptodev_null_create(name, &init_params); } /** Uninitialise null crypto device */ diff --git a/drivers/crypto/openssl/rte_openssl_pmd.c b/drivers/crypto/openssl/rte_openssl_pmd.c index 9deead8efd..f0c5ca3cd4 100644 --- a/drivers/crypto/openssl/rte_openssl_pmd.c +++ b/drivers/crypto/openssl/rte_openssl_pmd.c @@ -1264,22 +1264,16 @@ openssl_pmd_dequeue_burst(void *queue_pair, struct rte_crypto_op **ops, /** Create OPENSSL crypto device */ static int -cryptodev_openssl_create(struct rte_vdev_device *vdev, - struct rte_crypto_vdev_init_params *init_params) +cryptodev_openssl_create(const char *name, + struct rte_vdev_device *vdev, + struct rte_crypto_vdev_init_params *init_params) { struct rte_cryptodev *dev; struct openssl_private *internals; - if (init_params->name[0] == '\0') { - int ret = rte_cryptodev_pmd_create_dev_name( - init_params->name, - RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)); - - if (ret < 0) { - OPENSSL_LOG_ERR("failed to create unique name"); - return ret; - } - } + if (init_params->name[0] == '\0') + snprintf(init_params->name, sizeof(init_params->name), + "%s", name); dev = rte_cryptodev_pmd_virtual_dev_init(init_params->name, sizeof(struct openssl_private), @@ -1347,7 +1341,7 @@ cryptodev_openssl_probe(struct rte_vdev_device *vdev) RTE_LOG(INFO, PMD, " Max number of sessions = %d\n", init_params.max_nb_sessions); - return cryptodev_openssl_create(vdev, &init_params); + return cryptodev_openssl_create(name, vdev, &init_params); } /** Uninitialise OPENSSL crypto device */ diff --git a/drivers/crypto/scheduler/scheduler_pmd.c b/drivers/crypto/scheduler/scheduler_pmd.c index c03f1ca162..dfa21c228f 100644 --- a/drivers/crypto/scheduler/scheduler_pmd.c +++ b/drivers/crypto/scheduler/scheduler_pmd.c @@ -91,27 +91,17 @@ static int cryptodev_scheduler_create(const char *name, struct scheduler_init_params *init_params) { - char crypto_dev_name[RTE_CRYPTODEV_NAME_MAX_LEN] = {0}; struct rte_cryptodev *dev; struct scheduler_ctx *sched_ctx; uint32_t i; int ret; - if (init_params->def_p.name[0] == '\0') { - ret = rte_cryptodev_pmd_create_dev_name( - crypto_dev_name, - RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); + if (init_params->def_p.name[0] == '\0') + snprintf(init_params->def_p.name, + sizeof(init_params->def_p.name), + "%s", name); - if (ret < 0) { - CS_LOG_ERR("failed to create unique name"); - return ret; - } - } else { - strncpy(crypto_dev_name, init_params->def_p.name, - RTE_CRYPTODEV_NAME_MAX_LEN - 1); - } - - dev = rte_cryptodev_pmd_virtual_dev_init(crypto_dev_name, + dev = rte_cryptodev_pmd_virtual_dev_init(init_params->def_p.name, sizeof(struct scheduler_ctx), init_params->def_p.socket_id); if (dev == NULL) { @@ -434,8 +424,8 @@ cryptodev_scheduler_probe(struct rte_vdev_device *vdev) RTE_LOG(INFO, PMD, " User defined name = %s\n", init_params.def_p.name); - return cryptodev_scheduler_create(rte_vdev_device_name(vdev), - &init_params); + return cryptodev_scheduler_create(name, + &init_params); } static struct rte_vdev_driver cryptodev_scheduler_pmd_drv = { diff --git a/drivers/crypto/snow3g/rte_snow3g_pmd.c b/drivers/crypto/snow3g/rte_snow3g_pmd.c index 42b802bcde..960956cab4 100644 --- a/drivers/crypto/snow3g/rte_snow3g_pmd.c +++ b/drivers/crypto/snow3g/rte_snow3g_pmd.c @@ -542,23 +542,17 @@ snow3g_pmd_dequeue_burst(void *queue_pair, static int cryptodev_snow3g_remove(struct rte_vdev_device *vdev); static int -cryptodev_snow3g_create(struct rte_vdev_device *vdev, +cryptodev_snow3g_create(const char *name, + struct rte_vdev_device *vdev, struct rte_crypto_vdev_init_params *init_params) { struct rte_cryptodev *dev; struct snow3g_private *internals; uint64_t cpu_flags = 0; - if (init_params->name[0] == '\0') { - int ret = rte_cryptodev_pmd_create_dev_name( - init_params->name, - RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD)); - - if (ret < 0) { - SNOW3G_LOG_ERR("failed to create unique name"); - return ret; - } - } + if (init_params->name[0] == '\0') + snprintf(init_params->name, sizeof(init_params->name), + "%s", name); /* Check CPU for supported vector instruction set */ if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_SSE4_1)) @@ -629,7 +623,7 @@ cryptodev_snow3g_probe(struct rte_vdev_device *vdev) RTE_LOG(INFO, PMD, " Max number of sessions = %d\n", init_params.max_nb_sessions); - return cryptodev_snow3g_create(vdev, &init_params); + return cryptodev_snow3g_create(name, vdev, &init_params); } static int diff --git a/drivers/crypto/zuc/rte_zuc_pmd.c b/drivers/crypto/zuc/rte_zuc_pmd.c index 22bf8bf583..1020544bfd 100644 --- a/drivers/crypto/zuc/rte_zuc_pmd.c +++ b/drivers/crypto/zuc/rte_zuc_pmd.c @@ -442,23 +442,17 @@ zuc_pmd_dequeue_burst(void *queue_pair, static int cryptodev_zuc_remove(struct rte_vdev_device *vdev); static int -cryptodev_zuc_create(struct rte_vdev_device *vdev, - struct rte_crypto_vdev_init_params *init_params) +cryptodev_zuc_create(const char *name, + struct rte_vdev_device *vdev, + struct rte_crypto_vdev_init_params *init_params) { struct rte_cryptodev *dev; struct zuc_private *internals; uint64_t cpu_flags = 0; - if (init_params->name[0] == '\0') { - int ret = rte_cryptodev_pmd_create_dev_name( - init_params->name, - RTE_STR(CRYPTODEV_NAME_ZUC_PMD)); - - if (ret < 0) { - ZUC_LOG_ERR("failed to create unique name"); - return ret; - } - } + if (init_params->name[0] == '\0') + snprintf(init_params->name, sizeof(init_params->name), + "%s", name); /* Check CPU for supported vector instruction set */ if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_SSE4_1)) @@ -529,7 +523,7 @@ cryptodev_zuc_probe(struct rte_vdev_device *vdev) RTE_LOG(INFO, PMD, " Max number of sessions = %d\n", init_params.max_nb_sessions); - return cryptodev_zuc_create(vdev, &init_params); + return cryptodev_zuc_create(name, vdev, &init_params); } static int -- 2.20.1