All of lore.kernel.org
 help / color / mirror / Atom feed
From: Srikanth Kaka <srikanth.k@oneconvergence.com>
To: Stephen Hemminger <sthemmin@microsoft.com>,
	Long Li <longli@microsoft.com>
Cc: dev@dpdk.org, Vag Singh <vag.singh@oneconvergence.com>,
	Anand Thulasiram <avelu@juniper.net>,
	Srikanth Kaka <srikanth.k@oneconvergence.com>
Subject: [PATCH v4 03/14] bus/vmbus: move OS independent UIO functions
Date: Mon, 18 Apr 2022 09:59:04 +0530	[thread overview]
Message-ID: <20220418042915.5765-4-srikanth.k@oneconvergence.com> (raw)
In-Reply-To: <20220418042915.5765-1-srikanth.k@oneconvergence.com>

Moved all Linux independent UIO functions to OSI dir.
Split the vmbus_uio_map_subchan() by keeping OS dependent
code in vmbus_uio_map_subchan_os() function

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/linux/vmbus_uio.c   | 292 +-----------------------
 drivers/bus/vmbus/meson.build         |   3 +-
 drivers/bus/vmbus/osi/vmbus_osi.h     |  12 +
 drivers/bus/vmbus/osi/vmbus_osi_uio.c | 306 ++++++++++++++++++++++++++
 4 files changed, 330 insertions(+), 283 deletions(-)
 create mode 100644 drivers/bus/vmbus/osi/vmbus_osi_uio.c

diff --git a/drivers/bus/vmbus/linux/vmbus_uio.c b/drivers/bus/vmbus/linux/vmbus_uio.c
index 5db70f8e0d..ea6df21409 100644
--- a/drivers/bus/vmbus/linux/vmbus_uio.c
+++ b/drivers/bus/vmbus/linux/vmbus_uio.c
@@ -21,233 +21,18 @@
 #include <rte_string_fns.h>
 
 #include "private.h"
+#include "vmbus_osi.h"
 
 /** Pathname of VMBUS devices directory. */
 #define SYSFS_VMBUS_DEVICES "/sys/bus/vmbus/devices"
 
-static void *vmbus_map_addr;
-
-/* Control interrupts */
-void vmbus_uio_irq_control(struct rte_vmbus_device *dev, int32_t onoff)
-{
-	if ((rte_intr_fd_get(dev->intr_handle) < 0) ||
-	    write(rte_intr_fd_get(dev->intr_handle), &onoff,
-		  sizeof(onoff)) < 0) {
-		VMBUS_LOG(ERR, "cannot write to %d:%s",
-			  rte_intr_fd_get(dev->intr_handle),
-			  strerror(errno));
-	}
-}
-
-int vmbus_uio_irq_read(struct rte_vmbus_device *dev)
-{
-	int32_t count;
-	int cc;
-
-	if (rte_intr_fd_get(dev->intr_handle) < 0)
-		return -1;
-
-	cc = read(rte_intr_fd_get(dev->intr_handle), &count,
-		  sizeof(count));
-	if (cc < (int)sizeof(count)) {
-		if (cc < 0) {
-			VMBUS_LOG(ERR, "IRQ read failed %s",
-				  strerror(errno));
-			return -errno;
-		}
-		VMBUS_LOG(ERR, "can't read IRQ count");
-		return -EINVAL;
-	}
-
-	return count;
-}
-
-void
-vmbus_uio_free_resource(struct rte_vmbus_device *dev,
-		struct mapped_vmbus_resource *uio_res)
-{
-	rte_free(uio_res);
-
-	if (rte_intr_dev_fd_get(dev->intr_handle) >= 0) {
-		close(rte_intr_dev_fd_get(dev->intr_handle));
-		rte_intr_dev_fd_set(dev->intr_handle, -1);
-	}
-
-	if (rte_intr_fd_get(dev->intr_handle) >= 0) {
-		close(rte_intr_fd_get(dev->intr_handle));
-		rte_intr_fd_set(dev->intr_handle, -1);
-		rte_intr_type_set(dev->intr_handle, RTE_INTR_HANDLE_UNKNOWN);
-	}
-}
-
-int
-vmbus_uio_alloc_resource(struct rte_vmbus_device *dev,
-			 struct mapped_vmbus_resource **uio_res)
-{
-	char devname[PATH_MAX]; /* contains the /dev/uioX */
-	int fd;
-
-	/* save fd if in primary process */
-	snprintf(devname, sizeof(devname), "/dev/uio%u", dev->uio_num);
-	fd = open(devname, O_RDWR);
-	if (fd < 0) {
-		VMBUS_LOG(ERR, "Cannot open %s: %s",
-			devname, strerror(errno));
-		goto error;
-	}
-
-	if (rte_intr_fd_set(dev->intr_handle, fd))
-		goto error;
-
-	if (rte_intr_type_set(dev->intr_handle, RTE_INTR_HANDLE_UIO_INTX))
-		goto error;
-
-	/* allocate the mapping details for secondary processes*/
-	*uio_res = rte_zmalloc("UIO_RES", sizeof(**uio_res), 0);
-	if (*uio_res == NULL) {
-		VMBUS_LOG(ERR, "cannot store uio mmap details");
-		goto error;
-	}
-
-	strlcpy((*uio_res)->path, devname, PATH_MAX);
-	rte_uuid_copy((*uio_res)->id, dev->device_id);
-
-	return 0;
-
-error:
-	vmbus_uio_free_resource(dev, *uio_res);
-	return -1;
-}
-
-static int
-find_max_end_va(const struct rte_memseg_list *msl, void *arg)
-{
-	size_t sz = msl->memseg_arr.len * msl->page_sz;
-	void *end_va = RTE_PTR_ADD(msl->base_va, sz);
-	void **max_va = arg;
-
-	if (*max_va < end_va)
-		*max_va = end_va;
-	return 0;
-}
-
-/*
- * TODO: this should be part of memseg api.
- *       code is duplicated from PCI.
- */
-static void *
-vmbus_find_max_end_va(void)
-{
-	void *va = NULL;
-
-	rte_memseg_list_walk(find_max_end_va, &va);
-	return va;
-}
-
-int
-vmbus_uio_map_resource_by_index(struct rte_vmbus_device *dev, int idx,
-				struct mapped_vmbus_resource *uio_res,
-				int flags)
-{
-	size_t size = dev->resource[idx].len;
-	struct vmbus_map *maps = uio_res->maps;
-	void *mapaddr;
-	off_t offset;
-	int fd;
-
-	/* devname for mmap  */
-	fd = open(uio_res->path, O_RDWR);
-	if (fd < 0) {
-		VMBUS_LOG(ERR, "Cannot open %s: %s",
-			  uio_res->path, strerror(errno));
-		return -1;
-	}
-
-	/* try mapping somewhere close to the end of hugepages */
-	if (vmbus_map_addr == NULL)
-		vmbus_map_addr = vmbus_find_max_end_va();
-
-	/* offset is special in uio it indicates which resource */
-	offset = idx * rte_mem_page_size();
-
-	mapaddr = vmbus_map_resource(vmbus_map_addr, fd, offset, size, flags);
-	close(fd);
-
-	if (mapaddr == MAP_FAILED)
-		return -1;
-
-	dev->resource[idx].addr = mapaddr;
-	vmbus_map_addr = RTE_PTR_ADD(mapaddr, size);
-
-	/* Record result of successful mapping for use by secondary */
-	maps[idx].addr = mapaddr;
-	maps[idx].size = size;
-
-	return 0;
-}
-
-static int vmbus_uio_map_primary(struct vmbus_channel *chan,
-				 void **ring_buf, uint32_t *ring_size)
-{
-	struct mapped_vmbus_resource *uio_res;
-
-	uio_res = vmbus_uio_find_resource(chan->device);
-	if (!uio_res) {
-		VMBUS_LOG(ERR, "can not find resources!");
-		return -ENOMEM;
-	}
-
-	if (uio_res->nb_maps < VMBUS_MAX_RESOURCE) {
-		VMBUS_LOG(ERR, "VMBUS: only %u resources found!",
-			  uio_res->nb_maps);
-		return -EINVAL;
-	}
-
-	*ring_size = uio_res->maps[HV_TXRX_RING_MAP].size / 2;
-	*ring_buf  = uio_res->maps[HV_TXRX_RING_MAP].addr;
-	return 0;
-}
-
-static int vmbus_uio_map_subchan(const struct rte_vmbus_device *dev,
-				 const struct vmbus_channel *chan,
-				 void **ring_buf, uint32_t *ring_size)
+int vmbus_uio_map_subchan_os(const struct rte_vmbus_device *dev,
+			     const struct vmbus_channel *chan,
+			     void **mapaddr, size_t *file_size)
 {
 	char ring_path[PATH_MAX];
-	size_t file_size;
 	struct stat sb;
-	void *mapaddr;
 	int fd;
-	struct mapped_vmbus_resource *uio_res;
-	int channel_idx;
-
-	uio_res = vmbus_uio_find_resource(dev);
-	if (!uio_res) {
-		VMBUS_LOG(ERR, "can not find resources for mapping subchan");
-		return -ENOMEM;
-	}
-
-	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
-		if (uio_res->nb_subchannels >= UIO_MAX_SUBCHANNEL) {
-			VMBUS_LOG(ERR,
-				"exceeding max subchannels UIO_MAX_SUBCHANNEL(%d)",
-				UIO_MAX_SUBCHANNEL);
-			VMBUS_LOG(ERR, "Change UIO_MAX_SUBCHANNEL and recompile");
-			return -ENOMEM;
-		}
-	} else {
-		for (channel_idx = 0; channel_idx < uio_res->nb_subchannels;
-		     channel_idx++)
-			if (uio_res->subchannel_maps[channel_idx].relid ==
-					chan->relid)
-				break;
-		if (channel_idx == uio_res->nb_subchannels) {
-			VMBUS_LOG(ERR,
-				"couldn't find sub channel %d from shared mapping in primary",
-				chan->relid);
-			return -ENOMEM;
-		}
-		vmbus_map_addr = uio_res->subchannel_maps[channel_idx].addr;
-	}
 
 	snprintf(ring_path, sizeof(ring_path),
 		 "%s/%s/channels/%u/ring",
@@ -267,68 +52,23 @@ static int vmbus_uio_map_subchan(const struct rte_vmbus_device *dev,
 		close(fd);
 		return -errno;
 	}
-	file_size = sb.st_size;
+	*file_size = sb.st_size;
 
-	if (file_size == 0 || (file_size & (rte_mem_page_size() - 1))) {
+	if (*file_size == 0 || (*file_size & (rte_mem_page_size() - 1))) {
 		VMBUS_LOG(ERR, "incorrect size %s: %zu",
-			  ring_path, file_size);
+			  ring_path, *file_size);
 
 		close(fd);
 		return -EINVAL;
 	}
 
-	mapaddr = vmbus_map_resource(vmbus_map_addr, fd,
-				     0, file_size, 0);
+	*mapaddr = vmbus_map_resource(vmbus_map_addr, fd,
+				     0, *file_size, 0);
 	close(fd);
 
-	if (mapaddr == MAP_FAILED)
+	if (*mapaddr == MAP_FAILED)
 		return -EIO;
 
-	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
-
-		/* Add this mapping to uio_res for use by secondary */
-		uio_res->subchannel_maps[uio_res->nb_subchannels].relid =
-			chan->relid;
-		uio_res->subchannel_maps[uio_res->nb_subchannels].addr =
-			mapaddr;
-		uio_res->subchannel_maps[uio_res->nb_subchannels].size =
-			file_size;
-		uio_res->nb_subchannels++;
-
-		vmbus_map_addr = RTE_PTR_ADD(mapaddr, file_size);
-	} else {
-		if (mapaddr != vmbus_map_addr) {
-			VMBUS_LOG(ERR, "failed to map channel %d to addr %p",
-					chan->relid, mapaddr);
-			vmbus_unmap_resource(mapaddr, file_size);
-			return -EIO;
-		}
-	}
-
-	*ring_size = file_size / 2;
-	*ring_buf = mapaddr;
-
-	return 0;
-}
-
-int vmbus_uio_map_rings(struct vmbus_channel *chan)
-{
-	const struct rte_vmbus_device *dev = chan->device;
-	uint32_t ring_size;
-	void *ring_buf;
-	int ret;
-
-	/* Primary channel */
-	if (chan->subchannel_id == 0)
-		ret = vmbus_uio_map_primary(chan, &ring_buf, &ring_size);
-	else
-		ret = vmbus_uio_map_subchan(dev, chan, &ring_buf, &ring_size);
-
-	if (ret)
-		return ret;
-
-	vmbus_br_setup(&chan->txbr, ring_buf, ring_size);
-	vmbus_br_setup(&chan->rxbr, (char *)ring_buf + ring_size, ring_size);
 	return 0;
 }
 
@@ -377,18 +117,6 @@ bool vmbus_uio_subchannels_supported(const struct rte_vmbus_device *dev,
 	return vmbus_uio_ring_present(dev, chan->relid);
 }
 
-static bool vmbus_isnew_subchannel(struct vmbus_channel *primary,
-				   unsigned long id)
-{
-	const struct vmbus_channel *c;
-
-	STAILQ_FOREACH(c, &primary->subchannel_list, next) {
-		if (c->relid == id)
-			return false;
-	}
-	return true;
-}
-
 int vmbus_uio_get_subchan(struct vmbus_channel *primary,
 			  struct vmbus_channel **subchan)
 {
diff --git a/drivers/bus/vmbus/meson.build b/drivers/bus/vmbus/meson.build
index cbcba44e16..fe9c72bce1 100644
--- a/drivers/bus/vmbus/meson.build
+++ b/drivers/bus/vmbus/meson.build
@@ -18,7 +18,8 @@ sources = files(
 
 includes += include_directories('osi')
 sources += files(
-	'osi/vmbus_osi_bus.c'
+	'osi/vmbus_osi_bus.c',
+	'osi/vmbus_osi_uio.c'
 )
 
 if is_linux
diff --git a/drivers/bus/vmbus/osi/vmbus_osi.h b/drivers/bus/vmbus/osi/vmbus_osi.h
index 2db9399181..579c4bb99c 100644
--- a/drivers/bus/vmbus/osi/vmbus_osi.h
+++ b/drivers/bus/vmbus/osi/vmbus_osi.h
@@ -6,6 +6,18 @@
 #ifndef _VMBUS_BUS_OSI_H_
 #define _VMBUS_BUS_OSI_H_
 
+#include <rte_bus_vmbus.h>
+
+#include "private.h"
+
 extern const rte_uuid_t vmbus_nic_uuid;
+extern void *vmbus_map_addr;
+
+int vmbus_uio_map_subchan_os(const struct rte_vmbus_device *dev,
+			     const struct vmbus_channel *chan,
+			     void **mapaddr, size_t *file_size);
+
+bool vmbus_isnew_subchannel(struct vmbus_channel *primary,
+			    unsigned long id);
 
 #endif /* _VMBUS_BUS_OSI_H_ */
diff --git a/drivers/bus/vmbus/osi/vmbus_osi_uio.c b/drivers/bus/vmbus/osi/vmbus_osi_uio.c
new file mode 100644
index 0000000000..35106e247e
--- /dev/null
+++ b/drivers/bus/vmbus/osi/vmbus_osi_uio.c
@@ -0,0 +1,306 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2018, Microsoft Corporation.
+ * All Rights Reserved.
+ */
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+
+#include <rte_eal.h>
+#include <rte_log.h>
+#include <rte_bus.h>
+#include <rte_memory.h>
+#include <rte_common.h>
+#include <rte_malloc.h>
+#include <rte_bus_vmbus.h>
+#include <rte_string_fns.h>
+
+#include "private.h"
+#include "vmbus_osi.h"
+
+void *vmbus_map_addr;
+
+/* Control interrupts */
+void vmbus_uio_irq_control(struct rte_vmbus_device *dev, int32_t onoff)
+{
+	if ((rte_intr_fd_get(dev->intr_handle) < 0) ||
+	    write(rte_intr_fd_get(dev->intr_handle), &onoff,
+		  sizeof(onoff)) < 0) {
+		VMBUS_LOG(ERR, "cannot write to %d:%s",
+			  rte_intr_fd_get(dev->intr_handle),
+			  strerror(errno));
+	}
+}
+
+int vmbus_uio_irq_read(struct rte_vmbus_device *dev)
+{
+	int32_t count;
+	int cc;
+
+	if (rte_intr_fd_get(dev->intr_handle) < 0)
+		return -1;
+
+	cc = read(rte_intr_fd_get(dev->intr_handle), &count,
+		  sizeof(count));
+	if (cc < (int)sizeof(count)) {
+		if (cc < 0) {
+			VMBUS_LOG(ERR, "IRQ read failed %s",
+				  strerror(errno));
+			return -errno;
+		}
+		VMBUS_LOG(ERR, "can't read IRQ count");
+		return -EINVAL;
+	}
+
+	return count;
+}
+
+void
+vmbus_uio_free_resource(struct rte_vmbus_device *dev,
+		struct mapped_vmbus_resource *uio_res)
+{
+	rte_free(uio_res);
+
+	if (rte_intr_dev_fd_get(dev->intr_handle) >= 0) {
+		close(rte_intr_dev_fd_get(dev->intr_handle));
+		rte_intr_dev_fd_set(dev->intr_handle, -1);
+	}
+
+	if (rte_intr_fd_get(dev->intr_handle) >= 0) {
+		close(rte_intr_fd_get(dev->intr_handle));
+		rte_intr_fd_set(dev->intr_handle, -1);
+		rte_intr_type_set(dev->intr_handle, RTE_INTR_HANDLE_UNKNOWN);
+	}
+}
+
+int
+vmbus_uio_alloc_resource(struct rte_vmbus_device *dev,
+			 struct mapped_vmbus_resource **uio_res)
+{
+	char devname[PATH_MAX]; /* contains the /dev/uioX */
+	int fd;
+
+	/* save fd if in primary process */
+	snprintf(devname, sizeof(devname), "/dev/uio%u", dev->uio_num);
+	fd = open(devname, O_RDWR);
+	if (fd < 0) {
+		VMBUS_LOG(ERR, "Cannot open %s: %s",
+			devname, strerror(errno));
+		goto error;
+	}
+
+	if (rte_intr_fd_set(dev->intr_handle, fd))
+		goto error;
+
+	if (rte_intr_type_set(dev->intr_handle, RTE_INTR_HANDLE_UIO_INTX))
+		goto error;
+
+	/* allocate the mapping details for secondary processes*/
+	*uio_res = rte_zmalloc("UIO_RES", sizeof(**uio_res), 0);
+	if (*uio_res == NULL) {
+		VMBUS_LOG(ERR, "cannot store uio mmap details");
+		goto error;
+	}
+
+	strlcpy((*uio_res)->path, devname, PATH_MAX);
+	rte_uuid_copy((*uio_res)->id, dev->device_id);
+
+	return 0;
+
+error:
+	vmbus_uio_free_resource(dev, *uio_res);
+	return -1;
+}
+
+static int
+find_max_end_va(const struct rte_memseg_list *msl, void *arg)
+{
+	size_t sz = msl->memseg_arr.len * msl->page_sz;
+	void *end_va = RTE_PTR_ADD(msl->base_va, sz);
+	void **max_va = arg;
+
+	if (*max_va < end_va)
+		*max_va = end_va;
+	return 0;
+}
+
+/*
+ * TODO: this should be part of memseg api.
+ *       code is duplicated from PCI.
+ */
+static void *
+vmbus_find_max_end_va(void)
+{
+	void *va = NULL;
+
+	rte_memseg_list_walk(find_max_end_va, &va);
+	return va;
+}
+
+int
+vmbus_uio_map_resource_by_index(struct rte_vmbus_device *dev, int idx,
+				struct mapped_vmbus_resource *uio_res,
+				int flags)
+{
+	size_t size = dev->resource[idx].len;
+	struct vmbus_map *maps = uio_res->maps;
+	void *mapaddr;
+	off_t offset;
+	int fd;
+
+	/* devname for mmap  */
+	fd = open(uio_res->path, O_RDWR);
+	if (fd < 0) {
+		VMBUS_LOG(ERR, "Cannot open %s: %s",
+			  uio_res->path, strerror(errno));
+		return -1;
+	}
+
+	/* try mapping somewhere close to the end of hugepages */
+	if (vmbus_map_addr == NULL)
+		vmbus_map_addr = vmbus_find_max_end_va();
+
+	/* offset is special in uio it indicates which resource */
+	offset = idx * rte_mem_page_size();
+
+	mapaddr = vmbus_map_resource(vmbus_map_addr, fd, offset, size, flags);
+	close(fd);
+
+	if (mapaddr == MAP_FAILED)
+		return -1;
+
+	dev->resource[idx].addr = mapaddr;
+	vmbus_map_addr = RTE_PTR_ADD(mapaddr, size);
+
+	/* Record result of successful mapping for use by secondary */
+	maps[idx].addr = mapaddr;
+	maps[idx].size = size;
+
+	return 0;
+}
+
+static int vmbus_uio_map_primary(struct vmbus_channel *chan,
+				 void **ring_buf, uint32_t *ring_size)
+{
+	struct mapped_vmbus_resource *uio_res;
+
+	uio_res = vmbus_uio_find_resource(chan->device);
+	if (!uio_res) {
+		VMBUS_LOG(ERR, "can not find resources!");
+		return -ENOMEM;
+	}
+
+	if (uio_res->nb_maps < VMBUS_MAX_RESOURCE) {
+		VMBUS_LOG(ERR, "VMBUS: only %u resources found!",
+			  uio_res->nb_maps);
+		return -EINVAL;
+	}
+
+	*ring_size = uio_res->maps[HV_TXRX_RING_MAP].size / 2;
+	*ring_buf  = uio_res->maps[HV_TXRX_RING_MAP].addr;
+	return 0;
+}
+
+static int vmbus_uio_map_subchan(const struct rte_vmbus_device *dev,
+				 const struct vmbus_channel *chan,
+				 void **ring_buf, uint32_t *ring_size)
+{
+	size_t file_size = 0;
+	void *mapaddr = NULL;
+	struct mapped_vmbus_resource *uio_res;
+	int channel_idx;
+	int ret;
+
+	uio_res = vmbus_uio_find_resource(dev);
+	if (!uio_res) {
+		VMBUS_LOG(ERR, "can not find resources for mapping subchan");
+		return -ENOMEM;
+	}
+
+	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
+		if (uio_res->nb_subchannels >= UIO_MAX_SUBCHANNEL) {
+			VMBUS_LOG(ERR,
+				"exceeding max subchannels UIO_MAX_SUBCHANNEL(%d)",
+				UIO_MAX_SUBCHANNEL);
+			VMBUS_LOG(ERR, "Change UIO_MAX_SUBCHANNEL and recompile");
+			return -ENOMEM;
+		}
+	} else {
+		for (channel_idx = 0; channel_idx < uio_res->nb_subchannels;
+		     channel_idx++)
+			if (uio_res->subchannel_maps[channel_idx].relid ==
+					chan->relid)
+				break;
+		if (channel_idx == uio_res->nb_subchannels) {
+			VMBUS_LOG(ERR,
+				"couldn't find sub channel %d from shared mapping in primary",
+				chan->relid);
+			return -ENOMEM;
+		}
+		vmbus_map_addr = uio_res->subchannel_maps[channel_idx].addr;
+	}
+
+	ret = vmbus_uio_map_subchan_os(dev, chan, &mapaddr, &file_size);
+	if (ret)
+		return ret;
+
+	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
+
+		/* Add this mapping to uio_res for use by secondary */
+		uio_res->subchannel_maps[uio_res->nb_subchannels].relid =
+			chan->relid;
+		uio_res->subchannel_maps[uio_res->nb_subchannels].addr =
+			mapaddr;
+		uio_res->subchannel_maps[uio_res->nb_subchannels].size =
+			file_size;
+		uio_res->nb_subchannels++;
+
+		vmbus_map_addr = RTE_PTR_ADD(mapaddr, file_size);
+	} else {
+		if (mapaddr != vmbus_map_addr) {
+			VMBUS_LOG(ERR, "failed to map channel %d to addr %p",
+					chan->relid, mapaddr);
+			vmbus_unmap_resource(mapaddr, file_size);
+			return -EIO;
+		}
+	}
+
+	*ring_size = file_size / 2;
+	*ring_buf = mapaddr;
+
+	return 0;
+}
+
+int vmbus_uio_map_rings(struct vmbus_channel *chan)
+{
+	const struct rte_vmbus_device *dev = chan->device;
+	uint32_t ring_size = 0;
+	void *ring_buf = NULL;
+	int ret;
+
+	/* Primary channel */
+	if (chan->subchannel_id == 0)
+		ret = vmbus_uio_map_primary(chan, &ring_buf, &ring_size);
+	else
+		ret = vmbus_uio_map_subchan(dev, chan, &ring_buf, &ring_size);
+
+	if (ret)
+		return ret;
+
+	vmbus_br_setup(&chan->txbr, ring_buf, ring_size);
+	vmbus_br_setup(&chan->rxbr, (char *)ring_buf + ring_size, ring_size);
+	return 0;
+}
+
+bool vmbus_isnew_subchannel(struct vmbus_channel *primary,
+			    unsigned long id)
+{
+	const struct vmbus_channel *c;
+
+	STAILQ_FOREACH(c, &primary->subchannel_list, next) {
+		if (c->relid == id)
+			return false;
+	}
+	return true;
+}
-- 
2.30.2


  parent reply	other threads:[~2022-04-19  9:34 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-27 13:42 [dpdk-dev] [PATCH 00/11] add FreeBSD support to VMBUS & NetVSC PMDs Srikanth Kaka
2021-09-27 13:42 ` [dpdk-dev] [PATCH 01/11] bus/vmbus: stub for FreeBSD support Srikanth Kaka
2021-11-06 20:44   ` Long Li
2021-09-27 13:42 ` [dpdk-dev] [PATCH 02/11] bus/vmbus: scan and get the network device Srikanth Kaka
2021-10-08 11:39   ` [dpdk-dev] [PATCH v2 " Srikanth Kaka
2021-09-27 13:42 ` [dpdk-dev] [PATCH 03/11] bus/vmbus: handle mapping of device resources Srikanth Kaka
2021-09-27 13:42 ` [dpdk-dev] [PATCH 04/11] bus/vmbus: get device resource values using sysctl Srikanth Kaka
2021-09-27 13:42 ` [dpdk-dev] [PATCH 05/11] bus/vmbus: open subchannels Srikanth Kaka
2021-09-30 23:17   ` Long Li
2021-10-08 11:41   ` [dpdk-dev] [PATCH v2 " Srikanth Kaka
2021-11-06 20:49     ` Long Li
2022-02-08 16:35       ` Thomas Monjalon
2021-09-27 13:42 ` [dpdk-dev] [PATCH 06/11] net/netvsc: request HV_UIO to open sub-channels Srikanth Kaka
2021-09-30 23:19   ` Long Li
2021-10-01  5:31     ` Srikanth K
2021-09-27 13:42 ` [dpdk-dev] [PATCH 07/11] bus/vmbus: map the subchannel resources Srikanth Kaka
2021-09-27 13:42 ` [dpdk-dev] [PATCH 08/11] net/netvsc: moving event monitoring support Srikanth Kaka
2021-11-06 20:51   ` Long Li
2021-09-27 13:42 ` [dpdk-dev] [PATCH 09/11] net/netvsc: moving hotplug retry to OS dir Srikanth Kaka
2021-11-06 20:54   ` Long Li
2021-09-27 13:42 ` [dpdk-dev] [PATCH 10/11] bus/vmbus: add meson support for FreeBSD OS Srikanth Kaka
2021-11-06 20:54   ` Long Li
2021-09-27 13:42 ` [dpdk-dev] [PATCH 11/11] net/netvsc: add meson support for FreeBSD Srikanth Kaka
2021-10-08 11:42   ` [dpdk-dev] [PATCH v2 " Srikanth Kaka
2021-11-06 20:50     ` Long Li
2021-09-30 23:25 ` [dpdk-dev] [PATCH 00/11] add FreeBSD support to VMBUS & NetVSC PMDs Long Li
2022-02-17 16:05 ` [PATCH v3 00/15] " Srikanth Kaka
2022-02-17 16:05   ` [PATCH v3 01/15] bus/vmbus: scan and get the network device Srikanth Kaka
2022-02-17 16:29     ` Stephen Hemminger
2022-02-17 16:06   ` [PATCH v3 02/15] bus/vmbus: handle mapping of device resources Srikanth Kaka
2022-02-17 16:06   ` [PATCH v3 03/15] bus/vmbus: get device resource values using sysctl Srikanth Kaka
2022-02-17 16:06   ` [PATCH v3 04/15] bus/vmbus: add resource by index Srikanth Kaka
2022-02-17 16:06   ` [PATCH v3 05/15] net/netvsc: make event monitor OS dependent Srikanth Kaka
2022-02-17 16:06   ` [PATCH v3 06/15] bus/vmbus: add ring mapping APIs Srikanth Kaka
2022-02-17 16:06   ` [PATCH v3 07/15] bus/vmbus: add stub for subchannel support API Srikanth Kaka
2022-02-17 16:06   ` [PATCH v3 08/15] bus/vmbus: open subchannels Srikanth Kaka
2022-02-17 16:06   ` [PATCH v3 09/15] net/netvsc: make IOCTL call to " Srikanth Kaka
2022-02-17 16:06   ` [PATCH v3 10/15] bus/vmbus: get subchannel info Srikanth Kaka
2022-02-17 16:06   ` [PATCH v3 11/15] net/netvsc: moving hotplug retry to OS dir Srikanth Kaka
2022-02-17 16:06   ` [PATCH v3 12/15] bus/vmbus: add meson support for FreeBSD Srikanth Kaka
2022-02-17 16:06   ` [PATCH v3 13/15] net/netvsc: " Srikanth Kaka
2022-02-17 16:06   ` [PATCH v3 14/15] bus/vmbus: add APIs to mask/unmask IRQs Srikanth Kaka
2022-02-17 16:06   ` [PATCH v3 15/15] bus/vmbus: update MAINTAINERS and docs Srikanth Kaka
2022-04-18  4:29     ` [PATCH v4 00/14] add FreeBSD support to VMBUS & NetVSC PMDs Srikanth Kaka
2022-04-18  4:29       ` [PATCH v4 01/14] bus/vmbus: move independent code from Linux Srikanth Kaka
2022-04-19 14:49         ` Stephen Hemminger
2022-04-19 14:52           ` Srikanth K
2022-04-18  4:29       ` [PATCH v4 02/14] bus/vmbus: move independent bus functions Srikanth Kaka
2022-04-18  4:29       ` Srikanth Kaka [this message]
2022-04-18  4:29       ` [PATCH v4 04/14] bus/vmbus: scan and get the network device on FreeBSD Srikanth Kaka
2022-04-18  4:29       ` [PATCH v4 05/14] bus/vmbus: handle mapping of device resources Srikanth Kaka
2022-04-18  4:29       ` [PATCH v4 06/14] bus/vmbus: get device resource values using sysctl Srikanth Kaka
2022-04-18  4:29       ` [PATCH v4 07/14] net/netvsc: make event monitor OS dependent Srikanth Kaka
2022-04-18  4:29       ` [PATCH v4 08/14] bus/vmbus: add sub-channel mapping support Srikanth Kaka
2022-04-18  4:29       ` [PATCH v4 09/14] bus/vmbus: open subchannels Srikanth Kaka
2022-04-19 15:00         ` Stephen Hemminger
2022-04-18  4:29       ` [PATCH v4 10/14] net/netvsc: make IOCTL call to " Srikanth Kaka
2022-04-18  4:29       ` [PATCH v4 11/14] bus/vmbus: get subchannel info Srikanth Kaka
2022-04-19 14:51         ` Stephen Hemminger
2022-04-18  4:29       ` [PATCH v4 12/14] net/netvsc: moving hotplug retry to OS dir Srikanth Kaka
2022-04-18  4:29       ` [PATCH v4 13/14] bus/vmbus: add meson support for FreeBSD Srikanth Kaka
2022-04-18  4:29       ` [PATCH v4 14/14] bus/vmbus: update MAINTAINERS and docs Srikanth Kaka
2022-04-23  4:28       ` [PATCH v5 00/14] add FreeBSD support to VMBUS & NetVSC PMDs Srikanth Kaka
2022-04-23  4:28         ` [PATCH v5 01/14] bus/vmbus: move independent code from Linux Srikanth Kaka
2022-04-23  4:28         ` [PATCH v5 02/14] bus/vmbus: move independent bus functions Srikanth Kaka
2022-04-23  4:28         ` [PATCH v5 03/14] bus/vmbus: move OS independent UIO functions Srikanth Kaka
2022-04-23  4:28         ` [PATCH v5 04/14] bus/vmbus: scan and get the network device on FreeBSD Srikanth Kaka
2022-04-23  4:28         ` [PATCH v5 05/14] bus/vmbus: handle mapping of device resources Srikanth Kaka
2022-04-23  4:28         ` [PATCH v5 06/14] bus/vmbus: get device resource values using sysctl Srikanth Kaka
2022-04-23  4:28         ` [PATCH v5 07/14] net/netvsc: make event monitor OS dependent Srikanth Kaka
2022-04-23  4:28         ` [PATCH v5 08/14] bus/vmbus: add sub-channel mapping support Srikanth Kaka
2022-04-23  4:28         ` [PATCH v5 09/14] bus/vmbus: open subchannels Srikanth Kaka
2023-08-10 15:41           ` Stephen Hemminger
2022-04-23  4:28         ` [PATCH v5 10/14] net/netvsc: make IOCTL call to " Srikanth Kaka
2022-04-23  4:28         ` [PATCH v5 11/14] bus/vmbus: get subchannel info Srikanth Kaka
2022-04-23  4:28         ` [PATCH v5 12/14] net/netvsc: moving hotplug retry to OS dir Srikanth Kaka
2022-04-23  4:28         ` [PATCH v5 13/14] bus/vmbus: add meson support for FreeBSD Srikanth Kaka
2022-04-23  4:28         ` [PATCH v5 14/14] bus/vmbus: update MAINTAINERS and docs Srikanth Kaka
2023-08-10 15:44           ` Stephen Hemminger
2022-05-18  8:18         ` [PATCH v5 00/14] add FreeBSD support to VMBUS & NetVSC PMDs Thomas Monjalon
2022-10-06 14:58           ` Thomas Monjalon
2023-07-04  0:07             ` Stephen Hemminger
2022-04-14  8:54   ` [PATCH v3 00/15] " Thomas Monjalon
2022-04-14  9:01     ` Srikanth K

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220418042915.5765-4-srikanth.k@oneconvergence.com \
    --to=srikanth.k@oneconvergence.com \
    --cc=avelu@juniper.net \
    --cc=dev@dpdk.org \
    --cc=longli@microsoft.com \
    --cc=sthemmin@microsoft.com \
    --cc=vag.singh@oneconvergence.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.