From patchwork Wed Nov 23 19:36:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Walker, Benjamin" X-Patchwork-Id: 17195 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 2CA4C5936; Wed, 23 Nov 2016 20:37:27 +0100 (CET) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 4C855558D for ; Wed, 23 Nov 2016 20:36:50 +0100 (CET) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP; 23 Nov 2016 11:36:47 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.31,539,1473145200"; d="scan'208"; a="1072691988" Received: from bwalker-desk.ch.intel.com ([143.182.137.60]) by fmsmga001.fm.intel.com with ESMTP; 23 Nov 2016 11:36:47 -0800 From: Ben Walker To: dev@dpdk.org Cc: Ben Walker Date: Wed, 23 Nov 2016 12:36:43 -0700 Message-Id: <1479929804-19614-7-git-send-email-benjamin.walker@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1479929804-19614-1-git-send-email-benjamin.walker@intel.com> References: <1479929804-19614-1-git-send-email-benjamin.walker@intel.com> Subject: [dpdk-dev] [PATCH 6/7] pci: Combine rte_eal_pci_scan and rte_eal_pci_probe 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Two functions is both confusing and unnecessary. Previously, rte_eal_pci_scan populated an internal list of devices by scanning sysfs. Then, rte_eal_pci_probe would match registered drivers to that internal list. These are not really useful operations to perform separately independently, though, so simplify the api down to just rte_eal_pci_probe which can be called repeatedly through the lifetime of the application to scan for new or removed PCI devices and load or unload drivers as required. Signed-off-by: Ben Walker --- app/test/test_pci.c | 2 +- lib/librte_eal/bsdapp/eal/eal.c | 3 --- lib/librte_eal/bsdapp/eal/eal_pci.c | 17 +---------------- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 1 - lib/librte_eal/common/eal_common_pci.c | 7 +++++++ lib/librte_eal/common/eal_private.h | 14 +++++--------- lib/librte_eal/common/include/rte_pci.h | 17 +++++------------ lib/librte_eal/linuxapp/eal/eal.c | 3 --- lib/librte_eal/linuxapp/eal/eal_pci.c | 18 +----------------- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 1 - 10 files changed, 20 insertions(+), 63 deletions(-) diff --git a/app/test/test_pci.c b/app/test/test_pci.c index cda186d..fdd84f7 100644 --- a/app/test/test_pci.c +++ b/app/test/test_pci.c @@ -180,7 +180,7 @@ test_pci_setup(void) TAILQ_INSERT_TAIL(&real_pci_device_list, dev, next); } - ret = rte_eal_pci_scan(); + ret = rte_eal_pci_probe(); TEST_ASSERT_SUCCESS(ret, "failed to scan PCI bus"); rte_eal_pci_dump(stdout); diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c index 35e3117..fd44528 100644 --- a/lib/librte_eal/bsdapp/eal/eal.c +++ b/lib/librte_eal/bsdapp/eal/eal.c @@ -561,9 +561,6 @@ 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_pci_init() < 0) - rte_panic("Cannot init PCI\n"); - eal_check_mem_on_local_socket(); if (eal_plugins_init() < 0) diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c index 8b3ed88..6c3a169 100644 --- a/lib/librte_eal/bsdapp/eal/eal_pci.c +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c @@ -361,7 +361,7 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf) * list. Call pci_scan_one() for each pci entry found. */ int -rte_eal_pci_scan(void) +pci_scan(void) { int fd; unsigned dev_count = 0; @@ -667,18 +667,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; -} diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map index 2f81f7c..67c469c 100644 --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map @@ -44,7 +44,6 @@ DPDK_2.0 { rte_eal_pci_probe; rte_eal_pci_probe_one; rte_eal_pci_register; - rte_eal_pci_scan; rte_eal_pci_unregister; rte_eal_process_type; rte_eal_remote_launch; diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c index 4f8c3a0..62b996d 100644 --- a/lib/librte_eal/common/eal_common_pci.c +++ b/lib/librte_eal/common/eal_common_pci.c @@ -81,6 +81,7 @@ #include #include "eal_private.h" +#include "eal_internal_cfg.h" struct pci_driver_list pci_driver_list = TAILQ_HEAD_INITIALIZER(pci_driver_list); @@ -423,6 +424,12 @@ rte_eal_pci_probe(void) int probe_all = 0; int ret = 0; + if (internal_config.no_pci) { + return 0; + } + + pci_scan(); + if (rte_eal_devargs_type_count(RTE_DEVTYPE_WHITELISTED_PCI) == 0) probe_all = 1; diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h index 9e7d8f6..54f18ea 100644 --- a/lib/librte_eal/common/eal_private.h +++ b/lib/librte_eal/common/eal_private.h @@ -108,18 +108,14 @@ int rte_eal_timer_init(void); */ int rte_eal_log_init(const char *id, int facility); -/** - * Init the PCI infrastructure +struct rte_pci_driver; +struct rte_pci_device; + +/* Scan the PCI bus for devices * * This function is private to EAL. - * - * @return - * 0 on success, negative on error */ -int rte_eal_pci_init(void); - -struct rte_pci_driver; -struct rte_pci_device; +int pci_scan(void); /** * Update a pci device object by asking the kernel for the latest information. diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h index 5d0feac..2154a54 100644 --- a/lib/librte_eal/common/include/rte_pci.h +++ b/lib/librte_eal/common/include/rte_pci.h @@ -386,20 +386,13 @@ RTE_PMD_EXPORT_NAME(nm, __COUNTER__) void rte_eal_pci_unregister(struct rte_pci_driver *driver); /** - * Scan the content of the PCI bus, and the devices in the devices - * list - * - * @return - * 0 on success, negative on error - */ -int rte_eal_pci_scan(void); - -/** - * Probe the PCI bus for registered drivers. + * Scan the PCI bus for devices and match them to their driver. * * Scan the content of the PCI bus, and call the probe() function for - * all registered drivers that have a matching entry in its id_table - * for discovered devices. + * all registered drivers that have a matching entry in their id_table. + * If a device already has a driver loaded, probe will not be called. + * If a previously discovered device is no longer present on the system, + * the associated driver's remove() callback will be called. * * @return * - 0 on success. diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c index 2075282..f47f361 100644 --- a/lib/librte_eal/linuxapp/eal/eal.c +++ b/lib/librte_eal/linuxapp/eal/eal.c @@ -802,9 +802,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"); diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index f237864..663e106 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -479,7 +479,7 @@ parse_pci_addr_format(const char *buf, int bufsize, struct rte_pci_addr *addr) * list */ int -rte_eal_pci_scan(void) +pci_scan(void) { struct dirent *e; DIR *dir; @@ -806,19 +806,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; -} diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map index 83721ba..856728e 100644 --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map @@ -44,7 +44,6 @@ DPDK_2.0 { rte_eal_pci_probe; rte_eal_pci_probe_one; rte_eal_pci_register; - rte_eal_pci_scan; rte_eal_pci_unregister; rte_eal_process_type; rte_eal_remote_launch;