From patchwork Tue Jun 25 10:44:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hemant Agrawal X-Patchwork-Id: 167696 Delivered-To: patch@linaro.org Received: by 2002:ac9:6410:0:0:0:0:0 with SMTP id r16csp4829628ock; Tue, 25 Jun 2019 03:46:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqzznJ+4XOsBnpHMRE7HbgDoCuH2sdcDdoUdAkSzM+8JJZu9NQBXirNyGnFhwAaLbVJItxto X-Received: by 2002:a50:97ad:: with SMTP id e42mr153296897edb.243.1561459569450; Tue, 25 Jun 2019 03:46:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561459569; cv=none; d=google.com; s=arc-20160816; b=pdca7zGNrWK7WV7mIptAxJeHAMFy1ZsnkZNSULSaCa67dvk33EFe7TGv7iua4EsG5b 6XIfp5O2QocE3r3xwafyjxPWj+8WW6Qyg3Cqvjw5NqGcuI626Z6VWfsqKp6LakQX5pFa ck6BmCd0/HWC5vU/eD5uuw9oAnHpPdzGzebEiD3NjvjxBBUYlPU29RPu3SHeXUL5Ek6D P8gHVRStrBDuLnke4icgA1a6iZO67n85rfBrdzBySIHCwviIido5CLPccj23QUMIrUjR uOQ45CCAPvTDA4a+dC3VzuHaHIwk0LH9abucdGkCLTzgiJpYFEpQLqi6dsKGObFhY+5N GPkA== 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=gscI7fz84Tl4lw/dFrndSGb1s1T9axUnRymFFpP9EPU=; b=PONyWj7OsTfAbqMr5t8wZ+9lgd7PRJiFtOTCQ++5NBWO5ngShKZVIZrE4qzhwH/U4M KaYHbLEKTitukh52A7aUeo33IDFzXO+naYwPW49luBXOLl6ERPOSBo7+tWpCM55XRMjm t8NbUW3PQoPRGqLOxNWY2iI7zH5c7ub2A6LhbAd7DIMeqkpr3Yo2RXIJgoXeZ09j5yFH cQUfKUWqRbs+TYuLXFTdvHsKnsKsjXnkiHRC9apV/Z81g8cyjXpnwA+jtVA80cQbmFcK eXSpGfguPFYkEemCEA+JgYMMdC+P9h8XnQgIw5NqWsFRNggNjUBB2ymjsU2GeoptnFtb pZ7A== 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 d48si109050eda.214.2019.06.25.03.46.09; Tue, 25 Jun 2019 03:46:09 -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 E6E3A1BABD; Tue, 25 Jun 2019 12:46:01 +0200 (CEST) Received: from inva020.nxp.com (inva020.nxp.com [92.121.34.13]) by dpdk.org (Postfix) with ESMTP id 7DE761BA5B for ; Tue, 25 Jun 2019 12:45:56 +0200 (CEST) Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 2DA221A07A5; Tue, 25 Jun 2019 12:45:56 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 439011A07AE; Tue, 25 Jun 2019 12:45:54 +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 BE31D4030F; Tue, 25 Jun 2019 18:45:51 +0800 (SGT) From: Hemant Agrawal To: dev@dpdk.org Cc: ferruh.yigit@intel.com Date: Tue, 25 Jun 2019 16:14:09 +0530 Message-Id: <20190625104411.19565-3-hemant.agrawal@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190625104411.19565-1-hemant.agrawal@nxp.com> References: <20190625104411.19565-1-hemant.agrawal@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Subject: [dpdk-dev] [PATCH 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 1aae56fa9..711780e74 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; @@ -821,10 +835,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;