1 --- a/drivers/net/wireless/ath/ath9k/main.c
2 +++ b/drivers/net/wireless/ath/ath9k/main.c
3 @@ -212,83 +212,46 @@ 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 bool ath_prepare_reset(struct ath_softc *sc, bool retry_tx, bool flush)
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;
25 - if (sc->sc_flags & SC_OP_INVALID)
27 + ieee80211_stop_queues(sc->hw);
29 sc->hw_busy_count = 0;
31 del_timer_sync(&common->ani.timer);
32 cancel_work_sync(&sc->paprd_work);
33 cancel_work_sync(&sc->hw_check_work);
34 cancel_delayed_work_sync(&sc->tx_complete_work);
35 cancel_delayed_work_sync(&sc->hw_pll_work);
37 - ath9k_ps_wakeup(sc);
39 - spin_lock_bh(&sc->sc_pcu_lock);
42 - * This is only performed if the channel settings have
45 - * To switch channels clear any pending DMA operations;
46 - * wait long enough for the RX fifo to drain, reset the
47 - * hardware at the new frequency, and then re-enable
48 - * the relevant bits of the h/w.
50 ath9k_hw_disable_interrupts(ah);
51 - stopped = ath_drain_all_txq(sc, false);
53 - if (!ath_stoprecv(sc))
55 + ret = ath_drain_all_txq(sc, retry_tx);
57 - if (!ath9k_hw_check_alive(ah))
60 - /* XXX: do not flush receive queue here. We don't want
61 - * to flush data frames already in queue because of
62 - * changing channel. */
64 - if (!stopped || !(sc->sc_flags & SC_OP_OFFCHANNEL))
66 + if (!ath_stoprecv(sc))
69 - if (!(sc->sc_flags & SC_OP_OFFCHANNEL))
70 - caldata = &sc->caldata;
72 + if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
73 + ath_rx_tasklet(sc, 0, true);
74 + ath_rx_tasklet(sc, 0, false);
79 - ath_dbg(common, ATH_DBG_CONFIG,
80 - "(%u MHz) -> (%u MHz), conf_is_ht40: %d fastcc: %d\n",
81 - sc->sc_ah->curchan->channel,
82 - channel->center_freq, conf_is_ht40(conf),
87 - r = ath9k_hw_reset(ah, hchan, caldata, fastcc);
90 - "Unable to reset channel (%u MHz), reset status %d\n",
91 - channel->center_freq, r);
94 +static bool ath_complete_reset(struct ath_softc *sc, bool start)
96 + struct ath_hw *ah = sc->sc_ah;
97 + struct ath_common *common = ath9k_hw_common(ah);
99 if (ath_startrecv(sc) != 0) {
100 ath_err(common, "Unable to restart recv logic\n");
106 ath9k_cmn_update_txpow(ah, sc->curtxpow,
107 @@ -296,21 +259,89 @@ static int ath_set_channel(struct ath_so
108 ath9k_hw_set_interrupts(ah, ah->imask);
109 ath9k_hw_enable_interrupts(ah);
111 - if (!(sc->sc_flags & (SC_OP_OFFCHANNEL))) {
112 + if (!(sc->sc_flags & (SC_OP_OFFCHANNEL)) && start) {
113 if (sc->sc_flags & SC_OP_BEACONS)
116 ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
117 ieee80211_queue_delayed_work(sc->hw, &sc->hw_pll_work, HZ/2);
118 if (!common->disable_ani)
119 ath_start_ani(common);
123 - ieee80211_wake_queues(hw);
124 + ieee80211_wake_queues(sc->hw);
129 +static int ath_reset_internal(struct ath_softc *sc, struct ath9k_channel *hchan,
132 + struct ath_hw *ah = sc->sc_ah;
133 + struct ath_common *common = ath9k_hw_common(ah);
134 + struct ath9k_hw_cal_data *caldata = NULL;
135 + bool fastcc = true;
136 + bool flush = false;
139 + if (!(sc->sc_flags & SC_OP_OFFCHANNEL)) {
141 + caldata = &sc->caldata;
147 + hchan = ah->curchan;
150 + if (fastcc && !ath9k_hw_check_alive(ah))
153 + if (!ath_prepare_reset(sc, retry_tx, flush))
156 + ath_dbg(common, ATH_DBG_CONFIG,
157 + "Reset to %u MHz, HT40: %d fastcc: %d\n",
158 + hchan->channel, !!(hchan->channelFlags & (CHANNEL_HT40MINUS |
159 + CHANNEL_HT40PLUS)),
162 + r = ath9k_hw_reset(ah, hchan, caldata, fastcc);
165 + "Unable to reset channel, reset status %d\n", r);
169 + if (!ath_complete_reset(sc, true))
177 + * Set/change channels. If the channel is really being changed, it's done
178 + * by reseting the chip. To accomplish this we must first cleanup any pending
179 + * DMA, then restart stuff.
181 +static int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
182 + struct ath9k_channel *hchan)
186 + if (sc->sc_flags & SC_OP_INVALID)
189 + ath9k_ps_wakeup(sc);
191 + spin_lock_bh(&sc->sc_pcu_lock);
192 + r = ath_reset_internal(sc, hchan, false);
193 spin_unlock_bh(&sc->sc_pcu_lock);
195 ath9k_ps_restore(sc);
200 @@ -893,28 +924,13 @@ static void ath_radio_enable(struct ath_
201 channel->center_freq, r);
204 - ath9k_cmn_update_txpow(ah, sc->curtxpow,
205 - sc->config.txpowlimit, &sc->curtxpow);
206 - if (ath_startrecv(sc) != 0) {
207 - ath_err(common, "Unable to restart recv logic\n");
210 - if (sc->sc_flags & SC_OP_BEACONS)
211 - ath_set_beacon(sc); /* restart beacons */
213 - /* Re-Enable interrupts */
214 - ath9k_hw_set_interrupts(ah, ah->imask);
215 - ath9k_hw_enable_interrupts(ah);
216 + ath_complete_reset(sc, true);
219 ath9k_hw_cfg_output(ah, ah->led_pin,
220 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
221 ath9k_hw_set_gpio(ah, ah->led_pin, 0);
223 - ieee80211_wake_queues(hw);
224 - ieee80211_queue_delayed_work(hw, &sc->hw_pll_work, HZ/2);
227 spin_unlock_bh(&sc->sc_pcu_lock);
229 ath9k_ps_restore(sc);
230 @@ -927,12 +943,8 @@ void ath_radio_disable(struct ath_softc
234 - cancel_delayed_work_sync(&sc->hw_pll_work);
236 spin_lock_bh(&sc->sc_pcu_lock);
238 - ieee80211_stop_queues(hw);
241 * Keep the LED on when the radio is disabled
242 * during idle unassociated state.
243 @@ -942,13 +954,7 @@ void ath_radio_disable(struct ath_softc
244 ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
247 - /* Disable interrupts */
248 - ath9k_hw_disable_interrupts(ah);
250 - ath_drain_all_txq(sc, false); /* clear pending tx frames */
252 - ath_stoprecv(sc); /* turn off frame recv */
253 - ath_flushrecv(sc); /* flush recv queue */
254 + ath_prepare_reset(sc, false, true);
257 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
258 @@ -970,48 +976,11 @@ void ath_radio_disable(struct ath_softc
260 int ath_reset(struct ath_softc *sc, bool retry_tx)
262 - struct ath_hw *ah = sc->sc_ah;
263 - struct ath_common *common = ath9k_hw_common(ah);
264 - struct ieee80211_hw *hw = sc->hw;
267 - sc->hw_busy_count = 0;
271 - del_timer_sync(&common->ani.timer);
275 - ieee80211_stop_queues(hw);
277 - ath9k_hw_disable_interrupts(ah);
278 - ath_drain_all_txq(sc, retry_tx);
283 - r = ath9k_hw_reset(ah, sc->sc_ah->curchan, ah->caldata, false);
286 - "Unable to reset hardware; reset status %d\n", r);
288 - if (ath_startrecv(sc) != 0)
289 - ath_err(common, "Unable to start recv logic\n");
292 - * We may be doing a reset in response to a request
293 - * that changes the channel so update any state that
294 - * might change as a result.
296 - ath9k_cmn_update_txpow(ah, sc->curtxpow,
297 - sc->config.txpowlimit, &sc->curtxpow);
299 - if ((sc->sc_flags & SC_OP_BEACONS) || !(sc->sc_flags & (SC_OP_OFFCHANNEL)))
300 - ath_set_beacon(sc); /* restart beacons */
302 - ath9k_hw_set_interrupts(ah, ah->imask);
303 - ath9k_hw_enable_interrupts(ah);
304 + r = ath_reset_internal(sc, NULL, retry_tx);
308 @@ -1024,12 +993,6 @@ int ath_reset(struct ath_softc *sc, bool
312 - ieee80211_wake_queues(hw);
315 - if (!common->disable_ani)
316 - ath_start_ani(common);
318 ath9k_ps_restore(sc);
321 @@ -1081,28 +1044,6 @@ static int ath9k_start(struct ieee80211_
326 - * This is needed only to setup initial state
327 - * but it's best done after a reset.
329 - ath9k_cmn_update_txpow(ah, sc->curtxpow,
330 - sc->config.txpowlimit, &sc->curtxpow);
333 - * Setup the hardware after reset:
334 - * The receive engine is set going.
335 - * Frame transmit is handled entirely
336 - * in the frame output path; there's nothing to do
337 - * here except setup the interrupt mask.
339 - if (ath_startrecv(sc) != 0) {
340 - ath_err(common, "Unable to start recv logic\n");
342 - spin_unlock_bh(&sc->sc_pcu_lock);
345 - spin_unlock_bh(&sc->sc_pcu_lock);
347 /* Setup our intr mask. */
348 ah->imask = ATH9K_INT_TX | ATH9K_INT_RXEOL |
349 ATH9K_INT_RXORN | ATH9K_INT_FATAL |
350 @@ -1125,12 +1066,14 @@ static int ath9k_start(struct ieee80211_
352 /* Disable BMISS interrupt when we're not associated */
353 ah->imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
354 - ath9k_hw_set_interrupts(ah, ah->imask);
355 - ath9k_hw_enable_interrupts(ah);
357 - ieee80211_wake_queues(hw);
358 + if (!ath_complete_reset(sc, false)) {
360 + spin_unlock_bh(&sc->sc_pcu_lock);
364 - ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
365 + spin_unlock_bh(&sc->sc_pcu_lock);
367 if ((ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE) &&
368 !ah->btcoex_hw.enabled) {