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 04/14] bus/vmbus: scan and get the network device on FreeBSD
Date: Sat, 23 Apr 2022 09:58:39 +0530 [thread overview]
Message-ID: <20220423042849.7718-5-srikanth.k@oneconvergence.com> (raw)
In-Reply-To: <20220423042849.7718-1-srikanth.k@oneconvergence.com>
Using sysctl, all the devices on the VMBUS are identified by the PMD.
On finding the Network device's device id, it is added to VMBUS dev
list.
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_bus.c | 268 ++++++++++++++++++++++++++++++++++
1 file changed, 268 insertions(+)
create mode 100644 drivers/bus/vmbus/freebsd/vmbus_bus.c
diff --git a/drivers/bus/vmbus/freebsd/vmbus_bus.c b/drivers/bus/vmbus/freebsd/vmbus_bus.c
new file mode 100644
index 0000000..c1a3a5f
--- /dev/null
+++ b/drivers/bus/vmbus/freebsd/vmbus_bus.c
@@ -0,0 +1,268 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2018, Microsoft Corporation.
+ * All Rights Reserved.
+ */
+
+#include <rte_eal.h>
+#include <rte_bus_vmbus.h>
+
+#include "private.h"
+#include "vmbus_unix.h"
+
+#include <sys/bus.h>
+#include <sys/types.h>
+#include <sys/sysctl.h>
+
+/* Parse UUID. Caller must pass NULL terminated string */
+static int
+parse_sysfs_uuid(const char *filename, rte_uuid_t uu)
+{
+ char in[BUFSIZ];
+
+ memcpy(in, filename, BUFSIZ);
+ if (rte_uuid_parse(in, uu) < 0) {
+ VMBUS_LOG(ERR, "%s not a valid UUID", in);
+ return -1;
+ }
+
+ return 0;
+}
+
+/* Scan one vmbus entry, and fill the devices list from it. */
+static int
+vmbus_scan_one(const char *name, unsigned int unit_num)
+{
+ struct rte_vmbus_device *dev, *dev2;
+ char sysctl_buf[PATH_MAX], sysctl_var[PATH_MAX];
+ size_t guid_len = 36, len = PATH_MAX;
+ char classid[guid_len + 1], deviceid[guid_len + 1];
+
+ dev = calloc(1, sizeof(*dev));
+ if (dev == NULL)
+ return -1;
+
+ /* get class id and device id */
+ snprintf(sysctl_var, len, "dev.%s.%u.%%pnpinfo", name, unit_num);
+ if (sysctlbyname(sysctl_var, &sysctl_buf, &len, NULL, 0) < 0)
+ goto error;
+
+ /* pnpinfo: classid=f912ad6d-2b17-48ea-bd65-f927a61c7684
+ * deviceid=d34b2567-b9b6-42b9-8778-0a4ec0b955bf
+ */
+ if (sysctl_buf[0] == 'c' && sysctl_buf[1] == 'l' &&
+ sysctl_buf[7] == '=') {
+ memcpy(classid, &sysctl_buf[8], guid_len);
+ classid[guid_len] = '\0';
+ }
+ if (parse_sysfs_uuid(classid, dev->class_id) < 0)
+ goto error;
+
+ /* skip non-network devices */
+ if (rte_uuid_compare(dev->class_id, vmbus_nic_uuid) != 0) {
+ free(dev);
+ return 0;
+ }
+
+ if (sysctl_buf[45] == 'd' && sysctl_buf[46] == 'e' &&
+ sysctl_buf[47] == 'v' && sysctl_buf[53] == '=') {
+ memcpy(deviceid, &sysctl_buf[54], guid_len);
+ deviceid[guid_len] = '\0';
+ }
+ if (parse_sysfs_uuid(deviceid, dev->device_id) < 0)
+ goto error;
+
+ if (!strcmp(name, "hv_uio"))
+ dev->uio_num = unit_num;
+ else
+ dev->uio_num = -1;
+ dev->device.bus = &rte_vmbus_bus.bus;
+ dev->device.numa_node = 0;
+ dev->device.name = strdup(deviceid);
+ if (!dev->device.name)
+ goto error;
+
+ dev->device.devargs = vmbus_devargs_lookup(dev);
+
+ dev->intr_handle = rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_PRIVATE);
+ if (dev->intr_handle == NULL)
+ goto error;
+
+ /* device is valid, add in list (sorted) */
+ VMBUS_LOG(DEBUG, "Adding vmbus device %s", name);
+
+ TAILQ_FOREACH(dev2, &rte_vmbus_bus.device_list, next) {
+ int ret;
+
+ ret = rte_uuid_compare(dev->device_id, dev2->device_id);
+ if (ret > 0)
+ continue;
+
+ if (ret < 0) {
+ vmbus_insert_device(dev2, dev);
+ } else { /* already registered */
+ VMBUS_LOG(NOTICE,
+ "%s already registered", name);
+ free(dev);
+ }
+ return 0;
+ }
+
+ vmbus_add_device(dev);
+ return 0;
+error:
+ VMBUS_LOG(DEBUG, "failed");
+
+ free(dev);
+ return -1;
+}
+
+static int
+vmbus_unpack(char *walker, char *ep, char **str)
+{
+ int ret = 0;
+
+ *str = strdup(walker);
+ if (*str == NULL) {
+ ret = -ENOMEM;
+ goto exit;
+ }
+
+ if (walker + strnlen(walker, ep - walker) >= ep) {
+ ret = -EINVAL;
+ goto exit;
+ }
+exit:
+ return ret;
+}
+
+/*
+ * Scan the content of the vmbus, and the devices in the devices list
+ */
+int
+rte_vmbus_scan(void)
+{
+ struct u_device udev;
+ struct u_businfo ubus;
+ int dev_idx, dev_ptr, name2oid[2], oid[CTL_MAXNAME + 12], error;
+ size_t oidlen, rlen, ub_size;
+ uintptr_t vmbus_handle = 0;
+ char *walker, *ep;
+ char name[16] = "hw.bus.devices";
+ char *dd_name, *dd_desc, *dd_drivername, *dd_pnpinfo, *dd_location;
+
+ /*
+ * devinfo FreeBSD APP logic to fetch all the VMBus devices
+ * using SYSCTLs
+ */
+ name2oid[0] = 0;
+ name2oid[1] = 3;
+ oidlen = sizeof(oid);
+ error = sysctl(name2oid, 2, oid, &oidlen, name, strlen(name));
+ if (error < 0) {
+ VMBUS_LOG(DEBUG, "can't find hw.bus.devices sysctl node");
+ return -ENOENT;
+ }
+ oidlen /= sizeof(int);
+ if (oidlen > CTL_MAXNAME) {
+ VMBUS_LOG(DEBUG, "hw.bus.devices oid is too large");
+ return -EINVAL;
+ }
+
+ ub_size = sizeof(ubus);
+ if (sysctlbyname("hw.bus.info", &ubus, &ub_size, NULL, 0) != 0) {
+ VMBUS_LOG(DEBUG, "sysctlbyname(\"hw.bus.info\", ...) failed");
+ return -EINVAL;
+ }
+ if ((ub_size != sizeof(ubus)) ||
+ (ubus.ub_version != BUS_USER_VERSION)) {
+ VMBUS_LOG(DEBUG,
+ "kernel bus interface version mismatch: kernel %d expected %d",
+ ubus.ub_version, BUS_USER_VERSION);
+ return -EINVAL;
+ }
+
+ oid[oidlen++] = ubus.ub_generation;
+ dev_ptr = oidlen++;
+
+ /*
+ * Scan devices.
+ *
+ * Stop after a fairly insane number to avoid death in the case
+ * of kernel corruption.
+ */
+
+ for (dev_idx = 0; dev_idx < 10000; dev_idx++) {
+ /*
+ * Get the device information.
+ */
+ oid[dev_ptr] = dev_idx;
+ rlen = sizeof(udev);
+ error = sysctl(oid, oidlen, &udev, &rlen, NULL, 0);
+ if (error < 0) {
+ if (errno == ENOENT) /* end of list */
+ break;
+ if (errno != EINVAL) /* gen count skip, restart */
+ VMBUS_LOG(DEBUG, "sysctl hw.bus.devices.%d",
+ dev_idx);
+ return errno;
+ }
+ if (rlen != sizeof(udev)) {
+ VMBUS_LOG(DEBUG,
+ "sysctl returned wrong data %zd bytes instead of %zd",
+ rlen, sizeof(udev));
+ return -EINVAL;
+ }
+
+ walker = udev.dv_fields;
+ ep = walker + sizeof(udev.dv_fields);
+ dd_name = NULL;
+ dd_desc = NULL;
+ dd_drivername = NULL;
+ dd_pnpinfo = NULL;
+ dd_location = NULL;
+
+ error = vmbus_unpack(walker, ep, &dd_name);
+ if (error < 0)
+ return error;
+ walker += strlen(walker) + 1;
+
+ error = vmbus_unpack(walker, ep, &dd_desc);
+ if (error < 0)
+ return error;
+ walker += strlen(walker) + 1;
+
+ error = vmbus_unpack(walker, ep, &dd_drivername);
+ if (error < 0)
+ return error;
+ walker += strlen(walker) + 1;
+
+ error = vmbus_unpack(walker, ep, &dd_pnpinfo);
+ if (error < 0)
+ return error;
+ walker += strlen(walker) + 1;
+
+ error = vmbus_unpack(walker, ep, &dd_location);
+ if (error < 0)
+ return error;
+
+ if (*dd_drivername && !(strcmp(dd_drivername, "vmbus")))
+ vmbus_handle = udev.dv_handle;
+
+ if (vmbus_handle && (vmbus_handle == udev.dv_parent)
+ && *dd_pnpinfo && *dd_name) {
+ unsigned int driver_len = 0, unit_num = 0;
+ char *endptr;
+
+ driver_len = strlen(dd_drivername);
+ unit_num = strtoull(&dd_name[driver_len], &endptr, 10);
+ VMBUS_LOG(DEBUG, "Device name:%s, pnpinfo:%s",
+ dd_name, dd_pnpinfo);
+
+ if (vmbus_scan_one(dd_drivername, unit_num) < 0)
+ goto error;
+ }
+ }
+ return 0;
+error:
+ return -1;
+}
--
1.8.3.1
next prev 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 ` Srikanth Kaka [this message]
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=20220423042849.7718-5-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).