From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f47.google.com (mail-wm0-f47.google.com [74.125.82.47]) by dpdk.org (Postfix) with ESMTP id 50B16377E for ; Wed, 5 Jul 2017 01:55:45 +0200 (CEST) Received: by mail-wm0-f47.google.com with SMTP id i127so150650338wma.0 for ; Tue, 04 Jul 2017 16:55:45 -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=ZKUGpAPpebiJRZEb/X+2ChmN3uFUhQ0Tu9M3FWD7AW4=; b=kfMjVQV3/RCISuLyEAZeK866dnYMEpcmuC4GFcXhHE6fToYb9njYIpmNVZJbh8M6NE 6O7xUXCNOHwuMc3ZAoZV+1IwIf4dzYHB535h3qZaZ0mqjIsKhAjjDy8VOoAA1KCEnSVK JpRSpu/GZ2Y5scMSEsql7UroyMsUUXvywIKzlNPA2FxMPuDOv4SPl5vNkXwib/f6raOD hGl27JL31AZUrtZQzZzQoyNioaoaxcOPci0U+Q1xKpK/TZ9raVBpF2OtkCYh035dnBLn eTk/C96rZirbVJfV/meII47JPMIyirJjOczccFBun6+yiXbGooVoE2P6wl2jKN01kRjW wHBQ== 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=ZKUGpAPpebiJRZEb/X+2ChmN3uFUhQ0Tu9M3FWD7AW4=; b=inRLDAxZsEKFeq6ARXxUSWD59rRsJVIzbVqoLow701PIHc47HEuCN8P9RYAE1q9PSW KBnCKvF19+X5HHvJSgrDSq+p0gIIaxsxctWHngbgjjpsG9WZfIPu1lLDQrgCtFdDQdbQ Uqir7H8HmNQTpxV5ufX0lOl6rKKgDIpH08ACpRqkQWvRMNnx8dzYF2O/XKD5iRCvpbvy 1g6DrqRcNcSSAz5f8Va/VvyDF1fju8k4WbPKZ+kGJCyH8MyhCBO6O9/FZlQ0ZseJDQ+3 gRNYmwCCu288TWhBzpOKSH1FHAa1u87K0wTMna8BKAAL5b+awJtJ1fz4dliYVmlOKBVp iEQg== X-Gm-Message-State: AKS2vOxSpllfhJW1A3z8j9tGbwJSjPyFmvaE5r9LVqpdOZmnaXYg+vdu kVKo0ufHM39twZbce0A= X-Received: by 10.28.136.129 with SMTP id k123mr28160548wmd.14.1499212544774; Tue, 04 Jul 2017 16:55:44 -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 19sm23406533wrx.26.2017.07.04.16.55.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 04 Jul 2017 16:55:43 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Wed, 5 Jul 2017 01:55:23 +0200 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v7 6/6] devargs: parse bus info 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: Tue, 04 Jul 2017 23:55:45 -0000 Signed-off-by: Gaetan Rivet --- lib/librte_eal/common/eal_common_devargs.c | 42 ++++++++++++++++++++++++----- lib/librte_eal/common/eal_common_vdev.c | 6 +++-- lib/librte_eal/common/include/rte_devargs.h | 3 +++ 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c index ffa8ad9..102bd8d 100644 --- a/lib/librte_eal/common/eal_common_devargs.c +++ b/lib/librte_eal/common/eal_common_devargs.c @@ -78,12 +78,23 @@ rte_eal_parse_devargs_str(const char *devargs_str, return 0; } +static int +bus_name_cmp(const struct rte_bus *bus, const void *_name) +{ + const char *name = _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 +105,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); diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c index 6ecd1b5..8fd1ef7 100644 --- a/lib/librte_eal/common/eal_common_vdev.c +++ b/lib/librte_eal/common/eal_common_vdev.c @@ -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); diff --git a/lib/librte_eal/common/include/rte_devargs.h b/lib/librte_eal/common/include/rte_devargs.h index 88120a1..1f50a24 100644 --- a/lib/librte_eal/common/include/rte_devargs.h +++ b/lib/librte_eal/common/include/rte_devargs.h @@ -51,6 +51,7 @@ extern "C" { #include #include #include +#include /** * Type of generic device @@ -89,6 +90,8 @@ struct rte_devargs { char drv_name[32]; } virt; }; + /** Bus handle for the device. */ + struct rte_bus *bus; /** Arguments string as given by user or "" for no argument. */ char *args; }; -- 2.1.4