1 From 7446da6910f1368273a55ca99acba18828306a6e Mon Sep 17 00:00:00 2001
2 From: Gabor Juhos <juhosg@openwrt.org>
3 Date: Sun, 21 Jun 2009 16:59:53 +0200
4 Subject: [PATCH 3/3] ath9k: serialize ath9k_ps_{wakeup,restore} calls
6 These functions are changing the power mode of the chip, but this may
7 have unpredictable effects, if another code are trying to set the power
8 mode via 'ath9k_hw_setpower' in the same time from another context.
10 Changes-licensed-under: ISC
11 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
13 drivers/net/wireless/ath/ath9k/ath9k.h | 2 +-
14 drivers/net/wireless/ath/ath9k/hw.c | 42 ++++++++++++++++++++++----------
15 2 files changed, 30 insertions(+), 14 deletions(-)
17 --- a/drivers/net/wireless/ath/ath9k/ath9k.h
18 +++ b/drivers/net/wireless/ath/ath9k/ath9k.h
19 @@ -561,7 +561,7 @@ struct ath_softc {
21 DECLARE_BITMAP(keymap, ATH_KEYMAX);
23 - atomic_t ps_usecount;
24 + unsigned long ps_usecount;
26 enum ath9k_ht_extprotspacing ht_extprotspacing;
27 enum ath9k_ht_macmode tx_chan_width;
28 --- a/drivers/net/wireless/ath/ath9k/hw.c
29 +++ b/drivers/net/wireless/ath/ath9k/hw.c
30 @@ -2787,23 +2787,39 @@ bool ath9k_hw_setpower(struct ath_hw *ah
32 void ath9k_ps_wakeup(struct ath_softc *sc)
34 - if (atomic_inc_return(&sc->ps_usecount) == 1)
35 - if (sc->sc_ah->power_mode != ATH9K_PM_AWAKE) {
36 - sc->sc_ah->restore_mode = sc->sc_ah->power_mode;
37 - ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
39 + unsigned long flags;
41 + spin_lock_irqsave(&sc->sc_pm_lock, flags);
42 + if (++sc->ps_usecount != 1)
45 + if (sc->sc_ah->power_mode != ATH9K_PM_AWAKE) {
46 + sc->sc_ah->restore_mode = sc->sc_ah->power_mode;
47 + ath9k_hw_setpower_nolock(sc->sc_ah, ATH9K_PM_AWAKE);
51 + spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
54 void ath9k_ps_restore(struct ath_softc *sc)
56 - if (atomic_dec_and_test(&sc->ps_usecount))
57 - if ((sc->hw->conf.flags & IEEE80211_CONF_PS) &&
58 - !(sc->sc_flags & (SC_OP_WAIT_FOR_BEACON |
59 - SC_OP_WAIT_FOR_CAB |
60 - SC_OP_WAIT_FOR_PSPOLL_DATA |
61 - SC_OP_WAIT_FOR_TX_ACK)))
62 - ath9k_hw_setpower(sc->sc_ah,
63 - sc->sc_ah->restore_mode);
64 + unsigned long flags;
66 + spin_lock_irqsave(&sc->sc_pm_lock, flags);
67 + if (--sc->ps_usecount != 0)
70 + if ((sc->hw->conf.flags & IEEE80211_CONF_PS) &&
71 + !(sc->sc_flags & (SC_OP_WAIT_FOR_BEACON |
72 + SC_OP_WAIT_FOR_CAB |
73 + SC_OP_WAIT_FOR_PSPOLL_DATA |
74 + SC_OP_WAIT_FOR_TX_ACK)))
75 + ath9k_hw_setpower_nolock(sc->sc_ah,
76 + sc->sc_ah->restore_mode);
79 + spin_unlock_irqrestore(&sc->sc_pm_lock, flags);