Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1 | /* |
Luis R. Rodriguez | b3950e6 | 2010-04-15 17:39:03 -0400 | [diff] [blame] | 2 | * Copyright (c) 2008-2010 Atheros Communications Inc. |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3 | * |
| 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. |
| 7 | * |
| 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. |
| 15 | */ |
| 16 | |
| 17 | #include <linux/io.h> |
| 18 | #include <asm/unaligned.h> |
| 19 | |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 20 | #include "hw.h" |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 21 | #include "hw-ops.h" |
Luis R. Rodriguez | cfe8cba | 2009-09-13 23:39:31 -0700 | [diff] [blame] | 22 | #include "rc.h" |
Luis R. Rodriguez | b622a72 | 2010-04-15 17:39:28 -0400 | [diff] [blame] | 23 | #include "ar9003_mac.h" |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 24 | |
Luis R. Rodriguez | 4febf7b | 2008-12-23 15:58:48 -0800 | [diff] [blame] | 25 | #define ATH9K_CLOCK_RATE_CCK 22 |
| 26 | #define ATH9K_CLOCK_RATE_5GHZ_OFDM 40 |
| 27 | #define ATH9K_CLOCK_RATE_2GHZ_OFDM 44 |
Vasanthakumar Thiagarajan | e555372 | 2010-04-26 15:04:33 -0400 | [diff] [blame^] | 28 | #define ATH9K_CLOCK_FAST_RATE_5GHZ_OFDM 44 |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 29 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 30 | static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 31 | |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 32 | MODULE_AUTHOR("Atheros Communications"); |
| 33 | MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards."); |
| 34 | MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards"); |
| 35 | MODULE_LICENSE("Dual BSD/GPL"); |
| 36 | |
| 37 | static int __init ath9k_init(void) |
| 38 | { |
| 39 | return 0; |
| 40 | } |
| 41 | module_init(ath9k_init); |
| 42 | |
| 43 | static void __exit ath9k_exit(void) |
| 44 | { |
| 45 | return; |
| 46 | } |
| 47 | module_exit(ath9k_exit); |
| 48 | |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 49 | /* Private hardware callbacks */ |
| 50 | |
| 51 | static void ath9k_hw_init_cal_settings(struct ath_hw *ah) |
| 52 | { |
| 53 | ath9k_hw_private_ops(ah)->init_cal_settings(ah); |
| 54 | } |
| 55 | |
| 56 | static void ath9k_hw_init_mode_regs(struct ath_hw *ah) |
| 57 | { |
| 58 | ath9k_hw_private_ops(ah)->init_mode_regs(ah); |
| 59 | } |
| 60 | |
| 61 | static bool ath9k_hw_macversion_supported(struct ath_hw *ah) |
| 62 | { |
| 63 | struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah); |
| 64 | |
| 65 | return priv_ops->macversion_supported(ah->hw_version.macVersion); |
| 66 | } |
| 67 | |
Luis R. Rodriguez | 6477396 | 2010-04-15 17:38:17 -0400 | [diff] [blame] | 68 | static u32 ath9k_hw_compute_pll_control(struct ath_hw *ah, |
| 69 | struct ath9k_channel *chan) |
| 70 | { |
| 71 | return ath9k_hw_private_ops(ah)->compute_pll_control(ah, chan); |
| 72 | } |
| 73 | |
Luis R. Rodriguez | 991312d | 2010-04-15 17:39:05 -0400 | [diff] [blame] | 74 | static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah) |
| 75 | { |
| 76 | if (!ath9k_hw_private_ops(ah)->init_mode_gain_regs) |
| 77 | return; |
| 78 | |
| 79 | ath9k_hw_private_ops(ah)->init_mode_gain_regs(ah); |
| 80 | } |
| 81 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 82 | /********************/ |
| 83 | /* Helper Functions */ |
| 84 | /********************/ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 85 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 86 | static u32 ath9k_hw_mac_clks(struct ath_hw *ah, u32 usecs) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 87 | { |
Luis R. Rodriguez | b002a4a | 2009-09-13 00:03:27 -0700 | [diff] [blame] | 88 | struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf; |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 89 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 90 | if (!ah->curchan) /* should really check for CCK instead */ |
Luis R. Rodriguez | 4febf7b | 2008-12-23 15:58:48 -0800 | [diff] [blame] | 91 | return usecs *ATH9K_CLOCK_RATE_CCK; |
| 92 | if (conf->channel->band == IEEE80211_BAND_2GHZ) |
| 93 | return usecs *ATH9K_CLOCK_RATE_2GHZ_OFDM; |
Vasanthakumar Thiagarajan | e555372 | 2010-04-26 15:04:33 -0400 | [diff] [blame^] | 94 | |
| 95 | if (ah->caps.hw_caps & ATH9K_HW_CAP_FASTCLOCK) |
| 96 | return usecs * ATH9K_CLOCK_FAST_RATE_5GHZ_OFDM; |
| 97 | else |
| 98 | return usecs * ATH9K_CLOCK_RATE_5GHZ_OFDM; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 99 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 100 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 101 | static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 102 | { |
Luis R. Rodriguez | b002a4a | 2009-09-13 00:03:27 -0700 | [diff] [blame] | 103 | struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf; |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 104 | |
Luis R. Rodriguez | 4febf7b | 2008-12-23 15:58:48 -0800 | [diff] [blame] | 105 | if (conf_is_ht40(conf)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 106 | return ath9k_hw_mac_clks(ah, usecs) * 2; |
| 107 | else |
| 108 | return ath9k_hw_mac_clks(ah, usecs); |
| 109 | } |
| 110 | |
Sujith | 0caa7b1 | 2009-02-16 13:23:20 +0530 | [diff] [blame] | 111 | bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 112 | { |
| 113 | int i; |
| 114 | |
Sujith | 0caa7b1 | 2009-02-16 13:23:20 +0530 | [diff] [blame] | 115 | BUG_ON(timeout < AH_TIME_QUANTUM); |
| 116 | |
| 117 | for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 118 | if ((REG_READ(ah, reg) & mask) == val) |
| 119 | return true; |
| 120 | |
| 121 | udelay(AH_TIME_QUANTUM); |
| 122 | } |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 123 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 124 | ath_print(ath9k_hw_common(ah), ATH_DBG_ANY, |
| 125 | "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n", |
| 126 | timeout, reg, REG_READ(ah, reg), mask, val); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 127 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 128 | return false; |
| 129 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 130 | EXPORT_SYMBOL(ath9k_hw_wait); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 131 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 132 | u32 ath9k_hw_reverse_bits(u32 val, u32 n) |
| 133 | { |
| 134 | u32 retval; |
| 135 | int i; |
| 136 | |
| 137 | for (i = 0, retval = 0; i < n; i++) { |
| 138 | retval = (retval << 1) | (val & 1); |
| 139 | val >>= 1; |
| 140 | } |
| 141 | return retval; |
| 142 | } |
| 143 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 144 | bool ath9k_get_channel_edges(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 145 | u16 flags, u16 *low, |
| 146 | u16 *high) |
| 147 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 148 | struct ath9k_hw_capabilities *pCap = &ah->caps; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 149 | |
| 150 | if (flags & CHANNEL_5GHZ) { |
| 151 | *low = pCap->low_5ghz_chan; |
| 152 | *high = pCap->high_5ghz_chan; |
| 153 | return true; |
| 154 | } |
| 155 | if ((flags & CHANNEL_2GHZ)) { |
| 156 | *low = pCap->low_2ghz_chan; |
| 157 | *high = pCap->high_2ghz_chan; |
| 158 | return true; |
| 159 | } |
| 160 | return false; |
| 161 | } |
| 162 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 163 | u16 ath9k_hw_computetxtime(struct ath_hw *ah, |
Felix Fietkau | 545750d | 2009-11-23 22:21:01 +0100 | [diff] [blame] | 164 | u8 phy, int kbps, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 165 | u32 frameLen, u16 rateix, |
| 166 | bool shortPreamble) |
| 167 | { |
| 168 | u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 169 | |
| 170 | if (kbps == 0) |
| 171 | return 0; |
| 172 | |
Felix Fietkau | 545750d | 2009-11-23 22:21:01 +0100 | [diff] [blame] | 173 | switch (phy) { |
Sujith | 46d14a5 | 2008-11-18 09:08:13 +0530 | [diff] [blame] | 174 | case WLAN_RC_PHY_CCK: |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 175 | phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS; |
Felix Fietkau | 545750d | 2009-11-23 22:21:01 +0100 | [diff] [blame] | 176 | if (shortPreamble) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 177 | phyTime >>= 1; |
| 178 | numBits = frameLen << 3; |
| 179 | txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps); |
| 180 | break; |
Sujith | 46d14a5 | 2008-11-18 09:08:13 +0530 | [diff] [blame] | 181 | case WLAN_RC_PHY_OFDM: |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 182 | if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 183 | bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000; |
| 184 | numBits = OFDM_PLCP_BITS + (frameLen << 3); |
| 185 | numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol); |
| 186 | txTime = OFDM_SIFS_TIME_QUARTER |
| 187 | + OFDM_PREAMBLE_TIME_QUARTER |
| 188 | + (numSymbols * OFDM_SYMBOL_TIME_QUARTER); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 189 | } else if (ah->curchan && |
| 190 | IS_CHAN_HALF_RATE(ah->curchan)) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 191 | bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000; |
| 192 | numBits = OFDM_PLCP_BITS + (frameLen << 3); |
| 193 | numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol); |
| 194 | txTime = OFDM_SIFS_TIME_HALF + |
| 195 | OFDM_PREAMBLE_TIME_HALF |
| 196 | + (numSymbols * OFDM_SYMBOL_TIME_HALF); |
| 197 | } else { |
| 198 | bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000; |
| 199 | numBits = OFDM_PLCP_BITS + (frameLen << 3); |
| 200 | numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol); |
| 201 | txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME |
| 202 | + (numSymbols * OFDM_SYMBOL_TIME); |
| 203 | } |
| 204 | break; |
| 205 | default: |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 206 | ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL, |
Felix Fietkau | 545750d | 2009-11-23 22:21:01 +0100 | [diff] [blame] | 207 | "Unknown phy %u (rate ix %u)\n", phy, rateix); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 208 | txTime = 0; |
| 209 | break; |
| 210 | } |
| 211 | |
| 212 | return txTime; |
| 213 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 214 | EXPORT_SYMBOL(ath9k_hw_computetxtime); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 215 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 216 | void ath9k_hw_get_channel_centers(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 217 | struct ath9k_channel *chan, |
| 218 | struct chan_centers *centers) |
| 219 | { |
| 220 | int8_t extoff; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 221 | |
| 222 | if (!IS_CHAN_HT40(chan)) { |
| 223 | centers->ctl_center = centers->ext_center = |
| 224 | centers->synth_center = chan->channel; |
| 225 | return; |
| 226 | } |
| 227 | |
| 228 | if ((chan->chanmode == CHANNEL_A_HT40PLUS) || |
| 229 | (chan->chanmode == CHANNEL_G_HT40PLUS)) { |
| 230 | centers->synth_center = |
| 231 | chan->channel + HT40_CHANNEL_CENTER_SHIFT; |
| 232 | extoff = 1; |
| 233 | } else { |
| 234 | centers->synth_center = |
| 235 | chan->channel - HT40_CHANNEL_CENTER_SHIFT; |
| 236 | extoff = -1; |
| 237 | } |
| 238 | |
| 239 | centers->ctl_center = |
| 240 | centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT); |
Luis R. Rodriguez | 6420014 | 2009-09-13 22:05:04 -0700 | [diff] [blame] | 241 | /* 25 MHz spacing is supported by hw but not on upper layers */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 242 | centers->ext_center = |
Luis R. Rodriguez | 6420014 | 2009-09-13 22:05:04 -0700 | [diff] [blame] | 243 | centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | /******************/ |
| 247 | /* Chip Revisions */ |
| 248 | /******************/ |
| 249 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 250 | static void ath9k_hw_read_revisions(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 251 | { |
| 252 | u32 val; |
| 253 | |
| 254 | val = REG_READ(ah, AR_SREV) & AR_SREV_ID; |
| 255 | |
| 256 | if (val == 0xFF) { |
| 257 | val = REG_READ(ah, AR_SREV); |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 258 | ah->hw_version.macVersion = |
| 259 | (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S; |
| 260 | ah->hw_version.macRev = MS(val, AR_SREV_REVISION2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 261 | ah->is_pciexpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 262 | } else { |
| 263 | if (!AR_SREV_9100(ah)) |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 264 | ah->hw_version.macVersion = MS(val, AR_SREV_VERSION); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 265 | |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 266 | ah->hw_version.macRev = val & AR_SREV_REVISION; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 267 | |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 268 | if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 269 | ah->is_pciexpress = true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 270 | } |
| 271 | } |
| 272 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 273 | /************************************/ |
| 274 | /* HW Attach, Detach, Init Routines */ |
| 275 | /************************************/ |
| 276 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 277 | static void ath9k_hw_disablepcie(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 278 | { |
Sujith | feed029 | 2009-01-29 11:37:35 +0530 | [diff] [blame] | 279 | if (AR_SREV_9100(ah)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 280 | return; |
| 281 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 282 | ENABLE_REGWRITE_BUFFER(ah); |
| 283 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 284 | REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00); |
| 285 | REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924); |
| 286 | REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029); |
| 287 | REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824); |
| 288 | REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579); |
| 289 | REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000); |
| 290 | REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40); |
| 291 | REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554); |
| 292 | REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007); |
| 293 | |
| 294 | REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000); |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 295 | |
| 296 | REGWRITE_BUFFER_FLUSH(ah); |
| 297 | DISABLE_REGWRITE_BUFFER(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 298 | } |
| 299 | |
Senthil Balasubramanian | 1f3f061 | 2010-04-15 17:38:29 -0400 | [diff] [blame] | 300 | /* This should work for all families including legacy */ |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 301 | static bool ath9k_hw_chip_test(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 302 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 303 | struct ath_common *common = ath9k_hw_common(ah); |
Senthil Balasubramanian | 1f3f061 | 2010-04-15 17:38:29 -0400 | [diff] [blame] | 304 | u32 regAddr[2] = { AR_STA_ID0 }; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 305 | u32 regHold[2]; |
| 306 | u32 patternData[4] = { 0x55555555, |
| 307 | 0xaaaaaaaa, |
| 308 | 0x66666666, |
| 309 | 0x99999999 }; |
Senthil Balasubramanian | 1f3f061 | 2010-04-15 17:38:29 -0400 | [diff] [blame] | 310 | int i, j, loop_max; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 311 | |
Senthil Balasubramanian | 1f3f061 | 2010-04-15 17:38:29 -0400 | [diff] [blame] | 312 | if (!AR_SREV_9300_20_OR_LATER(ah)) { |
| 313 | loop_max = 2; |
| 314 | regAddr[1] = AR_PHY_BASE + (8 << 2); |
| 315 | } else |
| 316 | loop_max = 1; |
| 317 | |
| 318 | for (i = 0; i < loop_max; i++) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 319 | u32 addr = regAddr[i]; |
| 320 | u32 wrData, rdData; |
| 321 | |
| 322 | regHold[i] = REG_READ(ah, addr); |
| 323 | for (j = 0; j < 0x100; j++) { |
| 324 | wrData = (j << 16) | j; |
| 325 | REG_WRITE(ah, addr, wrData); |
| 326 | rdData = REG_READ(ah, addr); |
| 327 | if (rdData != wrData) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 328 | ath_print(common, ATH_DBG_FATAL, |
| 329 | "address test failed " |
| 330 | "addr: 0x%08x - wr:0x%08x != " |
| 331 | "rd:0x%08x\n", |
| 332 | addr, wrData, rdData); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 333 | return false; |
| 334 | } |
| 335 | } |
| 336 | for (j = 0; j < 4; j++) { |
| 337 | wrData = patternData[j]; |
| 338 | REG_WRITE(ah, addr, wrData); |
| 339 | rdData = REG_READ(ah, addr); |
| 340 | if (wrData != rdData) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 341 | ath_print(common, ATH_DBG_FATAL, |
| 342 | "address test failed " |
| 343 | "addr: 0x%08x - wr:0x%08x != " |
| 344 | "rd:0x%08x\n", |
| 345 | addr, wrData, rdData); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 346 | return false; |
| 347 | } |
| 348 | } |
| 349 | REG_WRITE(ah, regAddr[i], regHold[i]); |
| 350 | } |
| 351 | udelay(100); |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 352 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 353 | return true; |
| 354 | } |
| 355 | |
Luis R. Rodriguez | b8b0f37 | 2009-08-03 12:24:43 -0700 | [diff] [blame] | 356 | static void ath9k_hw_init_config(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 357 | { |
| 358 | int i; |
| 359 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 360 | ah->config.dma_beacon_response_time = 2; |
| 361 | ah->config.sw_beacon_response_time = 10; |
| 362 | ah->config.additional_swba_backoff = 0; |
| 363 | ah->config.ack_6mb = 0x0; |
| 364 | ah->config.cwm_ignore_extcca = 0; |
| 365 | ah->config.pcie_powersave_enable = 0; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 366 | ah->config.pcie_clock_req = 0; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 367 | ah->config.pcie_waen = 0; |
| 368 | ah->config.analog_shiftreg = 1; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 369 | ah->config.ofdm_trig_low = 200; |
| 370 | ah->config.ofdm_trig_high = 500; |
| 371 | ah->config.cck_trig_high = 200; |
| 372 | ah->config.cck_trig_low = 100; |
Luis R. Rodriguez | 31a0bd3 | 2010-04-15 17:38:22 -0400 | [diff] [blame] | 373 | |
| 374 | /* |
| 375 | * For now ANI is disabled for AR9003, it is still |
| 376 | * being tested. |
| 377 | */ |
| 378 | if (!AR_SREV_9300_20_OR_LATER(ah)) |
| 379 | ah->config.enable_ani = 1; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 380 | |
| 381 | for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 382 | ah->config.spurchans[i][0] = AR_NO_SPUR; |
| 383 | ah->config.spurchans[i][1] = AR_NO_SPUR; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 384 | } |
| 385 | |
Luis R. Rodriguez | 5ffaf8a | 2010-02-02 11:58:33 -0500 | [diff] [blame] | 386 | if (ah->hw_version.devid != AR2427_DEVID_PCIE) |
| 387 | ah->config.ht_enable = 1; |
| 388 | else |
| 389 | ah->config.ht_enable = 0; |
| 390 | |
Sujith | 0ce024c | 2009-12-14 14:57:00 +0530 | [diff] [blame] | 391 | ah->config.rx_intr_mitigation = true; |
Luis R. Rodriguez | 6158425 | 2009-03-12 18:18:49 -0400 | [diff] [blame] | 392 | |
| 393 | /* |
Luis R. Rodriguez | b360a88 | 2010-04-26 15:04:32 -0400 | [diff] [blame] | 394 | * Tx IQ Calibration (ah->config.tx_iq_calibration) is only |
| 395 | * used by AR9003, but it is showing reliability issues. |
| 396 | * It will take a while to fix so this is currently disabled. |
| 397 | */ |
| 398 | |
| 399 | /* |
Luis R. Rodriguez | 6158425 | 2009-03-12 18:18:49 -0400 | [diff] [blame] | 400 | * We need this for PCI devices only (Cardbus, PCI, miniPCI) |
| 401 | * _and_ if on non-uniprocessor systems (Multiprocessor/HT). |
| 402 | * This means we use it for all AR5416 devices, and the few |
| 403 | * minor PCI AR9280 devices out there. |
| 404 | * |
| 405 | * Serialization is required because these devices do not handle |
| 406 | * well the case of two concurrent reads/writes due to the latency |
| 407 | * involved. During one read/write another read/write can be issued |
| 408 | * on another CPU while the previous read/write may still be working |
| 409 | * on our hardware, if we hit this case the hardware poops in a loop. |
| 410 | * We prevent this by serializing reads and writes. |
| 411 | * |
| 412 | * This issue is not present on PCI-Express devices or pre-AR5416 |
| 413 | * devices (legacy, 802.11abg). |
| 414 | */ |
| 415 | if (num_possible_cpus() > 1) |
David S. Miller | 2d6a5e9 | 2009-03-17 15:01:30 -0700 | [diff] [blame] | 416 | ah->config.serialize_regmode = SER_REG_MODE_AUTO; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 417 | } |
| 418 | |
Luis R. Rodriguez | 50aca25 | 2009-08-03 12:24:42 -0700 | [diff] [blame] | 419 | static void ath9k_hw_init_defaults(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 420 | { |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 421 | struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah); |
| 422 | |
| 423 | regulatory->country_code = CTRY_DEFAULT; |
| 424 | regulatory->power_limit = MAX_RATE_POWER; |
| 425 | regulatory->tp_scale = ATH9K_TP_SCALE_MAX; |
| 426 | |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 427 | ah->hw_version.magic = AR5416_MAGIC; |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 428 | ah->hw_version.subvendorid = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 429 | |
| 430 | ah->ah_flags = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 431 | if (!AR_SREV_9100(ah)) |
| 432 | ah->ah_flags = AH_USE_EEPROM; |
| 433 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 434 | ah->atim_window = 0; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 435 | ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE; |
| 436 | ah->beacon_interval = 100; |
| 437 | ah->enable_32kHz_clock = DONT_USE_32KHZ; |
| 438 | ah->slottime = (u32) -1; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 439 | ah->globaltxtimeout = (u32) -1; |
Gabor Juhos | cbdec97 | 2009-07-24 17:27:22 +0200 | [diff] [blame] | 440 | ah->power_mode = ATH9K_PM_UNDEFINED; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 443 | static int ath9k_hw_init_macaddr(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 444 | { |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 445 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 446 | u32 sum; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 447 | int i; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 448 | u16 eeval; |
Luis R. Rodriguez | 4910167 | 2010-04-15 17:39:13 -0400 | [diff] [blame] | 449 | u32 EEP_MAC[] = { EEP_MAC_LSW, EEP_MAC_MID, EEP_MAC_MSW }; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 450 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 451 | sum = 0; |
| 452 | for (i = 0; i < 3; i++) { |
Luis R. Rodriguez | 4910167 | 2010-04-15 17:39:13 -0400 | [diff] [blame] | 453 | eeval = ah->eep_ops->get_eeprom(ah, EEP_MAC[i]); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 454 | sum += eeval; |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 455 | common->macaddr[2 * i] = eeval >> 8; |
| 456 | common->macaddr[2 * i + 1] = eeval & 0xff; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 457 | } |
Sujith | d8baa93 | 2009-03-30 15:28:25 +0530 | [diff] [blame] | 458 | if (sum == 0 || sum == 0xffff * 3) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 459 | return -EADDRNOTAVAIL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 460 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 461 | return 0; |
| 462 | } |
| 463 | |
Luis R. Rodriguez | f637cfd | 2009-08-03 12:24:46 -0700 | [diff] [blame] | 464 | static int ath9k_hw_post_init(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 465 | { |
| 466 | int ecode; |
| 467 | |
Sujith | 527d485 | 2010-03-17 14:25:16 +0530 | [diff] [blame] | 468 | if (!AR_SREV_9271(ah)) { |
| 469 | if (!ath9k_hw_chip_test(ah)) |
| 470 | return -ENODEV; |
| 471 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 472 | |
Luis R. Rodriguez | ebd5a14 | 2010-04-15 17:39:18 -0400 | [diff] [blame] | 473 | if (!AR_SREV_9300_20_OR_LATER(ah)) { |
| 474 | ecode = ar9002_hw_rf_claim(ah); |
| 475 | if (ecode != 0) |
| 476 | return ecode; |
| 477 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 478 | |
Luis R. Rodriguez | f637cfd | 2009-08-03 12:24:46 -0700 | [diff] [blame] | 479 | ecode = ath9k_hw_eeprom_init(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 480 | if (ecode != 0) |
| 481 | return ecode; |
Sujith | 7d01b22 | 2009-03-13 08:55:55 +0530 | [diff] [blame] | 482 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 483 | ath_print(ath9k_hw_common(ah), ATH_DBG_CONFIG, |
| 484 | "Eeprom VER: %d, REV: %d\n", |
| 485 | ah->eep_ops->get_eeprom_ver(ah), |
| 486 | ah->eep_ops->get_eeprom_rev(ah)); |
Sujith | 7d01b22 | 2009-03-13 08:55:55 +0530 | [diff] [blame] | 487 | |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 488 | ecode = ath9k_hw_rf_alloc_ext_banks(ah); |
| 489 | if (ecode) { |
| 490 | ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL, |
| 491 | "Failed allocating banks for " |
| 492 | "external radio\n"); |
| 493 | return ecode; |
Luis R. Rodriguez | 574d6b1 | 2009-10-19 02:33:37 -0400 | [diff] [blame] | 494 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 495 | |
| 496 | if (!AR_SREV_9100(ah)) { |
| 497 | ath9k_hw_ani_setup(ah); |
Luis R. Rodriguez | f637cfd | 2009-08-03 12:24:46 -0700 | [diff] [blame] | 498 | ath9k_hw_ani_init(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 499 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 500 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 501 | return 0; |
| 502 | } |
| 503 | |
Luis R. Rodriguez | 8525f28 | 2010-04-15 17:38:19 -0400 | [diff] [blame] | 504 | static void ath9k_hw_attach_ops(struct ath_hw *ah) |
| 505 | { |
| 506 | if (AR_SREV_9300_20_OR_LATER(ah)) |
| 507 | ar9003_hw_attach_ops(ah); |
| 508 | else |
| 509 | ar9002_hw_attach_ops(ah); |
| 510 | } |
| 511 | |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 512 | /* Called for all hardware families */ |
| 513 | static int __ath9k_hw_init(struct ath_hw *ah) |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 514 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 515 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | 95fafca | 2009-08-03 12:24:54 -0700 | [diff] [blame] | 516 | int r = 0; |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 517 | |
Luis R. Rodriguez | bab1f62 | 2010-04-15 17:38:20 -0400 | [diff] [blame] | 518 | if (ah->hw_version.devid == AR5416_AR9100_DEVID) |
| 519 | ah->hw_version.macVersion = AR_SREV_VERSION_9100; |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 520 | |
| 521 | if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 522 | ath_print(common, ATH_DBG_FATAL, |
| 523 | "Couldn't reset chip\n"); |
Luis R. Rodriguez | 95fafca | 2009-08-03 12:24:54 -0700 | [diff] [blame] | 524 | return -EIO; |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 525 | } |
| 526 | |
Luis R. Rodriguez | bab1f62 | 2010-04-15 17:38:20 -0400 | [diff] [blame] | 527 | ath9k_hw_init_defaults(ah); |
| 528 | ath9k_hw_init_config(ah); |
| 529 | |
Luis R. Rodriguez | 8525f28 | 2010-04-15 17:38:19 -0400 | [diff] [blame] | 530 | ath9k_hw_attach_ops(ah); |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 531 | |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 532 | if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 533 | ath_print(common, ATH_DBG_FATAL, "Couldn't wakeup chip\n"); |
Luis R. Rodriguez | 95fafca | 2009-08-03 12:24:54 -0700 | [diff] [blame] | 534 | return -EIO; |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) { |
| 538 | if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI || |
| 539 | (AR_SREV_9280(ah) && !ah->is_pciexpress)) { |
| 540 | ah->config.serialize_regmode = |
| 541 | SER_REG_MODE_ON; |
| 542 | } else { |
| 543 | ah->config.serialize_regmode = |
| 544 | SER_REG_MODE_OFF; |
| 545 | } |
| 546 | } |
| 547 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 548 | ath_print(common, ATH_DBG_RESET, "serialize_regmode is %d\n", |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 549 | ah->config.serialize_regmode); |
| 550 | |
Luis R. Rodriguez | f4709fd | 2009-11-24 21:37:57 -0500 | [diff] [blame] | 551 | if (AR_SREV_9285(ah) || AR_SREV_9271(ah)) |
| 552 | ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD >> 1; |
| 553 | else |
| 554 | ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD; |
| 555 | |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 556 | if (!ath9k_hw_macversion_supported(ah)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 557 | ath_print(common, ATH_DBG_FATAL, |
| 558 | "Mac Chip Rev 0x%02x.%x is not supported by " |
| 559 | "this driver\n", ah->hw_version.macVersion, |
| 560 | ah->hw_version.macRev); |
Luis R. Rodriguez | 95fafca | 2009-08-03 12:24:54 -0700 | [diff] [blame] | 561 | return -EOPNOTSUPP; |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 562 | } |
| 563 | |
Luis R. Rodriguez | 0df13da | 2010-04-15 17:38:59 -0400 | [diff] [blame] | 564 | if (AR_SREV_9271(ah) || AR_SREV_9100(ah)) |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 565 | ah->is_pciexpress = false; |
| 566 | |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 567 | ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID); |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 568 | ath9k_hw_init_cal_settings(ah); |
| 569 | |
| 570 | ah->ani_function = ATH9K_ANI_ALL; |
Luis R. Rodriguez | 31a0bd3 | 2010-04-15 17:38:22 -0400 | [diff] [blame] | 571 | if (AR_SREV_9280_10_OR_LATER(ah) && !AR_SREV_9300_20_OR_LATER(ah)) |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 572 | ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL; |
| 573 | |
| 574 | ath9k_hw_init_mode_regs(ah); |
| 575 | |
| 576 | if (ah->is_pciexpress) |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 577 | ath9k_hw_configpcipowersave(ah, 0, 0); |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 578 | else |
| 579 | ath9k_hw_disablepcie(ah); |
| 580 | |
Luis R. Rodriguez | d8f492b | 2010-04-15 17:39:04 -0400 | [diff] [blame] | 581 | if (!AR_SREV_9300_20_OR_LATER(ah)) |
| 582 | ar9002_hw_cck_chan14_spread(ah); |
Sujith | 193cd45 | 2009-09-18 15:04:07 +0530 | [diff] [blame] | 583 | |
Luis R. Rodriguez | f637cfd | 2009-08-03 12:24:46 -0700 | [diff] [blame] | 584 | r = ath9k_hw_post_init(ah); |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 585 | if (r) |
Luis R. Rodriguez | 95fafca | 2009-08-03 12:24:54 -0700 | [diff] [blame] | 586 | return r; |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 587 | |
| 588 | ath9k_hw_init_mode_gain_regs(ah); |
Gabor Juhos | a9a29ce | 2009-11-27 12:01:35 +0100 | [diff] [blame] | 589 | r = ath9k_hw_fill_cap_info(ah); |
| 590 | if (r) |
| 591 | return r; |
| 592 | |
Luis R. Rodriguez | 4f3acf8 | 2009-08-03 12:24:36 -0700 | [diff] [blame] | 593 | r = ath9k_hw_init_macaddr(ah); |
| 594 | if (r) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 595 | ath_print(common, ATH_DBG_FATAL, |
| 596 | "Failed to initialize MAC address\n"); |
Luis R. Rodriguez | 95fafca | 2009-08-03 12:24:54 -0700 | [diff] [blame] | 597 | return r; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 598 | } |
| 599 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 600 | if (AR_SREV_9285(ah) || AR_SREV_9271(ah)) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 601 | ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 602 | else |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 603 | ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 604 | |
Felix Fietkau | 641d992 | 2010-04-15 17:38:49 -0400 | [diff] [blame] | 605 | if (AR_SREV_9300_20_OR_LATER(ah)) |
| 606 | ar9003_hw_set_nf_limits(ah); |
| 607 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 608 | ath9k_init_nfcal_hist_buffer(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 609 | |
Luis R. Rodriguez | 211f585 | 2009-10-06 21:19:07 -0400 | [diff] [blame] | 610 | common->state = ATH_HW_INITIALIZED; |
| 611 | |
Luis R. Rodriguez | 4f3acf8 | 2009-08-03 12:24:36 -0700 | [diff] [blame] | 612 | return 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 613 | } |
| 614 | |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 615 | int ath9k_hw_init(struct ath_hw *ah) |
| 616 | { |
| 617 | int ret; |
| 618 | struct ath_common *common = ath9k_hw_common(ah); |
| 619 | |
| 620 | /* These are all the AR5008/AR9001/AR9002 hardware family of chipsets */ |
| 621 | switch (ah->hw_version.devid) { |
| 622 | case AR5416_DEVID_PCI: |
| 623 | case AR5416_DEVID_PCIE: |
| 624 | case AR5416_AR9100_DEVID: |
| 625 | case AR9160_DEVID_PCI: |
| 626 | case AR9280_DEVID_PCI: |
| 627 | case AR9280_DEVID_PCIE: |
| 628 | case AR9285_DEVID_PCIE: |
Senthil Balasubramanian | db3cc53 | 2010-04-15 17:38:18 -0400 | [diff] [blame] | 629 | case AR9287_DEVID_PCI: |
| 630 | case AR9287_DEVID_PCIE: |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 631 | case AR2427_DEVID_PCIE: |
Senthil Balasubramanian | db3cc53 | 2010-04-15 17:38:18 -0400 | [diff] [blame] | 632 | case AR9300_DEVID_PCIE: |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 633 | break; |
| 634 | default: |
| 635 | if (common->bus_ops->ath_bus_type == ATH_USB) |
| 636 | break; |
| 637 | ath_print(common, ATH_DBG_FATAL, |
| 638 | "Hardware device ID 0x%04x not supported\n", |
| 639 | ah->hw_version.devid); |
| 640 | return -EOPNOTSUPP; |
| 641 | } |
| 642 | |
| 643 | ret = __ath9k_hw_init(ah); |
| 644 | if (ret) { |
| 645 | ath_print(common, ATH_DBG_FATAL, |
| 646 | "Unable to initialize hardware; " |
| 647 | "initialization status: %d\n", ret); |
| 648 | return ret; |
| 649 | } |
| 650 | |
| 651 | return 0; |
| 652 | } |
| 653 | EXPORT_SYMBOL(ath9k_hw_init); |
| 654 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 655 | static void ath9k_hw_init_qos(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 656 | { |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 657 | ENABLE_REGWRITE_BUFFER(ah); |
| 658 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 659 | REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa); |
| 660 | REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210); |
| 661 | |
| 662 | REG_WRITE(ah, AR_QOS_NO_ACK, |
| 663 | SM(2, AR_QOS_NO_ACK_TWO_BIT) | |
| 664 | SM(5, AR_QOS_NO_ACK_BIT_OFF) | |
| 665 | SM(0, AR_QOS_NO_ACK_BYTE_OFF)); |
| 666 | |
| 667 | REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL); |
| 668 | REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF); |
| 669 | REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF); |
| 670 | REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF); |
| 671 | REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF); |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 672 | |
| 673 | REGWRITE_BUFFER_FLUSH(ah); |
| 674 | DISABLE_REGWRITE_BUFFER(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 675 | } |
| 676 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 677 | static void ath9k_hw_init_pll(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 678 | struct ath9k_channel *chan) |
| 679 | { |
Luis R. Rodriguez | 6477396 | 2010-04-15 17:38:17 -0400 | [diff] [blame] | 680 | u32 pll = ath9k_hw_compute_pll_control(ah, chan); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 681 | |
Gabor Juhos | d03a66c | 2009-01-14 20:17:09 +0100 | [diff] [blame] | 682 | REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 683 | |
Luis R. Rodriguez | c75724d | 2009-10-19 02:33:34 -0400 | [diff] [blame] | 684 | /* Switch the core clock for ar9271 to 117Mhz */ |
| 685 | if (AR_SREV_9271(ah)) { |
Sujith | 25e2ab1 | 2010-03-17 14:25:22 +0530 | [diff] [blame] | 686 | udelay(500); |
| 687 | REG_WRITE(ah, 0x50040, 0x304); |
Luis R. Rodriguez | c75724d | 2009-10-19 02:33:34 -0400 | [diff] [blame] | 688 | } |
| 689 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 690 | udelay(RTC_PLL_SETTLE_DELAY); |
| 691 | |
| 692 | REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK); |
| 693 | } |
| 694 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 695 | static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah, |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 696 | enum nl80211_iftype opmode) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 697 | { |
Pavel Roskin | 152d530 | 2010-03-31 18:05:37 -0400 | [diff] [blame] | 698 | u32 imr_reg = AR_IMR_TXERR | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 699 | AR_IMR_TXURN | |
| 700 | AR_IMR_RXERR | |
| 701 | AR_IMR_RXORN | |
| 702 | AR_IMR_BCNMISC; |
| 703 | |
Vasanthakumar Thiagarajan | 6686024 | 2010-04-15 17:39:07 -0400 | [diff] [blame] | 704 | if (AR_SREV_9300_20_OR_LATER(ah)) { |
| 705 | imr_reg |= AR_IMR_RXOK_HP; |
| 706 | if (ah->config.rx_intr_mitigation) |
| 707 | imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR; |
| 708 | else |
| 709 | imr_reg |= AR_IMR_RXOK_LP; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 710 | |
Vasanthakumar Thiagarajan | 6686024 | 2010-04-15 17:39:07 -0400 | [diff] [blame] | 711 | } else { |
| 712 | if (ah->config.rx_intr_mitigation) |
| 713 | imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR; |
| 714 | else |
| 715 | imr_reg |= AR_IMR_RXOK; |
| 716 | } |
| 717 | |
| 718 | if (ah->config.tx_intr_mitigation) |
| 719 | imr_reg |= AR_IMR_TXINTM | AR_IMR_TXMINTR; |
| 720 | else |
| 721 | imr_reg |= AR_IMR_TXOK; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 722 | |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 723 | if (opmode == NL80211_IFTYPE_AP) |
Pavel Roskin | 152d530 | 2010-03-31 18:05:37 -0400 | [diff] [blame] | 724 | imr_reg |= AR_IMR_MIB; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 725 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 726 | ENABLE_REGWRITE_BUFFER(ah); |
| 727 | |
Pavel Roskin | 152d530 | 2010-03-31 18:05:37 -0400 | [diff] [blame] | 728 | REG_WRITE(ah, AR_IMR, imr_reg); |
Pavel Roskin | 74bad5c | 2010-02-23 18:15:27 -0500 | [diff] [blame] | 729 | ah->imrs2_reg |= AR_IMR_S2_GTT; |
| 730 | REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 731 | |
| 732 | if (!AR_SREV_9100(ah)) { |
| 733 | REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF); |
| 734 | REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT); |
| 735 | REG_WRITE(ah, AR_INTR_SYNC_MASK, 0); |
| 736 | } |
Vasanthakumar Thiagarajan | 6686024 | 2010-04-15 17:39:07 -0400 | [diff] [blame] | 737 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 738 | REGWRITE_BUFFER_FLUSH(ah); |
| 739 | DISABLE_REGWRITE_BUFFER(ah); |
| 740 | |
Vasanthakumar Thiagarajan | 6686024 | 2010-04-15 17:39:07 -0400 | [diff] [blame] | 741 | if (AR_SREV_9300_20_OR_LATER(ah)) { |
| 742 | REG_WRITE(ah, AR_INTR_PRIO_ASYNC_ENABLE, 0); |
| 743 | REG_WRITE(ah, AR_INTR_PRIO_ASYNC_MASK, 0); |
| 744 | REG_WRITE(ah, AR_INTR_PRIO_SYNC_ENABLE, 0); |
| 745 | REG_WRITE(ah, AR_INTR_PRIO_SYNC_MASK, 0); |
| 746 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 747 | } |
| 748 | |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 749 | static void ath9k_hw_setslottime(struct ath_hw *ah, u32 us) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 750 | { |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 751 | u32 val = ath9k_hw_mac_to_clks(ah, us); |
| 752 | val = min(val, (u32) 0xFFFF); |
| 753 | REG_WRITE(ah, AR_D_GBL_IFS_SLOT, val); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 754 | } |
| 755 | |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 756 | static void ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 757 | { |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 758 | u32 val = ath9k_hw_mac_to_clks(ah, us); |
| 759 | val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_ACK)); |
| 760 | REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_ACK, val); |
| 761 | } |
| 762 | |
| 763 | static void ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us) |
| 764 | { |
| 765 | u32 val = ath9k_hw_mac_to_clks(ah, us); |
| 766 | val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_CTS)); |
| 767 | REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_CTS, val); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 768 | } |
| 769 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 770 | static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 771 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 772 | if (tu > 0xFFFF) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 773 | ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT, |
| 774 | "bad global tx timeout %u\n", tu); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 775 | ah->globaltxtimeout = (u32) -1; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 776 | return false; |
| 777 | } else { |
| 778 | REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 779 | ah->globaltxtimeout = tu; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 780 | return true; |
| 781 | } |
| 782 | } |
| 783 | |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 784 | void ath9k_hw_init_global_settings(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 785 | { |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 786 | struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf; |
| 787 | int acktimeout; |
Felix Fietkau | e239d85 | 2010-01-15 02:34:58 +0100 | [diff] [blame] | 788 | int slottime; |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 789 | int sifstime; |
| 790 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 791 | ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, "ah->misc_mode 0x%x\n", |
| 792 | ah->misc_mode); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 793 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 794 | if (ah->misc_mode != 0) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 795 | REG_WRITE(ah, AR_PCU_MISC, |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 796 | REG_READ(ah, AR_PCU_MISC) | ah->misc_mode); |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 797 | |
| 798 | if (conf->channel && conf->channel->band == IEEE80211_BAND_5GHZ) |
| 799 | sifstime = 16; |
| 800 | else |
| 801 | sifstime = 10; |
| 802 | |
Felix Fietkau | e239d85 | 2010-01-15 02:34:58 +0100 | [diff] [blame] | 803 | /* As defined by IEEE 802.11-2007 17.3.8.6 */ |
| 804 | slottime = ah->slottime + 3 * ah->coverage_class; |
| 805 | acktimeout = slottime + sifstime; |
Felix Fietkau | 42c4568 | 2010-02-11 18:07:19 +0100 | [diff] [blame] | 806 | |
| 807 | /* |
| 808 | * Workaround for early ACK timeouts, add an offset to match the |
| 809 | * initval's 64us ack timeout value. |
| 810 | * This was initially only meant to work around an issue with delayed |
| 811 | * BA frames in some implementations, but it has been found to fix ACK |
| 812 | * timeout issues in other cases as well. |
| 813 | */ |
| 814 | if (conf->channel && conf->channel->band == IEEE80211_BAND_2GHZ) |
| 815 | acktimeout += 64 - sifstime - ah->slottime; |
| 816 | |
Felix Fietkau | e239d85 | 2010-01-15 02:34:58 +0100 | [diff] [blame] | 817 | ath9k_hw_setslottime(ah, slottime); |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 818 | ath9k_hw_set_ack_timeout(ah, acktimeout); |
| 819 | ath9k_hw_set_cts_timeout(ah, acktimeout); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 820 | if (ah->globaltxtimeout != (u32) -1) |
| 821 | ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 822 | } |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 823 | EXPORT_SYMBOL(ath9k_hw_init_global_settings); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 824 | |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 825 | void ath9k_hw_deinit(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 826 | { |
Luis R. Rodriguez | 211f585 | 2009-10-06 21:19:07 -0400 | [diff] [blame] | 827 | struct ath_common *common = ath9k_hw_common(ah); |
| 828 | |
Sujith | 736b3a2 | 2010-03-17 14:25:24 +0530 | [diff] [blame] | 829 | if (common->state < ATH_HW_INITIALIZED) |
Luis R. Rodriguez | 211f585 | 2009-10-06 21:19:07 -0400 | [diff] [blame] | 830 | goto free_hw; |
| 831 | |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 832 | ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP); |
Luis R. Rodriguez | 211f585 | 2009-10-06 21:19:07 -0400 | [diff] [blame] | 833 | |
| 834 | free_hw: |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 835 | ath9k_hw_rf_free_ext_banks(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 836 | } |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 837 | EXPORT_SYMBOL(ath9k_hw_deinit); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 838 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 839 | /*******/ |
| 840 | /* INI */ |
| 841 | /*******/ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 842 | |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 843 | u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan) |
Bob Copeland | 3a702e4 | 2009-03-30 22:30:29 -0400 | [diff] [blame] | 844 | { |
| 845 | u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band); |
| 846 | |
| 847 | if (IS_CHAN_B(chan)) |
| 848 | ctl |= CTL_11B; |
| 849 | else if (IS_CHAN_G(chan)) |
| 850 | ctl |= CTL_11G; |
| 851 | else |
| 852 | ctl |= CTL_11A; |
| 853 | |
| 854 | return ctl; |
| 855 | } |
| 856 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 857 | /****************************************/ |
| 858 | /* Reset and Channel Switching Routines */ |
| 859 | /****************************************/ |
| 860 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 861 | static inline void ath9k_hw_set_dma(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 862 | { |
Felix Fietkau | 57b3222 | 2010-04-15 17:39:22 -0400 | [diff] [blame] | 863 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 864 | u32 regval; |
| 865 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 866 | ENABLE_REGWRITE_BUFFER(ah); |
| 867 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 868 | /* |
| 869 | * set AHB_MODE not to do cacheline prefetches |
| 870 | */ |
Felix Fietkau | 57b3222 | 2010-04-15 17:39:22 -0400 | [diff] [blame] | 871 | if (!AR_SREV_9300_20_OR_LATER(ah)) { |
| 872 | regval = REG_READ(ah, AR_AHB_MODE); |
| 873 | REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN); |
| 874 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 875 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 876 | /* |
| 877 | * let mac dma reads be in 128 byte chunks |
| 878 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 879 | regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK; |
| 880 | REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B); |
| 881 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 882 | REGWRITE_BUFFER_FLUSH(ah); |
| 883 | DISABLE_REGWRITE_BUFFER(ah); |
| 884 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 885 | /* |
| 886 | * Restore TX Trigger Level to its pre-reset value. |
| 887 | * The initial value depends on whether aggregation is enabled, and is |
| 888 | * adjusted whenever underruns are detected. |
| 889 | */ |
Felix Fietkau | 57b3222 | 2010-04-15 17:39:22 -0400 | [diff] [blame] | 890 | if (!AR_SREV_9300_20_OR_LATER(ah)) |
| 891 | REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 892 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 893 | ENABLE_REGWRITE_BUFFER(ah); |
| 894 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 895 | /* |
| 896 | * let mac dma writes be in 128 byte chunks |
| 897 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 898 | regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK; |
| 899 | REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B); |
| 900 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 901 | /* |
| 902 | * Setup receive FIFO threshold to hold off TX activities |
| 903 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 904 | REG_WRITE(ah, AR_RXFIFO_CFG, 0x200); |
| 905 | |
Felix Fietkau | 57b3222 | 2010-04-15 17:39:22 -0400 | [diff] [blame] | 906 | if (AR_SREV_9300_20_OR_LATER(ah)) { |
| 907 | REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_HP, 0x1); |
| 908 | REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_LP, 0x1); |
| 909 | |
| 910 | ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize - |
| 911 | ah->caps.rx_status_len); |
| 912 | } |
| 913 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 914 | /* |
| 915 | * reduce the number of usable entries in PCU TXBUF to avoid |
| 916 | * wrap around issues. |
| 917 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 918 | if (AR_SREV_9285(ah)) { |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 919 | /* For AR9285 the number of Fifos are reduced to half. |
| 920 | * So set the usable tx buf size also to half to |
| 921 | * avoid data/delimiter underruns |
| 922 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 923 | REG_WRITE(ah, AR_PCU_TXBUF_CTRL, |
| 924 | AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE); |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 925 | } else if (!AR_SREV_9271(ah)) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 926 | REG_WRITE(ah, AR_PCU_TXBUF_CTRL, |
| 927 | AR_PCU_TXBUF_CTRL_USABLE_SIZE); |
| 928 | } |
Vasanthakumar Thiagarajan | 744d402 | 2010-04-15 17:39:27 -0400 | [diff] [blame] | 929 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 930 | REGWRITE_BUFFER_FLUSH(ah); |
| 931 | DISABLE_REGWRITE_BUFFER(ah); |
| 932 | |
Vasanthakumar Thiagarajan | 744d402 | 2010-04-15 17:39:27 -0400 | [diff] [blame] | 933 | if (AR_SREV_9300_20_OR_LATER(ah)) |
| 934 | ath9k_hw_reset_txstatus_ring(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 935 | } |
| 936 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 937 | static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 938 | { |
| 939 | u32 val; |
| 940 | |
| 941 | val = REG_READ(ah, AR_STA_ID1); |
| 942 | val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC); |
| 943 | switch (opmode) { |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 944 | case NL80211_IFTYPE_AP: |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 945 | REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP |
| 946 | | AR_STA_ID1_KSRCH_MODE); |
| 947 | REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION); |
| 948 | break; |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 949 | case NL80211_IFTYPE_ADHOC: |
Pat Erley | 9cb5412 | 2009-03-20 22:59:59 -0400 | [diff] [blame] | 950 | case NL80211_IFTYPE_MESH_POINT: |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 951 | REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC |
| 952 | | AR_STA_ID1_KSRCH_MODE); |
| 953 | REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION); |
| 954 | break; |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 955 | case NL80211_IFTYPE_STATION: |
| 956 | case NL80211_IFTYPE_MONITOR: |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 957 | REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE); |
| 958 | break; |
| 959 | } |
| 960 | } |
| 961 | |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 962 | void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled, |
| 963 | u32 *coef_mantissa, u32 *coef_exponent) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 964 | { |
| 965 | u32 coef_exp, coef_man; |
| 966 | |
| 967 | for (coef_exp = 31; coef_exp > 0; coef_exp--) |
| 968 | if ((coef_scaled >> coef_exp) & 0x1) |
| 969 | break; |
| 970 | |
| 971 | coef_exp = 14 - (coef_exp - COEF_SCALE_S); |
| 972 | |
| 973 | coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1)); |
| 974 | |
| 975 | *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp); |
| 976 | *coef_exponent = coef_exp - 16; |
| 977 | } |
| 978 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 979 | static bool ath9k_hw_set_reset(struct ath_hw *ah, int type) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 980 | { |
| 981 | u32 rst_flags; |
| 982 | u32 tmpReg; |
| 983 | |
Sujith | 7076849 | 2009-02-16 13:23:12 +0530 | [diff] [blame] | 984 | if (AR_SREV_9100(ah)) { |
| 985 | u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK); |
| 986 | val &= ~AR_RTC_DERIVED_CLK_PERIOD; |
| 987 | val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD); |
| 988 | REG_WRITE(ah, AR_RTC_DERIVED_CLK, val); |
| 989 | (void)REG_READ(ah, AR_RTC_DERIVED_CLK); |
| 990 | } |
| 991 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 992 | ENABLE_REGWRITE_BUFFER(ah); |
| 993 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 994 | REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN | |
| 995 | AR_RTC_FORCE_WAKE_ON_INT); |
| 996 | |
| 997 | if (AR_SREV_9100(ah)) { |
| 998 | rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD | |
| 999 | AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET; |
| 1000 | } else { |
| 1001 | tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE); |
| 1002 | if (tmpReg & |
| 1003 | (AR_INTR_SYNC_LOCAL_TIMEOUT | |
| 1004 | AR_INTR_SYNC_RADM_CPL_TIMEOUT)) { |
Luis R. Rodriguez | 42d5bc3 | 2010-04-15 17:38:12 -0400 | [diff] [blame] | 1005 | u32 val; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1006 | REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0); |
Luis R. Rodriguez | 42d5bc3 | 2010-04-15 17:38:12 -0400 | [diff] [blame] | 1007 | |
| 1008 | val = AR_RC_HOSTIF; |
| 1009 | if (!AR_SREV_9300_20_OR_LATER(ah)) |
| 1010 | val |= AR_RC_AHB; |
| 1011 | REG_WRITE(ah, AR_RC, val); |
| 1012 | |
| 1013 | } else if (!AR_SREV_9300_20_OR_LATER(ah)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1014 | REG_WRITE(ah, AR_RC, AR_RC_AHB); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1015 | |
| 1016 | rst_flags = AR_RTC_RC_MAC_WARM; |
| 1017 | if (type == ATH9K_RESET_COLD) |
| 1018 | rst_flags |= AR_RTC_RC_MAC_COLD; |
| 1019 | } |
| 1020 | |
Gabor Juhos | d03a66c | 2009-01-14 20:17:09 +0100 | [diff] [blame] | 1021 | REG_WRITE(ah, AR_RTC_RC, rst_flags); |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1022 | |
| 1023 | REGWRITE_BUFFER_FLUSH(ah); |
| 1024 | DISABLE_REGWRITE_BUFFER(ah); |
| 1025 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1026 | udelay(50); |
| 1027 | |
Gabor Juhos | d03a66c | 2009-01-14 20:17:09 +0100 | [diff] [blame] | 1028 | REG_WRITE(ah, AR_RTC_RC, 0); |
Sujith | 0caa7b1 | 2009-02-16 13:23:20 +0530 | [diff] [blame] | 1029 | if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1030 | ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, |
| 1031 | "RTC stuck in MAC reset\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1032 | return false; |
| 1033 | } |
| 1034 | |
| 1035 | if (!AR_SREV_9100(ah)) |
| 1036 | REG_WRITE(ah, AR_RC, 0); |
| 1037 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1038 | if (AR_SREV_9100(ah)) |
| 1039 | udelay(50); |
| 1040 | |
| 1041 | return true; |
| 1042 | } |
| 1043 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1044 | static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1045 | { |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1046 | ENABLE_REGWRITE_BUFFER(ah); |
| 1047 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1048 | REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN | |
| 1049 | AR_RTC_FORCE_WAKE_ON_INT); |
| 1050 | |
Luis R. Rodriguez | 42d5bc3 | 2010-04-15 17:38:12 -0400 | [diff] [blame] | 1051 | if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah)) |
Vasanthakumar Thiagarajan | 1c29ce6 | 2009-08-31 17:48:36 +0530 | [diff] [blame] | 1052 | REG_WRITE(ah, AR_RC, AR_RC_AHB); |
| 1053 | |
Gabor Juhos | d03a66c | 2009-01-14 20:17:09 +0100 | [diff] [blame] | 1054 | REG_WRITE(ah, AR_RTC_RESET, 0); |
Vasanthakumar Thiagarajan | 1c29ce6 | 2009-08-31 17:48:36 +0530 | [diff] [blame] | 1055 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1056 | REGWRITE_BUFFER_FLUSH(ah); |
| 1057 | DISABLE_REGWRITE_BUFFER(ah); |
| 1058 | |
Senthil Balasubramanian | 84e2169 | 2010-04-15 17:38:30 -0400 | [diff] [blame] | 1059 | if (!AR_SREV_9300_20_OR_LATER(ah)) |
| 1060 | udelay(2); |
| 1061 | |
| 1062 | if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah)) |
Vasanthakumar Thiagarajan | 1c29ce6 | 2009-08-31 17:48:36 +0530 | [diff] [blame] | 1063 | REG_WRITE(ah, AR_RC, 0); |
| 1064 | |
Gabor Juhos | d03a66c | 2009-01-14 20:17:09 +0100 | [diff] [blame] | 1065 | REG_WRITE(ah, AR_RTC_RESET, 1); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1066 | |
| 1067 | if (!ath9k_hw_wait(ah, |
| 1068 | AR_RTC_STATUS, |
| 1069 | AR_RTC_STATUS_M, |
Sujith | 0caa7b1 | 2009-02-16 13:23:20 +0530 | [diff] [blame] | 1070 | AR_RTC_STATUS_ON, |
| 1071 | AH_WAIT_TIMEOUT)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1072 | ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, |
| 1073 | "RTC not waking up\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1074 | return false; |
| 1075 | } |
| 1076 | |
| 1077 | ath9k_hw_read_revisions(ah); |
| 1078 | |
| 1079 | return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM); |
| 1080 | } |
| 1081 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1082 | static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1083 | { |
| 1084 | REG_WRITE(ah, AR_RTC_FORCE_WAKE, |
| 1085 | AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT); |
| 1086 | |
| 1087 | switch (type) { |
| 1088 | case ATH9K_RESET_POWER_ON: |
| 1089 | return ath9k_hw_set_reset_power_on(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1090 | case ATH9K_RESET_WARM: |
| 1091 | case ATH9K_RESET_COLD: |
| 1092 | return ath9k_hw_set_reset(ah, type); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1093 | default: |
| 1094 | return false; |
| 1095 | } |
| 1096 | } |
| 1097 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1098 | static bool ath9k_hw_chip_reset(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1099 | struct ath9k_channel *chan) |
| 1100 | { |
Vivek Natarajan | 42abfbe | 2009-09-17 09:27:59 +0530 | [diff] [blame] | 1101 | if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) { |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 1102 | if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) |
| 1103 | return false; |
| 1104 | } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1105 | return false; |
| 1106 | |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 1107 | if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1108 | return false; |
| 1109 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1110 | ah->chip_fullsleep = false; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1111 | ath9k_hw_init_pll(ah, chan); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1112 | ath9k_hw_set_rfmode(ah, chan); |
| 1113 | |
| 1114 | return true; |
| 1115 | } |
| 1116 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1117 | static bool ath9k_hw_channel_change(struct ath_hw *ah, |
Luis R. Rodriguez | 25c56ee | 2009-09-13 23:04:44 -0700 | [diff] [blame] | 1118 | struct ath9k_channel *chan) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1119 | { |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 1120 | struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1121 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 1122 | struct ieee80211_channel *channel = chan->chan; |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1123 | u32 qnum; |
Luis R. Rodriguez | 0a3b7ba | 2009-10-19 02:33:40 -0400 | [diff] [blame] | 1124 | int r; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1125 | |
| 1126 | for (qnum = 0; qnum < AR_NUM_QCU; qnum++) { |
| 1127 | if (ath9k_hw_numtxpending(ah, qnum)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1128 | ath_print(common, ATH_DBG_QUEUE, |
| 1129 | "Transmit frames pending on " |
| 1130 | "queue %d\n", qnum); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1131 | return false; |
| 1132 | } |
| 1133 | } |
| 1134 | |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1135 | if (!ath9k_hw_rfbus_req(ah)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1136 | ath_print(common, ATH_DBG_FATAL, |
| 1137 | "Could not kill baseband RX\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1138 | return false; |
| 1139 | } |
| 1140 | |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1141 | ath9k_hw_set_channel_regs(ah, chan); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1142 | |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1143 | r = ath9k_hw_rf_set_freq(ah, chan); |
Luis R. Rodriguez | 0a3b7ba | 2009-10-19 02:33:40 -0400 | [diff] [blame] | 1144 | if (r) { |
| 1145 | ath_print(common, ATH_DBG_FATAL, |
| 1146 | "Failed to set channel\n"); |
| 1147 | return false; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1148 | } |
| 1149 | |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 1150 | ah->eep_ops->set_txpower(ah, chan, |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 1151 | ath9k_regd_get_ctl(regulatory, chan), |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1152 | channel->max_antenna_gain * 2, |
| 1153 | channel->max_power * 2, |
| 1154 | min((u32) MAX_RATE_POWER, |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 1155 | (u32) regulatory->power_limit)); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1156 | |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1157 | ath9k_hw_rfbus_done(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1158 | |
| 1159 | if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan)) |
| 1160 | ath9k_hw_set_delta_slope(ah, chan); |
| 1161 | |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1162 | ath9k_hw_spur_mitigate_freq(ah, chan); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1163 | |
| 1164 | if (!chan->oneTimeCalsDone) |
| 1165 | chan->oneTimeCalsDone = true; |
| 1166 | |
| 1167 | return true; |
| 1168 | } |
| 1169 | |
Felix Fietkau | c9c99e5 | 2010-04-19 19:57:29 +0200 | [diff] [blame] | 1170 | bool ath9k_hw_check_alive(struct ath_hw *ah) |
| 1171 | { |
| 1172 | int count = 50; |
| 1173 | u32 reg; |
| 1174 | |
| 1175 | if (AR_SREV_9285_10_OR_LATER(ah)) |
| 1176 | return true; |
| 1177 | |
| 1178 | do { |
| 1179 | reg = REG_READ(ah, AR_OBS_BUS_1); |
| 1180 | |
| 1181 | if ((reg & 0x7E7FFFEF) == 0x00702400) |
| 1182 | continue; |
| 1183 | |
| 1184 | switch (reg & 0x7E000B00) { |
| 1185 | case 0x1E000000: |
| 1186 | case 0x52000B00: |
| 1187 | case 0x18000B00: |
| 1188 | continue; |
| 1189 | default: |
| 1190 | return true; |
| 1191 | } |
| 1192 | } while (count-- > 0); |
| 1193 | |
| 1194 | return false; |
| 1195 | } |
| 1196 | EXPORT_SYMBOL(ath9k_hw_check_alive); |
| 1197 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1198 | int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan, |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 1199 | bool bChannelChange) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1200 | { |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 1201 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1202 | u32 saveLedState; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1203 | struct ath9k_channel *curchan = ah->curchan; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1204 | u32 saveDefAntenna; |
| 1205 | u32 macStaId1; |
Sujith | 46fe782 | 2009-09-17 09:25:25 +0530 | [diff] [blame] | 1206 | u64 tsf = 0; |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1207 | int i, r; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1208 | |
Luis R. Rodriguez | 43c2761 | 2009-09-13 21:07:07 -0700 | [diff] [blame] | 1209 | ah->txchainmask = common->tx_chainmask; |
| 1210 | ah->rxchainmask = common->rx_chainmask; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1211 | |
Vasanthakumar Thiagarajan | 9b9cc61 | 2010-04-15 17:39:41 -0400 | [diff] [blame] | 1212 | if (!ah->chip_fullsleep) { |
| 1213 | ath9k_hw_abortpcurecv(ah); |
| 1214 | if (!ath9k_hw_stopdmarecv(ah)) |
| 1215 | ath_print(common, ATH_DBG_XMIT, |
| 1216 | "Failed to stop receive dma\n"); |
| 1217 | } |
| 1218 | |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 1219 | if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 1220 | return -EIO; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1221 | |
Vasanthakumar Thiagarajan | 9ebef799 | 2009-09-17 09:26:44 +0530 | [diff] [blame] | 1222 | if (curchan && !ah->chip_fullsleep) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1223 | ath9k_hw_getnf(ah, curchan); |
| 1224 | |
| 1225 | if (bChannelChange && |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1226 | (ah->chip_fullsleep != true) && |
| 1227 | (ah->curchan != NULL) && |
| 1228 | (chan->channel != ah->curchan->channel) && |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1229 | ((chan->channelFlags & CHANNEL_ALL) == |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1230 | (ah->curchan->channelFlags & CHANNEL_ALL)) && |
Vasanthakumar Thiagarajan | 0a475cc | 2009-09-17 09:27:10 +0530 | [diff] [blame] | 1231 | !(AR_SREV_9280(ah) || IS_CHAN_A_5MHZ_SPACED(chan) || |
| 1232 | IS_CHAN_A_5MHZ_SPACED(ah->curchan))) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1233 | |
Luis R. Rodriguez | 25c56ee | 2009-09-13 23:04:44 -0700 | [diff] [blame] | 1234 | if (ath9k_hw_channel_change(ah, chan)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1235 | ath9k_hw_loadnf(ah, ah->curchan); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1236 | ath9k_hw_start_nfcal(ah); |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 1237 | return 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1238 | } |
| 1239 | } |
| 1240 | |
| 1241 | saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA); |
| 1242 | if (saveDefAntenna == 0) |
| 1243 | saveDefAntenna = 1; |
| 1244 | |
| 1245 | macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B; |
| 1246 | |
Sujith | 46fe782 | 2009-09-17 09:25:25 +0530 | [diff] [blame] | 1247 | /* For chips on which RTC reset is done, save TSF before it gets cleared */ |
| 1248 | if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) |
| 1249 | tsf = ath9k_hw_gettsf64(ah); |
| 1250 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1251 | saveLedState = REG_READ(ah, AR_CFG_LED) & |
| 1252 | (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL | |
| 1253 | AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW); |
| 1254 | |
| 1255 | ath9k_hw_mark_phy_inactive(ah); |
| 1256 | |
Sujith | 05020d2 | 2010-03-17 14:25:23 +0530 | [diff] [blame] | 1257 | /* Only required on the first reset */ |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1258 | if (AR_SREV_9271(ah) && ah->htc_reset_init) { |
| 1259 | REG_WRITE(ah, |
| 1260 | AR9271_RESET_POWER_DOWN_CONTROL, |
| 1261 | AR9271_RADIO_RF_RST); |
| 1262 | udelay(50); |
| 1263 | } |
| 1264 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1265 | if (!ath9k_hw_chip_reset(ah, chan)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1266 | ath_print(common, ATH_DBG_FATAL, "Chip reset failed\n"); |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 1267 | return -EINVAL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1268 | } |
| 1269 | |
Sujith | 05020d2 | 2010-03-17 14:25:23 +0530 | [diff] [blame] | 1270 | /* Only required on the first reset */ |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1271 | if (AR_SREV_9271(ah) && ah->htc_reset_init) { |
| 1272 | ah->htc_reset_init = false; |
| 1273 | REG_WRITE(ah, |
| 1274 | AR9271_RESET_POWER_DOWN_CONTROL, |
| 1275 | AR9271_GATE_MAC_CTL); |
| 1276 | udelay(50); |
| 1277 | } |
| 1278 | |
Sujith | 46fe782 | 2009-09-17 09:25:25 +0530 | [diff] [blame] | 1279 | /* Restore TSF */ |
| 1280 | if (tsf && AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) |
| 1281 | ath9k_hw_settsf64(ah, tsf); |
| 1282 | |
Vasanthakumar Thiagarajan | 369391d | 2009-01-21 19:24:13 +0530 | [diff] [blame] | 1283 | if (AR_SREV_9280_10_OR_LATER(ah)) |
| 1284 | REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1285 | |
Luis R. Rodriguez | 25c56ee | 2009-09-13 23:04:44 -0700 | [diff] [blame] | 1286 | r = ath9k_hw_process_ini(ah, chan); |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 1287 | if (r) |
| 1288 | return r; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1289 | |
Jouni Malinen | 0ced0e1 | 2009-01-08 13:32:13 +0200 | [diff] [blame] | 1290 | /* Setup MFP options for CCMP */ |
| 1291 | if (AR_SREV_9280_20_OR_LATER(ah)) { |
| 1292 | /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt |
| 1293 | * frames when constructing CCMP AAD. */ |
| 1294 | REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT, |
| 1295 | 0xc7ff); |
| 1296 | ah->sw_mgmt_crypto = false; |
| 1297 | } else if (AR_SREV_9160_10_OR_LATER(ah)) { |
| 1298 | /* Disable hardware crypto for management frames */ |
| 1299 | REG_CLR_BIT(ah, AR_PCU_MISC_MODE2, |
| 1300 | AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE); |
| 1301 | REG_SET_BIT(ah, AR_PCU_MISC_MODE2, |
| 1302 | AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT); |
| 1303 | ah->sw_mgmt_crypto = true; |
| 1304 | } else |
| 1305 | ah->sw_mgmt_crypto = true; |
| 1306 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1307 | if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan)) |
| 1308 | ath9k_hw_set_delta_slope(ah, chan); |
| 1309 | |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1310 | ath9k_hw_spur_mitigate_freq(ah, chan); |
Sujith | d650915 | 2009-03-13 08:56:05 +0530 | [diff] [blame] | 1311 | ah->eep_ops->set_board_values(ah, chan); |
Luis R. Rodriguez | a776582 | 2009-10-19 02:33:45 -0400 | [diff] [blame] | 1312 | |
Sujith | 6819d57 | 2010-04-16 11:53:56 +0530 | [diff] [blame] | 1313 | ath9k_hw_set_operating_mode(ah, ah->opmode); |
| 1314 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1315 | ENABLE_REGWRITE_BUFFER(ah); |
| 1316 | |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 1317 | REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr)); |
| 1318 | REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1319 | | macStaId1 |
| 1320 | | AR_STA_ID1_RTS_USE_DEF |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1321 | | (ah->config. |
Sujith | 60b67f5 | 2008-08-07 10:52:38 +0530 | [diff] [blame] | 1322 | ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1323 | | ah->sta_id1_defaults); |
Luis R. Rodriguez | 13b8155 | 2009-09-10 17:52:45 -0700 | [diff] [blame] | 1324 | ath_hw_setbssidmask(common); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1325 | REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna); |
Luis R. Rodriguez | 3453ad8 | 2009-09-10 08:57:00 -0700 | [diff] [blame] | 1326 | ath9k_hw_write_associd(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1327 | REG_WRITE(ah, AR_ISR, ~0); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1328 | REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR); |
| 1329 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1330 | REGWRITE_BUFFER_FLUSH(ah); |
| 1331 | DISABLE_REGWRITE_BUFFER(ah); |
| 1332 | |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1333 | r = ath9k_hw_rf_set_freq(ah, chan); |
Luis R. Rodriguez | 0a3b7ba | 2009-10-19 02:33:40 -0400 | [diff] [blame] | 1334 | if (r) |
| 1335 | return r; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1336 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1337 | ENABLE_REGWRITE_BUFFER(ah); |
| 1338 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1339 | for (i = 0; i < AR_NUM_DCU; i++) |
| 1340 | REG_WRITE(ah, AR_DQCUMASK(i), 1 << i); |
| 1341 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1342 | REGWRITE_BUFFER_FLUSH(ah); |
| 1343 | DISABLE_REGWRITE_BUFFER(ah); |
| 1344 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1345 | ah->intr_txqs = 0; |
| 1346 | for (i = 0; i < ah->caps.total_queues; i++) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1347 | ath9k_hw_resettxqueue(ah, i); |
| 1348 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1349 | ath9k_hw_init_interrupt_masks(ah, ah->opmode); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1350 | ath9k_hw_init_qos(ah); |
| 1351 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1352 | if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT) |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 1353 | ath9k_enable_rfkill(ah); |
Johannes Berg | 3b319aa | 2009-06-13 14:50:26 +0530 | [diff] [blame] | 1354 | |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 1355 | ath9k_hw_init_global_settings(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1356 | |
Luis R. Rodriguez | 6c94fdc | 2010-04-15 17:39:24 -0400 | [diff] [blame] | 1357 | if (!AR_SREV_9300_20_OR_LATER(ah)) { |
Luis R. Rodriguez | 78ec267 | 2010-04-15 17:39:23 -0400 | [diff] [blame] | 1358 | ar9002_hw_enable_async_fifo(ah); |
Luis R. Rodriguez | 6c94fdc | 2010-04-15 17:39:24 -0400 | [diff] [blame] | 1359 | ar9002_hw_enable_wep_aggregation(ah); |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 1360 | } |
| 1361 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1362 | REG_WRITE(ah, AR_STA_ID1, |
| 1363 | REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM); |
| 1364 | |
| 1365 | ath9k_hw_set_dma(ah); |
| 1366 | |
| 1367 | REG_WRITE(ah, AR_OBS, 8); |
| 1368 | |
Sujith | 0ce024c | 2009-12-14 14:57:00 +0530 | [diff] [blame] | 1369 | if (ah->config.rx_intr_mitigation) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1370 | REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500); |
| 1371 | REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000); |
| 1372 | } |
| 1373 | |
Vasanthakumar Thiagarajan | 7f62a13 | 2010-04-15 17:39:19 -0400 | [diff] [blame] | 1374 | if (ah->config.tx_intr_mitigation) { |
| 1375 | REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_LAST, 300); |
| 1376 | REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_FIRST, 750); |
| 1377 | } |
| 1378 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1379 | ath9k_hw_init_bb(ah, chan); |
| 1380 | |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 1381 | if (!ath9k_hw_init_cal(ah, chan)) |
Joe Perches | 6badaaf | 2009-06-28 09:26:32 -0700 | [diff] [blame] | 1382 | return -EIO; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1383 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1384 | ENABLE_REGWRITE_BUFFER(ah); |
| 1385 | |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1386 | ath9k_hw_restore_chainmask(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1387 | REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ); |
| 1388 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1389 | REGWRITE_BUFFER_FLUSH(ah); |
| 1390 | DISABLE_REGWRITE_BUFFER(ah); |
| 1391 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1392 | /* |
| 1393 | * For big endian systems turn on swapping for descriptors |
| 1394 | */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1395 | if (AR_SREV_9100(ah)) { |
| 1396 | u32 mask; |
| 1397 | mask = REG_READ(ah, AR_CFG); |
| 1398 | if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1399 | ath_print(common, ATH_DBG_RESET, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 1400 | "CFG Byte Swap Set 0x%x\n", mask); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1401 | } else { |
| 1402 | mask = |
| 1403 | INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB; |
| 1404 | REG_WRITE(ah, AR_CFG, mask); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1405 | ath_print(common, ATH_DBG_RESET, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 1406 | "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1407 | } |
| 1408 | } else { |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1409 | /* Configure AR9271 target WLAN */ |
| 1410 | if (AR_SREV_9271(ah)) |
| 1411 | REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1412 | #ifdef __BIG_ENDIAN |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1413 | else |
| 1414 | REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1415 | #endif |
| 1416 | } |
| 1417 | |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 1418 | if (ah->btcoex_hw.enabled) |
Vasanthakumar Thiagarajan | 42cc41e | 2009-08-26 21:08:45 +0530 | [diff] [blame] | 1419 | ath9k_hw_btcoex_enable(ah); |
| 1420 | |
Vasanthakumar Thiagarajan | d8903a5 | 2010-04-15 17:39:25 -0400 | [diff] [blame] | 1421 | if (AR_SREV_9300_20_OR_LATER(ah)) { |
| 1422 | ath9k_hw_loadnf(ah, curchan); |
| 1423 | ath9k_hw_start_nfcal(ah); |
| 1424 | } |
| 1425 | |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 1426 | return 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1427 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 1428 | EXPORT_SYMBOL(ath9k_hw_reset); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1429 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1430 | /************************/ |
| 1431 | /* Key Cache Management */ |
| 1432 | /************************/ |
| 1433 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1434 | bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1435 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1436 | u32 keyType; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1437 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1438 | if (entry >= ah->caps.keycache_size) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1439 | ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL, |
| 1440 | "keychache entry %u out of range\n", entry); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1441 | return false; |
| 1442 | } |
| 1443 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1444 | keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1445 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1446 | REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0); |
| 1447 | REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0); |
| 1448 | REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0); |
| 1449 | REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0); |
| 1450 | REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0); |
| 1451 | REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR); |
| 1452 | REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0); |
| 1453 | REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0); |
| 1454 | |
| 1455 | if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) { |
| 1456 | u16 micentry = entry + 64; |
| 1457 | |
| 1458 | REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0); |
| 1459 | REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0); |
| 1460 | REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0); |
| 1461 | REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0); |
| 1462 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1463 | } |
| 1464 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1465 | return true; |
| 1466 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 1467 | EXPORT_SYMBOL(ath9k_hw_keyreset); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1468 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1469 | bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1470 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1471 | u32 macHi, macLo; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1472 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1473 | if (entry >= ah->caps.keycache_size) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1474 | ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL, |
| 1475 | "keychache entry %u out of range\n", entry); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1476 | return false; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1477 | } |
| 1478 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1479 | if (mac != NULL) { |
| 1480 | macHi = (mac[5] << 8) | mac[4]; |
| 1481 | macLo = (mac[3] << 24) | |
| 1482 | (mac[2] << 16) | |
| 1483 | (mac[1] << 8) | |
| 1484 | mac[0]; |
| 1485 | macLo >>= 1; |
| 1486 | macLo |= (macHi & 1) << 31; |
| 1487 | macHi >>= 1; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1488 | } else { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1489 | macLo = macHi = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1490 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1491 | REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo); |
| 1492 | REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1493 | |
| 1494 | return true; |
| 1495 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 1496 | EXPORT_SYMBOL(ath9k_hw_keysetmac); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1497 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1498 | bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1499 | const struct ath9k_keyval *k, |
Jouni Malinen | e0caf9e | 2009-03-02 18:15:53 +0200 | [diff] [blame] | 1500 | const u8 *mac) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1501 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1502 | const struct ath9k_hw_capabilities *pCap = &ah->caps; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1503 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1504 | u32 key0, key1, key2, key3, key4; |
| 1505 | u32 keyType; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1506 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1507 | if (entry >= pCap->keycache_size) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1508 | ath_print(common, ATH_DBG_FATAL, |
| 1509 | "keycache entry %u out of range\n", entry); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1510 | return false; |
| 1511 | } |
| 1512 | |
| 1513 | switch (k->kv_type) { |
| 1514 | case ATH9K_CIPHER_AES_OCB: |
| 1515 | keyType = AR_KEYTABLE_TYPE_AES; |
| 1516 | break; |
| 1517 | case ATH9K_CIPHER_AES_CCM: |
| 1518 | if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1519 | ath_print(common, ATH_DBG_ANY, |
| 1520 | "AES-CCM not supported by mac rev 0x%x\n", |
| 1521 | ah->hw_version.macRev); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1522 | return false; |
| 1523 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1524 | keyType = AR_KEYTABLE_TYPE_CCM; |
| 1525 | break; |
| 1526 | case ATH9K_CIPHER_TKIP: |
| 1527 | keyType = AR_KEYTABLE_TYPE_TKIP; |
| 1528 | if (ATH9K_IS_MIC_ENABLED(ah) |
| 1529 | && entry + 64 >= pCap->keycache_size) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1530 | ath_print(common, ATH_DBG_ANY, |
| 1531 | "entry %u inappropriate for TKIP\n", entry); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1532 | return false; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1533 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1534 | break; |
| 1535 | case ATH9K_CIPHER_WEP: |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 1536 | if (k->kv_len < WLAN_KEY_LEN_WEP40) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1537 | ath_print(common, ATH_DBG_ANY, |
| 1538 | "WEP key length %u too small\n", k->kv_len); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1539 | return false; |
| 1540 | } |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 1541 | if (k->kv_len <= WLAN_KEY_LEN_WEP40) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1542 | keyType = AR_KEYTABLE_TYPE_40; |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 1543 | else if (k->kv_len <= WLAN_KEY_LEN_WEP104) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1544 | keyType = AR_KEYTABLE_TYPE_104; |
| 1545 | else |
| 1546 | keyType = AR_KEYTABLE_TYPE_128; |
| 1547 | break; |
| 1548 | case ATH9K_CIPHER_CLR: |
| 1549 | keyType = AR_KEYTABLE_TYPE_CLR; |
| 1550 | break; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1551 | default: |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1552 | ath_print(common, ATH_DBG_FATAL, |
| 1553 | "cipher %u not supported\n", k->kv_type); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1554 | return false; |
| 1555 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1556 | |
Jouni Malinen | e0caf9e | 2009-03-02 18:15:53 +0200 | [diff] [blame] | 1557 | key0 = get_unaligned_le32(k->kv_val + 0); |
| 1558 | key1 = get_unaligned_le16(k->kv_val + 4); |
| 1559 | key2 = get_unaligned_le32(k->kv_val + 6); |
| 1560 | key3 = get_unaligned_le16(k->kv_val + 10); |
| 1561 | key4 = get_unaligned_le32(k->kv_val + 12); |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 1562 | if (k->kv_len <= WLAN_KEY_LEN_WEP104) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1563 | key4 &= 0xff; |
| 1564 | |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1565 | /* |
| 1566 | * Note: Key cache registers access special memory area that requires |
| 1567 | * two 32-bit writes to actually update the values in the internal |
| 1568 | * memory. Consequently, the exact order and pairs used here must be |
| 1569 | * maintained. |
| 1570 | */ |
| 1571 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1572 | if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) { |
| 1573 | u16 micentry = entry + 64; |
| 1574 | |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1575 | /* |
| 1576 | * Write inverted key[47:0] first to avoid Michael MIC errors |
| 1577 | * on frames that could be sent or received at the same time. |
| 1578 | * The correct key will be written in the end once everything |
| 1579 | * else is ready. |
| 1580 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1581 | REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0); |
| 1582 | REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1583 | |
| 1584 | /* Write key[95:48] */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1585 | REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2); |
| 1586 | REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1587 | |
| 1588 | /* Write key[127:96] and key type */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1589 | REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4); |
| 1590 | REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1591 | |
| 1592 | /* Write MAC address for the entry */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1593 | (void) ath9k_hw_keysetmac(ah, entry, mac); |
| 1594 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1595 | if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) { |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1596 | /* |
| 1597 | * TKIP uses two key cache entries: |
| 1598 | * Michael MIC TX/RX keys in the same key cache entry |
| 1599 | * (idx = main index + 64): |
| 1600 | * key0 [31:0] = RX key [31:0] |
| 1601 | * key1 [15:0] = TX key [31:16] |
| 1602 | * key1 [31:16] = reserved |
| 1603 | * key2 [31:0] = RX key [63:32] |
| 1604 | * key3 [15:0] = TX key [15:0] |
| 1605 | * key3 [31:16] = reserved |
| 1606 | * key4 [31:0] = TX key [63:32] |
| 1607 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1608 | u32 mic0, mic1, mic2, mic3, mic4; |
| 1609 | |
| 1610 | mic0 = get_unaligned_le32(k->kv_mic + 0); |
| 1611 | mic2 = get_unaligned_le32(k->kv_mic + 4); |
| 1612 | mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff; |
| 1613 | mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff; |
| 1614 | mic4 = get_unaligned_le32(k->kv_txmic + 4); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1615 | |
| 1616 | /* Write RX[31:0] and TX[31:16] */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1617 | REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0); |
| 1618 | REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1619 | |
| 1620 | /* Write RX[63:32] and TX[15:0] */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1621 | REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2); |
| 1622 | REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1623 | |
| 1624 | /* Write TX[63:32] and keyType(reserved) */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1625 | REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4); |
| 1626 | REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry), |
| 1627 | AR_KEYTABLE_TYPE_CLR); |
| 1628 | |
| 1629 | } else { |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1630 | /* |
| 1631 | * TKIP uses four key cache entries (two for group |
| 1632 | * keys): |
| 1633 | * Michael MIC TX/RX keys are in different key cache |
| 1634 | * entries (idx = main index + 64 for TX and |
| 1635 | * main index + 32 + 96 for RX): |
| 1636 | * key0 [31:0] = TX/RX MIC key [31:0] |
| 1637 | * key1 [31:0] = reserved |
| 1638 | * key2 [31:0] = TX/RX MIC key [63:32] |
| 1639 | * key3 [31:0] = reserved |
| 1640 | * key4 [31:0] = reserved |
| 1641 | * |
| 1642 | * Upper layer code will call this function separately |
| 1643 | * for TX and RX keys when these registers offsets are |
| 1644 | * used. |
| 1645 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1646 | u32 mic0, mic2; |
| 1647 | |
| 1648 | mic0 = get_unaligned_le32(k->kv_mic + 0); |
| 1649 | mic2 = get_unaligned_le32(k->kv_mic + 4); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1650 | |
| 1651 | /* Write MIC key[31:0] */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1652 | REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0); |
| 1653 | REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1654 | |
| 1655 | /* Write MIC key[63:32] */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1656 | REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2); |
| 1657 | REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1658 | |
| 1659 | /* Write TX[63:32] and keyType(reserved) */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1660 | REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0); |
| 1661 | REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry), |
| 1662 | AR_KEYTABLE_TYPE_CLR); |
| 1663 | } |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1664 | |
| 1665 | /* MAC address registers are reserved for the MIC entry */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1666 | REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0); |
| 1667 | REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1668 | |
| 1669 | /* |
| 1670 | * Write the correct (un-inverted) key[47:0] last to enable |
| 1671 | * TKIP now that all other registers are set with correct |
| 1672 | * values. |
| 1673 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1674 | REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0); |
| 1675 | REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1); |
| 1676 | } else { |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1677 | /* Write key[47:0] */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1678 | REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0); |
| 1679 | REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1680 | |
| 1681 | /* Write key[95:48] */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1682 | REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2); |
| 1683 | REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1684 | |
| 1685 | /* Write key[127:96] and key type */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1686 | REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4); |
| 1687 | REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType); |
| 1688 | |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1689 | /* Write MAC address for the entry */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1690 | (void) ath9k_hw_keysetmac(ah, entry, mac); |
| 1691 | } |
| 1692 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1693 | return true; |
| 1694 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 1695 | EXPORT_SYMBOL(ath9k_hw_set_keycache_entry); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1696 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1697 | bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1698 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1699 | if (entry < ah->caps.keycache_size) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1700 | u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry)); |
| 1701 | if (val & AR_KEYTABLE_VALID) |
| 1702 | return true; |
| 1703 | } |
| 1704 | return false; |
| 1705 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 1706 | EXPORT_SYMBOL(ath9k_hw_keyisvalid); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1707 | |
| 1708 | /******************************/ |
| 1709 | /* Power Management (Chipset) */ |
| 1710 | /******************************/ |
| 1711 | |
Luis R. Rodriguez | 42d5bc3 | 2010-04-15 17:38:12 -0400 | [diff] [blame] | 1712 | /* |
| 1713 | * Notify Power Mgt is disabled in self-generated frames. |
| 1714 | * If requested, force chip to sleep. |
| 1715 | */ |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1716 | static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1717 | { |
| 1718 | REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV); |
| 1719 | if (setChip) { |
Luis R. Rodriguez | 42d5bc3 | 2010-04-15 17:38:12 -0400 | [diff] [blame] | 1720 | /* |
| 1721 | * Clear the RTC force wake bit to allow the |
| 1722 | * mac to go to sleep. |
| 1723 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1724 | REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, |
| 1725 | AR_RTC_FORCE_WAKE_EN); |
Luis R. Rodriguez | 42d5bc3 | 2010-04-15 17:38:12 -0400 | [diff] [blame] | 1726 | if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1727 | REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF); |
| 1728 | |
Luis R. Rodriguez | 42d5bc3 | 2010-04-15 17:38:12 -0400 | [diff] [blame] | 1729 | /* Shutdown chip. Active low */ |
Sujith | 14b3af3 | 2010-03-17 14:25:18 +0530 | [diff] [blame] | 1730 | if (!AR_SREV_5416(ah) && !AR_SREV_9271(ah)) |
Sujith | 4921be8 | 2009-09-18 15:04:27 +0530 | [diff] [blame] | 1731 | REG_CLR_BIT(ah, (AR_RTC_RESET), |
| 1732 | AR_RTC_RESET_EN); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1733 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1734 | } |
| 1735 | |
Luis R. Rodriguez | bbd79af | 2010-04-15 17:38:16 -0400 | [diff] [blame] | 1736 | /* |
| 1737 | * Notify Power Management is enabled in self-generating |
| 1738 | * frames. If request, set power mode of chip to |
| 1739 | * auto/normal. Duration in units of 128us (1/8 TU). |
| 1740 | */ |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1741 | static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1742 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1743 | REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV); |
| 1744 | if (setChip) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1745 | struct ath9k_hw_capabilities *pCap = &ah->caps; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1746 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1747 | if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) { |
Luis R. Rodriguez | bbd79af | 2010-04-15 17:38:16 -0400 | [diff] [blame] | 1748 | /* Set WakeOnInterrupt bit; clear ForceWake bit */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1749 | REG_WRITE(ah, AR_RTC_FORCE_WAKE, |
| 1750 | AR_RTC_FORCE_WAKE_ON_INT); |
| 1751 | } else { |
Luis R. Rodriguez | bbd79af | 2010-04-15 17:38:16 -0400 | [diff] [blame] | 1752 | /* |
| 1753 | * Clear the RTC force wake bit to allow the |
| 1754 | * mac to go to sleep. |
| 1755 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1756 | REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, |
| 1757 | AR_RTC_FORCE_WAKE_EN); |
| 1758 | } |
| 1759 | } |
| 1760 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1761 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1762 | static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1763 | { |
| 1764 | u32 val; |
| 1765 | int i; |
| 1766 | |
| 1767 | if (setChip) { |
| 1768 | if ((REG_READ(ah, AR_RTC_STATUS) & |
| 1769 | AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) { |
| 1770 | if (ath9k_hw_set_reset_reg(ah, |
| 1771 | ATH9K_RESET_POWER_ON) != true) { |
| 1772 | return false; |
| 1773 | } |
Luis R. Rodriguez | e041228 | 2010-04-15 17:38:15 -0400 | [diff] [blame] | 1774 | if (!AR_SREV_9300_20_OR_LATER(ah)) |
| 1775 | ath9k_hw_init_pll(ah, NULL); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1776 | } |
| 1777 | if (AR_SREV_9100(ah)) |
| 1778 | REG_SET_BIT(ah, AR_RTC_RESET, |
| 1779 | AR_RTC_RESET_EN); |
| 1780 | |
| 1781 | REG_SET_BIT(ah, AR_RTC_FORCE_WAKE, |
| 1782 | AR_RTC_FORCE_WAKE_EN); |
| 1783 | udelay(50); |
| 1784 | |
| 1785 | for (i = POWER_UP_TIME / 50; i > 0; i--) { |
| 1786 | val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M; |
| 1787 | if (val == AR_RTC_STATUS_ON) |
| 1788 | break; |
| 1789 | udelay(50); |
| 1790 | REG_SET_BIT(ah, AR_RTC_FORCE_WAKE, |
| 1791 | AR_RTC_FORCE_WAKE_EN); |
| 1792 | } |
| 1793 | if (i == 0) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1794 | ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL, |
| 1795 | "Failed to wakeup in %uus\n", |
| 1796 | POWER_UP_TIME / 20); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1797 | return false; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1798 | } |
| 1799 | } |
| 1800 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1801 | REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV); |
| 1802 | |
| 1803 | return true; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1804 | } |
| 1805 | |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 1806 | bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1807 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1808 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1809 | int status = true, setChip = true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1810 | static const char *modes[] = { |
| 1811 | "AWAKE", |
| 1812 | "FULL-SLEEP", |
| 1813 | "NETWORK SLEEP", |
| 1814 | "UNDEFINED" |
| 1815 | }; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1816 | |
Gabor Juhos | cbdec97 | 2009-07-24 17:27:22 +0200 | [diff] [blame] | 1817 | if (ah->power_mode == mode) |
| 1818 | return status; |
| 1819 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1820 | ath_print(common, ATH_DBG_RESET, "%s -> %s\n", |
| 1821 | modes[ah->power_mode], modes[mode]); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1822 | |
| 1823 | switch (mode) { |
| 1824 | case ATH9K_PM_AWAKE: |
| 1825 | status = ath9k_hw_set_power_awake(ah, setChip); |
| 1826 | break; |
| 1827 | case ATH9K_PM_FULL_SLEEP: |
| 1828 | ath9k_set_power_sleep(ah, setChip); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1829 | ah->chip_fullsleep = true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1830 | break; |
| 1831 | case ATH9K_PM_NETWORK_SLEEP: |
| 1832 | ath9k_set_power_network_sleep(ah, setChip); |
| 1833 | break; |
| 1834 | default: |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1835 | ath_print(common, ATH_DBG_FATAL, |
| 1836 | "Unknown power mode %u\n", mode); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1837 | return false; |
| 1838 | } |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1839 | ah->power_mode = mode; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1840 | |
| 1841 | return status; |
| 1842 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 1843 | EXPORT_SYMBOL(ath9k_hw_setpower); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1844 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1845 | /*******************/ |
| 1846 | /* Beacon Handling */ |
| 1847 | /*******************/ |
| 1848 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1849 | void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1850 | { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1851 | int flags = 0; |
| 1852 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1853 | ah->beacon_interval = beacon_period; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1854 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1855 | ENABLE_REGWRITE_BUFFER(ah); |
| 1856 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1857 | switch (ah->opmode) { |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 1858 | case NL80211_IFTYPE_STATION: |
| 1859 | case NL80211_IFTYPE_MONITOR: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1860 | REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon)); |
| 1861 | REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff); |
| 1862 | REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff); |
| 1863 | flags |= AR_TBTT_TIMER_EN; |
| 1864 | break; |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 1865 | case NL80211_IFTYPE_ADHOC: |
Pat Erley | 9cb5412 | 2009-03-20 22:59:59 -0400 | [diff] [blame] | 1866 | case NL80211_IFTYPE_MESH_POINT: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1867 | REG_SET_BIT(ah, AR_TXCFG, |
| 1868 | AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY); |
| 1869 | REG_WRITE(ah, AR_NEXT_NDP_TIMER, |
| 1870 | TU_TO_USEC(next_beacon + |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1871 | (ah->atim_window ? ah-> |
| 1872 | atim_window : 1))); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1873 | flags |= AR_NDP_TIMER_EN; |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 1874 | case NL80211_IFTYPE_AP: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1875 | REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon)); |
| 1876 | REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, |
| 1877 | TU_TO_USEC(next_beacon - |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1878 | ah->config. |
Sujith | 60b67f5 | 2008-08-07 10:52:38 +0530 | [diff] [blame] | 1879 | dma_beacon_response_time)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1880 | REG_WRITE(ah, AR_NEXT_SWBA, |
| 1881 | TU_TO_USEC(next_beacon - |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1882 | ah->config. |
Sujith | 60b67f5 | 2008-08-07 10:52:38 +0530 | [diff] [blame] | 1883 | sw_beacon_response_time)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1884 | flags |= |
| 1885 | AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN; |
| 1886 | break; |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 1887 | default: |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1888 | ath_print(ath9k_hw_common(ah), ATH_DBG_BEACON, |
| 1889 | "%s: unsupported opmode: %d\n", |
| 1890 | __func__, ah->opmode); |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 1891 | return; |
| 1892 | break; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1893 | } |
| 1894 | |
| 1895 | REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period)); |
| 1896 | REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period)); |
| 1897 | REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period)); |
| 1898 | REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period)); |
| 1899 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1900 | REGWRITE_BUFFER_FLUSH(ah); |
| 1901 | DISABLE_REGWRITE_BUFFER(ah); |
| 1902 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1903 | beacon_period &= ~ATH9K_BEACON_ENA; |
| 1904 | if (beacon_period & ATH9K_BEACON_RESET_TSF) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1905 | ath9k_hw_reset_tsf(ah); |
| 1906 | } |
| 1907 | |
| 1908 | REG_SET_BIT(ah, AR_TIMER_MODE, flags); |
| 1909 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 1910 | EXPORT_SYMBOL(ath9k_hw_beaconinit); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1911 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1912 | void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1913 | const struct ath9k_beacon_state *bs) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1914 | { |
| 1915 | u32 nextTbtt, beaconintval, dtimperiod, beacontimeout; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1916 | struct ath9k_hw_capabilities *pCap = &ah->caps; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1917 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1918 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1919 | ENABLE_REGWRITE_BUFFER(ah); |
| 1920 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1921 | REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt)); |
| 1922 | |
| 1923 | REG_WRITE(ah, AR_BEACON_PERIOD, |
| 1924 | TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD)); |
| 1925 | REG_WRITE(ah, AR_DMA_BEACON_PERIOD, |
| 1926 | TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD)); |
| 1927 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1928 | REGWRITE_BUFFER_FLUSH(ah); |
| 1929 | DISABLE_REGWRITE_BUFFER(ah); |
| 1930 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1931 | REG_RMW_FIELD(ah, AR_RSSI_THR, |
| 1932 | AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold); |
| 1933 | |
| 1934 | beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD; |
| 1935 | |
| 1936 | if (bs->bs_sleepduration > beaconintval) |
| 1937 | beaconintval = bs->bs_sleepduration; |
| 1938 | |
| 1939 | dtimperiod = bs->bs_dtimperiod; |
| 1940 | if (bs->bs_sleepduration > dtimperiod) |
| 1941 | dtimperiod = bs->bs_sleepduration; |
| 1942 | |
| 1943 | if (beaconintval == dtimperiod) |
| 1944 | nextTbtt = bs->bs_nextdtim; |
| 1945 | else |
| 1946 | nextTbtt = bs->bs_nexttbtt; |
| 1947 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1948 | ath_print(common, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim); |
| 1949 | ath_print(common, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt); |
| 1950 | ath_print(common, ATH_DBG_BEACON, "beacon period %d\n", beaconintval); |
| 1951 | ath_print(common, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1952 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1953 | ENABLE_REGWRITE_BUFFER(ah); |
| 1954 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1955 | REG_WRITE(ah, AR_NEXT_DTIM, |
| 1956 | TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP)); |
| 1957 | REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP)); |
| 1958 | |
| 1959 | REG_WRITE(ah, AR_SLEEP1, |
| 1960 | SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT) |
| 1961 | | AR_SLEEP1_ASSUME_DTIM); |
| 1962 | |
Sujith | 60b67f5 | 2008-08-07 10:52:38 +0530 | [diff] [blame] | 1963 | if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1964 | beacontimeout = (BEACON_TIMEOUT_VAL << 3); |
| 1965 | else |
| 1966 | beacontimeout = MIN_BEACON_TIMEOUT_VAL; |
| 1967 | |
| 1968 | REG_WRITE(ah, AR_SLEEP2, |
| 1969 | SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT)); |
| 1970 | |
| 1971 | REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval)); |
| 1972 | REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod)); |
| 1973 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1974 | REGWRITE_BUFFER_FLUSH(ah); |
| 1975 | DISABLE_REGWRITE_BUFFER(ah); |
| 1976 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1977 | REG_SET_BIT(ah, AR_TIMER_MODE, |
| 1978 | AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN | |
| 1979 | AR_DTIM_TIMER_EN); |
| 1980 | |
Sujith | 4af9cf4 | 2009-02-12 10:06:47 +0530 | [diff] [blame] | 1981 | /* TSF Out of Range Threshold */ |
| 1982 | REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1983 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 1984 | EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1985 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1986 | /*******************/ |
| 1987 | /* HW Capabilities */ |
| 1988 | /*******************/ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1989 | |
Gabor Juhos | a9a29ce | 2009-11-27 12:01:35 +0100 | [diff] [blame] | 1990 | int ath9k_hw_fill_cap_info(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1991 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1992 | struct ath9k_hw_capabilities *pCap = &ah->caps; |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 1993 | struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1994 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 1995 | struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw; |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 1996 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1997 | u16 capField = 0, eeval; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1998 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1999 | eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0); |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 2000 | regulatory->current_rd = eeval; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2001 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2002 | eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1); |
Sujith | fec0de1 | 2009-02-12 10:06:43 +0530 | [diff] [blame] | 2003 | if (AR_SREV_9285_10_OR_LATER(ah)) |
| 2004 | eeval |= AR9285_RDEXT_DEFAULT; |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 2005 | regulatory->current_rd_ext = eeval; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2006 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2007 | capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2008 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2009 | if (ah->opmode != NL80211_IFTYPE_AP && |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 2010 | ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) { |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 2011 | if (regulatory->current_rd == 0x64 || |
| 2012 | regulatory->current_rd == 0x65) |
| 2013 | regulatory->current_rd += 5; |
| 2014 | else if (regulatory->current_rd == 0x41) |
| 2015 | regulatory->current_rd = 0x43; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2016 | ath_print(common, ATH_DBG_REGULATORY, |
| 2017 | "regdomain mapped to 0x%x\n", regulatory->current_rd); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2018 | } |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 2019 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2020 | eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE); |
Gabor Juhos | a9a29ce | 2009-11-27 12:01:35 +0100 | [diff] [blame] | 2021 | if ((eeval & (AR5416_OPFLAGS_11G | AR5416_OPFLAGS_11A)) == 0) { |
| 2022 | ath_print(common, ATH_DBG_FATAL, |
| 2023 | "no band has been marked as supported in EEPROM.\n"); |
| 2024 | return -EINVAL; |
| 2025 | } |
| 2026 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2027 | bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2028 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2029 | if (eeval & AR5416_OPFLAGS_11A) { |
| 2030 | set_bit(ATH9K_MODE_11A, pCap->wireless_modes); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2031 | if (ah->config.ht_enable) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2032 | if (!(eeval & AR5416_OPFLAGS_N_5G_HT20)) |
| 2033 | set_bit(ATH9K_MODE_11NA_HT20, |
| 2034 | pCap->wireless_modes); |
| 2035 | if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) { |
| 2036 | set_bit(ATH9K_MODE_11NA_HT40PLUS, |
| 2037 | pCap->wireless_modes); |
| 2038 | set_bit(ATH9K_MODE_11NA_HT40MINUS, |
| 2039 | pCap->wireless_modes); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2040 | } |
| 2041 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2042 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2043 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2044 | if (eeval & AR5416_OPFLAGS_11G) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2045 | set_bit(ATH9K_MODE_11G, pCap->wireless_modes); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2046 | if (ah->config.ht_enable) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2047 | if (!(eeval & AR5416_OPFLAGS_N_2G_HT20)) |
| 2048 | set_bit(ATH9K_MODE_11NG_HT20, |
| 2049 | pCap->wireless_modes); |
| 2050 | if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) { |
| 2051 | set_bit(ATH9K_MODE_11NG_HT40PLUS, |
| 2052 | pCap->wireless_modes); |
| 2053 | set_bit(ATH9K_MODE_11NG_HT40MINUS, |
| 2054 | pCap->wireless_modes); |
| 2055 | } |
| 2056 | } |
Luis R. Rodriguez | 6f25542 | 2008-10-03 15:45:27 -0700 | [diff] [blame] | 2057 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2058 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2059 | pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK); |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 2060 | /* |
| 2061 | * For AR9271 we will temporarilly uses the rx chainmax as read from |
| 2062 | * the EEPROM. |
| 2063 | */ |
Sujith | 8147f5d | 2009-02-20 15:13:23 +0530 | [diff] [blame] | 2064 | if ((ah->hw_version.devid == AR5416_DEVID_PCI) && |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 2065 | !(eeval & AR5416_OPFLAGS_11A) && |
| 2066 | !(AR_SREV_9271(ah))) |
| 2067 | /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */ |
Sujith | 8147f5d | 2009-02-20 15:13:23 +0530 | [diff] [blame] | 2068 | pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7; |
| 2069 | else |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 2070 | /* Use rx_chainmask from EEPROM. */ |
Sujith | 8147f5d | 2009-02-20 15:13:23 +0530 | [diff] [blame] | 2071 | pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2072 | |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 2073 | if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0))) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2074 | ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2075 | |
| 2076 | pCap->low_2ghz_chan = 2312; |
| 2077 | pCap->high_2ghz_chan = 2732; |
| 2078 | |
| 2079 | pCap->low_5ghz_chan = 4920; |
| 2080 | pCap->high_5ghz_chan = 6100; |
| 2081 | |
| 2082 | pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP; |
| 2083 | pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP; |
| 2084 | pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM; |
| 2085 | |
| 2086 | pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP; |
| 2087 | pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP; |
| 2088 | pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM; |
| 2089 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2090 | if (ah->config.ht_enable) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2091 | pCap->hw_caps |= ATH9K_HW_CAP_HT; |
| 2092 | else |
| 2093 | pCap->hw_caps &= ~ATH9K_HW_CAP_HT; |
| 2094 | |
| 2095 | pCap->hw_caps |= ATH9K_HW_CAP_GTT; |
| 2096 | pCap->hw_caps |= ATH9K_HW_CAP_VEOL; |
| 2097 | pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK; |
| 2098 | pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH; |
| 2099 | |
| 2100 | if (capField & AR_EEPROM_EEPCAP_MAXQCU) |
| 2101 | pCap->total_queues = |
| 2102 | MS(capField, AR_EEPROM_EEPCAP_MAXQCU); |
| 2103 | else |
| 2104 | pCap->total_queues = ATH9K_NUM_TX_QUEUES; |
| 2105 | |
| 2106 | if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES) |
| 2107 | pCap->keycache_size = |
| 2108 | 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES); |
| 2109 | else |
| 2110 | pCap->keycache_size = AR_KEYTABLE_SIZE; |
| 2111 | |
| 2112 | pCap->hw_caps |= ATH9K_HW_CAP_FASTCC; |
Luis R. Rodriguez | f4709fd | 2009-11-24 21:37:57 -0500 | [diff] [blame] | 2113 | |
| 2114 | if (AR_SREV_9285(ah) || AR_SREV_9271(ah)) |
| 2115 | pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD >> 1; |
| 2116 | else |
| 2117 | pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2118 | |
Sujith | 5b5fa35 | 2010-03-17 14:25:15 +0530 | [diff] [blame] | 2119 | if (AR_SREV_9271(ah)) |
| 2120 | pCap->num_gpio_pins = AR9271_NUM_GPIO; |
| 2121 | else if (AR_SREV_9285_10_OR_LATER(ah)) |
Senthil Balasubramanian | cb33c41 | 2008-12-24 18:03:58 +0530 | [diff] [blame] | 2122 | pCap->num_gpio_pins = AR9285_NUM_GPIO; |
| 2123 | else if (AR_SREV_9280_10_OR_LATER(ah)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2124 | pCap->num_gpio_pins = AR928X_NUM_GPIO; |
| 2125 | else |
| 2126 | pCap->num_gpio_pins = AR_NUM_GPIO; |
| 2127 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2128 | if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) { |
| 2129 | pCap->hw_caps |= ATH9K_HW_CAP_CST; |
| 2130 | pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX; |
| 2131 | } else { |
| 2132 | pCap->rts_aggr_limit = (8 * 1024); |
| 2133 | } |
| 2134 | |
| 2135 | pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM; |
| 2136 | |
Senthil Balasubramanian | e97275c | 2008-11-13 18:00:02 +0530 | [diff] [blame] | 2137 | #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2138 | ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT); |
| 2139 | if (ah->rfsilent & EEP_RFSILENT_ENABLED) { |
| 2140 | ah->rfkill_gpio = |
| 2141 | MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL); |
| 2142 | ah->rfkill_polarity = |
| 2143 | MS(ah->rfsilent, EEP_RFSILENT_POLARITY); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2144 | |
| 2145 | pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT; |
| 2146 | } |
| 2147 | #endif |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 2148 | if (AR_SREV_9271(ah)) |
| 2149 | pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP; |
| 2150 | else |
| 2151 | pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2152 | |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 2153 | if (AR_SREV_9280(ah) || AR_SREV_9285(ah)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2154 | pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS; |
| 2155 | else |
| 2156 | pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS; |
| 2157 | |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 2158 | if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2159 | pCap->reg_cap = |
| 2160 | AR_EEPROM_EEREGCAP_EN_KK_NEW_11A | |
| 2161 | AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN | |
| 2162 | AR_EEPROM_EEREGCAP_EN_KK_U2 | |
| 2163 | AR_EEPROM_EEREGCAP_EN_KK_MIDBAND; |
| 2164 | } else { |
| 2165 | pCap->reg_cap = |
| 2166 | AR_EEPROM_EEREGCAP_EN_KK_NEW_11A | |
| 2167 | AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN; |
| 2168 | } |
| 2169 | |
Senthil Balasubramanian | ebb90cf | 2009-09-18 15:07:33 +0530 | [diff] [blame] | 2170 | /* Advertise midband for AR5416 with FCC midband set in eeprom */ |
| 2171 | if (regulatory->current_rd_ext & (1 << REG_EXT_FCC_MIDBAND) && |
| 2172 | AR_SREV_5416(ah)) |
| 2173 | pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2174 | |
| 2175 | pCap->num_antcfg_5ghz = |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2176 | ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2177 | pCap->num_antcfg_2ghz = |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2178 | ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2179 | |
Vasanthakumar Thiagarajan | fe12946 | 2009-09-09 15:25:50 +0530 | [diff] [blame] | 2180 | if (AR_SREV_9280_10_OR_LATER(ah) && |
Luis R. Rodriguez | a36cfbc | 2009-09-09 16:05:32 -0700 | [diff] [blame] | 2181 | ath9k_hw_btcoex_supported(ah)) { |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 2182 | btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO; |
| 2183 | btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO; |
Vasanthakumar Thiagarajan | 22f25d0 | 2009-08-26 21:08:47 +0530 | [diff] [blame] | 2184 | |
Vasanthakumar Thiagarajan | 8c8f9ba | 2009-09-09 15:25:52 +0530 | [diff] [blame] | 2185 | if (AR_SREV_9285(ah)) { |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 2186 | btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE; |
| 2187 | btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO; |
Vasanthakumar Thiagarajan | 8c8f9ba | 2009-09-09 15:25:52 +0530 | [diff] [blame] | 2188 | } else { |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 2189 | btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE; |
Vasanthakumar Thiagarajan | 8c8f9ba | 2009-09-09 15:25:52 +0530 | [diff] [blame] | 2190 | } |
Vasanthakumar Thiagarajan | 22f25d0 | 2009-08-26 21:08:47 +0530 | [diff] [blame] | 2191 | } else { |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 2192 | btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE; |
Vasanthakumar Thiagarajan | c97c92d | 2009-01-02 15:35:46 +0530 | [diff] [blame] | 2193 | } |
Gabor Juhos | a9a29ce | 2009-11-27 12:01:35 +0100 | [diff] [blame] | 2194 | |
Vasanthakumar Thiagarajan | ceb2644 | 2010-04-15 17:38:25 -0400 | [diff] [blame] | 2195 | if (AR_SREV_9300_20_OR_LATER(ah)) { |
Vasanthakumar Thiagarajan | e555372 | 2010-04-26 15:04:33 -0400 | [diff] [blame^] | 2196 | pCap->hw_caps |= ATH9K_HW_CAP_EDMA | ATH9K_HW_CAP_LDPC | |
| 2197 | ATH9K_HW_CAP_FASTCLOCK; |
Vasanthakumar Thiagarajan | ceb2644 | 2010-04-15 17:38:25 -0400 | [diff] [blame] | 2198 | pCap->rx_hp_qdepth = ATH9K_HW_RX_HP_QDEPTH; |
| 2199 | pCap->rx_lp_qdepth = ATH9K_HW_RX_LP_QDEPTH; |
| 2200 | pCap->rx_status_len = sizeof(struct ar9003_rxs); |
Vasanthakumar Thiagarajan | 162c3be | 2010-04-15 17:38:41 -0400 | [diff] [blame] | 2201 | pCap->tx_desc_len = sizeof(struct ar9003_txc); |
Vasanthakumar Thiagarajan | 5088c2f | 2010-04-15 17:39:34 -0400 | [diff] [blame] | 2202 | pCap->txs_len = sizeof(struct ar9003_txs); |
Vasanthakumar Thiagarajan | 162c3be | 2010-04-15 17:38:41 -0400 | [diff] [blame] | 2203 | } else { |
| 2204 | pCap->tx_desc_len = sizeof(struct ath_desc); |
Vasanthakumar Thiagarajan | ceb2644 | 2010-04-15 17:38:25 -0400 | [diff] [blame] | 2205 | } |
Vasanthakumar Thiagarajan | 1adf02f | 2010-04-15 17:38:24 -0400 | [diff] [blame] | 2206 | |
Vasanthakumar Thiagarajan | 6c84ce0 | 2010-04-15 17:39:16 -0400 | [diff] [blame] | 2207 | if (AR_SREV_9300_20_OR_LATER(ah)) |
| 2208 | pCap->hw_caps |= ATH9K_HW_CAP_RAC_SUPPORTED; |
| 2209 | |
Gabor Juhos | a9a29ce | 2009-11-27 12:01:35 +0100 | [diff] [blame] | 2210 | return 0; |
Luis R. Rodriguez | 6f25542 | 2008-10-03 15:45:27 -0700 | [diff] [blame] | 2211 | } |
| 2212 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2213 | bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2214 | u32 capability, u32 *result) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2215 | { |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 2216 | struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2217 | switch (type) { |
| 2218 | case ATH9K_CAP_CIPHER: |
| 2219 | switch (capability) { |
| 2220 | case ATH9K_CIPHER_AES_CCM: |
| 2221 | case ATH9K_CIPHER_AES_OCB: |
| 2222 | case ATH9K_CIPHER_TKIP: |
| 2223 | case ATH9K_CIPHER_WEP: |
| 2224 | case ATH9K_CIPHER_MIC: |
| 2225 | case ATH9K_CIPHER_CLR: |
| 2226 | return true; |
| 2227 | default: |
| 2228 | return false; |
| 2229 | } |
| 2230 | case ATH9K_CAP_TKIP_MIC: |
| 2231 | switch (capability) { |
| 2232 | case 0: |
| 2233 | return true; |
| 2234 | case 1: |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2235 | return (ah->sta_id1_defaults & |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2236 | AR_STA_ID1_CRPT_MIC_ENABLE) ? true : |
| 2237 | false; |
| 2238 | } |
| 2239 | case ATH9K_CAP_TKIP_SPLIT: |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2240 | return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ? |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2241 | false : true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2242 | case ATH9K_CAP_MCAST_KEYSRCH: |
| 2243 | switch (capability) { |
| 2244 | case 0: |
| 2245 | return true; |
| 2246 | case 1: |
| 2247 | if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) { |
| 2248 | return false; |
| 2249 | } else { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2250 | return (ah->sta_id1_defaults & |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2251 | AR_STA_ID1_MCAST_KSRCH) ? true : |
| 2252 | false; |
| 2253 | } |
| 2254 | } |
| 2255 | return false; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2256 | case ATH9K_CAP_TXPOW: |
| 2257 | switch (capability) { |
| 2258 | case 0: |
| 2259 | return 0; |
| 2260 | case 1: |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 2261 | *result = regulatory->power_limit; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2262 | return 0; |
| 2263 | case 2: |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 2264 | *result = regulatory->max_power_level; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2265 | return 0; |
| 2266 | case 3: |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 2267 | *result = regulatory->tp_scale; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2268 | return 0; |
| 2269 | } |
| 2270 | return false; |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 2271 | case ATH9K_CAP_DS: |
| 2272 | return (AR_SREV_9280_20_OR_LATER(ah) && |
| 2273 | (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1)) |
| 2274 | ? false : true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2275 | default: |
| 2276 | return false; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2277 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2278 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2279 | EXPORT_SYMBOL(ath9k_hw_getcapability); |
Luis R. Rodriguez | 6f25542 | 2008-10-03 15:45:27 -0700 | [diff] [blame] | 2280 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2281 | bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2282 | u32 capability, u32 setting, int *status) |
| 2283 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2284 | switch (type) { |
| 2285 | case ATH9K_CAP_TKIP_MIC: |
| 2286 | if (setting) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2287 | ah->sta_id1_defaults |= |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2288 | AR_STA_ID1_CRPT_MIC_ENABLE; |
| 2289 | else |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2290 | ah->sta_id1_defaults &= |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2291 | ~AR_STA_ID1_CRPT_MIC_ENABLE; |
| 2292 | return true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2293 | case ATH9K_CAP_MCAST_KEYSRCH: |
| 2294 | if (setting) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2295 | ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2296 | else |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2297 | ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2298 | return true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2299 | default: |
| 2300 | return false; |
| 2301 | } |
| 2302 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2303 | EXPORT_SYMBOL(ath9k_hw_setcapability); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2304 | |
| 2305 | /****************************/ |
| 2306 | /* GPIO / RFKILL / Antennae */ |
| 2307 | /****************************/ |
| 2308 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2309 | static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2310 | u32 gpio, u32 type) |
| 2311 | { |
| 2312 | int addr; |
| 2313 | u32 gpio_shift, tmp; |
| 2314 | |
| 2315 | if (gpio > 11) |
| 2316 | addr = AR_GPIO_OUTPUT_MUX3; |
| 2317 | else if (gpio > 5) |
| 2318 | addr = AR_GPIO_OUTPUT_MUX2; |
| 2319 | else |
| 2320 | addr = AR_GPIO_OUTPUT_MUX1; |
| 2321 | |
| 2322 | gpio_shift = (gpio % 6) * 5; |
| 2323 | |
| 2324 | if (AR_SREV_9280_20_OR_LATER(ah) |
| 2325 | || (addr != AR_GPIO_OUTPUT_MUX1)) { |
| 2326 | REG_RMW(ah, addr, (type << gpio_shift), |
| 2327 | (0x1f << gpio_shift)); |
| 2328 | } else { |
| 2329 | tmp = REG_READ(ah, addr); |
| 2330 | tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0); |
| 2331 | tmp &= ~(0x1f << gpio_shift); |
| 2332 | tmp |= (type << gpio_shift); |
| 2333 | REG_WRITE(ah, addr, tmp); |
| 2334 | } |
| 2335 | } |
| 2336 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2337 | void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2338 | { |
| 2339 | u32 gpio_shift; |
| 2340 | |
Luis R. Rodriguez | 9680e8a | 2009-09-13 23:28:00 -0700 | [diff] [blame] | 2341 | BUG_ON(gpio >= ah->caps.num_gpio_pins); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2342 | |
| 2343 | gpio_shift = gpio << 1; |
| 2344 | |
| 2345 | REG_RMW(ah, |
| 2346 | AR_GPIO_OE_OUT, |
| 2347 | (AR_GPIO_OE_OUT_DRV_NO << gpio_shift), |
| 2348 | (AR_GPIO_OE_OUT_DRV << gpio_shift)); |
| 2349 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2350 | EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2351 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2352 | u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2353 | { |
Senthil Balasubramanian | cb33c41 | 2008-12-24 18:03:58 +0530 | [diff] [blame] | 2354 | #define MS_REG_READ(x, y) \ |
| 2355 | (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y))) |
| 2356 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2357 | if (gpio >= ah->caps.num_gpio_pins) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2358 | return 0xffffffff; |
| 2359 | |
Felix Fietkau | 783dfca | 2010-04-15 17:38:11 -0400 | [diff] [blame] | 2360 | if (AR_SREV_9300_20_OR_LATER(ah)) |
| 2361 | return MS_REG_READ(AR9300, gpio) != 0; |
| 2362 | else if (AR_SREV_9271(ah)) |
Sujith | 5b5fa35 | 2010-03-17 14:25:15 +0530 | [diff] [blame] | 2363 | return MS_REG_READ(AR9271, gpio) != 0; |
| 2364 | else if (AR_SREV_9287_10_OR_LATER(ah)) |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 2365 | return MS_REG_READ(AR9287, gpio) != 0; |
| 2366 | else if (AR_SREV_9285_10_OR_LATER(ah)) |
Senthil Balasubramanian | cb33c41 | 2008-12-24 18:03:58 +0530 | [diff] [blame] | 2367 | return MS_REG_READ(AR9285, gpio) != 0; |
| 2368 | else if (AR_SREV_9280_10_OR_LATER(ah)) |
| 2369 | return MS_REG_READ(AR928X, gpio) != 0; |
| 2370 | else |
| 2371 | return MS_REG_READ(AR, gpio) != 0; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2372 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2373 | EXPORT_SYMBOL(ath9k_hw_gpio_get); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2374 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2375 | void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2376 | u32 ah_signal_type) |
| 2377 | { |
| 2378 | u32 gpio_shift; |
| 2379 | |
| 2380 | ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type); |
| 2381 | |
| 2382 | gpio_shift = 2 * gpio; |
| 2383 | |
| 2384 | REG_RMW(ah, |
| 2385 | AR_GPIO_OE_OUT, |
| 2386 | (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift), |
| 2387 | (AR_GPIO_OE_OUT_DRV << gpio_shift)); |
| 2388 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2389 | EXPORT_SYMBOL(ath9k_hw_cfg_output); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2390 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2391 | void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2392 | { |
Sujith | 5b5fa35 | 2010-03-17 14:25:15 +0530 | [diff] [blame] | 2393 | if (AR_SREV_9271(ah)) |
| 2394 | val = ~val; |
| 2395 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2396 | REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio), |
| 2397 | AR_GPIO_BIT(gpio)); |
| 2398 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2399 | EXPORT_SYMBOL(ath9k_hw_set_gpio); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2400 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2401 | u32 ath9k_hw_getdefantenna(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2402 | { |
| 2403 | return REG_READ(ah, AR_DEF_ANTENNA) & 0x7; |
| 2404 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2405 | EXPORT_SYMBOL(ath9k_hw_getdefantenna); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2406 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2407 | void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2408 | { |
| 2409 | REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7)); |
| 2410 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2411 | EXPORT_SYMBOL(ath9k_hw_setantenna); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2412 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2413 | /*********************/ |
| 2414 | /* General Operation */ |
| 2415 | /*********************/ |
| 2416 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2417 | u32 ath9k_hw_getrxfilter(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2418 | { |
| 2419 | u32 bits = REG_READ(ah, AR_RX_FILTER); |
| 2420 | u32 phybits = REG_READ(ah, AR_PHY_ERR); |
| 2421 | |
| 2422 | if (phybits & AR_PHY_ERR_RADAR) |
| 2423 | bits |= ATH9K_RX_FILTER_PHYRADAR; |
| 2424 | if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING)) |
| 2425 | bits |= ATH9K_RX_FILTER_PHYERR; |
| 2426 | |
| 2427 | return bits; |
| 2428 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2429 | EXPORT_SYMBOL(ath9k_hw_getrxfilter); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2430 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2431 | void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2432 | { |
| 2433 | u32 phybits; |
| 2434 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 2435 | ENABLE_REGWRITE_BUFFER(ah); |
| 2436 | |
Sujith | 7ea310b | 2009-09-03 12:08:43 +0530 | [diff] [blame] | 2437 | REG_WRITE(ah, AR_RX_FILTER, bits); |
| 2438 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2439 | phybits = 0; |
| 2440 | if (bits & ATH9K_RX_FILTER_PHYRADAR) |
| 2441 | phybits |= AR_PHY_ERR_RADAR; |
| 2442 | if (bits & ATH9K_RX_FILTER_PHYERR) |
| 2443 | phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING; |
| 2444 | REG_WRITE(ah, AR_PHY_ERR, phybits); |
| 2445 | |
| 2446 | if (phybits) |
| 2447 | REG_WRITE(ah, AR_RXCFG, |
| 2448 | REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA); |
| 2449 | else |
| 2450 | REG_WRITE(ah, AR_RXCFG, |
| 2451 | REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA); |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 2452 | |
| 2453 | REGWRITE_BUFFER_FLUSH(ah); |
| 2454 | DISABLE_REGWRITE_BUFFER(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2455 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2456 | EXPORT_SYMBOL(ath9k_hw_setrxfilter); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2457 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2458 | bool ath9k_hw_phy_disable(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2459 | { |
Senthil Balasubramanian | 63a75b9 | 2009-09-18 15:07:03 +0530 | [diff] [blame] | 2460 | if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM)) |
| 2461 | return false; |
| 2462 | |
| 2463 | ath9k_hw_init_pll(ah, NULL); |
| 2464 | return true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2465 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2466 | EXPORT_SYMBOL(ath9k_hw_phy_disable); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2467 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2468 | bool ath9k_hw_disable(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2469 | { |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 2470 | if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2471 | return false; |
| 2472 | |
Senthil Balasubramanian | 63a75b9 | 2009-09-18 15:07:03 +0530 | [diff] [blame] | 2473 | if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD)) |
| 2474 | return false; |
| 2475 | |
| 2476 | ath9k_hw_init_pll(ah, NULL); |
| 2477 | return true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2478 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2479 | EXPORT_SYMBOL(ath9k_hw_disable); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2480 | |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 2481 | void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2482 | { |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 2483 | struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2484 | struct ath9k_channel *chan = ah->curchan; |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 2485 | struct ieee80211_channel *channel = chan->chan; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2486 | |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 2487 | regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2488 | |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 2489 | ah->eep_ops->set_txpower(ah, chan, |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 2490 | ath9k_regd_get_ctl(regulatory, chan), |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 2491 | channel->max_antenna_gain * 2, |
| 2492 | channel->max_power * 2, |
| 2493 | min((u32) MAX_RATE_POWER, |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 2494 | (u32) regulatory->power_limit)); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2495 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2496 | EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2497 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2498 | void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2499 | { |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 2500 | memcpy(ath9k_hw_common(ah)->macaddr, mac, ETH_ALEN); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2501 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2502 | EXPORT_SYMBOL(ath9k_hw_setmac); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2503 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2504 | void ath9k_hw_setopmode(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2505 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2506 | ath9k_hw_set_operating_mode(ah, ah->opmode); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2507 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2508 | EXPORT_SYMBOL(ath9k_hw_setopmode); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2509 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2510 | void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2511 | { |
| 2512 | REG_WRITE(ah, AR_MCAST_FIL0, filter0); |
| 2513 | REG_WRITE(ah, AR_MCAST_FIL1, filter1); |
| 2514 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2515 | EXPORT_SYMBOL(ath9k_hw_setmcastfilter); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2516 | |
Luis R. Rodriguez | f2b2143 | 2009-09-10 08:50:20 -0700 | [diff] [blame] | 2517 | void ath9k_hw_write_associd(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2518 | { |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 2519 | struct ath_common *common = ath9k_hw_common(ah); |
| 2520 | |
| 2521 | REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid)); |
| 2522 | REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) | |
| 2523 | ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S)); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2524 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2525 | EXPORT_SYMBOL(ath9k_hw_write_associd); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2526 | |
Benoit Papillault | 1c0fc65 | 2010-04-16 00:07:26 +0200 | [diff] [blame] | 2527 | #define ATH9K_MAX_TSF_READ 10 |
| 2528 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2529 | u64 ath9k_hw_gettsf64(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2530 | { |
Benoit Papillault | 1c0fc65 | 2010-04-16 00:07:26 +0200 | [diff] [blame] | 2531 | u32 tsf_lower, tsf_upper1, tsf_upper2; |
| 2532 | int i; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2533 | |
Benoit Papillault | 1c0fc65 | 2010-04-16 00:07:26 +0200 | [diff] [blame] | 2534 | tsf_upper1 = REG_READ(ah, AR_TSF_U32); |
| 2535 | for (i = 0; i < ATH9K_MAX_TSF_READ; i++) { |
| 2536 | tsf_lower = REG_READ(ah, AR_TSF_L32); |
| 2537 | tsf_upper2 = REG_READ(ah, AR_TSF_U32); |
| 2538 | if (tsf_upper2 == tsf_upper1) |
| 2539 | break; |
| 2540 | tsf_upper1 = tsf_upper2; |
| 2541 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2542 | |
Benoit Papillault | 1c0fc65 | 2010-04-16 00:07:26 +0200 | [diff] [blame] | 2543 | WARN_ON( i == ATH9K_MAX_TSF_READ ); |
| 2544 | |
| 2545 | return (((u64)tsf_upper1 << 32) | tsf_lower); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2546 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2547 | EXPORT_SYMBOL(ath9k_hw_gettsf64); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2548 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2549 | void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64) |
Alina Friedrichsen | 27abe06 | 2009-01-23 05:44:21 +0100 | [diff] [blame] | 2550 | { |
Alina Friedrichsen | 27abe06 | 2009-01-23 05:44:21 +0100 | [diff] [blame] | 2551 | REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff); |
Alina Friedrichsen | b9a1619 | 2009-03-02 23:28:38 +0100 | [diff] [blame] | 2552 | REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff); |
Alina Friedrichsen | 27abe06 | 2009-01-23 05:44:21 +0100 | [diff] [blame] | 2553 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2554 | EXPORT_SYMBOL(ath9k_hw_settsf64); |
Alina Friedrichsen | 27abe06 | 2009-01-23 05:44:21 +0100 | [diff] [blame] | 2555 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2556 | void ath9k_hw_reset_tsf(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2557 | { |
Gabor Juhos | f9b604f | 2009-06-21 00:02:15 +0200 | [diff] [blame] | 2558 | if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0, |
| 2559 | AH_TSF_WRITE_TIMEOUT)) |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2560 | ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, |
| 2561 | "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n"); |
Gabor Juhos | f9b604f | 2009-06-21 00:02:15 +0200 | [diff] [blame] | 2562 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2563 | REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2564 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2565 | EXPORT_SYMBOL(ath9k_hw_reset_tsf); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2566 | |
Sujith | 54e4cec | 2009-08-07 09:45:09 +0530 | [diff] [blame] | 2567 | void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2568 | { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2569 | if (setting) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2570 | ah->misc_mode |= AR_PCU_TX_ADD_TSF; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2571 | else |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2572 | ah->misc_mode &= ~AR_PCU_TX_ADD_TSF; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2573 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2574 | EXPORT_SYMBOL(ath9k_hw_set_tsfadjust); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2575 | |
Luis R. Rodriguez | 30cbd42 | 2009-11-03 16:10:46 -0800 | [diff] [blame] | 2576 | /* |
| 2577 | * Extend 15-bit time stamp from rx descriptor to |
| 2578 | * a full 64-bit TSF using the current h/w TSF. |
| 2579 | */ |
| 2580 | u64 ath9k_hw_extend_tsf(struct ath_hw *ah, u32 rstamp) |
| 2581 | { |
| 2582 | u64 tsf; |
| 2583 | |
| 2584 | tsf = ath9k_hw_gettsf64(ah); |
| 2585 | if ((tsf & 0x7fff) < rstamp) |
| 2586 | tsf -= 0x8000; |
| 2587 | return (tsf & ~0x7fff) | rstamp; |
| 2588 | } |
| 2589 | EXPORT_SYMBOL(ath9k_hw_extend_tsf); |
| 2590 | |
Luis R. Rodriguez | 25c56ee | 2009-09-13 23:04:44 -0700 | [diff] [blame] | 2591 | void ath9k_hw_set11nmac2040(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2592 | { |
Luis R. Rodriguez | 25c56ee | 2009-09-13 23:04:44 -0700 | [diff] [blame] | 2593 | struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2594 | u32 macmode; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2595 | |
Luis R. Rodriguez | 25c56ee | 2009-09-13 23:04:44 -0700 | [diff] [blame] | 2596 | if (conf_is_ht40(conf) && !ah->config.cwm_ignore_extcca) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2597 | macmode = AR_2040_JOINED_RX_CLEAR; |
| 2598 | else |
| 2599 | macmode = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2600 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2601 | REG_WRITE(ah, AR_2040_MODE, macmode); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2602 | } |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 2603 | |
| 2604 | /* HW Generic timers configuration */ |
| 2605 | |
| 2606 | static const struct ath_gen_timer_configuration gen_tmr_configuration[] = |
| 2607 | { |
| 2608 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 2609 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 2610 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 2611 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 2612 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 2613 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 2614 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 2615 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 2616 | {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001}, |
| 2617 | {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4, |
| 2618 | AR_NDP2_TIMER_MODE, 0x0002}, |
| 2619 | {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4, |
| 2620 | AR_NDP2_TIMER_MODE, 0x0004}, |
| 2621 | {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4, |
| 2622 | AR_NDP2_TIMER_MODE, 0x0008}, |
| 2623 | {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4, |
| 2624 | AR_NDP2_TIMER_MODE, 0x0010}, |
| 2625 | {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4, |
| 2626 | AR_NDP2_TIMER_MODE, 0x0020}, |
| 2627 | {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4, |
| 2628 | AR_NDP2_TIMER_MODE, 0x0040}, |
| 2629 | {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4, |
| 2630 | AR_NDP2_TIMER_MODE, 0x0080} |
| 2631 | }; |
| 2632 | |
| 2633 | /* HW generic timer primitives */ |
| 2634 | |
| 2635 | /* compute and clear index of rightmost 1 */ |
| 2636 | static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask) |
| 2637 | { |
| 2638 | u32 b; |
| 2639 | |
| 2640 | b = *mask; |
| 2641 | b &= (0-b); |
| 2642 | *mask &= ~b; |
| 2643 | b *= debruijn32; |
| 2644 | b >>= 27; |
| 2645 | |
| 2646 | return timer_table->gen_timer_index[b]; |
| 2647 | } |
| 2648 | |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 2649 | u32 ath9k_hw_gettsf32(struct ath_hw *ah) |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 2650 | { |
| 2651 | return REG_READ(ah, AR_TSF_L32); |
| 2652 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2653 | EXPORT_SYMBOL(ath9k_hw_gettsf32); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 2654 | |
| 2655 | struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah, |
| 2656 | void (*trigger)(void *), |
| 2657 | void (*overflow)(void *), |
| 2658 | void *arg, |
| 2659 | u8 timer_index) |
| 2660 | { |
| 2661 | struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers; |
| 2662 | struct ath_gen_timer *timer; |
| 2663 | |
| 2664 | timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL); |
| 2665 | |
| 2666 | if (timer == NULL) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2667 | ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL, |
| 2668 | "Failed to allocate memory" |
| 2669 | "for hw timer[%d]\n", timer_index); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 2670 | return NULL; |
| 2671 | } |
| 2672 | |
| 2673 | /* allocate a hardware generic timer slot */ |
| 2674 | timer_table->timers[timer_index] = timer; |
| 2675 | timer->index = timer_index; |
| 2676 | timer->trigger = trigger; |
| 2677 | timer->overflow = overflow; |
| 2678 | timer->arg = arg; |
| 2679 | |
| 2680 | return timer; |
| 2681 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2682 | EXPORT_SYMBOL(ath_gen_timer_alloc); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 2683 | |
Luis R. Rodriguez | cd9bf68 | 2009-09-13 02:08:34 -0700 | [diff] [blame] | 2684 | void ath9k_hw_gen_timer_start(struct ath_hw *ah, |
| 2685 | struct ath_gen_timer *timer, |
| 2686 | u32 timer_next, |
| 2687 | u32 timer_period) |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 2688 | { |
| 2689 | struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers; |
| 2690 | u32 tsf; |
| 2691 | |
| 2692 | BUG_ON(!timer_period); |
| 2693 | |
| 2694 | set_bit(timer->index, &timer_table->timer_mask.timer_bits); |
| 2695 | |
| 2696 | tsf = ath9k_hw_gettsf32(ah); |
| 2697 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2698 | ath_print(ath9k_hw_common(ah), ATH_DBG_HWTIMER, |
| 2699 | "curent tsf %x period %x" |
| 2700 | "timer_next %x\n", tsf, timer_period, timer_next); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 2701 | |
| 2702 | /* |
| 2703 | * Pull timer_next forward if the current TSF already passed it |
| 2704 | * because of software latency |
| 2705 | */ |
| 2706 | if (timer_next < tsf) |
| 2707 | timer_next = tsf + timer_period; |
| 2708 | |
| 2709 | /* |
| 2710 | * Program generic timer registers |
| 2711 | */ |
| 2712 | REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr, |
| 2713 | timer_next); |
| 2714 | REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr, |
| 2715 | timer_period); |
| 2716 | REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr, |
| 2717 | gen_tmr_configuration[timer->index].mode_mask); |
| 2718 | |
| 2719 | /* Enable both trigger and thresh interrupt masks */ |
| 2720 | REG_SET_BIT(ah, AR_IMR_S5, |
| 2721 | (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) | |
| 2722 | SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG))); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 2723 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2724 | EXPORT_SYMBOL(ath9k_hw_gen_timer_start); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 2725 | |
Luis R. Rodriguez | cd9bf68 | 2009-09-13 02:08:34 -0700 | [diff] [blame] | 2726 | void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer) |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 2727 | { |
| 2728 | struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers; |
| 2729 | |
| 2730 | if ((timer->index < AR_FIRST_NDP_TIMER) || |
| 2731 | (timer->index >= ATH_MAX_GEN_TIMER)) { |
| 2732 | return; |
| 2733 | } |
| 2734 | |
| 2735 | /* Clear generic timer enable bits. */ |
| 2736 | REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr, |
| 2737 | gen_tmr_configuration[timer->index].mode_mask); |
| 2738 | |
| 2739 | /* Disable both trigger and thresh interrupt masks */ |
| 2740 | REG_CLR_BIT(ah, AR_IMR_S5, |
| 2741 | (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) | |
| 2742 | SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG))); |
| 2743 | |
| 2744 | clear_bit(timer->index, &timer_table->timer_mask.timer_bits); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 2745 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2746 | EXPORT_SYMBOL(ath9k_hw_gen_timer_stop); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 2747 | |
| 2748 | void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer) |
| 2749 | { |
| 2750 | struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers; |
| 2751 | |
| 2752 | /* free the hardware generic timer slot */ |
| 2753 | timer_table->timers[timer->index] = NULL; |
| 2754 | kfree(timer); |
| 2755 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2756 | EXPORT_SYMBOL(ath_gen_timer_free); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 2757 | |
| 2758 | /* |
| 2759 | * Generic Timer Interrupts handling |
| 2760 | */ |
| 2761 | void ath_gen_timer_isr(struct ath_hw *ah) |
| 2762 | { |
| 2763 | struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers; |
| 2764 | struct ath_gen_timer *timer; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2765 | struct ath_common *common = ath9k_hw_common(ah); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 2766 | u32 trigger_mask, thresh_mask, index; |
| 2767 | |
| 2768 | /* get hardware generic timer interrupt status */ |
| 2769 | trigger_mask = ah->intr_gen_timer_trigger; |
| 2770 | thresh_mask = ah->intr_gen_timer_thresh; |
| 2771 | trigger_mask &= timer_table->timer_mask.val; |
| 2772 | thresh_mask &= timer_table->timer_mask.val; |
| 2773 | |
| 2774 | trigger_mask &= ~thresh_mask; |
| 2775 | |
| 2776 | while (thresh_mask) { |
| 2777 | index = rightmost_index(timer_table, &thresh_mask); |
| 2778 | timer = timer_table->timers[index]; |
| 2779 | BUG_ON(!timer); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2780 | ath_print(common, ATH_DBG_HWTIMER, |
| 2781 | "TSF overflow for Gen timer %d\n", index); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 2782 | timer->overflow(timer->arg); |
| 2783 | } |
| 2784 | |
| 2785 | while (trigger_mask) { |
| 2786 | index = rightmost_index(timer_table, &trigger_mask); |
| 2787 | timer = timer_table->timers[index]; |
| 2788 | BUG_ON(!timer); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2789 | ath_print(common, ATH_DBG_HWTIMER, |
| 2790 | "Gen timer[%d] trigger\n", index); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 2791 | timer->trigger(timer->arg); |
| 2792 | } |
| 2793 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2794 | EXPORT_SYMBOL(ath_gen_timer_isr); |
Luis R. Rodriguez | 2da4f01 | 2009-10-27 12:59:33 -0400 | [diff] [blame] | 2795 | |
Sujith | 05020d2 | 2010-03-17 14:25:23 +0530 | [diff] [blame] | 2796 | /********/ |
| 2797 | /* HTC */ |
| 2798 | /********/ |
| 2799 | |
| 2800 | void ath9k_hw_htc_resetinit(struct ath_hw *ah) |
| 2801 | { |
| 2802 | ah->htc_reset_init = true; |
| 2803 | } |
| 2804 | EXPORT_SYMBOL(ath9k_hw_htc_resetinit); |
| 2805 | |
Luis R. Rodriguez | 2da4f01 | 2009-10-27 12:59:33 -0400 | [diff] [blame] | 2806 | static struct { |
| 2807 | u32 version; |
| 2808 | const char * name; |
| 2809 | } ath_mac_bb_names[] = { |
| 2810 | /* Devices with external radios */ |
| 2811 | { AR_SREV_VERSION_5416_PCI, "5416" }, |
| 2812 | { AR_SREV_VERSION_5416_PCIE, "5418" }, |
| 2813 | { AR_SREV_VERSION_9100, "9100" }, |
| 2814 | { AR_SREV_VERSION_9160, "9160" }, |
| 2815 | /* Single-chip solutions */ |
| 2816 | { AR_SREV_VERSION_9280, "9280" }, |
| 2817 | { AR_SREV_VERSION_9285, "9285" }, |
Luis R. Rodriguez | 1115847 | 2009-10-27 12:59:35 -0400 | [diff] [blame] | 2818 | { AR_SREV_VERSION_9287, "9287" }, |
| 2819 | { AR_SREV_VERSION_9271, "9271" }, |
Luis R. Rodriguez | ec83903 | 2010-04-15 17:39:20 -0400 | [diff] [blame] | 2820 | { AR_SREV_VERSION_9300, "9300" }, |
Luis R. Rodriguez | 2da4f01 | 2009-10-27 12:59:33 -0400 | [diff] [blame] | 2821 | }; |
| 2822 | |
| 2823 | /* For devices with external radios */ |
| 2824 | static struct { |
| 2825 | u16 version; |
| 2826 | const char * name; |
| 2827 | } ath_rf_names[] = { |
| 2828 | { 0, "5133" }, |
| 2829 | { AR_RAD5133_SREV_MAJOR, "5133" }, |
| 2830 | { AR_RAD5122_SREV_MAJOR, "5122" }, |
| 2831 | { AR_RAD2133_SREV_MAJOR, "2133" }, |
| 2832 | { AR_RAD2122_SREV_MAJOR, "2122" } |
| 2833 | }; |
| 2834 | |
| 2835 | /* |
| 2836 | * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown. |
| 2837 | */ |
Luis R. Rodriguez | f934c4d | 2009-10-27 12:59:34 -0400 | [diff] [blame] | 2838 | static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version) |
Luis R. Rodriguez | 2da4f01 | 2009-10-27 12:59:33 -0400 | [diff] [blame] | 2839 | { |
| 2840 | int i; |
| 2841 | |
| 2842 | for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) { |
| 2843 | if (ath_mac_bb_names[i].version == mac_bb_version) { |
| 2844 | return ath_mac_bb_names[i].name; |
| 2845 | } |
| 2846 | } |
| 2847 | |
| 2848 | return "????"; |
| 2849 | } |
Luis R. Rodriguez | 2da4f01 | 2009-10-27 12:59:33 -0400 | [diff] [blame] | 2850 | |
| 2851 | /* |
| 2852 | * Return the RF name. "????" is returned if the RF is unknown. |
| 2853 | * Used for devices with external radios. |
| 2854 | */ |
Luis R. Rodriguez | f934c4d | 2009-10-27 12:59:34 -0400 | [diff] [blame] | 2855 | static const char *ath9k_hw_rf_name(u16 rf_version) |
Luis R. Rodriguez | 2da4f01 | 2009-10-27 12:59:33 -0400 | [diff] [blame] | 2856 | { |
| 2857 | int i; |
| 2858 | |
| 2859 | for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) { |
| 2860 | if (ath_rf_names[i].version == rf_version) { |
| 2861 | return ath_rf_names[i].name; |
| 2862 | } |
| 2863 | } |
| 2864 | |
| 2865 | return "????"; |
| 2866 | } |
Luis R. Rodriguez | f934c4d | 2009-10-27 12:59:34 -0400 | [diff] [blame] | 2867 | |
| 2868 | void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len) |
| 2869 | { |
| 2870 | int used; |
| 2871 | |
| 2872 | /* chipsets >= AR9280 are single-chip */ |
| 2873 | if (AR_SREV_9280_10_OR_LATER(ah)) { |
| 2874 | used = snprintf(hw_name, len, |
| 2875 | "Atheros AR%s Rev:%x", |
| 2876 | ath9k_hw_mac_bb_name(ah->hw_version.macVersion), |
| 2877 | ah->hw_version.macRev); |
| 2878 | } |
| 2879 | else { |
| 2880 | used = snprintf(hw_name, len, |
| 2881 | "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x", |
| 2882 | ath9k_hw_mac_bb_name(ah->hw_version.macVersion), |
| 2883 | ah->hw_version.macRev, |
| 2884 | ath9k_hw_rf_name((ah->hw_version.analog5GhzRev & |
| 2885 | AR_RADIO_SREV_MAJOR)), |
| 2886 | ah->hw_version.phyRev); |
| 2887 | } |
| 2888 | |
| 2889 | hw_name[used] = '\0'; |
| 2890 | } |
| 2891 | EXPORT_SYMBOL(ath9k_hw_name); |