2 * Copyright (c) 2008-2009 Atheros Communications Inc.
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.
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.
17 #include <linux/nl80211.h>
21 static char *dev_info = "ath9k";
23 MODULE_AUTHOR("Atheros Communications");
24 MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
25 MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
26 MODULE_LICENSE("Dual BSD/GPL");
28 static int modparam_nohwcrypt;
29 module_param_named(nohwcrypt, modparam_nohwcrypt, int, 0444);
30 MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption");
32 /* We use the hw_value as an index into our private channel structure */
34 #define CHAN2G(_freq, _idx) { \
35 .center_freq = (_freq), \
40 #define CHAN5G(_freq, _idx) { \
41 .band = IEEE80211_BAND_5GHZ, \
42 .center_freq = (_freq), \
47 /* Some 2 GHz radios are actually tunable on 2312-2732
48 * on 5 MHz steps, we support the channels which we know
49 * we have calibration data for all cards though to make
51 static struct ieee80211_channel ath9k_2ghz_chantable[] = {
52 CHAN2G(2412, 0), /* Channel 1 */
53 CHAN2G(2417, 1), /* Channel 2 */
54 CHAN2G(2422, 2), /* Channel 3 */
55 CHAN2G(2427, 3), /* Channel 4 */
56 CHAN2G(2432, 4), /* Channel 5 */
57 CHAN2G(2437, 5), /* Channel 6 */
58 CHAN2G(2442, 6), /* Channel 7 */
59 CHAN2G(2447, 7), /* Channel 8 */
60 CHAN2G(2452, 8), /* Channel 9 */
61 CHAN2G(2457, 9), /* Channel 10 */
62 CHAN2G(2462, 10), /* Channel 11 */
63 CHAN2G(2467, 11), /* Channel 12 */
64 CHAN2G(2472, 12), /* Channel 13 */
65 CHAN2G(2484, 13), /* Channel 14 */
68 /* Some 5 GHz radios are actually tunable on XXXX-YYYY
69 * on 5 MHz steps, we support the channels which we know
70 * we have calibration data for all cards though to make
72 static struct ieee80211_channel ath9k_5ghz_chantable[] = {
73 /* _We_ call this UNII 1 */
74 CHAN5G(5180, 14), /* Channel 36 */
75 CHAN5G(5200, 15), /* Channel 40 */
76 CHAN5G(5220, 16), /* Channel 44 */
77 CHAN5G(5240, 17), /* Channel 48 */
78 /* _We_ call this UNII 2 */
79 CHAN5G(5260, 18), /* Channel 52 */
80 CHAN5G(5280, 19), /* Channel 56 */
81 CHAN5G(5300, 20), /* Channel 60 */
82 CHAN5G(5320, 21), /* Channel 64 */
83 /* _We_ call this "Middle band" */
84 CHAN5G(5500, 22), /* Channel 100 */
85 CHAN5G(5520, 23), /* Channel 104 */
86 CHAN5G(5540, 24), /* Channel 108 */
87 CHAN5G(5560, 25), /* Channel 112 */
88 CHAN5G(5580, 26), /* Channel 116 */
89 CHAN5G(5600, 27), /* Channel 120 */
90 CHAN5G(5620, 28), /* Channel 124 */
91 CHAN5G(5640, 29), /* Channel 128 */
92 CHAN5G(5660, 30), /* Channel 132 */
93 CHAN5G(5680, 31), /* Channel 136 */
94 CHAN5G(5700, 32), /* Channel 140 */
95 /* _We_ call this UNII 3 */
96 CHAN5G(5745, 33), /* Channel 149 */
97 CHAN5G(5765, 34), /* Channel 153 */
98 CHAN5G(5785, 35), /* Channel 157 */
99 CHAN5G(5805, 36), /* Channel 161 */
100 CHAN5G(5825, 37), /* Channel 165 */
103 static void ath_cache_conf_rate(struct ath_softc *sc,
104 struct ieee80211_conf *conf)
106 switch (conf->channel->band) {
107 case IEEE80211_BAND_2GHZ:
108 if (conf_is_ht20(conf))
110 sc->hw_rate_table[ATH9K_MODE_11NG_HT20];
111 else if (conf_is_ht40_minus(conf))
113 sc->hw_rate_table[ATH9K_MODE_11NG_HT40MINUS];
114 else if (conf_is_ht40_plus(conf))
116 sc->hw_rate_table[ATH9K_MODE_11NG_HT40PLUS];
119 sc->hw_rate_table[ATH9K_MODE_11G];
121 case IEEE80211_BAND_5GHZ:
122 if (conf_is_ht20(conf))
124 sc->hw_rate_table[ATH9K_MODE_11NA_HT20];
125 else if (conf_is_ht40_minus(conf))
127 sc->hw_rate_table[ATH9K_MODE_11NA_HT40MINUS];
128 else if (conf_is_ht40_plus(conf))
130 sc->hw_rate_table[ATH9K_MODE_11NA_HT40PLUS];
133 sc->hw_rate_table[ATH9K_MODE_11A];
141 static void ath_update_txpow(struct ath_softc *sc)
143 struct ath_hw *ah = sc->sc_ah;
146 if (sc->curtxpow != sc->config.txpowlimit) {
147 ath9k_hw_set_txpowerlimit(ah, sc->config.txpowlimit);
148 /* read back in case value is clamped */
149 ath9k_hw_getcapability(ah, ATH9K_CAP_TXPOW, 1, &txpow);
150 sc->curtxpow = txpow;
154 static u8 parse_mpdudensity(u8 mpdudensity)
157 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
158 * 0 for no restriction
167 switch (mpdudensity) {
173 /* Our lower layer calculations limit our precision to
189 static void ath_setup_rates(struct ath_softc *sc, enum ieee80211_band band)
191 const struct ath_rate_table *rate_table = NULL;
192 struct ieee80211_supported_band *sband;
193 struct ieee80211_rate *rate;
197 case IEEE80211_BAND_2GHZ:
198 rate_table = sc->hw_rate_table[ATH9K_MODE_11G];
200 case IEEE80211_BAND_5GHZ:
201 rate_table = sc->hw_rate_table[ATH9K_MODE_11A];
207 if (rate_table == NULL)
210 sband = &sc->sbands[band];
211 rate = sc->rates[band];
213 if (rate_table->rate_cnt > ATH_RATE_MAX)
214 maxrates = ATH_RATE_MAX;
216 maxrates = rate_table->rate_cnt;
218 for (i = 0; i < maxrates; i++) {
219 rate[i].bitrate = rate_table->info[i].ratekbps / 100;
220 rate[i].hw_value = rate_table->info[i].ratecode;
221 if (rate_table->info[i].short_preamble) {
222 rate[i].hw_value_short = rate_table->info[i].ratecode |
223 rate_table->info[i].short_preamble;
224 rate[i].flags = IEEE80211_RATE_SHORT_PREAMBLE;
228 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "Rate: %2dMbps, ratecode: %2d\n",
229 rate[i].bitrate / 10, rate[i].hw_value);
233 static struct ath9k_channel *ath_get_curchannel(struct ath_softc *sc,
234 struct ieee80211_hw *hw)
236 struct ieee80211_channel *curchan = hw->conf.channel;
237 struct ath9k_channel *channel;
240 chan_idx = curchan->hw_value;
241 channel = &sc->sc_ah->channels[chan_idx];
242 ath9k_update_ichannel(sc, hw, channel);
246 static bool ath9k_setpower(struct ath_softc *sc, enum ath9k_power_mode mode)
251 spin_lock_irqsave(&sc->sc_pm_lock, flags);
252 ret = ath9k_hw_setpower(sc->sc_ah, mode);
253 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
258 void ath9k_ps_wakeup(struct ath_softc *sc)
262 spin_lock_irqsave(&sc->sc_pm_lock, flags);
263 if (++sc->ps_usecount != 1)
266 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
269 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
272 void ath9k_ps_restore(struct ath_softc *sc)
276 spin_lock_irqsave(&sc->sc_pm_lock, flags);
277 if (--sc->ps_usecount != 0)
280 if (sc->ps_enabled &&
281 !(sc->sc_flags & (SC_OP_WAIT_FOR_BEACON |
283 SC_OP_WAIT_FOR_PSPOLL_DATA |
284 SC_OP_WAIT_FOR_TX_ACK)))
285 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_NETWORK_SLEEP);
288 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
292 * Set/change channels. If the channel is really being changed, it's done
293 * by reseting the chip. To accomplish this we must first cleanup any pending
294 * DMA, then restart stuff.
296 int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
297 struct ath9k_channel *hchan)
299 struct ath_hw *ah = sc->sc_ah;
300 bool fastcc = true, stopped;
301 struct ieee80211_channel *channel = hw->conf.channel;
304 if (sc->sc_flags & SC_OP_INVALID)
310 * This is only performed if the channel settings have
313 * To switch channels clear any pending DMA operations;
314 * wait long enough for the RX fifo to drain, reset the
315 * hardware at the new frequency, and then re-enable
316 * the relevant bits of the h/w.
318 ath9k_hw_set_interrupts(ah, 0);
319 ath_drain_all_txq(sc, false);
320 stopped = ath_stoprecv(sc);
322 /* XXX: do not flush receive queue here. We don't want
323 * to flush data frames already in queue because of
324 * changing channel. */
326 if (!stopped || (sc->sc_flags & SC_OP_FULL_RESET))
329 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG,
330 "(%u MHz) -> (%u MHz), chanwidth: %d\n",
331 sc->sc_ah->curchan->channel,
332 channel->center_freq, sc->tx_chan_width);
334 spin_lock_bh(&sc->sc_resetlock);
336 r = ath9k_hw_reset(ah, hchan, fastcc);
338 DPRINTF(sc->sc_ah, ATH_DBG_FATAL,
339 "Unable to reset channel (%u Mhz) "
341 channel->center_freq, r);
342 spin_unlock_bh(&sc->sc_resetlock);
345 spin_unlock_bh(&sc->sc_resetlock);
347 sc->sc_flags &= ~SC_OP_FULL_RESET;
349 if (ath_startrecv(sc) != 0) {
350 DPRINTF(sc->sc_ah, ATH_DBG_FATAL,
351 "Unable to restart recv logic\n");
356 ath_cache_conf_rate(sc, &hw->conf);
357 ath_update_txpow(sc);
358 ath9k_hw_set_interrupts(ah, sc->imask);
361 ath9k_ps_restore(sc);
366 * This routine performs the periodic noise floor calibration function
367 * that is used to adjust and optimize the chip performance. This
368 * takes environmental changes (location, temperature) into account.
369 * When the task is complete, it reschedules itself depending on the
370 * appropriate interval that was calculated.
372 static void ath_ani_calibrate(unsigned long data)
374 struct ath_softc *sc = (struct ath_softc *)data;
375 struct ath_hw *ah = sc->sc_ah;
376 bool longcal = false;
377 bool shortcal = false;
378 bool aniflag = false;
379 unsigned int timestamp = jiffies_to_msecs(jiffies);
380 u32 cal_interval, short_cal_interval;
382 short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ?
383 ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL;
386 * don't calibrate when we're scanning.
387 * we are most likely not on our home channel.
389 spin_lock(&sc->ani_lock);
390 if (sc->sc_flags & SC_OP_SCANNING)
393 /* Only calibrate if awake */
394 if (sc->sc_ah->power_mode != ATH9K_PM_AWAKE)
399 /* Long calibration runs independently of short calibration. */
400 if ((timestamp - sc->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
402 DPRINTF(sc->sc_ah, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
403 sc->ani.longcal_timer = timestamp;
406 /* Short calibration applies only while caldone is false */
407 if (!sc->ani.caldone) {
408 if ((timestamp - sc->ani.shortcal_timer) >= short_cal_interval) {
410 DPRINTF(sc->sc_ah, ATH_DBG_ANI, "shortcal @%lu\n", jiffies);
411 sc->ani.shortcal_timer = timestamp;
412 sc->ani.resetcal_timer = timestamp;
415 if ((timestamp - sc->ani.resetcal_timer) >=
416 ATH_RESTART_CALINTERVAL) {
417 sc->ani.caldone = ath9k_hw_reset_calvalid(ah);
419 sc->ani.resetcal_timer = timestamp;
423 /* Verify whether we must check ANI */
424 if ((timestamp - sc->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
426 sc->ani.checkani_timer = timestamp;
429 /* Skip all processing if there's nothing to do. */
430 if (longcal || shortcal || aniflag) {
431 /* Call ANI routine if necessary */
433 ath9k_hw_ani_monitor(ah, ah->curchan);
435 /* Perform calibration if necessary */
436 if (longcal || shortcal) {
437 sc->ani.caldone = ath9k_hw_calibrate(ah, ah->curchan,
438 sc->rx_chainmask, longcal);
441 sc->ani.noise_floor = ath9k_hw_getchan_noise(ah,
444 DPRINTF(sc->sc_ah, ATH_DBG_ANI," calibrate chan %u/%x nf: %d\n",
445 ah->curchan->channel, ah->curchan->channelFlags,
446 sc->ani.noise_floor);
450 ath9k_ps_restore(sc);
453 spin_unlock(&sc->ani_lock);
455 * Set timer interval based on previous results.
456 * The interval must be the shortest necessary to satisfy ANI,
457 * short calibration and long calibration.
459 cal_interval = ATH_LONG_CALINTERVAL;
460 if (sc->sc_ah->config.enable_ani)
461 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
462 if (!sc->ani.caldone)
463 cal_interval = min(cal_interval, (u32)short_cal_interval);
465 mod_timer(&sc->ani.timer, jiffies + msecs_to_jiffies(cal_interval));
468 static void ath_start_ani(struct ath_softc *sc)
470 unsigned long timestamp = jiffies_to_msecs(jiffies);
472 sc->ani.longcal_timer = timestamp;
473 sc->ani.shortcal_timer = timestamp;
474 sc->ani.checkani_timer = timestamp;
476 mod_timer(&sc->ani.timer,
477 jiffies + msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
481 * Update tx/rx chainmask. For legacy association,
482 * hard code chainmask to 1x1, for 11n association, use
483 * the chainmask configuration, for bt coexistence, use
484 * the chainmask configuration even in legacy mode.
486 void ath_update_chainmask(struct ath_softc *sc, int is_ht)
488 struct ath_hw *ah = sc->sc_ah;
490 if ((sc->sc_flags & SC_OP_SCANNING) || is_ht ||
491 (ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE)) {
492 sc->tx_chainmask = sc->sc_ah->caps.tx_chainmask;
493 sc->rx_chainmask = sc->sc_ah->caps.rx_chainmask;
495 sc->tx_chainmask = 1;
496 sc->rx_chainmask = 1;
499 DPRINTF(ah, ATH_DBG_CONFIG, "tx chmask: %d, rx chmask: %d\n",
500 sc->tx_chainmask, sc->rx_chainmask);
503 static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta)
507 an = (struct ath_node *)sta->drv_priv;
509 if (sc->sc_flags & SC_OP_TXAGGR) {
510 ath_tx_node_init(sc, an);
511 an->maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
512 sta->ht_cap.ampdu_factor);
513 an->mpdudensity = parse_mpdudensity(sta->ht_cap.ampdu_density);
514 an->last_rssi = ATH_RSSI_DUMMY_MARKER;
518 static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta)
520 struct ath_node *an = (struct ath_node *)sta->drv_priv;
522 if (sc->sc_flags & SC_OP_TXAGGR)
523 ath_tx_node_cleanup(sc, an);
526 static void ath9k_tasklet(unsigned long data)
528 struct ath_softc *sc = (struct ath_softc *)data;
529 struct ath_hw *ah = sc->sc_ah;
531 u32 status = sc->intrstatus;
535 if (status & ATH9K_INT_FATAL) {
536 ath_reset(sc, false);
537 ath9k_ps_restore(sc);
541 if (status & (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN)) {
542 spin_lock_bh(&sc->rx.rxflushlock);
543 ath_rx_tasklet(sc, 0);
544 spin_unlock_bh(&sc->rx.rxflushlock);
547 if (status & ATH9K_INT_TX)
550 if ((status & ATH9K_INT_TSFOOR) && sc->ps_enabled) {
552 * TSF sync does not look correct; remain awake to sync with
555 DPRINTF(ah, ATH_DBG_PS, "TSFOOR - Sync with next Beacon\n");
556 sc->sc_flags |= SC_OP_WAIT_FOR_BEACON | SC_OP_BEACON_SYNC;
559 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
560 if (status & ATH9K_INT_GENTIMER)
561 ath_gen_timer_isr(sc->sc_ah);
563 /* re-enable hardware interrupt */
564 ath9k_hw_set_interrupts(ah, sc->imask);
565 ath9k_ps_restore(sc);
568 irqreturn_t ath_isr(int irq, void *dev)
570 #define SCHED_INTR ( \
581 struct ath_softc *sc = dev;
582 struct ath_hw *ah = sc->sc_ah;
583 enum ath9k_int status;
587 * The hardware is not ready/present, don't
588 * touch anything. Note this can happen early
589 * on if the IRQ is shared.
591 if (sc->sc_flags & SC_OP_INVALID)
595 /* shared irq, not for us */
597 if (!ath9k_hw_intrpend(ah))
601 * Figure out the reason(s) for the interrupt. Note
602 * that the hal returns a pseudo-ISR that may include
603 * bits we haven't explicitly enabled so we mask the
604 * value to insure we only process bits we requested.
606 ath9k_hw_getisr(ah, &status); /* NB: clears ISR too */
607 status &= sc->imask; /* discard unasked-for bits */
610 * If there are no status bits set, then this interrupt was not
611 * for me (should have been caught above).
616 /* Cache the status */
617 sc->intrstatus = status;
619 if (status & SCHED_INTR)
623 * If a FATAL or RXORN interrupt is received, we have to reset the
626 if (status & (ATH9K_INT_FATAL | ATH9K_INT_RXORN))
629 if (status & ATH9K_INT_SWBA)
630 tasklet_schedule(&sc->bcon_tasklet);
632 if (status & ATH9K_INT_TXURN)
633 ath9k_hw_updatetxtriglevel(ah, true);
635 if (status & ATH9K_INT_MIB) {
637 * Disable interrupts until we service the MIB
638 * interrupt; otherwise it will continue to
641 ath9k_hw_set_interrupts(ah, 0);
643 * Let the hal handle the event. We assume
644 * it will clear whatever condition caused
647 ath9k_hw_procmibevent(ah);
648 ath9k_hw_set_interrupts(ah, sc->imask);
651 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
652 if (status & ATH9K_INT_TIM_TIMER) {
653 /* Clear RxAbort bit so that we can
655 ath9k_setpower(sc, ATH9K_PM_AWAKE);
656 ath9k_hw_setrxabort(sc->sc_ah, 0);
657 sc->sc_flags |= SC_OP_WAIT_FOR_BEACON;
662 ath_debug_stat_interrupt(sc, status);
665 /* turn off every interrupt except SWBA */
666 ath9k_hw_set_interrupts(ah, (sc->imask & ATH9K_INT_SWBA));
667 tasklet_schedule(&sc->intr_tq);
675 static u32 ath_get_extchanmode(struct ath_softc *sc,
676 struct ieee80211_channel *chan,
677 enum nl80211_channel_type channel_type)
681 switch (chan->band) {
682 case IEEE80211_BAND_2GHZ:
683 switch(channel_type) {
684 case NL80211_CHAN_NO_HT:
685 case NL80211_CHAN_HT20:
686 chanmode = CHANNEL_G_HT20;
688 case NL80211_CHAN_HT40PLUS:
689 chanmode = CHANNEL_G_HT40PLUS;
691 case NL80211_CHAN_HT40MINUS:
692 chanmode = CHANNEL_G_HT40MINUS;
696 case IEEE80211_BAND_5GHZ:
697 switch(channel_type) {
698 case NL80211_CHAN_NO_HT:
699 case NL80211_CHAN_HT20:
700 chanmode = CHANNEL_A_HT20;
702 case NL80211_CHAN_HT40PLUS:
703 chanmode = CHANNEL_A_HT40PLUS;
705 case NL80211_CHAN_HT40MINUS:
706 chanmode = CHANNEL_A_HT40MINUS;
717 static int ath_setkey_tkip(struct ath_softc *sc, u16 keyix, const u8 *key,
718 struct ath9k_keyval *hk, const u8 *addr,
724 key_txmic = key + NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY;
725 key_rxmic = key + NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY;
729 * Group key installation - only two key cache entries are used
730 * regardless of splitmic capability since group key is only
731 * used either for TX or RX.
734 memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
735 memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_mic));
737 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
738 memcpy(hk->kv_txmic, key_rxmic, sizeof(hk->kv_mic));
740 return ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, addr);
743 /* TX and RX keys share the same key cache entry. */
744 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
745 memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_txmic));
746 return ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, addr);
749 /* Separate key cache entries for TX and RX */
751 /* TX key goes at first index, RX key at +32. */
752 memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
753 if (!ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, NULL)) {
754 /* TX MIC entry failed. No need to proceed further */
755 DPRINTF(sc->sc_ah, ATH_DBG_FATAL,
756 "Setting TX MIC Key Failed\n");
760 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
761 /* XXX delete tx key on failure? */
762 return ath9k_hw_set_keycache_entry(sc->sc_ah, keyix + 32, hk, addr);
765 static int ath_reserve_key_cache_slot_tkip(struct ath_softc *sc)
769 for (i = IEEE80211_WEP_NKID; i < sc->keymax / 2; i++) {
770 if (test_bit(i, sc->keymap) ||
771 test_bit(i + 64, sc->keymap))
772 continue; /* At least one part of TKIP key allocated */
774 (test_bit(i + 32, sc->keymap) ||
775 test_bit(i + 64 + 32, sc->keymap)))
776 continue; /* At least one part of TKIP key allocated */
778 /* Found a free slot for a TKIP key */
784 static int ath_reserve_key_cache_slot(struct ath_softc *sc)
788 /* First, try to find slots that would not be available for TKIP. */
790 for (i = IEEE80211_WEP_NKID; i < sc->keymax / 4; i++) {
791 if (!test_bit(i, sc->keymap) &&
792 (test_bit(i + 32, sc->keymap) ||
793 test_bit(i + 64, sc->keymap) ||
794 test_bit(i + 64 + 32, sc->keymap)))
796 if (!test_bit(i + 32, sc->keymap) &&
797 (test_bit(i, sc->keymap) ||
798 test_bit(i + 64, sc->keymap) ||
799 test_bit(i + 64 + 32, sc->keymap)))
801 if (!test_bit(i + 64, sc->keymap) &&
802 (test_bit(i , sc->keymap) ||
803 test_bit(i + 32, sc->keymap) ||
804 test_bit(i + 64 + 32, sc->keymap)))
806 if (!test_bit(i + 64 + 32, sc->keymap) &&
807 (test_bit(i, sc->keymap) ||
808 test_bit(i + 32, sc->keymap) ||
809 test_bit(i + 64, sc->keymap)))
813 for (i = IEEE80211_WEP_NKID; i < sc->keymax / 2; i++) {
814 if (!test_bit(i, sc->keymap) &&
815 test_bit(i + 64, sc->keymap))
817 if (test_bit(i, sc->keymap) &&
818 !test_bit(i + 64, sc->keymap))
823 /* No partially used TKIP slots, pick any available slot */
824 for (i = IEEE80211_WEP_NKID; i < sc->keymax; i++) {
825 /* Do not allow slots that could be needed for TKIP group keys
826 * to be used. This limitation could be removed if we know that
827 * TKIP will not be used. */
828 if (i >= 64 && i < 64 + IEEE80211_WEP_NKID)
831 if (i >= 32 && i < 32 + IEEE80211_WEP_NKID)
833 if (i >= 64 + 32 && i < 64 + 32 + IEEE80211_WEP_NKID)
837 if (!test_bit(i, sc->keymap))
838 return i; /* Found a free slot for a key */
841 /* No free slot found */
845 static int ath_key_config(struct ath_softc *sc,
846 struct ieee80211_vif *vif,
847 struct ieee80211_sta *sta,
848 struct ieee80211_key_conf *key)
850 struct ath9k_keyval hk;
851 const u8 *mac = NULL;
855 memset(&hk, 0, sizeof(hk));
859 hk.kv_type = ATH9K_CIPHER_WEP;
862 hk.kv_type = ATH9K_CIPHER_TKIP;
865 hk.kv_type = ATH9K_CIPHER_AES_CCM;
871 hk.kv_len = key->keylen;
872 memcpy(hk.kv_val, key->key, key->keylen);
874 if (!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
875 /* For now, use the default keys for broadcast keys. This may
876 * need to change with virtual interfaces. */
878 } else if (key->keyidx) {
883 if (vif->type != NL80211_IFTYPE_AP) {
884 /* Only keyidx 0 should be used with unicast key, but
885 * allow this for client mode for now. */
894 if (key->alg == ALG_TKIP)
895 idx = ath_reserve_key_cache_slot_tkip(sc);
897 idx = ath_reserve_key_cache_slot(sc);
899 return -ENOSPC; /* no free key cache entries */
902 if (key->alg == ALG_TKIP)
903 ret = ath_setkey_tkip(sc, idx, key->key, &hk, mac,
904 vif->type == NL80211_IFTYPE_AP);
906 ret = ath9k_hw_set_keycache_entry(sc->sc_ah, idx, &hk, mac);
911 set_bit(idx, sc->keymap);
912 if (key->alg == ALG_TKIP) {
913 set_bit(idx + 64, sc->keymap);
915 set_bit(idx + 32, sc->keymap);
916 set_bit(idx + 64 + 32, sc->keymap);
923 static void ath_key_delete(struct ath_softc *sc, struct ieee80211_key_conf *key)
925 ath9k_hw_keyreset(sc->sc_ah, key->hw_key_idx);
926 if (key->hw_key_idx < IEEE80211_WEP_NKID)
929 clear_bit(key->hw_key_idx, sc->keymap);
930 if (key->alg != ALG_TKIP)
933 clear_bit(key->hw_key_idx + 64, sc->keymap);
935 clear_bit(key->hw_key_idx + 32, sc->keymap);
936 clear_bit(key->hw_key_idx + 64 + 32, sc->keymap);
940 static void setup_ht_cap(struct ath_softc *sc,
941 struct ieee80211_sta_ht_cap *ht_info)
943 u8 tx_streams, rx_streams;
945 ht_info->ht_supported = true;
946 ht_info->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
947 IEEE80211_HT_CAP_SM_PS |
948 IEEE80211_HT_CAP_SGI_40 |
949 IEEE80211_HT_CAP_DSSSCCK40;
951 ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
952 ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
954 /* set up supported mcs set */
955 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
956 tx_streams = !(sc->tx_chainmask & (sc->tx_chainmask - 1)) ? 1 : 2;
957 rx_streams = !(sc->rx_chainmask & (sc->rx_chainmask - 1)) ? 1 : 2;
959 if (tx_streams != rx_streams) {
960 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "TX streams %d, RX streams: %d\n",
961 tx_streams, rx_streams);
962 ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
963 ht_info->mcs.tx_params |= ((tx_streams - 1) <<
964 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
967 ht_info->mcs.rx_mask[0] = 0xff;
969 ht_info->mcs.rx_mask[1] = 0xff;
971 ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
974 static void ath9k_bss_assoc_info(struct ath_softc *sc,
975 struct ieee80211_vif *vif,
976 struct ieee80211_bss_conf *bss_conf)
978 struct ath_hw *ah = sc->sc_ah;
979 struct ath_common *common = ath9k_hw_common(ah);
981 if (bss_conf->assoc) {
982 DPRINTF(ah, ATH_DBG_CONFIG, "Bss Info ASSOC %d, bssid: %pM\n",
983 bss_conf->aid, common->curbssid);
985 /* New association, store aid */
986 common->curaid = bss_conf->aid;
987 ath9k_hw_write_associd(ah);
990 * Request a re-configuration of Beacon related timers
991 * on the receipt of the first Beacon frame (i.e.,
992 * after time sync with the AP).
994 sc->sc_flags |= SC_OP_BEACON_SYNC;
996 /* Configure the beacon */
997 ath_beacon_config(sc, vif);
999 /* Reset rssi stats */
1000 sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
1004 DPRINTF(ah, ATH_DBG_CONFIG, "Bss Info DISASSOC\n");
1007 del_timer_sync(&sc->ani.timer);
1011 /********************************/
1013 /********************************/
1015 static void ath_led_blink_work(struct work_struct *work)
1017 struct ath_softc *sc = container_of(work, struct ath_softc,
1018 ath_led_blink_work.work);
1020 if (!(sc->sc_flags & SC_OP_LED_ASSOCIATED))
1023 if ((sc->led_on_duration == ATH_LED_ON_DURATION_IDLE) ||
1024 (sc->led_off_duration == ATH_LED_OFF_DURATION_IDLE))
1025 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 0);
1027 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin,
1028 (sc->sc_flags & SC_OP_LED_ON) ? 1 : 0);
1030 ieee80211_queue_delayed_work(sc->hw,
1031 &sc->ath_led_blink_work,
1032 (sc->sc_flags & SC_OP_LED_ON) ?
1033 msecs_to_jiffies(sc->led_off_duration) :
1034 msecs_to_jiffies(sc->led_on_duration));
1036 sc->led_on_duration = sc->led_on_cnt ?
1037 max((ATH_LED_ON_DURATION_IDLE - sc->led_on_cnt), 25) :
1038 ATH_LED_ON_DURATION_IDLE;
1039 sc->led_off_duration = sc->led_off_cnt ?
1040 max((ATH_LED_OFF_DURATION_IDLE - sc->led_off_cnt), 10) :
1041 ATH_LED_OFF_DURATION_IDLE;
1042 sc->led_on_cnt = sc->led_off_cnt = 0;
1043 if (sc->sc_flags & SC_OP_LED_ON)
1044 sc->sc_flags &= ~SC_OP_LED_ON;
1046 sc->sc_flags |= SC_OP_LED_ON;
1049 static void ath_led_brightness(struct led_classdev *led_cdev,
1050 enum led_brightness brightness)
1052 struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev);
1053 struct ath_softc *sc = led->sc;
1055 switch (brightness) {
1057 if (led->led_type == ATH_LED_ASSOC ||
1058 led->led_type == ATH_LED_RADIO) {
1059 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin,
1060 (led->led_type == ATH_LED_RADIO));
1061 sc->sc_flags &= ~SC_OP_LED_ASSOCIATED;
1062 if (led->led_type == ATH_LED_RADIO)
1063 sc->sc_flags &= ~SC_OP_LED_ON;
1069 if (led->led_type == ATH_LED_ASSOC) {
1070 sc->sc_flags |= SC_OP_LED_ASSOCIATED;
1071 ieee80211_queue_delayed_work(sc->hw,
1072 &sc->ath_led_blink_work, 0);
1073 } else if (led->led_type == ATH_LED_RADIO) {
1074 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 0);
1075 sc->sc_flags |= SC_OP_LED_ON;
1085 static int ath_register_led(struct ath_softc *sc, struct ath_led *led,
1091 led->led_cdev.name = led->name;
1092 led->led_cdev.default_trigger = trigger;
1093 led->led_cdev.brightness_set = ath_led_brightness;
1095 ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &led->led_cdev);
1097 DPRINTF(sc->sc_ah, ATH_DBG_FATAL,
1098 "Failed to register led:%s", led->name);
1100 led->registered = 1;
1104 static void ath_unregister_led(struct ath_led *led)
1106 if (led->registered) {
1107 led_classdev_unregister(&led->led_cdev);
1108 led->registered = 0;
1112 static void ath_deinit_leds(struct ath_softc *sc)
1114 ath_unregister_led(&sc->assoc_led);
1115 sc->sc_flags &= ~SC_OP_LED_ASSOCIATED;
1116 ath_unregister_led(&sc->tx_led);
1117 ath_unregister_led(&sc->rx_led);
1118 ath_unregister_led(&sc->radio_led);
1119 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 1);
1122 static void ath_init_leds(struct ath_softc *sc)
1127 if (AR_SREV_9287(sc->sc_ah))
1128 sc->sc_ah->led_pin = ATH_LED_PIN_9287;
1130 sc->sc_ah->led_pin = ATH_LED_PIN_DEF;
1132 /* Configure gpio 1 for output */
1133 ath9k_hw_cfg_output(sc->sc_ah, sc->sc_ah->led_pin,
1134 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1135 /* LED off, active low */
1136 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 1);
1138 INIT_DELAYED_WORK(&sc->ath_led_blink_work, ath_led_blink_work);
1140 trigger = ieee80211_get_radio_led_name(sc->hw);
1141 snprintf(sc->radio_led.name, sizeof(sc->radio_led.name),
1142 "ath9k-%s::radio", wiphy_name(sc->hw->wiphy));
1143 ret = ath_register_led(sc, &sc->radio_led, trigger);
1144 sc->radio_led.led_type = ATH_LED_RADIO;
1148 trigger = ieee80211_get_assoc_led_name(sc->hw);
1149 snprintf(sc->assoc_led.name, sizeof(sc->assoc_led.name),
1150 "ath9k-%s::assoc", wiphy_name(sc->hw->wiphy));
1151 ret = ath_register_led(sc, &sc->assoc_led, trigger);
1152 sc->assoc_led.led_type = ATH_LED_ASSOC;
1156 trigger = ieee80211_get_tx_led_name(sc->hw);
1157 snprintf(sc->tx_led.name, sizeof(sc->tx_led.name),
1158 "ath9k-%s::tx", wiphy_name(sc->hw->wiphy));
1159 ret = ath_register_led(sc, &sc->tx_led, trigger);
1160 sc->tx_led.led_type = ATH_LED_TX;
1164 trigger = ieee80211_get_rx_led_name(sc->hw);
1165 snprintf(sc->rx_led.name, sizeof(sc->rx_led.name),
1166 "ath9k-%s::rx", wiphy_name(sc->hw->wiphy));
1167 ret = ath_register_led(sc, &sc->rx_led, trigger);
1168 sc->rx_led.led_type = ATH_LED_RX;
1175 cancel_delayed_work_sync(&sc->ath_led_blink_work);
1176 ath_deinit_leds(sc);
1179 void ath_radio_enable(struct ath_softc *sc)
1181 struct ath_hw *ah = sc->sc_ah;
1182 struct ieee80211_channel *channel = sc->hw->conf.channel;
1185 ath9k_ps_wakeup(sc);
1186 ath9k_hw_configpcipowersave(ah, 0, 0);
1189 ah->curchan = ath_get_curchannel(sc, sc->hw);
1191 spin_lock_bh(&sc->sc_resetlock);
1192 r = ath9k_hw_reset(ah, ah->curchan, false);
1194 DPRINTF(sc->sc_ah, ATH_DBG_FATAL,
1195 "Unable to reset channel %u (%uMhz) ",
1196 "reset status %d\n",
1197 channel->center_freq, r);
1199 spin_unlock_bh(&sc->sc_resetlock);
1201 ath_update_txpow(sc);
1202 if (ath_startrecv(sc) != 0) {
1203 DPRINTF(sc->sc_ah, ATH_DBG_FATAL,
1204 "Unable to restart recv logic\n");
1208 if (sc->sc_flags & SC_OP_BEACONS)
1209 ath_beacon_config(sc, NULL); /* restart beacons */
1211 /* Re-Enable interrupts */
1212 ath9k_hw_set_interrupts(ah, sc->imask);
1215 ath9k_hw_cfg_output(ah, ah->led_pin,
1216 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1217 ath9k_hw_set_gpio(ah, ah->led_pin, 0);
1219 ieee80211_wake_queues(sc->hw);
1220 ath9k_ps_restore(sc);
1223 void ath_radio_disable(struct ath_softc *sc)
1225 struct ath_hw *ah = sc->sc_ah;
1226 struct ieee80211_channel *channel = sc->hw->conf.channel;
1229 ath9k_ps_wakeup(sc);
1230 ieee80211_stop_queues(sc->hw);
1233 ath9k_hw_set_gpio(ah, ah->led_pin, 1);
1234 ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
1236 /* Disable interrupts */
1237 ath9k_hw_set_interrupts(ah, 0);
1239 ath_drain_all_txq(sc, false); /* clear pending tx frames */
1240 ath_stoprecv(sc); /* turn off frame recv */
1241 ath_flushrecv(sc); /* flush recv queue */
1244 ah->curchan = ath_get_curchannel(sc, sc->hw);
1246 spin_lock_bh(&sc->sc_resetlock);
1247 r = ath9k_hw_reset(ah, ah->curchan, false);
1249 DPRINTF(sc->sc_ah, ATH_DBG_FATAL,
1250 "Unable to reset channel %u (%uMhz) "
1251 "reset status %d\n",
1252 channel->center_freq, r);
1254 spin_unlock_bh(&sc->sc_resetlock);
1256 ath9k_hw_phy_disable(ah);
1257 ath9k_hw_configpcipowersave(ah, 1, 1);
1258 ath9k_ps_restore(sc);
1259 ath9k_setpower(sc, ATH9K_PM_FULL_SLEEP);
1262 /*******************/
1264 /*******************/
1266 static bool ath_is_rfkill_set(struct ath_softc *sc)
1268 struct ath_hw *ah = sc->sc_ah;
1270 return ath9k_hw_gpio_get(ah, ah->rfkill_gpio) ==
1271 ah->rfkill_polarity;
1274 static void ath9k_rfkill_poll_state(struct ieee80211_hw *hw)
1276 struct ath_wiphy *aphy = hw->priv;
1277 struct ath_softc *sc = aphy->sc;
1278 bool blocked = !!ath_is_rfkill_set(sc);
1280 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
1283 static void ath_start_rfkill_poll(struct ath_softc *sc)
1285 struct ath_hw *ah = sc->sc_ah;
1287 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1288 wiphy_rfkill_start_polling(sc->hw->wiphy);
1291 void ath_cleanup(struct ath_softc *sc)
1294 free_irq(sc->irq, sc);
1295 ath_bus_cleanup(sc);
1296 kfree(sc->sec_wiphy);
1297 ieee80211_free_hw(sc->hw);
1300 void ath_detach(struct ath_softc *sc)
1302 struct ieee80211_hw *hw = sc->hw;
1303 struct ath_hw *ah = sc->sc_ah;
1306 ath9k_ps_wakeup(sc);
1308 dev_dbg(sc->dev, "Detach ATH hw\n");
1310 ath_deinit_leds(sc);
1311 wiphy_rfkill_stop_polling(sc->hw->wiphy);
1313 for (i = 0; i < sc->num_sec_wiphy; i++) {
1314 struct ath_wiphy *aphy = sc->sec_wiphy[i];
1317 sc->sec_wiphy[i] = NULL;
1318 ieee80211_unregister_hw(aphy->hw);
1319 ieee80211_free_hw(aphy->hw);
1321 ieee80211_unregister_hw(hw);
1325 tasklet_kill(&sc->intr_tq);
1326 tasklet_kill(&sc->bcon_tasklet);
1328 if (!(sc->sc_flags & SC_OP_INVALID))
1329 ath9k_setpower(sc, ATH9K_PM_AWAKE);
1331 /* cleanup tx queues */
1332 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1333 if (ATH_TXQ_SETUP(sc, i))
1334 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
1336 if ((sc->btcoex.no_stomp_timer) &&
1337 ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
1338 ath_gen_timer_free(ah, sc->btcoex.no_stomp_timer);
1340 ath9k_hw_detach(ah);
1341 ath9k_exit_debug(ah);
1345 static int ath9k_reg_notifier(struct wiphy *wiphy,
1346 struct regulatory_request *request)
1348 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1349 struct ath_wiphy *aphy = hw->priv;
1350 struct ath_softc *sc = aphy->sc;
1351 struct ath_regulatory *reg = ath9k_hw_regulatory(sc->sc_ah);
1353 return ath_reg_notifier_apply(wiphy, request, reg);
1357 * Detects if there is any priority bt traffic
1359 static void ath_detect_bt_priority(struct ath_softc *sc)
1361 struct ath_btcoex *btcoex = &sc->btcoex;
1362 struct ath_hw *ah = sc->sc_ah;
1364 if (ath9k_hw_gpio_get(sc->sc_ah, ah->btcoex_hw.btpriority_gpio))
1365 btcoex->bt_priority_cnt++;
1367 if (time_after(jiffies, btcoex->bt_priority_time +
1368 msecs_to_jiffies(ATH_BT_PRIORITY_TIME_THRESHOLD))) {
1369 if (btcoex->bt_priority_cnt >= ATH_BT_CNT_THRESHOLD) {
1370 DPRINTF(sc->sc_ah, ATH_DBG_BTCOEX,
1371 "BT priority traffic detected");
1372 sc->sc_flags |= SC_OP_BT_PRIORITY_DETECTED;
1374 sc->sc_flags &= ~SC_OP_BT_PRIORITY_DETECTED;
1377 btcoex->bt_priority_cnt = 0;
1378 btcoex->bt_priority_time = jiffies;
1383 * Configures appropriate weight based on stomp type.
1385 static void ath9k_btcoex_bt_stomp(struct ath_softc *sc,
1386 enum ath_stomp_type stomp_type)
1388 struct ath_hw *ah = sc->sc_ah;
1390 switch (stomp_type) {
1391 case ATH_BTCOEX_STOMP_ALL:
1392 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
1393 AR_STOMP_ALL_WLAN_WGHT);
1395 case ATH_BTCOEX_STOMP_LOW:
1396 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
1397 AR_STOMP_LOW_WLAN_WGHT);
1399 case ATH_BTCOEX_STOMP_NONE:
1400 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
1401 AR_STOMP_NONE_WLAN_WGHT);
1404 DPRINTF(ah, ATH_DBG_BTCOEX, "Invalid Stomptype\n");
1408 ath9k_hw_btcoex_enable(ah);
1411 static void ath9k_gen_timer_start(struct ath_hw *ah,
1412 struct ath_gen_timer *timer,
1416 ath9k_hw_gen_timer_start(ah, timer, timer_next, timer_period);
1418 if ((ah->ah_sc->imask & ATH9K_INT_GENTIMER) == 0) {
1419 ath9k_hw_set_interrupts(ah, 0);
1420 ah->ah_sc->imask |= ATH9K_INT_GENTIMER;
1421 ath9k_hw_set_interrupts(ah, ah->ah_sc->imask);
1425 static void ath9k_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
1427 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
1429 ath9k_hw_gen_timer_stop(ah, timer);
1431 /* if no timer is enabled, turn off interrupt mask */
1432 if (timer_table->timer_mask.val == 0) {
1433 ath9k_hw_set_interrupts(ah, 0);
1434 ah->ah_sc->imask &= ~ATH9K_INT_GENTIMER;
1435 ath9k_hw_set_interrupts(ah, ah->ah_sc->imask);
1440 * This is the master bt coex timer which runs for every
1441 * 45ms, bt traffic will be given priority during 55% of this
1442 * period while wlan gets remaining 45%
1444 static void ath_btcoex_period_timer(unsigned long data)
1446 struct ath_softc *sc = (struct ath_softc *) data;
1447 struct ath_hw *ah = sc->sc_ah;
1448 struct ath_btcoex *btcoex = &sc->btcoex;
1450 ath_detect_bt_priority(sc);
1452 spin_lock_bh(&btcoex->btcoex_lock);
1454 ath9k_btcoex_bt_stomp(sc, btcoex->bt_stomp_type);
1456 spin_unlock_bh(&btcoex->btcoex_lock);
1458 if (btcoex->btcoex_period != btcoex->btcoex_no_stomp) {
1459 if (btcoex->hw_timer_enabled)
1460 ath9k_gen_timer_stop(ah, btcoex->no_stomp_timer);
1462 ath9k_gen_timer_start(ah,
1463 btcoex->no_stomp_timer,
1464 (ath9k_hw_gettsf32(ah) +
1465 btcoex->btcoex_no_stomp),
1466 btcoex->btcoex_no_stomp * 10);
1467 btcoex->hw_timer_enabled = true;
1470 mod_timer(&btcoex->period_timer, jiffies +
1471 msecs_to_jiffies(ATH_BTCOEX_DEF_BT_PERIOD));
1475 * Generic tsf based hw timer which configures weight
1476 * registers to time slice between wlan and bt traffic
1478 static void ath_btcoex_no_stomp_timer(void *arg)
1480 struct ath_softc *sc = (struct ath_softc *)arg;
1481 struct ath_hw *ah = sc->sc_ah;
1482 struct ath_btcoex *btcoex = &sc->btcoex;
1484 DPRINTF(ah, ATH_DBG_BTCOEX, "no stomp timer running \n");
1486 spin_lock_bh(&btcoex->btcoex_lock);
1488 if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_LOW)
1489 ath9k_btcoex_bt_stomp(sc, ATH_BTCOEX_STOMP_NONE);
1490 else if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_ALL)
1491 ath9k_btcoex_bt_stomp(sc, ATH_BTCOEX_STOMP_LOW);
1493 spin_unlock_bh(&btcoex->btcoex_lock);
1496 static int ath_init_btcoex_timer(struct ath_softc *sc)
1498 struct ath_btcoex *btcoex = &sc->btcoex;
1500 btcoex->btcoex_period = ATH_BTCOEX_DEF_BT_PERIOD * 1000;
1501 btcoex->btcoex_no_stomp = (100 - ATH_BTCOEX_DEF_DUTY_CYCLE) *
1502 btcoex->btcoex_period / 100;
1504 setup_timer(&btcoex->period_timer, ath_btcoex_period_timer,
1505 (unsigned long) sc);
1507 spin_lock_init(&btcoex->btcoex_lock);
1509 btcoex->no_stomp_timer = ath_gen_timer_alloc(sc->sc_ah,
1510 ath_btcoex_no_stomp_timer,
1511 ath_btcoex_no_stomp_timer,
1512 (void *) sc, AR_FIRST_NDP_TIMER);
1514 if (!btcoex->no_stomp_timer)
1521 * Read and write, they both share the same lock. We do this to serialize
1522 * reads and writes on Atheros 802.11n PCI devices only. This is required
1523 * as the FIFO on these devices can only accept sanely 2 requests. After
1524 * that the device goes bananas. Serializing the reads/writes prevents this
1528 static void ath9k_iowrite32(void *hw_priv, u32 val, u32 reg_offset)
1530 struct ath_hw *ah = (struct ath_hw *) hw_priv;
1532 if (ah->config.serialize_regmode == SER_REG_MODE_ON) {
1533 unsigned long flags;
1534 spin_lock_irqsave(&ah->ah_sc->sc_serial_rw, flags);
1535 iowrite32(val, ah->ah_sc->mem + reg_offset);
1536 spin_unlock_irqrestore(&ah->ah_sc->sc_serial_rw, flags);
1538 iowrite32(val, ah->ah_sc->mem + reg_offset);
1541 static unsigned int ath9k_ioread32(void *hw_priv, u32 reg_offset)
1543 struct ath_hw *ah = (struct ath_hw *) hw_priv;
1546 if (ah->config.serialize_regmode == SER_REG_MODE_ON) {
1547 unsigned long flags;
1548 spin_lock_irqsave(&ah->ah_sc->sc_serial_rw, flags);
1549 val = ioread32(ah->ah_sc->mem + reg_offset);
1550 spin_unlock_irqrestore(&ah->ah_sc->sc_serial_rw, flags);
1552 val = ioread32(ah->ah_sc->mem + reg_offset);
1556 static struct ath_ops ath9k_common_ops = {
1557 .read = ath9k_ioread32,
1558 .write = ath9k_iowrite32,
1562 * Initialize and fill ath_softc, ath_sofct is the
1563 * "Software Carrier" struct. Historically it has existed
1564 * to allow the separation between hardware specific
1565 * variables (now in ath_hw) and driver specific variables.
1567 static int ath_init_softc(u16 devid, struct ath_softc *sc, u16 subsysid)
1569 struct ath_hw *ah = NULL;
1570 struct ath_common *common;
1575 /* XXX: hardware will not be ready until ath_open() being called */
1576 sc->sc_flags |= SC_OP_INVALID;
1578 spin_lock_init(&sc->wiphy_lock);
1579 spin_lock_init(&sc->sc_resetlock);
1580 spin_lock_init(&sc->sc_serial_rw);
1581 spin_lock_init(&sc->ani_lock);
1582 spin_lock_init(&sc->sc_pm_lock);
1583 mutex_init(&sc->mutex);
1584 tasklet_init(&sc->intr_tq, ath9k_tasklet, (unsigned long)sc);
1585 tasklet_init(&sc->bcon_tasklet, ath_beacon_tasklet,
1588 ah = kzalloc(sizeof(struct ath_hw), GFP_KERNEL);
1595 ah->hw_version.devid = devid;
1596 ah->hw_version.subsysid = subsysid;
1599 common = ath9k_hw_common(ah);
1600 common->ops = &ath9k_common_ops;
1602 common->hw = sc->hw;
1605 * Cache line size is used to size and align various
1606 * structures used to communicate with the hardware.
1608 ath_read_cachesize(sc, &csz);
1609 /* XXX assert csz is non-zero */
1610 common->cachelsz = csz << 2; /* convert to bytes */
1612 if (ath9k_init_debug(ah) < 0)
1613 dev_err(sc->dev, "Unable to create debugfs files\n");
1615 r = ath9k_hw_init(ah);
1617 DPRINTF(ah, ATH_DBG_FATAL,
1618 "Unable to initialize hardware; "
1619 "initialization status: %d\n", r);
1623 /* Get the hardware key cache size. */
1624 sc->keymax = ah->caps.keycache_size;
1625 if (sc->keymax > ATH_KEYMAX) {
1626 DPRINTF(ah, ATH_DBG_ANY,
1627 "Warning, using only %u entries in %u key cache\n",
1628 ATH_KEYMAX, sc->keymax);
1629 sc->keymax = ATH_KEYMAX;
1633 * Reset the key cache since some parts do not
1634 * reset the contents on initial power up.
1636 for (i = 0; i < sc->keymax; i++)
1637 ath9k_hw_keyreset(ah, (u16) i);
1639 /* default to MONITOR mode */
1640 sc->sc_ah->opmode = NL80211_IFTYPE_MONITOR;
1642 /* Setup rate tables */
1644 ath_rate_attach(sc);
1645 ath_setup_rates(sc, IEEE80211_BAND_2GHZ);
1646 ath_setup_rates(sc, IEEE80211_BAND_5GHZ);
1649 * Allocate hardware transmit queues: one queue for
1650 * beacon frames and one data queue for each QoS
1651 * priority. Note that the hal handles reseting
1652 * these queues at the needed time.
1654 sc->beacon.beaconq = ath_beaconq_setup(ah);
1655 if (sc->beacon.beaconq == -1) {
1656 DPRINTF(ah, ATH_DBG_FATAL,
1657 "Unable to setup a beacon xmit queue\n");
1661 sc->beacon.cabq = ath_txq_setup(sc, ATH9K_TX_QUEUE_CAB, 0);
1662 if (sc->beacon.cabq == NULL) {
1663 DPRINTF(ah, ATH_DBG_FATAL,
1664 "Unable to setup CAB xmit queue\n");
1669 sc->config.cabqReadytime = ATH_CABQ_READY_TIME;
1670 ath_cabq_update(sc);
1672 for (i = 0; i < ARRAY_SIZE(sc->tx.hwq_map); i++)
1673 sc->tx.hwq_map[i] = -1;
1675 /* Setup data queues */
1676 /* NB: ensure BK queue is the lowest priority h/w queue */
1677 if (!ath_tx_setup(sc, ATH9K_WME_AC_BK)) {
1678 DPRINTF(ah, ATH_DBG_FATAL,
1679 "Unable to setup xmit queue for BK traffic\n");
1684 if (!ath_tx_setup(sc, ATH9K_WME_AC_BE)) {
1685 DPRINTF(ah, ATH_DBG_FATAL,
1686 "Unable to setup xmit queue for BE traffic\n");
1690 if (!ath_tx_setup(sc, ATH9K_WME_AC_VI)) {
1691 DPRINTF(ah, ATH_DBG_FATAL,
1692 "Unable to setup xmit queue for VI traffic\n");
1696 if (!ath_tx_setup(sc, ATH9K_WME_AC_VO)) {
1697 DPRINTF(ah, ATH_DBG_FATAL,
1698 "Unable to setup xmit queue for VO traffic\n");
1703 /* Initializes the noise floor to a reasonable default value.
1704 * Later on this will be updated during ANI processing. */
1706 sc->ani.noise_floor = ATH_DEFAULT_NOISE_FLOOR;
1707 setup_timer(&sc->ani.timer, ath_ani_calibrate, (unsigned long)sc);
1709 if (ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
1710 ATH9K_CIPHER_TKIP, NULL)) {
1712 * Whether we should enable h/w TKIP MIC.
1713 * XXX: if we don't support WME TKIP MIC, then we wouldn't
1714 * report WMM capable, so it's always safe to turn on
1715 * TKIP MIC in this case.
1717 ath9k_hw_setcapability(sc->sc_ah, ATH9K_CAP_TKIP_MIC,
1722 * Check whether the separate key cache entries
1723 * are required to handle both tx+rx MIC keys.
1724 * With split mic keys the number of stations is limited
1725 * to 27 otherwise 59.
1727 if (ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
1728 ATH9K_CIPHER_TKIP, NULL)
1729 && ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
1730 ATH9K_CIPHER_MIC, NULL)
1731 && ath9k_hw_getcapability(ah, ATH9K_CAP_TKIP_SPLIT,
1735 /* turn on mcast key search if possible */
1736 if (!ath9k_hw_getcapability(ah, ATH9K_CAP_MCAST_KEYSRCH, 0, NULL))
1737 (void)ath9k_hw_setcapability(ah, ATH9K_CAP_MCAST_KEYSRCH, 1,
1740 sc->config.txpowlimit = ATH_TXPOWER_MAX;
1742 /* 11n Capabilities */
1743 if (ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
1744 sc->sc_flags |= SC_OP_TXAGGR;
1745 sc->sc_flags |= SC_OP_RXAGGR;
1748 sc->tx_chainmask = ah->caps.tx_chainmask;
1749 sc->rx_chainmask = ah->caps.rx_chainmask;
1751 ath9k_hw_setcapability(ah, ATH9K_CAP_DIVERSITY, 1, true, NULL);
1752 sc->rx.defant = ath9k_hw_getdefantenna(ah);
1754 if (ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
1755 memcpy(common->bssidmask, ath_bcast_mac, ETH_ALEN);
1757 sc->beacon.slottime = ATH9K_SLOT_TIME_9; /* default to short slot time */
1759 /* initialize beacon slots */
1760 for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++) {
1761 sc->beacon.bslot[i] = NULL;
1762 sc->beacon.bslot_aphy[i] = NULL;
1765 /* setup channels and rates */
1767 sc->sbands[IEEE80211_BAND_2GHZ].channels = ath9k_2ghz_chantable;
1768 sc->sbands[IEEE80211_BAND_2GHZ].bitrates =
1769 sc->rates[IEEE80211_BAND_2GHZ];
1770 sc->sbands[IEEE80211_BAND_2GHZ].band = IEEE80211_BAND_2GHZ;
1771 sc->sbands[IEEE80211_BAND_2GHZ].n_channels =
1772 ARRAY_SIZE(ath9k_2ghz_chantable);
1774 if (test_bit(ATH9K_MODE_11A, sc->sc_ah->caps.wireless_modes)) {
1775 sc->sbands[IEEE80211_BAND_5GHZ].channels = ath9k_5ghz_chantable;
1776 sc->sbands[IEEE80211_BAND_5GHZ].bitrates =
1777 sc->rates[IEEE80211_BAND_5GHZ];
1778 sc->sbands[IEEE80211_BAND_5GHZ].band = IEEE80211_BAND_5GHZ;
1779 sc->sbands[IEEE80211_BAND_5GHZ].n_channels =
1780 ARRAY_SIZE(ath9k_5ghz_chantable);
1783 switch (ah->btcoex_hw.scheme) {
1784 case ATH_BTCOEX_CFG_NONE:
1786 case ATH_BTCOEX_CFG_2WIRE:
1787 ath9k_hw_btcoex_init_2wire(ah);
1789 case ATH_BTCOEX_CFG_3WIRE:
1790 ath9k_hw_btcoex_init_3wire(ah);
1791 r = ath_init_btcoex_timer(sc);
1794 qnum = ath_tx_get_qnum(sc, ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_BE);
1795 ath9k_hw_init_btcoex_hw(ah, qnum);
1796 sc->btcoex.bt_stomp_type = ATH_BTCOEX_STOMP_LOW;
1805 /* cleanup tx queues */
1806 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1807 if (ATH_TXQ_SETUP(sc, i))
1808 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
1810 ath9k_hw_detach(ah);
1812 ath9k_exit_debug(sc->sc_ah);
1818 void ath_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
1820 hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
1821 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
1822 IEEE80211_HW_SIGNAL_DBM |
1823 IEEE80211_HW_AMPDU_AGGREGATION |
1824 IEEE80211_HW_SUPPORTS_PS |
1825 IEEE80211_HW_PS_NULLFUNC_STACK |
1826 IEEE80211_HW_SPECTRUM_MGMT;
1828 if (AR_SREV_9160_10_OR_LATER(sc->sc_ah) || modparam_nohwcrypt)
1829 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
1831 hw->wiphy->interface_modes =
1832 BIT(NL80211_IFTYPE_AP) |
1833 BIT(NL80211_IFTYPE_STATION) |
1834 BIT(NL80211_IFTYPE_ADHOC) |
1835 BIT(NL80211_IFTYPE_MESH_POINT);
1839 hw->channel_change_time = 5000;
1840 hw->max_listen_interval = 10;
1841 /* Hardware supports 10 but we use 4 */
1842 hw->max_rate_tries = 4;
1843 hw->sta_data_size = sizeof(struct ath_node);
1844 hw->vif_data_size = sizeof(struct ath_vif);
1846 hw->rate_control_algorithm = "ath9k_rate_control";
1848 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
1849 &sc->sbands[IEEE80211_BAND_2GHZ];
1850 if (test_bit(ATH9K_MODE_11A, sc->sc_ah->caps.wireless_modes))
1851 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
1852 &sc->sbands[IEEE80211_BAND_5GHZ];
1855 /* Device driver core initialization */
1856 int ath_init_device(u16 devid, struct ath_softc *sc, u16 subsysid)
1858 struct ieee80211_hw *hw = sc->hw;
1859 struct ath_common *common;
1862 struct ath_regulatory *reg;
1864 dev_dbg(sc->dev, "Attach ATH hw\n");
1866 error = ath_init_softc(devid, sc, subsysid);
1871 common = ath9k_hw_common(ah);
1873 /* get mac address from hardware and set in mac80211 */
1875 SET_IEEE80211_PERM_ADDR(hw, common->macaddr);
1877 ath_set_hw_capab(sc, hw);
1879 error = ath_regd_init(&common->regulatory, sc->hw->wiphy,
1880 ath9k_reg_notifier);
1884 reg = &common->regulatory;
1886 if (ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
1887 setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_2GHZ].ht_cap);
1888 if (test_bit(ATH9K_MODE_11A, ah->caps.wireless_modes))
1889 setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_5GHZ].ht_cap);
1892 /* initialize tx/rx engine */
1893 error = ath_tx_init(sc, ATH_TXBUF);
1897 error = ath_rx_init(sc, ATH_RXBUF);
1901 INIT_WORK(&sc->chan_work, ath9k_wiphy_chan_work);
1902 INIT_DELAYED_WORK(&sc->wiphy_work, ath9k_wiphy_work);
1903 sc->wiphy_scheduler_int = msecs_to_jiffies(500);
1905 error = ieee80211_register_hw(hw);
1907 if (!ath_is_world_regd(reg)) {
1908 error = regulatory_hint(hw->wiphy, reg->alpha2);
1913 /* Initialize LED control */
1916 ath_start_rfkill_poll(sc);
1921 /* cleanup tx queues */
1922 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1923 if (ATH_TXQ_SETUP(sc, i))
1924 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
1926 ath9k_hw_detach(ah);
1927 ath9k_exit_debug(ah);
1933 int ath_reset(struct ath_softc *sc, bool retry_tx)
1935 struct ath_hw *ah = sc->sc_ah;
1936 struct ieee80211_hw *hw = sc->hw;
1939 ath9k_hw_set_interrupts(ah, 0);
1940 ath_drain_all_txq(sc, retry_tx);
1944 spin_lock_bh(&sc->sc_resetlock);
1945 r = ath9k_hw_reset(ah, sc->sc_ah->curchan, false);
1947 DPRINTF(ah, ATH_DBG_FATAL,
1948 "Unable to reset hardware; reset status %d\n", r);
1949 spin_unlock_bh(&sc->sc_resetlock);
1951 if (ath_startrecv(sc) != 0)
1952 DPRINTF(ah, ATH_DBG_FATAL, "Unable to start recv logic\n");
1955 * We may be doing a reset in response to a request
1956 * that changes the channel so update any state that
1957 * might change as a result.
1959 ath_cache_conf_rate(sc, &hw->conf);
1961 ath_update_txpow(sc);
1963 if (sc->sc_flags & SC_OP_BEACONS)
1964 ath_beacon_config(sc, NULL); /* restart beacons */
1966 ath9k_hw_set_interrupts(ah, sc->imask);
1970 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
1971 if (ATH_TXQ_SETUP(sc, i)) {
1972 spin_lock_bh(&sc->tx.txq[i].axq_lock);
1973 ath_txq_schedule(sc, &sc->tx.txq[i]);
1974 spin_unlock_bh(&sc->tx.txq[i].axq_lock);
1983 * This function will allocate both the DMA descriptor structure, and the
1984 * buffers it contains. These are used to contain the descriptors used
1987 int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
1988 struct list_head *head, const char *name,
1989 int nbuf, int ndesc)
1991 #define DS2PHYS(_dd, _ds) \
1992 ((_dd)->dd_desc_paddr + ((caddr_t)(_ds) - (caddr_t)(_dd)->dd_desc))
1993 #define ATH_DESC_4KB_BOUND_CHECK(_daddr) ((((_daddr) & 0xFFF) > 0xF7F) ? 1 : 0)
1994 #define ATH_DESC_4KB_BOUND_NUM_SKIPPED(_len) ((_len) / 4096)
1996 struct ath_desc *ds;
1998 int i, bsize, error;
2000 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "%s DMA: %u buffers %u desc/buf\n",
2003 INIT_LIST_HEAD(head);
2004 /* ath_desc must be a multiple of DWORDs */
2005 if ((sizeof(struct ath_desc) % 4) != 0) {
2006 DPRINTF(sc->sc_ah, ATH_DBG_FATAL, "ath_desc not DWORD aligned\n");
2007 ASSERT((sizeof(struct ath_desc) % 4) == 0);
2012 dd->dd_desc_len = sizeof(struct ath_desc) * nbuf * ndesc;
2015 * Need additional DMA memory because we can't use
2016 * descriptors that cross the 4K page boundary. Assume
2017 * one skipped descriptor per 4K page.
2019 if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_4KB_SPLITTRANS)) {
2021 ATH_DESC_4KB_BOUND_NUM_SKIPPED(dd->dd_desc_len);
2024 while (ndesc_skipped) {
2025 dma_len = ndesc_skipped * sizeof(struct ath_desc);
2026 dd->dd_desc_len += dma_len;
2028 ndesc_skipped = ATH_DESC_4KB_BOUND_NUM_SKIPPED(dma_len);
2032 /* allocate descriptors */
2033 dd->dd_desc = dma_alloc_coherent(sc->dev, dd->dd_desc_len,
2034 &dd->dd_desc_paddr, GFP_KERNEL);
2035 if (dd->dd_desc == NULL) {
2040 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "%s DMA map: %p (%u) -> %llx (%u)\n",
2041 name, ds, (u32) dd->dd_desc_len,
2042 ito64(dd->dd_desc_paddr), /*XXX*/(u32) dd->dd_desc_len);
2044 /* allocate buffers */
2045 bsize = sizeof(struct ath_buf) * nbuf;
2046 bf = kzalloc(bsize, GFP_KERNEL);
2053 for (i = 0; i < nbuf; i++, bf++, ds += ndesc) {
2055 bf->bf_daddr = DS2PHYS(dd, ds);
2057 if (!(sc->sc_ah->caps.hw_caps &
2058 ATH9K_HW_CAP_4KB_SPLITTRANS)) {
2060 * Skip descriptor addresses which can cause 4KB
2061 * boundary crossing (addr + length) with a 32 dword
2064 while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
2065 ASSERT((caddr_t) bf->bf_desc <
2066 ((caddr_t) dd->dd_desc +
2071 bf->bf_daddr = DS2PHYS(dd, ds);
2074 list_add_tail(&bf->list, head);
2078 dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc,
2081 memset(dd, 0, sizeof(*dd));
2083 #undef ATH_DESC_4KB_BOUND_CHECK
2084 #undef ATH_DESC_4KB_BOUND_NUM_SKIPPED
2088 void ath_descdma_cleanup(struct ath_softc *sc,
2089 struct ath_descdma *dd,
2090 struct list_head *head)
2092 dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc,
2095 INIT_LIST_HEAD(head);
2096 kfree(dd->dd_bufptr);
2097 memset(dd, 0, sizeof(*dd));
2100 int ath_get_hal_qnum(u16 queue, struct ath_softc *sc)
2106 qnum = sc->tx.hwq_map[ATH9K_WME_AC_VO];
2109 qnum = sc->tx.hwq_map[ATH9K_WME_AC_VI];
2112 qnum = sc->tx.hwq_map[ATH9K_WME_AC_BE];
2115 qnum = sc->tx.hwq_map[ATH9K_WME_AC_BK];
2118 qnum = sc->tx.hwq_map[ATH9K_WME_AC_BE];
2125 int ath_get_mac80211_qnum(u32 queue, struct ath_softc *sc)
2130 case ATH9K_WME_AC_VO:
2133 case ATH9K_WME_AC_VI:
2136 case ATH9K_WME_AC_BE:
2139 case ATH9K_WME_AC_BK:
2150 /* XXX: Remove me once we don't depend on ath9k_channel for all
2151 * this redundant data */
2152 void ath9k_update_ichannel(struct ath_softc *sc, struct ieee80211_hw *hw,
2153 struct ath9k_channel *ichan)
2155 struct ieee80211_channel *chan = hw->conf.channel;
2156 struct ieee80211_conf *conf = &hw->conf;
2158 ichan->channel = chan->center_freq;
2161 if (chan->band == IEEE80211_BAND_2GHZ) {
2162 ichan->chanmode = CHANNEL_G;
2163 ichan->channelFlags = CHANNEL_2GHZ | CHANNEL_OFDM | CHANNEL_G;
2165 ichan->chanmode = CHANNEL_A;
2166 ichan->channelFlags = CHANNEL_5GHZ | CHANNEL_OFDM;
2169 sc->tx_chan_width = ATH9K_HT_MACMODE_20;
2171 if (conf_is_ht(conf)) {
2172 if (conf_is_ht40(conf))
2173 sc->tx_chan_width = ATH9K_HT_MACMODE_2040;
2175 ichan->chanmode = ath_get_extchanmode(sc, chan,
2176 conf->channel_type);
2180 /**********************/
2181 /* mac80211 callbacks */
2182 /**********************/
2185 * (Re)start btcoex timers
2187 static void ath9k_btcoex_timer_resume(struct ath_softc *sc)
2189 struct ath_btcoex *btcoex = &sc->btcoex;
2190 struct ath_hw *ah = sc->sc_ah;
2192 DPRINTF(ah, ATH_DBG_BTCOEX, "Starting btcoex timers");
2194 /* make sure duty cycle timer is also stopped when resuming */
2195 if (btcoex->hw_timer_enabled)
2196 ath9k_gen_timer_stop(sc->sc_ah, btcoex->no_stomp_timer);
2198 btcoex->bt_priority_cnt = 0;
2199 btcoex->bt_priority_time = jiffies;
2200 sc->sc_flags &= ~SC_OP_BT_PRIORITY_DETECTED;
2202 mod_timer(&btcoex->period_timer, jiffies);
2205 static int ath9k_start(struct ieee80211_hw *hw)
2207 struct ath_wiphy *aphy = hw->priv;
2208 struct ath_softc *sc = aphy->sc;
2209 struct ath_hw *ah = sc->sc_ah;
2210 struct ieee80211_channel *curchan = hw->conf.channel;
2211 struct ath9k_channel *init_channel;
2214 DPRINTF(ah, ATH_DBG_CONFIG, "Starting driver with "
2215 "initial channel: %d MHz\n", curchan->center_freq);
2217 mutex_lock(&sc->mutex);
2219 if (ath9k_wiphy_started(sc)) {
2220 if (sc->chan_idx == curchan->hw_value) {
2222 * Already on the operational channel, the new wiphy
2223 * can be marked active.
2225 aphy->state = ATH_WIPHY_ACTIVE;
2226 ieee80211_wake_queues(hw);
2229 * Another wiphy is on another channel, start the new
2230 * wiphy in paused state.
2232 aphy->state = ATH_WIPHY_PAUSED;
2233 ieee80211_stop_queues(hw);
2235 mutex_unlock(&sc->mutex);
2238 aphy->state = ATH_WIPHY_ACTIVE;
2240 /* setup initial channel */
2242 sc->chan_idx = curchan->hw_value;
2244 init_channel = ath_get_curchannel(sc, hw);
2246 /* Reset SERDES registers */
2247 ath9k_hw_configpcipowersave(ah, 0, 0);
2250 * The basic interface to setting the hardware in a good
2251 * state is ``reset''. On return the hardware is known to
2252 * be powered up and with interrupts disabled. This must
2253 * be followed by initialization of the appropriate bits
2254 * and then setup of the interrupt mask.
2256 spin_lock_bh(&sc->sc_resetlock);
2257 r = ath9k_hw_reset(ah, init_channel, false);
2259 DPRINTF(ah, ATH_DBG_FATAL,
2260 "Unable to reset hardware; reset status %d "
2261 "(freq %u MHz)\n", r,
2262 curchan->center_freq);
2263 spin_unlock_bh(&sc->sc_resetlock);
2266 spin_unlock_bh(&sc->sc_resetlock);
2269 * This is needed only to setup initial state
2270 * but it's best done after a reset.
2272 ath_update_txpow(sc);
2275 * Setup the hardware after reset:
2276 * The receive engine is set going.
2277 * Frame transmit is handled entirely
2278 * in the frame output path; there's nothing to do
2279 * here except setup the interrupt mask.
2281 if (ath_startrecv(sc) != 0) {
2282 DPRINTF(ah, ATH_DBG_FATAL, "Unable to start recv logic\n");
2287 /* Setup our intr mask. */
2288 sc->imask = ATH9K_INT_RX | ATH9K_INT_TX
2289 | ATH9K_INT_RXEOL | ATH9K_INT_RXORN
2290 | ATH9K_INT_FATAL | ATH9K_INT_GLOBAL;
2292 if (ah->caps.hw_caps & ATH9K_HW_CAP_GTT)
2293 sc->imask |= ATH9K_INT_GTT;
2295 if (ah->caps.hw_caps & ATH9K_HW_CAP_HT)
2296 sc->imask |= ATH9K_INT_CST;
2298 ath_cache_conf_rate(sc, &hw->conf);
2300 sc->sc_flags &= ~SC_OP_INVALID;
2302 /* Disable BMISS interrupt when we're not associated */
2303 sc->imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
2304 ath9k_hw_set_interrupts(ah, sc->imask);
2306 ieee80211_wake_queues(hw);
2308 ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
2310 if ((ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE) &&
2311 !ah->btcoex_hw.enabled) {
2312 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
2313 AR_STOMP_LOW_WLAN_WGHT);
2314 ath9k_hw_btcoex_enable(ah);
2316 if (sc->bus_ops->bt_coex_prep)
2317 sc->bus_ops->bt_coex_prep(sc);
2318 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
2319 ath9k_btcoex_timer_resume(sc);
2323 mutex_unlock(&sc->mutex);
2328 static int ath9k_tx(struct ieee80211_hw *hw,
2329 struct sk_buff *skb)
2331 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2332 struct ath_wiphy *aphy = hw->priv;
2333 struct ath_softc *sc = aphy->sc;
2334 struct ath_tx_control txctl;
2335 int hdrlen, padsize;
2337 if (aphy->state != ATH_WIPHY_ACTIVE && aphy->state != ATH_WIPHY_SCAN) {
2338 printk(KERN_DEBUG "ath9k: %s: TX in unexpected wiphy state "
2339 "%d\n", wiphy_name(hw->wiphy), aphy->state);
2343 if (sc->ps_enabled) {
2344 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2346 * mac80211 does not set PM field for normal data frames, so we
2347 * need to update that based on the current PS mode.
2349 if (ieee80211_is_data(hdr->frame_control) &&
2350 !ieee80211_is_nullfunc(hdr->frame_control) &&
2351 !ieee80211_has_pm(hdr->frame_control)) {
2352 DPRINTF(sc->sc_ah, ATH_DBG_PS, "Add PM=1 for a TX frame "
2353 "while in PS mode\n");
2354 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
2358 if (unlikely(sc->sc_ah->power_mode != ATH9K_PM_AWAKE)) {
2360 * We are using PS-Poll and mac80211 can request TX while in
2361 * power save mode. Need to wake up hardware for the TX to be
2362 * completed and if needed, also for RX of buffered frames.
2364 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2365 ath9k_ps_wakeup(sc);
2366 ath9k_hw_setrxabort(sc->sc_ah, 0);
2367 if (ieee80211_is_pspoll(hdr->frame_control)) {
2368 DPRINTF(sc->sc_ah, ATH_DBG_PS, "Sending PS-Poll to pick a "
2369 "buffered frame\n");
2370 sc->sc_flags |= SC_OP_WAIT_FOR_PSPOLL_DATA;
2372 DPRINTF(sc->sc_ah, ATH_DBG_PS, "Wake up to complete TX\n");
2373 sc->sc_flags |= SC_OP_WAIT_FOR_TX_ACK;
2376 * The actual restore operation will happen only after
2377 * the sc_flags bit is cleared. We are just dropping
2378 * the ps_usecount here.
2380 ath9k_ps_restore(sc);
2383 memset(&txctl, 0, sizeof(struct ath_tx_control));
2386 * As a temporary workaround, assign seq# here; this will likely need
2387 * to be cleaned up to work better with Beacon transmission and virtual
2390 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
2391 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2392 if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
2393 sc->tx.seq_no += 0x10;
2394 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
2395 hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no);
2398 /* Add the padding after the header if this is not already done */
2399 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
2401 padsize = hdrlen % 4;
2402 if (skb_headroom(skb) < padsize)
2404 skb_push(skb, padsize);
2405 memmove(skb->data, skb->data + padsize, hdrlen);
2408 /* Check if a tx queue is available */
2410 txctl.txq = ath_test_get_txq(sc, skb);
2414 DPRINTF(sc->sc_ah, ATH_DBG_XMIT, "transmitting packet, skb: %p\n", skb);
2416 if (ath_tx_start(hw, skb, &txctl) != 0) {
2417 DPRINTF(sc->sc_ah, ATH_DBG_XMIT, "TX failed\n");
2423 dev_kfree_skb_any(skb);
2428 * Pause btcoex timer and bt duty cycle timer
2430 static void ath9k_btcoex_timer_pause(struct ath_softc *sc)
2432 struct ath_btcoex *btcoex = &sc->btcoex;
2433 struct ath_hw *ah = sc->sc_ah;
2435 del_timer_sync(&btcoex->period_timer);
2437 if (btcoex->hw_timer_enabled)
2438 ath9k_gen_timer_stop(ah, btcoex->no_stomp_timer);
2440 btcoex->hw_timer_enabled = false;
2443 static void ath9k_stop(struct ieee80211_hw *hw)
2445 struct ath_wiphy *aphy = hw->priv;
2446 struct ath_softc *sc = aphy->sc;
2447 struct ath_hw *ah = sc->sc_ah;
2449 mutex_lock(&sc->mutex);
2451 aphy->state = ATH_WIPHY_INACTIVE;
2453 cancel_delayed_work_sync(&sc->ath_led_blink_work);
2454 cancel_delayed_work_sync(&sc->tx_complete_work);
2456 if (!sc->num_sec_wiphy) {
2457 cancel_delayed_work_sync(&sc->wiphy_work);
2458 cancel_work_sync(&sc->chan_work);
2461 if (sc->sc_flags & SC_OP_INVALID) {
2462 DPRINTF(ah, ATH_DBG_ANY, "Device not present\n");
2463 mutex_unlock(&sc->mutex);
2467 if (ath9k_wiphy_started(sc)) {
2468 mutex_unlock(&sc->mutex);
2469 return; /* another wiphy still in use */
2472 if (ah->btcoex_hw.enabled) {
2473 ath9k_hw_btcoex_disable(ah);
2474 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
2475 ath9k_btcoex_timer_pause(sc);
2478 /* make sure h/w will not generate any interrupt
2479 * before setting the invalid flag. */
2480 ath9k_hw_set_interrupts(ah, 0);
2482 if (!(sc->sc_flags & SC_OP_INVALID)) {
2483 ath_drain_all_txq(sc, false);
2485 ath9k_hw_phy_disable(ah);
2487 sc->rx.rxlink = NULL;
2489 /* disable HAL and put h/w to sleep */
2490 ath9k_hw_disable(ah);
2491 ath9k_hw_configpcipowersave(ah, 1, 1);
2492 ath9k_setpower(sc, ATH9K_PM_FULL_SLEEP);
2494 sc->sc_flags |= SC_OP_INVALID;
2496 mutex_unlock(&sc->mutex);
2498 DPRINTF(ah, ATH_DBG_CONFIG, "Driver halt\n");
2501 static int ath9k_add_interface(struct ieee80211_hw *hw,
2502 struct ieee80211_if_init_conf *conf)
2504 struct ath_wiphy *aphy = hw->priv;
2505 struct ath_softc *sc = aphy->sc;
2506 struct ath_vif *avp = (void *)conf->vif->drv_priv;
2507 enum nl80211_iftype ic_opmode = NL80211_IFTYPE_UNSPECIFIED;
2510 mutex_lock(&sc->mutex);
2512 if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK) &&
2518 switch (conf->type) {
2519 case NL80211_IFTYPE_STATION:
2520 ic_opmode = NL80211_IFTYPE_STATION;
2522 case NL80211_IFTYPE_ADHOC:
2523 case NL80211_IFTYPE_AP:
2524 case NL80211_IFTYPE_MESH_POINT:
2525 if (sc->nbcnvifs >= ATH_BCBUF) {
2529 ic_opmode = conf->type;
2532 DPRINTF(sc->sc_ah, ATH_DBG_FATAL,
2533 "Interface type %d not yet supported\n", conf->type);
2538 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "Attach a VIF of type: %d\n", ic_opmode);
2540 /* Set the VIF opmode */
2541 avp->av_opmode = ic_opmode;
2546 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
2547 ath9k_set_bssid_mask(hw);
2550 goto out; /* skip global settings for secondary vif */
2552 if (ic_opmode == NL80211_IFTYPE_AP) {
2553 ath9k_hw_set_tsfadjust(sc->sc_ah, 1);
2554 sc->sc_flags |= SC_OP_TSF_RESET;
2557 /* Set the device opmode */
2558 sc->sc_ah->opmode = ic_opmode;
2561 * Enable MIB interrupts when there are hardware phy counters.
2562 * Note we only do this (at the moment) for station mode.
2564 if ((conf->type == NL80211_IFTYPE_STATION) ||
2565 (conf->type == NL80211_IFTYPE_ADHOC) ||
2566 (conf->type == NL80211_IFTYPE_MESH_POINT)) {
2567 sc->imask |= ATH9K_INT_MIB;
2568 sc->imask |= ATH9K_INT_TSFOOR;
2571 ath9k_hw_set_interrupts(sc->sc_ah, sc->imask);
2573 if (conf->type == NL80211_IFTYPE_AP ||
2574 conf->type == NL80211_IFTYPE_ADHOC ||
2575 conf->type == NL80211_IFTYPE_MONITOR)
2579 mutex_unlock(&sc->mutex);
2583 static void ath9k_remove_interface(struct ieee80211_hw *hw,
2584 struct ieee80211_if_init_conf *conf)
2586 struct ath_wiphy *aphy = hw->priv;
2587 struct ath_softc *sc = aphy->sc;
2588 struct ath_vif *avp = (void *)conf->vif->drv_priv;
2591 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "Detach Interface\n");
2593 mutex_lock(&sc->mutex);
2596 del_timer_sync(&sc->ani.timer);
2598 /* Reclaim beacon resources */
2599 if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) ||
2600 (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC) ||
2601 (sc->sc_ah->opmode == NL80211_IFTYPE_MESH_POINT)) {
2602 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
2603 ath_beacon_return(sc, avp);
2606 sc->sc_flags &= ~SC_OP_BEACONS;
2608 for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++) {
2609 if (sc->beacon.bslot[i] == conf->vif) {
2610 printk(KERN_DEBUG "%s: vif had allocated beacon "
2611 "slot\n", __func__);
2612 sc->beacon.bslot[i] = NULL;
2613 sc->beacon.bslot_aphy[i] = NULL;
2619 mutex_unlock(&sc->mutex);
2622 static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
2624 struct ath_wiphy *aphy = hw->priv;
2625 struct ath_softc *sc = aphy->sc;
2626 struct ieee80211_conf *conf = &hw->conf;
2627 struct ath_hw *ah = sc->sc_ah;
2628 bool all_wiphys_idle = false, disable_radio = false;
2630 mutex_lock(&sc->mutex);
2632 /* Leave this as the first check */
2633 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
2635 spin_lock_bh(&sc->wiphy_lock);
2636 all_wiphys_idle = ath9k_all_wiphys_idle(sc);
2637 spin_unlock_bh(&sc->wiphy_lock);
2639 if (conf->flags & IEEE80211_CONF_IDLE){
2640 if (all_wiphys_idle)
2641 disable_radio = true;
2643 else if (all_wiphys_idle) {
2644 ath_radio_enable(sc);
2645 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG,
2646 "not-idle: enabling radio\n");
2650 if (changed & IEEE80211_CONF_CHANGE_PS) {
2651 if (conf->flags & IEEE80211_CONF_PS) {
2652 if (!(ah->caps.hw_caps &
2653 ATH9K_HW_CAP_AUTOSLEEP)) {
2654 if ((sc->imask & ATH9K_INT_TIM_TIMER) == 0) {
2655 sc->imask |= ATH9K_INT_TIM_TIMER;
2656 ath9k_hw_set_interrupts(sc->sc_ah,
2659 ath9k_hw_setrxabort(sc->sc_ah, 1);
2661 sc->ps_enabled = true;
2663 sc->ps_enabled = false;
2664 ath9k_setpower(sc, ATH9K_PM_AWAKE);
2665 if (!(ah->caps.hw_caps &
2666 ATH9K_HW_CAP_AUTOSLEEP)) {
2667 ath9k_hw_setrxabort(sc->sc_ah, 0);
2668 sc->sc_flags &= ~(SC_OP_WAIT_FOR_BEACON |
2669 SC_OP_WAIT_FOR_CAB |
2670 SC_OP_WAIT_FOR_PSPOLL_DATA |
2671 SC_OP_WAIT_FOR_TX_ACK);
2672 if (sc->imask & ATH9K_INT_TIM_TIMER) {
2673 sc->imask &= ~ATH9K_INT_TIM_TIMER;
2674 ath9k_hw_set_interrupts(sc->sc_ah,
2681 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
2682 struct ieee80211_channel *curchan = hw->conf.channel;
2683 int pos = curchan->hw_value;
2685 aphy->chan_idx = pos;
2686 aphy->chan_is_ht = conf_is_ht(conf);
2688 if (aphy->state == ATH_WIPHY_SCAN ||
2689 aphy->state == ATH_WIPHY_ACTIVE)
2690 ath9k_wiphy_pause_all_forced(sc, aphy);
2693 * Do not change operational channel based on a paused
2696 goto skip_chan_change;
2699 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
2700 curchan->center_freq);
2702 /* XXX: remove me eventualy */
2703 ath9k_update_ichannel(sc, hw, &sc->sc_ah->channels[pos]);
2705 ath_update_chainmask(sc, conf_is_ht(conf));
2707 if (ath_set_channel(sc, hw, &sc->sc_ah->channels[pos]) < 0) {
2708 DPRINTF(sc->sc_ah, ATH_DBG_FATAL, "Unable to set channel\n");
2709 mutex_unlock(&sc->mutex);
2715 if (changed & IEEE80211_CONF_CHANGE_POWER)
2716 sc->config.txpowlimit = 2 * conf->power_level;
2718 if (disable_radio) {
2719 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "idle: disabling radio\n");
2720 ath_radio_disable(sc);
2723 mutex_unlock(&sc->mutex);
2728 #define SUPPORTED_FILTERS \
2729 (FIF_PROMISC_IN_BSS | \
2734 FIF_BCN_PRBRESP_PROMISC | \
2737 /* FIXME: sc->sc_full_reset ? */
2738 static void ath9k_configure_filter(struct ieee80211_hw *hw,
2739 unsigned int changed_flags,
2740 unsigned int *total_flags,
2743 struct ath_wiphy *aphy = hw->priv;
2744 struct ath_softc *sc = aphy->sc;
2747 changed_flags &= SUPPORTED_FILTERS;
2748 *total_flags &= SUPPORTED_FILTERS;
2750 sc->rx.rxfilter = *total_flags;
2751 ath9k_ps_wakeup(sc);
2752 rfilt = ath_calcrxfilter(sc);
2753 ath9k_hw_setrxfilter(sc->sc_ah, rfilt);
2754 ath9k_ps_restore(sc);
2756 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "Set HW RX filter: 0x%x\n", rfilt);
2759 static void ath9k_sta_notify(struct ieee80211_hw *hw,
2760 struct ieee80211_vif *vif,
2761 enum sta_notify_cmd cmd,
2762 struct ieee80211_sta *sta)
2764 struct ath_wiphy *aphy = hw->priv;
2765 struct ath_softc *sc = aphy->sc;
2768 case STA_NOTIFY_ADD:
2769 ath_node_attach(sc, sta);
2771 case STA_NOTIFY_REMOVE:
2772 ath_node_detach(sc, sta);
2779 static int ath9k_conf_tx(struct ieee80211_hw *hw, u16 queue,
2780 const struct ieee80211_tx_queue_params *params)
2782 struct ath_wiphy *aphy = hw->priv;
2783 struct ath_softc *sc = aphy->sc;
2784 struct ath9k_tx_queue_info qi;
2787 if (queue >= WME_NUM_AC)
2790 mutex_lock(&sc->mutex);
2792 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
2794 qi.tqi_aifs = params->aifs;
2795 qi.tqi_cwmin = params->cw_min;
2796 qi.tqi_cwmax = params->cw_max;
2797 qi.tqi_burstTime = params->txop;
2798 qnum = ath_get_hal_qnum(queue, sc);
2800 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG,
2801 "Configure tx [queue/halq] [%d/%d], "
2802 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
2803 queue, qnum, params->aifs, params->cw_min,
2804 params->cw_max, params->txop);
2806 ret = ath_txq_update(sc, qnum, &qi);
2808 DPRINTF(sc->sc_ah, ATH_DBG_FATAL, "TXQ Update failed\n");
2810 mutex_unlock(&sc->mutex);
2815 static int ath9k_set_key(struct ieee80211_hw *hw,
2816 enum set_key_cmd cmd,
2817 struct ieee80211_vif *vif,
2818 struct ieee80211_sta *sta,
2819 struct ieee80211_key_conf *key)
2821 struct ath_wiphy *aphy = hw->priv;
2822 struct ath_softc *sc = aphy->sc;
2825 if (modparam_nohwcrypt)
2828 mutex_lock(&sc->mutex);
2829 ath9k_ps_wakeup(sc);
2830 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "Set HW Key\n");
2834 ret = ath_key_config(sc, vif, sta, key);
2836 key->hw_key_idx = ret;
2837 /* push IV and Michael MIC generation to stack */
2838 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
2839 if (key->alg == ALG_TKIP)
2840 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
2841 if (sc->sc_ah->sw_mgmt_crypto && key->alg == ALG_CCMP)
2842 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
2847 ath_key_delete(sc, key);
2853 ath9k_ps_restore(sc);
2854 mutex_unlock(&sc->mutex);
2859 static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
2860 struct ieee80211_vif *vif,
2861 struct ieee80211_bss_conf *bss_conf,
2864 struct ath_wiphy *aphy = hw->priv;
2865 struct ath_softc *sc = aphy->sc;
2866 struct ath_hw *ah = sc->sc_ah;
2867 struct ath_common *common = ath9k_hw_common(ah);
2868 struct ath_vif *avp = (void *)vif->drv_priv;
2872 mutex_lock(&sc->mutex);
2875 * TODO: Need to decide which hw opmode to use for
2876 * multi-interface cases
2877 * XXX: This belongs into add_interface!
2879 if (vif->type == NL80211_IFTYPE_AP &&
2880 ah->opmode != NL80211_IFTYPE_AP) {
2881 ah->opmode = NL80211_IFTYPE_STATION;
2882 ath9k_hw_setopmode(ah);
2883 memcpy(common->curbssid, common->macaddr, ETH_ALEN);
2885 ath9k_hw_write_associd(ah);
2886 /* Request full reset to get hw opmode changed properly */
2887 sc->sc_flags |= SC_OP_FULL_RESET;
2890 if ((changed & BSS_CHANGED_BSSID) &&
2891 !is_zero_ether_addr(bss_conf->bssid)) {
2892 switch (vif->type) {
2893 case NL80211_IFTYPE_STATION:
2894 case NL80211_IFTYPE_ADHOC:
2895 case NL80211_IFTYPE_MESH_POINT:
2897 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
2898 memcpy(avp->bssid, bss_conf->bssid, ETH_ALEN);
2900 ath9k_hw_write_associd(ah);
2902 /* Set aggregation protection mode parameters */
2903 sc->config.ath_aggr_prot = 0;
2905 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG,
2906 "RX filter 0x%x bssid %pM aid 0x%x\n",
2907 rfilt, common->curbssid, common->curaid);
2909 /* need to reconfigure the beacon */
2910 sc->sc_flags &= ~SC_OP_BEACONS ;
2918 if ((vif->type == NL80211_IFTYPE_ADHOC) ||
2919 (vif->type == NL80211_IFTYPE_AP) ||
2920 (vif->type == NL80211_IFTYPE_MESH_POINT)) {
2921 if ((changed & BSS_CHANGED_BEACON) ||
2922 (changed & BSS_CHANGED_BEACON_ENABLED &&
2923 bss_conf->enable_beacon)) {
2925 * Allocate and setup the beacon frame.
2927 * Stop any previous beacon DMA. This may be
2928 * necessary, for example, when an ibss merge
2929 * causes reconfiguration; we may be called
2930 * with beacon transmission active.
2932 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
2934 error = ath_beacon_alloc(aphy, vif);
2936 ath_beacon_config(sc, vif);
2940 /* Check for WLAN_CAPABILITY_PRIVACY ? */
2941 if ((avp->av_opmode != NL80211_IFTYPE_STATION)) {
2942 for (i = 0; i < IEEE80211_WEP_NKID; i++)
2943 if (ath9k_hw_keyisvalid(sc->sc_ah, (u16)i))
2944 ath9k_hw_keysetmac(sc->sc_ah,
2949 /* Only legacy IBSS for now */
2950 if (vif->type == NL80211_IFTYPE_ADHOC)
2951 ath_update_chainmask(sc, 0);
2953 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2954 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
2955 bss_conf->use_short_preamble);
2956 if (bss_conf->use_short_preamble)
2957 sc->sc_flags |= SC_OP_PREAMBLE_SHORT;
2959 sc->sc_flags &= ~SC_OP_PREAMBLE_SHORT;
2962 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
2963 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
2964 bss_conf->use_cts_prot);
2965 if (bss_conf->use_cts_prot &&
2966 hw->conf.channel->band != IEEE80211_BAND_5GHZ)
2967 sc->sc_flags |= SC_OP_PROTECT_ENABLE;
2969 sc->sc_flags &= ~SC_OP_PROTECT_ENABLE;
2972 if (changed & BSS_CHANGED_ASSOC) {
2973 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
2975 ath9k_bss_assoc_info(sc, vif, bss_conf);
2979 * The HW TSF has to be reset when the beacon interval changes.
2980 * We set the flag here, and ath_beacon_config_ap() would take this
2981 * into account when it gets called through the subsequent
2982 * config_interface() call - with IFCC_BEACON in the changed field.
2985 if (changed & BSS_CHANGED_BEACON_INT) {
2986 sc->sc_flags |= SC_OP_TSF_RESET;
2987 sc->beacon_interval = bss_conf->beacon_int;
2990 mutex_unlock(&sc->mutex);
2993 static u64 ath9k_get_tsf(struct ieee80211_hw *hw)
2996 struct ath_wiphy *aphy = hw->priv;
2997 struct ath_softc *sc = aphy->sc;
2999 mutex_lock(&sc->mutex);
3000 tsf = ath9k_hw_gettsf64(sc->sc_ah);
3001 mutex_unlock(&sc->mutex);
3006 static void ath9k_set_tsf(struct ieee80211_hw *hw, u64 tsf)
3008 struct ath_wiphy *aphy = hw->priv;
3009 struct ath_softc *sc = aphy->sc;
3011 mutex_lock(&sc->mutex);
3012 ath9k_hw_settsf64(sc->sc_ah, tsf);
3013 mutex_unlock(&sc->mutex);
3016 static void ath9k_reset_tsf(struct ieee80211_hw *hw)
3018 struct ath_wiphy *aphy = hw->priv;
3019 struct ath_softc *sc = aphy->sc;
3021 mutex_lock(&sc->mutex);
3023 ath9k_ps_wakeup(sc);
3024 ath9k_hw_reset_tsf(sc->sc_ah);
3025 ath9k_ps_restore(sc);
3027 mutex_unlock(&sc->mutex);
3030 static int ath9k_ampdu_action(struct ieee80211_hw *hw,
3031 enum ieee80211_ampdu_mlme_action action,
3032 struct ieee80211_sta *sta,
3035 struct ath_wiphy *aphy = hw->priv;
3036 struct ath_softc *sc = aphy->sc;
3040 case IEEE80211_AMPDU_RX_START:
3041 if (!(sc->sc_flags & SC_OP_RXAGGR))
3044 case IEEE80211_AMPDU_RX_STOP:
3046 case IEEE80211_AMPDU_TX_START:
3047 ath_tx_aggr_start(sc, sta, tid, ssn);
3048 ieee80211_start_tx_ba_cb_irqsafe(hw, sta->addr, tid);
3050 case IEEE80211_AMPDU_TX_STOP:
3051 ath_tx_aggr_stop(sc, sta, tid);
3052 ieee80211_stop_tx_ba_cb_irqsafe(hw, sta->addr, tid);
3054 case IEEE80211_AMPDU_TX_OPERATIONAL:
3055 ath_tx_aggr_resume(sc, sta, tid);
3058 DPRINTF(sc->sc_ah, ATH_DBG_FATAL, "Unknown AMPDU action\n");
3064 static void ath9k_sw_scan_start(struct ieee80211_hw *hw)
3066 struct ath_wiphy *aphy = hw->priv;
3067 struct ath_softc *sc = aphy->sc;
3069 mutex_lock(&sc->mutex);
3070 if (ath9k_wiphy_scanning(sc)) {
3071 printk(KERN_DEBUG "ath9k: Two wiphys trying to scan at the "
3074 * Do not allow the concurrent scanning state for now. This
3075 * could be improved with scanning control moved into ath9k.
3077 mutex_unlock(&sc->mutex);
3081 aphy->state = ATH_WIPHY_SCAN;
3082 ath9k_wiphy_pause_all_forced(sc, aphy);
3084 spin_lock_bh(&sc->ani_lock);
3085 sc->sc_flags |= SC_OP_SCANNING;
3086 spin_unlock_bh(&sc->ani_lock);
3087 mutex_unlock(&sc->mutex);
3090 static void ath9k_sw_scan_complete(struct ieee80211_hw *hw)
3092 struct ath_wiphy *aphy = hw->priv;
3093 struct ath_softc *sc = aphy->sc;
3095 mutex_lock(&sc->mutex);
3096 spin_lock_bh(&sc->ani_lock);
3097 aphy->state = ATH_WIPHY_ACTIVE;
3098 sc->sc_flags &= ~SC_OP_SCANNING;
3099 sc->sc_flags |= SC_OP_FULL_RESET;
3100 spin_unlock_bh(&sc->ani_lock);
3101 ath_beacon_config(sc, NULL);
3102 mutex_unlock(&sc->mutex);
3105 struct ieee80211_ops ath9k_ops = {
3107 .start = ath9k_start,
3109 .add_interface = ath9k_add_interface,
3110 .remove_interface = ath9k_remove_interface,
3111 .config = ath9k_config,
3112 .configure_filter = ath9k_configure_filter,
3113 .sta_notify = ath9k_sta_notify,
3114 .conf_tx = ath9k_conf_tx,
3115 .bss_info_changed = ath9k_bss_info_changed,
3116 .set_key = ath9k_set_key,
3117 .get_tsf = ath9k_get_tsf,
3118 .set_tsf = ath9k_set_tsf,
3119 .reset_tsf = ath9k_reset_tsf,
3120 .ampdu_action = ath9k_ampdu_action,
3121 .sw_scan_start = ath9k_sw_scan_start,
3122 .sw_scan_complete = ath9k_sw_scan_complete,
3123 .rfkill_poll = ath9k_rfkill_poll_state,
3129 } ath_mac_bb_names[] = {
3130 { AR_SREV_VERSION_5416_PCI, "5416" },
3131 { AR_SREV_VERSION_5416_PCIE, "5418" },
3132 { AR_SREV_VERSION_9100, "9100" },
3133 { AR_SREV_VERSION_9160, "9160" },
3134 { AR_SREV_VERSION_9280, "9280" },
3135 { AR_SREV_VERSION_9285, "9285" },
3136 { AR_SREV_VERSION_9287, "9287" }
3142 } ath_rf_names[] = {
3144 { AR_RAD5133_SREV_MAJOR, "5133" },
3145 { AR_RAD5122_SREV_MAJOR, "5122" },
3146 { AR_RAD2133_SREV_MAJOR, "2133" },
3147 { AR_RAD2122_SREV_MAJOR, "2122" }
3151 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.