ath9k: add some fixes for radio reinit and frame flush
[openwrt.git] / package / mac80211 / patches / 560-ath9k_fix_radio_stop.patch
1 --- a/drivers/net/wireless/ath/ath9k/main.c
2 +++ b/drivers/net/wireless/ath/ath9k/main.c
3 @@ -124,14 +124,14 @@ void ath9k_ps_restore(struct ath_softc *
4                  !(sc->ps_flags & (PS_WAIT_FOR_BEACON |
5                               PS_WAIT_FOR_CAB |
6                               PS_WAIT_FOR_PSPOLL_DATA |
7 -                             PS_WAIT_FOR_TX_ACK)))
8 +                             PS_WAIT_FOR_TX_ACK))) {
9                 mode = ATH9K_PM_NETWORK_SLEEP;
10 -       else
11 -               goto unlock;
12  
13 -       spin_lock(&common->cc_lock);
14 -       ath_hw_cycle_counters_update(common);
15 -       spin_unlock(&common->cc_lock);
16 +               spin_lock(&common->cc_lock);
17 +               ath_hw_cycle_counters_update(common);
18 +               spin_unlock(&common->cc_lock);
19 +       } else
20 +               goto unlock;
21  
22         ath9k_hw_setpower(sc->sc_ah, mode);
23  
24 @@ -880,82 +880,6 @@ chip_reset:
25  #undef SCHED_INTR
26  }
27  
28 -static void ath_radio_enable(struct ath_softc *sc, struct ieee80211_hw *hw)
29 -{
30 -       struct ath_hw *ah = sc->sc_ah;
31 -       struct ath_common *common = ath9k_hw_common(ah);
32 -       struct ieee80211_channel *channel = hw->conf.channel;
33 -       int r;
34 -
35 -       ath9k_ps_wakeup(sc);
36 -       spin_lock_bh(&sc->sc_pcu_lock);
37 -       atomic_set(&ah->intr_ref_cnt, -1);
38 -
39 -       ath9k_hw_configpcipowersave(ah, false);
40 -
41 -       if (!ah->curchan)
42 -               ah->curchan = ath9k_cmn_get_curchannel(sc->hw, ah);
43 -
44 -       r = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
45 -       if (r) {
46 -               ath_err(common,
47 -                       "Unable to reset channel (%u MHz), reset status %d\n",
48 -                       channel->center_freq, r);
49 -       }
50 -
51 -       ath_complete_reset(sc, true);
52 -
53 -       /* Enable LED */
54 -       ath9k_hw_cfg_output(ah, ah->led_pin,
55 -                           AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
56 -       ath9k_hw_set_gpio(ah, ah->led_pin, 0);
57 -
58 -       spin_unlock_bh(&sc->sc_pcu_lock);
59 -
60 -       ath9k_ps_restore(sc);
61 -}
62 -
63 -void ath_radio_disable(struct ath_softc *sc, struct ieee80211_hw *hw)
64 -{
65 -       struct ath_hw *ah = sc->sc_ah;
66 -       struct ieee80211_channel *channel = hw->conf.channel;
67 -       int r;
68 -
69 -       ath9k_ps_wakeup(sc);
70 -
71 -       ath_cancel_work(sc);
72 -
73 -       spin_lock_bh(&sc->sc_pcu_lock);
74 -
75 -       /*
76 -        * Keep the LED on when the radio is disabled
77 -        * during idle unassociated state.
78 -        */
79 -       if (!sc->ps_idle) {
80 -               ath9k_hw_set_gpio(ah, ah->led_pin, 1);
81 -               ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
82 -       }
83 -
84 -       ath_prepare_reset(sc, false, true);
85 -
86 -       if (!ah->curchan)
87 -               ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
88 -
89 -       r = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
90 -       if (r) {
91 -               ath_err(ath9k_hw_common(sc->sc_ah),
92 -                       "Unable to reset channel (%u MHz), reset status %d\n",
93 -                       channel->center_freq, r);
94 -       }
95 -
96 -       ath9k_hw_phy_disable(ah);
97 -
98 -       ath9k_hw_configpcipowersave(ah, true);
99 -
100 -       spin_unlock_bh(&sc->sc_pcu_lock);
101 -       ath9k_ps_restore(sc);
102 -}
103 -
104  static int ath_reset(struct ath_softc *sc, bool retry_tx)
105  {
106         int r;
107 @@ -1091,6 +1015,9 @@ static int ath9k_start(struct ieee80211_
108          * and then setup of the interrupt mask.
109          */
110         spin_lock_bh(&sc->sc_pcu_lock);
111 +
112 +       atomic_set(&ah->intr_ref_cnt, -1);
113 +
114         r = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
115         if (r) {
116                 ath_err(common,
117 @@ -1129,6 +1056,16 @@ static int ath9k_start(struct ieee80211_
118                 goto mutex_unlock;
119         }
120  
121 +       ath9k_hw_cfg_output(ah, ah->led_pin,
122 +                           AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
123 +       ath9k_hw_set_gpio(ah, ah->led_pin, 0);
124 +
125 +       /*
126 +        * Reset key cache to sane defaults (all entries cleared) instead of
127 +        * semi-random values after suspend/resume.
128 +        */
129 +       ath9k_cmn_init_crypto(sc->sc_ah);
130 +
131         spin_unlock_bh(&sc->sc_pcu_lock);
132  
133         if ((ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE) &&
134 @@ -1260,9 +1197,6 @@ static void ath9k_stop(struct ieee80211_
135                 sc->rx.frag = NULL;
136         }
137  
138 -       /* disable HAL and put h/w to sleep */
139 -       ath9k_hw_disable(ah);
140 -
141         spin_unlock_bh(&sc->sc_pcu_lock);
142  
143         /* we can now sync irq and kill any running tasklets, since we already
144 @@ -1271,10 +1205,27 @@ static void ath9k_stop(struct ieee80211_
145         tasklet_kill(&sc->intr_tq);
146         tasklet_kill(&sc->bcon_tasklet);
147  
148 -       ath9k_ps_restore(sc);
149 -
150         sc->ps_idle = true;
151 -       ath_radio_disable(sc, hw);
152 +
153 +       spin_lock_bh(&sc->sc_pcu_lock);
154 +
155 +       ath9k_hw_set_gpio(ah, ah->led_pin, 1);
156 +       ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
157 +
158 +       ath_prepare_reset(sc, false, true);
159 +
160 +       if (!ah->curchan)
161 +               ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
162 +
163 +       ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
164 +       ath9k_hw_phy_disable(ah);
165 +       ath9k_hw_disable(ah);
166 +
167 +       ath9k_hw_configpcipowersave(ah, true);
168 +
169 +       spin_unlock_bh(&sc->sc_pcu_lock);
170 +
171 +       ath9k_ps_restore(sc);
172  
173         sc->sc_flags |= SC_OP_INVALID;
174  
175 @@ -1598,8 +1549,8 @@ static int ath9k_config(struct ieee80211
176         struct ath_hw *ah = sc->sc_ah;
177         struct ath_common *common = ath9k_hw_common(ah);
178         struct ieee80211_conf *conf = &hw->conf;
179 -       bool disable_radio = false;
180  
181 +       ath9k_ps_wakeup(sc);
182         mutex_lock(&sc->mutex);
183  
184         /*
185 @@ -1608,16 +1559,8 @@ static int ath9k_config(struct ieee80211
186          * of the changes. Likewise we must only disable the radio towards
187          * the end.
188          */
189 -       if (changed & IEEE80211_CONF_CHANGE_IDLE) {
190 +       if (changed & IEEE80211_CONF_CHANGE_IDLE)
191                 sc->ps_idle = !!(conf->flags & IEEE80211_CONF_IDLE);
192 -               if (!sc->ps_idle) {
193 -                       ath_radio_enable(sc, hw);
194 -                       ath_dbg(common, ATH_DBG_CONFIG,
195 -                               "not-idle: enabling radio\n");
196 -               } else {
197 -                       disable_radio = true;
198 -               }
199 -       }
200  
201         /*
202          * We just prepare to enable PS. We have to wait until our AP has
203 @@ -1742,19 +1685,13 @@ static int ath9k_config(struct ieee80211
204                 ath_dbg(common, ATH_DBG_CONFIG,
205                         "Set power: %d\n", conf->power_level);
206                 sc->config.txpowlimit = 2 * conf->power_level;
207 -               ath9k_ps_wakeup(sc);
208                 ath9k_cmn_update_txpow(ah, sc->curtxpow,
209                                        sc->config.txpowlimit, &sc->curtxpow);
210 -               ath9k_ps_restore(sc);
211                 conf->cur_power_level = sc->curtxpow / 2;
212         }
213  
214 -       if (disable_radio) {
215 -               ath_dbg(common, ATH_DBG_CONFIG, "idle: disabling radio\n");
216 -               ath_radio_disable(sc, hw);
217 -       }
218 -
219         mutex_unlock(&sc->mutex);
220 +       ath9k_ps_restore(sc);
221  
222         return 0;
223  }
224 --- a/drivers/net/wireless/ath/ath9k/pci.c
225 +++ b/drivers/net/wireless/ath/ath9k/pci.c
226 @@ -302,26 +302,12 @@ static void ath_pci_remove(struct pci_de
227  
228  static int ath_pci_suspend(struct device *device)
229  {
230 -       struct pci_dev *pdev = to_pci_dev(device);
231 -       struct ieee80211_hw *hw = pci_get_drvdata(pdev);
232 -       struct ath_softc *sc = hw->priv;
233 -
234 -       ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 1);
235 -
236 -       /* The device has to be moved to FULLSLEEP forcibly.
237 -        * Otherwise the chip never moved to full sleep,
238 -        * when no interface is up.
239 -        */
240 -       ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_FULL_SLEEP);
241 -
242         return 0;
243  }
244  
245  static int ath_pci_resume(struct device *device)
246  {
247         struct pci_dev *pdev = to_pci_dev(device);
248 -       struct ieee80211_hw *hw = pci_get_drvdata(pdev);
249 -       struct ath_softc *sc = hw->priv;
250         u32 val;
251  
252         /*
253 @@ -333,22 +319,6 @@ static int ath_pci_resume(struct device 
254         if ((val & 0x0000ff00) != 0)
255                 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
256  
257 -       ath9k_ps_wakeup(sc);
258 -       /* Enable LED */
259 -       ath9k_hw_cfg_output(sc->sc_ah, sc->sc_ah->led_pin,
260 -                           AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
261 -       ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 0);
262 -
263 -         /*
264 -          * Reset key cache to sane defaults (all entries cleared) instead of
265 -          * semi-random values after suspend/resume.
266 -          */
267 -       ath9k_cmn_init_crypto(sc->sc_ah);
268 -       ath9k_ps_restore(sc);
269 -
270 -       sc->ps_idle = true;
271 -       ath_radio_disable(sc, hw);
272 -
273         return 0;
274  }
275