[v4,08/14] bus/vmbus: add sub-channel mapping support

Message ID 20220418042915.5765-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 success coding style OK

Commit Message

Srikanth Kaka April 18, 2022, 4:29 a.m. UTC
To map the subchannels, an mmap request is directly made after
determining the subchan memory offset

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 | 48 +++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
  

Patch

diff --git a/drivers/bus/vmbus/freebsd/vmbus_uio.c b/drivers/bus/vmbus/freebsd/vmbus_uio.c
index b622388ce9..6b43b4349f 100644
--- a/drivers/bus/vmbus/freebsd/vmbus_uio.c
+++ b/drivers/bus/vmbus/freebsd/vmbus_uio.c
@@ -18,6 +18,13 @@ 
 #include "private.h"
 #include "vmbus_osi.h"
 
+/*
+ * Macros to distinguish mmap request
+ * [7-0] - Device memory region
+ * [15-8]- Sub-channel id
+ */
+#define UH_SUBCHAN_MASK_SHIFT  8
+
 const char *driver_name = "hv_uio";
 
 /* Check map names with kernel names */
@@ -99,6 +106,47 @@  int vmbus_get_device_info_os(struct rte_vmbus_device *dev)
 	return sysctl_get_vmbus_device_info(dev);
 }
 
+int vmbus_uio_map_subchan_os(const struct rte_vmbus_device *dev,
+			     const struct vmbus_channel *chan,
+			     void **mapaddr, size_t *size)
+{
+	char ring_path[PATH_MAX];
+	off_t offset;
+	int fd;
+
+	snprintf(ring_path, sizeof(ring_path),
+		 "/dev/hv_uio%d", dev->uio_num);
+
+	fd = open(ring_path, O_RDWR);
+	if (fd < 0) {
+		VMBUS_LOG(ERR, "Cannot open %s: %s",
+			  ring_path, strerror(errno));
+		return -errno;
+	}
+
+	/* subchannel rings are of the same size as primary */
+	*size = dev->resource[HV_TXRX_RING_MAP].len;
+	offset = (chan->relid << UH_SUBCHAN_MASK_SHIFT) * PAGE_SIZE;
+
+	*mapaddr = vmbus_map_resource(vmbus_map_addr, fd,
+				      offset, *size, 0);
+	close(fd);
+
+	if (*mapaddr == MAP_FAILED)
+		return -EIO;
+
+	return 0;
+}
+
+/* This function should always succeed */
+bool vmbus_uio_subchannels_supported(const struct rte_vmbus_device *dev,
+				     const struct vmbus_channel *chan)
+{
+	RTE_SET_USED(dev);
+	RTE_SET_USED(chan);
+	return true;
+}
+
 const char *get_devname_os(void)
 {
 	return "/dev/hv_uio";