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 EA14EA034E; Thu, 17 Feb 2022 17:11:33 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 13AD14116A; Thu, 17 Feb 2022 17:10:58 +0100 (CET) Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by mails.dpdk.org (Postfix) with ESMTP id 8B1DA40395 for ; Thu, 17 Feb 2022 17:06:45 +0100 (CET) Received: by mail-pj1-f41.google.com with SMTP id qe15so6002941pjb.3 for ; Thu, 17 Feb 2022 08:06:45 -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=FQE7R5QnH3f3iR0R/TgKwsCPuFKvpff6aX+RZerj3xU=; b=LuygHn7VzxdYP2ovtVO46GEC6rlEHrg3dGLZo4tPaxpGjx6t1lC1VG+8MamoNG9BpC zGX6l9d+ty/VY0/uetI8zIlh41GO0C7y/c40vymKRTxjd9GDVwmL4Oi95u/Y3E00Ln0N /YfozuETV9hP/Kt9xOfikGMOdBtCNqZRBtOHI= 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=FQE7R5QnH3f3iR0R/TgKwsCPuFKvpff6aX+RZerj3xU=; b=Xhf1JbJ0T51rTYzL+1TfTPcC5w5S3sdNwiBrya71TI7byDphXpAzZZ2w70m5O8iYxv R9BTLAliebV8ZXcE+KKw0yX+wuYs3itCyF1VWZY9PCWni8b5A+bpaR6phYpsR5Em6m83 XMS4rNAOgK9Eo3CNGl4DU2AJzKUUwBYYvKt6pkaIpRf53Y6CYm+W305peur5d36E56n/ TjSbwyvQz8rjElDEW8BpJ+lTIbJM3RszoCVIY0dd7K4PKaNDI0gRLjxP/KpYt1Ut/kOZ VWzDZ/8iPeSfxcXIIDdHgoxuLV1Yg8jx3ByYKDtdJ8Qs30oL6KogoLmWpx/2W8sULQdJ JNvQ== X-Gm-Message-State: AOAM530xIsgcYe6ouKV1hxmUPynU+Zh9OPFgmx8AE/CYoqaahO+rL06Q 1DiB/wW8LK3UHA1RbubaInFcmQ== X-Google-Smtp-Source: ABdhPJxJV658pLdJ/u1dVA3Uefbqs8L7J5KISfZRTOD4/+hyDvqk8SVEP/YBZ6d4+U14e+bK0dJjRg== X-Received: by 2002:a17:902:e84f:b0:14d:8437:5130 with SMTP id t15-20020a170902e84f00b0014d84375130mr3433979plg.60.1645114004744; Thu, 17 Feb 2022 08:06:44 -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.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 08:06:44 -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 06/15] bus/vmbus: add ring mapping APIs Date: Thu, 17 Feb 2022 21:36:04 +0530 Message-Id: <20220217160613.70161-7-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 Based on its channel id, mapping of primary channel or subchannel is determined. The primary channel memmory is mapped in the same way as done in Linux. For the subchannel an mmap request is directly made after determining the subchan memory offset Signed-off-by: Srikanth Kaka Signed-off-by: Vag Singh Signed-off-by: Anand Thulasiram --- drivers/bus/vmbus/freebsd/vmbus_uio.c | 86 +++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/drivers/bus/vmbus/freebsd/vmbus_uio.c b/drivers/bus/vmbus/freebsd/vmbus_uio.c index 41522ba2b5..b0c011dd9a 100644 --- a/drivers/bus/vmbus/freebsd/vmbus_uio.c +++ b/drivers/bus/vmbus/freebsd/vmbus_uio.c @@ -17,6 +17,12 @@ #include "private.h" +/* Macros to distinguish mmap request + * [7-0] - Device memory region + * [15-8]- Sub-channel id + */ +#define UH_SUBCHAN_MASK_SHIFT 8 + const char *driver_name = "hv_uio"; static void *vmbus_map_addr; @@ -210,3 +216,83 @@ vmbus_uio_map_resource_by_index(struct rte_vmbus_device *dev, int idx, return 0; } +static int vmbus_uio_map_primary(struct vmbus_channel *chan, + void **ring_buf, uint32_t *ring_size) +{ + struct mapped_vmbus_resource *uio_res; + + uio_res = vmbus_uio_find_resource(chan->device); + if (!uio_res) { + VMBUS_LOG(ERR, "can not find resources!"); + return -ENOMEM; + } + + if (uio_res->nb_maps < VMBUS_MAX_RESOURCE) { + VMBUS_LOG(ERR, "VMBUS: only %u resources found!", + uio_res->nb_maps); + return -EINVAL; + } + + *ring_size = uio_res->maps[HV_TXRX_RING_MAP].size / 2; + *ring_buf = uio_res->maps[HV_TXRX_RING_MAP].addr; + return 0; +} + +static int vmbus_uio_map_subchan(const struct rte_vmbus_device *dev, + struct vmbus_channel *chan, + void **ring_buf, uint32_t *ring_size) +{ + char ring_path[PATH_MAX]; + size_t size; + void *mapaddr; + off_t offset; + int fd; + + snprintf(ring_path, sizeof(ring_path), + "/dev/hv_uio%d", dev->uio_num); + + fd = open(ring_path, O_RDWR); + if (fd < 0) { + VMBUS_LOG(ERR, "Cannot open %s: %s", + ring_path, strerror(errno)); + return -errno; + } + + /* subchannel rings are of the same size as primary */ + size = dev->resource[HV_TXRX_RING_MAP].len; + offset = (chan->relid << UH_SUBCHAN_MASK_SHIFT) * PAGE_SIZE; + + mapaddr = vmbus_map_resource(vmbus_map_addr, fd, + offset, size, 0); + close(fd); + + if (mapaddr == MAP_FAILED) + return -EIO; + + *ring_size = size / 2; + *ring_buf = mapaddr; + + vmbus_map_addr = RTE_PTR_ADD(mapaddr, size); + return 0; +} + +int vmbus_uio_map_rings(struct vmbus_channel *chan) +{ + const struct rte_vmbus_device *dev = chan->device; + uint32_t ring_size; + void *ring_buf; + int ret; + + /* Primary channel */ + if (chan->subchannel_id == 0) + ret = vmbus_uio_map_primary(chan, &ring_buf, &ring_size); + else + ret = vmbus_uio_map_subchan(dev, chan, &ring_buf, &ring_size); + + if (ret) + return ret; + + vmbus_br_setup(&chan->txbr, ring_buf, ring_size); + vmbus_br_setup(&chan->rxbr, (char *)ring_buf + ring_size, ring_size); + return 0; +} -- 2.30.2