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,95 @@ 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 + sc->sc_flags &= ~SC_OP_HW_RESET;
159 + if (!(sc->sc_flags & SC_OP_OFFCHANNEL)) {
161 + caldata = &sc->caldata;
167 + hchan = ah->curchan;
170 + if (fastcc && !ath9k_hw_check_alive(ah))
173 + if (!ath_prepare_reset(sc, retry_tx, flush))
176 + ath_dbg(common, ATH_DBG_CONFIG,
177 + "Reset to %u MHz, HT40: %d fastcc: %d\n",
178 + hchan->channel, !!(hchan->channelFlags & (CHANNEL_HT40MINUS |
179 + CHANNEL_HT40PLUS)),
182 + r = ath9k_hw_reset(ah, hchan, caldata, fastcc);
185 + "Unable to reset channel, reset status %d\n", r);
189 + if (!ath_complete_reset(sc, true))
193 spin_unlock_bh(&sc->sc_pcu_lock);
199 + * Set/change channels. If the channel is really being changed, it's done
200 + * by reseting the chip. To accomplish this we must first cleanup any pending
201 + * DMA, then restart stuff.
203 +static int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
204 + struct ath9k_channel *hchan)
208 + if (sc->sc_flags & SC_OP_INVALID)
211 + ath9k_ps_wakeup(sc);
213 + r = ath_reset_internal(sc, hchan, false);
215 ath9k_ps_restore(sc);
220 @@ -824,28 +871,13 @@ static void ath_radio_enable(struct ath_
221 channel->center_freq, r);
224 - ath9k_cmn_update_txpow(ah, sc->curtxpow,
225 - sc->config.txpowlimit, &sc->curtxpow);
226 - if (ath_startrecv(sc) != 0) {
227 - ath_err(common, "Unable to restart recv logic\n");
230 - if (sc->sc_flags & SC_OP_BEACONS)
231 - ath_set_beacon(sc); /* restart beacons */
233 - /* Re-Enable interrupts */
234 - ath9k_hw_set_interrupts(ah, ah->imask);
235 - ath9k_hw_enable_interrupts(ah);
236 + ath_complete_reset(sc, true);
239 ath9k_hw_cfg_output(ah, ah->led_pin,
240 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
241 ath9k_hw_set_gpio(ah, ah->led_pin, 0);
243 - ieee80211_wake_queues(hw);
244 - ieee80211_queue_delayed_work(hw, &sc->hw_pll_work, HZ/2);
247 spin_unlock_bh(&sc->sc_pcu_lock);
249 ath9k_ps_restore(sc);
250 @@ -858,11 +890,10 @@ void ath_radio_disable(struct ath_softc
254 - cancel_delayed_work_sync(&sc->hw_pll_work);
256 - spin_lock_bh(&sc->sc_pcu_lock);
257 + ath_cancel_work(sc);
259 - ieee80211_stop_queues(hw);
260 + spin_lock_bh(&sc->sc_pcu_lock);
263 * Keep the LED on when the radio is disabled
264 @@ -873,13 +904,7 @@ void ath_radio_disable(struct ath_softc
265 ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
268 - /* Disable interrupts */
269 - ath9k_hw_disable_interrupts(ah);
271 - ath_drain_all_txq(sc, false); /* clear pending tx frames */
273 - ath_stoprecv(sc); /* turn off frame recv */
274 - ath_flushrecv(sc); /* flush recv queue */
275 + ath_prepare_reset(sc, false, true);
278 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
279 @@ -901,49 +926,11 @@ void ath_radio_disable(struct ath_softc
281 static int ath_reset(struct ath_softc *sc, bool retry_tx)
283 - struct ath_hw *ah = sc->sc_ah;
284 - struct ath_common *common = ath9k_hw_common(ah);
285 - struct ieee80211_hw *hw = sc->hw;
288 - sc->sc_flags &= ~SC_OP_HW_RESET;
289 - sc->hw_busy_count = 0;
293 - del_timer_sync(&common->ani.timer);
297 - ieee80211_stop_queues(hw);
299 - ath9k_hw_disable_interrupts(ah);
300 - ath_drain_all_txq(sc, retry_tx);
305 - r = ath9k_hw_reset(ah, sc->sc_ah->curchan, ah->caldata, false);
308 - "Unable to reset hardware; reset status %d\n", r);
310 - if (ath_startrecv(sc) != 0)
311 - ath_err(common, "Unable to start recv logic\n");
314 - * We may be doing a reset in response to a request
315 - * that changes the channel so update any state that
316 - * might change as a result.
318 - ath9k_cmn_update_txpow(ah, sc->curtxpow,
319 - sc->config.txpowlimit, &sc->curtxpow);
321 - if ((sc->sc_flags & SC_OP_BEACONS) || !(sc->sc_flags & (SC_OP_OFFCHANNEL)))
322 - ath_set_beacon(sc); /* restart beacons */
324 - ath9k_hw_set_interrupts(ah, ah->imask);
325 - ath9k_hw_enable_interrupts(ah);
326 + r = ath_reset_internal(sc, NULL, retry_tx);
330 @@ -956,12 +943,6 @@ static int ath_reset(struct ath_softc *s
334 - ieee80211_wake_queues(hw);
337 - if (!common->disable_ani)
338 - ath_start_ani(common);
340 ath9k_ps_restore(sc);
343 @@ -971,9 +952,7 @@ void ath_reset_work(struct work_struct *
345 struct ath_softc *sc = container_of(work, struct ath_softc, hw_check_work);
347 - spin_lock_bh(&sc->sc_pcu_lock);
349 - spin_unlock_bh(&sc->sc_pcu_lock);
352 void ath_hw_check(struct work_struct *work)
353 @@ -994,11 +973,8 @@ void ath_hw_check(struct work_struct *wo
354 ath_dbg(common, ATH_DBG_RESET, "Possible baseband hang, "
355 "busy=%d (try %d)\n", busy, sc->hw_busy_count + 1);
357 - if (++sc->hw_busy_count >= 3) {
358 - spin_lock_bh(&sc->sc_pcu_lock);
359 - ath_reset(sc, true);
360 - spin_unlock_bh(&sc->sc_pcu_lock);
362 + if (++sc->hw_busy_count >= 3)
363 + ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
365 } else if (busy >= 0)
366 sc->hw_busy_count = 0;
367 @@ -1018,9 +994,7 @@ static void ath_hw_pll_rx_hang_check(str
368 /* Rx is hung for more than 500ms. Reset it */
369 ath_dbg(common, ATH_DBG_RESET,
370 "Possible RX hang, resetting");
371 - spin_lock_bh(&sc->sc_pcu_lock);
372 - ath_reset(sc, true);
373 - spin_unlock_bh(&sc->sc_pcu_lock);
374 + ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
378 @@ -1091,28 +1065,6 @@ static int ath9k_start(struct ieee80211_
383 - * This is needed only to setup initial state
384 - * but it's best done after a reset.
386 - ath9k_cmn_update_txpow(ah, sc->curtxpow,
387 - sc->config.txpowlimit, &sc->curtxpow);
390 - * Setup the hardware after reset:
391 - * The receive engine is set going.
392 - * Frame transmit is handled entirely
393 - * in the frame output path; there's nothing to do
394 - * here except setup the interrupt mask.
396 - if (ath_startrecv(sc) != 0) {
397 - ath_err(common, "Unable to start recv logic\n");
399 - spin_unlock_bh(&sc->sc_pcu_lock);
402 - spin_unlock_bh(&sc->sc_pcu_lock);
404 /* Setup our intr mask. */
405 ah->imask = ATH9K_INT_TX | ATH9K_INT_RXEOL |
406 ATH9K_INT_RXORN | ATH9K_INT_FATAL |
407 @@ -1135,12 +1087,14 @@ static int ath9k_start(struct ieee80211_
409 /* Disable BMISS interrupt when we're not associated */
410 ah->imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
411 - ath9k_hw_set_interrupts(ah, ah->imask);
412 - ath9k_hw_enable_interrupts(ah);
414 - ieee80211_wake_queues(hw);
415 + if (!ath_complete_reset(sc, false)) {
417 + spin_unlock_bh(&sc->sc_pcu_lock);
421 - ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
422 + spin_unlock_bh(&sc->sc_pcu_lock);
424 if ((ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE) &&
425 !ah->btcoex_hw.enabled) {
426 @@ -1233,11 +1187,7 @@ static void ath9k_stop(struct ieee80211_
428 mutex_lock(&sc->mutex);
430 - cancel_delayed_work_sync(&sc->tx_complete_work);
431 - cancel_delayed_work_sync(&sc->hw_pll_work);
432 - cancel_work_sync(&sc->paprd_work);
433 - cancel_work_sync(&sc->hw_check_work);
434 - cancel_work_sync(&sc->hw_reset_work);
435 + ath_cancel_work(sc);
437 if (sc->sc_flags & SC_OP_INVALID) {
438 ath_dbg(common, ATH_DBG_ANY, "Device not present\n");
439 @@ -2354,9 +2304,11 @@ static void ath9k_flush(struct ieee80211
441 spin_lock_bh(&sc->sc_pcu_lock);
442 drain_txq = ath_drain_all_txq(sc, false);
443 + spin_unlock_bh(&sc->sc_pcu_lock);
446 ath_reset(sc, false);
447 - spin_unlock_bh(&sc->sc_pcu_lock);
449 ath9k_ps_restore(sc);
450 ieee80211_wake_queues(hw);