From: Jan Blunck <jblunck@infradead.org>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH 07/13] devargs: add busname string field
Date: Tue, 11 Jul 2017 19:25:06 -0400 [thread overview]
Message-ID: <20170711232512.54641-8-jblunck@infradead.org> (raw)
In-Reply-To: <20170711232512.54641-1-jblunck@infradead.org>
This adds the busname as a string to struct rte_devargs. The function
rte_eal_devargs_add() is adding the busname based on the devtype which
is ok for now since the function is deprecated anyway.
As a side-effect this is also no longer validating the PCI device name.
This was done only for PCI devices anyway but didn't guarantee that this
device exists.
Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
lib/librte_eal/common/eal_common_devargs.c | 89 +++++++++++++++++++++--------
lib/librte_eal/common/include/rte_devargs.h | 9 ++-
test/test/test_devargs.c | 12 ----
3 files changed, 71 insertions(+), 39 deletions(-)
diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
index 691538095..f9f23f5fd 100644
--- a/lib/librte_eal/common/eal_common_devargs.c
+++ b/lib/librte_eal/common/eal_common_devargs.c
@@ -77,6 +77,42 @@ rte_eal_parse_devargs_str(const char *devargs_str,
return 0;
}
+static struct rte_devargs *
+devargs_alloc(const char *busname, const char *name, const char *args)
+{
+ struct rte_devargs *devargs;
+ int ret;
+
+ if (busname == NULL || name == NULL || args == NULL)
+ return NULL;
+
+ /* use calloc instead of rte_zmalloc as it's called early at init */
+ devargs = calloc(1, sizeof(*devargs));
+ if (devargs == NULL)
+ goto fail;
+
+ ret = snprintf(devargs->busname, sizeof(devargs->busname), "%s",
+ busname);
+ if (ret < 0 || ret >= (int)sizeof(devargs->busname))
+ goto fail;
+
+ ret = snprintf(devargs->name, sizeof(devargs->name), "%s", name);
+ if (ret < 0 || ret >= (int)sizeof(devargs->name))
+ goto fail;
+
+ devargs->args = strdup(args);
+ TAILQ_INSERT_TAIL(&devargs_list, devargs, next);
+ return devargs;
+
+fail:
+ if (devargs != NULL) {
+ free(devargs->args);
+ free(devargs);
+ }
+
+ return NULL;
+}
+
static int
bus_name_cmp(const struct rte_bus *bus, const void *name)
{
@@ -150,38 +186,43 @@ int
rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
{
struct rte_devargs *devargs = NULL;
- struct rte_bus *bus = NULL;
- const char *dev = devargs_str;
+ const char *busname = NULL;
+ char *name = NULL;
+ char *args = NULL;
int ret;
- /* use calloc instead of rte_zmalloc as it's called early at init */
- devargs = calloc(1, sizeof(*devargs));
- if (devargs == NULL)
+ ret = rte_eal_parse_devargs_str(devargs_str, &name, &args);
+ if (ret != 0)
goto fail;
- if (rte_eal_devargs_parse(dev, devargs))
- goto fail;
- devargs->type = devtype;
- bus = devargs->bus;
- ret = rte_bus_configure(bus,
- devtype == RTE_DEVTYPE_WHITELISTED_PCI ?
- &BUS_CONF_WHITELIST : &BUS_CONF_WHITELIST);
- if (ret != 0) {
- RTE_LOG(ERR, EAL,
- "incompatible device type and bus scan mode\n");
- goto fail;
+ switch (devtype) {
+ case RTE_DEVTYPE_WHITELISTED_PCI:
+ case RTE_DEVTYPE_BLACKLISTED_PCI:
+ busname = "pci";
+ ret = rte_bus_configure(rte_bus_find_by_name(busname),
+ devtype == RTE_DEVTYPE_WHITELISTED_PCI ?
+ &BUS_CONF_WHITELIST : &BUS_CONF_BLACKLIST);
+ if (ret != 0) {
+ RTE_LOG(ERR, EAL,
+ "Bus [%s] scan_mode conflicts with devtype: "
+ "%s\n", busname, name);
+ goto fail;
+ }
+ break;
+ case RTE_DEVTYPE_VIRTUAL:
+ busname = "vdev";
+ break;
}
- TAILQ_INSERT_TAIL(&devargs_list, devargs, next);
- return 0;
+ devargs = devargs_alloc(busname, name, args);
+ if (devargs != NULL)
+ devargs->type = devtype;
+ ret = devargs == NULL ? -1 : 0;
fail:
- if (devargs) {
- free(devargs->args);
- free(devargs);
- }
-
- return -1;
+ free(name);
+ free(args);
+ return ret;
}
/* count the number of devices of a specified type */
diff --git a/lib/librte_eal/common/include/rte_devargs.h b/lib/librte_eal/common/include/rte_devargs.h
index 41db817cc..29631cbaa 100644
--- a/lib/librte_eal/common/include/rte_devargs.h
+++ b/lib/librte_eal/common/include/rte_devargs.h
@@ -79,6 +79,8 @@ struct rte_devargs {
enum rte_devtype type;
/** Bus handle for the device. */
struct rte_bus *bus;
+ /** Name of the bus the device belongs to. */
+ char busname[RTE_DEV_NAME_MAX_LEN];
/** Name of the device. */
char name[RTE_DEV_NAME_MAX_LEN];
/** Arguments string as given by user or "" for no argument. */
@@ -149,9 +151,10 @@ rte_eal_devargs_parse(const char *dev,
*
* For virtual devices, the format of arguments string is "DRIVER_NAME*"
* or "DRIVER_NAME*,key=val,key2=val2,...". Examples: "net_ring",
- * "net_ring0", "net_pmdAnything,arg=0:arg2=1". The validity of the
- * driver name is not checked by this function, it is done when probing
- * the drivers.
+ * "net_ring0", "net_pmdAnything,arg=0:arg2=1".
+ *
+ * The validity of the device name is not checked by this function, it is
+ * done when probing the drivers.
*
* @param devtype
* The type of the device.
diff --git a/test/test/test_devargs.c b/test/test/test_devargs.c
index 02fec8b1f..048b3d00b 100644
--- a/test/test/test_devargs.c
+++ b/test/test/test_devargs.c
@@ -109,18 +109,6 @@ test_devargs(void)
goto fail;
free_devargs_list();
- /* test error case: bad PCI address */
- if (rte_eal_devargs_add(RTE_DEVTYPE_WHITELISTED_PCI, "08:1") == 0)
- goto fail;
- if (rte_eal_devargs_add(RTE_DEVTYPE_WHITELISTED_PCI, "00.1") == 0)
- goto fail;
- if (rte_eal_devargs_add(RTE_DEVTYPE_WHITELISTED_PCI, "foo") == 0)
- goto fail;
- if (rte_eal_devargs_add(RTE_DEVTYPE_WHITELISTED_PCI, ",") == 0)
- goto fail;
- if (rte_eal_devargs_add(RTE_DEVTYPE_WHITELISTED_PCI, "000f:0:0") == 0)
- goto fail;
-
devargs_list = save_devargs_list;
return 0;
--
2.13.2
next prev parent reply other threads:[~2017-07-11 23:25 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-11 23:24 [dpdk-dev] [PATCH 00/13] devargs fixes Jan Blunck
2017-07-11 23:25 ` [dpdk-dev] [PATCH 01/13] Revert "devargs: make device types generic" Jan Blunck
2017-07-11 23:25 ` [dpdk-dev] [PATCH 02/13] devargs: fix unittest Jan Blunck
2017-07-11 23:25 ` [dpdk-dev] [PATCH 03/13] devargs: deprecate enum rte_devtype based functions Jan Blunck
2017-08-07 23:02 ` Thomas Monjalon
2017-07-11 23:25 ` [dpdk-dev] [PATCH 04/13] pci: use scan_mode configuration Jan Blunck
2017-07-13 17:59 ` Gaëtan Rivet
2017-07-13 19:42 ` Jan Blunck
2017-07-13 20:48 ` Thomas Monjalon
2017-07-11 23:25 ` [dpdk-dev] [PATCH 05/13] bus: add configuration interface for buses Jan Blunck
2017-07-11 23:25 ` [dpdk-dev] [PATCH 06/13] devargs: use bus configuration interface to set scanning mode Jan Blunck
2017-07-11 23:25 ` Jan Blunck [this message]
2017-07-13 13:17 ` [dpdk-dev] [PATCH 07/13] devargs: add busname string field Gaëtan Rivet
2017-07-11 23:25 ` [dpdk-dev] [PATCH 08/13] devargs: use busname Jan Blunck
2017-07-11 23:25 ` [dpdk-dev] [PATCH 09/13] devargs: parse "bus=" argument Jan Blunck
2017-07-13 13:40 ` Gaëtan Rivet
2017-07-13 19:34 ` Jan Blunck
2017-07-11 23:25 ` [dpdk-dev] [PATCH 10/13] pci: use busname Jan Blunck
2017-07-11 23:25 ` [dpdk-dev] [PATCH 11/13] vdev: " Jan Blunck
2017-07-11 23:25 ` [dpdk-dev] [PATCH 12/13] devargs: remove type field Jan Blunck
2017-07-11 23:25 ` [dpdk-dev] [PATCH 13/13] devargs: remove bus field Jan Blunck
2017-07-12 7:29 ` [dpdk-dev] [PATCH 00/13] devargs fixes Thomas Monjalon
2017-07-12 8:09 ` Jan Blunck
2017-07-12 8:50 ` Thomas Monjalon
2017-07-12 9:25 ` Jan Blunck
2017-07-14 21:11 ` [dpdk-dev] [PATCH v2 00/15] " Jan Blunck
2017-07-14 21:11 ` [dpdk-dev] [PATCH v2 01/15] Revert "devargs: make device types generic" Jan Blunck
2017-09-04 16:05 ` Ferruh Yigit
2017-07-14 21:12 ` [dpdk-dev] [PATCH v2 02/15] devargs: fix unittest Jan Blunck
2017-09-04 16:05 ` Ferruh Yigit
2017-07-14 21:12 ` [dpdk-dev] [PATCH v2 03/15] devargs: extend unittest Jan Blunck
2017-09-04 16:05 ` Ferruh Yigit
2017-07-14 21:12 ` [dpdk-dev] [PATCH v2 04/15] devargs: deprecate enum rte_devtype based functions Jan Blunck
2017-09-04 16:06 ` Ferruh Yigit
2017-07-14 21:12 ` [dpdk-dev] [PATCH v2 05/15] pci: use scan_mode configuration Jan Blunck
2017-09-04 16:22 ` Ferruh Yigit
2017-07-14 21:12 ` [dpdk-dev] [PATCH v2 06/15] bus: add configuration interface for buses Jan Blunck
2017-09-04 16:23 ` Ferruh Yigit
2017-07-14 21:12 ` [dpdk-dev] [PATCH v2 07/15] devargs: use bus configuration interface to set scanning mode Jan Blunck
2017-07-14 21:12 ` [dpdk-dev] [PATCH v2 08/15] devargs: use existing functions in rte_eal_devargs_parse() Jan Blunck
2017-09-04 16:24 ` Ferruh Yigit
2017-07-14 21:12 ` [dpdk-dev] [PATCH v2 09/15] devargs: add busname string field Jan Blunck
2017-07-14 21:12 ` [dpdk-dev] [PATCH v2 10/15] devargs: use busname Jan Blunck
2017-07-14 21:12 ` [dpdk-dev] [PATCH v2 11/15] pci: " Jan Blunck
2017-07-14 21:12 ` [dpdk-dev] [PATCH v2 12/15] vdev: " Jan Blunck
2017-07-14 21:12 ` [dpdk-dev] [PATCH v2 13/15] devargs: pass busname argument when parsing Jan Blunck
2017-07-15 14:48 ` Gaëtan Rivet
2017-09-04 16:28 ` Ferruh Yigit
2017-09-04 16:28 ` Ferruh Yigit
2017-07-14 21:12 ` [dpdk-dev] [PATCH v2 14/15] devargs: remove type field Jan Blunck
2017-09-04 16:29 ` Ferruh Yigit
2017-07-14 21:12 ` [dpdk-dev] [PATCH v2 15/15] devargs: remove bus field Jan Blunck
2017-07-15 18:20 ` [dpdk-dev] [PATCH v2 00/15] devargs fixes Thomas Monjalon
2017-09-04 16:04 ` Ferruh Yigit
2017-09-05 8:20 ` Gaëtan Rivet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170711232512.54641-8-jblunck@infradead.org \
--to=jblunck@infradead.org \
--cc=dev@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).