From f5afa5f778459c2c117811ddf4a232cc29ba6edb Mon Sep 17 00:00:00 2001
From: Sascha Wildner <saw@online.de>
Date: Tue, 31 Aug 2010 21:25:03 +0200
Subject: [PATCH] Take back my previous commit and solve the LINT breakage otherwise.

To keep differences with FreeBSD minimal, keep the sc argument for the
locking macros and mark the one case as __unused where sc was declared
only for passing it to the macros (in wpi_start()).

Requested-by: josepht
---
 sys/dev/netif/wpi/if_wpi.c    |   84 +++++++++++++++++++++--------------------
 sys/dev/netif/wpi/if_wpivar.h |   10 ++--
 2 files changed, 48 insertions(+), 46 deletions(-)

diff --git a/sys/dev/netif/wpi/if_wpi.c b/sys/dev/netif/wpi/if_wpi.c
index 180d5c9..d691c3c 100644
--- a/sys/dev/netif/wpi/if_wpi.c
+++ b/sys/dev/netif/wpi/if_wpi.c
@@ -328,19 +328,19 @@ wpi_load_firmware(struct wpi_softc *sc)
 	DPRINTFN(WPI_DEBUG_FIRMWARE,
 	    ("Attempting Loading Firmware from wpi_fw module\n"));
 
-	WPI_UNLOCK();
+	WPI_UNLOCK(sc);
 
 	if (sc->fw_fp == NULL && (sc->fw_fp = firmware_get("wpifw")) == NULL) {
 		device_printf(sc->sc_dev,
 		    "could not load firmware image 'wpifw_fw'\n");
 		error = ENOENT;
-		WPI_LOCK();
+		WPI_LOCK(sc);
 		goto fail;
 	}
 
 	fp = sc->fw_fp;
 
-	WPI_LOCK();
+	WPI_LOCK(sc);
 
 
 	/* Validate the firmware is minimum a particular version */
@@ -484,9 +484,9 @@ wpi_unload_firmware(struct wpi_softc *sc)
 	ifp = sc->sc_ifp;
 
 	if (sc->fw_fp) {
-		WPI_UNLOCK();
+		WPI_UNLOCK(sc);
 		firmware_put(sc->fw_fp, FIRMWARE_UNLOAD);
-		WPI_LOCK();
+		WPI_LOCK(sc);
 		sc->fw_fp = NULL;
 	}
 }
@@ -524,7 +524,7 @@ wpi_attach(device_t dev)
 	TASK_INIT(&sc->sc_restarttask, 0, wpi_hwreset, sc);
 	TASK_INIT(&sc->sc_radiotask, 0, wpi_rfreset, sc);
 
-	WPI_LOCK_INIT();
+	WPI_LOCK_INIT(sc);
 
 	callout_init(&sc->calib_to);
 	callout_init(&sc->watchdog_to);
@@ -733,7 +733,7 @@ wpi_detach(device_t dev)
 		ieee80211_ifdetach(ic);
 	}
 
-	WPI_LOCK();
+	WPI_LOCK(sc);
 	if (sc->txq[0].data_dmat) {
 		for (ac = 0; ac < WME_NUM_AC; ac++)
 			wpi_free_tx_ring(sc, &sc->txq[ac]);
@@ -749,7 +749,7 @@ wpi_detach(device_t dev)
 
 	if (sc->fw_dma.tag)
 		wpi_free_fwmem(sc);
-	WPI_UNLOCK();
+	WPI_UNLOCK(sc);
 
 	if (sc->irq != NULL) {
 		bus_teardown_intr(dev, sc->irq, sc->sc_ih);
@@ -762,7 +762,7 @@ wpi_detach(device_t dev)
 	if (ifp != NULL)
 		if_free(ifp);
 
-	WPI_LOCK_DESTROY();
+	WPI_LOCK_DESTROY(sc);
 
 	return 0;
 }
@@ -1206,10 +1206,10 @@ wpi_shutdown(device_t dev)
 {
 	struct wpi_softc *sc = device_get_softc(dev);
 
-	WPI_LOCK();
+	WPI_LOCK(sc);
 	wpi_stop_locked(sc);
 	wpi_unload_firmware(sc);
-	WPI_UNLOCK();
+	WPI_UNLOCK(sc);
 
 	return 0;
 }
@@ -1268,7 +1268,7 @@ wpi_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
 		ieee80211_state_name[nstate], sc->flags));
 
 	IEEE80211_UNLOCK(ic);
-	WPI_LOCK();
+	WPI_LOCK(sc);
 	if (nstate == IEEE80211_S_AUTH) {
 		/* The node must be registered in the firmware before auth */
 		error = wpi_auth(sc, vap);
@@ -1291,7 +1291,7 @@ wpi_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
 		wpi_calib_timeout(sc);
 		/* XXX split out rate control timer */
 	}
-	WPI_UNLOCK();
+	WPI_UNLOCK(sc);
 	IEEE80211_LOCK(ic);
 	return wvp->newstate(vap, nstate, arg);
 }
@@ -1551,7 +1551,7 @@ wpi_rx_intr(struct wpi_softc *sc, struct wpi_rx_desc *desc,
 			tap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
 	}
 
-	WPI_UNLOCK();
+	WPI_UNLOCK(sc);
 
 	ni = ieee80211_find_rxnode(ic, mtod(m, struct ieee80211_frame_min *));
 	if (ni != NULL) {
@@ -1560,7 +1560,7 @@ wpi_rx_intr(struct wpi_softc *sc, struct wpi_rx_desc *desc,
 	} else
 		(void) ieee80211_input_all(ic, m, stat->rssi, 0);
 
-	WPI_LOCK();
+	WPI_LOCK(sc);
 }
 
 static void
@@ -1769,11 +1769,11 @@ wpi_intr(void *arg)
 	struct wpi_softc *sc = arg;
 	uint32_t r;
 
-	WPI_LOCK();
+	WPI_LOCK(sc);
 
 	r = WPI_READ(sc, WPI_INTR);
 	if (r == 0 || r == 0xffffffff) {
-		WPI_UNLOCK();
+		WPI_UNLOCK(sc);
 		return;
 	}
 
@@ -1794,7 +1794,7 @@ wpi_intr(void *arg)
 			ieee80211_cancel_scan(vap);
 		ieee80211_runtask(ic, &sc->sc_restarttask);
 		sc->flags &= ~WPI_FLAG_BUSY;
-		WPI_UNLOCK();
+		WPI_UNLOCK(sc);
 		return;
 	}
 
@@ -1808,7 +1808,7 @@ wpi_intr(void *arg)
 	if (sc->sc_ifp->if_flags & IFF_UP)
 		WPI_WRITE(sc, WPI_MASK, WPI_INTR_MASK);
 
-	WPI_UNLOCK();
+	WPI_UNLOCK(sc);
 }
 
 static uint8_t
@@ -2017,9 +2017,11 @@ wpi_tx_data(struct wpi_softc *sc, struct mbuf *m0, struct ieee80211_node *ni,
 static void
 wpi_start(struct ifnet *ifp)
 {
-	WPI_LOCK();
+	__unused struct wpi_softc *sc = ifp->if_softc;
+
+	WPI_LOCK(sc);
 	wpi_start_locked(ifp);
-	WPI_UNLOCK();
+	WPI_UNLOCK(sc);
 }
 
 static void
@@ -2030,7 +2032,7 @@ wpi_start_locked(struct ifnet *ifp)
 	struct mbuf *m;
 	int ac;
 
-	WPI_LOCK_ASSERT();
+	WPI_LOCK_ASSERT(sc);
 
 	if ((ifp->if_flags & IFF_RUNNING) == 0) {
 		ifq_purge(&ifp->if_snd);
@@ -2072,13 +2074,13 @@ wpi_raw_xmit(struct ieee80211_node *ni, struct mbuf *m,
 		ieee80211_free_node(ni);
 		return ENETDOWN;
 	}
-	WPI_LOCK();
+	WPI_LOCK(sc);
 
 	/* management frames go into ring 0 */
 	if (sc->txq[0].queued > sc->txq[0].count - 8) {
 		ifp->if_flags |= IFF_OACTIVE;
 		m_freem(m);
-		WPI_UNLOCK();
+		WPI_UNLOCK(sc);
 		ieee80211_free_node(ni);
 		return ENOBUFS;		/* XXX */
 	}
@@ -2089,11 +2091,11 @@ wpi_raw_xmit(struct ieee80211_node *ni, struct mbuf *m,
 	sc->sc_tx_timer = 5;
 	callout_reset(&sc->watchdog_to, hz, wpi_watchdog, sc);
 
-	WPI_UNLOCK();
+	WPI_UNLOCK(sc);
 	return 0;
 bad:
 	ifp->if_oerrors++;
-	WPI_UNLOCK();
+	WPI_UNLOCK(sc);
 	ieee80211_free_node(ni);
 	return EIO;		/* XXX */
 }
@@ -2108,7 +2110,7 @@ wpi_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cred)
 
 	switch (cmd) {
 	case SIOCSIFFLAGS:
-		WPI_LOCK();
+		WPI_LOCK(sc);
 		if ((ifp->if_flags & IFF_UP)) {
 			if (!(ifp->if_flags & IFF_RUNNING)) {
 				wpi_init_locked(sc, 0);
@@ -2117,7 +2119,7 @@ wpi_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cred)
 		} else if ((ifp->if_flags & IFF_RUNNING) ||
 			   (sc->flags & WPI_FLAG_HW_RADIO_OFF))
 			wpi_stop_locked(sc);
-		WPI_UNLOCK();
+		WPI_UNLOCK(sc);
 		if (startall)
 			ieee80211_start_all(ic);
 		break;
@@ -2174,7 +2176,7 @@ wpi_cmd(struct wpi_softc *sc, int code, const void *buf, int size, int async)
 
 #ifdef WPI_DEBUG
 	if (!async) {
-		WPI_LOCK_ASSERT();
+		WPI_LOCK_ASSERT(sc);
 	}
 #endif
 
@@ -3160,9 +3162,9 @@ wpi_init(void *arg)
 	struct ifnet *ifp = sc->sc_ifp;
 	struct ieee80211com *ic = ifp->if_l2com;
 
-	WPI_LOCK();
+	WPI_LOCK(sc);
 	wpi_init_locked(sc, 0);
-	WPI_UNLOCK();
+	WPI_UNLOCK(sc);
 
 	if (ifp->if_flags & IFF_RUNNING)
 		ieee80211_start_all(ic);		/* start all vaps */
@@ -3217,9 +3219,9 @@ wpi_stop_locked(struct wpi_softc *sc)
 static void
 wpi_stop(struct wpi_softc *sc)
 {
-	WPI_LOCK();
+	WPI_LOCK(sc);
 	wpi_stop_locked(sc);
-	WPI_UNLOCK();
+	WPI_UNLOCK(sc);
 }
 
 static void
@@ -3530,9 +3532,9 @@ wpi_scan_start(struct ieee80211com *ic)
 	struct ifnet *ifp = ic->ic_ifp;
 	struct wpi_softc *sc = ifp->if_softc;
 
-	WPI_LOCK();
+	WPI_LOCK(sc);
 	wpi_set_led(sc, WPI_LED_LINK, 20, 2);
-	WPI_UNLOCK();
+	WPI_UNLOCK(sc);
 }
 
 /**
@@ -3581,10 +3583,10 @@ wpi_scan_curchan(struct ieee80211_scan_state *ss, unsigned long maxdwell)
 	struct ifnet *ifp = vap->iv_ic->ic_ifp;
 	struct wpi_softc *sc = ifp->if_softc;
 
-	WPI_LOCK();
+	WPI_LOCK(sc);
 	if (wpi_scan(sc))
 		ieee80211_cancel_scan(vap);
-	WPI_UNLOCK();
+	WPI_UNLOCK(sc);
 }
 
 /**
@@ -3604,9 +3606,9 @@ wpi_hwreset(void *arg, int pending)
 {
 	struct wpi_softc *sc = arg;
 
-	WPI_LOCK();
+	WPI_LOCK(sc);
 	wpi_init_locked(sc, 0);
-	WPI_UNLOCK();
+	WPI_UNLOCK(sc);
 }
 
 static void
@@ -3614,9 +3616,9 @@ wpi_rfreset(void *arg, int pending)
 {
 	struct wpi_softc *sc = arg;
 
-	WPI_LOCK();
+	WPI_LOCK(sc);
 	wpi_rfkill_resume(sc);
-	WPI_UNLOCK();
+	WPI_UNLOCK(sc);
 }
 
 /*
diff --git a/sys/dev/netif/wpi/if_wpivar.h b/sys/dev/netif/wpi/if_wpivar.h
index 8a98fa3..7e4f499 100644
--- a/sys/dev/netif/wpi/if_wpivar.h
+++ b/sys/dev/netif/wpi/if_wpivar.h
@@ -206,8 +206,8 @@ struct wpi_softc {
 	char			domain[4];	/*reglatory domain XXX */
 };
 
-#define WPI_LOCK_INIT()
-#define WPI_LOCK() lwkt_gettoken(&wlan_token)
-#define WPI_UNLOCK() lwkt_reltoken(&wlan_token)
-#define WPI_LOCK_DESTROY()
-#define WPI_LOCK_ASSERT() ASSERT_LWKT_TOKEN_HELD(&wlan_token)
+#define WPI_LOCK_INIT(_sc)
+#define WPI_LOCK(_sc) lwkt_gettoken(&wlan_token)
+#define WPI_UNLOCK(_sc) lwkt_reltoken(&wlan_token)
+#define WPI_LOCK_DESTROY(_sc)
+#define WPI_LOCK_ASSERT(_sc) ASSERT_LWKT_TOKEN_HELD(&wlan_token)
-- 
1.6.6.1

