DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH v4 0/5] Clean up pci uio implementations
@ 2015-05-19  5:54 Tetsuya Mukawa
  2015-05-19  5:54 ` [dpdk-dev] [PATCH v4 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
                   ` (5 more replies)
  0 siblings, 6 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-05-19  5:54 UTC (permalink / raw)
  To: dev

This patch set cleans up pci uio implementation. These clean up are
for consolidating pci uio implementation of linuxapp and bsdapp, and
moving consolidated functions in eal common.
Because of above, this patch set tries to implement linuxapp and bsdapp
almost same.
Actual consolidations will be done later patch set.

PATCH v4 changes:
 - Rebase to latest master branch.
 - Fix bug in pci_uio_map_resource() of BSD code. 'maps[i].path' shouldn't be freed.
     Fixed in below patch:
     [PATCH 3/5] eal: Fix memory leaks and needless increment of pci_map_addr
 - 'path' member of 'struct mapped_pci_resource' should not be removed because it will be used in BSD code.
     Fixed in below patch:
     [PATCH 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp

PATCH v3 changes:
 - Squash patches related with pci_map_resource().
 - Free maps[].path to easy to understand.
   (Thanks to Iremonger, Bernard)
 - Close fds opened in this function.
 - Remove unused path variable from mapped_pci_resource structure.

PATCH v2 changes:
 - Move 'if-condition' to later patch series.
 - Fix memory leaks of path.
 - Fix typos.
   (Thanks to David Marchand)
 - Fix commit title and body.
 - Fix pci_map_resource() to handle MAP_FAILED.
   (Thanks to Iremonger, Bernard)

Changes:
 - This patch set is derived from below.
   "[PATCH v2] eal: Port Hotplug support for BSD"
 - Set cfg_fd as -1, when cfg_fd is closed.
   (Thanks to Iremonger, Bernard)
 - Remove needless coding style fixings.
 - Fix coding style of if-else condition.
   (Thanks to Richardson, Bruce)


Tetsuya Mukawa (5):
  eal: Fix coding style of eal_pci.c and eal_pci_uio.c
  eal: Close file descriptor of uio configuration
  eal: Fix memory leaks and needless increment of pci_map_addr
  eal/bsdapp: Change names of pci related data structure
  eal: Fix uio mapping differences between linuxapp and bsdapp

 lib/librte_eal/bsdapp/eal/eal_pci.c       | 164 ++++++++++++++++++------------
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c |  88 +++++++++-------
 2 files changed, 153 insertions(+), 99 deletions(-)

-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v4 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c
  2015-05-19  5:54 [dpdk-dev] [PATCH v4 0/5] Clean up pci uio implementations Tetsuya Mukawa
@ 2015-05-19  5:54 ` Tetsuya Mukawa
  2015-05-19 14:51   ` Stephen Hemminger
  2015-06-25  3:19   ` [dpdk-dev] [PATCH v5 0/5] Clean up pci uio implementations Tetsuya Mukawa
  2015-05-19  5:54 ` [dpdk-dev] [PATCH v4 2/5] eal: Close file descriptor of uio configuration Tetsuya Mukawa
                   ` (4 subsequent siblings)
  5 siblings, 2 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-05-19  5:54 UTC (permalink / raw)
  To: dev

This patch fixes coding style of below files in linuxapp and bsdapp.
 - eal_pci.c
 - eal_pci_uio.c

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c       | 24 +++++++++++++-----------
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 12 ++++++++----
 2 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 61e8921..8e24fd1 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -161,9 +161,10 @@ fail:
 static int
 pci_uio_map_secondary(struct rte_pci_device *dev)
 {
-        size_t i;
-        struct uio_resource *uio_res;
-	struct uio_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
+	size_t i;
+	struct uio_resource *uio_res;
+	struct uio_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
 
 	TAILQ_FOREACH(uio_res, uio_res_list, next) {
 
@@ -179,10 +180,10 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 			    != uio_res->maps[i].addr) {
 				RTE_LOG(ERR, EAL,
 					"Cannot mmap device resource\n");
-				return (-1);
+				return -1;
 			}
 		}
-		return (0);
+		return 0;
 	}
 
 	RTE_LOG(ERR, EAL, "Cannot find resource for device\n");
@@ -201,7 +202,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	uint64_t pagesz;
 	struct rte_pci_addr *loc = &dev->addr;
 	struct uio_resource *uio_res;
-	struct uio_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
+	struct uio_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
 	struct uio_map *maps;
 
 	dev->intr_handle.fd = -1;
@@ -209,7 +211,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 	/* secondary processes - use already recorded details */
 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
-		return (pci_uio_map_secondary(dev));
+		return pci_uio_map_secondary(dev);
 
 	snprintf(devname, sizeof(devname), "/dev/uio@pci:%u:%u:%u",
 			dev->addr.bus, dev->addr.devid, dev->addr.function);
@@ -233,7 +235,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) == NULL) {
 		RTE_LOG(ERR, EAL,
 			"%s(): cannot store uio mmap details\n", __func__);
-		return (-1);
+		return -1;
 	}
 
 	snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
@@ -261,7 +263,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 						(size_t)maps[j].size)
 		    ) == NULL) {
 			rte_free(uio_res);
-			return (-1);
+			return -1;
 		}
 
 		maps[j].addr = mapaddr;
@@ -271,7 +273,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
 
-	return (0);
+	return 0;
 }
 
 /* Scan one pci sysfs entry, and fill the devices list from it. */
@@ -311,7 +313,7 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
 	/* FreeBSD has no NUMA support (yet) */
 	dev->numa_node = 0;
 
-/* parse resources */
+	/* parse resources */
 	switch (conf->pc_hdr & PCIM_HDRTYPE) {
 	case PCIM_HDRTYPE_NORMAL:
 		max = PCIR_MAX_BAR_0;
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index b5116a7..5d3354d 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -92,7 +92,8 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 {
 	int fd, i;
 	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 
 	TAILQ_FOREACH(uio_res, uio_res_list, next) {
 
@@ -272,7 +273,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	uint64_t phaddr;
 	struct rte_pci_addr *loc = &dev->addr;
 	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 	struct pci_map *maps;
 
 	dev->intr_handle.fd = -1;
@@ -417,7 +419,8 @@ static struct mapped_pci_resource *
 pci_uio_find_resource(struct rte_pci_device *dev)
 {
 	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 
 	if (dev == NULL)
 		return NULL;
@@ -436,7 +439,8 @@ void
 pci_uio_unmap_resource(struct rte_pci_device *dev)
 {
 	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 
 	if (dev == NULL)
 		return;
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v4 2/5] eal: Close file descriptor of uio configuration
  2015-05-19  5:54 [dpdk-dev] [PATCH v4 0/5] Clean up pci uio implementations Tetsuya Mukawa
  2015-05-19  5:54 ` [dpdk-dev] [PATCH v4 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
@ 2015-05-19  5:54 ` Tetsuya Mukawa
  2015-05-19 16:02   ` Stephen Hemminger
  2015-05-19  5:54 ` [dpdk-dev] [PATCH v4 3/5] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-05-19  5:54 UTC (permalink / raw)
  To: dev

When pci_uio_unmap_resource() is called, a file descriptor that is used
for uio configuration should be closed.

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 5d3354d..34316b6 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -464,8 +464,12 @@ pci_uio_unmap_resource(struct rte_pci_device *dev)
 
 	/* close fd if in primary process */
 	close(dev->intr_handle.fd);
-
 	dev->intr_handle.fd = -1;
+
+	/* close cfg_fd if in primary process */
+	close(dev->intr_handle.uio_cfg_fd);
+	dev->intr_handle.uio_cfg_fd = -1;
+
 	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
 }
 #endif /* RTE_LIBRTE_EAL_HOTPLUG */
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v4 3/5] eal: Fix memory leaks and needless increment of pci_map_addr
  2015-05-19  5:54 [dpdk-dev] [PATCH v4 0/5] Clean up pci uio implementations Tetsuya Mukawa
  2015-05-19  5:54 ` [dpdk-dev] [PATCH v4 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
  2015-05-19  5:54 ` [dpdk-dev] [PATCH v4 2/5] eal: Close file descriptor of uio configuration Tetsuya Mukawa
@ 2015-05-19  5:54 ` Tetsuya Mukawa
  2015-06-15 14:29   ` Iremonger, Bernard
  2015-05-19  5:54 ` [dpdk-dev] [PATCH v4 4/5] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-05-19  5:54 UTC (permalink / raw)
  To: dev

This patch fixes following memory leaks.
- When open() is failed, uio_res and fds won't be freed in
  pci_uio_map_resource().
- When pci_map_resource() is failed but path is allocated correctly,
  path and fds won't be freed in pci_uio_map_recource().
- When pci_uio_unmap() is called, path should be freed.

Also, fixes below.
- When pci_map_resource() is failed, mapaddr will be MAP_FAILED.
  In this case, pci_map_addr should not be incremented in
  pci_uio_map_resource().
- To shrink code, move close().
- Remove fail variable.

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c       | 14 +++++++--
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 51 ++++++++++++++++++++-----------
 2 files changed, 44 insertions(+), 21 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 8e24fd1..b071f07 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -235,7 +235,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) == NULL) {
 		RTE_LOG(ERR, EAL,
 			"%s(): cannot store uio mmap details\n", __func__);
-		return -1;
+		goto close_fd;
 	}
 
 	snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
@@ -262,8 +262,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 		    (mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
 						(size_t)maps[j].size)
 		    ) == NULL) {
-			rte_free(uio_res);
-			return -1;
+			goto free_uio_res;
 		}
 
 		maps[j].addr = mapaddr;
@@ -274,6 +273,15 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
 
 	return 0;
+
+free_uio_res:
+	rte_free(uio_res);
+close_fd:
+	close(dev->intr_handle.fd);
+	dev->intr_handle.fd = -1;
+	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+
+	return -1;
 }
 
 /* Scan one pci sysfs entry, and fill the devices list from it. */
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 34316b6..2dd83d3 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -308,7 +308,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	if (dev->intr_handle.uio_cfg_fd < 0) {
 		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
 			cfgname, strerror(errno));
-		return -1;
+		goto close_fd;
 	}
 
 	if (dev->kdrv == RTE_KDRV_IGB_UIO)
@@ -328,7 +328,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	if (uio_res == NULL) {
 		RTE_LOG(ERR, EAL,
 			"%s(): cannot store uio mmap details\n", __func__);
-		return -1;
+		goto close_fd;
 	}
 
 	snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
@@ -338,7 +338,6 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	maps = uio_res->maps;
 	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
 		int fd;
-		int fail = 0;
 
 		/* skip empty BAR */
 		phaddr = dev->mem_resource[i].phys_addr;
@@ -352,6 +351,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 				loc->domain, loc->bus, loc->devid, loc->function,
 				i);
 
+		/* allocate memory to keep path */
+		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
+		if (maps[map_idx].path == NULL)
+			goto free_uio_res;
+
 		/*
 		 * open resource file, to mmap it
 		 */
@@ -359,7 +363,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 		if (fd < 0) {
 			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
 					devname, strerror(errno));
-			return -1;
+			rte_free(maps[map_idx].path);
+			goto free_uio_res;
 		}
 
 		/* try mapping somewhere close to the end of hugepages */
@@ -368,23 +373,15 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 		mapaddr = pci_map_resource(pci_map_addr, fd, 0,
 				(size_t)dev->mem_resource[i].len, 0);
-		if (mapaddr == MAP_FAILED)
-			fail = 1;
+		close(fd);
+		if (mapaddr == MAP_FAILED) {
+			rte_free(maps[map_idx].path);
+			goto free_uio_res;
+		}
 
 		pci_map_addr = RTE_PTR_ADD(mapaddr,
 				(size_t)dev->mem_resource[i].len);
 
-		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
-		if (maps[map_idx].path == NULL)
-			fail = 1;
-
-		if (fail) {
-			rte_free(uio_res);
-			close(fd);
-			return -1;
-		}
-		close(fd);
-
 		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
 		maps[map_idx].size = dev->mem_resource[i].len;
 		maps[map_idx].addr = mapaddr;
@@ -399,6 +396,22 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
 
 	return 0;
+
+free_uio_res:
+	for (i = 0; i < map_idx; i++)
+		rte_free(maps[i].path);
+	rte_free(uio_res);
+close_fd:
+	if (dev->intr_handle.uio_cfg_fd >= 0) {
+		close(dev->intr_handle.uio_cfg_fd);
+		dev->intr_handle.uio_cfg_fd = -1;
+	}
+
+	close(dev->intr_handle.fd);
+	dev->intr_handle.fd = -1;
+	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+
+	return -1;
 }
 
 #ifdef RTE_LIBRTE_EAL_HOTPLUG
@@ -410,9 +423,11 @@ pci_uio_unmap(struct mapped_pci_resource *uio_res)
 	if (uio_res == NULL)
 		return;
 
-	for (i = 0; i != uio_res->nb_maps; i++)
+	for (i = 0; i != uio_res->nb_maps; i++) {
 		pci_unmap_resource(uio_res->maps[i].addr,
 				(size_t)uio_res->maps[i].size);
+		rte_free(uio_res->maps[i].path);
+	}
 }
 
 static struct mapped_pci_resource *
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v4 4/5] eal/bsdapp: Change names of pci related data structure
  2015-05-19  5:54 [dpdk-dev] [PATCH v4 0/5] Clean up pci uio implementations Tetsuya Mukawa
                   ` (2 preceding siblings ...)
  2015-05-19  5:54 ` [dpdk-dev] [PATCH v4 3/5] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
@ 2015-05-19  5:54 ` Tetsuya Mukawa
  2015-05-19  5:54 ` [dpdk-dev] [PATCH v4 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp Tetsuya Mukawa
  2015-05-19  5:57 ` [dpdk-dev] [PATCH v4 0/5] Clean up pci uio implementations Tetsuya Mukawa
  5 siblings, 0 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-05-19  5:54 UTC (permalink / raw)
  To: dev

To merge pci code of linuxapp and bsdapp, this patch changes names
like below.
 - uio_map to pci_map
 - uio_resource to mapped_pci_resource
 - uio_res_list to mapped_pci_res_list

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index b071f07..8261e09 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -83,7 +83,7 @@
  * enabling bus master.
  */
 
-struct uio_map {
+struct pci_map {
 	void *addr;
 	uint64_t offset;
 	uint64_t size;
@@ -94,16 +94,16 @@ struct uio_map {
  * For multi-process we need to reproduce all PCI mappings in secondary
  * processes, so save them in a tailq.
  */
-struct uio_resource {
-	TAILQ_ENTRY(uio_resource) next;
+struct mapped_pci_resource {
+	TAILQ_ENTRY(mapped_pci_resource) next;
 
 	struct rte_pci_addr pci_addr;
 	char path[PATH_MAX];
 	size_t nb_maps;
-	struct uio_map maps[PCI_MAX_RESOURCE];
+	struct pci_map maps[PCI_MAX_RESOURCE];
 };
 
-TAILQ_HEAD(uio_res_list, uio_resource);
+TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource);
 
 static struct rte_tailq_elem rte_uio_tailq = {
 	.name = "UIO_RESOURCE_LIST",
@@ -162,9 +162,9 @@ static int
 pci_uio_map_secondary(struct rte_pci_device *dev)
 {
 	size_t i;
-	struct uio_resource *uio_res;
-	struct uio_res_list *uio_res_list =
-			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
+	struct mapped_pci_resource *uio_res;
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 
 	TAILQ_FOREACH(uio_res, uio_res_list, next) {
 
@@ -201,10 +201,10 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	uint64_t offset;
 	uint64_t pagesz;
 	struct rte_pci_addr *loc = &dev->addr;
-	struct uio_resource *uio_res;
-	struct uio_res_list *uio_res_list =
-			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
-	struct uio_map *maps;
+	struct mapped_pci_resource *uio_res;
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct pci_map *maps;
 
 	dev->intr_handle.fd = -1;
 	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v4 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp
  2015-05-19  5:54 [dpdk-dev] [PATCH v4 0/5] Clean up pci uio implementations Tetsuya Mukawa
                   ` (3 preceding siblings ...)
  2015-05-19  5:54 ` [dpdk-dev] [PATCH v4 4/5] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
@ 2015-05-19  5:54 ` Tetsuya Mukawa
  2015-06-15 14:31   ` Iremonger, Bernard
  2015-05-19  5:57 ` [dpdk-dev] [PATCH v4 0/5] Clean up pci uio implementations Tetsuya Mukawa
  5 siblings, 1 reply; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-05-19  5:54 UTC (permalink / raw)
  To: dev

This patch fixes below.
- bsdapp
 - Use map_id in pci_uio_map_resource().
 - Fix interface of pci_map_resource().
 - Move path variable of mapped_pci_resource structure to pci_map.
- linuxapp
 - Remove redundant error message of linuxapp.

'pci_uio_map_resource()' is implemented in both linuxapp and bsdapp,
but interface is different. The patch fixes the function of bsdapp
to do same as linuxapp. After applying it, file descriptor should be
opened and closed out of pci_map_resource().

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c       | 118 ++++++++++++++++++------------
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c |  21 +++---
 2 files changed, 80 insertions(+), 59 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 8261e09..06c564f 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -85,6 +85,7 @@
 
 struct pci_map {
 	void *addr;
+	char *path;
 	uint64_t offset;
 	uint64_t size;
 	uint64_t phaddr;
@@ -99,7 +100,7 @@ struct mapped_pci_resource {
 
 	struct rte_pci_addr pci_addr;
 	char path[PATH_MAX];
-	size_t nb_maps;
+	int nb_maps;
 	struct pci_map maps[PCI_MAX_RESOURCE];
 };
 
@@ -121,47 +122,30 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)
 
 /* map a particular resource from a file */
 static void *
-pci_map_resource(void *requested_addr, const char *devname, off_t offset,
-		 size_t size)
+pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
+		 int additional_flags)
 {
-	int fd;
 	void *mapaddr;
 
-	/*
-	 * open devname, to mmap it
-	 */
-	fd = open(devname, O_RDWR);
-	if (fd < 0) {
-		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
-			devname, strerror(errno));
-		goto fail;
-	}
-
 	/* Map the PCI memory resource of device */
 	mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
-			MAP_SHARED, fd, offset);
-	close(fd);
-	if (mapaddr == MAP_FAILED ||
-			(requested_addr != NULL && mapaddr != requested_addr)) {
-		RTE_LOG(ERR, EAL, "%s(): cannot mmap(%s(%d), %p, 0x%lx, 0x%lx):"
-			" %s (%p)\n", __func__, devname, fd, requested_addr,
+			MAP_SHARED | additional_flags, fd, offset);
+	if (mapaddr == MAP_FAILED) {
+		RTE_LOG(ERR, EAL,
+			"%s(): cannot mmap(%d, %p, 0x%lx, 0x%lx): %s (%p)\n",
+			__func__, fd, requested_addr,
 			(unsigned long)size, (unsigned long)offset,
 			strerror(errno), mapaddr);
-		goto fail;
-	}
-
-	RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
+	} else
+		RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
 
 	return mapaddr;
-
-fail:
-	return NULL;
 }
 
 static int
 pci_uio_map_secondary(struct rte_pci_device *dev)
 {
-	size_t i;
+	int i, fd;
 	struct mapped_pci_resource *uio_res;
 	struct mapped_pci_res_list *uio_res_list =
 			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
@@ -169,19 +153,34 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 	TAILQ_FOREACH(uio_res, uio_res_list, next) {
 
 		/* skip this element if it doesn't match our PCI address */
-		if (memcmp(&uio_res->pci_addr, &dev->addr, sizeof(dev->addr)))
+		if (rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr))
 			continue;
 
 		for (i = 0; i != uio_res->nb_maps; i++) {
-			if (pci_map_resource(uio_res->maps[i].addr,
-					     uio_res->path,
-					     (off_t)uio_res->maps[i].offset,
-					     (size_t)uio_res->maps[i].size)
-			    != uio_res->maps[i].addr) {
+			/*
+			 * open devname, to mmap it
+			 */
+			fd = open(uio_res->maps[i].path, O_RDWR);
+			if (fd < 0) {
+				RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
+					uio_res->maps[i].path, strerror(errno));
+				return -1;
+			}
+
+			void *mapaddr = pci_map_resource(uio_res->maps[i].addr,
+					fd, (off_t)uio_res->maps[i].offset,
+					(size_t)uio_res->maps[i].size, 0);
+			if (mapaddr != uio_res->maps[i].addr) {
 				RTE_LOG(ERR, EAL,
-					"Cannot mmap device resource\n");
+						"Cannot mmap device resource "
+						"file %s to address: %p\n",
+						uio_res->maps[i].path,
+						uio_res->maps[i].addr);
+				close(fd);
 				return -1;
 			}
+			/* fd is not needed in slave process, close it */
+			close(fd);
 		}
 		return 0;
 	}
@@ -194,7 +193,7 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 static int
 pci_uio_map_resource(struct rte_pci_device *dev)
 {
-	int i, j;
+	int i, map_idx;
 	char devname[PATH_MAX]; /* contains the /dev/uioX */
 	void *mapaddr;
 	uint64_t phaddr;
@@ -246,35 +245,60 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	pagesz = sysconf(_SC_PAGESIZE);
 
 	maps = uio_res->maps;
-	for (i = uio_res->nb_maps = 0; i != PCI_MAX_RESOURCE; i++) {
+	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
+		int fd;
 
-		j = uio_res->nb_maps;
 		/* skip empty BAR */
 		if ((phaddr = dev->mem_resource[i].phys_addr) == 0)
 			continue;
 
+		/* allocate memory to keep path */
+		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
+		if (maps[map_idx].path == NULL) {
+			RTE_LOG(ERR, EAL, "Cannot allocate memory for "
+					"path: %s\n", strerror(errno));
+			goto free_uio_res;
+		}
+
+		/*
+		 * open resource file, to mmap it
+		 */
+		fd = open(devname, O_RDWR);
+		if (fd < 0) {
+			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
+					devname, strerror(errno));
+			rte_free(maps[map_idx].path);
+			goto free_uio_res;
+		}
+
 		/* if matching map is found, then use it */
 		offset = i * pagesz;
-		maps[j].offset = offset;
-		maps[j].phaddr = dev->mem_resource[i].phys_addr;
-		maps[j].size = dev->mem_resource[i].len;
-		if (maps[j].addr != NULL ||
-		    (mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
-						(size_t)maps[j].size)
-		    ) == NULL) {
+		mapaddr = pci_map_resource(NULL, fd, (off_t)offset,
+					(size_t)dev->mem_resource[i].len, 0);
+		close(fd);
+		if (mapaddr == MAP_FAILED) {
+			rte_free(maps[map_idx].path);
 			goto free_uio_res;
 		}
 
-		maps[j].addr = mapaddr;
-		uio_res->nb_maps++;
+		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
+		maps[map_idx].size = dev->mem_resource[i].len;
+		maps[map_idx].addr = mapaddr;
+		maps[map_idx].offset = offset;
+		strcpy(maps[map_idx].path, devname);
+		map_idx++;
 		dev->mem_resource[i].addr = mapaddr;
 	}
 
+	uio_res->nb_maps = map_idx;
+
 	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
 
 	return 0;
 
 free_uio_res:
+	for (i = 0; i < map_idx; i++)
+		rte_free(maps[i].path);
 	rte_free(uio_res);
 close_fd:
 	close(dev->intr_handle.fd);
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 2dd83d3..98f4847 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -116,17 +116,11 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 					fd, (off_t)uio_res->maps[i].offset,
 					(size_t)uio_res->maps[i].size, 0);
 			if (mapaddr != uio_res->maps[i].addr) {
-				if (mapaddr == MAP_FAILED)
-					RTE_LOG(ERR, EAL,
-							"Cannot mmap device resource file %s: %s\n",
-							uio_res->maps[i].path,
-							strerror(errno));
-				else
-					RTE_LOG(ERR, EAL,
-							"Cannot mmap device resource file %s to address: %p\n",
-							uio_res->maps[i].path,
-							uio_res->maps[i].addr);
-
+				RTE_LOG(ERR, EAL,
+						"Cannot mmap device resource "
+						"file %s to address: %p\n",
+						uio_res->maps[i].path,
+						uio_res->maps[i].addr);
 				close(fd);
 				return -1;
 			}
@@ -353,8 +347,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 		/* allocate memory to keep path */
 		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
-		if (maps[map_idx].path == NULL)
+		if (maps[map_idx].path == NULL) {
+			RTE_LOG(ERR, EAL, "Cannot allocate memory for "
+					"path: %s\n", strerror(errno));
 			goto free_uio_res;
+		}
 
 		/*
 		 * open resource file, to mmap it
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v4 0/5] Clean up pci uio implementations
  2015-05-19  5:54 [dpdk-dev] [PATCH v4 0/5] Clean up pci uio implementations Tetsuya Mukawa
                   ` (4 preceding siblings ...)
  2015-05-19  5:54 ` [dpdk-dev] [PATCH v4 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp Tetsuya Mukawa
@ 2015-05-19  5:57 ` Tetsuya Mukawa
  5 siblings, 0 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-05-19  5:57 UTC (permalink / raw)
  To: bernard.iremonger; +Cc: dev

Hi Bernard,


I've updated the series, because I've found the issue in BSD code.
Also, I have rebased the series for latest master branch.

Could you please read my below comments?


On 2015/05/19 14:54, Tetsuya Mukawa wrote:
> This patch set cleans up pci uio implementation. These clean up are
> for consolidating pci uio implementation of linuxapp and bsdapp, and
> moving consolidated functions in eal common.
> Because of above, this patch set tries to implement linuxapp and bsdapp
> almost same.
> Actual consolidations will be done later patch set.
>
> PATCH v4 changes:
>  - Rebase to latest master branch.
>  - Fix bug in pci_uio_map_resource() of BSD code. 'maps[i].path' shouldn't be freed.
>      Fixed in below patch:
>      [PATCH 3/5] eal: Fix memory leaks and needless increment of pci_map_addr

pci_uio_map_resource() {
         ....snip....
-       for (i = 0; i < map_idx; i++)
-               rte_free(maps[i].path);
         ....snip....
}

I removed above code from BSD, because 'maps[i].path' will not be
allocated in BSD code.



>  - 'path' member of 'struct mapped_pci_resource' should not be removed because it will be used in BSD code.
>      Fixed in below patch:
>      [PATCH 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp

struct mapped_pci_resource {
        .....snip.....
        char path[PATH_MAX];
        .....snip.....
 };

I left 'path' member like above. It will be used by BSD code even after
BSD support port hotplug function.

Regards,
Tetsuya

>
> PATCH v3 changes:
>  - Squash patches related with pci_map_resource().
>  - Free maps[].path to easy to understand.
>    (Thanks to Iremonger, Bernard)
>  - Close fds opened in this function.
>  - Remove unused path variable from mapped_pci_resource structure.
>
> PATCH v2 changes:
>  - Move 'if-condition' to later patch series.
>  - Fix memory leaks of path.
>  - Fix typos.
>    (Thanks to David Marchand)
>  - Fix commit title and body.
>  - Fix pci_map_resource() to handle MAP_FAILED.
>    (Thanks to Iremonger, Bernard)
>
> Changes:
>  - This patch set is derived from below.
>    "[PATCH v2] eal: Port Hotplug support for BSD"
>  - Set cfg_fd as -1, when cfg_fd is closed.
>    (Thanks to Iremonger, Bernard)
>  - Remove needless coding style fixings.
>  - Fix coding style of if-else condition.
>    (Thanks to Richardson, Bruce)
>
>
> Tetsuya Mukawa (5):
>   eal: Fix coding style of eal_pci.c and eal_pci_uio.c
>   eal: Close file descriptor of uio configuration
>   eal: Fix memory leaks and needless increment of pci_map_addr
>   eal/bsdapp: Change names of pci related data structure
>   eal: Fix uio mapping differences between linuxapp and bsdapp
>
>  lib/librte_eal/bsdapp/eal/eal_pci.c       | 164 ++++++++++++++++++------------
>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c |  88 +++++++++-------
>  2 files changed, 153 insertions(+), 99 deletions(-)
>

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v4 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c
  2015-05-19  5:54 ` [dpdk-dev] [PATCH v4 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
@ 2015-05-19 14:51   ` Stephen Hemminger
  2015-06-25  3:19   ` [dpdk-dev] [PATCH v5 0/5] Clean up pci uio implementations Tetsuya Mukawa
  1 sibling, 0 replies; 120+ messages in thread
From: Stephen Hemminger @ 2015-05-19 14:51 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

Acked-by: Stephen Hemminger <stephen@networkplumber.org>

On Mon, May 18, 2015 at 10:54 PM, Tetsuya Mukawa <mukawa@igel.co.jp> wrote:

> This patch fixes coding style of below files in linuxapp and bsdapp.
>  - eal_pci.c
>  - eal_pci_uio.c
>
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  lib/librte_eal/bsdapp/eal/eal_pci.c       | 24 +++++++++++++-----------
>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 12 ++++++++----
>  2 files changed, 21 insertions(+), 15 deletions(-)
>
> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c
> b/lib/librte_eal/bsdapp/eal/eal_pci.c
> index 61e8921..8e24fd1 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> @@ -161,9 +161,10 @@ fail:
>  static int
>  pci_uio_map_secondary(struct rte_pci_device *dev)
>  {
> -        size_t i;
> -        struct uio_resource *uio_res;
> -       struct uio_res_list *uio_res_list =
> RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
> +       size_t i;
> +       struct uio_resource *uio_res;
> +       struct uio_res_list *uio_res_list =
> +                       RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
>
>         TAILQ_FOREACH(uio_res, uio_res_list, next) {
>
> @@ -179,10 +180,10 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
>                             != uio_res->maps[i].addr) {
>                                 RTE_LOG(ERR, EAL,
>                                         "Cannot mmap device resource\n");
> -                               return (-1);
> +                               return -1;
>                         }
>                 }
> -               return (0);
> +               return 0;
>         }
>
>         RTE_LOG(ERR, EAL, "Cannot find resource for device\n");
> @@ -201,7 +202,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>         uint64_t pagesz;
>         struct rte_pci_addr *loc = &dev->addr;
>         struct uio_resource *uio_res;
> -       struct uio_res_list *uio_res_list =
> RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
> +       struct uio_res_list *uio_res_list =
> +                       RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
>         struct uio_map *maps;
>
>         dev->intr_handle.fd = -1;
> @@ -209,7 +211,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>
>         /* secondary processes - use already recorded details */
>         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
> -               return (pci_uio_map_secondary(dev));
> +               return pci_uio_map_secondary(dev);
>
>         snprintf(devname, sizeof(devname), "/dev/uio@pci:%u:%u:%u",
>                         dev->addr.bus, dev->addr.devid,
> dev->addr.function);
> @@ -233,7 +235,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>         if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) ==
> NULL) {
>                 RTE_LOG(ERR, EAL,
>                         "%s(): cannot store uio mmap details\n", __func__);
> -               return (-1);
> +               return -1;
>         }
>
>         snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
> @@ -261,7 +263,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>                                                 (size_t)maps[j].size)
>                     ) == NULL) {
>                         rte_free(uio_res);
> -                       return (-1);
> +                       return -1;
>                 }
>
>                 maps[j].addr = mapaddr;
> @@ -271,7 +273,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>
>         TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
>
> -       return (0);
> +       return 0;
>  }
>
>  /* Scan one pci sysfs entry, and fill the devices list from it. */
> @@ -311,7 +313,7 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
>         /* FreeBSD has no NUMA support (yet) */
>         dev->numa_node = 0;
>
> -/* parse resources */
> +       /* parse resources */
>         switch (conf->pc_hdr & PCIM_HDRTYPE) {
>         case PCIM_HDRTYPE_NORMAL:
>                 max = PCIR_MAX_BAR_0;
> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> index b5116a7..5d3354d 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> @@ -92,7 +92,8 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
>  {
>         int fd, i;
>         struct mapped_pci_resource *uio_res;
> -       struct mapped_pci_res_list *uio_res_list =
> RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
> +       struct mapped_pci_res_list *uio_res_list =
> +                       RTE_TAILQ_CAST(rte_uio_tailq.head,
> mapped_pci_res_list);
>
>         TAILQ_FOREACH(uio_res, uio_res_list, next) {
>
> @@ -272,7 +273,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>         uint64_t phaddr;
>         struct rte_pci_addr *loc = &dev->addr;
>         struct mapped_pci_resource *uio_res;
> -       struct mapped_pci_res_list *uio_res_list =
> RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
> +       struct mapped_pci_res_list *uio_res_list =
> +                       RTE_TAILQ_CAST(rte_uio_tailq.head,
> mapped_pci_res_list);
>         struct pci_map *maps;
>
>         dev->intr_handle.fd = -1;
> @@ -417,7 +419,8 @@ static struct mapped_pci_resource *
>  pci_uio_find_resource(struct rte_pci_device *dev)
>  {
>         struct mapped_pci_resource *uio_res;
> -       struct mapped_pci_res_list *uio_res_list =
> RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
> +       struct mapped_pci_res_list *uio_res_list =
> +                       RTE_TAILQ_CAST(rte_uio_tailq.head,
> mapped_pci_res_list);
>
>         if (dev == NULL)
>                 return NULL;
> @@ -436,7 +439,8 @@ void
>  pci_uio_unmap_resource(struct rte_pci_device *dev)
>  {
>         struct mapped_pci_resource *uio_res;
> -       struct mapped_pci_res_list *uio_res_list =
> RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
> +       struct mapped_pci_res_list *uio_res_list =
> +                       RTE_TAILQ_CAST(rte_uio_tailq.head,
> mapped_pci_res_list);
>
>         if (dev == NULL)
>                 return;
> --
> 2.1.4
>
>

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v4 2/5] eal: Close file descriptor of uio configuration
  2015-05-19  5:54 ` [dpdk-dev] [PATCH v4 2/5] eal: Close file descriptor of uio configuration Tetsuya Mukawa
@ 2015-05-19 16:02   ` Stephen Hemminger
  0 siblings, 0 replies; 120+ messages in thread
From: Stephen Hemminger @ 2015-05-19 16:02 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Tue, 19 May 2015 14:54:55 +0900
Tetsuya Mukawa <mukawa@igel.co.jp> wrote:

> When pci_uio_unmap_resource() is called, a file descriptor that is used
> for uio configuration should be closed.
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> index 5d3354d..34316b6 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> @@ -464,8 +464,12 @@ pci_uio_unmap_resource(struct rte_pci_device *dev)
>  
>  	/* close fd if in primary process */
>  	close(dev->intr_handle.fd);
> -
>  	dev->intr_handle.fd = -1;
> +
> +	/* close cfg_fd if in primary process */
> +	close(dev->intr_handle.uio_cfg_fd);
> +	dev->intr_handle.uio_cfg_fd = -1;
> +
>  	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
>  }
>  #endif /* RTE_LIBRTE_EAL_HOTPLUG */

Acked-by: Stephen Hemminger <stephen@networkplumber.org>

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v4 3/5] eal: Fix memory leaks and needless increment of pci_map_addr
  2015-05-19  5:54 ` [dpdk-dev] [PATCH v4 3/5] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
@ 2015-06-15 14:29   ` Iremonger, Bernard
  2015-06-15 15:05     ` Iremonger, Bernard
  0 siblings, 1 reply; 120+ messages in thread
From: Iremonger, Bernard @ 2015-06-15 14:29 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev

> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Tuesday, May 19, 2015 6:55 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; Tetsuya Mukawa
> Subject: [PATCH v4 3/5] eal: Fix memory leaks and needless increment of
> pci_map_addr
> 
> This patch fixes following memory leaks.
> - When open() is failed, uio_res and fds won't be freed in
>   pci_uio_map_resource().
> - When pci_map_resource() is failed but path is allocated correctly,
>   path and fds won't be freed in pci_uio_map_recource().
> - When pci_uio_unmap() is called, path should be freed.
> 
> Also, fixes below.
> - When pci_map_resource() is failed, mapaddr will be MAP_FAILED.
>   In this case, pci_map_addr should not be incremented in
>   pci_uio_map_resource().
> - To shrink code, move close().
> - Remove fail variable.
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  lib/librte_eal/bsdapp/eal/eal_pci.c       | 14 +++++++--
>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 51 ++++++++++++++++++++------
> -----
>  2 files changed, 44 insertions(+), 21 deletions(-)
> 
> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c
> b/lib/librte_eal/bsdapp/eal/eal_pci.c
> index 8e24fd1..b071f07 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> @@ -235,7 +235,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  	if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) == NULL)
> {
>  		RTE_LOG(ERR, EAL,
>  			"%s(): cannot store uio mmap details\n", __func__);
> -		return -1;
> +		goto close_fd;
>  	}
> 
>  	snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname); @@
> -262,8 +262,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  		    (mapaddr = pci_map_resource(NULL, devname,
> (off_t)offset,
>  						(size_t)maps[j].size)
>  		    ) == NULL) {
> -			rte_free(uio_res);
> -			return -1;
> +			goto free_uio_res;
>  		}
> 
>  		maps[j].addr = mapaddr;
> @@ -274,6 +273,15 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
> 
>  	return 0;
> +
> +free_uio_res:
> +	rte_free(uio_res);
> +close_fd:
> +	close(dev->intr_handle.fd);
> +	dev->intr_handle.fd = -1;
> +	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
> +
> +	return -1;
>  }
> 
>  /* Scan one pci sysfs entry, and fill the devices list from it. */ diff --git
> a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> index 34316b6..2dd83d3 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> @@ -308,7 +308,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  	if (dev->intr_handle.uio_cfg_fd < 0) {
>  		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
>  			cfgname, strerror(errno));
> -		return -1;
> +		goto close_fd;
>  	}
> 
>  	if (dev->kdrv == RTE_KDRV_IGB_UIO)
> @@ -328,7 +328,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  	if (uio_res == NULL) {
>  		RTE_LOG(ERR, EAL,
>  			"%s(): cannot store uio mmap details\n", __func__);
> -		return -1;
> +		goto close_fd;
>  	}
> 
>  	snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname); @@
> -338,7 +338,6 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  	maps = uio_res->maps;
>  	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
>  		int fd;
> -		int fail = 0;
> 
>  		/* skip empty BAR */
>  		phaddr = dev->mem_resource[i].phys_addr; @@ -352,6
> +351,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  				loc->domain, loc->bus, loc->devid, loc-
> >function,
>  				i);
> 
> +		/* allocate memory to keep path */
> +		maps[map_idx].path = rte_malloc(NULL, strlen(devname) +
> 1, 0);
> +		if (maps[map_idx].path == NULL)
> +			goto free_uio_res;
> +
>  		/*
>  		 * open resource file, to mmap it
>  		 */
> @@ -359,7 +363,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  		if (fd < 0) {
>  			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
>  					devname, strerror(errno));
> -			return -1;
> +			rte_free(maps[map_idx].path);
> +			goto free_uio_res;
>  		}
> 
>  		/* try mapping somewhere close to the end of hugepages */
> @@ -368,23 +373,15 @@ pci_uio_map_resource(struct rte_pci_device *dev)
> 
>  		mapaddr = pci_map_resource(pci_map_addr, fd, 0,
>  				(size_t)dev->mem_resource[i].len, 0);
> -		if (mapaddr == MAP_FAILED)
> -			fail = 1;
> +		close(fd);
> +		if (mapaddr == MAP_FAILED) {
> +			rte_free(maps[map_idx].path);
> +			goto free_uio_res;
> +		}
> 
>  		pci_map_addr = RTE_PTR_ADD(mapaddr,
>  				(size_t)dev->mem_resource[i].len);
> 
> -		maps[map_idx].path = rte_malloc(NULL, strlen(devname) +
> 1, 0);
> -		if (maps[map_idx].path == NULL)
> -			fail = 1;
> -
> -		if (fail) {
> -			rte_free(uio_res);
> -			close(fd);
> -			return -1;
> -		}
> -		close(fd);
> -
>  		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
>  		maps[map_idx].size = dev->mem_resource[i].len;
>  		maps[map_idx].addr = mapaddr;
> @@ -399,6 +396,22 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
> 
>  	return 0;
> +
> +free_uio_res:
> +	for (i = 0; i < map_idx; i++)
> +		rte_free(maps[i].path);
> +	rte_free(uio_res);
> +close_fd:
> +	if (dev->intr_handle.uio_cfg_fd >= 0) {
> +		close(dev->intr_handle.uio_cfg_fd);
> +		dev->intr_handle.uio_cfg_fd = -1;
> +	}
> +
> +	close(dev->intr_handle.fd);
> +	dev->intr_handle.fd = -1;
> +	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
> +
> +	return -1;
>  }
> 
>  #ifdef RTE_LIBRTE_EAL_HOTPLUG
> @@ -410,9 +423,11 @@ pci_uio_unmap(struct mapped_pci_resource
> *uio_res)
>  	if (uio_res == NULL)
>  		return;
> 
> -	for (i = 0; i != uio_res->nb_maps; i++)
> +	for (i = 0; i != uio_res->nb_maps; i++) {
>  		pci_unmap_resource(uio_res->maps[i].addr,
>  				(size_t)uio_res->maps[i].size);
> +		rte_free(uio_res->maps[i].path);
> +	}
>  }
> 
>  static struct mapped_pci_resource *
> --
> 2.1.4

Hi Tetsuya,

This patch fails to apply to the latest code.

Applying: eal: Fix memory leaks and needless increment of pci_map_addr
error: patch failed: lib/librte_eal/linuxapp/eal/eal_pci_uio.c:309

It looks like another rebase is needed.

Regards,

Bernard.

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v4 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp
  2015-05-19  5:54 ` [dpdk-dev] [PATCH v4 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp Tetsuya Mukawa
@ 2015-06-15 14:31   ` Iremonger, Bernard
  2015-06-15 15:08     ` Iremonger, Bernard
  0 siblings, 1 reply; 120+ messages in thread
From: Iremonger, Bernard @ 2015-06-15 14:31 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev

> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Tuesday, May 19, 2015 6:55 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; Tetsuya Mukawa
> Subject: [PATCH v4 5/5] eal: Fix uio mapping differences between linuxapp
> and bsdapp
> 
> This patch fixes below.
> - bsdapp
>  - Use map_id in pci_uio_map_resource().
>  - Fix interface of pci_map_resource().
>  - Move path variable of mapped_pci_resource structure to pci_map.
> - linuxapp
>  - Remove redundant error message of linuxapp.
> 
> 'pci_uio_map_resource()' is implemented in both linuxapp and bsdapp, but
> interface is different. The patch fixes the function of bsdapp to do same as
> linuxapp. After applying it, file descriptor should be opened and closed out of
> pci_map_resource().
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  lib/librte_eal/bsdapp/eal/eal_pci.c       | 118 ++++++++++++++++++-----------
> -
>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c |  21 +++---
>  2 files changed, 80 insertions(+), 59 deletions(-)
> 
> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c
> b/lib/librte_eal/bsdapp/eal/eal_pci.c
> index 8261e09..06c564f 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> @@ -85,6 +85,7 @@
> 
>  struct pci_map {
>  	void *addr;
> +	char *path;
>  	uint64_t offset;
>  	uint64_t size;
>  	uint64_t phaddr;
> @@ -99,7 +100,7 @@ struct mapped_pci_resource {
> 
>  	struct rte_pci_addr pci_addr;
>  	char path[PATH_MAX];
> -	size_t nb_maps;
> +	int nb_maps;
>  	struct pci_map maps[PCI_MAX_RESOURCE];  };
> 
> @@ -121,47 +122,30 @@ pci_unbind_kernel_driver(struct rte_pci_device
> *dev __rte_unused)
> 
>  /* map a particular resource from a file */  static void * -
> pci_map_resource(void *requested_addr, const char *devname, off_t
> offset,
> -		 size_t size)
> +pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
> +		 int additional_flags)
>  {
> -	int fd;
>  	void *mapaddr;
> 
> -	/*
> -	 * open devname, to mmap it
> -	 */
> -	fd = open(devname, O_RDWR);
> -	if (fd < 0) {
> -		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
> -			devname, strerror(errno));
> -		goto fail;
> -	}
> -
>  	/* Map the PCI memory resource of device */
>  	mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
> -			MAP_SHARED, fd, offset);
> -	close(fd);
> -	if (mapaddr == MAP_FAILED ||
> -			(requested_addr != NULL && mapaddr !=
> requested_addr)) {
> -		RTE_LOG(ERR, EAL, "%s(): cannot mmap(%s(%d), %p, 0x%lx,
> 0x%lx):"
> -			" %s (%p)\n", __func__, devname, fd,
> requested_addr,
> +			MAP_SHARED | additional_flags, fd, offset);
> +	if (mapaddr == MAP_FAILED) {
> +		RTE_LOG(ERR, EAL,
> +			"%s(): cannot mmap(%d, %p, 0x%lx, 0x%lx): %s
> (%p)\n",
> +			__func__, fd, requested_addr,
>  			(unsigned long)size, (unsigned long)offset,
>  			strerror(errno), mapaddr);
> -		goto fail;
> -	}
> -
> -	RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
> +	} else
> +		RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n",
> mapaddr);
> 
>  	return mapaddr;
> -
> -fail:
> -	return NULL;
>  }
> 
>  static int
>  pci_uio_map_secondary(struct rte_pci_device *dev)  {
> -	size_t i;
> +	int i, fd;
>  	struct mapped_pci_resource *uio_res;
>  	struct mapped_pci_res_list *uio_res_list =
>  			RTE_TAILQ_CAST(rte_uio_tailq.head,
> mapped_pci_res_list); @@ -169,19 +153,34 @@
> pci_uio_map_secondary(struct rte_pci_device *dev)
>  	TAILQ_FOREACH(uio_res, uio_res_list, next) {
> 
>  		/* skip this element if it doesn't match our PCI address */
> -		if (memcmp(&uio_res->pci_addr, &dev->addr, sizeof(dev-
> >addr)))
> +		if (rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev-
> >addr))
>  			continue;
> 
>  		for (i = 0; i != uio_res->nb_maps; i++) {
> -			if (pci_map_resource(uio_res->maps[i].addr,
> -					     uio_res->path,
> -					     (off_t)uio_res->maps[i].offset,
> -					     (size_t)uio_res->maps[i].size)
> -			    != uio_res->maps[i].addr) {
> +			/*
> +			 * open devname, to mmap it
> +			 */
> +			fd = open(uio_res->maps[i].path, O_RDWR);
> +			if (fd < 0) {
> +				RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
> +					uio_res->maps[i].path,
> strerror(errno));
> +				return -1;
> +			}
> +
> +			void *mapaddr = pci_map_resource(uio_res-
> >maps[i].addr,
> +					fd, (off_t)uio_res->maps[i].offset,
> +					(size_t)uio_res->maps[i].size, 0);
> +			if (mapaddr != uio_res->maps[i].addr) {
>  				RTE_LOG(ERR, EAL,
> -					"Cannot mmap device resource\n");
> +						"Cannot mmap device
> resource "
> +						"file %s to address: %p\n",
> +						uio_res->maps[i].path,
> +						uio_res->maps[i].addr);
> +				close(fd);
>  				return -1;
>  			}
> +			/* fd is not needed in slave process, close it */
> +			close(fd);
>  		}
>  		return 0;
>  	}
> @@ -194,7 +193,7 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
> static int  pci_uio_map_resource(struct rte_pci_device *dev)  {
> -	int i, j;
> +	int i, map_idx;
>  	char devname[PATH_MAX]; /* contains the /dev/uioX */
>  	void *mapaddr;
>  	uint64_t phaddr;
> @@ -246,35 +245,60 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  	pagesz = sysconf(_SC_PAGESIZE);
> 
>  	maps = uio_res->maps;
> -	for (i = uio_res->nb_maps = 0; i != PCI_MAX_RESOURCE; i++) {
> +	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
> +		int fd;
> 
> -		j = uio_res->nb_maps;
>  		/* skip empty BAR */
>  		if ((phaddr = dev->mem_resource[i].phys_addr) == 0)
>  			continue;
> 
> +		/* allocate memory to keep path */
> +		maps[map_idx].path = rte_malloc(NULL, strlen(devname) +
> 1, 0);
> +		if (maps[map_idx].path == NULL) {
> +			RTE_LOG(ERR, EAL, "Cannot allocate memory for "
> +					"path: %s\n", strerror(errno));
> +			goto free_uio_res;
> +		}
> +
> +		/*
> +		 * open resource file, to mmap it
> +		 */
> +		fd = open(devname, O_RDWR);
> +		if (fd < 0) {
> +			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
> +					devname, strerror(errno));
> +			rte_free(maps[map_idx].path);
> +			goto free_uio_res;
> +		}
> +
>  		/* if matching map is found, then use it */
>  		offset = i * pagesz;
> -		maps[j].offset = offset;
> -		maps[j].phaddr = dev->mem_resource[i].phys_addr;
> -		maps[j].size = dev->mem_resource[i].len;
> -		if (maps[j].addr != NULL ||
> -		    (mapaddr = pci_map_resource(NULL, devname,
> (off_t)offset,
> -						(size_t)maps[j].size)
> -		    ) == NULL) {
> +		mapaddr = pci_map_resource(NULL, fd, (off_t)offset,
> +					(size_t)dev->mem_resource[i].len,
> 0);
> +		close(fd);
> +		if (mapaddr == MAP_FAILED) {
> +			rte_free(maps[map_idx].path);
>  			goto free_uio_res;
>  		}
> 
> -		maps[j].addr = mapaddr;
> -		uio_res->nb_maps++;
> +		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
> +		maps[map_idx].size = dev->mem_resource[i].len;
> +		maps[map_idx].addr = mapaddr;
> +		maps[map_idx].offset = offset;
> +		strcpy(maps[map_idx].path, devname);
> +		map_idx++;
>  		dev->mem_resource[i].addr = mapaddr;
>  	}
> 
> +	uio_res->nb_maps = map_idx;
> +
>  	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
> 
>  	return 0;
> 
>  free_uio_res:
> +	for (i = 0; i < map_idx; i++)
> +		rte_free(maps[i].path);
>  	rte_free(uio_res);
>  close_fd:
>  	close(dev->intr_handle.fd);
> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> index 2dd83d3..98f4847 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> @@ -116,17 +116,11 @@ pci_uio_map_secondary(struct rte_pci_device
> *dev)
>  					fd, (off_t)uio_res->maps[i].offset,
>  					(size_t)uio_res->maps[i].size, 0);
>  			if (mapaddr != uio_res->maps[i].addr) {
> -				if (mapaddr == MAP_FAILED)
> -					RTE_LOG(ERR, EAL,
> -							"Cannot mmap
> device resource file %s: %s\n",
> -							uio_res-
> >maps[i].path,
> -							strerror(errno));
> -				else
> -					RTE_LOG(ERR, EAL,
> -							"Cannot mmap
> device resource file %s to address: %p\n",
> -							uio_res-
> >maps[i].path,
> -							uio_res-
> >maps[i].addr);
> -
> +				RTE_LOG(ERR, EAL,
> +						"Cannot mmap device
> resource "
> +						"file %s to address: %p\n",
> +						uio_res->maps[i].path,
> +						uio_res->maps[i].addr);
>  				close(fd);
>  				return -1;
>  			}
> @@ -353,8 +347,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
> 
>  		/* allocate memory to keep path */
>  		maps[map_idx].path = rte_malloc(NULL, strlen(devname) +
> 1, 0);
> -		if (maps[map_idx].path == NULL)
> +		if (maps[map_idx].path == NULL) {
> +			RTE_LOG(ERR, EAL, "Cannot allocate memory for "
> +					"path: %s\n", strerror(errno));
>  			goto free_uio_res;
> +		}
> 
>  		/*
>  		 * open resource file, to mmap it
> --
> 2.1.4

Hi Tetsuya,

This patch fails to apply to the latest code.

Applying: eal: Fix uio mapping differences between linuxapp and bsdapp
error: patch failed: lib/librte_eal/bsdapp/eal/eal_pci.c:238
error: lib/librte_eal/bsdapp/eal/eal_pci.c: patch does not apply
error: patch failed: lib/librte_eal/linuxapp/eal/eal_pci_uio.c:326
error: lib/librte_eal/linuxapp/eal/eal_pci_uio.c: patch does not apply

It looks like another rebase is needed.

Regards,

Bernard.

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v4 3/5] eal: Fix memory leaks and needless increment of pci_map_addr
  2015-06-15 14:29   ` Iremonger, Bernard
@ 2015-06-15 15:05     ` Iremonger, Bernard
  0 siblings, 0 replies; 120+ messages in thread
From: Iremonger, Bernard @ 2015-06-15 15:05 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev

> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Iremonger, Bernard
> Sent: Monday, June 15, 2015 3:30 PM
> To: Tetsuya Mukawa; dev@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH v4 3/5] eal: Fix memory leaks and needless
> increment of pci_map_addr
> 
> > -----Original Message-----
> > From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> > Sent: Tuesday, May 19, 2015 6:55 AM
> > To: dev@dpdk.org
> > Cc: Iremonger, Bernard; Tetsuya Mukawa
> > Subject: [PATCH v4 3/5] eal: Fix memory leaks and needless increment
> > of pci_map_addr
> >
> > This patch fixes following memory leaks.
> > - When open() is failed, uio_res and fds won't be freed in
> >   pci_uio_map_resource().
> > - When pci_map_resource() is failed but path is allocated correctly,
> >   path and fds won't be freed in pci_uio_map_recource().
> > - When pci_uio_unmap() is called, path should be freed.
> >
> > Also, fixes below.
> > - When pci_map_resource() is failed, mapaddr will be MAP_FAILED.
> >   In this case, pci_map_addr should not be incremented in
> >   pci_uio_map_resource().
> > - To shrink code, move close().
> > - Remove fail variable.
> >
> > Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> > ---
> >  lib/librte_eal/bsdapp/eal/eal_pci.c       | 14 +++++++--
> >  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 51
> > ++++++++++++++++++++------
> > -----
> >  2 files changed, 44 insertions(+), 21 deletions(-)
> >
> > diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c
> > b/lib/librte_eal/bsdapp/eal/eal_pci.c
> > index 8e24fd1..b071f07 100644
> > --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> > +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> > @@ -235,7 +235,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
> >  	if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) ==
> > NULL) {
> >  		RTE_LOG(ERR, EAL,
> >  			"%s(): cannot store uio mmap details\n", __func__);
> > -		return -1;
> > +		goto close_fd;
> >  	}
> >
> >  	snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname); @@
> > -262,8 +262,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
> >  		    (mapaddr = pci_map_resource(NULL, devname,
> (off_t)offset,
> >  						(size_t)maps[j].size)
> >  		    ) == NULL) {
> > -			rte_free(uio_res);
> > -			return -1;
> > +			goto free_uio_res;
> >  		}
> >
> >  		maps[j].addr = mapaddr;
> > @@ -274,6 +273,15 @@ pci_uio_map_resource(struct rte_pci_device
> *dev)
> >  	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
> >
> >  	return 0;
> > +
> > +free_uio_res:
> > +	rte_free(uio_res);
> > +close_fd:
> > +	close(dev->intr_handle.fd);
> > +	dev->intr_handle.fd = -1;
> > +	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
> > +
> > +	return -1;
> >  }
> >
> >  /* Scan one pci sysfs entry, and fill the devices list from it. */
> > diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> > b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> > index 34316b6..2dd83d3 100644
> > --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> > +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> > @@ -308,7 +308,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
> >  	if (dev->intr_handle.uio_cfg_fd < 0) {
> >  		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
> >  			cfgname, strerror(errno));
> > -		return -1;
> > +		goto close_fd;
> >  	}
> >
> >  	if (dev->kdrv == RTE_KDRV_IGB_UIO)
> > @@ -328,7 +328,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
> >  	if (uio_res == NULL) {
> >  		RTE_LOG(ERR, EAL,
> >  			"%s(): cannot store uio mmap details\n", __func__);
> > -		return -1;
> > +		goto close_fd;
> >  	}
> >
> >  	snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname); @@
> > -338,7 +338,6 @@ pci_uio_map_resource(struct rte_pci_device *dev)
> >  	maps = uio_res->maps;
> >  	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
> >  		int fd;
> > -		int fail = 0;
> >
> >  		/* skip empty BAR */
> >  		phaddr = dev->mem_resource[i].phys_addr; @@ -352,6
> > +351,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
> >  				loc->domain, loc->bus, loc->devid, loc-
> > >function,
> >  				i);
> >
> > +		/* allocate memory to keep path */
> > +		maps[map_idx].path = rte_malloc(NULL, strlen(devname) +
> > 1, 0);
> > +		if (maps[map_idx].path == NULL)
> > +			goto free_uio_res;
> > +
> >  		/*
> >  		 * open resource file, to mmap it
> >  		 */
> > @@ -359,7 +363,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
> >  		if (fd < 0) {
> >  			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
> >  					devname, strerror(errno));
> > -			return -1;
> > +			rte_free(maps[map_idx].path);
> > +			goto free_uio_res;
> >  		}
> >
> >  		/* try mapping somewhere close to the end of hugepages */
> @@
> > -368,23 +373,15 @@ pci_uio_map_resource(struct rte_pci_device *dev)
> >
> >  		mapaddr = pci_map_resource(pci_map_addr, fd, 0,
> >  				(size_t)dev->mem_resource[i].len, 0);
> > -		if (mapaddr == MAP_FAILED)
> > -			fail = 1;
> > +		close(fd);
> > +		if (mapaddr == MAP_FAILED) {
> > +			rte_free(maps[map_idx].path);
> > +			goto free_uio_res;
> > +		}
> >
> >  		pci_map_addr = RTE_PTR_ADD(mapaddr,
> >  				(size_t)dev->mem_resource[i].len);
> >
> > -		maps[map_idx].path = rte_malloc(NULL, strlen(devname) +
> > 1, 0);
> > -		if (maps[map_idx].path == NULL)
> > -			fail = 1;
> > -
> > -		if (fail) {
> > -			rte_free(uio_res);
> > -			close(fd);
> > -			return -1;
> > -		}
> > -		close(fd);
> > -
> >  		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
> >  		maps[map_idx].size = dev->mem_resource[i].len;
> >  		maps[map_idx].addr = mapaddr;
> > @@ -399,6 +396,22 @@ pci_uio_map_resource(struct rte_pci_device
> *dev)
> >  	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
> >
> >  	return 0;
> > +
> > +free_uio_res:
> > +	for (i = 0; i < map_idx; i++)
> > +		rte_free(maps[i].path);
> > +	rte_free(uio_res);
> > +close_fd:
> > +	if (dev->intr_handle.uio_cfg_fd >= 0) {
> > +		close(dev->intr_handle.uio_cfg_fd);
> > +		dev->intr_handle.uio_cfg_fd = -1;
> > +	}
> > +
> > +	close(dev->intr_handle.fd);
> > +	dev->intr_handle.fd = -1;
> > +	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
> > +
> > +	return -1;
> >  }
> >
> >  #ifdef RTE_LIBRTE_EAL_HOTPLUG
> > @@ -410,9 +423,11 @@ pci_uio_unmap(struct mapped_pci_resource
> > *uio_res)
> >  	if (uio_res == NULL)
> >  		return;
> >
> > -	for (i = 0; i != uio_res->nb_maps; i++)
> > +	for (i = 0; i != uio_res->nb_maps; i++) {
> >  		pci_unmap_resource(uio_res->maps[i].addr,
> >  				(size_t)uio_res->maps[i].size);
> > +		rte_free(uio_res->maps[i].path);
> > +	}
> >  }
> >
> >  static struct mapped_pci_resource *
> > --
> > 2.1.4
> 
> Hi Tetsuya,
> 
> This patch fails to apply to the latest code.
> 
> Applying: eal: Fix memory leaks and needless increment of pci_map_addr
> error: patch failed: lib/librte_eal/linuxapp/eal/eal_pci_uio.c:309
> 
> It looks like another rebase is needed.
> 
> Regards,
> 
> Bernard.
> 
Hi Tetsuya,

Please ignore previous email.
This patch applies ok to the latest code ( I applied the v3 patch by mistake).

Regards,

Bernard.

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v4 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp
  2015-06-15 14:31   ` Iremonger, Bernard
@ 2015-06-15 15:08     ` Iremonger, Bernard
  2015-06-15 15:17       ` Thomas Monjalon
  0 siblings, 1 reply; 120+ messages in thread
From: Iremonger, Bernard @ 2015-06-15 15:08 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev

> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Iremonger, Bernard
> Sent: Monday, June 15, 2015 3:32 PM
> To: Tetsuya Mukawa; dev@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH v4 5/5] eal: Fix uio mapping differences
> between linuxapp and bsdapp
> 
> > -----Original Message-----
> > From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> > Sent: Tuesday, May 19, 2015 6:55 AM
> > To: dev@dpdk.org
> > Cc: Iremonger, Bernard; Tetsuya Mukawa
> > Subject: [PATCH v4 5/5] eal: Fix uio mapping differences between
> > linuxapp and bsdapp
> >
> > This patch fixes below.
> > - bsdapp
> >  - Use map_id in pci_uio_map_resource().
> >  - Fix interface of pci_map_resource().
> >  - Move path variable of mapped_pci_resource structure to pci_map.
> > - linuxapp
> >  - Remove redundant error message of linuxapp.
> >
> > 'pci_uio_map_resource()' is implemented in both linuxapp and bsdapp,
> > but interface is different. The patch fixes the function of bsdapp to
> > do same as linuxapp. After applying it, file descriptor should be
> > opened and closed out of pci_map_resource().
> >
> > Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> > ---
> >  lib/librte_eal/bsdapp/eal/eal_pci.c       | 118 ++++++++++++++++++---------
> --
> > -
> >  lib/librte_eal/linuxapp/eal/eal_pci_uio.c |  21 +++---
> >  2 files changed, 80 insertions(+), 59 deletions(-)
> >
> > diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c
> > b/lib/librte_eal/bsdapp/eal/eal_pci.c
> > index 8261e09..06c564f 100644
> > --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> > +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> > @@ -85,6 +85,7 @@
> >
> >  struct pci_map {
> >  	void *addr;
> > +	char *path;
> >  	uint64_t offset;
> >  	uint64_t size;
> >  	uint64_t phaddr;
> > @@ -99,7 +100,7 @@ struct mapped_pci_resource {
> >
> >  	struct rte_pci_addr pci_addr;
> >  	char path[PATH_MAX];
> > -	size_t nb_maps;
> > +	int nb_maps;
> >  	struct pci_map maps[PCI_MAX_RESOURCE];  };
> >
> > @@ -121,47 +122,30 @@ pci_unbind_kernel_driver(struct rte_pci_device
> > *dev __rte_unused)
> >
> >  /* map a particular resource from a file */  static void * -
> > pci_map_resource(void *requested_addr, const char *devname, off_t
> > offset,
> > -		 size_t size)
> > +pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
> > +		 int additional_flags)
> >  {
> > -	int fd;
> >  	void *mapaddr;
> >
> > -	/*
> > -	 * open devname, to mmap it
> > -	 */
> > -	fd = open(devname, O_RDWR);
> > -	if (fd < 0) {
> > -		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
> > -			devname, strerror(errno));
> > -		goto fail;
> > -	}
> > -
> >  	/* Map the PCI memory resource of device */
> >  	mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
> > -			MAP_SHARED, fd, offset);
> > -	close(fd);
> > -	if (mapaddr == MAP_FAILED ||
> > -			(requested_addr != NULL && mapaddr !=
> > requested_addr)) {
> > -		RTE_LOG(ERR, EAL, "%s(): cannot mmap(%s(%d), %p, 0x%lx,
> > 0x%lx):"
> > -			" %s (%p)\n", __func__, devname, fd,
> > requested_addr,
> > +			MAP_SHARED | additional_flags, fd, offset);
> > +	if (mapaddr == MAP_FAILED) {
> > +		RTE_LOG(ERR, EAL,
> > +			"%s(): cannot mmap(%d, %p, 0x%lx, 0x%lx): %s
> > (%p)\n",
> > +			__func__, fd, requested_addr,
> >  			(unsigned long)size, (unsigned long)offset,
> >  			strerror(errno), mapaddr);
> > -		goto fail;
> > -	}
> > -
> > -	RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
> > +	} else
> > +		RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n",
> > mapaddr);
> >
> >  	return mapaddr;
> > -
> > -fail:
> > -	return NULL;
> >  }
> >
> >  static int
> >  pci_uio_map_secondary(struct rte_pci_device *dev)  {
> > -	size_t i;
> > +	int i, fd;
> >  	struct mapped_pci_resource *uio_res;
> >  	struct mapped_pci_res_list *uio_res_list =
> >  			RTE_TAILQ_CAST(rte_uio_tailq.head,
> > mapped_pci_res_list); @@ -169,19 +153,34 @@
> > pci_uio_map_secondary(struct rte_pci_device *dev)
> >  	TAILQ_FOREACH(uio_res, uio_res_list, next) {
> >
> >  		/* skip this element if it doesn't match our PCI address */
> > -		if (memcmp(&uio_res->pci_addr, &dev->addr, sizeof(dev-
> > >addr)))
> > +		if (rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev-
> > >addr))
> >  			continue;
> >
> >  		for (i = 0; i != uio_res->nb_maps; i++) {
> > -			if (pci_map_resource(uio_res->maps[i].addr,
> > -					     uio_res->path,
> > -					     (off_t)uio_res->maps[i].offset,
> > -					     (size_t)uio_res->maps[i].size)
> > -			    != uio_res->maps[i].addr) {
> > +			/*
> > +			 * open devname, to mmap it
> > +			 */
> > +			fd = open(uio_res->maps[i].path, O_RDWR);
> > +			if (fd < 0) {
> > +				RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
> > +					uio_res->maps[i].path,
> > strerror(errno));
> > +				return -1;
> > +			}
> > +
> > +			void *mapaddr = pci_map_resource(uio_res-
> > >maps[i].addr,
> > +					fd, (off_t)uio_res->maps[i].offset,
> > +					(size_t)uio_res->maps[i].size, 0);
> > +			if (mapaddr != uio_res->maps[i].addr) {
> >  				RTE_LOG(ERR, EAL,
> > -					"Cannot mmap device resource\n");
> > +						"Cannot mmap device
> > resource "
> > +						"file %s to address: %p\n",
> > +						uio_res->maps[i].path,
> > +						uio_res->maps[i].addr);
> > +				close(fd);
> >  				return -1;
> >  			}
> > +			/* fd is not needed in slave process, close it */
> > +			close(fd);
> >  		}
> >  		return 0;
> >  	}
> > @@ -194,7 +193,7 @@ pci_uio_map_secondary(struct rte_pci_device
> *dev)
> > static int  pci_uio_map_resource(struct rte_pci_device *dev)  {
> > -	int i, j;
> > +	int i, map_idx;
> >  	char devname[PATH_MAX]; /* contains the /dev/uioX */
> >  	void *mapaddr;
> >  	uint64_t phaddr;
> > @@ -246,35 +245,60 @@ pci_uio_map_resource(struct rte_pci_device
> *dev)
> >  	pagesz = sysconf(_SC_PAGESIZE);
> >
> >  	maps = uio_res->maps;
> > -	for (i = uio_res->nb_maps = 0; i != PCI_MAX_RESOURCE; i++) {
> > +	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
> > +		int fd;
> >
> > -		j = uio_res->nb_maps;
> >  		/* skip empty BAR */
> >  		if ((phaddr = dev->mem_resource[i].phys_addr) == 0)
> >  			continue;
> >
> > +		/* allocate memory to keep path */
> > +		maps[map_idx].path = rte_malloc(NULL, strlen(devname) +
> > 1, 0);
> > +		if (maps[map_idx].path == NULL) {
> > +			RTE_LOG(ERR, EAL, "Cannot allocate memory for "
> > +					"path: %s\n", strerror(errno));
> > +			goto free_uio_res;
> > +		}
> > +
> > +		/*
> > +		 * open resource file, to mmap it
> > +		 */
> > +		fd = open(devname, O_RDWR);
> > +		if (fd < 0) {
> > +			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
> > +					devname, strerror(errno));
> > +			rte_free(maps[map_idx].path);
> > +			goto free_uio_res;
> > +		}
> > +
> >  		/* if matching map is found, then use it */
> >  		offset = i * pagesz;
> > -		maps[j].offset = offset;
> > -		maps[j].phaddr = dev->mem_resource[i].phys_addr;
> > -		maps[j].size = dev->mem_resource[i].len;
> > -		if (maps[j].addr != NULL ||
> > -		    (mapaddr = pci_map_resource(NULL, devname,
> > (off_t)offset,
> > -						(size_t)maps[j].size)
> > -		    ) == NULL) {
> > +		mapaddr = pci_map_resource(NULL, fd, (off_t)offset,
> > +					(size_t)dev->mem_resource[i].len,
> > 0);
> > +		close(fd);
> > +		if (mapaddr == MAP_FAILED) {
> > +			rte_free(maps[map_idx].path);
> >  			goto free_uio_res;
> >  		}
> >
> > -		maps[j].addr = mapaddr;
> > -		uio_res->nb_maps++;
> > +		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
> > +		maps[map_idx].size = dev->mem_resource[i].len;
> > +		maps[map_idx].addr = mapaddr;
> > +		maps[map_idx].offset = offset;
> > +		strcpy(maps[map_idx].path, devname);
> > +		map_idx++;
> >  		dev->mem_resource[i].addr = mapaddr;
> >  	}
> >
> > +	uio_res->nb_maps = map_idx;
> > +
> >  	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
> >
> >  	return 0;
> >
> >  free_uio_res:
> > +	for (i = 0; i < map_idx; i++)
> > +		rte_free(maps[i].path);
> >  	rte_free(uio_res);
> >  close_fd:
> >  	close(dev->intr_handle.fd);
> > diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> > b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> > index 2dd83d3..98f4847 100644
> > --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> > +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> > @@ -116,17 +116,11 @@ pci_uio_map_secondary(struct rte_pci_device
> > *dev)
> >  					fd, (off_t)uio_res->maps[i].offset,
> >  					(size_t)uio_res->maps[i].size, 0);
> >  			if (mapaddr != uio_res->maps[i].addr) {
> > -				if (mapaddr == MAP_FAILED)
> > -					RTE_LOG(ERR, EAL,
> > -							"Cannot mmap
> > device resource file %s: %s\n",
> > -							uio_res-
> > >maps[i].path,
> > -							strerror(errno));
> > -				else
> > -					RTE_LOG(ERR, EAL,
> > -							"Cannot mmap
> > device resource file %s to address: %p\n",
> > -							uio_res-
> > >maps[i].path,
> > -							uio_res-
> > >maps[i].addr);
> > -
> > +				RTE_LOG(ERR, EAL,
> > +						"Cannot mmap device
> > resource "
> > +						"file %s to address: %p\n",
> > +						uio_res->maps[i].path,
> > +						uio_res->maps[i].addr);
> >  				close(fd);
> >  				return -1;
> >  			}
> > @@ -353,8 +347,11 @@ pci_uio_map_resource(struct rte_pci_device
> *dev)
> >
> >  		/* allocate memory to keep path */
> >  		maps[map_idx].path = rte_malloc(NULL, strlen(devname) +
> 1, 0);
> > -		if (maps[map_idx].path == NULL)
> > +		if (maps[map_idx].path == NULL) {
> > +			RTE_LOG(ERR, EAL, "Cannot allocate memory for "
> > +					"path: %s\n", strerror(errno));
> >  			goto free_uio_res;
> > +		}
> >
> >  		/*
> >  		 * open resource file, to mmap it
> > --
> > 2.1.4
> 
> Hi Tetsuya,
> 
> This patch fails to apply to the latest code.
> 
> Applying: eal: Fix uio mapping differences between linuxapp and bsdapp
> error: patch failed: lib/librte_eal/bsdapp/eal/eal_pci.c:238
> error: lib/librte_eal/bsdapp/eal/eal_pci.c: patch does not apply
> error: patch failed: lib/librte_eal/linuxapp/eal/eal_pci_uio.c:326
> error: lib/librte_eal/linuxapp/eal/eal_pci_uio.c: patch does not apply
> 
> It looks like another rebase is needed.
> 
> Regards,
> 
> Bernard.

Hi Tetsuya,

Please ignore the previous email.
This patch applies ok to the latest code (I applied the v3 patch by mistake).

Regards,

Bernard.

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v4 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp
  2015-06-15 15:08     ` Iremonger, Bernard
@ 2015-06-15 15:17       ` Thomas Monjalon
  0 siblings, 0 replies; 120+ messages in thread
From: Thomas Monjalon @ 2015-06-15 15:17 UTC (permalink / raw)
  To: Iremonger, Bernard; +Cc: dev

Hi Bernard,

2015-06-15 15:08, Iremonger, Bernard:
[snip]

In order to avoid filling too much the patchwork page of the patch,
it's better to remove useless lines while keeping only the lines needed
to understand the history.

> > Hi Tetsuya,
> > 
> > This patch fails to apply to the latest code.
> > 
> > Applying: eal: Fix uio mapping differences between linuxapp and bsdapp
> > error: patch failed: lib/librte_eal/bsdapp/eal/eal_pci.c:238
> > error: lib/librte_eal/bsdapp/eal/eal_pci.c: patch does not apply
> > error: patch failed: lib/librte_eal/linuxapp/eal/eal_pci_uio.c:326
> > error: lib/librte_eal/linuxapp/eal/eal_pci_uio.c: patch does not apply
> > 
> > It looks like another rebase is needed.

About patch rebasing, in general, you can do it yourself by forking a
temporary branch before the conflicting commit, and rebasing it after.

> > 
> > Regards,
> > 
> > Bernard.
> 
> Hi Tetsuya,
> 
> Please ignore the previous email.
> This patch applies ok to the latest code (I applied the v3 patch by mistake).
> 
> Regards,
> 
> Bernard.

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v5 0/5] Clean up pci uio implementations
  2015-05-19  5:54 ` [dpdk-dev] [PATCH v4 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
  2015-05-19 14:51   ` Stephen Hemminger
@ 2015-06-25  3:19   ` Tetsuya Mukawa
  2015-06-25  3:19     ` [dpdk-dev] [PATCH v5 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
                       ` (4 more replies)
  1 sibling, 5 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-06-25  3:19 UTC (permalink / raw)
  To: dev

This patch set cleans up pci uio implementation. These clean up are
for consolidating pci uio implementation of linuxapp and bsdapp, and
moving consolidated functions in eal common.
Because of above, this patch set tries to implement linuxapp and bsdapp
almost same.
Actual consolidations will be done later patch set.

PATCH v5 changes:
 - Rebase to latest master branch.

PATCH v4 changes:
 - Rebase to latest master branch.
 - Fix bug in pci_uio_map_resource() of BSD code. 'maps[i].path' shouldn't be freed.
     Fixed in below patch:
     [PATCH 3/5] eal: Fix memory leaks and needless increment of pci_map_addr
 - 'path' member of 'struct mapped_pci_resource' should not be removed because it will be used in BSD code.
     Fixed in below patch:
     [PATCH 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp

PATCH v3 changes:
 - Squash patches related with pci_map_resource().
 - Free maps[].path to easy to understand.
   (Thanks to Iremonger, Bernard)
 - Close fds opened in this function.
 - Remove unused path variable from mapped_pci_resource structure.

PATCH v2 changes:
 - Move 'if-condition' to later patch series.
 - Fix memory leaks of path.
 - Fix typos.
   (Thanks to David Marchand)
 - Fix commit title and body.
 - Fix pci_map_resource() to handle MAP_FAILED.
   (Thanks to Iremonger, Bernard)

Changes:
 - This patch set is derived from below.
   "[PATCH v2] eal: Port Hotplug support for BSD"
 - Set cfg_fd as -1, when cfg_fd is closed.
   (Thanks to Iremonger, Bernard)
 - Remove needless coding style fixings.
 - Fix coding style of if-else condition.
   (Thanks to Richardson, Bruce)



Tetsuya.Mukawa (5):
  eal: Fix coding style of eal_pci.c and eal_pci_uio.c
  eal: Close file descriptor of uio configuration
  eal: Fix memory leaks and needless increment of pci_map_addr
  eal/bsdapp: Change names of pci related data structure
  eal: Fix uio mapping differences between linuxapp and bsdapp

 lib/librte_eal/bsdapp/eal/eal_pci.c       | 156 ++++++++++++++++++------------
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c |  88 ++++++++++-------
 2 files changed, 149 insertions(+), 95 deletions(-)

-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v5 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c
  2015-06-25  3:19   ` [dpdk-dev] [PATCH v5 0/5] Clean up pci uio implementations Tetsuya Mukawa
@ 2015-06-25  3:19     ` Tetsuya Mukawa
  2015-06-25  9:16       ` David Marchand
  2015-06-25  3:19     ` [dpdk-dev] [PATCH v5 2/5] eal: Close file descriptor of uio configuration Tetsuya Mukawa
                       ` (3 subsequent siblings)
  4 siblings, 1 reply; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-06-25  3:19 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

This patch fixes coding style of below files in linuxapp and bsdapp.
 - eal_pci.c
 - eal_pci_uio.c

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c       | 12 +++++++-----
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 12 ++++++++----
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 2df5c1c..8e24fd1 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -161,9 +161,10 @@ fail:
 static int
 pci_uio_map_secondary(struct rte_pci_device *dev)
 {
-        size_t i;
-        struct uio_resource *uio_res;
-	struct uio_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
+	size_t i;
+	struct uio_resource *uio_res;
+	struct uio_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
 
 	TAILQ_FOREACH(uio_res, uio_res_list, next) {
 
@@ -201,7 +202,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	uint64_t pagesz;
 	struct rte_pci_addr *loc = &dev->addr;
 	struct uio_resource *uio_res;
-	struct uio_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
+	struct uio_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
 	struct uio_map *maps;
 
 	dev->intr_handle.fd = -1;
@@ -311,7 +313,7 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
 	/* FreeBSD has no NUMA support (yet) */
 	dev->numa_node = 0;
 
-/* parse resources */
+	/* parse resources */
 	switch (conf->pc_hdr & PCIM_HDRTYPE) {
 	case PCIM_HDRTYPE_NORMAL:
 		max = PCIR_MAX_BAR_0;
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index b5116a7..5d3354d 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -92,7 +92,8 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 {
 	int fd, i;
 	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 
 	TAILQ_FOREACH(uio_res, uio_res_list, next) {
 
@@ -272,7 +273,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	uint64_t phaddr;
 	struct rte_pci_addr *loc = &dev->addr;
 	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 	struct pci_map *maps;
 
 	dev->intr_handle.fd = -1;
@@ -417,7 +419,8 @@ static struct mapped_pci_resource *
 pci_uio_find_resource(struct rte_pci_device *dev)
 {
 	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 
 	if (dev == NULL)
 		return NULL;
@@ -436,7 +439,8 @@ void
 pci_uio_unmap_resource(struct rte_pci_device *dev)
 {
 	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 
 	if (dev == NULL)
 		return;
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v5 2/5] eal: Close file descriptor of uio configuration
  2015-06-25  3:19   ` [dpdk-dev] [PATCH v5 0/5] Clean up pci uio implementations Tetsuya Mukawa
  2015-06-25  3:19     ` [dpdk-dev] [PATCH v5 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
@ 2015-06-25  3:19     ` Tetsuya Mukawa
  2015-06-25  3:19     ` [dpdk-dev] [PATCH v5 3/5] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
                       ` (2 subsequent siblings)
  4 siblings, 0 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-06-25  3:19 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

When pci_uio_unmap_resource() is called, a file descriptor that is used
for uio configuration should be closed.

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 5d3354d..34316b6 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -464,8 +464,12 @@ pci_uio_unmap_resource(struct rte_pci_device *dev)
 
 	/* close fd if in primary process */
 	close(dev->intr_handle.fd);
-
 	dev->intr_handle.fd = -1;
+
+	/* close cfg_fd if in primary process */
+	close(dev->intr_handle.uio_cfg_fd);
+	dev->intr_handle.uio_cfg_fd = -1;
+
 	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
 }
 #endif /* RTE_LIBRTE_EAL_HOTPLUG */
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v5 3/5] eal: Fix memory leaks and needless increment of pci_map_addr
  2015-06-25  3:19   ` [dpdk-dev] [PATCH v5 0/5] Clean up pci uio implementations Tetsuya Mukawa
  2015-06-25  3:19     ` [dpdk-dev] [PATCH v5 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
  2015-06-25  3:19     ` [dpdk-dev] [PATCH v5 2/5] eal: Close file descriptor of uio configuration Tetsuya Mukawa
@ 2015-06-25  3:19     ` Tetsuya Mukawa
  2015-06-25  9:16       ` David Marchand
                         ` (2 more replies)
  2015-06-25  3:19     ` [dpdk-dev] [PATCH v5 4/5] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
  2015-06-25  3:19     ` [dpdk-dev] [PATCH v5 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp Tetsuya Mukawa
  4 siblings, 3 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-06-25  3:19 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

This patch fixes following memory leaks.
- When open() is failed, uio_res and fds won't be freed in
  pci_uio_map_resource().
- When pci_map_resource() is failed but path is allocated correctly,
  path and fds won't be freed in pci_uio_map_recource().
- When pci_uio_unmap() is called, path should be freed.

Also, fixes below.
- When pci_map_resource() is failed, mapaddr will be MAP_FAILED.
  In this case, pci_map_addr should not be incremented in
  pci_uio_map_resource().
- To shrink code, move close().
- Remove fail variable.

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c       | 14 +++++++--
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 51 ++++++++++++++++++++-----------
 2 files changed, 44 insertions(+), 21 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 8e24fd1..b071f07 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -235,7 +235,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) == NULL) {
 		RTE_LOG(ERR, EAL,
 			"%s(): cannot store uio mmap details\n", __func__);
-		return -1;
+		goto close_fd;
 	}
 
 	snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
@@ -262,8 +262,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 		    (mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
 						(size_t)maps[j].size)
 		    ) == NULL) {
-			rte_free(uio_res);
-			return -1;
+			goto free_uio_res;
 		}
 
 		maps[j].addr = mapaddr;
@@ -274,6 +273,15 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
 
 	return 0;
+
+free_uio_res:
+	rte_free(uio_res);
+close_fd:
+	close(dev->intr_handle.fd);
+	dev->intr_handle.fd = -1;
+	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+
+	return -1;
 }
 
 /* Scan one pci sysfs entry, and fill the devices list from it. */
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 34316b6..2dd83d3 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -308,7 +308,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	if (dev->intr_handle.uio_cfg_fd < 0) {
 		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
 			cfgname, strerror(errno));
-		return -1;
+		goto close_fd;
 	}
 
 	if (dev->kdrv == RTE_KDRV_IGB_UIO)
@@ -328,7 +328,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	if (uio_res == NULL) {
 		RTE_LOG(ERR, EAL,
 			"%s(): cannot store uio mmap details\n", __func__);
-		return -1;
+		goto close_fd;
 	}
 
 	snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
@@ -338,7 +338,6 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	maps = uio_res->maps;
 	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
 		int fd;
-		int fail = 0;
 
 		/* skip empty BAR */
 		phaddr = dev->mem_resource[i].phys_addr;
@@ -352,6 +351,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 				loc->domain, loc->bus, loc->devid, loc->function,
 				i);
 
+		/* allocate memory to keep path */
+		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
+		if (maps[map_idx].path == NULL)
+			goto free_uio_res;
+
 		/*
 		 * open resource file, to mmap it
 		 */
@@ -359,7 +363,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 		if (fd < 0) {
 			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
 					devname, strerror(errno));
-			return -1;
+			rte_free(maps[map_idx].path);
+			goto free_uio_res;
 		}
 
 		/* try mapping somewhere close to the end of hugepages */
@@ -368,23 +373,15 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 		mapaddr = pci_map_resource(pci_map_addr, fd, 0,
 				(size_t)dev->mem_resource[i].len, 0);
-		if (mapaddr == MAP_FAILED)
-			fail = 1;
+		close(fd);
+		if (mapaddr == MAP_FAILED) {
+			rte_free(maps[map_idx].path);
+			goto free_uio_res;
+		}
 
 		pci_map_addr = RTE_PTR_ADD(mapaddr,
 				(size_t)dev->mem_resource[i].len);
 
-		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
-		if (maps[map_idx].path == NULL)
-			fail = 1;
-
-		if (fail) {
-			rte_free(uio_res);
-			close(fd);
-			return -1;
-		}
-		close(fd);
-
 		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
 		maps[map_idx].size = dev->mem_resource[i].len;
 		maps[map_idx].addr = mapaddr;
@@ -399,6 +396,22 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
 
 	return 0;
+
+free_uio_res:
+	for (i = 0; i < map_idx; i++)
+		rte_free(maps[i].path);
+	rte_free(uio_res);
+close_fd:
+	if (dev->intr_handle.uio_cfg_fd >= 0) {
+		close(dev->intr_handle.uio_cfg_fd);
+		dev->intr_handle.uio_cfg_fd = -1;
+	}
+
+	close(dev->intr_handle.fd);
+	dev->intr_handle.fd = -1;
+	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+
+	return -1;
 }
 
 #ifdef RTE_LIBRTE_EAL_HOTPLUG
@@ -410,9 +423,11 @@ pci_uio_unmap(struct mapped_pci_resource *uio_res)
 	if (uio_res == NULL)
 		return;
 
-	for (i = 0; i != uio_res->nb_maps; i++)
+	for (i = 0; i != uio_res->nb_maps; i++) {
 		pci_unmap_resource(uio_res->maps[i].addr,
 				(size_t)uio_res->maps[i].size);
+		rte_free(uio_res->maps[i].path);
+	}
 }
 
 static struct mapped_pci_resource *
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v5 4/5] eal/bsdapp: Change names of pci related data structure
  2015-06-25  3:19   ` [dpdk-dev] [PATCH v5 0/5] Clean up pci uio implementations Tetsuya Mukawa
                       ` (2 preceding siblings ...)
  2015-06-25  3:19     ` [dpdk-dev] [PATCH v5 3/5] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
@ 2015-06-25  3:19     ` Tetsuya Mukawa
  2015-06-25  9:19       ` David Marchand
  2015-06-25  3:19     ` [dpdk-dev] [PATCH v5 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp Tetsuya Mukawa
  4 siblings, 1 reply; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-06-25  3:19 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

To merge pci code of linuxapp and bsdapp, this patch changes names
like below.
 - uio_map to pci_map
 - uio_resource to mapped_pci_resource
 - uio_res_list to mapped_pci_res_list

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index b071f07..8261e09 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -83,7 +83,7 @@
  * enabling bus master.
  */
 
-struct uio_map {
+struct pci_map {
 	void *addr;
 	uint64_t offset;
 	uint64_t size;
@@ -94,16 +94,16 @@ struct uio_map {
  * For multi-process we need to reproduce all PCI mappings in secondary
  * processes, so save them in a tailq.
  */
-struct uio_resource {
-	TAILQ_ENTRY(uio_resource) next;
+struct mapped_pci_resource {
+	TAILQ_ENTRY(mapped_pci_resource) next;
 
 	struct rte_pci_addr pci_addr;
 	char path[PATH_MAX];
 	size_t nb_maps;
-	struct uio_map maps[PCI_MAX_RESOURCE];
+	struct pci_map maps[PCI_MAX_RESOURCE];
 };
 
-TAILQ_HEAD(uio_res_list, uio_resource);
+TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource);
 
 static struct rte_tailq_elem rte_uio_tailq = {
 	.name = "UIO_RESOURCE_LIST",
@@ -162,9 +162,9 @@ static int
 pci_uio_map_secondary(struct rte_pci_device *dev)
 {
 	size_t i;
-	struct uio_resource *uio_res;
-	struct uio_res_list *uio_res_list =
-			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
+	struct mapped_pci_resource *uio_res;
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 
 	TAILQ_FOREACH(uio_res, uio_res_list, next) {
 
@@ -201,10 +201,10 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	uint64_t offset;
 	uint64_t pagesz;
 	struct rte_pci_addr *loc = &dev->addr;
-	struct uio_resource *uio_res;
-	struct uio_res_list *uio_res_list =
-			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
-	struct uio_map *maps;
+	struct mapped_pci_resource *uio_res;
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct pci_map *maps;
 
 	dev->intr_handle.fd = -1;
 	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v5 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp
  2015-06-25  3:19   ` [dpdk-dev] [PATCH v5 0/5] Clean up pci uio implementations Tetsuya Mukawa
                       ` (3 preceding siblings ...)
  2015-06-25  3:19     ` [dpdk-dev] [PATCH v5 4/5] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
@ 2015-06-25  3:19     ` Tetsuya Mukawa
  4 siblings, 0 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-06-25  3:19 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

This patch fixes below.
- bsdapp
 - Use map_id in pci_uio_map_resource().
 - Fix interface of pci_map_resource().
 - Move path variable of mapped_pci_resource structure to pci_map.
- linuxapp
 - Remove redundant error message of linuxapp.

'pci_uio_map_resource()' is implemented in both linuxapp and bsdapp,
but interface is different. The patch fixes the function of bsdapp
to do same as linuxapp. After applying it, file descriptor should be
opened and closed out of pci_map_resource().

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c       | 118 ++++++++++++++++++------------
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c |  21 +++---
 2 files changed, 80 insertions(+), 59 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 8261e09..06c564f 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -85,6 +85,7 @@
 
 struct pci_map {
 	void *addr;
+	char *path;
 	uint64_t offset;
 	uint64_t size;
 	uint64_t phaddr;
@@ -99,7 +100,7 @@ struct mapped_pci_resource {
 
 	struct rte_pci_addr pci_addr;
 	char path[PATH_MAX];
-	size_t nb_maps;
+	int nb_maps;
 	struct pci_map maps[PCI_MAX_RESOURCE];
 };
 
@@ -121,47 +122,30 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)
 
 /* map a particular resource from a file */
 static void *
-pci_map_resource(void *requested_addr, const char *devname, off_t offset,
-		 size_t size)
+pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
+		 int additional_flags)
 {
-	int fd;
 	void *mapaddr;
 
-	/*
-	 * open devname, to mmap it
-	 */
-	fd = open(devname, O_RDWR);
-	if (fd < 0) {
-		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
-			devname, strerror(errno));
-		goto fail;
-	}
-
 	/* Map the PCI memory resource of device */
 	mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
-			MAP_SHARED, fd, offset);
-	close(fd);
-	if (mapaddr == MAP_FAILED ||
-			(requested_addr != NULL && mapaddr != requested_addr)) {
-		RTE_LOG(ERR, EAL, "%s(): cannot mmap(%s(%d), %p, 0x%lx, 0x%lx):"
-			" %s (%p)\n", __func__, devname, fd, requested_addr,
+			MAP_SHARED | additional_flags, fd, offset);
+	if (mapaddr == MAP_FAILED) {
+		RTE_LOG(ERR, EAL,
+			"%s(): cannot mmap(%d, %p, 0x%lx, 0x%lx): %s (%p)\n",
+			__func__, fd, requested_addr,
 			(unsigned long)size, (unsigned long)offset,
 			strerror(errno), mapaddr);
-		goto fail;
-	}
-
-	RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
+	} else
+		RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
 
 	return mapaddr;
-
-fail:
-	return NULL;
 }
 
 static int
 pci_uio_map_secondary(struct rte_pci_device *dev)
 {
-	size_t i;
+	int i, fd;
 	struct mapped_pci_resource *uio_res;
 	struct mapped_pci_res_list *uio_res_list =
 			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
@@ -169,19 +153,34 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 	TAILQ_FOREACH(uio_res, uio_res_list, next) {
 
 		/* skip this element if it doesn't match our PCI address */
-		if (memcmp(&uio_res->pci_addr, &dev->addr, sizeof(dev->addr)))
+		if (rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr))
 			continue;
 
 		for (i = 0; i != uio_res->nb_maps; i++) {
-			if (pci_map_resource(uio_res->maps[i].addr,
-					     uio_res->path,
-					     (off_t)uio_res->maps[i].offset,
-					     (size_t)uio_res->maps[i].size)
-			    != uio_res->maps[i].addr) {
+			/*
+			 * open devname, to mmap it
+			 */
+			fd = open(uio_res->maps[i].path, O_RDWR);
+			if (fd < 0) {
+				RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
+					uio_res->maps[i].path, strerror(errno));
+				return -1;
+			}
+
+			void *mapaddr = pci_map_resource(uio_res->maps[i].addr,
+					fd, (off_t)uio_res->maps[i].offset,
+					(size_t)uio_res->maps[i].size, 0);
+			if (mapaddr != uio_res->maps[i].addr) {
 				RTE_LOG(ERR, EAL,
-					"Cannot mmap device resource\n");
+						"Cannot mmap device resource "
+						"file %s to address: %p\n",
+						uio_res->maps[i].path,
+						uio_res->maps[i].addr);
+				close(fd);
 				return -1;
 			}
+			/* fd is not needed in slave process, close it */
+			close(fd);
 		}
 		return 0;
 	}
@@ -194,7 +193,7 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 static int
 pci_uio_map_resource(struct rte_pci_device *dev)
 {
-	int i, j;
+	int i, map_idx;
 	char devname[PATH_MAX]; /* contains the /dev/uioX */
 	void *mapaddr;
 	uint64_t phaddr;
@@ -246,35 +245,60 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	pagesz = sysconf(_SC_PAGESIZE);
 
 	maps = uio_res->maps;
-	for (i = uio_res->nb_maps = 0; i != PCI_MAX_RESOURCE; i++) {
+	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
+		int fd;
 
-		j = uio_res->nb_maps;
 		/* skip empty BAR */
 		if ((phaddr = dev->mem_resource[i].phys_addr) == 0)
 			continue;
 
+		/* allocate memory to keep path */
+		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
+		if (maps[map_idx].path == NULL) {
+			RTE_LOG(ERR, EAL, "Cannot allocate memory for "
+					"path: %s\n", strerror(errno));
+			goto free_uio_res;
+		}
+
+		/*
+		 * open resource file, to mmap it
+		 */
+		fd = open(devname, O_RDWR);
+		if (fd < 0) {
+			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
+					devname, strerror(errno));
+			rte_free(maps[map_idx].path);
+			goto free_uio_res;
+		}
+
 		/* if matching map is found, then use it */
 		offset = i * pagesz;
-		maps[j].offset = offset;
-		maps[j].phaddr = dev->mem_resource[i].phys_addr;
-		maps[j].size = dev->mem_resource[i].len;
-		if (maps[j].addr != NULL ||
-		    (mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
-						(size_t)maps[j].size)
-		    ) == NULL) {
+		mapaddr = pci_map_resource(NULL, fd, (off_t)offset,
+					(size_t)dev->mem_resource[i].len, 0);
+		close(fd);
+		if (mapaddr == MAP_FAILED) {
+			rte_free(maps[map_idx].path);
 			goto free_uio_res;
 		}
 
-		maps[j].addr = mapaddr;
-		uio_res->nb_maps++;
+		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
+		maps[map_idx].size = dev->mem_resource[i].len;
+		maps[map_idx].addr = mapaddr;
+		maps[map_idx].offset = offset;
+		strcpy(maps[map_idx].path, devname);
+		map_idx++;
 		dev->mem_resource[i].addr = mapaddr;
 	}
 
+	uio_res->nb_maps = map_idx;
+
 	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
 
 	return 0;
 
 free_uio_res:
+	for (i = 0; i < map_idx; i++)
+		rte_free(maps[i].path);
 	rte_free(uio_res);
 close_fd:
 	close(dev->intr_handle.fd);
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 2dd83d3..98f4847 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -116,17 +116,11 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 					fd, (off_t)uio_res->maps[i].offset,
 					(size_t)uio_res->maps[i].size, 0);
 			if (mapaddr != uio_res->maps[i].addr) {
-				if (mapaddr == MAP_FAILED)
-					RTE_LOG(ERR, EAL,
-							"Cannot mmap device resource file %s: %s\n",
-							uio_res->maps[i].path,
-							strerror(errno));
-				else
-					RTE_LOG(ERR, EAL,
-							"Cannot mmap device resource file %s to address: %p\n",
-							uio_res->maps[i].path,
-							uio_res->maps[i].addr);
-
+				RTE_LOG(ERR, EAL,
+						"Cannot mmap device resource "
+						"file %s to address: %p\n",
+						uio_res->maps[i].path,
+						uio_res->maps[i].addr);
 				close(fd);
 				return -1;
 			}
@@ -353,8 +347,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 		/* allocate memory to keep path */
 		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
-		if (maps[map_idx].path == NULL)
+		if (maps[map_idx].path == NULL) {
+			RTE_LOG(ERR, EAL, "Cannot allocate memory for "
+					"path: %s\n", strerror(errno));
 			goto free_uio_res;
+		}
 
 		/*
 		 * open resource file, to mmap it
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v5 3/5] eal: Fix memory leaks and needless increment of pci_map_addr
  2015-06-25  3:19     ` [dpdk-dev] [PATCH v5 3/5] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
@ 2015-06-25  9:16       ` David Marchand
  2015-06-26  1:30         ` Tetsuya Mukawa
  2015-06-25  9:18       ` David Marchand
  2015-06-26  8:18       ` [dpdk-dev] [PATCH v6 0/5] Clean up pci uio implementations Tetsuya Mukawa
  2 siblings, 1 reply; 120+ messages in thread
From: David Marchand @ 2015-06-25  9:16 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

Hello Tetsuya,


On Thu, Jun 25, 2015 at 5:19 AM, Tetsuya Mukawa <mukawa@igel.co.jp> wrote:

> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
>
> This patch fixes following memory leaks.
> - When open() is failed, uio_res and fds won't be freed in
>   pci_uio_map_resource().
> - When pci_map_resource() is failed but path is allocated correctly,
>   path and fds won't be freed in pci_uio_map_recource().
> - When pci_uio_unmap() is called, path should be freed.
>
> Also, fixes below.
> - When pci_map_resource() is failed, mapaddr will be MAP_FAILED.
>   In this case, pci_map_addr should not be incremented in
>   pci_uio_map_resource().
> - To shrink code, move close().
> - Remove fail variable.
>
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  lib/librte_eal/bsdapp/eal/eal_pci.c       | 14 +++++++--
>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 51
> ++++++++++++++++++++-----------
>  2 files changed, 44 insertions(+), 21 deletions(-)
>
> [snip]
> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> index 34316b6..2dd83d3 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> @@ -308,7 +308,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>         if (dev->intr_handle.uio_cfg_fd < 0) {
>                 RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
>                         cfgname, strerror(errno));
> -               return -1;
> +               goto close_fd;
>         }
>
>         if (dev->kdrv == RTE_KDRV_IGB_UIO)
>


You missed a return here :

        if (dev->kdrv == RTE_KDRV_IGB_UIO)

                dev->intr_handle.type = RTE_INTR_HANDLE_UIO;

        else {

                dev->intr_handle.type = RTE_INTR_HANDLE_UIO_INTX;



                /* set bus master that is not done by uio_pci_generic */

                if (pci_uio_set_bus_master(dev->intr_handle.uio_cfg_fd)) {

                        RTE_LOG(ERR, EAL, "Cannot set up bus
mastering!\n");
                        return -1;

                }

        }




@@ -328,7 +328,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>         if (uio_res == NULL) {
>                 RTE_LOG(ERR, EAL,
>                         "%s(): cannot store uio mmap details\n", __func__);
> -               return -1;
> +               goto close_fd;
>         }
>
>         snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
> @@ -338,7 +338,6 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>         maps = uio_res->maps;
>         for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
>                 int fd;
> -               int fail = 0;
>
>                 /* skip empty BAR */
>                 phaddr = dev->mem_resource[i].phys_addr;
>


The rest looks good to me.


-- 
David Marchand

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v5 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c
  2015-06-25  3:19     ` [dpdk-dev] [PATCH v5 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
@ 2015-06-25  9:16       ` David Marchand
  0 siblings, 0 replies; 120+ messages in thread
From: David Marchand @ 2015-06-25  9:16 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Thu, Jun 25, 2015 at 5:19 AM, Tetsuya Mukawa <mukawa@igel.co.jp> wrote:

> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
>
> This patch fixes coding style of below files in linuxapp and bsdapp.
>  - eal_pci.c
>  - eal_pci_uio.c
>
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> Acked-by: Stephen Hemminger <stephen@networkplumber.org>
>

Acked-by: David Marchand <david.marchand@6wind.com>


-- 
David Marchand

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v5 3/5] eal: Fix memory leaks and needless increment of pci_map_addr
  2015-06-25  3:19     ` [dpdk-dev] [PATCH v5 3/5] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
  2015-06-25  9:16       ` David Marchand
@ 2015-06-25  9:18       ` David Marchand
  2015-06-26  1:35         ` Tetsuya Mukawa
  2015-06-26  8:18       ` [dpdk-dev] [PATCH v6 0/5] Clean up pci uio implementations Tetsuya Mukawa
  2 siblings, 1 reply; 120+ messages in thread
From: David Marchand @ 2015-06-25  9:18 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Thu, Jun 25, 2015 at 5:19 AM, Tetsuya Mukawa <mukawa@igel.co.jp> wrote:

> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
>
> This patch fixes following memory leaks.
> - When open() is failed, uio_res and fds won't be freed in
>   pci_uio_map_resource().
> - When pci_map_resource() is failed but path is allocated correctly,
>   path and fds won't be freed in pci_uio_map_recource().
> - When pci_uio_unmap() is called, path should be freed.
>
> Also, fixes below.
> - When pci_map_resource() is failed, mapaddr will be MAP_FAILED.
>   In this case, pci_map_addr should not be incremented in
>   pci_uio_map_resource().
> - To shrink code, move close().
> - Remove fail variable.
>
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  lib/librte_eal/bsdapp/eal/eal_pci.c       | 14 +++++++--
>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 51
> ++++++++++++++++++++-----------
>  2 files changed, 44 insertions(+), 21 deletions(-)
>
> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c
> b/lib/librte_eal/bsdapp/eal/eal_pci.c
> index 8e24fd1..b071f07 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> @@ -235,7 +235,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>         if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) ==
> NULL) {
>                 RTE_LOG(ERR, EAL,
>                         "%s(): cannot store uio mmap details\n", __func__);
> -               return -1;
> +               goto close_fd;
>         }
>
>         snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
> @@ -262,8 +262,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>                     (mapaddr = pci_map_resource(NULL, devname,
> (off_t)offset,
>                                                 (size_t)maps[j].size)
>                     ) == NULL) {
> -                       rte_free(uio_res);
> -                       return -1;
> +                       goto free_uio_res;
>                 }
>
>                 maps[j].addr = mapaddr;
> @@ -274,6 +273,15 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>         TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
>
>         return 0;
> +
> +free_uio_res:
> +       rte_free(uio_res);
> +close_fd:
> +       close(dev->intr_handle.fd);
> +       dev->intr_handle.fd = -1;
> +       dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
> +
> +       return -1;
>  }
>
>
Thinking about it, when something fails, don't you need to unmap pci
resources in uio_res->maps before freeing ?


-- 
David Marchand

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v5 4/5] eal/bsdapp: Change names of pci related data structure
  2015-06-25  3:19     ` [dpdk-dev] [PATCH v5 4/5] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
@ 2015-06-25  9:19       ` David Marchand
  0 siblings, 0 replies; 120+ messages in thread
From: David Marchand @ 2015-06-25  9:19 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Thu, Jun 25, 2015 at 5:19 AM, Tetsuya Mukawa <mukawa@igel.co.jp> wrote:

> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
>
> To merge pci code of linuxapp and bsdapp, this patch changes names
> like below.
>  - uio_map to pci_map
>  - uio_resource to mapped_pci_resource
>  - uio_res_list to mapped_pci_res_list
>
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
>


Acked-by: David Marchand <david.marchand@6wind.com>


-- 
David Marchand

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v5 3/5] eal: Fix memory leaks and needless increment of pci_map_addr
  2015-06-25  9:16       ` David Marchand
@ 2015-06-26  1:30         ` Tetsuya Mukawa
  0 siblings, 0 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-06-26  1:30 UTC (permalink / raw)
  To: David Marchand; +Cc: dev

On 2015/06/25 18:16, David Marchand wrote:
> Hello Tetsuya, 
>
>
> On Thu, Jun 25, 2015 at 5:19 AM, Tetsuya Mukawa <mukawa@igel.co.jp
> <mailto:mukawa@igel.co.jp>> wrote:
>
>     From: "Tetsuya.Mukawa" <mukawa@igel.co.jp <mailto:mukawa@igel.co.jp>>
>
>     This patch fixes following memory leaks.
>     - When open() is failed, uio_res and fds won't be freed in
>       pci_uio_map_resource().
>     - When pci_map_resource() is failed but path is allocated correctly,
>       path and fds won't be freed in pci_uio_map_recource().
>     - When pci_uio_unmap() is called, path should be freed.
>
>     Also, fixes below.
>     - When pci_map_resource() is failed, mapaddr will be MAP_FAILED.
>       In this case, pci_map_addr should not be incremented in
>       pci_uio_map_resource().
>     - To shrink code, move close().
>     - Remove fail variable.
>
>     Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp
>     <mailto:mukawa@igel.co.jp>>
>     ---
>      lib/librte_eal/bsdapp/eal/eal_pci.c       | 14 +++++++--
>      lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 51
>     ++++++++++++++++++++-----------
>      2 files changed, 44 insertions(+), 21 deletions(-)
>
>     [snip]
>     diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>     b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>     index 34316b6..2dd83d3 100644
>     --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>     +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>     @@ -308,7 +308,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>             if (dev->intr_handle.uio_cfg_fd < 0) {
>                     RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
>                             cfgname, strerror(errno));
>     -               return -1;
>     +               goto close_fd;
>             }
>
>             if (dev->kdrv == RTE_KDRV_IGB_UIO)
>
>
>
> You missed a return here :

Hi David,

Thanks for reviewing
It seems I needed to fix it while rebasing.

Regards,
Tetsuya

>
>         if (dev->kdrv == RTE_KDRV_IGB_UIO)                            
>           
>                 dev->intr_handle.type = RTE_INTR_HANDLE_UIO;          
>           
>         else {                                                        
>           
>                 dev->intr_handle.type = RTE_INTR_HANDLE_UIO_INTX;    
>            
>                                                                      
>            
>                 /* set bus master that is not done by uio_pci_generic
> */         
>                 if
> (pci_uio_set_bus_master(dev->intr_handle.uio_cfg_fd)) {       
>                         RTE_LOG(ERR, EAL, "Cannot set up bus
> mastering!\n");     
>                         return -1;                                    
>           
>                 }                                                    
>            
>         }                                                            
>            
>
>
>
>     @@ -328,7 +328,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>             if (uio_res == NULL) {
>                     RTE_LOG(ERR, EAL,
>                             "%s(): cannot store uio mmap details\n",
>     __func__);
>     -               return -1;
>     +               goto close_fd;
>             }
>
>             snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
>     @@ -338,7 +338,6 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>             maps = uio_res->maps;
>             for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
>                     int fd;
>     -               int fail = 0;
>
>                     /* skip empty BAR */
>                     phaddr = dev->mem_resource[i].phys_addr;
>
>
>
> The rest looks good to me.
>
>
> -- 
> David Marchand 

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v5 3/5] eal: Fix memory leaks and needless increment of pci_map_addr
  2015-06-25  9:18       ` David Marchand
@ 2015-06-26  1:35         ` Tetsuya Mukawa
  0 siblings, 0 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-06-26  1:35 UTC (permalink / raw)
  To: David Marchand; +Cc: dev

On 2015/06/25 18:18, David Marchand wrote:
> On Thu, Jun 25, 2015 at 5:19 AM, Tetsuya Mukawa <mukawa@igel.co.jp
> <mailto:mukawa@igel.co.jp>> wrote:
>
>     From: "Tetsuya.Mukawa" <mukawa@igel.co.jp <mailto:mukawa@igel.co.jp>>
>
>     This patch fixes following memory leaks.
>     - When open() is failed, uio_res and fds won't be freed in
>       pci_uio_map_resource().
>     - When pci_map_resource() is failed but path is allocated correctly,
>       path and fds won't be freed in pci_uio_map_recource().
>     - When pci_uio_unmap() is called, path should be freed.
>
>     Also, fixes below.
>     - When pci_map_resource() is failed, mapaddr will be MAP_FAILED.
>       In this case, pci_map_addr should not be incremented in
>       pci_uio_map_resource().
>     - To shrink code, move close().
>     - Remove fail variable.
>
>     Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp
>     <mailto:mukawa@igel.co.jp>>
>     ---
>      lib/librte_eal/bsdapp/eal/eal_pci.c       | 14 +++++++--
>      lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 51
>     ++++++++++++++++++++-----------
>      2 files changed, 44 insertions(+), 21 deletions(-)
>
>     diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c
>     b/lib/librte_eal/bsdapp/eal/eal_pci.c
>     index 8e24fd1..b071f07 100644
>     --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
>     +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
>     @@ -235,7 +235,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>             if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res),
>     0)) == NULL) {
>                     RTE_LOG(ERR, EAL,
>                             "%s(): cannot store uio mmap details\n",
>     __func__);
>     -               return -1;
>     +               goto close_fd;
>             }
>
>             snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
>     @@ -262,8 +262,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>                         (mapaddr = pci_map_resource(NULL, devname,
>     (off_t)offset,
>                                                     (size_t)maps[j].size)
>                         ) == NULL) {
>     -                       rte_free(uio_res);
>     -                       return -1;
>     +                       goto free_uio_res;
>                     }
>
>                     maps[j].addr = mapaddr;
>     @@ -274,6 +273,15 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>             TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
>
>             return 0;
>     +
>     +free_uio_res:
>     +       rte_free(uio_res);
>     +close_fd:
>     +       close(dev->intr_handle.fd);
>     +       dev->intr_handle.fd = -1;
>     +       dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
>     +
>     +       return -1;
>      }
>
>
> Thinking about it, when something fails, don't you need to unmap pci
> resources in uio_res->maps before freeing ?

Yes, you are right. I will add it to linux code.
So far BSD doesn't have unmap function. It will be added through other
patch series I've already submitted.

Regards,
Tetsuya

>
>
> -- 
> David Marchand

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v6 0/5] Clean up pci uio implementations
  2015-06-25  3:19     ` [dpdk-dev] [PATCH v5 3/5] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
  2015-06-25  9:16       ` David Marchand
  2015-06-25  9:18       ` David Marchand
@ 2015-06-26  8:18       ` Tetsuya Mukawa
  2015-06-26  8:18         ` [dpdk-dev] [PATCH v6 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
                           ` (4 more replies)
  2 siblings, 5 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-06-26  8:18 UTC (permalink / raw)
  To: dev

This patch set cleans up pci uio implementation. These clean up are
for consolidating pci uio implementation of linuxapp and bsdapp, and
moving consolidated functions in eal common.
Because of above, this patch set tries to implement linuxapp and bsdapp
almost same.
Actual consolidations will be done later patch set.

PATCH v6 changes:
 - Free mapped resources in pci_uio_map_resource().
 - Fix error handling in pci_uio_map_resource().
   (Thanks to David, Marchand)

PATCH v5 changes:
 - Rebase to latest master branch.

PATCH v4 changes:
 - Rebase to latest master branch.
 - Fix bug in pci_uio_map_resource() of BSD code. 'maps[i].path' shouldn't be freed.
     Fixed in below patch:
     [PATCH 3/5] eal: Fix memory leaks and needless increment of pci_map_addr
 - 'path' member of 'struct mapped_pci_resource' should not be removed because it will be used in BSD code.
     Fixed in below patch:
     [PATCH 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp

PATCH v3 changes:
 - Squash patches related with pci_map_resource().
 - Free maps[].path to easy to understand.
   (Thanks to Iremonger, Bernard)
 - Close fds opened in this function.
 - Remove unused path variable from mapped_pci_resource structure.

PATCH v2 changes:
 - Move 'if-condition' to later patch series.
 - Fix memory leaks of path.
 - Fix typos.
   (Thanks to David Marchand)
 - Fix commit title and body.
 - Fix pci_map_resource() to handle MAP_FAILED.
   (Thanks to Iremonger, Bernard)

Changes:
 - This patch set is derived from below.
   "[PATCH v2] eal: Port Hotplug support for BSD"
 - Set cfg_fd as -1, when cfg_fd is closed.
   (Thanks to Iremonger, Bernard)
 - Remove needless coding style fixings.
 - Fix coding style of if-else condition.
   (Thanks to Richardson, Bruce)



Tetsuya.Mukawa (5):
  eal: Fix coding style of eal_pci.c and eal_pci_uio.c
  eal: Close file descriptor of uio configuration
  eal: Fix memory leaks and needless increment of pci_map_addr
  eal/bsdapp: Change names of pci related data structure
  eal: Fix uio mapping differences between linuxapp and bsdapp

 lib/librte_eal/bsdapp/eal/eal_pci.c       | 156 ++++++++++++++++++------------
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c |  93 +++++++++++-------
 2 files changed, 153 insertions(+), 96 deletions(-)

-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v6 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c
  2015-06-26  8:18       ` [dpdk-dev] [PATCH v6 0/5] Clean up pci uio implementations Tetsuya Mukawa
@ 2015-06-26  8:18         ` Tetsuya Mukawa
  2015-06-26 14:30           ` Iremonger, Bernard
  2015-06-26  8:18         ` [dpdk-dev] [PATCH v6 2/5] eal: Close file descriptor of uio configuration Tetsuya Mukawa
                           ` (3 subsequent siblings)
  4 siblings, 1 reply; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-06-26  8:18 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

This patch fixes coding style of below files in linuxapp and bsdapp.
 - eal_pci.c
 - eal_pci_uio.c

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c       | 12 +++++++-----
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 12 ++++++++----
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 2df5c1c..8e24fd1 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -161,9 +161,10 @@ fail:
 static int
 pci_uio_map_secondary(struct rte_pci_device *dev)
 {
-        size_t i;
-        struct uio_resource *uio_res;
-	struct uio_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
+	size_t i;
+	struct uio_resource *uio_res;
+	struct uio_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
 
 	TAILQ_FOREACH(uio_res, uio_res_list, next) {
 
@@ -201,7 +202,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	uint64_t pagesz;
 	struct rte_pci_addr *loc = &dev->addr;
 	struct uio_resource *uio_res;
-	struct uio_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
+	struct uio_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
 	struct uio_map *maps;
 
 	dev->intr_handle.fd = -1;
@@ -311,7 +313,7 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
 	/* FreeBSD has no NUMA support (yet) */
 	dev->numa_node = 0;
 
-/* parse resources */
+	/* parse resources */
 	switch (conf->pc_hdr & PCIM_HDRTYPE) {
 	case PCIM_HDRTYPE_NORMAL:
 		max = PCIR_MAX_BAR_0;
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index b5116a7..5d3354d 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -92,7 +92,8 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 {
 	int fd, i;
 	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 
 	TAILQ_FOREACH(uio_res, uio_res_list, next) {
 
@@ -272,7 +273,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	uint64_t phaddr;
 	struct rte_pci_addr *loc = &dev->addr;
 	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 	struct pci_map *maps;
 
 	dev->intr_handle.fd = -1;
@@ -417,7 +419,8 @@ static struct mapped_pci_resource *
 pci_uio_find_resource(struct rte_pci_device *dev)
 {
 	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 
 	if (dev == NULL)
 		return NULL;
@@ -436,7 +439,8 @@ void
 pci_uio_unmap_resource(struct rte_pci_device *dev)
 {
 	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 
 	if (dev == NULL)
 		return;
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v6 2/5] eal: Close file descriptor of uio configuration
  2015-06-26  8:18       ` [dpdk-dev] [PATCH v6 0/5] Clean up pci uio implementations Tetsuya Mukawa
  2015-06-26  8:18         ` [dpdk-dev] [PATCH v6 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
@ 2015-06-26  8:18         ` Tetsuya Mukawa
  2015-06-26 14:32           ` Iremonger, Bernard
  2015-06-26  8:18         ` [dpdk-dev] [PATCH v6 3/5] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
                           ` (2 subsequent siblings)
  4 siblings, 1 reply; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-06-26  8:18 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

When pci_uio_unmap_resource() is called, a file descriptor that is used
for uio configuration should be closed.

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 5d3354d..34316b6 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -464,8 +464,12 @@ pci_uio_unmap_resource(struct rte_pci_device *dev)
 
 	/* close fd if in primary process */
 	close(dev->intr_handle.fd);
-
 	dev->intr_handle.fd = -1;
+
+	/* close cfg_fd if in primary process */
+	close(dev->intr_handle.uio_cfg_fd);
+	dev->intr_handle.uio_cfg_fd = -1;
+
 	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
 }
 #endif /* RTE_LIBRTE_EAL_HOTPLUG */
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v6 3/5] eal: Fix memory leaks and needless increment of pci_map_addr
  2015-06-26  8:18       ` [dpdk-dev] [PATCH v6 0/5] Clean up pci uio implementations Tetsuya Mukawa
  2015-06-26  8:18         ` [dpdk-dev] [PATCH v6 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
  2015-06-26  8:18         ` [dpdk-dev] [PATCH v6 2/5] eal: Close file descriptor of uio configuration Tetsuya Mukawa
@ 2015-06-26  8:18         ` Tetsuya Mukawa
  2015-06-26 14:34           ` Iremonger, Bernard
  2015-06-30  8:24           ` [dpdk-dev] [PATCH v7 00/12] Clean up pci uio implementations Tetsuya Mukawa
  2015-06-26  8:18         ` [dpdk-dev] [PATCH v6 4/5] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
  2015-06-26  8:18         ` [dpdk-dev] [PATCH v6 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp Tetsuya Mukawa
  4 siblings, 2 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-06-26  8:18 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

This patch fixes following memory leaks.
- When open() is failed, uio_res and fds won't be freed in
  pci_uio_map_resource().
- When pci_map_resource() is failed but path is allocated correctly,
  path and fds won't be freed in pci_uio_map_recource().
  Also, some mapped resources should be freed.
- When pci_uio_unmap() is called, path should be freed.

Also, fixes below.
- When pci_map_resource() is failed, mapaddr will be MAP_FAILED.
  In this case, pci_map_addr should not be incremented in
  pci_uio_map_resource().
- To shrink code, move close().
- Remove fail variable.

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c       | 14 ++++++--
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 56 ++++++++++++++++++++-----------
 2 files changed, 48 insertions(+), 22 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 8e24fd1..b071f07 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -235,7 +235,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) == NULL) {
 		RTE_LOG(ERR, EAL,
 			"%s(): cannot store uio mmap details\n", __func__);
-		return -1;
+		goto close_fd;
 	}
 
 	snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
@@ -262,8 +262,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 		    (mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
 						(size_t)maps[j].size)
 		    ) == NULL) {
-			rte_free(uio_res);
-			return -1;
+			goto free_uio_res;
 		}
 
 		maps[j].addr = mapaddr;
@@ -274,6 +273,15 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
 
 	return 0;
+
+free_uio_res:
+	rte_free(uio_res);
+close_fd:
+	close(dev->intr_handle.fd);
+	dev->intr_handle.fd = -1;
+	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+
+	return -1;
 }
 
 /* Scan one pci sysfs entry, and fill the devices list from it. */
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 34316b6..c3b259b 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -308,7 +308,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	if (dev->intr_handle.uio_cfg_fd < 0) {
 		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
 			cfgname, strerror(errno));
-		return -1;
+		goto close_fd;
 	}
 
 	if (dev->kdrv == RTE_KDRV_IGB_UIO)
@@ -319,7 +319,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 		/* set bus master that is not done by uio_pci_generic */
 		if (pci_uio_set_bus_master(dev->intr_handle.uio_cfg_fd)) {
 			RTE_LOG(ERR, EAL, "Cannot set up bus mastering!\n");
-			return -1;
+			goto close_fd;
 		}
 	}
 
@@ -328,7 +328,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	if (uio_res == NULL) {
 		RTE_LOG(ERR, EAL,
 			"%s(): cannot store uio mmap details\n", __func__);
-		return -1;
+		goto close_fd;
 	}
 
 	snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
@@ -338,7 +338,6 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	maps = uio_res->maps;
 	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
 		int fd;
-		int fail = 0;
 
 		/* skip empty BAR */
 		phaddr = dev->mem_resource[i].phys_addr;
@@ -352,6 +351,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 				loc->domain, loc->bus, loc->devid, loc->function,
 				i);
 
+		/* allocate memory to keep path */
+		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
+		if (maps[map_idx].path == NULL)
+			goto free_uio_res;
+
 		/*
 		 * open resource file, to mmap it
 		 */
@@ -359,7 +363,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 		if (fd < 0) {
 			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
 					devname, strerror(errno));
-			return -1;
+			rte_free(maps[map_idx].path);
+			goto free_uio_res;
 		}
 
 		/* try mapping somewhere close to the end of hugepages */
@@ -368,23 +373,15 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 		mapaddr = pci_map_resource(pci_map_addr, fd, 0,
 				(size_t)dev->mem_resource[i].len, 0);
-		if (mapaddr == MAP_FAILED)
-			fail = 1;
+		close(fd);
+		if (mapaddr == MAP_FAILED) {
+			rte_free(maps[map_idx].path);
+			goto free_uio_res;
+		}
 
 		pci_map_addr = RTE_PTR_ADD(mapaddr,
 				(size_t)dev->mem_resource[i].len);
 
-		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
-		if (maps[map_idx].path == NULL)
-			fail = 1;
-
-		if (fail) {
-			rte_free(uio_res);
-			close(fd);
-			return -1;
-		}
-		close(fd);
-
 		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
 		maps[map_idx].size = dev->mem_resource[i].len;
 		maps[map_idx].addr = mapaddr;
@@ -399,6 +396,25 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
 
 	return 0;
+
+free_uio_res:
+	for (i = 0; i < map_idx; i++) {
+		pci_unmap_resource(uio_res->maps[i].addr,
+				(size_t)uio_res->maps[i].size);
+		rte_free(maps[i].path);
+	}
+	rte_free(uio_res);
+close_fd:
+	if (dev->intr_handle.uio_cfg_fd >= 0) {
+		close(dev->intr_handle.uio_cfg_fd);
+		dev->intr_handle.uio_cfg_fd = -1;
+	}
+
+	close(dev->intr_handle.fd);
+	dev->intr_handle.fd = -1;
+	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+
+	return -1;
 }
 
 #ifdef RTE_LIBRTE_EAL_HOTPLUG
@@ -410,9 +426,11 @@ pci_uio_unmap(struct mapped_pci_resource *uio_res)
 	if (uio_res == NULL)
 		return;
 
-	for (i = 0; i != uio_res->nb_maps; i++)
+	for (i = 0; i != uio_res->nb_maps; i++) {
 		pci_unmap_resource(uio_res->maps[i].addr,
 				(size_t)uio_res->maps[i].size);
+		rte_free(uio_res->maps[i].path);
+	}
 }
 
 static struct mapped_pci_resource *
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v6 4/5] eal/bsdapp: Change names of pci related data structure
  2015-06-26  8:18       ` [dpdk-dev] [PATCH v6 0/5] Clean up pci uio implementations Tetsuya Mukawa
                           ` (2 preceding siblings ...)
  2015-06-26  8:18         ` [dpdk-dev] [PATCH v6 3/5] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
@ 2015-06-26  8:18         ` Tetsuya Mukawa
  2015-06-26 14:36           ` Iremonger, Bernard
  2015-06-26  8:18         ` [dpdk-dev] [PATCH v6 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp Tetsuya Mukawa
  4 siblings, 1 reply; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-06-26  8:18 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

To merge pci code of linuxapp and bsdapp, this patch changes names
like below.
 - uio_map to pci_map
 - uio_resource to mapped_pci_resource
 - uio_res_list to mapped_pci_res_list

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index b071f07..8261e09 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -83,7 +83,7 @@
  * enabling bus master.
  */
 
-struct uio_map {
+struct pci_map {
 	void *addr;
 	uint64_t offset;
 	uint64_t size;
@@ -94,16 +94,16 @@ struct uio_map {
  * For multi-process we need to reproduce all PCI mappings in secondary
  * processes, so save them in a tailq.
  */
-struct uio_resource {
-	TAILQ_ENTRY(uio_resource) next;
+struct mapped_pci_resource {
+	TAILQ_ENTRY(mapped_pci_resource) next;
 
 	struct rte_pci_addr pci_addr;
 	char path[PATH_MAX];
 	size_t nb_maps;
-	struct uio_map maps[PCI_MAX_RESOURCE];
+	struct pci_map maps[PCI_MAX_RESOURCE];
 };
 
-TAILQ_HEAD(uio_res_list, uio_resource);
+TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource);
 
 static struct rte_tailq_elem rte_uio_tailq = {
 	.name = "UIO_RESOURCE_LIST",
@@ -162,9 +162,9 @@ static int
 pci_uio_map_secondary(struct rte_pci_device *dev)
 {
 	size_t i;
-	struct uio_resource *uio_res;
-	struct uio_res_list *uio_res_list =
-			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
+	struct mapped_pci_resource *uio_res;
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 
 	TAILQ_FOREACH(uio_res, uio_res_list, next) {
 
@@ -201,10 +201,10 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	uint64_t offset;
 	uint64_t pagesz;
 	struct rte_pci_addr *loc = &dev->addr;
-	struct uio_resource *uio_res;
-	struct uio_res_list *uio_res_list =
-			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
-	struct uio_map *maps;
+	struct mapped_pci_resource *uio_res;
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct pci_map *maps;
 
 	dev->intr_handle.fd = -1;
 	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v6 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp
  2015-06-26  8:18       ` [dpdk-dev] [PATCH v6 0/5] Clean up pci uio implementations Tetsuya Mukawa
                           ` (3 preceding siblings ...)
  2015-06-26  8:18         ` [dpdk-dev] [PATCH v6 4/5] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
@ 2015-06-26  8:18         ` Tetsuya Mukawa
  2015-06-26 14:42           ` Iremonger, Bernard
  4 siblings, 1 reply; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-06-26  8:18 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

This patch fixes below.
- bsdapp
 - Use map_id in pci_uio_map_resource().
 - Fix interface of pci_map_resource().
 - Move path variable of mapped_pci_resource structure to pci_map.
- linuxapp
 - Remove redundant error message of linuxapp.

'pci_uio_map_resource()' is implemented in both linuxapp and bsdapp,
but interface is different. The patch fixes the function of bsdapp
to do same as linuxapp. After applying it, file descriptor should be
opened and closed out of pci_map_resource().

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c       | 118 ++++++++++++++++++------------
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c |  21 +++---
 2 files changed, 80 insertions(+), 59 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 8261e09..06c564f 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -85,6 +85,7 @@
 
 struct pci_map {
 	void *addr;
+	char *path;
 	uint64_t offset;
 	uint64_t size;
 	uint64_t phaddr;
@@ -99,7 +100,7 @@ struct mapped_pci_resource {
 
 	struct rte_pci_addr pci_addr;
 	char path[PATH_MAX];
-	size_t nb_maps;
+	int nb_maps;
 	struct pci_map maps[PCI_MAX_RESOURCE];
 };
 
@@ -121,47 +122,30 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)
 
 /* map a particular resource from a file */
 static void *
-pci_map_resource(void *requested_addr, const char *devname, off_t offset,
-		 size_t size)
+pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
+		 int additional_flags)
 {
-	int fd;
 	void *mapaddr;
 
-	/*
-	 * open devname, to mmap it
-	 */
-	fd = open(devname, O_RDWR);
-	if (fd < 0) {
-		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
-			devname, strerror(errno));
-		goto fail;
-	}
-
 	/* Map the PCI memory resource of device */
 	mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
-			MAP_SHARED, fd, offset);
-	close(fd);
-	if (mapaddr == MAP_FAILED ||
-			(requested_addr != NULL && mapaddr != requested_addr)) {
-		RTE_LOG(ERR, EAL, "%s(): cannot mmap(%s(%d), %p, 0x%lx, 0x%lx):"
-			" %s (%p)\n", __func__, devname, fd, requested_addr,
+			MAP_SHARED | additional_flags, fd, offset);
+	if (mapaddr == MAP_FAILED) {
+		RTE_LOG(ERR, EAL,
+			"%s(): cannot mmap(%d, %p, 0x%lx, 0x%lx): %s (%p)\n",
+			__func__, fd, requested_addr,
 			(unsigned long)size, (unsigned long)offset,
 			strerror(errno), mapaddr);
-		goto fail;
-	}
-
-	RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
+	} else
+		RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
 
 	return mapaddr;
-
-fail:
-	return NULL;
 }
 
 static int
 pci_uio_map_secondary(struct rte_pci_device *dev)
 {
-	size_t i;
+	int i, fd;
 	struct mapped_pci_resource *uio_res;
 	struct mapped_pci_res_list *uio_res_list =
 			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
@@ -169,19 +153,34 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 	TAILQ_FOREACH(uio_res, uio_res_list, next) {
 
 		/* skip this element if it doesn't match our PCI address */
-		if (memcmp(&uio_res->pci_addr, &dev->addr, sizeof(dev->addr)))
+		if (rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr))
 			continue;
 
 		for (i = 0; i != uio_res->nb_maps; i++) {
-			if (pci_map_resource(uio_res->maps[i].addr,
-					     uio_res->path,
-					     (off_t)uio_res->maps[i].offset,
-					     (size_t)uio_res->maps[i].size)
-			    != uio_res->maps[i].addr) {
+			/*
+			 * open devname, to mmap it
+			 */
+			fd = open(uio_res->maps[i].path, O_RDWR);
+			if (fd < 0) {
+				RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
+					uio_res->maps[i].path, strerror(errno));
+				return -1;
+			}
+
+			void *mapaddr = pci_map_resource(uio_res->maps[i].addr,
+					fd, (off_t)uio_res->maps[i].offset,
+					(size_t)uio_res->maps[i].size, 0);
+			if (mapaddr != uio_res->maps[i].addr) {
 				RTE_LOG(ERR, EAL,
-					"Cannot mmap device resource\n");
+						"Cannot mmap device resource "
+						"file %s to address: %p\n",
+						uio_res->maps[i].path,
+						uio_res->maps[i].addr);
+				close(fd);
 				return -1;
 			}
+			/* fd is not needed in slave process, close it */
+			close(fd);
 		}
 		return 0;
 	}
@@ -194,7 +193,7 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 static int
 pci_uio_map_resource(struct rte_pci_device *dev)
 {
-	int i, j;
+	int i, map_idx;
 	char devname[PATH_MAX]; /* contains the /dev/uioX */
 	void *mapaddr;
 	uint64_t phaddr;
@@ -246,35 +245,60 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	pagesz = sysconf(_SC_PAGESIZE);
 
 	maps = uio_res->maps;
-	for (i = uio_res->nb_maps = 0; i != PCI_MAX_RESOURCE; i++) {
+	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
+		int fd;
 
-		j = uio_res->nb_maps;
 		/* skip empty BAR */
 		if ((phaddr = dev->mem_resource[i].phys_addr) == 0)
 			continue;
 
+		/* allocate memory to keep path */
+		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
+		if (maps[map_idx].path == NULL) {
+			RTE_LOG(ERR, EAL, "Cannot allocate memory for "
+					"path: %s\n", strerror(errno));
+			goto free_uio_res;
+		}
+
+		/*
+		 * open resource file, to mmap it
+		 */
+		fd = open(devname, O_RDWR);
+		if (fd < 0) {
+			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
+					devname, strerror(errno));
+			rte_free(maps[map_idx].path);
+			goto free_uio_res;
+		}
+
 		/* if matching map is found, then use it */
 		offset = i * pagesz;
-		maps[j].offset = offset;
-		maps[j].phaddr = dev->mem_resource[i].phys_addr;
-		maps[j].size = dev->mem_resource[i].len;
-		if (maps[j].addr != NULL ||
-		    (mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
-						(size_t)maps[j].size)
-		    ) == NULL) {
+		mapaddr = pci_map_resource(NULL, fd, (off_t)offset,
+					(size_t)dev->mem_resource[i].len, 0);
+		close(fd);
+		if (mapaddr == MAP_FAILED) {
+			rte_free(maps[map_idx].path);
 			goto free_uio_res;
 		}
 
-		maps[j].addr = mapaddr;
-		uio_res->nb_maps++;
+		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
+		maps[map_idx].size = dev->mem_resource[i].len;
+		maps[map_idx].addr = mapaddr;
+		maps[map_idx].offset = offset;
+		strcpy(maps[map_idx].path, devname);
+		map_idx++;
 		dev->mem_resource[i].addr = mapaddr;
 	}
 
+	uio_res->nb_maps = map_idx;
+
 	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
 
 	return 0;
 
 free_uio_res:
+	for (i = 0; i < map_idx; i++)
+		rte_free(maps[i].path);
 	rte_free(uio_res);
 close_fd:
 	close(dev->intr_handle.fd);
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index c3b259b..19620fe 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -116,17 +116,11 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 					fd, (off_t)uio_res->maps[i].offset,
 					(size_t)uio_res->maps[i].size, 0);
 			if (mapaddr != uio_res->maps[i].addr) {
-				if (mapaddr == MAP_FAILED)
-					RTE_LOG(ERR, EAL,
-							"Cannot mmap device resource file %s: %s\n",
-							uio_res->maps[i].path,
-							strerror(errno));
-				else
-					RTE_LOG(ERR, EAL,
-							"Cannot mmap device resource file %s to address: %p\n",
-							uio_res->maps[i].path,
-							uio_res->maps[i].addr);
-
+				RTE_LOG(ERR, EAL,
+						"Cannot mmap device resource "
+						"file %s to address: %p\n",
+						uio_res->maps[i].path,
+						uio_res->maps[i].addr);
 				close(fd);
 				return -1;
 			}
@@ -353,8 +347,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 		/* allocate memory to keep path */
 		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
-		if (maps[map_idx].path == NULL)
+		if (maps[map_idx].path == NULL) {
+			RTE_LOG(ERR, EAL, "Cannot allocate memory for "
+					"path: %s\n", strerror(errno));
 			goto free_uio_res;
+		}
 
 		/*
 		 * open resource file, to mmap it
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v6 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c
  2015-06-26  8:18         ` [dpdk-dev] [PATCH v6 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
@ 2015-06-26 14:30           ` Iremonger, Bernard
  0 siblings, 0 replies; 120+ messages in thread
From: Iremonger, Bernard @ 2015-06-26 14:30 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev


> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Friday, June 26, 2015 9:18 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; david.marchand@6wind.com; Tetsuya.Mukawa
> Subject: [PATCH v6 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c
> 
> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
> 
> This patch fixes coding style of below files in linuxapp and bsdapp.
>  - eal_pci.c
>  - eal_pci_uio.c
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> Acked-by: Stephen Hemminger <stephen@networkplumber.org>

Acked-by: Bernard Iremonger <Bernard.iremonger@intel.com>

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v6 2/5] eal: Close file descriptor of uio configuration
  2015-06-26  8:18         ` [dpdk-dev] [PATCH v6 2/5] eal: Close file descriptor of uio configuration Tetsuya Mukawa
@ 2015-06-26 14:32           ` Iremonger, Bernard
  0 siblings, 0 replies; 120+ messages in thread
From: Iremonger, Bernard @ 2015-06-26 14:32 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev

> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Friday, June 26, 2015 9:18 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; david.marchand@6wind.com; Tetsuya.Mukawa
> Subject: [PATCH v6 2/5] eal: Close file descriptor of uio configuration
> 
> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
> 
> When pci_uio_unmap_resource() is called, a file descriptor that is used for
> uio configuration should be closed.
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> Acked-by: Stephen Hemminger <stephen@networkplumber.org>

Acked-by: Bernard Iremonger <bernard.iremonger@intel.com>

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v6 3/5] eal: Fix memory leaks and needless increment of pci_map_addr
  2015-06-26  8:18         ` [dpdk-dev] [PATCH v6 3/5] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
@ 2015-06-26 14:34           ` Iremonger, Bernard
  2015-06-30  8:24           ` [dpdk-dev] [PATCH v7 00/12] Clean up pci uio implementations Tetsuya Mukawa
  1 sibling, 0 replies; 120+ messages in thread
From: Iremonger, Bernard @ 2015-06-26 14:34 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev

> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Friday, June 26, 2015 9:18 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; david.marchand@6wind.com; Tetsuya.Mukawa
> Subject: [PATCH v6 3/5] eal: Fix memory leaks and needless increment of
> pci_map_addr
> 
> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
> 
> This patch fixes following memory leaks.
> - When open() is failed, uio_res and fds won't be freed in
>   pci_uio_map_resource().
> - When pci_map_resource() is failed but path is allocated correctly,
>   path and fds won't be freed in pci_uio_map_recource().
>   Also, some mapped resources should be freed.
> - When pci_uio_unmap() is called, path should be freed.
> 
> Also, fixes below.
> - When pci_map_resource() is failed, mapaddr will be MAP_FAILED.
>   In this case, pci_map_addr should not be incremented in
>   pci_uio_map_resource().
> - To shrink code, move close().
> - Remove fail variable.
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
Acked-by: Bernard Iremonger <Bernard.iremonger@intel.com>

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v6 4/5] eal/bsdapp: Change names of pci related data structure
  2015-06-26  8:18         ` [dpdk-dev] [PATCH v6 4/5] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
@ 2015-06-26 14:36           ` Iremonger, Bernard
  0 siblings, 0 replies; 120+ messages in thread
From: Iremonger, Bernard @ 2015-06-26 14:36 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev

> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Friday, June 26, 2015 9:18 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; david.marchand@6wind.com; Tetsuya.Mukawa
> Subject: [PATCH v6 4/5] eal/bsdapp: Change names of pci related data
> structure
> 
> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
> 
> To merge pci code of linuxapp and bsdapp, this patch changes names like
> below.
>  - uio_map to pci_map
>  - uio_resource to mapped_pci_resource
>  - uio_res_list to mapped_pci_res_list
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>

Acked-by: Bernard Iremonger <bernard.iremonger@intel.com>

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v6 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp
  2015-06-26  8:18         ` [dpdk-dev] [PATCH v6 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp Tetsuya Mukawa
@ 2015-06-26 14:42           ` Iremonger, Bernard
  0 siblings, 0 replies; 120+ messages in thread
From: Iremonger, Bernard @ 2015-06-26 14:42 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev

> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Friday, June 26, 2015 9:18 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; david.marchand@6wind.com; Tetsuya.Mukawa
> Subject: [PATCH v6 5/5] eal: Fix uio mapping differences between linuxapp
> and bsdapp
> 
> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
> 
> This patch fixes below.
> - bsdapp
>  - Use map_id in pci_uio_map_resource().
>  - Fix interface of pci_map_resource().
>  - Move path variable of mapped_pci_resource structure to pci_map.
> - linuxapp
>  - Remove redundant error message of linuxapp.
> 
> 'pci_uio_map_resource()' is implemented in both linuxapp and bsdapp, but
> interface is different. The patch fixes the function of bsdapp to do same as
> linuxapp. After applying it, file descriptor should be opened and closed out of
> pci_map_resource().
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>

Acked-by: Bernard Iremonger <bernard.iremonger@intel.com>

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v7 00/12] Clean up pci uio implementations
  2015-06-26  8:18         ` [dpdk-dev] [PATCH v6 3/5] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
  2015-06-26 14:34           ` Iremonger, Bernard
@ 2015-06-30  8:24           ` Tetsuya Mukawa
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 01/12] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
                               ` (12 more replies)
  1 sibling, 13 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-06-30  8:24 UTC (permalink / raw)
  To: dev

Currently Linux implementation and BSD implementation have almost same
code about pci uio. This patch series cleans up it.

PATCH v7 changes:
 - Add below patches. Also, the order of patches are changed.
   - eal: Add pci_uio_alloc_resource()
   - eal: Add pci_uio_map_resource_by_index()
   - eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp
   - eal: Consolidate pci_map/unmap_resource() of linuxapp and bsdapp
   - eal: Consolidate pci uio functions of linuxapp and bsdapp
   - eal: Consolidate pci_map/unmap_device() of linuxapp and bsdapp
   - eal: Consolidate rte_eal_pci_probe/close_one_driver() of linuxapp and bsdapp
   (Thanks to Bruce Richardson)
 - While adding above, below patches are not changed at all.
   - eal: Fix coding style of eal_pci.c and eal_pci_uio.c
   - eal: Close file descriptor of uio configuration
   - eal: Fix memory leaks and needless increment of pci_map_addr
   - eal/bsdapp: Change names of pci related data structure
   - eal: Fix uio mapping differences between linuxapp and bsdapp
 - some function names are changed like below.
   - pci_uio_alloc_uio_resource() to pci_uio_alloc_resource().
   - pci_uio_map_uio_resource_by_index() to pci_uio_map_resource_by_index().
   (Thanks to Iremonger, Bernard)

PATCH v6 changes:
 - Free mapped resources in pci_uio_map_resource().
 - Fix error handling in pci_uio_map_resource().
   (Thanks to David, Marchand)

PATCH v5 changes:
 - Rebase to latest master branch.

PATCH v4 changes:
 - Rebase to latest master branch.
 - Fix bug in pci_uio_map_resource() of BSD code. 'maps[i].path' shouldn't be freed.
     Fixed in below patch:
     [PATCH 3/5] eal: Fix memory leaks and needless increment of pci_map_addr
 - 'path' member of 'struct mapped_pci_resource' should not be removed because it will be used in BSD code.
     Fixed in below patch:
     [PATCH 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp

PATCH v3 changes:
 - Squash patches related with pci_map_resource().
 - Free maps[].path to easy to understand.
   (Thanks to Iremonger, Bernard)
 - Close fds opened in this function.
 - Remove unused path variable from mapped_pci_resource structure.

PATCH v2 changes:
 - Move 'if-condition' to later patch series.
 - Fix memory leaks of path.
 - Fix typos.
   (Thanks to David Marchand)
 - Fix commit title and body.
 - Fix pci_map_resource() to handle MAP_FAILED.
   (Thanks to Iremonger, Bernard)

Changes:
 - This patch set is derived from below.
   "[PATCH v2] eal: Port Hotplug support for BSD"
 - Set cfg_fd as -1, when cfg_fd is closed.
   (Thanks to Iremonger, Bernard)
 - Remove needless coding style fixings.
 - Fix coding style of if-else condition.
   (Thanks to Richardson, Bruce)



Tetsuya.Mukawa (12):
  eal: Fix coding style of eal_pci.c and eal_pci_uio.c
  eal: Close file descriptor of uio configuration
  eal: Fix memory leaks and needless increment of pci_map_addr
  eal/bsdapp: Change names of pci related data structure
  eal: Fix uio mapping differences between linuxapp and bsdapp
  eal: Add pci_uio_alloc_resource()
  eal: Add pci_uio_map_resource_by_index()
  eal: Consolidate pci_map and mapped_pci_resource of linuxapp and
    bsdapp
  eal: Consolidate pci_map/unmap_resource() of linuxapp and bsdapp
  eal: Consolidate pci uio functions of linuxapp and bsdapp
  eal: Consolidate pci_map/unmap_device() of linuxapp and bsdapp
  eal: Consolidate rte_eal_pci_probe/close_one_driver() of linuxapp and
    bsdapp

 lib/librte_eal/bsdapp/eal/Makefile                 |   1 +
 lib/librte_eal/bsdapp/eal/eal_pci.c                | 283 ++++++--------------
 .../bsdapp/eal/include/exec-env/rte_interrupts.h   |   1 +
 lib/librte_eal/common/eal_common_pci.c             | 225 ++++++++++++++++
 lib/librte_eal/common/eal_common_pci_uio.c         | 270 +++++++++++++++++++
 lib/librte_eal/common/eal_private.h                |  59 ++++-
 lib/librte_eal/common/include/rte_pci.h            |  40 +++
 lib/librte_eal/linuxapp/eal/Makefile               |   1 +
 lib/librte_eal/linuxapp/eal/eal_pci.c              | 236 +----------------
 lib/librte_eal/linuxapp/eal/eal_pci_init.h         |  39 +--
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c          | 290 ++++++---------------
 lib/librte_ether/rte_ethdev.c                      |   1 +
 12 files changed, 753 insertions(+), 693 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_pci_uio.c

-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v7 01/12] eal: Fix coding style of eal_pci.c and eal_pci_uio.c
  2015-06-30  8:24           ` [dpdk-dev] [PATCH v7 00/12] Clean up pci uio implementations Tetsuya Mukawa
@ 2015-06-30  8:24             ` Tetsuya Mukawa
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 02/12] eal: Close file descriptor of uio configuration Tetsuya Mukawa
                               ` (11 subsequent siblings)
  12 siblings, 0 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-06-30  8:24 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

This patch fixes coding style of below files in linuxapp and bsdapp.
 - eal_pci.c
 - eal_pci_uio.c

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c       | 12 +++++++-----
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 12 ++++++++----
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 2df5c1c..8e24fd1 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -161,9 +161,10 @@ fail:
 static int
 pci_uio_map_secondary(struct rte_pci_device *dev)
 {
-        size_t i;
-        struct uio_resource *uio_res;
-	struct uio_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
+	size_t i;
+	struct uio_resource *uio_res;
+	struct uio_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
 
 	TAILQ_FOREACH(uio_res, uio_res_list, next) {
 
@@ -201,7 +202,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	uint64_t pagesz;
 	struct rte_pci_addr *loc = &dev->addr;
 	struct uio_resource *uio_res;
-	struct uio_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
+	struct uio_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
 	struct uio_map *maps;
 
 	dev->intr_handle.fd = -1;
@@ -311,7 +313,7 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
 	/* FreeBSD has no NUMA support (yet) */
 	dev->numa_node = 0;
 
-/* parse resources */
+	/* parse resources */
 	switch (conf->pc_hdr & PCIM_HDRTYPE) {
 	case PCIM_HDRTYPE_NORMAL:
 		max = PCIR_MAX_BAR_0;
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index b5116a7..5d3354d 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -92,7 +92,8 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 {
 	int fd, i;
 	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 
 	TAILQ_FOREACH(uio_res, uio_res_list, next) {
 
@@ -272,7 +273,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	uint64_t phaddr;
 	struct rte_pci_addr *loc = &dev->addr;
 	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 	struct pci_map *maps;
 
 	dev->intr_handle.fd = -1;
@@ -417,7 +419,8 @@ static struct mapped_pci_resource *
 pci_uio_find_resource(struct rte_pci_device *dev)
 {
 	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 
 	if (dev == NULL)
 		return NULL;
@@ -436,7 +439,8 @@ void
 pci_uio_unmap_resource(struct rte_pci_device *dev)
 {
 	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 
 	if (dev == NULL)
 		return;
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v7 02/12] eal: Close file descriptor of uio configuration
  2015-06-30  8:24           ` [dpdk-dev] [PATCH v7 00/12] Clean up pci uio implementations Tetsuya Mukawa
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 01/12] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
@ 2015-06-30  8:24             ` Tetsuya Mukawa
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 03/12] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
                               ` (10 subsequent siblings)
  12 siblings, 0 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-06-30  8:24 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

When pci_uio_unmap_resource() is called, a file descriptor that is used
for uio configuration should be closed.

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 5d3354d..34316b6 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -464,8 +464,12 @@ pci_uio_unmap_resource(struct rte_pci_device *dev)
 
 	/* close fd if in primary process */
 	close(dev->intr_handle.fd);
-
 	dev->intr_handle.fd = -1;
+
+	/* close cfg_fd if in primary process */
+	close(dev->intr_handle.uio_cfg_fd);
+	dev->intr_handle.uio_cfg_fd = -1;
+
 	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
 }
 #endif /* RTE_LIBRTE_EAL_HOTPLUG */
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v7 03/12] eal: Fix memory leaks and needless increment of pci_map_addr
  2015-06-30  8:24           ` [dpdk-dev] [PATCH v7 00/12] Clean up pci uio implementations Tetsuya Mukawa
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 01/12] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 02/12] eal: Close file descriptor of uio configuration Tetsuya Mukawa
@ 2015-06-30  8:24             ` Tetsuya Mukawa
  2015-06-30 12:33               ` Iremonger, Bernard
  2015-07-02  9:57               ` Bruce Richardson
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 04/12] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
                               ` (9 subsequent siblings)
  12 siblings, 2 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-06-30  8:24 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

This patch fixes following memory leaks.
- When open() is failed, uio_res and fds won't be freed in
  pci_uio_map_resource().
- When pci_map_resource() is failed but path is allocated correctly,
  path and fds won't be freed in pci_uio_map_recource().
  Also, some mapped resources should be freed.
- When pci_uio_unmap() is called, path should be freed.

Also, fixes below.
- When pci_map_resource() is failed, mapaddr will be MAP_FAILED.
  In this case, pci_map_addr should not be incremented in
  pci_uio_map_resource().
- To shrink code, move close().
- Remove fail variable.

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c       | 14 ++++++--
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 56 ++++++++++++++++++++-----------
 2 files changed, 48 insertions(+), 22 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 8e24fd1..b071f07 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -235,7 +235,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) == NULL) {
 		RTE_LOG(ERR, EAL,
 			"%s(): cannot store uio mmap details\n", __func__);
-		return -1;
+		goto close_fd;
 	}
 
 	snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
@@ -262,8 +262,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 		    (mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
 						(size_t)maps[j].size)
 		    ) == NULL) {
-			rte_free(uio_res);
-			return -1;
+			goto free_uio_res;
 		}
 
 		maps[j].addr = mapaddr;
@@ -274,6 +273,15 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
 
 	return 0;
+
+free_uio_res:
+	rte_free(uio_res);
+close_fd:
+	close(dev->intr_handle.fd);
+	dev->intr_handle.fd = -1;
+	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+
+	return -1;
 }
 
 /* Scan one pci sysfs entry, and fill the devices list from it. */
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 34316b6..c3b259b 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -308,7 +308,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	if (dev->intr_handle.uio_cfg_fd < 0) {
 		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
 			cfgname, strerror(errno));
-		return -1;
+		goto close_fd;
 	}
 
 	if (dev->kdrv == RTE_KDRV_IGB_UIO)
@@ -319,7 +319,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 		/* set bus master that is not done by uio_pci_generic */
 		if (pci_uio_set_bus_master(dev->intr_handle.uio_cfg_fd)) {
 			RTE_LOG(ERR, EAL, "Cannot set up bus mastering!\n");
-			return -1;
+			goto close_fd;
 		}
 	}
 
@@ -328,7 +328,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	if (uio_res == NULL) {
 		RTE_LOG(ERR, EAL,
 			"%s(): cannot store uio mmap details\n", __func__);
-		return -1;
+		goto close_fd;
 	}
 
 	snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
@@ -338,7 +338,6 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	maps = uio_res->maps;
 	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
 		int fd;
-		int fail = 0;
 
 		/* skip empty BAR */
 		phaddr = dev->mem_resource[i].phys_addr;
@@ -352,6 +351,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 				loc->domain, loc->bus, loc->devid, loc->function,
 				i);
 
+		/* allocate memory to keep path */
+		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
+		if (maps[map_idx].path == NULL)
+			goto free_uio_res;
+
 		/*
 		 * open resource file, to mmap it
 		 */
@@ -359,7 +363,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 		if (fd < 0) {
 			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
 					devname, strerror(errno));
-			return -1;
+			rte_free(maps[map_idx].path);
+			goto free_uio_res;
 		}
 
 		/* try mapping somewhere close to the end of hugepages */
@@ -368,23 +373,15 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 		mapaddr = pci_map_resource(pci_map_addr, fd, 0,
 				(size_t)dev->mem_resource[i].len, 0);
-		if (mapaddr == MAP_FAILED)
-			fail = 1;
+		close(fd);
+		if (mapaddr == MAP_FAILED) {
+			rte_free(maps[map_idx].path);
+			goto free_uio_res;
+		}
 
 		pci_map_addr = RTE_PTR_ADD(mapaddr,
 				(size_t)dev->mem_resource[i].len);
 
-		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
-		if (maps[map_idx].path == NULL)
-			fail = 1;
-
-		if (fail) {
-			rte_free(uio_res);
-			close(fd);
-			return -1;
-		}
-		close(fd);
-
 		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
 		maps[map_idx].size = dev->mem_resource[i].len;
 		maps[map_idx].addr = mapaddr;
@@ -399,6 +396,25 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
 
 	return 0;
+
+free_uio_res:
+	for (i = 0; i < map_idx; i++) {
+		pci_unmap_resource(uio_res->maps[i].addr,
+				(size_t)uio_res->maps[i].size);
+		rte_free(maps[i].path);
+	}
+	rte_free(uio_res);
+close_fd:
+	if (dev->intr_handle.uio_cfg_fd >= 0) {
+		close(dev->intr_handle.uio_cfg_fd);
+		dev->intr_handle.uio_cfg_fd = -1;
+	}
+
+	close(dev->intr_handle.fd);
+	dev->intr_handle.fd = -1;
+	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+
+	return -1;
 }
 
 #ifdef RTE_LIBRTE_EAL_HOTPLUG
@@ -410,9 +426,11 @@ pci_uio_unmap(struct mapped_pci_resource *uio_res)
 	if (uio_res == NULL)
 		return;
 
-	for (i = 0; i != uio_res->nb_maps; i++)
+	for (i = 0; i != uio_res->nb_maps; i++) {
 		pci_unmap_resource(uio_res->maps[i].addr,
 				(size_t)uio_res->maps[i].size);
+		rte_free(uio_res->maps[i].path);
+	}
 }
 
 static struct mapped_pci_resource *
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v7 04/12] eal/bsdapp: Change names of pci related data structure
  2015-06-30  8:24           ` [dpdk-dev] [PATCH v7 00/12] Clean up pci uio implementations Tetsuya Mukawa
                               ` (2 preceding siblings ...)
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 03/12] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
@ 2015-06-30  8:24             ` Tetsuya Mukawa
  2015-06-30 12:36               ` Iremonger, Bernard
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 05/12] eal: Fix uio mapping differences between linuxapp and bsdapp Tetsuya Mukawa
                               ` (8 subsequent siblings)
  12 siblings, 1 reply; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-06-30  8:24 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

To merge pci code of linuxapp and bsdapp, this patch changes names
like below.
 - uio_map to pci_map
 - uio_resource to mapped_pci_resource
 - uio_res_list to mapped_pci_res_list

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index b071f07..8261e09 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -83,7 +83,7 @@
  * enabling bus master.
  */
 
-struct uio_map {
+struct pci_map {
 	void *addr;
 	uint64_t offset;
 	uint64_t size;
@@ -94,16 +94,16 @@ struct uio_map {
  * For multi-process we need to reproduce all PCI mappings in secondary
  * processes, so save them in a tailq.
  */
-struct uio_resource {
-	TAILQ_ENTRY(uio_resource) next;
+struct mapped_pci_resource {
+	TAILQ_ENTRY(mapped_pci_resource) next;
 
 	struct rte_pci_addr pci_addr;
 	char path[PATH_MAX];
 	size_t nb_maps;
-	struct uio_map maps[PCI_MAX_RESOURCE];
+	struct pci_map maps[PCI_MAX_RESOURCE];
 };
 
-TAILQ_HEAD(uio_res_list, uio_resource);
+TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource);
 
 static struct rte_tailq_elem rte_uio_tailq = {
 	.name = "UIO_RESOURCE_LIST",
@@ -162,9 +162,9 @@ static int
 pci_uio_map_secondary(struct rte_pci_device *dev)
 {
 	size_t i;
-	struct uio_resource *uio_res;
-	struct uio_res_list *uio_res_list =
-			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
+	struct mapped_pci_resource *uio_res;
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 
 	TAILQ_FOREACH(uio_res, uio_res_list, next) {
 
@@ -201,10 +201,10 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	uint64_t offset;
 	uint64_t pagesz;
 	struct rte_pci_addr *loc = &dev->addr;
-	struct uio_resource *uio_res;
-	struct uio_res_list *uio_res_list =
-			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
-	struct uio_map *maps;
+	struct mapped_pci_resource *uio_res;
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct pci_map *maps;
 
 	dev->intr_handle.fd = -1;
 	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v7 05/12] eal: Fix uio mapping differences between linuxapp and bsdapp
  2015-06-30  8:24           ` [dpdk-dev] [PATCH v7 00/12] Clean up pci uio implementations Tetsuya Mukawa
                               ` (3 preceding siblings ...)
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 04/12] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
@ 2015-06-30  8:24             ` Tetsuya Mukawa
  2015-06-30 12:51               ` Iremonger, Bernard
  2015-07-02 10:20               ` Bruce Richardson
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 06/12] eal: Add pci_uio_alloc_resource() Tetsuya Mukawa
                               ` (7 subsequent siblings)
  12 siblings, 2 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-06-30  8:24 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

This patch fixes below.
- bsdapp
 - Use map_id in pci_uio_map_resource().
 - Fix interface of pci_map_resource().
 - Move path variable of mapped_pci_resource structure to pci_map.
- linuxapp
 - Remove redundant error message of linuxapp.

'pci_uio_map_resource()' is implemented in both linuxapp and bsdapp,
but interface is different. The patch fixes the function of bsdapp
to do same as linuxapp. After applying it, file descriptor should be
opened and closed out of pci_map_resource().

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c       | 118 ++++++++++++++++++------------
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c |  21 +++---
 2 files changed, 80 insertions(+), 59 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 8261e09..06c564f 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -85,6 +85,7 @@
 
 struct pci_map {
 	void *addr;
+	char *path;
 	uint64_t offset;
 	uint64_t size;
 	uint64_t phaddr;
@@ -99,7 +100,7 @@ struct mapped_pci_resource {
 
 	struct rte_pci_addr pci_addr;
 	char path[PATH_MAX];
-	size_t nb_maps;
+	int nb_maps;
 	struct pci_map maps[PCI_MAX_RESOURCE];
 };
 
@@ -121,47 +122,30 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)
 
 /* map a particular resource from a file */
 static void *
-pci_map_resource(void *requested_addr, const char *devname, off_t offset,
-		 size_t size)
+pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
+		 int additional_flags)
 {
-	int fd;
 	void *mapaddr;
 
-	/*
-	 * open devname, to mmap it
-	 */
-	fd = open(devname, O_RDWR);
-	if (fd < 0) {
-		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
-			devname, strerror(errno));
-		goto fail;
-	}
-
 	/* Map the PCI memory resource of device */
 	mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
-			MAP_SHARED, fd, offset);
-	close(fd);
-	if (mapaddr == MAP_FAILED ||
-			(requested_addr != NULL && mapaddr != requested_addr)) {
-		RTE_LOG(ERR, EAL, "%s(): cannot mmap(%s(%d), %p, 0x%lx, 0x%lx):"
-			" %s (%p)\n", __func__, devname, fd, requested_addr,
+			MAP_SHARED | additional_flags, fd, offset);
+	if (mapaddr == MAP_FAILED) {
+		RTE_LOG(ERR, EAL,
+			"%s(): cannot mmap(%d, %p, 0x%lx, 0x%lx): %s (%p)\n",
+			__func__, fd, requested_addr,
 			(unsigned long)size, (unsigned long)offset,
 			strerror(errno), mapaddr);
-		goto fail;
-	}
-
-	RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
+	} else
+		RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
 
 	return mapaddr;
-
-fail:
-	return NULL;
 }
 
 static int
 pci_uio_map_secondary(struct rte_pci_device *dev)
 {
-	size_t i;
+	int i, fd;
 	struct mapped_pci_resource *uio_res;
 	struct mapped_pci_res_list *uio_res_list =
 			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
@@ -169,19 +153,34 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 	TAILQ_FOREACH(uio_res, uio_res_list, next) {
 
 		/* skip this element if it doesn't match our PCI address */
-		if (memcmp(&uio_res->pci_addr, &dev->addr, sizeof(dev->addr)))
+		if (rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr))
 			continue;
 
 		for (i = 0; i != uio_res->nb_maps; i++) {
-			if (pci_map_resource(uio_res->maps[i].addr,
-					     uio_res->path,
-					     (off_t)uio_res->maps[i].offset,
-					     (size_t)uio_res->maps[i].size)
-			    != uio_res->maps[i].addr) {
+			/*
+			 * open devname, to mmap it
+			 */
+			fd = open(uio_res->maps[i].path, O_RDWR);
+			if (fd < 0) {
+				RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
+					uio_res->maps[i].path, strerror(errno));
+				return -1;
+			}
+
+			void *mapaddr = pci_map_resource(uio_res->maps[i].addr,
+					fd, (off_t)uio_res->maps[i].offset,
+					(size_t)uio_res->maps[i].size, 0);
+			if (mapaddr != uio_res->maps[i].addr) {
 				RTE_LOG(ERR, EAL,
-					"Cannot mmap device resource\n");
+						"Cannot mmap device resource "
+						"file %s to address: %p\n",
+						uio_res->maps[i].path,
+						uio_res->maps[i].addr);
+				close(fd);
 				return -1;
 			}
+			/* fd is not needed in slave process, close it */
+			close(fd);
 		}
 		return 0;
 	}
@@ -194,7 +193,7 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 static int
 pci_uio_map_resource(struct rte_pci_device *dev)
 {
-	int i, j;
+	int i, map_idx;
 	char devname[PATH_MAX]; /* contains the /dev/uioX */
 	void *mapaddr;
 	uint64_t phaddr;
@@ -246,35 +245,60 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	pagesz = sysconf(_SC_PAGESIZE);
 
 	maps = uio_res->maps;
-	for (i = uio_res->nb_maps = 0; i != PCI_MAX_RESOURCE; i++) {
+	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
+		int fd;
 
-		j = uio_res->nb_maps;
 		/* skip empty BAR */
 		if ((phaddr = dev->mem_resource[i].phys_addr) == 0)
 			continue;
 
+		/* allocate memory to keep path */
+		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
+		if (maps[map_idx].path == NULL) {
+			RTE_LOG(ERR, EAL, "Cannot allocate memory for "
+					"path: %s\n", strerror(errno));
+			goto free_uio_res;
+		}
+
+		/*
+		 * open resource file, to mmap it
+		 */
+		fd = open(devname, O_RDWR);
+		if (fd < 0) {
+			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
+					devname, strerror(errno));
+			rte_free(maps[map_idx].path);
+			goto free_uio_res;
+		}
+
 		/* if matching map is found, then use it */
 		offset = i * pagesz;
-		maps[j].offset = offset;
-		maps[j].phaddr = dev->mem_resource[i].phys_addr;
-		maps[j].size = dev->mem_resource[i].len;
-		if (maps[j].addr != NULL ||
-		    (mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
-						(size_t)maps[j].size)
-		    ) == NULL) {
+		mapaddr = pci_map_resource(NULL, fd, (off_t)offset,
+					(size_t)dev->mem_resource[i].len, 0);
+		close(fd);
+		if (mapaddr == MAP_FAILED) {
+			rte_free(maps[map_idx].path);
 			goto free_uio_res;
 		}
 
-		maps[j].addr = mapaddr;
-		uio_res->nb_maps++;
+		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
+		maps[map_idx].size = dev->mem_resource[i].len;
+		maps[map_idx].addr = mapaddr;
+		maps[map_idx].offset = offset;
+		strcpy(maps[map_idx].path, devname);
+		map_idx++;
 		dev->mem_resource[i].addr = mapaddr;
 	}
 
+	uio_res->nb_maps = map_idx;
+
 	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
 
 	return 0;
 
 free_uio_res:
+	for (i = 0; i < map_idx; i++)
+		rte_free(maps[i].path);
 	rte_free(uio_res);
 close_fd:
 	close(dev->intr_handle.fd);
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index c3b259b..19620fe 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -116,17 +116,11 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 					fd, (off_t)uio_res->maps[i].offset,
 					(size_t)uio_res->maps[i].size, 0);
 			if (mapaddr != uio_res->maps[i].addr) {
-				if (mapaddr == MAP_FAILED)
-					RTE_LOG(ERR, EAL,
-							"Cannot mmap device resource file %s: %s\n",
-							uio_res->maps[i].path,
-							strerror(errno));
-				else
-					RTE_LOG(ERR, EAL,
-							"Cannot mmap device resource file %s to address: %p\n",
-							uio_res->maps[i].path,
-							uio_res->maps[i].addr);
-
+				RTE_LOG(ERR, EAL,
+						"Cannot mmap device resource "
+						"file %s to address: %p\n",
+						uio_res->maps[i].path,
+						uio_res->maps[i].addr);
 				close(fd);
 				return -1;
 			}
@@ -353,8 +347,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 		/* allocate memory to keep path */
 		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
-		if (maps[map_idx].path == NULL)
+		if (maps[map_idx].path == NULL) {
+			RTE_LOG(ERR, EAL, "Cannot allocate memory for "
+					"path: %s\n", strerror(errno));
 			goto free_uio_res;
+		}
 
 		/*
 		 * open resource file, to mmap it
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v7 06/12] eal: Add pci_uio_alloc_resource()
  2015-06-30  8:24           ` [dpdk-dev] [PATCH v7 00/12] Clean up pci uio implementations Tetsuya Mukawa
                               ` (4 preceding siblings ...)
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 05/12] eal: Fix uio mapping differences between linuxapp and bsdapp Tetsuya Mukawa
@ 2015-06-30  8:24             ` Tetsuya Mukawa
  2015-07-02 10:46               ` Bruce Richardson
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 07/12] eal: Add pci_uio_map_resource_by_index() Tetsuya Mukawa
                               ` (6 subsequent siblings)
  12 siblings, 1 reply; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-06-30  8:24 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

This patch adds a new function called pci_uio_alloc_resource().
The function hides how to prepare uio resource in linuxapp and bsdapp.
With the function, pci_uio_map_resource() will be more abstracted.

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c       | 70 +++++++++++++++++++---------
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 77 ++++++++++++++++++++++---------
 2 files changed, 104 insertions(+), 43 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 06c564f..7d2f8b5 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -189,28 +189,17 @@ 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)
+pci_uio_alloc_resource(struct rte_pci_device *dev,
+		struct mapped_pci_resource **uio_res)
 {
-	int i, map_idx;
 	char devname[PATH_MAX]; /* contains the /dev/uioX */
-	void *mapaddr;
-	uint64_t phaddr;
-	uint64_t offset;
-	uint64_t pagesz;
-	struct rte_pci_addr *loc = &dev->addr;
-	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list =
-			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
-	struct pci_map *maps;
+	struct rte_pci_addr *loc;
 
-	dev->intr_handle.fd = -1;
-	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+	if ((dev == NULL) || (uio_res == NULL))
+		return -1;
 
-	/* secondary processes - use already recorded details */
-	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
-		return pci_uio_map_secondary(dev);
+	loc = &dev->addr;
 
 	snprintf(devname, sizeof(devname), "/dev/uio@pci:%u:%u:%u",
 			dev->addr.bus, dev->addr.devid, dev->addr.function);
@@ -231,18 +220,56 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	dev->intr_handle.type = RTE_INTR_HANDLE_UIO;
 
 	/* allocate the mapping details for secondary processes*/
-	if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) == NULL) {
+	*uio_res = rte_zmalloc("UIO_RES", sizeof(**uio_res), 0);
+	if (*uio_res == NULL) {
 		RTE_LOG(ERR, EAL,
 			"%s(): cannot store uio mmap details\n", __func__);
 		goto close_fd;
 	}
 
-	snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
-	memcpy(&uio_res->pci_addr, &dev->addr, sizeof(uio_res->pci_addr));
+	snprintf((*uio_res)->path, sizeof((*uio_res)->path), "%s", devname);
+	memcpy(&(*uio_res)->pci_addr, &dev->addr, sizeof((*uio_res)->pci_addr));
 
+	return 0;
+
+close_fd:
+	close(dev->intr_handle.fd);
+	dev->intr_handle.fd = -1;
+	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+
+	return -1;
+}
+
+/* map the PCI resource of a PCI device in virtual memory */
+static int
+pci_uio_map_resource(struct rte_pci_device *dev)
+{
+	int i, map_idx, ret;
+	char *devname;
+	void *mapaddr;
+	uint64_t phaddr;
+	uint64_t offset;
+	uint64_t pagesz;
+	struct mapped_pci_resource *uio_res = NULL;
+	struct mapped_pci_res_list *uio_res_list =
+		RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct pci_map *maps;
+
+	dev->intr_handle.fd = -1;
+	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+
+	/* secondary processes - use already recorded details */
+	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+		return pci_uio_map_secondary(dev);
+
+	/* allocate uio resource */
+	ret = pci_uio_alloc_resource(dev, &uio_res);
+	if ((ret != 0) || (uio_res == NULL))
+		return ret;
 
 	/* Map all BARs */
 	pagesz = sysconf(_SC_PAGESIZE);
+	devname = uio_res->path;
 
 	maps = uio_res->maps;
 	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
@@ -300,7 +327,8 @@ free_uio_res:
 	for (i = 0; i < map_idx; i++)
 		rte_free(maps[i].path);
 	rte_free(uio_res);
-close_fd:
+
+	/* close fd opened by pci_uio_alloc_resource() */
 	close(dev->intr_handle.fd);
 	dev->intr_handle.fd = -1;
 	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 19620fe..9483667 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -254,30 +254,20 @@ pci_get_uio_dev(struct rte_pci_device *dev, char *dstbuf,
 	return uio_num;
 }
 
-/* map the PCI resource of a PCI device in virtual memory */
-int
-pci_uio_map_resource(struct rte_pci_device *dev)
+static int
+pci_uio_alloc_resource(struct rte_pci_device *dev,
+		struct mapped_pci_resource **uio_res)
 {
-	int i, map_idx;
 	char dirname[PATH_MAX];
 	char cfgname[PATH_MAX];
 	char devname[PATH_MAX]; /* contains the /dev/uioX */
-	void *mapaddr;
 	int uio_num;
-	uint64_t phaddr;
-	struct rte_pci_addr *loc = &dev->addr;
-	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list =
-			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
-	struct pci_map *maps;
+	struct rte_pci_addr *loc;
 
-	dev->intr_handle.fd = -1;
-	dev->intr_handle.uio_cfg_fd = -1;
-	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+	if ((dev == NULL) || (uio_res == NULL))
+		return -1;
 
-	/* secondary processes - use already recorded details */
-	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
-		return pci_uio_map_secondary(dev);
+	loc = &dev->addr;
 
 	/* find uio resource */
 	uio_num = pci_get_uio_dev(dev, dirname, sizeof(dirname));
@@ -318,15 +308,57 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	}
 
 	/* allocate the mapping details for secondary processes*/
-	uio_res = rte_zmalloc("UIO_RES", sizeof(*uio_res), 0);
-	if (uio_res == NULL) {
+	*uio_res = rte_zmalloc("UIO_RES", sizeof(**uio_res), 0);
+	if (*uio_res == NULL) {
 		RTE_LOG(ERR, EAL,
 			"%s(): cannot store uio mmap details\n", __func__);
 		goto close_fd;
 	}
 
-	snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
-	memcpy(&uio_res->pci_addr, &dev->addr, sizeof(uio_res->pci_addr));
+	snprintf((*uio_res)->path, sizeof((*uio_res)->path), "%s", devname);
+	memcpy(&(*uio_res)->pci_addr, &dev->addr, sizeof((*uio_res)->pci_addr));
+
+	return 0;
+
+close_fd:
+	if (dev->intr_handle.uio_cfg_fd >= 0) {
+		close(dev->intr_handle.uio_cfg_fd);
+		dev->intr_handle.uio_cfg_fd = -1;
+	}
+
+	close(dev->intr_handle.fd);
+	dev->intr_handle.fd = -1;
+	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+
+	return -1;
+}
+
+/* map the PCI resource of a PCI device in virtual memory */
+int
+pci_uio_map_resource(struct rte_pci_device *dev)
+{
+	int i, map_idx, ret;
+	char devname[PATH_MAX]; /* contains the /dev/uioX */
+	void *mapaddr;
+	uint64_t phaddr;
+	struct rte_pci_addr *loc = &dev->addr;
+	struct mapped_pci_resource *uio_res = NULL;
+	struct mapped_pci_res_list *uio_res_list =
+		RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct pci_map *maps;
+
+	dev->intr_handle.fd = -1;
+	dev->intr_handle.uio_cfg_fd = -1;
+	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+
+	/* secondary processes - use already recorded details */
+	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+		return pci_uio_map_secondary(dev);
+
+	/* allocate uio resource */
+	ret = pci_uio_alloc_resource(dev, &uio_res);
+	if ((ret != 0) || (uio_res == NULL))
+		return ret;
 
 	/* Map all BARs */
 	maps = uio_res->maps;
@@ -401,7 +433,8 @@ free_uio_res:
 		rte_free(maps[i].path);
 	}
 	rte_free(uio_res);
-close_fd:
+
+	/* close fd opened by pci_uio_alloc_resource() */
 	if (dev->intr_handle.uio_cfg_fd >= 0) {
 		close(dev->intr_handle.uio_cfg_fd);
 		dev->intr_handle.uio_cfg_fd = -1;
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v7 07/12] eal: Add pci_uio_map_resource_by_index()
  2015-06-30  8:24           ` [dpdk-dev] [PATCH v7 00/12] Clean up pci uio implementations Tetsuya Mukawa
                               ` (5 preceding siblings ...)
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 06/12] eal: Add pci_uio_alloc_resource() Tetsuya Mukawa
@ 2015-06-30  8:24             ` Tetsuya Mukawa
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 08/12] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp Tetsuya Mukawa
                               ` (5 subsequent siblings)
  12 siblings, 0 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-06-30  8:24 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

This patch adds a new function called pci_uio_map_resource_by_index().
The function hides how to map uio resource in linuxapp and bsdapp.
With the function, pci_uio_map_resource() will be more abstracted.

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c       | 107 +++++++++++++++-----------
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 124 +++++++++++++++++-------------
 2 files changed, 133 insertions(+), 98 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 7d2f8b5..da81d76 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -240,20 +240,73 @@ close_fd:
 	return -1;
 }
 
+static int
+pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
+		struct mapped_pci_resource *uio_res, int map_idx)
+{
+	int fd;
+	char *devname;
+	void *mapaddr;
+	uint64_t offset;
+	uint64_t pagesz;
+	struct pci_map *maps;
+
+	if ((dev == NULL) || (uio_res == NULL) || (uio_res->path == NULL))
+		return -1;
+
+	maps = uio_res->maps;
+	devname = uio_res->path;
+	pagesz = sysconf(_SC_PAGESIZE);
+
+	/* allocate memory to keep path */
+	maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
+	if (maps[map_idx].path == NULL) {
+		RTE_LOG(ERR, EAL, "Cannot allocate memory for "
+				"path: %s\n", strerror(errno));
+		return -1;
+	}
+
+	/*
+	 * open resource file, to mmap it
+	 */
+	fd = open(devname, O_RDWR);
+	if (fd < 0) {
+		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
+				devname, strerror(errno));
+		goto fail;
+	}
+
+	/* if matching map is found, then use it */
+	offset = res_idx * pagesz;
+	mapaddr = pci_map_resource(NULL, fd, (off_t)offset,
+			(size_t)dev->mem_resource[res_idx].len, 0);
+	close(fd);
+	if (mapaddr == MAP_FAILED)
+		goto fail;
+
+	maps[map_idx].phaddr = dev->mem_resource[res_idx].phys_addr;
+	maps[map_idx].size = dev->mem_resource[res_idx].len;
+	maps[map_idx].addr = mapaddr;
+	maps[map_idx].offset = offset;
+	strcpy(maps[map_idx].path, devname);
+	dev->mem_resource[res_idx].addr = mapaddr;
+
+	return 0;
+
+fail:
+	rte_free(maps[map_idx].path);
+	return -1;
+}
+
 /* map the PCI resource of a PCI device in virtual memory */
 static int
 pci_uio_map_resource(struct rte_pci_device *dev)
 {
 	int i, map_idx, ret;
-	char *devname;
-	void *mapaddr;
 	uint64_t phaddr;
-	uint64_t offset;
-	uint64_t pagesz;
 	struct mapped_pci_resource *uio_res = NULL;
 	struct mapped_pci_res_list *uio_res_list =
 		RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
-	struct pci_map *maps;
 
 	dev->intr_handle.fd = -1;
 	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
@@ -268,53 +321,17 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 		return ret;
 
 	/* Map all BARs */
-	pagesz = sysconf(_SC_PAGESIZE);
-	devname = uio_res->path;
-
-	maps = uio_res->maps;
 	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
-		int fd;
-
 		/* skip empty BAR */
 		if ((phaddr = dev->mem_resource[i].phys_addr) == 0)
 			continue;
 
-		/* allocate memory to keep path */
-		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
-		if (maps[map_idx].path == NULL) {
-			RTE_LOG(ERR, EAL, "Cannot allocate memory for "
-					"path: %s\n", strerror(errno));
+		ret = pci_uio_map_resource_by_index(dev, i,
+				uio_res, map_idx);
+		if (ret != 0)
 			goto free_uio_res;
-		}
 
-		/*
-		 * open resource file, to mmap it
-		 */
-		fd = open(devname, O_RDWR);
-		if (fd < 0) {
-			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
-					devname, strerror(errno));
-			rte_free(maps[map_idx].path);
-			goto free_uio_res;
-		}
-
-		/* if matching map is found, then use it */
-		offset = i * pagesz;
-		mapaddr = pci_map_resource(NULL, fd, (off_t)offset,
-					(size_t)dev->mem_resource[i].len, 0);
-		close(fd);
-		if (mapaddr == MAP_FAILED) {
-			rte_free(maps[map_idx].path);
-			goto free_uio_res;
-		}
-
-		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
-		maps[map_idx].size = dev->mem_resource[i].len;
-		maps[map_idx].addr = mapaddr;
-		maps[map_idx].offset = offset;
-		strcpy(maps[map_idx].path, devname);
 		map_idx++;
-		dev->mem_resource[i].addr = mapaddr;
 	}
 
 	uio_res->nb_maps = map_idx;
@@ -325,7 +342,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 free_uio_res:
 	for (i = 0; i < map_idx; i++)
-		rte_free(maps[i].path);
+		rte_free(uio_res->maps[i].path);
 	rte_free(uio_res);
 
 	/* close fd opened by pci_uio_alloc_resource() */
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 9483667..39fb50f 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -333,19 +333,82 @@ close_fd:
 	return -1;
 }
 
+static int
+pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
+		struct mapped_pci_resource *uio_res, int map_idx)
+{
+	int fd;
+	char devname[PATH_MAX]; /* contains the /dev/uioX */
+	void *mapaddr;
+	struct rte_pci_addr *loc;
+	struct pci_map *maps;
+
+	if ((dev == NULL) || (uio_res == NULL))
+		return -1;
+
+	loc = &dev->addr;
+	maps = uio_res->maps;
+
+	/* update devname for mmap  */
+	snprintf(devname, sizeof(devname),
+			SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/resource%d",
+			loc->domain, loc->bus, loc->devid,
+			loc->function, res_idx);
+
+	/* allocate memory to keep path */
+	maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
+	if (maps[map_idx].path == NULL) {
+		RTE_LOG(ERR, EAL, "Cannot allocate memory for "
+				"path: %s\n", strerror(errno));
+		return -1;
+	}
+
+	/*
+	 * open resource file, to mmap it
+	 */
+	fd = open(devname, O_RDWR);
+	if (fd < 0) {
+		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
+				devname, strerror(errno));
+		goto fail;
+	}
+
+	/* try mapping somewhere close to the end of hugepages */
+	if (pci_map_addr == NULL)
+		pci_map_addr = pci_find_max_end_va();
+
+	mapaddr = pci_map_resource(pci_map_addr, fd, 0,
+			(size_t)dev->mem_resource[res_idx].len, 0);
+	close(fd);
+	if (mapaddr == MAP_FAILED)
+		goto fail;
+
+	pci_map_addr = RTE_PTR_ADD(mapaddr,
+			(size_t)dev->mem_resource[res_idx].len);
+
+	maps[map_idx].phaddr = dev->mem_resource[res_idx].phys_addr;
+	maps[map_idx].size = dev->mem_resource[res_idx].len;
+	maps[map_idx].addr = mapaddr;
+	maps[map_idx].offset = 0;
+	strcpy(maps[map_idx].path, devname);
+	dev->mem_resource[res_idx].addr = mapaddr;
+
+	return 0;
+
+fail:
+	rte_free(maps[map_idx].path);
+	return -1;
+}
+
 /* map the PCI resource of a PCI device in virtual memory */
 int
 pci_uio_map_resource(struct rte_pci_device *dev)
 {
 	int i, map_idx, ret;
-	char devname[PATH_MAX]; /* contains the /dev/uioX */
-	void *mapaddr;
 	uint64_t phaddr;
-	struct rte_pci_addr *loc = &dev->addr;
 	struct mapped_pci_resource *uio_res = NULL;
 	struct mapped_pci_res_list *uio_res_list =
 		RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
-	struct pci_map *maps;
 
 	dev->intr_handle.fd = -1;
 	dev->intr_handle.uio_cfg_fd = -1;
@@ -361,63 +424,18 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 		return ret;
 
 	/* Map all BARs */
-	maps = uio_res->maps;
 	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
-		int fd;
-
 		/* skip empty BAR */
 		phaddr = dev->mem_resource[i].phys_addr;
 		if (phaddr == 0)
 			continue;
 
-
-		/* update devname for mmap  */
-		snprintf(devname, sizeof(devname),
-				SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/resource%d",
-				loc->domain, loc->bus, loc->devid, loc->function,
-				i);
-
-		/* allocate memory to keep path */
-		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
-		if (maps[map_idx].path == NULL) {
-			RTE_LOG(ERR, EAL, "Cannot allocate memory for "
-					"path: %s\n", strerror(errno));
-			goto free_uio_res;
-		}
-
-		/*
-		 * open resource file, to mmap it
-		 */
-		fd = open(devname, O_RDWR);
-		if (fd < 0) {
-			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
-					devname, strerror(errno));
-			rte_free(maps[map_idx].path);
+		ret = pci_uio_map_resource_by_index(dev, i,
+				uio_res, map_idx);
+		if (ret != 0)
 			goto free_uio_res;
-		}
-
-		/* try mapping somewhere close to the end of hugepages */
-		if (pci_map_addr == NULL)
-			pci_map_addr = pci_find_max_end_va();
-
-		mapaddr = pci_map_resource(pci_map_addr, fd, 0,
-				(size_t)dev->mem_resource[i].len, 0);
-		close(fd);
-		if (mapaddr == MAP_FAILED) {
-			rte_free(maps[map_idx].path);
-			goto free_uio_res;
-		}
-
-		pci_map_addr = RTE_PTR_ADD(mapaddr,
-				(size_t)dev->mem_resource[i].len);
 
-		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
-		maps[map_idx].size = dev->mem_resource[i].len;
-		maps[map_idx].addr = mapaddr;
-		maps[map_idx].offset = 0;
-		strcpy(maps[map_idx].path, devname);
 		map_idx++;
-		dev->mem_resource[i].addr = mapaddr;
 	}
 
 	uio_res->nb_maps = map_idx;
@@ -430,7 +448,7 @@ free_uio_res:
 	for (i = 0; i < map_idx; i++) {
 		pci_unmap_resource(uio_res->maps[i].addr,
 				(size_t)uio_res->maps[i].size);
-		rte_free(maps[i].path);
+		rte_free(uio_res->maps[i].path);
 	}
 	rte_free(uio_res);
 
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v7 08/12] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp
  2015-06-30  8:24           ` [dpdk-dev] [PATCH v7 00/12] Clean up pci uio implementations Tetsuya Mukawa
                               ` (6 preceding siblings ...)
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 07/12] eal: Add pci_uio_map_resource_by_index() Tetsuya Mukawa
@ 2015-06-30  8:24             ` Tetsuya Mukawa
  2015-06-30 14:25               ` Iremonger, Bernard
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 09/12] eal: Consolidate pci_map/unmap_resource() " Tetsuya Mukawa
                               ` (4 subsequent siblings)
  12 siblings, 1 reply; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-06-30  8:24 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

This patch consolidates below structures, and defines them in common code.
 - struct pci_map
 - strucy mapped_pci_resouces

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c        | 24 ------------------------
 lib/librte_eal/common/include/rte_pci.h    | 28 ++++++++++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_pci_init.h | 23 -----------------------
 3 files changed, 28 insertions(+), 47 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index da81d76..c045674 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -82,30 +82,6 @@
  * network card, only providing access to PCI BAR to applications, and
  * enabling bus master.
  */
-
-struct pci_map {
-	void *addr;
-	char *path;
-	uint64_t offset;
-	uint64_t size;
-	uint64_t phaddr;
-};
-
-/*
- * For multi-process we need to reproduce all PCI mappings in secondary
- * processes, so save them in a tailq.
- */
-struct mapped_pci_resource {
-	TAILQ_ENTRY(mapped_pci_resource) next;
-
-	struct rte_pci_addr pci_addr;
-	char path[PATH_MAX];
-	int nb_maps;
-	struct pci_map maps[PCI_MAX_RESOURCE];
-};
-
-TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource);
-
 static struct rte_tailq_elem rte_uio_tailq = {
 	.name = "UIO_RESOURCE_LIST",
 };
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index 7801fa0..0a2ef09 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -220,6 +220,34 @@ struct rte_pci_driver {
 /** Device driver supports detaching capability */
 #define RTE_PCI_DRV_DETACHABLE	0x0010
 
+/**
+ * A structure describing a PCI mapping.
+ */
+struct pci_map {
+	void *addr;
+	char *path;
+	uint64_t offset;
+	uint64_t size;
+	uint64_t phaddr;
+};
+
+/**
+ * A structure describing a mapped PCI resource.
+ * For multi-process we need to reproduce all PCI mappings in secondary
+ * processes, so save them in a tailq.
+ */
+struct mapped_pci_resource {
+	TAILQ_ENTRY(mapped_pci_resource) next;
+
+	struct rte_pci_addr pci_addr;
+	char path[PATH_MAX];
+	int nb_maps;
+	struct pci_map maps[PCI_MAX_RESOURCE];
+};
+
+/** mapped pci device list */
+TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource);
+
 /**< Internal use only - Macro used by pci addr parsing functions **/
 #define GET_PCIADDR_FIELD(in, fd, lim, dlm)                   \
 do {                                                               \
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
index aa7b755..d9d1878 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
@@ -36,29 +36,6 @@
 
 #include "eal_vfio.h"
 
-struct pci_map {
-	void *addr;
-	char *path;
-	uint64_t offset;
-	uint64_t size;
-	uint64_t phaddr;
-};
-
-/*
- * For multi-process we need to reproduce all PCI mappings in secondary
- * processes, so save them in a tailq.
- */
-struct mapped_pci_resource {
-	TAILQ_ENTRY(mapped_pci_resource) next;
-
-	struct rte_pci_addr pci_addr;
-	char path[PATH_MAX];
-	int nb_maps;
-	struct pci_map maps[PCI_MAX_RESOURCE];
-};
-
-TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource);
-
 /*
  * Helper function to map PCI resources right after hugepages in virtual memory
  */
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v7 09/12] eal: Consolidate pci_map/unmap_resource() of linuxapp and bsdapp
  2015-06-30  8:24           ` [dpdk-dev] [PATCH v7 00/12] Clean up pci uio implementations Tetsuya Mukawa
                               ` (7 preceding siblings ...)
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 08/12] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp Tetsuya Mukawa
@ 2015-06-30  8:24             ` Tetsuya Mukawa
  2015-06-30 14:28               ` Iremonger, Bernard
  2015-07-02 11:11               ` Bruce Richardson
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 10/12] eal: Consolidate pci uio functions " Tetsuya Mukawa
                               ` (3 subsequent siblings)
  12 siblings, 2 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-06-30  8:24 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

The patch consolidates below functions, and implemented in common
eal code.
 - pci_map_resource()
 - pci_unmap_resource()

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c        | 22 ----------------
 lib/librte_eal/common/eal_common_pci.c     | 39 ++++++++++++++++++++++++++++
 lib/librte_eal/common/include/rte_pci.h    | 11 ++++++++
 lib/librte_eal/linuxapp/eal/eal_pci.c      | 41 ------------------------------
 lib/librte_eal/linuxapp/eal/eal_pci_init.h |  5 ----
 5 files changed, 50 insertions(+), 68 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index c045674..aac4826 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -96,28 +96,6 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)
 	return -ENOTSUP;
 }
 
-/* map a particular resource from a file */
-static void *
-pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
-		 int additional_flags)
-{
-	void *mapaddr;
-
-	/* Map the PCI memory resource of device */
-	mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
-			MAP_SHARED | additional_flags, fd, offset);
-	if (mapaddr == MAP_FAILED) {
-		RTE_LOG(ERR, EAL,
-			"%s(): cannot mmap(%d, %p, 0x%lx, 0x%lx): %s (%p)\n",
-			__func__, fd, requested_addr,
-			(unsigned long)size, (unsigned long)offset,
-			strerror(errno), mapaddr);
-	} else
-		RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
-
-	return mapaddr;
-}
-
 static int
 pci_uio_map_secondary(struct rte_pci_device *dev)
 {
diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 4229aaf..81b8fd6 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -67,6 +67,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <sys/queue.h>
+#include <sys/mman.h>
 
 #include <rte_interrupts.h>
 #include <rte_log.h>
@@ -98,6 +99,44 @@ static struct rte_devargs *pci_devargs_lookup(struct rte_pci_device *dev)
 	return NULL;
 }
 
+/* map a particular resource from a file */
+void *
+pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
+		 int additional_flags)
+{
+	void *mapaddr;
+
+	/* Map the PCI memory resource of device */
+	mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
+			MAP_SHARED | additional_flags, fd, offset);
+	if (mapaddr == MAP_FAILED) {
+		RTE_LOG(ERR, EAL, "%s(): cannot mmap(%d, %p, 0x%lx, 0x%lx): %s (%p)\n",
+			__func__, fd, requested_addr,
+			(unsigned long)size, (unsigned long)offset,
+			strerror(errno), mapaddr);
+	} else
+		RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
+
+	return mapaddr;
+}
+
+/* unmap a particular resource */
+void
+pci_unmap_resource(void *requested_addr, size_t size)
+{
+	if (requested_addr == NULL)
+		return;
+
+	/* Unmap the PCI memory resource of device */
+	if (munmap(requested_addr, size)) {
+		RTE_LOG(ERR, EAL, "%s(): cannot munmap(%p, 0x%lx): %s\n",
+			__func__, requested_addr, (unsigned long)size,
+			strerror(errno));
+	} else
+		RTE_LOG(DEBUG, EAL, "  PCI memory unmapped at %p\n",
+				requested_addr);
+}
+
 /*
  * If vendor/device ID match, call the devinit() function of all
  * registered driver for the given device. Return -1 if initialization
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index 0a2ef09..56dcb46 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -364,6 +364,17 @@ int rte_eal_pci_scan(void);
  */
 int rte_eal_pci_probe(void);
 
+/**
+ * Map pci resouce.
+ */
+void *pci_map_resource(void *requested_addr, int fd, off_t offset,
+		size_t size, int additional_flags);
+
+/**
+ * Map pci resouce.
+ */
+void pci_unmap_resource(void *requested_addr, size_t size);
+
 #ifdef RTE_LIBRTE_EAL_HOTPLUG
 /**
  * Probe the single PCI device.
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index d2adc66..fc99eaa 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -33,7 +33,6 @@
 
 #include <string.h>
 #include <dirent.h>
-#include <sys/mman.h>
 
 #include <rte_log.h>
 #include <rte_pci.h>
@@ -142,46 +141,6 @@ pci_find_max_end_va(void)
 	return RTE_PTR_ADD(last->addr, last->len);
 }
 
-
-/* map a particular resource from a file */
-void *
-pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
-		 int additional_flags)
-{
-	void *mapaddr;
-
-	/* Map the PCI memory resource of device */
-	mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
-			MAP_SHARED | additional_flags, fd, offset);
-	if (mapaddr == MAP_FAILED) {
-		RTE_LOG(ERR, EAL, "%s(): cannot mmap(%d, %p, 0x%lx, 0x%lx): %s (%p)\n",
-			__func__, fd, requested_addr,
-			(unsigned long)size, (unsigned long)offset,
-			strerror(errno), mapaddr);
-	} else {
-		RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
-	}
-
-	return mapaddr;
-}
-
-/* unmap a particular resource */
-void
-pci_unmap_resource(void *requested_addr, size_t size)
-{
-	if (requested_addr == NULL)
-		return;
-
-	/* Unmap the PCI memory resource of device */
-	if (munmap(requested_addr, size)) {
-		RTE_LOG(ERR, EAL, "%s(): cannot munmap(%p, 0x%lx): %s\n",
-			__func__, requested_addr, (unsigned long)size,
-			strerror(errno));
-	} else
-		RTE_LOG(DEBUG, EAL, "  PCI memory unmapped at %p\n",
-				requested_addr);
-}
-
 /* parse the "resource" sysfs file */
 static int
 pci_parse_sysfs_resource(const char *filename, struct rte_pci_device *dev)
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
index d9d1878..d426b27 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
@@ -42,14 +42,9 @@
 extern void *pci_map_addr;
 void *pci_find_max_end_va(void);
 
-void *pci_map_resource(void *requested_addr, int fd, off_t offset,
-	       size_t size, int additional_flags);
-
 /* map IGB_UIO resource prototype */
 int pci_uio_map_resource(struct rte_pci_device *dev);
 
-void pci_unmap_resource(void *requested_addr, size_t size);
-
 #ifdef RTE_LIBRTE_EAL_HOTPLUG
 /* unmap IGB_UIO resource prototype */
 void pci_uio_unmap_resource(struct rte_pci_device *dev);
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v7 10/12] eal: Consolidate pci uio functions of linuxapp and bsdapp
  2015-06-30  8:24           ` [dpdk-dev] [PATCH v7 00/12] Clean up pci uio implementations Tetsuya Mukawa
                               ` (8 preceding siblings ...)
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 09/12] eal: Consolidate pci_map/unmap_resource() " Tetsuya Mukawa
@ 2015-06-30  8:24             ` Tetsuya Mukawa
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 11/12] eal: Consolidate pci_map/unmap_device() " Tetsuya Mukawa
                               ` (2 subsequent siblings)
  12 siblings, 0 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-06-30  8:24 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

The patch consolidates below functions, and implement these
in eal_common_pci_uio.c.
 - pci_uio_map_secondary()
 - pci_uio_map_resource()
 - pci_uio_unmap()
 - pci_uio_find_resource()
 - pci_uio_unmap_resource()

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/Makefile                 |   1 +
 lib/librte_eal/bsdapp/eal/eal_pci.c                | 110 +--------
 .../bsdapp/eal/include/exec-env/rte_interrupts.h   |   1 +
 lib/librte_eal/common/eal_common_pci_uio.c         | 270 +++++++++++++++++++++
 lib/librte_eal/common/eal_private.h                |  55 +++++
 lib/librte_eal/linuxapp/eal/Makefile               |   1 +
 lib/librte_eal/linuxapp/eal/eal_pci_init.h         |  11 +-
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c          | 196 +--------------
 8 files changed, 336 insertions(+), 309 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_pci_uio.c

diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile
index c73ffb6..40ec648 100644
--- a/lib/librte_eal/bsdapp/eal/Makefile
+++ b/lib/librte_eal/bsdapp/eal/Makefile
@@ -68,6 +68,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_memzone.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_log.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_launch.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_pci.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_pci_uio.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_memory.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_tailqs.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_errno.c
diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index aac4826..329c268 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -82,10 +82,6 @@
  * network card, only providing access to PCI BAR to applications, and
  * enabling bus master.
  */
-static struct rte_tailq_elem rte_uio_tailq = {
-	.name = "UIO_RESOURCE_LIST",
-};
-EAL_REGISTER_TAILQ(rte_uio_tailq)
 
 /* unbind kernel driver for this device */
 static int
@@ -96,54 +92,7 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)
 	return -ENOTSUP;
 }
 
-static int
-pci_uio_map_secondary(struct rte_pci_device *dev)
-{
-	int i, fd;
-	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list =
-			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
-
-	TAILQ_FOREACH(uio_res, uio_res_list, next) {
-
-		/* skip this element if it doesn't match our PCI address */
-		if (rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr))
-			continue;
-
-		for (i = 0; i != uio_res->nb_maps; i++) {
-			/*
-			 * open devname, to mmap it
-			 */
-			fd = open(uio_res->maps[i].path, O_RDWR);
-			if (fd < 0) {
-				RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
-					uio_res->maps[i].path, strerror(errno));
-				return -1;
-			}
-
-			void *mapaddr = pci_map_resource(uio_res->maps[i].addr,
-					fd, (off_t)uio_res->maps[i].offset,
-					(size_t)uio_res->maps[i].size, 0);
-			if (mapaddr != uio_res->maps[i].addr) {
-				RTE_LOG(ERR, EAL,
-						"Cannot mmap device resource "
-						"file %s to address: %p\n",
-						uio_res->maps[i].path,
-						uio_res->maps[i].addr);
-				close(fd);
-				return -1;
-			}
-			/* fd is not needed in slave process, close it */
-			close(fd);
-		}
-		return 0;
-	}
-
-	RTE_LOG(ERR, EAL, "Cannot find resource for device\n");
-	return 1;
-}
-
-static int
+int
 pci_uio_alloc_resource(struct rte_pci_device *dev,
 		struct mapped_pci_resource **uio_res)
 {
@@ -194,7 +143,7 @@ close_fd:
 	return -1;
 }
 
-static int
+int
 pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
 		struct mapped_pci_resource *uio_res, int map_idx)
 {
@@ -252,61 +201,6 @@ fail:
 	return -1;
 }
 
-/* map the PCI resource of a PCI device in virtual memory */
-static int
-pci_uio_map_resource(struct rte_pci_device *dev)
-{
-	int i, map_idx, ret;
-	uint64_t phaddr;
-	struct mapped_pci_resource *uio_res = NULL;
-	struct mapped_pci_res_list *uio_res_list =
-		RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
-
-	dev->intr_handle.fd = -1;
-	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
-
-	/* secondary processes - use already recorded details */
-	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
-		return pci_uio_map_secondary(dev);
-
-	/* allocate uio resource */
-	ret = pci_uio_alloc_resource(dev, &uio_res);
-	if ((ret != 0) || (uio_res == NULL))
-		return ret;
-
-	/* Map all BARs */
-	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
-		/* skip empty BAR */
-		if ((phaddr = dev->mem_resource[i].phys_addr) == 0)
-			continue;
-
-		ret = pci_uio_map_resource_by_index(dev, i,
-				uio_res, map_idx);
-		if (ret != 0)
-			goto free_uio_res;
-
-		map_idx++;
-	}
-
-	uio_res->nb_maps = map_idx;
-
-	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
-
-	return 0;
-
-free_uio_res:
-	for (i = 0; i < map_idx; i++)
-		rte_free(uio_res->maps[i].path);
-	rte_free(uio_res);
-
-	/* close fd opened by pci_uio_alloc_resource() */
-	close(dev->intr_handle.fd);
-	dev->intr_handle.fd = -1;
-	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
-
-	return -1;
-}
-
 /* Scan one pci sysfs entry, and fill the devices list from it. */
 static int
 pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
diff --git a/lib/librte_eal/bsdapp/eal/include/exec-env/rte_interrupts.h b/lib/librte_eal/bsdapp/eal/include/exec-env/rte_interrupts.h
index 87a9cf6..d4c388f 100644
--- a/lib/librte_eal/bsdapp/eal/include/exec-env/rte_interrupts.h
+++ b/lib/librte_eal/bsdapp/eal/include/exec-env/rte_interrupts.h
@@ -48,6 +48,7 @@ enum rte_intr_handle_type {
 /** Handle for interrupts. */
 struct rte_intr_handle {
 	int fd;                          /**< file descriptor */
+	int uio_cfg_fd;                  /**< UIO config file descriptor */
 	enum rte_intr_handle_type type;  /**< handle type */
 };
 
diff --git a/lib/librte_eal/common/eal_common_pci_uio.c b/lib/librte_eal/common/eal_common_pci_uio.c
new file mode 100644
index 0000000..bf29484
--- /dev/null
+++ b/lib/librte_eal/common/eal_common_pci_uio.c
@@ -0,0 +1,270 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2015 IGEL Co.,Ltd. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of IGEL Co.,Ltd. nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <fcntl.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+
+#include <rte_eal.h>
+#include <rte_tailq.h>
+#include <rte_log.h>
+#include <rte_malloc.h>
+
+#include "eal_private.h"
+
+static struct rte_tailq_elem rte_uio_tailq = {
+	.name = "UIO_RESOURCE_LIST",
+};
+EAL_REGISTER_TAILQ(rte_uio_tailq)
+
+static int
+pci_uio_map_secondary(struct rte_pci_device *dev)
+{
+	int fd, i;
+	struct mapped_pci_resource *uio_res;
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+
+	TAILQ_FOREACH(uio_res, uio_res_list, next) {
+
+		/* skip this element if it doesn't match our PCI address */
+		if (rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr))
+			continue;
+
+		for (i = 0; i != uio_res->nb_maps; i++) {
+			/*
+			 * open devname, to mmap it
+			 */
+			fd = open(uio_res->maps[i].path, O_RDWR);
+			if (fd < 0) {
+				RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
+					uio_res->maps[i].path, strerror(errno));
+				return -1;
+			}
+
+			void *mapaddr = pci_map_resource(uio_res->maps[i].addr,
+					fd, (off_t)uio_res->maps[i].offset,
+					(size_t)uio_res->maps[i].size, 0);
+			if (mapaddr != uio_res->maps[i].addr) {
+				RTE_LOG(ERR, EAL,
+						"Cannot mmap device resource "
+						"file %s to address: %p\n",
+						uio_res->maps[i].path,
+						uio_res->maps[i].addr);
+				close(fd);
+				return -1;
+			}
+			/* fd is not needed in slave process, close it */
+			close(fd);
+		}
+		return 0;
+	}
+
+	RTE_LOG(ERR, EAL, "Cannot find resource for device\n");
+	return 1;
+}
+
+/* map the PCI resource of a PCI device in virtual memory */
+int
+pci_uio_map_resource(struct rte_pci_device *dev)
+{
+	int i, map_idx, ret;
+	uint64_t phaddr;
+	struct mapped_pci_resource *uio_res = NULL;
+	struct mapped_pci_res_list *uio_res_list =
+		RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+
+	dev->intr_handle.fd = -1;
+	dev->intr_handle.uio_cfg_fd = -1;
+	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+
+	/* secondary processes - use already recorded details */
+	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+		return pci_uio_map_secondary(dev);
+
+	/* allocate uio resource */
+	ret = pci_uio_alloc_resource(dev, &uio_res);
+	if ((ret != 0) || (uio_res == NULL))
+		return ret;
+
+	/* Map all BARs */
+	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
+		/* skip empty BAR */
+		phaddr = dev->mem_resource[i].phys_addr;
+		if (phaddr == 0)
+			continue;
+
+		ret = pci_uio_map_resource_by_index(dev, i,
+				uio_res, map_idx);
+		if (ret != 0)
+			goto free_uio_res;
+
+		map_idx++;
+	}
+
+	uio_res->nb_maps = map_idx;
+
+	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
+
+	return 0;
+
+free_uio_res:
+	for (i = 0; i < map_idx; i++) {
+		pci_unmap_resource(uio_res->maps[i].addr,
+				(size_t)uio_res->maps[i].size);
+		rte_free(uio_res->maps[i].path);
+	}
+	rte_free(uio_res);
+
+	/* close fd opened by pci_uio_alloc_resource() */
+	if (dev->intr_handle.uio_cfg_fd >= 0) {
+		close(dev->intr_handle.uio_cfg_fd);
+		dev->intr_handle.uio_cfg_fd = -1;
+	}
+
+	close(dev->intr_handle.fd);
+	dev->intr_handle.fd = -1;
+	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+
+	return -1;
+}
+
+#ifdef RTE_LIBRTE_EAL_HOTPLUG
+static void
+pci_uio_unmap(struct mapped_pci_resource *uio_res)
+{
+	int i;
+
+	if (uio_res == NULL)
+		return;
+
+	for (i = 0; i != uio_res->nb_maps; i++) {
+		pci_unmap_resource(uio_res->maps[i].addr,
+				(size_t)uio_res->maps[i].size);
+		rte_free(uio_res->maps[i].path);
+	}
+}
+
+static struct mapped_pci_resource *
+pci_uio_find_resource(struct rte_pci_device *dev)
+{
+	struct mapped_pci_resource *uio_res;
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+
+	if (dev == NULL)
+		return NULL;
+
+	TAILQ_FOREACH(uio_res, uio_res_list, next) {
+
+		/* skip this element if it doesn't match our PCI address */
+		if (!rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr))
+			return uio_res;
+	}
+	return NULL;
+}
+
+/* unmap the PCI resource of a PCI device in virtual memory */
+void
+pci_uio_unmap_resource(struct rte_pci_device *dev)
+{
+	struct mapped_pci_resource *uio_res;
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+
+	if (dev == NULL)
+		return;
+
+	/* find an entry for the device */
+	uio_res = pci_uio_find_resource(dev);
+	if (uio_res == NULL)
+		return;
+
+	/* secondary processes - just free maps */
+	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+		return pci_uio_unmap(uio_res);
+
+	TAILQ_REMOVE(uio_res_list, uio_res, next);
+
+	/* unmap all resources */
+	pci_uio_unmap(uio_res);
+
+	/* free uio resource */
+	rte_free(uio_res);
+
+	/* close fd if in primary process */
+	close(dev->intr_handle.fd);
+	if (dev->intr_handle.uio_cfg_fd >= 0) {
+		close(dev->intr_handle.uio_cfg_fd);
+		dev->intr_handle.uio_cfg_fd = -1;
+	}
+
+	dev->intr_handle.fd = -1;
+	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+}
+#endif /* RTE_LIBRTE_EAL_HOTPLUG */
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 4acf5a0..c3a3fe4 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -35,6 +35,7 @@
 #define _EAL_PRIVATE_H_
 
 #include <stdio.h>
+#include <rte_pci.h>
 
 /**
  * Initialize the memzone subsystem (private to eal).
@@ -154,6 +155,25 @@ struct rte_pci_driver;
 struct rte_pci_device;
 
 /**
+ * Map this device
+ *
+ * This function is private to EAL.
+ *
+ * @return
+ *   0 on success, negative on error
+ */
+int pci_uio_map_resource(struct rte_pci_device *dev);
+
+#ifdef RTE_LIBRTE_EAL_HOTPLUG
+/**
+ * Unmap this device
+ *
+ * This function is private to EAL.
+ */
+void pci_uio_unmap_resource(struct rte_pci_device *dev);
+#endif /* RTE_LIBRTE_EAL_HOTPLUG */
+
+/**
  * Mmap memory for single PCI device
  *
  * This function is private to EAL.
@@ -180,6 +200,41 @@ int rte_eal_pci_close_one_driver(struct rte_pci_driver *dr,
 		struct rte_pci_device *dev);
 
 /**
+ * Allocate uio resource for PCI device
+ *
+ * This function is private to EAL.
+ *
+ * @param dev
+ *   PCI device to allocate uio resource
+ * @param uio_res
+ *   Pointer to uio resource.
+ *   If the function returns 0, the pointer will be filled.
+ * @return
+ *   0 on success, negative on error
+ */
+int pci_uio_alloc_resource(struct rte_pci_device *dev,
+		struct mapped_pci_resource **uio_res);
+
+/**
+ * Map device memory to uio resource
+ *
+ * This function is private to EAL.
+ *
+ * @param dev
+ *   PCI device that has memory information.
+ * @param res_idx
+ *   Memory resource index of the PCI device.
+ * @param uio_res
+ *  uio resource that will keep mapping information.
+ * @param map_idx
+ *   Mapping information index of the uio resource.
+ * @return
+ *   0 on success, negative on error
+ */
+int pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
+		struct mapped_pci_resource *uio_res, int map_idx);
+
+/**
  * Init tail queues for non-EAL library structures. This is to allow
  * the rings, mempools, etc. lists to be shared among multiple processes
  *
diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
index e99d7a3..42a16fe 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -80,6 +80,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_memzone.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_log.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_launch.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_pci.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_pci_uio.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_memory.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_tailqs.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_errno.c
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
index d426b27..0b53518 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
@@ -42,13 +42,10 @@
 extern void *pci_map_addr;
 void *pci_find_max_end_va(void);
 
-/* map IGB_UIO resource prototype */
-int pci_uio_map_resource(struct rte_pci_device *dev);
-
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
-/* unmap IGB_UIO resource prototype */
-void pci_uio_unmap_resource(struct rte_pci_device *dev);
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
+int pci_uio_alloc_resource(struct rte_pci_device *dev,
+		struct mapped_pci_resource **uio_res);
+int pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
+		struct mapped_pci_resource *uio_res, int map_idx);
 
 #ifdef VFIO_PRESENT
 
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 39fb50f..cc38f60 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -51,11 +51,6 @@
 
 void *pci_map_addr = NULL;
 
-static struct rte_tailq_elem rte_uio_tailq = {
-	.name = "UIO_RESOURCE_LIST",
-};
-EAL_REGISTER_TAILQ(rte_uio_tailq)
-
 #define OFF_MAX              ((uint64_t)(off_t)-1)
 
 static int
@@ -88,53 +83,6 @@ pci_uio_set_bus_master(int dev_fd)
 }
 
 static int
-pci_uio_map_secondary(struct rte_pci_device *dev)
-{
-	int fd, i;
-	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list =
-			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
-
-	TAILQ_FOREACH(uio_res, uio_res_list, next) {
-
-		/* skip this element if it doesn't match our PCI address */
-		if (rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr))
-			continue;
-
-		for (i = 0; i != uio_res->nb_maps; i++) {
-			/*
-			 * open devname, to mmap it
-			 */
-			fd = open(uio_res->maps[i].path, O_RDWR);
-			if (fd < 0) {
-				RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
-					uio_res->maps[i].path, strerror(errno));
-				return -1;
-			}
-
-			void *mapaddr = pci_map_resource(uio_res->maps[i].addr,
-					fd, (off_t)uio_res->maps[i].offset,
-					(size_t)uio_res->maps[i].size, 0);
-			if (mapaddr != uio_res->maps[i].addr) {
-				RTE_LOG(ERR, EAL,
-						"Cannot mmap device resource "
-						"file %s to address: %p\n",
-						uio_res->maps[i].path,
-						uio_res->maps[i].addr);
-				close(fd);
-				return -1;
-			}
-			/* fd is not needed in slave process, close it */
-			close(fd);
-		}
-		return 0;
-	}
-
-	RTE_LOG(ERR, EAL, "Cannot find resource for device\n");
-	return 1;
-}
-
-static int
 pci_mknod_uio_dev(const char *sysfs_uio_path, unsigned uio_num)
 {
 	FILE *f;
@@ -254,7 +202,7 @@ pci_get_uio_dev(struct rte_pci_device *dev, char *dstbuf,
 	return uio_num;
 }
 
-static int
+int
 pci_uio_alloc_resource(struct rte_pci_device *dev,
 		struct mapped_pci_resource **uio_res)
 {
@@ -333,7 +281,7 @@ close_fd:
 	return -1;
 }
 
-static int
+int
 pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
 		struct mapped_pci_resource *uio_res, int map_idx)
 {
@@ -399,143 +347,3 @@ fail:
 	rte_free(maps[map_idx].path);
 	return -1;
 }
-
-/* map the PCI resource of a PCI device in virtual memory */
-int
-pci_uio_map_resource(struct rte_pci_device *dev)
-{
-	int i, map_idx, ret;
-	uint64_t phaddr;
-	struct mapped_pci_resource *uio_res = NULL;
-	struct mapped_pci_res_list *uio_res_list =
-		RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
-
-	dev->intr_handle.fd = -1;
-	dev->intr_handle.uio_cfg_fd = -1;
-	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
-
-	/* secondary processes - use already recorded details */
-	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
-		return pci_uio_map_secondary(dev);
-
-	/* allocate uio resource */
-	ret = pci_uio_alloc_resource(dev, &uio_res);
-	if ((ret != 0) || (uio_res == NULL))
-		return ret;
-
-	/* Map all BARs */
-	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
-		/* skip empty BAR */
-		phaddr = dev->mem_resource[i].phys_addr;
-		if (phaddr == 0)
-			continue;
-
-		ret = pci_uio_map_resource_by_index(dev, i,
-				uio_res, map_idx);
-		if (ret != 0)
-			goto free_uio_res;
-
-		map_idx++;
-	}
-
-	uio_res->nb_maps = map_idx;
-
-	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
-
-	return 0;
-
-free_uio_res:
-	for (i = 0; i < map_idx; i++) {
-		pci_unmap_resource(uio_res->maps[i].addr,
-				(size_t)uio_res->maps[i].size);
-		rte_free(uio_res->maps[i].path);
-	}
-	rte_free(uio_res);
-
-	/* close fd opened by pci_uio_alloc_resource() */
-	if (dev->intr_handle.uio_cfg_fd >= 0) {
-		close(dev->intr_handle.uio_cfg_fd);
-		dev->intr_handle.uio_cfg_fd = -1;
-	}
-
-	close(dev->intr_handle.fd);
-	dev->intr_handle.fd = -1;
-	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
-
-	return -1;
-}
-
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
-static void
-pci_uio_unmap(struct mapped_pci_resource *uio_res)
-{
-	int i;
-
-	if (uio_res == NULL)
-		return;
-
-	for (i = 0; i != uio_res->nb_maps; i++) {
-		pci_unmap_resource(uio_res->maps[i].addr,
-				(size_t)uio_res->maps[i].size);
-		rte_free(uio_res->maps[i].path);
-	}
-}
-
-static struct mapped_pci_resource *
-pci_uio_find_resource(struct rte_pci_device *dev)
-{
-	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list =
-			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
-
-	if (dev == NULL)
-		return NULL;
-
-	TAILQ_FOREACH(uio_res, uio_res_list, next) {
-
-		/* skip this element if it doesn't match our PCI address */
-		if (!rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr))
-			return uio_res;
-	}
-	return NULL;
-}
-
-/* unmap the PCI resource of a PCI device in virtual memory */
-void
-pci_uio_unmap_resource(struct rte_pci_device *dev)
-{
-	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list =
-			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
-
-	if (dev == NULL)
-		return;
-
-	/* find an entry for the device */
-	uio_res = pci_uio_find_resource(dev);
-	if (uio_res == NULL)
-		return;
-
-	/* secondary processes - just free maps */
-	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
-		return pci_uio_unmap(uio_res);
-
-	TAILQ_REMOVE(uio_res_list, uio_res, next);
-
-	/* unmap all resources */
-	pci_uio_unmap(uio_res);
-
-	/* free uio resource */
-	rte_free(uio_res);
-
-	/* close fd if in primary process */
-	close(dev->intr_handle.fd);
-	dev->intr_handle.fd = -1;
-
-	/* close cfg_fd if in primary process */
-	close(dev->intr_handle.uio_cfg_fd);
-	dev->intr_handle.uio_cfg_fd = -1;
-
-	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
-}
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v7 11/12] eal: Consolidate pci_map/unmap_device() of linuxapp and bsdapp
  2015-06-30  8:24           ` [dpdk-dev] [PATCH v7 00/12] Clean up pci uio implementations Tetsuya Mukawa
                               ` (9 preceding siblings ...)
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 10/12] eal: Consolidate pci uio functions " Tetsuya Mukawa
@ 2015-06-30  8:24             ` Tetsuya Mukawa
  2015-06-30 14:45               ` Iremonger, Bernard
                                 ` (2 more replies)
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 12/12] eal: Consolidate rte_eal_pci_probe/close_one_driver() of linuxapp and bsdapp Tetsuya Mukawa
  2015-07-02 11:32             ` [dpdk-dev] [PATCH v7 00/12] Clean up pci uio implementations Bruce Richardson
  12 siblings, 3 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-06-30  8:24 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

The patch consolidates below functions, and implemented in common
eal code.
 - pci_map_device()
 - pci_unmap_device()

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c     |  3 ++
 lib/librte_eal/common/eal_common_pci.c  | 57 +++++++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_private.h     | 19 +++++++++++
 lib/librte_eal/common/include/rte_pci.h |  1 +
 lib/librte_eal/linuxapp/eal/eal_pci.c   | 53 ------------------------------
 lib/librte_ether/rte_ethdev.c           |  1 +
 6 files changed, 81 insertions(+), 53 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 329c268..c057f6a 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -238,6 +238,9 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
 	/* FreeBSD has no NUMA support (yet) */
 	dev->numa_node = 0;
 
+	/* FreeBSD has only one pass through driver */
+	dev->kdrv = RTE_KDRV_NIC_UIO;
+
 	/* parse resources */
 	switch (conf->pc_hdr & PCIM_HDRTYPE) {
 	case PCIM_HDRTYPE_NORMAL:
diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 81b8fd6..c0be292 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -137,6 +137,63 @@ pci_unmap_resource(void *requested_addr, size_t size)
 				requested_addr);
 }
 
+/* Map pci device */
+int
+pci_map_device(struct rte_pci_device *dev)
+{
+	int ret = -1;
+
+	/* try mapping the NIC resources using VFIO if it exists */
+	switch (dev->kdrv) {
+	case RTE_KDRV_VFIO:
+#ifdef VFIO_PRESENT
+		if (pci_vfio_is_enabled())
+			ret = pci_vfio_map_resource(dev);
+#endif
+		break;
+	case RTE_KDRV_IGB_UIO:
+	case RTE_KDRV_UIO_GENERIC:
+	case RTE_KDRV_NIC_UIO:
+		/* map resources for devices that use uio */
+		ret = pci_uio_map_resource(dev);
+		break;
+	default:
+		RTE_LOG(DEBUG, EAL, "  Not managed by a supported kernel driver,"
+			" skipped\n");
+		ret = 1;
+		break;
+	}
+
+	return ret;
+}
+
+#ifdef RTE_LIBRTE_EAL_HOTPLUG
+/* Unmap pci device */
+void
+pci_unmap_device(struct rte_pci_device *dev)
+{
+	if (dev == NULL)
+		return;
+
+	/* try unmapping the NIC resources using VFIO if it exists */
+	switch (dev->kdrv) {
+	case RTE_KDRV_VFIO:
+		RTE_LOG(ERR, EAL, "Hotplug doesn't support vfio yet\n");
+		break;
+	case RTE_KDRV_IGB_UIO:
+	case RTE_KDRV_UIO_GENERIC:
+	case RTE_KDRV_NIC_UIO:
+		/* unmap resources for devices that use uio */
+		pci_uio_unmap_resource(dev);
+		break;
+	default:
+		RTE_LOG(DEBUG, EAL, "  Not managed by a supported kernel driver,"
+			" skipped\n");
+		break;
+	}
+}
+#endif /* RTE_LIBRTE_EAL_HOTPLUG */
+
 /*
  * If vendor/device ID match, call the devinit() function of all
  * registered driver for the given device. Return -1 if initialization
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index c3a3fe4..eec396c 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -162,6 +162,25 @@ struct rte_pci_device;
  * @return
  *   0 on success, negative on error
  */
+int pci_map_device(struct rte_pci_device *dev);
+
+#ifdef RTE_LIBRTE_EAL_HOTPLUG
+/**
+ * Unmap this device
+ *
+ * This function is private to EAL.
+ */
+void pci_unmap_device(struct rte_pci_device *dev);
+#endif /* RTE_LIBRTE_EAL_HOTPLUG */
+
+/**
+ * Map this device
+ *
+ * This function is private to EAL.
+ *
+ * @return
+ *   0 on success, negative on error
+ */
 int pci_uio_map_resource(struct rte_pci_device *dev);
 
 #ifdef RTE_LIBRTE_EAL_HOTPLUG
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index 56dcb46..475d2dc 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -148,6 +148,7 @@ enum rte_kernel_driver {
 	RTE_KDRV_IGB_UIO,
 	RTE_KDRV_VFIO,
 	RTE_KDRV_UIO_GENERIC,
+	RTE_KDRV_NIC_UIO,
 };
 
 /**
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index fc99eaa..7e8df7d 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -522,59 +522,6 @@ pci_config_space_set(struct rte_pci_device *dev)
 }
 #endif
 
-static int
-pci_map_device(struct rte_pci_device *dev)
-{
-	int ret = -1;
-
-	/* try mapping the NIC resources using VFIO if it exists */
-	switch (dev->kdrv) {
-	case RTE_KDRV_VFIO:
-#ifdef VFIO_PRESENT
-		if (pci_vfio_is_enabled())
-			ret = pci_vfio_map_resource(dev);
-#endif
-		break;
-	case RTE_KDRV_IGB_UIO:
-	case RTE_KDRV_UIO_GENERIC:
-		/* map resources for devices that use uio */
-		ret = pci_uio_map_resource(dev);
-		break;
-	default:
-		RTE_LOG(DEBUG, EAL, "  Not managed by a supported kernel driver,"
-			" skipped\n");
-		ret = 1;
-		break;
-	}
-
-	return ret;
-}
-
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
-static void
-pci_unmap_device(struct rte_pci_device *dev)
-{
-	if (dev == NULL)
-		return;
-
-	/* try unmapping the NIC resources using VFIO if it exists */
-	switch (dev->kdrv) {
-	case RTE_KDRV_VFIO:
-		RTE_LOG(ERR, EAL, "Hotplug doesn't support vfio yet\n");
-		break;
-	case RTE_KDRV_IGB_UIO:
-	case RTE_KDRV_UIO_GENERIC:
-		/* unmap resources for devices that use uio */
-		pci_uio_unmap_resource(dev);
-		break;
-	default:
-		RTE_LOG(DEBUG, EAL, "  Not managed by a supported kernel driver,"
-			" skipped\n");
-		break;
-	}
-}
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
-
 /*
  * If vendor/device ID match, call the devinit() function of the
  * driver.
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 02cd07f..1822258 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -515,6 +515,7 @@ rte_eth_dev_is_detachable(uint8_t port_id)
 		switch (rte_eth_devices[port_id].pci_dev->kdrv) {
 		case RTE_KDRV_IGB_UIO:
 		case RTE_KDRV_UIO_GENERIC:
+		case RTE_KDRV_NIC_UIO:
 			break;
 		case RTE_KDRV_VFIO:
 		default:
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v7 12/12] eal: Consolidate rte_eal_pci_probe/close_one_driver() of linuxapp and bsdapp
  2015-06-30  8:24           ` [dpdk-dev] [PATCH v7 00/12] Clean up pci uio implementations Tetsuya Mukawa
                               ` (10 preceding siblings ...)
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 11/12] eal: Consolidate pci_map/unmap_device() " Tetsuya Mukawa
@ 2015-06-30  8:24             ` Tetsuya Mukawa
  2015-06-30 14:56               ` Iremonger, Bernard
  2015-07-02 11:32             ` [dpdk-dev] [PATCH v7 00/12] Clean up pci uio implementations Bruce Richardson
  12 siblings, 1 reply; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-06-30  8:24 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

This patch consolidates below functions, and implements these in common
eal code.
 - rte_eal_pci_probe_one_driver()
 - rte_eal_pci_close_one_driver()

Because pci_map_device() is only implemented in linuxapp, the patch
implements it in bsdapp too. This implemented function will be merged to
linuxapp one with later patch.

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c    |  67 +---------------
 lib/librte_eal/common/eal_common_pci.c | 133 +++++++++++++++++++++++++++++-
 lib/librte_eal/common/eal_private.h    |  39 +--------
 lib/librte_eal/linuxapp/eal/eal_pci.c  | 142 +--------------------------------
 4 files changed, 135 insertions(+), 246 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index c057f6a..508cfa7 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -84,7 +84,7 @@
  */
 
 /* unbind kernel driver for this device */
-static int
+int
 pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)
 {
 	RTE_LOG(ERR, EAL, "RTE_PCI_DRV_FORCE_UNBIND flag is not implemented "
@@ -355,71 +355,6 @@ error:
 	return -1;
 }
 
-/*
- * If vendor/device ID match, call the devinit() function of the
- * driver.
- */
-int
-rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dev)
-{
-	const struct rte_pci_id *id_table;
-	int ret;
-
-	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",
-				loc->domain, loc->bus, loc->devid, loc->function,
-				dev->numa_node);
-
-		RTE_LOG(DEBUG, EAL, "  probe driver: %x:%x %s\n", dev->id.vendor_id,
-				dev->id.device_id, dr->name);
-
-		/* no initialization when blacklisted, return without error */
-		if (dev->devargs != NULL &&
-			dev->devargs->type == RTE_DEVTYPE_BLACKLISTED_PCI) {
-
-			RTE_LOG(DEBUG, EAL, "  Device is blacklisted, not initializing\n");
-			return 0;
-		}
-
-		if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) {
-			/* map resources for devices that use igb_uio */
-			ret = pci_uio_map_resource(dev);
-			if (ret != 0)
-				return ret;
-		} else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND &&
-		           rte_eal_process_type() == RTE_PROC_PRIMARY) {
-			/* unbind current driver */
-			if (pci_unbind_kernel_driver(dev) < 0)
-				return -1;
-		}
-
-		/* reference driver structure */
-		dev->driver = dr;
-
-		/* call the driver devinit() function */
-		return dr->devinit(dr, dev);
-	}
-	/* return positive value if driver is not found */
-	return 1;
-}
-
 /* Init the PCI EAL subsystem */
 int
 rte_eal_pci_init(void)
diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index c0be292..8ef8057 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -138,7 +138,7 @@ pci_unmap_resource(void *requested_addr, size_t size)
 }
 
 /* Map pci device */
-int
+static int
 pci_map_device(struct rte_pci_device *dev)
 {
 	int ret = -1;
@@ -169,7 +169,7 @@ pci_map_device(struct rte_pci_device *dev)
 
 #ifdef RTE_LIBRTE_EAL_HOTPLUG
 /* Unmap pci device */
-void
+static void
 pci_unmap_device(struct rte_pci_device *dev)
 {
 	if (dev == NULL)
@@ -195,6 +195,135 @@ pci_unmap_device(struct rte_pci_device *dev)
 #endif /* RTE_LIBRTE_EAL_HOTPLUG */
 
 /*
+ * 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;
+	const struct rte_pci_id *id_table;
+
+	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",
+				loc->domain, loc->bus, loc->devid, loc->function,
+				dev->numa_node);
+
+		RTE_LOG(DEBUG, EAL, "  probe driver: %x:%x %s\n", dev->id.vendor_id,
+				dev->id.device_id, dr->name);
+
+		/* no initialization when blacklisted, return without error */
+		if (dev->devargs != NULL &&
+			dev->devargs->type == RTE_DEVTYPE_BLACKLISTED_PCI) {
+			RTE_LOG(DEBUG, EAL, "  Device is blacklisted, not initializing\n");
+			return 1;
+		}
+
+		if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) {
+#ifdef RTE_PCI_CONFIG
+			/*
+			 * Set PCIe config space for high performance.
+			 * Return value can be ignored.
+			 */
+			pci_config_space_set(dev);
+#endif
+			/* map resources for devices that use igb_uio */
+			ret = pci_map_device(dev);
+			if (ret != 0)
+				return ret;
+		} else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND &&
+				rte_eal_process_type() == RTE_PROC_PRIMARY) {
+			/* unbind current driver */
+			if (pci_unbind_kernel_driver(dev) < 0)
+				return -1;
+		}
+
+		/* reference driver structure */
+		dev->driver = dr;
+
+		/* call the driver devinit() function */
+		return dr->devinit(dr, dev);
+	}
+	/* return positive value if driver is not found */
+	return 1;
+}
+
+#ifdef RTE_LIBRTE_EAL_HOTPLUG
+/*
+ * If vendor/device ID match, call the devuninit() function of the
+ * driver.
+ */
+static int
+rte_eal_pci_close_one_driver(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",
+				loc->domain, loc->bus, loc->devid,
+				loc->function, dev->numa_node);
+
+		RTE_LOG(DEBUG, EAL, "  remove driver: %x:%x %s\n", dev->id.vendor_id,
+				dev->id.device_id, dr->name);
+
+		/* call the driver devuninit() function */
+		if (dr->devuninit && (dr->devuninit(dev) < 0))
+			return -1;	/* negative value is an error */
+
+		/* clear driver structure */
+		dev->driver = NULL;
+
+		if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING)
+			/* unmap resources for devices that use igb_uio */
+			pci_unmap_device(dev);
+
+		return 0;
+	}
+
+	/* return positive value if driver is not found */
+	return 1;
+}
+#endif /* RTE_LIBRTE_EAL_HOTPLUG */
+
+/*
  * 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.
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index eec396c..216c098 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -155,23 +155,14 @@ struct rte_pci_driver;
 struct rte_pci_device;
 
 /**
- * Map this device
+ * Unbind kernel driver for this device
  *
  * This function is private to EAL.
  *
  * @return
  *   0 on success, negative on error
  */
-int pci_map_device(struct rte_pci_device *dev);
-
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
-/**
- * Unmap this device
- *
- * This function is private to EAL.
- */
-void pci_unmap_device(struct rte_pci_device *dev);
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
+int pci_unbind_kernel_driver(struct rte_pci_device *dev);
 
 /**
  * Map this device
@@ -193,32 +184,6 @@ void pci_uio_unmap_resource(struct rte_pci_device *dev);
 #endif /* RTE_LIBRTE_EAL_HOTPLUG */
 
 /**
- * Mmap memory for single PCI device
- *
- * This function is private to EAL.
- *
- * @return
- *   0 on success, negative on error
- */
-int rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr,
-		struct rte_pci_device *dev);
-
-/**
- * Munmap memory for single PCI device
- *
- * This function is private to EAL.
- *
- * @param	dr
- *  The pointer to the pci driver structure
- * @param	dev
- *  The pointer to the pci device structure
- * @return
- *   0 on success, negative on error
- */
-int rte_eal_pci_close_one_driver(struct rte_pci_driver *dr,
-		struct rte_pci_device *dev);
-
-/**
  * Allocate uio resource for PCI device
  *
  * 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 7e8df7d..1d5a13b 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -56,7 +56,7 @@
  */
 
 /* unbind kernel driver for this device */
-static int
+int
 pci_unbind_kernel_driver(struct rte_pci_device *dev)
 {
 	int n;
@@ -522,146 +522,6 @@ pci_config_space_set(struct rte_pci_device *dev)
 }
 #endif
 
-/*
- * If vendor/device ID match, call the devinit() function of the
- * driver.
- */
-int
-rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, 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++) {
-
-		/* 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",
-				loc->domain, loc->bus, loc->devid, loc->function,
-				dev->numa_node);
-
-		RTE_LOG(DEBUG, EAL, "  probe driver: %x:%x %s\n", dev->id.vendor_id,
-				dev->id.device_id, dr->name);
-
-		/* no initialization when blacklisted, return without error */
-		if (dev->devargs != NULL &&
-			dev->devargs->type == RTE_DEVTYPE_BLACKLISTED_PCI) {
-			RTE_LOG(DEBUG, EAL, "  Device is blacklisted, not initializing\n");
-			return 1;
-		}
-
-		if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) {
-#ifdef RTE_PCI_CONFIG
-			/*
-			 * Set PCIe config space for high performance.
-			 * Return value can be ignored.
-			 */
-			pci_config_space_set(dev);
-#endif
-			/* map resources for devices that use igb_uio */
-			ret = pci_map_device(dev);
-			if (ret != 0)
-				return ret;
-		} else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND &&
-		           rte_eal_process_type() == RTE_PROC_PRIMARY) {
-			/* unbind current driver */
-			if (pci_unbind_kernel_driver(dev) < 0)
-				return -1;
-		}
-
-		/* reference driver structure */
-		dev->driver = dr;
-
-		/* call the driver devinit() function */
-		return dr->devinit(dr, dev);
-	}
-	/* return positive value if driver is not found */
-	return 1;
-}
-
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
-/*
- * If vendor/device ID match, call the devuninit() function of the
- * driver.
- */
-int
-rte_eal_pci_close_one_driver(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",
-				loc->domain, loc->bus, loc->devid,
-				loc->function, dev->numa_node);
-
-		RTE_LOG(DEBUG, EAL, "  remove driver: %x:%x %s\n",
-				dev->id.vendor_id, dev->id.device_id,
-				dr->name);
-
-		/* call the driver devuninit() function */
-		if (dr->devuninit && (dr->devuninit(dev) < 0))
-			return -1;	/* negative value is an error */
-
-		/* clear driver structure */
-		dev->driver = NULL;
-
-		if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING)
-			/* unmap resources for devices that use igb_uio */
-			pci_unmap_device(dev);
-
-		return 0;
-	}
-	/* return positive value if driver is not found */
-	return 1;
-}
-#else /* RTE_LIBRTE_EAL_HOTPLUG */
-int
-rte_eal_pci_close_one_driver(struct rte_pci_driver *dr __rte_unused,
-		struct rte_pci_device *dev __rte_unused)
-{
-	RTE_LOG(ERR, EAL, "Hotplug support isn't enabled\n");
-	return -1;
-}
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
-
 /* Init the PCI EAL subsystem */
 int
 rte_eal_pci_init(void)
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v7 03/12] eal: Fix memory leaks and needless increment of pci_map_addr
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 03/12] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
@ 2015-06-30 12:33               ` Iremonger, Bernard
  2015-07-02  9:57               ` Bruce Richardson
  1 sibling, 0 replies; 120+ messages in thread
From: Iremonger, Bernard @ 2015-06-30 12:33 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev

> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Tuesday, June 30, 2015 9:24 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; david.marchand@6wind.com; Richardson, Bruce;
> Tetsuya.Mukawa
> Subject: [PATCH v7 03/12] eal: Fix memory leaks and needless increment of
> pci_map_addr
> 
> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
> 
> This patch fixes following memory leaks.
> - When open() is failed, uio_res and fds won't be freed in
>   pci_uio_map_resource().
> - When pci_map_resource() is failed but path is allocated correctly,
>   path and fds won't be freed in pci_uio_map_recource().
>   Also, some mapped resources should be freed.
> - When pci_uio_unmap() is called, path should be freed.
> 
> Also, fixes below.
> - When pci_map_resource() is failed, mapaddr will be MAP_FAILED.
>   In this case, pci_map_addr should not be incremented in
>   pci_uio_map_resource().
> - To shrink code, move close().
> - Remove fail variable.
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
Acked-by:  Bernard Iremonger <Bernard.iremonger@intel.com>

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v7 04/12] eal/bsdapp: Change names of pci related data structure
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 04/12] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
@ 2015-06-30 12:36               ` Iremonger, Bernard
  0 siblings, 0 replies; 120+ messages in thread
From: Iremonger, Bernard @ 2015-06-30 12:36 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev

> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Tuesday, June 30, 2015 9:24 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; david.marchand@6wind.com; Richardson, Bruce;
> Tetsuya.Mukawa
> Subject: [PATCH v7 04/12] eal/bsdapp: Change names of pci related data
> structure
> 
> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
> 
> To merge pci code of linuxapp and bsdapp, this patch changes names like
> below.
>  - uio_map to pci_map
>  - uio_resource to mapped_pci_resource
>  - uio_res_list to mapped_pci_res_list
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
Acked-by: Bernard Iremonger <bernard.iremonger@intel.com>

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v7 05/12] eal: Fix uio mapping differences between linuxapp and bsdapp
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 05/12] eal: Fix uio mapping differences between linuxapp and bsdapp Tetsuya Mukawa
@ 2015-06-30 12:51               ` Iremonger, Bernard
  2015-07-02 10:20               ` Bruce Richardson
  1 sibling, 0 replies; 120+ messages in thread
From: Iremonger, Bernard @ 2015-06-30 12:51 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev

> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Tuesday, June 30, 2015 9:24 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; david.marchand@6wind.com; Richardson, Bruce;
> Tetsuya.Mukawa
> Subject: [PATCH v7 05/12] eal: Fix uio mapping differences between linuxapp
> and bsdapp
> 
> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
> 
> This patch fixes below.
> - bsdapp
>  - Use map_id in pci_uio_map_resource().
>  - Fix interface of pci_map_resource().
>  - Move path variable of mapped_pci_resource structure to pci_map.
> - linuxapp
>  - Remove redundant error message of linuxapp.
> 
> 'pci_uio_map_resource()' is implemented in both linuxapp and bsdapp, but
> interface is different. The patch fixes the function of bsdapp to do same as
> linuxapp. After applying it, file descriptor should be opened and closed out of
> pci_map_resource().
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
Acked-by: Bernard Iremonger <bernard.iremonger@intel.com>

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v7 08/12] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 08/12] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp Tetsuya Mukawa
@ 2015-06-30 14:25               ` Iremonger, Bernard
  0 siblings, 0 replies; 120+ messages in thread
From: Iremonger, Bernard @ 2015-06-30 14:25 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev



> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Tuesday, June 30, 2015 9:24 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; david.marchand@6wind.com; Richardson, Bruce;
> Tetsuya.Mukawa
> Subject: [PATCH v7 08/12] eal: Consolidate pci_map and
> mapped_pci_resource of linuxapp and bsdapp
> 
> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
> 
> This patch consolidates below structures, and defines them in common code.
>  - struct pci_map
>  - strucy mapped_pci_resouces
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
Acked-by: Bernard Iremonger <bernard.iremonger@intel.com>

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v7 09/12] eal: Consolidate pci_map/unmap_resource() of linuxapp and bsdapp
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 09/12] eal: Consolidate pci_map/unmap_resource() " Tetsuya Mukawa
@ 2015-06-30 14:28               ` Iremonger, Bernard
  2015-07-02 11:11               ` Bruce Richardson
  1 sibling, 0 replies; 120+ messages in thread
From: Iremonger, Bernard @ 2015-06-30 14:28 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev

> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Tuesday, June 30, 2015 9:24 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; david.marchand@6wind.com; Richardson, Bruce;
> Tetsuya.Mukawa
> Subject: [PATCH v7 09/12] eal: Consolidate pci_map/unmap_resource() of
> linuxapp and bsdapp
> 
> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
> 
> The patch consolidates below functions, and implemented in common eal
> code.
>  - pci_map_resource()
>  - pci_unmap_resource()
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
Acked-by: Bernard Iremonger <Bernard.iremonger@intel.com>

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v7 11/12] eal: Consolidate pci_map/unmap_device() of linuxapp and bsdapp
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 11/12] eal: Consolidate pci_map/unmap_device() " Tetsuya Mukawa
@ 2015-06-30 14:45               ` Iremonger, Bernard
  2015-07-06  6:24               ` [dpdk-dev] [PATCH v8 00/12] Clean up pci uio implementations Tetsuya Mukawa
  2015-07-08 10:34               ` [dpdk-dev] [PATCH v9 00/12] Clean up pci uio implementations Tetsuya Mukawa
  2 siblings, 0 replies; 120+ messages in thread
From: Iremonger, Bernard @ 2015-06-30 14:45 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev



> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Tuesday, June 30, 2015 9:24 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; david.marchand@6wind.com; Richardson, Bruce;
> Tetsuya.Mukawa
> Subject: [PATCH v7 11/12] eal: Consolidate pci_map/unmap_device() of
> linuxapp and bsdapp
> 
> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
> 
> The patch consolidates below functions, and implemented in common eal
> code.
>  - pci_map_device()
>  - pci_unmap_device()
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
Acked-by: Bernard Iremonger <Bernard.iremonger@intel.com>

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v7 12/12] eal: Consolidate rte_eal_pci_probe/close_one_driver() of linuxapp and bsdapp
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 12/12] eal: Consolidate rte_eal_pci_probe/close_one_driver() of linuxapp and bsdapp Tetsuya Mukawa
@ 2015-06-30 14:56               ` Iremonger, Bernard
  2015-07-01  6:39                 ` Tetsuya Mukawa
  0 siblings, 1 reply; 120+ messages in thread
From: Iremonger, Bernard @ 2015-06-30 14:56 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev

> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Tuesday, June 30, 2015 9:24 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; david.marchand@6wind.com; Richardson, Bruce;
> Tetsuya.Mukawa
> Subject: [PATCH v7 12/12] eal: Consolidate
> rte_eal_pci_probe/close_one_driver() of linuxapp and bsdapp
> 
> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
> 
> This patch consolidates below functions, and implements these in common
> eal code.
>  - rte_eal_pci_probe_one_driver()
>  - rte_eal_pci_close_one_driver()
> 
> Because pci_map_device() is only implemented in linuxapp, the patch
> implements it in bsdapp too. This implemented function will be merged to
> linuxapp one with later patch.

Hi Tetsuya,

The description lines above seem to be out of date now as pci_map_device() is not implemented in the bsdapp now.

Regards,

Bernard.

> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  lib/librte_eal/bsdapp/eal/eal_pci.c    |  67 +---------------
>  lib/librte_eal/common/eal_common_pci.c | 133
> +++++++++++++++++++++++++++++-
>  lib/librte_eal/common/eal_private.h    |  39 +--------
>  lib/librte_eal/linuxapp/eal/eal_pci.c  | 142 +--------------------------------
>  4 files changed, 135 insertions(+), 246 deletions(-)
> 
> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c
> b/lib/librte_eal/bsdapp/eal/eal_pci.c
> index c057f6a..508cfa7 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> @@ -84,7 +84,7 @@
>   */
> 
>  /* unbind kernel driver for this device */ -static int
> +int
>  pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)  {
>  	RTE_LOG(ERR, EAL, "RTE_PCI_DRV_FORCE_UNBIND flag is not
> implemented "
> @@ -355,71 +355,6 @@ error:
>  	return -1;
>  }
> 
> -/*
> - * If vendor/device ID match, call the devinit() function of the
> - * driver.
> - */
> -int
> -rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct
> rte_pci_device *dev) -{
> -	const struct rte_pci_id *id_table;
> -	int ret;
> -
> -	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",
> -				loc->domain, loc->bus, loc->devid, loc-
> >function,
> -				dev->numa_node);
> -
> -		RTE_LOG(DEBUG, EAL, "  probe driver: %x:%x %s\n", dev-
> >id.vendor_id,
> -				dev->id.device_id, dr->name);
> -
> -		/* no initialization when blacklisted, return without error */
> -		if (dev->devargs != NULL &&
> -			dev->devargs->type ==
> RTE_DEVTYPE_BLACKLISTED_PCI) {
> -
> -			RTE_LOG(DEBUG, EAL, "  Device is blacklisted, not
> initializing\n");
> -			return 0;
> -		}
> -
> -		if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) {
> -			/* map resources for devices that use igb_uio */
> -			ret = pci_uio_map_resource(dev);
> -			if (ret != 0)
> -				return ret;
> -		} else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND &&
> -		           rte_eal_process_type() == RTE_PROC_PRIMARY) {
> -			/* unbind current driver */
> -			if (pci_unbind_kernel_driver(dev) < 0)
> -				return -1;
> -		}
> -
> -		/* reference driver structure */
> -		dev->driver = dr;
> -
> -		/* call the driver devinit() function */
> -		return dr->devinit(dr, dev);
> -	}
> -	/* return positive value if driver is not found */
> -	return 1;
> -}
> -
>  /* Init the PCI EAL subsystem */
>  int
>  rte_eal_pci_init(void)
> diff --git a/lib/librte_eal/common/eal_common_pci.c
> b/lib/librte_eal/common/eal_common_pci.c
> index c0be292..8ef8057 100644
> --- a/lib/librte_eal/common/eal_common_pci.c
> +++ b/lib/librte_eal/common/eal_common_pci.c
> @@ -138,7 +138,7 @@ pci_unmap_resource(void *requested_addr, size_t
> size)  }
> 
>  /* Map pci device */
> -int
> +static int
>  pci_map_device(struct rte_pci_device *dev)  {
>  	int ret = -1;
> @@ -169,7 +169,7 @@ pci_map_device(struct rte_pci_device *dev)
> 
>  #ifdef RTE_LIBRTE_EAL_HOTPLUG
>  /* Unmap pci device */
> -void
> +static void
>  pci_unmap_device(struct rte_pci_device *dev)  {
>  	if (dev == NULL)
> @@ -195,6 +195,135 @@ pci_unmap_device(struct rte_pci_device *dev)
> #endif /* RTE_LIBRTE_EAL_HOTPLUG */
> 
>  /*
> + * 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;
> +	const struct rte_pci_id *id_table;
> +
> +	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",
> +				loc->domain, loc->bus, loc->devid, loc-
> >function,
> +				dev->numa_node);
> +
> +		RTE_LOG(DEBUG, EAL, "  probe driver: %x:%x %s\n", dev-
> >id.vendor_id,
> +				dev->id.device_id, dr->name);
> +
> +		/* no initialization when blacklisted, return without error */
> +		if (dev->devargs != NULL &&
> +			dev->devargs->type ==
> RTE_DEVTYPE_BLACKLISTED_PCI) {
> +			RTE_LOG(DEBUG, EAL, "  Device is blacklisted, not
> initializing\n");
> +			return 1;
> +		}
> +
> +		if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) { #ifdef
> RTE_PCI_CONFIG
> +			/*
> +			 * Set PCIe config space for high performance.
> +			 * Return value can be ignored.
> +			 */
> +			pci_config_space_set(dev);
> +#endif
> +			/* map resources for devices that use igb_uio */
> +			ret = pci_map_device(dev);
> +			if (ret != 0)
> +				return ret;
> +		} else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND &&
> +				rte_eal_process_type() ==
> RTE_PROC_PRIMARY) {
> +			/* unbind current driver */
> +			if (pci_unbind_kernel_driver(dev) < 0)
> +				return -1;
> +		}
> +
> +		/* reference driver structure */
> +		dev->driver = dr;
> +
> +		/* call the driver devinit() function */
> +		return dr->devinit(dr, dev);
> +	}
> +	/* return positive value if driver is not found */
> +	return 1;
> +}
> +
> +#ifdef RTE_LIBRTE_EAL_HOTPLUG
> +/*
> + * If vendor/device ID match, call the devuninit() function of the
> + * driver.
> + */
> +static int
> +rte_eal_pci_close_one_driver(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",
> +				loc->domain, loc->bus, loc->devid,
> +				loc->function, dev->numa_node);
> +
> +		RTE_LOG(DEBUG, EAL, "  remove driver: %x:%x %s\n", dev-
> >id.vendor_id,
> +				dev->id.device_id, dr->name);
> +
> +		/* call the driver devuninit() function */
> +		if (dr->devuninit && (dr->devuninit(dev) < 0))
> +			return -1;	/* negative value is an error */
> +
> +		/* clear driver structure */
> +		dev->driver = NULL;
> +
> +		if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING)
> +			/* unmap resources for devices that use igb_uio */
> +			pci_unmap_device(dev);
> +
> +		return 0;
> +	}
> +
> +	/* return positive value if driver is not found */
> +	return 1;
> +}
> +#endif /* RTE_LIBRTE_EAL_HOTPLUG */
> +
> +/*
>   * 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.
> diff --git a/lib/librte_eal/common/eal_private.h
> b/lib/librte_eal/common/eal_private.h
> index eec396c..216c098 100644
> --- a/lib/librte_eal/common/eal_private.h
> +++ b/lib/librte_eal/common/eal_private.h
> @@ -155,23 +155,14 @@ struct rte_pci_driver;  struct rte_pci_device;
> 
>  /**
> - * Map this device
> + * Unbind kernel driver for this device
>   *
>   * This function is private to EAL.
>   *
>   * @return
>   *   0 on success, negative on error
>   */
> -int pci_map_device(struct rte_pci_device *dev);
> -
> -#ifdef RTE_LIBRTE_EAL_HOTPLUG
> -/**
> - * Unmap this device
> - *
> - * This function is private to EAL.
> - */
> -void pci_unmap_device(struct rte_pci_device *dev); -#endif /*
> RTE_LIBRTE_EAL_HOTPLUG */
> +int pci_unbind_kernel_driver(struct rte_pci_device *dev);
> 
>  /**
>   * Map this device
> @@ -193,32 +184,6 @@ void pci_uio_unmap_resource(struct rte_pci_device
> *dev);  #endif /* RTE_LIBRTE_EAL_HOTPLUG */
> 
>  /**
> - * Mmap memory for single PCI device
> - *
> - * This function is private to EAL.
> - *
> - * @return
> - *   0 on success, negative on error
> - */
> -int rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr,
> -		struct rte_pci_device *dev);
> -
> -/**
> - * Munmap memory for single PCI device
> - *
> - * This function is private to EAL.
> - *
> - * @param	dr
> - *  The pointer to the pci driver structure
> - * @param	dev
> - *  The pointer to the pci device structure
> - * @return
> - *   0 on success, negative on error
> - */
> -int rte_eal_pci_close_one_driver(struct rte_pci_driver *dr,
> -		struct rte_pci_device *dev);
> -
> -/**
>   * Allocate uio resource for PCI device
>   *
>   * 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 7e8df7d..1d5a13b 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_pci.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
> @@ -56,7 +56,7 @@
>   */
> 
>  /* unbind kernel driver for this device */ -static int
> +int
>  pci_unbind_kernel_driver(struct rte_pci_device *dev)  {
>  	int n;
> @@ -522,146 +522,6 @@ pci_config_space_set(struct rte_pci_device *dev)
> }  #endif
> 
> -/*
> - * If vendor/device ID match, call the devinit() function of the
> - * driver.
> - */
> -int
> -rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, 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++) {
> -
> -		/* 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",
> -				loc->domain, loc->bus, loc->devid, loc-
> >function,
> -				dev->numa_node);
> -
> -		RTE_LOG(DEBUG, EAL, "  probe driver: %x:%x %s\n", dev-
> >id.vendor_id,
> -				dev->id.device_id, dr->name);
> -
> -		/* no initialization when blacklisted, return without error */
> -		if (dev->devargs != NULL &&
> -			dev->devargs->type ==
> RTE_DEVTYPE_BLACKLISTED_PCI) {
> -			RTE_LOG(DEBUG, EAL, "  Device is blacklisted, not
> initializing\n");
> -			return 1;
> -		}
> -
> -		if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) {
> -#ifdef RTE_PCI_CONFIG
> -			/*
> -			 * Set PCIe config space for high performance.
> -			 * Return value can be ignored.
> -			 */
> -			pci_config_space_set(dev);
> -#endif
> -			/* map resources for devices that use igb_uio */
> -			ret = pci_map_device(dev);
> -			if (ret != 0)
> -				return ret;
> -		} else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND &&
> -		           rte_eal_process_type() == RTE_PROC_PRIMARY) {
> -			/* unbind current driver */
> -			if (pci_unbind_kernel_driver(dev) < 0)
> -				return -1;
> -		}
> -
> -		/* reference driver structure */
> -		dev->driver = dr;
> -
> -		/* call the driver devinit() function */
> -		return dr->devinit(dr, dev);
> -	}
> -	/* return positive value if driver is not found */
> -	return 1;
> -}
> -
> -#ifdef RTE_LIBRTE_EAL_HOTPLUG
> -/*
> - * If vendor/device ID match, call the devuninit() function of the
> - * driver.
> - */
> -int
> -rte_eal_pci_close_one_driver(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",
> -				loc->domain, loc->bus, loc->devid,
> -				loc->function, dev->numa_node);
> -
> -		RTE_LOG(DEBUG, EAL, "  remove driver: %x:%x %s\n",
> -				dev->id.vendor_id, dev->id.device_id,
> -				dr->name);
> -
> -		/* call the driver devuninit() function */
> -		if (dr->devuninit && (dr->devuninit(dev) < 0))
> -			return -1;	/* negative value is an error */
> -
> -		/* clear driver structure */
> -		dev->driver = NULL;
> -
> -		if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING)
> -			/* unmap resources for devices that use igb_uio */
> -			pci_unmap_device(dev);
> -
> -		return 0;
> -	}
> -	/* return positive value if driver is not found */
> -	return 1;
> -}
> -#else /* RTE_LIBRTE_EAL_HOTPLUG */
> -int
> -rte_eal_pci_close_one_driver(struct rte_pci_driver *dr __rte_unused,
> -		struct rte_pci_device *dev __rte_unused)
> -{
> -	RTE_LOG(ERR, EAL, "Hotplug support isn't enabled\n");
> -	return -1;
> -}
> -#endif /* RTE_LIBRTE_EAL_HOTPLUG */
> -
>  /* Init the PCI EAL subsystem */
>  int
>  rte_eal_pci_init(void)
> --
> 2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v7 12/12] eal: Consolidate rte_eal_pci_probe/close_one_driver() of linuxapp and bsdapp
  2015-06-30 14:56               ` Iremonger, Bernard
@ 2015-07-01  6:39                 ` Tetsuya Mukawa
  0 siblings, 0 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-01  6:39 UTC (permalink / raw)
  To: Iremonger, Bernard, dev

On 2015/06/30 23:56, Iremonger, Bernard wrote:
>> -----Original Message-----
>> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
>> Sent: Tuesday, June 30, 2015 9:24 AM
>> To: dev@dpdk.org
>> Cc: Iremonger, Bernard; david.marchand@6wind.com; Richardson, Bruce;
>> Tetsuya.Mukawa
>> Subject: [PATCH v7 12/12] eal: Consolidate
>> rte_eal_pci_probe/close_one_driver() of linuxapp and bsdapp
>>
>> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
>>
>> This patch consolidates below functions, and implements these in common
>> eal code.
>>  - rte_eal_pci_probe_one_driver()
>>  - rte_eal_pci_close_one_driver()
>>
>> Because pci_map_device() is only implemented in linuxapp, the patch
>> implements it in bsdapp too. This implemented function will be merged to
>> linuxapp one with later patch.
> Hi Tetsuya,
>
> The description lines above seem to be out of date now as pci_map_device() is not implemented in the bsdapp now.
>
> Regards,
>
> Bernard.
>

Hi Bernard,

Yes, I needed to be change above description.
I will fix it in next patch series.

Regards,
Tetsuya

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v7 03/12] eal: Fix memory leaks and needless increment of pci_map_addr
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 03/12] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
  2015-06-30 12:33               ` Iremonger, Bernard
@ 2015-07-02  9:57               ` Bruce Richardson
  2015-07-03  8:51                 ` Tetsuya Mukawa
  1 sibling, 1 reply; 120+ messages in thread
From: Bruce Richardson @ 2015-07-02  9:57 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Tue, Jun 30, 2015 at 05:24:19PM +0900, Tetsuya Mukawa wrote:
> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
> 
> This patch fixes following memory leaks.
> - When open() is failed, uio_res and fds won't be freed in
>   pci_uio_map_resource().
> - When pci_map_resource() is failed but path is allocated correctly,
>   path and fds won't be freed in pci_uio_map_recource().
>   Also, some mapped resources should be freed.
> - When pci_uio_unmap() is called, path should be freed.
> 
> Also, fixes below.
> - When pci_map_resource() is failed, mapaddr will be MAP_FAILED.
>   In this case, pci_map_addr should not be incremented in
>   pci_uio_map_resource().
> - To shrink code, move close().
> - Remove fail variable.
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>

Couple of minor comments inline below.

/Bruce

> ---
>  lib/librte_eal/bsdapp/eal/eal_pci.c       | 14 ++++++--
>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 56 ++++++++++++++++++++-----------
>  2 files changed, 48 insertions(+), 22 deletions(-)
> 
> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
> index 8e24fd1..b071f07 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> @@ -235,7 +235,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  	if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) == NULL) {
>  		RTE_LOG(ERR, EAL,
>  			"%s(): cannot store uio mmap details\n", __func__);
> -		return -1;
> +		goto close_fd;
>  	}
>  
>  	snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
> @@ -262,8 +262,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  		    (mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
>  						(size_t)maps[j].size)
>  		    ) == NULL) {
> -			rte_free(uio_res);
> -			return -1;
> +			goto free_uio_res;
>  		}
>  
>  		maps[j].addr = mapaddr;
> @@ -274,6 +273,15 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
>  
>  	return 0;
> +
> +free_uio_res:
> +	rte_free(uio_res);
If you initialize uio_res to NULL when it is defined, you can get rid of the
distinction between "free_uio_res" and "close_fd" labels. 

Similarly, if you check for a valid dev->intr_handle.fd value before close, you can have a 
generic "error" leg, and replace all return -1's with goto error. While not as
useful as merging the labels, it might be something to consider.

> +close_fd:
> +	close(dev->intr_handle.fd);
> +	dev->intr_handle.fd = -1;
> +	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
> +
> +	return -1;
>  }
>  
>  /* Scan one pci sysfs entry, and fill the devices list from it. */
> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> index 34316b6..c3b259b 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> @@ -308,7 +308,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  	if (dev->intr_handle.uio_cfg_fd < 0) {
>  		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
>  			cfgname, strerror(errno));
> -		return -1;
> +		goto close_fd;
>  	}
>  
>  	if (dev->kdrv == RTE_KDRV_IGB_UIO)
> @@ -319,7 +319,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  		/* set bus master that is not done by uio_pci_generic */
>  		if (pci_uio_set_bus_master(dev->intr_handle.uio_cfg_fd)) {
>  			RTE_LOG(ERR, EAL, "Cannot set up bus mastering!\n");
> -			return -1;
> +			goto close_fd;
>  		}
>  	}
>  
> @@ -328,7 +328,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  	if (uio_res == NULL) {
>  		RTE_LOG(ERR, EAL,
>  			"%s(): cannot store uio mmap details\n", __func__);
> -		return -1;
> +		goto close_fd;
>  	}
>  
>  	snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
> @@ -338,7 +338,6 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  	maps = uio_res->maps;
>  	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
>  		int fd;
> -		int fail = 0;
>  
>  		/* skip empty BAR */
>  		phaddr = dev->mem_resource[i].phys_addr;
> @@ -352,6 +351,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  				loc->domain, loc->bus, loc->devid, loc->function,
>  				i);
>  
> +		/* allocate memory to keep path */
> +		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
> +		if (maps[map_idx].path == NULL)
> +			goto free_uio_res;
> +
>  		/*
>  		 * open resource file, to mmap it
>  		 */
> @@ -359,7 +363,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  		if (fd < 0) {
>  			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
>  					devname, strerror(errno));
> -			return -1;
> +			rte_free(maps[map_idx].path);
> +			goto free_uio_res;
>  		}
>  
>  		/* try mapping somewhere close to the end of hugepages */
> @@ -368,23 +373,15 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  
>  		mapaddr = pci_map_resource(pci_map_addr, fd, 0,
>  				(size_t)dev->mem_resource[i].len, 0);
> -		if (mapaddr == MAP_FAILED)
> -			fail = 1;
> +		close(fd);
> +		if (mapaddr == MAP_FAILED) {
> +			rte_free(maps[map_idx].path);
> +			goto free_uio_res;
> +		}
>  
>  		pci_map_addr = RTE_PTR_ADD(mapaddr,
>  				(size_t)dev->mem_resource[i].len);
>  
> -		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
> -		if (maps[map_idx].path == NULL)
> -			fail = 1;
> -
> -		if (fail) {
> -			rte_free(uio_res);
> -			close(fd);
> -			return -1;
> -		}
> -		close(fd);
> -
>  		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
>  		maps[map_idx].size = dev->mem_resource[i].len;
>  		maps[map_idx].addr = mapaddr;
> @@ -399,6 +396,25 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
>  
>  	return 0;
> +
> +free_uio_res:
> +	for (i = 0; i < map_idx; i++) {

If you move the initialization of map_idx = 0 from the "for" loop to the definition
at the start of the function, you may again be able to merge these two labels
into one.

> +		pci_unmap_resource(uio_res->maps[i].addr,
> +				(size_t)uio_res->maps[i].size);
> +		rte_free(maps[i].path);
> +	}
> +	rte_free(uio_res);
> +close_fd:
> +	if (dev->intr_handle.uio_cfg_fd >= 0) {
> +		close(dev->intr_handle.uio_cfg_fd);
> +		dev->intr_handle.uio_cfg_fd = -1;
> +	}
> +
> +	close(dev->intr_handle.fd);
> +	dev->intr_handle.fd = -1;
> +	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
> +
> +	return -1;
>  }
>  
>  #ifdef RTE_LIBRTE_EAL_HOTPLUG
> @@ -410,9 +426,11 @@ pci_uio_unmap(struct mapped_pci_resource *uio_res)
>  	if (uio_res == NULL)
>  		return;
>  
> -	for (i = 0; i != uio_res->nb_maps; i++)
> +	for (i = 0; i != uio_res->nb_maps; i++) {
>  		pci_unmap_resource(uio_res->maps[i].addr,
>  				(size_t)uio_res->maps[i].size);
> +		rte_free(uio_res->maps[i].path);
> +	}
>  }
>  
>  static struct mapped_pci_resource *
> -- 
> 2.1.4
> 

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v7 05/12] eal: Fix uio mapping differences between linuxapp and bsdapp
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 05/12] eal: Fix uio mapping differences between linuxapp and bsdapp Tetsuya Mukawa
  2015-06-30 12:51               ` Iremonger, Bernard
@ 2015-07-02 10:20               ` Bruce Richardson
  2015-07-03  8:51                 ` Tetsuya Mukawa
  1 sibling, 1 reply; 120+ messages in thread
From: Bruce Richardson @ 2015-07-02 10:20 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Tue, Jun 30, 2015 at 05:24:21PM +0900, Tetsuya Mukawa wrote:
> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
> 
> This patch fixes below.
> - bsdapp
>  - Use map_id in pci_uio_map_resource().
>  - Fix interface of pci_map_resource().
>  - Move path variable of mapped_pci_resource structure to pci_map.
> - linuxapp
>  - Remove redundant error message of linuxapp.
> 
> 'pci_uio_map_resource()' is implemented in both linuxapp and bsdapp,
> but interface is different. The patch fixes the function of bsdapp
> to do same as linuxapp. After applying it, file descriptor should be
> opened and closed out of pci_map_resource().
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  lib/librte_eal/bsdapp/eal/eal_pci.c       | 118 ++++++++++++++++++------------
>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c |  21 +++---
>  2 files changed, 80 insertions(+), 59 deletions(-)
> 
<snip>  
>  free_uio_res:
> +	for (i = 0; i < map_idx; i++)
> +		rte_free(maps[i].path);
>  	rte_free(uio_res);
>  close_fd:
>  	close(dev->intr_handle.fd);

Comments on previous patch about merging error labels would also apply here.

> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> index c3b259b..19620fe 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> @@ -116,17 +116,11 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
>  					fd, (off_t)uio_res->maps[i].offset,
>  					(size_t)uio_res->maps[i].size, 0);
>  			if (mapaddr != uio_res->maps[i].addr) {
> -				if (mapaddr == MAP_FAILED)
> -					RTE_LOG(ERR, EAL,
> -							"Cannot mmap device resource file %s: %s\n",
> -							uio_res->maps[i].path,
> -							strerror(errno));
> -				else
> -					RTE_LOG(ERR, EAL,
> -							"Cannot mmap device resource file %s to address: %p\n",
> -							uio_res->maps[i].path,
> -							uio_res->maps[i].addr);
> -
> +				RTE_LOG(ERR, EAL,
> +						"Cannot mmap device resource "
> +						"file %s to address: %p\n",
> +						uio_res->maps[i].path,
> +						uio_res->maps[i].addr);
>  				close(fd);
>  				return -1;
>  			}
> @@ -353,8 +347,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  
>  		/* allocate memory to keep path */
>  		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
> -		if (maps[map_idx].path == NULL)
> +		if (maps[map_idx].path == NULL) {
> +			RTE_LOG(ERR, EAL, "Cannot allocate memory for "
> +					"path: %s\n", strerror(errno));

It's recommended not to split literal strings across multiple lines. This is
so that it's easy to find error messages in the source code. In this case, because
of the split, someone using git grep to search for the error message 
"Cannot allocate memory for path" 
would not be able to find it in the code. Longer lines are allowed in code for
literal strings.

/Bruce

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v7 06/12] eal: Add pci_uio_alloc_resource()
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 06/12] eal: Add pci_uio_alloc_resource() Tetsuya Mukawa
@ 2015-07-02 10:46               ` Bruce Richardson
  2015-07-03  8:52                 ` Tetsuya Mukawa
  0 siblings, 1 reply; 120+ messages in thread
From: Bruce Richardson @ 2015-07-02 10:46 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Tue, Jun 30, 2015 at 05:24:22PM +0900, Tetsuya Mukawa wrote:
> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
> 
> This patch adds a new function called pci_uio_alloc_resource().
> The function hides how to prepare uio resource in linuxapp and bsdapp.
> With the function, pci_uio_map_resource() will be more abstracted.
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  lib/librte_eal/bsdapp/eal/eal_pci.c       | 70 +++++++++++++++++++---------
>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 77 ++++++++++++++++++++++---------
>  2 files changed, 104 insertions(+), 43 deletions(-)
> 
> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
> index 06c564f..7d2f8b5 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> @@ -189,28 +189,17 @@ 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)
> +pci_uio_alloc_resource(struct rte_pci_device *dev,
> +		struct mapped_pci_resource **uio_res)

Rather than having to pass in a pointer to a pointer, why not change the
return type to be "struct mapped_pci_resource *"? The only return values currently
are 0 and -1, so those could map to non-NULL and NULL respectively, for error
checking.

/Bruce

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v7 09/12] eal: Consolidate pci_map/unmap_resource() of linuxapp and bsdapp
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 09/12] eal: Consolidate pci_map/unmap_resource() " Tetsuya Mukawa
  2015-06-30 14:28               ` Iremonger, Bernard
@ 2015-07-02 11:11               ` Bruce Richardson
  2015-07-03  8:52                 ` Tetsuya Mukawa
  1 sibling, 1 reply; 120+ messages in thread
From: Bruce Richardson @ 2015-07-02 11:11 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Tue, Jun 30, 2015 at 05:24:25PM +0900, Tetsuya Mukawa wrote:
> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
> 
> The patch consolidates below functions, and implemented in common
> eal code.
>  - pci_map_resource()
>  - pci_unmap_resource()
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  lib/librte_eal/bsdapp/eal/eal_pci.c        | 22 ----------------
>  lib/librte_eal/common/eal_common_pci.c     | 39 ++++++++++++++++++++++++++++
>  lib/librte_eal/common/include/rte_pci.h    | 11 ++++++++
>  lib/librte_eal/linuxapp/eal/eal_pci.c      | 41 ------------------------------
>  lib/librte_eal/linuxapp/eal/eal_pci_init.h |  5 ----
>  5 files changed, 50 insertions(+), 68 deletions(-)
>
<snip>
> diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
> index 0a2ef09..56dcb46 100644
> --- a/lib/librte_eal/common/include/rte_pci.h
> +++ b/lib/librte_eal/common/include/rte_pci.h
> @@ -364,6 +364,17 @@ int rte_eal_pci_scan(void);
>   */
>  int rte_eal_pci_probe(void);
>  
> +/**
> + * Map pci resouce.
> + */
> +void *pci_map_resource(void *requested_addr, int fd, off_t offset,
> +		size_t size, int additional_flags);
> +
> +/**
> + * Map pci resouce.
> + */
> +void pci_unmap_resource(void *requested_addr, size_t size);
> +

These functions should probably be marked "@internal", right?

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v7 00/12] Clean up pci uio implementations
  2015-06-30  8:24           ` [dpdk-dev] [PATCH v7 00/12] Clean up pci uio implementations Tetsuya Mukawa
                               ` (11 preceding siblings ...)
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 12/12] eal: Consolidate rte_eal_pci_probe/close_one_driver() of linuxapp and bsdapp Tetsuya Mukawa
@ 2015-07-02 11:32             ` Bruce Richardson
  2015-07-03  8:52               ` Tetsuya Mukawa
  12 siblings, 1 reply; 120+ messages in thread
From: Bruce Richardson @ 2015-07-02 11:32 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Tue, Jun 30, 2015 at 05:24:16PM +0900, Tetsuya Mukawa wrote:
> Currently Linux implementation and BSD implementation have almost same
> code about pci uio. This patch series cleans up it.
> 
Overall, patchset looks a good idea. I've made some comments on some of the
individual patches. Quick test on FreeBSD shows that PCI port scanning and
mapping of the BARs of 82599 NICs works ok.

Tested-by: Bruce Richardson <bruce.richardson@intel.com>

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v7 03/12] eal: Fix memory leaks and needless increment of pci_map_addr
  2015-07-02  9:57               ` Bruce Richardson
@ 2015-07-03  8:51                 ` Tetsuya Mukawa
  0 siblings, 0 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-03  8:51 UTC (permalink / raw)
  To: Bruce Richardson; +Cc: dev

On 2015/07/02 18:57, Bruce Richardson wrote:
> On Tue, Jun 30, 2015 at 05:24:19PM +0900, Tetsuya Mukawa wrote:
>> ---
>>  lib/librte_eal/bsdapp/eal/eal_pci.c       | 14 ++++++--
>>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 56 ++++++++++++++++++++-----------
>>  2 files changed, 48 insertions(+), 22 deletions(-)
>>
>> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
>> index 8e24fd1..b071f07 100644
>> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
>> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
>> @@ -235,7 +235,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>>  	if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) == NULL) {
>>  		RTE_LOG(ERR, EAL,
>>  			"%s(): cannot store uio mmap details\n", __func__);
>> -		return -1;
>> +		goto close_fd;
>>  	}
>>  
>>  	snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
>> @@ -262,8 +262,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>>  		    (mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
>>  						(size_t)maps[j].size)
>>  		    ) == NULL) {
>> -			rte_free(uio_res);
>> -			return -1;
>> +			goto free_uio_res;
>>  		}
>>  
>>  		maps[j].addr = mapaddr;
>> @@ -274,6 +273,15 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>>  	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
>>  
>>  	return 0;
>> +
>> +free_uio_res:
>> +	rte_free(uio_res);
> If you initialize uio_res to NULL when it is defined, you can get rid of the
> distinction between "free_uio_res" and "close_fd" labels. 
>
> Similarly, if you check for a valid dev->intr_handle.fd value before close, you can have a 
> generic "error" leg, and replace all return -1's with goto error. While not as
> useful as merging the labels, it might be something to consider.

Hi Bruce,

Thanks for comments.
Sure, I will cleanup my patch like your mentioned. It will be easier to
read.

>> @@ -368,23 +373,15 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>>  
>>  		mapaddr = pci_map_resource(pci_map_addr, fd, 0,
>>  				(size_t)dev->mem_resource[i].len, 0);
>> -		if (mapaddr == MAP_FAILED)
>> -			fail = 1;
>> +		close(fd);
>> +		if (mapaddr == MAP_FAILED) {
>> +			rte_free(maps[map_idx].path);
>> +			goto free_uio_res;
>> +		}
>>  
>>  		pci_map_addr = RTE_PTR_ADD(mapaddr,
>>  				(size_t)dev->mem_resource[i].len);
>>  
>> -		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
>> -		if (maps[map_idx].path == NULL)
>> -			fail = 1;
>> -
>> -		if (fail) {
>> -			rte_free(uio_res);
>> -			close(fd);
>> -			return -1;
>> -		}
>> -		close(fd);
>> -
>>  		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
>>  		maps[map_idx].size = dev->mem_resource[i].len;
>>  		maps[map_idx].addr = mapaddr;
>> @@ -399,6 +396,25 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>>  	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
>>  
>>  	return 0;
>> +
>> +free_uio_res:
>> +	for (i = 0; i < map_idx; i++) {
> If you move the initialization of map_idx = 0 from the "for" loop to the definition
> at the start of the function, you may again be able to merge these two labels
> into one.

Also I will fix it in next patches.

Regards,
Tetsuya

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v7 05/12] eal: Fix uio mapping differences between linuxapp and bsdapp
  2015-07-02 10:20               ` Bruce Richardson
@ 2015-07-03  8:51                 ` Tetsuya Mukawa
  0 siblings, 0 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-03  8:51 UTC (permalink / raw)
  To: Bruce Richardson; +Cc: dev

On 2015/07/02 19:20, Bruce Richardson wrote:
> On Tue, Jun 30, 2015 at 05:24:21PM +0900, Tetsuya Mukawa wrote:
>> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
>>
>> This patch fixes below.
>> - bsdapp
>>  - Use map_id in pci_uio_map_resource().
>>  - Fix interface of pci_map_resource().
>>  - Move path variable of mapped_pci_resource structure to pci_map.
>> - linuxapp
>>  - Remove redundant error message of linuxapp.
>>
>> 'pci_uio_map_resource()' is implemented in both linuxapp and bsdapp,
>> but interface is different. The patch fixes the function of bsdapp
>> to do same as linuxapp. After applying it, file descriptor should be
>> opened and closed out of pci_map_resource().
>>
>> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
>> ---
>>  lib/librte_eal/bsdapp/eal/eal_pci.c       | 118 ++++++++++++++++++------------
>>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c |  21 +++---
>>  2 files changed, 80 insertions(+), 59 deletions(-)
>>
> <snip>  
>>  free_uio_res:
>> +	for (i = 0; i < map_idx; i++)
>> +		rte_free(maps[i].path);
>>  	rte_free(uio_res);
>>  close_fd:
>>  	close(dev->intr_handle.fd);
> Comments on previous patch about merging error labels would also apply here.

Right, I will fix it also.

>> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>> index c3b259b..19620fe 100644
>> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>> @@ -116,17 +116,11 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
>>  					fd, (off_t)uio_res->maps[i].offset,
>>  					(size_t)uio_res->maps[i].size, 0);
>>  			if (mapaddr != uio_res->maps[i].addr) {
>> -				if (mapaddr == MAP_FAILED)
>> -					RTE_LOG(ERR, EAL,
>> -							"Cannot mmap device resource file %s: %s\n",
>> -							uio_res->maps[i].path,
>> -							strerror(errno));
>> -				else
>> -					RTE_LOG(ERR, EAL,
>> -							"Cannot mmap device resource file %s to address: %p\n",
>> -							uio_res->maps[i].path,
>> -							uio_res->maps[i].addr);
>> -
>> +				RTE_LOG(ERR, EAL,
>> +						"Cannot mmap device resource "
>> +						"file %s to address: %p\n",
>> +						uio_res->maps[i].path,
>> +						uio_res->maps[i].addr);
>>  				close(fd);
>>  				return -1;
>>  			}
>> @@ -353,8 +347,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>>  
>>  		/* allocate memory to keep path */
>>  		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
>> -		if (maps[map_idx].path == NULL)
>> +		if (maps[map_idx].path == NULL) {
>> +			RTE_LOG(ERR, EAL, "Cannot allocate memory for "
>> +					"path: %s\n", strerror(errno));
> It's recommended not to split literal strings across multiple lines. This is
> so that it's easy to find error messages in the source code. In this case, because
> of the split, someone using git grep to search for the error message 
> "Cannot allocate memory for path" 
> would not be able to find it in the code. Longer lines are allowed in code for
> literal strings.
>
> /Bruce
>

Sure, I will fix it.

Tetsuya

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v7 06/12] eal: Add pci_uio_alloc_resource()
  2015-07-02 10:46               ` Bruce Richardson
@ 2015-07-03  8:52                 ` Tetsuya Mukawa
  2015-07-03  9:45                   ` Bruce Richardson
  0 siblings, 1 reply; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-03  8:52 UTC (permalink / raw)
  To: Bruce Richardson; +Cc: dev

On 2015/07/02 19:46, Bruce Richardson wrote:
> On Tue, Jun 30, 2015 at 05:24:22PM +0900, Tetsuya Mukawa wrote:
>> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
>>
>> This patch adds a new function called pci_uio_alloc_resource().
>> The function hides how to prepare uio resource in linuxapp and bsdapp.
>> With the function, pci_uio_map_resource() will be more abstracted.
>>
>> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
>> ---
>>  lib/librte_eal/bsdapp/eal/eal_pci.c       | 70 +++++++++++++++++++---------
>>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 77 ++++++++++++++++++++++---------
>>  2 files changed, 104 insertions(+), 43 deletions(-)
>>
>> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
>> index 06c564f..7d2f8b5 100644
>> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
>> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
>> @@ -189,28 +189,17 @@ 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)
>> +pci_uio_alloc_resource(struct rte_pci_device *dev,
>> +		struct mapped_pci_resource **uio_res)
> Rather than having to pass in a pointer to a pointer, why not change the
> return type to be "struct mapped_pci_resource *"? The only return values currently
> are 0 and -1, so those could map to non-NULL and NULL respectively, for error
> checking.
>
> /Bruce

It might be difficult to do like above, because pci_uio_alloc_resource()
returns 0, -1 and 1 as return value so far.

Original pci_uio_map_resource() returns negative return value as error,
and positive value as driver not found.
So I follow this specification while implementing the function.

Tetsuya

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v7 09/12] eal: Consolidate pci_map/unmap_resource() of linuxapp and bsdapp
  2015-07-02 11:11               ` Bruce Richardson
@ 2015-07-03  8:52                 ` Tetsuya Mukawa
  0 siblings, 0 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-03  8:52 UTC (permalink / raw)
  To: Bruce Richardson; +Cc: dev

On 2015/07/02 20:11, Bruce Richardson wrote:
> On Tue, Jun 30, 2015 at 05:24:25PM +0900, Tetsuya Mukawa wrote:
>> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
>>
>> The patch consolidates below functions, and implemented in common
>> eal code.
>>  - pci_map_resource()
>>  - pci_unmap_resource()
>>
>> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
>> ---
>>  lib/librte_eal/bsdapp/eal/eal_pci.c        | 22 ----------------
>>  lib/librte_eal/common/eal_common_pci.c     | 39 ++++++++++++++++++++++++++++
>>  lib/librte_eal/common/include/rte_pci.h    | 11 ++++++++
>>  lib/librte_eal/linuxapp/eal/eal_pci.c      | 41 ------------------------------
>>  lib/librte_eal/linuxapp/eal/eal_pci_init.h |  5 ----
>>  5 files changed, 50 insertions(+), 68 deletions(-)
>>
> <snip>
>> diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
>> index 0a2ef09..56dcb46 100644
>> --- a/lib/librte_eal/common/include/rte_pci.h
>> +++ b/lib/librte_eal/common/include/rte_pci.h
>> @@ -364,6 +364,17 @@ int rte_eal_pci_scan(void);
>>   */
>>  int rte_eal_pci_probe(void);
>>  
>> +/**
>> + * Map pci resouce.
>> + */
>> +void *pci_map_resource(void *requested_addr, int fd, off_t offset,
>> +		size_t size, int additional_flags);
>> +
>> +/**
>> + * Map pci resouce.
>> + */
>> +void pci_unmap_resource(void *requested_addr, size_t size);
>> +
> These functions should probably be marked "@internal", right?

Yes, it should be. I will fix it.

Tetsuya

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v7 00/12] Clean up pci uio implementations
  2015-07-02 11:32             ` [dpdk-dev] [PATCH v7 00/12] Clean up pci uio implementations Bruce Richardson
@ 2015-07-03  8:52               ` Tetsuya Mukawa
  0 siblings, 0 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-03  8:52 UTC (permalink / raw)
  To: Bruce Richardson; +Cc: dev

On 2015/07/02 20:32, Bruce Richardson wrote:
> On Tue, Jun 30, 2015 at 05:24:16PM +0900, Tetsuya Mukawa wrote:
>> Currently Linux implementation and BSD implementation have almost same
>> code about pci uio. This patch series cleans up it.
>>
> Overall, patchset looks a good idea. I've made some comments on some of the
> individual patches. Quick test on FreeBSD shows that PCI port scanning and
> mapping of the BARs of 82599 NICs works ok.
>
> Tested-by: Bruce Richardson <bruce.richardson@intel.com>
>

I appreciate your testing.
Just for other reviewers, here is my test environment.

 - FreeBSD 10.1
 - 82572EI Gigabit Ethernet Controller (Copper) (rev 06)

Regards,
Tetsuya

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v7 06/12] eal: Add pci_uio_alloc_resource()
  2015-07-03  8:52                 ` Tetsuya Mukawa
@ 2015-07-03  9:45                   ` Bruce Richardson
  0 siblings, 0 replies; 120+ messages in thread
From: Bruce Richardson @ 2015-07-03  9:45 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Fri, Jul 03, 2015 at 05:52:11PM +0900, Tetsuya Mukawa wrote:
> On 2015/07/02 19:46, Bruce Richardson wrote:
> > On Tue, Jun 30, 2015 at 05:24:22PM +0900, Tetsuya Mukawa wrote:
> >> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
> >>
> >> This patch adds a new function called pci_uio_alloc_resource().
> >> The function hides how to prepare uio resource in linuxapp and bsdapp.
> >> With the function, pci_uio_map_resource() will be more abstracted.
> >>
> >> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> >> ---
> >>  lib/librte_eal/bsdapp/eal/eal_pci.c       | 70 +++++++++++++++++++---------
> >>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 77 ++++++++++++++++++++++---------
> >>  2 files changed, 104 insertions(+), 43 deletions(-)
> >>
> >> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
> >> index 06c564f..7d2f8b5 100644
> >> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> >> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> >> @@ -189,28 +189,17 @@ 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)
> >> +pci_uio_alloc_resource(struct rte_pci_device *dev,
> >> +		struct mapped_pci_resource **uio_res)
> > Rather than having to pass in a pointer to a pointer, why not change the
> > return type to be "struct mapped_pci_resource *"? The only return values currently
> > are 0 and -1, so those could map to non-NULL and NULL respectively, for error
> > checking.
> >
> > /Bruce
> 
> It might be difficult to do like above, because pci_uio_alloc_resource()
> returns 0, -1 and 1 as return value so far.
> 
> Original pci_uio_map_resource() returns negative return value as error,
> and positive value as driver not found.
> So I follow this specification while implementing the function.
> 
> Tetsuya

Ok. Keep it as is, so.

/Bruce

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v8 00/12] Clean up pci uio implementations
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 11/12] eal: Consolidate pci_map/unmap_device() " Tetsuya Mukawa
  2015-06-30 14:45               ` Iremonger, Bernard
@ 2015-07-06  6:24               ` Tetsuya Mukawa
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 01/12] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
                                   ` (11 more replies)
  2015-07-08 10:34               ` [dpdk-dev] [PATCH v9 00/12] Clean up pci uio implementations Tetsuya Mukawa
  2 siblings, 12 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-06  6:24 UTC (permalink / raw)
  To: dev

Currently Linux implementation and BSD implementation have almost same
code about pci uio. This patch series cleans up it.

PATCH v8 changes:
 - Fix comments of header file.
 - Fix error handling logic of resource allocation functions.
   (Thanks to Bruce Richardson)
 - Add copyright.
 - Fix patch description.
   (Thanks to Iremonger, Bernard)

PATCH v7 changes:
 - Add below patches. Also, the order of patches are changed.
   - eal: Add pci_uio_alloc_resource()
   - eal: Add pci_uio_map_resource_by_index()
   - eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp
   - eal: Consolidate pci_map/unmap_resource() of linuxapp and bsdapp
   - eal: Consolidate pci uio functions of linuxapp and bsdapp
   - eal: Consolidate pci_map/unmap_device() of linuxapp and bsdapp
   - eal: Consolidate rte_eal_pci_probe/close_one_driver() of linuxapp and bsdapp
   (Thanks to Bruce Richardson)
 - While adding above, below patches are not changed at all.
   - eal: Fix coding style of eal_pci.c and eal_pci_uio.c
   - eal: Close file descriptor of uio configuration
   - eal: Fix memory leaks and needless increment of pci_map_addr
   - eal/bsdapp: Change names of pci related data structure
   - eal: Fix uio mapping differences between linuxapp and bsdapp
 - some function names are changed like below.
   - pci_uio_alloc_uio_resource() to pci_uio_alloc_resource().
   - pci_uio_map_uio_resource_by_index() to pci_uio_map_resource_by_index().
   (Thanks to Iremonger, Bernard)

PATCH v6 changes:
 - Free mapped resources in pci_uio_map_resource().
 - Fix error handling in pci_uio_map_resource().
   (Thanks to David, Marchand)

PATCH v5 changes:
 - Rebase to latest master branch.

PATCH v4 changes:
 - Rebase to latest master branch.
 - Fix bug in pci_uio_map_resource() of BSD code. 'maps[i].path' shouldn't be freed.
     Fixed in below patch:
     [PATCH 3/5] eal: Fix memory leaks and needless increment of pci_map_addr
 - 'path' member of 'struct mapped_pci_resource' should not be removed because it will be used in BSD code.
     Fixed in below patch:
     [PATCH 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp

PATCH v3 changes:
 - Squash patches related with pci_map_resource().
 - Free maps[].path to easy to understand.
   (Thanks to Iremonger, Bernard)
 - Close fds opened in this function.
 - Remove unused path variable from mapped_pci_resource structure.

PATCH v2 changes:
 - Move 'if-condition' to later patch series.
 - Fix memory leaks of path.
 - Fix typos.
   (Thanks to David Marchand)
 - Fix commit title and body.
 - Fix pci_map_resource() to handle MAP_FAILED.
   (Thanks to Iremonger, Bernard)

Changes:
 - This patch set is derived from below.
   "[PATCH v2] eal: Port Hotplug support for BSD"
 - Set cfg_fd as -1, when cfg_fd is closed.
   (Thanks to Iremonger, Bernard)
 - Remove needless coding style fixings.
 - Fix coding style of if-else condition.
   (Thanks to Richardson, Bruce)


Tetsuya.Mukawa (12):
  eal: Fix coding style of eal_pci.c and eal_pci_uio.c
  eal: Close file descriptor of uio configuration
  eal: Fix memory leaks and needless increment of pci_map_addr
  eal/bsdapp: Change names of pci related data structure
  eal: Fix uio mapping differences between linuxapp and bsdapp
  eal: Add pci_uio_alloc_resource()
  eal: Add pci_uio_map_resource_by_index()
  eal: Consolidate pci_map and mapped_pci_resource of linuxapp and
    bsdapp
  eal: Consolidate pci_map/unmap_resource() of linuxapp and bsdapp
  eal: Consolidate pci uio functions of linuxapp and bsdapp
  eal: Consolidate pci_map/unmap_device() of linuxapp and bsdapp
  eal: Consolidate rte_eal_pci_probe/close_one_driver() of linuxapp and
    bsdapp

 lib/librte_eal/bsdapp/eal/Makefile                 |   2 +
 lib/librte_eal/bsdapp/eal/eal_pci.c                | 293 ++++++---------------
 .../bsdapp/eal/include/exec-env/rte_interrupts.h   |   2 +
 lib/librte_eal/common/eal_common_pci.c             | 226 ++++++++++++++++
 lib/librte_eal/common/eal_common_pci_uio.c         | 240 +++++++++++++++++
 lib/librte_eal/common/eal_private.h                |  60 ++++-
 lib/librte_eal/common/include/rte_pci.h            |  62 +++++
 lib/librte_eal/linuxapp/eal/Makefile               |   2 +
 lib/librte_eal/linuxapp/eal/eal_pci.c              | 237 +----------------
 lib/librte_eal/linuxapp/eal/eal_pci_init.h         |  40 +--
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c          | 293 +++++++--------------
 lib/librte_ether/rte_ethdev.c                      |   2 +
 12 files changed, 761 insertions(+), 698 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_pci_uio.c

-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v8 01/12] eal: Fix coding style of eal_pci.c and eal_pci_uio.c
  2015-07-06  6:24               ` [dpdk-dev] [PATCH v8 00/12] Clean up pci uio implementations Tetsuya Mukawa
@ 2015-07-06  6:24                 ` Tetsuya Mukawa
  2015-07-07  8:04                   ` David Marchand
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 02/12] eal: Close file descriptor of uio configuration Tetsuya Mukawa
                                   ` (10 subsequent siblings)
  11 siblings, 1 reply; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-06  6:24 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

This patch fixes coding style of below files in linuxapp and bsdapp.
 - eal_pci.c
 - eal_pci_uio.c

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c       | 13 ++++++++-----
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 13 +++++++++----
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 2df5c1c..a63d450 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -2,6 +2,7 @@
  *   BSD LICENSE
  *
  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2015 IGEL Co., Ltd.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -161,9 +162,10 @@ fail:
 static int
 pci_uio_map_secondary(struct rte_pci_device *dev)
 {
-        size_t i;
-        struct uio_resource *uio_res;
-	struct uio_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
+	size_t i;
+	struct uio_resource *uio_res;
+	struct uio_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
 
 	TAILQ_FOREACH(uio_res, uio_res_list, next) {
 
@@ -201,7 +203,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	uint64_t pagesz;
 	struct rte_pci_addr *loc = &dev->addr;
 	struct uio_resource *uio_res;
-	struct uio_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
+	struct uio_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
 	struct uio_map *maps;
 
 	dev->intr_handle.fd = -1;
@@ -311,7 +314,7 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
 	/* FreeBSD has no NUMA support (yet) */
 	dev->numa_node = 0;
 
-/* parse resources */
+	/* parse resources */
 	switch (conf->pc_hdr & PCIM_HDRTYPE) {
 	case PCIM_HDRTYPE_NORMAL:
 		max = PCIR_MAX_BAR_0;
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index b5116a7..5915a84 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -2,6 +2,7 @@
  *   BSD LICENSE
  *
  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2015 IGEL Co., Ltd.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -92,7 +93,8 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 {
 	int fd, i;
 	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 
 	TAILQ_FOREACH(uio_res, uio_res_list, next) {
 
@@ -272,7 +274,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	uint64_t phaddr;
 	struct rte_pci_addr *loc = &dev->addr;
 	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 	struct pci_map *maps;
 
 	dev->intr_handle.fd = -1;
@@ -417,7 +420,8 @@ static struct mapped_pci_resource *
 pci_uio_find_resource(struct rte_pci_device *dev)
 {
 	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 
 	if (dev == NULL)
 		return NULL;
@@ -436,7 +440,8 @@ void
 pci_uio_unmap_resource(struct rte_pci_device *dev)
 {
 	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 
 	if (dev == NULL)
 		return;
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v8 02/12] eal: Close file descriptor of uio configuration
  2015-07-06  6:24               ` [dpdk-dev] [PATCH v8 00/12] Clean up pci uio implementations Tetsuya Mukawa
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 01/12] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
@ 2015-07-06  6:24                 ` Tetsuya Mukawa
  2015-07-07  8:04                   ` David Marchand
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 03/12] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
                                   ` (9 subsequent siblings)
  11 siblings, 1 reply; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-06  6:24 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

When pci_uio_unmap_resource() is called, a file descriptor that is used
for uio configuration should be closed.

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 5915a84..37dc936 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -465,8 +465,12 @@ pci_uio_unmap_resource(struct rte_pci_device *dev)
 
 	/* close fd if in primary process */
 	close(dev->intr_handle.fd);
-
 	dev->intr_handle.fd = -1;
+
+	/* close cfg_fd if in primary process */
+	close(dev->intr_handle.uio_cfg_fd);
+	dev->intr_handle.uio_cfg_fd = -1;
+
 	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
 }
 #endif /* RTE_LIBRTE_EAL_HOTPLUG */
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v8 03/12] eal: Fix memory leaks and needless increment of pci_map_addr
  2015-07-06  6:24               ` [dpdk-dev] [PATCH v8 00/12] Clean up pci uio implementations Tetsuya Mukawa
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 01/12] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 02/12] eal: Close file descriptor of uio configuration Tetsuya Mukawa
@ 2015-07-06  6:24                 ` Tetsuya Mukawa
  2015-07-07  8:04                   ` David Marchand
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 04/12] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
                                   ` (8 subsequent siblings)
  11 siblings, 1 reply; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-06  6:24 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

This patch fixes following memory leaks.
- When open() is failed, uio_res and fds won't be freed in
  pci_uio_map_resource().
- When pci_map_resource() is failed but path is allocated correctly,
  path and fds won't be freed in pci_uio_map_recource().
  Also, some mapped resources should be freed.
- When pci_uio_unmap() is called, path should be freed.

Also, fixes below.
- When pci_map_resource() is failed, mapaddr will be MAP_FAILED.
  In this case, pci_map_addr should not be incremented in
  pci_uio_map_resource().
- To shrink code, move close().
- Remove fail variable.

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c       | 19 ++++++---
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 64 ++++++++++++++++++++-----------
 2 files changed, 55 insertions(+), 28 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index a63d450..63758c7 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -202,7 +202,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	uint64_t offset;
 	uint64_t pagesz;
 	struct rte_pci_addr *loc = &dev->addr;
-	struct uio_resource *uio_res;
+	struct uio_resource *uio_res = NULL;
 	struct uio_res_list *uio_res_list =
 			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
 	struct uio_map *maps;
@@ -228,7 +228,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	if (dev->intr_handle.fd < 0) {
 		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
 			devname, strerror(errno));
-		return -1;
+		goto error;
 	}
 	dev->intr_handle.type = RTE_INTR_HANDLE_UIO;
 
@@ -236,7 +236,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) == NULL) {
 		RTE_LOG(ERR, EAL,
 			"%s(): cannot store uio mmap details\n", __func__);
-		return -1;
+		goto error;
 	}
 
 	snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
@@ -263,8 +263,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 		    (mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
 						(size_t)maps[j].size)
 		    ) == NULL) {
-			rte_free(uio_res);
-			return -1;
+			goto error;
 		}
 
 		maps[j].addr = mapaddr;
@@ -275,6 +274,16 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
 
 	return 0;
+
+error:
+	if (uio_res)
+		rte_free(uio_res);
+	if (dev->intr_handle.fd >= 0) {
+		close(dev->intr_handle.fd);
+		dev->intr_handle.fd = -1;
+		dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+	}
+	return -1;
 }
 
 /* Scan one pci sysfs entry, and fill the devices list from it. */
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 37dc936..4e50533 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -265,7 +265,7 @@ pci_get_uio_dev(struct rte_pci_device *dev, char *dstbuf,
 int
 pci_uio_map_resource(struct rte_pci_device *dev)
 {
-	int i, map_idx;
+	int i, map_idx = 0;
 	char dirname[PATH_MAX];
 	char cfgname[PATH_MAX];
 	char devname[PATH_MAX]; /* contains the /dev/uioX */
@@ -273,7 +273,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	int uio_num;
 	uint64_t phaddr;
 	struct rte_pci_addr *loc = &dev->addr;
-	struct mapped_pci_resource *uio_res;
+	struct mapped_pci_resource *uio_res = NULL;
 	struct mapped_pci_res_list *uio_res_list =
 			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 	struct pci_map *maps;
@@ -300,7 +300,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	if (dev->intr_handle.fd < 0) {
 		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
 			devname, strerror(errno));
-		return -1;
+		goto error;
 	}
 
 	snprintf(cfgname, sizeof(cfgname),
@@ -309,7 +309,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	if (dev->intr_handle.uio_cfg_fd < 0) {
 		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
 			cfgname, strerror(errno));
-		return -1;
+		goto error;
 	}
 
 	if (dev->kdrv == RTE_KDRV_IGB_UIO)
@@ -320,7 +320,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 		/* set bus master that is not done by uio_pci_generic */
 		if (pci_uio_set_bus_master(dev->intr_handle.uio_cfg_fd)) {
 			RTE_LOG(ERR, EAL, "Cannot set up bus mastering!\n");
-			return -1;
+			goto error;
 		}
 	}
 
@@ -329,7 +329,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	if (uio_res == NULL) {
 		RTE_LOG(ERR, EAL,
 			"%s(): cannot store uio mmap details\n", __func__);
-		return -1;
+		goto error;
 	}
 
 	snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
@@ -337,9 +337,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 	/* Map all BARs */
 	maps = uio_res->maps;
-	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
+	for (i = 0; i != PCI_MAX_RESOURCE; i++) {
 		int fd;
-		int fail = 0;
 
 		/* skip empty BAR */
 		phaddr = dev->mem_resource[i].phys_addr;
@@ -353,6 +352,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 				loc->domain, loc->bus, loc->devid, loc->function,
 				i);
 
+		/* allocate memory to keep path */
+		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
+		if (maps[map_idx].path == NULL)
+			goto error;
+
 		/*
 		 * open resource file, to mmap it
 		 */
@@ -360,7 +364,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 		if (fd < 0) {
 			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
 					devname, strerror(errno));
-			return -1;
+			rte_free(maps[map_idx].path);
+			goto error;
 		}
 
 		/* try mapping somewhere close to the end of hugepages */
@@ -369,23 +374,15 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 		mapaddr = pci_map_resource(pci_map_addr, fd, 0,
 				(size_t)dev->mem_resource[i].len, 0);
-		if (mapaddr == MAP_FAILED)
-			fail = 1;
+		close(fd);
+		if (mapaddr == MAP_FAILED) {
+			rte_free(maps[map_idx].path);
+			goto error;
+		}
 
 		pci_map_addr = RTE_PTR_ADD(mapaddr,
 				(size_t)dev->mem_resource[i].len);
 
-		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
-		if (maps[map_idx].path == NULL)
-			fail = 1;
-
-		if (fail) {
-			rte_free(uio_res);
-			close(fd);
-			return -1;
-		}
-		close(fd);
-
 		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
 		maps[map_idx].size = dev->mem_resource[i].len;
 		maps[map_idx].addr = mapaddr;
@@ -400,6 +397,25 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
 
 	return 0;
+
+error:
+	for (i = 0; i < map_idx; i++) {
+		pci_unmap_resource(uio_res->maps[i].addr,
+				(size_t)uio_res->maps[i].size);
+		rte_free(maps[i].path);
+	}
+	if (uio_res)
+		rte_free(uio_res);
+	if (dev->intr_handle.uio_cfg_fd >= 0) {
+		close(dev->intr_handle.uio_cfg_fd);
+		dev->intr_handle.uio_cfg_fd = -1;
+	}
+	if (dev->intr_handle.fd >= 0) {
+		close(dev->intr_handle.fd);
+		dev->intr_handle.fd = -1;
+		dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+	}
+	return -1;
 }
 
 #ifdef RTE_LIBRTE_EAL_HOTPLUG
@@ -411,9 +427,11 @@ pci_uio_unmap(struct mapped_pci_resource *uio_res)
 	if (uio_res == NULL)
 		return;
 
-	for (i = 0; i != uio_res->nb_maps; i++)
+	for (i = 0; i != uio_res->nb_maps; i++) {
 		pci_unmap_resource(uio_res->maps[i].addr,
 				(size_t)uio_res->maps[i].size);
+		rte_free(uio_res->maps[i].path);
+	}
 }
 
 static struct mapped_pci_resource *
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v8 04/12] eal/bsdapp: Change names of pci related data structure
  2015-07-06  6:24               ` [dpdk-dev] [PATCH v8 00/12] Clean up pci uio implementations Tetsuya Mukawa
                                   ` (2 preceding siblings ...)
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 03/12] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
@ 2015-07-06  6:24                 ` Tetsuya Mukawa
  2015-07-07  8:04                   ` David Marchand
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 05/12] eal: Fix uio mapping differences between linuxapp and bsdapp Tetsuya Mukawa
                                   ` (7 subsequent siblings)
  11 siblings, 1 reply; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-06  6:24 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

To merge pci code of linuxapp and bsdapp, this patch changes names
like below.
 - uio_map to pci_map
 - uio_resource to mapped_pci_resource
 - uio_res_list to mapped_pci_res_list

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 63758c7..21d1e66 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -84,7 +84,7 @@
  * enabling bus master.
  */
 
-struct uio_map {
+struct pci_map {
 	void *addr;
 	uint64_t offset;
 	uint64_t size;
@@ -95,16 +95,16 @@ struct uio_map {
  * For multi-process we need to reproduce all PCI mappings in secondary
  * processes, so save them in a tailq.
  */
-struct uio_resource {
-	TAILQ_ENTRY(uio_resource) next;
+struct mapped_pci_resource {
+	TAILQ_ENTRY(mapped_pci_resource) next;
 
 	struct rte_pci_addr pci_addr;
 	char path[PATH_MAX];
 	size_t nb_maps;
-	struct uio_map maps[PCI_MAX_RESOURCE];
+	struct pci_map maps[PCI_MAX_RESOURCE];
 };
 
-TAILQ_HEAD(uio_res_list, uio_resource);
+TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource);
 
 static struct rte_tailq_elem rte_uio_tailq = {
 	.name = "UIO_RESOURCE_LIST",
@@ -163,9 +163,9 @@ static int
 pci_uio_map_secondary(struct rte_pci_device *dev)
 {
 	size_t i;
-	struct uio_resource *uio_res;
-	struct uio_res_list *uio_res_list =
-			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
+	struct mapped_pci_resource *uio_res;
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 
 	TAILQ_FOREACH(uio_res, uio_res_list, next) {
 
@@ -202,10 +202,10 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	uint64_t offset;
 	uint64_t pagesz;
 	struct rte_pci_addr *loc = &dev->addr;
-	struct uio_resource *uio_res = NULL;
-	struct uio_res_list *uio_res_list =
-			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
-	struct uio_map *maps;
+	struct mapped_pci_resource *uio_res = NULL;
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct pci_map *maps;
 
 	dev->intr_handle.fd = -1;
 	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v8 05/12] eal: Fix uio mapping differences between linuxapp and bsdapp
  2015-07-06  6:24               ` [dpdk-dev] [PATCH v8 00/12] Clean up pci uio implementations Tetsuya Mukawa
                                   ` (3 preceding siblings ...)
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 04/12] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
@ 2015-07-06  6:24                 ` Tetsuya Mukawa
  2015-07-07  8:04                   ` David Marchand
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 06/12] eal: Add pci_uio_alloc_resource() Tetsuya Mukawa
                                   ` (6 subsequent siblings)
  11 siblings, 1 reply; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-06  6:24 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

This patch fixes below.
- bsdapp
 - Use map_id in pci_uio_map_resource().
 - Fix interface of pci_map_resource().
 - Move path variable of mapped_pci_resource structure to pci_map.
- linuxapp
 - Remove redundant error message of linuxapp.

'pci_uio_map_resource()' is implemented in both linuxapp and bsdapp,
but interface is different. The patch fixes the function of bsdapp
to do same as linuxapp. After applying it, file descriptor should be
opened and closed out of pci_map_resource().

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c       | 118 ++++++++++++++++++------------
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c |  20 ++---
 2 files changed, 78 insertions(+), 60 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 21d1e66..92d9886 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -86,6 +86,7 @@
 
 struct pci_map {
 	void *addr;
+	char *path;
 	uint64_t offset;
 	uint64_t size;
 	uint64_t phaddr;
@@ -100,7 +101,7 @@ struct mapped_pci_resource {
 
 	struct rte_pci_addr pci_addr;
 	char path[PATH_MAX];
-	size_t nb_maps;
+	int nb_maps;
 	struct pci_map maps[PCI_MAX_RESOURCE];
 };
 
@@ -122,47 +123,30 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)
 
 /* map a particular resource from a file */
 static void *
-pci_map_resource(void *requested_addr, const char *devname, off_t offset,
-		 size_t size)
+pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
+		 int additional_flags)
 {
-	int fd;
 	void *mapaddr;
 
-	/*
-	 * open devname, to mmap it
-	 */
-	fd = open(devname, O_RDWR);
-	if (fd < 0) {
-		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
-			devname, strerror(errno));
-		goto fail;
-	}
-
 	/* Map the PCI memory resource of device */
 	mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
-			MAP_SHARED, fd, offset);
-	close(fd);
-	if (mapaddr == MAP_FAILED ||
-			(requested_addr != NULL && mapaddr != requested_addr)) {
-		RTE_LOG(ERR, EAL, "%s(): cannot mmap(%s(%d), %p, 0x%lx, 0x%lx):"
-			" %s (%p)\n", __func__, devname, fd, requested_addr,
+			MAP_SHARED | additional_flags, fd, offset);
+	if (mapaddr == MAP_FAILED) {
+		RTE_LOG(ERR, EAL,
+			"%s(): cannot mmap(%d, %p, 0x%lx, 0x%lx): %s (%p)\n",
+			__func__, fd, requested_addr,
 			(unsigned long)size, (unsigned long)offset,
 			strerror(errno), mapaddr);
-		goto fail;
-	}
-
-	RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
+	} else
+		RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
 
 	return mapaddr;
-
-fail:
-	return NULL;
 }
 
 static int
 pci_uio_map_secondary(struct rte_pci_device *dev)
 {
-	size_t i;
+	int i, fd;
 	struct mapped_pci_resource *uio_res;
 	struct mapped_pci_res_list *uio_res_list =
 			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
@@ -170,19 +154,33 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 	TAILQ_FOREACH(uio_res, uio_res_list, next) {
 
 		/* skip this element if it doesn't match our PCI address */
-		if (memcmp(&uio_res->pci_addr, &dev->addr, sizeof(dev->addr)))
+		if (rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr))
 			continue;
 
 		for (i = 0; i != uio_res->nb_maps; i++) {
-			if (pci_map_resource(uio_res->maps[i].addr,
-					     uio_res->path,
-					     (off_t)uio_res->maps[i].offset,
-					     (size_t)uio_res->maps[i].size)
-			    != uio_res->maps[i].addr) {
+			/*
+			 * open devname, to mmap it
+			 */
+			fd = open(uio_res->maps[i].path, O_RDWR);
+			if (fd < 0) {
+				RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
+					uio_res->maps[i].path, strerror(errno));
+				return -1;
+			}
+
+			void *mapaddr = pci_map_resource(uio_res->maps[i].addr,
+					fd, (off_t)uio_res->maps[i].offset,
+					(size_t)uio_res->maps[i].size, 0);
+			if (mapaddr != uio_res->maps[i].addr) {
 				RTE_LOG(ERR, EAL,
-					"Cannot mmap device resource\n");
+					"Cannot mmap device resource file %s to address: %p\n",
+					uio_res->maps[i].path,
+					uio_res->maps[i].addr);
+				close(fd);
 				return -1;
 			}
+			/* fd is not needed in slave process, close it */
+			close(fd);
 		}
 		return 0;
 	}
@@ -195,7 +193,7 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 static int
 pci_uio_map_resource(struct rte_pci_device *dev)
 {
-	int i, j;
+	int i, map_idx = 0;
 	char devname[PATH_MAX]; /* contains the /dev/uioX */
 	void *mapaddr;
 	uint64_t phaddr;
@@ -247,35 +245,59 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	pagesz = sysconf(_SC_PAGESIZE);
 
 	maps = uio_res->maps;
-	for (i = uio_res->nb_maps = 0; i != PCI_MAX_RESOURCE; i++) {
+	for (i = 0; i != PCI_MAX_RESOURCE; i++) {
+		int fd;
 
-		j = uio_res->nb_maps;
 		/* skip empty BAR */
 		if ((phaddr = dev->mem_resource[i].phys_addr) == 0)
 			continue;
 
+		/* allocate memory to keep path */
+		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
+		if (maps[map_idx].path == NULL) {
+			RTE_LOG(ERR, EAL, "Cannot allocate memory for path: %s\n",
+					strerror(errno));
+			goto error;
+		}
+
+		/*
+		 * open resource file, to mmap it
+		 */
+		fd = open(devname, O_RDWR);
+		if (fd < 0) {
+			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
+					devname, strerror(errno));
+			rte_free(maps[map_idx].path);
+			goto error;
+		}
+
 		/* if matching map is found, then use it */
 		offset = i * pagesz;
-		maps[j].offset = offset;
-		maps[j].phaddr = dev->mem_resource[i].phys_addr;
-		maps[j].size = dev->mem_resource[i].len;
-		if (maps[j].addr != NULL ||
-		    (mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
-						(size_t)maps[j].size)
-		    ) == NULL) {
+		mapaddr = pci_map_resource(NULL, fd, (off_t)offset,
+					(size_t)dev->mem_resource[i].len, 0);
+		close(fd);
+		if (mapaddr == MAP_FAILED) {
+			rte_free(maps[map_idx].path);
 			goto error;
 		}
 
-		maps[j].addr = mapaddr;
-		uio_res->nb_maps++;
+		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
+		maps[map_idx].size = dev->mem_resource[i].len;
+		maps[map_idx].addr = mapaddr;
+		maps[map_idx].offset = offset;
+		strcpy(maps[map_idx].path, devname);
+		map_idx++;
 		dev->mem_resource[i].addr = mapaddr;
 	}
 
+	uio_res->nb_maps = map_idx;
+
 	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
 
 	return 0;
-
 error:
+	for (i = 0; i < map_idx; i++)
+		rte_free(maps[i].path);
 	if (uio_res)
 		rte_free(uio_res);
 	if (dev->intr_handle.fd >= 0) {
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 4e50533..38a93c9 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -117,17 +117,10 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 					fd, (off_t)uio_res->maps[i].offset,
 					(size_t)uio_res->maps[i].size, 0);
 			if (mapaddr != uio_res->maps[i].addr) {
-				if (mapaddr == MAP_FAILED)
-					RTE_LOG(ERR, EAL,
-							"Cannot mmap device resource file %s: %s\n",
-							uio_res->maps[i].path,
-							strerror(errno));
-				else
-					RTE_LOG(ERR, EAL,
-							"Cannot mmap device resource file %s to address: %p\n",
-							uio_res->maps[i].path,
-							uio_res->maps[i].addr);
-
+				RTE_LOG(ERR, EAL,
+					"Cannot mmap device resource file %s to address: %p\n",
+					uio_res->maps[i].path,
+					uio_res->maps[i].addr);
 				close(fd);
 				return -1;
 			}
@@ -354,8 +347,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 		/* allocate memory to keep path */
 		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
-		if (maps[map_idx].path == NULL)
+		if (maps[map_idx].path == NULL) {
+			RTE_LOG(ERR, EAL, "Cannot allocate memory for path: %s\n",
+					strerror(errno));
 			goto error;
+		}
 
 		/*
 		 * open resource file, to mmap it
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v8 06/12] eal: Add pci_uio_alloc_resource()
  2015-07-06  6:24               ` [dpdk-dev] [PATCH v8 00/12] Clean up pci uio implementations Tetsuya Mukawa
                                   ` (4 preceding siblings ...)
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 05/12] eal: Fix uio mapping differences between linuxapp and bsdapp Tetsuya Mukawa
@ 2015-07-06  6:24                 ` Tetsuya Mukawa
  2015-07-07  8:04                   ` David Marchand
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 07/12] eal: Add pci_uio_map_resource_by_index() Tetsuya Mukawa
                                   ` (5 subsequent siblings)
  11 siblings, 1 reply; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-06  6:24 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

This patch adds a new function called pci_uio_alloc_resource().
The function hides how to prepare uio resource in linuxapp and bsdapp.
With the function, pci_uio_map_resource() will be more abstracted.

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c       | 84 +++++++++++++++++---------
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 98 +++++++++++++++++++++----------
 2 files changed, 123 insertions(+), 59 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 92d9886..ce0ca07 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -189,28 +189,17 @@ 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)
+pci_uio_alloc_resource(struct rte_pci_device *dev,
+		struct mapped_pci_resource **uio_res)
 {
-	int i, map_idx = 0;
 	char devname[PATH_MAX]; /* contains the /dev/uioX */
-	void *mapaddr;
-	uint64_t phaddr;
-	uint64_t offset;
-	uint64_t pagesz;
-	struct rte_pci_addr *loc = &dev->addr;
-	struct mapped_pci_resource *uio_res = NULL;
-	struct mapped_pci_res_list *uio_res_list =
-			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
-	struct pci_map *maps;
+	struct rte_pci_addr *loc;
 
-	dev->intr_handle.fd = -1;
-	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+	if ((dev == NULL) || (uio_res == NULL))
+		return -1;
 
-	/* secondary processes - use already recorded details */
-	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
-		return pci_uio_map_secondary(dev);
+	loc = &dev->addr;
 
 	snprintf(devname, sizeof(devname), "/dev/uio@pci:%u:%u:%u",
 			dev->addr.bus, dev->addr.devid, dev->addr.function);
@@ -231,18 +220,57 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	dev->intr_handle.type = RTE_INTR_HANDLE_UIO;
 
 	/* allocate the mapping details for secondary processes*/
-	if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) == NULL) {
+	*uio_res = rte_zmalloc("UIO_RES", sizeof(**uio_res), 0);
+	if (*uio_res == NULL) {
 		RTE_LOG(ERR, EAL,
 			"%s(): cannot store uio mmap details\n", __func__);
 		goto error;
 	}
 
-	snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
-	memcpy(&uio_res->pci_addr, &dev->addr, sizeof(uio_res->pci_addr));
+	snprintf((*uio_res)->path, sizeof((*uio_res)->path), "%s", devname);
+	memcpy(&(*uio_res)->pci_addr, &dev->addr, sizeof((*uio_res)->pci_addr));
 
+	return 0;
+
+error:
+	if (dev->intr_handle.fd) {
+		close(dev->intr_handle.fd);
+		dev->intr_handle.fd = -1;
+		dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+	}
+	return -1;
+}
+
+/* map the PCI resource of a PCI device in virtual memory */
+static int
+pci_uio_map_resource(struct rte_pci_device *dev)
+{
+	int i, map_idx = 0, ret;
+	char *devname;
+	void *mapaddr;
+	uint64_t phaddr;
+	uint64_t offset;
+	uint64_t pagesz;
+	struct mapped_pci_resource *uio_res = NULL;
+	struct mapped_pci_res_list *uio_res_list =
+		RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct pci_map *maps;
+
+	dev->intr_handle.fd = -1;
+	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+
+	/* secondary processes - use already recorded details */
+	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+		return pci_uio_map_secondary(dev);
+
+	/* allocate uio resource */
+	ret = pci_uio_alloc_resource(dev, &uio_res);
+	if ((ret != 0) || (uio_res == NULL))
+		return ret;
 
 	/* Map all BARs */
 	pagesz = sysconf(_SC_PAGESIZE);
+	devname = uio_res->path;
 
 	maps = uio_res->maps;
 	for (i = 0; i != PCI_MAX_RESOURCE; i++) {
@@ -298,13 +326,15 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 error:
 	for (i = 0; i < map_idx; i++)
 		rte_free(maps[i].path);
-	if (uio_res)
-		rte_free(uio_res);
-	if (dev->intr_handle.fd >= 0) {
-		close(dev->intr_handle.fd);
-		dev->intr_handle.fd = -1;
-		dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
-	}
+
+	/* 'uio_res' has valid value here */
+	rte_free(uio_res);
+
+	/* 'fd' has valid value here */
+	close(dev->intr_handle.fd);
+	dev->intr_handle.fd = -1;
+	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+
 	return -1;
 }
 
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 38a93c9..f408bd3 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -254,30 +254,20 @@ pci_get_uio_dev(struct rte_pci_device *dev, char *dstbuf,
 	return uio_num;
 }
 
-/* map the PCI resource of a PCI device in virtual memory */
-int
-pci_uio_map_resource(struct rte_pci_device *dev)
+static int
+pci_uio_alloc_resource(struct rte_pci_device *dev,
+		struct mapped_pci_resource **uio_res)
 {
-	int i, map_idx = 0;
 	char dirname[PATH_MAX];
 	char cfgname[PATH_MAX];
 	char devname[PATH_MAX]; /* contains the /dev/uioX */
-	void *mapaddr;
 	int uio_num;
-	uint64_t phaddr;
-	struct rte_pci_addr *loc = &dev->addr;
-	struct mapped_pci_resource *uio_res = NULL;
-	struct mapped_pci_res_list *uio_res_list =
-			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
-	struct pci_map *maps;
+	struct rte_pci_addr *loc;
 
-	dev->intr_handle.fd = -1;
-	dev->intr_handle.uio_cfg_fd = -1;
-	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+	if ((dev == NULL) || (uio_res == NULL))
+		return -1;
 
-	/* secondary processes - use already recorded details */
-	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
-		return pci_uio_map_secondary(dev);
+	loc = &dev->addr;
 
 	/* find uio resource */
 	uio_num = pci_get_uio_dev(dev, dirname, sizeof(dirname));
@@ -318,15 +308,57 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	}
 
 	/* allocate the mapping details for secondary processes*/
-	uio_res = rte_zmalloc("UIO_RES", sizeof(*uio_res), 0);
-	if (uio_res == NULL) {
+	*uio_res = rte_zmalloc("UIO_RES", sizeof(**uio_res), 0);
+	if (*uio_res == NULL) {
 		RTE_LOG(ERR, EAL,
 			"%s(): cannot store uio mmap details\n", __func__);
 		goto error;
 	}
 
-	snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
-	memcpy(&uio_res->pci_addr, &dev->addr, sizeof(uio_res->pci_addr));
+	snprintf((*uio_res)->path, sizeof((*uio_res)->path), "%s", devname);
+	memcpy(&(*uio_res)->pci_addr, &dev->addr, sizeof((*uio_res)->pci_addr));
+
+	return 0;
+
+error:
+	if (dev->intr_handle.uio_cfg_fd >= 0) {
+		close(dev->intr_handle.uio_cfg_fd);
+		dev->intr_handle.uio_cfg_fd = -1;
+	}
+	if (dev->intr_handle.fd >= 0) {
+		close(dev->intr_handle.fd);
+		dev->intr_handle.fd = -1;
+		dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+	}
+	return -1;
+}
+
+/* map the PCI resource of a PCI device in virtual memory */
+int
+pci_uio_map_resource(struct rte_pci_device *dev)
+{
+	int i, map_idx = 0, ret;
+	char devname[PATH_MAX]; /* contains the /dev/uioX */
+	void *mapaddr;
+	uint64_t phaddr;
+	struct rte_pci_addr *loc = &dev->addr;
+	struct mapped_pci_resource *uio_res = NULL;
+	struct mapped_pci_res_list *uio_res_list =
+		RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct pci_map *maps;
+
+	dev->intr_handle.fd = -1;
+	dev->intr_handle.uio_cfg_fd = -1;
+	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+
+	/* secondary processes - use already recorded details */
+	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+		return pci_uio_map_secondary(dev);
+
+	/* allocate uio resource */
+	ret = pci_uio_alloc_resource(dev, &uio_res);
+	if ((ret != 0) || (uio_res == NULL))
+		return ret;
 
 	/* Map all BARs */
 	maps = uio_res->maps;
@@ -400,17 +432,19 @@ error:
 				(size_t)uio_res->maps[i].size);
 		rte_free(maps[i].path);
 	}
-	if (uio_res)
-		rte_free(uio_res);
-	if (dev->intr_handle.uio_cfg_fd >= 0) {
-		close(dev->intr_handle.uio_cfg_fd);
-		dev->intr_handle.uio_cfg_fd = -1;
-	}
-	if (dev->intr_handle.fd >= 0) {
-		close(dev->intr_handle.fd);
-		dev->intr_handle.fd = -1;
-		dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
-	}
+
+	/* 'uio_res' has valid value here */
+	rte_free(uio_res);
+
+	/* 'uio_cfg_fd' has valid value here */
+	close(dev->intr_handle.uio_cfg_fd);
+	dev->intr_handle.uio_cfg_fd = -1;
+
+	/* 'fd' has valid value here */
+	close(dev->intr_handle.fd);
+	dev->intr_handle.fd = -1;
+	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+
 	return -1;
 }
 
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v8 07/12] eal: Add pci_uio_map_resource_by_index()
  2015-07-06  6:24               ` [dpdk-dev] [PATCH v8 00/12] Clean up pci uio implementations Tetsuya Mukawa
                                   ` (5 preceding siblings ...)
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 06/12] eal: Add pci_uio_alloc_resource() Tetsuya Mukawa
@ 2015-07-06  6:24                 ` Tetsuya Mukawa
  2015-07-07  8:05                   ` David Marchand
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 08/12] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp Tetsuya Mukawa
                                   ` (4 subsequent siblings)
  11 siblings, 1 reply; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-06  6:24 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

This patch adds a new function called pci_uio_map_resource_by_index().
The function hides how to map uio resource in linuxapp and bsdapp.
With the function, pci_uio_map_resource() will be more abstracted.

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c       | 107 +++++++++++++++-----------
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 124 +++++++++++++++++-------------
 2 files changed, 133 insertions(+), 98 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index ce0ca07..c76f936 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -241,20 +241,73 @@ error:
 	return -1;
 }
 
+static int
+pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
+		struct mapped_pci_resource *uio_res, int map_idx)
+{
+	int fd;
+	char *devname;
+	void *mapaddr;
+	uint64_t offset;
+	uint64_t pagesz;
+	struct pci_map *maps;
+
+	if ((dev == NULL) || (uio_res == NULL) || (uio_res->path == NULL))
+		return -1;
+
+	maps = uio_res->maps;
+	devname = uio_res->path;
+	pagesz = sysconf(_SC_PAGESIZE);
+
+	/* allocate memory to keep path */
+	maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
+	if (maps[map_idx].path == NULL) {
+		RTE_LOG(ERR, EAL, "Cannot allocate memory for path: %s\n",
+				strerror(errno));
+		return -1;
+	}
+
+	/*
+	 * open resource file, to mmap it
+	 */
+	fd = open(devname, O_RDWR);
+	if (fd < 0) {
+		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
+				devname, strerror(errno));
+		goto error;
+	}
+
+	/* if matching map is found, then use it */
+	offset = res_idx * pagesz;
+	mapaddr = pci_map_resource(NULL, fd, (off_t)offset,
+			(size_t)dev->mem_resource[res_idx].len, 0);
+	close(fd);
+	if (mapaddr == MAP_FAILED)
+		goto error;
+
+	maps[map_idx].phaddr = dev->mem_resource[res_idx].phys_addr;
+	maps[map_idx].size = dev->mem_resource[res_idx].len;
+	maps[map_idx].addr = mapaddr;
+	maps[map_idx].offset = offset;
+	strcpy(maps[map_idx].path, devname);
+	dev->mem_resource[res_idx].addr = mapaddr;
+
+	return 0;
+
+error:
+	rte_free(maps[map_idx].path);
+	return -1;
+}
+
 /* map the PCI resource of a PCI device in virtual memory */
 static int
 pci_uio_map_resource(struct rte_pci_device *dev)
 {
 	int i, map_idx = 0, ret;
-	char *devname;
-	void *mapaddr;
 	uint64_t phaddr;
-	uint64_t offset;
-	uint64_t pagesz;
 	struct mapped_pci_resource *uio_res = NULL;
 	struct mapped_pci_res_list *uio_res_list =
 		RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
-	struct pci_map *maps;
 
 	dev->intr_handle.fd = -1;
 	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
@@ -269,53 +322,17 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 		return ret;
 
 	/* Map all BARs */
-	pagesz = sysconf(_SC_PAGESIZE);
-	devname = uio_res->path;
-
-	maps = uio_res->maps;
 	for (i = 0; i != PCI_MAX_RESOURCE; i++) {
-		int fd;
-
 		/* skip empty BAR */
 		if ((phaddr = dev->mem_resource[i].phys_addr) == 0)
 			continue;
 
-		/* allocate memory to keep path */
-		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
-		if (maps[map_idx].path == NULL) {
-			RTE_LOG(ERR, EAL, "Cannot allocate memory for path: %s\n",
-					strerror(errno));
+		ret = pci_uio_map_resource_by_index(dev, i,
+				uio_res, map_idx);
+		if (ret != 0)
 			goto error;
-		}
 
-		/*
-		 * open resource file, to mmap it
-		 */
-		fd = open(devname, O_RDWR);
-		if (fd < 0) {
-			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
-					devname, strerror(errno));
-			rte_free(maps[map_idx].path);
-			goto error;
-		}
-
-		/* if matching map is found, then use it */
-		offset = i * pagesz;
-		mapaddr = pci_map_resource(NULL, fd, (off_t)offset,
-					(size_t)dev->mem_resource[i].len, 0);
-		close(fd);
-		if (mapaddr == MAP_FAILED) {
-			rte_free(maps[map_idx].path);
-			goto error;
-		}
-
-		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
-		maps[map_idx].size = dev->mem_resource[i].len;
-		maps[map_idx].addr = mapaddr;
-		maps[map_idx].offset = offset;
-		strcpy(maps[map_idx].path, devname);
 		map_idx++;
-		dev->mem_resource[i].addr = mapaddr;
 	}
 
 	uio_res->nb_maps = map_idx;
@@ -325,7 +342,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	return 0;
 error:
 	for (i = 0; i < map_idx; i++)
-		rte_free(maps[i].path);
+		rte_free(uio_res->maps[i].path);
 
 	/* 'uio_res' has valid value here */
 	rte_free(uio_res);
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index f408bd3..cafabba 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -333,19 +333,82 @@ error:
 	return -1;
 }
 
+static int
+pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
+		struct mapped_pci_resource *uio_res, int map_idx)
+{
+	int fd;
+	char devname[PATH_MAX]; /* contains the /dev/uioX */
+	void *mapaddr;
+	struct rte_pci_addr *loc;
+	struct pci_map *maps;
+
+	if ((dev == NULL) || (uio_res == NULL))
+		return -1;
+
+	loc = &dev->addr;
+	maps = uio_res->maps;
+
+	/* update devname for mmap  */
+	snprintf(devname, sizeof(devname),
+			SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/resource%d",
+			loc->domain, loc->bus, loc->devid,
+			loc->function, res_idx);
+
+	/* allocate memory to keep path */
+	maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
+	if (maps[map_idx].path == NULL) {
+		RTE_LOG(ERR, EAL, "Cannot allocate memory for path: %s\n",
+				strerror(errno));
+		return -1;
+	}
+
+	/*
+	 * open resource file, to mmap it
+	 */
+	fd = open(devname, O_RDWR);
+	if (fd < 0) {
+		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
+				devname, strerror(errno));
+		goto error;
+	}
+
+	/* try mapping somewhere close to the end of hugepages */
+	if (pci_map_addr == NULL)
+		pci_map_addr = pci_find_max_end_va();
+
+	mapaddr = pci_map_resource(pci_map_addr, fd, 0,
+			(size_t)dev->mem_resource[res_idx].len, 0);
+	close(fd);
+	if (mapaddr == MAP_FAILED)
+		goto error;
+
+	pci_map_addr = RTE_PTR_ADD(mapaddr,
+			(size_t)dev->mem_resource[res_idx].len);
+
+	maps[map_idx].phaddr = dev->mem_resource[res_idx].phys_addr;
+	maps[map_idx].size = dev->mem_resource[res_idx].len;
+	maps[map_idx].addr = mapaddr;
+	maps[map_idx].offset = 0;
+	strcpy(maps[map_idx].path, devname);
+	dev->mem_resource[res_idx].addr = mapaddr;
+
+	return 0;
+
+error:
+	rte_free(maps[map_idx].path);
+	return -1;
+}
+
 /* map the PCI resource of a PCI device in virtual memory */
 int
 pci_uio_map_resource(struct rte_pci_device *dev)
 {
 	int i, map_idx = 0, ret;
-	char devname[PATH_MAX]; /* contains the /dev/uioX */
-	void *mapaddr;
 	uint64_t phaddr;
-	struct rte_pci_addr *loc = &dev->addr;
 	struct mapped_pci_resource *uio_res = NULL;
 	struct mapped_pci_res_list *uio_res_list =
 		RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
-	struct pci_map *maps;
 
 	dev->intr_handle.fd = -1;
 	dev->intr_handle.uio_cfg_fd = -1;
@@ -361,63 +424,18 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 		return ret;
 
 	/* Map all BARs */
-	maps = uio_res->maps;
 	for (i = 0; i != PCI_MAX_RESOURCE; i++) {
-		int fd;
-
 		/* skip empty BAR */
 		phaddr = dev->mem_resource[i].phys_addr;
 		if (phaddr == 0)
 			continue;
 
-
-		/* update devname for mmap  */
-		snprintf(devname, sizeof(devname),
-				SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/resource%d",
-				loc->domain, loc->bus, loc->devid, loc->function,
-				i);
-
-		/* allocate memory to keep path */
-		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
-		if (maps[map_idx].path == NULL) {
-			RTE_LOG(ERR, EAL, "Cannot allocate memory for path: %s\n",
-					strerror(errno));
-			goto error;
-		}
-
-		/*
-		 * open resource file, to mmap it
-		 */
-		fd = open(devname, O_RDWR);
-		if (fd < 0) {
-			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
-					devname, strerror(errno));
-			rte_free(maps[map_idx].path);
+		ret = pci_uio_map_resource_by_index(dev, i,
+				uio_res, map_idx);
+		if (ret != 0)
 			goto error;
-		}
-
-		/* try mapping somewhere close to the end of hugepages */
-		if (pci_map_addr == NULL)
-			pci_map_addr = pci_find_max_end_va();
-
-		mapaddr = pci_map_resource(pci_map_addr, fd, 0,
-				(size_t)dev->mem_resource[i].len, 0);
-		close(fd);
-		if (mapaddr == MAP_FAILED) {
-			rte_free(maps[map_idx].path);
-			goto error;
-		}
-
-		pci_map_addr = RTE_PTR_ADD(mapaddr,
-				(size_t)dev->mem_resource[i].len);
 
-		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
-		maps[map_idx].size = dev->mem_resource[i].len;
-		maps[map_idx].addr = mapaddr;
-		maps[map_idx].offset = 0;
-		strcpy(maps[map_idx].path, devname);
 		map_idx++;
-		dev->mem_resource[i].addr = mapaddr;
 	}
 
 	uio_res->nb_maps = map_idx;
@@ -430,7 +448,7 @@ error:
 	for (i = 0; i < map_idx; i++) {
 		pci_unmap_resource(uio_res->maps[i].addr,
 				(size_t)uio_res->maps[i].size);
-		rte_free(maps[i].path);
+		rte_free(uio_res->maps[i].path);
 	}
 
 	/* 'uio_res' has valid value here */
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v8 08/12] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp
  2015-07-06  6:24               ` [dpdk-dev] [PATCH v8 00/12] Clean up pci uio implementations Tetsuya Mukawa
                                   ` (6 preceding siblings ...)
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 07/12] eal: Add pci_uio_map_resource_by_index() Tetsuya Mukawa
@ 2015-07-06  6:24                 ` Tetsuya Mukawa
  2015-07-07  8:05                   ` David Marchand
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 09/12] eal: Consolidate pci_map/unmap_resource() " Tetsuya Mukawa
                                   ` (3 subsequent siblings)
  11 siblings, 1 reply; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-06  6:24 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

This patch consolidates below structures, and defines them in common code.
 - struct pci_map
 - strucy mapped_pci_resouces

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c        | 24 ------------------------
 lib/librte_eal/common/include/rte_pci.h    | 29 +++++++++++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_pci_init.h | 23 -----------------------
 3 files changed, 29 insertions(+), 47 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index c76f936..6067e31 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -83,30 +83,6 @@
  * network card, only providing access to PCI BAR to applications, and
  * enabling bus master.
  */
-
-struct pci_map {
-	void *addr;
-	char *path;
-	uint64_t offset;
-	uint64_t size;
-	uint64_t phaddr;
-};
-
-/*
- * For multi-process we need to reproduce all PCI mappings in secondary
- * processes, so save them in a tailq.
- */
-struct mapped_pci_resource {
-	TAILQ_ENTRY(mapped_pci_resource) next;
-
-	struct rte_pci_addr pci_addr;
-	char path[PATH_MAX];
-	int nb_maps;
-	struct pci_map maps[PCI_MAX_RESOURCE];
-};
-
-TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource);
-
 static struct rte_tailq_elem rte_uio_tailq = {
 	.name = "UIO_RESOURCE_LIST",
 };
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index 7801fa0..d95747e 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -2,6 +2,7 @@
  *   BSD LICENSE
  *
  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2015 IGEL Co., Ltd.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -220,6 +221,34 @@ struct rte_pci_driver {
 /** Device driver supports detaching capability */
 #define RTE_PCI_DRV_DETACHABLE	0x0010
 
+/**
+ * A structure describing a PCI mapping.
+ */
+struct pci_map {
+	void *addr;
+	char *path;
+	uint64_t offset;
+	uint64_t size;
+	uint64_t phaddr;
+};
+
+/**
+ * A structure describing a mapped PCI resource.
+ * For multi-process we need to reproduce all PCI mappings in secondary
+ * processes, so save them in a tailq.
+ */
+struct mapped_pci_resource {
+	TAILQ_ENTRY(mapped_pci_resource) next;
+
+	struct rte_pci_addr pci_addr;
+	char path[PATH_MAX];
+	int nb_maps;
+	struct pci_map maps[PCI_MAX_RESOURCE];
+};
+
+/** mapped pci device list */
+TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource);
+
 /**< Internal use only - Macro used by pci addr parsing functions **/
 #define GET_PCIADDR_FIELD(in, fd, lim, dlm)                   \
 do {                                                               \
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
index aa7b755..d9d1878 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
@@ -36,29 +36,6 @@
 
 #include "eal_vfio.h"
 
-struct pci_map {
-	void *addr;
-	char *path;
-	uint64_t offset;
-	uint64_t size;
-	uint64_t phaddr;
-};
-
-/*
- * For multi-process we need to reproduce all PCI mappings in secondary
- * processes, so save them in a tailq.
- */
-struct mapped_pci_resource {
-	TAILQ_ENTRY(mapped_pci_resource) next;
-
-	struct rte_pci_addr pci_addr;
-	char path[PATH_MAX];
-	int nb_maps;
-	struct pci_map maps[PCI_MAX_RESOURCE];
-};
-
-TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource);
-
 /*
  * Helper function to map PCI resources right after hugepages in virtual memory
  */
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v8 09/12] eal: Consolidate pci_map/unmap_resource() of linuxapp and bsdapp
  2015-07-06  6:24               ` [dpdk-dev] [PATCH v8 00/12] Clean up pci uio implementations Tetsuya Mukawa
                                   ` (7 preceding siblings ...)
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 08/12] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp Tetsuya Mukawa
@ 2015-07-06  6:24                 ` Tetsuya Mukawa
  2015-07-07  8:05                   ` David Marchand
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 10/12] eal: Consolidate pci uio functions " Tetsuya Mukawa
                                   ` (2 subsequent siblings)
  11 siblings, 1 reply; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-06  6:24 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

The patch consolidates below functions, and implemented in common
eal code.
 - pci_map_resource()
 - pci_unmap_resource()

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c        | 22 ----------------
 lib/librte_eal/common/eal_common_pci.c     | 40 +++++++++++++++++++++++++++++
 lib/librte_eal/common/include/rte_pci.h    | 32 +++++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_pci.c      | 41 ------------------------------
 lib/librte_eal/linuxapp/eal/eal_pci_init.h |  5 ----
 5 files changed, 72 insertions(+), 68 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 6067e31..5bb93cd 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -97,28 +97,6 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)
 	return -ENOTSUP;
 }
 
-/* map a particular resource from a file */
-static void *
-pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
-		 int additional_flags)
-{
-	void *mapaddr;
-
-	/* Map the PCI memory resource of device */
-	mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
-			MAP_SHARED | additional_flags, fd, offset);
-	if (mapaddr == MAP_FAILED) {
-		RTE_LOG(ERR, EAL,
-			"%s(): cannot mmap(%d, %p, 0x%lx, 0x%lx): %s (%p)\n",
-			__func__, fd, requested_addr,
-			(unsigned long)size, (unsigned long)offset,
-			strerror(errno), mapaddr);
-	} else
-		RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
-
-	return mapaddr;
-}
-
 static int
 pci_uio_map_secondary(struct rte_pci_device *dev)
 {
diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 4229aaf..eab147a 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -2,6 +2,7 @@
  *   BSD LICENSE
  *
  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2015 IGEL Co., Ltd.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -67,6 +68,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <sys/queue.h>
+#include <sys/mman.h>
 
 #include <rte_interrupts.h>
 #include <rte_log.h>
@@ -98,6 +100,44 @@ static struct rte_devargs *pci_devargs_lookup(struct rte_pci_device *dev)
 	return NULL;
 }
 
+/* map a particular resource from a file */
+void *
+pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
+		 int additional_flags)
+{
+	void *mapaddr;
+
+	/* Map the PCI memory resource of device */
+	mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
+			MAP_SHARED | additional_flags, fd, offset);
+	if (mapaddr == MAP_FAILED) {
+		RTE_LOG(ERR, EAL, "%s(): cannot mmap(%d, %p, 0x%lx, 0x%lx): %s (%p)\n",
+			__func__, fd, requested_addr,
+			(unsigned long)size, (unsigned long)offset,
+			strerror(errno), mapaddr);
+	} else
+		RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
+
+	return mapaddr;
+}
+
+/* unmap a particular resource */
+void
+pci_unmap_resource(void *requested_addr, size_t size)
+{
+	if (requested_addr == NULL)
+		return;
+
+	/* Unmap the PCI memory resource of device */
+	if (munmap(requested_addr, size)) {
+		RTE_LOG(ERR, EAL, "%s(): cannot munmap(%p, 0x%lx): %s\n",
+			__func__, requested_addr, (unsigned long)size,
+			strerror(errno));
+	} else
+		RTE_LOG(DEBUG, EAL, "  PCI memory unmapped at %p\n",
+				requested_addr);
+}
+
 /*
  * If vendor/device ID match, call the devinit() function of all
  * registered driver for the given device. Return -1 if initialization
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index d95747e..4a4641c 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -365,6 +365,38 @@ int rte_eal_pci_scan(void);
  */
 int rte_eal_pci_probe(void);
 
+/**
+ * @internal
+ * Map a particular resource from a file.
+ *
+ * @param requested_addr
+ *      The starting address for the new mapping range.
+ * @param fd
+ *      The file descriptor.
+ * @param offset
+ *      The offset for the mapping range.
+ * @param size
+ *      The size for the mapping range.
+ * @param additional_flags
+ *      The additional flags for the mapping range.
+ * @return
+ *   - On success, the function returns a pointer to the mapped area.
+ *   - On error, the value MAP_FAILED is returned.
+ */
+void *pci_map_resource(void *requested_addr, int fd, off_t offset,
+		size_t size, int additional_flags);
+
+/**
+ * @internal
+ * Unmap a particular resource.
+ *
+ * @param requested_addr
+ *      The address for the unmapping range.
+ * @param size
+ *      The size for the unmapping range.
+ */
+void pci_unmap_resource(void *requested_addr, size_t size);
+
 #ifdef RTE_LIBRTE_EAL_HOTPLUG
 /**
  * Probe the single PCI device.
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index d2adc66..fc99eaa 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -33,7 +33,6 @@
 
 #include <string.h>
 #include <dirent.h>
-#include <sys/mman.h>
 
 #include <rte_log.h>
 #include <rte_pci.h>
@@ -142,46 +141,6 @@ pci_find_max_end_va(void)
 	return RTE_PTR_ADD(last->addr, last->len);
 }
 
-
-/* map a particular resource from a file */
-void *
-pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
-		 int additional_flags)
-{
-	void *mapaddr;
-
-	/* Map the PCI memory resource of device */
-	mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
-			MAP_SHARED | additional_flags, fd, offset);
-	if (mapaddr == MAP_FAILED) {
-		RTE_LOG(ERR, EAL, "%s(): cannot mmap(%d, %p, 0x%lx, 0x%lx): %s (%p)\n",
-			__func__, fd, requested_addr,
-			(unsigned long)size, (unsigned long)offset,
-			strerror(errno), mapaddr);
-	} else {
-		RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
-	}
-
-	return mapaddr;
-}
-
-/* unmap a particular resource */
-void
-pci_unmap_resource(void *requested_addr, size_t size)
-{
-	if (requested_addr == NULL)
-		return;
-
-	/* Unmap the PCI memory resource of device */
-	if (munmap(requested_addr, size)) {
-		RTE_LOG(ERR, EAL, "%s(): cannot munmap(%p, 0x%lx): %s\n",
-			__func__, requested_addr, (unsigned long)size,
-			strerror(errno));
-	} else
-		RTE_LOG(DEBUG, EAL, "  PCI memory unmapped at %p\n",
-				requested_addr);
-}
-
 /* parse the "resource" sysfs file */
 static int
 pci_parse_sysfs_resource(const char *filename, struct rte_pci_device *dev)
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
index d9d1878..d426b27 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
@@ -42,14 +42,9 @@
 extern void *pci_map_addr;
 void *pci_find_max_end_va(void);
 
-void *pci_map_resource(void *requested_addr, int fd, off_t offset,
-	       size_t size, int additional_flags);
-
 /* map IGB_UIO resource prototype */
 int pci_uio_map_resource(struct rte_pci_device *dev);
 
-void pci_unmap_resource(void *requested_addr, size_t size);
-
 #ifdef RTE_LIBRTE_EAL_HOTPLUG
 /* unmap IGB_UIO resource prototype */
 void pci_uio_unmap_resource(struct rte_pci_device *dev);
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v8 10/12] eal: Consolidate pci uio functions of linuxapp and bsdapp
  2015-07-06  6:24               ` [dpdk-dev] [PATCH v8 00/12] Clean up pci uio implementations Tetsuya Mukawa
                                   ` (8 preceding siblings ...)
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 09/12] eal: Consolidate pci_map/unmap_resource() " Tetsuya Mukawa
@ 2015-07-06  6:24                 ` Tetsuya Mukawa
  2015-07-07  8:07                   ` David Marchand
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 11/12] eal: Consolidate pci_map/unmap_device() " Tetsuya Mukawa
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 12/12] eal: Consolidate rte_eal_pci_probe/close_one_driver() " Tetsuya Mukawa
  11 siblings, 1 reply; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-06  6:24 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

The patch consolidates below functions, and implement these
in eal_common_pci_uio.c.
 - pci_uio_map_secondary()
 - pci_uio_map_resource()
 - pci_uio_unmap()
 - pci_uio_find_resource()
 - pci_uio_unmap_resource()

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/Makefile                 |   2 +
 lib/librte_eal/bsdapp/eal/eal_pci.c                | 110 +---------
 .../bsdapp/eal/include/exec-env/rte_interrupts.h   |   2 +
 lib/librte_eal/common/eal_common_pci_uio.c         | 240 +++++++++++++++++++++
 lib/librte_eal/common/eal_private.h                |  56 +++++
 lib/librte_eal/linuxapp/eal/Makefile               |   2 +
 lib/librte_eal/linuxapp/eal/eal_pci_init.h         |  12 +-
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c          | 196 +----------------
 8 files changed, 311 insertions(+), 309 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_pci_uio.c

diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile
index c73ffb6..0d72330 100644
--- a/lib/librte_eal/bsdapp/eal/Makefile
+++ b/lib/librte_eal/bsdapp/eal/Makefile
@@ -1,6 +1,7 @@
 #   BSD LICENSE
 #
 #   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
+#   Copyright(c) 2015 IGEL Co., Ltd.
 #   All rights reserved.
 #
 #   Redistribution and use in source and binary forms, with or without
@@ -68,6 +69,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_memzone.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_log.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_launch.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_pci.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_pci_uio.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_memory.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_tailqs.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_errno.c
diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 5bb93cd..f85fc1e 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -83,10 +83,6 @@
  * network card, only providing access to PCI BAR to applications, and
  * enabling bus master.
  */
-static struct rte_tailq_elem rte_uio_tailq = {
-	.name = "UIO_RESOURCE_LIST",
-};
-EAL_REGISTER_TAILQ(rte_uio_tailq)
 
 /* unbind kernel driver for this device */
 static int
@@ -97,53 +93,7 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)
 	return -ENOTSUP;
 }
 
-static int
-pci_uio_map_secondary(struct rte_pci_device *dev)
-{
-	int i, fd;
-	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list =
-			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
-
-	TAILQ_FOREACH(uio_res, uio_res_list, next) {
-
-		/* skip this element if it doesn't match our PCI address */
-		if (rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr))
-			continue;
-
-		for (i = 0; i != uio_res->nb_maps; i++) {
-			/*
-			 * open devname, to mmap it
-			 */
-			fd = open(uio_res->maps[i].path, O_RDWR);
-			if (fd < 0) {
-				RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
-					uio_res->maps[i].path, strerror(errno));
-				return -1;
-			}
-
-			void *mapaddr = pci_map_resource(uio_res->maps[i].addr,
-					fd, (off_t)uio_res->maps[i].offset,
-					(size_t)uio_res->maps[i].size, 0);
-			if (mapaddr != uio_res->maps[i].addr) {
-				RTE_LOG(ERR, EAL,
-					"Cannot mmap device resource file %s to address: %p\n",
-					uio_res->maps[i].path,
-					uio_res->maps[i].addr);
-				close(fd);
-				return -1;
-			}
-			/* fd is not needed in slave process, close it */
-			close(fd);
-		}
-		return 0;
-	}
-
-	RTE_LOG(ERR, EAL, "Cannot find resource for device\n");
-	return 1;
-}
-
-static int
+int
 pci_uio_alloc_resource(struct rte_pci_device *dev,
 		struct mapped_pci_resource **uio_res)
 {
@@ -195,7 +145,7 @@ error:
 	return -1;
 }
 
-static int
+int
 pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
 		struct mapped_pci_resource *uio_res, int map_idx)
 {
@@ -253,62 +203,6 @@ error:
 	return -1;
 }
 
-/* map the PCI resource of a PCI device in virtual memory */
-static int
-pci_uio_map_resource(struct rte_pci_device *dev)
-{
-	int i, map_idx = 0, ret;
-	uint64_t phaddr;
-	struct mapped_pci_resource *uio_res = NULL;
-	struct mapped_pci_res_list *uio_res_list =
-		RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
-
-	dev->intr_handle.fd = -1;
-	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
-
-	/* secondary processes - use already recorded details */
-	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
-		return pci_uio_map_secondary(dev);
-
-	/* allocate uio resource */
-	ret = pci_uio_alloc_resource(dev, &uio_res);
-	if ((ret != 0) || (uio_res == NULL))
-		return ret;
-
-	/* Map all BARs */
-	for (i = 0; i != PCI_MAX_RESOURCE; i++) {
-		/* skip empty BAR */
-		if ((phaddr = dev->mem_resource[i].phys_addr) == 0)
-			continue;
-
-		ret = pci_uio_map_resource_by_index(dev, i,
-				uio_res, map_idx);
-		if (ret != 0)
-			goto error;
-
-		map_idx++;
-	}
-
-	uio_res->nb_maps = map_idx;
-
-	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
-
-	return 0;
-error:
-	for (i = 0; i < map_idx; i++)
-		rte_free(uio_res->maps[i].path);
-
-	/* 'uio_res' has valid value here */
-	rte_free(uio_res);
-
-	/* 'fd' has valid value here */
-	close(dev->intr_handle.fd);
-	dev->intr_handle.fd = -1;
-	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
-
-	return -1;
-}
-
 /* Scan one pci sysfs entry, and fill the devices list from it. */
 static int
 pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
diff --git a/lib/librte_eal/bsdapp/eal/include/exec-env/rte_interrupts.h b/lib/librte_eal/bsdapp/eal/include/exec-env/rte_interrupts.h
index 87a9cf6..410dd21 100644
--- a/lib/librte_eal/bsdapp/eal/include/exec-env/rte_interrupts.h
+++ b/lib/librte_eal/bsdapp/eal/include/exec-env/rte_interrupts.h
@@ -2,6 +2,7 @@
  *   BSD LICENSE
  *
  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2015 IGEL Co., Ltd.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -48,6 +49,7 @@ enum rte_intr_handle_type {
 /** Handle for interrupts. */
 struct rte_intr_handle {
 	int fd;                          /**< file descriptor */
+	int uio_cfg_fd;                  /**< UIO config file descriptor */
 	enum rte_intr_handle_type type;  /**< handle type */
 };
 
diff --git a/lib/librte_eal/common/eal_common_pci_uio.c b/lib/librte_eal/common/eal_common_pci_uio.c
new file mode 100644
index 0000000..249a70b
--- /dev/null
+++ b/lib/librte_eal/common/eal_common_pci_uio.c
@@ -0,0 +1,240 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2015 IGEL Co., Ltd.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <fcntl.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+
+#include <rte_eal.h>
+#include <rte_tailq.h>
+#include <rte_log.h>
+#include <rte_malloc.h>
+
+#include "eal_private.h"
+
+static struct rte_tailq_elem rte_uio_tailq = {
+	.name = "UIO_RESOURCE_LIST",
+};
+EAL_REGISTER_TAILQ(rte_uio_tailq)
+
+static int
+pci_uio_map_secondary(struct rte_pci_device *dev)
+{
+	int fd, i;
+	struct mapped_pci_resource *uio_res;
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+
+	TAILQ_FOREACH(uio_res, uio_res_list, next) {
+
+		/* skip this element if it doesn't match our PCI address */
+		if (rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr))
+			continue;
+
+		for (i = 0; i != uio_res->nb_maps; i++) {
+			/*
+			 * open devname, to mmap it
+			 */
+			fd = open(uio_res->maps[i].path, O_RDWR);
+			if (fd < 0) {
+				RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
+					uio_res->maps[i].path, strerror(errno));
+				return -1;
+			}
+
+			void *mapaddr = pci_map_resource(uio_res->maps[i].addr,
+					fd, (off_t)uio_res->maps[i].offset,
+					(size_t)uio_res->maps[i].size, 0);
+			if (mapaddr != uio_res->maps[i].addr) {
+				RTE_LOG(ERR, EAL,
+					"Cannot mmap device resource file %s to address: %p\n",
+					uio_res->maps[i].path,
+					uio_res->maps[i].addr);
+				close(fd);
+				return -1;
+			}
+			/* fd is not needed in slave process, close it */
+			close(fd);
+		}
+		return 0;
+	}
+
+	RTE_LOG(ERR, EAL, "Cannot find resource for device\n");
+	return 1;
+}
+
+/* map the PCI resource of a PCI device in virtual memory */
+int
+pci_uio_map_resource(struct rte_pci_device *dev)
+{
+	int i, map_idx = 0, ret;
+	uint64_t phaddr;
+	struct mapped_pci_resource *uio_res = NULL;
+	struct mapped_pci_res_list *uio_res_list =
+		RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+
+	dev->intr_handle.fd = -1;
+	dev->intr_handle.uio_cfg_fd = -1;
+	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+
+	/* secondary processes - use already recorded details */
+	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+		return pci_uio_map_secondary(dev);
+
+	/* allocate uio resource */
+	ret = pci_uio_alloc_resource(dev, &uio_res);
+	if ((ret != 0) || (uio_res == NULL))
+		return ret;
+
+	/* Map all BARs */
+	for (i = 0; i != PCI_MAX_RESOURCE; i++) {
+		/* skip empty BAR */
+		phaddr = dev->mem_resource[i].phys_addr;
+		if (phaddr == 0)
+			continue;
+
+		ret = pci_uio_map_resource_by_index(dev, i,
+				uio_res, map_idx);
+		if (ret != 0)
+			goto error;
+
+		map_idx++;
+	}
+
+	uio_res->nb_maps = map_idx;
+
+	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
+
+	return 0;
+error:
+	for (i = 0; i < map_idx; i++) {
+		pci_unmap_resource(uio_res->maps[i].addr,
+				(size_t)uio_res->maps[i].size);
+		rte_free(uio_res->maps[i].path);
+	}
+
+	/* 'uio_res' has valid value here */
+	rte_free(uio_res);
+
+	/* 'uio_cfg_fd' may have invalid value */
+	if (dev->intr_handle.uio_cfg_fd >= 0) {
+		close(dev->intr_handle.uio_cfg_fd);
+		dev->intr_handle.uio_cfg_fd = -1;
+	}
+
+	/* 'fd' has valid value here */
+	close(dev->intr_handle.fd);
+	dev->intr_handle.fd = -1;
+	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+
+	return -1;
+}
+
+#ifdef RTE_LIBRTE_EAL_HOTPLUG
+static void
+pci_uio_unmap(struct mapped_pci_resource *uio_res)
+{
+	int i;
+
+	if (uio_res == NULL)
+		return;
+
+	for (i = 0; i != uio_res->nb_maps; i++) {
+		pci_unmap_resource(uio_res->maps[i].addr,
+				(size_t)uio_res->maps[i].size);
+		rte_free(uio_res->maps[i].path);
+	}
+}
+
+static struct mapped_pci_resource *
+pci_uio_find_resource(struct rte_pci_device *dev)
+{
+	struct mapped_pci_resource *uio_res;
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+
+	if (dev == NULL)
+		return NULL;
+
+	TAILQ_FOREACH(uio_res, uio_res_list, next) {
+
+		/* skip this element if it doesn't match our PCI address */
+		if (!rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr))
+			return uio_res;
+	}
+	return NULL;
+}
+
+/* unmap the PCI resource of a PCI device in virtual memory */
+void
+pci_uio_unmap_resource(struct rte_pci_device *dev)
+{
+	struct mapped_pci_resource *uio_res;
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+
+	if (dev == NULL)
+		return;
+
+	/* find an entry for the device */
+	uio_res = pci_uio_find_resource(dev);
+	if (uio_res == NULL)
+		return;
+
+	/* secondary processes - just free maps */
+	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+		return pci_uio_unmap(uio_res);
+
+	TAILQ_REMOVE(uio_res_list, uio_res, next);
+
+	/* unmap all resources */
+	pci_uio_unmap(uio_res);
+
+	/* free uio resource */
+	rte_free(uio_res);
+
+	/* close fd if in primary process */
+	close(dev->intr_handle.fd);
+	if (dev->intr_handle.uio_cfg_fd >= 0) {
+		close(dev->intr_handle.uio_cfg_fd);
+		dev->intr_handle.uio_cfg_fd = -1;
+	}
+
+	dev->intr_handle.fd = -1;
+	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+}
+#endif /* RTE_LIBRTE_EAL_HOTPLUG */
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 4acf5a0..4125589 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -2,6 +2,7 @@
  *   BSD LICENSE
  *
  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2015 IGEL Co., Ltd.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -35,6 +36,7 @@
 #define _EAL_PRIVATE_H_
 
 #include <stdio.h>
+#include <rte_pci.h>
 
 /**
  * Initialize the memzone subsystem (private to eal).
@@ -154,6 +156,25 @@ struct rte_pci_driver;
 struct rte_pci_device;
 
 /**
+ * Map the PCI resource of a PCI device in virtual memory
+ *
+ * This function is private to EAL.
+ *
+ * @return
+ *   0 on success, negative on error
+ */
+int pci_uio_map_resource(struct rte_pci_device *dev);
+
+#ifdef RTE_LIBRTE_EAL_HOTPLUG
+/**
+ * Unmap the PCI resource of a PCI device
+ *
+ * This function is private to EAL.
+ */
+void pci_uio_unmap_resource(struct rte_pci_device *dev);
+#endif /* RTE_LIBRTE_EAL_HOTPLUG */
+
+/**
  * Mmap memory for single PCI device
  *
  * This function is private to EAL.
@@ -180,6 +201,41 @@ int rte_eal_pci_close_one_driver(struct rte_pci_driver *dr,
 		struct rte_pci_device *dev);
 
 /**
+ * Allocate uio resource for PCI device
+ *
+ * This function is private to EAL.
+ *
+ * @param dev
+ *   PCI device to allocate uio resource
+ * @param uio_res
+ *   Pointer to uio resource.
+ *   If the function returns 0, the pointer will be filled.
+ * @return
+ *   0 on success, negative on error
+ */
+int pci_uio_alloc_resource(struct rte_pci_device *dev,
+		struct mapped_pci_resource **uio_res);
+
+/**
+ * Map device memory to uio resource
+ *
+ * This function is private to EAL.
+ *
+ * @param dev
+ *   PCI device that has memory information.
+ * @param res_idx
+ *   Memory resource index of the PCI device.
+ * @param uio_res
+ *  uio resource that will keep mapping information.
+ * @param map_idx
+ *   Mapping information index of the uio resource.
+ * @return
+ *   0 on success, negative on error
+ */
+int pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
+		struct mapped_pci_resource *uio_res, int map_idx);
+
+/**
  * Init tail queues for non-EAL library structures. This is to allow
  * the rings, mempools, etc. lists to be shared among multiple processes
  *
diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
index e99d7a3..92900d6 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -1,6 +1,7 @@
 #   BSD LICENSE
 #
 #   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
+#   Copyright(c) 2015 IGEL Co., Ltd.
 #   All rights reserved.
 #
 #   Redistribution and use in source and binary forms, with or without
@@ -80,6 +81,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_memzone.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_log.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_launch.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_pci.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_pci_uio.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_memory.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_tailqs.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_errno.c
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
index d426b27..51783f0 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
@@ -2,6 +2,7 @@
  *   BSD LICENSE
  *
  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2015 IGEL Co., Ltd.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -42,13 +43,10 @@
 extern void *pci_map_addr;
 void *pci_find_max_end_va(void);
 
-/* map IGB_UIO resource prototype */
-int pci_uio_map_resource(struct rte_pci_device *dev);
-
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
-/* unmap IGB_UIO resource prototype */
-void pci_uio_unmap_resource(struct rte_pci_device *dev);
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
+int pci_uio_alloc_resource(struct rte_pci_device *dev,
+		struct mapped_pci_resource **uio_res);
+int pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
+		struct mapped_pci_resource *uio_res, int map_idx);
 
 #ifdef VFIO_PRESENT
 
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index cafabba..3dfc17b 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -52,11 +52,6 @@
 
 void *pci_map_addr = NULL;
 
-static struct rte_tailq_elem rte_uio_tailq = {
-	.name = "UIO_RESOURCE_LIST",
-};
-EAL_REGISTER_TAILQ(rte_uio_tailq)
-
 #define OFF_MAX              ((uint64_t)(off_t)-1)
 
 static int
@@ -89,52 +84,6 @@ pci_uio_set_bus_master(int dev_fd)
 }
 
 static int
-pci_uio_map_secondary(struct rte_pci_device *dev)
-{
-	int fd, i;
-	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list =
-			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
-
-	TAILQ_FOREACH(uio_res, uio_res_list, next) {
-
-		/* skip this element if it doesn't match our PCI address */
-		if (rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr))
-			continue;
-
-		for (i = 0; i != uio_res->nb_maps; i++) {
-			/*
-			 * open devname, to mmap it
-			 */
-			fd = open(uio_res->maps[i].path, O_RDWR);
-			if (fd < 0) {
-				RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
-					uio_res->maps[i].path, strerror(errno));
-				return -1;
-			}
-
-			void *mapaddr = pci_map_resource(uio_res->maps[i].addr,
-					fd, (off_t)uio_res->maps[i].offset,
-					(size_t)uio_res->maps[i].size, 0);
-			if (mapaddr != uio_res->maps[i].addr) {
-				RTE_LOG(ERR, EAL,
-					"Cannot mmap device resource file %s to address: %p\n",
-					uio_res->maps[i].path,
-					uio_res->maps[i].addr);
-				close(fd);
-				return -1;
-			}
-			/* fd is not needed in slave process, close it */
-			close(fd);
-		}
-		return 0;
-	}
-
-	RTE_LOG(ERR, EAL, "Cannot find resource for device\n");
-	return 1;
-}
-
-static int
 pci_mknod_uio_dev(const char *sysfs_uio_path, unsigned uio_num)
 {
 	FILE *f;
@@ -254,7 +203,7 @@ pci_get_uio_dev(struct rte_pci_device *dev, char *dstbuf,
 	return uio_num;
 }
 
-static int
+int
 pci_uio_alloc_resource(struct rte_pci_device *dev,
 		struct mapped_pci_resource **uio_res)
 {
@@ -333,7 +282,7 @@ error:
 	return -1;
 }
 
-static int
+int
 pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
 		struct mapped_pci_resource *uio_res, int map_idx)
 {
@@ -399,144 +348,3 @@ error:
 	rte_free(maps[map_idx].path);
 	return -1;
 }
-
-/* map the PCI resource of a PCI device in virtual memory */
-int
-pci_uio_map_resource(struct rte_pci_device *dev)
-{
-	int i, map_idx = 0, ret;
-	uint64_t phaddr;
-	struct mapped_pci_resource *uio_res = NULL;
-	struct mapped_pci_res_list *uio_res_list =
-		RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
-
-	dev->intr_handle.fd = -1;
-	dev->intr_handle.uio_cfg_fd = -1;
-	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
-
-	/* secondary processes - use already recorded details */
-	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
-		return pci_uio_map_secondary(dev);
-
-	/* allocate uio resource */
-	ret = pci_uio_alloc_resource(dev, &uio_res);
-	if ((ret != 0) || (uio_res == NULL))
-		return ret;
-
-	/* Map all BARs */
-	for (i = 0; i != PCI_MAX_RESOURCE; i++) {
-		/* skip empty BAR */
-		phaddr = dev->mem_resource[i].phys_addr;
-		if (phaddr == 0)
-			continue;
-
-		ret = pci_uio_map_resource_by_index(dev, i,
-				uio_res, map_idx);
-		if (ret != 0)
-			goto error;
-
-		map_idx++;
-	}
-
-	uio_res->nb_maps = map_idx;
-
-	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
-
-	return 0;
-
-error:
-	for (i = 0; i < map_idx; i++) {
-		pci_unmap_resource(uio_res->maps[i].addr,
-				(size_t)uio_res->maps[i].size);
-		rte_free(uio_res->maps[i].path);
-	}
-
-	/* 'uio_res' has valid value here */
-	rte_free(uio_res);
-
-	/* 'uio_cfg_fd' has valid value here */
-	close(dev->intr_handle.uio_cfg_fd);
-	dev->intr_handle.uio_cfg_fd = -1;
-
-	/* 'fd' has valid value here */
-	close(dev->intr_handle.fd);
-	dev->intr_handle.fd = -1;
-	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
-
-	return -1;
-}
-
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
-static void
-pci_uio_unmap(struct mapped_pci_resource *uio_res)
-{
-	int i;
-
-	if (uio_res == NULL)
-		return;
-
-	for (i = 0; i != uio_res->nb_maps; i++) {
-		pci_unmap_resource(uio_res->maps[i].addr,
-				(size_t)uio_res->maps[i].size);
-		rte_free(uio_res->maps[i].path);
-	}
-}
-
-static struct mapped_pci_resource *
-pci_uio_find_resource(struct rte_pci_device *dev)
-{
-	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list =
-			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
-
-	if (dev == NULL)
-		return NULL;
-
-	TAILQ_FOREACH(uio_res, uio_res_list, next) {
-
-		/* skip this element if it doesn't match our PCI address */
-		if (!rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr))
-			return uio_res;
-	}
-	return NULL;
-}
-
-/* unmap the PCI resource of a PCI device in virtual memory */
-void
-pci_uio_unmap_resource(struct rte_pci_device *dev)
-{
-	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list =
-			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
-
-	if (dev == NULL)
-		return;
-
-	/* find an entry for the device */
-	uio_res = pci_uio_find_resource(dev);
-	if (uio_res == NULL)
-		return;
-
-	/* secondary processes - just free maps */
-	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
-		return pci_uio_unmap(uio_res);
-
-	TAILQ_REMOVE(uio_res_list, uio_res, next);
-
-	/* unmap all resources */
-	pci_uio_unmap(uio_res);
-
-	/* free uio resource */
-	rte_free(uio_res);
-
-	/* close fd if in primary process */
-	close(dev->intr_handle.fd);
-	dev->intr_handle.fd = -1;
-
-	/* close cfg_fd if in primary process */
-	close(dev->intr_handle.uio_cfg_fd);
-	dev->intr_handle.uio_cfg_fd = -1;
-
-	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
-}
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v8 11/12] eal: Consolidate pci_map/unmap_device() of linuxapp and bsdapp
  2015-07-06  6:24               ` [dpdk-dev] [PATCH v8 00/12] Clean up pci uio implementations Tetsuya Mukawa
                                   ` (9 preceding siblings ...)
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 10/12] eal: Consolidate pci uio functions " Tetsuya Mukawa
@ 2015-07-06  6:24                 ` Tetsuya Mukawa
  2015-07-07  8:06                   ` David Marchand
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 12/12] eal: Consolidate rte_eal_pci_probe/close_one_driver() " Tetsuya Mukawa
  11 siblings, 1 reply; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-06  6:24 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

The patch consolidates below functions, and implemented in common
eal code.
 - pci_map_device()
 - pci_unmap_device()

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c     |  3 ++
 lib/librte_eal/common/eal_common_pci.c  | 57 +++++++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_private.h     | 19 +++++++++++
 lib/librte_eal/common/include/rte_pci.h |  1 +
 lib/librte_eal/linuxapp/eal/eal_pci.c   | 53 ------------------------------
 lib/librte_ether/rte_ethdev.c           |  2 ++
 6 files changed, 82 insertions(+), 53 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index f85fc1e..a27dca3 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -240,6 +240,9 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
 	/* FreeBSD has no NUMA support (yet) */
 	dev->numa_node = 0;
 
+	/* FreeBSD has only one pass through driver */
+	dev->kdrv = RTE_KDRV_NIC_UIO;
+
 	/* parse resources */
 	switch (conf->pc_hdr & PCIM_HDRTYPE) {
 	case PCIM_HDRTYPE_NORMAL:
diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index eab147a..afd14ec 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -138,6 +138,63 @@ pci_unmap_resource(void *requested_addr, size_t size)
 				requested_addr);
 }
 
+/* Map pci device */
+int
+pci_map_device(struct rte_pci_device *dev)
+{
+	int ret = -1;
+
+	/* try mapping the NIC resources using VFIO if it exists */
+	switch (dev->kdrv) {
+	case RTE_KDRV_VFIO:
+#ifdef VFIO_PRESENT
+		if (pci_vfio_is_enabled())
+			ret = pci_vfio_map_resource(dev);
+#endif
+		break;
+	case RTE_KDRV_IGB_UIO:
+	case RTE_KDRV_UIO_GENERIC:
+	case RTE_KDRV_NIC_UIO:
+		/* map resources for devices that use uio */
+		ret = pci_uio_map_resource(dev);
+		break;
+	default:
+		RTE_LOG(DEBUG, EAL, "  Not managed by a supported kernel driver,"
+			" skipped\n");
+		ret = 1;
+		break;
+	}
+
+	return ret;
+}
+
+#ifdef RTE_LIBRTE_EAL_HOTPLUG
+/* Unmap pci device */
+void
+pci_unmap_device(struct rte_pci_device *dev)
+{
+	if (dev == NULL)
+		return;
+
+	/* try unmapping the NIC resources using VFIO if it exists */
+	switch (dev->kdrv) {
+	case RTE_KDRV_VFIO:
+		RTE_LOG(ERR, EAL, "Hotplug doesn't support vfio yet\n");
+		break;
+	case RTE_KDRV_IGB_UIO:
+	case RTE_KDRV_UIO_GENERIC:
+	case RTE_KDRV_NIC_UIO:
+		/* unmap resources for devices that use uio */
+		pci_uio_unmap_resource(dev);
+		break;
+	default:
+		RTE_LOG(DEBUG, EAL, "  Not managed by a supported kernel driver,"
+			" skipped\n");
+		break;
+	}
+}
+#endif /* RTE_LIBRTE_EAL_HOTPLUG */
+
 /*
  * If vendor/device ID match, call the devinit() function of all
  * registered driver for the given device. Return -1 if initialization
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 4125589..95b9e30 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -156,6 +156,25 @@ struct rte_pci_driver;
 struct rte_pci_device;
 
 /**
+ * Map this device
+ *
+ * This function is private to EAL.
+ *
+ * @return
+ *   0 on success, negative on error
+ */
+int pci_map_device(struct rte_pci_device *dev);
+
+#ifdef RTE_LIBRTE_EAL_HOTPLUG
+/**
+ * Unmap this device
+ *
+ * This function is private to EAL.
+ */
+void pci_unmap_device(struct rte_pci_device *dev);
+#endif /* RTE_LIBRTE_EAL_HOTPLUG */
+
+/**
  * Map the PCI resource of a PCI device in virtual memory
  *
  * This function is private to EAL.
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index 4a4641c..1f09252 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -149,6 +149,7 @@ enum rte_kernel_driver {
 	RTE_KDRV_IGB_UIO,
 	RTE_KDRV_VFIO,
 	RTE_KDRV_UIO_GENERIC,
+	RTE_KDRV_NIC_UIO,
 };
 
 /**
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index fc99eaa..7e8df7d 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -522,59 +522,6 @@ pci_config_space_set(struct rte_pci_device *dev)
 }
 #endif
 
-static int
-pci_map_device(struct rte_pci_device *dev)
-{
-	int ret = -1;
-
-	/* try mapping the NIC resources using VFIO if it exists */
-	switch (dev->kdrv) {
-	case RTE_KDRV_VFIO:
-#ifdef VFIO_PRESENT
-		if (pci_vfio_is_enabled())
-			ret = pci_vfio_map_resource(dev);
-#endif
-		break;
-	case RTE_KDRV_IGB_UIO:
-	case RTE_KDRV_UIO_GENERIC:
-		/* map resources for devices that use uio */
-		ret = pci_uio_map_resource(dev);
-		break;
-	default:
-		RTE_LOG(DEBUG, EAL, "  Not managed by a supported kernel driver,"
-			" skipped\n");
-		ret = 1;
-		break;
-	}
-
-	return ret;
-}
-
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
-static void
-pci_unmap_device(struct rte_pci_device *dev)
-{
-	if (dev == NULL)
-		return;
-
-	/* try unmapping the NIC resources using VFIO if it exists */
-	switch (dev->kdrv) {
-	case RTE_KDRV_VFIO:
-		RTE_LOG(ERR, EAL, "Hotplug doesn't support vfio yet\n");
-		break;
-	case RTE_KDRV_IGB_UIO:
-	case RTE_KDRV_UIO_GENERIC:
-		/* unmap resources for devices that use uio */
-		pci_uio_unmap_resource(dev);
-		break;
-	default:
-		RTE_LOG(DEBUG, EAL, "  Not managed by a supported kernel driver,"
-			" skipped\n");
-		break;
-	}
-}
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
-
 /*
  * If vendor/device ID match, call the devinit() function of the
  * driver.
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index da915db..7b24e26 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -2,6 +2,7 @@
  *   BSD LICENSE
  *
  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2015 IGEL Co., Ltd.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -527,6 +528,7 @@ rte_eth_dev_is_detachable(uint8_t port_id)
 		switch (rte_eth_devices[port_id].pci_dev->kdrv) {
 		case RTE_KDRV_IGB_UIO:
 		case RTE_KDRV_UIO_GENERIC:
+		case RTE_KDRV_NIC_UIO:
 			break;
 		case RTE_KDRV_VFIO:
 		default:
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v8 12/12] eal: Consolidate rte_eal_pci_probe/close_one_driver() of linuxapp and bsdapp
  2015-07-06  6:24               ` [dpdk-dev] [PATCH v8 00/12] Clean up pci uio implementations Tetsuya Mukawa
                                   ` (10 preceding siblings ...)
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 11/12] eal: Consolidate pci_map/unmap_device() " Tetsuya Mukawa
@ 2015-07-06  6:24                 ` Tetsuya Mukawa
  2015-07-07  8:07                   ` David Marchand
  11 siblings, 1 reply; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-06  6:24 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

This patch consolidates below functions, and implements these in common
eal code.
 - rte_eal_pci_probe_one_driver()
 - rte_eal_pci_close_one_driver()

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c    |  67 +--------------
 lib/librte_eal/common/eal_common_pci.c | 133 +++++++++++++++++++++++++++++-
 lib/librte_eal/common/eal_private.h    |  39 +--------
 lib/librte_eal/linuxapp/eal/eal_pci.c  | 143 +--------------------------------
 4 files changed, 136 insertions(+), 246 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index a27dca3..b7c34f4 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -85,7 +85,7 @@
  */
 
 /* unbind kernel driver for this device */
-static int
+int
 pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)
 {
 	RTE_LOG(ERR, EAL, "RTE_PCI_DRV_FORCE_UNBIND flag is not implemented "
@@ -357,71 +357,6 @@ error:
 	return -1;
 }
 
-/*
- * If vendor/device ID match, call the devinit() function of the
- * driver.
- */
-int
-rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dev)
-{
-	const struct rte_pci_id *id_table;
-	int ret;
-
-	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",
-				loc->domain, loc->bus, loc->devid, loc->function,
-				dev->numa_node);
-
-		RTE_LOG(DEBUG, EAL, "  probe driver: %x:%x %s\n", dev->id.vendor_id,
-				dev->id.device_id, dr->name);
-
-		/* no initialization when blacklisted, return without error */
-		if (dev->devargs != NULL &&
-			dev->devargs->type == RTE_DEVTYPE_BLACKLISTED_PCI) {
-
-			RTE_LOG(DEBUG, EAL, "  Device is blacklisted, not initializing\n");
-			return 0;
-		}
-
-		if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) {
-			/* map resources for devices that use igb_uio */
-			ret = pci_uio_map_resource(dev);
-			if (ret != 0)
-				return ret;
-		} else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND &&
-		           rte_eal_process_type() == RTE_PROC_PRIMARY) {
-			/* unbind current driver */
-			if (pci_unbind_kernel_driver(dev) < 0)
-				return -1;
-		}
-
-		/* reference driver structure */
-		dev->driver = dr;
-
-		/* call the driver devinit() function */
-		return dr->devinit(dr, dev);
-	}
-	/* return positive value if driver is not found */
-	return 1;
-}
-
 /* Init the PCI EAL subsystem */
 int
 rte_eal_pci_init(void)
diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index afd14ec..031c7a7 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -139,7 +139,7 @@ pci_unmap_resource(void *requested_addr, size_t size)
 }
 
 /* Map pci device */
-int
+static int
 pci_map_device(struct rte_pci_device *dev)
 {
 	int ret = -1;
@@ -170,7 +170,7 @@ pci_map_device(struct rte_pci_device *dev)
 
 #ifdef RTE_LIBRTE_EAL_HOTPLUG
 /* Unmap pci device */
-void
+static void
 pci_unmap_device(struct rte_pci_device *dev)
 {
 	if (dev == NULL)
@@ -196,6 +196,135 @@ pci_unmap_device(struct rte_pci_device *dev)
 #endif /* RTE_LIBRTE_EAL_HOTPLUG */
 
 /*
+ * 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;
+	const struct rte_pci_id *id_table;
+
+	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",
+				loc->domain, loc->bus, loc->devid, loc->function,
+				dev->numa_node);
+
+		RTE_LOG(DEBUG, EAL, "  probe driver: %x:%x %s\n", dev->id.vendor_id,
+				dev->id.device_id, dr->name);
+
+		/* no initialization when blacklisted, return without error */
+		if (dev->devargs != NULL &&
+			dev->devargs->type == RTE_DEVTYPE_BLACKLISTED_PCI) {
+			RTE_LOG(DEBUG, EAL, "  Device is blacklisted, not initializing\n");
+			return 1;
+		}
+
+		if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) {
+#ifdef RTE_PCI_CONFIG
+			/*
+			 * Set PCIe config space for high performance.
+			 * Return value can be ignored.
+			 */
+			pci_config_space_set(dev);
+#endif
+			/* map resources for devices that use igb_uio */
+			ret = pci_map_device(dev);
+			if (ret != 0)
+				return ret;
+		} else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND &&
+				rte_eal_process_type() == RTE_PROC_PRIMARY) {
+			/* unbind current driver */
+			if (pci_unbind_kernel_driver(dev) < 0)
+				return -1;
+		}
+
+		/* reference driver structure */
+		dev->driver = dr;
+
+		/* call the driver devinit() function */
+		return dr->devinit(dr, dev);
+	}
+	/* return positive value if driver is not found */
+	return 1;
+}
+
+#ifdef RTE_LIBRTE_EAL_HOTPLUG
+/*
+ * If vendor/device ID match, call the devuninit() function of the
+ * driver.
+ */
+static int
+rte_eal_pci_close_one_driver(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",
+				loc->domain, loc->bus, loc->devid,
+				loc->function, dev->numa_node);
+
+		RTE_LOG(DEBUG, EAL, "  remove driver: %x:%x %s\n", dev->id.vendor_id,
+				dev->id.device_id, dr->name);
+
+		/* call the driver devuninit() function */
+		if (dr->devuninit && (dr->devuninit(dev) < 0))
+			return -1;	/* negative value is an error */
+
+		/* clear driver structure */
+		dev->driver = NULL;
+
+		if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING)
+			/* unmap resources for devices that use igb_uio */
+			pci_unmap_device(dev);
+
+		return 0;
+	}
+
+	/* return positive value if driver is not found */
+	return 1;
+}
+#endif /* RTE_LIBRTE_EAL_HOTPLUG */
+
+/*
  * 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.
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 95b9e30..c3659e2 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -156,23 +156,14 @@ struct rte_pci_driver;
 struct rte_pci_device;
 
 /**
- * Map this device
+ * Unbind kernel driver for this device
  *
  * This function is private to EAL.
  *
  * @return
  *   0 on success, negative on error
  */
-int pci_map_device(struct rte_pci_device *dev);
-
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
-/**
- * Unmap this device
- *
- * This function is private to EAL.
- */
-void pci_unmap_device(struct rte_pci_device *dev);
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
+int pci_unbind_kernel_driver(struct rte_pci_device *dev);
 
 /**
  * Map the PCI resource of a PCI device in virtual memory
@@ -194,32 +185,6 @@ void pci_uio_unmap_resource(struct rte_pci_device *dev);
 #endif /* RTE_LIBRTE_EAL_HOTPLUG */
 
 /**
- * Mmap memory for single PCI device
- *
- * This function is private to EAL.
- *
- * @return
- *   0 on success, negative on error
- */
-int rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr,
-		struct rte_pci_device *dev);
-
-/**
- * Munmap memory for single PCI device
- *
- * This function is private to EAL.
- *
- * @param	dr
- *  The pointer to the pci driver structure
- * @param	dev
- *  The pointer to the pci device structure
- * @return
- *   0 on success, negative on error
- */
-int rte_eal_pci_close_one_driver(struct rte_pci_driver *dr,
-		struct rte_pci_device *dev);
-
-/**
  * Allocate uio resource for PCI device
  *
  * 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 7e8df7d..ad6d1de 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -2,6 +2,7 @@
  *   BSD LICENSE
  *
  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2015 IGEL Co., Ltd.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -56,7 +57,7 @@
  */
 
 /* unbind kernel driver for this device */
-static int
+int
 pci_unbind_kernel_driver(struct rte_pci_device *dev)
 {
 	int n;
@@ -522,146 +523,6 @@ pci_config_space_set(struct rte_pci_device *dev)
 }
 #endif
 
-/*
- * If vendor/device ID match, call the devinit() function of the
- * driver.
- */
-int
-rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, 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++) {
-
-		/* 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",
-				loc->domain, loc->bus, loc->devid, loc->function,
-				dev->numa_node);
-
-		RTE_LOG(DEBUG, EAL, "  probe driver: %x:%x %s\n", dev->id.vendor_id,
-				dev->id.device_id, dr->name);
-
-		/* no initialization when blacklisted, return without error */
-		if (dev->devargs != NULL &&
-			dev->devargs->type == RTE_DEVTYPE_BLACKLISTED_PCI) {
-			RTE_LOG(DEBUG, EAL, "  Device is blacklisted, not initializing\n");
-			return 1;
-		}
-
-		if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) {
-#ifdef RTE_PCI_CONFIG
-			/*
-			 * Set PCIe config space for high performance.
-			 * Return value can be ignored.
-			 */
-			pci_config_space_set(dev);
-#endif
-			/* map resources for devices that use igb_uio */
-			ret = pci_map_device(dev);
-			if (ret != 0)
-				return ret;
-		} else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND &&
-		           rte_eal_process_type() == RTE_PROC_PRIMARY) {
-			/* unbind current driver */
-			if (pci_unbind_kernel_driver(dev) < 0)
-				return -1;
-		}
-
-		/* reference driver structure */
-		dev->driver = dr;
-
-		/* call the driver devinit() function */
-		return dr->devinit(dr, dev);
-	}
-	/* return positive value if driver is not found */
-	return 1;
-}
-
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
-/*
- * If vendor/device ID match, call the devuninit() function of the
- * driver.
- */
-int
-rte_eal_pci_close_one_driver(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",
-				loc->domain, loc->bus, loc->devid,
-				loc->function, dev->numa_node);
-
-		RTE_LOG(DEBUG, EAL, "  remove driver: %x:%x %s\n",
-				dev->id.vendor_id, dev->id.device_id,
-				dr->name);
-
-		/* call the driver devuninit() function */
-		if (dr->devuninit && (dr->devuninit(dev) < 0))
-			return -1;	/* negative value is an error */
-
-		/* clear driver structure */
-		dev->driver = NULL;
-
-		if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING)
-			/* unmap resources for devices that use igb_uio */
-			pci_unmap_device(dev);
-
-		return 0;
-	}
-	/* return positive value if driver is not found */
-	return 1;
-}
-#else /* RTE_LIBRTE_EAL_HOTPLUG */
-int
-rte_eal_pci_close_one_driver(struct rte_pci_driver *dr __rte_unused,
-		struct rte_pci_device *dev __rte_unused)
-{
-	RTE_LOG(ERR, EAL, "Hotplug support isn't enabled\n");
-	return -1;
-}
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
-
 /* Init the PCI EAL subsystem */
 int
 rte_eal_pci_init(void)
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v8 01/12] eal: Fix coding style of eal_pci.c and eal_pci_uio.c
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 01/12] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
@ 2015-07-07  8:04                   ` David Marchand
  2015-07-08  2:42                     ` Tetsuya Mukawa
  0 siblings, 1 reply; 120+ messages in thread
From: David Marchand @ 2015-07-07  8:04 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Mon, Jul 6, 2015 at 8:24 AM, Tetsuya Mukawa <mukawa@igel.co.jp> wrote:

> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
>
> This patch fixes coding style of below files in linuxapp and bsdapp.
>  - eal_pci.c
>  - eal_pci_uio.c
>
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> Acked-by: Stephen Hemminger <stephen@networkplumber.org>
>

Acked-by: David Marchand <david.marchand@6wind.com>

I think I already acked this, please can you keep the ack tags (even if
this is a trivial patch) ?


-- 
David Marchand

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v8 02/12] eal: Close file descriptor of uio configuration
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 02/12] eal: Close file descriptor of uio configuration Tetsuya Mukawa
@ 2015-07-07  8:04                   ` David Marchand
  0 siblings, 0 replies; 120+ messages in thread
From: David Marchand @ 2015-07-07  8:04 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Mon, Jul 6, 2015 at 8:24 AM, Tetsuya Mukawa <mukawa@igel.co.jp> wrote:

> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
>
> When pci_uio_unmap_resource() is called, a file descriptor that is used
> for uio configuration should be closed.
>
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> Acked-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> index 5915a84..37dc936 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> @@ -465,8 +465,12 @@ pci_uio_unmap_resource(struct rte_pci_device *dev)
>
>         /* close fd if in primary process */
>         close(dev->intr_handle.fd);
> -
>         dev->intr_handle.fd = -1;
> +
> +       /* close cfg_fd if in primary process */
> +       close(dev->intr_handle.uio_cfg_fd);
> +       dev->intr_handle.uio_cfg_fd = -1;
> +
>         dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
>  }
>  #endif /* RTE_LIBRTE_EAL_HOTPLUG */
> --
> 2.1.4
>
>

Acked-by: David Marchand <david.marchand@6wind.com>

-- 
David Marchand

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v8 03/12] eal: Fix memory leaks and needless increment of pci_map_addr
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 03/12] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
@ 2015-07-07  8:04                   ` David Marchand
  2015-07-08  2:42                     ` Tetsuya Mukawa
  0 siblings, 1 reply; 120+ messages in thread
From: David Marchand @ 2015-07-07  8:04 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

Hello Tetsuya,

Little comment below for this patch.

On Mon, Jul 6, 2015 at 8:24 AM, Tetsuya Mukawa <mukawa@igel.co.jp> wrote:

>
> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c
> b/lib/librte_eal/bsdapp/eal/eal_pci.c
> index a63d450..63758c7 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> @@ -202,7 +202,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>         uint64_t offset;
>         uint64_t pagesz;
>         struct rte_pci_addr *loc = &dev->addr;
> -       struct uio_resource *uio_res;
> +       struct uio_resource *uio_res = NULL;
>         struct uio_res_list *uio_res_list =
>                         RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
>         struct uio_map *maps;
> [snip]
> @@ -275,6 +274,16 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>         TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
>
>         return 0;
> +
> +error:
> +       if (uio_res)
> +               rte_free(uio_res);
>

As long as uio_res is initialized to NULL, no need to check.
rte_free() behaves the same as free().


diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> index 37dc936..4e50533 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> [snip]
> @@ -400,6 +397,25 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>         TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
>
>         return 0;
> +
> +error:
> +       for (i = 0; i < map_idx; i++) {
> +               pci_unmap_resource(uio_res->maps[i].addr,
> +                               (size_t)uio_res->maps[i].size);
> +               rte_free(maps[i].path);
> +       }
> +       if (uio_res)
> +               rte_free(uio_res);
>

Idem.


With this,
Acked-by: David Marchand <david.marchand@6wind.com>

-- 
David Marchand

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v8 04/12] eal/bsdapp: Change names of pci related data structure
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 04/12] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
@ 2015-07-07  8:04                   ` David Marchand
  0 siblings, 0 replies; 120+ messages in thread
From: David Marchand @ 2015-07-07  8:04 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Mon, Jul 6, 2015 at 8:24 AM, Tetsuya Mukawa <mukawa@igel.co.jp> wrote:

> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
>
> To merge pci code of linuxapp and bsdapp, this patch changes names
> like below.
>  - uio_map to pci_map
>  - uio_resource to mapped_pci_resource
>  - uio_res_list to mapped_pci_res_list
>
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  lib/librte_eal/bsdapp/eal/eal_pci.c | 24 ++++++++++++------------
>  1 file changed, 12 insertions(+), 12 deletions(-)
>
> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c
> b/lib/librte_eal/bsdapp/eal/eal_pci.c
> index 63758c7..21d1e66 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> @@ -84,7 +84,7 @@
>   * enabling bus master.
>   */
>
> -struct uio_map {
> +struct pci_map {
>         void *addr;
>         uint64_t offset;
>         uint64_t size;
> @@ -95,16 +95,16 @@ struct uio_map {
>   * For multi-process we need to reproduce all PCI mappings in secondary
>   * processes, so save them in a tailq.
>   */
> -struct uio_resource {
> -       TAILQ_ENTRY(uio_resource) next;
> +struct mapped_pci_resource {
> +       TAILQ_ENTRY(mapped_pci_resource) next;
>
>         struct rte_pci_addr pci_addr;
>         char path[PATH_MAX];
>         size_t nb_maps;
> -       struct uio_map maps[PCI_MAX_RESOURCE];
> +       struct pci_map maps[PCI_MAX_RESOURCE];
>  };
>
> -TAILQ_HEAD(uio_res_list, uio_resource);
> +TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource);
>
>  static struct rte_tailq_elem rte_uio_tailq = {
>         .name = "UIO_RESOURCE_LIST",
> @@ -163,9 +163,9 @@ static int
>  pci_uio_map_secondary(struct rte_pci_device *dev)
>  {
>         size_t i;
> -       struct uio_resource *uio_res;
> -       struct uio_res_list *uio_res_list =
> -                       RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
> +       struct mapped_pci_resource *uio_res;
> +       struct mapped_pci_res_list *uio_res_list =
> +                       RTE_TAILQ_CAST(rte_uio_tailq.head,
> mapped_pci_res_list);
>
>         TAILQ_FOREACH(uio_res, uio_res_list, next) {
>
> @@ -202,10 +202,10 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>         uint64_t offset;
>         uint64_t pagesz;
>         struct rte_pci_addr *loc = &dev->addr;
> -       struct uio_resource *uio_res = NULL;
> -       struct uio_res_list *uio_res_list =
> -                       RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
> -       struct uio_map *maps;
> +       struct mapped_pci_resource *uio_res = NULL;
> +       struct mapped_pci_res_list *uio_res_list =
> +                       RTE_TAILQ_CAST(rte_uio_tailq.head,
> mapped_pci_res_list);
> +       struct pci_map *maps;
>
>         dev->intr_handle.fd = -1;
>         dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
> --
> 2.1.4
>
>
Looks good to me.
Acked-by: David Marchand <david.marchand@6wind.com>

-- 
David Marchand

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v8 05/12] eal: Fix uio mapping differences between linuxapp and bsdapp
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 05/12] eal: Fix uio mapping differences between linuxapp and bsdapp Tetsuya Mukawa
@ 2015-07-07  8:04                   ` David Marchand
  2015-07-08  2:42                     ` Tetsuya Mukawa
  0 siblings, 1 reply; 120+ messages in thread
From: David Marchand @ 2015-07-07  8:04 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Mon, Jul 6, 2015 at 8:24 AM, Tetsuya Mukawa <mukawa@igel.co.jp> wrote:

> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c
> b/lib/librte_eal/bsdapp/eal/eal_pci.c
> index 21d1e66..92d9886 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
>
> @@ -170,19 +154,33 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
>         TAILQ_FOREACH(uio_res, uio_res_list, next) {
>
>                 /* skip this element if it doesn't match our PCI address */
> -               if (memcmp(&uio_res->pci_addr, &dev->addr,
> sizeof(dev->addr)))
> +               if (rte_eal_compare_pci_addr(&uio_res->pci_addr,
> &dev->addr))
>                         continue;
>
>                 for (i = 0; i != uio_res->nb_maps; i++) {
> -                       if (pci_map_resource(uio_res->maps[i].addr,
> -                                            uio_res->path,
> -
> (off_t)uio_res->maps[i].offset,
> -                                            (size_t)uio_res->maps[i].size)
> -                           != uio_res->maps[i].addr) {
> +                       /*
> +                        * open devname, to mmap it
> +                        */
> +                       fd = open(uio_res->maps[i].path, O_RDWR);
> +                       if (fd < 0) {
> +                               RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
> +                                       uio_res->maps[i].path,
> strerror(errno));
> +                               return -1;
> +                       }
> +
> +                       void *mapaddr =
> pci_map_resource(uio_res->maps[i].addr,
> +                                       fd, (off_t)uio_res->maps[i].offset,
> +                                       (size_t)uio_res->maps[i].size, 0);
>

I suppose you can close fd here


> +                       if (mapaddr != uio_res->maps[i].addr) {
>                                 RTE_LOG(ERR, EAL,
> -                                       "Cannot mmap device resource\n");
> +                                       "Cannot mmap device resource file
> %s to address: %p\n",
> +                                       uio_res->maps[i].path,
> +                                       uio_res->maps[i].addr);
> +                               close(fd);
>

and remove it from here

>                                 return -1;
>                         }
> +                       /* fd is not needed in slave process, close it */
> +                       close(fd);
>

and here.


The rest is ok for me.
Acked-by: David Marchand <david.marchand@6wind.com>

-- 
David Marchand

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v8 06/12] eal: Add pci_uio_alloc_resource()
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 06/12] eal: Add pci_uio_alloc_resource() Tetsuya Mukawa
@ 2015-07-07  8:04                   ` David Marchand
  2015-07-08  2:42                     ` Tetsuya Mukawa
  0 siblings, 1 reply; 120+ messages in thread
From: David Marchand @ 2015-07-07  8:04 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Mon, Jul 6, 2015 at 8:24 AM, Tetsuya Mukawa <mukawa@igel.co.jp> wrote:

> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
>
> This patch adds a new function called pci_uio_alloc_resource().
> The function hides how to prepare uio resource in linuxapp and bsdapp.
> With the function, pci_uio_map_resource() will be more abstracted.
>
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  lib/librte_eal/bsdapp/eal/eal_pci.c       | 84 +++++++++++++++++---------
>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 98
> +++++++++++++++++++++----------
>  2 files changed, 123 insertions(+), 59 deletions(-)
>
> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c
> b/lib/librte_eal/bsdapp/eal/eal_pci.c
> index 92d9886..ce0ca07 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> @@ -189,28 +189,17 @@ 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)
> +pci_uio_alloc_resource(struct rte_pci_device *dev,
> +               struct mapped_pci_resource **uio_res)
>  {
> -       int i, map_idx = 0;
>         char devname[PATH_MAX]; /* contains the /dev/uioX */
> -       void *mapaddr;
> -       uint64_t phaddr;
> -       uint64_t offset;
> -       uint64_t pagesz;
> -       struct rte_pci_addr *loc = &dev->addr;
> -       struct mapped_pci_resource *uio_res = NULL;
> -       struct mapped_pci_res_list *uio_res_list =
> -                       RTE_TAILQ_CAST(rte_uio_tailq.head,
> mapped_pci_res_list);
> -       struct pci_map *maps;
> +       struct rte_pci_addr *loc;
>
> -       dev->intr_handle.fd = -1;
> -       dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
> +       if ((dev == NULL) || (uio_res == NULL))
> +               return -1;
>
>
This is an "internal" function, dev cannot be null, neither uio_res.


> -       /* secondary processes - use already recorded details */
> -       if (rte_eal_process_type() != RTE_PROC_PRIMARY)
> -               return pci_uio_map_secondary(dev);
> +       loc = &dev->addr;
>
>         snprintf(devname, sizeof(devname), "/dev/uio@pci:%u:%u:%u",
>                         dev->addr.bus, dev->addr.devid,
> dev->addr.function);
> @@ -231,18 +220,57 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>         dev->intr_handle.type = RTE_INTR_HANDLE_UIO;
>
>         /* allocate the mapping details for secondary processes*/
> -       if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) ==
> NULL) {
> +       *uio_res = rte_zmalloc("UIO_RES", sizeof(**uio_res), 0);
> +       if (*uio_res == NULL) {
>                 RTE_LOG(ERR, EAL,
>                         "%s(): cannot store uio mmap details\n", __func__);
>                 goto error;
>         }
>
> -       snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
> -       memcpy(&uio_res->pci_addr, &dev->addr, sizeof(uio_res->pci_addr));
> +       snprintf((*uio_res)->path, sizeof((*uio_res)->path), "%s",
> devname);
> +       memcpy(&(*uio_res)->pci_addr, &dev->addr,
> sizeof((*uio_res)->pci_addr));
>
> +       return 0;
> +
> +error:
> +       if (dev->intr_handle.fd) {
> +               close(dev->intr_handle.fd);
> +               dev->intr_handle.fd = -1;
> +               dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
> +       }
> +       return -1;
> +}
> +
> +/* map the PCI resource of a PCI device in virtual memory */
> +static int
> +pci_uio_map_resource(struct rte_pci_device *dev)
> +{
> +       int i, map_idx = 0, ret;
> +       char *devname;
> +       void *mapaddr;
> +       uint64_t phaddr;
> +       uint64_t offset;
> +       uint64_t pagesz;
> +       struct mapped_pci_resource *uio_res = NULL;
> +       struct mapped_pci_res_list *uio_res_list =
> +               RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
> +       struct pci_map *maps;
> +
> +       dev->intr_handle.fd = -1;
> +       dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
> +
> +       /* secondary processes - use already recorded details */
> +       if (rte_eal_process_type() != RTE_PROC_PRIMARY)
> +               return pci_uio_map_secondary(dev);
> +
> +       /* allocate uio resource */
> +       ret = pci_uio_alloc_resource(dev, &uio_res);
> +       if ((ret != 0) || (uio_res == NULL))
> +               return ret;
>
>
If ret != 0, uio_res cannot be NULL.



>         /* Map all BARs */
>         pagesz = sysconf(_SC_PAGESIZE);
> +       devname = uio_res->path;
>
>         maps = uio_res->maps;
>         for (i = 0; i != PCI_MAX_RESOURCE; i++) {
> @@ -298,13 +326,15 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  error:
>         for (i = 0; i < map_idx; i++)
>                 rte_free(maps[i].path);
> -       if (uio_res)
> -               rte_free(uio_res);
> -       if (dev->intr_handle.fd >= 0) {
> -               close(dev->intr_handle.fd);
> -               dev->intr_handle.fd = -1;
> -               dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
> -       }
> +
> +       /* 'uio_res' has valid value here */
>

Not sure what this comment means, do you mean != NULL ? It does not matter.


> +       rte_free(uio_res);
> +
> +       /* 'fd' has valid value here */
> +       close(dev->intr_handle.fd);
> +       dev->intr_handle.fd = -1;
> +       dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
> +
>         return -1;
>  }
>

In the end, if you add this "alloc" function, why not introduce a "free"
function that does this cleanup ?


Same comments apply to linux modifications.


-- 
David Marchand

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v8 07/12] eal: Add pci_uio_map_resource_by_index()
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 07/12] eal: Add pci_uio_map_resource_by_index() Tetsuya Mukawa
@ 2015-07-07  8:05                   ` David Marchand
  2015-07-08  2:42                     ` Tetsuya Mukawa
  0 siblings, 1 reply; 120+ messages in thread
From: David Marchand @ 2015-07-07  8:05 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Mon, Jul 6, 2015 at 8:24 AM, Tetsuya Mukawa <mukawa@igel.co.jp> wrote:

> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
>
> This patch adds a new function called pci_uio_map_resource_by_index().
> The function hides how to map uio resource in linuxapp and bsdapp.
> With the function, pci_uio_map_resource() will be more abstracted.
>
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  lib/librte_eal/bsdapp/eal/eal_pci.c       | 107 +++++++++++++++-----------
>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 124
> +++++++++++++++++-------------
>  2 files changed, 133 insertions(+), 98 deletions(-)
>
> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c
> b/lib/librte_eal/bsdapp/eal/eal_pci.c
> index ce0ca07..c76f936 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> @@ -241,20 +241,73 @@ error:
>         return -1;
>  }
>
> +static int
> +pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
> +               struct mapped_pci_resource *uio_res, int map_idx)
> +{
> +       int fd;
> +       char *devname;
> +       void *mapaddr;
> +       uint64_t offset;
> +       uint64_t pagesz;
> +       struct pci_map *maps;
> +
> +       if ((dev == NULL) || (uio_res == NULL) || (uio_res->path == NULL))
> +               return -1;
>

No need for these checks.


> +
> +       maps = uio_res->maps;
> +       devname = uio_res->path;
> +       pagesz = sysconf(_SC_PAGESIZE);
> +
> +       /* allocate memory to keep path */
> +       maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
> +       if (maps[map_idx].path == NULL) {
> +               RTE_LOG(ERR, EAL, "Cannot allocate memory for path: %s\n",
> +                               strerror(errno));
> +               return -1;
> +       }
> +
> +       /*
> +        * open resource file, to mmap it
> +        */
> +       fd = open(devname, O_RDWR);
> +       if (fd < 0) {
> +               RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
> +                               devname, strerror(errno));
> +               goto error;
> +       }
> +
> +       /* if matching map is found, then use it */
> +       offset = res_idx * pagesz;
> +       mapaddr = pci_map_resource(NULL, fd, (off_t)offset,
> +                       (size_t)dev->mem_resource[res_idx].len, 0);
> +       close(fd);
> +       if (mapaddr == MAP_FAILED)
> +               goto error;
> +
> +       maps[map_idx].phaddr = dev->mem_resource[res_idx].phys_addr;
> +       maps[map_idx].size = dev->mem_resource[res_idx].len;
> +       maps[map_idx].addr = mapaddr;
> +       maps[map_idx].offset = offset;
> +       strcpy(maps[map_idx].path, devname);
> +       dev->mem_resource[res_idx].addr = mapaddr;
> +
> +       return 0;
> +
> +error:
> +       rte_free(maps[map_idx].path);
> +       return -1;
> +}
> +
>  /* map the PCI resource of a PCI device in virtual memory */
>  static int
>  pci_uio_map_resource(struct rte_pci_device *dev)
>  {
>         int i, map_idx = 0, ret;
> -       char *devname;
> -       void *mapaddr;
>         uint64_t phaddr;
> -       uint64_t offset;
> -       uint64_t pagesz;
>         struct mapped_pci_resource *uio_res = NULL;
>         struct mapped_pci_res_list *uio_res_list =
>                 RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
> -       struct pci_map *maps;
>
>         dev->intr_handle.fd = -1;
>         dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
> @@ -269,53 +322,17 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>                 return ret;
>
>         /* Map all BARs */
> -       pagesz = sysconf(_SC_PAGESIZE);
> -       devname = uio_res->path;
> -
> -       maps = uio_res->maps;
>         for (i = 0; i != PCI_MAX_RESOURCE; i++) {
> -               int fd;
> -
>                 /* skip empty BAR */
>                 if ((phaddr = dev->mem_resource[i].phys_addr) == 0)
>                         continue;
>
> -               /* allocate memory to keep path */
> -               maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1,
> 0);
> -               if (maps[map_idx].path == NULL) {
> -                       RTE_LOG(ERR, EAL, "Cannot allocate memory for
> path: %s\n",
> -                                       strerror(errno));
> +               ret = pci_uio_map_resource_by_index(dev, i,
> +                               uio_res, map_idx);
> +               if (ret != 0)
>                         goto error;
> -               }
>
> -               /*
> -                * open resource file, to mmap it
> -                */
> -               fd = open(devname, O_RDWR);
> -               if (fd < 0) {
> -                       RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
> -                                       devname, strerror(errno));
> -                       rte_free(maps[map_idx].path);
> -                       goto error;
> -               }
> -
> -               /* if matching map is found, then use it */
> -               offset = i * pagesz;
> -               mapaddr = pci_map_resource(NULL, fd, (off_t)offset,
> -                                       (size_t)dev->mem_resource[i].len,
> 0);
> -               close(fd);
> -               if (mapaddr == MAP_FAILED) {
> -                       rte_free(maps[map_idx].path);
> -                       goto error;
> -               }
> -
> -               maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
> -               maps[map_idx].size = dev->mem_resource[i].len;
> -               maps[map_idx].addr = mapaddr;
> -               maps[map_idx].offset = offset;
> -               strcpy(maps[map_idx].path, devname);
>                 map_idx++;
> -               dev->mem_resource[i].addr = mapaddr;
>         }
>
>         uio_res->nb_maps = map_idx;
> @@ -325,7 +342,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>         return 0;
>  error:
>         for (i = 0; i < map_idx; i++)
> -               rte_free(maps[i].path);
> +               rte_free(uio_res->maps[i].path);
>
>         /* 'uio_res' has valid value here */
>         rte_free(uio_res);
> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> index f408bd3..cafabba 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> @@ -333,19 +333,82 @@ error:
>         return -1;
>  }
>
> +static int
> +pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
> +               struct mapped_pci_resource *uio_res, int map_idx)
> +{
> +       int fd;
> +       char devname[PATH_MAX]; /* contains the /dev/uioX */
> +       void *mapaddr;
> +       struct rte_pci_addr *loc;
> +       struct pci_map *maps;
> +
> +       if ((dev == NULL) || (uio_res == NULL))
> +               return -1;
>

Idem.


Then,
Acked-by: David Marchand <david.marchand@6wind.com>


-- 
David Marchand

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v8 08/12] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 08/12] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp Tetsuya Mukawa
@ 2015-07-07  8:05                   ` David Marchand
  0 siblings, 0 replies; 120+ messages in thread
From: David Marchand @ 2015-07-07  8:05 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Mon, Jul 6, 2015 at 8:24 AM, Tetsuya Mukawa <mukawa@igel.co.jp> wrote:

> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
>
> This patch consolidates below structures, and defines them in common code.
>  - struct pci_map
>  - strucy mapped_pci_resouces
>
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  lib/librte_eal/bsdapp/eal/eal_pci.c        | 24 ------------------------
>  lib/librte_eal/common/include/rte_pci.h    | 29
> +++++++++++++++++++++++++++++
>  lib/librte_eal/linuxapp/eal/eal_pci_init.h | 23 -----------------------
>  3 files changed, 29 insertions(+), 47 deletions(-)
>
> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c
> b/lib/librte_eal/bsdapp/eal/eal_pci.c
> index c76f936..6067e31 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> @@ -83,30 +83,6 @@
>   * network card, only providing access to PCI BAR to applications, and
>   * enabling bus master.
>   */
> -
> -struct pci_map {
> -       void *addr;
> -       char *path;
> -       uint64_t offset;
> -       uint64_t size;
> -       uint64_t phaddr;
> -};
> -
> -/*
> - * For multi-process we need to reproduce all PCI mappings in secondary
> - * processes, so save them in a tailq.
> - */
> -struct mapped_pci_resource {
> -       TAILQ_ENTRY(mapped_pci_resource) next;
> -
> -       struct rte_pci_addr pci_addr;
> -       char path[PATH_MAX];
> -       int nb_maps;
> -       struct pci_map maps[PCI_MAX_RESOURCE];
> -};
> -
> -TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource);
> -
>  static struct rte_tailq_elem rte_uio_tailq = {
>         .name = "UIO_RESOURCE_LIST",
>  };
> diff --git a/lib/librte_eal/common/include/rte_pci.h
> b/lib/librte_eal/common/include/rte_pci.h
> index 7801fa0..d95747e 100644
> --- a/lib/librte_eal/common/include/rte_pci.h
> +++ b/lib/librte_eal/common/include/rte_pci.h
> @@ -2,6 +2,7 @@
>   *   BSD LICENSE
>   *
>   *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
> + *   Copyright(c) 2015 IGEL Co., Ltd.
>   *   All rights reserved.
>   *
>   *   Redistribution and use in source and binary forms, with or without
> @@ -220,6 +221,34 @@ struct rte_pci_driver {
>  /** Device driver supports detaching capability */
>  #define RTE_PCI_DRV_DETACHABLE 0x0010
>
> +/**
> + * A structure describing a PCI mapping.
> + */
> +struct pci_map {
> +       void *addr;
> +       char *path;
> +       uint64_t offset;
> +       uint64_t size;
> +       uint64_t phaddr;
> +};
> +
> +/**
> + * A structure describing a mapped PCI resource.
> + * For multi-process we need to reproduce all PCI mappings in secondary
> + * processes, so save them in a tailq.
> + */
> +struct mapped_pci_resource {
> +       TAILQ_ENTRY(mapped_pci_resource) next;
> +
> +       struct rte_pci_addr pci_addr;
> +       char path[PATH_MAX];
> +       int nb_maps;
> +       struct pci_map maps[PCI_MAX_RESOURCE];
> +};
> +
> +/** mapped pci device list */
> +TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource);
> +
>  /**< Internal use only - Macro used by pci addr parsing functions **/
>  #define GET_PCIADDR_FIELD(in, fd, lim, dlm)                   \
>  do {                                                               \
> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
> b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
> index aa7b755..d9d1878 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
> @@ -36,29 +36,6 @@
>
>  #include "eal_vfio.h"
>
> -struct pci_map {
> -       void *addr;
> -       char *path;
> -       uint64_t offset;
> -       uint64_t size;
> -       uint64_t phaddr;
> -};
> -
> -/*
> - * For multi-process we need to reproduce all PCI mappings in secondary
> - * processes, so save them in a tailq.
> - */
> -struct mapped_pci_resource {
> -       TAILQ_ENTRY(mapped_pci_resource) next;
> -
> -       struct rte_pci_addr pci_addr;
> -       char path[PATH_MAX];
> -       int nb_maps;
> -       struct pci_map maps[PCI_MAX_RESOURCE];
> -};
> -
> -TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource);
> -
>  /*
>   * Helper function to map PCI resources right after hugepages in virtual
> memory
>   */
> --
> 2.1.4
>
>

Acked-by: David Marchand <david.marchand@6wind.com>


-- 
David Marchand

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v8 09/12] eal: Consolidate pci_map/unmap_resource() of linuxapp and bsdapp
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 09/12] eal: Consolidate pci_map/unmap_resource() " Tetsuya Mukawa
@ 2015-07-07  8:05                   ` David Marchand
  0 siblings, 0 replies; 120+ messages in thread
From: David Marchand @ 2015-07-07  8:05 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Mon, Jul 6, 2015 at 8:24 AM, Tetsuya Mukawa <mukawa@igel.co.jp> wrote:

> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
>
> The patch consolidates below functions, and implemented in common
> eal code.
>  - pci_map_resource()
>  - pci_unmap_resource()
>
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  lib/librte_eal/bsdapp/eal/eal_pci.c        | 22 ----------------
>  lib/librte_eal/common/eal_common_pci.c     | 40
> +++++++++++++++++++++++++++++
>  lib/librte_eal/common/include/rte_pci.h    | 32 +++++++++++++++++++++++
>  lib/librte_eal/linuxapp/eal/eal_pci.c      | 41
> ------------------------------
>  lib/librte_eal/linuxapp/eal/eal_pci_init.h |  5 ----
>  5 files changed, 72 insertions(+), 68 deletions(-)
>
> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c
> b/lib/librte_eal/bsdapp/eal/eal_pci.c
> index 6067e31..5bb93cd 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> @@ -97,28 +97,6 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev
> __rte_unused)
>         return -ENOTSUP;
>  }
>
> -/* map a particular resource from a file */
> -static void *
> -pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
> -                int additional_flags)
> -{
> -       void *mapaddr;
> -
> -       /* Map the PCI memory resource of device */
> -       mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
> -                       MAP_SHARED | additional_flags, fd, offset);
> -       if (mapaddr == MAP_FAILED) {
> -               RTE_LOG(ERR, EAL,
> -                       "%s(): cannot mmap(%d, %p, 0x%lx, 0x%lx): %s
> (%p)\n",
> -                       __func__, fd, requested_addr,
> -                       (unsigned long)size, (unsigned long)offset,
> -                       strerror(errno), mapaddr);
> -       } else
> -               RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n",
> mapaddr);
> -
> -       return mapaddr;
> -}
> -
>  static int
>  pci_uio_map_secondary(struct rte_pci_device *dev)
>  {
> diff --git a/lib/librte_eal/common/eal_common_pci.c
> b/lib/librte_eal/common/eal_common_pci.c
> index 4229aaf..eab147a 100644
> --- a/lib/librte_eal/common/eal_common_pci.c
> +++ b/lib/librte_eal/common/eal_common_pci.c
> @@ -2,6 +2,7 @@
>   *   BSD LICENSE
>   *
>   *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
> + *   Copyright(c) 2015 IGEL Co., Ltd.
>   *   All rights reserved.
>   *
>   *   Redistribution and use in source and binary forms, with or without
> @@ -67,6 +68,7 @@
>  #include <stdlib.h>
>  #include <stdio.h>
>  #include <sys/queue.h>
> +#include <sys/mman.h>
>
>  #include <rte_interrupts.h>
>  #include <rte_log.h>
> @@ -98,6 +100,44 @@ static struct rte_devargs *pci_devargs_lookup(struct
> rte_pci_device *dev)
>         return NULL;
>  }
>
> +/* map a particular resource from a file */
> +void *
> +pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
> +                int additional_flags)
> +{
> +       void *mapaddr;
> +
> +       /* Map the PCI memory resource of device */
> +       mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
> +                       MAP_SHARED | additional_flags, fd, offset);
> +       if (mapaddr == MAP_FAILED) {
> +               RTE_LOG(ERR, EAL, "%s(): cannot mmap(%d, %p, 0x%lx,
> 0x%lx): %s (%p)\n",
> +                       __func__, fd, requested_addr,
> +                       (unsigned long)size, (unsigned long)offset,
> +                       strerror(errno), mapaddr);
> +       } else
> +               RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n",
> mapaddr);
> +
> +       return mapaddr;
> +}
> +
> +/* unmap a particular resource */
> +void
> +pci_unmap_resource(void *requested_addr, size_t size)
> +{
> +       if (requested_addr == NULL)
> +               return;
> +
> +       /* Unmap the PCI memory resource of device */
> +       if (munmap(requested_addr, size)) {
> +               RTE_LOG(ERR, EAL, "%s(): cannot munmap(%p, 0x%lx): %s\n",
> +                       __func__, requested_addr, (unsigned long)size,
> +                       strerror(errno));
> +       } else
> +               RTE_LOG(DEBUG, EAL, "  PCI memory unmapped at %p\n",
> +                               requested_addr);
> +}
> +
>  /*
>   * If vendor/device ID match, call the devinit() function of all
>   * registered driver for the given device. Return -1 if initialization
> diff --git a/lib/librte_eal/common/include/rte_pci.h
> b/lib/librte_eal/common/include/rte_pci.h
> index d95747e..4a4641c 100644
> --- a/lib/librte_eal/common/include/rte_pci.h
> +++ b/lib/librte_eal/common/include/rte_pci.h
> @@ -365,6 +365,38 @@ int rte_eal_pci_scan(void);
>   */
>  int rte_eal_pci_probe(void);
>
> +/**
> + * @internal
> + * Map a particular resource from a file.
> + *
> + * @param requested_addr
> + *      The starting address for the new mapping range.
> + * @param fd
> + *      The file descriptor.
> + * @param offset
> + *      The offset for the mapping range.
> + * @param size
> + *      The size for the mapping range.
> + * @param additional_flags
> + *      The additional flags for the mapping range.
> + * @return
> + *   - On success, the function returns a pointer to the mapped area.
> + *   - On error, the value MAP_FAILED is returned.
> + */
> +void *pci_map_resource(void *requested_addr, int fd, off_t offset,
> +               size_t size, int additional_flags);
> +
> +/**
> + * @internal
> + * Unmap a particular resource.
> + *
> + * @param requested_addr
> + *      The address for the unmapping range.
> + * @param size
> + *      The size for the unmapping range.
> + */
> +void pci_unmap_resource(void *requested_addr, size_t size);
> +
>  #ifdef RTE_LIBRTE_EAL_HOTPLUG
>  /**
>   * Probe the single PCI device.
> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c
> b/lib/librte_eal/linuxapp/eal/eal_pci.c
> index d2adc66..fc99eaa 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_pci.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
> @@ -33,7 +33,6 @@
>
>  #include <string.h>
>  #include <dirent.h>
> -#include <sys/mman.h>
>
>  #include <rte_log.h>
>  #include <rte_pci.h>
> @@ -142,46 +141,6 @@ pci_find_max_end_va(void)
>         return RTE_PTR_ADD(last->addr, last->len);
>  }
>
> -
> -/* map a particular resource from a file */
> -void *
> -pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
> -                int additional_flags)
> -{
> -       void *mapaddr;
> -
> -       /* Map the PCI memory resource of device */
> -       mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
> -                       MAP_SHARED | additional_flags, fd, offset);
> -       if (mapaddr == MAP_FAILED) {
> -               RTE_LOG(ERR, EAL, "%s(): cannot mmap(%d, %p, 0x%lx,
> 0x%lx): %s (%p)\n",
> -                       __func__, fd, requested_addr,
> -                       (unsigned long)size, (unsigned long)offset,
> -                       strerror(errno), mapaddr);
> -       } else {
> -               RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n",
> mapaddr);
> -       }
> -
> -       return mapaddr;
> -}
> -
> -/* unmap a particular resource */
> -void
> -pci_unmap_resource(void *requested_addr, size_t size)
> -{
> -       if (requested_addr == NULL)
> -               return;
> -
> -       /* Unmap the PCI memory resource of device */
> -       if (munmap(requested_addr, size)) {
> -               RTE_LOG(ERR, EAL, "%s(): cannot munmap(%p, 0x%lx): %s\n",
> -                       __func__, requested_addr, (unsigned long)size,
> -                       strerror(errno));
> -       } else
> -               RTE_LOG(DEBUG, EAL, "  PCI memory unmapped at %p\n",
> -                               requested_addr);
> -}
> -
>  /* parse the "resource" sysfs file */
>  static int
>  pci_parse_sysfs_resource(const char *filename, struct rte_pci_device *dev)
> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
> b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
> index d9d1878..d426b27 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
> @@ -42,14 +42,9 @@
>  extern void *pci_map_addr;
>  void *pci_find_max_end_va(void);
>
> -void *pci_map_resource(void *requested_addr, int fd, off_t offset,
> -              size_t size, int additional_flags);
> -
>  /* map IGB_UIO resource prototype */
>  int pci_uio_map_resource(struct rte_pci_device *dev);
>
> -void pci_unmap_resource(void *requested_addr, size_t size);
> -
>  #ifdef RTE_LIBRTE_EAL_HOTPLUG
>  /* unmap IGB_UIO resource prototype */
>  void pci_uio_unmap_resource(struct rte_pci_device *dev);
> --
> 2.1.4
>
>
Acked-by: David Marchand <david.marchand@6wind.com>


-- 
David Marchand

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v8 11/12] eal: Consolidate pci_map/unmap_device() of linuxapp and bsdapp
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 11/12] eal: Consolidate pci_map/unmap_device() " Tetsuya Mukawa
@ 2015-07-07  8:06                   ` David Marchand
  2015-07-08  2:42                     ` Tetsuya Mukawa
  0 siblings, 1 reply; 120+ messages in thread
From: David Marchand @ 2015-07-07  8:06 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Mon, Jul 6, 2015 at 8:24 AM, Tetsuya Mukawa <mukawa@igel.co.jp> wrote:

> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
>
> The patch consolidates below functions, and implemented in common
> eal code.
>  - pci_map_device()
>  - pci_unmap_device()
>
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  lib/librte_eal/bsdapp/eal/eal_pci.c     |  3 ++
>  lib/librte_eal/common/eal_common_pci.c  | 57
> +++++++++++++++++++++++++++++++++
>  lib/librte_eal/common/eal_private.h     | 19 +++++++++++
>  lib/librte_eal/common/include/rte_pci.h |  1 +
>  lib/librte_eal/linuxapp/eal/eal_pci.c   | 53
> ------------------------------
>  lib/librte_ether/rte_ethdev.c           |  2 ++
>  6 files changed, 82 insertions(+), 53 deletions(-)
>
> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c
> b/lib/librte_eal/bsdapp/eal/eal_pci.c
> index f85fc1e..a27dca3 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> @@ -240,6 +240,9 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
>         /* FreeBSD has no NUMA support (yet) */
>         dev->numa_node = 0;
>
> +       /* FreeBSD has only one pass through driver */
> +       dev->kdrv = RTE_KDRV_NIC_UIO;
> +
>

Do we need a new define for this ?

I know this is not really part of this patchset, but this kdrv should just
disappear.


-- 
David Marchand

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v8 10/12] eal: Consolidate pci uio functions of linuxapp and bsdapp
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 10/12] eal: Consolidate pci uio functions " Tetsuya Mukawa
@ 2015-07-07  8:07                   ` David Marchand
  0 siblings, 0 replies; 120+ messages in thread
From: David Marchand @ 2015-07-07  8:07 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Mon, Jul 6, 2015 at 8:24 AM, Tetsuya Mukawa <mukawa@igel.co.jp> wrote:

> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
>
> The patch consolidates below functions, and implement these
> in eal_common_pci_uio.c.
>  - pci_uio_map_secondary()
>  - pci_uio_map_resource()
>  - pci_uio_unmap()
>  - pci_uio_find_resource()
>  - pci_uio_unmap_resource()
>
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  lib/librte_eal/bsdapp/eal/Makefile                 |   2 +
>  lib/librte_eal/bsdapp/eal/eal_pci.c                | 110 +---------
>  .../bsdapp/eal/include/exec-env/rte_interrupts.h   |   2 +
>  lib/librte_eal/common/eal_common_pci_uio.c         | 240
> +++++++++++++++++++++
>  lib/librte_eal/common/eal_private.h                |  56 +++++
>  lib/librte_eal/linuxapp/eal/Makefile               |   2 +
>  lib/librte_eal/linuxapp/eal/eal_pci_init.h         |  12 +-
>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c          | 196 +----------------
>  8 files changed, 311 insertions(+), 309 deletions(-)
>  create mode 100644 lib/librte_eal/common/eal_common_pci_uio.c
>
> diff --git a/lib/librte_eal/bsdapp/eal/Makefile
> b/lib/librte_eal/bsdapp/eal/Makefile
> index c73ffb6..0d72330 100644
> --- a/lib/librte_eal/bsdapp/eal/Makefile
> +++ b/lib/librte_eal/bsdapp/eal/Makefile
> @@ -1,6 +1,7 @@
>  #   BSD LICENSE
>  #
>  #   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
> +#   Copyright(c) 2015 IGEL Co., Ltd.
>  #   All rights reserved.
>  #
>  #   Redistribution and use in source and binary forms, with or without
> @@ -68,6 +69,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) +=
> eal_common_memzone.c
>  SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_log.c
>  SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_launch.c
>  SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_pci.c
> +SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_pci_uio.c
>  SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_memory.c
>  SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_tailqs.c
>  SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_errno.c
> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c
> b/lib/librte_eal/bsdapp/eal/eal_pci.c
> index 5bb93cd..f85fc1e 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> @@ -83,10 +83,6 @@
>   * network card, only providing access to PCI BAR to applications, and
>   * enabling bus master.
>   */
> -static struct rte_tailq_elem rte_uio_tailq = {
> -       .name = "UIO_RESOURCE_LIST",
> -};
> -EAL_REGISTER_TAILQ(rte_uio_tailq)
>
>  /* unbind kernel driver for this device */
>  static int
> @@ -97,53 +93,7 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev
> __rte_unused)
>         return -ENOTSUP;
>  }
>
> -static int
> -pci_uio_map_secondary(struct rte_pci_device *dev)
> -{
> -       int i, fd;
> -       struct mapped_pci_resource *uio_res;
> -       struct mapped_pci_res_list *uio_res_list =
> -                       RTE_TAILQ_CAST(rte_uio_tailq.head,
> mapped_pci_res_list);
> -
> -       TAILQ_FOREACH(uio_res, uio_res_list, next) {
> -
> -               /* skip this element if it doesn't match our PCI address */
> -               if (rte_eal_compare_pci_addr(&uio_res->pci_addr,
> &dev->addr))
> -                       continue;
> -
> -               for (i = 0; i != uio_res->nb_maps; i++) {
> -                       /*
> -                        * open devname, to mmap it
> -                        */
> -                       fd = open(uio_res->maps[i].path, O_RDWR);
> -                       if (fd < 0) {
> -                               RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
> -                                       uio_res->maps[i].path,
> strerror(errno));
> -                               return -1;
> -                       }
> -
> -                       void *mapaddr =
> pci_map_resource(uio_res->maps[i].addr,
> -                                       fd, (off_t)uio_res->maps[i].offset,
> -                                       (size_t)uio_res->maps[i].size, 0);
> -                       if (mapaddr != uio_res->maps[i].addr) {
> -                               RTE_LOG(ERR, EAL,
> -                                       "Cannot mmap device resource file
> %s to address: %p\n",
> -                                       uio_res->maps[i].path,
> -                                       uio_res->maps[i].addr);
> -                               close(fd);
> -                               return -1;
> -                       }
> -                       /* fd is not needed in slave process, close it */
> -                       close(fd);
> -               }
> -               return 0;
> -       }
> -
> -       RTE_LOG(ERR, EAL, "Cannot find resource for device\n");
> -       return 1;
> -}
> -
> -static int
> +int
>  pci_uio_alloc_resource(struct rte_pci_device *dev,
>                 struct mapped_pci_resource **uio_res)
>  {
> @@ -195,7 +145,7 @@ error:
>         return -1;
>  }
>
> -static int
> +int
>  pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
>                 struct mapped_pci_resource *uio_res, int map_idx)
>  {
> @@ -253,62 +203,6 @@ error:
>         return -1;
>  }
>
> -/* map the PCI resource of a PCI device in virtual memory */
> -static int
> -pci_uio_map_resource(struct rte_pci_device *dev)
> -{
> -       int i, map_idx = 0, ret;
> -       uint64_t phaddr;
> -       struct mapped_pci_resource *uio_res = NULL;
> -       struct mapped_pci_res_list *uio_res_list =
> -               RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
> -
> -       dev->intr_handle.fd = -1;
> -       dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
> -
> -       /* secondary processes - use already recorded details */
> -       if (rte_eal_process_type() != RTE_PROC_PRIMARY)
> -               return pci_uio_map_secondary(dev);
> -
> -       /* allocate uio resource */
> -       ret = pci_uio_alloc_resource(dev, &uio_res);
> -       if ((ret != 0) || (uio_res == NULL))
> -               return ret;
> -
> -       /* Map all BARs */
> -       for (i = 0; i != PCI_MAX_RESOURCE; i++) {
> -               /* skip empty BAR */
> -               if ((phaddr = dev->mem_resource[i].phys_addr) == 0)
> -                       continue;
> -
> -               ret = pci_uio_map_resource_by_index(dev, i,
> -                               uio_res, map_idx);
> -               if (ret != 0)
> -                       goto error;
> -
> -               map_idx++;
> -       }
> -
> -       uio_res->nb_maps = map_idx;
> -
> -       TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
> -
> -       return 0;
> -error:
> -       for (i = 0; i < map_idx; i++)
> -               rte_free(uio_res->maps[i].path);
> -
> -       /* 'uio_res' has valid value here */
> -       rte_free(uio_res);
> -
> -       /* 'fd' has valid value here */
> -       close(dev->intr_handle.fd);
> -       dev->intr_handle.fd = -1;
> -       dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
> -
> -       return -1;
> -}
> -
>  /* Scan one pci sysfs entry, and fill the devices list from it. */
>  static int
>  pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
> diff --git a/lib/librte_eal/bsdapp/eal/include/exec-env/rte_interrupts.h
> b/lib/librte_eal/bsdapp/eal/include/exec-env/rte_interrupts.h
> index 87a9cf6..410dd21 100644
> --- a/lib/librte_eal/bsdapp/eal/include/exec-env/rte_interrupts.h
> +++ b/lib/librte_eal/bsdapp/eal/include/exec-env/rte_interrupts.h
> @@ -2,6 +2,7 @@
>   *   BSD LICENSE
>   *
>   *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
> + *   Copyright(c) 2015 IGEL Co., Ltd.
>   *   All rights reserved.
>   *
>   *   Redistribution and use in source and binary forms, with or without
> @@ -48,6 +49,7 @@ enum rte_intr_handle_type {
>  /** Handle for interrupts. */
>  struct rte_intr_handle {
>         int fd;                          /**< file descriptor */
> +       int uio_cfg_fd;                  /**< UIO config file descriptor */
>         enum rte_intr_handle_type type;  /**< handle type */
>  };
>
> diff --git a/lib/librte_eal/common/eal_common_pci_uio.c
> b/lib/librte_eal/common/eal_common_pci_uio.c
> new file mode 100644
> index 0000000..249a70b
> --- /dev/null
> +++ b/lib/librte_eal/common/eal_common_pci_uio.c
> @@ -0,0 +1,240 @@
> +/*-
> + *   BSD LICENSE
> + *
> + *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
> + *   Copyright(c) 2015 IGEL Co., Ltd.
> + *   All rights reserved.
> + *
> + *   Redistribution and use in source and binary forms, with or without
> + *   modification, are permitted provided that the following conditions
> + *   are met:
> + *
> + *     * Redistributions of source code must retain the above copyright
> + *       notice, this list of conditions and the following disclaimer.
> + *     * Redistributions in binary form must reproduce the above copyright
> + *       notice, this list of conditions and the following disclaimer in
> + *       the documentation and/or other materials provided with the
> + *       distribution.
> + *     * Neither the name of Intel Corporation nor the names of its
> + *       contributors may be used to endorse or promote products derived
> + *       from this software without specific prior written permission.
> + *
> + *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> + *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
> + *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
> + *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
> + *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> + *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> + *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
> + *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
> + *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> + *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
> + *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +#include <fcntl.h>
> +#include <string.h>
> +#include <unistd.h>
> +#include <sys/types.h>
> +#include <sys/stat.h>
> +#include <sys/mman.h>
> +
> +#include <rte_eal.h>
> +#include <rte_tailq.h>
> +#include <rte_log.h>
> +#include <rte_malloc.h>
> +
> +#include "eal_private.h"
> +
> +static struct rte_tailq_elem rte_uio_tailq = {
> +       .name = "UIO_RESOURCE_LIST",
> +};
> +EAL_REGISTER_TAILQ(rte_uio_tailq)
> +
> +static int
> +pci_uio_map_secondary(struct rte_pci_device *dev)
> +{
> +       int fd, i;
> +       struct mapped_pci_resource *uio_res;
> +       struct mapped_pci_res_list *uio_res_list =
> +                       RTE_TAILQ_CAST(rte_uio_tailq.head,
> mapped_pci_res_list);
> +
> +       TAILQ_FOREACH(uio_res, uio_res_list, next) {
> +
> +               /* skip this element if it doesn't match our PCI address */
> +               if (rte_eal_compare_pci_addr(&uio_res->pci_addr,
> &dev->addr))
> +                       continue;
> +
> +               for (i = 0; i != uio_res->nb_maps; i++) {
> +                       /*
> +                        * open devname, to mmap it
> +                        */
> +                       fd = open(uio_res->maps[i].path, O_RDWR);
> +                       if (fd < 0) {
> +                               RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
> +                                       uio_res->maps[i].path,
> strerror(errno));
> +                               return -1;
> +                       }
> +
> +                       void *mapaddr =
> pci_map_resource(uio_res->maps[i].addr,
> +                                       fd, (off_t)uio_res->maps[i].offset,
> +                                       (size_t)uio_res->maps[i].size, 0);
> +                       if (mapaddr != uio_res->maps[i].addr) {
> +                               RTE_LOG(ERR, EAL,
> +                                       "Cannot mmap device resource file
> %s to address: %p\n",
> +                                       uio_res->maps[i].path,
> +                                       uio_res->maps[i].addr);
> +                               close(fd);
> +                               return -1;
> +                       }
> +                       /* fd is not needed in slave process, close it */
> +                       close(fd);
> +               }
> +               return 0;
> +       }
> +
> +       RTE_LOG(ERR, EAL, "Cannot find resource for device\n");
> +       return 1;
> +}
> +
> +/* map the PCI resource of a PCI device in virtual memory */
> +int
> +pci_uio_map_resource(struct rte_pci_device *dev)
> +{
> +       int i, map_idx = 0, ret;
> +       uint64_t phaddr;
> +       struct mapped_pci_resource *uio_res = NULL;
> +       struct mapped_pci_res_list *uio_res_list =
> +               RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
> +
> +       dev->intr_handle.fd = -1;
> +       dev->intr_handle.uio_cfg_fd = -1;
> +       dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
> +
> +       /* secondary processes - use already recorded details */
> +       if (rte_eal_process_type() != RTE_PROC_PRIMARY)
> +               return pci_uio_map_secondary(dev);
> +
> +       /* allocate uio resource */
> +       ret = pci_uio_alloc_resource(dev, &uio_res);
> +       if ((ret != 0) || (uio_res == NULL))
> +               return ret;
> +
> +       /* Map all BARs */
> +       for (i = 0; i != PCI_MAX_RESOURCE; i++) {
> +               /* skip empty BAR */
> +               phaddr = dev->mem_resource[i].phys_addr;
> +               if (phaddr == 0)
> +                       continue;
> +
> +               ret = pci_uio_map_resource_by_index(dev, i,
> +                               uio_res, map_idx);
> +               if (ret != 0)
> +                       goto error;
> +
> +               map_idx++;
> +       }
> +
> +       uio_res->nb_maps = map_idx;
> +
> +       TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
> +
> +       return 0;
> +error:
> +       for (i = 0; i < map_idx; i++) {
> +               pci_unmap_resource(uio_res->maps[i].addr,
> +                               (size_t)uio_res->maps[i].size);
> +               rte_free(uio_res->maps[i].path);
> +       }
> +
> +       /* 'uio_res' has valid value here */
> +       rte_free(uio_res);
> +
> +       /* 'uio_cfg_fd' may have invalid value */
> +       if (dev->intr_handle.uio_cfg_fd >= 0) {
> +               close(dev->intr_handle.uio_cfg_fd);
> +               dev->intr_handle.uio_cfg_fd = -1;
> +       }
> +
> +       /* 'fd' has valid value here */
> +       close(dev->intr_handle.fd);
> +       dev->intr_handle.fd = -1;
> +       dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
> +
> +       return -1;
> +}
> +
> +#ifdef RTE_LIBRTE_EAL_HOTPLUG
> +static void
> +pci_uio_unmap(struct mapped_pci_resource *uio_res)
> +{
> +       int i;
> +
> +       if (uio_res == NULL)
> +               return;
> +
> +       for (i = 0; i != uio_res->nb_maps; i++) {
> +               pci_unmap_resource(uio_res->maps[i].addr,
> +                               (size_t)uio_res->maps[i].size);
> +               rte_free(uio_res->maps[i].path);
> +       }
> +}
> +
> +static struct mapped_pci_resource *
> +pci_uio_find_resource(struct rte_pci_device *dev)
> +{
> +       struct mapped_pci_resource *uio_res;
> +       struct mapped_pci_res_list *uio_res_list =
> +                       RTE_TAILQ_CAST(rte_uio_tailq.head,
> mapped_pci_res_list);
> +
> +       if (dev == NULL)
> +               return NULL;
> +
> +       TAILQ_FOREACH(uio_res, uio_res_list, next) {
> +
> +               /* skip this element if it doesn't match our PCI address */
> +               if (!rte_eal_compare_pci_addr(&uio_res->pci_addr,
> &dev->addr))
> +                       return uio_res;
> +       }
> +       return NULL;
> +}
> +
> +/* unmap the PCI resource of a PCI device in virtual memory */
> +void
> +pci_uio_unmap_resource(struct rte_pci_device *dev)
> +{
> +       struct mapped_pci_resource *uio_res;
> +       struct mapped_pci_res_list *uio_res_list =
> +                       RTE_TAILQ_CAST(rte_uio_tailq.head,
> mapped_pci_res_list);
> +
> +       if (dev == NULL)
> +               return;
> +
> +       /* find an entry for the device */
> +       uio_res = pci_uio_find_resource(dev);
> +       if (uio_res == NULL)
> +               return;
> +
> +       /* secondary processes - just free maps */
> +       if (rte_eal_process_type() != RTE_PROC_PRIMARY)
> +               return pci_uio_unmap(uio_res);
> +
> +       TAILQ_REMOVE(uio_res_list, uio_res, next);
> +
> +       /* unmap all resources */
> +       pci_uio_unmap(uio_res);
> +
> +       /* free uio resource */
> +       rte_free(uio_res);
> +
> +       /* close fd if in primary process */
> +       close(dev->intr_handle.fd);
> +       if (dev->intr_handle.uio_cfg_fd >= 0) {
> +               close(dev->intr_handle.uio_cfg_fd);
> +               dev->intr_handle.uio_cfg_fd = -1;
> +       }
> +
> +       dev->intr_handle.fd = -1;
> +       dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
> +}
> +#endif /* RTE_LIBRTE_EAL_HOTPLUG */
> diff --git a/lib/librte_eal/common/eal_private.h
> b/lib/librte_eal/common/eal_private.h
> index 4acf5a0..4125589 100644
> --- a/lib/librte_eal/common/eal_private.h
> +++ b/lib/librte_eal/common/eal_private.h
> @@ -2,6 +2,7 @@
>   *   BSD LICENSE
>   *
>   *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
> + *   Copyright(c) 2015 IGEL Co., Ltd.
>   *   All rights reserved.
>   *
>   *   Redistribution and use in source and binary forms, with or without
> @@ -35,6 +36,7 @@
>  #define _EAL_PRIVATE_H_
>
>  #include <stdio.h>
> +#include <rte_pci.h>
>
>  /**
>   * Initialize the memzone subsystem (private to eal).
> @@ -154,6 +156,25 @@ struct rte_pci_driver;
>  struct rte_pci_device;
>
>  /**
> + * Map the PCI resource of a PCI device in virtual memory
> + *
> + * This function is private to EAL.
> + *
> + * @return
> + *   0 on success, negative on error
> + */
> +int pci_uio_map_resource(struct rte_pci_device *dev);
> +
> +#ifdef RTE_LIBRTE_EAL_HOTPLUG
> +/**
> + * Unmap the PCI resource of a PCI device
> + *
> + * This function is private to EAL.
> + */
> +void pci_uio_unmap_resource(struct rte_pci_device *dev);
> +#endif /* RTE_LIBRTE_EAL_HOTPLUG */
> +
> +/**
>   * Mmap memory for single PCI device
>   *
>   * This function is private to EAL.
> @@ -180,6 +201,41 @@ int rte_eal_pci_close_one_driver(struct
> rte_pci_driver *dr,
>                 struct rte_pci_device *dev);
>
>  /**
> + * Allocate uio resource for PCI device
> + *
> + * This function is private to EAL.
> + *
> + * @param dev
> + *   PCI device to allocate uio resource
> + * @param uio_res
> + *   Pointer to uio resource.
> + *   If the function returns 0, the pointer will be filled.
> + * @return
> + *   0 on success, negative on error
> + */
> +int pci_uio_alloc_resource(struct rte_pci_device *dev,
> +               struct mapped_pci_resource **uio_res);
> +
> +/**
> + * Map device memory to uio resource
> + *
> + * This function is private to EAL.
> + *
> + * @param dev
> + *   PCI device that has memory information.
> + * @param res_idx
> + *   Memory resource index of the PCI device.
> + * @param uio_res
> + *  uio resource that will keep mapping information.
> + * @param map_idx
> + *   Mapping information index of the uio resource.
> + * @return
> + *   0 on success, negative on error
> + */
> +int pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
> +               struct mapped_pci_resource *uio_res, int map_idx);
> +
> +/**
>   * Init tail queues for non-EAL library structures. This is to allow
>   * the rings, mempools, etc. lists to be shared among multiple processes
>   *
> diff --git a/lib/librte_eal/linuxapp/eal/Makefile
> b/lib/librte_eal/linuxapp/eal/Makefile
> index e99d7a3..92900d6 100644
> --- a/lib/librte_eal/linuxapp/eal/Makefile
> +++ b/lib/librte_eal/linuxapp/eal/Makefile
> @@ -1,6 +1,7 @@
>  #   BSD LICENSE
>  #
>  #   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
> +#   Copyright(c) 2015 IGEL Co., Ltd.
>  #   All rights reserved.
>  #
>  #   Redistribution and use in source and binary forms, with or without
> @@ -80,6 +81,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) +=
> eal_common_memzone.c
>  SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_log.c
>  SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_launch.c
>  SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_pci.c
> +SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_pci_uio.c
>  SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_memory.c
>  SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_tailqs.c
>  SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_errno.c
> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
> b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
> index d426b27..51783f0 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
> @@ -2,6 +2,7 @@
>   *   BSD LICENSE
>   *
>   *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
> + *   Copyright(c) 2015 IGEL Co., Ltd.
>   *   All rights reserved.
>   *
>   *   Redistribution and use in source and binary forms, with or without
> @@ -42,13 +43,10 @@
>  extern void *pci_map_addr;
>  void *pci_find_max_end_va(void);
>
> -/* map IGB_UIO resource prototype */
> -int pci_uio_map_resource(struct rte_pci_device *dev);
> -
> -#ifdef RTE_LIBRTE_EAL_HOTPLUG
> -/* unmap IGB_UIO resource prototype */
> -void pci_uio_unmap_resource(struct rte_pci_device *dev);
> -#endif /* RTE_LIBRTE_EAL_HOTPLUG */
> +int pci_uio_alloc_resource(struct rte_pci_device *dev,
> +               struct mapped_pci_resource **uio_res);
> +int pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
> +               struct mapped_pci_resource *uio_res, int map_idx);
>
>  #ifdef VFIO_PRESENT
>
> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> index cafabba..3dfc17b 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> @@ -52,11 +52,6 @@
>
>  void *pci_map_addr = NULL;
>
> -static struct rte_tailq_elem rte_uio_tailq = {
> -       .name = "UIO_RESOURCE_LIST",
> -};
> -EAL_REGISTER_TAILQ(rte_uio_tailq)
> -
>  #define OFF_MAX              ((uint64_t)(off_t)-1)
>
>  static int
> @@ -89,52 +84,6 @@ pci_uio_set_bus_master(int dev_fd)
>  }
>
>  static int
> -pci_uio_map_secondary(struct rte_pci_device *dev)
> -{
> -       int fd, i;
> -       struct mapped_pci_resource *uio_res;
> -       struct mapped_pci_res_list *uio_res_list =
> -                       RTE_TAILQ_CAST(rte_uio_tailq.head,
> mapped_pci_res_list);
> -
> -       TAILQ_FOREACH(uio_res, uio_res_list, next) {
> -
> -               /* skip this element if it doesn't match our PCI address */
> -               if (rte_eal_compare_pci_addr(&uio_res->pci_addr,
> &dev->addr))
> -                       continue;
> -
> -               for (i = 0; i != uio_res->nb_maps; i++) {
> -                       /*
> -                        * open devname, to mmap it
> -                        */
> -                       fd = open(uio_res->maps[i].path, O_RDWR);
> -                       if (fd < 0) {
> -                               RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
> -                                       uio_res->maps[i].path,
> strerror(errno));
> -                               return -1;
> -                       }
> -
> -                       void *mapaddr =
> pci_map_resource(uio_res->maps[i].addr,
> -                                       fd, (off_t)uio_res->maps[i].offset,
> -                                       (size_t)uio_res->maps[i].size, 0);
> -                       if (mapaddr != uio_res->maps[i].addr) {
> -                               RTE_LOG(ERR, EAL,
> -                                       "Cannot mmap device resource file
> %s to address: %p\n",
> -                                       uio_res->maps[i].path,
> -                                       uio_res->maps[i].addr);
> -                               close(fd);
> -                               return -1;
> -                       }
> -                       /* fd is not needed in slave process, close it */
> -                       close(fd);
> -               }
> -               return 0;
> -       }
> -
> -       RTE_LOG(ERR, EAL, "Cannot find resource for device\n");
> -       return 1;
> -}
> -
> -static int
>  pci_mknod_uio_dev(const char *sysfs_uio_path, unsigned uio_num)
>  {
>         FILE *f;
> @@ -254,7 +203,7 @@ pci_get_uio_dev(struct rte_pci_device *dev, char
> *dstbuf,
>         return uio_num;
>  }
>
> -static int
> +int
>  pci_uio_alloc_resource(struct rte_pci_device *dev,
>                 struct mapped_pci_resource **uio_res)
>  {
> @@ -333,7 +282,7 @@ error:
>         return -1;
>  }
>
> -static int
> +int
>  pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
>                 struct mapped_pci_resource *uio_res, int map_idx)
>  {
> @@ -399,144 +348,3 @@ error:
>         rte_free(maps[map_idx].path);
>         return -1;
>  }
> -
> -/* map the PCI resource of a PCI device in virtual memory */
> -int
> -pci_uio_map_resource(struct rte_pci_device *dev)
> -{
> -       int i, map_idx = 0, ret;
> -       uint64_t phaddr;
> -       struct mapped_pci_resource *uio_res = NULL;
> -       struct mapped_pci_res_list *uio_res_list =
> -               RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
> -
> -       dev->intr_handle.fd = -1;
> -       dev->intr_handle.uio_cfg_fd = -1;
> -       dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
> -
> -       /* secondary processes - use already recorded details */
> -       if (rte_eal_process_type() != RTE_PROC_PRIMARY)
> -               return pci_uio_map_secondary(dev);
> -
> -       /* allocate uio resource */
> -       ret = pci_uio_alloc_resource(dev, &uio_res);
> -       if ((ret != 0) || (uio_res == NULL))
> -               return ret;
> -
> -       /* Map all BARs */
> -       for (i = 0; i != PCI_MAX_RESOURCE; i++) {
> -               /* skip empty BAR */
> -               phaddr = dev->mem_resource[i].phys_addr;
> -               if (phaddr == 0)
> -                       continue;
> -
> -               ret = pci_uio_map_resource_by_index(dev, i,
> -                               uio_res, map_idx);
> -               if (ret != 0)
> -                       goto error;
> -
> -               map_idx++;
> -       }
> -
> -       uio_res->nb_maps = map_idx;
> -
> -       TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
> -
> -       return 0;
> -
> -error:
> -       for (i = 0; i < map_idx; i++) {
> -               pci_unmap_resource(uio_res->maps[i].addr,
> -                               (size_t)uio_res->maps[i].size);
> -               rte_free(uio_res->maps[i].path);
> -       }
> -
> -       /* 'uio_res' has valid value here */
> -       rte_free(uio_res);
> -
> -       /* 'uio_cfg_fd' has valid value here */
> -       close(dev->intr_handle.uio_cfg_fd);
> -       dev->intr_handle.uio_cfg_fd = -1;
> -
> -       /* 'fd' has valid value here */
> -       close(dev->intr_handle.fd);
> -       dev->intr_handle.fd = -1;
> -       dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
> -
> -       return -1;
> -}
> -
> -#ifdef RTE_LIBRTE_EAL_HOTPLUG
> -static void
> -pci_uio_unmap(struct mapped_pci_resource *uio_res)
> -{
> -       int i;
> -
> -       if (uio_res == NULL)
> -               return;
> -
> -       for (i = 0; i != uio_res->nb_maps; i++) {
> -               pci_unmap_resource(uio_res->maps[i].addr,
> -                               (size_t)uio_res->maps[i].size);
> -               rte_free(uio_res->maps[i].path);
> -       }
> -}
> -
> -static struct mapped_pci_resource *
> -pci_uio_find_resource(struct rte_pci_device *dev)
> -{
> -       struct mapped_pci_resource *uio_res;
> -       struct mapped_pci_res_list *uio_res_list =
> -                       RTE_TAILQ_CAST(rte_uio_tailq.head,
> mapped_pci_res_list);
> -
> -       if (dev == NULL)
> -               return NULL;
> -
> -       TAILQ_FOREACH(uio_res, uio_res_list, next) {
> -
> -               /* skip this element if it doesn't match our PCI address */
> -               if (!rte_eal_compare_pci_addr(&uio_res->pci_addr,
> &dev->addr))
> -                       return uio_res;
> -       }
> -       return NULL;
> -}
> -
> -/* unmap the PCI resource of a PCI device in virtual memory */
> -void
> -pci_uio_unmap_resource(struct rte_pci_device *dev)
> -{
> -       struct mapped_pci_resource *uio_res;
> -       struct mapped_pci_res_list *uio_res_list =
> -                       RTE_TAILQ_CAST(rte_uio_tailq.head,
> mapped_pci_res_list);
> -
> -       if (dev == NULL)
> -               return;
> -
> -       /* find an entry for the device */
> -       uio_res = pci_uio_find_resource(dev);
> -       if (uio_res == NULL)
> -               return;
> -
> -       /* secondary processes - just free maps */
> -       if (rte_eal_process_type() != RTE_PROC_PRIMARY)
> -               return pci_uio_unmap(uio_res);
> -
> -       TAILQ_REMOVE(uio_res_list, uio_res, next);
> -
> -       /* unmap all resources */
> -       pci_uio_unmap(uio_res);
> -
> -       /* free uio resource */
> -       rte_free(uio_res);
> -
> -       /* close fd if in primary process */
> -       close(dev->intr_handle.fd);
> -       dev->intr_handle.fd = -1;
> -
> -       /* close cfg_fd if in primary process */
> -       close(dev->intr_handle.uio_cfg_fd);
> -       dev->intr_handle.uio_cfg_fd = -1;
> -
> -       dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
> -}
> -#endif /* RTE_LIBRTE_EAL_HOTPLUG */
> --
> 2.1.4
>


Acked-by: David Marchand <david.marchand@6wind.com>

-- 
David Marchand

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v8 12/12] eal: Consolidate rte_eal_pci_probe/close_one_driver() of linuxapp and bsdapp
  2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 12/12] eal: Consolidate rte_eal_pci_probe/close_one_driver() " Tetsuya Mukawa
@ 2015-07-07  8:07                   ` David Marchand
  0 siblings, 0 replies; 120+ messages in thread
From: David Marchand @ 2015-07-07  8:07 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Mon, Jul 6, 2015 at 8:24 AM, Tetsuya Mukawa <mukawa@igel.co.jp> wrote:

> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
>
> This patch consolidates below functions, and implements these in common
> eal code.
>  - rte_eal_pci_probe_one_driver()
>  - rte_eal_pci_close_one_driver()
>
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  lib/librte_eal/bsdapp/eal/eal_pci.c    |  67 +--------------
>  lib/librte_eal/common/eal_common_pci.c | 133
> +++++++++++++++++++++++++++++-
>  lib/librte_eal/common/eal_private.h    |  39 +--------
>  lib/librte_eal/linuxapp/eal/eal_pci.c  | 143
> +--------------------------------
>  4 files changed, 136 insertions(+), 246 deletions(-)
>
> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c
> b/lib/librte_eal/bsdapp/eal/eal_pci.c
> index a27dca3..b7c34f4 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> @@ -85,7 +85,7 @@
>   */
>
>  /* unbind kernel driver for this device */
> -static int
> +int
>  pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)
>  {
>         RTE_LOG(ERR, EAL, "RTE_PCI_DRV_FORCE_UNBIND flag is not
> implemented "
> @@ -357,71 +357,6 @@ error:
>         return -1;
>  }
>
> -/*
> - * If vendor/device ID match, call the devinit() function of the
> - * driver.
> - */
> -int
> -rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct
> rte_pci_device *dev)
> -{
> -       const struct rte_pci_id *id_table;
> -       int ret;
> -
> -       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",
> -                               loc->domain, loc->bus, loc->devid,
> loc->function,
> -                               dev->numa_node);
> -
> -               RTE_LOG(DEBUG, EAL, "  probe driver: %x:%x %s\n",
> dev->id.vendor_id,
> -                               dev->id.device_id, dr->name);
> -
> -               /* no initialization when blacklisted, return without
> error */
> -               if (dev->devargs != NULL &&
> -                       dev->devargs->type == RTE_DEVTYPE_BLACKLISTED_PCI)
> {
> -
> -                       RTE_LOG(DEBUG, EAL, "  Device is blacklisted, not
> initializing\n");
> -                       return 0;
> -               }
> -
> -               if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) {
> -                       /* map resources for devices that use igb_uio */
> -                       ret = pci_uio_map_resource(dev);
> -                       if (ret != 0)
> -                               return ret;
> -               } else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND &&
> -                          rte_eal_process_type() == RTE_PROC_PRIMARY) {
> -                       /* unbind current driver */
> -                       if (pci_unbind_kernel_driver(dev) < 0)
> -                               return -1;
> -               }
> -
> -               /* reference driver structure */
> -               dev->driver = dr;
> -
> -               /* call the driver devinit() function */
> -               return dr->devinit(dr, dev);
> -       }
> -       /* return positive value if driver is not found */
> -       return 1;
> -}
> -
>  /* Init the PCI EAL subsystem */
>  int
>  rte_eal_pci_init(void)
> diff --git a/lib/librte_eal/common/eal_common_pci.c
> b/lib/librte_eal/common/eal_common_pci.c
> index afd14ec..031c7a7 100644
> --- a/lib/librte_eal/common/eal_common_pci.c
> +++ b/lib/librte_eal/common/eal_common_pci.c
> @@ -139,7 +139,7 @@ pci_unmap_resource(void *requested_addr, size_t size)
>  }
>
>  /* Map pci device */
> -int
> +static int
>  pci_map_device(struct rte_pci_device *dev)
>  {
>         int ret = -1;
> @@ -170,7 +170,7 @@ pci_map_device(struct rte_pci_device *dev)
>
>  #ifdef RTE_LIBRTE_EAL_HOTPLUG
>  /* Unmap pci device */
> -void
> +static void
>  pci_unmap_device(struct rte_pci_device *dev)
>  {
>         if (dev == NULL)
> @@ -196,6 +196,135 @@ pci_unmap_device(struct rte_pci_device *dev)
>  #endif /* RTE_LIBRTE_EAL_HOTPLUG */
>
>  /*
> + * 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;
> +       const struct rte_pci_id *id_table;
> +
> +       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",
> +                               loc->domain, loc->bus, loc->devid,
> loc->function,
> +                               dev->numa_node);
> +
> +               RTE_LOG(DEBUG, EAL, "  probe driver: %x:%x %s\n",
> dev->id.vendor_id,
> +                               dev->id.device_id, dr->name);
> +
> +               /* no initialization when blacklisted, return without
> error */
> +               if (dev->devargs != NULL &&
> +                       dev->devargs->type == RTE_DEVTYPE_BLACKLISTED_PCI)
> {
> +                       RTE_LOG(DEBUG, EAL, "  Device is blacklisted, not
> initializing\n");
> +                       return 1;
> +               }
> +
> +               if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) {
> +#ifdef RTE_PCI_CONFIG
> +                       /*
> +                        * Set PCIe config space for high performance.
> +                        * Return value can be ignored.
> +                        */
> +                       pci_config_space_set(dev);
> +#endif
> +                       /* map resources for devices that use igb_uio */
> +                       ret = pci_map_device(dev);
> +                       if (ret != 0)
> +                               return ret;
> +               } else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND &&
> +                               rte_eal_process_type() ==
> RTE_PROC_PRIMARY) {
> +                       /* unbind current driver */
> +                       if (pci_unbind_kernel_driver(dev) < 0)
> +                               return -1;
> +               }
> +
> +               /* reference driver structure */
> +               dev->driver = dr;
> +
> +               /* call the driver devinit() function */
> +               return dr->devinit(dr, dev);
> +       }
> +       /* return positive value if driver is not found */
> +       return 1;
> +}
> +
> +#ifdef RTE_LIBRTE_EAL_HOTPLUG
> +/*
> + * If vendor/device ID match, call the devuninit() function of the
> + * driver.
> + */
> +static int
> +rte_eal_pci_close_one_driver(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",
> +                               loc->domain, loc->bus, loc->devid,
> +                               loc->function, dev->numa_node);
> +
> +               RTE_LOG(DEBUG, EAL, "  remove driver: %x:%x %s\n",
> dev->id.vendor_id,
> +                               dev->id.device_id, dr->name);
> +
> +               /* call the driver devuninit() function */
> +               if (dr->devuninit && (dr->devuninit(dev) < 0))
> +                       return -1;      /* negative value is an error */
> +
> +               /* clear driver structure */
> +               dev->driver = NULL;
> +
> +               if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING)
> +                       /* unmap resources for devices that use igb_uio */
> +                       pci_unmap_device(dev);
> +
> +               return 0;
> +       }
> +
> +       /* return positive value if driver is not found */
> +       return 1;
> +}
> +#endif /* RTE_LIBRTE_EAL_HOTPLUG */
> +
> +/*
>   * 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.
> diff --git a/lib/librte_eal/common/eal_private.h
> b/lib/librte_eal/common/eal_private.h
> index 95b9e30..c3659e2 100644
> --- a/lib/librte_eal/common/eal_private.h
> +++ b/lib/librte_eal/common/eal_private.h
> @@ -156,23 +156,14 @@ struct rte_pci_driver;
>  struct rte_pci_device;
>
>  /**
> - * Map this device
> + * Unbind kernel driver for this device
>   *
>   * This function is private to EAL.
>   *
>   * @return
>   *   0 on success, negative on error
>   */
> -int pci_map_device(struct rte_pci_device *dev);
> -
> -#ifdef RTE_LIBRTE_EAL_HOTPLUG
> -/**
> - * Unmap this device
> - *
> - * This function is private to EAL.
> - */
> -void pci_unmap_device(struct rte_pci_device *dev);
> -#endif /* RTE_LIBRTE_EAL_HOTPLUG */
> +int pci_unbind_kernel_driver(struct rte_pci_device *dev);
>
>  /**
>   * Map the PCI resource of a PCI device in virtual memory
> @@ -194,32 +185,6 @@ void pci_uio_unmap_resource(struct rte_pci_device
> *dev);
>  #endif /* RTE_LIBRTE_EAL_HOTPLUG */
>
>  /**
> - * Mmap memory for single PCI device
> - *
> - * This function is private to EAL.
> - *
> - * @return
> - *   0 on success, negative on error
> - */
> -int rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr,
> -               struct rte_pci_device *dev);
> -
> -/**
> - * Munmap memory for single PCI device
> - *
> - * This function is private to EAL.
> - *
> - * @param      dr
> - *  The pointer to the pci driver structure
> - * @param      dev
> - *  The pointer to the pci device structure
> - * @return
> - *   0 on success, negative on error
> - */
> -int rte_eal_pci_close_one_driver(struct rte_pci_driver *dr,
> -               struct rte_pci_device *dev);
> -
> -/**
>   * Allocate uio resource for PCI device
>   *
>   * 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 7e8df7d..ad6d1de 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_pci.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
> @@ -2,6 +2,7 @@
>   *   BSD LICENSE
>   *
>   *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
> + *   Copyright(c) 2015 IGEL Co., Ltd.
>   *   All rights reserved.
>   *
>   *   Redistribution and use in source and binary forms, with or without
> @@ -56,7 +57,7 @@
>   */
>
>  /* unbind kernel driver for this device */
> -static int
> +int
>  pci_unbind_kernel_driver(struct rte_pci_device *dev)
>  {
>         int n;
> @@ -522,146 +523,6 @@ pci_config_space_set(struct rte_pci_device *dev)
>  }
>  #endif
>
> -/*
> - * If vendor/device ID match, call the devinit() function of the
> - * driver.
> - */
> -int
> -rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, 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++) {
> -
> -               /* 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",
> -                               loc->domain, loc->bus, loc->devid,
> loc->function,
> -                               dev->numa_node);
> -
> -               RTE_LOG(DEBUG, EAL, "  probe driver: %x:%x %s\n",
> dev->id.vendor_id,
> -                               dev->id.device_id, dr->name);
> -
> -               /* no initialization when blacklisted, return without
> error */
> -               if (dev->devargs != NULL &&
> -                       dev->devargs->type == RTE_DEVTYPE_BLACKLISTED_PCI)
> {
> -                       RTE_LOG(DEBUG, EAL, "  Device is blacklisted, not
> initializing\n");
> -                       return 1;
> -               }
> -
> -               if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) {
> -#ifdef RTE_PCI_CONFIG
> -                       /*
> -                        * Set PCIe config space for high performance.
> -                        * Return value can be ignored.
> -                        */
> -                       pci_config_space_set(dev);
> -#endif
> -                       /* map resources for devices that use igb_uio */
> -                       ret = pci_map_device(dev);
> -                       if (ret != 0)
> -                               return ret;
> -               } else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND &&
> -                          rte_eal_process_type() == RTE_PROC_PRIMARY) {
> -                       /* unbind current driver */
> -                       if (pci_unbind_kernel_driver(dev) < 0)
> -                               return -1;
> -               }
> -
> -               /* reference driver structure */
> -               dev->driver = dr;
> -
> -               /* call the driver devinit() function */
> -               return dr->devinit(dr, dev);
> -       }
> -       /* return positive value if driver is not found */
> -       return 1;
> -}
> -
> -#ifdef RTE_LIBRTE_EAL_HOTPLUG
> -/*
> - * If vendor/device ID match, call the devuninit() function of the
> - * driver.
> - */
> -int
> -rte_eal_pci_close_one_driver(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",
> -                               loc->domain, loc->bus, loc->devid,
> -                               loc->function, dev->numa_node);
> -
> -               RTE_LOG(DEBUG, EAL, "  remove driver: %x:%x %s\n",
> -                               dev->id.vendor_id, dev->id.device_id,
> -                               dr->name);
> -
> -               /* call the driver devuninit() function */
> -               if (dr->devuninit && (dr->devuninit(dev) < 0))
> -                       return -1;      /* negative value is an error */
> -
> -               /* clear driver structure */
> -               dev->driver = NULL;
> -
> -               if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING)
> -                       /* unmap resources for devices that use igb_uio */
> -                       pci_unmap_device(dev);
> -
> -               return 0;
> -       }
> -       /* return positive value if driver is not found */
> -       return 1;
> -}
> -#else /* RTE_LIBRTE_EAL_HOTPLUG */
> -int
> -rte_eal_pci_close_one_driver(struct rte_pci_driver *dr __rte_unused,
> -               struct rte_pci_device *dev __rte_unused)
> -{
> -       RTE_LOG(ERR, EAL, "Hotplug support isn't enabled\n");
> -       return -1;
> -}
> -#endif /* RTE_LIBRTE_EAL_HOTPLUG */
> -
>  /* Init the PCI EAL subsystem */
>  int
>  rte_eal_pci_init(void)
> --
> 2.1.4
>
>

Acked-by: David Marchand <david.marchand@6wind.com>

-- 
David Marchand

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v8 01/12] eal: Fix coding style of eal_pci.c and eal_pci_uio.c
  2015-07-07  8:04                   ` David Marchand
@ 2015-07-08  2:42                     ` Tetsuya Mukawa
  0 siblings, 0 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-08  2:42 UTC (permalink / raw)
  To: David Marchand; +Cc: dev

On 2015/07/07 17:04, David Marchand wrote:
> On Mon, Jul 6, 2015 at 8:24 AM, Tetsuya Mukawa <mukawa@igel.co.jp
> <mailto:mukawa@igel.co.jp>> wrote:
>
>     From: "Tetsuya.Mukawa" <mukawa@igel.co.jp <mailto:mukawa@igel.co.jp>>
>
>     This patch fixes coding style of below files in linuxapp and bsdapp.
>      - eal_pci.c
>      - eal_pci_uio.c
>
>     Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp
>     <mailto:mukawa@igel.co.jp>>
>     Acked-by: Stephen Hemminger <stephen@networkplumber.org
>     <mailto:stephen@networkplumber.org>>
>
>
> Acked-by: David Marchand <david.marchand@6wind.com
> <mailto:david.marchand@6wind.com>>
>
> I think I already acked this, please can you keep the ack tags (even
> if this is a trivial patch) ?
>
>
> -- 
> David Marchand

Hi David,

I appreciate your comments.
I will add above in next patch.

Regards,
Tetsuya

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v8 03/12] eal: Fix memory leaks and needless increment of pci_map_addr
  2015-07-07  8:04                   ` David Marchand
@ 2015-07-08  2:42                     ` Tetsuya Mukawa
  0 siblings, 0 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-08  2:42 UTC (permalink / raw)
  To: David Marchand; +Cc: dev

On 2015/07/07 17:04, David Marchand wrote:
> Hello Tetsuya, 
>
> Little comment below for this patch.
>
> On Mon, Jul 6, 2015 at 8:24 AM, Tetsuya Mukawa <mukawa@igel.co.jp
> <mailto:mukawa@igel.co.jp>> wrote:
>
>
>     diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c
>     b/lib/librte_eal/bsdapp/eal/eal_pci.c
>     index a63d450..63758c7 100644
>     --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
>     +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
>     @@ -202,7 +202,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>             uint64_t offset;
>             uint64_t pagesz;
>             struct rte_pci_addr *loc = &dev->addr;
>     -       struct uio_resource *uio_res;
>     +       struct uio_resource *uio_res = NULL;
>             struct uio_res_list *uio_res_list =
>                             RTE_TAILQ_CAST(rte_uio_tailq.head,
>     uio_res_list);
>             struct uio_map *maps;
>     [snip]
>     @@ -275,6 +274,16 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>             TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
>
>             return 0;
>     +
>     +error:
>     +       if (uio_res)
>     +               rte_free(uio_res);
>
>
> As long as uio_res is initialized to NULL, no need to check.
> rte_free() behaves the same as free().
>  

Oh, I didn't notice it. Thanks.

>
>     diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>     b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>     index 37dc936..4e50533 100644
>     --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>     +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>     [snip]
>     @@ -400,6 +397,25 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>             TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
>
>             return 0;
>     +
>     +error:
>     +       for (i = 0; i < map_idx; i++) {
>     +               pci_unmap_resource(uio_res->maps[i].addr,
>     +                               (size_t)uio_res->maps[i].size);
>     +               rte_free(maps[i].path);
>     +       }
>     +       if (uio_res)
>     +               rte_free(uio_res);
>
>
> Idem.
>
>
> With this, 
> Acked-by: David Marchand <david.marchand@6wind.com
> <mailto:david.marchand@6wind.com>>
>

I will fix codes like above.

Tetsuya


> -- 
> David Marchand

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v8 05/12] eal: Fix uio mapping differences between linuxapp and bsdapp
  2015-07-07  8:04                   ` David Marchand
@ 2015-07-08  2:42                     ` Tetsuya Mukawa
  0 siblings, 0 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-08  2:42 UTC (permalink / raw)
  To: David Marchand; +Cc: dev

On 2015/07/07 17:04, David Marchand wrote:
> On Mon, Jul 6, 2015 at 8:24 AM, Tetsuya Mukawa <mukawa@igel.co.jp
> <mailto:mukawa@igel.co.jp>> wrote:
>
>     diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c
>     b/lib/librte_eal/bsdapp/eal/eal_pci.c
>     index 21d1e66..92d9886 100644
>     --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
>     +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
>
>     @@ -170,19 +154,33 @@ pci_uio_map_secondary(struct rte_pci_device
>     *dev)
>             TAILQ_FOREACH(uio_res, uio_res_list, next) {
>
>                     /* skip this element if it doesn't match our PCI
>     address */
>     -               if (memcmp(&uio_res->pci_addr, &dev->addr,
>     sizeof(dev->addr)))
>     +               if (rte_eal_compare_pci_addr(&uio_res->pci_addr,
>     &dev->addr))
>                             continue;
>
>                     for (i = 0; i != uio_res->nb_maps; i++) {
>     -                       if (pci_map_resource(uio_res->maps[i].addr,
>     -                                            uio_res->path,
>     -                                           
>     (off_t)uio_res->maps[i].offset,
>     -                                           
>     (size_t)uio_res->maps[i].size)
>     -                           != uio_res->maps[i].addr) {
>     +                       /*
>     +                        * open devname, to mmap it
>     +                        */
>     +                       fd = open(uio_res->maps[i].path, O_RDWR);
>     +                       if (fd < 0) {
>     +                               RTE_LOG(ERR, EAL, "Cannot open %s:
>     %s\n",
>     +                                       uio_res->maps[i].path,
>     strerror(errno));
>     +                               return -1;
>     +                       }
>     +
>     +                       void *mapaddr =
>     pci_map_resource(uio_res->maps[i].addr,
>     +                                       fd,
>     (off_t)uio_res->maps[i].offset,
>     +                                     
>      (size_t)uio_res->maps[i].size, 0);
>
>
> I suppose you can close fd here

Yes, I will move close() here.

Tetsuya

>  
>
>     +                       if (mapaddr != uio_res->maps[i].addr) {
>                                     RTE_LOG(ERR, EAL,
>     -                                       "Cannot mmap device
>     resource\n");
>     +                                       "Cannot mmap device
>     resource file %s to address: %p\n",
>     +                                       uio_res->maps[i].path,
>     +                                       uio_res->maps[i].addr);
>     +                               close(fd);
>
>
> and remove it from here
>
>                                     return -1;
>                             }
>     +                       /* fd is not needed in slave process,
>     close it */
>     +                       close(fd);
>
>
> and here.
>
>
> The rest is ok for me.
> Acked-by: David Marchand <david.marchand@6wind.com
> <mailto:david.marchand@6wind.com>>
>
> -- 
> David Marchand

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v8 06/12] eal: Add pci_uio_alloc_resource()
  2015-07-07  8:04                   ` David Marchand
@ 2015-07-08  2:42                     ` Tetsuya Mukawa
  0 siblings, 0 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-08  2:42 UTC (permalink / raw)
  To: David Marchand; +Cc: dev

On 2015/07/07 17:04, David Marchand wrote:
> On Mon, Jul 6, 2015 at 8:24 AM, Tetsuya Mukawa <mukawa@igel.co.jp
> <mailto:mukawa@igel.co.jp>> wrote:
>
>     From: "Tetsuya.Mukawa" <mukawa@igel.co.jp <mailto:mukawa@igel.co.jp>>
>
>     This patch adds a new function called pci_uio_alloc_resource().
>     The function hides how to prepare uio resource in linuxapp and bsdapp.
>     With the function, pci_uio_map_resource() will be more abstracted.
>
>     Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp
>     <mailto:mukawa@igel.co.jp>>
>     ---
>      lib/librte_eal/bsdapp/eal/eal_pci.c       | 84
>     +++++++++++++++++---------
>      lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 98
>     +++++++++++++++++++++----------
>      2 files changed, 123 insertions(+), 59 deletions(-)
>
>     diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c
>     b/lib/librte_eal/bsdapp/eal/eal_pci.c
>     index 92d9886..ce0ca07 100644
>     --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
>     +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
>     @@ -189,28 +189,17 @@ 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)
>     +pci_uio_alloc_resource(struct rte_pci_device *dev,
>     +               struct mapped_pci_resource **uio_res)
>      {
>     -       int i, map_idx = 0;
>             char devname[PATH_MAX]; /* contains the /dev/uioX */
>     -       void *mapaddr;
>     -       uint64_t phaddr;
>     -       uint64_t offset;
>     -       uint64_t pagesz;
>     -       struct rte_pci_addr *loc = &dev->addr;
>     -       struct mapped_pci_resource *uio_res = NULL;
>     -       struct mapped_pci_res_list *uio_res_list =
>     -                       RTE_TAILQ_CAST(rte_uio_tailq.head,
>     mapped_pci_res_list);
>     -       struct pci_map *maps;
>     +       struct rte_pci_addr *loc;
>
>     -       dev->intr_handle.fd = -1;
>     -       dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
>     +       if ((dev == NULL) || (uio_res == NULL))
>     +               return -1;
>
>
> This is an "internal" function, dev cannot be null, neither uio_res.

I will fix it.

>  
>
>     -       /* secondary processes - use already recorded details */
>     -       if (rte_eal_process_type() != RTE_PROC_PRIMARY)
>     -               return pci_uio_map_secondary(dev);
>     +       loc = &dev->addr;
>
>             snprintf(devname, sizeof(devname), "/dev/uio@pci:%u:%u:%u",
>                             dev->addr.bus, dev->addr.devid,
>     dev->addr.function);
>     @@ -231,18 +220,57 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>             dev->intr_handle.type = RTE_INTR_HANDLE_UIO;
>
>             /* allocate the mapping details for secondary processes*/
>     -       if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res),
>     0)) == NULL) {
>     +       *uio_res = rte_zmalloc("UIO_RES", sizeof(**uio_res), 0);
>     +       if (*uio_res == NULL) {
>                     RTE_LOG(ERR, EAL,
>                             "%s(): cannot store uio mmap details\n",
>     __func__);
>                     goto error;
>             }
>
>     -       snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
>     -       memcpy(&uio_res->pci_addr, &dev->addr,
>     sizeof(uio_res->pci_addr));
>     +       snprintf((*uio_res)->path, sizeof((*uio_res)->path), "%s",
>     devname);
>     +       memcpy(&(*uio_res)->pci_addr, &dev->addr,
>     sizeof((*uio_res)->pci_addr));
>
>     +       return 0;
>     +
>     +error:
>     +       if (dev->intr_handle.fd) {
>     +               close(dev->intr_handle.fd);
>     +               dev->intr_handle.fd = -1;
>     +               dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
>     +       }
>     +       return -1;
>     +}
>     +
>     +/* map the PCI resource of a PCI device in virtual memory */
>     +static int
>     +pci_uio_map_resource(struct rte_pci_device *dev)
>     +{
>     +       int i, map_idx = 0, ret;
>     +       char *devname;
>     +       void *mapaddr;
>     +       uint64_t phaddr;
>     +       uint64_t offset;
>     +       uint64_t pagesz;
>     +       struct mapped_pci_resource *uio_res = NULL;
>     +       struct mapped_pci_res_list *uio_res_list =
>     +               RTE_TAILQ_CAST(rte_uio_tailq.head,
>     mapped_pci_res_list);
>     +       struct pci_map *maps;
>     +
>     +       dev->intr_handle.fd = -1;
>     +       dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
>     +
>     +       /* secondary processes - use already recorded details */
>     +       if (rte_eal_process_type() != RTE_PROC_PRIMARY)
>     +               return pci_uio_map_secondary(dev);
>     +
>     +       /* allocate uio resource */
>     +       ret = pci_uio_alloc_resource(dev, &uio_res);
>     +       if ((ret != 0) || (uio_res == NULL))
>     +               return ret;
>
>
> If ret != 0, uio_res cannot be NULL.

Also I will fix it.

>
>  
>
>             /* Map all BARs */
>             pagesz = sysconf(_SC_PAGESIZE);
>     +       devname = uio_res->path;
>
>             maps = uio_res->maps;
>             for (i = 0; i != PCI_MAX_RESOURCE; i++) {
>     @@ -298,13 +326,15 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>      error:
>             for (i = 0; i < map_idx; i++)
>                     rte_free(maps[i].path);
>     -       if (uio_res)
>     -               rte_free(uio_res);
>     -       if (dev->intr_handle.fd >= 0) {
>     -               close(dev->intr_handle.fd);
>     -               dev->intr_handle.fd = -1;
>     -               dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
>     -       }
>     +
>     +       /* 'uio_res' has valid value here */
>
>
> Not sure what this comment means, do you mean != NULL ? It does not
> matter.

I thought rte_free() fails when NULL is passed.
Because of above, I wanted to mention here we don't need to check NULL
because uio_res will have non-NULL value.
But, as you mentioned in other patch, we don't need to check it.
Anyway, I will remove the comment.

>  
>
>     +       rte_free(uio_res);
>     +
>     +       /* 'fd' has valid value here */
>     +       close(dev->intr_handle.fd);
>     +       dev->intr_handle.fd = -1;
>     +       dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
>     +
>             return -1;
>      }
>
>
> In the end, if you add this "alloc" function, why not introduce a
> "free" function that does this cleanup ? 
>
>
> Same comments apply to linux modifications.
>

Sure, I will introduce it.

Tetsuya

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v8 07/12] eal: Add pci_uio_map_resource_by_index()
  2015-07-07  8:05                   ` David Marchand
@ 2015-07-08  2:42                     ` Tetsuya Mukawa
  0 siblings, 0 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-08  2:42 UTC (permalink / raw)
  To: David Marchand; +Cc: dev

On 2015/07/07 17:05, David Marchand wrote:
>
>
> On Mon, Jul 6, 2015 at 8:24 AM, Tetsuya Mukawa <mukawa@igel.co.jp
> <mailto:mukawa@igel.co.jp>> wrote:
>
>     From: "Tetsuya.Mukawa" <mukawa@igel.co.jp <mailto:mukawa@igel.co.jp>>
>
>     This patch adds a new function called pci_uio_map_resource_by_index().
>     The function hides how to map uio resource in linuxapp and bsdapp.
>     With the function, pci_uio_map_resource() will be more abstracted.
>
>     Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp
>     <mailto:mukawa@igel.co.jp>>
>     ---
>      lib/librte_eal/bsdapp/eal/eal_pci.c       | 107
>     +++++++++++++++-----------
>      lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 124
>     +++++++++++++++++-------------
>      2 files changed, 133 insertions(+), 98 deletions(-)
>
>     diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c
>     b/lib/librte_eal/bsdapp/eal/eal_pci.c
>     index ce0ca07..c76f936 100644
>     --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
>     +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
>     @@ -241,20 +241,73 @@ error:
>             return -1;
>      }
>
>     +static int
>     +pci_uio_map_resource_by_index(struct rte_pci_device *dev, int
>     res_idx,
>     +               struct mapped_pci_resource *uio_res, int map_idx)
>     +{
>     +       int fd;
>     +       char *devname;
>     +       void *mapaddr;
>     +       uint64_t offset;
>     +       uint64_t pagesz;
>     +       struct pci_map *maps;
>     +
>     +       if ((dev == NULL) || (uio_res == NULL) || (uio_res->path
>     == NULL))
>     +               return -1;
>
>
> No need for these checks.
>  

I will fix it.

>     diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>     b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>     index f408bd3..cafabba 100644
>     --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>     +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>     @@ -333,19 +333,82 @@ error:
>             return -1;
>      }
>
>     +static int
>     +pci_uio_map_resource_by_index(struct rte_pci_device *dev, int
>     res_idx,
>     +               struct mapped_pci_resource *uio_res, int map_idx)
>     +{
>     +       int fd;
>     +       char devname[PATH_MAX]; /* contains the /dev/uioX */
>     +       void *mapaddr;
>     +       struct rte_pci_addr *loc;
>     +       struct pci_map *maps;
>     +
>     +       if ((dev == NULL) || (uio_res == NULL))
>     +               return -1;
>
>
> Idem.
>
>

Also, I will fix it.

Tetsuya


> Then, 
> Acked-by: David Marchand <david.marchand@6wind.com
> <mailto:david.marchand@6wind.com>>
>
>
> -- 
> David Marchand
>

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v8 11/12] eal: Consolidate pci_map/unmap_device() of linuxapp and bsdapp
  2015-07-07  8:06                   ` David Marchand
@ 2015-07-08  2:42                     ` Tetsuya Mukawa
  2015-07-08  8:27                       ` Thomas Monjalon
  0 siblings, 1 reply; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-08  2:42 UTC (permalink / raw)
  To: David Marchand; +Cc: dev

On 2015/07/07 17:06, David Marchand wrote:
> On Mon, Jul 6, 2015 at 8:24 AM, Tetsuya Mukawa <mukawa@igel.co.jp
> <mailto:mukawa@igel.co.jp>> wrote:
>
>     From: "Tetsuya.Mukawa" <mukawa@igel.co.jp <mailto:mukawa@igel.co.jp>>
>
>     The patch consolidates below functions, and implemented in common
>     eal code.
>      - pci_map_device()
>      - pci_unmap_device()
>
>     Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp
>     <mailto:mukawa@igel.co.jp>>
>     ---
>      lib/librte_eal/bsdapp/eal/eal_pci.c     |  3 ++
>      lib/librte_eal/common/eal_common_pci.c  | 57
>     +++++++++++++++++++++++++++++++++
>      lib/librte_eal/common/eal_private.h     | 19 +++++++++++
>      lib/librte_eal/common/include/rte_pci.h |  1 +
>      lib/librte_eal/linuxapp/eal/eal_pci.c   | 53
>     ------------------------------
>      lib/librte_ether/rte_ethdev.c           |  2 ++
>      6 files changed, 82 insertions(+), 53 deletions(-)
>
>     diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c
>     b/lib/librte_eal/bsdapp/eal/eal_pci.c
>     index f85fc1e..a27dca3 100644
>     --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
>     +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
>     @@ -240,6 +240,9 @@ pci_scan_one(int dev_pci_fd, struct pci_conf
>     *conf)
>             /* FreeBSD has no NUMA support (yet) */
>             dev->numa_node = 0;
>
>     +       /* FreeBSD has only one pass through driver */
>     +       dev->kdrv = RTE_KDRV_NIC_UIO;
>     +
>
>
> Do we need a new define for this ?
>
> I know this is not really part of this patchset, but this kdrv should
> just disappear.

Could I make sure this?
It seems 'struct rte_pci_device' still has kdrv member, also my patch
defines RTE_KDRV_NIC_UIO like below.

--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -149,6 +149,7 @@ enum rte_kernel_driver {
 	RTE_KDRV_IGB_UIO,
 	RTE_KDRV_VFIO,
 	RTE_KDRV_UIO_GENERIC,
+	RTE_KDRV_NIC_UIO,
 };

Do you mean kdrv member will disappear in next DPDK release?

Tetsuya

>
>
> -- 
> David Marchand

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v8 11/12] eal: Consolidate pci_map/unmap_device() of linuxapp and bsdapp
  2015-07-08  2:42                     ` Tetsuya Mukawa
@ 2015-07-08  8:27                       ` Thomas Monjalon
  2015-07-08  8:50                         ` Tetsuya Mukawa
  0 siblings, 1 reply; 120+ messages in thread
From: Thomas Monjalon @ 2015-07-08  8:27 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

2015-07-08 11:42, Tetsuya Mukawa:
> On 2015/07/07 17:06, David Marchand wrote:
> > On Mon, Jul 6, 2015 at 8:24 AM, Tetsuya Mukawa <mukawa@igel.co.jp
> >     +       /* FreeBSD has only one pass through driver */
> >     +       dev->kdrv = RTE_KDRV_NIC_UIO;
> >     +
> >
> > Do we need a new define for this ?
> >
> > I know this is not really part of this patchset, but this kdrv should
> > just disappear.
> 
> Do you mean kdrv member will disappear in next DPDK release?

No, it is not (yet) planned to be removed.
But David thinks it shouldn't be part of the public API.
So, as David said, this comment is not really related to your patch.
It may be addressed separately.
Please Tetsuya, go ahead with the v9.
Thanks

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v8 11/12] eal: Consolidate pci_map/unmap_device() of linuxapp and bsdapp
  2015-07-08  8:27                       ` Thomas Monjalon
@ 2015-07-08  8:50                         ` Tetsuya Mukawa
  0 siblings, 0 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-08  8:50 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev

On 2015/07/08 17:27, Thomas Monjalon wrote:
> 2015-07-08 11:42, Tetsuya Mukawa:
>> On 2015/07/07 17:06, David Marchand wrote:
>>> On Mon, Jul 6, 2015 at 8:24 AM, Tetsuya Mukawa <mukawa@igel.co.jp
>>>     +       /* FreeBSD has only one pass through driver */
>>>     +       dev->kdrv = RTE_KDRV_NIC_UIO;
>>>     +
>>>
>>> Do we need a new define for this ?
>>>
>>> I know this is not really part of this patchset, but this kdrv should
>>> just disappear.
>> Do you mean kdrv member will disappear in next DPDK release?
> No, it is not (yet) planned to be removed.
> But David thinks it shouldn't be part of the public API.
> So, as David said, this comment is not really related to your patch.
> It may be addressed separately.
> Please Tetsuya, go ahead with the v9.
> Thanks

Thanks, I've got it.

Tetsuya

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v9 00/12] Clean up pci uio implementations
  2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 11/12] eal: Consolidate pci_map/unmap_device() " Tetsuya Mukawa
  2015-06-30 14:45               ` Iremonger, Bernard
  2015-07-06  6:24               ` [dpdk-dev] [PATCH v8 00/12] Clean up pci uio implementations Tetsuya Mukawa
@ 2015-07-08 10:34               ` Tetsuya Mukawa
  2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 01/12] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
                                   ` (12 more replies)
  2 siblings, 13 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-08 10:34 UTC (permalink / raw)
  To: dev

Currently Linux implementation and BSD implementation have almost same
code about pci uio. This patch series cleans up it.

PATCH v9 changes:
 - Add lost Acked-by and Tested-by signatures.
 - Remove NULL checkings before calling rte_free().
 - Fix pci_uio_map_secondary() to remove needless close().
 - Remove needless parameter checkings of pci_uio_alloc_resource() and
   pci_uio_map_resource_by_index().
 - Remove needless error checking for return value of pci_uio_alloc_resource().
 - Introduce pci_uio_free_resource().
 - Remove some comments of pci_uio_map_resource().
   (Thanks to David Marchand)

PATCH v8 changes:
 - Fix comments of header file.
 - Fix error handling logic of resource allocation functions.
   (Thanks to Bruce Richardson)
 - Add copyright.
 - Fix patch description.
   (Thanks to Iremonger, Bernard)

PATCH v7 changes:
 - Add below patches. Also, the order of patches are changed.
   - eal: Add pci_uio_alloc_resource()
   - eal: Add pci_uio_map_resource_by_index()
   - eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp
   - eal: Consolidate pci_map/unmap_resource() of linuxapp and bsdapp
   - eal: Consolidate pci uio functions of linuxapp and bsdapp
   - eal: Consolidate pci_map/unmap_device() of linuxapp and bsdapp
   - eal: Consolidate rte_eal_pci_probe/close_one_driver() of linuxapp and bsdapp
   (Thanks to Bruce Richardson)
 - While adding above, below patches are not changed at all.
   - eal: Fix coding style of eal_pci.c and eal_pci_uio.c
   - eal: Close file descriptor of uio configuration
   - eal: Fix memory leaks and needless increment of pci_map_addr
   - eal/bsdapp: Change names of pci related data structure
   - eal: Fix uio mapping differences between linuxapp and bsdapp
 - some function names are changed like below.
   - pci_uio_alloc_uio_resource() to pci_uio_alloc_resource().
   - pci_uio_map_uio_resource_by_index() to pci_uio_map_resource_by_index().
   (Thanks to Iremonger, Bernard)

PATCH v6 changes:
 - Free mapped resources in pci_uio_map_resource().
 - Fix error handling in pci_uio_map_resource().
   (Thanks to David, Marchand)

PATCH v5 changes:
 - Rebase to latest master branch.

PATCH v4 changes:
 - Rebase to latest master branch.
 - Fix bug in pci_uio_map_resource() of BSD code. 'maps[i].path' shouldn't be freed.
     Fixed in below patch:
     [PATCH 3/5] eal: Fix memory leaks and needless increment of pci_map_addr
 - 'path' member of 'struct mapped_pci_resource' should not be removed because it will be used in BSD code.
     Fixed in below patch:
     [PATCH 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp

PATCH v3 changes:
 - Squash patches related with pci_map_resource().
 - Free maps[].path to easy to understand.
   (Thanks to Iremonger, Bernard)
 - Close fds opened in this function.
 - Remove unused path variable from mapped_pci_resource structure.

PATCH v2 changes:
 - Move 'if-condition' to later patch series.
 - Fix memory leaks of path.
 - Fix typos.
   (Thanks to David Marchand)
 - Fix commit title and body.
 - Fix pci_map_resource() to handle MAP_FAILED.
   (Thanks to Iremonger, Bernard)

Changes:
 - This patch set is derived from below.
   "[PATCH v2] eal: Port Hotplug support for BSD"
 - Set cfg_fd as -1, when cfg_fd is closed.
   (Thanks to Iremonger, Bernard)
 - Remove needless coding style fixings.
 - Fix coding style of if-else condition.
   (Thanks to Richardson, Bruce)


Tetsuya.Mukawa (12):
  eal: Fix coding style of eal_pci.c and eal_pci_uio.c
  eal: Close file descriptor of uio configuration
  eal: Fix memory leaks and needless increment of pci_map_addr
  eal/bsdapp: Change names of pci related data structure
  eal: Fix uio mapping differences between linuxapp and bsdapp
  eal: Add pci_uio_alloc/free_resource()
  eal: Add pci_uio_map_resource_by_index()
  eal: Consolidate pci_map and mapped_pci_resource of linuxapp and
    bsdapp
  eal: Consolidate pci_map/unmap_resource() of linuxapp and bsdapp
  eal: Consolidate pci uio functions of linuxapp and bsdapp
  eal: Consolidate pci_map/unmap_device() of linuxapp and bsdapp
  eal: Consolidate rte_eal_pci_probe/close_one_driver() of linuxapp and
    bsdapp

 lib/librte_eal/bsdapp/eal/Makefile                 |   2 +
 lib/librte_eal/bsdapp/eal/eal_pci.c                | 283 ++++++--------------
 .../bsdapp/eal/include/exec-env/rte_interrupts.h   |   2 +
 lib/librte_eal/common/eal_common_pci.c             | 226 ++++++++++++++++
 lib/librte_eal/common/eal_common_pci_uio.c         | 225 ++++++++++++++++
 lib/librte_eal/common/eal_private.h                |  73 ++++-
 lib/librte_eal/common/include/rte_pci.h            |  62 +++++
 lib/librte_eal/linuxapp/eal/Makefile               |   2 +
 lib/librte_eal/linuxapp/eal/eal_pci.c              | 237 +----------------
 lib/librte_eal/linuxapp/eal/eal_pci_init.h         |  42 +--
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c          | 296 +++++++--------------
 lib/librte_ether/rte_ethdev.c                      |   2 +
 12 files changed, 760 insertions(+), 692 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_pci_uio.c

-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v9 01/12] eal: Fix coding style of eal_pci.c and eal_pci_uio.c
  2015-07-08 10:34               ` [dpdk-dev] [PATCH v9 00/12] Clean up pci uio implementations Tetsuya Mukawa
@ 2015-07-08 10:34                 ` Tetsuya Mukawa
  2015-07-08 16:09                   ` Stephen Hemminger
  2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 02/12] eal: Close file descriptor of uio configuration Tetsuya Mukawa
                                   ` (11 subsequent siblings)
  12 siblings, 1 reply; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-08 10:34 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

This patch fixes coding style of below files in linuxapp and bsdapp.
 - eal_pci.c
 - eal_pci_uio.c

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: David Marchand <david.marchand@6wind.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Bernard Iremonger <bernard.iremonger@intel.com>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c       | 13 ++++++++-----
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 13 +++++++++----
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 2df5c1c..a63d450 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -2,6 +2,7 @@
  *   BSD LICENSE
  *
  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2015 IGEL Co., Ltd.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -161,9 +162,10 @@ fail:
 static int
 pci_uio_map_secondary(struct rte_pci_device *dev)
 {
-        size_t i;
-        struct uio_resource *uio_res;
-	struct uio_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
+	size_t i;
+	struct uio_resource *uio_res;
+	struct uio_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
 
 	TAILQ_FOREACH(uio_res, uio_res_list, next) {
 
@@ -201,7 +203,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	uint64_t pagesz;
 	struct rte_pci_addr *loc = &dev->addr;
 	struct uio_resource *uio_res;
-	struct uio_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
+	struct uio_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
 	struct uio_map *maps;
 
 	dev->intr_handle.fd = -1;
@@ -311,7 +314,7 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
 	/* FreeBSD has no NUMA support (yet) */
 	dev->numa_node = 0;
 
-/* parse resources */
+	/* parse resources */
 	switch (conf->pc_hdr & PCIM_HDRTYPE) {
 	case PCIM_HDRTYPE_NORMAL:
 		max = PCIR_MAX_BAR_0;
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index b5116a7..5915a84 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -2,6 +2,7 @@
  *   BSD LICENSE
  *
  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2015 IGEL Co., Ltd.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -92,7 +93,8 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 {
 	int fd, i;
 	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 
 	TAILQ_FOREACH(uio_res, uio_res_list, next) {
 
@@ -272,7 +274,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	uint64_t phaddr;
 	struct rte_pci_addr *loc = &dev->addr;
 	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 	struct pci_map *maps;
 
 	dev->intr_handle.fd = -1;
@@ -417,7 +420,8 @@ static struct mapped_pci_resource *
 pci_uio_find_resource(struct rte_pci_device *dev)
 {
 	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 
 	if (dev == NULL)
 		return NULL;
@@ -436,7 +440,8 @@ void
 pci_uio_unmap_resource(struct rte_pci_device *dev)
 {
 	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 
 	if (dev == NULL)
 		return;
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v9 02/12] eal: Close file descriptor of uio configuration
  2015-07-08 10:34               ` [dpdk-dev] [PATCH v9 00/12] Clean up pci uio implementations Tetsuya Mukawa
  2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 01/12] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
@ 2015-07-08 10:34                 ` Tetsuya Mukawa
  2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 03/12] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
                                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-08 10:34 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

When pci_uio_unmap_resource() is called, a file descriptor that is used
for uio configuration should be closed.

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Bernard Iremonger <bernard.iremonger@intel.com>
Acked-by: David Marchand <david.marchand@6wind.com>
---
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 5915a84..37dc936 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -465,8 +465,12 @@ pci_uio_unmap_resource(struct rte_pci_device *dev)
 
 	/* close fd if in primary process */
 	close(dev->intr_handle.fd);
-
 	dev->intr_handle.fd = -1;
+
+	/* close cfg_fd if in primary process */
+	close(dev->intr_handle.uio_cfg_fd);
+	dev->intr_handle.uio_cfg_fd = -1;
+
 	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
 }
 #endif /* RTE_LIBRTE_EAL_HOTPLUG */
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v9 03/12] eal: Fix memory leaks and needless increment of pci_map_addr
  2015-07-08 10:34               ` [dpdk-dev] [PATCH v9 00/12] Clean up pci uio implementations Tetsuya Mukawa
  2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 01/12] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
  2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 02/12] eal: Close file descriptor of uio configuration Tetsuya Mukawa
@ 2015-07-08 10:34                 ` Tetsuya Mukawa
  2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 04/12] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
                                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-08 10:34 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

This patch fixes following memory leaks.
- When open() is failed, uio_res and fds won't be freed in
  pci_uio_map_resource().
- When pci_map_resource() is failed but path is allocated correctly,
  path and fds won't be freed in pci_uio_map_recource().
  Also, some mapped resources should be freed.
- When pci_uio_unmap() is called, path should be freed.

Also, fixes below.
- When pci_map_resource() is failed, mapaddr will be MAP_FAILED.
  In this case, pci_map_addr should not be incremented in
  pci_uio_map_resource().
- To shrink code, move close().
- Remove fail variable.

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
Acked-by: Bernard Iremonger <bernard.iremonger@intel.com>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c       | 18 ++++++---
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 63 ++++++++++++++++++++-----------
 2 files changed, 53 insertions(+), 28 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index a63d450..da17685 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -202,7 +202,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	uint64_t offset;
 	uint64_t pagesz;
 	struct rte_pci_addr *loc = &dev->addr;
-	struct uio_resource *uio_res;
+	struct uio_resource *uio_res = NULL;
 	struct uio_res_list *uio_res_list =
 			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
 	struct uio_map *maps;
@@ -228,7 +228,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	if (dev->intr_handle.fd < 0) {
 		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
 			devname, strerror(errno));
-		return -1;
+		goto error;
 	}
 	dev->intr_handle.type = RTE_INTR_HANDLE_UIO;
 
@@ -236,7 +236,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) == NULL) {
 		RTE_LOG(ERR, EAL,
 			"%s(): cannot store uio mmap details\n", __func__);
-		return -1;
+		goto error;
 	}
 
 	snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
@@ -263,8 +263,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 		    (mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
 						(size_t)maps[j].size)
 		    ) == NULL) {
-			rte_free(uio_res);
-			return -1;
+			goto error;
 		}
 
 		maps[j].addr = mapaddr;
@@ -275,6 +274,15 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
 
 	return 0;
+
+error:
+	rte_free(uio_res);
+	if (dev->intr_handle.fd >= 0) {
+		close(dev->intr_handle.fd);
+		dev->intr_handle.fd = -1;
+		dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+	}
+	return -1;
 }
 
 /* Scan one pci sysfs entry, and fill the devices list from it. */
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 37dc936..838b851 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -265,7 +265,7 @@ pci_get_uio_dev(struct rte_pci_device *dev, char *dstbuf,
 int
 pci_uio_map_resource(struct rte_pci_device *dev)
 {
-	int i, map_idx;
+	int i, map_idx = 0;
 	char dirname[PATH_MAX];
 	char cfgname[PATH_MAX];
 	char devname[PATH_MAX]; /* contains the /dev/uioX */
@@ -273,7 +273,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	int uio_num;
 	uint64_t phaddr;
 	struct rte_pci_addr *loc = &dev->addr;
-	struct mapped_pci_resource *uio_res;
+	struct mapped_pci_resource *uio_res = NULL;
 	struct mapped_pci_res_list *uio_res_list =
 			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 	struct pci_map *maps;
@@ -300,7 +300,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	if (dev->intr_handle.fd < 0) {
 		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
 			devname, strerror(errno));
-		return -1;
+		goto error;
 	}
 
 	snprintf(cfgname, sizeof(cfgname),
@@ -309,7 +309,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	if (dev->intr_handle.uio_cfg_fd < 0) {
 		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
 			cfgname, strerror(errno));
-		return -1;
+		goto error;
 	}
 
 	if (dev->kdrv == RTE_KDRV_IGB_UIO)
@@ -320,7 +320,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 		/* set bus master that is not done by uio_pci_generic */
 		if (pci_uio_set_bus_master(dev->intr_handle.uio_cfg_fd)) {
 			RTE_LOG(ERR, EAL, "Cannot set up bus mastering!\n");
-			return -1;
+			goto error;
 		}
 	}
 
@@ -329,7 +329,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	if (uio_res == NULL) {
 		RTE_LOG(ERR, EAL,
 			"%s(): cannot store uio mmap details\n", __func__);
-		return -1;
+		goto error;
 	}
 
 	snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
@@ -337,9 +337,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 	/* Map all BARs */
 	maps = uio_res->maps;
-	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
+	for (i = 0; i != PCI_MAX_RESOURCE; i++) {
 		int fd;
-		int fail = 0;
 
 		/* skip empty BAR */
 		phaddr = dev->mem_resource[i].phys_addr;
@@ -353,6 +352,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 				loc->domain, loc->bus, loc->devid, loc->function,
 				i);
 
+		/* allocate memory to keep path */
+		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
+		if (maps[map_idx].path == NULL)
+			goto error;
+
 		/*
 		 * open resource file, to mmap it
 		 */
@@ -360,7 +364,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 		if (fd < 0) {
 			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
 					devname, strerror(errno));
-			return -1;
+			rte_free(maps[map_idx].path);
+			goto error;
 		}
 
 		/* try mapping somewhere close to the end of hugepages */
@@ -369,23 +374,15 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 		mapaddr = pci_map_resource(pci_map_addr, fd, 0,
 				(size_t)dev->mem_resource[i].len, 0);
-		if (mapaddr == MAP_FAILED)
-			fail = 1;
+		close(fd);
+		if (mapaddr == MAP_FAILED) {
+			rte_free(maps[map_idx].path);
+			goto error;
+		}
 
 		pci_map_addr = RTE_PTR_ADD(mapaddr,
 				(size_t)dev->mem_resource[i].len);
 
-		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
-		if (maps[map_idx].path == NULL)
-			fail = 1;
-
-		if (fail) {
-			rte_free(uio_res);
-			close(fd);
-			return -1;
-		}
-		close(fd);
-
 		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
 		maps[map_idx].size = dev->mem_resource[i].len;
 		maps[map_idx].addr = mapaddr;
@@ -400,6 +397,24 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
 
 	return 0;
+
+error:
+	for (i = 0; i < map_idx; i++) {
+		pci_unmap_resource(uio_res->maps[i].addr,
+				(size_t)uio_res->maps[i].size);
+		rte_free(maps[i].path);
+	}
+	rte_free(uio_res);
+	if (dev->intr_handle.uio_cfg_fd >= 0) {
+		close(dev->intr_handle.uio_cfg_fd);
+		dev->intr_handle.uio_cfg_fd = -1;
+	}
+	if (dev->intr_handle.fd >= 0) {
+		close(dev->intr_handle.fd);
+		dev->intr_handle.fd = -1;
+		dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+	}
+	return -1;
 }
 
 #ifdef RTE_LIBRTE_EAL_HOTPLUG
@@ -411,9 +426,11 @@ pci_uio_unmap(struct mapped_pci_resource *uio_res)
 	if (uio_res == NULL)
 		return;
 
-	for (i = 0; i != uio_res->nb_maps; i++)
+	for (i = 0; i != uio_res->nb_maps; i++) {
 		pci_unmap_resource(uio_res->maps[i].addr,
 				(size_t)uio_res->maps[i].size);
+		rte_free(uio_res->maps[i].path);
+	}
 }
 
 static struct mapped_pci_resource *
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v9 04/12] eal/bsdapp: Change names of pci related data structure
  2015-07-08 10:34               ` [dpdk-dev] [PATCH v9 00/12] Clean up pci uio implementations Tetsuya Mukawa
                                   ` (2 preceding siblings ...)
  2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 03/12] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
@ 2015-07-08 10:34                 ` Tetsuya Mukawa
  2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 05/12] eal: Fix uio mapping differences between linuxapp and bsdapp Tetsuya Mukawa
                                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-08 10:34 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

To merge pci code of linuxapp and bsdapp, this patch changes names
like below.
 - uio_map to pci_map
 - uio_resource to mapped_pci_resource
 - uio_res_list to mapped_pci_res_list

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
Acked-by: Bernard Iremonger <bernard.iremonger@intel.com>
Acked-by: David Marchand <david.marchand@6wind.com>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index da17685..aeaedec 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -84,7 +84,7 @@
  * enabling bus master.
  */
 
-struct uio_map {
+struct pci_map {
 	void *addr;
 	uint64_t offset;
 	uint64_t size;
@@ -95,16 +95,16 @@ struct uio_map {
  * For multi-process we need to reproduce all PCI mappings in secondary
  * processes, so save them in a tailq.
  */
-struct uio_resource {
-	TAILQ_ENTRY(uio_resource) next;
+struct mapped_pci_resource {
+	TAILQ_ENTRY(mapped_pci_resource) next;
 
 	struct rte_pci_addr pci_addr;
 	char path[PATH_MAX];
 	size_t nb_maps;
-	struct uio_map maps[PCI_MAX_RESOURCE];
+	struct pci_map maps[PCI_MAX_RESOURCE];
 };
 
-TAILQ_HEAD(uio_res_list, uio_resource);
+TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource);
 
 static struct rte_tailq_elem rte_uio_tailq = {
 	.name = "UIO_RESOURCE_LIST",
@@ -163,9 +163,9 @@ static int
 pci_uio_map_secondary(struct rte_pci_device *dev)
 {
 	size_t i;
-	struct uio_resource *uio_res;
-	struct uio_res_list *uio_res_list =
-			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
+	struct mapped_pci_resource *uio_res;
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 
 	TAILQ_FOREACH(uio_res, uio_res_list, next) {
 
@@ -202,10 +202,10 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	uint64_t offset;
 	uint64_t pagesz;
 	struct rte_pci_addr *loc = &dev->addr;
-	struct uio_resource *uio_res = NULL;
-	struct uio_res_list *uio_res_list =
-			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
-	struct uio_map *maps;
+	struct mapped_pci_resource *uio_res = NULL;
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct pci_map *maps;
 
 	dev->intr_handle.fd = -1;
 	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v9 05/12] eal: Fix uio mapping differences between linuxapp and bsdapp
  2015-07-08 10:34               ` [dpdk-dev] [PATCH v9 00/12] Clean up pci uio implementations Tetsuya Mukawa
                                   ` (3 preceding siblings ...)
  2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 04/12] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
@ 2015-07-08 10:34                 ` Tetsuya Mukawa
  2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 06/12] eal: Add pci_uio_alloc/free_resource() Tetsuya Mukawa
                                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-08 10:34 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

This patch fixes below.
- bsdapp
 - Use map_id in pci_uio_map_resource().
 - Fix interface of pci_map_resource().
 - Move path variable of mapped_pci_resource structure to pci_map.
- linuxapp
 - Remove redundant error message of linuxapp.

'pci_uio_map_resource()' is implemented in both linuxapp and bsdapp,
but interface is different. The patch fixes the function of bsdapp
to do same as linuxapp. After applying it, file descriptor should be
opened and closed out of pci_map_resource().

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
Acked-by: Bernard Iremonger <bernard.iremonger@intel.com>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c       | 117 ++++++++++++++++++------------
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c |  27 +++----
 2 files changed, 80 insertions(+), 64 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index aeaedec..fba67df 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -86,6 +86,7 @@
 
 struct pci_map {
 	void *addr;
+	char *path;
 	uint64_t offset;
 	uint64_t size;
 	uint64_t phaddr;
@@ -100,7 +101,7 @@ struct mapped_pci_resource {
 
 	struct rte_pci_addr pci_addr;
 	char path[PATH_MAX];
-	size_t nb_maps;
+	int nb_maps;
 	struct pci_map maps[PCI_MAX_RESOURCE];
 };
 
@@ -122,47 +123,30 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)
 
 /* map a particular resource from a file */
 static void *
-pci_map_resource(void *requested_addr, const char *devname, off_t offset,
-		 size_t size)
+pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
+		 int additional_flags)
 {
-	int fd;
 	void *mapaddr;
 
-	/*
-	 * open devname, to mmap it
-	 */
-	fd = open(devname, O_RDWR);
-	if (fd < 0) {
-		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
-			devname, strerror(errno));
-		goto fail;
-	}
-
 	/* Map the PCI memory resource of device */
 	mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
-			MAP_SHARED, fd, offset);
-	close(fd);
-	if (mapaddr == MAP_FAILED ||
-			(requested_addr != NULL && mapaddr != requested_addr)) {
-		RTE_LOG(ERR, EAL, "%s(): cannot mmap(%s(%d), %p, 0x%lx, 0x%lx):"
-			" %s (%p)\n", __func__, devname, fd, requested_addr,
+			MAP_SHARED | additional_flags, fd, offset);
+	if (mapaddr == MAP_FAILED) {
+		RTE_LOG(ERR, EAL,
+			"%s(): cannot mmap(%d, %p, 0x%lx, 0x%lx): %s (%p)\n",
+			__func__, fd, requested_addr,
 			(unsigned long)size, (unsigned long)offset,
 			strerror(errno), mapaddr);
-		goto fail;
-	}
-
-	RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
+	} else
+		RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
 
 	return mapaddr;
-
-fail:
-	return NULL;
 }
 
 static int
 pci_uio_map_secondary(struct rte_pci_device *dev)
 {
-	size_t i;
+	int i, fd;
 	struct mapped_pci_resource *uio_res;
 	struct mapped_pci_res_list *uio_res_list =
 			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
@@ -170,17 +154,30 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 	TAILQ_FOREACH(uio_res, uio_res_list, next) {
 
 		/* skip this element if it doesn't match our PCI address */
-		if (memcmp(&uio_res->pci_addr, &dev->addr, sizeof(dev->addr)))
+		if (rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr))
 			continue;
 
 		for (i = 0; i != uio_res->nb_maps; i++) {
-			if (pci_map_resource(uio_res->maps[i].addr,
-					     uio_res->path,
-					     (off_t)uio_res->maps[i].offset,
-					     (size_t)uio_res->maps[i].size)
-			    != uio_res->maps[i].addr) {
+			/*
+			 * open devname, to mmap it
+			 */
+			fd = open(uio_res->maps[i].path, O_RDWR);
+			if (fd < 0) {
+				RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
+					uio_res->maps[i].path, strerror(errno));
+				return -1;
+			}
+
+			void *mapaddr = pci_map_resource(uio_res->maps[i].addr,
+					fd, (off_t)uio_res->maps[i].offset,
+					(size_t)uio_res->maps[i].size, 0);
+			/* fd is not needed in slave process, close it */
+			close(fd);
+			if (mapaddr != uio_res->maps[i].addr) {
 				RTE_LOG(ERR, EAL,
-					"Cannot mmap device resource\n");
+					"Cannot mmap device resource file %s to address: %p\n",
+					uio_res->maps[i].path,
+					uio_res->maps[i].addr);
 				return -1;
 			}
 		}
@@ -195,7 +192,7 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 static int
 pci_uio_map_resource(struct rte_pci_device *dev)
 {
-	int i, j;
+	int i, map_idx = 0;
 	char devname[PATH_MAX]; /* contains the /dev/uioX */
 	void *mapaddr;
 	uint64_t phaddr;
@@ -247,35 +244,59 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	pagesz = sysconf(_SC_PAGESIZE);
 
 	maps = uio_res->maps;
-	for (i = uio_res->nb_maps = 0; i != PCI_MAX_RESOURCE; i++) {
+	for (i = 0; i != PCI_MAX_RESOURCE; i++) {
+		int fd;
 
-		j = uio_res->nb_maps;
 		/* skip empty BAR */
 		if ((phaddr = dev->mem_resource[i].phys_addr) == 0)
 			continue;
 
+		/* allocate memory to keep path */
+		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
+		if (maps[map_idx].path == NULL) {
+			RTE_LOG(ERR, EAL, "Cannot allocate memory for path: %s\n",
+					strerror(errno));
+			goto error;
+		}
+
+		/*
+		 * open resource file, to mmap it
+		 */
+		fd = open(devname, O_RDWR);
+		if (fd < 0) {
+			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
+					devname, strerror(errno));
+			rte_free(maps[map_idx].path);
+			goto error;
+		}
+
 		/* if matching map is found, then use it */
 		offset = i * pagesz;
-		maps[j].offset = offset;
-		maps[j].phaddr = dev->mem_resource[i].phys_addr;
-		maps[j].size = dev->mem_resource[i].len;
-		if (maps[j].addr != NULL ||
-		    (mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
-						(size_t)maps[j].size)
-		    ) == NULL) {
+		mapaddr = pci_map_resource(NULL, fd, (off_t)offset,
+					(size_t)dev->mem_resource[i].len, 0);
+		close(fd);
+		if (mapaddr == MAP_FAILED) {
+			rte_free(maps[map_idx].path);
 			goto error;
 		}
 
-		maps[j].addr = mapaddr;
-		uio_res->nb_maps++;
+		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
+		maps[map_idx].size = dev->mem_resource[i].len;
+		maps[map_idx].addr = mapaddr;
+		maps[map_idx].offset = offset;
+		strcpy(maps[map_idx].path, devname);
+		map_idx++;
 		dev->mem_resource[i].addr = mapaddr;
 	}
 
+	uio_res->nb_maps = map_idx;
+
 	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
 
 	return 0;
-
 error:
+	for (i = 0; i < map_idx; i++)
+		rte_free(maps[i].path);
 	rte_free(uio_res);
 	if (dev->intr_handle.fd >= 0) {
 		close(dev->intr_handle.fd);
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 838b851..f4e5dd1 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -116,23 +116,15 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 			void *mapaddr = pci_map_resource(uio_res->maps[i].addr,
 					fd, (off_t)uio_res->maps[i].offset,
 					(size_t)uio_res->maps[i].size, 0);
-			if (mapaddr != uio_res->maps[i].addr) {
-				if (mapaddr == MAP_FAILED)
-					RTE_LOG(ERR, EAL,
-							"Cannot mmap device resource file %s: %s\n",
-							uio_res->maps[i].path,
-							strerror(errno));
-				else
-					RTE_LOG(ERR, EAL,
-							"Cannot mmap device resource file %s to address: %p\n",
-							uio_res->maps[i].path,
-							uio_res->maps[i].addr);
-
-				close(fd);
-				return -1;
-			}
 			/* fd is not needed in slave process, close it */
 			close(fd);
+			if (mapaddr != uio_res->maps[i].addr) {
+				RTE_LOG(ERR, EAL,
+					"Cannot mmap device resource file %s to address: %p\n",
+					uio_res->maps[i].path,
+					uio_res->maps[i].addr);
+				return -1;
+			}
 		}
 		return 0;
 	}
@@ -354,8 +346,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 		/* allocate memory to keep path */
 		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
-		if (maps[map_idx].path == NULL)
+		if (maps[map_idx].path == NULL) {
+			RTE_LOG(ERR, EAL, "Cannot allocate memory for path: %s\n",
+					strerror(errno));
 			goto error;
+		}
 
 		/*
 		 * open resource file, to mmap it
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v9 06/12] eal: Add pci_uio_alloc/free_resource()
  2015-07-08 10:34               ` [dpdk-dev] [PATCH v9 00/12] Clean up pci uio implementations Tetsuya Mukawa
                                   ` (4 preceding siblings ...)
  2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 05/12] eal: Fix uio mapping differences between linuxapp and bsdapp Tetsuya Mukawa
@ 2015-07-08 10:34                 ` Tetsuya Mukawa
  2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 07/12] eal: Add pci_uio_map_resource_by_index() Tetsuya Mukawa
                                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-08 10:34 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

This patch adds new functions called pci_uio_alloc_resource() and
pci_uio_free_resource().
The functions hides how to prepare or free uio resource in linuxapp
and bsdapp. With the function, pci_uio_map_resource() will be more
abstracted.

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c       | 83 ++++++++++++++++++---------
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 93 ++++++++++++++++++++-----------
 2 files changed, 117 insertions(+), 59 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index fba67df..b4a2631 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -188,28 +188,27 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 	return 1;
 }
 
-/* map the PCI resource of a PCI device in virtual memory */
+static void
+pci_uio_free_resource(struct rte_pci_device *dev,
+		struct mapped_pci_resource *uio_res)
+{
+	rte_free(uio_res);
+
+	if (dev->intr_handle.fd) {
+		close(dev->intr_handle.fd);
+		dev->intr_handle.fd = -1;
+		dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+	}
+}
+
 static int
-pci_uio_map_resource(struct rte_pci_device *dev)
+pci_uio_alloc_resource(struct rte_pci_device *dev,
+		struct mapped_pci_resource **uio_res)
 {
-	int i, map_idx = 0;
 	char devname[PATH_MAX]; /* contains the /dev/uioX */
-	void *mapaddr;
-	uint64_t phaddr;
-	uint64_t offset;
-	uint64_t pagesz;
-	struct rte_pci_addr *loc = &dev->addr;
-	struct mapped_pci_resource *uio_res = NULL;
-	struct mapped_pci_res_list *uio_res_list =
-			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
-	struct pci_map *maps;
+	struct rte_pci_addr *loc;
 
-	dev->intr_handle.fd = -1;
-	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
-
-	/* secondary processes - use already recorded details */
-	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
-		return pci_uio_map_secondary(dev);
+	loc = &dev->addr;
 
 	snprintf(devname, sizeof(devname), "/dev/uio@pci:%u:%u:%u",
 			dev->addr.bus, dev->addr.devid, dev->addr.function);
@@ -230,18 +229,53 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	dev->intr_handle.type = RTE_INTR_HANDLE_UIO;
 
 	/* allocate the mapping details for secondary processes*/
-	if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) == NULL) {
+	*uio_res = rte_zmalloc("UIO_RES", sizeof(**uio_res), 0);
+	if (*uio_res == NULL) {
 		RTE_LOG(ERR, EAL,
 			"%s(): cannot store uio mmap details\n", __func__);
 		goto error;
 	}
 
-	snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
-	memcpy(&uio_res->pci_addr, &dev->addr, sizeof(uio_res->pci_addr));
+	snprintf((*uio_res)->path, sizeof((*uio_res)->path), "%s", devname);
+	memcpy(&(*uio_res)->pci_addr, &dev->addr, sizeof((*uio_res)->pci_addr));
 
+	return 0;
+
+error:
+	pci_uio_free_resource(dev, *uio_res);
+	return -1;
+}
+
+/* map the PCI resource of a PCI device in virtual memory */
+static int
+pci_uio_map_resource(struct rte_pci_device *dev)
+{
+	int i, map_idx = 0, ret;
+	char *devname;
+	void *mapaddr;
+	uint64_t phaddr;
+	uint64_t offset;
+	uint64_t pagesz;
+	struct mapped_pci_resource *uio_res = NULL;
+	struct mapped_pci_res_list *uio_res_list =
+		RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct pci_map *maps;
+
+	dev->intr_handle.fd = -1;
+	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+
+	/* secondary processes - use already recorded details */
+	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+		return pci_uio_map_secondary(dev);
+
+	/* allocate uio resource */
+	ret = pci_uio_alloc_resource(dev, &uio_res);
+	if (ret)
+		return ret;
 
 	/* Map all BARs */
 	pagesz = sysconf(_SC_PAGESIZE);
+	devname = uio_res->path;
 
 	maps = uio_res->maps;
 	for (i = 0; i != PCI_MAX_RESOURCE; i++) {
@@ -297,12 +331,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 error:
 	for (i = 0; i < map_idx; i++)
 		rte_free(maps[i].path);
-	rte_free(uio_res);
-	if (dev->intr_handle.fd >= 0) {
-		close(dev->intr_handle.fd);
-		dev->intr_handle.fd = -1;
-		dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
-	}
+	pci_uio_free_resource(dev, uio_res);
 	return -1;
 }
 
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index f4e5dd1..986f431 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -253,30 +253,34 @@ pci_get_uio_dev(struct rte_pci_device *dev, char *dstbuf,
 	return uio_num;
 }
 
-/* map the PCI resource of a PCI device in virtual memory */
-int
-pci_uio_map_resource(struct rte_pci_device *dev)
+static void
+pci_uio_free_resource(struct rte_pci_device *dev,
+		struct mapped_pci_resource *uio_res)
+{
+	rte_free(uio_res);
+
+	if (dev->intr_handle.uio_cfg_fd >= 0) {
+		close(dev->intr_handle.uio_cfg_fd);
+		dev->intr_handle.uio_cfg_fd = -1;
+	}
+	if (dev->intr_handle.fd) {
+		close(dev->intr_handle.fd);
+		dev->intr_handle.fd = -1;
+		dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+	}
+}
+
+static int
+pci_uio_alloc_resource(struct rte_pci_device *dev,
+		struct mapped_pci_resource **uio_res)
 {
-	int i, map_idx = 0;
 	char dirname[PATH_MAX];
 	char cfgname[PATH_MAX];
 	char devname[PATH_MAX]; /* contains the /dev/uioX */
-	void *mapaddr;
 	int uio_num;
-	uint64_t phaddr;
-	struct rte_pci_addr *loc = &dev->addr;
-	struct mapped_pci_resource *uio_res = NULL;
-	struct mapped_pci_res_list *uio_res_list =
-			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
-	struct pci_map *maps;
+	struct rte_pci_addr *loc;
 
-	dev->intr_handle.fd = -1;
-	dev->intr_handle.uio_cfg_fd = -1;
-	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
-
-	/* secondary processes - use already recorded details */
-	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
-		return pci_uio_map_secondary(dev);
+	loc = &dev->addr;
 
 	/* find uio resource */
 	uio_num = pci_get_uio_dev(dev, dirname, sizeof(dirname));
@@ -317,15 +321,49 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	}
 
 	/* allocate the mapping details for secondary processes*/
-	uio_res = rte_zmalloc("UIO_RES", sizeof(*uio_res), 0);
-	if (uio_res == NULL) {
+	*uio_res = rte_zmalloc("UIO_RES", sizeof(**uio_res), 0);
+	if (*uio_res == NULL) {
 		RTE_LOG(ERR, EAL,
 			"%s(): cannot store uio mmap details\n", __func__);
 		goto error;
 	}
 
-	snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
-	memcpy(&uio_res->pci_addr, &dev->addr, sizeof(uio_res->pci_addr));
+	snprintf((*uio_res)->path, sizeof((*uio_res)->path), "%s", devname);
+	memcpy(&(*uio_res)->pci_addr, &dev->addr, sizeof((*uio_res)->pci_addr));
+
+	return 0;
+
+error:
+	pci_uio_free_resource(dev, *uio_res);
+	return -1;
+}
+
+/* map the PCI resource of a PCI device in virtual memory */
+int
+pci_uio_map_resource(struct rte_pci_device *dev)
+{
+	int i, map_idx = 0, ret;
+	char devname[PATH_MAX]; /* contains the /dev/uioX */
+	void *mapaddr;
+	uint64_t phaddr;
+	struct rte_pci_addr *loc = &dev->addr;
+	struct mapped_pci_resource *uio_res = NULL;
+	struct mapped_pci_res_list *uio_res_list =
+		RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct pci_map *maps;
+
+	dev->intr_handle.fd = -1;
+	dev->intr_handle.uio_cfg_fd = -1;
+	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+
+	/* secondary processes - use already recorded details */
+	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+		return pci_uio_map_secondary(dev);
+
+	/* allocate uio resource */
+	ret = pci_uio_alloc_resource(dev, &uio_res);
+	if (ret)
+		return ret;
 
 	/* Map all BARs */
 	maps = uio_res->maps;
@@ -399,16 +437,7 @@ error:
 				(size_t)uio_res->maps[i].size);
 		rte_free(maps[i].path);
 	}
-	rte_free(uio_res);
-	if (dev->intr_handle.uio_cfg_fd >= 0) {
-		close(dev->intr_handle.uio_cfg_fd);
-		dev->intr_handle.uio_cfg_fd = -1;
-	}
-	if (dev->intr_handle.fd >= 0) {
-		close(dev->intr_handle.fd);
-		dev->intr_handle.fd = -1;
-		dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
-	}
+	pci_uio_free_resource(dev, uio_res);
 	return -1;
 }
 
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v9 07/12] eal: Add pci_uio_map_resource_by_index()
  2015-07-08 10:34               ` [dpdk-dev] [PATCH v9 00/12] Clean up pci uio implementations Tetsuya Mukawa
                                   ` (5 preceding siblings ...)
  2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 06/12] eal: Add pci_uio_alloc/free_resource() Tetsuya Mukawa
@ 2015-07-08 10:34                 ` Tetsuya Mukawa
  2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 08/12] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp Tetsuya Mukawa
                                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-08 10:34 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

This patch adds a new function called pci_uio_map_resource_by_index().
The function hides how to map uio resource in linuxapp and bsdapp.
With the function, pci_uio_map_resource() will be more abstracted.

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c       | 104 ++++++++++++++-----------
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 121 +++++++++++++++++-------------
 2 files changed, 127 insertions(+), 98 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index b4a2631..1dfcb82 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -246,20 +246,70 @@ error:
 	return -1;
 }
 
+static int
+pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
+		struct mapped_pci_resource *uio_res, int map_idx)
+{
+	int fd;
+	char *devname;
+	void *mapaddr;
+	uint64_t offset;
+	uint64_t pagesz;
+	struct pci_map *maps;
+
+	maps = uio_res->maps;
+	devname = uio_res->path;
+	pagesz = sysconf(_SC_PAGESIZE);
+
+	/* allocate memory to keep path */
+	maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
+	if (maps[map_idx].path == NULL) {
+		RTE_LOG(ERR, EAL, "Cannot allocate memory for path: %s\n",
+				strerror(errno));
+		return -1;
+	}
+
+	/*
+	 * open resource file, to mmap it
+	 */
+	fd = open(devname, O_RDWR);
+	if (fd < 0) {
+		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
+				devname, strerror(errno));
+		goto error;
+	}
+
+	/* if matching map is found, then use it */
+	offset = res_idx * pagesz;
+	mapaddr = pci_map_resource(NULL, fd, (off_t)offset,
+			(size_t)dev->mem_resource[res_idx].len, 0);
+	close(fd);
+	if (mapaddr == MAP_FAILED)
+		goto error;
+
+	maps[map_idx].phaddr = dev->mem_resource[res_idx].phys_addr;
+	maps[map_idx].size = dev->mem_resource[res_idx].len;
+	maps[map_idx].addr = mapaddr;
+	maps[map_idx].offset = offset;
+	strcpy(maps[map_idx].path, devname);
+	dev->mem_resource[res_idx].addr = mapaddr;
+
+	return 0;
+
+error:
+	rte_free(maps[map_idx].path);
+	return -1;
+}
+
 /* map the PCI resource of a PCI device in virtual memory */
 static int
 pci_uio_map_resource(struct rte_pci_device *dev)
 {
 	int i, map_idx = 0, ret;
-	char *devname;
-	void *mapaddr;
 	uint64_t phaddr;
-	uint64_t offset;
-	uint64_t pagesz;
 	struct mapped_pci_resource *uio_res = NULL;
 	struct mapped_pci_res_list *uio_res_list =
 		RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
-	struct pci_map *maps;
 
 	dev->intr_handle.fd = -1;
 	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
@@ -274,53 +324,17 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 		return ret;
 
 	/* Map all BARs */
-	pagesz = sysconf(_SC_PAGESIZE);
-	devname = uio_res->path;
-
-	maps = uio_res->maps;
 	for (i = 0; i != PCI_MAX_RESOURCE; i++) {
-		int fd;
-
 		/* skip empty BAR */
 		if ((phaddr = dev->mem_resource[i].phys_addr) == 0)
 			continue;
 
-		/* allocate memory to keep path */
-		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
-		if (maps[map_idx].path == NULL) {
-			RTE_LOG(ERR, EAL, "Cannot allocate memory for path: %s\n",
-					strerror(errno));
+		ret = pci_uio_map_resource_by_index(dev, i,
+				uio_res, map_idx);
+		if (ret)
 			goto error;
-		}
 
-		/*
-		 * open resource file, to mmap it
-		 */
-		fd = open(devname, O_RDWR);
-		if (fd < 0) {
-			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
-					devname, strerror(errno));
-			rte_free(maps[map_idx].path);
-			goto error;
-		}
-
-		/* if matching map is found, then use it */
-		offset = i * pagesz;
-		mapaddr = pci_map_resource(NULL, fd, (off_t)offset,
-					(size_t)dev->mem_resource[i].len, 0);
-		close(fd);
-		if (mapaddr == MAP_FAILED) {
-			rte_free(maps[map_idx].path);
-			goto error;
-		}
-
-		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
-		maps[map_idx].size = dev->mem_resource[i].len;
-		maps[map_idx].addr = mapaddr;
-		maps[map_idx].offset = offset;
-		strcpy(maps[map_idx].path, devname);
 		map_idx++;
-		dev->mem_resource[i].addr = mapaddr;
 	}
 
 	uio_res->nb_maps = map_idx;
@@ -330,7 +344,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	return 0;
 error:
 	for (i = 0; i < map_idx; i++)
-		rte_free(maps[i].path);
+		rte_free(uio_res->maps[i].path);
 	pci_uio_free_resource(dev, uio_res);
 	return -1;
 }
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 986f431..3f5520f 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -338,19 +338,79 @@ error:
 	return -1;
 }
 
+static int
+pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
+		struct mapped_pci_resource *uio_res, int map_idx)
+{
+	int fd;
+	char devname[PATH_MAX]; /* contains the /dev/uioX */
+	void *mapaddr;
+	struct rte_pci_addr *loc;
+	struct pci_map *maps;
+
+	loc = &dev->addr;
+	maps = uio_res->maps;
+
+	/* update devname for mmap  */
+	snprintf(devname, sizeof(devname),
+			SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/resource%d",
+			loc->domain, loc->bus, loc->devid,
+			loc->function, res_idx);
+
+	/* allocate memory to keep path */
+	maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
+	if (maps[map_idx].path == NULL) {
+		RTE_LOG(ERR, EAL, "Cannot allocate memory for path: %s\n",
+				strerror(errno));
+		return -1;
+	}
+
+	/*
+	 * open resource file, to mmap it
+	 */
+	fd = open(devname, O_RDWR);
+	if (fd < 0) {
+		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
+				devname, strerror(errno));
+		goto error;
+	}
+
+	/* try mapping somewhere close to the end of hugepages */
+	if (pci_map_addr == NULL)
+		pci_map_addr = pci_find_max_end_va();
+
+	mapaddr = pci_map_resource(pci_map_addr, fd, 0,
+			(size_t)dev->mem_resource[res_idx].len, 0);
+	close(fd);
+	if (mapaddr == MAP_FAILED)
+		goto error;
+
+	pci_map_addr = RTE_PTR_ADD(mapaddr,
+			(size_t)dev->mem_resource[res_idx].len);
+
+	maps[map_idx].phaddr = dev->mem_resource[res_idx].phys_addr;
+	maps[map_idx].size = dev->mem_resource[res_idx].len;
+	maps[map_idx].addr = mapaddr;
+	maps[map_idx].offset = 0;
+	strcpy(maps[map_idx].path, devname);
+	dev->mem_resource[res_idx].addr = mapaddr;
+
+	return 0;
+
+error:
+	rte_free(maps[map_idx].path);
+	return -1;
+}
+
 /* map the PCI resource of a PCI device in virtual memory */
 int
 pci_uio_map_resource(struct rte_pci_device *dev)
 {
 	int i, map_idx = 0, ret;
-	char devname[PATH_MAX]; /* contains the /dev/uioX */
-	void *mapaddr;
 	uint64_t phaddr;
-	struct rte_pci_addr *loc = &dev->addr;
 	struct mapped_pci_resource *uio_res = NULL;
 	struct mapped_pci_res_list *uio_res_list =
 		RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
-	struct pci_map *maps;
 
 	dev->intr_handle.fd = -1;
 	dev->intr_handle.uio_cfg_fd = -1;
@@ -366,63 +426,18 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 		return ret;
 
 	/* Map all BARs */
-	maps = uio_res->maps;
 	for (i = 0; i != PCI_MAX_RESOURCE; i++) {
-		int fd;
-
 		/* skip empty BAR */
 		phaddr = dev->mem_resource[i].phys_addr;
 		if (phaddr == 0)
 			continue;
 
-
-		/* update devname for mmap  */
-		snprintf(devname, sizeof(devname),
-				SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/resource%d",
-				loc->domain, loc->bus, loc->devid, loc->function,
-				i);
-
-		/* allocate memory to keep path */
-		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
-		if (maps[map_idx].path == NULL) {
-			RTE_LOG(ERR, EAL, "Cannot allocate memory for path: %s\n",
-					strerror(errno));
-			goto error;
-		}
-
-		/*
-		 * open resource file, to mmap it
-		 */
-		fd = open(devname, O_RDWR);
-		if (fd < 0) {
-			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
-					devname, strerror(errno));
-			rte_free(maps[map_idx].path);
+		ret = pci_uio_map_resource_by_index(dev, i,
+				uio_res, map_idx);
+		if (ret)
 			goto error;
-		}
-
-		/* try mapping somewhere close to the end of hugepages */
-		if (pci_map_addr == NULL)
-			pci_map_addr = pci_find_max_end_va();
-
-		mapaddr = pci_map_resource(pci_map_addr, fd, 0,
-				(size_t)dev->mem_resource[i].len, 0);
-		close(fd);
-		if (mapaddr == MAP_FAILED) {
-			rte_free(maps[map_idx].path);
-			goto error;
-		}
-
-		pci_map_addr = RTE_PTR_ADD(mapaddr,
-				(size_t)dev->mem_resource[i].len);
 
-		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
-		maps[map_idx].size = dev->mem_resource[i].len;
-		maps[map_idx].addr = mapaddr;
-		maps[map_idx].offset = 0;
-		strcpy(maps[map_idx].path, devname);
 		map_idx++;
-		dev->mem_resource[i].addr = mapaddr;
 	}
 
 	uio_res->nb_maps = map_idx;
@@ -435,7 +450,7 @@ error:
 	for (i = 0; i < map_idx; i++) {
 		pci_unmap_resource(uio_res->maps[i].addr,
 				(size_t)uio_res->maps[i].size);
-		rte_free(maps[i].path);
+		rte_free(uio_res->maps[i].path);
 	}
 	pci_uio_free_resource(dev, uio_res);
 	return -1;
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v9 08/12] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp
  2015-07-08 10:34               ` [dpdk-dev] [PATCH v9 00/12] Clean up pci uio implementations Tetsuya Mukawa
                                   ` (6 preceding siblings ...)
  2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 07/12] eal: Add pci_uio_map_resource_by_index() Tetsuya Mukawa
@ 2015-07-08 10:34                 ` Tetsuya Mukawa
  2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 09/12] eal: Consolidate pci_map/unmap_resource() " Tetsuya Mukawa
                                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-08 10:34 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

This patch consolidates below structures, and defines them in common code.
 - struct pci_map
 - strucy mapped_pci_resouces

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
Acked-by: Bernard Iremonger <bernard.iremonger@intel.com>
Acked-by: David Marchand <david.marchand@6wind.com>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c        | 24 ------------------------
 lib/librte_eal/common/include/rte_pci.h    | 29 +++++++++++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_pci_init.h | 23 -----------------------
 3 files changed, 29 insertions(+), 47 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 1dfcb82..83c8d0c 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -83,30 +83,6 @@
  * network card, only providing access to PCI BAR to applications, and
  * enabling bus master.
  */
-
-struct pci_map {
-	void *addr;
-	char *path;
-	uint64_t offset;
-	uint64_t size;
-	uint64_t phaddr;
-};
-
-/*
- * For multi-process we need to reproduce all PCI mappings in secondary
- * processes, so save them in a tailq.
- */
-struct mapped_pci_resource {
-	TAILQ_ENTRY(mapped_pci_resource) next;
-
-	struct rte_pci_addr pci_addr;
-	char path[PATH_MAX];
-	int nb_maps;
-	struct pci_map maps[PCI_MAX_RESOURCE];
-};
-
-TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource);
-
 static struct rte_tailq_elem rte_uio_tailq = {
 	.name = "UIO_RESOURCE_LIST",
 };
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index 7801fa0..d95747e 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -2,6 +2,7 @@
  *   BSD LICENSE
  *
  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2015 IGEL Co., Ltd.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -220,6 +221,34 @@ struct rte_pci_driver {
 /** Device driver supports detaching capability */
 #define RTE_PCI_DRV_DETACHABLE	0x0010
 
+/**
+ * A structure describing a PCI mapping.
+ */
+struct pci_map {
+	void *addr;
+	char *path;
+	uint64_t offset;
+	uint64_t size;
+	uint64_t phaddr;
+};
+
+/**
+ * A structure describing a mapped PCI resource.
+ * For multi-process we need to reproduce all PCI mappings in secondary
+ * processes, so save them in a tailq.
+ */
+struct mapped_pci_resource {
+	TAILQ_ENTRY(mapped_pci_resource) next;
+
+	struct rte_pci_addr pci_addr;
+	char path[PATH_MAX];
+	int nb_maps;
+	struct pci_map maps[PCI_MAX_RESOURCE];
+};
+
+/** mapped pci device list */
+TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource);
+
 /**< Internal use only - Macro used by pci addr parsing functions **/
 #define GET_PCIADDR_FIELD(in, fd, lim, dlm)                   \
 do {                                                               \
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
index aa7b755..d9d1878 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
@@ -36,29 +36,6 @@
 
 #include "eal_vfio.h"
 
-struct pci_map {
-	void *addr;
-	char *path;
-	uint64_t offset;
-	uint64_t size;
-	uint64_t phaddr;
-};
-
-/*
- * For multi-process we need to reproduce all PCI mappings in secondary
- * processes, so save them in a tailq.
- */
-struct mapped_pci_resource {
-	TAILQ_ENTRY(mapped_pci_resource) next;
-
-	struct rte_pci_addr pci_addr;
-	char path[PATH_MAX];
-	int nb_maps;
-	struct pci_map maps[PCI_MAX_RESOURCE];
-};
-
-TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource);
-
 /*
  * Helper function to map PCI resources right after hugepages in virtual memory
  */
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v9 09/12] eal: Consolidate pci_map/unmap_resource() of linuxapp and bsdapp
  2015-07-08 10:34               ` [dpdk-dev] [PATCH v9 00/12] Clean up pci uio implementations Tetsuya Mukawa
                                   ` (7 preceding siblings ...)
  2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 08/12] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp Tetsuya Mukawa
@ 2015-07-08 10:34                 ` Tetsuya Mukawa
  2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 10/12] eal: Consolidate pci uio functions " Tetsuya Mukawa
                                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-08 10:34 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

The patch consolidates below functions, and implemented in common
eal code.
 - pci_map_resource()
 - pci_unmap_resource()

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
Acked-by: Bernard Iremonger <bernard.iremonger@intel.com>
Acked-by: David Marchand <david.marchand@6wind.com>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c        | 22 ----------------
 lib/librte_eal/common/eal_common_pci.c     | 40 +++++++++++++++++++++++++++++
 lib/librte_eal/common/include/rte_pci.h    | 32 +++++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_pci.c      | 41 ------------------------------
 lib/librte_eal/linuxapp/eal/eal_pci_init.h |  5 ----
 5 files changed, 72 insertions(+), 68 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 83c8d0c..16bda09 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -97,28 +97,6 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)
 	return -ENOTSUP;
 }
 
-/* map a particular resource from a file */
-static void *
-pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
-		 int additional_flags)
-{
-	void *mapaddr;
-
-	/* Map the PCI memory resource of device */
-	mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
-			MAP_SHARED | additional_flags, fd, offset);
-	if (mapaddr == MAP_FAILED) {
-		RTE_LOG(ERR, EAL,
-			"%s(): cannot mmap(%d, %p, 0x%lx, 0x%lx): %s (%p)\n",
-			__func__, fd, requested_addr,
-			(unsigned long)size, (unsigned long)offset,
-			strerror(errno), mapaddr);
-	} else
-		RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
-
-	return mapaddr;
-}
-
 static int
 pci_uio_map_secondary(struct rte_pci_device *dev)
 {
diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 4229aaf..eab147a 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -2,6 +2,7 @@
  *   BSD LICENSE
  *
  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2015 IGEL Co., Ltd.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -67,6 +68,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <sys/queue.h>
+#include <sys/mman.h>
 
 #include <rte_interrupts.h>
 #include <rte_log.h>
@@ -98,6 +100,44 @@ static struct rte_devargs *pci_devargs_lookup(struct rte_pci_device *dev)
 	return NULL;
 }
 
+/* map a particular resource from a file */
+void *
+pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
+		 int additional_flags)
+{
+	void *mapaddr;
+
+	/* Map the PCI memory resource of device */
+	mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
+			MAP_SHARED | additional_flags, fd, offset);
+	if (mapaddr == MAP_FAILED) {
+		RTE_LOG(ERR, EAL, "%s(): cannot mmap(%d, %p, 0x%lx, 0x%lx): %s (%p)\n",
+			__func__, fd, requested_addr,
+			(unsigned long)size, (unsigned long)offset,
+			strerror(errno), mapaddr);
+	} else
+		RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
+
+	return mapaddr;
+}
+
+/* unmap a particular resource */
+void
+pci_unmap_resource(void *requested_addr, size_t size)
+{
+	if (requested_addr == NULL)
+		return;
+
+	/* Unmap the PCI memory resource of device */
+	if (munmap(requested_addr, size)) {
+		RTE_LOG(ERR, EAL, "%s(): cannot munmap(%p, 0x%lx): %s\n",
+			__func__, requested_addr, (unsigned long)size,
+			strerror(errno));
+	} else
+		RTE_LOG(DEBUG, EAL, "  PCI memory unmapped at %p\n",
+				requested_addr);
+}
+
 /*
  * If vendor/device ID match, call the devinit() function of all
  * registered driver for the given device. Return -1 if initialization
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index d95747e..4a4641c 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -365,6 +365,38 @@ int rte_eal_pci_scan(void);
  */
 int rte_eal_pci_probe(void);
 
+/**
+ * @internal
+ * Map a particular resource from a file.
+ *
+ * @param requested_addr
+ *      The starting address for the new mapping range.
+ * @param fd
+ *      The file descriptor.
+ * @param offset
+ *      The offset for the mapping range.
+ * @param size
+ *      The size for the mapping range.
+ * @param additional_flags
+ *      The additional flags for the mapping range.
+ * @return
+ *   - On success, the function returns a pointer to the mapped area.
+ *   - On error, the value MAP_FAILED is returned.
+ */
+void *pci_map_resource(void *requested_addr, int fd, off_t offset,
+		size_t size, int additional_flags);
+
+/**
+ * @internal
+ * Unmap a particular resource.
+ *
+ * @param requested_addr
+ *      The address for the unmapping range.
+ * @param size
+ *      The size for the unmapping range.
+ */
+void pci_unmap_resource(void *requested_addr, size_t size);
+
 #ifdef RTE_LIBRTE_EAL_HOTPLUG
 /**
  * Probe the single PCI device.
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index d2adc66..fc99eaa 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -33,7 +33,6 @@
 
 #include <string.h>
 #include <dirent.h>
-#include <sys/mman.h>
 
 #include <rte_log.h>
 #include <rte_pci.h>
@@ -142,46 +141,6 @@ pci_find_max_end_va(void)
 	return RTE_PTR_ADD(last->addr, last->len);
 }
 
-
-/* map a particular resource from a file */
-void *
-pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
-		 int additional_flags)
-{
-	void *mapaddr;
-
-	/* Map the PCI memory resource of device */
-	mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
-			MAP_SHARED | additional_flags, fd, offset);
-	if (mapaddr == MAP_FAILED) {
-		RTE_LOG(ERR, EAL, "%s(): cannot mmap(%d, %p, 0x%lx, 0x%lx): %s (%p)\n",
-			__func__, fd, requested_addr,
-			(unsigned long)size, (unsigned long)offset,
-			strerror(errno), mapaddr);
-	} else {
-		RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
-	}
-
-	return mapaddr;
-}
-
-/* unmap a particular resource */
-void
-pci_unmap_resource(void *requested_addr, size_t size)
-{
-	if (requested_addr == NULL)
-		return;
-
-	/* Unmap the PCI memory resource of device */
-	if (munmap(requested_addr, size)) {
-		RTE_LOG(ERR, EAL, "%s(): cannot munmap(%p, 0x%lx): %s\n",
-			__func__, requested_addr, (unsigned long)size,
-			strerror(errno));
-	} else
-		RTE_LOG(DEBUG, EAL, "  PCI memory unmapped at %p\n",
-				requested_addr);
-}
-
 /* parse the "resource" sysfs file */
 static int
 pci_parse_sysfs_resource(const char *filename, struct rte_pci_device *dev)
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
index d9d1878..d426b27 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
@@ -42,14 +42,9 @@
 extern void *pci_map_addr;
 void *pci_find_max_end_va(void);
 
-void *pci_map_resource(void *requested_addr, int fd, off_t offset,
-	       size_t size, int additional_flags);
-
 /* map IGB_UIO resource prototype */
 int pci_uio_map_resource(struct rte_pci_device *dev);
 
-void pci_unmap_resource(void *requested_addr, size_t size);
-
 #ifdef RTE_LIBRTE_EAL_HOTPLUG
 /* unmap IGB_UIO resource prototype */
 void pci_uio_unmap_resource(struct rte_pci_device *dev);
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v9 10/12] eal: Consolidate pci uio functions of linuxapp and bsdapp
  2015-07-08 10:34               ` [dpdk-dev] [PATCH v9 00/12] Clean up pci uio implementations Tetsuya Mukawa
                                   ` (8 preceding siblings ...)
  2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 09/12] eal: Consolidate pci_map/unmap_resource() " Tetsuya Mukawa
@ 2015-07-08 10:34                 ` Tetsuya Mukawa
  2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 11/12] eal: Consolidate pci_map/unmap_device() " Tetsuya Mukawa
                                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-08 10:34 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

The patch consolidates below functions, and implement these
in eal_common_pci_uio.c.
 - pci_uio_map_secondary()
 - pci_uio_map_resource()
 - pci_uio_unmap()
 - pci_uio_find_resource()
 - pci_uio_unmap_resource()

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
Acked-by: David Marchand <david.marchand@6wind.com>
---
 lib/librte_eal/bsdapp/eal/Makefile                 |   2 +
 lib/librte_eal/bsdapp/eal/eal_pci.c                | 104 +---------
 .../bsdapp/eal/include/exec-env/rte_interrupts.h   |   2 +
 lib/librte_eal/common/eal_common_pci_uio.c         | 225 +++++++++++++++++++++
 lib/librte_eal/common/eal_private.h                |  69 +++++++
 lib/librte_eal/linuxapp/eal/Makefile               |   2 +
 lib/librte_eal/linuxapp/eal/eal_pci_init.h         |  14 +-
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c          | 185 +----------------
 8 files changed, 313 insertions(+), 290 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_pci_uio.c

diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile
index c73ffb6..0d72330 100644
--- a/lib/librte_eal/bsdapp/eal/Makefile
+++ b/lib/librte_eal/bsdapp/eal/Makefile
@@ -1,6 +1,7 @@
 #   BSD LICENSE
 #
 #   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
+#   Copyright(c) 2015 IGEL Co., Ltd.
 #   All rights reserved.
 #
 #   Redistribution and use in source and binary forms, with or without
@@ -68,6 +69,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_memzone.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_log.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_launch.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_pci.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_pci_uio.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_memory.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_tailqs.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_errno.c
diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 16bda09..42cf87e 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -83,10 +83,6 @@
  * network card, only providing access to PCI BAR to applications, and
  * enabling bus master.
  */
-static struct rte_tailq_elem rte_uio_tailq = {
-	.name = "UIO_RESOURCE_LIST",
-};
-EAL_REGISTER_TAILQ(rte_uio_tailq)
 
 /* unbind kernel driver for this device */
 static int
@@ -97,52 +93,7 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)
 	return -ENOTSUP;
 }
 
-static int
-pci_uio_map_secondary(struct rte_pci_device *dev)
-{
-	int i, fd;
-	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list =
-			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
-
-	TAILQ_FOREACH(uio_res, uio_res_list, next) {
-
-		/* skip this element if it doesn't match our PCI address */
-		if (rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr))
-			continue;
-
-		for (i = 0; i != uio_res->nb_maps; i++) {
-			/*
-			 * open devname, to mmap it
-			 */
-			fd = open(uio_res->maps[i].path, O_RDWR);
-			if (fd < 0) {
-				RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
-					uio_res->maps[i].path, strerror(errno));
-				return -1;
-			}
-
-			void *mapaddr = pci_map_resource(uio_res->maps[i].addr,
-					fd, (off_t)uio_res->maps[i].offset,
-					(size_t)uio_res->maps[i].size, 0);
-			/* fd is not needed in slave process, close it */
-			close(fd);
-			if (mapaddr != uio_res->maps[i].addr) {
-				RTE_LOG(ERR, EAL,
-					"Cannot mmap device resource file %s to address: %p\n",
-					uio_res->maps[i].path,
-					uio_res->maps[i].addr);
-				return -1;
-			}
-		}
-		return 0;
-	}
-
-	RTE_LOG(ERR, EAL, "Cannot find resource for device\n");
-	return 1;
-}
-
-static void
+void
 pci_uio_free_resource(struct rte_pci_device *dev,
 		struct mapped_pci_resource *uio_res)
 {
@@ -155,7 +106,7 @@ pci_uio_free_resource(struct rte_pci_device *dev,
 	}
 }
 
-static int
+int
 pci_uio_alloc_resource(struct rte_pci_device *dev,
 		struct mapped_pci_resource **uio_res)
 {
@@ -200,7 +151,7 @@ error:
 	return -1;
 }
 
-static int
+int
 pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
 		struct mapped_pci_resource *uio_res, int map_idx)
 {
@@ -255,55 +206,6 @@ error:
 	return -1;
 }
 
-/* map the PCI resource of a PCI device in virtual memory */
-static int
-pci_uio_map_resource(struct rte_pci_device *dev)
-{
-	int i, map_idx = 0, ret;
-	uint64_t phaddr;
-	struct mapped_pci_resource *uio_res = NULL;
-	struct mapped_pci_res_list *uio_res_list =
-		RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
-
-	dev->intr_handle.fd = -1;
-	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
-
-	/* secondary processes - use already recorded details */
-	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
-		return pci_uio_map_secondary(dev);
-
-	/* allocate uio resource */
-	ret = pci_uio_alloc_resource(dev, &uio_res);
-	if (ret)
-		return ret;
-
-	/* Map all BARs */
-	for (i = 0; i != PCI_MAX_RESOURCE; i++) {
-		/* skip empty BAR */
-		if ((phaddr = dev->mem_resource[i].phys_addr) == 0)
-			continue;
-
-		ret = pci_uio_map_resource_by_index(dev, i,
-				uio_res, map_idx);
-		if (ret)
-			goto error;
-
-		map_idx++;
-	}
-
-	uio_res->nb_maps = map_idx;
-
-	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
-
-	return 0;
-error:
-	for (i = 0; i < map_idx; i++)
-		rte_free(uio_res->maps[i].path);
-	pci_uio_free_resource(dev, uio_res);
-	return -1;
-}
-
-/* Scan one pci sysfs entry, and fill the devices list from it. */
 static int
 pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
 {
diff --git a/lib/librte_eal/bsdapp/eal/include/exec-env/rte_interrupts.h b/lib/librte_eal/bsdapp/eal/include/exec-env/rte_interrupts.h
index 87a9cf6..410dd21 100644
--- a/lib/librte_eal/bsdapp/eal/include/exec-env/rte_interrupts.h
+++ b/lib/librte_eal/bsdapp/eal/include/exec-env/rte_interrupts.h
@@ -2,6 +2,7 @@
  *   BSD LICENSE
  *
  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2015 IGEL Co., Ltd.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -48,6 +49,7 @@ enum rte_intr_handle_type {
 /** Handle for interrupts. */
 struct rte_intr_handle {
 	int fd;                          /**< file descriptor */
+	int uio_cfg_fd;                  /**< UIO config file descriptor */
 	enum rte_intr_handle_type type;  /**< handle type */
 };
 
diff --git a/lib/librte_eal/common/eal_common_pci_uio.c b/lib/librte_eal/common/eal_common_pci_uio.c
new file mode 100644
index 0000000..9fa9844
--- /dev/null
+++ b/lib/librte_eal/common/eal_common_pci_uio.c
@@ -0,0 +1,225 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2015 IGEL Co., Ltd.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <fcntl.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+
+#include <rte_eal.h>
+#include <rte_tailq.h>
+#include <rte_log.h>
+#include <rte_malloc.h>
+
+#include "eal_private.h"
+
+static struct rte_tailq_elem rte_uio_tailq = {
+	.name = "UIO_RESOURCE_LIST",
+};
+EAL_REGISTER_TAILQ(rte_uio_tailq)
+
+static int
+pci_uio_map_secondary(struct rte_pci_device *dev)
+{
+	int fd, i;
+	struct mapped_pci_resource *uio_res;
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+
+	TAILQ_FOREACH(uio_res, uio_res_list, next) {
+
+		/* skip this element if it doesn't match our PCI address */
+		if (rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr))
+			continue;
+
+		for (i = 0; i != uio_res->nb_maps; i++) {
+			/*
+			 * open devname, to mmap it
+			 */
+			fd = open(uio_res->maps[i].path, O_RDWR);
+			if (fd < 0) {
+				RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
+					uio_res->maps[i].path, strerror(errno));
+				return -1;
+			}
+
+			void *mapaddr = pci_map_resource(uio_res->maps[i].addr,
+					fd, (off_t)uio_res->maps[i].offset,
+					(size_t)uio_res->maps[i].size, 0);
+			/* fd is not needed in slave process, close it */
+			close(fd);
+			if (mapaddr != uio_res->maps[i].addr) {
+				RTE_LOG(ERR, EAL,
+					"Cannot mmap device resource file %s to address: %p\n",
+					uio_res->maps[i].path,
+					uio_res->maps[i].addr);
+				return -1;
+			}
+		}
+		return 0;
+	}
+
+	RTE_LOG(ERR, EAL, "Cannot find resource for device\n");
+	return 1;
+}
+
+/* map the PCI resource of a PCI device in virtual memory */
+int
+pci_uio_map_resource(struct rte_pci_device *dev)
+{
+	int i, map_idx = 0, ret;
+	uint64_t phaddr;
+	struct mapped_pci_resource *uio_res = NULL;
+	struct mapped_pci_res_list *uio_res_list =
+		RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+
+	dev->intr_handle.fd = -1;
+	dev->intr_handle.uio_cfg_fd = -1;
+	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+
+	/* secondary processes - use already recorded details */
+	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+		return pci_uio_map_secondary(dev);
+
+	/* allocate uio resource */
+	ret = pci_uio_alloc_resource(dev, &uio_res);
+	if (ret)
+		return ret;
+
+	/* Map all BARs */
+	for (i = 0; i != PCI_MAX_RESOURCE; i++) {
+		/* skip empty BAR */
+		phaddr = dev->mem_resource[i].phys_addr;
+		if (phaddr == 0)
+			continue;
+
+		ret = pci_uio_map_resource_by_index(dev, i,
+				uio_res, map_idx);
+		if (ret)
+			goto error;
+
+		map_idx++;
+	}
+
+	uio_res->nb_maps = map_idx;
+
+	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
+
+	return 0;
+error:
+	for (i = 0; i < map_idx; i++) {
+		pci_unmap_resource(uio_res->maps[i].addr,
+				(size_t)uio_res->maps[i].size);
+		rte_free(uio_res->maps[i].path);
+	}
+	pci_uio_free_resource(dev, uio_res);
+	return -1;
+}
+
+#ifdef RTE_LIBRTE_EAL_HOTPLUG
+static void
+pci_uio_unmap(struct mapped_pci_resource *uio_res)
+{
+	int i;
+
+	if (uio_res == NULL)
+		return;
+
+	for (i = 0; i != uio_res->nb_maps; i++) {
+		pci_unmap_resource(uio_res->maps[i].addr,
+				(size_t)uio_res->maps[i].size);
+		rte_free(uio_res->maps[i].path);
+	}
+}
+
+static struct mapped_pci_resource *
+pci_uio_find_resource(struct rte_pci_device *dev)
+{
+	struct mapped_pci_resource *uio_res;
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+
+	if (dev == NULL)
+		return NULL;
+
+	TAILQ_FOREACH(uio_res, uio_res_list, next) {
+
+		/* skip this element if it doesn't match our PCI address */
+		if (!rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr))
+			return uio_res;
+	}
+	return NULL;
+}
+
+/* unmap the PCI resource of a PCI device in virtual memory */
+void
+pci_uio_unmap_resource(struct rte_pci_device *dev)
+{
+	struct mapped_pci_resource *uio_res;
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+
+	if (dev == NULL)
+		return;
+
+	/* find an entry for the device */
+	uio_res = pci_uio_find_resource(dev);
+	if (uio_res == NULL)
+		return;
+
+	/* secondary processes - just free maps */
+	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+		return pci_uio_unmap(uio_res);
+
+	TAILQ_REMOVE(uio_res_list, uio_res, next);
+
+	/* unmap all resources */
+	pci_uio_unmap(uio_res);
+
+	/* free uio resource */
+	rte_free(uio_res);
+
+	/* close fd if in primary process */
+	close(dev->intr_handle.fd);
+	if (dev->intr_handle.uio_cfg_fd >= 0) {
+		close(dev->intr_handle.uio_cfg_fd);
+		dev->intr_handle.uio_cfg_fd = -1;
+	}
+
+	dev->intr_handle.fd = -1;
+	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+}
+#endif /* RTE_LIBRTE_EAL_HOTPLUG */
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 4acf5a0..c0b62b7 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -2,6 +2,7 @@
  *   BSD LICENSE
  *
  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2015 IGEL Co., Ltd.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -35,6 +36,7 @@
 #define _EAL_PRIVATE_H_
 
 #include <stdio.h>
+#include <rte_pci.h>
 
 /**
  * Initialize the memzone subsystem (private to eal).
@@ -154,6 +156,25 @@ struct rte_pci_driver;
 struct rte_pci_device;
 
 /**
+ * Map the PCI resource of a PCI device in virtual memory
+ *
+ * This function is private to EAL.
+ *
+ * @return
+ *   0 on success, negative on error
+ */
+int pci_uio_map_resource(struct rte_pci_device *dev);
+
+#ifdef RTE_LIBRTE_EAL_HOTPLUG
+/**
+ * Unmap the PCI resource of a PCI device
+ *
+ * This function is private to EAL.
+ */
+void pci_uio_unmap_resource(struct rte_pci_device *dev);
+#endif /* RTE_LIBRTE_EAL_HOTPLUG */
+
+/**
  * Mmap memory for single PCI device
  *
  * This function is private to EAL.
@@ -180,6 +201,54 @@ int rte_eal_pci_close_one_driver(struct rte_pci_driver *dr,
 		struct rte_pci_device *dev);
 
 /**
+ * Allocate uio resource for PCI device
+ *
+ * This function is private to EAL.
+ *
+ * @param dev
+ *   PCI device to allocate uio resource
+ * @param uio_res
+ *   Pointer to uio resource.
+ *   If the function returns 0, the pointer will be filled.
+ * @return
+ *   0 on success, negative on error
+ */
+int pci_uio_alloc_resource(struct rte_pci_device *dev,
+		struct mapped_pci_resource **uio_res);
+
+/**
+ * Free uio resource for PCI device
+ *
+ * This function is private to EAL.
+ *
+ * @param dev
+ *   PCI device to free uio resource
+ * @param uio_res
+ *   Pointer to uio resource.
+ */
+void pci_uio_free_resource(struct rte_pci_device *dev,
+		struct mapped_pci_resource *uio_res);
+
+/**
+ * Map device memory to uio resource
+ *
+ * This function is private to EAL.
+ *
+ * @param dev
+ *   PCI device that has memory information.
+ * @param res_idx
+ *   Memory resource index of the PCI device.
+ * @param uio_res
+ *  uio resource that will keep mapping information.
+ * @param map_idx
+ *   Mapping information index of the uio resource.
+ * @return
+ *   0 on success, negative on error
+ */
+int pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
+		struct mapped_pci_resource *uio_res, int map_idx);
+
+/**
  * Init tail queues for non-EAL library structures. This is to allow
  * the rings, mempools, etc. lists to be shared among multiple processes
  *
diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
index e99d7a3..92900d6 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -1,6 +1,7 @@
 #   BSD LICENSE
 #
 #   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
+#   Copyright(c) 2015 IGEL Co., Ltd.
 #   All rights reserved.
 #
 #   Redistribution and use in source and binary forms, with or without
@@ -80,6 +81,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_memzone.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_log.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_launch.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_pci.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_pci_uio.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_memory.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_tailqs.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_errno.c
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
index d426b27..32de148 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
@@ -2,6 +2,7 @@
  *   BSD LICENSE
  *
  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2015 IGEL Co., Ltd.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -42,13 +43,12 @@
 extern void *pci_map_addr;
 void *pci_find_max_end_va(void);
 
-/* map IGB_UIO resource prototype */
-int pci_uio_map_resource(struct rte_pci_device *dev);
-
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
-/* unmap IGB_UIO resource prototype */
-void pci_uio_unmap_resource(struct rte_pci_device *dev);
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
+int pci_uio_alloc_resource(struct rte_pci_device *dev,
+		struct mapped_pci_resource **uio_res);
+void pci_uio_free_resource(struct rte_pci_device *dev,
+		struct mapped_pci_resource *uio_res);
+int pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
+		struct mapped_pci_resource *uio_res, int map_idx);
 
 #ifdef VFIO_PRESENT
 
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 3f5520f..c1d9cdc 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -52,11 +52,6 @@
 
 void *pci_map_addr = NULL;
 
-static struct rte_tailq_elem rte_uio_tailq = {
-	.name = "UIO_RESOURCE_LIST",
-};
-EAL_REGISTER_TAILQ(rte_uio_tailq)
-
 #define OFF_MAX              ((uint64_t)(off_t)-1)
 
 static int
@@ -89,51 +84,6 @@ pci_uio_set_bus_master(int dev_fd)
 }
 
 static int
-pci_uio_map_secondary(struct rte_pci_device *dev)
-{
-	int fd, i;
-	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list =
-			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
-
-	TAILQ_FOREACH(uio_res, uio_res_list, next) {
-
-		/* skip this element if it doesn't match our PCI address */
-		if (rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr))
-			continue;
-
-		for (i = 0; i != uio_res->nb_maps; i++) {
-			/*
-			 * open devname, to mmap it
-			 */
-			fd = open(uio_res->maps[i].path, O_RDWR);
-			if (fd < 0) {
-				RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
-					uio_res->maps[i].path, strerror(errno));
-				return -1;
-			}
-
-			void *mapaddr = pci_map_resource(uio_res->maps[i].addr,
-					fd, (off_t)uio_res->maps[i].offset,
-					(size_t)uio_res->maps[i].size, 0);
-			/* fd is not needed in slave process, close it */
-			close(fd);
-			if (mapaddr != uio_res->maps[i].addr) {
-				RTE_LOG(ERR, EAL,
-					"Cannot mmap device resource file %s to address: %p\n",
-					uio_res->maps[i].path,
-					uio_res->maps[i].addr);
-				return -1;
-			}
-		}
-		return 0;
-	}
-
-	RTE_LOG(ERR, EAL, "Cannot find resource for device\n");
-	return 1;
-}
-
-static int
 pci_mknod_uio_dev(const char *sysfs_uio_path, unsigned uio_num)
 {
 	FILE *f;
@@ -253,7 +203,7 @@ pci_get_uio_dev(struct rte_pci_device *dev, char *dstbuf,
 	return uio_num;
 }
 
-static void
+void
 pci_uio_free_resource(struct rte_pci_device *dev,
 		struct mapped_pci_resource *uio_res)
 {
@@ -270,7 +220,7 @@ pci_uio_free_resource(struct rte_pci_device *dev,
 	}
 }
 
-static int
+int
 pci_uio_alloc_resource(struct rte_pci_device *dev,
 		struct mapped_pci_resource **uio_res)
 {
@@ -338,7 +288,7 @@ error:
 	return -1;
 }
 
-static int
+int
 pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
 		struct mapped_pci_resource *uio_res, int map_idx)
 {
@@ -401,132 +351,3 @@ error:
 	rte_free(maps[map_idx].path);
 	return -1;
 }
-
-/* map the PCI resource of a PCI device in virtual memory */
-int
-pci_uio_map_resource(struct rte_pci_device *dev)
-{
-	int i, map_idx = 0, ret;
-	uint64_t phaddr;
-	struct mapped_pci_resource *uio_res = NULL;
-	struct mapped_pci_res_list *uio_res_list =
-		RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
-
-	dev->intr_handle.fd = -1;
-	dev->intr_handle.uio_cfg_fd = -1;
-	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
-
-	/* secondary processes - use already recorded details */
-	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
-		return pci_uio_map_secondary(dev);
-
-	/* allocate uio resource */
-	ret = pci_uio_alloc_resource(dev, &uio_res);
-	if (ret)
-		return ret;
-
-	/* Map all BARs */
-	for (i = 0; i != PCI_MAX_RESOURCE; i++) {
-		/* skip empty BAR */
-		phaddr = dev->mem_resource[i].phys_addr;
-		if (phaddr == 0)
-			continue;
-
-		ret = pci_uio_map_resource_by_index(dev, i,
-				uio_res, map_idx);
-		if (ret)
-			goto error;
-
-		map_idx++;
-	}
-
-	uio_res->nb_maps = map_idx;
-
-	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
-
-	return 0;
-
-error:
-	for (i = 0; i < map_idx; i++) {
-		pci_unmap_resource(uio_res->maps[i].addr,
-				(size_t)uio_res->maps[i].size);
-		rte_free(uio_res->maps[i].path);
-	}
-	pci_uio_free_resource(dev, uio_res);
-	return -1;
-}
-
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
-static void
-pci_uio_unmap(struct mapped_pci_resource *uio_res)
-{
-	int i;
-
-	if (uio_res == NULL)
-		return;
-
-	for (i = 0; i != uio_res->nb_maps; i++) {
-		pci_unmap_resource(uio_res->maps[i].addr,
-				(size_t)uio_res->maps[i].size);
-		rte_free(uio_res->maps[i].path);
-	}
-}
-
-static struct mapped_pci_resource *
-pci_uio_find_resource(struct rte_pci_device *dev)
-{
-	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list =
-			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
-
-	if (dev == NULL)
-		return NULL;
-
-	TAILQ_FOREACH(uio_res, uio_res_list, next) {
-
-		/* skip this element if it doesn't match our PCI address */
-		if (!rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr))
-			return uio_res;
-	}
-	return NULL;
-}
-
-/* unmap the PCI resource of a PCI device in virtual memory */
-void
-pci_uio_unmap_resource(struct rte_pci_device *dev)
-{
-	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list =
-			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
-
-	if (dev == NULL)
-		return;
-
-	/* find an entry for the device */
-	uio_res = pci_uio_find_resource(dev);
-	if (uio_res == NULL)
-		return;
-
-	/* secondary processes - just free maps */
-	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
-		return pci_uio_unmap(uio_res);
-
-	TAILQ_REMOVE(uio_res_list, uio_res, next);
-
-	/* unmap all resources */
-	pci_uio_unmap(uio_res);
-
-	/* free uio resource */
-	rte_free(uio_res);
-
-	/* close fd if in primary process */
-	close(dev->intr_handle.fd);
-	dev->intr_handle.fd = -1;
-
-	/* close cfg_fd if in primary process */
-	close(dev->intr_handle.uio_cfg_fd);
-	dev->intr_handle.uio_cfg_fd = -1;
-
-	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
-}
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v9 11/12] eal: Consolidate pci_map/unmap_device() of linuxapp and bsdapp
  2015-07-08 10:34               ` [dpdk-dev] [PATCH v9 00/12] Clean up pci uio implementations Tetsuya Mukawa
                                   ` (9 preceding siblings ...)
  2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 10/12] eal: Consolidate pci uio functions " Tetsuya Mukawa
@ 2015-07-08 10:34                 ` Tetsuya Mukawa
  2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 12/12] eal: Consolidate rte_eal_pci_probe/close_one_driver() " Tetsuya Mukawa
  2015-07-08 12:36                 ` [dpdk-dev] [PATCH v9 00/12] Clean up pci uio implementations David Marchand
  12 siblings, 0 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-08 10:34 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

The patch consolidates below functions, and implemented in common
eal code.
 - pci_map_device()
 - pci_unmap_device()

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
Acked-by: Bernard Iremonger <bernard.iremonger@intel.com>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c     |  3 ++
 lib/librte_eal/common/eal_common_pci.c  | 57 +++++++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_private.h     | 19 +++++++++++
 lib/librte_eal/common/include/rte_pci.h |  1 +
 lib/librte_eal/linuxapp/eal/eal_pci.c   | 53 ------------------------------
 lib/librte_ether/rte_ethdev.c           |  2 ++
 6 files changed, 82 insertions(+), 53 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 42cf87e..d790d1f 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -242,6 +242,9 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
 	/* FreeBSD has no NUMA support (yet) */
 	dev->numa_node = 0;
 
+	/* FreeBSD has only one pass through driver */
+	dev->kdrv = RTE_KDRV_NIC_UIO;
+
 	/* parse resources */
 	switch (conf->pc_hdr & PCIM_HDRTYPE) {
 	case PCIM_HDRTYPE_NORMAL:
diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index eab147a..afd14ec 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -138,6 +138,63 @@ pci_unmap_resource(void *requested_addr, size_t size)
 				requested_addr);
 }
 
+/* Map pci device */
+int
+pci_map_device(struct rte_pci_device *dev)
+{
+	int ret = -1;
+
+	/* try mapping the NIC resources using VFIO if it exists */
+	switch (dev->kdrv) {
+	case RTE_KDRV_VFIO:
+#ifdef VFIO_PRESENT
+		if (pci_vfio_is_enabled())
+			ret = pci_vfio_map_resource(dev);
+#endif
+		break;
+	case RTE_KDRV_IGB_UIO:
+	case RTE_KDRV_UIO_GENERIC:
+	case RTE_KDRV_NIC_UIO:
+		/* map resources for devices that use uio */
+		ret = pci_uio_map_resource(dev);
+		break;
+	default:
+		RTE_LOG(DEBUG, EAL, "  Not managed by a supported kernel driver,"
+			" skipped\n");
+		ret = 1;
+		break;
+	}
+
+	return ret;
+}
+
+#ifdef RTE_LIBRTE_EAL_HOTPLUG
+/* Unmap pci device */
+void
+pci_unmap_device(struct rte_pci_device *dev)
+{
+	if (dev == NULL)
+		return;
+
+	/* try unmapping the NIC resources using VFIO if it exists */
+	switch (dev->kdrv) {
+	case RTE_KDRV_VFIO:
+		RTE_LOG(ERR, EAL, "Hotplug doesn't support vfio yet\n");
+		break;
+	case RTE_KDRV_IGB_UIO:
+	case RTE_KDRV_UIO_GENERIC:
+	case RTE_KDRV_NIC_UIO:
+		/* unmap resources for devices that use uio */
+		pci_uio_unmap_resource(dev);
+		break;
+	default:
+		RTE_LOG(DEBUG, EAL, "  Not managed by a supported kernel driver,"
+			" skipped\n");
+		break;
+	}
+}
+#endif /* RTE_LIBRTE_EAL_HOTPLUG */
+
 /*
  * If vendor/device ID match, call the devinit() function of all
  * registered driver for the given device. Return -1 if initialization
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index c0b62b7..cc022be 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -156,6 +156,25 @@ struct rte_pci_driver;
 struct rte_pci_device;
 
 /**
+ * Map this device
+ *
+ * This function is private to EAL.
+ *
+ * @return
+ *   0 on success, negative on error
+ */
+int pci_map_device(struct rte_pci_device *dev);
+
+#ifdef RTE_LIBRTE_EAL_HOTPLUG
+/**
+ * Unmap this device
+ *
+ * This function is private to EAL.
+ */
+void pci_unmap_device(struct rte_pci_device *dev);
+#endif /* RTE_LIBRTE_EAL_HOTPLUG */
+
+/**
  * Map the PCI resource of a PCI device in virtual memory
  *
  * This function is private to EAL.
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index 4a4641c..1f09252 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -149,6 +149,7 @@ enum rte_kernel_driver {
 	RTE_KDRV_IGB_UIO,
 	RTE_KDRV_VFIO,
 	RTE_KDRV_UIO_GENERIC,
+	RTE_KDRV_NIC_UIO,
 };
 
 /**
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index fc99eaa..7e8df7d 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -522,59 +522,6 @@ pci_config_space_set(struct rte_pci_device *dev)
 }
 #endif
 
-static int
-pci_map_device(struct rte_pci_device *dev)
-{
-	int ret = -1;
-
-	/* try mapping the NIC resources using VFIO if it exists */
-	switch (dev->kdrv) {
-	case RTE_KDRV_VFIO:
-#ifdef VFIO_PRESENT
-		if (pci_vfio_is_enabled())
-			ret = pci_vfio_map_resource(dev);
-#endif
-		break;
-	case RTE_KDRV_IGB_UIO:
-	case RTE_KDRV_UIO_GENERIC:
-		/* map resources for devices that use uio */
-		ret = pci_uio_map_resource(dev);
-		break;
-	default:
-		RTE_LOG(DEBUG, EAL, "  Not managed by a supported kernel driver,"
-			" skipped\n");
-		ret = 1;
-		break;
-	}
-
-	return ret;
-}
-
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
-static void
-pci_unmap_device(struct rte_pci_device *dev)
-{
-	if (dev == NULL)
-		return;
-
-	/* try unmapping the NIC resources using VFIO if it exists */
-	switch (dev->kdrv) {
-	case RTE_KDRV_VFIO:
-		RTE_LOG(ERR, EAL, "Hotplug doesn't support vfio yet\n");
-		break;
-	case RTE_KDRV_IGB_UIO:
-	case RTE_KDRV_UIO_GENERIC:
-		/* unmap resources for devices that use uio */
-		pci_uio_unmap_resource(dev);
-		break;
-	default:
-		RTE_LOG(DEBUG, EAL, "  Not managed by a supported kernel driver,"
-			" skipped\n");
-		break;
-	}
-}
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
-
 /*
  * If vendor/device ID match, call the devinit() function of the
  * driver.
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index da915db..7b24e26 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -2,6 +2,7 @@
  *   BSD LICENSE
  *
  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2015 IGEL Co., Ltd.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -527,6 +528,7 @@ rte_eth_dev_is_detachable(uint8_t port_id)
 		switch (rte_eth_devices[port_id].pci_dev->kdrv) {
 		case RTE_KDRV_IGB_UIO:
 		case RTE_KDRV_UIO_GENERIC:
+		case RTE_KDRV_NIC_UIO:
 			break;
 		case RTE_KDRV_VFIO:
 		default:
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* [dpdk-dev] [PATCH v9 12/12] eal: Consolidate rte_eal_pci_probe/close_one_driver() of linuxapp and bsdapp
  2015-07-08 10:34               ` [dpdk-dev] [PATCH v9 00/12] Clean up pci uio implementations Tetsuya Mukawa
                                   ` (10 preceding siblings ...)
  2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 11/12] eal: Consolidate pci_map/unmap_device() " Tetsuya Mukawa
@ 2015-07-08 10:34                 ` Tetsuya Mukawa
  2015-07-08 12:36                 ` [dpdk-dev] [PATCH v9 00/12] Clean up pci uio implementations David Marchand
  12 siblings, 0 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-08 10:34 UTC (permalink / raw)
  To: dev

From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

This patch consolidates below functions, and implements these in common
eal code.
 - rte_eal_pci_probe_one_driver()
 - rte_eal_pci_close_one_driver()

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
Acked-by: David Marchand <david.marchand@6wind.com>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c    |  67 +--------------
 lib/librte_eal/common/eal_common_pci.c | 133 +++++++++++++++++++++++++++++-
 lib/librte_eal/common/eal_private.h    |  39 +--------
 lib/librte_eal/linuxapp/eal/eal_pci.c  | 143 +--------------------------------
 4 files changed, 136 insertions(+), 246 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index d790d1f..7f49958 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -85,7 +85,7 @@
  */
 
 /* unbind kernel driver for this device */
-static int
+int
 pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)
 {
 	RTE_LOG(ERR, EAL, "RTE_PCI_DRV_FORCE_UNBIND flag is not implemented "
@@ -359,71 +359,6 @@ error:
 	return -1;
 }
 
-/*
- * If vendor/device ID match, call the devinit() function of the
- * driver.
- */
-int
-rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dev)
-{
-	const struct rte_pci_id *id_table;
-	int ret;
-
-	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",
-				loc->domain, loc->bus, loc->devid, loc->function,
-				dev->numa_node);
-
-		RTE_LOG(DEBUG, EAL, "  probe driver: %x:%x %s\n", dev->id.vendor_id,
-				dev->id.device_id, dr->name);
-
-		/* no initialization when blacklisted, return without error */
-		if (dev->devargs != NULL &&
-			dev->devargs->type == RTE_DEVTYPE_BLACKLISTED_PCI) {
-
-			RTE_LOG(DEBUG, EAL, "  Device is blacklisted, not initializing\n");
-			return 0;
-		}
-
-		if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) {
-			/* map resources for devices that use igb_uio */
-			ret = pci_uio_map_resource(dev);
-			if (ret != 0)
-				return ret;
-		} else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND &&
-		           rte_eal_process_type() == RTE_PROC_PRIMARY) {
-			/* unbind current driver */
-			if (pci_unbind_kernel_driver(dev) < 0)
-				return -1;
-		}
-
-		/* reference driver structure */
-		dev->driver = dr;
-
-		/* call the driver devinit() function */
-		return dr->devinit(dr, dev);
-	}
-	/* return positive value if driver is not found */
-	return 1;
-}
-
 /* Init the PCI EAL subsystem */
 int
 rte_eal_pci_init(void)
diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index afd14ec..031c7a7 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -139,7 +139,7 @@ pci_unmap_resource(void *requested_addr, size_t size)
 }
 
 /* Map pci device */
-int
+static int
 pci_map_device(struct rte_pci_device *dev)
 {
 	int ret = -1;
@@ -170,7 +170,7 @@ pci_map_device(struct rte_pci_device *dev)
 
 #ifdef RTE_LIBRTE_EAL_HOTPLUG
 /* Unmap pci device */
-void
+static void
 pci_unmap_device(struct rte_pci_device *dev)
 {
 	if (dev == NULL)
@@ -196,6 +196,135 @@ pci_unmap_device(struct rte_pci_device *dev)
 #endif /* RTE_LIBRTE_EAL_HOTPLUG */
 
 /*
+ * 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;
+	const struct rte_pci_id *id_table;
+
+	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",
+				loc->domain, loc->bus, loc->devid, loc->function,
+				dev->numa_node);
+
+		RTE_LOG(DEBUG, EAL, "  probe driver: %x:%x %s\n", dev->id.vendor_id,
+				dev->id.device_id, dr->name);
+
+		/* no initialization when blacklisted, return without error */
+		if (dev->devargs != NULL &&
+			dev->devargs->type == RTE_DEVTYPE_BLACKLISTED_PCI) {
+			RTE_LOG(DEBUG, EAL, "  Device is blacklisted, not initializing\n");
+			return 1;
+		}
+
+		if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) {
+#ifdef RTE_PCI_CONFIG
+			/*
+			 * Set PCIe config space for high performance.
+			 * Return value can be ignored.
+			 */
+			pci_config_space_set(dev);
+#endif
+			/* map resources for devices that use igb_uio */
+			ret = pci_map_device(dev);
+			if (ret != 0)
+				return ret;
+		} else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND &&
+				rte_eal_process_type() == RTE_PROC_PRIMARY) {
+			/* unbind current driver */
+			if (pci_unbind_kernel_driver(dev) < 0)
+				return -1;
+		}
+
+		/* reference driver structure */
+		dev->driver = dr;
+
+		/* call the driver devinit() function */
+		return dr->devinit(dr, dev);
+	}
+	/* return positive value if driver is not found */
+	return 1;
+}
+
+#ifdef RTE_LIBRTE_EAL_HOTPLUG
+/*
+ * If vendor/device ID match, call the devuninit() function of the
+ * driver.
+ */
+static int
+rte_eal_pci_close_one_driver(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",
+				loc->domain, loc->bus, loc->devid,
+				loc->function, dev->numa_node);
+
+		RTE_LOG(DEBUG, EAL, "  remove driver: %x:%x %s\n", dev->id.vendor_id,
+				dev->id.device_id, dr->name);
+
+		/* call the driver devuninit() function */
+		if (dr->devuninit && (dr->devuninit(dev) < 0))
+			return -1;	/* negative value is an error */
+
+		/* clear driver structure */
+		dev->driver = NULL;
+
+		if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING)
+			/* unmap resources for devices that use igb_uio */
+			pci_unmap_device(dev);
+
+		return 0;
+	}
+
+	/* return positive value if driver is not found */
+	return 1;
+}
+#endif /* RTE_LIBRTE_EAL_HOTPLUG */
+
+/*
  * 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.
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index cc022be..f909010 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -156,23 +156,14 @@ struct rte_pci_driver;
 struct rte_pci_device;
 
 /**
- * Map this device
+ * Unbind kernel driver for this device
  *
  * This function is private to EAL.
  *
  * @return
  *   0 on success, negative on error
  */
-int pci_map_device(struct rte_pci_device *dev);
-
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
-/**
- * Unmap this device
- *
- * This function is private to EAL.
- */
-void pci_unmap_device(struct rte_pci_device *dev);
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
+int pci_unbind_kernel_driver(struct rte_pci_device *dev);
 
 /**
  * Map the PCI resource of a PCI device in virtual memory
@@ -194,32 +185,6 @@ void pci_uio_unmap_resource(struct rte_pci_device *dev);
 #endif /* RTE_LIBRTE_EAL_HOTPLUG */
 
 /**
- * Mmap memory for single PCI device
- *
- * This function is private to EAL.
- *
- * @return
- *   0 on success, negative on error
- */
-int rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr,
-		struct rte_pci_device *dev);
-
-/**
- * Munmap memory for single PCI device
- *
- * This function is private to EAL.
- *
- * @param	dr
- *  The pointer to the pci driver structure
- * @param	dev
- *  The pointer to the pci device structure
- * @return
- *   0 on success, negative on error
- */
-int rte_eal_pci_close_one_driver(struct rte_pci_driver *dr,
-		struct rte_pci_device *dev);
-
-/**
  * Allocate uio resource for PCI device
  *
  * 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 7e8df7d..ad6d1de 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -2,6 +2,7 @@
  *   BSD LICENSE
  *
  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2015 IGEL Co., Ltd.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -56,7 +57,7 @@
  */
 
 /* unbind kernel driver for this device */
-static int
+int
 pci_unbind_kernel_driver(struct rte_pci_device *dev)
 {
 	int n;
@@ -522,146 +523,6 @@ pci_config_space_set(struct rte_pci_device *dev)
 }
 #endif
 
-/*
- * If vendor/device ID match, call the devinit() function of the
- * driver.
- */
-int
-rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, 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++) {
-
-		/* 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",
-				loc->domain, loc->bus, loc->devid, loc->function,
-				dev->numa_node);
-
-		RTE_LOG(DEBUG, EAL, "  probe driver: %x:%x %s\n", dev->id.vendor_id,
-				dev->id.device_id, dr->name);
-
-		/* no initialization when blacklisted, return without error */
-		if (dev->devargs != NULL &&
-			dev->devargs->type == RTE_DEVTYPE_BLACKLISTED_PCI) {
-			RTE_LOG(DEBUG, EAL, "  Device is blacklisted, not initializing\n");
-			return 1;
-		}
-
-		if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) {
-#ifdef RTE_PCI_CONFIG
-			/*
-			 * Set PCIe config space for high performance.
-			 * Return value can be ignored.
-			 */
-			pci_config_space_set(dev);
-#endif
-			/* map resources for devices that use igb_uio */
-			ret = pci_map_device(dev);
-			if (ret != 0)
-				return ret;
-		} else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND &&
-		           rte_eal_process_type() == RTE_PROC_PRIMARY) {
-			/* unbind current driver */
-			if (pci_unbind_kernel_driver(dev) < 0)
-				return -1;
-		}
-
-		/* reference driver structure */
-		dev->driver = dr;
-
-		/* call the driver devinit() function */
-		return dr->devinit(dr, dev);
-	}
-	/* return positive value if driver is not found */
-	return 1;
-}
-
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
-/*
- * If vendor/device ID match, call the devuninit() function of the
- * driver.
- */
-int
-rte_eal_pci_close_one_driver(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",
-				loc->domain, loc->bus, loc->devid,
-				loc->function, dev->numa_node);
-
-		RTE_LOG(DEBUG, EAL, "  remove driver: %x:%x %s\n",
-				dev->id.vendor_id, dev->id.device_id,
-				dr->name);
-
-		/* call the driver devuninit() function */
-		if (dr->devuninit && (dr->devuninit(dev) < 0))
-			return -1;	/* negative value is an error */
-
-		/* clear driver structure */
-		dev->driver = NULL;
-
-		if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING)
-			/* unmap resources for devices that use igb_uio */
-			pci_unmap_device(dev);
-
-		return 0;
-	}
-	/* return positive value if driver is not found */
-	return 1;
-}
-#else /* RTE_LIBRTE_EAL_HOTPLUG */
-int
-rte_eal_pci_close_one_driver(struct rte_pci_driver *dr __rte_unused,
-		struct rte_pci_device *dev __rte_unused)
-{
-	RTE_LOG(ERR, EAL, "Hotplug support isn't enabled\n");
-	return -1;
-}
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
-
 /* Init the PCI EAL subsystem */
 int
 rte_eal_pci_init(void)
-- 
2.1.4

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v9 00/12] Clean up pci uio implementations
  2015-07-08 10:34               ` [dpdk-dev] [PATCH v9 00/12] Clean up pci uio implementations Tetsuya Mukawa
                                   ` (11 preceding siblings ...)
  2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 12/12] eal: Consolidate rte_eal_pci_probe/close_one_driver() " Tetsuya Mukawa
@ 2015-07-08 12:36                 ` David Marchand
  2015-07-08 21:52                   ` Thomas Monjalon
  12 siblings, 1 reply; 120+ messages in thread
From: David Marchand @ 2015-07-08 12:36 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Wed, Jul 8, 2015 at 12:34 PM, Tetsuya Mukawa <mukawa@igel.co.jp> wrote:

> Currently Linux implementation and BSD implementation have almost same
> code about pci uio. This patch series cleans up it.
>
> PATCH v9 changes:
>  - Add lost Acked-by and Tested-by signatures.
>  - Remove NULL checkings before calling rte_free().
>  - Fix pci_uio_map_secondary() to remove needless close().
>  - Remove needless parameter checkings of pci_uio_alloc_resource() and
>    pci_uio_map_resource_by_index().
>  - Remove needless error checking for return value of
> pci_uio_alloc_resource().
>  - Introduce pci_uio_free_resource().
>  - Remove some comments of pci_uio_map_resource().
>    (Thanks to David Marchand)
>
>
Acked-by: David Marchand <david.marchand@6wind.com>

Thanks for this big cleanup Tetsuya.


-- 
David Marchand

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v9 01/12] eal: Fix coding style of eal_pci.c and eal_pci_uio.c
  2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 01/12] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
@ 2015-07-08 16:09                   ` Stephen Hemminger
  2015-07-08 20:30                     ` Thomas Monjalon
  0 siblings, 1 reply; 120+ messages in thread
From: Stephen Hemminger @ 2015-07-08 16:09 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Wed,  8 Jul 2015 19:34:42 +0900
Tetsuya Mukawa <mukawa@igel.co.jp> wrote:

> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
> index 2df5c1c..a63d450 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> @@ -2,6 +2,7 @@
>   *   BSD LICENSE
>   *
>   *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
> + *   Copyright(c) 2015 IGEL Co., Ltd.

I think copyright in file should stay with original author, otherwise
the Copyright will keep growing with all patches.

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v9 01/12] eal: Fix coding style of eal_pci.c and eal_pci_uio.c
  2015-07-08 16:09                   ` Stephen Hemminger
@ 2015-07-08 20:30                     ` Thomas Monjalon
  2015-07-09  1:09                       ` Tetsuya Mukawa
  0 siblings, 1 reply; 120+ messages in thread
From: Thomas Monjalon @ 2015-07-08 20:30 UTC (permalink / raw)
  To: Stephen Hemminger, Tetsuya Mukawa; +Cc: dev

2015-07-08 09:09, Stephen Hemminger:
> On Wed,  8 Jul 2015 19:34:42 +0900
> Tetsuya Mukawa <mukawa@igel.co.jp> wrote:
> 
> > diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
> > index 2df5c1c..a63d450 100644
> > --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> > +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> > @@ -2,6 +2,7 @@
> >   *   BSD LICENSE
> >   *
> >   *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
> > + *   Copyright(c) 2015 IGEL Co., Ltd.
> 
> I think copyright in file should stay with original author, otherwise
> the Copyright will keep growing with all patches.

Yes you're right.
There is no strict rule, but Copyright should be added only in new files
or with a really significant change.

Tetsuya, you have copyright on PMD null and hotplug framework in doc.
Hope you'll agree to not add new ones while doing some EAL cleanup.

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v9 00/12] Clean up pci uio implementations
  2015-07-08 12:36                 ` [dpdk-dev] [PATCH v9 00/12] Clean up pci uio implementations David Marchand
@ 2015-07-08 21:52                   ` Thomas Monjalon
  0 siblings, 0 replies; 120+ messages in thread
From: Thomas Monjalon @ 2015-07-08 21:52 UTC (permalink / raw)
  To: dev, Tetsuya Mukawa

> > Currently Linux implementation and BSD implementation have almost same
> > code about pci uio. This patch series cleans up it.
> >
> > PATCH v9 changes:
> >  - Add lost Acked-by and Tested-by signatures.
> >  - Remove NULL checkings before calling rte_free().
> >  - Fix pci_uio_map_secondary() to remove needless close().
> >  - Remove needless parameter checkings of pci_uio_alloc_resource() and
> >    pci_uio_map_resource_by_index().
> >  - Remove needless error checking for return value of
> > pci_uio_alloc_resource().
> >  - Introduce pci_uio_free_resource().
> >  - Remove some comments of pci_uio_map_resource().
> >    (Thanks to David Marchand)
> >
> Acked-by: David Marchand <david.marchand@6wind.com>

Applied, thanks

The copyright additions were removed because not appropriate in a cleanup.

^ permalink raw reply	[flat|nested] 120+ messages in thread

* Re: [dpdk-dev] [PATCH v9 01/12] eal: Fix coding style of eal_pci.c and eal_pci_uio.c
  2015-07-08 20:30                     ` Thomas Monjalon
@ 2015-07-09  1:09                       ` Tetsuya Mukawa
  0 siblings, 0 replies; 120+ messages in thread
From: Tetsuya Mukawa @ 2015-07-09  1:09 UTC (permalink / raw)
  To: Thomas Monjalon, Stephen Hemminger; +Cc: dev

On 2015/07/09 5:30, Thomas Monjalon wrote:
> 2015-07-08 09:09, Stephen Hemminger:
>> On Wed,  8 Jul 2015 19:34:42 +0900
>> Tetsuya Mukawa <mukawa@igel.co.jp> wrote:
>>
>>> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
>>> index 2df5c1c..a63d450 100644
>>> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
>>> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
>>> @@ -2,6 +2,7 @@
>>>   *   BSD LICENSE
>>>   *
>>>   *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
>>> + *   Copyright(c) 2015 IGEL Co., Ltd.
>> I think copyright in file should stay with original author, otherwise
>> the Copyright will keep growing with all patches.
> Yes you're right.
> There is no strict rule, but Copyright should be added only in new files
> or with a really significant change.
>
> Tetsuya, you have copyright on PMD null and hotplug framework in doc.
> Hope you'll agree to not add new ones while doing some EAL cleanup.

Hi Thomas and Stephen,

Yes, I don't need to add copyrights.
Thanks for fixing to apply.

Regards,
Tetsuya

^ permalink raw reply	[flat|nested] 120+ messages in thread

end of thread, other threads:[~2015-07-09  1:09 UTC | newest]

Thread overview: 120+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-19  5:54 [dpdk-dev] [PATCH v4 0/5] Clean up pci uio implementations Tetsuya Mukawa
2015-05-19  5:54 ` [dpdk-dev] [PATCH v4 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
2015-05-19 14:51   ` Stephen Hemminger
2015-06-25  3:19   ` [dpdk-dev] [PATCH v5 0/5] Clean up pci uio implementations Tetsuya Mukawa
2015-06-25  3:19     ` [dpdk-dev] [PATCH v5 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
2015-06-25  9:16       ` David Marchand
2015-06-25  3:19     ` [dpdk-dev] [PATCH v5 2/5] eal: Close file descriptor of uio configuration Tetsuya Mukawa
2015-06-25  3:19     ` [dpdk-dev] [PATCH v5 3/5] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
2015-06-25  9:16       ` David Marchand
2015-06-26  1:30         ` Tetsuya Mukawa
2015-06-25  9:18       ` David Marchand
2015-06-26  1:35         ` Tetsuya Mukawa
2015-06-26  8:18       ` [dpdk-dev] [PATCH v6 0/5] Clean up pci uio implementations Tetsuya Mukawa
2015-06-26  8:18         ` [dpdk-dev] [PATCH v6 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
2015-06-26 14:30           ` Iremonger, Bernard
2015-06-26  8:18         ` [dpdk-dev] [PATCH v6 2/5] eal: Close file descriptor of uio configuration Tetsuya Mukawa
2015-06-26 14:32           ` Iremonger, Bernard
2015-06-26  8:18         ` [dpdk-dev] [PATCH v6 3/5] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
2015-06-26 14:34           ` Iremonger, Bernard
2015-06-30  8:24           ` [dpdk-dev] [PATCH v7 00/12] Clean up pci uio implementations Tetsuya Mukawa
2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 01/12] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 02/12] eal: Close file descriptor of uio configuration Tetsuya Mukawa
2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 03/12] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
2015-06-30 12:33               ` Iremonger, Bernard
2015-07-02  9:57               ` Bruce Richardson
2015-07-03  8:51                 ` Tetsuya Mukawa
2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 04/12] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
2015-06-30 12:36               ` Iremonger, Bernard
2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 05/12] eal: Fix uio mapping differences between linuxapp and bsdapp Tetsuya Mukawa
2015-06-30 12:51               ` Iremonger, Bernard
2015-07-02 10:20               ` Bruce Richardson
2015-07-03  8:51                 ` Tetsuya Mukawa
2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 06/12] eal: Add pci_uio_alloc_resource() Tetsuya Mukawa
2015-07-02 10:46               ` Bruce Richardson
2015-07-03  8:52                 ` Tetsuya Mukawa
2015-07-03  9:45                   ` Bruce Richardson
2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 07/12] eal: Add pci_uio_map_resource_by_index() Tetsuya Mukawa
2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 08/12] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp Tetsuya Mukawa
2015-06-30 14:25               ` Iremonger, Bernard
2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 09/12] eal: Consolidate pci_map/unmap_resource() " Tetsuya Mukawa
2015-06-30 14:28               ` Iremonger, Bernard
2015-07-02 11:11               ` Bruce Richardson
2015-07-03  8:52                 ` Tetsuya Mukawa
2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 10/12] eal: Consolidate pci uio functions " Tetsuya Mukawa
2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 11/12] eal: Consolidate pci_map/unmap_device() " Tetsuya Mukawa
2015-06-30 14:45               ` Iremonger, Bernard
2015-07-06  6:24               ` [dpdk-dev] [PATCH v8 00/12] Clean up pci uio implementations Tetsuya Mukawa
2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 01/12] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
2015-07-07  8:04                   ` David Marchand
2015-07-08  2:42                     ` Tetsuya Mukawa
2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 02/12] eal: Close file descriptor of uio configuration Tetsuya Mukawa
2015-07-07  8:04                   ` David Marchand
2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 03/12] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
2015-07-07  8:04                   ` David Marchand
2015-07-08  2:42                     ` Tetsuya Mukawa
2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 04/12] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
2015-07-07  8:04                   ` David Marchand
2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 05/12] eal: Fix uio mapping differences between linuxapp and bsdapp Tetsuya Mukawa
2015-07-07  8:04                   ` David Marchand
2015-07-08  2:42                     ` Tetsuya Mukawa
2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 06/12] eal: Add pci_uio_alloc_resource() Tetsuya Mukawa
2015-07-07  8:04                   ` David Marchand
2015-07-08  2:42                     ` Tetsuya Mukawa
2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 07/12] eal: Add pci_uio_map_resource_by_index() Tetsuya Mukawa
2015-07-07  8:05                   ` David Marchand
2015-07-08  2:42                     ` Tetsuya Mukawa
2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 08/12] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp Tetsuya Mukawa
2015-07-07  8:05                   ` David Marchand
2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 09/12] eal: Consolidate pci_map/unmap_resource() " Tetsuya Mukawa
2015-07-07  8:05                   ` David Marchand
2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 10/12] eal: Consolidate pci uio functions " Tetsuya Mukawa
2015-07-07  8:07                   ` David Marchand
2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 11/12] eal: Consolidate pci_map/unmap_device() " Tetsuya Mukawa
2015-07-07  8:06                   ` David Marchand
2015-07-08  2:42                     ` Tetsuya Mukawa
2015-07-08  8:27                       ` Thomas Monjalon
2015-07-08  8:50                         ` Tetsuya Mukawa
2015-07-06  6:24                 ` [dpdk-dev] [PATCH v8 12/12] eal: Consolidate rte_eal_pci_probe/close_one_driver() " Tetsuya Mukawa
2015-07-07  8:07                   ` David Marchand
2015-07-08 10:34               ` [dpdk-dev] [PATCH v9 00/12] Clean up pci uio implementations Tetsuya Mukawa
2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 01/12] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
2015-07-08 16:09                   ` Stephen Hemminger
2015-07-08 20:30                     ` Thomas Monjalon
2015-07-09  1:09                       ` Tetsuya Mukawa
2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 02/12] eal: Close file descriptor of uio configuration Tetsuya Mukawa
2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 03/12] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 04/12] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 05/12] eal: Fix uio mapping differences between linuxapp and bsdapp Tetsuya Mukawa
2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 06/12] eal: Add pci_uio_alloc/free_resource() Tetsuya Mukawa
2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 07/12] eal: Add pci_uio_map_resource_by_index() Tetsuya Mukawa
2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 08/12] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp Tetsuya Mukawa
2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 09/12] eal: Consolidate pci_map/unmap_resource() " Tetsuya Mukawa
2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 10/12] eal: Consolidate pci uio functions " Tetsuya Mukawa
2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 11/12] eal: Consolidate pci_map/unmap_device() " Tetsuya Mukawa
2015-07-08 10:34                 ` [dpdk-dev] [PATCH v9 12/12] eal: Consolidate rte_eal_pci_probe/close_one_driver() " Tetsuya Mukawa
2015-07-08 12:36                 ` [dpdk-dev] [PATCH v9 00/12] Clean up pci uio implementations David Marchand
2015-07-08 21:52                   ` Thomas Monjalon
2015-06-30  8:24             ` [dpdk-dev] [PATCH v7 12/12] eal: Consolidate rte_eal_pci_probe/close_one_driver() of linuxapp and bsdapp Tetsuya Mukawa
2015-06-30 14:56               ` Iremonger, Bernard
2015-07-01  6:39                 ` Tetsuya Mukawa
2015-07-02 11:32             ` [dpdk-dev] [PATCH v7 00/12] Clean up pci uio implementations Bruce Richardson
2015-07-03  8:52               ` Tetsuya Mukawa
2015-06-26  8:18         ` [dpdk-dev] [PATCH v6 4/5] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
2015-06-26 14:36           ` Iremonger, Bernard
2015-06-26  8:18         ` [dpdk-dev] [PATCH v6 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp Tetsuya Mukawa
2015-06-26 14:42           ` Iremonger, Bernard
2015-06-25  3:19     ` [dpdk-dev] [PATCH v5 4/5] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
2015-06-25  9:19       ` David Marchand
2015-06-25  3:19     ` [dpdk-dev] [PATCH v5 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp Tetsuya Mukawa
2015-05-19  5:54 ` [dpdk-dev] [PATCH v4 2/5] eal: Close file descriptor of uio configuration Tetsuya Mukawa
2015-05-19 16:02   ` Stephen Hemminger
2015-05-19  5:54 ` [dpdk-dev] [PATCH v4 3/5] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
2015-06-15 14:29   ` Iremonger, Bernard
2015-06-15 15:05     ` Iremonger, Bernard
2015-05-19  5:54 ` [dpdk-dev] [PATCH v4 4/5] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
2015-05-19  5:54 ` [dpdk-dev] [PATCH v4 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp Tetsuya Mukawa
2015-06-15 14:31   ` Iremonger, Bernard
2015-06-15 15:08     ` Iremonger, Bernard
2015-06-15 15:17       ` Thomas Monjalon
2015-05-19  5:57 ` [dpdk-dev] [PATCH v4 0/5] Clean up pci uio implementations Tetsuya Mukawa

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).