43 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
45 #include <linux/module.h>
51 #include <linux/netdevice.h>
53 #include <linux/ethtool.h>
55 #include <linux/slab.h>
61 #include <asm/unaligned.h>
70 #define CREATE_TRACE_POINTS
77 static bool modparam_fastchanswitch;
79 MODULE_PARM_DESC(fastchanswitch,
"Enable fast channel switching for AR2413/AR5413 radios.");
81 static bool ath5k_modparam_no_hw_rfkill_switch;
84 MODULE_PARM_DESC(no_hw_rfkill_switch,
"Ignore the GPIO RFKill switch state");
100 #ifdef CONFIG_ATHEROS_AR231X
143 #ifdef CONFIG_ATHEROS_AR231X
195 if ((tsf & 0x7fff) < rstamp)
198 return (tsf & ~0x7fff) | rstamp;
204 const char *
name =
"xxxxx";
207 for (i = 0; i <
ARRAY_SIZE(srev_names); i++) {
208 if (srev_names[i].sr_type != type)
211 if ((val & 0xf0) == srev_names[
i].
sr_val)
212 name = srev_names[i].sr_name;
214 if ((val & 0xff) == srev_names[
i].
sr_val) {
222 static unsigned int ath5k_ioread32(
void *hw_priv,
u32 reg_offset)
225 return ath5k_hw_reg_read(ah, reg_offset);
228 static void ath5k_iowrite32(
void *hw_priv,
u32 val,
u32 reg_offset)
231 ath5k_hw_reg_write(ah, val, reg_offset);
234 static const struct ath_ops ath5k_common_ops = {
235 .read = ath5k_ioread32,
236 .write = ath5k_iowrite32,
259 #ifdef CONFIG_ATH5K_TEST_CHANNELS
272 (((chan & 3) == 0 && chan >= 36 && chan <= 64) ||
274 ((chan & 3) == 0 && chan >= 100 && chan <= 140) ||
276 ((chan & 3) == 1 && chan >= 149 && chan <= 165) ||
278 (chan == 8 || chan == 12 || chan == 16) ||
280 (chan == 184 || chan == 188 || chan == 192 || chan == 196));
286 unsigned int mode,
unsigned int max)
303 ATH5K_WARN(ah,
"bad mode, not copying channels\n");
308 for (ch = 1; ch <= size && count <
max; ch++) {
323 if (!ath5k_is_standard_channel(ch, band))
352 int max_c, count_c = 0;
387 for (i = 0; i < 4; i++) {
403 ath5k_setup_rate_idx(ah, sband);
421 ath5k_setup_rate_idx(ah, sband);
439 "channel set, resetting (%u -> %u MHz)\n",
448 return ath5k_reset(ah, chan,
true);
455 struct ath5k_vif *avf = (
void *)vif->drv_priv;
459 iter_data->
mask[i] &=
468 if (ether_addr_equal(iter_data->
hw_macaddr, mac))
534 if (iter_data.
n_stas > 1) {
548 ath5k_hw_to_driver_rix(
struct ath5k_hw *ah,
int hw_rix)
553 if (
WARN(hw_rix < 0 || hw_rix >= AR5K_MAX_RATES,
554 "hw_rix out of bounds: %x\n", hw_rix))
558 if (
WARN(rix < 0,
"invalid hw_rix: %x\n", hw_rix))
583 ATH5K_ERR(ah,
"can't alloc skbuff of size %u\n",
593 ATH5K_ERR(ah,
"%s: DMA mapping failed\n", __func__);
608 skb = ath5k_rx_skb_alloc(ah, &bf->
skbaddr);
634 ATH5K_ERR(ah,
"%s: could not setup RX desc\n", __func__);
653 if (ieee80211_is_beacon(fc))
655 else if (ieee80211_is_probe_resp(fc))
657 else if (ieee80211_is_atim(fc))
659 else if (ieee80211_is_pspoll(fc))
676 unsigned int mrr_rate[3], mrr_tries[3];
689 rate = ieee80211_get_tx_rate(ah->
hw, info);
698 rc_flags = info->
control.rates[0].flags;
708 keyidx = info->
control.hw_key->hw_key_idx;
709 pktlen += info->
control.hw_key->icv_len;
713 cts_rate = ieee80211_get_rts_cts_rate(ah->
hw, info)->hw_value;
715 info->
control.vif, pktlen, info));
719 cts_rate = ieee80211_get_rts_cts_rate(ah->
hw, info)->hw_value;
721 info->
control.vif, pktlen, info));
725 get_hw_packet_type(skb),
735 memset(mrr_rate, 0,
sizeof(mrr_rate));
736 memset(mrr_tries, 0,
sizeof(mrr_tries));
737 for (i = 0; i < 3; i++) {
738 rate = ieee80211_get_alt_retry_rate(ah->
hw, info, i);
743 mrr_tries[
i] = info->
control.rates[i + 1].count;
747 mrr_rate[0], mrr_tries[0],
748 mrr_rate[1], mrr_tries[1],
749 mrr_rate[2], mrr_tries[2]);
755 spin_lock_bh(&txq->
lock);
766 spin_unlock_bh(&txq->
lock);
779 ath5k_desc_alloc(
struct ath5k_hw *ah)
794 ATH5K_ERR(ah,
"can't allocate descriptors\n");
806 ATH5K_ERR(ah,
"can't allocate bufptr\n");
812 INIT_LIST_HEAD(&ah->
rxbuf);
813 for (i = 0; i <
ATH_RXBUF; i++, bf++, ds++, da +=
sizeof(*ds)) {
819 INIT_LIST_HEAD(&ah->
txbuf);
821 for (i = 0; i <
ATH_TXBUF; i++, bf++, ds++, da +=
sizeof(*ds)) {
828 INIT_LIST_HEAD(&ah->
bcbuf);
829 for (i = 0; i <
ATH_BCBUF; i++, bf++, ds++, da +=
sizeof(*ds)) {
854 bf->
desc->ds_data = 0;
860 struct ath_common *common = ath5k_hw_common(ah);
870 bf->
desc->ds_data = 0;
874 ath5k_desc_free(
struct ath5k_hw *ah)
934 return ERR_PTR(qnum);
936 txq = &ah->txqs[qnum];
940 INIT_LIST_HEAD(&txq->
q);
948 return &ah->txqs[qnum];
952 ath5k_beaconq_setup(
struct ath5k_hw *ah)
968 ath5k_beaconq_config(
struct ath5k_hw *ah)
996 "beacon queueprops tqi_aifs:%d tqi_cw_min:%d tqi_cw_max:%d\n",
1001 ATH5K_ERR(ah,
"%s: unable to update parameters for beacon "
1002 "hardware queue!\n", __func__);
1036 ath5k_drain_tx_buffs(
struct ath5k_hw *ah)
1043 if (ah->
txqs[i].setup) {
1045 spin_lock_bh(&txq->
lock);
1059 spin_unlock_bh(&txq->
lock);
1065 ath5k_txq_release(
struct ath5k_hw *ah)
1086 ath5k_rx_start(
struct ath5k_hw *ah)
1088 struct ath_common *common = ath5k_hw_common(ah);
1100 ret = ath5k_rxbuf_setup(ah, bf);
1140 struct ath_common *common = ath5k_hw_common(ah);
1142 unsigned int keyix, hlen;
1154 skb->
len >= hlen + 4) {
1155 keyix = skb->
data[hlen + 3] >> 6;
1157 if (
test_bit(keyix, common->keymap))
1169 struct ath_common *common = ath5k_hw_common(ah);
1187 "beacon %llx mactime %llx (diff %lld) tsf now %llx\n",
1188 (
unsigned long long)bc_tstamp,
1189 (
unsigned long long)rxs->
mactime,
1190 (
unsigned long long)(rxs->
mactime - bc_tstamp),
1191 (
unsigned long long)tsf);
1204 if (bc_tstamp > rxs->
mactime) {
1206 "fixing mactime from %llx to %llx\n",
1207 (
unsigned long long)rxs->
mactime,
1208 (
unsigned long long)tsf);
1227 "fixed beacon timers after beacon receive\n");
1233 ath5k_update_beacon_rssi(
struct ath5k_hw *ah,
struct sk_buff *skb,
int rssi)
1236 struct ath_common *common = ath5k_hw_common(ah);
1252 static int ath5k_common_padpos(
struct sk_buff *skb)
1271 static int ath5k_add_padding(
struct sk_buff *skb)
1273 int padpos = ath5k_common_padpos(skb);
1274 int padsize = padpos & 3;
1276 if (padsize && skb->
len > padpos) {
1278 if (skb_headroom(skb) < padsize)
1302 static int ath5k_remove_padding(
struct sk_buff *skb)
1304 int padpos = ath5k_common_padpos(skb);
1305 int padsize = padpos & 3;
1307 if (padsize && skb->
len >= padpos + padsize) {
1322 ath5k_remove_padding(skb);
1324 rxs = IEEE80211_SKB_RXCB(skb);
1363 ah->
stats.antenna_rx[0]++;
1366 rxs->
flag |= ath5k_rx_decrypted(ah, skb, rs);
1372 trace_ath5k_rx(ah, skb);
1374 ath5k_update_beacon_rssi(ah, skb, rs->
rs_rssi);
1378 ath5k_check_ibss_tsf(ah, skb, rxs);
1391 ah->
stats.rx_all_count++;
1396 ah->
stats.rxerr_crc++;
1398 ah->
stats.rxerr_fifo++;
1400 ah->
stats.rxerr_phy++;
1416 ah->
stats.rxerr_decrypt++;
1422 ah->
stats.rxerr_mic++;
1432 ah->
stats.rxerr_jumbo++;
1439 ath5k_set_current_imask(
struct ath5k_hw *ah)
1442 unsigned long flags;
1451 spin_unlock_irqrestore(&ah->
irqlock, flags);
1455 ath5k_tasklet_rx(
unsigned long data)
1460 struct ath5k_hw *ah = (
void *)data;
1461 struct ath_common *common = ath5k_hw_common(ah);
1467 if (list_empty(&ah->
rxbuf)) {
1485 ATH5K_ERR(ah,
"error in processing rx descriptor\n");
1486 ah->
stats.rxerr_proc++;
1490 if (ath5k_receive_frame_ok(ah, &rs)) {
1491 next_skb = ath5k_rx_skb_alloc(ah, &next_skb_addr);
1506 ath5k_receive_frame(ah, skb, &rs);
1513 }
while (ath5k_rxbuf_setup(ah, bf) == 0);
1517 ath5k_set_current_imask(ah);
1531 unsigned long flags;
1534 trace_ath5k_tx(ah, skb, txq);
1540 padsize = ath5k_add_padding(skb);
1542 ATH5K_ERR(ah,
"tx hdrlen not %%4: not enough"
1543 " headroom to pad");
1552 if (list_empty(&ah->
txbuf)) {
1553 ATH5K_ERR(ah,
"no further txbuf available, dropping packet\n");
1554 spin_unlock_irqrestore(&ah->
txbuflock, flags);
1561 if (list_empty(&ah->
txbuf))
1563 spin_unlock_irqrestore(&ah->
txbuflock, flags);
1567 if (ath5k_txbuf_setup(ah, bf, txq, padsize)) {
1572 spin_unlock_irqrestore(&ah->
txbuflock, flags);
1589 ah->
stats.tx_all_count++;
1590 ah->
stats.tx_bytes_count += skb->
len;
1591 info = IEEE80211_SKB_CB(skb);
1593 tries[0] = info->
status.rates[0].count;
1594 tries[1] = info->
status.rates[1].count;
1595 tries[2] = info->
status.rates[2].count;
1597 ieee80211_tx_info_clear_status(info);
1610 ah->
stats.ack_fail++;
1613 ah->
stats.txerr_filt++;
1616 ah->
stats.txerr_retry++;
1618 ah->
stats.txerr_fifo++;
1631 ath5k_remove_padding(skb);
1636 ah->
stats.antenna_tx[0]++;
1638 trace_ath5k_tx_complete(ah, skb, txq, ts);
1651 spin_lock(&txq->
lock);
1657 if (bf->
skb != NULL) {
1665 "error %d while processing "
1666 "queue %u\n", ret, txq->
qnum);
1675 ath5k_tx_frame_completed(ah, skb, txq, &ts);
1692 spin_unlock(&txq->
lock);
1698 ath5k_tasklet_tx(
unsigned long data)
1701 struct ath5k_hw *ah = (
void *)data;
1705 ath5k_tx_processq(ah, &ah->
txqs[i]);
1708 ath5k_set_current_imask(ah);
1728 const int padsize = 0;
1733 "skbaddr %llx\n", skb, skb->
data, skb->
len,
1734 (
unsigned long long)bf->
skbaddr);
1737 ATH5K_ERR(ah,
"beacon DMA mapping failed\n");
1772 antenna = ah->
bsent & 4 ? 2 : 1;
1783 ieee80211_get_tx_rate(ah->
hw, info)->hw_value,
1785 antenna, flags, 0, 0);
1815 skb = ieee80211_beacon_get(hw, vif);
1822 avf = (
void *)vif->drv_priv;
1825 ret = ath5k_beacon_setup(ah, avf->
bbuf);
1839 ath5k_beacon_send(
struct ath5k_hw *ah)
1859 "missed %u consecutive beacons\n", ah->
bmisscount);
1862 "stuck beacon time (%u missed)\n",
1865 "stuck beacon, resetting\n");
1872 "resume beacon xmit after %u misses\n",
1885 "tsf %llx tsftu %x intval %u slot %u vif %p\n",
1886 (
unsigned long long)tsf, tsftu, ah->
bintval, slot, vif);
1893 avf = (
void *)vif->drv_priv;
1931 if (ah->
cabq->txq_len >= ah->
cabq->txq_max)
1959 u32 nexttbtt, intval, hw_tu, bc_tu;
1967 ATH5K_WARN(ah,
"intval %u is too low, min 15\n",
1980 #define FUDGE (AR5K_TUNE_SW_BEACON_RESP + 3)
1991 }
else if (bc_tsf == 0) {
1998 }
else if (bc_tsf > hw_tsf) {
2007 "need to wait for HW TSF sync\n");
2017 nexttbtt = bc_tu +
roundup(hw_tu +
FUDGE - bc_tu, intval);
2032 "reconfigured timers based on HW TSF\n");
2033 else if (bc_tsf == 0)
2035 "reset HW TSF and timers\n");
2038 "updated timers based on beacon TSF\n");
2041 "bc_tsf %llx hw_tsf %llx bc_tu %u hw_tu %u nexttbtt %u\n",
2042 (
unsigned long long) bc_tsf,
2043 (
unsigned long long) hw_tsf, bc_tu, hw_tu, nexttbtt);
2061 spin_lock_bh(&ah->
block);
2073 ath5k_beaconq_config(ah);
2079 ath5k_beacon_send(ah);
2088 spin_unlock_bh(&ah->
block);
2091 static void ath5k_tasklet_beacon(
unsigned long data)
2108 "SWBA nexttbtt: %x hw_tu: %x "
2112 (
unsigned long long) tsf);
2114 spin_lock(&ah->
block);
2115 ath5k_beacon_send(ah);
2116 spin_unlock(&ah->
block);
2126 ath5k_intr_calibration_poll(
struct ath5k_hw *ah)
2159 ath5k_schedule_rx(
struct ath5k_hw *ah)
2162 tasklet_schedule(&ah->
rxtq);
2166 ath5k_schedule_tx(
struct ath5k_hw *ah)
2169 tasklet_schedule(&ah->
txtq);
2191 ((ath5k_get_bus_type(ah) !=
ATH_AHB) &&
2212 "fatal int, resetting\n");
2230 ah->
stats.rxorn_intr++;
2234 "rx overrun, resetting\n");
2237 ath5k_schedule_rx(ah);
2243 tasklet_hi_schedule(&ah->
beacontq);
2253 ah->
stats.rxeol_intr++;
2262 ath5k_schedule_rx(ah);
2269 ath5k_schedule_tx(ah);
2277 ah->
stats.mib_intr++;
2284 tasklet_schedule(&ah->
rf_kill.toggleq);
2288 if (ath5k_get_bus_type(ah) ==
ATH_AHB)
2300 ath5k_set_current_imask(ah);
2303 ATH5K_WARN(ah,
"too many interrupts, giving up for now\n");
2306 ath5k_intr_calibration_poll(ah);
2329 "running full calibration\n");
2337 "got new rfgain, resetting\n");
2349 ATH5K_ERR(ah,
"calibration of channel %u failed\n",
2362 ath5k_tasklet_ani(
unsigned long data)
2364 struct ath5k_hw *ah = (
void *)data;
2373 ath5k_tx_complete_poll_work(
struct work_struct *work)
2379 bool needreset =
false;
2384 if (ah->
txqs[i].setup) {
2386 spin_lock_bh(&txq->
lock);
2390 "TX queue stuck %d\n",
2394 spin_unlock_bh(&txq->
lock);
2400 spin_unlock_bh(&txq->
lock);
2406 "TX queues stuck, resetting\n");
2407 ath5k_reset(ah, NULL,
true);
2423 { .max = 4, .types =
2424 #ifdef CONFIG_MAC80211_MESH
2431 .limits = if_limits,
2433 .max_interfaces = 2048,
2434 .num_different_channels = 1,
2446 SET_IEEE80211_DEV(hw, ah->
dev);
2453 hw->
wiphy->interface_modes =
2459 hw->
wiphy->iface_combinations = &if_comb;
2460 hw->
wiphy->n_iface_combinations = 1;
2466 hw->
wiphy->available_antennas_tx = 0x3;
2467 hw->
wiphy->available_antennas_rx = 0x3;
2493 common = ath5k_hw_common(ah);
2494 common->
ops = &ath5k_common_ops;
2505 ath5k_read_cachesize(common, &csz);
2525 ret = ath5k_init(hw);
2529 ATH5K_INFO(ah,
"Atheros AR%s chip found (MAC: 0x%x, PHY: 0x%x)\n",
2541 ATH5K_INFO(ah,
"RF%s 2GHz radio found (0x%x)\n",
2549 ATH5K_INFO(ah,
"RF%s 5GHz radio found (0x%x)\n",
2566 ATH5K_INFO(ah,
"RF%s 5GHz radio found (0x%x)\n",
2570 ATH5K_INFO(ah,
"RF%s 2GHz radio found (0x%x)\n",
2592 ath5k_stop_locked(
struct ath5k_hw *ah)
2621 ath5k_drain_tx_buffs(ah);
2631 struct ath_common *common = ath5k_hw_common(ah);
2642 ath5k_stop_locked(ah);
2662 ret = ath5k_reset(ah, NULL,
false);
2666 if (!ath5k_modparam_no_hw_rfkill_switch)
2673 for (i = 0; i < common->
keymax; i++)
2681 ah->
bslot[i] = NULL;
2694 static void ath5k_stop_tasklets(
struct ath5k_hw *ah)
2716 ret = ath5k_stop_locked(ah);
2741 "putting device to sleep\n");
2747 ath5k_stop_tasklets(ah);
2751 if (!ath5k_modparam_no_hw_rfkill_switch)
2765 struct ath_common *common = ath5k_hw_common(ah);
2773 ath5k_stop_tasklets(ah);
2784 ath5k_drain_tx_buffs(ah);
2788 fast = ((chan !=
NULL) && modparam_fastchanswitch) ? 1 : 0;
2792 ATH5K_ERR(ah,
"can't reset hardware (%d)\n", ret);
2796 ret = ath5k_rx_start(ah);
2798 ATH5K_ERR(ah,
"can't start recv logic\n");
2826 spin_lock_bh(&common->
cc_lock);
2830 spin_unlock_bh(&common->
cc_lock);
2853 static void ath5k_reset_work(
struct work_struct *work)
2859 ath5k_reset(ah, NULL,
true);
2880 ret = ath5k_setup_bands(hw);
2889 ret = ath5k_desc_alloc(ah);
2891 ATH5K_ERR(ah,
"can't allocate descriptors\n");
2901 ret = ath5k_beaconq_setup(ah);
2903 ATH5K_ERR(ah,
"can't setup a beacon xmit queue\n");
2908 if (IS_ERR(ah->
cabq)) {
2909 ATH5K_ERR(ah,
"can't setup cab queue\n");
2910 ret = PTR_ERR(ah->
cabq);
2921 ATH5K_ERR(ah,
"can't setup xmit queue\n");
2927 ATH5K_ERR(ah,
"can't setup xmit queue\n");
2933 ATH5K_ERR(ah,
"can't setup xmit queue\n");
2939 ATH5K_ERR(ah,
"can't setup xmit queue\n");
2948 ATH5K_ERR(ah,
"can't setup xmit queue\n");
2964 ret = ath5k_hw_common(ah)->bus_ops->eeprom_read_mac(ah, mac);
2966 ATH5K_ERR(ah,
"unable to read address from EEPROM\n");
2970 SET_IEEE80211_PERM_ADDR(hw, mac);
2977 ATH5K_ERR(ah,
"can't initialize regulatory system\n");
2983 ATH5K_ERR(ah,
"can't register ieee80211 hw\n");
2996 ath5k_txq_release(ah);
3000 ath5k_desc_free(ah);
3024 ath5k_desc_free(ah);
3025 ath5k_txq_release(ah);
3068 const char *
fmt, ...)
3080 level, wiphy_name(ah->
hw->wiphy), &vaf);