nfp: turn reading PCIe RTsym parameters into a helper
authorJakub Kicinski <jakub.kicinski@netronome.com>
Wed, 31 May 2017 15:06:45 +0000 (08:06 -0700)
committerDavid S. Miller <davem@davemloft.net>
Wed, 31 May 2017 21:58:13 +0000 (17:58 -0400)
Turn the function to read number of ports into a generic helper.
While at it make sure we propagate all errors other than -ENOENT.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/netronome/nfp/nfp_net_main.c

index 388759e047d8866fade95bed1f8fbb928acb51cf..55a4a334cf6ba4a491e6b1fe259b3f20a7fe6d21 100644 (file)
@@ -191,26 +191,32 @@ nfp_net_find_port(struct nfp_eth_table *eth_tbl, unsigned int id)
        return NULL;
 }
 
-static unsigned int nfp_net_pf_get_num_ports(struct nfp_pf *pf)
+static int
+nfp_net_pf_rtsym_read_optional(struct nfp_pf *pf, const char *format,
+                              unsigned int default_val)
 {
        char name[256];
        int err = 0;
        u64 val;
 
-       snprintf(name, sizeof(name), "nfd_cfg_pf%u_num_ports",
-                nfp_cppcore_pcie_unit(pf->cpp));
+       snprintf(name, sizeof(name), format, nfp_cppcore_pcie_unit(pf->cpp));
 
        val = nfp_rtsym_read_le(pf->cpp, name, &err);
-       /* Default to one port/vNIC */
        if (err) {
-               if (err != -ENOENT)
-                       nfp_err(pf->cpp, "Unable to read adapter vNIC count\n");
-               val = 1;
+               if (err == -ENOENT)
+                       return default_val;
+               nfp_err(pf->cpp, "Unable to read symbol %s\n", name);
+               return err;
        }
 
        return val;
 }
 
+static int nfp_net_pf_get_num_ports(struct nfp_pf *pf)
+{
+       return nfp_net_pf_rtsym_read_optional(pf, "nfd_cfg_pf%u_num_ports", 1);
+}
+
 static unsigned int
 nfp_net_pf_total_qcs(struct nfp_pf *pf, void __iomem *ctrl_bar,
                     unsigned int stride, u32 start_off, u32 num_off)
@@ -675,6 +681,10 @@ int nfp_net_pci_probe(struct nfp_pf *pf)
 
        mutex_lock(&pf->lock);
        pf->max_data_vnics = nfp_net_pf_get_num_ports(pf);
+       if ((int)pf->max_data_vnics < 0) {
+               err = pf->max_data_vnics;
+               goto err_unlock;
+       }
 
        ctrl_bar = nfp_net_pf_map_ctrl_bar(pf);
        if (!ctrl_bar) {