From patchwork Mon Jul 15 08:44:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hemant Agrawal X-Patchwork-Id: 168981 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4104281ilk; Mon, 15 Jul 2019 01:46:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqytofD8f4xpk+1yK7aliey3qbX+n4Kh+SpW+xsiC0++NqYn0zalBgwNYjN3pTfcpvS5yrMZ X-Received: by 2002:aa7:da14:: with SMTP id r20mr21883786eds.65.1563180386254; Mon, 15 Jul 2019 01:46:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563180386; cv=none; d=google.com; s=arc-20160816; b=KHc6yOR67Sv0HdakEDPPG8XywoQ46nS1Ai95HTOPW8rYteEYRzj2Wh/B0ZFbE7vYGt iLmp6dWZiDkrqcMjRTwpzqs84anB7ubXBM8WdzW+OsiC3CVS7UVbhzCy+seZy+DfiTvb ESWyEfyYje3bNTVAO9xFPLiy/zYRNmdKocLZlVBySyS5QisH0dmRzyMfTVJxYQrWEv5T AP+CXO/ymZVjx2HQz6yU5BopjKzEdeLMVEOr1V3iVM4f2I+6uxFE4IjPmEtUX1NAOwKZ CKeKZch7p5ayM403YBZ3gqtMirG0YBOvbTIz0d9NtNDY4AaaEkKuafKJWZIZzmEeXk5/ PEqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:cc:to:from; bh=waNWQuUVOkiv24Kl2ipmlZY9ltQNjA3kNBDPe8067Tg=; b=S8XsHQFPE/5F3YUNQ9Plv5rDZLk6ScQWZD9So1FjBmAX96eDfBBJ1Hvqqut2Q2AjvI q8ZKQ2kdHWbQdtUkNSvEHnEJAnlYJFcwhr6gkgGoMNZix/SByEUCruJMeMVFh9VLM/DH vs/wfLv3quBzMszzu3AvnSBTQFxvTlnYi9T2ADpu0oBHJqJrENMsWd8/FxOTf85DU8Ga Htd2g0jJ+OJHUN6e7J+cWzMyuTCwsVXgFhO6K39mr7u7jZKlek26XL98HAzJSWSFrQ5H Cj4yc75vXfy3vKqK5nbVdupW57DC0a0qXalSIDyi72vjT5W+ZKt+LZz+SjUrVU9cDFIB k+qg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from dpdk.org (dpdk.org. [92.243.14.124]) by mx.google.com with ESMTP id z31si10136833edz.165.2019.07.15.01.46.26; Mon, 15 Jul 2019 01:46:26 -0700 (PDT) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) client-ip=92.243.14.124; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 16C3B1B993; Mon, 15 Jul 2019 10:46:10 +0200 (CEST) Received: from inva021.nxp.com (inva021.nxp.com [92.121.34.21]) by dpdk.org (Postfix) with ESMTP id 1243D3772 for ; Mon, 15 Jul 2019 10:46:03 +0200 (CEST) Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id C31062001B5; Mon, 15 Jul 2019 10:46:03 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 6BAA420000E; Mon, 15 Jul 2019 10:46:01 +0200 (CEST) Received: from bf-netperf1.ap.freescale.net (bf-netperf1.ap.freescale.net [10.232.133.63]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id 3459F402A8; Mon, 15 Jul 2019 16:45:58 +0800 (SGT) From: Hemant Agrawal To: dev@dpdk.org Cc: thomas@monjalon.net, Shreyansh Jain Date: Mon, 15 Jul 2019 14:14:40 +0530 Message-Id: <20190715084442.14686-4-hemant.agrawal@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190715084442.14686-1-hemant.agrawal@nxp.com> References: <20190627093343.5171-2-hemant.agrawal@nxp.com> <20190715084442.14686-1-hemant.agrawal@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Subject: [dpdk-dev] [PATCH v3 3/5] bus/fslmc: dynamic iommu mode detection X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 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" From: Shreyansh Jain This patch adds following: 1. 'g_container' variable name is not right way to represent the FSLMC container. Renaming it to fslmc_container. 2. dynamic selection of IOMMU mode based on run environment Signed-off-by: Shreyansh Jain --- drivers/bus/fslmc/fslmc_vfio.c | 38 +++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 12 deletions(-) -- 2.17.1 diff --git a/drivers/bus/fslmc/fslmc_vfio.c b/drivers/bus/fslmc/fslmc_vfio.c index 44e4fa6e2..1383af4f1 100644 --- a/drivers/bus/fslmc/fslmc_vfio.c +++ b/drivers/bus/fslmc/fslmc_vfio.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 2015-2016 Freescale Semiconductor, Inc. All rights reserved. - * Copyright 2016-2018 NXP + * Copyright 2016-2019 NXP * */ @@ -49,7 +49,8 @@ static struct fslmc_vfio_group vfio_group; static struct fslmc_vfio_container vfio_container; static int container_device_fd; -static char *g_container; +static char *fslmc_container; +static int fslmc_iommu_type; static uint32_t *msi_intr_vaddr; void *(*rte_mcp_ptr_list); @@ -71,7 +72,7 @@ fslmc_get_container_group(int *groupid) int ret; char *container; - if (!g_container) { + if (!fslmc_container) { container = getenv("DPRC"); if (container == NULL) { DPAA2_BUS_DEBUG("DPAA2: DPRC not available"); @@ -83,23 +84,26 @@ fslmc_get_container_group(int *groupid) return -1; } - g_container = strdup(container); - if (!g_container) { + fslmc_container = strdup(container); + if (!fslmc_container) { DPAA2_BUS_ERR("Mem alloc failure; Container name"); return -ENOMEM; } } + fslmc_iommu_type = (rte_vfio_noiommu_is_enabled() == 1) ? + RTE_VFIO_NOIOMMU : VFIO_TYPE1_IOMMU; + /* get group number */ ret = rte_vfio_get_group_num(SYSFS_FSL_MC_DEVICES, - g_container, groupid); + fslmc_container, groupid); if (ret <= 0) { - DPAA2_BUS_ERR("Unable to find %s IOMMU group", g_container); + DPAA2_BUS_ERR("Unable to find %s IOMMU group", fslmc_container); return -1; } DPAA2_BUS_DEBUG("Container: %s has VFIO iommu group id = %d", - g_container, *groupid); + fslmc_container, *groupid); return 0; } @@ -132,7 +136,7 @@ vfio_connect_container(void) } /* Check whether support for SMMU type IOMMU present or not */ - if (ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU)) { + if (ioctl(fd, VFIO_CHECK_EXTENSION, fslmc_iommu_type)) { /* Connect group to container */ ret = ioctl(vfio_group.fd, VFIO_GROUP_SET_CONTAINER, &fd); if (ret) { @@ -141,7 +145,7 @@ vfio_connect_container(void) return -errno; } - ret = ioctl(fd, VFIO_SET_IOMMU, VFIO_TYPE1_IOMMU); + ret = ioctl(fd, VFIO_SET_IOMMU, fslmc_iommu_type); if (ret) { DPAA2_BUS_ERR("Failed to setup VFIO iommu"); close(fd); @@ -261,6 +265,11 @@ fslmc_map_dma(uint64_t vaddr, rte_iova_t iovaddr __rte_unused, size_t len) }; int ret; + if (fslmc_iommu_type == RTE_VFIO_NOIOMMU) { + DPAA2_BUS_DEBUG("Running in NOIOMMU mode"); + return 0; + } + dma_map.size = len; dma_map.vaddr = vaddr; @@ -300,6 +309,11 @@ fslmc_unmap_dma(uint64_t vaddr, uint64_t iovaddr __rte_unused, size_t len) }; int ret; + if (fslmc_iommu_type == RTE_VFIO_NOIOMMU) { + DPAA2_BUS_DEBUG("Running in NOIOMMU mode"); + return 0; + } + dma_unmap.size = len; dma_unmap.iova = vaddr; @@ -819,10 +833,10 @@ fslmc_vfio_setup_group(void) } /* Get Device information */ - ret = ioctl(vfio_group.fd, VFIO_GROUP_GET_DEVICE_FD, g_container); + ret = ioctl(vfio_group.fd, VFIO_GROUP_GET_DEVICE_FD, fslmc_container); if (ret < 0) { DPAA2_BUS_ERR("Error getting device %s fd from group %d", - g_container, vfio_group.groupid); + fslmc_container, vfio_group.groupid); close(vfio_group.fd); rte_vfio_clear_group(vfio_group.fd); return ret;