From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wi0-f172.google.com (mail-wi0-f172.google.com [209.85.212.172]) by dpdk.org (Postfix) with ESMTP id 7C0F36B7F for ; Sat, 1 Mar 2014 13:13:17 +0100 (CET) Received: by mail-wi0-f172.google.com with SMTP id r20so1713930wiv.11 for ; Sat, 01 Mar 2014 04:14:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XJluK9WTpxiwKQfVWMuq/aRVimSVSDNG2NhE+glDzgg=; b=MH+D3iR2lKuCgek7yIHpa5bcm4kaQoOtapnExST/PJJwX3C6jfwflyQ/wJ38Y0KX78 rO2W9XKVfPeQuY2cq34N8MNPYnV2/FwUYZDiI9FdxcfqEqFSp20eeILu+V0LrsdLq+a0 ALBLzCY13NxwPcvplDnVyBJV3Xf7Mi6deEAP9/DkBxqoIVpiaA6MZBmXuCF3FpX0P7Gp loGyrH7Ro66/uOMlWZrEBZBYc39mW8kPQoJ44S8oeqy6AmsHMhG5J+WflGMkJi8w5AJc Huh2JnUjYtkZ9ijdHvhT34cqecUlv9OUMTlRNYVWMYUkU4NlfUZiIqpRYAfhPtfkJGNV 1WLA== X-Gm-Message-State: ALoCoQm5ImdL1eFrdDkiYD6Iv27i/3c6FoU1oveY4CeWNsxmGNG1rWqqaJiQ8/gQpJoYrjOTSzF1 X-Received: by 10.194.92.7 with SMTP id ci7mr1287624wjb.58.1393676084536; Sat, 01 Mar 2014 04:14:44 -0800 (PST) Received: from glumotte.dev.6wind.com (guy78-3-82-239-227-177.fbx.proxad.net. [82.239.227.177]) by mx.google.com with ESMTPSA id h13sm12045619wjr.22.2014.03.01.04.14.42 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 01 Mar 2014 04:14:43 -0800 (PST) From: Olivier Matz To: dev@dpdk.org Date: Sat, 1 Mar 2014 13:14:34 +0100 Message-Id: <1393676074-17703-1-git-send-email-olivier.matz@6wind.com> X-Mailer: git-send-email 1.8.5.3 In-Reply-To: <1393608350-4431-4-git-send-email-olivier.matz@6wind.com> References: <1393608350-4431-4-git-send-email-olivier.matz@6wind.com> Subject: [dpdk-dev] [PATCH v2 03/11] devices-args: use rte_devargs and remove old whitelist code X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 01 Mar 2014 12:13:18 -0000 Remove old whitelist code: - remove references to rte_pmd_ring, rte_pmd_pcap and pmd_xenvirt in is_valid_wl_entry() as we want to be able to register external virtual drivers as a shared library. Moreover this code was duplicated with dev_types[] from eal_common_pci.c - eal_common_whitelist.c was badly named: it was able to process PCI devices white list and the registration of virtual devices - the parsing code was complex: all arguments were prepended in one string dev_list_str[4096], then split again Use the newly introduced rte_devargs to get: - the PCI white list - the PCI black list - the list of virtual devices Rework the tests: - a part of the whitelist test can be removed as it is now tested in app/test/test_devargs.c - the other parts are just reworked to adapt them to the new API This commit induce a small API modification: it is not possible to specify several devices per "--use-device" option. This notation was anyway a bit cryptic. Ex: --use-device="eth_ring0,eth_pcap0;iface=ixgbe0" now becomes: --use-device="eth_ring0" --use-device="eth_pcap0;iface=ixgbe0" On the other hand, it is now possible to work in PCI blacklist mode and instanciate virtual drivers, which was not possible before this patch. Test result: ./app/test -c 0x15 -n 3 -m 64 RTE>>devargs_autotest EAL: invalid PCI identifier <08:1> EAL: invalid PCI identifier <00.1> EAL: invalid PCI identifier EAL: invalid PCI identifier <> EAL: invalid PCI identifier <000f:0:0> Test OK Signed-off-by: Olivier Matz --- app/test/test_eal_flags.c | 49 +----- app/test/test_pci.c | 51 +++--- lib/librte_eal/common/eal_common_nonpci_devs.c | 36 +++- lib/librte_eal/common/eal_common_pci.c | 60 +++---- lib/librte_eal/common/eal_common_whitelist.c | 227 ------------------------- lib/librte_eal/common/include/eal_private.h | 38 ----- lib/librte_eal/common/include/rte_pci.h | 10 -- lib/librte_eal/linuxapp/eal/Makefile | 1 - lib/librte_eal/linuxapp/eal/eal.c | 79 +++++---- lib/librte_pmd_ring/rte_eth_ring.c | 2 +- 10 files changed, 132 insertions(+), 421 deletions(-) delete mode 100644 lib/librte_eal/common/eal_common_whitelist.c v2 changes: * passed checkpatch.pl diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c index 964a3a9..9bab1a5 100644 --- a/app/test/test_eal_flags.c +++ b/app/test/test_eal_flags.c @@ -2,6 +2,7 @@ * BSD LICENSE * * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. + * Copyright(c) 2014 6WIND S.A. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -271,20 +272,6 @@ get_current_prefix(char * prefix, int size) return prefix; } -/* extra function prototypes for internal eal function to test in whitelist - * ICC 12 doesn't approve of this practice, so temporarily disable warnings for it */ -#ifdef __INTEL_COMPILER -#pragma warning disable 1419 -#endif -extern int eal_dev_whitelist_exists(void); -extern int eal_dev_whitelist_add_entry(const char *); -extern int eal_dev_whitelist_parse(void); -extern int eal_dev_is_whitelisted(const char *, const char **); -extern void eal_dev_whitelist_clear(void); -#ifdef __INTEL_COMPILER -#pragma warning enable 1419 -#endif - /* * Test that the app doesn't run with invalid whitelist option. * Final tests ensures it does run with valid options as sanity check (one @@ -319,17 +306,15 @@ test_whitelist_flag(void) use_device, "error0:0:0.1", "", ""}, {prgname, prefix, mp_flag, "-n", "1", "-c", "1", use_device, "0:0:0.1.2", "", ""}, - {prgname, prefix, mp_flag, "-n", "1", "-c", "1", - use_device, "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x", - use_device, "y,z,1,2,3,4,5,6,7,8,9,0"}, }; /* Test with valid whitelist option */ const char *wlval1[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", use_device, "00FF:09:0B.3"}; const char *wlval2[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", - use_device, "09:0B.3,0a:0b.1"}; + use_device, "09:0B.3", use_device, "0a:0b.1"}; const char *wlval3[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", - use_device, "09:0B.3;type=test,08:00.1;type=normal"}; + use_device, "09:0B.3;type=test", + use_device, "08:00.1;type=normal"}; for (i = 0; i < sizeof(wlinval) / sizeof(wlinval[0]); i++) { if (launch_proc(wlinval[i]) == 0) { @@ -351,32 +336,6 @@ test_whitelist_flag(void) return -1; } - /* extra-sanity checks of whitelists - to be run only if no whitelist */ - if (eal_dev_whitelist_exists()) - return 0; - - /* check that whitelist_parse returns error without whitelist */ - if (eal_dev_whitelist_parse() != -1) { - printf("ERROR: calling whitelist parse without a whitelist doesn't " - "return an error\n"); - return -1; - } - if (eal_dev_is_whitelisted("adevice", NULL)) { - printf("Whitelist lookup does not return false if no whitelist\n"); - return -1; - } - eal_dev_whitelist_add_entry("0000:00:00.0"); - eal_dev_whitelist_parse(); - if (eal_dev_is_whitelisted("adevice", NULL)) { - printf("Whitelist lookup does not return false for unlisted dev\n"); - return -1; - } - if (!eal_dev_is_whitelisted("0000:00:00.0", NULL)) { - printf("Whitelist lookup does not return true for whitelisted dev\n"); - return -1; - } - eal_dev_whitelist_clear(); - return 0; } diff --git a/app/test/test_pci.c b/app/test/test_pci.c index 64b13c1..223d76a 100644 --- a/app/test/test_pci.c +++ b/app/test/test_pci.c @@ -2,6 +2,7 @@ * BSD LICENSE * * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. + * Copyright(c) 2014 6WIND S.A. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -38,12 +39,11 @@ #include #include +#include #include "test.h" -#define TEST_BLACKLIST_NUM 0x100 - /* * PCI test * ======== @@ -58,7 +58,6 @@ int test_pci_run = 0; /* value checked by the multiprocess test */ static unsigned pci_dev_count; static unsigned driver_registered = 0; -static struct rte_pci_addr blacklist[TEST_BLACKLIST_NUM]; static int my_driver_init(struct rte_pci_driver *dr, struct rte_pci_device *dev); @@ -116,37 +115,42 @@ my_driver_init(__attribute__((unused)) struct rte_pci_driver *dr, } static void -blacklist_clear(void) -{ - rte_eal_pci_set_blacklist(NULL, 0); -} - - - -static void blacklist_all_devices(void) { struct rte_pci_device *dev = NULL; - unsigned idx = 0; - - memset(blacklist, 0, sizeof (blacklist)); + unsigned i = 0; + char pci_addr_str[16]; TAILQ_FOREACH(dev, &device_list, next) { - if (idx >= sizeof (blacklist) / sizeof (blacklist[0])) { - printf("Error: too many devices to blacklist"); + snprintf(pci_addr_str, sizeof(pci_addr_str), PCI_PRI_FMT, + dev->addr.domain, dev->addr.bus, dev->addr.devid, + dev->addr.function); + if (rte_eal_devargs_add(RTE_DEVTYPE_BLACKLISTED_PCI, + pci_addr_str) < 0) { + printf("Error: cannot blacklist <%s>", pci_addr_str); break; } - blacklist[idx] = dev->addr; - ++idx; + i++; } + printf("%u devices blacklisted\n", i); +} + +/* clear devargs list that was modified by the test */ +static void free_devargs_list(void) +{ + struct rte_devargs *devargs; - rte_eal_pci_set_blacklist(blacklist, idx); - printf("%u devices blacklisted\n", idx); + while (!TAILQ_EMPTY(&devargs_list)) { + devargs = TAILQ_FIRST(&devargs_list); + TAILQ_REMOVE(&devargs_list, devargs, next); + free(devargs); + } } int test_pci(void) { + struct rte_devargs_list save_devargs_list; printf("Dump all devices\n"); rte_eal_pci_dump(); @@ -165,13 +169,18 @@ test_pci(void) return -1; } + /* save the real devargs_list */ + save_devargs_list = devargs_list; + TAILQ_INIT(&devargs_list); + blacklist_all_devices(); pci_dev_count = 0; printf("Scan bus with all devices blacklisted\n"); rte_eal_pci_probe(); - blacklist_clear(); + free_devargs_list(); + devargs_list = save_devargs_list; if (pci_dev_count != 0) { printf("not all devices are blacklisted\n"); diff --git a/lib/librte_eal/common/eal_common_nonpci_devs.c b/lib/librte_eal/common/eal_common_nonpci_devs.c index 1c9c88b..71cbb1e 100644 --- a/lib/librte_eal/common/eal_common_nonpci_devs.c +++ b/lib/librte_eal/common/eal_common_nonpci_devs.c @@ -2,6 +2,7 @@ * BSD LICENSE * * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. + * Copyright(c) 2014 6WIND S.A. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,6 +32,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #ifdef RTE_LIBRTE_PMD_RING @@ -42,6 +44,8 @@ #ifdef RTE_LIBRTE_PMD_XENVIRT #include #endif +#include +#include #include "eal_private.h" struct device_init { @@ -78,15 +82,29 @@ struct device_init dev_types[] = { int rte_eal_non_pci_ethdev_init(void) { - uint8_t i, j; - for (i = 0; i < NUM_DEV_TYPES; i++) { - for (j = 0; j < RTE_MAX_ETHPORTS; j++) { - const char *params; - char buf[16]; - rte_snprintf(buf, sizeof(buf), "%s%"PRIu8, - dev_types[i].dev_prefix, j); - if (eal_dev_is_whitelisted(buf, ¶ms)) - dev_types[i].init_fn(buf, params); + struct rte_devargs *devargs; + uint8_t i; + + /* call the init function for each virtual device */ + TAILQ_FOREACH(devargs, &devargs_list, next) { + + if (devargs->type != RTE_DEVTYPE_VIRTUAL) + continue; + + for (i = 0; i < NUM_DEV_TYPES; i++) { + /* search a driver prefix in virtual device name */ + if (!strncmp(dev_types[i].dev_prefix, + devargs->virtual.drv_name, + sizeof(dev_types[i].dev_prefix) - 1)) { + dev_types[i].init_fn(devargs->virtual.drv_name, + devargs->args); + break; + } + } + + if (i == NUM_DEV_TYPES) { + rte_panic("no driver found for %s\n", + devargs->virtual.drv_name); } } return 0; diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c index 9c9e842..0ab7e9c 100644 --- a/lib/librte_eal/common/eal_common_pci.c +++ b/lib/librte_eal/common/eal_common_pci.c @@ -61,6 +61,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include @@ -77,29 +78,23 @@ #include #include #include +#include #include "eal_private.h" struct pci_driver_list driver_list; struct pci_device_list device_list; -static struct rte_pci_addr *dev_blacklist = NULL; -static unsigned dev_blacklist_size = 0; - static int is_blacklisted(struct rte_pci_device *dev) { - struct rte_pci_addr *loc = &dev->addr; - unsigned i; - - for (i = 0; i < dev_blacklist_size; i++) { - if ((loc->domain == dev_blacklist[i].domain) && - (loc->bus == dev_blacklist[i].bus) && - (loc->devid == dev_blacklist[i].devid) && - (loc->function == dev_blacklist[i].function)) { + struct rte_devargs *devargs; + + TAILQ_FOREACH(devargs, &devargs_list, next) { + if (devargs->type != RTE_DEVTYPE_BLACKLISTED_PCI) + continue; + if (!memcmp(&dev->addr, &devargs->pci.addr, sizeof(dev->addr))) return 1; - } } - return 0; /* not in blacklist */ } @@ -143,16 +138,15 @@ pci_probe_all_drivers(struct rte_pci_device *dev) static int pcidev_is_whitelisted(struct rte_pci_device *dev) { - char buf[16]; - if (dev->addr.domain == 0) { - rte_snprintf(buf, sizeof(buf), PCI_SHORT_PRI_FMT, dev->addr.bus, - dev->addr.devid, dev->addr.function); - if (eal_dev_is_whitelisted(buf, NULL)) + struct rte_devargs *devargs; + + TAILQ_FOREACH(devargs, &devargs_list, next) { + if (devargs->type != RTE_DEVTYPE_WHITELISTED_PCI) + continue; + if (!memcmp(&dev->addr, &devargs->pci.addr, sizeof(dev->addr))) return 1; } - rte_snprintf(buf, sizeof(buf), PCI_PRI_FMT, dev->addr.domain,dev->addr.bus, - dev->addr.devid, dev->addr.function); - return eal_dev_is_whitelisted(buf, NULL); + return 0; } /* @@ -164,14 +158,19 @@ int rte_eal_pci_probe(void) { struct rte_pci_device *dev = NULL; + int probe_all = 0; - TAILQ_FOREACH(dev, &device_list, next) - if (!eal_dev_whitelist_exists()) + if (rte_eal_devargs_type_count(RTE_DEVTYPE_WHITELISTED_PCI) == 0) + probe_all = 1; + + TAILQ_FOREACH(dev, &device_list, next) { + if (probe_all) pci_probe_all_drivers(dev); - else if (pcidev_is_whitelisted(dev) && pci_probe_all_drivers(dev) < 0 ) - rte_exit(EXIT_FAILURE, "Requested device " PCI_PRI_FMT - " cannot be used\n", dev->addr.domain,dev->addr.bus, - dev->addr.devid, dev->addr.function); + else if (pcidev_is_whitelisted(dev) && pci_probe_all_drivers(dev) < 0) + rte_exit(EXIT_FAILURE, "Requested device " PCI_PRI_FMT + " cannot be used\n", dev->addr.domain, dev->addr.bus, + dev->addr.devid, dev->addr.function); + } return 0; } @@ -220,10 +219,3 @@ rte_eal_pci_unregister(struct rte_pci_driver *driver) { TAILQ_REMOVE(&driver_list, driver, next); } - -void -rte_eal_pci_set_blacklist(struct rte_pci_addr *blacklist, unsigned size) -{ - dev_blacklist = blacklist; - dev_blacklist_size = size; -} diff --git a/lib/librte_eal/common/eal_common_whitelist.c b/lib/librte_eal/common/eal_common_whitelist.c deleted file mode 100644 index 9cc0446..0000000 --- a/lib/librte_eal/common/eal_common_whitelist.c +++ /dev/null @@ -1,227 +0,0 @@ -/*- - * BSD LICENSE - * - * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Intel Corporation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -/** - * This file provides functions for managing a whitelist of devices. An EAL - * command-line parameter should be used for specifying what devices to - * whitelist, and the functions here should be called in handling that - * parameter. Then when scanning the PCI bus, the is_whitelisted() function - * can be used to query the previously set up whitelist. - */ -#include -#include -#include -#include -#include -#include -#ifdef RTE_LIBRTE_PMD_RING -#include -#endif -#ifdef RTE_LIBRTE_PMD_PCAP -#include -#endif -#ifdef RTE_LIBRTE_PMD_XENVIRT -#include -#endif -#include "eal_private.h" - -static char dev_list_str[4096]; -static size_t dev_list_str_len = 0; - -/* - * structure for storing a whitelist entry. Unlike for blacklists, we may - * in future use this for dummy NICs not backed by a physical device, e.g. - * backed by a file-system object instead, so we store the device path/addr - * as a string, rather than as a PCI Bus-Device-Function. - */ -static struct whitelist_entry { - const char *device_str; - const char *device_params; -} whitelist[RTE_MAX_ETHPORTS] = { {NULL, NULL} }; - -static unsigned num_wl_entries = 0; - -/* store a whitelist parameter for later parsing */ -int -eal_dev_whitelist_add_entry(const char *entry) -{ - dev_list_str_len += rte_snprintf(&dev_list_str[dev_list_str_len], - sizeof(dev_list_str)-dev_list_str_len, "%s,", entry); - /* check for strings that won't fit (snprintf doesn't go beyond buffer) */ - if (dev_list_str_len >= sizeof(dev_list_str)) { - dev_list_str_len = sizeof(dev_list_str) - 1; - return -1; - } - - return 0; -} - -/* check if a whitelist has been set up */ -int -eal_dev_whitelist_exists(void) -{ - return !!dev_list_str_len; -} - -/* sanity checks a whitelist entry to ensure device is correct */ -static int -is_valid_wl_entry(const char *device_str, size_t dev_buf_len) -{ -#define NUM_PREFIXES (sizeof(non_pci_prefixes)/sizeof(non_pci_prefixes[0])) - static const char *non_pci_prefixes[] = { -#ifdef RTE_LIBRTE_PMD_RING - RTE_ETH_RING_PARAM_NAME, -#endif -#ifdef RTE_LIBRTE_PMD_PCAP - RTE_ETH_PCAP_PARAM_NAME, -#endif -#ifdef RTE_LIBRTE_PMD_XENVIRT - RTE_ETH_XENVIRT_PARAM_NAME, -#endif - "-nodev-" /* dummy value to prevent compiler warnings */ - }; - static uint8_t prefix_counts[NUM_PREFIXES] = {0}; - char buf[16]; - unsigned i; - struct rte_pci_addr pci_addr = { .domain = 0 }; - - if (eal_parse_pci_BDF(device_str, &pci_addr) == 0) { - size_t n = rte_snprintf(buf, sizeof(buf), PCI_SHORT_PRI_FMT, - pci_addr.bus, pci_addr.devid, pci_addr.function); - return (n == dev_buf_len) && (!strncmp(buf, device_str, dev_buf_len)); - } - if (eal_parse_pci_DomBDF(device_str, &pci_addr) == 0) { - size_t n = rte_snprintf(buf, sizeof(buf), PCI_PRI_FMT, pci_addr.domain, - pci_addr.bus, pci_addr.devid, pci_addr.function); - return (n == dev_buf_len) && (!strncmp(buf, device_str, dev_buf_len)); - } - for (i = 0; i < NUM_PREFIXES; i++) { - size_t n = rte_snprintf(buf, sizeof(buf), "%s%u", - non_pci_prefixes[i], prefix_counts[i]); - if ((n == dev_buf_len) && (!strncmp(buf, device_str, dev_buf_len))) { - prefix_counts[i]++; - return 1; - } - } - return 0; -} - -/* - * parse a whitelist string into a set of valid devices. To be called once - * all parameters have been added to the whitelist string. - */ -int -eal_dev_whitelist_parse(void) -{ - char *devs[RTE_MAX_ETHPORTS + 1] = { NULL }; - int i, num_devs; - unsigned dev_name_len, j; - - if (!eal_dev_whitelist_exists()) - return -1; - - /* strip off any extra commas */ - if (dev_list_str[dev_list_str_len - 1] == ',') - dev_list_str[--dev_list_str_len] = '\0'; - - /* split on commas into separate device entries */ - num_devs = rte_strsplit(dev_list_str, sizeof(dev_list_str), devs, - RTE_MAX_ETHPORTS+1, ','); - if (num_devs > RTE_MAX_ETHPORTS) { - RTE_LOG(ERR, EAL, "Error, too many devices specified. " - "[RTE_MAX_ETHPORTS = %u]\n", (unsigned)RTE_MAX_ETHPORTS); - return -1; - } - - size_t buf_len_rem = sizeof(dev_list_str); /* for tracking buffer length */ - for (i = 0; i < num_devs; i++) { - char *dev_n_params[2]; /* possibly split device name from params*/ - - size_t curr_len = strnlen(devs[i], buf_len_rem); - buf_len_rem-= (curr_len + 1); - - int split_res = rte_strsplit(devs[i], curr_len, dev_n_params, 2, ';'); - - /* device names go lower case, i.e. '00:0A.0' wouldn't work - * while '00:0a.0' would. */ - dev_name_len = strnlen(dev_n_params[0], curr_len); - for (j = 0; j < dev_name_len; j++) - dev_n_params[0][j] = (char)tolower((int)dev_n_params[0][j]); - - switch (split_res) { - case 2: - whitelist[i].device_params = dev_n_params[1]; /* fallthrough */ - case 1: - whitelist[i].device_str = dev_n_params[0]; - break; - default: /* should never ever occur */ - rte_panic("Fatal error parsing whitelist [--use-device] options\n"); - } - - if (!is_valid_wl_entry(whitelist[i].device_str, - strnlen(whitelist[i].device_str, curr_len))) { - RTE_LOG(ERR, EAL, "Error parsing device identifier: '%s'\n", - whitelist[i].device_str); - return -1; - } - } - num_wl_entries = num_devs; - return 0; -} - -/* check if a device is on the whitelist */ -int -eal_dev_is_whitelisted(const char *device_str, const char **params) -{ - unsigned i; - if (!eal_dev_whitelist_exists()) - return 0; /* return false if no whitelist set up */ - - for (i = 0; i < num_wl_entries; i++) - if (strncmp(device_str, whitelist[i].device_str, 32) == 0) { - if (params != NULL) - *params = whitelist[i].device_params; - return 1; - } - - return 0; -} - -/* clear the whole whitelist */ -void -eal_dev_whitelist_clear(void) -{ - dev_list_str[0] = '\0'; - dev_list_str_len = num_wl_entries = 0; -} diff --git a/lib/librte_eal/common/include/eal_private.h b/lib/librte_eal/common/include/eal_private.h index 251f15e..f9a019b 100644 --- a/lib/librte_eal/common/include/eal_private.h +++ b/lib/librte_eal/common/include/eal_private.h @@ -197,44 +197,6 @@ int rte_eal_intr_init(void); int rte_eal_alarm_init(void); /** - * When parsing command-line args add a new entry to the whitelist string - * to be parsed, i.e. this is used to join multiple --use-device flags together - * - * This function is private to EAL - */ -int eal_dev_whitelist_add_entry(const char *entry); - -/** - * Returns true if whitelist parameters are available for parsing, - * false otherwise. - * - * This function is private to EAL - */ -int eal_dev_whitelist_exists(void); - -/** - * Parse the combined whitelist options into a single white-list for later use. - * - * This function is private to EAL - */ -int eal_dev_whitelist_parse(void); - -/** - * Check if a particular device is whitelisted or not. Returns true if the - * device is in the whitelist. - * - * This function is private to EAL - */ -int eal_dev_is_whitelisted(const char *device_str, const char **params); - -/** - * This function clears the whitelist settings. - * - * This function is private to the EAL. - */ -void eal_dev_whitelist_clear(void); - -/** * This function initialises any non-PCI i.e. dummy ethernet devices * * This function is private to the EAL. diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h index 9d4f94f..0aee5ff 100644 --- a/lib/librte_eal/common/include/rte_pci.h +++ b/lib/librte_eal/common/include/rte_pci.h @@ -290,16 +290,6 @@ void rte_eal_pci_register(struct rte_pci_driver *driver); */ void rte_eal_pci_unregister(struct rte_pci_driver *driver); -/** - * Register a list of PCI locations that will be blacklisted (not used by DPDK). - * - * @param blacklist - * List of PCI device addresses that will not be used by DPDK. - * @param size - * Number of items in the list. - */ -void rte_eal_pci_set_blacklist(struct rte_pci_addr *blacklist, unsigned size); - #ifdef __cplusplus } #endif diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile index f57fda5..bdd940d 100644 --- a/lib/librte_eal/linuxapp/eal/Makefile +++ b/lib/librte_eal/linuxapp/eal/Makefile @@ -76,7 +76,6 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_tailqs.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_errno.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_cpuflags.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_hexdump.c -SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_whitelist.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_devargs.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_nonpci_devs.c diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c index db0e15c..e9e97dc 100644 --- a/lib/librte_eal/linuxapp/eal/eal.c +++ b/lib/librte_eal/linuxapp/eal/eal.c @@ -2,7 +2,7 @@ * BSD LICENSE * * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. - * Copyright(c) 2012-2013 6WIND S.A. + * Copyright(c) 2012-2014 6WIND S.A. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -69,6 +69,7 @@ #include #include #include +#include #include #include #include @@ -142,8 +143,6 @@ static struct rte_config rte_config = { .mem_config = &early_mem_config, }; -static struct rte_pci_addr eal_dev_blacklist[RTE_EAL_BLACKLIST_SIZE]; - /* internal configuration (per-core) */ struct lcore_config lcore_config[RTE_MAX_LCORE]; @@ -350,9 +349,11 @@ eal_usage(const char *prgname) " --"OPT_HUGE_DIR" : directory where hugetlbfs is mounted\n" " --"OPT_PROC_TYPE" : type of this process\n" " --"OPT_FILE_PREFIX": prefix for hugepage filenames\n" - " --"OPT_USE_DEVICE": use the specified ethernet device(s) only. " - "Use comma-separate <[domain:]bus:devid.func> values.\n" - " [NOTE: Cannot be used with -b option]\n" + " --"OPT_USE_DEVICE": use the specified ethernet device(s) only.\n" + " The argument format is <[domain:]bus:devid.func> to add\n" + " a PCI device to the white list or [;key=val;...]\n" + " to add a virtual device.\n" + " [NOTE: PCI whitelist cannot be used with -b option]\n" " --"OPT_VMWARE_TSC_MAP": use VMware TSC map instead of " "native RDTSC\n" " --"OPT_BASE_VIRTADDR": specify base virtual address\n" @@ -600,20 +601,31 @@ eal_parse_proc_type(const char *arg) return RTE_PROC_INVALID; } -static ssize_t -eal_parse_blacklist_opt(const char *optarg, size_t idx) +static int +eal_parse_use_device(const char *optarg) { - if (idx >= sizeof (eal_dev_blacklist) / sizeof (eal_dev_blacklist[0])) { - RTE_LOG(ERR, EAL, "%s - too many devices to blacklist...\n", optarg); - return (-EINVAL); - } else if (eal_parse_pci_DomBDF(optarg, eal_dev_blacklist + idx) < 0 && - eal_parse_pci_BDF(optarg, eal_dev_blacklist + idx) < 0) { - RTE_LOG(ERR, EAL, "%s - invalid device to blacklist...\n", optarg); - return (-EINVAL); + struct rte_pci_addr addr; + char *dup, *sep; + + dup = strdup(optarg); + if (dup == NULL) + return -1; + + /* remove arguments in 'dup' string */ + sep = strchr(dup, ';'); + if (sep != NULL) + *sep = '\0'; + + /* if argument is a PCI address, it's a whitelisted device */ + if (eal_parse_pci_DomBDF(dup, &addr) == 0 || + eal_parse_pci_BDF(dup, &addr) == 0) { + rte_eal_devargs_add(RTE_DEVTYPE_WHITELISTED_PCI, optarg); + } else { + rte_eal_devargs_add(RTE_DEVTYPE_VIRTUAL, optarg); } - idx += 1; - return (idx); + free(dup); + return 0; } /* Parse the argument given in the command line of the application */ @@ -624,7 +636,6 @@ eal_parse_args(int argc, char **argv) char **argvopt; int option_index; int coremask_ok = 0; - ssize_t blacklist_index = 0; char *prgname = argv[0]; static struct option lgopts[] = { {OPT_NO_HUGE, 0, 0, 0}, @@ -677,8 +688,8 @@ eal_parse_args(int argc, char **argv) switch (opt) { /* blacklist */ case 'b': - if ((blacklist_index = eal_parse_blacklist_opt(optarg, - blacklist_index)) < 0) { + if (rte_eal_devargs_add(RTE_DEVTYPE_BLACKLISTED_PCI, + optarg) < 0) { eal_usage(prgname); return (-1); } @@ -782,7 +793,12 @@ eal_parse_args(int argc, char **argv) } } else if (!strcmp(lgopts[option_index].name, OPT_USE_DEVICE)) { - eal_dev_whitelist_add_entry(optarg); + if (eal_parse_use_device(optarg) < 0) { + RTE_LOG(ERR, EAL, "invalid parameters for --" + OPT_USE_DEVICE "\n"); + eal_usage(prgname); + return -1; + } } else if (!strcmp(lgopts[option_index].name, OPT_SYSLOG)) { if (eal_parse_syslog(optarg) < 0) { @@ -858,20 +874,13 @@ eal_parse_args(int argc, char **argv) eal_usage(prgname); return -1; } - /* if no blacklist, parse a whitelist */ - if (blacklist_index > 0) { - if (eal_dev_whitelist_exists()) { - RTE_LOG(ERR, EAL, "Error: blacklist [-b] and whitelist " - "[--use-device] options cannot be used at the same time\n"); - eal_usage(prgname); - return -1; - } - rte_eal_pci_set_blacklist(eal_dev_blacklist, blacklist_index); - } else { - if (eal_dev_whitelist_exists() && eal_dev_whitelist_parse() < 0) { - RTE_LOG(ERR,EAL, "Error parsing whitelist[--use-device] options\n"); - return -1; - } + + if (rte_eal_devargs_type_count(RTE_DEVTYPE_WHITELISTED_PCI) != 0 && + rte_eal_devargs_type_count(RTE_DEVTYPE_BLACKLISTED_PCI) != 0) { + RTE_LOG(ERR, EAL, "Error: blacklist [-b] and whitelist " + "[--use-device] options cannot be used at the same time\n"); + eal_usage(prgname); + return -1; } if (optind >= 0) diff --git a/lib/librte_pmd_ring/rte_eth_ring.c b/lib/librte_pmd_ring/rte_eth_ring.c index 1fed8d3..24635f3 100644 --- a/lib/librte_pmd_ring/rte_eth_ring.c +++ b/lib/librte_pmd_ring/rte_eth_ring.c @@ -386,7 +386,7 @@ rte_pmd_ring_init(const char *name, const char *params) { RTE_LOG(INFO, PMD, "Initializing pmd_ring for %s\n", name); - if (params == NULL) + if (params == NULL || params[0] == '\0') eth_dev_ring_create(name, rte_socket_id(), DEV_CREATE); else { RTE_LOG(INFO, PMD, "Ignoring unsupported parameters when creating" -- 1.8.5.3