From: David Marchand <david.marchand@6wind.com>
To: dev@dpdk.org
Cc: viktorin@rehivetech.com
Subject: [dpdk-dev] [PATCH v2 6/9] pci: factorize driver search
Date: Fri, 29 Jan 2016 15:49:10 +0100 [thread overview]
Message-ID: <1454078953-23744-7-git-send-email-david.marchand@6wind.com> (raw)
In-Reply-To: <1454078953-23744-1-git-send-email-david.marchand@6wind.com>
Same idea as a few commits before, no need to implement the same logic in
probe and detach functions.
Here, the driver matching is done by a helper, then probe / detach
functions are called respectively.
Signed-off-by: David Marchand <david.marchand@6wind.com>
---
lib/librte_eal/common/eal_common_pci.c | 96 ++++++++++++----------------------
1 file changed, 34 insertions(+), 62 deletions(-)
diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index fd88305..768421a 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -280,55 +280,16 @@ pci_detach_device(struct rte_pci_driver *dr, struct rte_pci_device *dev)
return 0;
}
-/*
- * If vendor/device ID match, call the devinit() function of all
- * registered driver for the given device. Return -1 if initialization
- * failed, return 1 if no driver is found for this device.
- */
-static int
-pci_probe_all_drivers(struct rte_pci_device *dev)
-{
- struct rte_pci_driver *dr = NULL;
- int rc = 0;
-
- TAILQ_FOREACH(dr, &pci_driver_list, next) {
- if (!pci_driver_supports_device(dr, dev))
- continue;
-
- rc = pci_probe_device(dr, dev);
- if (rc < 0)
- /* negative value is an error */
- return -1;
- if (rc > 0)
- /* positive value means device is blacklisted */
- continue;
- return 0;
- }
- return 1;
-}
-
-/*
- * If vendor/device ID match, call the devuninit() function of all
- * registered driver for the given device. Return -1 if initialization
- * failed, return 1 if no driver is found for this device.
- */
-static int
-pci_detach_all_drivers(struct rte_pci_device *dev)
+static struct rte_pci_driver *
+pci_find_driver(struct rte_pci_device *dev)
{
- struct rte_pci_driver *dr = NULL;
- int rc = 0;
+ struct rte_pci_driver *dr;
TAILQ_FOREACH(dr, &pci_driver_list, next) {
- if (!pci_driver_supports_device(dr, dev))
- continue;
-
- rc = pci_detach_device(dr, dev);
- if (rc < 0)
- /* negative value is an error */
- return -1;
- return 0;
+ if (pci_driver_supports_device(dr, dev))
+ break;
}
- return 1;
+ return dr;
}
/*
@@ -338,8 +299,8 @@ pci_detach_all_drivers(struct rte_pci_device *dev)
int
rte_eal_pci_probe_one(const struct rte_pci_addr *addr)
{
- struct rte_pci_device *dev = NULL;
- int ret = 0;
+ struct rte_pci_device *dev;
+ struct rte_pci_driver *dr;
if (addr == NULL)
return -1;
@@ -353,8 +314,11 @@ rte_eal_pci_probe_one(const struct rte_pci_addr *addr)
if (!dev)
goto err_return;
- ret = pci_probe_all_drivers(dev);
- if (ret < 0)
+ dr = pci_find_driver(dev);
+ if (!dr)
+ goto err_return;
+
+ if (pci_probe_device(dr, dev) < 0)
goto err_return;
return 0;
@@ -372,8 +336,8 @@ err_return:
int
rte_eal_pci_detach(const struct rte_pci_addr *addr)
{
- struct rte_pci_device *dev = NULL;
- int ret = 0;
+ struct rte_pci_device *dev;
+ struct rte_pci_driver *dr;
if (addr == NULL)
return -1;
@@ -382,8 +346,11 @@ rte_eal_pci_detach(const struct rte_pci_addr *addr)
if (!dev)
goto err_return;
- ret = pci_detach_all_drivers(dev);
- if (ret < 0)
+ dr = pci_find_driver(dev);
+ if (!dr)
+ goto err_return;
+
+ if (pci_detach_device(dr, dev) < 0)
goto err_return;
TAILQ_REMOVE(&pci_device_list, dev, next);
@@ -404,28 +371,33 @@ err_return:
int
rte_eal_pci_probe(void)
{
- struct rte_pci_device *dev = NULL;
+ struct rte_pci_device *dev;
+ struct rte_pci_driver *dr;
struct rte_devargs *devargs;
int probe_all = 0;
- int ret = 0;
if (rte_eal_devargs_type_count(RTE_DEVTYPE_WHITELISTED_PCI) == 0)
probe_all = 1;
TAILQ_FOREACH(dev, &pci_device_list, next) {
+ /* no driver available */
+ dr = pci_find_driver(dev);
+ if (!dr)
+ continue;
+
/* set devargs in PCI structure */
devargs = pci_devargs_lookup(dev);
if (devargs != NULL)
dev->devargs = devargs;
- /* probe all or only whitelisted devices */
- if (probe_all)
- ret = pci_probe_all_drivers(dev);
- else if (devargs != NULL &&
- devargs->type == RTE_DEVTYPE_WHITELISTED_PCI)
- ret = pci_probe_all_drivers(dev);
- if (ret < 0)
+ /* skip if not probing all and device is not whitelisted */
+ if (!probe_all &&
+ (devargs == NULL ||
+ devargs->type != RTE_DEVTYPE_WHITELISTED_PCI))
+ continue;
+
+ if (pci_probe_device(dr, dev) < 0)
rte_exit(EXIT_FAILURE, "Requested device " PCI_PRI_FMT
" cannot be used\n", dev->addr.domain, dev->addr.bus,
dev->addr.devid, dev->addr.function);
--
1.9.1
next prev 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 ` [dpdk-dev] [PATCH v2 4/9] pci: factorize probe/detach code David Marchand
2016-01-29 14:49 ` [dpdk-dev] [PATCH v2 5/9] pci: cosmetic change David Marchand
2016-01-29 14:49 ` David Marchand [this message]
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-7-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).