From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-SN1-obe.outbound.protection.outlook.com (mail-sn1nam01on0075.outbound.protection.outlook.com [104.47.32.75]) by dpdk.org (Postfix) with ESMTP id 298BD558B for ; Thu, 17 Nov 2016 06:28:18 +0100 (CET) Received: from DM2PR03CA0042.namprd03.prod.outlook.com (10.141.96.41) by BN1PR0301MB0737.namprd03.prod.outlook.com (10.160.78.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.721.10; Thu, 17 Nov 2016 05:28:15 +0000 Received: from BN1AFFO11FD048.protection.gbl (2a01:111:f400:7c10::121) by DM2PR03CA0042.outlook.office365.com (2a01:111:e400:2428::41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.721.10 via Frontend Transport; Thu, 17 Nov 2016 05:28:15 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com;nxp.com; dkim=none (message not signed) header.d=none; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BN1AFFO11FD048.mail.protection.outlook.com (10.58.53.63) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.721.5 via Frontend Transport; Thu, 17 Nov 2016 05:28:14 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:; UpperCasedChecksum:; SizeAsReceived:663; Count:10 Received: from Tophie.ap.freescale.net ([10.232.14.87]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id uAH5S1pu018741; Wed, 16 Nov 2016 22:28:12 -0700 From: Shreyansh Jain To: CC: , Shreyansh Jain Date: Thu, 17 Nov 2016 11:00:04 +0530 Message-ID: <1479360605-20558-6-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1479360605-20558-1-git-send-email-shreyansh.jain@nxp.com> References: <1479360605-20558-1-git-send-email-shreyansh.jain@nxp.com> X-IncomingHeaderCount: 10 X-EOPAttributedMessage: 0 X-Matching-Connectors: 131238340949449667; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(7916002)(2980300002)(1109001)(1110001)(339900001)(336004)(189002)(199003)(50466002)(48376002)(76176999)(47776003)(110136003)(50986999)(85426001)(189998001)(97736004)(7846002)(6666003)(50226002)(2950100002)(6916009)(33646002)(8676002)(8666005)(5660300001)(305945005)(68736007)(2351001)(77096005)(626004)(92566002)(106466001)(356003)(2906002)(104016004)(8936002)(5003940100001)(87936001)(105606002)(4326007)(86362001)(36756003)(81156014)(81166006)(7059030)(217873001); DIR:OUT; SFP:1101; SCL:1; SRVR:BN1PR0301MB0737; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD048; 1:Y4NmytDwztD4GEtkO6e4zouvioRODU/NDW9Z9vroN9D7GbdMhMx2wHulYwKQLKwcgMAS6vhSfRYCbebfVyHErv9eD+YkEKtjPhtkq8XUytLmSXZsF972k0RZIntwJIdiBh6XebG7AzBN8zFzkGDyRgRn4XqcAGGszINS1BwM9dSPfoZjWB0IBKmeOOjBjIPbG+gaUhvSqhjFl/PndOIvdXhJGC3rGENmoxlqwj8B/byEnXY5t3xuXf8owREwNUcj+A7WlP7ytM2C8VdpWrLwVK66aT8VEs9NtS28mdOazUx2oInmJQgp//MRh2HAdci1wMlubMW9oWwUh9qc4CnMUyacNUfPc15VFovX7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CzOc4IbPSYzOjJtarwZ1nGq/lT8ADO+uokzpItrsfXG1p9PL/wsWOKzsbsqIJuzlJboYQzdFyBuPY6Le/ojnM8b0RQlcqk9K2+Z+PMaXMcAL9VTQTrcSZZDAl00l02d4DYRbNZEMSg80t9qTP7Dd0FqfjY7Q40NeHAl3t0amq8fTgr8KTTRpy3C/kNjEfnIafKGS4vYcxKLjwiaYtb1zA4xlR4QBCgWqMVLnHevuXQRT9FfrjIQcCYbKsyEHP7K6Q0AzSyHHosAdJzysA4o7aoZz5UglRC/FgiCWU9YiM9/IkAPEu7D+wRxrn1WAc38DKE9X4w== X-MS-Office365-Filtering-Correlation-Id: fe9f78a7-5fe0-4de0-ba64-08d40eaa87a8 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:BN1PR0301MB0737; X-Microsoft-Exchange-Diagnostics: 1; BN1PR0301MB0737; 31:lV7s+KDEJA9VK+45EugpW6+1Cv7/bk9HeYTFqLlMctiQHagUTIISN/f+kzbdkdwazm0wX3CZEa8V84SyEJaKFXrXliMYOWmHW/WbyqF3KdPz6zqgR2Uhlxz76g8HLziqJSp+bBAnJDWApCnDXKCXKCNjOLYUAP/0eFSvqieWMB9LLWdHv6dyHZ4QPiodw9HSLAwRCY5/0ohcKg61jEeMeFqLibaLQm3DzNLVd3n0LhvMfsA9xh1S/8Kqn0DBOE7nUnNRbTMOYbQTfHjXo0p7KTtB8Ew7JtYWU21K2lrb1Y4=; 4:B9QskG4J53940DOCWE+ADVCzBaeYqQGM2iR4EOKDYd9yEFxapj/hDBFVswn5VcAmcOaPp5xYwwRK/zw+uat0MSjZAn+UTDOVrrvu+I0m6G2CvATlsbFWG5AbqoJRdWZn84JeE4v6p2yAAds4b6A6fHAY3BZiK4GqfLeoItFaueQk0cEFHCWttF0XICcGbsOAmMHHoANKZyxKL/UzdpsxecwTOVfcKYB2ZKT2N4xxbAM7hBMxqsFa6E5WeSHonCZUwcJAVSUczebcJqdPdkyLk5JXatPKvV2VodPINt++28t3Z7GgNJA9HRw5bymkOiyadoLRIflfQok5KcAi8YlkpTV/JnYsz6wBVEmZX6vhYcMHMHZ1JawkzUF7UaTbdUPU3pq84uU2kNGUpco3zhyhHakam8VRvHbmfVcgQvaH9PKuGWzPkSA/DDsxVFLMpJYiLrgXFy1Y6HTdo1Cq1mXqyefWRI93n0It7RBXmcAEZrScKVwuGZQ1Cy4Of4zf78VxBKQh72Awwgv745UKxcUtq2b5dPaMqi/c/fqViF5/vp9AJb4vChMvGfF0gcYsgjGFIkm2vsSlcxUaiEVuFuFyUA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6095035)(601004)(2401047)(13023025)(8121501046)(13024025)(5005006)(13015025)(13017025)(13018025)(3002001)(10201501046)(6055026)(6096035); SRVR:BN1PR0301MB0737; BCL:0; PCL:0; RULEID:(400006); SRVR:BN1PR0301MB0737; X-Forefront-PRVS: 01294F875B X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN1PR0301MB0737; 23:4yTAhOovM+HCJ1WyNDDbdug3G1ESts2psUrL+JK?= =?us-ascii?Q?WKO5BAsUhOeMnKwI/mkVj7eU/z7s8r4SFbQIG5wxeGEqc3xe+6M1G2XUjVhA?= =?us-ascii?Q?moRNXR114wFchb5tULi1EW62X66RS2Ou3ybdgGHrsPUQcNcl3VF1lt/v8Mlo?= =?us-ascii?Q?IGpu5VXt6HZJz3Wmz33Flw75LE9X9nAG5nbpAVPA+/d7+9FIIv/Om0oJFO27?= =?us-ascii?Q?dC8OeRtSWTdICrixsssYiQ4BzuRfPET7Coo+vGFYc5z/KFGNsWXHp+E8Sg5Y?= =?us-ascii?Q?X3WzTtp1jNtz5lpOhZDY8Ov4b+hmForL6HLsUth2dulEwYXF5U5SxgX5go0i?= =?us-ascii?Q?KZRCeELLz5vD1PUKKiaG/1kzE6Udz2jo/tS6K7vuqVqhTC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exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN1PR0301MB0737 Subject: [dpdk-dev] [RFC PATCH 5/6] eal: supporting bus model in init process 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: Thu, 17 Nov 2016 05:28:18 -0000 This patch makes necessary changes to the EAL for handling bus scan and probe. Most of the scan function has been moved to bus/* implementation, (currently only for pci, linuxapp). There are still some functions which exists in the EAL (bind, unbind module, mmap etc). Missing/Grey area; - Should all the operations for a PCI device, whether binding to a driver or mmap, be moved to PCI bus code base? All of that is not relevant for a bus, but then having multiple implementation areas for a common sub-system (PCI, here) is also not a nice thing. Signed-off-by: Shreyansh Jain --- lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal.c | 51 +++++- lib/librte_eal/linuxapp/eal/eal_pci.c | 298 ---------------------------------- 3 files changed, 44 insertions(+), 306 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile index 4e206f0..124dceb 100644 --- a/lib/librte_eal/linuxapp/eal/Makefile +++ b/lib/librte_eal/linuxapp/eal/Makefile @@ -77,6 +77,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_memzone.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_log.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_launch.c +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_bus.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_vdev.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_pci.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_pci_uio.c diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c index 2075282..332d1f4 100644 --- a/lib/librte_eal/linuxapp/eal/eal.c +++ b/lib/librte_eal/linuxapp/eal/eal.c @@ -739,6 +739,44 @@ static int rte_eal_vfio_setup(void) } #endif +static int +rte_eal_scan(void) +{ + int ret = 0; + + /* For now, as vdev replacement is not complete, continue with a call + * rte_bus_list scan + */ + rte_eal_bus_scan(); + + ret = rte_eal_dev_init(); + if (ret) { + RTE_LOG(ERR, EAL, "Cannot init pmd devices\n"); + } + +out: + return ret; +} + +static int +rte_eal_probe(void) +{ + int ret = 0; + + /* Probe & Initialize PCI devices */ + ret = rte_eal_pci_probe(); + if (ret) { + RTE_LOG(ERR, EAL, "Cannot probe PCI\n"); + goto out; + } + + /* ToDo: vdev scan already does the probe - it should be moved here */ + + /* Last successful bus probe would set ret = 0 */ +out: + return ret; +} + /* Launch threads, called at application init(). */ int rte_eal_init(int argc, char **argv) @@ -802,9 +840,6 @@ rte_eal_init(int argc, char **argv) if (rte_eal_log_init(logid, internal_config.syslog_facility) < 0) rte_panic("Cannot init logs\n"); - if (rte_eal_pci_init() < 0) - rte_panic("Cannot init PCI\n"); - #ifdef VFIO_PRESENT if (rte_eal_vfio_setup() < 0) rte_panic("Cannot init VFIO\n"); @@ -828,6 +863,9 @@ rte_eal_init(int argc, char **argv) if (rte_eal_timer_init() < 0) rte_panic("Cannot init HPET or TSC timers\n"); + if (rte_eal_scan() < 0) + rte_panic("Cannot scan for devices\n"); + eal_check_mem_on_local_socket(); if (eal_plugins_init() < 0) @@ -841,9 +879,6 @@ rte_eal_init(int argc, char **argv) rte_config.master_lcore, (int)thread_id, cpuset, ret == 0 ? "" : "..."); - if (rte_eal_dev_init() < 0) - rte_panic("Cannot init pmd devices\n"); - if (rte_eal_intr_init() < 0) rte_panic("Cannot init interrupt-handling thread\n"); @@ -884,8 +919,8 @@ rte_eal_init(int argc, char **argv) rte_eal_mp_wait_lcore(); /* Probe & Initialize PCI devices */ - if (rte_eal_pci_probe()) - rte_panic("Cannot probe PCI\n"); + if (rte_eal_probe()) + rte_panic("Cannot complete probe\n"); rte_eal_mcfg_complete(); diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index 876ba38..e3916ab 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -224,202 +224,6 @@ pci_parse_one_sysfs_resource(char *line, size_t len, uint64_t *phys_addr, return 0; } -/* parse the "resource" sysfs file */ -static int -pci_parse_sysfs_resource(const char *filename, struct rte_pci_device *dev) -{ - FILE *f; - char buf[BUFSIZ]; - int i; - uint64_t phys_addr, end_addr, flags; - - f = fopen(filename, "r"); - if (f == NULL) { - RTE_LOG(ERR, EAL, "Cannot open sysfs resource\n"); - return -1; - } - - for (i = 0; imem_resource[i].phys_addr = phys_addr; - dev->mem_resource[i].len = end_addr - phys_addr + 1; - /* not mapped for now */ - dev->mem_resource[i].addr = NULL; - } - } - fclose(f); - return 0; - -error: - fclose(f); - return -1; -} - -/* Scan one pci sysfs entry, and fill the devices list from it. */ -static int -pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus, - uint8_t devid, uint8_t function) -{ - char filename[PATH_MAX]; - unsigned long tmp; - struct rte_pci_device *dev; - char driver[PATH_MAX]; - int ret; - - dev = malloc(sizeof(*dev)); - if (dev == NULL) - return -1; - - memset(dev, 0, sizeof(*dev)); - dev->addr.domain = domain; - dev->addr.bus = bus; - dev->addr.devid = devid; - dev->addr.function = function; - - /* get vendor id */ - snprintf(filename, sizeof(filename), "%s/vendor", dirname); - if (eal_parse_sysfs_value(filename, &tmp) < 0) { - free(dev); - return -1; - } - dev->id.vendor_id = (uint16_t)tmp; - - /* get device id */ - snprintf(filename, sizeof(filename), "%s/device", dirname); - if (eal_parse_sysfs_value(filename, &tmp) < 0) { - free(dev); - return -1; - } - dev->id.device_id = (uint16_t)tmp; - - /* get subsystem_vendor id */ - snprintf(filename, sizeof(filename), "%s/subsystem_vendor", - dirname); - if (eal_parse_sysfs_value(filename, &tmp) < 0) { - free(dev); - return -1; - } - dev->id.subsystem_vendor_id = (uint16_t)tmp; - - /* get subsystem_device id */ - snprintf(filename, sizeof(filename), "%s/subsystem_device", - dirname); - if (eal_parse_sysfs_value(filename, &tmp) < 0) { - free(dev); - return -1; - } - dev->id.subsystem_device_id = (uint16_t)tmp; - - /* get class_id */ - snprintf(filename, sizeof(filename), "%s/class", - dirname); - if (eal_parse_sysfs_value(filename, &tmp) < 0) { - free(dev); - return -1; - } - /* the least 24 bits are valid: class, subclass, program interface */ - dev->id.class_id = (uint32_t)tmp & RTE_CLASS_ANY_ID; - - /* get max_vfs */ - dev->max_vfs = 0; - snprintf(filename, sizeof(filename), "%s/max_vfs", dirname); - if (!access(filename, F_OK) && - eal_parse_sysfs_value(filename, &tmp) == 0) - dev->max_vfs = (uint16_t)tmp; - else { - /* for non igb_uio driver, need kernel version >= 3.8 */ - snprintf(filename, sizeof(filename), - "%s/sriov_numvfs", dirname); - if (!access(filename, F_OK) && - eal_parse_sysfs_value(filename, &tmp) == 0) - dev->max_vfs = (uint16_t)tmp; - } - - /* get numa node */ - snprintf(filename, sizeof(filename), "%s/numa_node", - dirname); - if (access(filename, R_OK) != 0) { - /* if no NUMA support, set default to 0 */ - dev->device.numa_node = 0; - } else { - if (eal_parse_sysfs_value(filename, &tmp) < 0) { - free(dev); - return -1; - } - dev->device.numa_node = tmp; - } - - /* parse resources */ - snprintf(filename, sizeof(filename), "%s/resource", dirname); - if (pci_parse_sysfs_resource(filename, dev) < 0) { - RTE_LOG(ERR, EAL, "%s(): cannot parse resource\n", __func__); - free(dev); - return -1; - } - - /* parse driver */ - snprintf(filename, sizeof(filename), "%s/driver", dirname); - ret = pci_get_kernel_driver_by_path(filename, driver); - if (ret < 0) { - RTE_LOG(ERR, EAL, "Fail to get kernel driver\n"); - free(dev); - return -1; - } - - if (!ret) { - if (!strcmp(driver, "vfio-pci")) - dev->kdrv = RTE_KDRV_VFIO; - else if (!strcmp(driver, "igb_uio")) - dev->kdrv = RTE_KDRV_IGB_UIO; - else if (!strcmp(driver, "uio_pci_generic")) - dev->kdrv = RTE_KDRV_UIO_GENERIC; - else - dev->kdrv = RTE_KDRV_UNKNOWN; - } else - dev->kdrv = RTE_KDRV_NONE; - - /* device is valid, add in list (sorted) */ - if (TAILQ_EMPTY(&pci_device_list)) { - rte_eal_device_insert(&dev->device); - TAILQ_INSERT_TAIL(&pci_device_list, dev, next); - } else { - struct rte_pci_device *dev2; - int ret; - - TAILQ_FOREACH(dev2, &pci_device_list, next) { - ret = rte_eal_compare_pci_addr(&dev->addr, &dev2->addr); - if (ret > 0) - continue; - - if (ret < 0) { - TAILQ_INSERT_BEFORE(dev2, dev, next); - rte_eal_device_insert(&dev->device); - } else { /* already registered */ - dev2->kdrv = dev->kdrv; - dev2->max_vfs = dev->max_vfs; - memmove(dev2->mem_resource, dev->mem_resource, - sizeof(dev->mem_resource)); - free(dev); - } - return 0; - } - rte_eal_device_insert(&dev->device); - TAILQ_INSERT_TAIL(&pci_device_list, dev, next); - } - - return 0; -} - int pci_update_device(const struct rte_pci_addr *addr) { @@ -433,93 +237,7 @@ pci_update_device(const struct rte_pci_addr *addr) addr->function); } -/* - * split up a pci address into its constituent parts. - */ -static int -parse_pci_addr_format(const char *buf, int bufsize, uint16_t *domain, - uint8_t *bus, uint8_t *devid, uint8_t *function) -{ - /* first split on ':' */ - union splitaddr { - struct { - char *domain; - char *bus; - char *devid; - char *function; - }; - char *str[PCI_FMT_NVAL]; /* last element-separator is "." not ":" */ - } splitaddr; - - char *buf_copy = strndup(buf, bufsize); - if (buf_copy == NULL) - return -1; - - if (rte_strsplit(buf_copy, bufsize, splitaddr.str, PCI_FMT_NVAL, ':') - != PCI_FMT_NVAL - 1) - goto error; - /* final split is on '.' between devid and function */ - splitaddr.function = strchr(splitaddr.devid,'.'); - if (splitaddr.function == NULL) - goto error; - *splitaddr.function++ = '\0'; - - /* now convert to int values */ - errno = 0; - *domain = (uint16_t)strtoul(splitaddr.domain, NULL, 16); - *bus = (uint8_t)strtoul(splitaddr.bus, NULL, 16); - *devid = (uint8_t)strtoul(splitaddr.devid, NULL, 16); - *function = (uint8_t)strtoul(splitaddr.function, NULL, 10); - if (errno != 0) - goto error; - - free(buf_copy); /* free the copy made with strdup */ - return 0; -error: - free(buf_copy); - return -1; -} - -/* - * Scan the content of the PCI bus, and the devices in the devices - * list - */ -int -rte_eal_pci_scan(void) -{ - struct dirent *e; - DIR *dir; - char dirname[PATH_MAX]; - uint16_t domain; - uint8_t bus, devid, function; - - dir = opendir(pci_get_sysfs_path()); - if (dir == NULL) { - RTE_LOG(ERR, EAL, "%s(): opendir failed: %s\n", - __func__, strerror(errno)); - return -1; - } - while ((e = readdir(dir)) != NULL) { - if (e->d_name[0] == '.') - continue; - - if (parse_pci_addr_format(e->d_name, sizeof(e->d_name), &domain, - &bus, &devid, &function) != 0) - continue; - - snprintf(dirname, sizeof(dirname), "%s/%s", - pci_get_sysfs_path(), e->d_name); - if (pci_scan_one(dirname, domain, bus, devid, function) < 0) - goto error; - } - closedir(dir); - return 0; - -error: - closedir(dir); - return -1; -} /* Read PCI config space. */ int rte_eal_pci_read_config(const struct rte_pci_device *device, @@ -754,19 +472,3 @@ rte_eal_pci_ioport_unmap(struct rte_pci_ioport *p) return ret; } - -/* Init the PCI EAL subsystem */ -int -rte_eal_pci_init(void) -{ - /* for debug purposes, PCI can be disabled */ - if (internal_config.no_pci) - return 0; - - if (rte_eal_pci_scan() < 0) { - RTE_LOG(ERR, EAL, "%s(): Cannot scan PCI bus\n", __func__); - return -1; - } - - return 0; -} -- 2.7.4