DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 1/3] BSD: Support Port Hotplug function
@ 2015-03-04  3:11 Tetsuya Mukawa
  2015-03-04  3:11 ` [dpdk-dev] [PATCH 2/3] eal, ethdev: Remove CONFIG_RTE_LIBRTE_EAL_HOTPLUG Tetsuya Mukawa
                   ` (3 more replies)
  0 siblings, 4 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-04  3:11 UTC (permalink / raw)
  To: dev

This patch adds Hotplug support to BSD.

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c           | 169 +++++++++++++++++++++++++-
 lib/librte_eal/bsdapp/eal/rte_eal_version.map |   6 +
 lib/librte_eal/common/include/rte_pci.h       |   1 +
 lib/librte_ether/rte_ethdev.c                 |   1 +
 4 files changed, 174 insertions(+), 3 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 9193f80..fc5a088 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -156,6 +156,26 @@ fail:
 	return NULL;
 }
 
+/* unmap a particular resource */
+static int
+pci_unmap_resource(void *requested_addr, size_t size)
+{
+	if (requested_addr == NULL)
+		return -EINVAL;
+
+	/* 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);
+		return -EFAULT;
+	}
+	return 0;
+}
+
 static int
 pci_uio_map_secondary(struct rte_pci_device *dev)
 {
@@ -270,6 +290,76 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	return (0);
 }
 
+static int
+pci_uio_unmap(struct uio_resource *uio_res)
+{
+	int ret;
+	unsigned i;
+
+	if (uio_res == NULL)
+		return -EINVAL;
+
+	for (i = 0; i != uio_res->nb_maps; i++) {
+		ret = pci_unmap_resource(uio_res->maps[i].addr,
+				(size_t)uio_res->maps[i].size);
+		if (ret < 0)
+			return ret;
+	}
+	return 0;
+}
+
+static struct uio_resource *
+pci_uio_find_resource(struct rte_pci_device *dev)
+{
+	struct uio_resource *uio_res;
+
+	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;
+}
+
+/* map the PCI resource of a PCI device in virtual memory */
+static int
+pci_uio_unmap_resource(struct rte_pci_device *dev)
+{
+	struct uio_resource *uio_res;
+
+	if (dev == NULL)
+		return -EINVAL;
+
+	/* find an entry for the device */
+	uio_res = pci_uio_find_resource(dev);
+	if (uio_res == NULL)
+		return -ENODEV;
+
+	/* 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;
+	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+
+	return 0;
+}
+
 /* 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)
@@ -307,6 +397,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->pt_driver = RTE_PT_NIC_UIO;
+
 /* parse resources */
 	switch (conf->pc_hdr & PCIM_HDRTYPE) {
 	case PCIM_HDRTYPE_NORMAL:
@@ -376,8 +469,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 = -1;
 	unsigned dev_count = 0;
@@ -487,6 +580,76 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *d
 	return 1;
 }
 
+/*
+ * 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)
+{
+	struct rte_pci_id *id_table;
+	int ret;
+
+	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);
+
+		/* 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;
+		}
+
+		/* 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) {
+			/* map resources for devices that use igb_uio */
+			ret = pci_uio_unmap_resource(dev);
+			if (ret != 0)
+				return ret;
+		}
+	}
+	/* return positive value if driver is not found */
+	return 1;
+}
+
 /* Init the PCI EAL subsystem */
 int
 rte_eal_pci_init(void)
@@ -499,7 +662,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 d83524d..54f5ff1 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -37,9 +37,13 @@ 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;
@@ -47,6 +51,8 @@ DPDK_2.0 {
 	rte_eal_tailq_lookup_by_idx;
 	rte_eal_tailq_reserve;
 	rte_eal_tailq_reserve_by_idx;
+	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/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index b9cdf8b..dc74821 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_pt_driver {
 	RTE_PT_IGB_UIO		= 1,
 	RTE_PT_VFIO		= 2,
 	RTE_PT_UIO_GENERIC	= 3,
+	RTE_PT_NIC_UIO		= 4, /* Driver for BSD */
 };
 
 /**
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 6ea7a17..9687fab 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -516,6 +516,7 @@ rte_eth_dev_is_detachable(uint8_t port_id)
 		switch (rte_eth_devices[port_id].pci_dev->pt_driver) {
 		case RTE_PT_IGB_UIO:
 		case RTE_PT_UIO_GENERIC:
+		case RTE_PT_NIC_UIO:
 			break;
 		case RTE_PT_VFIO:
 		default:
-- 
1.9.1

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

* [dpdk-dev] [PATCH 2/3] eal, ethdev: Remove CONFIG_RTE_LIBRTE_EAL_HOTPLUG
  2015-03-04  3:11 [dpdk-dev] [PATCH 1/3] BSD: Support Port Hotplug function Tetsuya Mukawa
@ 2015-03-04  3:11 ` Tetsuya Mukawa
  2015-03-04  3:11 ` [dpdk-dev] [PATCH 3/3] doc: Remove BSD limitation from hotplug section of programmer's guide Tetsuya Mukawa
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-04  3:11 UTC (permalink / raw)
  To: dev

The patch removes CONFIG_RTE_LIBRTE_EAL_HOTPLUG option from DPDK.

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 config/common_bsdapp                       |  6 ------
 config/common_linuxapp                     |  5 -----
 lib/librte_eal/common/eal_common_dev.c     |  2 --
 lib/librte_eal/common/eal_common_pci.c     |  2 --
 lib/librte_eal/common/include/rte_pci.h    |  2 --
 lib/librte_eal/linuxapp/eal/eal_pci.c      | 12 ------------
 lib/librte_eal/linuxapp/eal/eal_pci_init.h |  2 --
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c  |  2 --
 lib/librte_ether/rte_ethdev.c              | 21 ---------------------
 9 files changed, 54 deletions(-)

diff --git a/config/common_bsdapp b/config/common_bsdapp
index 8ff4dc2..88b44e9 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 97f1c9e..f9c9780 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/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 5b6b55d..80f51d3 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -126,7 +126,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
@@ -217,7 +216,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/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index dc74821..3c8a26b 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -335,7 +335,6 @@ int rte_eal_pci_scan(void);
  */
 int rte_eal_pci_probe(void);
 
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
 /**
  * Probe the single PCI device.
  *
@@ -365,7 +364,6 @@ int rte_eal_pci_probe_one(struct rte_pci_addr *addr);
  *   - Negative on error.
  */
 int rte_eal_pci_close_one(struct rte_pci_addr *addr);
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
 
 /**
  * Dump the content of the PCI bus.
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index 6d4932d..3914f52 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -595,7 +595,6 @@ pci_map_device(struct rte_pci_device *dev)
 	return ret;
 }
 
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
 static void
 pci_unmap_device(struct rte_pci_device *dev)
 {
@@ -618,7 +617,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
@@ -691,7 +689,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.
@@ -750,15 +747,6 @@ rte_eal_pci_close_one_driver(struct rte_pci_driver *dr,
 	/* 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
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
index 6af84d1..86088bd 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
@@ -74,10 +74,8 @@ 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);
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
 
 #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 0b397ca..a0bf9d7 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -388,7 +388,6 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	return 0;
 }
 
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
 static void
 pci_uio_unmap(struct mapped_pci_resource *uio_res)
 {
@@ -451,4 +450,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_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 9687fab..42e3f92 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -426,9 +426,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)
 {
@@ -709,24 +706,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)
-- 
1.9.1

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

* [dpdk-dev] [PATCH 3/3] doc: Remove BSD limitation from hotplug section of programmer's guide
  2015-03-04  3:11 [dpdk-dev] [PATCH 1/3] BSD: Support Port Hotplug function Tetsuya Mukawa
  2015-03-04  3:11 ` [dpdk-dev] [PATCH 2/3] eal, ethdev: Remove CONFIG_RTE_LIBRTE_EAL_HOTPLUG Tetsuya Mukawa
@ 2015-03-04  3:11 ` Tetsuya Mukawa
  2015-03-06 10:32 ` [dpdk-dev] [PATCH 1/3] BSD: Support Port Hotplug function Iremonger, Bernard
  2015-03-12 10:17 ` [dpdk-dev] [PATCH v2 00/15] eal: Port Hotplug support for BSD Tetsuya Mukawa
  3 siblings, 0 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-04  3:11 UTC (permalink / raw)
  To: dev

This patch removes below limitation from hotplug section of
programmer's guide.

- The framework can only be enabled with Linux. BSD is not supported.

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 doc/guides/prog_guide/port_hotplug_framework.rst | 2 --
 1 file changed, 2 deletions(-)

diff --git a/doc/guides/prog_guide/port_hotplug_framework.rst b/doc/guides/prog_guide/port_hotplug_framework.rst
index fe6d72a..17030bf 100644
--- a/doc/guides/prog_guide/port_hotplug_framework.rst
+++ b/doc/guides/prog_guide/port_hotplug_framework.rst
@@ -99,8 +99,6 @@ Limitations
 
 *       The Port Hotplug APIs are not thread safe.
 
-*       The framework can only be enabled with Linux. BSD is not supported.
-
 *       To detach a port, the port should be backed by a device that igb_uio
         manages. VFIO is not supported.
 
-- 
1.9.1

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

* Re: [dpdk-dev] [PATCH 1/3] BSD: Support Port Hotplug function
  2015-03-04  3:11 [dpdk-dev] [PATCH 1/3] BSD: Support Port Hotplug function Tetsuya Mukawa
  2015-03-04  3:11 ` [dpdk-dev] [PATCH 2/3] eal, ethdev: Remove CONFIG_RTE_LIBRTE_EAL_HOTPLUG Tetsuya Mukawa
  2015-03-04  3:11 ` [dpdk-dev] [PATCH 3/3] doc: Remove BSD limitation from hotplug section of programmer's guide Tetsuya Mukawa
@ 2015-03-06 10:32 ` Iremonger, Bernard
  2015-03-09  2:23   ` Tetsuya Mukawa
  2015-03-12 10:17 ` [dpdk-dev] [PATCH v2 00/15] eal: Port Hotplug support for BSD Tetsuya Mukawa
  3 siblings, 1 reply; 87+ messages in thread
From: Iremonger, Bernard @ 2015-03-06 10:32 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev

> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Tetsuya Mukawa
> Sent: Wednesday, March 4, 2015 3:12 AM
> To: dev@dpdk.org
> Subject: [dpdk-dev] [PATCH 1/3] BSD: Support Port Hotplug function
> 
> This patch adds Hotplug support to BSD.
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  lib/librte_eal/bsdapp/eal/eal_pci.c           | 169 +++++++++++++++++++++++++-
>  lib/librte_eal/bsdapp/eal/rte_eal_version.map |   6 +
>  lib/librte_eal/common/include/rte_pci.h       |   1 +
>  lib/librte_ether/rte_ethdev.c                 |   1 +
>  4 files changed, 174 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
> index 9193f80..fc5a088 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> @@ -156,6 +156,26 @@ fail:
>  	return NULL;
>  }
> 
> +/* unmap a particular resource */
> +static int
> +pci_unmap_resource(void *requested_addr, size_t size) {
> +	if (requested_addr == NULL)
> +		return -EINVAL;
> +
> +	/* 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);
> +		return -EFAULT;
> +	}
> +	return 0;
> +}
> +
>  static int
>  pci_uio_map_secondary(struct rte_pci_device *dev)  { @@ -270,6 +290,76 @@
> pci_uio_map_resource(struct rte_pci_device *dev)
>  	return (0);
>  }
> 
> +static int
> +pci_uio_unmap(struct uio_resource *uio_res) {
> +	int ret;
> +	unsigned i;
> +
> +	if (uio_res == NULL)
> +		return -EINVAL;
> +
> +	for (i = 0; i != uio_res->nb_maps; i++) {
> +		ret = pci_unmap_resource(uio_res->maps[i].addr,
> +				(size_t)uio_res->maps[i].size);
> +		if (ret < 0)
> +			return ret;
> +	}
> +	return 0;
> +}
> +
> +static struct uio_resource *
> +pci_uio_find_resource(struct rte_pci_device *dev) {
> +	struct uio_resource *uio_res;
> +
> +	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;
> +}
> +
> +/* map the PCI resource of a PCI device in virtual memory */ static int
> +pci_uio_unmap_resource(struct rte_pci_device *dev) {
> +	struct uio_resource *uio_res;
> +
> +	if (dev == NULL)
> +		return -EINVAL;
> +
> +	/* find an entry for the device */
> +	uio_res = pci_uio_find_resource(dev);
> +	if (uio_res == NULL)
> +		return -ENODEV;
> +
> +	/* 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;
> +	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
> +
> +	return 0;
> +}
> +
>  /* 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) @@ -307,6 +397,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->pt_driver = RTE_PT_NIC_UIO;
> +
>  /* parse resources */
>  	switch (conf->pc_hdr & PCIM_HDRTYPE) {
>  	case PCIM_HDRTYPE_NORMAL:
> @@ -376,8 +469,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 = -1;
>  	unsigned dev_count = 0;
> @@ -487,6 +580,76 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct
> rte_pci_device *d
>  	return 1;
>  }
> 
> +/*
> + * 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)
> +{
> +	struct rte_pci_id *id_table;
> +	int ret;
> +
> +	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);
> +
> +		/* 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;
> +		}
> +
> +		/* 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) {
> +			/* map resources for devices that use igb_uio */
> +			ret = pci_uio_unmap_resource(dev);
> +			if (ret != 0)
> +				return ret;
> +		}
> +	}
> +	/* return positive value if driver is not found */
> +	return 1;
> +}
> +
Hi Tetsuya,

The above functions being added to /lib/librte_eal/bsdapp/eal/eal_pci.c are very similar to the functions
in lib/librte_eal/linuxapp/eal/eal_pci.c the main difference seems to be "struct uio_resource *uio_res" in bsd
and "struct mapped_pci_resource *uio_res " in linux.
Both of these structures are the same although named differently.
There are at present only 3 references to   "struct uio_resource" in librte_eal/bsdapp/eal/eal_pci.c. If "struct uio_resource"  was renamed to" struct mapped_pci_resource "  the functions being  added to bsdapp/eal/eal_pci.c would be the same as the functions in linuxapp/eal/eal_pci.c.
If both groups of functions were the same  it would make sense to have only one copy of these functions  which could be moved into librte_eal/common/eal_common_pci.c .

There may be some extra work in doing  this but I think it would make the code more maintainable in the  future.
What do you think?

Regards,

Bernard.


>  /* Init the PCI EAL subsystem */
>  int
>  rte_eal_pci_init(void)
> @@ -499,7 +662,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 d83524d..54f5ff1 100644
> --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> @@ -37,9 +37,13 @@ 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;
> @@ -47,6 +51,8 @@ DPDK_2.0 {
>  	rte_eal_tailq_lookup_by_idx;
>  	rte_eal_tailq_reserve;
>  	rte_eal_tailq_reserve_by_idx;
> +	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/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
> index b9cdf8b..dc74821 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_pt_driver {
>  	RTE_PT_IGB_UIO		= 1,
>  	RTE_PT_VFIO		= 2,
>  	RTE_PT_UIO_GENERIC	= 3,
> +	RTE_PT_NIC_UIO		= 4, /* Driver for BSD */
>  };
> 
>  /**
> diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 6ea7a17..9687fab
> 100644
> --- a/lib/librte_ether/rte_ethdev.c
> +++ b/lib/librte_ether/rte_ethdev.c
> @@ -516,6 +516,7 @@ rte_eth_dev_is_detachable(uint8_t port_id)
>  		switch (rte_eth_devices[port_id].pci_dev->pt_driver) {
>  		case RTE_PT_IGB_UIO:
>  		case RTE_PT_UIO_GENERIC:
> +		case RTE_PT_NIC_UIO:
>  			break;
>  		case RTE_PT_VFIO:
>  		default:
> --
> 1.9.1

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

* Re: [dpdk-dev] [PATCH 1/3] BSD: Support Port Hotplug function
  2015-03-06 10:32 ` [dpdk-dev] [PATCH 1/3] BSD: Support Port Hotplug function Iremonger, Bernard
@ 2015-03-09  2:23   ` Tetsuya Mukawa
  2015-03-12 10:24     ` Tetsuya Mukawa
  0 siblings, 1 reply; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-09  2:23 UTC (permalink / raw)
  To: Iremonger, Bernard, dev

On 2015/03/06 19:32, Iremonger, Bernard wrote:
>> -----Original Message-----
>> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Tetsuya Mukawa
>> Sent: Wednesday, March 4, 2015 3:12 AM
>> To: dev@dpdk.org
>> Subject: [dpdk-dev] [PATCH 1/3] BSD: Support Port Hotplug function
>>
>> This patch adds Hotplug support to BSD.
>>
>> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
>> ---
>>  lib/librte_eal/bsdapp/eal/eal_pci.c           | 169 +++++++++++++++++++++++++-
>>  lib/librte_eal/bsdapp/eal/rte_eal_version.map |   6 +
>>  lib/librte_eal/common/include/rte_pci.h       |   1 +
>>  lib/librte_ether/rte_ethdev.c                 |   1 +
>>  4 files changed, 174 insertions(+), 3 deletions(-)
>>
>> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
>> index 9193f80..fc5a088 100644
>> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
>> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
>> @@ -156,6 +156,26 @@ fail:
>>  	return NULL;
>>  }
>>
>> +/* unmap a particular resource */
>> +static int
>> +pci_unmap_resource(void *requested_addr, size_t size) {
>> +	if (requested_addr == NULL)
>> +		return -EINVAL;
>> +
>> +	/* 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);
>> +		return -EFAULT;
>> +	}
>> +	return 0;
>> +}
>> +
>>  static int
>>  pci_uio_map_secondary(struct rte_pci_device *dev)  { @@ -270,6 +290,76 @@
>> pci_uio_map_resource(struct rte_pci_device *dev)
>>  	return (0);
>>  }
>>
>> +static int
>> +pci_uio_unmap(struct uio_resource *uio_res) {
>> +	int ret;
>> +	unsigned i;
>> +
>> +	if (uio_res == NULL)
>> +		return -EINVAL;
>> +
>> +	for (i = 0; i != uio_res->nb_maps; i++) {
>> +		ret = pci_unmap_resource(uio_res->maps[i].addr,
>> +				(size_t)uio_res->maps[i].size);
>> +		if (ret < 0)
>> +			return ret;
>> +	}
>> +	return 0;
>> +}
>> +
>> +static struct uio_resource *
>> +pci_uio_find_resource(struct rte_pci_device *dev) {
>> +	struct uio_resource *uio_res;
>> +
>> +	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;
>> +}
>> +
>> +/* map the PCI resource of a PCI device in virtual memory */ static int
>> +pci_uio_unmap_resource(struct rte_pci_device *dev) {
>> +	struct uio_resource *uio_res;
>> +
>> +	if (dev == NULL)
>> +		return -EINVAL;
>> +
>> +	/* find an entry for the device */
>> +	uio_res = pci_uio_find_resource(dev);
>> +	if (uio_res == NULL)
>> +		return -ENODEV;
>> +
>> +	/* 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;
>> +	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
>> +
>> +	return 0;
>> +}
>> +
>>  /* 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) @@ -307,6 +397,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->pt_driver = RTE_PT_NIC_UIO;
>> +
>>  /* parse resources */
>>  	switch (conf->pc_hdr & PCIM_HDRTYPE) {
>>  	case PCIM_HDRTYPE_NORMAL:
>> @@ -376,8 +469,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 = -1;
>>  	unsigned dev_count = 0;
>> @@ -487,6 +580,76 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct
>> rte_pci_device *d
>>  	return 1;
>>  }
>>
>> +/*
>> + * 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)
>> +{
>> +	struct rte_pci_id *id_table;
>> +	int ret;
>> +
>> +	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);
>> +
>> +		/* 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;
>> +		}
>> +
>> +		/* 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) {
>> +			/* map resources for devices that use igb_uio */
>> +			ret = pci_uio_unmap_resource(dev);
>> +			if (ret != 0)
>> +				return ret;
>> +		}
>> +	}
>> +	/* return positive value if driver is not found */
>> +	return 1;
>> +}
>> +
> Hi Tetsuya,
>
> The above functions being added to /lib/librte_eal/bsdapp/eal/eal_pci.c are very similar to the functions
> in lib/librte_eal/linuxapp/eal/eal_pci.c the main difference seems to be "struct uio_resource *uio_res" in bsd
> and "struct mapped_pci_resource *uio_res " in linux.
> Both of these structures are the same although named differently.
> There are at present only 3 references to   "struct uio_resource" in librte_eal/bsdapp/eal/eal_pci.c. If "struct uio_resource"  was renamed to" struct mapped_pci_resource "  the functions being  added to bsdapp/eal/eal_pci.c would be the same as the functions in linuxapp/eal/eal_pci.c.
> If both groups of functions were the same  it would make sense to have only one copy of these functions  which could be moved into librte_eal/common/eal_common_pci.c .
>
> There may be some extra work in doing  this but I think it would make the code more maintainable in the  future.
> What do you think?

Hi Bernard,

Yes, I agree with it.
I will merge above, and submit again.
Thanks for suggestion.

Regards,
Tetsuya

> Regards,
>
> Bernard.
>
>
>>  /* Init the PCI EAL subsystem */
>>  int
>>  rte_eal_pci_init(void)
>> @@ -499,7 +662,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 d83524d..54f5ff1 100644
>> --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
>> +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
>> @@ -37,9 +37,13 @@ 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;
>> @@ -47,6 +51,8 @@ DPDK_2.0 {
>>  	rte_eal_tailq_lookup_by_idx;
>>  	rte_eal_tailq_reserve;
>>  	rte_eal_tailq_reserve_by_idx;
>> +	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/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
>> index b9cdf8b..dc74821 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_pt_driver {
>>  	RTE_PT_IGB_UIO		= 1,
>>  	RTE_PT_VFIO		= 2,
>>  	RTE_PT_UIO_GENERIC	= 3,
>> +	RTE_PT_NIC_UIO		= 4, /* Driver for BSD */
>>  };
>>
>>  /**
>> diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 6ea7a17..9687fab
>> 100644
>> --- a/lib/librte_ether/rte_ethdev.c
>> +++ b/lib/librte_ether/rte_ethdev.c
>> @@ -516,6 +516,7 @@ rte_eth_dev_is_detachable(uint8_t port_id)
>>  		switch (rte_eth_devices[port_id].pci_dev->pt_driver) {
>>  		case RTE_PT_IGB_UIO:
>>  		case RTE_PT_UIO_GENERIC:
>> +		case RTE_PT_NIC_UIO:
>>  			break;
>>  		case RTE_PT_VFIO:
>>  		default:
>> --
>> 1.9.1

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

* [dpdk-dev] [PATCH v2 00/15] eal: Port Hotplug support for BSD
  2015-03-04  3:11 [dpdk-dev] [PATCH 1/3] BSD: Support Port Hotplug function Tetsuya Mukawa
                   ` (2 preceding siblings ...)
  2015-03-06 10:32 ` [dpdk-dev] [PATCH 1/3] BSD: Support Port Hotplug function Iremonger, Bernard
@ 2015-03-12 10:17 ` Tetsuya Mukawa
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 01/15] eal: Fix cording style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
                     ` (15 more replies)
  3 siblings, 16 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-12 10:17 UTC (permalink / raw)
  To: dev

This patch series adds port hotplug support to BSD.
Also, the patches consolidates pci uio functions of linuxapp and bsdapp.

Following patches cleanup pci uio code to consolidate later.
  eal: Fix cording style of eal_pci.c and eal_pci_uio.c
  eal: Close file descriptor of uio configuration
  eal: Fix memory leak of pci_uio_map_resource()
  eal: Fix needless incrementation of pci_map_addr
  eal/bsdapp: Change names of pci related data structure
  eal: Use map_idx in pci_uio_map_resource() of bsdapp to work same as
    linuxapp
  eal: Fix interface of pci_map_resource() of bsdapp
  eal: Add pci_uio_alloc_uio_resource()
  eal: Add pci_uio_map_uio_resource_by_index()

Following patches are actually for functions consolidation.
  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

The last patch removes CONFIG_RTE_LIBRTE_EAL_HOTPLUG configuration from Linux and BSD.
And port hotplug is enabled as default with both Linux and BSD.
  eal: Enable Port Hotplug as default in Linux and BSD


PATCH v2 changes
 - Consolidate pci uio functions of linuxapp and bsdapp.


Tetsuya Mukawa (15):
  eal: Fix cording style of eal_pci.c and eal_pci_uio.c
  eal: Close file descriptor of uio configuration
  eal: Fix memory leak of pci_uio_map_resource()
  eal: Fix needless incrementation of pci_map_addr
  eal/bsdapp: Change names of pci related data structure
  eal: Use map_idx in pci_uio_map_resource() of bsdapp to work same as
    linuxapp
  eal: Fix interface of pci_map_resource() of bsdapp
  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                | 292 ++++++---------------
 .../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             | 234 ++++++++++++++++-
 lib/librte_eal/common/eal_common_pci_uio.c         | 224 ++++++++++++++++
 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          | 263 +++++--------------
 lib/librte_ether/rte_ethdev.c                      |  22 +-
 16 files changed, 702 insertions(+), 729 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_pci_uio.c

-- 
1.9.1

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

* [dpdk-dev] [PATCH v2 01/15] eal: Fix cording style of eal_pci.c and eal_pci_uio.c
  2015-03-12 10:17 ` [dpdk-dev] [PATCH v2 00/15] eal: Port Hotplug support for BSD Tetsuya Mukawa
@ 2015-03-12 10:17   ` Tetsuya Mukawa
  2015-03-12 10:48     ` Bruce Richardson
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 02/15] eal: Close file descriptor of uio configuration Tetsuya Mukawa
                     ` (14 subsequent siblings)
  15 siblings, 1 reply; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-12 10:17 UTC (permalink / raw)
  To: dev

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

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c       | 67 ++++++++++++++++++-------------
 lib/librte_eal/linuxapp/eal/eal_pci.c     | 32 +++++++++------
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 37 ++++++++++-------
 3 files changed, 80 insertions(+), 56 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index fe3ef86..cbd0a4e 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -142,8 +142,9 @@ pci_map_resource(void *requested_addr, const char *devname, off_t offset,
 			MAP_SHARED, fd, offset);
 	close(fd);
 	if (mapaddr == MAP_FAILED ||
-			(requested_addr != NULL && mapaddr != requested_addr)) {
-		RTE_LOG(ERR, EAL, "%s(): cannot mmap(%s(%d), %p, 0x%lx, 0x%lx):"
+	    (requested_addr != NULL && mapaddr != requested_addr)) {
+		RTE_LOG(ERR, EAL,
+			"%s(): cannot mmap(%s(%d), %p, 0x%lx, 0x%lx):"
 			" %s (%p)\n", __func__, devname, fd, requested_addr,
 			(unsigned long)size, (unsigned long)offset,
 			strerror(errno), mapaddr);
@@ -161,9 +162,10 @@ fail:
 static int
 pci_uio_map_secondary(struct rte_pci_device *dev)
 {
-        size_t i;
-        struct uio_resource *uio_res;
-	struct uio_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
+	size_t i;
+	struct uio_resource *uio_res;
+	struct uio_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
 
 	TAILQ_FOREACH(uio_res, uio_res_list, next) {
 
@@ -179,10 +181,10 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 			    != uio_res->maps[i].addr) {
 				RTE_LOG(ERR, EAL,
 					"Cannot mmap device resource\n");
-				return (-1);
+				return -1;
 			}
 		}
-		return (0);
+		return 0;
 	}
 
 	RTE_LOG(ERR, EAL, "Cannot find resource for device\n");
@@ -201,7 +203,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	uint64_t pagesz;
 	struct rte_pci_addr *loc = &dev->addr;
 	struct uio_resource *uio_res;
-	struct uio_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
+	struct uio_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
 	struct uio_map *maps;
 
 	dev->intr_handle.fd = -1;
@@ -209,14 +212,16 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 	/* secondary processes - use already recorded details */
 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
-		return (pci_uio_map_secondary(dev));
+		return pci_uio_map_secondary(dev);
 
 	snprintf(devname, sizeof(devname), "/dev/uio@pci:%u:%u:%u",
 			dev->addr.bus, dev->addr.devid, dev->addr.function);
 
 	if (access(devname, O_RDWR) < 0) {
-		RTE_LOG(WARNING, EAL, "  "PCI_PRI_FMT" not managed by UIO driver, "
-				"skipping\n", loc->domain, loc->bus, loc->devid, loc->function);
+		RTE_LOG(WARNING, EAL,
+			"  "PCI_PRI_FMT" not managed by UIO driver, "
+			"skipping\n", loc->domain, loc->bus,
+			loc->devid, loc->function);
 		return 1;
 	}
 
@@ -233,7 +238,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) == NULL) {
 		RTE_LOG(ERR, EAL,
 			"%s(): cannot store uio mmap details\n", __func__);
-		return (-1);
+		return -1;
 	}
 
 	snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
@@ -248,7 +253,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 		j = uio_res->nb_maps;
 		/* skip empty BAR */
-		if ((phaddr = dev->mem_resource[i].phys_addr) == 0)
+		phaddr = dev->mem_resource[i].phys_addr;
+		if (phaddr == 0)
 			continue;
 
 		/* if matching map is found, then use it */
@@ -261,7 +267,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 						(size_t)maps[j].size)
 		    ) == NULL) {
 			rte_free(uio_res);
-			return (-1);
+			return -1;
 		}
 
 		maps[j].addr = mapaddr;
@@ -271,7 +277,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
 
-	return (0);
+	return 0;
 }
 
 /* Scan one pci sysfs entry, and fill the devices list from it. */
@@ -311,7 +317,7 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
 	/* FreeBSD has no NUMA support (yet) */
 	dev->numa_node = 0;
 
-/* parse resources */
+	/* parse resources */
 	switch (conf->pc_hdr & PCIM_HDRTYPE) {
 	case PCIM_HDRTYPE_NORMAL:
 		max = PCIR_MAX_BAR_0;
@@ -440,32 +446,37 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *d
 
 		/* 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)
+		    id_table->vendor_id != PCI_ANY_ID)
 			continue;
 		if (id_table->device_id != dev->id.device_id &&
-				id_table->device_id != PCI_ANY_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)
+		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)
+		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,
+			"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);
+		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");
+			RTE_LOG(DEBUG, EAL,
+				"  Device is blacklisted, not initializing\n");
 			return 0;
 		}
 
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index 83c589e..353b0b8 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -154,7 +154,8 @@ pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
 	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",
+		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);
@@ -631,31 +632,36 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *d
 
 		/* 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)
+		    id_table->vendor_id != PCI_ANY_ID)
 			continue;
 		if (id_table->device_id != dev->id.device_id &&
-				id_table->device_id != PCI_ANY_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)
+		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)
+		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,
+			"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);
+		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");
+			RTE_LOG(DEBUG, EAL,
+				"  Device is blacklisted, not initializing\n");
 			return 1;
 		}
 
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 2d1c69b..6f229d6 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -92,7 +92,8 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 {
 	int fd, i;
 	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 
 	TAILQ_FOREACH(uio_res, uio_res_list, next) {
 
@@ -117,14 +118,16 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 			if (mapaddr != uio_res->maps[i].addr) {
 				if (mapaddr == MAP_FAILED)
 					RTE_LOG(ERR, EAL,
-							"Cannot mmap device resource file %s: %s\n",
-							uio_res->maps[i].path,
-							strerror(errno));
+						"Cannot mmap device resource "
+						"file %s: %s\n",
+						uio_res->maps[i].path,
+						strerror(errno));
 				else
 					RTE_LOG(ERR, EAL,
-							"Cannot mmap device resource file %s to address: %p\n",
-							uio_res->maps[i].path,
-							uio_res->maps[i].addr);
+						"Cannot mmap device resource "
+						"file %s to address: %p\n",
+						uio_res->maps[i].path,
+						uio_res->maps[i].addr);
 
 				close(fd);
 				return -1;
@@ -272,7 +275,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	uint64_t phaddr;
 	struct rte_pci_addr *loc = &dev->addr;
 	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 	struct pci_map *maps;
 
 	dev->intr_handle.fd = -1;
@@ -286,8 +290,10 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	/* find uio resource */
 	uio_num = pci_get_uio_dev(dev, dirname, sizeof(dirname));
 	if (uio_num < 0) {
-		RTE_LOG(WARNING, EAL, "  "PCI_PRI_FMT" not managed by UIO driver, "
-				"skipping\n", loc->domain, loc->bus, loc->devid, loc->function);
+		RTE_LOG(WARNING, EAL,
+			"  "PCI_PRI_FMT" not managed by UIO driver, "
+			"skipping\n", loc->domain, loc->bus,
+			loc->devid, loc->function);
 		return 1;
 	}
 	snprintf(devname, sizeof(devname), "/dev/uio%u", uio_num);
@@ -338,12 +344,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 		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);
+				loc->domain, loc->bus, loc->devid,
+				loc->function, i);
 
 		/*
 		 * open resource file, to mmap it
@@ -412,7 +417,8 @@ static struct mapped_pci_resource *
 pci_uio_find_resource(struct rte_pci_device *dev)
 {
 	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 
 	if (dev == NULL)
 		return NULL;
@@ -431,7 +437,8 @@ void
 pci_uio_unmap_resource(struct rte_pci_device *dev)
 {
 	struct mapped_pci_resource *uio_res;
-	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 
 	if (dev == NULL)
 		return;
-- 
1.9.1

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

* [dpdk-dev] [PATCH v2 02/15] eal: Close file descriptor of uio configuration
  2015-03-12 10:17 ` [dpdk-dev] [PATCH v2 00/15] eal: Port Hotplug support for BSD Tetsuya Mukawa
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 01/15] eal: Fix cording style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
@ 2015-03-12 10:17   ` Tetsuya Mukawa
  2015-03-13 13:54     ` Iremonger, Bernard
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 03/15] eal: Fix memory leak of pci_uio_map_resource() Tetsuya Mukawa
                     ` (13 subsequent siblings)
  15 siblings, 1 reply; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-12 10:17 UTC (permalink / raw)
  To: dev

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

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

diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 6f229d6..77bb5ed 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -462,6 +462,8 @@ pci_uio_unmap_resource(struct rte_pci_device *dev)
 
 	/* 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.fd = -1;
 	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
-- 
1.9.1

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

* [dpdk-dev] [PATCH v2 03/15] eal: Fix memory leak of pci_uio_map_resource()
  2015-03-12 10:17 ` [dpdk-dev] [PATCH v2 00/15] eal: Port Hotplug support for BSD Tetsuya Mukawa
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 01/15] eal: Fix cording style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 02/15] eal: Close file descriptor of uio configuration Tetsuya Mukawa
@ 2015-03-12 10:17   ` Tetsuya Mukawa
  2015-03-13 14:04     ` Iremonger, Bernard
  2015-03-17  9:30     ` [dpdk-dev] [PATCH 0/6] Clean up pci uio implementations Tetsuya Mukawa
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 04/15] eal: Fix needless incrementation of pci_map_addr Tetsuya Mukawa
                     ` (12 subsequent siblings)
  15 siblings, 2 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-12 10:17 UTC (permalink / raw)
  To: dev

When pci_map_resource() is failed but path is allocated correctly,
path won't be freed. Also, when open() is failed, uio_res won't be freed.
This patch fixes these.

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

diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 77bb5ed..901f277 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -350,6 +350,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 				loc->domain, loc->bus, loc->devid,
 				loc->function, i);
 
+		/* allocate memory to keep path */
+		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
+		if (maps[map_idx].path == NULL)
+			goto fail0;
+
 		/*
 		 * open resource file, to mmap it
 		 */
@@ -357,7 +362,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 		if (fd < 0) {
 			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
 					devname, strerror(errno));
-			return -1;
+			goto fail0;
 		}
 
 		/* try mapping somewhere close to the end of hugepages */
@@ -372,14 +377,9 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 		pci_map_addr = RTE_PTR_ADD(mapaddr,
 				(size_t)dev->mem_resource[i].len);
 
-		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
-		if (maps[map_idx].path == NULL)
-			fail = 1;
-
 		if (fail) {
-			rte_free(uio_res);
 			close(fd);
-			return -1;
+			goto fail1;
 		}
 		close(fd);
 
@@ -397,6 +397,12 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
 
 	return 0;
+
+fail1:
+	rte_free(maps[map_idx].path);
+fail0:
+	rte_free(uio_res);
+	return -1;
 }
 
 #ifdef RTE_LIBRTE_EAL_HOTPLUG
-- 
1.9.1

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

* [dpdk-dev] [PATCH v2 04/15] eal: Fix needless incrementation of pci_map_addr
  2015-03-12 10:17 ` [dpdk-dev] [PATCH v2 00/15] eal: Port Hotplug support for BSD Tetsuya Mukawa
                     ` (2 preceding siblings ...)
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 03/15] eal: Fix memory leak of pci_uio_map_resource() Tetsuya Mukawa
@ 2015-03-12 10:17   ` Tetsuya Mukawa
  2015-03-13 14:49     ` Iremonger, Bernard
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 05/15] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
                     ` (11 subsequent siblings)
  15 siblings, 1 reply; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-12 10:17 UTC (permalink / raw)
  To: dev

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

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

diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 901f277..2741c62 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -337,7 +337,6 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	maps = uio_res->maps;
 	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
 		int fd;
-		int fail = 0;
 
 		/* skip empty BAR */
 		phaddr = dev->mem_resource[i].phys_addr;
@@ -371,18 +370,13 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 		mapaddr = pci_map_resource(pci_map_addr, fd, 0,
 				(size_t)dev->mem_resource[i].len, 0);
+		close(fd);
 		if (mapaddr == MAP_FAILED)
-			fail = 1;
+			goto fail1;
 
 		pci_map_addr = RTE_PTR_ADD(mapaddr,
 				(size_t)dev->mem_resource[i].len);
 
-		if (fail) {
-			close(fd);
-			goto fail1;
-		}
-		close(fd);
-
 		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
 		maps[map_idx].size = dev->mem_resource[i].len;
 		maps[map_idx].addr = mapaddr;
-- 
1.9.1

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

* [dpdk-dev] [PATCH v2 05/15] eal/bsdapp: Change names of pci related data structure
  2015-03-12 10:17 ` [dpdk-dev] [PATCH v2 00/15] eal: Port Hotplug support for BSD Tetsuya Mukawa
                     ` (3 preceding siblings ...)
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 04/15] eal: Fix needless incrementation of pci_map_addr Tetsuya Mukawa
@ 2015-03-12 10:17   ` Tetsuya Mukawa
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 06/15] eal: Use map_idx in pci_uio_map_resource() of bsdapp to work same as linuxapp Tetsuya Mukawa
                     ` (10 subsequent siblings)
  15 siblings, 0 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-12 10:17 UTC (permalink / raw)
  To: dev

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

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

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

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

* [dpdk-dev] [PATCH v2 06/15] eal: Use map_idx in pci_uio_map_resource() of bsdapp to work same as linuxapp
  2015-03-12 10:17 ` [dpdk-dev] [PATCH v2 00/15] eal: Port Hotplug support for BSD Tetsuya Mukawa
                     ` (4 preceding siblings ...)
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 05/15] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
@ 2015-03-12 10:17   ` Tetsuya Mukawa
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 07/15] eal: Fix interface of pci_map_resource() of bsdapp Tetsuya Mukawa
                     ` (9 subsequent siblings)
  15 siblings, 0 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-12 10:17 UTC (permalink / raw)
  To: dev

This patch changes code that maps pci resources in bsdapp.
Linuxapp has almost same code. To consolidate both, fix implementation
of bsdapp to work same as linuxapp.

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

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 7fcb15d..bd0f8cd 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -196,7 +196,7 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 static int
 pci_uio_map_resource(struct rte_pci_device *dev)
 {
-	int i, j;
+	int i, map_idx;
 	char devname[PATH_MAX]; /* contains the /dev/uioX */
 	void *mapaddr;
 	uint64_t phaddr;
@@ -250,9 +250,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	pagesz = sysconf(_SC_PAGESIZE);
 
 	maps = uio_res->maps;
-	for (i = uio_res->nb_maps = 0; i != PCI_MAX_RESOURCE; i++) {
+	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
 
-		j = uio_res->nb_maps;
 		/* skip empty BAR */
 		phaddr = dev->mem_resource[i].phys_addr;
 		if (phaddr == 0)
@@ -260,22 +259,23 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 		/* if matching map is found, then use it */
 		offset = i * pagesz;
-		maps[j].offset = offset;
-		maps[j].phaddr = dev->mem_resource[i].phys_addr;
-		maps[j].size = dev->mem_resource[i].len;
-		if (maps[j].addr != NULL ||
-		    (mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
-						(size_t)maps[j].size)
-		    ) == NULL) {
+		maps[map_idx].offset = offset;
+		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
+		maps[map_idx].size = dev->mem_resource[i].len;
+		mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
+					(size_t)maps[map_idx].size);
+		if ((maps[map_idx].addr != NULL) || (mapaddr == NULL)) {
 			rte_free(uio_res);
 			return -1;
 		}
 
-		maps[j].addr = mapaddr;
-		uio_res->nb_maps++;
+		maps[map_idx].addr = mapaddr;
+		map_idx++;
 		dev->mem_resource[i].addr = mapaddr;
 	}
 
+	uio_res->nb_maps = map_idx;
+
 	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
 
 	return 0;
-- 
1.9.1

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

* [dpdk-dev] [PATCH v2 07/15] eal: Fix interface of pci_map_resource() of bsdapp
  2015-03-12 10:17 ` [dpdk-dev] [PATCH v2 00/15] eal: Port Hotplug support for BSD Tetsuya Mukawa
                     ` (5 preceding siblings ...)
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 06/15] eal: Use map_idx in pci_uio_map_resource() of bsdapp to work same as linuxapp Tetsuya Mukawa
@ 2015-03-12 10:17   ` Tetsuya Mukawa
  2015-03-12 11:04     ` Bruce Richardson
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 08/15] eal: Add pci_uio_alloc_uio_resource() Tetsuya Mukawa
                     ` (8 subsequent siblings)
  15 siblings, 1 reply; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-12 10:17 UTC (permalink / raw)
  To: dev

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

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

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index bd0f8cd..c92c624 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -100,7 +100,7 @@ struct mapped_pci_resource {
 
 	struct rte_pci_addr pci_addr;
 	char path[PATH_MAX];
-	size_t nb_maps;
+	int nb_maps;
 	struct pci_map maps[PCI_MAX_RESOURCE];
 };
 
@@ -122,48 +122,31 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)
 
 /* map a particular resource from a file */
 static void *
-pci_map_resource(void *requested_addr, const char *devname, off_t offset,
-		 size_t size)
+pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
+		 int additional_flags)
 {
-	int fd;
 	void *mapaddr;
 
-	/*
-	 * open devname, to mmap it
-	 */
-	fd = open(devname, O_RDWR);
-	if (fd < 0) {
-		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
-			devname, strerror(errno));
-		goto fail;
-	}
-
 	/* Map the PCI memory resource of device */
 	mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
-			MAP_SHARED, fd, offset);
-	close(fd);
-	if (mapaddr == MAP_FAILED ||
-	    (requested_addr != NULL && mapaddr != requested_addr)) {
+			MAP_SHARED | additional_flags, fd, offset);
+	if (mapaddr == MAP_FAILED) {
 		RTE_LOG(ERR, EAL,
-			"%s(): cannot mmap(%s(%d), %p, 0x%lx, 0x%lx):"
-			" %s (%p)\n", __func__, devname, fd, requested_addr,
+			"%s(): cannot mmap(%d, %p, 0x%lx, 0x%lx): %s (%p)\n",
+			__func__, fd, requested_addr,
 			(unsigned long)size, (unsigned long)offset,
 			strerror(errno), mapaddr);
-		goto fail;
+	} else {
+		RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
 	}
 
-	RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
-
 	return mapaddr;
-
-fail:
-	return NULL;
 }
 
 static int
 pci_uio_map_secondary(struct rte_pci_device *dev)
 {
-	size_t i;
+	int i, fd;
 	struct mapped_pci_resource *uio_res;
 	struct mapped_pci_res_list *uio_res_list =
 			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
@@ -171,19 +154,42 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 	TAILQ_FOREACH(uio_res, uio_res_list, next) {
 
 		/* skip this element if it doesn't match our PCI address */
-		if (memcmp(&uio_res->pci_addr, &dev->addr, sizeof(dev->addr)))
+		if (rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr))
 			continue;
 
 		for (i = 0; i != uio_res->nb_maps; i++) {
-			if (pci_map_resource(uio_res->maps[i].addr,
-					     uio_res->path,
-					     (off_t)uio_res->maps[i].offset,
-					     (size_t)uio_res->maps[i].size)
-			    != uio_res->maps[i].addr) {
-				RTE_LOG(ERR, EAL,
-					"Cannot mmap device resource\n");
+			/*
+			 * 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) {
+				if (mapaddr == MAP_FAILED)
+					RTE_LOG(ERR, EAL,
+						"Cannot mmap device resource "
+						"file %s: %s\n",
+						uio_res->maps[i].path,
+						strerror(errno));
+				else
+					RTE_LOG(ERR, EAL,
+						"Cannot mmap device resource "
+						"file %s to address: %p\n",
+						uio_res->maps[i].path,
+						uio_res->maps[i].addr);
+
+				close(fd);
 				return -1;
 			}
+			/* fd is not needed in slave process, close it */
+			close(fd);
 		}
 		return 0;
 	}
@@ -251,25 +257,44 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 	maps = uio_res->maps;
 	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
+		int fd;
 
 		/* skip empty BAR */
 		phaddr = dev->mem_resource[i].phys_addr;
 		if (phaddr == 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 fail0;
+		}
+
+		/*
+		 * 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 fail0;
+		}
+
 		/* if matching map is found, then use it */
 		offset = i * pagesz;
-		maps[map_idx].offset = offset;
+		mapaddr = pci_map_resource(NULL, fd, (off_t)offset,
+					(size_t)dev->mem_resource[i].len, 0);
+		close(fd);
+		if (mapaddr == NULL)
+			goto fail1;
+
 		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
 		maps[map_idx].size = dev->mem_resource[i].len;
-		mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
-					(size_t)maps[map_idx].size);
-		if ((maps[map_idx].addr != NULL) || (mapaddr == NULL)) {
-			rte_free(uio_res);
-			return -1;
-		}
-
 		maps[map_idx].addr = mapaddr;
+		maps[map_idx].offset = offset;
+		strcpy(maps[map_idx].path, devname);
 		map_idx++;
 		dev->mem_resource[i].addr = mapaddr;
 	}
@@ -279,6 +304,12 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
 
 	return 0;
+
+fail1:
+	rte_free(maps[map_idx].path);
+fail0:
+	rte_free(uio_res);
+	return -1;
 }
 
 /* Scan one pci sysfs entry, and fill the devices list from it. */
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 2741c62..f100c1a 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -351,8 +351,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 		/* allocate memory to keep path */
 		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
-		if (maps[map_idx].path == NULL)
+		if (maps[map_idx].path == NULL) {
+			RTE_LOG(ERR, EAL, "Cannot allocate memory for "
+					"path: %s\n", strerror(errno));
 			goto fail0;
+		}
 
 		/*
 		 * open resource file, to mmap it
-- 
1.9.1

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

* [dpdk-dev] [PATCH v2 08/15] eal: Add pci_uio_alloc_uio_resource()
  2015-03-12 10:17 ` [dpdk-dev] [PATCH v2 00/15] eal: Port Hotplug support for BSD Tetsuya Mukawa
                     ` (6 preceding siblings ...)
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 07/15] eal: Fix interface of pci_map_resource() of bsdapp Tetsuya Mukawa
@ 2015-03-12 10:17   ` Tetsuya Mukawa
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 09/15] eal: Add pci_uio_map_uio_resource_by_index() Tetsuya Mukawa
                     ` (7 subsequent siblings)
  15 siblings, 0 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-12 10:17 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       | 61 ++++++++++++++++++++----------
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 63 ++++++++++++++++++++-----------
 2 files changed, 83 insertions(+), 41 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index c92c624..f88cd15 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -198,28 +198,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);
@@ -242,18 +231,50 @@ 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__);
 		return -1;
 	}
 
-	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;
+}
+
+/* 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++) {
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index f100c1a..099c413 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -262,30 +262,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));
@@ -323,15 +313,46 @@ 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__);
 		return -1;
 	}
 
-	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;
+}
+
+/* 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;
-- 
1.9.1

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

* [dpdk-dev] [PATCH v2 09/15] eal: Add pci_uio_map_uio_resource_by_index()
  2015-03-12 10:17 ` [dpdk-dev] [PATCH v2 00/15] eal: Port Hotplug support for BSD Tetsuya Mukawa
                     ` (7 preceding siblings ...)
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 08/15] eal: Add pci_uio_alloc_uio_resource() Tetsuya Mukawa
@ 2015-03-12 10:17   ` Tetsuya Mukawa
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 10/15] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp Tetsuya Mukawa
                     ` (6 subsequent siblings)
  15 siblings, 0 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-12 10:17 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       | 108 +++++++++++++++-----------
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 124 +++++++++++++++++-------------
 2 files changed, 135 insertions(+), 97 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index f88cd15..3e63835 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -245,20 +245,73 @@ pci_uio_alloc_uio_resource(struct rte_pci_device *dev,
 	return 0;
 }
 
-/* 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 == NULL)
+		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;
@@ -273,51 +326,18 @@ 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 */
 		phaddr = dev->mem_resource[i].phys_addr;
 		if (phaddr == 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 fail0;
-		}
-
-		/*
-		 * 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 fail0;
-		}
+		ret = pci_uio_map_uio_resource_by_index(dev, i,
+				uio_res, map_idx);
+		if (ret != 0)
+			goto fail;
 
-		/* 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 == NULL)
-			goto fail1;
-
-		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;
@@ -326,9 +346,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 	return 0;
 
-fail1:
-	rte_free(maps[map_idx].path);
-fail0:
+fail:
 	rte_free(uio_res);
 	return -1;
 }
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 099c413..6fca796 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -327,19 +327,82 @@ pci_uio_alloc_uio_resource(struct rte_pci_device *dev,
 	return 0;
 }
 
+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) || (uio_res->path == 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;
@@ -355,59 +418,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 fail0;
-		}
-
-		/*
-		 * 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 fail0;
-		}
-
-		/* 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)
-			goto fail1;
+		ret = pci_uio_map_uio_resource_by_index(dev, i,
+				uio_res, map_idx);
+		if (ret != 0)
+			goto fail;
 
-		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;
@@ -416,9 +438,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 	return 0;
 
-fail1:
-	rte_free(maps[map_idx].path);
-fail0:
+fail:
 	rte_free(uio_res);
 	return -1;
 }
-- 
1.9.1

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

* [dpdk-dev] [PATCH v2 10/15] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp
  2015-03-12 10:17 ` [dpdk-dev] [PATCH v2 00/15] eal: Port Hotplug support for BSD Tetsuya Mukawa
                     ` (8 preceding siblings ...)
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 09/15] eal: Add pci_uio_map_uio_resource_by_index() Tetsuya Mukawa
@ 2015-03-12 10:17   ` Tetsuya Mukawa
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 11/15] eal: Consolidate rte_eal_pci_probe/close_one_driver() " Tetsuya Mukawa
                     ` (5 subsequent siblings)
  15 siblings, 0 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-12 10:17 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 3e63835..67ad88f 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 995f814..fc64601 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
  */
-- 
1.9.1

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

* [dpdk-dev] [PATCH v2 11/15] eal: Consolidate rte_eal_pci_probe/close_one_driver() of linuxapp and bsdapp
  2015-03-12 10:17 ` [dpdk-dev] [PATCH v2 00/15] eal: Port Hotplug support for BSD Tetsuya Mukawa
                     ` (9 preceding siblings ...)
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 10/15] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp Tetsuya Mukawa
@ 2015-03-12 10:17   ` Tetsuya Mukawa
  2015-03-13 15:03     ` Iremonger, Bernard
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 12/15] eal: Consolidate pci_map/unmap_device() " Tetsuya Mukawa
                     ` (4 subsequent siblings)
  15 siblings, 1 reply; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-12 10:17 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    |  79 ++---------------
 lib/librte_eal/common/eal_common_pci.c | 138 +++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_private.h    |  21 ++---
 lib/librte_eal/linuxapp/eal/eal_pci.c  | 153 ++-------------------------------
 4 files changed, 162 insertions(+), 229 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 67ad88f..3778763 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 "
@@ -429,6 +429,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.
@@ -479,76 +486,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)
-{
-	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 808b87b..538b2d9 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -99,6 +99,144 @@ 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;
+	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)
+{
+	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 353b0b8..dbc2548 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;
@@ -565,7 +565,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;
@@ -594,7 +595,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)
@@ -618,151 +620,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;
-	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)
-{
-	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)
-- 
1.9.1

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

* [dpdk-dev] [PATCH v2 12/15] eal: Consolidate pci_map/unmap_device() of linuxapp and bsdapp
  2015-03-12 10:17 ` [dpdk-dev] [PATCH v2 00/15] eal: Port Hotplug support for BSD Tetsuya Mukawa
                     ` (10 preceding siblings ...)
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 11/15] eal: Consolidate rte_eal_pci_probe/close_one_driver() " Tetsuya Mukawa
@ 2015-03-12 10:17   ` Tetsuya Mukawa
  2015-03-13 15:10     ` Iremonger, Bernard
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 13/15] eal: Consolidate pci_map/unmap_resource() " Tetsuya Mukawa
                     ` (3 subsequent siblings)
  15 siblings, 1 reply; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-12 10:17 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 3778763..1e42e42 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -280,7 +280,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;
@@ -364,6 +364,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->pt_driver = RTE_PT_NIC_UIO;
+
 	/* parse resources */
 	switch (conf->pc_hdr & PCIM_HDRTYPE) {
 	case PCIM_HDRTYPE_NORMAL:
@@ -429,13 +432,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 538b2d9..726026f 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->pt_driver) {
+	case RTE_PT_VFIO:
+#ifdef VFIO_PRESENT
+		if (pci_vfio_is_enabled())
+			ret = pci_vfio_map_resource(dev);
+#endif
+		break;
+	case RTE_PT_IGB_UIO:
+	case RTE_PT_UIO_GENERIC:
+	case RTE_PT_NIC_UIO:
+		/* map resources for devices that use uio */
+		ret = pci_uio_map_resource(dev);
+		break;
+	default:
+		RTE_LOG(DEBUG, EAL, "  Not managed by known pt 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->pt_driver) {
+	case RTE_PT_VFIO:
+		RTE_LOG(ERR, EAL, "Hotplug doesn't support vfio yet\n");
+		break;
+	case RTE_PT_IGB_UIO:
+	case RTE_PT_UIO_GENERIC:
+	case RTE_PT_NIC_UIO:
+		/* unmap resources for devices that use uio */
+		pci_uio_unmap_resource(dev);
+		break;
+	default:
+		RTE_LOG(DEBUG, EAL, "  Not managed by known pt 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 fc64601..47345b8 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_pt_driver {
 	RTE_PT_IGB_UIO		= 1,
 	RTE_PT_VFIO		= 2,
 	RTE_PT_UIO_GENERIC	= 3,
+	RTE_PT_NIC_UIO		= 4,
 };
 
 /**
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index dbc2548..6a8153c 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -565,61 +565,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->pt_driver) {
-	case RTE_PT_VFIO:
-#ifdef VFIO_PRESENT
-		if (pci_vfio_is_enabled())
-			ret = pci_vfio_map_resource(dev);
-#endif
-		break;
-	case RTE_PT_IGB_UIO:
-	case RTE_PT_UIO_GENERIC:
-		/* map resources for devices that use uio */
-		ret = pci_uio_map_resource(dev);
-		break;
-	default:
-		RTE_LOG(DEBUG, EAL, "  Not managed by known pt 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->pt_driver) {
-	case RTE_PT_VFIO:
-		RTE_LOG(ERR, EAL, "Hotplug doesn't support vfio yet\n");
-		break;
-	case RTE_PT_IGB_UIO:
-	case RTE_PT_UIO_GENERIC:
-		/* unmap resources for devices that use uio */
-		pci_uio_unmap_resource(dev);
-		break;
-	default:
-		RTE_LOG(DEBUG, EAL, "  Not managed by known pt 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 03fce08..e23d7da 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->pt_driver) {
 		case RTE_PT_IGB_UIO:
 		case RTE_PT_UIO_GENERIC:
+		case RTE_PT_NIC_UIO:
 			break;
 		case RTE_PT_VFIO:
 		default:
-- 
1.9.1

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

* [dpdk-dev] [PATCH v2 13/15] eal: Consolidate pci_map/unmap_resource() of linuxapp and bsdapp
  2015-03-12 10:17 ` [dpdk-dev] [PATCH v2 00/15] eal: Port Hotplug support for BSD Tetsuya Mukawa
                     ` (11 preceding siblings ...)
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 12/15] eal: Consolidate pci_map/unmap_device() " Tetsuya Mukawa
@ 2015-03-12 10:17   ` Tetsuya Mukawa
  2015-03-13 15:23     ` Iremonger, Bernard
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 14/15] eal: Consolidate pci uio functions " Tetsuya Mukawa
                     ` (2 subsequent siblings)
  15 siblings, 1 reply; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-12 10:17 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        | 24 -----------------
 lib/librte_eal/common/eal_common_pci.c     | 43 ++++++++++++++++++++++++++++++
 lib/librte_eal/common/include/rte_pci.h    | 11 ++++++++
 lib/librte_eal/linuxapp/eal/eal_pci.c      | 42 -----------------------------
 lib/librte_eal/linuxapp/eal/eal_pci_init.h |  5 ----
 5 files changed, 54 insertions(+), 71 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 1e42e42..d7d6439 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -46,7 +46,6 @@
 #include <dirent.h>
 #include <limits.h>
 #include <sys/queue.h>
-#include <sys/mman.h>
 #include <sys/ioctl.h>
 #include <sys/pciio.h>
 #include <dev/pci/pcireg.h>
@@ -96,29 +95,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 726026f..6d98194 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,48 @@ 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 47345b8..d3b883e 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -363,8 +363,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 6a8153c..d072e98 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,47 +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);
-- 
1.9.1

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

* [dpdk-dev] [PATCH v2 14/15] eal: Consolidate pci uio functions of linuxapp and bsdapp
  2015-03-12 10:17 ` [dpdk-dev] [PATCH v2 00/15] eal: Port Hotplug support for BSD Tetsuya Mukawa
                     ` (12 preceding siblings ...)
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 13/15] eal: Consolidate pci_map/unmap_resource() " Tetsuya Mukawa
@ 2015-03-12 10:17   ` Tetsuya Mukawa
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 15/15] eal: Enable Port Hotplug as default in Linux and BSD Tetsuya Mukawa
  2015-03-13 11:46   ` [dpdk-dev] [PATCH v2 00/15] eal: Port Hotplug support for BSD Iremonger, Bernard
  15 siblings, 0 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-12 10:17 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                | 111 +---------
 .../bsdapp/eal/include/exec-env/rte_interrupts.h   |   1 +
 lib/librte_eal/common/eal_common_pci_uio.c         | 226 +++++++++++++++++++++
 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          | 184 +----------------
 8 files changed, 273 insertions(+), 298 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 d7d6439..b6785d4 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -81,10 +81,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
@@ -95,62 +91,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) {
-				if (mapaddr == MAP_FAILED)
-					RTE_LOG(ERR, EAL,
-						"Cannot mmap device resource "
-						"file %s: %s\n",
-						uio_res->maps[i].path,
-						strerror(errno));
-				else
-					RTE_LOG(ERR, EAL,
-						"Cannot mmap device resource "
-						"file %s to address: %p\n",
-						uio_res->maps[i].path,
-						uio_res->maps[i].addr);
-
-				close(fd);
-				return -1;
-			}
-			/* fd is not needed in slave process, close it */
-			close(fd);
-		}
-		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)
 {
@@ -197,7 +138,7 @@ pci_uio_alloc_uio_resource(struct rte_pci_device *dev,
 	return 0;
 }
 
-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)
 {
@@ -255,54 +196,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 */
-		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 fail;
-
-		map_idx++;
-	}
-
-	uio_res->nb_maps = map_idx;
-
-	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
-
-	return 0;
-
-fail:
-	rte_free(uio_res);
-	return -1;
-}
-
 /* Scan one pci sysfs entry, and fill the devices list from it. */
 static int
 pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
diff --git a/lib/librte_eal/bsdapp/eal/include/exec-env/rte_interrupts.h b/lib/librte_eal/bsdapp/eal/include/exec-env/rte_interrupts.h
index 87a9cf6..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..b9d7726
--- /dev/null
+++ b/lib/librte_eal/common/eal_common_pci_uio.c
@@ -0,0 +1,226 @@
+/*-
+ *   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 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) {
+				if (mapaddr == MAP_FAILED)
+					RTE_LOG(ERR, EAL,
+						"Cannot mmap device resource "
+						"file %s: %s\n",
+						uio_res->maps[i].path,
+						strerror(errno));
+				else
+					RTE_LOG(ERR, EAL,
+						"Cannot mmap device resource "
+						"file %s to address: %p\n",
+						uio_res->maps[i].path,
+						uio_res->maps[i].addr);
+
+				close(fd);
+				return -1;
+			}
+			/* fd is not needed in slave process, close it */
+			close(fd);
+		}
+		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 fail;
+
+		map_idx++;
+	}
+
+	uio_res->nb_maps = map_idx;
+
+	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
+
+	return 0;
+
+fail:
+	rte_free(uio_res);
+	return -1;
+}
+
+#ifdef RTE_LIBRTE_EAL_HOTPLUG
+static void
+pci_uio_unmap(struct mapped_pci_resource *uio_res)
+{
+	int i;
+
+	if (uio_res == NULL)
+		return;
+
+	for (i = 0; i != uio_res->nb_maps; i++)
+		pci_unmap_resource(uio_res->maps[i].addr,
+				(size_t)uio_res->maps[i].size);
+}
+
+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.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 23c2d48..a250662 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 6fca796..6abc639 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,61 +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) {
-				if (mapaddr == MAP_FAILED)
-					RTE_LOG(ERR, EAL,
-						"Cannot mmap device resource "
-						"file %s: %s\n",
-						uio_res->maps[i].path,
-						strerror(errno));
-				else
-					RTE_LOG(ERR, EAL,
-						"Cannot mmap device resource "
-						"file %s to address: %p\n",
-						uio_res->maps[i].path,
-						uio_res->maps[i].addr);
-
-				close(fd);
-				return -1;
-			}
-			/* fd is not needed in slave process, close it */
-			close(fd);
-		}
-		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;
@@ -262,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)
 {
@@ -327,7 +267,7 @@ pci_uio_alloc_uio_resource(struct rte_pci_device *dev,
 	return 0;
 }
 
-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)
 {
@@ -393,123 +333,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 fail;
-
-		map_idx++;
-	}
-
-	uio_res->nb_maps = map_idx;
-
-	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
-
-	return 0;
-
-fail:
-	rte_free(uio_res);
-	return -1;
-}
-
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
-static void
-pci_uio_unmap(struct mapped_pci_resource *uio_res)
-{
-	int i;
-
-	if (uio_res == NULL)
-		return;
-
-	for (i = 0; i != uio_res->nb_maps; i++)
-		pci_unmap_resource(uio_res->maps[i].addr,
-				(size_t)uio_res->maps[i].size);
-}
-
-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.fd = -1;
-	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
-}
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
-- 
1.9.1

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

* [dpdk-dev] [PATCH v2 15/15] eal: Enable Port Hotplug as default in Linux and BSD
  2015-03-12 10:17 ` [dpdk-dev] [PATCH v2 00/15] eal: Port Hotplug support for BSD Tetsuya Mukawa
                     ` (13 preceding siblings ...)
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 14/15] eal: Consolidate pci uio functions " Tetsuya Mukawa
@ 2015-03-12 10:17   ` Tetsuya Mukawa
  2015-03-13 15:47     ` Iremonger, Bernard
  2015-03-13 11:46   ` [dpdk-dev] [PATCH v2 00/15] eal: Port Hotplug support for BSD Iremonger, Bernard
  15 siblings, 1 reply; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-12 10:17 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 8ff4dc2..88b44e9 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 97f1c9e..f9c9780 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 b6785d4..50c9544 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -305,8 +305,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;
@@ -362,7 +362,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 6d98194..126dd01 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -122,7 +122,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)
@@ -139,7 +138,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
@@ -171,7 +169,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)
@@ -196,7 +193,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
@@ -275,7 +271,6 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr,
 	return 1;
 }
 
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
 /*
  * If vendor/device ID match, call the devuninit() function of the
  * driver.
@@ -334,7 +329,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
@@ -363,7 +357,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
@@ -454,7 +447,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 b9d7726..fe5dd5f 100644
--- a/lib/librte_eal/common/eal_common_pci_uio.c
+++ b/lib/librte_eal/common/eal_common_pci_uio.c
@@ -154,7 +154,6 @@ fail:
 	return -1;
 }
 
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
 static void
 pci_uio_unmap(struct mapped_pci_resource *uio_res)
 {
@@ -223,4 +222,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 d3b883e..b3c6a0f 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -369,7 +369,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.
  */
@@ -404,7 +403,6 @@ int rte_eal_pci_probe_one(struct rte_pci_addr *addr);
  *   - Negative on error.
  */
 int rte_eal_pci_close_one(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 e23d7da..818384a 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)
-- 
1.9.1

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

* Re: [dpdk-dev] [PATCH 1/3] BSD: Support Port Hotplug function
  2015-03-09  2:23   ` Tetsuya Mukawa
@ 2015-03-12 10:24     ` Tetsuya Mukawa
  0 siblings, 0 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-12 10:24 UTC (permalink / raw)
  To: Iremonger, Bernard, dev

On 2015/03/09 11:23, Tetsuya Mukawa wrote:
> On 2015/03/06 19:32, Iremonger, Bernard wrote:
>
>> Hi Tetsuya,
>>
>> The above functions being added to /lib/librte_eal/bsdapp/eal/eal_pci.c are very similar to the functions
>> in lib/librte_eal/linuxapp/eal/eal_pci.c the main difference seems to be "struct uio_resource *uio_res" in bsd
>> and "struct mapped_pci_resource *uio_res " in linux.
>> Both of these structures are the same although named differently.
>> There are at present only 3 references to   "struct uio_resource" in librte_eal/bsdapp/eal/eal_pci.c. If "struct uio_resource"  was renamed to" struct mapped_pci_resource "  the functions being  added to bsdapp/eal/eal_pci.c would be the same as the functions in linuxapp/eal/eal_pci.c.
>> If both groups of functions were the same  it would make sense to have only one copy of these functions  which could be moved into librte_eal/common/eal_common_pci.c .
>>
>> There may be some extra work in doing  this but I think it would make the code more maintainable in the  future.
>> What do you think?
> Hi Bernard,
>
> Yes, I agree with it.
> I will merge above, and submit again.
> Thanks for suggestion.
>
> Regards,
> Tetsuya
>

Hi Bernard,

I've sent v2 patches.
The patches depends on the latest master branch.
So if you apply it, could you please pull first?

Also, I tried to separate patches for reviewer, but if you feel it
should be squashed more, please let me know.

Thanks,
Tetsuya

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

* Re: [dpdk-dev] [PATCH v2 01/15] eal: Fix cording style of eal_pci.c and eal_pci_uio.c
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 01/15] eal: Fix cording style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
@ 2015-03-12 10:48     ` Bruce Richardson
  2015-03-12 10:57       ` Qiu, Michael
  0 siblings, 1 reply; 87+ messages in thread
From: Bruce Richardson @ 2015-03-12 10:48 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Thu, Mar 12, 2015 at 07:17:40PM +0900, Tetsuya Mukawa wrote:
> This patch fixes cording style of below files in linuxapp and bsdapp.
>  - eal_pci.c
>  - eal_pci_uio.c
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>

Hi Tetsuya,

While there is some good cleanup here, I disagree with a number of the changes
made purely to the whitespace in the file. The style of using a double-indent
for line continuations is very widely used in DPDK code, much more so than the
style of lining things up with the previous line.

So ack to the changes removing unnecessary braces, and occasional splitting of
really long lines (though a few chars over 80 is ok). NAK to the whitespace
and indentation changes.

Regards,
/Bruce

> ---
>  lib/librte_eal/bsdapp/eal/eal_pci.c       | 67 ++++++++++++++++++-------------
>  lib/librte_eal/linuxapp/eal/eal_pci.c     | 32 +++++++++------
>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 37 ++++++++++-------
>  3 files changed, 80 insertions(+), 56 deletions(-)
> 
> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
> index fe3ef86..cbd0a4e 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> @@ -142,8 +142,9 @@ pci_map_resource(void *requested_addr, const char *devname, off_t offset,
>  			MAP_SHARED, fd, offset);
>  	close(fd);
>  	if (mapaddr == MAP_FAILED ||
> -			(requested_addr != NULL && mapaddr != requested_addr)) {
> -		RTE_LOG(ERR, EAL, "%s(): cannot mmap(%s(%d), %p, 0x%lx, 0x%lx):"
> +	    (requested_addr != NULL && mapaddr != requested_addr)) {
> +		RTE_LOG(ERR, EAL,
> +			"%s(): cannot mmap(%s(%d), %p, 0x%lx, 0x%lx):"
>  			" %s (%p)\n", __func__, devname, fd, requested_addr,
>  			(unsigned long)size, (unsigned long)offset,
>  			strerror(errno), mapaddr);
> @@ -161,9 +162,10 @@ fail:
>  static int
>  pci_uio_map_secondary(struct rte_pci_device *dev)
>  {
> -        size_t i;
> -        struct uio_resource *uio_res;
> -	struct uio_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
> +	size_t i;
> +	struct uio_resource *uio_res;
> +	struct uio_res_list *uio_res_list =
> +			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
>  
>  	TAILQ_FOREACH(uio_res, uio_res_list, next) {
>  
> @@ -179,10 +181,10 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
>  			    != uio_res->maps[i].addr) {
>  				RTE_LOG(ERR, EAL,
>  					"Cannot mmap device resource\n");
> -				return (-1);
> +				return -1;
>  			}
>  		}
> -		return (0);
> +		return 0;
>  	}
>  
>  	RTE_LOG(ERR, EAL, "Cannot find resource for device\n");
> @@ -201,7 +203,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  	uint64_t pagesz;
>  	struct rte_pci_addr *loc = &dev->addr;
>  	struct uio_resource *uio_res;
> -	struct uio_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
> +	struct uio_res_list *uio_res_list =
> +			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
>  	struct uio_map *maps;
>  
>  	dev->intr_handle.fd = -1;
> @@ -209,14 +212,16 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  
>  	/* secondary processes - use already recorded details */
>  	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
> -		return (pci_uio_map_secondary(dev));
> +		return pci_uio_map_secondary(dev);
>  
>  	snprintf(devname, sizeof(devname), "/dev/uio@pci:%u:%u:%u",
>  			dev->addr.bus, dev->addr.devid, dev->addr.function);
>  
>  	if (access(devname, O_RDWR) < 0) {
> -		RTE_LOG(WARNING, EAL, "  "PCI_PRI_FMT" not managed by UIO driver, "
> -				"skipping\n", loc->domain, loc->bus, loc->devid, loc->function);
> +		RTE_LOG(WARNING, EAL,
> +			"  "PCI_PRI_FMT" not managed by UIO driver, "
> +			"skipping\n", loc->domain, loc->bus,
> +			loc->devid, loc->function);
>  		return 1;
>  	}
>  
> @@ -233,7 +238,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  	if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) == NULL) {
>  		RTE_LOG(ERR, EAL,
>  			"%s(): cannot store uio mmap details\n", __func__);
> -		return (-1);
> +		return -1;
>  	}
>  
>  	snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
> @@ -248,7 +253,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  
>  		j = uio_res->nb_maps;
>  		/* skip empty BAR */
> -		if ((phaddr = dev->mem_resource[i].phys_addr) == 0)
> +		phaddr = dev->mem_resource[i].phys_addr;
> +		if (phaddr == 0)
>  			continue;
>  
>  		/* if matching map is found, then use it */
> @@ -261,7 +267,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  						(size_t)maps[j].size)
>  		    ) == NULL) {
>  			rte_free(uio_res);
> -			return (-1);
> +			return -1;
>  		}
>  
>  		maps[j].addr = mapaddr;
> @@ -271,7 +277,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  
>  	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
>  
> -	return (0);
> +	return 0;
>  }
>  
>  /* Scan one pci sysfs entry, and fill the devices list from it. */
> @@ -311,7 +317,7 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
>  	/* FreeBSD has no NUMA support (yet) */
>  	dev->numa_node = 0;
>  
> -/* parse resources */
> +	/* parse resources */
>  	switch (conf->pc_hdr & PCIM_HDRTYPE) {
>  	case PCIM_HDRTYPE_NORMAL:
>  		max = PCIR_MAX_BAR_0;
> @@ -440,32 +446,37 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *d
>  
>  		/* 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)
> +		    id_table->vendor_id != PCI_ANY_ID)
>  			continue;
>  		if (id_table->device_id != dev->id.device_id &&
> -				id_table->device_id != PCI_ANY_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)
> +		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)
> +		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,
> +			"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);
> +		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");
> +			RTE_LOG(DEBUG, EAL,
> +				"  Device is blacklisted, not initializing\n");
>  			return 0;
>  		}
>  
> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
> index 83c589e..353b0b8 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_pci.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
> @@ -154,7 +154,8 @@ pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
>  	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",
> +		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);
> @@ -631,31 +632,36 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *d
>  
>  		/* 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)
> +		    id_table->vendor_id != PCI_ANY_ID)
>  			continue;
>  		if (id_table->device_id != dev->id.device_id &&
> -				id_table->device_id != PCI_ANY_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)
> +		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)
> +		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,
> +			"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);
> +		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");
> +			RTE_LOG(DEBUG, EAL,
> +				"  Device is blacklisted, not initializing\n");
>  			return 1;
>  		}
>  
> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> index 2d1c69b..6f229d6 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> @@ -92,7 +92,8 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
>  {
>  	int fd, i;
>  	struct mapped_pci_resource *uio_res;
> -	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
> +	struct mapped_pci_res_list *uio_res_list =
> +			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
>  
>  	TAILQ_FOREACH(uio_res, uio_res_list, next) {
>  
> @@ -117,14 +118,16 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
>  			if (mapaddr != uio_res->maps[i].addr) {
>  				if (mapaddr == MAP_FAILED)
>  					RTE_LOG(ERR, EAL,
> -							"Cannot mmap device resource file %s: %s\n",
> -							uio_res->maps[i].path,
> -							strerror(errno));
> +						"Cannot mmap device resource "
> +						"file %s: %s\n",
> +						uio_res->maps[i].path,
> +						strerror(errno));
>  				else
>  					RTE_LOG(ERR, EAL,
> -							"Cannot mmap device resource file %s to address: %p\n",
> -							uio_res->maps[i].path,
> -							uio_res->maps[i].addr);
> +						"Cannot mmap device resource "
> +						"file %s to address: %p\n",
> +						uio_res->maps[i].path,
> +						uio_res->maps[i].addr);
>  
>  				close(fd);
>  				return -1;
> @@ -272,7 +275,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  	uint64_t phaddr;
>  	struct rte_pci_addr *loc = &dev->addr;
>  	struct mapped_pci_resource *uio_res;
> -	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
> +	struct mapped_pci_res_list *uio_res_list =
> +			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
>  	struct pci_map *maps;
>  
>  	dev->intr_handle.fd = -1;
> @@ -286,8 +290,10 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  	/* find uio resource */
>  	uio_num = pci_get_uio_dev(dev, dirname, sizeof(dirname));
>  	if (uio_num < 0) {
> -		RTE_LOG(WARNING, EAL, "  "PCI_PRI_FMT" not managed by UIO driver, "
> -				"skipping\n", loc->domain, loc->bus, loc->devid, loc->function);
> +		RTE_LOG(WARNING, EAL,
> +			"  "PCI_PRI_FMT" not managed by UIO driver, "
> +			"skipping\n", loc->domain, loc->bus,
> +			loc->devid, loc->function);
>  		return 1;
>  	}
>  	snprintf(devname, sizeof(devname), "/dev/uio%u", uio_num);
> @@ -338,12 +344,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  		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);
> +				loc->domain, loc->bus, loc->devid,
> +				loc->function, i);
>  
>  		/*
>  		 * open resource file, to mmap it
> @@ -412,7 +417,8 @@ static struct mapped_pci_resource *
>  pci_uio_find_resource(struct rte_pci_device *dev)
>  {
>  	struct mapped_pci_resource *uio_res;
> -	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
> +	struct mapped_pci_res_list *uio_res_list =
> +			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
>  
>  	if (dev == NULL)
>  		return NULL;
> @@ -431,7 +437,8 @@ void
>  pci_uio_unmap_resource(struct rte_pci_device *dev)
>  {
>  	struct mapped_pci_resource *uio_res;
> -	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
> +	struct mapped_pci_res_list *uio_res_list =
> +			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
>  
>  	if (dev == NULL)
>  		return;
> -- 
> 1.9.1
> 

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

* Re: [dpdk-dev] [PATCH v2 01/15] eal: Fix cording style of eal_pci.c and eal_pci_uio.c
  2015-03-12 10:48     ` Bruce Richardson
@ 2015-03-12 10:57       ` Qiu, Michael
  2015-03-12 11:09         ` Bruce Richardson
  0 siblings, 1 reply; 87+ messages in thread
From: Qiu, Michael @ 2015-03-12 10:57 UTC (permalink / raw)
  To: Richardson, Bruce, Tetsuya Mukawa; +Cc: dev

On 3/12/2015 6:50 PM, Bruce Richardson wrote:
> On Thu, Mar 12, 2015 at 07:17:40PM +0900, Tetsuya Mukawa wrote:
>> This patch fixes cording style of below files in linuxapp and bsdapp.
>>  - eal_pci.c
>>  - eal_pci_uio.c
>>
>> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> Hi Tetsuya,
>
> While there is some good cleanup here, I disagree with a number of the changes
> made purely to the whitespace in the file. The style of using a double-indent
> for line continuations is very widely used in DPDK code, much more so than the
> style of lining things up with the previous line.

Yes, but both style are seeing in dpdk, here the patch is using Tab +
whitespace, which is also
the linux kernel's style.

So is there any rule to allow only one style?
Mixed style is bad...

Thanks,
Michael
> So ack to the changes removing unnecessary braces, and occasional splitting of
> really long lines (though a few chars over 80 is ok). NAK to the whitespace
> and indentation changes.
>
> Regards,
> /Bruce
>
>> ---
>>  lib/librte_eal/bsdapp/eal/eal_pci.c       | 67 ++++++++++++++++++-------------
>>  lib/librte_eal/linuxapp/eal/eal_pci.c     | 32 +++++++++------
>>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 37 ++++++++++-------
>>  3 files changed, 80 insertions(+), 56 deletions(-)
>>
>> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
>> index fe3ef86..cbd0a4e 100644
>> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
>> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
>> @@ -142,8 +142,9 @@ pci_map_resource(void *requested_addr, const char *devname, off_t offset,
>>  			MAP_SHARED, fd, offset);
>>  	close(fd);
>>  	if (mapaddr == MAP_FAILED ||
>> -			(requested_addr != NULL && mapaddr != requested_addr)) {
>> -		RTE_LOG(ERR, EAL, "%s(): cannot mmap(%s(%d), %p, 0x%lx, 0x%lx):"
>> +	    (requested_addr != NULL && mapaddr != requested_addr)) {
>> +		RTE_LOG(ERR, EAL,
>> +			"%s(): cannot mmap(%s(%d), %p, 0x%lx, 0x%lx):"
>>  			" %s (%p)\n", __func__, devname, fd, requested_addr,
>>  			(unsigned long)size, (unsigned long)offset,
>>  			strerror(errno), mapaddr);
>> @@ -161,9 +162,10 @@ fail:
>>  static int
>>  pci_uio_map_secondary(struct rte_pci_device *dev)
>>  {
>> -        size_t i;
>> -        struct uio_resource *uio_res;
>> -	struct uio_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
>> +	size_t i;
>> +	struct uio_resource *uio_res;
>> +	struct uio_res_list *uio_res_list =
>> +			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
>>  
>>  	TAILQ_FOREACH(uio_res, uio_res_list, next) {
>>  
>> @@ -179,10 +181,10 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
>>  			    != uio_res->maps[i].addr) {
>>  				RTE_LOG(ERR, EAL,
>>  					"Cannot mmap device resource\n");
>> -				return (-1);
>> +				return -1;
>>  			}
>>  		}
>> -		return (0);
>> +		return 0;
>>  	}
>>  
>>  	RTE_LOG(ERR, EAL, "Cannot find resource for device\n");
>> @@ -201,7 +203,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>>  	uint64_t pagesz;
>>  	struct rte_pci_addr *loc = &dev->addr;
>>  	struct uio_resource *uio_res;
>> -	struct uio_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
>> +	struct uio_res_list *uio_res_list =
>> +			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
>>  	struct uio_map *maps;
>>  
>>  	dev->intr_handle.fd = -1;
>> @@ -209,14 +212,16 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>>  
>>  	/* secondary processes - use already recorded details */
>>  	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
>> -		return (pci_uio_map_secondary(dev));
>> +		return pci_uio_map_secondary(dev);
>>  
>>  	snprintf(devname, sizeof(devname), "/dev/uio@pci:%u:%u:%u",
>>  			dev->addr.bus, dev->addr.devid, dev->addr.function);
>>  
>>  	if (access(devname, O_RDWR) < 0) {
>> -		RTE_LOG(WARNING, EAL, "  "PCI_PRI_FMT" not managed by UIO driver, "
>> -				"skipping\n", loc->domain, loc->bus, loc->devid, loc->function);
>> +		RTE_LOG(WARNING, EAL,
>> +			"  "PCI_PRI_FMT" not managed by UIO driver, "
>> +			"skipping\n", loc->domain, loc->bus,
>> +			loc->devid, loc->function);
>>  		return 1;
>>  	}
>>  
>> @@ -233,7 +238,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>>  	if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) == NULL) {
>>  		RTE_LOG(ERR, EAL,
>>  			"%s(): cannot store uio mmap details\n", __func__);
>> -		return (-1);
>> +		return -1;
>>  	}
>>  
>>  	snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
>> @@ -248,7 +253,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>>  
>>  		j = uio_res->nb_maps;
>>  		/* skip empty BAR */
>> -		if ((phaddr = dev->mem_resource[i].phys_addr) == 0)
>> +		phaddr = dev->mem_resource[i].phys_addr;
>> +		if (phaddr == 0)
>>  			continue;
>>  
>>  		/* if matching map is found, then use it */
>> @@ -261,7 +267,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>>  						(size_t)maps[j].size)
>>  		    ) == NULL) {
>>  			rte_free(uio_res);
>> -			return (-1);
>> +			return -1;
>>  		}
>>  
>>  		maps[j].addr = mapaddr;
>> @@ -271,7 +277,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>>  
>>  	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
>>  
>> -	return (0);
>> +	return 0;
>>  }
>>  
>>  /* Scan one pci sysfs entry, and fill the devices list from it. */
>> @@ -311,7 +317,7 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
>>  	/* FreeBSD has no NUMA support (yet) */
>>  	dev->numa_node = 0;
>>  
>> -/* parse resources */
>> +	/* parse resources */
>>  	switch (conf->pc_hdr & PCIM_HDRTYPE) {
>>  	case PCIM_HDRTYPE_NORMAL:
>>  		max = PCIR_MAX_BAR_0;
>> @@ -440,32 +446,37 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *d
>>  
>>  		/* 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)
>> +		    id_table->vendor_id != PCI_ANY_ID)
>>  			continue;
>>  		if (id_table->device_id != dev->id.device_id &&
>> -				id_table->device_id != PCI_ANY_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)
>> +		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)
>> +		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,
>> +			"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);
>> +		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");
>> +			RTE_LOG(DEBUG, EAL,
>> +				"  Device is blacklisted, not initializing\n");
>>  			return 0;
>>  		}
>>  
>> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
>> index 83c589e..353b0b8 100644
>> --- a/lib/librte_eal/linuxapp/eal/eal_pci.c
>> +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
>> @@ -154,7 +154,8 @@ pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
>>  	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",
>> +		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);
>> @@ -631,31 +632,36 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *d
>>  
>>  		/* 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)
>> +		    id_table->vendor_id != PCI_ANY_ID)
>>  			continue;
>>  		if (id_table->device_id != dev->id.device_id &&
>> -				id_table->device_id != PCI_ANY_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)
>> +		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)
>> +		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,
>> +			"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);
>> +		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");
>> +			RTE_LOG(DEBUG, EAL,
>> +				"  Device is blacklisted, not initializing\n");
>>  			return 1;
>>  		}
>>  
>> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>> index 2d1c69b..6f229d6 100644
>> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>> @@ -92,7 +92,8 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
>>  {
>>  	int fd, i;
>>  	struct mapped_pci_resource *uio_res;
>> -	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
>> +	struct mapped_pci_res_list *uio_res_list =
>> +			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
>>  
>>  	TAILQ_FOREACH(uio_res, uio_res_list, next) {
>>  
>> @@ -117,14 +118,16 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
>>  			if (mapaddr != uio_res->maps[i].addr) {
>>  				if (mapaddr == MAP_FAILED)
>>  					RTE_LOG(ERR, EAL,
>> -							"Cannot mmap device resource file %s: %s\n",
>> -							uio_res->maps[i].path,
>> -							strerror(errno));
>> +						"Cannot mmap device resource "
>> +						"file %s: %s\n",
>> +						uio_res->maps[i].path,
>> +						strerror(errno));
>>  				else
>>  					RTE_LOG(ERR, EAL,
>> -							"Cannot mmap device resource file %s to address: %p\n",
>> -							uio_res->maps[i].path,
>> -							uio_res->maps[i].addr);
>> +						"Cannot mmap device resource "
>> +						"file %s to address: %p\n",
>> +						uio_res->maps[i].path,
>> +						uio_res->maps[i].addr);
>>  
>>  				close(fd);
>>  				return -1;
>> @@ -272,7 +275,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>>  	uint64_t phaddr;
>>  	struct rte_pci_addr *loc = &dev->addr;
>>  	struct mapped_pci_resource *uio_res;
>> -	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
>> +	struct mapped_pci_res_list *uio_res_list =
>> +			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
>>  	struct pci_map *maps;
>>  
>>  	dev->intr_handle.fd = -1;
>> @@ -286,8 +290,10 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>>  	/* find uio resource */
>>  	uio_num = pci_get_uio_dev(dev, dirname, sizeof(dirname));
>>  	if (uio_num < 0) {
>> -		RTE_LOG(WARNING, EAL, "  "PCI_PRI_FMT" not managed by UIO driver, "
>> -				"skipping\n", loc->domain, loc->bus, loc->devid, loc->function);
>> +		RTE_LOG(WARNING, EAL,
>> +			"  "PCI_PRI_FMT" not managed by UIO driver, "
>> +			"skipping\n", loc->domain, loc->bus,
>> +			loc->devid, loc->function);
>>  		return 1;
>>  	}
>>  	snprintf(devname, sizeof(devname), "/dev/uio%u", uio_num);
>> @@ -338,12 +344,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>>  		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);
>> +				loc->domain, loc->bus, loc->devid,
>> +				loc->function, i);
>>  
>>  		/*
>>  		 * open resource file, to mmap it
>> @@ -412,7 +417,8 @@ static struct mapped_pci_resource *
>>  pci_uio_find_resource(struct rte_pci_device *dev)
>>  {
>>  	struct mapped_pci_resource *uio_res;
>> -	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
>> +	struct mapped_pci_res_list *uio_res_list =
>> +			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
>>  
>>  	if (dev == NULL)
>>  		return NULL;
>> @@ -431,7 +437,8 @@ void
>>  pci_uio_unmap_resource(struct rte_pci_device *dev)
>>  {
>>  	struct mapped_pci_resource *uio_res;
>> -	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
>> +	struct mapped_pci_res_list *uio_res_list =
>> +			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
>>  
>>  	if (dev == NULL)
>>  		return;
>> -- 
>> 1.9.1
>>


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

* Re: [dpdk-dev] [PATCH v2 07/15] eal: Fix interface of pci_map_resource() of bsdapp
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 07/15] eal: Fix interface of pci_map_resource() of bsdapp Tetsuya Mukawa
@ 2015-03-12 11:04     ` Bruce Richardson
  0 siblings, 0 replies; 87+ messages in thread
From: Bruce Richardson @ 2015-03-12 11:04 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Thu, Mar 12, 2015 at 07:17:46PM +0900, Tetsuya Mukawa wrote:
> The function is implemented in both linuxapp and bsdapp, but interface
> is different. The patch fixes the function of bsdapp to do same as
> linuxapp. After applying it, file descriptor should be opened and
> closed out of pci_map_resource().
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  lib/librte_eal/bsdapp/eal/eal_pci.c       | 117 +++++++++++++++++++-----------
>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c |   5 +-
>  2 files changed, 78 insertions(+), 44 deletions(-)
> 
> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
> index bd0f8cd..c92c624 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c

...<snip>...

> -			"%s(): cannot mmap(%s(%d), %p, 0x%lx, 0x%lx):"
> -			" %s (%p)\n", __func__, devname, fd, requested_addr,
> +			"%s(): cannot mmap(%d, %p, 0x%lx, 0x%lx): %s (%p)\n",
> +			__func__, fd, requested_addr,
>  			(unsigned long)size, (unsigned long)offset,
>  			strerror(errno), mapaddr);
> -		goto fail;
> +	} else {
> +		RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
>  	}

Coding style for DPDK is not to put braces around single-line blocks.

/Bruce

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

* Re: [dpdk-dev] [PATCH v2 01/15] eal: Fix cording style of eal_pci.c and eal_pci_uio.c
  2015-03-12 10:57       ` Qiu, Michael
@ 2015-03-12 11:09         ` Bruce Richardson
  2015-03-13  0:25           ` Tetsuya Mukawa
  0 siblings, 1 reply; 87+ messages in thread
From: Bruce Richardson @ 2015-03-12 11:09 UTC (permalink / raw)
  To: Qiu, Michael; +Cc: dev

On Thu, Mar 12, 2015 at 10:57:18AM +0000, Qiu, Michael wrote:
> On 3/12/2015 6:50 PM, Bruce Richardson wrote:
> > On Thu, Mar 12, 2015 at 07:17:40PM +0900, Tetsuya Mukawa wrote:
> >> This patch fixes cording style of below files in linuxapp and bsdapp.
> >>  - eal_pci.c
> >>  - eal_pci_uio.c
> >>
> >> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> > Hi Tetsuya,
> >
> > While there is some good cleanup here, I disagree with a number of the changes
> > made purely to the whitespace in the file. The style of using a double-indent
> > for line continuations is very widely used in DPDK code, much more so than the
> > style of lining things up with the previous line.
> 
> Yes, but both style are seeing in dpdk, here the patch is using Tab +
> whitespace, which is also
> the linux kernel's style.
> 
> So is there any rule to allow only one style?
> Mixed style is bad...
> 
> Thanks,
> Michael

No there is no hard rule, that I am aware of. While I prefer the double-indent
myself, that is beside the point that in the absense of a hard rule to be applied
globally, fixing whitespace from style A to style B just increases the size
of the diff which makes it hard to see the real code changes. Even with a slight
mixing of the styles the code is readable enough as-is.

/Bruce

> > So ack to the changes removing unnecessary braces, and occasional splitting of
> > really long lines (though a few chars over 80 is ok). NAK to the whitespace
> > and indentation changes.
> >
> > Regards,
> > /Bruce
> >
> >> ---
> >>  lib/librte_eal/bsdapp/eal/eal_pci.c       | 67 ++++++++++++++++++-------------
> >>  lib/librte_eal/linuxapp/eal/eal_pci.c     | 32 +++++++++------
> >>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 37 ++++++++++-------
> >>  3 files changed, 80 insertions(+), 56 deletions(-)
> >>
> >> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
> >> index fe3ef86..cbd0a4e 100644
> >> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> >> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> >> @@ -142,8 +142,9 @@ pci_map_resource(void *requested_addr, const char *devname, off_t offset,
> >>  			MAP_SHARED, fd, offset);
> >>  	close(fd);
> >>  	if (mapaddr == MAP_FAILED ||
> >> -			(requested_addr != NULL && mapaddr != requested_addr)) {
> >> -		RTE_LOG(ERR, EAL, "%s(): cannot mmap(%s(%d), %p, 0x%lx, 0x%lx):"
> >> +	    (requested_addr != NULL && mapaddr != requested_addr)) {
> >> +		RTE_LOG(ERR, EAL,
> >> +			"%s(): cannot mmap(%s(%d), %p, 0x%lx, 0x%lx):"
> >>  			" %s (%p)\n", __func__, devname, fd, requested_addr,
> >>  			(unsigned long)size, (unsigned long)offset,
> >>  			strerror(errno), mapaddr);
> >> @@ -161,9 +162,10 @@ fail:
> >>  static int
> >>  pci_uio_map_secondary(struct rte_pci_device *dev)
> >>  {
> >> -        size_t i;
> >> -        struct uio_resource *uio_res;
> >> -	struct uio_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
> >> +	size_t i;
> >> +	struct uio_resource *uio_res;
> >> +	struct uio_res_list *uio_res_list =
> >> +			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
> >>  
> >>  	TAILQ_FOREACH(uio_res, uio_res_list, next) {
> >>  
> >> @@ -179,10 +181,10 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
> >>  			    != uio_res->maps[i].addr) {
> >>  				RTE_LOG(ERR, EAL,
> >>  					"Cannot mmap device resource\n");
> >> -				return (-1);
> >> +				return -1;
> >>  			}
> >>  		}
> >> -		return (0);
> >> +		return 0;
> >>  	}
> >>  
> >>  	RTE_LOG(ERR, EAL, "Cannot find resource for device\n");
> >> @@ -201,7 +203,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
> >>  	uint64_t pagesz;
> >>  	struct rte_pci_addr *loc = &dev->addr;
> >>  	struct uio_resource *uio_res;
> >> -	struct uio_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
> >> +	struct uio_res_list *uio_res_list =
> >> +			RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
> >>  	struct uio_map *maps;
> >>  
> >>  	dev->intr_handle.fd = -1;
> >> @@ -209,14 +212,16 @@ pci_uio_map_resource(struct rte_pci_device *dev)
> >>  
> >>  	/* secondary processes - use already recorded details */
> >>  	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
> >> -		return (pci_uio_map_secondary(dev));
> >> +		return pci_uio_map_secondary(dev);
> >>  
> >>  	snprintf(devname, sizeof(devname), "/dev/uio@pci:%u:%u:%u",
> >>  			dev->addr.bus, dev->addr.devid, dev->addr.function);
> >>  
> >>  	if (access(devname, O_RDWR) < 0) {
> >> -		RTE_LOG(WARNING, EAL, "  "PCI_PRI_FMT" not managed by UIO driver, "
> >> -				"skipping\n", loc->domain, loc->bus, loc->devid, loc->function);
> >> +		RTE_LOG(WARNING, EAL,
> >> +			"  "PCI_PRI_FMT" not managed by UIO driver, "
> >> +			"skipping\n", loc->domain, loc->bus,
> >> +			loc->devid, loc->function);
> >>  		return 1;
> >>  	}
> >>  
> >> @@ -233,7 +238,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
> >>  	if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) == NULL) {
> >>  		RTE_LOG(ERR, EAL,
> >>  			"%s(): cannot store uio mmap details\n", __func__);
> >> -		return (-1);
> >> +		return -1;
> >>  	}
> >>  
> >>  	snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
> >> @@ -248,7 +253,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
> >>  
> >>  		j = uio_res->nb_maps;
> >>  		/* skip empty BAR */
> >> -		if ((phaddr = dev->mem_resource[i].phys_addr) == 0)
> >> +		phaddr = dev->mem_resource[i].phys_addr;
> >> +		if (phaddr == 0)
> >>  			continue;
> >>  
> >>  		/* if matching map is found, then use it */
> >> @@ -261,7 +267,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
> >>  						(size_t)maps[j].size)
> >>  		    ) == NULL) {
> >>  			rte_free(uio_res);
> >> -			return (-1);
> >> +			return -1;
> >>  		}
> >>  
> >>  		maps[j].addr = mapaddr;
> >> @@ -271,7 +277,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
> >>  
> >>  	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
> >>  
> >> -	return (0);
> >> +	return 0;
> >>  }
> >>  
> >>  /* Scan one pci sysfs entry, and fill the devices list from it. */
> >> @@ -311,7 +317,7 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
> >>  	/* FreeBSD has no NUMA support (yet) */
> >>  	dev->numa_node = 0;
> >>  
> >> -/* parse resources */
> >> +	/* parse resources */
> >>  	switch (conf->pc_hdr & PCIM_HDRTYPE) {
> >>  	case PCIM_HDRTYPE_NORMAL:
> >>  		max = PCIR_MAX_BAR_0;
> >> @@ -440,32 +446,37 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *d
> >>  
> >>  		/* 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)
> >> +		    id_table->vendor_id != PCI_ANY_ID)
> >>  			continue;
> >>  		if (id_table->device_id != dev->id.device_id &&
> >> -				id_table->device_id != PCI_ANY_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)
> >> +		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)
> >> +		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,
> >> +			"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);
> >> +		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");
> >> +			RTE_LOG(DEBUG, EAL,
> >> +				"  Device is blacklisted, not initializing\n");
> >>  			return 0;
> >>  		}
> >>  
> >> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
> >> index 83c589e..353b0b8 100644
> >> --- a/lib/librte_eal/linuxapp/eal/eal_pci.c
> >> +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
> >> @@ -154,7 +154,8 @@ pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
> >>  	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",
> >> +		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);
> >> @@ -631,31 +632,36 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *d
> >>  
> >>  		/* 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)
> >> +		    id_table->vendor_id != PCI_ANY_ID)
> >>  			continue;
> >>  		if (id_table->device_id != dev->id.device_id &&
> >> -				id_table->device_id != PCI_ANY_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)
> >> +		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)
> >> +		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,
> >> +			"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);
> >> +		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");
> >> +			RTE_LOG(DEBUG, EAL,
> >> +				"  Device is blacklisted, not initializing\n");
> >>  			return 1;
> >>  		}
> >>  
> >> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> >> index 2d1c69b..6f229d6 100644
> >> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> >> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> >> @@ -92,7 +92,8 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
> >>  {
> >>  	int fd, i;
> >>  	struct mapped_pci_resource *uio_res;
> >> -	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
> >> +	struct mapped_pci_res_list *uio_res_list =
> >> +			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
> >>  
> >>  	TAILQ_FOREACH(uio_res, uio_res_list, next) {
> >>  
> >> @@ -117,14 +118,16 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
> >>  			if (mapaddr != uio_res->maps[i].addr) {
> >>  				if (mapaddr == MAP_FAILED)
> >>  					RTE_LOG(ERR, EAL,
> >> -							"Cannot mmap device resource file %s: %s\n",
> >> -							uio_res->maps[i].path,
> >> -							strerror(errno));
> >> +						"Cannot mmap device resource "
> >> +						"file %s: %s\n",
> >> +						uio_res->maps[i].path,
> >> +						strerror(errno));
> >>  				else
> >>  					RTE_LOG(ERR, EAL,
> >> -							"Cannot mmap device resource file %s to address: %p\n",
> >> -							uio_res->maps[i].path,
> >> -							uio_res->maps[i].addr);
> >> +						"Cannot mmap device resource "
> >> +						"file %s to address: %p\n",
> >> +						uio_res->maps[i].path,
> >> +						uio_res->maps[i].addr);
> >>  
> >>  				close(fd);
> >>  				return -1;
> >> @@ -272,7 +275,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
> >>  	uint64_t phaddr;
> >>  	struct rte_pci_addr *loc = &dev->addr;
> >>  	struct mapped_pci_resource *uio_res;
> >> -	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
> >> +	struct mapped_pci_res_list *uio_res_list =
> >> +			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
> >>  	struct pci_map *maps;
> >>  
> >>  	dev->intr_handle.fd = -1;
> >> @@ -286,8 +290,10 @@ pci_uio_map_resource(struct rte_pci_device *dev)
> >>  	/* find uio resource */
> >>  	uio_num = pci_get_uio_dev(dev, dirname, sizeof(dirname));
> >>  	if (uio_num < 0) {
> >> -		RTE_LOG(WARNING, EAL, "  "PCI_PRI_FMT" not managed by UIO driver, "
> >> -				"skipping\n", loc->domain, loc->bus, loc->devid, loc->function);
> >> +		RTE_LOG(WARNING, EAL,
> >> +			"  "PCI_PRI_FMT" not managed by UIO driver, "
> >> +			"skipping\n", loc->domain, loc->bus,
> >> +			loc->devid, loc->function);
> >>  		return 1;
> >>  	}
> >>  	snprintf(devname, sizeof(devname), "/dev/uio%u", uio_num);
> >> @@ -338,12 +344,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
> >>  		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);
> >> +				loc->domain, loc->bus, loc->devid,
> >> +				loc->function, i);
> >>  
> >>  		/*
> >>  		 * open resource file, to mmap it
> >> @@ -412,7 +417,8 @@ static struct mapped_pci_resource *
> >>  pci_uio_find_resource(struct rte_pci_device *dev)
> >>  {
> >>  	struct mapped_pci_resource *uio_res;
> >> -	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
> >> +	struct mapped_pci_res_list *uio_res_list =
> >> +			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
> >>  
> >>  	if (dev == NULL)
> >>  		return NULL;
> >> @@ -431,7 +437,8 @@ void
> >>  pci_uio_unmap_resource(struct rte_pci_device *dev)
> >>  {
> >>  	struct mapped_pci_resource *uio_res;
> >> -	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
> >> +	struct mapped_pci_res_list *uio_res_list =
> >> +			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
> >>  
> >>  	if (dev == NULL)
> >>  		return;
> >> -- 
> >> 1.9.1
> >>
> 
> 

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

* Re: [dpdk-dev] [PATCH v2 01/15] eal: Fix cording style of eal_pci.c and eal_pci_uio.c
  2015-03-12 11:09         ` Bruce Richardson
@ 2015-03-13  0:25           ` Tetsuya Mukawa
  0 siblings, 0 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-13  0:25 UTC (permalink / raw)
  To: Bruce Richardson; +Cc: dev

2015-03-12 20:09 GMT+09:00 Bruce Richardson <bruce.richardson@intel.com>:
> On Thu, Mar 12, 2015 at 10:57:18AM +0000, Qiu, Michael wrote:
>> On 3/12/2015 6:50 PM, Bruce Richardson wrote:
>> > On Thu, Mar 12, 2015 at 07:17:40PM +0900, Tetsuya Mukawa wrote:
>> >> This patch fixes cording style of below files in linuxapp and bsdapp.
>> >>  - eal_pci.c
>> >>  - eal_pci_uio.c
>> >>
>> >> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
>> > Hi Tetsuya,
>> >
>> > While there is some good cleanup here, I disagree with a number of the changes
>> > made purely to the whitespace in the file. The style of using a double-indent
>> > for line continuations is very widely used in DPDK code, much more so than the
>> > style of lining things up with the previous line.
>>
>> Yes, but both style are seeing in dpdk, here the patch is using Tab +
>> whitespace, which is also
>> the linux kernel's style.
>>
>> So is there any rule to allow only one style?
>> Mixed style is bad...
>>
>> Thanks,
>> Michael
>
> No there is no hard rule, that I am aware of. While I prefer the double-indent
> myself, that is beside the point that in the absense of a hard rule to be applied
> globally, fixing whitespace from style A to style B just increases the size
> of the diff which makes it hard to see the real code changes. Even with a slight
> mixing of the styles the code is readable enough as-is.
>
> /Bruce

Hi Bruce, Michael,

Thanks for your reviews.
I will fix it, and submit again early next week.

Regards,
Tetsuya

>
>> > So ack to the changes removing unnecessary braces, and occasional splitting of
>> > really long lines (though a few chars over 80 is ok). NAK to the whitespace
>> > and indentation changes.
>> >
>> > Regards,
>> > /Bruce
>> >
>> >> ---
>> >>  lib/librte_eal/bsdapp/eal/eal_pci.c       | 67 ++++++++++++++++++-------------
>> >>  lib/librte_eal/linuxapp/eal/eal_pci.c     | 32 +++++++++------
>> >>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 37 ++++++++++-------
>> >>  3 files changed, 80 insertions(+), 56 deletions(-)
>> >>
>> >> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
>> >> index fe3ef86..cbd0a4e 100644
>> >> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
>> >> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
>> >> @@ -142,8 +142,9 @@ pci_map_resource(void *requested_addr, const char *devname, off_t offset,
>> >>                    MAP_SHARED, fd, offset);
>> >>    close(fd);
>> >>    if (mapaddr == MAP_FAILED ||
>> >> -                  (requested_addr != NULL && mapaddr != requested_addr)) {
>> >> -          RTE_LOG(ERR, EAL, "%s(): cannot mmap(%s(%d), %p, 0x%lx, 0x%lx):"
>> >> +      (requested_addr != NULL && mapaddr != requested_addr)) {
>> >> +          RTE_LOG(ERR, EAL,
>> >> +                  "%s(): cannot mmap(%s(%d), %p, 0x%lx, 0x%lx):"
>> >>                    " %s (%p)\n", __func__, devname, fd, requested_addr,
>> >>                    (unsigned long)size, (unsigned long)offset,
>> >>                    strerror(errno), mapaddr);
>> >> @@ -161,9 +162,10 @@ fail:
>> >>  static int
>> >>  pci_uio_map_secondary(struct rte_pci_device *dev)
>> >>  {
>> >> -        size_t i;
>> >> -        struct uio_resource *uio_res;
>> >> -  struct uio_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
>> >> +  size_t i;
>> >> +  struct uio_resource *uio_res;
>> >> +  struct uio_res_list *uio_res_list =
>> >> +                  RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
>> >>
>> >>    TAILQ_FOREACH(uio_res, uio_res_list, next) {
>> >>
>> >> @@ -179,10 +181,10 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
>> >>                        != uio_res->maps[i].addr) {
>> >>                            RTE_LOG(ERR, EAL,
>> >>                                    "Cannot mmap device resource\n");
>> >> -                          return (-1);
>> >> +                          return -1;
>> >>                    }
>> >>            }
>> >> -          return (0);
>> >> +          return 0;
>> >>    }
>> >>
>> >>    RTE_LOG(ERR, EAL, "Cannot find resource for device\n");
>> >> @@ -201,7 +203,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>> >>    uint64_t pagesz;
>> >>    struct rte_pci_addr *loc = &dev->addr;
>> >>    struct uio_resource *uio_res;
>> >> -  struct uio_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
>> >> +  struct uio_res_list *uio_res_list =
>> >> +                  RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);
>> >>    struct uio_map *maps;
>> >>
>> >>    dev->intr_handle.fd = -1;
>> >> @@ -209,14 +212,16 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>> >>
>> >>    /* secondary processes - use already recorded details */
>> >>    if (rte_eal_process_type() != RTE_PROC_PRIMARY)
>> >> -          return (pci_uio_map_secondary(dev));
>> >> +          return pci_uio_map_secondary(dev);
>> >>
>> >>    snprintf(devname, sizeof(devname), "/dev/uio@pci:%u:%u:%u",
>> >>                    dev->addr.bus, dev->addr.devid, dev->addr.function);
>> >>
>> >>    if (access(devname, O_RDWR) < 0) {
>> >> -          RTE_LOG(WARNING, EAL, "  "PCI_PRI_FMT" not managed by UIO driver, "
>> >> -                          "skipping\n", loc->domain, loc->bus, loc->devid, loc->function);
>> >> +          RTE_LOG(WARNING, EAL,
>> >> +                  "  "PCI_PRI_FMT" not managed by UIO driver, "
>> >> +                  "skipping\n", loc->domain, loc->bus,
>> >> +                  loc->devid, loc->function);
>> >>            return 1;
>> >>    }
>> >>
>> >> @@ -233,7 +238,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>> >>    if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) == NULL) {
>> >>            RTE_LOG(ERR, EAL,
>> >>                    "%s(): cannot store uio mmap details\n", __func__);
>> >> -          return (-1);
>> >> +          return -1;
>> >>    }
>> >>
>> >>    snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
>> >> @@ -248,7 +253,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>> >>
>> >>            j = uio_res->nb_maps;
>> >>            /* skip empty BAR */
>> >> -          if ((phaddr = dev->mem_resource[i].phys_addr) == 0)
>> >> +          phaddr = dev->mem_resource[i].phys_addr;
>> >> +          if (phaddr == 0)
>> >>                    continue;
>> >>
>> >>            /* if matching map is found, then use it */
>> >> @@ -261,7 +267,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>> >>                                            (size_t)maps[j].size)
>> >>                ) == NULL) {
>> >>                    rte_free(uio_res);
>> >> -                  return (-1);
>> >> +                  return -1;
>> >>            }
>> >>
>> >>            maps[j].addr = mapaddr;
>> >> @@ -271,7 +277,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>> >>
>> >>    TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
>> >>
>> >> -  return (0);
>> >> +  return 0;
>> >>  }
>> >>
>> >>  /* Scan one pci sysfs entry, and fill the devices list from it. */
>> >> @@ -311,7 +317,7 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
>> >>    /* FreeBSD has no NUMA support (yet) */
>> >>    dev->numa_node = 0;
>> >>
>> >> -/* parse resources */
>> >> +  /* parse resources */
>> >>    switch (conf->pc_hdr & PCIM_HDRTYPE) {
>> >>    case PCIM_HDRTYPE_NORMAL:
>> >>            max = PCIR_MAX_BAR_0;
>> >> @@ -440,32 +446,37 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *d
>> >>
>> >>            /* 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)
>> >> +              id_table->vendor_id != PCI_ANY_ID)
>> >>                    continue;
>> >>            if (id_table->device_id != dev->id.device_id &&
>> >> -                          id_table->device_id != PCI_ANY_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)
>> >> +          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)
>> >> +          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,
>> >> +                  "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);
>> >> +          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");
>> >> +                  RTE_LOG(DEBUG, EAL,
>> >> +                          "  Device is blacklisted, not initializing\n");
>> >>                    return 0;
>> >>            }
>> >>
>> >> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
>> >> index 83c589e..353b0b8 100644
>> >> --- a/lib/librte_eal/linuxapp/eal/eal_pci.c
>> >> +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
>> >> @@ -154,7 +154,8 @@ pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
>> >>    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",
>> >> +          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);
>> >> @@ -631,31 +632,36 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *d
>> >>
>> >>            /* 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)
>> >> +              id_table->vendor_id != PCI_ANY_ID)
>> >>                    continue;
>> >>            if (id_table->device_id != dev->id.device_id &&
>> >> -                          id_table->device_id != PCI_ANY_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)
>> >> +          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)
>> >> +          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,
>> >> +                  "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);
>> >> +          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");
>> >> +                  RTE_LOG(DEBUG, EAL,
>> >> +                          "  Device is blacklisted, not initializing\n");
>> >>                    return 1;
>> >>            }
>> >>
>> >> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>> >> index 2d1c69b..6f229d6 100644
>> >> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>> >> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>> >> @@ -92,7 +92,8 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
>> >>  {
>> >>    int fd, i;
>> >>    struct mapped_pci_resource *uio_res;
>> >> -  struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
>> >> +  struct mapped_pci_res_list *uio_res_list =
>> >> +                  RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
>> >>
>> >>    TAILQ_FOREACH(uio_res, uio_res_list, next) {
>> >>
>> >> @@ -117,14 +118,16 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
>> >>                    if (mapaddr != uio_res->maps[i].addr) {
>> >>                            if (mapaddr == MAP_FAILED)
>> >>                                    RTE_LOG(ERR, EAL,
>> >> -                                                  "Cannot mmap device resource file %s: %s\n",
>> >> -                                                  uio_res->maps[i].path,
>> >> -                                                  strerror(errno));
>> >> +                                          "Cannot mmap device resource "
>> >> +                                          "file %s: %s\n",
>> >> +                                          uio_res->maps[i].path,
>> >> +                                          strerror(errno));
>> >>                            else
>> >>                                    RTE_LOG(ERR, EAL,
>> >> -                                                  "Cannot mmap device resource file %s to address: %p\n",
>> >> -                                                  uio_res->maps[i].path,
>> >> -                                                  uio_res->maps[i].addr);
>> >> +                                          "Cannot mmap device resource "
>> >> +                                          "file %s to address: %p\n",
>> >> +                                          uio_res->maps[i].path,
>> >> +                                          uio_res->maps[i].addr);
>> >>
>> >>                            close(fd);
>> >>                            return -1;
>> >> @@ -272,7 +275,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>> >>    uint64_t phaddr;
>> >>    struct rte_pci_addr *loc = &dev->addr;
>> >>    struct mapped_pci_resource *uio_res;
>> >> -  struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
>> >> +  struct mapped_pci_res_list *uio_res_list =
>> >> +                  RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
>> >>    struct pci_map *maps;
>> >>
>> >>    dev->intr_handle.fd = -1;
>> >> @@ -286,8 +290,10 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>> >>    /* find uio resource */
>> >>    uio_num = pci_get_uio_dev(dev, dirname, sizeof(dirname));
>> >>    if (uio_num < 0) {
>> >> -          RTE_LOG(WARNING, EAL, "  "PCI_PRI_FMT" not managed by UIO driver, "
>> >> -                          "skipping\n", loc->domain, loc->bus, loc->devid, loc->function);
>> >> +          RTE_LOG(WARNING, EAL,
>> >> +                  "  "PCI_PRI_FMT" not managed by UIO driver, "
>> >> +                  "skipping\n", loc->domain, loc->bus,
>> >> +                  loc->devid, loc->function);
>> >>            return 1;
>> >>    }
>> >>    snprintf(devname, sizeof(devname), "/dev/uio%u", uio_num);
>> >> @@ -338,12 +344,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>> >>            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);
>> >> +                          loc->domain, loc->bus, loc->devid,
>> >> +                          loc->function, i);
>> >>
>> >>            /*
>> >>             * open resource file, to mmap it
>> >> @@ -412,7 +417,8 @@ static struct mapped_pci_resource *
>> >>  pci_uio_find_resource(struct rte_pci_device *dev)
>> >>  {
>> >>    struct mapped_pci_resource *uio_res;
>> >> -  struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
>> >> +  struct mapped_pci_res_list *uio_res_list =
>> >> +                  RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
>> >>
>> >>    if (dev == NULL)
>> >>            return NULL;
>> >> @@ -431,7 +437,8 @@ void
>> >>  pci_uio_unmap_resource(struct rte_pci_device *dev)
>> >>  {
>> >>    struct mapped_pci_resource *uio_res;
>> >> -  struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
>> >> +  struct mapped_pci_res_list *uio_res_list =
>> >> +                  RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
>> >>
>> >>    if (dev == NULL)
>> >>            return;
>> >> --
>> >> 1.9.1
>> >>
>>
>>

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

* Re: [dpdk-dev] [PATCH v2 00/15] eal: Port Hotplug support for BSD
  2015-03-12 10:17 ` [dpdk-dev] [PATCH v2 00/15] eal: Port Hotplug support for BSD Tetsuya Mukawa
                     ` (14 preceding siblings ...)
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 15/15] eal: Enable Port Hotplug as default in Linux and BSD Tetsuya Mukawa
@ 2015-03-13 11:46   ` Iremonger, Bernard
  2015-03-16  3:36     ` Tetsuya Mukawa
  15 siblings, 1 reply; 87+ messages in thread
From: Iremonger, Bernard @ 2015-03-13 11:46 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev



> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Thursday, March 12, 2015 10:18 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; Richardson, Bruce; Tetsuya Mukawa
> Subject: [PATCH v2 00/15] eal: Port Hotplug support for BSD
> 
> This patch series adds port hotplug support to BSD.
> Also, the patches consolidates pci uio functions of linuxapp and bsdapp.
> 
> Following patches cleanup pci uio code to consolidate later.
>   eal: Fix cording style of eal_pci.c and eal_pci_uio.c
>   eal: Close file descriptor of uio configuration
>   eal: Fix memory leak of pci_uio_map_resource()
>   eal: Fix needless incrementation of pci_map_addr
>   eal/bsdapp: Change names of pci related data structure
>   eal: Use map_idx in pci_uio_map_resource() of bsdapp to work same as
>     linuxapp
>   eal: Fix interface of pci_map_resource() of bsdapp
>   eal: Add pci_uio_alloc_uio_resource()
>   eal: Add pci_uio_map_uio_resource_by_index()
> 
Hi Tetsuya,

It might be better to split this patchset into two patch sets, 
A cleanup patchset and a consolidation patchset. 
It would make reviewing easier.

Regards,

Bernard.


> Following patches are actually for functions consolidation.
>   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
> 
> The last patch removes CONFIG_RTE_LIBRTE_EAL_HOTPLUG configuration from Linux and BSD.
> And port hotplug is enabled as default with both Linux and BSD.
>   eal: Enable Port Hotplug as default in Linux and BSD
> 
> 
> PATCH v2 changes
>  - Consolidate pci uio functions of linuxapp and bsdapp.
> 
> 
> Tetsuya Mukawa (15):
>   eal: Fix cording style of eal_pci.c and eal_pci_uio.c
>   eal: Close file descriptor of uio configuration
>   eal: Fix memory leak of pci_uio_map_resource()
>   eal: Fix needless incrementation of pci_map_addr
>   eal/bsdapp: Change names of pci related data structure
>   eal: Use map_idx in pci_uio_map_resource() of bsdapp to work same as
>     linuxapp
>   eal: Fix interface of pci_map_resource() of bsdapp
>   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                | 292 ++++++---------------
>  .../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             | 234 ++++++++++++++++-
>  lib/librte_eal/common/eal_common_pci_uio.c         | 224 ++++++++++++++++
>  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          | 263 +++++--------------
>  lib/librte_ether/rte_ethdev.c                      |  22 +-
>  16 files changed, 702 insertions(+), 729 deletions(-)  create mode 100644
> lib/librte_eal/common/eal_common_pci_uio.c
> 
> --
> 1.9.1

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

* Re: [dpdk-dev] [PATCH v2 02/15] eal: Close file descriptor of uio configuration
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 02/15] eal: Close file descriptor of uio configuration Tetsuya Mukawa
@ 2015-03-13 13:54     ` Iremonger, Bernard
  0 siblings, 0 replies; 87+ messages in thread
From: Iremonger, Bernard @ 2015-03-13 13:54 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev



> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Thursday, March 12, 2015 10:18 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; Richardson, Bruce; Tetsuya Mukawa
> Subject: [PATCH v2 02/15] eal: Close file descriptor of uio configuration
> 
> When pci_uio_unmap_resource() is called, a file descriptor that is used for uio configuration should be
> closed.
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> index 6f229d6..77bb5ed 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> @@ -462,6 +462,8 @@ pci_uio_unmap_resource(struct rte_pci_device *dev)
> 
>  	/* 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);
Hi Tetsuya,
 
Should  dev->intr_handle.uio_cfg_fd be set to -1 after closing it?

Regards,

Bernard.


> 
>  	dev->intr_handle.fd = -1;
>  	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
> --
> 1.9.1

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

* Re: [dpdk-dev] [PATCH v2 03/15] eal: Fix memory leak of pci_uio_map_resource()
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 03/15] eal: Fix memory leak of pci_uio_map_resource() Tetsuya Mukawa
@ 2015-03-13 14:04     ` Iremonger, Bernard
  2015-03-17  9:30     ` [dpdk-dev] [PATCH 0/6] Clean up pci uio implementations Tetsuya Mukawa
  1 sibling, 0 replies; 87+ messages in thread
From: Iremonger, Bernard @ 2015-03-13 14:04 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev



> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Thursday, March 12, 2015 10:18 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; Richardson, Bruce; Tetsuya Mukawa
> Subject: [PATCH v2 03/15] eal: Fix memory leak of pci_uio_map_resource()
> 
> When pci_map_resource() is failed but path is allocated correctly, path won't be freed. Also, when
> open() is failed, uio_res won't be freed.
> This patch fixes these.
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 20 +++++++++++++-------
>  1 file changed, 13 insertions(+), 7 deletions(-)
> 
> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> index 77bb5ed..901f277 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> @@ -350,6 +350,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  				loc->domain, loc->bus, loc->devid,
>  				loc->function, i);
> 
> +		/* allocate memory to keep path */
> +		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
> +		if (maps[map_idx].path == NULL)
> +			goto fail0;
> +
>  		/*
>  		 * open resource file, to mmap it
>  		 */
> @@ -357,7 +362,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  		if (fd < 0) {
>  			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
>  					devname, strerror(errno));
> -			return -1;
> +			goto fail0;
>  		}
> 
>  		/* try mapping somewhere close to the end of hugepages */ @@ -372,14 +377,9 @@
> pci_uio_map_resource(struct rte_pci_device *dev)
>  		pci_map_addr = RTE_PTR_ADD(mapaddr,
>  				(size_t)dev->mem_resource[i].len);
> 
> -		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
> -		if (maps[map_idx].path == NULL)
> -			fail = 1;
> -
Hi Tetsuya,

Could close(fd) be called before if(fail) and the following two close(fd) calls removed ?

Regards,

Bernard.

>  		if (fail) {
> -			rte_free(uio_res);
>  			close(fd);
> -			return -1;
> +			goto fail1;
>  		}
>  		close(fd);
> 
> @@ -397,6 +397,12 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
> 
>  	return 0;
> +
> +fail1:
> +	rte_free(maps[map_idx].path);
> +fail0:
> +	rte_free(uio_res);
> +	return -1;
>  }
> 
>  #ifdef RTE_LIBRTE_EAL_HOTPLUG
> --
> 1.9.1

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

* Re: [dpdk-dev] [PATCH v2 04/15] eal: Fix needless incrementation of pci_map_addr
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 04/15] eal: Fix needless incrementation of pci_map_addr Tetsuya Mukawa
@ 2015-03-13 14:49     ` Iremonger, Bernard
  0 siblings, 0 replies; 87+ messages in thread
From: Iremonger, Bernard @ 2015-03-13 14:49 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev



> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Thursday, March 12, 2015 10:18 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; Richardson, Bruce; Tetsuya Mukawa
> Subject: [PATCH v2 04/15] eal: Fix needless incrementation of pci_map_addr
> 
> When pci_map_resource() is failed, mapaddr will be MAP_FAILED.
> In this case, pci_map_addr should not be incremented.
> The patch fixes it. Also, fix below.
>  - To shrink code, move close().
>  - Remove fail variable.
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 10 ++--------
>  1 file changed, 2 insertions(+), 8 deletions(-)
> 
> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> index 901f277..2741c62 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> @@ -337,7 +337,6 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  	maps = uio_res->maps;
>  	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
>  		int fd;
> -		int fail = 0;
> 
>  		/* skip empty BAR */
>  		phaddr = dev->mem_resource[i].phys_addr; @@ -371,18 +370,13 @@
> pci_uio_map_resource(struct rte_pci_device *dev)
> 
>  		mapaddr = pci_map_resource(pci_map_addr, fd, 0,
>  				(size_t)dev->mem_resource[i].len, 0);
> +		close(fd);
>  		if (mapaddr == MAP_FAILED)
> -			fail = 1;
> +			goto fail1;
> 
>  		pci_map_addr = RTE_PTR_ADD(mapaddr,
>  				(size_t)dev->mem_resource[i].len);
> 
> -		if (fail) {
> -			close(fd);
> -			goto fail1;
> -		}
> -		close(fd);
> -
>  		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
>  		maps[map_idx].size = dev->mem_resource[i].len;
>  		maps[map_idx].addr = mapaddr;
> --
> 1.9.1
Hi Tetsuya,

This patch could be squashed into patch 3.

Regards,

Bernard.

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

* Re: [dpdk-dev] [PATCH v2 11/15] eal: Consolidate rte_eal_pci_probe/close_one_driver() of linuxapp and bsdapp
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 11/15] eal: Consolidate rte_eal_pci_probe/close_one_driver() " Tetsuya Mukawa
@ 2015-03-13 15:03     ` Iremonger, Bernard
  0 siblings, 0 replies; 87+ messages in thread
From: Iremonger, Bernard @ 2015-03-13 15:03 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev



> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Thursday, March 12, 2015 10:18 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; Richardson, Bruce; Tetsuya Mukawa
> Subject: [PATCH v2 11/15] eal: Consolidate rte_eal_pci_probe/close_one_driver() of linuxapp and
> bsdapp
> 
> 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    |  79 ++---------------
>  lib/librte_eal/common/eal_common_pci.c | 138 +++++++++++++++++++++++++++++
>  lib/librte_eal/common/eal_private.h    |  21 ++---
>  lib/librte_eal/linuxapp/eal/eal_pci.c  | 153 ++-------------------------------
>  4 files changed, 162 insertions(+), 229 deletions(-)
> 
> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
> index 67ad88f..3778763 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 "
> @@ -429,6 +429,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.
> @@ -479,76 +486,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) -{
> -	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 808b87b..538b2d9 100644
> --- a/lib/librte_eal/common/eal_common_pci.c
> +++ b/lib/librte_eal/common/eal_common_pci.c
> @@ -99,6 +99,144 @@ 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;
> +	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

Hi Tetsuya,

Can  #ifdef RTE_LIBRTE_EAL_HOTPLUG be removed now as file is common ?

Regards,

Bernard.


> +/*
> + * 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)
> +{
> +	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 */

Hi Tetsuya,

Can the #endif be removed too?

Regards,

Bernard.

 

> +
> +/*
>   * 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 353b0b8..dbc2548 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;
> @@ -565,7 +565,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;
> @@ -594,7 +595,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)
> @@ -618,151 +620,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;
> -	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)
> -{
> -	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)
> --
> 1.9.1

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

* Re: [dpdk-dev] [PATCH v2 12/15] eal: Consolidate pci_map/unmap_device() of linuxapp and bsdapp
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 12/15] eal: Consolidate pci_map/unmap_device() " Tetsuya Mukawa
@ 2015-03-13 15:10     ` Iremonger, Bernard
  0 siblings, 0 replies; 87+ messages in thread
From: Iremonger, Bernard @ 2015-03-13 15:10 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev



> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Thursday, March 12, 2015 10:18 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; Richardson, Bruce; Tetsuya Mukawa
> Subject: [PATCH v2 12/15] eal: Consolidate pci_map/unmap_device() of linuxapp and bsdapp
> 
> 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 3778763..1e42e42 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> @@ -280,7 +280,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;
> @@ -364,6 +364,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->pt_driver = RTE_PT_NIC_UIO;
> +
>  	/* parse resources */
>  	switch (conf->pc_hdr & PCIM_HDRTYPE) {
>  	case PCIM_HDRTYPE_NORMAL:
> @@ -429,13 +432,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 538b2d9..726026f 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->pt_driver) {
> +	case RTE_PT_VFIO:
> +#ifdef VFIO_PRESENT
> +		if (pci_vfio_is_enabled())
> +			ret = pci_vfio_map_resource(dev);
> +#endif
> +		break;
> +	case RTE_PT_IGB_UIO:
> +	case RTE_PT_UIO_GENERIC:
> +	case RTE_PT_NIC_UIO:
> +		/* map resources for devices that use uio */
> +		ret = pci_uio_map_resource(dev);
> +		break;
> +	default:
> +		RTE_LOG(DEBUG, EAL, "  Not managed by known pt driver,"
> +			" skipped\n");
> +		ret = 1;
> +		break;
> +	}
> +
> +	return ret;
> +}
> +
> +#ifdef RTE_LIBRTE_EAL_HOTPLUG

Hi Tetsuya,

Can  #ifdef RTE_LIBRTE_EAL_HOTPLUG be removed as code is now in eal_common_pci.c ?

Regards,

Bernard.

> +/* 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->pt_driver) {
> +	case RTE_PT_VFIO:
> +		RTE_LOG(ERR, EAL, "Hotplug doesn't support vfio yet\n");
> +		break;
> +	case RTE_PT_IGB_UIO:
> +	case RTE_PT_UIO_GENERIC:
> +	case RTE_PT_NIC_UIO:
> +		/* unmap resources for devices that use uio */
> +		pci_uio_unmap_resource(dev);
> +		break;
> +	default:
> +		RTE_LOG(DEBUG, EAL, "  Not managed by known pt driver,"
> +			" skipped\n");
> +		break;
> +	}
> +}
> +#endif /* RTE_LIBRTE_EAL_HOTPLUG */

Hi Tetsuya,

Can  #endif be removed  too as code is now in eal_common_pci.c ?

Regards,

Bernard.


> +
>  /*
>   * 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 fc64601..47345b8 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_pt_driver {
>  	RTE_PT_IGB_UIO		= 1,
>  	RTE_PT_VFIO		= 2,
>  	RTE_PT_UIO_GENERIC	= 3,
> +	RTE_PT_NIC_UIO		= 4,
>  };
> 
>  /**
> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
> index dbc2548..6a8153c 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_pci.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
> @@ -565,61 +565,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->pt_driver) {
> -	case RTE_PT_VFIO:
> -#ifdef VFIO_PRESENT
> -		if (pci_vfio_is_enabled())
> -			ret = pci_vfio_map_resource(dev);
> -#endif
> -		break;
> -	case RTE_PT_IGB_UIO:
> -	case RTE_PT_UIO_GENERIC:
> -		/* map resources for devices that use uio */
> -		ret = pci_uio_map_resource(dev);
> -		break;
> -	default:
> -		RTE_LOG(DEBUG, EAL, "  Not managed by known pt 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->pt_driver) {
> -	case RTE_PT_VFIO:
> -		RTE_LOG(ERR, EAL, "Hotplug doesn't support vfio yet\n");
> -		break;
> -	case RTE_PT_IGB_UIO:
> -	case RTE_PT_UIO_GENERIC:
> -		/* unmap resources for devices that use uio */
> -		pci_uio_unmap_resource(dev);
> -		break;
> -	default:
> -		RTE_LOG(DEBUG, EAL, "  Not managed by known pt 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 03fce08..e23d7da
> 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->pt_driver) {
>  		case RTE_PT_IGB_UIO:
>  		case RTE_PT_UIO_GENERIC:
> +		case RTE_PT_NIC_UIO:
>  			break;
>  		case RTE_PT_VFIO:
>  		default:
> --
> 1.9.1

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

* Re: [dpdk-dev] [PATCH v2 13/15] eal: Consolidate pci_map/unmap_resource() of linuxapp and bsdapp
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 13/15] eal: Consolidate pci_map/unmap_resource() " Tetsuya Mukawa
@ 2015-03-13 15:23     ` Iremonger, Bernard
  0 siblings, 0 replies; 87+ messages in thread
From: Iremonger, Bernard @ 2015-03-13 15:23 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev



> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Thursday, March 12, 2015 10:18 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; Richardson, Bruce; Tetsuya Mukawa
> Subject: [PATCH v2 13/15] eal: Consolidate pci_map/unmap_resource() of linuxapp and bsdapp
> 
> 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        | 24 -----------------
>  lib/librte_eal/common/eal_common_pci.c     | 43 ++++++++++++++++++++++++++++++
>  lib/librte_eal/common/include/rte_pci.h    | 11 ++++++++
>  lib/librte_eal/linuxapp/eal/eal_pci.c      | 42 -----------------------------
>  lib/librte_eal/linuxapp/eal/eal_pci_init.h |  5 ----
>  5 files changed, 54 insertions(+), 71 deletions(-)
> 
> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
> index 1e42e42..d7d6439 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> @@ -46,7 +46,6 @@
>  #include <dirent.h>
>  #include <limits.h>
>  #include <sys/queue.h>
> -#include <sys/mman.h>
>  #include <sys/ioctl.h>
>  #include <sys/pciio.h>
>  #include <dev/pci/pcireg.h>
> @@ -96,29 +95,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 726026f..6d98194 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,48 @@ 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

Hi Tetsuya,

Can #ifdef RTE_LIBRTE_EAL_HOTPLUG be removed as code is now in eal_common_pci.c ?

Regards,

Bernard.

> +/* 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 */
Hi Tetsuya,

Can #endif  be removed too as code is now in eal_common_pci.c ?

Regards,

Bernard.

> +
>  /* 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 47345b8..d3b883e 100644
> --- a/lib/librte_eal/common/include/rte_pci.h
> +++ b/lib/librte_eal/common/include/rte_pci.h
> @@ -363,8 +363,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 6a8153c..d072e98 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,47 +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

Hi Tetsuya,

Can #ifdef RTE_LIBRTE_EAL_HOTPLUG be removed ?

Regards,

Bernard.

>  /* unmap IGB_UIO resource prototype */
>  void pci_uio_unmap_resource(struct rte_pci_device *dev);
> --
> 1.9.1

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

* Re: [dpdk-dev] [PATCH v2 15/15] eal: Enable Port Hotplug as default in Linux and BSD
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 15/15] eal: Enable Port Hotplug as default in Linux and BSD Tetsuya Mukawa
@ 2015-03-13 15:47     ` Iremonger, Bernard
  2015-03-17  8:08       ` Tetsuya Mukawa
  0 siblings, 1 reply; 87+ messages in thread
From: Iremonger, Bernard @ 2015-03-13 15:47 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev



> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Thursday, March 12, 2015 10:18 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; Richardson, Bruce; Tetsuya Mukawa
> Subject: [PATCH v2 15/15] eal: Enable Port Hotplug as default in Linux and BSD
> 
> This patch removes CONFIG_RTE_LIBRTE_EAL_HOTPLUG option, and enables it as default in both
> Linux and BSD.

Hi Tetsuya,

This patch should probably be split with the config changes as the first patch of this patch set.
The #ifdef RTE_LIBRTE_EAL_HOTPLUG changes should be no longer necessary as they will have been taken care of in the earlier patches (v2-11, v2-12, v2-13).
Maybe the  /lib/librte_eal/bsdapp/eal/rte_eal_version.map changes could be moved to one of the earlier bsd patches?

Regards,

Bernard.


> 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 8ff4dc2..88b44e9 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 97f1c9e..f9c9780 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 b6785d4..50c9544 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> @@ -305,8 +305,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;
> @@ -362,7 +362,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 6d98194..126dd01 100644
> --- a/lib/librte_eal/common/eal_common_pci.c
> +++ b/lib/librte_eal/common/eal_common_pci.c
> @@ -122,7 +122,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) @@ -139,7 +138,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
> @@ -171,7 +169,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) @@ -196,7 +193,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 @@ -275,7 +271,6 @@
> rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr,
>  	return 1;
>  }
> 
> -#ifdef RTE_LIBRTE_EAL_HOTPLUG
>  /*
>   * If vendor/device ID match, call the devuninit() function of the
>   * driver.
> @@ -334,7 +329,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 @@ -363,7 +357,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 @@ -454,7 +447,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 b9d7726..fe5dd5f 100644
> --- a/lib/librte_eal/common/eal_common_pci_uio.c
> +++ b/lib/librte_eal/common/eal_common_pci_uio.c
> @@ -154,7 +154,6 @@ fail:
>  	return -1;
>  }
> 
> -#ifdef RTE_LIBRTE_EAL_HOTPLUG
>  static void
>  pci_uio_unmap(struct mapped_pci_resource *uio_res)  { @@ -223,4 +222,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 d3b883e..b3c6a0f 100644
> --- a/lib/librte_eal/common/include/rte_pci.h
> +++ b/lib/librte_eal/common/include/rte_pci.h
> @@ -369,7 +369,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.
>   */
> @@ -404,7 +403,6 @@ int rte_eal_pci_probe_one(struct rte_pci_addr *addr);
>   *   - Negative on error.
>   */
>  int rte_eal_pci_close_one(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 e23d7da..818384a
> 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)
> --
> 1.9.1

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

* Re: [dpdk-dev] [PATCH v2 00/15] eal: Port Hotplug support for BSD
  2015-03-13 11:46   ` [dpdk-dev] [PATCH v2 00/15] eal: Port Hotplug support for BSD Iremonger, Bernard
@ 2015-03-16  3:36     ` Tetsuya Mukawa
  0 siblings, 0 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-16  3:36 UTC (permalink / raw)
  To: Iremonger, Bernard, dev

On 2015/03/13 20:46, Iremonger, Bernard wrote:
>
>> -----Original Message-----
>> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
>> Sent: Thursday, March 12, 2015 10:18 AM
>> To: dev@dpdk.org
>> Cc: Iremonger, Bernard; Richardson, Bruce; Tetsuya Mukawa
>> Subject: [PATCH v2 00/15] eal: Port Hotplug support for BSD
>>
>> This patch series adds port hotplug support to BSD.
>> Also, the patches consolidates pci uio functions of linuxapp and bsdapp.
>>
>> Following patches cleanup pci uio code to consolidate later.
>>   eal: Fix cording style of eal_pci.c and eal_pci_uio.c
>>   eal: Close file descriptor of uio configuration
>>   eal: Fix memory leak of pci_uio_map_resource()
>>   eal: Fix needless incrementation of pci_map_addr
>>   eal/bsdapp: Change names of pci related data structure
>>   eal: Use map_idx in pci_uio_map_resource() of bsdapp to work same as
>>     linuxapp
>>   eal: Fix interface of pci_map_resource() of bsdapp
>>   eal: Add pci_uio_alloc_uio_resource()
>>   eal: Add pci_uio_map_uio_resource_by_index()
>>
> Hi Tetsuya,
>
> It might be better to split this patchset into two patch sets, 
> A cleanup patchset and a consolidation patchset. 
> It would make reviewing easier.

Hi Bernard,

Yes, I will split the series, and will submit cleanup patch set first.
Also, I will do followings.

- Set Initialized cfg_fd to -1 in below patch
  [PATCH v2 02/15] eal: Close file descriptor of uio configuration
- Squashed below patches.
  [PATCH v2 03/15] eal: Fix memory leak of pci_uio_map_resource()
  [PATCH v2 04/15] eal: Fix needless incrementation of pci_map_addr
- Removed '#ifdef RTE_LIBRTE_EAL_HOTPLUG' when the functions are
consolidated. and remove the last patch.

Regards,
Tetsuya

> Regards,
>
> Bernard.
>
>
>> Following patches are actually for functions consolidation.
>>   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
>>
>> The last patch removes CONFIG_RTE_LIBRTE_EAL_HOTPLUG configuration from Linux and BSD.
>> And port hotplug is enabled as default with both Linux and BSD.
>>   eal: Enable Port Hotplug as default in Linux and BSD
>>
>>
>> PATCH v2 changes
>>  - Consolidate pci uio functions of linuxapp and bsdapp.
>>
>>
>> Tetsuya Mukawa (15):
>>   eal: Fix cording style of eal_pci.c and eal_pci_uio.c
>>   eal: Close file descriptor of uio configuration
>>   eal: Fix memory leak of pci_uio_map_resource()
>>   eal: Fix needless incrementation of pci_map_addr
>>   eal/bsdapp: Change names of pci related data structure
>>   eal: Use map_idx in pci_uio_map_resource() of bsdapp to work same as
>>     linuxapp
>>   eal: Fix interface of pci_map_resource() of bsdapp
>>   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                | 292 ++++++---------------
>>  .../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             | 234 ++++++++++++++++-
>>  lib/librte_eal/common/eal_common_pci_uio.c         | 224 ++++++++++++++++
>>  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          | 263 +++++--------------
>>  lib/librte_ether/rte_ethdev.c                      |  22 +-
>>  16 files changed, 702 insertions(+), 729 deletions(-)  create mode 100644
>> lib/librte_eal/common/eal_common_pci_uio.c
>>
>> --
>> 1.9.1

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

* Re: [dpdk-dev] [PATCH v2 15/15] eal: Enable Port Hotplug as default in Linux and BSD
  2015-03-13 15:47     ` Iremonger, Bernard
@ 2015-03-17  8:08       ` Tetsuya Mukawa
  2015-03-19 11:41         ` Iremonger, Bernard
  0 siblings, 1 reply; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-17  8:08 UTC (permalink / raw)
  To: Iremonger, Bernard, dev

On 2015/03/14 0:47, Iremonger, Bernard wrote:
>
>> -----Original Message-----
>> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
>> Sent: Thursday, March 12, 2015 10:18 AM
>> To: dev@dpdk.org
>> Cc: Iremonger, Bernard; Richardson, Bruce; Tetsuya Mukawa
>> Subject: [PATCH v2 15/15] eal: Enable Port Hotplug as default in Linux and BSD
>>
>> This patch removes CONFIG_RTE_LIBRTE_EAL_HOTPLUG option, and enables it as default in both
>> Linux and BSD.
> Hi Tetsuya,
>
> This patch should probably be split with the config changes as the first patch of this patch set.
> The #ifdef RTE_LIBRTE_EAL_HOTPLUG changes should be no longer necessary as they will have been taken care of in the earlier patches (v2-11, v2-12, v2-13).
> Maybe the  /lib/librte_eal/bsdapp/eal/rte_eal_version.map changes could be moved to one of the earlier bsd patches?

Hi Bernard,

Could I make it sure your suggestion?
Did you mean that hotplug support for linuxapp and bsdapp should be
enabled at first of consolidation patches?

It seems I can remove "#ifdef RTE_LIBRTE_EAL_HOTPLUG" together with
below patches.
 - v2-11
 - v2-12
 - v2-13
(Probably this will clean up the last patch a bit.)

But I cannot enable hotplug support at the first of consolidation
patches, because bsdapp doesn't have some hotplug implementation at the
first.
(Actually, functions related with detach() are only exist in linuxapp at
the first.)
All related functions are moved to common while patch set, then bsdapp
can support hotplug.

I will clean up the last patch as much as possible, then submit again.
Is it okay for this patch?

Regards,
Tetsuya

> Regards,
>
> Bernard.
>
>
>> 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 8ff4dc2..88b44e9 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 97f1c9e..f9c9780 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 b6785d4..50c9544 100644
>> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
>> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
>> @@ -305,8 +305,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;
>> @@ -362,7 +362,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 6d98194..126dd01 100644
>> --- a/lib/librte_eal/common/eal_common_pci.c
>> +++ b/lib/librte_eal/common/eal_common_pci.c
>> @@ -122,7 +122,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) @@ -139,7 +138,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
>> @@ -171,7 +169,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) @@ -196,7 +193,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 @@ -275,7 +271,6 @@
>> rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr,
>>  	return 1;
>>  }
>>
>> -#ifdef RTE_LIBRTE_EAL_HOTPLUG
>>  /*
>>   * If vendor/device ID match, call the devuninit() function of the
>>   * driver.
>> @@ -334,7 +329,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 @@ -363,7 +357,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 @@ -454,7 +447,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 b9d7726..fe5dd5f 100644
>> --- a/lib/librte_eal/common/eal_common_pci_uio.c
>> +++ b/lib/librte_eal/common/eal_common_pci_uio.c
>> @@ -154,7 +154,6 @@ fail:
>>  	return -1;
>>  }
>>
>> -#ifdef RTE_LIBRTE_EAL_HOTPLUG
>>  static void
>>  pci_uio_unmap(struct mapped_pci_resource *uio_res)  { @@ -223,4 +222,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 d3b883e..b3c6a0f 100644
>> --- a/lib/librte_eal/common/include/rte_pci.h
>> +++ b/lib/librte_eal/common/include/rte_pci.h
>> @@ -369,7 +369,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.
>>   */
>> @@ -404,7 +403,6 @@ int rte_eal_pci_probe_one(struct rte_pci_addr *addr);
>>   *   - Negative on error.
>>   */
>>  int rte_eal_pci_close_one(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 e23d7da..818384a
>> 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)
>> --
>> 1.9.1

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

* [dpdk-dev] [PATCH 0/6] Clean up pci uio implementations
  2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 03/15] eal: Fix memory leak of pci_uio_map_resource() Tetsuya Mukawa
  2015-03-13 14:04     ` Iremonger, Bernard
@ 2015-03-17  9:30     ` Tetsuya Mukawa
  2015-03-17  9:30       ` [dpdk-dev] [PATCH 1/6] eal: Fix cording style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
                         ` (5 more replies)
  1 sibling, 6 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-17  9:30 UTC (permalink / raw)
  To: dev

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

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

Tetsuya Mukawa (6):
  eal: Fix cording style of eal_pci.c and eal_pci_uio.c
  eal: Close file descriptor of uio configuration
  eal: Fix memory leaks and needless incrementation of pci uio
    implementation
  eal/bsdapp: Change names of pci related data structure
  eal: Use map_idx in pci_uio_map_resource() of bsdapp to work same as
    linuxapp
  eal: Fix interface of pci_map_resource()

 lib/librte_eal/bsdapp/eal/eal_pci.c       | 160 +++++++++++++++++-------------
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c |  67 +++++++------
 2 files changed, 130 insertions(+), 97 deletions(-)

-- 
1.9.1

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

* [dpdk-dev] [PATCH 1/6] eal: Fix cording style of eal_pci.c and eal_pci_uio.c
  2015-03-17  9:30     ` [dpdk-dev] [PATCH 0/6] Clean up pci uio implementations Tetsuya Mukawa
@ 2015-03-17  9:30       ` Tetsuya Mukawa
  2015-03-18 14:29         ` Bruce Richardson
  2015-03-18 15:08         ` David Marchand
  2015-03-17  9:30       ` [dpdk-dev] [PATCH 2/6] eal: Close file descriptor of uio configuration Tetsuya Mukawa
                         ` (4 subsequent siblings)
  5 siblings, 2 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-17  9:30 UTC (permalink / raw)
  To: dev

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

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

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

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

* [dpdk-dev] [PATCH 2/6] eal: Close file descriptor of uio configuration
  2015-03-17  9:30     ` [dpdk-dev] [PATCH 0/6] Clean up pci uio implementations Tetsuya Mukawa
  2015-03-17  9:30       ` [dpdk-dev] [PATCH 1/6] eal: Fix cording style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
@ 2015-03-17  9:30       ` Tetsuya Mukawa
  2015-03-18 15:19         ` David Marchand
  2015-03-19 16:04         ` Iremonger, Bernard
  2015-03-17  9:30       ` [dpdk-dev] [PATCH 3/6] eal: Fix memory leaks and needless incrementation of pci uio implementation Tetsuya Mukawa
                         ` (3 subsequent siblings)
  5 siblings, 2 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-17  9:30 UTC (permalink / raw)
  To: dev

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

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

diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 9cdf24f..b971ec9 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -459,8 +459,14 @@ pci_uio_unmap_resource(struct rte_pci_device *dev)
 
 	/* close fd if in primary process */
 	close(dev->intr_handle.fd);
-
 	dev->intr_handle.fd = -1;
+
+	/* close cfg_fd if in primary process */
+	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.type = RTE_INTR_HANDLE_UNKNOWN;
 }
 #endif /* RTE_LIBRTE_EAL_HOTPLUG */
-- 
1.9.1

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

* [dpdk-dev] [PATCH 3/6] eal: Fix memory leaks and needless incrementation of pci uio implementation
  2015-03-17  9:30     ` [dpdk-dev] [PATCH 0/6] Clean up pci uio implementations Tetsuya Mukawa
  2015-03-17  9:30       ` [dpdk-dev] [PATCH 1/6] eal: Fix cording style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
  2015-03-17  9:30       ` [dpdk-dev] [PATCH 2/6] eal: Close file descriptor of uio configuration Tetsuya Mukawa
@ 2015-03-17  9:30       ` Tetsuya Mukawa
  2015-03-18 15:39         ` David Marchand
  2015-03-19 16:20         ` Iremonger, Bernard
  2015-03-17  9:30       ` [dpdk-dev] [PATCH 4/6] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
                         ` (2 subsequent siblings)
  5 siblings, 2 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-17  9:30 UTC (permalink / raw)
  To: dev

When pci_map_resource() is failed but path is allocated correctly,
path won't be freed. Also, when open() is failed, uio_res won't be freed.
This patch fixes these memory leaks.
When pci_map_resource() is failed, mapaddr will be MAP_FAILED.
In this case, pci_map_addr should not be incremented.

Also, the patch fixes belows.
 - To shrink code, move close().
 - Remove fail variable.

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

diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index b971ec9..5044884 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -333,7 +333,6 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	maps = uio_res->maps;
 	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
 		int fd;
-		int fail = 0;
 
 		/* skip empty BAR */
 		phaddr = dev->mem_resource[i].phys_addr;
@@ -347,6 +346,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 				loc->domain, loc->bus, loc->devid, loc->function,
 				i);
 
+		/* allocate memory to keep path */
+		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
+		if (maps[map_idx].path == NULL)
+			goto fail0;
+
 		/*
 		 * open resource file, to mmap it
 		 */
@@ -354,7 +358,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 		if (fd < 0) {
 			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
 					devname, strerror(errno));
-			return -1;
+			goto fail1;
 		}
 
 		/* try mapping somewhere close to the end of hugepages */
@@ -363,23 +367,13 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 		mapaddr = pci_map_resource(pci_map_addr, fd, 0,
 				(size_t)dev->mem_resource[i].len, 0);
+		close(fd);
 		if (mapaddr == MAP_FAILED)
-			fail = 1;
+			goto fail1;
 
 		pci_map_addr = RTE_PTR_ADD(mapaddr,
 				(size_t)dev->mem_resource[i].len);
 
-		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
-		if (maps[map_idx].path == NULL)
-			fail = 1;
-
-		if (fail) {
-			rte_free(uio_res);
-			close(fd);
-			return -1;
-		}
-		close(fd);
-
 		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
 		maps[map_idx].size = dev->mem_resource[i].len;
 		maps[map_idx].addr = mapaddr;
@@ -394,6 +388,12 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
 
 	return 0;
+
+fail1:
+	rte_free(maps[map_idx].path);
+fail0:
+	rte_free(uio_res);
+	return -1;
 }
 
 #ifdef RTE_LIBRTE_EAL_HOTPLUG
-- 
1.9.1

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

* [dpdk-dev] [PATCH 4/6] eal/bsdapp: Change names of pci related data structure
  2015-03-17  9:30     ` [dpdk-dev] [PATCH 0/6] Clean up pci uio implementations Tetsuya Mukawa
                         ` (2 preceding siblings ...)
  2015-03-17  9:30       ` [dpdk-dev] [PATCH 3/6] eal: Fix memory leaks and needless incrementation of pci uio implementation Tetsuya Mukawa
@ 2015-03-17  9:30       ` Tetsuya Mukawa
  2015-03-17  9:30       ` [dpdk-dev] [PATCH 5/6] eal: Use map_idx in pci_uio_map_resource() of bsdapp to work same as linuxapp Tetsuya Mukawa
  2015-03-17  9:30       ` [dpdk-dev] [PATCH 6/6] eal: Fix interface of pci_map_resource() Tetsuya Mukawa
  5 siblings, 0 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-17  9:30 UTC (permalink / raw)
  To: dev

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

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

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

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

* [dpdk-dev] [PATCH 5/6] eal: Use map_idx in pci_uio_map_resource() of bsdapp to work same as linuxapp
  2015-03-17  9:30     ` [dpdk-dev] [PATCH 0/6] Clean up pci uio implementations Tetsuya Mukawa
                         ` (3 preceding siblings ...)
  2015-03-17  9:30       ` [dpdk-dev] [PATCH 4/6] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
@ 2015-03-17  9:30       ` Tetsuya Mukawa
  2015-03-17  9:30       ` [dpdk-dev] [PATCH 6/6] eal: Fix interface of pci_map_resource() Tetsuya Mukawa
  5 siblings, 0 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-17  9:30 UTC (permalink / raw)
  To: dev

This patch changes code that maps pci resources in bsdapp.
Linuxapp has almost same code. To consolidate both, fix implementation
of bsdapp to work same as linuxapp.

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

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 85f8671..08b91b4 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -195,7 +195,7 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 static int
 pci_uio_map_resource(struct rte_pci_device *dev)
 {
-	int i, j;
+	int i, map_idx;
 	char devname[PATH_MAX]; /* contains the /dev/uioX */
 	void *mapaddr;
 	uint64_t phaddr;
@@ -247,31 +247,31 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	pagesz = sysconf(_SC_PAGESIZE);
 
 	maps = uio_res->maps;
-	for (i = uio_res->nb_maps = 0; i != PCI_MAX_RESOURCE; i++) {
+	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
 
-		j = uio_res->nb_maps;
 		/* skip empty BAR */
 		if ((phaddr = dev->mem_resource[i].phys_addr) == 0)
 			continue;
 
 		/* if matching map is found, then use it */
 		offset = i * pagesz;
-		maps[j].offset = offset;
-		maps[j].phaddr = dev->mem_resource[i].phys_addr;
-		maps[j].size = dev->mem_resource[i].len;
-		if (maps[j].addr != NULL ||
-		    (mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
-						(size_t)maps[j].size)
-		    ) == NULL) {
+		maps[map_idx].offset = offset;
+		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
+		maps[map_idx].size = dev->mem_resource[i].len;
+		mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
+					(size_t)maps[map_idx].size);
+		if ((maps[map_idx].addr != NULL) || (mapaddr == NULL)) {
 			rte_free(uio_res);
 			return -1;
 		}
 
-		maps[j].addr = mapaddr;
-		uio_res->nb_maps++;
+		maps[map_idx].addr = mapaddr;
+		map_idx++;
 		dev->mem_resource[i].addr = mapaddr;
 	}
 
+	uio_res->nb_maps = map_idx;
+
 	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
 
 	return 0;
-- 
1.9.1

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

* [dpdk-dev] [PATCH 6/6] eal: Fix interface of pci_map_resource()
  2015-03-17  9:30     ` [dpdk-dev] [PATCH 0/6] Clean up pci uio implementations Tetsuya Mukawa
                         ` (4 preceding siblings ...)
  2015-03-17  9:30       ` [dpdk-dev] [PATCH 5/6] eal: Use map_idx in pci_uio_map_resource() of bsdapp to work same as linuxapp Tetsuya Mukawa
@ 2015-03-17  9:30       ` Tetsuya Mukawa
  2015-03-20  9:53         ` Iremonger, Bernard
                           ` (2 more replies)
  5 siblings, 3 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-17  9:30 UTC (permalink / raw)
  To: dev

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

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

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 08b91b4..21a3d79 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -100,7 +100,7 @@ struct mapped_pci_resource {
 
 	struct rte_pci_addr pci_addr;
 	char path[PATH_MAX];
-	size_t nb_maps;
+	int nb_maps;
 	struct pci_map maps[PCI_MAX_RESOURCE];
 };
 
@@ -122,47 +122,30 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)
 
 /* map a particular resource from a file */
 static void *
-pci_map_resource(void *requested_addr, const char *devname, off_t offset,
-		 size_t size)
+pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
+		 int additional_flags)
 {
-	int fd;
 	void *mapaddr;
 
-	/*
-	 * open devname, to mmap it
-	 */
-	fd = open(devname, O_RDWR);
-	if (fd < 0) {
-		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
-			devname, strerror(errno));
-		goto fail;
-	}
-
 	/* Map the PCI memory resource of device */
 	mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
-			MAP_SHARED, fd, offset);
-	close(fd);
-	if (mapaddr == MAP_FAILED ||
-			(requested_addr != NULL && mapaddr != requested_addr)) {
-		RTE_LOG(ERR, EAL, "%s(): cannot mmap(%s(%d), %p, 0x%lx, 0x%lx):"
-			" %s (%p)\n", __func__, devname, fd, requested_addr,
+			MAP_SHARED | additional_flags, fd, offset);
+	if (mapaddr == MAP_FAILED) {
+		RTE_LOG(ERR, EAL,
+			"%s(): cannot mmap(%d, %p, 0x%lx, 0x%lx): %s (%p)\n",
+			__func__, fd, requested_addr,
 			(unsigned long)size, (unsigned long)offset,
 			strerror(errno), mapaddr);
-		goto fail;
-	}
-
-	RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
+	} else
+		RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
 
 	return mapaddr;
-
-fail:
-	return NULL;
 }
 
 static int
 pci_uio_map_secondary(struct rte_pci_device *dev)
 {
-	size_t i;
+	int i, fd;
 	struct mapped_pci_resource *uio_res;
 	struct mapped_pci_res_list *uio_res_list =
 			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
@@ -170,19 +153,34 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 	TAILQ_FOREACH(uio_res, uio_res_list, next) {
 
 		/* skip this element if it doesn't match our PCI address */
-		if (memcmp(&uio_res->pci_addr, &dev->addr, sizeof(dev->addr)))
+		if (rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr))
 			continue;
 
 		for (i = 0; i != uio_res->nb_maps; i++) {
-			if (pci_map_resource(uio_res->maps[i].addr,
-					     uio_res->path,
-					     (off_t)uio_res->maps[i].offset,
-					     (size_t)uio_res->maps[i].size)
-			    != uio_res->maps[i].addr) {
+			/*
+			 * open devname, to mmap it
+			 */
+			fd = open(uio_res->maps[i].path, O_RDWR);
+			if (fd < 0) {
+				RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
+					uio_res->maps[i].path, strerror(errno));
+				return -1;
+			}
+
+			void *mapaddr = pci_map_resource(uio_res->maps[i].addr,
+					fd, (off_t)uio_res->maps[i].offset,
+					(size_t)uio_res->maps[i].size, 0);
+			if (mapaddr != uio_res->maps[i].addr) {
 				RTE_LOG(ERR, EAL,
-					"Cannot mmap device resource\n");
+						"Cannot mmap device resource "
+						"file %s to address: %p\n",
+						uio_res->maps[i].path,
+						uio_res->maps[i].addr);
+				close(fd);
 				return -1;
 			}
+			/* fd is not needed in slave process, close it */
+			close(fd);
 		}
 		return 0;
 	}
@@ -248,24 +246,43 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 	maps = uio_res->maps;
 	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
+		int fd;
 
 		/* 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 fail0;
+		}
+
+		/*
+		 * 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 fail1;
+		}
+
 		/* if matching map is found, then use it */
 		offset = i * pagesz;
-		maps[map_idx].offset = offset;
+		mapaddr = pci_map_resource(NULL, fd, (off_t)offset,
+					(size_t)dev->mem_resource[i].len, 0);
+		close(fd);
+		if (mapaddr == NULL)
+			goto fail1;
+
 		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
 		maps[map_idx].size = dev->mem_resource[i].len;
-		mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
-					(size_t)maps[map_idx].size);
-		if ((maps[map_idx].addr != NULL) || (mapaddr == NULL)) {
-			rte_free(uio_res);
-			return -1;
-		}
-
 		maps[map_idx].addr = mapaddr;
+		maps[map_idx].offset = offset;
+		strcpy(maps[map_idx].path, devname);
 		map_idx++;
 		dev->mem_resource[i].addr = mapaddr;
 	}
@@ -275,6 +292,12 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
 
 	return 0;
+
+fail1:
+	rte_free(maps[map_idx].path);
+fail0:
+	rte_free(uio_res);
+	return -1;
 }
 
 /* Scan one pci sysfs entry, and fill the devices list from it. */
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 5044884..9eeaebb 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -116,17 +116,11 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 					fd, (off_t)uio_res->maps[i].offset,
 					(size_t)uio_res->maps[i].size, 0);
 			if (mapaddr != uio_res->maps[i].addr) {
-				if (mapaddr == MAP_FAILED)
-					RTE_LOG(ERR, EAL,
-							"Cannot mmap device resource file %s: %s\n",
-							uio_res->maps[i].path,
-							strerror(errno));
-				else
-					RTE_LOG(ERR, EAL,
-							"Cannot mmap device resource file %s to address: %p\n",
-							uio_res->maps[i].path,
-							uio_res->maps[i].addr);
-
+				RTE_LOG(ERR, EAL,
+						"Cannot mmap device resource "
+						"file %s to address: %p\n",
+						uio_res->maps[i].path,
+						uio_res->maps[i].addr);
 				close(fd);
 				return -1;
 			}
@@ -348,8 +342,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 		/* allocate memory to keep path */
 		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
-		if (maps[map_idx].path == NULL)
+		if (maps[map_idx].path == NULL) {
+			RTE_LOG(ERR, EAL, "Cannot allocate memory for "
+					"path: %s\n", strerror(errno));
 			goto fail0;
+		}
 
 		/*
 		 * open resource file, to mmap it
-- 
1.9.1

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

* Re: [dpdk-dev] [PATCH 1/6] eal: Fix cording style of eal_pci.c and eal_pci_uio.c
  2015-03-17  9:30       ` [dpdk-dev] [PATCH 1/6] eal: Fix cording style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
@ 2015-03-18 14:29         ` Bruce Richardson
  2015-03-18 15:08         ` David Marchand
  1 sibling, 0 replies; 87+ messages in thread
From: Bruce Richardson @ 2015-03-18 14:29 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Tue, Mar 17, 2015 at 06:30:40PM +0900, Tetsuya Mukawa wrote:
> This patch fixes cording style of below files in linuxapp and bsdapp.
>  - eal_pci.c
>  - eal_pci_uio.c
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>

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

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

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

* Re: [dpdk-dev] [PATCH 1/6] eal: Fix cording style of eal_pci.c and eal_pci_uio.c
  2015-03-17  9:30       ` [dpdk-dev] [PATCH 1/6] eal: Fix cording style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
  2015-03-18 14:29         ` Bruce Richardson
@ 2015-03-18 15:08         ` David Marchand
  1 sibling, 0 replies; 87+ messages in thread
From: David Marchand @ 2015-03-18 15:08 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

Hello Tetsuya,

On Tue, Mar 17, 2015 at 10:30 AM, Tetsuya Mukawa <mukawa@igel.co.jp> wrote:

> This patch fixes cording style of below files in linuxapp and bsdapp.
>  - eal_pci.c
>  - eal_pci_uio.c
>
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
>

I suppose typo for "coding style" in both title and commit log.
The rest looks fine to me.

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



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

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

* Re: [dpdk-dev] [PATCH 2/6] eal: Close file descriptor of uio configuration
  2015-03-17  9:30       ` [dpdk-dev] [PATCH 2/6] eal: Close file descriptor of uio configuration Tetsuya Mukawa
@ 2015-03-18 15:19         ` David Marchand
  2015-03-20  1:53           ` Tetsuya Mukawa
  2015-03-19 16:04         ` Iremonger, Bernard
  1 sibling, 1 reply; 87+ messages in thread
From: David Marchand @ 2015-03-18 15:19 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Tue, Mar 17, 2015 at 10:30 AM, Tetsuya Mukawa <mukawa@igel.co.jp> wrote:

> When pci_uio_unmap_resource() is called, a file descriptor that is used
> for uio configuration should be closed.
>
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> index 9cdf24f..b971ec9 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> @@ -459,8 +459,14 @@ pci_uio_unmap_resource(struct rte_pci_device *dev)
>
>         /* close fd if in primary process */
>         close(dev->intr_handle.fd);
> -
>         dev->intr_handle.fd = -1;
> +
> +       /* close cfg_fd if in primary process */

+       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.type = RTE_INTR_HANDLE_UNKNOWN;
>  }
>  #endif /* RTE_LIBRTE_EAL_HOTPLUG */
>

Hum, why check for < 0 value ?
There is no such check for intr_handle.fd and I can see no reason why we
should behave differently.


-- 
David Marchand

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

* Re: [dpdk-dev] [PATCH 3/6] eal: Fix memory leaks and needless incrementation of pci uio implementation
  2015-03-17  9:30       ` [dpdk-dev] [PATCH 3/6] eal: Fix memory leaks and needless incrementation of pci uio implementation Tetsuya Mukawa
@ 2015-03-18 15:39         ` David Marchand
  2015-03-20  1:53           ` Tetsuya Mukawa
  2015-03-19 16:20         ` Iremonger, Bernard
  1 sibling, 1 reply; 87+ messages in thread
From: David Marchand @ 2015-03-18 15:39 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Tue, Mar 17, 2015 at 10:30 AM, Tetsuya Mukawa <mukawa@igel.co.jp> wrote:

> When pci_map_resource() is failed but path is allocated correctly,
> path won't be freed. Also, when open() is failed, uio_res won't be freed.
> This patch fixes these memory leaks.
> When pci_map_resource() is failed, mapaddr will be MAP_FAILED.
> In this case, pci_map_addr should not be incremented.
>
> Also, the patch fixes belows.
>  - To shrink code, move close().
>  - Remove fail variable.
>
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 28
> ++++++++++++++--------------
>  1 file changed, 14 insertions(+), 14 deletions(-)
>
> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> index b971ec9..5044884 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> @@ -333,7 +333,6 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>         maps = uio_res->maps;
>         for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
>                 int fd;
> -               int fail = 0;
>
>                 /* skip empty BAR */
>                 phaddr = dev->mem_resource[i].phys_addr;
> @@ -347,6 +346,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>                                 loc->domain, loc->bus, loc->devid,
> loc->function,
>                                 i);
>
> +               /* allocate memory to keep path */
> +               maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1,
> 0);
> +               if (maps[map_idx].path == NULL)
> +                       goto fail0;
> +
>

 [snip]

Neither fail0 nor fail1 labels seem to free previous allocations.
Did I miss something ?

[snip]

+
> +fail1:
> +       rte_free(maps[map_idx].path);
> +fail0:
> +       rte_free(uio_res);
> +       return -1;
>  }
>



-- 
David Marchand

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

* Re: [dpdk-dev] [PATCH v2 15/15] eal: Enable Port Hotplug as default in Linux and BSD
  2015-03-17  8:08       ` Tetsuya Mukawa
@ 2015-03-19 11:41         ` Iremonger, Bernard
  0 siblings, 0 replies; 87+ messages in thread
From: Iremonger, Bernard @ 2015-03-19 11:41 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev

> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Tuesday, March 17, 2015 8:08 AM
> To: Iremonger, Bernard; dev@dpdk.org
> Cc: Richardson, Bruce
> Subject: Re: [PATCH v2 15/15] eal: Enable Port Hotplug as default in Linux and BSD
> 
> On 2015/03/14 0:47, Iremonger, Bernard wrote:
> >
> >> -----Original Message-----
> >> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> >> Sent: Thursday, March 12, 2015 10:18 AM
> >> To: dev@dpdk.org
> >> Cc: Iremonger, Bernard; Richardson, Bruce; Tetsuya Mukawa
> >> Subject: [PATCH v2 15/15] eal: Enable Port Hotplug as default in
> >> Linux and BSD
> >>
> >> This patch removes CONFIG_RTE_LIBRTE_EAL_HOTPLUG option, and enables
> >> it as default in both Linux and BSD.
> > Hi Tetsuya,
> >
> > This patch should probably be split with the config changes as the first patch of this patch set.
> > The #ifdef RTE_LIBRTE_EAL_HOTPLUG changes should be no longer necessary as they will have
> been taken care of in the earlier patches (v2-11, v2-12, v2-13).
> > Maybe the  /lib/librte_eal/bsdapp/eal/rte_eal_version.map changes could be moved to one of the
> earlier bsd patches?
> 
> Hi Bernard,
> 
> Could I make it sure your suggestion?
> Did you mean that hotplug support for linuxapp and bsdapp should be enabled at first of consolidation
> patches?
> 
> It seems I can remove "#ifdef RTE_LIBRTE_EAL_HOTPLUG" together with below patches.
>  - v2-11
>  - v2-12
>  - v2-13
> (Probably this will clean up the last patch a bit.)
> 
> But I cannot enable hotplug support at the first of consolidation patches, because bsdapp doesn't
> have some hotplug implementation at the first.
> (Actually, functions related with detach() are only exist in linuxapp at the first.) All related functions
> are moved to common while patch set, then bsdapp can support hotplug.
> 
> I will clean up the last patch as much as possible, then submit again.
> Is it okay for this patch?
> 
> Regards,
> Tetsuya
> 
Hi Tetsuya,

Ok, clean up as much as possible and then submit again as v3.

Regards,

Bernard.

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

* Re: [dpdk-dev] [PATCH 2/6] eal: Close file descriptor of uio configuration
  2015-03-17  9:30       ` [dpdk-dev] [PATCH 2/6] eal: Close file descriptor of uio configuration Tetsuya Mukawa
  2015-03-18 15:19         ` David Marchand
@ 2015-03-19 16:04         ` Iremonger, Bernard
  2015-03-20  1:54           ` Tetsuya Mukawa
  1 sibling, 1 reply; 87+ messages in thread
From: Iremonger, Bernard @ 2015-03-19 16:04 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev


> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Tuesday, March 17, 2015 9:31 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; Richardson, Bruce; Tetsuya Mukawa
> Subject: [PATCH 2/6] eal: Close file descriptor of uio configuration
> 
> When pci_uio_unmap_resource() is called, a file descriptor that is used for uio configuration should be
> closed.
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> index 9cdf24f..b971ec9 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> @@ -459,8 +459,14 @@ pci_uio_unmap_resource(struct rte_pci_device *dev)
> 
>  	/* close fd if in primary process */
Hi Tetsuya,

Should there be a check for the primary process before closing both of the these files?

Regards,

Bernard.

>  	close(dev->intr_handle.fd);
> -
>  	dev->intr_handle.fd = -1;
> +
> +	/* close cfg_fd if in primary process */
> +	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.type = RTE_INTR_HANDLE_UNKNOWN;  }  #endif /*
> RTE_LIBRTE_EAL_HOTPLUG */
> --
> 1.9.1

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

* Re: [dpdk-dev] [PATCH 3/6] eal: Fix memory leaks and needless incrementation of pci uio implementation
  2015-03-17  9:30       ` [dpdk-dev] [PATCH 3/6] eal: Fix memory leaks and needless incrementation of pci uio implementation Tetsuya Mukawa
  2015-03-18 15:39         ` David Marchand
@ 2015-03-19 16:20         ` Iremonger, Bernard
  2015-03-20  1:54           ` Tetsuya Mukawa
  1 sibling, 1 reply; 87+ messages in thread
From: Iremonger, Bernard @ 2015-03-19 16:20 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev



> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Tuesday, March 17, 2015 9:31 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; Richardson, Bruce; Tetsuya Mukawa
> Subject: [PATCH 3/6] eal: Fix memory leaks and needless incrementation of pci uio implementation

Hi Tetsuya,

It would be better to reword "needless incrementation of pci uio implementation" to "needless increment of pci_map_addr" in commit line.

> 
> When pci_map_resource() is failed but path is allocated correctly, path won't be freed. Also, when
> open() is failed, uio_res won't be freed.
> This patch fixes these memory leaks.
> When pci_map_resource() is failed, mapaddr will be MAP_FAILED.
> In this case, pci_map_addr should not be incremented.
> 
> Also, the patch fixes belows.

Typo "belows" should be "below".

Regards,

Bernard.

>  - To shrink code, move close().
>  - Remove fail variable.
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 28 ++++++++++++++--------------
>  1 file changed, 14 insertions(+), 14 deletions(-)
> 
> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> index b971ec9..5044884 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> @@ -333,7 +333,6 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  	maps = uio_res->maps;
>  	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
>  		int fd;
> -		int fail = 0;
> 
>  		/* skip empty BAR */
>  		phaddr = dev->mem_resource[i].phys_addr; @@ -347,6 +346,11 @@
> pci_uio_map_resource(struct rte_pci_device *dev)
>  				loc->domain, loc->bus, loc->devid, loc->function,
>  				i);
> 
> +		/* allocate memory to keep path */
> +		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
> +		if (maps[map_idx].path == NULL)
> +			goto fail0;
> +
>  		/*
>  		 * open resource file, to mmap it
>  		 */
> @@ -354,7 +358,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  		if (fd < 0) {
>  			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
>  					devname, strerror(errno));
> -			return -1;
> +			goto fail1;
>  		}
> 
>  		/* try mapping somewhere close to the end of hugepages */ @@ -363,23 +367,13 @@
> pci_uio_map_resource(struct rte_pci_device *dev)
> 
>  		mapaddr = pci_map_resource(pci_map_addr, fd, 0,
>  				(size_t)dev->mem_resource[i].len, 0);
> +		close(fd);
>  		if (mapaddr == MAP_FAILED)
> -			fail = 1;
> +			goto fail1;
> 
>  		pci_map_addr = RTE_PTR_ADD(mapaddr,
>  				(size_t)dev->mem_resource[i].len);
> 
> -		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
> -		if (maps[map_idx].path == NULL)
> -			fail = 1;
> -
> -		if (fail) {
> -			rte_free(uio_res);
> -			close(fd);
> -			return -1;
> -		}
> -		close(fd);
> -
>  		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
>  		maps[map_idx].size = dev->mem_resource[i].len;
>  		maps[map_idx].addr = mapaddr;
> @@ -394,6 +388,12 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
> 
>  	return 0;
> +
> +fail1:
> +	rte_free(maps[map_idx].path);
> +fail0:
> +	rte_free(uio_res);
> +	return -1;
>  }
> 
>  #ifdef RTE_LIBRTE_EAL_HOTPLUG
> --
> 1.9.1

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

* Re: [dpdk-dev] [PATCH 2/6] eal: Close file descriptor of uio configuration
  2015-03-18 15:19         ` David Marchand
@ 2015-03-20  1:53           ` Tetsuya Mukawa
  0 siblings, 0 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-20  1:53 UTC (permalink / raw)
  To: David Marchand; +Cc: dev

On 2015/03/19 0:19, David Marchand wrote:
> On Tue, Mar 17, 2015 at 10:30 AM, Tetsuya Mukawa <mukawa@igel.co.jp
> <mailto:mukawa@igel.co.jp>> wrote:
>
>     When pci_uio_unmap_resource() is called, a file descriptor that is
>     used
>     for uio configuration should be closed.
>
>     Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp
>     <mailto:mukawa@igel.co.jp>>
>     ---
>      lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 8 +++++++-
>      1 file changed, 7 insertions(+), 1 deletion(-)
>
>     diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>     b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>     index 9cdf24f..b971ec9 100644
>     --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>     +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>     @@ -459,8 +459,14 @@ pci_uio_unmap_resource(struct rte_pci_device
>     *dev)
>
>             /* close fd if in primary process */
>             close(dev->intr_handle.fd);
>     -
>             dev->intr_handle.fd = -1;
>     +
>     +       /* close cfg_fd if in primary process */
>
>     +       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.type = RTE_INTR_HANDLE_UNKNOWN;
>      }
>      #endif /* RTE_LIBRTE_EAL_HOTPLUG */
>
>
> Hum, why check for < 0 value ?
> There is no such check for intr_handle.fd and I can see no reason why
> we should behave differently.
>

Hi David,

There is a reason, but 'if-condition' should move to later patch.

When we move this function to eal common, bsdapp will not use cfg_fd at all.
(Nic uio of BSD will not use this file descriptor.)
So I added the 'if-condition' like above.
But, I will move this fixing in later patch that actually consolidate
this function.

Thanks,
Tetsuya


>
> -- 
> David Marchand

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

* Re: [dpdk-dev] [PATCH 3/6] eal: Fix memory leaks and needless incrementation of pci uio implementation
  2015-03-18 15:39         ` David Marchand
@ 2015-03-20  1:53           ` Tetsuya Mukawa
  0 siblings, 0 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-20  1:53 UTC (permalink / raw)
  To: David Marchand; +Cc: dev

On 2015/03/19 0:39, David Marchand wrote:
> On Tue, Mar 17, 2015 at 10:30 AM, Tetsuya Mukawa <mukawa@igel.co.jp
> <mailto:mukawa@igel.co.jp>> wrote:
>
>     When pci_map_resource() is failed but path is allocated correctly,
>     path won't be freed. Also, when open() is failed, uio_res won't be
>     freed.
>     This patch fixes these memory leaks.
>     When pci_map_resource() is failed, mapaddr will be MAP_FAILED.
>     In this case, pci_map_addr should not be incremented.
>
>     Also, the patch fixes belows.
>      - To shrink code, move close().
>      - Remove fail variable.
>
>     Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp
>     <mailto:mukawa@igel.co.jp>>
>     ---
>      lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 28
>     ++++++++++++++--------------
>      1 file changed, 14 insertions(+), 14 deletions(-)
>
>     diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>     b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>     index b971ec9..5044884 100644
>     --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>     +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>     @@ -333,7 +333,6 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>             maps = uio_res->maps;
>             for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
>                     int fd;
>     -               int fail = 0;
>
>                     /* skip empty BAR */
>                     phaddr = dev->mem_resource[i].phys_addr;
>     @@ -347,6 +346,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>                                     loc->domain, loc->bus, loc->devid,
>     loc->function,
>                                     i);
>
>     +               /* allocate memory to keep path */
>     +               maps[map_idx].path = rte_malloc(NULL,
>     strlen(devname) + 1, 0);
>     +               if (maps[map_idx].path == NULL)
>     +                       goto fail0;
>     +
>
>
>  [snip]
>
> Neither fail0 nor fail1 labels seem to free previous allocations.
> Did I miss something ?

Hi David,


Ah, you are right. I will free all 'maps[i].path' allocated in this
function.

Thanks,
Tetsuya


>
> [snip]
>
>     +
>     +fail1:
>     +       rte_free(maps[map_idx].path);
>     +fail0:
>     +       rte_free(uio_res);
>     +       return -1;
>      }
>
>
>  
>
> -- 
> David Marchand

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

* Re: [dpdk-dev] [PATCH 2/6] eal: Close file descriptor of uio configuration
  2015-03-19 16:04         ` Iremonger, Bernard
@ 2015-03-20  1:54           ` Tetsuya Mukawa
  0 siblings, 0 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-20  1:54 UTC (permalink / raw)
  To: Iremonger, Bernard, dev

On 2015/03/20 1:04, Iremonger, Bernard wrote:
>> -----Original Message-----
>> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
>> Sent: Tuesday, March 17, 2015 9:31 AM
>> To: dev@dpdk.org
>> Cc: Iremonger, Bernard; Richardson, Bruce; Tetsuya Mukawa
>> Subject: [PATCH 2/6] eal: Close file descriptor of uio configuration
>>
>> When pci_uio_unmap_resource() is called, a file descriptor that is used for uio configuration should be
>> closed.
>>
>> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
>> ---
>>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 8 +++++++-
>>  1 file changed, 7 insertions(+), 1 deletion(-)
>>
>> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>> index 9cdf24f..b971ec9 100644
>> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>> @@ -459,8 +459,14 @@ pci_uio_unmap_resource(struct rte_pci_device *dev)
>>
>>  	/* close fd if in primary process */
> Hi Tetsuya,
>
> Should there be a check for the primary process before closing both of the these files?

Hi Bernard,

Yes, the check is done like below.
(But it doesn't appear in this patch.)

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

        (snip)

        /* close fd if in primary process */
        close(dev->intr_handle.fd);
        dev->intr_handle.fd = -1;

        (snip)
}

Regards,
Tetsuya

> Regards,
>
> Bernard.
>
>>  	close(dev->intr_handle.fd);
>> -
>>  	dev->intr_handle.fd = -1;
>> +
>> +	/* close cfg_fd if in primary process */
>> +	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.type = RTE_INTR_HANDLE_UNKNOWN;  }  #endif /*
>> RTE_LIBRTE_EAL_HOTPLUG */
>> --
>> 1.9.1

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

* Re: [dpdk-dev] [PATCH 3/6] eal: Fix memory leaks and needless incrementation of pci uio implementation
  2015-03-19 16:20         ` Iremonger, Bernard
@ 2015-03-20  1:54           ` Tetsuya Mukawa
  0 siblings, 0 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-20  1:54 UTC (permalink / raw)
  To: Iremonger, Bernard, dev

On 2015/03/20 1:20, Iremonger, Bernard wrote:
>
>> -----Original Message-----
>> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
>> Sent: Tuesday, March 17, 2015 9:31 AM
>> To: dev@dpdk.org
>> Cc: Iremonger, Bernard; Richardson, Bruce; Tetsuya Mukawa
>> Subject: [PATCH 3/6] eal: Fix memory leaks and needless incrementation of pci uio implementation
> Hi Tetsuya,
>
> It would be better to reword "needless incrementation of pci uio implementation" to "needless increment of pci_map_addr" in commit line.
>
>> When pci_map_resource() is failed but path is allocated correctly, path won't be freed. Also, when
>> open() is failed, uio_res won't be freed.
>> This patch fixes these memory leaks.
>> When pci_map_resource() is failed, mapaddr will be MAP_FAILED.
>> In this case, pci_map_addr should not be incremented.
>>
>> Also, the patch fixes belows.
> Typo "belows" should be "below".

Hi Bernard,

I appreciate for your checking. I will fix it.

Regards,
Tetsuya

> Regards,
>
> Bernard.
>
>>  - To shrink code, move close().
>>  - Remove fail variable.
>>
>> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
>> ---
>>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 28 ++++++++++++++--------------
>>  1 file changed, 14 insertions(+), 14 deletions(-)
>>
>> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>> index b971ec9..5044884 100644
>> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>> @@ -333,7 +333,6 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>>  	maps = uio_res->maps;
>>  	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
>>  		int fd;
>> -		int fail = 0;
>>
>>  		/* skip empty BAR */
>>  		phaddr = dev->mem_resource[i].phys_addr; @@ -347,6 +346,11 @@
>> pci_uio_map_resource(struct rte_pci_device *dev)
>>  				loc->domain, loc->bus, loc->devid, loc->function,
>>  				i);
>>
>> +		/* allocate memory to keep path */
>> +		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
>> +		if (maps[map_idx].path == NULL)
>> +			goto fail0;
>> +
>>  		/*
>>  		 * open resource file, to mmap it
>>  		 */
>> @@ -354,7 +358,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>>  		if (fd < 0) {
>>  			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
>>  					devname, strerror(errno));
>> -			return -1;
>> +			goto fail1;
>>  		}
>>
>>  		/* try mapping somewhere close to the end of hugepages */ @@ -363,23 +367,13 @@
>> pci_uio_map_resource(struct rte_pci_device *dev)
>>
>>  		mapaddr = pci_map_resource(pci_map_addr, fd, 0,
>>  				(size_t)dev->mem_resource[i].len, 0);
>> +		close(fd);
>>  		if (mapaddr == MAP_FAILED)
>> -			fail = 1;
>> +			goto fail1;
>>
>>  		pci_map_addr = RTE_PTR_ADD(mapaddr,
>>  				(size_t)dev->mem_resource[i].len);
>>
>> -		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
>> -		if (maps[map_idx].path == NULL)
>> -			fail = 1;
>> -
>> -		if (fail) {
>> -			rte_free(uio_res);
>> -			close(fd);
>> -			return -1;
>> -		}
>> -		close(fd);
>> -
>>  		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
>>  		maps[map_idx].size = dev->mem_resource[i].len;
>>  		maps[map_idx].addr = mapaddr;
>> @@ -394,6 +388,12 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>>  	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
>>
>>  	return 0;
>> +
>> +fail1:
>> +	rte_free(maps[map_idx].path);
>> +fail0:
>> +	rte_free(uio_res);
>> +	return -1;
>>  }
>>
>>  #ifdef RTE_LIBRTE_EAL_HOTPLUG
>> --
>> 1.9.1

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

* Re: [dpdk-dev] [PATCH 6/6] eal: Fix interface of pci_map_resource()
  2015-03-17  9:30       ` [dpdk-dev] [PATCH 6/6] eal: Fix interface of pci_map_resource() Tetsuya Mukawa
@ 2015-03-20  9:53         ` Iremonger, Bernard
  2015-03-24  4:18           ` Tetsuya Mukawa
  2015-03-24  4:18         ` [dpdk-dev] [PATCH v2 0/6] Clean up pci uio implementations Tetsuya Mukawa
  2015-03-27  8:39         ` [dpdk-dev] [PATCH v3 0/5] Clean up pci uio implementations Tetsuya Mukawa
  2 siblings, 1 reply; 87+ messages in thread
From: Iremonger, Bernard @ 2015-03-20  9:53 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev

> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Tuesday, March 17, 2015 9:31 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; Richardson, Bruce; Tetsuya Mukawa
> Subject: [PATCH 6/6] eal: Fix interface of pci_map_resource()
> 
> The function is implemented in both linuxapp and bsdapp, but interface is different. The patch fixes
> the function of bsdapp to do same as linuxapp. After applying it, file descriptor should be opened and
> closed out of pci_map_resource().
> Also, remove redundant error messages from linuxapp.
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  lib/librte_eal/bsdapp/eal/eal_pci.c       | 109 ++++++++++++++++++------------
>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c |  21 +++---
>  2 files changed, 75 insertions(+), 55 deletions(-)
> 
> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
> index 08b91b4..21a3d79 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> @@ -100,7 +100,7 @@ struct mapped_pci_resource {
> 
>  	struct rte_pci_addr pci_addr;
>  	char path[PATH_MAX];
> -	size_t nb_maps;
> +	int nb_maps;
>  	struct pci_map maps[PCI_MAX_RESOURCE];  };
> 
> @@ -122,47 +122,30 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)
> 
>  /* map a particular resource from a file */  static void * -pci_map_resource(void *requested_addr,
> const char *devname, off_t offset,
> -		 size_t size)
> +pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
> +		 int additional_flags)
>  {
> -	int fd;
>  	void *mapaddr;
> 
> -	/*
> -	 * open devname, to mmap it
> -	 */
> -	fd = open(devname, O_RDWR);
> -	if (fd < 0) {
> -		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
> -			devname, strerror(errno));
> -		goto fail;
> -	}
> -
>  	/* Map the PCI memory resource of device */
>  	mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
> -			MAP_SHARED, fd, offset);
> -	close(fd);
> -	if (mapaddr == MAP_FAILED ||
> -			(requested_addr != NULL && mapaddr != requested_addr)) {
> -		RTE_LOG(ERR, EAL, "%s(): cannot mmap(%s(%d), %p, 0x%lx, 0x%lx):"
> -			" %s (%p)\n", __func__, devname, fd, requested_addr,
> +			MAP_SHARED | additional_flags, fd, offset);
> +	if (mapaddr == MAP_FAILED) {
> +		RTE_LOG(ERR, EAL,
> +			"%s(): cannot mmap(%d, %p, 0x%lx, 0x%lx): %s (%p)\n",
> +			__func__, fd, requested_addr,
>  			(unsigned long)size, (unsigned long)offset,
>  			strerror(errno), mapaddr);
> -		goto fail;

Hi Tetsuya,

Previously pci_map_resource() returned NULL  when MAP_FAILED occurred.
It now returns MAP_FAILED.
Where pci_map_resource() is called it should now check for MAP_FAILED instead of NULL, or else the return value of NULL should be restored.
There is another comment below.


> -	}
> -
> -	RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
> +	} else
> +		RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
> 
>  	return mapaddr;
> -
> -fail:
> -	return NULL;
>  }
> 
>  static int
>  pci_uio_map_secondary(struct rte_pci_device *dev)  {
> -	size_t i;
> +	int i, fd;
>  	struct mapped_pci_resource *uio_res;
>  	struct mapped_pci_res_list *uio_res_list =
>  			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list); @@ -170,19
> +153,34 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
>  	TAILQ_FOREACH(uio_res, uio_res_list, next) {
> 
>  		/* skip this element if it doesn't match our PCI address */
> -		if (memcmp(&uio_res->pci_addr, &dev->addr, sizeof(dev->addr)))
> +		if (rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr))
>  			continue;
> 
>  		for (i = 0; i != uio_res->nb_maps; i++) {
> -			if (pci_map_resource(uio_res->maps[i].addr,
> -					     uio_res->path,
> -					     (off_t)uio_res->maps[i].offset,
> -					     (size_t)uio_res->maps[i].size)
> -			    != uio_res->maps[i].addr) {
> +			/*
> +			 * open devname, to mmap it
> +			 */
> +			fd = open(uio_res->maps[i].path, O_RDWR);
> +			if (fd < 0) {
> +				RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
> +					uio_res->maps[i].path, strerror(errno));
> +				return -1;
> +			}
> +
> +			void *mapaddr = pci_map_resource(uio_res->maps[i].addr,
> +					fd, (off_t)uio_res->maps[i].offset,
> +					(size_t)uio_res->maps[i].size, 0);
> +			if (mapaddr != uio_res->maps[i].addr) {
>  				RTE_LOG(ERR, EAL,
> -					"Cannot mmap device resource\n");
> +						"Cannot mmap device resource "
> +						"file %s to address: %p\n",
> +						uio_res->maps[i].path,
> +						uio_res->maps[i].addr);
> +				close(fd);
>  				return -1;
>  			}
> +			/* fd is not needed in slave process, close it */
> +			close(fd);
>  		}
>  		return 0;
>  	}
> @@ -248,24 +246,43 @@ pci_uio_map_resource(struct rte_pci_device *dev)
> 
>  	maps = uio_res->maps;
>  	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
> +		int fd;
> 
>  		/* 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 fail0;
> +		}
> +
> +		/*
> +		 * 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 fail1;
> +		}
> +
>  		/* if matching map is found, then use it */
>  		offset = i * pagesz;
> -		maps[map_idx].offset = offset;
> +		mapaddr = pci_map_resource(NULL, fd, (off_t)offset,
> +					(size_t)dev->mem_resource[i].len, 0);
> +		close(fd);
> +		if (mapaddr == NULL)

The check here should be for MAP_FAILED instead of NULL.

Regards,
Bernard.


> +			goto fail1;
> +
>  		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
>  		maps[map_idx].size = dev->mem_resource[i].len;
> -		mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
> -					(size_t)maps[map_idx].size);
> -		if ((maps[map_idx].addr != NULL) || (mapaddr == NULL)) {
> -			rte_free(uio_res);
> -			return -1;
> -		}
> -
>  		maps[map_idx].addr = mapaddr;
> +		maps[map_idx].offset = offset;
> +		strcpy(maps[map_idx].path, devname);
>  		map_idx++;
>  		dev->mem_resource[i].addr = mapaddr;
>  	}
> @@ -275,6 +292,12 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
> 
>  	return 0;
> +
> +fail1:
> +	rte_free(maps[map_idx].path);
> +fail0:
> +	rte_free(uio_res);
> +	return -1;
>  }
> 
>  /* Scan one pci sysfs entry, and fill the devices list from it. */ diff --git
> a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> index 5044884..9eeaebb 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> @@ -116,17 +116,11 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
>  					fd, (off_t)uio_res->maps[i].offset,
>  					(size_t)uio_res->maps[i].size, 0);
>  			if (mapaddr != uio_res->maps[i].addr) {
> -				if (mapaddr == MAP_FAILED)
> -					RTE_LOG(ERR, EAL,
> -							"Cannot mmap device resource file %s: %s\n",
> -							uio_res->maps[i].path,
> -							strerror(errno));
> -				else
> -					RTE_LOG(ERR, EAL,
> -							"Cannot mmap device resource file %s to
> address: %p\n",
> -							uio_res->maps[i].path,
> -							uio_res->maps[i].addr);
> -
> +				RTE_LOG(ERR, EAL,
> +						"Cannot mmap device resource "
> +						"file %s to address: %p\n",
> +						uio_res->maps[i].path,
> +						uio_res->maps[i].addr);
>  				close(fd);
>  				return -1;
>  			}
> @@ -348,8 +342,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
> 
>  		/* allocate memory to keep path */
>  		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
> -		if (maps[map_idx].path == NULL)
> +		if (maps[map_idx].path == NULL) {
> +			RTE_LOG(ERR, EAL, "Cannot allocate memory for "
> +					"path: %s\n", strerror(errno));
>  			goto fail0;
> +		}
> 
>  		/*
>  		 * open resource file, to mmap it
> --
> 1.9.1

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

* Re: [dpdk-dev] [PATCH 6/6] eal: Fix interface of pci_map_resource()
  2015-03-20  9:53         ` Iremonger, Bernard
@ 2015-03-24  4:18           ` Tetsuya Mukawa
  0 siblings, 0 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-24  4:18 UTC (permalink / raw)
  To: Iremonger, Bernard, dev

On 2015/03/20 18:53, Iremonger, Bernard wrote:
>> -----Original Message-----
>> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
>> Sent: Tuesday, March 17, 2015 9:31 AM
>> To: dev@dpdk.org
>> Cc: Iremonger, Bernard; Richardson, Bruce; Tetsuya Mukawa
>> Subject: [PATCH 6/6] eal: Fix interface of pci_map_resource()
>>
>> The function is implemented in both linuxapp and bsdapp, but interface is different. The patch fixes
>> the function of bsdapp to do same as linuxapp. After applying it, file descriptor should be opened and
>> closed out of pci_map_resource().
>> Also, remove redundant error messages from linuxapp.
>>
>> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
>> ---
>>  lib/librte_eal/bsdapp/eal/eal_pci.c       | 109 ++++++++++++++++++------------
>>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c |  21 +++---
>>  2 files changed, 75 insertions(+), 55 deletions(-)
>>
>> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
>> index 08b91b4..21a3d79 100644
>> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
>> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
>> @@ -100,7 +100,7 @@ struct mapped_pci_resource {
>>
>>  	struct rte_pci_addr pci_addr;
>>  	char path[PATH_MAX];
>> -	size_t nb_maps;
>> +	int nb_maps;
>>  	struct pci_map maps[PCI_MAX_RESOURCE];  };
>>
>> @@ -122,47 +122,30 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)
>>
>>  /* map a particular resource from a file */  static void * -pci_map_resource(void *requested_addr,
>> const char *devname, off_t offset,
>> -		 size_t size)
>> +pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
>> +		 int additional_flags)
>>  {
>> -	int fd;
>>  	void *mapaddr;
>>
>> -	/*
>> -	 * open devname, to mmap it
>> -	 */
>> -	fd = open(devname, O_RDWR);
>> -	if (fd < 0) {
>> -		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
>> -			devname, strerror(errno));
>> -		goto fail;
>> -	}
>> -
>>  	/* Map the PCI memory resource of device */
>>  	mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
>> -			MAP_SHARED, fd, offset);
>> -	close(fd);
>> -	if (mapaddr == MAP_FAILED ||
>> -			(requested_addr != NULL && mapaddr != requested_addr)) {
>> -		RTE_LOG(ERR, EAL, "%s(): cannot mmap(%s(%d), %p, 0x%lx, 0x%lx):"
>> -			" %s (%p)\n", __func__, devname, fd, requested_addr,
>> +			MAP_SHARED | additional_flags, fd, offset);
>> +	if (mapaddr == MAP_FAILED) {
>> +		RTE_LOG(ERR, EAL,
>> +			"%s(): cannot mmap(%d, %p, 0x%lx, 0x%lx): %s (%p)\n",
>> +			__func__, fd, requested_addr,
>>  			(unsigned long)size, (unsigned long)offset,
>>  			strerror(errno), mapaddr);
>> -		goto fail;
> Hi Tetsuya,
>
> Previously pci_map_resource() returned NULL  when MAP_FAILED occurred.
> It now returns MAP_FAILED.
> Where pci_map_resource() is called it should now check for MAP_FAILED instead of NULL, or else the return value of NULL should be restored.
> There is another comment below.

Hi Bernard,

I appreciate for your comment.
Yes it should be. I will fix it.

Regards,
Tetsuya

>
>
>> -	}
>> -
>> -	RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
>> +	} else
>> +		RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
>>
>>  	return mapaddr;
>> -
>> -fail:
>> -	return NULL;
>>  }
>>
>>  static int
>>  pci_uio_map_secondary(struct rte_pci_device *dev)  {
>> -	size_t i;
>> +	int i, fd;
>>  	struct mapped_pci_resource *uio_res;
>>  	struct mapped_pci_res_list *uio_res_list =
>>  			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list); @@ -170,19
>> +153,34 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
>>  	TAILQ_FOREACH(uio_res, uio_res_list, next) {
>>
>>  		/* skip this element if it doesn't match our PCI address */
>> -		if (memcmp(&uio_res->pci_addr, &dev->addr, sizeof(dev->addr)))
>> +		if (rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr))
>>  			continue;
>>
>>  		for (i = 0; i != uio_res->nb_maps; i++) {
>> -			if (pci_map_resource(uio_res->maps[i].addr,
>> -					     uio_res->path,
>> -					     (off_t)uio_res->maps[i].offset,
>> -					     (size_t)uio_res->maps[i].size)
>> -			    != uio_res->maps[i].addr) {
>> +			/*
>> +			 * open devname, to mmap it
>> +			 */
>> +			fd = open(uio_res->maps[i].path, O_RDWR);
>> +			if (fd < 0) {
>> +				RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
>> +					uio_res->maps[i].path, strerror(errno));
>> +				return -1;
>> +			}
>> +
>> +			void *mapaddr = pci_map_resource(uio_res->maps[i].addr,
>> +					fd, (off_t)uio_res->maps[i].offset,
>> +					(size_t)uio_res->maps[i].size, 0);
>> +			if (mapaddr != uio_res->maps[i].addr) {
>>  				RTE_LOG(ERR, EAL,
>> -					"Cannot mmap device resource\n");
>> +						"Cannot mmap device resource "
>> +						"file %s to address: %p\n",
>> +						uio_res->maps[i].path,
>> +						uio_res->maps[i].addr);
>> +				close(fd);
>>  				return -1;
>>  			}
>> +			/* fd is not needed in slave process, close it */
>> +			close(fd);
>>  		}
>>  		return 0;
>>  	}
>> @@ -248,24 +246,43 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>>
>>  	maps = uio_res->maps;
>>  	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
>> +		int fd;
>>
>>  		/* 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 fail0;
>> +		}
>> +
>> +		/*
>> +		 * 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 fail1;
>> +		}
>> +
>>  		/* if matching map is found, then use it */
>>  		offset = i * pagesz;
>> -		maps[map_idx].offset = offset;
>> +		mapaddr = pci_map_resource(NULL, fd, (off_t)offset,
>> +					(size_t)dev->mem_resource[i].len, 0);
>> +		close(fd);
>> +		if (mapaddr == NULL)
> The check here should be for MAP_FAILED instead of NULL.
>
> Regards,
> Bernard.
>
>
>> +			goto fail1;
>> +
>>  		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
>>  		maps[map_idx].size = dev->mem_resource[i].len;
>> -		mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
>> -					(size_t)maps[map_idx].size);
>> -		if ((maps[map_idx].addr != NULL) || (mapaddr == NULL)) {
>> -			rte_free(uio_res);
>> -			return -1;
>> -		}
>> -
>>  		maps[map_idx].addr = mapaddr;
>> +		maps[map_idx].offset = offset;
>> +		strcpy(maps[map_idx].path, devname);
>>  		map_idx++;
>>  		dev->mem_resource[i].addr = mapaddr;
>>  	}
>> @@ -275,6 +292,12 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>>  	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
>>
>>  	return 0;
>> +
>> +fail1:
>> +	rte_free(maps[map_idx].path);
>> +fail0:
>> +	rte_free(uio_res);
>> +	return -1;
>>  }
>>
>>  /* Scan one pci sysfs entry, and fill the devices list from it. */ diff --git
>> a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>> index 5044884..9eeaebb 100644
>> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>> @@ -116,17 +116,11 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
>>  					fd, (off_t)uio_res->maps[i].offset,
>>  					(size_t)uio_res->maps[i].size, 0);
>>  			if (mapaddr != uio_res->maps[i].addr) {
>> -				if (mapaddr == MAP_FAILED)
>> -					RTE_LOG(ERR, EAL,
>> -							"Cannot mmap device resource file %s: %s\n",
>> -							uio_res->maps[i].path,
>> -							strerror(errno));
>> -				else
>> -					RTE_LOG(ERR, EAL,
>> -							"Cannot mmap device resource file %s to
>> address: %p\n",
>> -							uio_res->maps[i].path,
>> -							uio_res->maps[i].addr);
>> -
>> +				RTE_LOG(ERR, EAL,
>> +						"Cannot mmap device resource "
>> +						"file %s to address: %p\n",
>> +						uio_res->maps[i].path,
>> +						uio_res->maps[i].addr);
>>  				close(fd);
>>  				return -1;
>>  			}
>> @@ -348,8 +342,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>>
>>  		/* allocate memory to keep path */
>>  		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
>> -		if (maps[map_idx].path == NULL)
>> +		if (maps[map_idx].path == NULL) {
>> +			RTE_LOG(ERR, EAL, "Cannot allocate memory for "
>> +					"path: %s\n", strerror(errno));
>>  			goto fail0;
>> +		}
>>
>>  		/*
>>  		 * open resource file, to mmap it
>> --
>> 1.9.1

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

* [dpdk-dev] [PATCH v2 0/6] Clean up pci uio implementations
  2015-03-17  9:30       ` [dpdk-dev] [PATCH 6/6] eal: Fix interface of pci_map_resource() Tetsuya Mukawa
  2015-03-20  9:53         ` Iremonger, Bernard
@ 2015-03-24  4:18         ` Tetsuya Mukawa
  2015-03-24  4:18           ` [dpdk-dev] [PATCH v2 1/6] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
                             ` (5 more replies)
  2015-03-27  8:39         ` [dpdk-dev] [PATCH v3 0/5] Clean up pci uio implementations Tetsuya Mukawa
  2 siblings, 6 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-24  4:18 UTC (permalink / raw)
  To: dev

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

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

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


Tetsuya Mukawa (6):
  eal: Fix coding style of eal_pci.c and eal_pci_uio.c
  eal: Close file descriptor of uio configuration
  eal: Fix memory leaks and needless increment of pci_map_addr
  eal/bsdapp: Change names of pci related data structure
  eal: Use map_idx in pci_uio_map_resource() of bsdapp to work same as
    linuxapp
  eal: Fix interface of pci_map_resource()

 lib/librte_eal/bsdapp/eal/eal_pci.c       | 162 ++++++++++++++++++------------
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c |  72 +++++++------
 2 files changed, 136 insertions(+), 98 deletions(-)

-- 
1.9.1

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

* [dpdk-dev] [PATCH v2 1/6] eal: Fix coding style of eal_pci.c and eal_pci_uio.c
  2015-03-24  4:18         ` [dpdk-dev] [PATCH v2 0/6] Clean up pci uio implementations Tetsuya Mukawa
@ 2015-03-24  4:18           ` Tetsuya Mukawa
  2015-03-24  4:18           ` [dpdk-dev] [PATCH v2 2/6] eal: Close file descriptor of uio configuration Tetsuya Mukawa
                             ` (4 subsequent siblings)
  5 siblings, 0 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-24  4:18 UTC (permalink / raw)
  To: dev

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

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

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

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

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

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

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

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

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

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

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

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

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

diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index f0277be..0128cec 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -333,7 +333,6 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	maps = uio_res->maps;
 	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
 		int fd;
-		int fail = 0;
 
 		/* skip empty BAR */
 		phaddr = dev->mem_resource[i].phys_addr;
@@ -347,6 +346,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 				loc->domain, loc->bus, loc->devid, loc->function,
 				i);
 
+		/* allocate memory to keep path */
+		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
+		if (maps[map_idx].path == NULL)
+			goto fail0;
+
 		/*
 		 * open resource file, to mmap it
 		 */
@@ -354,7 +358,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 		if (fd < 0) {
 			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
 					devname, strerror(errno));
-			return -1;
+			goto fail1;
 		}
 
 		/* try mapping somewhere close to the end of hugepages */
@@ -363,23 +367,13 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 		mapaddr = pci_map_resource(pci_map_addr, fd, 0,
 				(size_t)dev->mem_resource[i].len, 0);
+		close(fd);
 		if (mapaddr == MAP_FAILED)
-			fail = 1;
+			goto fail1;
 
 		pci_map_addr = RTE_PTR_ADD(mapaddr,
 				(size_t)dev->mem_resource[i].len);
 
-		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
-		if (maps[map_idx].path == NULL)
-			fail = 1;
-
-		if (fail) {
-			rte_free(uio_res);
-			close(fd);
-			return -1;
-		}
-		close(fd);
-
 		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
 		maps[map_idx].size = dev->mem_resource[i].len;
 		maps[map_idx].addr = mapaddr;
@@ -394,6 +388,15 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
 
 	return 0;
+
+fail1:
+	rte_free(maps[map_idx].path);
+fail0:
+	for (i = 0; i < map_idx; i++)
+		rte_free(maps[i].path);
+	rte_free(uio_res);
+
+	return -1;
 }
 
 #ifdef RTE_LIBRTE_EAL_HOTPLUG
@@ -405,9 +408,11 @@ pci_uio_unmap(struct mapped_pci_resource *uio_res)
 	if (uio_res == NULL)
 		return;
 
-	for (i = 0; i != uio_res->nb_maps; i++)
+	for (i = 0; i != uio_res->nb_maps; i++) {
 		pci_unmap_resource(uio_res->maps[i].addr,
 				(size_t)uio_res->maps[i].size);
+		rte_free(uio_res->maps[i].path);
+	}
 }
 
 static struct mapped_pci_resource *
-- 
1.9.1

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

* [dpdk-dev] [PATCH v2 4/6] eal/bsdapp: Change names of pci related data structure
  2015-03-24  4:18         ` [dpdk-dev] [PATCH v2 0/6] Clean up pci uio implementations Tetsuya Mukawa
                             ` (2 preceding siblings ...)
  2015-03-24  4:18           ` [dpdk-dev] [PATCH v2 3/6] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
@ 2015-03-24  4:18           ` Tetsuya Mukawa
  2015-03-24  4:18           ` [dpdk-dev] [PATCH v2 5/6] eal: Use map_idx in pci_uio_map_resource() of bsdapp to work same as linuxapp Tetsuya Mukawa
  2015-03-24  4:18           ` [dpdk-dev] [PATCH v2 6/6] eal: Fix interface of pci_map_resource() Tetsuya Mukawa
  5 siblings, 0 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-24  4:18 UTC (permalink / raw)
  To: dev

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

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

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

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

* [dpdk-dev] [PATCH v2 5/6] eal: Use map_idx in pci_uio_map_resource() of bsdapp to work same as linuxapp
  2015-03-24  4:18         ` [dpdk-dev] [PATCH v2 0/6] Clean up pci uio implementations Tetsuya Mukawa
                             ` (3 preceding siblings ...)
  2015-03-24  4:18           ` [dpdk-dev] [PATCH v2 4/6] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
@ 2015-03-24  4:18           ` Tetsuya Mukawa
  2015-03-25 15:27             ` Iremonger, Bernard
  2015-03-24  4:18           ` [dpdk-dev] [PATCH v2 6/6] eal: Fix interface of pci_map_resource() Tetsuya Mukawa
  5 siblings, 1 reply; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-24  4:18 UTC (permalink / raw)
  To: dev

This patch changes code that maps pci resources in bsdapp.
Linuxapp has almost same code. To consolidate both, fix implementation
of bsdapp to work same as linuxapp.

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

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 85f8671..08b91b4 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -195,7 +195,7 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 static int
 pci_uio_map_resource(struct rte_pci_device *dev)
 {
-	int i, j;
+	int i, map_idx;
 	char devname[PATH_MAX]; /* contains the /dev/uioX */
 	void *mapaddr;
 	uint64_t phaddr;
@@ -247,31 +247,31 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	pagesz = sysconf(_SC_PAGESIZE);
 
 	maps = uio_res->maps;
-	for (i = uio_res->nb_maps = 0; i != PCI_MAX_RESOURCE; i++) {
+	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
 
-		j = uio_res->nb_maps;
 		/* skip empty BAR */
 		if ((phaddr = dev->mem_resource[i].phys_addr) == 0)
 			continue;
 
 		/* if matching map is found, then use it */
 		offset = i * pagesz;
-		maps[j].offset = offset;
-		maps[j].phaddr = dev->mem_resource[i].phys_addr;
-		maps[j].size = dev->mem_resource[i].len;
-		if (maps[j].addr != NULL ||
-		    (mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
-						(size_t)maps[j].size)
-		    ) == NULL) {
+		maps[map_idx].offset = offset;
+		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
+		maps[map_idx].size = dev->mem_resource[i].len;
+		mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
+					(size_t)maps[map_idx].size);
+		if ((maps[map_idx].addr != NULL) || (mapaddr == NULL)) {
 			rte_free(uio_res);
 			return -1;
 		}
 
-		maps[j].addr = mapaddr;
-		uio_res->nb_maps++;
+		maps[map_idx].addr = mapaddr;
+		map_idx++;
 		dev->mem_resource[i].addr = mapaddr;
 	}
 
+	uio_res->nb_maps = map_idx;
+
 	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
 
 	return 0;
-- 
1.9.1

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

* [dpdk-dev] [PATCH v2 6/6] eal: Fix interface of pci_map_resource()
  2015-03-24  4:18         ` [dpdk-dev] [PATCH v2 0/6] Clean up pci uio implementations Tetsuya Mukawa
                             ` (4 preceding siblings ...)
  2015-03-24  4:18           ` [dpdk-dev] [PATCH v2 5/6] eal: Use map_idx in pci_uio_map_resource() of bsdapp to work same as linuxapp Tetsuya Mukawa
@ 2015-03-24  4:18           ` Tetsuya Mukawa
  2015-03-25 15:03             ` Iremonger, Bernard
  5 siblings, 1 reply; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-24  4:18 UTC (permalink / raw)
  To: dev

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

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

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 08b91b4..d83916b 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -100,7 +100,7 @@ struct mapped_pci_resource {
 
 	struct rte_pci_addr pci_addr;
 	char path[PATH_MAX];
-	size_t nb_maps;
+	int nb_maps;
 	struct pci_map maps[PCI_MAX_RESOURCE];
 };
 
@@ -122,47 +122,30 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)
 
 /* map a particular resource from a file */
 static void *
-pci_map_resource(void *requested_addr, const char *devname, off_t offset,
-		 size_t size)
+pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
+		 int additional_flags)
 {
-	int fd;
 	void *mapaddr;
 
-	/*
-	 * open devname, to mmap it
-	 */
-	fd = open(devname, O_RDWR);
-	if (fd < 0) {
-		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
-			devname, strerror(errno));
-		goto fail;
-	}
-
 	/* Map the PCI memory resource of device */
 	mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
-			MAP_SHARED, fd, offset);
-	close(fd);
-	if (mapaddr == MAP_FAILED ||
-			(requested_addr != NULL && mapaddr != requested_addr)) {
-		RTE_LOG(ERR, EAL, "%s(): cannot mmap(%s(%d), %p, 0x%lx, 0x%lx):"
-			" %s (%p)\n", __func__, devname, fd, requested_addr,
+			MAP_SHARED | additional_flags, fd, offset);
+	if (mapaddr == MAP_FAILED) {
+		RTE_LOG(ERR, EAL,
+			"%s(): cannot mmap(%d, %p, 0x%lx, 0x%lx): %s (%p)\n",
+			__func__, fd, requested_addr,
 			(unsigned long)size, (unsigned long)offset,
 			strerror(errno), mapaddr);
-		goto fail;
-	}
-
-	RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
+	} else
+		RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
 
 	return mapaddr;
-
-fail:
-	return NULL;
 }
 
 static int
 pci_uio_map_secondary(struct rte_pci_device *dev)
 {
-	size_t i;
+	int i, fd;
 	struct mapped_pci_resource *uio_res;
 	struct mapped_pci_res_list *uio_res_list =
 			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
@@ -170,19 +153,34 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 	TAILQ_FOREACH(uio_res, uio_res_list, next) {
 
 		/* skip this element if it doesn't match our PCI address */
-		if (memcmp(&uio_res->pci_addr, &dev->addr, sizeof(dev->addr)))
+		if (rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr))
 			continue;
 
 		for (i = 0; i != uio_res->nb_maps; i++) {
-			if (pci_map_resource(uio_res->maps[i].addr,
-					     uio_res->path,
-					     (off_t)uio_res->maps[i].offset,
-					     (size_t)uio_res->maps[i].size)
-			    != uio_res->maps[i].addr) {
+			/*
+			 * open devname, to mmap it
+			 */
+			fd = open(uio_res->maps[i].path, O_RDWR);
+			if (fd < 0) {
+				RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
+					uio_res->maps[i].path, strerror(errno));
+				return -1;
+			}
+
+			void *mapaddr = pci_map_resource(uio_res->maps[i].addr,
+					fd, (off_t)uio_res->maps[i].offset,
+					(size_t)uio_res->maps[i].size, 0);
+			if (mapaddr != uio_res->maps[i].addr) {
 				RTE_LOG(ERR, EAL,
-					"Cannot mmap device resource\n");
+						"Cannot mmap device resource "
+						"file %s to address: %p\n",
+						uio_res->maps[i].path,
+						uio_res->maps[i].addr);
+				close(fd);
 				return -1;
 			}
+			/* fd is not needed in slave process, close it */
+			close(fd);
 		}
 		return 0;
 	}
@@ -248,24 +246,43 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 	maps = uio_res->maps;
 	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
+		int fd;
 
 		/* 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 fail0;
+		}
+
+		/*
+		 * 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 fail1;
+		}
+
 		/* if matching map is found, then use it */
 		offset = i * pagesz;
-		maps[map_idx].offset = offset;
+		mapaddr = pci_map_resource(NULL, fd, (off_t)offset,
+					(size_t)dev->mem_resource[i].len, 0);
+		close(fd);
+		if (mapaddr == MAP_FAILED)
+			goto fail1;
+
 		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
 		maps[map_idx].size = dev->mem_resource[i].len;
-		mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
-					(size_t)maps[map_idx].size);
-		if ((maps[map_idx].addr != NULL) || (mapaddr == NULL)) {
-			rte_free(uio_res);
-			return -1;
-		}
-
 		maps[map_idx].addr = mapaddr;
+		maps[map_idx].offset = offset;
+		strcpy(maps[map_idx].path, devname);
 		map_idx++;
 		dev->mem_resource[i].addr = mapaddr;
 	}
@@ -275,6 +292,14 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
 
 	return 0;
+
+fail1:
+	rte_free(maps[map_idx].path);
+fail0:
+	for (i = 0; i < map_idx; i++)
+		rte_free(maps[i].path);
+	rte_free(uio_res);
+	return -1;
 }
 
 /* Scan one pci sysfs entry, and fill the devices list from it. */
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 0128cec..1f94d3a 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -116,17 +116,11 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 					fd, (off_t)uio_res->maps[i].offset,
 					(size_t)uio_res->maps[i].size, 0);
 			if (mapaddr != uio_res->maps[i].addr) {
-				if (mapaddr == MAP_FAILED)
-					RTE_LOG(ERR, EAL,
-							"Cannot mmap device resource file %s: %s\n",
-							uio_res->maps[i].path,
-							strerror(errno));
-				else
-					RTE_LOG(ERR, EAL,
-							"Cannot mmap device resource file %s to address: %p\n",
-							uio_res->maps[i].path,
-							uio_res->maps[i].addr);
-
+				RTE_LOG(ERR, EAL,
+						"Cannot mmap device resource "
+						"file %s to address: %p\n",
+						uio_res->maps[i].path,
+						uio_res->maps[i].addr);
 				close(fd);
 				return -1;
 			}
@@ -348,8 +342,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 		/* allocate memory to keep path */
 		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
-		if (maps[map_idx].path == NULL)
+		if (maps[map_idx].path == NULL) {
+			RTE_LOG(ERR, EAL, "Cannot allocate memory for "
+					"path: %s\n", strerror(errno));
 			goto fail0;
+		}
 
 		/*
 		 * open resource file, to mmap it
-- 
1.9.1

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

* Re: [dpdk-dev] [PATCH v2 2/6] eal: Close file descriptor of uio configuration
  2015-03-24  4:18           ` [dpdk-dev] [PATCH v2 2/6] eal: Close file descriptor of uio configuration Tetsuya Mukawa
@ 2015-03-24 18:33             ` Stephen Hemminger
  2015-03-25  3:17               ` Tetsuya Mukawa
  0 siblings, 1 reply; 87+ messages in thread
From: Stephen Hemminger @ 2015-03-24 18:33 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Tue, 24 Mar 2015 13:18:33 +0900
Tetsuya Mukawa <mukawa@igel.co.jp> wrote:

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


For the Qlogic/Broadcom driver it needed the config fd handle, and I added
generic config space access functions.

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

* Re: [dpdk-dev] [PATCH v2 2/6] eal: Close file descriptor of uio configuration
  2015-03-24 18:33             ` Stephen Hemminger
@ 2015-03-25  3:17               ` Tetsuya Mukawa
  2015-03-25  5:07                 ` Stephen Hemminger
  0 siblings, 1 reply; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-25  3:17 UTC (permalink / raw)
  To: Stephen Hemminger, Iremonger, Bernard, david.marchand; +Cc: dev

On 2015/03/25 3:33, Stephen Hemminger wrote:
> On Tue, 24 Mar 2015 13:18:33 +0900
> Tetsuya Mukawa <mukawa@igel.co.jp> wrote:
>
>> When pci_uio_unmap_resource() is called, a file descriptor that is used
>> for uio configuration should be closed.
>>
>> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
>> ---
>>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 6 +++++-
>>  1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>> index 9cdf24f..f0277be 100644
>> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>> @@ -459,8 +459,12 @@ pci_uio_unmap_resource(struct rte_pci_device *dev)
>>  
>>  	/* close fd if in primary process */
>>  	close(dev->intr_handle.fd);
>> -
>>  	dev->intr_handle.fd = -1;
>> +
>> +	/* close cfg_fd if in primary process */
>> +	close(dev->intr_handle.uio_cfg_fd);
>> +	dev->intr_handle.uio_cfg_fd = -1;
>> +
>>  	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
>>  }
>>  #endif /* RTE_LIBRTE_EAL_HOTPLUG */
>
> For the Qlogic/Broadcom driver it needed the config fd handle, and I added
> generic config space access functions.

Hi Stephen,

Is this the patch you mentioned?
http://dpdk.org/dev/patchwork/patch/3024/


Hi David, Bernard, Stephen

I guess here are works we will need to do.
1. Add close(dev->config_fd) in Stephen's patch.
2. Write a patch for uio to merge "dev->intr_handle->uio_cfg_fd" and
"dev->config_fd".
3. Write a patch for vfio to merge "dev->intr_handle->vfio_cfg_fd" and
"dev->config_fd".

If we already have these patches, I guess it may be nice to merge above
patches first.
Do you have a suggestion how to merge patches related with pci config fd?

Thanks,
Tetsuya

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

* Re: [dpdk-dev] [PATCH v2 2/6] eal: Close file descriptor of uio configuration
  2015-03-25  3:17               ` Tetsuya Mukawa
@ 2015-03-25  5:07                 ` Stephen Hemminger
  2015-03-26  4:19                   ` Tetsuya Mukawa
  0 siblings, 1 reply; 87+ messages in thread
From: Stephen Hemminger @ 2015-03-25  5:07 UTC (permalink / raw)
  To: Tetsuya Mukawa; +Cc: dev

On Wed, 25 Mar 2015 12:17:32 +0900
Tetsuya Mukawa <mukawa@igel.co.jp> wrote:

> On 2015/03/25 3:33, Stephen Hemminger wrote:
> > On Tue, 24 Mar 2015 13:18:33 +0900
> > Tetsuya Mukawa <mukawa@igel.co.jp> wrote:
> >
> >> When pci_uio_unmap_resource() is called, a file descriptor that is used
> >> for uio configuration should be closed.
> >>
> >> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> >> ---
> >>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 6 +++++-
> >>  1 file changed, 5 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> >> index 9cdf24f..f0277be 100644
> >> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> >> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> >> @@ -459,8 +459,12 @@ pci_uio_unmap_resource(struct rte_pci_device *dev)
> >>  
> >>  	/* close fd if in primary process */
> >>  	close(dev->intr_handle.fd);
> >> -
> >>  	dev->intr_handle.fd = -1;
> >> +
> >> +	/* close cfg_fd if in primary process */
> >> +	close(dev->intr_handle.uio_cfg_fd);
> >> +	dev->intr_handle.uio_cfg_fd = -1;
> >> +
> >>  	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
> >>  }
> >>  #endif /* RTE_LIBRTE_EAL_HOTPLUG */
> >
> > For the Qlogic/Broadcom driver it needed the config fd handle, and I added
> > generic config space access functions.
> 
> Hi Stephen,
> 
> Is this the patch you mentioned?
> http://dpdk.org/dev/patchwork/patch/3024/
> 
> 
> Hi David, Bernard, Stephen
> 
> I guess here are works we will need to do.
> 1. Add close(dev->config_fd) in Stephen's patch.
> 2. Write a patch for uio to merge "dev->intr_handle->uio_cfg_fd" and
> "dev->config_fd".
> 3. Write a patch for vfio to merge "dev->intr_handle->vfio_cfg_fd" and
> "dev->config_fd".
> 
> If we already have these patches, I guess it may be nice to merge above
> patches first.
> Do you have a suggestion how to merge patches related with pci config fd?
> 
> Thanks,
> Tetsuya
> 

Yeah, that is the patch. It reopens config fd, it seems to overlap
this.

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

* Re: [dpdk-dev] [PATCH v2 3/6] eal: Fix memory leaks and needless increment of pci_map_addr
  2015-03-24  4:18           ` [dpdk-dev] [PATCH v2 3/6] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
@ 2015-03-25 15:00             ` Iremonger, Bernard
  2015-03-26  2:44               ` Tetsuya Mukawa
  0 siblings, 1 reply; 87+ messages in thread
From: Iremonger, Bernard @ 2015-03-25 15:00 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev



> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Tuesday, March 24, 2015 4:19 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; Richardson, Bruce; david.marchand@6wind.com; Tetsuya Mukawa
> Subject: [PATCH v2 3/6] eal: Fix memory leaks and needless increment of pci_map_addr
> 
> This patch fixes following memory leaks.
> - When pci_map_resource() is failed but path is allocated correctly,
>   path won't be freed in pci_uio_map_recource().
> - When open() is failed, uio_res won't be freed in
>   pci_uio_map_resource().
> - When pci_uio_unmap() is called, path should be freed.
> 
> Also, fixes below.
> - When pci_map_resource() is failed, mapaddr will be MAP_FAILED.
>   In this case, pci_map_addr should not be incremented in
>   pci_uio_map_resource().
> - To shrink code, move close().
> - Remove fail variable.
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 35 ++++++++++++++++++-------------
>  1 file changed, 20 insertions(+), 15 deletions(-)
> 
> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> index f0277be..0128cec 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> @@ -333,7 +333,6 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  	maps = uio_res->maps;
>  	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
>  		int fd;
> -		int fail = 0;
> 
>  		/* skip empty BAR */
>  		phaddr = dev->mem_resource[i].phys_addr; @@ -347,6 +346,11 @@
> pci_uio_map_resource(struct rte_pci_device *dev)
>  				loc->domain, loc->bus, loc->devid, loc->function,
>  				i);
> 
> +		/* allocate memory to keep path */
> +		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
> +		if (maps[map_idx].path == NULL)
> +			goto fail0;
> +
>  		/*
>  		 * open resource file, to mmap it
>  		 */
> @@ -354,7 +358,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  		if (fd < 0) {
>  			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
>  					devname, strerror(errno));
> -			return -1;
> +			goto fail1;
>  		}
> 
>  		/* try mapping somewhere close to the end of hugepages */ @@ -363,23 +367,13 @@
> pci_uio_map_resource(struct rte_pci_device *dev)
> 
>  		mapaddr = pci_map_resource(pci_map_addr, fd, 0,
>  				(size_t)dev->mem_resource[i].len, 0);
> +		close(fd);
>  		if (mapaddr == MAP_FAILED)
> -			fail = 1;
> +			goto fail1;
> 
>  		pci_map_addr = RTE_PTR_ADD(mapaddr,
>  				(size_t)dev->mem_resource[i].len);
> 
> -		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
> -		if (maps[map_idx].path == NULL)
> -			fail = 1;
> -
> -		if (fail) {
> -			rte_free(uio_res);
> -			close(fd);
> -			return -1;
> -		}
> -		close(fd);
> -
>  		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
>  		maps[map_idx].size = dev->mem_resource[i].len;
>  		maps[map_idx].addr = mapaddr;
> @@ -394,6 +388,15 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
> 
>  	return 0;
> +
> +fail1:
> +	rte_free(maps[map_idx].path);
> +fail0:
> +	for (i = 0; i < map_idx; i++)

Hi Tetsuya,

fail1: falls through to  fail0:
Would it be cleaner to drop fail1: and change the for loop in fail0:  to
for (i = 0; i <= map_idx; i++) 

Regards,

Bernard.

> +		rte_free(maps[i].path);
> +	rte_free(uio_res);
> +
> +	return -1;
>  }
> 
>  #ifdef RTE_LIBRTE_EAL_HOTPLUG
> @@ -405,9 +408,11 @@ pci_uio_unmap(struct mapped_pci_resource *uio_res)
>  	if (uio_res == NULL)
>  		return;
> 
> -	for (i = 0; i != uio_res->nb_maps; i++)
> +	for (i = 0; i != uio_res->nb_maps; i++) {
>  		pci_unmap_resource(uio_res->maps[i].addr,
>  				(size_t)uio_res->maps[i].size);
> +		rte_free(uio_res->maps[i].path);
> +	}
>  }
> 
>  static struct mapped_pci_resource *
> --
> 1.9.1

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

* Re: [dpdk-dev] [PATCH v2 6/6] eal: Fix interface of pci_map_resource()
  2015-03-24  4:18           ` [dpdk-dev] [PATCH v2 6/6] eal: Fix interface of pci_map_resource() Tetsuya Mukawa
@ 2015-03-25 15:03             ` Iremonger, Bernard
  0 siblings, 0 replies; 87+ messages in thread
From: Iremonger, Bernard @ 2015-03-25 15:03 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev

> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Tuesday, March 24, 2015 4:19 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; Richardson, Bruce; david.marchand@6wind.com; Tetsuya Mukawa
> Subject: [PATCH v2 6/6] eal: Fix interface of pci_map_resource()
> 
> The function is implemented in both linuxapp and bsdapp, but interface is different. The patch fixes
> the function of bsdapp to do same as linuxapp. After applying it, file descriptor should be opened and
> closed out of pci_map_resource().
> Also, remove redundant error messages from linuxapp.
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  lib/librte_eal/bsdapp/eal/eal_pci.c       | 111 ++++++++++++++++++------------
>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c |  21 +++---
>  2 files changed, 77 insertions(+), 55 deletions(-)
> 
> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
> index 08b91b4..d83916b 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> @@ -100,7 +100,7 @@ struct mapped_pci_resource {
> 
>  	struct rte_pci_addr pci_addr;
>  	char path[PATH_MAX];
> -	size_t nb_maps;
> +	int nb_maps;
>  	struct pci_map maps[PCI_MAX_RESOURCE];  };
> 
> @@ -122,47 +122,30 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)
> 
>  /* map a particular resource from a file */  static void * -pci_map_resource(void *requested_addr,
> const char *devname, off_t offset,
> -		 size_t size)
> +pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
> +		 int additional_flags)
>  {
> -	int fd;
>  	void *mapaddr;
> 
> -	/*
> -	 * open devname, to mmap it
> -	 */
> -	fd = open(devname, O_RDWR);
> -	if (fd < 0) {
> -		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
> -			devname, strerror(errno));
> -		goto fail;
> -	}
> -
>  	/* Map the PCI memory resource of device */
>  	mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
> -			MAP_SHARED, fd, offset);
> -	close(fd);
> -	if (mapaddr == MAP_FAILED ||
> -			(requested_addr != NULL && mapaddr != requested_addr)) {
> -		RTE_LOG(ERR, EAL, "%s(): cannot mmap(%s(%d), %p, 0x%lx, 0x%lx):"
> -			" %s (%p)\n", __func__, devname, fd, requested_addr,
> +			MAP_SHARED | additional_flags, fd, offset);
> +	if (mapaddr == MAP_FAILED) {
> +		RTE_LOG(ERR, EAL,
> +			"%s(): cannot mmap(%d, %p, 0x%lx, 0x%lx): %s (%p)\n",
> +			__func__, fd, requested_addr,
>  			(unsigned long)size, (unsigned long)offset,
>  			strerror(errno), mapaddr);
> -		goto fail;
> -	}
> -
> -	RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
> +	} else
> +		RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
> 
>  	return mapaddr;
> -
> -fail:
> -	return NULL;
>  }
> 
>  static int
>  pci_uio_map_secondary(struct rte_pci_device *dev)  {
> -	size_t i;
> +	int i, fd;
>  	struct mapped_pci_resource *uio_res;
>  	struct mapped_pci_res_list *uio_res_list =
>  			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list); @@ -170,19
> +153,34 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
>  	TAILQ_FOREACH(uio_res, uio_res_list, next) {
> 
>  		/* skip this element if it doesn't match our PCI address */
> -		if (memcmp(&uio_res->pci_addr, &dev->addr, sizeof(dev->addr)))
> +		if (rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr))
>  			continue;
> 
>  		for (i = 0; i != uio_res->nb_maps; i++) {
> -			if (pci_map_resource(uio_res->maps[i].addr,
> -					     uio_res->path,
> -					     (off_t)uio_res->maps[i].offset,
> -					     (size_t)uio_res->maps[i].size)
> -			    != uio_res->maps[i].addr) {
> +			/*
> +			 * open devname, to mmap it
> +			 */
> +			fd = open(uio_res->maps[i].path, O_RDWR);
> +			if (fd < 0) {
> +				RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
> +					uio_res->maps[i].path, strerror(errno));
> +				return -1;
> +			}
> +
> +			void *mapaddr = pci_map_resource(uio_res->maps[i].addr,
> +					fd, (off_t)uio_res->maps[i].offset,
> +					(size_t)uio_res->maps[i].size, 0);
> +			if (mapaddr != uio_res->maps[i].addr) {
>  				RTE_LOG(ERR, EAL,
> -					"Cannot mmap device resource\n");
> +						"Cannot mmap device resource "
> +						"file %s to address: %p\n",
> +						uio_res->maps[i].path,
> +						uio_res->maps[i].addr);
> +				close(fd);
>  				return -1;
>  			}
> +			/* fd is not needed in slave process, close it */
> +			close(fd);
>  		}
>  		return 0;
>  	}
> @@ -248,24 +246,43 @@ pci_uio_map_resource(struct rte_pci_device *dev)
> 
>  	maps = uio_res->maps;
>  	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
> +		int fd;
> 
>  		/* 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 fail0;
> +		}
> +
> +		/*
> +		 * 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 fail1;
> +		}
> +
>  		/* if matching map is found, then use it */
>  		offset = i * pagesz;
> -		maps[map_idx].offset = offset;
> +		mapaddr = pci_map_resource(NULL, fd, (off_t)offset,
> +					(size_t)dev->mem_resource[i].len, 0);
> +		close(fd);
> +		if (mapaddr == MAP_FAILED)
> +			goto fail1;
> +
>  		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
>  		maps[map_idx].size = dev->mem_resource[i].len;
> -		mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
> -					(size_t)maps[map_idx].size);
> -		if ((maps[map_idx].addr != NULL) || (mapaddr == NULL)) {
> -			rte_free(uio_res);
> -			return -1;
> -		}
> -
>  		maps[map_idx].addr = mapaddr;
> +		maps[map_idx].offset = offset;
> +		strcpy(maps[map_idx].path, devname);
>  		map_idx++;
>  		dev->mem_resource[i].addr = mapaddr;
>  	}
> @@ -275,6 +292,14 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
> 
>  	return 0;
> +
> +fail1:
> +	rte_free(maps[map_idx].path);
> +fail0:
> +	for (i = 0; i < map_idx; i++)

Hi Tetsuya,

fail1: falls through to  fail0:
Would it be cleaner to drop fail1: and change the for loop in fail0:  to
for (i = 0; i <= map_idx; i++) 

Regards,

Bernard.

> +		rte_free(maps[i].path);
> +	rte_free(uio_res);
> +	return -1;
>  }
> 
>  /* Scan one pci sysfs entry, and fill the devices list from it. */ diff --git
> a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> index 0128cec..1f94d3a 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> @@ -116,17 +116,11 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
>  					fd, (off_t)uio_res->maps[i].offset,
>  					(size_t)uio_res->maps[i].size, 0);
>  			if (mapaddr != uio_res->maps[i].addr) {
> -				if (mapaddr == MAP_FAILED)
> -					RTE_LOG(ERR, EAL,
> -							"Cannot mmap device resource file %s: %s\n",
> -							uio_res->maps[i].path,
> -							strerror(errno));
> -				else
> -					RTE_LOG(ERR, EAL,
> -							"Cannot mmap device resource file %s to
> address: %p\n",
> -							uio_res->maps[i].path,
> -							uio_res->maps[i].addr);
> -
> +				RTE_LOG(ERR, EAL,
> +						"Cannot mmap device resource "
> +						"file %s to address: %p\n",
> +						uio_res->maps[i].path,
> +						uio_res->maps[i].addr);
>  				close(fd);
>  				return -1;
>  			}
> @@ -348,8 +342,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
> 
>  		/* allocate memory to keep path */
>  		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
> -		if (maps[map_idx].path == NULL)
> +		if (maps[map_idx].path == NULL) {
> +			RTE_LOG(ERR, EAL, "Cannot allocate memory for "
> +					"path: %s\n", strerror(errno));
>  			goto fail0;
> +		}
> 
>  		/*
>  		 * open resource file, to mmap it
> --
> 1.9.1

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

* Re: [dpdk-dev] [PATCH v2 5/6] eal: Use map_idx in pci_uio_map_resource() of bsdapp to work same as linuxapp
  2015-03-24  4:18           ` [dpdk-dev] [PATCH v2 5/6] eal: Use map_idx in pci_uio_map_resource() of bsdapp to work same as linuxapp Tetsuya Mukawa
@ 2015-03-25 15:27             ` Iremonger, Bernard
  2015-03-26  2:50               ` Tetsuya Mukawa
  0 siblings, 1 reply; 87+ messages in thread
From: Iremonger, Bernard @ 2015-03-25 15:27 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev



> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Tuesday, March 24, 2015 4:19 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; Richardson, Bruce; david.marchand@6wind.com; Tetsuya Mukawa
> Subject: [PATCH v2 5/6] eal: Use map_idx in pci_uio_map_resource() of bsdapp to work same as
> linuxapp
> 
> This patch changes code that maps pci resources in bsdapp.
> Linuxapp has almost same code. To consolidate both, fix implementation of bsdapp to work same as
> linuxapp.
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  lib/librte_eal/bsdapp/eal/eal_pci.c | 24 ++++++++++++------------
>  1 file changed, 12 insertions(+), 12 deletions(-)
> 
> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
> index 85f8671..08b91b4 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> @@ -195,7 +195,7 @@ pci_uio_map_secondary(struct rte_pci_device *dev)  static int
> pci_uio_map_resource(struct rte_pci_device *dev)  {
> -	int i, j;
> +	int i, map_idx;
>  	char devname[PATH_MAX]; /* contains the /dev/uioX */
>  	void *mapaddr;
>  	uint64_t phaddr;
> @@ -247,31 +247,31 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>  	pagesz = sysconf(_SC_PAGESIZE);
> 
>  	maps = uio_res->maps;
> -	for (i = uio_res->nb_maps = 0; i != PCI_MAX_RESOURCE; i++) {
> +	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
> 
> -		j = uio_res->nb_maps;
>  		/* skip empty BAR */
>  		if ((phaddr = dev->mem_resource[i].phys_addr) == 0)
>  			continue;
> 
>  		/* if matching map is found, then use it */
>  		offset = i * pagesz;
> -		maps[j].offset = offset;
> -		maps[j].phaddr = dev->mem_resource[i].phys_addr;
> -		maps[j].size = dev->mem_resource[i].len;
> -		if (maps[j].addr != NULL ||
> -		    (mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
> -						(size_t)maps[j].size)
> -		    ) == NULL) {
> +		maps[map_idx].offset = offset;
> +		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
> +		maps[map_idx].size = dev->mem_resource[i].len;
> +		mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
> +					(size_t)maps[map_idx].size);
> +		if ((maps[map_idx].addr != NULL) || (mapaddr == NULL)) {

Hi Tetsuya,

Should be checking for  if  (mapaddr == MAP_FAILED) here.
Seems to be fixed in patch 6/6 though.

Regards,

Bernard.

>  			rte_free(uio_res);
>  			return -1;
>  		}
> 
> -		maps[j].addr = mapaddr;
> -		uio_res->nb_maps++;
> +		maps[map_idx].addr = mapaddr;
> +		map_idx++;
>  		dev->mem_resource[i].addr = mapaddr;
>  	}
> 
> +	uio_res->nb_maps = map_idx;
> +
>  	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
> 
>  	return 0;
> --
> 1.9.1

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

* Re: [dpdk-dev] [PATCH v2 3/6] eal: Fix memory leaks and needless increment of pci_map_addr
  2015-03-25 15:00             ` Iremonger, Bernard
@ 2015-03-26  2:44               ` Tetsuya Mukawa
  0 siblings, 0 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-26  2:44 UTC (permalink / raw)
  To: Iremonger, Bernard, dev

On 2015/03/26 0:00, Iremonger, Bernard wrote:
>
>> -----Original Message-----
>> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
>> Sent: Tuesday, March 24, 2015 4:19 AM
>> To: dev@dpdk.org
>> Cc: Iremonger, Bernard; Richardson, Bruce; david.marchand@6wind.com; Tetsuya Mukawa
>> Subject: [PATCH v2 3/6] eal: Fix memory leaks and needless increment of pci_map_addr
>>
>> This patch fixes following memory leaks.
>> - When pci_map_resource() is failed but path is allocated correctly,
>>   path won't be freed in pci_uio_map_recource().
>> - When open() is failed, uio_res won't be freed in
>>   pci_uio_map_resource().
>> - When pci_uio_unmap() is called, path should be freed.
>>
>> Also, fixes below.
>> - When pci_map_resource() is failed, mapaddr will be MAP_FAILED.
>>   In this case, pci_map_addr should not be incremented in
>>   pci_uio_map_resource().
>> - To shrink code, move close().
>> - Remove fail variable.
>>
>> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
>> ---
>>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 35 ++++++++++++++++++-------------
>>  1 file changed, 20 insertions(+), 15 deletions(-)
>>
>> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>> index f0277be..0128cec 100644
>> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>> @@ -333,7 +333,6 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>>  	maps = uio_res->maps;
>>  	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
>>  		int fd;
>> -		int fail = 0;
>>
>>  		/* skip empty BAR */
>>  		phaddr = dev->mem_resource[i].phys_addr; @@ -347,6 +346,11 @@
>> pci_uio_map_resource(struct rte_pci_device *dev)
>>  				loc->domain, loc->bus, loc->devid, loc->function,
>>  				i);
>>
>> +		/* allocate memory to keep path */
>> +		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
>> +		if (maps[map_idx].path == NULL)
>> +			goto fail0;
>> +
>>  		/*
>>  		 * open resource file, to mmap it
>>  		 */
>> @@ -354,7 +358,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>>  		if (fd < 0) {
>>  			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
>>  					devname, strerror(errno));
>> -			return -1;
>> +			goto fail1;
>>  		}
>>
>>  		/* try mapping somewhere close to the end of hugepages */ @@ -363,23 +367,13 @@
>> pci_uio_map_resource(struct rte_pci_device *dev)
>>
>>  		mapaddr = pci_map_resource(pci_map_addr, fd, 0,
>>  				(size_t)dev->mem_resource[i].len, 0);
>> +		close(fd);
>>  		if (mapaddr == MAP_FAILED)
>> -			fail = 1;
>> +			goto fail1;
>>
>>  		pci_map_addr = RTE_PTR_ADD(mapaddr,
>>  				(size_t)dev->mem_resource[i].len);
>>
>> -		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
>> -		if (maps[map_idx].path == NULL)
>> -			fail = 1;
>> -
>> -		if (fail) {
>> -			rte_free(uio_res);
>> -			close(fd);
>> -			return -1;
>> -		}
>> -		close(fd);
>> -
>>  		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
>>  		maps[map_idx].size = dev->mem_resource[i].len;
>>  		maps[map_idx].addr = mapaddr;
>> @@ -394,6 +388,15 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>>  	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
>>
>>  	return 0;
>> +
>> +fail1:
>> +	rte_free(maps[map_idx].path);
>> +fail0:
>> +	for (i = 0; i < map_idx; i++)
> Hi Tetsuya,
>
> fail1: falls through to  fail0:
> Would it be cleaner to drop fail1: and change the for loop in fail0:  to
> for (i = 0; i <= map_idx; i++) 

Hi Bernard,

Thanks for suggestion.
I will rewrite a bit to be more cleaner.

Regards,
Tetsuya

> Regards,
>
> Bernard.
>
>> +		rte_free(maps[i].path);
>> +	rte_free(uio_res);
>> +
>> +	return -1;
>>  }
>>
>>  #ifdef RTE_LIBRTE_EAL_HOTPLUG
>> @@ -405,9 +408,11 @@ pci_uio_unmap(struct mapped_pci_resource *uio_res)
>>  	if (uio_res == NULL)
>>  		return;
>>
>> -	for (i = 0; i != uio_res->nb_maps; i++)
>> +	for (i = 0; i != uio_res->nb_maps; i++) {
>>  		pci_unmap_resource(uio_res->maps[i].addr,
>>  				(size_t)uio_res->maps[i].size);
>> +		rte_free(uio_res->maps[i].path);
>> +	}
>>  }
>>
>>  static struct mapped_pci_resource *
>> --
>> 1.9.1

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

* Re: [dpdk-dev] [PATCH v2 5/6] eal: Use map_idx in pci_uio_map_resource() of bsdapp to work same as linuxapp
  2015-03-25 15:27             ` Iremonger, Bernard
@ 2015-03-26  2:50               ` Tetsuya Mukawa
  2015-03-26 10:41                 ` Iremonger, Bernard
  0 siblings, 1 reply; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-26  2:50 UTC (permalink / raw)
  To: Iremonger, Bernard, dev

On 2015/03/26 0:27, Iremonger, Bernard wrote:
>
>> -----Original Message-----
>> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
>> Sent: Tuesday, March 24, 2015 4:19 AM
>> To: dev@dpdk.org
>> Cc: Iremonger, Bernard; Richardson, Bruce; david.marchand@6wind.com; Tetsuya Mukawa
>> Subject: [PATCH v2 5/6] eal: Use map_idx in pci_uio_map_resource() of bsdapp to work same as
>> linuxapp
>>
>> This patch changes code that maps pci resources in bsdapp.
>> Linuxapp has almost same code. To consolidate both, fix implementation of bsdapp to work same as
>> linuxapp.
>>
>> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
>> ---
>>  lib/librte_eal/bsdapp/eal/eal_pci.c | 24 ++++++++++++------------
>>  1 file changed, 12 insertions(+), 12 deletions(-)
>>
>> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
>> index 85f8671..08b91b4 100644
>> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
>> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
>> @@ -195,7 +195,7 @@ pci_uio_map_secondary(struct rte_pci_device *dev)  static int
>> pci_uio_map_resource(struct rte_pci_device *dev)  {
>> -	int i, j;
>> +	int i, map_idx;
>>  	char devname[PATH_MAX]; /* contains the /dev/uioX */
>>  	void *mapaddr;
>>  	uint64_t phaddr;
>> @@ -247,31 +247,31 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>>  	pagesz = sysconf(_SC_PAGESIZE);
>>
>>  	maps = uio_res->maps;
>> -	for (i = uio_res->nb_maps = 0; i != PCI_MAX_RESOURCE; i++) {
>> +	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
>>
>> -		j = uio_res->nb_maps;
>>  		/* skip empty BAR */
>>  		if ((phaddr = dev->mem_resource[i].phys_addr) == 0)
>>  			continue;
>>
>>  		/* if matching map is found, then use it */
>>  		offset = i * pagesz;
>> -		maps[j].offset = offset;
>> -		maps[j].phaddr = dev->mem_resource[i].phys_addr;
>> -		maps[j].size = dev->mem_resource[i].len;
>> -		if (maps[j].addr != NULL ||
>> -		    (mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
>> -						(size_t)maps[j].size)
>> -		    ) == NULL) {
>> +		maps[map_idx].offset = offset;
>> +		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
>> +		maps[map_idx].size = dev->mem_resource[i].len;
>> +		mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
>> +					(size_t)maps[map_idx].size);
>> +		if ((maps[map_idx].addr != NULL) || (mapaddr == NULL)) {
> Hi Tetsuya,
>
> Should be checking for  if  (mapaddr == MAP_FAILED) here.
> Seems to be fixed in patch 6/6 though.

Hi Bernard,

Here, bsdapp still has old pci_map_resource().
Old pci_map_resource() return NULL when mapping is failed.
And this behavior will be changed in 6/6. This is why MAP_FAILED is
checked in 6/6.

Regards,
Tetsuya

> Regards,
>
> Bernard.
>
>>  			rte_free(uio_res);
>>  			return -1;
>>  		}
>>
>> -		maps[j].addr = mapaddr;
>> -		uio_res->nb_maps++;
>> +		maps[map_idx].addr = mapaddr;
>> +		map_idx++;
>>  		dev->mem_resource[i].addr = mapaddr;
>>  	}
>>
>> +	uio_res->nb_maps = map_idx;
>> +
>>  	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
>>
>>  	return 0;
>> --
>> 1.9.1

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

* Re: [dpdk-dev] [PATCH v2 2/6] eal: Close file descriptor of uio configuration
  2015-03-25  5:07                 ` Stephen Hemminger
@ 2015-03-26  4:19                   ` Tetsuya Mukawa
  2015-03-26 10:03                     ` Iremonger, Bernard
  0 siblings, 1 reply; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-26  4:19 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: dev

On 2015/03/25 14:07, Stephen Hemminger wrote:
> On Wed, 25 Mar 2015 12:17:32 +0900
> Tetsuya Mukawa <mukawa@igel.co.jp> wrote:
>
>> On 2015/03/25 3:33, Stephen Hemminger wrote:
>>> On Tue, 24 Mar 2015 13:18:33 +0900
>>> Tetsuya Mukawa <mukawa@igel.co.jp> wrote:
>>>
>>>> When pci_uio_unmap_resource() is called, a file descriptor that is used
>>>> for uio configuration should be closed.
>>>>
>>>> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
>>>> ---
>>>>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 6 +++++-
>>>>  1 file changed, 5 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>>>> index 9cdf24f..f0277be 100644
>>>> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>>>> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>>>> @@ -459,8 +459,12 @@ pci_uio_unmap_resource(struct rte_pci_device *dev)
>>>>  
>>>>  	/* close fd if in primary process */
>>>>  	close(dev->intr_handle.fd);
>>>> -
>>>>  	dev->intr_handle.fd = -1;
>>>> +
>>>> +	/* close cfg_fd if in primary process */
>>>> +	close(dev->intr_handle.uio_cfg_fd);
>>>> +	dev->intr_handle.uio_cfg_fd = -1;
>>>> +
>>>>  	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
>>>>  }
>>>>  #endif /* RTE_LIBRTE_EAL_HOTPLUG */
>>> For the Qlogic/Broadcom driver it needed the config fd handle, and I added
>>> generic config space access functions.
>> Hi Stephen,
>>
>> Is this the patch you mentioned?
>> http://dpdk.org/dev/patchwork/patch/3024/
>>
>>
>> Hi David, Bernard, Stephen
>>
>> I guess here are works we will need to do.
>> 1. Add close(dev->config_fd) in Stephen's patch.
>> 2. Write a patch for uio to merge "dev->intr_handle->uio_cfg_fd" and
>> "dev->config_fd".
>> 3. Write a patch for vfio to merge "dev->intr_handle->vfio_cfg_fd" and
>> "dev->config_fd".
>>
>> If we already have these patches, I guess it may be nice to merge above
>> patches first.
>> Do you have a suggestion how to merge patches related with pci config fd?
>>
>> Thanks,
>> Tetsuya
>>
> Yeah, that is the patch. It reopens config fd, it seems to overlap
> this.

Hi Stephen, David, Bernard,

If you are OK, I will cherry pick below Stephen's patch, then put it on
top of my patches.
- http://dpdk.org/dev/patchwork/patch/3024/

Also I will write patches to merge following fds.
 - dev->config_fd
 - dev->intr_handle->uio_cfg_fd
 - dev->intr_handle->vfio_cfg_fd

Is this direction OK?


Stephen,

For uio, I guess it will be OK that I just replace pread/pwrite by your
APIs.
But for vfio, I need to write a function to wrap vfio ioctl.
May be rte_eal_pci_ioctl_config()?
And replace all vfio ioctls by the function.
Is this correct way to adopt your APIs for vfio?

Regards,
Tetsuya

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

* Re: [dpdk-dev] [PATCH v2 2/6] eal: Close file descriptor of uio configuration
  2015-03-26  4:19                   ` Tetsuya Mukawa
@ 2015-03-26 10:03                     ` Iremonger, Bernard
  2015-03-27  6:01                       ` Tetsuya Mukawa
  0 siblings, 1 reply; 87+ messages in thread
From: Iremonger, Bernard @ 2015-03-26 10:03 UTC (permalink / raw)
  To: Tetsuya Mukawa, Stephen Hemminger; +Cc: dev



> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Thursday, March 26, 2015 4:19 AM
> To: Stephen Hemminger
> Cc: Iremonger, Bernard; david.marchand@6wind.com; dev@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH v2 2/6] eal: Close file descriptor of uio configuration
> 
> On 2015/03/25 14:07, Stephen Hemminger wrote:
> > On Wed, 25 Mar 2015 12:17:32 +0900
> > Tetsuya Mukawa <mukawa@igel.co.jp> wrote:
> >
> >> On 2015/03/25 3:33, Stephen Hemminger wrote:
> >>> On Tue, 24 Mar 2015 13:18:33 +0900
> >>> Tetsuya Mukawa <mukawa@igel.co.jp> wrote:
> >>>
> >>>> When pci_uio_unmap_resource() is called, a file descriptor that is
> >>>> used for uio configuration should be closed.
> >>>>
> >>>> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> >>>> ---
> >>>>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 6 +++++-
> >>>>  1 file changed, 5 insertions(+), 1 deletion(-)
> >>>>
> >>>> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> >>>> b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> >>>> index 9cdf24f..f0277be 100644
> >>>> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> >>>> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
> >>>> @@ -459,8 +459,12 @@ pci_uio_unmap_resource(struct rte_pci_device
> >>>> *dev)
> >>>>
> >>>>  	/* close fd if in primary process */
> >>>>  	close(dev->intr_handle.fd);
> >>>> -
> >>>>  	dev->intr_handle.fd = -1;
> >>>> +
> >>>> +	/* close cfg_fd if in primary process */
> >>>> +	close(dev->intr_handle.uio_cfg_fd);
> >>>> +	dev->intr_handle.uio_cfg_fd = -1;
> >>>> +
> >>>>  	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;  }  #endif /*
> >>>> RTE_LIBRTE_EAL_HOTPLUG */
> >>> For the Qlogic/Broadcom driver it needed the config fd handle, and I
> >>> added generic config space access functions.
> >> Hi Stephen,
> >>
> >> Is this the patch you mentioned?
> >> http://dpdk.org/dev/patchwork/patch/3024/
> >>
> >>
> >> Hi David, Bernard, Stephen
> >>
> >> I guess here are works we will need to do.
> >> 1. Add close(dev->config_fd) in Stephen's patch.
> >> 2. Write a patch for uio to merge "dev->intr_handle->uio_cfg_fd" and
> >> "dev->config_fd".
> >> 3. Write a patch for vfio to merge "dev->intr_handle->vfio_cfg_fd"
> >> and "dev->config_fd".
> >>
> >> If we already have these patches, I guess it may be nice to merge
> >> above patches first.
> >> Do you have a suggestion how to merge patches related with pci config fd?
> >>
> >> Thanks,
> >> Tetsuya
> >>
> > Yeah, that is the patch. It reopens config fd, it seems to overlap
> > this.
> 
> Hi Stephen, David, Bernard,
> 
> If you are OK, I will cherry pick below Stephen's patch, then put it on top of my patches.
> - http://dpdk.org/dev/patchwork/patch/3024/
> 
> Also I will write patches to merge following fds.
>  - dev->config_fd
>  - dev->intr_handle->uio_cfg_fd
>  - dev->intr_handle->vfio_cfg_fd
> 
> Is this direction OK?
> 
> 
> Stephen,
> 
> For uio, I guess it will be OK that I just replace pread/pwrite by your APIs.
> But for vfio, I need to write a function to wrap vfio ioctl.
> May be rte_eal_pci_ioctl_config()?
> And replace all vfio ioctls by the function.
> Is this correct way to adopt your APIs for vfio?
> 
> Regards,
> Tetsuya

Hi Tetsuya,

It would be better not to broaden the scope of the BSD cleanup patch set at this point.
It would be better to have a separate patch set  to apply Stephen's changes to the BSD code base.
Also, discussion is still ongoing on Stephen's changes so it might be better to wait until the discussion is completed.

Regards,

Bernard.

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

* Re: [dpdk-dev] [PATCH v2 5/6] eal: Use map_idx in pci_uio_map_resource() of bsdapp to work same as linuxapp
  2015-03-26  2:50               ` Tetsuya Mukawa
@ 2015-03-26 10:41                 ` Iremonger, Bernard
  2015-03-27  8:19                   ` Tetsuya Mukawa
  0 siblings, 1 reply; 87+ messages in thread
From: Iremonger, Bernard @ 2015-03-26 10:41 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev



> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Thursday, March 26, 2015 2:51 AM
> To: Iremonger, Bernard; dev@dpdk.org
> Cc: Richardson, Bruce; david.marchand@6wind.com
> Subject: Re: [PATCH v2 5/6] eal: Use map_idx in pci_uio_map_resource() of bsdapp to work same as
> linuxapp
> 
> On 2015/03/26 0:27, Iremonger, Bernard wrote:
> >
> >> -----Original Message-----
> >> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> >> Sent: Tuesday, March 24, 2015 4:19 AM
> >> To: dev@dpdk.org
> >> Cc: Iremonger, Bernard; Richardson, Bruce; david.marchand@6wind.com;
> >> Tetsuya Mukawa
> >> Subject: [PATCH v2 5/6] eal: Use map_idx in pci_uio_map_resource() of
> >> bsdapp to work same as linuxapp
> >>
> >> This patch changes code that maps pci resources in bsdapp.
> >> Linuxapp has almost same code. To consolidate both, fix
> >> implementation of bsdapp to work same as linuxapp.
> >>
> >> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> >> ---
> >>  lib/librte_eal/bsdapp/eal/eal_pci.c | 24 ++++++++++++------------
> >>  1 file changed, 12 insertions(+), 12 deletions(-)
> >>
> >> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c
> >> b/lib/librte_eal/bsdapp/eal/eal_pci.c
> >> index 85f8671..08b91b4 100644
> >> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> >> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> >> @@ -195,7 +195,7 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
> >> static int pci_uio_map_resource(struct rte_pci_device *dev)  {
> >> -	int i, j;
> >> +	int i, map_idx;
> >>  	char devname[PATH_MAX]; /* contains the /dev/uioX */
> >>  	void *mapaddr;
> >>  	uint64_t phaddr;
> >> @@ -247,31 +247,31 @@ pci_uio_map_resource(struct rte_pci_device *dev)
> >>  	pagesz = sysconf(_SC_PAGESIZE);
> >>
> >>  	maps = uio_res->maps;
> >> -	for (i = uio_res->nb_maps = 0; i != PCI_MAX_RESOURCE; i++) {
> >> +	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
> >>
> >> -		j = uio_res->nb_maps;
> >>  		/* skip empty BAR */
> >>  		if ((phaddr = dev->mem_resource[i].phys_addr) == 0)
> >>  			continue;
> >>
> >>  		/* if matching map is found, then use it */
> >>  		offset = i * pagesz;
> >> -		maps[j].offset = offset;
> >> -		maps[j].phaddr = dev->mem_resource[i].phys_addr;
> >> -		maps[j].size = dev->mem_resource[i].len;
> >> -		if (maps[j].addr != NULL ||
> >> -		    (mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
> >> -						(size_t)maps[j].size)
> >> -		    ) == NULL) {
> >> +		maps[map_idx].offset = offset;
> >> +		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
> >> +		maps[map_idx].size = dev->mem_resource[i].len;
> >> +		mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
> >> +					(size_t)maps[map_idx].size);
> >> +		if ((maps[map_idx].addr != NULL) || (mapaddr == NULL)) {
> > Hi Tetsuya,
> >
> > Should be checking for  if  (mapaddr == MAP_FAILED) here.
> > Seems to be fixed in patch 6/6 though.
> 
> Hi Bernard,
> 
> Here, bsdapp still has old pci_map_resource().
> Old pci_map_resource() return NULL when mapping is failed.
> And this behavior will be changed in 6/6. This is why MAP_FAILED is checked in 6/6.
> 
> Regards,
> Tetsuya
> 

Hi Tetsuya,

Would it make sense to squash patches 5/6 and 6/6 ?

Regards,

Bernard.

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

* Re: [dpdk-dev] [PATCH v2 2/6] eal: Close file descriptor of uio configuration
  2015-03-26 10:03                     ` Iremonger, Bernard
@ 2015-03-27  6:01                       ` Tetsuya Mukawa
  0 siblings, 0 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-27  6:01 UTC (permalink / raw)
  To: Iremonger, Bernard, Stephen Hemminger; +Cc: dev

On 2015/03/26 19:03, Iremonger, Bernard wrote:
>
>> -----Original Message-----
>> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
>> Sent: Thursday, March 26, 2015 4:19 AM
>> To: Stephen Hemminger
>> Cc: Iremonger, Bernard; david.marchand@6wind.com; dev@dpdk.org
>> Subject: Re: [dpdk-dev] [PATCH v2 2/6] eal: Close file descriptor of uio configuration
>>
>> On 2015/03/25 14:07, Stephen Hemminger wrote:
>>> On Wed, 25 Mar 2015 12:17:32 +0900
>>> Tetsuya Mukawa <mukawa@igel.co.jp> wrote:
>>>
>>>> On 2015/03/25 3:33, Stephen Hemminger wrote:
>>>>> On Tue, 24 Mar 2015 13:18:33 +0900
>>>>> Tetsuya Mukawa <mukawa@igel.co.jp> wrote:
>>>>>
>>>>>> When pci_uio_unmap_resource() is called, a file descriptor that is
>>>>>> used for uio configuration should be closed.
>>>>>>
>>>>>> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
>>>>>> ---
>>>>>>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 6 +++++-
>>>>>>  1 file changed, 5 insertions(+), 1 deletion(-)
>>>>>>
>>>>>> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>>>>>> b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>>>>>> index 9cdf24f..f0277be 100644
>>>>>> --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>>>>>> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
>>>>>> @@ -459,8 +459,12 @@ pci_uio_unmap_resource(struct rte_pci_device
>>>>>> *dev)
>>>>>>
>>>>>>  	/* close fd if in primary process */
>>>>>>  	close(dev->intr_handle.fd);
>>>>>> -
>>>>>>  	dev->intr_handle.fd = -1;
>>>>>> +
>>>>>> +	/* close cfg_fd if in primary process */
>>>>>> +	close(dev->intr_handle.uio_cfg_fd);
>>>>>> +	dev->intr_handle.uio_cfg_fd = -1;
>>>>>> +
>>>>>>  	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;  }  #endif /*
>>>>>> RTE_LIBRTE_EAL_HOTPLUG */
>>>>> For the Qlogic/Broadcom driver it needed the config fd handle, and I
>>>>> added generic config space access functions.
>>>> Hi Stephen,
>>>>
>>>> Is this the patch you mentioned?
>>>> http://dpdk.org/dev/patchwork/patch/3024/
>>>>
>>>>
>>>> Hi David, Bernard, Stephen
>>>>
>>>> I guess here are works we will need to do.
>>>> 1. Add close(dev->config_fd) in Stephen's patch.
>>>> 2. Write a patch for uio to merge "dev->intr_handle->uio_cfg_fd" and
>>>> "dev->config_fd".
>>>> 3. Write a patch for vfio to merge "dev->intr_handle->vfio_cfg_fd"
>>>> and "dev->config_fd".
>>>>
>>>> If we already have these patches, I guess it may be nice to merge
>>>> above patches first.
>>>> Do you have a suggestion how to merge patches related with pci config fd?
>>>>
>>>> Thanks,
>>>> Tetsuya
>>>>
>>> Yeah, that is the patch. It reopens config fd, it seems to overlap
>>> this.
>> Hi Stephen, David, Bernard,
>>
>> If you are OK, I will cherry pick below Stephen's patch, then put it on top of my patches.
>> - http://dpdk.org/dev/patchwork/patch/3024/
>>
>> Also I will write patches to merge following fds.
>>  - dev->config_fd
>>  - dev->intr_handle->uio_cfg_fd
>>  - dev->intr_handle->vfio_cfg_fd
>>
>> Is this direction OK?
>>
>>
>> Stephen,
>>
>> For uio, I guess it will be OK that I just replace pread/pwrite by your APIs.
>> But for vfio, I need to write a function to wrap vfio ioctl.
>> May be rte_eal_pci_ioctl_config()?
>> And replace all vfio ioctls by the function.
>> Is this correct way to adopt your APIs for vfio?
>>
>> Regards,
>> Tetsuya
> Hi Tetsuya,
>
> It would be better not to broaden the scope of the BSD cleanup patch set at this point.
> It would be better to have a separate patch set  to apply Stephen's changes to the BSD code base.
> Also, discussion is still ongoing on Stephen's changes so it might be better to wait until the discussion is completed.

Hi Bernard,

Thanks for comments. I will focus on BSD thing.

Regards,
Tetsuya

> Regards,
>
> Bernard.
>
>
>

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

* Re: [dpdk-dev] [PATCH v2 5/6] eal: Use map_idx in pci_uio_map_resource() of bsdapp to work same as linuxapp
  2015-03-26 10:41                 ` Iremonger, Bernard
@ 2015-03-27  8:19                   ` Tetsuya Mukawa
  0 siblings, 0 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-27  8:19 UTC (permalink / raw)
  To: Iremonger, Bernard, dev

On 2015/03/26 19:41, Iremonger, Bernard wrote:
>
>> -----Original Message-----
>> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
>> Sent: Thursday, March 26, 2015 2:51 AM
>> To: Iremonger, Bernard; dev@dpdk.org
>> Cc: Richardson, Bruce; david.marchand@6wind.com
>> Subject: Re: [PATCH v2 5/6] eal: Use map_idx in pci_uio_map_resource() of bsdapp to work same as
>> linuxapp
>>
>> On 2015/03/26 0:27, Iremonger, Bernard wrote:
>>>> -----Original Message-----
>>>> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
>>>> Sent: Tuesday, March 24, 2015 4:19 AM
>>>> To: dev@dpdk.org
>>>> Cc: Iremonger, Bernard; Richardson, Bruce; david.marchand@6wind.com;
>>>> Tetsuya Mukawa
>>>> Subject: [PATCH v2 5/6] eal: Use map_idx in pci_uio_map_resource() of
>>>> bsdapp to work same as linuxapp
>>>>
>>>> This patch changes code that maps pci resources in bsdapp.
>>>> Linuxapp has almost same code. To consolidate both, fix
>>>> implementation of bsdapp to work same as linuxapp.
>>>>
>>>> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
>>>> ---
>>>>  lib/librte_eal/bsdapp/eal/eal_pci.c | 24 ++++++++++++------------
>>>>  1 file changed, 12 insertions(+), 12 deletions(-)
>>>>
>>>> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c
>>>> b/lib/librte_eal/bsdapp/eal/eal_pci.c
>>>> index 85f8671..08b91b4 100644
>>>> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
>>>> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
>>>> @@ -195,7 +195,7 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
>>>> static int pci_uio_map_resource(struct rte_pci_device *dev)  {
>>>> -	int i, j;
>>>> +	int i, map_idx;
>>>>  	char devname[PATH_MAX]; /* contains the /dev/uioX */
>>>>  	void *mapaddr;
>>>>  	uint64_t phaddr;
>>>> @@ -247,31 +247,31 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>>>>  	pagesz = sysconf(_SC_PAGESIZE);
>>>>
>>>>  	maps = uio_res->maps;
>>>> -	for (i = uio_res->nb_maps = 0; i != PCI_MAX_RESOURCE; i++) {
>>>> +	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
>>>>
>>>> -		j = uio_res->nb_maps;
>>>>  		/* skip empty BAR */
>>>>  		if ((phaddr = dev->mem_resource[i].phys_addr) == 0)
>>>>  			continue;
>>>>
>>>>  		/* if matching map is found, then use it */
>>>>  		offset = i * pagesz;
>>>> -		maps[j].offset = offset;
>>>> -		maps[j].phaddr = dev->mem_resource[i].phys_addr;
>>>> -		maps[j].size = dev->mem_resource[i].len;
>>>> -		if (maps[j].addr != NULL ||
>>>> -		    (mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
>>>> -						(size_t)maps[j].size)
>>>> -		    ) == NULL) {
>>>> +		maps[map_idx].offset = offset;
>>>> +		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
>>>> +		maps[map_idx].size = dev->mem_resource[i].len;
>>>> +		mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
>>>> +					(size_t)maps[map_idx].size);
>>>> +		if ((maps[map_idx].addr != NULL) || (mapaddr == NULL)) {
>>> Hi Tetsuya,
>>>
>>> Should be checking for  if  (mapaddr == MAP_FAILED) here.
>>> Seems to be fixed in patch 6/6 though.
>> Hi Bernard,
>>
>> Here, bsdapp still has old pci_map_resource().
>> Old pci_map_resource() return NULL when mapping is failed.
>> And this behavior will be changed in 6/6. This is why MAP_FAILED is checked in 6/6.
>>
>> Regards,
>> Tetsuya
>>
> Hi Tetsuya,
>
> Would it make sense to squash patches 5/6 and 6/6 ?

Hi Bernard,

I don't have strong opinion about it.
So let's squash patches. And then if you feel to want to split it again,
let me know.

Regards,
Tetsuya

>
> Regards,
>
> Bernard.
>

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

* [dpdk-dev] [PATCH v3 0/5] Clean up pci uio implementations
  2015-03-17  9:30       ` [dpdk-dev] [PATCH 6/6] eal: Fix interface of pci_map_resource() Tetsuya Mukawa
  2015-03-20  9:53         ` Iremonger, Bernard
  2015-03-24  4:18         ` [dpdk-dev] [PATCH v2 0/6] Clean up pci uio implementations Tetsuya Mukawa
@ 2015-03-27  8:39         ` Tetsuya Mukawa
  2015-03-27  8:39           ` [dpdk-dev] [PATCH v3 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
                             ` (5 more replies)
  2 siblings, 6 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-27  8:39 UTC (permalink / raw)
  To: dev

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

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

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

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



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

 lib/librte_eal/bsdapp/eal/eal_pci.c        | 166 +++++++++++++++++------------
 lib/librte_eal/linuxapp/eal/eal_pci_init.h |   1 -
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c  |  91 +++++++++-------
 3 files changed, 154 insertions(+), 104 deletions(-)

-- 
1.9.1

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

* [dpdk-dev] [PATCH v3 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c
  2015-03-27  8:39         ` [dpdk-dev] [PATCH v3 0/5] Clean up pci uio implementations Tetsuya Mukawa
@ 2015-03-27  8:39           ` Tetsuya Mukawa
  2015-03-27  8:39           ` [dpdk-dev] [PATCH v3 2/5] eal: Close file descriptor of uio configuration Tetsuya Mukawa
                             ` (4 subsequent siblings)
  5 siblings, 0 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-27  8:39 UTC (permalink / raw)
  To: dev

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

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

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

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

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

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

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

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

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

* [dpdk-dev] [PATCH v3 3/5] eal: Fix memory leaks and needless increment of pci_map_addr
  2015-03-27  8:39         ` [dpdk-dev] [PATCH v3 0/5] Clean up pci uio implementations Tetsuya Mukawa
  2015-03-27  8:39           ` [dpdk-dev] [PATCH v3 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
  2015-03-27  8:39           ` [dpdk-dev] [PATCH v3 2/5] eal: Close file descriptor of uio configuration Tetsuya Mukawa
@ 2015-03-27  8:39           ` Tetsuya Mukawa
  2015-03-27  8:39           ` [dpdk-dev] [PATCH v3 4/5] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
                             ` (2 subsequent siblings)
  5 siblings, 0 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-27  8:39 UTC (permalink / raw)
  To: dev

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

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

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

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 3a22b49..b5319d9 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -235,7 +235,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) == NULL) {
 		RTE_LOG(ERR, EAL,
 			"%s(): cannot store uio mmap details\n", __func__);
-		return -1;
+		goto close_fd;
 	}
 
 	snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
@@ -262,8 +262,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 		    (mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
 						(size_t)maps[j].size)
 		    ) == NULL) {
-			rte_free(uio_res);
-			return -1;
+			goto free_uio_res;
 		}
 
 		maps[j].addr = mapaddr;
@@ -274,6 +273,17 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
 
 	return 0;
+
+free_uio_res:
+	for (i = 0; i < map_idx; i++)
+		rte_free(maps[i].path);
+	rte_free(uio_res);
+close_fd:
+	close(dev->intr_handle.fd);
+	dev->intr_handle.fd = -1;
+	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+
+	return -1;
 }
 
 /* Scan one pci sysfs entry, and fill the devices list from it. */
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index f0277be..bf8c7fe 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -309,13 +309,13 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	if (dev->intr_handle.uio_cfg_fd < 0) {
 		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
 			cfgname, strerror(errno));
-		return -1;
+		goto close_fd;
 	}
 
 	/* set bus master that is not done by uio_pci_generic */
 	if (pci_uio_set_bus_master(dev->intr_handle.uio_cfg_fd)) {
 		RTE_LOG(ERR, EAL, "Cannot set up bus mastering!\n");
-		return -1;
+		goto close_fd;
 	}
 
 	/* allocate the mapping details for secondary processes*/
@@ -323,7 +323,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	if (uio_res == NULL) {
 		RTE_LOG(ERR, EAL,
 			"%s(): cannot store uio mmap details\n", __func__);
-		return -1;
+		goto close_fd;
 	}
 
 	snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
@@ -333,7 +333,6 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	maps = uio_res->maps;
 	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
 		int fd;
-		int fail = 0;
 
 		/* skip empty BAR */
 		phaddr = dev->mem_resource[i].phys_addr;
@@ -347,6 +346,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 				loc->domain, loc->bus, loc->devid, loc->function,
 				i);
 
+		/* allocate memory to keep path */
+		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
+		if (maps[map_idx].path == NULL)
+			goto free_uio_res;
+
 		/*
 		 * open resource file, to mmap it
 		 */
@@ -354,7 +358,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 		if (fd < 0) {
 			RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
 					devname, strerror(errno));
-			return -1;
+			rte_free(maps[map_idx].path);
+			goto free_uio_res;
 		}
 
 		/* try mapping somewhere close to the end of hugepages */
@@ -363,23 +368,15 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 		mapaddr = pci_map_resource(pci_map_addr, fd, 0,
 				(size_t)dev->mem_resource[i].len, 0);
-		if (mapaddr == MAP_FAILED)
-			fail = 1;
+		close(fd);
+		if (mapaddr == MAP_FAILED) {
+			rte_free(maps[map_idx].path);
+			goto free_uio_res;
+		}
 
 		pci_map_addr = RTE_PTR_ADD(mapaddr,
 				(size_t)dev->mem_resource[i].len);
 
-		maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
-		if (maps[map_idx].path == NULL)
-			fail = 1;
-
-		if (fail) {
-			rte_free(uio_res);
-			close(fd);
-			return -1;
-		}
-		close(fd);
-
 		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
 		maps[map_idx].size = dev->mem_resource[i].len;
 		maps[map_idx].addr = mapaddr;
@@ -394,6 +391,22 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
 
 	return 0;
+
+free_uio_res:
+	for (i = 0; i < map_idx; i++)
+		rte_free(maps[i].path);
+	rte_free(uio_res);
+close_fd:
+	if (dev->intr_handle.uio_cfg_fd >= 0) {
+		close(dev->intr_handle.uio_cfg_fd);
+		dev->intr_handle.uio_cfg_fd = -1;
+	}
+
+	close(dev->intr_handle.fd);
+	dev->intr_handle.fd = -1;
+	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+
+	return -1;
 }
 
 #ifdef RTE_LIBRTE_EAL_HOTPLUG
@@ -405,9 +418,11 @@ pci_uio_unmap(struct mapped_pci_resource *uio_res)
 	if (uio_res == NULL)
 		return;
 
-	for (i = 0; i != uio_res->nb_maps; i++)
+	for (i = 0; i != uio_res->nb_maps; i++) {
 		pci_unmap_resource(uio_res->maps[i].addr,
 				(size_t)uio_res->maps[i].size);
+		rte_free(uio_res->maps[i].path);
+	}
 }
 
 static struct mapped_pci_resource *
-- 
1.9.1

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

* [dpdk-dev] [PATCH v3 4/5] eal/bsdapp: Change names of pci related data structure
  2015-03-27  8:39         ` [dpdk-dev] [PATCH v3 0/5] Clean up pci uio implementations Tetsuya Mukawa
                             ` (2 preceding siblings ...)
  2015-03-27  8:39           ` [dpdk-dev] [PATCH v3 3/5] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
@ 2015-03-27  8:39           ` Tetsuya Mukawa
  2015-03-27  8:39           ` [dpdk-dev] [PATCH v3 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp Tetsuya Mukawa
  2015-04-21 13:15           ` [dpdk-dev] [PATCH v3 0/5] Clean up pci uio implementations Iremonger, Bernard
  5 siblings, 0 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-27  8:39 UTC (permalink / raw)
  To: dev

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

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

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

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

* [dpdk-dev] [PATCH v3 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp
  2015-03-27  8:39         ` [dpdk-dev] [PATCH v3 0/5] Clean up pci uio implementations Tetsuya Mukawa
                             ` (3 preceding siblings ...)
  2015-03-27  8:39           ` [dpdk-dev] [PATCH v3 4/5] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
@ 2015-03-27  8:39           ` Tetsuya Mukawa
  2015-04-21 13:15           ` [dpdk-dev] [PATCH v3 0/5] Clean up pci uio implementations Iremonger, Bernard
  5 siblings, 0 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-03-27  8:39 UTC (permalink / raw)
  To: dev

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

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

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c        | 118 +++++++++++++++++------------
 lib/librte_eal/linuxapp/eal/eal_pci_init.h |   1 -
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c  |  22 +++---
 3 files changed, 78 insertions(+), 63 deletions(-)

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

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

* Re: [dpdk-dev] [PATCH v3 0/5] Clean up pci uio implementations
  2015-03-27  8:39         ` [dpdk-dev] [PATCH v3 0/5] Clean up pci uio implementations Tetsuya Mukawa
                             ` (4 preceding siblings ...)
  2015-03-27  8:39           ` [dpdk-dev] [PATCH v3 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp Tetsuya Mukawa
@ 2015-04-21 13:15           ` Iremonger, Bernard
  2015-04-23  4:23             ` Tetsuya Mukawa
  5 siblings, 1 reply; 87+ messages in thread
From: Iremonger, Bernard @ 2015-04-21 13:15 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev

> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Friday, March 27, 2015 8:39 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; Richardson, Bruce; david.marchand@6wind.com; Tetsuya Mukawa
> Subject: [PATCH v3 0/5] Clean up pci uio implementations
> 
> This patch set cleans up pci uio implementation. These clean up are for consolidating pci uio
> implementation of linuxapp and bsdapp, and moving consolidated functions in eal common.
> Because of above, this patch set tries to implement linuxapp and bsdapp almost same.
> Actual consolidations will be done later patch set.
> 
> PATCH v3 changes:
>  - Squash patches related with pci_map_resource().
>  - Free maps[].path to easy to understand.
>    (Thanks to Iremonger, Bernard)
>  - Close fds opened in this function.
>  - Remove unused path variable from mapped_pci_resource structure.
> 
> PATCH v2 changes:
>  - Move 'if-condition' to later patch series.
>  - Fix memory leaks of path.
>  - Fix typos.
>    (Thanks to David Marchand)
>  - Fix commit title and body.
>  - Fix pci_map_resource() to handle MAP_FAILED.
>    (Thanks to Iremonger, Bernard)
> 
> Changes:
>  - This patch set is derived from below.
>    "[PATCH v2] eal: Port Hotplug support for BSD"
>  - Set cfg_fd as -1, when cfg_fd is closed.
>    (Thanks to Iremonger, Bernard)
>  - Remove needless coding style fixings.
>  - Fix coding style of if-else condition.
>    (Thanks to Richardson, Bruce)
> 
> 
> 
> Tetsuya Mukawa (5):
>   eal: Fix coding style of eal_pci.c and eal_pci_uio.c
>   eal: Close file descriptor of uio configuration
>   eal: Fix memory leaks and needless increment of pci_map_addr
>   eal/bsdapp: Change names of pci related data structure
>   eal: Fix uio mapping differences between linuxapp and bsdapp
> 
>  lib/librte_eal/bsdapp/eal/eal_pci.c        | 166 +++++++++++++++++------------
>  lib/librte_eal/linuxapp/eal/eal_pci_init.h |   1 -
>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c  |  91 +++++++++-------
>  3 files changed, 154 insertions(+), 104 deletions(-)
> 
> --
> 1.9.1
Series
Acked-by: Bernard Iremonger <bernard.iremonger@intel.com>

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

* Re: [dpdk-dev] [PATCH v3 0/5] Clean up pci uio implementations
  2015-04-21 13:15           ` [dpdk-dev] [PATCH v3 0/5] Clean up pci uio implementations Iremonger, Bernard
@ 2015-04-23  4:23             ` Tetsuya Mukawa
  2015-04-23  8:12               ` Iremonger, Bernard
  0 siblings, 1 reply; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-04-23  4:23 UTC (permalink / raw)
  To: Iremonger, Bernard, dev

On 2015/04/21 22:15, Iremonger, Bernard wrote:
>> -----Original Message-----
>> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
>> Sent: Friday, March 27, 2015 8:39 AM
>> To: dev@dpdk.org
>> Cc: Iremonger, Bernard; Richardson, Bruce; david.marchand@6wind.com; Tetsuya Mukawa
>> Subject: [PATCH v3 0/5] Clean up pci uio implementations
>>
>> This patch set cleans up pci uio implementation. These clean up are for consolidating pci uio
>> implementation of linuxapp and bsdapp, and moving consolidated functions in eal common.
>> Because of above, this patch set tries to implement linuxapp and bsdapp almost same.
>> Actual consolidations will be done later patch set.
>>
>> PATCH v3 changes:
>>  - Squash patches related with pci_map_resource().
>>  - Free maps[].path to easy to understand.
>>    (Thanks to Iremonger, Bernard)
>>  - Close fds opened in this function.
>>  - Remove unused path variable from mapped_pci_resource structure.
>>
>> PATCH v2 changes:
>>  - Move 'if-condition' to later patch series.
>>  - Fix memory leaks of path.
>>  - Fix typos.
>>    (Thanks to David Marchand)
>>  - Fix commit title and body.
>>  - Fix pci_map_resource() to handle MAP_FAILED.
>>    (Thanks to Iremonger, Bernard)
>>
>> Changes:
>>  - This patch set is derived from below.
>>    "[PATCH v2] eal: Port Hotplug support for BSD"
>>  - Set cfg_fd as -1, when cfg_fd is closed.
>>    (Thanks to Iremonger, Bernard)
>>  - Remove needless coding style fixings.
>>  - Fix coding style of if-else condition.
>>    (Thanks to Richardson, Bruce)
>>
>>
>>
>> Tetsuya Mukawa (5):
>>   eal: Fix coding style of eal_pci.c and eal_pci_uio.c
>>   eal: Close file descriptor of uio configuration
>>   eal: Fix memory leaks and needless increment of pci_map_addr
>>   eal/bsdapp: Change names of pci related data structure
>>   eal: Fix uio mapping differences between linuxapp and bsdapp
>>
>>  lib/librte_eal/bsdapp/eal/eal_pci.c        | 166 +++++++++++++++++------------
>>  lib/librte_eal/linuxapp/eal/eal_pci_init.h |   1 -
>>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c  |  91 +++++++++-------
>>  3 files changed, 154 insertions(+), 104 deletions(-)
>>
>> --
>> 1.9.1
> Series
> Acked-by: Bernard Iremonger <bernard.iremonger@intel.com>
Hi Bernard,

Thanks for your checking.
It seems I need to rebase this patches for latest matser branch.
So I will update and submit it soon.

Regards,
Tetsuya

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

* Re: [dpdk-dev] [PATCH v3 0/5] Clean up pci uio implementations
  2015-04-23  4:23             ` Tetsuya Mukawa
@ 2015-04-23  8:12               ` Iremonger, Bernard
  2015-04-23  9:48                 ` Tetsuya Mukawa
  0 siblings, 1 reply; 87+ messages in thread
From: Iremonger, Bernard @ 2015-04-23  8:12 UTC (permalink / raw)
  To: Tetsuya Mukawa, dev



> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Thursday, April 23, 2015 5:24 AM
> To: Iremonger, Bernard; dev@dpdk.org
> Cc: Richardson, Bruce; david.marchand@6wind.com
> Subject: Re: [PATCH v3 0/5] Clean up pci uio implementations
> 
> On 2015/04/21 22:15, Iremonger, Bernard wrote:
> >> -----Original Message-----
> >> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> >> Sent: Friday, March 27, 2015 8:39 AM
> >> To: dev@dpdk.org
> >> Cc: Iremonger, Bernard; Richardson, Bruce; david.marchand@6wind.com;
> >> Tetsuya Mukawa
> >> Subject: [PATCH v3 0/5] Clean up pci uio implementations
> >>
> >> This patch set cleans up pci uio implementation. These clean up are
> >> for consolidating pci uio implementation of linuxapp and bsdapp, and moving consolidated
> functions in eal common.
> >> Because of above, this patch set tries to implement linuxapp and bsdapp almost same.
> >> Actual consolidations will be done later patch set.
> >>
> >> PATCH v3 changes:
> >>  - Squash patches related with pci_map_resource().
> >>  - Free maps[].path to easy to understand.
> >>    (Thanks to Iremonger, Bernard)
> >>  - Close fds opened in this function.
> >>  - Remove unused path variable from mapped_pci_resource structure.
> >>
> >> PATCH v2 changes:
> >>  - Move 'if-condition' to later patch series.
> >>  - Fix memory leaks of path.
> >>  - Fix typos.
> >>    (Thanks to David Marchand)
> >>  - Fix commit title and body.
> >>  - Fix pci_map_resource() to handle MAP_FAILED.
> >>    (Thanks to Iremonger, Bernard)
> >>
> >> Changes:
> >>  - This patch set is derived from below.
> >>    "[PATCH v2] eal: Port Hotplug support for BSD"
> >>  - Set cfg_fd as -1, when cfg_fd is closed.
> >>    (Thanks to Iremonger, Bernard)
> >>  - Remove needless coding style fixings.
> >>  - Fix coding style of if-else condition.
> >>    (Thanks to Richardson, Bruce)
> >>
> >>
> >>
> >> Tetsuya Mukawa (5):
> >>   eal: Fix coding style of eal_pci.c and eal_pci_uio.c
> >>   eal: Close file descriptor of uio configuration
> >>   eal: Fix memory leaks and needless increment of pci_map_addr
> >>   eal/bsdapp: Change names of pci related data structure
> >>   eal: Fix uio mapping differences between linuxapp and bsdapp
> >>
> >>  lib/librte_eal/bsdapp/eal/eal_pci.c        | 166 +++++++++++++++++------------
> >>  lib/librte_eal/linuxapp/eal/eal_pci_init.h |   1 -
> >>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c  |  91 +++++++++-------
> >>  3 files changed, 154 insertions(+), 104 deletions(-)
> >>
> >> --
> >> 1.9.1
> > Series
> > Acked-by: Bernard Iremonger <bernard.iremonger@intel.com>
> Hi Bernard,
> 
> Thanks for your checking.
> It seems I need to rebase this patches for latest matser branch.
> So I will update and submit it soon.
> 
> Regards,
> Tetsuya

Hi Tetsuya,
I applied the v3 patches to the latest master branch on Monday last and there were no issues.
The patches built cleanly on Linux and Free BSD.

Regards,

Bernard.
 

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

* Re: [dpdk-dev] [PATCH v3 0/5] Clean up pci uio implementations
  2015-04-23  8:12               ` Iremonger, Bernard
@ 2015-04-23  9:48                 ` Tetsuya Mukawa
  0 siblings, 0 replies; 87+ messages in thread
From: Tetsuya Mukawa @ 2015-04-23  9:48 UTC (permalink / raw)
  To: Iremonger, Bernard, dev

On 2015/04/23 17:12, Iremonger, Bernard wrote:
>
>> -----Original Message-----
>> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
>> Sent: Thursday, April 23, 2015 5:24 AM
>> To: Iremonger, Bernard; dev@dpdk.org
>> Cc: Richardson, Bruce; david.marchand@6wind.com
>> Subject: Re: [PATCH v3 0/5] Clean up pci uio implementations
>>
>> On 2015/04/21 22:15, Iremonger, Bernard wrote:
>>>> -----Original Message-----
>>>> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
>>>> Sent: Friday, March 27, 2015 8:39 AM
>>>> To: dev@dpdk.org
>>>> Cc: Iremonger, Bernard; Richardson, Bruce; david.marchand@6wind.com;
>>>> Tetsuya Mukawa
>>>> Subject: [PATCH v3 0/5] Clean up pci uio implementations
>>>>
>>>> This patch set cleans up pci uio implementation. These clean up are
>>>> for consolidating pci uio implementation of linuxapp and bsdapp, and moving consolidated
>> functions in eal common.
>>>> Because of above, this patch set tries to implement linuxapp and bsdapp almost same.
>>>> Actual consolidations will be done later patch set.
>>>>
>>>> PATCH v3 changes:
>>>>  - Squash patches related with pci_map_resource().
>>>>  - Free maps[].path to easy to understand.
>>>>    (Thanks to Iremonger, Bernard)
>>>>  - Close fds opened in this function.
>>>>  - Remove unused path variable from mapped_pci_resource structure.
>>>>
>>>> PATCH v2 changes:
>>>>  - Move 'if-condition' to later patch series.
>>>>  - Fix memory leaks of path.
>>>>  - Fix typos.
>>>>    (Thanks to David Marchand)
>>>>  - Fix commit title and body.
>>>>  - Fix pci_map_resource() to handle MAP_FAILED.
>>>>    (Thanks to Iremonger, Bernard)
>>>>
>>>> Changes:
>>>>  - This patch set is derived from below.
>>>>    "[PATCH v2] eal: Port Hotplug support for BSD"
>>>>  - Set cfg_fd as -1, when cfg_fd is closed.
>>>>    (Thanks to Iremonger, Bernard)
>>>>  - Remove needless coding style fixings.
>>>>  - Fix coding style of if-else condition.
>>>>    (Thanks to Richardson, Bruce)
>>>>
>>>>
>>>>
>>>> Tetsuya Mukawa (5):
>>>>   eal: Fix coding style of eal_pci.c and eal_pci_uio.c
>>>>   eal: Close file descriptor of uio configuration
>>>>   eal: Fix memory leaks and needless increment of pci_map_addr
>>>>   eal/bsdapp: Change names of pci related data structure
>>>>   eal: Fix uio mapping differences between linuxapp and bsdapp
>>>>
>>>>  lib/librte_eal/bsdapp/eal/eal_pci.c        | 166 +++++++++++++++++------------
>>>>  lib/librte_eal/linuxapp/eal/eal_pci_init.h |   1 -
>>>>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c  |  91 +++++++++-------
>>>>  3 files changed, 154 insertions(+), 104 deletions(-)
>>>>
>>>> --
>>>> 1.9.1
>>> Series
>>> Acked-by: Bernard Iremonger <bernard.iremonger@intel.com>
>> Hi Bernard,
>>
>> Thanks for your checking.
>> It seems I need to rebase this patches for latest matser branch.
>> So I will update and submit it soon.
>>
>> Regards,
>> Tetsuya
> Hi Tetsuya,
> I applied the v3 patches to the latest master branch on Monday last and there were no issues.
> The patches built cleanly on Linux and Free BSD.
>
> Regards,
>
> Bernard.
>  

Hi Bernard,

Thanks. I made sure I could apply my patches to latest.
I will prepare bottom half of port hotplug patches for BSD.

Regards,
Tetsuya

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

end of thread, other threads:[~2015-04-23  9:48 UTC | newest]

Thread overview: 87+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-04  3:11 [dpdk-dev] [PATCH 1/3] BSD: Support Port Hotplug function Tetsuya Mukawa
2015-03-04  3:11 ` [dpdk-dev] [PATCH 2/3] eal, ethdev: Remove CONFIG_RTE_LIBRTE_EAL_HOTPLUG Tetsuya Mukawa
2015-03-04  3:11 ` [dpdk-dev] [PATCH 3/3] doc: Remove BSD limitation from hotplug section of programmer's guide Tetsuya Mukawa
2015-03-06 10:32 ` [dpdk-dev] [PATCH 1/3] BSD: Support Port Hotplug function Iremonger, Bernard
2015-03-09  2:23   ` Tetsuya Mukawa
2015-03-12 10:24     ` Tetsuya Mukawa
2015-03-12 10:17 ` [dpdk-dev] [PATCH v2 00/15] eal: Port Hotplug support for BSD Tetsuya Mukawa
2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 01/15] eal: Fix cording style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
2015-03-12 10:48     ` Bruce Richardson
2015-03-12 10:57       ` Qiu, Michael
2015-03-12 11:09         ` Bruce Richardson
2015-03-13  0:25           ` Tetsuya Mukawa
2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 02/15] eal: Close file descriptor of uio configuration Tetsuya Mukawa
2015-03-13 13:54     ` Iremonger, Bernard
2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 03/15] eal: Fix memory leak of pci_uio_map_resource() Tetsuya Mukawa
2015-03-13 14:04     ` Iremonger, Bernard
2015-03-17  9:30     ` [dpdk-dev] [PATCH 0/6] Clean up pci uio implementations Tetsuya Mukawa
2015-03-17  9:30       ` [dpdk-dev] [PATCH 1/6] eal: Fix cording style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
2015-03-18 14:29         ` Bruce Richardson
2015-03-18 15:08         ` David Marchand
2015-03-17  9:30       ` [dpdk-dev] [PATCH 2/6] eal: Close file descriptor of uio configuration Tetsuya Mukawa
2015-03-18 15:19         ` David Marchand
2015-03-20  1:53           ` Tetsuya Mukawa
2015-03-19 16:04         ` Iremonger, Bernard
2015-03-20  1:54           ` Tetsuya Mukawa
2015-03-17  9:30       ` [dpdk-dev] [PATCH 3/6] eal: Fix memory leaks and needless incrementation of pci uio implementation Tetsuya Mukawa
2015-03-18 15:39         ` David Marchand
2015-03-20  1:53           ` Tetsuya Mukawa
2015-03-19 16:20         ` Iremonger, Bernard
2015-03-20  1:54           ` Tetsuya Mukawa
2015-03-17  9:30       ` [dpdk-dev] [PATCH 4/6] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
2015-03-17  9:30       ` [dpdk-dev] [PATCH 5/6] eal: Use map_idx in pci_uio_map_resource() of bsdapp to work same as linuxapp Tetsuya Mukawa
2015-03-17  9:30       ` [dpdk-dev] [PATCH 6/6] eal: Fix interface of pci_map_resource() Tetsuya Mukawa
2015-03-20  9:53         ` Iremonger, Bernard
2015-03-24  4:18           ` Tetsuya Mukawa
2015-03-24  4:18         ` [dpdk-dev] [PATCH v2 0/6] Clean up pci uio implementations Tetsuya Mukawa
2015-03-24  4:18           ` [dpdk-dev] [PATCH v2 1/6] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
2015-03-24  4:18           ` [dpdk-dev] [PATCH v2 2/6] eal: Close file descriptor of uio configuration Tetsuya Mukawa
2015-03-24 18:33             ` Stephen Hemminger
2015-03-25  3:17               ` Tetsuya Mukawa
2015-03-25  5:07                 ` Stephen Hemminger
2015-03-26  4:19                   ` Tetsuya Mukawa
2015-03-26 10:03                     ` Iremonger, Bernard
2015-03-27  6:01                       ` Tetsuya Mukawa
2015-03-24  4:18           ` [dpdk-dev] [PATCH v2 3/6] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
2015-03-25 15:00             ` Iremonger, Bernard
2015-03-26  2:44               ` Tetsuya Mukawa
2015-03-24  4:18           ` [dpdk-dev] [PATCH v2 4/6] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
2015-03-24  4:18           ` [dpdk-dev] [PATCH v2 5/6] eal: Use map_idx in pci_uio_map_resource() of bsdapp to work same as linuxapp Tetsuya Mukawa
2015-03-25 15:27             ` Iremonger, Bernard
2015-03-26  2:50               ` Tetsuya Mukawa
2015-03-26 10:41                 ` Iremonger, Bernard
2015-03-27  8:19                   ` Tetsuya Mukawa
2015-03-24  4:18           ` [dpdk-dev] [PATCH v2 6/6] eal: Fix interface of pci_map_resource() Tetsuya Mukawa
2015-03-25 15:03             ` Iremonger, Bernard
2015-03-27  8:39         ` [dpdk-dev] [PATCH v3 0/5] Clean up pci uio implementations Tetsuya Mukawa
2015-03-27  8:39           ` [dpdk-dev] [PATCH v3 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
2015-03-27  8:39           ` [dpdk-dev] [PATCH v3 2/5] eal: Close file descriptor of uio configuration Tetsuya Mukawa
2015-03-27  8:39           ` [dpdk-dev] [PATCH v3 3/5] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
2015-03-27  8:39           ` [dpdk-dev] [PATCH v3 4/5] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
2015-03-27  8:39           ` [dpdk-dev] [PATCH v3 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp Tetsuya Mukawa
2015-04-21 13:15           ` [dpdk-dev] [PATCH v3 0/5] Clean up pci uio implementations Iremonger, Bernard
2015-04-23  4:23             ` Tetsuya Mukawa
2015-04-23  8:12               ` Iremonger, Bernard
2015-04-23  9:48                 ` Tetsuya Mukawa
2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 04/15] eal: Fix needless incrementation of pci_map_addr Tetsuya Mukawa
2015-03-13 14:49     ` Iremonger, Bernard
2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 05/15] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 06/15] eal: Use map_idx in pci_uio_map_resource() of bsdapp to work same as linuxapp Tetsuya Mukawa
2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 07/15] eal: Fix interface of pci_map_resource() of bsdapp Tetsuya Mukawa
2015-03-12 11:04     ` Bruce Richardson
2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 08/15] eal: Add pci_uio_alloc_uio_resource() Tetsuya Mukawa
2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 09/15] eal: Add pci_uio_map_uio_resource_by_index() Tetsuya Mukawa
2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 10/15] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp Tetsuya Mukawa
2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 11/15] eal: Consolidate rte_eal_pci_probe/close_one_driver() " Tetsuya Mukawa
2015-03-13 15:03     ` Iremonger, Bernard
2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 12/15] eal: Consolidate pci_map/unmap_device() " Tetsuya Mukawa
2015-03-13 15:10     ` Iremonger, Bernard
2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 13/15] eal: Consolidate pci_map/unmap_resource() " Tetsuya Mukawa
2015-03-13 15:23     ` Iremonger, Bernard
2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 14/15] eal: Consolidate pci uio functions " Tetsuya Mukawa
2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 15/15] eal: Enable Port Hotplug as default in Linux and BSD Tetsuya Mukawa
2015-03-13 15:47     ` Iremonger, Bernard
2015-03-17  8:08       ` Tetsuya Mukawa
2015-03-19 11:41         ` Iremonger, Bernard
2015-03-13 11:46   ` [dpdk-dev] [PATCH v2 00/15] eal: Port Hotplug support for BSD Iremonger, Bernard
2015-03-16  3:36     ` Tetsuya Mukawa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).