cryptodev: add user defined name for vdev
authorFan Zhang <roy.fan.zhang@intel.com>
Mon, 16 Jan 2017 14:14:54 +0000 (14:14 +0000)
committerPablo de Lara <pablo.de.lara.guarch@intel.com>
Wed, 18 Jan 2017 20:48:56 +0000 (21:48 +0100)
This patch adds a user defined name initializing parameter to cryptodev
library.

Originally, for software cryptodev PMD, the vdev name parameter is
treated as the driver identifier, and will create an unique name for each
device automatically, which is not necessarily as same as the vdev
parameter.

This patch allows the user to either create a unique name for his software
cryptodev, or by default, let the system creates a unique one. This should
help the user managing the created cryptodevs easily.

Examples:
CLI command fragment 1: --vdev "crypto_aesni_gcm_pmd"
The above command will result in creating a AESNI-GCM PMD with name of
"crypto_aesni_gcm_X", where postfix X is the number assigned by the system,
starting from 0. This fragment can be placed in the same CLI command
multiple times, resulting the postfixs incremented by one for each new
device.

CLI command fragment 2: --vdev "crypto_aesni_gcm_pmd,name=gcm1"
The above command will result in creating a AESNI-GCM PMD with name of
"gcm1". This fragment can be placed in the same CLI command multiple
times, as long as each having a unique name value.

Signed-off-by: Fan Zhang <roy.fan.zhang@intel.com>
Acked-by: Declan Doherty <declan.doherty@intel.com>
drivers/crypto/aesni_gcm/aesni_gcm_pmd.c
drivers/crypto/aesni_mb/rte_aesni_mb_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/snow3g/rte_snow3g_pmd.c
drivers/crypto/zuc/rte_zuc_pmd.c
lib/librte_cryptodev/rte_cryptodev.c
lib/librte_cryptodev/rte_cryptodev.h
lib/librte_cryptodev/rte_cryptodev_pmd.h
lib/librte_cryptodev/rte_cryptodev_version.map

index 5af22f7..796825a 100644 (file)
 
 #include "aesni_gcm_pmd_private.h"
 
-/**
- * Global static parameter used to create a unique name for each AES-NI multi
- * buffer crypto device.
- */
-static unsigned unique_name_id;
-
-static inline int
-create_unique_device_name(char *name, size_t size)
-{
-       int ret;
-
-       if (name == NULL)
-               return -EINVAL;
-
-       ret = snprintf(name, size, "%s_%u", RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD),
-                       unique_name_id++);
-       if (ret < 0)
-               return ret;
-       return 0;
-}
-
 static int
 aesni_gcm_calculate_hash_sub_key(uint8_t *hsubkey, unsigned hsubkey_length,
                uint8_t *aeskey, unsigned aeskey_length)
@@ -423,14 +402,23 @@ aesni_gcm_pmd_dequeue_burst(void *queue_pair,
 static int aesni_gcm_remove(const char *name);
 
 static int
-aesni_gcm_create(const char *name,
-               struct rte_crypto_vdev_init_params *init_params)
+aesni_gcm_create(struct rte_crypto_vdev_init_params *init_params)
 {
        struct rte_cryptodev *dev;
-       char crypto_dev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
        struct aesni_gcm_private *internals;
        enum aesni_gcm_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_GCM_PMD));
+
+               if (ret < 0) {
+                       GCM_LOG_ERR("failed to create unique name");
+                       return ret;
+               }
+       }
+
        /* Check CPU for support for AES instruction set */
        if (!rte_cpu_get_flag_enabled(RTE_CPUFLAG_AES)) {
                GCM_LOG_ERR("AES instructions not supported by CPU");
@@ -449,15 +437,7 @@ aesni_gcm_create(const char *name,
                return -EFAULT;
        }
 
-       /* create a unique device name */
-       if (create_unique_device_name(crypto_dev_name,
-                       RTE_CRYPTODEV_NAME_MAX_LEN) != 0) {
-               GCM_LOG_ERR("failed to create unique cryptodev name");
-               return -EINVAL;
-       }
-
-
-       dev = rte_cryptodev_pmd_virtual_dev_init(crypto_dev_name,
+       dev = rte_cryptodev_pmd_virtual_dev_init(init_params->name,
                        sizeof(struct aesni_gcm_private), init_params->socket_id);
        if (dev == NULL) {
                GCM_LOG_ERR("failed to create cryptodev vdev");
@@ -500,9 +480,9 @@ aesni_gcm_create(const char *name,
        return 0;
 
 init_error:
-       GCM_LOG_ERR("driver %s: create failed", name);
+       GCM_LOG_ERR("driver %s: create failed", init_params->name);
 
-       aesni_gcm_remove(crypto_dev_name);
+       aesni_gcm_remove(init_params->name);
        return -EFAULT;
 }
 
@@ -512,19 +492,23 @@ aesni_gcm_probe(const char *name, const char *input_args)
        struct rte_crypto_vdev_init_params init_params = {
                RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_QUEUE_PAIRS,
                RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_SESSIONS,
-               rte_socket_id()
+               rte_socket_id(),
+               {0}
        };
 
        rte_cryptodev_parse_vdev_init_params(&init_params, input_args);
 
        RTE_LOG(INFO, PMD, "Initialising %s on NUMA node %d\n", name,
                        init_params.socket_id);
+       if (init_params.name[0] != '\0')
+               RTE_LOG(INFO, PMD, "  User defined name = %s\n",
+                       init_params.name);
        RTE_LOG(INFO, PMD, "  Max number of queue pairs = %d\n",
                        init_params.max_nb_queue_pairs);
        RTE_LOG(INFO, PMD, "  Max number of sessions = %d\n",
                        init_params.max_nb_sessions);
 
-       return aesni_gcm_create(name, &init_params);
+       return aesni_gcm_create(&init_params);
 }
 
 static int
index 25f681b..432d239 100644 (file)
 
 #include "rte_aesni_mb_pmd_private.h"
 
-/**
- * Global static parameter used to create a unique name for each AES-NI multi
- * buffer crypto device.
- */
-static unsigned unique_name_id;
-
-static inline int
-create_unique_device_name(char *name, size_t size)
-{
-       int ret;
-
-       if (name == NULL)
-               return -EINVAL;
-
-       ret = snprintf(name, size, "%s_%u", RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
-                       unique_name_id++);
-       if (ret < 0)
-               return ret;
-       return 0;
-}
-
 typedef void (*hash_one_block_t)(void *data, void *digest);
 typedef void (*aes_keyexp_t)(void *key, void *enc_exp_keys, void *dec_exp_keys);
 
@@ -653,18 +632,21 @@ aesni_mb_pmd_dequeue_burst(void *queue_pair, struct rte_crypto_op **ops,
 static int cryptodev_aesni_mb_remove(const char *name);
 
 static int
-cryptodev_aesni_mb_create(const char *name,
-               struct rte_crypto_vdev_init_params *init_params)
+cryptodev_aesni_mb_create(struct rte_crypto_vdev_init_params *init_params)
 {
        struct rte_cryptodev *dev;
-       char crypto_dev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
        struct aesni_mb_private *internals;
        enum aesni_mb_vector_mode vector_mode;
 
-       /* Check CPU for support for AES instruction set */
-       if (!rte_cpu_get_flag_enabled(RTE_CPUFLAG_AES)) {
-               MB_LOG_ERR("AES instructions not supported by CPU");
-               return -EFAULT;
+       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;
+               }
        }
 
        /* Check CPU for supported vector instruction set */
@@ -681,15 +663,7 @@ cryptodev_aesni_mb_create(const char *name,
                return -EFAULT;
        }
 
-       /* create a unique device name */
-       if (create_unique_device_name(crypto_dev_name,
-                       RTE_CRYPTODEV_NAME_MAX_LEN) != 0) {
-               MB_LOG_ERR("failed to create unique cryptodev name");
-               return -EINVAL;
-       }
-
-
-       dev = rte_cryptodev_pmd_virtual_dev_init(crypto_dev_name,
+       dev = rte_cryptodev_pmd_virtual_dev_init(init_params->name,
                        sizeof(struct aesni_mb_private), init_params->socket_id);
        if (dev == NULL) {
                MB_LOG_ERR("failed to create cryptodev vdev");
@@ -733,9 +707,10 @@ cryptodev_aesni_mb_create(const char *name,
 
        return 0;
 init_error:
-       MB_LOG_ERR("driver %s: cryptodev_aesni_create failed", name);
+       MB_LOG_ERR("driver %s: cryptodev_aesni_create failed",
+                       init_params->name);
 
-       cryptodev_aesni_mb_remove(crypto_dev_name);
+       cryptodev_aesni_mb_remove(init_params->name);
        return -EFAULT;
 }
 
@@ -747,19 +722,23 @@ cryptodev_aesni_mb_probe(const char *name,
        struct rte_crypto_vdev_init_params init_params = {
                RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_QUEUE_PAIRS,
                RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_SESSIONS,
-               rte_socket_id()
+               rte_socket_id(),
+               ""
        };
 
        rte_cryptodev_parse_vdev_init_params(&init_params, input_args);
 
        RTE_LOG(INFO, PMD, "Initialising %s on NUMA node %d\n", name,
                        init_params.socket_id);
+       if (init_params.name[0] != '\0')
+               RTE_LOG(INFO, PMD, "  User defined name = %s\n",
+                       init_params.name);
        RTE_LOG(INFO, PMD, "  Max number of queue pairs = %d\n",
                        init_params.max_nb_queue_pairs);
        RTE_LOG(INFO, PMD, "  Max number of sessions = %d\n",
                        init_params.max_nb_sessions);
 
-       return cryptodev_aesni_mb_create(name, &init_params);
+       return cryptodev_aesni_mb_create(&init_params);
 }
 
 static int
index 4bdd7bb..a1ec653 100644 (file)
 #define KASUMI_MAX_BURST 4
 #define BYTE_LEN 8
 
-/**
- * Global static parameter used to create a unique name for each KASUMI
- * crypto device.
- */
-static unsigned unique_name_id;
-
-static inline int
-create_unique_device_name(char *name, size_t size)
-{
-       int ret;
-
-       if (name == NULL)
-               return -EINVAL;
-
-       ret = snprintf(name, size, "%s_%u", RTE_STR(CRYPTODEV_NAME_KASUMI_PMD),
-                       unique_name_id++);
-       if (ret < 0)
-               return ret;
-       return 0;
-}
-
 /** Get xform chain order. */
 static enum kasumi_operation
 kasumi_get_mode(const struct rte_crypto_sym_xform *xform)
@@ -572,14 +551,23 @@ kasumi_pmd_dequeue_burst(void *queue_pair,
 static int cryptodev_kasumi_remove(const char *name);
 
 static int
-cryptodev_kasumi_create(const char *name,
-               struct rte_crypto_vdev_init_params *init_params)
+cryptodev_kasumi_create(struct rte_crypto_vdev_init_params *init_params)
 {
        struct rte_cryptodev *dev;
-       char crypto_dev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
        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;
+               }
+       }
+
        /* Check CPU for supported vector instruction set */
        if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX))
                cpu_flags |= RTE_CRYPTODEV_FF_CPU_AVX;
@@ -590,14 +578,7 @@ cryptodev_kasumi_create(const char *name,
                return -EFAULT;
        }
 
-       /* Create a unique device name. */
-       if (create_unique_device_name(crypto_dev_name,
-                       RTE_CRYPTODEV_NAME_MAX_LEN) != 0) {
-               KASUMI_LOG_ERR("failed to create unique cryptodev name");
-               return -EINVAL;
-       }
-
-       dev = rte_cryptodev_pmd_virtual_dev_init(crypto_dev_name,
+       dev = rte_cryptodev_pmd_virtual_dev_init(init_params->name,
                        sizeof(struct kasumi_private), init_params->socket_id);
        if (dev == NULL) {
                KASUMI_LOG_ERR("failed to create cryptodev vdev");
@@ -622,9 +603,10 @@ cryptodev_kasumi_create(const char *name,
 
        return 0;
 init_error:
-       KASUMI_LOG_ERR("driver %s: cryptodev_kasumi_create failed", name);
+       KASUMI_LOG_ERR("driver %s: cryptodev_kasumi_create failed",
+                       init_params->name);
 
-       cryptodev_kasumi_remove(crypto_dev_name);
+       cryptodev_kasumi_remove(init_params->name);
        return -EFAULT;
 }
 
@@ -635,19 +617,23 @@ cryptodev_kasumi_probe(const char *name,
        struct rte_crypto_vdev_init_params init_params = {
                RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_QUEUE_PAIRS,
                RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_SESSIONS,
-               rte_socket_id()
+               rte_socket_id(),
+               {0}
        };
 
        rte_cryptodev_parse_vdev_init_params(&init_params, input_args);
 
        RTE_LOG(INFO, PMD, "Initialising %s on NUMA node %d\n", name,
                        init_params.socket_id);
+       if (init_params.name[0] != '\0')
+               RTE_LOG(INFO, PMD, "  User defined name = %s\n",
+                       init_params.name);
        RTE_LOG(INFO, PMD, "  Max number of queue pairs = %d\n",
                        init_params.max_nb_queue_pairs);
        RTE_LOG(INFO, PMD, "  Max number of sessions = %d\n",
                        init_params.max_nb_sessions);
 
-       return cryptodev_kasumi_create(name, &init_params);
+       return cryptodev_kasumi_create(&init_params);
 }
 
 static int
index c37d3d6..ed5a9fc 100644 (file)
 
 #include "null_crypto_pmd_private.h"
 
-/**
- * Global static parameter used to create a unique name for each crypto device.
- */
-static unsigned unique_name_id;
-
-static inline int
-create_unique_device_name(char *name, size_t size)
-{
-       int ret;
-
-       if (name == NULL)
-               return -EINVAL;
-
-       ret = snprintf(name, size, "%s_%u", RTE_STR(CRYPTODEV_NAME_NULL_PMD),
-                       unique_name_id++);
-       if (ret < 0)
-               return ret;
-       return 0;
-}
-
-
 /** verify and set session parameters */
 int
 null_crypto_set_session_parameters(
@@ -186,21 +165,24 @@ static int cryptodev_null_remove(const char *name);
 
 /** Create crypto device */
 static int
-cryptodev_null_create(const char *name,
-               struct rte_crypto_vdev_init_params *init_params)
+cryptodev_null_create(struct rte_crypto_vdev_init_params *init_params)
 {
        struct rte_cryptodev *dev;
-       char crypto_dev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
        struct null_crypto_private *internals;
 
-       /* create a unique device name */
-       if (create_unique_device_name(crypto_dev_name,
-                       RTE_CRYPTODEV_NAME_MAX_LEN) != 0) {
-               NULL_CRYPTO_LOG_ERR("failed to create unique cryptodev name");
-               return -EINVAL;
+       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;
+               }
        }
 
-       dev = rte_cryptodev_pmd_virtual_dev_init(crypto_dev_name,
+       dev = rte_cryptodev_pmd_virtual_dev_init(init_params->name,
                        sizeof(struct null_crypto_private),
                        init_params->socket_id);
        if (dev == NULL) {
@@ -227,8 +209,9 @@ cryptodev_null_create(const char *name,
        return 0;
 
 init_error:
-       NULL_CRYPTO_LOG_ERR("driver %s: cryptodev_null_create failed", name);
-       cryptodev_null_remove(crypto_dev_name);
+       NULL_CRYPTO_LOG_ERR("driver %s: cryptodev_null_create failed",
+                       init_params->name);
+       cryptodev_null_remove(init_params->name);
 
        return -EFAULT;
 }
@@ -241,19 +224,23 @@ cryptodev_null_probe(const char *name,
        struct rte_crypto_vdev_init_params init_params = {
                RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_QUEUE_PAIRS,
                RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_SESSIONS,
-               rte_socket_id()
+               rte_socket_id(),
+               {0}
        };
 
        rte_cryptodev_parse_vdev_init_params(&init_params, input_args);
 
        RTE_LOG(INFO, PMD, "Initialising %s on NUMA node %d\n", name,
                        init_params.socket_id);
+       if (init_params.name[0] != '\0')
+               RTE_LOG(INFO, PMD, "  User defined name = %s\n",
+                       init_params.name);
        RTE_LOG(INFO, PMD, "  Max number of queue pairs = %d\n",
                        init_params.max_nb_queue_pairs);
        RTE_LOG(INFO, PMD, "  Max number of sessions = %d\n",
                        init_params.max_nb_sessions);
 
-       return cryptodev_null_create(name, &init_params);
+       return cryptodev_null_create(&init_params);
 }
 
 /** Uninitialise null crypto device */
index 426e407..e74c5cf 100644 (file)
@@ -46,28 +46,6 @@ static int cryptodev_openssl_remove(const char *name);
 
 /*----------------------------------------------------------------------------*/
 
-/**
- * Global static parameter used to create a unique name for each
- * OPENSSL crypto device.
- */
-static unsigned int unique_name_id;
-
-static inline int
-create_unique_device_name(char *name, size_t size)
-{
-       int ret;
-
-       if (name == NULL)
-               return -EINVAL;
-
-       ret = snprintf(name, size, "%s_%u",
-                       RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD),
-                       unique_name_id++);
-       if (ret < 0)
-               return ret;
-       return 0;
-}
-
 /**
  * Increment counter by 1
  * Counter is 64 bit array, big-endian
@@ -1149,21 +1127,23 @@ openssl_pmd_dequeue_burst(void *queue_pair, struct rte_crypto_op **ops,
 
 /** Create OPENSSL crypto device */
 static int
-cryptodev_openssl_create(const char *name,
-               struct rte_crypto_vdev_init_params *init_params)
+cryptodev_openssl_create(struct rte_crypto_vdev_init_params *init_params)
 {
        struct rte_cryptodev *dev;
-       char crypto_dev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
        struct openssl_private *internals;
 
-       /* create a unique device name */
-       if (create_unique_device_name(crypto_dev_name,
-                       RTE_CRYPTODEV_NAME_MAX_LEN) != 0) {
-               OPENSSL_LOG_ERR("failed to create unique cryptodev name");
-               return -EINVAL;
+       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;
+               }
        }
 
-       dev = rte_cryptodev_pmd_virtual_dev_init(crypto_dev_name,
+       dev = rte_cryptodev_pmd_virtual_dev_init(init_params->name,
                        sizeof(struct openssl_private),
                        init_params->socket_id);
        if (dev == NULL) {
@@ -1192,9 +1172,10 @@ cryptodev_openssl_create(const char *name,
        return 0;
 
 init_error:
-       OPENSSL_LOG_ERR("driver %s: cryptodev_openssl_create failed", name);
+       OPENSSL_LOG_ERR("driver %s: cryptodev_openssl_create failed",
+                       init_params->name);
 
-       cryptodev_openssl_remove(crypto_dev_name);
+       cryptodev_openssl_remove(init_params->name);
        return -EFAULT;
 }
 
@@ -1206,19 +1187,23 @@ cryptodev_openssl_probe(const char *name,
        struct rte_crypto_vdev_init_params init_params = {
                RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_QUEUE_PAIRS,
                RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_SESSIONS,
-               rte_socket_id()
+               rte_socket_id(),
+               {0}
        };
 
        rte_cryptodev_parse_vdev_init_params(&init_params, input_args);
 
        RTE_LOG(INFO, PMD, "Initialising %s on NUMA node %d\n", name,
                        init_params.socket_id);
+       if (init_params.name[0] != '\0')
+               RTE_LOG(INFO, PMD, "  User defined name = %s\n",
+                       init_params.name);
        RTE_LOG(INFO, PMD, "  Max number of queue pairs = %d\n",
                        init_params.max_nb_queue_pairs);
        RTE_LOG(INFO, PMD, "  Max number of sessions = %d\n",
                        init_params.max_nb_sessions);
 
-       return cryptodev_openssl_create(name, &init_params);
+       return cryptodev_openssl_create(&init_params);
 }
 
 /** Uninitialise OPENSSL crypto device */
index 9a6f16d..bccf6a5 100644 (file)
 #define SNOW3G_MAX_BURST 8
 #define BYTE_LEN 8
 
-/**
- * Global static parameter used to create a unique name for each SNOW 3G
- * crypto device.
- */
-static unsigned unique_name_id;
-
-static inline int
-create_unique_device_name(char *name, size_t size)
-{
-       int ret;
-
-       if (name == NULL)
-               return -EINVAL;
-
-       ret = snprintf(name, size, "%s_%u", RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD),
-                       unique_name_id++);
-       if (ret < 0)
-               return ret;
-       return 0;
-}
-
 /** Get xform chain order. */
 static enum snow3g_operation
 snow3g_get_mode(const struct rte_crypto_sym_xform *xform)
@@ -563,14 +542,23 @@ snow3g_pmd_dequeue_burst(void *queue_pair,
 static int cryptodev_snow3g_remove(const char *name);
 
 static int
-cryptodev_snow3g_create(const char *name,
-               struct rte_crypto_vdev_init_params *init_params)
+cryptodev_snow3g_create(struct rte_crypto_vdev_init_params *init_params)
 {
        struct rte_cryptodev *dev;
-       char crypto_dev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
        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;
+               }
+       }
+
        /* Check CPU for supported vector instruction set */
        if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_SSE4_1))
                cpu_flags |= RTE_CRYPTODEV_FF_CPU_SSE;
@@ -579,15 +567,7 @@ cryptodev_snow3g_create(const char *name,
                return -EFAULT;
        }
 
-
-       /* Create a unique device name. */
-       if (create_unique_device_name(crypto_dev_name,
-                       RTE_CRYPTODEV_NAME_MAX_LEN) != 0) {
-               SNOW3G_LOG_ERR("failed to create unique cryptodev name");
-               return -EINVAL;
-       }
-
-       dev = rte_cryptodev_pmd_virtual_dev_init(crypto_dev_name,
+       dev = rte_cryptodev_pmd_virtual_dev_init(init_params->name,
                        sizeof(struct snow3g_private), init_params->socket_id);
        if (dev == NULL) {
                SNOW3G_LOG_ERR("failed to create cryptodev vdev");
@@ -612,9 +592,10 @@ cryptodev_snow3g_create(const char *name,
 
        return 0;
 init_error:
-       SNOW3G_LOG_ERR("driver %s: cryptodev_snow3g_create failed", name);
+       SNOW3G_LOG_ERR("driver %s: cryptodev_snow3g_create failed",
+                       init_params->name);
 
-       cryptodev_snow3g_remove(crypto_dev_name);
+       cryptodev_snow3g_remove(init_params->name);
        return -EFAULT;
 }
 
@@ -625,19 +606,23 @@ cryptodev_snow3g_probe(const char *name,
        struct rte_crypto_vdev_init_params init_params = {
                RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_QUEUE_PAIRS,
                RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_SESSIONS,
-               rte_socket_id()
+               rte_socket_id(),
+               {0}
        };
 
        rte_cryptodev_parse_vdev_init_params(&init_params, input_args);
 
        RTE_LOG(INFO, PMD, "Initialising %s on NUMA node %d\n", name,
                        init_params.socket_id);
+       if (init_params.name[0] != '\0')
+               RTE_LOG(INFO, PMD, "  User defined name = %s\n",
+                       init_params.name);
        RTE_LOG(INFO, PMD, "  Max number of queue pairs = %d\n",
                        init_params.max_nb_queue_pairs);
        RTE_LOG(INFO, PMD, "  Max number of sessions = %d\n",
                        init_params.max_nb_sessions);
 
-       return cryptodev_snow3g_create(name, &init_params);
+       return cryptodev_snow3g_create(&init_params);
 }
 
 static int
index bf53f76..fabcfb4 100644 (file)
 #define ZUC_MAX_BURST 8
 #define BYTE_LEN 8
 
-/**
- * Global static parameter used to create a unique name for each ZUC
- * crypto device.
- */
-static unsigned unique_name_id;
-
-static inline int
-create_unique_device_name(char *name, size_t size)
-{
-       int ret;
-
-       if (name == NULL)
-               return -EINVAL;
-
-       ret = snprintf(name, size, "%s_%u", RTE_STR(CRYPTODEV_NAME_ZUC_PMD),
-                       unique_name_id++);
-       if (ret < 0)
-               return ret;
-       return 0;
-}
-
 /** Get xform chain order. */
 static enum zuc_operation
 zuc_get_mode(const struct rte_crypto_sym_xform *xform)
@@ -461,14 +440,23 @@ zuc_pmd_dequeue_burst(void *queue_pair,
 static int cryptodev_zuc_remove(const char *name);
 
 static int
-cryptodev_zuc_create(const char *name,
-               struct rte_crypto_vdev_init_params *init_params)
+cryptodev_zuc_create(struct rte_crypto_vdev_init_params *init_params)
 {
        struct rte_cryptodev *dev;
-       char crypto_dev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
        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;
+               }
+       }
+
        /* Check CPU for supported vector instruction set */
        if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_SSE4_1))
                cpu_flags |= RTE_CRYPTODEV_FF_CPU_SSE;
@@ -477,15 +465,7 @@ cryptodev_zuc_create(const char *name,
                return -EFAULT;
        }
 
-
-       /* Create a unique device name. */
-       if (create_unique_device_name(crypto_dev_name,
-                       RTE_CRYPTODEV_NAME_MAX_LEN) != 0) {
-               ZUC_LOG_ERR("failed to create unique cryptodev name");
-               return -EINVAL;
-       }
-
-       dev = rte_cryptodev_pmd_virtual_dev_init(crypto_dev_name,
+       dev = rte_cryptodev_pmd_virtual_dev_init(init_params->name,
                        sizeof(struct zuc_private), init_params->socket_id);
        if (dev == NULL) {
                ZUC_LOG_ERR("failed to create cryptodev vdev");
@@ -510,9 +490,10 @@ cryptodev_zuc_create(const char *name,
 
        return 0;
 init_error:
-       ZUC_LOG_ERR("driver %s: cryptodev_zuc_create failed", name);
+       ZUC_LOG_ERR("driver %s: cryptodev_zuc_create failed",
+                       init_params->name);
 
-       cryptodev_zuc_remove(crypto_dev_name);
+       cryptodev_zuc_remove(init_params->name);
        return -EFAULT;
 }
 
@@ -523,19 +504,23 @@ cryptodev_zuc_probe(const char *name,
        struct rte_crypto_vdev_init_params init_params = {
                RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_QUEUE_PAIRS,
                RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_SESSIONS,
-               rte_socket_id()
+               rte_socket_id(),
+               {0}
        };
 
        rte_cryptodev_parse_vdev_init_params(&init_params, input_args);
 
        RTE_LOG(INFO, PMD, "Initialising %s on NUMA node %d\n", name,
                        init_params.socket_id);
+       if (init_params.name[0] != '\0')
+               RTE_LOG(INFO, PMD, "  User defined name = %s\n",
+                       init_params.name);
        RTE_LOG(INFO, PMD, "  Max number of queue pairs = %d\n",
                        init_params.max_nb_queue_pairs);
        RTE_LOG(INFO, PMD, "  Max number of sessions = %d\n",
                        init_params.max_nb_sessions);
 
-       return cryptodev_zuc_create(name, &init_params);
+       return cryptodev_zuc_create(&init_params);
 }
 
 static int
index bbab4b3..f2ceb9b 100644 (file)
@@ -101,11 +101,13 @@ struct rte_cryptodev_callback {
        uint32_t active;                        /**< Callback is executing */
 };
 
+#define RTE_CRYPTODEV_VDEV_NAME                                ("name")
 #define RTE_CRYPTODEV_VDEV_MAX_NB_QP_ARG               ("max_nb_queue_pairs")
 #define RTE_CRYPTODEV_VDEV_MAX_NB_SESS_ARG             ("max_nb_sessions")
 #define RTE_CRYPTODEV_VDEV_SOCKET_ID                   ("socket_id")
 
 static const char *cryptodev_vdev_valid_params[] = {
+       RTE_CRYPTODEV_VDEV_NAME,
        RTE_CRYPTODEV_VDEV_MAX_NB_QP_ARG,
        RTE_CRYPTODEV_VDEV_MAX_NB_SESS_ARG,
        RTE_CRYPTODEV_VDEV_SOCKET_ID
@@ -143,6 +145,25 @@ parse_integer_arg(const char *key __rte_unused,
        return 0;
 }
 
+/** Parse name */
+static int
+parse_name_arg(const char *key __rte_unused,
+               const char *value, void *extra_args)
+{
+       struct rte_crypto_vdev_init_params *params = extra_args;
+
+       if (strlen(value) >= RTE_CRYPTODEV_NAME_MAX_LEN - 1) {
+               CDEV_LOG_ERR("Invalid name %s, should be less than "
+                               "%u bytes", value,
+                               RTE_CRYPTODEV_NAME_MAX_LEN - 1);
+               return -1;
+       }
+
+       strncpy(params->name, value, RTE_CRYPTODEV_NAME_MAX_LEN);
+
+       return 0;
+}
+
 int
 rte_cryptodev_parse_vdev_init_params(struct rte_crypto_vdev_init_params *params,
                const char *input_args)
@@ -179,6 +200,12 @@ rte_cryptodev_parse_vdev_init_params(struct rte_crypto_vdev_init_params *params,
                if (ret < 0)
                        goto free_kvlist;
 
+               ret = rte_kvargs_process(kvlist, RTE_CRYPTODEV_VDEV_NAME,
+                                       &parse_name_arg,
+                                       params);
+               if (ret < 0)
+                       goto free_kvlist;
+
                if (params->socket_id >= number_of_sockets()) {
                        CDEV_LOG_ERR("Invalid socket id specified to create "
                                "the virtual crypto device on");
@@ -1206,3 +1233,27 @@ rte_crypto_op_pool_create(const char *name, enum rte_crypto_op_type type,
 
        return mp;
 }
+
+int
+rte_cryptodev_pmd_create_dev_name(char *name, const char *dev_name_prefix)
+{
+       struct rte_cryptodev *dev = NULL;
+       uint32_t i = 0;
+
+       if (name == NULL)
+               return -EINVAL;
+
+       for (i = 0; i < RTE_CRYPTO_MAX_DEVS; i++) {
+               int ret = snprintf(name, RTE_CRYPTODEV_NAME_MAX_LEN,
+                               "%s_%u", dev_name_prefix, i);
+
+               if (ret < 0)
+                       return ret;
+
+               dev = rte_cryptodev_pmd_get_named_dev(name);
+               if (!dev)
+                       return 0;
+       }
+
+       return -1;
+}
index fa311a9..f4e66e6 100644 (file)
@@ -304,6 +304,8 @@ struct rte_cryptodev_stats {
        /**< Total error count on operations dequeued */
 };
 
+#define RTE_CRYPTODEV_NAME_MAX_LEN     (64)
+/**< Max length of name of crypto PMD */
 #define RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_QUEUE_PAIRS  8
 #define RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_SESSIONS     2048
 
@@ -315,6 +317,7 @@ struct rte_crypto_vdev_init_params {
        unsigned max_nb_queue_pairs;
        unsigned max_nb_sessions;
        uint8_t socket_id;
+       char name[RTE_CRYPTODEV_NAME_MAX_LEN];
 };
 
 /**
@@ -639,10 +642,6 @@ struct rte_cryptodev {
        /**< Flag indicating the device is attached */
 } __rte_cache_aligned;
 
-
-#define RTE_CRYPTODEV_NAME_MAX_LEN     (64)
-/**< Max length of name of crypto PMD */
-
 /**
  *
  * The data part, with no function pointers, associated with each device.
index c6a5794..aabef41 100644 (file)
@@ -520,6 +520,13 @@ int rte_cryptodev_pci_probe(struct rte_pci_driver *pci_drv,
  */
 int rte_cryptodev_pci_remove(struct rte_pci_device *pci_dev);
 
+/**
+ * @internal
+ * Create unique device name
+ */
+int
+rte_cryptodev_pmd_create_dev_name(char *name, const char *dev_name_prefix);
+
 #ifdef __cplusplus
 }
 #endif
index 9dde0e7..c581eea 100644 (file)
@@ -46,3 +46,10 @@ DPDK_16.11 {
        rte_cryptodev_pci_remove;
 
 } DPDK_16.07;
+
+DPDK_17.02 {
+       global:
+
+       rte_cryptodev_pmd_create_dev_name;
+
+} DPDK_16.11;