PERFORCE change 126590 for review

Sam Leffler sam at FreeBSD.org
Tue Sep 18 22:02:01 PDT 2007


http://perforce.freebsd.org/chv.cgi?CH=126590

Change 126590 by sam at sam_ebb on 2007/09/19 05:01:27

	revert experimental polling and sx lock stuff

Affected files ...

.. //depot/projects/wifi/sys/dev/ath/if_ath.c#152 edit
.. //depot/projects/wifi/sys/dev/ath/if_ath_pci.c#16 edit
.. //depot/projects/wifi/sys/dev/ath/if_athvar.h#60 edit

Differences ...

==== //depot/projects/wifi/sys/dev/ath/if_ath.c#152 (text+ko) ====

@@ -37,9 +37,6 @@
  * is greatly appreciated.
  */
 
-#ifdef HAVE_KERNEL_OPTION_HEADERS
-#include "opt_device_polling.h"
-#endif
 #include "opt_inet.h"
 #include "opt_ath.h"
 
@@ -49,7 +46,7 @@
 #include <sys/mbuf.h>   
 #include <sys/malloc.h>
 #include <sys/lock.h>
-#include <sys/sx.h>
+#include <sys/mutex.h>
 #include <sys/kernel.h>
 #include <sys/socket.h>
 #include <sys/sockio.h>
@@ -104,6 +101,7 @@
 
 static void	ath_init(void *);
 static void	ath_stop_locked(struct ifnet *);
+static void	ath_stop(struct ifnet *);
 static void	ath_start(struct ifnet *);
 static int	ath_reset(struct ifnet *);
 static int	ath_media_change(struct ifnet *);
@@ -497,7 +495,6 @@
 	IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN);
 	ifp->if_snd.ifq_drv_maxlen = IFQ_MAXLEN;
 	IFQ_SET_READY(&ifp->if_snd);
-	ifp->if_capabilities |= IFCAP_POLLING;
 
 	ic->ic_ifp = ifp;
 	ic->ic_reset = ath_reset;
@@ -657,23 +654,14 @@
 }
 
 int
-ath_detach(struct ath_softc *sc, struct resource *irq, void *irq_handler)
+ath_detach(struct ath_softc *sc)
 {
 	struct ifnet *ifp = sc->sc_ifp;
 
 	DPRINTF(sc, ATH_DEBUG_ANY, "%s: if_flags %x\n",
 		__func__, ifp->if_flags);
 
-#ifdef DEVICE_POLLING
-	if (ifp->if_capenable & IFCAP_POLLING)
-		ether_poll_deregister(ifp);
-#endif
-	ATH_LOCK(sc);
-	ath_stop_locked(ifp);
-	ATH_UNLOCK(sc);
-
-	bus_teardown_intr(sc->sc_dev, irq, irq_handler);
-
+	ath_stop(ifp);
 	bpfdetach(ifp);
 	/* 
 	 * NB: the order of these is important:
@@ -710,31 +698,25 @@
 	DPRINTF(sc, ATH_DEBUG_ANY, "%s: if_flags %x\n",
 		__func__, ifp->if_flags);
 
-	ATH_LOCK(sc);
-	ath_stop_locked(ifp);
-	ath_hal_setpower(sc->sc_ah, HAL_PM_FULL_SLEEP);
-	ATH_UNLOCK(sc);
+	ath_stop(ifp);
 }
 
 void
 ath_resume(struct ath_softc *sc)
 {
 	struct ifnet *ifp = sc->sc_ifp;
-	struct ath_hal *ah = sc->sc_ah;
 
 	DPRINTF(sc, ATH_DEBUG_ANY, "%s: if_flags %x\n",
 		__func__, ifp->if_flags);
 
-	ath_hal_setpower(ah, HAL_PM_AWAKE);
-
 	if (ifp->if_flags & IFF_UP) {
 		ath_init(sc);
 		if (ifp->if_drv_flags & IFF_DRV_RUNNING)
 			ath_start(ifp);
 	}
 	if (sc->sc_softled) {
-		ath_hal_gpioCfgOutput(ah, sc->sc_ledpin);
-		ath_hal_gpioset(ah, sc->sc_ledpin, !sc->sc_ledon);
+		ath_hal_gpioCfgOutput(sc->sc_ah, sc->sc_ledpin);
+		ath_hal_gpioset(sc->sc_ah, sc->sc_ledpin, !sc->sc_ledon);
 	}
 }
 
@@ -746,40 +728,16 @@
 	DPRINTF(sc, ATH_DEBUG_ANY, "%s: if_flags %x\n",
 		__func__, ifp->if_flags);
 
-	ATH_LOCK(sc);
-	ath_stop_locked(ifp);
-	if (!sc->sc_invalid) {
-		/*
-		 * Set the chip in full sleep mode.  Note that we are
-		 * careful to do this only when bringing the interface
-		 * completely to a stop.  When the chip is in this state
-		 * it must be carefully woken up or references to
-		 * registers in the PCI clock domain may freeze the bus
-		 * (and system).  This varies by chip and is mostly an
-		 * issue with newer parts that go to sleep more quickly.
-		 */
-		ath_hal_setpower(sc->sc_ah, HAL_PM_FULL_SLEEP);
-	}
-	ATH_UNLOCK(sc);
+	ath_stop(ifp);
 }
 
 /*
- * Set/enable interrupts. We actually enable
- * interrupts only if we are not polling.
+ * Interrupt handler.  Most of the actual processing is deferred.
  */
-static __inline void
-ath_intrset(struct ath_softc *sc, u_int32_t mask)
+void
+ath_intr(void *arg)
 {
-	struct ath_hal *ah = sc->sc_ah;
-
-	if (sc->sc_ifp->if_capenable & IFCAP_POLLING)
-		mask &= ~HAL_INT_GLOBAL;
-	ath_hal_intrset(ah, mask);
-}
-
-static void
-ath_intr_body(struct ath_softc *sc, int count)
-{
+	struct ath_softc *sc = arg;
 	struct ifnet *ifp = sc->sc_ifp;
 	struct ath_hal *ah = sc->sc_ah;
 	HAL_INT status;
@@ -865,60 +823,11 @@
 			 * clear whatever condition caused the interrupt.
 			 */
 			ath_hal_mibevent(ah, &sc->sc_halstats);
-			ath_intrset(sc, sc->sc_imask);
+			ath_hal_intrset(ah, sc->sc_imask);
 		}
 	}
 }
 
-/*
- * Interrupt handler.  Most of the actual processing is deferred.
- */
-void
-ath_intr(void *arg)
-{
-	struct ath_softc *sc = arg;
-	struct ifnet *ifp = sc->sc_ifp;
-	struct ath_hal *ah = sc->sc_ah;
-
-	if (ifp->if_capenable & IFCAP_POLLING)
-		return;
-	if (sc->sc_invalid) {
-		/*
-		 * The hardware is not ready/present, don't touch anything.
-		 * Note this can happen early on if the IRQ is shared.
-		 */
-		DPRINTF(sc, ATH_DEBUG_ANY, "%s: invalid; ignored\n", __func__);
-		return;
-	}
-	if (!ath_hal_intrpend(ah))		/* shared irq, not for us */
-		return;
-	if ((ifp->if_flags & IFF_UP) == 0 ||
-	    (ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) {
-		HAL_INT status;
-
-		DPRINTF(sc, ATH_DEBUG_ANY, "%s: if_flags 0x%x\n",
-			__func__, ifp->if_flags);
-		ath_hal_getisr(ah, &status);	/* clear ISR */
-		ath_hal_intrset(ah, 0);		/* disable further intr's */
-		return;
-	}
-	ath_intr_body(sc, 1);
-}
-
-#ifdef DEVICE_POLLING
-/*
- * Polling callback.
- */
-static void     
-ath_poll(struct ifnet *ifp, enum poll_cmd cmd, int count)
-{
-        struct ath_softc *sc = ifp->if_softc;
-
-	if (ifp->if_drv_flags & IFF_DRV_RUNNING)
-		ath_intr_body(sc, count);
-}
-#endif
-
 static void
 ath_fatal_proc(void *arg, int pending)
 {
@@ -1100,7 +1009,7 @@
 	 */
 	if (sc->sc_needmib && ic->ic_opmode == IEEE80211_M_STA)
 		sc->sc_imask |= HAL_INT_MIB;
-	ath_intrset(sc, sc->sc_imask);
+	ath_hal_intrset(ah, sc->sc_imask);
 
 	ifp->if_drv_flags |= IFF_DRV_RUNNING;
 	ic->ic_state = IEEE80211_S_INIT;
@@ -1179,6 +1088,28 @@
 	}
 }
 
+static void
+ath_stop(struct ifnet *ifp)
+{
+	struct ath_softc *sc = ifp->if_softc;
+
+	ATH_LOCK(sc);
+	ath_stop_locked(ifp);
+	if (!sc->sc_invalid) {
+		/*
+		 * Set the chip in full sleep mode.  Note that we are
+		 * careful to do this only when bringing the interface
+		 * completely to a stop.  When the chip is in this state
+		 * it must be carefully woken up or references to
+		 * registers in the PCI clock domain may freeze the bus
+		 * (and system).  This varies by chip and is mostly an
+		 * issue with newer parts that go to sleep more quickly.
+		 */
+		ath_hal_setpower(sc->sc_ah, HAL_PM_FULL_SLEEP);
+	}
+	ATH_UNLOCK(sc);
+}
+
 /*
  * Reset the hardware w/o losing operational state.  This is
  * basically a more efficient way of doing ath_stop, ath_init,
@@ -1221,7 +1152,7 @@
 	ath_chan_change(sc, ic->ic_curchan);
 	if (ic->ic_state == IEEE80211_S_RUN)
 		ath_beacon_config(sc);	/* restart beacons */
-	ath_intrset(sc, sc->sc_imask);
+	ath_hal_intrset(ah, sc->sc_imask);
 
 	ath_start(ifp);			/* restart xmit */
 	return 0;
@@ -2977,7 +2908,7 @@
 		ath_hal_intrset(ah, 0);
 		ath_hal_beacontimers(ah, &bs);
 		sc->sc_imask |= HAL_INT_BMISS;
-		ath_intrset(sc, sc->sc_imask);
+		ath_hal_intrset(ah, sc->sc_imask);
 	} else {
 		ath_hal_intrset(ah, 0);
 		if (nexttbtt == intval)
@@ -3016,7 +2947,7 @@
 		}
 		ath_hal_beaconinit(ah, nexttbtt, intval);
 		sc->sc_bmisscount = 0;
-		ath_intrset(sc, sc->sc_imask);
+		ath_hal_intrset(ah, sc->sc_imask);
 		/*
 		 * When using a self-linked beacon descriptor in
 		 * ibss mode load it once here.
@@ -5169,7 +5100,7 @@
 		/*
 		 * Re-enable interrupts.
 		 */
-		ath_intrset(sc, sc->sc_imask);
+		ath_hal_intrset(ah, sc->sc_imask);
 	}
 	return 0;
 }
@@ -5326,12 +5257,14 @@
 		 * o notify the rate control algorithm
 		 */
 		sc->sc_imask &= ~(HAL_INT_SWBA | HAL_INT_BMISS);
-		ath_intrset(sc, sc->sc_imask &~ HAL_INT_GLOBAL);
+		ath_hal_intrset(ah, sc->sc_imask &~ HAL_INT_GLOBAL);
+#if 0
+		/* XXX can't use taskqueue_drain 'cuz we're holding sc_mtx */
 		taskqueue_drain(sc->sc_tq, &sc->sc_rxtask);
-		taskqueue_drain(sc->sc_tq, &sc->sc_txtask);
 		taskqueue_drain(sc->sc_tq, &sc->sc_rxorntask);
 		taskqueue_drain(sc->sc_tq, &sc->sc_bmisstask);
 		taskqueue_drain(sc->sc_tq, &sc->sc_bstucktask);
+#endif
 		ath_rate_newstate(sc, nstate);
 		goto done;
 	}
@@ -5975,22 +5908,6 @@
 		ATH_LOCK(sc);
 		break;
 #endif
-	case SIOCSIFCAP:
-#ifdef DEVICE_POLLING
-		if ((ifr->ifr_reqcap ^ ifp->if_capenable) & IFCAP_POLLING) {
-			if (ifr->ifr_reqcap & IFCAP_POLLING) {
-				error = ether_poll_register(ath_poll, ifp);
-				if (!error)
-					ifp->if_capenable |= IFCAP_POLLING;
-			} else {
-				error = ether_poll_deregister(ifp);
-				/* NB: enable interrupts even if error */
-				ifp->if_capenable &= ~IFCAP_POLLING;
-			}
-			ath_intrset(sc, sc->sc_imask);
-		}
-#endif
-		break;
 	default:
 		error = ieee80211_ioctl(ic, cmd, data);
 		if (error == ENETRESET) {
@@ -6192,14 +6109,18 @@
 {
 	struct ath_softc *sc = arg1;
 	struct ifnet *ifp = sc->sc_ifp;
-	u_int rfkill = ath_hal_getrfkill(sc->sc_ah);
+	struct ath_hal *ah = sc->sc_ah;
+	u_int rfkill = ath_hal_getrfkill(ah);
 	int error;
 
 	error = sysctl_handle_int(oidp, &rfkill, 0, req);
 	if (error || !req->newptr)
 		return error;
-	return !ath_hal_setrfkill(sc->sc_ah, rfkill) ? EINVAL :
-	    (ifp->if_drv_flags & IFF_DRV_RUNNING) ? ath_reset(ifp) : 0;
+	if (rfkill == ath_hal_getrfkill(ah))	/* unchanged */
+		return 0;
+	if (!ath_hal_setrfkill(ah, rfkill))
+		return EINVAL;
+	return (ifp->if_drv_flags & IFF_DRV_RUNNING) ? ath_reset(ifp) : 0;
 }
 
 static int
@@ -6213,7 +6134,11 @@
 	error = sysctl_handle_int(oidp, &rfsilent, 0, req);
 	if (error || !req->newptr)
 		return error;
-	return !ath_hal_setrfsilent(sc->sc_ah, rfsilent) ? EINVAL : 0;
+	if (!ath_hal_setrfsilent(sc->sc_ah, rfsilent))
+		return EINVAL;
+	sc->sc_rfsilentpin = rfsilent & 0x1c;
+	sc->sc_rfsilentpol = (rfsilent & 0x2) != 0;
+	return 0;
 }
 
 static int

==== //depot/projects/wifi/sys/dev/ath/if_ath_pci.c#16 (text+ko) ====

@@ -39,7 +39,7 @@
 #include <sys/module.h>
 #include <sys/kernel.h>
 #include <sys/lock.h>
-#include <sys/sx.h>
+#include <sys/mutex.h>
 #include <sys/errno.h>
 
 #include <machine/bus.h>
@@ -213,9 +213,10 @@
 	/* check if device was removed */
 	sc->sc_invalid = !bus_child_present(dev);
 
-	ath_detach(sc, psc->sc_irq, psc->sc_ih);
+	ath_detach(sc);
 
 	bus_generic_detach(dev);
+	bus_teardown_intr(dev, psc->sc_irq, psc->sc_ih);
 	bus_release_resource(dev, SYS_RES_IRQ, 0, psc->sc_irq);
 
 	bus_dma_tag_destroy(sc->sc_dmat);

==== //depot/projects/wifi/sys/dev/ath/if_athvar.h#60 (text+ko) ====

@@ -197,7 +197,7 @@
 	HAL_BUS_TAG		sc_st;		/* bus space tag */
 	HAL_BUS_HANDLE		sc_sh;		/* bus space handle */
 	bus_dma_tag_t		sc_dmat;	/* bus DMA tag */
-	struct sx		sc_mtx;		/* master lock (recursive) */
+	struct mtx		sc_mtx;		/* master lock (recursive) */
 	struct taskqueue	*sc_tq;		/* private task queue */
 	struct ath_hal		*sc_ah;		/* Atheros HAL */
 	struct ath_ratectrl	*sc_rc;		/* tx rate control support */
@@ -321,12 +321,12 @@
 #define	sc_rx_th		u_rx_rt.th
 
 #define	ATH_LOCK_INIT(_sc) \
-	sx_init_flags(&(_sc)->sc_mtx, device_get_nameunit((_sc)->sc_dev), \
-		SX_RECURSE)
-#define	ATH_LOCK_DESTROY(_sc)	sx_destroy(&(_sc)->sc_mtx)
-#define	ATH_LOCK(_sc)		sx_xlock(&(_sc)->sc_mtx)
-#define	ATH_UNLOCK(_sc)		sx_xunlock(&(_sc)->sc_mtx)
-#define	ATH_LOCK_ASSERT(_sc)	sx_assert(&(_sc)->sc_mtx, SA_LOCKED)
+	mtx_init(&(_sc)->sc_mtx, device_get_nameunit((_sc)->sc_dev), \
+		 NULL, MTX_DEF | MTX_RECURSE)
+#define	ATH_LOCK_DESTROY(_sc)	mtx_destroy(&(_sc)->sc_mtx)
+#define	ATH_LOCK(_sc)		mtx_lock(&(_sc)->sc_mtx)
+#define	ATH_UNLOCK(_sc)		mtx_unlock(&(_sc)->sc_mtx)
+#define	ATH_LOCK_ASSERT(_sc)	mtx_assert(&(_sc)->sc_mtx, MA_OWNED)
 
 #define	ATH_TXQ_SETUP(sc, i)	((sc)->sc_txqsetup & (1<<i))
 
@@ -342,7 +342,7 @@
 	mtx_assert(&(_sc)->sc_txbuflock, MA_OWNED)
 
 int	ath_attach(u_int16_t, struct ath_softc *);
-int	ath_detach(struct ath_softc *, struct resource *, void *);
+int	ath_detach(struct ath_softc *);
 void	ath_resume(struct ath_softc *);
 void	ath_suspend(struct ath_softc *);
 void	ath_shutdown(struct ath_softc *);


More information about the p4-projects mailing list