diff mbox series

[linux,dev-6.5] net: ftgmac100: support getting MAC address from NVMEM

Message ID 20231108215050.11121-2-zev@bewilderbeest.net
State New
Headers show
Series [linux,dev-6.5] net: ftgmac100: support getting MAC address from NVMEM | expand

Commit Message

Zev Weiss Nov. 8, 2023, 9:50 p.m. UTC
From: Paul Fertser <fercerpav@gmail.com>

Make use of of_get_ethdev_address() to support reading MAC address not
only from the usual DT nodes but also from an NVMEM provider (e.g. using
a dedicated area in an FRU EEPROM).

Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Link: https://lore.kernel.org/r/20230713095743.30517-1-fercerpav@gmail.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
(cherry picked from commit 2cee73cef253a333c7d48a0f8edda53e3cca990c)
---
 drivers/net/ethernet/faraday/ftgmac100.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

Comments

Joel Stanley Nov. 10, 2023, 2:41 a.m. UTC | #1
On Thu, 9 Nov 2023 at 08:21, Zev Weiss <zev@bewilderbeest.net> wrote:
>
> From: Paul Fertser <fercerpav@gmail.com>
>
> Make use of of_get_ethdev_address() to support reading MAC address not
> only from the usual DT nodes but also from an NVMEM provider (e.g. using
> a dedicated area in an FRU EEPROM).
>
> Signed-off-by: Paul Fertser <fercerpav@gmail.com>
> Link: https://lore.kernel.org/r/20230713095743.30517-1-fercerpav@gmail.com
> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
> (cherry picked from commit 2cee73cef253a333c7d48a0f8edda53e3cca990c)

I didn't know the kernel had code to do this. Very neat.

Applied to dev-6.5.
diff mbox series

Patch

diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
index 0e7fd1a6299f..27d2e2311bad 100644
--- a/drivers/net/ethernet/faraday/ftgmac100.c
+++ b/drivers/net/ethernet/faraday/ftgmac100.c
@@ -177,16 +177,20 @@  static void ftgmac100_write_mac_addr(struct ftgmac100 *priv, const u8 *mac)
 	iowrite32(laddr, priv->base + FTGMAC100_OFFSET_MAC_LADR);
 }
 
-static void ftgmac100_initial_mac(struct ftgmac100 *priv)
+static int ftgmac100_initial_mac(struct ftgmac100 *priv)
 {
 	u8 mac[ETH_ALEN];
 	unsigned int m;
 	unsigned int l;
+	int err;
 
-	if (!device_get_ethdev_address(priv->dev, priv->netdev)) {
+	err = of_get_ethdev_address(priv->dev->of_node, priv->netdev);
+	if (err == -EPROBE_DEFER)
+		return err;
+	if (!err) {
 		dev_info(priv->dev, "Read MAC address %pM from device tree\n",
 			 priv->netdev->dev_addr);
-		return;
+		return 0;
 	}
 
 	m = ioread32(priv->base + FTGMAC100_OFFSET_MAC_MADR);
@@ -207,6 +211,8 @@  static void ftgmac100_initial_mac(struct ftgmac100 *priv)
 		dev_info(priv->dev, "Generated random MAC address %pM\n",
 			 priv->netdev->dev_addr);
 	}
+
+	return 0;
 }
 
 static int ftgmac100_set_mac_addr(struct net_device *dev, void *p)
@@ -1853,7 +1859,9 @@  static int ftgmac100_probe(struct platform_device *pdev)
 	priv->aneg_pause = true;
 
 	/* MAC address from chip or random one */
-	ftgmac100_initial_mac(priv);
+	err = ftgmac100_initial_mac(priv);
+	if (err)
+		goto err_phy_connect;
 
 	np = pdev->dev.of_node;
 	if (np && (of_device_is_compatible(np, "aspeed,ast2400-mac") ||