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