drivers/crypto: do not create unique name internally
authorPablo de Lara <pablo.de.lara.guarch@intel.com>
Tue, 18 Apr 2017 14:34:20 +0000 (15:34 +0100)
committerPablo de Lara <pablo.de.lara.guarch@intel.com>
Thu, 20 Apr 2017 09:32:45 +0000 (11:32 +0200)
Crypto devices of the same type could be initialized
with the same name, since internally this name was suffixed
with an index.

Since commit <dda987315ca2> ("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 <pablo.de.lara.guarch@intel.com>
Acked-by: Fan Zhang <roy.fan.zhang@intel.com>
drivers/crypto/aesni_gcm/aesni_gcm_pmd.c
drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c
drivers/crypto/armv8/rte_armv8_pmd.c
drivers/crypto/kasumi/rte_kasumi_pmd.c
drivers/crypto/null/null_crypto_pmd.c
drivers/crypto/openssl/rte_openssl_pmd.c
drivers/crypto/scheduler/scheduler_pmd.c
drivers/crypto/snow3g/rte_snow3g_pmd.c
drivers/crypto/zuc/rte_zuc_pmd.c

index f4dd1ae..101ef98 100644 (file)
@@ -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
index 88b691e..45b25c9 100644 (file)
@@ -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
index a8af4a3..3d603a5 100644 (file)
@@ -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 */
index b4476e8..9da9e89 100644 (file)
@@ -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
index 3d131ca..023450a 100644 (file)
@@ -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 */
index 9deead8..f0c5ca3 100644 (file)
@@ -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 */
index c03f1ca..dfa21c2 100644 (file)
@@ -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 = {
index 42b802b..960956c 100644 (file)
@@ -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
index 22bf8bf..1020544 100644 (file)
@@ -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