All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] Generalize PCI specific EAL function/structures
@ 2016-09-01  4:41 Shreyansh Jain
  2016-09-01  4:41 ` [PATCH 1/5] eal: make enum rte_kernel_driver non-PCI specific Shreyansh Jain
                   ` (5 more replies)
  0 siblings, 6 replies; 27+ messages in thread
From: Shreyansh Jain @ 2016-09-01  4:41 UTC (permalink / raw)
  To: viktorin, dev; +Cc: thomas.monjalon, Shreyansh Jain

From: Jan Viktorin <viktorin@rehivetech.com>

(I rebased these over HEAD e228563)

These patches were initially part of Jan's original series on SoC Framework
([1],[2]). An update to that series, without these patches, was posted by me
here [3].

Main motivation for these is aim of introducing a non-PCI centric subsystem
in EAL. As of now the first usecase is SoC, but not limited to it.

5 patches in this series are independent of each other, as well as SoC
framework. All these focus on generalizing some structure or functions
present with the PCI specific code to EAL Common area (or splitting a 
function to be more userful).

 - 0001: move the rte_kernel_driver enum from rte_pci to rte_dev. As of now
   this structure is embedded in rte_pci_device, but, going ahead it can be
   part of other rte_xxx_device structures. Either way, it has no impact on
   PCI.
 - 0002: eal_parse_sysfs_value function has been split into two, one
   accepting filename and other working on a file object. This is helpful if
   multiple calls to this are made from EAL - that way infra can maintain a
   file object.
 - 0003: Functions pci_map_resource/pci_unmap_resource are moved to EAL
   common as rte_eal_map_resource/rte_eal_unmap_resource, respectively.
 - 0004: Split the  pci_unbind_kernel_driver into two, still working on the
   PCI BDF sysfs layout, first handles the file path (and validations) and
   second does the actual unbind. The second part might be useful in case of
   non-PCI layouts.
 - 0005: Move pci_get_kernel_driver_by_path to
   rte_eal_get_kernel_driver_by_path in EAL common. This function is generic
   for any sysfs compliant driver and can be re-used by other non-PCI
   subsystem.

If need be, I can propose them as 5 separate patches - but I think clubbing
them together makes more sense (these are loosely related).

[1] http://dpdk.org/ml/archives/dev/2016-January/030915.html
[2] http://www.dpdk.org/ml/archives/dev/2016-May/038486.html
[3] http://dpdk.org/ml/archives/dev/2016-August/045993.html

Jan Viktorin (5):
  eal: make enum rte_kernel_driver non-PCI specific
  eal: extract function eal_parse_sysfs_valuef
  eal: Convert pci_(un)map_resource to rte_eal_(un)map_resource
  eal/linux: extract function rte_eal_unbind_kernel_driver
  eal/linux: extract function rte_eal_get_kernel_driver_by_path

 lib/librte_eal/bsdapp/eal/eal_pci.c             |  2 +-
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  8 +++
 lib/librte_eal/common/eal_common_dev.c          | 39 +++++++++++
 lib/librte_eal/common/eal_common_pci.c          | 39 -----------
 lib/librte_eal/common/eal_common_pci_uio.c      | 16 +++--
 lib/librte_eal/common/eal_filesystem.h          |  5 ++
 lib/librte_eal/common/eal_private.h             | 27 ++++++++
 lib/librte_eal/common/include/rte_dev.h         | 44 ++++++++++++
 lib/librte_eal/common/include/rte_pci.h         | 41 -----------
 lib/librte_eal/linuxapp/eal/eal.c               | 91 ++++++++++++++++++++++---
 lib/librte_eal/linuxapp/eal/eal_pci.c           | 62 +++--------------
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c       |  2 +-
 lib/librte_eal/linuxapp/eal/eal_pci_vfio.c      |  5 +-
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  8 +++
 14 files changed, 234 insertions(+), 155 deletions(-)

-- 
2.7.4

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

* [PATCH 1/5] eal: make enum rte_kernel_driver non-PCI specific
  2016-09-01  4:41 [PATCH 0/5] Generalize PCI specific EAL function/structures Shreyansh Jain
@ 2016-09-01  4:41 ` Shreyansh Jain
  2016-09-11 12:15   ` Yuanhan Liu
  2016-09-01  4:41 ` [PATCH 2/5] eal: extract function eal_parse_sysfs_valuef Shreyansh Jain
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 27+ messages in thread
From: Shreyansh Jain @ 2016-09-01  4:41 UTC (permalink / raw)
  To: viktorin, dev; +Cc: thomas.monjalon, Shreyansh Jain

From: Jan Viktorin <viktorin@rehivetech.com>

From: Jan Viktorin <viktorin@rehivetech.com>

Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/common/include/rte_dev.h | 12 ++++++++++++
 lib/librte_eal/common/include/rte_pci.h |  9 ---------
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h
index 95789f9..60bc91d 100644
--- a/lib/librte_eal/common/include/rte_dev.h
+++ b/lib/librte_eal/common/include/rte_dev.h
@@ -101,6 +101,18 @@ rte_pmd_debug_trace(const char *func_name, const char *fmt, ...)
 } while (0)
 
 
+/**
+ * Kernel driver passthrough type
+ */
+enum rte_kernel_driver {
+	RTE_KDRV_UNKNOWN = 0,
+	RTE_KDRV_IGB_UIO,
+	RTE_KDRV_VFIO,
+	RTE_KDRV_UIO_GENERIC,
+	RTE_KDRV_NIC_UIO,
+	RTE_KDRV_NONE,
+};
+
 /** Double linked list of device drivers. */
 TAILQ_HEAD(rte_driver_list, rte_driver);
 
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index fa74962..a4c8156 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -141,15 +141,6 @@ struct rte_pci_addr {
 
 struct rte_devargs;
 
-enum rte_kernel_driver {
-	RTE_KDRV_UNKNOWN = 0,
-	RTE_KDRV_IGB_UIO,
-	RTE_KDRV_VFIO,
-	RTE_KDRV_UIO_GENERIC,
-	RTE_KDRV_NIC_UIO,
-	RTE_KDRV_NONE,
-};
-
 /**
  * A structure describing a PCI device.
  */
-- 
2.7.4

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

* [PATCH 2/5] eal: extract function eal_parse_sysfs_valuef
  2016-09-01  4:41 [PATCH 0/5] Generalize PCI specific EAL function/structures Shreyansh Jain
  2016-09-01  4:41 ` [PATCH 1/5] eal: make enum rte_kernel_driver non-PCI specific Shreyansh Jain
@ 2016-09-01  4:41 ` Shreyansh Jain
  2016-09-01  6:30   ` Stephen Hemminger
  2016-09-01  4:41 ` [PATCH 3/5] eal: Convert pci_(un)map_resource to rte_eal_(un)map_resource Shreyansh Jain
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 27+ messages in thread
From: Shreyansh Jain @ 2016-09-01  4:41 UTC (permalink / raw)
  To: viktorin, dev; +Cc: thomas.monjalon, Shreyansh Jain

From: Jan Viktorin <viktorin@rehivetech.com>

From: Jan Viktorin <viktorin@rehivetech.com>

The eal_parse_sysfs_value function accepts a filename however, such
interface introduces race-conditions to the code. Introduce the
variant of this function that accepts an already opened file instead of
a filename.

Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/common/eal_filesystem.h |  5 +++++
 lib/librte_eal/linuxapp/eal/eal.c      | 36 +++++++++++++++++++++++-----------
 2 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/lib/librte_eal/common/eal_filesystem.h b/lib/librte_eal/common/eal_filesystem.h
index fdb4a70..7875454 100644
--- a/lib/librte_eal/common/eal_filesystem.h
+++ b/lib/librte_eal/common/eal_filesystem.h
@@ -43,6 +43,7 @@
 /** Path of rte config file. */
 #define RUNTIME_CONFIG_FMT "%s/.%s_config"
 
+#include <stdio.h>
 #include <stdint.h>
 #include <limits.h>
 #include <unistd.h>
@@ -115,4 +116,8 @@ eal_get_hugefile_temp_path(char *buffer, size_t buflen, const char *hugedir, int
  * Used to read information from files on /sys */
 int eal_parse_sysfs_value(const char *filename, unsigned long *val);
 
+/** Function to read a single numeric value from a file on the filesystem.
+ * Used to read information from files on /sys */
+int eal_parse_sysfs_valuef(FILE *f, unsigned long *val);
+
 #endif /* EAL_FILESYSTEM_H */
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index d5b81a3..f912e4e 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -126,13 +126,30 @@ rte_eal_get_configuration(void)
 	return &rte_config;
 }
 
+int
+eal_parse_sysfs_valuef(FILE *f, unsigned long *val)
+{
+	char buf[BUFSIZ];
+	char *end = NULL;
+
+	RTE_VERIFY(f != NULL);
+
+	if (fgets(buf, sizeof(buf), f) == NULL)
+		return -1;
+
+	*val = strtoul(buf, &end, 0);
+	if ((buf[0] == '\0') || (end == NULL) || (*end != '\n'))
+		return -2;
+
+	return 0;
+}
+
 /* parse a sysfs (or other) file containing one integer value */
 int
 eal_parse_sysfs_value(const char *filename, unsigned long *val)
 {
+	int ret;
 	FILE *f;
-	char buf[BUFSIZ];
-	char *end = NULL;
 
 	if ((f = fopen(filename, "r")) == NULL) {
 		RTE_LOG(ERR, EAL, "%s(): cannot open sysfs value %s\n",
@@ -140,21 +157,18 @@ eal_parse_sysfs_value(const char *filename, unsigned long *val)
 		return -1;
 	}
 
-	if (fgets(buf, sizeof(buf), f) == NULL) {
+	ret = eal_parse_sysfs_valuef(f, val);
+	if (ret == -1) {
 		RTE_LOG(ERR, EAL, "%s(): cannot read sysfs value %s\n",
-			__func__, filename);
-		fclose(f);
-		return -1;
+				__func__, filename);
 	}
-	*val = strtoul(buf, &end, 0);
-	if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) {
+	else if (ret < 0) {
 		RTE_LOG(ERR, EAL, "%s(): cannot parse sysfs value %s\n",
 				__func__, filename);
-		fclose(f);
-		return -1;
 	}
+
 	fclose(f);
-	return 0;
+	return ret;
 }
 
 
-- 
2.7.4

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

* [PATCH 3/5] eal: Convert pci_(un)map_resource to rte_eal_(un)map_resource
  2016-09-01  4:41 [PATCH 0/5] Generalize PCI specific EAL function/structures Shreyansh Jain
  2016-09-01  4:41 ` [PATCH 1/5] eal: make enum rte_kernel_driver non-PCI specific Shreyansh Jain
  2016-09-01  4:41 ` [PATCH 2/5] eal: extract function eal_parse_sysfs_valuef Shreyansh Jain
@ 2016-09-01  4:41 ` Shreyansh Jain
  2016-09-01  4:41 ` [PATCH 4/5] eal/linux: extract function rte_eal_unbind_kernel_driver Shreyansh Jain
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 27+ messages in thread
From: Shreyansh Jain @ 2016-09-01  4:41 UTC (permalink / raw)
  To: viktorin, dev; +Cc: thomas.monjalon, Shreyansh Jain

From: Jan Viktorin <viktorin@rehivetech.com>

From: Jan Viktorin <viktorin@rehivetech.com>

The functions pci_map_resource, pci_unmap_resource are generic so the
pci_* prefix can be omitted. The functions are moved to the
eal_common_dev.c so they can be reused by other infrastructure.

Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c             |  2 +-
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  8 +++++
 lib/librte_eal/common/eal_common_dev.c          | 39 +++++++++++++++++++++++++
 lib/librte_eal/common/eal_common_pci.c          | 39 -------------------------
 lib/librte_eal/common/eal_common_pci_uio.c      | 16 +++++-----
 lib/librte_eal/common/include/rte_dev.h         | 32 ++++++++++++++++++++
 lib/librte_eal/common/include/rte_pci.h         | 32 --------------------
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c       |  2 +-
 lib/librte_eal/linuxapp/eal/eal_pci_vfio.c      |  5 ++--
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  8 +++++
 10 files changed, 101 insertions(+), 82 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 374b68f..c021969 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -228,7 +228,7 @@ pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
 
 	/* if matching map is found, then use it */
 	offset = res_idx * pagesz;
-	mapaddr = pci_map_resource(NULL, fd, (off_t)offset,
+	mapaddr = rte_eal_map_resource(NULL, fd, (off_t)offset,
 			(size_t)dev->mem_resource[res_idx].len, 0);
 	close(fd);
 	if (mapaddr == MAP_FAILED)
diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index a335e04..6dd4186 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -162,3 +162,11 @@ DPDK_16.07 {
 	rte_thread_setname;
 
 } DPDK_16.04;
+
+DPDK_16.11 {
+	global:
+
+	rte_eal_map_resource;
+	rte_eal_unmap_resource;
+
+} DPDK_16.07;
diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index a8a4146..83aa1ca 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -36,6 +36,7 @@
 #include <string.h>
 #include <inttypes.h>
 #include <sys/queue.h>
+#include <sys/mman.h>
 
 #include <rte_dev.h>
 #include <rte_devargs.h>
@@ -150,3 +151,41 @@ rte_eal_vdev_uninit(const char *name)
 	RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
 	return -EINVAL;
 }
+
+/* map a particular resource from a file */
+void *
+rte_eal_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
+		 int additional_flags)
+{
+	void *mapaddr;
+
+	/* Map the 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, "  Device memory mapped at %p\n", mapaddr);
+
+	return mapaddr;
+}
+
+/* unmap a particular resource */
+void
+rte_eal_unmap_resource(void *requested_addr, size_t size)
+{
+	if (requested_addr == NULL)
+		return;
+
+	/* Unmap the 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, "  Device memory unmapped at %p\n",
+				requested_addr);
+}
diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 7248c38..0818b63 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -67,7 +67,6 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <sys/queue.h>
-#include <sys/mman.h>
 
 #include <rte_interrupts.h>
 #include <rte_log.h>
@@ -112,44 +111,6 @@ static struct rte_devargs *pci_devargs_lookup(struct rte_pci_device *dev)
 	return NULL;
 }
 
-/* map a particular resource from a file */
-void *
-pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
-		 int additional_flags)
-{
-	void *mapaddr;
-
-	/* Map the PCI memory resource of device */
-	mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
-			MAP_SHARED | additional_flags, fd, offset);
-	if (mapaddr == MAP_FAILED) {
-		RTE_LOG(ERR, EAL, "%s(): cannot mmap(%d, %p, 0x%lx, 0x%lx): %s (%p)\n",
-			__func__, fd, requested_addr,
-			(unsigned long)size, (unsigned long)offset,
-			strerror(errno), mapaddr);
-	} else
-		RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
-
-	return mapaddr;
-}
-
-/* unmap a particular resource */
-void
-pci_unmap_resource(void *requested_addr, size_t size)
-{
-	if (requested_addr == NULL)
-		return;
-
-	/* Unmap the PCI memory resource of device */
-	if (munmap(requested_addr, size)) {
-		RTE_LOG(ERR, EAL, "%s(): cannot munmap(%p, 0x%lx): %s\n",
-			__func__, requested_addr, (unsigned long)size,
-			strerror(errno));
-	} else
-		RTE_LOG(DEBUG, EAL, "  PCI memory unmapped at %p\n",
-				requested_addr);
-}
-
 /*
  * If vendor/device ID match, call the devinit() function of the
  * driver.
diff --git a/lib/librte_eal/common/eal_common_pci_uio.c b/lib/librte_eal/common/eal_common_pci_uio.c
index 367a681..3402518 100644
--- a/lib/librte_eal/common/eal_common_pci_uio.c
+++ b/lib/librte_eal/common/eal_common_pci_uio.c
@@ -75,9 +75,11 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 				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);
+			void *mapaddr = rte_eal_map_resource(
+						uio_res->maps[i].addr, fd,
+						(off_t)uio_res->maps[i].offset,
+						(size_t)uio_res->maps[i].size,
+						0);
 			/* fd is not needed in slave process, close it */
 			close(fd);
 			if (mapaddr != uio_res->maps[i].addr) {
@@ -88,11 +90,11 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 				if (mapaddr != MAP_FAILED) {
 					/* unmap addrs correctly mapped */
 					for (j = 0; j < i; j++)
-						pci_unmap_resource(
+						rte_eal_unmap_resource(
 							uio_res->maps[j].addr,
 							(size_t)uio_res->maps[j].size);
 					/* unmap addr wrongly mapped */
-					pci_unmap_resource(mapaddr,
+					rte_eal_unmap_resource(mapaddr,
 						(size_t)uio_res->maps[i].size);
 				}
 				return -1;
@@ -150,7 +152,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	return 0;
 error:
 	for (i = 0; i < map_idx; i++) {
-		pci_unmap_resource(uio_res->maps[i].addr,
+		rte_eal_unmap_resource(uio_res->maps[i].addr,
 				(size_t)uio_res->maps[i].size);
 		rte_free(uio_res->maps[i].path);
 	}
@@ -167,7 +169,7 @@ pci_uio_unmap(struct mapped_pci_resource *uio_res)
 		return;
 
 	for (i = 0; i != uio_res->nb_maps; i++) {
-		pci_unmap_resource(uio_res->maps[i].addr,
+		rte_eal_unmap_resource(uio_res->maps[i].addr,
 				(size_t)uio_res->maps[i].size);
 		if (rte_eal_process_type() == RTE_PROC_PRIMARY)
 			rte_free(uio_res->maps[i].path);
diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h
index 60bc91d..938f8c8 100644
--- a/lib/librte_eal/common/include/rte_dev.h
+++ b/lib/librte_eal/common/include/rte_dev.h
@@ -190,6 +190,38 @@ int rte_eal_vdev_init(const char *name, const char *args);
  */
 int rte_eal_vdev_uninit(const char *name);
 
+/**
+ * @internal
+ * Map a particular resource from a file.
+ *
+ * @param requested_addr
+ *      The starting address for the new mapping range.
+ * @param fd
+ *      The file descriptor.
+ * @param offset
+ *      The offset for the mapping range.
+ * @param size
+ *      The size for the mapping range.
+ * @param additional_flags
+ *      The additional flags for the mapping range.
+ * @return
+ *   - On success, the function returns a pointer to the mapped area.
+ *   - On error, the value MAP_FAILED is returned.
+ */
+void *rte_eal_map_resource(void *requested_addr, int fd, off_t offset,
+		size_t size, int additional_flags);
+
+/**
+ * @internal
+ * Unmap a particular resource.
+ *
+ * @param requested_addr
+ *      The address for the unmapping range.
+ * @param size
+ *      The size for the unmapping range.
+ */
+void rte_eal_unmap_resource(void *requested_addr, size_t size);
+
 #define DRIVER_EXPORT_NAME_ARRAY(n, idx) n##idx[]
 
 #define DRIVER_EXPORT_NAME(name, idx) \
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index a4c8156..78e0245 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -383,38 +383,6 @@ int rte_eal_pci_map_device(struct rte_pci_device *dev);
 void rte_eal_pci_unmap_device(struct rte_pci_device *dev);
 
 /**
- * @internal
- * Map a particular resource from a file.
- *
- * @param requested_addr
- *      The starting address for the new mapping range.
- * @param fd
- *      The file descriptor.
- * @param offset
- *      The offset for the mapping range.
- * @param size
- *      The size for the mapping range.
- * @param additional_flags
- *      The additional flags for the mapping range.
- * @return
- *   - On success, the function returns a pointer to the mapped area.
- *   - On error, the value MAP_FAILED is returned.
- */
-void *pci_map_resource(void *requested_addr, int fd, off_t offset,
-		size_t size, int additional_flags);
-
-/**
- * @internal
- * Unmap a particular resource.
- *
- * @param requested_addr
- *      The address for the unmapping range.
- * @param size
- *      The size for the unmapping range.
- */
-void pci_unmap_resource(void *requested_addr, size_t size);
-
-/**
  * 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_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 1786b75..5c34421 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -347,7 +347,7 @@ pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
 	if (pci_map_addr == NULL)
 		pci_map_addr = pci_find_max_end_va();
 
-	mapaddr = pci_map_resource(pci_map_addr, fd, 0,
+	mapaddr = rte_eal_map_resource(pci_map_addr, fd, 0,
 			(size_t)dev->mem_resource[res_idx].len, 0);
 	close(fd);
 	if (mapaddr == MAP_FAILED)
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
index 5f478c5..5ad8cbe 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
@@ -465,7 +465,8 @@ pci_vfio_map_resource(struct rte_pci_device *dev)
 			void *map_addr = NULL;
 			if (memreg[0].size) {
 				/* actual map of first part */
-				map_addr = pci_map_resource(bar_addr, vfio_dev_fd,
+				map_addr = rte_eal_map_resource(bar_addr,
+							    vfio_dev_fd,
 							    memreg[0].offset,
 							    memreg[0].size,
 							    MAP_FIXED);
@@ -477,7 +478,7 @@ pci_vfio_map_resource(struct rte_pci_device *dev)
 				void *second_addr = RTE_PTR_ADD(bar_addr,
 								memreg[1].offset -
 								(uintptr_t)reg.offset);
-				map_addr = pci_map_resource(second_addr,
+				map_addr = rte_eal_map_resource(second_addr,
 							    vfio_dev_fd, memreg[1].offset,
 							    memreg[1].size,
 							    MAP_FIXED);
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index db8c984..15e8332 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -166,3 +166,11 @@ DPDK_16.07 {
 	rte_thread_setname;
 
 } DPDK_16.04;
+
+DPDK_16.11 {
+	global:
+
+	rte_eal_map_resource;
+	rte_eal_unmap_resource;
+
+} DPDK_16.07;
-- 
2.7.4

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

* [PATCH 4/5] eal/linux: extract function rte_eal_unbind_kernel_driver
  2016-09-01  4:41 [PATCH 0/5] Generalize PCI specific EAL function/structures Shreyansh Jain
                   ` (2 preceding siblings ...)
  2016-09-01  4:41 ` [PATCH 3/5] eal: Convert pci_(un)map_resource to rte_eal_(un)map_resource Shreyansh Jain
@ 2016-09-01  4:41 ` Shreyansh Jain
  2016-09-01  4:41 ` [PATCH 5/5] eal/linux: extract function rte_eal_get_kernel_driver_by_path Shreyansh Jain
  2016-09-27 14:12 ` [PATCH v1 0/4] Generalize PCI specific EAL function/structures Shreyansh Jain
  5 siblings, 0 replies; 27+ messages in thread
From: Shreyansh Jain @ 2016-09-01  4:41 UTC (permalink / raw)
  To: viktorin, dev; +Cc: thomas.monjalon, Shreyansh Jain

From: Jan Viktorin <viktorin@rehivetech.com>

From: Jan Viktorin <viktorin@rehivetech.com>

Generalize the PCI-specific pci_unbind_kernel_driver. It is now divided
into two parts. First, determination of the path and string identification
of the device to be unbound. Second, the actual unbind operation which is
generic.

Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/common/eal_private.h   | 13 +++++++++++++
 lib/librte_eal/linuxapp/eal/eal.c     | 26 ++++++++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_pci.c | 33 +++++++++------------------------
 3 files changed, 48 insertions(+), 24 deletions(-)

diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 19f7535..0740c0c 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -258,6 +258,19 @@ int rte_eal_dev_init(void);
 int rte_eal_check_module(const char *module_name);
 
 /**
+ * Unbind kernel driver bound to the device specified by the given devpath,
+ * and its string identification.
+ *
+ * @param devpath  path to the device directory ("/sys/.../devices/<name>")
+ * @param devid    identification of the device (<name>)
+ *
+ * @return
+ *      -1  unbind has failed
+ *       0  module has been unbound
+ */
+int rte_eal_unbind_kernel_driver(const char *devpath, const char *devid);
+
+/**
  * Get cpu core_id.
  *
  * This function is private to the EAL.
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index f912e4e..8711d9a 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -947,3 +947,29 @@ rte_eal_check_module(const char *module_name)
 	/* Module has been found */
 	return 1;
 }
+
+int
+rte_eal_unbind_kernel_driver(const char *devpath, const char *devid)
+{
+	char filename[PATH_MAX];
+	FILE *f;
+
+	snprintf(filename, sizeof(filename),
+	         "%s/driver/unbind", devpath);
+
+	f = fopen(filename, "w");
+	if (f == NULL) /* device was not bound */
+		return 0;
+
+	if (fwrite(devid, strlen(devid), 1, f) == 0) {
+		RTE_LOG(ERR, EAL, "%s(): could not write to %s\n", __func__,
+				filename);
+		goto error;
+	}
+
+	fclose(f);
+	return 0;
+error:
+	fclose(f);
+	return -1;
+}
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index cd9de7c..4792d05 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -59,38 +59,23 @@ int
 pci_unbind_kernel_driver(struct rte_pci_device *dev)
 {
 	int n;
-	FILE *f;
-	char filename[PATH_MAX];
-	char buf[BUFSIZ];
+	char devpath[PATH_MAX];
+	char devid[BUFSIZ];
 	struct rte_pci_addr *loc = &dev->addr;
 
-	/* open /sys/bus/pci/devices/AAAA:BB:CC.D/driver */
-	snprintf(filename, sizeof(filename),
-		"%s/" PCI_PRI_FMT "/driver/unbind", pci_get_sysfs_path(),
+	/* devpath /sys/bus/pci/devices/AAAA:BB:CC.D */
+	snprintf(devpath, sizeof(devpath),
+		"%s/" PCI_PRI_FMT, pci_get_sysfs_path(),
 		loc->domain, loc->bus, loc->devid, loc->function);
 
-	f = fopen(filename, "w");
-	if (f == NULL) /* device was not bound */
-		return 0;
-
-	n = snprintf(buf, sizeof(buf), PCI_PRI_FMT "\n",
+	n = snprintf(devid, sizeof(devid), PCI_PRI_FMT "\n",
 	             loc->domain, loc->bus, loc->devid, loc->function);
-	if ((n < 0) || (n >= (int)sizeof(buf))) {
+	if ((n < 0) || (n >= (int)sizeof(devid))) {
 		RTE_LOG(ERR, EAL, "%s(): snprintf failed\n", __func__);
-		goto error;
-	}
-	if (fwrite(buf, n, 1, f) == 0) {
-		RTE_LOG(ERR, EAL, "%s(): could not write to %s\n", __func__,
-				filename);
-		goto error;
+		return -1;
 	}
 
-	fclose(f);
-	return 0;
-
-error:
-	fclose(f);
-	return -1;
+	return rte_eal_unbind_kernel_driver(devpath, devid);
 }
 
 static int
-- 
2.7.4

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

* [PATCH 5/5] eal/linux: extract function rte_eal_get_kernel_driver_by_path
  2016-09-01  4:41 [PATCH 0/5] Generalize PCI specific EAL function/structures Shreyansh Jain
                   ` (3 preceding siblings ...)
  2016-09-01  4:41 ` [PATCH 4/5] eal/linux: extract function rte_eal_unbind_kernel_driver Shreyansh Jain
@ 2016-09-01  4:41 ` Shreyansh Jain
  2016-09-27 14:12 ` [PATCH v1 0/4] Generalize PCI specific EAL function/structures Shreyansh Jain
  5 siblings, 0 replies; 27+ messages in thread
From: Shreyansh Jain @ 2016-09-01  4:41 UTC (permalink / raw)
  To: viktorin, dev; +Cc: thomas.monjalon, Shreyansh Jain

From: Jan Viktorin <viktorin@rehivetech.com>

From: Jan Viktorin <viktorin@rehivetech.com>

Generalize the PCI-specific pci_get_kernel_driver_by_path. The function
is general enough, we have just moved it to eal.c, changed the prefix to
rte_eal and provided it privately to other parts of EAL.

Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/common/eal_private.h   | 14 ++++++++++++++
 lib/librte_eal/linuxapp/eal/eal.c     | 29 +++++++++++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_pci.c | 31 +------------------------------
 3 files changed, 44 insertions(+), 30 deletions(-)

diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 0740c0c..5ea30a2 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -271,6 +271,20 @@ int rte_eal_check_module(const char *module_name);
 int rte_eal_unbind_kernel_driver(const char *devpath, const char *devid);
 
 /**
+ * Extrat the kernel driver name from the absolute path to the driver.
+ *
+ * @param filename  path to the driver ("<path-to-device>/driver")
+ * @path  dri_name  target buffer where to place the driver name
+ *                  (should be at least PATH_MAX long)
+ *
+ * @return
+ *      -1   on failure
+ *       0   when successful
+ *       1   when there is no such driver
+ */
+int rte_eal_get_kernel_driver_by_path(const char *filename, char *dri_name);
+
+/**
  * Get cpu core_id.
  *
  * This function is private to the EAL.
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index 8711d9a..9a4c498 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -973,3 +973,32 @@ error:
 	fclose(f);
 	return -1;
 }
+
+int
+rte_eal_get_kernel_driver_by_path(const char *filename, char *dri_name)
+{
+	int count;
+	char path[PATH_MAX];
+	char *name;
+
+	if (!filename || !dri_name)
+		return -1;
+
+	count = readlink(filename, path, PATH_MAX);
+	if (count >= PATH_MAX)
+		return -1;
+
+	/* For device does not have a driver */
+	if (count < 0)
+		return 1;
+
+	path[count] = '\0';
+
+	name = strrchr(path, '/');
+	if (name) {
+		strncpy(dri_name, name + 1, strlen(name + 1) + 1);
+		return 0;
+	}
+
+	return -1;
+}
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index 4792d05..f923e42 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -78,35 +78,6 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev)
 	return rte_eal_unbind_kernel_driver(devpath, devid);
 }
 
-static int
-pci_get_kernel_driver_by_path(const char *filename, char *dri_name)
-{
-	int count;
-	char path[PATH_MAX];
-	char *name;
-
-	if (!filename || !dri_name)
-		return -1;
-
-	count = readlink(filename, path, PATH_MAX);
-	if (count >= PATH_MAX)
-		return -1;
-
-	/* For device does not have a driver */
-	if (count < 0)
-		return 1;
-
-	path[count] = '\0';
-
-	name = strrchr(path, '/');
-	if (name) {
-		strncpy(dri_name, name + 1, strlen(name + 1) + 1);
-		return 0;
-	}
-
-	return -1;
-}
-
 /* Map pci device */
 int
 rte_eal_pci_map_device(struct rte_pci_device *dev)
@@ -354,7 +325,7 @@ pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus,
 
 	/* parse driver */
 	snprintf(filename, sizeof(filename), "%s/driver", dirname);
-	ret = pci_get_kernel_driver_by_path(filename, driver);
+	ret = rte_eal_get_kernel_driver_by_path(filename, driver);
 	if (ret < 0) {
 		RTE_LOG(ERR, EAL, "Fail to get kernel driver\n");
 		free(dev);
-- 
2.7.4

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

* Re: [PATCH 2/5] eal: extract function eal_parse_sysfs_valuef
  2016-09-01  4:41 ` [PATCH 2/5] eal: extract function eal_parse_sysfs_valuef Shreyansh Jain
@ 2016-09-01  6:30   ` Stephen Hemminger
  2016-09-01  9:01     ` Shreyansh Jain
  0 siblings, 1 reply; 27+ messages in thread
From: Stephen Hemminger @ 2016-09-01  6:30 UTC (permalink / raw)
  To: Shreyansh Jain; +Cc: viktorin, dev, thomas.monjalon

On Thu, 1 Sep 2016 10:11:52 +0530
Shreyansh Jain <shreyansh.jain@nxp.com> wrote:

> From: Jan Viktorin <viktorin@rehivetech.com>
> 
> From: Jan Viktorin <viktorin@rehivetech.com>
> 
> The eal_parse_sysfs_value function accepts a filename however, such
> interface introduces race-conditions to the code. Introduce the
> variant of this function that accepts an already opened file instead of
> a filename.
> 
> Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
> Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
> ---

You introduce new API, but don't use it in your other patches.
I don't see where passing filename is racy. sysfs files only get created/destroyed
when device is added/removed.

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

* Re: [PATCH 2/5] eal: extract function eal_parse_sysfs_valuef
  2016-09-01  6:30   ` Stephen Hemminger
@ 2016-09-01  9:01     ` Shreyansh Jain
  0 siblings, 0 replies; 27+ messages in thread
From: Shreyansh Jain @ 2016-09-01  9:01 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: viktorin, dev, thomas.monjalon

Hi Stephen,

On Thursday 01 September 2016 12:00 PM, Stephen Hemminger wrote:
> On Thu, 1 Sep 2016 10:11:52 +0530
> Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
>
>> From: Jan Viktorin <viktorin@rehivetech.com>
>>
>> From: Jan Viktorin <viktorin@rehivetech.com>
>>
>> The eal_parse_sysfs_value function accepts a filename however, such
>> interface introduces race-conditions to the code. Introduce the
>> variant of this function that accepts an already opened file instead of
>> a filename.
>>
>> Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
>> Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
>> ---
>
> You introduce new API, but don't use it in your other patches.

Indeed - I have not used this API anywhere in my patches. As highlighted 
in the covering letter, these are some proposed changes which *might* 
help in future (for e.g., introducing new SoC infra).
Patches don't depend on each other.

> I don't see where passing filename is racy. sysfs files only get created/destroyed
> when device is added/removed.
>

Agree that 'race-condition' is not the right word.

parse_sysfs_value reads a single integer from a given sysfs file and is 
a useful helper for EAL layer, specifically for non-PCI infra as and 
when it is introduced (reading through custom sysfs files).
At that time, it may be possible that caller keeps the context of the 
call rather than open the file every time - for reading more than an 
integer, for example.

-
Shreyansh

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

* Re: [PATCH 1/5] eal: make enum rte_kernel_driver non-PCI specific
  2016-09-01  4:41 ` [PATCH 1/5] eal: make enum rte_kernel_driver non-PCI specific Shreyansh Jain
@ 2016-09-11 12:15   ` Yuanhan Liu
  2016-09-12  5:10     ` Shreyansh Jain
  0 siblings, 1 reply; 27+ messages in thread
From: Yuanhan Liu @ 2016-09-11 12:15 UTC (permalink / raw)
  To: Shreyansh Jain; +Cc: viktorin, dev, thomas.monjalon

On Thu, Sep 01, 2016 at 10:11:51AM +0530, Shreyansh Jain wrote:
> From: Jan Viktorin <viktorin@rehivetech.com>
> 
> From: Jan Viktorin <viktorin@rehivetech.com>
> 
> Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
> Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>

Hi,

FYI, my testrobot caught some errors when this patch is applied.

        --yliu

---
i686-native-linuxapp-gcc: config-all-yes
========================================
In file included from lib/librte_eal/linuxapp/eal/eal_pci.c:38:0:
i686-native-linuxapp-gcc/include/rte_pci.h:157:25: error: field 'kdrv' has incomplete type
  enum rte_kernel_driver kdrv;            /**< Kernel driver passthrough */
                         ^
In file included from lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c:52:0:
i686-native-linuxapp-gcc/include/rte_pci.h:157:25: error: field 'kdrv' has incomplete type
  enum rte_kernel_driver kdrv;            /**< Kernel driver passthrough */
                         ^
In file included from lib/librte_eal/common/eal_private.h:38:0,
                 from lib/librte_eal/linuxapp/eal/eal_thread.c:55:
i686-native-linuxapp-gcc/include/rte_pci.h:157:25: error: field 'kdrv' has incomplete type
  enum rte_kernel_driver kdrv;            /**< Kernel driver passthrough */
                         ^
make[7]: *** [eal_thread.o] Error 1
make[7]: *** Waiting for unfinished jobs....
In file included from lib/librte_eal/linuxapp/eal/eal.c:72:0:
i686-native-linuxapp-gcc/include/rte_pci.h:157:25: error: field 'kdrv' has incomplete type
  enum rte_kernel_driver kdrv;            /**< Kernel driver passthrough */
                         ^
In file included from lib/librte_eal/common/eal_private.h:38:0,
                 from lib/librte_eal/linuxapp/eal/eal_memory.c:97:
i686-native-linuxapp-gcc/include/rte_pci.h:157:25: error: field 'kdrv' has incomplete type
  enum rte_kernel_driver kdrv;            /**< Kernel driver passthrough */
                         ^
In file included from lib/librte_eal/common/eal_private.h:38:0,
                 from lib/librte_eal/linuxapp/eal/eal_log.c:50:
i686-native-linuxapp-gcc/include/rte_pci.h:157:25: error: field 'kdrv' has incomplete type
  enum rte_kernel_driver kdrv;            /**< Kernel driver passthrough */
                         ^
make[7]: *** [eal_log.o] Error 1
make[7]: *** [eal_vfio_mp_sync.o] Error 1
In file included from lib/librte_eal/common/eal_private.h:38:0,
                 from lib/librte_eal/linuxapp/eal/eal_vfio.c:45:
i686-native-linuxapp-gcc/include/rte_pci.h:157:25: error: field 'kdrv' has incomplete type
  enum rte_kernel_driver kdrv;            /**< Kernel driver passthrough */
                         ^
make[7]: *** [eal.o] Error 1
make[7]: *** [eal_memory.o] Error 1
make[7]: *** [eal_vfio.o] Error 1
lib/librte_eal/linuxapp/eal/eal_pci.c: In function 'rte_eal_pci_map_device':
lib/librte_eal/linuxapp/eal/eal_pci.c:133:7: error: 'RTE_KDRV_VFIO' undeclared (first use in this function)
  case RTE_KDRV_VFIO:
       ^
lib/librte_eal/linuxapp/eal/eal_pci.c:133:7: note: each undeclared identifier is reported only once for each function it appears in
lib/librte_eal/linuxapp/eal/eal_pci.c:139:7: error: 'RTE_KDRV_IGB_UIO' undeclared (first use in this function)
  case RTE_KDRV_IGB_UIO:
       ^
lib/librte_eal/linuxapp/eal/eal_pci.c:140:7: error: 'RTE_KDRV_UIO_GENERIC' undeclared (first use in this function)
  case RTE_KDRV_UIO_GENERIC:
       ^
lib/librte_eal/linuxapp/eal/eal_pci.c: In function 'rte_eal_pci_unmap_device':
lib/librte_eal/linuxapp/eal/eal_pci.c:160:7: error: 'RTE_KDRV_VFIO' undeclared (first use in this function)
  case RTE_KDRV_VFIO:
       ^
lib/librte_eal/linuxapp/eal/eal_pci.c:163:7: error: 'RTE_KDRV_IGB_UIO' undeclared (first use in this function)
  case RTE_KDRV_IGB_UIO:
       ^
lib/librte_eal/linuxapp/eal/eal_pci.c:164:7: error: 'RTE_KDRV_UIO_GENERIC' undeclared (first use in this function)
  case RTE_KDRV_UIO_GENERIC:
       ^
lib/librte_eal/linuxapp/eal/eal_pci.c: In function 'pci_scan_one':
lib/librte_eal/linuxapp/eal/eal_pci.c:381:16: error: 'RTE_KDRV_VFIO' undeclared (first use in this function)
    dev->kdrv = RTE_KDRV_VFIO;
                ^
lib/librte_eal/linuxapp/eal/eal_pci.c:383:16: error: 'RTE_KDRV_IGB_UIO' undeclared (first use in this function)
    dev->kdrv = RTE_KDRV_IGB_UIO;
                ^
lib/librte_eal/linuxapp/eal/eal_pci.c:385:16: error: 'RTE_KDRV_UIO_GENERIC' undeclared (first use in this function)
    dev->kdrv = RTE_KDRV_UIO_GENERIC;
                ^
lib/librte_eal/linuxapp/eal/eal_pci.c:387:16: error: 'RTE_KDRV_UNKNOWN' undeclared (first use in this function)
    dev->kdrv = RTE_KDRV_UNKNOWN;
                ^
lib/librte_eal/linuxapp/eal/eal_pci.c:389:15: error: 'RTE_KDRV_NONE' undeclared (first use in this function)
   dev->kdrv = RTE_KDRV_NONE;
               ^
lib/librte_eal/linuxapp/eal/eal_pci.c: In function 'rte_eal_pci_ioport_map':
lib/librte_eal/linuxapp/eal/eal_pci.c:626:7: error: 'RTE_KDRV_VFIO' undeclared (first use in this function)
  case RTE_KDRV_VFIO:
       ^
lib/librte_eal/linuxapp/eal/eal_pci.c:631:7: error: 'RTE_KDRV_IGB_UIO' undeclared (first use in this function)
  case RTE_KDRV_IGB_UIO:
       ^
lib/librte_eal/linuxapp/eal/eal_pci.c:634:7: error: 'RTE_KDRV_UIO_GENERIC' undeclared (first use in this function)
  case RTE_KDRV_UIO_GENERIC:
       ^
lib/librte_eal/linuxapp/eal/eal_pci.c:641:7: error: 'RTE_KDRV_NONE' undeclared (first use in this function)
  case RTE_KDRV_NONE:
       ^
lib/librte_eal/linuxapp/eal/eal_pci.c: In function 'rte_eal_pci_ioport_read':
lib/librte_eal/linuxapp/eal/eal_pci.c:662:7: error: 'RTE_KDRV_VFIO' undeclared (first use in this function)
  case RTE_KDRV_VFIO:
       ^
lib/librte_eal/linuxapp/eal/eal_pci.c:666:7: error: 'RTE_KDRV_IGB_UIO' undeclared (first use in this function)
  case RTE_KDRV_IGB_UIO:
       ^
lib/librte_eal/linuxapp/eal/eal_pci.c:669:7: error: 'RTE_KDRV_UIO_GENERIC' undeclared (first use in this function)
  case RTE_KDRV_UIO_GENERIC:
       ^
lib/librte_eal/linuxapp/eal/eal_pci.c:672:7: error: 'RTE_KDRV_NONE' undeclared (first use in this function)
  case RTE_KDRV_NONE:
       ^
lib/librte_eal/linuxapp/eal/eal_pci.c: In function 'rte_eal_pci_ioport_write':
lib/librte_eal/linuxapp/eal/eal_pci.c:688:7: error: 'RTE_KDRV_VFIO' undeclared (first use in this function)
  case RTE_KDRV_VFIO:
       ^
lib/librte_eal/linuxapp/eal/eal_pci.c:692:7: error: 'RTE_KDRV_IGB_UIO' undeclared (first use in this function)
  case RTE_KDRV_IGB_UIO:
       ^
lib/librte_eal/linuxapp/eal/eal_pci.c:695:7: error: 'RTE_KDRV_UIO_GENERIC' undeclared (first use in this function)
  case RTE_KDRV_UIO_GENERIC:
       ^
lib/librte_eal/linuxapp/eal/eal_pci.c:698:7: error: 'RTE_KDRV_NONE' undeclared (first use in this function)
  case RTE_KDRV_NONE:
       ^
lib/librte_eal/linuxapp/eal/eal_pci.c: In function 'rte_eal_pci_ioport_unmap':
lib/librte_eal/linuxapp/eal/eal_pci.c:715:7: error: 'RTE_KDRV_VFIO' undeclared (first use in this function)
  case RTE_KDRV_VFIO:
       ^
lib/librte_eal/linuxapp/eal/eal_pci.c:720:7: error: 'RTE_KDRV_IGB_UIO' undeclared (first use in this function)
  case RTE_KDRV_IGB_UIO:
       ^
lib/librte_eal/linuxapp/eal/eal_pci.c:723:7: error: 'RTE_KDRV_UIO_GENERIC' undeclared (first use in this function)
  case RTE_KDRV_UIO_GENERIC:
       ^
lib/librte_eal/linuxapp/eal/eal_pci.c:730:7: error: 'RTE_KDRV_NONE' undeclared (first use in this function)
  case RTE_KDRV_NONE:
       ^
make[7]: *** [eal_pci.o] Error 1
make[6]: *** [eal] Error 2
make[5]: *** [linuxapp] Error 2
make[4]: *** [librte_eal] Error 2
make[3]: *** [lib] Error 2
make[2]: *** [all] Error 2
make[1]: *** [pre_install] Error 2
make: *** [install] Error 2
error: build failed

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

* Re: [PATCH 1/5] eal: make enum rte_kernel_driver non-PCI specific
  2016-09-11 12:15   ` Yuanhan Liu
@ 2016-09-12  5:10     ` Shreyansh Jain
  0 siblings, 0 replies; 27+ messages in thread
From: Shreyansh Jain @ 2016-09-12  5:10 UTC (permalink / raw)
  To: Yuanhan Liu; +Cc: viktorin, dev, thomas.monjalon

Hi,

On Sunday 11 September 2016 05:45 PM, Yuanhan Liu wrote:
> On Thu, Sep 01, 2016 at 10:11:51AM +0530, Shreyansh Jain wrote:
>> From: Jan Viktorin <viktorin@rehivetech.com>
>>
>> From: Jan Viktorin <viktorin@rehivetech.com>
>>
>> Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
>> Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
>
> Hi,
>
> FYI, my testrobot caught some errors when this patch is applied.
>
>         --yliu
>
> ---
> i686-native-linuxapp-gcc: config-all-yes
> ========================================
> In file included from lib/librte_eal/linuxapp/eal/eal_pci.c:38:0:
> i686-native-linuxapp-gcc/include/rte_pci.h:157:25: error: field 'kdrv' has incomplete type
>   enum rte_kernel_driver kdrv;            /**< Kernel driver passthrough */
>                          ^
> In file included from lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c:52:0:
> i686-native-linuxapp-gcc/include/rte_pci.h:157:25: error: field 'kdrv' has incomplete type
>   enum rte_kernel_driver kdrv;            /**< Kernel driver passthrough */
>                          ^
> In file included from lib/librte_eal/common/eal_private.h:38:0,
>                  from lib/librte_eal/linuxapp/eal/eal_thread.c:55:
> i686-native-linuxapp-gcc/include/rte_pci.h:157:25: error: field 'kdrv' has incomplete type
>   enum rte_kernel_driver kdrv;            /**< Kernel driver passthrough */
>                          ^
> make[7]: *** [eal_thread.o] Error 1
> make[7]: *** Waiting for unfinished jobs....
> In file included from lib/librte_eal/linuxapp/eal/eal.c:72:0:
> i686-native-linuxapp-gcc/include/rte_pci.h:157:25: error: field 'kdrv' has incomplete type
>   enum rte_kernel_driver kdrv;            /**< Kernel driver passthrough */
>                          ^
> In file included from lib/librte_eal/common/eal_private.h:38:0,
>                  from lib/librte_eal/linuxapp/eal/eal_memory.c:97:
> i686-native-linuxapp-gcc/include/rte_pci.h:157:25: error: field 'kdrv' has incomplete type
>   enum rte_kernel_driver kdrv;            /**< Kernel driver passthrough */
>                          ^
> In file included from lib/librte_eal/common/eal_private.h:38:0,
>                  from lib/librte_eal/linuxapp/eal/eal_log.c:50:
> i686-native-linuxapp-gcc/include/rte_pci.h:157:25: error: field 'kdrv' has incomplete type
>   enum rte_kernel_driver kdrv;            /**< Kernel driver passthrough */
>                          ^
> make[7]: *** [eal_log.o] Error 1
> make[7]: *** [eal_vfio_mp_sync.o] Error 1
> In file included from lib/librte_eal/common/eal_private.h:38:0,
>                  from lib/librte_eal/linuxapp/eal/eal_vfio.c:45:
> i686-native-linuxapp-gcc/include/rte_pci.h:157:25: error: field 'kdrv' has incomplete type
>   enum rte_kernel_driver kdrv;            /**< Kernel driver passthrough */
>                          ^
> make[7]: *** [eal.o] Error 1
> make[7]: *** [eal_memory.o] Error 1
> make[7]: *** [eal_vfio.o] Error 1
> lib/librte_eal/linuxapp/eal/eal_pci.c: In function 'rte_eal_pci_map_device':
> lib/librte_eal/linuxapp/eal/eal_pci.c:133:7: error: 'RTE_KDRV_VFIO' undeclared (first use in this function)
>   case RTE_KDRV_VFIO:
>        ^
> lib/librte_eal/linuxapp/eal/eal_pci.c:133:7: note: each undeclared identifier is reported only once for each function it appears in
> lib/librte_eal/linuxapp/eal/eal_pci.c:139:7: error: 'RTE_KDRV_IGB_UIO' undeclared (first use in this function)
>   case RTE_KDRV_IGB_UIO:
>        ^
> lib/librte_eal/linuxapp/eal/eal_pci.c:140:7: error: 'RTE_KDRV_UIO_GENERIC' undeclared (first use in this function)
>   case RTE_KDRV_UIO_GENERIC:
>        ^
> lib/librte_eal/linuxapp/eal/eal_pci.c: In function 'rte_eal_pci_unmap_device':
> lib/librte_eal/linuxapp/eal/eal_pci.c:160:7: error: 'RTE_KDRV_VFIO' undeclared (first use in this function)
>   case RTE_KDRV_VFIO:
>        ^
> lib/librte_eal/linuxapp/eal/eal_pci.c:163:7: error: 'RTE_KDRV_IGB_UIO' undeclared (first use in this function)
>   case RTE_KDRV_IGB_UIO:
>        ^
> lib/librte_eal/linuxapp/eal/eal_pci.c:164:7: error: 'RTE_KDRV_UIO_GENERIC' undeclared (first use in this function)
>   case RTE_KDRV_UIO_GENERIC:
>        ^
> lib/librte_eal/linuxapp/eal/eal_pci.c: In function 'pci_scan_one':
> lib/librte_eal/linuxapp/eal/eal_pci.c:381:16: error: 'RTE_KDRV_VFIO' undeclared (first use in this function)
>     dev->kdrv = RTE_KDRV_VFIO;
>                 ^
> lib/librte_eal/linuxapp/eal/eal_pci.c:383:16: error: 'RTE_KDRV_IGB_UIO' undeclared (first use in this function)
>     dev->kdrv = RTE_KDRV_IGB_UIO;
>                 ^
> lib/librte_eal/linuxapp/eal/eal_pci.c:385:16: error: 'RTE_KDRV_UIO_GENERIC' undeclared (first use in this function)
>     dev->kdrv = RTE_KDRV_UIO_GENERIC;
>                 ^
> lib/librte_eal/linuxapp/eal/eal_pci.c:387:16: error: 'RTE_KDRV_UNKNOWN' undeclared (first use in this function)
>     dev->kdrv = RTE_KDRV_UNKNOWN;
>                 ^
> lib/librte_eal/linuxapp/eal/eal_pci.c:389:15: error: 'RTE_KDRV_NONE' undeclared (first use in this function)
>    dev->kdrv = RTE_KDRV_NONE;
>                ^
> lib/librte_eal/linuxapp/eal/eal_pci.c: In function 'rte_eal_pci_ioport_map':
> lib/librte_eal/linuxapp/eal/eal_pci.c:626:7: error: 'RTE_KDRV_VFIO' undeclared (first use in this function)
>   case RTE_KDRV_VFIO:
>        ^
> lib/librte_eal/linuxapp/eal/eal_pci.c:631:7: error: 'RTE_KDRV_IGB_UIO' undeclared (first use in this function)
>   case RTE_KDRV_IGB_UIO:
>        ^
> lib/librte_eal/linuxapp/eal/eal_pci.c:634:7: error: 'RTE_KDRV_UIO_GENERIC' undeclared (first use in this function)
>   case RTE_KDRV_UIO_GENERIC:
>        ^
> lib/librte_eal/linuxapp/eal/eal_pci.c:641:7: error: 'RTE_KDRV_NONE' undeclared (first use in this function)
>   case RTE_KDRV_NONE:
>        ^
> lib/librte_eal/linuxapp/eal/eal_pci.c: In function 'rte_eal_pci_ioport_read':
> lib/librte_eal/linuxapp/eal/eal_pci.c:662:7: error: 'RTE_KDRV_VFIO' undeclared (first use in this function)
>   case RTE_KDRV_VFIO:
>        ^
> lib/librte_eal/linuxapp/eal/eal_pci.c:666:7: error: 'RTE_KDRV_IGB_UIO' undeclared (first use in this function)
>   case RTE_KDRV_IGB_UIO:
>        ^
> lib/librte_eal/linuxapp/eal/eal_pci.c:669:7: error: 'RTE_KDRV_UIO_GENERIC' undeclared (first use in this function)
>   case RTE_KDRV_UIO_GENERIC:
>        ^
> lib/librte_eal/linuxapp/eal/eal_pci.c:672:7: error: 'RTE_KDRV_NONE' undeclared (first use in this function)
>   case RTE_KDRV_NONE:
>        ^
> lib/librte_eal/linuxapp/eal/eal_pci.c: In function 'rte_eal_pci_ioport_write':
> lib/librte_eal/linuxapp/eal/eal_pci.c:688:7: error: 'RTE_KDRV_VFIO' undeclared (first use in this function)
>   case RTE_KDRV_VFIO:
>        ^
> lib/librte_eal/linuxapp/eal/eal_pci.c:692:7: error: 'RTE_KDRV_IGB_UIO' undeclared (first use in this function)
>   case RTE_KDRV_IGB_UIO:
>        ^
> lib/librte_eal/linuxapp/eal/eal_pci.c:695:7: error: 'RTE_KDRV_UIO_GENERIC' undeclared (first use in this function)
>   case RTE_KDRV_UIO_GENERIC:
>        ^
> lib/librte_eal/linuxapp/eal/eal_pci.c:698:7: error: 'RTE_KDRV_NONE' undeclared (first use in this function)
>   case RTE_KDRV_NONE:
>        ^
> lib/librte_eal/linuxapp/eal/eal_pci.c: In function 'rte_eal_pci_ioport_unmap':
> lib/librte_eal/linuxapp/eal/eal_pci.c:715:7: error: 'RTE_KDRV_VFIO' undeclared (first use in this function)
>   case RTE_KDRV_VFIO:
>        ^
> lib/librte_eal/linuxapp/eal/eal_pci.c:720:7: error: 'RTE_KDRV_IGB_UIO' undeclared (first use in this function)
>   case RTE_KDRV_IGB_UIO:
>        ^
> lib/librte_eal/linuxapp/eal/eal_pci.c:723:7: error: 'RTE_KDRV_UIO_GENERIC' undeclared (first use in this function)
>   case RTE_KDRV_UIO_GENERIC:
>        ^
> lib/librte_eal/linuxapp/eal/eal_pci.c:730:7: error: 'RTE_KDRV_NONE' undeclared (first use in this function)
>   case RTE_KDRV_NONE:
>        ^
> make[7]: *** [eal_pci.o] Error 1
> make[6]: *** [eal] Error 2
> make[5]: *** [linuxapp] Error 2
> make[4]: *** [librte_eal] Error 2
> make[3]: *** [lib] Error 2
> make[2]: *** [all] Error 2
> make[1]: *** [pre_install] Error 2
> make: *** [install] Error 2
> error: build failed
>

Thanks for highlighting.
That is my mistake.
While sending the patch my intention was to highlight that these are 
more as a RFC than direct patches. I forgot to add that and didn't 
notice it after posting either.

Problem is that this patch moves 'enum rte_kernel_driver' to rte_dev.h 
from rte_pci.h. All the above errors are reported by files which still 
include rte_dev.h.

I was hoping that if these patches look fine to all, I will update all 
the headers and send again.

--
Shreyansh

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

* [PATCH v1 0/4] Generalize PCI specific EAL function/structures
  2016-09-01  4:41 [PATCH 0/5] Generalize PCI specific EAL function/structures Shreyansh Jain
                   ` (4 preceding siblings ...)
  2016-09-01  4:41 ` [PATCH 5/5] eal/linux: extract function rte_eal_get_kernel_driver_by_path Shreyansh Jain
@ 2016-09-27 14:12 ` Shreyansh Jain
  2016-09-27 14:12   ` [PATCH v1 1/4] eal: generalize PCI kernel driver enum to EAL Shreyansh Jain
                     ` (5 more replies)
  5 siblings, 6 replies; 27+ messages in thread
From: Shreyansh Jain @ 2016-09-27 14:12 UTC (permalink / raw)
  To: dev; +Cc: viktorin, thomas.monjalon, david.marchand, Shreyansh Jain

(I rebased these over HEAD 7b3c4f3)

These patches were initially part of Jan's original series on SoC
Framework ([1],[2]). An update to that series, without these patches,
was posted here [3].

Main motivation for these is aim of introducing a non-PCI centric
subsystem in EAL. As of now the first usecase is SoC, but not limited to
it.

4 patches in this series are independent of each other, as well as SoC
framework. All these focus on generalizing some structure or functions
present with the PCI specific code to EAL Common area (or splitting a
function to be more userful).

 - 0001: move the rte_kernel_driver enum from rte_pci to rte_dev. As of
   now this structure is embedded in rte_pci_device, but, going ahead it
   can be part of other rte_xxx_device structures. Either way, it has no
   impact on PCI.
 - 0002: Functions pci_map_resource/pci_unmap_resource are moved to EAL
   common as rte_eal_map_resource/rte_eal_unmap_resource, respectively.
 - 0003: Split the  pci_unbind_kernel_driver into two, still working on
   the PCI BDF sysfs layout, first handles the file path (and validations)
   and second does the actual unbind. The second part might be useful in
   case of non-PCI layouts.
 - 0004: Move pci_get_kernel_driver_by_path to
   rte_eal_get_kernel_driver_by_path in EAL common. This function is
   generic for any sysfs compliant driver and can be re-used by other
   non-PCI subsystem.

Changes since v0 [4]:
 - Fix for checkpatch and check-git-log
 - Fix missing include in patch 0001
 - Drop patch 2 for splitting sysfs into a sub-function taking file
   handle. This patch doesn't really fit into the model of PCI->EAL
   movement of generic functions which other patches relate to.
   Also, taking cue from review comment [5], it might not have a
   viable use-case as of now.

[1] http://dpdk.org/ml/archives/dev/2016-January/030915.html
[2] http://www.dpdk.org/ml/archives/dev/2016-May/038486.html
[3] http://dpdk.org/ml/archives/dev/2016-August/045993.html
[4] http://dpdk.org/ml/archives/dev/2016-September/046035.html
[5] http://dpdk.org/ml/archives/dev/2016-September/046041.html

Jan Viktorin (4):
  eal: generalize PCI kernel driver enum to EAL
  eal: generalize PCI map/unmap resource to EAL
  eal/linux: generalize PCI kernel unbinding driver to EAL
  eal/linux: generalize PCI kernel driver extraction to EAL

 lib/librte_eal/bsdapp/eal/eal_pci.c             |  2 +-
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  8 ++++
 lib/librte_eal/common/eal_common_dev.c          | 39 ++++++++++++++++
 lib/librte_eal/common/eal_common_pci.c          | 39 ----------------
 lib/librte_eal/common/eal_common_pci_uio.c      | 16 ++++---
 lib/librte_eal/common/eal_private.h             | 27 +++++++++++
 lib/librte_eal/common/include/rte_dev.h         | 44 ++++++++++++++++++
 lib/librte_eal/common/include/rte_pci.h         | 42 +----------------
 lib/librte_eal/linuxapp/eal/eal.c               | 55 ++++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_pci.c           | 62 ++++---------------------
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c       |  2 +-
 lib/librte_eal/linuxapp/eal/eal_pci_vfio.c      |  5 +-
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  8 ++++
 13 files changed, 205 insertions(+), 144 deletions(-)

-- 
2.7.4

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

* [PATCH v1 1/4] eal: generalize PCI kernel driver enum to EAL
  2016-09-27 14:12 ` [PATCH v1 0/4] Generalize PCI specific EAL function/structures Shreyansh Jain
@ 2016-09-27 14:12   ` Shreyansh Jain
  2016-09-27 14:12   ` [PATCH v1 2/4] eal: generalize PCI map/unmap resource " Shreyansh Jain
                     ` (4 subsequent siblings)
  5 siblings, 0 replies; 27+ messages in thread
From: Shreyansh Jain @ 2016-09-27 14:12 UTC (permalink / raw)
  To: dev; +Cc: viktorin, thomas.monjalon, david.marchand, Shreyansh Jain

From: Jan Viktorin <viktorin@rehivetech.com>

Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>

--
Changes since v0:
 - fix compilation error due to missing include
---
 lib/librte_eal/common/include/rte_dev.h | 12 ++++++++++++
 lib/librte_eal/common/include/rte_pci.h | 10 +---------
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h
index 95789f9..60bc91d 100644
--- a/lib/librte_eal/common/include/rte_dev.h
+++ b/lib/librte_eal/common/include/rte_dev.h
@@ -101,6 +101,18 @@ rte_pmd_debug_trace(const char *func_name, const char *fmt, ...)
 } while (0)
 
 
+/**
+ * Kernel driver passthrough type
+ */
+enum rte_kernel_driver {
+	RTE_KDRV_UNKNOWN = 0,
+	RTE_KDRV_IGB_UIO,
+	RTE_KDRV_VFIO,
+	RTE_KDRV_UIO_GENERIC,
+	RTE_KDRV_NIC_UIO,
+	RTE_KDRV_NONE,
+};
+
 /** Double linked list of device drivers. */
 TAILQ_HEAD(rte_driver_list, rte_driver);
 
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index fa74962..108000a 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -82,6 +82,7 @@ extern "C" {
 #include <stdint.h>
 #include <inttypes.h>
 
+#include <rte_dev.h>
 #include <rte_interrupts.h>
 
 TAILQ_HEAD(pci_device_list, rte_pci_device); /**< PCI devices in D-linked Q. */
@@ -141,15 +142,6 @@ struct rte_pci_addr {
 
 struct rte_devargs;
 
-enum rte_kernel_driver {
-	RTE_KDRV_UNKNOWN = 0,
-	RTE_KDRV_IGB_UIO,
-	RTE_KDRV_VFIO,
-	RTE_KDRV_UIO_GENERIC,
-	RTE_KDRV_NIC_UIO,
-	RTE_KDRV_NONE,
-};
-
 /**
  * A structure describing a PCI device.
  */
-- 
2.7.4

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

* [PATCH v1 2/4] eal: generalize PCI map/unmap resource to EAL
  2016-09-27 14:12 ` [PATCH v1 0/4] Generalize PCI specific EAL function/structures Shreyansh Jain
  2016-09-27 14:12   ` [PATCH v1 1/4] eal: generalize PCI kernel driver enum to EAL Shreyansh Jain
@ 2016-09-27 14:12   ` Shreyansh Jain
  2016-09-27 14:12   ` [PATCH v1 3/4] eal/linux: generalize PCI kernel unbinding driver " Shreyansh Jain
                     ` (3 subsequent siblings)
  5 siblings, 0 replies; 27+ messages in thread
From: Shreyansh Jain @ 2016-09-27 14:12 UTC (permalink / raw)
  To: dev; +Cc: viktorin, thomas.monjalon, david.marchand, Shreyansh Jain

From: Jan Viktorin <viktorin@rehivetech.com>

The functions pci_map_resource, pci_unmap_resource are generic so the
pci_* prefix can be omitted. The functions are moved to the
eal_common_dev.c so they can be reused by other infrastructure.

Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c             |  2 +-
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  8 +++++
 lib/librte_eal/common/eal_common_dev.c          | 39 +++++++++++++++++++++++++
 lib/librte_eal/common/eal_common_pci.c          | 39 -------------------------
 lib/librte_eal/common/eal_common_pci_uio.c      | 16 +++++-----
 lib/librte_eal/common/include/rte_dev.h         | 32 ++++++++++++++++++++
 lib/librte_eal/common/include/rte_pci.h         | 32 --------------------
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c       |  2 +-
 lib/librte_eal/linuxapp/eal/eal_pci_vfio.c      |  5 ++--
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  8 +++++
 10 files changed, 101 insertions(+), 82 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 374b68f..c021969 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -228,7 +228,7 @@ pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
 
 	/* if matching map is found, then use it */
 	offset = res_idx * pagesz;
-	mapaddr = pci_map_resource(NULL, fd, (off_t)offset,
+	mapaddr = rte_eal_map_resource(NULL, fd, (off_t)offset,
 			(size_t)dev->mem_resource[res_idx].len, 0);
 	close(fd);
 	if (mapaddr == MAP_FAILED)
diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index a335e04..6dd4186 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -162,3 +162,11 @@ DPDK_16.07 {
 	rte_thread_setname;
 
 } DPDK_16.04;
+
+DPDK_16.11 {
+	global:
+
+	rte_eal_map_resource;
+	rte_eal_unmap_resource;
+
+} DPDK_16.07;
diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index a8a4146..83aa1ca 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -36,6 +36,7 @@
 #include <string.h>
 #include <inttypes.h>
 #include <sys/queue.h>
+#include <sys/mman.h>
 
 #include <rte_dev.h>
 #include <rte_devargs.h>
@@ -150,3 +151,41 @@ rte_eal_vdev_uninit(const char *name)
 	RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
 	return -EINVAL;
 }
+
+/* map a particular resource from a file */
+void *
+rte_eal_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
+		 int additional_flags)
+{
+	void *mapaddr;
+
+	/* Map the 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, "  Device memory mapped at %p\n", mapaddr);
+
+	return mapaddr;
+}
+
+/* unmap a particular resource */
+void
+rte_eal_unmap_resource(void *requested_addr, size_t size)
+{
+	if (requested_addr == NULL)
+		return;
+
+	/* Unmap the 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, "  Device memory unmapped at %p\n",
+				requested_addr);
+}
diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 7248c38..0818b63 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -67,7 +67,6 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <sys/queue.h>
-#include <sys/mman.h>
 
 #include <rte_interrupts.h>
 #include <rte_log.h>
@@ -112,44 +111,6 @@ static struct rte_devargs *pci_devargs_lookup(struct rte_pci_device *dev)
 	return NULL;
 }
 
-/* map a particular resource from a file */
-void *
-pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
-		 int additional_flags)
-{
-	void *mapaddr;
-
-	/* Map the PCI memory resource of device */
-	mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
-			MAP_SHARED | additional_flags, fd, offset);
-	if (mapaddr == MAP_FAILED) {
-		RTE_LOG(ERR, EAL, "%s(): cannot mmap(%d, %p, 0x%lx, 0x%lx): %s (%p)\n",
-			__func__, fd, requested_addr,
-			(unsigned long)size, (unsigned long)offset,
-			strerror(errno), mapaddr);
-	} else
-		RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
-
-	return mapaddr;
-}
-
-/* unmap a particular resource */
-void
-pci_unmap_resource(void *requested_addr, size_t size)
-{
-	if (requested_addr == NULL)
-		return;
-
-	/* Unmap the PCI memory resource of device */
-	if (munmap(requested_addr, size)) {
-		RTE_LOG(ERR, EAL, "%s(): cannot munmap(%p, 0x%lx): %s\n",
-			__func__, requested_addr, (unsigned long)size,
-			strerror(errno));
-	} else
-		RTE_LOG(DEBUG, EAL, "  PCI memory unmapped at %p\n",
-				requested_addr);
-}
-
 /*
  * If vendor/device ID match, call the devinit() function of the
  * driver.
diff --git a/lib/librte_eal/common/eal_common_pci_uio.c b/lib/librte_eal/common/eal_common_pci_uio.c
index 367a681..3402518 100644
--- a/lib/librte_eal/common/eal_common_pci_uio.c
+++ b/lib/librte_eal/common/eal_common_pci_uio.c
@@ -75,9 +75,11 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 				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);
+			void *mapaddr = rte_eal_map_resource(
+						uio_res->maps[i].addr, fd,
+						(off_t)uio_res->maps[i].offset,
+						(size_t)uio_res->maps[i].size,
+						0);
 			/* fd is not needed in slave process, close it */
 			close(fd);
 			if (mapaddr != uio_res->maps[i].addr) {
@@ -88,11 +90,11 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 				if (mapaddr != MAP_FAILED) {
 					/* unmap addrs correctly mapped */
 					for (j = 0; j < i; j++)
-						pci_unmap_resource(
+						rte_eal_unmap_resource(
 							uio_res->maps[j].addr,
 							(size_t)uio_res->maps[j].size);
 					/* unmap addr wrongly mapped */
-					pci_unmap_resource(mapaddr,
+					rte_eal_unmap_resource(mapaddr,
 						(size_t)uio_res->maps[i].size);
 				}
 				return -1;
@@ -150,7 +152,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	return 0;
 error:
 	for (i = 0; i < map_idx; i++) {
-		pci_unmap_resource(uio_res->maps[i].addr,
+		rte_eal_unmap_resource(uio_res->maps[i].addr,
 				(size_t)uio_res->maps[i].size);
 		rte_free(uio_res->maps[i].path);
 	}
@@ -167,7 +169,7 @@ pci_uio_unmap(struct mapped_pci_resource *uio_res)
 		return;
 
 	for (i = 0; i != uio_res->nb_maps; i++) {
-		pci_unmap_resource(uio_res->maps[i].addr,
+		rte_eal_unmap_resource(uio_res->maps[i].addr,
 				(size_t)uio_res->maps[i].size);
 		if (rte_eal_process_type() == RTE_PROC_PRIMARY)
 			rte_free(uio_res->maps[i].path);
diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h
index 60bc91d..938f8c8 100644
--- a/lib/librte_eal/common/include/rte_dev.h
+++ b/lib/librte_eal/common/include/rte_dev.h
@@ -190,6 +190,38 @@ int rte_eal_vdev_init(const char *name, const char *args);
  */
 int rte_eal_vdev_uninit(const char *name);
 
+/**
+ * @internal
+ * Map a particular resource from a file.
+ *
+ * @param requested_addr
+ *      The starting address for the new mapping range.
+ * @param fd
+ *      The file descriptor.
+ * @param offset
+ *      The offset for the mapping range.
+ * @param size
+ *      The size for the mapping range.
+ * @param additional_flags
+ *      The additional flags for the mapping range.
+ * @return
+ *   - On success, the function returns a pointer to the mapped area.
+ *   - On error, the value MAP_FAILED is returned.
+ */
+void *rte_eal_map_resource(void *requested_addr, int fd, off_t offset,
+		size_t size, int additional_flags);
+
+/**
+ * @internal
+ * Unmap a particular resource.
+ *
+ * @param requested_addr
+ *      The address for the unmapping range.
+ * @param size
+ *      The size for the unmapping range.
+ */
+void rte_eal_unmap_resource(void *requested_addr, size_t size);
+
 #define DRIVER_EXPORT_NAME_ARRAY(n, idx) n##idx[]
 
 #define DRIVER_EXPORT_NAME(name, idx) \
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index 108000a..418fd6b 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -384,38 +384,6 @@ int rte_eal_pci_map_device(struct rte_pci_device *dev);
 void rte_eal_pci_unmap_device(struct rte_pci_device *dev);
 
 /**
- * @internal
- * Map a particular resource from a file.
- *
- * @param requested_addr
- *      The starting address for the new mapping range.
- * @param fd
- *      The file descriptor.
- * @param offset
- *      The offset for the mapping range.
- * @param size
- *      The size for the mapping range.
- * @param additional_flags
- *      The additional flags for the mapping range.
- * @return
- *   - On success, the function returns a pointer to the mapped area.
- *   - On error, the value MAP_FAILED is returned.
- */
-void *pci_map_resource(void *requested_addr, int fd, off_t offset,
-		size_t size, int additional_flags);
-
-/**
- * @internal
- * Unmap a particular resource.
- *
- * @param requested_addr
- *      The address for the unmapping range.
- * @param size
- *      The size for the unmapping range.
- */
-void pci_unmap_resource(void *requested_addr, size_t size);
-
-/**
  * 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_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 1786b75..5c34421 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -347,7 +347,7 @@ pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
 	if (pci_map_addr == NULL)
 		pci_map_addr = pci_find_max_end_va();
 
-	mapaddr = pci_map_resource(pci_map_addr, fd, 0,
+	mapaddr = rte_eal_map_resource(pci_map_addr, fd, 0,
 			(size_t)dev->mem_resource[res_idx].len, 0);
 	close(fd);
 	if (mapaddr == MAP_FAILED)
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
index 5f478c5..5ad8cbe 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
@@ -465,7 +465,8 @@ pci_vfio_map_resource(struct rte_pci_device *dev)
 			void *map_addr = NULL;
 			if (memreg[0].size) {
 				/* actual map of first part */
-				map_addr = pci_map_resource(bar_addr, vfio_dev_fd,
+				map_addr = rte_eal_map_resource(bar_addr,
+							    vfio_dev_fd,
 							    memreg[0].offset,
 							    memreg[0].size,
 							    MAP_FIXED);
@@ -477,7 +478,7 @@ pci_vfio_map_resource(struct rte_pci_device *dev)
 				void *second_addr = RTE_PTR_ADD(bar_addr,
 								memreg[1].offset -
 								(uintptr_t)reg.offset);
-				map_addr = pci_map_resource(second_addr,
+				map_addr = rte_eal_map_resource(second_addr,
 							    vfio_dev_fd, memreg[1].offset,
 							    memreg[1].size,
 							    MAP_FIXED);
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index db8c984..15e8332 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -166,3 +166,11 @@ DPDK_16.07 {
 	rte_thread_setname;
 
 } DPDK_16.04;
+
+DPDK_16.11 {
+	global:
+
+	rte_eal_map_resource;
+	rte_eal_unmap_resource;
+
+} DPDK_16.07;
-- 
2.7.4

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

* [PATCH v1 3/4] eal/linux: generalize PCI kernel unbinding driver to EAL
  2016-09-27 14:12 ` [PATCH v1 0/4] Generalize PCI specific EAL function/structures Shreyansh Jain
  2016-09-27 14:12   ` [PATCH v1 1/4] eal: generalize PCI kernel driver enum to EAL Shreyansh Jain
  2016-09-27 14:12   ` [PATCH v1 2/4] eal: generalize PCI map/unmap resource " Shreyansh Jain
@ 2016-09-27 14:12   ` Shreyansh Jain
  2016-09-27 14:12   ` [PATCH v1 4/4] eal/linux: generalize PCI kernel driver extraction " Shreyansh Jain
                     ` (2 subsequent siblings)
  5 siblings, 0 replies; 27+ messages in thread
From: Shreyansh Jain @ 2016-09-27 14:12 UTC (permalink / raw)
  To: dev; +Cc: viktorin, thomas.monjalon, david.marchand, Shreyansh Jain

From: Jan Viktorin <viktorin@rehivetech.com>

Generalize the PCI-specific pci_unbind_kernel_driver. It is now divided
into two parts. First, determination of the path and string identification
of the device to be unbound. Second, the actual unbind operation which is
generic.

Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/common/eal_private.h   | 13 +++++++++++++
 lib/librte_eal/linuxapp/eal/eal.c     | 26 ++++++++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_pci.c | 33 +++++++++------------------------
 3 files changed, 48 insertions(+), 24 deletions(-)

diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 19f7535..0740c0c 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -258,6 +258,19 @@ int rte_eal_dev_init(void);
 int rte_eal_check_module(const char *module_name);
 
 /**
+ * Unbind kernel driver bound to the device specified by the given devpath,
+ * and its string identification.
+ *
+ * @param devpath  path to the device directory ("/sys/.../devices/<name>")
+ * @param devid    identification of the device (<name>)
+ *
+ * @return
+ *      -1  unbind has failed
+ *       0  module has been unbound
+ */
+int rte_eal_unbind_kernel_driver(const char *devpath, const char *devid);
+
+/**
  * Get cpu core_id.
  *
  * This function is private to the EAL.
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index d5b81a3..a9c974b 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -933,3 +933,29 @@ rte_eal_check_module(const char *module_name)
 	/* Module has been found */
 	return 1;
 }
+
+int
+rte_eal_unbind_kernel_driver(const char *devpath, const char *devid)
+{
+	char filename[PATH_MAX];
+	FILE *f;
+
+	snprintf(filename, sizeof(filename),
+		 "%s/driver/unbind", devpath);
+
+	f = fopen(filename, "w");
+	if (f == NULL) /* device was not bound */
+		return 0;
+
+	if (fwrite(devid, strlen(devid), 1, f) == 0) {
+		RTE_LOG(ERR, EAL, "%s(): could not write to %s\n", __func__,
+				filename);
+		goto error;
+	}
+
+	fclose(f);
+	return 0;
+error:
+	fclose(f);
+	return -1;
+}
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index cd9de7c..4792d05 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -59,38 +59,23 @@ int
 pci_unbind_kernel_driver(struct rte_pci_device *dev)
 {
 	int n;
-	FILE *f;
-	char filename[PATH_MAX];
-	char buf[BUFSIZ];
+	char devpath[PATH_MAX];
+	char devid[BUFSIZ];
 	struct rte_pci_addr *loc = &dev->addr;
 
-	/* open /sys/bus/pci/devices/AAAA:BB:CC.D/driver */
-	snprintf(filename, sizeof(filename),
-		"%s/" PCI_PRI_FMT "/driver/unbind", pci_get_sysfs_path(),
+	/* devpath /sys/bus/pci/devices/AAAA:BB:CC.D */
+	snprintf(devpath, sizeof(devpath),
+		"%s/" PCI_PRI_FMT, pci_get_sysfs_path(),
 		loc->domain, loc->bus, loc->devid, loc->function);
 
-	f = fopen(filename, "w");
-	if (f == NULL) /* device was not bound */
-		return 0;
-
-	n = snprintf(buf, sizeof(buf), PCI_PRI_FMT "\n",
+	n = snprintf(devid, sizeof(devid), PCI_PRI_FMT "\n",
 	             loc->domain, loc->bus, loc->devid, loc->function);
-	if ((n < 0) || (n >= (int)sizeof(buf))) {
+	if ((n < 0) || (n >= (int)sizeof(devid))) {
 		RTE_LOG(ERR, EAL, "%s(): snprintf failed\n", __func__);
-		goto error;
-	}
-	if (fwrite(buf, n, 1, f) == 0) {
-		RTE_LOG(ERR, EAL, "%s(): could not write to %s\n", __func__,
-				filename);
-		goto error;
+		return -1;
 	}
 
-	fclose(f);
-	return 0;
-
-error:
-	fclose(f);
-	return -1;
+	return rte_eal_unbind_kernel_driver(devpath, devid);
 }
 
 static int
-- 
2.7.4

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

* [PATCH v1 4/4] eal/linux: generalize PCI kernel driver extraction to EAL
  2016-09-27 14:12 ` [PATCH v1 0/4] Generalize PCI specific EAL function/structures Shreyansh Jain
                     ` (2 preceding siblings ...)
  2016-09-27 14:12   ` [PATCH v1 3/4] eal/linux: generalize PCI kernel unbinding driver " Shreyansh Jain
@ 2016-09-27 14:12   ` Shreyansh Jain
  2016-09-30 15:31   ` [PATCH v1 0/4] Generalize PCI specific EAL function/structures David Marchand
  2016-10-14 10:55   ` [PATCH v2 " Shreyansh Jain
  5 siblings, 0 replies; 27+ messages in thread
From: Shreyansh Jain @ 2016-09-27 14:12 UTC (permalink / raw)
  To: dev; +Cc: viktorin, thomas.monjalon, david.marchand, Shreyansh Jain

From: Jan Viktorin <viktorin@rehivetech.com>

Generalize the PCI-specific pci_get_kernel_driver_by_path. The function
is general enough, we have just moved it to eal.c, changed the prefix to
rte_eal and provided it privately to other parts of EAL.

Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/common/eal_private.h   | 14 ++++++++++++++
 lib/librte_eal/linuxapp/eal/eal.c     | 29 +++++++++++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_pci.c | 31 +------------------------------
 3 files changed, 44 insertions(+), 30 deletions(-)

diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 0740c0c..5ea30a2 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -271,6 +271,20 @@ int rte_eal_check_module(const char *module_name);
 int rte_eal_unbind_kernel_driver(const char *devpath, const char *devid);
 
 /**
+ * Extrat the kernel driver name from the absolute path to the driver.
+ *
+ * @param filename  path to the driver ("<path-to-device>/driver")
+ * @path  dri_name  target buffer where to place the driver name
+ *                  (should be at least PATH_MAX long)
+ *
+ * @return
+ *      -1   on failure
+ *       0   when successful
+ *       1   when there is no such driver
+ */
+int rte_eal_get_kernel_driver_by_path(const char *filename, char *dri_name);
+
+/**
  * Get cpu core_id.
  *
  * This function is private to the EAL.
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index a9c974b..956afda 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -959,3 +959,32 @@ error:
 	fclose(f);
 	return -1;
 }
+
+int
+rte_eal_get_kernel_driver_by_path(const char *filename, char *dri_name)
+{
+	int count;
+	char path[PATH_MAX];
+	char *name;
+
+	if (!filename || !dri_name)
+		return -1;
+
+	count = readlink(filename, path, PATH_MAX);
+	if (count >= PATH_MAX)
+		return -1;
+
+	/* For device does not have a driver */
+	if (count < 0)
+		return 1;
+
+	path[count] = '\0';
+
+	name = strrchr(path, '/');
+	if (name) {
+		strncpy(dri_name, name + 1, strlen(name + 1) + 1);
+		return 0;
+	}
+
+	return -1;
+}
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index 4792d05..f923e42 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -78,35 +78,6 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev)
 	return rte_eal_unbind_kernel_driver(devpath, devid);
 }
 
-static int
-pci_get_kernel_driver_by_path(const char *filename, char *dri_name)
-{
-	int count;
-	char path[PATH_MAX];
-	char *name;
-
-	if (!filename || !dri_name)
-		return -1;
-
-	count = readlink(filename, path, PATH_MAX);
-	if (count >= PATH_MAX)
-		return -1;
-
-	/* For device does not have a driver */
-	if (count < 0)
-		return 1;
-
-	path[count] = '\0';
-
-	name = strrchr(path, '/');
-	if (name) {
-		strncpy(dri_name, name + 1, strlen(name + 1) + 1);
-		return 0;
-	}
-
-	return -1;
-}
-
 /* Map pci device */
 int
 rte_eal_pci_map_device(struct rte_pci_device *dev)
@@ -354,7 +325,7 @@ pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus,
 
 	/* parse driver */
 	snprintf(filename, sizeof(filename), "%s/driver", dirname);
-	ret = pci_get_kernel_driver_by_path(filename, driver);
+	ret = rte_eal_get_kernel_driver_by_path(filename, driver);
 	if (ret < 0) {
 		RTE_LOG(ERR, EAL, "Fail to get kernel driver\n");
 		free(dev);
-- 
2.7.4

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

* Re: [PATCH v1 0/4] Generalize PCI specific EAL function/structures
  2016-09-27 14:12 ` [PATCH v1 0/4] Generalize PCI specific EAL function/structures Shreyansh Jain
                     ` (3 preceding siblings ...)
  2016-09-27 14:12   ` [PATCH v1 4/4] eal/linux: generalize PCI kernel driver extraction " Shreyansh Jain
@ 2016-09-30 15:31   ` David Marchand
  2016-10-03  5:37     ` Shreyansh Jain
  2016-10-13  6:47     ` Shreyansh Jain
  2016-10-14 10:55   ` [PATCH v2 " Shreyansh Jain
  5 siblings, 2 replies; 27+ messages in thread
From: David Marchand @ 2016-09-30 15:31 UTC (permalink / raw)
  To: Shreyansh Jain; +Cc: dev, Jan Viktorin, Thomas Monjalon

On Tue, Sep 27, 2016 at 4:12 PM, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
> (I rebased these over HEAD 7b3c4f3)
>
> These patches were initially part of Jan's original series on SoC
> Framework ([1],[2]). An update to that series, without these patches,
> was posted here [3].
>
> Main motivation for these is aim of introducing a non-PCI centric
> subsystem in EAL. As of now the first usecase is SoC, but not limited to
> it.
>
> 4 patches in this series are independent of each other, as well as SoC
> framework. All these focus on generalizing some structure or functions
> present with the PCI specific code to EAL Common area (or splitting a
> function to be more userful).

Those patches move linux specifics (binding pci devices using sysfs)
to common infrastucture.
We have no proper hotplug support on bsd, but if we had some common
code we should at least try to make the apis generic.


-- 
David Marchand

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

* Re: [PATCH v1 0/4] Generalize PCI specific EAL function/structures
  2016-09-30 15:31   ` [PATCH v1 0/4] Generalize PCI specific EAL function/structures David Marchand
@ 2016-10-03  5:37     ` Shreyansh Jain
  2016-10-03 13:12       ` Jan Viktorin
  2016-10-03 13:36       ` Thomas Monjalon
  2016-10-13  6:47     ` Shreyansh Jain
  1 sibling, 2 replies; 27+ messages in thread
From: Shreyansh Jain @ 2016-10-03  5:37 UTC (permalink / raw)
  To: David Marchand; +Cc: dev, Jan Viktorin, Thomas Monjalon

Hi David,

On Friday 30 September 2016 09:01 PM, David Marchand wrote:
> On Tue, Sep 27, 2016 at 4:12 PM, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
>> (I rebased these over HEAD 7b3c4f3)
>>
>> These patches were initially part of Jan's original series on SoC
>> Framework ([1],[2]). An update to that series, without these patches,
>> was posted here [3].
>>
>> Main motivation for these is aim of introducing a non-PCI centric
>> subsystem in EAL. As of now the first usecase is SoC, but not limited to
>> it.
>>
>> 4 patches in this series are independent of each other, as well as SoC
>> framework. All these focus on generalizing some structure or functions
>> present with the PCI specific code to EAL Common area (or splitting a
>> function to be more userful).
>
> Those patches move linux specifics (binding pci devices using sysfs)
> to common infrastucture.
> We have no proper hotplug support on bsd, but if we had some common
> code we should at least try to make the apis generic.
>

I am not sure if I understood your point well. Just to confirm - you are 
stating that the movement done in the patches might not suit BSD. 
Probably you are talking about (Patch 3/4 and 4/4).
Is my understanding correct?

So, movement to just Linux area is not enough?
I am not well versed with BSD way of doing something similar so if 
someone can point it out, I can integrate that. (I will investigate it 
at my end as well).

This patchset makes the PCI->EAL movement *only* for Linux for sysfs 
bind/unbind. (I should add this to cover letter, at the least).

-
Shreyansh

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

* Re: [PATCH v1 0/4] Generalize PCI specific EAL function/structures
  2016-10-03  5:37     ` Shreyansh Jain
@ 2016-10-03 13:12       ` Jan Viktorin
  2016-10-03 13:36       ` Thomas Monjalon
  1 sibling, 0 replies; 27+ messages in thread
From: Jan Viktorin @ 2016-10-03 13:12 UTC (permalink / raw)
  To: David Marchand; +Cc: Shreyansh Jain, dev, Thomas Monjalon

On Mon, 3 Oct 2016 11:07:43 +0530
Shreyansh Jain <shreyansh.jain@nxp.com> wrote:

> Hi David,
> 
> On Friday 30 September 2016 09:01 PM, David Marchand wrote:
> > On Tue, Sep 27, 2016 at 4:12 PM, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:  
> >> (I rebased these over HEAD 7b3c4f3)
> >>
> >> These patches were initially part of Jan's original series on SoC
> >> Framework ([1],[2]). An update to that series, without these patches,
> >> was posted here [3].
> >>
> >> Main motivation for these is aim of introducing a non-PCI centric
> >> subsystem in EAL. As of now the first usecase is SoC, but not limited to
> >> it.
> >>
> >> 4 patches in this series are independent of each other, as well as SoC
> >> framework. All these focus on generalizing some structure or functions
> >> present with the PCI specific code to EAL Common area (or splitting a
> >> function to be more userful).  
> >
> > Those patches move linux specifics (binding pci devices using sysfs)
> > to common infrastucture.
> > We have no proper hotplug support on bsd, but if we had some common
> > code we should at least try to make the apis generic.
> >  
> 
> I am not sure if I understood your point well. Just to confirm - you are 

I don't clearly see the point, either.

Jan

> stating that the movement done in the patches might not suit BSD. 
> Probably you are talking about (Patch 3/4 and 4/4).
> Is my understanding correct?
> 
> So, movement to just Linux area is not enough?
> I am not well versed with BSD way of doing something similar so if 
> someone can point it out, I can integrate that. (I will investigate it 
> at my end as well).
> 
> This patchset makes the PCI->EAL movement *only* for Linux for sysfs 
> bind/unbind. (I should add this to cover letter, at the least).
> 
> -
> Shreyansh



-- 
   Jan Viktorin                  E-mail: Viktorin@RehiveTech.com
   System Architect              Web:    www.RehiveTech.com
   RehiveTech
   Brno, Czech Republic

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

* Re: [PATCH v1 0/4] Generalize PCI specific EAL function/structures
  2016-10-03  5:37     ` Shreyansh Jain
  2016-10-03 13:12       ` Jan Viktorin
@ 2016-10-03 13:36       ` Thomas Monjalon
  2016-10-06 11:43         ` Shreyansh Jain
  1 sibling, 1 reply; 27+ messages in thread
From: Thomas Monjalon @ 2016-10-03 13:36 UTC (permalink / raw)
  To: Shreyansh Jain; +Cc: David Marchand, dev, Jan Viktorin

2016-10-03 11:07, Shreyansh Jain:
> Hi David,
> 
> On Friday 30 September 2016 09:01 PM, David Marchand wrote:
> > On Tue, Sep 27, 2016 at 4:12 PM, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
> >> (I rebased these over HEAD 7b3c4f3)
> >>
> >> These patches were initially part of Jan's original series on SoC
> >> Framework ([1],[2]). An update to that series, without these patches,
> >> was posted here [3].
> >>
> >> Main motivation for these is aim of introducing a non-PCI centric
> >> subsystem in EAL. As of now the first usecase is SoC, but not limited to
> >> it.
> >>
> >> 4 patches in this series are independent of each other, as well as SoC
> >> framework. All these focus on generalizing some structure or functions
> >> present with the PCI specific code to EAL Common area (or splitting a
> >> function to be more userful).
> >
> > Those patches move linux specifics (binding pci devices using sysfs)
> > to common infrastucture.
> > We have no proper hotplug support on bsd, but if we had some common
> > code we should at least try to make the apis generic.
> >
> 
> I am not sure if I understood your point well. Just to confirm - you are 
> stating that the movement done in the patches might not suit BSD. 
> Probably you are talking about (Patch 3/4 and 4/4).
> Is my understanding correct?
> 
> So, movement to just Linux area is not enough?
> I am not well versed with BSD way of doing something similar so if 
> someone can point it out, I can integrate that. (I will investigate it 
> at my end as well).
> 
> This patchset makes the PCI->EAL movement *only* for Linux for sysfs 
> bind/unbind. (I should add this to cover letter, at the least).

The concern is about function declarations in
	lib/librte_eal/common/eal_private.h
We cannot be sure it can be applicable to something else than Linux.
As it is implemented in Linux only, it should not be in a common header.

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

* Re: [PATCH v1 0/4] Generalize PCI specific EAL function/structures
  2016-10-03 13:36       ` Thomas Monjalon
@ 2016-10-06 11:43         ` Shreyansh Jain
  2016-10-06 13:01           ` Thomas Monjalon
  0 siblings, 1 reply; 27+ messages in thread
From: Shreyansh Jain @ 2016-10-06 11:43 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: David Marchand, dev, Jan Viktorin

Hi Thomas,

On Monday 03 October 2016 07:06 PM, Thomas Monjalon wrote:
> 2016-10-03 11:07, Shreyansh Jain:
>> Hi David,
>>
>> On Friday 30 September 2016 09:01 PM, David Marchand wrote:
>>> On Tue, Sep 27, 2016 at 4:12 PM, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
>>>> (I rebased these over HEAD 7b3c4f3)
>>>>
>>>> These patches were initially part of Jan's original series on SoC
>>>> Framework ([1],[2]). An update to that series, without these patches,
>>>> was posted here [3].
>>>>
>>>> Main motivation for these is aim of introducing a non-PCI centric
>>>> subsystem in EAL. As of now the first usecase is SoC, but not limited to
>>>> it.
>>>>
>>>> 4 patches in this series are independent of each other, as well as SoC
>>>> framework. All these focus on generalizing some structure or functions
>>>> present with the PCI specific code to EAL Common area (or splitting a
>>>> function to be more userful).
>>>
>>> Those patches move linux specifics (binding pci devices using sysfs)
>>> to common infrastucture.
>>> We have no proper hotplug support on bsd, but if we had some common
>>> code we should at least try to make the apis generic.
>>>
>>
>> I am not sure if I understood your point well. Just to confirm - you are
>> stating that the movement done in the patches might not suit BSD.
>> Probably you are talking about (Patch 3/4 and 4/4).
>> Is my understanding correct?
>>
>> So, movement to just Linux area is not enough?
>> I am not well versed with BSD way of doing something similar so if
>> someone can point it out, I can integrate that. (I will investigate it
>> at my end as well).
>>
>> This patchset makes the PCI->EAL movement *only* for Linux for sysfs
>> bind/unbind. (I should add this to cover letter, at the least).
>
> The concern is about function declarations in
> 	lib/librte_eal/common/eal_private.h
> We cannot be sure it can be applicable to something else than Linux.
> As it is implemented in Linux only, it should not be in a common header.
>

Ok. But, digging a little I found at least one more similar case.
'rte_eal_check_module()' which is present in the linuxapp/eal.c and has 
existence in common, but no parallel implementation for BSD exists. This 
function is accessing /sys/modules - which might be Linux specific.

It seems to be a pretty old entry though (dating back to 2014).

-
Shreyansh

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

* Re: [PATCH v1 0/4] Generalize PCI specific EAL function/structures
  2016-10-06 11:43         ` Shreyansh Jain
@ 2016-10-06 13:01           ` Thomas Monjalon
  0 siblings, 0 replies; 27+ messages in thread
From: Thomas Monjalon @ 2016-10-06 13:01 UTC (permalink / raw)
  To: Shreyansh Jain; +Cc: David Marchand, dev, Jan Viktorin

2016-10-06 17:13, Shreyansh Jain:
> Hi Thomas,
> 
> On Monday 03 October 2016 07:06 PM, Thomas Monjalon wrote:
> > 2016-10-03 11:07, Shreyansh Jain:
> >> Hi David,
> >>
> >> On Friday 30 September 2016 09:01 PM, David Marchand wrote:
> >>> Those patches move linux specifics (binding pci devices using sysfs)
> >>> to common infrastucture.
> >>> We have no proper hotplug support on bsd, but if we had some common
> >>> code we should at least try to make the apis generic.
> >>>
> >>
> >> I am not sure if I understood your point well. Just to confirm - you are
> >> stating that the movement done in the patches might not suit BSD.
> >> Probably you are talking about (Patch 3/4 and 4/4).
> >> Is my understanding correct?
> >>
> >> So, movement to just Linux area is not enough?
> >> I am not well versed with BSD way of doing something similar so if
> >> someone can point it out, I can integrate that. (I will investigate it
> >> at my end as well).
> >>
> >> This patchset makes the PCI->EAL movement *only* for Linux for sysfs
> >> bind/unbind. (I should add this to cover letter, at the least).
> >
> > The concern is about function declarations in
> > 	lib/librte_eal/common/eal_private.h
> > We cannot be sure it can be applicable to something else than Linux.
> > As it is implemented in Linux only, it should not be in a common header.
> >
> 
> Ok. But, digging a little I found at least one more similar case.
> 'rte_eal_check_module()' which is present in the linuxapp/eal.c and has 
> existence in common, but no parallel implementation for BSD exists. This 
> function is accessing /sys/modules - which might be Linux specific.

Yes the BSD implementation is missing.
But the common function prototype makes sense as it can be called by an
application and could be implemented for BSD.

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

* Re: [PATCH v1 0/4] Generalize PCI specific EAL function/structures
  2016-09-30 15:31   ` [PATCH v1 0/4] Generalize PCI specific EAL function/structures David Marchand
  2016-10-03  5:37     ` Shreyansh Jain
@ 2016-10-13  6:47     ` Shreyansh Jain
  1 sibling, 0 replies; 27+ messages in thread
From: Shreyansh Jain @ 2016-10-13  6:47 UTC (permalink / raw)
  To: David Marchand; +Cc: dev, Jan Viktorin, Thomas Monjalon

Hi David,

On Friday 30 September 2016 09:01 PM, David Marchand wrote:
> On Tue, Sep 27, 2016 at 4:12 PM, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
>> (I rebased these over HEAD 7b3c4f3)
>>
>> These patches were initially part of Jan's original series on SoC
>> Framework ([1],[2]). An update to that series, without these patches,
>> was posted here [3].
>>
>> Main motivation for these is aim of introducing a non-PCI centric
>> subsystem in EAL. As of now the first usecase is SoC, but not limited to
>> it.
>>
>> 4 patches in this series are independent of each other, as well as SoC
>> framework. All these focus on generalizing some structure or functions
>> present with the PCI specific code to EAL Common area (or splitting a
>> function to be more userful).
>
> Those patches move linux specifics (binding pci devices using sysfs)
> to common infrastucture.
> We have no proper hotplug support on bsd, but if we had some common
> code we should at least try to make the apis generic.
>

rte_eal_unbind_kernel_driver() defined in the patch is essentially a 
wrapper which can be implemented for Linux as well as BSD. Just that in 
this patch a ENOTSUP implementation of this was not given for BSD.

I can think of two options:

1. Implement a ENOTSUPP code for BSD and allow 
rte_eal_unbind_kernel_driver() as part of common/eal_private header.
implement rte_eal_unbind_kernel_driver in BSD as not supported.

2. That we keep this contained within Linux area:
   linux_unbind_kernel_driver <-- pci_unbind_kernel_driver
                            ^
                             `-- xxx_unbind_kernel_driver

   bsd_unbind_kernel_driver <-- pci_unbind_kernel_driver
     `-> this returns ENOTSUPP


@Jan: any additions/suggestions?

-
Shreyansh

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

* [PATCH v2 0/4] Generalize PCI specific EAL function/structures
  2016-09-27 14:12 ` [PATCH v1 0/4] Generalize PCI specific EAL function/structures Shreyansh Jain
                     ` (4 preceding siblings ...)
  2016-09-30 15:31   ` [PATCH v1 0/4] Generalize PCI specific EAL function/structures David Marchand
@ 2016-10-14 10:55   ` Shreyansh Jain
  2016-10-14 10:55     ` [PATCH v2 1/4] eal: generalize PCI kernel driver enum to EAL Shreyansh Jain
                       ` (3 more replies)
  5 siblings, 4 replies; 27+ messages in thread
From: Shreyansh Jain @ 2016-10-14 10:55 UTC (permalink / raw)
  To: dev; +Cc: viktorin, thomas.monjalon, david.marchand, Shreyansh Jain

(Rebased these over HEAD fed622dfd)

These patches were initially part of Jan's original series on SoC
Framework ([1],[2]). An update to that series, without these patches,
was posted here [3].

Main motivation for these is aim of introducing a non-PCI centric
subsystem in EAL. As of now the first usecase is SoC, but not limited to
it.

4 patches in this series are independent of each other, as well as SoC
framework. All these focus on generalizing some structure or functions
present with the PCI specific code to EAL Common area (or splitting a
function to be more userful).

 - 0001: move the rte_kernel_driver enum from rte_pci to rte_dev. As of
   now this structure is embedded in rte_pci_device, but, going ahead it
   can be part of other rte_xxx_device structures. Either way, it has no
   impact on PCI.
 - 0002: Functions pci_map_resource/pci_unmap_resource are moved to EAL
   common as rte_eal_map_resource/rte_eal_unmap_resource, respectively.
 - 0003: Split the  pci_unbind_kernel_driver into two, still working on
   the PCI BDF sysfs layout, first handles the file path (and validations)
   and second does the actual unbind. The second part might be useful in
   case of non-PCI layouts.
   -- This is useful for other subsystem, parallel to PCI, which require
    | MMAP support.
    `- an equivalent NOTSUP function for BSD has been added in v1
 - 0004: Move pci_get_kernel_driver_by_path to
   rte_eal_get_kernel_driver_by_path in EAL common. This function is
   generic for any sysfs compliant driver and can be re-used by other
   non-PCI subsystem.
    `- an equivalent NOTSUP function for BSD has been added in v1

Changes since v1
 - Rebased over master (fed622dfd)
 - Added dummy functions for BSD for unbind and kernel driver fetch
   functions (patches 003, 004)

Changes since v0 [4]:
 - Fix for checkpatch and check-git-log
 - Fix missing include in patch 0001
 - Drop patch 2 for splitting sysfs into a sub-function taking file
   handle. This patch doesn't really fit into the model of PCI->EAL
   movement of generic functions which other patches relate to.
   Also, taking cue from review comment [5], it might not have a
   viable use-case as of now.

[1] http://dpdk.org/ml/archives/dev/2016-January/030915.html
[2] http://www.dpdk.org/ml/archives/dev/2016-May/038486.html
[3] http://dpdk.org/ml/archives/dev/2016-August/045993.html
[4] http://dpdk.org/ml/archives/dev/2016-September/046035.html
[5] http://dpdk.org/ml/archives/dev/2016-September/046041.html

Jan Viktorin (4):
  eal: generalize PCI kernel driver enum to EAL
  eal: generalize PCI map/unmap resource to EAL
  eal/linux: generalize PCI kernel unbinding driver to EAL
  eal/linux: generalize PCI kernel driver extraction to EAL

 lib/librte_eal/bsdapp/eal/eal.c                 | 14 ++++++
 lib/librte_eal/bsdapp/eal/eal_pci.c             |  6 +--
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  2 +
 lib/librte_eal/common/eal_common_dev.c          | 39 ++++++++++++++++
 lib/librte_eal/common/eal_common_pci.c          | 39 ----------------
 lib/librte_eal/common/eal_common_pci_uio.c      | 16 ++++---
 lib/librte_eal/common/eal_private.h             | 27 +++++++++++
 lib/librte_eal/common/include/rte_dev.h         | 44 ++++++++++++++++++
 lib/librte_eal/common/include/rte_pci.h         | 41 ----------------
 lib/librte_eal/linuxapp/eal/eal.c               | 55 ++++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_pci.c           | 62 ++++---------------------
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c       |  2 +-
 lib/librte_eal/linuxapp/eal/eal_pci_vfio.c      |  5 +-
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  2 +
 14 files changed, 208 insertions(+), 146 deletions(-)

-- 
2.7.4

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

* [PATCH v2 1/4] eal: generalize PCI kernel driver enum to EAL
  2016-10-14 10:55   ` [PATCH v2 " Shreyansh Jain
@ 2016-10-14 10:55     ` Shreyansh Jain
  2016-10-14 10:55     ` [PATCH v2 2/4] eal: generalize PCI map/unmap resource " Shreyansh Jain
                       ` (2 subsequent siblings)
  3 siblings, 0 replies; 27+ messages in thread
From: Shreyansh Jain @ 2016-10-14 10:55 UTC (permalink / raw)
  To: dev; +Cc: viktorin, thomas.monjalon, david.marchand, Shreyansh Jain

From: Jan Viktorin <viktorin@rehivetech.com>

Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>

--
Changes since v0:
 - fix compilation error due to missing include
---
 lib/librte_eal/common/include/rte_dev.h | 12 ++++++++++++
 lib/librte_eal/common/include/rte_pci.h |  9 ---------
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h
index b3873bd..e73b0fa 100644
--- a/lib/librte_eal/common/include/rte_dev.h
+++ b/lib/librte_eal/common/include/rte_dev.h
@@ -109,6 +109,18 @@ struct rte_mem_resource {
 	void *addr;         /**< Virtual address, NULL when not mapped. */
 };
 
+/**
+ * Kernel driver passthrough type
+ */
+enum rte_kernel_driver {
+	RTE_KDRV_UNKNOWN = 0,
+	RTE_KDRV_IGB_UIO,
+	RTE_KDRV_VFIO,
+	RTE_KDRV_UIO_GENERIC,
+	RTE_KDRV_NIC_UIO,
+	RTE_KDRV_NONE,
+};
+
 /** Double linked list of device drivers. */
 TAILQ_HEAD(rte_driver_list, rte_driver);
 /** Double linked list of devices. */
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index 9ce8847..2c7046f 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -135,15 +135,6 @@ struct rte_pci_addr {
 
 struct rte_devargs;
 
-enum rte_kernel_driver {
-	RTE_KDRV_UNKNOWN = 0,
-	RTE_KDRV_IGB_UIO,
-	RTE_KDRV_VFIO,
-	RTE_KDRV_UIO_GENERIC,
-	RTE_KDRV_NIC_UIO,
-	RTE_KDRV_NONE,
-};
-
 /**
  * A structure describing a PCI device.
  */
-- 
2.7.4

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

* [PATCH v2 2/4] eal: generalize PCI map/unmap resource to EAL
  2016-10-14 10:55   ` [PATCH v2 " Shreyansh Jain
  2016-10-14 10:55     ` [PATCH v2 1/4] eal: generalize PCI kernel driver enum to EAL Shreyansh Jain
@ 2016-10-14 10:55     ` Shreyansh Jain
  2016-10-14 10:55     ` [PATCH v2 3/4] eal/linux: generalize PCI kernel unbinding driver " Shreyansh Jain
  2016-10-14 10:55     ` [PATCH v2 4/4] eal/linux: generalize PCI kernel driver extraction " Shreyansh Jain
  3 siblings, 0 replies; 27+ messages in thread
From: Shreyansh Jain @ 2016-10-14 10:55 UTC (permalink / raw)
  To: dev; +Cc: viktorin, thomas.monjalon, david.marchand, Shreyansh Jain

From: Jan Viktorin <viktorin@rehivetech.com>

The functions pci_map_resource, pci_unmap_resource are generic so the
pci_* prefix can be omitted. The functions are moved to the
eal_common_dev.c so they can be reused by other infrastructure.

Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c             |  2 +-
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  2 ++
 lib/librte_eal/common/eal_common_dev.c          | 39 +++++++++++++++++++++++++
 lib/librte_eal/common/eal_common_pci.c          | 39 -------------------------
 lib/librte_eal/common/eal_common_pci_uio.c      | 16 +++++-----
 lib/librte_eal/common/include/rte_dev.h         | 32 ++++++++++++++++++++
 lib/librte_eal/common/include/rte_pci.h         | 32 --------------------
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c       |  2 +-
 lib/librte_eal/linuxapp/eal/eal_pci_vfio.c      |  5 ++--
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  2 ++
 10 files changed, 89 insertions(+), 82 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 8b3ed88..7ed0115 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -228,7 +228,7 @@ pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
 
 	/* if matching map is found, then use it */
 	offset = res_idx * pagesz;
-	mapaddr = pci_map_resource(NULL, fd, (off_t)offset,
+	mapaddr = rte_eal_map_resource(NULL, fd, (off_t)offset,
 			(size_t)dev->mem_resource[res_idx].len, 0);
 	close(fd);
 	if (mapaddr == MAP_FAILED)
diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 2f81f7c..11d9f59 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -170,6 +170,8 @@ DPDK_16.11 {
 	rte_delay_us_callback_register;
 	rte_eal_dev_attach;
 	rte_eal_dev_detach;
+	rte_eal_map_resource;
+	rte_eal_unmap_resource;
 	rte_eal_vdrv_register;
 	rte_eal_vdrv_unregister;
 
diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 4f3b493..457d227 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -36,6 +36,7 @@
 #include <string.h>
 #include <inttypes.h>
 #include <sys/queue.h>
+#include <sys/mman.h>
 
 #include <rte_dev.h>
 #include <rte_devargs.h>
@@ -151,3 +152,41 @@ err:
 	RTE_LOG(ERR, EAL, "Driver cannot detach the device (%s)\n", name);
 	return -EINVAL;
 }
+
+/* map a particular resource from a file */
+void *
+rte_eal_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
+		 int additional_flags)
+{
+	void *mapaddr;
+
+	/* Map the 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, "  Device memory mapped at %p\n", mapaddr);
+
+	return mapaddr;
+}
+
+/* unmap a particular resource */
+void
+rte_eal_unmap_resource(void *requested_addr, size_t size)
+{
+	if (requested_addr == NULL)
+		return;
+
+	/* Unmap the 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, "  Device memory unmapped at %p\n",
+				requested_addr);
+}
diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 638cd86..464acc1 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -67,7 +67,6 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <sys/queue.h>
-#include <sys/mman.h>
 
 #include <rte_interrupts.h>
 #include <rte_log.h>
@@ -114,44 +113,6 @@ static struct rte_devargs *pci_devargs_lookup(struct rte_pci_device *dev)
 	return NULL;
 }
 
-/* map a particular resource from a file */
-void *
-pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
-		 int additional_flags)
-{
-	void *mapaddr;
-
-	/* Map the PCI memory resource of device */
-	mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
-			MAP_SHARED | additional_flags, fd, offset);
-	if (mapaddr == MAP_FAILED) {
-		RTE_LOG(ERR, EAL, "%s(): cannot mmap(%d, %p, 0x%lx, 0x%lx): %s (%p)\n",
-			__func__, fd, requested_addr,
-			(unsigned long)size, (unsigned long)offset,
-			strerror(errno), mapaddr);
-	} else
-		RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
-
-	return mapaddr;
-}
-
-/* unmap a particular resource */
-void
-pci_unmap_resource(void *requested_addr, size_t size)
-{
-	if (requested_addr == NULL)
-		return;
-
-	/* Unmap the PCI memory resource of device */
-	if (munmap(requested_addr, size)) {
-		RTE_LOG(ERR, EAL, "%s(): cannot munmap(%p, 0x%lx): %s\n",
-			__func__, requested_addr, (unsigned long)size,
-			strerror(errno));
-	} else
-		RTE_LOG(DEBUG, EAL, "  PCI memory unmapped at %p\n",
-				requested_addr);
-}
-
 /*
  * If vendor/device ID match, call the probe() function of the
  * driver.
diff --git a/lib/librte_eal/common/eal_common_pci_uio.c b/lib/librte_eal/common/eal_common_pci_uio.c
index 367a681..3402518 100644
--- a/lib/librte_eal/common/eal_common_pci_uio.c
+++ b/lib/librte_eal/common/eal_common_pci_uio.c
@@ -75,9 +75,11 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 				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);
+			void *mapaddr = rte_eal_map_resource(
+						uio_res->maps[i].addr, fd,
+						(off_t)uio_res->maps[i].offset,
+						(size_t)uio_res->maps[i].size,
+						0);
 			/* fd is not needed in slave process, close it */
 			close(fd);
 			if (mapaddr != uio_res->maps[i].addr) {
@@ -88,11 +90,11 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 				if (mapaddr != MAP_FAILED) {
 					/* unmap addrs correctly mapped */
 					for (j = 0; j < i; j++)
-						pci_unmap_resource(
+						rte_eal_unmap_resource(
 							uio_res->maps[j].addr,
 							(size_t)uio_res->maps[j].size);
 					/* unmap addr wrongly mapped */
-					pci_unmap_resource(mapaddr,
+					rte_eal_unmap_resource(mapaddr,
 						(size_t)uio_res->maps[i].size);
 				}
 				return -1;
@@ -150,7 +152,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	return 0;
 error:
 	for (i = 0; i < map_idx; i++) {
-		pci_unmap_resource(uio_res->maps[i].addr,
+		rte_eal_unmap_resource(uio_res->maps[i].addr,
 				(size_t)uio_res->maps[i].size);
 		rte_free(uio_res->maps[i].path);
 	}
@@ -167,7 +169,7 @@ pci_uio_unmap(struct mapped_pci_resource *uio_res)
 		return;
 
 	for (i = 0; i != uio_res->nb_maps; i++) {
-		pci_unmap_resource(uio_res->maps[i].addr,
+		rte_eal_unmap_resource(uio_res->maps[i].addr,
 				(size_t)uio_res->maps[i].size);
 		if (rte_eal_process_type() == RTE_PROC_PRIMARY)
 			rte_free(uio_res->maps[i].path);
diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h
index e73b0fa..277c07b 100644
--- a/lib/librte_eal/common/include/rte_dev.h
+++ b/lib/librte_eal/common/include/rte_dev.h
@@ -234,6 +234,38 @@ int rte_eal_dev_attach(const char *name, const char *devargs);
  */
 int rte_eal_dev_detach(const char *name);
 
+/*
+ * @internal
+ * Map a particular resource from a file.
+ *
+ * @param requested_addr
+ *      The starting address for the new mapping range.
+ * @param fd
+ *      The file descriptor.
+ * @param offset
+ *      The offset for the mapping range.
+ * @param size
+ *      The size for the mapping range.
+ * @param additional_flags
+ *      The additional flags for the mapping range.
+ * @return
+ *   - On success, the function returns a pointer to the mapped area.
+ *   - On error, the value MAP_FAILED is returned.
+ */
+void *rte_eal_map_resource(void *requested_addr, int fd, off_t offset,
+			   size_t size, int additional_flags);
+
+/**
+ * @internal
+ * Unmap a particular resource.
+ *
+ * @param requested_addr
+ *      The address for the unmapping range.
+ * @param size
+ *      The size for the unmapping range.
+ */
+void rte_eal_unmap_resource(void *requested_addr, size_t size);
+
 #define RTE_PMD_EXPORT_NAME_ARRAY(n, idx) n##idx[]
 
 #define RTE_PMD_EXPORT_NAME(name, idx) \
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index 2c7046f..7d6eef5 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -399,38 +399,6 @@ int rte_eal_pci_map_device(struct rte_pci_device *dev);
 void rte_eal_pci_unmap_device(struct rte_pci_device *dev);
 
 /**
- * @internal
- * Map a particular resource from a file.
- *
- * @param requested_addr
- *      The starting address for the new mapping range.
- * @param fd
- *      The file descriptor.
- * @param offset
- *      The offset for the mapping range.
- * @param size
- *      The size for the mapping range.
- * @param additional_flags
- *      The additional flags for the mapping range.
- * @return
- *   - On success, the function returns a pointer to the mapped area.
- *   - On error, the value MAP_FAILED is returned.
- */
-void *pci_map_resource(void *requested_addr, int fd, off_t offset,
-		size_t size, int additional_flags);
-
-/**
- * @internal
- * Unmap a particular resource.
- *
- * @param requested_addr
- *      The address for the unmapping range.
- * @param size
- *      The size for the unmapping range.
- */
-void pci_unmap_resource(void *requested_addr, size_t size);
-
-/**
  * 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_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 1786b75..5c34421 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -347,7 +347,7 @@ pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
 	if (pci_map_addr == NULL)
 		pci_map_addr = pci_find_max_end_va();
 
-	mapaddr = pci_map_resource(pci_map_addr, fd, 0,
+	mapaddr = rte_eal_map_resource(pci_map_addr, fd, 0,
 			(size_t)dev->mem_resource[res_idx].len, 0);
 	close(fd);
 	if (mapaddr == MAP_FAILED)
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
index 5f478c5..5ad8cbe 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
@@ -465,7 +465,8 @@ pci_vfio_map_resource(struct rte_pci_device *dev)
 			void *map_addr = NULL;
 			if (memreg[0].size) {
 				/* actual map of first part */
-				map_addr = pci_map_resource(bar_addr, vfio_dev_fd,
+				map_addr = rte_eal_map_resource(bar_addr,
+							    vfio_dev_fd,
 							    memreg[0].offset,
 							    memreg[0].size,
 							    MAP_FIXED);
@@ -477,7 +478,7 @@ pci_vfio_map_resource(struct rte_pci_device *dev)
 				void *second_addr = RTE_PTR_ADD(bar_addr,
 								memreg[1].offset -
 								(uintptr_t)reg.offset);
-				map_addr = pci_map_resource(second_addr,
+				map_addr = rte_eal_map_resource(second_addr,
 							    vfio_dev_fd, memreg[1].offset,
 							    memreg[1].size,
 							    MAP_FIXED);
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index 83721ba..22b5b59 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -174,6 +174,8 @@ DPDK_16.11 {
 	rte_delay_us_callback_register;
 	rte_eal_dev_attach;
 	rte_eal_dev_detach;
+	rte_eal_map_resource;
+	rte_eal_unmap_resource;
 	rte_eal_vdrv_register;
 	rte_eal_vdrv_unregister;
 
-- 
2.7.4

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

* [PATCH v2 3/4] eal/linux: generalize PCI kernel unbinding driver to EAL
  2016-10-14 10:55   ` [PATCH v2 " Shreyansh Jain
  2016-10-14 10:55     ` [PATCH v2 1/4] eal: generalize PCI kernel driver enum to EAL Shreyansh Jain
  2016-10-14 10:55     ` [PATCH v2 2/4] eal: generalize PCI map/unmap resource " Shreyansh Jain
@ 2016-10-14 10:55     ` Shreyansh Jain
  2016-10-14 10:55     ` [PATCH v2 4/4] eal/linux: generalize PCI kernel driver extraction " Shreyansh Jain
  3 siblings, 0 replies; 27+ messages in thread
From: Shreyansh Jain @ 2016-10-14 10:55 UTC (permalink / raw)
  To: dev; +Cc: viktorin, thomas.monjalon, david.marchand, Shreyansh Jain

From: Jan Viktorin <viktorin@rehivetech.com>

Generalize the PCI-specific pci_unbind_kernel_driver. It is now divided
into two parts. First, determination of the path and string identification
of the device to be unbound. Second, the actual unbind operation which is
generic.

BSD implementation updated as ENOTSUP

Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
--
Changes since v1:
 - update BSD support for unbind kernel driver

---
 lib/librte_eal/bsdapp/eal/eal.c       |  7 +++++++
 lib/librte_eal/bsdapp/eal/eal_pci.c   |  4 ++--
 lib/librte_eal/common/eal_private.h   | 13 +++++++++++++
 lib/librte_eal/linuxapp/eal/eal.c     | 26 ++++++++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_pci.c | 33 +++++++++------------------------
 5 files changed, 57 insertions(+), 26 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c
index 35e3117..5271fc2 100644
--- a/lib/librte_eal/bsdapp/eal/eal.c
+++ b/lib/librte_eal/bsdapp/eal/eal.c
@@ -633,3 +633,10 @@ rte_eal_process_type(void)
 {
 	return rte_config.process_type;
 }
+
+int
+rte_eal_unbind_kernel_driver(const char *devpath __rte_unused,
+			     const char *devid __rte_unused)
+{
+	return -ENOTSUP;
+}
diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 7ed0115..703f034 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -89,11 +89,11 @@
 
 /* unbind kernel driver for this device */
 int
-pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)
+pci_unbind_kernel_driver(struct rte_pci_device *dev)
 {
 	RTE_LOG(ERR, EAL, "RTE_PCI_DRV_FORCE_UNBIND flag is not implemented "
 		"for BSD\n");
-	return -ENOTSUP;
+	return rte_eal_unbind_kernel_driver(dev);
 }
 
 /* Map pci device */
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 9e7d8f6..b0c208a 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -256,6 +256,19 @@ int rte_eal_alarm_init(void);
 int rte_eal_check_module(const char *module_name);
 
 /**
+ * Unbind kernel driver bound to the device specified by the given devpath,
+ * and its string identification.
+ *
+ * @param devpath  path to the device directory ("/sys/.../devices/<name>")
+ * @param devid    identification of the device (<name>)
+ *
+ * @return
+ *      -1  unbind has failed
+ *       0  module has been unbound
+ */
+int rte_eal_unbind_kernel_driver(const char *devpath, const char *devid);
+
+/**
  * Get cpu core_id.
  *
  * This function is private to the EAL.
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index 2075282..5f6676d 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -943,3 +943,29 @@ rte_eal_check_module(const char *module_name)
 	/* Module has been found */
 	return 1;
 }
+
+int
+rte_eal_unbind_kernel_driver(const char *devpath, const char *devid)
+{
+	char filename[PATH_MAX];
+	FILE *f;
+
+	snprintf(filename, sizeof(filename),
+		 "%s/driver/unbind", devpath);
+
+	f = fopen(filename, "w");
+	if (f == NULL) /* device was not bound */
+		return 0;
+
+	if (fwrite(devid, strlen(devid), 1, f) == 0) {
+		RTE_LOG(ERR, EAL, "%s(): could not write to %s\n", __func__,
+				filename);
+		goto error;
+	}
+
+	fclose(f);
+	return 0;
+error:
+	fclose(f);
+	return -1;
+}
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index 876ba38..a03553f 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -59,38 +59,23 @@ int
 pci_unbind_kernel_driver(struct rte_pci_device *dev)
 {
 	int n;
-	FILE *f;
-	char filename[PATH_MAX];
-	char buf[BUFSIZ];
+	char devpath[PATH_MAX];
+	char devid[BUFSIZ];
 	struct rte_pci_addr *loc = &dev->addr;
 
-	/* open /sys/bus/pci/devices/AAAA:BB:CC.D/driver */
-	snprintf(filename, sizeof(filename),
-		"%s/" PCI_PRI_FMT "/driver/unbind", pci_get_sysfs_path(),
+	/* devpath /sys/bus/pci/devices/AAAA:BB:CC.D */
+	snprintf(devpath, sizeof(devpath),
+		"%s/" PCI_PRI_FMT, pci_get_sysfs_path(),
 		loc->domain, loc->bus, loc->devid, loc->function);
 
-	f = fopen(filename, "w");
-	if (f == NULL) /* device was not bound */
-		return 0;
-
-	n = snprintf(buf, sizeof(buf), PCI_PRI_FMT "\n",
+	n = snprintf(devid, sizeof(devid), PCI_PRI_FMT "\n",
 	             loc->domain, loc->bus, loc->devid, loc->function);
-	if ((n < 0) || (n >= (int)sizeof(buf))) {
+	if ((n < 0) || (n >= (int)sizeof(devid))) {
 		RTE_LOG(ERR, EAL, "%s(): snprintf failed\n", __func__);
-		goto error;
-	}
-	if (fwrite(buf, n, 1, f) == 0) {
-		RTE_LOG(ERR, EAL, "%s(): could not write to %s\n", __func__,
-				filename);
-		goto error;
+		return -1;
 	}
 
-	fclose(f);
-	return 0;
-
-error:
-	fclose(f);
-	return -1;
+	return rte_eal_unbind_kernel_driver(devpath, devid);
 }
 
 static int
-- 
2.7.4

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

* [PATCH v2 4/4] eal/linux: generalize PCI kernel driver extraction to EAL
  2016-10-14 10:55   ` [PATCH v2 " Shreyansh Jain
                       ` (2 preceding siblings ...)
  2016-10-14 10:55     ` [PATCH v2 3/4] eal/linux: generalize PCI kernel unbinding driver " Shreyansh Jain
@ 2016-10-14 10:55     ` Shreyansh Jain
  3 siblings, 0 replies; 27+ messages in thread
From: Shreyansh Jain @ 2016-10-14 10:55 UTC (permalink / raw)
  To: dev; +Cc: viktorin, thomas.monjalon, david.marchand, Shreyansh Jain

From: Jan Viktorin <viktorin@rehivetech.com>

Generalize the PCI-specific pci_get_kernel_driver_by_path. The function
is general enough, we have just moved it to eal.c, changed the prefix to
rte_eal and provided it privately to other parts of EAL.

Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
--
Changes since v1:
 - update BSD support for unbind kernel driver

---
 lib/librte_eal/bsdapp/eal/eal.c       |  7 +++++++
 lib/librte_eal/common/eal_private.h   | 14 ++++++++++++++
 lib/librte_eal/linuxapp/eal/eal.c     | 29 +++++++++++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_pci.c | 31 +------------------------------
 4 files changed, 51 insertions(+), 30 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c
index 5271fc2..9b93da3 100644
--- a/lib/librte_eal/bsdapp/eal/eal.c
+++ b/lib/librte_eal/bsdapp/eal/eal.c
@@ -640,3 +640,10 @@ rte_eal_unbind_kernel_driver(const char *devpath __rte_unused,
 {
 	return -ENOTSUP;
 }
+
+int
+rte_eal_get_kernel_driver_by_path(const char *filename __rte_unused,
+				  char *dri_name __rte_unused)
+{
+	return -ENOTSUP;
+}
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index b0c208a..c8c2131 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -269,6 +269,20 @@ int rte_eal_check_module(const char *module_name);
 int rte_eal_unbind_kernel_driver(const char *devpath, const char *devid);
 
 /**
+ * Extract the kernel driver name from the absolute path to the driver.
+ *
+ * @param filename  path to the driver ("<path-to-device>/driver")
+ * @path  dri_name  target buffer where to place the driver name
+ *                  (should be at least PATH_MAX long)
+ *
+ * @return
+ *      -1   on failure
+ *       0   when successful
+ *       1   when there is no such driver
+ */
+int rte_eal_get_kernel_driver_by_path(const char *filename, char *dri_name);
+
+/**
  * Get cpu core_id.
  *
  * This function is private to the EAL.
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index 5f6676d..00af21c 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -969,3 +969,32 @@ error:
 	fclose(f);
 	return -1;
 }
+
+int
+rte_eal_get_kernel_driver_by_path(const char *filename, char *dri_name)
+{
+	int count;
+	char path[PATH_MAX];
+	char *name;
+
+	if (!filename || !dri_name)
+		return -1;
+
+	count = readlink(filename, path, PATH_MAX);
+	if (count >= PATH_MAX)
+		return -1;
+
+	/* For device does not have a driver */
+	if (count < 0)
+		return 1;
+
+	path[count] = '\0';
+
+	name = strrchr(path, '/');
+	if (name) {
+		strncpy(dri_name, name + 1, strlen(name + 1) + 1);
+		return 0;
+	}
+
+	return -1;
+}
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index a03553f..e1cf9e8 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -78,35 +78,6 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev)
 	return rte_eal_unbind_kernel_driver(devpath, devid);
 }
 
-static int
-pci_get_kernel_driver_by_path(const char *filename, char *dri_name)
-{
-	int count;
-	char path[PATH_MAX];
-	char *name;
-
-	if (!filename || !dri_name)
-		return -1;
-
-	count = readlink(filename, path, PATH_MAX);
-	if (count >= PATH_MAX)
-		return -1;
-
-	/* For device does not have a driver */
-	if (count < 0)
-		return 1;
-
-	path[count] = '\0';
-
-	name = strrchr(path, '/');
-	if (name) {
-		strncpy(dri_name, name + 1, strlen(name + 1) + 1);
-		return 0;
-	}
-
-	return -1;
-}
-
 /* Map pci device */
 int
 rte_eal_pci_map_device(struct rte_pci_device *dev)
@@ -354,7 +325,7 @@ pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus,
 
 	/* parse driver */
 	snprintf(filename, sizeof(filename), "%s/driver", dirname);
-	ret = pci_get_kernel_driver_by_path(filename, driver);
+	ret = rte_eal_get_kernel_driver_by_path(filename, driver);
 	if (ret < 0) {
 		RTE_LOG(ERR, EAL, "Fail to get kernel driver\n");
 		free(dev);
-- 
2.7.4

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

end of thread, other threads:[~2016-10-14 10:54 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-01  4:41 [PATCH 0/5] Generalize PCI specific EAL function/structures Shreyansh Jain
2016-09-01  4:41 ` [PATCH 1/5] eal: make enum rte_kernel_driver non-PCI specific Shreyansh Jain
2016-09-11 12:15   ` Yuanhan Liu
2016-09-12  5:10     ` Shreyansh Jain
2016-09-01  4:41 ` [PATCH 2/5] eal: extract function eal_parse_sysfs_valuef Shreyansh Jain
2016-09-01  6:30   ` Stephen Hemminger
2016-09-01  9:01     ` Shreyansh Jain
2016-09-01  4:41 ` [PATCH 3/5] eal: Convert pci_(un)map_resource to rte_eal_(un)map_resource Shreyansh Jain
2016-09-01  4:41 ` [PATCH 4/5] eal/linux: extract function rte_eal_unbind_kernel_driver Shreyansh Jain
2016-09-01  4:41 ` [PATCH 5/5] eal/linux: extract function rte_eal_get_kernel_driver_by_path Shreyansh Jain
2016-09-27 14:12 ` [PATCH v1 0/4] Generalize PCI specific EAL function/structures Shreyansh Jain
2016-09-27 14:12   ` [PATCH v1 1/4] eal: generalize PCI kernel driver enum to EAL Shreyansh Jain
2016-09-27 14:12   ` [PATCH v1 2/4] eal: generalize PCI map/unmap resource " Shreyansh Jain
2016-09-27 14:12   ` [PATCH v1 3/4] eal/linux: generalize PCI kernel unbinding driver " Shreyansh Jain
2016-09-27 14:12   ` [PATCH v1 4/4] eal/linux: generalize PCI kernel driver extraction " Shreyansh Jain
2016-09-30 15:31   ` [PATCH v1 0/4] Generalize PCI specific EAL function/structures David Marchand
2016-10-03  5:37     ` Shreyansh Jain
2016-10-03 13:12       ` Jan Viktorin
2016-10-03 13:36       ` Thomas Monjalon
2016-10-06 11:43         ` Shreyansh Jain
2016-10-06 13:01           ` Thomas Monjalon
2016-10-13  6:47     ` Shreyansh Jain
2016-10-14 10:55   ` [PATCH v2 " Shreyansh Jain
2016-10-14 10:55     ` [PATCH v2 1/4] eal: generalize PCI kernel driver enum to EAL Shreyansh Jain
2016-10-14 10:55     ` [PATCH v2 2/4] eal: generalize PCI map/unmap resource " Shreyansh Jain
2016-10-14 10:55     ` [PATCH v2 3/4] eal/linux: generalize PCI kernel unbinding driver " Shreyansh Jain
2016-10-14 10:55     ` [PATCH v2 4/4] eal/linux: generalize PCI kernel driver extraction " Shreyansh Jain

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.