From: kevlo Date: Wed, 15 Aug 2018 07:13:51 +0000 (+0000) Subject: Introduce mue_eeprom_present to check if the EEPROM is present. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=a20dd8f554d1b6b2f5e949cfbb48f5cd1cc22dbd;p=openbsd Introduce mue_eeprom_present to check if the EEPROM is present. When the EEPROM is not populated, set the MAC config register MUE_MAC_CR_AUTO_SPEED. While there, encode the MAC address for the onboard USB Ethernet for the Rasperry Pi, like smsc(4) does. --- diff --git a/sys/dev/usb/if_mue.c b/sys/dev/usb/if_mue.c index e943edcf27a..f4d6b9018ba 100644 --- a/sys/dev/usb/if_mue.c +++ b/sys/dev/usb/if_mue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_mue.c,v 1.3 2018/08/04 16:42:46 jsg Exp $ */ +/* $OpenBSD: if_mue.c,v 1.4 2018/08/15 07:13:51 kevlo Exp $ */ /* * Copyright (c) 2018 Kevin Lo @@ -139,6 +139,39 @@ void mue_tick_task(void *); #define MUE_CLRBIT(sc, reg, x) \ mue_csr_write(sc, reg, mue_csr_read(sc, reg) & ~(x)) +#if defined(__arm__) || defined(__arm64__) + +#include + +void +mue_enaddr_OF(struct mue_softc *sc) +{ + char *device = "/axi/usb/hub/ethernet"; + char prop[64]; + int node; + + if (sc->mue_dev.dv_unit != 0) + return; + + /* Get the Raspberry Pi MAC address from FDT. */ + if ((node = OF_finddevice("/aliases")) == -1) + return; + if (OF_getprop(node, "ethernet0", prop, sizeof(prop)) > 0 || + OF_getprop(node, "ethernet", prop, sizeof(prop)) > 0) + device = prop; + + if ((node = OF_finddevice(device)) == -1) + return; + if (OF_getprop(node, "local-mac-address", sc->arpcom.ac_enaddr, + sizeof(sc->arpcom.ac_enaddr)) != sizeof(sc->arpcom.ac_enaddr)) { + OF_getprop(node, "mac-address", sc->arpcom.ac_enaddr, + sizeof(sc->arpcom.ac_enaddr)); + } +} +#else +#define mue_enaddr_OF(x) do {} while(0) +#endif + uint32_t mue_csr_read(struct mue_softc *sc, uint32_t reg) { @@ -605,7 +638,7 @@ mue_chip_init(struct mue_softc *sc) if (sc->mue_product == USB_PRODUCT_SMC2_LAN7801) MUE_CLRBIT(sc, MUE_MAC_CR, MUE_MAC_CR_GMII_EN); - if (sc->mue_flags & LAN7500) { + if (sc->mue_flags & LAN7500 || !sc->mue_eeprom_present) { /* Allow MAC to detect speed and duplex from PHY. */ MUE_SETBIT(sc, MUE_MAC_CR, MUE_MAC_CR_AUTO_SPEED | MUE_MAC_CR_AUTO_DUPLEX); @@ -712,6 +745,10 @@ mue_attach(struct device *parent, struct device *self, void *aux) sc->mue_phyno = 1; + /* Check if the EEPROM programmed indicator is present. */ + mue_read_eeprom(sc, (caddr_t)&i, MUE_EE_IND_OFFSET, 1); + sc->mue_eeprom_present = (i == MUE_EEPROM_INDICATOR) ? 1 : 0; + if (mue_chip_init(sc) != 0) { printf("%s: chip initialization failed\n", sc->mue_dev.dv_xname); @@ -720,13 +757,16 @@ mue_attach(struct device *parent, struct device *self, void *aux) } /* Get station address from the EEPROM. */ - if (mue_read_eeprom(sc, (caddr_t)&sc->arpcom.ac_enaddr, - MUE_EE_MAC_OFFSET, ETHER_ADDR_LEN)) { - printf("%s: failed to read station address\n", - sc->mue_dev.dv_xname); - splx(s); - return; - } + if (sc->mue_eeprom_present) { + if (mue_read_eeprom(sc, (caddr_t)&sc->arpcom.ac_enaddr, + MUE_EE_MAC_OFFSET, ETHER_ADDR_LEN)) { + printf("%s: failed to read station address\n", + sc->mue_dev.dv_xname); + splx(s); + return; + } + } else + mue_enaddr_OF(sc); /* A Microchip chip was detected. Inform the world. */ printf("%s:", sc->mue_dev.dv_xname); diff --git a/sys/dev/usb/if_muereg.h b/sys/dev/usb/if_muereg.h index e547bf01bfd..b078ea178b4 100644 --- a/sys/dev/usb/if_muereg.h +++ b/sys/dev/usb/if_muereg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_muereg.h,v 1.1 2018/08/03 01:50:15 kevlo Exp $ */ +/* $OpenBSD: if_muereg.h,v 1.2 2018/08/15 07:13:51 kevlo Exp $ */ /* * Copyright (c) 2018 Kevin Lo @@ -25,6 +25,7 @@ /* * Offset of MAC address inside EEPROM. */ +#define MUE_EE_IND_OFFSET 0x00 #define MUE_EE_MAC_OFFSET 0x01 #define MUE_EE_LTM_OFFSET 0x3f @@ -167,6 +168,8 @@ #define MUE_MAX_BUFSZ 18944 #define MUE_MIN_BUFSZ 8256 +#define MUE_EEPROM_INDICATOR 0xa5 + /* * The interrupt endpoint is currently unused by the Moschip part. */ @@ -246,4 +249,5 @@ struct mue_softc { int mue_phyno; int mue_bufsz; int mue_link; + int mue_eeprom_present; };