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 E879FA0C46; Mon, 27 Sep 2021 17:00:57 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CD7BC41196; Mon, 27 Sep 2021 16:58:34 +0200 (CEST) Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by mails.dpdk.org (Postfix) with ESMTP id 291C6410DD for ; Mon, 27 Sep 2021 15:43:10 +0200 (CEST) Received: by mail-pl1-f178.google.com with SMTP id x8so8982333plv.8 for ; Mon, 27 Sep 2021 06:43:10 -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=lHGfUmAGv9M4RA1w8+Uve1rNW3LVrft/ZlIS+myyUWQ=; b=grd8h9MZoHfRoPhHuRfrAjDTDUOohU3eXLoiyvQJW7tjgHmZhyzRdFqLGcJcBUveFR gCoSf0gqI7MP+THcfVAP6rYaS63EhsfYJpwgwCFQKBC1t+O7Ohg+B4MkucJCn36eb0UH 3cwgMA0etHACqYhjLy+k+CyppOh7ECfQ4JIGI= 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=lHGfUmAGv9M4RA1w8+Uve1rNW3LVrft/ZlIS+myyUWQ=; b=ymulQie2LQSCPnN/4S1QZD2qK/5H+vdbT7H/BS9s2fVyVH2Ju6RWoXGVPCAC/o7Yqy Dq/nOUE1PIe/uJZf+Vk9dOOHs8m+yAALKW82EJVnEGw92zitdbdTTH7u+3ZcjVSkUU1b hgAELAhpm5hVBaECTNNs9RNC3iO+VYIrLAiNzWGdV9iTdreyJGn2HtRWne38Bo0WxNnF l5StZuUj156Zw8l5T/uVHLRgFzQf/AUjApehf2im15GbY/j6RMF/oByr3yiOo8jByhnu wferZu+MdQM/AsNwqZOcosLCEAPH1Lu8C5FUQfqTJHYu2OdCdua+VSkhjYfjazfzOyXH EniA== X-Gm-Message-State: AOAM532w4aQtlFItCWABDBrufypdqNG+QpVQnH8tTZuUi7UvMk2SjsmM VhrSTRH8IZwRNTsKD/2mFqLJ7w== X-Google-Smtp-Source: ABdhPJxGsHAaQdPtedkrt+r6aEmWG8zuB+tUl8ptmaTYL5ehm6J/IdC/D3m/NOFk7+wcZTfPYQ8kaQ== X-Received: by 2002:a17:90b:4b51:: with SMTP id mi17mr22335pjb.120.1632750189293; Mon, 27 Sep 2021 06:43:09 -0700 (PDT) Received: from srikanth-ThinkPad-T450.domain.name ([223.178.22.200]) by smtp.gmail.com with ESMTPSA id b3sm16960665pfo.23.2021.09.27.06.43.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Sep 2021 06:43:09 -0700 (PDT) From: Srikanth Kaka To: Stephen Hemminger , Long Li Cc: dev@dpdk.org, Vag Singh , Anand Thulasiram , Srikanth Kaka Date: Mon, 27 Sep 2021 19:12:24 +0530 Message-Id: <20210927134231.11177-5-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 04/11] bus/vmbus: get device resource values using sysctl 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 Sender: "dev" 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 | 98 ++++++++++++++++++++++----- 1 file changed, 81 insertions(+), 17 deletions(-) diff --git a/drivers/bus/vmbus/freebsd/vmbus_uio.c b/drivers/bus/vmbus/freebsd/vmbus_uio.c index b52ca5bf1d..fdd37dac3a 100644 --- a/drivers/bus/vmbus/freebsd/vmbus_uio.c +++ b/drivers/bus/vmbus/freebsd/vmbus_uio.c @@ -10,6 +10,8 @@ #include #include #include +#include +#include #include #include @@ -24,8 +26,18 @@ /** Pathname of VMBUS devices directory. */ #define SYSFS_VMBUS_DEVICES "/sys/bus/vmbus/devices" +const char *driver_name = "hv_uio"; static void *vmbus_map_addr; +/* 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", +}; + /* Control interrupts */ void vmbus_uio_irq_control(struct rte_vmbus_device *dev, int32_t onoff) { @@ -72,14 +84,75 @@ vmbus_uio_free_resource(struct rte_vmbus_device *dev, } } +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/uioX */ + char devname[PATH_MAX]; /* contains the /dev/hv_uioX */ /* save fd if in primary process */ - snprintf(devname, sizeof(devname), "/dev/uio%u", dev->uio_num); + 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", @@ -98,8 +171,10 @@ vmbus_uio_alloc_resource(struct rte_vmbus_device *dev, strlcpy((*uio_res)->path, devname, PATH_MAX); rte_uuid_copy((*uio_res)->id, dev->device_id); - return 0; + if (sysctl_get_vmbus_device_info(dev) < 0) + goto error; + return 0; error: vmbus_uio_free_resource(dev, *uio_res); return -1; @@ -338,23 +413,12 @@ static int vmbus_uio_sysfs_read(const char *dir, const char *name, return ret; } -static bool vmbus_uio_ring_present(const struct rte_vmbus_device *dev, - uint32_t relid) -{ - char ring_path[PATH_MAX]; - - /* Check if kernel has subchannel sysfs files */ - snprintf(ring_path, sizeof(ring_path), - "%s/%s/channels/%u/ring", - SYSFS_VMBUS_DEVICES, dev->device.name, relid); - - return access(ring_path, R_OK|W_OK) == 0; -} - bool vmbus_uio_subchannels_supported(const struct rte_vmbus_device *dev, const struct vmbus_channel *chan) { - return vmbus_uio_ring_present(dev, chan->relid); + RTE_SET_USED(dev); + RTE_SET_USED(chan); + return true; } static bool vmbus_isnew_subchannel(struct vmbus_channel *primary, -- 2.30.2