devargs: parse bus info
authorGaetan Rivet <gaetan.rivet@6wind.com>
Fri, 7 Jul 2017 00:03:12 +0000 (02:03 +0200)
committerThomas Monjalon <thomas@monjalon.net>
Sat, 8 Jul 2017 20:29:38 +0000 (22:29 +0200)
Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
lib/librte_eal/common/eal_common_devargs.c
lib/librte_eal/common/eal_common_vdev.c
lib/librte_eal/common/include/rte_devargs.h

index ffa8ad9..2e97d79 100644 (file)
@@ -78,12 +78,20 @@ rte_eal_parse_devargs_str(const char *devargs_str,
        return 0;
 }
 
+static int
+bus_name_cmp(const struct rte_bus *bus, const void *name)
+{
+       return strncmp(bus->name, name, strlen(bus->name));
+}
+
 /* store a whitelist parameter for later parsing */
 int
 rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
 {
        struct rte_devargs *devargs = NULL;
-       char *buf = NULL;
+       struct rte_bus *bus = NULL;
+       char *dev = NULL;
+       const char *devname;
        int ret;
 
        /* use malloc instead of rte_malloc as it's called early at init */
@@ -94,34 +102,51 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
        memset(devargs, 0, sizeof(*devargs));
        devargs->type = devtype;
 
-       if (rte_eal_parse_devargs_str(devargs_str, &buf, &devargs->args))
+       if (rte_eal_parse_devargs_str(devargs_str, &dev, &devargs->args))
                goto fail;
+       devname = dev;
+       do {
+               bus = rte_bus_find(bus, bus_name_cmp, dev);
+               if (bus == NULL)
+                       break;
+               devname = dev + strlen(bus->name) + 1;
+               if (rte_bus_find_by_device_name(devname) == bus)
+                       break;
+               devname = dev;
+       } while (1);
+       if (bus == NULL) {
+               bus = rte_bus_find_by_device_name(devname);
+               if (bus == NULL) {
+                       fprintf(stderr, "ERROR: failed to parse bus info from device declaration\n");
+                       goto fail;
+               }
+       }
+       devargs->bus = bus;
 
        switch (devargs->type) {
        case RTE_DEVTYPE_WHITELISTED_PCI:
        case RTE_DEVTYPE_BLACKLISTED_PCI:
                /* try to parse pci identifier */
-               if (eal_parse_pci_BDF(buf, &devargs->pci.addr) != 0 &&
-                   eal_parse_pci_DomBDF(buf, &devargs->pci.addr) != 0)
+               if (bus->parse(devname, &devargs->pci.addr) != 0)
                        goto fail;
 
                break;
        case RTE_DEVTYPE_VIRTUAL:
                /* save driver name */
                ret = snprintf(devargs->virt.drv_name,
-                              sizeof(devargs->virt.drv_name), "%s", buf);
+                              sizeof(devargs->virt.drv_name), "%s", devname);
                if (ret < 0 || ret >= (int)sizeof(devargs->virt.drv_name))
                        goto fail;
 
                break;
        }
 
-       free(buf);
+       free(dev);
        TAILQ_INSERT_TAIL(&devargs_list, devargs, next);
        return 0;
 
 fail:
-       free(buf);
+       free(dev);
        if (devargs) {
                free(devargs->args);
                free(devargs);
index 2250b8f..a985294 100644 (file)
@@ -177,6 +177,7 @@ alloc_devargs(const char *name, const char *args)
                return NULL;
 
        devargs->type = RTE_DEVTYPE_VIRTUAL;
+       devargs->bus = rte_bus_find_by_name("vdev");
        if (args)
                devargs->args = strdup(args);
 
@@ -289,12 +290,13 @@ vdev_scan(void)
 {
        struct rte_vdev_device *dev;
        struct rte_devargs *devargs;
+       struct rte_bus *vbus;
 
        /* for virtual devices we scan the devargs_list populated via cmdline */
-
+       vbus = rte_bus_find_by_name("vdev");
        TAILQ_FOREACH(devargs, &devargs_list, next) {
 
-               if (devargs->type != RTE_DEVTYPE_VIRTUAL)
+               if (devargs->bus != vbus)
                        continue;
 
                dev = find_vdev(devargs->virt.drv_name);
index b11cbfc..6014853 100644 (file)
@@ -51,6 +51,7 @@ extern "C" {
 #include <stdio.h>
 #include <sys/queue.h>
 #include <rte_pci.h>
+#include <rte_bus.h>
 
 /**
  * Type of generic device
@@ -89,6 +90,8 @@ struct rte_devargs {
                        char drv_name[RTE_DEV_NAME_MAX_LEN];
                } virt;
        };
+       /** Bus handle for the device. */
+       struct rte_bus *bus;
        /** Arguments string as given by user or "" for no argument. */
        char *args;
 };