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