Hi,

now as u-boot env is more likely to be found in the FAT by default[0],
i presume there will be more use for this, so that things work
consistently across all ethernet drivers(except if_dwxe) on armv7.

just reading what might be set in the registers already doesn't really
work out consistently, as it might not get set out of the box without
messing with u-boot distro_defaults, since efi payload does get run
before dhcp/pxeboot or whatever; ie. the usual case to get things set
w/o touching individual environment variables is to run the dhcp command
on u-boot prompt.

diff w/intention to be minimal.
-Artturi

[0] https://patchwork.ozlabs.org/cover/842057/


diff --git a/sys/arch/armv7/sunxi/sxie.c b/sys/arch/armv7/sunxi/sxie.c
index 116fda5f8d7..f4c6f8b1ca0 100644
--- a/sys/arch/armv7/sunxi/sxie.c
+++ b/sys/arch/armv7/sunxi/sxie.c
@@ -173,7 +173,7 @@ struct sxie_softc *sxie_sc;
 int    sxie_match(struct device *, void *, void *);
 void   sxie_attach(struct device *, struct device *, void *);
 void   sxie_setup_interface(struct sxie_softc *, struct device *);
-void   sxie_socware_init(struct sxie_softc *);
+void   sxie_socware_init(struct sxie_softc *, int);
 int    sxie_ioctl(struct ifnet *, u_long, caddr_t);
 void   sxie_start(struct ifnet *);
 void   sxie_watchdog(struct ifnet *);
@@ -230,7 +230,7 @@ sxie_attach(struct device *parent, struct device *self, 
void *aux)
 
        clock_enable_all(faa->fa_node);
 
-       sxie_socware_init(sc);
+       sxie_socware_init(sc, faa->fa_node);
        sc->txf_inuse = 0;
 
        sc->sc_ih = arm_intr_establish_fdt(faa->fa_node, IPL_NET,
@@ -276,8 +276,9 @@ sxie_attach(struct device *parent, struct device *self, 
void *aux)
 }
 
 void
-sxie_socware_init(struct sxie_softc *sc)
+sxie_socware_init(struct sxie_softc *sc, int node)
 {
+       uint8_t *enaddr = &sc->sc_ac.ac_enaddr[0];
        int have_mac = 0;
        uint32_t reg;
 
@@ -287,12 +288,17 @@ sxie_socware_init(struct sxie_softc *sc)
        SXIWRITE4(sc, SXIE_INTCR, SXIE_INTR_DISABLE);
        SXISET4(sc, SXIE_INTSR, SXIE_INTR_CLEAR);
 
+       if (OF_getproplen(node, "local-mac-address") == ETHER_ADDR_LEN) {
+               OF_getprop(node, "local-mac-address", enaddr, ETHER_ADDR_LEN);
+               have_mac = 1;
+       }
+
        /*
         * If u-boot doesn't set emac, use the Security ID area
         * to generate a consistent MAC address of.
         */
        reg = SXIREAD4(sc, SXIE_MACA0);
-       if (reg != 0) {
+       if (!have_mac && reg != 0) {
                sc->sc_ac.ac_enaddr[3] = reg >> 16 & 0xff;
                sc->sc_ac.ac_enaddr[4] = reg >> 8 & 0xff;
                sc->sc_ac.ac_enaddr[5] = reg & 0xff;
diff --git a/sys/dev/fdt/if_dwge_fdt.c b/sys/dev/fdt/if_dwge_fdt.c
index edfe5acb992..bca2cee2f72 100644
--- a/sys/dev/fdt/if_dwge_fdt.c
+++ b/sys/dev/fdt/if_dwge_fdt.c
@@ -87,6 +87,7 @@ dwge_fdt_attach(struct device *parent, struct device *self, 
void *aux)
        struct dwge_fdt_softc *fsc = (struct dwge_fdt_softc *)self;
        struct dwc_gmac_softc *sc = &fsc->sc_core;
        struct fdt_attach_args *faa = aux;
+       uint8_t *enaddr = &sc->sc_ac.ac_enaddr[0];
        int phyloc = MII_PHY_ANY;
        uint32_t phy_supply;
        uint32_t phy;
@@ -145,6 +146,12 @@ dwge_fdt_attach(struct device *parent, struct device 
*self, void *aux)
                goto clrpwr;
        }
 
+       /* Setup lladdr here, if we have one, to keep fdt out of dwc_gmac */
+       if (OF_getproplen(node, "local-mac-address") == ETHER_ADDR_LEN) {
+               OF_getprop(node, "local-mac-address", enaddr, ETHER_ADDR_LEN);
+               dwc_gmac_write_hwaddr(sc, enaddr);
+       }
+
        dwc_gmac_attach(sc, GMAC_MII_CLK_150_250M_DIV102, phyloc);
 
        return;
diff --git a/sys/dev/ic/dwc_gmac_var.h b/sys/dev/ic/dwc_gmac_var.h
index c2b3ce97e92..517bae968f7 100644
--- a/sys/dev/ic/dwc_gmac_var.h
+++ b/sys/dev/ic/dwc_gmac_var.h
@@ -94,3 +94,4 @@ struct dwc_gmac_softc {
 
 void dwc_gmac_attach(struct dwc_gmac_softc*, uint32_t, int);
 int dwc_gmac_intr(struct dwc_gmac_softc*);
+void dwc_gmac_write_hwaddr(struct dwc_gmac_softc *, uint8_t *);

Reply via email to