Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1 | /* |
Sujith | cee075a | 2009-03-13 09:07:23 +0530 | [diff] [blame] | 2 | * Copyright (c) 2008-2009 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 | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 23 | #include "initvals.h" |
| 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 |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 28 | |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 29 | static void ar9002_hw_attach_ops(struct ath_hw *ah); |
Luis R. Rodriguez | 8525f28 | 2010-04-15 17:38:19 -0400 | [diff] [blame] | 30 | static void ar9003_hw_attach_ops(struct ath_hw *ah); |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 31 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 32 | 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] | 33 | |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 34 | MODULE_AUTHOR("Atheros Communications"); |
| 35 | MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards."); |
| 36 | MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards"); |
| 37 | MODULE_LICENSE("Dual BSD/GPL"); |
| 38 | |
| 39 | static int __init ath9k_init(void) |
| 40 | { |
| 41 | return 0; |
| 42 | } |
| 43 | module_init(ath9k_init); |
| 44 | |
| 45 | static void __exit ath9k_exit(void) |
| 46 | { |
| 47 | return; |
| 48 | } |
| 49 | module_exit(ath9k_exit); |
| 50 | |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 51 | /* Private hardware callbacks */ |
| 52 | |
| 53 | static void ath9k_hw_init_cal_settings(struct ath_hw *ah) |
| 54 | { |
| 55 | ath9k_hw_private_ops(ah)->init_cal_settings(ah); |
| 56 | } |
| 57 | |
| 58 | static void ath9k_hw_init_mode_regs(struct ath_hw *ah) |
| 59 | { |
| 60 | ath9k_hw_private_ops(ah)->init_mode_regs(ah); |
| 61 | } |
| 62 | |
| 63 | static bool ath9k_hw_macversion_supported(struct ath_hw *ah) |
| 64 | { |
| 65 | struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah); |
| 66 | |
| 67 | return priv_ops->macversion_supported(ah->hw_version.macVersion); |
| 68 | } |
| 69 | |
Luis R. Rodriguez | 6477396 | 2010-04-15 17:38:17 -0400 | [diff] [blame] | 70 | static u32 ath9k_hw_compute_pll_control(struct ath_hw *ah, |
| 71 | struct ath9k_channel *chan) |
| 72 | { |
| 73 | return ath9k_hw_private_ops(ah)->compute_pll_control(ah, chan); |
| 74 | } |
| 75 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 76 | /********************/ |
| 77 | /* Helper Functions */ |
| 78 | /********************/ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 79 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 80 | static u32 ath9k_hw_mac_clks(struct ath_hw *ah, u32 usecs) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 81 | { |
Luis R. Rodriguez | b002a4a | 2009-09-13 00:03:27 -0700 | [diff] [blame] | 82 | struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf; |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 83 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 84 | if (!ah->curchan) /* should really check for CCK instead */ |
Luis R. Rodriguez | 4febf7b | 2008-12-23 15:58:48 -0800 | [diff] [blame] | 85 | return usecs *ATH9K_CLOCK_RATE_CCK; |
| 86 | if (conf->channel->band == IEEE80211_BAND_2GHZ) |
| 87 | return usecs *ATH9K_CLOCK_RATE_2GHZ_OFDM; |
| 88 | return usecs *ATH9K_CLOCK_RATE_5GHZ_OFDM; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 89 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 90 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 91 | static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 92 | { |
Luis R. Rodriguez | b002a4a | 2009-09-13 00:03:27 -0700 | [diff] [blame] | 93 | struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf; |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 94 | |
Luis R. Rodriguez | 4febf7b | 2008-12-23 15:58:48 -0800 | [diff] [blame] | 95 | if (conf_is_ht40(conf)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 96 | return ath9k_hw_mac_clks(ah, usecs) * 2; |
| 97 | else |
| 98 | return ath9k_hw_mac_clks(ah, usecs); |
| 99 | } |
| 100 | |
Sujith | 0caa7b1 | 2009-02-16 13:23:20 +0530 | [diff] [blame] | 101 | 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] | 102 | { |
| 103 | int i; |
| 104 | |
Sujith | 0caa7b1 | 2009-02-16 13:23:20 +0530 | [diff] [blame] | 105 | BUG_ON(timeout < AH_TIME_QUANTUM); |
| 106 | |
| 107 | for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 108 | if ((REG_READ(ah, reg) & mask) == val) |
| 109 | return true; |
| 110 | |
| 111 | udelay(AH_TIME_QUANTUM); |
| 112 | } |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 113 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 114 | ath_print(ath9k_hw_common(ah), ATH_DBG_ANY, |
| 115 | "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n", |
| 116 | timeout, reg, REG_READ(ah, reg), mask, val); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 117 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 118 | return false; |
| 119 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 120 | EXPORT_SYMBOL(ath9k_hw_wait); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 121 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 122 | u32 ath9k_hw_reverse_bits(u32 val, u32 n) |
| 123 | { |
| 124 | u32 retval; |
| 125 | int i; |
| 126 | |
| 127 | for (i = 0, retval = 0; i < n; i++) { |
| 128 | retval = (retval << 1) | (val & 1); |
| 129 | val >>= 1; |
| 130 | } |
| 131 | return retval; |
| 132 | } |
| 133 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 134 | bool ath9k_get_channel_edges(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 135 | u16 flags, u16 *low, |
| 136 | u16 *high) |
| 137 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 138 | struct ath9k_hw_capabilities *pCap = &ah->caps; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 139 | |
| 140 | if (flags & CHANNEL_5GHZ) { |
| 141 | *low = pCap->low_5ghz_chan; |
| 142 | *high = pCap->high_5ghz_chan; |
| 143 | return true; |
| 144 | } |
| 145 | if ((flags & CHANNEL_2GHZ)) { |
| 146 | *low = pCap->low_2ghz_chan; |
| 147 | *high = pCap->high_2ghz_chan; |
| 148 | return true; |
| 149 | } |
| 150 | return false; |
| 151 | } |
| 152 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 153 | u16 ath9k_hw_computetxtime(struct ath_hw *ah, |
Felix Fietkau | 545750d | 2009-11-23 22:21:01 +0100 | [diff] [blame] | 154 | u8 phy, int kbps, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 155 | u32 frameLen, u16 rateix, |
| 156 | bool shortPreamble) |
| 157 | { |
| 158 | u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 159 | |
| 160 | if (kbps == 0) |
| 161 | return 0; |
| 162 | |
Felix Fietkau | 545750d | 2009-11-23 22:21:01 +0100 | [diff] [blame] | 163 | switch (phy) { |
Sujith | 46d14a5 | 2008-11-18 09:08:13 +0530 | [diff] [blame] | 164 | case WLAN_RC_PHY_CCK: |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 165 | phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS; |
Felix Fietkau | 545750d | 2009-11-23 22:21:01 +0100 | [diff] [blame] | 166 | if (shortPreamble) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 167 | phyTime >>= 1; |
| 168 | numBits = frameLen << 3; |
| 169 | txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps); |
| 170 | break; |
Sujith | 46d14a5 | 2008-11-18 09:08:13 +0530 | [diff] [blame] | 171 | case WLAN_RC_PHY_OFDM: |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 172 | if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 173 | bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000; |
| 174 | numBits = OFDM_PLCP_BITS + (frameLen << 3); |
| 175 | numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol); |
| 176 | txTime = OFDM_SIFS_TIME_QUARTER |
| 177 | + OFDM_PREAMBLE_TIME_QUARTER |
| 178 | + (numSymbols * OFDM_SYMBOL_TIME_QUARTER); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 179 | } else if (ah->curchan && |
| 180 | IS_CHAN_HALF_RATE(ah->curchan)) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 181 | bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000; |
| 182 | numBits = OFDM_PLCP_BITS + (frameLen << 3); |
| 183 | numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol); |
| 184 | txTime = OFDM_SIFS_TIME_HALF + |
| 185 | OFDM_PREAMBLE_TIME_HALF |
| 186 | + (numSymbols * OFDM_SYMBOL_TIME_HALF); |
| 187 | } else { |
| 188 | bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000; |
| 189 | numBits = OFDM_PLCP_BITS + (frameLen << 3); |
| 190 | numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol); |
| 191 | txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME |
| 192 | + (numSymbols * OFDM_SYMBOL_TIME); |
| 193 | } |
| 194 | break; |
| 195 | default: |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 196 | ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL, |
Felix Fietkau | 545750d | 2009-11-23 22:21:01 +0100 | [diff] [blame] | 197 | "Unknown phy %u (rate ix %u)\n", phy, rateix); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 198 | txTime = 0; |
| 199 | break; |
| 200 | } |
| 201 | |
| 202 | return txTime; |
| 203 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 204 | EXPORT_SYMBOL(ath9k_hw_computetxtime); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 205 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 206 | void ath9k_hw_get_channel_centers(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 207 | struct ath9k_channel *chan, |
| 208 | struct chan_centers *centers) |
| 209 | { |
| 210 | int8_t extoff; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 211 | |
| 212 | if (!IS_CHAN_HT40(chan)) { |
| 213 | centers->ctl_center = centers->ext_center = |
| 214 | centers->synth_center = chan->channel; |
| 215 | return; |
| 216 | } |
| 217 | |
| 218 | if ((chan->chanmode == CHANNEL_A_HT40PLUS) || |
| 219 | (chan->chanmode == CHANNEL_G_HT40PLUS)) { |
| 220 | centers->synth_center = |
| 221 | chan->channel + HT40_CHANNEL_CENTER_SHIFT; |
| 222 | extoff = 1; |
| 223 | } else { |
| 224 | centers->synth_center = |
| 225 | chan->channel - HT40_CHANNEL_CENTER_SHIFT; |
| 226 | extoff = -1; |
| 227 | } |
| 228 | |
| 229 | centers->ctl_center = |
| 230 | centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT); |
Luis R. Rodriguez | 6420014 | 2009-09-13 22:05:04 -0700 | [diff] [blame] | 231 | /* 25 MHz spacing is supported by hw but not on upper layers */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 232 | centers->ext_center = |
Luis R. Rodriguez | 6420014 | 2009-09-13 22:05:04 -0700 | [diff] [blame] | 233 | centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | /******************/ |
| 237 | /* Chip Revisions */ |
| 238 | /******************/ |
| 239 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 240 | static void ath9k_hw_read_revisions(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 241 | { |
| 242 | u32 val; |
| 243 | |
| 244 | val = REG_READ(ah, AR_SREV) & AR_SREV_ID; |
| 245 | |
| 246 | if (val == 0xFF) { |
| 247 | val = REG_READ(ah, AR_SREV); |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 248 | ah->hw_version.macVersion = |
| 249 | (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S; |
| 250 | ah->hw_version.macRev = MS(val, AR_SREV_REVISION2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 251 | ah->is_pciexpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 252 | } else { |
| 253 | if (!AR_SREV_9100(ah)) |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 254 | ah->hw_version.macVersion = MS(val, AR_SREV_VERSION); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 255 | |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 256 | ah->hw_version.macRev = val & AR_SREV_REVISION; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 257 | |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 258 | if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 259 | ah->is_pciexpress = true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 260 | } |
| 261 | } |
| 262 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 263 | static int ath9k_hw_get_radiorev(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 264 | { |
| 265 | u32 val; |
| 266 | int i; |
| 267 | |
| 268 | REG_WRITE(ah, AR_PHY(0x36), 0x00007058); |
| 269 | |
| 270 | for (i = 0; i < 8; i++) |
| 271 | REG_WRITE(ah, AR_PHY(0x20), 0x00010000); |
| 272 | val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff; |
| 273 | val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4); |
| 274 | |
| 275 | return ath9k_hw_reverse_bits(val, 8); |
| 276 | } |
| 277 | |
| 278 | /************************************/ |
| 279 | /* HW Attach, Detach, Init Routines */ |
| 280 | /************************************/ |
| 281 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 282 | static void ath9k_hw_disablepcie(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 283 | { |
Sujith | feed029 | 2009-01-29 11:37:35 +0530 | [diff] [blame] | 284 | if (AR_SREV_9100(ah)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 285 | return; |
| 286 | |
| 287 | REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00); |
| 288 | REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924); |
| 289 | REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029); |
| 290 | REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824); |
| 291 | REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579); |
| 292 | REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000); |
| 293 | REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40); |
| 294 | REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554); |
| 295 | REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007); |
| 296 | |
| 297 | REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000); |
| 298 | } |
| 299 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 300 | static bool ath9k_hw_chip_test(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 301 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 302 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 303 | u32 regAddr[2] = { AR_STA_ID0, AR_PHY_BASE + (8 << 2) }; |
| 304 | u32 regHold[2]; |
| 305 | u32 patternData[4] = { 0x55555555, |
| 306 | 0xaaaaaaaa, |
| 307 | 0x66666666, |
| 308 | 0x99999999 }; |
| 309 | int i, j; |
| 310 | |
| 311 | for (i = 0; i < 2; i++) { |
| 312 | u32 addr = regAddr[i]; |
| 313 | u32 wrData, rdData; |
| 314 | |
| 315 | regHold[i] = REG_READ(ah, addr); |
| 316 | for (j = 0; j < 0x100; j++) { |
| 317 | wrData = (j << 16) | j; |
| 318 | REG_WRITE(ah, addr, wrData); |
| 319 | rdData = REG_READ(ah, addr); |
| 320 | if (rdData != wrData) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 321 | ath_print(common, ATH_DBG_FATAL, |
| 322 | "address test failed " |
| 323 | "addr: 0x%08x - wr:0x%08x != " |
| 324 | "rd:0x%08x\n", |
| 325 | addr, wrData, rdData); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 326 | return false; |
| 327 | } |
| 328 | } |
| 329 | for (j = 0; j < 4; j++) { |
| 330 | wrData = patternData[j]; |
| 331 | REG_WRITE(ah, addr, wrData); |
| 332 | rdData = REG_READ(ah, addr); |
| 333 | if (wrData != rdData) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 334 | ath_print(common, ATH_DBG_FATAL, |
| 335 | "address test failed " |
| 336 | "addr: 0x%08x - wr:0x%08x != " |
| 337 | "rd:0x%08x\n", |
| 338 | addr, wrData, rdData); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 339 | return false; |
| 340 | } |
| 341 | } |
| 342 | REG_WRITE(ah, regAddr[i], regHold[i]); |
| 343 | } |
| 344 | udelay(100); |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 345 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 346 | return true; |
| 347 | } |
| 348 | |
Luis R. Rodriguez | b8b0f37 | 2009-08-03 12:24:43 -0700 | [diff] [blame] | 349 | static void ath9k_hw_init_config(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 350 | { |
| 351 | int i; |
| 352 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 353 | ah->config.dma_beacon_response_time = 2; |
| 354 | ah->config.sw_beacon_response_time = 10; |
| 355 | ah->config.additional_swba_backoff = 0; |
| 356 | ah->config.ack_6mb = 0x0; |
| 357 | ah->config.cwm_ignore_extcca = 0; |
| 358 | ah->config.pcie_powersave_enable = 0; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 359 | ah->config.pcie_clock_req = 0; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 360 | ah->config.pcie_waen = 0; |
| 361 | ah->config.analog_shiftreg = 1; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 362 | ah->config.ofdm_trig_low = 200; |
| 363 | ah->config.ofdm_trig_high = 500; |
| 364 | ah->config.cck_trig_high = 200; |
| 365 | ah->config.cck_trig_low = 100; |
| 366 | ah->config.enable_ani = 1; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 367 | |
| 368 | for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 369 | ah->config.spurchans[i][0] = AR_NO_SPUR; |
| 370 | ah->config.spurchans[i][1] = AR_NO_SPUR; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 371 | } |
| 372 | |
Luis R. Rodriguez | 5ffaf8a | 2010-02-02 11:58:33 -0500 | [diff] [blame] | 373 | if (ah->hw_version.devid != AR2427_DEVID_PCIE) |
| 374 | ah->config.ht_enable = 1; |
| 375 | else |
| 376 | ah->config.ht_enable = 0; |
| 377 | |
Sujith | 0ce024c | 2009-12-14 14:57:00 +0530 | [diff] [blame] | 378 | ah->config.rx_intr_mitigation = true; |
Luis R. Rodriguez | 6158425 | 2009-03-12 18:18:49 -0400 | [diff] [blame] | 379 | |
| 380 | /* |
| 381 | * We need this for PCI devices only (Cardbus, PCI, miniPCI) |
| 382 | * _and_ if on non-uniprocessor systems (Multiprocessor/HT). |
| 383 | * This means we use it for all AR5416 devices, and the few |
| 384 | * minor PCI AR9280 devices out there. |
| 385 | * |
| 386 | * Serialization is required because these devices do not handle |
| 387 | * well the case of two concurrent reads/writes due to the latency |
| 388 | * involved. During one read/write another read/write can be issued |
| 389 | * on another CPU while the previous read/write may still be working |
| 390 | * on our hardware, if we hit this case the hardware poops in a loop. |
| 391 | * We prevent this by serializing reads and writes. |
| 392 | * |
| 393 | * This issue is not present on PCI-Express devices or pre-AR5416 |
| 394 | * devices (legacy, 802.11abg). |
| 395 | */ |
| 396 | if (num_possible_cpus() > 1) |
David S. Miller | 2d6a5e9 | 2009-03-17 15:01:30 -0700 | [diff] [blame] | 397 | ah->config.serialize_regmode = SER_REG_MODE_AUTO; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 398 | } |
| 399 | |
Luis R. Rodriguez | 50aca25 | 2009-08-03 12:24:42 -0700 | [diff] [blame] | 400 | static void ath9k_hw_init_defaults(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 401 | { |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 402 | struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah); |
| 403 | |
| 404 | regulatory->country_code = CTRY_DEFAULT; |
| 405 | regulatory->power_limit = MAX_RATE_POWER; |
| 406 | regulatory->tp_scale = ATH9K_TP_SCALE_MAX; |
| 407 | |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 408 | ah->hw_version.magic = AR5416_MAGIC; |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 409 | ah->hw_version.subvendorid = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 410 | |
| 411 | ah->ah_flags = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 412 | if (!AR_SREV_9100(ah)) |
| 413 | ah->ah_flags = AH_USE_EEPROM; |
| 414 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 415 | ah->atim_window = 0; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 416 | ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE; |
| 417 | ah->beacon_interval = 100; |
| 418 | ah->enable_32kHz_clock = DONT_USE_32KHZ; |
| 419 | ah->slottime = (u32) -1; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 420 | ah->globaltxtimeout = (u32) -1; |
Gabor Juhos | cbdec97 | 2009-07-24 17:27:22 +0200 | [diff] [blame] | 421 | ah->power_mode = ATH9K_PM_UNDEFINED; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 422 | } |
| 423 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 424 | static int ath9k_hw_rf_claim(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 425 | { |
| 426 | u32 val; |
| 427 | |
| 428 | REG_WRITE(ah, AR_PHY(0), 0x00000007); |
| 429 | |
| 430 | val = ath9k_hw_get_radiorev(ah); |
| 431 | switch (val & AR_RADIO_SREV_MAJOR) { |
| 432 | case 0: |
| 433 | val = AR_RAD5133_SREV_MAJOR; |
| 434 | break; |
| 435 | case AR_RAD5133_SREV_MAJOR: |
| 436 | case AR_RAD5122_SREV_MAJOR: |
| 437 | case AR_RAD2133_SREV_MAJOR: |
| 438 | case AR_RAD2122_SREV_MAJOR: |
| 439 | break; |
| 440 | default: |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 441 | ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL, |
| 442 | "Radio Chip Rev 0x%02X not supported\n", |
| 443 | val & AR_RADIO_SREV_MAJOR); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 444 | return -EOPNOTSUPP; |
| 445 | } |
| 446 | |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 447 | ah->hw_version.analog5GhzRev = val; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 448 | |
| 449 | return 0; |
| 450 | } |
| 451 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 452 | static int ath9k_hw_init_macaddr(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 453 | { |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 454 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 455 | u32 sum; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 456 | int i; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 457 | u16 eeval; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 458 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 459 | sum = 0; |
| 460 | for (i = 0; i < 3; i++) { |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 461 | eeval = ah->eep_ops->get_eeprom(ah, AR_EEPROM_MAC(i)); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 462 | sum += eeval; |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 463 | common->macaddr[2 * i] = eeval >> 8; |
| 464 | common->macaddr[2 * i + 1] = eeval & 0xff; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 465 | } |
Sujith | d8baa93 | 2009-03-30 15:28:25 +0530 | [diff] [blame] | 466 | if (sum == 0 || sum == 0xffff * 3) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 467 | return -EADDRNOTAVAIL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 468 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 469 | return 0; |
| 470 | } |
| 471 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 472 | static void ath9k_hw_init_rxgain_ini(struct ath_hw *ah) |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 473 | { |
| 474 | u32 rxgain_type; |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 475 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 476 | if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_17) { |
| 477 | rxgain_type = ah->eep_ops->get_eeprom(ah, EEP_RXGAIN_TYPE); |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 478 | |
| 479 | if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 480 | INIT_INI_ARRAY(&ah->iniModesRxGain, |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 481 | ar9280Modes_backoff_13db_rxgain_9280_2, |
| 482 | ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2), 6); |
| 483 | else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 484 | INIT_INI_ARRAY(&ah->iniModesRxGain, |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 485 | ar9280Modes_backoff_23db_rxgain_9280_2, |
| 486 | ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 6); |
| 487 | else |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 488 | INIT_INI_ARRAY(&ah->iniModesRxGain, |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 489 | ar9280Modes_original_rxgain_9280_2, |
| 490 | ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6); |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 491 | } else { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 492 | INIT_INI_ARRAY(&ah->iniModesRxGain, |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 493 | ar9280Modes_original_rxgain_9280_2, |
| 494 | ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6); |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 495 | } |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 496 | } |
| 497 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 498 | static void ath9k_hw_init_txgain_ini(struct ath_hw *ah) |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 499 | { |
| 500 | u32 txgain_type; |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 501 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 502 | if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_19) { |
| 503 | txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE); |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 504 | |
| 505 | if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 506 | INIT_INI_ARRAY(&ah->iniModesTxGain, |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 507 | ar9280Modes_high_power_tx_gain_9280_2, |
| 508 | ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 6); |
| 509 | else |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 510 | INIT_INI_ARRAY(&ah->iniModesTxGain, |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 511 | ar9280Modes_original_tx_gain_9280_2, |
| 512 | ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6); |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 513 | } else { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 514 | INIT_INI_ARRAY(&ah->iniModesTxGain, |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 515 | ar9280Modes_original_tx_gain_9280_2, |
| 516 | ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6); |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 517 | } |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 518 | } |
| 519 | |
Luis R. Rodriguez | f637cfd | 2009-08-03 12:24:46 -0700 | [diff] [blame] | 520 | static int ath9k_hw_post_init(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 521 | { |
| 522 | int ecode; |
| 523 | |
Sujith | 527d485 | 2010-03-17 14:25:16 +0530 | [diff] [blame] | 524 | if (!AR_SREV_9271(ah)) { |
| 525 | if (!ath9k_hw_chip_test(ah)) |
| 526 | return -ENODEV; |
| 527 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 528 | |
| 529 | ecode = ath9k_hw_rf_claim(ah); |
| 530 | if (ecode != 0) |
| 531 | return ecode; |
| 532 | |
Luis R. Rodriguez | f637cfd | 2009-08-03 12:24:46 -0700 | [diff] [blame] | 533 | ecode = ath9k_hw_eeprom_init(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 534 | if (ecode != 0) |
| 535 | return ecode; |
Sujith | 7d01b22 | 2009-03-13 08:55:55 +0530 | [diff] [blame] | 536 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 537 | ath_print(ath9k_hw_common(ah), ATH_DBG_CONFIG, |
| 538 | "Eeprom VER: %d, REV: %d\n", |
| 539 | ah->eep_ops->get_eeprom_ver(ah), |
| 540 | ah->eep_ops->get_eeprom_rev(ah)); |
Sujith | 7d01b22 | 2009-03-13 08:55:55 +0530 | [diff] [blame] | 541 | |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 542 | ecode = ath9k_hw_rf_alloc_ext_banks(ah); |
| 543 | if (ecode) { |
| 544 | ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL, |
| 545 | "Failed allocating banks for " |
| 546 | "external radio\n"); |
| 547 | return ecode; |
Luis R. Rodriguez | 574d6b1 | 2009-10-19 02:33:37 -0400 | [diff] [blame] | 548 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 549 | |
| 550 | if (!AR_SREV_9100(ah)) { |
| 551 | ath9k_hw_ani_setup(ah); |
Luis R. Rodriguez | f637cfd | 2009-08-03 12:24:46 -0700 | [diff] [blame] | 552 | ath9k_hw_ani_init(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 553 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 554 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 555 | return 0; |
| 556 | } |
| 557 | |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 558 | static bool ar9002_hw_macversion_supported(u32 macversion) |
Luis R. Rodriguez | f9d4a66 | 2009-08-03 12:24:41 -0700 | [diff] [blame] | 559 | { |
| 560 | switch (macversion) { |
| 561 | case AR_SREV_VERSION_5416_PCI: |
| 562 | case AR_SREV_VERSION_5416_PCIE: |
| 563 | case AR_SREV_VERSION_9160: |
| 564 | case AR_SREV_VERSION_9100: |
| 565 | case AR_SREV_VERSION_9280: |
| 566 | case AR_SREV_VERSION_9285: |
| 567 | case AR_SREV_VERSION_9287: |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 568 | case AR_SREV_VERSION_9271: |
Luis R. Rodriguez | 7976b42 | 2009-09-23 23:07:02 -0400 | [diff] [blame] | 569 | return true; |
Luis R. Rodriguez | f9d4a66 | 2009-08-03 12:24:41 -0700 | [diff] [blame] | 570 | default: |
| 571 | break; |
| 572 | } |
| 573 | return false; |
| 574 | } |
| 575 | |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 576 | static void ar9002_hw_init_cal_settings(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 577 | { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 578 | if (AR_SREV_9160_10_OR_LATER(ah)) { |
| 579 | if (AR_SREV_9280_10_OR_LATER(ah)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 580 | ah->iq_caldata.calData = &iq_cal_single_sample; |
| 581 | ah->adcgain_caldata.calData = |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 582 | &adc_gain_cal_single_sample; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 583 | ah->adcdc_caldata.calData = |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 584 | &adc_dc_cal_single_sample; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 585 | ah->adcdc_calinitdata.calData = |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 586 | &adc_init_dc_cal; |
| 587 | } else { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 588 | ah->iq_caldata.calData = &iq_cal_multi_sample; |
| 589 | ah->adcgain_caldata.calData = |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 590 | &adc_gain_cal_multi_sample; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 591 | ah->adcdc_caldata.calData = |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 592 | &adc_dc_cal_multi_sample; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 593 | ah->adcdc_calinitdata.calData = |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 594 | &adc_init_dc_cal; |
| 595 | } |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 596 | ah->supp_cals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 597 | } |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 598 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 599 | |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 600 | static void ar9002_hw_init_mode_regs(struct ath_hw *ah) |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 601 | { |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 602 | if (AR_SREV_9271(ah)) { |
Luis R. Rodriguez | 8564328 | 2009-10-19 02:33:33 -0400 | [diff] [blame] | 603 | INIT_INI_ARRAY(&ah->iniModes, ar9271Modes_9271, |
| 604 | ARRAY_SIZE(ar9271Modes_9271), 6); |
| 605 | INIT_INI_ARRAY(&ah->iniCommon, ar9271Common_9271, |
| 606 | ARRAY_SIZE(ar9271Common_9271), 2); |
Sujith | 70807e9 | 2010-03-17 14:25:14 +0530 | [diff] [blame] | 607 | INIT_INI_ARRAY(&ah->iniCommon_normal_cck_fir_coeff_9271, |
| 608 | ar9271Common_normal_cck_fir_coeff_9271, |
| 609 | ARRAY_SIZE(ar9271Common_normal_cck_fir_coeff_9271), 2); |
| 610 | INIT_INI_ARRAY(&ah->iniCommon_japan_2484_cck_fir_coeff_9271, |
| 611 | ar9271Common_japan_2484_cck_fir_coeff_9271, |
| 612 | ARRAY_SIZE(ar9271Common_japan_2484_cck_fir_coeff_9271), 2); |
Luis R. Rodriguez | 8564328 | 2009-10-19 02:33:33 -0400 | [diff] [blame] | 613 | INIT_INI_ARRAY(&ah->iniModes_9271_1_0_only, |
| 614 | ar9271Modes_9271_1_0_only, |
| 615 | ARRAY_SIZE(ar9271Modes_9271_1_0_only), 6); |
Sujith | 70807e9 | 2010-03-17 14:25:14 +0530 | [diff] [blame] | 616 | INIT_INI_ARRAY(&ah->iniModes_9271_ANI_reg, ar9271Modes_9271_ANI_reg, |
| 617 | ARRAY_SIZE(ar9271Modes_9271_ANI_reg), 6); |
| 618 | INIT_INI_ARRAY(&ah->iniModes_high_power_tx_gain_9271, |
| 619 | ar9271Modes_high_power_tx_gain_9271, |
| 620 | ARRAY_SIZE(ar9271Modes_high_power_tx_gain_9271), 6); |
| 621 | INIT_INI_ARRAY(&ah->iniModes_normal_power_tx_gain_9271, |
| 622 | ar9271Modes_normal_power_tx_gain_9271, |
| 623 | ARRAY_SIZE(ar9271Modes_normal_power_tx_gain_9271), 6); |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 624 | return; |
| 625 | } |
| 626 | |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 627 | if (AR_SREV_9287_11_OR_LATER(ah)) { |
| 628 | INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_1, |
| 629 | ARRAY_SIZE(ar9287Modes_9287_1_1), 6); |
| 630 | INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_1, |
| 631 | ARRAY_SIZE(ar9287Common_9287_1_1), 2); |
| 632 | if (ah->config.pcie_clock_req) |
| 633 | INIT_INI_ARRAY(&ah->iniPcieSerdes, |
| 634 | ar9287PciePhy_clkreq_off_L1_9287_1_1, |
| 635 | ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_1), 2); |
| 636 | else |
| 637 | INIT_INI_ARRAY(&ah->iniPcieSerdes, |
| 638 | ar9287PciePhy_clkreq_always_on_L1_9287_1_1, |
| 639 | ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_1), |
| 640 | 2); |
| 641 | } else if (AR_SREV_9287_10_OR_LATER(ah)) { |
| 642 | INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_0, |
| 643 | ARRAY_SIZE(ar9287Modes_9287_1_0), 6); |
| 644 | INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_0, |
| 645 | ARRAY_SIZE(ar9287Common_9287_1_0), 2); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 646 | |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 647 | if (ah->config.pcie_clock_req) |
| 648 | INIT_INI_ARRAY(&ah->iniPcieSerdes, |
| 649 | ar9287PciePhy_clkreq_off_L1_9287_1_0, |
| 650 | ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_0), 2); |
| 651 | else |
| 652 | INIT_INI_ARRAY(&ah->iniPcieSerdes, |
| 653 | ar9287PciePhy_clkreq_always_on_L1_9287_1_0, |
| 654 | ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_0), |
| 655 | 2); |
| 656 | } else if (AR_SREV_9285_12_OR_LATER(ah)) { |
| 657 | |
Senthil Balasubramanian | 4e84516 | 2009-03-06 11:24:10 +0530 | [diff] [blame] | 658 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 659 | INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 660 | ARRAY_SIZE(ar9285Modes_9285_1_2), 6); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 661 | INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 662 | ARRAY_SIZE(ar9285Common_9285_1_2), 2); |
| 663 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 664 | if (ah->config.pcie_clock_req) { |
| 665 | INIT_INI_ARRAY(&ah->iniPcieSerdes, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 666 | ar9285PciePhy_clkreq_off_L1_9285_1_2, |
| 667 | ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2); |
| 668 | } else { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 669 | INIT_INI_ARRAY(&ah->iniPcieSerdes, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 670 | ar9285PciePhy_clkreq_always_on_L1_9285_1_2, |
| 671 | ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2), |
| 672 | 2); |
| 673 | } |
| 674 | } else if (AR_SREV_9285_10_OR_LATER(ah)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 675 | INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 676 | ARRAY_SIZE(ar9285Modes_9285), 6); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 677 | INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 678 | ARRAY_SIZE(ar9285Common_9285), 2); |
| 679 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 680 | if (ah->config.pcie_clock_req) { |
| 681 | INIT_INI_ARRAY(&ah->iniPcieSerdes, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 682 | ar9285PciePhy_clkreq_off_L1_9285, |
| 683 | ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2); |
| 684 | } else { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 685 | INIT_INI_ARRAY(&ah->iniPcieSerdes, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 686 | ar9285PciePhy_clkreq_always_on_L1_9285, |
| 687 | ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285), 2); |
| 688 | } |
| 689 | } else if (AR_SREV_9280_20_OR_LATER(ah)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 690 | INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 691 | ARRAY_SIZE(ar9280Modes_9280_2), 6); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 692 | INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 693 | ARRAY_SIZE(ar9280Common_9280_2), 2); |
| 694 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 695 | if (ah->config.pcie_clock_req) { |
| 696 | INIT_INI_ARRAY(&ah->iniPcieSerdes, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 697 | ar9280PciePhy_clkreq_off_L1_9280, |
| 698 | ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 699 | } else { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 700 | INIT_INI_ARRAY(&ah->iniPcieSerdes, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 701 | ar9280PciePhy_clkreq_always_on_L1_9280, |
| 702 | ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 703 | } |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 704 | INIT_INI_ARRAY(&ah->iniModesAdditional, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 705 | ar9280Modes_fast_clock_9280_2, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 706 | ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 707 | } else if (AR_SREV_9280_10_OR_LATER(ah)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 708 | INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 709 | ARRAY_SIZE(ar9280Modes_9280), 6); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 710 | INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 711 | ARRAY_SIZE(ar9280Common_9280), 2); |
| 712 | } else if (AR_SREV_9160_10_OR_LATER(ah)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 713 | INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 714 | ARRAY_SIZE(ar5416Modes_9160), 6); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 715 | INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 716 | ARRAY_SIZE(ar5416Common_9160), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 717 | INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9160, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 718 | ARRAY_SIZE(ar5416Bank0_9160), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 719 | INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9160, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 720 | ARRAY_SIZE(ar5416BB_RfGain_9160), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 721 | INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9160, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 722 | ARRAY_SIZE(ar5416Bank1_9160), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 723 | INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9160, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 724 | ARRAY_SIZE(ar5416Bank2_9160), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 725 | INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9160, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 726 | ARRAY_SIZE(ar5416Bank3_9160), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 727 | INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9160, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 728 | ARRAY_SIZE(ar5416Bank6_9160), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 729 | INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9160, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 730 | ARRAY_SIZE(ar5416Bank6TPC_9160), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 731 | INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9160, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 732 | ARRAY_SIZE(ar5416Bank7_9160), 2); |
| 733 | if (AR_SREV_9160_11(ah)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 734 | INIT_INI_ARRAY(&ah->iniAddac, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 735 | ar5416Addac_91601_1, |
| 736 | ARRAY_SIZE(ar5416Addac_91601_1), 2); |
| 737 | } else { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 738 | INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 739 | ARRAY_SIZE(ar5416Addac_9160), 2); |
| 740 | } |
| 741 | } else if (AR_SREV_9100_OR_LATER(ah)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 742 | INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 743 | ARRAY_SIZE(ar5416Modes_9100), 6); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 744 | INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 745 | ARRAY_SIZE(ar5416Common_9100), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 746 | INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9100, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 747 | ARRAY_SIZE(ar5416Bank0_9100), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 748 | INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9100, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 749 | ARRAY_SIZE(ar5416BB_RfGain_9100), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 750 | INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9100, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 751 | ARRAY_SIZE(ar5416Bank1_9100), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 752 | INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9100, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 753 | ARRAY_SIZE(ar5416Bank2_9100), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 754 | INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9100, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 755 | ARRAY_SIZE(ar5416Bank3_9100), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 756 | INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9100, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 757 | ARRAY_SIZE(ar5416Bank6_9100), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 758 | INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9100, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 759 | ARRAY_SIZE(ar5416Bank6TPC_9100), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 760 | INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9100, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 761 | ARRAY_SIZE(ar5416Bank7_9100), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 762 | INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 763 | ARRAY_SIZE(ar5416Addac_9100), 2); |
| 764 | } else { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 765 | INIT_INI_ARRAY(&ah->iniModes, ar5416Modes, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 766 | ARRAY_SIZE(ar5416Modes), 6); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 767 | INIT_INI_ARRAY(&ah->iniCommon, ar5416Common, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 768 | ARRAY_SIZE(ar5416Common), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 769 | INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 770 | ARRAY_SIZE(ar5416Bank0), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 771 | INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 772 | ARRAY_SIZE(ar5416BB_RfGain), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 773 | INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 774 | ARRAY_SIZE(ar5416Bank1), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 775 | INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 776 | ARRAY_SIZE(ar5416Bank2), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 777 | INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 778 | ARRAY_SIZE(ar5416Bank3), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 779 | INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 780 | ARRAY_SIZE(ar5416Bank6), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 781 | INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 782 | ARRAY_SIZE(ar5416Bank6TPC), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 783 | INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 784 | ARRAY_SIZE(ar5416Bank7), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 785 | INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 786 | ARRAY_SIZE(ar5416Addac), 2); |
| 787 | } |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 788 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 789 | |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 790 | static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah) |
| 791 | { |
Vivek Natarajan | b37fa87 | 2009-09-23 16:27:27 +0530 | [diff] [blame] | 792 | if (AR_SREV_9287_11_OR_LATER(ah)) |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 793 | INIT_INI_ARRAY(&ah->iniModesRxGain, |
| 794 | ar9287Modes_rx_gain_9287_1_1, |
| 795 | ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_1), 6); |
| 796 | else if (AR_SREV_9287_10(ah)) |
| 797 | INIT_INI_ARRAY(&ah->iniModesRxGain, |
| 798 | ar9287Modes_rx_gain_9287_1_0, |
| 799 | ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_0), 6); |
| 800 | else if (AR_SREV_9280_20(ah)) |
| 801 | ath9k_hw_init_rxgain_ini(ah); |
| 802 | |
Vivek Natarajan | b37fa87 | 2009-09-23 16:27:27 +0530 | [diff] [blame] | 803 | if (AR_SREV_9287_11_OR_LATER(ah)) { |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 804 | INIT_INI_ARRAY(&ah->iniModesTxGain, |
| 805 | ar9287Modes_tx_gain_9287_1_1, |
| 806 | ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_1), 6); |
| 807 | } else if (AR_SREV_9287_10(ah)) { |
| 808 | INIT_INI_ARRAY(&ah->iniModesTxGain, |
| 809 | ar9287Modes_tx_gain_9287_1_0, |
| 810 | ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_0), 6); |
| 811 | } else if (AR_SREV_9280_20(ah)) { |
| 812 | ath9k_hw_init_txgain_ini(ah); |
| 813 | } else if (AR_SREV_9285_12_OR_LATER(ah)) { |
Senthil Balasubramanian | 4e84516 | 2009-03-06 11:24:10 +0530 | [diff] [blame] | 814 | u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE); |
| 815 | |
| 816 | /* txgain table */ |
| 817 | if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) { |
Vivek Natarajan | 53bc7aa | 2010-04-05 14:48:04 +0530 | [diff] [blame] | 818 | if (AR_SREV_9285E_20(ah)) { |
| 819 | INIT_INI_ARRAY(&ah->iniModesTxGain, |
| 820 | ar9285Modes_XE2_0_high_power, |
| 821 | ARRAY_SIZE( |
| 822 | ar9285Modes_XE2_0_high_power), 6); |
| 823 | } else { |
| 824 | INIT_INI_ARRAY(&ah->iniModesTxGain, |
| 825 | ar9285Modes_high_power_tx_gain_9285_1_2, |
| 826 | ARRAY_SIZE( |
| 827 | ar9285Modes_high_power_tx_gain_9285_1_2), 6); |
| 828 | } |
Senthil Balasubramanian | 4e84516 | 2009-03-06 11:24:10 +0530 | [diff] [blame] | 829 | } else { |
Vivek Natarajan | 53bc7aa | 2010-04-05 14:48:04 +0530 | [diff] [blame] | 830 | if (AR_SREV_9285E_20(ah)) { |
| 831 | INIT_INI_ARRAY(&ah->iniModesTxGain, |
| 832 | ar9285Modes_XE2_0_normal_power, |
| 833 | ARRAY_SIZE( |
| 834 | ar9285Modes_XE2_0_normal_power), 6); |
| 835 | } else { |
| 836 | INIT_INI_ARRAY(&ah->iniModesTxGain, |
| 837 | ar9285Modes_original_tx_gain_9285_1_2, |
| 838 | ARRAY_SIZE( |
| 839 | ar9285Modes_original_tx_gain_9285_1_2), 6); |
| 840 | } |
Senthil Balasubramanian | 4e84516 | 2009-03-06 11:24:10 +0530 | [diff] [blame] | 841 | } |
Senthil Balasubramanian | 4e84516 | 2009-03-06 11:24:10 +0530 | [diff] [blame] | 842 | } |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 843 | } |
Senthil Balasubramanian | 4e84516 | 2009-03-06 11:24:10 +0530 | [diff] [blame] | 844 | |
Felix Fietkau | aa8bc9e | 2010-01-23 20:04:18 +0100 | [diff] [blame] | 845 | static void ath9k_hw_init_eeprom_fix(struct ath_hw *ah) |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 846 | { |
Pavel Roskin | 2eb46d9 | 2010-04-07 01:33:33 -0400 | [diff] [blame] | 847 | struct base_eep_header *pBase = &(ah->eeprom.def.baseEepHeader); |
| 848 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | 06d0f06 | 2009-02-12 10:06:45 +0530 | [diff] [blame] | 849 | |
Pavel Roskin | 2eb46d9 | 2010-04-07 01:33:33 -0400 | [diff] [blame] | 850 | ah->need_an_top2_fixup = (ah->hw_version.devid == AR9280_DEVID_PCI) && |
| 851 | (ah->eep_map != EEP_MAP_4KBITS) && |
| 852 | ((pBase->version & 0xff) > 0x0a) && |
| 853 | (pBase->pwdclkind == 0); |
Sujith | 06d0f06 | 2009-02-12 10:06:45 +0530 | [diff] [blame] | 854 | |
Pavel Roskin | 2eb46d9 | 2010-04-07 01:33:33 -0400 | [diff] [blame] | 855 | if (ah->need_an_top2_fixup) |
| 856 | ath_print(common, ATH_DBG_EEPROM, |
| 857 | "needs fixup for AR_AN_TOP2 register\n"); |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 858 | } |
| 859 | |
Luis R. Rodriguez | 8525f28 | 2010-04-15 17:38:19 -0400 | [diff] [blame] | 860 | static void ath9k_hw_attach_ops(struct ath_hw *ah) |
| 861 | { |
| 862 | if (AR_SREV_9300_20_OR_LATER(ah)) |
| 863 | ar9003_hw_attach_ops(ah); |
| 864 | else |
| 865 | ar9002_hw_attach_ops(ah); |
| 866 | } |
| 867 | |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 868 | /* Called for all hardware families */ |
| 869 | static int __ath9k_hw_init(struct ath_hw *ah) |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 870 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 871 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | 95fafca | 2009-08-03 12:24:54 -0700 | [diff] [blame] | 872 | int r = 0; |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 873 | |
Luis R. Rodriguez | bab1f62 | 2010-04-15 17:38:20 -0400 | [diff] [blame^] | 874 | if (ah->hw_version.devid == AR5416_AR9100_DEVID) |
| 875 | ah->hw_version.macVersion = AR_SREV_VERSION_9100; |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 876 | |
| 877 | if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 878 | ath_print(common, ATH_DBG_FATAL, |
| 879 | "Couldn't reset chip\n"); |
Luis R. Rodriguez | 95fafca | 2009-08-03 12:24:54 -0700 | [diff] [blame] | 880 | return -EIO; |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 881 | } |
| 882 | |
Luis R. Rodriguez | bab1f62 | 2010-04-15 17:38:20 -0400 | [diff] [blame^] | 883 | ath9k_hw_init_defaults(ah); |
| 884 | ath9k_hw_init_config(ah); |
| 885 | |
Luis R. Rodriguez | 8525f28 | 2010-04-15 17:38:19 -0400 | [diff] [blame] | 886 | ath9k_hw_attach_ops(ah); |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 887 | |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 888 | if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 889 | ath_print(common, ATH_DBG_FATAL, "Couldn't wakeup chip\n"); |
Luis R. Rodriguez | 95fafca | 2009-08-03 12:24:54 -0700 | [diff] [blame] | 890 | return -EIO; |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) { |
| 894 | if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI || |
| 895 | (AR_SREV_9280(ah) && !ah->is_pciexpress)) { |
| 896 | ah->config.serialize_regmode = |
| 897 | SER_REG_MODE_ON; |
| 898 | } else { |
| 899 | ah->config.serialize_regmode = |
| 900 | SER_REG_MODE_OFF; |
| 901 | } |
| 902 | } |
| 903 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 904 | ath_print(common, ATH_DBG_RESET, "serialize_regmode is %d\n", |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 905 | ah->config.serialize_regmode); |
| 906 | |
Luis R. Rodriguez | f4709fd | 2009-11-24 21:37:57 -0500 | [diff] [blame] | 907 | if (AR_SREV_9285(ah) || AR_SREV_9271(ah)) |
| 908 | ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD >> 1; |
| 909 | else |
| 910 | ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD; |
| 911 | |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 912 | if (!ath9k_hw_macversion_supported(ah)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 913 | ath_print(common, ATH_DBG_FATAL, |
| 914 | "Mac Chip Rev 0x%02x.%x is not supported by " |
| 915 | "this driver\n", ah->hw_version.macVersion, |
| 916 | ah->hw_version.macRev); |
Luis R. Rodriguez | 95fafca | 2009-08-03 12:24:54 -0700 | [diff] [blame] | 917 | return -EOPNOTSUPP; |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | if (AR_SREV_9100(ah)) { |
| 921 | ah->iq_caldata.calData = &iq_cal_multi_sample; |
| 922 | ah->supp_cals = IQ_MISMATCH_CAL; |
| 923 | ah->is_pciexpress = false; |
| 924 | } |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 925 | |
| 926 | if (AR_SREV_9271(ah)) |
| 927 | ah->is_pciexpress = false; |
| 928 | |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 929 | ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID); |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 930 | ath9k_hw_init_cal_settings(ah); |
| 931 | |
| 932 | ah->ani_function = ATH9K_ANI_ALL; |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 933 | if (AR_SREV_9280_10_OR_LATER(ah)) |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 934 | ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL; |
| 935 | |
| 936 | ath9k_hw_init_mode_regs(ah); |
| 937 | |
| 938 | if (ah->is_pciexpress) |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 939 | ath9k_hw_configpcipowersave(ah, 0, 0); |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 940 | else |
| 941 | ath9k_hw_disablepcie(ah); |
| 942 | |
Sujith | 193cd45 | 2009-09-18 15:04:07 +0530 | [diff] [blame] | 943 | /* Support for Japan ch.14 (2484) spread */ |
| 944 | if (AR_SREV_9287_11_OR_LATER(ah)) { |
| 945 | INIT_INI_ARRAY(&ah->iniCckfirNormal, |
| 946 | ar9287Common_normal_cck_fir_coeff_92871_1, |
| 947 | ARRAY_SIZE(ar9287Common_normal_cck_fir_coeff_92871_1), 2); |
| 948 | INIT_INI_ARRAY(&ah->iniCckfirJapan2484, |
| 949 | ar9287Common_japan_2484_cck_fir_coeff_92871_1, |
| 950 | ARRAY_SIZE(ar9287Common_japan_2484_cck_fir_coeff_92871_1), 2); |
| 951 | } |
| 952 | |
Luis R. Rodriguez | f637cfd | 2009-08-03 12:24:46 -0700 | [diff] [blame] | 953 | r = ath9k_hw_post_init(ah); |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 954 | if (r) |
Luis R. Rodriguez | 95fafca | 2009-08-03 12:24:54 -0700 | [diff] [blame] | 955 | return r; |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 956 | |
| 957 | ath9k_hw_init_mode_gain_regs(ah); |
Gabor Juhos | a9a29ce | 2009-11-27 12:01:35 +0100 | [diff] [blame] | 958 | r = ath9k_hw_fill_cap_info(ah); |
| 959 | if (r) |
| 960 | return r; |
| 961 | |
Felix Fietkau | aa8bc9e | 2010-01-23 20:04:18 +0100 | [diff] [blame] | 962 | ath9k_hw_init_eeprom_fix(ah); |
Sujith | f6688cd | 2008-12-07 21:43:10 +0530 | [diff] [blame] | 963 | |
Luis R. Rodriguez | 4f3acf8 | 2009-08-03 12:24:36 -0700 | [diff] [blame] | 964 | r = ath9k_hw_init_macaddr(ah); |
| 965 | if (r) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 966 | ath_print(common, ATH_DBG_FATAL, |
| 967 | "Failed to initialize MAC address\n"); |
Luis R. Rodriguez | 95fafca | 2009-08-03 12:24:54 -0700 | [diff] [blame] | 968 | return r; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 969 | } |
| 970 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 971 | if (AR_SREV_9285(ah) || AR_SREV_9271(ah)) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 972 | ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 973 | else |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 974 | ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 975 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 976 | ath9k_init_nfcal_hist_buffer(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 977 | |
Luis R. Rodriguez | 211f585 | 2009-10-06 21:19:07 -0400 | [diff] [blame] | 978 | common->state = ATH_HW_INITIALIZED; |
| 979 | |
Luis R. Rodriguez | 4f3acf8 | 2009-08-03 12:24:36 -0700 | [diff] [blame] | 980 | return 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 981 | } |
| 982 | |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 983 | int ath9k_hw_init(struct ath_hw *ah) |
| 984 | { |
| 985 | int ret; |
| 986 | struct ath_common *common = ath9k_hw_common(ah); |
| 987 | |
| 988 | /* These are all the AR5008/AR9001/AR9002 hardware family of chipsets */ |
| 989 | switch (ah->hw_version.devid) { |
| 990 | case AR5416_DEVID_PCI: |
| 991 | case AR5416_DEVID_PCIE: |
| 992 | case AR5416_AR9100_DEVID: |
| 993 | case AR9160_DEVID_PCI: |
| 994 | case AR9280_DEVID_PCI: |
| 995 | case AR9280_DEVID_PCIE: |
| 996 | case AR9285_DEVID_PCIE: |
Senthil Balasubramanian | db3cc53 | 2010-04-15 17:38:18 -0400 | [diff] [blame] | 997 | case AR9287_DEVID_PCI: |
| 998 | case AR9287_DEVID_PCIE: |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 999 | case AR2427_DEVID_PCIE: |
Senthil Balasubramanian | db3cc53 | 2010-04-15 17:38:18 -0400 | [diff] [blame] | 1000 | case AR9300_DEVID_PCIE: |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 1001 | break; |
| 1002 | default: |
| 1003 | if (common->bus_ops->ath_bus_type == ATH_USB) |
| 1004 | break; |
| 1005 | ath_print(common, ATH_DBG_FATAL, |
| 1006 | "Hardware device ID 0x%04x not supported\n", |
| 1007 | ah->hw_version.devid); |
| 1008 | return -EOPNOTSUPP; |
| 1009 | } |
| 1010 | |
| 1011 | ret = __ath9k_hw_init(ah); |
| 1012 | if (ret) { |
| 1013 | ath_print(common, ATH_DBG_FATAL, |
| 1014 | "Unable to initialize hardware; " |
| 1015 | "initialization status: %d\n", ret); |
| 1016 | return ret; |
| 1017 | } |
| 1018 | |
| 1019 | return 0; |
| 1020 | } |
| 1021 | EXPORT_SYMBOL(ath9k_hw_init); |
| 1022 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1023 | static void ath9k_hw_init_qos(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1024 | { |
| 1025 | REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa); |
| 1026 | REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210); |
| 1027 | |
| 1028 | REG_WRITE(ah, AR_QOS_NO_ACK, |
| 1029 | SM(2, AR_QOS_NO_ACK_TWO_BIT) | |
| 1030 | SM(5, AR_QOS_NO_ACK_BIT_OFF) | |
| 1031 | SM(0, AR_QOS_NO_ACK_BYTE_OFF)); |
| 1032 | |
| 1033 | REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL); |
| 1034 | REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF); |
| 1035 | REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF); |
| 1036 | REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF); |
| 1037 | REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF); |
| 1038 | } |
| 1039 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1040 | static void ath9k_hw_init_pll(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1041 | struct ath9k_channel *chan) |
| 1042 | { |
Luis R. Rodriguez | 6477396 | 2010-04-15 17:38:17 -0400 | [diff] [blame] | 1043 | u32 pll = ath9k_hw_compute_pll_control(ah, chan); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1044 | |
Gabor Juhos | d03a66c | 2009-01-14 20:17:09 +0100 | [diff] [blame] | 1045 | REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1046 | |
Luis R. Rodriguez | c75724d | 2009-10-19 02:33:34 -0400 | [diff] [blame] | 1047 | /* Switch the core clock for ar9271 to 117Mhz */ |
| 1048 | if (AR_SREV_9271(ah)) { |
Sujith | 25e2ab1 | 2010-03-17 14:25:22 +0530 | [diff] [blame] | 1049 | udelay(500); |
| 1050 | REG_WRITE(ah, 0x50040, 0x304); |
Luis R. Rodriguez | c75724d | 2009-10-19 02:33:34 -0400 | [diff] [blame] | 1051 | } |
| 1052 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1053 | udelay(RTC_PLL_SETTLE_DELAY); |
| 1054 | |
| 1055 | REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK); |
| 1056 | } |
| 1057 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1058 | static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah, |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 1059 | enum nl80211_iftype opmode) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1060 | { |
Pavel Roskin | 152d530 | 2010-03-31 18:05:37 -0400 | [diff] [blame] | 1061 | u32 imr_reg = AR_IMR_TXERR | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1062 | AR_IMR_TXURN | |
| 1063 | AR_IMR_RXERR | |
| 1064 | AR_IMR_RXORN | |
| 1065 | AR_IMR_BCNMISC; |
| 1066 | |
Sujith | 0ce024c | 2009-12-14 14:57:00 +0530 | [diff] [blame] | 1067 | if (ah->config.rx_intr_mitigation) |
Pavel Roskin | 152d530 | 2010-03-31 18:05:37 -0400 | [diff] [blame] | 1068 | imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1069 | else |
Pavel Roskin | 152d530 | 2010-03-31 18:05:37 -0400 | [diff] [blame] | 1070 | imr_reg |= AR_IMR_RXOK; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1071 | |
Pavel Roskin | 152d530 | 2010-03-31 18:05:37 -0400 | [diff] [blame] | 1072 | imr_reg |= AR_IMR_TXOK; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1073 | |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 1074 | if (opmode == NL80211_IFTYPE_AP) |
Pavel Roskin | 152d530 | 2010-03-31 18:05:37 -0400 | [diff] [blame] | 1075 | imr_reg |= AR_IMR_MIB; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1076 | |
Pavel Roskin | 152d530 | 2010-03-31 18:05:37 -0400 | [diff] [blame] | 1077 | REG_WRITE(ah, AR_IMR, imr_reg); |
Pavel Roskin | 74bad5c | 2010-02-23 18:15:27 -0500 | [diff] [blame] | 1078 | ah->imrs2_reg |= AR_IMR_S2_GTT; |
| 1079 | REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1080 | |
| 1081 | if (!AR_SREV_9100(ah)) { |
| 1082 | REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF); |
| 1083 | REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT); |
| 1084 | REG_WRITE(ah, AR_INTR_SYNC_MASK, 0); |
| 1085 | } |
| 1086 | } |
| 1087 | |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 1088 | static void ath9k_hw_setslottime(struct ath_hw *ah, u32 us) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1089 | { |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 1090 | u32 val = ath9k_hw_mac_to_clks(ah, us); |
| 1091 | val = min(val, (u32) 0xFFFF); |
| 1092 | REG_WRITE(ah, AR_D_GBL_IFS_SLOT, val); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1093 | } |
| 1094 | |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 1095 | static void ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1096 | { |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 1097 | u32 val = ath9k_hw_mac_to_clks(ah, us); |
| 1098 | val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_ACK)); |
| 1099 | REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_ACK, val); |
| 1100 | } |
| 1101 | |
| 1102 | static void ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us) |
| 1103 | { |
| 1104 | u32 val = ath9k_hw_mac_to_clks(ah, us); |
| 1105 | val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_CTS)); |
| 1106 | REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_CTS, val); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1107 | } |
| 1108 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1109 | static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1110 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1111 | if (tu > 0xFFFF) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1112 | ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT, |
| 1113 | "bad global tx timeout %u\n", tu); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1114 | ah->globaltxtimeout = (u32) -1; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1115 | return false; |
| 1116 | } else { |
| 1117 | REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1118 | ah->globaltxtimeout = tu; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1119 | return true; |
| 1120 | } |
| 1121 | } |
| 1122 | |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 1123 | void ath9k_hw_init_global_settings(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1124 | { |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 1125 | struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf; |
| 1126 | int acktimeout; |
Felix Fietkau | e239d85 | 2010-01-15 02:34:58 +0100 | [diff] [blame] | 1127 | int slottime; |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 1128 | int sifstime; |
| 1129 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1130 | ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, "ah->misc_mode 0x%x\n", |
| 1131 | ah->misc_mode); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1132 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1133 | if (ah->misc_mode != 0) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1134 | REG_WRITE(ah, AR_PCU_MISC, |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1135 | REG_READ(ah, AR_PCU_MISC) | ah->misc_mode); |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 1136 | |
| 1137 | if (conf->channel && conf->channel->band == IEEE80211_BAND_5GHZ) |
| 1138 | sifstime = 16; |
| 1139 | else |
| 1140 | sifstime = 10; |
| 1141 | |
Felix Fietkau | e239d85 | 2010-01-15 02:34:58 +0100 | [diff] [blame] | 1142 | /* As defined by IEEE 802.11-2007 17.3.8.6 */ |
| 1143 | slottime = ah->slottime + 3 * ah->coverage_class; |
| 1144 | acktimeout = slottime + sifstime; |
Felix Fietkau | 42c4568 | 2010-02-11 18:07:19 +0100 | [diff] [blame] | 1145 | |
| 1146 | /* |
| 1147 | * Workaround for early ACK timeouts, add an offset to match the |
| 1148 | * initval's 64us ack timeout value. |
| 1149 | * This was initially only meant to work around an issue with delayed |
| 1150 | * BA frames in some implementations, but it has been found to fix ACK |
| 1151 | * timeout issues in other cases as well. |
| 1152 | */ |
| 1153 | if (conf->channel && conf->channel->band == IEEE80211_BAND_2GHZ) |
| 1154 | acktimeout += 64 - sifstime - ah->slottime; |
| 1155 | |
Felix Fietkau | e239d85 | 2010-01-15 02:34:58 +0100 | [diff] [blame] | 1156 | ath9k_hw_setslottime(ah, slottime); |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 1157 | ath9k_hw_set_ack_timeout(ah, acktimeout); |
| 1158 | ath9k_hw_set_cts_timeout(ah, acktimeout); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1159 | if (ah->globaltxtimeout != (u32) -1) |
| 1160 | ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1161 | } |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 1162 | EXPORT_SYMBOL(ath9k_hw_init_global_settings); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1163 | |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 1164 | void ath9k_hw_deinit(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1165 | { |
Luis R. Rodriguez | 211f585 | 2009-10-06 21:19:07 -0400 | [diff] [blame] | 1166 | struct ath_common *common = ath9k_hw_common(ah); |
| 1167 | |
Sujith | 736b3a2 | 2010-03-17 14:25:24 +0530 | [diff] [blame] | 1168 | if (common->state < ATH_HW_INITIALIZED) |
Luis R. Rodriguez | 211f585 | 2009-10-06 21:19:07 -0400 | [diff] [blame] | 1169 | goto free_hw; |
| 1170 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1171 | if (!AR_SREV_9100(ah)) |
Luis R. Rodriguez | e70c0cf | 2009-08-03 12:24:51 -0700 | [diff] [blame] | 1172 | ath9k_hw_ani_disable(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1173 | |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 1174 | ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP); |
Luis R. Rodriguez | 211f585 | 2009-10-06 21:19:07 -0400 | [diff] [blame] | 1175 | |
| 1176 | free_hw: |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1177 | ath9k_hw_rf_free_ext_banks(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1178 | } |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 1179 | EXPORT_SYMBOL(ath9k_hw_deinit); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1180 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1181 | /*******/ |
| 1182 | /* INI */ |
| 1183 | /*******/ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1184 | |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1185 | 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] | 1186 | { |
| 1187 | u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band); |
| 1188 | |
| 1189 | if (IS_CHAN_B(chan)) |
| 1190 | ctl |= CTL_11B; |
| 1191 | else if (IS_CHAN_G(chan)) |
| 1192 | ctl |= CTL_11G; |
| 1193 | else |
| 1194 | ctl |= CTL_11A; |
| 1195 | |
| 1196 | return ctl; |
| 1197 | } |
| 1198 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1199 | /****************************************/ |
| 1200 | /* Reset and Channel Switching Routines */ |
| 1201 | /****************************************/ |
| 1202 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1203 | static inline void ath9k_hw_set_dma(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1204 | { |
| 1205 | u32 regval; |
| 1206 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1207 | /* |
| 1208 | * set AHB_MODE not to do cacheline prefetches |
| 1209 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1210 | regval = REG_READ(ah, AR_AHB_MODE); |
| 1211 | REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN); |
| 1212 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1213 | /* |
| 1214 | * let mac dma reads be in 128 byte chunks |
| 1215 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1216 | regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK; |
| 1217 | REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B); |
| 1218 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1219 | /* |
| 1220 | * Restore TX Trigger Level to its pre-reset value. |
| 1221 | * The initial value depends on whether aggregation is enabled, and is |
| 1222 | * adjusted whenever underruns are detected. |
| 1223 | */ |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1224 | REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1225 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1226 | /* |
| 1227 | * let mac dma writes be in 128 byte chunks |
| 1228 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1229 | regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK; |
| 1230 | REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B); |
| 1231 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1232 | /* |
| 1233 | * Setup receive FIFO threshold to hold off TX activities |
| 1234 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1235 | REG_WRITE(ah, AR_RXFIFO_CFG, 0x200); |
| 1236 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1237 | /* |
| 1238 | * reduce the number of usable entries in PCU TXBUF to avoid |
| 1239 | * wrap around issues. |
| 1240 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1241 | if (AR_SREV_9285(ah)) { |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1242 | /* For AR9285 the number of Fifos are reduced to half. |
| 1243 | * So set the usable tx buf size also to half to |
| 1244 | * avoid data/delimiter underruns |
| 1245 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1246 | REG_WRITE(ah, AR_PCU_TXBUF_CTRL, |
| 1247 | AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE); |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1248 | } else if (!AR_SREV_9271(ah)) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1249 | REG_WRITE(ah, AR_PCU_TXBUF_CTRL, |
| 1250 | AR_PCU_TXBUF_CTRL_USABLE_SIZE); |
| 1251 | } |
| 1252 | } |
| 1253 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1254 | static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1255 | { |
| 1256 | u32 val; |
| 1257 | |
| 1258 | val = REG_READ(ah, AR_STA_ID1); |
| 1259 | val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC); |
| 1260 | switch (opmode) { |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 1261 | case NL80211_IFTYPE_AP: |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1262 | REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP |
| 1263 | | AR_STA_ID1_KSRCH_MODE); |
| 1264 | REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION); |
| 1265 | break; |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 1266 | case NL80211_IFTYPE_ADHOC: |
Pat Erley | 9cb5412 | 2009-03-20 22:59:59 -0400 | [diff] [blame] | 1267 | case NL80211_IFTYPE_MESH_POINT: |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1268 | REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC |
| 1269 | | AR_STA_ID1_KSRCH_MODE); |
| 1270 | REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION); |
| 1271 | break; |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 1272 | case NL80211_IFTYPE_STATION: |
| 1273 | case NL80211_IFTYPE_MONITOR: |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1274 | REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE); |
| 1275 | break; |
| 1276 | } |
| 1277 | } |
| 1278 | |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1279 | void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled, |
| 1280 | u32 *coef_mantissa, u32 *coef_exponent) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1281 | { |
| 1282 | u32 coef_exp, coef_man; |
| 1283 | |
| 1284 | for (coef_exp = 31; coef_exp > 0; coef_exp--) |
| 1285 | if ((coef_scaled >> coef_exp) & 0x1) |
| 1286 | break; |
| 1287 | |
| 1288 | coef_exp = 14 - (coef_exp - COEF_SCALE_S); |
| 1289 | |
| 1290 | coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1)); |
| 1291 | |
| 1292 | *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp); |
| 1293 | *coef_exponent = coef_exp - 16; |
| 1294 | } |
| 1295 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1296 | static bool ath9k_hw_set_reset(struct ath_hw *ah, int type) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1297 | { |
| 1298 | u32 rst_flags; |
| 1299 | u32 tmpReg; |
| 1300 | |
Sujith | 7076849 | 2009-02-16 13:23:12 +0530 | [diff] [blame] | 1301 | if (AR_SREV_9100(ah)) { |
| 1302 | u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK); |
| 1303 | val &= ~AR_RTC_DERIVED_CLK_PERIOD; |
| 1304 | val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD); |
| 1305 | REG_WRITE(ah, AR_RTC_DERIVED_CLK, val); |
| 1306 | (void)REG_READ(ah, AR_RTC_DERIVED_CLK); |
| 1307 | } |
| 1308 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1309 | REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN | |
| 1310 | AR_RTC_FORCE_WAKE_ON_INT); |
| 1311 | |
| 1312 | if (AR_SREV_9100(ah)) { |
| 1313 | rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD | |
| 1314 | AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET; |
| 1315 | } else { |
| 1316 | tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE); |
| 1317 | if (tmpReg & |
| 1318 | (AR_INTR_SYNC_LOCAL_TIMEOUT | |
| 1319 | AR_INTR_SYNC_RADM_CPL_TIMEOUT)) { |
Luis R. Rodriguez | 42d5bc3 | 2010-04-15 17:38:12 -0400 | [diff] [blame] | 1320 | u32 val; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1321 | REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0); |
Luis R. Rodriguez | 42d5bc3 | 2010-04-15 17:38:12 -0400 | [diff] [blame] | 1322 | |
| 1323 | val = AR_RC_HOSTIF; |
| 1324 | if (!AR_SREV_9300_20_OR_LATER(ah)) |
| 1325 | val |= AR_RC_AHB; |
| 1326 | REG_WRITE(ah, AR_RC, val); |
| 1327 | |
| 1328 | } else if (!AR_SREV_9300_20_OR_LATER(ah)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1329 | REG_WRITE(ah, AR_RC, AR_RC_AHB); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1330 | |
| 1331 | rst_flags = AR_RTC_RC_MAC_WARM; |
| 1332 | if (type == ATH9K_RESET_COLD) |
| 1333 | rst_flags |= AR_RTC_RC_MAC_COLD; |
| 1334 | } |
| 1335 | |
Gabor Juhos | d03a66c | 2009-01-14 20:17:09 +0100 | [diff] [blame] | 1336 | REG_WRITE(ah, AR_RTC_RC, rst_flags); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1337 | udelay(50); |
| 1338 | |
Gabor Juhos | d03a66c | 2009-01-14 20:17:09 +0100 | [diff] [blame] | 1339 | REG_WRITE(ah, AR_RTC_RC, 0); |
Sujith | 0caa7b1 | 2009-02-16 13:23:20 +0530 | [diff] [blame] | 1340 | 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] | 1341 | ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, |
| 1342 | "RTC stuck in MAC reset\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1343 | return false; |
| 1344 | } |
| 1345 | |
| 1346 | if (!AR_SREV_9100(ah)) |
| 1347 | REG_WRITE(ah, AR_RC, 0); |
| 1348 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1349 | if (AR_SREV_9100(ah)) |
| 1350 | udelay(50); |
| 1351 | |
| 1352 | return true; |
| 1353 | } |
| 1354 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1355 | static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1356 | { |
| 1357 | REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN | |
| 1358 | AR_RTC_FORCE_WAKE_ON_INT); |
| 1359 | |
Luis R. Rodriguez | 42d5bc3 | 2010-04-15 17:38:12 -0400 | [diff] [blame] | 1360 | if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah)) |
Vasanthakumar Thiagarajan | 1c29ce6 | 2009-08-31 17:48:36 +0530 | [diff] [blame] | 1361 | REG_WRITE(ah, AR_RC, AR_RC_AHB); |
| 1362 | |
Gabor Juhos | d03a66c | 2009-01-14 20:17:09 +0100 | [diff] [blame] | 1363 | REG_WRITE(ah, AR_RTC_RESET, 0); |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 1364 | udelay(2); |
Vasanthakumar Thiagarajan | 1c29ce6 | 2009-08-31 17:48:36 +0530 | [diff] [blame] | 1365 | |
| 1366 | if (!AR_SREV_9100(ah)) |
| 1367 | REG_WRITE(ah, AR_RC, 0); |
| 1368 | |
Gabor Juhos | d03a66c | 2009-01-14 20:17:09 +0100 | [diff] [blame] | 1369 | REG_WRITE(ah, AR_RTC_RESET, 1); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1370 | |
| 1371 | if (!ath9k_hw_wait(ah, |
| 1372 | AR_RTC_STATUS, |
| 1373 | AR_RTC_STATUS_M, |
Sujith | 0caa7b1 | 2009-02-16 13:23:20 +0530 | [diff] [blame] | 1374 | AR_RTC_STATUS_ON, |
| 1375 | AH_WAIT_TIMEOUT)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1376 | ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, |
| 1377 | "RTC not waking up\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1378 | return false; |
| 1379 | } |
| 1380 | |
| 1381 | ath9k_hw_read_revisions(ah); |
| 1382 | |
| 1383 | return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM); |
| 1384 | } |
| 1385 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1386 | static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1387 | { |
| 1388 | REG_WRITE(ah, AR_RTC_FORCE_WAKE, |
| 1389 | AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT); |
| 1390 | |
| 1391 | switch (type) { |
| 1392 | case ATH9K_RESET_POWER_ON: |
| 1393 | return ath9k_hw_set_reset_power_on(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1394 | case ATH9K_RESET_WARM: |
| 1395 | case ATH9K_RESET_COLD: |
| 1396 | return ath9k_hw_set_reset(ah, type); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1397 | default: |
| 1398 | return false; |
| 1399 | } |
| 1400 | } |
| 1401 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1402 | static bool ath9k_hw_chip_reset(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1403 | struct ath9k_channel *chan) |
| 1404 | { |
Vivek Natarajan | 42abfbe | 2009-09-17 09:27:59 +0530 | [diff] [blame] | 1405 | 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] | 1406 | if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) |
| 1407 | return false; |
| 1408 | } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1409 | return false; |
| 1410 | |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 1411 | if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1412 | return false; |
| 1413 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1414 | ah->chip_fullsleep = false; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1415 | ath9k_hw_init_pll(ah, chan); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1416 | ath9k_hw_set_rfmode(ah, chan); |
| 1417 | |
| 1418 | return true; |
| 1419 | } |
| 1420 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1421 | static bool ath9k_hw_channel_change(struct ath_hw *ah, |
Luis R. Rodriguez | 25c56ee | 2009-09-13 23:04:44 -0700 | [diff] [blame] | 1422 | struct ath9k_channel *chan) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1423 | { |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 1424 | struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1425 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 1426 | struct ieee80211_channel *channel = chan->chan; |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1427 | u32 qnum; |
Luis R. Rodriguez | 0a3b7ba | 2009-10-19 02:33:40 -0400 | [diff] [blame] | 1428 | int r; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1429 | |
| 1430 | for (qnum = 0; qnum < AR_NUM_QCU; qnum++) { |
| 1431 | if (ath9k_hw_numtxpending(ah, qnum)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1432 | ath_print(common, ATH_DBG_QUEUE, |
| 1433 | "Transmit frames pending on " |
| 1434 | "queue %d\n", qnum); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1435 | return false; |
| 1436 | } |
| 1437 | } |
| 1438 | |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1439 | if (!ath9k_hw_rfbus_req(ah)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1440 | ath_print(common, ATH_DBG_FATAL, |
| 1441 | "Could not kill baseband RX\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1442 | return false; |
| 1443 | } |
| 1444 | |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1445 | ath9k_hw_set_channel_regs(ah, chan); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1446 | |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1447 | r = ath9k_hw_rf_set_freq(ah, chan); |
Luis R. Rodriguez | 0a3b7ba | 2009-10-19 02:33:40 -0400 | [diff] [blame] | 1448 | if (r) { |
| 1449 | ath_print(common, ATH_DBG_FATAL, |
| 1450 | "Failed to set channel\n"); |
| 1451 | return false; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1452 | } |
| 1453 | |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 1454 | ah->eep_ops->set_txpower(ah, chan, |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 1455 | ath9k_regd_get_ctl(regulatory, chan), |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1456 | channel->max_antenna_gain * 2, |
| 1457 | channel->max_power * 2, |
| 1458 | min((u32) MAX_RATE_POWER, |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 1459 | (u32) regulatory->power_limit)); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1460 | |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1461 | ath9k_hw_rfbus_done(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1462 | |
| 1463 | if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan)) |
| 1464 | ath9k_hw_set_delta_slope(ah, chan); |
| 1465 | |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1466 | ath9k_hw_spur_mitigate_freq(ah, chan); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1467 | |
| 1468 | if (!chan->oneTimeCalsDone) |
| 1469 | chan->oneTimeCalsDone = true; |
| 1470 | |
| 1471 | return true; |
| 1472 | } |
| 1473 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1474 | 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] | 1475 | bool bChannelChange) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1476 | { |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 1477 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1478 | u32 saveLedState; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1479 | struct ath9k_channel *curchan = ah->curchan; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1480 | u32 saveDefAntenna; |
| 1481 | u32 macStaId1; |
Sujith | 46fe782 | 2009-09-17 09:25:25 +0530 | [diff] [blame] | 1482 | u64 tsf = 0; |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1483 | int i, r; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1484 | |
Luis R. Rodriguez | 43c2761 | 2009-09-13 21:07:07 -0700 | [diff] [blame] | 1485 | ah->txchainmask = common->tx_chainmask; |
| 1486 | ah->rxchainmask = common->rx_chainmask; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1487 | |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 1488 | if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 1489 | return -EIO; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1490 | |
Vasanthakumar Thiagarajan | 9ebef799 | 2009-09-17 09:26:44 +0530 | [diff] [blame] | 1491 | if (curchan && !ah->chip_fullsleep) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1492 | ath9k_hw_getnf(ah, curchan); |
| 1493 | |
| 1494 | if (bChannelChange && |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1495 | (ah->chip_fullsleep != true) && |
| 1496 | (ah->curchan != NULL) && |
| 1497 | (chan->channel != ah->curchan->channel) && |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1498 | ((chan->channelFlags & CHANNEL_ALL) == |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1499 | (ah->curchan->channelFlags & CHANNEL_ALL)) && |
Vasanthakumar Thiagarajan | 0a475cc | 2009-09-17 09:27:10 +0530 | [diff] [blame] | 1500 | !(AR_SREV_9280(ah) || IS_CHAN_A_5MHZ_SPACED(chan) || |
| 1501 | IS_CHAN_A_5MHZ_SPACED(ah->curchan))) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1502 | |
Luis R. Rodriguez | 25c56ee | 2009-09-13 23:04:44 -0700 | [diff] [blame] | 1503 | if (ath9k_hw_channel_change(ah, chan)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1504 | ath9k_hw_loadnf(ah, ah->curchan); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1505 | ath9k_hw_start_nfcal(ah); |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 1506 | return 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1507 | } |
| 1508 | } |
| 1509 | |
| 1510 | saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA); |
| 1511 | if (saveDefAntenna == 0) |
| 1512 | saveDefAntenna = 1; |
| 1513 | |
| 1514 | macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B; |
| 1515 | |
Sujith | 46fe782 | 2009-09-17 09:25:25 +0530 | [diff] [blame] | 1516 | /* For chips on which RTC reset is done, save TSF before it gets cleared */ |
| 1517 | if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) |
| 1518 | tsf = ath9k_hw_gettsf64(ah); |
| 1519 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1520 | saveLedState = REG_READ(ah, AR_CFG_LED) & |
| 1521 | (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL | |
| 1522 | AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW); |
| 1523 | |
| 1524 | ath9k_hw_mark_phy_inactive(ah); |
| 1525 | |
Sujith | 05020d2 | 2010-03-17 14:25:23 +0530 | [diff] [blame] | 1526 | /* Only required on the first reset */ |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1527 | if (AR_SREV_9271(ah) && ah->htc_reset_init) { |
| 1528 | REG_WRITE(ah, |
| 1529 | AR9271_RESET_POWER_DOWN_CONTROL, |
| 1530 | AR9271_RADIO_RF_RST); |
| 1531 | udelay(50); |
| 1532 | } |
| 1533 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1534 | if (!ath9k_hw_chip_reset(ah, chan)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1535 | ath_print(common, ATH_DBG_FATAL, "Chip reset failed\n"); |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 1536 | return -EINVAL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1537 | } |
| 1538 | |
Sujith | 05020d2 | 2010-03-17 14:25:23 +0530 | [diff] [blame] | 1539 | /* Only required on the first reset */ |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1540 | if (AR_SREV_9271(ah) && ah->htc_reset_init) { |
| 1541 | ah->htc_reset_init = false; |
| 1542 | REG_WRITE(ah, |
| 1543 | AR9271_RESET_POWER_DOWN_CONTROL, |
| 1544 | AR9271_GATE_MAC_CTL); |
| 1545 | udelay(50); |
| 1546 | } |
| 1547 | |
Sujith | 46fe782 | 2009-09-17 09:25:25 +0530 | [diff] [blame] | 1548 | /* Restore TSF */ |
| 1549 | if (tsf && AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) |
| 1550 | ath9k_hw_settsf64(ah, tsf); |
| 1551 | |
Vasanthakumar Thiagarajan | 369391d | 2009-01-21 19:24:13 +0530 | [diff] [blame] | 1552 | if (AR_SREV_9280_10_OR_LATER(ah)) |
| 1553 | 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] | 1554 | |
Luis R. Rodriguez | 25c56ee | 2009-09-13 23:04:44 -0700 | [diff] [blame] | 1555 | r = ath9k_hw_process_ini(ah, chan); |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 1556 | if (r) |
| 1557 | return r; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1558 | |
Jouni Malinen | 0ced0e1 | 2009-01-08 13:32:13 +0200 | [diff] [blame] | 1559 | /* Setup MFP options for CCMP */ |
| 1560 | if (AR_SREV_9280_20_OR_LATER(ah)) { |
| 1561 | /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt |
| 1562 | * frames when constructing CCMP AAD. */ |
| 1563 | REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT, |
| 1564 | 0xc7ff); |
| 1565 | ah->sw_mgmt_crypto = false; |
| 1566 | } else if (AR_SREV_9160_10_OR_LATER(ah)) { |
| 1567 | /* Disable hardware crypto for management frames */ |
| 1568 | REG_CLR_BIT(ah, AR_PCU_MISC_MODE2, |
| 1569 | AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE); |
| 1570 | REG_SET_BIT(ah, AR_PCU_MISC_MODE2, |
| 1571 | AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT); |
| 1572 | ah->sw_mgmt_crypto = true; |
| 1573 | } else |
| 1574 | ah->sw_mgmt_crypto = true; |
| 1575 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1576 | if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan)) |
| 1577 | ath9k_hw_set_delta_slope(ah, chan); |
| 1578 | |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1579 | ath9k_hw_spur_mitigate_freq(ah, chan); |
Sujith | d650915 | 2009-03-13 08:56:05 +0530 | [diff] [blame] | 1580 | ah->eep_ops->set_board_values(ah, chan); |
Luis R. Rodriguez | a776582 | 2009-10-19 02:33:45 -0400 | [diff] [blame] | 1581 | |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 1582 | REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr)); |
| 1583 | 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] | 1584 | | macStaId1 |
| 1585 | | AR_STA_ID1_RTS_USE_DEF |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1586 | | (ah->config. |
Sujith | 60b67f5 | 2008-08-07 10:52:38 +0530 | [diff] [blame] | 1587 | ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1588 | | ah->sta_id1_defaults); |
| 1589 | ath9k_hw_set_operating_mode(ah, ah->opmode); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1590 | |
Luis R. Rodriguez | 13b8155 | 2009-09-10 17:52:45 -0700 | [diff] [blame] | 1591 | ath_hw_setbssidmask(common); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1592 | |
| 1593 | REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna); |
| 1594 | |
Luis R. Rodriguez | 3453ad8 | 2009-09-10 08:57:00 -0700 | [diff] [blame] | 1595 | ath9k_hw_write_associd(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1596 | |
| 1597 | REG_WRITE(ah, AR_ISR, ~0); |
| 1598 | |
| 1599 | REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR); |
| 1600 | |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1601 | r = ath9k_hw_rf_set_freq(ah, chan); |
Luis R. Rodriguez | 0a3b7ba | 2009-10-19 02:33:40 -0400 | [diff] [blame] | 1602 | if (r) |
| 1603 | return r; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1604 | |
| 1605 | for (i = 0; i < AR_NUM_DCU; i++) |
| 1606 | REG_WRITE(ah, AR_DQCUMASK(i), 1 << i); |
| 1607 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1608 | ah->intr_txqs = 0; |
| 1609 | for (i = 0; i < ah->caps.total_queues; i++) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1610 | ath9k_hw_resettxqueue(ah, i); |
| 1611 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1612 | ath9k_hw_init_interrupt_masks(ah, ah->opmode); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1613 | ath9k_hw_init_qos(ah); |
| 1614 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1615 | if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT) |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 1616 | ath9k_enable_rfkill(ah); |
Johannes Berg | 3b319aa | 2009-06-13 14:50:26 +0530 | [diff] [blame] | 1617 | |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 1618 | ath9k_hw_init_global_settings(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1619 | |
Vivek Natarajan | 326bebb | 2009-08-14 11:33:36 +0530 | [diff] [blame] | 1620 | if (AR_SREV_9287_12_OR_LATER(ah)) { |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 1621 | REG_WRITE(ah, AR_D_GBL_IFS_SIFS, |
| 1622 | AR_D_GBL_IFS_SIFS_ASYNC_FIFO_DUR); |
| 1623 | REG_WRITE(ah, AR_D_GBL_IFS_SLOT, |
| 1624 | AR_D_GBL_IFS_SLOT_ASYNC_FIFO_DUR); |
| 1625 | REG_WRITE(ah, AR_D_GBL_IFS_EIFS, |
| 1626 | AR_D_GBL_IFS_EIFS_ASYNC_FIFO_DUR); |
| 1627 | |
| 1628 | REG_WRITE(ah, AR_TIME_OUT, AR_TIME_OUT_ACK_CTS_ASYNC_FIFO_DUR); |
| 1629 | REG_WRITE(ah, AR_USEC, AR_USEC_ASYNC_FIFO_DUR); |
| 1630 | |
| 1631 | REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER, |
| 1632 | AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768); |
| 1633 | REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN, |
| 1634 | AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL); |
| 1635 | } |
Vivek Natarajan | 326bebb | 2009-08-14 11:33:36 +0530 | [diff] [blame] | 1636 | if (AR_SREV_9287_12_OR_LATER(ah)) { |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 1637 | REG_SET_BIT(ah, AR_PCU_MISC_MODE2, |
| 1638 | AR_PCU_MISC_MODE2_ENABLE_AGGWEP); |
| 1639 | } |
| 1640 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1641 | REG_WRITE(ah, AR_STA_ID1, |
| 1642 | REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM); |
| 1643 | |
| 1644 | ath9k_hw_set_dma(ah); |
| 1645 | |
| 1646 | REG_WRITE(ah, AR_OBS, 8); |
| 1647 | |
Sujith | 0ce024c | 2009-12-14 14:57:00 +0530 | [diff] [blame] | 1648 | if (ah->config.rx_intr_mitigation) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1649 | REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500); |
| 1650 | REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000); |
| 1651 | } |
| 1652 | |
| 1653 | ath9k_hw_init_bb(ah, chan); |
| 1654 | |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 1655 | if (!ath9k_hw_init_cal(ah, chan)) |
Joe Perches | 6badaaf | 2009-06-28 09:26:32 -0700 | [diff] [blame] | 1656 | return -EIO; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1657 | |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1658 | ath9k_hw_restore_chainmask(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1659 | REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ); |
| 1660 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1661 | /* |
| 1662 | * For big endian systems turn on swapping for descriptors |
| 1663 | */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1664 | if (AR_SREV_9100(ah)) { |
| 1665 | u32 mask; |
| 1666 | mask = REG_READ(ah, AR_CFG); |
| 1667 | if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1668 | ath_print(common, ATH_DBG_RESET, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 1669 | "CFG Byte Swap Set 0x%x\n", mask); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1670 | } else { |
| 1671 | mask = |
| 1672 | INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB; |
| 1673 | REG_WRITE(ah, AR_CFG, mask); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1674 | ath_print(common, ATH_DBG_RESET, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 1675 | "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1676 | } |
| 1677 | } else { |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1678 | /* Configure AR9271 target WLAN */ |
| 1679 | if (AR_SREV_9271(ah)) |
| 1680 | REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1681 | #ifdef __BIG_ENDIAN |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1682 | else |
| 1683 | REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1684 | #endif |
| 1685 | } |
| 1686 | |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 1687 | if (ah->btcoex_hw.enabled) |
Vasanthakumar Thiagarajan | 42cc41e | 2009-08-26 21:08:45 +0530 | [diff] [blame] | 1688 | ath9k_hw_btcoex_enable(ah); |
| 1689 | |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 1690 | return 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1691 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 1692 | EXPORT_SYMBOL(ath9k_hw_reset); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1693 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1694 | /************************/ |
| 1695 | /* Key Cache Management */ |
| 1696 | /************************/ |
| 1697 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1698 | bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1699 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1700 | u32 keyType; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1701 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1702 | if (entry >= ah->caps.keycache_size) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1703 | ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL, |
| 1704 | "keychache entry %u out of range\n", entry); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1705 | return false; |
| 1706 | } |
| 1707 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1708 | keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1709 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1710 | REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0); |
| 1711 | REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0); |
| 1712 | REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0); |
| 1713 | REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0); |
| 1714 | REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0); |
| 1715 | REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR); |
| 1716 | REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0); |
| 1717 | REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0); |
| 1718 | |
| 1719 | if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) { |
| 1720 | u16 micentry = entry + 64; |
| 1721 | |
| 1722 | REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0); |
| 1723 | REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0); |
| 1724 | REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0); |
| 1725 | REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0); |
| 1726 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1727 | } |
| 1728 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1729 | return true; |
| 1730 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 1731 | EXPORT_SYMBOL(ath9k_hw_keyreset); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1732 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1733 | 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] | 1734 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1735 | u32 macHi, macLo; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1736 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1737 | if (entry >= ah->caps.keycache_size) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1738 | ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL, |
| 1739 | "keychache entry %u out of range\n", entry); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1740 | return false; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1741 | } |
| 1742 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1743 | if (mac != NULL) { |
| 1744 | macHi = (mac[5] << 8) | mac[4]; |
| 1745 | macLo = (mac[3] << 24) | |
| 1746 | (mac[2] << 16) | |
| 1747 | (mac[1] << 8) | |
| 1748 | mac[0]; |
| 1749 | macLo >>= 1; |
| 1750 | macLo |= (macHi & 1) << 31; |
| 1751 | macHi >>= 1; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1752 | } else { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1753 | macLo = macHi = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1754 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1755 | REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo); |
| 1756 | REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1757 | |
| 1758 | return true; |
| 1759 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 1760 | EXPORT_SYMBOL(ath9k_hw_keysetmac); |
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 | bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1763 | const struct ath9k_keyval *k, |
Jouni Malinen | e0caf9e | 2009-03-02 18:15:53 +0200 | [diff] [blame] | 1764 | const u8 *mac) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1765 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1766 | const struct ath9k_hw_capabilities *pCap = &ah->caps; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1767 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1768 | u32 key0, key1, key2, key3, key4; |
| 1769 | u32 keyType; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1770 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1771 | if (entry >= pCap->keycache_size) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1772 | ath_print(common, ATH_DBG_FATAL, |
| 1773 | "keycache entry %u out of range\n", entry); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1774 | return false; |
| 1775 | } |
| 1776 | |
| 1777 | switch (k->kv_type) { |
| 1778 | case ATH9K_CIPHER_AES_OCB: |
| 1779 | keyType = AR_KEYTABLE_TYPE_AES; |
| 1780 | break; |
| 1781 | case ATH9K_CIPHER_AES_CCM: |
| 1782 | if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1783 | ath_print(common, ATH_DBG_ANY, |
| 1784 | "AES-CCM not supported by mac rev 0x%x\n", |
| 1785 | ah->hw_version.macRev); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1786 | return false; |
| 1787 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1788 | keyType = AR_KEYTABLE_TYPE_CCM; |
| 1789 | break; |
| 1790 | case ATH9K_CIPHER_TKIP: |
| 1791 | keyType = AR_KEYTABLE_TYPE_TKIP; |
| 1792 | if (ATH9K_IS_MIC_ENABLED(ah) |
| 1793 | && entry + 64 >= pCap->keycache_size) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1794 | ath_print(common, ATH_DBG_ANY, |
| 1795 | "entry %u inappropriate for TKIP\n", entry); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1796 | return false; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1797 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1798 | break; |
| 1799 | case ATH9K_CIPHER_WEP: |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 1800 | if (k->kv_len < WLAN_KEY_LEN_WEP40) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1801 | ath_print(common, ATH_DBG_ANY, |
| 1802 | "WEP key length %u too small\n", k->kv_len); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1803 | return false; |
| 1804 | } |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 1805 | if (k->kv_len <= WLAN_KEY_LEN_WEP40) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1806 | keyType = AR_KEYTABLE_TYPE_40; |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 1807 | else if (k->kv_len <= WLAN_KEY_LEN_WEP104) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1808 | keyType = AR_KEYTABLE_TYPE_104; |
| 1809 | else |
| 1810 | keyType = AR_KEYTABLE_TYPE_128; |
| 1811 | break; |
| 1812 | case ATH9K_CIPHER_CLR: |
| 1813 | keyType = AR_KEYTABLE_TYPE_CLR; |
| 1814 | break; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1815 | default: |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1816 | ath_print(common, ATH_DBG_FATAL, |
| 1817 | "cipher %u not supported\n", k->kv_type); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1818 | return false; |
| 1819 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1820 | |
Jouni Malinen | e0caf9e | 2009-03-02 18:15:53 +0200 | [diff] [blame] | 1821 | key0 = get_unaligned_le32(k->kv_val + 0); |
| 1822 | key1 = get_unaligned_le16(k->kv_val + 4); |
| 1823 | key2 = get_unaligned_le32(k->kv_val + 6); |
| 1824 | key3 = get_unaligned_le16(k->kv_val + 10); |
| 1825 | key4 = get_unaligned_le32(k->kv_val + 12); |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 1826 | if (k->kv_len <= WLAN_KEY_LEN_WEP104) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1827 | key4 &= 0xff; |
| 1828 | |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1829 | /* |
| 1830 | * Note: Key cache registers access special memory area that requires |
| 1831 | * two 32-bit writes to actually update the values in the internal |
| 1832 | * memory. Consequently, the exact order and pairs used here must be |
| 1833 | * maintained. |
| 1834 | */ |
| 1835 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1836 | if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) { |
| 1837 | u16 micentry = entry + 64; |
| 1838 | |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1839 | /* |
| 1840 | * Write inverted key[47:0] first to avoid Michael MIC errors |
| 1841 | * on frames that could be sent or received at the same time. |
| 1842 | * The correct key will be written in the end once everything |
| 1843 | * else is ready. |
| 1844 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1845 | REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0); |
| 1846 | REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1847 | |
| 1848 | /* Write key[95:48] */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1849 | REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2); |
| 1850 | REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1851 | |
| 1852 | /* Write key[127:96] and key type */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1853 | REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4); |
| 1854 | REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1855 | |
| 1856 | /* Write MAC address for the entry */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1857 | (void) ath9k_hw_keysetmac(ah, entry, mac); |
| 1858 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1859 | if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) { |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1860 | /* |
| 1861 | * TKIP uses two key cache entries: |
| 1862 | * Michael MIC TX/RX keys in the same key cache entry |
| 1863 | * (idx = main index + 64): |
| 1864 | * key0 [31:0] = RX key [31:0] |
| 1865 | * key1 [15:0] = TX key [31:16] |
| 1866 | * key1 [31:16] = reserved |
| 1867 | * key2 [31:0] = RX key [63:32] |
| 1868 | * key3 [15:0] = TX key [15:0] |
| 1869 | * key3 [31:16] = reserved |
| 1870 | * key4 [31:0] = TX key [63:32] |
| 1871 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1872 | u32 mic0, mic1, mic2, mic3, mic4; |
| 1873 | |
| 1874 | mic0 = get_unaligned_le32(k->kv_mic + 0); |
| 1875 | mic2 = get_unaligned_le32(k->kv_mic + 4); |
| 1876 | mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff; |
| 1877 | mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff; |
| 1878 | mic4 = get_unaligned_le32(k->kv_txmic + 4); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1879 | |
| 1880 | /* Write RX[31:0] and TX[31:16] */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1881 | REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0); |
| 1882 | REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1883 | |
| 1884 | /* Write RX[63:32] and TX[15:0] */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1885 | REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2); |
| 1886 | REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1887 | |
| 1888 | /* Write TX[63:32] and keyType(reserved) */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1889 | REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4); |
| 1890 | REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry), |
| 1891 | AR_KEYTABLE_TYPE_CLR); |
| 1892 | |
| 1893 | } else { |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1894 | /* |
| 1895 | * TKIP uses four key cache entries (two for group |
| 1896 | * keys): |
| 1897 | * Michael MIC TX/RX keys are in different key cache |
| 1898 | * entries (idx = main index + 64 for TX and |
| 1899 | * main index + 32 + 96 for RX): |
| 1900 | * key0 [31:0] = TX/RX MIC key [31:0] |
| 1901 | * key1 [31:0] = reserved |
| 1902 | * key2 [31:0] = TX/RX MIC key [63:32] |
| 1903 | * key3 [31:0] = reserved |
| 1904 | * key4 [31:0] = reserved |
| 1905 | * |
| 1906 | * Upper layer code will call this function separately |
| 1907 | * for TX and RX keys when these registers offsets are |
| 1908 | * used. |
| 1909 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1910 | u32 mic0, mic2; |
| 1911 | |
| 1912 | mic0 = get_unaligned_le32(k->kv_mic + 0); |
| 1913 | mic2 = get_unaligned_le32(k->kv_mic + 4); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1914 | |
| 1915 | /* Write MIC key[31:0] */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1916 | REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0); |
| 1917 | REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1918 | |
| 1919 | /* Write MIC key[63:32] */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1920 | REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2); |
| 1921 | REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1922 | |
| 1923 | /* Write TX[63:32] and keyType(reserved) */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1924 | REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0); |
| 1925 | REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry), |
| 1926 | AR_KEYTABLE_TYPE_CLR); |
| 1927 | } |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1928 | |
| 1929 | /* MAC address registers are reserved for the MIC entry */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1930 | REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0); |
| 1931 | REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1932 | |
| 1933 | /* |
| 1934 | * Write the correct (un-inverted) key[47:0] last to enable |
| 1935 | * TKIP now that all other registers are set with correct |
| 1936 | * values. |
| 1937 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1938 | REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0); |
| 1939 | REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1); |
| 1940 | } else { |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1941 | /* Write key[47:0] */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1942 | REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0); |
| 1943 | REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1944 | |
| 1945 | /* Write key[95:48] */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1946 | REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2); |
| 1947 | REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1948 | |
| 1949 | /* Write key[127:96] and key type */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1950 | REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4); |
| 1951 | REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType); |
| 1952 | |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 1953 | /* Write MAC address for the entry */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1954 | (void) ath9k_hw_keysetmac(ah, entry, mac); |
| 1955 | } |
| 1956 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1957 | return true; |
| 1958 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 1959 | EXPORT_SYMBOL(ath9k_hw_set_keycache_entry); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1960 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1961 | bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1962 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1963 | if (entry < ah->caps.keycache_size) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1964 | u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry)); |
| 1965 | if (val & AR_KEYTABLE_VALID) |
| 1966 | return true; |
| 1967 | } |
| 1968 | return false; |
| 1969 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 1970 | EXPORT_SYMBOL(ath9k_hw_keyisvalid); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1971 | |
| 1972 | /******************************/ |
| 1973 | /* Power Management (Chipset) */ |
| 1974 | /******************************/ |
| 1975 | |
Luis R. Rodriguez | 42d5bc3 | 2010-04-15 17:38:12 -0400 | [diff] [blame] | 1976 | /* |
| 1977 | * Notify Power Mgt is disabled in self-generated frames. |
| 1978 | * If requested, force chip to sleep. |
| 1979 | */ |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1980 | static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1981 | { |
| 1982 | REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV); |
| 1983 | if (setChip) { |
Luis R. Rodriguez | 42d5bc3 | 2010-04-15 17:38:12 -0400 | [diff] [blame] | 1984 | /* |
| 1985 | * Clear the RTC force wake bit to allow the |
| 1986 | * mac to go to sleep. |
| 1987 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1988 | REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, |
| 1989 | AR_RTC_FORCE_WAKE_EN); |
Luis R. Rodriguez | 42d5bc3 | 2010-04-15 17:38:12 -0400 | [diff] [blame] | 1990 | if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1991 | REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF); |
| 1992 | |
Luis R. Rodriguez | 42d5bc3 | 2010-04-15 17:38:12 -0400 | [diff] [blame] | 1993 | /* Shutdown chip. Active low */ |
Sujith | 14b3af3 | 2010-03-17 14:25:18 +0530 | [diff] [blame] | 1994 | if (!AR_SREV_5416(ah) && !AR_SREV_9271(ah)) |
Sujith | 4921be8 | 2009-09-18 15:04:27 +0530 | [diff] [blame] | 1995 | REG_CLR_BIT(ah, (AR_RTC_RESET), |
| 1996 | AR_RTC_RESET_EN); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1997 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1998 | } |
| 1999 | |
Luis R. Rodriguez | bbd79af | 2010-04-15 17:38:16 -0400 | [diff] [blame] | 2000 | /* |
| 2001 | * Notify Power Management is enabled in self-generating |
| 2002 | * frames. If request, set power mode of chip to |
| 2003 | * auto/normal. Duration in units of 128us (1/8 TU). |
| 2004 | */ |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2005 | 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] | 2006 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2007 | REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV); |
| 2008 | if (setChip) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2009 | struct ath9k_hw_capabilities *pCap = &ah->caps; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2010 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2011 | if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) { |
Luis R. Rodriguez | bbd79af | 2010-04-15 17:38:16 -0400 | [diff] [blame] | 2012 | /* Set WakeOnInterrupt bit; clear ForceWake bit */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2013 | REG_WRITE(ah, AR_RTC_FORCE_WAKE, |
| 2014 | AR_RTC_FORCE_WAKE_ON_INT); |
| 2015 | } else { |
Luis R. Rodriguez | bbd79af | 2010-04-15 17:38:16 -0400 | [diff] [blame] | 2016 | /* |
| 2017 | * Clear the RTC force wake bit to allow the |
| 2018 | * mac to go to sleep. |
| 2019 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2020 | REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, |
| 2021 | AR_RTC_FORCE_WAKE_EN); |
| 2022 | } |
| 2023 | } |
| 2024 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2025 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2026 | static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2027 | { |
| 2028 | u32 val; |
| 2029 | int i; |
| 2030 | |
| 2031 | if (setChip) { |
| 2032 | if ((REG_READ(ah, AR_RTC_STATUS) & |
| 2033 | AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) { |
| 2034 | if (ath9k_hw_set_reset_reg(ah, |
| 2035 | ATH9K_RESET_POWER_ON) != true) { |
| 2036 | return false; |
| 2037 | } |
Luis R. Rodriguez | e041228 | 2010-04-15 17:38:15 -0400 | [diff] [blame] | 2038 | if (!AR_SREV_9300_20_OR_LATER(ah)) |
| 2039 | ath9k_hw_init_pll(ah, NULL); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2040 | } |
| 2041 | if (AR_SREV_9100(ah)) |
| 2042 | REG_SET_BIT(ah, AR_RTC_RESET, |
| 2043 | AR_RTC_RESET_EN); |
| 2044 | |
| 2045 | REG_SET_BIT(ah, AR_RTC_FORCE_WAKE, |
| 2046 | AR_RTC_FORCE_WAKE_EN); |
| 2047 | udelay(50); |
| 2048 | |
| 2049 | for (i = POWER_UP_TIME / 50; i > 0; i--) { |
| 2050 | val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M; |
| 2051 | if (val == AR_RTC_STATUS_ON) |
| 2052 | break; |
| 2053 | udelay(50); |
| 2054 | REG_SET_BIT(ah, AR_RTC_FORCE_WAKE, |
| 2055 | AR_RTC_FORCE_WAKE_EN); |
| 2056 | } |
| 2057 | if (i == 0) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2058 | ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL, |
| 2059 | "Failed to wakeup in %uus\n", |
| 2060 | POWER_UP_TIME / 20); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2061 | return false; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2062 | } |
| 2063 | } |
| 2064 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2065 | REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV); |
| 2066 | |
| 2067 | return true; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2068 | } |
| 2069 | |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 2070 | bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2071 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2072 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2073 | int status = true, setChip = true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2074 | static const char *modes[] = { |
| 2075 | "AWAKE", |
| 2076 | "FULL-SLEEP", |
| 2077 | "NETWORK SLEEP", |
| 2078 | "UNDEFINED" |
| 2079 | }; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2080 | |
Gabor Juhos | cbdec97 | 2009-07-24 17:27:22 +0200 | [diff] [blame] | 2081 | if (ah->power_mode == mode) |
| 2082 | return status; |
| 2083 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2084 | ath_print(common, ATH_DBG_RESET, "%s -> %s\n", |
| 2085 | modes[ah->power_mode], modes[mode]); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2086 | |
| 2087 | switch (mode) { |
| 2088 | case ATH9K_PM_AWAKE: |
| 2089 | status = ath9k_hw_set_power_awake(ah, setChip); |
| 2090 | break; |
| 2091 | case ATH9K_PM_FULL_SLEEP: |
| 2092 | ath9k_set_power_sleep(ah, setChip); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2093 | ah->chip_fullsleep = true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2094 | break; |
| 2095 | case ATH9K_PM_NETWORK_SLEEP: |
| 2096 | ath9k_set_power_network_sleep(ah, setChip); |
| 2097 | break; |
| 2098 | default: |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2099 | ath_print(common, ATH_DBG_FATAL, |
| 2100 | "Unknown power mode %u\n", mode); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2101 | return false; |
| 2102 | } |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2103 | ah->power_mode = mode; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2104 | |
| 2105 | return status; |
| 2106 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2107 | EXPORT_SYMBOL(ath9k_hw_setpower); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2108 | |
Luis R. Rodriguez | 24c1a28 | 2009-02-10 15:35:22 -0800 | [diff] [blame] | 2109 | /* |
| 2110 | * Helper for ASPM support. |
| 2111 | * |
| 2112 | * Disable PLL when in L0s as well as receiver clock when in L1. |
| 2113 | * This power saving option must be enabled through the SerDes. |
| 2114 | * |
| 2115 | * Programming the SerDes must go through the same 288 bit serial shift |
| 2116 | * register as the other analog registers. Hence the 9 writes. |
| 2117 | */ |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 2118 | static void ar9002_hw_configpcipowersave(struct ath_hw *ah, |
| 2119 | int restore, |
| 2120 | int power_off) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2121 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2122 | u8 i; |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 2123 | u32 val; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2124 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2125 | if (ah->is_pciexpress != true) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2126 | return; |
| 2127 | |
Luis R. Rodriguez | 24c1a28 | 2009-02-10 15:35:22 -0800 | [diff] [blame] | 2128 | /* Do not touch SerDes registers */ |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2129 | if (ah->config.pcie_powersave_enable == 2) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2130 | return; |
| 2131 | |
Luis R. Rodriguez | 24c1a28 | 2009-02-10 15:35:22 -0800 | [diff] [blame] | 2132 | /* Nothing to do on restore for 11N */ |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 2133 | if (!restore) { |
| 2134 | if (AR_SREV_9280_20_OR_LATER(ah)) { |
| 2135 | /* |
| 2136 | * AR9280 2.0 or later chips use SerDes values from the |
| 2137 | * initvals.h initialized depending on chipset during |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 2138 | * __ath9k_hw_init() |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 2139 | */ |
| 2140 | for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) { |
| 2141 | REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0), |
| 2142 | INI_RA(&ah->iniPcieSerdes, i, 1)); |
| 2143 | } |
| 2144 | } else if (AR_SREV_9280(ah) && |
| 2145 | (ah->hw_version.macRev == AR_SREV_REVISION_9280_10)) { |
| 2146 | REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00); |
| 2147 | REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2148 | |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 2149 | /* RX shut off when elecidle is asserted */ |
| 2150 | REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019); |
| 2151 | REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820); |
| 2152 | REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560); |
| 2153 | |
| 2154 | /* Shut off CLKREQ active in L1 */ |
| 2155 | if (ah->config.pcie_clock_req) |
| 2156 | REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc); |
| 2157 | else |
| 2158 | REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd); |
| 2159 | |
| 2160 | REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40); |
| 2161 | REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554); |
| 2162 | REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007); |
| 2163 | |
| 2164 | /* Load the new settings */ |
| 2165 | REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000); |
| 2166 | |
| 2167 | } else { |
| 2168 | REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00); |
| 2169 | REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924); |
| 2170 | |
| 2171 | /* RX shut off when elecidle is asserted */ |
| 2172 | REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039); |
| 2173 | REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824); |
| 2174 | REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579); |
| 2175 | |
| 2176 | /* |
| 2177 | * Ignore ah->ah_config.pcie_clock_req setting for |
| 2178 | * pre-AR9280 11n |
| 2179 | */ |
| 2180 | REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff); |
| 2181 | |
| 2182 | REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40); |
| 2183 | REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554); |
| 2184 | REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007); |
| 2185 | |
| 2186 | /* Load the new settings */ |
| 2187 | REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2188 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2189 | |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 2190 | udelay(1000); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2191 | |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 2192 | /* set bit 19 to allow forcing of pcie core into L1 state */ |
| 2193 | REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2194 | |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 2195 | /* Several PCIe massages to ensure proper behaviour */ |
| 2196 | if (ah->config.pcie_waen) { |
| 2197 | val = ah->config.pcie_waen; |
| 2198 | if (!power_off) |
| 2199 | val &= (~AR_WA_D3_L1_DISABLE); |
| 2200 | } else { |
| 2201 | if (AR_SREV_9285(ah) || AR_SREV_9271(ah) || |
| 2202 | AR_SREV_9287(ah)) { |
| 2203 | val = AR9285_WA_DEFAULT; |
| 2204 | if (!power_off) |
| 2205 | val &= (~AR_WA_D3_L1_DISABLE); |
| 2206 | } else if (AR_SREV_9280(ah)) { |
| 2207 | /* |
| 2208 | * On AR9280 chips bit 22 of 0x4004 needs to be |
| 2209 | * set otherwise card may disappear. |
| 2210 | */ |
| 2211 | val = AR9280_WA_DEFAULT; |
| 2212 | if (!power_off) |
| 2213 | val &= (~AR_WA_D3_L1_DISABLE); |
| 2214 | } else |
| 2215 | val = AR_WA_DEFAULT; |
| 2216 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2217 | |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 2218 | REG_WRITE(ah, AR_WA, val); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2219 | } |
| 2220 | |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 2221 | if (power_off) { |
Luis R. Rodriguez | 24c1a28 | 2009-02-10 15:35:22 -0800 | [diff] [blame] | 2222 | /* |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 2223 | * Set PCIe workaround bits |
| 2224 | * bit 14 in WA register (disable L1) should only |
| 2225 | * be set when device enters D3 and be cleared |
| 2226 | * when device comes back to D0. |
Luis R. Rodriguez | 24c1a28 | 2009-02-10 15:35:22 -0800 | [diff] [blame] | 2227 | */ |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 2228 | if (ah->config.pcie_waen) { |
| 2229 | if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE) |
| 2230 | REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE); |
| 2231 | } else { |
| 2232 | if (((AR_SREV_9285(ah) || AR_SREV_9271(ah) || |
| 2233 | AR_SREV_9287(ah)) && |
| 2234 | (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)) || |
| 2235 | (AR_SREV_9280(ah) && |
| 2236 | (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE))) { |
| 2237 | REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE); |
| 2238 | } |
| 2239 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2240 | } |
| 2241 | } |
| 2242 | |
| 2243 | /**********************/ |
| 2244 | /* Interrupt Handling */ |
| 2245 | /**********************/ |
| 2246 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2247 | bool ath9k_hw_intrpend(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2248 | { |
| 2249 | u32 host_isr; |
| 2250 | |
| 2251 | if (AR_SREV_9100(ah)) |
| 2252 | return true; |
| 2253 | |
| 2254 | host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE); |
| 2255 | if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS)) |
| 2256 | return true; |
| 2257 | |
| 2258 | host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE); |
| 2259 | if ((host_isr & AR_INTR_SYNC_DEFAULT) |
| 2260 | && (host_isr != AR_INTR_SPURIOUS)) |
| 2261 | return true; |
| 2262 | |
| 2263 | return false; |
| 2264 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2265 | EXPORT_SYMBOL(ath9k_hw_intrpend); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2266 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2267 | bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2268 | { |
| 2269 | u32 isr = 0; |
| 2270 | u32 mask2 = 0; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2271 | struct ath9k_hw_capabilities *pCap = &ah->caps; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2272 | u32 sync_cause = 0; |
| 2273 | bool fatal_int = false; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2274 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2275 | |
| 2276 | if (!AR_SREV_9100(ah)) { |
| 2277 | if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) { |
| 2278 | if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M) |
| 2279 | == AR_RTC_STATUS_ON) { |
| 2280 | isr = REG_READ(ah, AR_ISR); |
| 2281 | } |
| 2282 | } |
| 2283 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2284 | sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) & |
| 2285 | AR_INTR_SYNC_DEFAULT; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2286 | |
| 2287 | *masked = 0; |
| 2288 | |
| 2289 | if (!isr && !sync_cause) |
| 2290 | return false; |
| 2291 | } else { |
| 2292 | *masked = 0; |
| 2293 | isr = REG_READ(ah, AR_ISR); |
| 2294 | } |
| 2295 | |
| 2296 | if (isr) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2297 | if (isr & AR_ISR_BCNMISC) { |
| 2298 | u32 isr2; |
| 2299 | isr2 = REG_READ(ah, AR_ISR_S2); |
| 2300 | if (isr2 & AR_ISR_S2_TIM) |
| 2301 | mask2 |= ATH9K_INT_TIM; |
| 2302 | if (isr2 & AR_ISR_S2_DTIM) |
| 2303 | mask2 |= ATH9K_INT_DTIM; |
| 2304 | if (isr2 & AR_ISR_S2_DTIMSYNC) |
| 2305 | mask2 |= ATH9K_INT_DTIMSYNC; |
| 2306 | if (isr2 & (AR_ISR_S2_CABEND)) |
| 2307 | mask2 |= ATH9K_INT_CABEND; |
| 2308 | if (isr2 & AR_ISR_S2_GTT) |
| 2309 | mask2 |= ATH9K_INT_GTT; |
| 2310 | if (isr2 & AR_ISR_S2_CST) |
| 2311 | mask2 |= ATH9K_INT_CST; |
Sujith | 4af9cf4 | 2009-02-12 10:06:47 +0530 | [diff] [blame] | 2312 | if (isr2 & AR_ISR_S2_TSFOOR) |
| 2313 | mask2 |= ATH9K_INT_TSFOOR; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2314 | } |
| 2315 | |
| 2316 | isr = REG_READ(ah, AR_ISR_RAC); |
| 2317 | if (isr == 0xffffffff) { |
| 2318 | *masked = 0; |
| 2319 | return false; |
| 2320 | } |
| 2321 | |
| 2322 | *masked = isr & ATH9K_INT_COMMON; |
| 2323 | |
Sujith | 0ce024c | 2009-12-14 14:57:00 +0530 | [diff] [blame] | 2324 | if (ah->config.rx_intr_mitigation) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2325 | if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM)) |
| 2326 | *masked |= ATH9K_INT_RX; |
| 2327 | } |
| 2328 | |
| 2329 | if (isr & (AR_ISR_RXOK | AR_ISR_RXERR)) |
| 2330 | *masked |= ATH9K_INT_RX; |
| 2331 | if (isr & |
| 2332 | (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR | |
| 2333 | AR_ISR_TXEOL)) { |
| 2334 | u32 s0_s, s1_s; |
| 2335 | |
| 2336 | *masked |= ATH9K_INT_TX; |
| 2337 | |
| 2338 | s0_s = REG_READ(ah, AR_ISR_S0_S); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2339 | ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK); |
| 2340 | ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2341 | |
| 2342 | s1_s = REG_READ(ah, AR_ISR_S1_S); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2343 | ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR); |
| 2344 | ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2345 | } |
| 2346 | |
| 2347 | if (isr & AR_ISR_RXORN) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2348 | ath_print(common, ATH_DBG_INTERRUPT, |
| 2349 | "receive FIFO overrun interrupt\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2350 | } |
| 2351 | |
| 2352 | if (!AR_SREV_9100(ah)) { |
Sujith | 60b67f5 | 2008-08-07 10:52:38 +0530 | [diff] [blame] | 2353 | if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2354 | u32 isr5 = REG_READ(ah, AR_ISR_S5_S); |
| 2355 | if (isr5 & AR_ISR_S5_TIM_TIMER) |
| 2356 | *masked |= ATH9K_INT_TIM_TIMER; |
| 2357 | } |
| 2358 | } |
| 2359 | |
| 2360 | *masked |= mask2; |
| 2361 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2362 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2363 | if (AR_SREV_9100(ah)) |
| 2364 | return true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2365 | |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 2366 | if (isr & AR_ISR_GENTMR) { |
| 2367 | u32 s5_s; |
| 2368 | |
| 2369 | s5_s = REG_READ(ah, AR_ISR_S5_S); |
| 2370 | if (isr & AR_ISR_GENTMR) { |
| 2371 | ah->intr_gen_timer_trigger = |
| 2372 | MS(s5_s, AR_ISR_S5_GENTIMER_TRIG); |
| 2373 | |
| 2374 | ah->intr_gen_timer_thresh = |
| 2375 | MS(s5_s, AR_ISR_S5_GENTIMER_THRESH); |
| 2376 | |
| 2377 | if (ah->intr_gen_timer_trigger) |
| 2378 | *masked |= ATH9K_INT_GENTIMER; |
| 2379 | |
| 2380 | } |
| 2381 | } |
| 2382 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2383 | if (sync_cause) { |
| 2384 | fatal_int = |
| 2385 | (sync_cause & |
| 2386 | (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR)) |
| 2387 | ? true : false; |
| 2388 | |
| 2389 | if (fatal_int) { |
| 2390 | if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2391 | ath_print(common, ATH_DBG_ANY, |
| 2392 | "received PCI FATAL interrupt\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2393 | } |
| 2394 | if (sync_cause & AR_INTR_SYNC_HOST1_PERR) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2395 | ath_print(common, ATH_DBG_ANY, |
| 2396 | "received PCI PERR interrupt\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2397 | } |
Steven Luo | a89bff9 | 2009-04-12 02:57:54 -0700 | [diff] [blame] | 2398 | *masked |= ATH9K_INT_FATAL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2399 | } |
| 2400 | if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2401 | ath_print(common, ATH_DBG_INTERRUPT, |
| 2402 | "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2403 | REG_WRITE(ah, AR_RC, AR_RC_HOSTIF); |
| 2404 | REG_WRITE(ah, AR_RC, 0); |
| 2405 | *masked |= ATH9K_INT_FATAL; |
| 2406 | } |
| 2407 | if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2408 | ath_print(common, ATH_DBG_INTERRUPT, |
| 2409 | "AR_INTR_SYNC_LOCAL_TIMEOUT\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2410 | } |
| 2411 | |
| 2412 | REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause); |
| 2413 | (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR); |
| 2414 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2415 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2416 | return true; |
| 2417 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2418 | EXPORT_SYMBOL(ath9k_hw_getisr); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2419 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2420 | enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2421 | { |
Pavel Roskin | 152d530 | 2010-03-31 18:05:37 -0400 | [diff] [blame] | 2422 | enum ath9k_int omask = ah->imask; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2423 | u32 mask, mask2; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2424 | struct ath9k_hw_capabilities *pCap = &ah->caps; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2425 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2426 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2427 | ath_print(common, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2428 | |
| 2429 | if (omask & ATH9K_INT_GLOBAL) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2430 | ath_print(common, ATH_DBG_INTERRUPT, "disable IER\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2431 | REG_WRITE(ah, AR_IER, AR_IER_DISABLE); |
| 2432 | (void) REG_READ(ah, AR_IER); |
| 2433 | if (!AR_SREV_9100(ah)) { |
| 2434 | REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0); |
| 2435 | (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE); |
| 2436 | |
| 2437 | REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0); |
| 2438 | (void) REG_READ(ah, AR_INTR_SYNC_ENABLE); |
| 2439 | } |
| 2440 | } |
| 2441 | |
| 2442 | mask = ints & ATH9K_INT_COMMON; |
| 2443 | mask2 = 0; |
| 2444 | |
| 2445 | if (ints & ATH9K_INT_TX) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2446 | if (ah->txok_interrupt_mask) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2447 | mask |= AR_IMR_TXOK; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2448 | if (ah->txdesc_interrupt_mask) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2449 | mask |= AR_IMR_TXDESC; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2450 | if (ah->txerr_interrupt_mask) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2451 | mask |= AR_IMR_TXERR; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2452 | if (ah->txeol_interrupt_mask) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2453 | mask |= AR_IMR_TXEOL; |
| 2454 | } |
| 2455 | if (ints & ATH9K_INT_RX) { |
| 2456 | mask |= AR_IMR_RXERR; |
Sujith | 0ce024c | 2009-12-14 14:57:00 +0530 | [diff] [blame] | 2457 | if (ah->config.rx_intr_mitigation) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2458 | mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM; |
| 2459 | else |
| 2460 | mask |= AR_IMR_RXOK | AR_IMR_RXDESC; |
Sujith | 60b67f5 | 2008-08-07 10:52:38 +0530 | [diff] [blame] | 2461 | if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2462 | mask |= AR_IMR_GENTMR; |
| 2463 | } |
| 2464 | |
| 2465 | if (ints & (ATH9K_INT_BMISC)) { |
| 2466 | mask |= AR_IMR_BCNMISC; |
| 2467 | if (ints & ATH9K_INT_TIM) |
| 2468 | mask2 |= AR_IMR_S2_TIM; |
| 2469 | if (ints & ATH9K_INT_DTIM) |
| 2470 | mask2 |= AR_IMR_S2_DTIM; |
| 2471 | if (ints & ATH9K_INT_DTIMSYNC) |
| 2472 | mask2 |= AR_IMR_S2_DTIMSYNC; |
| 2473 | if (ints & ATH9K_INT_CABEND) |
Sujith | 4af9cf4 | 2009-02-12 10:06:47 +0530 | [diff] [blame] | 2474 | mask2 |= AR_IMR_S2_CABEND; |
| 2475 | if (ints & ATH9K_INT_TSFOOR) |
| 2476 | mask2 |= AR_IMR_S2_TSFOOR; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2477 | } |
| 2478 | |
| 2479 | if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) { |
| 2480 | mask |= AR_IMR_BCNMISC; |
| 2481 | if (ints & ATH9K_INT_GTT) |
| 2482 | mask2 |= AR_IMR_S2_GTT; |
| 2483 | if (ints & ATH9K_INT_CST) |
| 2484 | mask2 |= AR_IMR_S2_CST; |
| 2485 | } |
| 2486 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2487 | ath_print(common, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2488 | REG_WRITE(ah, AR_IMR, mask); |
Pavel Roskin | 74bad5c | 2010-02-23 18:15:27 -0500 | [diff] [blame] | 2489 | ah->imrs2_reg &= ~(AR_IMR_S2_TIM | AR_IMR_S2_DTIM | AR_IMR_S2_DTIMSYNC | |
| 2490 | AR_IMR_S2_CABEND | AR_IMR_S2_CABTO | |
| 2491 | AR_IMR_S2_TSFOOR | AR_IMR_S2_GTT | AR_IMR_S2_CST); |
| 2492 | ah->imrs2_reg |= mask2; |
| 2493 | REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2494 | |
Sujith | 60b67f5 | 2008-08-07 10:52:38 +0530 | [diff] [blame] | 2495 | if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2496 | if (ints & ATH9K_INT_TIM_TIMER) |
| 2497 | REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER); |
| 2498 | else |
| 2499 | REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER); |
| 2500 | } |
| 2501 | |
| 2502 | if (ints & ATH9K_INT_GLOBAL) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2503 | ath_print(common, ATH_DBG_INTERRUPT, "enable IER\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2504 | REG_WRITE(ah, AR_IER, AR_IER_ENABLE); |
| 2505 | if (!AR_SREV_9100(ah)) { |
| 2506 | REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, |
| 2507 | AR_INTR_MAC_IRQ); |
| 2508 | REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ); |
| 2509 | |
| 2510 | |
| 2511 | REG_WRITE(ah, AR_INTR_SYNC_ENABLE, |
| 2512 | AR_INTR_SYNC_DEFAULT); |
| 2513 | REG_WRITE(ah, AR_INTR_SYNC_MASK, |
| 2514 | AR_INTR_SYNC_DEFAULT); |
| 2515 | } |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2516 | ath_print(common, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n", |
| 2517 | REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2518 | } |
| 2519 | |
| 2520 | return omask; |
| 2521 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2522 | EXPORT_SYMBOL(ath9k_hw_set_interrupts); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2523 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2524 | /*******************/ |
| 2525 | /* Beacon Handling */ |
| 2526 | /*******************/ |
| 2527 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2528 | 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] | 2529 | { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2530 | int flags = 0; |
| 2531 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2532 | ah->beacon_interval = beacon_period; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2533 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2534 | switch (ah->opmode) { |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 2535 | case NL80211_IFTYPE_STATION: |
| 2536 | case NL80211_IFTYPE_MONITOR: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2537 | REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon)); |
| 2538 | REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff); |
| 2539 | REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff); |
| 2540 | flags |= AR_TBTT_TIMER_EN; |
| 2541 | break; |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 2542 | case NL80211_IFTYPE_ADHOC: |
Pat Erley | 9cb5412 | 2009-03-20 22:59:59 -0400 | [diff] [blame] | 2543 | case NL80211_IFTYPE_MESH_POINT: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2544 | REG_SET_BIT(ah, AR_TXCFG, |
| 2545 | AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY); |
| 2546 | REG_WRITE(ah, AR_NEXT_NDP_TIMER, |
| 2547 | TU_TO_USEC(next_beacon + |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2548 | (ah->atim_window ? ah-> |
| 2549 | atim_window : 1))); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2550 | flags |= AR_NDP_TIMER_EN; |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 2551 | case NL80211_IFTYPE_AP: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2552 | REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon)); |
| 2553 | REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, |
| 2554 | TU_TO_USEC(next_beacon - |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2555 | ah->config. |
Sujith | 60b67f5 | 2008-08-07 10:52:38 +0530 | [diff] [blame] | 2556 | dma_beacon_response_time)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2557 | REG_WRITE(ah, AR_NEXT_SWBA, |
| 2558 | TU_TO_USEC(next_beacon - |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2559 | ah->config. |
Sujith | 60b67f5 | 2008-08-07 10:52:38 +0530 | [diff] [blame] | 2560 | sw_beacon_response_time)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2561 | flags |= |
| 2562 | AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN; |
| 2563 | break; |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 2564 | default: |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2565 | ath_print(ath9k_hw_common(ah), ATH_DBG_BEACON, |
| 2566 | "%s: unsupported opmode: %d\n", |
| 2567 | __func__, ah->opmode); |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 2568 | return; |
| 2569 | break; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2570 | } |
| 2571 | |
| 2572 | REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period)); |
| 2573 | REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period)); |
| 2574 | REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period)); |
| 2575 | REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period)); |
| 2576 | |
| 2577 | beacon_period &= ~ATH9K_BEACON_ENA; |
| 2578 | if (beacon_period & ATH9K_BEACON_RESET_TSF) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2579 | ath9k_hw_reset_tsf(ah); |
| 2580 | } |
| 2581 | |
| 2582 | REG_SET_BIT(ah, AR_TIMER_MODE, flags); |
| 2583 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2584 | EXPORT_SYMBOL(ath9k_hw_beaconinit); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2585 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2586 | void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2587 | const struct ath9k_beacon_state *bs) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2588 | { |
| 2589 | u32 nextTbtt, beaconintval, dtimperiod, beacontimeout; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2590 | struct ath9k_hw_capabilities *pCap = &ah->caps; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2591 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2592 | |
| 2593 | REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt)); |
| 2594 | |
| 2595 | REG_WRITE(ah, AR_BEACON_PERIOD, |
| 2596 | TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD)); |
| 2597 | REG_WRITE(ah, AR_DMA_BEACON_PERIOD, |
| 2598 | TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD)); |
| 2599 | |
| 2600 | REG_RMW_FIELD(ah, AR_RSSI_THR, |
| 2601 | AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold); |
| 2602 | |
| 2603 | beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD; |
| 2604 | |
| 2605 | if (bs->bs_sleepduration > beaconintval) |
| 2606 | beaconintval = bs->bs_sleepduration; |
| 2607 | |
| 2608 | dtimperiod = bs->bs_dtimperiod; |
| 2609 | if (bs->bs_sleepduration > dtimperiod) |
| 2610 | dtimperiod = bs->bs_sleepduration; |
| 2611 | |
| 2612 | if (beaconintval == dtimperiod) |
| 2613 | nextTbtt = bs->bs_nextdtim; |
| 2614 | else |
| 2615 | nextTbtt = bs->bs_nexttbtt; |
| 2616 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2617 | ath_print(common, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim); |
| 2618 | ath_print(common, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt); |
| 2619 | ath_print(common, ATH_DBG_BEACON, "beacon period %d\n", beaconintval); |
| 2620 | ath_print(common, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2621 | |
| 2622 | REG_WRITE(ah, AR_NEXT_DTIM, |
| 2623 | TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP)); |
| 2624 | REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP)); |
| 2625 | |
| 2626 | REG_WRITE(ah, AR_SLEEP1, |
| 2627 | SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT) |
| 2628 | | AR_SLEEP1_ASSUME_DTIM); |
| 2629 | |
Sujith | 60b67f5 | 2008-08-07 10:52:38 +0530 | [diff] [blame] | 2630 | if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2631 | beacontimeout = (BEACON_TIMEOUT_VAL << 3); |
| 2632 | else |
| 2633 | beacontimeout = MIN_BEACON_TIMEOUT_VAL; |
| 2634 | |
| 2635 | REG_WRITE(ah, AR_SLEEP2, |
| 2636 | SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT)); |
| 2637 | |
| 2638 | REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval)); |
| 2639 | REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod)); |
| 2640 | |
| 2641 | REG_SET_BIT(ah, AR_TIMER_MODE, |
| 2642 | AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN | |
| 2643 | AR_DTIM_TIMER_EN); |
| 2644 | |
Sujith | 4af9cf4 | 2009-02-12 10:06:47 +0530 | [diff] [blame] | 2645 | /* TSF Out of Range Threshold */ |
| 2646 | REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2647 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2648 | EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2649 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2650 | /*******************/ |
| 2651 | /* HW Capabilities */ |
| 2652 | /*******************/ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2653 | |
Gabor Juhos | a9a29ce | 2009-11-27 12:01:35 +0100 | [diff] [blame] | 2654 | int ath9k_hw_fill_cap_info(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2655 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2656 | struct ath9k_hw_capabilities *pCap = &ah->caps; |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 2657 | struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2658 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 2659 | struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw; |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 2660 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2661 | u16 capField = 0, eeval; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2662 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2663 | eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0); |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 2664 | regulatory->current_rd = eeval; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2665 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2666 | eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1); |
Sujith | fec0de1 | 2009-02-12 10:06:43 +0530 | [diff] [blame] | 2667 | if (AR_SREV_9285_10_OR_LATER(ah)) |
| 2668 | eeval |= AR9285_RDEXT_DEFAULT; |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 2669 | regulatory->current_rd_ext = eeval; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2670 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2671 | capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2672 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2673 | if (ah->opmode != NL80211_IFTYPE_AP && |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 2674 | ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) { |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 2675 | if (regulatory->current_rd == 0x64 || |
| 2676 | regulatory->current_rd == 0x65) |
| 2677 | regulatory->current_rd += 5; |
| 2678 | else if (regulatory->current_rd == 0x41) |
| 2679 | regulatory->current_rd = 0x43; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2680 | ath_print(common, ATH_DBG_REGULATORY, |
| 2681 | "regdomain mapped to 0x%x\n", regulatory->current_rd); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2682 | } |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 2683 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2684 | eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE); |
Gabor Juhos | a9a29ce | 2009-11-27 12:01:35 +0100 | [diff] [blame] | 2685 | if ((eeval & (AR5416_OPFLAGS_11G | AR5416_OPFLAGS_11A)) == 0) { |
| 2686 | ath_print(common, ATH_DBG_FATAL, |
| 2687 | "no band has been marked as supported in EEPROM.\n"); |
| 2688 | return -EINVAL; |
| 2689 | } |
| 2690 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2691 | bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2692 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2693 | if (eeval & AR5416_OPFLAGS_11A) { |
| 2694 | set_bit(ATH9K_MODE_11A, pCap->wireless_modes); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2695 | if (ah->config.ht_enable) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2696 | if (!(eeval & AR5416_OPFLAGS_N_5G_HT20)) |
| 2697 | set_bit(ATH9K_MODE_11NA_HT20, |
| 2698 | pCap->wireless_modes); |
| 2699 | if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) { |
| 2700 | set_bit(ATH9K_MODE_11NA_HT40PLUS, |
| 2701 | pCap->wireless_modes); |
| 2702 | set_bit(ATH9K_MODE_11NA_HT40MINUS, |
| 2703 | pCap->wireless_modes); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2704 | } |
| 2705 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2706 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2707 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2708 | if (eeval & AR5416_OPFLAGS_11G) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2709 | set_bit(ATH9K_MODE_11G, pCap->wireless_modes); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2710 | if (ah->config.ht_enable) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2711 | if (!(eeval & AR5416_OPFLAGS_N_2G_HT20)) |
| 2712 | set_bit(ATH9K_MODE_11NG_HT20, |
| 2713 | pCap->wireless_modes); |
| 2714 | if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) { |
| 2715 | set_bit(ATH9K_MODE_11NG_HT40PLUS, |
| 2716 | pCap->wireless_modes); |
| 2717 | set_bit(ATH9K_MODE_11NG_HT40MINUS, |
| 2718 | pCap->wireless_modes); |
| 2719 | } |
| 2720 | } |
Luis R. Rodriguez | 6f25542 | 2008-10-03 15:45:27 -0700 | [diff] [blame] | 2721 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2722 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2723 | 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] | 2724 | /* |
| 2725 | * For AR9271 we will temporarilly uses the rx chainmax as read from |
| 2726 | * the EEPROM. |
| 2727 | */ |
Sujith | 8147f5d | 2009-02-20 15:13:23 +0530 | [diff] [blame] | 2728 | if ((ah->hw_version.devid == AR5416_DEVID_PCI) && |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 2729 | !(eeval & AR5416_OPFLAGS_11A) && |
| 2730 | !(AR_SREV_9271(ah))) |
| 2731 | /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */ |
Sujith | 8147f5d | 2009-02-20 15:13:23 +0530 | [diff] [blame] | 2732 | pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7; |
| 2733 | else |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 2734 | /* Use rx_chainmask from EEPROM. */ |
Sujith | 8147f5d | 2009-02-20 15:13:23 +0530 | [diff] [blame] | 2735 | pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2736 | |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 2737 | if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0))) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2738 | ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2739 | |
| 2740 | pCap->low_2ghz_chan = 2312; |
| 2741 | pCap->high_2ghz_chan = 2732; |
| 2742 | |
| 2743 | pCap->low_5ghz_chan = 4920; |
| 2744 | pCap->high_5ghz_chan = 6100; |
| 2745 | |
| 2746 | pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP; |
| 2747 | pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP; |
| 2748 | pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM; |
| 2749 | |
| 2750 | pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP; |
| 2751 | pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP; |
| 2752 | pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM; |
| 2753 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2754 | if (ah->config.ht_enable) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2755 | pCap->hw_caps |= ATH9K_HW_CAP_HT; |
| 2756 | else |
| 2757 | pCap->hw_caps &= ~ATH9K_HW_CAP_HT; |
| 2758 | |
| 2759 | pCap->hw_caps |= ATH9K_HW_CAP_GTT; |
| 2760 | pCap->hw_caps |= ATH9K_HW_CAP_VEOL; |
| 2761 | pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK; |
| 2762 | pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH; |
| 2763 | |
| 2764 | if (capField & AR_EEPROM_EEPCAP_MAXQCU) |
| 2765 | pCap->total_queues = |
| 2766 | MS(capField, AR_EEPROM_EEPCAP_MAXQCU); |
| 2767 | else |
| 2768 | pCap->total_queues = ATH9K_NUM_TX_QUEUES; |
| 2769 | |
| 2770 | if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES) |
| 2771 | pCap->keycache_size = |
| 2772 | 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES); |
| 2773 | else |
| 2774 | pCap->keycache_size = AR_KEYTABLE_SIZE; |
| 2775 | |
| 2776 | pCap->hw_caps |= ATH9K_HW_CAP_FASTCC; |
Luis R. Rodriguez | f4709fd | 2009-11-24 21:37:57 -0500 | [diff] [blame] | 2777 | |
| 2778 | if (AR_SREV_9285(ah) || AR_SREV_9271(ah)) |
| 2779 | pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD >> 1; |
| 2780 | else |
| 2781 | pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2782 | |
Sujith | 5b5fa35 | 2010-03-17 14:25:15 +0530 | [diff] [blame] | 2783 | if (AR_SREV_9271(ah)) |
| 2784 | pCap->num_gpio_pins = AR9271_NUM_GPIO; |
| 2785 | else if (AR_SREV_9285_10_OR_LATER(ah)) |
Senthil Balasubramanian | cb33c41 | 2008-12-24 18:03:58 +0530 | [diff] [blame] | 2786 | pCap->num_gpio_pins = AR9285_NUM_GPIO; |
| 2787 | else if (AR_SREV_9280_10_OR_LATER(ah)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2788 | pCap->num_gpio_pins = AR928X_NUM_GPIO; |
| 2789 | else |
| 2790 | pCap->num_gpio_pins = AR_NUM_GPIO; |
| 2791 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2792 | if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) { |
| 2793 | pCap->hw_caps |= ATH9K_HW_CAP_CST; |
| 2794 | pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX; |
| 2795 | } else { |
| 2796 | pCap->rts_aggr_limit = (8 * 1024); |
| 2797 | } |
| 2798 | |
| 2799 | pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM; |
| 2800 | |
Senthil Balasubramanian | e97275c | 2008-11-13 18:00:02 +0530 | [diff] [blame] | 2801 | #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2802 | ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT); |
| 2803 | if (ah->rfsilent & EEP_RFSILENT_ENABLED) { |
| 2804 | ah->rfkill_gpio = |
| 2805 | MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL); |
| 2806 | ah->rfkill_polarity = |
| 2807 | MS(ah->rfsilent, EEP_RFSILENT_POLARITY); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2808 | |
| 2809 | pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT; |
| 2810 | } |
| 2811 | #endif |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 2812 | if (AR_SREV_9271(ah)) |
| 2813 | pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP; |
| 2814 | else |
| 2815 | pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2816 | |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 2817 | if (AR_SREV_9280(ah) || AR_SREV_9285(ah)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2818 | pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS; |
| 2819 | else |
| 2820 | pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS; |
| 2821 | |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 2822 | if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2823 | pCap->reg_cap = |
| 2824 | AR_EEPROM_EEREGCAP_EN_KK_NEW_11A | |
| 2825 | AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN | |
| 2826 | AR_EEPROM_EEREGCAP_EN_KK_U2 | |
| 2827 | AR_EEPROM_EEREGCAP_EN_KK_MIDBAND; |
| 2828 | } else { |
| 2829 | pCap->reg_cap = |
| 2830 | AR_EEPROM_EEREGCAP_EN_KK_NEW_11A | |
| 2831 | AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN; |
| 2832 | } |
| 2833 | |
Senthil Balasubramanian | ebb90cf | 2009-09-18 15:07:33 +0530 | [diff] [blame] | 2834 | /* Advertise midband for AR5416 with FCC midband set in eeprom */ |
| 2835 | if (regulatory->current_rd_ext & (1 << REG_EXT_FCC_MIDBAND) && |
| 2836 | AR_SREV_5416(ah)) |
| 2837 | pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2838 | |
| 2839 | pCap->num_antcfg_5ghz = |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2840 | ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2841 | pCap->num_antcfg_2ghz = |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2842 | ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2843 | |
Vasanthakumar Thiagarajan | fe12946 | 2009-09-09 15:25:50 +0530 | [diff] [blame] | 2844 | if (AR_SREV_9280_10_OR_LATER(ah) && |
Luis R. Rodriguez | a36cfbc | 2009-09-09 16:05:32 -0700 | [diff] [blame] | 2845 | ath9k_hw_btcoex_supported(ah)) { |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 2846 | btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO; |
| 2847 | btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO; |
Vasanthakumar Thiagarajan | 22f25d0 | 2009-08-26 21:08:47 +0530 | [diff] [blame] | 2848 | |
Vasanthakumar Thiagarajan | 8c8f9ba | 2009-09-09 15:25:52 +0530 | [diff] [blame] | 2849 | if (AR_SREV_9285(ah)) { |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 2850 | btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE; |
| 2851 | btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO; |
Vasanthakumar Thiagarajan | 8c8f9ba | 2009-09-09 15:25:52 +0530 | [diff] [blame] | 2852 | } else { |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 2853 | btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE; |
Vasanthakumar Thiagarajan | 8c8f9ba | 2009-09-09 15:25:52 +0530 | [diff] [blame] | 2854 | } |
Vasanthakumar Thiagarajan | 22f25d0 | 2009-08-26 21:08:47 +0530 | [diff] [blame] | 2855 | } else { |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 2856 | btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE; |
Vasanthakumar Thiagarajan | c97c92d | 2009-01-02 15:35:46 +0530 | [diff] [blame] | 2857 | } |
Gabor Juhos | a9a29ce | 2009-11-27 12:01:35 +0100 | [diff] [blame] | 2858 | |
| 2859 | return 0; |
Luis R. Rodriguez | 6f25542 | 2008-10-03 15:45:27 -0700 | [diff] [blame] | 2860 | } |
| 2861 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2862 | bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2863 | u32 capability, u32 *result) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2864 | { |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 2865 | struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2866 | switch (type) { |
| 2867 | case ATH9K_CAP_CIPHER: |
| 2868 | switch (capability) { |
| 2869 | case ATH9K_CIPHER_AES_CCM: |
| 2870 | case ATH9K_CIPHER_AES_OCB: |
| 2871 | case ATH9K_CIPHER_TKIP: |
| 2872 | case ATH9K_CIPHER_WEP: |
| 2873 | case ATH9K_CIPHER_MIC: |
| 2874 | case ATH9K_CIPHER_CLR: |
| 2875 | return true; |
| 2876 | default: |
| 2877 | return false; |
| 2878 | } |
| 2879 | case ATH9K_CAP_TKIP_MIC: |
| 2880 | switch (capability) { |
| 2881 | case 0: |
| 2882 | return true; |
| 2883 | case 1: |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2884 | return (ah->sta_id1_defaults & |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2885 | AR_STA_ID1_CRPT_MIC_ENABLE) ? true : |
| 2886 | false; |
| 2887 | } |
| 2888 | case ATH9K_CAP_TKIP_SPLIT: |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2889 | return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ? |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2890 | false : true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2891 | case ATH9K_CAP_MCAST_KEYSRCH: |
| 2892 | switch (capability) { |
| 2893 | case 0: |
| 2894 | return true; |
| 2895 | case 1: |
| 2896 | if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) { |
| 2897 | return false; |
| 2898 | } else { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2899 | return (ah->sta_id1_defaults & |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2900 | AR_STA_ID1_MCAST_KSRCH) ? true : |
| 2901 | false; |
| 2902 | } |
| 2903 | } |
| 2904 | return false; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2905 | case ATH9K_CAP_TXPOW: |
| 2906 | switch (capability) { |
| 2907 | case 0: |
| 2908 | return 0; |
| 2909 | case 1: |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 2910 | *result = regulatory->power_limit; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2911 | return 0; |
| 2912 | case 2: |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 2913 | *result = regulatory->max_power_level; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2914 | return 0; |
| 2915 | case 3: |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 2916 | *result = regulatory->tp_scale; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2917 | return 0; |
| 2918 | } |
| 2919 | return false; |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 2920 | case ATH9K_CAP_DS: |
| 2921 | return (AR_SREV_9280_20_OR_LATER(ah) && |
| 2922 | (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1)) |
| 2923 | ? false : true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2924 | default: |
| 2925 | return false; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2926 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2927 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2928 | EXPORT_SYMBOL(ath9k_hw_getcapability); |
Luis R. Rodriguez | 6f25542 | 2008-10-03 15:45:27 -0700 | [diff] [blame] | 2929 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2930 | bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2931 | u32 capability, u32 setting, int *status) |
| 2932 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2933 | switch (type) { |
| 2934 | case ATH9K_CAP_TKIP_MIC: |
| 2935 | if (setting) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2936 | ah->sta_id1_defaults |= |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2937 | AR_STA_ID1_CRPT_MIC_ENABLE; |
| 2938 | else |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2939 | ah->sta_id1_defaults &= |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2940 | ~AR_STA_ID1_CRPT_MIC_ENABLE; |
| 2941 | return true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2942 | case ATH9K_CAP_MCAST_KEYSRCH: |
| 2943 | if (setting) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2944 | ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2945 | else |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2946 | ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2947 | return true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2948 | default: |
| 2949 | return false; |
| 2950 | } |
| 2951 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2952 | EXPORT_SYMBOL(ath9k_hw_setcapability); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2953 | |
| 2954 | /****************************/ |
| 2955 | /* GPIO / RFKILL / Antennae */ |
| 2956 | /****************************/ |
| 2957 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2958 | static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2959 | u32 gpio, u32 type) |
| 2960 | { |
| 2961 | int addr; |
| 2962 | u32 gpio_shift, tmp; |
| 2963 | |
| 2964 | if (gpio > 11) |
| 2965 | addr = AR_GPIO_OUTPUT_MUX3; |
| 2966 | else if (gpio > 5) |
| 2967 | addr = AR_GPIO_OUTPUT_MUX2; |
| 2968 | else |
| 2969 | addr = AR_GPIO_OUTPUT_MUX1; |
| 2970 | |
| 2971 | gpio_shift = (gpio % 6) * 5; |
| 2972 | |
| 2973 | if (AR_SREV_9280_20_OR_LATER(ah) |
| 2974 | || (addr != AR_GPIO_OUTPUT_MUX1)) { |
| 2975 | REG_RMW(ah, addr, (type << gpio_shift), |
| 2976 | (0x1f << gpio_shift)); |
| 2977 | } else { |
| 2978 | tmp = REG_READ(ah, addr); |
| 2979 | tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0); |
| 2980 | tmp &= ~(0x1f << gpio_shift); |
| 2981 | tmp |= (type << gpio_shift); |
| 2982 | REG_WRITE(ah, addr, tmp); |
| 2983 | } |
| 2984 | } |
| 2985 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2986 | void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2987 | { |
| 2988 | u32 gpio_shift; |
| 2989 | |
Luis R. Rodriguez | 9680e8a | 2009-09-13 23:28:00 -0700 | [diff] [blame] | 2990 | BUG_ON(gpio >= ah->caps.num_gpio_pins); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2991 | |
| 2992 | gpio_shift = gpio << 1; |
| 2993 | |
| 2994 | REG_RMW(ah, |
| 2995 | AR_GPIO_OE_OUT, |
| 2996 | (AR_GPIO_OE_OUT_DRV_NO << gpio_shift), |
| 2997 | (AR_GPIO_OE_OUT_DRV << gpio_shift)); |
| 2998 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2999 | EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3000 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3001 | u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3002 | { |
Senthil Balasubramanian | cb33c41 | 2008-12-24 18:03:58 +0530 | [diff] [blame] | 3003 | #define MS_REG_READ(x, y) \ |
| 3004 | (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y))) |
| 3005 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3006 | if (gpio >= ah->caps.num_gpio_pins) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3007 | return 0xffffffff; |
| 3008 | |
Felix Fietkau | 783dfca | 2010-04-15 17:38:11 -0400 | [diff] [blame] | 3009 | if (AR_SREV_9300_20_OR_LATER(ah)) |
| 3010 | return MS_REG_READ(AR9300, gpio) != 0; |
| 3011 | else if (AR_SREV_9271(ah)) |
Sujith | 5b5fa35 | 2010-03-17 14:25:15 +0530 | [diff] [blame] | 3012 | return MS_REG_READ(AR9271, gpio) != 0; |
| 3013 | else if (AR_SREV_9287_10_OR_LATER(ah)) |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 3014 | return MS_REG_READ(AR9287, gpio) != 0; |
| 3015 | else if (AR_SREV_9285_10_OR_LATER(ah)) |
Senthil Balasubramanian | cb33c41 | 2008-12-24 18:03:58 +0530 | [diff] [blame] | 3016 | return MS_REG_READ(AR9285, gpio) != 0; |
| 3017 | else if (AR_SREV_9280_10_OR_LATER(ah)) |
| 3018 | return MS_REG_READ(AR928X, gpio) != 0; |
| 3019 | else |
| 3020 | return MS_REG_READ(AR, gpio) != 0; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3021 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 3022 | EXPORT_SYMBOL(ath9k_hw_gpio_get); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3023 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3024 | void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3025 | u32 ah_signal_type) |
| 3026 | { |
| 3027 | u32 gpio_shift; |
| 3028 | |
| 3029 | ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type); |
| 3030 | |
| 3031 | gpio_shift = 2 * gpio; |
| 3032 | |
| 3033 | REG_RMW(ah, |
| 3034 | AR_GPIO_OE_OUT, |
| 3035 | (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift), |
| 3036 | (AR_GPIO_OE_OUT_DRV << gpio_shift)); |
| 3037 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 3038 | EXPORT_SYMBOL(ath9k_hw_cfg_output); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3039 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3040 | void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3041 | { |
Sujith | 5b5fa35 | 2010-03-17 14:25:15 +0530 | [diff] [blame] | 3042 | if (AR_SREV_9271(ah)) |
| 3043 | val = ~val; |
| 3044 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3045 | REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio), |
| 3046 | AR_GPIO_BIT(gpio)); |
| 3047 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 3048 | EXPORT_SYMBOL(ath9k_hw_set_gpio); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3049 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3050 | u32 ath9k_hw_getdefantenna(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3051 | { |
| 3052 | return REG_READ(ah, AR_DEF_ANTENNA) & 0x7; |
| 3053 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 3054 | EXPORT_SYMBOL(ath9k_hw_getdefantenna); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3055 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3056 | void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3057 | { |
| 3058 | REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7)); |
| 3059 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 3060 | EXPORT_SYMBOL(ath9k_hw_setantenna); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3061 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3062 | /*********************/ |
| 3063 | /* General Operation */ |
| 3064 | /*********************/ |
| 3065 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3066 | u32 ath9k_hw_getrxfilter(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3067 | { |
| 3068 | u32 bits = REG_READ(ah, AR_RX_FILTER); |
| 3069 | u32 phybits = REG_READ(ah, AR_PHY_ERR); |
| 3070 | |
| 3071 | if (phybits & AR_PHY_ERR_RADAR) |
| 3072 | bits |= ATH9K_RX_FILTER_PHYRADAR; |
| 3073 | if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING)) |
| 3074 | bits |= ATH9K_RX_FILTER_PHYERR; |
| 3075 | |
| 3076 | return bits; |
| 3077 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 3078 | EXPORT_SYMBOL(ath9k_hw_getrxfilter); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3079 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3080 | void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3081 | { |
| 3082 | u32 phybits; |
| 3083 | |
Sujith | 7ea310b | 2009-09-03 12:08:43 +0530 | [diff] [blame] | 3084 | REG_WRITE(ah, AR_RX_FILTER, bits); |
| 3085 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3086 | phybits = 0; |
| 3087 | if (bits & ATH9K_RX_FILTER_PHYRADAR) |
| 3088 | phybits |= AR_PHY_ERR_RADAR; |
| 3089 | if (bits & ATH9K_RX_FILTER_PHYERR) |
| 3090 | phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING; |
| 3091 | REG_WRITE(ah, AR_PHY_ERR, phybits); |
| 3092 | |
| 3093 | if (phybits) |
| 3094 | REG_WRITE(ah, AR_RXCFG, |
| 3095 | REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA); |
| 3096 | else |
| 3097 | REG_WRITE(ah, AR_RXCFG, |
| 3098 | REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA); |
| 3099 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 3100 | EXPORT_SYMBOL(ath9k_hw_setrxfilter); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3101 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3102 | bool ath9k_hw_phy_disable(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3103 | { |
Senthil Balasubramanian | 63a75b9 | 2009-09-18 15:07:03 +0530 | [diff] [blame] | 3104 | if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM)) |
| 3105 | return false; |
| 3106 | |
| 3107 | ath9k_hw_init_pll(ah, NULL); |
| 3108 | return true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3109 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 3110 | EXPORT_SYMBOL(ath9k_hw_phy_disable); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3111 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3112 | bool ath9k_hw_disable(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3113 | { |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 3114 | if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3115 | return false; |
| 3116 | |
Senthil Balasubramanian | 63a75b9 | 2009-09-18 15:07:03 +0530 | [diff] [blame] | 3117 | if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD)) |
| 3118 | return false; |
| 3119 | |
| 3120 | ath9k_hw_init_pll(ah, NULL); |
| 3121 | return true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3122 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 3123 | EXPORT_SYMBOL(ath9k_hw_disable); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3124 | |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 3125 | void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3126 | { |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 3127 | struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3128 | struct ath9k_channel *chan = ah->curchan; |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 3129 | struct ieee80211_channel *channel = chan->chan; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3130 | |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 3131 | regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3132 | |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 3133 | ah->eep_ops->set_txpower(ah, chan, |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 3134 | ath9k_regd_get_ctl(regulatory, chan), |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 3135 | channel->max_antenna_gain * 2, |
| 3136 | channel->max_power * 2, |
| 3137 | min((u32) MAX_RATE_POWER, |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 3138 | (u32) regulatory->power_limit)); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3139 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 3140 | EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3141 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3142 | void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3143 | { |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 3144 | memcpy(ath9k_hw_common(ah)->macaddr, mac, ETH_ALEN); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3145 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 3146 | EXPORT_SYMBOL(ath9k_hw_setmac); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3147 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3148 | void ath9k_hw_setopmode(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3149 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3150 | ath9k_hw_set_operating_mode(ah, ah->opmode); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3151 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 3152 | EXPORT_SYMBOL(ath9k_hw_setopmode); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3153 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3154 | void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3155 | { |
| 3156 | REG_WRITE(ah, AR_MCAST_FIL0, filter0); |
| 3157 | REG_WRITE(ah, AR_MCAST_FIL1, filter1); |
| 3158 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 3159 | EXPORT_SYMBOL(ath9k_hw_setmcastfilter); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3160 | |
Luis R. Rodriguez | f2b2143 | 2009-09-10 08:50:20 -0700 | [diff] [blame] | 3161 | void ath9k_hw_write_associd(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3162 | { |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 3163 | struct ath_common *common = ath9k_hw_common(ah); |
| 3164 | |
| 3165 | REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid)); |
| 3166 | REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) | |
| 3167 | ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S)); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3168 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 3169 | EXPORT_SYMBOL(ath9k_hw_write_associd); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3170 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3171 | u64 ath9k_hw_gettsf64(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3172 | { |
| 3173 | u64 tsf; |
| 3174 | |
| 3175 | tsf = REG_READ(ah, AR_TSF_U32); |
| 3176 | tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32); |
| 3177 | |
| 3178 | return tsf; |
| 3179 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 3180 | EXPORT_SYMBOL(ath9k_hw_gettsf64); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3181 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3182 | void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64) |
Alina Friedrichsen | 27abe06 | 2009-01-23 05:44:21 +0100 | [diff] [blame] | 3183 | { |
Alina Friedrichsen | 27abe06 | 2009-01-23 05:44:21 +0100 | [diff] [blame] | 3184 | REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff); |
Alina Friedrichsen | b9a1619 | 2009-03-02 23:28:38 +0100 | [diff] [blame] | 3185 | REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff); |
Alina Friedrichsen | 27abe06 | 2009-01-23 05:44:21 +0100 | [diff] [blame] | 3186 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 3187 | EXPORT_SYMBOL(ath9k_hw_settsf64); |
Alina Friedrichsen | 27abe06 | 2009-01-23 05:44:21 +0100 | [diff] [blame] | 3188 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3189 | void ath9k_hw_reset_tsf(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3190 | { |
Gabor Juhos | f9b604f | 2009-06-21 00:02:15 +0200 | [diff] [blame] | 3191 | if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0, |
| 3192 | AH_TSF_WRITE_TIMEOUT)) |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 3193 | ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, |
| 3194 | "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n"); |
Gabor Juhos | f9b604f | 2009-06-21 00:02:15 +0200 | [diff] [blame] | 3195 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3196 | REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3197 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 3198 | EXPORT_SYMBOL(ath9k_hw_reset_tsf); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3199 | |
Sujith | 54e4cec | 2009-08-07 09:45:09 +0530 | [diff] [blame] | 3200 | void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3201 | { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3202 | if (setting) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3203 | ah->misc_mode |= AR_PCU_TX_ADD_TSF; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3204 | else |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3205 | ah->misc_mode &= ~AR_PCU_TX_ADD_TSF; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3206 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 3207 | EXPORT_SYMBOL(ath9k_hw_set_tsfadjust); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3208 | |
Luis R. Rodriguez | 30cbd42 | 2009-11-03 16:10:46 -0800 | [diff] [blame] | 3209 | /* |
| 3210 | * Extend 15-bit time stamp from rx descriptor to |
| 3211 | * a full 64-bit TSF using the current h/w TSF. |
| 3212 | */ |
| 3213 | u64 ath9k_hw_extend_tsf(struct ath_hw *ah, u32 rstamp) |
| 3214 | { |
| 3215 | u64 tsf; |
| 3216 | |
| 3217 | tsf = ath9k_hw_gettsf64(ah); |
| 3218 | if ((tsf & 0x7fff) < rstamp) |
| 3219 | tsf -= 0x8000; |
| 3220 | return (tsf & ~0x7fff) | rstamp; |
| 3221 | } |
| 3222 | EXPORT_SYMBOL(ath9k_hw_extend_tsf); |
| 3223 | |
Luis R. Rodriguez | 25c56ee | 2009-09-13 23:04:44 -0700 | [diff] [blame] | 3224 | void ath9k_hw_set11nmac2040(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3225 | { |
Luis R. Rodriguez | 25c56ee | 2009-09-13 23:04:44 -0700 | [diff] [blame] | 3226 | struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3227 | u32 macmode; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3228 | |
Luis R. Rodriguez | 25c56ee | 2009-09-13 23:04:44 -0700 | [diff] [blame] | 3229 | if (conf_is_ht40(conf) && !ah->config.cwm_ignore_extcca) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3230 | macmode = AR_2040_JOINED_RX_CLEAR; |
| 3231 | else |
| 3232 | macmode = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3233 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3234 | REG_WRITE(ah, AR_2040_MODE, macmode); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3235 | } |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3236 | |
| 3237 | /* HW Generic timers configuration */ |
| 3238 | |
| 3239 | static const struct ath_gen_timer_configuration gen_tmr_configuration[] = |
| 3240 | { |
| 3241 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 3242 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 3243 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 3244 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 3245 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 3246 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 3247 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 3248 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 3249 | {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001}, |
| 3250 | {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4, |
| 3251 | AR_NDP2_TIMER_MODE, 0x0002}, |
| 3252 | {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4, |
| 3253 | AR_NDP2_TIMER_MODE, 0x0004}, |
| 3254 | {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4, |
| 3255 | AR_NDP2_TIMER_MODE, 0x0008}, |
| 3256 | {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4, |
| 3257 | AR_NDP2_TIMER_MODE, 0x0010}, |
| 3258 | {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4, |
| 3259 | AR_NDP2_TIMER_MODE, 0x0020}, |
| 3260 | {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4, |
| 3261 | AR_NDP2_TIMER_MODE, 0x0040}, |
| 3262 | {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4, |
| 3263 | AR_NDP2_TIMER_MODE, 0x0080} |
| 3264 | }; |
| 3265 | |
| 3266 | /* HW generic timer primitives */ |
| 3267 | |
| 3268 | /* compute and clear index of rightmost 1 */ |
| 3269 | static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask) |
| 3270 | { |
| 3271 | u32 b; |
| 3272 | |
| 3273 | b = *mask; |
| 3274 | b &= (0-b); |
| 3275 | *mask &= ~b; |
| 3276 | b *= debruijn32; |
| 3277 | b >>= 27; |
| 3278 | |
| 3279 | return timer_table->gen_timer_index[b]; |
| 3280 | } |
| 3281 | |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 3282 | u32 ath9k_hw_gettsf32(struct ath_hw *ah) |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3283 | { |
| 3284 | return REG_READ(ah, AR_TSF_L32); |
| 3285 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 3286 | EXPORT_SYMBOL(ath9k_hw_gettsf32); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3287 | |
| 3288 | struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah, |
| 3289 | void (*trigger)(void *), |
| 3290 | void (*overflow)(void *), |
| 3291 | void *arg, |
| 3292 | u8 timer_index) |
| 3293 | { |
| 3294 | struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers; |
| 3295 | struct ath_gen_timer *timer; |
| 3296 | |
| 3297 | timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL); |
| 3298 | |
| 3299 | if (timer == NULL) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 3300 | ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL, |
| 3301 | "Failed to allocate memory" |
| 3302 | "for hw timer[%d]\n", timer_index); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3303 | return NULL; |
| 3304 | } |
| 3305 | |
| 3306 | /* allocate a hardware generic timer slot */ |
| 3307 | timer_table->timers[timer_index] = timer; |
| 3308 | timer->index = timer_index; |
| 3309 | timer->trigger = trigger; |
| 3310 | timer->overflow = overflow; |
| 3311 | timer->arg = arg; |
| 3312 | |
| 3313 | return timer; |
| 3314 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 3315 | EXPORT_SYMBOL(ath_gen_timer_alloc); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3316 | |
Luis R. Rodriguez | cd9bf68 | 2009-09-13 02:08:34 -0700 | [diff] [blame] | 3317 | void ath9k_hw_gen_timer_start(struct ath_hw *ah, |
| 3318 | struct ath_gen_timer *timer, |
| 3319 | u32 timer_next, |
| 3320 | u32 timer_period) |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3321 | { |
| 3322 | struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers; |
| 3323 | u32 tsf; |
| 3324 | |
| 3325 | BUG_ON(!timer_period); |
| 3326 | |
| 3327 | set_bit(timer->index, &timer_table->timer_mask.timer_bits); |
| 3328 | |
| 3329 | tsf = ath9k_hw_gettsf32(ah); |
| 3330 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 3331 | ath_print(ath9k_hw_common(ah), ATH_DBG_HWTIMER, |
| 3332 | "curent tsf %x period %x" |
| 3333 | "timer_next %x\n", tsf, timer_period, timer_next); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3334 | |
| 3335 | /* |
| 3336 | * Pull timer_next forward if the current TSF already passed it |
| 3337 | * because of software latency |
| 3338 | */ |
| 3339 | if (timer_next < tsf) |
| 3340 | timer_next = tsf + timer_period; |
| 3341 | |
| 3342 | /* |
| 3343 | * Program generic timer registers |
| 3344 | */ |
| 3345 | REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr, |
| 3346 | timer_next); |
| 3347 | REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr, |
| 3348 | timer_period); |
| 3349 | REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr, |
| 3350 | gen_tmr_configuration[timer->index].mode_mask); |
| 3351 | |
| 3352 | /* Enable both trigger and thresh interrupt masks */ |
| 3353 | REG_SET_BIT(ah, AR_IMR_S5, |
| 3354 | (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) | |
| 3355 | SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG))); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3356 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 3357 | EXPORT_SYMBOL(ath9k_hw_gen_timer_start); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3358 | |
Luis R. Rodriguez | cd9bf68 | 2009-09-13 02:08:34 -0700 | [diff] [blame] | 3359 | 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] | 3360 | { |
| 3361 | struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers; |
| 3362 | |
| 3363 | if ((timer->index < AR_FIRST_NDP_TIMER) || |
| 3364 | (timer->index >= ATH_MAX_GEN_TIMER)) { |
| 3365 | return; |
| 3366 | } |
| 3367 | |
| 3368 | /* Clear generic timer enable bits. */ |
| 3369 | REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr, |
| 3370 | gen_tmr_configuration[timer->index].mode_mask); |
| 3371 | |
| 3372 | /* Disable both trigger and thresh interrupt masks */ |
| 3373 | REG_CLR_BIT(ah, AR_IMR_S5, |
| 3374 | (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) | |
| 3375 | SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG))); |
| 3376 | |
| 3377 | clear_bit(timer->index, &timer_table->timer_mask.timer_bits); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3378 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 3379 | EXPORT_SYMBOL(ath9k_hw_gen_timer_stop); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3380 | |
| 3381 | void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer) |
| 3382 | { |
| 3383 | struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers; |
| 3384 | |
| 3385 | /* free the hardware generic timer slot */ |
| 3386 | timer_table->timers[timer->index] = NULL; |
| 3387 | kfree(timer); |
| 3388 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 3389 | EXPORT_SYMBOL(ath_gen_timer_free); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3390 | |
| 3391 | /* |
| 3392 | * Generic Timer Interrupts handling |
| 3393 | */ |
| 3394 | void ath_gen_timer_isr(struct ath_hw *ah) |
| 3395 | { |
| 3396 | struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers; |
| 3397 | struct ath_gen_timer *timer; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 3398 | struct ath_common *common = ath9k_hw_common(ah); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3399 | u32 trigger_mask, thresh_mask, index; |
| 3400 | |
| 3401 | /* get hardware generic timer interrupt status */ |
| 3402 | trigger_mask = ah->intr_gen_timer_trigger; |
| 3403 | thresh_mask = ah->intr_gen_timer_thresh; |
| 3404 | trigger_mask &= timer_table->timer_mask.val; |
| 3405 | thresh_mask &= timer_table->timer_mask.val; |
| 3406 | |
| 3407 | trigger_mask &= ~thresh_mask; |
| 3408 | |
| 3409 | while (thresh_mask) { |
| 3410 | index = rightmost_index(timer_table, &thresh_mask); |
| 3411 | timer = timer_table->timers[index]; |
| 3412 | BUG_ON(!timer); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 3413 | ath_print(common, ATH_DBG_HWTIMER, |
| 3414 | "TSF overflow for Gen timer %d\n", index); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3415 | timer->overflow(timer->arg); |
| 3416 | } |
| 3417 | |
| 3418 | while (trigger_mask) { |
| 3419 | index = rightmost_index(timer_table, &trigger_mask); |
| 3420 | timer = timer_table->timers[index]; |
| 3421 | BUG_ON(!timer); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 3422 | ath_print(common, ATH_DBG_HWTIMER, |
| 3423 | "Gen timer[%d] trigger\n", index); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3424 | timer->trigger(timer->arg); |
| 3425 | } |
| 3426 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 3427 | EXPORT_SYMBOL(ath_gen_timer_isr); |
Luis R. Rodriguez | 2da4f01 | 2009-10-27 12:59:33 -0400 | [diff] [blame] | 3428 | |
Sujith | 05020d2 | 2010-03-17 14:25:23 +0530 | [diff] [blame] | 3429 | /********/ |
| 3430 | /* HTC */ |
| 3431 | /********/ |
| 3432 | |
| 3433 | void ath9k_hw_htc_resetinit(struct ath_hw *ah) |
| 3434 | { |
| 3435 | ah->htc_reset_init = true; |
| 3436 | } |
| 3437 | EXPORT_SYMBOL(ath9k_hw_htc_resetinit); |
| 3438 | |
Luis R. Rodriguez | 2da4f01 | 2009-10-27 12:59:33 -0400 | [diff] [blame] | 3439 | static struct { |
| 3440 | u32 version; |
| 3441 | const char * name; |
| 3442 | } ath_mac_bb_names[] = { |
| 3443 | /* Devices with external radios */ |
| 3444 | { AR_SREV_VERSION_5416_PCI, "5416" }, |
| 3445 | { AR_SREV_VERSION_5416_PCIE, "5418" }, |
| 3446 | { AR_SREV_VERSION_9100, "9100" }, |
| 3447 | { AR_SREV_VERSION_9160, "9160" }, |
| 3448 | /* Single-chip solutions */ |
| 3449 | { AR_SREV_VERSION_9280, "9280" }, |
| 3450 | { AR_SREV_VERSION_9285, "9285" }, |
Luis R. Rodriguez | 1115847 | 2009-10-27 12:59:35 -0400 | [diff] [blame] | 3451 | { AR_SREV_VERSION_9287, "9287" }, |
| 3452 | { AR_SREV_VERSION_9271, "9271" }, |
Luis R. Rodriguez | 2da4f01 | 2009-10-27 12:59:33 -0400 | [diff] [blame] | 3453 | }; |
| 3454 | |
| 3455 | /* For devices with external radios */ |
| 3456 | static struct { |
| 3457 | u16 version; |
| 3458 | const char * name; |
| 3459 | } ath_rf_names[] = { |
| 3460 | { 0, "5133" }, |
| 3461 | { AR_RAD5133_SREV_MAJOR, "5133" }, |
| 3462 | { AR_RAD5122_SREV_MAJOR, "5122" }, |
| 3463 | { AR_RAD2133_SREV_MAJOR, "2133" }, |
| 3464 | { AR_RAD2122_SREV_MAJOR, "2122" } |
| 3465 | }; |
| 3466 | |
| 3467 | /* |
| 3468 | * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown. |
| 3469 | */ |
Luis R. Rodriguez | f934c4d | 2009-10-27 12:59:34 -0400 | [diff] [blame] | 3470 | 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] | 3471 | { |
| 3472 | int i; |
| 3473 | |
| 3474 | for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) { |
| 3475 | if (ath_mac_bb_names[i].version == mac_bb_version) { |
| 3476 | return ath_mac_bb_names[i].name; |
| 3477 | } |
| 3478 | } |
| 3479 | |
| 3480 | return "????"; |
| 3481 | } |
Luis R. Rodriguez | 2da4f01 | 2009-10-27 12:59:33 -0400 | [diff] [blame] | 3482 | |
| 3483 | /* |
| 3484 | * Return the RF name. "????" is returned if the RF is unknown. |
| 3485 | * Used for devices with external radios. |
| 3486 | */ |
Luis R. Rodriguez | f934c4d | 2009-10-27 12:59:34 -0400 | [diff] [blame] | 3487 | static const char *ath9k_hw_rf_name(u16 rf_version) |
Luis R. Rodriguez | 2da4f01 | 2009-10-27 12:59:33 -0400 | [diff] [blame] | 3488 | { |
| 3489 | int i; |
| 3490 | |
| 3491 | for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) { |
| 3492 | if (ath_rf_names[i].version == rf_version) { |
| 3493 | return ath_rf_names[i].name; |
| 3494 | } |
| 3495 | } |
| 3496 | |
| 3497 | return "????"; |
| 3498 | } |
Luis R. Rodriguez | f934c4d | 2009-10-27 12:59:34 -0400 | [diff] [blame] | 3499 | |
| 3500 | void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len) |
| 3501 | { |
| 3502 | int used; |
| 3503 | |
| 3504 | /* chipsets >= AR9280 are single-chip */ |
| 3505 | if (AR_SREV_9280_10_OR_LATER(ah)) { |
| 3506 | used = snprintf(hw_name, len, |
| 3507 | "Atheros AR%s Rev:%x", |
| 3508 | ath9k_hw_mac_bb_name(ah->hw_version.macVersion), |
| 3509 | ah->hw_version.macRev); |
| 3510 | } |
| 3511 | else { |
| 3512 | used = snprintf(hw_name, len, |
| 3513 | "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x", |
| 3514 | ath9k_hw_mac_bb_name(ah->hw_version.macVersion), |
| 3515 | ah->hw_version.macRev, |
| 3516 | ath9k_hw_rf_name((ah->hw_version.analog5GhzRev & |
| 3517 | AR_RADIO_SREV_MAJOR)), |
| 3518 | ah->hw_version.phyRev); |
| 3519 | } |
| 3520 | |
| 3521 | hw_name[used] = '\0'; |
| 3522 | } |
| 3523 | EXPORT_SYMBOL(ath9k_hw_name); |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 3524 | |
| 3525 | /* Sets up the AR5008/AR9001/AR9002 hardware familiy callbacks */ |
| 3526 | static void ar9002_hw_attach_ops(struct ath_hw *ah) |
| 3527 | { |
| 3528 | struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah); |
| 3529 | struct ath_hw_ops *ops = ath9k_hw_ops(ah); |
| 3530 | |
| 3531 | priv_ops->init_cal_settings = ar9002_hw_init_cal_settings; |
| 3532 | priv_ops->init_mode_regs = ar9002_hw_init_mode_regs; |
| 3533 | priv_ops->macversion_supported = ar9002_hw_macversion_supported; |
| 3534 | |
| 3535 | ops->config_pci_powersave = ar9002_hw_configpcipowersave; |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 3536 | |
Luis R. Rodriguez | 8525f28 | 2010-04-15 17:38:19 -0400 | [diff] [blame] | 3537 | ar5008_hw_attach_phy_ops(ah); |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 3538 | if (AR_SREV_9280_10_OR_LATER(ah)) |
| 3539 | ar9002_hw_attach_phy_ops(ah); |
Luis R. Rodriguez | 8525f28 | 2010-04-15 17:38:19 -0400 | [diff] [blame] | 3540 | } |
| 3541 | |
| 3542 | /* Sets up the AR9003 hardware familiy callbacks */ |
| 3543 | static void ar9003_hw_attach_ops(struct ath_hw *ah) |
| 3544 | { |
| 3545 | ar9003_hw_attach_phy_ops(ah); |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 3546 | } |