From 20ea6dd5807b2d17cef5858966235c13909b5194 Mon Sep 17 00:00:00 2001 From: Bill Paul Date: Sun, 15 Jun 2003 21:45:43 +0000 Subject: [PATCH] In the device attach routine, don't depend on uaa->iface being populated. Apparently, if you use an ehci controller, it's not. Use usbd_device2interface_handle() to retrieve the interface handle. NOTE: uaa->iface is populated in the probe routine, so I suspect the fact that it's NULL in the attach routine is a bug in the ehci driver. Also, don't depend on the PHY addresses returned by the AXE_CMD_READ_PHYID command. The address is correct for my LinkSys NIC, but a user has reported that with a D-Link NIC, the PHYID command returns address 4 while the attached Broadcom PHY is in fact strapped for address 0. Instead, latch onto the first PHY address that returns valid data during a readreg operation. --- sys/dev/usb/if_axe.c | 27 +++++++++++++++++++++++---- sys/dev/usb/if_axereg.h | 1 + 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/sys/dev/usb/if_axe.c b/sys/dev/usb/if_axe.c index bb5db389b513..b31247ae91f3 100644 --- a/sys/dev/usb/if_axe.c +++ b/sys/dev/usb/if_axe.c @@ -213,6 +213,7 @@ axe_miibus_readreg(device_ptr_t dev, int phy, int reg) if (sc->axe_dying) return(0); +#ifdef notdef /* * The chip tells us the MII address of any supported * PHYs attached to the chip, so only read from those. @@ -223,6 +224,9 @@ axe_miibus_readreg(device_ptr_t dev, int phy, int reg) if (sc->axe_phyaddrs[1] != AXE_NOPHY && phy != sc->axe_phyaddrs[1]) return (0); +#endif + if (sc->axe_phyaddrs[0] != 0xFF && sc->axe_phyaddrs[0] != phy) + return (0); AXE_LOCK(sc); axe_cmd(sc, AXE_CMD_MII_OPMODE_SW, 0, 0, NULL); @@ -235,6 +239,9 @@ axe_miibus_readreg(device_ptr_t dev, int phy, int reg) return(-1); } + if (val) + sc->axe_phyaddrs[0] = phy; + return (val); } @@ -377,7 +384,7 @@ axe_reset(struct axe_softc *sc) return; if (usbd_set_config_no(sc->axe_udev, AXE_CONFIG_NO, 1) || - usbd_device2interface_handle(sc->axe_udev, 0 /*AXE_IFACE_IDX*/, + usbd_device2interface_handle(sc->axe_udev, AXE_IFACE_IDX, &sc->axe_iface)) { printf("axe%d: getting interface handle failed\n", sc->axe_unit); @@ -426,7 +433,6 @@ USB_ATTACH(axe) int i; bzero(sc, sizeof(struct axe_softc)); - sc->axe_iface = uaa->iface; sc->axe_udev = uaa->device; sc->axe_dev = self; sc->axe_unit = device_get_unit(self); @@ -437,7 +443,14 @@ USB_ATTACH(axe) USB_ATTACH_ERROR_RETURN; } - id = usbd_get_interface_descriptor(uaa->iface); + if (usbd_device2interface_handle(uaa->device, + AXE_IFACE_IDX, &sc->axe_iface)) { + printf("axe%d: getting interface handle failed\n", + sc->axe_unit); + USB_ATTACH_ERROR_RETURN; + } + + id = usbd_get_interface_descriptor(sc->axe_iface); usbd_devinfo(uaa->device, 0, devinfo); device_set_desc_copy(self, devinfo); @@ -445,7 +458,7 @@ USB_ATTACH(axe) /* Find endpoints. */ for (i = 0; i < id->bNumEndpoints; i++) { - ed = usbd_interface2endpoint_descriptor(uaa->iface, i); + ed = usbd_interface2endpoint_descriptor(sc->axe_iface, i); if (!ed) { printf("axe%d: couldn't get ep %d\n", sc->axe_unit, i); @@ -478,6 +491,12 @@ USB_ATTACH(axe) axe_cmd(sc, AXE_CMD_READ_IPG012, 0, 0, (void *)&sc->axe_ipgs); axe_cmd(sc, AXE_CMD_READ_PHYID, 0, 0, (void *)&sc->axe_phyaddrs); + /* + * Work around broken adapters that appear to lie about + * their PHY addresses. + */ + sc->axe_phyaddrs[0] = sc->axe_phyaddrs[1] = 0xFF; + /* * An ASIX chip was detected. Inform the world. */ diff --git a/sys/dev/usb/if_axereg.h b/sys/dev/usb/if_axereg.h index b293f043c07f..c880785e1ccf 100644 --- a/sys/dev/usb/if_axereg.h +++ b/sys/dev/usb/if_axereg.h @@ -105,6 +105,7 @@ #define AXE_CTL_WRITE 0x02 #define AXE_CONFIG_NO 1 +#define AXE_IFACE_IDX 0 /* * The interrupt endpoint is currently unused