1 --- a/drivers/net/wireless/ath/ath9k/main.c
2 +++ b/drivers/net/wireless/ath/ath9k/main.c
3 @@ -212,83 +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_delayed_work_sync(&sc->tx_complete_work);
33 cancel_delayed_work_sync(&sc->hw_pll_work);
36 - ath9k_ps_wakeup(sc);
37 +static void ath_cancel_work(struct ath_softc *sc)
39 + __ath_cancel_work(sc);
40 + cancel_work_sync(&sc->hw_reset_work);
43 - spin_lock_bh(&sc->sc_pcu_lock);
44 +static bool ath_prepare_reset(struct ath_softc *sc, bool retry_tx, bool flush)
46 + struct ath_hw *ah = sc->sc_ah;
47 + struct ath_common *common = ath9k_hw_common(ah);
51 - * This is only performed if the channel settings have
54 - * To switch channels clear any pending DMA operations;
55 - * wait long enough for the RX fifo to drain, reset the
56 - * hardware at the new frequency, and then re-enable
57 - * the relevant bits of the h/w.
59 - ath9k_hw_disable_interrupts(ah);
60 - stopped = ath_drain_all_txq(sc, false);
61 + ieee80211_stop_queues(sc->hw);
63 - if (!ath_stoprecv(sc))
65 + sc->hw_busy_count = 0;
66 + del_timer_sync(&common->ani.timer);
68 - if (!ath9k_hw_check_alive(ah))
70 + ath9k_hw_disable_interrupts(ah);
72 - /* XXX: do not flush receive queue here. We don't want
73 - * to flush data frames already in queue because of
74 - * changing channel. */
75 + ret = ath_drain_all_txq(sc, retry_tx);
77 - if (!stopped || !(sc->sc_flags & SC_OP_OFFCHANNEL))
79 + if (!ath_stoprecv(sc))
82 - if (!(sc->sc_flags & SC_OP_OFFCHANNEL))
83 - caldata = &sc->caldata;
85 + if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
86 + ath_rx_tasklet(sc, 0, true);
87 + ath_rx_tasklet(sc, 0, false);
92 - ath_dbg(common, ATH_DBG_CONFIG,
93 - "(%u MHz) -> (%u MHz), conf_is_ht40: %d fastcc: %d\n",
94 - sc->sc_ah->curchan->channel,
95 - channel->center_freq, conf_is_ht40(conf),
100 - r = ath9k_hw_reset(ah, hchan, caldata, fastcc);
103 - "Unable to reset channel (%u MHz), reset status %d\n",
104 - channel->center_freq, r);
107 +static bool ath_complete_reset(struct ath_softc *sc, bool start)
109 + struct ath_hw *ah = sc->sc_ah;
110 + struct ath_common *common = ath9k_hw_common(ah);
112 if (ath_startrecv(sc) != 0) {
113 ath_err(common, "Unable to restart recv logic\n");
119 ath9k_cmn_update_txpow(ah, sc->curtxpow,
120 @@ -296,21 +270,93 @@ static int ath_set_channel(struct ath_so
121 ath9k_hw_set_interrupts(ah, ah->imask);
122 ath9k_hw_enable_interrupts(ah);
124 - if (!(sc->sc_flags & (SC_OP_OFFCHANNEL))) {
125 + if (!(sc->sc_flags & (SC_OP_OFFCHANNEL)) && start) {
126 if (sc->sc_flags & SC_OP_BEACONS)
129 ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
130 ieee80211_queue_delayed_work(sc->hw, &sc->hw_pll_work, HZ/2);
131 if (!common->disable_ani)
132 ath_start_ani(common);
136 - ieee80211_wake_queues(hw);
137 + ieee80211_wake_queues(sc->hw);
142 +static int ath_reset_internal(struct ath_softc *sc, struct ath9k_channel *hchan,
145 + struct ath_hw *ah = sc->sc_ah;
146 + struct ath_common *common = ath9k_hw_common(ah);
147 + struct ath9k_hw_cal_data *caldata = NULL;
148 + bool fastcc = true;
149 + bool flush = false;
152 + __ath_cancel_work(sc);
154 + spin_lock_bh(&sc->sc_pcu_lock);
156 + if (!(sc->sc_flags & SC_OP_OFFCHANNEL)) {
158 + caldata = &sc->caldata;
164 + hchan = ah->curchan;
167 + if (fastcc && !ath9k_hw_check_alive(ah))
170 + if (!ath_prepare_reset(sc, retry_tx, flush))
173 + ath_dbg(common, ATH_DBG_CONFIG,
174 + "Reset to %u MHz, HT40: %d fastcc: %d\n",
175 + hchan->channel, !!(hchan->channelFlags & (CHANNEL_HT40MINUS |
176 + CHANNEL_HT40PLUS)),
179 + r = ath9k_hw_reset(ah, hchan, caldata, fastcc);
182 + "Unable to reset channel, reset status %d\n", r);
186 + if (!ath_complete_reset(sc, true))
190 spin_unlock_bh(&sc->sc_pcu_lock);
196 + * Set/change channels. If the channel is really being changed, it's done
197 + * by reseting the chip. To accomplish this we must first cleanup any pending
198 + * DMA, then restart stuff.
200 +static int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
201 + struct ath9k_channel *hchan)
205 + if (sc->sc_flags & SC_OP_INVALID)
208 + ath9k_ps_wakeup(sc);
210 + r = ath_reset_internal(sc, hchan, false);
212 ath9k_ps_restore(sc);
217 @@ -823,28 +869,13 @@ static void ath_radio_enable(struct ath_
218 channel->center_freq, r);
221 - ath9k_cmn_update_txpow(ah, sc->curtxpow,
222 - sc->config.txpowlimit, &sc->curtxpow);
223 - if (ath_startrecv(sc) != 0) {
224 - ath_err(common, "Unable to restart recv logic\n");
227 - if (sc->sc_flags & SC_OP_BEACONS)
228 - ath_set_beacon(sc); /* restart beacons */
230 - /* Re-Enable interrupts */
231 - ath9k_hw_set_interrupts(ah, ah->imask);
232 - ath9k_hw_enable_interrupts(ah);
233 + ath_complete_reset(sc, true);
236 ath9k_hw_cfg_output(ah, ah->led_pin,
237 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
238 ath9k_hw_set_gpio(ah, ah->led_pin, 0);
240 - ieee80211_wake_queues(hw);
241 - ieee80211_queue_delayed_work(hw, &sc->hw_pll_work, HZ/2);
244 spin_unlock_bh(&sc->sc_pcu_lock);
246 ath9k_ps_restore(sc);
247 @@ -857,11 +888,10 @@ void ath_radio_disable(struct ath_softc
251 - cancel_delayed_work_sync(&sc->hw_pll_work);
253 - spin_lock_bh(&sc->sc_pcu_lock);
254 + ath_cancel_work(sc);
256 - ieee80211_stop_queues(hw);
257 + spin_lock_bh(&sc->sc_pcu_lock);
260 * Keep the LED on when the radio is disabled
261 @@ -872,13 +902,7 @@ void ath_radio_disable(struct ath_softc
262 ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
265 - /* Disable interrupts */
266 - ath9k_hw_disable_interrupts(ah);
268 - ath_drain_all_txq(sc, false); /* clear pending tx frames */
270 - ath_stoprecv(sc); /* turn off frame recv */
271 - ath_flushrecv(sc); /* flush recv queue */
272 + ath_prepare_reset(sc, false, true);
275 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
276 @@ -900,48 +924,11 @@ void ath_radio_disable(struct ath_softc
278 static int ath_reset(struct ath_softc *sc, bool retry_tx)
280 - struct ath_hw *ah = sc->sc_ah;
281 - struct ath_common *common = ath9k_hw_common(ah);
282 - struct ieee80211_hw *hw = sc->hw;
285 - sc->hw_busy_count = 0;
289 - del_timer_sync(&common->ani.timer);
293 - ieee80211_stop_queues(hw);
295 - ath9k_hw_disable_interrupts(ah);
296 - ath_drain_all_txq(sc, retry_tx);
301 - r = ath9k_hw_reset(ah, sc->sc_ah->curchan, ah->caldata, false);
304 - "Unable to reset hardware; reset status %d\n", r);
306 - if (ath_startrecv(sc) != 0)
307 - ath_err(common, "Unable to start recv logic\n");
310 - * We may be doing a reset in response to a request
311 - * that changes the channel so update any state that
312 - * might change as a result.
314 - ath9k_cmn_update_txpow(ah, sc->curtxpow,
315 - sc->config.txpowlimit, &sc->curtxpow);
317 - if ((sc->sc_flags & SC_OP_BEACONS) || !(sc->sc_flags & (SC_OP_OFFCHANNEL)))
318 - ath_set_beacon(sc); /* restart beacons */
320 - ath9k_hw_set_interrupts(ah, ah->imask);
321 - ath9k_hw_enable_interrupts(ah);
322 + r = ath_reset_internal(sc, NULL, retry_tx);
326 @@ -954,12 +941,6 @@ static int ath_reset(struct ath_softc *s
330 - ieee80211_wake_queues(hw);
333 - if (!common->disable_ani)
334 - ath_start_ani(common);
336 ath9k_ps_restore(sc);
339 @@ -969,9 +950,7 @@ void ath_reset_work(struct work_struct *
341 struct ath_softc *sc = container_of(work, struct ath_softc, hw_check_work);
343 - spin_lock_bh(&sc->sc_pcu_lock);
345 - spin_unlock_bh(&sc->sc_pcu_lock);
348 void ath_hw_check(struct work_struct *work)
349 @@ -992,11 +971,8 @@ void ath_hw_check(struct work_struct *wo
350 ath_dbg(common, ATH_DBG_RESET, "Possible baseband hang, "
351 "busy=%d (try %d)\n", busy, sc->hw_busy_count + 1);
353 - if (++sc->hw_busy_count >= 3) {
354 - spin_lock_bh(&sc->sc_pcu_lock);
355 - ath_reset(sc, true);
356 - spin_unlock_bh(&sc->sc_pcu_lock);
358 + if (++sc->hw_busy_count >= 3)
359 + ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
361 } else if (busy >= 0)
362 sc->hw_busy_count = 0;
363 @@ -1016,9 +992,7 @@ static void ath_hw_pll_rx_hang_check(str
364 /* Rx is hung for more than 500ms. Reset it */
365 ath_dbg(common, ATH_DBG_RESET,
366 "Possible RX hang, resetting");
367 - spin_lock_bh(&sc->sc_pcu_lock);
368 - ath_reset(sc, true);
369 - spin_unlock_bh(&sc->sc_pcu_lock);
370 + ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
374 @@ -1089,28 +1063,6 @@ static int ath9k_start(struct ieee80211_
379 - * This is needed only to setup initial state
380 - * but it's best done after a reset.
382 - ath9k_cmn_update_txpow(ah, sc->curtxpow,
383 - sc->config.txpowlimit, &sc->curtxpow);
386 - * Setup the hardware after reset:
387 - * The receive engine is set going.
388 - * Frame transmit is handled entirely
389 - * in the frame output path; there's nothing to do
390 - * here except setup the interrupt mask.
392 - if (ath_startrecv(sc) != 0) {
393 - ath_err(common, "Unable to start recv logic\n");
395 - spin_unlock_bh(&sc->sc_pcu_lock);
398 - spin_unlock_bh(&sc->sc_pcu_lock);
400 /* Setup our intr mask. */
401 ah->imask = ATH9K_INT_TX | ATH9K_INT_RXEOL |
402 ATH9K_INT_RXORN | ATH9K_INT_FATAL |
403 @@ -1133,12 +1085,14 @@ static int ath9k_start(struct ieee80211_
405 /* Disable BMISS interrupt when we're not associated */
406 ah->imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
407 - ath9k_hw_set_interrupts(ah, ah->imask);
408 - ath9k_hw_enable_interrupts(ah);
410 - ieee80211_wake_queues(hw);
411 + if (!ath_complete_reset(sc, false)) {
413 + spin_unlock_bh(&sc->sc_pcu_lock);
417 - ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
418 + spin_unlock_bh(&sc->sc_pcu_lock);
420 if ((ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE) &&
421 !ah->btcoex_hw.enabled) {
422 @@ -1231,10 +1185,7 @@ static void ath9k_stop(struct ieee80211_
424 mutex_lock(&sc->mutex);
426 - cancel_delayed_work_sync(&sc->tx_complete_work);
427 - cancel_delayed_work_sync(&sc->hw_pll_work);
428 - cancel_work_sync(&sc->paprd_work);
429 - cancel_work_sync(&sc->hw_check_work);
430 + ath_cancel_work(sc);
432 if (sc->sc_flags & SC_OP_INVALID) {
433 ath_dbg(common, ATH_DBG_ANY, "Device not present\n");
434 @@ -2351,9 +2302,11 @@ static void ath9k_flush(struct ieee80211
436 spin_lock_bh(&sc->sc_pcu_lock);
437 drain_txq = ath_drain_all_txq(sc, false);
438 + spin_unlock_bh(&sc->sc_pcu_lock);
441 ath_reset(sc, false);
442 - spin_unlock_bh(&sc->sc_pcu_lock);
444 ath9k_ps_restore(sc);
445 ieee80211_wake_queues(hw);