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
);
529 /* set h/w channel */
530 if (ath_set_channel(sc
, &hchan
) < 0)
531 DPRINTF(sc
, ATH_DEBUG_FATAL
, "%s: Unable to set channel\n",
537 static int ath9k_config_interface(struct ieee80211_hw
*hw
,
538 struct ieee80211_vif
*vif
,
539 struct ieee80211_if_conf
*conf
)
541 struct ath_softc
*sc
= hw
->priv
;
542 int error
= 0, flags
= 0;
543 struct sk_buff
*beacon
;
549 case IEEE80211_IF_TYPE_STA
:
550 /* XXX: Handle (conf->changed & IEEE80211_IFCC_SSID) */
551 flags
|= ATH_IF_HW_ON
;
552 /* sync with next received beacon */
553 flags
|= ATH_IF_BEACON_SYNC
;
555 DPRINTF(sc
, ATH_DEBUG_CONFIG
, "%s: Bring up VAP: %d\n",
558 error
= ath_vap_up(sc
, 0, conf
->bssid
, 0, flags
);
560 DPRINTF(sc
, ATH_DEBUG_FATAL
,
561 "%s: Unable to bring up VAP: %d, error: %d\n",
567 case IEEE80211_IF_TYPE_IBSS
:
568 if (!(conf
->changed
& IEEE80211_IFCC_BEACON
))
570 beacon
= ieee80211_beacon_get(hw
, vif
);
573 ath9k_beacon_update(hw
, beacon
);
581 #define SUPPORTED_FILTERS \
582 (FIF_PROMISC_IN_BSS | \
586 FIF_BCN_PRBRESP_PROMISC | \
589 /* Accept unicast, bcast and mcast frames */
591 static void ath9k_configure_filter(struct ieee80211_hw
*hw
,
592 unsigned int changed_flags
,
593 unsigned int *total_flags
,
595 struct dev_mc_list
*mclist
)
597 struct ath_softc
*sc
= hw
->priv
;
599 changed_flags
&= SUPPORTED_FILTERS
;
600 *total_flags
&= SUPPORTED_FILTERS
;
602 if (changed_flags
& FIF_BCN_PRBRESP_PROMISC
) {
603 if (*total_flags
& FIF_BCN_PRBRESP_PROMISC
)
610 static void ath9k_sta_notify(struct ieee80211_hw
*hw
,
611 struct ieee80211_vif
*vif
,
612 enum sta_notify_cmd cmd
,
615 struct ath_softc
*sc
= hw
->priv
;
618 DECLARE_MAC_BUF(mac
);
620 spin_lock_irqsave(&sc
->node_lock
, flags
);
621 an
= ath_node_find(sc
, (u8
*) addr
);
622 spin_unlock_irqrestore(&sc
->node_lock
, flags
);
626 spin_lock_irqsave(&sc
->node_lock
, flags
);
628 ath_node_attach(sc
, (u8
*)addr
, 0);
629 DPRINTF(sc
, ATH_DEBUG_NODE
, "%s: Attach a node: %s\n",
631 print_mac(mac
, addr
));
633 ath_node_get(sc
, (u8
*)addr
);
635 spin_unlock_irqrestore(&sc
->node_lock
, flags
);
637 case STA_NOTIFY_REMOVE
:
639 DPRINTF(sc
, ATH_DEBUG_FATAL
,
640 "%s: Removal of a non-existent node\n",
643 ath_node_put(sc
, an
, ATH9K_BH_STATUS_INTACT
);
644 DPRINTF(sc
, ATH_DEBUG_NODE
, "%s: Put a node: %s\n",
646 print_mac(mac
, addr
));
654 static int ath9k_conf_tx(struct ieee80211_hw
*hw
,
656 const struct ieee80211_tx_queue_params
*params
)
658 struct ath_softc
*sc
= hw
->priv
;
659 struct hal_txq_info qi
;
662 if (queue
>= WME_NUM_AC
)
665 qi
.tqi_aifs
= params
->aifs
;
666 qi
.tqi_cwmin
= params
->cw_min
;
667 qi
.tqi_cwmax
= params
->cw_max
;
668 qi
.tqi_burstTime
= params
->txop
;
669 qnum
= ath_get_hal_qnum(queue
, sc
);
671 DPRINTF(sc
, ATH_DEBUG_CONFIG
,
672 "%s: Configure tx [queue/halq] [%d/%d], "
673 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
682 ret
= ath_txq_update(sc
, qnum
, &qi
);
684 DPRINTF(sc
, ATH_DEBUG_FATAL
,
685 "%s: TXQ Update failed\n", __func__
);
690 static int ath9k_set_key(struct ieee80211_hw
*hw
,
691 enum set_key_cmd cmd
,
692 const u8
*local_addr
,
694 struct ieee80211_key_conf
*key
)
696 struct ath_softc
*sc
= hw
->priv
;
699 DPRINTF(sc
, ATH_DEBUG_KEYCACHE
, " %s: Set HW Key\n", __func__
);
703 ret
= ath_key_config(sc
, addr
, key
);
705 set_bit(key
->keyidx
, sc
->sc_keymap
);
706 key
->hw_key_idx
= key
->keyidx
;
707 /* push IV and Michael MIC generation to stack */
708 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
709 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
713 ath_key_delete(sc
, key
);
714 clear_bit(key
->keyidx
, sc
->sc_keymap
);
715 sc
->sc_keytype
= HAL_CIPHER_CLR
;
724 static void ath9k_ht_conf(struct ath_softc
*sc
,
725 struct ieee80211_bss_conf
*bss_conf
)
727 #define IEEE80211_HT_CAP_40MHZ_INTOLERANT BIT(14)
728 struct ath_ht_info
*ht_info
= &sc
->sc_ht_info
;
730 if (bss_conf
->assoc_ht
) {
731 ht_info
->ext_chan_offset
=
732 bss_conf
->ht_bss_conf
->bss_cap
&
733 IEEE80211_HT_IE_CHA_SEC_OFFSET
;
735 if (!(bss_conf
->ht_conf
->cap
&
736 IEEE80211_HT_CAP_40MHZ_INTOLERANT
) &&
737 (bss_conf
->ht_bss_conf
->bss_cap
&
738 IEEE80211_HT_IE_CHA_WIDTH
))
739 ht_info
->tx_chan_width
= HAL_HT_MACMODE_2040
;
741 ht_info
->tx_chan_width
= HAL_HT_MACMODE_20
;
743 cwm_action_mac_change_chwidth(sc
, ht_info
->tx_chan_width
);
744 ht_info
->maxampdu
= 1 << (IEEE80211_HTCAP_MAXRXAMPDU_FACTOR
+
745 bss_conf
->ht_conf
->ampdu_factor
);
746 ht_info
->mpdudensity
=
747 parse_mpdudensity(bss_conf
->ht_conf
->ampdu_density
);
751 #undef IEEE80211_HT_CAP_40MHZ_INTOLERANT
754 static void ath9k_bss_assoc_info(struct ath_softc
*sc
,
755 struct ieee80211_bss_conf
*bss_conf
)
757 struct ieee80211_hw
*hw
= sc
->hw
;
758 struct ieee80211_channel
*curchan
= hw
->conf
.channel
;
759 struct hal_channel hchan
;
761 if (bss_conf
->assoc
) {
762 /* FIXME : Do we need any other info
763 * which is part of association */
764 DPRINTF(sc
, ATH_DEBUG_CONFIG
, "%s: Bss Info ASSOC %d\n",
767 sc
->sc_curaid
= bss_conf
->aid
;
769 DPRINTF(sc
, ATH_DEBUG_CONFIG
, "%s: Set channel: %d MHz\n",
771 curchan
->center_freq
);
773 hchan
.channel
= curchan
->center_freq
;
774 hchan
.channelFlags
= ath_chan2flags(curchan
, sc
);
776 /* set h/w channel */
777 if (ath_set_channel(sc
, &hchan
) < 0)
778 DPRINTF(sc
, ATH_DEBUG_FATAL
,
779 "%s: Unable to set channel\n",
782 DPRINTF(sc
, ATH_DEBUG_CONFIG
,
783 "%s: Bss Info DISSOC\n", __func__
);
788 static void ath9k_bss_info_changed(struct ieee80211_hw
*hw
,
789 struct ieee80211_vif
*vif
,
790 struct ieee80211_bss_conf
*bss_conf
,
793 struct ath_softc
*sc
= hw
->priv
;
795 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
796 DPRINTF(sc
, ATH_DEBUG_CONFIG
, "%s: BSS Changed PREAMBLE %d\n",
798 bss_conf
->use_short_preamble
);
799 if (bss_conf
->use_short_preamble
)
800 sc
->sc_flags
|= ATH_PREAMBLE_SHORT
;
802 sc
->sc_flags
&= ~ATH_PREAMBLE_SHORT
;
805 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
806 DPRINTF(sc
, ATH_DEBUG_CONFIG
, "%s: BSS Changed CTS PROT %d\n",
808 bss_conf
->use_cts_prot
);
809 if (bss_conf
->use_cts_prot
&&
810 hw
->conf
.channel
->band
!= IEEE80211_BAND_5GHZ
)
811 sc
->sc_flags
|= ATH_PROTECT_ENABLE
;
813 sc
->sc_flags
&= ~ATH_PROTECT_ENABLE
;
816 if (changed
& BSS_CHANGED_HT
) {
817 DPRINTF(sc
, ATH_DEBUG_CONFIG
, "%s: BSS Changed HT %d\n",
820 ath9k_ht_conf(sc
, bss_conf
);
823 if (changed
& BSS_CHANGED_ASSOC
) {
824 DPRINTF(sc
, ATH_DEBUG_CONFIG
, "%s: BSS Changed ASSOC %d\n",
827 ath9k_bss_assoc_info(sc
, bss_conf
);
831 static u64
ath9k_get_tsf(struct ieee80211_hw
*hw
)
834 struct ath_softc
*sc
= hw
->priv
;
835 struct ath_hal
*ah
= sc
->sc_ah
;
837 tsf
= ath9k_hw_gettsf64(ah
);
842 static void ath9k_reset_tsf(struct ieee80211_hw
*hw
)
844 struct ath_softc
*sc
= hw
->priv
;
845 struct ath_hal
*ah
= sc
->sc_ah
;
847 ath9k_hw_reset_tsf(ah
);
850 static int ath9k_ampdu_action(struct ieee80211_hw
*hw
,
851 enum ieee80211_ampdu_mlme_action action
,
856 struct ath_softc
*sc
= hw
->priv
;
860 case IEEE80211_AMPDU_RX_START
:
861 ret
= ath_rx_aggr_start(sc
, addr
, tid
, ssn
);
863 DPRINTF(sc
, ATH_DEBUG_FATAL
,
864 "%s: Unable to start RX aggregation\n",
867 case IEEE80211_AMPDU_RX_STOP
:
868 ret
= ath_rx_aggr_stop(sc
, addr
, tid
);
870 DPRINTF(sc
, ATH_DEBUG_FATAL
,
871 "%s: Unable to stop RX aggregation\n",
874 case IEEE80211_AMPDU_TX_START
:
875 ret
= ath_tx_aggr_start(sc
, addr
, tid
, ssn
);
877 DPRINTF(sc
, ATH_DEBUG_FATAL
,
878 "%s: Unable to start TX aggregation\n",
881 ieee80211_start_tx_ba_cb_irqsafe(hw
, (u8
*)addr
, tid
);
883 case IEEE80211_AMPDU_TX_STOP
:
884 ret
= ath_tx_aggr_stop(sc
, addr
, tid
);
886 DPRINTF(sc
, ATH_DEBUG_FATAL
,
887 "%s: Unable to stop TX aggregation\n",
890 ieee80211_stop_tx_ba_cb_irqsafe(hw
, (u8
*)addr
, tid
);
893 DPRINTF(sc
, ATH_DEBUG_FATAL
,
894 "%s: Unknown AMPDU action\n", __func__
);
900 static struct ieee80211_ops ath9k_ops
= {
902 .start
= ath9k_start
,
904 .add_interface
= ath9k_add_interface
,
905 .remove_interface
= ath9k_remove_interface
,
906 .config
= ath9k_config
,
907 .config_interface
= ath9k_config_interface
,
908 .configure_filter
= ath9k_configure_filter
,
910 .sta_notify
= ath9k_sta_notify
,
911 .conf_tx
= ath9k_conf_tx
,
912 .get_tx_stats
= NULL
,
913 .bss_info_changed
= ath9k_bss_info_changed
,
915 .set_key
= ath9k_set_key
,
917 .get_tkip_seq
= NULL
,
918 .set_rts_threshold
= NULL
,
919 .set_frag_threshold
= NULL
,
920 .set_retry_limit
= NULL
,
921 .get_tsf
= ath9k_get_tsf
,
922 .reset_tsf
= ath9k_reset_tsf
,
923 .tx_last_beacon
= NULL
,
924 .ampdu_action
= ath9k_ampdu_action
927 u_int32_t
ath_chan2flags(struct ieee80211_channel
*chan
,
928 struct ath_softc
*sc
)
930 struct ieee80211_hw
*hw
= sc
->hw
;
931 struct ath_ht_info
*ht_info
= &sc
->sc_ht_info
;
933 if (sc
->sc_scanning
) {
934 if (chan
->band
== IEEE80211_BAND_5GHZ
) {
935 if (ath_check_chanflags(chan
, CHANNEL_A_HT20
, sc
))
936 return CHANNEL_A_HT20
;
940 if (ath_check_chanflags(chan
, CHANNEL_G_HT20
, sc
))
941 return CHANNEL_G_HT20
;
942 else if (ath_check_chanflags(chan
, CHANNEL_G
, sc
))
948 if (chan
->band
== IEEE80211_BAND_2GHZ
) {
949 if (!hw
->conf
.ht_conf
.ht_supported
) {
950 if (ath_check_chanflags(chan
, CHANNEL_G
, sc
))
955 if ((ht_info
->ext_chan_offset
==
956 IEEE80211_HT_IE_CHA_SEC_NONE
) &&
957 (ht_info
->tx_chan_width
== HAL_HT_MACMODE_20
))
958 return CHANNEL_G_HT20
;
959 if ((ht_info
->ext_chan_offset
==
960 IEEE80211_HT_IE_CHA_SEC_ABOVE
) &&
961 (ht_info
->tx_chan_width
== HAL_HT_MACMODE_2040
))
962 return CHANNEL_G_HT40PLUS
;
963 if ((ht_info
->ext_chan_offset
==
964 IEEE80211_HT_IE_CHA_SEC_BELOW
) &&
965 (ht_info
->tx_chan_width
== HAL_HT_MACMODE_2040
))
966 return CHANNEL_G_HT40MINUS
;
969 if (!hw
->conf
.ht_conf
.ht_supported
)
971 if ((ht_info
->ext_chan_offset
==
972 IEEE80211_HT_IE_CHA_SEC_NONE
) &&
973 (ht_info
->tx_chan_width
== HAL_HT_MACMODE_20
))
974 return CHANNEL_A_HT20
;
975 if ((ht_info
->ext_chan_offset
==
976 IEEE80211_HT_IE_CHA_SEC_ABOVE
) &&
977 (ht_info
->tx_chan_width
== HAL_HT_MACMODE_2040
))
978 return CHANNEL_A_HT40PLUS
;
979 if ((ht_info
->ext_chan_offset
==
980 IEEE80211_HT_IE_CHA_SEC_BELOW
) &&
981 (ht_info
->tx_chan_width
== HAL_HT_MACMODE_2040
))
982 return CHANNEL_A_HT40MINUS
;
988 void ath_setup_channel_list(struct ath_softc
*sc
,
989 enum ieee80211_clist_cmd cmd
,
990 const struct hal_channel
*chans
,
992 const u_int8_t
*regclassids
,
996 const struct hal_channel
*c
;
997 int i
, a
= 0, b
= 0, flags
;
999 if (countrycode
== CTRY_DEFAULT
) {
1000 for (i
= 0; i
< nchan
; i
++) {
1003 /* XXX: Ah! make more readable, and
1004 * idententation friendly */
1005 if (IS_CHAN_2GHZ(c
) &&
1006 !test_update_chan(IEEE80211_BAND_2GHZ
, c
, sc
)) {
1007 sc
->channels
[IEEE80211_BAND_2GHZ
][a
].band
=
1008 IEEE80211_BAND_2GHZ
;
1009 sc
->channels
[IEEE80211_BAND_2GHZ
][a
].
1012 sc
->channels
[IEEE80211_BAND_2GHZ
][a
].max_power
=
1014 sc
->channels
[IEEE80211_BAND_2GHZ
][a
].hw_value
=
1017 if (c
->privFlags
& CHANNEL_DISALLOW_ADHOC
)
1018 flags
|= IEEE80211_CHAN_NO_IBSS
;
1019 if (IS_CHAN_PASSIVE(c
))
1020 flags
|= IEEE80211_CHAN_PASSIVE_SCAN
;
1022 sc
->channels
[IEEE80211_BAND_2GHZ
][a
].flags
=
1024 sc
->sbands
[IEEE80211_BAND_2GHZ
].n_channels
++;
1026 DPRINTF(sc
, ATH_DEBUG_CONFIG
,
1027 "%s: 2MHz channel: %d, "
1028 "channelFlags: 0x%x\n",
1032 } else if (IS_CHAN_5GHZ(c
) &&
1033 !test_update_chan(IEEE80211_BAND_5GHZ
, c
, sc
)) {
1034 sc
->channels
[IEEE80211_BAND_5GHZ
][b
].band
=
1035 IEEE80211_BAND_5GHZ
;
1036 sc
->channels
[IEEE80211_BAND_5GHZ
][b
].
1039 sc
->channels
[IEEE80211_BAND_5GHZ
][b
].max_power
=
1041 sc
->channels
[IEEE80211_BAND_5GHZ
][b
].hw_value
=
1044 if (c
->privFlags
& CHANNEL_DISALLOW_ADHOC
)
1045 flags
|= IEEE80211_CHAN_NO_IBSS
;
1046 if (IS_CHAN_PASSIVE(c
))
1047 flags
|= IEEE80211_CHAN_PASSIVE_SCAN
;
1049 sc
->channels
[IEEE80211_BAND_5GHZ
][b
].
1051 sc
->sbands
[IEEE80211_BAND_5GHZ
].n_channels
++;
1053 DPRINTF(sc
, ATH_DEBUG_CONFIG
,
1054 "%s: 5MHz channel: %d, "
1055 "channelFlags: 0x%x\n",
1064 void ath__update_txpow(struct ath_softc
*sc
,
1065 u_int16_t txpowlimit
,
1066 u_int16_t txpowlevel
)
1071 void ath_get_beaconconfig(struct ath_softc
*sc
,
1073 struct ath_beacon_config
*conf
)
1075 struct ieee80211_hw
*hw
= sc
->hw
;
1077 /* fill in beacon config data */
1079 conf
->beacon_interval
= hw
->conf
.beacon_int
;
1080 conf
->listen_interval
= 100;
1081 conf
->dtim_count
= 1;
1082 conf
->bmiss_timeout
= ATH_DEFAULT_BMISS_LIMIT
* conf
->listen_interval
;
1085 struct sk_buff
*ath_get_beacon(struct ath_softc
*sc
,
1087 struct ath_beacon_offset
*bo
,
1088 struct ath_tx_control
*txctl
)
1093 int ath_update_beacon(struct ath_softc
*sc
,
1095 struct ath_beacon_offset
*bo
,
1096 struct sk_buff
*skb
,
1102 void ath_tx_complete(struct ath_softc
*sc
, struct sk_buff
*skb
,
1103 struct ath_xmit_status
*tx_status
, struct ath_node
*an
)
1105 struct ieee80211_hw
*hw
= sc
->hw
;
1106 struct ieee80211_tx_info
*tx_info
= IEEE80211_SKB_CB(skb
);
1108 DPRINTF(sc
, ATH_DEBUG_XMIT
,
1109 "%s: TX complete: skb: %p\n", __func__
, skb
);
1111 if (tx_info
->flags
& IEEE80211_TX_CTL_NO_ACK
||
1112 tx_info
->flags
& IEEE80211_TX_STAT_TX_FILTERED
) {
1113 /* free driver's private data area of tx_info */
1114 if (tx_info
->driver_data
[0] != NULL
)
1115 kfree(tx_info
->driver_data
[0]);
1116 tx_info
->driver_data
[0] = NULL
;
1119 if (tx_status
->flags
& ATH_TX_BAR
) {
1120 tx_info
->flags
|= IEEE80211_TX_STAT_AMPDU_NO_BACK
;
1121 tx_status
->flags
&= ~ATH_TX_BAR
;
1123 if (tx_status
->flags
)
1124 tx_info
->status
.excessive_retries
= 1;
1126 tx_info
->status
.retry_count
= tx_status
->retries
;
1128 ieee80211_tx_status(hw
, skb
);
1130 ath_node_put(sc
, an
, ATH9K_BH_STATUS_CHANGE
);
1133 int ath__rx_indicate(struct ath_softc
*sc
,
1134 struct sk_buff
*skb
,
1135 struct ath_recv_status
*status
,
1138 struct ieee80211_hw
*hw
= sc
->hw
;
1139 struct ath_node
*an
= NULL
;
1140 struct ieee80211_rx_status rx_status
;
1141 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1142 int hdrlen
= ieee80211_get_hdrlen_from_skb(skb
);
1144 enum ATH_RX_TYPE st
;
1146 /* see if any padding is done by the hw and remove it */
1148 padsize
= hdrlen
% 4;
1149 memmove(skb
->data
+ padsize
, skb
->data
, hdrlen
);
1150 skb_pull(skb
, padsize
);
1153 /* remove FCS before passing up to protocol stack */
1154 skb_trim(skb
, (skb
->len
- FCS_LEN
));
1156 /* Prepare rx status */
1157 ath9k_rx_prepare(sc
, skb
, status
, &rx_status
);
1159 if (!(keyix
== HAL_RXKEYIX_INVALID
) &&
1160 !(status
->flags
& ATH_RX_DECRYPT_ERROR
)) {
1161 rx_status
.flag
|= RX_FLAG_DECRYPTED
;
1162 } else if ((le16_to_cpu(hdr
->frame_control
) & IEEE80211_FCTL_PROTECTED
)
1163 && !(status
->flags
& ATH_RX_DECRYPT_ERROR
)
1164 && skb
->len
>= hdrlen
+ 4) {
1165 keyix
= skb
->data
[hdrlen
+ 3] >> 6;
1167 if (test_bit(keyix
, sc
->sc_keymap
))
1168 rx_status
.flag
|= RX_FLAG_DECRYPTED
;
1171 spin_lock_bh(&sc
->node_lock
);
1172 an
= ath_node_find(sc
, hdr
->addr2
);
1173 spin_unlock_bh(&sc
->node_lock
);
1176 ath_rx_input(sc
, an
,
1177 hw
->conf
.ht_conf
.ht_supported
,
1180 if (!an
|| (st
!= ATH_RX_CONSUMED
))
1181 __ieee80211_rx(hw
, skb
, &rx_status
);
1186 int ath_rx_subframe(struct ath_node
*an
,
1187 struct sk_buff
*skb
,
1188 struct ath_recv_status
*status
)
1190 struct ath_softc
*sc
= an
->an_sc
;
1191 struct ieee80211_hw
*hw
= sc
->hw
;
1192 struct ieee80211_rx_status rx_status
;
1194 /* Prepare rx status */
1195 ath9k_rx_prepare(sc
, skb
, status
, &rx_status
);
1196 if (!(status
->flags
& ATH_RX_DECRYPT_ERROR
))
1197 rx_status
.flag
|= RX_FLAG_DECRYPTED
;
1199 __ieee80211_rx(hw
, skb
, &rx_status
);
1204 enum hal_ht_macmode
ath_cwm_macmode(struct ath_softc
*sc
)
1206 return sc
->sc_ht_info
.tx_chan_width
;
1209 void ath_setup_rate(struct ath_softc
*sc
,
1210 enum wireless_mode wMode
,
1211 enum RATE_TYPE type
,
1212 const struct hal_rate_table
*rt
)
1214 int i
, maxrates
, a
= 0, b
= 0;
1215 struct ieee80211_supported_band
*band_2ghz
;
1216 struct ieee80211_supported_band
*band_5ghz
;
1217 struct ieee80211_rate
*rates_2ghz
;
1218 struct ieee80211_rate
*rates_5ghz
;
1220 if ((wMode
>= WIRELESS_MODE_MAX
) || (type
!= NORMAL_RATE
))
1223 band_2ghz
= &sc
->sbands
[IEEE80211_BAND_2GHZ
];
1224 band_5ghz
= &sc
->sbands
[IEEE80211_BAND_5GHZ
];
1225 rates_2ghz
= sc
->rates
[IEEE80211_BAND_2GHZ
];
1226 rates_5ghz
= sc
->rates
[IEEE80211_BAND_5GHZ
];
1228 if (rt
->rateCount
> ATH_RATE_MAX
)
1229 maxrates
= ATH_RATE_MAX
;
1231 maxrates
= rt
->rateCount
;
1233 if ((band_2ghz
->n_bitrates
!= 0) && (band_5ghz
->n_bitrates
!= 0)) {
1234 DPRINTF(sc
, ATH_DEBUG_CONFIG
,
1235 "%s: Rates already setup\n", __func__
);
1239 for (i
= 0; i
< maxrates
; i
++) {
1241 case WIRELESS_MODE_11b
:
1242 case WIRELESS_MODE_11g
:
1243 rates_2ghz
[a
].bitrate
= rt
->info
[i
].rateKbps
/ 100;
1244 rates_2ghz
[a
].hw_value
= rt
->info
[i
].rateCode
;
1246 band_2ghz
->n_bitrates
= a
;
1248 case WIRELESS_MODE_11a
:
1249 rates_5ghz
[b
].bitrate
= rt
->info
[i
].rateKbps
/ 100;
1250 rates_5ghz
[b
].hw_value
= rt
->info
[i
].rateCode
;
1252 band_5ghz
->n_bitrates
= b
;
1259 if (band_2ghz
->n_bitrates
) {
1260 for (i
= 0; i
< band_2ghz
->n_bitrates
; i
++) {
1261 DPRINTF(sc
, ATH_DEBUG_CONFIG
,
1262 "%s: 2GHz Rate: %2dMbps, ratecode: %2d\n",
1264 rates_2ghz
[i
].bitrate
/ 10,
1265 rates_2ghz
[i
].hw_value
);
1267 } else if (band_5ghz
->n_bitrates
) {
1268 for (i
= 0; i
< band_5ghz
->n_bitrates
; i
++) {
1269 DPRINTF(sc
, ATH_DEBUG_CONFIG
,
1270 "%s: 5Ghz Rate: %2dMbps, ratecode: %2d\n",
1272 rates_5ghz
[i
].bitrate
/ 10,
1273 rates_5ghz
[i
].hw_value
);
1278 static int ath_detach(struct ath_softc
*sc
)
1280 struct ieee80211_hw
*hw
= sc
->hw
;
1282 DPRINTF(sc
, ATH_DEBUG_CONFIG
, "%s: Detach ATH hw\n", __func__
);
1286 ieee80211_unregister_hw(hw
);
1288 /* unregister Rate control */
1289 ath_rate_control_unregister();
1303 static int ath_attach(u_int16_t devid
,
1304 struct ath_softc
*sc
)
1306 struct ieee80211_hw
*hw
= sc
->hw
;
1309 DPRINTF(sc
, ATH_DEBUG_CONFIG
, "%s: Attach ATH hw\n", __func__
);
1311 error
= ath_init(devid
, sc
);
1317 INIT_LIST_HEAD(&sc
->node_list
);
1318 spin_lock_init(&sc
->node_lock
);
1320 /* get mac address from hardware and set in mac80211 */
1322 SET_IEEE80211_PERM_ADDR(hw
, sc
->sc_myaddr
);
1324 /* setup channels and rates */
1326 sc
->sbands
[IEEE80211_BAND_2GHZ
].channels
=
1327 sc
->channels
[IEEE80211_BAND_2GHZ
];
1328 sc
->sbands
[IEEE80211_BAND_2GHZ
].bitrates
=
1329 sc
->rates
[IEEE80211_BAND_2GHZ
];
1330 sc
->sbands
[IEEE80211_BAND_2GHZ
].band
= IEEE80211_BAND_2GHZ
;
1332 if (sc
->sc_hashtsupport
)
1333 /* Setup HT capabilities for 2.4Ghz*/
1334 setup_ht_cap(&sc
->sbands
[IEEE80211_BAND_2GHZ
].ht_info
);
1336 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] =
1337 &sc
->sbands
[IEEE80211_BAND_2GHZ
];
1339 if (sc
->sc_ah
->ah_caps
.halWirelessModes
& ATH9K_MODE_SEL_11A
) {
1340 sc
->sbands
[IEEE80211_BAND_5GHZ
].channels
=
1341 sc
->channels
[IEEE80211_BAND_5GHZ
];
1342 sc
->sbands
[IEEE80211_BAND_5GHZ
].bitrates
=
1343 sc
->rates
[IEEE80211_BAND_5GHZ
];
1344 sc
->sbands
[IEEE80211_BAND_5GHZ
].band
=
1345 IEEE80211_BAND_5GHZ
;
1347 if (sc
->sc_hashtsupport
)
1348 /* Setup HT capabilities for 5Ghz*/
1349 setup_ht_cap(&sc
->sbands
[IEEE80211_BAND_5GHZ
].ht_info
);
1351 hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] =
1352 &sc
->sbands
[IEEE80211_BAND_5GHZ
];
1355 /* FIXME: Have to figure out proper hw init values later */
1358 hw
->ampdu_queues
= 1;
1360 /* Register rate control */
1361 hw
->rate_control_algorithm
= "ath9k_rate_control";
1362 error
= ath_rate_control_register();
1364 DPRINTF(sc
, ATH_DEBUG_FATAL
,
1365 "%s: Unable to register rate control "
1366 "algorithm:%d\n", __func__
, error
);
1367 ath_rate_control_unregister();
1371 error
= ieee80211_register_hw(hw
);
1373 ath_rate_control_unregister();
1377 /* initialize tx/rx engine */
1379 error
= ath_tx_init(sc
, ATH_TXBUF
);
1383 error
= ath_rx_init(sc
, ATH_RXBUF
);
1394 static irqreturn_t
ath_isr(int irq
, void *dev_id
)
1396 struct ath_softc
*sc
= dev_id
;
1399 /* always acknowledge the interrupt */
1400 sched
= ath_intr(sc
);
1403 case ATH_ISR_NOSCHED
:
1405 case ATH_ISR_NOTMINE
:
1408 tasklet_schedule(&sc
->intr_tq
);
1414 static int ath_pci_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
1417 struct ath_softc
*sc
;
1418 struct ieee80211_hw
*hw
;
1419 const char *athname
;
1424 if (pci_enable_device(pdev
))
1427 /* XXX 32-bit addressing only */
1428 if (pci_set_dma_mask(pdev
, 0xffffffff)) {
1429 printk(KERN_ERR
"ath_pci: 32-bit DMA not available\n");
1435 * Cache line size is used to size and align various
1436 * structures used to communicate with the hardware.
1438 pci_read_config_byte(pdev
, PCI_CACHE_LINE_SIZE
, &csz
);
1441 * Linux 2.4.18 (at least) writes the cache line size
1442 * register as a 16-bit wide register which is wrong.
1443 * We must have this setup properly for rx buffer
1444 * DMA to work so force a reasonable value here if it
1447 csz
= L1_CACHE_BYTES
/ sizeof(u_int32_t
);
1448 pci_write_config_byte(pdev
, PCI_CACHE_LINE_SIZE
, csz
);
1451 * The default setting of latency timer yields poor results,
1452 * set it to the value used by other systems. It may be worth
1453 * tweaking this setting more.
1455 pci_write_config_byte(pdev
, PCI_LATENCY_TIMER
, 0xa8);
1457 pci_set_master(pdev
);
1460 * Disable the RETRY_TIMEOUT register (0x41) to keep
1461 * PCI Tx retries from interfering with C3 CPU state.
1463 pci_read_config_dword(pdev
, 0x40, &val
);
1464 if ((val
& 0x0000ff00) != 0)
1465 pci_write_config_dword(pdev
, 0x40, val
& 0xffff00ff);
1467 ret
= pci_request_region(pdev
, 0, "ath9k");
1469 dev_err(&pdev
->dev
, "PCI memory region reserve error\n");
1474 mem
= pci_iomap(pdev
, 0, 0);
1476 printk(KERN_ERR
"PCI memory map error\n") ;
1481 hw
= ieee80211_alloc_hw(sizeof(struct ath_softc
), &ath9k_ops
);
1483 printk(KERN_ERR
"ath_pci: no memory for ieee80211_hw\n");
1487 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
1488 pci_set_drvdata(pdev
, hw
);
1495 if (ath_attach(id
->device
, sc
) != 0) {
1500 /* setup interrupt service routine */
1502 if (request_irq(pdev
->irq
, ath_isr
, IRQF_SHARED
, "ath", sc
)) {
1503 printk(KERN_ERR
"%s: request_irq failed\n",
1504 wiphy_name(hw
->wiphy
));
1509 athname
= ath9k_hw_probe(id
->vendor
, id
->device
);
1511 printk(KERN_INFO
"%s: %s: mem=0x%lx, irq=%d\n",
1512 wiphy_name(hw
->wiphy
),
1513 athname
? athname
: "Atheros ???",
1514 (unsigned long)mem
, pdev
->irq
);
1520 ieee80211_free_hw(hw
);
1522 pci_iounmap(pdev
, mem
);
1524 pci_release_region(pdev
, 0);
1526 pci_disable_device(pdev
);
1530 static void ath_pci_remove(struct pci_dev
*pdev
)
1532 struct ieee80211_hw
*hw
= pci_get_drvdata(pdev
);
1533 struct ath_softc
*sc
= hw
->priv
;
1536 free_irq(pdev
->irq
, sc
);
1538 pci_iounmap(pdev
, sc
->mem
);
1539 pci_release_region(pdev
, 0);
1540 pci_disable_device(pdev
);
1541 ieee80211_free_hw(hw
);
1546 static int ath_pci_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1548 pci_save_state(pdev
);
1549 pci_disable_device(pdev
);
1550 pci_set_power_state(pdev
, 3);
1555 static int ath_pci_resume(struct pci_dev
*pdev
)
1560 err
= pci_enable_device(pdev
);
1563 pci_restore_state(pdev
);
1565 * Suspend/Resume resets the PCI configuration space, so we have to
1566 * re-disable the RETRY_TIMEOUT register (0x41) to keep
1567 * PCI Tx retries from interfering with C3 CPU state
1569 pci_read_config_dword(pdev
, 0x40, &val
);
1570 if ((val
& 0x0000ff00) != 0)
1571 pci_write_config_dword(pdev
, 0x40, val
& 0xffff00ff);
1576 #endif /* CONFIG_PM */
1578 MODULE_DEVICE_TABLE(pci
, ath_pci_id_table
);
1580 static struct pci_driver ath_pci_driver
= {
1582 .id_table
= ath_pci_id_table
,
1583 .probe
= ath_pci_probe
,
1584 .remove
= ath_pci_remove
,
1586 .suspend
= ath_pci_suspend
,
1587 .resume
= ath_pci_resume
,
1588 #endif /* CONFIG_PM */
1591 static int __init
init_ath_pci(void)
1593 printk(KERN_INFO
"%s: %s\n", dev_info
, ATH_PCI_VERSION
);
1595 if (pci_register_driver(&ath_pci_driver
) < 0) {
1597 "ath_pci: No devices found, driver not installed.\n");
1598 pci_unregister_driver(&ath_pci_driver
);
1604 module_init(init_ath_pci
);
1606 static void __exit
exit_ath_pci(void)
1608 pci_unregister_driver(&ath_pci_driver
);
1609 printk(KERN_INFO
"%s: driver unloaded\n", dev_info
);
1611 module_exit(exit_ath_pci
);