DPDK patches and discussions
 help / color / mirror / Atom feed
From: David Marchand <david.marchand@6wind.com>
To: dev@dpdk.org
Cc: viktorin@rehivetech.com
Subject: [dpdk-dev] [PATCH v2 4/9] pci: factorize probe/detach code
Date: Fri, 29 Jan 2016 15:49:08 +0100	[thread overview]
Message-ID: <1454078953-23744-5-git-send-email-david.marchand@6wind.com> (raw)
In-Reply-To: <1454078953-23744-1-git-send-email-david.marchand@6wind.com>

Move pci id matching to a helper and reuse it in probe and detach
functions.

Signed-off-by: David Marchand <david.marchand@6wind.com>
---
 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

  parent reply	other threads:[~2016-01-29 14:49 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-22 15:27 [dpdk-dev] [PATCH 0/9] pci cleanup and blacklist rework David Marchand
2016-01-22 15:27 ` [dpdk-dev] [PATCH 1/9] pci: no need for dynamic tailq init David Marchand
2016-01-22 15:27 ` [dpdk-dev] [PATCH 2/9] pci: add internal device list helpers David Marchand
2016-01-22 15:27 ` [dpdk-dev] [PATCH 3/9] pci: minor cleanup David Marchand
2016-01-22 15:27 ` [dpdk-dev] [PATCH 4/9] pci: rework sysfs parsing for driver David Marchand
2016-01-22 15:27 ` [dpdk-dev] [PATCH 5/9] pci: factorize probe/detach code David Marchand
2016-01-22 15:27 ` [dpdk-dev] [PATCH 6/9] pci: cosmetic change David Marchand
2016-01-22 15:27 ` [dpdk-dev] [PATCH 7/9] pci: factorize driver search David Marchand
2016-01-22 15:27 ` [dpdk-dev] [PATCH 8/9] pci: remove driver lookup from detach David Marchand
2016-01-22 15:27 ` [dpdk-dev] [PATCH 9/9] pci: blacklist only in global probe function David Marchand
2016-01-27 13:07 ` [dpdk-dev] [PATCH 0/9] pci cleanup and blacklist rework David Marchand
2016-01-29 14:49 ` [dpdk-dev] [PATCH v2 " David Marchand
2016-01-29 14:49   ` [dpdk-dev] [PATCH v2 1/9] pci: add internal device list helpers David Marchand
2016-01-29 14:49   ` [dpdk-dev] [PATCH v2 2/9] pci/linux: minor cleanup David Marchand
2016-01-29 14:49   ` [dpdk-dev] [PATCH v2 3/9] pci/linux: rework sysfs parsing for driver David Marchand
2016-01-29 14:49   ` David Marchand [this message]
2016-01-29 14:49   ` [dpdk-dev] [PATCH v2 5/9] pci: cosmetic change David Marchand
2016-01-29 14:49   ` [dpdk-dev] [PATCH v2 6/9] pci: factorize driver search David Marchand
2016-01-29 14:49   ` [dpdk-dev] [PATCH v2 7/9] pci: remove driver lookup from detach David Marchand
2016-01-29 14:49   ` [dpdk-dev] [PATCH v2 8/9] pci: implement blacklist using a hook David Marchand
2016-01-29 14:49   ` [dpdk-dev] [PATCH v2 9/9] pci: implement automatic bind/unbind David Marchand
2016-02-03  9:26     ` Ivan Boule
2016-02-08 13:31   ` [dpdk-dev] [PATCH v2 0/9] pci cleanup and blacklist rework Jan Viktorin
2016-02-09  8:39     ` David Marchand
2016-03-16 16:07   ` Jan Viktorin
2016-03-22 10:24     ` David Marchand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1454078953-23744-5-git-send-email-david.marchand@6wind.com \
    --to=david.marchand@6wind.com \
    --cc=dev@dpdk.org \
    --cc=viktorin@rehivetech.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).