Skip to contentSkip to conversation

Enable uio_pci_generic support

PATCH Superseded Danny Zhou 4 participants 8 messages Jan 29, 2015 – Feb 19, 2015 2 messages not in the archive

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Danny Zhou

author
#0 lore raw

cover Enable uio_pci_generic support

Linux kernel provides UIO as well as VFIO mechanism to support writing user space device driver. Comparing to UIO which is available since 2.6.32 kernel, the VFIO is introduced into kernel since version 3.6.0 with better interrupt and memory protection (build on top of Intel VT-d technology) supports. Basically, UIO and VFIO do two common things below:
1) Map PCIe device's I/O memory space to user space driver
2) Support device interrupt notification mechanism that notifies user space driver/application when a device interrupt triggers.

To run an DPDK application and make use of VFIO, two in_kernel modules vfio and vfio-pci module must be loaded. To use UIO, a DPDK kernel module igb_uio, which was there since DPDK is invented, must be loaded to attach to in_kernel uio module. As an solution to deprecate igb_uio, this patch serials leverage the uio_pci_generic in_kernel module to support DPDK user space PMD in a generic fashion (similar to how VFIO works), to remove user space DPDK dependency on GPL code igb_uio in kernel.

Example to bind Network Ports to uio_pci_generic:

	modprobe uio
	modprobe uio_pci_generic
	/* to bind device 08:00.0, to the uio_pci_generic driver */
	./tools/dpdk_nic_bind.py -b uio_pci_generic 08:00.0

Note: this patch set does not remove igb_uio support due to igb_uio supports creating maximum number of SR-IOV VFs (Virtual Functions) by using max_vfs kernel parameter on older kernels (kernel 3.7.x and below). Specifically, igb_uio explicitly calls pci_enable_sriov() to create VFs, while it is not invoked in either uio or uio_pci_generic kernel modules. On kernel 3.8.x and above, user can use the standard sysfs to enable VFs. For examples:

#echo $num_vf_enabled > /sys/class/net/$dev/device/sriov_numvfs //enable VFs
#echo 0 > /sys/class/net/$dev/device/sriov_numvfs //disable VFs

Danny Zhou (3):
eal: add interrupt enable/disable routines for uio_pci_generic
eal: enable uio_pci_generic support
tools: enable binding NIC device to uio_pci_generic

 lib/librte_eal/common/include/rte_pci.h            |   1 +
 lib/librte_eal/linuxapp/eal/eal_interrupts.c       |  68 +++++--
 lib/librte_eal/linuxapp/eal/eal_pci.c              |   2 +-
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c          | 202 +++++++++++----------
 .../linuxapp/eal/include/exec-env/rte_interrupts.h |  10 +-
 tools/dpdk_nic_bind.py                             |   2 +-
 6 files changed, 172 insertions(+), 113 deletions(-)
Signature · 1 line
1.8.1.4
author
#2 lore raw

PATCH 1/3 eal: enable uio_pci_generic support

In reply to a message not in the archive

1) Unify procedure to retrieve BAR resource mapping information.
2) Setup bus master bit in NIC's PCIe configuration space for uio_pci_generic.

---
 lib/librte_eal/common/include/rte_pci.h            |   1 +
 lib/librte_eal/linuxapp/eal/eal_pci.c              |   2 +-
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c          | 202 +++++++++++----------
 .../linuxapp/eal/include/exec-env/rte_interrupts.h |  10 +-
 4 files changed, 119 insertions(+), 96 deletions(-)
lib/librte_eal/common/include/rte_pci.h +1 -0
index 66ed793..71ca882 100644
@@ -148,6 +148,7 @@ struct rte_pci_device {
 	struct rte_pci_id id;                   /**< PCI ID. */
 	struct rte_pci_resource mem_resource[PCI_MAX_RESOURCE];   /**< PCI Memory Resource */
 	struct rte_intr_handle intr_handle;     /**< Interrupt handle */
+	char driver_name[BUFSIZ];               /**< driver name */
 	const struct rte_pci_driver *driver;    /**< Associated driver */
 	uint16_t max_vfs;                       /**< sriov enable if not zero */
 	int numa_node;                          /**< NUMA node connection */
lib/librte_eal/linuxapp/eal/eal_pci.c +1 -1
index b5f5410..8c307e9 100644
@@ -512,7 +512,7 @@ pci_map_device(struct rte_pci_device *dev)
 			return ret;
 	}
 #endif
-	/* map resources for devices that use igb_uio */
+	/* map resources for devices that use uio_pci_generic or igb_uio */
 	if (!mapped) {
 		ret = pci_uio_map_resource(dev);
 		if (ret != 0)
lib/librte_eal/linuxapp/eal/eal_pci_uio.c +109 -93

283 lines not on this page · raw message

lib/librte_eal/linuxapp/eal/include/exec-env/rte_interrupts.h +8 -2
index 23eafd9..adc1c8d 100644
@@ -50,8 +50,14 @@ enum rte_intr_handle_type {
 
 /** Handle for interrupts. */
 struct rte_intr_handle {
-	int vfio_dev_fd;                 /**< VFIO device file descriptor */
-	int fd;                          /**< file descriptor */
+	union {
+		int vfio_dev_fd;  /**< VFIO device file descriptor */
+	};
+        union {
+		int uio_cfg_fd;  /**< UIO config file descriptor
+					for uio_pci_generic */
+	};
+	int fd;	 /**< interrupt event file descriptor */
 	enum rte_intr_handle_type type;  /**< handle type */
 };
 
Signature · 1 line
1.8.1.4
author
#6 lore raw

PATCH 2/3 eal: add interrupt enable/disable routines for uio_pci_generic

In reply to a message not in the archive

enable/disable interrupt by manipulating enable/disable bit of command register on NIC's PCIe configuration space.

---
 lib/librte_eal/linuxapp/eal/eal_interrupts.c | 68 +++++++++++++++++++++-------
 1 file changed, 52 insertions(+), 16 deletions(-)
lib/librte_eal/linuxapp/eal/eal_interrupts.c +52 -16
index dc2668a..8c5b834 100644
@@ -361,6 +361,54 @@ vfio_disable_msix(struct rte_intr_handle *intr_handle) {
 }
 #endif
 
+static int
+uio_intr_disable(struct rte_intr_handle *intr_handle)
+{
+	unsigned char command_high;
+
+	/* use UIO config file descriptor for uio_pci_generic */
+	if (pread(intr_handle->uio_cfg_fd, &command_high, 1, 5) != 1) {
+		RTE_LOG(ERR, EAL,
+			"Error reading interrupts status for fd %d\n",
+			intr_handle->uio_cfg_fd);
+		return -1;
+	}
+	/* disable interrupts */
+	command_high |= 0x4;
+	if (pwrite(intr_handle->uio_cfg_fd, &command_high, 1, 5) != 1) {
+		RTE_LOG(ERR, EAL,
+			"Error disabling interrupts for fd %d\n",
+			intr_handle->uio_cfg_fd);
+		return -1;
+	}
+
+	return 0;
+}
+
+static int
+uio_intr_enable(struct rte_intr_handle *intr_handle)
+{
+	unsigned char command_high;
+
+	/* use UIO config file descriptor for uio_pci_generic */
+	if (pread(intr_handle->uio_cfg_fd, &command_high, 1, 5) != 1) {
+		RTE_LOG(ERR, EAL,
+			"Error reading interrupts status for fd %d\n",
+			intr_handle->uio_cfg_fd);
+		return -1;
+	}
+	/* enable interrupts */
+	command_high &= ~0x4;
+	if (pwrite(intr_handle->uio_cfg_fd, &command_high, 1, 5) != 1) {
+		RTE_LOG(ERR, EAL,
+			"Error enabling interrupts for fd %d\n",
+			intr_handle->uio_cfg_fd);
+		return -1;
+	}
+
+	return 0;
+}
+
 int
 rte_intr_callback_register(struct rte_intr_handle *intr_handle,
 			rte_intr_callback_fn cb, void *cb_arg)
@@ -500,20 +548,14 @@ rte_intr_callback_unregister(struct rte_intr_handle *intr_handle,
 int
 rte_intr_enable(struct rte_intr_handle *intr_handle)
 {
-	const int value = 1;
-
-	if (!intr_handle || intr_handle->fd < 0)
+	if (!intr_handle || intr_handle->fd < 0 || intr_handle->uio_cfg_fd < 0)
 		return -1;
 
 	switch (intr_handle->type){
 	/* write to the uio fd to enable the interrupt */
 	case RTE_INTR_HANDLE_UIO:
-		if (write(intr_handle->fd, &value, sizeof(value)) < 0) {
-			RTE_LOG(ERR, EAL,
-				"Error enabling interrupts for fd %d\n",
-							intr_handle->fd);
+		if (uio_intr_enable(intr_handle))
 			return -1;
-		}
 		break;
 	/* not used at this moment */
 	case RTE_INTR_HANDLE_ALARM:
@@ -546,20 +588,14 @@ rte_intr_enable(struct rte_intr_handle *intr_handle)
 int
 rte_intr_disable(struct rte_intr_handle *intr_handle)
 {
-	const int value = 0;
-
-	if (!intr_handle || intr_handle->fd < 0)
+	if (!intr_handle || intr_handle->fd < 0 || intr_handle->uio_cfg_fd < 0)
 		return -1;
 
 	switch (intr_handle->type){
 	/* write to the uio fd to disable the interrupt */
 	case RTE_INTR_HANDLE_UIO:
-		if (write(intr_handle->fd, &value, sizeof(value)) < 0){
-			RTE_LOG(ERR, EAL,
-				"Error disabling interrupts for fd %d\n",
-							intr_handle->fd);
+		if (uio_intr_disable(intr_handle))
 			return -1;
-		}
 		break;
 	/* not used at this moment */
 	case RTE_INTR_HANDLE_ALARM:
Signature · 1 line
1.8.1.4
author
#7 lore raw

PATCH 3/3 tools: enable binding NIC device to uio_pci_generic

In reply to a message not in the archive

Add uio_pci_generic to the list of supported DPDK driver.

---
 tools/dpdk_nic_bind.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/dpdk_nic_bind.py +1 -1
index 812b6a1..2483056 100755
@@ -43,7 +43,7 @@ ETHERNET_CLASS = "0200"
 # Each device within this is itself a dictionary of device properties
 devices = {}
 # list of supported DPDK drivers
-dpdk_drivers = [ "igb_uio", "vfio-pci" ]
+dpdk_drivers = [ "igb_uio", "vfio-pci", "uio_pci_generic" ]
 
 # command-line arg flags
 b_flag = None
Signature · 1 line
1.8.1.4
#9 lore raw
In reply to Danny Zhou
Quoted 4 lines · Danny Zhou

Linux kernel provides UIO as well as VFIO mechanism to support writing user space device driver. Comparing to UIO which is available since 2.6.32 kernel, the VFIO is introduced into kernel since version 3.6.0 with better interrupt and memory protection (build on top of Intel VT-d technology) supports.

I would like to say that, VFIO is not only for X86.

Thanks,
Michael

Quoted 42 lines

Basically, UIO and VFIO do two common things below:
1) Map PCIe device's I/O memory space to user space driver
2) Support device interrupt notification mechanism that notifies user space driver/application when a device interrupt triggers.

To run an DPDK application and make use of VFIO, two in_kernel modules vfio and vfio-pci module must be loaded. To use UIO, a DPDK kernel module igb_uio, which was there since DPDK is invented, must be loaded to attach to in_kernel uio module. As an solution to deprecate igb_uio, this patch serials leverage the uio_pci_generic in_kernel module to support DPDK user space PMD in a generic fashion (similar to how VFIO works), to remove user space DPDK dependency on GPL code igb_uio in kernel.

Example to bind Network Ports to uio_pci_generic:

	modprobe uio
	modprobe uio_pci_generic
	/* to bind device 08:00.0, to the uio_pci_generic driver */
	./tools/dpdk_nic_bind.py -b uio_pci_generic 08:00.0

Note: this patch set does not remove igb_uio support due to igb_uio supports creating maximum number of SR-IOV VFs (Virtual Functions) by using max_vfs kernel parameter on older kernels (kernel 3.7.x and below). Specifically, igb_uio explicitly calls pci_enable_sriov() to create VFs, while it is not invoked in either uio or uio_pci_generic kernel modules. On kernel 3.8.x and above, user can use the standard sysfs to enable VFs. For examples:

#echo $num_vf_enabled > /sys/class/net/$dev/device/sriov_numvfs //enable VFs
#echo 0 > /sys/class/net/$dev/device/sriov_numvfs //disable VFs

Danny Zhou (3):
eal: add interrupt enable/disable routines for uio_pci_generic
eal: enable uio_pci_generic support
tools: enable binding NIC device to uio_pci_generic

 lib/librte_eal/common/include/rte_pci.h            |   1 +
 lib/librte_eal/linuxapp/eal/eal_interrupts.c       |  68 +++++--
 lib/librte_eal/linuxapp/eal/eal_pci.c              |   2 +-
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c          | 202 +++++++++++----------
 .../linuxapp/eal/include/exec-env/rte_interrupts.h |  10 +-
 tools/dpdk_nic_bind.py                             |   2 +-
 6 files changed, 172 insertions(+), 113 deletions(-)
#8 lore raw
In reply to a message not in the archive
Quoted 38 lines · Danny Zhou

Linux kernel provides UIO as well as VFIO mechanism to support writing user space device driver. Comparing to UIO which is available since 2.6.32 kernel, the VFIO is introduced into kernel since version 3.6.0 with better interrupt and memory protection (build on top of Intel VT-d technology) supports. Basically, UIO and VFIO do two common things below:
1) Map PCIe device's I/O memory space to user space driver
2) Support device interrupt notification mechanism that notifies user space driver/application when a device interrupt triggers.

To run an DPDK application and make use of VFIO, two in_kernel modules vfio and vfio-pci module must be loaded. To use UIO, a DPDK kernel module igb_uio, which was there since DPDK is invented, must be loaded to attach to in_kernel uio module. As an solution to deprecate igb_uio, this patch serials leverage the uio_pci_generic in_kernel module to support DPDK user space PMD in a generic fashion (similar to how VFIO works), to remove user space DPDK dependency on GPL code igb_uio in kernel.

Example to bind Network Ports to uio_pci_generic:

	modprobe uio
	modprobe uio_pci_generic
	/* to bind device 08:00.0, to the uio_pci_generic driver */
	./tools/dpdk_nic_bind.py -b uio_pci_generic 08:00.0

Note: this patch set does not remove igb_uio support due to igb_uio supports creating maximum number of SR-IOV VFs (Virtual Functions) by using max_vfs kernel parameter on older kernels (kernel 3.7.x and below). Specifically, igb_uio explicitly calls pci_enable_sriov() to create VFs, while it is not invoked in either uio or uio_pci_generic kernel modules. On kernel 3.8.x and above, user can use the standard sysfs to enable VFs. For examples:

#echo $num_vf_enabled > /sys/class/net/$dev/device/sriov_numvfs //enable VFs
#echo 0 > /sys/class/net/$dev/device/sriov_numvfs //disable VFs

Danny Zhou (3):
eal: add interrupt enable/disable routines for uio_pci_generic
eal: enable uio_pci_generic support
tools: enable binding NIC device to uio_pci_generic

Quoted 11 lines
 lib/librte_eal/common/include/rte_pci.h            |   1 +
 lib/librte_eal/linuxapp/eal/eal_interrupts.c       |  68 +++++--
 lib/librte_eal/linuxapp/eal/eal_pci.c              |   2 +-
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c          | 202 +++++++++++----------
 .../linuxapp/eal/include/exec-env/rte_interrupts.h |  10 +-
 tools/dpdk_nic_bind.py                             |   2 +-
 6 files changed, 172 insertions(+), 113 deletions(-)
Signature · 1 line
1.8.1.4

Series

#4 lore raw

Re: [PATCH v1 1/3] eal: enable uio_pci_generic support

In reply to a message not in the archive

Hi Danny,

I wanted to apply this patchset which was reviewed. But when having a quick overview, I've seen some strange additions.

2015-01-29 17:28, Danny Zhou:

Quoted 5 lines

1) Unify procedure to retrieve BAR resource mapping information.
2) Setup bus master bit in NIC's PCIe configuration space for uio_pci_generic.

[...]

lib/librte_eal/common/include/rte_pci.h struct rte_pci_device { · line 151

Quoted 7 lines
lib/librte_eal/common/include/rte_pci.h +1 -0
@@ -148,6 +148,7 @@ struct rte_pci_device {
 	struct rte_pci_id id;                   /**< PCI ID. */
 	struct rte_pci_resource mem_resource[PCI_MAX_RESOURCE];   /**< PCI Memory Resource */
 	struct rte_intr_handle intr_handle;     /**< Interrupt handle */
+	char driver_name[BUFSIZ];               /**< driver name */

Why not embedding this field in driver struct?
The name and comment should be more precise.
There is also driver->name and hotplug patchset is adding a kernel driver name. Please bring the light in all these driver names :)

Quoted 1 line
lib/librte_eal/common/include/rte_pci.h +0 -0
 	const struct rte_pci_driver *driver;    /**< Associated driver */

[...]

lib/librte_eal/linuxapp/eal/eal_pci_uio.c line 51

Quoted 3 lines
lib/librte_eal/linuxapp/eal/eal_pci_uio.c +1 -0
+#define IORESOURCE_MEM        0x00000200

Please comment this value.

Quoted 5 lines
lib/librte_eal/linuxapp/eal/include/exec-env/rte_interrupts.h +0 -0
@@ -50,8 +50,14 @@ enum rte_intr_handle_type {
 
 /** Handle for interrupts. */

lib/librte_eal/linuxapp/eal/include/exec-env/rte_interrupts.h enum rte_intr_handle_type { · line 59

Quoted 10 lines
lib/librte_eal/linuxapp/eal/include/exec-env/rte_interrupts.h +7 -2
 struct rte_intr_handle {
-	int vfio_dev_fd;                 /**< VFIO device file descriptor */
-	int fd;                          /**< file descriptor */
+	union {
+		int vfio_dev_fd;  /**< VFIO device file descriptor */
+	};
+        union {
+		int uio_cfg_fd;  /**< UIO config file descriptor
+					for uio_pci_generic */
+	};

Apart the indent, it seems there is a mistake here. Why 2 unions with 1 field each?

Quoted 3 lines
lib/librte_eal/linuxapp/eal/include/exec-env/rte_interrupts.h +1 -0
+	int fd;	 /**< interrupt event file descriptor */
 	enum rte_intr_handle_type type;  /**< handle type */
 };
#5 lore raw

Re: [PATCH v1 1/3] eal: enable uio_pci_generic support

Thomas, thanks for review and I added comments inline.

Quoted 19 lines

-----Original Message-----
From: Thomas Monjalon [mailto:[email protected]]
Sent: Wednesday, February 18, 2015 9:40 PM
To: Zhou, Danny
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH v1 1/3] eal: enable uio_pci_generic support

Hi Danny,

I wanted to apply this patchset which was reviewed. But when having a quick overview, I've seen some strange additions.

2015-01-29 17:28, Danny Zhou:

Quoted 5 lines

1) Unify procedure to retrieve BAR resource mapping information.
2) Setup bus master bit in NIC's PCIe configuration space for uio_pci_generic.

[...]

Quoted 13 lines

lib/librte_eal/common/include/rte_pci.h struct rte_pci_device { · line 151

Quoted 7 lines
lib/librte_eal/common/include/rte_pci.h +1 -0
@@ -148,6 +148,7 @@ struct rte_pci_device {
 	struct rte_pci_id id;                   /**< PCI ID. */
 	struct rte_pci_resource mem_resource[PCI_MAX_RESOURCE];   /**< PCI Memory Resource */
 	struct rte_intr_handle intr_handle;     /**< Interrupt handle */
+	char driver_name[BUFSIZ];               /**< driver name */

Why not embedding this field in driver struct?
The name and comment should be more precise.
There is also driver->name and hotplug patchset is adding a kernel driver name. Please bring the light in all these driver names :)

This driver_name is the name of kernel driver(e.g. vfio_pci, igb_uio, uio_pci_generic) while the driver->name is a user-defined name for user space driver. I am going to change it to kernel_driver_name with precise comment in V2 patch, and when the V2 patch is applied, I think the function pci_get_kernel_driver_by_path() in hotplug patchset is not necessary then as it could directly retrieve the kernel driver name from this variable.

Quoted 7 lines
Quoted 1 line
lib/librte_eal/common/include/rte_pci.h +0 -0
 	const struct rte_pci_driver *driver;    /**< Associated driver */

[...]

lib/librte_eal/linuxapp/eal/eal_pci_uio.c line 51

Quoted 3 lines
lib/librte_eal/linuxapp/eal/eal_pci_uio.c +1 -0
+#define IORESOURCE_MEM        0x00000200

Please comment this value.

Will do.

Quoted 5 lines
Quoted 5 lines
lib/librte_eal/linuxapp/eal/include/exec-env/rte_interrupts.h +0 -0
@@ -50,8 +50,14 @@ enum rte_intr_handle_type {
 
Quoted 14 lines

lib/librte_eal/linuxapp/eal/include/exec-env/rte_interrupts.h enum rte_intr_handle_type { · line 59

Quoted 11 lines
lib/librte_eal/linuxapp/eal/include/exec-env/rte_interrupts.h +7 -2
 /** Handle for interrupts. */
 struct rte_intr_handle {
-	int vfio_dev_fd;                 /**< VFIO device file descriptor */
-	int fd;                          /**< file descriptor */
+	union {
+		int vfio_dev_fd;  /**< VFIO device file descriptor */
+	};
+        union {
+		int uio_cfg_fd;  /**< UIO config file descriptor
+					for uio_pci_generic */
+	};

Apart the indent, it seems there is a mistake here. Why 2 unions with 1 field each?

It is a mistake I made during code merge, will fix it in V2.

Quoted 4 lines
Quoted 4 lines
lib/librte_eal/linuxapp/eal/include/exec-env/rte_interrupts.h +1 -0
+	int fd;	 /**< interrupt event file descriptor */
 	enum rte_intr_handle_type type;  /**< handle type */
 };