diff options
| author | Brian Scott <bscott@bunyatech.com.au> | 2026-05-11 16:54:04 +0000 |
|---|---|---|
| committer | Mitchell Horne <mhorne@FreeBSD.org> | 2026-05-12 14:00:10 +0000 |
| commit | 351fad05e075c388dece4cd6dd8613494b870bad (patch) | |
| tree | 9856a843495a09e1593b465f56ee1c671797d2f8 | |
| parent | 23b263dfbf5ec24de2f6e1abc2a4eb04869b3e07 (diff) | |
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
| -rw-r--r-- | sys/dev/eqos/if_eqos_starfive.c | 12 |
1 files changed, 12 insertions, 0 deletions
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); } |
