From: David Marchand <david.marchand@6wind.com>
To: dev@dpdk.org
Cc: viktorin@rehivetech.com
Subject: [dpdk-dev] [PATCH v2 1/9] pci: add internal device list helpers
Date: Fri, 29 Jan 2016 15:49:05 +0100 [thread overview]
Message-ID: <1454078953-23744-2-git-send-email-david.marchand@6wind.com> (raw)
In-Reply-To: <1454078953-23744-1-git-send-email-david.marchand@6wind.com>
Remove duplicate code by moving this to helpers in common.
Signed-off-by: David Marchand <david.marchand@6wind.com>
---
Changes since v1:
- moved helpers to eal_private.h
---
lib/librte_eal/bsdapp/eal/eal_pci.c | 34 ++++-----------
lib/librte_eal/common/eal_common_pci.c | 76 ++++++++++++++++++++++++----------
lib/librte_eal/common/eal_private.h | 26 ++++++++++++
lib/librte_eal/linuxapp/eal/eal_pci.c | 34 +++++----------
4 files changed, 99 insertions(+), 71 deletions(-)
diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 5dd89e3..e95249b 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -247,6 +247,7 @@ static int
pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
{
struct rte_pci_device *dev;
+ struct rte_pci_device *dev2;
struct pci_bar_io bar;
unsigned i, max;
@@ -311,32 +312,15 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
dev->mem_resource[i].phys_addr = bar.pbi_base & ~((uint64_t)0xf);
}
- /* device is valid, add in list (sorted) */
- if (TAILQ_EMPTY(&pci_device_list)) {
- TAILQ_INSERT_TAIL(&pci_device_list, dev, next);
- }
+ dev2 = pci_find_device(&dev->addr);
+ if (!dev2)
+ pci_add_device(dev);
else {
- struct rte_pci_device *dev2 = NULL;
- int ret;
-
- TAILQ_FOREACH(dev2, &pci_device_list, next) {
- ret = rte_eal_compare_pci_addr(&dev->addr, &dev2->addr);
- if (ret > 0)
- continue;
- else if (ret < 0) {
- TAILQ_INSERT_BEFORE(dev2, dev, next);
- return 0;
- } else { /* already registered */
- dev2->kdrv = dev->kdrv;
- dev2->max_vfs = dev->max_vfs;
- memmove(dev2->mem_resource,
- dev->mem_resource,
- sizeof(dev->mem_resource));
- free(dev);
- return 0;
- }
- }
- TAILQ_INSERT_TAIL(&pci_device_list, dev, next);
+ dev2->kdrv = dev->kdrv;
+ dev2->max_vfs = dev->max_vfs;
+ memmove(dev2->mem_resource, dev->mem_resource,
+ sizeof(dev->mem_resource));
+ free(dev);
}
return 0;
diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index d9aa66b..c3a33c6 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -139,6 +139,41 @@ pci_unmap_resource(void *requested_addr, size_t size)
requested_addr);
}
+struct rte_pci_device *
+pci_find_device(const struct rte_pci_addr *addr)
+{
+ struct rte_pci_device *dev;
+
+ TAILQ_FOREACH(dev, &pci_device_list, next) {
+ if (!rte_eal_compare_pci_addr(&dev->addr, addr))
+ break;
+ }
+
+ return dev;
+}
+
+int
+pci_add_device(struct rte_pci_device *dev)
+{
+ struct rte_pci_device *dev2;
+ int ret;
+
+ TAILQ_FOREACH(dev2, &pci_device_list, next) {
+ ret = rte_eal_compare_pci_addr(&dev->addr, &dev2->addr);
+ if (ret > 0)
+ continue;
+
+ if (ret == 0)
+ return -1;
+
+ TAILQ_INSERT_BEFORE(dev2, dev, next);
+ return 0;
+ }
+
+ TAILQ_INSERT_TAIL(&pci_device_list, dev, next);
+ return 0;
+}
+
/*
* If vendor/device ID match, call the devinit() function of the
* driver.
@@ -337,16 +372,15 @@ rte_eal_pci_probe_one(const struct rte_pci_addr *addr)
if (pci_refresh_device(addr) < 0)
goto err_return;
- TAILQ_FOREACH(dev, &pci_device_list, next) {
- if (rte_eal_compare_pci_addr(&dev->addr, addr))
- continue;
+ dev = pci_find_device(addr);
+ if (!dev)
+ goto err_return;
- ret = pci_probe_all_drivers(dev);
- if (ret < 0)
- goto err_return;
- return 0;
- }
- return -1;
+ ret = pci_probe_all_drivers(dev);
+ if (ret < 0)
+ goto err_return;
+
+ return 0;
err_return:
RTE_LOG(WARNING, EAL,
@@ -367,23 +401,21 @@ rte_eal_pci_detach(const struct rte_pci_addr *addr)
if (addr == NULL)
return -1;
- TAILQ_FOREACH(dev, &pci_device_list, next) {
- if (rte_eal_compare_pci_addr(&dev->addr, addr))
- continue;
+ dev = pci_find_device(addr);
+ if (!dev)
+ goto err_return;
- ret = pci_detach_all_drivers(dev);
- if (ret < 0)
- goto err_return;
+ ret = pci_detach_all_drivers(dev);
+ if (ret < 0)
+ goto err_return;
- TAILQ_REMOVE(&pci_device_list, dev, next);
- return 0;
- }
- return -1;
+ TAILQ_REMOVE(&pci_device_list, dev, next);
+ return 0;
err_return:
- RTE_LOG(WARNING, EAL, "Requested device " PCI_PRI_FMT
- " cannot be used\n", dev->addr.domain, dev->addr.bus,
- dev->addr.devid, dev->addr.function);
+ RTE_LOG(WARNING, EAL,
+ "Requested device " PCI_PRI_FMT " cannot be detached\n",
+ addr->domain, addr->bus, addr->devid, addr->function);
return -1;
}
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index ed1903f..e44a448 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -155,6 +155,32 @@ struct rte_pci_driver;
struct rte_pci_device;
/**
+ * Add a pci device to sorted pci device list
+ *
+ * This function is private to EAL.
+ *
+ * @param dev
+ * The PCI device object.
+ * @return
+ * - 0 on success.
+ * - negative on error.
+ */
+int pci_add_device(struct rte_pci_device *dev);
+
+/**
+ * Find a pci device object based on a PCI Bus-Device-Function address.
+ *
+ * This function is private to EAL.
+ *
+ * @param addr
+ * The PCI Bus-Device-Function address to look for
+ * @return
+ * - pointer to the object,
+ * - NULL when not found.
+ */
+struct rte_pci_device *pci_find_device(const struct rte_pci_addr *addr);
+
+/**
* Refresh a pci device object by asking the kernel for the latest information.
*
* This function is private to EAL.
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index 4fe8b60..d9d6de7 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -259,6 +259,7 @@ pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus,
char filename[PATH_MAX];
unsigned long tmp;
struct rte_pci_device *dev;
+ struct rte_pci_device *dev2;
char driver[PATH_MAX];
int ret;
@@ -364,30 +365,15 @@ pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus,
} else
dev->kdrv = RTE_KDRV_UNKNOWN;
- /* device is valid, add in list (sorted) */
- if (TAILQ_EMPTY(&pci_device_list)) {
- TAILQ_INSERT_TAIL(&pci_device_list, dev, next);
- } else {
- struct rte_pci_device *dev2;
- int ret;
-
- TAILQ_FOREACH(dev2, &pci_device_list, next) {
- ret = rte_eal_compare_pci_addr(&dev->addr, &dev2->addr);
- if (ret > 0)
- continue;
-
- if (ret < 0) {
- TAILQ_INSERT_BEFORE(dev2, dev, next);
- } else { /* already registered */
- dev2->kdrv = dev->kdrv;
- dev2->max_vfs = dev->max_vfs;
- memmove(dev2->mem_resource, dev->mem_resource,
- sizeof(dev->mem_resource));
- free(dev);
- }
- return 0;
- }
- TAILQ_INSERT_TAIL(&pci_device_list, dev, next);
+ dev2 = pci_find_device(&dev->addr);
+ if (!dev2)
+ pci_add_device(dev);
+ else {
+ dev2->kdrv = dev->kdrv;
+ dev2->max_vfs = dev->max_vfs;
+ memmove(dev2->mem_resource, dev->mem_resource,
+ sizeof(dev->mem_resource));
+ free(dev);
}
return 0;
--
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 ` David Marchand [this message]
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 ` [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-2-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).