]>
Commit | Line | Data |
---|---|---|
f078f209 | 1 | /* |
cee075a2 | 2 | * Copyright (c) 2008-2009 Atheros Communications Inc. |
f078f209 LR |
3 | * |
4 | * Permission to use, copy, modify, and/or distribute this software for any | |
5 | * purpose with or without fee is hereby granted, provided that the above | |
6 | * copyright notice and this permission notice appear in all copies. | |
7 | * | |
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
15 | */ | |
16 | ||
f078f209 | 17 | #include <linux/nl80211.h> |
10598c12 | 18 | #include <linux/pm_qos_params.h> |
394cf0a1 | 19 | #include "ath9k.h" |
af03abec | 20 | #include "btcoex.h" |
f078f209 | 21 | |
ff37e337 S |
22 | static void ath_update_txpow(struct ath_softc *sc) |
23 | { | |
cbe61d8a | 24 | struct ath_hw *ah = sc->sc_ah; |
ff37e337 | 25 | |
17d7904d S |
26 | if (sc->curtxpow != sc->config.txpowlimit) { |
27 | ath9k_hw_set_txpowerlimit(ah, sc->config.txpowlimit); | |
ff37e337 | 28 | /* read back in case value is clamped */ |
9cc3271f | 29 | sc->curtxpow = ath9k_hw_regulatory(ah)->power_limit; |
ff37e337 S |
30 | } |
31 | } | |
32 | ||
33 | static u8 parse_mpdudensity(u8 mpdudensity) | |
34 | { | |
35 | /* | |
36 | * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing": | |
37 | * 0 for no restriction | |
38 | * 1 for 1/4 us | |
39 | * 2 for 1/2 us | |
40 | * 3 for 1 us | |
41 | * 4 for 2 us | |
42 | * 5 for 4 us | |
43 | * 6 for 8 us | |
44 | * 7 for 16 us | |
45 | */ | |
46 | switch (mpdudensity) { | |
47 | case 0: | |
48 | return 0; | |
49 | case 1: | |
50 | case 2: | |
51 | case 3: | |
52 | /* Our lower layer calculations limit our precision to | |
53 | 1 microsecond */ | |
54 | return 1; | |
55 | case 4: | |
56 | return 2; | |
57 | case 5: | |
58 | return 4; | |
59 | case 6: | |
60 | return 8; | |
61 | case 7: | |
62 | return 16; | |
63 | default: | |
64 | return 0; | |
65 | } | |
66 | } | |
67 | ||
82880a7c VT |
68 | static struct ath9k_channel *ath_get_curchannel(struct ath_softc *sc, |
69 | struct ieee80211_hw *hw) | |
70 | { | |
71 | struct ieee80211_channel *curchan = hw->conf.channel; | |
72 | struct ath9k_channel *channel; | |
73 | u8 chan_idx; | |
74 | ||
75 | chan_idx = curchan->hw_value; | |
76 | channel = &sc->sc_ah->channels[chan_idx]; | |
77 | ath9k_update_ichannel(sc, hw, channel); | |
78 | return channel; | |
79 | } | |
80 | ||
55624204 | 81 | bool ath9k_setpower(struct ath_softc *sc, enum ath9k_power_mode mode) |
8c77a569 LR |
82 | { |
83 | unsigned long flags; | |
84 | bool ret; | |
85 | ||
9ecdef4b LR |
86 | spin_lock_irqsave(&sc->sc_pm_lock, flags); |
87 | ret = ath9k_hw_setpower(sc->sc_ah, mode); | |
88 | spin_unlock_irqrestore(&sc->sc_pm_lock, flags); | |
8c77a569 LR |
89 | |
90 | return ret; | |
91 | } | |
92 | ||
a91d75ae LR |
93 | void ath9k_ps_wakeup(struct ath_softc *sc) |
94 | { | |
898c914a | 95 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
a91d75ae | 96 | unsigned long flags; |
fbb078fc | 97 | enum ath9k_power_mode power_mode; |
a91d75ae LR |
98 | |
99 | spin_lock_irqsave(&sc->sc_pm_lock, flags); | |
100 | if (++sc->ps_usecount != 1) | |
101 | goto unlock; | |
102 | ||
fbb078fc | 103 | power_mode = sc->sc_ah->power_mode; |
9ecdef4b | 104 | ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE); |
a91d75ae | 105 | |
898c914a FF |
106 | /* |
107 | * While the hardware is asleep, the cycle counters contain no | |
108 | * useful data. Better clear them now so that they don't mess up | |
109 | * survey data results. | |
110 | */ | |
fbb078fc FF |
111 | if (power_mode != ATH9K_PM_AWAKE) { |
112 | spin_lock(&common->cc_lock); | |
113 | ath_hw_cycle_counters_update(common); | |
114 | memset(&common->cc_survey, 0, sizeof(common->cc_survey)); | |
115 | spin_unlock(&common->cc_lock); | |
116 | } | |
898c914a | 117 | |
a91d75ae LR |
118 | unlock: |
119 | spin_unlock_irqrestore(&sc->sc_pm_lock, flags); | |
120 | } | |
121 | ||
122 | void ath9k_ps_restore(struct ath_softc *sc) | |
123 | { | |
898c914a | 124 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
a91d75ae LR |
125 | unsigned long flags; |
126 | ||
127 | spin_lock_irqsave(&sc->sc_pm_lock, flags); | |
128 | if (--sc->ps_usecount != 0) | |
129 | goto unlock; | |
130 | ||
898c914a FF |
131 | spin_lock(&common->cc_lock); |
132 | ath_hw_cycle_counters_update(common); | |
133 | spin_unlock(&common->cc_lock); | |
134 | ||
1dbfd9d4 VN |
135 | if (sc->ps_idle) |
136 | ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_FULL_SLEEP); | |
137 | else if (sc->ps_enabled && | |
138 | !(sc->ps_flags & (PS_WAIT_FOR_BEACON | | |
1b04b930 S |
139 | PS_WAIT_FOR_CAB | |
140 | PS_WAIT_FOR_PSPOLL_DATA | | |
141 | PS_WAIT_FOR_TX_ACK))) | |
9ecdef4b | 142 | ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_NETWORK_SLEEP); |
a91d75ae LR |
143 | |
144 | unlock: | |
145 | spin_unlock_irqrestore(&sc->sc_pm_lock, flags); | |
146 | } | |
147 | ||
5ee08656 FF |
148 | static void ath_start_ani(struct ath_common *common) |
149 | { | |
150 | struct ath_hw *ah = common->ah; | |
151 | unsigned long timestamp = jiffies_to_msecs(jiffies); | |
152 | struct ath_softc *sc = (struct ath_softc *) common->priv; | |
153 | ||
154 | if (!(sc->sc_flags & SC_OP_ANI_RUN)) | |
155 | return; | |
156 | ||
157 | if (sc->sc_flags & SC_OP_OFFCHANNEL) | |
158 | return; | |
159 | ||
160 | common->ani.longcal_timer = timestamp; | |
161 | common->ani.shortcal_timer = timestamp; | |
162 | common->ani.checkani_timer = timestamp; | |
163 | ||
164 | mod_timer(&common->ani.timer, | |
165 | jiffies + | |
166 | msecs_to_jiffies((u32)ah->config.ani_poll_interval)); | |
167 | } | |
168 | ||
3430098a FF |
169 | static void ath_update_survey_nf(struct ath_softc *sc, int channel) |
170 | { | |
171 | struct ath_hw *ah = sc->sc_ah; | |
172 | struct ath9k_channel *chan = &ah->channels[channel]; | |
173 | struct survey_info *survey = &sc->survey[channel]; | |
174 | ||
175 | if (chan->noisefloor) { | |
176 | survey->filled |= SURVEY_INFO_NOISE_DBM; | |
177 | survey->noise = chan->noisefloor; | |
178 | } | |
179 | } | |
180 | ||
181 | static void ath_update_survey_stats(struct ath_softc *sc) | |
182 | { | |
183 | struct ath_hw *ah = sc->sc_ah; | |
184 | struct ath_common *common = ath9k_hw_common(ah); | |
185 | int pos = ah->curchan - &ah->channels[0]; | |
186 | struct survey_info *survey = &sc->survey[pos]; | |
187 | struct ath_cycle_counters *cc = &common->cc_survey; | |
188 | unsigned int div = common->clockrate * 1000; | |
189 | ||
0845735e FF |
190 | if (!ah->curchan) |
191 | return; | |
192 | ||
898c914a FF |
193 | if (ah->power_mode == ATH9K_PM_AWAKE) |
194 | ath_hw_cycle_counters_update(common); | |
3430098a FF |
195 | |
196 | if (cc->cycles > 0) { | |
197 | survey->filled |= SURVEY_INFO_CHANNEL_TIME | | |
198 | SURVEY_INFO_CHANNEL_TIME_BUSY | | |
199 | SURVEY_INFO_CHANNEL_TIME_RX | | |
200 | SURVEY_INFO_CHANNEL_TIME_TX; | |
201 | survey->channel_time += cc->cycles / div; | |
202 | survey->channel_time_busy += cc->rx_busy / div; | |
203 | survey->channel_time_rx += cc->rx_frame / div; | |
204 | survey->channel_time_tx += cc->tx_frame / div; | |
205 | } | |
206 | memset(cc, 0, sizeof(*cc)); | |
207 | ||
208 | ath_update_survey_nf(sc, pos); | |
209 | } | |
210 | ||
ff37e337 S |
211 | /* |
212 | * Set/change channels. If the channel is really being changed, it's done | |
213 | * by reseting the chip. To accomplish this we must first cleanup any pending | |
214 | * DMA, then restart stuff. | |
215 | */ | |
0e2dedf9 JM |
216 | int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw, |
217 | struct ath9k_channel *hchan) | |
ff37e337 | 218 | { |
20bd2a09 | 219 | struct ath_wiphy *aphy = hw->priv; |
cbe61d8a | 220 | struct ath_hw *ah = sc->sc_ah; |
c46917bb | 221 | struct ath_common *common = ath9k_hw_common(ah); |
25c56eec | 222 | struct ieee80211_conf *conf = &common->hw->conf; |
ff37e337 | 223 | bool fastcc = true, stopped; |
ae8d2858 | 224 | struct ieee80211_channel *channel = hw->conf.channel; |
20bd2a09 | 225 | struct ath9k_hw_cal_data *caldata = NULL; |
ae8d2858 | 226 | int r; |
ff37e337 S |
227 | |
228 | if (sc->sc_flags & SC_OP_INVALID) | |
229 | return -EIO; | |
230 | ||
5ee08656 FF |
231 | del_timer_sync(&common->ani.timer); |
232 | cancel_work_sync(&sc->paprd_work); | |
233 | cancel_work_sync(&sc->hw_check_work); | |
234 | cancel_delayed_work_sync(&sc->tx_complete_work); | |
235 | ||
3cbb5dd7 VN |
236 | ath9k_ps_wakeup(sc); |
237 | ||
c0d7c7af LR |
238 | /* |
239 | * This is only performed if the channel settings have | |
240 | * actually changed. | |
241 | * | |
242 | * To switch channels clear any pending DMA operations; | |
243 | * wait long enough for the RX fifo to drain, reset the | |
244 | * hardware at the new frequency, and then re-enable | |
245 | * the relevant bits of the h/w. | |
246 | */ | |
247 | ath9k_hw_set_interrupts(ah, 0); | |
043a0405 | 248 | ath_drain_all_txq(sc, false); |
5e848f78 LR |
249 | |
250 | spin_lock_bh(&sc->rx.pcu_lock); | |
251 | ||
c0d7c7af | 252 | stopped = ath_stoprecv(sc); |
ff37e337 | 253 | |
c0d7c7af LR |
254 | /* XXX: do not flush receive queue here. We don't want |
255 | * to flush data frames already in queue because of | |
256 | * changing channel. */ | |
ff37e337 | 257 | |
5ee08656 | 258 | if (!stopped || !(sc->sc_flags & SC_OP_OFFCHANNEL)) |
c0d7c7af LR |
259 | fastcc = false; |
260 | ||
20bd2a09 FF |
261 | if (!(sc->sc_flags & SC_OP_OFFCHANNEL)) |
262 | caldata = &aphy->caldata; | |
263 | ||
c46917bb | 264 | ath_print(common, ATH_DBG_CONFIG, |
1e51b2ff | 265 | "(%u MHz) -> (%u MHz), conf_is_ht40: %d fastcc: %d\n", |
c46917bb | 266 | sc->sc_ah->curchan->channel, |
1e51b2ff LR |
267 | channel->center_freq, conf_is_ht40(conf), |
268 | fastcc); | |
ff37e337 | 269 | |
c0d7c7af LR |
270 | spin_lock_bh(&sc->sc_resetlock); |
271 | ||
20bd2a09 | 272 | r = ath9k_hw_reset(ah, hchan, caldata, fastcc); |
c0d7c7af | 273 | if (r) { |
c46917bb | 274 | ath_print(common, ATH_DBG_FATAL, |
f643e51d | 275 | "Unable to reset channel (%u MHz), " |
c46917bb LR |
276 | "reset status %d\n", |
277 | channel->center_freq, r); | |
c0d7c7af | 278 | spin_unlock_bh(&sc->sc_resetlock); |
5e848f78 | 279 | spin_unlock_bh(&sc->rx.pcu_lock); |
3989279c | 280 | goto ps_restore; |
ff37e337 | 281 | } |
c0d7c7af LR |
282 | spin_unlock_bh(&sc->sc_resetlock); |
283 | ||
c0d7c7af | 284 | if (ath_startrecv(sc) != 0) { |
c46917bb LR |
285 | ath_print(common, ATH_DBG_FATAL, |
286 | "Unable to restart recv logic\n"); | |
3989279c | 287 | r = -EIO; |
5e848f78 | 288 | spin_unlock_bh(&sc->rx.pcu_lock); |
3989279c | 289 | goto ps_restore; |
c0d7c7af LR |
290 | } |
291 | ||
5e848f78 LR |
292 | spin_unlock_bh(&sc->rx.pcu_lock); |
293 | ||
c0d7c7af | 294 | ath_update_txpow(sc); |
3069168c | 295 | ath9k_hw_set_interrupts(ah, ah->imask); |
3989279c | 296 | |
48a6a468 LR |
297 | if (!(sc->sc_flags & (SC_OP_OFFCHANNEL))) { |
298 | ath_beacon_config(sc, NULL); | |
5ee08656 | 299 | ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0); |
48a6a468 | 300 | ath_start_ani(common); |
5ee08656 FF |
301 | } |
302 | ||
3989279c | 303 | ps_restore: |
3cbb5dd7 | 304 | ath9k_ps_restore(sc); |
3989279c | 305 | return r; |
ff37e337 S |
306 | } |
307 | ||
9f42c2b6 FF |
308 | static void ath_paprd_activate(struct ath_softc *sc) |
309 | { | |
310 | struct ath_hw *ah = sc->sc_ah; | |
20bd2a09 | 311 | struct ath9k_hw_cal_data *caldata = ah->caldata; |
9094537c | 312 | struct ath_common *common = ath9k_hw_common(ah); |
9f42c2b6 FF |
313 | int chain; |
314 | ||
20bd2a09 | 315 | if (!caldata || !caldata->paprd_done) |
9f42c2b6 FF |
316 | return; |
317 | ||
318 | ath9k_ps_wakeup(sc); | |
ddfef792 | 319 | ar9003_paprd_enable(ah, false); |
9f42c2b6 | 320 | for (chain = 0; chain < AR9300_MAX_CHAINS; chain++) { |
9094537c | 321 | if (!(common->tx_chainmask & BIT(chain))) |
9f42c2b6 FF |
322 | continue; |
323 | ||
20bd2a09 | 324 | ar9003_paprd_populate_single_table(ah, caldata, chain); |
9f42c2b6 FF |
325 | } |
326 | ||
327 | ar9003_paprd_enable(ah, true); | |
328 | ath9k_ps_restore(sc); | |
329 | } | |
330 | ||
331 | void ath_paprd_calibrate(struct work_struct *work) | |
332 | { | |
333 | struct ath_softc *sc = container_of(work, struct ath_softc, paprd_work); | |
334 | struct ieee80211_hw *hw = sc->hw; | |
335 | struct ath_hw *ah = sc->sc_ah; | |
336 | struct ieee80211_hdr *hdr; | |
337 | struct sk_buff *skb = NULL; | |
338 | struct ieee80211_tx_info *tx_info; | |
339 | int band = hw->conf.channel->band; | |
340 | struct ieee80211_supported_band *sband = &sc->sbands[band]; | |
341 | struct ath_tx_control txctl; | |
20bd2a09 | 342 | struct ath9k_hw_cal_data *caldata = ah->caldata; |
9094537c | 343 | struct ath_common *common = ath9k_hw_common(ah); |
9f42c2b6 FF |
344 | int qnum, ftype; |
345 | int chain_ok = 0; | |
346 | int chain; | |
347 | int len = 1800; | |
348 | int time_left; | |
349 | int i; | |
350 | ||
20bd2a09 FF |
351 | if (!caldata) |
352 | return; | |
353 | ||
9f42c2b6 FF |
354 | skb = alloc_skb(len, GFP_KERNEL); |
355 | if (!skb) | |
356 | return; | |
357 | ||
358 | tx_info = IEEE80211_SKB_CB(skb); | |
359 | ||
360 | skb_put(skb, len); | |
361 | memset(skb->data, 0, len); | |
362 | hdr = (struct ieee80211_hdr *)skb->data; | |
363 | ftype = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC; | |
364 | hdr->frame_control = cpu_to_le16(ftype); | |
a3d3da14 | 365 | hdr->duration_id = cpu_to_le16(10); |
9f42c2b6 FF |
366 | memcpy(hdr->addr1, hw->wiphy->perm_addr, ETH_ALEN); |
367 | memcpy(hdr->addr2, hw->wiphy->perm_addr, ETH_ALEN); | |
368 | memcpy(hdr->addr3, hw->wiphy->perm_addr, ETH_ALEN); | |
369 | ||
370 | memset(&txctl, 0, sizeof(txctl)); | |
371 | qnum = sc->tx.hwq_map[WME_AC_BE]; | |
372 | txctl.txq = &sc->tx.txq[qnum]; | |
373 | ||
47399f1a | 374 | ath9k_ps_wakeup(sc); |
9f42c2b6 FF |
375 | ar9003_paprd_init_table(ah); |
376 | for (chain = 0; chain < AR9300_MAX_CHAINS; chain++) { | |
9094537c | 377 | if (!(common->tx_chainmask & BIT(chain))) |
9f42c2b6 FF |
378 | continue; |
379 | ||
380 | chain_ok = 0; | |
381 | memset(tx_info, 0, sizeof(*tx_info)); | |
382 | tx_info->band = band; | |
383 | ||
384 | for (i = 0; i < 4; i++) { | |
385 | tx_info->control.rates[i].idx = sband->n_bitrates - 1; | |
386 | tx_info->control.rates[i].count = 6; | |
387 | } | |
388 | ||
389 | init_completion(&sc->paprd_complete); | |
390 | ar9003_paprd_setup_gain_table(ah, chain); | |
391 | txctl.paprd = BIT(chain); | |
392 | if (ath_tx_start(hw, skb, &txctl) != 0) | |
393 | break; | |
394 | ||
395 | time_left = wait_for_completion_timeout(&sc->paprd_complete, | |
ca369eb4 | 396 | msecs_to_jiffies(ATH_PAPRD_TIMEOUT)); |
9f42c2b6 FF |
397 | if (!time_left) { |
398 | ath_print(ath9k_hw_common(ah), ATH_DBG_CALIBRATE, | |
399 | "Timeout waiting for paprd training on " | |
400 | "TX chain %d\n", | |
401 | chain); | |
ca369eb4 | 402 | goto fail_paprd; |
9f42c2b6 FF |
403 | } |
404 | ||
405 | if (!ar9003_paprd_is_done(ah)) | |
406 | break; | |
407 | ||
20bd2a09 | 408 | if (ar9003_paprd_create_curve(ah, caldata, chain) != 0) |
9f42c2b6 FF |
409 | break; |
410 | ||
411 | chain_ok = 1; | |
412 | } | |
413 | kfree_skb(skb); | |
414 | ||
415 | if (chain_ok) { | |
20bd2a09 | 416 | caldata->paprd_done = true; |
9f42c2b6 FF |
417 | ath_paprd_activate(sc); |
418 | } | |
419 | ||
ca369eb4 | 420 | fail_paprd: |
9f42c2b6 FF |
421 | ath9k_ps_restore(sc); |
422 | } | |
423 | ||
ff37e337 S |
424 | /* |
425 | * This routine performs the periodic noise floor calibration function | |
426 | * that is used to adjust and optimize the chip performance. This | |
427 | * takes environmental changes (location, temperature) into account. | |
428 | * When the task is complete, it reschedules itself depending on the | |
429 | * appropriate interval that was calculated. | |
430 | */ | |
55624204 | 431 | void ath_ani_calibrate(unsigned long data) |
ff37e337 | 432 | { |
20977d3e S |
433 | struct ath_softc *sc = (struct ath_softc *)data; |
434 | struct ath_hw *ah = sc->sc_ah; | |
c46917bb | 435 | struct ath_common *common = ath9k_hw_common(ah); |
ff37e337 S |
436 | bool longcal = false; |
437 | bool shortcal = false; | |
438 | bool aniflag = false; | |
439 | unsigned int timestamp = jiffies_to_msecs(jiffies); | |
6044474e | 440 | u32 cal_interval, short_cal_interval, long_cal_interval; |
b5bfc568 | 441 | unsigned long flags; |
6044474e FF |
442 | |
443 | if (ah->caldata && ah->caldata->nfcal_interference) | |
444 | long_cal_interval = ATH_LONG_CALINTERVAL_INT; | |
445 | else | |
446 | long_cal_interval = ATH_LONG_CALINTERVAL; | |
ff37e337 | 447 | |
20977d3e S |
448 | short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ? |
449 | ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL; | |
ff37e337 | 450 | |
1ffc1c61 JM |
451 | /* Only calibrate if awake */ |
452 | if (sc->sc_ah->power_mode != ATH9K_PM_AWAKE) | |
453 | goto set_timer; | |
454 | ||
455 | ath9k_ps_wakeup(sc); | |
456 | ||
ff37e337 | 457 | /* Long calibration runs independently of short calibration. */ |
6044474e | 458 | if ((timestamp - common->ani.longcal_timer) >= long_cal_interval) { |
ff37e337 | 459 | longcal = true; |
c46917bb | 460 | ath_print(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies); |
3d536acf | 461 | common->ani.longcal_timer = timestamp; |
ff37e337 S |
462 | } |
463 | ||
17d7904d | 464 | /* Short calibration applies only while caldone is false */ |
3d536acf LR |
465 | if (!common->ani.caldone) { |
466 | if ((timestamp - common->ani.shortcal_timer) >= short_cal_interval) { | |
ff37e337 | 467 | shortcal = true; |
c46917bb LR |
468 | ath_print(common, ATH_DBG_ANI, |
469 | "shortcal @%lu\n", jiffies); | |
3d536acf LR |
470 | common->ani.shortcal_timer = timestamp; |
471 | common->ani.resetcal_timer = timestamp; | |
ff37e337 S |
472 | } |
473 | } else { | |
3d536acf | 474 | if ((timestamp - common->ani.resetcal_timer) >= |
ff37e337 | 475 | ATH_RESTART_CALINTERVAL) { |
3d536acf LR |
476 | common->ani.caldone = ath9k_hw_reset_calvalid(ah); |
477 | if (common->ani.caldone) | |
478 | common->ani.resetcal_timer = timestamp; | |
ff37e337 S |
479 | } |
480 | } | |
481 | ||
482 | /* Verify whether we must check ANI */ | |
e36b27af LR |
483 | if ((timestamp - common->ani.checkani_timer) >= |
484 | ah->config.ani_poll_interval) { | |
ff37e337 | 485 | aniflag = true; |
3d536acf | 486 | common->ani.checkani_timer = timestamp; |
ff37e337 S |
487 | } |
488 | ||
489 | /* Skip all processing if there's nothing to do. */ | |
490 | if (longcal || shortcal || aniflag) { | |
491 | /* Call ANI routine if necessary */ | |
b5bfc568 FF |
492 | if (aniflag) { |
493 | spin_lock_irqsave(&common->cc_lock, flags); | |
22e66a4c | 494 | ath9k_hw_ani_monitor(ah, ah->curchan); |
3430098a | 495 | ath_update_survey_stats(sc); |
b5bfc568 FF |
496 | spin_unlock_irqrestore(&common->cc_lock, flags); |
497 | } | |
ff37e337 S |
498 | |
499 | /* Perform calibration if necessary */ | |
500 | if (longcal || shortcal) { | |
3d536acf | 501 | common->ani.caldone = |
43c27613 LR |
502 | ath9k_hw_calibrate(ah, |
503 | ah->curchan, | |
504 | common->rx_chainmask, | |
505 | longcal); | |
ff37e337 S |
506 | } |
507 | } | |
508 | ||
1ffc1c61 JM |
509 | ath9k_ps_restore(sc); |
510 | ||
20977d3e | 511 | set_timer: |
ff37e337 S |
512 | /* |
513 | * Set timer interval based on previous results. | |
514 | * The interval must be the shortest necessary to satisfy ANI, | |
515 | * short calibration and long calibration. | |
516 | */ | |
aac9207e | 517 | cal_interval = ATH_LONG_CALINTERVAL; |
2660b81a | 518 | if (sc->sc_ah->config.enable_ani) |
e36b27af LR |
519 | cal_interval = min(cal_interval, |
520 | (u32)ah->config.ani_poll_interval); | |
3d536acf | 521 | if (!common->ani.caldone) |
20977d3e | 522 | cal_interval = min(cal_interval, (u32)short_cal_interval); |
ff37e337 | 523 | |
3d536acf | 524 | mod_timer(&common->ani.timer, jiffies + msecs_to_jiffies(cal_interval)); |
20bd2a09 FF |
525 | if ((sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_PAPRD) && ah->caldata) { |
526 | if (!ah->caldata->paprd_done) | |
9f42c2b6 FF |
527 | ieee80211_queue_work(sc->hw, &sc->paprd_work); |
528 | else | |
529 | ath_paprd_activate(sc); | |
530 | } | |
ff37e337 S |
531 | } |
532 | ||
533 | /* | |
534 | * Update tx/rx chainmask. For legacy association, | |
535 | * hard code chainmask to 1x1, for 11n association, use | |
c97c92d9 VT |
536 | * the chainmask configuration, for bt coexistence, use |
537 | * the chainmask configuration even in legacy mode. | |
ff37e337 | 538 | */ |
0e2dedf9 | 539 | void ath_update_chainmask(struct ath_softc *sc, int is_ht) |
ff37e337 | 540 | { |
af03abec | 541 | struct ath_hw *ah = sc->sc_ah; |
43c27613 | 542 | struct ath_common *common = ath9k_hw_common(ah); |
af03abec | 543 | |
5ee08656 | 544 | if ((sc->sc_flags & SC_OP_OFFCHANNEL) || is_ht || |
766ec4a9 | 545 | (ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE)) { |
43c27613 LR |
546 | common->tx_chainmask = ah->caps.tx_chainmask; |
547 | common->rx_chainmask = ah->caps.rx_chainmask; | |
ff37e337 | 548 | } else { |
43c27613 LR |
549 | common->tx_chainmask = 1; |
550 | common->rx_chainmask = 1; | |
ff37e337 S |
551 | } |
552 | ||
43c27613 | 553 | ath_print(common, ATH_DBG_CONFIG, |
c46917bb | 554 | "tx chmask: %d, rx chmask: %d\n", |
43c27613 LR |
555 | common->tx_chainmask, |
556 | common->rx_chainmask); | |
ff37e337 S |
557 | } |
558 | ||
559 | static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta) | |
560 | { | |
561 | struct ath_node *an; | |
562 | ||
563 | an = (struct ath_node *)sta->drv_priv; | |
564 | ||
87792efc | 565 | if (sc->sc_flags & SC_OP_TXAGGR) { |
ff37e337 | 566 | ath_tx_node_init(sc, an); |
9e98ac65 | 567 | an->maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR + |
87792efc S |
568 | sta->ht_cap.ampdu_factor); |
569 | an->mpdudensity = parse_mpdudensity(sta->ht_cap.ampdu_density); | |
a59b5a5e | 570 | an->last_rssi = ATH_RSSI_DUMMY_MARKER; |
87792efc | 571 | } |
ff37e337 S |
572 | } |
573 | ||
574 | static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta) | |
575 | { | |
576 | struct ath_node *an = (struct ath_node *)sta->drv_priv; | |
577 | ||
578 | if (sc->sc_flags & SC_OP_TXAGGR) | |
579 | ath_tx_node_cleanup(sc, an); | |
580 | } | |
581 | ||
347809fc FF |
582 | void ath_hw_check(struct work_struct *work) |
583 | { | |
584 | struct ath_softc *sc = container_of(work, struct ath_softc, hw_check_work); | |
585 | int i; | |
586 | ||
587 | ath9k_ps_wakeup(sc); | |
588 | ||
589 | for (i = 0; i < 3; i++) { | |
590 | if (ath9k_hw_check_alive(sc->sc_ah)) | |
591 | goto out; | |
592 | ||
593 | msleep(1); | |
594 | } | |
fac6b6a0 | 595 | ath_reset(sc, true); |
347809fc FF |
596 | |
597 | out: | |
598 | ath9k_ps_restore(sc); | |
599 | } | |
600 | ||
55624204 | 601 | void ath9k_tasklet(unsigned long data) |
ff37e337 S |
602 | { |
603 | struct ath_softc *sc = (struct ath_softc *)data; | |
af03abec | 604 | struct ath_hw *ah = sc->sc_ah; |
c46917bb | 605 | struct ath_common *common = ath9k_hw_common(ah); |
af03abec | 606 | |
17d7904d | 607 | u32 status = sc->intrstatus; |
b5c80475 | 608 | u32 rxmask; |
ff37e337 | 609 | |
153e080d VT |
610 | ath9k_ps_wakeup(sc); |
611 | ||
347809fc | 612 | if (status & ATH9K_INT_FATAL) { |
fac6b6a0 | 613 | ath_reset(sc, true); |
153e080d | 614 | ath9k_ps_restore(sc); |
ff37e337 | 615 | return; |
063d8be3 | 616 | } |
ff37e337 | 617 | |
347809fc FF |
618 | if (!ath9k_hw_check_alive(ah)) |
619 | ieee80211_queue_work(sc->hw, &sc->hw_check_work); | |
620 | ||
b5c80475 FF |
621 | if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) |
622 | rxmask = (ATH9K_INT_RXHP | ATH9K_INT_RXLP | ATH9K_INT_RXEOL | | |
623 | ATH9K_INT_RXORN); | |
624 | else | |
625 | rxmask = (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN); | |
626 | ||
627 | if (status & rxmask) { | |
b79b33c4 | 628 | spin_lock_bh(&sc->rx.pcu_lock); |
b5c80475 FF |
629 | |
630 | /* Check for high priority Rx first */ | |
631 | if ((ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) && | |
632 | (status & ATH9K_INT_RXHP)) | |
633 | ath_rx_tasklet(sc, 0, true); | |
634 | ||
635 | ath_rx_tasklet(sc, 0, false); | |
b79b33c4 | 636 | spin_unlock_bh(&sc->rx.pcu_lock); |
ff37e337 S |
637 | } |
638 | ||
e5003249 VT |
639 | if (status & ATH9K_INT_TX) { |
640 | if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) | |
641 | ath_tx_edma_tasklet(sc); | |
642 | else | |
643 | ath_tx_tasklet(sc); | |
644 | } | |
063d8be3 | 645 | |
96148326 | 646 | if ((status & ATH9K_INT_TSFOOR) && sc->ps_enabled) { |
54ce846e JM |
647 | /* |
648 | * TSF sync does not look correct; remain awake to sync with | |
649 | * the next Beacon. | |
650 | */ | |
c46917bb LR |
651 | ath_print(common, ATH_DBG_PS, |
652 | "TSFOOR - Sync with next Beacon\n"); | |
1b04b930 | 653 | sc->ps_flags |= PS_WAIT_FOR_BEACON | PS_BEACON_SYNC; |
54ce846e JM |
654 | } |
655 | ||
766ec4a9 | 656 | if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE) |
ebb8e1d7 VT |
657 | if (status & ATH9K_INT_GENTIMER) |
658 | ath_gen_timer_isr(sc->sc_ah); | |
659 | ||
ff37e337 | 660 | /* re-enable hardware interrupt */ |
3069168c | 661 | ath9k_hw_set_interrupts(ah, ah->imask); |
153e080d | 662 | ath9k_ps_restore(sc); |
ff37e337 S |
663 | } |
664 | ||
6baff7f9 | 665 | irqreturn_t ath_isr(int irq, void *dev) |
ff37e337 | 666 | { |
063d8be3 S |
667 | #define SCHED_INTR ( \ |
668 | ATH9K_INT_FATAL | \ | |
669 | ATH9K_INT_RXORN | \ | |
670 | ATH9K_INT_RXEOL | \ | |
671 | ATH9K_INT_RX | \ | |
b5c80475 FF |
672 | ATH9K_INT_RXLP | \ |
673 | ATH9K_INT_RXHP | \ | |
063d8be3 S |
674 | ATH9K_INT_TX | \ |
675 | ATH9K_INT_BMISS | \ | |
676 | ATH9K_INT_CST | \ | |
ebb8e1d7 VT |
677 | ATH9K_INT_TSFOOR | \ |
678 | ATH9K_INT_GENTIMER) | |
063d8be3 | 679 | |
ff37e337 | 680 | struct ath_softc *sc = dev; |
cbe61d8a | 681 | struct ath_hw *ah = sc->sc_ah; |
b5bfc568 | 682 | struct ath_common *common = ath9k_hw_common(ah); |
ff37e337 S |
683 | enum ath9k_int status; |
684 | bool sched = false; | |
685 | ||
063d8be3 S |
686 | /* |
687 | * The hardware is not ready/present, don't | |
688 | * touch anything. Note this can happen early | |
689 | * on if the IRQ is shared. | |
690 | */ | |
691 | if (sc->sc_flags & SC_OP_INVALID) | |
692 | return IRQ_NONE; | |
ff37e337 | 693 | |
063d8be3 S |
694 | |
695 | /* shared irq, not for us */ | |
696 | ||
153e080d | 697 | if (!ath9k_hw_intrpend(ah)) |
063d8be3 | 698 | return IRQ_NONE; |
063d8be3 S |
699 | |
700 | /* | |
701 | * Figure out the reason(s) for the interrupt. Note | |
702 | * that the hal returns a pseudo-ISR that may include | |
703 | * bits we haven't explicitly enabled so we mask the | |
704 | * value to insure we only process bits we requested. | |
705 | */ | |
706 | ath9k_hw_getisr(ah, &status); /* NB: clears ISR too */ | |
3069168c | 707 | status &= ah->imask; /* discard unasked-for bits */ |
ff37e337 | 708 | |
063d8be3 S |
709 | /* |
710 | * If there are no status bits set, then this interrupt was not | |
711 | * for me (should have been caught above). | |
712 | */ | |
153e080d | 713 | if (!status) |
063d8be3 | 714 | return IRQ_NONE; |
ff37e337 | 715 | |
063d8be3 S |
716 | /* Cache the status */ |
717 | sc->intrstatus = status; | |
718 | ||
719 | if (status & SCHED_INTR) | |
720 | sched = true; | |
721 | ||
722 | /* | |
723 | * If a FATAL or RXORN interrupt is received, we have to reset the | |
724 | * chip immediately. | |
725 | */ | |
b5c80475 FF |
726 | if ((status & ATH9K_INT_FATAL) || ((status & ATH9K_INT_RXORN) && |
727 | !(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA))) | |
063d8be3 S |
728 | goto chip_reset; |
729 | ||
08578b8f LR |
730 | if ((ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) && |
731 | (status & ATH9K_INT_BB_WATCHDOG)) { | |
b5bfc568 FF |
732 | |
733 | spin_lock(&common->cc_lock); | |
734 | ath_hw_cycle_counters_update(common); | |
08578b8f | 735 | ar9003_hw_bb_watchdog_dbg_info(ah); |
b5bfc568 FF |
736 | spin_unlock(&common->cc_lock); |
737 | ||
08578b8f LR |
738 | goto chip_reset; |
739 | } | |
740 | ||
063d8be3 S |
741 | if (status & ATH9K_INT_SWBA) |
742 | tasklet_schedule(&sc->bcon_tasklet); | |
743 | ||
744 | if (status & ATH9K_INT_TXURN) | |
745 | ath9k_hw_updatetxtriglevel(ah, true); | |
746 | ||
b5c80475 FF |
747 | if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) { |
748 | if (status & ATH9K_INT_RXEOL) { | |
749 | ah->imask &= ~(ATH9K_INT_RXEOL | ATH9K_INT_RXORN); | |
750 | ath9k_hw_set_interrupts(ah, ah->imask); | |
751 | } | |
752 | } | |
753 | ||
063d8be3 | 754 | if (status & ATH9K_INT_MIB) { |
ff37e337 | 755 | /* |
063d8be3 S |
756 | * Disable interrupts until we service the MIB |
757 | * interrupt; otherwise it will continue to | |
758 | * fire. | |
ff37e337 | 759 | */ |
063d8be3 S |
760 | ath9k_hw_set_interrupts(ah, 0); |
761 | /* | |
762 | * Let the hal handle the event. We assume | |
763 | * it will clear whatever condition caused | |
764 | * the interrupt. | |
765 | */ | |
88eac2da | 766 | spin_lock(&common->cc_lock); |
bfc472bb | 767 | ath9k_hw_proc_mib_event(ah); |
88eac2da | 768 | spin_unlock(&common->cc_lock); |
3069168c | 769 | ath9k_hw_set_interrupts(ah, ah->imask); |
063d8be3 | 770 | } |
ff37e337 | 771 | |
153e080d VT |
772 | if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) |
773 | if (status & ATH9K_INT_TIM_TIMER) { | |
063d8be3 S |
774 | /* Clear RxAbort bit so that we can |
775 | * receive frames */ | |
9ecdef4b | 776 | ath9k_setpower(sc, ATH9K_PM_AWAKE); |
153e080d | 777 | ath9k_hw_setrxabort(sc->sc_ah, 0); |
1b04b930 | 778 | sc->ps_flags |= PS_WAIT_FOR_BEACON; |
ff37e337 | 779 | } |
063d8be3 S |
780 | |
781 | chip_reset: | |
ff37e337 | 782 | |
817e11de S |
783 | ath_debug_stat_interrupt(sc, status); |
784 | ||
ff37e337 S |
785 | if (sched) { |
786 | /* turn off every interrupt except SWBA */ | |
3069168c | 787 | ath9k_hw_set_interrupts(ah, (ah->imask & ATH9K_INT_SWBA)); |
ff37e337 S |
788 | tasklet_schedule(&sc->intr_tq); |
789 | } | |
790 | ||
791 | return IRQ_HANDLED; | |
063d8be3 S |
792 | |
793 | #undef SCHED_INTR | |
ff37e337 S |
794 | } |
795 | ||
f078f209 | 796 | static u32 ath_get_extchanmode(struct ath_softc *sc, |
99405f93 | 797 | struct ieee80211_channel *chan, |
094d05dc | 798 | enum nl80211_channel_type channel_type) |
f078f209 LR |
799 | { |
800 | u32 chanmode = 0; | |
f078f209 LR |
801 | |
802 | switch (chan->band) { | |
803 | case IEEE80211_BAND_2GHZ: | |
094d05dc S |
804 | switch(channel_type) { |
805 | case NL80211_CHAN_NO_HT: | |
806 | case NL80211_CHAN_HT20: | |
f078f209 | 807 | chanmode = CHANNEL_G_HT20; |
094d05dc S |
808 | break; |
809 | case NL80211_CHAN_HT40PLUS: | |
f078f209 | 810 | chanmode = CHANNEL_G_HT40PLUS; |
094d05dc S |
811 | break; |
812 | case NL80211_CHAN_HT40MINUS: | |
f078f209 | 813 | chanmode = CHANNEL_G_HT40MINUS; |
094d05dc S |
814 | break; |
815 | } | |
f078f209 LR |
816 | break; |
817 | case IEEE80211_BAND_5GHZ: | |
094d05dc S |
818 | switch(channel_type) { |
819 | case NL80211_CHAN_NO_HT: | |
820 | case NL80211_CHAN_HT20: | |
f078f209 | 821 | chanmode = CHANNEL_A_HT20; |
094d05dc S |
822 | break; |
823 | case NL80211_CHAN_HT40PLUS: | |
f078f209 | 824 | chanmode = CHANNEL_A_HT40PLUS; |
094d05dc S |
825 | break; |
826 | case NL80211_CHAN_HT40MINUS: | |
f078f209 | 827 | chanmode = CHANNEL_A_HT40MINUS; |
094d05dc S |
828 | break; |
829 | } | |
f078f209 LR |
830 | break; |
831 | default: | |
832 | break; | |
833 | } | |
834 | ||
835 | return chanmode; | |
836 | } | |
837 | ||
8feceb67 | 838 | static void ath9k_bss_assoc_info(struct ath_softc *sc, |
5640b08e | 839 | struct ieee80211_vif *vif, |
8feceb67 | 840 | struct ieee80211_bss_conf *bss_conf) |
f078f209 | 841 | { |
f2b2143e | 842 | struct ath_hw *ah = sc->sc_ah; |
1510718d | 843 | struct ath_common *common = ath9k_hw_common(ah); |
f078f209 | 844 | |
8feceb67 | 845 | if (bss_conf->assoc) { |
c46917bb LR |
846 | ath_print(common, ATH_DBG_CONFIG, |
847 | "Bss Info ASSOC %d, bssid: %pM\n", | |
848 | bss_conf->aid, common->curbssid); | |
f078f209 | 849 | |
8feceb67 | 850 | /* New association, store aid */ |
1510718d | 851 | common->curaid = bss_conf->aid; |
f2b2143e | 852 | ath9k_hw_write_associd(ah); |
2664f201 SB |
853 | |
854 | /* | |
855 | * Request a re-configuration of Beacon related timers | |
856 | * on the receipt of the first Beacon frame (i.e., | |
857 | * after time sync with the AP). | |
858 | */ | |
1b04b930 | 859 | sc->ps_flags |= PS_BEACON_SYNC; |
f078f209 | 860 | |
8feceb67 | 861 | /* Configure the beacon */ |
2c3db3d5 | 862 | ath_beacon_config(sc, vif); |
f078f209 | 863 | |
8feceb67 | 864 | /* Reset rssi stats */ |
22e66a4c | 865 | sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER; |
f078f209 | 866 | |
6c3118e2 | 867 | sc->sc_flags |= SC_OP_ANI_RUN; |
3d536acf | 868 | ath_start_ani(common); |
8feceb67 | 869 | } else { |
c46917bb | 870 | ath_print(common, ATH_DBG_CONFIG, "Bss Info DISASSOC\n"); |
1510718d | 871 | common->curaid = 0; |
f38faa31 | 872 | /* Stop ANI */ |
6c3118e2 | 873 | sc->sc_flags &= ~SC_OP_ANI_RUN; |
3d536acf | 874 | del_timer_sync(&common->ani.timer); |
f078f209 | 875 | } |
8feceb67 | 876 | } |
f078f209 | 877 | |
68a89116 | 878 | void ath_radio_enable(struct ath_softc *sc, struct ieee80211_hw *hw) |
500c064d | 879 | { |
cbe61d8a | 880 | struct ath_hw *ah = sc->sc_ah; |
c46917bb | 881 | struct ath_common *common = ath9k_hw_common(ah); |
68a89116 | 882 | struct ieee80211_channel *channel = hw->conf.channel; |
ae8d2858 | 883 | int r; |
500c064d | 884 | |
3cbb5dd7 | 885 | ath9k_ps_wakeup(sc); |
93b1b37f | 886 | ath9k_hw_configpcipowersave(ah, 0, 0); |
ae8d2858 | 887 | |
159cd468 VT |
888 | if (!ah->curchan) |
889 | ah->curchan = ath_get_curchannel(sc, sc->hw); | |
890 | ||
5e848f78 | 891 | spin_lock_bh(&sc->rx.pcu_lock); |
d2f5b3a6 | 892 | spin_lock_bh(&sc->sc_resetlock); |
20bd2a09 | 893 | r = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false); |
ae8d2858 | 894 | if (r) { |
c46917bb | 895 | ath_print(common, ATH_DBG_FATAL, |
f643e51d | 896 | "Unable to reset channel (%u MHz), " |
c46917bb LR |
897 | "reset status %d\n", |
898 | channel->center_freq, r); | |
500c064d VT |
899 | } |
900 | spin_unlock_bh(&sc->sc_resetlock); | |
901 | ||
902 | ath_update_txpow(sc); | |
903 | if (ath_startrecv(sc) != 0) { | |
c46917bb LR |
904 | ath_print(common, ATH_DBG_FATAL, |
905 | "Unable to restart recv logic\n"); | |
5e848f78 | 906 | spin_unlock_bh(&sc->rx.pcu_lock); |
500c064d VT |
907 | return; |
908 | } | |
5e848f78 | 909 | spin_unlock_bh(&sc->rx.pcu_lock); |
500c064d VT |
910 | |
911 | if (sc->sc_flags & SC_OP_BEACONS) | |
2c3db3d5 | 912 | ath_beacon_config(sc, NULL); /* restart beacons */ |
500c064d VT |
913 | |
914 | /* Re-Enable interrupts */ | |
3069168c | 915 | ath9k_hw_set_interrupts(ah, ah->imask); |
500c064d VT |
916 | |
917 | /* Enable LED */ | |
08fc5c1b | 918 | ath9k_hw_cfg_output(ah, ah->led_pin, |
500c064d | 919 | AR_GPIO_OUTPUT_MUX_AS_OUTPUT); |
08fc5c1b | 920 | ath9k_hw_set_gpio(ah, ah->led_pin, 0); |
500c064d | 921 | |
68a89116 | 922 | ieee80211_wake_queues(hw); |
3cbb5dd7 | 923 | ath9k_ps_restore(sc); |
500c064d VT |
924 | } |
925 | ||
68a89116 | 926 | void ath_radio_disable(struct ath_softc *sc, struct ieee80211_hw *hw) |
500c064d | 927 | { |
cbe61d8a | 928 | struct ath_hw *ah = sc->sc_ah; |
68a89116 | 929 | struct ieee80211_channel *channel = hw->conf.channel; |
ae8d2858 | 930 | int r; |
500c064d | 931 | |
3cbb5dd7 | 932 | ath9k_ps_wakeup(sc); |
68a89116 | 933 | ieee80211_stop_queues(hw); |
500c064d | 934 | |
982723df VN |
935 | /* |
936 | * Keep the LED on when the radio is disabled | |
937 | * during idle unassociated state. | |
938 | */ | |
939 | if (!sc->ps_idle) { | |
940 | ath9k_hw_set_gpio(ah, ah->led_pin, 1); | |
941 | ath9k_hw_cfg_gpio_input(ah, ah->led_pin); | |
942 | } | |
500c064d VT |
943 | |
944 | /* Disable interrupts */ | |
945 | ath9k_hw_set_interrupts(ah, 0); | |
946 | ||
043a0405 | 947 | ath_drain_all_txq(sc, false); /* clear pending tx frames */ |
5e848f78 LR |
948 | |
949 | spin_lock_bh(&sc->rx.pcu_lock); | |
950 | ||
500c064d VT |
951 | ath_stoprecv(sc); /* turn off frame recv */ |
952 | ath_flushrecv(sc); /* flush recv queue */ | |
953 | ||
159cd468 | 954 | if (!ah->curchan) |
68a89116 | 955 | ah->curchan = ath_get_curchannel(sc, hw); |
159cd468 | 956 | |
500c064d | 957 | spin_lock_bh(&sc->sc_resetlock); |
20bd2a09 | 958 | r = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false); |
ae8d2858 | 959 | if (r) { |
c46917bb | 960 | ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL, |
f643e51d | 961 | "Unable to reset channel (%u MHz), " |
c46917bb LR |
962 | "reset status %d\n", |
963 | channel->center_freq, r); | |
500c064d VT |
964 | } |
965 | spin_unlock_bh(&sc->sc_resetlock); | |
966 | ||
967 | ath9k_hw_phy_disable(ah); | |
5e848f78 LR |
968 | |
969 | spin_unlock_bh(&sc->rx.pcu_lock); | |
970 | ||
93b1b37f | 971 | ath9k_hw_configpcipowersave(ah, 1, 1); |
3cbb5dd7 | 972 | ath9k_ps_restore(sc); |
9ecdef4b | 973 | ath9k_setpower(sc, ATH9K_PM_FULL_SLEEP); |
500c064d VT |
974 | } |
975 | ||
ff37e337 S |
976 | int ath_reset(struct ath_softc *sc, bool retry_tx) |
977 | { | |
cbe61d8a | 978 | struct ath_hw *ah = sc->sc_ah; |
c46917bb | 979 | struct ath_common *common = ath9k_hw_common(ah); |
030bb495 | 980 | struct ieee80211_hw *hw = sc->hw; |
ae8d2858 | 981 | int r; |
ff37e337 | 982 | |
2ab81d4a S |
983 | /* Stop ANI */ |
984 | del_timer_sync(&common->ani.timer); | |
985 | ||
cc9c378a S |
986 | ieee80211_stop_queues(hw); |
987 | ||
ff37e337 | 988 | ath9k_hw_set_interrupts(ah, 0); |
043a0405 | 989 | ath_drain_all_txq(sc, retry_tx); |
5e848f78 LR |
990 | |
991 | spin_lock_bh(&sc->rx.pcu_lock); | |
992 | ||
ff37e337 S |
993 | ath_stoprecv(sc); |
994 | ath_flushrecv(sc); | |
995 | ||
996 | spin_lock_bh(&sc->sc_resetlock); | |
20bd2a09 | 997 | r = ath9k_hw_reset(ah, sc->sc_ah->curchan, ah->caldata, false); |
ae8d2858 | 998 | if (r) |
c46917bb LR |
999 | ath_print(common, ATH_DBG_FATAL, |
1000 | "Unable to reset hardware; reset status %d\n", r); | |
ff37e337 S |
1001 | spin_unlock_bh(&sc->sc_resetlock); |
1002 | ||
1003 | if (ath_startrecv(sc) != 0) | |
c46917bb LR |
1004 | ath_print(common, ATH_DBG_FATAL, |
1005 | "Unable to start recv logic\n"); | |
ff37e337 | 1006 | |
5e848f78 LR |
1007 | spin_unlock_bh(&sc->rx.pcu_lock); |
1008 | ||
ff37e337 S |
1009 | /* |
1010 | * We may be doing a reset in response to a request | |
1011 | * that changes the channel so update any state that | |
1012 | * might change as a result. | |
1013 | */ | |
ff37e337 S |
1014 | ath_update_txpow(sc); |
1015 | ||
52b8ac92 | 1016 | if ((sc->sc_flags & SC_OP_BEACONS) || !(sc->sc_flags & (SC_OP_OFFCHANNEL))) |
2c3db3d5 | 1017 | ath_beacon_config(sc, NULL); /* restart beacons */ |
ff37e337 | 1018 | |
3069168c | 1019 | ath9k_hw_set_interrupts(ah, ah->imask); |
ff37e337 S |
1020 | |
1021 | if (retry_tx) { | |
1022 | int i; | |
1023 | for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) { | |
1024 | if (ATH_TXQ_SETUP(sc, i)) { | |
b77f483f S |
1025 | spin_lock_bh(&sc->tx.txq[i].axq_lock); |
1026 | ath_txq_schedule(sc, &sc->tx.txq[i]); | |
1027 | spin_unlock_bh(&sc->tx.txq[i].axq_lock); | |
ff37e337 S |
1028 | } |
1029 | } | |
1030 | } | |
1031 | ||
cc9c378a S |
1032 | ieee80211_wake_queues(hw); |
1033 | ||
2ab81d4a S |
1034 | /* Start ANI */ |
1035 | ath_start_ani(common); | |
1036 | ||
ae8d2858 | 1037 | return r; |
ff37e337 S |
1038 | } |
1039 | ||
ebe297c3 | 1040 | static int ath_get_hal_qnum(u16 queue, struct ath_softc *sc) |
ff37e337 S |
1041 | { |
1042 | int qnum; | |
1043 | ||
1044 | switch (queue) { | |
1045 | case 0: | |
1d2231e2 | 1046 | qnum = sc->tx.hwq_map[WME_AC_VO]; |
ff37e337 S |
1047 | break; |
1048 | case 1: | |
1d2231e2 | 1049 | qnum = sc->tx.hwq_map[WME_AC_VI]; |
ff37e337 S |
1050 | break; |
1051 | case 2: | |
1d2231e2 | 1052 | qnum = sc->tx.hwq_map[WME_AC_BE]; |
ff37e337 S |
1053 | break; |
1054 | case 3: | |
1d2231e2 | 1055 | qnum = sc->tx.hwq_map[WME_AC_BK]; |
ff37e337 S |
1056 | break; |
1057 | default: | |
1d2231e2 | 1058 | qnum = sc->tx.hwq_map[WME_AC_BE]; |
ff37e337 S |
1059 | break; |
1060 | } | |
1061 | ||
1062 | return qnum; | |
1063 | } | |
1064 | ||
1065 | int ath_get_mac80211_qnum(u32 queue, struct ath_softc *sc) | |
1066 | { | |
1067 | int qnum; | |
1068 | ||
1069 | switch (queue) { | |
1d2231e2 | 1070 | case WME_AC_VO: |
ff37e337 S |
1071 | qnum = 0; |
1072 | break; | |
1d2231e2 | 1073 | case WME_AC_VI: |
ff37e337 S |
1074 | qnum = 1; |
1075 | break; | |
1d2231e2 | 1076 | case WME_AC_BE: |
ff37e337 S |
1077 | qnum = 2; |
1078 | break; | |
1d2231e2 | 1079 | case WME_AC_BK: |
ff37e337 S |
1080 | qnum = 3; |
1081 | break; | |
1082 | default: | |
1083 | qnum = -1; | |
1084 | break; | |
1085 | } | |
1086 | ||
1087 | return qnum; | |
1088 | } | |
1089 | ||
5f8e077c LR |
1090 | /* XXX: Remove me once we don't depend on ath9k_channel for all |
1091 | * this redundant data */ | |
0e2dedf9 JM |
1092 | void ath9k_update_ichannel(struct ath_softc *sc, struct ieee80211_hw *hw, |
1093 | struct ath9k_channel *ichan) | |
5f8e077c | 1094 | { |
5f8e077c LR |
1095 | struct ieee80211_channel *chan = hw->conf.channel; |
1096 | struct ieee80211_conf *conf = &hw->conf; | |
1097 | ||
1098 | ichan->channel = chan->center_freq; | |
1099 | ichan->chan = chan; | |
1100 | ||
1101 | if (chan->band == IEEE80211_BAND_2GHZ) { | |
1102 | ichan->chanmode = CHANNEL_G; | |
8813262e | 1103 | ichan->channelFlags = CHANNEL_2GHZ | CHANNEL_OFDM | CHANNEL_G; |
5f8e077c LR |
1104 | } else { |
1105 | ichan->chanmode = CHANNEL_A; | |
1106 | ichan->channelFlags = CHANNEL_5GHZ | CHANNEL_OFDM; | |
1107 | } | |
1108 | ||
25c56eec | 1109 | if (conf_is_ht(conf)) |
5f8e077c LR |
1110 | ichan->chanmode = ath_get_extchanmode(sc, chan, |
1111 | conf->channel_type); | |
5f8e077c LR |
1112 | } |
1113 | ||
ff37e337 S |
1114 | /**********************/ |
1115 | /* mac80211 callbacks */ | |
1116 | /**********************/ | |
1117 | ||
8feceb67 | 1118 | static int ath9k_start(struct ieee80211_hw *hw) |
f078f209 | 1119 | { |
bce048d7 JM |
1120 | struct ath_wiphy *aphy = hw->priv; |
1121 | struct ath_softc *sc = aphy->sc; | |
af03abec | 1122 | struct ath_hw *ah = sc->sc_ah; |
c46917bb | 1123 | struct ath_common *common = ath9k_hw_common(ah); |
8feceb67 | 1124 | struct ieee80211_channel *curchan = hw->conf.channel; |
ff37e337 | 1125 | struct ath9k_channel *init_channel; |
82880a7c | 1126 | int r; |
f078f209 | 1127 | |
c46917bb LR |
1128 | ath_print(common, ATH_DBG_CONFIG, |
1129 | "Starting driver with initial channel: %d MHz\n", | |
1130 | curchan->center_freq); | |
f078f209 | 1131 | |
141b38b6 S |
1132 | mutex_lock(&sc->mutex); |
1133 | ||
9580a222 JM |
1134 | if (ath9k_wiphy_started(sc)) { |
1135 | if (sc->chan_idx == curchan->hw_value) { | |
1136 | /* | |
1137 | * Already on the operational channel, the new wiphy | |
1138 | * can be marked active. | |
1139 | */ | |
1140 | aphy->state = ATH_WIPHY_ACTIVE; | |
1141 | ieee80211_wake_queues(hw); | |
1142 | } else { | |
1143 | /* | |
1144 | * Another wiphy is on another channel, start the new | |
1145 | * wiphy in paused state. | |
1146 | */ | |
1147 | aphy->state = ATH_WIPHY_PAUSED; | |
1148 | ieee80211_stop_queues(hw); | |
1149 | } | |
1150 | mutex_unlock(&sc->mutex); | |
1151 | return 0; | |
1152 | } | |
1153 | aphy->state = ATH_WIPHY_ACTIVE; | |
1154 | ||
8feceb67 | 1155 | /* setup initial channel */ |
f078f209 | 1156 | |
82880a7c | 1157 | sc->chan_idx = curchan->hw_value; |
f078f209 | 1158 | |
82880a7c | 1159 | init_channel = ath_get_curchannel(sc, hw); |
ff37e337 S |
1160 | |
1161 | /* Reset SERDES registers */ | |
af03abec | 1162 | ath9k_hw_configpcipowersave(ah, 0, 0); |
ff37e337 S |
1163 | |
1164 | /* | |
1165 | * The basic interface to setting the hardware in a good | |
1166 | * state is ``reset''. On return the hardware is known to | |
1167 | * be powered up and with interrupts disabled. This must | |
1168 | * be followed by initialization of the appropriate bits | |
1169 | * and then setup of the interrupt mask. | |
1170 | */ | |
5e848f78 | 1171 | spin_lock_bh(&sc->rx.pcu_lock); |
ff37e337 | 1172 | spin_lock_bh(&sc->sc_resetlock); |
20bd2a09 | 1173 | r = ath9k_hw_reset(ah, init_channel, ah->caldata, false); |
ae8d2858 | 1174 | if (r) { |
c46917bb LR |
1175 | ath_print(common, ATH_DBG_FATAL, |
1176 | "Unable to reset hardware; reset status %d " | |
1177 | "(freq %u MHz)\n", r, | |
1178 | curchan->center_freq); | |
ff37e337 | 1179 | spin_unlock_bh(&sc->sc_resetlock); |
5e848f78 | 1180 | spin_unlock_bh(&sc->rx.pcu_lock); |
141b38b6 | 1181 | goto mutex_unlock; |
ff37e337 S |
1182 | } |
1183 | spin_unlock_bh(&sc->sc_resetlock); | |
1184 | ||
1185 | /* | |
1186 | * This is needed only to setup initial state | |
1187 | * but it's best done after a reset. | |
1188 | */ | |
1189 | ath_update_txpow(sc); | |
8feceb67 | 1190 | |
ff37e337 S |
1191 | /* |
1192 | * Setup the hardware after reset: | |
1193 | * The receive engine is set going. | |
1194 | * Frame transmit is handled entirely | |
1195 | * in the frame output path; there's nothing to do | |
1196 | * here except setup the interrupt mask. | |
1197 | */ | |
1198 | if (ath_startrecv(sc) != 0) { | |
c46917bb LR |
1199 | ath_print(common, ATH_DBG_FATAL, |
1200 | "Unable to start recv logic\n"); | |
141b38b6 | 1201 | r = -EIO; |
5e848f78 | 1202 | spin_unlock_bh(&sc->rx.pcu_lock); |
141b38b6 | 1203 | goto mutex_unlock; |
f078f209 | 1204 | } |
5e848f78 | 1205 | spin_unlock_bh(&sc->rx.pcu_lock); |
8feceb67 | 1206 | |
ff37e337 | 1207 | /* Setup our intr mask. */ |
b5c80475 FF |
1208 | ah->imask = ATH9K_INT_TX | ATH9K_INT_RXEOL | |
1209 | ATH9K_INT_RXORN | ATH9K_INT_FATAL | | |
1210 | ATH9K_INT_GLOBAL; | |
1211 | ||
1212 | if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) | |
08578b8f LR |
1213 | ah->imask |= ATH9K_INT_RXHP | |
1214 | ATH9K_INT_RXLP | | |
1215 | ATH9K_INT_BB_WATCHDOG; | |
b5c80475 FF |
1216 | else |
1217 | ah->imask |= ATH9K_INT_RX; | |
ff37e337 | 1218 | |
364734fa | 1219 | ah->imask |= ATH9K_INT_GTT; |
ff37e337 | 1220 | |
af03abec | 1221 | if (ah->caps.hw_caps & ATH9K_HW_CAP_HT) |
3069168c | 1222 | ah->imask |= ATH9K_INT_CST; |
ff37e337 | 1223 | |
ff37e337 | 1224 | sc->sc_flags &= ~SC_OP_INVALID; |
5f841b41 | 1225 | sc->sc_ah->is_monitoring = false; |
ff37e337 S |
1226 | |
1227 | /* Disable BMISS interrupt when we're not associated */ | |
3069168c PR |
1228 | ah->imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS); |
1229 | ath9k_hw_set_interrupts(ah, ah->imask); | |
ff37e337 | 1230 | |
bce048d7 | 1231 | ieee80211_wake_queues(hw); |
ff37e337 | 1232 | |
42935eca | 1233 | ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0); |
164ace38 | 1234 | |
766ec4a9 LR |
1235 | if ((ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE) && |
1236 | !ah->btcoex_hw.enabled) { | |
5e197292 LR |
1237 | ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT, |
1238 | AR_STOMP_LOW_WLAN_WGHT); | |
af03abec | 1239 | ath9k_hw_btcoex_enable(ah); |
f985ad12 | 1240 | |
5bb12791 LR |
1241 | if (common->bus_ops->bt_coex_prep) |
1242 | common->bus_ops->bt_coex_prep(common); | |
766ec4a9 | 1243 | if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE) |
75d7839f | 1244 | ath9k_btcoex_timer_resume(sc); |
1773912b VT |
1245 | } |
1246 | ||
10598c12 VN |
1247 | pm_qos_update_request(&ath9k_pm_qos_req, 55); |
1248 | ||
141b38b6 S |
1249 | mutex_unlock: |
1250 | mutex_unlock(&sc->mutex); | |
1251 | ||
ae8d2858 | 1252 | return r; |
f078f209 LR |
1253 | } |
1254 | ||
8feceb67 VT |
1255 | static int ath9k_tx(struct ieee80211_hw *hw, |
1256 | struct sk_buff *skb) | |
f078f209 | 1257 | { |
528f0c6b | 1258 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
bce048d7 JM |
1259 | struct ath_wiphy *aphy = hw->priv; |
1260 | struct ath_softc *sc = aphy->sc; | |
c46917bb | 1261 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
528f0c6b | 1262 | struct ath_tx_control txctl; |
1bc14880 BP |
1263 | int padpos, padsize; |
1264 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; | |
84642d6b | 1265 | int qnum; |
528f0c6b | 1266 | |
8089cc47 | 1267 | if (aphy->state != ATH_WIPHY_ACTIVE && aphy->state != ATH_WIPHY_SCAN) { |
c46917bb LR |
1268 | ath_print(common, ATH_DBG_XMIT, |
1269 | "ath9k: %s: TX in unexpected wiphy state " | |
1270 | "%d\n", wiphy_name(hw->wiphy), aphy->state); | |
ee166a0e JM |
1271 | goto exit; |
1272 | } | |
1273 | ||
96148326 | 1274 | if (sc->ps_enabled) { |
dc8c4585 JM |
1275 | /* |
1276 | * mac80211 does not set PM field for normal data frames, so we | |
1277 | * need to update that based on the current PS mode. | |
1278 | */ | |
1279 | if (ieee80211_is_data(hdr->frame_control) && | |
1280 | !ieee80211_is_nullfunc(hdr->frame_control) && | |
1281 | !ieee80211_has_pm(hdr->frame_control)) { | |
c46917bb LR |
1282 | ath_print(common, ATH_DBG_PS, "Add PM=1 for a TX frame " |
1283 | "while in PS mode\n"); | |
dc8c4585 JM |
1284 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); |
1285 | } | |
1286 | } | |
1287 | ||
9a23f9ca JM |
1288 | if (unlikely(sc->sc_ah->power_mode != ATH9K_PM_AWAKE)) { |
1289 | /* | |
1290 | * We are using PS-Poll and mac80211 can request TX while in | |
1291 | * power save mode. Need to wake up hardware for the TX to be | |
1292 | * completed and if needed, also for RX of buffered frames. | |
1293 | */ | |
9a23f9ca | 1294 | ath9k_ps_wakeup(sc); |
fdf76622 VT |
1295 | if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) |
1296 | ath9k_hw_setrxabort(sc->sc_ah, 0); | |
9a23f9ca | 1297 | if (ieee80211_is_pspoll(hdr->frame_control)) { |
c46917bb LR |
1298 | ath_print(common, ATH_DBG_PS, |
1299 | "Sending PS-Poll to pick a buffered frame\n"); | |
1b04b930 | 1300 | sc->ps_flags |= PS_WAIT_FOR_PSPOLL_DATA; |
9a23f9ca | 1301 | } else { |
c46917bb LR |
1302 | ath_print(common, ATH_DBG_PS, |
1303 | "Wake up to complete TX\n"); | |
1b04b930 | 1304 | sc->ps_flags |= PS_WAIT_FOR_TX_ACK; |
9a23f9ca JM |
1305 | } |
1306 | /* | |
1307 | * The actual restore operation will happen only after | |
1308 | * the sc_flags bit is cleared. We are just dropping | |
1309 | * the ps_usecount here. | |
1310 | */ | |
1311 | ath9k_ps_restore(sc); | |
1312 | } | |
1313 | ||
528f0c6b | 1314 | memset(&txctl, 0, sizeof(struct ath_tx_control)); |
f078f209 | 1315 | |
8feceb67 VT |
1316 | /* |
1317 | * As a temporary workaround, assign seq# here; this will likely need | |
1318 | * to be cleaned up to work better with Beacon transmission and virtual | |
1319 | * BSSes. | |
1320 | */ | |
1321 | if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) { | |
8feceb67 | 1322 | if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) |
b77f483f | 1323 | sc->tx.seq_no += 0x10; |
8feceb67 | 1324 | hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG); |
b77f483f | 1325 | hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no); |
8feceb67 | 1326 | } |
f078f209 | 1327 | |
8feceb67 | 1328 | /* Add the padding after the header if this is not already done */ |
1bc14880 BP |
1329 | padpos = ath9k_cmn_padpos(hdr->frame_control); |
1330 | padsize = padpos & 3; | |
1331 | if (padsize && skb->len>padpos) { | |
8feceb67 VT |
1332 | if (skb_headroom(skb) < padsize) |
1333 | return -1; | |
1334 | skb_push(skb, padsize); | |
1bc14880 | 1335 | memmove(skb->data, skb->data + padsize, padpos); |
8feceb67 VT |
1336 | } |
1337 | ||
84642d6b FF |
1338 | qnum = ath_get_hal_qnum(skb_get_queue_mapping(skb), sc); |
1339 | txctl.txq = &sc->tx.txq[qnum]; | |
528f0c6b | 1340 | |
c46917bb | 1341 | ath_print(common, ATH_DBG_XMIT, "transmitting packet, skb: %p\n", skb); |
8feceb67 | 1342 | |
c52f33d0 | 1343 | if (ath_tx_start(hw, skb, &txctl) != 0) { |
c46917bb | 1344 | ath_print(common, ATH_DBG_XMIT, "TX failed\n"); |
528f0c6b | 1345 | goto exit; |
8feceb67 VT |
1346 | } |
1347 | ||
528f0c6b S |
1348 | return 0; |
1349 | exit: | |
1350 | dev_kfree_skb_any(skb); | |
8feceb67 | 1351 | return 0; |
f078f209 LR |
1352 | } |
1353 | ||
8feceb67 | 1354 | static void ath9k_stop(struct ieee80211_hw *hw) |
f078f209 | 1355 | { |
bce048d7 JM |
1356 | struct ath_wiphy *aphy = hw->priv; |
1357 | struct ath_softc *sc = aphy->sc; | |
af03abec | 1358 | struct ath_hw *ah = sc->sc_ah; |
c46917bb | 1359 | struct ath_common *common = ath9k_hw_common(ah); |
447a42c2 | 1360 | int i; |
f078f209 | 1361 | |
4c483817 S |
1362 | mutex_lock(&sc->mutex); |
1363 | ||
9580a222 JM |
1364 | aphy->state = ATH_WIPHY_INACTIVE; |
1365 | ||
9a75c2ff VN |
1366 | if (led_blink) |
1367 | cancel_delayed_work_sync(&sc->ath_led_blink_work); | |
1368 | ||
c94dbff7 | 1369 | cancel_delayed_work_sync(&sc->tx_complete_work); |
9f42c2b6 | 1370 | cancel_work_sync(&sc->paprd_work); |
347809fc | 1371 | cancel_work_sync(&sc->hw_check_work); |
c94dbff7 | 1372 | |
447a42c2 RM |
1373 | for (i = 0; i < sc->num_sec_wiphy; i++) { |
1374 | if (sc->sec_wiphy[i]) | |
1375 | break; | |
1376 | } | |
1377 | ||
1378 | if (i == sc->num_sec_wiphy) { | |
c94dbff7 LR |
1379 | cancel_delayed_work_sync(&sc->wiphy_work); |
1380 | cancel_work_sync(&sc->chan_work); | |
1381 | } | |
1382 | ||
9c84b797 | 1383 | if (sc->sc_flags & SC_OP_INVALID) { |
c46917bb | 1384 | ath_print(common, ATH_DBG_ANY, "Device not present\n"); |
4c483817 | 1385 | mutex_unlock(&sc->mutex); |
9c84b797 S |
1386 | return; |
1387 | } | |
8feceb67 | 1388 | |
9580a222 JM |
1389 | if (ath9k_wiphy_started(sc)) { |
1390 | mutex_unlock(&sc->mutex); | |
1391 | return; /* another wiphy still in use */ | |
1392 | } | |
1393 | ||
3867cf6a S |
1394 | /* Ensure HW is awake when we try to shut it down. */ |
1395 | ath9k_ps_wakeup(sc); | |
1396 | ||
766ec4a9 | 1397 | if (ah->btcoex_hw.enabled) { |
af03abec | 1398 | ath9k_hw_btcoex_disable(ah); |
766ec4a9 | 1399 | if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE) |
75d7839f | 1400 | ath9k_btcoex_timer_pause(sc); |
1773912b VT |
1401 | } |
1402 | ||
ff37e337 S |
1403 | /* make sure h/w will not generate any interrupt |
1404 | * before setting the invalid flag. */ | |
af03abec | 1405 | ath9k_hw_set_interrupts(ah, 0); |
ff37e337 | 1406 | |
5e848f78 | 1407 | spin_lock_bh(&sc->rx.pcu_lock); |
ff37e337 | 1408 | if (!(sc->sc_flags & SC_OP_INVALID)) { |
043a0405 | 1409 | ath_drain_all_txq(sc, false); |
ff37e337 | 1410 | ath_stoprecv(sc); |
af03abec | 1411 | ath9k_hw_phy_disable(ah); |
ff37e337 | 1412 | } else |
b77f483f | 1413 | sc->rx.rxlink = NULL; |
5e848f78 | 1414 | spin_unlock_bh(&sc->rx.pcu_lock); |
ff37e337 | 1415 | |
ff37e337 | 1416 | /* disable HAL and put h/w to sleep */ |
af03abec LR |
1417 | ath9k_hw_disable(ah); |
1418 | ath9k_hw_configpcipowersave(ah, 1, 1); | |
3867cf6a S |
1419 | ath9k_ps_restore(sc); |
1420 | ||
1421 | /* Finally, put the chip in FULL SLEEP mode */ | |
9ecdef4b | 1422 | ath9k_setpower(sc, ATH9K_PM_FULL_SLEEP); |
ff37e337 S |
1423 | |
1424 | sc->sc_flags |= SC_OP_INVALID; | |
500c064d | 1425 | |
10598c12 VN |
1426 | pm_qos_update_request(&ath9k_pm_qos_req, PM_QOS_DEFAULT_VALUE); |
1427 | ||
141b38b6 S |
1428 | mutex_unlock(&sc->mutex); |
1429 | ||
c46917bb | 1430 | ath_print(common, ATH_DBG_CONFIG, "Driver halt\n"); |
f078f209 LR |
1431 | } |
1432 | ||
8feceb67 | 1433 | static int ath9k_add_interface(struct ieee80211_hw *hw, |
1ed32e4f | 1434 | struct ieee80211_vif *vif) |
f078f209 | 1435 | { |
bce048d7 JM |
1436 | struct ath_wiphy *aphy = hw->priv; |
1437 | struct ath_softc *sc = aphy->sc; | |
3069168c PR |
1438 | struct ath_hw *ah = sc->sc_ah; |
1439 | struct ath_common *common = ath9k_hw_common(ah); | |
1ed32e4f | 1440 | struct ath_vif *avp = (void *)vif->drv_priv; |
d97809db | 1441 | enum nl80211_iftype ic_opmode = NL80211_IFTYPE_UNSPECIFIED; |
2c3db3d5 | 1442 | int ret = 0; |
8feceb67 | 1443 | |
141b38b6 S |
1444 | mutex_lock(&sc->mutex); |
1445 | ||
1ed32e4f | 1446 | switch (vif->type) { |
05c914fe | 1447 | case NL80211_IFTYPE_STATION: |
d97809db | 1448 | ic_opmode = NL80211_IFTYPE_STATION; |
f078f209 | 1449 | break; |
e51f3eff BJ |
1450 | case NL80211_IFTYPE_WDS: |
1451 | ic_opmode = NL80211_IFTYPE_WDS; | |
1452 | break; | |
05c914fe | 1453 | case NL80211_IFTYPE_ADHOC: |
05c914fe | 1454 | case NL80211_IFTYPE_AP: |
9cb5412b | 1455 | case NL80211_IFTYPE_MESH_POINT: |
2c3db3d5 JM |
1456 | if (sc->nbcnvifs >= ATH_BCBUF) { |
1457 | ret = -ENOBUFS; | |
1458 | goto out; | |
1459 | } | |
1ed32e4f | 1460 | ic_opmode = vif->type; |
f078f209 LR |
1461 | break; |
1462 | default: | |
c46917bb | 1463 | ath_print(common, ATH_DBG_FATAL, |
1ed32e4f | 1464 | "Interface type %d not yet supported\n", vif->type); |
2c3db3d5 JM |
1465 | ret = -EOPNOTSUPP; |
1466 | goto out; | |
f078f209 LR |
1467 | } |
1468 | ||
c46917bb LR |
1469 | ath_print(common, ATH_DBG_CONFIG, |
1470 | "Attach a VIF of type: %d\n", ic_opmode); | |
8feceb67 | 1471 | |
17d7904d | 1472 | /* Set the VIF opmode */ |
5640b08e S |
1473 | avp->av_opmode = ic_opmode; |
1474 | avp->av_bslot = -1; | |
1475 | ||
2c3db3d5 | 1476 | sc->nvifs++; |
8ca21f01 | 1477 | |
364734fa | 1478 | ath9k_set_bssid_mask(hw, vif); |
8ca21f01 | 1479 | |
2c3db3d5 JM |
1480 | if (sc->nvifs > 1) |
1481 | goto out; /* skip global settings for secondary vif */ | |
1482 | ||
b238e90e | 1483 | if (ic_opmode == NL80211_IFTYPE_AP) { |
3069168c | 1484 | ath9k_hw_set_tsfadjust(ah, 1); |
b238e90e S |
1485 | sc->sc_flags |= SC_OP_TSF_RESET; |
1486 | } | |
5640b08e | 1487 | |
5640b08e | 1488 | /* Set the device opmode */ |
3069168c | 1489 | ah->opmode = ic_opmode; |
5640b08e | 1490 | |
4e30ffa2 VN |
1491 | /* |
1492 | * Enable MIB interrupts when there are hardware phy counters. | |
1493 | * Note we only do this (at the moment) for station mode. | |
1494 | */ | |
1ed32e4f JB |
1495 | if ((vif->type == NL80211_IFTYPE_STATION) || |
1496 | (vif->type == NL80211_IFTYPE_ADHOC) || | |
1497 | (vif->type == NL80211_IFTYPE_MESH_POINT)) { | |
3448f912 LR |
1498 | if (ah->config.enable_ani) |
1499 | ah->imask |= ATH9K_INT_MIB; | |
3069168c | 1500 | ah->imask |= ATH9K_INT_TSFOOR; |
4af9cf4f S |
1501 | } |
1502 | ||
3069168c | 1503 | ath9k_hw_set_interrupts(ah, ah->imask); |
4e30ffa2 | 1504 | |
1ed32e4f | 1505 | if (vif->type == NL80211_IFTYPE_AP || |
5f841b41 | 1506 | vif->type == NL80211_IFTYPE_ADHOC) { |
6c3118e2 | 1507 | sc->sc_flags |= SC_OP_ANI_RUN; |
3d536acf | 1508 | ath_start_ani(common); |
6c3118e2 | 1509 | } |
6f255425 | 1510 | |
2c3db3d5 | 1511 | out: |
141b38b6 | 1512 | mutex_unlock(&sc->mutex); |
2c3db3d5 | 1513 | return ret; |
f078f209 LR |
1514 | } |
1515 | ||
8feceb67 | 1516 | static void ath9k_remove_interface(struct ieee80211_hw *hw, |
1ed32e4f | 1517 | struct ieee80211_vif *vif) |
f078f209 | 1518 | { |
bce048d7 JM |
1519 | struct ath_wiphy *aphy = hw->priv; |
1520 | struct ath_softc *sc = aphy->sc; | |
c46917bb | 1521 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
1ed32e4f | 1522 | struct ath_vif *avp = (void *)vif->drv_priv; |
2c3db3d5 | 1523 | int i; |
f078f209 | 1524 | |
c46917bb | 1525 | ath_print(common, ATH_DBG_CONFIG, "Detach Interface\n"); |
f078f209 | 1526 | |
141b38b6 S |
1527 | mutex_lock(&sc->mutex); |
1528 | ||
6f255425 | 1529 | /* Stop ANI */ |
6c3118e2 | 1530 | sc->sc_flags &= ~SC_OP_ANI_RUN; |
3d536acf | 1531 | del_timer_sync(&common->ani.timer); |
580f0b8a | 1532 | |
8feceb67 | 1533 | /* Reclaim beacon resources */ |
9cb5412b PE |
1534 | if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) || |
1535 | (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC) || | |
1536 | (sc->sc_ah->opmode == NL80211_IFTYPE_MESH_POINT)) { | |
5f70a88f | 1537 | ath9k_ps_wakeup(sc); |
b77f483f | 1538 | ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq); |
5f70a88f | 1539 | ath9k_ps_restore(sc); |
580f0b8a | 1540 | } |
f078f209 | 1541 | |
74401773 | 1542 | ath_beacon_return(sc, avp); |
8feceb67 | 1543 | sc->sc_flags &= ~SC_OP_BEACONS; |
f078f209 | 1544 | |
2c3db3d5 | 1545 | for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++) { |
1ed32e4f | 1546 | if (sc->beacon.bslot[i] == vif) { |
2c3db3d5 JM |
1547 | printk(KERN_DEBUG "%s: vif had allocated beacon " |
1548 | "slot\n", __func__); | |
1549 | sc->beacon.bslot[i] = NULL; | |
c52f33d0 | 1550 | sc->beacon.bslot_aphy[i] = NULL; |
2c3db3d5 JM |
1551 | } |
1552 | } | |
1553 | ||
17d7904d | 1554 | sc->nvifs--; |
141b38b6 S |
1555 | |
1556 | mutex_unlock(&sc->mutex); | |
f078f209 LR |
1557 | } |
1558 | ||
fbab7390 | 1559 | static void ath9k_enable_ps(struct ath_softc *sc) |
3f7c5c10 | 1560 | { |
3069168c PR |
1561 | struct ath_hw *ah = sc->sc_ah; |
1562 | ||
3f7c5c10 | 1563 | sc->ps_enabled = true; |
3069168c PR |
1564 | if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) { |
1565 | if ((ah->imask & ATH9K_INT_TIM_TIMER) == 0) { | |
1566 | ah->imask |= ATH9K_INT_TIM_TIMER; | |
1567 | ath9k_hw_set_interrupts(ah, ah->imask); | |
3f7c5c10 | 1568 | } |
fdf76622 | 1569 | ath9k_hw_setrxabort(ah, 1); |
3f7c5c10 | 1570 | } |
3f7c5c10 SB |
1571 | } |
1572 | ||
845d708e SB |
1573 | static void ath9k_disable_ps(struct ath_softc *sc) |
1574 | { | |
1575 | struct ath_hw *ah = sc->sc_ah; | |
1576 | ||
1577 | sc->ps_enabled = false; | |
1578 | ath9k_hw_setpower(ah, ATH9K_PM_AWAKE); | |
1579 | if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) { | |
1580 | ath9k_hw_setrxabort(ah, 0); | |
1581 | sc->ps_flags &= ~(PS_WAIT_FOR_BEACON | | |
1582 | PS_WAIT_FOR_CAB | | |
1583 | PS_WAIT_FOR_PSPOLL_DATA | | |
1584 | PS_WAIT_FOR_TX_ACK); | |
1585 | if (ah->imask & ATH9K_INT_TIM_TIMER) { | |
1586 | ah->imask &= ~ATH9K_INT_TIM_TIMER; | |
1587 | ath9k_hw_set_interrupts(ah, ah->imask); | |
1588 | } | |
1589 | } | |
1590 | ||
1591 | } | |
1592 | ||
e8975581 | 1593 | static int ath9k_config(struct ieee80211_hw *hw, u32 changed) |
f078f209 | 1594 | { |
bce048d7 JM |
1595 | struct ath_wiphy *aphy = hw->priv; |
1596 | struct ath_softc *sc = aphy->sc; | |
3430098a FF |
1597 | struct ath_hw *ah = sc->sc_ah; |
1598 | struct ath_common *common = ath9k_hw_common(ah); | |
e8975581 | 1599 | struct ieee80211_conf *conf = &hw->conf; |
194b7c13 | 1600 | bool disable_radio; |
f078f209 | 1601 | |
aa33de09 | 1602 | mutex_lock(&sc->mutex); |
141b38b6 | 1603 | |
194b7c13 LR |
1604 | /* |
1605 | * Leave this as the first check because we need to turn on the | |
1606 | * radio if it was disabled before prior to processing the rest | |
1607 | * of the changes. Likewise we must only disable the radio towards | |
1608 | * the end. | |
1609 | */ | |
64839170 | 1610 | if (changed & IEEE80211_CONF_CHANGE_IDLE) { |
194b7c13 LR |
1611 | bool enable_radio; |
1612 | bool all_wiphys_idle; | |
1613 | bool idle = !!(conf->flags & IEEE80211_CONF_IDLE); | |
64839170 LR |
1614 | |
1615 | spin_lock_bh(&sc->wiphy_lock); | |
1616 | all_wiphys_idle = ath9k_all_wiphys_idle(sc); | |
194b7c13 LR |
1617 | ath9k_set_wiphy_idle(aphy, idle); |
1618 | ||
11446011 | 1619 | enable_radio = (!idle && all_wiphys_idle); |
194b7c13 LR |
1620 | |
1621 | /* | |
1622 | * After we unlock here its possible another wiphy | |
1623 | * can be re-renabled so to account for that we will | |
1624 | * only disable the radio toward the end of this routine | |
1625 | * if by then all wiphys are still idle. | |
1626 | */ | |
64839170 LR |
1627 | spin_unlock_bh(&sc->wiphy_lock); |
1628 | ||
194b7c13 | 1629 | if (enable_radio) { |
1dbfd9d4 | 1630 | sc->ps_idle = false; |
68a89116 | 1631 | ath_radio_enable(sc, hw); |
c46917bb LR |
1632 | ath_print(common, ATH_DBG_CONFIG, |
1633 | "not-idle: enabling radio\n"); | |
64839170 LR |
1634 | } |
1635 | } | |
1636 | ||
e7824a50 LR |
1637 | /* |
1638 | * We just prepare to enable PS. We have to wait until our AP has | |
1639 | * ACK'd our null data frame to disable RX otherwise we'll ignore | |
1640 | * those ACKs and end up retransmitting the same null data frames. | |
1641 | * IEEE80211_CONF_CHANGE_PS is only passed by mac80211 for STA mode. | |
1642 | */ | |
3cbb5dd7 | 1643 | if (changed & IEEE80211_CONF_CHANGE_PS) { |
8ab2cd09 LR |
1644 | unsigned long flags; |
1645 | spin_lock_irqsave(&sc->sc_pm_lock, flags); | |
fbab7390 SB |
1646 | if (conf->flags & IEEE80211_CONF_PS) |
1647 | ath9k_enable_ps(sc); | |
845d708e SB |
1648 | else |
1649 | ath9k_disable_ps(sc); | |
8ab2cd09 | 1650 | spin_unlock_irqrestore(&sc->sc_pm_lock, flags); |
3cbb5dd7 VN |
1651 | } |
1652 | ||
199afd9d S |
1653 | if (changed & IEEE80211_CONF_CHANGE_MONITOR) { |
1654 | if (conf->flags & IEEE80211_CONF_MONITOR) { | |
1655 | ath_print(common, ATH_DBG_CONFIG, | |
5f841b41 RM |
1656 | "Monitor mode is enabled\n"); |
1657 | sc->sc_ah->is_monitoring = true; | |
1658 | } else { | |
1659 | ath_print(common, ATH_DBG_CONFIG, | |
1660 | "Monitor mode is disabled\n"); | |
1661 | sc->sc_ah->is_monitoring = false; | |
199afd9d S |
1662 | } |
1663 | } | |
1664 | ||
4797938c | 1665 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { |
99405f93 | 1666 | struct ieee80211_channel *curchan = hw->conf.channel; |
5f8e077c | 1667 | int pos = curchan->hw_value; |
3430098a FF |
1668 | int old_pos = -1; |
1669 | unsigned long flags; | |
1670 | ||
1671 | if (ah->curchan) | |
1672 | old_pos = ah->curchan - &ah->channels[0]; | |
ae5eb026 | 1673 | |
0e2dedf9 JM |
1674 | aphy->chan_idx = pos; |
1675 | aphy->chan_is_ht = conf_is_ht(conf); | |
5ee08656 FF |
1676 | if (hw->conf.flags & IEEE80211_CONF_OFFCHANNEL) |
1677 | sc->sc_flags |= SC_OP_OFFCHANNEL; | |
1678 | else | |
1679 | sc->sc_flags &= ~SC_OP_OFFCHANNEL; | |
0e2dedf9 | 1680 | |
8089cc47 JM |
1681 | if (aphy->state == ATH_WIPHY_SCAN || |
1682 | aphy->state == ATH_WIPHY_ACTIVE) | |
1683 | ath9k_wiphy_pause_all_forced(sc, aphy); | |
1684 | else { | |
1685 | /* | |
1686 | * Do not change operational channel based on a paused | |
1687 | * wiphy changes. | |
1688 | */ | |
1689 | goto skip_chan_change; | |
1690 | } | |
0e2dedf9 | 1691 | |
c46917bb LR |
1692 | ath_print(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n", |
1693 | curchan->center_freq); | |
f078f209 | 1694 | |
5f8e077c | 1695 | /* XXX: remove me eventualy */ |
0e2dedf9 | 1696 | ath9k_update_ichannel(sc, hw, &sc->sc_ah->channels[pos]); |
e11602b7 | 1697 | |
ecf70441 | 1698 | ath_update_chainmask(sc, conf_is_ht(conf)); |
86060f0d | 1699 | |
3430098a FF |
1700 | /* update survey stats for the old channel before switching */ |
1701 | spin_lock_irqsave(&common->cc_lock, flags); | |
1702 | ath_update_survey_stats(sc); | |
1703 | spin_unlock_irqrestore(&common->cc_lock, flags); | |
1704 | ||
1705 | /* | |
1706 | * If the operating channel changes, change the survey in-use flags | |
1707 | * along with it. | |
1708 | * Reset the survey data for the new channel, unless we're switching | |
1709 | * back to the operating channel from an off-channel operation. | |
1710 | */ | |
1711 | if (!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL) && | |
1712 | sc->cur_survey != &sc->survey[pos]) { | |
1713 | ||
1714 | if (sc->cur_survey) | |
1715 | sc->cur_survey->filled &= ~SURVEY_INFO_IN_USE; | |
1716 | ||
1717 | sc->cur_survey = &sc->survey[pos]; | |
1718 | ||
1719 | memset(sc->cur_survey, 0, sizeof(struct survey_info)); | |
1720 | sc->cur_survey->filled |= SURVEY_INFO_IN_USE; | |
1721 | } else if (!(sc->survey[pos].filled & SURVEY_INFO_IN_USE)) { | |
1722 | memset(&sc->survey[pos], 0, sizeof(struct survey_info)); | |
1723 | } | |
1724 | ||
0e2dedf9 | 1725 | if (ath_set_channel(sc, hw, &sc->sc_ah->channels[pos]) < 0) { |
c46917bb LR |
1726 | ath_print(common, ATH_DBG_FATAL, |
1727 | "Unable to set channel\n"); | |
aa33de09 | 1728 | mutex_unlock(&sc->mutex); |
e11602b7 S |
1729 | return -EINVAL; |
1730 | } | |
3430098a FF |
1731 | |
1732 | /* | |
1733 | * The most recent snapshot of channel->noisefloor for the old | |
1734 | * channel is only available after the hardware reset. Copy it to | |
1735 | * the survey stats now. | |
1736 | */ | |
1737 | if (old_pos >= 0) | |
1738 | ath_update_survey_nf(sc, old_pos); | |
094d05dc | 1739 | } |
f078f209 | 1740 | |
8089cc47 | 1741 | skip_chan_change: |
c9f6a656 | 1742 | if (changed & IEEE80211_CONF_CHANGE_POWER) { |
17d7904d | 1743 | sc->config.txpowlimit = 2 * conf->power_level; |
c9f6a656 LR |
1744 | ath_update_txpow(sc); |
1745 | } | |
f078f209 | 1746 | |
194b7c13 LR |
1747 | spin_lock_bh(&sc->wiphy_lock); |
1748 | disable_radio = ath9k_all_wiphys_idle(sc); | |
1749 | spin_unlock_bh(&sc->wiphy_lock); | |
1750 | ||
64839170 | 1751 | if (disable_radio) { |
c46917bb | 1752 | ath_print(common, ATH_DBG_CONFIG, "idle: disabling radio\n"); |
1dbfd9d4 | 1753 | sc->ps_idle = true; |
68a89116 | 1754 | ath_radio_disable(sc, hw); |
64839170 LR |
1755 | } |
1756 | ||
aa33de09 | 1757 | mutex_unlock(&sc->mutex); |
141b38b6 | 1758 | |
f078f209 LR |
1759 | return 0; |
1760 | } | |
1761 | ||
8feceb67 VT |
1762 | #define SUPPORTED_FILTERS \ |
1763 | (FIF_PROMISC_IN_BSS | \ | |
1764 | FIF_ALLMULTI | \ | |
1765 | FIF_CONTROL | \ | |
af6a3fc7 | 1766 | FIF_PSPOLL | \ |
8feceb67 VT |
1767 | FIF_OTHER_BSS | \ |
1768 | FIF_BCN_PRBRESP_PROMISC | \ | |
9c1d8e4a | 1769 | FIF_PROBE_REQ | \ |
8feceb67 | 1770 | FIF_FCSFAIL) |
c83be688 | 1771 | |
8feceb67 VT |
1772 | /* FIXME: sc->sc_full_reset ? */ |
1773 | static void ath9k_configure_filter(struct ieee80211_hw *hw, | |
1774 | unsigned int changed_flags, | |
1775 | unsigned int *total_flags, | |
3ac64bee | 1776 | u64 multicast) |
8feceb67 | 1777 | { |
bce048d7 JM |
1778 | struct ath_wiphy *aphy = hw->priv; |
1779 | struct ath_softc *sc = aphy->sc; | |
8feceb67 | 1780 | u32 rfilt; |
f078f209 | 1781 | |
8feceb67 VT |
1782 | changed_flags &= SUPPORTED_FILTERS; |
1783 | *total_flags &= SUPPORTED_FILTERS; | |
f078f209 | 1784 | |
b77f483f | 1785 | sc->rx.rxfilter = *total_flags; |
aa68aeaa | 1786 | ath9k_ps_wakeup(sc); |
8feceb67 VT |
1787 | rfilt = ath_calcrxfilter(sc); |
1788 | ath9k_hw_setrxfilter(sc->sc_ah, rfilt); | |
aa68aeaa | 1789 | ath9k_ps_restore(sc); |
f078f209 | 1790 | |
c46917bb LR |
1791 | ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_CONFIG, |
1792 | "Set HW RX filter: 0x%x\n", rfilt); | |
8feceb67 | 1793 | } |
f078f209 | 1794 | |
4ca77860 JB |
1795 | static int ath9k_sta_add(struct ieee80211_hw *hw, |
1796 | struct ieee80211_vif *vif, | |
1797 | struct ieee80211_sta *sta) | |
8feceb67 | 1798 | { |
bce048d7 JM |
1799 | struct ath_wiphy *aphy = hw->priv; |
1800 | struct ath_softc *sc = aphy->sc; | |
f078f209 | 1801 | |
4ca77860 JB |
1802 | ath_node_attach(sc, sta); |
1803 | ||
1804 | return 0; | |
1805 | } | |
1806 | ||
1807 | static int ath9k_sta_remove(struct ieee80211_hw *hw, | |
1808 | struct ieee80211_vif *vif, | |
1809 | struct ieee80211_sta *sta) | |
1810 | { | |
1811 | struct ath_wiphy *aphy = hw->priv; | |
1812 | struct ath_softc *sc = aphy->sc; | |
1813 | ||
1814 | ath_node_detach(sc, sta); | |
1815 | ||
1816 | return 0; | |
f078f209 LR |
1817 | } |
1818 | ||
141b38b6 | 1819 | static int ath9k_conf_tx(struct ieee80211_hw *hw, u16 queue, |
8feceb67 | 1820 | const struct ieee80211_tx_queue_params *params) |
f078f209 | 1821 | { |
bce048d7 JM |
1822 | struct ath_wiphy *aphy = hw->priv; |
1823 | struct ath_softc *sc = aphy->sc; | |
c46917bb | 1824 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
8feceb67 VT |
1825 | struct ath9k_tx_queue_info qi; |
1826 | int ret = 0, qnum; | |
f078f209 | 1827 | |
8feceb67 VT |
1828 | if (queue >= WME_NUM_AC) |
1829 | return 0; | |
f078f209 | 1830 | |
141b38b6 S |
1831 | mutex_lock(&sc->mutex); |
1832 | ||
1ffb0610 S |
1833 | memset(&qi, 0, sizeof(struct ath9k_tx_queue_info)); |
1834 | ||
8feceb67 VT |
1835 | qi.tqi_aifs = params->aifs; |
1836 | qi.tqi_cwmin = params->cw_min; | |
1837 | qi.tqi_cwmax = params->cw_max; | |
1838 | qi.tqi_burstTime = params->txop; | |
1839 | qnum = ath_get_hal_qnum(queue, sc); | |
f078f209 | 1840 | |
c46917bb LR |
1841 | ath_print(common, ATH_DBG_CONFIG, |
1842 | "Configure tx [queue/halq] [%d/%d], " | |
1843 | "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n", | |
1844 | queue, qnum, params->aifs, params->cw_min, | |
1845 | params->cw_max, params->txop); | |
f078f209 | 1846 | |
8feceb67 VT |
1847 | ret = ath_txq_update(sc, qnum, &qi); |
1848 | if (ret) | |
c46917bb | 1849 | ath_print(common, ATH_DBG_FATAL, "TXQ Update failed\n"); |
f078f209 | 1850 | |
94db2936 | 1851 | if (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC) |
1d2231e2 | 1852 | if ((qnum == sc->tx.hwq_map[WME_AC_BE]) && !ret) |
94db2936 VN |
1853 | ath_beaconq_config(sc); |
1854 | ||
141b38b6 S |
1855 | mutex_unlock(&sc->mutex); |
1856 | ||
8feceb67 VT |
1857 | return ret; |
1858 | } | |
f078f209 | 1859 | |
8feceb67 VT |
1860 | static int ath9k_set_key(struct ieee80211_hw *hw, |
1861 | enum set_key_cmd cmd, | |
dc822b5d JB |
1862 | struct ieee80211_vif *vif, |
1863 | struct ieee80211_sta *sta, | |
8feceb67 VT |
1864 | struct ieee80211_key_conf *key) |
1865 | { | |
bce048d7 JM |
1866 | struct ath_wiphy *aphy = hw->priv; |
1867 | struct ath_softc *sc = aphy->sc; | |
c46917bb | 1868 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
8feceb67 | 1869 | int ret = 0; |
f078f209 | 1870 | |
b3bd89ce JM |
1871 | if (modparam_nohwcrypt) |
1872 | return -ENOSPC; | |
1873 | ||
141b38b6 | 1874 | mutex_lock(&sc->mutex); |
3cbb5dd7 | 1875 | ath9k_ps_wakeup(sc); |
c46917bb | 1876 | ath_print(common, ATH_DBG_CONFIG, "Set HW Key\n"); |
f078f209 | 1877 | |
8feceb67 VT |
1878 | switch (cmd) { |
1879 | case SET_KEY: | |
040e539e | 1880 | ret = ath_key_config(common, vif, sta, key); |
6ace2891 JM |
1881 | if (ret >= 0) { |
1882 | key->hw_key_idx = ret; | |
8feceb67 VT |
1883 | /* push IV and Michael MIC generation to stack */ |
1884 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; | |
97359d12 | 1885 | if (key->cipher == WLAN_CIPHER_SUITE_TKIP) |
8feceb67 | 1886 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; |
97359d12 JB |
1887 | if (sc->sc_ah->sw_mgmt_crypto && |
1888 | key->cipher == WLAN_CIPHER_SUITE_CCMP) | |
0ced0e17 | 1889 | key->flags |= IEEE80211_KEY_FLAG_SW_MGMT; |
6ace2891 | 1890 | ret = 0; |
8feceb67 VT |
1891 | } |
1892 | break; | |
1893 | case DISABLE_KEY: | |
040e539e | 1894 | ath_key_delete(common, key); |
8feceb67 VT |
1895 | break; |
1896 | default: | |
1897 | ret = -EINVAL; | |
1898 | } | |
f078f209 | 1899 | |
3cbb5dd7 | 1900 | ath9k_ps_restore(sc); |
141b38b6 S |
1901 | mutex_unlock(&sc->mutex); |
1902 | ||
8feceb67 VT |
1903 | return ret; |
1904 | } | |
f078f209 | 1905 | |
8feceb67 VT |
1906 | static void ath9k_bss_info_changed(struct ieee80211_hw *hw, |
1907 | struct ieee80211_vif *vif, | |
1908 | struct ieee80211_bss_conf *bss_conf, | |
1909 | u32 changed) | |
1910 | { | |
bce048d7 JM |
1911 | struct ath_wiphy *aphy = hw->priv; |
1912 | struct ath_softc *sc = aphy->sc; | |
2d0ddec5 | 1913 | struct ath_hw *ah = sc->sc_ah; |
1510718d | 1914 | struct ath_common *common = ath9k_hw_common(ah); |
2d0ddec5 | 1915 | struct ath_vif *avp = (void *)vif->drv_priv; |
0005baf4 | 1916 | int slottime; |
c6089ccc | 1917 | int error; |
f078f209 | 1918 | |
141b38b6 S |
1919 | mutex_lock(&sc->mutex); |
1920 | ||
c6089ccc S |
1921 | if (changed & BSS_CHANGED_BSSID) { |
1922 | /* Set BSSID */ | |
1923 | memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN); | |
1924 | memcpy(avp->bssid, bss_conf->bssid, ETH_ALEN); | |
1510718d | 1925 | common->curaid = 0; |
f2b2143e | 1926 | ath9k_hw_write_associd(ah); |
2d0ddec5 | 1927 | |
c6089ccc S |
1928 | /* Set aggregation protection mode parameters */ |
1929 | sc->config.ath_aggr_prot = 0; | |
2d0ddec5 | 1930 | |
c6089ccc S |
1931 | /* Only legacy IBSS for now */ |
1932 | if (vif->type == NL80211_IFTYPE_ADHOC) | |
1933 | ath_update_chainmask(sc, 0); | |
2d0ddec5 | 1934 | |
c6089ccc S |
1935 | ath_print(common, ATH_DBG_CONFIG, |
1936 | "BSSID: %pM aid: 0x%x\n", | |
1937 | common->curbssid, common->curaid); | |
2d0ddec5 | 1938 | |
c6089ccc S |
1939 | /* need to reconfigure the beacon */ |
1940 | sc->sc_flags &= ~SC_OP_BEACONS ; | |
1941 | } | |
2d0ddec5 | 1942 | |
c6089ccc S |
1943 | /* Enable transmission of beacons (AP, IBSS, MESH) */ |
1944 | if ((changed & BSS_CHANGED_BEACON) || | |
1945 | ((changed & BSS_CHANGED_BEACON_ENABLED) && bss_conf->enable_beacon)) { | |
1946 | ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq); | |
1947 | error = ath_beacon_alloc(aphy, vif); | |
1948 | if (!error) | |
1949 | ath_beacon_config(sc, vif); | |
0005baf4 FF |
1950 | } |
1951 | ||
1952 | if (changed & BSS_CHANGED_ERP_SLOT) { | |
1953 | if (bss_conf->use_short_slot) | |
1954 | slottime = 9; | |
1955 | else | |
1956 | slottime = 20; | |
1957 | if (vif->type == NL80211_IFTYPE_AP) { | |
1958 | /* | |
1959 | * Defer update, so that connected stations can adjust | |
1960 | * their settings at the same time. | |
1961 | * See beacon.c for more details | |
1962 | */ | |
1963 | sc->beacon.slottime = slottime; | |
1964 | sc->beacon.updateslot = UPDATE; | |
1965 | } else { | |
1966 | ah->slottime = slottime; | |
1967 | ath9k_hw_init_global_settings(ah); | |
1968 | } | |
2d0ddec5 JB |
1969 | } |
1970 | ||
c6089ccc S |
1971 | /* Disable transmission of beacons */ |
1972 | if ((changed & BSS_CHANGED_BEACON_ENABLED) && !bss_conf->enable_beacon) | |
1973 | ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq); | |
2d0ddec5 | 1974 | |
c6089ccc S |
1975 | if (changed & BSS_CHANGED_BEACON_INT) { |
1976 | sc->beacon_interval = bss_conf->beacon_int; | |
1977 | /* | |
1978 | * In case of AP mode, the HW TSF has to be reset | |
1979 | * when the beacon interval changes. | |
1980 | */ | |
1981 | if (vif->type == NL80211_IFTYPE_AP) { | |
1982 | sc->sc_flags |= SC_OP_TSF_RESET; | |
1983 | ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq); | |
2d0ddec5 JB |
1984 | error = ath_beacon_alloc(aphy, vif); |
1985 | if (!error) | |
1986 | ath_beacon_config(sc, vif); | |
c6089ccc S |
1987 | } else { |
1988 | ath_beacon_config(sc, vif); | |
2d0ddec5 JB |
1989 | } |
1990 | } | |
1991 | ||
8feceb67 | 1992 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { |
c46917bb LR |
1993 | ath_print(common, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n", |
1994 | bss_conf->use_short_preamble); | |
8feceb67 VT |
1995 | if (bss_conf->use_short_preamble) |
1996 | sc->sc_flags |= SC_OP_PREAMBLE_SHORT; | |
1997 | else | |
1998 | sc->sc_flags &= ~SC_OP_PREAMBLE_SHORT; | |
1999 | } | |
f078f209 | 2000 | |
8feceb67 | 2001 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { |
c46917bb LR |
2002 | ath_print(common, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n", |
2003 | bss_conf->use_cts_prot); | |
8feceb67 VT |
2004 | if (bss_conf->use_cts_prot && |
2005 | hw->conf.channel->band != IEEE80211_BAND_5GHZ) | |
2006 | sc->sc_flags |= SC_OP_PROTECT_ENABLE; | |
2007 | else | |
2008 | sc->sc_flags &= ~SC_OP_PROTECT_ENABLE; | |
2009 | } | |
f078f209 | 2010 | |
8feceb67 | 2011 | if (changed & BSS_CHANGED_ASSOC) { |
c46917bb | 2012 | ath_print(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n", |
8feceb67 | 2013 | bss_conf->assoc); |
5640b08e | 2014 | ath9k_bss_assoc_info(sc, vif, bss_conf); |
8feceb67 | 2015 | } |
141b38b6 S |
2016 | |
2017 | mutex_unlock(&sc->mutex); | |
8feceb67 | 2018 | } |
f078f209 | 2019 | |
8feceb67 VT |
2020 | static u64 ath9k_get_tsf(struct ieee80211_hw *hw) |
2021 | { | |
2022 | u64 tsf; | |
bce048d7 JM |
2023 | struct ath_wiphy *aphy = hw->priv; |
2024 | struct ath_softc *sc = aphy->sc; | |
f078f209 | 2025 | |
141b38b6 S |
2026 | mutex_lock(&sc->mutex); |
2027 | tsf = ath9k_hw_gettsf64(sc->sc_ah); | |
2028 | mutex_unlock(&sc->mutex); | |
f078f209 | 2029 | |
8feceb67 VT |
2030 | return tsf; |
2031 | } | |
f078f209 | 2032 | |
3b5d665b AF |
2033 | static void ath9k_set_tsf(struct ieee80211_hw *hw, u64 tsf) |
2034 | { | |
bce048d7 JM |
2035 | struct ath_wiphy *aphy = hw->priv; |
2036 | struct ath_softc *sc = aphy->sc; | |
3b5d665b | 2037 | |
141b38b6 S |
2038 | mutex_lock(&sc->mutex); |
2039 | ath9k_hw_settsf64(sc->sc_ah, tsf); | |
2040 | mutex_unlock(&sc->mutex); | |
3b5d665b AF |
2041 | } |
2042 | ||
8feceb67 VT |
2043 | static void ath9k_reset_tsf(struct ieee80211_hw *hw) |
2044 | { | |
bce048d7 JM |
2045 | struct ath_wiphy *aphy = hw->priv; |
2046 | struct ath_softc *sc = aphy->sc; | |
c83be688 | 2047 | |
141b38b6 | 2048 | mutex_lock(&sc->mutex); |
21526d57 LR |
2049 | |
2050 | ath9k_ps_wakeup(sc); | |
141b38b6 | 2051 | ath9k_hw_reset_tsf(sc->sc_ah); |
21526d57 LR |
2052 | ath9k_ps_restore(sc); |
2053 | ||
141b38b6 | 2054 | mutex_unlock(&sc->mutex); |
8feceb67 | 2055 | } |
f078f209 | 2056 | |
8feceb67 | 2057 | static int ath9k_ampdu_action(struct ieee80211_hw *hw, |
c951ad35 | 2058 | struct ieee80211_vif *vif, |
141b38b6 S |
2059 | enum ieee80211_ampdu_mlme_action action, |
2060 | struct ieee80211_sta *sta, | |
2061 | u16 tid, u16 *ssn) | |
8feceb67 | 2062 | { |
bce048d7 JM |
2063 | struct ath_wiphy *aphy = hw->priv; |
2064 | struct ath_softc *sc = aphy->sc; | |
8feceb67 | 2065 | int ret = 0; |
f078f209 | 2066 | |
85ad181e JB |
2067 | local_bh_disable(); |
2068 | ||
8feceb67 VT |
2069 | switch (action) { |
2070 | case IEEE80211_AMPDU_RX_START: | |
dca3edb8 S |
2071 | if (!(sc->sc_flags & SC_OP_RXAGGR)) |
2072 | ret = -ENOTSUPP; | |
8feceb67 VT |
2073 | break; |
2074 | case IEEE80211_AMPDU_RX_STOP: | |
8feceb67 VT |
2075 | break; |
2076 | case IEEE80211_AMPDU_TX_START: | |
8b685ba9 | 2077 | ath9k_ps_wakeup(sc); |
231c3a1f FF |
2078 | ret = ath_tx_aggr_start(sc, sta, tid, ssn); |
2079 | if (!ret) | |
2080 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); | |
8b685ba9 | 2081 | ath9k_ps_restore(sc); |
8feceb67 VT |
2082 | break; |
2083 | case IEEE80211_AMPDU_TX_STOP: | |
8b685ba9 | 2084 | ath9k_ps_wakeup(sc); |
f83da965 | 2085 | ath_tx_aggr_stop(sc, sta, tid); |
c951ad35 | 2086 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
8b685ba9 | 2087 | ath9k_ps_restore(sc); |
8feceb67 | 2088 | break; |
b1720231 | 2089 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
8b685ba9 | 2090 | ath9k_ps_wakeup(sc); |
8469cdef | 2091 | ath_tx_aggr_resume(sc, sta, tid); |
8b685ba9 | 2092 | ath9k_ps_restore(sc); |
8469cdef | 2093 | break; |
8feceb67 | 2094 | default: |
c46917bb LR |
2095 | ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL, |
2096 | "Unknown AMPDU action\n"); | |
8feceb67 VT |
2097 | } |
2098 | ||
85ad181e JB |
2099 | local_bh_enable(); |
2100 | ||
8feceb67 | 2101 | return ret; |
f078f209 LR |
2102 | } |
2103 | ||
62dad5b0 BP |
2104 | static int ath9k_get_survey(struct ieee80211_hw *hw, int idx, |
2105 | struct survey_info *survey) | |
2106 | { | |
2107 | struct ath_wiphy *aphy = hw->priv; | |
2108 | struct ath_softc *sc = aphy->sc; | |
3430098a | 2109 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
39162dbe | 2110 | struct ieee80211_supported_band *sband; |
3430098a FF |
2111 | struct ieee80211_channel *chan; |
2112 | unsigned long flags; | |
2113 | int pos; | |
2114 | ||
2115 | spin_lock_irqsave(&common->cc_lock, flags); | |
2116 | if (idx == 0) | |
2117 | ath_update_survey_stats(sc); | |
39162dbe FF |
2118 | |
2119 | sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ]; | |
2120 | if (sband && idx >= sband->n_channels) { | |
2121 | idx -= sband->n_channels; | |
2122 | sband = NULL; | |
2123 | } | |
62dad5b0 | 2124 | |
39162dbe FF |
2125 | if (!sband) |
2126 | sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ]; | |
62dad5b0 | 2127 | |
3430098a FF |
2128 | if (!sband || idx >= sband->n_channels) { |
2129 | spin_unlock_irqrestore(&common->cc_lock, flags); | |
2130 | return -ENOENT; | |
4f1a5a4b | 2131 | } |
62dad5b0 | 2132 | |
3430098a FF |
2133 | chan = &sband->channels[idx]; |
2134 | pos = chan->hw_value; | |
2135 | memcpy(survey, &sc->survey[pos], sizeof(*survey)); | |
2136 | survey->channel = chan; | |
2137 | spin_unlock_irqrestore(&common->cc_lock, flags); | |
2138 | ||
62dad5b0 BP |
2139 | return 0; |
2140 | } | |
2141 | ||
0c98de65 S |
2142 | static void ath9k_sw_scan_start(struct ieee80211_hw *hw) |
2143 | { | |
bce048d7 JM |
2144 | struct ath_wiphy *aphy = hw->priv; |
2145 | struct ath_softc *sc = aphy->sc; | |
0c98de65 | 2146 | |
3d832611 | 2147 | mutex_lock(&sc->mutex); |
8089cc47 | 2148 | if (ath9k_wiphy_scanning(sc)) { |
8089cc47 | 2149 | /* |
30888338 LR |
2150 | * There is a race here in mac80211 but fixing it requires |
2151 | * we revisit how we handle the scan complete callback. | |
2152 | * After mac80211 fixes we will not have configured hardware | |
2153 | * to the home channel nor would we have configured the RX | |
2154 | * filter yet. | |
8089cc47 | 2155 | */ |
3d832611 | 2156 | mutex_unlock(&sc->mutex); |
8089cc47 JM |
2157 | return; |
2158 | } | |
2159 | ||
2160 | aphy->state = ATH_WIPHY_SCAN; | |
2161 | ath9k_wiphy_pause_all_forced(sc, aphy); | |
3d832611 | 2162 | mutex_unlock(&sc->mutex); |
0c98de65 S |
2163 | } |
2164 | ||
30888338 LR |
2165 | /* |
2166 | * XXX: this requires a revisit after the driver | |
2167 | * scan_complete gets moved to another place/removed in mac80211. | |
2168 | */ | |
0c98de65 S |
2169 | static void ath9k_sw_scan_complete(struct ieee80211_hw *hw) |
2170 | { | |
bce048d7 JM |
2171 | struct ath_wiphy *aphy = hw->priv; |
2172 | struct ath_softc *sc = aphy->sc; | |
0c98de65 | 2173 | |
3d832611 | 2174 | mutex_lock(&sc->mutex); |
8089cc47 | 2175 | aphy->state = ATH_WIPHY_ACTIVE; |
3d832611 | 2176 | mutex_unlock(&sc->mutex); |
0c98de65 S |
2177 | } |
2178 | ||
e239d859 FF |
2179 | static void ath9k_set_coverage_class(struct ieee80211_hw *hw, u8 coverage_class) |
2180 | { | |
2181 | struct ath_wiphy *aphy = hw->priv; | |
2182 | struct ath_softc *sc = aphy->sc; | |
2183 | struct ath_hw *ah = sc->sc_ah; | |
2184 | ||
2185 | mutex_lock(&sc->mutex); | |
2186 | ah->coverage_class = coverage_class; | |
2187 | ath9k_hw_init_global_settings(ah); | |
2188 | mutex_unlock(&sc->mutex); | |
2189 | } | |
2190 | ||
6baff7f9 | 2191 | struct ieee80211_ops ath9k_ops = { |
8feceb67 VT |
2192 | .tx = ath9k_tx, |
2193 | .start = ath9k_start, | |
2194 | .stop = ath9k_stop, | |
2195 | .add_interface = ath9k_add_interface, | |
2196 | .remove_interface = ath9k_remove_interface, | |
2197 | .config = ath9k_config, | |
8feceb67 | 2198 | .configure_filter = ath9k_configure_filter, |
4ca77860 JB |
2199 | .sta_add = ath9k_sta_add, |
2200 | .sta_remove = ath9k_sta_remove, | |
8feceb67 | 2201 | .conf_tx = ath9k_conf_tx, |
8feceb67 | 2202 | .bss_info_changed = ath9k_bss_info_changed, |
8feceb67 | 2203 | .set_key = ath9k_set_key, |
8feceb67 | 2204 | .get_tsf = ath9k_get_tsf, |
3b5d665b | 2205 | .set_tsf = ath9k_set_tsf, |
8feceb67 | 2206 | .reset_tsf = ath9k_reset_tsf, |
4233df6b | 2207 | .ampdu_action = ath9k_ampdu_action, |
62dad5b0 | 2208 | .get_survey = ath9k_get_survey, |
0c98de65 S |
2209 | .sw_scan_start = ath9k_sw_scan_start, |
2210 | .sw_scan_complete = ath9k_sw_scan_complete, | |
3b319aae | 2211 | .rfkill_poll = ath9k_rfkill_poll_state, |
e239d859 | 2212 | .set_coverage_class = ath9k_set_coverage_class, |
8feceb67 | 2213 | }; |