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
25 #define IEEE80211_ACTION_CAT_HT 7
26 #define IEEE80211_ACTION_HT_TXCHWIDTH 0
28 static char *dev_info
= "ath9k";
30 MODULE_AUTHOR("Atheros Communications");
31 MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
32 MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
33 MODULE_LICENSE("Dual BSD/GPL");
35 static struct pci_device_id ath_pci_id_table
[] __devinitdata
= {
36 { PCI_VDEVICE(ATHEROS
, 0x0023) }, /* PCI */
37 { PCI_VDEVICE(ATHEROS
, 0x0024) }, /* PCI-E */
38 { PCI_VDEVICE(ATHEROS
, 0x0027) }, /* PCI */
39 { PCI_VDEVICE(ATHEROS
, 0x0029) }, /* PCI */
40 { PCI_VDEVICE(ATHEROS
, 0x002A) }, /* PCI-E */
44 static int test_update_chan(enum ieee80211_band band
,
45 const struct hal_channel
*chan
,
50 for (i
= 0; i
< sc
->sbands
[band
].n_channels
; i
++) {
51 if (sc
->channels
[band
][i
].center_freq
== chan
->channel
)
58 static int ath_check_chanflags(struct ieee80211_channel
*chan
,
62 struct ieee80211_hw
*hw
= sc
->hw
;
63 struct ieee80211_supported_band
*band
;
64 struct ieee80211_channel
*band_channel
;
67 band
= hw
->wiphy
->bands
[chan
->band
];
69 for (i
= 0; i
< band
->n_channels
; i
++) {
70 band_channel
= &band
->channels
[i
];
72 if ((band_channel
->center_freq
== chan
->center_freq
) &&
73 ((band_channel
->hw_value
& mode
) == mode
))
79 static int ath_setkey_tkip(struct ath_softc
*sc
,
80 struct ieee80211_key_conf
*key
,
81 struct hal_keyval
*hk
,
87 key_txmic
= key
->key
+ NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY
;
88 key_rxmic
= key
->key
+ NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY
;
91 /* Group key installation */
92 memcpy(hk
->kv_mic
, key_rxmic
, sizeof(hk
->kv_mic
));
93 return ath_keyset(sc
, key
->keyidx
, hk
, addr
);
95 if (!sc
->sc_splitmic
) {
97 * data key goes at first index,
98 * the hal handles the MIC keys at index+64.
100 memcpy(hk
->kv_mic
, key_rxmic
, sizeof(hk
->kv_mic
));
101 memcpy(hk
->kv_txmic
, key_txmic
, sizeof(hk
->kv_txmic
));
102 return ath_keyset(sc
, key
->keyidx
, hk
, addr
);
105 * TX key goes at first index, RX key at +32.
106 * The hal handles the MIC keys at index+64.
108 memcpy(hk
->kv_mic
, key_txmic
, sizeof(hk
->kv_mic
));
109 if (!ath_keyset(sc
, key
->keyidx
, hk
, NULL
)) {
110 /* Txmic entry failed. No need to proceed further */
111 DPRINTF(sc
, ATH_DEBUG_KEYCACHE
,
112 "%s Setting TX MIC Key Failed\n", __func__
);
116 memcpy(hk
->kv_mic
, key_rxmic
, sizeof(hk
->kv_mic
));
117 /* XXX delete tx key on failure? */
118 return ath_keyset(sc
, key
->keyidx
+32, hk
, addr
);
121 static int ath_key_config(struct ath_softc
*sc
,
123 struct ieee80211_key_conf
*key
)
125 struct ieee80211_vif
*vif
;
126 struct hal_keyval hk
;
127 const u8
*mac
= NULL
;
129 enum ieee80211_if_types opmode
;
131 memset(&hk
, 0, sizeof(hk
));
135 hk
.kv_type
= HAL_CIPHER_WEP
;
138 hk
.kv_type
= HAL_CIPHER_TKIP
;
141 hk
.kv_type
= HAL_CIPHER_AES_CCM
;
147 hk
.kv_len
= key
->keylen
;
148 memcpy(hk
.kv_val
, key
->key
, key
->keylen
);
153 vif
= sc
->sc_vaps
[0]->av_if_data
;
158 * For _M_STA mc tx, we will not setup a key at all since we never
160 * _M_STA mc rx, we will use the keyID.
161 * for _M_IBSS mc tx, we will use the keyID, and no macaddr.
162 * for _M_IBSS mc rx, we will alloc a slot and plumb the mac of the
163 * peer node. BUT we will plumb a cleartext key so that we can do
164 * perSta default key table lookup in software.
166 if (is_broadcast_ether_addr(addr
)) {
168 case IEEE80211_IF_TYPE_STA
:
169 /* default key: could be group WPA key
170 * or could be static WEP key */
173 case IEEE80211_IF_TYPE_IBSS
:
175 case IEEE80211_IF_TYPE_AP
:
185 if (key
->alg
== ALG_TKIP
)
186 ret
= ath_setkey_tkip(sc
, key
, &hk
, mac
);
188 ret
= ath_keyset(sc
, key
->keyidx
, &hk
, mac
);
193 sc
->sc_keytype
= hk
.kv_type
;
197 static void ath_key_delete(struct ath_softc
*sc
, struct ieee80211_key_conf
*key
)
199 #define ATH_MAX_NUM_KEYS 4
202 freeslot
= (key
->keyidx
>= ATH_MAX_NUM_KEYS
) ? 1 : 0;
203 ath_key_reset(sc
, key
->keyidx
, freeslot
);
204 #undef ATH_MAX_NUM_KEYS
207 static void setup_ht_cap(struct ieee80211_ht_info
*ht_info
)
209 /* Until mac80211 includes these fields */
211 #define IEEE80211_HT_CAP_DSSSCCK40 0x1000
212 #define IEEE80211_HT_CAP_MAXRXAMPDU_65536 0x3 /* 2 ^ 16 */
213 #define IEEE80211_HT_CAP_MPDUDENSITY_8 0x6 /* 8 usec */
215 ht_info
->ht_supported
= 1;
216 ht_info
->cap
= (u16
)IEEE80211_HT_CAP_SUP_WIDTH
217 |(u16
)IEEE80211_HT_CAP_MIMO_PS
218 |(u16
)IEEE80211_HT_CAP_SGI_40
219 |(u16
)IEEE80211_HT_CAP_DSSSCCK40
;
221 ht_info
->ampdu_factor
= IEEE80211_HT_CAP_MAXRXAMPDU_65536
;
222 ht_info
->ampdu_density
= IEEE80211_HT_CAP_MPDUDENSITY_8
;
223 /* setup supported mcs set */
224 memset(ht_info
->supp_mcs_set
, 0, 16);
225 ht_info
->supp_mcs_set
[0] = 0xff;
226 ht_info
->supp_mcs_set
[1] = 0xff;
227 ht_info
->supp_mcs_set
[12] = IEEE80211_HT_CAP_MCS_TX_DEFINED
;
230 static int ath_rate2idx(struct ath_softc
*sc
, int rate
)
232 int i
= 0, cur_band
, n_rates
;
233 struct ieee80211_hw
*hw
= sc
->hw
;
235 cur_band
= hw
->conf
.channel
->band
;
236 n_rates
= sc
->sbands
[cur_band
].n_bitrates
;
238 for (i
= 0; i
< n_rates
; i
++) {
239 if (sc
->sbands
[cur_band
].bitrates
[i
].bitrate
== rate
)
244 * NB:mac80211 validates rx rate index against the supported legacy rate
245 * index only (should be done against ht rates also), return the highest
246 * legacy rate index for rx rate which does not match any one of the
247 * supported basic and extended rates to make mac80211 happy.
248 * The following hack will be cleaned up once the issue with
249 * the rx rate index validation in mac80211 is fixed.
256 static void ath9k_rx_prepare(struct ath_softc
*sc
,
258 struct ath_recv_status
*status
,
259 struct ieee80211_rx_status
*rx_status
)
261 struct ieee80211_hw
*hw
= sc
->hw
;
262 struct ieee80211_channel
*curchan
= hw
->conf
.channel
;
264 memset(rx_status
, 0, sizeof(struct ieee80211_rx_status
));
266 rx_status
->mactime
= status
->tsf
;
267 rx_status
->band
= curchan
->band
;
268 rx_status
->freq
= curchan
->center_freq
;
269 rx_status
->signal
= (status
->rssi
* 64) / 100;
270 rx_status
->noise
= ATH_DEFAULT_NOISE_FLOOR
;
271 rx_status
->rate_idx
= ath_rate2idx(sc
, (status
->rateKbps
/ 100));
272 rx_status
->antenna
= status
->antenna
;
274 if (status
->flags
& ATH_RX_MIC_ERROR
)
275 rx_status
->flag
|= RX_FLAG_MMIC_ERROR
;
276 if (status
->flags
& ATH_RX_FCS_ERROR
)
277 rx_status
->flag
|= RX_FLAG_FAILED_FCS_CRC
;
279 rx_status
->flag
|= RX_FLAG_TSFT
;
283 * Update all associated nodes and VAPs
285 * Called when local channel width changed. e.g. if AP mode,
286 * update all associated STAs when the AP's channel width changes.
288 static void cwm_rate_updateallnodes(struct ath_softc
*sc
)
290 int flags
= 0, error
;
291 struct ieee80211_vif
*vif
;
292 enum ieee80211_if_types opmode
;
293 struct ieee80211_hw
*hw
= sc
->hw
;
295 if (sc
->sc_vaps
[0]) {
296 vif
= sc
->sc_vaps
[0]->av_if_data
;
299 case IEEE80211_IF_TYPE_STA
:
300 /* sync with next received beacon */
301 flags
|= ATH_IF_BEACON_SYNC
;
302 if (hw
->conf
.ht_conf
.ht_supported
)
304 error
= ath_vap_up(sc
, 0,
305 /* sc->sc_vaps[i]->av_btxctl->if_id, FIX ME if_id */
306 /* sc->sc_vaps[i]->bssid, FIX ME bssid */
310 if (error
)/* FIX ME if_id */
311 DPRINTF(sc
, ATH_DEBUG_CWM
,
312 "%s: Unable to up vap: "
313 "%d\n", __func__
, 0);
315 DPRINTF(sc
, ATH_DEBUG_CWM
,
316 "%s: VAP up for id: "
317 "%d\n", __func__
, 0);
319 case IEEE80211_IF_TYPE_IBSS
:
320 case IEEE80211_IF_TYPE_AP
:
329 /* Action: switch MAC from 40 to 20 (OR) 20 to 40 based on ch_width arg */
330 static void cwm_action_mac_change_chwidth(struct ath_softc
*sc
,
331 enum hal_ht_macmode ch_width
)
333 ath_set_macmode(sc
, ch_width
);
335 /* notify rate control of new mode (select new rate table) */
336 cwm_rate_updateallnodes(sc
);
338 /* XXX: all virtual APs - send ch width action management frame */
341 static u_int8_t
parse_mpdudensity(u_int8_t mpdudensity
)
344 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
345 * 0 for no restriction
354 switch (mpdudensity
) {
360 /* Our lower layer calculations limit our precision to
376 static int ath9k_start(struct ieee80211_hw
*hw
)
378 struct ath_softc
*sc
= hw
->priv
;
379 struct ieee80211_channel
*curchan
= hw
->conf
.channel
;
380 struct hal_channel hchan
;
383 DPRINTF(sc
, ATH_DEBUG_CONFIG
, "%s: Starting driver with "
384 "initial channel: %d MHz\n", __func__
, curchan
->center_freq
);
386 /* setup initial channel */
388 hchan
.channel
= curchan
->center_freq
;
389 hchan
.channelFlags
= ath_chan2flags(curchan
, sc
);
392 error
= ath_open(sc
, &hchan
);
394 DPRINTF(sc
, ATH_DEBUG_FATAL
,
395 "%s: Unable to complete ath_open\n", __func__
);
399 ieee80211_wake_queues(hw
);
403 static int ath9k_tx(struct ieee80211_hw
*hw
,
406 struct ath_softc
*sc
= hw
->priv
;
409 /* Add the padding after the header if this is not already done */
410 hdrlen
= ieee80211_get_hdrlen_from_skb(skb
);
412 padsize
= hdrlen
% 4;
413 if (skb_headroom(skb
) < padsize
)
415 skb_push(skb
, padsize
);
416 memmove(skb
->data
, skb
->data
+ padsize
, hdrlen
);
419 DPRINTF(sc
, ATH_DEBUG_XMIT
, "%s: transmitting packet, skb: %p\n",
423 if (ath_tx_start(sc
, skb
) != 0) {
424 DPRINTF(sc
, ATH_DEBUG_XMIT
, "%s: TX failed\n", __func__
);
425 dev_kfree_skb_any(skb
);
426 /* FIXME: Check for proper return value from ATH_DEV */
433 static int ath9k_beacon_update(struct ieee80211_hw
*hw
,
437 struct ath_softc
*sc
= hw
->priv
;
439 DPRINTF(sc
, ATH_DEBUG_BEACON
, "%s: Update Beacon\n", __func__
);
440 return ath9k_tx(hw
, skb
);
443 static void ath9k_stop(struct ieee80211_hw
*hw
)
445 struct ath_softc
*sc
= hw
->priv
;
448 DPRINTF(sc
, ATH_DEBUG_CONFIG
, "%s: Driver halt\n", __func__
);
450 error
= ath_suspend(sc
);
452 DPRINTF(sc
, ATH_DEBUG_CONFIG
,
453 "%s: Device is no longer present\n", __func__
);
455 ieee80211_stop_queues(hw
);
458 static int ath9k_add_interface(struct ieee80211_hw
*hw
,
459 struct ieee80211_if_init_conf
*conf
)
461 struct ath_softc
*sc
= hw
->priv
;
462 int error
, ic_opmode
= 0;
464 /* Support only vap for now */
469 switch (conf
->type
) {
470 case IEEE80211_IF_TYPE_STA
:
471 ic_opmode
= HAL_M_STA
;
476 DPRINTF(sc
, ATH_DEBUG_CONFIG
, "%s: Attach a VAP of type: %d\n",
480 error
= ath_vap_attach(sc
, 0, conf
->vif
, ic_opmode
, ic_opmode
, 0);
482 DPRINTF(sc
, ATH_DEBUG_FATAL
,
483 "%s: Unable to attach vap, error: %d\n",
493 static void ath9k_remove_interface(struct ieee80211_hw
*hw
,
494 struct ieee80211_if_init_conf
*conf
)
496 struct ath_softc
*sc
= hw
->priv
;
497 int error
, flags
= 0;
499 DPRINTF(sc
, ATH_DEBUG_CONFIG
, "%s: Detach VAP\n", __func__
);
501 flags
|= ATH_IF_HW_OFF
;
503 error
= ath_vap_down(sc
, 0, flags
);
505 DPRINTF(sc
, ATH_DEBUG_FATAL
,
506 "%s: Unable to down vap, error: %d\n", __func__
, error
);
508 error
= ath_vap_detach(sc
, 0);
510 DPRINTF(sc
, ATH_DEBUG_FATAL
,
511 "%s: Unable to detach vap, error: %d\n",
515 static int ath9k_config(struct ieee80211_hw
*hw
,
516 struct ieee80211_conf
*conf
)
518 struct ath_softc
*sc
= hw
->priv
;
519 struct ieee80211_channel
*curchan
= hw
->conf
.channel
;
520 struct hal_channel hchan
;
522 DPRINTF(sc
, ATH_DEBUG_CONFIG
, "%s: Set channel: %d MHz\n",
524 curchan
->center_freq
);
526 hchan
.channel
= curchan
->center_freq
;
527 hchan
.channelFlags
= ath_chan2flags(curchan
, sc
);
528 sc
->sc_config
.txpowlimit
= 2 * conf
->power_level
;
530 /* set h/w channel */
531 if (ath_set_channel(sc
, &hchan
) < 0)
532 DPRINTF(sc
, ATH_DEBUG_FATAL
, "%s: Unable to set channel\n",
538 static int ath9k_config_interface(struct ieee80211_hw
*hw
,
539 struct ieee80211_vif
*vif
,
540 struct ieee80211_if_conf
*conf
)
542 struct ath_softc
*sc
= hw
->priv
;
543 int error
= 0, flags
= 0;
544 struct sk_buff
*beacon
;
550 case IEEE80211_IF_TYPE_STA
:
551 /* XXX: Handle (conf->changed & IEEE80211_IFCC_SSID) */
552 flags
|= ATH_IF_HW_ON
;
553 /* sync with next received beacon */
554 flags
|= ATH_IF_BEACON_SYNC
;
556 DPRINTF(sc
, ATH_DEBUG_CONFIG
, "%s: Bring up VAP: %d\n",
559 error
= ath_vap_up(sc
, 0, conf
->bssid
, 0, flags
);
561 DPRINTF(sc
, ATH_DEBUG_FATAL
,
562 "%s: Unable to bring up VAP: %d, error: %d\n",
568 case IEEE80211_IF_TYPE_IBSS
:
569 if (!(conf
->changed
& IEEE80211_IFCC_BEACON
))
571 beacon
= ieee80211_beacon_get(hw
, vif
);
574 ath9k_beacon_update(hw
, beacon
);
582 #define SUPPORTED_FILTERS \
583 (FIF_PROMISC_IN_BSS | \
587 FIF_BCN_PRBRESP_PROMISC | \
590 /* Accept unicast, bcast and mcast frames */
592 static void ath9k_configure_filter(struct ieee80211_hw
*hw
,
593 unsigned int changed_flags
,
594 unsigned int *total_flags
,
596 struct dev_mc_list
*mclist
)
598 struct ath_softc
*sc
= hw
->priv
;
600 changed_flags
&= SUPPORTED_FILTERS
;
601 *total_flags
&= SUPPORTED_FILTERS
;
603 if (changed_flags
& FIF_BCN_PRBRESP_PROMISC
) {
604 if (*total_flags
& FIF_BCN_PRBRESP_PROMISC
)
611 static void ath9k_sta_notify(struct ieee80211_hw
*hw
,
612 struct ieee80211_vif
*vif
,
613 enum sta_notify_cmd cmd
,
616 struct ath_softc
*sc
= hw
->priv
;
619 DECLARE_MAC_BUF(mac
);
621 spin_lock_irqsave(&sc
->node_lock
, flags
);
622 an
= ath_node_find(sc
, (u8
*) addr
);
623 spin_unlock_irqrestore(&sc
->node_lock
, flags
);
627 spin_lock_irqsave(&sc
->node_lock
, flags
);
629 ath_node_attach(sc
, (u8
*)addr
, 0);
630 DPRINTF(sc
, ATH_DEBUG_NODE
, "%s: Attach a node: %s\n",
632 print_mac(mac
, addr
));
634 ath_node_get(sc
, (u8
*)addr
);
636 spin_unlock_irqrestore(&sc
->node_lock
, flags
);
638 case STA_NOTIFY_REMOVE
:
640 DPRINTF(sc
, ATH_DEBUG_FATAL
,
641 "%s: Removal of a non-existent node\n",
644 ath_node_put(sc
, an
, ATH9K_BH_STATUS_INTACT
);
645 DPRINTF(sc
, ATH_DEBUG_NODE
, "%s: Put a node: %s\n",
647 print_mac(mac
, addr
));
655 static int ath9k_conf_tx(struct ieee80211_hw
*hw
,
657 const struct ieee80211_tx_queue_params
*params
)
659 struct ath_softc
*sc
= hw
->priv
;
660 struct hal_txq_info qi
;
663 if (queue
>= WME_NUM_AC
)
666 qi
.tqi_aifs
= params
->aifs
;
667 qi
.tqi_cwmin
= params
->cw_min
;
668 qi
.tqi_cwmax
= params
->cw_max
;
669 qi
.tqi_burstTime
= params
->txop
;
670 qnum
= ath_get_hal_qnum(queue
, sc
);
672 DPRINTF(sc
, ATH_DEBUG_CONFIG
,
673 "%s: Configure tx [queue/halq] [%d/%d], "
674 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
683 ret
= ath_txq_update(sc
, qnum
, &qi
);
685 DPRINTF(sc
, ATH_DEBUG_FATAL
,
686 "%s: TXQ Update failed\n", __func__
);
691 static int ath9k_set_key(struct ieee80211_hw
*hw
,
692 enum set_key_cmd cmd
,
693 const u8
*local_addr
,
695 struct ieee80211_key_conf
*key
)
697 struct ath_softc
*sc
= hw
->priv
;
700 DPRINTF(sc
, ATH_DEBUG_KEYCACHE
, " %s: Set HW Key\n", __func__
);
704 ret
= ath_key_config(sc
, addr
, key
);
706 set_bit(key
->keyidx
, sc
->sc_keymap
);
707 key
->hw_key_idx
= key
->keyidx
;
708 /* push IV and Michael MIC generation to stack */
709 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
710 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
714 ath_key_delete(sc
, key
);
715 clear_bit(key
->keyidx
, sc
->sc_keymap
);
716 sc
->sc_keytype
= HAL_CIPHER_CLR
;
725 static void ath9k_ht_conf(struct ath_softc
*sc
,
726 struct ieee80211_bss_conf
*bss_conf
)
728 #define IEEE80211_HT_CAP_40MHZ_INTOLERANT BIT(14)
729 struct ath_ht_info
*ht_info
= &sc
->sc_ht_info
;
731 if (bss_conf
->assoc_ht
) {
732 ht_info
->ext_chan_offset
=
733 bss_conf
->ht_bss_conf
->bss_cap
&
734 IEEE80211_HT_IE_CHA_SEC_OFFSET
;
736 if (!(bss_conf
->ht_conf
->cap
&
737 IEEE80211_HT_CAP_40MHZ_INTOLERANT
) &&
738 (bss_conf
->ht_bss_conf
->bss_cap
&
739 IEEE80211_HT_IE_CHA_WIDTH
))
740 ht_info
->tx_chan_width
= HAL_HT_MACMODE_2040
;
742 ht_info
->tx_chan_width
= HAL_HT_MACMODE_20
;
744 cwm_action_mac_change_chwidth(sc
, ht_info
->tx_chan_width
);
745 ht_info
->maxampdu
= 1 << (IEEE80211_HTCAP_MAXRXAMPDU_FACTOR
+
746 bss_conf
->ht_conf
->ampdu_factor
);
747 ht_info
->mpdudensity
=
748 parse_mpdudensity(bss_conf
->ht_conf
->ampdu_density
);
752 #undef IEEE80211_HT_CAP_40MHZ_INTOLERANT
755 static void ath9k_bss_assoc_info(struct ath_softc
*sc
,
756 struct ieee80211_bss_conf
*bss_conf
)
758 struct ieee80211_hw
*hw
= sc
->hw
;
759 struct ieee80211_channel
*curchan
= hw
->conf
.channel
;
760 struct hal_channel hchan
;
762 if (bss_conf
->assoc
) {
763 /* FIXME : Do we need any other info
764 * which is part of association */
765 DPRINTF(sc
, ATH_DEBUG_CONFIG
, "%s: Bss Info ASSOC %d\n",
768 sc
->sc_curaid
= bss_conf
->aid
;
770 DPRINTF(sc
, ATH_DEBUG_CONFIG
, "%s: Set channel: %d MHz\n",
772 curchan
->center_freq
);
774 hchan
.channel
= curchan
->center_freq
;
775 hchan
.channelFlags
= ath_chan2flags(curchan
, sc
);
777 /* set h/w channel */
778 if (ath_set_channel(sc
, &hchan
) < 0)
779 DPRINTF(sc
, ATH_DEBUG_FATAL
,
780 "%s: Unable to set channel\n",
783 DPRINTF(sc
, ATH_DEBUG_CONFIG
,
784 "%s: Bss Info DISSOC\n", __func__
);
789 static void ath9k_bss_info_changed(struct ieee80211_hw
*hw
,
790 struct ieee80211_vif
*vif
,
791 struct ieee80211_bss_conf
*bss_conf
,
794 struct ath_softc
*sc
= hw
->priv
;
796 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
797 DPRINTF(sc
, ATH_DEBUG_CONFIG
, "%s: BSS Changed PREAMBLE %d\n",
799 bss_conf
->use_short_preamble
);
800 if (bss_conf
->use_short_preamble
)
801 sc
->sc_flags
|= ATH_PREAMBLE_SHORT
;
803 sc
->sc_flags
&= ~ATH_PREAMBLE_SHORT
;
806 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
807 DPRINTF(sc
, ATH_DEBUG_CONFIG
, "%s: BSS Changed CTS PROT %d\n",
809 bss_conf
->use_cts_prot
);
810 if (bss_conf
->use_cts_prot
&&
811 hw
->conf
.channel
->band
!= IEEE80211_BAND_5GHZ
)
812 sc
->sc_flags
|= ATH_PROTECT_ENABLE
;
814 sc
->sc_flags
&= ~ATH_PROTECT_ENABLE
;
817 if (changed
& BSS_CHANGED_HT
) {
818 DPRINTF(sc
, ATH_DEBUG_CONFIG
, "%s: BSS Changed HT %d\n",
821 ath9k_ht_conf(sc
, bss_conf
);
824 if (changed
& BSS_CHANGED_ASSOC
) {
825 DPRINTF(sc
, ATH_DEBUG_CONFIG
, "%s: BSS Changed ASSOC %d\n",
828 ath9k_bss_assoc_info(sc
, bss_conf
);
832 static u64
ath9k_get_tsf(struct ieee80211_hw
*hw
)
835 struct ath_softc
*sc
= hw
->priv
;
836 struct ath_hal
*ah
= sc
->sc_ah
;
838 tsf
= ath9k_hw_gettsf64(ah
);
843 static void ath9k_reset_tsf(struct ieee80211_hw
*hw
)
845 struct ath_softc
*sc
= hw
->priv
;
846 struct ath_hal
*ah
= sc
->sc_ah
;
848 ath9k_hw_reset_tsf(ah
);
851 static int ath9k_ampdu_action(struct ieee80211_hw
*hw
,
852 enum ieee80211_ampdu_mlme_action action
,
857 struct ath_softc
*sc
= hw
->priv
;
861 case IEEE80211_AMPDU_RX_START
:
862 ret
= ath_rx_aggr_start(sc
, addr
, tid
, ssn
);
864 DPRINTF(sc
, ATH_DEBUG_FATAL
,
865 "%s: Unable to start RX aggregation\n",
868 case IEEE80211_AMPDU_RX_STOP
:
869 ret
= ath_rx_aggr_stop(sc
, addr
, tid
);
871 DPRINTF(sc
, ATH_DEBUG_FATAL
,
872 "%s: Unable to stop RX aggregation\n",
875 case IEEE80211_AMPDU_TX_START
:
876 ret
= ath_tx_aggr_start(sc
, addr
, tid
, ssn
);
878 DPRINTF(sc
, ATH_DEBUG_FATAL
,
879 "%s: Unable to start TX aggregation\n",
882 ieee80211_start_tx_ba_cb_irqsafe(hw
, (u8
*)addr
, tid
);
884 case IEEE80211_AMPDU_TX_STOP
:
885 ret
= ath_tx_aggr_stop(sc
, addr
, tid
);
887 DPRINTF(sc
, ATH_DEBUG_FATAL
,
888 "%s: Unable to stop TX aggregation\n",
891 ieee80211_stop_tx_ba_cb_irqsafe(hw
, (u8
*)addr
, tid
);
894 DPRINTF(sc
, ATH_DEBUG_FATAL
,
895 "%s: Unknown AMPDU action\n", __func__
);
901 static struct ieee80211_ops ath9k_ops
= {
903 .start
= ath9k_start
,
905 .add_interface
= ath9k_add_interface
,
906 .remove_interface
= ath9k_remove_interface
,
907 .config
= ath9k_config
,
908 .config_interface
= ath9k_config_interface
,
909 .configure_filter
= ath9k_configure_filter
,
911 .sta_notify
= ath9k_sta_notify
,
912 .conf_tx
= ath9k_conf_tx
,
913 .get_tx_stats
= NULL
,
914 .bss_info_changed
= ath9k_bss_info_changed
,
916 .set_key
= ath9k_set_key
,
918 .get_tkip_seq
= NULL
,
919 .set_rts_threshold
= NULL
,
920 .set_frag_threshold
= NULL
,
921 .set_retry_limit
= NULL
,
922 .get_tsf
= ath9k_get_tsf
,
923 .reset_tsf
= ath9k_reset_tsf
,
924 .tx_last_beacon
= NULL
,
925 .ampdu_action
= ath9k_ampdu_action
928 u_int32_t
ath_chan2flags(struct ieee80211_channel
*chan
,
929 struct ath_softc
*sc
)
931 struct ieee80211_hw
*hw
= sc
->hw
;
932 struct ath_ht_info
*ht_info
= &sc
->sc_ht_info
;
934 if (sc
->sc_scanning
) {
935 if (chan
->band
== IEEE80211_BAND_5GHZ
) {
936 if (ath_check_chanflags(chan
, CHANNEL_A_HT20
, sc
))
937 return CHANNEL_A_HT20
;
941 if (ath_check_chanflags(chan
, CHANNEL_G_HT20
, sc
))
942 return CHANNEL_G_HT20
;
943 else if (ath_check_chanflags(chan
, CHANNEL_G
, sc
))
949 if (chan
->band
== IEEE80211_BAND_2GHZ
) {
950 if (!hw
->conf
.ht_conf
.ht_supported
) {
951 if (ath_check_chanflags(chan
, CHANNEL_G
, sc
))
956 if ((ht_info
->ext_chan_offset
==
957 IEEE80211_HT_IE_CHA_SEC_NONE
) &&
958 (ht_info
->tx_chan_width
== HAL_HT_MACMODE_20
))
959 return CHANNEL_G_HT20
;
960 if ((ht_info
->ext_chan_offset
==
961 IEEE80211_HT_IE_CHA_SEC_ABOVE
) &&
962 (ht_info
->tx_chan_width
== HAL_HT_MACMODE_2040
))
963 return CHANNEL_G_HT40PLUS
;
964 if ((ht_info
->ext_chan_offset
==
965 IEEE80211_HT_IE_CHA_SEC_BELOW
) &&
966 (ht_info
->tx_chan_width
== HAL_HT_MACMODE_2040
))
967 return CHANNEL_G_HT40MINUS
;
970 if (!hw
->conf
.ht_conf
.ht_supported
)
972 if ((ht_info
->ext_chan_offset
==
973 IEEE80211_HT_IE_CHA_SEC_NONE
) &&
974 (ht_info
->tx_chan_width
== HAL_HT_MACMODE_20
))
975 return CHANNEL_A_HT20
;
976 if ((ht_info
->ext_chan_offset
==
977 IEEE80211_HT_IE_CHA_SEC_ABOVE
) &&
978 (ht_info
->tx_chan_width
== HAL_HT_MACMODE_2040
))
979 return CHANNEL_A_HT40PLUS
;
980 if ((ht_info
->ext_chan_offset
==
981 IEEE80211_HT_IE_CHA_SEC_BELOW
) &&
982 (ht_info
->tx_chan_width
== HAL_HT_MACMODE_2040
))
983 return CHANNEL_A_HT40MINUS
;
989 void ath_setup_channel_list(struct ath_softc
*sc
,
990 enum ieee80211_clist_cmd cmd
,
991 const struct hal_channel
*chans
,
993 const u_int8_t
*regclassids
,
997 const struct hal_channel
*c
;
998 int i
, a
= 0, b
= 0, flags
;
1000 if (countrycode
== CTRY_DEFAULT
) {
1001 for (i
= 0; i
< nchan
; i
++) {
1004 /* XXX: Ah! make more readable, and
1005 * idententation friendly */
1006 if (IS_CHAN_2GHZ(c
) &&
1007 !test_update_chan(IEEE80211_BAND_2GHZ
, c
, sc
)) {
1008 sc
->channels
[IEEE80211_BAND_2GHZ
][a
].band
=
1009 IEEE80211_BAND_2GHZ
;
1010 sc
->channels
[IEEE80211_BAND_2GHZ
][a
].
1013 sc
->channels
[IEEE80211_BAND_2GHZ
][a
].max_power
=
1015 sc
->channels
[IEEE80211_BAND_2GHZ
][a
].hw_value
=
1018 if (c
->privFlags
& CHANNEL_DISALLOW_ADHOC
)
1019 flags
|= IEEE80211_CHAN_NO_IBSS
;
1020 if (IS_CHAN_PASSIVE(c
))
1021 flags
|= IEEE80211_CHAN_PASSIVE_SCAN
;
1023 sc
->channels
[IEEE80211_BAND_2GHZ
][a
].flags
=
1025 sc
->sbands
[IEEE80211_BAND_2GHZ
].n_channels
++;
1027 DPRINTF(sc
, ATH_DEBUG_CONFIG
,
1028 "%s: 2MHz channel: %d, "
1029 "channelFlags: 0x%x\n",
1033 } else if (IS_CHAN_5GHZ(c
) &&
1034 !test_update_chan(IEEE80211_BAND_5GHZ
, c
, sc
)) {
1035 sc
->channels
[IEEE80211_BAND_5GHZ
][b
].band
=
1036 IEEE80211_BAND_5GHZ
;
1037 sc
->channels
[IEEE80211_BAND_5GHZ
][b
].
1040 sc
->channels
[IEEE80211_BAND_5GHZ
][b
].max_power
=
1042 sc
->channels
[IEEE80211_BAND_5GHZ
][b
].hw_value
=
1045 if (c
->privFlags
& CHANNEL_DISALLOW_ADHOC
)
1046 flags
|= IEEE80211_CHAN_NO_IBSS
;
1047 if (IS_CHAN_PASSIVE(c
))
1048 flags
|= IEEE80211_CHAN_PASSIVE_SCAN
;
1050 sc
->channels
[IEEE80211_BAND_5GHZ
][b
].
1052 sc
->sbands
[IEEE80211_BAND_5GHZ
].n_channels
++;
1054 DPRINTF(sc
, ATH_DEBUG_CONFIG
,
1055 "%s: 5MHz channel: %d, "
1056 "channelFlags: 0x%x\n",
1065 void ath_get_beaconconfig(struct ath_softc
*sc
,
1067 struct ath_beacon_config
*conf
)
1069 struct ieee80211_hw
*hw
= sc
->hw
;
1071 /* fill in beacon config data */
1073 conf
->beacon_interval
= hw
->conf
.beacon_int
;
1074 conf
->listen_interval
= 100;
1075 conf
->dtim_count
= 1;
1076 conf
->bmiss_timeout
= ATH_DEFAULT_BMISS_LIMIT
* conf
->listen_interval
;
1079 struct sk_buff
*ath_get_beacon(struct ath_softc
*sc
,
1081 struct ath_beacon_offset
*bo
,
1082 struct ath_tx_control
*txctl
)
1087 int ath_update_beacon(struct ath_softc
*sc
,
1089 struct ath_beacon_offset
*bo
,
1090 struct sk_buff
*skb
,
1096 void ath_tx_complete(struct ath_softc
*sc
, struct sk_buff
*skb
,
1097 struct ath_xmit_status
*tx_status
, struct ath_node
*an
)
1099 struct ieee80211_hw
*hw
= sc
->hw
;
1100 struct ieee80211_tx_info
*tx_info
= IEEE80211_SKB_CB(skb
);
1102 DPRINTF(sc
, ATH_DEBUG_XMIT
,
1103 "%s: TX complete: skb: %p\n", __func__
, skb
);
1105 if (tx_info
->flags
& IEEE80211_TX_CTL_NO_ACK
||
1106 tx_info
->flags
& IEEE80211_TX_STAT_TX_FILTERED
) {
1107 /* free driver's private data area of tx_info */
1108 if (tx_info
->driver_data
[0] != NULL
)
1109 kfree(tx_info
->driver_data
[0]);
1110 tx_info
->driver_data
[0] = NULL
;
1113 if (tx_status
->flags
& ATH_TX_BAR
) {
1114 tx_info
->flags
|= IEEE80211_TX_STAT_AMPDU_NO_BACK
;
1115 tx_status
->flags
&= ~ATH_TX_BAR
;
1117 if (tx_status
->flags
)
1118 tx_info
->status
.excessive_retries
= 1;
1120 tx_info
->status
.retry_count
= tx_status
->retries
;
1122 ieee80211_tx_status(hw
, skb
);
1124 ath_node_put(sc
, an
, ATH9K_BH_STATUS_CHANGE
);
1127 int ath__rx_indicate(struct ath_softc
*sc
,
1128 struct sk_buff
*skb
,
1129 struct ath_recv_status
*status
,
1132 struct ieee80211_hw
*hw
= sc
->hw
;
1133 struct ath_node
*an
= NULL
;
1134 struct ieee80211_rx_status rx_status
;
1135 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1136 int hdrlen
= ieee80211_get_hdrlen_from_skb(skb
);
1138 enum ATH_RX_TYPE st
;
1140 /* see if any padding is done by the hw and remove it */
1142 padsize
= hdrlen
% 4;
1143 memmove(skb
->data
+ padsize
, skb
->data
, hdrlen
);
1144 skb_pull(skb
, padsize
);
1147 /* remove FCS before passing up to protocol stack */
1148 skb_trim(skb
, (skb
->len
- FCS_LEN
));
1150 /* Prepare rx status */
1151 ath9k_rx_prepare(sc
, skb
, status
, &rx_status
);
1153 if (!(keyix
== HAL_RXKEYIX_INVALID
) &&
1154 !(status
->flags
& ATH_RX_DECRYPT_ERROR
)) {
1155 rx_status
.flag
|= RX_FLAG_DECRYPTED
;
1156 } else if ((le16_to_cpu(hdr
->frame_control
) & IEEE80211_FCTL_PROTECTED
)
1157 && !(status
->flags
& ATH_RX_DECRYPT_ERROR
)
1158 && skb
->len
>= hdrlen
+ 4) {
1159 keyix
= skb
->data
[hdrlen
+ 3] >> 6;
1161 if (test_bit(keyix
, sc
->sc_keymap
))
1162 rx_status
.flag
|= RX_FLAG_DECRYPTED
;
1165 spin_lock_bh(&sc
->node_lock
);
1166 an
= ath_node_find(sc
, hdr
->addr2
);
1167 spin_unlock_bh(&sc
->node_lock
);
1170 ath_rx_input(sc
, an
,
1171 hw
->conf
.ht_conf
.ht_supported
,
1174 if (!an
|| (st
!= ATH_RX_CONSUMED
))
1175 __ieee80211_rx(hw
, skb
, &rx_status
);
1180 int ath_rx_subframe(struct ath_node
*an
,
1181 struct sk_buff
*skb
,
1182 struct ath_recv_status
*status
)
1184 struct ath_softc
*sc
= an
->an_sc
;
1185 struct ieee80211_hw
*hw
= sc
->hw
;
1186 struct ieee80211_rx_status rx_status
;
1188 /* Prepare rx status */
1189 ath9k_rx_prepare(sc
, skb
, status
, &rx_status
);
1190 if (!(status
->flags
& ATH_RX_DECRYPT_ERROR
))
1191 rx_status
.flag
|= RX_FLAG_DECRYPTED
;
1193 __ieee80211_rx(hw
, skb
, &rx_status
);
1198 enum hal_ht_macmode
ath_cwm_macmode(struct ath_softc
*sc
)
1200 return sc
->sc_ht_info
.tx_chan_width
;
1203 void ath_setup_rate(struct ath_softc
*sc
,
1204 enum wireless_mode wMode
,
1205 enum RATE_TYPE type
,
1206 const struct hal_rate_table
*rt
)
1208 int i
, maxrates
, a
= 0, b
= 0;
1209 struct ieee80211_supported_band
*band_2ghz
;
1210 struct ieee80211_supported_band
*band_5ghz
;
1211 struct ieee80211_rate
*rates_2ghz
;
1212 struct ieee80211_rate
*rates_5ghz
;
1214 if ((wMode
>= WIRELESS_MODE_MAX
) || (type
!= NORMAL_RATE
))
1217 band_2ghz
= &sc
->sbands
[IEEE80211_BAND_2GHZ
];
1218 band_5ghz
= &sc
->sbands
[IEEE80211_BAND_5GHZ
];
1219 rates_2ghz
= sc
->rates
[IEEE80211_BAND_2GHZ
];
1220 rates_5ghz
= sc
->rates
[IEEE80211_BAND_5GHZ
];
1222 if (rt
->rateCount
> ATH_RATE_MAX
)
1223 maxrates
= ATH_RATE_MAX
;
1225 maxrates
= rt
->rateCount
;
1227 if ((band_2ghz
->n_bitrates
!= 0) && (band_5ghz
->n_bitrates
!= 0)) {
1228 DPRINTF(sc
, ATH_DEBUG_CONFIG
,
1229 "%s: Rates already setup\n", __func__
);
1233 for (i
= 0; i
< maxrates
; i
++) {
1235 case WIRELESS_MODE_11b
:
1236 case WIRELESS_MODE_11g
:
1237 rates_2ghz
[a
].bitrate
= rt
->info
[i
].rateKbps
/ 100;
1238 rates_2ghz
[a
].hw_value
= rt
->info
[i
].rateCode
;
1240 band_2ghz
->n_bitrates
= a
;
1242 case WIRELESS_MODE_11a
:
1243 rates_5ghz
[b
].bitrate
= rt
->info
[i
].rateKbps
/ 100;
1244 rates_5ghz
[b
].hw_value
= rt
->info
[i
].rateCode
;
1246 band_5ghz
->n_bitrates
= b
;
1253 if (band_2ghz
->n_bitrates
) {
1254 for (i
= 0; i
< band_2ghz
->n_bitrates
; i
++) {
1255 DPRINTF(sc
, ATH_DEBUG_CONFIG
,
1256 "%s: 2GHz Rate: %2dMbps, ratecode: %2d\n",
1258 rates_2ghz
[i
].bitrate
/ 10,
1259 rates_2ghz
[i
].hw_value
);
1261 } else if (band_5ghz
->n_bitrates
) {
1262 for (i
= 0; i
< band_5ghz
->n_bitrates
; i
++) {
1263 DPRINTF(sc
, ATH_DEBUG_CONFIG
,
1264 "%s: 5Ghz Rate: %2dMbps, ratecode: %2d\n",
1266 rates_5ghz
[i
].bitrate
/ 10,
1267 rates_5ghz
[i
].hw_value
);
1272 static int ath_detach(struct ath_softc
*sc
)
1274 struct ieee80211_hw
*hw
= sc
->hw
;
1276 DPRINTF(sc
, ATH_DEBUG_CONFIG
, "%s: Detach ATH hw\n", __func__
);
1280 ieee80211_unregister_hw(hw
);
1282 /* unregister Rate control */
1283 ath_rate_control_unregister();
1297 static int ath_attach(u_int16_t devid
,
1298 struct ath_softc
*sc
)
1300 struct ieee80211_hw
*hw
= sc
->hw
;
1303 DPRINTF(sc
, ATH_DEBUG_CONFIG
, "%s: Attach ATH hw\n", __func__
);
1305 error
= ath_init(devid
, sc
);
1311 INIT_LIST_HEAD(&sc
->node_list
);
1312 spin_lock_init(&sc
->node_lock
);
1314 /* get mac address from hardware and set in mac80211 */
1316 SET_IEEE80211_PERM_ADDR(hw
, sc
->sc_myaddr
);
1318 /* setup channels and rates */
1320 sc
->sbands
[IEEE80211_BAND_2GHZ
].channels
=
1321 sc
->channels
[IEEE80211_BAND_2GHZ
];
1322 sc
->sbands
[IEEE80211_BAND_2GHZ
].bitrates
=
1323 sc
->rates
[IEEE80211_BAND_2GHZ
];
1324 sc
->sbands
[IEEE80211_BAND_2GHZ
].band
= IEEE80211_BAND_2GHZ
;
1326 if (sc
->sc_hashtsupport
)
1327 /* Setup HT capabilities for 2.4Ghz*/
1328 setup_ht_cap(&sc
->sbands
[IEEE80211_BAND_2GHZ
].ht_info
);
1330 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] =
1331 &sc
->sbands
[IEEE80211_BAND_2GHZ
];
1333 if (sc
->sc_ah
->ah_caps
.halWirelessModes
& ATH9K_MODE_SEL_11A
) {
1334 sc
->sbands
[IEEE80211_BAND_5GHZ
].channels
=
1335 sc
->channels
[IEEE80211_BAND_5GHZ
];
1336 sc
->sbands
[IEEE80211_BAND_5GHZ
].bitrates
=
1337 sc
->rates
[IEEE80211_BAND_5GHZ
];
1338 sc
->sbands
[IEEE80211_BAND_5GHZ
].band
=
1339 IEEE80211_BAND_5GHZ
;
1341 if (sc
->sc_hashtsupport
)
1342 /* Setup HT capabilities for 5Ghz*/
1343 setup_ht_cap(&sc
->sbands
[IEEE80211_BAND_5GHZ
].ht_info
);
1345 hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] =
1346 &sc
->sbands
[IEEE80211_BAND_5GHZ
];
1349 /* FIXME: Have to figure out proper hw init values later */
1352 hw
->ampdu_queues
= 1;
1354 /* Register rate control */
1355 hw
->rate_control_algorithm
= "ath9k_rate_control";
1356 error
= ath_rate_control_register();
1358 DPRINTF(sc
, ATH_DEBUG_FATAL
,
1359 "%s: Unable to register rate control "
1360 "algorithm:%d\n", __func__
, error
);
1361 ath_rate_control_unregister();
1365 error
= ieee80211_register_hw(hw
);
1367 ath_rate_control_unregister();
1371 /* initialize tx/rx engine */
1373 error
= ath_tx_init(sc
, ATH_TXBUF
);
1377 error
= ath_rx_init(sc
, ATH_RXBUF
);
1388 static irqreturn_t
ath_isr(int irq
, void *dev_id
)
1390 struct ath_softc
*sc
= dev_id
;
1393 /* always acknowledge the interrupt */
1394 sched
= ath_intr(sc
);
1397 case ATH_ISR_NOSCHED
:
1399 case ATH_ISR_NOTMINE
:
1402 tasklet_schedule(&sc
->intr_tq
);
1408 static int ath_pci_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
1411 struct ath_softc
*sc
;
1412 struct ieee80211_hw
*hw
;
1413 const char *athname
;
1418 if (pci_enable_device(pdev
))
1421 /* XXX 32-bit addressing only */
1422 if (pci_set_dma_mask(pdev
, 0xffffffff)) {
1423 printk(KERN_ERR
"ath_pci: 32-bit DMA not available\n");
1429 * Cache line size is used to size and align various
1430 * structures used to communicate with the hardware.
1432 pci_read_config_byte(pdev
, PCI_CACHE_LINE_SIZE
, &csz
);
1435 * Linux 2.4.18 (at least) writes the cache line size
1436 * register as a 16-bit wide register which is wrong.
1437 * We must have this setup properly for rx buffer
1438 * DMA to work so force a reasonable value here if it
1441 csz
= L1_CACHE_BYTES
/ sizeof(u_int32_t
);
1442 pci_write_config_byte(pdev
, PCI_CACHE_LINE_SIZE
, csz
);
1445 * The default setting of latency timer yields poor results,
1446 * set it to the value used by other systems. It may be worth
1447 * tweaking this setting more.
1449 pci_write_config_byte(pdev
, PCI_LATENCY_TIMER
, 0xa8);
1451 pci_set_master(pdev
);
1454 * Disable the RETRY_TIMEOUT register (0x41) to keep
1455 * PCI Tx retries from interfering with C3 CPU state.
1457 pci_read_config_dword(pdev
, 0x40, &val
);
1458 if ((val
& 0x0000ff00) != 0)
1459 pci_write_config_dword(pdev
, 0x40, val
& 0xffff00ff);
1461 ret
= pci_request_region(pdev
, 0, "ath9k");
1463 dev_err(&pdev
->dev
, "PCI memory region reserve error\n");
1468 mem
= pci_iomap(pdev
, 0, 0);
1470 printk(KERN_ERR
"PCI memory map error\n") ;
1475 hw
= ieee80211_alloc_hw(sizeof(struct ath_softc
), &ath9k_ops
);
1477 printk(KERN_ERR
"ath_pci: no memory for ieee80211_hw\n");
1481 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
1482 pci_set_drvdata(pdev
, hw
);
1489 if (ath_attach(id
->device
, sc
) != 0) {
1494 /* setup interrupt service routine */
1496 if (request_irq(pdev
->irq
, ath_isr
, IRQF_SHARED
, "ath", sc
)) {
1497 printk(KERN_ERR
"%s: request_irq failed\n",
1498 wiphy_name(hw
->wiphy
));
1503 athname
= ath9k_hw_probe(id
->vendor
, id
->device
);
1505 printk(KERN_INFO
"%s: %s: mem=0x%lx, irq=%d\n",
1506 wiphy_name(hw
->wiphy
),
1507 athname
? athname
: "Atheros ???",
1508 (unsigned long)mem
, pdev
->irq
);
1514 ieee80211_free_hw(hw
);
1516 pci_iounmap(pdev
, mem
);
1518 pci_release_region(pdev
, 0);
1520 pci_disable_device(pdev
);
1524 static void ath_pci_remove(struct pci_dev
*pdev
)
1526 struct ieee80211_hw
*hw
= pci_get_drvdata(pdev
);
1527 struct ath_softc
*sc
= hw
->priv
;
1530 free_irq(pdev
->irq
, sc
);
1532 pci_iounmap(pdev
, sc
->mem
);
1533 pci_release_region(pdev
, 0);
1534 pci_disable_device(pdev
);
1535 ieee80211_free_hw(hw
);
1540 static int ath_pci_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1542 pci_save_state(pdev
);
1543 pci_disable_device(pdev
);
1544 pci_set_power_state(pdev
, 3);
1549 static int ath_pci_resume(struct pci_dev
*pdev
)
1554 err
= pci_enable_device(pdev
);
1557 pci_restore_state(pdev
);
1559 * Suspend/Resume resets the PCI configuration space, so we have to
1560 * re-disable the RETRY_TIMEOUT register (0x41) to keep
1561 * PCI Tx retries from interfering with C3 CPU state
1563 pci_read_config_dword(pdev
, 0x40, &val
);
1564 if ((val
& 0x0000ff00) != 0)
1565 pci_write_config_dword(pdev
, 0x40, val
& 0xffff00ff);
1570 #endif /* CONFIG_PM */
1572 MODULE_DEVICE_TABLE(pci
, ath_pci_id_table
);
1574 static struct pci_driver ath_pci_driver
= {
1576 .id_table
= ath_pci_id_table
,
1577 .probe
= ath_pci_probe
,
1578 .remove
= ath_pci_remove
,
1580 .suspend
= ath_pci_suspend
,
1581 .resume
= ath_pci_resume
,
1582 #endif /* CONFIG_PM */
1585 static int __init
init_ath_pci(void)
1587 printk(KERN_INFO
"%s: %s\n", dev_info
, ATH_PCI_VERSION
);
1589 if (pci_register_driver(&ath_pci_driver
) < 0) {
1591 "ath_pci: No devices found, driver not installed.\n");
1592 pci_unregister_driver(&ath_pci_driver
);
1598 module_init(init_ath_pci
);
1600 static void __exit
exit_ath_pci(void)
1602 pci_unregister_driver(&ath_pci_driver
);
1603 printk(KERN_INFO
"%s: driver unloaded\n", dev_info
);
1605 module_exit(exit_ath_pci
);