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,95 @@ 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 + sc->sc_flags &= ~SC_OP_HW_RESET;
158 + if (!(sc->sc_flags & SC_OP_OFFCHANNEL)) {
160 + caldata = &sc->caldata;
166 + hchan = ah->curchan;
169 + if (fastcc && !ath9k_hw_check_alive(ah))
172 + if (!ath_prepare_reset(sc, retry_tx, flush))
175 + ath_dbg(common, ATH_DBG_CONFIG,
176 + "Reset to %u MHz, HT40: %d fastcc: %d\n",
177 + hchan->channel, !!(hchan->channelFlags & (CHANNEL_HT40MINUS |
178 + CHANNEL_HT40PLUS)),
181 + r = ath9k_hw_reset(ah, hchan, caldata, fastcc);
184 + "Unable to reset channel, reset status %d\n", r);
188 + if (!ath_complete_reset(sc, true))
192 spin_unlock_bh(&sc->sc_pcu_lock);
198 + * Set/change channels. If the channel is really being changed, it's done
199 + * by reseting the chip. To accomplish this we must first cleanup any pending
200 + * DMA, then restart stuff.
202 +static int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
203 + struct ath9k_channel *hchan)
207 + if (sc->sc_flags & SC_OP_INVALID)
210 + ath9k_ps_wakeup(sc);
212 + r = ath_reset_internal(sc, hchan, false);
214 ath9k_ps_restore(sc);
219 @@ -823,28 +871,13 @@ static void ath_radio_enable(struct ath_
220 channel->center_freq, r);
223 - ath9k_cmn_update_txpow(ah, sc->curtxpow,
224 - sc->config.txpowlimit, &sc->curtxpow);
225 - if (ath_startrecv(sc) != 0) {
226 - ath_err(common, "Unable to restart recv logic\n");
229 - if (sc->sc_flags & SC_OP_BEACONS)
230 - ath_set_beacon(sc); /* restart beacons */
232 - /* Re-Enable interrupts */
233 - ath9k_hw_set_interrupts(ah, ah->imask);
234 - ath9k_hw_enable_interrupts(ah);
235 + ath_complete_reset(sc, true);
238 ath9k_hw_cfg_output(ah, ah->led_pin,
239 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
240 ath9k_hw_set_gpio(ah, ah->led_pin, 0);
242 - ieee80211_wake_queues(hw);
243 - ieee80211_queue_delayed_work(hw, &sc->hw_pll_work, HZ/2);
246 spin_unlock_bh(&sc->sc_pcu_lock);
248 ath9k_ps_restore(sc);
249 @@ -857,11 +890,10 @@ void ath_radio_disable(struct ath_softc
253 - cancel_delayed_work_sync(&sc->hw_pll_work);
255 - spin_lock_bh(&sc->sc_pcu_lock);
256 + ath_cancel_work(sc);
258 - ieee80211_stop_queues(hw);
259 + spin_lock_bh(&sc->sc_pcu_lock);
262 * Keep the LED on when the radio is disabled
263 @@ -872,13 +904,7 @@ void ath_radio_disable(struct ath_softc
264 ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
267 - /* Disable interrupts */
268 - ath9k_hw_disable_interrupts(ah);
270 - ath_drain_all_txq(sc, false); /* clear pending tx frames */
272 - ath_stoprecv(sc); /* turn off frame recv */
273 - ath_flushrecv(sc); /* flush recv queue */
274 + ath_prepare_reset(sc, false, true);
277 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
278 @@ -900,49 +926,11 @@ void ath_radio_disable(struct ath_softc
280 static int ath_reset(struct ath_softc *sc, bool retry_tx)
282 - struct ath_hw *ah = sc->sc_ah;
283 - struct ath_common *common = ath9k_hw_common(ah);
284 - struct ieee80211_hw *hw = sc->hw;
287 - sc->sc_flags &= ~SC_OP_HW_RESET;
288 - sc->hw_busy_count = 0;
292 - del_timer_sync(&common->ani.timer);
296 - ieee80211_stop_queues(hw);
298 - ath9k_hw_disable_interrupts(ah);
299 - ath_drain_all_txq(sc, retry_tx);
304 - r = ath9k_hw_reset(ah, sc->sc_ah->curchan, ah->caldata, false);
307 - "Unable to reset hardware; reset status %d\n", r);
309 - if (ath_startrecv(sc) != 0)
310 - ath_err(common, "Unable to start recv logic\n");
313 - * We may be doing a reset in response to a request
314 - * that changes the channel so update any state that
315 - * might change as a result.
317 - ath9k_cmn_update_txpow(ah, sc->curtxpow,
318 - sc->config.txpowlimit, &sc->curtxpow);
320 - if ((sc->sc_flags & SC_OP_BEACONS) || !(sc->sc_flags & (SC_OP_OFFCHANNEL)))
321 - ath_set_beacon(sc); /* restart beacons */
323 - ath9k_hw_set_interrupts(ah, ah->imask);
324 - ath9k_hw_enable_interrupts(ah);
325 + r = ath_reset_internal(sc, NULL, retry_tx);
329 @@ -955,12 +943,6 @@ static int ath_reset(struct ath_softc *s
333 - ieee80211_wake_queues(hw);
336 - if (!common->disable_ani)
337 - ath_start_ani(common);
339 ath9k_ps_restore(sc);
342 @@ -970,9 +952,7 @@ void ath_reset_work(struct work_struct *
344 struct ath_softc *sc = container_of(work, struct ath_softc, hw_check_work);
346 - spin_lock_bh(&sc->sc_pcu_lock);
348 - spin_unlock_bh(&sc->sc_pcu_lock);
351 void ath_hw_check(struct work_struct *work)
352 @@ -993,11 +973,8 @@ void ath_hw_check(struct work_struct *wo
353 ath_dbg(common, ATH_DBG_RESET, "Possible baseband hang, "
354 "busy=%d (try %d)\n", busy, sc->hw_busy_count + 1);
356 - if (++sc->hw_busy_count >= 3) {
357 - spin_lock_bh(&sc->sc_pcu_lock);
358 - ath_reset(sc, true);
359 - spin_unlock_bh(&sc->sc_pcu_lock);
361 + if (++sc->hw_busy_count >= 3)
362 + ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
364 } else if (busy >= 0)
365 sc->hw_busy_count = 0;
366 @@ -1017,9 +994,7 @@ static void ath_hw_pll_rx_hang_check(str
367 /* Rx is hung for more than 500ms. Reset it */
368 ath_dbg(common, ATH_DBG_RESET,
369 "Possible RX hang, resetting");
370 - spin_lock_bh(&sc->sc_pcu_lock);
371 - ath_reset(sc, true);
372 - spin_unlock_bh(&sc->sc_pcu_lock);
373 + ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
377 @@ -1090,28 +1065,6 @@ static int ath9k_start(struct ieee80211_
382 - * This is needed only to setup initial state
383 - * but it's best done after a reset.
385 - ath9k_cmn_update_txpow(ah, sc->curtxpow,
386 - sc->config.txpowlimit, &sc->curtxpow);
389 - * Setup the hardware after reset:
390 - * The receive engine is set going.
391 - * Frame transmit is handled entirely
392 - * in the frame output path; there's nothing to do
393 - * here except setup the interrupt mask.
395 - if (ath_startrecv(sc) != 0) {
396 - ath_err(common, "Unable to start recv logic\n");
398 - spin_unlock_bh(&sc->sc_pcu_lock);
401 - spin_unlock_bh(&sc->sc_pcu_lock);
403 /* Setup our intr mask. */
404 ah->imask = ATH9K_INT_TX | ATH9K_INT_RXEOL |
405 ATH9K_INT_RXORN | ATH9K_INT_FATAL |
406 @@ -1134,12 +1087,14 @@ static int ath9k_start(struct ieee80211_
408 /* Disable BMISS interrupt when we're not associated */
409 ah->imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
410 - ath9k_hw_set_interrupts(ah, ah->imask);
411 - ath9k_hw_enable_interrupts(ah);
413 - ieee80211_wake_queues(hw);
414 + if (!ath_complete_reset(sc, false)) {
416 + spin_unlock_bh(&sc->sc_pcu_lock);
420 - ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
421 + spin_unlock_bh(&sc->sc_pcu_lock);
423 if ((ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE) &&
424 !ah->btcoex_hw.enabled) {
425 @@ -1232,10 +1187,7 @@ static void ath9k_stop(struct ieee80211_
427 mutex_lock(&sc->mutex);
429 - cancel_delayed_work_sync(&sc->tx_complete_work);
430 - cancel_delayed_work_sync(&sc->hw_pll_work);
431 - cancel_work_sync(&sc->paprd_work);
432 - cancel_work_sync(&sc->hw_check_work);
433 + ath_cancel_work(sc);
435 if (sc->sc_flags & SC_OP_INVALID) {
436 ath_dbg(common, ATH_DBG_ANY, "Device not present\n");
437 @@ -2352,9 +2304,11 @@ static void ath9k_flush(struct ieee80211
439 spin_lock_bh(&sc->sc_pcu_lock);
440 drain_txq = ath_drain_all_txq(sc, false);
441 + spin_unlock_bh(&sc->sc_pcu_lock);
444 ath_reset(sc, false);
445 - spin_unlock_bh(&sc->sc_pcu_lock);
447 ath9k_ps_restore(sc);
448 ieee80211_wake_queues(hw);