summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGaetan Rivet <gaetan.rivet@6wind.com>2018-07-11 23:44:52 +0200
committerThomas Monjalon <thomas@monjalon.net>2018-07-15 23:42:10 +0200
commita23bc2c4e01bf29ed6dd571dbc5b76cc69c10b51 (patch)
tree5143a7fb07a07886fddc094bbb0cc3c6aae78285
parent0436120e33e0e117ce294a024555f522a7e68fb3 (diff)
downloaddpdk-a23bc2c4e01bf29ed6dd571dbc5b76cc69c10b51.zip
dpdk-a23bc2c4e01bf29ed6dd571dbc5b76cc69c10b51.tar.gz
dpdk-a23bc2c4e01bf29ed6dd571dbc5b76cc69c10b51.tar.xz
devargs: add non-variadic parsing function
rte_devargs_parse becomes non-variadic, rte_devargs_parsef becomes the variadic version, to be used to compose device strings. Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com> Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com> Acked-by: Thomas Monjalon <thomas@monjalon.net>
-rw-r--r--drivers/net/failsafe/failsafe_args.c2
-rw-r--r--drivers/net/failsafe/failsafe_eal.c2
-rw-r--r--lib/librte_eal/common/eal_common_dev.c4
-rw-r--r--lib/librte_eal/common/eal_common_devargs.c42
-rw-r--r--lib/librte_eal/common/include/rte_devargs.h40
-rw-r--r--lib/librte_eal/rte_eal_version.map1
-rw-r--r--lib/librte_ethdev/rte_ethdev.c2
7 files changed, 76 insertions, 17 deletions
diff --git a/drivers/net/failsafe/failsafe_args.c b/drivers/net/failsafe/failsafe_args.c
index 2c002b1..626883c 100644
--- a/drivers/net/failsafe/failsafe_args.c
+++ b/drivers/net/failsafe/failsafe_args.c
@@ -63,7 +63,7 @@ fs_parse_device(struct sub_device *sdev, char *args)
d = &sdev->devargs;
DEBUG("%s", args);
- ret = rte_devargs_parse(d, "%s", args);
+ ret = rte_devargs_parse(d, args);
if (ret) {
DEBUG("devargs parsing failed with code %d", ret);
return ret;
diff --git a/drivers/net/failsafe/failsafe_eal.c b/drivers/net/failsafe/failsafe_eal.c
index 5672f39..ce1633f 100644
--- a/drivers/net/failsafe/failsafe_eal.c
+++ b/drivers/net/failsafe/failsafe_eal.c
@@ -86,7 +86,7 @@ fs_bus_init(struct rte_eth_dev *dev)
else
snprintf(devstr, sizeof(devstr), "%s",
rte_eth_devices[pid].device->name);
- ret = rte_devargs_parse(da, "%s", devstr);
+ ret = rte_devargs_parse(da, devstr);
if (ret) {
ERROR("Probed devargs parsing failed with code"
" %d", ret);
diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 61cb3b1..ce4b514 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -138,8 +138,8 @@ int __rte_experimental rte_eal_hotplug_add(const char *busname, const char *devn
if (da == NULL)
return -ENOMEM;
- ret = rte_devargs_parse(da, "%s:%s,%s",
- busname, devname, devargs);
+ ret = rte_devargs_parsef(da, "%s:%s,%s",
+ busname, devname, devargs);
if (ret)
goto err_devarg;
diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
index 894749e..f84f3d2 100644
--- a/lib/librte_eal/common/eal_common_devargs.c
+++ b/lib/librte_eal/common/eal_common_devargs.c
@@ -63,24 +63,18 @@ bus_name_cmp(const struct rte_bus *bus, const void *name)
return strncmp(bus->name, name, strlen(bus->name));
}
-int __rte_experimental
-rte_devargs_parse(struct rte_devargs *da, const char *format, ...)
+__rte_experimental
+int
+rte_devargs_parse(struct rte_devargs *da, const char *dev)
{
struct rte_bus *bus = NULL;
- va_list ap;
- va_start(ap, format);
- char dev[vsnprintf(NULL, 0, format, ap) + 1];
const char *devname;
const size_t maxlen = sizeof(da->name);
size_t i;
- va_end(ap);
if (da == NULL)
return -EINVAL;
- va_start(ap, format);
- vsnprintf(dev, sizeof(dev), format, ap);
- va_end(ap);
/* Retrieve eventual bus info */
do {
devname = dev;
@@ -125,6 +119,34 @@ rte_devargs_parse(struct rte_devargs *da, const char *format, ...)
return 0;
}
+__rte_experimental
+int
+rte_devargs_parsef(struct rte_devargs *da, const char *format, ...)
+{
+ va_list ap;
+ size_t len;
+ char *dev;
+
+ if (da == NULL)
+ return -EINVAL;
+
+ va_start(ap, format);
+ len = vsnprintf(NULL, 0, format, ap);
+ va_end(ap);
+
+ dev = calloc(1, len + 1);
+ if (dev == NULL) {
+ RTE_LOG(ERR, EAL, "not enough memory to parse device\n");
+ return -ENOMEM;
+ }
+
+ va_start(ap, format);
+ vsnprintf(dev, len, format, ap);
+ va_end(ap);
+
+ return rte_devargs_parse(da, dev);
+}
+
int __rte_experimental
rte_devargs_insert(struct rte_devargs *da)
{
@@ -151,7 +173,7 @@ rte_devargs_add(enum rte_devtype devtype, const char *devargs_str)
if (devargs == NULL)
goto fail;
- if (rte_devargs_parse(devargs, "%s", dev))
+ if (rte_devargs_parse(devargs, dev))
goto fail;
devargs->type = devtype;
bus = devargs->bus;
diff --git a/lib/librte_eal/common/include/rte_devargs.h b/lib/librte_eal/common/include/rte_devargs.h
index 58fbd90..6c3b632 100644
--- a/lib/librte_eal/common/include/rte_devargs.h
+++ b/lib/librte_eal/common/include/rte_devargs.h
@@ -96,6 +96,42 @@ int rte_eal_parse_devargs_str(const char *devargs_str,
* in argument. Store which bus will handle the device, its name
* and the eventual device parameters.
*
+ * The syntax is:
+ *
+ * bus:device_identifier,arg1=val1,arg2=val2
+ *
+ * where "bus:" is the bus name followed by any character separator.
+ * The bus name is optional. If no bus name is specified, each bus
+ * will attempt to recognize the device identifier. The first one
+ * to succeed will be used.
+ *
+ * Examples:
+ *
+ * pci:0000:05.00.0,arg=val
+ * 05.00.0,arg=val
+ * vdev:net_ring0
+ *
+ * @param da
+ * The devargs structure holding the device information.
+ *
+ * @param dev
+ * String describing a device.
+ *
+ * @return
+ * - 0 on success.
+ * - Negative errno on error.
+ */
+__rte_experimental
+int
+rte_devargs_parse(struct rte_devargs *da, const char *dev);
+
+/**
+ * Parse a device string.
+ *
+ * Verify that a bus is capable of handling the device passed
+ * in argument. Store which bus will handle the device, its name
+ * and the eventual device parameters.
+ *
* The device string is built with a printf-like syntax.
*
* The syntax is:
@@ -124,8 +160,8 @@ int rte_eal_parse_devargs_str(const char *devargs_str,
*/
__rte_experimental
int
-rte_devargs_parse(struct rte_devargs *da,
- const char *format, ...)
+rte_devargs_parsef(struct rte_devargs *da,
+ const char *format, ...)
__attribute__((format(printf, 2, 0)));
/**
diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map
index e17dd2c..8ea268b 100644
--- a/lib/librte_eal/rte_eal_version.map
+++ b/lib/librte_eal/rte_eal_version.map
@@ -264,6 +264,7 @@ EXPERIMENTAL {
rte_devargs_insert;
rte_devargs_next;
rte_devargs_parse;
+ rte_devargs_parsef;
rte_devargs_remove;
rte_devargs_type_count;
rte_eal_cleanup;
diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index e262904..2e40c3f 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -658,7 +658,7 @@ rte_eth_dev_attach(const char *devargs, uint16_t *port_id)
}
/* parse devargs */
- if (rte_devargs_parse(&da, "%s", devargs))
+ if (rte_devargs_parse(&da, devargs))
goto err;
ret = rte_eal_hotplug_add(da.bus->name, da.name, da.args);