2 * Copyright (c) 2008 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>
22 #define ATH_PCI_VERSION "0.1"
24 static char *dev_info = "ath9k";
26 MODULE_AUTHOR("Atheros Communications");
27 MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
28 MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
29 MODULE_LICENSE("Dual BSD/GPL");
31 static void ath_cache_conf_rate(struct ath_softc *sc,
32 struct ieee80211_conf *conf)
34 switch (conf->channel->band) {
35 case IEEE80211_BAND_2GHZ:
36 if (conf_is_ht20(conf))
38 sc->hw_rate_table[ATH9K_MODE_11NG_HT20];
39 else if (conf_is_ht40_minus(conf))
41 sc->hw_rate_table[ATH9K_MODE_11NG_HT40MINUS];
42 else if (conf_is_ht40_plus(conf))
44 sc->hw_rate_table[ATH9K_MODE_11NG_HT40PLUS];
47 sc->hw_rate_table[ATH9K_MODE_11G];
49 case IEEE80211_BAND_5GHZ:
50 if (conf_is_ht20(conf))
52 sc->hw_rate_table[ATH9K_MODE_11NA_HT20];
53 else if (conf_is_ht40_minus(conf))
55 sc->hw_rate_table[ATH9K_MODE_11NA_HT40MINUS];
56 else if (conf_is_ht40_plus(conf))
58 sc->hw_rate_table[ATH9K_MODE_11NA_HT40PLUS];
61 sc->hw_rate_table[ATH9K_MODE_11A];
69 static void ath_update_txpow(struct ath_softc *sc)
71 struct ath_hal *ah = sc->sc_ah;
74 if (sc->sc_curtxpow != sc->sc_config.txpowlimit) {
75 ath9k_hw_set_txpowerlimit(ah, sc->sc_config.txpowlimit);
76 /* read back in case value is clamped */
77 ath9k_hw_getcapability(ah, ATH9K_CAP_TXPOW, 1, &txpow);
78 sc->sc_curtxpow = txpow;
82 static u8 parse_mpdudensity(u8 mpdudensity)
85 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
86 * 0 for no restriction
95 switch (mpdudensity) {
101 /* Our lower layer calculations limit our precision to
117 static void ath_setup_rates(struct ath_softc *sc, enum ieee80211_band band)
119 struct ath_rate_table *rate_table = NULL;
120 struct ieee80211_supported_band *sband;
121 struct ieee80211_rate *rate;
125 case IEEE80211_BAND_2GHZ:
126 rate_table = sc->hw_rate_table[ATH9K_MODE_11G];
128 case IEEE80211_BAND_5GHZ:
129 rate_table = sc->hw_rate_table[ATH9K_MODE_11A];
135 if (rate_table == NULL)
138 sband = &sc->sbands[band];
139 rate = sc->rates[band];
141 if (rate_table->rate_cnt > ATH_RATE_MAX)
142 maxrates = ATH_RATE_MAX;
144 maxrates = rate_table->rate_cnt;
146 for (i = 0; i < maxrates; i++) {
147 rate[i].bitrate = rate_table->info[i].ratekbps / 100;
148 rate[i].hw_value = rate_table->info[i].ratecode;
150 DPRINTF(sc, ATH_DBG_CONFIG, "Rate: %2dMbps, ratecode: %2d\n",
151 rate[i].bitrate / 10, rate[i].hw_value);
155 static int ath_setup_channels(struct ath_softc *sc)
157 struct ath_hal *ah = sc->sc_ah;
158 int nchan, i, a = 0, b = 0;
159 u8 regclassids[ATH_REGCLASSIDS_MAX];
161 struct ieee80211_supported_band *band_2ghz;
162 struct ieee80211_supported_band *band_5ghz;
163 struct ieee80211_channel *chan_2ghz;
164 struct ieee80211_channel *chan_5ghz;
165 struct ath9k_channel *c;
167 /* Fill in ah->ah_channels */
168 if (!ath9k_regd_init_channels(ah, ATH_CHAN_MAX, (u32 *)&nchan,
169 regclassids, ATH_REGCLASSIDS_MAX,
170 &nregclass, CTRY_DEFAULT, false, 1)) {
171 u32 rd = ah->ah_currentRD;
172 DPRINTF(sc, ATH_DBG_FATAL,
173 "Unable to collect channel list; "
174 "regdomain likely %u country code %u\n",
179 band_2ghz = &sc->sbands[IEEE80211_BAND_2GHZ];
180 band_5ghz = &sc->sbands[IEEE80211_BAND_5GHZ];
181 chan_2ghz = sc->channels[IEEE80211_BAND_2GHZ];
182 chan_5ghz = sc->channels[IEEE80211_BAND_5GHZ];
184 for (i = 0; i < nchan; i++) {
185 c = &ah->ah_channels[i];
186 if (IS_CHAN_2GHZ(c)) {
187 chan_2ghz[a].band = IEEE80211_BAND_2GHZ;
188 chan_2ghz[a].center_freq = c->channel;
189 chan_2ghz[a].max_power = c->maxTxPower;
190 c->chan = &chan_2ghz[a];
192 if (c->privFlags & CHANNEL_DISALLOW_ADHOC)
193 chan_2ghz[a].flags |= IEEE80211_CHAN_NO_IBSS;
194 if (c->channelFlags & CHANNEL_PASSIVE)
195 chan_2ghz[a].flags |= IEEE80211_CHAN_PASSIVE_SCAN;
197 band_2ghz->n_channels = ++a;
199 DPRINTF(sc, ATH_DBG_CONFIG, "2MHz channel: %d, "
200 "channelFlags: 0x%x\n",
201 c->channel, c->channelFlags);
202 } else if (IS_CHAN_5GHZ(c)) {
203 chan_5ghz[b].band = IEEE80211_BAND_5GHZ;
204 chan_5ghz[b].center_freq = c->channel;
205 chan_5ghz[b].max_power = c->maxTxPower;
206 c->chan = &chan_5ghz[a];
208 if (c->privFlags & CHANNEL_DISALLOW_ADHOC)
209 chan_5ghz[b].flags |= IEEE80211_CHAN_NO_IBSS;
210 if (c->channelFlags & CHANNEL_PASSIVE)
211 chan_5ghz[b].flags |= IEEE80211_CHAN_PASSIVE_SCAN;
213 band_5ghz->n_channels = ++b;
215 DPRINTF(sc, ATH_DBG_CONFIG, "5MHz channel: %d, "
216 "channelFlags: 0x%x\n",
217 c->channel, c->channelFlags);
225 * Set/change channels. If the channel is really being changed, it's done
226 * by reseting the chip. To accomplish this we must first cleanup any pending
227 * DMA, then restart stuff.
229 static int ath_set_channel(struct ath_softc *sc, struct ath9k_channel *hchan)
231 struct ath_hal *ah = sc->sc_ah;
232 bool fastcc = true, stopped;
233 struct ieee80211_hw *hw = sc->hw;
234 struct ieee80211_channel *channel = hw->conf.channel;
237 if (sc->sc_flags & SC_OP_INVALID)
243 * This is only performed if the channel settings have
246 * To switch channels clear any pending DMA operations;
247 * wait long enough for the RX fifo to drain, reset the
248 * hardware at the new frequency, and then re-enable
249 * the relevant bits of the h/w.
251 ath9k_hw_set_interrupts(ah, 0);
252 ath_drain_all_txq(sc, false);
253 stopped = ath_stoprecv(sc);
255 /* XXX: do not flush receive queue here. We don't want
256 * to flush data frames already in queue because of
257 * changing channel. */
259 if (!stopped || (sc->sc_flags & SC_OP_FULL_RESET))
262 DPRINTF(sc, ATH_DBG_CONFIG,
263 "(%u MHz) -> (%u MHz), chanwidth: %d\n",
264 sc->sc_ah->ah_curchan->channel,
265 channel->center_freq, sc->tx_chan_width);
267 spin_lock_bh(&sc->sc_resetlock);
269 r = ath9k_hw_reset(ah, hchan, fastcc);
271 DPRINTF(sc, ATH_DBG_FATAL,
272 "Unable to reset channel (%u Mhz) "
274 channel->center_freq, r);
275 spin_unlock_bh(&sc->sc_resetlock);
278 spin_unlock_bh(&sc->sc_resetlock);
280 sc->sc_flags &= ~SC_OP_CHAINMASK_UPDATE;
281 sc->sc_flags &= ~SC_OP_FULL_RESET;
283 if (ath_startrecv(sc) != 0) {
284 DPRINTF(sc, ATH_DBG_FATAL,
285 "Unable to restart recv logic\n");
289 ath_cache_conf_rate(sc, &hw->conf);
290 ath_update_txpow(sc);
291 ath9k_hw_set_interrupts(ah, sc->sc_imask);
292 ath9k_ps_restore(sc);
297 * This routine performs the periodic noise floor calibration function
298 * that is used to adjust and optimize the chip performance. This
299 * takes environmental changes (location, temperature) into account.
300 * When the task is complete, it reschedules itself depending on the
301 * appropriate interval that was calculated.
303 static void ath_ani_calibrate(unsigned long data)
305 struct ath_softc *sc;
307 bool longcal = false;
308 bool shortcal = false;
309 bool aniflag = false;
310 unsigned int timestamp = jiffies_to_msecs(jiffies);
313 sc = (struct ath_softc *)data;
317 * don't calibrate when we're scanning.
318 * we are most likely not on our home channel.
320 if (sc->rx.rxfilter & FIF_BCN_PRBRESP_PROMISC)
323 /* Long calibration runs independently of short calibration. */
324 if ((timestamp - sc->sc_ani.sc_longcal_timer) >= ATH_LONG_CALINTERVAL) {
326 DPRINTF(sc, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
327 sc->sc_ani.sc_longcal_timer = timestamp;
330 /* Short calibration applies only while sc_caldone is false */
331 if (!sc->sc_ani.sc_caldone) {
332 if ((timestamp - sc->sc_ani.sc_shortcal_timer) >=
333 ATH_SHORT_CALINTERVAL) {
335 DPRINTF(sc, ATH_DBG_ANI, "shortcal @%lu\n", jiffies);
336 sc->sc_ani.sc_shortcal_timer = timestamp;
337 sc->sc_ani.sc_resetcal_timer = timestamp;
340 if ((timestamp - sc->sc_ani.sc_resetcal_timer) >=
341 ATH_RESTART_CALINTERVAL) {
342 sc->sc_ani.sc_caldone = ath9k_hw_reset_calvalid(ah);
343 if (sc->sc_ani.sc_caldone)
344 sc->sc_ani.sc_resetcal_timer = timestamp;
348 /* Verify whether we must check ANI */
349 if ((timestamp - sc->sc_ani.sc_checkani_timer) >=
350 ATH_ANI_POLLINTERVAL) {
352 sc->sc_ani.sc_checkani_timer = timestamp;
355 /* Skip all processing if there's nothing to do. */
356 if (longcal || shortcal || aniflag) {
357 /* Call ANI routine if necessary */
359 ath9k_hw_ani_monitor(ah, &sc->sc_halstats,
362 /* Perform calibration if necessary */
363 if (longcal || shortcal) {
364 bool iscaldone = false;
366 if (ath9k_hw_calibrate(ah, ah->ah_curchan,
367 sc->sc_rx_chainmask, longcal,
370 sc->sc_ani.sc_noise_floor =
371 ath9k_hw_getchan_noise(ah,
374 DPRINTF(sc, ATH_DBG_ANI,
375 "calibrate chan %u/%x nf: %d\n",
376 ah->ah_curchan->channel,
377 ah->ah_curchan->channelFlags,
378 sc->sc_ani.sc_noise_floor);
380 DPRINTF(sc, ATH_DBG_ANY,
381 "calibrate chan %u/%x failed\n",
382 ah->ah_curchan->channel,
383 ah->ah_curchan->channelFlags);
385 sc->sc_ani.sc_caldone = iscaldone;
390 * Set timer interval based on previous results.
391 * The interval must be the shortest necessary to satisfy ANI,
392 * short calibration and long calibration.
394 cal_interval = ATH_LONG_CALINTERVAL;
395 if (sc->sc_ah->ah_config.enable_ani)
396 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
397 if (!sc->sc_ani.sc_caldone)
398 cal_interval = min(cal_interval, (u32)ATH_SHORT_CALINTERVAL);
400 mod_timer(&sc->sc_ani.timer, jiffies + msecs_to_jiffies(cal_interval));
404 * Update tx/rx chainmask. For legacy association,
405 * hard code chainmask to 1x1, for 11n association, use
406 * the chainmask configuration, for bt coexistence, use
407 * the chainmask configuration even in legacy mode.
409 static void ath_update_chainmask(struct ath_softc *sc, int is_ht)
411 sc->sc_flags |= SC_OP_CHAINMASK_UPDATE;
413 (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_BT_COEX)) {
414 sc->sc_tx_chainmask = sc->sc_ah->ah_caps.tx_chainmask;
415 sc->sc_rx_chainmask = sc->sc_ah->ah_caps.rx_chainmask;
417 sc->sc_tx_chainmask = 1;
418 sc->sc_rx_chainmask = 1;
421 DPRINTF(sc, ATH_DBG_CONFIG, "tx chmask: %d, rx chmask: %d\n",
422 sc->sc_tx_chainmask, sc->sc_rx_chainmask);
425 static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta)
429 an = (struct ath_node *)sta->drv_priv;
431 if (sc->sc_flags & SC_OP_TXAGGR)
432 ath_tx_node_init(sc, an);
434 an->maxampdu = 1 << (IEEE80211_HTCAP_MAXRXAMPDU_FACTOR +
435 sta->ht_cap.ampdu_factor);
436 an->mpdudensity = parse_mpdudensity(sta->ht_cap.ampdu_density);
439 static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta)
441 struct ath_node *an = (struct ath_node *)sta->drv_priv;
443 if (sc->sc_flags & SC_OP_TXAGGR)
444 ath_tx_node_cleanup(sc, an);
447 static void ath9k_tasklet(unsigned long data)
449 struct ath_softc *sc = (struct ath_softc *)data;
450 u32 status = sc->sc_intrstatus;
452 if (status & ATH9K_INT_FATAL) {
453 /* need a chip reset */
454 ath_reset(sc, false);
459 (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN)) {
460 spin_lock_bh(&sc->rx.rxflushlock);
461 ath_rx_tasklet(sc, 0);
462 spin_unlock_bh(&sc->rx.rxflushlock);
464 /* XXX: optimize this */
465 if (status & ATH9K_INT_TX)
469 /* re-enable hardware interrupt */
470 ath9k_hw_set_interrupts(sc->sc_ah, sc->sc_imask);
473 irqreturn_t ath_isr(int irq, void *dev)
475 struct ath_softc *sc = dev;
476 struct ath_hal *ah = sc->sc_ah;
477 enum ath9k_int status;
481 if (sc->sc_flags & SC_OP_INVALID) {
483 * The hardware is not ready/present, don't
484 * touch anything. Note this can happen early
485 * on if the IRQ is shared.
489 if (!ath9k_hw_intrpend(ah)) { /* shared irq, not for us */
494 * Figure out the reason(s) for the interrupt. Note
495 * that the hal returns a pseudo-ISR that may include
496 * bits we haven't explicitly enabled so we mask the
497 * value to insure we only process bits we requested.
499 ath9k_hw_getisr(ah, &status); /* NB: clears ISR too */
501 status &= sc->sc_imask; /* discard unasked-for bits */
504 * If there are no status bits set, then this interrupt was not
505 * for me (should have been caught above).
510 sc->sc_intrstatus = status;
512 if (status & ATH9K_INT_FATAL) {
513 /* need a chip reset */
515 } else if (status & ATH9K_INT_RXORN) {
516 /* need a chip reset */
519 if (status & ATH9K_INT_SWBA) {
520 /* schedule a tasklet for beacon handling */
521 tasklet_schedule(&sc->bcon_tasklet);
523 if (status & ATH9K_INT_RXEOL) {
525 * NB: the hardware should re-read the link when
526 * RXE bit is written, but it doesn't work
527 * at least on older hardware revs.
532 if (status & ATH9K_INT_TXURN)
533 /* bump tx trigger level */
534 ath9k_hw_updatetxtriglevel(ah, true);
535 /* XXX: optimize this */
536 if (status & ATH9K_INT_RX)
538 if (status & ATH9K_INT_TX)
540 if (status & ATH9K_INT_BMISS)
542 /* carrier sense timeout */
543 if (status & ATH9K_INT_CST)
545 if (status & ATH9K_INT_MIB) {
547 * Disable interrupts until we service the MIB
548 * interrupt; otherwise it will continue to
551 ath9k_hw_set_interrupts(ah, 0);
553 * Let the hal handle the event. We assume
554 * it will clear whatever condition caused
557 ath9k_hw_procmibevent(ah, &sc->sc_halstats);
558 ath9k_hw_set_interrupts(ah, sc->sc_imask);
560 if (status & ATH9K_INT_TIM_TIMER) {
561 if (!(ah->ah_caps.hw_caps &
562 ATH9K_HW_CAP_AUTOSLEEP)) {
563 /* Clear RxAbort bit so that we can
565 ath9k_hw_setpower(ah, ATH9K_PM_AWAKE);
566 ath9k_hw_setrxabort(ah, 0);
568 sc->sc_flags |= SC_OP_WAIT_FOR_BEACON;
574 ath_debug_stat_interrupt(sc, status);
577 /* turn off every interrupt except SWBA */
578 ath9k_hw_set_interrupts(ah, (sc->sc_imask & ATH9K_INT_SWBA));
579 tasklet_schedule(&sc->intr_tq);
585 static int ath_get_channel(struct ath_softc *sc,
586 struct ieee80211_channel *chan)
590 for (i = 0; i < sc->sc_ah->ah_nchan; i++) {
591 if (sc->sc_ah->ah_channels[i].channel == chan->center_freq)
598 static u32 ath_get_extchanmode(struct ath_softc *sc,
599 struct ieee80211_channel *chan,
600 enum nl80211_channel_type channel_type)
604 switch (chan->band) {
605 case IEEE80211_BAND_2GHZ:
606 switch(channel_type) {
607 case NL80211_CHAN_NO_HT:
608 case NL80211_CHAN_HT20:
609 chanmode = CHANNEL_G_HT20;
611 case NL80211_CHAN_HT40PLUS:
612 chanmode = CHANNEL_G_HT40PLUS;
614 case NL80211_CHAN_HT40MINUS:
615 chanmode = CHANNEL_G_HT40MINUS;
619 case IEEE80211_BAND_5GHZ:
620 switch(channel_type) {
621 case NL80211_CHAN_NO_HT:
622 case NL80211_CHAN_HT20:
623 chanmode = CHANNEL_A_HT20;
625 case NL80211_CHAN_HT40PLUS:
626 chanmode = CHANNEL_A_HT40PLUS;
628 case NL80211_CHAN_HT40MINUS:
629 chanmode = CHANNEL_A_HT40MINUS;
640 static int ath_keyset(struct ath_softc *sc, u16 keyix,
641 struct ath9k_keyval *hk, const u8 mac[ETH_ALEN])
645 status = ath9k_hw_set_keycache_entry(sc->sc_ah,
646 keyix, hk, mac, false);
648 return status != false;
651 static int ath_setkey_tkip(struct ath_softc *sc, u16 keyix, const u8 *key,
652 struct ath9k_keyval *hk,
658 key_txmic = key + NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY;
659 key_rxmic = key + NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY;
662 /* Group key installation */
663 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
664 return ath_keyset(sc, keyix, hk, addr);
666 if (!sc->sc_splitmic) {
668 * data key goes at first index,
669 * the hal handles the MIC keys at index+64.
671 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
672 memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_txmic));
673 return ath_keyset(sc, keyix, hk, addr);
676 * TX key goes at first index, RX key at +32.
677 * The hal handles the MIC keys at index+64.
679 memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
680 if (!ath_keyset(sc, keyix, hk, NULL)) {
681 /* Txmic entry failed. No need to proceed further */
682 DPRINTF(sc, ATH_DBG_KEYCACHE,
683 "Setting TX MIC Key Failed\n");
687 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
688 /* XXX delete tx key on failure? */
689 return ath_keyset(sc, keyix + 32, hk, addr);
692 static int ath_reserve_key_cache_slot_tkip(struct ath_softc *sc)
696 for (i = IEEE80211_WEP_NKID; i < sc->sc_keymax / 2; i++) {
697 if (test_bit(i, sc->sc_keymap) ||
698 test_bit(i + 64, sc->sc_keymap))
699 continue; /* At least one part of TKIP key allocated */
700 if (sc->sc_splitmic &&
701 (test_bit(i + 32, sc->sc_keymap) ||
702 test_bit(i + 64 + 32, sc->sc_keymap)))
703 continue; /* At least one part of TKIP key allocated */
705 /* Found a free slot for a TKIP key */
711 static int ath_reserve_key_cache_slot(struct ath_softc *sc)
715 /* First, try to find slots that would not be available for TKIP. */
716 if (sc->sc_splitmic) {
717 for (i = IEEE80211_WEP_NKID; i < sc->sc_keymax / 4; i++) {
718 if (!test_bit(i, sc->sc_keymap) &&
719 (test_bit(i + 32, sc->sc_keymap) ||
720 test_bit(i + 64, sc->sc_keymap) ||
721 test_bit(i + 64 + 32, sc->sc_keymap)))
723 if (!test_bit(i + 32, sc->sc_keymap) &&
724 (test_bit(i, sc->sc_keymap) ||
725 test_bit(i + 64, sc->sc_keymap) ||
726 test_bit(i + 64 + 32, sc->sc_keymap)))
728 if (!test_bit(i + 64, sc->sc_keymap) &&
729 (test_bit(i , sc->sc_keymap) ||
730 test_bit(i + 32, sc->sc_keymap) ||
731 test_bit(i + 64 + 32, sc->sc_keymap)))
733 if (!test_bit(i + 64 + 32, sc->sc_keymap) &&
734 (test_bit(i, sc->sc_keymap) ||
735 test_bit(i + 32, sc->sc_keymap) ||
736 test_bit(i + 64, sc->sc_keymap)))
740 for (i = IEEE80211_WEP_NKID; i < sc->sc_keymax / 2; i++) {
741 if (!test_bit(i, sc->sc_keymap) &&
742 test_bit(i + 64, sc->sc_keymap))
744 if (test_bit(i, sc->sc_keymap) &&
745 !test_bit(i + 64, sc->sc_keymap))
750 /* No partially used TKIP slots, pick any available slot */
751 for (i = IEEE80211_WEP_NKID; i < sc->sc_keymax; i++) {
752 /* Do not allow slots that could be needed for TKIP group keys
753 * to be used. This limitation could be removed if we know that
754 * TKIP will not be used. */
755 if (i >= 64 && i < 64 + IEEE80211_WEP_NKID)
757 if (sc->sc_splitmic) {
758 if (i >= 32 && i < 32 + IEEE80211_WEP_NKID)
760 if (i >= 64 + 32 && i < 64 + 32 + IEEE80211_WEP_NKID)
764 if (!test_bit(i, sc->sc_keymap))
765 return i; /* Found a free slot for a key */
768 /* No free slot found */
772 static int ath_key_config(struct ath_softc *sc,
773 struct ieee80211_sta *sta,
774 struct ieee80211_key_conf *key)
776 struct ath9k_keyval hk;
777 const u8 *mac = NULL;
781 memset(&hk, 0, sizeof(hk));
785 hk.kv_type = ATH9K_CIPHER_WEP;
788 hk.kv_type = ATH9K_CIPHER_TKIP;
791 hk.kv_type = ATH9K_CIPHER_AES_CCM;
797 hk.kv_len = key->keylen;
798 memcpy(hk.kv_val, key->key, key->keylen);
800 if (!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
801 /* For now, use the default keys for broadcast keys. This may
802 * need to change with virtual interfaces. */
804 } else if (key->keyidx) {
805 struct ieee80211_vif *vif;
811 vif = sc->sc_vaps[0];
812 if (vif->type != NL80211_IFTYPE_AP) {
813 /* Only keyidx 0 should be used with unicast key, but
814 * allow this for client mode for now. */
823 if (key->alg == ALG_TKIP)
824 idx = ath_reserve_key_cache_slot_tkip(sc);
826 idx = ath_reserve_key_cache_slot(sc);
828 return -ENOSPC; /* no free key cache entries */
831 if (key->alg == ALG_TKIP)
832 ret = ath_setkey_tkip(sc, idx, key->key, &hk, mac);
834 ret = ath_keyset(sc, idx, &hk, mac);
839 set_bit(idx, sc->sc_keymap);
840 if (key->alg == ALG_TKIP) {
841 set_bit(idx + 64, sc->sc_keymap);
842 if (sc->sc_splitmic) {
843 set_bit(idx + 32, sc->sc_keymap);
844 set_bit(idx + 64 + 32, sc->sc_keymap);
851 static void ath_key_delete(struct ath_softc *sc, struct ieee80211_key_conf *key)
853 ath9k_hw_keyreset(sc->sc_ah, key->hw_key_idx);
854 if (key->hw_key_idx < IEEE80211_WEP_NKID)
857 clear_bit(key->hw_key_idx, sc->sc_keymap);
858 if (key->alg != ALG_TKIP)
861 clear_bit(key->hw_key_idx + 64, sc->sc_keymap);
862 if (sc->sc_splitmic) {
863 clear_bit(key->hw_key_idx + 32, sc->sc_keymap);
864 clear_bit(key->hw_key_idx + 64 + 32, sc->sc_keymap);
868 static void setup_ht_cap(struct ieee80211_sta_ht_cap *ht_info)
870 #define ATH9K_HT_CAP_MAXRXAMPDU_65536 0x3 /* 2 ^ 16 */
871 #define ATH9K_HT_CAP_MPDUDENSITY_8 0x6 /* 8 usec */
873 ht_info->ht_supported = true;
874 ht_info->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
875 IEEE80211_HT_CAP_SM_PS |
876 IEEE80211_HT_CAP_SGI_40 |
877 IEEE80211_HT_CAP_DSSSCCK40;
879 ht_info->ampdu_factor = ATH9K_HT_CAP_MAXRXAMPDU_65536;
880 ht_info->ampdu_density = ATH9K_HT_CAP_MPDUDENSITY_8;
881 /* set up supported mcs set */
882 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
883 ht_info->mcs.rx_mask[0] = 0xff;
884 ht_info->mcs.rx_mask[1] = 0xff;
885 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
888 static void ath9k_bss_assoc_info(struct ath_softc *sc,
889 struct ieee80211_vif *vif,
890 struct ieee80211_bss_conf *bss_conf)
892 struct ath_vap *avp = (void *)vif->drv_priv;
894 if (bss_conf->assoc) {
895 DPRINTF(sc, ATH_DBG_CONFIG, "Bss Info ASSOC %d, bssid: %pM\n",
896 bss_conf->aid, sc->sc_curbssid);
898 /* New association, store aid */
899 if (avp->av_opmode == NL80211_IFTYPE_STATION) {
900 sc->sc_curaid = bss_conf->aid;
901 ath9k_hw_write_associd(sc->sc_ah, sc->sc_curbssid,
905 /* Configure the beacon */
906 ath_beacon_config(sc, 0);
907 sc->sc_flags |= SC_OP_BEACONS;
909 /* Reset rssi stats */
910 sc->sc_halstats.ns_avgbrssi = ATH_RSSI_DUMMY_MARKER;
911 sc->sc_halstats.ns_avgrssi = ATH_RSSI_DUMMY_MARKER;
912 sc->sc_halstats.ns_avgtxrssi = ATH_RSSI_DUMMY_MARKER;
913 sc->sc_halstats.ns_avgtxrate = ATH_RATE_DUMMY_MARKER;
916 mod_timer(&sc->sc_ani.timer,
917 jiffies + msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
920 DPRINTF(sc, ATH_DBG_CONFIG, "Bss Info DISSOC\n");
925 /********************************/
927 /********************************/
929 static void ath_led_brightness(struct led_classdev *led_cdev,
930 enum led_brightness brightness)
932 struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev);
933 struct ath_softc *sc = led->sc;
935 switch (brightness) {
937 if (led->led_type == ATH_LED_ASSOC ||
938 led->led_type == ATH_LED_RADIO)
939 sc->sc_flags &= ~SC_OP_LED_ASSOCIATED;
940 ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN,
941 (led->led_type == ATH_LED_RADIO) ? 1 :
942 !!(sc->sc_flags & SC_OP_LED_ASSOCIATED));
945 if (led->led_type == ATH_LED_ASSOC)
946 sc->sc_flags |= SC_OP_LED_ASSOCIATED;
947 ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 0);
954 static int ath_register_led(struct ath_softc *sc, struct ath_led *led,
960 led->led_cdev.name = led->name;
961 led->led_cdev.default_trigger = trigger;
962 led->led_cdev.brightness_set = ath_led_brightness;
964 ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &led->led_cdev);
966 DPRINTF(sc, ATH_DBG_FATAL,
967 "Failed to register led:%s", led->name);
973 static void ath_unregister_led(struct ath_led *led)
975 if (led->registered) {
976 led_classdev_unregister(&led->led_cdev);
981 static void ath_deinit_leds(struct ath_softc *sc)
983 ath_unregister_led(&sc->assoc_led);
984 sc->sc_flags &= ~SC_OP_LED_ASSOCIATED;
985 ath_unregister_led(&sc->tx_led);
986 ath_unregister_led(&sc->rx_led);
987 ath_unregister_led(&sc->radio_led);
988 ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1);
991 static void ath_init_leds(struct ath_softc *sc)
996 /* Configure gpio 1 for output */
997 ath9k_hw_cfg_output(sc->sc_ah, ATH_LED_PIN,
998 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
999 /* LED off, active low */
1000 ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1);
1002 trigger = ieee80211_get_radio_led_name(sc->hw);
1003 snprintf(sc->radio_led.name, sizeof(sc->radio_led.name),
1004 "ath9k-%s:radio", wiphy_name(sc->hw->wiphy));
1005 ret = ath_register_led(sc, &sc->radio_led, trigger);
1006 sc->radio_led.led_type = ATH_LED_RADIO;
1010 trigger = ieee80211_get_assoc_led_name(sc->hw);
1011 snprintf(sc->assoc_led.name, sizeof(sc->assoc_led.name),
1012 "ath9k-%s:assoc", wiphy_name(sc->hw->wiphy));
1013 ret = ath_register_led(sc, &sc->assoc_led, trigger);
1014 sc->assoc_led.led_type = ATH_LED_ASSOC;
1018 trigger = ieee80211_get_tx_led_name(sc->hw);
1019 snprintf(sc->tx_led.name, sizeof(sc->tx_led.name),
1020 "ath9k-%s:tx", wiphy_name(sc->hw->wiphy));
1021 ret = ath_register_led(sc, &sc->tx_led, trigger);
1022 sc->tx_led.led_type = ATH_LED_TX;
1026 trigger = ieee80211_get_rx_led_name(sc->hw);
1027 snprintf(sc->rx_led.name, sizeof(sc->rx_led.name),
1028 "ath9k-%s:rx", wiphy_name(sc->hw->wiphy));
1029 ret = ath_register_led(sc, &sc->rx_led, trigger);
1030 sc->rx_led.led_type = ATH_LED_RX;
1037 ath_deinit_leds(sc);
1040 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
1042 /*******************/
1044 /*******************/
1046 static void ath_radio_enable(struct ath_softc *sc)
1048 struct ath_hal *ah = sc->sc_ah;
1049 struct ieee80211_channel *channel = sc->hw->conf.channel;
1052 ath9k_ps_wakeup(sc);
1053 spin_lock_bh(&sc->sc_resetlock);
1055 r = ath9k_hw_reset(ah, ah->ah_curchan, false);
1058 DPRINTF(sc, ATH_DBG_FATAL,
1059 "Unable to reset channel %u (%uMhz) ",
1060 "reset status %u\n",
1061 channel->center_freq, r);
1063 spin_unlock_bh(&sc->sc_resetlock);
1065 ath_update_txpow(sc);
1066 if (ath_startrecv(sc) != 0) {
1067 DPRINTF(sc, ATH_DBG_FATAL,
1068 "Unable to restart recv logic\n");
1072 if (sc->sc_flags & SC_OP_BEACONS)
1073 ath_beacon_config(sc, ATH_IF_ID_ANY); /* restart beacons */
1075 /* Re-Enable interrupts */
1076 ath9k_hw_set_interrupts(ah, sc->sc_imask);
1079 ath9k_hw_cfg_output(ah, ATH_LED_PIN,
1080 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1081 ath9k_hw_set_gpio(ah, ATH_LED_PIN, 0);
1083 ieee80211_wake_queues(sc->hw);
1084 ath9k_ps_restore(sc);
1087 static void ath_radio_disable(struct ath_softc *sc)
1089 struct ath_hal *ah = sc->sc_ah;
1090 struct ieee80211_channel *channel = sc->hw->conf.channel;
1093 ath9k_ps_wakeup(sc);
1094 ieee80211_stop_queues(sc->hw);
1097 ath9k_hw_set_gpio(ah, ATH_LED_PIN, 1);
1098 ath9k_hw_cfg_gpio_input(ah, ATH_LED_PIN);
1100 /* Disable interrupts */
1101 ath9k_hw_set_interrupts(ah, 0);
1103 ath_drain_all_txq(sc, false); /* clear pending tx frames */
1104 ath_stoprecv(sc); /* turn off frame recv */
1105 ath_flushrecv(sc); /* flush recv queue */
1107 spin_lock_bh(&sc->sc_resetlock);
1108 r = ath9k_hw_reset(ah, ah->ah_curchan, false);
1110 DPRINTF(sc, ATH_DBG_FATAL,
1111 "Unable to reset channel %u (%uMhz) "
1112 "reset status %u\n",
1113 channel->center_freq, r);
1115 spin_unlock_bh(&sc->sc_resetlock);
1117 ath9k_hw_phy_disable(ah);
1118 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
1119 ath9k_ps_restore(sc);
1122 static bool ath_is_rfkill_set(struct ath_softc *sc)
1124 struct ath_hal *ah = sc->sc_ah;
1126 return ath9k_hw_gpio_get(ah, ah->ah_rfkill_gpio) ==
1127 ah->ah_rfkill_polarity;
1130 /* h/w rfkill poll function */
1131 static void ath_rfkill_poll(struct work_struct *work)
1133 struct ath_softc *sc = container_of(work, struct ath_softc,
1134 rf_kill.rfkill_poll.work);
1137 if (sc->sc_flags & SC_OP_INVALID)
1140 radio_on = !ath_is_rfkill_set(sc);
1143 * enable/disable radio only when there is a
1144 * state change in RF switch
1146 if (radio_on == !!(sc->sc_flags & SC_OP_RFKILL_HW_BLOCKED)) {
1147 enum rfkill_state state;
1149 if (sc->sc_flags & SC_OP_RFKILL_SW_BLOCKED) {
1150 state = radio_on ? RFKILL_STATE_SOFT_BLOCKED
1151 : RFKILL_STATE_HARD_BLOCKED;
1152 } else if (radio_on) {
1153 ath_radio_enable(sc);
1154 state = RFKILL_STATE_UNBLOCKED;
1156 ath_radio_disable(sc);
1157 state = RFKILL_STATE_HARD_BLOCKED;
1160 if (state == RFKILL_STATE_HARD_BLOCKED)
1161 sc->sc_flags |= SC_OP_RFKILL_HW_BLOCKED;
1163 sc->sc_flags &= ~SC_OP_RFKILL_HW_BLOCKED;
1165 rfkill_force_state(sc->rf_kill.rfkill, state);
1168 queue_delayed_work(sc->hw->workqueue, &sc->rf_kill.rfkill_poll,
1169 msecs_to_jiffies(ATH_RFKILL_POLL_INTERVAL));
1172 /* s/w rfkill handler */
1173 static int ath_sw_toggle_radio(void *data, enum rfkill_state state)
1175 struct ath_softc *sc = data;
1178 case RFKILL_STATE_SOFT_BLOCKED:
1179 if (!(sc->sc_flags & (SC_OP_RFKILL_HW_BLOCKED |
1180 SC_OP_RFKILL_SW_BLOCKED)))
1181 ath_radio_disable(sc);
1182 sc->sc_flags |= SC_OP_RFKILL_SW_BLOCKED;
1184 case RFKILL_STATE_UNBLOCKED:
1185 if ((sc->sc_flags & SC_OP_RFKILL_SW_BLOCKED)) {
1186 sc->sc_flags &= ~SC_OP_RFKILL_SW_BLOCKED;
1187 if (sc->sc_flags & SC_OP_RFKILL_HW_BLOCKED) {
1188 DPRINTF(sc, ATH_DBG_FATAL, "Can't turn on the"
1189 "radio as it is disabled by h/w\n");
1192 ath_radio_enable(sc);
1200 /* Init s/w rfkill */
1201 static int ath_init_sw_rfkill(struct ath_softc *sc)
1203 sc->rf_kill.rfkill = rfkill_allocate(wiphy_dev(sc->hw->wiphy),
1205 if (!sc->rf_kill.rfkill) {
1206 DPRINTF(sc, ATH_DBG_FATAL, "Failed to allocate rfkill\n");
1210 snprintf(sc->rf_kill.rfkill_name, sizeof(sc->rf_kill.rfkill_name),
1211 "ath9k-%s:rfkill", wiphy_name(sc->hw->wiphy));
1212 sc->rf_kill.rfkill->name = sc->rf_kill.rfkill_name;
1213 sc->rf_kill.rfkill->data = sc;
1214 sc->rf_kill.rfkill->toggle_radio = ath_sw_toggle_radio;
1215 sc->rf_kill.rfkill->state = RFKILL_STATE_UNBLOCKED;
1216 sc->rf_kill.rfkill->user_claim_unsupported = 1;
1221 /* Deinitialize rfkill */
1222 static void ath_deinit_rfkill(struct ath_softc *sc)
1224 if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1225 cancel_delayed_work_sync(&sc->rf_kill.rfkill_poll);
1227 if (sc->sc_flags & SC_OP_RFKILL_REGISTERED) {
1228 rfkill_unregister(sc->rf_kill.rfkill);
1229 sc->sc_flags &= ~SC_OP_RFKILL_REGISTERED;
1230 sc->rf_kill.rfkill = NULL;
1234 static int ath_start_rfkill_poll(struct ath_softc *sc)
1236 if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1237 queue_delayed_work(sc->hw->workqueue,
1238 &sc->rf_kill.rfkill_poll, 0);
1240 if (!(sc->sc_flags & SC_OP_RFKILL_REGISTERED)) {
1241 if (rfkill_register(sc->rf_kill.rfkill)) {
1242 DPRINTF(sc, ATH_DBG_FATAL,
1243 "Unable to register rfkill\n");
1244 rfkill_free(sc->rf_kill.rfkill);
1246 /* Deinitialize the device */
1250 sc->sc_flags |= SC_OP_RFKILL_REGISTERED;
1256 #endif /* CONFIG_RFKILL */
1258 void ath_cleanup(struct ath_softc *sc)
1261 free_irq(sc->irq, sc);
1262 ath_bus_cleanup(sc);
1263 ieee80211_free_hw(sc->hw);
1266 void ath_detach(struct ath_softc *sc)
1268 struct ieee80211_hw *hw = sc->hw;
1271 ath9k_ps_wakeup(sc);
1273 DPRINTF(sc, ATH_DBG_CONFIG, "Detach ATH hw\n");
1275 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
1276 ath_deinit_rfkill(sc);
1278 ath_deinit_leds(sc);
1280 ieee80211_unregister_hw(hw);
1284 tasklet_kill(&sc->intr_tq);
1285 tasklet_kill(&sc->bcon_tasklet);
1287 if (!(sc->sc_flags & SC_OP_INVALID))
1288 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
1290 /* cleanup tx queues */
1291 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1292 if (ATH_TXQ_SETUP(sc, i))
1293 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
1295 ath9k_hw_detach(sc->sc_ah);
1296 ath9k_exit_debug(sc);
1297 ath9k_ps_restore(sc);
1300 static int ath_init(u16 devid, struct ath_softc *sc)
1302 struct ath_hal *ah = NULL;
1307 /* XXX: hardware will not be ready until ath_open() being called */
1308 sc->sc_flags |= SC_OP_INVALID;
1310 if (ath9k_init_debug(sc) < 0)
1311 printk(KERN_ERR "Unable to create debugfs files\n");
1313 spin_lock_init(&sc->sc_resetlock);
1314 mutex_init(&sc->mutex);
1315 tasklet_init(&sc->intr_tq, ath9k_tasklet, (unsigned long)sc);
1316 tasklet_init(&sc->bcon_tasklet, ath9k_beacon_tasklet,
1320 * Cache line size is used to size and align various
1321 * structures used to communicate with the hardware.
1323 ath_read_cachesize(sc, &csz);
1324 /* XXX assert csz is non-zero */
1325 sc->sc_cachelsz = csz << 2; /* convert to bytes */
1327 ah = ath9k_hw_attach(devid, sc, sc->mem, &status);
1329 DPRINTF(sc, ATH_DBG_FATAL,
1330 "Unable to attach hardware; HAL status %d\n", status);
1336 /* Get the hardware key cache size. */
1337 sc->sc_keymax = ah->ah_caps.keycache_size;
1338 if (sc->sc_keymax > ATH_KEYMAX) {
1339 DPRINTF(sc, ATH_DBG_KEYCACHE,
1340 "Warning, using only %u entries in %u key cache\n",
1341 ATH_KEYMAX, sc->sc_keymax);
1342 sc->sc_keymax = ATH_KEYMAX;
1346 * Reset the key cache since some parts do not
1347 * reset the contents on initial power up.
1349 for (i = 0; i < sc->sc_keymax; i++)
1350 ath9k_hw_keyreset(ah, (u16) i);
1352 /* Collect the channel list using the default country code */
1354 error = ath_setup_channels(sc);
1358 /* default to MONITOR mode */
1359 sc->sc_ah->ah_opmode = NL80211_IFTYPE_MONITOR;
1362 /* Setup rate tables */
1364 ath_rate_attach(sc);
1365 ath_setup_rates(sc, IEEE80211_BAND_2GHZ);
1366 ath_setup_rates(sc, IEEE80211_BAND_5GHZ);
1369 * Allocate hardware transmit queues: one queue for
1370 * beacon frames and one data queue for each QoS
1371 * priority. Note that the hal handles reseting
1372 * these queues at the needed time.
1374 sc->beacon.beaconq = ath_beaconq_setup(ah);
1375 if (sc->beacon.beaconq == -1) {
1376 DPRINTF(sc, ATH_DBG_FATAL,
1377 "Unable to setup a beacon xmit queue\n");
1381 sc->beacon.cabq = ath_txq_setup(sc, ATH9K_TX_QUEUE_CAB, 0);
1382 if (sc->beacon.cabq == NULL) {
1383 DPRINTF(sc, ATH_DBG_FATAL,
1384 "Unable to setup CAB xmit queue\n");
1389 sc->sc_config.cabqReadytime = ATH_CABQ_READY_TIME;
1390 ath_cabq_update(sc);
1392 for (i = 0; i < ARRAY_SIZE(sc->tx.hwq_map); i++)
1393 sc->tx.hwq_map[i] = -1;
1395 /* Setup data queues */
1396 /* NB: ensure BK queue is the lowest priority h/w queue */
1397 if (!ath_tx_setup(sc, ATH9K_WME_AC_BK)) {
1398 DPRINTF(sc, ATH_DBG_FATAL,
1399 "Unable to setup xmit queue for BK traffic\n");
1404 if (!ath_tx_setup(sc, ATH9K_WME_AC_BE)) {
1405 DPRINTF(sc, ATH_DBG_FATAL,
1406 "Unable to setup xmit queue for BE traffic\n");
1410 if (!ath_tx_setup(sc, ATH9K_WME_AC_VI)) {
1411 DPRINTF(sc, ATH_DBG_FATAL,
1412 "Unable to setup xmit queue for VI traffic\n");
1416 if (!ath_tx_setup(sc, ATH9K_WME_AC_VO)) {
1417 DPRINTF(sc, ATH_DBG_FATAL,
1418 "Unable to setup xmit queue for VO traffic\n");
1423 /* Initializes the noise floor to a reasonable default value.
1424 * Later on this will be updated during ANI processing. */
1426 sc->sc_ani.sc_noise_floor = ATH_DEFAULT_NOISE_FLOOR;
1427 setup_timer(&sc->sc_ani.timer, ath_ani_calibrate, (unsigned long)sc);
1429 if (ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
1430 ATH9K_CIPHER_TKIP, NULL)) {
1432 * Whether we should enable h/w TKIP MIC.
1433 * XXX: if we don't support WME TKIP MIC, then we wouldn't
1434 * report WMM capable, so it's always safe to turn on
1435 * TKIP MIC in this case.
1437 ath9k_hw_setcapability(sc->sc_ah, ATH9K_CAP_TKIP_MIC,
1442 * Check whether the separate key cache entries
1443 * are required to handle both tx+rx MIC keys.
1444 * With split mic keys the number of stations is limited
1445 * to 27 otherwise 59.
1447 if (ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
1448 ATH9K_CIPHER_TKIP, NULL)
1449 && ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
1450 ATH9K_CIPHER_MIC, NULL)
1451 && ath9k_hw_getcapability(ah, ATH9K_CAP_TKIP_SPLIT,
1453 sc->sc_splitmic = 1;
1455 /* turn on mcast key search if possible */
1456 if (!ath9k_hw_getcapability(ah, ATH9K_CAP_MCAST_KEYSRCH, 0, NULL))
1457 (void)ath9k_hw_setcapability(ah, ATH9K_CAP_MCAST_KEYSRCH, 1,
1460 sc->sc_config.txpowlimit = ATH_TXPOWER_MAX;
1461 sc->sc_config.txpowlimit_override = 0;
1463 /* 11n Capabilities */
1464 if (ah->ah_caps.hw_caps & ATH9K_HW_CAP_HT) {
1465 sc->sc_flags |= SC_OP_TXAGGR;
1466 sc->sc_flags |= SC_OP_RXAGGR;
1469 sc->sc_tx_chainmask = ah->ah_caps.tx_chainmask;
1470 sc->sc_rx_chainmask = ah->ah_caps.rx_chainmask;
1472 ath9k_hw_setcapability(ah, ATH9K_CAP_DIVERSITY, 1, true, NULL);
1473 sc->rx.defant = ath9k_hw_getdefantenna(ah);
1475 ath9k_hw_getmac(ah, sc->sc_myaddr);
1476 if (ah->ah_caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK) {
1477 ath9k_hw_getbssidmask(ah, sc->sc_bssidmask);
1478 ATH_SET_VAP_BSSID_MASK(sc->sc_bssidmask);
1479 ath9k_hw_setbssidmask(ah, sc->sc_bssidmask);
1482 sc->beacon.slottime = ATH9K_SLOT_TIME_9; /* default to short slot time */
1484 /* initialize beacon slots */
1485 for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++)
1486 sc->beacon.bslot[i] = ATH_IF_ID_ANY;
1488 /* save MISC configurations */
1489 sc->sc_config.swBeaconProcess = 1;
1491 /* setup channels and rates */
1493 sc->sbands[IEEE80211_BAND_2GHZ].channels =
1494 sc->channels[IEEE80211_BAND_2GHZ];
1495 sc->sbands[IEEE80211_BAND_2GHZ].bitrates =
1496 sc->rates[IEEE80211_BAND_2GHZ];
1497 sc->sbands[IEEE80211_BAND_2GHZ].band = IEEE80211_BAND_2GHZ;
1499 if (test_bit(ATH9K_MODE_11A, sc->sc_ah->ah_caps.wireless_modes)) {
1500 sc->sbands[IEEE80211_BAND_5GHZ].channels =
1501 sc->channels[IEEE80211_BAND_5GHZ];
1502 sc->sbands[IEEE80211_BAND_5GHZ].bitrates =
1503 sc->rates[IEEE80211_BAND_5GHZ];
1504 sc->sbands[IEEE80211_BAND_5GHZ].band = IEEE80211_BAND_5GHZ;
1507 if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_BT_COEX)
1508 ath9k_hw_btcoex_enable(sc->sc_ah);
1512 /* cleanup tx queues */
1513 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1514 if (ATH_TXQ_SETUP(sc, i))
1515 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
1518 ath9k_hw_detach(ah);
1523 int ath_attach(u16 devid, struct ath_softc *sc)
1525 struct ieee80211_hw *hw = sc->hw;
1528 DPRINTF(sc, ATH_DBG_CONFIG, "Attach ATH hw\n");
1530 error = ath_init(devid, sc);
1534 /* get mac address from hardware and set in mac80211 */
1536 SET_IEEE80211_PERM_ADDR(hw, sc->sc_myaddr);
1538 hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
1539 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
1540 IEEE80211_HW_SIGNAL_DBM |
1541 IEEE80211_HW_AMPDU_AGGREGATION |
1542 IEEE80211_HW_SUPPORTS_PS |
1543 IEEE80211_HW_PS_NULLFUNC_STACK;
1545 if (AR_SREV_9160_10_OR_LATER(sc->sc_ah))
1546 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
1548 hw->wiphy->interface_modes =
1549 BIT(NL80211_IFTYPE_AP) |
1550 BIT(NL80211_IFTYPE_STATION) |
1551 BIT(NL80211_IFTYPE_ADHOC);
1555 hw->max_rate_tries = ATH_11N_TXMAXTRY;
1556 hw->sta_data_size = sizeof(struct ath_node);
1557 hw->vif_data_size = sizeof(struct ath_vap);
1559 hw->rate_control_algorithm = "ath9k_rate_control";
1561 if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_HT) {
1562 setup_ht_cap(&sc->sbands[IEEE80211_BAND_2GHZ].ht_cap);
1563 if (test_bit(ATH9K_MODE_11A, sc->sc_ah->ah_caps.wireless_modes))
1564 setup_ht_cap(&sc->sbands[IEEE80211_BAND_5GHZ].ht_cap);
1567 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &sc->sbands[IEEE80211_BAND_2GHZ];
1568 if (test_bit(ATH9K_MODE_11A, sc->sc_ah->ah_caps.wireless_modes))
1569 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
1570 &sc->sbands[IEEE80211_BAND_5GHZ];
1572 /* initialize tx/rx engine */
1573 error = ath_tx_init(sc, ATH_TXBUF);
1577 error = ath_rx_init(sc, ATH_RXBUF);
1581 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
1582 /* Initialze h/w Rfkill */
1583 if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1584 INIT_DELAYED_WORK(&sc->rf_kill.rfkill_poll, ath_rfkill_poll);
1586 /* Initialize s/w rfkill */
1587 if (ath_init_sw_rfkill(sc))
1591 error = ieee80211_register_hw(hw);
1593 /* Initialize LED control */
1602 int ath_reset(struct ath_softc *sc, bool retry_tx)
1604 struct ath_hal *ah = sc->sc_ah;
1605 struct ieee80211_hw *hw = sc->hw;
1608 ath9k_hw_set_interrupts(ah, 0);
1609 ath_drain_all_txq(sc, retry_tx);
1613 spin_lock_bh(&sc->sc_resetlock);
1614 r = ath9k_hw_reset(ah, sc->sc_ah->ah_curchan, false);
1616 DPRINTF(sc, ATH_DBG_FATAL,
1617 "Unable to reset hardware; reset status %u\n", r);
1618 spin_unlock_bh(&sc->sc_resetlock);
1620 if (ath_startrecv(sc) != 0)
1621 DPRINTF(sc, ATH_DBG_FATAL, "Unable to start recv logic\n");
1624 * We may be doing a reset in response to a request
1625 * that changes the channel so update any state that
1626 * might change as a result.
1628 ath_cache_conf_rate(sc, &hw->conf);
1630 ath_update_txpow(sc);
1632 if (sc->sc_flags & SC_OP_BEACONS)
1633 ath_beacon_config(sc, ATH_IF_ID_ANY); /* restart beacons */
1635 ath9k_hw_set_interrupts(ah, sc->sc_imask);
1639 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
1640 if (ATH_TXQ_SETUP(sc, i)) {
1641 spin_lock_bh(&sc->tx.txq[i].axq_lock);
1642 ath_txq_schedule(sc, &sc->tx.txq[i]);
1643 spin_unlock_bh(&sc->tx.txq[i].axq_lock);
1652 * This function will allocate both the DMA descriptor structure, and the
1653 * buffers it contains. These are used to contain the descriptors used
1656 int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
1657 struct list_head *head, const char *name,
1658 int nbuf, int ndesc)
1660 #define DS2PHYS(_dd, _ds) \
1661 ((_dd)->dd_desc_paddr + ((caddr_t)(_ds) - (caddr_t)(_dd)->dd_desc))
1662 #define ATH_DESC_4KB_BOUND_CHECK(_daddr) ((((_daddr) & 0xFFF) > 0xF7F) ? 1 : 0)
1663 #define ATH_DESC_4KB_BOUND_NUM_SKIPPED(_len) ((_len) / 4096)
1665 struct ath_desc *ds;
1667 int i, bsize, error;
1669 DPRINTF(sc, ATH_DBG_CONFIG, "%s DMA: %u buffers %u desc/buf\n",
1672 /* ath_desc must be a multiple of DWORDs */
1673 if ((sizeof(struct ath_desc) % 4) != 0) {
1674 DPRINTF(sc, ATH_DBG_FATAL, "ath_desc not DWORD aligned\n");
1675 ASSERT((sizeof(struct ath_desc) % 4) == 0);
1681 dd->dd_desc_len = sizeof(struct ath_desc) * nbuf * ndesc;
1684 * Need additional DMA memory because we can't use
1685 * descriptors that cross the 4K page boundary. Assume
1686 * one skipped descriptor per 4K page.
1688 if (!(sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_4KB_SPLITTRANS)) {
1690 ATH_DESC_4KB_BOUND_NUM_SKIPPED(dd->dd_desc_len);
1693 while (ndesc_skipped) {
1694 dma_len = ndesc_skipped * sizeof(struct ath_desc);
1695 dd->dd_desc_len += dma_len;
1697 ndesc_skipped = ATH_DESC_4KB_BOUND_NUM_SKIPPED(dma_len);
1701 /* allocate descriptors */
1702 dd->dd_desc = dma_alloc_coherent(sc->dev, dd->dd_desc_len,
1703 &dd->dd_desc_paddr, GFP_ATOMIC);
1704 if (dd->dd_desc == NULL) {
1709 DPRINTF(sc, ATH_DBG_CONFIG, "%s DMA map: %p (%u) -> %llx (%u)\n",
1710 dd->dd_name, ds, (u32) dd->dd_desc_len,
1711 ito64(dd->dd_desc_paddr), /*XXX*/(u32) dd->dd_desc_len);
1713 /* allocate buffers */
1714 bsize = sizeof(struct ath_buf) * nbuf;
1715 bf = kmalloc(bsize, GFP_KERNEL);
1720 memset(bf, 0, bsize);
1723 INIT_LIST_HEAD(head);
1724 for (i = 0; i < nbuf; i++, bf++, ds += ndesc) {
1726 bf->bf_daddr = DS2PHYS(dd, ds);
1728 if (!(sc->sc_ah->ah_caps.hw_caps &
1729 ATH9K_HW_CAP_4KB_SPLITTRANS)) {
1731 * Skip descriptor addresses which can cause 4KB
1732 * boundary crossing (addr + length) with a 32 dword
1735 while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
1736 ASSERT((caddr_t) bf->bf_desc <
1737 ((caddr_t) dd->dd_desc +
1742 bf->bf_daddr = DS2PHYS(dd, ds);
1745 list_add_tail(&bf->list, head);
1749 dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc,
1752 memset(dd, 0, sizeof(*dd));
1754 #undef ATH_DESC_4KB_BOUND_CHECK
1755 #undef ATH_DESC_4KB_BOUND_NUM_SKIPPED
1759 void ath_descdma_cleanup(struct ath_softc *sc,
1760 struct ath_descdma *dd,
1761 struct list_head *head)
1763 dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc,
1766 INIT_LIST_HEAD(head);
1767 kfree(dd->dd_bufptr);
1768 memset(dd, 0, sizeof(*dd));
1771 int ath_get_hal_qnum(u16 queue, struct ath_softc *sc)
1777 qnum = sc->tx.hwq_map[ATH9K_WME_AC_VO];
1780 qnum = sc->tx.hwq_map[ATH9K_WME_AC_VI];
1783 qnum = sc->tx.hwq_map[ATH9K_WME_AC_BE];
1786 qnum = sc->tx.hwq_map[ATH9K_WME_AC_BK];
1789 qnum = sc->tx.hwq_map[ATH9K_WME_AC_BE];
1796 int ath_get_mac80211_qnum(u32 queue, struct ath_softc *sc)
1801 case ATH9K_WME_AC_VO:
1804 case ATH9K_WME_AC_VI:
1807 case ATH9K_WME_AC_BE:
1810 case ATH9K_WME_AC_BK:
1821 /**********************/
1822 /* mac80211 callbacks */
1823 /**********************/
1825 static int ath9k_start(struct ieee80211_hw *hw)
1827 struct ath_softc *sc = hw->priv;
1828 struct ieee80211_channel *curchan = hw->conf.channel;
1829 struct ath9k_channel *init_channel;
1832 DPRINTF(sc, ATH_DBG_CONFIG, "Starting driver with "
1833 "initial channel: %d MHz\n", curchan->center_freq);
1835 /* setup initial channel */
1837 pos = ath_get_channel(sc, curchan);
1839 DPRINTF(sc, ATH_DBG_FATAL, "Invalid channel: %d\n", curchan->center_freq);
1843 sc->tx_chan_width = ATH9K_HT_MACMODE_20;
1844 sc->sc_ah->ah_channels[pos].chanmode =
1845 (curchan->band == IEEE80211_BAND_2GHZ) ? CHANNEL_G : CHANNEL_A;
1846 init_channel = &sc->sc_ah->ah_channels[pos];
1848 /* Reset SERDES registers */
1849 ath9k_hw_configpcipowersave(sc->sc_ah, 0);
1852 * The basic interface to setting the hardware in a good
1853 * state is ``reset''. On return the hardware is known to
1854 * be powered up and with interrupts disabled. This must
1855 * be followed by initialization of the appropriate bits
1856 * and then setup of the interrupt mask.
1858 spin_lock_bh(&sc->sc_resetlock);
1859 r = ath9k_hw_reset(sc->sc_ah, init_channel, false);
1861 DPRINTF(sc, ATH_DBG_FATAL,
1862 "Unable to reset hardware; reset status %u "
1863 "(freq %u MHz)\n", r,
1864 curchan->center_freq);
1865 spin_unlock_bh(&sc->sc_resetlock);
1868 spin_unlock_bh(&sc->sc_resetlock);
1871 * This is needed only to setup initial state
1872 * but it's best done after a reset.
1874 ath_update_txpow(sc);
1877 * Setup the hardware after reset:
1878 * The receive engine is set going.
1879 * Frame transmit is handled entirely
1880 * in the frame output path; there's nothing to do
1881 * here except setup the interrupt mask.
1883 if (ath_startrecv(sc) != 0) {
1884 DPRINTF(sc, ATH_DBG_FATAL,
1885 "Unable to start recv logic\n");
1889 /* Setup our intr mask. */
1890 sc->sc_imask = ATH9K_INT_RX | ATH9K_INT_TX
1891 | ATH9K_INT_RXEOL | ATH9K_INT_RXORN
1892 | ATH9K_INT_FATAL | ATH9K_INT_GLOBAL;
1894 if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_GTT)
1895 sc->sc_imask |= ATH9K_INT_GTT;
1897 if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_HT)
1898 sc->sc_imask |= ATH9K_INT_CST;
1901 * Enable MIB interrupts when there are hardware phy counters.
1902 * Note we only do this (at the moment) for station mode.
1904 if (ath9k_hw_phycounters(sc->sc_ah) &&
1905 ((sc->sc_ah->ah_opmode == NL80211_IFTYPE_STATION) ||
1906 (sc->sc_ah->ah_opmode == NL80211_IFTYPE_ADHOC)))
1907 sc->sc_imask |= ATH9K_INT_MIB;
1909 * Some hardware processes the TIM IE and fires an
1910 * interrupt when the TIM bit is set. For hardware
1911 * that does, if not overridden by configuration,
1912 * enable the TIM interrupt when operating as station.
1914 if ((sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_ENHANCEDPM) &&
1915 (sc->sc_ah->ah_opmode == NL80211_IFTYPE_STATION) &&
1916 !sc->sc_config.swBeaconProcess)
1917 sc->sc_imask |= ATH9K_INT_TIM;
1919 ath_cache_conf_rate(sc, &hw->conf);
1921 sc->sc_flags &= ~SC_OP_INVALID;
1923 /* Disable BMISS interrupt when we're not associated */
1924 sc->sc_imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
1925 ath9k_hw_set_interrupts(sc->sc_ah, sc->sc_imask);
1927 ieee80211_wake_queues(sc->hw);
1929 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
1930 r = ath_start_rfkill_poll(sc);
1935 static int ath9k_tx(struct ieee80211_hw *hw,
1936 struct sk_buff *skb)
1938 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1939 struct ath_softc *sc = hw->priv;
1940 struct ath_tx_control txctl;
1941 int hdrlen, padsize;
1943 memset(&txctl, 0, sizeof(struct ath_tx_control));
1946 * As a temporary workaround, assign seq# here; this will likely need
1947 * to be cleaned up to work better with Beacon transmission and virtual
1950 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1951 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1952 if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
1953 sc->tx.seq_no += 0x10;
1954 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
1955 hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no);
1958 /* Add the padding after the header if this is not already done */
1959 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
1961 padsize = hdrlen % 4;
1962 if (skb_headroom(skb) < padsize)
1964 skb_push(skb, padsize);
1965 memmove(skb->data, skb->data + padsize, hdrlen);
1968 /* Check if a tx queue is available */
1970 txctl.txq = ath_test_get_txq(sc, skb);
1974 DPRINTF(sc, ATH_DBG_XMIT, "transmitting packet, skb: %p\n", skb);
1976 if (ath_tx_start(sc, skb, &txctl) != 0) {
1977 DPRINTF(sc, ATH_DBG_XMIT, "TX failed\n");
1983 dev_kfree_skb_any(skb);
1987 static void ath9k_stop(struct ieee80211_hw *hw)
1989 struct ath_softc *sc = hw->priv;
1991 if (sc->sc_flags & SC_OP_INVALID) {
1992 DPRINTF(sc, ATH_DBG_ANY, "Device not present\n");
1996 DPRINTF(sc, ATH_DBG_CONFIG, "Cleaning up\n");
1998 ieee80211_stop_queues(sc->hw);
2000 /* make sure h/w will not generate any interrupt
2001 * before setting the invalid flag. */
2002 ath9k_hw_set_interrupts(sc->sc_ah, 0);
2004 if (!(sc->sc_flags & SC_OP_INVALID)) {
2005 ath_drain_all_txq(sc, false);
2007 ath9k_hw_phy_disable(sc->sc_ah);
2009 sc->rx.rxlink = NULL;
2011 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
2012 if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
2013 cancel_delayed_work_sync(&sc->rf_kill.rfkill_poll);
2015 /* disable HAL and put h/w to sleep */
2016 ath9k_hw_disable(sc->sc_ah);
2017 ath9k_hw_configpcipowersave(sc->sc_ah, 1);
2019 sc->sc_flags |= SC_OP_INVALID;
2021 DPRINTF(sc, ATH_DBG_CONFIG, "Driver halt\n");
2024 static int ath9k_add_interface(struct ieee80211_hw *hw,
2025 struct ieee80211_if_init_conf *conf)
2027 struct ath_softc *sc = hw->priv;
2028 struct ath_vap *avp = (void *)conf->vif->drv_priv;
2029 enum nl80211_iftype ic_opmode = NL80211_IFTYPE_UNSPECIFIED;
2031 /* Support only vap for now */
2036 switch (conf->type) {
2037 case NL80211_IFTYPE_STATION:
2038 ic_opmode = NL80211_IFTYPE_STATION;
2040 case NL80211_IFTYPE_ADHOC:
2041 ic_opmode = NL80211_IFTYPE_ADHOC;
2043 case NL80211_IFTYPE_AP:
2044 ic_opmode = NL80211_IFTYPE_AP;
2047 DPRINTF(sc, ATH_DBG_FATAL,
2048 "Interface type %d not yet supported\n", conf->type);
2052 DPRINTF(sc, ATH_DBG_CONFIG, "Attach a VAP of type: %d\n", ic_opmode);
2054 /* Set the VAP opmode */
2055 avp->av_opmode = ic_opmode;
2058 if (ic_opmode == NL80211_IFTYPE_AP)
2059 ath9k_hw_set_tsfadjust(sc->sc_ah, 1);
2061 sc->sc_vaps[0] = conf->vif;
2064 /* Set the device opmode */
2065 sc->sc_ah->ah_opmode = ic_opmode;
2067 if (conf->type == NL80211_IFTYPE_AP) {
2068 /* TODO: is this a suitable place to start ANI for AP mode? */
2070 mod_timer(&sc->sc_ani.timer,
2071 jiffies + msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
2077 static void ath9k_remove_interface(struct ieee80211_hw *hw,
2078 struct ieee80211_if_init_conf *conf)
2080 struct ath_softc *sc = hw->priv;
2081 struct ath_vap *avp = (void *)conf->vif->drv_priv;
2083 DPRINTF(sc, ATH_DBG_CONFIG, "Detach Interface\n");
2086 del_timer_sync(&sc->sc_ani.timer);
2088 /* Reclaim beacon resources */
2089 if (sc->sc_ah->ah_opmode == NL80211_IFTYPE_AP ||
2090 sc->sc_ah->ah_opmode == NL80211_IFTYPE_ADHOC) {
2091 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
2092 ath_beacon_return(sc, avp);
2095 sc->sc_flags &= ~SC_OP_BEACONS;
2097 sc->sc_vaps[0] = NULL;
2101 static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
2103 struct ath_softc *sc = hw->priv;
2104 struct ieee80211_conf *conf = &hw->conf;
2106 mutex_lock(&sc->mutex);
2107 if (changed & IEEE80211_CONF_CHANGE_PS) {
2108 if (conf->flags & IEEE80211_CONF_PS) {
2109 if ((sc->sc_imask & ATH9K_INT_TIM_TIMER) == 0) {
2110 sc->sc_imask |= ATH9K_INT_TIM_TIMER;
2111 ath9k_hw_set_interrupts(sc->sc_ah,
2114 ath9k_hw_setrxabort(sc->sc_ah, 1);
2115 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_NETWORK_SLEEP);
2117 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
2118 ath9k_hw_setrxabort(sc->sc_ah, 0);
2119 sc->sc_flags &= ~SC_OP_WAIT_FOR_BEACON;
2120 if (sc->sc_imask & ATH9K_INT_TIM_TIMER) {
2121 sc->sc_imask &= ~ATH9K_INT_TIM_TIMER;
2122 ath9k_hw_set_interrupts(sc->sc_ah,
2128 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
2129 struct ieee80211_channel *curchan = hw->conf.channel;
2132 DPRINTF(sc, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
2133 curchan->center_freq);
2135 pos = ath_get_channel(sc, curchan);
2137 DPRINTF(sc, ATH_DBG_FATAL, "Invalid channel: %d\n",
2138 curchan->center_freq);
2139 mutex_unlock(&sc->mutex);
2143 sc->tx_chan_width = ATH9K_HT_MACMODE_20;
2144 sc->sc_ah->ah_channels[pos].chanmode =
2145 (curchan->band == IEEE80211_BAND_2GHZ) ?
2146 CHANNEL_G : CHANNEL_A;
2148 if (conf_is_ht(conf)) {
2149 if (conf_is_ht40(conf))
2150 sc->tx_chan_width = ATH9K_HT_MACMODE_2040;
2152 sc->sc_ah->ah_channels[pos].chanmode =
2153 ath_get_extchanmode(sc, curchan,
2154 conf->channel_type);
2157 ath_update_chainmask(sc, conf_is_ht(conf));
2159 if (ath_set_channel(sc, &sc->sc_ah->ah_channels[pos]) < 0) {
2160 DPRINTF(sc, ATH_DBG_FATAL, "Unable to set channel\n");
2161 mutex_unlock(&sc->mutex);
2166 if (changed & IEEE80211_CONF_CHANGE_POWER)
2167 sc->sc_config.txpowlimit = 2 * conf->power_level;
2169 mutex_unlock(&sc->mutex);
2173 static int ath9k_config_interface(struct ieee80211_hw *hw,
2174 struct ieee80211_vif *vif,
2175 struct ieee80211_if_conf *conf)
2177 struct ath_softc *sc = hw->priv;
2178 struct ath_hal *ah = sc->sc_ah;
2179 struct ath_vap *avp = (void *)vif->drv_priv;
2183 /* TODO: Need to decide which hw opmode to use for multi-interface
2185 if (vif->type == NL80211_IFTYPE_AP &&
2186 ah->ah_opmode != NL80211_IFTYPE_AP) {
2187 ah->ah_opmode = NL80211_IFTYPE_STATION;
2188 ath9k_hw_setopmode(ah);
2189 ath9k_hw_write_associd(ah, sc->sc_myaddr, 0);
2190 /* Request full reset to get hw opmode changed properly */
2191 sc->sc_flags |= SC_OP_FULL_RESET;
2194 if ((conf->changed & IEEE80211_IFCC_BSSID) &&
2195 !is_zero_ether_addr(conf->bssid)) {
2196 switch (vif->type) {
2197 case NL80211_IFTYPE_STATION:
2198 case NL80211_IFTYPE_ADHOC:
2200 memcpy(sc->sc_curbssid, conf->bssid, ETH_ALEN);
2202 ath9k_hw_write_associd(sc->sc_ah, sc->sc_curbssid,
2205 /* Set aggregation protection mode parameters */
2206 sc->sc_config.ath_aggr_prot = 0;
2208 DPRINTF(sc, ATH_DBG_CONFIG,
2209 "RX filter 0x%x bssid %pM aid 0x%x\n",
2210 rfilt, sc->sc_curbssid, sc->sc_curaid);
2212 /* need to reconfigure the beacon */
2213 sc->sc_flags &= ~SC_OP_BEACONS ;
2221 if ((conf->changed & IEEE80211_IFCC_BEACON) &&
2222 ((vif->type == NL80211_IFTYPE_ADHOC) ||
2223 (vif->type == NL80211_IFTYPE_AP))) {
2225 * Allocate and setup the beacon frame.
2227 * Stop any previous beacon DMA. This may be
2228 * necessary, for example, when an ibss merge
2229 * causes reconfiguration; we may be called
2230 * with beacon transmission active.
2232 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
2234 error = ath_beacon_alloc(sc, 0);
2238 ath_beacon_sync(sc, 0);
2241 /* Check for WLAN_CAPABILITY_PRIVACY ? */
2242 if ((avp->av_opmode != NL80211_IFTYPE_STATION)) {
2243 for (i = 0; i < IEEE80211_WEP_NKID; i++)
2244 if (ath9k_hw_keyisvalid(sc->sc_ah, (u16)i))
2245 ath9k_hw_keysetmac(sc->sc_ah,
2250 /* Only legacy IBSS for now */
2251 if (vif->type == NL80211_IFTYPE_ADHOC)
2252 ath_update_chainmask(sc, 0);
2257 #define SUPPORTED_FILTERS \
2258 (FIF_PROMISC_IN_BSS | \
2262 FIF_BCN_PRBRESP_PROMISC | \
2265 /* FIXME: sc->sc_full_reset ? */
2266 static void ath9k_configure_filter(struct ieee80211_hw *hw,
2267 unsigned int changed_flags,
2268 unsigned int *total_flags,
2270 struct dev_mc_list *mclist)
2272 struct ath_softc *sc = hw->priv;
2275 changed_flags &= SUPPORTED_FILTERS;
2276 *total_flags &= SUPPORTED_FILTERS;
2278 sc->rx.rxfilter = *total_flags;
2279 rfilt = ath_calcrxfilter(sc);
2280 ath9k_hw_setrxfilter(sc->sc_ah, rfilt);
2282 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
2283 if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
2284 ath9k_hw_write_associd(sc->sc_ah, ath_bcast_mac, 0);
2287 DPRINTF(sc, ATH_DBG_CONFIG, "Set HW RX filter: 0x%x\n", sc->rx.rxfilter);
2290 static void ath9k_sta_notify(struct ieee80211_hw *hw,
2291 struct ieee80211_vif *vif,
2292 enum sta_notify_cmd cmd,
2293 struct ieee80211_sta *sta)
2295 struct ath_softc *sc = hw->priv;
2298 case STA_NOTIFY_ADD:
2299 ath_node_attach(sc, sta);
2301 case STA_NOTIFY_REMOVE:
2302 ath_node_detach(sc, sta);
2309 static int ath9k_conf_tx(struct ieee80211_hw *hw,
2311 const struct ieee80211_tx_queue_params *params)
2313 struct ath_softc *sc = hw->priv;
2314 struct ath9k_tx_queue_info qi;
2317 if (queue >= WME_NUM_AC)
2320 qi.tqi_aifs = params->aifs;
2321 qi.tqi_cwmin = params->cw_min;
2322 qi.tqi_cwmax = params->cw_max;
2323 qi.tqi_burstTime = params->txop;
2324 qnum = ath_get_hal_qnum(queue, sc);
2326 DPRINTF(sc, ATH_DBG_CONFIG,
2327 "Configure tx [queue/halq] [%d/%d], "
2328 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
2329 queue, qnum, params->aifs, params->cw_min,
2330 params->cw_max, params->txop);
2332 ret = ath_txq_update(sc, qnum, &qi);
2334 DPRINTF(sc, ATH_DBG_FATAL, "TXQ Update failed\n");
2339 static int ath9k_set_key(struct ieee80211_hw *hw,
2340 enum set_key_cmd cmd,
2341 struct ieee80211_vif *vif,
2342 struct ieee80211_sta *sta,
2343 struct ieee80211_key_conf *key)
2345 struct ath_softc *sc = hw->priv;
2348 ath9k_ps_wakeup(sc);
2349 DPRINTF(sc, ATH_DBG_KEYCACHE, "Set HW Key\n");
2353 ret = ath_key_config(sc, sta, key);
2355 key->hw_key_idx = ret;
2356 /* push IV and Michael MIC generation to stack */
2357 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
2358 if (key->alg == ALG_TKIP)
2359 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
2360 if (sc->sc_ah->sw_mgmt_crypto && key->alg == ALG_CCMP)
2361 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
2366 ath_key_delete(sc, key);
2372 ath9k_ps_restore(sc);
2376 static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
2377 struct ieee80211_vif *vif,
2378 struct ieee80211_bss_conf *bss_conf,
2381 struct ath_softc *sc = hw->priv;
2383 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2384 DPRINTF(sc, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
2385 bss_conf->use_short_preamble);
2386 if (bss_conf->use_short_preamble)
2387 sc->sc_flags |= SC_OP_PREAMBLE_SHORT;
2389 sc->sc_flags &= ~SC_OP_PREAMBLE_SHORT;
2392 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
2393 DPRINTF(sc, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
2394 bss_conf->use_cts_prot);
2395 if (bss_conf->use_cts_prot &&
2396 hw->conf.channel->band != IEEE80211_BAND_5GHZ)
2397 sc->sc_flags |= SC_OP_PROTECT_ENABLE;
2399 sc->sc_flags &= ~SC_OP_PROTECT_ENABLE;
2402 if (changed & BSS_CHANGED_ASSOC) {
2403 DPRINTF(sc, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
2405 ath9k_bss_assoc_info(sc, vif, bss_conf);
2409 static u64 ath9k_get_tsf(struct ieee80211_hw *hw)
2412 struct ath_softc *sc = hw->priv;
2413 struct ath_hal *ah = sc->sc_ah;
2415 tsf = ath9k_hw_gettsf64(ah);
2420 static void ath9k_reset_tsf(struct ieee80211_hw *hw)
2422 struct ath_softc *sc = hw->priv;
2423 struct ath_hal *ah = sc->sc_ah;
2425 ath9k_hw_reset_tsf(ah);
2428 static int ath9k_ampdu_action(struct ieee80211_hw *hw,
2429 enum ieee80211_ampdu_mlme_action action,
2430 struct ieee80211_sta *sta,
2433 struct ath_softc *sc = hw->priv;
2437 case IEEE80211_AMPDU_RX_START:
2438 if (!(sc->sc_flags & SC_OP_RXAGGR))
2441 case IEEE80211_AMPDU_RX_STOP:
2443 case IEEE80211_AMPDU_TX_START:
2444 ret = ath_tx_aggr_start(sc, sta, tid, ssn);
2446 DPRINTF(sc, ATH_DBG_FATAL,
2447 "Unable to start TX aggregation\n");
2449 ieee80211_start_tx_ba_cb_irqsafe(hw, sta->addr, tid);
2451 case IEEE80211_AMPDU_TX_STOP:
2452 ret = ath_tx_aggr_stop(sc, sta, tid);
2454 DPRINTF(sc, ATH_DBG_FATAL,
2455 "Unable to stop TX aggregation\n");
2457 ieee80211_stop_tx_ba_cb_irqsafe(hw, sta->addr, tid);
2459 case IEEE80211_AMPDU_TX_RESUME:
2460 ath_tx_aggr_resume(sc, sta, tid);
2463 DPRINTF(sc, ATH_DBG_FATAL, "Unknown AMPDU action\n");
2469 struct ieee80211_ops ath9k_ops = {
2471 .start = ath9k_start,
2473 .add_interface = ath9k_add_interface,
2474 .remove_interface = ath9k_remove_interface,
2475 .config = ath9k_config,
2476 .config_interface = ath9k_config_interface,
2477 .configure_filter = ath9k_configure_filter,
2478 .sta_notify = ath9k_sta_notify,
2479 .conf_tx = ath9k_conf_tx,
2480 .bss_info_changed = ath9k_bss_info_changed,
2481 .set_key = ath9k_set_key,
2482 .get_tsf = ath9k_get_tsf,
2483 .reset_tsf = ath9k_reset_tsf,
2484 .ampdu_action = ath9k_ampdu_action,
2490 } ath_mac_bb_names[] = {
2491 { AR_SREV_VERSION_5416_PCI, "5416" },
2492 { AR_SREV_VERSION_5416_PCIE, "5418" },
2493 { AR_SREV_VERSION_9100, "9100" },
2494 { AR_SREV_VERSION_9160, "9160" },
2495 { AR_SREV_VERSION_9280, "9280" },
2496 { AR_SREV_VERSION_9285, "9285" }
2502 } ath_rf_names[] = {
2504 { AR_RAD5133_SREV_MAJOR, "5133" },
2505 { AR_RAD5122_SREV_MAJOR, "5122" },
2506 { AR_RAD2133_SREV_MAJOR, "2133" },
2507 { AR_RAD2122_SREV_MAJOR, "2122" }
2511 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
2514 ath_mac_bb_name(u32 mac_bb_version)
2518 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
2519 if (ath_mac_bb_names[i].version == mac_bb_version) {
2520 return ath_mac_bb_names[i].name;
2528 * Return the RF name. "????" is returned if the RF is unknown.
2531 ath_rf_name(u16 rf_version)
2535 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
2536 if (ath_rf_names[i].version == rf_version) {
2537 return ath_rf_names[i].name;
2544 static int __init ath9k_init(void)
2548 printk(KERN_INFO "%s: %s\n", dev_info, ATH_PCI_VERSION);
2550 /* Register rate control algorithm */
2551 error = ath_rate_control_register();
2554 "Unable to register rate control algorithm: %d\n",
2559 error = ath_pci_init();
2562 "ath_pci: No devices found, driver not installed.\n");
2564 goto err_rate_unregister;
2567 error = ath_ahb_init();
2578 err_rate_unregister:
2579 ath_rate_control_unregister();
2583 module_init(ath9k_init);
2585 static void __exit ath9k_exit(void)
2589 ath_rate_control_unregister();
2590 printk(KERN_INFO "%s: Driver unloaded\n", dev_info);
2592 module_exit(ath9k_exit);