DPDK patches and discussions
 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: [dpdk-dev] [PATCH 07/11] bus/vmbus: map the subchannel resources
Date: Mon, 27 Sep 2021 19:12:27 +0530	[thread overview]
Message-ID: <20210927134231.11177-8-srikanth.k@oneconvergence.com> (raw)
In-Reply-To: <20210927134231.11177-1-srikanth.k@oneconvergence.com>

Using sysctl, the resource values of subchannels are obtained and
an mmap request to made to their buffers.

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 | 181 ++++++++++----------------
 1 file changed, 66 insertions(+), 115 deletions(-)

diff --git a/drivers/bus/vmbus/freebsd/vmbus_uio.c b/drivers/bus/vmbus/freebsd/vmbus_uio.c
index 022ac85302..14b858f39d 100644
--- a/drivers/bus/vmbus/freebsd/vmbus_uio.c
+++ b/drivers/bus/vmbus/freebsd/vmbus_uio.c
@@ -24,8 +24,11 @@
 
 #include "private.h"
 
-/** Pathname of VMBUS devices directory. */
-#define SYSFS_VMBUS_DEVICES "/sys/bus/vmbus/devices"
+/* Macros to distinguish mmap request
+ * [7-0] - Device memory region
+ * [15-8]- Sub-channel id
+ */
+#define UH_SUBCHAN_MASK_SHIFT  8
 
 /* ioctl */
 #define HVIOOPENSUBCHAN     _IOW('h', 14, uint32_t)
@@ -274,19 +277,17 @@ static int vmbus_uio_map_primary(struct vmbus_channel *chan,
 }
 
 static int vmbus_uio_map_subchan(const struct rte_vmbus_device *dev,
-				 const struct vmbus_channel *chan,
+				 struct vmbus_channel *chan,
 				 void **ring_buf, uint32_t *ring_size)
 {
 	char ring_path[PATH_MAX];
-	size_t file_size;
-	struct stat sb;
+	size_t size;
 	void *mapaddr;
+	off_t offset;
 	int fd;
 
 	snprintf(ring_path, sizeof(ring_path),
-		 "%s/%s/channels/%u/ring",
-		 SYSFS_VMBUS_DEVICES, dev->device.name,
-		 chan->relid);
+		 "/dev/hv_uio%d", dev->uio_num);
 
 	fd = open(ring_path, O_RDWR);
 	if (fd < 0) {
@@ -295,33 +296,21 @@ static int vmbus_uio_map_subchan(const struct rte_vmbus_device *dev,
 		return -errno;
 	}
 
-	if (fstat(fd, &sb) < 0) {
-		VMBUS_LOG(ERR, "Cannot state %s: %s",
-			  ring_path, strerror(errno));
-		close(fd);
-		return -errno;
-	}
-	file_size = sb.st_size;
-
-	if (file_size == 0 || (file_size & (rte_mem_page_size() - 1))) {
-		VMBUS_LOG(ERR, "incorrect size %s: %zu",
-			  ring_path, file_size);
-
-		close(fd);
-		return -EINVAL;
-	}
+	/* 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,
-				     0, file_size, 0);
+				     offset, size, 0);
 	close(fd);
 
 	if (mapaddr == MAP_FAILED)
 		return -EIO;
 
-	*ring_size = file_size / 2;
+	*ring_size = size / 2;
 	*ring_buf = mapaddr;
 
-	vmbus_map_addr = RTE_PTR_ADD(mapaddr, file_size);
+	vmbus_map_addr = RTE_PTR_ADD(mapaddr, size);
 	return 0;
 }
 
@@ -336,9 +325,7 @@ vmbus_uio_map_secondary_subchan(const struct rte_vmbus_device *dev,
 	int fd;
 
 	snprintf(ring_path, sizeof(ring_path),
-		 "%s/%s/channels/%u/ring",
-		 SYSFS_VMBUS_DEVICES, dev->device.name,
-		 chan->relid);
+		 "/dev/ring%d", dev->uio_num);
 
 	ring_buf = br->vbr;
 	ring_size = br->dsize + sizeof(struct vmbus_bufring);
@@ -391,32 +378,6 @@ int vmbus_uio_map_rings(struct vmbus_channel *chan)
 	return 0;
 }
 
-static int vmbus_uio_sysfs_read(const char *dir, const char *name,
-				unsigned long *val, unsigned long max_range)
-{
-	char path[PATH_MAX];
-	FILE *f;
-	int ret;
-
-	snprintf(path, sizeof(path), "%s/%s", dir, name);
-	f = fopen(path, "r");
-	if (!f) {
-		VMBUS_LOG(ERR, "can't open %s:%s",
-			  path, strerror(errno));
-		return -errno;
-	}
-
-	if (fscanf(f, "%lu", val) != 1)
-		ret = -EIO;
-	else if (*val > max_range)
-		ret = -ERANGE;
-	else
-		ret = 0;
-	fclose(f);
-
-	return ret;
-}
-
 bool vmbus_uio_subchannels_supported(const struct rte_vmbus_device *dev,
 				     const struct vmbus_channel *chan)
 {
@@ -426,7 +387,7 @@ bool vmbus_uio_subchannels_supported(const struct rte_vmbus_device *dev,
 }
 
 static bool vmbus_isnew_subchannel(struct vmbus_channel *primary,
-				   unsigned long id)
+				   uint16_t id)
 {
 	const struct vmbus_channel *c;
 
@@ -441,83 +402,73 @@ int vmbus_uio_get_subchan(struct vmbus_channel *primary,
 			  struct vmbus_channel **subchan)
 {
 	const struct rte_vmbus_device *dev = primary->device;
-	char chan_path[PATH_MAX], subchan_path[PATH_MAX];
-	struct dirent *ent;
-	DIR *chan_dir;
+	char sysctlBuffer[PATH_MAX], sysctlVar[PATH_MAX];
+	size_t len = PATH_MAX, sysctl_len;
+	/* nr_schan, relid, subid & monid datatype must match kernel's for sysctl */
+	uint32_t relid, subid, nr_schan, i;
+	uint8_t monid;
 	int err;
 
-	snprintf(chan_path, sizeof(chan_path),
-		 "%s/%s/channels",
-		 SYSFS_VMBUS_DEVICES, dev->device.name);
-
-	chan_dir = opendir(chan_path);
-	if (!chan_dir) {
-		VMBUS_LOG(ERR, "cannot open %s: %s",
-			  chan_path, strerror(errno));
-		return -errno;
+	/* get no. of sub-channels opened by hv_uio
+	 * dev.hv_uio.0.subchan_cnt
+	 */
+	snprintf(sysctlVar, len, "dev.%s.%d.subchan_cnt", driver_name,
+		 dev->uio_num);
+	sysctl_len = sizeof(nr_schan);
+	if (sysctlbyname(sysctlVar, &nr_schan, &sysctl_len, NULL, 0) < 0) {
+		VMBUS_LOG(ERR, "could not read %s : %s", sysctlVar,
+				strerror(errno));
+		return -1;
 	}
 
-	while ((ent = readdir(chan_dir))) {
-		unsigned long relid, subid, monid;
-		char *endp;
-
-		if (ent->d_name[0] == '.')
-			continue;
-
-		errno = 0;
-		relid = strtoul(ent->d_name, &endp, 0);
-		if (*endp || errno != 0 || relid > UINT16_MAX) {
-			VMBUS_LOG(NOTICE, "not a valid channel relid: %s",
-				  ent->d_name);
-			continue;
-		}
-
-		if (!vmbus_isnew_subchannel(primary, relid)) {
-			VMBUS_LOG(DEBUG, "skip already found channel: %lu",
-				  relid);
-			continue;
+	/* dev.hv_uio.0.channel.14.sub */
+	snprintf(sysctlBuffer, len, "dev.%s.%d.channel.%u.sub", driver_name,
+		 dev->uio_num, primary->relid);
+	for (i = 1; i <= nr_schan; i++) {
+		/* get relid */
+		snprintf(sysctlVar, len, "%s.%u.chanid", sysctlBuffer, i);
+		sysctl_len = sizeof(relid);
+		if (sysctlbyname(sysctlVar, &relid, &sysctl_len, NULL, 0) < 0) {
+			VMBUS_LOG(ERR, "could not read %s : %s", sysctlVar,
+					strerror(errno));
+			goto error;
 		}
 
-		if (!vmbus_uio_ring_present(dev, relid)) {
-			VMBUS_LOG(DEBUG, "ring mmap not found (yet) for: %lu",
-				  relid);
+		if (!vmbus_isnew_subchannel(primary, (uint16_t)relid)) {
+			VMBUS_LOG(DEBUG, "skip already found channel: %u",
+					relid);
 			continue;
 		}
 
-		snprintf(subchan_path, sizeof(subchan_path), "%s/%lu",
-			 chan_path, relid);
-		err = vmbus_uio_sysfs_read(subchan_path, "subchannel_id",
-					   &subid, UINT16_MAX);
-		if (err) {
-			VMBUS_LOG(NOTICE, "no subchannel_id in %s:%s",
-				  subchan_path, strerror(-err));
-			goto fail;
+		/* get sub-channel id */
+		snprintf(sysctlVar, len, "%s.%u.ch_subidx", sysctlBuffer, i);
+		sysctl_len = sizeof(subid);
+		if (sysctlbyname(sysctlVar, &subid, &sysctl_len, NULL, 0) < 0) {
+			VMBUS_LOG(ERR, "could not read %s : %s", sysctlVar,
+					strerror(errno));
+			goto error;
 		}
 
-		if (subid == 0)
-			continue;	/* skip primary channel */
-
-		err = vmbus_uio_sysfs_read(subchan_path, "monitor_id",
-					   &monid, UINT8_MAX);
-		if (err) {
-			VMBUS_LOG(NOTICE, "no monitor_id in %s:%s",
-				  subchan_path, strerror(-err));
-			goto fail;
+		/* get monitor id */
+		snprintf(sysctlVar, len, "%s.%u.monitor_id", sysctlBuffer, i);
+		sysctl_len = sizeof(monid);
+		if (sysctlbyname(sysctlVar, &monid, &sysctl_len, NULL, 0) < 0) {
+			VMBUS_LOG(ERR, "could not read %s : %s", sysctlVar,
+					strerror(errno));
+			goto error;
 		}
 
-		err = vmbus_chan_create(dev, relid, subid, monid, subchan);
+		err = vmbus_chan_create(dev, (uint16_t)relid, (uint16_t)subid,
+					monid, subchan);
 		if (err) {
 			VMBUS_LOG(ERR, "subchannel setup failed");
-			goto fail;
+			return err;
 		}
 		break;
 	}
-	closedir(chan_dir);
-
-	return (ent == NULL) ? -ENOENT : 0;
-fail:
-	closedir(chan_dir);
-	return err;
+	return 0;
+error:
+	return -1;
 }
 
 int vmbus_uio_subchan_open(struct rte_vmbus_device *dev, uint32_t subchan)
-- 
2.30.2


  parent reply	other threads:[~2021-09-27 15:01 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 ` Srikanth Kaka [this message]
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       ` [PATCH v4 03/14] bus/vmbus: move OS independent UIO functions Srikanth Kaka
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=20210927134231.11177-8-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).