devargs: use devargs for vdev and PCI whitelist/blacklist
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 <foo> EAL: invalid PCI identifier <> EAL: invalid PCI identifier <000f:0:0> Test OK Signed-off-by: Olivier Matz <olivier.matz@6wind.com> Acked-by: Thomas Monjalon <thomas.monjalon@6wind.com>
This commit is contained in:
parent
bf6dea0e04
commit
1220458951
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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 <rte_interrupts.h>
|
||||
#include <rte_pci.h>
|
||||
#include <rte_devargs.h>
|
||||
|
||||
#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);
|
||||
@ -115,38 +114,43 @@ my_driver_init(__attribute__((unused)) struct rte_pci_driver *dr,
|
||||
return 0;
|
||||
}
|
||||
|
||||
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, &pci_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);
|
||||
}
|
||||
|
||||
rte_eal_pci_set_blacklist(blacklist, idx);
|
||||
printf("%u devices blacklisted\n", idx);
|
||||
/* clear devargs list that was modified by the test */
|
||||
static void free_devargs_list(void)
|
||||
{
|
||||
struct rte_devargs *devargs;
|
||||
|
||||
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");
|
||||
|
@ -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 <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <rte_string_fns.h>
|
||||
#ifdef RTE_LIBRTE_PMD_RING
|
||||
@ -42,6 +44,8 @@
|
||||
#ifdef RTE_LIBRTE_PMD_XENVIRT
|
||||
#include <rte_eth_xenvirt.h>
|
||||
#endif
|
||||
#include <rte_debug.h>
|
||||
#include <rte_devargs.h>
|
||||
#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;
|
||||
|
@ -61,6 +61,7 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
@ -77,29 +78,23 @@
|
||||
#include <rte_eal.h>
|
||||
#include <rte_string_fns.h>
|
||||
#include <rte_common.h>
|
||||
#include <rte_devargs.h>
|
||||
|
||||
#include "eal_private.h"
|
||||
|
||||
struct pci_driver_list pci_driver_list;
|
||||
struct pci_device_list pci_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;
|
||||
struct rte_devargs *devargs;
|
||||
|
||||
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)) {
|
||||
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, &pci_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, &pci_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(&pci_driver_list, driver, next);
|
||||
}
|
||||
|
||||
void
|
||||
rte_eal_pci_set_blacklist(struct rte_pci_addr *blacklist, unsigned size)
|
||||
{
|
||||
dev_blacklist = blacklist;
|
||||
dev_blacklist_size = size;
|
||||
}
|
||||
|
@ -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 <string.h>
|
||||
#include <rte_string_fns.h>
|
||||
#include <rte_log.h>
|
||||
#include <rte_debug.h>
|
||||
#include <rte_pci.h>
|
||||
#include <ctype.h>
|
||||
#ifdef RTE_LIBRTE_PMD_RING
|
||||
#include <rte_eth_ring.h>
|
||||
#endif
|
||||
#ifdef RTE_LIBRTE_PMD_PCAP
|
||||
#include <rte_eth_pcap.h>
|
||||
#endif
|
||||
#ifdef RTE_LIBRTE_PMD_XENVIRT
|
||||
#include <rte_eth_xenvirt.h>
|
||||
#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;
|
||||
}
|
@ -196,44 +196,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
|
||||
*
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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 <rte_cpuflags.h>
|
||||
#include <rte_interrupts.h>
|
||||
#include <rte_pci.h>
|
||||
#include <rte_devargs.h>
|
||||
#include <rte_common.h>
|
||||
#include <rte_version.h>
|
||||
#include <rte_atomic.h>
|
||||
@ -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 <driver><id>[;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)
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user