From: David Marchand <david.marchand@6wind.com>
To: dev@dpdk.org
Cc: viktorin@rehivetech.com
Subject: [dpdk-dev] [PATCH 2/9] pci: add internal device list helpers
Date: Fri, 22 Jan 2016 16:27:37 +0100 [thread overview]
Message-ID: <1453476464-31767-3-git-send-email-david.marchand@6wind.com> (raw)
In-Reply-To: <1453476464-31767-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>
---
lib/librte_eal/bsdapp/eal/eal_pci.c | 34 +++++-----------
lib/librte_eal/common/eal_common_pci.c | 70 ++++++++++++++++++++++++---------
lib/librte_eal/common/include/rte_pci.h | 24 +++++++++++
lib/librte_eal/linuxapp/eal/eal_pci.c | 34 +++++-----------
4 files changed, 94 insertions(+), 68 deletions(-)
diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 4584522..401cda3 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 1e12776..2528775 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.
@@ -332,16 +367,15 @@ rte_eal_pci_probe_one(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_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, "Requested device " PCI_PRI_FMT
@@ -362,18 +396,16 @@ 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
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index 334c12e..4ba7192 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -399,6 +399,30 @@ void *pci_map_resource(void *requested_addr, int fd, off_t offset,
void pci_unmap_resource(void *requested_addr, size_t size);
/**
+ * @internal
+ * Add a pci device to sorted pci device list
+ *
+ * @param dev
+ * The PCI device object.
+ * @return
+ * - 0 on success.
+ * - negative on error.
+ */
+int pci_add_device(struct rte_pci_device *dev);
+
+/**
+ * @internal
+ * Find a pci device object based on a PCI Bus-Device-Function address.
+ *
+ * @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);
+
+/**
* Probe the single PCI device.
*
* Scan the content of the PCI bus, and find the pci device specified by pci
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index a354f76..83eec5d 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-22 15:27 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 ` David Marchand [this message]
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 ` [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=1453476464-31767-3-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).