build images for D-Link DSL-2650U (#9003)
[openwrt/staging/chunkeey.git] / package / mac80211 / patches / 561-ath9k_fix_ps_idle_handling.patch
1 --- a/drivers/net/wireless/ath/ath9k/main.c
2 +++ b/drivers/net/wireless/ath/ath9k/main.c
3 @@ -883,82 +883,6 @@ chip_reset:
4 #undef SCHED_INTR
5 }
6
7 -static void ath_radio_enable(struct ath_softc *sc, struct ieee80211_hw *hw)
8 -{
9 - struct ath_hw *ah = sc->sc_ah;
10 - struct ath_common *common = ath9k_hw_common(ah);
11 - struct ieee80211_channel *channel = hw->conf.channel;
12 - int r;
13 -
14 - ath9k_ps_wakeup(sc);
15 - spin_lock_bh(&sc->sc_pcu_lock);
16 - atomic_set(&ah->intr_ref_cnt, -1);
17 -
18 - ath9k_hw_configpcipowersave(ah, false);
19 -
20 - if (!ah->curchan)
21 - ah->curchan = ath9k_cmn_get_curchannel(sc->hw, ah);
22 -
23 - r = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
24 - if (r) {
25 - ath_err(common,
26 - "Unable to reset channel (%u MHz), reset status %d\n",
27 - channel->center_freq, r);
28 - }
29 -
30 - ath_complete_reset(sc, true);
31 -
32 - /* Enable LED */
33 - ath9k_hw_cfg_output(ah, ah->led_pin,
34 - AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
35 - ath9k_hw_set_gpio(ah, ah->led_pin, 0);
36 -
37 - spin_unlock_bh(&sc->sc_pcu_lock);
38 -
39 - ath9k_ps_restore(sc);
40 -}
41 -
42 -void ath_radio_disable(struct ath_softc *sc, struct ieee80211_hw *hw)
43 -{
44 - struct ath_hw *ah = sc->sc_ah;
45 - struct ieee80211_channel *channel = hw->conf.channel;
46 - int r;
47 -
48 - ath9k_ps_wakeup(sc);
49 -
50 - ath_cancel_work(sc);
51 -
52 - spin_lock_bh(&sc->sc_pcu_lock);
53 -
54 - /*
55 - * Keep the LED on when the radio is disabled
56 - * during idle unassociated state.
57 - */
58 - if (!sc->ps_idle) {
59 - ath9k_hw_set_gpio(ah, ah->led_pin, 1);
60 - ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
61 - }
62 -
63 - ath_prepare_reset(sc, false, true);
64 -
65 - if (!ah->curchan)
66 - ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
67 -
68 - r = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
69 - if (r) {
70 - ath_err(ath9k_hw_common(sc->sc_ah),
71 - "Unable to reset channel (%u MHz), reset status %d\n",
72 - channel->center_freq, r);
73 - }
74 -
75 - ath9k_hw_phy_disable(ah);
76 -
77 - ath9k_hw_configpcipowersave(ah, true);
78 -
79 - spin_unlock_bh(&sc->sc_pcu_lock);
80 - ath9k_ps_restore(sc);
81 -}
82 -
83 static int ath_reset(struct ath_softc *sc, bool retry_tx)
84 {
85 int r;
86 @@ -1094,6 +1018,9 @@ static int ath9k_start(struct ieee80211_
87 * and then setup of the interrupt mask.
88 */
89 spin_lock_bh(&sc->sc_pcu_lock);
90 +
91 + atomic_set(&ah->intr_ref_cnt, -1);
92 +
93 r = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
94 if (r) {
95 ath_err(common,
96 @@ -1132,6 +1059,18 @@ static int ath9k_start(struct ieee80211_
97 goto mutex_unlock;
98 }
99
100 + if (ah->led_pin >= 0) {
101 + ath9k_hw_cfg_output(ah, ah->led_pin,
102 + AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
103 + ath9k_hw_set_gpio(ah, ah->led_pin, 0);
104 + }
105 +
106 + /*
107 + * Reset key cache to sane defaults (all entries cleared) instead of
108 + * semi-random values after suspend/resume.
109 + */
110 + ath9k_cmn_init_crypto(sc->sc_ah);
111 +
112 spin_unlock_bh(&sc->sc_pcu_lock);
113
114 if ((ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE) &&
115 @@ -1229,6 +1168,7 @@ static void ath9k_stop(struct ieee80211_
116 struct ath_softc *sc = hw->priv;
117 struct ath_hw *ah = sc->sc_ah;
118 struct ath_common *common = ath9k_hw_common(ah);
119 + bool prev_idle;
120
121 mutex_lock(&sc->mutex);
122
123 @@ -1258,35 +1198,45 @@ static void ath9k_stop(struct ieee80211_
124 * before setting the invalid flag. */
125 ath9k_hw_disable_interrupts(ah);
126
127 - if (!(sc->sc_flags & SC_OP_INVALID)) {
128 - ath_drain_all_txq(sc, false);
129 - ath_stoprecv(sc);
130 - ath9k_hw_phy_disable(ah);
131 - } else
132 - sc->rx.rxlink = NULL;
133 + spin_unlock_bh(&sc->sc_pcu_lock);
134 +
135 + /* we can now sync irq and kill any running tasklets, since we already
136 + * disabled interrupts and not holding a spin lock */
137 + synchronize_irq(sc->irq);
138 + tasklet_kill(&sc->intr_tq);
139 + tasklet_kill(&sc->bcon_tasklet);
140 +
141 + prev_idle = sc->ps_idle;
142 + sc->ps_idle = true;
143 +
144 + spin_lock_bh(&sc->sc_pcu_lock);
145 +
146 + if (ah->led_pin >= 0) {
147 + ath9k_hw_set_gpio(ah, ah->led_pin, 1);
148 + ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
149 + }
150 +
151 + ath_prepare_reset(sc, false, true);
152
153 if (sc->rx.frag) {
154 dev_kfree_skb_any(sc->rx.frag);
155 sc->rx.frag = NULL;
156 }
157
158 - /* disable HAL and put h/w to sleep */
159 - ath9k_hw_disable(ah);
160 + if (!ah->curchan)
161 + ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
162
163 - spin_unlock_bh(&sc->sc_pcu_lock);
164 + ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
165 + ath9k_hw_phy_disable(ah);
166
167 - /* we can now sync irq and kill any running tasklets, since we already
168 - * disabled interrupts and not holding a spin lock */
169 - synchronize_irq(sc->irq);
170 - tasklet_kill(&sc->intr_tq);
171 - tasklet_kill(&sc->bcon_tasklet);
172 + ath9k_hw_configpcipowersave(ah, true);
173
174 - ath9k_ps_restore(sc);
175 + spin_unlock_bh(&sc->sc_pcu_lock);
176
177 - sc->ps_idle = true;
178 - ath_radio_disable(sc, hw);
179 + ath9k_ps_restore(sc);
180
181 sc->sc_flags |= SC_OP_INVALID;
182 + sc->ps_idle = prev_idle;
183
184 mutex_unlock(&sc->mutex);
185
186 @@ -1608,8 +1558,8 @@ static int ath9k_config(struct ieee80211
187 struct ath_hw *ah = sc->sc_ah;
188 struct ath_common *common = ath9k_hw_common(ah);
189 struct ieee80211_conf *conf = &hw->conf;
190 - bool disable_radio = false;
191
192 + ath9k_ps_wakeup(sc);
193 mutex_lock(&sc->mutex);
194
195 /*
196 @@ -1618,16 +1568,8 @@ static int ath9k_config(struct ieee80211
197 * of the changes. Likewise we must only disable the radio towards
198 * the end.
199 */
200 - if (changed & IEEE80211_CONF_CHANGE_IDLE) {
201 + if (changed & IEEE80211_CONF_CHANGE_IDLE)
202 sc->ps_idle = !!(conf->flags & IEEE80211_CONF_IDLE);
203 - if (!sc->ps_idle) {
204 - ath_radio_enable(sc, hw);
205 - ath_dbg(common, ATH_DBG_CONFIG,
206 - "not-idle: enabling radio\n");
207 - } else {
208 - disable_radio = true;
209 - }
210 - }
211
212 /*
213 * We just prepare to enable PS. We have to wait until our AP has
214 @@ -1752,19 +1694,13 @@ static int ath9k_config(struct ieee80211
215 ath_dbg(common, ATH_DBG_CONFIG,
216 "Set power: %d\n", conf->power_level);
217 sc->config.txpowlimit = 2 * conf->power_level;
218 - ath9k_ps_wakeup(sc);
219 ath9k_cmn_update_txpow(ah, sc->curtxpow,
220 sc->config.txpowlimit, &sc->curtxpow);
221 - ath9k_ps_restore(sc);
222 conf->cur_power_level = sc->curtxpow / 2;
223 }
224
225 - if (disable_radio) {
226 - ath_dbg(common, ATH_DBG_CONFIG, "idle: disabling radio\n");
227 - ath_radio_disable(sc, hw);
228 - }
229 -
230 mutex_unlock(&sc->mutex);
231 + ath9k_ps_restore(sc);
232
233 return 0;
234 }
235 --- a/drivers/net/wireless/ath/ath9k/pci.c
236 +++ b/drivers/net/wireless/ath/ath9k/pci.c
237 @@ -306,12 +306,11 @@ static int ath_pci_suspend(struct device
238 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
239 struct ath_softc *sc = hw->priv;
240
241 - ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 1);
242 -
243 /* The device has to be moved to FULLSLEEP forcibly.
244 * Otherwise the chip never moved to full sleep,
245 * when no interface is up.
246 */
247 + ath9k_hw_disable(sc->sc_ah);
248 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_FULL_SLEEP);
249
250 return 0;
251 @@ -333,22 +332,6 @@ static int ath_pci_resume(struct device
252 if ((val & 0x0000ff00) != 0)
253 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
254
255 - ath9k_ps_wakeup(sc);
256 - /* Enable LED */
257 - ath9k_hw_cfg_output(sc->sc_ah, sc->sc_ah->led_pin,
258 - AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
259 - ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 0);
260 -
261 - /*
262 - * Reset key cache to sane defaults (all entries cleared) instead of
263 - * semi-random values after suspend/resume.
264 - */
265 - ath9k_cmn_init_crypto(sc->sc_ah);
266 - ath9k_ps_restore(sc);
267 -
268 - sc->ps_idle = true;
269 - ath_radio_disable(sc, hw);
270 -
271 return 0;
272 }
273