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 /* mac80211 and PCI callbacks */
19 #include <linux/nl80211.h>
22 #define ATH_PCI_VERSION "0.1"
24 #define IEEE80211_HTCAP_MAXRXAMPDU_FACTOR 13
26 static char *dev_info = "ath9k";
28 MODULE_AUTHOR("Atheros Communications");
29 MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
30 MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
31 MODULE_LICENSE("Dual BSD/GPL");
33 static struct pci_device_id ath_pci_id_table[] __devinitdata = {
34 { PCI_VDEVICE(ATHEROS, 0x0023) }, /* PCI */
35 { PCI_VDEVICE(ATHEROS, 0x0024) }, /* PCI-E */
36 { PCI_VDEVICE(ATHEROS, 0x0027) }, /* PCI */
37 { PCI_VDEVICE(ATHEROS, 0x0029) }, /* PCI */
38 { PCI_VDEVICE(ATHEROS, 0x002A) }, /* PCI-E */
42 static int ath_get_channel(struct ath_softc *sc,
43 struct ieee80211_channel *chan)
47 for (i = 0; i < sc->sc_ah->ah_nchan; i++) {
48 if (sc->sc_ah->ah_channels[i].channel == chan->center_freq)
55 static u32 ath_get_extchanmode(struct ath_softc *sc,
56 struct ieee80211_channel *chan)
59 u8 ext_chan_offset = sc->sc_ht_info.ext_chan_offset;
60 enum ath9k_ht_macmode tx_chan_width = sc->sc_ht_info.tx_chan_width;
63 case IEEE80211_BAND_2GHZ:
64 if ((ext_chan_offset == IEEE80211_HT_IE_CHA_SEC_NONE) &&
65 (tx_chan_width == ATH9K_HT_MACMODE_20))
66 chanmode = CHANNEL_G_HT20;
67 if ((ext_chan_offset == IEEE80211_HT_IE_CHA_SEC_ABOVE) &&
68 (tx_chan_width == ATH9K_HT_MACMODE_2040))
69 chanmode = CHANNEL_G_HT40PLUS;
70 if ((ext_chan_offset == IEEE80211_HT_IE_CHA_SEC_BELOW) &&
71 (tx_chan_width == ATH9K_HT_MACMODE_2040))
72 chanmode = CHANNEL_G_HT40MINUS;
74 case IEEE80211_BAND_5GHZ:
75 if ((ext_chan_offset == IEEE80211_HT_IE_CHA_SEC_NONE) &&
76 (tx_chan_width == ATH9K_HT_MACMODE_20))
77 chanmode = CHANNEL_A_HT20;
78 if ((ext_chan_offset == IEEE80211_HT_IE_CHA_SEC_ABOVE) &&
79 (tx_chan_width == ATH9K_HT_MACMODE_2040))
80 chanmode = CHANNEL_A_HT40PLUS;
81 if ((ext_chan_offset == IEEE80211_HT_IE_CHA_SEC_BELOW) &&
82 (tx_chan_width == ATH9K_HT_MACMODE_2040))
83 chanmode = CHANNEL_A_HT40MINUS;
93 static int ath_setkey_tkip(struct ath_softc *sc,
94 struct ieee80211_key_conf *key,
95 struct ath9k_keyval *hk,
101 key_txmic = key->key + NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY;
102 key_rxmic = key->key + NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY;
105 /* Group key installation */
106 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
107 return ath_keyset(sc, key->keyidx, hk, addr);
109 if (!sc->sc_splitmic) {
111 * data key goes at first index,
112 * the hal handles the MIC keys at index+64.
114 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
115 memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_txmic));
116 return ath_keyset(sc, key->keyidx, hk, addr);
119 * TX key goes at first index, RX key at +32.
120 * The hal handles the MIC keys at index+64.
122 memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
123 if (!ath_keyset(sc, key->keyidx, hk, NULL)) {
124 /* Txmic entry failed. No need to proceed further */
125 DPRINTF(sc, ATH_DBG_KEYCACHE,
126 "%s Setting TX MIC Key Failed\n", __func__);
130 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
131 /* XXX delete tx key on failure? */
132 return ath_keyset(sc, key->keyidx+32, hk, addr);
135 static int ath_key_config(struct ath_softc *sc,
137 struct ieee80211_key_conf *key)
139 struct ieee80211_vif *vif;
140 struct ath9k_keyval hk;
141 const u8 *mac = NULL;
143 enum nl80211_iftype opmode;
145 memset(&hk, 0, sizeof(hk));
149 hk.kv_type = ATH9K_CIPHER_WEP;
152 hk.kv_type = ATH9K_CIPHER_TKIP;
155 hk.kv_type = ATH9K_CIPHER_AES_CCM;
161 hk.kv_len = key->keylen;
162 memcpy(hk.kv_val, key->key, key->keylen);
167 vif = sc->sc_vaps[0]->av_if_data;
172 * For _M_STA mc tx, we will not setup a key at all since we never
174 * _M_STA mc rx, we will use the keyID.
175 * for _M_IBSS mc tx, we will use the keyID, and no macaddr.
176 * for _M_IBSS mc rx, we will alloc a slot and plumb the mac of the
177 * peer node. BUT we will plumb a cleartext key so that we can do
178 * perSta default key table lookup in software.
180 if (is_broadcast_ether_addr(addr)) {
182 case NL80211_IFTYPE_STATION:
183 /* default key: could be group WPA key
184 * or could be static WEP key */
187 case NL80211_IFTYPE_ADHOC:
189 case NL80211_IFTYPE_AP:
199 if (key->alg == ALG_TKIP)
200 ret = ath_setkey_tkip(sc, key, &hk, mac);
202 ret = ath_keyset(sc, key->keyidx, &hk, mac);
208 sc->sc_keytype = hk.kv_type;
212 static void ath_key_delete(struct ath_softc *sc, struct ieee80211_key_conf *key)
216 freeslot = (key->keyidx >= 4) ? 1 : 0;
217 ath_key_reset(sc, key->keyidx, freeslot);
220 static void setup_ht_cap(struct ieee80211_ht_info *ht_info)
222 #define ATH9K_HT_CAP_MAXRXAMPDU_65536 0x3 /* 2 ^ 16 */
223 #define ATH9K_HT_CAP_MPDUDENSITY_8 0x6 /* 8 usec */
225 ht_info->ht_supported = 1;
226 ht_info->cap = (u16)IEEE80211_HT_CAP_SUP_WIDTH
227 |(u16)IEEE80211_HT_CAP_SM_PS
228 |(u16)IEEE80211_HT_CAP_SGI_40
229 |(u16)IEEE80211_HT_CAP_DSSSCCK40;
231 ht_info->ampdu_factor = ATH9K_HT_CAP_MAXRXAMPDU_65536;
232 ht_info->ampdu_density = ATH9K_HT_CAP_MPDUDENSITY_8;
233 /* setup supported mcs set */
234 memset(ht_info->supp_mcs_set, 0, 16);
235 ht_info->supp_mcs_set[0] = 0xff;
236 ht_info->supp_mcs_set[1] = 0xff;
237 ht_info->supp_mcs_set[12] = IEEE80211_HT_CAP_MCS_TX_DEFINED;
240 static int ath_rate2idx(struct ath_softc *sc, int rate)
242 int i = 0, cur_band, n_rates;
243 struct ieee80211_hw *hw = sc->hw;
245 cur_band = hw->conf.channel->band;
246 n_rates = sc->sbands[cur_band].n_bitrates;
248 for (i = 0; i < n_rates; i++) {
249 if (sc->sbands[cur_band].bitrates[i].bitrate == rate)
254 * NB:mac80211 validates rx rate index against the supported legacy rate
255 * index only (should be done against ht rates also), return the highest
256 * legacy rate index for rx rate which does not match any one of the
257 * supported basic and extended rates to make mac80211 happy.
258 * The following hack will be cleaned up once the issue with
259 * the rx rate index validation in mac80211 is fixed.
266 static void ath9k_rx_prepare(struct ath_softc *sc,
268 struct ath_recv_status *status,
269 struct ieee80211_rx_status *rx_status)
271 struct ieee80211_hw *hw = sc->hw;
272 struct ieee80211_channel *curchan = hw->conf.channel;
274 memset(rx_status, 0, sizeof(struct ieee80211_rx_status));
276 rx_status->mactime = status->tsf;
277 rx_status->band = curchan->band;
278 rx_status->freq = curchan->center_freq;
279 rx_status->noise = ATH_DEFAULT_NOISE_FLOOR;
280 rx_status->signal = rx_status->noise + status->rssi;
281 rx_status->rate_idx = ath_rate2idx(sc, (status->rateKbps / 100));
282 rx_status->antenna = status->antenna;
283 rx_status->qual = status->rssi * 100 / 64;
285 if (status->flags & ATH_RX_MIC_ERROR)
286 rx_status->flag |= RX_FLAG_MMIC_ERROR;
287 if (status->flags & ATH_RX_FCS_ERROR)
288 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
290 rx_status->flag |= RX_FLAG_TSFT;
293 static u8 parse_mpdudensity(u8 mpdudensity)
296 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
297 * 0 for no restriction
306 switch (mpdudensity) {
312 /* Our lower layer calculations limit our precision to
328 static void ath9k_ht_conf(struct ath_softc *sc,
329 struct ieee80211_bss_conf *bss_conf)
331 #define IEEE80211_HT_CAP_40MHZ_INTOLERANT BIT(14)
332 struct ath_ht_info *ht_info = &sc->sc_ht_info;
334 if (bss_conf->assoc_ht) {
335 ht_info->ext_chan_offset =
336 bss_conf->ht_bss_conf->bss_cap &
337 IEEE80211_HT_IE_CHA_SEC_OFFSET;
339 if (!(bss_conf->ht_conf->cap &
340 IEEE80211_HT_CAP_40MHZ_INTOLERANT) &&
341 (bss_conf->ht_bss_conf->bss_cap &
342 IEEE80211_HT_IE_CHA_WIDTH))
343 ht_info->tx_chan_width = ATH9K_HT_MACMODE_2040;
345 ht_info->tx_chan_width = ATH9K_HT_MACMODE_20;
347 ath9k_hw_set11nmac2040(sc->sc_ah, ht_info->tx_chan_width);
348 ht_info->maxampdu = 1 << (IEEE80211_HTCAP_MAXRXAMPDU_FACTOR +
349 bss_conf->ht_conf->ampdu_factor);
350 ht_info->mpdudensity =
351 parse_mpdudensity(bss_conf->ht_conf->ampdu_density);
355 #undef IEEE80211_HT_CAP_40MHZ_INTOLERANT
358 static void ath9k_bss_assoc_info(struct ath_softc *sc,
359 struct ieee80211_bss_conf *bss_conf)
361 struct ieee80211_hw *hw = sc->hw;
362 struct ieee80211_channel *curchan = hw->conf.channel;
365 DECLARE_MAC_BUF(mac);
367 if (bss_conf->assoc) {
368 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Bss Info ASSOC %d\n",
372 avp = sc->sc_vaps[0];
374 DPRINTF(sc, ATH_DBG_FATAL, "%s: Invalid interface\n",
379 /* New association, store aid */
380 if (avp->av_opmode == ATH9K_M_STA) {
381 sc->sc_curaid = bss_conf->aid;
382 ath9k_hw_write_associd(sc->sc_ah, sc->sc_curbssid,
386 /* Configure the beacon */
387 ath_beacon_config(sc, 0);
388 sc->sc_flags |= SC_OP_BEACONS;
390 /* Reset rssi stats */
391 sc->sc_halstats.ns_avgbrssi = ATH_RSSI_DUMMY_MARKER;
392 sc->sc_halstats.ns_avgrssi = ATH_RSSI_DUMMY_MARKER;
393 sc->sc_halstats.ns_avgtxrssi = ATH_RSSI_DUMMY_MARKER;
394 sc->sc_halstats.ns_avgtxrate = ATH_RATE_DUMMY_MARKER;
396 /* Update chainmask */
397 ath_update_chainmask(sc, bss_conf->assoc_ht);
399 DPRINTF(sc, ATH_DBG_CONFIG,
400 "%s: bssid %s aid 0x%x\n",
402 print_mac(mac, sc->sc_curbssid), sc->sc_curaid);
404 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Set channel: %d MHz\n",
406 curchan->center_freq);
408 pos = ath_get_channel(sc, curchan);
410 DPRINTF(sc, ATH_DBG_FATAL,
411 "%s: Invalid channel\n", __func__);
415 if (hw->conf.ht_conf.ht_supported)
416 sc->sc_ah->ah_channels[pos].chanmode =
417 ath_get_extchanmode(sc, curchan);
419 sc->sc_ah->ah_channels[pos].chanmode =
420 (curchan->band == IEEE80211_BAND_2GHZ) ?
421 CHANNEL_G : CHANNEL_A;
423 /* set h/w channel */
424 if (ath_set_channel(sc, &sc->sc_ah->ah_channels[pos]) < 0)
425 DPRINTF(sc, ATH_DBG_FATAL,
426 "%s: Unable to set channel\n",
429 ath_rate_newstate(sc, avp);
430 /* Update ratectrl about the new state */
431 ath_rc_node_update(hw, avp->rc_node);
433 DPRINTF(sc, ATH_DBG_CONFIG,
434 "%s: Bss Info DISSOC\n", __func__);
439 void ath_get_beaconconfig(struct ath_softc *sc,
441 struct ath_beacon_config *conf)
443 struct ieee80211_hw *hw = sc->hw;
445 /* fill in beacon config data */
447 conf->beacon_interval = hw->conf.beacon_int;
448 conf->listen_interval = 100;
449 conf->dtim_count = 1;
450 conf->bmiss_timeout = ATH_DEFAULT_BMISS_LIMIT * conf->listen_interval;
453 void ath_tx_complete(struct ath_softc *sc, struct sk_buff *skb,
454 struct ath_xmit_status *tx_status, struct ath_node *an)
456 struct ieee80211_hw *hw = sc->hw;
457 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
459 DPRINTF(sc, ATH_DBG_XMIT,
460 "%s: TX complete: skb: %p\n", __func__, skb);
462 if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK ||
463 tx_info->flags & IEEE80211_TX_STAT_TX_FILTERED) {
464 /* free driver's private data area of tx_info */
465 if (tx_info->driver_data[0] != NULL)
466 kfree(tx_info->driver_data[0]);
467 tx_info->driver_data[0] = NULL;
470 if (tx_status->flags & ATH_TX_BAR) {
471 tx_info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
472 tx_status->flags &= ~ATH_TX_BAR;
475 if (tx_status->flags & (ATH_TX_ERROR | ATH_TX_XRETRY)) {
476 if (!(tx_info->flags & IEEE80211_TX_CTL_NO_ACK)) {
477 /* Frame was not ACKed, but an ACK was expected */
478 tx_info->status.excessive_retries = 1;
481 /* Frame was ACKed */
482 tx_info->flags |= IEEE80211_TX_STAT_ACK;
485 tx_info->status.retry_count = tx_status->retries;
487 ieee80211_tx_status(hw, skb);
489 ath_node_put(sc, an, ATH9K_BH_STATUS_CHANGE);
492 int _ath_rx_indicate(struct ath_softc *sc,
494 struct ath_recv_status *status,
497 struct ieee80211_hw *hw = sc->hw;
498 struct ath_node *an = NULL;
499 struct ieee80211_rx_status rx_status;
500 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
501 int hdrlen = ieee80211_get_hdrlen_from_skb(skb);
505 /* see if any padding is done by the hw and remove it */
507 padsize = hdrlen % 4;
508 memmove(skb->data + padsize, skb->data, hdrlen);
509 skb_pull(skb, padsize);
512 /* Prepare rx status */
513 ath9k_rx_prepare(sc, skb, status, &rx_status);
515 if (!(keyix == ATH9K_RXKEYIX_INVALID) &&
516 !(status->flags & ATH_RX_DECRYPT_ERROR)) {
517 rx_status.flag |= RX_FLAG_DECRYPTED;
518 } else if ((le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_PROTECTED)
519 && !(status->flags & ATH_RX_DECRYPT_ERROR)
520 && skb->len >= hdrlen + 4) {
521 keyix = skb->data[hdrlen + 3] >> 6;
523 if (test_bit(keyix, sc->sc_keymap))
524 rx_status.flag |= RX_FLAG_DECRYPTED;
527 spin_lock_bh(&sc->node_lock);
528 an = ath_node_find(sc, hdr->addr2);
529 spin_unlock_bh(&sc->node_lock);
533 hw->conf.ht_conf.ht_supported,
536 if (!an || (st != ATH_RX_CONSUMED))
537 __ieee80211_rx(hw, skb, &rx_status);
542 int ath_rx_subframe(struct ath_node *an,
544 struct ath_recv_status *status)
546 struct ath_softc *sc = an->an_sc;
547 struct ieee80211_hw *hw = sc->hw;
548 struct ieee80211_rx_status rx_status;
550 /* Prepare rx status */
551 ath9k_rx_prepare(sc, skb, status, &rx_status);
552 if (!(status->flags & ATH_RX_DECRYPT_ERROR))
553 rx_status.flag |= RX_FLAG_DECRYPTED;
555 __ieee80211_rx(hw, skb, &rx_status);
560 /********************************/
562 /********************************/
564 static void ath_led_brightness(struct led_classdev *led_cdev,
565 enum led_brightness brightness)
567 struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev);
568 struct ath_softc *sc = led->sc;
570 switch (brightness) {
572 if (led->led_type == ATH_LED_ASSOC ||
573 led->led_type == ATH_LED_RADIO)
574 sc->sc_flags &= ~SC_OP_LED_ASSOCIATED;
575 ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN,
576 (led->led_type == ATH_LED_RADIO) ? 1 :
577 !!(sc->sc_flags & SC_OP_LED_ASSOCIATED));
580 if (led->led_type == ATH_LED_ASSOC)
581 sc->sc_flags |= SC_OP_LED_ASSOCIATED;
582 ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 0);
589 static int ath_register_led(struct ath_softc *sc, struct ath_led *led,
595 led->led_cdev.name = led->name;
596 led->led_cdev.default_trigger = trigger;
597 led->led_cdev.brightness_set = ath_led_brightness;
599 ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &led->led_cdev);
601 DPRINTF(sc, ATH_DBG_FATAL,
602 "Failed to register led:%s", led->name);
608 static void ath_unregister_led(struct ath_led *led)
610 if (led->registered) {
611 led_classdev_unregister(&led->led_cdev);
616 static void ath_deinit_leds(struct ath_softc *sc)
618 ath_unregister_led(&sc->assoc_led);
619 sc->sc_flags &= ~SC_OP_LED_ASSOCIATED;
620 ath_unregister_led(&sc->tx_led);
621 ath_unregister_led(&sc->rx_led);
622 ath_unregister_led(&sc->radio_led);
623 ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1);
626 static void ath_init_leds(struct ath_softc *sc)
631 /* Configure gpio 1 for output */
632 ath9k_hw_cfg_output(sc->sc_ah, ATH_LED_PIN,
633 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
634 /* LED off, active low */
635 ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1);
637 trigger = ieee80211_get_radio_led_name(sc->hw);
638 snprintf(sc->radio_led.name, sizeof(sc->radio_led.name),
639 "ath9k-%s:radio", wiphy_name(sc->hw->wiphy));
640 ret = ath_register_led(sc, &sc->radio_led, trigger);
641 sc->radio_led.led_type = ATH_LED_RADIO;
645 trigger = ieee80211_get_assoc_led_name(sc->hw);
646 snprintf(sc->assoc_led.name, sizeof(sc->assoc_led.name),
647 "ath9k-%s:assoc", wiphy_name(sc->hw->wiphy));
648 ret = ath_register_led(sc, &sc->assoc_led, trigger);
649 sc->assoc_led.led_type = ATH_LED_ASSOC;
653 trigger = ieee80211_get_tx_led_name(sc->hw);
654 snprintf(sc->tx_led.name, sizeof(sc->tx_led.name),
655 "ath9k-%s:tx", wiphy_name(sc->hw->wiphy));
656 ret = ath_register_led(sc, &sc->tx_led, trigger);
657 sc->tx_led.led_type = ATH_LED_TX;
661 trigger = ieee80211_get_rx_led_name(sc->hw);
662 snprintf(sc->rx_led.name, sizeof(sc->rx_led.name),
663 "ath9k-%s:rx", wiphy_name(sc->hw->wiphy));
664 ret = ath_register_led(sc, &sc->rx_led, trigger);
665 sc->rx_led.led_type = ATH_LED_RX;
676 /*******************/
678 /*******************/
680 static void ath_radio_enable(struct ath_softc *sc)
682 struct ath_hal *ah = sc->sc_ah;
685 spin_lock_bh(&sc->sc_resetlock);
686 if (!ath9k_hw_reset(ah, ah->ah_curchan,
687 sc->sc_ht_info.tx_chan_width,
690 sc->sc_ht_extprotspacing,
692 DPRINTF(sc, ATH_DBG_FATAL,
693 "%s: unable to reset channel %u (%uMhz) "
694 "flags 0x%x hal status %u\n", __func__,
695 ath9k_hw_mhz2ieee(ah,
696 ah->ah_curchan->channel,
697 ah->ah_curchan->channelFlags),
698 ah->ah_curchan->channel,
699 ah->ah_curchan->channelFlags, status);
701 spin_unlock_bh(&sc->sc_resetlock);
703 ath_update_txpow(sc);
704 if (ath_startrecv(sc) != 0) {
705 DPRINTF(sc, ATH_DBG_FATAL,
706 "%s: unable to restart recv logic\n", __func__);
710 if (sc->sc_flags & SC_OP_BEACONS)
711 ath_beacon_config(sc, ATH_IF_ID_ANY); /* restart beacons */
713 /* Re-Enable interrupts */
714 ath9k_hw_set_interrupts(ah, sc->sc_imask);
717 ath9k_hw_cfg_output(ah, ATH_LED_PIN,
718 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
719 ath9k_hw_set_gpio(ah, ATH_LED_PIN, 0);
721 ieee80211_wake_queues(sc->hw);
724 static void ath_radio_disable(struct ath_softc *sc)
726 struct ath_hal *ah = sc->sc_ah;
730 ieee80211_stop_queues(sc->hw);
733 ath9k_hw_set_gpio(ah, ATH_LED_PIN, 1);
734 ath9k_hw_cfg_gpio_input(ah, ATH_LED_PIN);
736 /* Disable interrupts */
737 ath9k_hw_set_interrupts(ah, 0);
739 ath_draintxq(sc, false); /* clear pending tx frames */
740 ath_stoprecv(sc); /* turn off frame recv */
741 ath_flushrecv(sc); /* flush recv queue */
743 spin_lock_bh(&sc->sc_resetlock);
744 if (!ath9k_hw_reset(ah, ah->ah_curchan,
745 sc->sc_ht_info.tx_chan_width,
748 sc->sc_ht_extprotspacing,
750 DPRINTF(sc, ATH_DBG_FATAL,
751 "%s: unable to reset channel %u (%uMhz) "
752 "flags 0x%x hal status %u\n", __func__,
753 ath9k_hw_mhz2ieee(ah,
754 ah->ah_curchan->channel,
755 ah->ah_curchan->channelFlags),
756 ah->ah_curchan->channel,
757 ah->ah_curchan->channelFlags, status);
759 spin_unlock_bh(&sc->sc_resetlock);
761 ath9k_hw_phy_disable(ah);
762 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
765 static bool ath_is_rfkill_set(struct ath_softc *sc)
767 struct ath_hal *ah = sc->sc_ah;
769 return ath9k_hw_gpio_get(ah, ah->ah_rfkill_gpio) ==
770 ah->ah_rfkill_polarity;
773 /* h/w rfkill poll function */
774 static void ath_rfkill_poll(struct work_struct *work)
776 struct ath_softc *sc = container_of(work, struct ath_softc,
777 rf_kill.rfkill_poll.work);
780 if (sc->sc_flags & SC_OP_INVALID)
783 radio_on = !ath_is_rfkill_set(sc);
786 * enable/disable radio only when there is a
787 * state change in RF switch
789 if (radio_on == !!(sc->sc_flags & SC_OP_RFKILL_HW_BLOCKED)) {
790 enum rfkill_state state;
792 if (sc->sc_flags & SC_OP_RFKILL_SW_BLOCKED) {
793 state = radio_on ? RFKILL_STATE_SOFT_BLOCKED
794 : RFKILL_STATE_HARD_BLOCKED;
795 } else if (radio_on) {
796 ath_radio_enable(sc);
797 state = RFKILL_STATE_UNBLOCKED;
799 ath_radio_disable(sc);
800 state = RFKILL_STATE_HARD_BLOCKED;
803 if (state == RFKILL_STATE_HARD_BLOCKED)
804 sc->sc_flags |= SC_OP_RFKILL_HW_BLOCKED;
806 sc->sc_flags &= ~SC_OP_RFKILL_HW_BLOCKED;
808 rfkill_force_state(sc->rf_kill.rfkill, state);
811 queue_delayed_work(sc->hw->workqueue, &sc->rf_kill.rfkill_poll,
812 msecs_to_jiffies(ATH_RFKILL_POLL_INTERVAL));
815 /* s/w rfkill handler */
816 static int ath_sw_toggle_radio(void *data, enum rfkill_state state)
818 struct ath_softc *sc = data;
821 case RFKILL_STATE_SOFT_BLOCKED:
822 if (!(sc->sc_flags & (SC_OP_RFKILL_HW_BLOCKED |
823 SC_OP_RFKILL_SW_BLOCKED)))
824 ath_radio_disable(sc);
825 sc->sc_flags |= SC_OP_RFKILL_SW_BLOCKED;
827 case RFKILL_STATE_UNBLOCKED:
828 if ((sc->sc_flags & SC_OP_RFKILL_SW_BLOCKED)) {
829 sc->sc_flags &= ~SC_OP_RFKILL_SW_BLOCKED;
830 if (sc->sc_flags & SC_OP_RFKILL_HW_BLOCKED) {
831 DPRINTF(sc, ATH_DBG_FATAL, "Can't turn on the"
832 "radio as it is disabled by h/w \n");
835 ath_radio_enable(sc);
843 /* Init s/w rfkill */
844 static int ath_init_sw_rfkill(struct ath_softc *sc)
846 sc->rf_kill.rfkill = rfkill_allocate(wiphy_dev(sc->hw->wiphy),
848 if (!sc->rf_kill.rfkill) {
849 DPRINTF(sc, ATH_DBG_FATAL, "Failed to allocate rfkill\n");
853 snprintf(sc->rf_kill.rfkill_name, sizeof(sc->rf_kill.rfkill_name),
854 "ath9k-%s:rfkill", wiphy_name(sc->hw->wiphy));
855 sc->rf_kill.rfkill->name = sc->rf_kill.rfkill_name;
856 sc->rf_kill.rfkill->data = sc;
857 sc->rf_kill.rfkill->toggle_radio = ath_sw_toggle_radio;
858 sc->rf_kill.rfkill->state = RFKILL_STATE_UNBLOCKED;
859 sc->rf_kill.rfkill->user_claim_unsupported = 1;
864 /* Deinitialize rfkill */
865 static void ath_deinit_rfkill(struct ath_softc *sc)
867 if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
868 cancel_delayed_work_sync(&sc->rf_kill.rfkill_poll);
870 if (sc->sc_flags & SC_OP_RFKILL_REGISTERED) {
871 rfkill_unregister(sc->rf_kill.rfkill);
872 sc->sc_flags &= ~SC_OP_RFKILL_REGISTERED;
873 sc->rf_kill.rfkill = NULL;
876 #endif /* CONFIG_RFKILL */
878 static int ath_detach(struct ath_softc *sc)
880 struct ieee80211_hw *hw = sc->hw;
882 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Detach ATH hw\n", __func__);
884 /* Deinit LED control */
889 ath_deinit_rfkill(sc);
894 ieee80211_unregister_hw(hw);
896 /* unregister Rate control */
897 ath_rate_control_unregister();
911 static int ath_attach(u16 devid,
912 struct ath_softc *sc)
914 struct ieee80211_hw *hw = sc->hw;
917 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Attach ATH hw\n", __func__);
919 error = ath_init(devid, sc);
925 INIT_LIST_HEAD(&sc->node_list);
926 spin_lock_init(&sc->node_lock);
928 /* get mac address from hardware and set in mac80211 */
930 SET_IEEE80211_PERM_ADDR(hw, sc->sc_myaddr);
932 /* setup channels and rates */
934 sc->sbands[IEEE80211_BAND_2GHZ].channels =
935 sc->channels[IEEE80211_BAND_2GHZ];
936 sc->sbands[IEEE80211_BAND_2GHZ].bitrates =
937 sc->rates[IEEE80211_BAND_2GHZ];
938 sc->sbands[IEEE80211_BAND_2GHZ].band = IEEE80211_BAND_2GHZ;
940 if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_HT)
941 /* Setup HT capabilities for 2.4Ghz*/
942 setup_ht_cap(&sc->sbands[IEEE80211_BAND_2GHZ].ht_info);
944 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
945 &sc->sbands[IEEE80211_BAND_2GHZ];
947 if (test_bit(ATH9K_MODE_11A, sc->sc_ah->ah_caps.wireless_modes)) {
948 sc->sbands[IEEE80211_BAND_5GHZ].channels =
949 sc->channels[IEEE80211_BAND_5GHZ];
950 sc->sbands[IEEE80211_BAND_5GHZ].bitrates =
951 sc->rates[IEEE80211_BAND_5GHZ];
952 sc->sbands[IEEE80211_BAND_5GHZ].band =
955 if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_HT)
956 /* Setup HT capabilities for 5Ghz*/
957 setup_ht_cap(&sc->sbands[IEEE80211_BAND_5GHZ].ht_info);
959 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
960 &sc->sbands[IEEE80211_BAND_5GHZ];
963 /* FIXME: Have to figure out proper hw init values later */
966 hw->ampdu_queues = 1;
968 /* Register rate control */
969 hw->rate_control_algorithm = "ath9k_rate_control";
970 error = ath_rate_control_register();
972 DPRINTF(sc, ATH_DBG_FATAL,
973 "%s: Unable to register rate control "
974 "algorithm:%d\n", __func__, error);
975 ath_rate_control_unregister();
979 error = ieee80211_register_hw(hw);
981 ath_rate_control_unregister();
985 /* Initialize LED control */
989 /* Initialze h/w Rfkill */
990 if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
991 INIT_DELAYED_WORK(&sc->rf_kill.rfkill_poll, ath_rfkill_poll);
993 /* Initialize s/w rfkill */
994 if (ath_init_sw_rfkill(sc))
998 /* initialize tx/rx engine */
1000 error = ath_tx_init(sc, ATH_TXBUF);
1004 error = ath_rx_init(sc, ATH_RXBUF);
1015 static int ath9k_start(struct ieee80211_hw *hw)
1017 struct ath_softc *sc = hw->priv;
1018 struct ieee80211_channel *curchan = hw->conf.channel;
1021 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Starting driver with "
1022 "initial channel: %d MHz\n", __func__, curchan->center_freq);
1024 /* setup initial channel */
1026 pos = ath_get_channel(sc, curchan);
1028 DPRINTF(sc, ATH_DBG_FATAL, "%s: Invalid channel\n", __func__);
1032 sc->sc_ah->ah_channels[pos].chanmode =
1033 (curchan->band == IEEE80211_BAND_2GHZ) ? CHANNEL_G : CHANNEL_A;
1036 error = ath_open(sc, &sc->sc_ah->ah_channels[pos]);
1038 DPRINTF(sc, ATH_DBG_FATAL,
1039 "%s: Unable to complete ath_open\n", __func__);
1043 #ifdef CONFIG_RFKILL
1044 /* Start rfkill polling */
1045 if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1046 queue_delayed_work(sc->hw->workqueue,
1047 &sc->rf_kill.rfkill_poll, 0);
1049 if (!(sc->sc_flags & SC_OP_RFKILL_REGISTERED)) {
1050 if (rfkill_register(sc->rf_kill.rfkill)) {
1051 DPRINTF(sc, ATH_DBG_FATAL,
1052 "Unable to register rfkill\n");
1053 rfkill_free(sc->rf_kill.rfkill);
1055 /* Deinitialize the device */
1057 free_irq(sc->pdev->irq, sc);
1059 pci_iounmap(sc->pdev, sc->mem);
1060 pci_release_region(sc->pdev, 0);
1061 pci_disable_device(sc->pdev);
1062 ieee80211_free_hw(hw);
1065 sc->sc_flags |= SC_OP_RFKILL_REGISTERED;
1070 ieee80211_wake_queues(hw);
1074 static int ath9k_tx(struct ieee80211_hw *hw,
1075 struct sk_buff *skb)
1077 struct ath_softc *sc = hw->priv;
1078 int hdrlen, padsize;
1079 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1082 * As a temporary workaround, assign seq# here; this will likely need
1083 * to be cleaned up to work better with Beacon transmission and virtual
1086 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1087 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1088 if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
1090 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
1091 hdr->seq_ctrl |= cpu_to_le16(sc->seq_no);
1094 /* Add the padding after the header if this is not already done */
1095 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
1097 padsize = hdrlen % 4;
1098 if (skb_headroom(skb) < padsize)
1100 skb_push(skb, padsize);
1101 memmove(skb->data, skb->data + padsize, hdrlen);
1104 DPRINTF(sc, ATH_DBG_XMIT, "%s: transmitting packet, skb: %p\n",
1108 if (ath_tx_start(sc, skb) != 0) {
1109 DPRINTF(sc, ATH_DBG_XMIT, "%s: TX failed\n", __func__);
1110 dev_kfree_skb_any(skb);
1111 /* FIXME: Check for proper return value from ATH_DEV */
1118 static void ath9k_stop(struct ieee80211_hw *hw)
1120 struct ath_softc *sc = hw->priv;
1123 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Driver halt\n", __func__);
1125 error = ath_suspend(sc);
1127 DPRINTF(sc, ATH_DBG_CONFIG,
1128 "%s: Device is no longer present\n", __func__);
1130 ieee80211_stop_queues(hw);
1132 #ifdef CONFIG_RFKILL
1133 if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1134 cancel_delayed_work_sync(&sc->rf_kill.rfkill_poll);
1138 static int ath9k_add_interface(struct ieee80211_hw *hw,
1139 struct ieee80211_if_init_conf *conf)
1141 struct ath_softc *sc = hw->priv;
1142 int error, ic_opmode = 0;
1144 /* Support only vap for now */
1149 switch (conf->type) {
1150 case NL80211_IFTYPE_STATION:
1151 ic_opmode = ATH9K_M_STA;
1153 case NL80211_IFTYPE_ADHOC:
1154 ic_opmode = ATH9K_M_IBSS;
1156 case NL80211_IFTYPE_AP:
1157 ic_opmode = ATH9K_M_HOSTAP;
1160 DPRINTF(sc, ATH_DBG_FATAL,
1161 "%s: Interface type %d not yet supported\n",
1162 __func__, conf->type);
1166 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Attach a VAP of type: %d\n",
1170 error = ath_vap_attach(sc, 0, conf->vif, ic_opmode);
1172 DPRINTF(sc, ATH_DBG_FATAL,
1173 "%s: Unable to attach vap, error: %d\n",
1181 static void ath9k_remove_interface(struct ieee80211_hw *hw,
1182 struct ieee80211_if_init_conf *conf)
1184 struct ath_softc *sc = hw->priv;
1185 struct ath_vap *avp;
1188 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Detach VAP\n", __func__);
1190 avp = sc->sc_vaps[0];
1192 DPRINTF(sc, ATH_DBG_FATAL, "%s: Invalid interface\n",
1197 #ifdef CONFIG_SLOW_ANT_DIV
1198 ath_slow_ant_div_stop(&sc->sc_antdiv);
1201 /* Update ratectrl */
1202 ath_rate_newstate(sc, avp);
1204 /* Reclaim beacon resources */
1205 if (sc->sc_ah->ah_opmode == ATH9K_M_HOSTAP ||
1206 sc->sc_ah->ah_opmode == ATH9K_M_IBSS) {
1207 ath9k_hw_stoptxdma(sc->sc_ah, sc->sc_bhalq);
1208 ath_beacon_return(sc, avp);
1211 /* Set interrupt mask */
1212 sc->sc_imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
1213 ath9k_hw_set_interrupts(sc->sc_ah, sc->sc_imask & ~ATH9K_INT_GLOBAL);
1214 sc->sc_flags &= ~SC_OP_BEACONS;
1216 error = ath_vap_detach(sc, 0);
1218 DPRINTF(sc, ATH_DBG_FATAL,
1219 "%s: Unable to detach vap, error: %d\n",
1223 static int ath9k_config(struct ieee80211_hw *hw,
1224 struct ieee80211_conf *conf)
1226 struct ath_softc *sc = hw->priv;
1227 struct ieee80211_channel *curchan = hw->conf.channel;
1230 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Set channel: %d MHz\n",
1232 curchan->center_freq);
1234 pos = ath_get_channel(sc, curchan);
1236 DPRINTF(sc, ATH_DBG_FATAL, "%s: Invalid channel\n", __func__);
1240 sc->sc_ah->ah_channels[pos].chanmode =
1241 (curchan->band == IEEE80211_BAND_2GHZ) ?
1242 CHANNEL_G : CHANNEL_A;
1244 if (sc->sc_curaid && hw->conf.ht_conf.ht_supported)
1245 sc->sc_ah->ah_channels[pos].chanmode =
1246 ath_get_extchanmode(sc, curchan);
1248 sc->sc_config.txpowlimit = 2 * conf->power_level;
1250 /* set h/w channel */
1251 if (ath_set_channel(sc, &sc->sc_ah->ah_channels[pos]) < 0)
1252 DPRINTF(sc, ATH_DBG_FATAL, "%s: Unable to set channel\n",
1258 static int ath9k_config_interface(struct ieee80211_hw *hw,
1259 struct ieee80211_vif *vif,
1260 struct ieee80211_if_conf *conf)
1262 struct ath_softc *sc = hw->priv;
1263 struct ath_hal *ah = sc->sc_ah;
1264 struct ath_vap *avp;
1267 DECLARE_MAC_BUF(mac);
1269 avp = sc->sc_vaps[0];
1271 DPRINTF(sc, ATH_DBG_FATAL, "%s: Invalid interface\n",
1276 /* TODO: Need to decide which hw opmode to use for multi-interface
1278 if (vif->type == NL80211_IFTYPE_AP &&
1279 ah->ah_opmode != ATH9K_M_HOSTAP) {
1280 ah->ah_opmode = ATH9K_M_HOSTAP;
1281 ath9k_hw_setopmode(ah);
1282 ath9k_hw_write_associd(ah, sc->sc_myaddr, 0);
1283 /* Request full reset to get hw opmode changed properly */
1284 sc->sc_flags |= SC_OP_FULL_RESET;
1287 if ((conf->changed & IEEE80211_IFCC_BSSID) &&
1288 !is_zero_ether_addr(conf->bssid)) {
1289 switch (vif->type) {
1290 case NL80211_IFTYPE_STATION:
1291 case NL80211_IFTYPE_ADHOC:
1292 /* Update ratectrl about the new state */
1293 ath_rate_newstate(sc, avp);
1296 memcpy(sc->sc_curbssid, conf->bssid, ETH_ALEN);
1298 ath9k_hw_write_associd(sc->sc_ah, sc->sc_curbssid,
1301 /* Set aggregation protection mode parameters */
1302 sc->sc_config.ath_aggr_prot = 0;
1305 * Reset our TSF so that its value is lower than the
1306 * beacon that we are trying to catch.
1307 * Only then hw will update its TSF register with the
1308 * new beacon. Reset the TSF before setting the BSSID
1309 * to avoid allowing in any frames that would update
1310 * our TSF only to have us clear it
1311 * immediately thereafter.
1313 ath9k_hw_reset_tsf(sc->sc_ah);
1315 /* Disable BMISS interrupt when we're not associated */
1316 ath9k_hw_set_interrupts(sc->sc_ah,
1318 ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS));
1319 sc->sc_imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
1321 DPRINTF(sc, ATH_DBG_CONFIG,
1322 "%s: RX filter 0x%x bssid %s aid 0x%x\n",
1324 print_mac(mac, sc->sc_curbssid), sc->sc_curaid);
1326 /* need to reconfigure the beacon */
1327 sc->sc_flags &= ~SC_OP_BEACONS ;
1335 if ((conf->changed & IEEE80211_IFCC_BEACON) &&
1336 ((vif->type == NL80211_IFTYPE_ADHOC) ||
1337 (vif->type == NL80211_IFTYPE_AP))) {
1339 * Allocate and setup the beacon frame.
1341 * Stop any previous beacon DMA. This may be
1342 * necessary, for example, when an ibss merge
1343 * causes reconfiguration; we may be called
1344 * with beacon transmission active.
1346 ath9k_hw_stoptxdma(sc->sc_ah, sc->sc_bhalq);
1348 error = ath_beacon_alloc(sc, 0);
1352 ath_beacon_sync(sc, 0);
1355 /* Check for WLAN_CAPABILITY_PRIVACY ? */
1356 if ((avp->av_opmode != NL80211_IFTYPE_STATION)) {
1357 for (i = 0; i < IEEE80211_WEP_NKID; i++)
1358 if (ath9k_hw_keyisvalid(sc->sc_ah, (u16)i))
1359 ath9k_hw_keysetmac(sc->sc_ah,
1364 /* Only legacy IBSS for now */
1365 if (vif->type == NL80211_IFTYPE_ADHOC)
1366 ath_update_chainmask(sc, 0);
1371 #define SUPPORTED_FILTERS \
1372 (FIF_PROMISC_IN_BSS | \
1376 FIF_BCN_PRBRESP_PROMISC | \
1379 /* FIXME: sc->sc_full_reset ? */
1380 static void ath9k_configure_filter(struct ieee80211_hw *hw,
1381 unsigned int changed_flags,
1382 unsigned int *total_flags,
1384 struct dev_mc_list *mclist)
1386 struct ath_softc *sc = hw->priv;
1389 changed_flags &= SUPPORTED_FILTERS;
1390 *total_flags &= SUPPORTED_FILTERS;
1392 sc->rx_filter = *total_flags;
1393 rfilt = ath_calcrxfilter(sc);
1394 ath9k_hw_setrxfilter(sc->sc_ah, rfilt);
1396 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
1397 if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
1398 ath9k_hw_write_associd(sc->sc_ah, ath_bcast_mac, 0);
1401 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Set HW RX filter: 0x%x\n",
1402 __func__, sc->rx_filter);
1405 static void ath9k_sta_notify(struct ieee80211_hw *hw,
1406 struct ieee80211_vif *vif,
1407 enum sta_notify_cmd cmd,
1408 struct ieee80211_sta *sta)
1410 struct ath_softc *sc = hw->priv;
1411 struct ath_node *an;
1412 unsigned long flags;
1413 DECLARE_MAC_BUF(mac);
1415 spin_lock_irqsave(&sc->node_lock, flags);
1416 an = ath_node_find(sc, sta->addr);
1417 spin_unlock_irqrestore(&sc->node_lock, flags);
1420 case STA_NOTIFY_ADD:
1421 spin_lock_irqsave(&sc->node_lock, flags);
1423 ath_node_attach(sc, sta->addr, 0);
1424 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Attach a node: %s\n",
1425 __func__, print_mac(mac, sta->addr));
1427 ath_node_get(sc, sta->addr);
1429 spin_unlock_irqrestore(&sc->node_lock, flags);
1431 case STA_NOTIFY_REMOVE:
1433 DPRINTF(sc, ATH_DBG_FATAL,
1434 "%s: Removal of a non-existent node\n",
1437 ath_node_put(sc, an, ATH9K_BH_STATUS_INTACT);
1438 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Put a node: %s\n",
1440 print_mac(mac, sta->addr));
1448 static int ath9k_conf_tx(struct ieee80211_hw *hw,
1450 const struct ieee80211_tx_queue_params *params)
1452 struct ath_softc *sc = hw->priv;
1453 struct ath9k_tx_queue_info qi;
1456 if (queue >= WME_NUM_AC)
1459 qi.tqi_aifs = params->aifs;
1460 qi.tqi_cwmin = params->cw_min;
1461 qi.tqi_cwmax = params->cw_max;
1462 qi.tqi_burstTime = params->txop;
1463 qnum = ath_get_hal_qnum(queue, sc);
1465 DPRINTF(sc, ATH_DBG_CONFIG,
1466 "%s: Configure tx [queue/halq] [%d/%d], "
1467 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1476 ret = ath_txq_update(sc, qnum, &qi);
1478 DPRINTF(sc, ATH_DBG_FATAL,
1479 "%s: TXQ Update failed\n", __func__);
1484 static int ath9k_set_key(struct ieee80211_hw *hw,
1485 enum set_key_cmd cmd,
1486 const u8 *local_addr,
1488 struct ieee80211_key_conf *key)
1490 struct ath_softc *sc = hw->priv;
1493 DPRINTF(sc, ATH_DBG_KEYCACHE, " %s: Set HW Key\n", __func__);
1497 ret = ath_key_config(sc, addr, key);
1499 set_bit(key->keyidx, sc->sc_keymap);
1500 key->hw_key_idx = key->keyidx;
1501 /* push IV and Michael MIC generation to stack */
1502 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1503 if (key->alg == ALG_TKIP)
1504 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1508 ath_key_delete(sc, key);
1509 clear_bit(key->keyidx, sc->sc_keymap);
1510 sc->sc_keytype = ATH9K_CIPHER_CLR;
1519 static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
1520 struct ieee80211_vif *vif,
1521 struct ieee80211_bss_conf *bss_conf,
1524 struct ath_softc *sc = hw->priv;
1526 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1527 DPRINTF(sc, ATH_DBG_CONFIG, "%s: BSS Changed PREAMBLE %d\n",
1529 bss_conf->use_short_preamble);
1530 if (bss_conf->use_short_preamble)
1531 sc->sc_flags |= SC_OP_PREAMBLE_SHORT;
1533 sc->sc_flags &= ~SC_OP_PREAMBLE_SHORT;
1536 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1537 DPRINTF(sc, ATH_DBG_CONFIG, "%s: BSS Changed CTS PROT %d\n",
1539 bss_conf->use_cts_prot);
1540 if (bss_conf->use_cts_prot &&
1541 hw->conf.channel->band != IEEE80211_BAND_5GHZ)
1542 sc->sc_flags |= SC_OP_PROTECT_ENABLE;
1544 sc->sc_flags &= ~SC_OP_PROTECT_ENABLE;
1547 if (changed & BSS_CHANGED_HT) {
1548 DPRINTF(sc, ATH_DBG_CONFIG, "%s: BSS Changed HT %d\n",
1550 bss_conf->assoc_ht);
1551 ath9k_ht_conf(sc, bss_conf);
1554 if (changed & BSS_CHANGED_ASSOC) {
1555 DPRINTF(sc, ATH_DBG_CONFIG, "%s: BSS Changed ASSOC %d\n",
1558 ath9k_bss_assoc_info(sc, bss_conf);
1562 static u64 ath9k_get_tsf(struct ieee80211_hw *hw)
1565 struct ath_softc *sc = hw->priv;
1566 struct ath_hal *ah = sc->sc_ah;
1568 tsf = ath9k_hw_gettsf64(ah);
1573 static void ath9k_reset_tsf(struct ieee80211_hw *hw)
1575 struct ath_softc *sc = hw->priv;
1576 struct ath_hal *ah = sc->sc_ah;
1578 ath9k_hw_reset_tsf(ah);
1581 static int ath9k_ampdu_action(struct ieee80211_hw *hw,
1582 enum ieee80211_ampdu_mlme_action action,
1583 struct ieee80211_sta *sta,
1586 struct ath_softc *sc = hw->priv;
1590 case IEEE80211_AMPDU_RX_START:
1591 ret = ath_rx_aggr_start(sc, sta->addr, tid, ssn);
1593 DPRINTF(sc, ATH_DBG_FATAL,
1594 "%s: Unable to start RX aggregation\n",
1597 case IEEE80211_AMPDU_RX_STOP:
1598 ret = ath_rx_aggr_stop(sc, sta->addr, tid);
1600 DPRINTF(sc, ATH_DBG_FATAL,
1601 "%s: Unable to stop RX aggregation\n",
1604 case IEEE80211_AMPDU_TX_START:
1605 ret = ath_tx_aggr_start(sc, sta->addr, tid, ssn);
1607 DPRINTF(sc, ATH_DBG_FATAL,
1608 "%s: Unable to start TX aggregation\n",
1611 ieee80211_start_tx_ba_cb_irqsafe(hw, sta->addr, tid);
1613 case IEEE80211_AMPDU_TX_STOP:
1614 ret = ath_tx_aggr_stop(sc, sta->addr, tid);
1616 DPRINTF(sc, ATH_DBG_FATAL,
1617 "%s: Unable to stop TX aggregation\n",
1620 ieee80211_stop_tx_ba_cb_irqsafe(hw, sta->addr, tid);
1623 DPRINTF(sc, ATH_DBG_FATAL,
1624 "%s: Unknown AMPDU action\n", __func__);
1630 static struct ieee80211_ops ath9k_ops = {
1632 .start = ath9k_start,
1634 .add_interface = ath9k_add_interface,
1635 .remove_interface = ath9k_remove_interface,
1636 .config = ath9k_config,
1637 .config_interface = ath9k_config_interface,
1638 .configure_filter = ath9k_configure_filter,
1640 .sta_notify = ath9k_sta_notify,
1641 .conf_tx = ath9k_conf_tx,
1642 .get_tx_stats = NULL,
1643 .bss_info_changed = ath9k_bss_info_changed,
1645 .set_key = ath9k_set_key,
1647 .get_tkip_seq = NULL,
1648 .set_rts_threshold = NULL,
1649 .set_frag_threshold = NULL,
1650 .set_retry_limit = NULL,
1651 .get_tsf = ath9k_get_tsf,
1652 .reset_tsf = ath9k_reset_tsf,
1653 .tx_last_beacon = NULL,
1654 .ampdu_action = ath9k_ampdu_action
1657 static int ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1660 struct ath_softc *sc;
1661 struct ieee80211_hw *hw;
1662 const char *athname;
1667 if (pci_enable_device(pdev))
1670 /* XXX 32-bit addressing only */
1671 if (pci_set_dma_mask(pdev, 0xffffffff)) {
1672 printk(KERN_ERR "ath_pci: 32-bit DMA not available\n");
1678 * Cache line size is used to size and align various
1679 * structures used to communicate with the hardware.
1681 pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &csz);
1684 * Linux 2.4.18 (at least) writes the cache line size
1685 * register as a 16-bit wide register which is wrong.
1686 * We must have this setup properly for rx buffer
1687 * DMA to work so force a reasonable value here if it
1690 csz = L1_CACHE_BYTES / sizeof(u32);
1691 pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, csz);
1694 * The default setting of latency timer yields poor results,
1695 * set it to the value used by other systems. It may be worth
1696 * tweaking this setting more.
1698 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0xa8);
1700 pci_set_master(pdev);
1703 * Disable the RETRY_TIMEOUT register (0x41) to keep
1704 * PCI Tx retries from interfering with C3 CPU state.
1706 pci_read_config_dword(pdev, 0x40, &val);
1707 if ((val & 0x0000ff00) != 0)
1708 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1710 ret = pci_request_region(pdev, 0, "ath9k");
1712 dev_err(&pdev->dev, "PCI memory region reserve error\n");
1717 mem = pci_iomap(pdev, 0, 0);
1719 printk(KERN_ERR "PCI memory map error\n") ;
1724 hw = ieee80211_alloc_hw(sizeof(struct ath_softc), &ath9k_ops);
1726 printk(KERN_ERR "ath_pci: no memory for ieee80211_hw\n");
1730 hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
1731 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
1732 IEEE80211_HW_SIGNAL_DBM |
1733 IEEE80211_HW_NOISE_DBM;
1735 hw->wiphy->interface_modes =
1736 BIT(NL80211_IFTYPE_AP) |
1737 BIT(NL80211_IFTYPE_STATION) |
1738 BIT(NL80211_IFTYPE_ADHOC);
1740 SET_IEEE80211_DEV(hw, &pdev->dev);
1741 pci_set_drvdata(pdev, hw);
1748 if (ath_attach(id->device, sc) != 0) {
1753 /* setup interrupt service routine */
1755 if (request_irq(pdev->irq, ath_isr, IRQF_SHARED, "ath", sc)) {
1756 printk(KERN_ERR "%s: request_irq failed\n",
1757 wiphy_name(hw->wiphy));
1762 athname = ath9k_hw_probe(id->vendor, id->device);
1764 printk(KERN_INFO "%s: %s: mem=0x%lx, irq=%d\n",
1765 wiphy_name(hw->wiphy),
1766 athname ? athname : "Atheros ???",
1767 (unsigned long)mem, pdev->irq);
1773 ieee80211_free_hw(hw);
1775 pci_iounmap(pdev, mem);
1777 pci_release_region(pdev, 0);
1779 pci_disable_device(pdev);
1783 static void ath_pci_remove(struct pci_dev *pdev)
1785 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1786 struct ath_softc *sc = hw->priv;
1789 free_irq(pdev->irq, sc);
1791 pci_iounmap(pdev, sc->mem);
1792 pci_release_region(pdev, 0);
1793 pci_disable_device(pdev);
1794 ieee80211_free_hw(hw);
1799 static int ath_pci_suspend(struct pci_dev *pdev, pm_message_t state)
1801 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1802 struct ath_softc *sc = hw->priv;
1804 ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1);
1806 #ifdef CONFIG_RFKILL
1807 if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1808 cancel_delayed_work_sync(&sc->rf_kill.rfkill_poll);
1811 pci_save_state(pdev);
1812 pci_disable_device(pdev);
1813 pci_set_power_state(pdev, 3);
1818 static int ath_pci_resume(struct pci_dev *pdev)
1820 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1821 struct ath_softc *sc = hw->priv;
1825 err = pci_enable_device(pdev);
1828 pci_restore_state(pdev);
1830 * Suspend/Resume resets the PCI configuration space, so we have to
1831 * re-disable the RETRY_TIMEOUT register (0x41) to keep
1832 * PCI Tx retries from interfering with C3 CPU state
1834 pci_read_config_dword(pdev, 0x40, &val);
1835 if ((val & 0x0000ff00) != 0)
1836 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1839 ath9k_hw_cfg_output(sc->sc_ah, ATH_LED_PIN,
1840 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1841 ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1);
1843 #ifdef CONFIG_RFKILL
1845 * check the h/w rfkill state on resume
1846 * and start the rfkill poll timer
1848 if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1849 queue_delayed_work(sc->hw->workqueue,
1850 &sc->rf_kill.rfkill_poll, 0);
1856 #endif /* CONFIG_PM */
1858 MODULE_DEVICE_TABLE(pci, ath_pci_id_table);
1860 static struct pci_driver ath_pci_driver = {
1862 .id_table = ath_pci_id_table,
1863 .probe = ath_pci_probe,
1864 .remove = ath_pci_remove,
1866 .suspend = ath_pci_suspend,
1867 .resume = ath_pci_resume,
1868 #endif /* CONFIG_PM */
1871 static int __init init_ath_pci(void)
1873 printk(KERN_INFO "%s: %s\n", dev_info, ATH_PCI_VERSION);
1875 if (pci_register_driver(&ath_pci_driver) < 0) {
1877 "ath_pci: No devices found, driver not installed.\n");
1878 pci_unregister_driver(&ath_pci_driver);
1884 module_init(init_ath_pci);
1886 static void __exit exit_ath_pci(void)
1888 pci_unregister_driver(&ath_pci_driver);
1889 printk(KERN_INFO "%s: driver unloaded\n", dev_info);
1891 module_exit(exit_ath_pci);