[dpdk-dev,v7,11/12] eal: Consolidate pci_map/unmap_device() of linuxapp and bsdapp

Message ID 1435652668-3380-12-git-send-email-mukawa@igel.co.jp (mailing list archive)
State Superseded, archived
Headers

Commit Message

Tetsuya Mukawa June 30, 2015, 8:24 a.m. UTC
  From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>

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

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

Comments

Iremonger, Bernard June 30, 2015, 2:45 p.m. UTC | #1
> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Tuesday, June 30, 2015 9:24 AM
> To: dev@dpdk.org
> Cc: Iremonger, Bernard; david.marchand@6wind.com; Richardson, Bruce;
> Tetsuya.Mukawa
> Subject: [PATCH v7 11/12] eal: Consolidate pci_map/unmap_device() of
> linuxapp and bsdapp
> 
> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
> 
> The patch consolidates below functions, and implemented in common eal
> code.
>  - pci_map_device()
>  - pci_unmap_device()
> 
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
Acked-by: Bernard Iremonger <Bernard.iremonger@intel.com>
  
Tetsuya Mukawa July 6, 2015, 6:24 a.m. UTC | #2
Currently Linux implementation and BSD implementation have almost same
code about pci uio. This patch series cleans up it.

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

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

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

PATCH v5 changes:
 - Rebase to latest master branch.

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

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

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

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


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

 lib/librte_eal/bsdapp/eal/Makefile                 |   2 +
 lib/librte_eal/bsdapp/eal/eal_pci.c                | 293 ++++++---------------
 .../bsdapp/eal/include/exec-env/rte_interrupts.h   |   2 +
 lib/librte_eal/common/eal_common_pci.c             | 226 ++++++++++++++++
 lib/librte_eal/common/eal_common_pci_uio.c         | 240 +++++++++++++++++
 lib/librte_eal/common/eal_private.h                |  60 ++++-
 lib/librte_eal/common/include/rte_pci.h            |  62 +++++
 lib/librte_eal/linuxapp/eal/Makefile               |   2 +
 lib/librte_eal/linuxapp/eal/eal_pci.c              | 237 +----------------
 lib/librte_eal/linuxapp/eal/eal_pci_init.h         |  40 +--
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c          | 293 +++++++--------------
 lib/librte_ether/rte_ethdev.c                      |   2 +
 12 files changed, 761 insertions(+), 698 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_pci_uio.c
  
Tetsuya Mukawa July 8, 2015, 10:34 a.m. UTC | #3
Currently Linux implementation and BSD implementation have almost same
code about pci uio. This patch series cleans up it.

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

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

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

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

PATCH v5 changes:
 - Rebase to latest master branch.

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

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

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

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


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

 lib/librte_eal/bsdapp/eal/Makefile                 |   2 +
 lib/librte_eal/bsdapp/eal/eal_pci.c                | 283 ++++++--------------
 .../bsdapp/eal/include/exec-env/rte_interrupts.h   |   2 +
 lib/librte_eal/common/eal_common_pci.c             | 226 ++++++++++++++++
 lib/librte_eal/common/eal_common_pci_uio.c         | 225 ++++++++++++++++
 lib/librte_eal/common/eal_private.h                |  73 ++++-
 lib/librte_eal/common/include/rte_pci.h            |  62 +++++
 lib/librte_eal/linuxapp/eal/Makefile               |   2 +
 lib/librte_eal/linuxapp/eal/eal_pci.c              | 237 +----------------
 lib/librte_eal/linuxapp/eal/eal_pci_init.h         |  42 +--
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c          | 296 +++++++--------------
 lib/librte_ether/rte_ethdev.c                      |   2 +
 12 files changed, 760 insertions(+), 692 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_pci_uio.c
  
David Marchand July 8, 2015, 12:36 p.m. UTC | #4
On Wed, Jul 8, 2015 at 12:34 PM, Tetsuya Mukawa <mukawa@igel.co.jp> wrote:

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

Thanks for this big cleanup Tetsuya.
  
Thomas Monjalon July 8, 2015, 9:52 p.m. UTC | #5
> > Currently Linux implementation and BSD implementation have almost same
> > code about pci uio. This patch series cleans up it.
> >
> > PATCH v9 changes:
> >  - Add lost Acked-by and Tested-by signatures.
> >  - Remove NULL checkings before calling rte_free().
> >  - Fix pci_uio_map_secondary() to remove needless close().
> >  - Remove needless parameter checkings of pci_uio_alloc_resource() and
> >    pci_uio_map_resource_by_index().
> >  - Remove needless error checking for return value of
> > pci_uio_alloc_resource().
> >  - Introduce pci_uio_free_resource().
> >  - Remove some comments of pci_uio_map_resource().
> >    (Thanks to David Marchand)
> >
> Acked-by: David Marchand <david.marchand@6wind.com>

Applied, thanks

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

Patch

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