From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f46.google.com (mail-wm0-f46.google.com [74.125.82.46]) by dpdk.org (Postfix) with ESMTP id 19924C6E8 for ; Fri, 29 Jan 2016 15:49:26 +0100 (CET) Received: by mail-wm0-f46.google.com with SMTP id l66so57666510wml.0 for ; Fri, 29 Jan 2016 06:49:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=x8G8YxC1U/vd0/yVcag5tsOTH62228i/uxZ2YpUN+ZY=; b=GL2AY5wzOamaHCG8pkHdsSxrRIP588Jz787DkX58L5T/SgOMJSzFuv5MxPFY95CSNq 9dyMBbglfgv1UcxGKQvpP1UNpg6z4n7aisMrKgN2ANlCSHR68kZQ11KJ61RKA2P/qpeu zteQpbelv9X1z0wEx28sOJ+YZogKO7tnJ53XRV4ACqk6+lPzrW2yAOdCke2S59X2nq00 yDKKt9odmv4gFHvTGE67OIaEx5YnDCNg7eMZ4ZlaeYvSRtHeCN1sGeZgviEMHG5L+JBx plAMrfNpOqFOTxNTSEzLiKdP3BiSuQwLcrV/7elyOd+s63G68uu58gzxp5KT/jvjsU6O JAFw== 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=x8G8YxC1U/vd0/yVcag5tsOTH62228i/uxZ2YpUN+ZY=; b=AryMMDQCqTRlUYV9zdFO8rVnUZ0m52pZMwBE4tFEO1+GwG4JDUJF7S25gSYb8yQqd+ VRKOAIGG8byC0IJWh31T/bUZwUmpsElGYqPwHuahFZ1S8SrHf9BnQGAuKYFlUAaTXrr7 GaALJKtGdiHC8gUhEDWjDLdKvytTlvdzC7PnMrzedoIF0RW7YQkrZk69W769mvM+WrFu eEe6obiivGmPTOpTYgzYMMhLbmcloPbERl3YJe3Zvu+pmHRMbIS2My21U3BRn9FChZom 5/Mh1jjkACf3f8UQXJgLaALKdGPqqGcKLdLavxZo7i7pLTUZgQYfpWnSMZmVO2cDsoDh +8rw== X-Gm-Message-State: AG10YOR6HIO6DcedVgO14NvY5vK9QmxNBxi3zc/KQ2Rug5i8ujw9uD20/P242Xn3dLXRzUr2 X-Received: by 10.194.109.2 with SMTP id ho2mr10807958wjb.66.1454078962946; Fri, 29 Jan 2016 06:49:22 -0800 (PST) Received: from gloops.dev.6wind.com (144.77.126.78.rev.sfr.net. [78.126.77.144]) by smtp.gmail.com with ESMTPSA id y188sm7811294wmy.11.2016.01.29.06.49.21 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 29 Jan 2016 06:49:22 -0800 (PST) From: David Marchand To: dev@dpdk.org Date: Fri, 29 Jan 2016 15:49:08 +0100 Message-Id: <1454078953-23744-5-git-send-email-david.marchand@6wind.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1454078953-23744-1-git-send-email-david.marchand@6wind.com> References: <1453476464-31767-1-git-send-email-david.marchand@6wind.com> <1454078953-23744-1-git-send-email-david.marchand@6wind.com> Cc: viktorin@rehivetech.com Subject: [dpdk-dev] [PATCH v2 4/9] pci: factorize probe/detach 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: Fri, 29 Jan 2016 14:49:26 -0000 Move pci id matching to a helper and reuse it in probe and detach functions. Signed-off-by: David Marchand --- lib/librte_eal/common/eal_common_pci.c | 67 ++++++++++++---------------------- 1 file changed, 23 insertions(+), 44 deletions(-) diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c index c3a33c6..a6791c1 100644 --- a/lib/librte_eal/common/eal_common_pci.c +++ b/lib/librte_eal/common/eal_common_pci.c @@ -174,14 +174,10 @@ pci_add_device(struct rte_pci_device *dev) return 0; } -/* - * If vendor/device ID match, call the devinit() function of the - * driver. - */ static int -rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dev) +pci_driver_supports_device(const struct rte_pci_driver *dr, + const struct rte_pci_device *dev) { - int ret; const struct rte_pci_id *id_table; for (id_table = dr->id_table; id_table->vendor_id != 0; id_table++) { @@ -200,6 +196,20 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *d id_table->subsystem_device_id != PCI_ANY_ID) continue; + return 1; + } + return 0; +} + +/* + * If vendor/device ID match, call the devinit() function of the + * driver. + */ +static int +rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, + struct rte_pci_device *dev) +{ + int ret; struct rte_pci_addr *loc = &dev->addr; RTE_LOG(DEBUG, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n", @@ -240,9 +250,6 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *d /* call the driver devinit() function */ return dr->devinit(dr, dev); - } - /* return positive value if driver is not found */ - return 1; } /* @@ -253,27 +260,6 @@ static int rte_eal_pci_detach_dev(struct rte_pci_driver *dr, struct rte_pci_device *dev) { - const struct rte_pci_id *id_table; - - if ((dr == NULL) || (dev == NULL)) - return -EINVAL; - - for (id_table = dr->id_table; id_table->vendor_id != 0; id_table++) { - - /* check if device's identifiers match the driver's ones */ - if (id_table->vendor_id != dev->id.vendor_id && - id_table->vendor_id != PCI_ANY_ID) - continue; - if (id_table->device_id != dev->id.device_id && - id_table->device_id != PCI_ANY_ID) - continue; - if (id_table->subsystem_vendor_id != dev->id.subsystem_vendor_id && - id_table->subsystem_vendor_id != PCI_ANY_ID) - continue; - if (id_table->subsystem_device_id != dev->id.subsystem_device_id && - id_table->subsystem_device_id != PCI_ANY_ID) - continue; - struct rte_pci_addr *loc = &dev->addr; RTE_LOG(DEBUG, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n", @@ -294,10 +280,6 @@ rte_eal_pci_detach_dev(struct rte_pci_driver *dr, pci_unmap_device(dev); return 0; - } - - /* return positive value if driver is not found */ - return 1; } /* @@ -311,16 +293,16 @@ pci_probe_all_drivers(struct rte_pci_device *dev) struct rte_pci_driver *dr = NULL; int rc = 0; - if (dev == NULL) - return -1; - TAILQ_FOREACH(dr, &pci_driver_list, next) { + if (!pci_driver_supports_device(dr, dev)) + continue; + rc = rte_eal_pci_probe_one_driver(dr, dev); if (rc < 0) /* negative value is an error */ return -1; if (rc > 0) - /* positive value means driver not found */ + /* positive value means device is blacklisted */ continue; return 0; } @@ -338,17 +320,14 @@ pci_detach_all_drivers(struct rte_pci_device *dev) struct rte_pci_driver *dr = NULL; int rc = 0; - if (dev == NULL) - return -1; - TAILQ_FOREACH(dr, &pci_driver_list, next) { + if (!pci_driver_supports_device(dr, dev)) + continue; + rc = rte_eal_pci_detach_dev(dr, dev); if (rc < 0) /* negative value is an error */ return -1; - if (rc > 0) - /* positive value means driver not found */ - continue; return 0; } return 1; -- 1.9.1