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 AE369A0C46; Mon, 27 Sep 2021 17:00:49 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A9D1A41192; Mon, 27 Sep 2021 16:58:33 +0200 (CEST) Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by mails.dpdk.org (Postfix) with ESMTP id 50287410DA for ; Mon, 27 Sep 2021 15:43:07 +0200 (CEST) Received: by mail-pj1-f54.google.com with SMTP id v19so12488427pjh.2 for ; Mon, 27 Sep 2021 06:43:07 -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=qphklSi75ISsDBXC9paON1aCROjJrp9WEVfCh5Z5KOI=; b=V1rKmKiH1ytXAY4IHK0hfCnpYkku0WrlsEnBoqtnWoAZVoz5ogG6odtFYbp5ouWiw/ Srz8rDFuFg/RoKLUPeKL3WPpUN/A06k3la6AQfPW9yrhA8xWzPlfYZdynhVtDYJROwRt 6KeHQ+QdXKF5+b/bEpMpVz7XcwrHxx2jPq3kk= 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=qphklSi75ISsDBXC9paON1aCROjJrp9WEVfCh5Z5KOI=; b=MFgX2bhY+Tui4RPsMcZMEqNQ6VeO4jq9H2WYN4UNfZSiSKHtwTNGEjgbvuWOJGNasg Z1pBssFyssmI4MSYt0PwZHk44foWLBSfbyWhRh6v+6Fscvp6t7quyOfyusjMYvB6tXK5 gHOTLH3uTMsgFveWsaD/oikvCBLY+imkvjGQ2sm9u+lgxtgmAhJDs9rBL2Tn7XhVdz2P bWwZ8w2juGHM3FTv2XEzKIRUnQjD0ABI+m8fZ+yoRjKT+b1BX9t515uOZoLnmlbOGiEW RKG2bHPgMKt9jFezOb6xH9l0EWLBKXE0Wt5CN7OrudMa3uwVmQk7VVyxzTHhCR+QEvKP VcXA== X-Gm-Message-State: AOAM533iRdKJLacLh2IwwsaJz7EK99fJ3j0qMEOfyawmegFpCAyWAnVd 263HRTCvLBZHTD1hHejexfAn9A== X-Google-Smtp-Source: ABdhPJy+1E0aBhjnodUmUldy8b+o37Ks7jDNuMZfcsPW1jxoROVKqzXGneunJAvTmcirVRiGDkbKSw== X-Received: by 2002:a17:90b:3890:: with SMTP id mu16mr20444986pjb.78.1632750186543; Mon, 27 Sep 2021 06:43:06 -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.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Sep 2021 06:43:06 -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:23 +0530 Message-Id: <20210927134231.11177-4-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 03/11] bus/vmbus: handle mapping of device resources 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" All resource values are published by HV_UIO driver as sysctl key value pairs and they are read at a later point of the code flow Signed-off-by: Srikanth Kaka Signed-off-by: Vag Singh Signed-off-by: Anand Thulasiram --- drivers/bus/vmbus/freebsd/vmbus_bus.c | 127 -------------------------- 1 file changed, 127 deletions(-) diff --git a/drivers/bus/vmbus/freebsd/vmbus_bus.c b/drivers/bus/vmbus/freebsd/vmbus_bus.c index 8eb428a154..9b23b1131c 100644 --- a/drivers/bus/vmbus/freebsd/vmbus_bus.c +++ b/drivers/bus/vmbus/freebsd/vmbus_bus.c @@ -55,142 +55,15 @@ parse_sysfs_uuid(const char *filename, rte_uuid_t uu) return 0; } -static int -get_sysfs_string(const char *filename, char *buf, size_t buflen) -{ - char *cp; - FILE *f; - - f = fopen(filename, "r"); - if (f == NULL) { - VMBUS_LOG(ERR, "cannot open sysfs value %s:%s", - filename, strerror(errno)); - return -1; - } - - if (fgets(buf, buflen, f) == NULL) { - VMBUS_LOG(ERR, "cannot read sysfs value %s", - filename); - fclose(f); - return -1; - } - fclose(f); - - /* remove trailing newline */ - cp = memchr(buf, '\n', buflen); - if (cp) - *cp = '\0'; - - return 0; -} - -static int -vmbus_get_uio_dev(const struct rte_vmbus_device *dev, - char *dstbuf, size_t buflen) -{ - char dirname[PATH_MAX]; - unsigned int uio_num; - struct dirent *e; - DIR *dir; - - /* Assume recent kernel where uio is in uio/uioX */ - snprintf(dirname, sizeof(dirname), - SYSFS_VMBUS_DEVICES "/%s/uio", dev->device.name); - - dir = opendir(dirname); - if (dir == NULL) - return -1; /* Not a UIO device */ - - /* take the first file starting with "uio" */ - while ((e = readdir(dir)) != NULL) { - const int prefix_len = 3; - char *endptr; - - if (strncmp(e->d_name, "uio", prefix_len) != 0) - continue; - - /* try uio%d */ - errno = 0; - uio_num = strtoull(e->d_name + prefix_len, &endptr, 10); - if (errno == 0 && endptr != (e->d_name + prefix_len)) { - snprintf(dstbuf, buflen, "%s/uio%u", dirname, uio_num); - break; - } - } - closedir(dir); - - if (e == NULL) - return -1; - - return uio_num; -} - -/* 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:", - [HV_SEND_BUF_MAP] = "send:", -}; - - /* map the resources of a vmbus device in virtual memory */ int rte_vmbus_map_device(struct rte_vmbus_device *dev) { - char uioname[PATH_MAX], filename[PATH_MAX]; - char dirname[PATH_MAX], mapname[64]; - int i; - - dev->uio_num = vmbus_get_uio_dev(dev, uioname, sizeof(uioname)); if (dev->uio_num < 0) { VMBUS_LOG(DEBUG, "Not managed by UIO driver, skipped"); return 1; } - /* Extract resource value */ - for (i = 0; i < VMBUS_MAX_RESOURCE; i++) { - struct rte_mem_resource *res = &dev->resource[i]; - unsigned long len, gpad = 0; - char *cp; - - snprintf(dirname, sizeof(dirname), - "%s/maps/map%d", uioname, i); - - snprintf(filename, sizeof(filename), - "%s/name", dirname); - - if (get_sysfs_string(filename, mapname, sizeof(mapname)) < 0) { - VMBUS_LOG(ERR, "could not read %s", filename); - return -1; - } - - if (strncmp(map_names[i], mapname, strlen(map_names[i])) != 0) { - VMBUS_LOG(ERR, - "unexpected resource %s (expected %s)", - mapname, map_names[i]); - return -1; - } - - snprintf(filename, sizeof(filename), - "%s/size", dirname); - if (eal_parse_sysfs_value(filename, &len) < 0) { - VMBUS_LOG(ERR, - "could not read %s", filename); - return -1; - } - res->len = len; - - /* both send and receive buffers have gpad in name */ - cp = memchr(mapname, ':', sizeof(mapname)); - if (cp) - gpad = strtoul(cp+1, NULL, 0); - - /* put the GPAD value in physical address */ - res->phys_addr = gpad; - } - return vmbus_uio_map_resource(dev); } -- 2.30.2