Skip to content

Commit 1d6d537

Browse files
dangowrtdavem330
authored andcommitted
net: ethernet: mtk_eth_soc: handle probe deferral
Move the call to of_get_ethdev_address to mtk_add_mac which is part of the probe function and can hence itself return -EPROBE_DEFER should of_get_ethdev_address return -EPROBE_DEFER. This allows us to entirely get rid of the mtk_init function. The problem of of_get_ethdev_address returning -EPROBE_DEFER surfaced in situations in which the NVMEM provider holding the MAC address has not yet be loaded at the time mtk_eth_soc is initially probed. In this case probing of mtk_eth_soc should be deferred instead of falling back to use a random MAC address, so once the NVMEM provider becomes available probing can be repeated. Fixes: 656e705 ("net-next: mediatek: add support for MT7623 ethernet") Signed-off-by: Daniel Golle <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 56a1603 commit 1d6d537

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

drivers/net/ethernet/mediatek/mtk_eth_soc.c

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3846,23 +3846,6 @@ static int mtk_hw_deinit(struct mtk_eth *eth)
38463846
return 0;
38473847
}
38483848

3849-
static int __init mtk_init(struct net_device *dev)
3850-
{
3851-
struct mtk_mac *mac = netdev_priv(dev);
3852-
struct mtk_eth *eth = mac->hw;
3853-
int ret;
3854-
3855-
ret = of_get_ethdev_address(mac->of_node, dev);
3856-
if (ret) {
3857-
/* If the mac address is invalid, use random mac address */
3858-
eth_hw_addr_random(dev);
3859-
dev_err(eth->dev, "generated random MAC address %pM\n",
3860-
dev->dev_addr);
3861-
}
3862-
3863-
return 0;
3864-
}
3865-
38663849
static void mtk_uninit(struct net_device *dev)
38673850
{
38683851
struct mtk_mac *mac = netdev_priv(dev);
@@ -4278,7 +4261,6 @@ static const struct ethtool_ops mtk_ethtool_ops = {
42784261
};
42794262

42804263
static const struct net_device_ops mtk_netdev_ops = {
4281-
.ndo_init = mtk_init,
42824264
.ndo_uninit = mtk_uninit,
42834265
.ndo_open = mtk_open,
42844266
.ndo_stop = mtk_stop,
@@ -4340,6 +4322,17 @@ static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
43404322
mac->hw = eth;
43414323
mac->of_node = np;
43424324

4325+
err = of_get_ethdev_address(mac->of_node, eth->netdev[id]);
4326+
if (err == -EPROBE_DEFER)
4327+
return err;
4328+
4329+
if (err) {
4330+
/* If the mac address is invalid, use random mac address */
4331+
eth_hw_addr_random(eth->netdev[id]);
4332+
dev_err(eth->dev, "generated random MAC address %pM\n",
4333+
eth->netdev[id]->dev_addr);
4334+
}
4335+
43434336
memset(mac->hwlro_ip, 0, sizeof(mac->hwlro_ip));
43444337
mac->hwlro_ip_cnt = 0;
43454338

0 commit comments

Comments
 (0)