Skip to contentSkip to conversation

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

PATCH Applied Sergei Antonov 4 participants 4 messages Aug 18, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 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.

CC Jakub Kicinski <[email protected]>
CC Vladimir Oltean <[email protected]>
CC Yang Yingliang <[email protected]>
CC Pavel Skripkin <[email protected]>
CC Guobin Huang <[email protected]>
CC Yang Wei <[email protected]>
CC Christophe JAILLET <[email protected]>
---
 drivers/net/ethernet/moxa/moxart_ether.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/net/ethernet/moxa/moxart_ether.c +8 -6
index f11f1cb92025..402fea7505e6 100644
@@ -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,14 @@ static int moxart_mac_probe(struct platform_device *pdev)
 	}
 	ndev->base_addr = res->start;
 
+	// MAC address
+	ret = platform_get_ethdev_address(p_dev, ndev);
+	if (ret == -EPROBE_DEFER) // EEPROM has not probed yet?
+		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;
Signature · 1 line
2.32.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 13 lines · Sergei Antonov

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

Quoted 6 lines

v1 -> v2:
Handle EPROBE_DEFER returned from platform_get_ethdev_address(). Move MAC reading code to the beginning of the probe function.

Andrew

Reviewed-by on v2 1/1
#2 lore raw
In reply to Sergei Antonov
Quoted 55 lines · Sergei Antonov

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.

CC Jakub Kicinski <[email protected]>
CC Vladimir Oltean <[email protected]>
CC Yang Yingliang <[email protected]>
CC Pavel Skripkin <[email protected]>
CC Guobin Huang <[email protected]>
CC Yang Wei <[email protected]>
CC Christophe JAILLET <[email protected]>
---
 drivers/net/ethernet/moxa/moxart_ether.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/net/ethernet/moxa/moxart_ether.c +0 -6
index f11f1cb92025..402fea7505e6 100644
@@ -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);

drivers/net/ethernet/moxa/moxart_ether.c static int moxart_mac_probe(struct platform_device *pdev) · line 488

Quoted 7 lines
drivers/net/ethernet/moxa/moxart_ether.c +4 -0
@@ -488,6 +482,14 @@ static int moxart_mac_probe(struct platform_device *pdev)
 	}
 	ndev->base_addr = res->start;
 
+	// MAC address
+	ret = platform_get_ethdev_address(p_dev, ndev);
+	if (ret == -EPROBE_DEFER) // EEPROM has not probed yet?
+		goto init_fail;

The comments are not very useful, and the kernel coding style is to use the C-style comments /* */ rather than the C++ style //. Anyway this is a minor remark, I don't think you have to resend for this.

Quoted 10 lines
drivers/net/ethernet/moxa/moxart_ether.c +4 -0
+	if (ret)
+		eth_hw_addr_random(ndev);
+	moxart_update_mac_address(ndev);
+
 	spin_lock_init(&priv->txlock);
 
 	priv->tx_buf_size = TX_BUF_SIZE;
Signature · 1 line
2.32.0
#3 lore raw
In reply to Sergei Antonov
This patch was applied to netdev/net.git (master) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (master)
by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Thu, 18 Aug 2022 12:23:17 +0300 you wrote:

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().

[...]

Here is the summary with links:
- [v2] net: moxa: MAC address reading, generating, validity checking

    https://git.kernel.org/netdev/net/c/f4693b81ea38

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html