[v5,09/14] bus/vmbus: open subchannels

Message ID 20220423042849.7718-10-srikanth.k@oneconvergence.com (mailing list archive)
State Awaiting Upstream
Delegated to: Thomas Monjalon
Headers
Series add FreeBSD support to VMBUS & NetVSC PMDs |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Srikanth Kaka April 23, 2022, 4:28 a.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     | 11 +++++++++++
 drivers/bus/vmbus/version.map         |  6 ++++++
 drivers/bus/vmbus/vmbus_channel.c     |  5 +++++
 6 files changed, 65 insertions(+)
  

Comments

Stephen Hemminger Aug. 10, 2023, 3:41 p.m. UTC | #1
On Sat, 23 Apr 2022 09:58:44 +0530
Srikanth Kaka <srikanth.k@oneconvergence.com> wrote:

> +/**
> + * Perform IOCTL to VMBUS device
> + *
> + * @param device
> + *	A pointer to a rte_vmbus_device structure
> + * @param subchan
> + *	Count of subchannels to open
> + */
> +__rte_experimental
> +int rte_vmbus_ioctl(struct rte_vmbus_device *device, uint32_t subchan);

The functionality is good, but have problem with naming.
The word 'ioctl' implies that this is a kernel system call but it is not.
Suggest rte_vmbus_add_channels() as function name instead.
  

Patch

diff --git a/drivers/bus/vmbus/freebsd/vmbus_uio.c b/drivers/bus/vmbus/freebsd/vmbus_uio.c
index 55b8f18..438db41 100644
--- a/drivers/bus/vmbus/freebsd/vmbus_uio.c
+++ b/drivers/bus/vmbus/freebsd/vmbus_uio.c
@@ -25,6 +25,9 @@ 
  */
 #define UH_SUBCHAN_MASK_SHIFT  8
 
+/* ioctl */
+#define HVIOOPENSUBCHAN     _IOW('h', 14, uint32_t)
+
 const char *driver_name = "hv_uio";
 
 /* Check map names with kernel names */
@@ -151,3 +154,30 @@  const char *get_devname_os(void)
 {
 	return "/dev/hv_uio";
 }
+
+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 69f0b26..b9616bd 100644
--- a/drivers/bus/vmbus/linux/vmbus_uio.c
+++ b/drivers/bus/vmbus/linux/vmbus_uio.c
@@ -215,3 +215,15 @@  const char *get_devname_os(void)
 {
 	return "/dev/uio";
 }
+
+/*
+ * 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 1bca147..ea0276a 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 a24bad8..06b2ffc 100644
--- a/drivers/bus/vmbus/rte_bus_vmbus.h
+++ b/drivers/bus/vmbus/rte_bus_vmbus.h
@@ -404,6 +404,17 @@  void rte_vmbus_set_latency(const struct rte_vmbus_device *dev,
  */
 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
+ */
+__rte_experimental
+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 3cadec7..e5b7218 100644
--- a/drivers/bus/vmbus/version.map
+++ b/drivers/bus/vmbus/version.map
@@ -26,3 +26,9 @@  DPDK_22 {
 
 	local: *;
 };
+
+EXPERIMENTAL {
+	global:
+
+	rte_vmbus_ioctl;
+};
diff --git a/drivers/bus/vmbus/vmbus_channel.c b/drivers/bus/vmbus/vmbus_channel.c
index 119b9b3..9a8f6e3 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)