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> |
Vasanthakumar Thiagarajan | 7b6840a | 2009-09-07 17:46:49 +0530 | [diff] [blame] | 19 | #include <linux/pci.h> |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 20 | |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 21 | #include "hw.h" |
Sujith | 394cf0a | 2009-02-09 13:26:54 +0530 | [diff] [blame] | 22 | #include "ath9k.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 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 29 | static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type); |
| 30 | static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 31 | enum ath9k_ht_macmode macmode); |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 32 | static u32 ath9k_hw_ini_fixup(struct ath_hw *ah, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 33 | struct ar5416_eeprom_def *pEepData, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 34 | u32 reg, u32 value); |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 35 | static void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan); |
| 36 | static void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 37 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 38 | /********************/ |
| 39 | /* Helper Functions */ |
| 40 | /********************/ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 41 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 42 | static u32 ath9k_hw_mac_usec(struct ath_hw *ah, u32 clks) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 43 | { |
Luis R. Rodriguez | 4febf7b | 2008-12-23 15:58:48 -0800 | [diff] [blame] | 44 | struct ieee80211_conf *conf = &ah->ah_sc->hw->conf; |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 45 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 46 | if (!ah->curchan) /* should really check for CCK instead */ |
Luis R. Rodriguez | 4febf7b | 2008-12-23 15:58:48 -0800 | [diff] [blame] | 47 | return clks / ATH9K_CLOCK_RATE_CCK; |
| 48 | if (conf->channel->band == IEEE80211_BAND_2GHZ) |
| 49 | return clks / ATH9K_CLOCK_RATE_2GHZ_OFDM; |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 50 | |
Luis R. Rodriguez | 4febf7b | 2008-12-23 15:58:48 -0800 | [diff] [blame] | 51 | return clks / ATH9K_CLOCK_RATE_5GHZ_OFDM; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 52 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 53 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 54 | static u32 ath9k_hw_mac_to_usec(struct ath_hw *ah, u32 clks) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 55 | { |
Luis R. Rodriguez | 4febf7b | 2008-12-23 15:58:48 -0800 | [diff] [blame] | 56 | struct ieee80211_conf *conf = &ah->ah_sc->hw->conf; |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 57 | |
Luis R. Rodriguez | 4febf7b | 2008-12-23 15:58:48 -0800 | [diff] [blame] | 58 | if (conf_is_ht40(conf)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 59 | return ath9k_hw_mac_usec(ah, clks) / 2; |
| 60 | else |
| 61 | return ath9k_hw_mac_usec(ah, clks); |
| 62 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 63 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 64 | static u32 ath9k_hw_mac_clks(struct ath_hw *ah, u32 usecs) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 65 | { |
Luis R. Rodriguez | 4febf7b | 2008-12-23 15:58:48 -0800 | [diff] [blame] | 66 | struct ieee80211_conf *conf = &ah->ah_sc->hw->conf; |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 67 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 68 | if (!ah->curchan) /* should really check for CCK instead */ |
Luis R. Rodriguez | 4febf7b | 2008-12-23 15:58:48 -0800 | [diff] [blame] | 69 | return usecs *ATH9K_CLOCK_RATE_CCK; |
| 70 | if (conf->channel->band == IEEE80211_BAND_2GHZ) |
| 71 | return usecs *ATH9K_CLOCK_RATE_2GHZ_OFDM; |
| 72 | return usecs *ATH9K_CLOCK_RATE_5GHZ_OFDM; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 73 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 74 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 75 | static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 76 | { |
Luis R. Rodriguez | 4febf7b | 2008-12-23 15:58:48 -0800 | [diff] [blame] | 77 | struct ieee80211_conf *conf = &ah->ah_sc->hw->conf; |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 78 | |
Luis R. Rodriguez | 4febf7b | 2008-12-23 15:58:48 -0800 | [diff] [blame] | 79 | if (conf_is_ht40(conf)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 80 | return ath9k_hw_mac_clks(ah, usecs) * 2; |
| 81 | else |
| 82 | return ath9k_hw_mac_clks(ah, usecs); |
| 83 | } |
| 84 | |
Gabor Juhos | fb4a3d3 | 2009-04-29 13:01:58 +0200 | [diff] [blame] | 85 | /* |
| 86 | * Read and write, they both share the same lock. We do this to serialize |
| 87 | * reads and writes on Atheros 802.11n PCI devices only. This is required |
| 88 | * as the FIFO on these devices can only accept sanely 2 requests. After |
| 89 | * that the device goes bananas. Serializing the reads/writes prevents this |
| 90 | * from happening. |
| 91 | */ |
| 92 | |
| 93 | void ath9k_iowrite32(struct ath_hw *ah, u32 reg_offset, u32 val) |
| 94 | { |
| 95 | if (ah->config.serialize_regmode == SER_REG_MODE_ON) { |
| 96 | unsigned long flags; |
| 97 | spin_lock_irqsave(&ah->ah_sc->sc_serial_rw, flags); |
| 98 | iowrite32(val, ah->ah_sc->mem + reg_offset); |
| 99 | spin_unlock_irqrestore(&ah->ah_sc->sc_serial_rw, flags); |
| 100 | } else |
| 101 | iowrite32(val, ah->ah_sc->mem + reg_offset); |
| 102 | } |
| 103 | |
| 104 | unsigned int ath9k_ioread32(struct ath_hw *ah, u32 reg_offset) |
| 105 | { |
| 106 | u32 val; |
| 107 | if (ah->config.serialize_regmode == SER_REG_MODE_ON) { |
| 108 | unsigned long flags; |
| 109 | spin_lock_irqsave(&ah->ah_sc->sc_serial_rw, flags); |
| 110 | val = ioread32(ah->ah_sc->mem + reg_offset); |
| 111 | spin_unlock_irqrestore(&ah->ah_sc->sc_serial_rw, flags); |
| 112 | } else |
| 113 | val = ioread32(ah->ah_sc->mem + reg_offset); |
| 114 | return val; |
| 115 | } |
| 116 | |
Sujith | 0caa7b1 | 2009-02-16 13:23:20 +0530 | [diff] [blame] | 117 | 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] | 118 | { |
| 119 | int i; |
| 120 | |
Sujith | 0caa7b1 | 2009-02-16 13:23:20 +0530 | [diff] [blame] | 121 | BUG_ON(timeout < AH_TIME_QUANTUM); |
| 122 | |
| 123 | for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 124 | if ((REG_READ(ah, reg) & mask) == val) |
| 125 | return true; |
| 126 | |
| 127 | udelay(AH_TIME_QUANTUM); |
| 128 | } |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 129 | |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 130 | DPRINTF(ah, ATH_DBG_ANY, |
Sujith | 0caa7b1 | 2009-02-16 13:23:20 +0530 | [diff] [blame] | 131 | "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n", |
| 132 | timeout, reg, REG_READ(ah, reg), mask, val); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 133 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 134 | return false; |
| 135 | } |
| 136 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 137 | u32 ath9k_hw_reverse_bits(u32 val, u32 n) |
| 138 | { |
| 139 | u32 retval; |
| 140 | int i; |
| 141 | |
| 142 | for (i = 0, retval = 0; i < n; i++) { |
| 143 | retval = (retval << 1) | (val & 1); |
| 144 | val >>= 1; |
| 145 | } |
| 146 | return retval; |
| 147 | } |
| 148 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 149 | bool ath9k_get_channel_edges(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 150 | u16 flags, u16 *low, |
| 151 | u16 *high) |
| 152 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 153 | struct ath9k_hw_capabilities *pCap = &ah->caps; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 154 | |
| 155 | if (flags & CHANNEL_5GHZ) { |
| 156 | *low = pCap->low_5ghz_chan; |
| 157 | *high = pCap->high_5ghz_chan; |
| 158 | return true; |
| 159 | } |
| 160 | if ((flags & CHANNEL_2GHZ)) { |
| 161 | *low = pCap->low_2ghz_chan; |
| 162 | *high = pCap->high_2ghz_chan; |
| 163 | return true; |
| 164 | } |
| 165 | return false; |
| 166 | } |
| 167 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 168 | u16 ath9k_hw_computetxtime(struct ath_hw *ah, |
Luis R. Rodriguez | 4f0fc7c | 2009-05-06 02:20:00 -0400 | [diff] [blame] | 169 | const struct ath_rate_table *rates, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 170 | u32 frameLen, u16 rateix, |
| 171 | bool shortPreamble) |
| 172 | { |
| 173 | u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime; |
| 174 | u32 kbps; |
| 175 | |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 176 | kbps = rates->info[rateix].ratekbps; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 177 | |
| 178 | if (kbps == 0) |
| 179 | return 0; |
| 180 | |
| 181 | switch (rates->info[rateix].phy) { |
Sujith | 46d14a5 | 2008-11-18 09:08:13 +0530 | [diff] [blame] | 182 | case WLAN_RC_PHY_CCK: |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 183 | phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS; |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 184 | if (shortPreamble && rates->info[rateix].short_preamble) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 185 | phyTime >>= 1; |
| 186 | numBits = frameLen << 3; |
| 187 | txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps); |
| 188 | break; |
Sujith | 46d14a5 | 2008-11-18 09:08:13 +0530 | [diff] [blame] | 189 | case WLAN_RC_PHY_OFDM: |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 190 | if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 191 | bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000; |
| 192 | numBits = OFDM_PLCP_BITS + (frameLen << 3); |
| 193 | numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol); |
| 194 | txTime = OFDM_SIFS_TIME_QUARTER |
| 195 | + OFDM_PREAMBLE_TIME_QUARTER |
| 196 | + (numSymbols * OFDM_SYMBOL_TIME_QUARTER); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 197 | } else if (ah->curchan && |
| 198 | IS_CHAN_HALF_RATE(ah->curchan)) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 199 | bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000; |
| 200 | numBits = OFDM_PLCP_BITS + (frameLen << 3); |
| 201 | numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol); |
| 202 | txTime = OFDM_SIFS_TIME_HALF + |
| 203 | OFDM_PREAMBLE_TIME_HALF |
| 204 | + (numSymbols * OFDM_SYMBOL_TIME_HALF); |
| 205 | } else { |
| 206 | bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000; |
| 207 | numBits = OFDM_PLCP_BITS + (frameLen << 3); |
| 208 | numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol); |
| 209 | txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME |
| 210 | + (numSymbols * OFDM_SYMBOL_TIME); |
| 211 | } |
| 212 | break; |
| 213 | default: |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 214 | DPRINTF(ah, ATH_DBG_FATAL, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 215 | "Unknown phy %u (rate ix %u)\n", |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 216 | rates->info[rateix].phy, rateix); |
| 217 | txTime = 0; |
| 218 | break; |
| 219 | } |
| 220 | |
| 221 | return txTime; |
| 222 | } |
| 223 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 224 | void ath9k_hw_get_channel_centers(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 225 | struct ath9k_channel *chan, |
| 226 | struct chan_centers *centers) |
| 227 | { |
| 228 | int8_t extoff; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 229 | |
| 230 | if (!IS_CHAN_HT40(chan)) { |
| 231 | centers->ctl_center = centers->ext_center = |
| 232 | centers->synth_center = chan->channel; |
| 233 | return; |
| 234 | } |
| 235 | |
| 236 | if ((chan->chanmode == CHANNEL_A_HT40PLUS) || |
| 237 | (chan->chanmode == CHANNEL_G_HT40PLUS)) { |
| 238 | centers->synth_center = |
| 239 | chan->channel + HT40_CHANNEL_CENTER_SHIFT; |
| 240 | extoff = 1; |
| 241 | } else { |
| 242 | centers->synth_center = |
| 243 | chan->channel - HT40_CHANNEL_CENTER_SHIFT; |
| 244 | extoff = -1; |
| 245 | } |
| 246 | |
| 247 | centers->ctl_center = |
| 248 | centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT); |
| 249 | centers->ext_center = |
| 250 | centers->synth_center + (extoff * |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 251 | ((ah->extprotspacing == ATH9K_HT_EXTPROTSPACING_20) ? |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 252 | HT40_CHANNEL_CENTER_SHIFT : 15)); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | /******************/ |
| 256 | /* Chip Revisions */ |
| 257 | /******************/ |
| 258 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 259 | static void ath9k_hw_read_revisions(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 260 | { |
| 261 | u32 val; |
| 262 | |
| 263 | val = REG_READ(ah, AR_SREV) & AR_SREV_ID; |
| 264 | |
| 265 | if (val == 0xFF) { |
| 266 | val = REG_READ(ah, AR_SREV); |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 267 | ah->hw_version.macVersion = |
| 268 | (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S; |
| 269 | ah->hw_version.macRev = MS(val, AR_SREV_REVISION2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 270 | ah->is_pciexpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 271 | } else { |
| 272 | if (!AR_SREV_9100(ah)) |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 273 | ah->hw_version.macVersion = MS(val, AR_SREV_VERSION); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 274 | |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 275 | ah->hw_version.macRev = val & AR_SREV_REVISION; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 276 | |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 277 | if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 278 | ah->is_pciexpress = true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 279 | } |
| 280 | } |
| 281 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 282 | static int ath9k_hw_get_radiorev(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 283 | { |
| 284 | u32 val; |
| 285 | int i; |
| 286 | |
| 287 | REG_WRITE(ah, AR_PHY(0x36), 0x00007058); |
| 288 | |
| 289 | for (i = 0; i < 8; i++) |
| 290 | REG_WRITE(ah, AR_PHY(0x20), 0x00010000); |
| 291 | val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff; |
| 292 | val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4); |
| 293 | |
| 294 | return ath9k_hw_reverse_bits(val, 8); |
| 295 | } |
| 296 | |
| 297 | /************************************/ |
| 298 | /* HW Attach, Detach, Init Routines */ |
| 299 | /************************************/ |
| 300 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 301 | static void ath9k_hw_disablepcie(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 302 | { |
Sujith | feed029 | 2009-01-29 11:37:35 +0530 | [diff] [blame] | 303 | if (AR_SREV_9100(ah)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 304 | return; |
| 305 | |
| 306 | REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00); |
| 307 | REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924); |
| 308 | REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029); |
| 309 | REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824); |
| 310 | REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579); |
| 311 | REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000); |
| 312 | REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40); |
| 313 | REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554); |
| 314 | REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007); |
| 315 | |
| 316 | REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000); |
| 317 | } |
| 318 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 319 | static bool ath9k_hw_chip_test(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 320 | { |
| 321 | u32 regAddr[2] = { AR_STA_ID0, AR_PHY_BASE + (8 << 2) }; |
| 322 | u32 regHold[2]; |
| 323 | u32 patternData[4] = { 0x55555555, |
| 324 | 0xaaaaaaaa, |
| 325 | 0x66666666, |
| 326 | 0x99999999 }; |
| 327 | int i, j; |
| 328 | |
| 329 | for (i = 0; i < 2; i++) { |
| 330 | u32 addr = regAddr[i]; |
| 331 | u32 wrData, rdData; |
| 332 | |
| 333 | regHold[i] = REG_READ(ah, addr); |
| 334 | for (j = 0; j < 0x100; j++) { |
| 335 | wrData = (j << 16) | j; |
| 336 | REG_WRITE(ah, addr, wrData); |
| 337 | rdData = REG_READ(ah, addr); |
| 338 | if (rdData != wrData) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 339 | DPRINTF(ah, ATH_DBG_FATAL, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 340 | "address test failed " |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 341 | "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n", |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 342 | addr, wrData, rdData); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 343 | return false; |
| 344 | } |
| 345 | } |
| 346 | for (j = 0; j < 4; j++) { |
| 347 | wrData = patternData[j]; |
| 348 | REG_WRITE(ah, addr, wrData); |
| 349 | rdData = REG_READ(ah, addr); |
| 350 | if (wrData != rdData) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 351 | DPRINTF(ah, ATH_DBG_FATAL, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 352 | "address test failed " |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 353 | "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n", |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 354 | addr, wrData, rdData); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 355 | return false; |
| 356 | } |
| 357 | } |
| 358 | REG_WRITE(ah, regAddr[i], regHold[i]); |
| 359 | } |
| 360 | udelay(100); |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 361 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 362 | return true; |
| 363 | } |
| 364 | |
| 365 | static const char *ath9k_hw_devname(u16 devid) |
| 366 | { |
| 367 | switch (devid) { |
| 368 | case AR5416_DEVID_PCI: |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 369 | return "Atheros 5416"; |
Benoit PAPILLAULT | 392dff8 | 2008-11-06 22:26:49 +0100 | [diff] [blame] | 370 | case AR5416_DEVID_PCIE: |
| 371 | return "Atheros 5418"; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 372 | case AR9160_DEVID_PCI: |
| 373 | return "Atheros 9160"; |
Gabor Juhos | 0c1aa49 | 2009-01-14 20:17:12 +0100 | [diff] [blame] | 374 | case AR5416_AR9100_DEVID: |
| 375 | return "Atheros 9100"; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 376 | case AR9280_DEVID_PCI: |
| 377 | case AR9280_DEVID_PCIE: |
| 378 | return "Atheros 9280"; |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 379 | case AR9285_DEVID_PCIE: |
| 380 | return "Atheros 9285"; |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 381 | case AR5416_DEVID_AR9287_PCI: |
| 382 | case AR5416_DEVID_AR9287_PCIE: |
| 383 | return "Atheros 9287"; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | return NULL; |
| 387 | } |
| 388 | |
Luis R. Rodriguez | b8b0f37 | 2009-08-03 12:24:43 -0700 | [diff] [blame] | 389 | static void ath9k_hw_init_config(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 390 | { |
| 391 | int i; |
| 392 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 393 | ah->config.dma_beacon_response_time = 2; |
| 394 | ah->config.sw_beacon_response_time = 10; |
| 395 | ah->config.additional_swba_backoff = 0; |
| 396 | ah->config.ack_6mb = 0x0; |
| 397 | ah->config.cwm_ignore_extcca = 0; |
| 398 | ah->config.pcie_powersave_enable = 0; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 399 | ah->config.pcie_clock_req = 0; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 400 | ah->config.pcie_waen = 0; |
| 401 | ah->config.analog_shiftreg = 1; |
| 402 | ah->config.ht_enable = 1; |
| 403 | ah->config.ofdm_trig_low = 200; |
| 404 | ah->config.ofdm_trig_high = 500; |
| 405 | ah->config.cck_trig_high = 200; |
| 406 | ah->config.cck_trig_low = 100; |
| 407 | ah->config.enable_ani = 1; |
Sujith | 1cf6873 | 2009-08-13 09:34:32 +0530 | [diff] [blame] | 408 | ah->config.diversity_control = ATH9K_ANT_VARIABLE; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 409 | ah->config.antenna_switch_swap = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 410 | |
| 411 | for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 412 | ah->config.spurchans[i][0] = AR_NO_SPUR; |
| 413 | ah->config.spurchans[i][1] = AR_NO_SPUR; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 414 | } |
| 415 | |
Sujith | 0ef1f16 | 2009-03-30 15:28:35 +0530 | [diff] [blame] | 416 | ah->config.intr_mitigation = true; |
Luis R. Rodriguez | 6158425 | 2009-03-12 18:18:49 -0400 | [diff] [blame] | 417 | |
| 418 | /* |
| 419 | * We need this for PCI devices only (Cardbus, PCI, miniPCI) |
| 420 | * _and_ if on non-uniprocessor systems (Multiprocessor/HT). |
| 421 | * This means we use it for all AR5416 devices, and the few |
| 422 | * minor PCI AR9280 devices out there. |
| 423 | * |
| 424 | * Serialization is required because these devices do not handle |
| 425 | * well the case of two concurrent reads/writes due to the latency |
| 426 | * involved. During one read/write another read/write can be issued |
| 427 | * on another CPU while the previous read/write may still be working |
| 428 | * on our hardware, if we hit this case the hardware poops in a loop. |
| 429 | * We prevent this by serializing reads and writes. |
| 430 | * |
| 431 | * This issue is not present on PCI-Express devices or pre-AR5416 |
| 432 | * devices (legacy, 802.11abg). |
| 433 | */ |
| 434 | if (num_possible_cpus() > 1) |
David S. Miller | 2d6a5e9 | 2009-03-17 15:01:30 -0700 | [diff] [blame] | 435 | ah->config.serialize_regmode = SER_REG_MODE_AUTO; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 436 | } |
| 437 | |
Luis R. Rodriguez | 50aca25 | 2009-08-03 12:24:42 -0700 | [diff] [blame] | 438 | static void ath9k_hw_init_defaults(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 439 | { |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 440 | struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah); |
| 441 | |
| 442 | regulatory->country_code = CTRY_DEFAULT; |
| 443 | regulatory->power_limit = MAX_RATE_POWER; |
| 444 | regulatory->tp_scale = ATH9K_TP_SCALE_MAX; |
| 445 | |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 446 | ah->hw_version.magic = AR5416_MAGIC; |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 447 | ah->hw_version.subvendorid = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 448 | |
| 449 | ah->ah_flags = 0; |
Luis R. Rodriguez | 8df5d1b | 2009-08-03 12:24:37 -0700 | [diff] [blame] | 450 | if (ah->hw_version.devid == AR5416_AR9100_DEVID) |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 451 | ah->hw_version.macVersion = AR_SREV_VERSION_9100; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 452 | if (!AR_SREV_9100(ah)) |
| 453 | ah->ah_flags = AH_USE_EEPROM; |
| 454 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 455 | ah->atim_window = 0; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 456 | ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE; |
| 457 | ah->beacon_interval = 100; |
| 458 | ah->enable_32kHz_clock = DONT_USE_32KHZ; |
| 459 | ah->slottime = (u32) -1; |
| 460 | ah->acktimeout = (u32) -1; |
| 461 | ah->ctstimeout = (u32) -1; |
| 462 | ah->globaltxtimeout = (u32) -1; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 463 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 464 | ah->gbeacon_rate = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 465 | |
Gabor Juhos | cbdec97 | 2009-07-24 17:27:22 +0200 | [diff] [blame] | 466 | ah->power_mode = ATH9K_PM_UNDEFINED; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 469 | static int ath9k_hw_rfattach(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 470 | { |
| 471 | bool rfStatus = false; |
| 472 | int ecode = 0; |
| 473 | |
| 474 | rfStatus = ath9k_hw_init_rf(ah, &ecode); |
| 475 | if (!rfStatus) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 476 | DPRINTF(ah, ATH_DBG_FATAL, |
Sujith | d8baa93 | 2009-03-30 15:28:25 +0530 | [diff] [blame] | 477 | "RF setup failed, status: %u\n", ecode); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 478 | return ecode; |
| 479 | } |
| 480 | |
| 481 | return 0; |
| 482 | } |
| 483 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 484 | static int ath9k_hw_rf_claim(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 485 | { |
| 486 | u32 val; |
| 487 | |
| 488 | REG_WRITE(ah, AR_PHY(0), 0x00000007); |
| 489 | |
| 490 | val = ath9k_hw_get_radiorev(ah); |
| 491 | switch (val & AR_RADIO_SREV_MAJOR) { |
| 492 | case 0: |
| 493 | val = AR_RAD5133_SREV_MAJOR; |
| 494 | break; |
| 495 | case AR_RAD5133_SREV_MAJOR: |
| 496 | case AR_RAD5122_SREV_MAJOR: |
| 497 | case AR_RAD2133_SREV_MAJOR: |
| 498 | case AR_RAD2122_SREV_MAJOR: |
| 499 | break; |
| 500 | default: |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 501 | DPRINTF(ah, ATH_DBG_FATAL, |
Sujith | d8baa93 | 2009-03-30 15:28:25 +0530 | [diff] [blame] | 502 | "Radio Chip Rev 0x%02X not supported\n", |
| 503 | val & AR_RADIO_SREV_MAJOR); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 504 | return -EOPNOTSUPP; |
| 505 | } |
| 506 | |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 507 | ah->hw_version.analog5GhzRev = val; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 508 | |
| 509 | return 0; |
| 510 | } |
| 511 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 512 | static int ath9k_hw_init_macaddr(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 513 | { |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame^] | 514 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 515 | u32 sum; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 516 | int i; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 517 | u16 eeval; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 518 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 519 | sum = 0; |
| 520 | for (i = 0; i < 3; i++) { |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 521 | eeval = ah->eep_ops->get_eeprom(ah, AR_EEPROM_MAC(i)); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 522 | sum += eeval; |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame^] | 523 | common->macaddr[2 * i] = eeval >> 8; |
| 524 | common->macaddr[2 * i + 1] = eeval & 0xff; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 525 | } |
Sujith | d8baa93 | 2009-03-30 15:28:25 +0530 | [diff] [blame] | 526 | if (sum == 0 || sum == 0xffff * 3) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 527 | return -EADDRNOTAVAIL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 528 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 529 | return 0; |
| 530 | } |
| 531 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 532 | static void ath9k_hw_init_rxgain_ini(struct ath_hw *ah) |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 533 | { |
| 534 | u32 rxgain_type; |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 535 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 536 | if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_17) { |
| 537 | rxgain_type = ah->eep_ops->get_eeprom(ah, EEP_RXGAIN_TYPE); |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 538 | |
| 539 | if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 540 | INIT_INI_ARRAY(&ah->iniModesRxGain, |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 541 | ar9280Modes_backoff_13db_rxgain_9280_2, |
| 542 | ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2), 6); |
| 543 | else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 544 | INIT_INI_ARRAY(&ah->iniModesRxGain, |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 545 | ar9280Modes_backoff_23db_rxgain_9280_2, |
| 546 | ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 6); |
| 547 | else |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 548 | INIT_INI_ARRAY(&ah->iniModesRxGain, |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 549 | ar9280Modes_original_rxgain_9280_2, |
| 550 | ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6); |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 551 | } else { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 552 | INIT_INI_ARRAY(&ah->iniModesRxGain, |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 553 | ar9280Modes_original_rxgain_9280_2, |
| 554 | ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6); |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 555 | } |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 556 | } |
| 557 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 558 | static void ath9k_hw_init_txgain_ini(struct ath_hw *ah) |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 559 | { |
| 560 | u32 txgain_type; |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 561 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 562 | if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_19) { |
| 563 | txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE); |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 564 | |
| 565 | if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 566 | INIT_INI_ARRAY(&ah->iniModesTxGain, |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 567 | ar9280Modes_high_power_tx_gain_9280_2, |
| 568 | ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 6); |
| 569 | else |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 570 | INIT_INI_ARRAY(&ah->iniModesTxGain, |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 571 | ar9280Modes_original_tx_gain_9280_2, |
| 572 | ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6); |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 573 | } else { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 574 | INIT_INI_ARRAY(&ah->iniModesTxGain, |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 575 | ar9280Modes_original_tx_gain_9280_2, |
| 576 | ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6); |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 577 | } |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 578 | } |
| 579 | |
Luis R. Rodriguez | f637cfd | 2009-08-03 12:24:46 -0700 | [diff] [blame] | 580 | static int ath9k_hw_post_init(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 581 | { |
| 582 | int ecode; |
| 583 | |
Sujith | d8baa93 | 2009-03-30 15:28:25 +0530 | [diff] [blame] | 584 | if (!ath9k_hw_chip_test(ah)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 585 | return -ENODEV; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 586 | |
| 587 | ecode = ath9k_hw_rf_claim(ah); |
| 588 | if (ecode != 0) |
| 589 | return ecode; |
| 590 | |
Luis R. Rodriguez | f637cfd | 2009-08-03 12:24:46 -0700 | [diff] [blame] | 591 | ecode = ath9k_hw_eeprom_init(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 592 | if (ecode != 0) |
| 593 | return ecode; |
Sujith | 7d01b22 | 2009-03-13 08:55:55 +0530 | [diff] [blame] | 594 | |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 595 | DPRINTF(ah, ATH_DBG_CONFIG, "Eeprom VER: %d, REV: %d\n", |
Sujith | 7d01b22 | 2009-03-13 08:55:55 +0530 | [diff] [blame] | 596 | ah->eep_ops->get_eeprom_ver(ah), ah->eep_ops->get_eeprom_rev(ah)); |
| 597 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 598 | ecode = ath9k_hw_rfattach(ah); |
| 599 | if (ecode != 0) |
| 600 | return ecode; |
| 601 | |
| 602 | if (!AR_SREV_9100(ah)) { |
| 603 | ath9k_hw_ani_setup(ah); |
Luis R. Rodriguez | f637cfd | 2009-08-03 12:24:46 -0700 | [diff] [blame] | 604 | ath9k_hw_ani_init(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 605 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 606 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 607 | return 0; |
| 608 | } |
| 609 | |
Luis R. Rodriguez | ee2bb46 | 2009-08-03 12:24:39 -0700 | [diff] [blame] | 610 | static bool ath9k_hw_devid_supported(u16 devid) |
| 611 | { |
| 612 | switch (devid) { |
| 613 | case AR5416_DEVID_PCI: |
| 614 | case AR5416_DEVID_PCIE: |
| 615 | case AR5416_AR9100_DEVID: |
| 616 | case AR9160_DEVID_PCI: |
| 617 | case AR9280_DEVID_PCI: |
| 618 | case AR9280_DEVID_PCIE: |
| 619 | case AR9285_DEVID_PCIE: |
| 620 | case AR5416_DEVID_AR9287_PCI: |
| 621 | case AR5416_DEVID_AR9287_PCIE: |
| 622 | return true; |
| 623 | default: |
| 624 | break; |
| 625 | } |
| 626 | return false; |
| 627 | } |
| 628 | |
Luis R. Rodriguez | f9d4a66 | 2009-08-03 12:24:41 -0700 | [diff] [blame] | 629 | static bool ath9k_hw_macversion_supported(u32 macversion) |
| 630 | { |
| 631 | switch (macversion) { |
| 632 | case AR_SREV_VERSION_5416_PCI: |
| 633 | case AR_SREV_VERSION_5416_PCIE: |
| 634 | case AR_SREV_VERSION_9160: |
| 635 | case AR_SREV_VERSION_9100: |
| 636 | case AR_SREV_VERSION_9280: |
| 637 | case AR_SREV_VERSION_9285: |
| 638 | case AR_SREV_VERSION_9287: |
| 639 | return true; |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 640 | /* Not yet */ |
| 641 | case AR_SREV_VERSION_9271: |
Luis R. Rodriguez | f9d4a66 | 2009-08-03 12:24:41 -0700 | [diff] [blame] | 642 | default: |
| 643 | break; |
| 644 | } |
| 645 | return false; |
| 646 | } |
| 647 | |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 648 | static void ath9k_hw_init_cal_settings(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 649 | { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 650 | if (AR_SREV_9160_10_OR_LATER(ah)) { |
| 651 | if (AR_SREV_9280_10_OR_LATER(ah)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 652 | ah->iq_caldata.calData = &iq_cal_single_sample; |
| 653 | ah->adcgain_caldata.calData = |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 654 | &adc_gain_cal_single_sample; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 655 | ah->adcdc_caldata.calData = |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 656 | &adc_dc_cal_single_sample; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 657 | ah->adcdc_calinitdata.calData = |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 658 | &adc_init_dc_cal; |
| 659 | } else { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 660 | ah->iq_caldata.calData = &iq_cal_multi_sample; |
| 661 | ah->adcgain_caldata.calData = |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 662 | &adc_gain_cal_multi_sample; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 663 | ah->adcdc_caldata.calData = |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 664 | &adc_dc_cal_multi_sample; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 665 | ah->adcdc_calinitdata.calData = |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 666 | &adc_init_dc_cal; |
| 667 | } |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 668 | 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] | 669 | } |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 670 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 671 | |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 672 | static void ath9k_hw_init_mode_regs(struct ath_hw *ah) |
| 673 | { |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 674 | if (AR_SREV_9271(ah)) { |
| 675 | INIT_INI_ARRAY(&ah->iniModes, ar9271Modes_9271_1_0, |
| 676 | ARRAY_SIZE(ar9271Modes_9271_1_0), 6); |
| 677 | INIT_INI_ARRAY(&ah->iniCommon, ar9271Common_9271_1_0, |
| 678 | ARRAY_SIZE(ar9271Common_9271_1_0), 2); |
| 679 | return; |
| 680 | } |
| 681 | |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 682 | if (AR_SREV_9287_11_OR_LATER(ah)) { |
| 683 | INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_1, |
| 684 | ARRAY_SIZE(ar9287Modes_9287_1_1), 6); |
| 685 | INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_1, |
| 686 | ARRAY_SIZE(ar9287Common_9287_1_1), 2); |
| 687 | if (ah->config.pcie_clock_req) |
| 688 | INIT_INI_ARRAY(&ah->iniPcieSerdes, |
| 689 | ar9287PciePhy_clkreq_off_L1_9287_1_1, |
| 690 | ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_1), 2); |
| 691 | else |
| 692 | INIT_INI_ARRAY(&ah->iniPcieSerdes, |
| 693 | ar9287PciePhy_clkreq_always_on_L1_9287_1_1, |
| 694 | ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_1), |
| 695 | 2); |
| 696 | } else if (AR_SREV_9287_10_OR_LATER(ah)) { |
| 697 | INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_0, |
| 698 | ARRAY_SIZE(ar9287Modes_9287_1_0), 6); |
| 699 | INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_0, |
| 700 | ARRAY_SIZE(ar9287Common_9287_1_0), 2); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 701 | |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 702 | if (ah->config.pcie_clock_req) |
| 703 | INIT_INI_ARRAY(&ah->iniPcieSerdes, |
| 704 | ar9287PciePhy_clkreq_off_L1_9287_1_0, |
| 705 | ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_0), 2); |
| 706 | else |
| 707 | INIT_INI_ARRAY(&ah->iniPcieSerdes, |
| 708 | ar9287PciePhy_clkreq_always_on_L1_9287_1_0, |
| 709 | ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_0), |
| 710 | 2); |
| 711 | } else if (AR_SREV_9285_12_OR_LATER(ah)) { |
| 712 | |
Senthil Balasubramanian | 4e84516 | 2009-03-06 11:24:10 +0530 | [diff] [blame] | 713 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 714 | INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 715 | ARRAY_SIZE(ar9285Modes_9285_1_2), 6); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 716 | INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 717 | ARRAY_SIZE(ar9285Common_9285_1_2), 2); |
| 718 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 719 | if (ah->config.pcie_clock_req) { |
| 720 | INIT_INI_ARRAY(&ah->iniPcieSerdes, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 721 | ar9285PciePhy_clkreq_off_L1_9285_1_2, |
| 722 | ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2); |
| 723 | } else { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 724 | INIT_INI_ARRAY(&ah->iniPcieSerdes, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 725 | ar9285PciePhy_clkreq_always_on_L1_9285_1_2, |
| 726 | ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2), |
| 727 | 2); |
| 728 | } |
| 729 | } else if (AR_SREV_9285_10_OR_LATER(ah)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 730 | INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 731 | ARRAY_SIZE(ar9285Modes_9285), 6); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 732 | INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 733 | ARRAY_SIZE(ar9285Common_9285), 2); |
| 734 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 735 | if (ah->config.pcie_clock_req) { |
| 736 | INIT_INI_ARRAY(&ah->iniPcieSerdes, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 737 | ar9285PciePhy_clkreq_off_L1_9285, |
| 738 | ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2); |
| 739 | } else { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 740 | INIT_INI_ARRAY(&ah->iniPcieSerdes, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 741 | ar9285PciePhy_clkreq_always_on_L1_9285, |
| 742 | ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285), 2); |
| 743 | } |
| 744 | } else if (AR_SREV_9280_20_OR_LATER(ah)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 745 | INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 746 | ARRAY_SIZE(ar9280Modes_9280_2), 6); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 747 | INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 748 | ARRAY_SIZE(ar9280Common_9280_2), 2); |
| 749 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 750 | if (ah->config.pcie_clock_req) { |
| 751 | INIT_INI_ARRAY(&ah->iniPcieSerdes, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 752 | ar9280PciePhy_clkreq_off_L1_9280, |
| 753 | ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 754 | } else { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 755 | INIT_INI_ARRAY(&ah->iniPcieSerdes, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 756 | ar9280PciePhy_clkreq_always_on_L1_9280, |
| 757 | ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 758 | } |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 759 | INIT_INI_ARRAY(&ah->iniModesAdditional, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 760 | ar9280Modes_fast_clock_9280_2, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 761 | ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 762 | } else if (AR_SREV_9280_10_OR_LATER(ah)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 763 | INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 764 | ARRAY_SIZE(ar9280Modes_9280), 6); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 765 | INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 766 | ARRAY_SIZE(ar9280Common_9280), 2); |
| 767 | } else if (AR_SREV_9160_10_OR_LATER(ah)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 768 | INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 769 | ARRAY_SIZE(ar5416Modes_9160), 6); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 770 | INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 771 | ARRAY_SIZE(ar5416Common_9160), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 772 | INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9160, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 773 | ARRAY_SIZE(ar5416Bank0_9160), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 774 | INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9160, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 775 | ARRAY_SIZE(ar5416BB_RfGain_9160), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 776 | INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9160, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 777 | ARRAY_SIZE(ar5416Bank1_9160), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 778 | INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9160, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 779 | ARRAY_SIZE(ar5416Bank2_9160), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 780 | INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9160, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 781 | ARRAY_SIZE(ar5416Bank3_9160), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 782 | INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9160, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 783 | ARRAY_SIZE(ar5416Bank6_9160), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 784 | INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9160, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 785 | ARRAY_SIZE(ar5416Bank6TPC_9160), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 786 | INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9160, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 787 | ARRAY_SIZE(ar5416Bank7_9160), 2); |
| 788 | if (AR_SREV_9160_11(ah)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 789 | INIT_INI_ARRAY(&ah->iniAddac, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 790 | ar5416Addac_91601_1, |
| 791 | ARRAY_SIZE(ar5416Addac_91601_1), 2); |
| 792 | } else { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 793 | INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 794 | ARRAY_SIZE(ar5416Addac_9160), 2); |
| 795 | } |
| 796 | } else if (AR_SREV_9100_OR_LATER(ah)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 797 | INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 798 | ARRAY_SIZE(ar5416Modes_9100), 6); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 799 | INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 800 | ARRAY_SIZE(ar5416Common_9100), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 801 | INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9100, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 802 | ARRAY_SIZE(ar5416Bank0_9100), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 803 | INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9100, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 804 | ARRAY_SIZE(ar5416BB_RfGain_9100), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 805 | INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9100, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 806 | ARRAY_SIZE(ar5416Bank1_9100), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 807 | INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9100, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 808 | ARRAY_SIZE(ar5416Bank2_9100), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 809 | INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9100, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 810 | ARRAY_SIZE(ar5416Bank3_9100), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 811 | INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9100, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 812 | ARRAY_SIZE(ar5416Bank6_9100), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 813 | INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9100, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 814 | ARRAY_SIZE(ar5416Bank6TPC_9100), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 815 | INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9100, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 816 | ARRAY_SIZE(ar5416Bank7_9100), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 817 | INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 818 | ARRAY_SIZE(ar5416Addac_9100), 2); |
| 819 | } else { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 820 | INIT_INI_ARRAY(&ah->iniModes, ar5416Modes, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 821 | ARRAY_SIZE(ar5416Modes), 6); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 822 | INIT_INI_ARRAY(&ah->iniCommon, ar5416Common, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 823 | ARRAY_SIZE(ar5416Common), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 824 | INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 825 | ARRAY_SIZE(ar5416Bank0), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 826 | INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 827 | ARRAY_SIZE(ar5416BB_RfGain), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 828 | INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 829 | ARRAY_SIZE(ar5416Bank1), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 830 | INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 831 | ARRAY_SIZE(ar5416Bank2), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 832 | INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 833 | ARRAY_SIZE(ar5416Bank3), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 834 | INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 835 | ARRAY_SIZE(ar5416Bank6), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 836 | INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 837 | ARRAY_SIZE(ar5416Bank6TPC), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 838 | INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 839 | ARRAY_SIZE(ar5416Bank7), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 840 | INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 841 | ARRAY_SIZE(ar5416Addac), 2); |
| 842 | } |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 843 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 844 | |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 845 | static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah) |
| 846 | { |
Vivek Natarajan | b37fa87 | 2009-09-23 16:27:27 +0530 | [diff] [blame] | 847 | if (AR_SREV_9287_11_OR_LATER(ah)) |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 848 | INIT_INI_ARRAY(&ah->iniModesRxGain, |
| 849 | ar9287Modes_rx_gain_9287_1_1, |
| 850 | ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_1), 6); |
| 851 | else if (AR_SREV_9287_10(ah)) |
| 852 | INIT_INI_ARRAY(&ah->iniModesRxGain, |
| 853 | ar9287Modes_rx_gain_9287_1_0, |
| 854 | ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_0), 6); |
| 855 | else if (AR_SREV_9280_20(ah)) |
| 856 | ath9k_hw_init_rxgain_ini(ah); |
| 857 | |
Vivek Natarajan | b37fa87 | 2009-09-23 16:27:27 +0530 | [diff] [blame] | 858 | if (AR_SREV_9287_11_OR_LATER(ah)) { |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 859 | INIT_INI_ARRAY(&ah->iniModesTxGain, |
| 860 | ar9287Modes_tx_gain_9287_1_1, |
| 861 | ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_1), 6); |
| 862 | } else if (AR_SREV_9287_10(ah)) { |
| 863 | INIT_INI_ARRAY(&ah->iniModesTxGain, |
| 864 | ar9287Modes_tx_gain_9287_1_0, |
| 865 | ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_0), 6); |
| 866 | } else if (AR_SREV_9280_20(ah)) { |
| 867 | ath9k_hw_init_txgain_ini(ah); |
| 868 | } else if (AR_SREV_9285_12_OR_LATER(ah)) { |
Senthil Balasubramanian | 4e84516 | 2009-03-06 11:24:10 +0530 | [diff] [blame] | 869 | u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE); |
| 870 | |
| 871 | /* txgain table */ |
| 872 | if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) { |
| 873 | INIT_INI_ARRAY(&ah->iniModesTxGain, |
| 874 | ar9285Modes_high_power_tx_gain_9285_1_2, |
| 875 | ARRAY_SIZE(ar9285Modes_high_power_tx_gain_9285_1_2), 6); |
| 876 | } else { |
| 877 | INIT_INI_ARRAY(&ah->iniModesTxGain, |
| 878 | ar9285Modes_original_tx_gain_9285_1_2, |
| 879 | ARRAY_SIZE(ar9285Modes_original_tx_gain_9285_1_2), 6); |
| 880 | } |
| 881 | |
| 882 | } |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 883 | } |
Senthil Balasubramanian | 4e84516 | 2009-03-06 11:24:10 +0530 | [diff] [blame] | 884 | |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 885 | static void ath9k_hw_init_11a_eeprom_fix(struct ath_hw *ah) |
| 886 | { |
| 887 | u32 i, j; |
Sujith | 06d0f06 | 2009-02-12 10:06:45 +0530 | [diff] [blame] | 888 | |
| 889 | if ((ah->hw_version.devid == AR9280_DEVID_PCI) && |
| 890 | test_bit(ATH9K_MODE_11A, ah->caps.wireless_modes)) { |
| 891 | |
| 892 | /* EEPROM Fixup */ |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 893 | for (i = 0; i < ah->iniModes.ia_rows; i++) { |
| 894 | u32 reg = INI_RA(&ah->iniModes, i, 0); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 895 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 896 | for (j = 1; j < ah->iniModes.ia_columns; j++) { |
| 897 | u32 val = INI_RA(&ah->iniModes, i, j); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 898 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 899 | INI_RA(&ah->iniModes, i, j) = |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 900 | ath9k_hw_ini_fixup(ah, |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 901 | &ah->eeprom.def, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 902 | reg, val); |
| 903 | } |
| 904 | } |
| 905 | } |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 906 | } |
| 907 | |
Luis R. Rodriguez | f637cfd | 2009-08-03 12:24:46 -0700 | [diff] [blame] | 908 | int ath9k_hw_init(struct ath_hw *ah) |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 909 | { |
Luis R. Rodriguez | 95fafca | 2009-08-03 12:24:54 -0700 | [diff] [blame] | 910 | int r = 0; |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 911 | |
Luis R. Rodriguez | 95fafca | 2009-08-03 12:24:54 -0700 | [diff] [blame] | 912 | if (!ath9k_hw_devid_supported(ah->hw_version.devid)) |
| 913 | return -EOPNOTSUPP; |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 914 | |
| 915 | ath9k_hw_init_defaults(ah); |
| 916 | ath9k_hw_init_config(ah); |
| 917 | |
| 918 | if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 919 | DPRINTF(ah, ATH_DBG_FATAL, "Couldn't reset chip\n"); |
Luis R. Rodriguez | 95fafca | 2009-08-03 12:24:54 -0700 | [diff] [blame] | 920 | return -EIO; |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 921 | } |
| 922 | |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 923 | if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 924 | DPRINTF(ah, ATH_DBG_FATAL, "Couldn't wakeup chip\n"); |
Luis R. Rodriguez | 95fafca | 2009-08-03 12:24:54 -0700 | [diff] [blame] | 925 | return -EIO; |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) { |
| 929 | if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI || |
| 930 | (AR_SREV_9280(ah) && !ah->is_pciexpress)) { |
| 931 | ah->config.serialize_regmode = |
| 932 | SER_REG_MODE_ON; |
| 933 | } else { |
| 934 | ah->config.serialize_regmode = |
| 935 | SER_REG_MODE_OFF; |
| 936 | } |
| 937 | } |
| 938 | |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 939 | DPRINTF(ah, ATH_DBG_RESET, "serialize_regmode is %d\n", |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 940 | ah->config.serialize_regmode); |
| 941 | |
| 942 | if (!ath9k_hw_macversion_supported(ah->hw_version.macVersion)) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 943 | DPRINTF(ah, ATH_DBG_FATAL, |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 944 | "Mac Chip Rev 0x%02x.%x is not supported by " |
| 945 | "this driver\n", ah->hw_version.macVersion, |
| 946 | ah->hw_version.macRev); |
Luis R. Rodriguez | 95fafca | 2009-08-03 12:24:54 -0700 | [diff] [blame] | 947 | return -EOPNOTSUPP; |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | if (AR_SREV_9100(ah)) { |
| 951 | ah->iq_caldata.calData = &iq_cal_multi_sample; |
| 952 | ah->supp_cals = IQ_MISMATCH_CAL; |
| 953 | ah->is_pciexpress = false; |
| 954 | } |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 955 | |
| 956 | if (AR_SREV_9271(ah)) |
| 957 | ah->is_pciexpress = false; |
| 958 | |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 959 | ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID); |
| 960 | |
| 961 | ath9k_hw_init_cal_settings(ah); |
| 962 | |
| 963 | ah->ani_function = ATH9K_ANI_ALL; |
| 964 | if (AR_SREV_9280_10_OR_LATER(ah)) |
| 965 | ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL; |
| 966 | |
| 967 | ath9k_hw_init_mode_regs(ah); |
| 968 | |
| 969 | if (ah->is_pciexpress) |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 970 | ath9k_hw_configpcipowersave(ah, 0, 0); |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 971 | else |
| 972 | ath9k_hw_disablepcie(ah); |
| 973 | |
Luis R. Rodriguez | f637cfd | 2009-08-03 12:24:46 -0700 | [diff] [blame] | 974 | r = ath9k_hw_post_init(ah); |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 975 | if (r) |
Luis R. Rodriguez | 95fafca | 2009-08-03 12:24:54 -0700 | [diff] [blame] | 976 | return r; |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 977 | |
| 978 | ath9k_hw_init_mode_gain_regs(ah); |
| 979 | ath9k_hw_fill_cap_info(ah); |
| 980 | ath9k_hw_init_11a_eeprom_fix(ah); |
Sujith | f6688cd | 2008-12-07 21:43:10 +0530 | [diff] [blame] | 981 | |
Luis R. Rodriguez | 4f3acf8 | 2009-08-03 12:24:36 -0700 | [diff] [blame] | 982 | r = ath9k_hw_init_macaddr(ah); |
| 983 | if (r) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 984 | DPRINTF(ah, ATH_DBG_FATAL, |
Sujith | d8baa93 | 2009-03-30 15:28:25 +0530 | [diff] [blame] | 985 | "Failed to initialize MAC address\n"); |
Luis R. Rodriguez | 95fafca | 2009-08-03 12:24:54 -0700 | [diff] [blame] | 986 | return r; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 987 | } |
| 988 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 989 | if (AR_SREV_9285(ah) || AR_SREV_9271(ah)) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 990 | ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 991 | else |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 992 | ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 993 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 994 | ath9k_init_nfcal_hist_buffer(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 995 | |
Luis R. Rodriguez | 4f3acf8 | 2009-08-03 12:24:36 -0700 | [diff] [blame] | 996 | return 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 997 | } |
| 998 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 999 | static void ath9k_hw_init_bb(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1000 | struct ath9k_channel *chan) |
| 1001 | { |
| 1002 | u32 synthDelay; |
| 1003 | |
| 1004 | synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY; |
Sujith | 788a3d6 | 2008-11-18 09:09:54 +0530 | [diff] [blame] | 1005 | if (IS_CHAN_B(chan)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1006 | synthDelay = (4 * synthDelay) / 22; |
| 1007 | else |
| 1008 | synthDelay /= 10; |
| 1009 | |
| 1010 | REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN); |
| 1011 | |
| 1012 | udelay(synthDelay + BASE_ACTIVATE_DELAY); |
| 1013 | } |
| 1014 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1015 | static void ath9k_hw_init_qos(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1016 | { |
| 1017 | REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa); |
| 1018 | REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210); |
| 1019 | |
| 1020 | REG_WRITE(ah, AR_QOS_NO_ACK, |
| 1021 | SM(2, AR_QOS_NO_ACK_TWO_BIT) | |
| 1022 | SM(5, AR_QOS_NO_ACK_BIT_OFF) | |
| 1023 | SM(0, AR_QOS_NO_ACK_BYTE_OFF)); |
| 1024 | |
| 1025 | REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL); |
| 1026 | REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF); |
| 1027 | REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF); |
| 1028 | REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF); |
| 1029 | REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF); |
| 1030 | } |
| 1031 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1032 | static void ath9k_hw_init_pll(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1033 | struct ath9k_channel *chan) |
| 1034 | { |
| 1035 | u32 pll; |
| 1036 | |
| 1037 | if (AR_SREV_9100(ah)) { |
| 1038 | if (chan && IS_CHAN_5GHZ(chan)) |
| 1039 | pll = 0x1450; |
| 1040 | else |
| 1041 | pll = 0x1458; |
| 1042 | } else { |
| 1043 | if (AR_SREV_9280_10_OR_LATER(ah)) { |
| 1044 | pll = SM(0x5, AR_RTC_9160_PLL_REFDIV); |
| 1045 | |
| 1046 | if (chan && IS_CHAN_HALF_RATE(chan)) |
| 1047 | pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL); |
| 1048 | else if (chan && IS_CHAN_QUARTER_RATE(chan)) |
| 1049 | pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL); |
| 1050 | |
| 1051 | if (chan && IS_CHAN_5GHZ(chan)) { |
| 1052 | pll |= SM(0x28, AR_RTC_9160_PLL_DIV); |
| 1053 | |
| 1054 | |
| 1055 | if (AR_SREV_9280_20(ah)) { |
| 1056 | if (((chan->channel % 20) == 0) |
| 1057 | || ((chan->channel % 10) == 0)) |
| 1058 | pll = 0x2850; |
| 1059 | else |
| 1060 | pll = 0x142c; |
| 1061 | } |
| 1062 | } else { |
| 1063 | pll |= SM(0x2c, AR_RTC_9160_PLL_DIV); |
| 1064 | } |
| 1065 | |
| 1066 | } else if (AR_SREV_9160_10_OR_LATER(ah)) { |
| 1067 | |
| 1068 | pll = SM(0x5, AR_RTC_9160_PLL_REFDIV); |
| 1069 | |
| 1070 | if (chan && IS_CHAN_HALF_RATE(chan)) |
| 1071 | pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL); |
| 1072 | else if (chan && IS_CHAN_QUARTER_RATE(chan)) |
| 1073 | pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL); |
| 1074 | |
| 1075 | if (chan && IS_CHAN_5GHZ(chan)) |
| 1076 | pll |= SM(0x50, AR_RTC_9160_PLL_DIV); |
| 1077 | else |
| 1078 | pll |= SM(0x58, AR_RTC_9160_PLL_DIV); |
| 1079 | } else { |
| 1080 | pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2; |
| 1081 | |
| 1082 | if (chan && IS_CHAN_HALF_RATE(chan)) |
| 1083 | pll |= SM(0x1, AR_RTC_PLL_CLKSEL); |
| 1084 | else if (chan && IS_CHAN_QUARTER_RATE(chan)) |
| 1085 | pll |= SM(0x2, AR_RTC_PLL_CLKSEL); |
| 1086 | |
| 1087 | if (chan && IS_CHAN_5GHZ(chan)) |
| 1088 | pll |= SM(0xa, AR_RTC_PLL_DIV); |
| 1089 | else |
| 1090 | pll |= SM(0xb, AR_RTC_PLL_DIV); |
| 1091 | } |
| 1092 | } |
Gabor Juhos | d03a66c | 2009-01-14 20:17:09 +0100 | [diff] [blame] | 1093 | REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1094 | |
| 1095 | udelay(RTC_PLL_SETTLE_DELAY); |
| 1096 | |
| 1097 | REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK); |
| 1098 | } |
| 1099 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1100 | static void ath9k_hw_init_chain_masks(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1101 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1102 | int rx_chainmask, tx_chainmask; |
| 1103 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1104 | rx_chainmask = ah->rxchainmask; |
| 1105 | tx_chainmask = ah->txchainmask; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1106 | |
| 1107 | switch (rx_chainmask) { |
| 1108 | case 0x5: |
| 1109 | REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP, |
| 1110 | AR_PHY_SWAP_ALT_CHAIN); |
| 1111 | case 0x3: |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 1112 | if (((ah)->hw_version.macVersion <= AR_SREV_VERSION_9160)) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1113 | REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7); |
| 1114 | REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7); |
| 1115 | break; |
| 1116 | } |
| 1117 | case 0x1: |
| 1118 | case 0x2: |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1119 | case 0x7: |
| 1120 | REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask); |
| 1121 | REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask); |
| 1122 | break; |
| 1123 | default: |
| 1124 | break; |
| 1125 | } |
| 1126 | |
| 1127 | REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask); |
| 1128 | if (tx_chainmask == 0x5) { |
| 1129 | REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP, |
| 1130 | AR_PHY_SWAP_ALT_CHAIN); |
| 1131 | } |
| 1132 | if (AR_SREV_9100(ah)) |
| 1133 | REG_WRITE(ah, AR_PHY_ANALOG_SWAP, |
| 1134 | REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001); |
| 1135 | } |
| 1136 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1137 | static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah, |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 1138 | enum nl80211_iftype opmode) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1139 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1140 | ah->mask_reg = AR_IMR_TXERR | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1141 | AR_IMR_TXURN | |
| 1142 | AR_IMR_RXERR | |
| 1143 | AR_IMR_RXORN | |
| 1144 | AR_IMR_BCNMISC; |
| 1145 | |
Sujith | 0ef1f16 | 2009-03-30 15:28:35 +0530 | [diff] [blame] | 1146 | if (ah->config.intr_mitigation) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1147 | ah->mask_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1148 | else |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1149 | ah->mask_reg |= AR_IMR_RXOK; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1150 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1151 | ah->mask_reg |= AR_IMR_TXOK; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1152 | |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 1153 | if (opmode == NL80211_IFTYPE_AP) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1154 | ah->mask_reg |= AR_IMR_MIB; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1155 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1156 | REG_WRITE(ah, AR_IMR, ah->mask_reg); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1157 | REG_WRITE(ah, AR_IMR_S2, REG_READ(ah, AR_IMR_S2) | AR_IMR_S2_GTT); |
| 1158 | |
| 1159 | if (!AR_SREV_9100(ah)) { |
| 1160 | REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF); |
| 1161 | REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT); |
| 1162 | REG_WRITE(ah, AR_INTR_SYNC_MASK, 0); |
| 1163 | } |
| 1164 | } |
| 1165 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1166 | static bool ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1167 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1168 | if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 1169 | DPRINTF(ah, ATH_DBG_RESET, "bad ack timeout %u\n", us); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1170 | ah->acktimeout = (u32) -1; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1171 | return false; |
| 1172 | } else { |
| 1173 | REG_RMW_FIELD(ah, AR_TIME_OUT, |
| 1174 | AR_TIME_OUT_ACK, ath9k_hw_mac_to_clks(ah, us)); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1175 | ah->acktimeout = us; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1176 | return true; |
| 1177 | } |
| 1178 | } |
| 1179 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1180 | static bool ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1181 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1182 | if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_CTS))) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 1183 | DPRINTF(ah, ATH_DBG_RESET, "bad cts timeout %u\n", us); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1184 | ah->ctstimeout = (u32) -1; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1185 | return false; |
| 1186 | } else { |
| 1187 | REG_RMW_FIELD(ah, AR_TIME_OUT, |
| 1188 | AR_TIME_OUT_CTS, ath9k_hw_mac_to_clks(ah, us)); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1189 | ah->ctstimeout = us; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1190 | return true; |
| 1191 | } |
| 1192 | } |
| 1193 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1194 | static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1195 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1196 | if (tu > 0xFFFF) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 1197 | DPRINTF(ah, ATH_DBG_XMIT, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 1198 | "bad global tx timeout %u\n", tu); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1199 | ah->globaltxtimeout = (u32) -1; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1200 | return false; |
| 1201 | } else { |
| 1202 | REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1203 | ah->globaltxtimeout = tu; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1204 | return true; |
| 1205 | } |
| 1206 | } |
| 1207 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1208 | static void ath9k_hw_init_user_settings(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1209 | { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 1210 | DPRINTF(ah, ATH_DBG_RESET, "ah->misc_mode 0x%x\n", |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1211 | ah->misc_mode); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1212 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1213 | if (ah->misc_mode != 0) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1214 | REG_WRITE(ah, AR_PCU_MISC, |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1215 | REG_READ(ah, AR_PCU_MISC) | ah->misc_mode); |
| 1216 | if (ah->slottime != (u32) -1) |
| 1217 | ath9k_hw_setslottime(ah, ah->slottime); |
| 1218 | if (ah->acktimeout != (u32) -1) |
| 1219 | ath9k_hw_set_ack_timeout(ah, ah->acktimeout); |
| 1220 | if (ah->ctstimeout != (u32) -1) |
| 1221 | ath9k_hw_set_cts_timeout(ah, ah->ctstimeout); |
| 1222 | if (ah->globaltxtimeout != (u32) -1) |
| 1223 | ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1224 | } |
| 1225 | |
| 1226 | const char *ath9k_hw_probe(u16 vendorid, u16 devid) |
| 1227 | { |
| 1228 | return vendorid == ATHEROS_VENDOR_ID ? |
| 1229 | ath9k_hw_devname(devid) : NULL; |
| 1230 | } |
| 1231 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1232 | void ath9k_hw_detach(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1233 | { |
| 1234 | if (!AR_SREV_9100(ah)) |
Luis R. Rodriguez | e70c0cf | 2009-08-03 12:24:51 -0700 | [diff] [blame] | 1235 | ath9k_hw_ani_disable(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1236 | |
Luis R. Rodriguez | 081b35a | 2009-08-03 12:24:50 -0700 | [diff] [blame] | 1237 | ath9k_hw_rf_free(ah); |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 1238 | ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1239 | kfree(ah); |
Luis R. Rodriguez | 9db6b6a | 2009-08-03 12:24:52 -0700 | [diff] [blame] | 1240 | ah = NULL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1241 | } |
| 1242 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1243 | /*******/ |
| 1244 | /* INI */ |
| 1245 | /*******/ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1246 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1247 | static void ath9k_hw_override_ini(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1248 | struct ath9k_channel *chan) |
| 1249 | { |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1250 | u32 val; |
| 1251 | |
| 1252 | if (AR_SREV_9271(ah)) { |
| 1253 | /* |
| 1254 | * Enable spectral scan to solution for issues with stuck |
| 1255 | * beacons on AR9271 1.0. The beacon stuck issue is not seeon on |
| 1256 | * AR9271 1.1 |
| 1257 | */ |
| 1258 | if (AR_SREV_9271_10(ah)) { |
| 1259 | val = REG_READ(ah, AR_PHY_SPECTRAL_SCAN) | AR_PHY_SPECTRAL_SCAN_ENABLE; |
| 1260 | REG_WRITE(ah, AR_PHY_SPECTRAL_SCAN, val); |
| 1261 | } |
| 1262 | else if (AR_SREV_9271_11(ah)) |
| 1263 | /* |
| 1264 | * change AR_PHY_RF_CTL3 setting to fix MAC issue |
| 1265 | * present on AR9271 1.1 |
| 1266 | */ |
| 1267 | REG_WRITE(ah, AR_PHY_RF_CTL3, 0x3a020001); |
| 1268 | return; |
| 1269 | } |
| 1270 | |
Senthil Balasubramanian | 8aa15e1 | 2008-12-08 19:43:50 +0530 | [diff] [blame] | 1271 | /* |
| 1272 | * Set the RX_ABORT and RX_DIS and clear if off only after |
| 1273 | * RXE is set for MAC. This prevents frames with corrupted |
| 1274 | * descriptor status. |
| 1275 | */ |
| 1276 | REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT)); |
| 1277 | |
Vasanthakumar Thiagarajan | 204d794 | 2009-09-17 09:26:14 +0530 | [diff] [blame] | 1278 | if (AR_SREV_9280_10_OR_LATER(ah)) { |
| 1279 | val = REG_READ(ah, AR_PCU_MISC_MODE2) & |
| 1280 | (~AR_PCU_MISC_MODE2_HWWAR1); |
| 1281 | |
| 1282 | if (AR_SREV_9287_10_OR_LATER(ah)) |
| 1283 | val = val & (~AR_PCU_MISC_MODE2_HWWAR2); |
| 1284 | |
| 1285 | REG_WRITE(ah, AR_PCU_MISC_MODE2, val); |
| 1286 | } |
Senthil Balasubramanian | 8aa15e1 | 2008-12-08 19:43:50 +0530 | [diff] [blame] | 1287 | |
Gabor Juhos | a8c96d3 | 2009-03-06 09:08:51 +0100 | [diff] [blame] | 1288 | if (!AR_SREV_5416_20_OR_LATER(ah) || |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1289 | AR_SREV_9280_10_OR_LATER(ah)) |
| 1290 | return; |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1291 | /* |
| 1292 | * Disable BB clock gating |
| 1293 | * Necessary to avoid issues on AR5416 2.0 |
| 1294 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1295 | REG_WRITE(ah, 0x9800 + (651 << 2), 0x11); |
| 1296 | } |
| 1297 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1298 | static u32 ath9k_hw_def_ini_fixup(struct ath_hw *ah, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1299 | struct ar5416_eeprom_def *pEepData, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1300 | u32 reg, u32 value) |
| 1301 | { |
| 1302 | struct base_eep_header *pBase = &(pEepData->baseEepHeader); |
| 1303 | |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 1304 | switch (ah->hw_version.devid) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1305 | case AR9280_DEVID_PCI: |
| 1306 | if (reg == 0x7894) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 1307 | DPRINTF(ah, ATH_DBG_EEPROM, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1308 | "ini VAL: %x EEPROM: %x\n", value, |
| 1309 | (pBase->version & 0xff)); |
| 1310 | |
| 1311 | if ((pBase->version & 0xff) > 0x0a) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 1312 | DPRINTF(ah, ATH_DBG_EEPROM, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1313 | "PWDCLKIND: %d\n", |
| 1314 | pBase->pwdclkind); |
| 1315 | value &= ~AR_AN_TOP2_PWDCLKIND; |
| 1316 | value |= AR_AN_TOP2_PWDCLKIND & |
| 1317 | (pBase->pwdclkind << AR_AN_TOP2_PWDCLKIND_S); |
| 1318 | } else { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 1319 | DPRINTF(ah, ATH_DBG_EEPROM, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1320 | "PWDCLKIND Earlier Rev\n"); |
| 1321 | } |
| 1322 | |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 1323 | DPRINTF(ah, ATH_DBG_EEPROM, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1324 | "final ini VAL: %x\n", value); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1325 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1326 | break; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1327 | } |
| 1328 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1329 | return value; |
| 1330 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1331 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1332 | static u32 ath9k_hw_ini_fixup(struct ath_hw *ah, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1333 | struct ar5416_eeprom_def *pEepData, |
| 1334 | u32 reg, u32 value) |
| 1335 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1336 | if (ah->eep_map == EEP_MAP_4KBITS) |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1337 | return value; |
| 1338 | else |
| 1339 | return ath9k_hw_def_ini_fixup(ah, pEepData, reg, value); |
| 1340 | } |
| 1341 | |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 1342 | static void ath9k_olc_init(struct ath_hw *ah) |
| 1343 | { |
| 1344 | u32 i; |
| 1345 | |
Vivek Natarajan | db91f2e | 2009-08-14 11:27:16 +0530 | [diff] [blame] | 1346 | if (OLC_FOR_AR9287_10_LATER) { |
| 1347 | REG_SET_BIT(ah, AR_PHY_TX_PWRCTRL9, |
| 1348 | AR_PHY_TX_PWRCTRL9_RES_DC_REMOVAL); |
| 1349 | ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TXPC0, |
| 1350 | AR9287_AN_TXPC0_TXPCMODE, |
| 1351 | AR9287_AN_TXPC0_TXPCMODE_S, |
| 1352 | AR9287_AN_TXPC0_TXPCMODE_TEMPSENSE); |
| 1353 | udelay(100); |
| 1354 | } else { |
| 1355 | for (i = 0; i < AR9280_TX_GAIN_TABLE_SIZE; i++) |
| 1356 | ah->originalGain[i] = |
| 1357 | MS(REG_READ(ah, AR_PHY_TX_GAIN_TBL1 + i * 4), |
| 1358 | AR_PHY_TX_GAIN); |
| 1359 | ah->PDADCdelta = 0; |
| 1360 | } |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 1361 | } |
| 1362 | |
Bob Copeland | 3a702e4 | 2009-03-30 22:30:29 -0400 | [diff] [blame] | 1363 | static u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, |
| 1364 | struct ath9k_channel *chan) |
| 1365 | { |
| 1366 | u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band); |
| 1367 | |
| 1368 | if (IS_CHAN_B(chan)) |
| 1369 | ctl |= CTL_11B; |
| 1370 | else if (IS_CHAN_G(chan)) |
| 1371 | ctl |= CTL_11G; |
| 1372 | else |
| 1373 | ctl |= CTL_11A; |
| 1374 | |
| 1375 | return ctl; |
| 1376 | } |
| 1377 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1378 | static int ath9k_hw_process_ini(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1379 | struct ath9k_channel *chan, |
| 1380 | enum ath9k_ht_macmode macmode) |
| 1381 | { |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 1382 | struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1383 | int i, regWrites = 0; |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 1384 | struct ieee80211_channel *channel = chan->chan; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1385 | u32 modesIndex, freqIndex; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1386 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1387 | switch (chan->chanmode) { |
| 1388 | case CHANNEL_A: |
| 1389 | case CHANNEL_A_HT20: |
| 1390 | modesIndex = 1; |
| 1391 | freqIndex = 1; |
| 1392 | break; |
| 1393 | case CHANNEL_A_HT40PLUS: |
| 1394 | case CHANNEL_A_HT40MINUS: |
| 1395 | modesIndex = 2; |
| 1396 | freqIndex = 1; |
| 1397 | break; |
| 1398 | case CHANNEL_G: |
| 1399 | case CHANNEL_G_HT20: |
| 1400 | case CHANNEL_B: |
| 1401 | modesIndex = 4; |
| 1402 | freqIndex = 2; |
| 1403 | break; |
| 1404 | case CHANNEL_G_HT40PLUS: |
| 1405 | case CHANNEL_G_HT40MINUS: |
| 1406 | modesIndex = 3; |
| 1407 | freqIndex = 2; |
| 1408 | break; |
| 1409 | |
| 1410 | default: |
| 1411 | return -EINVAL; |
| 1412 | } |
| 1413 | |
| 1414 | REG_WRITE(ah, AR_PHY(0), 0x00000007); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1415 | REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO); |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1416 | ah->eep_ops->set_addac(ah, chan); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1417 | |
Gabor Juhos | a8c96d3 | 2009-03-06 09:08:51 +0100 | [diff] [blame] | 1418 | if (AR_SREV_5416_22_OR_LATER(ah)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1419 | REG_WRITE_ARRAY(&ah->iniAddac, 1, regWrites); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1420 | } else { |
| 1421 | struct ar5416IniArray temp; |
| 1422 | u32 addacSize = |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1423 | sizeof(u32) * ah->iniAddac.ia_rows * |
| 1424 | ah->iniAddac.ia_columns; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1425 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1426 | memcpy(ah->addac5416_21, |
| 1427 | ah->iniAddac.ia_array, addacSize); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1428 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1429 | (ah->addac5416_21)[31 * ah->iniAddac.ia_columns + 1] = 0; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1430 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1431 | temp.ia_array = ah->addac5416_21; |
| 1432 | temp.ia_columns = ah->iniAddac.ia_columns; |
| 1433 | temp.ia_rows = ah->iniAddac.ia_rows; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1434 | REG_WRITE_ARRAY(&temp, 1, regWrites); |
| 1435 | } |
| 1436 | |
| 1437 | REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC); |
| 1438 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1439 | for (i = 0; i < ah->iniModes.ia_rows; i++) { |
| 1440 | u32 reg = INI_RA(&ah->iniModes, i, 0); |
| 1441 | u32 val = INI_RA(&ah->iniModes, i, modesIndex); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1442 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1443 | REG_WRITE(ah, reg, val); |
| 1444 | |
| 1445 | if (reg >= 0x7800 && reg < 0x78a0 |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1446 | && ah->config.analog_shiftreg) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1447 | udelay(100); |
| 1448 | } |
| 1449 | |
| 1450 | DO_DELAY(regWrites); |
| 1451 | } |
| 1452 | |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 1453 | if (AR_SREV_9280(ah) || AR_SREV_9287_10_OR_LATER(ah)) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1454 | REG_WRITE_ARRAY(&ah->iniModesRxGain, modesIndex, regWrites); |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 1455 | |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 1456 | if (AR_SREV_9280(ah) || AR_SREV_9285_12_OR_LATER(ah) || |
| 1457 | AR_SREV_9287_10_OR_LATER(ah)) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1458 | REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites); |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 1459 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1460 | for (i = 0; i < ah->iniCommon.ia_rows; i++) { |
| 1461 | u32 reg = INI_RA(&ah->iniCommon, i, 0); |
| 1462 | u32 val = INI_RA(&ah->iniCommon, i, 1); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1463 | |
| 1464 | REG_WRITE(ah, reg, val); |
| 1465 | |
| 1466 | if (reg >= 0x7800 && reg < 0x78a0 |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1467 | && ah->config.analog_shiftreg) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1468 | udelay(100); |
| 1469 | } |
| 1470 | |
| 1471 | DO_DELAY(regWrites); |
| 1472 | } |
| 1473 | |
| 1474 | ath9k_hw_write_regs(ah, modesIndex, freqIndex, regWrites); |
| 1475 | |
| 1476 | if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1477 | REG_WRITE_ARRAY(&ah->iniModesAdditional, modesIndex, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1478 | regWrites); |
| 1479 | } |
| 1480 | |
| 1481 | ath9k_hw_override_ini(ah, chan); |
| 1482 | ath9k_hw_set_regs(ah, chan, macmode); |
| 1483 | ath9k_hw_init_chain_masks(ah); |
| 1484 | |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 1485 | if (OLC_FOR_AR9280_20_LATER) |
| 1486 | ath9k_olc_init(ah); |
| 1487 | |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 1488 | ah->eep_ops->set_txpower(ah, chan, |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 1489 | ath9k_regd_get_ctl(regulatory, chan), |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 1490 | channel->max_antenna_gain * 2, |
| 1491 | channel->max_power * 2, |
| 1492 | min((u32) MAX_RATE_POWER, |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 1493 | (u32) regulatory->power_limit)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1494 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1495 | if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 1496 | DPRINTF(ah, ATH_DBG_FATAL, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 1497 | "ar5416SetRfRegs failed\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1498 | return -EIO; |
| 1499 | } |
| 1500 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1501 | return 0; |
| 1502 | } |
| 1503 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1504 | /****************************************/ |
| 1505 | /* Reset and Channel Switching Routines */ |
| 1506 | /****************************************/ |
| 1507 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1508 | static void ath9k_hw_set_rfmode(struct ath_hw *ah, struct ath9k_channel *chan) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1509 | { |
| 1510 | u32 rfMode = 0; |
| 1511 | |
| 1512 | if (chan == NULL) |
| 1513 | return; |
| 1514 | |
| 1515 | rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan)) |
| 1516 | ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM; |
| 1517 | |
| 1518 | if (!AR_SREV_9280_10_OR_LATER(ah)) |
| 1519 | rfMode |= (IS_CHAN_5GHZ(chan)) ? |
| 1520 | AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ; |
| 1521 | |
| 1522 | if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan)) |
| 1523 | rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE); |
| 1524 | |
| 1525 | REG_WRITE(ah, AR_PHY_MODE, rfMode); |
| 1526 | } |
| 1527 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1528 | static void ath9k_hw_mark_phy_inactive(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1529 | { |
| 1530 | REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS); |
| 1531 | } |
| 1532 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1533 | static inline void ath9k_hw_set_dma(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1534 | { |
| 1535 | u32 regval; |
| 1536 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1537 | /* |
| 1538 | * set AHB_MODE not to do cacheline prefetches |
| 1539 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1540 | regval = REG_READ(ah, AR_AHB_MODE); |
| 1541 | REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN); |
| 1542 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1543 | /* |
| 1544 | * let mac dma reads be in 128 byte chunks |
| 1545 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1546 | regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK; |
| 1547 | REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B); |
| 1548 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1549 | /* |
| 1550 | * Restore TX Trigger Level to its pre-reset value. |
| 1551 | * The initial value depends on whether aggregation is enabled, and is |
| 1552 | * adjusted whenever underruns are detected. |
| 1553 | */ |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1554 | REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1555 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1556 | /* |
| 1557 | * let mac dma writes be in 128 byte chunks |
| 1558 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1559 | regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK; |
| 1560 | REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B); |
| 1561 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1562 | /* |
| 1563 | * Setup receive FIFO threshold to hold off TX activities |
| 1564 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1565 | REG_WRITE(ah, AR_RXFIFO_CFG, 0x200); |
| 1566 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1567 | /* |
| 1568 | * reduce the number of usable entries in PCU TXBUF to avoid |
| 1569 | * wrap around issues. |
| 1570 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1571 | if (AR_SREV_9285(ah)) { |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1572 | /* For AR9285 the number of Fifos are reduced to half. |
| 1573 | * So set the usable tx buf size also to half to |
| 1574 | * avoid data/delimiter underruns |
| 1575 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1576 | REG_WRITE(ah, AR_PCU_TXBUF_CTRL, |
| 1577 | AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE); |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1578 | } else if (!AR_SREV_9271(ah)) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1579 | REG_WRITE(ah, AR_PCU_TXBUF_CTRL, |
| 1580 | AR_PCU_TXBUF_CTRL_USABLE_SIZE); |
| 1581 | } |
| 1582 | } |
| 1583 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1584 | static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1585 | { |
| 1586 | u32 val; |
| 1587 | |
| 1588 | val = REG_READ(ah, AR_STA_ID1); |
| 1589 | val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC); |
| 1590 | switch (opmode) { |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 1591 | case NL80211_IFTYPE_AP: |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1592 | REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP |
| 1593 | | AR_STA_ID1_KSRCH_MODE); |
| 1594 | REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION); |
| 1595 | break; |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 1596 | case NL80211_IFTYPE_ADHOC: |
Pat Erley | 9cb5412 | 2009-03-20 22:59:59 -0400 | [diff] [blame] | 1597 | case NL80211_IFTYPE_MESH_POINT: |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1598 | REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC |
| 1599 | | AR_STA_ID1_KSRCH_MODE); |
| 1600 | REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION); |
| 1601 | break; |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 1602 | case NL80211_IFTYPE_STATION: |
| 1603 | case NL80211_IFTYPE_MONITOR: |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1604 | REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE); |
| 1605 | break; |
| 1606 | } |
| 1607 | } |
| 1608 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1609 | static inline void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1610 | u32 coef_scaled, |
| 1611 | u32 *coef_mantissa, |
| 1612 | u32 *coef_exponent) |
| 1613 | { |
| 1614 | u32 coef_exp, coef_man; |
| 1615 | |
| 1616 | for (coef_exp = 31; coef_exp > 0; coef_exp--) |
| 1617 | if ((coef_scaled >> coef_exp) & 0x1) |
| 1618 | break; |
| 1619 | |
| 1620 | coef_exp = 14 - (coef_exp - COEF_SCALE_S); |
| 1621 | |
| 1622 | coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1)); |
| 1623 | |
| 1624 | *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp); |
| 1625 | *coef_exponent = coef_exp - 16; |
| 1626 | } |
| 1627 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1628 | static void ath9k_hw_set_delta_slope(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1629 | struct ath9k_channel *chan) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1630 | { |
| 1631 | u32 coef_scaled, ds_coef_exp, ds_coef_man; |
| 1632 | u32 clockMhzScaled = 0x64000000; |
| 1633 | struct chan_centers centers; |
| 1634 | |
| 1635 | if (IS_CHAN_HALF_RATE(chan)) |
| 1636 | clockMhzScaled = clockMhzScaled >> 1; |
| 1637 | else if (IS_CHAN_QUARTER_RATE(chan)) |
| 1638 | clockMhzScaled = clockMhzScaled >> 2; |
| 1639 | |
| 1640 | ath9k_hw_get_channel_centers(ah, chan, ¢ers); |
| 1641 | coef_scaled = clockMhzScaled / centers.synth_center; |
| 1642 | |
| 1643 | ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man, |
| 1644 | &ds_coef_exp); |
| 1645 | |
| 1646 | REG_RMW_FIELD(ah, AR_PHY_TIMING3, |
| 1647 | AR_PHY_TIMING3_DSC_MAN, ds_coef_man); |
| 1648 | REG_RMW_FIELD(ah, AR_PHY_TIMING3, |
| 1649 | AR_PHY_TIMING3_DSC_EXP, ds_coef_exp); |
| 1650 | |
| 1651 | coef_scaled = (9 * coef_scaled) / 10; |
| 1652 | |
| 1653 | ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man, |
| 1654 | &ds_coef_exp); |
| 1655 | |
| 1656 | REG_RMW_FIELD(ah, AR_PHY_HALFGI, |
| 1657 | AR_PHY_HALFGI_DSC_MAN, ds_coef_man); |
| 1658 | REG_RMW_FIELD(ah, AR_PHY_HALFGI, |
| 1659 | AR_PHY_HALFGI_DSC_EXP, ds_coef_exp); |
| 1660 | } |
| 1661 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1662 | static bool ath9k_hw_set_reset(struct ath_hw *ah, int type) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1663 | { |
| 1664 | u32 rst_flags; |
| 1665 | u32 tmpReg; |
| 1666 | |
Sujith | 7076849 | 2009-02-16 13:23:12 +0530 | [diff] [blame] | 1667 | if (AR_SREV_9100(ah)) { |
| 1668 | u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK); |
| 1669 | val &= ~AR_RTC_DERIVED_CLK_PERIOD; |
| 1670 | val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD); |
| 1671 | REG_WRITE(ah, AR_RTC_DERIVED_CLK, val); |
| 1672 | (void)REG_READ(ah, AR_RTC_DERIVED_CLK); |
| 1673 | } |
| 1674 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1675 | REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN | |
| 1676 | AR_RTC_FORCE_WAKE_ON_INT); |
| 1677 | |
| 1678 | if (AR_SREV_9100(ah)) { |
| 1679 | rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD | |
| 1680 | AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET; |
| 1681 | } else { |
| 1682 | tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE); |
| 1683 | if (tmpReg & |
| 1684 | (AR_INTR_SYNC_LOCAL_TIMEOUT | |
| 1685 | AR_INTR_SYNC_RADM_CPL_TIMEOUT)) { |
| 1686 | REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0); |
| 1687 | REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF); |
| 1688 | } else { |
| 1689 | REG_WRITE(ah, AR_RC, AR_RC_AHB); |
| 1690 | } |
| 1691 | |
| 1692 | rst_flags = AR_RTC_RC_MAC_WARM; |
| 1693 | if (type == ATH9K_RESET_COLD) |
| 1694 | rst_flags |= AR_RTC_RC_MAC_COLD; |
| 1695 | } |
| 1696 | |
Gabor Juhos | d03a66c | 2009-01-14 20:17:09 +0100 | [diff] [blame] | 1697 | REG_WRITE(ah, AR_RTC_RC, rst_flags); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1698 | udelay(50); |
| 1699 | |
Gabor Juhos | d03a66c | 2009-01-14 20:17:09 +0100 | [diff] [blame] | 1700 | REG_WRITE(ah, AR_RTC_RC, 0); |
Sujith | 0caa7b1 | 2009-02-16 13:23:20 +0530 | [diff] [blame] | 1701 | if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 1702 | DPRINTF(ah, ATH_DBG_RESET, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 1703 | "RTC stuck in MAC reset\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1704 | return false; |
| 1705 | } |
| 1706 | |
| 1707 | if (!AR_SREV_9100(ah)) |
| 1708 | REG_WRITE(ah, AR_RC, 0); |
| 1709 | |
| 1710 | ath9k_hw_init_pll(ah, NULL); |
| 1711 | |
| 1712 | if (AR_SREV_9100(ah)) |
| 1713 | udelay(50); |
| 1714 | |
| 1715 | return true; |
| 1716 | } |
| 1717 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1718 | static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1719 | { |
| 1720 | REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN | |
| 1721 | AR_RTC_FORCE_WAKE_ON_INT); |
| 1722 | |
Vasanthakumar Thiagarajan | 1c29ce6 | 2009-08-31 17:48:36 +0530 | [diff] [blame] | 1723 | if (!AR_SREV_9100(ah)) |
| 1724 | REG_WRITE(ah, AR_RC, AR_RC_AHB); |
| 1725 | |
Gabor Juhos | d03a66c | 2009-01-14 20:17:09 +0100 | [diff] [blame] | 1726 | REG_WRITE(ah, AR_RTC_RESET, 0); |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 1727 | udelay(2); |
Vasanthakumar Thiagarajan | 1c29ce6 | 2009-08-31 17:48:36 +0530 | [diff] [blame] | 1728 | |
| 1729 | if (!AR_SREV_9100(ah)) |
| 1730 | REG_WRITE(ah, AR_RC, 0); |
| 1731 | |
Gabor Juhos | d03a66c | 2009-01-14 20:17:09 +0100 | [diff] [blame] | 1732 | REG_WRITE(ah, AR_RTC_RESET, 1); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1733 | |
| 1734 | if (!ath9k_hw_wait(ah, |
| 1735 | AR_RTC_STATUS, |
| 1736 | AR_RTC_STATUS_M, |
Sujith | 0caa7b1 | 2009-02-16 13:23:20 +0530 | [diff] [blame] | 1737 | AR_RTC_STATUS_ON, |
| 1738 | AH_WAIT_TIMEOUT)) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 1739 | DPRINTF(ah, ATH_DBG_RESET, "RTC not waking up\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1740 | return false; |
| 1741 | } |
| 1742 | |
| 1743 | ath9k_hw_read_revisions(ah); |
| 1744 | |
| 1745 | return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM); |
| 1746 | } |
| 1747 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1748 | static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1749 | { |
| 1750 | REG_WRITE(ah, AR_RTC_FORCE_WAKE, |
| 1751 | AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT); |
| 1752 | |
| 1753 | switch (type) { |
| 1754 | case ATH9K_RESET_POWER_ON: |
| 1755 | return ath9k_hw_set_reset_power_on(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1756 | case ATH9K_RESET_WARM: |
| 1757 | case ATH9K_RESET_COLD: |
| 1758 | return ath9k_hw_set_reset(ah, type); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1759 | default: |
| 1760 | return false; |
| 1761 | } |
| 1762 | } |
| 1763 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1764 | static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1765 | enum ath9k_ht_macmode macmode) |
| 1766 | { |
| 1767 | u32 phymode; |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1768 | u32 enableDacFifo = 0; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1769 | |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1770 | if (AR_SREV_9285_10_OR_LATER(ah)) |
| 1771 | enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) & |
| 1772 | AR_PHY_FC_ENABLE_DAC_FIFO); |
| 1773 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1774 | phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40 |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1775 | | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1776 | |
| 1777 | if (IS_CHAN_HT40(chan)) { |
| 1778 | phymode |= AR_PHY_FC_DYN2040_EN; |
| 1779 | |
| 1780 | if ((chan->chanmode == CHANNEL_A_HT40PLUS) || |
| 1781 | (chan->chanmode == CHANNEL_G_HT40PLUS)) |
| 1782 | phymode |= AR_PHY_FC_DYN2040_PRI_CH; |
| 1783 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1784 | if (ah->extprotspacing == ATH9K_HT_EXTPROTSPACING_25) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1785 | phymode |= AR_PHY_FC_DYN2040_EXT_CH; |
| 1786 | } |
| 1787 | REG_WRITE(ah, AR_PHY_TURBO, phymode); |
| 1788 | |
| 1789 | ath9k_hw_set11nmac2040(ah, macmode); |
| 1790 | |
| 1791 | REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S); |
| 1792 | REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S); |
| 1793 | } |
| 1794 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1795 | static bool ath9k_hw_chip_reset(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1796 | struct ath9k_channel *chan) |
| 1797 | { |
Vivek Natarajan | 42abfbe | 2009-09-17 09:27:59 +0530 | [diff] [blame] | 1798 | 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] | 1799 | if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) |
| 1800 | return false; |
| 1801 | } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1802 | return false; |
| 1803 | |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 1804 | if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1805 | return false; |
| 1806 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1807 | ah->chip_fullsleep = false; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1808 | ath9k_hw_init_pll(ah, chan); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1809 | ath9k_hw_set_rfmode(ah, chan); |
| 1810 | |
| 1811 | return true; |
| 1812 | } |
| 1813 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1814 | static bool ath9k_hw_channel_change(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1815 | struct ath9k_channel *chan, |
| 1816 | enum ath9k_ht_macmode macmode) |
| 1817 | { |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 1818 | struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah); |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 1819 | struct ieee80211_channel *channel = chan->chan; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1820 | u32 synthDelay, qnum; |
| 1821 | |
| 1822 | for (qnum = 0; qnum < AR_NUM_QCU; qnum++) { |
| 1823 | if (ath9k_hw_numtxpending(ah, qnum)) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 1824 | DPRINTF(ah, ATH_DBG_QUEUE, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 1825 | "Transmit frames pending on queue %d\n", qnum); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1826 | return false; |
| 1827 | } |
| 1828 | } |
| 1829 | |
| 1830 | REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN); |
| 1831 | if (!ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN, |
Sujith | 0caa7b1 | 2009-02-16 13:23:20 +0530 | [diff] [blame] | 1832 | AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT)) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 1833 | DPRINTF(ah, ATH_DBG_FATAL, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 1834 | "Could not kill baseband RX\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1835 | return false; |
| 1836 | } |
| 1837 | |
| 1838 | ath9k_hw_set_regs(ah, chan, macmode); |
| 1839 | |
| 1840 | if (AR_SREV_9280_10_OR_LATER(ah)) { |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 1841 | ath9k_hw_ar9280_set_channel(ah, chan); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1842 | } else { |
| 1843 | if (!(ath9k_hw_set_channel(ah, chan))) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 1844 | DPRINTF(ah, ATH_DBG_FATAL, |
Sujith | d8baa93 | 2009-03-30 15:28:25 +0530 | [diff] [blame] | 1845 | "Failed to set channel\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1846 | return false; |
| 1847 | } |
| 1848 | } |
| 1849 | |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 1850 | ah->eep_ops->set_txpower(ah, chan, |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 1851 | ath9k_regd_get_ctl(regulatory, chan), |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1852 | channel->max_antenna_gain * 2, |
| 1853 | channel->max_power * 2, |
| 1854 | min((u32) MAX_RATE_POWER, |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 1855 | (u32) regulatory->power_limit)); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1856 | |
| 1857 | synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY; |
Sujith | 788a3d6 | 2008-11-18 09:09:54 +0530 | [diff] [blame] | 1858 | if (IS_CHAN_B(chan)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1859 | synthDelay = (4 * synthDelay) / 22; |
| 1860 | else |
| 1861 | synthDelay /= 10; |
| 1862 | |
| 1863 | udelay(synthDelay + BASE_ACTIVATE_DELAY); |
| 1864 | |
| 1865 | REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0); |
| 1866 | |
| 1867 | if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan)) |
| 1868 | ath9k_hw_set_delta_slope(ah, chan); |
| 1869 | |
| 1870 | if (AR_SREV_9280_10_OR_LATER(ah)) |
| 1871 | ath9k_hw_9280_spur_mitigate(ah, chan); |
| 1872 | else |
| 1873 | ath9k_hw_spur_mitigate(ah, chan); |
| 1874 | |
| 1875 | if (!chan->oneTimeCalsDone) |
| 1876 | chan->oneTimeCalsDone = true; |
| 1877 | |
| 1878 | return true; |
| 1879 | } |
| 1880 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1881 | static void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1882 | { |
| 1883 | int bb_spur = AR_NO_SPUR; |
| 1884 | int freq; |
| 1885 | int bin, cur_bin; |
| 1886 | int bb_spur_off, spur_subchannel_sd; |
| 1887 | int spur_freq_sd; |
| 1888 | int spur_delta_phase; |
| 1889 | int denominator; |
| 1890 | int upper, lower, cur_vit_mask; |
| 1891 | int tmp, newVal; |
| 1892 | int i; |
| 1893 | int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8, |
| 1894 | AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60 |
| 1895 | }; |
| 1896 | int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10, |
| 1897 | AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60 |
| 1898 | }; |
| 1899 | int inc[4] = { 0, 100, 0, 0 }; |
| 1900 | struct chan_centers centers; |
| 1901 | |
| 1902 | int8_t mask_m[123]; |
| 1903 | int8_t mask_p[123]; |
| 1904 | int8_t mask_amt; |
| 1905 | int tmp_mask; |
| 1906 | int cur_bb_spur; |
| 1907 | bool is2GHz = IS_CHAN_2GHZ(chan); |
| 1908 | |
| 1909 | memset(&mask_m, 0, sizeof(int8_t) * 123); |
| 1910 | memset(&mask_p, 0, sizeof(int8_t) * 123); |
| 1911 | |
| 1912 | ath9k_hw_get_channel_centers(ah, chan, ¢ers); |
| 1913 | freq = centers.synth_center; |
| 1914 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1915 | ah->config.spurmode = SPUR_ENABLE_EEPROM; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1916 | for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) { |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1917 | cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1918 | |
| 1919 | if (is2GHz) |
| 1920 | cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_2GHZ; |
| 1921 | else |
| 1922 | cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_5GHZ; |
| 1923 | |
| 1924 | if (AR_NO_SPUR == cur_bb_spur) |
| 1925 | break; |
| 1926 | cur_bb_spur = cur_bb_spur - freq; |
| 1927 | |
| 1928 | if (IS_CHAN_HT40(chan)) { |
| 1929 | if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT40) && |
| 1930 | (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT40)) { |
| 1931 | bb_spur = cur_bb_spur; |
| 1932 | break; |
| 1933 | } |
| 1934 | } else if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT20) && |
| 1935 | (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT20)) { |
| 1936 | bb_spur = cur_bb_spur; |
| 1937 | break; |
| 1938 | } |
| 1939 | } |
| 1940 | |
| 1941 | if (AR_NO_SPUR == bb_spur) { |
| 1942 | REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK, |
| 1943 | AR_PHY_FORCE_CLKEN_CCK_MRC_MUX); |
| 1944 | return; |
| 1945 | } else { |
| 1946 | REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK, |
| 1947 | AR_PHY_FORCE_CLKEN_CCK_MRC_MUX); |
| 1948 | } |
| 1949 | |
| 1950 | bin = bb_spur * 320; |
| 1951 | |
| 1952 | tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0)); |
| 1953 | |
| 1954 | newVal = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI | |
| 1955 | AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER | |
| 1956 | AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK | |
| 1957 | AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK); |
| 1958 | REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), newVal); |
| 1959 | |
| 1960 | newVal = (AR_PHY_SPUR_REG_MASK_RATE_CNTL | |
| 1961 | AR_PHY_SPUR_REG_ENABLE_MASK_PPM | |
| 1962 | AR_PHY_SPUR_REG_MASK_RATE_SELECT | |
| 1963 | AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI | |
| 1964 | SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH)); |
| 1965 | REG_WRITE(ah, AR_PHY_SPUR_REG, newVal); |
| 1966 | |
| 1967 | if (IS_CHAN_HT40(chan)) { |
| 1968 | if (bb_spur < 0) { |
| 1969 | spur_subchannel_sd = 1; |
| 1970 | bb_spur_off = bb_spur + 10; |
| 1971 | } else { |
| 1972 | spur_subchannel_sd = 0; |
| 1973 | bb_spur_off = bb_spur - 10; |
| 1974 | } |
| 1975 | } else { |
| 1976 | spur_subchannel_sd = 0; |
| 1977 | bb_spur_off = bb_spur; |
| 1978 | } |
| 1979 | |
| 1980 | if (IS_CHAN_HT40(chan)) |
| 1981 | spur_delta_phase = |
| 1982 | ((bb_spur * 262144) / |
| 1983 | 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE; |
| 1984 | else |
| 1985 | spur_delta_phase = |
| 1986 | ((bb_spur * 524288) / |
| 1987 | 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE; |
| 1988 | |
| 1989 | denominator = IS_CHAN_2GHZ(chan) ? 44 : 40; |
| 1990 | spur_freq_sd = ((bb_spur_off * 2048) / denominator) & 0x3ff; |
| 1991 | |
| 1992 | newVal = (AR_PHY_TIMING11_USE_SPUR_IN_AGC | |
| 1993 | SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) | |
| 1994 | SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE)); |
| 1995 | REG_WRITE(ah, AR_PHY_TIMING11, newVal); |
| 1996 | |
| 1997 | newVal = spur_subchannel_sd << AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S; |
| 1998 | REG_WRITE(ah, AR_PHY_SFCORR_EXT, newVal); |
| 1999 | |
| 2000 | cur_bin = -6000; |
| 2001 | upper = bin + 100; |
| 2002 | lower = bin - 100; |
| 2003 | |
| 2004 | for (i = 0; i < 4; i++) { |
| 2005 | int pilot_mask = 0; |
| 2006 | int chan_mask = 0; |
| 2007 | int bp = 0; |
| 2008 | for (bp = 0; bp < 30; bp++) { |
| 2009 | if ((cur_bin > lower) && (cur_bin < upper)) { |
| 2010 | pilot_mask = pilot_mask | 0x1 << bp; |
| 2011 | chan_mask = chan_mask | 0x1 << bp; |
| 2012 | } |
| 2013 | cur_bin += 100; |
| 2014 | } |
| 2015 | cur_bin += inc[i]; |
| 2016 | REG_WRITE(ah, pilot_mask_reg[i], pilot_mask); |
| 2017 | REG_WRITE(ah, chan_mask_reg[i], chan_mask); |
| 2018 | } |
| 2019 | |
| 2020 | cur_vit_mask = 6100; |
| 2021 | upper = bin + 120; |
| 2022 | lower = bin - 120; |
| 2023 | |
| 2024 | for (i = 0; i < 123; i++) { |
| 2025 | if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) { |
Adrian Bunk | b08cbcd | 2008-08-05 22:06:51 +0300 | [diff] [blame] | 2026 | |
| 2027 | /* workaround for gcc bug #37014 */ |
Luis R. Rodriguez | a085ff7 | 2008-12-23 15:58:51 -0800 | [diff] [blame] | 2028 | volatile int tmp_v = abs(cur_vit_mask - bin); |
Adrian Bunk | b08cbcd | 2008-08-05 22:06:51 +0300 | [diff] [blame] | 2029 | |
Luis R. Rodriguez | a085ff7 | 2008-12-23 15:58:51 -0800 | [diff] [blame] | 2030 | if (tmp_v < 75) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2031 | mask_amt = 1; |
| 2032 | else |
| 2033 | mask_amt = 0; |
| 2034 | if (cur_vit_mask < 0) |
| 2035 | mask_m[abs(cur_vit_mask / 100)] = mask_amt; |
| 2036 | else |
| 2037 | mask_p[cur_vit_mask / 100] = mask_amt; |
| 2038 | } |
| 2039 | cur_vit_mask -= 100; |
| 2040 | } |
| 2041 | |
| 2042 | tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28) |
| 2043 | | (mask_m[48] << 26) | (mask_m[49] << 24) |
| 2044 | | (mask_m[50] << 22) | (mask_m[51] << 20) |
| 2045 | | (mask_m[52] << 18) | (mask_m[53] << 16) |
| 2046 | | (mask_m[54] << 14) | (mask_m[55] << 12) |
| 2047 | | (mask_m[56] << 10) | (mask_m[57] << 8) |
| 2048 | | (mask_m[58] << 6) | (mask_m[59] << 4) |
| 2049 | | (mask_m[60] << 2) | (mask_m[61] << 0); |
| 2050 | REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask); |
| 2051 | REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask); |
| 2052 | |
| 2053 | tmp_mask = (mask_m[31] << 28) |
| 2054 | | (mask_m[32] << 26) | (mask_m[33] << 24) |
| 2055 | | (mask_m[34] << 22) | (mask_m[35] << 20) |
| 2056 | | (mask_m[36] << 18) | (mask_m[37] << 16) |
| 2057 | | (mask_m[48] << 14) | (mask_m[39] << 12) |
| 2058 | | (mask_m[40] << 10) | (mask_m[41] << 8) |
| 2059 | | (mask_m[42] << 6) | (mask_m[43] << 4) |
| 2060 | | (mask_m[44] << 2) | (mask_m[45] << 0); |
| 2061 | REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask); |
| 2062 | REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask); |
| 2063 | |
| 2064 | tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28) |
| 2065 | | (mask_m[18] << 26) | (mask_m[18] << 24) |
| 2066 | | (mask_m[20] << 22) | (mask_m[20] << 20) |
| 2067 | | (mask_m[22] << 18) | (mask_m[22] << 16) |
| 2068 | | (mask_m[24] << 14) | (mask_m[24] << 12) |
| 2069 | | (mask_m[25] << 10) | (mask_m[26] << 8) |
| 2070 | | (mask_m[27] << 6) | (mask_m[28] << 4) |
| 2071 | | (mask_m[29] << 2) | (mask_m[30] << 0); |
| 2072 | REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask); |
| 2073 | REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask); |
| 2074 | |
| 2075 | tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28) |
| 2076 | | (mask_m[2] << 26) | (mask_m[3] << 24) |
| 2077 | | (mask_m[4] << 22) | (mask_m[5] << 20) |
| 2078 | | (mask_m[6] << 18) | (mask_m[7] << 16) |
| 2079 | | (mask_m[8] << 14) | (mask_m[9] << 12) |
| 2080 | | (mask_m[10] << 10) | (mask_m[11] << 8) |
| 2081 | | (mask_m[12] << 6) | (mask_m[13] << 4) |
| 2082 | | (mask_m[14] << 2) | (mask_m[15] << 0); |
| 2083 | REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask); |
| 2084 | REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask); |
| 2085 | |
| 2086 | tmp_mask = (mask_p[15] << 28) |
| 2087 | | (mask_p[14] << 26) | (mask_p[13] << 24) |
| 2088 | | (mask_p[12] << 22) | (mask_p[11] << 20) |
| 2089 | | (mask_p[10] << 18) | (mask_p[9] << 16) |
| 2090 | | (mask_p[8] << 14) | (mask_p[7] << 12) |
| 2091 | | (mask_p[6] << 10) | (mask_p[5] << 8) |
| 2092 | | (mask_p[4] << 6) | (mask_p[3] << 4) |
| 2093 | | (mask_p[2] << 2) | (mask_p[1] << 0); |
| 2094 | REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask); |
| 2095 | REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask); |
| 2096 | |
| 2097 | tmp_mask = (mask_p[30] << 28) |
| 2098 | | (mask_p[29] << 26) | (mask_p[28] << 24) |
| 2099 | | (mask_p[27] << 22) | (mask_p[26] << 20) |
| 2100 | | (mask_p[25] << 18) | (mask_p[24] << 16) |
| 2101 | | (mask_p[23] << 14) | (mask_p[22] << 12) |
| 2102 | | (mask_p[21] << 10) | (mask_p[20] << 8) |
| 2103 | | (mask_p[19] << 6) | (mask_p[18] << 4) |
| 2104 | | (mask_p[17] << 2) | (mask_p[16] << 0); |
| 2105 | REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask); |
| 2106 | REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask); |
| 2107 | |
| 2108 | tmp_mask = (mask_p[45] << 28) |
| 2109 | | (mask_p[44] << 26) | (mask_p[43] << 24) |
| 2110 | | (mask_p[42] << 22) | (mask_p[41] << 20) |
| 2111 | | (mask_p[40] << 18) | (mask_p[39] << 16) |
| 2112 | | (mask_p[38] << 14) | (mask_p[37] << 12) |
| 2113 | | (mask_p[36] << 10) | (mask_p[35] << 8) |
| 2114 | | (mask_p[34] << 6) | (mask_p[33] << 4) |
| 2115 | | (mask_p[32] << 2) | (mask_p[31] << 0); |
| 2116 | REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask); |
| 2117 | REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask); |
| 2118 | |
| 2119 | tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28) |
| 2120 | | (mask_p[59] << 26) | (mask_p[58] << 24) |
| 2121 | | (mask_p[57] << 22) | (mask_p[56] << 20) |
| 2122 | | (mask_p[55] << 18) | (mask_p[54] << 16) |
| 2123 | | (mask_p[53] << 14) | (mask_p[52] << 12) |
| 2124 | | (mask_p[51] << 10) | (mask_p[50] << 8) |
| 2125 | | (mask_p[49] << 6) | (mask_p[48] << 4) |
| 2126 | | (mask_p[47] << 2) | (mask_p[46] << 0); |
| 2127 | REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask); |
| 2128 | REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask); |
| 2129 | } |
| 2130 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2131 | static void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2132 | { |
| 2133 | int bb_spur = AR_NO_SPUR; |
| 2134 | int bin, cur_bin; |
| 2135 | int spur_freq_sd; |
| 2136 | int spur_delta_phase; |
| 2137 | int denominator; |
| 2138 | int upper, lower, cur_vit_mask; |
| 2139 | int tmp, new; |
| 2140 | int i; |
| 2141 | int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8, |
| 2142 | AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60 |
| 2143 | }; |
| 2144 | int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10, |
| 2145 | AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60 |
| 2146 | }; |
| 2147 | int inc[4] = { 0, 100, 0, 0 }; |
| 2148 | |
| 2149 | int8_t mask_m[123]; |
| 2150 | int8_t mask_p[123]; |
| 2151 | int8_t mask_amt; |
| 2152 | int tmp_mask; |
| 2153 | int cur_bb_spur; |
| 2154 | bool is2GHz = IS_CHAN_2GHZ(chan); |
| 2155 | |
| 2156 | memset(&mask_m, 0, sizeof(int8_t) * 123); |
| 2157 | memset(&mask_p, 0, sizeof(int8_t) * 123); |
| 2158 | |
| 2159 | for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) { |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2160 | cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2161 | if (AR_NO_SPUR == cur_bb_spur) |
| 2162 | break; |
| 2163 | cur_bb_spur = cur_bb_spur - (chan->channel * 10); |
| 2164 | if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) { |
| 2165 | bb_spur = cur_bb_spur; |
| 2166 | break; |
| 2167 | } |
| 2168 | } |
| 2169 | |
| 2170 | if (AR_NO_SPUR == bb_spur) |
| 2171 | return; |
| 2172 | |
| 2173 | bin = bb_spur * 32; |
| 2174 | |
| 2175 | tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0)); |
| 2176 | new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI | |
| 2177 | AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER | |
| 2178 | AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK | |
| 2179 | AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK); |
| 2180 | |
| 2181 | REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new); |
| 2182 | |
| 2183 | new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL | |
| 2184 | AR_PHY_SPUR_REG_ENABLE_MASK_PPM | |
| 2185 | AR_PHY_SPUR_REG_MASK_RATE_SELECT | |
| 2186 | AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI | |
| 2187 | SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH)); |
| 2188 | REG_WRITE(ah, AR_PHY_SPUR_REG, new); |
| 2189 | |
| 2190 | spur_delta_phase = ((bb_spur * 524288) / 100) & |
| 2191 | AR_PHY_TIMING11_SPUR_DELTA_PHASE; |
| 2192 | |
| 2193 | denominator = IS_CHAN_2GHZ(chan) ? 440 : 400; |
| 2194 | spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff; |
| 2195 | |
| 2196 | new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC | |
| 2197 | SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) | |
| 2198 | SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE)); |
| 2199 | REG_WRITE(ah, AR_PHY_TIMING11, new); |
| 2200 | |
| 2201 | cur_bin = -6000; |
| 2202 | upper = bin + 100; |
| 2203 | lower = bin - 100; |
| 2204 | |
| 2205 | for (i = 0; i < 4; i++) { |
| 2206 | int pilot_mask = 0; |
| 2207 | int chan_mask = 0; |
| 2208 | int bp = 0; |
| 2209 | for (bp = 0; bp < 30; bp++) { |
| 2210 | if ((cur_bin > lower) && (cur_bin < upper)) { |
| 2211 | pilot_mask = pilot_mask | 0x1 << bp; |
| 2212 | chan_mask = chan_mask | 0x1 << bp; |
| 2213 | } |
| 2214 | cur_bin += 100; |
| 2215 | } |
| 2216 | cur_bin += inc[i]; |
| 2217 | REG_WRITE(ah, pilot_mask_reg[i], pilot_mask); |
| 2218 | REG_WRITE(ah, chan_mask_reg[i], chan_mask); |
| 2219 | } |
| 2220 | |
| 2221 | cur_vit_mask = 6100; |
| 2222 | upper = bin + 120; |
| 2223 | lower = bin - 120; |
| 2224 | |
| 2225 | for (i = 0; i < 123; i++) { |
| 2226 | if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) { |
Adrian Bunk | 88b9e2b | 2008-08-05 22:06:51 +0300 | [diff] [blame] | 2227 | |
| 2228 | /* workaround for gcc bug #37014 */ |
Luis R. Rodriguez | a085ff7 | 2008-12-23 15:58:51 -0800 | [diff] [blame] | 2229 | volatile int tmp_v = abs(cur_vit_mask - bin); |
Adrian Bunk | 88b9e2b | 2008-08-05 22:06:51 +0300 | [diff] [blame] | 2230 | |
Luis R. Rodriguez | a085ff7 | 2008-12-23 15:58:51 -0800 | [diff] [blame] | 2231 | if (tmp_v < 75) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2232 | mask_amt = 1; |
| 2233 | else |
| 2234 | mask_amt = 0; |
| 2235 | if (cur_vit_mask < 0) |
| 2236 | mask_m[abs(cur_vit_mask / 100)] = mask_amt; |
| 2237 | else |
| 2238 | mask_p[cur_vit_mask / 100] = mask_amt; |
| 2239 | } |
| 2240 | cur_vit_mask -= 100; |
| 2241 | } |
| 2242 | |
| 2243 | tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28) |
| 2244 | | (mask_m[48] << 26) | (mask_m[49] << 24) |
| 2245 | | (mask_m[50] << 22) | (mask_m[51] << 20) |
| 2246 | | (mask_m[52] << 18) | (mask_m[53] << 16) |
| 2247 | | (mask_m[54] << 14) | (mask_m[55] << 12) |
| 2248 | | (mask_m[56] << 10) | (mask_m[57] << 8) |
| 2249 | | (mask_m[58] << 6) | (mask_m[59] << 4) |
| 2250 | | (mask_m[60] << 2) | (mask_m[61] << 0); |
| 2251 | REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask); |
| 2252 | REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask); |
| 2253 | |
| 2254 | tmp_mask = (mask_m[31] << 28) |
| 2255 | | (mask_m[32] << 26) | (mask_m[33] << 24) |
| 2256 | | (mask_m[34] << 22) | (mask_m[35] << 20) |
| 2257 | | (mask_m[36] << 18) | (mask_m[37] << 16) |
| 2258 | | (mask_m[48] << 14) | (mask_m[39] << 12) |
| 2259 | | (mask_m[40] << 10) | (mask_m[41] << 8) |
| 2260 | | (mask_m[42] << 6) | (mask_m[43] << 4) |
| 2261 | | (mask_m[44] << 2) | (mask_m[45] << 0); |
| 2262 | REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask); |
| 2263 | REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask); |
| 2264 | |
| 2265 | tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28) |
| 2266 | | (mask_m[18] << 26) | (mask_m[18] << 24) |
| 2267 | | (mask_m[20] << 22) | (mask_m[20] << 20) |
| 2268 | | (mask_m[22] << 18) | (mask_m[22] << 16) |
| 2269 | | (mask_m[24] << 14) | (mask_m[24] << 12) |
| 2270 | | (mask_m[25] << 10) | (mask_m[26] << 8) |
| 2271 | | (mask_m[27] << 6) | (mask_m[28] << 4) |
| 2272 | | (mask_m[29] << 2) | (mask_m[30] << 0); |
| 2273 | REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask); |
| 2274 | REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask); |
| 2275 | |
| 2276 | tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28) |
| 2277 | | (mask_m[2] << 26) | (mask_m[3] << 24) |
| 2278 | | (mask_m[4] << 22) | (mask_m[5] << 20) |
| 2279 | | (mask_m[6] << 18) | (mask_m[7] << 16) |
| 2280 | | (mask_m[8] << 14) | (mask_m[9] << 12) |
| 2281 | | (mask_m[10] << 10) | (mask_m[11] << 8) |
| 2282 | | (mask_m[12] << 6) | (mask_m[13] << 4) |
| 2283 | | (mask_m[14] << 2) | (mask_m[15] << 0); |
| 2284 | REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask); |
| 2285 | REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask); |
| 2286 | |
| 2287 | tmp_mask = (mask_p[15] << 28) |
| 2288 | | (mask_p[14] << 26) | (mask_p[13] << 24) |
| 2289 | | (mask_p[12] << 22) | (mask_p[11] << 20) |
| 2290 | | (mask_p[10] << 18) | (mask_p[9] << 16) |
| 2291 | | (mask_p[8] << 14) | (mask_p[7] << 12) |
| 2292 | | (mask_p[6] << 10) | (mask_p[5] << 8) |
| 2293 | | (mask_p[4] << 6) | (mask_p[3] << 4) |
| 2294 | | (mask_p[2] << 2) | (mask_p[1] << 0); |
| 2295 | REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask); |
| 2296 | REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask); |
| 2297 | |
| 2298 | tmp_mask = (mask_p[30] << 28) |
| 2299 | | (mask_p[29] << 26) | (mask_p[28] << 24) |
| 2300 | | (mask_p[27] << 22) | (mask_p[26] << 20) |
| 2301 | | (mask_p[25] << 18) | (mask_p[24] << 16) |
| 2302 | | (mask_p[23] << 14) | (mask_p[22] << 12) |
| 2303 | | (mask_p[21] << 10) | (mask_p[20] << 8) |
| 2304 | | (mask_p[19] << 6) | (mask_p[18] << 4) |
| 2305 | | (mask_p[17] << 2) | (mask_p[16] << 0); |
| 2306 | REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask); |
| 2307 | REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask); |
| 2308 | |
| 2309 | tmp_mask = (mask_p[45] << 28) |
| 2310 | | (mask_p[44] << 26) | (mask_p[43] << 24) |
| 2311 | | (mask_p[42] << 22) | (mask_p[41] << 20) |
| 2312 | | (mask_p[40] << 18) | (mask_p[39] << 16) |
| 2313 | | (mask_p[38] << 14) | (mask_p[37] << 12) |
| 2314 | | (mask_p[36] << 10) | (mask_p[35] << 8) |
| 2315 | | (mask_p[34] << 6) | (mask_p[33] << 4) |
| 2316 | | (mask_p[32] << 2) | (mask_p[31] << 0); |
| 2317 | REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask); |
| 2318 | REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask); |
| 2319 | |
| 2320 | tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28) |
| 2321 | | (mask_p[59] << 26) | (mask_p[58] << 24) |
| 2322 | | (mask_p[57] << 22) | (mask_p[56] << 20) |
| 2323 | | (mask_p[55] << 18) | (mask_p[54] << 16) |
| 2324 | | (mask_p[53] << 14) | (mask_p[52] << 12) |
| 2325 | | (mask_p[51] << 10) | (mask_p[50] << 8) |
| 2326 | | (mask_p[49] << 6) | (mask_p[48] << 4) |
| 2327 | | (mask_p[47] << 2) | (mask_p[46] << 0); |
| 2328 | REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask); |
| 2329 | REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask); |
| 2330 | } |
| 2331 | |
Johannes Berg | 3b319aa | 2009-06-13 14:50:26 +0530 | [diff] [blame] | 2332 | static void ath9k_enable_rfkill(struct ath_hw *ah) |
| 2333 | { |
| 2334 | REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, |
| 2335 | AR_GPIO_INPUT_EN_VAL_RFSILENT_BB); |
| 2336 | |
| 2337 | REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2, |
| 2338 | AR_GPIO_INPUT_MUX2_RFSILENT); |
| 2339 | |
| 2340 | ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio); |
| 2341 | REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB); |
| 2342 | } |
| 2343 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2344 | 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] | 2345 | bool bChannelChange) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2346 | { |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame^] | 2347 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2348 | u32 saveLedState; |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 2349 | struct ath_softc *sc = ah->ah_sc; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2350 | struct ath9k_channel *curchan = ah->curchan; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2351 | u32 saveDefAntenna; |
| 2352 | u32 macStaId1; |
Sujith | 46fe782 | 2009-09-17 09:25:25 +0530 | [diff] [blame] | 2353 | u64 tsf = 0; |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 2354 | int i, rx_chainmask, r; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2355 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2356 | ah->extprotspacing = sc->ht_extprotspacing; |
| 2357 | ah->txchainmask = sc->tx_chainmask; |
| 2358 | ah->rxchainmask = sc->rx_chainmask; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2359 | |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 2360 | if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 2361 | return -EIO; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2362 | |
Vasanthakumar Thiagarajan | 9ebef799 | 2009-09-17 09:26:44 +0530 | [diff] [blame] | 2363 | if (curchan && !ah->chip_fullsleep) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2364 | ath9k_hw_getnf(ah, curchan); |
| 2365 | |
| 2366 | if (bChannelChange && |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2367 | (ah->chip_fullsleep != true) && |
| 2368 | (ah->curchan != NULL) && |
| 2369 | (chan->channel != ah->curchan->channel) && |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2370 | ((chan->channelFlags & CHANNEL_ALL) == |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2371 | (ah->curchan->channelFlags & CHANNEL_ALL)) && |
Vasanthakumar Thiagarajan | 0a475cc | 2009-09-17 09:27:10 +0530 | [diff] [blame] | 2372 | !(AR_SREV_9280(ah) || IS_CHAN_A_5MHZ_SPACED(chan) || |
| 2373 | IS_CHAN_A_5MHZ_SPACED(ah->curchan))) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2374 | |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 2375 | if (ath9k_hw_channel_change(ah, chan, sc->tx_chan_width)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2376 | ath9k_hw_loadnf(ah, ah->curchan); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2377 | ath9k_hw_start_nfcal(ah); |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 2378 | return 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2379 | } |
| 2380 | } |
| 2381 | |
| 2382 | saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA); |
| 2383 | if (saveDefAntenna == 0) |
| 2384 | saveDefAntenna = 1; |
| 2385 | |
| 2386 | macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B; |
| 2387 | |
Sujith | 46fe782 | 2009-09-17 09:25:25 +0530 | [diff] [blame] | 2388 | /* For chips on which RTC reset is done, save TSF before it gets cleared */ |
| 2389 | if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) |
| 2390 | tsf = ath9k_hw_gettsf64(ah); |
| 2391 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2392 | saveLedState = REG_READ(ah, AR_CFG_LED) & |
| 2393 | (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL | |
| 2394 | AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW); |
| 2395 | |
| 2396 | ath9k_hw_mark_phy_inactive(ah); |
| 2397 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 2398 | if (AR_SREV_9271(ah) && ah->htc_reset_init) { |
| 2399 | REG_WRITE(ah, |
| 2400 | AR9271_RESET_POWER_DOWN_CONTROL, |
| 2401 | AR9271_RADIO_RF_RST); |
| 2402 | udelay(50); |
| 2403 | } |
| 2404 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2405 | if (!ath9k_hw_chip_reset(ah, chan)) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 2406 | DPRINTF(ah, ATH_DBG_FATAL, "Chip reset failed\n"); |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 2407 | return -EINVAL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2408 | } |
| 2409 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 2410 | if (AR_SREV_9271(ah) && ah->htc_reset_init) { |
| 2411 | ah->htc_reset_init = false; |
| 2412 | REG_WRITE(ah, |
| 2413 | AR9271_RESET_POWER_DOWN_CONTROL, |
| 2414 | AR9271_GATE_MAC_CTL); |
| 2415 | udelay(50); |
| 2416 | } |
| 2417 | |
Sujith | 46fe782 | 2009-09-17 09:25:25 +0530 | [diff] [blame] | 2418 | /* Restore TSF */ |
| 2419 | if (tsf && AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) |
| 2420 | ath9k_hw_settsf64(ah, tsf); |
| 2421 | |
Vasanthakumar Thiagarajan | 369391d | 2009-01-21 19:24:13 +0530 | [diff] [blame] | 2422 | if (AR_SREV_9280_10_OR_LATER(ah)) |
| 2423 | 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] | 2424 | |
Vivek Natarajan | 326bebb | 2009-08-14 11:33:36 +0530 | [diff] [blame] | 2425 | if (AR_SREV_9287_12_OR_LATER(ah)) { |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 2426 | /* Enable ASYNC FIFO */ |
| 2427 | REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3, |
| 2428 | AR_MAC_PCU_ASYNC_FIFO_REG3_DATAPATH_SEL); |
| 2429 | REG_SET_BIT(ah, AR_PHY_MODE, AR_PHY_MODE_ASYNCFIFO); |
| 2430 | REG_CLR_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3, |
| 2431 | AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET); |
| 2432 | REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3, |
| 2433 | AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET); |
| 2434 | } |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 2435 | r = ath9k_hw_process_ini(ah, chan, sc->tx_chan_width); |
| 2436 | if (r) |
| 2437 | return r; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2438 | |
Jouni Malinen | 0ced0e1 | 2009-01-08 13:32:13 +0200 | [diff] [blame] | 2439 | /* Setup MFP options for CCMP */ |
| 2440 | if (AR_SREV_9280_20_OR_LATER(ah)) { |
| 2441 | /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt |
| 2442 | * frames when constructing CCMP AAD. */ |
| 2443 | REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT, |
| 2444 | 0xc7ff); |
| 2445 | ah->sw_mgmt_crypto = false; |
| 2446 | } else if (AR_SREV_9160_10_OR_LATER(ah)) { |
| 2447 | /* Disable hardware crypto for management frames */ |
| 2448 | REG_CLR_BIT(ah, AR_PCU_MISC_MODE2, |
| 2449 | AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE); |
| 2450 | REG_SET_BIT(ah, AR_PCU_MISC_MODE2, |
| 2451 | AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT); |
| 2452 | ah->sw_mgmt_crypto = true; |
| 2453 | } else |
| 2454 | ah->sw_mgmt_crypto = true; |
| 2455 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2456 | if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan)) |
| 2457 | ath9k_hw_set_delta_slope(ah, chan); |
| 2458 | |
| 2459 | if (AR_SREV_9280_10_OR_LATER(ah)) |
| 2460 | ath9k_hw_9280_spur_mitigate(ah, chan); |
| 2461 | else |
| 2462 | ath9k_hw_spur_mitigate(ah, chan); |
| 2463 | |
Sujith | d650915 | 2009-03-13 08:56:05 +0530 | [diff] [blame] | 2464 | ah->eep_ops->set_board_values(ah, chan); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2465 | |
| 2466 | ath9k_hw_decrease_chain_power(ah, chan); |
| 2467 | |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame^] | 2468 | REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr)); |
| 2469 | 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] | 2470 | | macStaId1 |
| 2471 | | AR_STA_ID1_RTS_USE_DEF |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2472 | | (ah->config. |
Sujith | 60b67f5 | 2008-08-07 10:52:38 +0530 | [diff] [blame] | 2473 | ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2474 | | ah->sta_id1_defaults); |
| 2475 | ath9k_hw_set_operating_mode(ah, ah->opmode); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2476 | |
Luis R. Rodriguez | 7664072 | 2009-09-10 08:54:56 -0700 | [diff] [blame] | 2477 | ath9k_hw_setbssidmask(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2478 | |
| 2479 | REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna); |
| 2480 | |
Luis R. Rodriguez | 3453ad8 | 2009-09-10 08:57:00 -0700 | [diff] [blame] | 2481 | ath9k_hw_write_associd(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2482 | |
| 2483 | REG_WRITE(ah, AR_ISR, ~0); |
| 2484 | |
| 2485 | REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR); |
| 2486 | |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 2487 | if (AR_SREV_9280_10_OR_LATER(ah)) |
| 2488 | ath9k_hw_ar9280_set_channel(ah, chan); |
| 2489 | else |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 2490 | if (!(ath9k_hw_set_channel(ah, chan))) |
| 2491 | return -EIO; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2492 | |
| 2493 | for (i = 0; i < AR_NUM_DCU; i++) |
| 2494 | REG_WRITE(ah, AR_DQCUMASK(i), 1 << i); |
| 2495 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2496 | ah->intr_txqs = 0; |
| 2497 | for (i = 0; i < ah->caps.total_queues; i++) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2498 | ath9k_hw_resettxqueue(ah, i); |
| 2499 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2500 | ath9k_hw_init_interrupt_masks(ah, ah->opmode); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2501 | ath9k_hw_init_qos(ah); |
| 2502 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2503 | if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT) |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 2504 | ath9k_enable_rfkill(ah); |
Johannes Berg | 3b319aa | 2009-06-13 14:50:26 +0530 | [diff] [blame] | 2505 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2506 | ath9k_hw_init_user_settings(ah); |
| 2507 | |
Vivek Natarajan | 326bebb | 2009-08-14 11:33:36 +0530 | [diff] [blame] | 2508 | if (AR_SREV_9287_12_OR_LATER(ah)) { |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 2509 | REG_WRITE(ah, AR_D_GBL_IFS_SIFS, |
| 2510 | AR_D_GBL_IFS_SIFS_ASYNC_FIFO_DUR); |
| 2511 | REG_WRITE(ah, AR_D_GBL_IFS_SLOT, |
| 2512 | AR_D_GBL_IFS_SLOT_ASYNC_FIFO_DUR); |
| 2513 | REG_WRITE(ah, AR_D_GBL_IFS_EIFS, |
| 2514 | AR_D_GBL_IFS_EIFS_ASYNC_FIFO_DUR); |
| 2515 | |
| 2516 | REG_WRITE(ah, AR_TIME_OUT, AR_TIME_OUT_ACK_CTS_ASYNC_FIFO_DUR); |
| 2517 | REG_WRITE(ah, AR_USEC, AR_USEC_ASYNC_FIFO_DUR); |
| 2518 | |
| 2519 | REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER, |
| 2520 | AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768); |
| 2521 | REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN, |
| 2522 | AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL); |
| 2523 | } |
Vivek Natarajan | 326bebb | 2009-08-14 11:33:36 +0530 | [diff] [blame] | 2524 | if (AR_SREV_9287_12_OR_LATER(ah)) { |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 2525 | REG_SET_BIT(ah, AR_PCU_MISC_MODE2, |
| 2526 | AR_PCU_MISC_MODE2_ENABLE_AGGWEP); |
| 2527 | } |
| 2528 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2529 | REG_WRITE(ah, AR_STA_ID1, |
| 2530 | REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM); |
| 2531 | |
| 2532 | ath9k_hw_set_dma(ah); |
| 2533 | |
| 2534 | REG_WRITE(ah, AR_OBS, 8); |
| 2535 | |
Sujith | 0ef1f16 | 2009-03-30 15:28:35 +0530 | [diff] [blame] | 2536 | if (ah->config.intr_mitigation) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2537 | REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500); |
| 2538 | REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000); |
| 2539 | } |
| 2540 | |
| 2541 | ath9k_hw_init_bb(ah, chan); |
| 2542 | |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 2543 | if (!ath9k_hw_init_cal(ah, chan)) |
Joe Perches | 6badaaf | 2009-06-28 09:26:32 -0700 | [diff] [blame] | 2544 | return -EIO; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2545 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2546 | rx_chainmask = ah->rxchainmask; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2547 | if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) { |
| 2548 | REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask); |
| 2549 | REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask); |
| 2550 | } |
| 2551 | |
| 2552 | REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ); |
| 2553 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 2554 | /* |
| 2555 | * For big endian systems turn on swapping for descriptors |
| 2556 | */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2557 | if (AR_SREV_9100(ah)) { |
| 2558 | u32 mask; |
| 2559 | mask = REG_READ(ah, AR_CFG); |
| 2560 | if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 2561 | DPRINTF(ah, ATH_DBG_RESET, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 2562 | "CFG Byte Swap Set 0x%x\n", mask); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2563 | } else { |
| 2564 | mask = |
| 2565 | INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB; |
| 2566 | REG_WRITE(ah, AR_CFG, mask); |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 2567 | DPRINTF(ah, ATH_DBG_RESET, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 2568 | "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2569 | } |
| 2570 | } else { |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 2571 | /* Configure AR9271 target WLAN */ |
| 2572 | if (AR_SREV_9271(ah)) |
| 2573 | REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2574 | #ifdef __BIG_ENDIAN |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 2575 | else |
| 2576 | REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2577 | #endif |
| 2578 | } |
| 2579 | |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 2580 | if (ah->btcoex_hw.enabled) |
Vasanthakumar Thiagarajan | 42cc41e | 2009-08-26 21:08:45 +0530 | [diff] [blame] | 2581 | ath9k_hw_btcoex_enable(ah); |
| 2582 | |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 2583 | return 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2584 | } |
| 2585 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2586 | /************************/ |
| 2587 | /* Key Cache Management */ |
| 2588 | /************************/ |
| 2589 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2590 | bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2591 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2592 | u32 keyType; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2593 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2594 | if (entry >= ah->caps.keycache_size) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 2595 | DPRINTF(ah, ATH_DBG_FATAL, |
Sujith | d8baa93 | 2009-03-30 15:28:25 +0530 | [diff] [blame] | 2596 | "keychache entry %u out of range\n", entry); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2597 | return false; |
| 2598 | } |
| 2599 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2600 | keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2601 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2602 | REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0); |
| 2603 | REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0); |
| 2604 | REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0); |
| 2605 | REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0); |
| 2606 | REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0); |
| 2607 | REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR); |
| 2608 | REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0); |
| 2609 | REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0); |
| 2610 | |
| 2611 | if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) { |
| 2612 | u16 micentry = entry + 64; |
| 2613 | |
| 2614 | REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0); |
| 2615 | REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0); |
| 2616 | REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0); |
| 2617 | REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0); |
| 2618 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2619 | } |
| 2620 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2621 | return true; |
| 2622 | } |
| 2623 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2624 | 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] | 2625 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2626 | u32 macHi, macLo; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2627 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2628 | if (entry >= ah->caps.keycache_size) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 2629 | DPRINTF(ah, ATH_DBG_FATAL, |
Sujith | d8baa93 | 2009-03-30 15:28:25 +0530 | [diff] [blame] | 2630 | "keychache entry %u out of range\n", entry); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2631 | return false; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2632 | } |
| 2633 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2634 | if (mac != NULL) { |
| 2635 | macHi = (mac[5] << 8) | mac[4]; |
| 2636 | macLo = (mac[3] << 24) | |
| 2637 | (mac[2] << 16) | |
| 2638 | (mac[1] << 8) | |
| 2639 | mac[0]; |
| 2640 | macLo >>= 1; |
| 2641 | macLo |= (macHi & 1) << 31; |
| 2642 | macHi >>= 1; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2643 | } else { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2644 | macLo = macHi = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2645 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2646 | REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo); |
| 2647 | REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2648 | |
| 2649 | return true; |
| 2650 | } |
| 2651 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2652 | bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2653 | const struct ath9k_keyval *k, |
Jouni Malinen | e0caf9e | 2009-03-02 18:15:53 +0200 | [diff] [blame] | 2654 | const u8 *mac) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2655 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2656 | const struct ath9k_hw_capabilities *pCap = &ah->caps; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2657 | u32 key0, key1, key2, key3, key4; |
| 2658 | u32 keyType; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2659 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2660 | if (entry >= pCap->keycache_size) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 2661 | DPRINTF(ah, ATH_DBG_FATAL, |
Sujith | d8baa93 | 2009-03-30 15:28:25 +0530 | [diff] [blame] | 2662 | "keycache entry %u out of range\n", entry); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2663 | return false; |
| 2664 | } |
| 2665 | |
| 2666 | switch (k->kv_type) { |
| 2667 | case ATH9K_CIPHER_AES_OCB: |
| 2668 | keyType = AR_KEYTABLE_TYPE_AES; |
| 2669 | break; |
| 2670 | case ATH9K_CIPHER_AES_CCM: |
| 2671 | if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 2672 | DPRINTF(ah, ATH_DBG_ANY, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 2673 | "AES-CCM not supported by mac rev 0x%x\n", |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 2674 | ah->hw_version.macRev); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2675 | return false; |
| 2676 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2677 | keyType = AR_KEYTABLE_TYPE_CCM; |
| 2678 | break; |
| 2679 | case ATH9K_CIPHER_TKIP: |
| 2680 | keyType = AR_KEYTABLE_TYPE_TKIP; |
| 2681 | if (ATH9K_IS_MIC_ENABLED(ah) |
| 2682 | && entry + 64 >= pCap->keycache_size) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 2683 | DPRINTF(ah, ATH_DBG_ANY, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 2684 | "entry %u inappropriate for TKIP\n", entry); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2685 | return false; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2686 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2687 | break; |
| 2688 | case ATH9K_CIPHER_WEP: |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 2689 | if (k->kv_len < WLAN_KEY_LEN_WEP40) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 2690 | DPRINTF(ah, ATH_DBG_ANY, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 2691 | "WEP key length %u too small\n", k->kv_len); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2692 | return false; |
| 2693 | } |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 2694 | if (k->kv_len <= WLAN_KEY_LEN_WEP40) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2695 | keyType = AR_KEYTABLE_TYPE_40; |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 2696 | else if (k->kv_len <= WLAN_KEY_LEN_WEP104) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2697 | keyType = AR_KEYTABLE_TYPE_104; |
| 2698 | else |
| 2699 | keyType = AR_KEYTABLE_TYPE_128; |
| 2700 | break; |
| 2701 | case ATH9K_CIPHER_CLR: |
| 2702 | keyType = AR_KEYTABLE_TYPE_CLR; |
| 2703 | break; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2704 | default: |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 2705 | DPRINTF(ah, ATH_DBG_FATAL, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 2706 | "cipher %u not supported\n", k->kv_type); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2707 | return false; |
| 2708 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2709 | |
Jouni Malinen | e0caf9e | 2009-03-02 18:15:53 +0200 | [diff] [blame] | 2710 | key0 = get_unaligned_le32(k->kv_val + 0); |
| 2711 | key1 = get_unaligned_le16(k->kv_val + 4); |
| 2712 | key2 = get_unaligned_le32(k->kv_val + 6); |
| 2713 | key3 = get_unaligned_le16(k->kv_val + 10); |
| 2714 | key4 = get_unaligned_le32(k->kv_val + 12); |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 2715 | if (k->kv_len <= WLAN_KEY_LEN_WEP104) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2716 | key4 &= 0xff; |
| 2717 | |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2718 | /* |
| 2719 | * Note: Key cache registers access special memory area that requires |
| 2720 | * two 32-bit writes to actually update the values in the internal |
| 2721 | * memory. Consequently, the exact order and pairs used here must be |
| 2722 | * maintained. |
| 2723 | */ |
| 2724 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2725 | if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) { |
| 2726 | u16 micentry = entry + 64; |
| 2727 | |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2728 | /* |
| 2729 | * Write inverted key[47:0] first to avoid Michael MIC errors |
| 2730 | * on frames that could be sent or received at the same time. |
| 2731 | * The correct key will be written in the end once everything |
| 2732 | * else is ready. |
| 2733 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2734 | REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0); |
| 2735 | REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2736 | |
| 2737 | /* Write key[95:48] */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2738 | REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2); |
| 2739 | REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2740 | |
| 2741 | /* Write key[127:96] and key type */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2742 | REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4); |
| 2743 | REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2744 | |
| 2745 | /* Write MAC address for the entry */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2746 | (void) ath9k_hw_keysetmac(ah, entry, mac); |
| 2747 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2748 | if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) { |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2749 | /* |
| 2750 | * TKIP uses two key cache entries: |
| 2751 | * Michael MIC TX/RX keys in the same key cache entry |
| 2752 | * (idx = main index + 64): |
| 2753 | * key0 [31:0] = RX key [31:0] |
| 2754 | * key1 [15:0] = TX key [31:16] |
| 2755 | * key1 [31:16] = reserved |
| 2756 | * key2 [31:0] = RX key [63:32] |
| 2757 | * key3 [15:0] = TX key [15:0] |
| 2758 | * key3 [31:16] = reserved |
| 2759 | * key4 [31:0] = TX key [63:32] |
| 2760 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2761 | u32 mic0, mic1, mic2, mic3, mic4; |
| 2762 | |
| 2763 | mic0 = get_unaligned_le32(k->kv_mic + 0); |
| 2764 | mic2 = get_unaligned_le32(k->kv_mic + 4); |
| 2765 | mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff; |
| 2766 | mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff; |
| 2767 | mic4 = get_unaligned_le32(k->kv_txmic + 4); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2768 | |
| 2769 | /* Write RX[31:0] and TX[31:16] */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2770 | REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0); |
| 2771 | REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2772 | |
| 2773 | /* Write RX[63:32] and TX[15:0] */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2774 | REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2); |
| 2775 | REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2776 | |
| 2777 | /* Write TX[63:32] and keyType(reserved) */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2778 | REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4); |
| 2779 | REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry), |
| 2780 | AR_KEYTABLE_TYPE_CLR); |
| 2781 | |
| 2782 | } else { |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2783 | /* |
| 2784 | * TKIP uses four key cache entries (two for group |
| 2785 | * keys): |
| 2786 | * Michael MIC TX/RX keys are in different key cache |
| 2787 | * entries (idx = main index + 64 for TX and |
| 2788 | * main index + 32 + 96 for RX): |
| 2789 | * key0 [31:0] = TX/RX MIC key [31:0] |
| 2790 | * key1 [31:0] = reserved |
| 2791 | * key2 [31:0] = TX/RX MIC key [63:32] |
| 2792 | * key3 [31:0] = reserved |
| 2793 | * key4 [31:0] = reserved |
| 2794 | * |
| 2795 | * Upper layer code will call this function separately |
| 2796 | * for TX and RX keys when these registers offsets are |
| 2797 | * used. |
| 2798 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2799 | u32 mic0, mic2; |
| 2800 | |
| 2801 | mic0 = get_unaligned_le32(k->kv_mic + 0); |
| 2802 | mic2 = get_unaligned_le32(k->kv_mic + 4); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2803 | |
| 2804 | /* Write MIC key[31:0] */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2805 | REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0); |
| 2806 | REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2807 | |
| 2808 | /* Write MIC key[63:32] */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2809 | REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2); |
| 2810 | REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2811 | |
| 2812 | /* Write TX[63:32] and keyType(reserved) */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2813 | REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0); |
| 2814 | REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry), |
| 2815 | AR_KEYTABLE_TYPE_CLR); |
| 2816 | } |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2817 | |
| 2818 | /* MAC address registers are reserved for the MIC entry */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2819 | REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0); |
| 2820 | REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2821 | |
| 2822 | /* |
| 2823 | * Write the correct (un-inverted) key[47:0] last to enable |
| 2824 | * TKIP now that all other registers are set with correct |
| 2825 | * values. |
| 2826 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2827 | REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0); |
| 2828 | REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1); |
| 2829 | } else { |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2830 | /* Write key[47:0] */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2831 | REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0); |
| 2832 | REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2833 | |
| 2834 | /* Write key[95:48] */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2835 | REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2); |
| 2836 | REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2837 | |
| 2838 | /* Write key[127:96] and key type */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2839 | REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4); |
| 2840 | REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType); |
| 2841 | |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2842 | /* Write MAC address for the entry */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2843 | (void) ath9k_hw_keysetmac(ah, entry, mac); |
| 2844 | } |
| 2845 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2846 | return true; |
| 2847 | } |
| 2848 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2849 | bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2850 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2851 | if (entry < ah->caps.keycache_size) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2852 | u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry)); |
| 2853 | if (val & AR_KEYTABLE_VALID) |
| 2854 | return true; |
| 2855 | } |
| 2856 | return false; |
| 2857 | } |
| 2858 | |
| 2859 | /******************************/ |
| 2860 | /* Power Management (Chipset) */ |
| 2861 | /******************************/ |
| 2862 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2863 | static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2864 | { |
| 2865 | REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV); |
| 2866 | if (setChip) { |
| 2867 | REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, |
| 2868 | AR_RTC_FORCE_WAKE_EN); |
| 2869 | if (!AR_SREV_9100(ah)) |
| 2870 | REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF); |
| 2871 | |
Gabor Juhos | d03a66c | 2009-01-14 20:17:09 +0100 | [diff] [blame] | 2872 | REG_CLR_BIT(ah, (AR_RTC_RESET), |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2873 | AR_RTC_RESET_EN); |
| 2874 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2875 | } |
| 2876 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2877 | 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] | 2878 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2879 | REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV); |
| 2880 | if (setChip) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2881 | struct ath9k_hw_capabilities *pCap = &ah->caps; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2882 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2883 | if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) { |
| 2884 | REG_WRITE(ah, AR_RTC_FORCE_WAKE, |
| 2885 | AR_RTC_FORCE_WAKE_ON_INT); |
| 2886 | } else { |
| 2887 | REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, |
| 2888 | AR_RTC_FORCE_WAKE_EN); |
| 2889 | } |
| 2890 | } |
| 2891 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2892 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2893 | static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2894 | { |
| 2895 | u32 val; |
| 2896 | int i; |
| 2897 | |
| 2898 | if (setChip) { |
| 2899 | if ((REG_READ(ah, AR_RTC_STATUS) & |
| 2900 | AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) { |
| 2901 | if (ath9k_hw_set_reset_reg(ah, |
| 2902 | ATH9K_RESET_POWER_ON) != true) { |
| 2903 | return false; |
| 2904 | } |
| 2905 | } |
| 2906 | if (AR_SREV_9100(ah)) |
| 2907 | REG_SET_BIT(ah, AR_RTC_RESET, |
| 2908 | AR_RTC_RESET_EN); |
| 2909 | |
| 2910 | REG_SET_BIT(ah, AR_RTC_FORCE_WAKE, |
| 2911 | AR_RTC_FORCE_WAKE_EN); |
| 2912 | udelay(50); |
| 2913 | |
| 2914 | for (i = POWER_UP_TIME / 50; i > 0; i--) { |
| 2915 | val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M; |
| 2916 | if (val == AR_RTC_STATUS_ON) |
| 2917 | break; |
| 2918 | udelay(50); |
| 2919 | REG_SET_BIT(ah, AR_RTC_FORCE_WAKE, |
| 2920 | AR_RTC_FORCE_WAKE_EN); |
| 2921 | } |
| 2922 | if (i == 0) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 2923 | DPRINTF(ah, ATH_DBG_FATAL, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 2924 | "Failed to wakeup in %uus\n", POWER_UP_TIME / 20); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2925 | return false; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2926 | } |
| 2927 | } |
| 2928 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2929 | REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV); |
| 2930 | |
| 2931 | return true; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2932 | } |
| 2933 | |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 2934 | bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2935 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2936 | int status = true, setChip = true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2937 | static const char *modes[] = { |
| 2938 | "AWAKE", |
| 2939 | "FULL-SLEEP", |
| 2940 | "NETWORK SLEEP", |
| 2941 | "UNDEFINED" |
| 2942 | }; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2943 | |
Gabor Juhos | cbdec97 | 2009-07-24 17:27:22 +0200 | [diff] [blame] | 2944 | if (ah->power_mode == mode) |
| 2945 | return status; |
| 2946 | |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 2947 | DPRINTF(ah, ATH_DBG_RESET, "%s -> %s\n", |
Sujith | d8baa93 | 2009-03-30 15:28:25 +0530 | [diff] [blame] | 2948 | modes[ah->power_mode], modes[mode]); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2949 | |
| 2950 | switch (mode) { |
| 2951 | case ATH9K_PM_AWAKE: |
| 2952 | status = ath9k_hw_set_power_awake(ah, setChip); |
| 2953 | break; |
| 2954 | case ATH9K_PM_FULL_SLEEP: |
| 2955 | ath9k_set_power_sleep(ah, setChip); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2956 | ah->chip_fullsleep = true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2957 | break; |
| 2958 | case ATH9K_PM_NETWORK_SLEEP: |
| 2959 | ath9k_set_power_network_sleep(ah, setChip); |
| 2960 | break; |
| 2961 | default: |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 2962 | DPRINTF(ah, ATH_DBG_FATAL, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 2963 | "Unknown power mode %u\n", mode); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2964 | return false; |
| 2965 | } |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2966 | ah->power_mode = mode; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2967 | |
| 2968 | return status; |
| 2969 | } |
| 2970 | |
Luis R. Rodriguez | 24c1a28 | 2009-02-10 15:35:22 -0800 | [diff] [blame] | 2971 | /* |
| 2972 | * Helper for ASPM support. |
| 2973 | * |
| 2974 | * Disable PLL when in L0s as well as receiver clock when in L1. |
| 2975 | * This power saving option must be enabled through the SerDes. |
| 2976 | * |
| 2977 | * Programming the SerDes must go through the same 288 bit serial shift |
| 2978 | * register as the other analog registers. Hence the 9 writes. |
| 2979 | */ |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 2980 | void ath9k_hw_configpcipowersave(struct ath_hw *ah, int restore, int power_off) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2981 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2982 | u8 i; |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 2983 | u32 val; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2984 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2985 | if (ah->is_pciexpress != true) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2986 | return; |
| 2987 | |
Luis R. Rodriguez | 24c1a28 | 2009-02-10 15:35:22 -0800 | [diff] [blame] | 2988 | /* Do not touch SerDes registers */ |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2989 | if (ah->config.pcie_powersave_enable == 2) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2990 | return; |
| 2991 | |
Luis R. Rodriguez | 24c1a28 | 2009-02-10 15:35:22 -0800 | [diff] [blame] | 2992 | /* Nothing to do on restore for 11N */ |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 2993 | if (!restore) { |
| 2994 | if (AR_SREV_9280_20_OR_LATER(ah)) { |
| 2995 | /* |
| 2996 | * AR9280 2.0 or later chips use SerDes values from the |
| 2997 | * initvals.h initialized depending on chipset during |
| 2998 | * ath9k_hw_init() |
| 2999 | */ |
| 3000 | for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) { |
| 3001 | REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0), |
| 3002 | INI_RA(&ah->iniPcieSerdes, i, 1)); |
| 3003 | } |
| 3004 | } else if (AR_SREV_9280(ah) && |
| 3005 | (ah->hw_version.macRev == AR_SREV_REVISION_9280_10)) { |
| 3006 | REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00); |
| 3007 | REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3008 | |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 3009 | /* RX shut off when elecidle is asserted */ |
| 3010 | REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019); |
| 3011 | REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820); |
| 3012 | REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560); |
| 3013 | |
| 3014 | /* Shut off CLKREQ active in L1 */ |
| 3015 | if (ah->config.pcie_clock_req) |
| 3016 | REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc); |
| 3017 | else |
| 3018 | REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd); |
| 3019 | |
| 3020 | REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40); |
| 3021 | REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554); |
| 3022 | REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007); |
| 3023 | |
| 3024 | /* Load the new settings */ |
| 3025 | REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000); |
| 3026 | |
| 3027 | } else { |
| 3028 | REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00); |
| 3029 | REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924); |
| 3030 | |
| 3031 | /* RX shut off when elecidle is asserted */ |
| 3032 | REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039); |
| 3033 | REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824); |
| 3034 | REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579); |
| 3035 | |
| 3036 | /* |
| 3037 | * Ignore ah->ah_config.pcie_clock_req setting for |
| 3038 | * pre-AR9280 11n |
| 3039 | */ |
| 3040 | REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff); |
| 3041 | |
| 3042 | REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40); |
| 3043 | REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554); |
| 3044 | REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007); |
| 3045 | |
| 3046 | /* Load the new settings */ |
| 3047 | REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3048 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3049 | |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 3050 | udelay(1000); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3051 | |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 3052 | /* set bit 19 to allow forcing of pcie core into L1 state */ |
| 3053 | REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3054 | |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 3055 | /* Several PCIe massages to ensure proper behaviour */ |
| 3056 | if (ah->config.pcie_waen) { |
| 3057 | val = ah->config.pcie_waen; |
| 3058 | if (!power_off) |
| 3059 | val &= (~AR_WA_D3_L1_DISABLE); |
| 3060 | } else { |
| 3061 | if (AR_SREV_9285(ah) || AR_SREV_9271(ah) || |
| 3062 | AR_SREV_9287(ah)) { |
| 3063 | val = AR9285_WA_DEFAULT; |
| 3064 | if (!power_off) |
| 3065 | val &= (~AR_WA_D3_L1_DISABLE); |
| 3066 | } else if (AR_SREV_9280(ah)) { |
| 3067 | /* |
| 3068 | * On AR9280 chips bit 22 of 0x4004 needs to be |
| 3069 | * set otherwise card may disappear. |
| 3070 | */ |
| 3071 | val = AR9280_WA_DEFAULT; |
| 3072 | if (!power_off) |
| 3073 | val &= (~AR_WA_D3_L1_DISABLE); |
| 3074 | } else |
| 3075 | val = AR_WA_DEFAULT; |
| 3076 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3077 | |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 3078 | REG_WRITE(ah, AR_WA, val); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3079 | } |
| 3080 | |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 3081 | if (power_off) { |
Luis R. Rodriguez | 24c1a28 | 2009-02-10 15:35:22 -0800 | [diff] [blame] | 3082 | /* |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 3083 | * Set PCIe workaround bits |
| 3084 | * bit 14 in WA register (disable L1) should only |
| 3085 | * be set when device enters D3 and be cleared |
| 3086 | * when device comes back to D0. |
Luis R. Rodriguez | 24c1a28 | 2009-02-10 15:35:22 -0800 | [diff] [blame] | 3087 | */ |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 3088 | if (ah->config.pcie_waen) { |
| 3089 | if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE) |
| 3090 | REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE); |
| 3091 | } else { |
| 3092 | if (((AR_SREV_9285(ah) || AR_SREV_9271(ah) || |
| 3093 | AR_SREV_9287(ah)) && |
| 3094 | (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)) || |
| 3095 | (AR_SREV_9280(ah) && |
| 3096 | (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE))) { |
| 3097 | REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE); |
| 3098 | } |
| 3099 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3100 | } |
| 3101 | } |
| 3102 | |
| 3103 | /**********************/ |
| 3104 | /* Interrupt Handling */ |
| 3105 | /**********************/ |
| 3106 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3107 | bool ath9k_hw_intrpend(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3108 | { |
| 3109 | u32 host_isr; |
| 3110 | |
| 3111 | if (AR_SREV_9100(ah)) |
| 3112 | return true; |
| 3113 | |
| 3114 | host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE); |
| 3115 | if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS)) |
| 3116 | return true; |
| 3117 | |
| 3118 | host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE); |
| 3119 | if ((host_isr & AR_INTR_SYNC_DEFAULT) |
| 3120 | && (host_isr != AR_INTR_SPURIOUS)) |
| 3121 | return true; |
| 3122 | |
| 3123 | return false; |
| 3124 | } |
| 3125 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3126 | 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] | 3127 | { |
| 3128 | u32 isr = 0; |
| 3129 | u32 mask2 = 0; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3130 | struct ath9k_hw_capabilities *pCap = &ah->caps; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3131 | u32 sync_cause = 0; |
| 3132 | bool fatal_int = false; |
| 3133 | |
| 3134 | if (!AR_SREV_9100(ah)) { |
| 3135 | if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) { |
| 3136 | if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M) |
| 3137 | == AR_RTC_STATUS_ON) { |
| 3138 | isr = REG_READ(ah, AR_ISR); |
| 3139 | } |
| 3140 | } |
| 3141 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3142 | sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) & |
| 3143 | AR_INTR_SYNC_DEFAULT; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3144 | |
| 3145 | *masked = 0; |
| 3146 | |
| 3147 | if (!isr && !sync_cause) |
| 3148 | return false; |
| 3149 | } else { |
| 3150 | *masked = 0; |
| 3151 | isr = REG_READ(ah, AR_ISR); |
| 3152 | } |
| 3153 | |
| 3154 | if (isr) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3155 | if (isr & AR_ISR_BCNMISC) { |
| 3156 | u32 isr2; |
| 3157 | isr2 = REG_READ(ah, AR_ISR_S2); |
| 3158 | if (isr2 & AR_ISR_S2_TIM) |
| 3159 | mask2 |= ATH9K_INT_TIM; |
| 3160 | if (isr2 & AR_ISR_S2_DTIM) |
| 3161 | mask2 |= ATH9K_INT_DTIM; |
| 3162 | if (isr2 & AR_ISR_S2_DTIMSYNC) |
| 3163 | mask2 |= ATH9K_INT_DTIMSYNC; |
| 3164 | if (isr2 & (AR_ISR_S2_CABEND)) |
| 3165 | mask2 |= ATH9K_INT_CABEND; |
| 3166 | if (isr2 & AR_ISR_S2_GTT) |
| 3167 | mask2 |= ATH9K_INT_GTT; |
| 3168 | if (isr2 & AR_ISR_S2_CST) |
| 3169 | mask2 |= ATH9K_INT_CST; |
Sujith | 4af9cf4 | 2009-02-12 10:06:47 +0530 | [diff] [blame] | 3170 | if (isr2 & AR_ISR_S2_TSFOOR) |
| 3171 | mask2 |= ATH9K_INT_TSFOOR; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3172 | } |
| 3173 | |
| 3174 | isr = REG_READ(ah, AR_ISR_RAC); |
| 3175 | if (isr == 0xffffffff) { |
| 3176 | *masked = 0; |
| 3177 | return false; |
| 3178 | } |
| 3179 | |
| 3180 | *masked = isr & ATH9K_INT_COMMON; |
| 3181 | |
Sujith | 0ef1f16 | 2009-03-30 15:28:35 +0530 | [diff] [blame] | 3182 | if (ah->config.intr_mitigation) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3183 | if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM)) |
| 3184 | *masked |= ATH9K_INT_RX; |
| 3185 | } |
| 3186 | |
| 3187 | if (isr & (AR_ISR_RXOK | AR_ISR_RXERR)) |
| 3188 | *masked |= ATH9K_INT_RX; |
| 3189 | if (isr & |
| 3190 | (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR | |
| 3191 | AR_ISR_TXEOL)) { |
| 3192 | u32 s0_s, s1_s; |
| 3193 | |
| 3194 | *masked |= ATH9K_INT_TX; |
| 3195 | |
| 3196 | s0_s = REG_READ(ah, AR_ISR_S0_S); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3197 | ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK); |
| 3198 | ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3199 | |
| 3200 | s1_s = REG_READ(ah, AR_ISR_S1_S); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3201 | ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR); |
| 3202 | ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3203 | } |
| 3204 | |
| 3205 | if (isr & AR_ISR_RXORN) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 3206 | DPRINTF(ah, ATH_DBG_INTERRUPT, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 3207 | "receive FIFO overrun interrupt\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3208 | } |
| 3209 | |
| 3210 | if (!AR_SREV_9100(ah)) { |
Sujith | 60b67f5 | 2008-08-07 10:52:38 +0530 | [diff] [blame] | 3211 | if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3212 | u32 isr5 = REG_READ(ah, AR_ISR_S5_S); |
| 3213 | if (isr5 & AR_ISR_S5_TIM_TIMER) |
| 3214 | *masked |= ATH9K_INT_TIM_TIMER; |
| 3215 | } |
| 3216 | } |
| 3217 | |
| 3218 | *masked |= mask2; |
| 3219 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3220 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3221 | if (AR_SREV_9100(ah)) |
| 3222 | return true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3223 | |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3224 | if (isr & AR_ISR_GENTMR) { |
| 3225 | u32 s5_s; |
| 3226 | |
| 3227 | s5_s = REG_READ(ah, AR_ISR_S5_S); |
| 3228 | if (isr & AR_ISR_GENTMR) { |
| 3229 | ah->intr_gen_timer_trigger = |
| 3230 | MS(s5_s, AR_ISR_S5_GENTIMER_TRIG); |
| 3231 | |
| 3232 | ah->intr_gen_timer_thresh = |
| 3233 | MS(s5_s, AR_ISR_S5_GENTIMER_THRESH); |
| 3234 | |
| 3235 | if (ah->intr_gen_timer_trigger) |
| 3236 | *masked |= ATH9K_INT_GENTIMER; |
| 3237 | |
| 3238 | } |
| 3239 | } |
| 3240 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3241 | if (sync_cause) { |
| 3242 | fatal_int = |
| 3243 | (sync_cause & |
| 3244 | (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR)) |
| 3245 | ? true : false; |
| 3246 | |
| 3247 | if (fatal_int) { |
| 3248 | if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 3249 | DPRINTF(ah, ATH_DBG_ANY, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 3250 | "received PCI FATAL interrupt\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3251 | } |
| 3252 | if (sync_cause & AR_INTR_SYNC_HOST1_PERR) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 3253 | DPRINTF(ah, ATH_DBG_ANY, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 3254 | "received PCI PERR interrupt\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3255 | } |
Steven Luo | a89bff9 | 2009-04-12 02:57:54 -0700 | [diff] [blame] | 3256 | *masked |= ATH9K_INT_FATAL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3257 | } |
| 3258 | if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 3259 | DPRINTF(ah, ATH_DBG_INTERRUPT, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 3260 | "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3261 | REG_WRITE(ah, AR_RC, AR_RC_HOSTIF); |
| 3262 | REG_WRITE(ah, AR_RC, 0); |
| 3263 | *masked |= ATH9K_INT_FATAL; |
| 3264 | } |
| 3265 | if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 3266 | DPRINTF(ah, ATH_DBG_INTERRUPT, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 3267 | "AR_INTR_SYNC_LOCAL_TIMEOUT\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3268 | } |
| 3269 | |
| 3270 | REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause); |
| 3271 | (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR); |
| 3272 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3273 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3274 | return true; |
| 3275 | } |
| 3276 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3277 | 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] | 3278 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3279 | u32 omask = ah->mask_reg; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3280 | u32 mask, mask2; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3281 | struct ath9k_hw_capabilities *pCap = &ah->caps; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3282 | |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 3283 | DPRINTF(ah, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3284 | |
| 3285 | if (omask & ATH9K_INT_GLOBAL) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 3286 | DPRINTF(ah, ATH_DBG_INTERRUPT, "disable IER\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3287 | REG_WRITE(ah, AR_IER, AR_IER_DISABLE); |
| 3288 | (void) REG_READ(ah, AR_IER); |
| 3289 | if (!AR_SREV_9100(ah)) { |
| 3290 | REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0); |
| 3291 | (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE); |
| 3292 | |
| 3293 | REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0); |
| 3294 | (void) REG_READ(ah, AR_INTR_SYNC_ENABLE); |
| 3295 | } |
| 3296 | } |
| 3297 | |
| 3298 | mask = ints & ATH9K_INT_COMMON; |
| 3299 | mask2 = 0; |
| 3300 | |
| 3301 | if (ints & ATH9K_INT_TX) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3302 | if (ah->txok_interrupt_mask) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3303 | mask |= AR_IMR_TXOK; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3304 | if (ah->txdesc_interrupt_mask) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3305 | mask |= AR_IMR_TXDESC; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3306 | if (ah->txerr_interrupt_mask) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3307 | mask |= AR_IMR_TXERR; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3308 | if (ah->txeol_interrupt_mask) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3309 | mask |= AR_IMR_TXEOL; |
| 3310 | } |
| 3311 | if (ints & ATH9K_INT_RX) { |
| 3312 | mask |= AR_IMR_RXERR; |
Sujith | 0ef1f16 | 2009-03-30 15:28:35 +0530 | [diff] [blame] | 3313 | if (ah->config.intr_mitigation) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3314 | mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM; |
| 3315 | else |
| 3316 | mask |= AR_IMR_RXOK | AR_IMR_RXDESC; |
Sujith | 60b67f5 | 2008-08-07 10:52:38 +0530 | [diff] [blame] | 3317 | if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3318 | mask |= AR_IMR_GENTMR; |
| 3319 | } |
| 3320 | |
| 3321 | if (ints & (ATH9K_INT_BMISC)) { |
| 3322 | mask |= AR_IMR_BCNMISC; |
| 3323 | if (ints & ATH9K_INT_TIM) |
| 3324 | mask2 |= AR_IMR_S2_TIM; |
| 3325 | if (ints & ATH9K_INT_DTIM) |
| 3326 | mask2 |= AR_IMR_S2_DTIM; |
| 3327 | if (ints & ATH9K_INT_DTIMSYNC) |
| 3328 | mask2 |= AR_IMR_S2_DTIMSYNC; |
| 3329 | if (ints & ATH9K_INT_CABEND) |
Sujith | 4af9cf4 | 2009-02-12 10:06:47 +0530 | [diff] [blame] | 3330 | mask2 |= AR_IMR_S2_CABEND; |
| 3331 | if (ints & ATH9K_INT_TSFOOR) |
| 3332 | mask2 |= AR_IMR_S2_TSFOOR; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3333 | } |
| 3334 | |
| 3335 | if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) { |
| 3336 | mask |= AR_IMR_BCNMISC; |
| 3337 | if (ints & ATH9K_INT_GTT) |
| 3338 | mask2 |= AR_IMR_S2_GTT; |
| 3339 | if (ints & ATH9K_INT_CST) |
| 3340 | mask2 |= AR_IMR_S2_CST; |
| 3341 | } |
| 3342 | |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 3343 | DPRINTF(ah, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3344 | REG_WRITE(ah, AR_IMR, mask); |
| 3345 | mask = REG_READ(ah, AR_IMR_S2) & ~(AR_IMR_S2_TIM | |
| 3346 | AR_IMR_S2_DTIM | |
| 3347 | AR_IMR_S2_DTIMSYNC | |
| 3348 | AR_IMR_S2_CABEND | |
| 3349 | AR_IMR_S2_CABTO | |
| 3350 | AR_IMR_S2_TSFOOR | |
| 3351 | AR_IMR_S2_GTT | AR_IMR_S2_CST); |
| 3352 | REG_WRITE(ah, AR_IMR_S2, mask | mask2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3353 | ah->mask_reg = ints; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3354 | |
Sujith | 60b67f5 | 2008-08-07 10:52:38 +0530 | [diff] [blame] | 3355 | if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3356 | if (ints & ATH9K_INT_TIM_TIMER) |
| 3357 | REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER); |
| 3358 | else |
| 3359 | REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER); |
| 3360 | } |
| 3361 | |
| 3362 | if (ints & ATH9K_INT_GLOBAL) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 3363 | DPRINTF(ah, ATH_DBG_INTERRUPT, "enable IER\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3364 | REG_WRITE(ah, AR_IER, AR_IER_ENABLE); |
| 3365 | if (!AR_SREV_9100(ah)) { |
| 3366 | REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, |
| 3367 | AR_INTR_MAC_IRQ); |
| 3368 | REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ); |
| 3369 | |
| 3370 | |
| 3371 | REG_WRITE(ah, AR_INTR_SYNC_ENABLE, |
| 3372 | AR_INTR_SYNC_DEFAULT); |
| 3373 | REG_WRITE(ah, AR_INTR_SYNC_MASK, |
| 3374 | AR_INTR_SYNC_DEFAULT); |
| 3375 | } |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 3376 | DPRINTF(ah, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n", |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3377 | REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER)); |
| 3378 | } |
| 3379 | |
| 3380 | return omask; |
| 3381 | } |
| 3382 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3383 | /*******************/ |
| 3384 | /* Beacon Handling */ |
| 3385 | /*******************/ |
| 3386 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3387 | 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] | 3388 | { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3389 | int flags = 0; |
| 3390 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3391 | ah->beacon_interval = beacon_period; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3392 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3393 | switch (ah->opmode) { |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 3394 | case NL80211_IFTYPE_STATION: |
| 3395 | case NL80211_IFTYPE_MONITOR: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3396 | REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon)); |
| 3397 | REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff); |
| 3398 | REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff); |
| 3399 | flags |= AR_TBTT_TIMER_EN; |
| 3400 | break; |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 3401 | case NL80211_IFTYPE_ADHOC: |
Pat Erley | 9cb5412 | 2009-03-20 22:59:59 -0400 | [diff] [blame] | 3402 | case NL80211_IFTYPE_MESH_POINT: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3403 | REG_SET_BIT(ah, AR_TXCFG, |
| 3404 | AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY); |
| 3405 | REG_WRITE(ah, AR_NEXT_NDP_TIMER, |
| 3406 | TU_TO_USEC(next_beacon + |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3407 | (ah->atim_window ? ah-> |
| 3408 | atim_window : 1))); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3409 | flags |= AR_NDP_TIMER_EN; |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 3410 | case NL80211_IFTYPE_AP: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3411 | REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon)); |
| 3412 | REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, |
| 3413 | TU_TO_USEC(next_beacon - |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3414 | ah->config. |
Sujith | 60b67f5 | 2008-08-07 10:52:38 +0530 | [diff] [blame] | 3415 | dma_beacon_response_time)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3416 | REG_WRITE(ah, AR_NEXT_SWBA, |
| 3417 | TU_TO_USEC(next_beacon - |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3418 | ah->config. |
Sujith | 60b67f5 | 2008-08-07 10:52:38 +0530 | [diff] [blame] | 3419 | sw_beacon_response_time)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3420 | flags |= |
| 3421 | AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN; |
| 3422 | break; |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 3423 | default: |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 3424 | DPRINTF(ah, ATH_DBG_BEACON, |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 3425 | "%s: unsupported opmode: %d\n", |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3426 | __func__, ah->opmode); |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 3427 | return; |
| 3428 | break; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3429 | } |
| 3430 | |
| 3431 | REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period)); |
| 3432 | REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period)); |
| 3433 | REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period)); |
| 3434 | REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period)); |
| 3435 | |
| 3436 | beacon_period &= ~ATH9K_BEACON_ENA; |
| 3437 | if (beacon_period & ATH9K_BEACON_RESET_TSF) { |
| 3438 | beacon_period &= ~ATH9K_BEACON_RESET_TSF; |
| 3439 | ath9k_hw_reset_tsf(ah); |
| 3440 | } |
| 3441 | |
| 3442 | REG_SET_BIT(ah, AR_TIMER_MODE, flags); |
| 3443 | } |
| 3444 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3445 | void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3446 | const struct ath9k_beacon_state *bs) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3447 | { |
| 3448 | u32 nextTbtt, beaconintval, dtimperiod, beacontimeout; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3449 | struct ath9k_hw_capabilities *pCap = &ah->caps; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3450 | |
| 3451 | REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt)); |
| 3452 | |
| 3453 | REG_WRITE(ah, AR_BEACON_PERIOD, |
| 3454 | TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD)); |
| 3455 | REG_WRITE(ah, AR_DMA_BEACON_PERIOD, |
| 3456 | TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD)); |
| 3457 | |
| 3458 | REG_RMW_FIELD(ah, AR_RSSI_THR, |
| 3459 | AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold); |
| 3460 | |
| 3461 | beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD; |
| 3462 | |
| 3463 | if (bs->bs_sleepduration > beaconintval) |
| 3464 | beaconintval = bs->bs_sleepduration; |
| 3465 | |
| 3466 | dtimperiod = bs->bs_dtimperiod; |
| 3467 | if (bs->bs_sleepduration > dtimperiod) |
| 3468 | dtimperiod = bs->bs_sleepduration; |
| 3469 | |
| 3470 | if (beaconintval == dtimperiod) |
| 3471 | nextTbtt = bs->bs_nextdtim; |
| 3472 | else |
| 3473 | nextTbtt = bs->bs_nexttbtt; |
| 3474 | |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 3475 | DPRINTF(ah, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim); |
| 3476 | DPRINTF(ah, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt); |
| 3477 | DPRINTF(ah, ATH_DBG_BEACON, "beacon period %d\n", beaconintval); |
| 3478 | DPRINTF(ah, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3479 | |
| 3480 | REG_WRITE(ah, AR_NEXT_DTIM, |
| 3481 | TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP)); |
| 3482 | REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP)); |
| 3483 | |
| 3484 | REG_WRITE(ah, AR_SLEEP1, |
| 3485 | SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT) |
| 3486 | | AR_SLEEP1_ASSUME_DTIM); |
| 3487 | |
Sujith | 60b67f5 | 2008-08-07 10:52:38 +0530 | [diff] [blame] | 3488 | if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3489 | beacontimeout = (BEACON_TIMEOUT_VAL << 3); |
| 3490 | else |
| 3491 | beacontimeout = MIN_BEACON_TIMEOUT_VAL; |
| 3492 | |
| 3493 | REG_WRITE(ah, AR_SLEEP2, |
| 3494 | SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT)); |
| 3495 | |
| 3496 | REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval)); |
| 3497 | REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod)); |
| 3498 | |
| 3499 | REG_SET_BIT(ah, AR_TIMER_MODE, |
| 3500 | AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN | |
| 3501 | AR_DTIM_TIMER_EN); |
| 3502 | |
Sujith | 4af9cf4 | 2009-02-12 10:06:47 +0530 | [diff] [blame] | 3503 | /* TSF Out of Range Threshold */ |
| 3504 | REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3505 | } |
| 3506 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3507 | /*******************/ |
| 3508 | /* HW Capabilities */ |
| 3509 | /*******************/ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3510 | |
Sujith | eef7a57 | 2009-03-30 15:28:28 +0530 | [diff] [blame] | 3511 | void ath9k_hw_fill_cap_info(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3512 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3513 | struct ath9k_hw_capabilities *pCap = &ah->caps; |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 3514 | struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah); |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 3515 | struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw; |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 3516 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3517 | u16 capField = 0, eeval; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3518 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 3519 | eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0); |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 3520 | regulatory->current_rd = eeval; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3521 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 3522 | eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1); |
Sujith | fec0de1 | 2009-02-12 10:06:43 +0530 | [diff] [blame] | 3523 | if (AR_SREV_9285_10_OR_LATER(ah)) |
| 3524 | eeval |= AR9285_RDEXT_DEFAULT; |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 3525 | regulatory->current_rd_ext = eeval; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3526 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 3527 | capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3528 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3529 | if (ah->opmode != NL80211_IFTYPE_AP && |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 3530 | ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) { |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 3531 | if (regulatory->current_rd == 0x64 || |
| 3532 | regulatory->current_rd == 0x65) |
| 3533 | regulatory->current_rd += 5; |
| 3534 | else if (regulatory->current_rd == 0x41) |
| 3535 | regulatory->current_rd = 0x43; |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 3536 | DPRINTF(ah, ATH_DBG_REGULATORY, |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 3537 | "regdomain mapped to 0x%x\n", regulatory->current_rd); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3538 | } |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 3539 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 3540 | eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3541 | bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3542 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3543 | if (eeval & AR5416_OPFLAGS_11A) { |
| 3544 | set_bit(ATH9K_MODE_11A, pCap->wireless_modes); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3545 | if (ah->config.ht_enable) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3546 | if (!(eeval & AR5416_OPFLAGS_N_5G_HT20)) |
| 3547 | set_bit(ATH9K_MODE_11NA_HT20, |
| 3548 | pCap->wireless_modes); |
| 3549 | if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) { |
| 3550 | set_bit(ATH9K_MODE_11NA_HT40PLUS, |
| 3551 | pCap->wireless_modes); |
| 3552 | set_bit(ATH9K_MODE_11NA_HT40MINUS, |
| 3553 | pCap->wireless_modes); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3554 | } |
| 3555 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3556 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3557 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3558 | if (eeval & AR5416_OPFLAGS_11G) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3559 | set_bit(ATH9K_MODE_11G, pCap->wireless_modes); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3560 | if (ah->config.ht_enable) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3561 | if (!(eeval & AR5416_OPFLAGS_N_2G_HT20)) |
| 3562 | set_bit(ATH9K_MODE_11NG_HT20, |
| 3563 | pCap->wireless_modes); |
| 3564 | if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) { |
| 3565 | set_bit(ATH9K_MODE_11NG_HT40PLUS, |
| 3566 | pCap->wireless_modes); |
| 3567 | set_bit(ATH9K_MODE_11NG_HT40MINUS, |
| 3568 | pCap->wireless_modes); |
| 3569 | } |
| 3570 | } |
Luis R. Rodriguez | 6f25542 | 2008-10-03 15:45:27 -0700 | [diff] [blame] | 3571 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3572 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 3573 | 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] | 3574 | /* |
| 3575 | * For AR9271 we will temporarilly uses the rx chainmax as read from |
| 3576 | * the EEPROM. |
| 3577 | */ |
Sujith | 8147f5d | 2009-02-20 15:13:23 +0530 | [diff] [blame] | 3578 | if ((ah->hw_version.devid == AR5416_DEVID_PCI) && |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 3579 | !(eeval & AR5416_OPFLAGS_11A) && |
| 3580 | !(AR_SREV_9271(ah))) |
| 3581 | /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */ |
Sujith | 8147f5d | 2009-02-20 15:13:23 +0530 | [diff] [blame] | 3582 | pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7; |
| 3583 | else |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 3584 | /* Use rx_chainmask from EEPROM. */ |
Sujith | 8147f5d | 2009-02-20 15:13:23 +0530 | [diff] [blame] | 3585 | pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3586 | |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 3587 | if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0))) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3588 | ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3589 | |
| 3590 | pCap->low_2ghz_chan = 2312; |
| 3591 | pCap->high_2ghz_chan = 2732; |
| 3592 | |
| 3593 | pCap->low_5ghz_chan = 4920; |
| 3594 | pCap->high_5ghz_chan = 6100; |
| 3595 | |
| 3596 | pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP; |
| 3597 | pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP; |
| 3598 | pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM; |
| 3599 | |
| 3600 | pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP; |
| 3601 | pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP; |
| 3602 | pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM; |
| 3603 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3604 | if (ah->config.ht_enable) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3605 | pCap->hw_caps |= ATH9K_HW_CAP_HT; |
| 3606 | else |
| 3607 | pCap->hw_caps &= ~ATH9K_HW_CAP_HT; |
| 3608 | |
| 3609 | pCap->hw_caps |= ATH9K_HW_CAP_GTT; |
| 3610 | pCap->hw_caps |= ATH9K_HW_CAP_VEOL; |
| 3611 | pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK; |
| 3612 | pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH; |
| 3613 | |
| 3614 | if (capField & AR_EEPROM_EEPCAP_MAXQCU) |
| 3615 | pCap->total_queues = |
| 3616 | MS(capField, AR_EEPROM_EEPCAP_MAXQCU); |
| 3617 | else |
| 3618 | pCap->total_queues = ATH9K_NUM_TX_QUEUES; |
| 3619 | |
| 3620 | if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES) |
| 3621 | pCap->keycache_size = |
| 3622 | 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES); |
| 3623 | else |
| 3624 | pCap->keycache_size = AR_KEYTABLE_SIZE; |
| 3625 | |
| 3626 | pCap->hw_caps |= ATH9K_HW_CAP_FASTCC; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3627 | pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD; |
| 3628 | |
Senthil Balasubramanian | cb33c41 | 2008-12-24 18:03:58 +0530 | [diff] [blame] | 3629 | if (AR_SREV_9285_10_OR_LATER(ah)) |
| 3630 | pCap->num_gpio_pins = AR9285_NUM_GPIO; |
| 3631 | else if (AR_SREV_9280_10_OR_LATER(ah)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3632 | pCap->num_gpio_pins = AR928X_NUM_GPIO; |
| 3633 | else |
| 3634 | pCap->num_gpio_pins = AR_NUM_GPIO; |
| 3635 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3636 | if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) { |
| 3637 | pCap->hw_caps |= ATH9K_HW_CAP_CST; |
| 3638 | pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX; |
| 3639 | } else { |
| 3640 | pCap->rts_aggr_limit = (8 * 1024); |
| 3641 | } |
| 3642 | |
| 3643 | pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM; |
| 3644 | |
Senthil Balasubramanian | e97275c | 2008-11-13 18:00:02 +0530 | [diff] [blame] | 3645 | #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3646 | ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT); |
| 3647 | if (ah->rfsilent & EEP_RFSILENT_ENABLED) { |
| 3648 | ah->rfkill_gpio = |
| 3649 | MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL); |
| 3650 | ah->rfkill_polarity = |
| 3651 | MS(ah->rfsilent, EEP_RFSILENT_POLARITY); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3652 | |
| 3653 | pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT; |
| 3654 | } |
| 3655 | #endif |
| 3656 | |
Vivek Natarajan | a3ca95fb | 2009-09-17 09:29:07 +0530 | [diff] [blame] | 3657 | pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3658 | |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 3659 | if (AR_SREV_9280(ah) || AR_SREV_9285(ah)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3660 | pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS; |
| 3661 | else |
| 3662 | pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS; |
| 3663 | |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 3664 | if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3665 | pCap->reg_cap = |
| 3666 | AR_EEPROM_EEREGCAP_EN_KK_NEW_11A | |
| 3667 | AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN | |
| 3668 | AR_EEPROM_EEREGCAP_EN_KK_U2 | |
| 3669 | AR_EEPROM_EEREGCAP_EN_KK_MIDBAND; |
| 3670 | } else { |
| 3671 | pCap->reg_cap = |
| 3672 | AR_EEPROM_EEREGCAP_EN_KK_NEW_11A | |
| 3673 | AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN; |
| 3674 | } |
| 3675 | |
| 3676 | pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND; |
| 3677 | |
| 3678 | pCap->num_antcfg_5ghz = |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 3679 | ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3680 | pCap->num_antcfg_2ghz = |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 3681 | ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3682 | |
Vasanthakumar Thiagarajan | fe12946 | 2009-09-09 15:25:50 +0530 | [diff] [blame] | 3683 | if (AR_SREV_9280_10_OR_LATER(ah) && |
Luis R. Rodriguez | a36cfbc | 2009-09-09 16:05:32 -0700 | [diff] [blame] | 3684 | ath9k_hw_btcoex_supported(ah)) { |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 3685 | btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO; |
| 3686 | btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO; |
Vasanthakumar Thiagarajan | 22f25d0 | 2009-08-26 21:08:47 +0530 | [diff] [blame] | 3687 | |
Vasanthakumar Thiagarajan | 8c8f9ba | 2009-09-09 15:25:52 +0530 | [diff] [blame] | 3688 | if (AR_SREV_9285(ah)) { |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 3689 | btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE; |
| 3690 | btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO; |
Vasanthakumar Thiagarajan | 8c8f9ba | 2009-09-09 15:25:52 +0530 | [diff] [blame] | 3691 | } else { |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 3692 | btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE; |
Vasanthakumar Thiagarajan | 8c8f9ba | 2009-09-09 15:25:52 +0530 | [diff] [blame] | 3693 | } |
Vasanthakumar Thiagarajan | 22f25d0 | 2009-08-26 21:08:47 +0530 | [diff] [blame] | 3694 | } else { |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 3695 | btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE; |
Vasanthakumar Thiagarajan | c97c92d | 2009-01-02 15:35:46 +0530 | [diff] [blame] | 3696 | } |
Luis R. Rodriguez | 6f25542 | 2008-10-03 15:45:27 -0700 | [diff] [blame] | 3697 | } |
| 3698 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3699 | bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3700 | u32 capability, u32 *result) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3701 | { |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 3702 | struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3703 | switch (type) { |
| 3704 | case ATH9K_CAP_CIPHER: |
| 3705 | switch (capability) { |
| 3706 | case ATH9K_CIPHER_AES_CCM: |
| 3707 | case ATH9K_CIPHER_AES_OCB: |
| 3708 | case ATH9K_CIPHER_TKIP: |
| 3709 | case ATH9K_CIPHER_WEP: |
| 3710 | case ATH9K_CIPHER_MIC: |
| 3711 | case ATH9K_CIPHER_CLR: |
| 3712 | return true; |
| 3713 | default: |
| 3714 | return false; |
| 3715 | } |
| 3716 | case ATH9K_CAP_TKIP_MIC: |
| 3717 | switch (capability) { |
| 3718 | case 0: |
| 3719 | return true; |
| 3720 | case 1: |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3721 | return (ah->sta_id1_defaults & |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3722 | AR_STA_ID1_CRPT_MIC_ENABLE) ? true : |
| 3723 | false; |
| 3724 | } |
| 3725 | case ATH9K_CAP_TKIP_SPLIT: |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3726 | return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ? |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3727 | false : true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3728 | case ATH9K_CAP_DIVERSITY: |
| 3729 | return (REG_READ(ah, AR_PHY_CCK_DETECT) & |
| 3730 | AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV) ? |
| 3731 | true : false; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3732 | case ATH9K_CAP_MCAST_KEYSRCH: |
| 3733 | switch (capability) { |
| 3734 | case 0: |
| 3735 | return true; |
| 3736 | case 1: |
| 3737 | if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) { |
| 3738 | return false; |
| 3739 | } else { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3740 | return (ah->sta_id1_defaults & |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3741 | AR_STA_ID1_MCAST_KSRCH) ? true : |
| 3742 | false; |
| 3743 | } |
| 3744 | } |
| 3745 | return false; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3746 | case ATH9K_CAP_TXPOW: |
| 3747 | switch (capability) { |
| 3748 | case 0: |
| 3749 | return 0; |
| 3750 | case 1: |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 3751 | *result = regulatory->power_limit; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3752 | return 0; |
| 3753 | case 2: |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 3754 | *result = regulatory->max_power_level; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3755 | return 0; |
| 3756 | case 3: |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 3757 | *result = regulatory->tp_scale; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3758 | return 0; |
| 3759 | } |
| 3760 | return false; |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 3761 | case ATH9K_CAP_DS: |
| 3762 | return (AR_SREV_9280_20_OR_LATER(ah) && |
| 3763 | (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1)) |
| 3764 | ? false : true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3765 | default: |
| 3766 | return false; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3767 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3768 | } |
Luis R. Rodriguez | 6f25542 | 2008-10-03 15:45:27 -0700 | [diff] [blame] | 3769 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3770 | bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3771 | u32 capability, u32 setting, int *status) |
| 3772 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3773 | u32 v; |
Luis R. Rodriguez | 6f25542 | 2008-10-03 15:45:27 -0700 | [diff] [blame] | 3774 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3775 | switch (type) { |
| 3776 | case ATH9K_CAP_TKIP_MIC: |
| 3777 | if (setting) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3778 | ah->sta_id1_defaults |= |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3779 | AR_STA_ID1_CRPT_MIC_ENABLE; |
| 3780 | else |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3781 | ah->sta_id1_defaults &= |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3782 | ~AR_STA_ID1_CRPT_MIC_ENABLE; |
| 3783 | return true; |
| 3784 | case ATH9K_CAP_DIVERSITY: |
| 3785 | v = REG_READ(ah, AR_PHY_CCK_DETECT); |
| 3786 | if (setting) |
| 3787 | v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV; |
| 3788 | else |
| 3789 | v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV; |
| 3790 | REG_WRITE(ah, AR_PHY_CCK_DETECT, v); |
| 3791 | return true; |
| 3792 | case ATH9K_CAP_MCAST_KEYSRCH: |
| 3793 | if (setting) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3794 | ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3795 | else |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3796 | ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3797 | return true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3798 | default: |
| 3799 | return false; |
| 3800 | } |
| 3801 | } |
| 3802 | |
| 3803 | /****************************/ |
| 3804 | /* GPIO / RFKILL / Antennae */ |
| 3805 | /****************************/ |
| 3806 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3807 | static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3808 | u32 gpio, u32 type) |
| 3809 | { |
| 3810 | int addr; |
| 3811 | u32 gpio_shift, tmp; |
| 3812 | |
| 3813 | if (gpio > 11) |
| 3814 | addr = AR_GPIO_OUTPUT_MUX3; |
| 3815 | else if (gpio > 5) |
| 3816 | addr = AR_GPIO_OUTPUT_MUX2; |
| 3817 | else |
| 3818 | addr = AR_GPIO_OUTPUT_MUX1; |
| 3819 | |
| 3820 | gpio_shift = (gpio % 6) * 5; |
| 3821 | |
| 3822 | if (AR_SREV_9280_20_OR_LATER(ah) |
| 3823 | || (addr != AR_GPIO_OUTPUT_MUX1)) { |
| 3824 | REG_RMW(ah, addr, (type << gpio_shift), |
| 3825 | (0x1f << gpio_shift)); |
| 3826 | } else { |
| 3827 | tmp = REG_READ(ah, addr); |
| 3828 | tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0); |
| 3829 | tmp &= ~(0x1f << gpio_shift); |
| 3830 | tmp |= (type << gpio_shift); |
| 3831 | REG_WRITE(ah, addr, tmp); |
| 3832 | } |
| 3833 | } |
| 3834 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3835 | void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3836 | { |
| 3837 | u32 gpio_shift; |
| 3838 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3839 | ASSERT(gpio < ah->caps.num_gpio_pins); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3840 | |
| 3841 | gpio_shift = gpio << 1; |
| 3842 | |
| 3843 | REG_RMW(ah, |
| 3844 | AR_GPIO_OE_OUT, |
| 3845 | (AR_GPIO_OE_OUT_DRV_NO << gpio_shift), |
| 3846 | (AR_GPIO_OE_OUT_DRV << gpio_shift)); |
| 3847 | } |
| 3848 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3849 | u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3850 | { |
Senthil Balasubramanian | cb33c41 | 2008-12-24 18:03:58 +0530 | [diff] [blame] | 3851 | #define MS_REG_READ(x, y) \ |
| 3852 | (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y))) |
| 3853 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3854 | if (gpio >= ah->caps.num_gpio_pins) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3855 | return 0xffffffff; |
| 3856 | |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 3857 | if (AR_SREV_9287_10_OR_LATER(ah)) |
| 3858 | return MS_REG_READ(AR9287, gpio) != 0; |
| 3859 | else if (AR_SREV_9285_10_OR_LATER(ah)) |
Senthil Balasubramanian | cb33c41 | 2008-12-24 18:03:58 +0530 | [diff] [blame] | 3860 | return MS_REG_READ(AR9285, gpio) != 0; |
| 3861 | else if (AR_SREV_9280_10_OR_LATER(ah)) |
| 3862 | return MS_REG_READ(AR928X, gpio) != 0; |
| 3863 | else |
| 3864 | return MS_REG_READ(AR, gpio) != 0; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3865 | } |
| 3866 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3867 | void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3868 | u32 ah_signal_type) |
| 3869 | { |
| 3870 | u32 gpio_shift; |
| 3871 | |
| 3872 | ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type); |
| 3873 | |
| 3874 | gpio_shift = 2 * gpio; |
| 3875 | |
| 3876 | REG_RMW(ah, |
| 3877 | AR_GPIO_OE_OUT, |
| 3878 | (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift), |
| 3879 | (AR_GPIO_OE_OUT_DRV << gpio_shift)); |
| 3880 | } |
| 3881 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3882 | void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3883 | { |
| 3884 | REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio), |
| 3885 | AR_GPIO_BIT(gpio)); |
| 3886 | } |
| 3887 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3888 | u32 ath9k_hw_getdefantenna(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3889 | { |
| 3890 | return REG_READ(ah, AR_DEF_ANTENNA) & 0x7; |
| 3891 | } |
| 3892 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3893 | void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3894 | { |
| 3895 | REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7)); |
| 3896 | } |
| 3897 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3898 | bool ath9k_hw_setantennaswitch(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3899 | enum ath9k_ant_setting settings, |
| 3900 | struct ath9k_channel *chan, |
| 3901 | u8 *tx_chainmask, |
| 3902 | u8 *rx_chainmask, |
| 3903 | u8 *antenna_cfgd) |
| 3904 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3905 | static u8 tx_chainmask_cfg, rx_chainmask_cfg; |
| 3906 | |
| 3907 | if (AR_SREV_9280(ah)) { |
| 3908 | if (!tx_chainmask_cfg) { |
| 3909 | |
| 3910 | tx_chainmask_cfg = *tx_chainmask; |
| 3911 | rx_chainmask_cfg = *rx_chainmask; |
| 3912 | } |
| 3913 | |
| 3914 | switch (settings) { |
| 3915 | case ATH9K_ANT_FIXED_A: |
| 3916 | *tx_chainmask = ATH9K_ANTENNA0_CHAINMASK; |
| 3917 | *rx_chainmask = ATH9K_ANTENNA0_CHAINMASK; |
| 3918 | *antenna_cfgd = true; |
| 3919 | break; |
| 3920 | case ATH9K_ANT_FIXED_B: |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3921 | if (ah->caps.tx_chainmask > |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3922 | ATH9K_ANTENNA1_CHAINMASK) { |
| 3923 | *tx_chainmask = ATH9K_ANTENNA1_CHAINMASK; |
| 3924 | } |
| 3925 | *rx_chainmask = ATH9K_ANTENNA1_CHAINMASK; |
| 3926 | *antenna_cfgd = true; |
| 3927 | break; |
| 3928 | case ATH9K_ANT_VARIABLE: |
| 3929 | *tx_chainmask = tx_chainmask_cfg; |
| 3930 | *rx_chainmask = rx_chainmask_cfg; |
| 3931 | *antenna_cfgd = true; |
| 3932 | break; |
| 3933 | default: |
| 3934 | break; |
| 3935 | } |
| 3936 | } else { |
Sujith | 1cf6873 | 2009-08-13 09:34:32 +0530 | [diff] [blame] | 3937 | ah->config.diversity_control = settings; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3938 | } |
| 3939 | |
| 3940 | return true; |
| 3941 | } |
| 3942 | |
| 3943 | /*********************/ |
| 3944 | /* General Operation */ |
| 3945 | /*********************/ |
| 3946 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3947 | u32 ath9k_hw_getrxfilter(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3948 | { |
| 3949 | u32 bits = REG_READ(ah, AR_RX_FILTER); |
| 3950 | u32 phybits = REG_READ(ah, AR_PHY_ERR); |
| 3951 | |
| 3952 | if (phybits & AR_PHY_ERR_RADAR) |
| 3953 | bits |= ATH9K_RX_FILTER_PHYRADAR; |
| 3954 | if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING)) |
| 3955 | bits |= ATH9K_RX_FILTER_PHYERR; |
| 3956 | |
| 3957 | return bits; |
| 3958 | } |
| 3959 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3960 | void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3961 | { |
| 3962 | u32 phybits; |
| 3963 | |
Sujith | 7ea310b | 2009-09-03 12:08:43 +0530 | [diff] [blame] | 3964 | REG_WRITE(ah, AR_RX_FILTER, bits); |
| 3965 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3966 | phybits = 0; |
| 3967 | if (bits & ATH9K_RX_FILTER_PHYRADAR) |
| 3968 | phybits |= AR_PHY_ERR_RADAR; |
| 3969 | if (bits & ATH9K_RX_FILTER_PHYERR) |
| 3970 | phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING; |
| 3971 | REG_WRITE(ah, AR_PHY_ERR, phybits); |
| 3972 | |
| 3973 | if (phybits) |
| 3974 | REG_WRITE(ah, AR_RXCFG, |
| 3975 | REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA); |
| 3976 | else |
| 3977 | REG_WRITE(ah, AR_RXCFG, |
| 3978 | REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA); |
| 3979 | } |
| 3980 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3981 | bool ath9k_hw_phy_disable(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3982 | { |
| 3983 | return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM); |
| 3984 | } |
| 3985 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3986 | bool ath9k_hw_disable(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3987 | { |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 3988 | if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3989 | return false; |
| 3990 | |
| 3991 | return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD); |
| 3992 | } |
| 3993 | |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 3994 | void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3995 | { |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 3996 | struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3997 | struct ath9k_channel *chan = ah->curchan; |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 3998 | struct ieee80211_channel *channel = chan->chan; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3999 | |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 4000 | regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4001 | |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 4002 | ah->eep_ops->set_txpower(ah, chan, |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 4003 | ath9k_regd_get_ctl(regulatory, chan), |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 4004 | channel->max_antenna_gain * 2, |
| 4005 | channel->max_power * 2, |
| 4006 | min((u32) MAX_RATE_POWER, |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 4007 | (u32) regulatory->power_limit)); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4008 | } |
| 4009 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 4010 | void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4011 | { |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame^] | 4012 | memcpy(ath9k_hw_common(ah)->macaddr, mac, ETH_ALEN); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4013 | } |
| 4014 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 4015 | void ath9k_hw_setopmode(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4016 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 4017 | ath9k_hw_set_operating_mode(ah, ah->opmode); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4018 | } |
| 4019 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 4020 | void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4021 | { |
| 4022 | REG_WRITE(ah, AR_MCAST_FIL0, filter0); |
| 4023 | REG_WRITE(ah, AR_MCAST_FIL1, filter1); |
| 4024 | } |
| 4025 | |
Luis R. Rodriguez | f2b2143 | 2009-09-10 08:50:20 -0700 | [diff] [blame] | 4026 | void ath9k_hw_setbssidmask(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4027 | { |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame^] | 4028 | struct ath_common *common = ath9k_hw_common(ah); |
| 4029 | |
| 4030 | REG_WRITE(ah, AR_BSSMSKL, get_unaligned_le32(common->bssidmask)); |
| 4031 | REG_WRITE(ah, AR_BSSMSKU, get_unaligned_le16(common->bssidmask + 4)); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4032 | } |
| 4033 | |
Luis R. Rodriguez | f2b2143 | 2009-09-10 08:50:20 -0700 | [diff] [blame] | 4034 | void ath9k_hw_write_associd(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4035 | { |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame^] | 4036 | struct ath_common *common = ath9k_hw_common(ah); |
| 4037 | |
| 4038 | REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid)); |
| 4039 | REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) | |
| 4040 | ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S)); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4041 | } |
| 4042 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 4043 | u64 ath9k_hw_gettsf64(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4044 | { |
| 4045 | u64 tsf; |
| 4046 | |
| 4047 | tsf = REG_READ(ah, AR_TSF_U32); |
| 4048 | tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32); |
| 4049 | |
| 4050 | return tsf; |
| 4051 | } |
| 4052 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 4053 | void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64) |
Alina Friedrichsen | 27abe06 | 2009-01-23 05:44:21 +0100 | [diff] [blame] | 4054 | { |
Alina Friedrichsen | 27abe06 | 2009-01-23 05:44:21 +0100 | [diff] [blame] | 4055 | REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff); |
Alina Friedrichsen | b9a1619 | 2009-03-02 23:28:38 +0100 | [diff] [blame] | 4056 | REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff); |
Alina Friedrichsen | 27abe06 | 2009-01-23 05:44:21 +0100 | [diff] [blame] | 4057 | } |
| 4058 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 4059 | void ath9k_hw_reset_tsf(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4060 | { |
Gabor Juhos | f9b604f | 2009-06-21 00:02:15 +0200 | [diff] [blame] | 4061 | if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0, |
| 4062 | AH_TSF_WRITE_TIMEOUT)) |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 4063 | DPRINTF(ah, ATH_DBG_RESET, |
Gabor Juhos | f9b604f | 2009-06-21 00:02:15 +0200 | [diff] [blame] | 4064 | "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n"); |
| 4065 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4066 | REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 4067 | } |
| 4068 | |
Sujith | 54e4cec | 2009-08-07 09:45:09 +0530 | [diff] [blame] | 4069 | void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 4070 | { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 4071 | if (setting) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 4072 | ah->misc_mode |= AR_PCU_TX_ADD_TSF; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 4073 | else |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 4074 | ah->misc_mode &= ~AR_PCU_TX_ADD_TSF; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 4075 | } |
| 4076 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 4077 | bool ath9k_hw_setslottime(struct ath_hw *ah, u32 us) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 4078 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4079 | if (us < ATH9K_SLOT_TIME_9 || us > ath9k_hw_mac_to_usec(ah, 0xffff)) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 4080 | DPRINTF(ah, ATH_DBG_RESET, "bad slot time %u\n", us); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 4081 | ah->slottime = (u32) -1; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4082 | return false; |
| 4083 | } else { |
| 4084 | REG_WRITE(ah, AR_D_GBL_IFS_SLOT, ath9k_hw_mac_to_clks(ah, us)); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 4085 | ah->slottime = us; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4086 | return true; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 4087 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 4088 | } |
| 4089 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 4090 | void ath9k_hw_set11nmac2040(struct ath_hw *ah, enum ath9k_ht_macmode mode) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 4091 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4092 | u32 macmode; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 4093 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4094 | if (mode == ATH9K_HT_MACMODE_2040 && |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 4095 | !ah->config.cwm_ignore_extcca) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4096 | macmode = AR_2040_JOINED_RX_CLEAR; |
| 4097 | else |
| 4098 | macmode = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 4099 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4100 | REG_WRITE(ah, AR_2040_MODE, macmode); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 4101 | } |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 4102 | |
| 4103 | /* HW Generic timers configuration */ |
| 4104 | |
| 4105 | static const struct ath_gen_timer_configuration gen_tmr_configuration[] = |
| 4106 | { |
| 4107 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 4108 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 4109 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 4110 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 4111 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 4112 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 4113 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 4114 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 4115 | {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001}, |
| 4116 | {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4, |
| 4117 | AR_NDP2_TIMER_MODE, 0x0002}, |
| 4118 | {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4, |
| 4119 | AR_NDP2_TIMER_MODE, 0x0004}, |
| 4120 | {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4, |
| 4121 | AR_NDP2_TIMER_MODE, 0x0008}, |
| 4122 | {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4, |
| 4123 | AR_NDP2_TIMER_MODE, 0x0010}, |
| 4124 | {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4, |
| 4125 | AR_NDP2_TIMER_MODE, 0x0020}, |
| 4126 | {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4, |
| 4127 | AR_NDP2_TIMER_MODE, 0x0040}, |
| 4128 | {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4, |
| 4129 | AR_NDP2_TIMER_MODE, 0x0080} |
| 4130 | }; |
| 4131 | |
| 4132 | /* HW generic timer primitives */ |
| 4133 | |
| 4134 | /* compute and clear index of rightmost 1 */ |
| 4135 | static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask) |
| 4136 | { |
| 4137 | u32 b; |
| 4138 | |
| 4139 | b = *mask; |
| 4140 | b &= (0-b); |
| 4141 | *mask &= ~b; |
| 4142 | b *= debruijn32; |
| 4143 | b >>= 27; |
| 4144 | |
| 4145 | return timer_table->gen_timer_index[b]; |
| 4146 | } |
| 4147 | |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 4148 | u32 ath9k_hw_gettsf32(struct ath_hw *ah) |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 4149 | { |
| 4150 | return REG_READ(ah, AR_TSF_L32); |
| 4151 | } |
| 4152 | |
| 4153 | struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah, |
| 4154 | void (*trigger)(void *), |
| 4155 | void (*overflow)(void *), |
| 4156 | void *arg, |
| 4157 | u8 timer_index) |
| 4158 | { |
| 4159 | struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers; |
| 4160 | struct ath_gen_timer *timer; |
| 4161 | |
| 4162 | timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL); |
| 4163 | |
| 4164 | if (timer == NULL) { |
| 4165 | printk(KERN_DEBUG "Failed to allocate memory" |
| 4166 | "for hw timer[%d]\n", timer_index); |
| 4167 | return NULL; |
| 4168 | } |
| 4169 | |
| 4170 | /* allocate a hardware generic timer slot */ |
| 4171 | timer_table->timers[timer_index] = timer; |
| 4172 | timer->index = timer_index; |
| 4173 | timer->trigger = trigger; |
| 4174 | timer->overflow = overflow; |
| 4175 | timer->arg = arg; |
| 4176 | |
| 4177 | return timer; |
| 4178 | } |
| 4179 | |
| 4180 | void ath_gen_timer_start(struct ath_hw *ah, |
| 4181 | struct ath_gen_timer *timer, |
| 4182 | u32 timer_next, u32 timer_period) |
| 4183 | { |
| 4184 | struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers; |
| 4185 | u32 tsf; |
| 4186 | |
| 4187 | BUG_ON(!timer_period); |
| 4188 | |
| 4189 | set_bit(timer->index, &timer_table->timer_mask.timer_bits); |
| 4190 | |
| 4191 | tsf = ath9k_hw_gettsf32(ah); |
| 4192 | |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 4193 | DPRINTF(ah, ATH_DBG_HWTIMER, "curent tsf %x period %x" |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 4194 | "timer_next %x\n", tsf, timer_period, timer_next); |
| 4195 | |
| 4196 | /* |
| 4197 | * Pull timer_next forward if the current TSF already passed it |
| 4198 | * because of software latency |
| 4199 | */ |
| 4200 | if (timer_next < tsf) |
| 4201 | timer_next = tsf + timer_period; |
| 4202 | |
| 4203 | /* |
| 4204 | * Program generic timer registers |
| 4205 | */ |
| 4206 | REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr, |
| 4207 | timer_next); |
| 4208 | REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr, |
| 4209 | timer_period); |
| 4210 | REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr, |
| 4211 | gen_tmr_configuration[timer->index].mode_mask); |
| 4212 | |
| 4213 | /* Enable both trigger and thresh interrupt masks */ |
| 4214 | REG_SET_BIT(ah, AR_IMR_S5, |
| 4215 | (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) | |
| 4216 | SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG))); |
| 4217 | |
| 4218 | if ((ah->ah_sc->imask & ATH9K_INT_GENTIMER) == 0) { |
| 4219 | ath9k_hw_set_interrupts(ah, 0); |
| 4220 | ah->ah_sc->imask |= ATH9K_INT_GENTIMER; |
| 4221 | ath9k_hw_set_interrupts(ah, ah->ah_sc->imask); |
| 4222 | } |
| 4223 | } |
| 4224 | |
| 4225 | void ath_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer) |
| 4226 | { |
| 4227 | struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers; |
| 4228 | |
| 4229 | if ((timer->index < AR_FIRST_NDP_TIMER) || |
| 4230 | (timer->index >= ATH_MAX_GEN_TIMER)) { |
| 4231 | return; |
| 4232 | } |
| 4233 | |
| 4234 | /* Clear generic timer enable bits. */ |
| 4235 | REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr, |
| 4236 | gen_tmr_configuration[timer->index].mode_mask); |
| 4237 | |
| 4238 | /* Disable both trigger and thresh interrupt masks */ |
| 4239 | REG_CLR_BIT(ah, AR_IMR_S5, |
| 4240 | (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) | |
| 4241 | SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG))); |
| 4242 | |
| 4243 | clear_bit(timer->index, &timer_table->timer_mask.timer_bits); |
| 4244 | |
| 4245 | /* if no timer is enabled, turn off interrupt mask */ |
| 4246 | if (timer_table->timer_mask.val == 0) { |
| 4247 | ath9k_hw_set_interrupts(ah, 0); |
| 4248 | ah->ah_sc->imask &= ~ATH9K_INT_GENTIMER; |
| 4249 | ath9k_hw_set_interrupts(ah, ah->ah_sc->imask); |
| 4250 | } |
| 4251 | } |
| 4252 | |
| 4253 | void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer) |
| 4254 | { |
| 4255 | struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers; |
| 4256 | |
| 4257 | /* free the hardware generic timer slot */ |
| 4258 | timer_table->timers[timer->index] = NULL; |
| 4259 | kfree(timer); |
| 4260 | } |
| 4261 | |
| 4262 | /* |
| 4263 | * Generic Timer Interrupts handling |
| 4264 | */ |
| 4265 | void ath_gen_timer_isr(struct ath_hw *ah) |
| 4266 | { |
| 4267 | struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers; |
| 4268 | struct ath_gen_timer *timer; |
| 4269 | u32 trigger_mask, thresh_mask, index; |
| 4270 | |
| 4271 | /* get hardware generic timer interrupt status */ |
| 4272 | trigger_mask = ah->intr_gen_timer_trigger; |
| 4273 | thresh_mask = ah->intr_gen_timer_thresh; |
| 4274 | trigger_mask &= timer_table->timer_mask.val; |
| 4275 | thresh_mask &= timer_table->timer_mask.val; |
| 4276 | |
| 4277 | trigger_mask &= ~thresh_mask; |
| 4278 | |
| 4279 | while (thresh_mask) { |
| 4280 | index = rightmost_index(timer_table, &thresh_mask); |
| 4281 | timer = timer_table->timers[index]; |
| 4282 | BUG_ON(!timer); |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 4283 | DPRINTF(ah, ATH_DBG_HWTIMER, |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 4284 | "TSF overflow for Gen timer %d\n", index); |
| 4285 | timer->overflow(timer->arg); |
| 4286 | } |
| 4287 | |
| 4288 | while (trigger_mask) { |
| 4289 | index = rightmost_index(timer_table, &trigger_mask); |
| 4290 | timer = timer_table->timers[index]; |
| 4291 | BUG_ON(!timer); |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 4292 | DPRINTF(ah, ATH_DBG_HWTIMER, |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 4293 | "Gen timer[%d] trigger\n", index); |
| 4294 | timer->trigger(timer->arg); |
| 4295 | } |
| 4296 | } |
Vasanthakumar Thiagarajan | 7b6840a | 2009-09-07 17:46:49 +0530 | [diff] [blame] | 4297 | |
| 4298 | /* |
| 4299 | * Primitive to disable ASPM |
| 4300 | */ |
| 4301 | void ath_pcie_aspm_disable(struct ath_softc *sc) |
| 4302 | { |
| 4303 | struct pci_dev *pdev = to_pci_dev(sc->dev); |
| 4304 | u8 aspm; |
| 4305 | |
| 4306 | pci_read_config_byte(pdev, ATH_PCIE_CAP_LINK_CTRL, &aspm); |
| 4307 | aspm &= ~(ATH_PCIE_CAP_LINK_L0S | ATH_PCIE_CAP_LINK_L1); |
| 4308 | pci_write_config_byte(pdev, ATH_PCIE_CAP_LINK_CTRL, aspm); |
| 4309 | } |