The videocore part of the raspberry pi that boots the system and runs
the mailbox interface and other functions afterwards knows about a MAC
address that appears to be derived from a portion of a unique serial
number along with the raspberry pi foundation oui

B827EB     (base 16)            Raspberry Pi Foundation

It modifies the device tree when booting to store the MAC address
in /axi/usb/hub/ethernet/mac-address so fetch and use that value
for the integrated smsc(4) Ethernet.

A different smsc adapter plugged into one of the USB ports
probes later and skips this path.

Index: if_smsc.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/if_smsc.c,v
retrieving revision 1.29
diff -u -p -r1.29 if_smsc.c
--- if_smsc.c   22 Jan 2017 10:17:39 -0000      1.29
+++ if_smsc.c   7 Feb 2017 02:51:13 -0000
@@ -176,6 +176,32 @@ const struct cfattach smsc_ca = {
        sizeof(struct smsc_softc), smsc_match, smsc_attach, smsc_detach,
 };
 
+#if defined(__arm__) || defined(__arm64__)
+
+#include <dev/ofw/openfirm.h>
+
+void
+smsc_enaddr_OF(struct smsc_softc *sc)
+{
+       int node;
+
+       if (sc->sc_dev.dv_unit != 0)
+               return;
+
+       /*
+        * Get the Raspberry Pi MAC address from FDT
+        * also available via mailbox interface
+        */
+       if ((node = OF_finddevice("/axi/usb/hub/ethernet")) == -1)
+               return;
+
+       OF_getprop(node, "mac-address", sc->sc_ac.ac_enaddr,
+           sizeof(sc->sc_ac.ac_enaddr));
+}
+#else
+#define smsc_enaddr_OF(x) do {} while(0)
+#endif
+
 int
 smsc_read_reg(struct smsc_softc *sc, uint32_t off, uint32_t *data)
 {
@@ -993,6 +1019,8 @@ smsc_attach(struct device *parent, struc
                sc->sc_ac.ac_enaddr[1] = (uint8_t)((mac_l >> 8) & 0xff);
                sc->sc_ac.ac_enaddr[0] = (uint8_t)((mac_l) & 0xff);
        }
+
+       smsc_enaddr_OF(sc);
        
        printf("%s: address %s\n", sc->sc_dev.dv_xname,
            ether_sprintf(sc->sc_ac.ac_enaddr));

Reply via email to