Commit f4693b81 authored by Sergei Antonov's avatar Sergei Antonov Committed by Jakub Kicinski

net: moxa: MAC address reading, generating, validity checking

This device does not remember its MAC address, so add a possibility
to get it from the platform. If it fails, generate a random address.
This will provide a MAC address early during boot without user space
being involved.

Also remove extra calls to is_valid_ether_addr().

Made after suggestions by Andrew Lunn:
1) Use eth_hw_addr_random() to assign a random MAC address during probe.
2) Remove is_valid_ether_addr() from moxart_mac_open()
3) Add a call to platform_get_ethdev_address() during probe
4) Remove is_valid_ether_addr() from moxart_set_mac_address(). The core does this

v1 -> v2:
Handle EPROBE_DEFER returned from platform_get_ethdev_address().
Move MAC reading code to the beginning of the probe function.
Signed-off-by: default avatarSergei Antonov <saproj@gmail.com>
Suggested-by: default avatarAndrew Lunn <andrew@lunn.ch>
CC: Yang Yingliang <yangyingliang@huawei.com>
CC: Pavel Skripkin <paskripkin@gmail.com>
CC: Guobin Huang <huangguobin4@huawei.com>
CC: Yang Wei <yang.wei9@zte.com.cn>
CC: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
Reviewed-by: default avatarVladimir Oltean <olteanv@gmail.com>
Link: https://lore.kernel.org/r/20220818092317.529557-1-saproj@gmail.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 267ef48e
......@@ -62,9 +62,6 @@ static int moxart_set_mac_address(struct net_device *ndev, void *addr)
{
struct sockaddr *address = addr;
if (!is_valid_ether_addr(address->sa_data))
return -EADDRNOTAVAIL;
eth_hw_addr_set(ndev, address->sa_data);
moxart_update_mac_address(ndev);
......@@ -172,9 +169,6 @@ static int moxart_mac_open(struct net_device *ndev)
{
struct moxart_mac_priv_t *priv = netdev_priv(ndev);
if (!is_valid_ether_addr(ndev->dev_addr))
return -EADDRNOTAVAIL;
napi_enable(&priv->napi);
moxart_mac_reset(ndev);
......@@ -488,6 +482,13 @@ static int moxart_mac_probe(struct platform_device *pdev)
}
ndev->base_addr = res->start;
ret = platform_get_ethdev_address(p_dev, ndev);
if (ret == -EPROBE_DEFER)
goto init_fail;
if (ret)
eth_hw_addr_random(ndev);
moxart_update_mac_address(ndev);
spin_lock_init(&priv->txlock);
priv->tx_buf_size = TX_BUF_SIZE;
......
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