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 ieee80211_if_types 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 IEEE80211_IF_TYPE_STA:
183 /* default key: could be group WPA key
184 * or could be static WEP key */
187 case IEEE80211_IF_TYPE_IBSS:
189 case IEEE80211_IF_TYPE_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_MIMO_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 int ath9k_start(struct ieee80211_hw *hw)
330 struct ath_softc *sc = hw->priv;
331 struct ieee80211_channel *curchan = hw->conf.channel;
334 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Starting driver with "
335 "initial channel: %d MHz\n", __func__, curchan->center_freq);
337 /* setup initial channel */
339 pos = ath_get_channel(sc, curchan);
341 DPRINTF(sc, ATH_DBG_FATAL, "%s: Invalid channel\n", __func__);
345 sc->sc_ah->ah_channels[pos].chanmode =
346 (curchan->band == IEEE80211_BAND_2GHZ) ? CHANNEL_G : CHANNEL_A;
349 error = ath_open(sc, &sc->sc_ah->ah_channels[pos]);
351 DPRINTF(sc, ATH_DBG_FATAL,
352 "%s: Unable to complete ath_open\n", __func__);
356 ieee80211_wake_queues(hw);
360 static int ath9k_tx(struct ieee80211_hw *hw,
363 struct ath_softc *sc = hw->priv;
365 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
368 * As a temporary workaround, assign seq# here; this will likely need
369 * to be cleaned up to work better with Beacon transmission and virtual
372 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
373 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
374 if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
376 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
377 hdr->seq_ctrl |= cpu_to_le16(sc->seq_no);
380 /* Add the padding after the header if this is not already done */
381 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
383 padsize = hdrlen % 4;
384 if (skb_headroom(skb) < padsize)
386 skb_push(skb, padsize);
387 memmove(skb->data, skb->data + padsize, hdrlen);
390 DPRINTF(sc, ATH_DBG_XMIT, "%s: transmitting packet, skb: %p\n",
394 if (ath_tx_start(sc, skb) != 0) {
395 DPRINTF(sc, ATH_DBG_XMIT, "%s: TX failed\n", __func__);
396 dev_kfree_skb_any(skb);
397 /* FIXME: Check for proper return value from ATH_DEV */
404 static void ath9k_stop(struct ieee80211_hw *hw)
406 struct ath_softc *sc = hw->priv;
409 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Driver halt\n", __func__);
411 error = ath_suspend(sc);
413 DPRINTF(sc, ATH_DBG_CONFIG,
414 "%s: Device is no longer present\n", __func__);
416 ieee80211_stop_queues(hw);
419 static int ath9k_add_interface(struct ieee80211_hw *hw,
420 struct ieee80211_if_init_conf *conf)
422 struct ath_softc *sc = hw->priv;
423 int error, ic_opmode = 0;
425 /* Support only vap for now */
430 switch (conf->type) {
431 case IEEE80211_IF_TYPE_STA:
432 ic_opmode = ATH9K_M_STA;
434 case IEEE80211_IF_TYPE_IBSS:
435 ic_opmode = ATH9K_M_IBSS;
437 case IEEE80211_IF_TYPE_AP:
438 ic_opmode = ATH9K_M_HOSTAP;
441 DPRINTF(sc, ATH_DBG_FATAL,
442 "%s: Interface type %d not yet supported\n",
443 __func__, conf->type);
447 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Attach a VAP of type: %d\n",
451 error = ath_vap_attach(sc, 0, conf->vif, ic_opmode);
453 DPRINTF(sc, ATH_DBG_FATAL,
454 "%s: Unable to attach vap, error: %d\n",
462 static void ath9k_remove_interface(struct ieee80211_hw *hw,
463 struct ieee80211_if_init_conf *conf)
465 struct ath_softc *sc = hw->priv;
469 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Detach VAP\n", __func__);
471 avp = sc->sc_vaps[0];
473 DPRINTF(sc, ATH_DBG_FATAL, "%s: Invalid interface\n",
478 #ifdef CONFIG_SLOW_ANT_DIV
479 ath_slow_ant_div_stop(&sc->sc_antdiv);
482 /* Update ratectrl */
483 ath_rate_newstate(sc, avp);
485 /* Reclaim beacon resources */
486 if (sc->sc_ah->ah_opmode == ATH9K_M_HOSTAP ||
487 sc->sc_ah->ah_opmode == ATH9K_M_IBSS) {
488 ath9k_hw_stoptxdma(sc->sc_ah, sc->sc_bhalq);
489 ath_beacon_return(sc, avp);
492 /* Set interrupt mask */
493 sc->sc_imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
494 ath9k_hw_set_interrupts(sc->sc_ah, sc->sc_imask & ~ATH9K_INT_GLOBAL);
495 sc->sc_flags &= ~SC_OP_BEACONS;
497 error = ath_vap_detach(sc, 0);
499 DPRINTF(sc, ATH_DBG_FATAL,
500 "%s: Unable to detach vap, error: %d\n",
504 static int ath9k_config(struct ieee80211_hw *hw,
505 struct ieee80211_conf *conf)
507 struct ath_softc *sc = hw->priv;
508 struct ieee80211_channel *curchan = hw->conf.channel;
511 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Set channel: %d MHz\n",
513 curchan->center_freq);
515 pos = ath_get_channel(sc, curchan);
517 DPRINTF(sc, ATH_DBG_FATAL, "%s: Invalid channel\n", __func__);
521 sc->sc_ah->ah_channels[pos].chanmode =
522 (curchan->band == IEEE80211_BAND_2GHZ) ?
523 CHANNEL_G : CHANNEL_A;
525 if (sc->sc_curaid && hw->conf.ht_conf.ht_supported)
526 sc->sc_ah->ah_channels[pos].chanmode =
527 ath_get_extchanmode(sc, curchan);
529 sc->sc_config.txpowlimit = 2 * conf->power_level;
531 /* set h/w channel */
532 if (ath_set_channel(sc, &sc->sc_ah->ah_channels[pos]) < 0)
533 DPRINTF(sc, ATH_DBG_FATAL, "%s: Unable to set channel\n",
539 static int ath9k_config_interface(struct ieee80211_hw *hw,
540 struct ieee80211_vif *vif,
541 struct ieee80211_if_conf *conf)
543 struct ath_softc *sc = hw->priv;
544 struct ath_hal *ah = sc->sc_ah;
548 DECLARE_MAC_BUF(mac);
550 avp = sc->sc_vaps[0];
552 DPRINTF(sc, ATH_DBG_FATAL, "%s: Invalid interface\n",
557 /* TODO: Need to decide which hw opmode to use for multi-interface
559 if (vif->type == IEEE80211_IF_TYPE_AP &&
560 ah->ah_opmode != ATH9K_M_HOSTAP) {
561 ah->ah_opmode = ATH9K_M_HOSTAP;
562 ath9k_hw_setopmode(ah);
563 ath9k_hw_write_associd(ah, sc->sc_myaddr, 0);
564 /* Request full reset to get hw opmode changed properly */
565 sc->sc_flags |= SC_OP_FULL_RESET;
568 if ((conf->changed & IEEE80211_IFCC_BSSID) &&
569 !is_zero_ether_addr(conf->bssid)) {
571 case IEEE80211_IF_TYPE_STA:
572 case IEEE80211_IF_TYPE_IBSS:
573 /* Update ratectrl about the new state */
574 ath_rate_newstate(sc, avp);
577 memcpy(sc->sc_curbssid, conf->bssid, ETH_ALEN);
579 ath9k_hw_write_associd(sc->sc_ah, sc->sc_curbssid,
582 /* Set aggregation protection mode parameters */
583 sc->sc_config.ath_aggr_prot = 0;
586 * Reset our TSF so that its value is lower than the
587 * beacon that we are trying to catch.
588 * Only then hw will update its TSF register with the
589 * new beacon. Reset the TSF before setting the BSSID
590 * to avoid allowing in any frames that would update
591 * our TSF only to have us clear it
592 * immediately thereafter.
594 ath9k_hw_reset_tsf(sc->sc_ah);
596 /* Disable BMISS interrupt when we're not associated */
597 ath9k_hw_set_interrupts(sc->sc_ah,
599 ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS));
600 sc->sc_imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
602 DPRINTF(sc, ATH_DBG_CONFIG,
603 "%s: RX filter 0x%x bssid %s aid 0x%x\n",
605 print_mac(mac, sc->sc_curbssid), sc->sc_curaid);
607 /* need to reconfigure the beacon */
608 sc->sc_flags &= ~SC_OP_BEACONS ;
616 if ((conf->changed & IEEE80211_IFCC_BEACON) &&
617 ((vif->type == IEEE80211_IF_TYPE_IBSS) ||
618 (vif->type == IEEE80211_IF_TYPE_AP))) {
620 * Allocate and setup the beacon frame.
622 * Stop any previous beacon DMA. This may be
623 * necessary, for example, when an ibss merge
624 * causes reconfiguration; we may be called
625 * with beacon transmission active.
627 ath9k_hw_stoptxdma(sc->sc_ah, sc->sc_bhalq);
629 error = ath_beacon_alloc(sc, 0);
633 ath_beacon_sync(sc, 0);
636 /* Check for WLAN_CAPABILITY_PRIVACY ? */
637 if ((avp->av_opmode != IEEE80211_IF_TYPE_STA)) {
638 for (i = 0; i < IEEE80211_WEP_NKID; i++)
639 if (ath9k_hw_keyisvalid(sc->sc_ah, (u16)i))
640 ath9k_hw_keysetmac(sc->sc_ah,
645 /* Only legacy IBSS for now */
646 if (vif->type == IEEE80211_IF_TYPE_IBSS)
647 ath_update_chainmask(sc, 0);
652 #define SUPPORTED_FILTERS \
653 (FIF_PROMISC_IN_BSS | \
657 FIF_BCN_PRBRESP_PROMISC | \
660 /* FIXME: sc->sc_full_reset ? */
661 static void ath9k_configure_filter(struct ieee80211_hw *hw,
662 unsigned int changed_flags,
663 unsigned int *total_flags,
665 struct dev_mc_list *mclist)
667 struct ath_softc *sc = hw->priv;
670 changed_flags &= SUPPORTED_FILTERS;
671 *total_flags &= SUPPORTED_FILTERS;
673 sc->rx_filter = *total_flags;
674 rfilt = ath_calcrxfilter(sc);
675 ath9k_hw_setrxfilter(sc->sc_ah, rfilt);
677 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
678 if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
679 ath9k_hw_write_associd(sc->sc_ah, ath_bcast_mac, 0);
682 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Set HW RX filter: 0x%x\n",
683 __func__, sc->rx_filter);
686 static void ath9k_sta_notify(struct ieee80211_hw *hw,
687 struct ieee80211_vif *vif,
688 enum sta_notify_cmd cmd,
691 struct ath_softc *sc = hw->priv;
694 DECLARE_MAC_BUF(mac);
696 spin_lock_irqsave(&sc->node_lock, flags);
697 an = ath_node_find(sc, (u8 *) addr);
698 spin_unlock_irqrestore(&sc->node_lock, flags);
702 spin_lock_irqsave(&sc->node_lock, flags);
704 ath_node_attach(sc, (u8 *)addr, 0);
705 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Attach a node: %s\n",
707 print_mac(mac, addr));
709 ath_node_get(sc, (u8 *)addr);
711 spin_unlock_irqrestore(&sc->node_lock, flags);
713 case STA_NOTIFY_REMOVE:
715 DPRINTF(sc, ATH_DBG_FATAL,
716 "%s: Removal of a non-existent node\n",
719 ath_node_put(sc, an, ATH9K_BH_STATUS_INTACT);
720 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Put a node: %s\n",
722 print_mac(mac, addr));
730 static int ath9k_conf_tx(struct ieee80211_hw *hw,
732 const struct ieee80211_tx_queue_params *params)
734 struct ath_softc *sc = hw->priv;
735 struct ath9k_tx_queue_info qi;
738 if (queue >= WME_NUM_AC)
741 qi.tqi_aifs = params->aifs;
742 qi.tqi_cwmin = params->cw_min;
743 qi.tqi_cwmax = params->cw_max;
744 qi.tqi_burstTime = params->txop;
745 qnum = ath_get_hal_qnum(queue, sc);
747 DPRINTF(sc, ATH_DBG_CONFIG,
748 "%s: Configure tx [queue/halq] [%d/%d], "
749 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
758 ret = ath_txq_update(sc, qnum, &qi);
760 DPRINTF(sc, ATH_DBG_FATAL,
761 "%s: TXQ Update failed\n", __func__);
766 static int ath9k_set_key(struct ieee80211_hw *hw,
767 enum set_key_cmd cmd,
768 const u8 *local_addr,
770 struct ieee80211_key_conf *key)
772 struct ath_softc *sc = hw->priv;
775 DPRINTF(sc, ATH_DBG_KEYCACHE, " %s: Set HW Key\n", __func__);
779 ret = ath_key_config(sc, addr, key);
781 set_bit(key->keyidx, sc->sc_keymap);
782 key->hw_key_idx = key->keyidx;
783 /* push IV and Michael MIC generation to stack */
784 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
785 if (key->alg == ALG_TKIP)
786 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
790 ath_key_delete(sc, key);
791 clear_bit(key->keyidx, sc->sc_keymap);
792 sc->sc_keytype = ATH9K_CIPHER_CLR;
801 static void ath9k_ht_conf(struct ath_softc *sc,
802 struct ieee80211_bss_conf *bss_conf)
804 #define IEEE80211_HT_CAP_40MHZ_INTOLERANT BIT(14)
805 struct ath_ht_info *ht_info = &sc->sc_ht_info;
807 if (bss_conf->assoc_ht) {
808 ht_info->ext_chan_offset =
809 bss_conf->ht_bss_conf->bss_cap &
810 IEEE80211_HT_IE_CHA_SEC_OFFSET;
812 if (!(bss_conf->ht_conf->cap &
813 IEEE80211_HT_CAP_40MHZ_INTOLERANT) &&
814 (bss_conf->ht_bss_conf->bss_cap &
815 IEEE80211_HT_IE_CHA_WIDTH))
816 ht_info->tx_chan_width = ATH9K_HT_MACMODE_2040;
818 ht_info->tx_chan_width = ATH9K_HT_MACMODE_20;
820 ath9k_hw_set11nmac2040(sc->sc_ah, ht_info->tx_chan_width);
821 ht_info->maxampdu = 1 << (IEEE80211_HTCAP_MAXRXAMPDU_FACTOR +
822 bss_conf->ht_conf->ampdu_factor);
823 ht_info->mpdudensity =
824 parse_mpdudensity(bss_conf->ht_conf->ampdu_density);
828 #undef IEEE80211_HT_CAP_40MHZ_INTOLERANT
831 static void ath9k_bss_assoc_info(struct ath_softc *sc,
832 struct ieee80211_bss_conf *bss_conf)
834 struct ieee80211_hw *hw = sc->hw;
835 struct ieee80211_channel *curchan = hw->conf.channel;
838 DECLARE_MAC_BUF(mac);
840 if (bss_conf->assoc) {
841 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Bss Info ASSOC %d\n",
845 avp = sc->sc_vaps[0];
847 DPRINTF(sc, ATH_DBG_FATAL, "%s: Invalid interface\n",
852 /* New association, store aid */
853 if (avp->av_opmode == ATH9K_M_STA) {
854 sc->sc_curaid = bss_conf->aid;
855 ath9k_hw_write_associd(sc->sc_ah, sc->sc_curbssid,
859 /* Configure the beacon */
860 ath_beacon_config(sc, 0);
861 sc->sc_flags |= SC_OP_BEACONS;
863 /* Reset rssi stats */
864 sc->sc_halstats.ns_avgbrssi = ATH_RSSI_DUMMY_MARKER;
865 sc->sc_halstats.ns_avgrssi = ATH_RSSI_DUMMY_MARKER;
866 sc->sc_halstats.ns_avgtxrssi = ATH_RSSI_DUMMY_MARKER;
867 sc->sc_halstats.ns_avgtxrate = ATH_RATE_DUMMY_MARKER;
869 /* Update chainmask */
870 ath_update_chainmask(sc, bss_conf->assoc_ht);
872 DPRINTF(sc, ATH_DBG_CONFIG,
873 "%s: bssid %s aid 0x%x\n",
875 print_mac(mac, sc->sc_curbssid), sc->sc_curaid);
877 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Set channel: %d MHz\n",
879 curchan->center_freq);
881 pos = ath_get_channel(sc, curchan);
883 DPRINTF(sc, ATH_DBG_FATAL,
884 "%s: Invalid channel\n", __func__);
888 if (hw->conf.ht_conf.ht_supported)
889 sc->sc_ah->ah_channels[pos].chanmode =
890 ath_get_extchanmode(sc, curchan);
892 sc->sc_ah->ah_channels[pos].chanmode =
893 (curchan->band == IEEE80211_BAND_2GHZ) ?
894 CHANNEL_G : CHANNEL_A;
896 /* set h/w channel */
897 if (ath_set_channel(sc, &sc->sc_ah->ah_channels[pos]) < 0)
898 DPRINTF(sc, ATH_DBG_FATAL,
899 "%s: Unable to set channel\n",
902 ath_rate_newstate(sc, avp);
903 /* Update ratectrl about the new state */
904 ath_rc_node_update(hw, avp->rc_node);
906 DPRINTF(sc, ATH_DBG_CONFIG,
907 "%s: Bss Info DISSOC\n", __func__);
912 static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
913 struct ieee80211_vif *vif,
914 struct ieee80211_bss_conf *bss_conf,
917 struct ath_softc *sc = hw->priv;
919 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
920 DPRINTF(sc, ATH_DBG_CONFIG, "%s: BSS Changed PREAMBLE %d\n",
922 bss_conf->use_short_preamble);
923 if (bss_conf->use_short_preamble)
924 sc->sc_flags |= SC_OP_PREAMBLE_SHORT;
926 sc->sc_flags &= ~SC_OP_PREAMBLE_SHORT;
929 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
930 DPRINTF(sc, ATH_DBG_CONFIG, "%s: BSS Changed CTS PROT %d\n",
932 bss_conf->use_cts_prot);
933 if (bss_conf->use_cts_prot &&
934 hw->conf.channel->band != IEEE80211_BAND_5GHZ)
935 sc->sc_flags |= SC_OP_PROTECT_ENABLE;
937 sc->sc_flags &= ~SC_OP_PROTECT_ENABLE;
940 if (changed & BSS_CHANGED_HT) {
941 DPRINTF(sc, ATH_DBG_CONFIG, "%s: BSS Changed HT %d\n",
944 ath9k_ht_conf(sc, bss_conf);
947 if (changed & BSS_CHANGED_ASSOC) {
948 DPRINTF(sc, ATH_DBG_CONFIG, "%s: BSS Changed ASSOC %d\n",
951 ath9k_bss_assoc_info(sc, bss_conf);
955 static u64 ath9k_get_tsf(struct ieee80211_hw *hw)
958 struct ath_softc *sc = hw->priv;
959 struct ath_hal *ah = sc->sc_ah;
961 tsf = ath9k_hw_gettsf64(ah);
966 static void ath9k_reset_tsf(struct ieee80211_hw *hw)
968 struct ath_softc *sc = hw->priv;
969 struct ath_hal *ah = sc->sc_ah;
971 ath9k_hw_reset_tsf(ah);
974 static int ath9k_ampdu_action(struct ieee80211_hw *hw,
975 enum ieee80211_ampdu_mlme_action action,
980 struct ath_softc *sc = hw->priv;
984 case IEEE80211_AMPDU_RX_START:
985 ret = ath_rx_aggr_start(sc, addr, tid, ssn);
987 DPRINTF(sc, ATH_DBG_FATAL,
988 "%s: Unable to start RX aggregation\n",
991 case IEEE80211_AMPDU_RX_STOP:
992 ret = ath_rx_aggr_stop(sc, addr, tid);
994 DPRINTF(sc, ATH_DBG_FATAL,
995 "%s: Unable to stop RX aggregation\n",
998 case IEEE80211_AMPDU_TX_START:
999 ret = ath_tx_aggr_start(sc, addr, tid, ssn);
1001 DPRINTF(sc, ATH_DBG_FATAL,
1002 "%s: Unable to start TX aggregation\n",
1005 ieee80211_start_tx_ba_cb_irqsafe(hw, (u8 *)addr, tid);
1007 case IEEE80211_AMPDU_TX_STOP:
1008 ret = ath_tx_aggr_stop(sc, addr, tid);
1010 DPRINTF(sc, ATH_DBG_FATAL,
1011 "%s: Unable to stop TX aggregation\n",
1014 ieee80211_stop_tx_ba_cb_irqsafe(hw, (u8 *)addr, tid);
1017 DPRINTF(sc, ATH_DBG_FATAL,
1018 "%s: Unknown AMPDU action\n", __func__);
1024 static struct ieee80211_ops ath9k_ops = {
1026 .start = ath9k_start,
1028 .add_interface = ath9k_add_interface,
1029 .remove_interface = ath9k_remove_interface,
1030 .config = ath9k_config,
1031 .config_interface = ath9k_config_interface,
1032 .configure_filter = ath9k_configure_filter,
1034 .sta_notify = ath9k_sta_notify,
1035 .conf_tx = ath9k_conf_tx,
1036 .get_tx_stats = NULL,
1037 .bss_info_changed = ath9k_bss_info_changed,
1039 .set_key = ath9k_set_key,
1041 .get_tkip_seq = NULL,
1042 .set_rts_threshold = NULL,
1043 .set_frag_threshold = NULL,
1044 .set_retry_limit = NULL,
1045 .get_tsf = ath9k_get_tsf,
1046 .reset_tsf = ath9k_reset_tsf,
1047 .tx_last_beacon = NULL,
1048 .ampdu_action = ath9k_ampdu_action
1051 void ath_get_beaconconfig(struct ath_softc *sc,
1053 struct ath_beacon_config *conf)
1055 struct ieee80211_hw *hw = sc->hw;
1057 /* fill in beacon config data */
1059 conf->beacon_interval = hw->conf.beacon_int;
1060 conf->listen_interval = 100;
1061 conf->dtim_count = 1;
1062 conf->bmiss_timeout = ATH_DEFAULT_BMISS_LIMIT * conf->listen_interval;
1065 void ath_tx_complete(struct ath_softc *sc, struct sk_buff *skb,
1066 struct ath_xmit_status *tx_status, struct ath_node *an)
1068 struct ieee80211_hw *hw = sc->hw;
1069 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
1071 DPRINTF(sc, ATH_DBG_XMIT,
1072 "%s: TX complete: skb: %p\n", __func__, skb);
1074 if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK ||
1075 tx_info->flags & IEEE80211_TX_STAT_TX_FILTERED) {
1076 /* free driver's private data area of tx_info */
1077 if (tx_info->driver_data[0] != NULL)
1078 kfree(tx_info->driver_data[0]);
1079 tx_info->driver_data[0] = NULL;
1082 if (tx_status->flags & ATH_TX_BAR) {
1083 tx_info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
1084 tx_status->flags &= ~ATH_TX_BAR;
1087 if (tx_status->flags & (ATH_TX_ERROR | ATH_TX_XRETRY)) {
1088 if (!(tx_info->flags & IEEE80211_TX_CTL_NO_ACK)) {
1089 /* Frame was not ACKed, but an ACK was expected */
1090 tx_info->status.excessive_retries = 1;
1093 /* Frame was ACKed */
1094 tx_info->flags |= IEEE80211_TX_STAT_ACK;
1097 tx_info->status.retry_count = tx_status->retries;
1099 ieee80211_tx_status(hw, skb);
1101 ath_node_put(sc, an, ATH9K_BH_STATUS_CHANGE);
1104 int _ath_rx_indicate(struct ath_softc *sc,
1105 struct sk_buff *skb,
1106 struct ath_recv_status *status,
1109 struct ieee80211_hw *hw = sc->hw;
1110 struct ath_node *an = NULL;
1111 struct ieee80211_rx_status rx_status;
1112 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1113 int hdrlen = ieee80211_get_hdrlen_from_skb(skb);
1115 enum ATH_RX_TYPE st;
1117 /* see if any padding is done by the hw and remove it */
1119 padsize = hdrlen % 4;
1120 memmove(skb->data + padsize, skb->data, hdrlen);
1121 skb_pull(skb, padsize);
1124 /* Prepare rx status */
1125 ath9k_rx_prepare(sc, skb, status, &rx_status);
1127 if (!(keyix == ATH9K_RXKEYIX_INVALID) &&
1128 !(status->flags & ATH_RX_DECRYPT_ERROR)) {
1129 rx_status.flag |= RX_FLAG_DECRYPTED;
1130 } else if ((le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_PROTECTED)
1131 && !(status->flags & ATH_RX_DECRYPT_ERROR)
1132 && skb->len >= hdrlen + 4) {
1133 keyix = skb->data[hdrlen + 3] >> 6;
1135 if (test_bit(keyix, sc->sc_keymap))
1136 rx_status.flag |= RX_FLAG_DECRYPTED;
1139 spin_lock_bh(&sc->node_lock);
1140 an = ath_node_find(sc, hdr->addr2);
1141 spin_unlock_bh(&sc->node_lock);
1144 ath_rx_input(sc, an,
1145 hw->conf.ht_conf.ht_supported,
1148 if (!an || (st != ATH_RX_CONSUMED))
1149 __ieee80211_rx(hw, skb, &rx_status);
1154 int ath_rx_subframe(struct ath_node *an,
1155 struct sk_buff *skb,
1156 struct ath_recv_status *status)
1158 struct ath_softc *sc = an->an_sc;
1159 struct ieee80211_hw *hw = sc->hw;
1160 struct ieee80211_rx_status rx_status;
1162 /* Prepare rx status */
1163 ath9k_rx_prepare(sc, skb, status, &rx_status);
1164 if (!(status->flags & ATH_RX_DECRYPT_ERROR))
1165 rx_status.flag |= RX_FLAG_DECRYPTED;
1167 __ieee80211_rx(hw, skb, &rx_status);
1172 /********************************/
1174 /********************************/
1176 static void ath_led_brightness(struct led_classdev *led_cdev,
1177 enum led_brightness brightness)
1179 struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev);
1180 struct ath_softc *sc = led->sc;
1182 switch (brightness) {
1184 if (led->led_type == ATH_LED_ASSOC ||
1185 led->led_type == ATH_LED_RADIO)
1186 sc->sc_flags &= ~SC_OP_LED_ASSOCIATED;
1187 ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN,
1188 (led->led_type == ATH_LED_RADIO) ? 1 :
1189 !!(sc->sc_flags & SC_OP_LED_ASSOCIATED));
1192 if (led->led_type == ATH_LED_ASSOC)
1193 sc->sc_flags |= SC_OP_LED_ASSOCIATED;
1194 ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 0);
1201 static int ath_register_led(struct ath_softc *sc, struct ath_led *led,
1207 led->led_cdev.name = led->name;
1208 led->led_cdev.default_trigger = trigger;
1209 led->led_cdev.brightness_set = ath_led_brightness;
1211 ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &led->led_cdev);
1213 DPRINTF(sc, ATH_DBG_FATAL,
1214 "Failed to register led:%s", led->name);
1216 led->registered = 1;
1220 static void ath_unregister_led(struct ath_led *led)
1222 if (led->registered) {
1223 led_classdev_unregister(&led->led_cdev);
1224 led->registered = 0;
1228 static void ath_deinit_leds(struct ath_softc *sc)
1230 ath_unregister_led(&sc->assoc_led);
1231 sc->sc_flags &= ~SC_OP_LED_ASSOCIATED;
1232 ath_unregister_led(&sc->tx_led);
1233 ath_unregister_led(&sc->rx_led);
1234 ath_unregister_led(&sc->radio_led);
1235 ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1);
1238 static void ath_init_leds(struct ath_softc *sc)
1243 /* Configure gpio 1 for output */
1244 ath9k_hw_cfg_output(sc->sc_ah, ATH_LED_PIN,
1245 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1246 /* LED off, active low */
1247 ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1);
1249 trigger = ieee80211_get_radio_led_name(sc->hw);
1250 snprintf(sc->radio_led.name, sizeof(sc->radio_led.name),
1251 "ath9k-%s:radio", wiphy_name(sc->hw->wiphy));
1252 ret = ath_register_led(sc, &sc->radio_led, trigger);
1253 sc->radio_led.led_type = ATH_LED_RADIO;
1257 trigger = ieee80211_get_assoc_led_name(sc->hw);
1258 snprintf(sc->assoc_led.name, sizeof(sc->assoc_led.name),
1259 "ath9k-%s:assoc", wiphy_name(sc->hw->wiphy));
1260 ret = ath_register_led(sc, &sc->assoc_led, trigger);
1261 sc->assoc_led.led_type = ATH_LED_ASSOC;
1265 trigger = ieee80211_get_tx_led_name(sc->hw);
1266 snprintf(sc->tx_led.name, sizeof(sc->tx_led.name),
1267 "ath9k-%s:tx", wiphy_name(sc->hw->wiphy));
1268 ret = ath_register_led(sc, &sc->tx_led, trigger);
1269 sc->tx_led.led_type = ATH_LED_TX;
1273 trigger = ieee80211_get_rx_led_name(sc->hw);
1274 snprintf(sc->rx_led.name, sizeof(sc->rx_led.name),
1275 "ath9k-%s:rx", wiphy_name(sc->hw->wiphy));
1276 ret = ath_register_led(sc, &sc->rx_led, trigger);
1277 sc->rx_led.led_type = ATH_LED_RX;
1284 ath_deinit_leds(sc);
1287 static int ath_detach(struct ath_softc *sc)
1289 struct ieee80211_hw *hw = sc->hw;
1291 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Detach ATH hw\n", __func__);
1293 /* Deinit LED control */
1294 ath_deinit_leds(sc);
1298 ieee80211_unregister_hw(hw);
1300 /* unregister Rate control */
1301 ath_rate_control_unregister();
1315 static int ath_attach(u16 devid,
1316 struct ath_softc *sc)
1318 struct ieee80211_hw *hw = sc->hw;
1321 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Attach ATH hw\n", __func__);
1323 error = ath_init(devid, sc);
1329 INIT_LIST_HEAD(&sc->node_list);
1330 spin_lock_init(&sc->node_lock);
1332 /* get mac address from hardware and set in mac80211 */
1334 SET_IEEE80211_PERM_ADDR(hw, sc->sc_myaddr);
1336 /* setup channels and rates */
1338 sc->sbands[IEEE80211_BAND_2GHZ].channels =
1339 sc->channels[IEEE80211_BAND_2GHZ];
1340 sc->sbands[IEEE80211_BAND_2GHZ].bitrates =
1341 sc->rates[IEEE80211_BAND_2GHZ];
1342 sc->sbands[IEEE80211_BAND_2GHZ].band = IEEE80211_BAND_2GHZ;
1344 if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_HT)
1345 /* Setup HT capabilities for 2.4Ghz*/
1346 setup_ht_cap(&sc->sbands[IEEE80211_BAND_2GHZ].ht_info);
1348 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
1349 &sc->sbands[IEEE80211_BAND_2GHZ];
1351 if (test_bit(ATH9K_MODE_11A, sc->sc_ah->ah_caps.wireless_modes)) {
1352 sc->sbands[IEEE80211_BAND_5GHZ].channels =
1353 sc->channels[IEEE80211_BAND_5GHZ];
1354 sc->sbands[IEEE80211_BAND_5GHZ].bitrates =
1355 sc->rates[IEEE80211_BAND_5GHZ];
1356 sc->sbands[IEEE80211_BAND_5GHZ].band =
1357 IEEE80211_BAND_5GHZ;
1359 if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_HT)
1360 /* Setup HT capabilities for 5Ghz*/
1361 setup_ht_cap(&sc->sbands[IEEE80211_BAND_5GHZ].ht_info);
1363 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
1364 &sc->sbands[IEEE80211_BAND_5GHZ];
1367 /* FIXME: Have to figure out proper hw init values later */
1370 hw->ampdu_queues = 1;
1372 /* Register rate control */
1373 hw->rate_control_algorithm = "ath9k_rate_control";
1374 error = ath_rate_control_register();
1376 DPRINTF(sc, ATH_DBG_FATAL,
1377 "%s: Unable to register rate control "
1378 "algorithm:%d\n", __func__, error);
1379 ath_rate_control_unregister();
1383 error = ieee80211_register_hw(hw);
1385 ath_rate_control_unregister();
1389 /* Initialize LED control */
1392 /* initialize tx/rx engine */
1394 error = ath_tx_init(sc, ATH_TXBUF);
1398 error = ath_rx_init(sc, ATH_RXBUF);
1409 static int ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1412 struct ath_softc *sc;
1413 struct ieee80211_hw *hw;
1414 const char *athname;
1419 if (pci_enable_device(pdev))
1422 /* XXX 32-bit addressing only */
1423 if (pci_set_dma_mask(pdev, 0xffffffff)) {
1424 printk(KERN_ERR "ath_pci: 32-bit DMA not available\n");
1430 * Cache line size is used to size and align various
1431 * structures used to communicate with the hardware.
1433 pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &csz);
1436 * Linux 2.4.18 (at least) writes the cache line size
1437 * register as a 16-bit wide register which is wrong.
1438 * We must have this setup properly for rx buffer
1439 * DMA to work so force a reasonable value here if it
1442 csz = L1_CACHE_BYTES / sizeof(u32);
1443 pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, csz);
1446 * The default setting of latency timer yields poor results,
1447 * set it to the value used by other systems. It may be worth
1448 * tweaking this setting more.
1450 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0xa8);
1452 pci_set_master(pdev);
1455 * Disable the RETRY_TIMEOUT register (0x41) to keep
1456 * PCI Tx retries from interfering with C3 CPU state.
1458 pci_read_config_dword(pdev, 0x40, &val);
1459 if ((val & 0x0000ff00) != 0)
1460 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1462 ret = pci_request_region(pdev, 0, "ath9k");
1464 dev_err(&pdev->dev, "PCI memory region reserve error\n");
1469 mem = pci_iomap(pdev, 0, 0);
1471 printk(KERN_ERR "PCI memory map error\n") ;
1476 hw = ieee80211_alloc_hw(sizeof(struct ath_softc), &ath9k_ops);
1478 printk(KERN_ERR "ath_pci: no memory for ieee80211_hw\n");
1482 hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
1483 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
1484 IEEE80211_HW_SIGNAL_DBM |
1485 IEEE80211_HW_NOISE_DBM;
1487 hw->wiphy->interface_modes =
1488 BIT(NL80211_IFTYPE_AP) |
1489 BIT(NL80211_IFTYPE_STATION) |
1490 BIT(NL80211_IFTYPE_ADHOC);
1492 SET_IEEE80211_DEV(hw, &pdev->dev);
1493 pci_set_drvdata(pdev, hw);
1500 if (ath_attach(id->device, sc) != 0) {
1505 /* setup interrupt service routine */
1507 if (request_irq(pdev->irq, ath_isr, IRQF_SHARED, "ath", sc)) {
1508 printk(KERN_ERR "%s: request_irq failed\n",
1509 wiphy_name(hw->wiphy));
1514 athname = ath9k_hw_probe(id->vendor, id->device);
1516 printk(KERN_INFO "%s: %s: mem=0x%lx, irq=%d\n",
1517 wiphy_name(hw->wiphy),
1518 athname ? athname : "Atheros ???",
1519 (unsigned long)mem, pdev->irq);
1525 ieee80211_free_hw(hw);
1527 pci_iounmap(pdev, mem);
1529 pci_release_region(pdev, 0);
1531 pci_disable_device(pdev);
1535 static void ath_pci_remove(struct pci_dev *pdev)
1537 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1538 struct ath_softc *sc = hw->priv;
1541 free_irq(pdev->irq, sc);
1543 pci_iounmap(pdev, sc->mem);
1544 pci_release_region(pdev, 0);
1545 pci_disable_device(pdev);
1546 ieee80211_free_hw(hw);
1551 static int ath_pci_suspend(struct pci_dev *pdev, pm_message_t state)
1553 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1554 struct ath_softc *sc = hw->priv;
1556 ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1);
1557 pci_save_state(pdev);
1558 pci_disable_device(pdev);
1559 pci_set_power_state(pdev, 3);
1564 static int ath_pci_resume(struct pci_dev *pdev)
1566 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1567 struct ath_softc *sc = hw->priv;
1571 err = pci_enable_device(pdev);
1574 pci_restore_state(pdev);
1576 * Suspend/Resume resets the PCI configuration space, so we have to
1577 * re-disable the RETRY_TIMEOUT register (0x41) to keep
1578 * PCI Tx retries from interfering with C3 CPU state
1580 pci_read_config_dword(pdev, 0x40, &val);
1581 if ((val & 0x0000ff00) != 0)
1582 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1585 ath9k_hw_cfg_output(sc->sc_ah, ATH_LED_PIN,
1586 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1587 ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1);
1592 #endif /* CONFIG_PM */
1594 MODULE_DEVICE_TABLE(pci, ath_pci_id_table);
1596 static struct pci_driver ath_pci_driver = {
1598 .id_table = ath_pci_id_table,
1599 .probe = ath_pci_probe,
1600 .remove = ath_pci_remove,
1602 .suspend = ath_pci_suspend,
1603 .resume = ath_pci_resume,
1604 #endif /* CONFIG_PM */
1607 static int __init init_ath_pci(void)
1609 printk(KERN_INFO "%s: %s\n", dev_info, ATH_PCI_VERSION);
1611 if (pci_register_driver(&ath_pci_driver) < 0) {
1613 "ath_pci: No devices found, driver not installed.\n");
1614 pci_unregister_driver(&ath_pci_driver);
1620 module_init(init_ath_pci);
1622 static void __exit exit_ath_pci(void)
1624 pci_unregister_driver(&ath_pci_driver);
1625 printk(KERN_INFO "%s: driver unloaded\n", dev_info);
1627 module_exit(exit_ath_pci);