From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f52.google.com (mail-wm0-f52.google.com [74.125.82.52]) by dpdk.org (Postfix) with ESMTP id CE67B5699 for ; Tue, 4 Jul 2017 02:58:53 +0200 (CEST) Received: by mail-wm0-f52.google.com with SMTP id 62so182077352wmw.1 for ; Mon, 03 Jul 2017 17:58:53 -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=WO/mRzdcW2WnmSnRPW82thr8PKLRBzXyhrS7W8GF6U8=; b=jeydBsJsIrT48c0hX+IXpWdBwDa9VO/u4QcPOWDNgob8W4Q2zVKFDAvf8yf2rfXTsj bQyOuSx5LpPY+U0QBojWB8L+CGP2q5a3lKJVajGdQIZn+8BKYDSSuykAqMrXgbwhosR9 WXY6Ri8y3mRR6IbM+TEXlTUb9tKazSShacSFzqe2uJV/AHWbQW5X8CV9fnmh6V7Xxsur PoTmhLiRX+82l9HBgelKUqBYDeHMKQZ0T14nnxEYSJ24HtweejZUDTTYuJwOn4KFsotS D96p5/UD1ECixZFhNXai593W8XxgPLnvH0/5Bj5L7hneu9XT0YWzSjM9720VLUSkkm5J N6wg== 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=WO/mRzdcW2WnmSnRPW82thr8PKLRBzXyhrS7W8GF6U8=; b=f9uwjznmyxWSS1S08tzlQCydD4ttWocRQij9g4gPARXvRGUeApGeLwAdJduUSJhWx7 DYTPofQxZBXniBhFjScIlfsL+JCEU0DdkjRXgeughW5MtYesu4EjjjSPye+xYH+ykcpv epeq9eXsffM5rA0ZeHfP4TInFRXBMBTyxQhXGjD5QN6jQdzq/5YBoI237kvdxJVSoTxc RnIfUCtSmT47UR/IfKdlIlyX1CxTprCVgNpeLW6jg/fAjkQYaw6qOOBJSgbKQmjc4KhN IazvHWYvZNTFo5ZzlYzlemiW4vo49YgNkWpGaLUWbTqCL9TgpGHYgTIZHKJGYA2crMUL mgTA== X-Gm-Message-State: AKS2vOyQCz5ifow1kuIl0mf4koF2rUO69v0FVgtjAEfWfqFKh8HjjA/s 3bGb8gbHXIrgdoMb/A0= X-Received: by 10.28.57.197 with SMTP id g188mr27225002wma.13.1499129933250; Mon, 03 Jul 2017 17:58:53 -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 n189sm15162731wmd.0.2017.07.03.17.58.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 03 Jul 2017 17:58:52 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Tue, 4 Jul 2017 02:58:33 +0200 Message-Id: <3331659a85270eef374f7d491216ededea4e6c88.1499127915.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 v6 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 00:58:54 -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 75a7b93..79ec528 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(VIRTUAL_BUS_NAME); 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(VIRTUAL_BUS_NAME); 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