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

nfp: don't depend on eth_tbl being available

For very very old generation of the management FW Ethernet port
information table may theoretically not be available.  This in
turn will cause the nfp_port structures to not be allocated.

Make sure we don't crash the kernel when there is no eth_tbl:

RIP: 0010:nfp_net_pci_probe+0xf2/0xb40 [nfp]
...
Call Trace:
  nfp_pci_probe+0x6de/0xab0 [nfp]
  local_pci_probe+0x47/0xa0
  work_for_cpu_fn+0x1a/0x30
  process_one_work+0x1de/0x3e0

Found while working with broken/development version of management FW.

Fixes: a5950182 ("nfp: map mac_stats and vf_cfg BARs")
Fixes: 93da7d96 ("nfp: provide nfp_port to of nfp_net_get_mac_addr()")
Signed-off-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: default avatarDirk van der Merwe <dirk.vandermerwe@netronome.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 7dbc73e6
......@@ -360,7 +360,7 @@ nfp_flower_spawn_phy_reprs(struct nfp_app *app, struct nfp_flower_priv *priv)
}
SET_NETDEV_DEV(repr, &priv->nn->pdev->dev);
nfp_net_get_mac_addr(app->pf, port);
nfp_net_get_mac_addr(app->pf, repr, port);
cmsg_port_id = nfp_flower_cmsg_phys_port(phys_port);
err = nfp_repr_init(app, repr,
......
......@@ -69,7 +69,7 @@ int nfp_app_nic_vnic_alloc(struct nfp_app *app, struct nfp_net *nn,
if (err)
return err < 0 ? err : 0;
nfp_net_get_mac_addr(app->pf, nn->port);
nfp_net_get_mac_addr(app->pf, nn->dp.netdev, nn->port);
return 0;
}
......@@ -171,7 +171,9 @@ void nfp_net_pci_remove(struct nfp_pf *pf);
int nfp_hwmon_register(struct nfp_pf *pf);
void nfp_hwmon_unregister(struct nfp_pf *pf);
void nfp_net_get_mac_addr(struct nfp_pf *pf, struct nfp_port *port);
void
nfp_net_get_mac_addr(struct nfp_pf *pf, struct net_device *netdev,
struct nfp_port *port);
bool nfp_ctrl_tx(struct nfp_net *nn, struct sk_buff *skb);
......
......@@ -67,23 +67,26 @@
/**
* nfp_net_get_mac_addr() - Get the MAC address.
* @pf: NFP PF handle
* @netdev: net_device to set MAC address on
* @port: NFP port structure
*
* First try to get the MAC address from NSP ETH table. If that
* fails generate a random address.
*/
void nfp_net_get_mac_addr(struct nfp_pf *pf, struct nfp_port *port)
void
nfp_net_get_mac_addr(struct nfp_pf *pf, struct net_device *netdev,
struct nfp_port *port)
{
struct nfp_eth_table_port *eth_port;
eth_port = __nfp_port_get_eth_port(port);
if (!eth_port) {
eth_hw_addr_random(port->netdev);
eth_hw_addr_random(netdev);
return;
}
ether_addr_copy(port->netdev->dev_addr, eth_port->mac_addr);
ether_addr_copy(port->netdev->perm_addr, eth_port->mac_addr);
ether_addr_copy(netdev->dev_addr, eth_port->mac_addr);
ether_addr_copy(netdev->perm_addr, eth_port->mac_addr);
}
static struct nfp_eth_table_port *
......@@ -511,6 +514,7 @@ static int nfp_net_pci_map_mem(struct nfp_pf *pf)
return PTR_ERR(mem);
}
if (pf->eth_tbl) {
min_size = NFP_MAC_STATS_SIZE * (pf->eth_tbl->max_index + 1);
pf->mac_stats_mem = nfp_rtsym_map(pf->rtbl, "_mac_stats",
"net.macstats", min_size,
......@@ -522,6 +526,7 @@ static int nfp_net_pci_map_mem(struct nfp_pf *pf)
}
pf->mac_stats_mem = NULL;
}
}
pf->vf_cfg_mem = nfp_net_pf_map_rtsym(pf, "net.vfcfg",
"_pf%d_net_vf_bar",
......
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