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>
23 #define ATH_PCI_VERSION "0.1"
25 static char *dev_info
= "ath9k";
27 MODULE_AUTHOR("Atheros Communications");
28 MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
29 MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
30 MODULE_LICENSE("Dual BSD/GPL");
32 static struct pci_device_id ath_pci_id_table
[] __devinitdata
= {
33 { PCI_VDEVICE(ATHEROS
, 0x0023) }, /* PCI */
34 { PCI_VDEVICE(ATHEROS
, 0x0024) }, /* PCI-E */
35 { PCI_VDEVICE(ATHEROS
, 0x0027) }, /* PCI */
36 { PCI_VDEVICE(ATHEROS
, 0x0029) }, /* PCI */
37 { PCI_VDEVICE(ATHEROS
, 0x002A) }, /* PCI-E */
41 static void ath_detach(struct ath_softc
*sc
);
43 static int ath_get_channel(struct ath_softc
*sc
,
44 struct ieee80211_channel
*chan
)
48 for (i
= 0; i
< sc
->sc_ah
->ah_nchan
; i
++) {
49 if (sc
->sc_ah
->ah_channels
[i
].channel
== chan
->center_freq
)
56 static u32
ath_get_extchanmode(struct ath_softc
*sc
,
57 struct ieee80211_channel
*chan
)
60 u8 ext_chan_offset
= sc
->sc_ht_info
.ext_chan_offset
;
61 enum ath9k_ht_macmode tx_chan_width
= sc
->sc_ht_info
.tx_chan_width
;
64 case IEEE80211_BAND_2GHZ
:
65 if ((ext_chan_offset
== IEEE80211_HT_PARAM_CHA_SEC_NONE
) &&
66 (tx_chan_width
== ATH9K_HT_MACMODE_20
))
67 chanmode
= CHANNEL_G_HT20
;
68 if ((ext_chan_offset
== IEEE80211_HT_PARAM_CHA_SEC_ABOVE
) &&
69 (tx_chan_width
== ATH9K_HT_MACMODE_2040
))
70 chanmode
= CHANNEL_G_HT40PLUS
;
71 if ((ext_chan_offset
== IEEE80211_HT_PARAM_CHA_SEC_BELOW
) &&
72 (tx_chan_width
== ATH9K_HT_MACMODE_2040
))
73 chanmode
= CHANNEL_G_HT40MINUS
;
75 case IEEE80211_BAND_5GHZ
:
76 if ((ext_chan_offset
== IEEE80211_HT_PARAM_CHA_SEC_NONE
) &&
77 (tx_chan_width
== ATH9K_HT_MACMODE_20
))
78 chanmode
= CHANNEL_A_HT20
;
79 if ((ext_chan_offset
== IEEE80211_HT_PARAM_CHA_SEC_ABOVE
) &&
80 (tx_chan_width
== ATH9K_HT_MACMODE_2040
))
81 chanmode
= CHANNEL_A_HT40PLUS
;
82 if ((ext_chan_offset
== IEEE80211_HT_PARAM_CHA_SEC_BELOW
) &&
83 (tx_chan_width
== ATH9K_HT_MACMODE_2040
))
84 chanmode
= CHANNEL_A_HT40MINUS
;
94 static int ath_setkey_tkip(struct ath_softc
*sc
,
95 struct ieee80211_key_conf
*key
,
96 struct ath9k_keyval
*hk
,
100 u8
*key_txmic
= NULL
;
102 key_txmic
= key
->key
+ NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY
;
103 key_rxmic
= key
->key
+ NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY
;
106 /* Group key installation */
107 memcpy(hk
->kv_mic
, key_rxmic
, sizeof(hk
->kv_mic
));
108 return ath_keyset(sc
, key
->keyidx
, hk
, addr
);
110 if (!sc
->sc_splitmic
) {
112 * data key goes at first index,
113 * the hal handles the MIC keys at index+64.
115 memcpy(hk
->kv_mic
, key_rxmic
, sizeof(hk
->kv_mic
));
116 memcpy(hk
->kv_txmic
, key_txmic
, sizeof(hk
->kv_txmic
));
117 return ath_keyset(sc
, key
->keyidx
, hk
, addr
);
120 * TX key goes at first index, RX key at +32.
121 * The hal handles the MIC keys at index+64.
123 memcpy(hk
->kv_mic
, key_txmic
, sizeof(hk
->kv_mic
));
124 if (!ath_keyset(sc
, key
->keyidx
, hk
, NULL
)) {
125 /* Txmic entry failed. No need to proceed further */
126 DPRINTF(sc
, ATH_DBG_KEYCACHE
,
127 "%s Setting TX MIC Key Failed\n", __func__
);
131 memcpy(hk
->kv_mic
, key_rxmic
, sizeof(hk
->kv_mic
));
132 /* XXX delete tx key on failure? */
133 return ath_keyset(sc
, key
->keyidx
+32, hk
, addr
);
136 static int ath_key_config(struct ath_softc
*sc
,
138 struct ieee80211_key_conf
*key
)
140 struct ieee80211_vif
*vif
;
141 struct ath9k_keyval hk
;
142 const u8
*mac
= NULL
;
144 enum nl80211_iftype opmode
;
146 memset(&hk
, 0, sizeof(hk
));
150 hk
.kv_type
= ATH9K_CIPHER_WEP
;
153 hk
.kv_type
= ATH9K_CIPHER_TKIP
;
156 hk
.kv_type
= ATH9K_CIPHER_AES_CCM
;
162 hk
.kv_len
= key
->keylen
;
163 memcpy(hk
.kv_val
, key
->key
, key
->keylen
);
168 vif
= sc
->sc_vaps
[0];
173 * For _M_STA mc tx, we will not setup a key at all since we never
175 * _M_STA mc rx, we will use the keyID.
176 * for _M_IBSS mc tx, we will use the keyID, and no macaddr.
177 * for _M_IBSS mc rx, we will alloc a slot and plumb the mac of the
178 * peer node. BUT we will plumb a cleartext key so that we can do
179 * perSta default key table lookup in software.
181 if (is_broadcast_ether_addr(addr
)) {
183 case NL80211_IFTYPE_STATION
:
184 /* default key: could be group WPA key
185 * or could be static WEP key */
188 case NL80211_IFTYPE_ADHOC
:
190 case NL80211_IFTYPE_AP
:
200 if (key
->alg
== ALG_TKIP
)
201 ret
= ath_setkey_tkip(sc
, key
, &hk
, mac
);
203 ret
= ath_keyset(sc
, key
->keyidx
, &hk
, mac
);
211 static void ath_key_delete(struct ath_softc
*sc
, struct ieee80211_key_conf
*key
)
215 freeslot
= (key
->keyidx
>= 4) ? 1 : 0;
216 ath_key_reset(sc
, key
->keyidx
, freeslot
);
219 static void setup_ht_cap(struct ieee80211_sta_ht_cap
*ht_info
)
221 #define ATH9K_HT_CAP_MAXRXAMPDU_65536 0x3 /* 2 ^ 16 */
222 #define ATH9K_HT_CAP_MPDUDENSITY_8 0x6 /* 8 usec */
224 ht_info
->ht_supported
= true;
225 ht_info
->cap
= IEEE80211_HT_CAP_SUP_WIDTH_20_40
|
226 IEEE80211_HT_CAP_SM_PS
|
227 IEEE80211_HT_CAP_SGI_40
|
228 IEEE80211_HT_CAP_DSSSCCK40
;
230 ht_info
->ampdu_factor
= ATH9K_HT_CAP_MAXRXAMPDU_65536
;
231 ht_info
->ampdu_density
= ATH9K_HT_CAP_MPDUDENSITY_8
;
232 /* set up supported mcs set */
233 memset(&ht_info
->mcs
, 0, sizeof(ht_info
->mcs
));
234 ht_info
->mcs
.rx_mask
[0] = 0xff;
235 ht_info
->mcs
.rx_mask
[1] = 0xff;
236 ht_info
->mcs
.tx_params
= IEEE80211_HT_MCS_TX_DEFINED
;
239 static void ath9k_ht_conf(struct ath_softc
*sc
,
240 struct ieee80211_bss_conf
*bss_conf
)
242 struct ath_ht_info
*ht_info
= &sc
->sc_ht_info
;
244 if (sc
->hw
->conf
.ht
.enabled
) {
245 ht_info
->ext_chan_offset
= bss_conf
->ht
.secondary_channel_offset
;
247 if (bss_conf
->ht
.width_40_ok
)
248 ht_info
->tx_chan_width
= ATH9K_HT_MACMODE_2040
;
250 ht_info
->tx_chan_width
= ATH9K_HT_MACMODE_20
;
252 ath9k_hw_set11nmac2040(sc
->sc_ah
, ht_info
->tx_chan_width
);
256 static void ath9k_bss_assoc_info(struct ath_softc
*sc
,
257 struct ieee80211_vif
*vif
,
258 struct ieee80211_bss_conf
*bss_conf
)
260 struct ieee80211_hw
*hw
= sc
->hw
;
261 struct ieee80211_channel
*curchan
= hw
->conf
.channel
;
262 struct ath_vap
*avp
= (void *)vif
->drv_priv
;
265 if (bss_conf
->assoc
) {
266 DPRINTF(sc
, ATH_DBG_CONFIG
, "%s: Bss Info ASSOC %d\n",
270 /* New association, store aid */
271 if (avp
->av_opmode
== ATH9K_M_STA
) {
272 sc
->sc_curaid
= bss_conf
->aid
;
273 ath9k_hw_write_associd(sc
->sc_ah
, sc
->sc_curbssid
,
277 /* Configure the beacon */
278 ath_beacon_config(sc
, 0);
279 sc
->sc_flags
|= SC_OP_BEACONS
;
281 /* Reset rssi stats */
282 sc
->sc_halstats
.ns_avgbrssi
= ATH_RSSI_DUMMY_MARKER
;
283 sc
->sc_halstats
.ns_avgrssi
= ATH_RSSI_DUMMY_MARKER
;
284 sc
->sc_halstats
.ns_avgtxrssi
= ATH_RSSI_DUMMY_MARKER
;
285 sc
->sc_halstats
.ns_avgtxrate
= ATH_RATE_DUMMY_MARKER
;
287 /* Update chainmask */
288 ath_update_chainmask(sc
, hw
->conf
.ht
.enabled
);
290 DPRINTF(sc
, ATH_DBG_CONFIG
,
291 "%s: bssid %pM aid 0x%x\n",
293 sc
->sc_curbssid
, sc
->sc_curaid
);
295 DPRINTF(sc
, ATH_DBG_CONFIG
, "%s: Set channel: %d MHz\n",
297 curchan
->center_freq
);
299 pos
= ath_get_channel(sc
, curchan
);
301 DPRINTF(sc
, ATH_DBG_FATAL
,
302 "%s: Invalid channel\n", __func__
);
306 if (hw
->conf
.ht
.enabled
)
307 sc
->sc_ah
->ah_channels
[pos
].chanmode
=
308 ath_get_extchanmode(sc
, curchan
);
310 sc
->sc_ah
->ah_channels
[pos
].chanmode
=
311 (curchan
->band
== IEEE80211_BAND_2GHZ
) ?
312 CHANNEL_G
: CHANNEL_A
;
314 /* set h/w channel */
315 if (ath_set_channel(sc
, &sc
->sc_ah
->ah_channels
[pos
]) < 0)
316 DPRINTF(sc
, ATH_DBG_FATAL
,
317 "%s: Unable to set channel\n",
320 /* Update ratectrl about the new state */
321 ath_rc_node_update(hw
, avp
->rc_node
);
324 mod_timer(&sc
->sc_ani
.timer
,
325 jiffies
+ msecs_to_jiffies(ATH_ANI_POLLINTERVAL
));
328 DPRINTF(sc
, ATH_DBG_CONFIG
,
329 "%s: Bss Info DISSOC\n", __func__
);
334 void ath_get_beaconconfig(struct ath_softc
*sc
,
336 struct ath_beacon_config
*conf
)
338 struct ieee80211_hw
*hw
= sc
->hw
;
340 /* fill in beacon config data */
342 conf
->beacon_interval
= hw
->conf
.beacon_int
;
343 conf
->listen_interval
= 100;
344 conf
->dtim_count
= 1;
345 conf
->bmiss_timeout
= ATH_DEFAULT_BMISS_LIMIT
* conf
->listen_interval
;
348 void ath_tx_complete(struct ath_softc
*sc
, struct sk_buff
*skb
,
349 struct ath_xmit_status
*tx_status
)
351 struct ieee80211_hw
*hw
= sc
->hw
;
352 struct ieee80211_tx_info
*tx_info
= IEEE80211_SKB_CB(skb
);
354 DPRINTF(sc
, ATH_DBG_XMIT
,
355 "%s: TX complete: skb: %p\n", __func__
, skb
);
357 ieee80211_tx_info_clear_status(tx_info
);
358 if (tx_info
->flags
& IEEE80211_TX_CTL_NO_ACK
||
359 tx_info
->flags
& IEEE80211_TX_STAT_TX_FILTERED
) {
360 /* free driver's private data area of tx_info, XXX: HACK! */
361 if (tx_info
->control
.vif
!= NULL
)
362 kfree(tx_info
->control
.vif
);
363 tx_info
->control
.vif
= NULL
;
366 if (tx_status
->flags
& ATH_TX_BAR
) {
367 tx_info
->flags
|= IEEE80211_TX_STAT_AMPDU_NO_BACK
;
368 tx_status
->flags
&= ~ATH_TX_BAR
;
371 if (!(tx_status
->flags
& (ATH_TX_ERROR
| ATH_TX_XRETRY
))) {
372 /* Frame was ACKed */
373 tx_info
->flags
|= IEEE80211_TX_STAT_ACK
;
376 tx_info
->status
.rates
[0].count
= tx_status
->retries
+ 1;
378 ieee80211_tx_status(hw
, skb
);
381 /********************************/
383 /********************************/
385 static void ath_led_brightness(struct led_classdev
*led_cdev
,
386 enum led_brightness brightness
)
388 struct ath_led
*led
= container_of(led_cdev
, struct ath_led
, led_cdev
);
389 struct ath_softc
*sc
= led
->sc
;
391 switch (brightness
) {
393 if (led
->led_type
== ATH_LED_ASSOC
||
394 led
->led_type
== ATH_LED_RADIO
)
395 sc
->sc_flags
&= ~SC_OP_LED_ASSOCIATED
;
396 ath9k_hw_set_gpio(sc
->sc_ah
, ATH_LED_PIN
,
397 (led
->led_type
== ATH_LED_RADIO
) ? 1 :
398 !!(sc
->sc_flags
& SC_OP_LED_ASSOCIATED
));
401 if (led
->led_type
== ATH_LED_ASSOC
)
402 sc
->sc_flags
|= SC_OP_LED_ASSOCIATED
;
403 ath9k_hw_set_gpio(sc
->sc_ah
, ATH_LED_PIN
, 0);
410 static int ath_register_led(struct ath_softc
*sc
, struct ath_led
*led
,
416 led
->led_cdev
.name
= led
->name
;
417 led
->led_cdev
.default_trigger
= trigger
;
418 led
->led_cdev
.brightness_set
= ath_led_brightness
;
420 ret
= led_classdev_register(wiphy_dev(sc
->hw
->wiphy
), &led
->led_cdev
);
422 DPRINTF(sc
, ATH_DBG_FATAL
,
423 "Failed to register led:%s", led
->name
);
429 static void ath_unregister_led(struct ath_led
*led
)
431 if (led
->registered
) {
432 led_classdev_unregister(&led
->led_cdev
);
437 static void ath_deinit_leds(struct ath_softc
*sc
)
439 ath_unregister_led(&sc
->assoc_led
);
440 sc
->sc_flags
&= ~SC_OP_LED_ASSOCIATED
;
441 ath_unregister_led(&sc
->tx_led
);
442 ath_unregister_led(&sc
->rx_led
);
443 ath_unregister_led(&sc
->radio_led
);
444 ath9k_hw_set_gpio(sc
->sc_ah
, ATH_LED_PIN
, 1);
447 static void ath_init_leds(struct ath_softc
*sc
)
452 /* Configure gpio 1 for output */
453 ath9k_hw_cfg_output(sc
->sc_ah
, ATH_LED_PIN
,
454 AR_GPIO_OUTPUT_MUX_AS_OUTPUT
);
455 /* LED off, active low */
456 ath9k_hw_set_gpio(sc
->sc_ah
, ATH_LED_PIN
, 1);
458 trigger
= ieee80211_get_radio_led_name(sc
->hw
);
459 snprintf(sc
->radio_led
.name
, sizeof(sc
->radio_led
.name
),
460 "ath9k-%s:radio", wiphy_name(sc
->hw
->wiphy
));
461 ret
= ath_register_led(sc
, &sc
->radio_led
, trigger
);
462 sc
->radio_led
.led_type
= ATH_LED_RADIO
;
466 trigger
= ieee80211_get_assoc_led_name(sc
->hw
);
467 snprintf(sc
->assoc_led
.name
, sizeof(sc
->assoc_led
.name
),
468 "ath9k-%s:assoc", wiphy_name(sc
->hw
->wiphy
));
469 ret
= ath_register_led(sc
, &sc
->assoc_led
, trigger
);
470 sc
->assoc_led
.led_type
= ATH_LED_ASSOC
;
474 trigger
= ieee80211_get_tx_led_name(sc
->hw
);
475 snprintf(sc
->tx_led
.name
, sizeof(sc
->tx_led
.name
),
476 "ath9k-%s:tx", wiphy_name(sc
->hw
->wiphy
));
477 ret
= ath_register_led(sc
, &sc
->tx_led
, trigger
);
478 sc
->tx_led
.led_type
= ATH_LED_TX
;
482 trigger
= ieee80211_get_rx_led_name(sc
->hw
);
483 snprintf(sc
->rx_led
.name
, sizeof(sc
->rx_led
.name
),
484 "ath9k-%s:rx", wiphy_name(sc
->hw
->wiphy
));
485 ret
= ath_register_led(sc
, &sc
->rx_led
, trigger
);
486 sc
->rx_led
.led_type
= ATH_LED_RX
;
496 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
498 /*******************/
500 /*******************/
502 static void ath_radio_enable(struct ath_softc
*sc
)
504 struct ath_hal
*ah
= sc
->sc_ah
;
507 spin_lock_bh(&sc
->sc_resetlock
);
508 if (!ath9k_hw_reset(ah
, ah
->ah_curchan
,
509 sc
->sc_ht_info
.tx_chan_width
,
512 sc
->sc_ht_extprotspacing
,
514 DPRINTF(sc
, ATH_DBG_FATAL
,
515 "%s: unable to reset channel %u (%uMhz) "
516 "flags 0x%x hal status %u\n", __func__
,
517 ath9k_hw_mhz2ieee(ah
,
518 ah
->ah_curchan
->channel
,
519 ah
->ah_curchan
->channelFlags
),
520 ah
->ah_curchan
->channel
,
521 ah
->ah_curchan
->channelFlags
, status
);
523 spin_unlock_bh(&sc
->sc_resetlock
);
525 ath_update_txpow(sc
);
526 if (ath_startrecv(sc
) != 0) {
527 DPRINTF(sc
, ATH_DBG_FATAL
,
528 "%s: unable to restart recv logic\n", __func__
);
532 if (sc
->sc_flags
& SC_OP_BEACONS
)
533 ath_beacon_config(sc
, ATH_IF_ID_ANY
); /* restart beacons */
535 /* Re-Enable interrupts */
536 ath9k_hw_set_interrupts(ah
, sc
->sc_imask
);
539 ath9k_hw_cfg_output(ah
, ATH_LED_PIN
,
540 AR_GPIO_OUTPUT_MUX_AS_OUTPUT
);
541 ath9k_hw_set_gpio(ah
, ATH_LED_PIN
, 0);
543 ieee80211_wake_queues(sc
->hw
);
546 static void ath_radio_disable(struct ath_softc
*sc
)
548 struct ath_hal
*ah
= sc
->sc_ah
;
552 ieee80211_stop_queues(sc
->hw
);
555 ath9k_hw_set_gpio(ah
, ATH_LED_PIN
, 1);
556 ath9k_hw_cfg_gpio_input(ah
, ATH_LED_PIN
);
558 /* Disable interrupts */
559 ath9k_hw_set_interrupts(ah
, 0);
561 ath_draintxq(sc
, false); /* clear pending tx frames */
562 ath_stoprecv(sc
); /* turn off frame recv */
563 ath_flushrecv(sc
); /* flush recv queue */
565 spin_lock_bh(&sc
->sc_resetlock
);
566 if (!ath9k_hw_reset(ah
, ah
->ah_curchan
,
567 sc
->sc_ht_info
.tx_chan_width
,
570 sc
->sc_ht_extprotspacing
,
572 DPRINTF(sc
, ATH_DBG_FATAL
,
573 "%s: unable to reset channel %u (%uMhz) "
574 "flags 0x%x hal status %u\n", __func__
,
575 ath9k_hw_mhz2ieee(ah
,
576 ah
->ah_curchan
->channel
,
577 ah
->ah_curchan
->channelFlags
),
578 ah
->ah_curchan
->channel
,
579 ah
->ah_curchan
->channelFlags
, status
);
581 spin_unlock_bh(&sc
->sc_resetlock
);
583 ath9k_hw_phy_disable(ah
);
584 ath9k_hw_setpower(ah
, ATH9K_PM_FULL_SLEEP
);
587 static bool ath_is_rfkill_set(struct ath_softc
*sc
)
589 struct ath_hal
*ah
= sc
->sc_ah
;
591 return ath9k_hw_gpio_get(ah
, ah
->ah_rfkill_gpio
) ==
592 ah
->ah_rfkill_polarity
;
595 /* h/w rfkill poll function */
596 static void ath_rfkill_poll(struct work_struct
*work
)
598 struct ath_softc
*sc
= container_of(work
, struct ath_softc
,
599 rf_kill
.rfkill_poll
.work
);
602 if (sc
->sc_flags
& SC_OP_INVALID
)
605 radio_on
= !ath_is_rfkill_set(sc
);
608 * enable/disable radio only when there is a
609 * state change in RF switch
611 if (radio_on
== !!(sc
->sc_flags
& SC_OP_RFKILL_HW_BLOCKED
)) {
612 enum rfkill_state state
;
614 if (sc
->sc_flags
& SC_OP_RFKILL_SW_BLOCKED
) {
615 state
= radio_on
? RFKILL_STATE_SOFT_BLOCKED
616 : RFKILL_STATE_HARD_BLOCKED
;
617 } else if (radio_on
) {
618 ath_radio_enable(sc
);
619 state
= RFKILL_STATE_UNBLOCKED
;
621 ath_radio_disable(sc
);
622 state
= RFKILL_STATE_HARD_BLOCKED
;
625 if (state
== RFKILL_STATE_HARD_BLOCKED
)
626 sc
->sc_flags
|= SC_OP_RFKILL_HW_BLOCKED
;
628 sc
->sc_flags
&= ~SC_OP_RFKILL_HW_BLOCKED
;
630 rfkill_force_state(sc
->rf_kill
.rfkill
, state
);
633 queue_delayed_work(sc
->hw
->workqueue
, &sc
->rf_kill
.rfkill_poll
,
634 msecs_to_jiffies(ATH_RFKILL_POLL_INTERVAL
));
637 /* s/w rfkill handler */
638 static int ath_sw_toggle_radio(void *data
, enum rfkill_state state
)
640 struct ath_softc
*sc
= data
;
643 case RFKILL_STATE_SOFT_BLOCKED
:
644 if (!(sc
->sc_flags
& (SC_OP_RFKILL_HW_BLOCKED
|
645 SC_OP_RFKILL_SW_BLOCKED
)))
646 ath_radio_disable(sc
);
647 sc
->sc_flags
|= SC_OP_RFKILL_SW_BLOCKED
;
649 case RFKILL_STATE_UNBLOCKED
:
650 if ((sc
->sc_flags
& SC_OP_RFKILL_SW_BLOCKED
)) {
651 sc
->sc_flags
&= ~SC_OP_RFKILL_SW_BLOCKED
;
652 if (sc
->sc_flags
& SC_OP_RFKILL_HW_BLOCKED
) {
653 DPRINTF(sc
, ATH_DBG_FATAL
, "Can't turn on the"
654 "radio as it is disabled by h/w \n");
657 ath_radio_enable(sc
);
665 /* Init s/w rfkill */
666 static int ath_init_sw_rfkill(struct ath_softc
*sc
)
668 sc
->rf_kill
.rfkill
= rfkill_allocate(wiphy_dev(sc
->hw
->wiphy
),
670 if (!sc
->rf_kill
.rfkill
) {
671 DPRINTF(sc
, ATH_DBG_FATAL
, "Failed to allocate rfkill\n");
675 snprintf(sc
->rf_kill
.rfkill_name
, sizeof(sc
->rf_kill
.rfkill_name
),
676 "ath9k-%s:rfkill", wiphy_name(sc
->hw
->wiphy
));
677 sc
->rf_kill
.rfkill
->name
= sc
->rf_kill
.rfkill_name
;
678 sc
->rf_kill
.rfkill
->data
= sc
;
679 sc
->rf_kill
.rfkill
->toggle_radio
= ath_sw_toggle_radio
;
680 sc
->rf_kill
.rfkill
->state
= RFKILL_STATE_UNBLOCKED
;
681 sc
->rf_kill
.rfkill
->user_claim_unsupported
= 1;
686 /* Deinitialize rfkill */
687 static void ath_deinit_rfkill(struct ath_softc
*sc
)
689 if (sc
->sc_ah
->ah_caps
.hw_caps
& ATH9K_HW_CAP_RFSILENT
)
690 cancel_delayed_work_sync(&sc
->rf_kill
.rfkill_poll
);
692 if (sc
->sc_flags
& SC_OP_RFKILL_REGISTERED
) {
693 rfkill_unregister(sc
->rf_kill
.rfkill
);
694 sc
->sc_flags
&= ~SC_OP_RFKILL_REGISTERED
;
695 sc
->rf_kill
.rfkill
= NULL
;
699 static int ath_start_rfkill_poll(struct ath_softc
*sc
)
701 if (sc
->sc_ah
->ah_caps
.hw_caps
& ATH9K_HW_CAP_RFSILENT
)
702 queue_delayed_work(sc
->hw
->workqueue
,
703 &sc
->rf_kill
.rfkill_poll
, 0);
705 if (!(sc
->sc_flags
& SC_OP_RFKILL_REGISTERED
)) {
706 if (rfkill_register(sc
->rf_kill
.rfkill
)) {
707 DPRINTF(sc
, ATH_DBG_FATAL
,
708 "Unable to register rfkill\n");
709 rfkill_free(sc
->rf_kill
.rfkill
);
711 /* Deinitialize the device */
714 free_irq(sc
->pdev
->irq
, sc
);
715 pci_iounmap(sc
->pdev
, sc
->mem
);
716 pci_release_region(sc
->pdev
, 0);
717 pci_disable_device(sc
->pdev
);
718 ieee80211_free_hw(sc
->hw
);
721 sc
->sc_flags
|= SC_OP_RFKILL_REGISTERED
;
727 #endif /* CONFIG_RFKILL */
729 static void ath_detach(struct ath_softc
*sc
)
731 struct ieee80211_hw
*hw
= sc
->hw
;
734 DPRINTF(sc
, ATH_DBG_CONFIG
, "%s: Detach ATH hw\n", __func__
);
736 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
737 ath_deinit_rfkill(sc
);
741 ieee80211_unregister_hw(hw
);
743 ath_rate_control_unregister();
744 ath_rate_detach(sc
->sc_rc
);
749 tasklet_kill(&sc
->intr_tq
);
750 tasklet_kill(&sc
->bcon_tasklet
);
752 if (!(sc
->sc_flags
& SC_OP_INVALID
))
753 ath9k_hw_setpower(sc
->sc_ah
, ATH9K_PM_AWAKE
);
755 /* cleanup tx queues */
756 for (i
= 0; i
< ATH9K_NUM_TX_QUEUES
; i
++)
757 if (ATH_TXQ_SETUP(sc
, i
))
758 ath_tx_cleanupq(sc
, &sc
->sc_txq
[i
]);
760 ath9k_hw_detach(sc
->sc_ah
);
763 static int ath_attach(u16 devid
, struct ath_softc
*sc
)
765 struct ieee80211_hw
*hw
= sc
->hw
;
768 DPRINTF(sc
, ATH_DBG_CONFIG
, "%s: Attach ATH hw\n", __func__
);
770 error
= ath_init(devid
, sc
);
774 /* get mac address from hardware and set in mac80211 */
776 SET_IEEE80211_PERM_ADDR(hw
, sc
->sc_myaddr
);
778 hw
->flags
= IEEE80211_HW_RX_INCLUDES_FCS
|
779 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING
|
780 IEEE80211_HW_SIGNAL_DBM
|
781 IEEE80211_HW_AMPDU_AGGREGATION
;
783 hw
->wiphy
->interface_modes
=
784 BIT(NL80211_IFTYPE_AP
) |
785 BIT(NL80211_IFTYPE_STATION
) |
786 BIT(NL80211_IFTYPE_ADHOC
);
789 hw
->sta_data_size
= sizeof(struct ath_node
);
790 hw
->vif_data_size
= sizeof(struct ath_vap
);
792 /* Register rate control */
793 hw
->rate_control_algorithm
= "ath9k_rate_control";
794 error
= ath_rate_control_register();
796 DPRINTF(sc
, ATH_DBG_FATAL
,
797 "%s: Unable to register rate control "
798 "algorithm:%d\n", __func__
, error
);
799 ath_rate_control_unregister();
803 if (sc
->sc_ah
->ah_caps
.hw_caps
& ATH9K_HW_CAP_HT
) {
804 setup_ht_cap(&sc
->sbands
[IEEE80211_BAND_2GHZ
].ht_cap
);
805 if (test_bit(ATH9K_MODE_11A
, sc
->sc_ah
->ah_caps
.wireless_modes
))
806 setup_ht_cap(&sc
->sbands
[IEEE80211_BAND_5GHZ
].ht_cap
);
809 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &sc
->sbands
[IEEE80211_BAND_2GHZ
];
810 if (test_bit(ATH9K_MODE_11A
, sc
->sc_ah
->ah_caps
.wireless_modes
))
811 hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] =
812 &sc
->sbands
[IEEE80211_BAND_5GHZ
];
814 /* initialize tx/rx engine */
815 error
= ath_tx_init(sc
, ATH_TXBUF
);
819 error
= ath_rx_init(sc
, ATH_RXBUF
);
823 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
824 /* Initialze h/w Rfkill */
825 if (sc
->sc_ah
->ah_caps
.hw_caps
& ATH9K_HW_CAP_RFSILENT
)
826 INIT_DELAYED_WORK(&sc
->rf_kill
.rfkill_poll
, ath_rfkill_poll
);
828 /* Initialize s/w rfkill */
829 if (ath_init_sw_rfkill(sc
))
833 error
= ieee80211_register_hw(hw
);
835 ath_rate_control_unregister();
839 /* Initialize LED control */
849 static int ath9k_start(struct ieee80211_hw
*hw
)
851 struct ath_softc
*sc
= hw
->priv
;
852 struct ieee80211_channel
*curchan
= hw
->conf
.channel
;
855 DPRINTF(sc
, ATH_DBG_CONFIG
, "%s: Starting driver with "
856 "initial channel: %d MHz\n", __func__
, curchan
->center_freq
);
858 memset(&sc
->sc_ht_info
, 0, sizeof(struct ath_ht_info
));
860 /* setup initial channel */
862 pos
= ath_get_channel(sc
, curchan
);
864 DPRINTF(sc
, ATH_DBG_FATAL
, "%s: Invalid channel\n", __func__
);
869 sc
->sc_ah
->ah_channels
[pos
].chanmode
=
870 (curchan
->band
== IEEE80211_BAND_2GHZ
) ? CHANNEL_G
: CHANNEL_A
;
872 error
= ath_open(sc
, &sc
->sc_ah
->ah_channels
[pos
]);
874 DPRINTF(sc
, ATH_DBG_FATAL
,
875 "%s: Unable to complete ath_open\n", __func__
);
879 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
880 error
= ath_start_rfkill_poll(sc
);
887 static int ath9k_tx(struct ieee80211_hw
*hw
,
890 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
891 struct ath_softc
*sc
= hw
->priv
;
892 struct ath_tx_control txctl
;
895 memset(&txctl
, 0, sizeof(struct ath_tx_control
));
898 * As a temporary workaround, assign seq# here; this will likely need
899 * to be cleaned up to work better with Beacon transmission and virtual
902 if (info
->flags
& IEEE80211_TX_CTL_ASSIGN_SEQ
) {
903 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
904 if (info
->flags
& IEEE80211_TX_CTL_FIRST_FRAGMENT
)
906 hdr
->seq_ctrl
&= cpu_to_le16(IEEE80211_SCTL_FRAG
);
907 hdr
->seq_ctrl
|= cpu_to_le16(sc
->seq_no
);
910 /* Add the padding after the header if this is not already done */
911 hdrlen
= ieee80211_get_hdrlen_from_skb(skb
);
913 padsize
= hdrlen
% 4;
914 if (skb_headroom(skb
) < padsize
)
916 skb_push(skb
, padsize
);
917 memmove(skb
->data
, skb
->data
+ padsize
, hdrlen
);
920 /* Check if a tx queue is available */
922 txctl
.txq
= ath_test_get_txq(sc
, skb
);
926 DPRINTF(sc
, ATH_DBG_XMIT
, "%s: transmitting packet, skb: %p\n",
930 if (ath_tx_start(sc
, skb
, &txctl
) != 0) {
931 DPRINTF(sc
, ATH_DBG_XMIT
, "%s: TX failed\n", __func__
);
937 dev_kfree_skb_any(skb
);
941 static void ath9k_stop(struct ieee80211_hw
*hw
)
943 struct ath_softc
*sc
= hw
->priv
;
945 if (sc
->sc_flags
& SC_OP_INVALID
) {
946 DPRINTF(sc
, ATH_DBG_ANY
, "%s: Device not present\n", __func__
);
952 DPRINTF(sc
, ATH_DBG_CONFIG
, "%s: Driver halt\n", __func__
);
955 static int ath9k_add_interface(struct ieee80211_hw
*hw
,
956 struct ieee80211_if_init_conf
*conf
)
958 struct ath_softc
*sc
= hw
->priv
;
959 struct ath_vap
*avp
= (void *)conf
->vif
->drv_priv
;
962 /* Support only vap for now */
967 switch (conf
->type
) {
968 case NL80211_IFTYPE_STATION
:
969 ic_opmode
= ATH9K_M_STA
;
971 case NL80211_IFTYPE_ADHOC
:
972 ic_opmode
= ATH9K_M_IBSS
;
974 case NL80211_IFTYPE_AP
:
975 ic_opmode
= ATH9K_M_HOSTAP
;
978 DPRINTF(sc
, ATH_DBG_FATAL
,
979 "%s: Interface type %d not yet supported\n",
980 __func__
, conf
->type
);
984 DPRINTF(sc
, ATH_DBG_CONFIG
, "%s: Attach a VAP of type: %d\n",
988 /* Set the VAP opmode */
989 avp
->av_opmode
= ic_opmode
;
992 if (ic_opmode
== ATH9K_M_HOSTAP
)
993 ath9k_hw_set_tsfadjust(sc
->sc_ah
, 1);
995 sc
->sc_vaps
[0] = conf
->vif
;
998 /* Set the device opmode */
999 sc
->sc_ah
->ah_opmode
= ic_opmode
;
1001 if (conf
->type
== NL80211_IFTYPE_AP
) {
1002 /* TODO: is this a suitable place to start ANI for AP mode? */
1004 mod_timer(&sc
->sc_ani
.timer
,
1005 jiffies
+ msecs_to_jiffies(ATH_ANI_POLLINTERVAL
));
1011 static void ath9k_remove_interface(struct ieee80211_hw
*hw
,
1012 struct ieee80211_if_init_conf
*conf
)
1014 struct ath_softc
*sc
= hw
->priv
;
1015 struct ath_vap
*avp
= (void *)conf
->vif
->drv_priv
;
1017 DPRINTF(sc
, ATH_DBG_CONFIG
, "%s: Detach VAP\n", __func__
);
1019 #ifdef CONFIG_SLOW_ANT_DIV
1020 ath_slow_ant_div_stop(&sc
->sc_antdiv
);
1023 del_timer_sync(&sc
->sc_ani
.timer
);
1025 /* Reclaim beacon resources */
1026 if (sc
->sc_ah
->ah_opmode
== ATH9K_M_HOSTAP
||
1027 sc
->sc_ah
->ah_opmode
== ATH9K_M_IBSS
) {
1028 ath9k_hw_stoptxdma(sc
->sc_ah
, sc
->sc_bhalq
);
1029 ath_beacon_return(sc
, avp
);
1032 sc
->sc_flags
&= ~SC_OP_BEACONS
;
1034 sc
->sc_vaps
[0] = NULL
;
1038 static int ath9k_config(struct ieee80211_hw
*hw
, u32 changed
)
1040 struct ath_softc
*sc
= hw
->priv
;
1041 struct ieee80211_channel
*curchan
= hw
->conf
.channel
;
1042 struct ieee80211_conf
*conf
= &hw
->conf
;
1045 DPRINTF(sc
, ATH_DBG_CONFIG
, "%s: Set channel: %d MHz\n",
1047 curchan
->center_freq
);
1049 /* Update chainmask */
1050 ath_update_chainmask(sc
, conf
->ht
.enabled
);
1052 pos
= ath_get_channel(sc
, curchan
);
1054 DPRINTF(sc
, ATH_DBG_FATAL
, "%s: Invalid channel\n", __func__
);
1058 sc
->sc_ah
->ah_channels
[pos
].chanmode
=
1059 (curchan
->band
== IEEE80211_BAND_2GHZ
) ?
1060 CHANNEL_G
: CHANNEL_A
;
1062 if (sc
->sc_curaid
&& hw
->conf
.ht
.enabled
)
1063 sc
->sc_ah
->ah_channels
[pos
].chanmode
=
1064 ath_get_extchanmode(sc
, curchan
);
1066 if (changed
& IEEE80211_CONF_CHANGE_POWER
)
1067 sc
->sc_config
.txpowlimit
= 2 * conf
->power_level
;
1069 /* set h/w channel */
1070 if (ath_set_channel(sc
, &sc
->sc_ah
->ah_channels
[pos
]) < 0)
1071 DPRINTF(sc
, ATH_DBG_FATAL
, "%s: Unable to set channel\n",
1077 static int ath9k_config_interface(struct ieee80211_hw
*hw
,
1078 struct ieee80211_vif
*vif
,
1079 struct ieee80211_if_conf
*conf
)
1081 struct ath_softc
*sc
= hw
->priv
;
1082 struct ath_hal
*ah
= sc
->sc_ah
;
1083 struct ath_vap
*avp
= (void *)vif
->drv_priv
;
1087 /* TODO: Need to decide which hw opmode to use for multi-interface
1089 if (vif
->type
== NL80211_IFTYPE_AP
&&
1090 ah
->ah_opmode
!= ATH9K_M_HOSTAP
) {
1091 ah
->ah_opmode
= ATH9K_M_HOSTAP
;
1092 ath9k_hw_setopmode(ah
);
1093 ath9k_hw_write_associd(ah
, sc
->sc_myaddr
, 0);
1094 /* Request full reset to get hw opmode changed properly */
1095 sc
->sc_flags
|= SC_OP_FULL_RESET
;
1098 if ((conf
->changed
& IEEE80211_IFCC_BSSID
) &&
1099 !is_zero_ether_addr(conf
->bssid
)) {
1100 switch (vif
->type
) {
1101 case NL80211_IFTYPE_STATION
:
1102 case NL80211_IFTYPE_ADHOC
:
1104 memcpy(sc
->sc_curbssid
, conf
->bssid
, ETH_ALEN
);
1106 ath9k_hw_write_associd(sc
->sc_ah
, sc
->sc_curbssid
,
1109 /* Set aggregation protection mode parameters */
1110 sc
->sc_config
.ath_aggr_prot
= 0;
1112 DPRINTF(sc
, ATH_DBG_CONFIG
,
1113 "%s: RX filter 0x%x bssid %pM aid 0x%x\n",
1115 sc
->sc_curbssid
, sc
->sc_curaid
);
1117 /* need to reconfigure the beacon */
1118 sc
->sc_flags
&= ~SC_OP_BEACONS
;
1126 if ((conf
->changed
& IEEE80211_IFCC_BEACON
) &&
1127 ((vif
->type
== NL80211_IFTYPE_ADHOC
) ||
1128 (vif
->type
== NL80211_IFTYPE_AP
))) {
1130 * Allocate and setup the beacon frame.
1132 * Stop any previous beacon DMA. This may be
1133 * necessary, for example, when an ibss merge
1134 * causes reconfiguration; we may be called
1135 * with beacon transmission active.
1137 ath9k_hw_stoptxdma(sc
->sc_ah
, sc
->sc_bhalq
);
1139 error
= ath_beacon_alloc(sc
, 0);
1143 ath_beacon_sync(sc
, 0);
1146 /* Check for WLAN_CAPABILITY_PRIVACY ? */
1147 if ((avp
->av_opmode
!= ATH9K_M_STA
)) {
1148 for (i
= 0; i
< IEEE80211_WEP_NKID
; i
++)
1149 if (ath9k_hw_keyisvalid(sc
->sc_ah
, (u16
)i
))
1150 ath9k_hw_keysetmac(sc
->sc_ah
,
1155 /* Only legacy IBSS for now */
1156 if (vif
->type
== NL80211_IFTYPE_ADHOC
)
1157 ath_update_chainmask(sc
, 0);
1162 #define SUPPORTED_FILTERS \
1163 (FIF_PROMISC_IN_BSS | \
1167 FIF_BCN_PRBRESP_PROMISC | \
1170 /* FIXME: sc->sc_full_reset ? */
1171 static void ath9k_configure_filter(struct ieee80211_hw
*hw
,
1172 unsigned int changed_flags
,
1173 unsigned int *total_flags
,
1175 struct dev_mc_list
*mclist
)
1177 struct ath_softc
*sc
= hw
->priv
;
1180 changed_flags
&= SUPPORTED_FILTERS
;
1181 *total_flags
&= SUPPORTED_FILTERS
;
1183 sc
->rx_filter
= *total_flags
;
1184 rfilt
= ath_calcrxfilter(sc
);
1185 ath9k_hw_setrxfilter(sc
->sc_ah
, rfilt
);
1187 if (changed_flags
& FIF_BCN_PRBRESP_PROMISC
) {
1188 if (*total_flags
& FIF_BCN_PRBRESP_PROMISC
)
1189 ath9k_hw_write_associd(sc
->sc_ah
, ath_bcast_mac
, 0);
1192 DPRINTF(sc
, ATH_DBG_CONFIG
, "%s: Set HW RX filter: 0x%x\n",
1193 __func__
, sc
->rx_filter
);
1196 static void ath9k_sta_notify(struct ieee80211_hw
*hw
,
1197 struct ieee80211_vif
*vif
,
1198 enum sta_notify_cmd cmd
,
1199 struct ieee80211_sta
*sta
)
1201 struct ath_softc
*sc
= hw
->priv
;
1204 case STA_NOTIFY_ADD
:
1205 ath_node_attach(sc
, sta
);
1207 case STA_NOTIFY_REMOVE
:
1208 ath_node_detach(sc
, sta
);
1215 static int ath9k_conf_tx(struct ieee80211_hw
*hw
,
1217 const struct ieee80211_tx_queue_params
*params
)
1219 struct ath_softc
*sc
= hw
->priv
;
1220 struct ath9k_tx_queue_info qi
;
1223 if (queue
>= WME_NUM_AC
)
1226 qi
.tqi_aifs
= params
->aifs
;
1227 qi
.tqi_cwmin
= params
->cw_min
;
1228 qi
.tqi_cwmax
= params
->cw_max
;
1229 qi
.tqi_burstTime
= params
->txop
;
1230 qnum
= ath_get_hal_qnum(queue
, sc
);
1232 DPRINTF(sc
, ATH_DBG_CONFIG
,
1233 "%s: Configure tx [queue/halq] [%d/%d], "
1234 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1243 ret
= ath_txq_update(sc
, qnum
, &qi
);
1245 DPRINTF(sc
, ATH_DBG_FATAL
,
1246 "%s: TXQ Update failed\n", __func__
);
1251 static int ath9k_set_key(struct ieee80211_hw
*hw
,
1252 enum set_key_cmd cmd
,
1253 const u8
*local_addr
,
1255 struct ieee80211_key_conf
*key
)
1257 struct ath_softc
*sc
= hw
->priv
;
1260 DPRINTF(sc
, ATH_DBG_KEYCACHE
, " %s: Set HW Key\n", __func__
);
1264 ret
= ath_key_config(sc
, addr
, key
);
1266 set_bit(key
->keyidx
, sc
->sc_keymap
);
1267 key
->hw_key_idx
= key
->keyidx
;
1268 /* push IV and Michael MIC generation to stack */
1269 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1270 if (key
->alg
== ALG_TKIP
)
1271 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1275 ath_key_delete(sc
, key
);
1276 clear_bit(key
->keyidx
, sc
->sc_keymap
);
1285 static void ath9k_bss_info_changed(struct ieee80211_hw
*hw
,
1286 struct ieee80211_vif
*vif
,
1287 struct ieee80211_bss_conf
*bss_conf
,
1290 struct ath_softc
*sc
= hw
->priv
;
1292 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
1293 DPRINTF(sc
, ATH_DBG_CONFIG
, "%s: BSS Changed PREAMBLE %d\n",
1295 bss_conf
->use_short_preamble
);
1296 if (bss_conf
->use_short_preamble
)
1297 sc
->sc_flags
|= SC_OP_PREAMBLE_SHORT
;
1299 sc
->sc_flags
&= ~SC_OP_PREAMBLE_SHORT
;
1302 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
1303 DPRINTF(sc
, ATH_DBG_CONFIG
, "%s: BSS Changed CTS PROT %d\n",
1305 bss_conf
->use_cts_prot
);
1306 if (bss_conf
->use_cts_prot
&&
1307 hw
->conf
.channel
->band
!= IEEE80211_BAND_5GHZ
)
1308 sc
->sc_flags
|= SC_OP_PROTECT_ENABLE
;
1310 sc
->sc_flags
&= ~SC_OP_PROTECT_ENABLE
;
1313 if (changed
& BSS_CHANGED_HT
) {
1314 DPRINTF(sc
, ATH_DBG_CONFIG
, "%s: BSS Changed HT\n",
1316 ath9k_ht_conf(sc
, bss_conf
);
1319 if (changed
& BSS_CHANGED_ASSOC
) {
1320 DPRINTF(sc
, ATH_DBG_CONFIG
, "%s: BSS Changed ASSOC %d\n",
1323 ath9k_bss_assoc_info(sc
, vif
, bss_conf
);
1327 static u64
ath9k_get_tsf(struct ieee80211_hw
*hw
)
1330 struct ath_softc
*sc
= hw
->priv
;
1331 struct ath_hal
*ah
= sc
->sc_ah
;
1333 tsf
= ath9k_hw_gettsf64(ah
);
1338 static void ath9k_reset_tsf(struct ieee80211_hw
*hw
)
1340 struct ath_softc
*sc
= hw
->priv
;
1341 struct ath_hal
*ah
= sc
->sc_ah
;
1343 ath9k_hw_reset_tsf(ah
);
1346 static int ath9k_ampdu_action(struct ieee80211_hw
*hw
,
1347 enum ieee80211_ampdu_mlme_action action
,
1348 struct ieee80211_sta
*sta
,
1351 struct ath_softc
*sc
= hw
->priv
;
1355 case IEEE80211_AMPDU_RX_START
:
1356 if (!(sc
->sc_flags
& SC_OP_RXAGGR
))
1359 case IEEE80211_AMPDU_RX_STOP
:
1361 case IEEE80211_AMPDU_TX_START
:
1362 ret
= ath_tx_aggr_start(sc
, sta
, tid
, ssn
);
1364 DPRINTF(sc
, ATH_DBG_FATAL
,
1365 "%s: Unable to start TX aggregation\n",
1368 ieee80211_start_tx_ba_cb_irqsafe(hw
, sta
->addr
, tid
);
1370 case IEEE80211_AMPDU_TX_STOP
:
1371 ret
= ath_tx_aggr_stop(sc
, sta
, tid
);
1373 DPRINTF(sc
, ATH_DBG_FATAL
,
1374 "%s: Unable to stop TX aggregation\n",
1377 ieee80211_stop_tx_ba_cb_irqsafe(hw
, sta
->addr
, tid
);
1379 case IEEE80211_AMPDU_TX_RESUME
:
1380 ath_tx_aggr_resume(sc
, sta
, tid
);
1383 DPRINTF(sc
, ATH_DBG_FATAL
,
1384 "%s: Unknown AMPDU action\n", __func__
);
1390 static int ath9k_no_fragmentation(struct ieee80211_hw
*hw
, u32 value
)
1395 static struct ieee80211_ops ath9k_ops
= {
1397 .start
= ath9k_start
,
1399 .add_interface
= ath9k_add_interface
,
1400 .remove_interface
= ath9k_remove_interface
,
1401 .config
= ath9k_config
,
1402 .config_interface
= ath9k_config_interface
,
1403 .configure_filter
= ath9k_configure_filter
,
1404 .sta_notify
= ath9k_sta_notify
,
1405 .conf_tx
= ath9k_conf_tx
,
1406 .bss_info_changed
= ath9k_bss_info_changed
,
1407 .set_key
= ath9k_set_key
,
1408 .get_tsf
= ath9k_get_tsf
,
1409 .reset_tsf
= ath9k_reset_tsf
,
1410 .ampdu_action
= ath9k_ampdu_action
,
1411 .set_frag_threshold
= ath9k_no_fragmentation
,
1417 } ath_mac_bb_names
[] = {
1418 { AR_SREV_VERSION_5416_PCI
, "5416" },
1419 { AR_SREV_VERSION_5416_PCIE
, "5418" },
1420 { AR_SREV_VERSION_9100
, "9100" },
1421 { AR_SREV_VERSION_9160
, "9160" },
1422 { AR_SREV_VERSION_9280
, "9280" },
1423 { AR_SREV_VERSION_9285
, "9285" }
1429 } ath_rf_names
[] = {
1431 { AR_RAD5133_SREV_MAJOR
, "5133" },
1432 { AR_RAD5122_SREV_MAJOR
, "5122" },
1433 { AR_RAD2133_SREV_MAJOR
, "2133" },
1434 { AR_RAD2122_SREV_MAJOR
, "2122" }
1438 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
1442 ath_mac_bb_name(u32 mac_bb_version
)
1446 for (i
=0; i
<ARRAY_SIZE(ath_mac_bb_names
); i
++) {
1447 if (ath_mac_bb_names
[i
].version
== mac_bb_version
) {
1448 return ath_mac_bb_names
[i
].name
;
1456 * Return the RF name. "????" is returned if the RF is unknown.
1460 ath_rf_name(u16 rf_version
)
1464 for (i
=0; i
<ARRAY_SIZE(ath_rf_names
); i
++) {
1465 if (ath_rf_names
[i
].version
== rf_version
) {
1466 return ath_rf_names
[i
].name
;
1473 static int ath_pci_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
1476 struct ath_softc
*sc
;
1477 struct ieee80211_hw
*hw
;
1483 if (pci_enable_device(pdev
))
1486 ret
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
);
1489 printk(KERN_ERR
"ath9k: 32-bit DMA not available\n");
1493 ret
= pci_set_consistent_dma_mask(pdev
, DMA_32BIT_MASK
);
1496 printk(KERN_ERR
"ath9k: 32-bit DMA consistent "
1497 "DMA enable faled\n");
1502 * Cache line size is used to size and align various
1503 * structures used to communicate with the hardware.
1505 pci_read_config_byte(pdev
, PCI_CACHE_LINE_SIZE
, &csz
);
1508 * Linux 2.4.18 (at least) writes the cache line size
1509 * register as a 16-bit wide register which is wrong.
1510 * We must have this setup properly for rx buffer
1511 * DMA to work so force a reasonable value here if it
1514 csz
= L1_CACHE_BYTES
/ sizeof(u32
);
1515 pci_write_config_byte(pdev
, PCI_CACHE_LINE_SIZE
, csz
);
1518 * The default setting of latency timer yields poor results,
1519 * set it to the value used by other systems. It may be worth
1520 * tweaking this setting more.
1522 pci_write_config_byte(pdev
, PCI_LATENCY_TIMER
, 0xa8);
1524 pci_set_master(pdev
);
1527 * Disable the RETRY_TIMEOUT register (0x41) to keep
1528 * PCI Tx retries from interfering with C3 CPU state.
1530 pci_read_config_dword(pdev
, 0x40, &val
);
1531 if ((val
& 0x0000ff00) != 0)
1532 pci_write_config_dword(pdev
, 0x40, val
& 0xffff00ff);
1534 ret
= pci_request_region(pdev
, 0, "ath9k");
1536 dev_err(&pdev
->dev
, "PCI memory region reserve error\n");
1541 mem
= pci_iomap(pdev
, 0, 0);
1543 printk(KERN_ERR
"PCI memory map error\n") ;
1548 hw
= ieee80211_alloc_hw(sizeof(struct ath_softc
), &ath9k_ops
);
1550 printk(KERN_ERR
"ath_pci: no memory for ieee80211_hw\n");
1554 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
1555 pci_set_drvdata(pdev
, hw
);
1562 if (ath_attach(id
->device
, sc
) != 0) {
1567 /* setup interrupt service routine */
1569 if (request_irq(pdev
->irq
, ath_isr
, IRQF_SHARED
, "ath", sc
)) {
1570 printk(KERN_ERR
"%s: request_irq failed\n",
1571 wiphy_name(hw
->wiphy
));
1578 "%s: Atheros AR%s MAC/BB Rev:%x "
1579 "AR%s RF Rev:%x: mem=0x%lx, irq=%d\n",
1580 wiphy_name(hw
->wiphy
),
1581 ath_mac_bb_name(ah
->ah_macVersion
),
1583 ath_rf_name((ah
->ah_analog5GhzRev
& AR_RADIO_SREV_MAJOR
)),
1585 (unsigned long)mem
, pdev
->irq
);
1591 ieee80211_free_hw(hw
);
1593 pci_iounmap(pdev
, mem
);
1595 pci_release_region(pdev
, 0);
1597 pci_disable_device(pdev
);
1601 static void ath_pci_remove(struct pci_dev
*pdev
)
1603 struct ieee80211_hw
*hw
= pci_get_drvdata(pdev
);
1604 struct ath_softc
*sc
= hw
->priv
;
1608 free_irq(pdev
->irq
, sc
);
1609 pci_iounmap(pdev
, sc
->mem
);
1610 pci_release_region(pdev
, 0);
1611 pci_disable_device(pdev
);
1612 ieee80211_free_hw(hw
);
1617 static int ath_pci_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1619 struct ieee80211_hw
*hw
= pci_get_drvdata(pdev
);
1620 struct ath_softc
*sc
= hw
->priv
;
1622 ath9k_hw_set_gpio(sc
->sc_ah
, ATH_LED_PIN
, 1);
1624 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
1625 if (sc
->sc_ah
->ah_caps
.hw_caps
& ATH9K_HW_CAP_RFSILENT
)
1626 cancel_delayed_work_sync(&sc
->rf_kill
.rfkill_poll
);
1629 pci_save_state(pdev
);
1630 pci_disable_device(pdev
);
1631 pci_set_power_state(pdev
, 3);
1636 static int ath_pci_resume(struct pci_dev
*pdev
)
1638 struct ieee80211_hw
*hw
= pci_get_drvdata(pdev
);
1639 struct ath_softc
*sc
= hw
->priv
;
1643 err
= pci_enable_device(pdev
);
1646 pci_restore_state(pdev
);
1648 * Suspend/Resume resets the PCI configuration space, so we have to
1649 * re-disable the RETRY_TIMEOUT register (0x41) to keep
1650 * PCI Tx retries from interfering with C3 CPU state
1652 pci_read_config_dword(pdev
, 0x40, &val
);
1653 if ((val
& 0x0000ff00) != 0)
1654 pci_write_config_dword(pdev
, 0x40, val
& 0xffff00ff);
1657 ath9k_hw_cfg_output(sc
->sc_ah
, ATH_LED_PIN
,
1658 AR_GPIO_OUTPUT_MUX_AS_OUTPUT
);
1659 ath9k_hw_set_gpio(sc
->sc_ah
, ATH_LED_PIN
, 1);
1661 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
1663 * check the h/w rfkill state on resume
1664 * and start the rfkill poll timer
1666 if (sc
->sc_ah
->ah_caps
.hw_caps
& ATH9K_HW_CAP_RFSILENT
)
1667 queue_delayed_work(sc
->hw
->workqueue
,
1668 &sc
->rf_kill
.rfkill_poll
, 0);
1674 #endif /* CONFIG_PM */
1676 MODULE_DEVICE_TABLE(pci
, ath_pci_id_table
);
1678 static struct pci_driver ath_pci_driver
= {
1680 .id_table
= ath_pci_id_table
,
1681 .probe
= ath_pci_probe
,
1682 .remove
= ath_pci_remove
,
1684 .suspend
= ath_pci_suspend
,
1685 .resume
= ath_pci_resume
,
1686 #endif /* CONFIG_PM */
1689 static int __init
init_ath_pci(void)
1691 printk(KERN_INFO
"%s: %s\n", dev_info
, ATH_PCI_VERSION
);
1693 if (pci_register_driver(&ath_pci_driver
) < 0) {
1695 "ath_pci: No devices found, driver not installed.\n");
1696 pci_unregister_driver(&ath_pci_driver
);
1702 module_init(init_ath_pci
);
1704 static void __exit
exit_ath_pci(void)
1706 pci_unregister_driver(&ath_pci_driver
);
1707 printk(KERN_INFO
"%s: driver unloaded\n", dev_info
);
1709 module_exit(exit_ath_pci
);