DPDK patches and discussions
 help / color / mirror / Atom feed
From: Hemant Agrawal <hemant.agrawal@nxp.com>
To: dev@dpdk.org
Cc: thomas@monjalon.net, Shreyansh Jain <shreyansh.jain@nxp.com>
Subject: [dpdk-dev] [PATCH v3 3/5] bus/fslmc: dynamic iommu mode detection
Date: Mon, 15 Jul 2019 14:14:40 +0530	[thread overview]
Message-ID: <20190715084442.14686-4-hemant.agrawal@nxp.com> (raw)
In-Reply-To: <20190715084442.14686-1-hemant.agrawal@nxp.com>

From: Shreyansh Jain <shreyansh.jain@nxp.com>

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 <shreyansh.jain@nxp.com>
---
 drivers/bus/fslmc/fslmc_vfio.c | 38 +++++++++++++++++++++++-----------
 1 file changed, 26 insertions(+), 12 deletions(-)

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;
-- 
2.17.1


  parent reply	other threads:[~2019-07-15  8:46 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-25 10:44 [dpdk-dev] [PATCH 1/5] bus/fslmc: support device iteration Hemant Agrawal
2019-06-25 10:44 ` [dpdk-dev] [PATCH 2/5] bus/fslmc: enhance error handling for dev parsing Hemant Agrawal
2019-06-25 10:44 ` [dpdk-dev] [PATCH 3/5] bus/fslmc: dynamic iommu mode detection Hemant Agrawal
2019-06-25 10:44 ` [dpdk-dev] [PATCH 4/5] bus/fslmc: use cinh read for eqcr ci on ls1088 platform Hemant Agrawal
2019-06-25 10:44 ` [dpdk-dev] [PATCH 5/5] mempool/dpaa2: vfio dmamap for user allocated memory Hemant Agrawal
2019-06-26 21:50 ` [dpdk-dev] [PATCH 1/5] bus/fslmc: support device iteration Thomas Monjalon
2019-06-27  9:20   ` Hemant Agrawal
2019-06-27  9:33 ` [dpdk-dev] [PATCH v2 0/5] FSLMC bus enchancements Hemant Agrawal
2019-06-27  9:33   ` [dpdk-dev] [PATCH v2 1/5] bus/fslmc: support device iteration Hemant Agrawal
2019-07-15  8:44     ` [dpdk-dev] [PATCH v3 0/5] FSLMC bus enchancements Hemant Agrawal
2019-07-15  8:44       ` [dpdk-dev] [PATCH v3 1/5] bus/fslmc: support device iteration Hemant Agrawal
2019-07-15  8:44       ` [dpdk-dev] [PATCH v3 2/5] bus/fslmc: enhance error handling for dev parsing Hemant Agrawal
2019-07-15  8:44       ` Hemant Agrawal [this message]
2019-07-15  8:44       ` [dpdk-dev] [PATCH v3 4/5] bus/fslmc: use cinh read for eqcr ci on ls1088 platform Hemant Agrawal
2019-07-15  8:44       ` [dpdk-dev] [PATCH v3 5/5] mempool/dpaa2: vfio dmamap for user allocated memory Hemant Agrawal
2019-07-15 21:53       ` [dpdk-dev] [PATCH v3 0/5] FSLMC bus enchancements Thomas Monjalon
2019-07-16 11:40         ` Ferruh Yigit
2019-07-16 13:36           ` Thomas Monjalon
2019-07-16 13:43             ` Bruce Richardson
2019-07-19 19:09             ` Ferruh Yigit
2019-07-22  6:56               ` Hemant Agrawal
2019-06-27  9:33   ` [dpdk-dev] [PATCH v2 2/5] bus/fslmc: enhance error handling for dev parsing Hemant Agrawal
2019-06-27  9:33   ` [dpdk-dev] [PATCH v2 3/5] bus/fslmc: dynamic iommu mode detection Hemant Agrawal
2019-06-27  9:33   ` [dpdk-dev] [PATCH v2 4/5] bus/fslmc: use cinh read for eqcr ci on ls1088 platform Hemant Agrawal
2019-06-27  9:33   ` [dpdk-dev] [PATCH v2 5/5] mempool/dpaa2: vfio dmamap for user allocated memory Hemant Agrawal
2019-07-07 19:55     ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190715084442.14686-4-hemant.agrawal@nxp.com \
    --to=hemant.agrawal@nxp.com \
    --cc=dev@dpdk.org \
    --cc=shreyansh.jain@nxp.com \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).