1 --- a/drivers/net/wireless/ath/ath9k/main.c
2 +++ b/drivers/net/wireless/ath/ath9k/main.c
3 @@ -212,84 +212,57 @@ static int ath_update_survey_stats(struc
8 - * Set/change channels. If the channel is really being changed, it's done
9 - * by reseting the chip. To accomplish this we must first cleanup any pending
10 - * DMA, then restart stuff.
12 -static int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
13 - struct ath9k_channel *hchan)
14 +static void __ath_cancel_work(struct ath_softc *sc)
16 - struct ath_hw *ah = sc->sc_ah;
17 - struct ath_common *common = ath9k_hw_common(ah);
18 - struct ieee80211_conf *conf = &common->hw->conf;
19 - bool fastcc = true, stopped;
20 - struct ieee80211_channel *channel = hw->conf.channel;
21 - struct ath9k_hw_cal_data *caldata = NULL;
24 - if (sc->sc_flags & SC_OP_INVALID)
27 - sc->hw_busy_count = 0;
29 - del_timer_sync(&common->ani.timer);
30 cancel_work_sync(&sc->paprd_work);
31 cancel_work_sync(&sc->hw_check_work);
32 - cancel_work_sync(&sc->hw_reset_work);
33 cancel_delayed_work_sync(&sc->tx_complete_work);
34 cancel_delayed_work_sync(&sc->hw_pll_work);
37 - ath9k_ps_wakeup(sc);
38 +static void ath_cancel_work(struct ath_softc *sc)
40 + __ath_cancel_work(sc);
41 + cancel_work_sync(&sc->hw_reset_work);
44 - spin_lock_bh(&sc->sc_pcu_lock);
45 +static bool ath_prepare_reset(struct ath_softc *sc, bool retry_tx, bool flush)
47 + struct ath_hw *ah = sc->sc_ah;
48 + struct ath_common *common = ath9k_hw_common(ah);
52 - * This is only performed if the channel settings have
55 - * To switch channels clear any pending DMA operations;
56 - * wait long enough for the RX fifo to drain, reset the
57 - * hardware at the new frequency, and then re-enable
58 - * the relevant bits of the h/w.
60 - ath9k_hw_disable_interrupts(ah);
61 - stopped = ath_drain_all_txq(sc, false);
62 + ieee80211_stop_queues(sc->hw);
64 - if (!ath_stoprecv(sc))
66 + sc->hw_busy_count = 0;
67 + del_timer_sync(&common->ani.timer);
69 - if (!ath9k_hw_check_alive(ah))
71 + ath9k_hw_disable_interrupts(ah);
73 - /* XXX: do not flush receive queue here. We don't want
74 - * to flush data frames already in queue because of
75 - * changing channel. */
76 + ret = ath_drain_all_txq(sc, retry_tx);
78 - if (!stopped || !(sc->sc_flags & SC_OP_OFFCHANNEL))
80 + if (!ath_stoprecv(sc))
83 - if (!(sc->sc_flags & SC_OP_OFFCHANNEL))
84 - caldata = &sc->caldata;
86 + if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
87 + ath_rx_tasklet(sc, 0, true);
88 + ath_rx_tasklet(sc, 0, false);
93 - ath_dbg(common, ATH_DBG_CONFIG,
94 - "(%u MHz) -> (%u MHz), conf_is_ht40: %d fastcc: %d\n",
95 - sc->sc_ah->curchan->channel,
96 - channel->center_freq, conf_is_ht40(conf),
101 - r = ath9k_hw_reset(ah, hchan, caldata, fastcc);
104 - "Unable to reset channel (%u MHz), reset status %d\n",
105 - channel->center_freq, r);
108 +static bool ath_complete_reset(struct ath_softc *sc, bool start)
110 + struct ath_hw *ah = sc->sc_ah;
111 + struct ath_common *common = ath9k_hw_common(ah);
113 if (ath_startrecv(sc) != 0) {
114 ath_err(common, "Unable to restart recv logic\n");
120 ath9k_cmn_update_txpow(ah, sc->curtxpow,
121 @@ -297,21 +270,93 @@ static int ath_set_channel(struct ath_so
122 ath9k_hw_set_interrupts(ah, ah->imask);
123 ath9k_hw_enable_interrupts(ah);
125 - if (!(sc->sc_flags & (SC_OP_OFFCHANNEL))) {
126 + if (!(sc->sc_flags & (SC_OP_OFFCHANNEL)) && start) {
127 if (sc->sc_flags & SC_OP_BEACONS)
130 ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
131 ieee80211_queue_delayed_work(sc->hw, &sc->hw_pll_work, HZ/2);
132 if (!common->disable_ani)
133 ath_start_ani(common);
137 - ieee80211_wake_queues(hw);
138 + ieee80211_wake_queues(sc->hw);
143 +static int ath_reset_internal(struct ath_softc *sc, struct ath9k_channel *hchan,
146 + struct ath_hw *ah = sc->sc_ah;
147 + struct ath_common *common = ath9k_hw_common(ah);
148 + struct ath9k_hw_cal_data *caldata = NULL;
149 + bool fastcc = true;
150 + bool flush = false;
153 + __ath_cancel_work(sc);
155 + spin_lock_bh(&sc->sc_pcu_lock);
157 + if (!(sc->sc_flags & SC_OP_OFFCHANNEL)) {
159 + caldata = &sc->caldata;
165 + hchan = ah->curchan;
168 + if (fastcc && !ath9k_hw_check_alive(ah))
171 + if (!ath_prepare_reset(sc, retry_tx, flush))
174 + ath_dbg(common, ATH_DBG_CONFIG,
175 + "Reset to %u MHz, HT40: %d fastcc: %d\n",
176 + hchan->channel, !!(hchan->channelFlags & (CHANNEL_HT40MINUS |
177 + CHANNEL_HT40PLUS)),
180 + r = ath9k_hw_reset(ah, hchan, caldata, fastcc);
183 + "Unable to reset channel, reset status %d\n", r);
187 + if (!ath_complete_reset(sc, true))
191 spin_unlock_bh(&sc->sc_pcu_lock);
197 + * Set/change channels. If the channel is really being changed, it's done
198 + * by reseting the chip. To accomplish this we must first cleanup any pending
199 + * DMA, then restart stuff.
201 +static int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
202 + struct ath9k_channel *hchan)
206 + if (sc->sc_flags & SC_OP_INVALID)
209 + ath9k_ps_wakeup(sc);
211 + r = ath_reset_internal(sc, hchan, false);
213 ath9k_ps_restore(sc);
218 @@ -824,28 +869,13 @@ static void ath_radio_enable(struct ath_
219 channel->center_freq, r);
222 - ath9k_cmn_update_txpow(ah, sc->curtxpow,
223 - sc->config.txpowlimit, &sc->curtxpow);
224 - if (ath_startrecv(sc) != 0) {
225 - ath_err(common, "Unable to restart recv logic\n");
228 - if (sc->sc_flags & SC_OP_BEACONS)
229 - ath_set_beacon(sc); /* restart beacons */
231 - /* Re-Enable interrupts */
232 - ath9k_hw_set_interrupts(ah, ah->imask);
233 - ath9k_hw_enable_interrupts(ah);
234 + ath_complete_reset(sc, true);
237 ath9k_hw_cfg_output(ah, ah->led_pin,
238 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
239 ath9k_hw_set_gpio(ah, ah->led_pin, 0);
241 - ieee80211_wake_queues(hw);
242 - ieee80211_queue_delayed_work(hw, &sc->hw_pll_work, HZ/2);
245 spin_unlock_bh(&sc->sc_pcu_lock);
247 ath9k_ps_restore(sc);
248 @@ -858,11 +888,10 @@ void ath_radio_disable(struct ath_softc
252 - cancel_delayed_work_sync(&sc->hw_pll_work);
254 - spin_lock_bh(&sc->sc_pcu_lock);
255 + ath_cancel_work(sc);
257 - ieee80211_stop_queues(hw);
258 + spin_lock_bh(&sc->sc_pcu_lock);
261 * Keep the LED on when the radio is disabled
262 @@ -873,13 +902,7 @@ void ath_radio_disable(struct ath_softc
263 ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
266 - /* Disable interrupts */
267 - ath9k_hw_disable_interrupts(ah);
269 - ath_drain_all_txq(sc, false); /* clear pending tx frames */
271 - ath_stoprecv(sc); /* turn off frame recv */
272 - ath_flushrecv(sc); /* flush recv queue */
273 + ath_prepare_reset(sc, false, true);
276 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
277 @@ -901,48 +924,11 @@ void ath_radio_disable(struct ath_softc
279 static int ath_reset(struct ath_softc *sc, bool retry_tx)
281 - struct ath_hw *ah = sc->sc_ah;
282 - struct ath_common *common = ath9k_hw_common(ah);
283 - struct ieee80211_hw *hw = sc->hw;
286 - sc->hw_busy_count = 0;
290 - del_timer_sync(&common->ani.timer);
294 - ieee80211_stop_queues(hw);
296 - ath9k_hw_disable_interrupts(ah);
297 - ath_drain_all_txq(sc, retry_tx);
302 - r = ath9k_hw_reset(ah, sc->sc_ah->curchan, ah->caldata, false);
305 - "Unable to reset hardware; reset status %d\n", r);
307 - if (ath_startrecv(sc) != 0)
308 - ath_err(common, "Unable to start recv logic\n");
311 - * We may be doing a reset in response to a request
312 - * that changes the channel so update any state that
313 - * might change as a result.
315 - ath9k_cmn_update_txpow(ah, sc->curtxpow,
316 - sc->config.txpowlimit, &sc->curtxpow);
318 - if ((sc->sc_flags & SC_OP_BEACONS) || !(sc->sc_flags & (SC_OP_OFFCHANNEL)))
319 - ath_set_beacon(sc); /* restart beacons */
321 - ath9k_hw_set_interrupts(ah, ah->imask);
322 - ath9k_hw_enable_interrupts(ah);
323 + r = ath_reset_internal(sc, NULL, retry_tx);
327 @@ -955,12 +941,6 @@ static int ath_reset(struct ath_softc *s
331 - ieee80211_wake_queues(hw);
334 - if (!common->disable_ani)
335 - ath_start_ani(common);
337 ath9k_ps_restore(sc);
340 @@ -970,9 +950,7 @@ void ath_reset_work(struct work_struct *
342 struct ath_softc *sc = container_of(work, struct ath_softc, hw_reset_work);
344 - spin_lock_bh(&sc->sc_pcu_lock);
346 - spin_unlock_bh(&sc->sc_pcu_lock);
349 void ath_hw_check(struct work_struct *work)
350 @@ -993,11 +971,8 @@ void ath_hw_check(struct work_struct *wo
351 ath_dbg(common, ATH_DBG_RESET, "Possible baseband hang, "
352 "busy=%d (try %d)\n", busy, sc->hw_busy_count + 1);
354 - if (++sc->hw_busy_count >= 3) {
355 - spin_lock_bh(&sc->sc_pcu_lock);
356 - ath_reset(sc, true);
357 - spin_unlock_bh(&sc->sc_pcu_lock);
359 + if (++sc->hw_busy_count >= 3)
360 + ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
362 } else if (busy >= 0)
363 sc->hw_busy_count = 0;
364 @@ -1017,9 +992,7 @@ static void ath_hw_pll_rx_hang_check(str
365 /* Rx is hung for more than 500ms. Reset it */
366 ath_dbg(common, ATH_DBG_RESET,
367 "Possible RX hang, resetting");
368 - spin_lock_bh(&sc->sc_pcu_lock);
369 - ath_reset(sc, true);
370 - spin_unlock_bh(&sc->sc_pcu_lock);
371 + ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
375 @@ -1090,28 +1063,6 @@ static int ath9k_start(struct ieee80211_
380 - * This is needed only to setup initial state
381 - * but it's best done after a reset.
383 - ath9k_cmn_update_txpow(ah, sc->curtxpow,
384 - sc->config.txpowlimit, &sc->curtxpow);
387 - * Setup the hardware after reset:
388 - * The receive engine is set going.
389 - * Frame transmit is handled entirely
390 - * in the frame output path; there's nothing to do
391 - * here except setup the interrupt mask.
393 - if (ath_startrecv(sc) != 0) {
394 - ath_err(common, "Unable to start recv logic\n");
396 - spin_unlock_bh(&sc->sc_pcu_lock);
399 - spin_unlock_bh(&sc->sc_pcu_lock);
401 /* Setup our intr mask. */
402 ah->imask = ATH9K_INT_TX | ATH9K_INT_RXEOL |
403 ATH9K_INT_RXORN | ATH9K_INT_FATAL |
404 @@ -1134,12 +1085,14 @@ static int ath9k_start(struct ieee80211_
406 /* Disable BMISS interrupt when we're not associated */
407 ah->imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
408 - ath9k_hw_set_interrupts(ah, ah->imask);
409 - ath9k_hw_enable_interrupts(ah);
411 - ieee80211_wake_queues(hw);
412 + if (!ath_complete_reset(sc, false)) {
414 + spin_unlock_bh(&sc->sc_pcu_lock);
418 - ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
419 + spin_unlock_bh(&sc->sc_pcu_lock);
421 if ((ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE) &&
422 !ah->btcoex_hw.enabled) {
423 @@ -1232,11 +1185,7 @@ static void ath9k_stop(struct ieee80211_
425 mutex_lock(&sc->mutex);
427 - cancel_delayed_work_sync(&sc->tx_complete_work);
428 - cancel_delayed_work_sync(&sc->hw_pll_work);
429 - cancel_work_sync(&sc->paprd_work);
430 - cancel_work_sync(&sc->hw_check_work);
431 - cancel_work_sync(&sc->hw_reset_work);
432 + ath_cancel_work(sc);
434 if (sc->sc_flags & SC_OP_INVALID) {
435 ath_dbg(common, ATH_DBG_ANY, "Device not present\n");
436 @@ -2353,9 +2302,11 @@ static void ath9k_flush(struct ieee80211
438 spin_lock_bh(&sc->sc_pcu_lock);
439 drain_txq = ath_drain_all_txq(sc, false);
440 + spin_unlock_bh(&sc->sc_pcu_lock);
443 ath_reset(sc, false);
444 - spin_unlock_bh(&sc->sc_pcu_lock);
446 ath9k_ps_restore(sc);
447 ieee80211_wake_queues(hw);