OSDN Git Service

nfp: use dev_info for PCIe config space BAR offsets
authorJakub Kicinski <jakub.kicinski@netronome.com>
Fri, 11 Mar 2022 10:43:02 +0000 (11:43 +0100)
committerJakub Kicinski <kuba@kernel.org>
Sat, 12 Mar 2022 07:10:22 +0000 (23:10 -0800)
NFP3800 uses a different PCIe configuration to CPP expansion BAR offsets.
We don't need to differentiate between the NFP4000, NFP5000 and NFP6000
since they all use the same offsets.

Signed-off-by: Dirk van der Merwe <dirk.vandermerwe@netronome.com>
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Fei Qin <fei.qin@corigine.com>
Signed-off-by: Simon Horman <simon.horman@corigine.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/netronome/nfp/nfpcore/nfp6000_pcie.c
drivers/net/ethernet/netronome/nfp/nfpcore/nfp_dev.c
drivers/net/ethernet/netronome/nfp/nfpcore/nfp_dev.h

index aa8122f..0d1d39e 100644 (file)
 #define NFP_PCIE_P2C_GENERAL_TOKEN_OFFSET(bar, x) ((x) << ((bar)->bitsize - 4))
 #define NFP_PCIE_P2C_GENERAL_SIZE(bar)             (1 << ((bar)->bitsize - 4))
 
-#define NFP_PCIE_CFG_BAR_PCIETOCPPEXPANSIONBAR(bar, slot) \
-       (0x400 + ((bar) * 8 + (slot)) * 4)
-
-#define NFP_PCIE_CPP_BAR_PCIETOCPPEXPANSIONBAR(bar, slot) \
-       (((bar) * 8 + (slot)) * 4)
+#define NFP_PCIE_P2C_EXPBAR_OFFSET(bar_index)          ((bar_index) * 4)
 
 /* The number of explicit BARs to reserve.
  * Minimum is 0, maximum is 4 on the NFP6000.
@@ -271,19 +267,16 @@ compute_bar(const struct nfp6000_pcie *nfp, const struct nfp_bar *bar,
 static int
 nfp6000_bar_write(struct nfp6000_pcie *nfp, struct nfp_bar *bar, u32 newcfg)
 {
-       int base, slot;
-       int xbar;
+       unsigned int xbar;
 
-       base = bar->index >> 3;
-       slot = bar->index & 7;
+       xbar = NFP_PCIE_P2C_EXPBAR_OFFSET(bar->index);
 
        if (nfp->iomem.csr) {
-               xbar = NFP_PCIE_CPP_BAR_PCIETOCPPEXPANSIONBAR(base, slot);
                writel(newcfg, nfp->iomem.csr + xbar);
                /* Readback to ensure BAR is flushed */
                readl(nfp->iomem.csr + xbar);
        } else {
-               xbar = NFP_PCIE_CFG_BAR_PCIETOCPPEXPANSIONBAR(base, slot);
+               xbar += nfp->dev_info->pcie_cfg_expbar_offset;
                pci_write_config_dword(nfp->pdev, xbar, newcfg);
        }
 
@@ -624,7 +617,8 @@ static int enable_bars(struct nfp6000_pcie *nfp, u16 interface)
 
                nfp6000_bar_write(nfp, bar, barcfg_msix_general);
 
-               nfp->expl.data = bar->iomem + NFP_PCIE_SRAM + 0x1000;
+               nfp->expl.data = bar->iomem + NFP_PCIE_SRAM +
+                       nfp->dev_info->pcie_expl_offset;
 
                switch (nfp->pdev->device) {
                case PCI_DEVICE_ID_NETRONOME_NFP3800:
index 6069d18..b3fb09c 100644 (file)
@@ -6,5 +6,7 @@
 const struct nfp_dev_info nfp_dev_info[NFP_DEV_CNT] = {
        [NFP_DEV_NFP6000] = {
                .chip_names             = "NFP4000/NFP5000/NFP6000",
+               .pcie_cfg_expbar_offset = 0x0400,
+               .pcie_expl_offset       = 0x1000,
        },
 };
index 514aa08..18ca8ac 100644 (file)
@@ -4,6 +4,8 @@
 #ifndef _NFP_DEV_H_
 #define _NFP_DEV_H_
 
+#include <linux/types.h>
+
 enum nfp_dev_id {
        NFP_DEV_NFP6000,
        NFP_DEV_CNT,
@@ -11,6 +13,8 @@ enum nfp_dev_id {
 
 struct nfp_dev_info {
        const char *chip_names;
+       u32 pcie_cfg_expbar_offset;
+       u32 pcie_expl_offset;
 };
 
 extern const struct nfp_dev_info nfp_dev_info[NFP_DEV_CNT];