git: 351fad05e075 - main - if_eqos_starfive: Read MAC address from device tree

From: Mitchell Horne <mhorne_at_FreeBSD.org>
Date: Tue, 12 May 2026 14:00:42 UTC
The branch main has been updated by mhorne:

URL: https://cgit.FreeBSD.org/src/commit/?id=351fad05e075c388dece4cd6dd8613494b870bad

commit 351fad05e075c388dece4cd6dd8613494b870bad
Author:     Brian Scott <bscott@bunyatech.com.au>
AuthorDate: 2026-05-11 16:54:04 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2026-05-12 14:00:10 +0000

    if_eqos_starfive: Read MAC address from device tree
    
    u-boot/opensbi determines the ethernet MAC address from ROM and passes
    it to the OS in the device tree. This change sets the correct MAC
    address from this source. This prevents the eqos class driver from
    generating random MAC addresses at each boot.
    
    Tested on Starfive VisionFive 2, riscv64 SBC.
    
    Reviewed by:    mhorne
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D56782
---
 sys/dev/eqos/if_eqos_starfive.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/sys/dev/eqos/if_eqos_starfive.c b/sys/dev/eqos/if_eqos_starfive.c
index 62f8b3f38983..f81118fd3094 100644
--- a/sys/dev/eqos/if_eqos_starfive.c
+++ b/sys/dev/eqos/if_eqos_starfive.c
@@ -17,6 +17,7 @@
 #include <sys/socket.h>
 #include <machine/bus.h>
 
+#include <net/ethernet.h>
 #include <net/if.h>
 #include <net/if_media.h>
 #include <dev/mii/mii.h>
@@ -40,6 +41,7 @@
 #define JH7110_CSR_FREQ		198000000
 
 #define	WR4(sc, o, v) bus_write_4(sc->base.res[EQOS_RES_MEM], (o), (v))
+#define	RD4(sc, o)	bus_read_4(sc->base.res[EQOS_RES_MEM], (o))
 
 static const struct ofw_compat_data compat_data[] = {
 	{"starfive,jh7110-dwmac",	1},
@@ -131,6 +133,8 @@ if_eqos_starfive_init(device_t dev)
 	struct if_eqos_starfive_softc *sc = device_get_softc(dev);
 	hwreset_t rst_ahb, rst_stmmaceth;
 	phandle_t node;
+	uint8_t eaddr[ETHER_ADDR_LEN];
+	uint32_t maclo, machi;
 
 	node = ofw_bus_get_node(dev);
 
@@ -186,6 +190,14 @@ if_eqos_starfive_init(device_t dev)
 		return (ENXIO);
 	}
 
+	if (OF_getprop(node, "local-mac-address", eaddr, sizeof(eaddr)) ==
+	    sizeof(eaddr)) {
+		machi = eaddr[5] | (eaddr[4] << 8);
+		WR4(sc, GMAC_MAC_ADDRESS0_HIGH, machi);
+		maclo = eaddr[3] | (eaddr[2] << 8) | (eaddr[1] << 16) |
+		    (eaddr[0] << 24);
+		WR4(sc, GMAC_MAC_ADDRESS0_LOW, maclo);
+	}
 	return (0);
 }