From owner-p4-projects@FreeBSD.ORG Sat Jun 9 02:57:24 2007 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 9CCE616A46B; Sat, 9 Jun 2007 02:57:24 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 6FD5516A41F for ; Sat, 9 Jun 2007 02:57:24 +0000 (UTC) (envelope-from thompsa@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.freebsd.org (Postfix) with ESMTP id 5BEBE13C45D for ; Sat, 9 Jun 2007 02:57:24 +0000 (UTC) (envelope-from thompsa@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.8/8.13.8) with ESMTP id l592vOw4032374 for ; Sat, 9 Jun 2007 02:57:24 GMT (envelope-from thompsa@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.8/8.13.8/Submit) id l592vNRA032365 for perforce@freebsd.org; Sat, 9 Jun 2007 02:57:23 GMT (envelope-from thompsa@freebsd.org) Date: Sat, 9 Jun 2007 02:57:23 GMT Message-Id: <200706090257.l592vNRA032365@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to thompsa@freebsd.org using -f From: Andrew Thompson To: Perforce Change Reviews Cc: Subject: PERFORCE change 121244 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 09 Jun 2007 02:57:24 -0000 http://perforce.freebsd.org/chv.cgi?CH=121244 Change 121244 by thompsa@thompsa_heff on 2007/06/09 02:56:50 Use a proper mtx_assert instead of a debug printf and improve the locking. Affected files ... .. //depot/projects/wifi/sys/dev/iwi/if_iwi.c#42 edit .. //depot/projects/wifi/sys/dev/iwi/if_iwivar.h#17 edit Differences ... ==== //depot/projects/wifi/sys/dev/iwi/if_iwi.c#42 (text+ko) ==== @@ -452,9 +452,12 @@ struct iwi_softc *sc = device_get_softc(dev); struct ieee80211com *ic = &sc->sc_ic; struct ifnet *ifp = ic->ic_ifp; + IWI_LOCK_DECL; if (ifp != NULL) { + IWI_LOCK(sc); iwi_stop(sc); + IWI_UNLOCK(sc); bpfdetach(ifp); ieee80211_ifdetach(ic); } @@ -794,8 +797,11 @@ iwi_shutdown(device_t dev) { struct iwi_softc *sc = device_get_softc(dev); + IWI_LOCK_DECL; + IWI_LOCK(sc); iwi_stop(sc); + IWI_UNLOCK(sc); iwi_put_firmware(sc); /* ??? XXX */ return 0; @@ -805,8 +811,11 @@ iwi_suspend(device_t dev) { struct iwi_softc *sc = device_get_softc(dev); + IWI_LOCK_DECL; + IWI_LOCK(sc); iwi_stop(sc); + IWI_UNLOCK(sc); return 0; } @@ -938,7 +947,7 @@ struct iwi_softc *sc = ifp->if_softc; int error = 0; - IWI_LOCK_CHECK(sc); + IWI_LOCK_ASSERT(sc); DPRINTF(("%s: %s -> %s flags 0x%x\n", __func__, ieee80211_state_name[ic->ic_state], ieee80211_state_name[nstate], sc->flags)); @@ -1661,7 +1670,7 @@ { struct iwi_cmd_desc *desc; - IWI_LOCK_CHECK(sc); + IWI_LOCK_ASSERT(sc); if (sc->flags & IWI_FLAG_BUSY) { device_printf(sc->sc_dev, "%s: cmd %d not sent, busy\n", @@ -1725,7 +1734,7 @@ int error, nsegs, hdrlen, i; int ismcast, flags, xflags, staid; - IWI_LOCK_CHECK(sc); + IWI_LOCK_ASSERT(sc); wh = mtod(m0, const struct ieee80211_frame *); /* NB: only data frames use this path */ hdrlen = ieee80211_hdrsize(wh); @@ -1967,7 +1976,7 @@ struct iwi_softc *sc = arg; struct ifnet *ifp = sc->sc_ifp; - IWI_LOCK_CHECK(sc); + IWI_LOCK_ASSERT(sc); if (sc->sc_tx_timer > 0) { if (--sc->sc_tx_timer == 0) { @@ -2062,8 +2071,6 @@ uint32_t tmp; int ntries; - IWI_LOCK_CHECK(sc); - /* disable interrupts */ CSR_WRITE_4(sc, IWI_CSR_INTR_MASK, 0); @@ -2330,7 +2337,7 @@ size_t size = fw->size; int i, ntries, error; - IWI_LOCK_CHECK(sc); + IWI_LOCK_ASSERT(sc); error = 0; CSR_WRITE_4(sc, IWI_CSR_RST, CSR_READ_4(sc, IWI_CSR_RST) | IWI_RST_STOP_MASTER); @@ -2403,7 +2410,7 @@ uint32_t sentinel, ctl, src, dst, sum, len, mlen, tmp; int ntries, error; - IWI_LOCK_CHECK(sc); + IWI_LOCK_ASSERT(sc); /* copy firmware image to DMA memory */ memcpy(sc->fw_virtaddr, fw->data, fw->size); @@ -2545,7 +2552,7 @@ struct iwi_txpower power; uint32_t data; int error, i; - IWI_LOCK_CHECK(sc); + IWI_LOCK_ASSERT(sc); IEEE80211_ADDR_COPY(ic->ic_myaddr, IF_LLADDR(ifp)); DPRINTF(("Setting MAC address to %6D\n", ic->ic_myaddr, ":")); @@ -2694,7 +2701,7 @@ struct iwi_scan_ext scan; int error = 0; - IWI_LOCK_CHECK(sc); + IWI_LOCK_ASSERT(sc); if (sc->flags & IWI_FLAG_SCANNING) { /* * This should not happen as we only trigger scan_next after @@ -2828,10 +2835,9 @@ int error; IWI_LOCK_DECL; - IWI_LOCK_CHECK(sc); + IWI_LOCK_ASSERT(sc); error = 0; - IWI_LOCK(sc); if (IEEE80211_IS_CHAN_2GHZ(ic->ic_curchan)) { memset(&config, 0, sizeof config); config.bluetooth_coexistence = sc->bluetooth; @@ -3079,7 +3085,7 @@ int i; IWI_LOCK_DECL; - IWI_LOCK_CHECK(sc); + IWI_LOCK_ASSERT(sc); if (sc->flags & IWI_FLAG_FW_LOADING) { device_printf(sc->sc_dev, "%s: already loading\n", __func__); return; /* XXX: condvar? */ @@ -3198,7 +3204,7 @@ struct ieee80211com *ic = &sc->sc_ic; struct ifnet *ifp = ic->ic_ifp; - IWI_LOCK_CHECK(sc); /* XXX: pretty sure this triggers */ + IWI_LOCK_ASSERT(sc); if (sc->sc_softled) { callout_stop(&sc->sc_ledtimer); sc->sc_blinking = 0; @@ -3261,10 +3267,13 @@ iwi_radio_off(void *arg, int pending) { struct iwi_softc *sc = arg; + IWI_LOCK_DECL; device_printf(sc->sc_dev, "radio turned off\n"); + IWI_LOCK(sc); iwi_stop(sc); sc->sc_rfkill_timer = 2; + IWI_UNLOCK(sc); } static int ==== //depot/projects/wifi/sys/dev/iwi/if_iwivar.h#17 (text+ko) ==== @@ -246,10 +246,7 @@ MTX_NETWORK_LOCK, MTX_DEF) #define IWI_LOCK_DESTROY(sc) mtx_destroy(&(sc)->sc_mtx) #define IWI_LOCK_DECL int __waslocked = 0 -#define IWI_LOCK_CHECK(sc) do { \ - if (!mtx_owned(&(sc)->sc_mtx)) \ - DPRINTF(("%s iwi_lock not held\n", __func__)); \ -} while (0) +#define IWI_LOCK_ASSERT(sc) mtx_assert(&(sc)->sc_mtx, MA_OWNED) #define IWI_LOCK(sc) do { \ if (!(__waslocked = mtx_owned(&(sc)->sc_mtx))) \ mtx_lock(&(sc)->sc_mtx); \