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: [PATCH v5 06/14] bus/vmbus: get device resource values using sysctl
Date: Sat, 23 Apr 2022 09:58:41 +0530	[thread overview]
Message-ID: <20220423042849.7718-7-srikanth.k@oneconvergence.com> (raw)
In-Reply-To: <20220423042849.7718-1-srikanth.k@oneconvergence.com>

The UIO device's attribute (relid, monitor id, etc) values are
retrieved using following sysctl variables:
$ sysctl dev.hv_uio.0
dev.hv_uio.0.send_buf.gpadl: 925241
dev.hv_uio.0.send_buf.size: 16777216
dev.hv_uio.0.recv_buf.gpadl: 925240
dev.hv_uio.0.recv_buf.size: 32505856
dev.hv_uio.0.monitor_page.size: 4096
dev.hv_uio.0.int_page.size: 4096

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   | 105 ++++++++++++++++++++++++++++++++
 drivers/bus/vmbus/linux/vmbus_uio.c     |  16 +++++
 drivers/bus/vmbus/unix/vmbus_unix.h     |   4 ++
 drivers/bus/vmbus/unix/vmbus_unix_uio.c |   6 +-
 4 files changed, 130 insertions(+), 1 deletion(-)
 create mode 100644 drivers/bus/vmbus/freebsd/vmbus_uio.c

diff --git a/drivers/bus/vmbus/freebsd/vmbus_uio.c b/drivers/bus/vmbus/freebsd/vmbus_uio.c
new file mode 100644
index 0000000..0544371
--- /dev/null
+++ b/drivers/bus/vmbus/freebsd/vmbus_uio.c
@@ -0,0 +1,105 @@
+/* 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 <sys/types.h>
+#include <sys/sysctl.h>
+#include <sys/ioctl.h>
+
+#include <rte_log.h>
+#include <rte_bus.h>
+#include <rte_malloc.h>
+#include <rte_bus_vmbus.h>
+
+#include "private.h"
+#include "vmbus_unix.h"
+
+const char *driver_name = "hv_uio";
+
+/* Check map names with kernel names */
+static const char *map_names[VMBUS_MAX_RESOURCE] = {
+	[HV_TXRX_RING_MAP] = "txrx_rings",
+	[HV_INT_PAGE_MAP]  = "int_page",
+	[HV_MON_PAGE_MAP]  = "monitor_page",
+	[HV_RECV_BUF_MAP]  = "recv_buf",
+	[HV_SEND_BUF_MAP]  = "send_buf",
+};
+
+static int
+sysctl_get_vmbus_device_info(struct rte_vmbus_device *dev)
+{
+	char sysctl_buf[PATH_MAX];
+	char sysctl_var[PATH_MAX];
+	size_t len = PATH_MAX, sysctl_len;
+	unsigned long tmp;
+	int i;
+
+	snprintf(sysctl_buf, len, "dev.%s.%d", driver_name, dev->uio_num);
+
+	sysctl_len = sizeof(unsigned long);
+	/* get relid */
+	snprintf(sysctl_var, len, "%s.channel.ch_id", sysctl_buf);
+	if (sysctlbyname(sysctl_var, &tmp, &sysctl_len, NULL, 0) < 0) {
+		VMBUS_LOG(ERR, "could not read %s", sysctl_var);
+		goto error;
+	}
+	dev->relid = tmp;
+
+	/* get monitor id */
+	snprintf(sysctl_var, len, "%s.channel.%u.monitor_id", sysctl_buf,
+		 dev->relid);
+	if (sysctlbyname(sysctl_var, &tmp, &sysctl_len, NULL, 0) < 0) {
+		VMBUS_LOG(ERR, "could not read %s", sysctl_var);
+		goto error;
+	}
+	dev->monitor_id = tmp;
+
+	/* Extract resource value */
+	for (i = 0; i < VMBUS_MAX_RESOURCE; i++) {
+		struct rte_mem_resource *res = &dev->resource[i];
+		unsigned long size, gpad = 0;
+		size_t sizelen = sizeof(len);
+
+		snprintf(sysctl_var, sizeof(sysctl_var), "%s.%s.size",
+			 sysctl_buf, map_names[i]);
+		if (sysctlbyname(sysctl_var, &size, &sizelen, NULL, 0) < 0) {
+			VMBUS_LOG(ERR,
+				"could not read %s", sysctl_var);
+			goto error;
+		}
+		res->len = size;
+
+		if (i == HV_RECV_BUF_MAP || i == HV_SEND_BUF_MAP) {
+			snprintf(sysctl_var, sizeof(sysctl_var), "%s.%s.gpadl",
+				 sysctl_buf, map_names[i]);
+			if (sysctlbyname(sysctl_var, &gpad, &sizelen, NULL, 0) < 0) {
+				VMBUS_LOG(ERR,
+					"could not read %s", sysctl_var);
+				goto error;
+			}
+			/* put the GPAD value in physical address */
+			res->phys_addr = gpad;
+		}
+	}
+	return 0;
+error:
+	return -1;
+}
+
+/*
+ * On FreeBSD, the device is opened first to ensure kernel UIO driver
+ * is properly initialized before reading device attributes
+ */
+int vmbus_get_device_info_os(struct rte_vmbus_device *dev)
+{
+	return sysctl_get_vmbus_device_info(dev);
+}
+
+const char *get_devname_os(void)
+{
+	return "/dev/hv_uio";
+}
diff --git a/drivers/bus/vmbus/linux/vmbus_uio.c b/drivers/bus/vmbus/linux/vmbus_uio.c
index b5d15c9..69f0b26 100644
--- a/drivers/bus/vmbus/linux/vmbus_uio.c
+++ b/drivers/bus/vmbus/linux/vmbus_uio.c
@@ -199,3 +199,19 @@ int vmbus_uio_get_subchan(struct vmbus_channel *primary,
 	closedir(chan_dir);
 	return err;
 }
+
+/*
+ * In Linux the device info is fetched from SYSFS and doesn't need
+ * opening of the device before reading its attributes
+ * This is a stub function and it should always succeed.
+ */
+int vmbus_get_device_info_os(struct rte_vmbus_device *dev)
+{
+	RTE_SET_USED(dev);
+	return 0;
+}
+
+const char *get_devname_os(void)
+{
+	return "/dev/uio";
+}
diff --git a/drivers/bus/vmbus/unix/vmbus_unix.h b/drivers/bus/vmbus/unix/vmbus_unix.h
index 579c4bb..59afc10 100644
--- a/drivers/bus/vmbus/unix/vmbus_unix.h
+++ b/drivers/bus/vmbus/unix/vmbus_unix.h
@@ -20,4 +20,8 @@ int vmbus_uio_map_subchan_os(const struct rte_vmbus_device *dev,
 bool vmbus_isnew_subchannel(struct vmbus_channel *primary,
 			    unsigned long id);
 
+int vmbus_get_device_info_os(struct rte_vmbus_device *dev);
+
+const char *get_devname_os(void);
+
 #endif /* _VMBUS_BUS_UNIX_H_ */
diff --git a/drivers/bus/vmbus/unix/vmbus_unix_uio.c b/drivers/bus/vmbus/unix/vmbus_unix_uio.c
index c5ce8ca..5a57a5e 100644
--- a/drivers/bus/vmbus/unix/vmbus_unix_uio.c
+++ b/drivers/bus/vmbus/unix/vmbus_unix_uio.c
@@ -82,7 +82,8 @@ int vmbus_uio_irq_read(struct rte_vmbus_device *dev)
 	int fd;
 
 	/* save fd if in primary process */
-	snprintf(devname, sizeof(devname), "/dev/uio%u", dev->uio_num);
+	snprintf(devname, sizeof(devname), "%s%u", get_devname_os(),
+		 dev->uio_num);
 	fd = open(devname, O_RDWR);
 	if (fd < 0) {
 		VMBUS_LOG(ERR, "Cannot open %s: %s",
@@ -106,6 +107,9 @@ int vmbus_uio_irq_read(struct rte_vmbus_device *dev)
 	strlcpy((*uio_res)->path, devname, PATH_MAX);
 	rte_uuid_copy((*uio_res)->id, dev->device_id);
 
+	if (vmbus_get_device_info_os(dev) < 0)
+		goto error;
+
 	return 0;
 
 error:
-- 
1.8.3.1


  parent reply	other threads:[~2022-04-26  8:33 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       ` [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         ` Srikanth Kaka [this message]
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=20220423042849.7718-7-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).