[PATCH u-boot v2016.07-aspeed-openbmc] drivers: ftgmac100: use hardware MAC by default

Alexander Filippov a.filippov at yadro.com
Mon Aug 10 22:12:20 AEST 2020


During the network interface initialization in ast_g5_phy based
configurations the original hardware MAC address is ignored and the
actual value is filled with zeros until the appropriate environment
variable is set.
Probably, others PHY-based configurations are also affected.
For example: The MAC addresses specified in command line arguments for
qemu are ignored and all ethernet interfaces have randomly generated MAC
addresses.

This commit makes ftg100 driver to read the hardware MAC address during
device initialization and do not fill it with zeros if the environment
has no definitions for this interface.

Signed-off-by: Alexander Filippov <a.filippov at yadro.com>
---
 drivers/net/ftgmac100.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ftgmac100.c b/drivers/net/ftgmac100.c
index 5779057ba8..5aaad533e5 100644
--- a/drivers/net/ftgmac100.c
+++ b/drivers/net/ftgmac100.c
@@ -481,6 +481,23 @@ static void ftgmac100_set_mac(struct eth_device *dev,
 	__raw_writel(laddr, &ftgmac100->mac_ladr);
 }
 
+/*
+ * Get actual MAC address
+ */
+static void ftgmac100_get_hw_mac(struct eth_device *dev)
+{
+	struct ftgmac100 *ftgmac100 = (struct ftgmac100 *)dev->iobase;
+	unsigned int maddr = __raw_readl(&ftgmac100->mac_madr);
+	unsigned int laddr = __raw_readl(&ftgmac100->mac_ladr);
+
+	dev->enetaddr[0] = (maddr >>  8) & 0xFF;
+	dev->enetaddr[1] = (maddr >>  0) & 0xFF;
+	dev->enetaddr[2] = (laddr >> 24) & 0xFF;
+	dev->enetaddr[3] = (laddr >> 16) & 0xFF;
+	dev->enetaddr[4] = (laddr >>  8) & 0xFF;
+	dev->enetaddr[5] = (laddr >>  0) & 0xFF;
+}
+
 static void ftgmac100_set_mac_from_env(struct eth_device *dev)
 {
 #ifdef CONFIG_SYS_I2C_MAC_OFFSET
@@ -513,7 +530,9 @@ static void ftgmac100_set_mac_from_env(struct eth_device *dev)
 
 	ftgmac100_set_mac(dev, dev->enetaddr);
 #else
-	eth_getenv_enetaddr_by_index("eth", dev->index, dev->enetaddr);
+	unsigned char enetaddr[6];
+	if (eth_getenv_enetaddr_by_index("eth", dev->index, enetaddr))
+		memcpy(dev->enetaddr, enetaddr, sizeof(enetaddr));
 //	eth_getenv_enetaddr("ethaddr", dev->enetaddr);
 	ftgmac100_set_mac(dev, dev->enetaddr);
 #endif
@@ -794,6 +813,7 @@ int ftgmac100_initialize(bd_t *bd)
 		ftgmac100_reset(dev);
 
 		/* set the ethernet address */
+		ftgmac100_get_hw_mac(dev);
 		ftgmac100_set_mac_from_env(dev);
 
 		card_number++;
-- 
2.21.3



More information about the openbmc mailing list