From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f196.google.com (mail-wr0-f196.google.com [209.85.128.196]) by dpdk.org (Postfix) with ESMTP id E0CA55A98 for ; Wed, 12 Jul 2017 01:25:41 +0200 (CEST) Received: by mail-wr0-f196.google.com with SMTP id x23so1757731wrb.0 for ; Tue, 11 Jul 2017 16:25:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=91yd6ClnNArOTeps7w8qqhlxCYUIgHrHBjCpVEBqEYk=; b=PJMZhMII/dJ2uceZ5yydXRJrlHi3k4CVmeTMb0OO/5UcZf19t6MVLUO2wcuY0tLU/J euwEkC/+vxiP/7KX7OgVmILik9LLPZzUKnxPhE04eVgFdrOPxbrWajcaurmLJQ53kmDU TnqG+i3BmwLwlkrDAq9BPfxukgZIWtFceBCY9tJng7S43U679NVMgkB3HJdigCE0g1ET 0qtA1Hj9yBOi3wxmOSI7F4u27orQLodZeGko4o+pX/MeLzVMRKQ4vfFvU0P4SSHRnv4g sCK6b8te0Nq9ucQZmqnOUkMHKcOhEEp8xl9QvzDIQJWTpB8gGIl/F+Xs8hPuxx+5ldZc vRJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=91yd6ClnNArOTeps7w8qqhlxCYUIgHrHBjCpVEBqEYk=; b=SQwtoioB79CGlBWOBEk6uhzCP5b0hiAHyqTwVqN2CGfS55uERuS+wtZPvYqdr5csZ8 dCy4efM9p47mZSWVCwp2WYtwBIrRzLKg4rNSMAZqd/VkZrfRf0qFZuNr0tqc6ZyKyfun g9izm+GaM0kB07U1EsN7mHyjh58UBR8xRM5gZniTPpWdBgSyosuwEOy4liCGMlndFnS5 0/4SXmaP5SDngd1AjAgn/2cUGIgdQBu1sthpRD+ju+02Pk0gMQeiAmfZVtHHGE6UCrei teEEW8YB1RS7F3JELfkKLkhUz2pWb5jn4qp+NDe956ahy10V9ngaf3WW1vpGSSX3oPC7 QjGQ== X-Gm-Message-State: AIVw110xChgUo1XKmAjhs8VLHbC+2om+nPdcQBkxL/VUCQpXN2AX6nt4 J+APYQEq2K3jzydG X-Received: by 10.80.177.182 with SMTP id m51mr4074513edd.111.1499815541403; Tue, 11 Jul 2017 16:25:41 -0700 (PDT) Received: from localhost.localdomain ([37.228.147.16]) by smtp.gmail.com with ESMTPSA id k45sm311516ede.16.2017.07.11.16.25.40 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 11 Jul 2017 16:25:40 -0700 (PDT) Sender: Jan Blunck From: Jan Blunck To: dev@dpdk.org Date: Tue, 11 Jul 2017 19:25:06 -0400 Message-Id: <20170711232512.54641-8-jblunck@infradead.org> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170711232512.54641-1-jblunck@infradead.org> References: <20170711232512.54641-1-jblunck@infradead.org> Subject: [dpdk-dev] [PATCH 07/13] devargs: add busname string field 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, 11 Jul 2017 23:25:42 -0000 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 --- 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