blob: 4e14c307b3daa243b1317c89d6da6145c247ab30 [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
Sujithcee075a2009-03-13 09:07:23 +05302 * Copyright (c) 2008-2009 Atheros Communications Inc.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003 *
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 Thiagarajan7b6840a2009-09-07 17:46:49 +053019#include <linux/pci.h>
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070020
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -070021#include "hw.h"
Sujith394cf0a2009-02-09 13:26:54 +053022#include "ath9k.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070023#include "initvals.h"
24
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080025#define ATH9K_CLOCK_RATE_CCK 22
26#define ATH9K_CLOCK_RATE_5GHZ_OFDM 40
27#define ATH9K_CLOCK_RATE_2GHZ_OFDM 44
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070028
Sujithcbe61d82009-02-09 13:27:12 +053029static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type);
30static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan,
Sujithf1dc5602008-10-29 10:16:30 +053031 enum ath9k_ht_macmode macmode);
Sujithcbe61d82009-02-09 13:27:12 +053032static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +053033 struct ar5416_eeprom_def *pEepData,
Sujithf1dc5602008-10-29 10:16:30 +053034 u32 reg, u32 value);
Sujithcbe61d82009-02-09 13:27:12 +053035static void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan);
36static void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070037
Sujithf1dc5602008-10-29 10:16:30 +053038/********************/
39/* Helper Functions */
40/********************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070041
Sujithcbe61d82009-02-09 13:27:12 +053042static u32 ath9k_hw_mac_usec(struct ath_hw *ah, u32 clks)
Sujithf1dc5602008-10-29 10:16:30 +053043{
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080044 struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053045
Sujith2660b812009-02-09 13:27:26 +053046 if (!ah->curchan) /* should really check for CCK instead */
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080047 return clks / ATH9K_CLOCK_RATE_CCK;
48 if (conf->channel->band == IEEE80211_BAND_2GHZ)
49 return clks / ATH9K_CLOCK_RATE_2GHZ_OFDM;
Sujithcbe61d82009-02-09 13:27:12 +053050
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080051 return clks / ATH9K_CLOCK_RATE_5GHZ_OFDM;
Sujithf1dc5602008-10-29 10:16:30 +053052}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070053
Sujithcbe61d82009-02-09 13:27:12 +053054static u32 ath9k_hw_mac_to_usec(struct ath_hw *ah, u32 clks)
Sujithf1dc5602008-10-29 10:16:30 +053055{
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080056 struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053057
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080058 if (conf_is_ht40(conf))
Sujithf1dc5602008-10-29 10:16:30 +053059 return ath9k_hw_mac_usec(ah, clks) / 2;
60 else
61 return ath9k_hw_mac_usec(ah, clks);
62}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070063
Sujithcbe61d82009-02-09 13:27:12 +053064static u32 ath9k_hw_mac_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053065{
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080066 struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053067
Sujith2660b812009-02-09 13:27:26 +053068 if (!ah->curchan) /* should really check for CCK instead */
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080069 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;
Sujithf1dc5602008-10-29 10:16:30 +053073}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070074
Sujithcbe61d82009-02-09 13:27:12 +053075static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053076{
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080077 struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053078
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080079 if (conf_is_ht40(conf))
Sujithf1dc5602008-10-29 10:16:30 +053080 return ath9k_hw_mac_clks(ah, usecs) * 2;
81 else
82 return ath9k_hw_mac_clks(ah, usecs);
83}
84
Gabor Juhosfb4a3d32009-04-29 13:01:58 +020085/*
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
93void 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
104unsigned 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
Sujith0caa7b12009-02-16 13:23:20 +0530117bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700118{
119 int i;
120
Sujith0caa7b12009-02-16 13:23:20 +0530121 BUG_ON(timeout < AH_TIME_QUANTUM);
122
123 for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700124 if ((REG_READ(ah, reg) & mask) == val)
125 return true;
126
127 udelay(AH_TIME_QUANTUM);
128 }
Sujith04bd46382008-11-28 22:18:05 +0530129
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700130 DPRINTF(ah, ATH_DBG_ANY,
Sujith0caa7b12009-02-16 13:23:20 +0530131 "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
132 timeout, reg, REG_READ(ah, reg), mask, val);
Sujithf1dc5602008-10-29 10:16:30 +0530133
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700134 return false;
135}
136
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700137u32 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
Sujithcbe61d82009-02-09 13:27:12 +0530149bool ath9k_get_channel_edges(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530150 u16 flags, u16 *low,
151 u16 *high)
152{
Sujith2660b812009-02-09 13:27:26 +0530153 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530154
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
Sujithcbe61d82009-02-09 13:27:12 +0530168u16 ath9k_hw_computetxtime(struct ath_hw *ah,
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400169 const struct ath_rate_table *rates,
Sujithf1dc5602008-10-29 10:16:30 +0530170 u32 frameLen, u16 rateix,
171 bool shortPreamble)
172{
173 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
174 u32 kbps;
175
Sujithe63835b2008-11-18 09:07:53 +0530176 kbps = rates->info[rateix].ratekbps;
Sujithf1dc5602008-10-29 10:16:30 +0530177
178 if (kbps == 0)
179 return 0;
180
181 switch (rates->info[rateix].phy) {
Sujith46d14a52008-11-18 09:08:13 +0530182 case WLAN_RC_PHY_CCK:
Sujithf1dc5602008-10-29 10:16:30 +0530183 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
Sujithe63835b2008-11-18 09:07:53 +0530184 if (shortPreamble && rates->info[rateix].short_preamble)
Sujithf1dc5602008-10-29 10:16:30 +0530185 phyTime >>= 1;
186 numBits = frameLen << 3;
187 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
188 break;
Sujith46d14a52008-11-18 09:08:13 +0530189 case WLAN_RC_PHY_OFDM:
Sujith2660b812009-02-09 13:27:26 +0530190 if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530191 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);
Sujith2660b812009-02-09 13:27:26 +0530197 } else if (ah->curchan &&
198 IS_CHAN_HALF_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530199 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. Rodriguez4d6b2282009-09-07 04:52:26 -0700214 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +0530215 "Unknown phy %u (rate ix %u)\n",
Sujithf1dc5602008-10-29 10:16:30 +0530216 rates->info[rateix].phy, rateix);
217 txTime = 0;
218 break;
219 }
220
221 return txTime;
222}
223
Sujithcbe61d82009-02-09 13:27:12 +0530224void ath9k_hw_get_channel_centers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530225 struct ath9k_channel *chan,
226 struct chan_centers *centers)
227{
228 int8_t extoff;
Sujithf1dc5602008-10-29 10:16:30 +0530229
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 *
Sujith2660b812009-02-09 13:27:26 +0530251 ((ah->extprotspacing == ATH9K_HT_EXTPROTSPACING_20) ?
Sujithf1dc5602008-10-29 10:16:30 +0530252 HT40_CHANNEL_CENTER_SHIFT : 15));
Sujithf1dc5602008-10-29 10:16:30 +0530253}
254
255/******************/
256/* Chip Revisions */
257/******************/
258
Sujithcbe61d82009-02-09 13:27:12 +0530259static void ath9k_hw_read_revisions(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530260{
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);
Sujithd535a422009-02-09 13:27:06 +0530267 ah->hw_version.macVersion =
268 (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
269 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
Sujith2660b812009-02-09 13:27:26 +0530270 ah->is_pciexpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
Sujithf1dc5602008-10-29 10:16:30 +0530271 } else {
272 if (!AR_SREV_9100(ah))
Sujithd535a422009-02-09 13:27:06 +0530273 ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
Sujithf1dc5602008-10-29 10:16:30 +0530274
Sujithd535a422009-02-09 13:27:06 +0530275 ah->hw_version.macRev = val & AR_SREV_REVISION;
Sujithf1dc5602008-10-29 10:16:30 +0530276
Sujithd535a422009-02-09 13:27:06 +0530277 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
Sujith2660b812009-02-09 13:27:26 +0530278 ah->is_pciexpress = true;
Sujithf1dc5602008-10-29 10:16:30 +0530279 }
280}
281
Sujithcbe61d82009-02-09 13:27:12 +0530282static int ath9k_hw_get_radiorev(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530283{
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
Sujithcbe61d82009-02-09 13:27:12 +0530301static void ath9k_hw_disablepcie(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530302{
Sujithfeed0292009-01-29 11:37:35 +0530303 if (AR_SREV_9100(ah))
Sujithf1dc5602008-10-29 10:16:30 +0530304 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
Sujithcbe61d82009-02-09 13:27:12 +0530319static bool ath9k_hw_chip_test(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530320{
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. Rodriguez4d6b2282009-09-07 04:52:26 -0700339 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +0530340 "address test failed "
Sujithf1dc5602008-10-29 10:16:30 +0530341 "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
Sujith04bd46382008-11-28 22:18:05 +0530342 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530343 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. Rodriguez4d6b2282009-09-07 04:52:26 -0700351 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +0530352 "address test failed "
Sujithf1dc5602008-10-29 10:16:30 +0530353 "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
Sujith04bd46382008-11-28 22:18:05 +0530354 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530355 return false;
356 }
357 }
358 REG_WRITE(ah, regAddr[i], regHold[i]);
359 }
360 udelay(100);
Sujithcbe61d82009-02-09 13:27:12 +0530361
Sujithf1dc5602008-10-29 10:16:30 +0530362 return true;
363}
364
365static const char *ath9k_hw_devname(u16 devid)
366{
367 switch (devid) {
368 case AR5416_DEVID_PCI:
Sujithf1dc5602008-10-29 10:16:30 +0530369 return "Atheros 5416";
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +0100370 case AR5416_DEVID_PCIE:
371 return "Atheros 5418";
Sujithf1dc5602008-10-29 10:16:30 +0530372 case AR9160_DEVID_PCI:
373 return "Atheros 9160";
Gabor Juhos0c1aa492009-01-14 20:17:12 +0100374 case AR5416_AR9100_DEVID:
375 return "Atheros 9100";
Sujithf1dc5602008-10-29 10:16:30 +0530376 case AR9280_DEVID_PCI:
377 case AR9280_DEVID_PCIE:
378 return "Atheros 9280";
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530379 case AR9285_DEVID_PCIE:
380 return "Atheros 9285";
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530381 case AR5416_DEVID_AR9287_PCI:
382 case AR5416_DEVID_AR9287_PCIE:
383 return "Atheros 9287";
Sujithf1dc5602008-10-29 10:16:30 +0530384 }
385
386 return NULL;
387}
388
Luis R. Rodriguezb8b0f372009-08-03 12:24:43 -0700389static void ath9k_hw_init_config(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700390{
391 int i;
392
Sujith2660b812009-02-09 13:27:26 +0530393 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;
Sujith2660b812009-02-09 13:27:26 +0530399 ah->config.pcie_clock_req = 0;
Sujith2660b812009-02-09 13:27:26 +0530400 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;
Sujith1cf68732009-08-13 09:34:32 +0530408 ah->config.diversity_control = ATH9K_ANT_VARIABLE;
Sujith2660b812009-02-09 13:27:26 +0530409 ah->config.antenna_switch_swap = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700410
411 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujith2660b812009-02-09 13:27:26 +0530412 ah->config.spurchans[i][0] = AR_NO_SPUR;
413 ah->config.spurchans[i][1] = AR_NO_SPUR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700414 }
415
Sujith0ef1f162009-03-30 15:28:35 +0530416 ah->config.intr_mitigation = true;
Luis R. Rodriguez61584252009-03-12 18:18:49 -0400417
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. Miller2d6a5e92009-03-17 15:01:30 -0700435 ah->config.serialize_regmode = SER_REG_MODE_AUTO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700436}
437
Luis R. Rodriguez50aca252009-08-03 12:24:42 -0700438static void ath9k_hw_init_defaults(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700439{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700440 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
Sujithd535a422009-02-09 13:27:06 +0530446 ah->hw_version.magic = AR5416_MAGIC;
Sujithd535a422009-02-09 13:27:06 +0530447 ah->hw_version.subvendorid = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700448
449 ah->ah_flags = 0;
Luis R. Rodriguez8df5d1b2009-08-03 12:24:37 -0700450 if (ah->hw_version.devid == AR5416_AR9100_DEVID)
Sujithd535a422009-02-09 13:27:06 +0530451 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700452 if (!AR_SREV_9100(ah))
453 ah->ah_flags = AH_USE_EEPROM;
454
Sujith2660b812009-02-09 13:27:26 +0530455 ah->atim_window = 0;
Sujith2660b812009-02-09 13:27:26 +0530456 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. Rodriguezf078f202008-08-04 00:16:41 -0700463
Sujith2660b812009-02-09 13:27:26 +0530464 ah->gbeacon_rate = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700465
Gabor Juhoscbdec972009-07-24 17:27:22 +0200466 ah->power_mode = ATH9K_PM_UNDEFINED;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700467}
468
Sujithcbe61d82009-02-09 13:27:12 +0530469static int ath9k_hw_rfattach(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700470{
471 bool rfStatus = false;
472 int ecode = 0;
473
474 rfStatus = ath9k_hw_init_rf(ah, &ecode);
475 if (!rfStatus) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700476 DPRINTF(ah, ATH_DBG_FATAL,
Sujithd8baa932009-03-30 15:28:25 +0530477 "RF setup failed, status: %u\n", ecode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700478 return ecode;
479 }
480
481 return 0;
482}
483
Sujithcbe61d82009-02-09 13:27:12 +0530484static int ath9k_hw_rf_claim(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700485{
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. Rodriguez4d6b2282009-09-07 04:52:26 -0700501 DPRINTF(ah, ATH_DBG_FATAL,
Sujithd8baa932009-03-30 15:28:25 +0530502 "Radio Chip Rev 0x%02X not supported\n",
503 val & AR_RADIO_SREV_MAJOR);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700504 return -EOPNOTSUPP;
505 }
506
Sujithd535a422009-02-09 13:27:06 +0530507 ah->hw_version.analog5GhzRev = val;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700508
509 return 0;
510}
511
Sujithcbe61d82009-02-09 13:27:12 +0530512static int ath9k_hw_init_macaddr(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700513{
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700514 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530515 u32 sum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700516 int i;
Sujithf1dc5602008-10-29 10:16:30 +0530517 u16 eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700518
Sujithf1dc5602008-10-29 10:16:30 +0530519 sum = 0;
520 for (i = 0; i < 3; i++) {
Sujithf74df6f2009-02-09 13:27:24 +0530521 eeval = ah->eep_ops->get_eeprom(ah, AR_EEPROM_MAC(i));
Sujithf1dc5602008-10-29 10:16:30 +0530522 sum += eeval;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700523 common->macaddr[2 * i] = eeval >> 8;
524 common->macaddr[2 * i + 1] = eeval & 0xff;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700525 }
Sujithd8baa932009-03-30 15:28:25 +0530526 if (sum == 0 || sum == 0xffff * 3)
Sujithf1dc5602008-10-29 10:16:30 +0530527 return -EADDRNOTAVAIL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700528
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700529 return 0;
530}
531
Sujithcbe61d82009-02-09 13:27:12 +0530532static void ath9k_hw_init_rxgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530533{
534 u32 rxgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530535
Sujithf74df6f2009-02-09 13:27:24 +0530536 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 Balasubramanian9f804202008-11-13 17:58:41 +0530538
539 if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530540 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530541 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)
Sujith2660b812009-02-09 13:27:26 +0530544 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530545 ar9280Modes_backoff_23db_rxgain_9280_2,
546 ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 6);
547 else
Sujith2660b812009-02-09 13:27:26 +0530548 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530549 ar9280Modes_original_rxgain_9280_2,
550 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530551 } else {
Sujith2660b812009-02-09 13:27:26 +0530552 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530553 ar9280Modes_original_rxgain_9280_2,
554 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530555 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530556}
557
Sujithcbe61d82009-02-09 13:27:12 +0530558static void ath9k_hw_init_txgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530559{
560 u32 txgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530561
Sujithf74df6f2009-02-09 13:27:24 +0530562 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 Balasubramanian9f804202008-11-13 17:58:41 +0530564
565 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
Sujith2660b812009-02-09 13:27:26 +0530566 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530567 ar9280Modes_high_power_tx_gain_9280_2,
568 ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 6);
569 else
Sujith2660b812009-02-09 13:27:26 +0530570 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530571 ar9280Modes_original_tx_gain_9280_2,
572 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530573 } else {
Sujith2660b812009-02-09 13:27:26 +0530574 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530575 ar9280Modes_original_tx_gain_9280_2,
576 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530577 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530578}
579
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700580static int ath9k_hw_post_init(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700581{
582 int ecode;
583
Sujithd8baa932009-03-30 15:28:25 +0530584 if (!ath9k_hw_chip_test(ah))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700585 return -ENODEV;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700586
587 ecode = ath9k_hw_rf_claim(ah);
588 if (ecode != 0)
589 return ecode;
590
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700591 ecode = ath9k_hw_eeprom_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700592 if (ecode != 0)
593 return ecode;
Sujith7d01b222009-03-13 08:55:55 +0530594
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700595 DPRINTF(ah, ATH_DBG_CONFIG, "Eeprom VER: %d, REV: %d\n",
Sujith7d01b222009-03-13 08:55:55 +0530596 ah->eep_ops->get_eeprom_ver(ah), ah->eep_ops->get_eeprom_rev(ah));
597
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700598 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. Rodriguezf637cfd2009-08-03 12:24:46 -0700604 ath9k_hw_ani_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700605 }
Sujithf1dc5602008-10-29 10:16:30 +0530606
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700607 return 0;
608}
609
Luis R. Rodriguezee2bb462009-08-03 12:24:39 -0700610static 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. Rodriguezf9d4a662009-08-03 12:24:41 -0700629static 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. Rodriguezd7e7d222009-08-03 23:14:12 -0400640 /* Not yet */
641 case AR_SREV_VERSION_9271:
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700642 default:
643 break;
644 }
645 return false;
646}
647
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700648static void ath9k_hw_init_cal_settings(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700649{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700650 if (AR_SREV_9160_10_OR_LATER(ah)) {
651 if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530652 ah->iq_caldata.calData = &iq_cal_single_sample;
653 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700654 &adc_gain_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530655 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700656 &adc_dc_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530657 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700658 &adc_init_dc_cal;
659 } else {
Sujith2660b812009-02-09 13:27:26 +0530660 ah->iq_caldata.calData = &iq_cal_multi_sample;
661 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700662 &adc_gain_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530663 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700664 &adc_dc_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530665 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700666 &adc_init_dc_cal;
667 }
Sujith2660b812009-02-09 13:27:26 +0530668 ah->supp_cals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700669 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700670}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700671
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700672static void ath9k_hw_init_mode_regs(struct ath_hw *ah)
673{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400674 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 Natarajanac88b6e2009-07-23 10:59:57 +0530682 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. Rodriguezf078f202008-08-04 00:16:41 -0700701
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530702 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 Balasubramanian4e845162009-03-06 11:24:10 +0530713
Sujith2660b812009-02-09 13:27:26 +0530714 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530715 ARRAY_SIZE(ar9285Modes_9285_1_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530716 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530717 ARRAY_SIZE(ar9285Common_9285_1_2), 2);
718
Sujith2660b812009-02-09 13:27:26 +0530719 if (ah->config.pcie_clock_req) {
720 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530721 ar9285PciePhy_clkreq_off_L1_9285_1_2,
722 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2);
723 } else {
Sujith2660b812009-02-09 13:27:26 +0530724 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530725 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)) {
Sujith2660b812009-02-09 13:27:26 +0530730 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530731 ARRAY_SIZE(ar9285Modes_9285), 6);
Sujith2660b812009-02-09 13:27:26 +0530732 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530733 ARRAY_SIZE(ar9285Common_9285), 2);
734
Sujith2660b812009-02-09 13:27:26 +0530735 if (ah->config.pcie_clock_req) {
736 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530737 ar9285PciePhy_clkreq_off_L1_9285,
738 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2);
739 } else {
Sujith2660b812009-02-09 13:27:26 +0530740 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530741 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)) {
Sujith2660b812009-02-09 13:27:26 +0530745 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700746 ARRAY_SIZE(ar9280Modes_9280_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530747 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700748 ARRAY_SIZE(ar9280Common_9280_2), 2);
749
Sujith2660b812009-02-09 13:27:26 +0530750 if (ah->config.pcie_clock_req) {
751 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530752 ar9280PciePhy_clkreq_off_L1_9280,
753 ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700754 } else {
Sujith2660b812009-02-09 13:27:26 +0530755 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530756 ar9280PciePhy_clkreq_always_on_L1_9280,
757 ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700758 }
Sujith2660b812009-02-09 13:27:26 +0530759 INIT_INI_ARRAY(&ah->iniModesAdditional,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700760 ar9280Modes_fast_clock_9280_2,
Sujithf1dc5602008-10-29 10:16:30 +0530761 ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700762 } else if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530763 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700764 ARRAY_SIZE(ar9280Modes_9280), 6);
Sujith2660b812009-02-09 13:27:26 +0530765 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700766 ARRAY_SIZE(ar9280Common_9280), 2);
767 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530768 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700769 ARRAY_SIZE(ar5416Modes_9160), 6);
Sujith2660b812009-02-09 13:27:26 +0530770 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700771 ARRAY_SIZE(ar5416Common_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530772 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700773 ARRAY_SIZE(ar5416Bank0_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530774 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700775 ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530776 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700777 ARRAY_SIZE(ar5416Bank1_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530778 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700779 ARRAY_SIZE(ar5416Bank2_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530780 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700781 ARRAY_SIZE(ar5416Bank3_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530782 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700783 ARRAY_SIZE(ar5416Bank6_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530784 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700785 ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530786 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700787 ARRAY_SIZE(ar5416Bank7_9160), 2);
788 if (AR_SREV_9160_11(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530789 INIT_INI_ARRAY(&ah->iniAddac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700790 ar5416Addac_91601_1,
791 ARRAY_SIZE(ar5416Addac_91601_1), 2);
792 } else {
Sujith2660b812009-02-09 13:27:26 +0530793 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700794 ARRAY_SIZE(ar5416Addac_9160), 2);
795 }
796 } else if (AR_SREV_9100_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530797 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700798 ARRAY_SIZE(ar5416Modes_9100), 6);
Sujith2660b812009-02-09 13:27:26 +0530799 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700800 ARRAY_SIZE(ar5416Common_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530801 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700802 ARRAY_SIZE(ar5416Bank0_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530803 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700804 ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530805 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700806 ARRAY_SIZE(ar5416Bank1_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530807 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700808 ARRAY_SIZE(ar5416Bank2_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530809 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700810 ARRAY_SIZE(ar5416Bank3_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530811 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700812 ARRAY_SIZE(ar5416Bank6_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530813 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700814 ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530815 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700816 ARRAY_SIZE(ar5416Bank7_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530817 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700818 ARRAY_SIZE(ar5416Addac_9100), 2);
819 } else {
Sujith2660b812009-02-09 13:27:26 +0530820 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700821 ARRAY_SIZE(ar5416Modes), 6);
Sujith2660b812009-02-09 13:27:26 +0530822 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700823 ARRAY_SIZE(ar5416Common), 2);
Sujith2660b812009-02-09 13:27:26 +0530824 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700825 ARRAY_SIZE(ar5416Bank0), 2);
Sujith2660b812009-02-09 13:27:26 +0530826 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700827 ARRAY_SIZE(ar5416BB_RfGain), 3);
Sujith2660b812009-02-09 13:27:26 +0530828 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700829 ARRAY_SIZE(ar5416Bank1), 2);
Sujith2660b812009-02-09 13:27:26 +0530830 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700831 ARRAY_SIZE(ar5416Bank2), 2);
Sujith2660b812009-02-09 13:27:26 +0530832 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700833 ARRAY_SIZE(ar5416Bank3), 3);
Sujith2660b812009-02-09 13:27:26 +0530834 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700835 ARRAY_SIZE(ar5416Bank6), 3);
Sujith2660b812009-02-09 13:27:26 +0530836 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700837 ARRAY_SIZE(ar5416Bank6TPC), 3);
Sujith2660b812009-02-09 13:27:26 +0530838 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700839 ARRAY_SIZE(ar5416Bank7), 2);
Sujith2660b812009-02-09 13:27:26 +0530840 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700841 ARRAY_SIZE(ar5416Addac), 2);
842 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700843}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700844
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700845static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
846{
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530847 if (AR_SREV_9287_11_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530848 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 Natarajanb37fa872009-09-23 16:27:27 +0530858 if (AR_SREV_9287_11_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530859 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 Balasubramanian4e845162009-03-06 11:24:10 +0530869 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. Rodriguezaa4058a2009-08-03 12:24:45 -0700883}
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530884
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700885static void ath9k_hw_init_11a_eeprom_fix(struct ath_hw *ah)
886{
887 u32 i, j;
Sujith06d0f062009-02-12 10:06:45 +0530888
889 if ((ah->hw_version.devid == AR9280_DEVID_PCI) &&
890 test_bit(ATH9K_MODE_11A, ah->caps.wireless_modes)) {
891
892 /* EEPROM Fixup */
Sujith2660b812009-02-09 13:27:26 +0530893 for (i = 0; i < ah->iniModes.ia_rows; i++) {
894 u32 reg = INI_RA(&ah->iniModes, i, 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700895
Sujith2660b812009-02-09 13:27:26 +0530896 for (j = 1; j < ah->iniModes.ia_columns; j++) {
897 u32 val = INI_RA(&ah->iniModes, i, j);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700898
Sujith2660b812009-02-09 13:27:26 +0530899 INI_RA(&ah->iniModes, i, j) =
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530900 ath9k_hw_ini_fixup(ah,
Sujith2660b812009-02-09 13:27:26 +0530901 &ah->eeprom.def,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700902 reg, val);
903 }
904 }
905 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700906}
907
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700908int ath9k_hw_init(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700909{
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700910 int r = 0;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700911
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700912 if (!ath9k_hw_devid_supported(ah->hw_version.devid))
913 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700914
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. Rodriguez4d6b2282009-09-07 04:52:26 -0700919 DPRINTF(ah, ATH_DBG_FATAL, "Couldn't reset chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700920 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700921 }
922
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700923 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700924 DPRINTF(ah, ATH_DBG_FATAL, "Couldn't wakeup chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700925 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700926 }
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. Rodriguez4d6b2282009-09-07 04:52:26 -0700939 DPRINTF(ah, ATH_DBG_RESET, "serialize_regmode is %d\n",
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700940 ah->config.serialize_regmode);
941
942 if (!ath9k_hw_macversion_supported(ah->hw_version.macVersion)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700943 DPRINTF(ah, ATH_DBG_FATAL,
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700944 "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. Rodriguez95fafca2009-08-03 12:24:54 -0700947 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700948 }
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. Rodriguezd7e7d222009-08-03 23:14:12 -0400955
956 if (AR_SREV_9271(ah))
957 ah->is_pciexpress = false;
958
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700959 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 Natarajan93b1b372009-09-17 09:24:58 +0530970 ath9k_hw_configpcipowersave(ah, 0, 0);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700971 else
972 ath9k_hw_disablepcie(ah);
973
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700974 r = ath9k_hw_post_init(ah);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700975 if (r)
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700976 return r;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700977
978 ath9k_hw_init_mode_gain_regs(ah);
979 ath9k_hw_fill_cap_info(ah);
980 ath9k_hw_init_11a_eeprom_fix(ah);
Sujithf6688cd2008-12-07 21:43:10 +0530981
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700982 r = ath9k_hw_init_macaddr(ah);
983 if (r) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700984 DPRINTF(ah, ATH_DBG_FATAL,
Sujithd8baa932009-03-30 15:28:25 +0530985 "Failed to initialize MAC address\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700986 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700987 }
988
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400989 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
Sujith2660b812009-02-09 13:27:26 +0530990 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700991 else
Sujith2660b812009-02-09 13:27:26 +0530992 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700993
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700994 ath9k_init_nfcal_hist_buffer(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700995
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700996 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700997}
998
Sujithcbe61d82009-02-09 13:27:12 +0530999static void ath9k_hw_init_bb(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301000 struct ath9k_channel *chan)
1001{
1002 u32 synthDelay;
1003
1004 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +05301005 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +05301006 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
Sujithcbe61d82009-02-09 13:27:12 +05301015static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301016{
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
Sujithcbe61d82009-02-09 13:27:12 +05301032static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301033 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 Juhosd03a66c2009-01-14 20:17:09 +01001093 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +05301094
1095 udelay(RTC_PLL_SETTLE_DELAY);
1096
1097 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
1098}
1099
Sujithcbe61d82009-02-09 13:27:12 +05301100static void ath9k_hw_init_chain_masks(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301101{
Sujithf1dc5602008-10-29 10:16:30 +05301102 int rx_chainmask, tx_chainmask;
1103
Sujith2660b812009-02-09 13:27:26 +05301104 rx_chainmask = ah->rxchainmask;
1105 tx_chainmask = ah->txchainmask;
Sujithf1dc5602008-10-29 10:16:30 +05301106
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:
Sujithd535a422009-02-09 13:27:06 +05301112 if (((ah)->hw_version.macVersion <= AR_SREV_VERSION_9160)) {
Sujithf1dc5602008-10-29 10:16:30 +05301113 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:
Sujithf1dc5602008-10-29 10:16:30 +05301119 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
Sujithcbe61d82009-02-09 13:27:12 +05301137static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -08001138 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301139{
Sujith2660b812009-02-09 13:27:26 +05301140 ah->mask_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +05301141 AR_IMR_TXURN |
1142 AR_IMR_RXERR |
1143 AR_IMR_RXORN |
1144 AR_IMR_BCNMISC;
1145
Sujith0ef1f162009-03-30 15:28:35 +05301146 if (ah->config.intr_mitigation)
Sujith2660b812009-02-09 13:27:26 +05301147 ah->mask_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
Sujithf1dc5602008-10-29 10:16:30 +05301148 else
Sujith2660b812009-02-09 13:27:26 +05301149 ah->mask_reg |= AR_IMR_RXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301150
Sujith2660b812009-02-09 13:27:26 +05301151 ah->mask_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301152
Colin McCabed97809d2008-12-01 13:38:55 -08001153 if (opmode == NL80211_IFTYPE_AP)
Sujith2660b812009-02-09 13:27:26 +05301154 ah->mask_reg |= AR_IMR_MIB;
Sujithf1dc5602008-10-29 10:16:30 +05301155
Sujith2660b812009-02-09 13:27:26 +05301156 REG_WRITE(ah, AR_IMR, ah->mask_reg);
Sujithf1dc5602008-10-29 10:16:30 +05301157 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
Sujithcbe61d82009-02-09 13:27:12 +05301166static bool ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301167{
Sujithf1dc5602008-10-29 10:16:30 +05301168 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001169 DPRINTF(ah, ATH_DBG_RESET, "bad ack timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301170 ah->acktimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301171 return false;
1172 } else {
1173 REG_RMW_FIELD(ah, AR_TIME_OUT,
1174 AR_TIME_OUT_ACK, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301175 ah->acktimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301176 return true;
1177 }
1178}
1179
Sujithcbe61d82009-02-09 13:27:12 +05301180static bool ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301181{
Sujithf1dc5602008-10-29 10:16:30 +05301182 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_CTS))) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001183 DPRINTF(ah, ATH_DBG_RESET, "bad cts timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301184 ah->ctstimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301185 return false;
1186 } else {
1187 REG_RMW_FIELD(ah, AR_TIME_OUT,
1188 AR_TIME_OUT_CTS, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301189 ah->ctstimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301190 return true;
1191 }
1192}
1193
Sujithcbe61d82009-02-09 13:27:12 +05301194static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +05301195{
Sujithf1dc5602008-10-29 10:16:30 +05301196 if (tu > 0xFFFF) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001197 DPRINTF(ah, ATH_DBG_XMIT,
Sujith04bd46382008-11-28 22:18:05 +05301198 "bad global tx timeout %u\n", tu);
Sujith2660b812009-02-09 13:27:26 +05301199 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301200 return false;
1201 } else {
1202 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +05301203 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +05301204 return true;
1205 }
1206}
1207
Sujithcbe61d82009-02-09 13:27:12 +05301208static void ath9k_hw_init_user_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301209{
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001210 DPRINTF(ah, ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
Sujith2660b812009-02-09 13:27:26 +05301211 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +05301212
Sujith2660b812009-02-09 13:27:26 +05301213 if (ah->misc_mode != 0)
Sujithf1dc5602008-10-29 10:16:30 +05301214 REG_WRITE(ah, AR_PCU_MISC,
Sujith2660b812009-02-09 13:27:26 +05301215 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);
Sujithf1dc5602008-10-29 10:16:30 +05301224}
1225
1226const char *ath9k_hw_probe(u16 vendorid, u16 devid)
1227{
1228 return vendorid == ATHEROS_VENDOR_ID ?
1229 ath9k_hw_devname(devid) : NULL;
1230}
1231
Sujithcbe61d82009-02-09 13:27:12 +05301232void ath9k_hw_detach(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001233{
1234 if (!AR_SREV_9100(ah))
Luis R. Rodrigueze70c0cf2009-08-03 12:24:51 -07001235 ath9k_hw_ani_disable(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001236
Luis R. Rodriguez081b35a2009-08-03 12:24:50 -07001237 ath9k_hw_rf_free(ah);
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001238 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001239 kfree(ah);
Luis R. Rodriguez9db6b6a2009-08-03 12:24:52 -07001240 ah = NULL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001241}
1242
Sujithf1dc5602008-10-29 10:16:30 +05301243/*******/
1244/* INI */
1245/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001246
Sujithcbe61d82009-02-09 13:27:12 +05301247static void ath9k_hw_override_ini(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301248 struct ath9k_channel *chan)
1249{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001250 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 Balasubramanian8aa15e12008-12-08 19:43:50 +05301271 /*
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 Thiagarajan204d7942009-09-17 09:26:14 +05301278 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 Balasubramanian8aa15e12008-12-08 19:43:50 +05301287
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001288 if (!AR_SREV_5416_20_OR_LATER(ah) ||
Sujithf1dc5602008-10-29 10:16:30 +05301289 AR_SREV_9280_10_OR_LATER(ah))
1290 return;
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001291 /*
1292 * Disable BB clock gating
1293 * Necessary to avoid issues on AR5416 2.0
1294 */
Sujithf1dc5602008-10-29 10:16:30 +05301295 REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
1296}
1297
Sujithcbe61d82009-02-09 13:27:12 +05301298static u32 ath9k_hw_def_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301299 struct ar5416_eeprom_def *pEepData,
Sujithf1dc5602008-10-29 10:16:30 +05301300 u32 reg, u32 value)
1301{
1302 struct base_eep_header *pBase = &(pEepData->baseEepHeader);
1303
Sujithd535a422009-02-09 13:27:06 +05301304 switch (ah->hw_version.devid) {
Sujithf1dc5602008-10-29 10:16:30 +05301305 case AR9280_DEVID_PCI:
1306 if (reg == 0x7894) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001307 DPRINTF(ah, ATH_DBG_EEPROM,
Sujithf1dc5602008-10-29 10:16:30 +05301308 "ini VAL: %x EEPROM: %x\n", value,
1309 (pBase->version & 0xff));
1310
1311 if ((pBase->version & 0xff) > 0x0a) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001312 DPRINTF(ah, ATH_DBG_EEPROM,
Sujithf1dc5602008-10-29 10:16:30 +05301313 "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. Rodriguez4d6b2282009-09-07 04:52:26 -07001319 DPRINTF(ah, ATH_DBG_EEPROM,
Sujithf1dc5602008-10-29 10:16:30 +05301320 "PWDCLKIND Earlier Rev\n");
1321 }
1322
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001323 DPRINTF(ah, ATH_DBG_EEPROM,
Sujithf1dc5602008-10-29 10:16:30 +05301324 "final ini VAL: %x\n", value);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001325 }
Sujithf1dc5602008-10-29 10:16:30 +05301326 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001327 }
1328
Sujithf1dc5602008-10-29 10:16:30 +05301329 return value;
1330}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001331
Sujithcbe61d82009-02-09 13:27:12 +05301332static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301333 struct ar5416_eeprom_def *pEepData,
1334 u32 reg, u32 value)
1335{
Sujith2660b812009-02-09 13:27:26 +05301336 if (ah->eep_map == EEP_MAP_4KBITS)
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301337 return value;
1338 else
1339 return ath9k_hw_def_ini_fixup(ah, pEepData, reg, value);
1340}
1341
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301342static void ath9k_olc_init(struct ath_hw *ah)
1343{
1344 u32 i;
1345
Vivek Natarajandb91f2e2009-08-14 11:27:16 +05301346 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 Balasubramanian8bd1d072009-02-12 13:57:03 +05301361}
1362
Bob Copeland3a702e42009-03-30 22:30:29 -04001363static 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
Sujithcbe61d82009-02-09 13:27:12 +05301378static int ath9k_hw_process_ini(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301379 struct ath9k_channel *chan,
1380 enum ath9k_ht_macmode macmode)
1381{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001382 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301383 int i, regWrites = 0;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001384 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301385 u32 modesIndex, freqIndex;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001386
Sujithf1dc5602008-10-29 10:16:30 +05301387 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);
Sujithf1dc5602008-10-29 10:16:30 +05301415 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
Sujithf74df6f2009-02-09 13:27:24 +05301416 ah->eep_ops->set_addac(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301417
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001418 if (AR_SREV_5416_22_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +05301419 REG_WRITE_ARRAY(&ah->iniAddac, 1, regWrites);
Sujithf1dc5602008-10-29 10:16:30 +05301420 } else {
1421 struct ar5416IniArray temp;
1422 u32 addacSize =
Sujith2660b812009-02-09 13:27:26 +05301423 sizeof(u32) * ah->iniAddac.ia_rows *
1424 ah->iniAddac.ia_columns;
Sujithf1dc5602008-10-29 10:16:30 +05301425
Sujith2660b812009-02-09 13:27:26 +05301426 memcpy(ah->addac5416_21,
1427 ah->iniAddac.ia_array, addacSize);
Sujithf1dc5602008-10-29 10:16:30 +05301428
Sujith2660b812009-02-09 13:27:26 +05301429 (ah->addac5416_21)[31 * ah->iniAddac.ia_columns + 1] = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301430
Sujith2660b812009-02-09 13:27:26 +05301431 temp.ia_array = ah->addac5416_21;
1432 temp.ia_columns = ah->iniAddac.ia_columns;
1433 temp.ia_rows = ah->iniAddac.ia_rows;
Sujithf1dc5602008-10-29 10:16:30 +05301434 REG_WRITE_ARRAY(&temp, 1, regWrites);
1435 }
1436
1437 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
1438
Sujith2660b812009-02-09 13:27:26 +05301439 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);
Sujithf1dc5602008-10-29 10:16:30 +05301442
Sujithf1dc5602008-10-29 10:16:30 +05301443 REG_WRITE(ah, reg, val);
1444
1445 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301446 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301447 udelay(100);
1448 }
1449
1450 DO_DELAY(regWrites);
1451 }
1452
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301453 if (AR_SREV_9280(ah) || AR_SREV_9287_10_OR_LATER(ah))
Sujith2660b812009-02-09 13:27:26 +05301454 REG_WRITE_ARRAY(&ah->iniModesRxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301455
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301456 if (AR_SREV_9280(ah) || AR_SREV_9285_12_OR_LATER(ah) ||
1457 AR_SREV_9287_10_OR_LATER(ah))
Sujith2660b812009-02-09 13:27:26 +05301458 REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301459
Sujith2660b812009-02-09 13:27:26 +05301460 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);
Sujithf1dc5602008-10-29 10:16:30 +05301463
1464 REG_WRITE(ah, reg, val);
1465
1466 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301467 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301468 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)) {
Sujith2660b812009-02-09 13:27:26 +05301477 REG_WRITE_ARRAY(&ah->iniModesAdditional, modesIndex,
Sujithf1dc5602008-10-29 10:16:30 +05301478 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 Balasubramanian8bd1d072009-02-12 13:57:03 +05301485 if (OLC_FOR_AR9280_20_LATER)
1486 ath9k_olc_init(ah);
1487
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001488 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001489 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001490 channel->max_antenna_gain * 2,
1491 channel->max_power * 2,
1492 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001493 (u32) regulatory->power_limit));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001494
Sujithf1dc5602008-10-29 10:16:30 +05301495 if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001496 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +05301497 "ar5416SetRfRegs failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001498 return -EIO;
1499 }
1500
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001501 return 0;
1502}
1503
Sujithf1dc5602008-10-29 10:16:30 +05301504/****************************************/
1505/* Reset and Channel Switching Routines */
1506/****************************************/
1507
Sujithcbe61d82009-02-09 13:27:12 +05301508static void ath9k_hw_set_rfmode(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301509{
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
Sujithcbe61d82009-02-09 13:27:12 +05301528static void ath9k_hw_mark_phy_inactive(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301529{
1530 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
1531}
1532
Sujithcbe61d82009-02-09 13:27:12 +05301533static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301534{
1535 u32 regval;
1536
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001537 /*
1538 * set AHB_MODE not to do cacheline prefetches
1539 */
Sujithf1dc5602008-10-29 10:16:30 +05301540 regval = REG_READ(ah, AR_AHB_MODE);
1541 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
1542
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001543 /*
1544 * let mac dma reads be in 128 byte chunks
1545 */
Sujithf1dc5602008-10-29 10:16:30 +05301546 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
1547 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
1548
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001549 /*
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 */
Sujith2660b812009-02-09 13:27:26 +05301554 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +05301555
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001556 /*
1557 * let mac dma writes be in 128 byte chunks
1558 */
Sujithf1dc5602008-10-29 10:16:30 +05301559 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
1560 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
1561
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001562 /*
1563 * Setup receive FIFO threshold to hold off TX activities
1564 */
Sujithf1dc5602008-10-29 10:16:30 +05301565 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1566
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001567 /*
1568 * reduce the number of usable entries in PCU TXBUF to avoid
1569 * wrap around issues.
1570 */
Sujithf1dc5602008-10-29 10:16:30 +05301571 if (AR_SREV_9285(ah)) {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001572 /* 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 */
Sujithf1dc5602008-10-29 10:16:30 +05301576 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1577 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001578 } else if (!AR_SREV_9271(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +05301579 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1580 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1581 }
1582}
1583
Sujithcbe61d82009-02-09 13:27:12 +05301584static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301585{
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 McCabed97809d2008-12-01 13:38:55 -08001591 case NL80211_IFTYPE_AP:
Sujithf1dc5602008-10-29 10:16:30 +05301592 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 McCabed97809d2008-12-01 13:38:55 -08001596 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04001597 case NL80211_IFTYPE_MESH_POINT:
Sujithf1dc5602008-10-29 10:16:30 +05301598 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 McCabed97809d2008-12-01 13:38:55 -08001602 case NL80211_IFTYPE_STATION:
1603 case NL80211_IFTYPE_MONITOR:
Sujithf1dc5602008-10-29 10:16:30 +05301604 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
1605 break;
1606 }
1607}
1608
Sujithcbe61d82009-02-09 13:27:12 +05301609static inline void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001610 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
Sujithcbe61d82009-02-09 13:27:12 +05301628static void ath9k_hw_set_delta_slope(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301629 struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001630{
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, &centers);
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
Sujithcbe61d82009-02-09 13:27:12 +05301662static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +05301663{
1664 u32 rst_flags;
1665 u32 tmpReg;
1666
Sujith70768492009-02-16 13:23:12 +05301667 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
Sujithf1dc5602008-10-29 10:16:30 +05301675 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 Juhosd03a66c2009-01-14 20:17:09 +01001697 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujithf1dc5602008-10-29 10:16:30 +05301698 udelay(50);
1699
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001700 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301701 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001702 DPRINTF(ah, ATH_DBG_RESET,
Sujith04bd46382008-11-28 22:18:05 +05301703 "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301704 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
Sujithcbe61d82009-02-09 13:27:12 +05301718static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301719{
1720 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1721 AR_RTC_FORCE_WAKE_ON_INT);
1722
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301723 if (!AR_SREV_9100(ah))
1724 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1725
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001726 REG_WRITE(ah, AR_RTC_RESET, 0);
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301727 udelay(2);
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301728
1729 if (!AR_SREV_9100(ah))
1730 REG_WRITE(ah, AR_RC, 0);
1731
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001732 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301733
1734 if (!ath9k_hw_wait(ah,
1735 AR_RTC_STATUS,
1736 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301737 AR_RTC_STATUS_ON,
1738 AH_WAIT_TIMEOUT)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001739 DPRINTF(ah, ATH_DBG_RESET, "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301740 return false;
1741 }
1742
1743 ath9k_hw_read_revisions(ah);
1744
1745 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1746}
1747
Sujithcbe61d82009-02-09 13:27:12 +05301748static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301749{
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);
Sujithf1dc5602008-10-29 10:16:30 +05301756 case ATH9K_RESET_WARM:
1757 case ATH9K_RESET_COLD:
1758 return ath9k_hw_set_reset(ah, type);
Sujithf1dc5602008-10-29 10:16:30 +05301759 default:
1760 return false;
1761 }
1762}
1763
Sujithcbe61d82009-02-09 13:27:12 +05301764static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan,
Sujithf1dc5602008-10-29 10:16:30 +05301765 enum ath9k_ht_macmode macmode)
1766{
1767 u32 phymode;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301768 u32 enableDacFifo = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301769
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301770 if (AR_SREV_9285_10_OR_LATER(ah))
1771 enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) &
1772 AR_PHY_FC_ENABLE_DAC_FIFO);
1773
Sujithf1dc5602008-10-29 10:16:30 +05301774 phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301775 | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo;
Sujithf1dc5602008-10-29 10:16:30 +05301776
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
Sujith2660b812009-02-09 13:27:26 +05301784 if (ah->extprotspacing == ATH9K_HT_EXTPROTSPACING_25)
Sujithf1dc5602008-10-29 10:16:30 +05301785 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
Sujithcbe61d82009-02-09 13:27:12 +05301795static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301796 struct ath9k_channel *chan)
1797{
Vivek Natarajan42abfbe2009-09-17 09:27:59 +05301798 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) {
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301799 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))
Sujithf1dc5602008-10-29 10:16:30 +05301802 return false;
1803
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001804 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05301805 return false;
1806
Sujith2660b812009-02-09 13:27:26 +05301807 ah->chip_fullsleep = false;
Sujithf1dc5602008-10-29 10:16:30 +05301808 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301809 ath9k_hw_set_rfmode(ah, chan);
1810
1811 return true;
1812}
1813
Sujithcbe61d82009-02-09 13:27:12 +05301814static bool ath9k_hw_channel_change(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301815 struct ath9k_channel *chan,
1816 enum ath9k_ht_macmode macmode)
1817{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001818 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001819 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301820 u32 synthDelay, qnum;
1821
1822 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1823 if (ath9k_hw_numtxpending(ah, qnum)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001824 DPRINTF(ah, ATH_DBG_QUEUE,
Sujith04bd46382008-11-28 22:18:05 +05301825 "Transmit frames pending on queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301826 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,
Sujith0caa7b12009-02-16 13:23:20 +05301832 AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001833 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +05301834 "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301835 return false;
1836 }
1837
1838 ath9k_hw_set_regs(ah, chan, macmode);
1839
1840 if (AR_SREV_9280_10_OR_LATER(ah)) {
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001841 ath9k_hw_ar9280_set_channel(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301842 } else {
1843 if (!(ath9k_hw_set_channel(ah, chan))) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001844 DPRINTF(ah, ATH_DBG_FATAL,
Sujithd8baa932009-03-30 15:28:25 +05301845 "Failed to set channel\n");
Sujithf1dc5602008-10-29 10:16:30 +05301846 return false;
1847 }
1848 }
1849
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001850 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001851 ath9k_regd_get_ctl(regulatory, chan),
Sujithf74df6f2009-02-09 13:27:24 +05301852 channel->max_antenna_gain * 2,
1853 channel->max_power * 2,
1854 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001855 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05301856
1857 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +05301858 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +05301859 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
Sujithcbe61d82009-02-09 13:27:12 +05301881static void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001882{
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, &centers);
1913 freq = centers.synth_center;
1914
Sujith2660b812009-02-09 13:27:26 +05301915 ah->config.spurmode = SPUR_ENABLE_EEPROM;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001916 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujithf74df6f2009-02-09 13:27:24 +05301917 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001918
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 Bunkb08cbcd2008-08-05 22:06:51 +03002026
2027 /* workaround for gcc bug #37014 */
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002028 volatile int tmp_v = abs(cur_vit_mask - bin);
Adrian Bunkb08cbcd2008-08-05 22:06:51 +03002029
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002030 if (tmp_v < 75)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002031 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
Sujithcbe61d82009-02-09 13:27:12 +05302131static void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002132{
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++) {
Sujithf74df6f2009-02-09 13:27:24 +05302160 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002161 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 Bunk88b9e2b2008-08-05 22:06:51 +03002227
2228 /* workaround for gcc bug #37014 */
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002229 volatile int tmp_v = abs(cur_vit_mask - bin);
Adrian Bunk88b9e2b2008-08-05 22:06:51 +03002230
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002231 if (tmp_v < 75)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002232 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 Berg3b319aa2009-06-13 14:50:26 +05302332static 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
Sujithcbe61d82009-02-09 13:27:12 +05302344int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002345 bool bChannelChange)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002346{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002347 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002348 u32 saveLedState;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002349 struct ath_softc *sc = ah->ah_sc;
Sujith2660b812009-02-09 13:27:26 +05302350 struct ath9k_channel *curchan = ah->curchan;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002351 u32 saveDefAntenna;
2352 u32 macStaId1;
Sujith46fe7822009-09-17 09:25:25 +05302353 u64 tsf = 0;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002354 int i, rx_chainmask, r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002355
Sujith2660b812009-02-09 13:27:26 +05302356 ah->extprotspacing = sc->ht_extprotspacing;
2357 ah->txchainmask = sc->tx_chainmask;
2358 ah->rxchainmask = sc->rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002359
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002360 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002361 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002362
Vasanthakumar Thiagarajan9ebef7992009-09-17 09:26:44 +05302363 if (curchan && !ah->chip_fullsleep)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002364 ath9k_hw_getnf(ah, curchan);
2365
2366 if (bChannelChange &&
Sujith2660b812009-02-09 13:27:26 +05302367 (ah->chip_fullsleep != true) &&
2368 (ah->curchan != NULL) &&
2369 (chan->channel != ah->curchan->channel) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002370 ((chan->channelFlags & CHANNEL_ALL) ==
Sujith2660b812009-02-09 13:27:26 +05302371 (ah->curchan->channelFlags & CHANNEL_ALL)) &&
Vasanthakumar Thiagarajan0a475cc2009-09-17 09:27:10 +05302372 !(AR_SREV_9280(ah) || IS_CHAN_A_5MHZ_SPACED(chan) ||
2373 IS_CHAN_A_5MHZ_SPACED(ah->curchan))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002374
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002375 if (ath9k_hw_channel_change(ah, chan, sc->tx_chan_width)) {
Sujith2660b812009-02-09 13:27:26 +05302376 ath9k_hw_loadnf(ah, ah->curchan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002377 ath9k_hw_start_nfcal(ah);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002378 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002379 }
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
Sujith46fe7822009-09-17 09:25:25 +05302388 /* 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. Rodriguezf078f202008-08-04 00:16:41 -07002392 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. Rodriguezd7e7d222009-08-03 23:14:12 -04002398 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. Rodriguezf078f202008-08-04 00:16:41 -07002405 if (!ath9k_hw_chip_reset(ah, chan)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002406 DPRINTF(ah, ATH_DBG_FATAL, "Chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002407 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002408 }
2409
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002410 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
Sujith46fe7822009-09-17 09:25:25 +05302418 /* 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 Thiagarajan369391d2009-01-21 19:24:13 +05302422 if (AR_SREV_9280_10_OR_LATER(ah))
2423 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002424
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302425 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302426 /* 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. Rodriguezae8d2852008-12-23 15:58:40 -08002435 r = ath9k_hw_process_ini(ah, chan, sc->tx_chan_width);
2436 if (r)
2437 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002438
Jouni Malinen0ced0e12009-01-08 13:32:13 +02002439 /* 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. Rodriguezf078f202008-08-04 00:16:41 -07002456 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
Sujithd6509152009-03-13 08:56:05 +05302464 ah->eep_ops->set_board_values(ah, chan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002465
2466 ath9k_hw_decrease_chain_power(ah, chan);
2467
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002468 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. Rodriguezf078f202008-08-04 00:16:41 -07002470 | macStaId1
2471 | AR_STA_ID1_RTS_USE_DEF
Sujith2660b812009-02-09 13:27:26 +05302472 | (ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302473 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Sujith2660b812009-02-09 13:27:26 +05302474 | ah->sta_id1_defaults);
2475 ath9k_hw_set_operating_mode(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002476
Luis R. Rodriguez76640722009-09-10 08:54:56 -07002477 ath9k_hw_setbssidmask(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002478
2479 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
2480
Luis R. Rodriguez3453ad82009-09-10 08:57:00 -07002481 ath9k_hw_write_associd(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002482
2483 REG_WRITE(ah, AR_ISR, ~0);
2484
2485 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
2486
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07002487 if (AR_SREV_9280_10_OR_LATER(ah))
2488 ath9k_hw_ar9280_set_channel(ah, chan);
2489 else
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002490 if (!(ath9k_hw_set_channel(ah, chan)))
2491 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002492
2493 for (i = 0; i < AR_NUM_DCU; i++)
2494 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
2495
Sujith2660b812009-02-09 13:27:26 +05302496 ah->intr_txqs = 0;
2497 for (i = 0; i < ah->caps.total_queues; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002498 ath9k_hw_resettxqueue(ah, i);
2499
Sujith2660b812009-02-09 13:27:26 +05302500 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002501 ath9k_hw_init_qos(ah);
2502
Sujith2660b812009-02-09 13:27:26 +05302503 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05302504 ath9k_enable_rfkill(ah);
Johannes Berg3b319aa2009-06-13 14:50:26 +05302505
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002506 ath9k_hw_init_user_settings(ah);
2507
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302508 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302509 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 Natarajan326bebb2009-08-14 11:33:36 +05302524 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302525 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
2526 AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
2527 }
2528
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002529 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
Sujith0ef1f162009-03-30 15:28:35 +05302536 if (ah->config.intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002537 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. Rodriguezae8d2852008-12-23 15:58:40 -08002543 if (!ath9k_hw_init_cal(ah, chan))
Joe Perches6badaaf2009-06-28 09:26:32 -07002544 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002545
Sujith2660b812009-02-09 13:27:26 +05302546 rx_chainmask = ah->rxchainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002547 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. Rodriguezd7e7d222009-08-03 23:14:12 -04002554 /*
2555 * For big endian systems turn on swapping for descriptors
2556 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002557 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. Rodriguez4d6b2282009-09-07 04:52:26 -07002561 DPRINTF(ah, ATH_DBG_RESET,
Sujith04bd46382008-11-28 22:18:05 +05302562 "CFG Byte Swap Set 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002563 } else {
2564 mask =
2565 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
2566 REG_WRITE(ah, AR_CFG, mask);
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002567 DPRINTF(ah, ATH_DBG_RESET,
Sujith04bd46382008-11-28 22:18:05 +05302568 "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002569 }
2570 } else {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002571 /* Configure AR9271 target WLAN */
2572 if (AR_SREV_9271(ah))
2573 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002574#ifdef __BIG_ENDIAN
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002575 else
2576 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002577#endif
2578 }
2579
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002580 if (ah->btcoex_hw.enabled)
Vasanthakumar Thiagarajan42cc41e2009-08-26 21:08:45 +05302581 ath9k_hw_btcoex_enable(ah);
2582
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002583 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002584}
2585
Sujithf1dc5602008-10-29 10:16:30 +05302586/************************/
2587/* Key Cache Management */
2588/************************/
2589
Sujithcbe61d82009-02-09 13:27:12 +05302590bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002591{
Sujithf1dc5602008-10-29 10:16:30 +05302592 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002593
Sujith2660b812009-02-09 13:27:26 +05302594 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002595 DPRINTF(ah, ATH_DBG_FATAL,
Sujithd8baa932009-03-30 15:28:25 +05302596 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002597 return false;
2598 }
2599
Sujithf1dc5602008-10-29 10:16:30 +05302600 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002601
Sujithf1dc5602008-10-29 10:16:30 +05302602 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. Rodriguezf078f202008-08-04 00:16:41 -07002619 }
2620
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002621 return true;
2622}
2623
Sujithcbe61d82009-02-09 13:27:12 +05302624bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002625{
Sujithf1dc5602008-10-29 10:16:30 +05302626 u32 macHi, macLo;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002627
Sujith2660b812009-02-09 13:27:26 +05302628 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002629 DPRINTF(ah, ATH_DBG_FATAL,
Sujithd8baa932009-03-30 15:28:25 +05302630 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002631 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002632 }
2633
Sujithf1dc5602008-10-29 10:16:30 +05302634 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. Rodriguezf078f202008-08-04 00:16:41 -07002643 } else {
Sujithf1dc5602008-10-29 10:16:30 +05302644 macLo = macHi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002645 }
Sujithf1dc5602008-10-29 10:16:30 +05302646 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
2647 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002648
2649 return true;
2650}
2651
Sujithcbe61d82009-02-09 13:27:12 +05302652bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
Sujithf1dc5602008-10-29 10:16:30 +05302653 const struct ath9k_keyval *k,
Jouni Malinene0caf9e2009-03-02 18:15:53 +02002654 const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002655{
Sujith2660b812009-02-09 13:27:26 +05302656 const struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +05302657 u32 key0, key1, key2, key3, key4;
2658 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002659
Sujithf1dc5602008-10-29 10:16:30 +05302660 if (entry >= pCap->keycache_size) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002661 DPRINTF(ah, ATH_DBG_FATAL,
Sujithd8baa932009-03-30 15:28:25 +05302662 "keycache entry %u out of range\n", entry);
Sujithf1dc5602008-10-29 10:16:30 +05302663 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. Rodriguez4d6b2282009-09-07 04:52:26 -07002672 DPRINTF(ah, ATH_DBG_ANY,
Sujith04bd46382008-11-28 22:18:05 +05302673 "AES-CCM not supported by mac rev 0x%x\n",
Sujithd535a422009-02-09 13:27:06 +05302674 ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002675 return false;
2676 }
Sujithf1dc5602008-10-29 10:16:30 +05302677 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. Rodriguez4d6b2282009-09-07 04:52:26 -07002683 DPRINTF(ah, ATH_DBG_ANY,
Sujith04bd46382008-11-28 22:18:05 +05302684 "entry %u inappropriate for TKIP\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002685 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002686 }
Sujithf1dc5602008-10-29 10:16:30 +05302687 break;
2688 case ATH9K_CIPHER_WEP:
Zhu Yie31a16d2009-05-21 21:47:03 +08002689 if (k->kv_len < WLAN_KEY_LEN_WEP40) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002690 DPRINTF(ah, ATH_DBG_ANY,
Sujith04bd46382008-11-28 22:18:05 +05302691 "WEP key length %u too small\n", k->kv_len);
Sujithf1dc5602008-10-29 10:16:30 +05302692 return false;
2693 }
Zhu Yie31a16d2009-05-21 21:47:03 +08002694 if (k->kv_len <= WLAN_KEY_LEN_WEP40)
Sujithf1dc5602008-10-29 10:16:30 +05302695 keyType = AR_KEYTABLE_TYPE_40;
Zhu Yie31a16d2009-05-21 21:47:03 +08002696 else if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05302697 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. Rodriguezf078f202008-08-04 00:16:41 -07002704 default:
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002705 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +05302706 "cipher %u not supported\n", k->kv_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002707 return false;
2708 }
Sujithf1dc5602008-10-29 10:16:30 +05302709
Jouni Malinene0caf9e2009-03-02 18:15:53 +02002710 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 Yie31a16d2009-05-21 21:47:03 +08002715 if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05302716 key4 &= 0xff;
2717
Jouni Malinen672903b2009-03-02 15:06:31 +02002718 /*
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
Sujithf1dc5602008-10-29 10:16:30 +05302725 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2726 u16 micentry = entry + 64;
2727
Jouni Malinen672903b2009-03-02 15:06:31 +02002728 /*
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 */
Sujithf1dc5602008-10-29 10:16:30 +05302734 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
2735 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002736
2737 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302738 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2739 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002740
2741 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302742 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2743 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
Jouni Malinen672903b2009-03-02 15:06:31 +02002744
2745 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302746 (void) ath9k_hw_keysetmac(ah, entry, mac);
2747
Sujith2660b812009-02-09 13:27:26 +05302748 if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) {
Jouni Malinen672903b2009-03-02 15:06:31 +02002749 /*
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 */
Sujithf1dc5602008-10-29 10:16:30 +05302761 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 Malinen672903b2009-03-02 15:06:31 +02002768
2769 /* Write RX[31:0] and TX[31:16] */
Sujithf1dc5602008-10-29 10:16:30 +05302770 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2771 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002772
2773 /* Write RX[63:32] and TX[15:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302774 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2775 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002776
2777 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302778 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 Malinen672903b2009-03-02 15:06:31 +02002783 /*
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 */
Sujithf1dc5602008-10-29 10:16:30 +05302799 u32 mic0, mic2;
2800
2801 mic0 = get_unaligned_le32(k->kv_mic + 0);
2802 mic2 = get_unaligned_le32(k->kv_mic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02002803
2804 /* Write MIC key[31:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302805 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2806 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002807
2808 /* Write MIC key[63:32] */
Sujithf1dc5602008-10-29 10:16:30 +05302809 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2810 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002811
2812 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302813 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
2814 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2815 AR_KEYTABLE_TYPE_CLR);
2816 }
Jouni Malinen672903b2009-03-02 15:06:31 +02002817
2818 /* MAC address registers are reserved for the MIC entry */
Sujithf1dc5602008-10-29 10:16:30 +05302819 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
2820 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002821
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 */
Sujithf1dc5602008-10-29 10:16:30 +05302827 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2828 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
2829 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002830 /* Write key[47:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302831 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2832 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002833
2834 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302835 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2836 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002837
2838 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302839 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2840 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
2841
Jouni Malinen672903b2009-03-02 15:06:31 +02002842 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302843 (void) ath9k_hw_keysetmac(ah, entry, mac);
2844 }
2845
Sujithf1dc5602008-10-29 10:16:30 +05302846 return true;
2847}
2848
Sujithcbe61d82009-02-09 13:27:12 +05302849bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry)
Sujithf1dc5602008-10-29 10:16:30 +05302850{
Sujith2660b812009-02-09 13:27:26 +05302851 if (entry < ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05302852 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
Sujithcbe61d82009-02-09 13:27:12 +05302863static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302864{
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 Juhosd03a66c2009-01-14 20:17:09 +01002872 REG_CLR_BIT(ah, (AR_RTC_RESET),
Sujithf1dc5602008-10-29 10:16:30 +05302873 AR_RTC_RESET_EN);
2874 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002875}
2876
Sujithcbe61d82009-02-09 13:27:12 +05302877static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002878{
Sujithf1dc5602008-10-29 10:16:30 +05302879 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2880 if (setChip) {
Sujith2660b812009-02-09 13:27:26 +05302881 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002882
Sujithf1dc5602008-10-29 10:16:30 +05302883 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. Rodriguezf078f202008-08-04 00:16:41 -07002892
Sujithcbe61d82009-02-09 13:27:12 +05302893static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302894{
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. Rodriguez4d6b2282009-09-07 04:52:26 -07002923 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +05302924 "Failed to wakeup in %uus\n", POWER_UP_TIME / 20);
Sujithf1dc5602008-10-29 10:16:30 +05302925 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002926 }
2927 }
2928
Sujithf1dc5602008-10-29 10:16:30 +05302929 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2930
2931 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002932}
2933
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002934bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05302935{
Sujithcbe61d82009-02-09 13:27:12 +05302936 int status = true, setChip = true;
Sujithf1dc5602008-10-29 10:16:30 +05302937 static const char *modes[] = {
2938 "AWAKE",
2939 "FULL-SLEEP",
2940 "NETWORK SLEEP",
2941 "UNDEFINED"
2942 };
Sujithf1dc5602008-10-29 10:16:30 +05302943
Gabor Juhoscbdec972009-07-24 17:27:22 +02002944 if (ah->power_mode == mode)
2945 return status;
2946
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002947 DPRINTF(ah, ATH_DBG_RESET, "%s -> %s\n",
Sujithd8baa932009-03-30 15:28:25 +05302948 modes[ah->power_mode], modes[mode]);
Sujithf1dc5602008-10-29 10:16:30 +05302949
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);
Sujith2660b812009-02-09 13:27:26 +05302956 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05302957 break;
2958 case ATH9K_PM_NETWORK_SLEEP:
2959 ath9k_set_power_network_sleep(ah, setChip);
2960 break;
2961 default:
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002962 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +05302963 "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05302964 return false;
2965 }
Sujith2660b812009-02-09 13:27:26 +05302966 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05302967
2968 return status;
2969}
2970
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002971/*
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 Natarajan93b1b372009-09-17 09:24:58 +05302980void ath9k_hw_configpcipowersave(struct ath_hw *ah, int restore, int power_off)
Sujithf1dc5602008-10-29 10:16:30 +05302981{
Sujithf1dc5602008-10-29 10:16:30 +05302982 u8 i;
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302983 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05302984
Sujith2660b812009-02-09 13:27:26 +05302985 if (ah->is_pciexpress != true)
Sujithf1dc5602008-10-29 10:16:30 +05302986 return;
2987
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002988 /* Do not touch SerDes registers */
Sujith2660b812009-02-09 13:27:26 +05302989 if (ah->config.pcie_powersave_enable == 2)
Sujithf1dc5602008-10-29 10:16:30 +05302990 return;
2991
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002992 /* Nothing to do on restore for 11N */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302993 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);
Sujithf1dc5602008-10-29 10:16:30 +05303008
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303009 /* 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);
Sujithf1dc5602008-10-29 10:16:30 +05303048 }
Sujithf1dc5602008-10-29 10:16:30 +05303049
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303050 udelay(1000);
Sujithf1dc5602008-10-29 10:16:30 +05303051
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303052 /* 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);
Sujithf1dc5602008-10-29 10:16:30 +05303054
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303055 /* 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 }
Sujithf1dc5602008-10-29 10:16:30 +05303077
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303078 REG_WRITE(ah, AR_WA, val);
Sujithf1dc5602008-10-29 10:16:30 +05303079 }
3080
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303081 if (power_off) {
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08003082 /*
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303083 * 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. Rodriguez24c1a282009-02-10 15:35:22 -08003087 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303088 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 }
Sujithf1dc5602008-10-29 10:16:30 +05303100 }
3101}
3102
3103/**********************/
3104/* Interrupt Handling */
3105/**********************/
3106
Sujithcbe61d82009-02-09 13:27:12 +05303107bool ath9k_hw_intrpend(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003108{
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
Sujithcbe61d82009-02-09 13:27:12 +05303126bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003127{
3128 u32 isr = 0;
3129 u32 mask2 = 0;
Sujith2660b812009-02-09 13:27:26 +05303130 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003131 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
Sujithf1dc5602008-10-29 10:16:30 +05303142 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
3143 AR_INTR_SYNC_DEFAULT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003144
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. Rodriguezf078f202008-08-04 00:16:41 -07003155 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;
Sujith4af9cf42009-02-12 10:06:47 +05303170 if (isr2 & AR_ISR_S2_TSFOOR)
3171 mask2 |= ATH9K_INT_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003172 }
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
Sujith0ef1f162009-03-30 15:28:35 +05303182 if (ah->config.intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003183 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);
Sujith2660b812009-02-09 13:27:26 +05303197 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. Rodriguezf078f202008-08-04 00:16:41 -07003199
3200 s1_s = REG_READ(ah, AR_ISR_S1_S);
Sujith2660b812009-02-09 13:27:26 +05303201 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. Rodriguezf078f202008-08-04 00:16:41 -07003203 }
3204
3205 if (isr & AR_ISR_RXORN) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07003206 DPRINTF(ah, ATH_DBG_INTERRUPT,
Sujith04bd46382008-11-28 22:18:05 +05303207 "receive FIFO overrun interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003208 }
3209
3210 if (!AR_SREV_9100(ah)) {
Sujith60b67f52008-08-07 10:52:38 +05303211 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003212 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 }
Sujithf1dc5602008-10-29 10:16:30 +05303220
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003221 if (AR_SREV_9100(ah))
3222 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303223
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303224 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. Rodriguezf078f202008-08-04 00:16:41 -07003241 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. Rodriguez4d6b2282009-09-07 04:52:26 -07003249 DPRINTF(ah, ATH_DBG_ANY,
Sujith04bd46382008-11-28 22:18:05 +05303250 "received PCI FATAL interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003251 }
3252 if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07003253 DPRINTF(ah, ATH_DBG_ANY,
Sujith04bd46382008-11-28 22:18:05 +05303254 "received PCI PERR interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003255 }
Steven Luoa89bff92009-04-12 02:57:54 -07003256 *masked |= ATH9K_INT_FATAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003257 }
3258 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07003259 DPRINTF(ah, ATH_DBG_INTERRUPT,
Sujith04bd46382008-11-28 22:18:05 +05303260 "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003261 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. Rodriguez4d6b2282009-09-07 04:52:26 -07003266 DPRINTF(ah, ATH_DBG_INTERRUPT,
Sujith04bd46382008-11-28 22:18:05 +05303267 "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003268 }
3269
3270 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
3271 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
3272 }
Sujithf1dc5602008-10-29 10:16:30 +05303273
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003274 return true;
3275}
3276
Sujithcbe61d82009-02-09 13:27:12 +05303277enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003278{
Sujith2660b812009-02-09 13:27:26 +05303279 u32 omask = ah->mask_reg;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003280 u32 mask, mask2;
Sujith2660b812009-02-09 13:27:26 +05303281 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003282
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07003283 DPRINTF(ah, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003284
3285 if (omask & ATH9K_INT_GLOBAL) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07003286 DPRINTF(ah, ATH_DBG_INTERRUPT, "disable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003287 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) {
Sujith2660b812009-02-09 13:27:26 +05303302 if (ah->txok_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003303 mask |= AR_IMR_TXOK;
Sujith2660b812009-02-09 13:27:26 +05303304 if (ah->txdesc_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003305 mask |= AR_IMR_TXDESC;
Sujith2660b812009-02-09 13:27:26 +05303306 if (ah->txerr_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003307 mask |= AR_IMR_TXERR;
Sujith2660b812009-02-09 13:27:26 +05303308 if (ah->txeol_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003309 mask |= AR_IMR_TXEOL;
3310 }
3311 if (ints & ATH9K_INT_RX) {
3312 mask |= AR_IMR_RXERR;
Sujith0ef1f162009-03-30 15:28:35 +05303313 if (ah->config.intr_mitigation)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003314 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
3315 else
3316 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
Sujith60b67f52008-08-07 10:52:38 +05303317 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003318 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)
Sujith4af9cf42009-02-12 10:06:47 +05303330 mask2 |= AR_IMR_S2_CABEND;
3331 if (ints & ATH9K_INT_TSFOOR)
3332 mask2 |= AR_IMR_S2_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003333 }
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. Rodriguez4d6b2282009-09-07 04:52:26 -07003343 DPRINTF(ah, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003344 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);
Sujith2660b812009-02-09 13:27:26 +05303353 ah->mask_reg = ints;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003354
Sujith60b67f52008-08-07 10:52:38 +05303355 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003356 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. Rodriguez4d6b2282009-09-07 04:52:26 -07003363 DPRINTF(ah, ATH_DBG_INTERRUPT, "enable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003364 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. Rodriguez4d6b2282009-09-07 04:52:26 -07003376 DPRINTF(ah, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003377 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
3378 }
3379
3380 return omask;
3381}
3382
Sujithf1dc5602008-10-29 10:16:30 +05303383/*******************/
3384/* Beacon Handling */
3385/*******************/
3386
Sujithcbe61d82009-02-09 13:27:12 +05303387void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003388{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003389 int flags = 0;
3390
Sujith2660b812009-02-09 13:27:26 +05303391 ah->beacon_interval = beacon_period;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003392
Sujith2660b812009-02-09 13:27:26 +05303393 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08003394 case NL80211_IFTYPE_STATION:
3395 case NL80211_IFTYPE_MONITOR:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003396 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 McCabed97809d2008-12-01 13:38:55 -08003401 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04003402 case NL80211_IFTYPE_MESH_POINT:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003403 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 +
Sujith2660b812009-02-09 13:27:26 +05303407 (ah->atim_window ? ah->
3408 atim_window : 1)));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003409 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08003410 case NL80211_IFTYPE_AP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003411 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 -
Sujith2660b812009-02-09 13:27:26 +05303414 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05303415 dma_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003416 REG_WRITE(ah, AR_NEXT_SWBA,
3417 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05303418 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05303419 sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003420 flags |=
3421 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
3422 break;
Colin McCabed97809d2008-12-01 13:38:55 -08003423 default:
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07003424 DPRINTF(ah, ATH_DBG_BEACON,
Colin McCabed97809d2008-12-01 13:38:55 -08003425 "%s: unsupported opmode: %d\n",
Sujith2660b812009-02-09 13:27:26 +05303426 __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08003427 return;
3428 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003429 }
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
Sujithcbe61d82009-02-09 13:27:12 +05303445void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303446 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003447{
3448 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05303449 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003450
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. Rodriguez4d6b2282009-09-07 04:52:26 -07003475 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. Rodriguezf078f202008-08-04 00:16:41 -07003479
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
Sujith60b67f52008-08-07 10:52:38 +05303488 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003489 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
Sujith4af9cf42009-02-12 10:06:47 +05303503 /* TSF Out of Range Threshold */
3504 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003505}
3506
Sujithf1dc5602008-10-29 10:16:30 +05303507/*******************/
3508/* HW Capabilities */
3509/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003510
Sujitheef7a572009-03-30 15:28:28 +05303511void ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003512{
Sujith2660b812009-02-09 13:27:26 +05303513 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003514 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003515 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003516
Sujithf1dc5602008-10-29 10:16:30 +05303517 u16 capField = 0, eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003518
Sujithf74df6f2009-02-09 13:27:24 +05303519 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003520 regulatory->current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303521
Sujithf74df6f2009-02-09 13:27:24 +05303522 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
Sujithfec0de12009-02-12 10:06:43 +05303523 if (AR_SREV_9285_10_OR_LATER(ah))
3524 eeval |= AR9285_RDEXT_DEFAULT;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003525 regulatory->current_rd_ext = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303526
Sujithf74df6f2009-02-09 13:27:24 +05303527 capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
Sujithf1dc5602008-10-29 10:16:30 +05303528
Sujith2660b812009-02-09 13:27:26 +05303529 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05303530 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003531 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. Rodriguez4d6b2282009-09-07 04:52:26 -07003536 DPRINTF(ah, ATH_DBG_REGULATORY,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003537 "regdomain mapped to 0x%x\n", regulatory->current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003538 }
Sujithdc2222a2008-08-14 13:26:55 +05303539
Sujithf74df6f2009-02-09 13:27:24 +05303540 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Sujithf1dc5602008-10-29 10:16:30 +05303541 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003542
Sujithf1dc5602008-10-29 10:16:30 +05303543 if (eeval & AR5416_OPFLAGS_11A) {
3544 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303545 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303546 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. Rodriguezf078f202008-08-04 00:16:41 -07003554 }
3555 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003556 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003557
Sujithf1dc5602008-10-29 10:16:30 +05303558 if (eeval & AR5416_OPFLAGS_11G) {
Sujithf1dc5602008-10-29 10:16:30 +05303559 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303560 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303561 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. Rodriguez6f255422008-10-03 15:45:27 -07003571 }
Sujithf1dc5602008-10-29 10:16:30 +05303572
Sujithf74df6f2009-02-09 13:27:24 +05303573 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003574 /*
3575 * For AR9271 we will temporarilly uses the rx chainmax as read from
3576 * the EEPROM.
3577 */
Sujith8147f5d2009-02-20 15:13:23 +05303578 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003579 !(eeval & AR5416_OPFLAGS_11A) &&
3580 !(AR_SREV_9271(ah)))
3581 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
Sujith8147f5d2009-02-20 15:13:23 +05303582 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
3583 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003584 /* Use rx_chainmask from EEPROM. */
Sujith8147f5d2009-02-20 15:13:23 +05303585 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05303586
Sujithd535a422009-02-09 13:27:06 +05303587 if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0)))
Sujith2660b812009-02-09 13:27:26 +05303588 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05303589
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
Sujith2660b812009-02-09 13:27:26 +05303604 if (ah->config.ht_enable)
Sujithf1dc5602008-10-29 10:16:30 +05303605 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;
Sujithf1dc5602008-10-29 10:16:30 +05303627 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
3628
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303629 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))
Sujithf1dc5602008-10-29 10:16:30 +05303632 pCap->num_gpio_pins = AR928X_NUM_GPIO;
3633 else
3634 pCap->num_gpio_pins = AR_NUM_GPIO;
3635
Sujithf1dc5602008-10-29 10:16:30 +05303636 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 Balasubramaniane97275c2008-11-13 18:00:02 +05303645#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05303646 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);
Sujithf1dc5602008-10-29 10:16:30 +05303652
3653 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
3654 }
3655#endif
3656
Vivek Natarajana3ca95fb2009-09-17 09:29:07 +05303657 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
Sujithf1dc5602008-10-29 10:16:30 +05303658
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05303659 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303660 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
3661 else
3662 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
3663
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003664 if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) {
Sujithf1dc5602008-10-29 10:16:30 +05303665 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 =
Sujithf74df6f2009-02-09 13:27:24 +05303679 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303680 pCap->num_antcfg_2ghz =
Sujithf74df6f2009-02-09 13:27:24 +05303681 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303682
Vasanthakumar Thiagarajanfe129462009-09-09 15:25:50 +05303683 if (AR_SREV_9280_10_OR_LATER(ah) &&
Luis R. Rodrigueza36cfbc2009-09-09 16:05:32 -07003684 ath9k_hw_btcoex_supported(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003685 btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO;
3686 btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO;
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05303687
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303688 if (AR_SREV_9285(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003689 btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
3690 btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303691 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003692 btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303693 }
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05303694 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003695 btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE;
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303696 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003697}
3698
Sujithcbe61d82009-02-09 13:27:12 +05303699bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303700 u32 capability, u32 *result)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003701{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003702 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05303703 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:
Sujith2660b812009-02-09 13:27:26 +05303721 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303722 AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
3723 false;
3724 }
3725 case ATH9K_CAP_TKIP_SPLIT:
Sujith2660b812009-02-09 13:27:26 +05303726 return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ?
Sujithf1dc5602008-10-29 10:16:30 +05303727 false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303728 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;
Sujithf1dc5602008-10-29 10:16:30 +05303732 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 {
Sujith2660b812009-02-09 13:27:26 +05303740 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303741 AR_STA_ID1_MCAST_KSRCH) ? true :
3742 false;
3743 }
3744 }
3745 return false;
Sujithf1dc5602008-10-29 10:16:30 +05303746 case ATH9K_CAP_TXPOW:
3747 switch (capability) {
3748 case 0:
3749 return 0;
3750 case 1:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003751 *result = regulatory->power_limit;
Sujithf1dc5602008-10-29 10:16:30 +05303752 return 0;
3753 case 2:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003754 *result = regulatory->max_power_level;
Sujithf1dc5602008-10-29 10:16:30 +05303755 return 0;
3756 case 3:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003757 *result = regulatory->tp_scale;
Sujithf1dc5602008-10-29 10:16:30 +05303758 return 0;
3759 }
3760 return false;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05303761 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;
Sujithf1dc5602008-10-29 10:16:30 +05303765 default:
3766 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003767 }
Sujithf1dc5602008-10-29 10:16:30 +05303768}
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003769
Sujithcbe61d82009-02-09 13:27:12 +05303770bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303771 u32 capability, u32 setting, int *status)
3772{
Sujithf1dc5602008-10-29 10:16:30 +05303773 u32 v;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003774
Sujithf1dc5602008-10-29 10:16:30 +05303775 switch (type) {
3776 case ATH9K_CAP_TKIP_MIC:
3777 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303778 ah->sta_id1_defaults |=
Sujithf1dc5602008-10-29 10:16:30 +05303779 AR_STA_ID1_CRPT_MIC_ENABLE;
3780 else
Sujith2660b812009-02-09 13:27:26 +05303781 ah->sta_id1_defaults &=
Sujithf1dc5602008-10-29 10:16:30 +05303782 ~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)
Sujith2660b812009-02-09 13:27:26 +05303794 ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303795 else
Sujith2660b812009-02-09 13:27:26 +05303796 ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303797 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303798 default:
3799 return false;
3800 }
3801}
3802
3803/****************************/
3804/* GPIO / RFKILL / Antennae */
3805/****************************/
3806
Sujithcbe61d82009-02-09 13:27:12 +05303807static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303808 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
Sujithcbe61d82009-02-09 13:27:12 +05303835void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303836{
3837 u32 gpio_shift;
3838
Sujith2660b812009-02-09 13:27:26 +05303839 ASSERT(gpio < ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05303840
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
Sujithcbe61d82009-02-09 13:27:12 +05303849u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303850{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303851#define MS_REG_READ(x, y) \
3852 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
3853
Sujith2660b812009-02-09 13:27:26 +05303854 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05303855 return 0xffffffff;
3856
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05303857 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 Balasubramaniancb33c412008-12-24 18:03:58 +05303860 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;
Sujithf1dc5602008-10-29 10:16:30 +05303865}
3866
Sujithcbe61d82009-02-09 13:27:12 +05303867void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05303868 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
Sujithcbe61d82009-02-09 13:27:12 +05303882void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05303883{
3884 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
3885 AR_GPIO_BIT(gpio));
3886}
3887
Sujithcbe61d82009-02-09 13:27:12 +05303888u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303889{
3890 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
3891}
3892
Sujithcbe61d82009-02-09 13:27:12 +05303893void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05303894{
3895 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
3896}
3897
Sujithcbe61d82009-02-09 13:27:12 +05303898bool ath9k_hw_setantennaswitch(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303899 enum ath9k_ant_setting settings,
3900 struct ath9k_channel *chan,
3901 u8 *tx_chainmask,
3902 u8 *rx_chainmask,
3903 u8 *antenna_cfgd)
3904{
Sujithf1dc5602008-10-29 10:16:30 +05303905 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:
Sujith2660b812009-02-09 13:27:26 +05303921 if (ah->caps.tx_chainmask >
Sujithf1dc5602008-10-29 10:16:30 +05303922 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 {
Sujith1cf68732009-08-13 09:34:32 +05303937 ah->config.diversity_control = settings;
Sujithf1dc5602008-10-29 10:16:30 +05303938 }
3939
3940 return true;
3941}
3942
3943/*********************/
3944/* General Operation */
3945/*********************/
3946
Sujithcbe61d82009-02-09 13:27:12 +05303947u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303948{
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
Sujithcbe61d82009-02-09 13:27:12 +05303960void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05303961{
3962 u32 phybits;
3963
Sujith7ea310b2009-09-03 12:08:43 +05303964 REG_WRITE(ah, AR_RX_FILTER, bits);
3965
Sujithf1dc5602008-10-29 10:16:30 +05303966 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
Sujithcbe61d82009-02-09 13:27:12 +05303981bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303982{
3983 return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM);
3984}
3985
Sujithcbe61d82009-02-09 13:27:12 +05303986bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303987{
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07003988 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05303989 return false;
3990
3991 return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD);
3992}
3993
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003994void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
Sujithf1dc5602008-10-29 10:16:30 +05303995{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003996 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujith2660b812009-02-09 13:27:26 +05303997 struct ath9k_channel *chan = ah->curchan;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08003998 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05303999
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07004000 regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER);
Sujithf1dc5602008-10-29 10:16:30 +05304001
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07004002 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07004003 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07004004 channel->max_antenna_gain * 2,
4005 channel->max_power * 2,
4006 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07004007 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05304008}
4009
Sujithcbe61d82009-02-09 13:27:12 +05304010void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac)
Sujithf1dc5602008-10-29 10:16:30 +05304011{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07004012 memcpy(ath9k_hw_common(ah)->macaddr, mac, ETH_ALEN);
Sujithf1dc5602008-10-29 10:16:30 +05304013}
4014
Sujithcbe61d82009-02-09 13:27:12 +05304015void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304016{
Sujith2660b812009-02-09 13:27:26 +05304017 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05304018}
4019
Sujithcbe61d82009-02-09 13:27:12 +05304020void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05304021{
4022 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
4023 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
4024}
4025
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07004026void ath9k_hw_setbssidmask(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304027{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07004028 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));
Sujithf1dc5602008-10-29 10:16:30 +05304032}
4033
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07004034void ath9k_hw_write_associd(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304035{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07004036 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));
Sujithf1dc5602008-10-29 10:16:30 +05304041}
4042
Sujithcbe61d82009-02-09 13:27:12 +05304043u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304044{
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
Sujithcbe61d82009-02-09 13:27:12 +05304053void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004054{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004055 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01004056 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004057}
4058
Sujithcbe61d82009-02-09 13:27:12 +05304059void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304060{
Gabor Juhosf9b604f2009-06-21 00:02:15 +02004061 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
4062 AH_TSF_WRITE_TIMEOUT))
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07004063 DPRINTF(ah, ATH_DBG_RESET,
Gabor Juhosf9b604f2009-06-21 00:02:15 +02004064 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
4065
Sujithf1dc5602008-10-29 10:16:30 +05304066 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004067}
4068
Sujith54e4cec2009-08-07 09:45:09 +05304069void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004070{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004071 if (setting)
Sujith2660b812009-02-09 13:27:26 +05304072 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004073 else
Sujith2660b812009-02-09 13:27:26 +05304074 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004075}
4076
Sujithcbe61d82009-02-09 13:27:12 +05304077bool ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004078{
Sujithf1dc5602008-10-29 10:16:30 +05304079 if (us < ATH9K_SLOT_TIME_9 || us > ath9k_hw_mac_to_usec(ah, 0xffff)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07004080 DPRINTF(ah, ATH_DBG_RESET, "bad slot time %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05304081 ah->slottime = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05304082 return false;
4083 } else {
4084 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05304085 ah->slottime = us;
Sujithf1dc5602008-10-29 10:16:30 +05304086 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004087 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004088}
4089
Sujithcbe61d82009-02-09 13:27:12 +05304090void ath9k_hw_set11nmac2040(struct ath_hw *ah, enum ath9k_ht_macmode mode)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004091{
Sujithf1dc5602008-10-29 10:16:30 +05304092 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004093
Sujithf1dc5602008-10-29 10:16:30 +05304094 if (mode == ATH9K_HT_MACMODE_2040 &&
Sujith2660b812009-02-09 13:27:26 +05304095 !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05304096 macmode = AR_2040_JOINED_RX_CLEAR;
4097 else
4098 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004099
Sujithf1dc5602008-10-29 10:16:30 +05304100 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004101}
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304102
4103/* HW Generic timers configuration */
4104
4105static 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 */
4135static 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 Thiagarajan17739122009-08-26 21:08:50 +05304148u32 ath9k_hw_gettsf32(struct ath_hw *ah)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304149{
4150 return REG_READ(ah, AR_TSF_L32);
4151}
4152
4153struct 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
4180void 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. Rodriguez4d6b2282009-09-07 04:52:26 -07004193 DPRINTF(ah, ATH_DBG_HWTIMER, "curent tsf %x period %x"
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304194 "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
4225void 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
4253void 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 */
4265void 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. Rodriguez4d6b2282009-09-07 04:52:26 -07004283 DPRINTF(ah, ATH_DBG_HWTIMER,
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304284 "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. Rodriguez4d6b2282009-09-07 04:52:26 -07004292 DPRINTF(ah, ATH_DBG_HWTIMER,
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304293 "Gen timer[%d] trigger\n", index);
4294 timer->trigger(timer->arg);
4295 }
4296}
Vasanthakumar Thiagarajan7b6840a2009-09-07 17:46:49 +05304297
4298/*
4299 * Primitive to disable ASPM
4300 */
4301void 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}