get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/99819/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 99819,
    "url": "https://patches.dpdk.org/api/patches/99819/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/20210927134231.11177-3-srikanth.k@oneconvergence.com/",
    "project": {
        "id": 1,
        "url": "https://patches.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<20210927134231.11177-3-srikanth.k@oneconvergence.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20210927134231.11177-3-srikanth.k@oneconvergence.com",
    "date": "2021-09-27T13:42:22",
    "name": "[02/11] bus/vmbus: scan and get the network device",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "afc4a8bf5fbcda8cb490a972c89c7c2e359566cb",
    "submitter": {
        "id": 2368,
        "url": "https://patches.dpdk.org/api/people/2368/?format=api",
        "name": "Srikanth Kaka",
        "email": "srikanth.k@oneconvergence.com"
    },
    "delegate": {
        "id": 1,
        "url": "https://patches.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/20210927134231.11177-3-srikanth.k@oneconvergence.com/mbox/",
    "series": [
        {
            "id": 19194,
            "url": "https://patches.dpdk.org/api/series/19194/?format=api",
            "web_url": "https://patches.dpdk.org/project/dpdk/list/?series=19194",
            "date": "2021-09-27T13:42:20",
            "name": "add FreeBSD support to VMBUS & NetVSC PMDs",
            "version": 1,
            "mbox": "https://patches.dpdk.org/series/19194/mbox/"
        }
    ],
    "comments": "https://patches.dpdk.org/api/patches/99819/comments/",
    "check": "warning",
    "checks": "https://patches.dpdk.org/api/patches/99819/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@inbox.dpdk.org",
        "Delivered-To": "patchwork@inbox.dpdk.org",
        "Received": [
            "from mails.dpdk.org (mails.dpdk.org [217.70.189.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id C06A2A0C46;\n\tMon, 27 Sep 2021 17:00:41 +0200 (CEST)",
            "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 91FDA4118B;\n\tMon, 27 Sep 2021 16:58:32 +0200 (CEST)",
            "from mail-pl1-f172.google.com (mail-pl1-f172.google.com\n [209.85.214.172])\n by mails.dpdk.org (Postfix) with ESMTP id 0A3DF40E3C\n for <dev@dpdk.org>; Mon, 27 Sep 2021 15:43:05 +0200 (CEST)",
            "by mail-pl1-f172.google.com with SMTP id j15so10382771plh.7\n for <dev@dpdk.org>; Mon, 27 Sep 2021 06:43:04 -0700 (PDT)",
            "from srikanth-ThinkPad-T450.domain.name ([223.178.22.200])\n by smtp.gmail.com with ESMTPSA id b3sm16960665pfo.23.2021.09.27.06.43.01\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Mon, 27 Sep 2021 06:43:03 -0700 (PDT)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=oneconvergence.com; s=google;\n h=from:to:cc:subject:date:message-id:in-reply-to:references\n :mime-version:content-transfer-encoding;\n bh=g+TV0cKT7Na0B4z9tOAoOFjxNzWuMF94m/xPrFGaCYU=;\n b=EB0bq80CTOIniufFJkdu+l/BeoZ8/esTkS9iQ87jySj/MUtWKA96Ue5oXMoBhIBcbE\n wKr2iWwgLjS0gkal5o1fORDJ9vP16WrDvurJ2WaR1yTgaP7OE6OaHQT+mrjZGqdX9hyE\n o7iIKCa4kB2wPft24J9yH+xaY6itEEqP9i0fc=",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20210112;\n h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n :references:mime-version:content-transfer-encoding;\n bh=g+TV0cKT7Na0B4z9tOAoOFjxNzWuMF94m/xPrFGaCYU=;\n b=JQCX3hX7jA55uD6y2+F9kpJYMsp2MfI2uLAzkn6KOqwU2T09VSTBYneB/qNSwhLtAr\n Pi4K2fuQ5xbsF1V/WSg6AVexo9xZOVN+X0LrY+IPus5Lu3SOHpoecGuCjqKdJKCrSrOX\n bAjihKzuQc3GGMNkdK5Ehd4aeSTZmNwOwDm17Xrf0JQAwsoY4Z7mx6znf5cTymbBqiW0\n NNYDBB7n29SBgH5fDaMNLWydZfuyOgo72myozeROcY9dTTQkUHq0LZDjYhMleqXY1ggs\n WuiYIQgN7f2aFq0iqagcjuxD7CEQs7axIXFm/F3lYjgOSdNfamzCM/VNCaRca6+tO37b\n A+8A==",
        "X-Gm-Message-State": "AOAM530WLN6aWdIYDPJLcAauqmmqXmOaPESM2NZ3KKh1OFfNWTJjQJqk\n x9C19bRHphsv8sNioY7F6EFF/Q==",
        "X-Google-Smtp-Source": "\n ABdhPJyICNyi+C5LSHtpxTK+Vy14tEVeZT1s17hVzqGYp7DOslkKGGQ4TuaybgcGZ9qkalzDToQJLw==",
        "X-Received": "by 2002:a17:902:8509:b0:13d:cef8:2735 with SMTP id\n bj9-20020a170902850900b0013dcef82735mr22770772plb.22.1632750184124;\n Mon, 27 Sep 2021 06:43:04 -0700 (PDT)",
        "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>,\n Anand Thulasiram <avelu@juniper.net>,\n Srikanth Kaka <srikanth.k@oneconvergence.com>",
        "Date": "Mon, 27 Sep 2021 19:12:22 +0530",
        "Message-Id": "<20210927134231.11177-3-srikanth.k@oneconvergence.com>",
        "X-Mailer": "git-send-email 2.30.2",
        "In-Reply-To": "<20210927134231.11177-1-srikanth.k@oneconvergence.com>",
        "References": "<20210927134231.11177-1-srikanth.k@oneconvergence.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "X-Mailman-Approved-At": "Mon, 27 Sep 2021 16:58:07 +0200",
        "Subject": "[dpdk-dev] [PATCH 02/11] bus/vmbus: scan and get the network device",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "Using sysctl, all the devices on the VMBUS are identified by the PMD.\nOn finding the Network device's device id, it is added to VMBUS dev\nlist.\n\nSigned-off-by: Srikanth Kaka <srikanth.k@oneconvergence.com>\nSigned-off-by: Vag Singh <vag.singh@oneconvergence.com>\nSigned-off-by: Anand Thulasiram <avelu@juniper.net>\n---\n drivers/bus/vmbus/freebsd/vmbus_bus.c | 241 +++++++++++++++-----------\n 1 file changed, 144 insertions(+), 97 deletions(-)",
    "diff": "diff --git a/drivers/bus/vmbus/freebsd/vmbus_bus.c b/drivers/bus/vmbus/freebsd/vmbus_bus.c\nindex 3c924eee14..8eb428a154 100644\n--- a/drivers/bus/vmbus/freebsd/vmbus_bus.c\n+++ b/drivers/bus/vmbus/freebsd/vmbus_bus.c\n@@ -22,8 +22,9 @@\n #include \"eal_filesystem.h\"\n #include \"private.h\"\n \n-/** Pathname of VMBUS devices directory. */\n-#define SYSFS_VMBUS_DEVICES \"/sys/bus/vmbus/devices\"\n+#include <sys/bus.h>\n+#include <sys/types.h>\n+#include <sys/sysctl.h>\n \n /*\n  * GUID associated with network devices\n@@ -39,44 +40,15 @@ static const rte_uuid_t vmbus_nic_uuid = {\n \n extern struct rte_vmbus_bus rte_vmbus_bus;\n \n-/* Read sysfs file to get UUID */\n+/* Parse UUID */\n static int\n parse_sysfs_uuid(const char *filename, rte_uuid_t uu)\n {\n-\tchar buf[BUFSIZ];\n-\tchar *cp, *in = buf;\n-\tFILE *f;\n-\n-\tf = fopen(filename, \"r\");\n-\tif (f == NULL) {\n-\t\tVMBUS_LOG(ERR, \"cannot open sysfs value %s: %s\",\n-\t\t\t  filename, strerror(errno));\n-\t\treturn -1;\n-\t}\n-\n-\tif (fgets(buf, sizeof(buf), f) == NULL) {\n-\t\tVMBUS_LOG(ERR, \"cannot read sysfs value %s\",\n-\t\t\t\tfilename);\n-\t\tfclose(f);\n-\t\treturn -1;\n-\t}\n-\tfclose(f);\n-\n-\tcp = strchr(buf, '\\n');\n-\tif (cp)\n-\t\t*cp = '\\0';\n-\n-\t/* strip { } notation */\n-\tif (buf[0] == '{') {\n-\t\tin = buf + 1;\n-\t\tcp = strchr(in, '}');\n-\t\tif (cp)\n-\t\t\t*cp = '\\0';\n-\t}\n+\tchar in[BUFSIZ];\n \n+\tstrncpy(in, filename, BUFSIZ);\n \tif (rte_uuid_parse(in, uu) < 0) {\n-\t\tVMBUS_LOG(ERR, \"%s %s not a valid UUID\",\n-\t\t\tfilename, buf);\n+\t\tVMBUS_LOG(ERR, \"%s not a valid UUID\", in);\n \t\treturn -1;\n \t}\n \n@@ -228,35 +200,33 @@ rte_vmbus_unmap_device(struct rte_vmbus_device *dev)\n \tvmbus_uio_unmap_resource(dev);\n }\n \n-/* Scan one vmbus sysfs entry, and fill the devices list from it. */\n+/* Scan one vmbus entry, and fill the devices list from it. */\n static int\n-vmbus_scan_one(const char *name)\n+vmbus_scan_one(const char *name, unsigned int unit_num)\n {\n \tstruct rte_vmbus_device *dev, *dev2;\n-\tchar filename[PATH_MAX];\n-\tchar dirname[PATH_MAX];\n-\tunsigned long tmp;\n+\tchar sysctlBuffer[PATH_MAX], sysctlVar[PATH_MAX];\n+\tsize_t guid_len = 36, len = PATH_MAX;\n+\tchar classid[guid_len], deviceid[guid_len];\n \n \tdev = calloc(1, sizeof(*dev));\n \tif (dev == NULL)\n \t\treturn -1;\n \n-\tdev->device.bus = &rte_vmbus_bus.bus;\n-\tdev->device.name = strdup(name);\n-\tif (!dev->device.name)\n+\t/* get class id and device id */\n+\tsnprintf(sysctlVar, len, \"dev.%s.%u.%%pnpinfo\", name, unit_num);\n+\tif (sysctlbyname(sysctlVar, &sysctlBuffer, &len, NULL, 0) < 0)\n \t\tgoto error;\n \n-\t/* sysfs base directory\n-\t *   /sys/bus/vmbus/devices/7a08391f-f5a0-4ac0-9802-d13fd964f8df\n-\t * or on older kernel\n-\t *   /sys/bus/vmbus/devices/vmbus_1\n+\t/* pnpinfo: classid=f912ad6d-2b17-48ea-bd65-f927a61c7684\n+\t * deviceid=d34b2567-b9b6-42b9-8778-0a4ec0b955bf\n \t */\n-\tsnprintf(dirname, sizeof(dirname), \"%s/%s\",\n-\t\t SYSFS_VMBUS_DEVICES, name);\n-\n-\t/* get device class  */\n-\tsnprintf(filename, sizeof(filename), \"%s/class_id\", dirname);\n-\tif (parse_sysfs_uuid(filename, dev->class_id) < 0)\n+\tif (sysctlBuffer[0] == 'c' && sysctlBuffer[1] == 'l' &&\n+\t    sysctlBuffer[7] == '=') {\n+\t\tstrncpy(classid, &sysctlBuffer[8], guid_len);\n+\t\tclassid[guid_len] = '\\0';\n+\t}\n+\tif (parse_sysfs_uuid(classid, dev->class_id) < 0)\n \t\tgoto error;\n \n \t/* skip non-network devices */\n@@ -265,35 +235,23 @@ vmbus_scan_one(const char *name)\n \t\treturn 0;\n \t}\n \n-\t/* get device id */\n-\tsnprintf(filename, sizeof(filename), \"%s/device_id\", dirname);\n-\tif (parse_sysfs_uuid(filename, dev->device_id) < 0)\n-\t\tgoto error;\n-\n-\t/* get relid */\n-\tsnprintf(filename, sizeof(filename), \"%s/id\", dirname);\n-\tif (eal_parse_sysfs_value(filename, &tmp) < 0)\n+\tif (sysctlBuffer[45] == 'd' && sysctlBuffer[46] == 'e' &&\n+\t    sysctlBuffer[47] == 'v' && sysctlBuffer[53] == '=') {\n+\t\tstrncpy(deviceid, &sysctlBuffer[54], guid_len);\n+\t\tdeviceid[guid_len] = '\\0';\n+\t}\n+\tif (parse_sysfs_uuid(deviceid, dev->device_id) < 0)\n \t\tgoto error;\n-\tdev->relid = tmp;\n \n-\t/* get monitor id */\n-\tsnprintf(filename, sizeof(filename), \"%s/monitor_id\", dirname);\n-\tif (eal_parse_sysfs_value(filename, &tmp) < 0)\n+\tif (!strcmp(name, \"hv_uio\"))\n+\t\tdev->uio_num = unit_num;\n+\telse\n+\t\tdev->uio_num = -1;\n+\tdev->device.bus = &rte_vmbus_bus.bus;\n+\tdev->device.numa_node = 0;\n+\tdev->device.name = strdup(deviceid);\n+\tif (!dev->device.name)\n \t\tgoto error;\n-\tdev->monitor_id = tmp;\n-\n-\t/* get numa node (if present) */\n-\tsnprintf(filename, sizeof(filename), \"%s/numa_node\",\n-\t\t dirname);\n-\n-\tif (access(filename, R_OK) == 0) {\n-\t\tif (eal_parse_sysfs_value(filename, &tmp) < 0)\n-\t\t\tgoto error;\n-\t\tdev->device.numa_node = tmp;\n-\t} else {\n-\t\t/* if no NUMA support, set default to 0 */\n-\t\tdev->device.numa_node = SOCKET_ID_ANY;\n-\t}\n \n \tdev->device.devargs = vmbus_devargs_lookup(dev);\n \n@@ -332,31 +290,120 @@ vmbus_scan_one(const char *name)\n int\n rte_vmbus_scan(void)\n {\n-\tstruct dirent *e;\n-\tDIR *dir;\n-\n-\tdir = opendir(SYSFS_VMBUS_DEVICES);\n-\tif (dir == NULL) {\n-\t\tif (errno == ENOENT)\n-\t\t\treturn 0;\n+\tstruct u_device udev;\n+\tstruct u_businfo ubus;\n+\tint dev_idx, dev_ptr, name2oid[2], oid[CTL_MAXNAME + 12], error;\n+\tsize_t oidlen, rlen, ub_size;\n+\tuintptr_t vmbus_handle = 0;\n+\tchar *walker, *ep;\n+\tchar name[16] = \"hw.bus.devices\";\n+\tchar *dd_name, *dd_desc, *dd_drivername, *dd_pnpinfo, *dd_location;\n+\n+\t/*\n+\t * devinfo FreeBSD APP logic to fetch all the VMBus devices\n+\t * using SYSCTLs\n+\t */\n+\tname2oid[0] = 0;\n+\tname2oid[1] = 3;\n+\toidlen = sizeof(oid);\n+\terror = sysctl(name2oid, 2, oid, &oidlen, name, strlen(name));\n+\tif (error < 0) {\n+\t\tVMBUS_LOG(DEBUG, \"can't find hw.bus.devices sysctl node\");\n+\t\treturn -ENOENT;\n+\t}\n+\toidlen /= sizeof(int);\n+\tif (oidlen > CTL_MAXNAME) {\n+\t\tVMBUS_LOG(DEBUG, \"hw.bus.devices oid is too large\");\n+\t\treturn -EINVAL;\n+\t}\n \n-\t\tVMBUS_LOG(ERR, \"opendir %s failed: %s\",\n-\t\t\t  SYSFS_VMBUS_DEVICES, strerror(errno));\n-\t\treturn -1;\n+\tub_size = sizeof(ubus);\n+\tif (sysctlbyname(\"hw.bus.info\", &ubus, &ub_size, NULL, 0) != 0) {\n+\t\tVMBUS_LOG(DEBUG, \"sysctlbyname(\\\"hw.bus.info\\\", ...) failed\");\n+\t\treturn -EINVAL;\n+\t}\n+\tif ((ub_size != sizeof(ubus)) ||\n+\t    (ubus.ub_version != BUS_USER_VERSION)) {\n+\t\tVMBUS_LOG(DEBUG,\n+\t\t\t\"kernel bus interface version mismatch: kernel %d expected %d\",\n+\t\t\tubus.ub_version, BUS_USER_VERSION);\n+\t\treturn -EINVAL;\n \t}\n \n-\twhile ((e = readdir(dir)) != NULL) {\n-\t\tif (e->d_name[0] == '.')\n-\t\t\tcontinue;\n+\toid[oidlen++] = ubus.ub_generation;\n+\tdev_ptr = oidlen++;\n+\n+\t/*\n+\t * Scan devices.\n+\t *\n+\t * Stop after a fairly insane number to avoid death in the case\n+\t * of kernel corruption.\n+\t */\n+\n+\tfor (dev_idx = 0; dev_idx < 10000; dev_idx++) {\n+\t\t/*\n+\t\t * Get the device information.\n+\t\t */\n+\t\toid[dev_ptr] = dev_idx;\n+\t\trlen = sizeof(udev);\n+\t\terror = sysctl(oid, oidlen, &udev, &rlen, NULL, 0);\n+\t\tif (error < 0) {\n+\t\t\tif (errno == ENOENT)    /* end of list */\n+\t\t\t\tbreak;\n+\t\t\tif (errno != EINVAL)    /* gen count skip, restart */\n+\t\t\t\tVMBUS_LOG(DEBUG, \"sysctl hw.bus.devices.%d\",\n+\t\t\t\t\tdev_idx);\n+\t\t\treturn errno;\n+\t\t}\n+\t\tif (rlen != sizeof(udev)) {\n+\t\t\tVMBUS_LOG(DEBUG,\n+\t\t\t\t\"sysctl returned wrong data %zd bytes instead of %zd\",\n+\t\t\t\trlen, sizeof(udev));\n+\t\t\treturn -EINVAL;\n+\t\t}\n \n-\t\tif (vmbus_scan_one(e->d_name) < 0)\n-\t\t\tgoto error;\n+\t\twalker = udev.dv_fields;\n+\t\tep = walker + sizeof(udev.dv_fields);\n+\t\tdd_name = NULL;\n+\t\tdd_desc = NULL;\n+\t\tdd_drivername = NULL;\n+\t\tdd_pnpinfo = NULL;\n+\t\tdd_location = NULL;\n+#define UNPACK(x)\t\t\t\t\t\t \\\n+\tdo {\t\t\t\t\t\t\t \\\n+\t\tx = strdup(walker);\t\t\t\t \\\n+\t\tif (x == NULL)\t\t\t\t\t \\\n+\t\t\treturn -ENOMEM;\t\t\t\t \\\n+\t\tif (walker + strnlen(walker, ep - walker) >= ep) \\\n+\t\t\treturn -EINVAL;\t\t\t\t \\\n+\t\twalker += strlen(walker) + 1;\t\t\t \\\n+\t} while (0)\n+\n+\t\tUNPACK(dd_name);\n+\t\tUNPACK(dd_desc);\n+\t\tUNPACK(dd_drivername);\n+\t\tUNPACK(dd_pnpinfo);\n+\t\tUNPACK(dd_location);\n+#undef UNPACK\n+\t\tif (*dd_drivername && !(strcmp(dd_drivername, \"vmbus\")))\n+\t\t\tvmbus_handle = udev.dv_handle;\n+\n+\t\tif (vmbus_handle && (vmbus_handle == udev.dv_parent)\n+\t\t    && *dd_pnpinfo && *dd_name) {\n+\t\t\tunsigned int driver_len = 0, unit_num = 0;\n+\t\t\tchar *endptr;\n+\n+\t\t\tdriver_len = strlen(dd_drivername);\n+\t\t\tunit_num = strtoull(&dd_name[driver_len], &endptr, 10);\n+\t\t\tVMBUS_LOG(DEBUG, \"Device name:%s, pnpinfo:%s\",\n+\t\t\t\tdd_name, dd_pnpinfo);\n+\n+\t\t\tif (vmbus_scan_one(dd_drivername, unit_num) < 0)\n+\t\t\t\tgoto error;\n+\t\t}\n \t}\n-\tclosedir(dir);\n \treturn 0;\n-\n error:\n-\tclosedir(dir);\n \treturn -1;\n }\n \n",
    "prefixes": [
        "02/11"
    ]
}