Skip to content

Commit c55ca68

Browse files
Jakub Kicinskidavem330
authored andcommitted
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: a595018 ("nfp: map mac_stats and vf_cfg BARs") Fixes: 93da7d9 ("nfp: provide nfp_port to of nfp_net_get_mac_addr()") Signed-off-by: Jakub Kicinski <[email protected]> Reviewed-by: Dirk van der Merwe <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7dbc73e commit c55ca68

File tree

4 files changed

+23
-16
lines changed

4 files changed

+23
-16
lines changed

drivers/net/ethernet/netronome/nfp/flower/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ nfp_flower_spawn_phy_reprs(struct nfp_app *app, struct nfp_flower_priv *priv)
360360
}
361361

362362
SET_NETDEV_DEV(repr, &priv->nn->pdev->dev);
363-
nfp_net_get_mac_addr(app->pf, port);
363+
nfp_net_get_mac_addr(app->pf, repr, port);
364364

365365
cmsg_port_id = nfp_flower_cmsg_phys_port(phys_port);
366366
err = nfp_repr_init(app, repr,

drivers/net/ethernet/netronome/nfp/nfp_app_nic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ int nfp_app_nic_vnic_alloc(struct nfp_app *app, struct nfp_net *nn,
6969
if (err)
7070
return err < 0 ? err : 0;
7171

72-
nfp_net_get_mac_addr(app->pf, nn->port);
72+
nfp_net_get_mac_addr(app->pf, nn->dp.netdev, nn->port);
7373

7474
return 0;
7575
}

drivers/net/ethernet/netronome/nfp/nfp_main.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,9 @@ void nfp_net_pci_remove(struct nfp_pf *pf);
171171
int nfp_hwmon_register(struct nfp_pf *pf);
172172
void nfp_hwmon_unregister(struct nfp_pf *pf);
173173

174-
void nfp_net_get_mac_addr(struct nfp_pf *pf, struct nfp_port *port);
174+
void
175+
nfp_net_get_mac_addr(struct nfp_pf *pf, struct net_device *netdev,
176+
struct nfp_port *port);
175177

176178
bool nfp_ctrl_tx(struct nfp_net *nn, struct sk_buff *skb);
177179

drivers/net/ethernet/netronome/nfp/nfp_net_main.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,26 @@
6767
/**
6868
* nfp_net_get_mac_addr() - Get the MAC address.
6969
* @pf: NFP PF handle
70+
* @netdev: net_device to set MAC address on
7071
* @port: NFP port structure
7172
*
7273
* First try to get the MAC address from NSP ETH table. If that
7374
* fails generate a random address.
7475
*/
75-
void nfp_net_get_mac_addr(struct nfp_pf *pf, struct nfp_port *port)
76+
void
77+
nfp_net_get_mac_addr(struct nfp_pf *pf, struct net_device *netdev,
78+
struct nfp_port *port)
7679
{
7780
struct nfp_eth_table_port *eth_port;
7881

7982
eth_port = __nfp_port_get_eth_port(port);
8083
if (!eth_port) {
81-
eth_hw_addr_random(port->netdev);
84+
eth_hw_addr_random(netdev);
8285
return;
8386
}
8487

85-
ether_addr_copy(port->netdev->dev_addr, eth_port->mac_addr);
86-
ether_addr_copy(port->netdev->perm_addr, eth_port->mac_addr);
88+
ether_addr_copy(netdev->dev_addr, eth_port->mac_addr);
89+
ether_addr_copy(netdev->perm_addr, eth_port->mac_addr);
8790
}
8891

8992
static struct nfp_eth_table_port *
@@ -511,16 +514,18 @@ static int nfp_net_pci_map_mem(struct nfp_pf *pf)
511514
return PTR_ERR(mem);
512515
}
513516

514-
min_size = NFP_MAC_STATS_SIZE * (pf->eth_tbl->max_index + 1);
515-
pf->mac_stats_mem = nfp_rtsym_map(pf->rtbl, "_mac_stats",
516-
"net.macstats", min_size,
517-
&pf->mac_stats_bar);
518-
if (IS_ERR(pf->mac_stats_mem)) {
519-
if (PTR_ERR(pf->mac_stats_mem) != -ENOENT) {
520-
err = PTR_ERR(pf->mac_stats_mem);
521-
goto err_unmap_ctrl;
517+
if (pf->eth_tbl) {
518+
min_size = NFP_MAC_STATS_SIZE * (pf->eth_tbl->max_index + 1);
519+
pf->mac_stats_mem = nfp_rtsym_map(pf->rtbl, "_mac_stats",
520+
"net.macstats", min_size,
521+
&pf->mac_stats_bar);
522+
if (IS_ERR(pf->mac_stats_mem)) {
523+
if (PTR_ERR(pf->mac_stats_mem) != -ENOENT) {
524+
err = PTR_ERR(pf->mac_stats_mem);
525+
goto err_unmap_ctrl;
526+
}
527+
pf->mac_stats_mem = NULL;
522528
}
523-
pf->mac_stats_mem = NULL;
524529
}
525530

526531
pf->vf_cfg_mem = nfp_net_pf_map_rtsym(pf, "net.vfcfg",

0 commit comments

Comments
 (0)