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 0238991CB for ; Fri, 22 Jan 2016 16:27:57 +0100 (CET) Received: by mail-wm0-f46.google.com with SMTP id r129so217719836wmr.0 for ; Fri, 22 Jan 2016 07:27:57 -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=bgT+URQAgvudBpJlKWdvnRkZ1XjkO0di7VXglRTVdIc=; b=e8wUcGsz8d/h/LXKDdjMzm/uJJRydTt5s1mzXsRBXUkxIUbYEm91Sqldg/IRvkUi8p 8x/RhVCUBjkCVmw/OOsfAsjHTRq3Lf7+ooP5ynIsoxI8HdrTYQdi6jy9xgxDw0wznpS7 trEQKkpI2mihLhdYLO3ZYamcSvfgcDH+I3g0n7QxqLu2MWiDHxyevbm0r6sKpF78lQgQ yxfbATp+mQGRuQAnTC9I84Rfd9zrt11CsWyZ9bOmO/ZiZBD3oVuxo59j5Qes1x0IVISD vfLfFJXM/8gA4Gj6xYsajinXoLLdZ3enYu7fxWTWKTO6wKy5SliFVRlrf7k0/5dEg0lY L2uQ== 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=bgT+URQAgvudBpJlKWdvnRkZ1XjkO0di7VXglRTVdIc=; b=fLpWMFEHjPY+SfyicVLmW6n263Ghgb8LKFWzewcWy77L3UsYjQEB4NeHqNSozmY/3k GT6eAab0HeAeYkmZ4pMlNHeoluiPP5dzM8iAdUCfo619ZEPhxb4oCM6/Dcn4fS1PztRd Ko0//e4b9HQMV/yVJ7CIkG14AoKm4v7zs6aWfw02b3/vrg9G8Ijc0JRovAMXQC8lhuHX VBRCMTZ0LWVU/zlwS3mVZHRgOCGYuIqLcxLsTzDTJIGvKz3QRTEQg7YQvfSjQ4qJuYHu X6z+PXN7PJbpFEKcI6GP3Ogd8fDI+06b/CKN69GxiErR+rIdoUMxN4/S36opj1Dl3ktV NUOg== X-Gm-Message-State: AG10YORiSB14jlUt5gA+yBFCG2yt3PKra1yHcj7vxxdFgkOSQSBixTuocjA8DPHnMuQ5ypvm X-Received: by 10.28.223.134 with SMTP id w128mr3984332wmg.69.1453476476855; Fri, 22 Jan 2016 07:27:56 -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 w73sm3359464wmw.21.2016.01.22.07.27.55 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 22 Jan 2016 07:27:56 -0800 (PST) From: David Marchand To: dev@dpdk.org Date: Fri, 22 Jan 2016 16:27:40 +0100 Message-Id: <1453476464-31767-6-git-send-email-david.marchand@6wind.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1453476464-31767-1-git-send-email-david.marchand@6wind.com> References: <1453476464-31767-1-git-send-email-david.marchand@6wind.com> Cc: viktorin@rehivetech.com Subject: [dpdk-dev] [PATCH 5/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, 22 Jan 2016 15:27:57 -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 2528775..44549f7 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