DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 0/8] Add Port Hotplug support to BSD
@ 2015-05-19  6:21 Tetsuya Mukawa
  2015-05-19  6:21 ` [dpdk-dev] [PATCH 1/8] eal: Add pci_uio_alloc_uio_resource() Tetsuya Mukawa
                   ` (8 more replies)
  0 siblings, 9 replies; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-05-19  6:21 UTC (permalink / raw)
  To: dev

This patch series adds port hotplug support to BSD.
Before applying, following patches should be applied.
 - [PATCH v4 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c
 - [PATCH v4 2/5] eal: Close file descriptor of uio configuration
 - [PATCH v4 3/5] eal: Fix memory leaks and needless increment of pci_map_addr
 - [PATCH v4 4/5] eal/bsdapp: Change names of pci related data structure
 - [PATCH v4 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp

Some functions will be consolidated after applying the patches, because
these functions are implemented in both Linux and BSD code.


Tetsuya Mukawa (8):
  eal: Add pci_uio_alloc_uio_resource()
  eal: Add pci_uio_map_uio_resource_by_index()
  eal: Consolidate pci_map and mapped_pci_resource of linuxapp and
    bsdapp
  eal: Consolidate rte_eal_pci_probe/close_one_driver() of linuxapp and
    bsdapp
  eal: Consolidate pci_map/unmap_device() of linuxapp and bsdapp
  eal: Consolidate pci_map/unmap_resource() of linuxapp and bsdapp
  eal: Consolidate pci uio functions of linuxapp and bsdapp
  eal: Enable Port Hotplug as default in Linux and BSD

 config/common_bsdapp                               |   6 -
 config/common_linuxapp                             |   5 -
 lib/librte_eal/bsdapp/eal/Makefile                 |   1 +
 lib/librte_eal/bsdapp/eal/eal_pci.c                | 309 +++++----------------
 .../bsdapp/eal/include/exec-env/rte_interrupts.h   |   1 +
 lib/librte_eal/bsdapp/eal/rte_eal_version.map      |   6 +
 lib/librte_eal/common/eal_common_dev.c             |   2 -
 lib/librte_eal/common/eal_common_pci.c             | 224 ++++++++++++++-
 lib/librte_eal/common/eal_common_pci_uio.c         | 233 ++++++++++++++++
 lib/librte_eal/common/eal_private.h                |  57 +++-
 lib/librte_eal/common/include/rte_pci.h            |  42 ++-
 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          | 265 +++++-------------
 lib/librte_ether/rte_ethdev.c                      |  22 +-
 16 files changed, 691 insertions(+), 758 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_pci_uio.c

-- 
2.1.4

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

* [dpdk-dev] [PATCH 1/8] eal: Add pci_uio_alloc_uio_resource()
  2015-05-19  6:21 [dpdk-dev] [PATCH 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
@ 2015-05-19  6:21 ` Tetsuya Mukawa
  2015-05-19  6:21 ` [dpdk-dev] [PATCH 2/8] eal: Add pci_uio_map_uio_resource_by_index() Tetsuya Mukawa
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-05-19  6:21 UTC (permalink / raw)
  To: dev

This patch adds a new function called pci_uio_alloc_uio_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..2d9f3a5 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_uio_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_uio_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_uio_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 98f4847..022bd7f 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_uio_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_uio_resource(dev, &uio_res);
+	if ((ret != 0) || (uio_res == NULL))
+		return ret;
 
 	/* Map all BARs */
 	maps = uio_res->maps;
@@ -398,7 +430,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_uio_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] 46+ messages in thread

* [dpdk-dev] [PATCH 2/8] eal: Add pci_uio_map_uio_resource_by_index()
  2015-05-19  6:21 [dpdk-dev] [PATCH 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
  2015-05-19  6:21 ` [dpdk-dev] [PATCH 1/8] eal: Add pci_uio_alloc_uio_resource() Tetsuya Mukawa
@ 2015-05-19  6:21 ` Tetsuya Mukawa
  2015-05-19  6:21 ` [dpdk-dev] [PATCH 3/8] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp Tetsuya Mukawa
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-05-19  6:21 UTC (permalink / raw)
  To: dev

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 2d9f3a5..61d1fe5 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;
 }
 
-/* map the PCI resource of a PCI device in virtual memory */
 static int
-pci_uio_map_resource(struct rte_pci_device *dev)
+pci_uio_map_uio_resource_by_index(struct rte_pci_device *dev, int res_idx,
+		struct mapped_pci_resource *uio_res, int map_idx)
 {
-	int i, map_idx, ret;
+	int fd;
 	char *devname;
 	void *mapaddr;
-	uint64_t phaddr;
 	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;
+	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);
-	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));
-			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);
+		ret = pci_uio_map_uio_resource_by_index(dev, i,
+				uio_res, map_idx);
+		if (ret != 0)
 			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_uio_resource() */
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 022bd7f..23c0830 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_uio_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_uio_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;
@@ -428,7 +446,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_uio_resource() */
-- 
2.1.4

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

* [dpdk-dev] [PATCH 3/8] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp
  2015-05-19  6:21 [dpdk-dev] [PATCH 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
  2015-05-19  6:21 ` [dpdk-dev] [PATCH 1/8] eal: Add pci_uio_alloc_uio_resource() Tetsuya Mukawa
  2015-05-19  6:21 ` [dpdk-dev] [PATCH 2/8] eal: Add pci_uio_map_uio_resource_by_index() Tetsuya Mukawa
@ 2015-05-19  6:21 ` Tetsuya Mukawa
  2015-05-19  6:21 ` [dpdk-dev] [PATCH 4/8] eal: Consolidate rte_eal_pci_probe/close_one_driver() " Tetsuya Mukawa
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-05-19  6:21 UTC (permalink / raw)
  To: dev

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 61d1fe5..c7017eb 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 223d3cd..6eb343f 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -219,6 +219,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] 46+ messages in thread

* [dpdk-dev] [PATCH 4/8] eal: Consolidate rte_eal_pci_probe/close_one_driver() of linuxapp and bsdapp
  2015-05-19  6:21 [dpdk-dev] [PATCH 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
                   ` (2 preceding siblings ...)
  2015-05-19  6:21 ` [dpdk-dev] [PATCH 3/8] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp Tetsuya Mukawa
@ 2015-05-19  6:21 ` Tetsuya Mukawa
  2015-06-26  8:21   ` [dpdk-dev] [PATCH v2 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
  2015-06-29  2:56   ` [dpdk-dev] [PATCH v3 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
  2015-05-19  6:21 ` [dpdk-dev] [PATCH 5/8] eal: Consolidate pci_map/unmap_device() of linuxapp and bsdapp Tetsuya Mukawa
                   ` (4 subsequent siblings)
  8 siblings, 2 replies; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-05-19  6:21 UTC (permalink / raw)
  To: dev

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    |  74 ++---------------
 lib/librte_eal/common/eal_common_pci.c | 129 ++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_private.h    |  21 ++---
 lib/librte_eal/linuxapp/eal/eal_pci.c  | 148 ++-------------------------------
 4 files changed, 153 insertions(+), 219 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index c7017eb..2a623e3 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -88,7 +88,7 @@ static struct rte_tailq_elem rte_uio_tailq = {
 EAL_REGISTER_TAILQ(rte_uio_tailq)
 
 /* 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 "
@@ -430,6 +430,13 @@ skipdev:
 	return 0;
 }
 
+/* Map pci device */
+int
+pci_map_device(struct rte_pci_device *dev)
+{
+	return pci_uio_map_resource(dev);
+}
+
 /*
  * Scan the content of the PCI bus, and add the devices in the devices
  * list. Call pci_scan_one() for each pci entry found.
@@ -480,71 +487,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 4229aaf..6eb6257 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -99,6 +99,135 @@ static struct rte_devargs *pci_devargs_lookup(struct rte_pci_device *dev)
 }
 
 /*
+ * 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 4acf5a0..fe2c596 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -154,30 +154,31 @@ struct rte_pci_driver;
 struct rte_pci_device;
 
 /**
- * Mmap memory for single PCI device
+ * Unbind kernel driver for this 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);
+int pci_unbind_kernel_driver(struct rte_pci_device *dev);
 
 /**
- * Munmap memory for single PCI device
+ * Map this 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);
+int pci_map_device(struct rte_pci_device *dev);
+
+/**
+ * Unmap this device
+ *
+ * This function is private to EAL.
+ */
+void pci_unmap_device(struct rte_pci_device *dev);
 
 /**
  * Init tail queues for non-EAL library structures. This is to allow
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index d2adc66..91e958e 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -57,7 +57,7 @@
  */
 
 /* unbind kernel driver for this device */
-static int
+int
 pci_unbind_kernel_driver(struct rte_pci_device *dev)
 {
 	int n;
@@ -563,7 +563,8 @@ pci_config_space_set(struct rte_pci_device *dev)
 }
 #endif
 
-static int
+/* Map pci device */
+int
 pci_map_device(struct rte_pci_device *dev)
 {
 	int ret = -1;
@@ -592,7 +593,8 @@ pci_map_device(struct rte_pci_device *dev)
 }
 
 #ifdef RTE_LIBRTE_EAL_HOTPLUG
-static void
+/* Unmap pci device */
+void
 pci_unmap_device(struct rte_pci_device *dev)
 {
 	if (dev == NULL)
@@ -616,146 +618,6 @@ 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.
- */
-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] 46+ messages in thread

* [dpdk-dev] [PATCH 5/8] eal: Consolidate pci_map/unmap_device() of linuxapp and bsdapp
  2015-05-19  6:21 [dpdk-dev] [PATCH 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
                   ` (3 preceding siblings ...)
  2015-05-19  6:21 ` [dpdk-dev] [PATCH 4/8] eal: Consolidate rte_eal_pci_probe/close_one_driver() " Tetsuya Mukawa
@ 2015-05-19  6:21 ` Tetsuya Mukawa
  2015-05-19  6:21 ` [dpdk-dev] [PATCH 6/8] eal: Consolidate pci_map/unmap_resource() " Tetsuya Mukawa
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-05-19  6:21 UTC (permalink / raw)
  To: dev

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     | 12 +++----
 lib/librte_eal/common/eal_common_pci.c  | 57 +++++++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_private.h     |  4 +--
 lib/librte_eal/common/include/rte_pci.h |  1 +
 lib/librte_eal/linuxapp/eal/eal_pci.c   | 55 -------------------------------
 lib/librte_ether/rte_ethdev.c           |  1 +
 6 files changed, 65 insertions(+), 65 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 2a623e3..56dc98c 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -275,7 +275,7 @@ fail:
 }
 
 /* map the PCI resource of a PCI device in virtual memory */
-static int
+int
 pci_uio_map_resource(struct rte_pci_device *dev)
 {
 	int i, map_idx, ret;
@@ -366,6 +366,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:
@@ -430,13 +433,6 @@ skipdev:
 	return 0;
 }
 
-/* Map pci device */
-int
-pci_map_device(struct rte_pci_device *dev)
-{
-	return pci_uio_map_resource(dev);
-}
-
 /*
  * Scan the content of the PCI bus, and add the devices in the devices
  * list. Call pci_scan_one() for each pci entry found.
diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 6eb6257..00547d9 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -98,6 +98,63 @@ static struct rte_devargs *pci_devargs_lookup(struct rte_pci_device *dev)
 	return NULL;
 }
 
+/* Map pci device */
+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:
+	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 */
+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:
+	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 the
  * driver.
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index fe2c596..badb55c 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -171,14 +171,14 @@ int pci_unbind_kernel_driver(struct rte_pci_device *dev);
  * @return
  *   0 on success, negative on error
  */
-int pci_map_device(struct rte_pci_device *dev);
+int pci_uio_map_resource(struct rte_pci_device *dev);
 
 /**
  * Unmap this device
  *
  * This function is private to EAL.
  */
-void pci_unmap_device(struct rte_pci_device *dev);
+void pci_uio_unmap_resource(struct rte_pci_device *dev);
 
 /**
  * Init tail queues for non-EAL library structures. This is to allow
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index 6eb343f..2dea298 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -147,6 +147,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 91e958e..5c30469 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -563,61 +563,6 @@ pci_config_space_set(struct rte_pci_device *dev)
 }
 #endif
 
-/* 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:
-		/* 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:
-		/* 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 */
-
 /* Init the PCI EAL subsystem */
 int
 rte_eal_pci_init(void)
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 024fe8b..3c38d09 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] 46+ messages in thread

* [dpdk-dev] [PATCH 6/8] eal: Consolidate pci_map/unmap_resource() of linuxapp and bsdapp
  2015-05-19  6:21 [dpdk-dev] [PATCH 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
                   ` (4 preceding siblings ...)
  2015-05-19  6:21 ` [dpdk-dev] [PATCH 5/8] eal: Consolidate pci_map/unmap_device() of linuxapp and bsdapp Tetsuya Mukawa
@ 2015-05-19  6:21 ` Tetsuya Mukawa
  2015-05-19  6:21 ` [dpdk-dev] [PATCH 7/8] eal: Consolidate pci uio functions " Tetsuya Mukawa
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-05-19  6:21 UTC (permalink / raw)
  To: dev

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     | 42 ++++++++++++++++++++++++++++++
 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, 53 insertions(+), 68 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 56dc98c..92a9fcf 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 00547d9..30ece44 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,47 @@ 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;
+}
+
+#ifdef RTE_LIBRTE_EAL_HOTPLUG
+/* 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);
+}
+#endif /* RTE_LIBRTE_EAL_HOTPLUG */
+
 /* Map pci device */
 static int
 pci_map_device(struct rte_pci_device *dev)
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index 2dea298..2ad3452 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -364,8 +364,19 @@ 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);
+
 #ifdef RTE_LIBRTE_EAL_HOTPLUG
 /**
+ * Map pci resouce.
+ */
+void pci_unmap_resource(void *requested_addr, size_t size);
+
+/**
  * Probe the single PCI device.
  *
  * Scan the content of the PCI bus, and find the pci device specified by pci
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index 5c30469..1d5a13b 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] 46+ messages in thread

* [dpdk-dev] [PATCH 7/8] eal: Consolidate pci uio functions of linuxapp and bsdapp
  2015-05-19  6:21 [dpdk-dev] [PATCH 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
                   ` (5 preceding siblings ...)
  2015-05-19  6:21 ` [dpdk-dev] [PATCH 6/8] eal: Consolidate pci_map/unmap_resource() " Tetsuya Mukawa
@ 2015-05-19  6:21 ` Tetsuya Mukawa
  2015-05-19  6:21 ` [dpdk-dev] [PATCH 8/8] eal: Enable Port Hotplug as default in Linux and BSD Tetsuya Mukawa
  2015-05-19 16:03 ` [dpdk-dev] [PATCH 0/8] Add Port Hotplug support to BSD Stephen Hemminger
  8 siblings, 0 replies; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-05-19  6:21 UTC (permalink / raw)
  To: dev

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         | 235 +++++++++++++++++++++
 lib/librte_eal/common/eal_private.h                |  36 ++++
 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          | 192 +----------------
 8 files changed, 282 insertions(+), 305 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 2357cfa..1dec11e 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 92a9fcf..0103e2b 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 */
 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_uio_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_uio_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 */
-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_uio_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_uio_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_uio_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..32d3f57
--- /dev/null
+++ b/lib/librte_eal/common/eal_common_pci_uio.c
@@ -0,0 +1,235 @@
+/*-
+ *   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_uio_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_uio_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_uio_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 badb55c..8c4145a 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).
@@ -181,6 +182,41 @@ int pci_uio_map_resource(struct rte_pci_device *dev);
 void pci_uio_unmap_resource(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_uio_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_uio_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 01f7b70..7fb2f2f 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..90409b3 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_uio_resource(struct rte_pci_device *dev,
+		struct mapped_pci_resource **uio_res);
+int pci_uio_map_uio_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 23c0830..9b339cf 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_uio_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_uio_resource_by_index(struct rte_pci_device *dev, int res_idx,
 		struct mapped_pci_resource *uio_res, int map_idx)
 {
@@ -400,139 +348,3 @@ fail:
 	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_uio_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_uio_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_uio_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] 46+ messages in thread

* [dpdk-dev] [PATCH 8/8] eal: Enable Port Hotplug as default in Linux and BSD
  2015-05-19  6:21 [dpdk-dev] [PATCH 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
                   ` (6 preceding siblings ...)
  2015-05-19  6:21 ` [dpdk-dev] [PATCH 7/8] eal: Consolidate pci uio functions " Tetsuya Mukawa
@ 2015-05-19  6:21 ` Tetsuya Mukawa
  2015-05-19 16:03 ` [dpdk-dev] [PATCH 0/8] Add Port Hotplug support to BSD Stephen Hemminger
  8 siblings, 0 replies; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-05-19  6:21 UTC (permalink / raw)
  To: dev

This patch removes CONFIG_RTE_LIBRTE_EAL_HOTPLUG option, and enables it
as default in both Linux and BSD.
Also, to support port hotplug, rte_eal_pci_scan() and below missing
symbols should be exported to ethdev library.
 - rte_eal_parse_devargs_str()
 - rte_eal_pci_close_one()
 - rte_eal_pci_probe_one()
 - rte_eal_pci_scan()
 - rte_eal_vdev_init()
 - rte_eal_vdev_uninit()

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 config/common_bsdapp                          |  6 ------
 config/common_linuxapp                        |  5 -----
 lib/librte_eal/bsdapp/eal/eal_pci.c           |  6 +++---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map |  6 ++++++
 lib/librte_eal/common/eal_common_dev.c        |  2 --
 lib/librte_eal/common/eal_common_pci.c        |  8 --------
 lib/librte_eal/common/eal_common_pci_uio.c    |  2 --
 lib/librte_eal/common/include/rte_pci.h       |  2 --
 lib/librte_ether/rte_ethdev.c                 | 21 ---------------------
 9 files changed, 9 insertions(+), 49 deletions(-)

diff --git a/config/common_bsdapp b/config/common_bsdapp
index c2374c0..a53bd7b 100644
--- a/config/common_bsdapp
+++ b/config/common_bsdapp
@@ -116,12 +116,6 @@ CONFIG_RTE_LIBRTE_EAL_BSDAPP=y
 CONFIG_RTE_LIBRTE_EAL_LINUXAPP=n
 
 #
-# Compile Environment Abstraction Layer to support hotplug
-# So far, Hotplug functions only support linux
-#
-CONFIG_RTE_LIBRTE_EAL_HOTPLUG=n
-
-#
 # Compile Environment Abstraction Layer to support Vmware TSC map
 #
 CONFIG_RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT=y
diff --git a/config/common_linuxapp b/config/common_linuxapp
index 0078dc9..b670a34 100644
--- a/config/common_linuxapp
+++ b/config/common_linuxapp
@@ -114,11 +114,6 @@ CONFIG_RTE_PCI_MAX_READ_REQUEST_SIZE=0
 CONFIG_RTE_LIBRTE_EAL_LINUXAPP=y
 
 #
-# Compile Environment Abstraction Layer to support hotplug
-#
-CONFIG_RTE_LIBRTE_EAL_HOTPLUG=y
-
-#
 # Compile Environment Abstraction Layer to support Vmware TSC map
 #
 CONFIG_RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT=y
diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 0103e2b..163e008 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -309,8 +309,8 @@ skipdev:
  * Scan the content of the PCI bus, and add the devices in the devices
  * list. Call pci_scan_one() for each pci entry found.
  */
-static int
-pci_scan(void)
+int
+rte_eal_pci_scan(void)
 {
 	int fd;
 	unsigned dev_count = 0;
@@ -366,7 +366,7 @@ rte_eal_pci_init(void)
 	if (internal_config.no_pci)
 		return 0;
 
-	if (pci_scan() < 0) {
+	if (rte_eal_pci_scan() < 0) {
 		RTE_LOG(ERR, EAL, "%s(): Cannot scan PCI bus\n", __func__);
 		return -1;
 	}
diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 67b6a6c..7e850a9 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -37,14 +37,20 @@ DPDK_2.0 {
 	rte_eal_lcore_role;
 	rte_eal_mp_remote_launch;
 	rte_eal_mp_wait_lcore;
+	rte_eal_parse_devargs_str;
+	rte_eal_pci_close_one;
 	rte_eal_pci_dump;
 	rte_eal_pci_probe;
+	rte_eal_pci_probe_one;
 	rte_eal_pci_register;
+	rte_eal_pci_scan;
 	rte_eal_pci_unregister;
 	rte_eal_process_type;
 	rte_eal_remote_launch;
 	rte_eal_tailq_lookup;
 	rte_eal_tailq_register;
+	rte_eal_vdev_init;
+	rte_eal_vdev_uninit;
 	rte_eal_wait_lcore;
 	rte_exit;
 	rte_get_hpet_cycles;
diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 92a5a94..4089d66 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -125,7 +125,6 @@ rte_eal_dev_init(void)
 	return 0;
 }
 
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
 int
 rte_eal_vdev_uninit(const char *name)
 {
@@ -151,4 +150,3 @@ rte_eal_vdev_uninit(const char *name)
 	RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
 	return -EINVAL;
 }
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 30ece44..c55112b 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -121,7 +121,6 @@ pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
 	return mapaddr;
 }
 
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
 /* unmap a particular resource */
 void
 pci_unmap_resource(void *requested_addr, size_t size)
@@ -138,7 +137,6 @@ pci_unmap_resource(void *requested_addr, size_t size)
 		RTE_LOG(DEBUG, EAL, "  PCI memory unmapped at %p\n",
 				requested_addr);
 }
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
 
 /* Map pci device */
 static int
@@ -170,7 +168,6 @@ pci_map_device(struct rte_pci_device *dev)
 	return ret;
 }
 
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
 /* Unmap pci device */
 static void
 pci_unmap_device(struct rte_pci_device *dev)
@@ -195,7 +192,6 @@ pci_unmap_device(struct rte_pci_device *dev)
 		break;
 	}
 }
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
 
 /*
  * If vendor/device ID match, call the devinit() function of the
@@ -268,7 +264,6 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *d
 	return 1;
 }
 
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
 /*
  * If vendor/device ID match, call the devuninit() function of the
  * driver.
@@ -324,7 +319,6 @@ rte_eal_pci_close_one_driver(struct rte_pci_driver *dr,
 	/* 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
@@ -353,7 +347,6 @@ pci_probe_all_drivers(struct rte_pci_device *dev)
 	return 1;
 }
 
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
 /*
  * If vendor/device ID match, call the devuninit() function of all
  * registered driver for the given device. Return -1 if initialization
@@ -444,7 +437,6 @@ err_return:
 			dev->addr.devid, dev->addr.function);
 	return -1;
 }
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
 
 /*
  * Scan the content of the PCI bus, and call the devinit() function for
diff --git a/lib/librte_eal/common/eal_common_pci_uio.c b/lib/librte_eal/common/eal_common_pci_uio.c
index 32d3f57..06470f0 100644
--- a/lib/librte_eal/common/eal_common_pci_uio.c
+++ b/lib/librte_eal/common/eal_common_pci_uio.c
@@ -159,7 +159,6 @@ free_uio_res:
 	return -1;
 }
 
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
 static void
 pci_uio_unmap(struct mapped_pci_resource *uio_res)
 {
@@ -232,4 +231,3 @@ pci_uio_unmap_resource(struct rte_pci_device *dev)
 	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/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index 2ad3452..a999d3e 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -370,7 +370,6 @@ int rte_eal_pci_probe(void);
 void *pci_map_resource(void *requested_addr, int fd, off_t offset,
 		size_t size, int additional_flags);
 
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
 /**
  * Map pci resouce.
  */
@@ -405,7 +404,6 @@ int rte_eal_pci_probe_one(const struct rte_pci_addr *addr);
  *   - Negative on error.
  */
 int rte_eal_pci_close_one(const struct rte_pci_addr *addr);
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
 
 /**
  * Dump the content of the PCI bus.
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 3c38d09..31c738f 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -425,9 +425,6 @@ rte_eth_dev_count(void)
 	return nb_ports;
 }
 
-/* So far, DPDK hotplug function only supports linux */
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
-
 static enum rte_eth_dev_type
 rte_eth_dev_get_device_type(uint8_t port_id)
 {
@@ -708,24 +705,6 @@ rte_eth_dev_detach(uint8_t port_id, char *name)
 	} else
 		return rte_eth_dev_detach_vdev(port_id, name);
 }
-#else /* RTE_LIBRTE_EAL_HOTPLUG */
-int
-rte_eth_dev_attach(const char *devargs __rte_unused,
-			uint8_t *port_id __rte_unused)
-{
-	RTE_LOG(ERR, EAL, "Hotplug support isn't enabled\n");
-	return -1;
-}
-
-/* detach the device, then store the name of the device */
-int
-rte_eth_dev_detach(uint8_t port_id __rte_unused,
-			char *name __rte_unused)
-{
-	RTE_LOG(ERR, EAL, "Hotplug support isn't enabled\n");
-	return -1;
-}
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
 
 static int
 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
-- 
2.1.4

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

* Re: [dpdk-dev] [PATCH 0/8] Add Port Hotplug support to BSD
  2015-05-19  6:21 [dpdk-dev] [PATCH 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
                   ` (7 preceding siblings ...)
  2015-05-19  6:21 ` [dpdk-dev] [PATCH 8/8] eal: Enable Port Hotplug as default in Linux and BSD Tetsuya Mukawa
@ 2015-05-19 16:03 ` Stephen Hemminger
  8 siblings, 0 replies; 46+ messages in thread
From: Stephen Hemminger @ 2015-05-19 16:03 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Tue, 19 May 2015 15:21:45 +0900
Tetsuya Mukawa <mukawa@igel.co.jp> wrote:

> This patch series adds port hotplug support to BSD.
> Before applying, following patches should be applied.
>  - [PATCH v4 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c
>  - [PATCH v4 2/5] eal: Close file descriptor of uio configuration
>  - [PATCH v4 3/5] eal: Fix memory leaks and needless increment of pci_map_addr
>  - [PATCH v4 4/5] eal/bsdapp: Change names of pci related data structure
>  - [PATCH v4 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp
> 
> Some functions will be consolidated after applying the patches, because
> these functions are implemented in both Linux and BSD code.
> 
> 
> Tetsuya Mukawa (8):
>   eal: Add pci_uio_alloc_uio_resource()
>   eal: Add pci_uio_map_uio_resource_by_index()
>   eal: Consolidate pci_map and mapped_pci_resource of linuxapp and
>     bsdapp
>   eal: Consolidate rte_eal_pci_probe/close_one_driver() of linuxapp and
>     bsdapp
>   eal: Consolidate pci_map/unmap_device() of linuxapp and bsdapp
>   eal: Consolidate pci_map/unmap_resource() of linuxapp and bsdapp
>   eal: Consolidate pci uio functions of linuxapp and bsdapp
>   eal: Enable Port Hotplug as default in Linux and BSD
> 
>  config/common_bsdapp                               |   6 -
>  config/common_linuxapp                             |   5 -
>  lib/librte_eal/bsdapp/eal/Makefile                 |   1 +
>  lib/librte_eal/bsdapp/eal/eal_pci.c                | 309 +++++----------------
>  .../bsdapp/eal/include/exec-env/rte_interrupts.h   |   1 +
>  lib/librte_eal/bsdapp/eal/rte_eal_version.map      |   6 +
>  lib/librte_eal/common/eal_common_dev.c             |   2 -
>  lib/librte_eal/common/eal_common_pci.c             | 224 ++++++++++++++-
>  lib/librte_eal/common/eal_common_pci_uio.c         | 233 ++++++++++++++++
>  lib/librte_eal/common/eal_private.h                |  57 +++-
>  lib/librte_eal/common/include/rte_pci.h            |  42 ++-
>  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          | 265 +++++-------------
>  lib/librte_ether/rte_ethdev.c                      |  22 +-
>  16 files changed, 691 insertions(+), 758 deletions(-)
>  create mode 100644 lib/librte_eal/common/eal_common_pci_uio.c
> 

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

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

* [dpdk-dev] [PATCH v2 0/8] Add Port Hotplug support to BSD
  2015-05-19  6:21 ` [dpdk-dev] [PATCH 4/8] eal: Consolidate rte_eal_pci_probe/close_one_driver() " Tetsuya Mukawa
@ 2015-06-26  8:21   ` Tetsuya Mukawa
  2015-06-26  8:21     ` [dpdk-dev] [PATCH v2 1/8] eal: Add pci_uio_alloc_uio_resource() Tetsuya Mukawa
                       ` (7 more replies)
  2015-06-29  2:56   ` [dpdk-dev] [PATCH v3 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
  1 sibling, 8 replies; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-06-26  8:21 UTC (permalink / raw)
  To: dev

This patch series adds port hotplug support to BSD.
Before applying, following patches should be applied.
 - [PATCH v6 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c
 - [PATCH v6 2/5] eal: Close file descriptor of uio configuration
 - [PATCH v6 3/5] eal: Fix memory leaks and needless increment of pci_map_addr
 - [PATCH v6 4/5] eal/bsdapp: Change names of pci related data structure
 - [PATCH v6 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp

Some functions will be consolidated after applying the patches, because
these functions are implemented in both Linux and BSD code.

PATCH v1 changes:
 - Rebase to below latest patch series.
   - [PATCH v6] Clean up pci uio implementations


Tetsuya.Mukawa (8):
  eal: Add pci_uio_alloc_uio_resource()
  eal: Add pci_uio_map_uio_resource_by_index()
  eal: Consolidate pci_map and mapped_pci_resource of linuxapp and
    bsdapp
  eal: Consolidate rte_eal_pci_probe/close_one_driver() of linuxapp and
    bsdapp
  eal: Consolidate pci_map/unmap_device() of linuxapp and bsdapp
  eal: Consolidate pci_map/unmap_resource() of linuxapp and bsdapp
  eal: Consolidate pci uio functions of linuxapp and bsdapp
  eal: Enable Port Hotplug as default in Linux and BSD

 config/common_bsdapp                               |   6 -
 config/common_linuxapp                             |   5 -
 lib/librte_eal/bsdapp/eal/Makefile                 |   1 +
 lib/librte_eal/bsdapp/eal/eal_pci.c                | 321 +++++----------------
 .../bsdapp/eal/include/exec-env/rte_interrupts.h   |   1 +
 lib/librte_eal/bsdapp/eal/rte_eal_version.map      |   6 +
 lib/librte_eal/common/eal_common_dev.c             |   2 -
 lib/librte_eal/common/eal_common_pci.c             | 224 +++++++++++++-
 lib/librte_eal/common/eal_common_pci_uio.c         | 236 +++++++++++++++
 lib/librte_eal/common/eal_private.h                |  57 +++-
 lib/librte_eal/common/include/rte_pci.h            |  42 ++-
 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          | 271 +++++------------
 lib/librte_ether/rte_ethdev.c                      |  22 +-
 16 files changed, 701 insertions(+), 769 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_pci_uio.c

-- 
2.1.4

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

* [dpdk-dev] [PATCH v2 1/8] eal: Add pci_uio_alloc_uio_resource()
  2015-06-26  8:21   ` [dpdk-dev] [PATCH v2 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
@ 2015-06-26  8:21     ` Tetsuya Mukawa
  2015-06-26  8:21     ` [dpdk-dev] [PATCH v2 2/8] eal: Add pci_uio_map_uio_resource_by_index() Tetsuya Mukawa
                       ` (6 subsequent siblings)
  7 siblings, 0 replies; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-06-26  8:21 UTC (permalink / raw)
  To: dev

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

This patch adds a new function called pci_uio_alloc_uio_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..2d9f3a5 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_uio_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_uio_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_uio_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..9e0b617 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_uio_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_uio_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_uio_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] 46+ messages in thread

* [dpdk-dev] [PATCH v2 2/8] eal: Add pci_uio_map_uio_resource_by_index()
  2015-06-26  8:21   ` [dpdk-dev] [PATCH v2 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
  2015-06-26  8:21     ` [dpdk-dev] [PATCH v2 1/8] eal: Add pci_uio_alloc_uio_resource() Tetsuya Mukawa
@ 2015-06-26  8:21     ` Tetsuya Mukawa
  2015-06-26  8:21     ` [dpdk-dev] [PATCH v2 3/8] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp Tetsuya Mukawa
                       ` (5 subsequent siblings)
  7 siblings, 0 replies; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-06-26  8:21 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 2d9f3a5..61d1fe5 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_uio_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_uio_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_uio_resource() */
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 9e0b617..7da4543 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_uio_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_uio_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] 46+ messages in thread

* [dpdk-dev] [PATCH v2 3/8] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp
  2015-06-26  8:21   ` [dpdk-dev] [PATCH v2 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
  2015-06-26  8:21     ` [dpdk-dev] [PATCH v2 1/8] eal: Add pci_uio_alloc_uio_resource() Tetsuya Mukawa
  2015-06-26  8:21     ` [dpdk-dev] [PATCH v2 2/8] eal: Add pci_uio_map_uio_resource_by_index() Tetsuya Mukawa
@ 2015-06-26  8:21     ` Tetsuya Mukawa
  2015-06-26  8:21     ` [dpdk-dev] [PATCH v2 4/8] eal: Consolidate rte_eal_pci_probe/close_one_driver() " Tetsuya Mukawa
                       ` (4 subsequent siblings)
  7 siblings, 0 replies; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-06-26  8:21 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 61d1fe5..c7017eb 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] 46+ messages in thread

* [dpdk-dev] [PATCH v2 4/8] eal: Consolidate rte_eal_pci_probe/close_one_driver() of linuxapp and bsdapp
  2015-06-26  8:21   ` [dpdk-dev] [PATCH v2 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
                       ` (2 preceding siblings ...)
  2015-06-26  8:21     ` [dpdk-dev] [PATCH v2 3/8] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp Tetsuya Mukawa
@ 2015-06-26  8:21     ` Tetsuya Mukawa
  2015-06-26  8:21     ` [dpdk-dev] [PATCH v2 5/8] eal: Consolidate pci_map/unmap_device() " Tetsuya Mukawa
                       ` (3 subsequent siblings)
  7 siblings, 0 replies; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-06-26  8:21 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    |  74 ++---------------
 lib/librte_eal/common/eal_common_pci.c | 129 ++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_private.h    |  21 ++---
 lib/librte_eal/linuxapp/eal/eal_pci.c  | 148 ++-------------------------------
 4 files changed, 153 insertions(+), 219 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index c7017eb..2a623e3 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -88,7 +88,7 @@ static struct rte_tailq_elem rte_uio_tailq = {
 EAL_REGISTER_TAILQ(rte_uio_tailq)
 
 /* 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 "
@@ -430,6 +430,13 @@ skipdev:
 	return 0;
 }
 
+/* Map pci device */
+int
+pci_map_device(struct rte_pci_device *dev)
+{
+	return pci_uio_map_resource(dev);
+}
+
 /*
  * Scan the content of the PCI bus, and add the devices in the devices
  * list. Call pci_scan_one() for each pci entry found.
@@ -480,71 +487,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 4229aaf..6eb6257 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -99,6 +99,135 @@ static struct rte_devargs *pci_devargs_lookup(struct rte_pci_device *dev)
 }
 
 /*
+ * 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 4acf5a0..fe2c596 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -154,30 +154,31 @@ struct rte_pci_driver;
 struct rte_pci_device;
 
 /**
- * Mmap memory for single PCI device
+ * Unbind kernel driver for this 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);
+int pci_unbind_kernel_driver(struct rte_pci_device *dev);
 
 /**
- * Munmap memory for single PCI device
+ * Map this 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);
+int pci_map_device(struct rte_pci_device *dev);
+
+/**
+ * Unmap this device
+ *
+ * This function is private to EAL.
+ */
+void pci_unmap_device(struct rte_pci_device *dev);
 
 /**
  * Init tail queues for non-EAL library structures. This is to allow
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index d2adc66..91e958e 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -57,7 +57,7 @@
  */
 
 /* unbind kernel driver for this device */
-static int
+int
 pci_unbind_kernel_driver(struct rte_pci_device *dev)
 {
 	int n;
@@ -563,7 +563,8 @@ pci_config_space_set(struct rte_pci_device *dev)
 }
 #endif
 
-static int
+/* Map pci device */
+int
 pci_map_device(struct rte_pci_device *dev)
 {
 	int ret = -1;
@@ -592,7 +593,8 @@ pci_map_device(struct rte_pci_device *dev)
 }
 
 #ifdef RTE_LIBRTE_EAL_HOTPLUG
-static void
+/* Unmap pci device */
+void
 pci_unmap_device(struct rte_pci_device *dev)
 {
 	if (dev == NULL)
@@ -616,146 +618,6 @@ 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.
- */
-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] 46+ messages in thread

* [dpdk-dev] [PATCH v2 5/8] eal: Consolidate pci_map/unmap_device() of linuxapp and bsdapp
  2015-06-26  8:21   ` [dpdk-dev] [PATCH v2 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
                       ` (3 preceding siblings ...)
  2015-06-26  8:21     ` [dpdk-dev] [PATCH v2 4/8] eal: Consolidate rte_eal_pci_probe/close_one_driver() " Tetsuya Mukawa
@ 2015-06-26  8:21     ` Tetsuya Mukawa
  2015-06-26  8:21     ` [dpdk-dev] [PATCH v2 6/8] eal: Consolidate pci_map/unmap_resource() " Tetsuya Mukawa
                       ` (2 subsequent siblings)
  7 siblings, 0 replies; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-06-26  8:21 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     | 12 +++----
 lib/librte_eal/common/eal_common_pci.c  | 57 +++++++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_private.h     |  4 +--
 lib/librte_eal/common/include/rte_pci.h |  1 +
 lib/librte_eal/linuxapp/eal/eal_pci.c   | 55 -------------------------------
 lib/librte_ether/rte_ethdev.c           |  1 +
 6 files changed, 65 insertions(+), 65 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 2a623e3..56dc98c 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -275,7 +275,7 @@ fail:
 }
 
 /* map the PCI resource of a PCI device in virtual memory */
-static int
+int
 pci_uio_map_resource(struct rte_pci_device *dev)
 {
 	int i, map_idx, ret;
@@ -366,6 +366,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:
@@ -430,13 +433,6 @@ skipdev:
 	return 0;
 }
 
-/* Map pci device */
-int
-pci_map_device(struct rte_pci_device *dev)
-{
-	return pci_uio_map_resource(dev);
-}
-
 /*
  * Scan the content of the PCI bus, and add the devices in the devices
  * list. Call pci_scan_one() for each pci entry found.
diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 6eb6257..00547d9 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -98,6 +98,63 @@ static struct rte_devargs *pci_devargs_lookup(struct rte_pci_device *dev)
 	return NULL;
 }
 
+/* Map pci device */
+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:
+	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 */
+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:
+	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 the
  * driver.
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index fe2c596..badb55c 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -171,14 +171,14 @@ int pci_unbind_kernel_driver(struct rte_pci_device *dev);
  * @return
  *   0 on success, negative on error
  */
-int pci_map_device(struct rte_pci_device *dev);
+int pci_uio_map_resource(struct rte_pci_device *dev);
 
 /**
  * Unmap this device
  *
  * This function is private to EAL.
  */
-void pci_unmap_device(struct rte_pci_device *dev);
+void pci_uio_unmap_resource(struct rte_pci_device *dev);
 
 /**
  * Init tail queues for non-EAL library structures. This is to allow
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index 0a2ef09..bd1ef4e 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 91e958e..5c30469 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -563,61 +563,6 @@ pci_config_space_set(struct rte_pci_device *dev)
 }
 #endif
 
-/* 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:
-		/* 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:
-		/* 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 */
-
 /* Init the PCI EAL subsystem */
 int
 rte_eal_pci_init(void)
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] 46+ messages in thread

* [dpdk-dev] [PATCH v2 6/8] eal: Consolidate pci_map/unmap_resource() of linuxapp and bsdapp
  2015-06-26  8:21   ` [dpdk-dev] [PATCH v2 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
                       ` (4 preceding siblings ...)
  2015-06-26  8:21     ` [dpdk-dev] [PATCH v2 5/8] eal: Consolidate pci_map/unmap_device() " Tetsuya Mukawa
@ 2015-06-26  8:21     ` Tetsuya Mukawa
  2015-06-26  8:21     ` [dpdk-dev] [PATCH v2 7/8] eal: Consolidate pci uio functions " Tetsuya Mukawa
  2015-06-26  8:21     ` [dpdk-dev] [PATCH v2 8/8] eal: Enable Port Hotplug as default in Linux and BSD Tetsuya Mukawa
  7 siblings, 0 replies; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-06-26  8:21 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    | 11 ++++++++
 lib/librte_eal/linuxapp/eal/eal_pci.c      | 41 ------------------------------
 lib/librte_eal/linuxapp/eal/eal_pci_init.h |  5 ----
 5 files changed, 51 insertions(+), 68 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 56dc98c..92a9fcf 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 00547d9..c4b24bc 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,45 @@ 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);
+}
+
 /* Map pci device */
 static int
 pci_map_device(struct rte_pci_device *dev)
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index bd1ef4e..475d2dc 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -365,6 +365,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 5c30469..1d5a13b 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] 46+ messages in thread

* [dpdk-dev] [PATCH v2 7/8] eal: Consolidate pci uio functions of linuxapp and bsdapp
  2015-06-26  8:21   ` [dpdk-dev] [PATCH v2 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
                       ` (5 preceding siblings ...)
  2015-06-26  8:21     ` [dpdk-dev] [PATCH v2 6/8] eal: Consolidate pci_map/unmap_resource() " Tetsuya Mukawa
@ 2015-06-26  8:21     ` Tetsuya Mukawa
  2015-06-26  8:21     ` [dpdk-dev] [PATCH v2 8/8] eal: Enable Port Hotplug as default in Linux and BSD Tetsuya Mukawa
  7 siblings, 0 replies; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-06-26  8:21 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         | 238 +++++++++++++++++++++
 lib/librte_eal/common/eal_private.h                |  36 ++++
 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, 285 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 92a9fcf..0103e2b 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 */
 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_uio_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_uio_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 */
-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_uio_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_uio_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_uio_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..fa36073
--- /dev/null
+++ b/lib/librte_eal/common/eal_common_pci_uio.c
@@ -0,0 +1,238 @@
+/*-
+ *   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_uio_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_uio_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_uio_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 badb55c..8c4145a 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).
@@ -181,6 +182,41 @@ int pci_uio_map_resource(struct rte_pci_device *dev);
 void pci_uio_unmap_resource(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_uio_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_uio_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..90409b3 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_uio_resource(struct rte_pci_device *dev,
+		struct mapped_pci_resource **uio_res);
+int pci_uio_map_uio_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 7da4543..3d475c7 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_uio_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_uio_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_uio_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_uio_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_uio_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] 46+ messages in thread

* [dpdk-dev] [PATCH v2 8/8] eal: Enable Port Hotplug as default in Linux and BSD
  2015-06-26  8:21   ` [dpdk-dev] [PATCH v2 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
                       ` (6 preceding siblings ...)
  2015-06-26  8:21     ` [dpdk-dev] [PATCH v2 7/8] eal: Consolidate pci uio functions " Tetsuya Mukawa
@ 2015-06-26  8:21     ` Tetsuya Mukawa
  7 siblings, 0 replies; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-06-26  8:21 UTC (permalink / raw)
  To: dev

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

This patch removes CONFIG_RTE_LIBRTE_EAL_HOTPLUG option, and enables it
as default in both Linux and BSD.
Also, to support port hotplug, rte_eal_pci_scan() and below missing
symbols should be exported to ethdev library.
 - rte_eal_parse_devargs_str()
 - rte_eal_pci_close_one()
 - rte_eal_pci_probe_one()
 - rte_eal_pci_scan()
 - rte_eal_vdev_init()
 - rte_eal_vdev_uninit()

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 config/common_bsdapp                          |  6 ------
 config/common_linuxapp                        |  5 -----
 lib/librte_eal/bsdapp/eal/eal_pci.c           |  6 +++---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map |  6 ++++++
 lib/librte_eal/common/eal_common_dev.c        |  2 --
 lib/librte_eal/common/eal_common_pci.c        |  6 ------
 lib/librte_eal/common/eal_common_pci_uio.c    |  2 --
 lib/librte_eal/common/include/rte_pci.h       |  2 --
 lib/librte_ether/rte_ethdev.c                 | 21 ---------------------
 9 files changed, 9 insertions(+), 47 deletions(-)

diff --git a/config/common_bsdapp b/config/common_bsdapp
index 464250b..c6e6e9c 100644
--- a/config/common_bsdapp
+++ b/config/common_bsdapp
@@ -121,12 +121,6 @@ CONFIG_RTE_LIBRTE_EAL_BSDAPP=y
 CONFIG_RTE_LIBRTE_EAL_LINUXAPP=n
 
 #
-# Compile Environment Abstraction Layer to support hotplug
-# So far, Hotplug functions only support linux
-#
-CONFIG_RTE_LIBRTE_EAL_HOTPLUG=n
-
-#
 # Compile Environment Abstraction Layer to support Vmware TSC map
 #
 CONFIG_RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT=y
diff --git a/config/common_linuxapp b/config/common_linuxapp
index aae22f4..c33a6fe 100644
--- a/config/common_linuxapp
+++ b/config/common_linuxapp
@@ -119,11 +119,6 @@ CONFIG_RTE_PCI_MAX_READ_REQUEST_SIZE=0
 CONFIG_RTE_LIBRTE_EAL_LINUXAPP=y
 
 #
-# Compile Environment Abstraction Layer to support hotplug
-#
-CONFIG_RTE_LIBRTE_EAL_HOTPLUG=y
-
-#
 # Compile Environment Abstraction Layer to support Vmware TSC map
 #
 CONFIG_RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT=y
diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 0103e2b..163e008 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -309,8 +309,8 @@ skipdev:
  * Scan the content of the PCI bus, and add the devices in the devices
  * list. Call pci_scan_one() for each pci entry found.
  */
-static int
-pci_scan(void)
+int
+rte_eal_pci_scan(void)
 {
 	int fd;
 	unsigned dev_count = 0;
@@ -366,7 +366,7 @@ rte_eal_pci_init(void)
 	if (internal_config.no_pci)
 		return 0;
 
-	if (pci_scan() < 0) {
+	if (rte_eal_pci_scan() < 0) {
 		RTE_LOG(ERR, EAL, "%s(): Cannot scan PCI bus\n", __func__);
 		return -1;
 	}
diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 67b6a6c..7e850a9 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -37,14 +37,20 @@ DPDK_2.0 {
 	rte_eal_lcore_role;
 	rte_eal_mp_remote_launch;
 	rte_eal_mp_wait_lcore;
+	rte_eal_parse_devargs_str;
+	rte_eal_pci_close_one;
 	rte_eal_pci_dump;
 	rte_eal_pci_probe;
+	rte_eal_pci_probe_one;
 	rte_eal_pci_register;
+	rte_eal_pci_scan;
 	rte_eal_pci_unregister;
 	rte_eal_process_type;
 	rte_eal_remote_launch;
 	rte_eal_tailq_lookup;
 	rte_eal_tailq_register;
+	rte_eal_vdev_init;
+	rte_eal_vdev_uninit;
 	rte_eal_wait_lcore;
 	rte_exit;
 	rte_get_hpet_cycles;
diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 92a5a94..4089d66 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -125,7 +125,6 @@ rte_eal_dev_init(void)
 	return 0;
 }
 
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
 int
 rte_eal_vdev_uninit(const char *name)
 {
@@ -151,4 +150,3 @@ rte_eal_vdev_uninit(const char *name)
 	RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
 	return -EINVAL;
 }
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index c4b24bc..c55112b 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -168,7 +168,6 @@ pci_map_device(struct rte_pci_device *dev)
 	return ret;
 }
 
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
 /* Unmap pci device */
 static void
 pci_unmap_device(struct rte_pci_device *dev)
@@ -193,7 +192,6 @@ pci_unmap_device(struct rte_pci_device *dev)
 		break;
 	}
 }
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
 
 /*
  * If vendor/device ID match, call the devinit() function of the
@@ -266,7 +264,6 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *d
 	return 1;
 }
 
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
 /*
  * If vendor/device ID match, call the devuninit() function of the
  * driver.
@@ -322,7 +319,6 @@ rte_eal_pci_close_one_driver(struct rte_pci_driver *dr,
 	/* 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
@@ -351,7 +347,6 @@ pci_probe_all_drivers(struct rte_pci_device *dev)
 	return 1;
 }
 
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
 /*
  * If vendor/device ID match, call the devuninit() function of all
  * registered driver for the given device. Return -1 if initialization
@@ -442,7 +437,6 @@ err_return:
 			dev->addr.devid, dev->addr.function);
 	return -1;
 }
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
 
 /*
  * Scan the content of the PCI bus, and call the devinit() function for
diff --git a/lib/librte_eal/common/eal_common_pci_uio.c b/lib/librte_eal/common/eal_common_pci_uio.c
index fa36073..84e392a 100644
--- a/lib/librte_eal/common/eal_common_pci_uio.c
+++ b/lib/librte_eal/common/eal_common_pci_uio.c
@@ -162,7 +162,6 @@ free_uio_res:
 	return -1;
 }
 
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
 static void
 pci_uio_unmap(struct mapped_pci_resource *uio_res)
 {
@@ -235,4 +234,3 @@ pci_uio_unmap_resource(struct rte_pci_device *dev)
 	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/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index 475d2dc..a8b6a10 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -376,7 +376,6 @@ void *pci_map_resource(void *requested_addr, int fd, off_t offset,
  */
 void pci_unmap_resource(void *requested_addr, size_t size);
 
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
 /**
  * Probe the single PCI device.
  *
@@ -406,7 +405,6 @@ int rte_eal_pci_probe_one(const struct rte_pci_addr *addr);
  *   - Negative on error.
  */
 int rte_eal_pci_close_one(const struct rte_pci_addr *addr);
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
 
 /**
  * Dump the content of the PCI bus.
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 1822258..43b9fcc 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -425,9 +425,6 @@ rte_eth_dev_count(void)
 	return nb_ports;
 }
 
-/* So far, DPDK hotplug function only supports linux */
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
-
 static enum rte_eth_dev_type
 rte_eth_dev_get_device_type(uint8_t port_id)
 {
@@ -708,24 +705,6 @@ rte_eth_dev_detach(uint8_t port_id, char *name)
 	} else
 		return rte_eth_dev_detach_vdev(port_id, name);
 }
-#else /* RTE_LIBRTE_EAL_HOTPLUG */
-int
-rte_eth_dev_attach(const char *devargs __rte_unused,
-			uint8_t *port_id __rte_unused)
-{
-	RTE_LOG(ERR, EAL, "Hotplug support isn't enabled\n");
-	return -1;
-}
-
-/* detach the device, then store the name of the device */
-int
-rte_eth_dev_detach(uint8_t port_id __rte_unused,
-			char *name __rte_unused)
-{
-	RTE_LOG(ERR, EAL, "Hotplug support isn't enabled\n");
-	return -1;
-}
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
 
 static int
 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
-- 
2.1.4

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

* [dpdk-dev] [PATCH v3 0/8] Add Port Hotplug support to BSD
  2015-05-19  6:21 ` [dpdk-dev] [PATCH 4/8] eal: Consolidate rte_eal_pci_probe/close_one_driver() " Tetsuya Mukawa
  2015-06-26  8:21   ` [dpdk-dev] [PATCH v2 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
@ 2015-06-29  2:56   ` Tetsuya Mukawa
  2015-06-29  2:56     ` [dpdk-dev] [PATCH v3 1/8] eal: Add pci_uio_alloc_uio_resource() Tetsuya Mukawa
                       ` (8 more replies)
  1 sibling, 9 replies; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-06-29  2:56 UTC (permalink / raw)
  To: dev

This patch series adds port hotplug support to BSD.
Before applying, following patches should be applied.
 - [PATCH v6 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c
 - [PATCH v6 2/5] eal: Close file descriptor of uio configuration
 - [PATCH v6 3/5] eal: Fix memory leaks and needless increment of pci_map_addr
 - [PATCH v6 4/5] eal/bsdapp: Change names of pci related data structure
 - [PATCH v6 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp

Some functions will be consolidated after applying the patches, because
these functions are implemented in both Linux and BSD code.

PATCH v2 changes:
 - Fix license of eal_common_pci_uio.c

PATCH v1 changes:
 - Rebase to below latest patch series.
   - [PATCH v6] Clean up pci uio implementations


Tetsuya.Mukawa (8):
  eal: Add pci_uio_alloc_uio_resource()
  eal: Add pci_uio_map_uio_resource_by_index()
  eal: Consolidate pci_map and mapped_pci_resource of linuxapp and
    bsdapp
  eal: Consolidate rte_eal_pci_probe/close_one_driver() of linuxapp and
    bsdapp
  eal: Consolidate pci_map/unmap_device() of linuxapp and bsdapp
  eal: Consolidate pci_map/unmap_resource() of linuxapp and bsdapp
  eal: Consolidate pci uio functions of linuxapp and bsdapp
  eal: Enable Port Hotplug as default in Linux and BSD

 config/common_bsdapp                               |   6 -
 config/common_linuxapp                             |   5 -
 lib/librte_eal/bsdapp/eal/Makefile                 |   1 +
 lib/librte_eal/bsdapp/eal/eal_pci.c                | 321 +++++----------------
 .../bsdapp/eal/include/exec-env/rte_interrupts.h   |   1 +
 lib/librte_eal/bsdapp/eal/rte_eal_version.map      |   6 +
 lib/librte_eal/common/eal_common_dev.c             |   2 -
 lib/librte_eal/common/eal_common_pci.c             | 224 +++++++++++++-
 lib/librte_eal/common/eal_common_pci_uio.c         | 268 +++++++++++++++++
 lib/librte_eal/common/eal_private.h                |  57 +++-
 lib/librte_eal/common/include/rte_pci.h            |  42 ++-
 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          | 271 +++++------------
 lib/librte_ether/rte_ethdev.c                      |  22 +-
 16 files changed, 733 insertions(+), 769 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_pci_uio.c

-- 
2.1.4

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

* [dpdk-dev] [PATCH v3 1/8] eal: Add pci_uio_alloc_uio_resource()
  2015-06-29  2:56   ` [dpdk-dev] [PATCH v3 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
@ 2015-06-29  2:56     ` Tetsuya Mukawa
  2015-06-29 13:24       ` Iremonger, Bernard
  2015-06-29  2:56     ` [dpdk-dev] [PATCH v3 2/8] eal: Add pci_uio_map_uio_resource_by_index() Tetsuya Mukawa
                       ` (7 subsequent siblings)
  8 siblings, 1 reply; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-06-29  2:56 UTC (permalink / raw)
  To: dev

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

This patch adds a new function called pci_uio_alloc_uio_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..2d9f3a5 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_uio_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_uio_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_uio_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..9e0b617 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_uio_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_uio_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_uio_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] 46+ messages in thread

* [dpdk-dev] [PATCH v3 2/8] eal: Add pci_uio_map_uio_resource_by_index()
  2015-06-29  2:56   ` [dpdk-dev] [PATCH v3 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
  2015-06-29  2:56     ` [dpdk-dev] [PATCH v3 1/8] eal: Add pci_uio_alloc_uio_resource() Tetsuya Mukawa
@ 2015-06-29  2:56     ` Tetsuya Mukawa
  2015-06-29 13:36       ` Iremonger, Bernard
  2015-06-29  2:56     ` [dpdk-dev] [PATCH v3 3/8] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp Tetsuya Mukawa
                       ` (6 subsequent siblings)
  8 siblings, 1 reply; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-06-29  2:56 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 2d9f3a5..61d1fe5 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_uio_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_uio_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_uio_resource() */
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 9e0b617..7da4543 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_uio_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_uio_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] 46+ messages in thread

* [dpdk-dev] [PATCH v3 3/8] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp
  2015-06-29  2:56   ` [dpdk-dev] [PATCH v3 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
  2015-06-29  2:56     ` [dpdk-dev] [PATCH v3 1/8] eal: Add pci_uio_alloc_uio_resource() Tetsuya Mukawa
  2015-06-29  2:56     ` [dpdk-dev] [PATCH v3 2/8] eal: Add pci_uio_map_uio_resource_by_index() Tetsuya Mukawa
@ 2015-06-29  2:56     ` Tetsuya Mukawa
  2015-06-29  2:56     ` [dpdk-dev] [PATCH v3 4/8] eal: Consolidate rte_eal_pci_probe/close_one_driver() " Tetsuya Mukawa
                       ` (5 subsequent siblings)
  8 siblings, 0 replies; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-06-29  2:56 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 61d1fe5..c7017eb 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] 46+ messages in thread

* [dpdk-dev] [PATCH v3 4/8] eal: Consolidate rte_eal_pci_probe/close_one_driver() of linuxapp and bsdapp
  2015-06-29  2:56   ` [dpdk-dev] [PATCH v3 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
                       ` (2 preceding siblings ...)
  2015-06-29  2:56     ` [dpdk-dev] [PATCH v3 3/8] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp Tetsuya Mukawa
@ 2015-06-29  2:56     ` Tetsuya Mukawa
  2015-06-29 15:28       ` Bruce Richardson
  2015-06-29  2:56     ` [dpdk-dev] [PATCH v3 5/8] eal: Consolidate pci_map/unmap_device() " Tetsuya Mukawa
                       ` (4 subsequent siblings)
  8 siblings, 1 reply; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-06-29  2:56 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    |  74 ++---------------
 lib/librte_eal/common/eal_common_pci.c | 129 ++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_private.h    |  21 ++---
 lib/librte_eal/linuxapp/eal/eal_pci.c  | 148 ++-------------------------------
 4 files changed, 153 insertions(+), 219 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index c7017eb..2a623e3 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -88,7 +88,7 @@ static struct rte_tailq_elem rte_uio_tailq = {
 EAL_REGISTER_TAILQ(rte_uio_tailq)
 
 /* 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 "
@@ -430,6 +430,13 @@ skipdev:
 	return 0;
 }
 
+/* Map pci device */
+int
+pci_map_device(struct rte_pci_device *dev)
+{
+	return pci_uio_map_resource(dev);
+}
+
 /*
  * Scan the content of the PCI bus, and add the devices in the devices
  * list. Call pci_scan_one() for each pci entry found.
@@ -480,71 +487,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 4229aaf..6eb6257 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -99,6 +99,135 @@ static struct rte_devargs *pci_devargs_lookup(struct rte_pci_device *dev)
 }
 
 /*
+ * 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 4acf5a0..fe2c596 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -154,30 +154,31 @@ struct rte_pci_driver;
 struct rte_pci_device;
 
 /**
- * Mmap memory for single PCI device
+ * Unbind kernel driver for this 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);
+int pci_unbind_kernel_driver(struct rte_pci_device *dev);
 
 /**
- * Munmap memory for single PCI device
+ * Map this 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);
+int pci_map_device(struct rte_pci_device *dev);
+
+/**
+ * Unmap this device
+ *
+ * This function is private to EAL.
+ */
+void pci_unmap_device(struct rte_pci_device *dev);
 
 /**
  * Init tail queues for non-EAL library structures. This is to allow
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index d2adc66..91e958e 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -57,7 +57,7 @@
  */
 
 /* unbind kernel driver for this device */
-static int
+int
 pci_unbind_kernel_driver(struct rte_pci_device *dev)
 {
 	int n;
@@ -563,7 +563,8 @@ pci_config_space_set(struct rte_pci_device *dev)
 }
 #endif
 
-static int
+/* Map pci device */
+int
 pci_map_device(struct rte_pci_device *dev)
 {
 	int ret = -1;
@@ -592,7 +593,8 @@ pci_map_device(struct rte_pci_device *dev)
 }
 
 #ifdef RTE_LIBRTE_EAL_HOTPLUG
-static void
+/* Unmap pci device */
+void
 pci_unmap_device(struct rte_pci_device *dev)
 {
 	if (dev == NULL)
@@ -616,146 +618,6 @@ 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.
- */
-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] 46+ messages in thread

* [dpdk-dev] [PATCH v3 5/8] eal: Consolidate pci_map/unmap_device() of linuxapp and bsdapp
  2015-06-29  2:56   ` [dpdk-dev] [PATCH v3 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
                       ` (3 preceding siblings ...)
  2015-06-29  2:56     ` [dpdk-dev] [PATCH v3 4/8] eal: Consolidate rte_eal_pci_probe/close_one_driver() " Tetsuya Mukawa
@ 2015-06-29  2:56     ` Tetsuya Mukawa
  2015-06-29  2:56     ` [dpdk-dev] [PATCH v3 6/8] eal: Consolidate pci_map/unmap_resource() " Tetsuya Mukawa
                       ` (3 subsequent siblings)
  8 siblings, 0 replies; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-06-29  2:56 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     | 12 +++----
 lib/librte_eal/common/eal_common_pci.c  | 57 +++++++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_private.h     |  4 +--
 lib/librte_eal/common/include/rte_pci.h |  1 +
 lib/librte_eal/linuxapp/eal/eal_pci.c   | 55 -------------------------------
 lib/librte_ether/rte_ethdev.c           |  1 +
 6 files changed, 65 insertions(+), 65 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 2a623e3..56dc98c 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -275,7 +275,7 @@ fail:
 }
 
 /* map the PCI resource of a PCI device in virtual memory */
-static int
+int
 pci_uio_map_resource(struct rte_pci_device *dev)
 {
 	int i, map_idx, ret;
@@ -366,6 +366,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:
@@ -430,13 +433,6 @@ skipdev:
 	return 0;
 }
 
-/* Map pci device */
-int
-pci_map_device(struct rte_pci_device *dev)
-{
-	return pci_uio_map_resource(dev);
-}
-
 /*
  * Scan the content of the PCI bus, and add the devices in the devices
  * list. Call pci_scan_one() for each pci entry found.
diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 6eb6257..00547d9 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -98,6 +98,63 @@ static struct rte_devargs *pci_devargs_lookup(struct rte_pci_device *dev)
 	return NULL;
 }
 
+/* Map pci device */
+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:
+	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 */
+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:
+	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 the
  * driver.
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index fe2c596..badb55c 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -171,14 +171,14 @@ int pci_unbind_kernel_driver(struct rte_pci_device *dev);
  * @return
  *   0 on success, negative on error
  */
-int pci_map_device(struct rte_pci_device *dev);
+int pci_uio_map_resource(struct rte_pci_device *dev);
 
 /**
  * Unmap this device
  *
  * This function is private to EAL.
  */
-void pci_unmap_device(struct rte_pci_device *dev);
+void pci_uio_unmap_resource(struct rte_pci_device *dev);
 
 /**
  * Init tail queues for non-EAL library structures. This is to allow
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index 0a2ef09..bd1ef4e 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 91e958e..5c30469 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -563,61 +563,6 @@ pci_config_space_set(struct rte_pci_device *dev)
 }
 #endif
 
-/* 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:
-		/* 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:
-		/* 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 */
-
 /* Init the PCI EAL subsystem */
 int
 rte_eal_pci_init(void)
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] 46+ messages in thread

* [dpdk-dev] [PATCH v3 6/8] eal: Consolidate pci_map/unmap_resource() of linuxapp and bsdapp
  2015-06-29  2:56   ` [dpdk-dev] [PATCH v3 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
                       ` (4 preceding siblings ...)
  2015-06-29  2:56     ` [dpdk-dev] [PATCH v3 5/8] eal: Consolidate pci_map/unmap_device() " Tetsuya Mukawa
@ 2015-06-29  2:56     ` Tetsuya Mukawa
  2015-06-29  2:56     ` [dpdk-dev] [PATCH v3 7/8] eal: Consolidate pci uio functions " Tetsuya Mukawa
                       ` (2 subsequent siblings)
  8 siblings, 0 replies; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-06-29  2:56 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    | 11 ++++++++
 lib/librte_eal/linuxapp/eal/eal_pci.c      | 41 ------------------------------
 lib/librte_eal/linuxapp/eal/eal_pci_init.h |  5 ----
 5 files changed, 51 insertions(+), 68 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 56dc98c..92a9fcf 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 00547d9..c4b24bc 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,45 @@ 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);
+}
+
 /* Map pci device */
 static int
 pci_map_device(struct rte_pci_device *dev)
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index bd1ef4e..475d2dc 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -365,6 +365,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 5c30469..1d5a13b 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] 46+ messages in thread

* [dpdk-dev] [PATCH v3 7/8] eal: Consolidate pci uio functions of linuxapp and bsdapp
  2015-06-29  2:56   ` [dpdk-dev] [PATCH v3 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
                       ` (5 preceding siblings ...)
  2015-06-29  2:56     ` [dpdk-dev] [PATCH v3 6/8] eal: Consolidate pci_map/unmap_resource() " Tetsuya Mukawa
@ 2015-06-29  2:56     ` Tetsuya Mukawa
  2015-06-29 14:03       ` Iremonger, Bernard
  2015-06-29  2:56     ` [dpdk-dev] [PATCH v3 8/8] eal: Enable Port Hotplug as default in Linux and BSD Tetsuya Mukawa
  2015-06-29 15:30     ` [dpdk-dev] [PATCH v3 0/8] Add Port Hotplug support to BSD Bruce Richardson
  8 siblings, 1 reply; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-06-29  2:56 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                |  36 +++
 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, 317 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 92a9fcf..0103e2b 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 */
 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_uio_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_uio_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 */
-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_uio_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_uio_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_uio_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..374478e
--- /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_uio_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_uio_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_uio_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 badb55c..8c4145a 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).
@@ -181,6 +182,41 @@ int pci_uio_map_resource(struct rte_pci_device *dev);
 void pci_uio_unmap_resource(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_uio_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_uio_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..90409b3 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_uio_resource(struct rte_pci_device *dev,
+		struct mapped_pci_resource **uio_res);
+int pci_uio_map_uio_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 7da4543..3d475c7 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_uio_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_uio_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_uio_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_uio_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_uio_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] 46+ messages in thread

* [dpdk-dev] [PATCH v3 8/8] eal: Enable Port Hotplug as default in Linux and BSD
  2015-06-29  2:56   ` [dpdk-dev] [PATCH v3 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
                       ` (6 preceding siblings ...)
  2015-06-29  2:56     ` [dpdk-dev] [PATCH v3 7/8] eal: Consolidate pci uio functions " Tetsuya Mukawa
@ 2015-06-29  2:56     ` Tetsuya Mukawa
  2015-06-30  8:26       ` [dpdk-dev] [PATCH v4] Add Port Hotplug support to BSD Tetsuya Mukawa
  2015-06-29 15:30     ` [dpdk-dev] [PATCH v3 0/8] Add Port Hotplug support to BSD Bruce Richardson
  8 siblings, 1 reply; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-06-29  2:56 UTC (permalink / raw)
  To: dev

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

This patch removes CONFIG_RTE_LIBRTE_EAL_HOTPLUG option, and enables it
as default in both Linux and BSD.
Also, to support port hotplug, rte_eal_pci_scan() and below missing
symbols should be exported to ethdev library.
 - rte_eal_parse_devargs_str()
 - rte_eal_pci_close_one()
 - rte_eal_pci_probe_one()
 - rte_eal_pci_scan()
 - rte_eal_vdev_init()
 - rte_eal_vdev_uninit()

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 config/common_bsdapp                          |  6 ------
 config/common_linuxapp                        |  5 -----
 lib/librte_eal/bsdapp/eal/eal_pci.c           |  6 +++---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map |  6 ++++++
 lib/librte_eal/common/eal_common_dev.c        |  2 --
 lib/librte_eal/common/eal_common_pci.c        |  6 ------
 lib/librte_eal/common/eal_common_pci_uio.c    |  2 --
 lib/librte_eal/common/include/rte_pci.h       |  2 --
 lib/librte_ether/rte_ethdev.c                 | 21 ---------------------
 9 files changed, 9 insertions(+), 47 deletions(-)

diff --git a/config/common_bsdapp b/config/common_bsdapp
index 464250b..c6e6e9c 100644
--- a/config/common_bsdapp
+++ b/config/common_bsdapp
@@ -121,12 +121,6 @@ CONFIG_RTE_LIBRTE_EAL_BSDAPP=y
 CONFIG_RTE_LIBRTE_EAL_LINUXAPP=n
 
 #
-# Compile Environment Abstraction Layer to support hotplug
-# So far, Hotplug functions only support linux
-#
-CONFIG_RTE_LIBRTE_EAL_HOTPLUG=n
-
-#
 # Compile Environment Abstraction Layer to support Vmware TSC map
 #
 CONFIG_RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT=y
diff --git a/config/common_linuxapp b/config/common_linuxapp
index aae22f4..c33a6fe 100644
--- a/config/common_linuxapp
+++ b/config/common_linuxapp
@@ -119,11 +119,6 @@ CONFIG_RTE_PCI_MAX_READ_REQUEST_SIZE=0
 CONFIG_RTE_LIBRTE_EAL_LINUXAPP=y
 
 #
-# Compile Environment Abstraction Layer to support hotplug
-#
-CONFIG_RTE_LIBRTE_EAL_HOTPLUG=y
-
-#
 # Compile Environment Abstraction Layer to support Vmware TSC map
 #
 CONFIG_RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT=y
diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 0103e2b..163e008 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -309,8 +309,8 @@ skipdev:
  * Scan the content of the PCI bus, and add the devices in the devices
  * list. Call pci_scan_one() for each pci entry found.
  */
-static int
-pci_scan(void)
+int
+rte_eal_pci_scan(void)
 {
 	int fd;
 	unsigned dev_count = 0;
@@ -366,7 +366,7 @@ rte_eal_pci_init(void)
 	if (internal_config.no_pci)
 		return 0;
 
-	if (pci_scan() < 0) {
+	if (rte_eal_pci_scan() < 0) {
 		RTE_LOG(ERR, EAL, "%s(): Cannot scan PCI bus\n", __func__);
 		return -1;
 	}
diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 67b6a6c..7e850a9 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -37,14 +37,20 @@ DPDK_2.0 {
 	rte_eal_lcore_role;
 	rte_eal_mp_remote_launch;
 	rte_eal_mp_wait_lcore;
+	rte_eal_parse_devargs_str;
+	rte_eal_pci_close_one;
 	rte_eal_pci_dump;
 	rte_eal_pci_probe;
+	rte_eal_pci_probe_one;
 	rte_eal_pci_register;
+	rte_eal_pci_scan;
 	rte_eal_pci_unregister;
 	rte_eal_process_type;
 	rte_eal_remote_launch;
 	rte_eal_tailq_lookup;
 	rte_eal_tailq_register;
+	rte_eal_vdev_init;
+	rte_eal_vdev_uninit;
 	rte_eal_wait_lcore;
 	rte_exit;
 	rte_get_hpet_cycles;
diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 92a5a94..4089d66 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -125,7 +125,6 @@ rte_eal_dev_init(void)
 	return 0;
 }
 
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
 int
 rte_eal_vdev_uninit(const char *name)
 {
@@ -151,4 +150,3 @@ rte_eal_vdev_uninit(const char *name)
 	RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
 	return -EINVAL;
 }
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index c4b24bc..c55112b 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -168,7 +168,6 @@ pci_map_device(struct rte_pci_device *dev)
 	return ret;
 }
 
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
 /* Unmap pci device */
 static void
 pci_unmap_device(struct rte_pci_device *dev)
@@ -193,7 +192,6 @@ pci_unmap_device(struct rte_pci_device *dev)
 		break;
 	}
 }
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
 
 /*
  * If vendor/device ID match, call the devinit() function of the
@@ -266,7 +264,6 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *d
 	return 1;
 }
 
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
 /*
  * If vendor/device ID match, call the devuninit() function of the
  * driver.
@@ -322,7 +319,6 @@ rte_eal_pci_close_one_driver(struct rte_pci_driver *dr,
 	/* 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
@@ -351,7 +347,6 @@ pci_probe_all_drivers(struct rte_pci_device *dev)
 	return 1;
 }
 
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
 /*
  * If vendor/device ID match, call the devuninit() function of all
  * registered driver for the given device. Return -1 if initialization
@@ -442,7 +437,6 @@ err_return:
 			dev->addr.devid, dev->addr.function);
 	return -1;
 }
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
 
 /*
  * Scan the content of the PCI bus, and call the devinit() function for
diff --git a/lib/librte_eal/common/eal_common_pci_uio.c b/lib/librte_eal/common/eal_common_pci_uio.c
index 374478e..0b3d40d 100644
--- a/lib/librte_eal/common/eal_common_pci_uio.c
+++ b/lib/librte_eal/common/eal_common_pci_uio.c
@@ -194,7 +194,6 @@ free_uio_res:
 	return -1;
 }
 
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
 static void
 pci_uio_unmap(struct mapped_pci_resource *uio_res)
 {
@@ -267,4 +266,3 @@ pci_uio_unmap_resource(struct rte_pci_device *dev)
 	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/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index 475d2dc..a8b6a10 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -376,7 +376,6 @@ void *pci_map_resource(void *requested_addr, int fd, off_t offset,
  */
 void pci_unmap_resource(void *requested_addr, size_t size);
 
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
 /**
  * Probe the single PCI device.
  *
@@ -406,7 +405,6 @@ int rte_eal_pci_probe_one(const struct rte_pci_addr *addr);
  *   - Negative on error.
  */
 int rte_eal_pci_close_one(const struct rte_pci_addr *addr);
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
 
 /**
  * Dump the content of the PCI bus.
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 1822258..43b9fcc 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -425,9 +425,6 @@ rte_eth_dev_count(void)
 	return nb_ports;
 }
 
-/* So far, DPDK hotplug function only supports linux */
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
-
 static enum rte_eth_dev_type
 rte_eth_dev_get_device_type(uint8_t port_id)
 {
@@ -708,24 +705,6 @@ rte_eth_dev_detach(uint8_t port_id, char *name)
 	} else
 		return rte_eth_dev_detach_vdev(port_id, name);
 }
-#else /* RTE_LIBRTE_EAL_HOTPLUG */
-int
-rte_eth_dev_attach(const char *devargs __rte_unused,
-			uint8_t *port_id __rte_unused)
-{
-	RTE_LOG(ERR, EAL, "Hotplug support isn't enabled\n");
-	return -1;
-}
-
-/* detach the device, then store the name of the device */
-int
-rte_eth_dev_detach(uint8_t port_id __rte_unused,
-			char *name __rte_unused)
-{
-	RTE_LOG(ERR, EAL, "Hotplug support isn't enabled\n");
-	return -1;
-}
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
 
 static int
 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
-- 
2.1.4

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

* Re: [dpdk-dev] [PATCH v3 1/8] eal: Add pci_uio_alloc_uio_resource()
  2015-06-29  2:56     ` [dpdk-dev] [PATCH v3 1/8] eal: Add pci_uio_alloc_uio_resource() Tetsuya Mukawa
@ 2015-06-29 13:24       ` Iremonger, Bernard
  2015-06-30  2:31         ` Tetsuya Mukawa
  0 siblings, 1 reply; 46+ messages in thread
From: Iremonger, Bernard @ 2015-06-29 13:24 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev



> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Monday, June 29, 2015 3:57 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; david.marchand@6wind.com; Tetsuya.Mukawa
> Subject: [PATCH v3 1/8] eal: Add pci_uio_alloc_uio_resource()
> 
> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
> 
> This patch adds a new function called pci_uio_alloc_uio_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>
Hi Tetsuya,

There are two comments inline below.

> ---
>  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..2d9f3a5 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_uio_resource(struct rte_pci_device *dev,
> +		struct mapped_pci_resource **uio_res)

The name of this function is a bit longwinded,  pci_uio_alloc_resource() might be better.

>  {
> -	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_uio_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_uio_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..9e0b617 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_uio_resource(struct rte_pci_device *dev,
> +		struct mapped_pci_resource **uio_res)

The name of this function is a bit longwinded,  pci_uio_alloc_resource() might be better.

Regards,

Bernard.

>  {
> -	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_uio_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_uio_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] 46+ messages in thread

* Re: [dpdk-dev] [PATCH v3 2/8] eal: Add pci_uio_map_uio_resource_by_index()
  2015-06-29  2:56     ` [dpdk-dev] [PATCH v3 2/8] eal: Add pci_uio_map_uio_resource_by_index() Tetsuya Mukawa
@ 2015-06-29 13:36       ` Iremonger, Bernard
  2015-06-30  2:34         ` Tetsuya Mukawa
  0 siblings, 1 reply; 46+ messages in thread
From: Iremonger, Bernard @ 2015-06-29 13:36 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev



> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Monday, June 29, 2015 3:57 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; david.marchand@6wind.com; Tetsuya.Mukawa
> Subject: [PATCH v3 2/8] eal: Add pci_uio_map_uio_resource_by_index()
> 
> 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>

Hi Tetsuya,

There are two comments inline below.

> ---
>  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 2d9f3a5..61d1fe5 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_uio_resource_by_index(struct rte_pci_device *dev, int
> res_idx,
> +		struct mapped_pci_resource *uio_res, int map_idx) {

The name of this function is a bit long winded, pci_uio_map_resource_by_index() might be better.

> +	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_uio_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_uio_resource() */ diff --git
> a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> index 9e0b617..7da4543 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_uio_resource_by_index(struct rte_pci_device *dev, int
> res_idx,
> +		struct mapped_pci_resource *uio_res, int map_idx) {

The name of this function is a bit long winded, pci_uio_map_resource_by_index() might be better.

Regards,

Bernard.


> +	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_uio_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] 46+ messages in thread

* Re: [dpdk-dev] [PATCH v3 7/8] eal: Consolidate pci uio functions of linuxapp and bsdapp
  2015-06-29  2:56     ` [dpdk-dev] [PATCH v3 7/8] eal: Consolidate pci uio functions " Tetsuya Mukawa
@ 2015-06-29 14:03       ` Iremonger, Bernard
  2015-06-30  2:43         ` Tetsuya Mukawa
  0 siblings, 1 reply; 46+ messages in thread
From: Iremonger, Bernard @ 2015-06-29 14:03 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev



> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Monday, June 29, 2015 3:57 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; david.marchand@6wind.com; Tetsuya.Mukawa
> Subject: [PATCH v3 7/8] eal: Consolidate pci uio functions of linuxapp and
> bsdapp
> 
> 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>
Hi Tetsuya,

The copyrights of all files in this patch set should be updated to 2015.

Regards,

Bernard.

> ---
>  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                |  36 +++
>  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, 317 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 92a9fcf..0103e2b 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 */  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_uio_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_uio_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 */ -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_uio_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_uio_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_uio_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..374478e
> --- /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_uio_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_uio_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_uio_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 badb55c..8c4145a 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).
> @@ -181,6 +182,41 @@ int pci_uio_map_resource(struct rte_pci_device
> *dev);  void pci_uio_unmap_resource(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_uio_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_uio_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..90409b3 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_uio_resource(struct rte_pci_device *dev,
> +		struct mapped_pci_resource **uio_res); int
> +pci_uio_map_uio_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 7da4543..3d475c7 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_uio_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_uio_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_uio_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_uio_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_uio_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] 46+ messages in thread

* Re: [dpdk-dev] [PATCH v3 4/8] eal: Consolidate rte_eal_pci_probe/close_one_driver() of linuxapp and bsdapp
  2015-06-29  2:56     ` [dpdk-dev] [PATCH v3 4/8] eal: Consolidate rte_eal_pci_probe/close_one_driver() " Tetsuya Mukawa
@ 2015-06-29 15:28       ` Bruce Richardson
  2015-06-30  8:08         ` Tetsuya Mukawa
  0 siblings, 1 reply; 46+ messages in thread
From: Bruce Richardson @ 2015-06-29 15:28 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Mon, Jun 29, 2015 at 11:56:46AM +0900, Tetsuya Mukawa 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()
> 
> 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    |  74 ++---------------
>  lib/librte_eal/common/eal_common_pci.c | 129 ++++++++++++++++++++++++++++
>  lib/librte_eal/common/eal_private.h    |  21 ++---
>  lib/librte_eal/linuxapp/eal/eal_pci.c  | 148 ++-------------------------------
>  4 files changed, 153 insertions(+), 219 deletions(-)
> 
> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
> index c7017eb..2a623e3 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> @@ -88,7 +88,7 @@ static struct rte_tailq_elem rte_uio_tailq = {
>  EAL_REGISTER_TAILQ(rte_uio_tailq)
>  
>  /* 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 "
> @@ -430,6 +430,13 @@ skipdev:
>  	return 0;
>  }
>  
> +/* Map pci device */
> +int
> +pci_map_device(struct rte_pci_device *dev)
> +{
> +	return pci_uio_map_resource(dev);
> +}
> +
These lines are added here, but removed again in the next patch in the series.
Though not wrong, per-se, it just seems untidy. Perhaps the patchset order needs
to be changed somewhat?

/Bruce

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

* Re: [dpdk-dev] [PATCH v3 0/8] Add Port Hotplug support to BSD
  2015-06-29  2:56   ` [dpdk-dev] [PATCH v3 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
                       ` (7 preceding siblings ...)
  2015-06-29  2:56     ` [dpdk-dev] [PATCH v3 8/8] eal: Enable Port Hotplug as default in Linux and BSD Tetsuya Mukawa
@ 2015-06-29 15:30     ` Bruce Richardson
  2015-06-30  8:08       ` Tetsuya Mukawa
  8 siblings, 1 reply; 46+ messages in thread
From: Bruce Richardson @ 2015-06-29 15:30 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Mon, Jun 29, 2015 at 11:56:42AM +0900, Tetsuya Mukawa wrote:
> This patch series adds port hotplug support to BSD.
> Before applying, following patches should be applied.
>  - [PATCH v6 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c
>  - [PATCH v6 2/5] eal: Close file descriptor of uio configuration
>  - [PATCH v6 3/5] eal: Fix memory leaks and needless increment of pci_map_addr
>  - [PATCH v6 4/5] eal/bsdapp: Change names of pci related data structure
>  - [PATCH v6 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp
> 
> Some functions will be consolidated after applying the patches, because
> these functions are implemented in both Linux and BSD code.
> 
> PATCH v2 changes:
>  - Fix license of eal_common_pci_uio.c
> 
> PATCH v1 changes:
>  - Rebase to below latest patch series.
>    - [PATCH v6] Clean up pci uio implementations
> 
>
The majority of patches in this set seem to be more concerned with cleaning up
common code between linux and FreeBSD rather than adding hotplug support. Are those
changes better made as part of the previous patchset listed as a requirement of
this?

/Bruce

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

* Re: [dpdk-dev] [PATCH v3 1/8] eal: Add pci_uio_alloc_uio_resource()
  2015-06-29 13:24       ` Iremonger, Bernard
@ 2015-06-30  2:31         ` Tetsuya Mukawa
  0 siblings, 0 replies; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-06-30  2:31 UTC (permalink / raw)
  To: Iremonger, Bernard, dev

On 2015/06/29 22:24, Iremonger, Bernard wrote:
>
>> -----Original Message-----
>> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
>> Sent: Monday, June 29, 2015 3:57 AM
>> To: dev@dpdk.org
>> Cc: Iremonger, Bernard; david.marchand@6wind.com; Tetsuya.Mukawa
>> Subject: [PATCH v3 1/8] eal: Add pci_uio_alloc_uio_resource()
>>
>> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
>>
>> This patch adds a new function called pci_uio_alloc_uio_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>
> Hi Tetsuya,
>
> There are two comments inline below.
>
>> ---
>>  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..2d9f3a5 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_uio_resource(struct rte_pci_device *dev,
>> +		struct mapped_pci_resource **uio_res)
> The name of this function is a bit longwinded,  pci_uio_alloc_resource() might be better.

Hi Bernard,

Thanks for comments.
Sure I will fix it.

>>
>> -/* 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_uio_resource(struct rte_pci_device *dev,
>> +		struct mapped_pci_resource **uio_res)
> The name of this function is a bit longwinded,  pci_uio_alloc_resource() might be better.

Also, I will fix above.

Regards,
Tetsuya

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

* Re: [dpdk-dev] [PATCH v3 2/8] eal: Add pci_uio_map_uio_resource_by_index()
  2015-06-29 13:36       ` Iremonger, Bernard
@ 2015-06-30  2:34         ` Tetsuya Mukawa
  0 siblings, 0 replies; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-06-30  2:34 UTC (permalink / raw)
  To: Iremonger, Bernard, dev

On 2015/06/29 22:36, Iremonger, Bernard wrote:
>
>> -----Original Message-----
>> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
>> Sent: Monday, June 29, 2015 3:57 AM
>> To: dev@dpdk.org
>> Cc: Iremonger, Bernard; david.marchand@6wind.com; Tetsuya.Mukawa
>> Subject: [PATCH v3 2/8] eal: Add pci_uio_map_uio_resource_by_index()
>>
>> 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>
> Hi Tetsuya,
>
> There are two comments inline below.
>
>> ---
>>  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 2d9f3a5..61d1fe5 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_uio_resource_by_index(struct rte_pci_device *dev, int
>> res_idx,
>> +		struct mapped_pci_resource *uio_res, int map_idx) {
> The name of this function is a bit long winded, pci_uio_map_resource_by_index() might be better.
>
>> a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>> b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>> index 9e0b617..7da4543 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_uio_resource_by_index(struct rte_pci_device *dev, int
>> res_idx,
>> +		struct mapped_pci_resource *uio_res, int map_idx) {
> The name of this function is a bit long winded, pci_uio_map_resource_by_index() might be better.

I will fix above 2 issues.

Regards,
Tetsuya

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

* Re: [dpdk-dev] [PATCH v3 7/8] eal: Consolidate pci uio functions of linuxapp and bsdapp
  2015-06-29 14:03       ` Iremonger, Bernard
@ 2015-06-30  2:43         ` Tetsuya Mukawa
  2015-06-30  8:28           ` Tetsuya Mukawa
  0 siblings, 1 reply; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-06-30  2:43 UTC (permalink / raw)
  To: Iremonger, Bernard, dev

On 2015/06/29 23:03, Iremonger, Bernard wrote:
>
>> -----Original Message-----
>> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
>> Sent: Monday, June 29, 2015 3:57 AM
>> To: dev@dpdk.org
>> Cc: Iremonger, Bernard; david.marchand@6wind.com; Tetsuya.Mukawa
>> Subject: [PATCH v3 7/8] eal: Consolidate pci uio functions of linuxapp and
>> bsdapp
>>
>> 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>
> Hi Tetsuya,
>
> The copyrights of all files in this patch set should be updated to 2015.

Hi Bernard,

Could I make sure this comment?
Is it okay to change copyright of Intel like below?
- Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ Copyright(c) 2010-2015 Intel Corporation. All rights reserved.

Or do you suggest it's better to add my company copyright below Intel?

Regards,
Tetsuya

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

* Re: [dpdk-dev] [PATCH v3 4/8] eal: Consolidate rte_eal_pci_probe/close_one_driver() of linuxapp and bsdapp
  2015-06-29 15:28       ` Bruce Richardson
@ 2015-06-30  8:08         ` Tetsuya Mukawa
  2015-06-30 12:50           ` Bruce Richardson
  0 siblings, 1 reply; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-06-30  8:08 UTC (permalink / raw)
  To: Bruce Richardson; +Cc: dev

On 2015/06/30 0:28, Bruce Richardson wrote:
> On Mon, Jun 29, 2015 at 11:56:46AM +0900, Tetsuya Mukawa 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()
>>
>> 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    |  74 ++---------------
>>  lib/librte_eal/common/eal_common_pci.c | 129 ++++++++++++++++++++++++++++
>>  lib/librte_eal/common/eal_private.h    |  21 ++---
>>  lib/librte_eal/linuxapp/eal/eal_pci.c  | 148 ++-------------------------------
>>  4 files changed, 153 insertions(+), 219 deletions(-)
>>
>> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
>> index c7017eb..2a623e3 100644
>> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
>> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
>> @@ -88,7 +88,7 @@ static struct rte_tailq_elem rte_uio_tailq = {
>>  EAL_REGISTER_TAILQ(rte_uio_tailq)
>>  
>>  /* 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 "
>> @@ -430,6 +430,13 @@ skipdev:
>>  	return 0;
>>  }
>>  
>> +/* Map pci device */
>> +int
>> +pci_map_device(struct rte_pci_device *dev)
>> +{
>> +	return pci_uio_map_resource(dev);
>> +}
>> +
> These lines are added here, but removed again in the next patch in the series.
> Though not wrong, per-se, it just seems untidy. Perhaps the patchset order needs
> to be changed somewhat?
>
> /Bruce

Hi Bruce,

I appreciate your comment.
Sure, I will change the order of these patches.
Could you please check patches I will send later?

Regards,
Tetsuya

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

* Re: [dpdk-dev] [PATCH v3 0/8] Add Port Hotplug support to BSD
  2015-06-29 15:30     ` [dpdk-dev] [PATCH v3 0/8] Add Port Hotplug support to BSD Bruce Richardson
@ 2015-06-30  8:08       ` Tetsuya Mukawa
  0 siblings, 0 replies; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-06-30  8:08 UTC (permalink / raw)
  To: Bruce Richardson; +Cc: dev

On 2015/06/30 0:30, Bruce Richardson wrote:
> On Mon, Jun 29, 2015 at 11:56:42AM +0900, Tetsuya Mukawa wrote:
>> This patch series adds port hotplug support to BSD.
>> Before applying, following patches should be applied.
>>  - [PATCH v6 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c
>>  - [PATCH v6 2/5] eal: Close file descriptor of uio configuration
>>  - [PATCH v6 3/5] eal: Fix memory leaks and needless increment of pci_map_addr
>>  - [PATCH v6 4/5] eal/bsdapp: Change names of pci related data structure
>>  - [PATCH v6 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp
>>
>> Some functions will be consolidated after applying the patches, because
>> these functions are implemented in both Linux and BSD code.
>>
>> PATCH v2 changes:
>>  - Fix license of eal_common_pci_uio.c
>>
>> PATCH v1 changes:
>>  - Rebase to below latest patch series.
>>    - [PATCH v6] Clean up pci uio implementations
>>
>>
> The majority of patches in this set seem to be more concerned with cleaning up
> common code between linux and FreeBSD rather than adding hotplug support. Are those
> changes better made as part of the previous patchset listed as a requirement of
> this?
>
> /Bruce

Hi Bruce,

I will move all most all patches to previous patch series.
Also, when I move, I will just add patches to previous series for reviewers.
(I will not change previous patches at all.)

Regards,
Tetsuya

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

* [dpdk-dev] [PATCH v4] Add Port Hotplug support to BSD
  2015-06-29  2:56     ` [dpdk-dev] [PATCH v3 8/8] eal: Enable Port Hotplug as default in Linux and BSD Tetsuya Mukawa
@ 2015-06-30  8:26       ` Tetsuya Mukawa
  2015-06-30  8:26         ` [dpdk-dev] [PATCH v4] eal: Enable Port Hotplug as default in Linux and BSD Tetsuya Mukawa
  0 siblings, 1 reply; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-06-30  8:26 UTC (permalink / raw)
  To: dev

This patch adds port hotplug support to BSD.
Before applying, following patches should be applied.
 - [PATCH v7 01/12] eal: Fix coding style of eal_pci.c and eal_pci_uio.c
 - [PATCH v7 02/12] eal: Close file descriptor of uio configuration
 - [PATCH v7 03/12] eal: Fix memory leaks and needless increment of pci_map_addr
 - [PATCH v7 04/12] eal/bsdapp: Change names of pci related data structure
 - [PATCH v7 05/12] eal: Fix uio mapping differences between linuxapp and bsdapp
 - [PATCH v7 06/12] eal: Add pci_uio_alloc_resource()
 - [PATCH v7 07/12] eal: Add pci_uio_map_resource_by_index()
 - [PATCH v7 08/12] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp
 - [PATCH v7 09/12] eal: Consolidate pci_map/unmap_resource() of linuxapp and bsdapp
 - [PATCH v7 10/12] eal: Consolidate pci uio functions of linuxapp and bsdapp
 - [PATCH v7 11/12] eal: Consolidate pci_map/unmap_device() of linuxapp and bsdapp
 - [PATCH v7 12/12] eal: Consolidate rte_eal_pci_probe/close_one_driver() of linuxapp and bsdapp

PATCH v3 changes:
 - Below patches are removed.
   - 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)

PATCH v2 changes:
 - Fix license of eal_common_pci_uio.c

PATCH v1 changes:
 - Rebase to below latest patch series.
   - [PATCH v6] Clean up pci uio implementations

Tetsuya.Mukawa (1):
  eal: Enable Port Hotplug as default in Linux and BSD

 config/common_bsdapp                          |  6 ------
 config/common_linuxapp                        |  5 -----
 lib/librte_eal/bsdapp/eal/eal_pci.c           |  6 +++---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map |  6 ++++++
 lib/librte_eal/common/eal_common_dev.c        |  2 --
 lib/librte_eal/common/eal_common_pci.c        |  6 ------
 lib/librte_eal/common/eal_common_pci_uio.c    |  2 --
 lib/librte_eal/common/eal_private.h           |  2 --
 lib/librte_eal/common/include/rte_pci.h       |  2 --
 lib/librte_ether/rte_ethdev.c                 | 21 ---------------------
 10 files changed, 9 insertions(+), 49 deletions(-)

-- 
2.1.4

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

* [dpdk-dev] [PATCH v4] eal: Enable Port Hotplug as default in Linux and BSD
  2015-06-30  8:26       ` [dpdk-dev] [PATCH v4] Add Port Hotplug support to BSD Tetsuya Mukawa
@ 2015-06-30  8:26         ` Tetsuya Mukawa
  2015-06-30 15:08           ` Iremonger, Bernard
  2015-07-08 22:15           ` Thomas Monjalon
  0 siblings, 2 replies; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-06-30  8:26 UTC (permalink / raw)
  To: dev

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

This patch removes CONFIG_RTE_LIBRTE_EAL_HOTPLUG option, and enables it
as default in both Linux and BSD.
Also, to support port hotplug, rte_eal_pci_scan() and below missing
symbols should be exported to ethdev library.
 - rte_eal_parse_devargs_str()
 - rte_eal_pci_close_one()
 - rte_eal_pci_probe_one()
 - rte_eal_pci_scan()
 - rte_eal_vdev_init()
 - rte_eal_vdev_uninit()

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 config/common_bsdapp                          |  6 ------
 config/common_linuxapp                        |  5 -----
 lib/librte_eal/bsdapp/eal/eal_pci.c           |  6 +++---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map |  6 ++++++
 lib/librte_eal/common/eal_common_dev.c        |  2 --
 lib/librte_eal/common/eal_common_pci.c        |  6 ------
 lib/librte_eal/common/eal_common_pci_uio.c    |  2 --
 lib/librte_eal/common/eal_private.h           |  2 --
 lib/librte_eal/common/include/rte_pci.h       |  2 --
 lib/librte_ether/rte_ethdev.c                 | 21 ---------------------
 10 files changed, 9 insertions(+), 49 deletions(-)

diff --git a/config/common_bsdapp b/config/common_bsdapp
index 464250b..c6e6e9c 100644
--- a/config/common_bsdapp
+++ b/config/common_bsdapp
@@ -121,12 +121,6 @@ CONFIG_RTE_LIBRTE_EAL_BSDAPP=y
 CONFIG_RTE_LIBRTE_EAL_LINUXAPP=n
 
 #
-# Compile Environment Abstraction Layer to support hotplug
-# So far, Hotplug functions only support linux
-#
-CONFIG_RTE_LIBRTE_EAL_HOTPLUG=n
-
-#
 # Compile Environment Abstraction Layer to support Vmware TSC map
 #
 CONFIG_RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT=y
diff --git a/config/common_linuxapp b/config/common_linuxapp
index aae22f4..c33a6fe 100644
--- a/config/common_linuxapp
+++ b/config/common_linuxapp
@@ -119,11 +119,6 @@ CONFIG_RTE_PCI_MAX_READ_REQUEST_SIZE=0
 CONFIG_RTE_LIBRTE_EAL_LINUXAPP=y
 
 #
-# Compile Environment Abstraction Layer to support hotplug
-#
-CONFIG_RTE_LIBRTE_EAL_HOTPLUG=y
-
-#
 # Compile Environment Abstraction Layer to support Vmware TSC map
 #
 CONFIG_RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT=y
diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 508cfa7..0724c45 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -309,8 +309,8 @@ skipdev:
  * Scan the content of the PCI bus, and add the devices in the devices
  * list. Call pci_scan_one() for each pci entry found.
  */
-static int
-pci_scan(void)
+int
+rte_eal_pci_scan(void)
 {
 	int fd;
 	unsigned dev_count = 0;
@@ -366,7 +366,7 @@ rte_eal_pci_init(void)
 	if (internal_config.no_pci)
 		return 0;
 
-	if (pci_scan() < 0) {
+	if (rte_eal_pci_scan() < 0) {
 		RTE_LOG(ERR, EAL, "%s(): Cannot scan PCI bus\n", __func__);
 		return -1;
 	}
diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 67b6a6c..7e850a9 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -37,14 +37,20 @@ DPDK_2.0 {
 	rte_eal_lcore_role;
 	rte_eal_mp_remote_launch;
 	rte_eal_mp_wait_lcore;
+	rte_eal_parse_devargs_str;
+	rte_eal_pci_close_one;
 	rte_eal_pci_dump;
 	rte_eal_pci_probe;
+	rte_eal_pci_probe_one;
 	rte_eal_pci_register;
+	rte_eal_pci_scan;
 	rte_eal_pci_unregister;
 	rte_eal_process_type;
 	rte_eal_remote_launch;
 	rte_eal_tailq_lookup;
 	rte_eal_tailq_register;
+	rte_eal_vdev_init;
+	rte_eal_vdev_uninit;
 	rte_eal_wait_lcore;
 	rte_exit;
 	rte_get_hpet_cycles;
diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 92a5a94..4089d66 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -125,7 +125,6 @@ rte_eal_dev_init(void)
 	return 0;
 }
 
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
 int
 rte_eal_vdev_uninit(const char *name)
 {
@@ -151,4 +150,3 @@ rte_eal_vdev_uninit(const char *name)
 	RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
 	return -EINVAL;
 }
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 8ef8057..3805aed 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -167,7 +167,6 @@ pci_map_device(struct rte_pci_device *dev)
 	return ret;
 }
 
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
 /* Unmap pci device */
 static void
 pci_unmap_device(struct rte_pci_device *dev)
@@ -192,7 +191,6 @@ pci_unmap_device(struct rte_pci_device *dev)
 		break;
 	}
 }
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
 
 /*
  * If vendor/device ID match, call the devinit() function of the
@@ -265,7 +263,6 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *d
 	return 1;
 }
 
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
 /*
  * If vendor/device ID match, call the devuninit() function of the
  * driver.
@@ -321,7 +318,6 @@ rte_eal_pci_close_one_driver(struct rte_pci_driver *dr,
 	/* 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
@@ -350,7 +346,6 @@ pci_probe_all_drivers(struct rte_pci_device *dev)
 	return 1;
 }
 
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
 /*
  * If vendor/device ID match, call the devuninit() function of all
  * registered driver for the given device. Return -1 if initialization
@@ -441,7 +436,6 @@ err_return:
 			dev->addr.devid, dev->addr.function);
 	return -1;
 }
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
 
 /*
  * Scan the content of the PCI bus, and call the devinit() function for
diff --git a/lib/librte_eal/common/eal_common_pci_uio.c b/lib/librte_eal/common/eal_common_pci_uio.c
index bf29484..bb38498 100644
--- a/lib/librte_eal/common/eal_common_pci_uio.c
+++ b/lib/librte_eal/common/eal_common_pci_uio.c
@@ -194,7 +194,6 @@ free_uio_res:
 	return -1;
 }
 
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
 static void
 pci_uio_unmap(struct mapped_pci_resource *uio_res)
 {
@@ -267,4 +266,3 @@ pci_uio_unmap_resource(struct rte_pci_device *dev)
 	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 216c098..6c9ac1a 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -174,14 +174,12 @@ int pci_unbind_kernel_driver(struct rte_pci_device *dev);
  */
 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 */
 
 /**
  * Allocate uio resource for PCI device
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index 475d2dc..a8b6a10 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -376,7 +376,6 @@ void *pci_map_resource(void *requested_addr, int fd, off_t offset,
  */
 void pci_unmap_resource(void *requested_addr, size_t size);
 
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
 /**
  * Probe the single PCI device.
  *
@@ -406,7 +405,6 @@ int rte_eal_pci_probe_one(const struct rte_pci_addr *addr);
  *   - Negative on error.
  */
 int rte_eal_pci_close_one(const struct rte_pci_addr *addr);
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
 
 /**
  * Dump the content of the PCI bus.
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 1822258..43b9fcc 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -425,9 +425,6 @@ rte_eth_dev_count(void)
 	return nb_ports;
 }
 
-/* So far, DPDK hotplug function only supports linux */
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
-
 static enum rte_eth_dev_type
 rte_eth_dev_get_device_type(uint8_t port_id)
 {
@@ -708,24 +705,6 @@ rte_eth_dev_detach(uint8_t port_id, char *name)
 	} else
 		return rte_eth_dev_detach_vdev(port_id, name);
 }
-#else /* RTE_LIBRTE_EAL_HOTPLUG */
-int
-rte_eth_dev_attach(const char *devargs __rte_unused,
-			uint8_t *port_id __rte_unused)
-{
-	RTE_LOG(ERR, EAL, "Hotplug support isn't enabled\n");
-	return -1;
-}
-
-/* detach the device, then store the name of the device */
-int
-rte_eth_dev_detach(uint8_t port_id __rte_unused,
-			char *name __rte_unused)
-{
-	RTE_LOG(ERR, EAL, "Hotplug support isn't enabled\n");
-	return -1;
-}
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
 
 static int
 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
-- 
2.1.4

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

* Re: [dpdk-dev] [PATCH v3 7/8] eal: Consolidate pci uio functions of linuxapp and bsdapp
  2015-06-30  2:43         ` Tetsuya Mukawa
@ 2015-06-30  8:28           ` Tetsuya Mukawa
  0 siblings, 0 replies; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-06-30  8:28 UTC (permalink / raw)
  To: Iremonger, Bernard, dev

On 2015/06/30 11:43, Tetsuya Mukawa wrote:
> On 2015/06/29 23:03, Iremonger, Bernard wrote:
>>> -----Original Message-----
>>> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
>>> Sent: Monday, June 29, 2015 3:57 AM
>>> To: dev@dpdk.org
>>> Cc: Iremonger, Bernard; david.marchand@6wind.com; Tetsuya.Mukawa
>>> Subject: [PATCH v3 7/8] eal: Consolidate pci uio functions of linuxapp and
>>> bsdapp
>>>
>>> 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>
>> Hi Tetsuya,
>>
>> The copyrights of all files in this patch set should be updated to 2015.
> Hi Bernard,
>
> Could I make sure this comment?
> Is it okay to change copyright of Intel like below?
> - Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
> + Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
>
> Or do you suggest it's better to add my company copyright below Intel?
>
> Regards,
> Tetsuya
>

Hi Bernard,

I haven't involved this fixing in latest patch series.
(Probably deadline will come soon, but my patches still have some
comments, so I will submit the patches that fix such issues.)
Even if we need to change copyright, it'll be very easy. In the case, I
will send new version patch series to fix it.

Regards,
Tetsuya

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

* Re: [dpdk-dev] [PATCH v3 4/8] eal: Consolidate rte_eal_pci_probe/close_one_driver() of linuxapp and bsdapp
  2015-06-30  8:08         ` Tetsuya Mukawa
@ 2015-06-30 12:50           ` Bruce Richardson
  0 siblings, 0 replies; 46+ messages in thread
From: Bruce Richardson @ 2015-06-30 12:50 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Tue, Jun 30, 2015 at 05:08:41PM +0900, Tetsuya Mukawa wrote:
> On 2015/06/30 0:28, Bruce Richardson wrote:
> > On Mon, Jun 29, 2015 at 11:56:46AM +0900, Tetsuya Mukawa 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()
> >>
> >> 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    |  74 ++---------------
> >>  lib/librte_eal/common/eal_common_pci.c | 129 ++++++++++++++++++++++++++++
> >>  lib/librte_eal/common/eal_private.h    |  21 ++---
> >>  lib/librte_eal/linuxapp/eal/eal_pci.c  | 148 ++-------------------------------
> >>  4 files changed, 153 insertions(+), 219 deletions(-)
> >>
> >> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
> >> index c7017eb..2a623e3 100644
> >> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> >> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> >> @@ -88,7 +88,7 @@ static struct rte_tailq_elem rte_uio_tailq = {
> >>  EAL_REGISTER_TAILQ(rte_uio_tailq)
> >>  
> >>  /* 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 "
> >> @@ -430,6 +430,13 @@ skipdev:
> >>  	return 0;
> >>  }
> >>  
> >> +/* Map pci device */
> >> +int
> >> +pci_map_device(struct rte_pci_device *dev)
> >> +{
> >> +	return pci_uio_map_resource(dev);
> >> +}
> >> +
> > These lines are added here, but removed again in the next patch in the series.
> > Though not wrong, per-se, it just seems untidy. Perhaps the patchset order needs
> > to be changed somewhat?
> >
> > /Bruce
> 
> Hi Bruce,
> 
> I appreciate your comment.
> Sure, I will change the order of these patches.
> Could you please check patches I will send later?
>
Yes, I'll test them on FreeBSD shortly.

/Bruce

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

* Re: [dpdk-dev] [PATCH v4] eal: Enable Port Hotplug as default in Linux and BSD
  2015-06-30  8:26         ` [dpdk-dev] [PATCH v4] eal: Enable Port Hotplug as default in Linux and BSD Tetsuya Mukawa
@ 2015-06-30 15:08           ` Iremonger, Bernard
  2015-06-30 15:40             ` Bruce Richardson
  2015-07-08 22:15           ` Thomas Monjalon
  1 sibling, 1 reply; 46+ messages in thread
From: Iremonger, Bernard @ 2015-06-30 15:08 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev


> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Tuesday, June 30, 2015 9:27 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; david.marchand@6wind.com; Richardson, Bruce;
> Tetsuya.Mukawa
> Subject: [PATCH v4] eal: Enable Port Hotplug as default in Linux and BSD
> 
> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
> 
> This patch removes CONFIG_RTE_LIBRTE_EAL_HOTPLUG option, and enables
> it as default in both Linux and BSD.
> Also, to support port hotplug, rte_eal_pci_scan() and below missing symbols
> should be exported to ethdev library.
>  - rte_eal_parse_devargs_str()
>  - rte_eal_pci_close_one()
>  - rte_eal_pci_probe_one()
>  - rte_eal_pci_scan()
>  - rte_eal_vdev_init()
>  - rte_eal_vdev_uninit()
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>

Hi Tetsuya,

Would it be cleaner to add this patch to the  [PATCH  v7 12/12] patch set as  patch 13 rather than having it as a separate patch?

Regards,

Bernard.
 
> ---
>  config/common_bsdapp                          |  6 ------
>  config/common_linuxapp                        |  5 -----
>  lib/librte_eal/bsdapp/eal/eal_pci.c           |  6 +++---
>  lib/librte_eal/bsdapp/eal/rte_eal_version.map |  6 ++++++
>  lib/librte_eal/common/eal_common_dev.c        |  2 --
>  lib/librte_eal/common/eal_common_pci.c        |  6 ------
>  lib/librte_eal/common/eal_common_pci_uio.c    |  2 --
>  lib/librte_eal/common/eal_private.h           |  2 --
>  lib/librte_eal/common/include/rte_pci.h       |  2 --
>  lib/librte_ether/rte_ethdev.c                 | 21 ---------------------
>  10 files changed, 9 insertions(+), 49 deletions(-)
> 
> diff --git a/config/common_bsdapp b/config/common_bsdapp index
> 464250b..c6e6e9c 100644
> --- a/config/common_bsdapp
> +++ b/config/common_bsdapp
> @@ -121,12 +121,6 @@ CONFIG_RTE_LIBRTE_EAL_BSDAPP=y
> CONFIG_RTE_LIBRTE_EAL_LINUXAPP=n
> 
>  #
> -# Compile Environment Abstraction Layer to support hotplug -# So far,
> Hotplug functions only support linux -# -
> CONFIG_RTE_LIBRTE_EAL_HOTPLUG=n
> -
> -#
>  # Compile Environment Abstraction Layer to support Vmware TSC map  #
> CONFIG_RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT=y
> diff --git a/config/common_linuxapp b/config/common_linuxapp index
> aae22f4..c33a6fe 100644
> --- a/config/common_linuxapp
> +++ b/config/common_linuxapp
> @@ -119,11 +119,6 @@ CONFIG_RTE_PCI_MAX_READ_REQUEST_SIZE=0
>  CONFIG_RTE_LIBRTE_EAL_LINUXAPP=y
> 
>  #
> -# Compile Environment Abstraction Layer to support hotplug -# -
> CONFIG_RTE_LIBRTE_EAL_HOTPLUG=y
> -
> -#
>  # Compile Environment Abstraction Layer to support Vmware TSC map  #
> CONFIG_RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT=y
> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c
> b/lib/librte_eal/bsdapp/eal/eal_pci.c
> index 508cfa7..0724c45 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> @@ -309,8 +309,8 @@ skipdev:
>   * Scan the content of the PCI bus, and add the devices in the devices
>   * list. Call pci_scan_one() for each pci entry found.
>   */
> -static int
> -pci_scan(void)
> +int
> +rte_eal_pci_scan(void)
>  {
>  	int fd;
>  	unsigned dev_count = 0;
> @@ -366,7 +366,7 @@ rte_eal_pci_init(void)
>  	if (internal_config.no_pci)
>  		return 0;
> 
> -	if (pci_scan() < 0) {
> +	if (rte_eal_pci_scan() < 0) {
>  		RTE_LOG(ERR, EAL, "%s(): Cannot scan PCI bus\n",
> __func__);
>  		return -1;
>  	}
> diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> index 67b6a6c..7e850a9 100644
> --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> @@ -37,14 +37,20 @@ DPDK_2.0 {
>  	rte_eal_lcore_role;
>  	rte_eal_mp_remote_launch;
>  	rte_eal_mp_wait_lcore;
> +	rte_eal_parse_devargs_str;
> +	rte_eal_pci_close_one;
>  	rte_eal_pci_dump;
>  	rte_eal_pci_probe;
> +	rte_eal_pci_probe_one;
>  	rte_eal_pci_register;
> +	rte_eal_pci_scan;
>  	rte_eal_pci_unregister;
>  	rte_eal_process_type;
>  	rte_eal_remote_launch;
>  	rte_eal_tailq_lookup;
>  	rte_eal_tailq_register;
> +	rte_eal_vdev_init;
> +	rte_eal_vdev_uninit;
>  	rte_eal_wait_lcore;
>  	rte_exit;
>  	rte_get_hpet_cycles;
> diff --git a/lib/librte_eal/common/eal_common_dev.c
> b/lib/librte_eal/common/eal_common_dev.c
> index 92a5a94..4089d66 100644
> --- a/lib/librte_eal/common/eal_common_dev.c
> +++ b/lib/librte_eal/common/eal_common_dev.c
> @@ -125,7 +125,6 @@ rte_eal_dev_init(void)
>  	return 0;
>  }
> 
> -#ifdef RTE_LIBRTE_EAL_HOTPLUG
>  int
>  rte_eal_vdev_uninit(const char *name)
>  {
> @@ -151,4 +150,3 @@ rte_eal_vdev_uninit(const char *name)
>  	RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
>  	return -EINVAL;
>  }
> -#endif /* RTE_LIBRTE_EAL_HOTPLUG */
> diff --git a/lib/librte_eal/common/eal_common_pci.c
> b/lib/librte_eal/common/eal_common_pci.c
> index 8ef8057..3805aed 100644
> --- a/lib/librte_eal/common/eal_common_pci.c
> +++ b/lib/librte_eal/common/eal_common_pci.c
> @@ -167,7 +167,6 @@ pci_map_device(struct rte_pci_device *dev)
>  	return ret;
>  }
> 
> -#ifdef RTE_LIBRTE_EAL_HOTPLUG
>  /* Unmap pci device */
>  static void
>  pci_unmap_device(struct rte_pci_device *dev) @@ -192,7 +191,6 @@
> pci_unmap_device(struct rte_pci_device *dev)
>  		break;
>  	}
>  }
> -#endif /* RTE_LIBRTE_EAL_HOTPLUG */
> 
>  /*
>   * If vendor/device ID match, call the devinit() function of the @@ -265,7
> +263,6 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct
> rte_pci_device *d
>  	return 1;
>  }
> 
> -#ifdef RTE_LIBRTE_EAL_HOTPLUG
>  /*
>   * If vendor/device ID match, call the devuninit() function of the
>   * driver.
> @@ -321,7 +318,6 @@ rte_eal_pci_close_one_driver(struct rte_pci_driver
> *dr,
>  	/* 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 @@ -350,7
> +346,6 @@ pci_probe_all_drivers(struct rte_pci_device *dev)
>  	return 1;
>  }
> 
> -#ifdef RTE_LIBRTE_EAL_HOTPLUG
>  /*
>   * If vendor/device ID match, call the devuninit() function of all
>   * registered driver for the given device. Return -1 if initialization @@ -441,7
> +436,6 @@ err_return:
>  			dev->addr.devid, dev->addr.function);
>  	return -1;
>  }
> -#endif /* RTE_LIBRTE_EAL_HOTPLUG */
> 
>  /*
>   * Scan the content of the PCI bus, and call the devinit() function for diff --git
> a/lib/librte_eal/common/eal_common_pci_uio.c
> b/lib/librte_eal/common/eal_common_pci_uio.c
> index bf29484..bb38498 100644
> --- a/lib/librte_eal/common/eal_common_pci_uio.c
> +++ b/lib/librte_eal/common/eal_common_pci_uio.c
> @@ -194,7 +194,6 @@ free_uio_res:
>  	return -1;
>  }
> 
> -#ifdef RTE_LIBRTE_EAL_HOTPLUG
>  static void
>  pci_uio_unmap(struct mapped_pci_resource *uio_res)  { @@ -267,4 +266,3
> @@ pci_uio_unmap_resource(struct rte_pci_device *dev)
>  	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 216c098..6c9ac1a 100644
> --- a/lib/librte_eal/common/eal_private.h
> +++ b/lib/librte_eal/common/eal_private.h
> @@ -174,14 +174,12 @@ int pci_unbind_kernel_driver(struct rte_pci_device
> *dev);
>   */
>  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 */
> 
>  /**
>   * Allocate uio resource for PCI device diff --git
> a/lib/librte_eal/common/include/rte_pci.h
> b/lib/librte_eal/common/include/rte_pci.h
> index 475d2dc..a8b6a10 100644
> --- a/lib/librte_eal/common/include/rte_pci.h
> +++ b/lib/librte_eal/common/include/rte_pci.h
> @@ -376,7 +376,6 @@ void *pci_map_resource(void *requested_addr, int
> fd, off_t offset,
>   */
>  void pci_unmap_resource(void *requested_addr, size_t size);
> 
> -#ifdef RTE_LIBRTE_EAL_HOTPLUG
>  /**
>   * Probe the single PCI device.
>   *
> @@ -406,7 +405,6 @@ int rte_eal_pci_probe_one(const struct rte_pci_addr
> *addr);
>   *   - Negative on error.
>   */
>  int rte_eal_pci_close_one(const struct rte_pci_addr *addr); -#endif /*
> RTE_LIBRTE_EAL_HOTPLUG */
> 
>  /**
>   * Dump the content of the PCI bus.
> diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
> index 1822258..43b9fcc 100644
> --- a/lib/librte_ether/rte_ethdev.c
> +++ b/lib/librte_ether/rte_ethdev.c
> @@ -425,9 +425,6 @@ rte_eth_dev_count(void)
>  	return nb_ports;
>  }
> 
> -/* So far, DPDK hotplug function only supports linux */ -#ifdef
> RTE_LIBRTE_EAL_HOTPLUG
> -
>  static enum rte_eth_dev_type
>  rte_eth_dev_get_device_type(uint8_t port_id)  { @@ -708,24 +705,6 @@
> rte_eth_dev_detach(uint8_t port_id, char *name)
>  	} else
>  		return rte_eth_dev_detach_vdev(port_id, name);  } -#else
> /* RTE_LIBRTE_EAL_HOTPLUG */ -int -rte_eth_dev_attach(const char
> *devargs __rte_unused,
> -			uint8_t *port_id __rte_unused)
> -{
> -	RTE_LOG(ERR, EAL, "Hotplug support isn't enabled\n");
> -	return -1;
> -}
> -
> -/* detach the device, then store the name of the device */ -int -
> rte_eth_dev_detach(uint8_t port_id __rte_unused,
> -			char *name __rte_unused)
> -{
> -	RTE_LOG(ERR, EAL, "Hotplug support isn't enabled\n");
> -	return -1;
> -}
> -#endif /* RTE_LIBRTE_EAL_HOTPLUG */
> 
>  static int
>  rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t
> nb_queues)
> --
> 2.1.4

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

* Re: [dpdk-dev] [PATCH v4] eal: Enable Port Hotplug as default in Linux and BSD
  2015-06-30 15:08           ` Iremonger, Bernard
@ 2015-06-30 15:40             ` Bruce Richardson
  2015-07-01  6:37               ` Tetsuya Mukawa
  0 siblings, 1 reply; 46+ messages in thread
From: Bruce Richardson @ 2015-06-30 15:40 UTC (permalink / raw)
  To: Iremonger, Bernard; +Cc: dev

On Tue, Jun 30, 2015 at 04:08:08PM +0100, Iremonger, Bernard wrote:
> 
> > -----Original Message-----
> > From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> > Sent: Tuesday, June 30, 2015 9:27 AM
> > To: dev@dpdk.org
> > Cc: Iremonger, Bernard; david.marchand@6wind.com; Richardson, Bruce;
> > Tetsuya.Mukawa
> > Subject: [PATCH v4] eal: Enable Port Hotplug as default in Linux and BSD
> > 
> > From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
> > 
> > This patch removes CONFIG_RTE_LIBRTE_EAL_HOTPLUG option, and enables
> > it as default in both Linux and BSD.
> > Also, to support port hotplug, rte_eal_pci_scan() and below missing symbols
> > should be exported to ethdev library.
> >  - rte_eal_parse_devargs_str()
> >  - rte_eal_pci_close_one()
> >  - rte_eal_pci_probe_one()
> >  - rte_eal_pci_scan()
> >  - rte_eal_vdev_init()
> >  - rte_eal_vdev_uninit()
> > 
> > Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> 
> Hi Tetsuya,
> 
> Would it be cleaner to add this patch to the  [PATCH  v7 12/12] patch set as  patch 13 rather than having it as a separate patch?
>
The other patch set is cleanup, merging BSD and Linuxapp code, so I think it's
best kept as a separate set. New features I'd suggest keeping separate from
cleanup. 
That being said, it is only one patch, so it probably doesn't matter much either
way. :-)

/Bruce

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

* Re: [dpdk-dev] [PATCH v4] eal: Enable Port Hotplug as default in Linux and BSD
  2015-06-30 15:40             ` Bruce Richardson
@ 2015-07-01  6:37               ` Tetsuya Mukawa
  0 siblings, 0 replies; 46+ messages in thread
From: Tetsuya Mukawa @ 2015-07-01  6:37 UTC (permalink / raw)
  To: Bruce Richardson, Iremonger, Bernard; +Cc: dev

On 2015/07/01 0:40, Bruce Richardson wrote:
> On Tue, Jun 30, 2015 at 04:08:08PM +0100, Iremonger, Bernard wrote:
>>> -----Original Message-----
>>> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
>>> Sent: Tuesday, June 30, 2015 9:27 AM
>>> To: dev@dpdk.org
>>> Cc: Iremonger, Bernard; david.marchand@6wind.com; Richardson, Bruce;
>>> Tetsuya.Mukawa
>>> Subject: [PATCH v4] eal: Enable Port Hotplug as default in Linux and BSD
>>>
>>> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
>>>
>>> This patch removes CONFIG_RTE_LIBRTE_EAL_HOTPLUG option, and enables
>>> it as default in both Linux and BSD.
>>> Also, to support port hotplug, rte_eal_pci_scan() and below missing symbols
>>> should be exported to ethdev library.
>>>  - rte_eal_parse_devargs_str()
>>>  - rte_eal_pci_close_one()
>>>  - rte_eal_pci_probe_one()
>>>  - rte_eal_pci_scan()
>>>  - rte_eal_vdev_init()
>>>  - rte_eal_vdev_uninit()
>>>
>>> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
>> Hi Tetsuya,
>>
>> Would it be cleaner to add this patch to the  [PATCH  v7 12/12] patch set as  patch 13 rather than having it as a separate patch?
>>
> The other patch set is cleanup, merging BSD and Linuxapp code, so I think it's
> best kept as a separate set. New features I'd suggest keeping separate from
> cleanup. 
> That being said, it is only one patch, so it probably doesn't matter much either
> way. :-)
>
> /Bruce

Thanks for commenting. Let's keep separating.
It will be easy for me to write cover-letter of the patch series.

Regards,
Tetsuya

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

* Re: [dpdk-dev] [PATCH v4] eal: Enable Port Hotplug as default in Linux and BSD
  2015-06-30  8:26         ` [dpdk-dev] [PATCH v4] eal: Enable Port Hotplug as default in Linux and BSD Tetsuya Mukawa
  2015-06-30 15:08           ` Iremonger, Bernard
@ 2015-07-08 22:15           ` Thomas Monjalon
  1 sibling, 0 replies; 46+ messages in thread
From: Thomas Monjalon @ 2015-07-08 22:15 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

2015-06-30 17:26, Tetsuya Mukawa:
> This patch removes CONFIG_RTE_LIBRTE_EAL_HOTPLUG option, and enables it
> as default in both Linux and BSD.
> Also, to support port hotplug, rte_eal_pci_scan() and below missing
> symbols should be exported to ethdev library.
>  - rte_eal_parse_devargs_str()
>  - rte_eal_pci_close_one()
>  - rte_eal_pci_probe_one()
>  - rte_eal_pci_scan()
>  - rte_eal_vdev_init()
>  - rte_eal_vdev_uninit()
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>

Applied, thanks

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

end of thread, other threads:[~2015-07-08 22:16 UTC | newest]

Thread overview: 46+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-19  6:21 [dpdk-dev] [PATCH 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
2015-05-19  6:21 ` [dpdk-dev] [PATCH 1/8] eal: Add pci_uio_alloc_uio_resource() Tetsuya Mukawa
2015-05-19  6:21 ` [dpdk-dev] [PATCH 2/8] eal: Add pci_uio_map_uio_resource_by_index() Tetsuya Mukawa
2015-05-19  6:21 ` [dpdk-dev] [PATCH 3/8] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp Tetsuya Mukawa
2015-05-19  6:21 ` [dpdk-dev] [PATCH 4/8] eal: Consolidate rte_eal_pci_probe/close_one_driver() " Tetsuya Mukawa
2015-06-26  8:21   ` [dpdk-dev] [PATCH v2 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
2015-06-26  8:21     ` [dpdk-dev] [PATCH v2 1/8] eal: Add pci_uio_alloc_uio_resource() Tetsuya Mukawa
2015-06-26  8:21     ` [dpdk-dev] [PATCH v2 2/8] eal: Add pci_uio_map_uio_resource_by_index() Tetsuya Mukawa
2015-06-26  8:21     ` [dpdk-dev] [PATCH v2 3/8] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp Tetsuya Mukawa
2015-06-26  8:21     ` [dpdk-dev] [PATCH v2 4/8] eal: Consolidate rte_eal_pci_probe/close_one_driver() " Tetsuya Mukawa
2015-06-26  8:21     ` [dpdk-dev] [PATCH v2 5/8] eal: Consolidate pci_map/unmap_device() " Tetsuya Mukawa
2015-06-26  8:21     ` [dpdk-dev] [PATCH v2 6/8] eal: Consolidate pci_map/unmap_resource() " Tetsuya Mukawa
2015-06-26  8:21     ` [dpdk-dev] [PATCH v2 7/8] eal: Consolidate pci uio functions " Tetsuya Mukawa
2015-06-26  8:21     ` [dpdk-dev] [PATCH v2 8/8] eal: Enable Port Hotplug as default in Linux and BSD Tetsuya Mukawa
2015-06-29  2:56   ` [dpdk-dev] [PATCH v3 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
2015-06-29  2:56     ` [dpdk-dev] [PATCH v3 1/8] eal: Add pci_uio_alloc_uio_resource() Tetsuya Mukawa
2015-06-29 13:24       ` Iremonger, Bernard
2015-06-30  2:31         ` Tetsuya Mukawa
2015-06-29  2:56     ` [dpdk-dev] [PATCH v3 2/8] eal: Add pci_uio_map_uio_resource_by_index() Tetsuya Mukawa
2015-06-29 13:36       ` Iremonger, Bernard
2015-06-30  2:34         ` Tetsuya Mukawa
2015-06-29  2:56     ` [dpdk-dev] [PATCH v3 3/8] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp Tetsuya Mukawa
2015-06-29  2:56     ` [dpdk-dev] [PATCH v3 4/8] eal: Consolidate rte_eal_pci_probe/close_one_driver() " Tetsuya Mukawa
2015-06-29 15:28       ` Bruce Richardson
2015-06-30  8:08         ` Tetsuya Mukawa
2015-06-30 12:50           ` Bruce Richardson
2015-06-29  2:56     ` [dpdk-dev] [PATCH v3 5/8] eal: Consolidate pci_map/unmap_device() " Tetsuya Mukawa
2015-06-29  2:56     ` [dpdk-dev] [PATCH v3 6/8] eal: Consolidate pci_map/unmap_resource() " Tetsuya Mukawa
2015-06-29  2:56     ` [dpdk-dev] [PATCH v3 7/8] eal: Consolidate pci uio functions " Tetsuya Mukawa
2015-06-29 14:03       ` Iremonger, Bernard
2015-06-30  2:43         ` Tetsuya Mukawa
2015-06-30  8:28           ` Tetsuya Mukawa
2015-06-29  2:56     ` [dpdk-dev] [PATCH v3 8/8] eal: Enable Port Hotplug as default in Linux and BSD Tetsuya Mukawa
2015-06-30  8:26       ` [dpdk-dev] [PATCH v4] Add Port Hotplug support to BSD Tetsuya Mukawa
2015-06-30  8:26         ` [dpdk-dev] [PATCH v4] eal: Enable Port Hotplug as default in Linux and BSD Tetsuya Mukawa
2015-06-30 15:08           ` Iremonger, Bernard
2015-06-30 15:40             ` Bruce Richardson
2015-07-01  6:37               ` Tetsuya Mukawa
2015-07-08 22:15           ` Thomas Monjalon
2015-06-29 15:30     ` [dpdk-dev] [PATCH v3 0/8] Add Port Hotplug support to BSD Bruce Richardson
2015-06-30  8:08       ` Tetsuya Mukawa
2015-05-19  6:21 ` [dpdk-dev] [PATCH 5/8] eal: Consolidate pci_map/unmap_device() of linuxapp and bsdapp Tetsuya Mukawa
2015-05-19  6:21 ` [dpdk-dev] [PATCH 6/8] eal: Consolidate pci_map/unmap_resource() " Tetsuya Mukawa
2015-05-19  6:21 ` [dpdk-dev] [PATCH 7/8] eal: Consolidate pci uio functions " Tetsuya Mukawa
2015-05-19  6:21 ` [dpdk-dev] [PATCH 8/8] eal: Enable Port Hotplug as default in Linux and BSD Tetsuya Mukawa
2015-05-19 16:03 ` [dpdk-dev] [PATCH 0/8] Add Port Hotplug support to BSD Stephen Hemminger

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