From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 47FE4A034E; Thu, 17 Feb 2022 17:11:13 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4843341156; Thu, 17 Feb 2022 17:10:55 +0100 (CET) Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by mails.dpdk.org (Postfix) with ESMTP id D4B1E40042 for ; Thu, 17 Feb 2022 17:06:36 +0100 (CET) Received: by mail-pg1-f193.google.com with SMTP id 27so190636pgk.10 for ; Thu, 17 Feb 2022 08:06:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oneconvergence.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7q4EcEPfPFHXHyGwieieMaE8V3ISeueyo0wKNLs5dtY=; b=DAaJcp7+vFxD7TNjeY5wANUwooE/wL0oCfOZ/+C8kg/oeh4o8JL/Rpzm1HsGDqZsOs fIEc1nzzsE37ec5fOC/YI9Bb2it2Q9oe3WgqoZS1dBUuZBk3ureeCDUnpKuBzUvfHIf7 m60WtV1KitpImzAXfX0vP4/KKGJnXf4ucArRw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7q4EcEPfPFHXHyGwieieMaE8V3ISeueyo0wKNLs5dtY=; b=bhIbPZ+6TXXkj60xT36dUVy0XMZk/KQUnWcfwiTMEbO0x6erRXo+ipjb/Gpo8PZfIw gEw2XTpyaRQmpSbEh6VnrjmSNTtAQ+1tLKmSGt1XTHtZS/o4hnbldRK67sTT8/Jmu0Uo kUn44Gzx31hGx/A9LNtzP32jY5kpuciQ65ccVD1Nw4ZL3NGRKQTq+aLptIjbBArRr9ad EvLGI/KECWX72eEM+cJOifTp2cQJl6TsRf4/bm5/1CMA1IeKquWY2cWSMgVSAPJJxC9w NRgeQhIR5zYnb5gf0kDtkY0bYHfWJsw9n04fJ6LtCMBUOCG/Rr1+Z0FIQharkU3WU+vR L2ug== X-Gm-Message-State: AOAM532orTgS7Bd5IJ7amlAWrY/vNXMoAJTlz2JqMbke/plZDRVvkxfE nzA1HNYvfmRZM8XxIC4GxCrXbw== X-Google-Smtp-Source: ABdhPJxzclGMCcoIm6x0gzaFSyHGewioN+BxQWk07rk68Q5e5mDfqGIxFZ8YP+ZgWoFhiT73ssnM7w== X-Received: by 2002:a63:ff01:0:b0:34a:d500:c77a with SMTP id k1-20020a63ff01000000b0034ad500c77amr2900093pgi.320.1645113995992; Thu, 17 Feb 2022 08:06:35 -0800 (PST) Received: from srikanth-ThinkPad-T450.. ([49.37.144.122]) by smtp.gmail.com with ESMTPSA id z14sm47807pfh.173.2022.02.17.08.06.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 08:06:35 -0800 (PST) From: Srikanth Kaka To: sthemmin@microsoft.com, longli@microsoft.com Cc: dev@dpdk.org, vag.singh@oneconvergence.com, avelu@juniper.net, Srikanth Kaka Subject: [PATCH v3 03/15] bus/vmbus: get device resource values using sysctl Date: Thu, 17 Feb 2022 21:36:01 +0530 Message-Id: <20220217160613.70161-4-srikanth.k@oneconvergence.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220217160613.70161-1-srikanth.k@oneconvergence.com> References: <20210927134231.11177-1-srikanth.k@oneconvergence.com> <20220217160613.70161-1-srikanth.k@oneconvergence.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Thu, 17 Feb 2022 17:10:51 +0100 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The UIO device's 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 Signed-off-by: Vag Singh Signed-off-by: Anand Thulasiram --- drivers/bus/vmbus/freebsd/vmbus_uio.c | 142 ++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) 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 0000000000..2059ab192b --- /dev/null +++ b/drivers/bus/vmbus/freebsd/vmbus_uio.c @@ -0,0 +1,142 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2018, Microsoft Corporation. + * All Rights Reserved. + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "private.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", +}; + +void +vmbus_uio_free_resource(struct rte_vmbus_device *dev, + struct mapped_vmbus_resource *uio_res) +{ + rte_free(uio_res); + + if (dev->intr_handle.uio_cfg_fd >= 0) { + close(dev->intr_handle.uio_cfg_fd); + dev->intr_handle.uio_cfg_fd = -1; + } + + if (dev->intr_handle.fd >= 0) { + close(dev->intr_handle.fd); + dev->intr_handle.fd = -1; + dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN; + } +} + +static int +sysctl_get_vmbus_device_info(struct rte_vmbus_device *dev) +{ + char sysctlBuffer[PATH_MAX]; + char sysctlVar[PATH_MAX]; + size_t len = PATH_MAX, sysctl_len; + unsigned long tmp; + int i; + + snprintf(sysctlBuffer, len, "dev.%s.%d", driver_name, dev->uio_num); + + sysctl_len = sizeof(unsigned long); + /* get relid */ + snprintf(sysctlVar, len, "%s.channel.ch_id", sysctlBuffer); + if (sysctlbyname(sysctlVar, &tmp, &sysctl_len, NULL, 0) < 0) { + VMBUS_LOG(ERR, "could not read %s", sysctlVar); + goto error; + } + dev->relid = tmp; + + /* get monitor id */ + snprintf(sysctlVar, len, "%s.channel.%u.monitor_id", sysctlBuffer, + dev->relid); + if (sysctlbyname(sysctlVar, &tmp, &sysctl_len, NULL, 0) < 0) { + VMBUS_LOG(ERR, "could not read %s", sysctlVar); + 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(sysctlVar, sizeof(sysctlVar), "%s.%s.size", + sysctlBuffer, map_names[i]); + if (sysctlbyname(sysctlVar, &size, &sizelen, NULL, 0) < 0) { + VMBUS_LOG(ERR, + "could not read %s", sysctlVar); + goto error; + } + res->len = size; + + if (i == HV_RECV_BUF_MAP || i == HV_SEND_BUF_MAP) { + snprintf(sysctlVar, sizeof(sysctlVar), "%s.%s.gpadl", + sysctlBuffer, map_names[i]); + if (sysctlbyname(sysctlVar, &gpad, &sizelen, NULL, 0) < 0) { + VMBUS_LOG(ERR, + "could not read %s", sysctlVar); + goto error; + } + /* put the GPAD value in physical address */ + res->phys_addr = gpad; + } + } + return 0; +error: + return -1; +} + +int +vmbus_uio_alloc_resource(struct rte_vmbus_device *dev, + struct mapped_vmbus_resource **uio_res) +{ + char devname[PATH_MAX]; /* contains the /dev/hv_uioX */ + + /* save fd if in primary process */ + snprintf(devname, sizeof(devname), "/dev/hv_uio%u", dev->uio_num); + dev->intr_handle.fd = open(devname, O_RDWR); + if (dev->intr_handle.fd < 0) { + VMBUS_LOG(ERR, "Cannot open %s: %s", + devname, strerror(errno)); + goto error; + } + dev->intr_handle.type = RTE_INTR_HANDLE_UIO_INTX; + + /* 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); + + if (sysctl_get_vmbus_device_info(dev) < 0) + goto error; + + return 0; +error: + vmbus_uio_free_resource(dev, *uio_res); + return -1; +} -- 2.30.2