From 49b2a5fedead582961b4e9de6ca87e07dff04769 Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Thu, 24 May 2018 16:34:06 +0000 Subject: [PATCH] if_muge: Add LAN78xx family USB ids but attach only to LAN7800 This driver was developed for the LAN7800 and the register-compatible LAN7515 and has only been tested on those devices. Adding support for other members of the family should be straightforward, once we have devices to test. With this change the driver will probe but fail to attach due to the Chip ID check, but will leave a hint leading to the driver that needs work. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D15537 --- sys/dev/usb/net/if_muge.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/sys/dev/usb/net/if_muge.c b/sys/dev/usb/net/if_muge.c index 9916d7726eb..b48d0b7cdd3 100644 --- a/sys/dev/usb/net/if_muge.c +++ b/sys/dev/usb/net/if_muge.c @@ -122,6 +122,8 @@ SYSCTL_INT(_hw_usb_muge, OID_AUTO, debug, CTLFLAG_RWTUN, &muge_debug, 0, static const struct usb_device_id lan78xx_devs[] = { #define MUGE_DEV(p,i) { USB_VPI(USB_VENDOR_SMC2, USB_PRODUCT_SMC2_##p, i) } MUGE_DEV(LAN7800_ETH, 0), + MUGE_DEV(LAN7801_ETH, 0), + MUGE_DEV(LAN7850_ETH, 0), #undef MUGE_DEV }; @@ -174,7 +176,8 @@ struct muge_softc { uint32_t sc_pfilter_table[MUGE_NUM_PFILTER_ADDRS_][2]; uint32_t sc_flags; -#define MUGE_FLAG_LINK 0x0001 +#define MUGE_FLAG_LINK 0x0001 +#define MUGE_FLAG_INIT_DONE 0x0002 }; #define MUGE_IFACE_IDX 0 @@ -1125,6 +1128,7 @@ lan78xx_chip_init(struct muge_softc *sc) buf |= ETH_FCT_TX_CTL_EN_; err = lan78xx_write_reg(sc, ETH_FCT_RX_CTL, buf); + sc->sc_flags |= MUGE_FLAG_INIT_DONE; return (0); init_failed: @@ -2116,7 +2120,7 @@ muge_attach(device_t dev) muge_config, MUGE_N_TRANSFER, sc, &sc->sc_mtx); if (err) { device_printf(dev, "error: allocating USB transfers failed\n"); - goto detach; + goto err; } ue->ue_sc = sc; @@ -2128,12 +2132,22 @@ muge_attach(device_t dev) err = uether_ifattach(ue); if (err) { device_printf(dev, "error: could not attach interface\n"); - goto detach; + goto err_usbd; } + + /* Wait for lan78xx_chip_init from post-attach callback to complete. */ + uether_ifattach_wait(ue); + if (!(sc->sc_flags & MUGE_FLAG_INIT_DONE)) + goto err_attached; + return (0); -detach: - muge_detach(dev); +err_attached: + uether_ifdetach(ue); +err_usbd: + usbd_transfer_unsetup(sc->sc_xfer, MUGE_N_TRANSFER); +err: + mtx_destroy(&sc->sc_mtx); return (ENXIO); }