From a6eb469d8e7137a65a4eb813cb0aa80f50e5c812 Mon Sep 17 00:00:00 2001 From: Philip Paeps Date: Tue, 29 Dec 2009 14:00:17 +0000 Subject: [PATCH] Fix autonegotiation: tell the MAC where to find the PHY. Fix crashes in the detach path. Submitted by: Kristof Provost MFC after: 1 month --- sys/dev/mge/if_mge.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/sys/dev/mge/if_mge.c b/sys/dev/mge/if_mge.c index 0188ae3b79f..30d485ebd0c 100644 --- a/sys/dev/mge/if_mge.c +++ b/sys/dev/mge/if_mge.c @@ -611,6 +611,7 @@ static int mge_attach(device_t dev) { struct mge_softc *sc; + struct mii_softc *miisc; struct ifnet *ifp; uint8_t hwaddr[ETHER_ADDR_LEN]; int i, error ; @@ -689,13 +690,15 @@ mge_attach(device_t dev) error = mii_phy_probe(dev, &sc->miibus, mge_ifmedia_upd, mge_ifmedia_sts); if (error) { device_printf(dev, "MII failed to find PHY\n"); - if_free(ifp); - sc->ifp = NULL; mge_detach(dev); return (error); } sc->mii = device_get_softc(sc->miibus); + /* Tell the MAC where to find the PHY so autoneg works */ + miisc = LIST_FIRST(&sc->mii->mii_phys); + MGE_WRITE(sc, MGE_REG_PHYDEV, miisc->mii_phy); + /* Attach interrupt handlers */ for (i = 0; i < 2; ++i) { error = bus_setup_intr(dev, sc->res[1 + i], @@ -704,7 +707,7 @@ mge_attach(device_t dev) if (error) { device_printf(dev, "could not setup %s\n", mge_intrs[i].description); - ether_ifdetach(sc->ifp); + mge_detach(dev); return (error); } } @@ -729,6 +732,9 @@ mge_detach(device_t dev) /* Stop and release all interrupts */ for (i = 0; i < 2; ++i) { + if (!sc->ih_cookie[i]) + continue; + error = bus_teardown_intr(dev, sc->res[1 + i], sc->ih_cookie[i]); if (error) device_printf(dev, "could not release %s\n",