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 24DB0A00C4; Tue, 26 Apr 2022 10:33:34 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 245FD42818; Tue, 26 Apr 2022 10:32:45 +0200 (CEST) Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by mails.dpdk.org (Postfix) with ESMTP id 5558740E09 for ; Sat, 23 Apr 2022 06:30:05 +0200 (CEST) Received: by mail-pl1-f193.google.com with SMTP id s14so15051146plk.8 for ; Fri, 22 Apr 2022 21:30:05 -0700 (PDT) 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=zTa18xyTYiPFfeU/TSe3fPXTKrS//TcwiQvqQibUXSY=; b=PnD1E0eptjASS/co4e3igpKu/JeBP6Q3i/pIcpb2/ZGw24u1A7Zl+T62AatI91YR1+ nr8VBofKJLvFWGJLATnkPmAvwdW63Fn2mlBaIj1i75ESJtjjgXRrZnzilxoDEsgwt1vF uk0TpArOq9pOVowpdg9LoyxI9e4b1S6LhZ/l8= 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=zTa18xyTYiPFfeU/TSe3fPXTKrS//TcwiQvqQibUXSY=; b=oNKu1+VJKkREwezzPxvxXD8wH5iAonb+aUC/8yOxzuSRho3slEQnrEClQnUX7gMaId rqdJ0xl8hAiatjxTg33njW8eD0dkjITCKZypIQkJSmuW0ymU+VjPC4AhFvV7P9wpCO4g vVmFMzTxXJZM+39scz+evaVMMu64f8/XpU2XypXnks2eDD8jc8pKGXmiQCjSxiEXkWVW ye3FMqW3BIPyx3Qg1hscVsHEQ/vjO8DKoQ1se36F+OKUvU3U2OHMjpV2yhAn/qDJPTk6 KMnw6esu1TvlzQeZQV6M0VDPGeTL57dxlMZao7ZV61OBIKwF36309YVvCnh4OnbLTzfe Wn+Q== X-Gm-Message-State: AOAM533U1uwqcCZQz5EttkWedgSL+UvOlAF9HZ9Z3nMSvmx3QVfDx8hN /zLoe3LqID3ka4EuG8VGMYIYGQ== X-Google-Smtp-Source: ABdhPJzuFtOrVVdICzkcRyu+zopuP9yYfs3lg1kB9mLy2lbVzH6PVoPrQaGMTLDR1VnHRLJW8qjlaw== X-Received: by 2002:a17:90b:3945:b0:1d2:9347:7fb8 with SMTP id oe5-20020a17090b394500b001d293477fb8mr9152952pjb.0.1650688204589; Fri, 22 Apr 2022 21:30:04 -0700 (PDT) Received: from home-desktop.localdomain ([49.37.158.191]) by smtp.gmail.com with ESMTPSA id g6-20020a17090a714600b001d7f3bb11d7sm4056438pjs.53.2022.04.22.21.30.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 21:30:03 -0700 (PDT) From: Srikanth Kaka To: Stephen Hemminger , Long Li Cc: dev@dpdk.org, Vag Singh , Anand Thulasiram , Srikanth Kaka Subject: [PATCH v5 06/14] bus/vmbus: get device resource values using sysctl Date: Sat, 23 Apr 2022 09:58:41 +0530 Message-Id: <20220423042849.7718-7-srikanth.k@oneconvergence.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220423042849.7718-1-srikanth.k@oneconvergence.com> References: <20220418042915.5765-1-srikanth.k@oneconvergence.com> <20220423042849.7718-1-srikanth.k@oneconvergence.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Tue, 26 Apr 2022 10:32:34 +0200 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 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 Signed-off-by: Vag Singh Signed-off-by: Anand Thulasiram --- 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 +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#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