nfp: refactor the per-chip PCIe config
authorJakub Kicinski <jakub.kicinski@netronome.com>
Tue, 28 Aug 2018 20:20:39 +0000 (13:20 -0700)
committerDavid S. Miller <davem@davemloft.net>
Tue, 28 Aug 2018 23:01:47 +0000 (16:01 -0700)
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: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/netronome/nfp/nfpcore/nfp6000_pcie.c
drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cpp.h

index 6ef5ac2d0827dbfc0ce0cff48e4f3444a9ca6d0e..fd63d83bdea55f3c9f364371730e27d76dc4ed29 100644 (file)
 
 /* 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)
index 3b5182143ec7ca61ae328ad2a94d22b5f367617b..af19fe9f493465a39f0eb3a7a6e87470fe276298 100644 (file)
 
 #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