[v3,08/15] bus/vmbus: open subchannels

Message ID 20220217160613.70161-9-srikanth.k@oneconvergence.com (mailing list archive)
State Superseded, archived
Headers
Series add FreeBSD support to VMBUS & NetVSC PMDs |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Srikanth Kaka Feb. 17, 2022, 4:06 p.m. UTC
In FreeBSD, unlike Linux there is no sub-channel open callback that
could be called by HV_UIO driver, upon their grant by the hypervisor.
Thus the PMD makes an IOCTL to the HV_UIO to open the sub-channels

On Linux, the vmbus_uio_subchan_open() will always return success
as the Linux HV_UIO opens them implicitly.

Signed-off-by: Srikanth Kaka <srikanth.k@oneconvergence.com>
Signed-off-by: Vag Singh <vag.singh@oneconvergence.com>
Signed-off-by: Anand Thulasiram <avelu@juniper.net>
---
 drivers/bus/vmbus/freebsd/vmbus_uio.c | 30 +++++++++++++++++++++++++++
 drivers/bus/vmbus/linux/vmbus_uio.c   | 12 +++++++++++
 drivers/bus/vmbus/private.h           |  1 +
 drivers/bus/vmbus/rte_bus_vmbus.h     | 10 +++++++++
 drivers/bus/vmbus/version.map         |  1 +
 drivers/bus/vmbus/vmbus_channel.c     |  5 +++++
 6 files changed, 59 insertions(+)
  

Patch

diff --git a/drivers/bus/vmbus/freebsd/vmbus_uio.c b/drivers/bus/vmbus/freebsd/vmbus_uio.c
index 95b030c749..affc0a3f4f 100644
--- a/drivers/bus/vmbus/freebsd/vmbus_uio.c
+++ b/drivers/bus/vmbus/freebsd/vmbus_uio.c
@@ -23,6 +23,9 @@ 
  */
 #define UH_SUBCHAN_MASK_SHIFT  8
 
+/* ioctl */
+#define HVIOOPENSUBCHAN     _IOW('h', 14, uint32_t)
+
 const char *driver_name = "hv_uio";
 static void *vmbus_map_addr;
 
@@ -304,3 +307,30 @@  bool vmbus_uio_subchannels_supported(const struct rte_vmbus_device *dev,
 	RTE_SET_USED(chan);
 	return true;
 }
+
+int vmbus_uio_subchan_open(struct rte_vmbus_device *dev, uint32_t subchan)
+{
+	struct mapped_vmbus_resource *uio_res;
+	int fd, err = 0;
+
+	uio_res = vmbus_uio_find_resource(dev);
+	if (!uio_res) {
+		VMBUS_LOG(ERR, "cannot find uio resource");
+		return -EINVAL;
+	}
+
+	fd = open(uio_res->path, O_RDWR);
+	if (fd < 0) {
+		VMBUS_LOG(ERR, "Cannot open %s: %s",
+				uio_res->path, strerror(errno));
+		return -1;
+	}
+
+	if (ioctl(fd, HVIOOPENSUBCHAN, &subchan)) {
+		VMBUS_LOG(ERR, "open subchan ioctl failed %s: %s",
+				uio_res->path, strerror(errno));
+		err = -1;
+	}
+	close(fd);
+	return err;
+}
diff --git a/drivers/bus/vmbus/linux/vmbus_uio.c b/drivers/bus/vmbus/linux/vmbus_uio.c
index 5db70f8e0d..7241c052e7 100644
--- a/drivers/bus/vmbus/linux/vmbus_uio.c
+++ b/drivers/bus/vmbus/linux/vmbus_uio.c
@@ -471,3 +471,15 @@  int vmbus_uio_get_subchan(struct vmbus_channel *primary,
 	closedir(chan_dir);
 	return err;
 }
+
+/*
+ * This is a stub function and it should always succeed.
+ * The Linux UIO kernel driver opens the subchannels implicitly.
+ */
+int vmbus_uio_subchan_open(struct rte_vmbus_device *dev,
+			   uint32_t subchan)
+{
+	RTE_SET_USED(dev);
+	RTE_SET_USED(subchan);
+	return 0;
+}
diff --git a/drivers/bus/vmbus/private.h b/drivers/bus/vmbus/private.h
index 1bca147e12..ea0276a6c6 100644
--- a/drivers/bus/vmbus/private.h
+++ b/drivers/bus/vmbus/private.h
@@ -116,6 +116,7 @@  bool vmbus_uio_subchannels_supported(const struct rte_vmbus_device *dev,
 int vmbus_uio_get_subchan(struct vmbus_channel *primary,
 			  struct vmbus_channel **subchan);
 int vmbus_uio_map_rings(struct vmbus_channel *chan);
+int vmbus_uio_subchan_open(struct rte_vmbus_device *device, uint32_t subchan);
 
 void vmbus_br_setup(struct vmbus_br *br, void *buf, unsigned int blen);
 
diff --git a/drivers/bus/vmbus/rte_bus_vmbus.h b/drivers/bus/vmbus/rte_bus_vmbus.h
index a24bad831d..c8cb4bc98c 100644
--- a/drivers/bus/vmbus/rte_bus_vmbus.h
+++ b/drivers/bus/vmbus/rte_bus_vmbus.h
@@ -404,6 +404,16 @@  void rte_vmbus_chan_dump(FILE *f, const struct vmbus_channel *chan);
  */
 void rte_vmbus_unregister(struct rte_vmbus_driver *driver);
 
+/**
+ * Perform IOCTL to VMBUS device
+ *
+ * @param device
+ *	A pointer to a rte_vmbus_device structure
+ * @param subchan
+ *	Count of subchannels to open
+ */
+int rte_vmbus_ioctl(struct rte_vmbus_device *device, uint32_t subchan);
+
 /** Helper for VMBUS device registration from driver instance */
 #define RTE_PMD_REGISTER_VMBUS(nm, vmbus_drv)		\
 	RTE_INIT(vmbusinitfn_ ##nm)			\
diff --git a/drivers/bus/vmbus/version.map b/drivers/bus/vmbus/version.map
index 3cadec7fae..3509d4fc14 100644
--- a/drivers/bus/vmbus/version.map
+++ b/drivers/bus/vmbus/version.map
@@ -23,6 +23,7 @@  DPDK_22 {
 	rte_vmbus_subchan_open;
 	rte_vmbus_unmap_device;
 	rte_vmbus_unregister;
+	rte_vmbus_ioctl;
 
 	local: *;
 };
diff --git a/drivers/bus/vmbus/vmbus_channel.c b/drivers/bus/vmbus/vmbus_channel.c
index 119b9b367e..9a8f6e3eef 100644
--- a/drivers/bus/vmbus/vmbus_channel.c
+++ b/drivers/bus/vmbus/vmbus_channel.c
@@ -365,6 +365,11 @@  int rte_vmbus_max_channels(const struct rte_vmbus_device *device)
 		return 1;
 }
 
+int rte_vmbus_ioctl(struct rte_vmbus_device *device, uint32_t subchan)
+{
+	return vmbus_uio_subchan_open(device, subchan);
+}
+
 /* Setup secondary channel */
 int rte_vmbus_subchan_open(struct vmbus_channel *primary,
 			   struct vmbus_channel **new_chan)