Commit 9bf6cce8 authored by Jakub Kicinski's avatar Jakub Kicinski Committed by David S. Miller

nfp: refactor the per-chip PCIe config

Use a switch statement instead of ifs for code dependent
on chip version.  While at it make sure we fail for unknown
chip revisions.
Signed-off-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 0377505c
......@@ -138,6 +138,7 @@
/* The number of explicit BARs to reserve.
* Minimum is 0, maximum is 4 on the NFP6000.
* The NFP3800 can have only one per PF.
*/
#define NFP_PCIE_EXPLICIT_BARS 2
......@@ -589,8 +590,8 @@ static int enable_bars(struct nfp6000_pcie *nfp, u16 interface)
NFP_PCIE_BAR_PCIE2CPP_MapType_EXPLICIT3),
};
char status_msg[196] = {};
int i, err, bars_free;
struct nfp_bar *bar;
int i, bars_free;
int expl_groups;
char *msg, *end;
......@@ -643,6 +644,8 @@ static int enable_bars(struct nfp6000_pcie *nfp, u16 interface)
bar->iomem = ioremap_nocache(nfp_bar_resource_start(bar),
nfp_bar_resource_len(bar));
if (bar->iomem) {
int pf;
msg += snprintf(msg, end - msg, "0.0: General/MSI-X SRAM, ");
atomic_inc(&bar->refcnt);
bars_free--;
......@@ -651,24 +654,40 @@ static int enable_bars(struct nfp6000_pcie *nfp, u16 interface)
nfp->expl.data = bar->iomem + NFP_PCIE_SRAM + 0x1000;
if (nfp->pdev->device == PCI_DEVICE_ID_NETRONOME_NFP4000 ||
nfp->pdev->device == PCI_DEVICE_ID_NETRONOME_NFP5000 ||
nfp->pdev->device == PCI_DEVICE_ID_NETRONOME_NFP6000) {
nfp->iomem.csr = bar->iomem + NFP_PCIE_BAR(0);
} else {
int pf = nfp->pdev->devfn & 7;
switch (nfp->pdev->device) {
case PCI_DEVICE_ID_NETRONOME_NFP3800:
pf = nfp->pdev->devfn & 7;
nfp->iomem.csr = bar->iomem + NFP_PCIE_BAR(pf);
break;
case PCI_DEVICE_ID_NETRONOME_NFP4000:
case PCI_DEVICE_ID_NETRONOME_NFP5000:
case PCI_DEVICE_ID_NETRONOME_NFP6000:
nfp->iomem.csr = bar->iomem + NFP_PCIE_BAR(0);
break;
default:
dev_err(nfp->dev, "Unsupported device ID: %04hx!\n",
nfp->pdev->device);
err = -EINVAL;
goto err_unmap_bar0;
}
nfp->iomem.em = bar->iomem + NFP_PCIE_EM;
}
if (nfp->pdev->device == PCI_DEVICE_ID_NETRONOME_NFP4000 ||
nfp->pdev->device == PCI_DEVICE_ID_NETRONOME_NFP5000 ||
nfp->pdev->device == PCI_DEVICE_ID_NETRONOME_NFP6000)
expl_groups = 4;
else
switch (nfp->pdev->device) {
case PCI_DEVICE_ID_NETRONOME_NFP3800:
expl_groups = 1;
break;
case PCI_DEVICE_ID_NETRONOME_NFP4000:
case PCI_DEVICE_ID_NETRONOME_NFP5000:
case PCI_DEVICE_ID_NETRONOME_NFP6000:
expl_groups = 4;
break;
default:
dev_err(nfp->dev, "Unsupported device ID: %04hx!\n",
nfp->pdev->device);
err = -EINVAL;
goto err_unmap_bar0;
}
/* Configure, and lock, BAR0.1 for PCIe XPB (MSI-X PBA) */
bar = &nfp->bar[1];
......@@ -713,6 +732,11 @@ static int enable_bars(struct nfp6000_pcie *nfp, u16 interface)
dev_info(nfp->dev, "%sfree: %d/%d\n", status_msg, bars_free, nfp->bars);
return 0;
err_unmap_bar0:
if (nfp->bar[0].iomem)
iounmap(nfp->bar[0].iomem);
return err;
}
static void disable_bars(struct nfp6000_pcie *nfp)
......
......@@ -62,6 +62,10 @@
#define PCI_64BIT_BAR_COUNT 3
/* NFP hardware vendor/device ids.
*/
#define PCI_DEVICE_ID_NETRONOME_NFP3800 0x3800
#define NFP_CPP_NUM_TARGETS 16
/* Max size of area it should be safe to request */
#define NFP_CPP_SAFE_AREA_SIZE SZ_2M
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment