git: 9efa26959d3f - main - dwc: Use the MAC address from the device tree

From: Emmanuel Vadot <manu_at_FreeBSD.org>
Date: Fri, 20 Nov 2026 13:55:49 UTC
The branch main has been updated by manu:

URL: https://cgit.FreeBSD.org/src/commit/?id=9efa26959d3fc29b104971329377f89729c17b74

commit 9efa26959d3fc29b104971329377f89729c17b74
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2026-10-20 15:30:48 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2026-11-20 13:55:22 +0000

    dwc: Use the MAC address from the device tree
    
    The bootloader usually sets the Ethernet address of the device in the
    device tree (mac-address or local-mac-address), but the driver only used the
    address read from the hardware, or a random one if there is none.
    
    Use fdt_ether_get_addr() right before attaching the interface, so the address
    from the device tree is preferred and the one from the hardware (or generated)
    remains the fallback.
    
    Differential Revision:  https://reviews.freebsd.org/D60916
---
 sys/dev/dwc/if_dwc.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/sys/dev/dwc/if_dwc.c b/sys/dev/dwc/if_dwc.c
index f0b32e1bf410..78216a5d14f6 100644
--- a/sys/dev/dwc/if_dwc.c
+++ b/sys/dev/dwc/if_dwc.c
@@ -67,6 +67,7 @@
 #include <dev/ofw/ofw_bus.h>
 #include <dev/ofw/ofw_bus_subr.h>
 #include <dev/mii/mii_fdt.h>
+#include <dev/fdt/fdt_common.h>
 
 #include <dev/dwc/if_dwcvar.h>
 #include <dev/dwc/dwc1000_core.h>
@@ -683,6 +684,12 @@ dwc_attach(device_t dev)
 	}
 	sc->mii_softc = device_get_softc(sc->miibus);
 
+	/*
+	 * Prefer the address from the device tree (set by the bootloader)
+	 * over the one read from the hardware or generated.
+	 */
+	fdt_ether_get_addr(sc->node, ifp, macaddr);
+
 	/* All ready to run, attach the ethernet interface. */
 	ether_ifattach(ifp, macaddr);
 	sc->is_attached = true;