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