From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f173.google.com (mail-wr0-f173.google.com [209.85.128.173]) by dpdk.org (Postfix) with ESMTP id 782DE7CBF for ; Fri, 7 Jul 2017 02:05:01 +0200 (CEST) Received: by mail-wr0-f173.google.com with SMTP id r103so24312944wrb.0 for ; Thu, 06 Jul 2017 17:05:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=jr4KOknixhtOszbgUhfVWJCMJQ2BVYCxOacIZLI3WsY=; b=sW7Q8OnjWbH7vr3R9jxgfJmHCrTh8iogvcA4mb+muP8J/QY6/I2Xg2uKzqjIeH/QHN pjNKIqNrXVRDcaEXPZMAhRjRzaVXVYHvfXnM23aBc0ookFEVoIc8ssPp+VelrJfg/QKm +29+u42GncZs71kaJvkW4fHEFBXoHr5JtPdHzEBmi6EQP6aOTT7Ba35/A30cKOQdeqeN PNSF/qK+qqgc/csge9AzaG6gvffC/EUkiN/imLAum6WjP8nl0VtbwYh7h/wS82e9uqzw GUws/09aqqY/W8X9fyFDyP7y9HQ70Pj26SpwHKHOqNqAzgDE+s4f1aantUn7OqPF55EX LP+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=jr4KOknixhtOszbgUhfVWJCMJQ2BVYCxOacIZLI3WsY=; b=DDEiYvU1/IOUku7Q5R3MLs9jtzi+PJvnrjiY0/zgRNz1UN8IudhmFD7CP8EFB8w03T fzXOSGDJTUY+DK8i82+yuNDLGpm4UzK7JmDzvKZd6MQEBNs9IAT5R3wyg1oI3SPA6XzH lDBjI8vcp0pYzSzi79WJys6N10O3KUGuiziDCX+2DGVUMIRIrzEMFR7zG1Osgi5nhuIk TMLFMr1GKNe1oGWlmuS5RhdeHY0xy39aTnCAc/IkbgZE9qBEHntNQ1/VKia72jVAW2Wx 4Ah6orYK97MywcMxbqcil1uahtA4W9iL40xukANqPb5ujLOdYJr3L29PFWib3Qe6O9sV YVkQ== X-Gm-Message-State: AIVw112vFqqLlOTJaCKs4/9W7oLozZuh6pT4/1iaDammvUJkRaElZU4F kV52aZ8uhecCAerGnl8= X-Received: by 10.28.92.80 with SMTP id q77mr272164wmb.4.1499385900757; Thu, 06 Jul 2017 17:05:00 -0700 (PDT) Received: from bidouze.dev.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id b197sm1111520wmb.4.2017.07.06.17.04.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 06 Jul 2017 17:04:59 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Fri, 7 Jul 2017 02:04:30 +0200 Message-Id: <0e255e28fe7f18d81706ffd8c87f7aeac4d799a0.1499384590.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v7 13/17] devargs: generic device representation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Jul 2017 00:05:01 -0000 Remove the dependency of this subsystem upon bus specific device representation. Devargs only validates that a device declaration is correct and handled by a bus. The device interpretation is done afterward within the bus. Signed-off-by: Gaetan Rivet --- app/test-pmd/testpmd.c | 9 +----- lib/librte_eal/common/eal_common_devargs.c | 47 +++++------------------------ lib/librte_eal/common/eal_common_pci.c | 9 ++++-- lib/librte_eal/common/eal_common_vdev.c | 11 +++---- lib/librte_eal/common/include/rte_devargs.h | 16 ++-------- lib/librte_eal/common/include/rte_vdev.h | 2 +- test/test/test_devargs.c | 9 ++---- 7 files changed, 26 insertions(+), 77 deletions(-) diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index a7bad73..bce3ecd 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -1810,21 +1810,14 @@ static void rmv_event_callback(void *arg) { struct rte_eth_dev *dev; - struct rte_devargs *da; - char name[32] = ""; uint8_t port_id = (intptr_t)arg; RTE_ETH_VALID_PORTID_OR_RET(port_id); dev = &rte_eth_devices[port_id]; - da = dev->device->devargs; stop_port(port_id); close_port(port_id); - if (da->type == RTE_DEVTYPE_VIRTUAL) - snprintf(name, sizeof(name), "%s", da->virt.drv_name); - else if (da->type == RTE_DEVTYPE_WHITELISTED_PCI) - rte_pci_device_name(&da->pci.addr, name, sizeof(name)); - printf("removing device %s\n", name); + printf("removing device %s\n", dev->device->name); rte_eal_dev_detach(dev->device); dev->state = RTE_ETH_DEV_UNUSED; } diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c index 16052a3..7b4dfca 100644 --- a/lib/librte_eal/common/eal_common_devargs.c +++ b/lib/librte_eal/common/eal_common_devargs.c @@ -40,7 +40,6 @@ #include #include -#include #include #include "eal_private.h" @@ -126,23 +125,10 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str) } devargs->bus = bus; - switch (devargs->type) { - case RTE_DEVTYPE_WHITELISTED_PCI: - case RTE_DEVTYPE_BLACKLISTED_PCI: - /* try to parse pci identifier */ - 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", devname); - if (ret < 0 || ret >= (int)sizeof(devargs->virt.drv_name)) - goto fail; - - break; - } + /* save device name. */ + ret = snprintf(devargs->name, sizeof(devargs->name), "%s", devname); + if (ret < 0 || ret >= (int)sizeof(devargs->name)) + goto fail; if (devargs->type == RTE_DEVTYPE_WHITELISTED_PCI) { if (bus->conf.scan_mode == RTE_BUS_SCAN_UNDEFINED) { bus->conf.scan_mode = RTE_BUS_SCAN_WHITELIST; @@ -194,27 +180,10 @@ rte_eal_devargs_dump(FILE *f) { struct rte_devargs *devargs; - fprintf(f, "User device white list:\n"); + fprintf(f, "User device list:\n"); TAILQ_FOREACH(devargs, &devargs_list, next) { - if (devargs->type == RTE_DEVTYPE_WHITELISTED_PCI) - fprintf(f, " PCI whitelist " PCI_PRI_FMT " %s\n", - devargs->pci.addr.domain, - devargs->pci.addr.bus, - devargs->pci.addr.devid, - devargs->pci.addr.function, - devargs->args); - else if (devargs->type == RTE_DEVTYPE_BLACKLISTED_PCI) - fprintf(f, " PCI blacklist " PCI_PRI_FMT " %s\n", - devargs->pci.addr.domain, - devargs->pci.addr.bus, - devargs->pci.addr.devid, - devargs->pci.addr.function, - devargs->args); - else if (devargs->type == RTE_DEVTYPE_VIRTUAL) - fprintf(f, " VIRTUAL %s %s\n", - devargs->virt.drv_name, - devargs->args); - else - fprintf(f, " UNKNOWN %s\n", devargs->args); + fprintf(f, " [%s]: %s %s\n", + (devargs->bus ? devargs->bus->name : "??"), + devargs->name, devargs->args); } } diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c index d7e2fb4..5838cc6 100644 --- a/lib/librte_eal/common/eal_common_pci.c +++ b/lib/librte_eal/common/eal_common_pci.c @@ -74,12 +74,15 @@ const char *pci_get_sysfs_path(void) static struct rte_devargs *pci_devargs_lookup(struct rte_pci_device *dev) { struct rte_devargs *devargs; + struct rte_pci_addr addr; + struct rte_bus *pbus; + pbus = rte_bus_find_by_name("pci"); TAILQ_FOREACH(devargs, &devargs_list, next) { - if (devargs->type != RTE_DEVTYPE_BLACKLISTED_PCI && - devargs->type != RTE_DEVTYPE_WHITELISTED_PCI) + if (devargs->bus != pbus) continue; - if (!rte_eal_compare_pci_addr(&dev->addr, &devargs->pci.addr)) + devargs->bus->parse(devargs->name, &addr); + if (!rte_eal_compare_pci_addr(&dev->addr, &addr)) return devargs; } return NULL; diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c index 8fd1ef7..639ef73 100644 --- a/lib/librte_eal/common/eal_common_vdev.c +++ b/lib/librte_eal/common/eal_common_vdev.c @@ -181,9 +181,8 @@ alloc_devargs(const char *name, const char *args) if (args) devargs->args = strdup(args); - ret = snprintf(devargs->virt.drv_name, - sizeof(devargs->virt.drv_name), "%s", name); - if (ret < 0 || ret >= (int)sizeof(devargs->virt.drv_name)) { + ret = snprintf(devargs->name, sizeof(devargs->name), "%s", name); + if (ret < 0 || ret >= (int)sizeof(devargs->name)) { free(devargs->args); free(devargs); return NULL; @@ -218,7 +217,7 @@ rte_vdev_init(const char *name, const char *args) dev->device.devargs = devargs; dev->device.numa_node = SOCKET_ID_ANY; - dev->device.name = devargs->virt.drv_name; + dev->device.name = devargs->name; ret = vdev_probe_all_drivers(dev); if (ret) { @@ -299,7 +298,7 @@ vdev_scan(void) if (devargs->bus != vbus) continue; - dev = find_vdev(devargs->virt.drv_name); + dev = find_vdev(devargs->name); if (dev) continue; @@ -309,7 +308,7 @@ vdev_scan(void) dev->device.devargs = devargs; dev->device.numa_node = SOCKET_ID_ANY; - dev->device.name = devargs->virt.drv_name; + dev->device.name = devargs->name; TAILQ_INSERT_TAIL(&vdev_device_list, dev, next); } diff --git a/lib/librte_eal/common/include/rte_devargs.h b/lib/librte_eal/common/include/rte_devargs.h index 6014853..35675fa 100644 --- a/lib/librte_eal/common/include/rte_devargs.h +++ b/lib/librte_eal/common/include/rte_devargs.h @@ -50,7 +50,6 @@ extern "C" { #include #include -#include #include /** @@ -77,21 +76,10 @@ struct rte_devargs { TAILQ_ENTRY(rte_devargs) next; /** Type of device. */ enum rte_devtype type; - RTE_STD_C11 - union { - /** Used if type is RTE_DEVTYPE_*_PCI. */ - struct { - /** PCI location. */ - struct rte_pci_addr addr; - } pci; - /** Used if type is RTE_DEVTYPE_VIRTUAL. */ - struct { - /** Driver name. */ - char drv_name[RTE_DEV_NAME_MAX_LEN]; - } virt; - }; /** Bus handle for the device. */ struct rte_bus *bus; + /** Name of the device. */ + char name[RTE_DEV_NAME_MAX_LEN]; /** Arguments string as given by user or "" for no argument. */ char *args; }; diff --git a/lib/librte_eal/common/include/rte_vdev.h b/lib/librte_eal/common/include/rte_vdev.h index e6b678e..3c07b76 100644 --- a/lib/librte_eal/common/include/rte_vdev.h +++ b/lib/librte_eal/common/include/rte_vdev.h @@ -50,7 +50,7 @@ static inline const char * rte_vdev_device_name(const struct rte_vdev_device *dev) { if (dev && dev->device.devargs) - return dev->device.devargs->virt.drv_name; + return dev->device.devargs->name; return NULL; } diff --git a/test/test/test_devargs.c b/test/test/test_devargs.c index 63242f1..18f54ed 100644 --- a/test/test/test_devargs.c +++ b/test/test/test_devargs.c @@ -90,8 +90,8 @@ test_devargs(void) if (rte_eal_devargs_add(RTE_DEVTYPE_VIRTUAL, "net_ring1,k1=val,k2=val2") < 0) goto fail; devargs = TAILQ_FIRST(&devargs_list); - if (strncmp(devargs->virt.drv_name, "net_ring1", - sizeof(devargs->virt.drv_name)) != 0) + if (strncmp(devargs->name, "net_ring1", + sizeof(devargs->name)) != 0) goto fail; if (!devargs->args || strcmp(devargs->args, "k1=val,k2=val2") != 0) goto fail; @@ -101,10 +101,7 @@ test_devargs(void) if (rte_eal_devargs_add(RTE_DEVTYPE_WHITELISTED_PCI, "04:00.1") < 0) goto fail; devargs = TAILQ_FIRST(&devargs_list); - if (devargs->pci.addr.domain != 0 || - devargs->pci.addr.bus != 4 || - devargs->pci.addr.devid != 0 || - devargs->pci.addr.function != 1) + if (strcmp(devargs->name, "04:00.1") != 0) goto fail; if (!devargs->args || strcmp(devargs->args, "") != 0) goto fail; -- 2.1.4