DPDK patches and discussions
 help / color / mirror / Atom feed
From: Olivier Matz <olivier.matz@6wind.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH 1/2] pci: split the function providing uio device and mappings
Date: Fri, 24 Jan 2014 16:31:26 +0100	[thread overview]
Message-ID: <1390577487-22242-2-git-send-email-olivier.matz@6wind.com> (raw)
In-Reply-To: <1390577487-22242-1-git-send-email-olivier.matz@6wind.com>

Add a new function pci_get_uio_dev() that parses /sys/bus/pci/devices
to get the uio device associated with a PCI device. This patch just
moves some code that was in pci_uio_map_resource() in the new function
without any functional change.

Thanks to this change, the next commit will be easier to understand.
Moreover it improves readability: having smaller functions help to
understand what pci_uio_map_resource() does.

Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
---
 lib/librte_eal/linuxapp/eal/eal_pci.c | 82 +++++++++++++++++++++--------------
 1 file changed, 50 insertions(+), 32 deletions(-)

diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index 37ee6f1..1039777 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -460,34 +460,20 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 	return -1;
 }
 
-/* map the PCI resource of a PCI device in virtual memory */
-static int
-pci_uio_map_resource(struct rte_pci_device *dev)
+/*
+ * Return the uioX char device used for a pci device. On success, return
+ * the UIO number and fill dstbuf string with the path of the device in
+ * sysfs. On error, return a negative value. In this case dstbuf is
+ * invalid.
+ */
+static int pci_get_uio_dev(struct rte_pci_device *dev, char *dstbuf,
+			   unsigned int buflen)
 {
-	int i, j;
+	struct rte_pci_addr *loc = &dev->addr;
+	unsigned int uio_num;
 	struct dirent *e;
 	DIR *dir;
 	char dirname[PATH_MAX];
-	char filename[PATH_MAX];
-	char dirname2[PATH_MAX];
-	char devname[PATH_MAX]; /* contains the /dev/uioX */
-	void *mapaddr;
-	unsigned uio_num;
-	unsigned long start,size;
-	uint64_t phaddr;
-	uint64_t offset;
-	uint64_t pagesz;
-	ssize_t nb_maps;
-	struct rte_pci_addr *loc = &dev->addr;
-	struct uio_resource *uio_res;
-	struct uio_map *maps;
-
-	dev->intr_handle.fd = -1;
-
-	/* secondary processes - use already recorded details */
-	if ((rte_eal_process_type() != RTE_PROC_PRIMARY) &&
-		(dev->id.vendor_id != PCI_VENDOR_ID_QUMRANET))
-		return (pci_uio_map_secondary(dev));
 
 	/* depending on kernel version, uio can be located in uio/uioX
 	 * or uio:uioX */
@@ -525,8 +511,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 		errno = 0;
 		uio_num = strtoull(e->d_name + shortprefix_len, &endptr, 10);
 		if (errno == 0 && endptr != (e->d_name + shortprefix_len)) {
-			rte_snprintf(dirname2, sizeof(dirname2),
-				 "%s/uio%u", dirname, uio_num);
+			rte_snprintf(dstbuf, buflen, "%s/uio%u", dirname, uio_num);
 			break;
 		}
 
@@ -534,15 +519,48 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 		errno = 0;
 		uio_num = strtoull(e->d_name + longprefix_len, &endptr, 10);
 		if (errno == 0 && endptr != (e->d_name + longprefix_len)) {
-			rte_snprintf(dirname2, sizeof(dirname2),
-				 "%s/uio:uio%u", dirname, uio_num);
+			rte_snprintf(dstbuf, buflen, "%s/uio:uio%u", dirname, uio_num);
 			break;
 		}
 	}
 	closedir(dir);
 
 	/* No uio resource found */
-	if (e == NULL) {
+	if (e == NULL)
+		return -1;
+
+	return 0;
+}
+
+/* map the PCI resource of a PCI device in virtual memory */
+static int
+pci_uio_map_resource(struct rte_pci_device *dev)
+{
+	int i, j;
+	char dirname[PATH_MAX];
+	char filename[PATH_MAX];
+	char devname[PATH_MAX]; /* contains the /dev/uioX */
+	void *mapaddr;
+	int uio_num;
+	unsigned long start,size;
+	uint64_t phaddr;
+	uint64_t offset;
+	uint64_t pagesz;
+	ssize_t nb_maps;
+	struct rte_pci_addr *loc = &dev->addr;
+	struct uio_resource *uio_res;
+	struct uio_map *maps;
+
+	dev->intr_handle.fd = -1;
+
+	/* secondary processes - use already recorded details */
+	if ((rte_eal_process_type() != RTE_PROC_PRIMARY) &&
+	    (dev->id.vendor_id != PCI_VENDOR_ID_QUMRANET))
+		return (pci_uio_map_secondary(dev));
+
+	/* find uio resource */
+	uio_num = pci_get_uio_dev(dev, dirname, sizeof(dirname));
+	if (uio_num < 0) {
 		RTE_LOG(WARNING, EAL, "  "PCI_PRI_FMT" not managed by UIO driver, "
 				"skipping\n", loc->domain, loc->bus, loc->devid, loc->function);
 		return -1;
@@ -551,7 +569,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	if(dev->id.vendor_id == PCI_VENDOR_ID_QUMRANET) {
 		/* get portio size */
 		rte_snprintf(filename, sizeof(filename),
-			 "%s/portio/port0/size", dirname2);
+			 "%s/portio/port0/size", dirname);
 		if (eal_parse_sysfs_value(filename, &size) < 0) {
 			RTE_LOG(ERR, EAL, "%s(): cannot parse size\n",
 				__func__);
@@ -560,7 +578,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 		/* get portio start */
 		rte_snprintf(filename, sizeof(filename),
-			 "%s/portio/port0/start", dirname2);
+			 "%s/portio/port0/start", dirname);
 		if (eal_parse_sysfs_value(filename, &start) < 0) {
 			RTE_LOG(ERR, EAL, "%s(): cannot parse portio start\n",
 				__func__);
@@ -585,7 +603,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	memcpy(&uio_res->pci_addr, &dev->addr, sizeof(uio_res->pci_addr));
 
 	/* collect info about device mappings */
-	if ((nb_maps = pci_uio_get_mappings(dirname2, uio_res->maps,
+	if ((nb_maps = pci_uio_get_mappings(dirname, uio_res->maps,
 			sizeof (uio_res->maps) / sizeof (uio_res->maps[0])))
 			< 0)
 		return (nb_maps);
-- 
1.8.4.rc3

  reply	other threads:[~2014-01-24 15:30 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-24 15:31 [dpdk-dev] [PATCH 0/2] pci: allow to run without hotplug Olivier Matz
2014-01-24 15:31 ` Olivier Matz [this message]
2014-01-28 15:35   ` [dpdk-dev] [PATCH 1/2] pci: split the function providing uio device and mappings Thomas Monjalon
2014-01-24 15:31 ` [dpdk-dev] [PATCH 2/2] pci: add option --create-uio-dev to run without hotplug Olivier Matz
2014-01-28 14:37   ` Thomas Monjalon
2014-01-28 15:26     ` [dpdk-dev] [PATCH 2/2 v2] " Olivier Matz
2014-01-28 15:36       ` Thomas Monjalon

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=1390577487-22242-2-git-send-email-olivier.matz@6wind.com \
    --to=olivier.matz@6wind.com \
    --cc=dev@dpdk.org \
    /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).