From patchwork Tue Jun 26 13:29:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Lucero X-Patchwork-Id: 41573 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A92A01B5CA; Tue, 26 Jun 2018 15:29:49 +0200 (CEST) Received: from netronome.com (host-79-78-33-110.static.as9105.net [79.78.33.110]) by dpdk.org (Postfix) with ESMTP id A0F061B5C8 for ; Tue, 26 Jun 2018 15:29:48 +0200 (CEST) Received: from netronome.com (localhost [127.0.0.1]) by netronome.com (8.14.4/8.14.4/Debian-4.1ubuntu1) with ESMTP id w5QDTLgZ027833 for ; Tue, 26 Jun 2018 14:29:21 +0100 Received: (from alucero@localhost) by netronome.com (8.14.4/8.14.4/Submit) id w5QDTLiX027832 for dev@dpdk.org; Tue, 26 Jun 2018 14:29:21 +0100 From: Alejandro Lucero To: dev@dpdk.org Date: Tue, 26 Jun 2018 14:29:21 +0100 Message-Id: <1530019761-27794-1-git-send-email-alejandro.lucero@netronome.com> X-Mailer: git-send-email 1.9.1 Subject: [dpdk-dev] [PATCH] net/nfp: avoid access to sysfs resource0 file 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" NFP CPP interface dinamically configures NFP CPP BARs for accessing any NFP chip component from user space. This requires to map PCI BAR regions specifically. However, this does not require to do such map over the usual map done by VFIO or UIO drivers with the device PCI BARs. This patch avoids this remapping and therefore also avoids to access the device sysfs resource0 file for doing that remapping. Signed-off-by: Alejandro Lucero --- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 46 ++---------------------------- 1 file changed, 3 insertions(+), 43 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index b0beb8d..c68d940 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -310,13 +310,8 @@ struct nfp_pcie_user { bar->csr = nfp->cfg + NFP_PCIE_CFG_BAR_PCIETOCPPEXPBAR(bar->index >> 3, bar->index & 7); - bar->iomem = - (char *)mmap(0, 1 << bar->bitsize, PROT_READ | PROT_WRITE, - MAP_SHARED, nfp->device, - bar->index << bar->bitsize); - if (bar->iomem == MAP_FAILED) - return (-ENOMEM); + bar->iomem = nfp->cfg + (bar->index << bar->bitsize); } return 0; } @@ -346,7 +341,6 @@ struct nfp_pcie_user { for (x = ARRAY_SIZE(nfp->bar); x > 0; x--) { bar = &nfp->bar[x - 1]; if (bar->iomem) { - munmap(bar->iomem, 1 << (nfp->barsz - 3)); bar->iomem = NULL; bar->lock = 0; } @@ -779,9 +773,6 @@ struct nfp6000_area_priv { static int nfp6000_init(struct nfp_cpp *cpp, struct rte_pci_device *dev) { - char link[120]; - char tmp_str[80]; - ssize_t size; int ret = 0; uint32_t model; struct nfp_pcie_user *desc; @@ -800,39 +791,16 @@ struct nfp6000_area_priv { return -1; } - snprintf(tmp_str, sizeof(tmp_str), "%s/%s/driver", PCI_DEVICES, - desc->busdev); - - size = readlink(tmp_str, link, sizeof(link)); - - if (size == -1) - tmp_str[0] = '\0'; - - if (size == sizeof(link)) - tmp_str[0] = '\0'; - - snprintf(tmp_str, sizeof(tmp_str), "%s/%s/resource0", PCI_DEVICES, - desc->busdev); - - desc->device = open(tmp_str, O_RDWR); - if (desc->device == -1) - return -1; - if (nfp6000_set_model(dev, cpp) < 0) return -1; if (nfp6000_set_interface(dev, cpp) < 0) return -1; if (nfp6000_set_serial(dev, cpp) < 0) return -1; - if (nfp6000_set_barsz(desc) < 0) + if (nfp6000_set_barsz(dev, desc) < 0) return -1; - desc->cfg = (char *)mmap(0, 1 << (desc->barsz - 3), - PROT_READ | PROT_WRITE, - MAP_SHARED, desc->device, 0); - - if (desc->cfg == MAP_FAILED) - return -1; + desc->cfg = (char *)dev->mem_resource[0].addr; nfp_enable_bars(desc); @@ -848,16 +816,8 @@ struct nfp6000_area_priv { nfp6000_free(struct nfp_cpp *cpp) { struct nfp_pcie_user *desc = nfp_cpp_priv(cpp); - int x; - /* Unmap may cause if there are any pending transaxctions */ nfp_disable_bars(desc); - munmap(desc->cfg, 1 << (desc->barsz - 3)); - - for (x = ARRAY_SIZE(desc->bar); x > 0; x--) { - if (desc->bar[x - 1].iomem) - munmap(desc->bar[x - 1].iomem, 1 << (desc->barsz - 3)); - } if (cpp->driver_lock_needed) close(desc->lock); close(desc->device);