--- //depot/vendor/freebsd/src/sys/dev/hme/if_hme.c 2005/06/10 16:51:34 +++ //depot/user/jhb/acpipci/dev/hme/if_hme.c 2005/08/02 14:58:28 @@ -112,7 +112,6 @@ static int hme_mac_bitflip(struct hme_softc *, u_int32_t, u_int32_t, u_int32_t, u_int32_t); static void hme_mifinit(struct hme_softc *); -static void hme_reset(struct hme_softc *); static void hme_setladrf(struct hme_softc *, int); static int hme_mediachange(struct ifnet *); @@ -224,7 +223,7 @@ error = bus_dma_tag_create(sc->sc_pdmatag, 2048, 0, BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL, size, 1, BUS_SPACE_MAXSIZE_32BIT, BUS_DMA_ALLOCNOW, busdma_lock_mutex, - &Giant, &sc->sc_cdmatag); + &sc->sc_lock, &sc->sc_cdmatag); if (error) goto fail_ptag; @@ -301,9 +300,7 @@ ifp->if_snd.ifq_drv_maxlen = HME_NTXQ; IFQ_SET_READY(&ifp->if_snd); - HME_LOCK(sc); hme_mifinit(sc); - HME_UNLOCK(sc); if ((error = mii_phy_probe(sc->sc_dev, &sc->sc_miibus, hme_mediachange, hme_mediastatus)) != 0) { @@ -391,6 +388,7 @@ HME_LOCK(sc); hme_stop(sc); HME_UNLOCK(sc); + callout_drain(&sc->sc_tick_ch); device_delete_child(sc->sc_dev, sc->sc_miibus); for (i = 0; i < HME_NTXQ; i++) { @@ -447,24 +445,13 @@ hme_tick(void *arg) { struct hme_softc *sc = arg; - int s; - s = splnet(); - mii_tick(sc->sc_mii); - splx(s); + HME_LOCK(sc); + if (sc->sc_ifp->if_flags & IFF_RUNNING) { + mii_tick(sc->sc_mii); - callout_reset(&sc->sc_tick_ch, hz, hme_tick, sc); -} - -static void -hme_reset(struct hme_softc *sc) -{ - int s; - - HME_LOCK(sc); - s = splnet(); - hme_init_locked(sc); - splx(s); + callout_reset(&sc->sc_tick_ch, hz, hme_tick, sc); + } HME_UNLOCK(sc); } @@ -475,6 +462,7 @@ int n; callout_stop(&sc->sc_tick_ch); + sc->sc_ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE); /* Reset transmitter and receiver */ HME_SEB_WRITE_4(sc, HME_SEBI_RESET, HME_SEB_RESET_ETX | @@ -871,11 +859,7 @@ #endif /* Set the current media. */ - /* - * HME_UNLOCK(sc); - * mii_mediachg(sc->sc_mii); - * HME_LOCK(sc); - */ + mii_mediachg(sc->sc_mii); /* Start the one second timer. */ callout_reset(&sc->sc_tick_ch, hz, hme_tick, sc); @@ -1371,9 +1355,9 @@ #endif device_printf(sc->sc_dev, "device timeout\n"); ++ifp->if_oerrors; + + hme_init_locked(sc); HME_UNLOCK(sc); - - hme_reset(sc); } /* @@ -1384,8 +1368,6 @@ { u_int32_t v; - HME_LOCK_ASSERT(sc, MA_OWNED); - /* Configure the MIF in frame mode */ v = HME_MIF_READ_4(sc, HME_MIFI_CFG); v &= ~HME_MIF_CFG_BBMODE; @@ -1402,7 +1384,8 @@ int n; u_int32_t v; - HME_LOCK(sc); + if (sc->sc_ifp->if_input != NULL) + HME_LOCK_ASSERT(sc, MA_OWNED); /* Select the desired PHY in the MIF configuration register */ v = HME_MIF_READ_4(sc, HME_MIFI_CFG); /* Clear PHY select bit */ @@ -1424,13 +1407,11 @@ DELAY(1); v = HME_MIF_READ_4(sc, HME_MIFI_FO); if (v & HME_MIF_FO_TALSB) { - HME_UNLOCK(sc); return (v & HME_MIF_FO_DATA); } } device_printf(sc->sc_dev, "mii_read timeout\n"); - HME_UNLOCK(sc); return (0); } @@ -1441,7 +1422,8 @@ int n; u_int32_t v; - HME_LOCK(sc); + if (sc->sc_ifp->if_input != NULL) + HME_LOCK_ASSERT(sc, MA_OWNED); /* Select the desired PHY in the MIF configuration register */ v = HME_MIF_READ_4(sc, HME_MIFI_CFG); /* Clear PHY select bit */ @@ -1463,14 +1445,11 @@ for (n = 0; n < 100; n++) { DELAY(1); v = HME_MIF_READ_4(sc, HME_MIFI_FO); - if (v & HME_MIF_FO_TALSB) { - HME_UNLOCK(sc); + if (v & HME_MIF_FO_TALSB) return (1); - } } device_printf(sc->sc_dev, "mii_write timeout\n"); - HME_UNLOCK(sc); return (0); } @@ -1482,7 +1461,8 @@ int phy; u_int32_t v; - HME_LOCK(sc); + if (sc->sc_ifp->if_input != NULL) + HME_LOCK_ASSERT(sc, MA_OWNED); instance = IFM_INST(sc->sc_mii->mii_media.ifm_cur->ifm_media); phy = sc->sc_phys[instance]; #ifdef HMEDEBUG @@ -1499,28 +1479,27 @@ /* Set the MAC Full Duplex bit appropriately */ v = HME_MAC_READ_4(sc, HME_MACI_TXCFG); - if (!hme_mac_bitflip(sc, HME_MACI_TXCFG, v, HME_MAC_TXCFG_ENABLE, 0)) { - HME_UNLOCK(sc); + if (!hme_mac_bitflip(sc, HME_MACI_TXCFG, v, HME_MAC_TXCFG_ENABLE, 0)) return; - } if ((IFM_OPTIONS(sc->sc_mii->mii_media_active) & IFM_FDX) != 0) v |= HME_MAC_TXCFG_FULLDPLX; else v &= ~HME_MAC_TXCFG_FULLDPLX; HME_MAC_WRITE_4(sc, HME_MACI_TXCFG, v); - if (!hme_mac_bitflip(sc, HME_MACI_TXCFG, v, 0, HME_MAC_TXCFG_ENABLE)) { - HME_UNLOCK(sc); + if (!hme_mac_bitflip(sc, HME_MACI_TXCFG, v, 0, HME_MAC_TXCFG_ENABLE)) return; - } - HME_UNLOCK(sc); } static int hme_mediachange(struct ifnet *ifp) { struct hme_softc *sc = ifp->if_softc; + int error; - return (mii_mediachg(sc->sc_mii)); + HME_LOCK(sc); + error = mii_mediachg(sc->sc_mii); + HME_UNLOCK(sc); + return (error); } static void @@ -1534,9 +1513,7 @@ return; } - HME_UNLOCK(sc); mii_pollstat(sc->sc_mii); - HME_LOCK(sc); ifmr->ifm_active = sc->sc_mii->mii_media_active; ifmr->ifm_status = sc->sc_mii->mii_media_status; HME_UNLOCK(sc); @@ -1550,13 +1527,11 @@ { struct hme_softc *sc = ifp->if_softc; struct ifreq *ifr = (struct ifreq *)data; - int s, error = 0; + int error = 0; - HME_LOCK(sc); - s = splnet(); - switch (cmd) { case SIOCSIFFLAGS: + HME_LOCK(sc); if ((ifp->if_flags & IFF_UP) == 0 && (ifp->if_flags & IFF_RUNNING) != 0) { /* @@ -1564,7 +1539,6 @@ * stop it. */ hme_stop(sc); - ifp->if_flags &= ~IFF_RUNNING; } else if ((ifp->if_flags & IFF_UP) != 0 && (ifp->if_flags & IFF_RUNNING) == 0) { /* @@ -1588,35 +1562,34 @@ #ifdef HMEDEBUG sc->sc_debug = (ifp->if_flags & IFF_DEBUG) != 0 ? 1 : 0; #endif + HME_UNLOCK(sc); break; case SIOCADDMULTI: case SIOCDELMULTI: + HME_LOCK(sc); hme_setladrf(sc, 1); + HME_UNLOCK(sc); error = 0; break; case SIOCGIFMEDIA: case SIOCSIFMEDIA: - HME_UNLOCK(sc); error = ifmedia_ioctl(ifp, ifr, &sc->sc_mii->mii_media, cmd); - HME_LOCK(sc); break; case SIOCSIFCAP: + HME_LOCK(sc); ifp->if_capenable = ifr->ifr_reqcap; if ((ifp->if_capenable & IFCAP_TXCSUM) != 0) ifp->if_hwassist = sc->sc_csum_features; else ifp->if_hwassist = 0; + HME_UNLOCK(sc); break; default: - HME_UNLOCK(sc); error = ether_ioctl(ifp, cmd, data); - HME_LOCK(sc); break; } - splx(s); - HME_UNLOCK(sc); return (error); }