Blame SOURCES/0002-net-nfp-avoid-access-to-sysfs-resource0-file.patch

702481
From 7ecfd061afed55cbbd5c82802bc288ed67bf2cb3 Mon Sep 17 00:00:00 2001
702481
From: Alejandro Lucero <alejandro.lucero@netronome.com>
702481
Date: Tue, 26 Jun 2018 14:29:21 +0100
702481
Subject: [PATCH 2/2] net/nfp: avoid access to sysfs resource0 file
702481
702481
NFP CPP interface dinamically configures NFP CPP BARs for accessing
702481
any NFP chip component from user space. This requires to map PCI BAR
702481
regions specifically. However, this does not require to do such map
702481
over the usual map done by VFIO or UIO drivers with the device PCI
702481
BARs.
702481
702481
This patch avoids this remapping and therefore also avoids to access
702481
the device sysfs resource0 file for doing that remapping.
702481
702481
Signed-off-by: Alejandro Lucero <alejandro.lucero@netronome.com>
702481
(cherry picked from commit a28fb7bef424d3b96ff13b996de7ed8775c67542)
702481
---
702481
 drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 44 +---------------------
702481
 1 file changed, 2 insertions(+), 42 deletions(-)
702481
702481
diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c
702481
index 9accc89cf..73124487a 100644
702481
--- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c
702481
+++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c
702481
@@ -309,13 +309,8 @@ nfp_enable_bars(struct nfp_pcie_user *nfp)
702481
 		bar->csr = nfp->cfg +
702481
 			   NFP_PCIE_CFG_BAR_PCIETOCPPEXPBAR(bar->index >> 3,
702481
 							   bar->index & 7);
702481
-		bar->iomem =
702481
-		    (char *)mmap(0, 1 << bar->bitsize, PROT_READ | PROT_WRITE,
702481
-				 MAP_SHARED, nfp->device,
702481
-				 bar->index << bar->bitsize);
702481
 
702481
-		if (bar->iomem == MAP_FAILED)
702481
-			return (-ENOMEM);
702481
+		bar->iomem = nfp->cfg + (bar->index << bar->bitsize);
702481
 	}
702481
 	return 0;
702481
 }
702481
@@ -345,7 +340,6 @@ nfp_disable_bars(struct nfp_pcie_user *nfp)
702481
 	for (x = ARRAY_SIZE(nfp->bar); x > 0; x--) {
702481
 		bar = &nfp->bar[x - 1];
702481
 		if (bar->iomem) {
702481
-			munmap(bar->iomem, 1 << (nfp->barsz - 3));
702481
 			bar->iomem = NULL;
702481
 			bar->lock = 0;
702481
 		}
702481
@@ -778,9 +772,6 @@ nfp6000_set_barsz(struct rte_pci_device *dev, struct nfp_pcie_user *desc)
702481
 static int
702481
 nfp6000_init(struct nfp_cpp *cpp, struct rte_pci_device *dev)
702481
 {
702481
-	char link[120];
702481
-	char tmp_str[80];
702481
-	ssize_t size;
702481
 	int ret = 0;
702481
 	uint32_t model;
702481
 	struct nfp_pcie_user *desc;
702481
@@ -799,24 +790,6 @@ nfp6000_init(struct nfp_cpp *cpp, struct rte_pci_device *dev)
702481
 			return -1;
702481
 	}
702481
 
702481
-	snprintf(tmp_str, sizeof(tmp_str), "%s/%s/driver", PCI_DEVICES,
702481
-		 desc->busdev);
702481
-
702481
-	size = readlink(tmp_str, link, sizeof(link));
702481
-
702481
-	if (size == -1)
702481
-		tmp_str[0] = '\0';
702481
-
702481
-	if (size == sizeof(link))
702481
-		tmp_str[0] = '\0';
702481
-
702481
-	snprintf(tmp_str, sizeof(tmp_str), "%s/%s/resource0", PCI_DEVICES,
702481
-		 desc->busdev);
702481
-
702481
-	desc->device = open(tmp_str, O_RDWR);
702481
-	if (desc->device == -1)
702481
-		return -1;
702481
-
702481
 	if (nfp6000_set_model(dev, cpp) < 0)
702481
 		return -1;
702481
 	if (nfp6000_set_interface(dev, cpp) < 0)
702481
@@ -826,12 +799,7 @@ nfp6000_init(struct nfp_cpp *cpp, struct rte_pci_device *dev)
702481
 	if (nfp6000_set_barsz(dev, desc) < 0)
702481
 		return -1;
702481
 
702481
-	desc->cfg = (char *)mmap(0, 1 << (desc->barsz - 3),
702481
-				 PROT_READ | PROT_WRITE,
702481
-				 MAP_SHARED, desc->device, 0);
702481
-
702481
-	if (desc->cfg == MAP_FAILED)
702481
-		return -1;
702481
+	desc->cfg = (char *)dev->mem_resource[0].addr;
702481
 
702481
 	nfp_enable_bars(desc);
702481
 
702481
@@ -847,16 +815,8 @@ static void
702481
 nfp6000_free(struct nfp_cpp *cpp)
702481
 {
702481
 	struct nfp_pcie_user *desc = nfp_cpp_priv(cpp);
702481
-	int x;
702481
 
702481
-	/* Unmap may cause if there are any pending transaxctions */
702481
 	nfp_disable_bars(desc);
702481
-	munmap(desc->cfg, 1 << (desc->barsz - 3));
702481
-
702481
-	for (x = ARRAY_SIZE(desc->bar); x > 0; x--) {
702481
-		if (desc->bar[x - 1].iomem)
702481
-			munmap(desc->bar[x - 1].iomem, 1 << (desc->barsz - 3));
702481
-	}
702481
 	if (cpp->driver_lock_needed)
702481
 		close(desc->lock);
702481
 	close(desc->device);
702481
-- 
702481
2.17.1
702481