blob: c10b33b1b67323fa5c0d214c53443ebaf7bee869 [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
2 * Copyright (c) 2008 Atheros Communications Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include <linux/io.h>
18#include <asm/unaligned.h>
19
Sujith394cf0a2009-02-09 13:26:54 +053020#include "ath9k.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070021#include "initvals.h"
22
Vasanthakumar Thiagarajan138ab2e2009-01-10 17:07:09 +053023static int btcoex_enable;
24module_param(btcoex_enable, bool, 0);
25MODULE_PARM_DESC(btcoex_enable, "Enable Bluetooth coexistence support");
26
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080027#define ATH9K_CLOCK_RATE_CCK 22
28#define ATH9K_CLOCK_RATE_5GHZ_OFDM 40
29#define ATH9K_CLOCK_RATE_2GHZ_OFDM 44
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070030
Sujithcbe61d82009-02-09 13:27:12 +053031static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type);
32static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan,
Sujithf1dc5602008-10-29 10:16:30 +053033 enum ath9k_ht_macmode macmode);
Sujithcbe61d82009-02-09 13:27:12 +053034static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +053035 struct ar5416_eeprom_def *pEepData,
Sujithf1dc5602008-10-29 10:16:30 +053036 u32 reg, u32 value);
Sujithcbe61d82009-02-09 13:27:12 +053037static void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan);
38static void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070039
Sujithf1dc5602008-10-29 10:16:30 +053040/********************/
41/* Helper Functions */
42/********************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070043
Sujithcbe61d82009-02-09 13:27:12 +053044static u32 ath9k_hw_mac_usec(struct ath_hw *ah, u32 clks)
Sujithf1dc5602008-10-29 10:16:30 +053045{
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080046 struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053047
Sujith2660b812009-02-09 13:27:26 +053048 if (!ah->curchan) /* should really check for CCK instead */
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080049 return clks / ATH9K_CLOCK_RATE_CCK;
50 if (conf->channel->band == IEEE80211_BAND_2GHZ)
51 return clks / ATH9K_CLOCK_RATE_2GHZ_OFDM;
Sujithcbe61d82009-02-09 13:27:12 +053052
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080053 return clks / ATH9K_CLOCK_RATE_5GHZ_OFDM;
Sujithf1dc5602008-10-29 10:16:30 +053054}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070055
Sujithcbe61d82009-02-09 13:27:12 +053056static u32 ath9k_hw_mac_to_usec(struct ath_hw *ah, u32 clks)
Sujithf1dc5602008-10-29 10:16:30 +053057{
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080058 struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053059
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080060 if (conf_is_ht40(conf))
Sujithf1dc5602008-10-29 10:16:30 +053061 return ath9k_hw_mac_usec(ah, clks) / 2;
62 else
63 return ath9k_hw_mac_usec(ah, clks);
64}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070065
Sujithcbe61d82009-02-09 13:27:12 +053066static u32 ath9k_hw_mac_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053067{
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080068 struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053069
Sujith2660b812009-02-09 13:27:26 +053070 if (!ah->curchan) /* should really check for CCK instead */
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080071 return usecs *ATH9K_CLOCK_RATE_CCK;
72 if (conf->channel->band == IEEE80211_BAND_2GHZ)
73 return usecs *ATH9K_CLOCK_RATE_2GHZ_OFDM;
74 return usecs *ATH9K_CLOCK_RATE_5GHZ_OFDM;
Sujithf1dc5602008-10-29 10:16:30 +053075}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070076
Sujithcbe61d82009-02-09 13:27:12 +053077static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053078{
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080079 struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053080
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080081 if (conf_is_ht40(conf))
Sujithf1dc5602008-10-29 10:16:30 +053082 return ath9k_hw_mac_clks(ah, usecs) * 2;
83 else
84 return ath9k_hw_mac_clks(ah, usecs);
85}
86
Sujith0caa7b12009-02-16 13:23:20 +053087bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070088{
89 int i;
90
Sujith0caa7b12009-02-16 13:23:20 +053091 BUG_ON(timeout < AH_TIME_QUANTUM);
92
93 for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070094 if ((REG_READ(ah, reg) & mask) == val)
95 return true;
96
97 udelay(AH_TIME_QUANTUM);
98 }
Sujith04bd46382008-11-28 22:18:05 +053099
100 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
Sujith0caa7b12009-02-16 13:23:20 +0530101 "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
102 timeout, reg, REG_READ(ah, reg), mask, val);
Sujithf1dc5602008-10-29 10:16:30 +0530103
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700104 return false;
105}
106
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700107u32 ath9k_hw_reverse_bits(u32 val, u32 n)
108{
109 u32 retval;
110 int i;
111
112 for (i = 0, retval = 0; i < n; i++) {
113 retval = (retval << 1) | (val & 1);
114 val >>= 1;
115 }
116 return retval;
117}
118
Sujithcbe61d82009-02-09 13:27:12 +0530119bool ath9k_get_channel_edges(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530120 u16 flags, u16 *low,
121 u16 *high)
122{
Sujith2660b812009-02-09 13:27:26 +0530123 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530124
125 if (flags & CHANNEL_5GHZ) {
126 *low = pCap->low_5ghz_chan;
127 *high = pCap->high_5ghz_chan;
128 return true;
129 }
130 if ((flags & CHANNEL_2GHZ)) {
131 *low = pCap->low_2ghz_chan;
132 *high = pCap->high_2ghz_chan;
133 return true;
134 }
135 return false;
136}
137
Sujithcbe61d82009-02-09 13:27:12 +0530138u16 ath9k_hw_computetxtime(struct ath_hw *ah,
Sujithe63835b2008-11-18 09:07:53 +0530139 struct ath_rate_table *rates,
Sujithf1dc5602008-10-29 10:16:30 +0530140 u32 frameLen, u16 rateix,
141 bool shortPreamble)
142{
143 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
144 u32 kbps;
145
Sujithe63835b2008-11-18 09:07:53 +0530146 kbps = rates->info[rateix].ratekbps;
Sujithf1dc5602008-10-29 10:16:30 +0530147
148 if (kbps == 0)
149 return 0;
150
151 switch (rates->info[rateix].phy) {
Sujith46d14a52008-11-18 09:08:13 +0530152 case WLAN_RC_PHY_CCK:
Sujithf1dc5602008-10-29 10:16:30 +0530153 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
Sujithe63835b2008-11-18 09:07:53 +0530154 if (shortPreamble && rates->info[rateix].short_preamble)
Sujithf1dc5602008-10-29 10:16:30 +0530155 phyTime >>= 1;
156 numBits = frameLen << 3;
157 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
158 break;
Sujith46d14a52008-11-18 09:08:13 +0530159 case WLAN_RC_PHY_OFDM:
Sujith2660b812009-02-09 13:27:26 +0530160 if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530161 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
162 numBits = OFDM_PLCP_BITS + (frameLen << 3);
163 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
164 txTime = OFDM_SIFS_TIME_QUARTER
165 + OFDM_PREAMBLE_TIME_QUARTER
166 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
Sujith2660b812009-02-09 13:27:26 +0530167 } else if (ah->curchan &&
168 IS_CHAN_HALF_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530169 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
170 numBits = OFDM_PLCP_BITS + (frameLen << 3);
171 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
172 txTime = OFDM_SIFS_TIME_HALF +
173 OFDM_PREAMBLE_TIME_HALF
174 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
175 } else {
176 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
177 numBits = OFDM_PLCP_BITS + (frameLen << 3);
178 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
179 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
180 + (numSymbols * OFDM_SYMBOL_TIME);
181 }
182 break;
183 default:
Sujith04bd46382008-11-28 22:18:05 +0530184 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
185 "Unknown phy %u (rate ix %u)\n",
Sujithf1dc5602008-10-29 10:16:30 +0530186 rates->info[rateix].phy, rateix);
187 txTime = 0;
188 break;
189 }
190
191 return txTime;
192}
193
Sujithcbe61d82009-02-09 13:27:12 +0530194void ath9k_hw_get_channel_centers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530195 struct ath9k_channel *chan,
196 struct chan_centers *centers)
197{
198 int8_t extoff;
Sujithf1dc5602008-10-29 10:16:30 +0530199
200 if (!IS_CHAN_HT40(chan)) {
201 centers->ctl_center = centers->ext_center =
202 centers->synth_center = chan->channel;
203 return;
204 }
205
206 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
207 (chan->chanmode == CHANNEL_G_HT40PLUS)) {
208 centers->synth_center =
209 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
210 extoff = 1;
211 } else {
212 centers->synth_center =
213 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
214 extoff = -1;
215 }
216
217 centers->ctl_center =
218 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
219 centers->ext_center =
220 centers->synth_center + (extoff *
Sujith2660b812009-02-09 13:27:26 +0530221 ((ah->extprotspacing == ATH9K_HT_EXTPROTSPACING_20) ?
Sujithf1dc5602008-10-29 10:16:30 +0530222 HT40_CHANNEL_CENTER_SHIFT : 15));
Sujithf1dc5602008-10-29 10:16:30 +0530223}
224
225/******************/
226/* Chip Revisions */
227/******************/
228
Sujithcbe61d82009-02-09 13:27:12 +0530229static void ath9k_hw_read_revisions(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530230{
231 u32 val;
232
233 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
234
235 if (val == 0xFF) {
236 val = REG_READ(ah, AR_SREV);
Sujithd535a422009-02-09 13:27:06 +0530237 ah->hw_version.macVersion =
238 (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
239 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
Sujith2660b812009-02-09 13:27:26 +0530240 ah->is_pciexpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
Sujithf1dc5602008-10-29 10:16:30 +0530241 } else {
242 if (!AR_SREV_9100(ah))
Sujithd535a422009-02-09 13:27:06 +0530243 ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
Sujithf1dc5602008-10-29 10:16:30 +0530244
Sujithd535a422009-02-09 13:27:06 +0530245 ah->hw_version.macRev = val & AR_SREV_REVISION;
Sujithf1dc5602008-10-29 10:16:30 +0530246
Sujithd535a422009-02-09 13:27:06 +0530247 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
Sujith2660b812009-02-09 13:27:26 +0530248 ah->is_pciexpress = true;
Sujithf1dc5602008-10-29 10:16:30 +0530249 }
250}
251
Sujithcbe61d82009-02-09 13:27:12 +0530252static int ath9k_hw_get_radiorev(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530253{
254 u32 val;
255 int i;
256
257 REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
258
259 for (i = 0; i < 8; i++)
260 REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
261 val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
262 val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
263
264 return ath9k_hw_reverse_bits(val, 8);
265}
266
267/************************************/
268/* HW Attach, Detach, Init Routines */
269/************************************/
270
Sujithcbe61d82009-02-09 13:27:12 +0530271static void ath9k_hw_disablepcie(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530272{
Sujithfeed0292009-01-29 11:37:35 +0530273 if (AR_SREV_9100(ah))
Sujithf1dc5602008-10-29 10:16:30 +0530274 return;
275
276 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
277 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
278 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
279 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
280 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
281 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
282 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
283 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
284 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
285
286 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
287}
288
Sujithcbe61d82009-02-09 13:27:12 +0530289static bool ath9k_hw_chip_test(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530290{
291 u32 regAddr[2] = { AR_STA_ID0, AR_PHY_BASE + (8 << 2) };
292 u32 regHold[2];
293 u32 patternData[4] = { 0x55555555,
294 0xaaaaaaaa,
295 0x66666666,
296 0x99999999 };
297 int i, j;
298
299 for (i = 0; i < 2; i++) {
300 u32 addr = regAddr[i];
301 u32 wrData, rdData;
302
303 regHold[i] = REG_READ(ah, addr);
304 for (j = 0; j < 0x100; j++) {
305 wrData = (j << 16) | j;
306 REG_WRITE(ah, addr, wrData);
307 rdData = REG_READ(ah, addr);
308 if (rdData != wrData) {
309 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
Sujith04bd46382008-11-28 22:18:05 +0530310 "address test failed "
Sujithf1dc5602008-10-29 10:16:30 +0530311 "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
Sujith04bd46382008-11-28 22:18:05 +0530312 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530313 return false;
314 }
315 }
316 for (j = 0; j < 4; j++) {
317 wrData = patternData[j];
318 REG_WRITE(ah, addr, wrData);
319 rdData = REG_READ(ah, addr);
320 if (wrData != rdData) {
321 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
Sujith04bd46382008-11-28 22:18:05 +0530322 "address test failed "
Sujithf1dc5602008-10-29 10:16:30 +0530323 "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
Sujith04bd46382008-11-28 22:18:05 +0530324 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530325 return false;
326 }
327 }
328 REG_WRITE(ah, regAddr[i], regHold[i]);
329 }
330 udelay(100);
Sujithcbe61d82009-02-09 13:27:12 +0530331
Sujithf1dc5602008-10-29 10:16:30 +0530332 return true;
333}
334
335static const char *ath9k_hw_devname(u16 devid)
336{
337 switch (devid) {
338 case AR5416_DEVID_PCI:
Sujithf1dc5602008-10-29 10:16:30 +0530339 return "Atheros 5416";
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +0100340 case AR5416_DEVID_PCIE:
341 return "Atheros 5418";
Sujithf1dc5602008-10-29 10:16:30 +0530342 case AR9160_DEVID_PCI:
343 return "Atheros 9160";
Gabor Juhos0c1aa492009-01-14 20:17:12 +0100344 case AR5416_AR9100_DEVID:
345 return "Atheros 9100";
Sujithf1dc5602008-10-29 10:16:30 +0530346 case AR9280_DEVID_PCI:
347 case AR9280_DEVID_PCIE:
348 return "Atheros 9280";
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530349 case AR9285_DEVID_PCIE:
350 return "Atheros 9285";
Sujithf1dc5602008-10-29 10:16:30 +0530351 }
352
353 return NULL;
354}
355
Sujithcbe61d82009-02-09 13:27:12 +0530356static void ath9k_hw_set_defaults(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700357{
358 int i;
359
Sujith2660b812009-02-09 13:27:26 +0530360 ah->config.dma_beacon_response_time = 2;
361 ah->config.sw_beacon_response_time = 10;
362 ah->config.additional_swba_backoff = 0;
363 ah->config.ack_6mb = 0x0;
364 ah->config.cwm_ignore_extcca = 0;
365 ah->config.pcie_powersave_enable = 0;
366 ah->config.pcie_l1skp_enable = 0;
367 ah->config.pcie_clock_req = 0;
368 ah->config.pcie_power_reset = 0x100;
369 ah->config.pcie_restore = 0;
370 ah->config.pcie_waen = 0;
371 ah->config.analog_shiftreg = 1;
372 ah->config.ht_enable = 1;
373 ah->config.ofdm_trig_low = 200;
374 ah->config.ofdm_trig_high = 500;
375 ah->config.cck_trig_high = 200;
376 ah->config.cck_trig_low = 100;
377 ah->config.enable_ani = 1;
378 ah->config.noise_immunity_level = 4;
379 ah->config.ofdm_weaksignal_det = 1;
380 ah->config.cck_weaksignal_thr = 0;
381 ah->config.spur_immunity_level = 2;
382 ah->config.firstep_level = 0;
383 ah->config.rssi_thr_high = 40;
384 ah->config.rssi_thr_low = 7;
385 ah->config.diversity_control = 0;
386 ah->config.antenna_switch_swap = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700387
388 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujith2660b812009-02-09 13:27:26 +0530389 ah->config.spurchans[i][0] = AR_NO_SPUR;
390 ah->config.spurchans[i][1] = AR_NO_SPUR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700391 }
392
Sujith2660b812009-02-09 13:27:26 +0530393 ah->config.intr_mitigation = 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700394}
395
Sujithcbe61d82009-02-09 13:27:12 +0530396static struct ath_hw *ath9k_hw_newstate(u16 devid, struct ath_softc *sc,
397 int *status)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700398{
Sujithcbe61d82009-02-09 13:27:12 +0530399 struct ath_hw *ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700400
Sujithcbe61d82009-02-09 13:27:12 +0530401 ah = kzalloc(sizeof(struct ath_hw), GFP_KERNEL);
402 if (ah == NULL) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700403 DPRINTF(sc, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +0530404 "Cannot allocate memory for state block\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700405 *status = -ENOMEM;
406 return NULL;
407 }
408
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700409 ah->ah_sc = sc;
Sujithd535a422009-02-09 13:27:06 +0530410 ah->hw_version.magic = AR5416_MAGIC;
Sujithd6bad492009-02-09 13:27:08 +0530411 ah->regulatory.country_code = CTRY_DEFAULT;
Sujithd535a422009-02-09 13:27:06 +0530412 ah->hw_version.devid = devid;
413 ah->hw_version.subvendorid = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700414
415 ah->ah_flags = 0;
416 if ((devid == AR5416_AR9100_DEVID))
Sujithd535a422009-02-09 13:27:06 +0530417 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700418 if (!AR_SREV_9100(ah))
419 ah->ah_flags = AH_USE_EEPROM;
420
Sujithd6bad492009-02-09 13:27:08 +0530421 ah->regulatory.power_limit = MAX_RATE_POWER;
422 ah->regulatory.tp_scale = ATH9K_TP_SCALE_MAX;
Sujith2660b812009-02-09 13:27:26 +0530423 ah->atim_window = 0;
424 ah->diversity_control = ah->config.diversity_control;
425 ah->antenna_switch_swap =
426 ah->config.antenna_switch_swap;
427 ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
428 ah->beacon_interval = 100;
429 ah->enable_32kHz_clock = DONT_USE_32KHZ;
430 ah->slottime = (u32) -1;
431 ah->acktimeout = (u32) -1;
432 ah->ctstimeout = (u32) -1;
433 ah->globaltxtimeout = (u32) -1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700434
Sujith2660b812009-02-09 13:27:26 +0530435 ah->gbeacon_rate = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700436
Sujithcbe61d82009-02-09 13:27:12 +0530437 return ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700438}
439
Sujithcbe61d82009-02-09 13:27:12 +0530440static int ath9k_hw_rfattach(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700441{
442 bool rfStatus = false;
443 int ecode = 0;
444
445 rfStatus = ath9k_hw_init_rf(ah, &ecode);
446 if (!rfStatus) {
447 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujith04bd46382008-11-28 22:18:05 +0530448 "RF setup failed, status %u\n", ecode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700449 return ecode;
450 }
451
452 return 0;
453}
454
Sujithcbe61d82009-02-09 13:27:12 +0530455static int ath9k_hw_rf_claim(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700456{
457 u32 val;
458
459 REG_WRITE(ah, AR_PHY(0), 0x00000007);
460
461 val = ath9k_hw_get_radiorev(ah);
462 switch (val & AR_RADIO_SREV_MAJOR) {
463 case 0:
464 val = AR_RAD5133_SREV_MAJOR;
465 break;
466 case AR_RAD5133_SREV_MAJOR:
467 case AR_RAD5122_SREV_MAJOR:
468 case AR_RAD2133_SREV_MAJOR:
469 case AR_RAD2122_SREV_MAJOR:
470 break;
471 default:
472 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
Sujith04bd46382008-11-28 22:18:05 +0530473 "5G Radio Chip Rev 0x%02X is not "
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700474 "supported by this driver\n",
Sujithd535a422009-02-09 13:27:06 +0530475 ah->hw_version.analog5GhzRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700476 return -EOPNOTSUPP;
477 }
478
Sujithd535a422009-02-09 13:27:06 +0530479 ah->hw_version.analog5GhzRev = val;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700480
481 return 0;
482}
483
Sujithcbe61d82009-02-09 13:27:12 +0530484static int ath9k_hw_init_macaddr(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700485{
Sujithf1dc5602008-10-29 10:16:30 +0530486 u32 sum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700487 int i;
Sujithf1dc5602008-10-29 10:16:30 +0530488 u16 eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700489
Sujithf1dc5602008-10-29 10:16:30 +0530490 sum = 0;
491 for (i = 0; i < 3; i++) {
Sujithf74df6f2009-02-09 13:27:24 +0530492 eeval = ah->eep_ops->get_eeprom(ah, AR_EEPROM_MAC(i));
Sujithf1dc5602008-10-29 10:16:30 +0530493 sum += eeval;
Sujithba52da52009-02-09 13:27:10 +0530494 ah->macaddr[2 * i] = eeval >> 8;
495 ah->macaddr[2 * i + 1] = eeval & 0xff;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700496 }
Sujithf1dc5602008-10-29 10:16:30 +0530497 if (sum == 0 || sum == 0xffff * 3) {
498 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
Sujith04bd46382008-11-28 22:18:05 +0530499 "mac address read failed: %pM\n",
Sujithba52da52009-02-09 13:27:10 +0530500 ah->macaddr);
Sujithf1dc5602008-10-29 10:16:30 +0530501 return -EADDRNOTAVAIL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700502 }
503
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700504 return 0;
505}
506
Sujithcbe61d82009-02-09 13:27:12 +0530507static void ath9k_hw_init_rxgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530508{
509 u32 rxgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530510
Sujithf74df6f2009-02-09 13:27:24 +0530511 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_17) {
512 rxgain_type = ah->eep_ops->get_eeprom(ah, EEP_RXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530513
514 if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530515 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530516 ar9280Modes_backoff_13db_rxgain_9280_2,
517 ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2), 6);
518 else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530519 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530520 ar9280Modes_backoff_23db_rxgain_9280_2,
521 ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 6);
522 else
Sujith2660b812009-02-09 13:27:26 +0530523 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530524 ar9280Modes_original_rxgain_9280_2,
525 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530526 } else {
Sujith2660b812009-02-09 13:27:26 +0530527 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530528 ar9280Modes_original_rxgain_9280_2,
529 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530530 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530531}
532
Sujithcbe61d82009-02-09 13:27:12 +0530533static void ath9k_hw_init_txgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530534{
535 u32 txgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530536
Sujithf74df6f2009-02-09 13:27:24 +0530537 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_19) {
538 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530539
540 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
Sujith2660b812009-02-09 13:27:26 +0530541 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530542 ar9280Modes_high_power_tx_gain_9280_2,
543 ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 6);
544 else
Sujith2660b812009-02-09 13:27:26 +0530545 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530546 ar9280Modes_original_tx_gain_9280_2,
547 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530548 } else {
Sujith2660b812009-02-09 13:27:26 +0530549 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530550 ar9280Modes_original_tx_gain_9280_2,
551 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530552 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530553}
554
Sujithcbe61d82009-02-09 13:27:12 +0530555static int ath9k_hw_post_attach(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700556{
557 int ecode;
558
559 if (!ath9k_hw_chip_test(ah)) {
560 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
Sujith04bd46382008-11-28 22:18:05 +0530561 "hardware self-test failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700562 return -ENODEV;
563 }
564
565 ecode = ath9k_hw_rf_claim(ah);
566 if (ecode != 0)
567 return ecode;
568
569 ecode = ath9k_hw_eeprom_attach(ah);
570 if (ecode != 0)
571 return ecode;
572 ecode = ath9k_hw_rfattach(ah);
573 if (ecode != 0)
574 return ecode;
575
576 if (!AR_SREV_9100(ah)) {
577 ath9k_hw_ani_setup(ah);
578 ath9k_hw_ani_attach(ah);
579 }
Sujithf1dc5602008-10-29 10:16:30 +0530580
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700581 return 0;
582}
583
Sujithcbe61d82009-02-09 13:27:12 +0530584static struct ath_hw *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc,
585 int *status)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700586{
Sujithcbe61d82009-02-09 13:27:12 +0530587 struct ath_hw *ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700588 int ecode;
Sujithf6688cd2008-12-07 21:43:10 +0530589 u32 i, j;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700590
Sujithcbe61d82009-02-09 13:27:12 +0530591 ah = ath9k_hw_newstate(devid, sc, status);
592 if (ah == NULL)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700593 return NULL;
594
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700595 ath9k_hw_set_defaults(ah);
596
Sujith2660b812009-02-09 13:27:26 +0530597 if (ah->config.intr_mitigation != 0)
598 ah->intr_mitigation = true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700599
600 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Sujithcbe61d82009-02-09 13:27:12 +0530601 DPRINTF(sc, ATH_DBG_RESET, "Couldn't reset chip\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700602 ecode = -EIO;
603 goto bad;
604 }
605
606 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
Sujithcbe61d82009-02-09 13:27:12 +0530607 DPRINTF(sc, ATH_DBG_RESET, "Couldn't wakeup chip\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700608 ecode = -EIO;
609 goto bad;
610 }
611
Sujith2660b812009-02-09 13:27:26 +0530612 if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
Sujithd535a422009-02-09 13:27:06 +0530613 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI) {
Sujith2660b812009-02-09 13:27:26 +0530614 ah->config.serialize_regmode =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700615 SER_REG_MODE_ON;
616 } else {
Sujith2660b812009-02-09 13:27:26 +0530617 ah->config.serialize_regmode =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700618 SER_REG_MODE_OFF;
619 }
620 }
Sujithf1dc5602008-10-29 10:16:30 +0530621
Sujithcbe61d82009-02-09 13:27:12 +0530622 DPRINTF(sc, ATH_DBG_RESET, "serialize_regmode is %d\n",
Sujith2660b812009-02-09 13:27:26 +0530623 ah->config.serialize_regmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700624
Sujithd535a422009-02-09 13:27:06 +0530625 if ((ah->hw_version.macVersion != AR_SREV_VERSION_5416_PCI) &&
626 (ah->hw_version.macVersion != AR_SREV_VERSION_5416_PCIE) &&
627 (ah->hw_version.macVersion != AR_SREV_VERSION_9160) &&
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530628 (!AR_SREV_9100(ah)) && (!AR_SREV_9280(ah)) && (!AR_SREV_9285(ah))) {
Sujithcbe61d82009-02-09 13:27:12 +0530629 DPRINTF(sc, ATH_DBG_RESET,
Sujith04bd46382008-11-28 22:18:05 +0530630 "Mac Chip Rev 0x%02x.%x is not supported by "
Sujithd535a422009-02-09 13:27:06 +0530631 "this driver\n", ah->hw_version.macVersion,
632 ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700633 ecode = -EOPNOTSUPP;
634 goto bad;
635 }
636
637 if (AR_SREV_9100(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530638 ah->iq_caldata.calData = &iq_cal_multi_sample;
639 ah->supp_cals = IQ_MISMATCH_CAL;
640 ah->is_pciexpress = false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700641 }
Sujithd535a422009-02-09 13:27:06 +0530642 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700643
644 if (AR_SREV_9160_10_OR_LATER(ah)) {
645 if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530646 ah->iq_caldata.calData = &iq_cal_single_sample;
647 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700648 &adc_gain_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530649 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700650 &adc_dc_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530651 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700652 &adc_init_dc_cal;
653 } else {
Sujith2660b812009-02-09 13:27:26 +0530654 ah->iq_caldata.calData = &iq_cal_multi_sample;
655 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700656 &adc_gain_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530657 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700658 &adc_dc_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530659 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700660 &adc_init_dc_cal;
661 }
Sujith2660b812009-02-09 13:27:26 +0530662 ah->supp_cals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700663 }
664
665 if (AR_SREV_9160(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530666 ah->config.enable_ani = 1;
667 ah->ani_function = (ATH9K_ANI_SPUR_IMMUNITY_LEVEL |
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700668 ATH9K_ANI_FIRSTEP_LEVEL);
669 } else {
Sujith2660b812009-02-09 13:27:26 +0530670 ah->ani_function = ATH9K_ANI_ALL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700671 if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530672 ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700673 }
674 }
675
Sujithcbe61d82009-02-09 13:27:12 +0530676 DPRINTF(sc, ATH_DBG_RESET,
Sujith04bd46382008-11-28 22:18:05 +0530677 "This Mac Chip Rev 0x%02x.%x is \n",
Sujithd535a422009-02-09 13:27:06 +0530678 ah->hw_version.macVersion, ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700679
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530680 if (AR_SREV_9285_12_OR_LATER(ah)) {
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530681
Sujith2660b812009-02-09 13:27:26 +0530682 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530683 ARRAY_SIZE(ar9285Modes_9285_1_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530684 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530685 ARRAY_SIZE(ar9285Common_9285_1_2), 2);
686
Sujith2660b812009-02-09 13:27:26 +0530687 if (ah->config.pcie_clock_req) {
688 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530689 ar9285PciePhy_clkreq_off_L1_9285_1_2,
690 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2);
691 } else {
Sujith2660b812009-02-09 13:27:26 +0530692 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530693 ar9285PciePhy_clkreq_always_on_L1_9285_1_2,
694 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2),
695 2);
696 }
697 } else if (AR_SREV_9285_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530698 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530699 ARRAY_SIZE(ar9285Modes_9285), 6);
Sujith2660b812009-02-09 13:27:26 +0530700 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530701 ARRAY_SIZE(ar9285Common_9285), 2);
702
Sujith2660b812009-02-09 13:27:26 +0530703 if (ah->config.pcie_clock_req) {
704 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530705 ar9285PciePhy_clkreq_off_L1_9285,
706 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2);
707 } else {
Sujith2660b812009-02-09 13:27:26 +0530708 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530709 ar9285PciePhy_clkreq_always_on_L1_9285,
710 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285), 2);
711 }
712 } else if (AR_SREV_9280_20_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530713 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700714 ARRAY_SIZE(ar9280Modes_9280_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530715 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700716 ARRAY_SIZE(ar9280Common_9280_2), 2);
717
Sujith2660b812009-02-09 13:27:26 +0530718 if (ah->config.pcie_clock_req) {
719 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530720 ar9280PciePhy_clkreq_off_L1_9280,
721 ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700722 } else {
Sujith2660b812009-02-09 13:27:26 +0530723 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530724 ar9280PciePhy_clkreq_always_on_L1_9280,
725 ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700726 }
Sujith2660b812009-02-09 13:27:26 +0530727 INIT_INI_ARRAY(&ah->iniModesAdditional,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700728 ar9280Modes_fast_clock_9280_2,
Sujithf1dc5602008-10-29 10:16:30 +0530729 ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700730 } else if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530731 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700732 ARRAY_SIZE(ar9280Modes_9280), 6);
Sujith2660b812009-02-09 13:27:26 +0530733 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700734 ARRAY_SIZE(ar9280Common_9280), 2);
735 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530736 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700737 ARRAY_SIZE(ar5416Modes_9160), 6);
Sujith2660b812009-02-09 13:27:26 +0530738 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700739 ARRAY_SIZE(ar5416Common_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530740 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700741 ARRAY_SIZE(ar5416Bank0_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530742 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700743 ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530744 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700745 ARRAY_SIZE(ar5416Bank1_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530746 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700747 ARRAY_SIZE(ar5416Bank2_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530748 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700749 ARRAY_SIZE(ar5416Bank3_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530750 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700751 ARRAY_SIZE(ar5416Bank6_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530752 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700753 ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530754 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700755 ARRAY_SIZE(ar5416Bank7_9160), 2);
756 if (AR_SREV_9160_11(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530757 INIT_INI_ARRAY(&ah->iniAddac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700758 ar5416Addac_91601_1,
759 ARRAY_SIZE(ar5416Addac_91601_1), 2);
760 } else {
Sujith2660b812009-02-09 13:27:26 +0530761 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700762 ARRAY_SIZE(ar5416Addac_9160), 2);
763 }
764 } else if (AR_SREV_9100_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530765 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700766 ARRAY_SIZE(ar5416Modes_9100), 6);
Sujith2660b812009-02-09 13:27:26 +0530767 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700768 ARRAY_SIZE(ar5416Common_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530769 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700770 ARRAY_SIZE(ar5416Bank0_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530771 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700772 ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530773 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700774 ARRAY_SIZE(ar5416Bank1_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530775 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700776 ARRAY_SIZE(ar5416Bank2_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530777 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700778 ARRAY_SIZE(ar5416Bank3_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530779 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700780 ARRAY_SIZE(ar5416Bank6_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530781 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700782 ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530783 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700784 ARRAY_SIZE(ar5416Bank7_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530785 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700786 ARRAY_SIZE(ar5416Addac_9100), 2);
787 } else {
Sujith2660b812009-02-09 13:27:26 +0530788 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700789 ARRAY_SIZE(ar5416Modes), 6);
Sujith2660b812009-02-09 13:27:26 +0530790 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700791 ARRAY_SIZE(ar5416Common), 2);
Sujith2660b812009-02-09 13:27:26 +0530792 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700793 ARRAY_SIZE(ar5416Bank0), 2);
Sujith2660b812009-02-09 13:27:26 +0530794 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700795 ARRAY_SIZE(ar5416BB_RfGain), 3);
Sujith2660b812009-02-09 13:27:26 +0530796 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700797 ARRAY_SIZE(ar5416Bank1), 2);
Sujith2660b812009-02-09 13:27:26 +0530798 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700799 ARRAY_SIZE(ar5416Bank2), 2);
Sujith2660b812009-02-09 13:27:26 +0530800 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700801 ARRAY_SIZE(ar5416Bank3), 3);
Sujith2660b812009-02-09 13:27:26 +0530802 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700803 ARRAY_SIZE(ar5416Bank6), 3);
Sujith2660b812009-02-09 13:27:26 +0530804 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700805 ARRAY_SIZE(ar5416Bank6TPC), 3);
Sujith2660b812009-02-09 13:27:26 +0530806 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700807 ARRAY_SIZE(ar5416Bank7), 2);
Sujith2660b812009-02-09 13:27:26 +0530808 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700809 ARRAY_SIZE(ar5416Addac), 2);
810 }
811
Sujith2660b812009-02-09 13:27:26 +0530812 if (ah->is_pciexpress)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700813 ath9k_hw_configpcipowersave(ah, 0);
814 else
Sujithf1dc5602008-10-29 10:16:30 +0530815 ath9k_hw_disablepcie(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700816
817 ecode = ath9k_hw_post_attach(ah);
818 if (ecode != 0)
819 goto bad;
820
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530821 if (AR_SREV_9285_12_OR_LATER(ah)) {
822 u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
823
824 /* txgain table */
825 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) {
826 INIT_INI_ARRAY(&ah->iniModesTxGain,
827 ar9285Modes_high_power_tx_gain_9285_1_2,
828 ARRAY_SIZE(ar9285Modes_high_power_tx_gain_9285_1_2), 6);
829 } else {
830 INIT_INI_ARRAY(&ah->iniModesTxGain,
831 ar9285Modes_original_tx_gain_9285_1_2,
832 ARRAY_SIZE(ar9285Modes_original_tx_gain_9285_1_2), 6);
833 }
834
835 }
836
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530837 /* rxgain table */
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530838 if (AR_SREV_9280_20(ah))
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530839 ath9k_hw_init_rxgain_ini(ah);
840
841 /* txgain table */
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530842 if (AR_SREV_9280_20(ah))
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530843 ath9k_hw_init_txgain_ini(ah);
844
Sujith06d0f062009-02-12 10:06:45 +0530845 if (!ath9k_hw_fill_cap_info(ah)) {
846 DPRINTF(sc, ATH_DBG_RESET, "failed ath9k_hw_fill_cap_info\n");
847 ecode = -EINVAL;
848 goto bad;
849 }
850
851 if ((ah->hw_version.devid == AR9280_DEVID_PCI) &&
852 test_bit(ATH9K_MODE_11A, ah->caps.wireless_modes)) {
853
854 /* EEPROM Fixup */
Sujith2660b812009-02-09 13:27:26 +0530855 for (i = 0; i < ah->iniModes.ia_rows; i++) {
856 u32 reg = INI_RA(&ah->iniModes, i, 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700857
Sujith2660b812009-02-09 13:27:26 +0530858 for (j = 1; j < ah->iniModes.ia_columns; j++) {
859 u32 val = INI_RA(&ah->iniModes, i, j);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700860
Sujith2660b812009-02-09 13:27:26 +0530861 INI_RA(&ah->iniModes, i, j) =
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530862 ath9k_hw_ini_fixup(ah,
Sujith2660b812009-02-09 13:27:26 +0530863 &ah->eeprom.def,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700864 reg, val);
865 }
866 }
867 }
Sujithf6688cd2008-12-07 21:43:10 +0530868
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700869 ecode = ath9k_hw_init_macaddr(ah);
870 if (ecode != 0) {
Sujithcbe61d82009-02-09 13:27:12 +0530871 DPRINTF(sc, ATH_DBG_RESET,
Sujith04bd46382008-11-28 22:18:05 +0530872 "failed initializing mac address\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700873 goto bad;
874 }
875
876 if (AR_SREV_9285(ah))
Sujith2660b812009-02-09 13:27:26 +0530877 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700878 else
Sujith2660b812009-02-09 13:27:26 +0530879 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700880
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700881 ath9k_init_nfcal_hist_buffer(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700882
883 return ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700884bad:
Sujithcbe61d82009-02-09 13:27:12 +0530885 if (ah)
886 ath9k_hw_detach(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700887 if (status)
888 *status = ecode;
Sujithf1dc5602008-10-29 10:16:30 +0530889
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700890 return NULL;
891}
892
Sujithcbe61d82009-02-09 13:27:12 +0530893static void ath9k_hw_init_bb(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530894 struct ath9k_channel *chan)
895{
896 u32 synthDelay;
897
898 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +0530899 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +0530900 synthDelay = (4 * synthDelay) / 22;
901 else
902 synthDelay /= 10;
903
904 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
905
906 udelay(synthDelay + BASE_ACTIVATE_DELAY);
907}
908
Sujithcbe61d82009-02-09 13:27:12 +0530909static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530910{
911 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
912 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
913
914 REG_WRITE(ah, AR_QOS_NO_ACK,
915 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
916 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
917 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
918
919 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
920 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
921 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
922 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
923 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
924}
925
Sujithcbe61d82009-02-09 13:27:12 +0530926static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530927 struct ath9k_channel *chan)
928{
929 u32 pll;
930
931 if (AR_SREV_9100(ah)) {
932 if (chan && IS_CHAN_5GHZ(chan))
933 pll = 0x1450;
934 else
935 pll = 0x1458;
936 } else {
937 if (AR_SREV_9280_10_OR_LATER(ah)) {
938 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
939
940 if (chan && IS_CHAN_HALF_RATE(chan))
941 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
942 else if (chan && IS_CHAN_QUARTER_RATE(chan))
943 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
944
945 if (chan && IS_CHAN_5GHZ(chan)) {
946 pll |= SM(0x28, AR_RTC_9160_PLL_DIV);
947
948
949 if (AR_SREV_9280_20(ah)) {
950 if (((chan->channel % 20) == 0)
951 || ((chan->channel % 10) == 0))
952 pll = 0x2850;
953 else
954 pll = 0x142c;
955 }
956 } else {
957 pll |= SM(0x2c, AR_RTC_9160_PLL_DIV);
958 }
959
960 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
961
962 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
963
964 if (chan && IS_CHAN_HALF_RATE(chan))
965 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
966 else if (chan && IS_CHAN_QUARTER_RATE(chan))
967 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
968
969 if (chan && IS_CHAN_5GHZ(chan))
970 pll |= SM(0x50, AR_RTC_9160_PLL_DIV);
971 else
972 pll |= SM(0x58, AR_RTC_9160_PLL_DIV);
973 } else {
974 pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2;
975
976 if (chan && IS_CHAN_HALF_RATE(chan))
977 pll |= SM(0x1, AR_RTC_PLL_CLKSEL);
978 else if (chan && IS_CHAN_QUARTER_RATE(chan))
979 pll |= SM(0x2, AR_RTC_PLL_CLKSEL);
980
981 if (chan && IS_CHAN_5GHZ(chan))
982 pll |= SM(0xa, AR_RTC_PLL_DIV);
983 else
984 pll |= SM(0xb, AR_RTC_PLL_DIV);
985 }
986 }
Gabor Juhosd03a66c2009-01-14 20:17:09 +0100987 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +0530988
989 udelay(RTC_PLL_SETTLE_DELAY);
990
991 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
992}
993
Sujithcbe61d82009-02-09 13:27:12 +0530994static void ath9k_hw_init_chain_masks(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530995{
Sujithf1dc5602008-10-29 10:16:30 +0530996 int rx_chainmask, tx_chainmask;
997
Sujith2660b812009-02-09 13:27:26 +0530998 rx_chainmask = ah->rxchainmask;
999 tx_chainmask = ah->txchainmask;
Sujithf1dc5602008-10-29 10:16:30 +05301000
1001 switch (rx_chainmask) {
1002 case 0x5:
1003 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1004 AR_PHY_SWAP_ALT_CHAIN);
1005 case 0x3:
Sujithd535a422009-02-09 13:27:06 +05301006 if (((ah)->hw_version.macVersion <= AR_SREV_VERSION_9160)) {
Sujithf1dc5602008-10-29 10:16:30 +05301007 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7);
1008 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7);
1009 break;
1010 }
1011 case 0x1:
1012 case 0x2:
Sujithf1dc5602008-10-29 10:16:30 +05301013 case 0x7:
1014 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
1015 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
1016 break;
1017 default:
1018 break;
1019 }
1020
1021 REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);
1022 if (tx_chainmask == 0x5) {
1023 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1024 AR_PHY_SWAP_ALT_CHAIN);
1025 }
1026 if (AR_SREV_9100(ah))
1027 REG_WRITE(ah, AR_PHY_ANALOG_SWAP,
1028 REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
1029}
1030
Sujithcbe61d82009-02-09 13:27:12 +05301031static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -08001032 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301033{
Sujith2660b812009-02-09 13:27:26 +05301034 ah->mask_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +05301035 AR_IMR_TXURN |
1036 AR_IMR_RXERR |
1037 AR_IMR_RXORN |
1038 AR_IMR_BCNMISC;
1039
Sujith2660b812009-02-09 13:27:26 +05301040 if (ah->intr_mitigation)
1041 ah->mask_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
Sujithf1dc5602008-10-29 10:16:30 +05301042 else
Sujith2660b812009-02-09 13:27:26 +05301043 ah->mask_reg |= AR_IMR_RXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301044
Sujith2660b812009-02-09 13:27:26 +05301045 ah->mask_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301046
Colin McCabed97809d2008-12-01 13:38:55 -08001047 if (opmode == NL80211_IFTYPE_AP)
Sujith2660b812009-02-09 13:27:26 +05301048 ah->mask_reg |= AR_IMR_MIB;
Sujithf1dc5602008-10-29 10:16:30 +05301049
Sujith2660b812009-02-09 13:27:26 +05301050 REG_WRITE(ah, AR_IMR, ah->mask_reg);
Sujithf1dc5602008-10-29 10:16:30 +05301051 REG_WRITE(ah, AR_IMR_S2, REG_READ(ah, AR_IMR_S2) | AR_IMR_S2_GTT);
1052
1053 if (!AR_SREV_9100(ah)) {
1054 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
1055 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
1056 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
1057 }
1058}
1059
Sujithcbe61d82009-02-09 13:27:12 +05301060static bool ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301061{
Sujithf1dc5602008-10-29 10:16:30 +05301062 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) {
Sujith04bd46382008-11-28 22:18:05 +05301063 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "bad ack timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301064 ah->acktimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301065 return false;
1066 } else {
1067 REG_RMW_FIELD(ah, AR_TIME_OUT,
1068 AR_TIME_OUT_ACK, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301069 ah->acktimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301070 return true;
1071 }
1072}
1073
Sujithcbe61d82009-02-09 13:27:12 +05301074static bool ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301075{
Sujithf1dc5602008-10-29 10:16:30 +05301076 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_CTS))) {
Sujith04bd46382008-11-28 22:18:05 +05301077 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "bad cts timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301078 ah->ctstimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301079 return false;
1080 } else {
1081 REG_RMW_FIELD(ah, AR_TIME_OUT,
1082 AR_TIME_OUT_CTS, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301083 ah->ctstimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301084 return true;
1085 }
1086}
1087
Sujithcbe61d82009-02-09 13:27:12 +05301088static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +05301089{
Sujithf1dc5602008-10-29 10:16:30 +05301090 if (tu > 0xFFFF) {
1091 DPRINTF(ah->ah_sc, ATH_DBG_XMIT,
Sujith04bd46382008-11-28 22:18:05 +05301092 "bad global tx timeout %u\n", tu);
Sujith2660b812009-02-09 13:27:26 +05301093 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301094 return false;
1095 } else {
1096 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +05301097 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +05301098 return true;
1099 }
1100}
1101
Sujithcbe61d82009-02-09 13:27:12 +05301102static void ath9k_hw_init_user_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301103{
Sujith2660b812009-02-09 13:27:26 +05301104 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
1105 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +05301106
Sujith2660b812009-02-09 13:27:26 +05301107 if (ah->misc_mode != 0)
Sujithf1dc5602008-10-29 10:16:30 +05301108 REG_WRITE(ah, AR_PCU_MISC,
Sujith2660b812009-02-09 13:27:26 +05301109 REG_READ(ah, AR_PCU_MISC) | ah->misc_mode);
1110 if (ah->slottime != (u32) -1)
1111 ath9k_hw_setslottime(ah, ah->slottime);
1112 if (ah->acktimeout != (u32) -1)
1113 ath9k_hw_set_ack_timeout(ah, ah->acktimeout);
1114 if (ah->ctstimeout != (u32) -1)
1115 ath9k_hw_set_cts_timeout(ah, ah->ctstimeout);
1116 if (ah->globaltxtimeout != (u32) -1)
1117 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Sujithf1dc5602008-10-29 10:16:30 +05301118}
1119
1120const char *ath9k_hw_probe(u16 vendorid, u16 devid)
1121{
1122 return vendorid == ATHEROS_VENDOR_ID ?
1123 ath9k_hw_devname(devid) : NULL;
1124}
1125
Sujithcbe61d82009-02-09 13:27:12 +05301126void ath9k_hw_detach(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001127{
1128 if (!AR_SREV_9100(ah))
1129 ath9k_hw_ani_detach(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001130
Sujithf1dc5602008-10-29 10:16:30 +05301131 ath9k_hw_rfdetach(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001132 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
1133 kfree(ah);
1134}
1135
Sujithcbe61d82009-02-09 13:27:12 +05301136struct ath_hw *ath9k_hw_attach(u16 devid, struct ath_softc *sc, int *error)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001137{
Sujithcbe61d82009-02-09 13:27:12 +05301138 struct ath_hw *ah = NULL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001139
Sujithf1dc5602008-10-29 10:16:30 +05301140 switch (devid) {
1141 case AR5416_DEVID_PCI:
1142 case AR5416_DEVID_PCIE:
Gabor Juhos0c1aa492009-01-14 20:17:12 +01001143 case AR5416_AR9100_DEVID:
Sujithf1dc5602008-10-29 10:16:30 +05301144 case AR9160_DEVID_PCI:
1145 case AR9280_DEVID_PCI:
1146 case AR9280_DEVID_PCIE:
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301147 case AR9285_DEVID_PCIE:
Sujithcbe61d82009-02-09 13:27:12 +05301148 ah = ath9k_hw_do_attach(devid, sc, error);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001149 break;
Sujithf1dc5602008-10-29 10:16:30 +05301150 default:
Sujithf1dc5602008-10-29 10:16:30 +05301151 *error = -ENXIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001152 break;
1153 }
1154
Sujithf1dc5602008-10-29 10:16:30 +05301155 return ah;
1156}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001157
Sujithf1dc5602008-10-29 10:16:30 +05301158/*******/
1159/* INI */
1160/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001161
Sujithcbe61d82009-02-09 13:27:12 +05301162static void ath9k_hw_override_ini(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301163 struct ath9k_channel *chan)
1164{
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +05301165 /*
1166 * Set the RX_ABORT and RX_DIS and clear if off only after
1167 * RXE is set for MAC. This prevents frames with corrupted
1168 * descriptor status.
1169 */
1170 REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
1171
1172
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001173 if (!AR_SREV_5416_20_OR_LATER(ah) ||
Sujithf1dc5602008-10-29 10:16:30 +05301174 AR_SREV_9280_10_OR_LATER(ah))
1175 return;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001176
Sujithf1dc5602008-10-29 10:16:30 +05301177 REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
1178}
1179
Sujithcbe61d82009-02-09 13:27:12 +05301180static u32 ath9k_hw_def_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301181 struct ar5416_eeprom_def *pEepData,
Sujithf1dc5602008-10-29 10:16:30 +05301182 u32 reg, u32 value)
1183{
1184 struct base_eep_header *pBase = &(pEepData->baseEepHeader);
1185
Sujithd535a422009-02-09 13:27:06 +05301186 switch (ah->hw_version.devid) {
Sujithf1dc5602008-10-29 10:16:30 +05301187 case AR9280_DEVID_PCI:
1188 if (reg == 0x7894) {
1189 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
1190 "ini VAL: %x EEPROM: %x\n", value,
1191 (pBase->version & 0xff));
1192
1193 if ((pBase->version & 0xff) > 0x0a) {
1194 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
1195 "PWDCLKIND: %d\n",
1196 pBase->pwdclkind);
1197 value &= ~AR_AN_TOP2_PWDCLKIND;
1198 value |= AR_AN_TOP2_PWDCLKIND &
1199 (pBase->pwdclkind << AR_AN_TOP2_PWDCLKIND_S);
1200 } else {
1201 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
1202 "PWDCLKIND Earlier Rev\n");
1203 }
1204
1205 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
1206 "final ini VAL: %x\n", value);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001207 }
Sujithf1dc5602008-10-29 10:16:30 +05301208 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001209 }
1210
Sujithf1dc5602008-10-29 10:16:30 +05301211 return value;
1212}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001213
Sujithcbe61d82009-02-09 13:27:12 +05301214static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301215 struct ar5416_eeprom_def *pEepData,
1216 u32 reg, u32 value)
1217{
Sujith2660b812009-02-09 13:27:26 +05301218 if (ah->eep_map == EEP_MAP_4KBITS)
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301219 return value;
1220 else
1221 return ath9k_hw_def_ini_fixup(ah, pEepData, reg, value);
1222}
1223
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301224static void ath9k_olc_init(struct ath_hw *ah)
1225{
1226 u32 i;
1227
1228 for (i = 0; i < AR9280_TX_GAIN_TABLE_SIZE; i++)
1229 ah->originalGain[i] =
1230 MS(REG_READ(ah, AR_PHY_TX_GAIN_TBL1 + i * 4),
1231 AR_PHY_TX_GAIN);
1232 ah->PDADCdelta = 0;
1233}
1234
Sujithcbe61d82009-02-09 13:27:12 +05301235static int ath9k_hw_process_ini(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301236 struct ath9k_channel *chan,
1237 enum ath9k_ht_macmode macmode)
1238{
1239 int i, regWrites = 0;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001240 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301241 u32 modesIndex, freqIndex;
1242 int status;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001243
Sujithf1dc5602008-10-29 10:16:30 +05301244 switch (chan->chanmode) {
1245 case CHANNEL_A:
1246 case CHANNEL_A_HT20:
1247 modesIndex = 1;
1248 freqIndex = 1;
1249 break;
1250 case CHANNEL_A_HT40PLUS:
1251 case CHANNEL_A_HT40MINUS:
1252 modesIndex = 2;
1253 freqIndex = 1;
1254 break;
1255 case CHANNEL_G:
1256 case CHANNEL_G_HT20:
1257 case CHANNEL_B:
1258 modesIndex = 4;
1259 freqIndex = 2;
1260 break;
1261 case CHANNEL_G_HT40PLUS:
1262 case CHANNEL_G_HT40MINUS:
1263 modesIndex = 3;
1264 freqIndex = 2;
1265 break;
1266
1267 default:
1268 return -EINVAL;
1269 }
1270
1271 REG_WRITE(ah, AR_PHY(0), 0x00000007);
Sujithf1dc5602008-10-29 10:16:30 +05301272 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
Sujithf74df6f2009-02-09 13:27:24 +05301273 ah->eep_ops->set_addac(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301274
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001275 if (AR_SREV_5416_22_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +05301276 REG_WRITE_ARRAY(&ah->iniAddac, 1, regWrites);
Sujithf1dc5602008-10-29 10:16:30 +05301277 } else {
1278 struct ar5416IniArray temp;
1279 u32 addacSize =
Sujith2660b812009-02-09 13:27:26 +05301280 sizeof(u32) * ah->iniAddac.ia_rows *
1281 ah->iniAddac.ia_columns;
Sujithf1dc5602008-10-29 10:16:30 +05301282
Sujith2660b812009-02-09 13:27:26 +05301283 memcpy(ah->addac5416_21,
1284 ah->iniAddac.ia_array, addacSize);
Sujithf1dc5602008-10-29 10:16:30 +05301285
Sujith2660b812009-02-09 13:27:26 +05301286 (ah->addac5416_21)[31 * ah->iniAddac.ia_columns + 1] = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301287
Sujith2660b812009-02-09 13:27:26 +05301288 temp.ia_array = ah->addac5416_21;
1289 temp.ia_columns = ah->iniAddac.ia_columns;
1290 temp.ia_rows = ah->iniAddac.ia_rows;
Sujithf1dc5602008-10-29 10:16:30 +05301291 REG_WRITE_ARRAY(&temp, 1, regWrites);
1292 }
1293
1294 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
1295
Sujith2660b812009-02-09 13:27:26 +05301296 for (i = 0; i < ah->iniModes.ia_rows; i++) {
1297 u32 reg = INI_RA(&ah->iniModes, i, 0);
1298 u32 val = INI_RA(&ah->iniModes, i, modesIndex);
Sujithf1dc5602008-10-29 10:16:30 +05301299
Sujithf1dc5602008-10-29 10:16:30 +05301300 REG_WRITE(ah, reg, val);
1301
1302 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301303 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301304 udelay(100);
1305 }
1306
1307 DO_DELAY(regWrites);
1308 }
1309
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301310 if (AR_SREV_9280(ah))
Sujith2660b812009-02-09 13:27:26 +05301311 REG_WRITE_ARRAY(&ah->iniModesRxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301312
Senthil Balasubramanian4e845162009-03-06 11:24:10 +05301313 if (AR_SREV_9280(ah) || (AR_SREV_9285(ah) &&
1314 AR_SREV_9285_12_OR_LATER(ah)))
Sujith2660b812009-02-09 13:27:26 +05301315 REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301316
Sujith2660b812009-02-09 13:27:26 +05301317 for (i = 0; i < ah->iniCommon.ia_rows; i++) {
1318 u32 reg = INI_RA(&ah->iniCommon, i, 0);
1319 u32 val = INI_RA(&ah->iniCommon, i, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301320
1321 REG_WRITE(ah, reg, val);
1322
1323 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301324 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301325 udelay(100);
1326 }
1327
1328 DO_DELAY(regWrites);
1329 }
1330
1331 ath9k_hw_write_regs(ah, modesIndex, freqIndex, regWrites);
1332
1333 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan)) {
Sujith2660b812009-02-09 13:27:26 +05301334 REG_WRITE_ARRAY(&ah->iniModesAdditional, modesIndex,
Sujithf1dc5602008-10-29 10:16:30 +05301335 regWrites);
1336 }
1337
1338 ath9k_hw_override_ini(ah, chan);
1339 ath9k_hw_set_regs(ah, chan, macmode);
1340 ath9k_hw_init_chain_masks(ah);
1341
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301342 if (OLC_FOR_AR9280_20_LATER)
1343 ath9k_olc_init(ah);
1344
Sujithf74df6f2009-02-09 13:27:24 +05301345 status = ah->eep_ops->set_txpower(ah, chan,
1346 ath9k_regd_get_ctl(ah, chan),
1347 channel->max_antenna_gain * 2,
1348 channel->max_power * 2,
1349 min((u32) MAX_RATE_POWER,
1350 (u32) ah->regulatory.power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05301351 if (status != 0) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001352 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
Sujith04bd46382008-11-28 22:18:05 +05301353 "error init'ing transmit power\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001354 return -EIO;
1355 }
1356
Sujithf1dc5602008-10-29 10:16:30 +05301357 if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
1358 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
Sujith04bd46382008-11-28 22:18:05 +05301359 "ar5416SetRfRegs failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001360 return -EIO;
1361 }
1362
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001363 return 0;
1364}
1365
Sujithf1dc5602008-10-29 10:16:30 +05301366/****************************************/
1367/* Reset and Channel Switching Routines */
1368/****************************************/
1369
Sujithcbe61d82009-02-09 13:27:12 +05301370static void ath9k_hw_set_rfmode(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301371{
1372 u32 rfMode = 0;
1373
1374 if (chan == NULL)
1375 return;
1376
1377 rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
1378 ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
1379
1380 if (!AR_SREV_9280_10_OR_LATER(ah))
1381 rfMode |= (IS_CHAN_5GHZ(chan)) ?
1382 AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ;
1383
1384 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan))
1385 rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
1386
1387 REG_WRITE(ah, AR_PHY_MODE, rfMode);
1388}
1389
Sujithcbe61d82009-02-09 13:27:12 +05301390static void ath9k_hw_mark_phy_inactive(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301391{
1392 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
1393}
1394
Sujithcbe61d82009-02-09 13:27:12 +05301395static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301396{
1397 u32 regval;
1398
1399 regval = REG_READ(ah, AR_AHB_MODE);
1400 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
1401
1402 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
1403 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
1404
Sujith2660b812009-02-09 13:27:26 +05301405 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +05301406
1407 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
1408 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
1409
1410 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1411
1412 if (AR_SREV_9285(ah)) {
1413 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1414 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
1415 } else {
1416 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1417 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1418 }
1419}
1420
Sujithcbe61d82009-02-09 13:27:12 +05301421static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301422{
1423 u32 val;
1424
1425 val = REG_READ(ah, AR_STA_ID1);
1426 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
1427 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001428 case NL80211_IFTYPE_AP:
Sujithf1dc5602008-10-29 10:16:30 +05301429 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
1430 | AR_STA_ID1_KSRCH_MODE);
1431 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1432 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001433 case NL80211_IFTYPE_ADHOC:
Sujithf1dc5602008-10-29 10:16:30 +05301434 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
1435 | AR_STA_ID1_KSRCH_MODE);
1436 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1437 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001438 case NL80211_IFTYPE_STATION:
1439 case NL80211_IFTYPE_MONITOR:
Sujithf1dc5602008-10-29 10:16:30 +05301440 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
1441 break;
1442 }
1443}
1444
Sujithcbe61d82009-02-09 13:27:12 +05301445static inline void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001446 u32 coef_scaled,
1447 u32 *coef_mantissa,
1448 u32 *coef_exponent)
1449{
1450 u32 coef_exp, coef_man;
1451
1452 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1453 if ((coef_scaled >> coef_exp) & 0x1)
1454 break;
1455
1456 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1457
1458 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1459
1460 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1461 *coef_exponent = coef_exp - 16;
1462}
1463
Sujithcbe61d82009-02-09 13:27:12 +05301464static void ath9k_hw_set_delta_slope(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301465 struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001466{
1467 u32 coef_scaled, ds_coef_exp, ds_coef_man;
1468 u32 clockMhzScaled = 0x64000000;
1469 struct chan_centers centers;
1470
1471 if (IS_CHAN_HALF_RATE(chan))
1472 clockMhzScaled = clockMhzScaled >> 1;
1473 else if (IS_CHAN_QUARTER_RATE(chan))
1474 clockMhzScaled = clockMhzScaled >> 2;
1475
1476 ath9k_hw_get_channel_centers(ah, chan, &centers);
1477 coef_scaled = clockMhzScaled / centers.synth_center;
1478
1479 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1480 &ds_coef_exp);
1481
1482 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1483 AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
1484 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1485 AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
1486
1487 coef_scaled = (9 * coef_scaled) / 10;
1488
1489 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1490 &ds_coef_exp);
1491
1492 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1493 AR_PHY_HALFGI_DSC_MAN, ds_coef_man);
1494 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1495 AR_PHY_HALFGI_DSC_EXP, ds_coef_exp);
1496}
1497
Sujithcbe61d82009-02-09 13:27:12 +05301498static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +05301499{
1500 u32 rst_flags;
1501 u32 tmpReg;
1502
Sujith70768492009-02-16 13:23:12 +05301503 if (AR_SREV_9100(ah)) {
1504 u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK);
1505 val &= ~AR_RTC_DERIVED_CLK_PERIOD;
1506 val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD);
1507 REG_WRITE(ah, AR_RTC_DERIVED_CLK, val);
1508 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1509 }
1510
Sujithf1dc5602008-10-29 10:16:30 +05301511 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1512 AR_RTC_FORCE_WAKE_ON_INT);
1513
1514 if (AR_SREV_9100(ah)) {
1515 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1516 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1517 } else {
1518 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1519 if (tmpReg &
1520 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1521 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
1522 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
1523 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1524 } else {
1525 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1526 }
1527
1528 rst_flags = AR_RTC_RC_MAC_WARM;
1529 if (type == ATH9K_RESET_COLD)
1530 rst_flags |= AR_RTC_RC_MAC_COLD;
1531 }
1532
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001533 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujithf1dc5602008-10-29 10:16:30 +05301534 udelay(50);
1535
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001536 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301537 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Sujithf1dc5602008-10-29 10:16:30 +05301538 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujith04bd46382008-11-28 22:18:05 +05301539 "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301540 return false;
1541 }
1542
1543 if (!AR_SREV_9100(ah))
1544 REG_WRITE(ah, AR_RC, 0);
1545
1546 ath9k_hw_init_pll(ah, NULL);
1547
1548 if (AR_SREV_9100(ah))
1549 udelay(50);
1550
1551 return true;
1552}
1553
Sujithcbe61d82009-02-09 13:27:12 +05301554static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301555{
1556 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1557 AR_RTC_FORCE_WAKE_ON_INT);
1558
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001559 REG_WRITE(ah, AR_RTC_RESET, 0);
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301560 udelay(2);
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001561 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301562
1563 if (!ath9k_hw_wait(ah,
1564 AR_RTC_STATUS,
1565 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301566 AR_RTC_STATUS_ON,
1567 AH_WAIT_TIMEOUT)) {
Sujith04bd46382008-11-28 22:18:05 +05301568 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301569 return false;
1570 }
1571
1572 ath9k_hw_read_revisions(ah);
1573
1574 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1575}
1576
Sujithcbe61d82009-02-09 13:27:12 +05301577static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301578{
1579 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1580 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1581
1582 switch (type) {
1583 case ATH9K_RESET_POWER_ON:
1584 return ath9k_hw_set_reset_power_on(ah);
1585 break;
1586 case ATH9K_RESET_WARM:
1587 case ATH9K_RESET_COLD:
1588 return ath9k_hw_set_reset(ah, type);
1589 break;
1590 default:
1591 return false;
1592 }
1593}
1594
Sujithcbe61d82009-02-09 13:27:12 +05301595static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan,
Sujithf1dc5602008-10-29 10:16:30 +05301596 enum ath9k_ht_macmode macmode)
1597{
1598 u32 phymode;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301599 u32 enableDacFifo = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301600
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301601 if (AR_SREV_9285_10_OR_LATER(ah))
1602 enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) &
1603 AR_PHY_FC_ENABLE_DAC_FIFO);
1604
Sujithf1dc5602008-10-29 10:16:30 +05301605 phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301606 | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo;
Sujithf1dc5602008-10-29 10:16:30 +05301607
1608 if (IS_CHAN_HT40(chan)) {
1609 phymode |= AR_PHY_FC_DYN2040_EN;
1610
1611 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
1612 (chan->chanmode == CHANNEL_G_HT40PLUS))
1613 phymode |= AR_PHY_FC_DYN2040_PRI_CH;
1614
Sujith2660b812009-02-09 13:27:26 +05301615 if (ah->extprotspacing == ATH9K_HT_EXTPROTSPACING_25)
Sujithf1dc5602008-10-29 10:16:30 +05301616 phymode |= AR_PHY_FC_DYN2040_EXT_CH;
1617 }
1618 REG_WRITE(ah, AR_PHY_TURBO, phymode);
1619
1620 ath9k_hw_set11nmac2040(ah, macmode);
1621
1622 REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
1623 REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
1624}
1625
Sujithcbe61d82009-02-09 13:27:12 +05301626static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301627 struct ath9k_channel *chan)
1628{
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301629 if (OLC_FOR_AR9280_20_LATER) {
1630 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
1631 return false;
1632 } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
Sujithf1dc5602008-10-29 10:16:30 +05301633 return false;
1634
1635 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
1636 return false;
1637
Sujith2660b812009-02-09 13:27:26 +05301638 ah->chip_fullsleep = false;
Sujithf1dc5602008-10-29 10:16:30 +05301639 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301640 ath9k_hw_set_rfmode(ah, chan);
1641
1642 return true;
1643}
1644
Sujithcbe61d82009-02-09 13:27:12 +05301645static bool ath9k_hw_channel_change(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301646 struct ath9k_channel *chan,
1647 enum ath9k_ht_macmode macmode)
1648{
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001649 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301650 u32 synthDelay, qnum;
1651
1652 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1653 if (ath9k_hw_numtxpending(ah, qnum)) {
1654 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
Sujith04bd46382008-11-28 22:18:05 +05301655 "Transmit frames pending on queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301656 return false;
1657 }
1658 }
1659
1660 REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
1661 if (!ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
Sujith0caa7b12009-02-16 13:23:20 +05301662 AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT)) {
Sujith04bd46382008-11-28 22:18:05 +05301663 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
1664 "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301665 return false;
1666 }
1667
1668 ath9k_hw_set_regs(ah, chan, macmode);
1669
1670 if (AR_SREV_9280_10_OR_LATER(ah)) {
1671 if (!(ath9k_hw_ar9280_set_channel(ah, chan))) {
1672 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
Sujith04bd46382008-11-28 22:18:05 +05301673 "failed to set channel\n");
Sujithf1dc5602008-10-29 10:16:30 +05301674 return false;
1675 }
1676 } else {
1677 if (!(ath9k_hw_set_channel(ah, chan))) {
1678 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
Sujith04bd46382008-11-28 22:18:05 +05301679 "failed to set channel\n");
Sujithf1dc5602008-10-29 10:16:30 +05301680 return false;
1681 }
1682 }
1683
Sujithf74df6f2009-02-09 13:27:24 +05301684 if (ah->eep_ops->set_txpower(ah, chan,
1685 ath9k_regd_get_ctl(ah, chan),
1686 channel->max_antenna_gain * 2,
1687 channel->max_power * 2,
1688 min((u32) MAX_RATE_POWER,
1689 (u32) ah->regulatory.power_limit)) != 0) {
Sujithf1dc5602008-10-29 10:16:30 +05301690 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
Sujith04bd46382008-11-28 22:18:05 +05301691 "error init'ing transmit power\n");
Sujithf1dc5602008-10-29 10:16:30 +05301692 return false;
1693 }
1694
1695 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +05301696 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +05301697 synthDelay = (4 * synthDelay) / 22;
1698 else
1699 synthDelay /= 10;
1700
1701 udelay(synthDelay + BASE_ACTIVATE_DELAY);
1702
1703 REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
1704
1705 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1706 ath9k_hw_set_delta_slope(ah, chan);
1707
1708 if (AR_SREV_9280_10_OR_LATER(ah))
1709 ath9k_hw_9280_spur_mitigate(ah, chan);
1710 else
1711 ath9k_hw_spur_mitigate(ah, chan);
1712
1713 if (!chan->oneTimeCalsDone)
1714 chan->oneTimeCalsDone = true;
1715
1716 return true;
1717}
1718
Sujithcbe61d82009-02-09 13:27:12 +05301719static void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001720{
1721 int bb_spur = AR_NO_SPUR;
1722 int freq;
1723 int bin, cur_bin;
1724 int bb_spur_off, spur_subchannel_sd;
1725 int spur_freq_sd;
1726 int spur_delta_phase;
1727 int denominator;
1728 int upper, lower, cur_vit_mask;
1729 int tmp, newVal;
1730 int i;
1731 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
1732 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
1733 };
1734 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
1735 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
1736 };
1737 int inc[4] = { 0, 100, 0, 0 };
1738 struct chan_centers centers;
1739
1740 int8_t mask_m[123];
1741 int8_t mask_p[123];
1742 int8_t mask_amt;
1743 int tmp_mask;
1744 int cur_bb_spur;
1745 bool is2GHz = IS_CHAN_2GHZ(chan);
1746
1747 memset(&mask_m, 0, sizeof(int8_t) * 123);
1748 memset(&mask_p, 0, sizeof(int8_t) * 123);
1749
1750 ath9k_hw_get_channel_centers(ah, chan, &centers);
1751 freq = centers.synth_center;
1752
Sujith2660b812009-02-09 13:27:26 +05301753 ah->config.spurmode = SPUR_ENABLE_EEPROM;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001754 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujithf74df6f2009-02-09 13:27:24 +05301755 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001756
1757 if (is2GHz)
1758 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_2GHZ;
1759 else
1760 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_5GHZ;
1761
1762 if (AR_NO_SPUR == cur_bb_spur)
1763 break;
1764 cur_bb_spur = cur_bb_spur - freq;
1765
1766 if (IS_CHAN_HT40(chan)) {
1767 if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT40) &&
1768 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT40)) {
1769 bb_spur = cur_bb_spur;
1770 break;
1771 }
1772 } else if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT20) &&
1773 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT20)) {
1774 bb_spur = cur_bb_spur;
1775 break;
1776 }
1777 }
1778
1779 if (AR_NO_SPUR == bb_spur) {
1780 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1781 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1782 return;
1783 } else {
1784 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1785 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1786 }
1787
1788 bin = bb_spur * 320;
1789
1790 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
1791
1792 newVal = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
1793 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
1794 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
1795 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
1796 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), newVal);
1797
1798 newVal = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
1799 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
1800 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
1801 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
1802 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
1803 REG_WRITE(ah, AR_PHY_SPUR_REG, newVal);
1804
1805 if (IS_CHAN_HT40(chan)) {
1806 if (bb_spur < 0) {
1807 spur_subchannel_sd = 1;
1808 bb_spur_off = bb_spur + 10;
1809 } else {
1810 spur_subchannel_sd = 0;
1811 bb_spur_off = bb_spur - 10;
1812 }
1813 } else {
1814 spur_subchannel_sd = 0;
1815 bb_spur_off = bb_spur;
1816 }
1817
1818 if (IS_CHAN_HT40(chan))
1819 spur_delta_phase =
1820 ((bb_spur * 262144) /
1821 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
1822 else
1823 spur_delta_phase =
1824 ((bb_spur * 524288) /
1825 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
1826
1827 denominator = IS_CHAN_2GHZ(chan) ? 44 : 40;
1828 spur_freq_sd = ((bb_spur_off * 2048) / denominator) & 0x3ff;
1829
1830 newVal = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
1831 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
1832 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
1833 REG_WRITE(ah, AR_PHY_TIMING11, newVal);
1834
1835 newVal = spur_subchannel_sd << AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S;
1836 REG_WRITE(ah, AR_PHY_SFCORR_EXT, newVal);
1837
1838 cur_bin = -6000;
1839 upper = bin + 100;
1840 lower = bin - 100;
1841
1842 for (i = 0; i < 4; i++) {
1843 int pilot_mask = 0;
1844 int chan_mask = 0;
1845 int bp = 0;
1846 for (bp = 0; bp < 30; bp++) {
1847 if ((cur_bin > lower) && (cur_bin < upper)) {
1848 pilot_mask = pilot_mask | 0x1 << bp;
1849 chan_mask = chan_mask | 0x1 << bp;
1850 }
1851 cur_bin += 100;
1852 }
1853 cur_bin += inc[i];
1854 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
1855 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
1856 }
1857
1858 cur_vit_mask = 6100;
1859 upper = bin + 120;
1860 lower = bin - 120;
1861
1862 for (i = 0; i < 123; i++) {
1863 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
Adrian Bunkb08cbcd2008-08-05 22:06:51 +03001864
1865 /* workaround for gcc bug #37014 */
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08001866 volatile int tmp_v = abs(cur_vit_mask - bin);
Adrian Bunkb08cbcd2008-08-05 22:06:51 +03001867
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08001868 if (tmp_v < 75)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001869 mask_amt = 1;
1870 else
1871 mask_amt = 0;
1872 if (cur_vit_mask < 0)
1873 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
1874 else
1875 mask_p[cur_vit_mask / 100] = mask_amt;
1876 }
1877 cur_vit_mask -= 100;
1878 }
1879
1880 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
1881 | (mask_m[48] << 26) | (mask_m[49] << 24)
1882 | (mask_m[50] << 22) | (mask_m[51] << 20)
1883 | (mask_m[52] << 18) | (mask_m[53] << 16)
1884 | (mask_m[54] << 14) | (mask_m[55] << 12)
1885 | (mask_m[56] << 10) | (mask_m[57] << 8)
1886 | (mask_m[58] << 6) | (mask_m[59] << 4)
1887 | (mask_m[60] << 2) | (mask_m[61] << 0);
1888 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
1889 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
1890
1891 tmp_mask = (mask_m[31] << 28)
1892 | (mask_m[32] << 26) | (mask_m[33] << 24)
1893 | (mask_m[34] << 22) | (mask_m[35] << 20)
1894 | (mask_m[36] << 18) | (mask_m[37] << 16)
1895 | (mask_m[48] << 14) | (mask_m[39] << 12)
1896 | (mask_m[40] << 10) | (mask_m[41] << 8)
1897 | (mask_m[42] << 6) | (mask_m[43] << 4)
1898 | (mask_m[44] << 2) | (mask_m[45] << 0);
1899 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
1900 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
1901
1902 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
1903 | (mask_m[18] << 26) | (mask_m[18] << 24)
1904 | (mask_m[20] << 22) | (mask_m[20] << 20)
1905 | (mask_m[22] << 18) | (mask_m[22] << 16)
1906 | (mask_m[24] << 14) | (mask_m[24] << 12)
1907 | (mask_m[25] << 10) | (mask_m[26] << 8)
1908 | (mask_m[27] << 6) | (mask_m[28] << 4)
1909 | (mask_m[29] << 2) | (mask_m[30] << 0);
1910 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
1911 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
1912
1913 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
1914 | (mask_m[2] << 26) | (mask_m[3] << 24)
1915 | (mask_m[4] << 22) | (mask_m[5] << 20)
1916 | (mask_m[6] << 18) | (mask_m[7] << 16)
1917 | (mask_m[8] << 14) | (mask_m[9] << 12)
1918 | (mask_m[10] << 10) | (mask_m[11] << 8)
1919 | (mask_m[12] << 6) | (mask_m[13] << 4)
1920 | (mask_m[14] << 2) | (mask_m[15] << 0);
1921 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
1922 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
1923
1924 tmp_mask = (mask_p[15] << 28)
1925 | (mask_p[14] << 26) | (mask_p[13] << 24)
1926 | (mask_p[12] << 22) | (mask_p[11] << 20)
1927 | (mask_p[10] << 18) | (mask_p[9] << 16)
1928 | (mask_p[8] << 14) | (mask_p[7] << 12)
1929 | (mask_p[6] << 10) | (mask_p[5] << 8)
1930 | (mask_p[4] << 6) | (mask_p[3] << 4)
1931 | (mask_p[2] << 2) | (mask_p[1] << 0);
1932 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
1933 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
1934
1935 tmp_mask = (mask_p[30] << 28)
1936 | (mask_p[29] << 26) | (mask_p[28] << 24)
1937 | (mask_p[27] << 22) | (mask_p[26] << 20)
1938 | (mask_p[25] << 18) | (mask_p[24] << 16)
1939 | (mask_p[23] << 14) | (mask_p[22] << 12)
1940 | (mask_p[21] << 10) | (mask_p[20] << 8)
1941 | (mask_p[19] << 6) | (mask_p[18] << 4)
1942 | (mask_p[17] << 2) | (mask_p[16] << 0);
1943 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
1944 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
1945
1946 tmp_mask = (mask_p[45] << 28)
1947 | (mask_p[44] << 26) | (mask_p[43] << 24)
1948 | (mask_p[42] << 22) | (mask_p[41] << 20)
1949 | (mask_p[40] << 18) | (mask_p[39] << 16)
1950 | (mask_p[38] << 14) | (mask_p[37] << 12)
1951 | (mask_p[36] << 10) | (mask_p[35] << 8)
1952 | (mask_p[34] << 6) | (mask_p[33] << 4)
1953 | (mask_p[32] << 2) | (mask_p[31] << 0);
1954 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
1955 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
1956
1957 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
1958 | (mask_p[59] << 26) | (mask_p[58] << 24)
1959 | (mask_p[57] << 22) | (mask_p[56] << 20)
1960 | (mask_p[55] << 18) | (mask_p[54] << 16)
1961 | (mask_p[53] << 14) | (mask_p[52] << 12)
1962 | (mask_p[51] << 10) | (mask_p[50] << 8)
1963 | (mask_p[49] << 6) | (mask_p[48] << 4)
1964 | (mask_p[47] << 2) | (mask_p[46] << 0);
1965 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
1966 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
1967}
1968
Sujithcbe61d82009-02-09 13:27:12 +05301969static void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001970{
1971 int bb_spur = AR_NO_SPUR;
1972 int bin, cur_bin;
1973 int spur_freq_sd;
1974 int spur_delta_phase;
1975 int denominator;
1976 int upper, lower, cur_vit_mask;
1977 int tmp, new;
1978 int i;
1979 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
1980 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
1981 };
1982 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
1983 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
1984 };
1985 int inc[4] = { 0, 100, 0, 0 };
1986
1987 int8_t mask_m[123];
1988 int8_t mask_p[123];
1989 int8_t mask_amt;
1990 int tmp_mask;
1991 int cur_bb_spur;
1992 bool is2GHz = IS_CHAN_2GHZ(chan);
1993
1994 memset(&mask_m, 0, sizeof(int8_t) * 123);
1995 memset(&mask_p, 0, sizeof(int8_t) * 123);
1996
1997 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujithf74df6f2009-02-09 13:27:24 +05301998 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001999 if (AR_NO_SPUR == cur_bb_spur)
2000 break;
2001 cur_bb_spur = cur_bb_spur - (chan->channel * 10);
2002 if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) {
2003 bb_spur = cur_bb_spur;
2004 break;
2005 }
2006 }
2007
2008 if (AR_NO_SPUR == bb_spur)
2009 return;
2010
2011 bin = bb_spur * 32;
2012
2013 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
2014 new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
2015 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
2016 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
2017 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
2018
2019 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new);
2020
2021 new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
2022 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
2023 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
2024 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
2025 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
2026 REG_WRITE(ah, AR_PHY_SPUR_REG, new);
2027
2028 spur_delta_phase = ((bb_spur * 524288) / 100) &
2029 AR_PHY_TIMING11_SPUR_DELTA_PHASE;
2030
2031 denominator = IS_CHAN_2GHZ(chan) ? 440 : 400;
2032 spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff;
2033
2034 new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
2035 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
2036 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
2037 REG_WRITE(ah, AR_PHY_TIMING11, new);
2038
2039 cur_bin = -6000;
2040 upper = bin + 100;
2041 lower = bin - 100;
2042
2043 for (i = 0; i < 4; i++) {
2044 int pilot_mask = 0;
2045 int chan_mask = 0;
2046 int bp = 0;
2047 for (bp = 0; bp < 30; bp++) {
2048 if ((cur_bin > lower) && (cur_bin < upper)) {
2049 pilot_mask = pilot_mask | 0x1 << bp;
2050 chan_mask = chan_mask | 0x1 << bp;
2051 }
2052 cur_bin += 100;
2053 }
2054 cur_bin += inc[i];
2055 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
2056 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
2057 }
2058
2059 cur_vit_mask = 6100;
2060 upper = bin + 120;
2061 lower = bin - 120;
2062
2063 for (i = 0; i < 123; i++) {
2064 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
Adrian Bunk88b9e2b2008-08-05 22:06:51 +03002065
2066 /* workaround for gcc bug #37014 */
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002067 volatile int tmp_v = abs(cur_vit_mask - bin);
Adrian Bunk88b9e2b2008-08-05 22:06:51 +03002068
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002069 if (tmp_v < 75)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002070 mask_amt = 1;
2071 else
2072 mask_amt = 0;
2073 if (cur_vit_mask < 0)
2074 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
2075 else
2076 mask_p[cur_vit_mask / 100] = mask_amt;
2077 }
2078 cur_vit_mask -= 100;
2079 }
2080
2081 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
2082 | (mask_m[48] << 26) | (mask_m[49] << 24)
2083 | (mask_m[50] << 22) | (mask_m[51] << 20)
2084 | (mask_m[52] << 18) | (mask_m[53] << 16)
2085 | (mask_m[54] << 14) | (mask_m[55] << 12)
2086 | (mask_m[56] << 10) | (mask_m[57] << 8)
2087 | (mask_m[58] << 6) | (mask_m[59] << 4)
2088 | (mask_m[60] << 2) | (mask_m[61] << 0);
2089 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
2090 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
2091
2092 tmp_mask = (mask_m[31] << 28)
2093 | (mask_m[32] << 26) | (mask_m[33] << 24)
2094 | (mask_m[34] << 22) | (mask_m[35] << 20)
2095 | (mask_m[36] << 18) | (mask_m[37] << 16)
2096 | (mask_m[48] << 14) | (mask_m[39] << 12)
2097 | (mask_m[40] << 10) | (mask_m[41] << 8)
2098 | (mask_m[42] << 6) | (mask_m[43] << 4)
2099 | (mask_m[44] << 2) | (mask_m[45] << 0);
2100 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
2101 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
2102
2103 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
2104 | (mask_m[18] << 26) | (mask_m[18] << 24)
2105 | (mask_m[20] << 22) | (mask_m[20] << 20)
2106 | (mask_m[22] << 18) | (mask_m[22] << 16)
2107 | (mask_m[24] << 14) | (mask_m[24] << 12)
2108 | (mask_m[25] << 10) | (mask_m[26] << 8)
2109 | (mask_m[27] << 6) | (mask_m[28] << 4)
2110 | (mask_m[29] << 2) | (mask_m[30] << 0);
2111 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
2112 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
2113
2114 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
2115 | (mask_m[2] << 26) | (mask_m[3] << 24)
2116 | (mask_m[4] << 22) | (mask_m[5] << 20)
2117 | (mask_m[6] << 18) | (mask_m[7] << 16)
2118 | (mask_m[8] << 14) | (mask_m[9] << 12)
2119 | (mask_m[10] << 10) | (mask_m[11] << 8)
2120 | (mask_m[12] << 6) | (mask_m[13] << 4)
2121 | (mask_m[14] << 2) | (mask_m[15] << 0);
2122 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
2123 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
2124
2125 tmp_mask = (mask_p[15] << 28)
2126 | (mask_p[14] << 26) | (mask_p[13] << 24)
2127 | (mask_p[12] << 22) | (mask_p[11] << 20)
2128 | (mask_p[10] << 18) | (mask_p[9] << 16)
2129 | (mask_p[8] << 14) | (mask_p[7] << 12)
2130 | (mask_p[6] << 10) | (mask_p[5] << 8)
2131 | (mask_p[4] << 6) | (mask_p[3] << 4)
2132 | (mask_p[2] << 2) | (mask_p[1] << 0);
2133 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
2134 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
2135
2136 tmp_mask = (mask_p[30] << 28)
2137 | (mask_p[29] << 26) | (mask_p[28] << 24)
2138 | (mask_p[27] << 22) | (mask_p[26] << 20)
2139 | (mask_p[25] << 18) | (mask_p[24] << 16)
2140 | (mask_p[23] << 14) | (mask_p[22] << 12)
2141 | (mask_p[21] << 10) | (mask_p[20] << 8)
2142 | (mask_p[19] << 6) | (mask_p[18] << 4)
2143 | (mask_p[17] << 2) | (mask_p[16] << 0);
2144 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
2145 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
2146
2147 tmp_mask = (mask_p[45] << 28)
2148 | (mask_p[44] << 26) | (mask_p[43] << 24)
2149 | (mask_p[42] << 22) | (mask_p[41] << 20)
2150 | (mask_p[40] << 18) | (mask_p[39] << 16)
2151 | (mask_p[38] << 14) | (mask_p[37] << 12)
2152 | (mask_p[36] << 10) | (mask_p[35] << 8)
2153 | (mask_p[34] << 6) | (mask_p[33] << 4)
2154 | (mask_p[32] << 2) | (mask_p[31] << 0);
2155 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
2156 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
2157
2158 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
2159 | (mask_p[59] << 26) | (mask_p[58] << 24)
2160 | (mask_p[57] << 22) | (mask_p[56] << 20)
2161 | (mask_p[55] << 18) | (mask_p[54] << 16)
2162 | (mask_p[53] << 14) | (mask_p[52] << 12)
2163 | (mask_p[51] << 10) | (mask_p[50] << 8)
2164 | (mask_p[49] << 6) | (mask_p[48] << 4)
2165 | (mask_p[47] << 2) | (mask_p[46] << 0);
2166 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
2167 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
2168}
2169
Sujithcbe61d82009-02-09 13:27:12 +05302170int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002171 bool bChannelChange)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002172{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002173 u32 saveLedState;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002174 struct ath_softc *sc = ah->ah_sc;
Sujith2660b812009-02-09 13:27:26 +05302175 struct ath9k_channel *curchan = ah->curchan;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002176 u32 saveDefAntenna;
2177 u32 macStaId1;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002178 int i, rx_chainmask, r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002179
Sujith2660b812009-02-09 13:27:26 +05302180 ah->extprotspacing = sc->ht_extprotspacing;
2181 ah->txchainmask = sc->tx_chainmask;
2182 ah->rxchainmask = sc->rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002183
Senthil Balasubramanian793c5922009-01-26 20:28:14 +05302184 if (AR_SREV_9285(ah)) {
Sujith2660b812009-02-09 13:27:26 +05302185 ah->txchainmask &= 0x1;
2186 ah->rxchainmask &= 0x1;
Senthil Balasubramanian793c5922009-01-26 20:28:14 +05302187 } else if (AR_SREV_9280(ah)) {
Sujith2660b812009-02-09 13:27:26 +05302188 ah->txchainmask &= 0x3;
2189 ah->rxchainmask &= 0x3;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002190 }
2191
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002192 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
2193 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002194
2195 if (curchan)
2196 ath9k_hw_getnf(ah, curchan);
2197
2198 if (bChannelChange &&
Sujith2660b812009-02-09 13:27:26 +05302199 (ah->chip_fullsleep != true) &&
2200 (ah->curchan != NULL) &&
2201 (chan->channel != ah->curchan->channel) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002202 ((chan->channelFlags & CHANNEL_ALL) ==
Sujith2660b812009-02-09 13:27:26 +05302203 (ah->curchan->channelFlags & CHANNEL_ALL)) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002204 (!AR_SREV_9280(ah) || (!IS_CHAN_A_5MHZ_SPACED(chan) &&
Sujith2660b812009-02-09 13:27:26 +05302205 !IS_CHAN_A_5MHZ_SPACED(ah->curchan)))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002206
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002207 if (ath9k_hw_channel_change(ah, chan, sc->tx_chan_width)) {
Sujith2660b812009-02-09 13:27:26 +05302208 ath9k_hw_loadnf(ah, ah->curchan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002209 ath9k_hw_start_nfcal(ah);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002210 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002211 }
2212 }
2213
2214 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
2215 if (saveDefAntenna == 0)
2216 saveDefAntenna = 1;
2217
2218 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
2219
2220 saveLedState = REG_READ(ah, AR_CFG_LED) &
2221 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
2222 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
2223
2224 ath9k_hw_mark_phy_inactive(ah);
2225
2226 if (!ath9k_hw_chip_reset(ah, chan)) {
Sujith04bd46382008-11-28 22:18:05 +05302227 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002228 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002229 }
2230
Vasanthakumar Thiagarajan369391d2009-01-21 19:24:13 +05302231 if (AR_SREV_9280_10_OR_LATER(ah))
2232 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002233
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002234 r = ath9k_hw_process_ini(ah, chan, sc->tx_chan_width);
2235 if (r)
2236 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002237
Jouni Malinen0ced0e12009-01-08 13:32:13 +02002238 /* Setup MFP options for CCMP */
2239 if (AR_SREV_9280_20_OR_LATER(ah)) {
2240 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
2241 * frames when constructing CCMP AAD. */
2242 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
2243 0xc7ff);
2244 ah->sw_mgmt_crypto = false;
2245 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
2246 /* Disable hardware crypto for management frames */
2247 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
2248 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
2249 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
2250 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
2251 ah->sw_mgmt_crypto = true;
2252 } else
2253 ah->sw_mgmt_crypto = true;
2254
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002255 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
2256 ath9k_hw_set_delta_slope(ah, chan);
2257
2258 if (AR_SREV_9280_10_OR_LATER(ah))
2259 ath9k_hw_9280_spur_mitigate(ah, chan);
2260 else
2261 ath9k_hw_spur_mitigate(ah, chan);
2262
Sujithf74df6f2009-02-09 13:27:24 +05302263 if (!ah->eep_ops->set_board_values(ah, chan)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002264 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
Sujith04bd46382008-11-28 22:18:05 +05302265 "error setting board options\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002266 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002267 }
2268
2269 ath9k_hw_decrease_chain_power(ah, chan);
2270
Sujithba52da52009-02-09 13:27:10 +05302271 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(ah->macaddr));
2272 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(ah->macaddr + 4)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002273 | macStaId1
2274 | AR_STA_ID1_RTS_USE_DEF
Sujith2660b812009-02-09 13:27:26 +05302275 | (ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302276 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Sujith2660b812009-02-09 13:27:26 +05302277 | ah->sta_id1_defaults);
2278 ath9k_hw_set_operating_mode(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002279
Sujithba52da52009-02-09 13:27:10 +05302280 REG_WRITE(ah, AR_BSSMSKL, get_unaligned_le32(sc->bssidmask));
2281 REG_WRITE(ah, AR_BSSMSKU, get_unaligned_le16(sc->bssidmask + 4));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002282
2283 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
2284
Sujithba52da52009-02-09 13:27:10 +05302285 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(sc->curbssid));
2286 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(sc->curbssid + 4) |
2287 ((sc->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002288
2289 REG_WRITE(ah, AR_ISR, ~0);
2290
2291 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
2292
2293 if (AR_SREV_9280_10_OR_LATER(ah)) {
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002294 if (!(ath9k_hw_ar9280_set_channel(ah, chan)))
2295 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002296 } else {
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002297 if (!(ath9k_hw_set_channel(ah, chan)))
2298 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002299 }
2300
2301 for (i = 0; i < AR_NUM_DCU; i++)
2302 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
2303
Sujith2660b812009-02-09 13:27:26 +05302304 ah->intr_txqs = 0;
2305 for (i = 0; i < ah->caps.total_queues; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002306 ath9k_hw_resettxqueue(ah, i);
2307
Sujith2660b812009-02-09 13:27:26 +05302308 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002309 ath9k_hw_init_qos(ah);
2310
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05302311#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05302312 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05302313 ath9k_enable_rfkill(ah);
2314#endif
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002315 ath9k_hw_init_user_settings(ah);
2316
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002317 REG_WRITE(ah, AR_STA_ID1,
2318 REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
2319
2320 ath9k_hw_set_dma(ah);
2321
2322 REG_WRITE(ah, AR_OBS, 8);
2323
Sujith2660b812009-02-09 13:27:26 +05302324 if (ah->intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002325
2326 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
2327 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
2328 }
2329
2330 ath9k_hw_init_bb(ah, chan);
2331
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002332 if (!ath9k_hw_init_cal(ah, chan))
2333 return -EIO;;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002334
Sujith2660b812009-02-09 13:27:26 +05302335 rx_chainmask = ah->rxchainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002336 if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) {
2337 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
2338 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
2339 }
2340
2341 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
2342
2343 if (AR_SREV_9100(ah)) {
2344 u32 mask;
2345 mask = REG_READ(ah, AR_CFG);
2346 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
2347 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujith04bd46382008-11-28 22:18:05 +05302348 "CFG Byte Swap Set 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002349 } else {
2350 mask =
2351 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
2352 REG_WRITE(ah, AR_CFG, mask);
2353 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujith04bd46382008-11-28 22:18:05 +05302354 "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002355 }
2356 } else {
2357#ifdef __BIG_ENDIAN
2358 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
2359#endif
2360 }
2361
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002362 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002363}
2364
Sujithf1dc5602008-10-29 10:16:30 +05302365/************************/
2366/* Key Cache Management */
2367/************************/
2368
Sujithcbe61d82009-02-09 13:27:12 +05302369bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002370{
Sujithf1dc5602008-10-29 10:16:30 +05302371 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002372
Sujith2660b812009-02-09 13:27:26 +05302373 if (entry >= ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05302374 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
Sujith04bd46382008-11-28 22:18:05 +05302375 "entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002376 return false;
2377 }
2378
Sujithf1dc5602008-10-29 10:16:30 +05302379 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002380
Sujithf1dc5602008-10-29 10:16:30 +05302381 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
2382 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
2383 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
2384 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
2385 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
2386 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
2387 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
2388 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
2389
2390 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2391 u16 micentry = entry + 64;
2392
2393 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
2394 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
2395 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
2396 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
2397
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002398 }
2399
Sujith2660b812009-02-09 13:27:26 +05302400 if (ah->curchan == NULL)
Sujithf1dc5602008-10-29 10:16:30 +05302401 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002402
2403 return true;
2404}
2405
Sujithcbe61d82009-02-09 13:27:12 +05302406bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002407{
Sujithf1dc5602008-10-29 10:16:30 +05302408 u32 macHi, macLo;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002409
Sujith2660b812009-02-09 13:27:26 +05302410 if (entry >= ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05302411 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
Sujith04bd46382008-11-28 22:18:05 +05302412 "entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002413 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002414 }
2415
Sujithf1dc5602008-10-29 10:16:30 +05302416 if (mac != NULL) {
2417 macHi = (mac[5] << 8) | mac[4];
2418 macLo = (mac[3] << 24) |
2419 (mac[2] << 16) |
2420 (mac[1] << 8) |
2421 mac[0];
2422 macLo >>= 1;
2423 macLo |= (macHi & 1) << 31;
2424 macHi >>= 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002425 } else {
Sujithf1dc5602008-10-29 10:16:30 +05302426 macLo = macHi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002427 }
Sujithf1dc5602008-10-29 10:16:30 +05302428 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
2429 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002430
2431 return true;
2432}
2433
Sujithcbe61d82009-02-09 13:27:12 +05302434bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
Sujithf1dc5602008-10-29 10:16:30 +05302435 const struct ath9k_keyval *k,
Jouni Malinene0caf9e2009-03-02 18:15:53 +02002436 const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002437{
Sujith2660b812009-02-09 13:27:26 +05302438 const struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +05302439 u32 key0, key1, key2, key3, key4;
2440 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002441
Sujithf1dc5602008-10-29 10:16:30 +05302442 if (entry >= pCap->keycache_size) {
2443 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
Sujith04bd46382008-11-28 22:18:05 +05302444 "entry %u out of range\n", entry);
Sujithf1dc5602008-10-29 10:16:30 +05302445 return false;
2446 }
2447
2448 switch (k->kv_type) {
2449 case ATH9K_CIPHER_AES_OCB:
2450 keyType = AR_KEYTABLE_TYPE_AES;
2451 break;
2452 case ATH9K_CIPHER_AES_CCM:
2453 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
2454 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
Sujith04bd46382008-11-28 22:18:05 +05302455 "AES-CCM not supported by mac rev 0x%x\n",
Sujithd535a422009-02-09 13:27:06 +05302456 ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002457 return false;
2458 }
Sujithf1dc5602008-10-29 10:16:30 +05302459 keyType = AR_KEYTABLE_TYPE_CCM;
2460 break;
2461 case ATH9K_CIPHER_TKIP:
2462 keyType = AR_KEYTABLE_TYPE_TKIP;
2463 if (ATH9K_IS_MIC_ENABLED(ah)
2464 && entry + 64 >= pCap->keycache_size) {
2465 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
Sujith04bd46382008-11-28 22:18:05 +05302466 "entry %u inappropriate for TKIP\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002467 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002468 }
Sujithf1dc5602008-10-29 10:16:30 +05302469 break;
2470 case ATH9K_CIPHER_WEP:
2471 if (k->kv_len < LEN_WEP40) {
2472 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
Sujith04bd46382008-11-28 22:18:05 +05302473 "WEP key length %u too small\n", k->kv_len);
Sujithf1dc5602008-10-29 10:16:30 +05302474 return false;
2475 }
2476 if (k->kv_len <= LEN_WEP40)
2477 keyType = AR_KEYTABLE_TYPE_40;
2478 else if (k->kv_len <= LEN_WEP104)
2479 keyType = AR_KEYTABLE_TYPE_104;
2480 else
2481 keyType = AR_KEYTABLE_TYPE_128;
2482 break;
2483 case ATH9K_CIPHER_CLR:
2484 keyType = AR_KEYTABLE_TYPE_CLR;
2485 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002486 default:
Sujithf1dc5602008-10-29 10:16:30 +05302487 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
Sujith04bd46382008-11-28 22:18:05 +05302488 "cipher %u not supported\n", k->kv_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002489 return false;
2490 }
Sujithf1dc5602008-10-29 10:16:30 +05302491
Jouni Malinene0caf9e2009-03-02 18:15:53 +02002492 key0 = get_unaligned_le32(k->kv_val + 0);
2493 key1 = get_unaligned_le16(k->kv_val + 4);
2494 key2 = get_unaligned_le32(k->kv_val + 6);
2495 key3 = get_unaligned_le16(k->kv_val + 10);
2496 key4 = get_unaligned_le32(k->kv_val + 12);
Sujithf1dc5602008-10-29 10:16:30 +05302497 if (k->kv_len <= LEN_WEP104)
2498 key4 &= 0xff;
2499
Jouni Malinen672903b2009-03-02 15:06:31 +02002500 /*
2501 * Note: Key cache registers access special memory area that requires
2502 * two 32-bit writes to actually update the values in the internal
2503 * memory. Consequently, the exact order and pairs used here must be
2504 * maintained.
2505 */
2506
Sujithf1dc5602008-10-29 10:16:30 +05302507 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2508 u16 micentry = entry + 64;
2509
Jouni Malinen672903b2009-03-02 15:06:31 +02002510 /*
2511 * Write inverted key[47:0] first to avoid Michael MIC errors
2512 * on frames that could be sent or received at the same time.
2513 * The correct key will be written in the end once everything
2514 * else is ready.
2515 */
Sujithf1dc5602008-10-29 10:16:30 +05302516 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
2517 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002518
2519 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302520 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2521 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002522
2523 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302524 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2525 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
Jouni Malinen672903b2009-03-02 15:06:31 +02002526
2527 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302528 (void) ath9k_hw_keysetmac(ah, entry, mac);
2529
Sujith2660b812009-02-09 13:27:26 +05302530 if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) {
Jouni Malinen672903b2009-03-02 15:06:31 +02002531 /*
2532 * TKIP uses two key cache entries:
2533 * Michael MIC TX/RX keys in the same key cache entry
2534 * (idx = main index + 64):
2535 * key0 [31:0] = RX key [31:0]
2536 * key1 [15:0] = TX key [31:16]
2537 * key1 [31:16] = reserved
2538 * key2 [31:0] = RX key [63:32]
2539 * key3 [15:0] = TX key [15:0]
2540 * key3 [31:16] = reserved
2541 * key4 [31:0] = TX key [63:32]
2542 */
Sujithf1dc5602008-10-29 10:16:30 +05302543 u32 mic0, mic1, mic2, mic3, mic4;
2544
2545 mic0 = get_unaligned_le32(k->kv_mic + 0);
2546 mic2 = get_unaligned_le32(k->kv_mic + 4);
2547 mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
2548 mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
2549 mic4 = get_unaligned_le32(k->kv_txmic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02002550
2551 /* Write RX[31:0] and TX[31:16] */
Sujithf1dc5602008-10-29 10:16:30 +05302552 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2553 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002554
2555 /* Write RX[63:32] and TX[15:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302556 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2557 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002558
2559 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302560 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
2561 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2562 AR_KEYTABLE_TYPE_CLR);
2563
2564 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002565 /*
2566 * TKIP uses four key cache entries (two for group
2567 * keys):
2568 * Michael MIC TX/RX keys are in different key cache
2569 * entries (idx = main index + 64 for TX and
2570 * main index + 32 + 96 for RX):
2571 * key0 [31:0] = TX/RX MIC key [31:0]
2572 * key1 [31:0] = reserved
2573 * key2 [31:0] = TX/RX MIC key [63:32]
2574 * key3 [31:0] = reserved
2575 * key4 [31:0] = reserved
2576 *
2577 * Upper layer code will call this function separately
2578 * for TX and RX keys when these registers offsets are
2579 * used.
2580 */
Sujithf1dc5602008-10-29 10:16:30 +05302581 u32 mic0, mic2;
2582
2583 mic0 = get_unaligned_le32(k->kv_mic + 0);
2584 mic2 = get_unaligned_le32(k->kv_mic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02002585
2586 /* Write MIC key[31:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302587 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2588 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002589
2590 /* Write MIC key[63:32] */
Sujithf1dc5602008-10-29 10:16:30 +05302591 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2592 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002593
2594 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302595 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
2596 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2597 AR_KEYTABLE_TYPE_CLR);
2598 }
Jouni Malinen672903b2009-03-02 15:06:31 +02002599
2600 /* MAC address registers are reserved for the MIC entry */
Sujithf1dc5602008-10-29 10:16:30 +05302601 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
2602 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002603
2604 /*
2605 * Write the correct (un-inverted) key[47:0] last to enable
2606 * TKIP now that all other registers are set with correct
2607 * values.
2608 */
Sujithf1dc5602008-10-29 10:16:30 +05302609 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2610 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
2611 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002612 /* Write key[47:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302613 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2614 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002615
2616 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302617 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2618 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002619
2620 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302621 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2622 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
2623
Jouni Malinen672903b2009-03-02 15:06:31 +02002624 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302625 (void) ath9k_hw_keysetmac(ah, entry, mac);
2626 }
2627
Sujithf1dc5602008-10-29 10:16:30 +05302628 return true;
2629}
2630
Sujithcbe61d82009-02-09 13:27:12 +05302631bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry)
Sujithf1dc5602008-10-29 10:16:30 +05302632{
Sujith2660b812009-02-09 13:27:26 +05302633 if (entry < ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05302634 u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
2635 if (val & AR_KEYTABLE_VALID)
2636 return true;
2637 }
2638 return false;
2639}
2640
2641/******************************/
2642/* Power Management (Chipset) */
2643/******************************/
2644
Sujithcbe61d82009-02-09 13:27:12 +05302645static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302646{
2647 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2648 if (setChip) {
2649 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2650 AR_RTC_FORCE_WAKE_EN);
2651 if (!AR_SREV_9100(ah))
2652 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
2653
Gabor Juhosd03a66c2009-01-14 20:17:09 +01002654 REG_CLR_BIT(ah, (AR_RTC_RESET),
Sujithf1dc5602008-10-29 10:16:30 +05302655 AR_RTC_RESET_EN);
2656 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002657}
2658
Sujithcbe61d82009-02-09 13:27:12 +05302659static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002660{
Sujithf1dc5602008-10-29 10:16:30 +05302661 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2662 if (setChip) {
Sujith2660b812009-02-09 13:27:26 +05302663 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002664
Sujithf1dc5602008-10-29 10:16:30 +05302665 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
2666 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2667 AR_RTC_FORCE_WAKE_ON_INT);
2668 } else {
2669 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2670 AR_RTC_FORCE_WAKE_EN);
2671 }
2672 }
2673}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002674
Sujithcbe61d82009-02-09 13:27:12 +05302675static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302676{
2677 u32 val;
2678 int i;
2679
2680 if (setChip) {
2681 if ((REG_READ(ah, AR_RTC_STATUS) &
2682 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2683 if (ath9k_hw_set_reset_reg(ah,
2684 ATH9K_RESET_POWER_ON) != true) {
2685 return false;
2686 }
2687 }
2688 if (AR_SREV_9100(ah))
2689 REG_SET_BIT(ah, AR_RTC_RESET,
2690 AR_RTC_RESET_EN);
2691
2692 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2693 AR_RTC_FORCE_WAKE_EN);
2694 udelay(50);
2695
2696 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2697 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2698 if (val == AR_RTC_STATUS_ON)
2699 break;
2700 udelay(50);
2701 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2702 AR_RTC_FORCE_WAKE_EN);
2703 }
2704 if (i == 0) {
2705 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
Sujith04bd46382008-11-28 22:18:05 +05302706 "Failed to wakeup in %uus\n", POWER_UP_TIME / 20);
Sujithf1dc5602008-10-29 10:16:30 +05302707 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002708 }
2709 }
2710
Sujithf1dc5602008-10-29 10:16:30 +05302711 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2712
2713 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002714}
2715
Sujithcbe61d82009-02-09 13:27:12 +05302716bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05302717{
Sujithcbe61d82009-02-09 13:27:12 +05302718 int status = true, setChip = true;
Sujithf1dc5602008-10-29 10:16:30 +05302719 static const char *modes[] = {
2720 "AWAKE",
2721 "FULL-SLEEP",
2722 "NETWORK SLEEP",
2723 "UNDEFINED"
2724 };
Sujithf1dc5602008-10-29 10:16:30 +05302725
Sujith04bd46382008-11-28 22:18:05 +05302726 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT, "%s -> %s (%s)\n",
Sujith2660b812009-02-09 13:27:26 +05302727 modes[ah->power_mode], modes[mode],
Sujithf1dc5602008-10-29 10:16:30 +05302728 setChip ? "set chip " : "");
2729
2730 switch (mode) {
2731 case ATH9K_PM_AWAKE:
2732 status = ath9k_hw_set_power_awake(ah, setChip);
2733 break;
2734 case ATH9K_PM_FULL_SLEEP:
2735 ath9k_set_power_sleep(ah, setChip);
Sujith2660b812009-02-09 13:27:26 +05302736 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05302737 break;
2738 case ATH9K_PM_NETWORK_SLEEP:
2739 ath9k_set_power_network_sleep(ah, setChip);
2740 break;
2741 default:
2742 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
Sujith04bd46382008-11-28 22:18:05 +05302743 "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05302744 return false;
2745 }
Sujith2660b812009-02-09 13:27:26 +05302746 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05302747
2748 return status;
2749}
2750
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002751/*
2752 * Helper for ASPM support.
2753 *
2754 * Disable PLL when in L0s as well as receiver clock when in L1.
2755 * This power saving option must be enabled through the SerDes.
2756 *
2757 * Programming the SerDes must go through the same 288 bit serial shift
2758 * register as the other analog registers. Hence the 9 writes.
2759 */
Sujithcbe61d82009-02-09 13:27:12 +05302760void ath9k_hw_configpcipowersave(struct ath_hw *ah, int restore)
Sujithf1dc5602008-10-29 10:16:30 +05302761{
Sujithf1dc5602008-10-29 10:16:30 +05302762 u8 i;
2763
Sujith2660b812009-02-09 13:27:26 +05302764 if (ah->is_pciexpress != true)
Sujithf1dc5602008-10-29 10:16:30 +05302765 return;
2766
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002767 /* Do not touch SerDes registers */
Sujith2660b812009-02-09 13:27:26 +05302768 if (ah->config.pcie_powersave_enable == 2)
Sujithf1dc5602008-10-29 10:16:30 +05302769 return;
2770
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002771 /* Nothing to do on restore for 11N */
Sujithf1dc5602008-10-29 10:16:30 +05302772 if (restore)
2773 return;
2774
2775 if (AR_SREV_9280_20_OR_LATER(ah)) {
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002776 /*
2777 * AR9280 2.0 or later chips use SerDes values from the
2778 * initvals.h initialized depending on chipset during
2779 * ath9k_hw_do_attach()
2780 */
Sujith2660b812009-02-09 13:27:26 +05302781 for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
2782 REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
2783 INI_RA(&ah->iniPcieSerdes, i, 1));
Sujithf1dc5602008-10-29 10:16:30 +05302784 }
Sujithf1dc5602008-10-29 10:16:30 +05302785 } else if (AR_SREV_9280(ah) &&
Sujithd535a422009-02-09 13:27:06 +05302786 (ah->hw_version.macRev == AR_SREV_REVISION_9280_10)) {
Sujithf1dc5602008-10-29 10:16:30 +05302787 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
2788 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
2789
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002790 /* RX shut off when elecidle is asserted */
Sujithf1dc5602008-10-29 10:16:30 +05302791 REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
2792 REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
2793 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
2794
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002795 /* Shut off CLKREQ active in L1 */
Sujith2660b812009-02-09 13:27:26 +05302796 if (ah->config.pcie_clock_req)
Sujithf1dc5602008-10-29 10:16:30 +05302797 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
2798 else
2799 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
2800
2801 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2802 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2803 REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
2804
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002805 /* Load the new settings */
Sujithf1dc5602008-10-29 10:16:30 +05302806 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
2807
Sujithf1dc5602008-10-29 10:16:30 +05302808 } else {
2809 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
2810 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002811
2812 /* RX shut off when elecidle is asserted */
Sujithf1dc5602008-10-29 10:16:30 +05302813 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
2814 REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
2815 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002816
2817 /*
2818 * Ignore ah->ah_config.pcie_clock_req setting for
2819 * pre-AR9280 11n
2820 */
Sujithf1dc5602008-10-29 10:16:30 +05302821 REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002822
Sujithf1dc5602008-10-29 10:16:30 +05302823 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2824 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2825 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002826
2827 /* Load the new settings */
Sujithf1dc5602008-10-29 10:16:30 +05302828 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
2829 }
2830
Luis R. Rodriguez6d08b9b2009-02-10 15:35:27 -08002831 udelay(1000);
2832
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002833 /* set bit 19 to allow forcing of pcie core into L1 state */
Sujithf1dc5602008-10-29 10:16:30 +05302834 REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
2835
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002836 /* Several PCIe massages to ensure proper behaviour */
Sujith2660b812009-02-09 13:27:26 +05302837 if (ah->config.pcie_waen) {
2838 REG_WRITE(ah, AR_WA, ah->config.pcie_waen);
Sujithf1dc5602008-10-29 10:16:30 +05302839 } else {
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302840 if (AR_SREV_9285(ah))
2841 REG_WRITE(ah, AR_WA, AR9285_WA_DEFAULT);
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002842 /*
2843 * On AR9280 chips bit 22 of 0x4004 needs to be set to
2844 * otherwise card may disappear.
2845 */
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302846 else if (AR_SREV_9280(ah))
2847 REG_WRITE(ah, AR_WA, AR9280_WA_DEFAULT);
Sujithf1dc5602008-10-29 10:16:30 +05302848 else
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302849 REG_WRITE(ah, AR_WA, AR_WA_DEFAULT);
Sujithf1dc5602008-10-29 10:16:30 +05302850 }
2851}
2852
2853/**********************/
2854/* Interrupt Handling */
2855/**********************/
2856
Sujithcbe61d82009-02-09 13:27:12 +05302857bool ath9k_hw_intrpend(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002858{
2859 u32 host_isr;
2860
2861 if (AR_SREV_9100(ah))
2862 return true;
2863
2864 host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
2865 if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
2866 return true;
2867
2868 host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
2869 if ((host_isr & AR_INTR_SYNC_DEFAULT)
2870 && (host_isr != AR_INTR_SPURIOUS))
2871 return true;
2872
2873 return false;
2874}
2875
Sujithcbe61d82009-02-09 13:27:12 +05302876bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002877{
2878 u32 isr = 0;
2879 u32 mask2 = 0;
Sujith2660b812009-02-09 13:27:26 +05302880 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002881 u32 sync_cause = 0;
2882 bool fatal_int = false;
2883
2884 if (!AR_SREV_9100(ah)) {
2885 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
2886 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
2887 == AR_RTC_STATUS_ON) {
2888 isr = REG_READ(ah, AR_ISR);
2889 }
2890 }
2891
Sujithf1dc5602008-10-29 10:16:30 +05302892 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
2893 AR_INTR_SYNC_DEFAULT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002894
2895 *masked = 0;
2896
2897 if (!isr && !sync_cause)
2898 return false;
2899 } else {
2900 *masked = 0;
2901 isr = REG_READ(ah, AR_ISR);
2902 }
2903
2904 if (isr) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002905 if (isr & AR_ISR_BCNMISC) {
2906 u32 isr2;
2907 isr2 = REG_READ(ah, AR_ISR_S2);
2908 if (isr2 & AR_ISR_S2_TIM)
2909 mask2 |= ATH9K_INT_TIM;
2910 if (isr2 & AR_ISR_S2_DTIM)
2911 mask2 |= ATH9K_INT_DTIM;
2912 if (isr2 & AR_ISR_S2_DTIMSYNC)
2913 mask2 |= ATH9K_INT_DTIMSYNC;
2914 if (isr2 & (AR_ISR_S2_CABEND))
2915 mask2 |= ATH9K_INT_CABEND;
2916 if (isr2 & AR_ISR_S2_GTT)
2917 mask2 |= ATH9K_INT_GTT;
2918 if (isr2 & AR_ISR_S2_CST)
2919 mask2 |= ATH9K_INT_CST;
Sujith4af9cf42009-02-12 10:06:47 +05302920 if (isr2 & AR_ISR_S2_TSFOOR)
2921 mask2 |= ATH9K_INT_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002922 }
2923
2924 isr = REG_READ(ah, AR_ISR_RAC);
2925 if (isr == 0xffffffff) {
2926 *masked = 0;
2927 return false;
2928 }
2929
2930 *masked = isr & ATH9K_INT_COMMON;
2931
Sujith2660b812009-02-09 13:27:26 +05302932 if (ah->intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002933 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
2934 *masked |= ATH9K_INT_RX;
2935 }
2936
2937 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
2938 *masked |= ATH9K_INT_RX;
2939 if (isr &
2940 (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
2941 AR_ISR_TXEOL)) {
2942 u32 s0_s, s1_s;
2943
2944 *masked |= ATH9K_INT_TX;
2945
2946 s0_s = REG_READ(ah, AR_ISR_S0_S);
Sujith2660b812009-02-09 13:27:26 +05302947 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
2948 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002949
2950 s1_s = REG_READ(ah, AR_ISR_S1_S);
Sujith2660b812009-02-09 13:27:26 +05302951 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
2952 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002953 }
2954
2955 if (isr & AR_ISR_RXORN) {
2956 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
Sujith04bd46382008-11-28 22:18:05 +05302957 "receive FIFO overrun interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002958 }
2959
2960 if (!AR_SREV_9100(ah)) {
Sujith60b67f52008-08-07 10:52:38 +05302961 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002962 u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
2963 if (isr5 & AR_ISR_S5_TIM_TIMER)
2964 *masked |= ATH9K_INT_TIM_TIMER;
2965 }
2966 }
2967
2968 *masked |= mask2;
2969 }
Sujithf1dc5602008-10-29 10:16:30 +05302970
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002971 if (AR_SREV_9100(ah))
2972 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302973
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002974 if (sync_cause) {
2975 fatal_int =
2976 (sync_cause &
2977 (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
2978 ? true : false;
2979
2980 if (fatal_int) {
2981 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
2982 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
Sujith04bd46382008-11-28 22:18:05 +05302983 "received PCI FATAL interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002984 }
2985 if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
2986 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
Sujith04bd46382008-11-28 22:18:05 +05302987 "received PCI PERR interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002988 }
2989 }
2990 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
2991 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
Sujith04bd46382008-11-28 22:18:05 +05302992 "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002993 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
2994 REG_WRITE(ah, AR_RC, 0);
2995 *masked |= ATH9K_INT_FATAL;
2996 }
2997 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
2998 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
Sujith04bd46382008-11-28 22:18:05 +05302999 "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003000 }
3001
3002 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
3003 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
3004 }
Sujithf1dc5602008-10-29 10:16:30 +05303005
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003006 return true;
3007}
3008
Sujithcbe61d82009-02-09 13:27:12 +05303009enum ath9k_int ath9k_hw_intrget(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003010{
Sujith2660b812009-02-09 13:27:26 +05303011 return ah->mask_reg;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003012}
3013
Sujithcbe61d82009-02-09 13:27:12 +05303014enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003015{
Sujith2660b812009-02-09 13:27:26 +05303016 u32 omask = ah->mask_reg;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003017 u32 mask, mask2;
Sujith2660b812009-02-09 13:27:26 +05303018 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003019
Sujith04bd46382008-11-28 22:18:05 +05303020 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003021
3022 if (omask & ATH9K_INT_GLOBAL) {
Sujith04bd46382008-11-28 22:18:05 +05303023 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "disable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003024 REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
3025 (void) REG_READ(ah, AR_IER);
3026 if (!AR_SREV_9100(ah)) {
3027 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
3028 (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
3029
3030 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
3031 (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
3032 }
3033 }
3034
3035 mask = ints & ATH9K_INT_COMMON;
3036 mask2 = 0;
3037
3038 if (ints & ATH9K_INT_TX) {
Sujith2660b812009-02-09 13:27:26 +05303039 if (ah->txok_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003040 mask |= AR_IMR_TXOK;
Sujith2660b812009-02-09 13:27:26 +05303041 if (ah->txdesc_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003042 mask |= AR_IMR_TXDESC;
Sujith2660b812009-02-09 13:27:26 +05303043 if (ah->txerr_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003044 mask |= AR_IMR_TXERR;
Sujith2660b812009-02-09 13:27:26 +05303045 if (ah->txeol_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003046 mask |= AR_IMR_TXEOL;
3047 }
3048 if (ints & ATH9K_INT_RX) {
3049 mask |= AR_IMR_RXERR;
Sujith2660b812009-02-09 13:27:26 +05303050 if (ah->intr_mitigation)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003051 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
3052 else
3053 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
Sujith60b67f52008-08-07 10:52:38 +05303054 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003055 mask |= AR_IMR_GENTMR;
3056 }
3057
3058 if (ints & (ATH9K_INT_BMISC)) {
3059 mask |= AR_IMR_BCNMISC;
3060 if (ints & ATH9K_INT_TIM)
3061 mask2 |= AR_IMR_S2_TIM;
3062 if (ints & ATH9K_INT_DTIM)
3063 mask2 |= AR_IMR_S2_DTIM;
3064 if (ints & ATH9K_INT_DTIMSYNC)
3065 mask2 |= AR_IMR_S2_DTIMSYNC;
3066 if (ints & ATH9K_INT_CABEND)
Sujith4af9cf42009-02-12 10:06:47 +05303067 mask2 |= AR_IMR_S2_CABEND;
3068 if (ints & ATH9K_INT_TSFOOR)
3069 mask2 |= AR_IMR_S2_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003070 }
3071
3072 if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
3073 mask |= AR_IMR_BCNMISC;
3074 if (ints & ATH9K_INT_GTT)
3075 mask2 |= AR_IMR_S2_GTT;
3076 if (ints & ATH9K_INT_CST)
3077 mask2 |= AR_IMR_S2_CST;
3078 }
3079
Sujith04bd46382008-11-28 22:18:05 +05303080 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003081 REG_WRITE(ah, AR_IMR, mask);
3082 mask = REG_READ(ah, AR_IMR_S2) & ~(AR_IMR_S2_TIM |
3083 AR_IMR_S2_DTIM |
3084 AR_IMR_S2_DTIMSYNC |
3085 AR_IMR_S2_CABEND |
3086 AR_IMR_S2_CABTO |
3087 AR_IMR_S2_TSFOOR |
3088 AR_IMR_S2_GTT | AR_IMR_S2_CST);
3089 REG_WRITE(ah, AR_IMR_S2, mask | mask2);
Sujith2660b812009-02-09 13:27:26 +05303090 ah->mask_reg = ints;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003091
Sujith60b67f52008-08-07 10:52:38 +05303092 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003093 if (ints & ATH9K_INT_TIM_TIMER)
3094 REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
3095 else
3096 REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
3097 }
3098
3099 if (ints & ATH9K_INT_GLOBAL) {
Sujith04bd46382008-11-28 22:18:05 +05303100 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "enable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003101 REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
3102 if (!AR_SREV_9100(ah)) {
3103 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
3104 AR_INTR_MAC_IRQ);
3105 REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
3106
3107
3108 REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
3109 AR_INTR_SYNC_DEFAULT);
3110 REG_WRITE(ah, AR_INTR_SYNC_MASK,
3111 AR_INTR_SYNC_DEFAULT);
3112 }
3113 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
3114 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
3115 }
3116
3117 return omask;
3118}
3119
Sujithf1dc5602008-10-29 10:16:30 +05303120/*******************/
3121/* Beacon Handling */
3122/*******************/
3123
Sujithcbe61d82009-02-09 13:27:12 +05303124void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003125{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003126 int flags = 0;
3127
Sujith2660b812009-02-09 13:27:26 +05303128 ah->beacon_interval = beacon_period;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003129
Sujith2660b812009-02-09 13:27:26 +05303130 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08003131 case NL80211_IFTYPE_STATION:
3132 case NL80211_IFTYPE_MONITOR:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003133 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3134 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
3135 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
3136 flags |= AR_TBTT_TIMER_EN;
3137 break;
Colin McCabed97809d2008-12-01 13:38:55 -08003138 case NL80211_IFTYPE_ADHOC:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003139 REG_SET_BIT(ah, AR_TXCFG,
3140 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
3141 REG_WRITE(ah, AR_NEXT_NDP_TIMER,
3142 TU_TO_USEC(next_beacon +
Sujith2660b812009-02-09 13:27:26 +05303143 (ah->atim_window ? ah->
3144 atim_window : 1)));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003145 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08003146 case NL80211_IFTYPE_AP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003147 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3148 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
3149 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05303150 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05303151 dma_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003152 REG_WRITE(ah, AR_NEXT_SWBA,
3153 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05303154 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05303155 sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003156 flags |=
3157 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
3158 break;
Colin McCabed97809d2008-12-01 13:38:55 -08003159 default:
3160 DPRINTF(ah->ah_sc, ATH_DBG_BEACON,
3161 "%s: unsupported opmode: %d\n",
Sujith2660b812009-02-09 13:27:26 +05303162 __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08003163 return;
3164 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003165 }
3166
3167 REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3168 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3169 REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
3170 REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
3171
3172 beacon_period &= ~ATH9K_BEACON_ENA;
3173 if (beacon_period & ATH9K_BEACON_RESET_TSF) {
3174 beacon_period &= ~ATH9K_BEACON_RESET_TSF;
3175 ath9k_hw_reset_tsf(ah);
3176 }
3177
3178 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
3179}
3180
Sujithcbe61d82009-02-09 13:27:12 +05303181void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303182 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003183{
3184 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05303185 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003186
3187 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
3188
3189 REG_WRITE(ah, AR_BEACON_PERIOD,
3190 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3191 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
3192 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3193
3194 REG_RMW_FIELD(ah, AR_RSSI_THR,
3195 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
3196
3197 beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
3198
3199 if (bs->bs_sleepduration > beaconintval)
3200 beaconintval = bs->bs_sleepduration;
3201
3202 dtimperiod = bs->bs_dtimperiod;
3203 if (bs->bs_sleepduration > dtimperiod)
3204 dtimperiod = bs->bs_sleepduration;
3205
3206 if (beaconintval == dtimperiod)
3207 nextTbtt = bs->bs_nextdtim;
3208 else
3209 nextTbtt = bs->bs_nexttbtt;
3210
Sujith04bd46382008-11-28 22:18:05 +05303211 DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
3212 DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
3213 DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
3214 DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003215
3216 REG_WRITE(ah, AR_NEXT_DTIM,
3217 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
3218 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
3219
3220 REG_WRITE(ah, AR_SLEEP1,
3221 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
3222 | AR_SLEEP1_ASSUME_DTIM);
3223
Sujith60b67f52008-08-07 10:52:38 +05303224 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003225 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
3226 else
3227 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
3228
3229 REG_WRITE(ah, AR_SLEEP2,
3230 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
3231
3232 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
3233 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
3234
3235 REG_SET_BIT(ah, AR_TIMER_MODE,
3236 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
3237 AR_DTIM_TIMER_EN);
3238
Sujith4af9cf42009-02-12 10:06:47 +05303239 /* TSF Out of Range Threshold */
3240 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003241}
3242
Sujithf1dc5602008-10-29 10:16:30 +05303243/*******************/
3244/* HW Capabilities */
3245/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003246
Sujithcbe61d82009-02-09 13:27:12 +05303247bool ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003248{
Sujith2660b812009-02-09 13:27:26 +05303249 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +05303250 u16 capField = 0, eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003251
Sujithf74df6f2009-02-09 13:27:24 +05303252 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Sujithd6bad492009-02-09 13:27:08 +05303253 ah->regulatory.current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303254
Sujithf74df6f2009-02-09 13:27:24 +05303255 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
Sujithfec0de12009-02-12 10:06:43 +05303256 if (AR_SREV_9285_10_OR_LATER(ah))
3257 eeval |= AR9285_RDEXT_DEFAULT;
Sujithd6bad492009-02-09 13:27:08 +05303258 ah->regulatory.current_rd_ext = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303259
Sujithf74df6f2009-02-09 13:27:24 +05303260 capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
Sujithf1dc5602008-10-29 10:16:30 +05303261
Sujith2660b812009-02-09 13:27:26 +05303262 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05303263 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Sujithd6bad492009-02-09 13:27:08 +05303264 if (ah->regulatory.current_rd == 0x64 ||
3265 ah->regulatory.current_rd == 0x65)
3266 ah->regulatory.current_rd += 5;
3267 else if (ah->regulatory.current_rd == 0x41)
3268 ah->regulatory.current_rd = 0x43;
Sujithf1dc5602008-10-29 10:16:30 +05303269 DPRINTF(ah->ah_sc, ATH_DBG_REGULATORY,
Sujithd6bad492009-02-09 13:27:08 +05303270 "regdomain mapped to 0x%x\n", ah->regulatory.current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003271 }
Sujithdc2222a2008-08-14 13:26:55 +05303272
Sujithf74df6f2009-02-09 13:27:24 +05303273 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Sujithf1dc5602008-10-29 10:16:30 +05303274 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003275
Sujithf1dc5602008-10-29 10:16:30 +05303276 if (eeval & AR5416_OPFLAGS_11A) {
3277 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303278 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303279 if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
3280 set_bit(ATH9K_MODE_11NA_HT20,
3281 pCap->wireless_modes);
3282 if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
3283 set_bit(ATH9K_MODE_11NA_HT40PLUS,
3284 pCap->wireless_modes);
3285 set_bit(ATH9K_MODE_11NA_HT40MINUS,
3286 pCap->wireless_modes);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003287 }
3288 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003289 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003290
Sujithf1dc5602008-10-29 10:16:30 +05303291 if (eeval & AR5416_OPFLAGS_11G) {
3292 set_bit(ATH9K_MODE_11B, pCap->wireless_modes);
3293 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303294 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303295 if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
3296 set_bit(ATH9K_MODE_11NG_HT20,
3297 pCap->wireless_modes);
3298 if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
3299 set_bit(ATH9K_MODE_11NG_HT40PLUS,
3300 pCap->wireless_modes);
3301 set_bit(ATH9K_MODE_11NG_HT40MINUS,
3302 pCap->wireless_modes);
3303 }
3304 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003305 }
Sujithf1dc5602008-10-29 10:16:30 +05303306
Sujithf74df6f2009-02-09 13:27:24 +05303307 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Sujith8147f5d2009-02-20 15:13:23 +05303308 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
3309 !(eeval & AR5416_OPFLAGS_11A))
3310 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
3311 else
3312 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05303313
Sujithd535a422009-02-09 13:27:06 +05303314 if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0)))
Sujith2660b812009-02-09 13:27:26 +05303315 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05303316
3317 pCap->low_2ghz_chan = 2312;
3318 pCap->high_2ghz_chan = 2732;
3319
3320 pCap->low_5ghz_chan = 4920;
3321 pCap->high_5ghz_chan = 6100;
3322
3323 pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
3324 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
3325 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
3326
3327 pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
3328 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
3329 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
3330
3331 pCap->hw_caps |= ATH9K_HW_CAP_CHAN_SPREAD;
3332
Sujith2660b812009-02-09 13:27:26 +05303333 if (ah->config.ht_enable)
Sujithf1dc5602008-10-29 10:16:30 +05303334 pCap->hw_caps |= ATH9K_HW_CAP_HT;
3335 else
3336 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
3337
3338 pCap->hw_caps |= ATH9K_HW_CAP_GTT;
3339 pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
3340 pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
3341 pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
3342
3343 if (capField & AR_EEPROM_EEPCAP_MAXQCU)
3344 pCap->total_queues =
3345 MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
3346 else
3347 pCap->total_queues = ATH9K_NUM_TX_QUEUES;
3348
3349 if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
3350 pCap->keycache_size =
3351 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
3352 else
3353 pCap->keycache_size = AR_KEYTABLE_SIZE;
3354
3355 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
3356 pCap->num_mr_retries = 4;
3357 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
3358
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303359 if (AR_SREV_9285_10_OR_LATER(ah))
3360 pCap->num_gpio_pins = AR9285_NUM_GPIO;
3361 else if (AR_SREV_9280_10_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303362 pCap->num_gpio_pins = AR928X_NUM_GPIO;
3363 else
3364 pCap->num_gpio_pins = AR_NUM_GPIO;
3365
3366 if (AR_SREV_9280_10_OR_LATER(ah)) {
3367 pCap->hw_caps |= ATH9K_HW_CAP_WOW;
3368 pCap->hw_caps |= ATH9K_HW_CAP_WOW_MATCHPATTERN_EXACT;
3369 } else {
3370 pCap->hw_caps &= ~ATH9K_HW_CAP_WOW;
3371 pCap->hw_caps &= ~ATH9K_HW_CAP_WOW_MATCHPATTERN_EXACT;
3372 }
3373
3374 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
3375 pCap->hw_caps |= ATH9K_HW_CAP_CST;
3376 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
3377 } else {
3378 pCap->rts_aggr_limit = (8 * 1024);
3379 }
3380
3381 pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
3382
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05303383#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05303384 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
3385 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
3386 ah->rfkill_gpio =
3387 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
3388 ah->rfkill_polarity =
3389 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05303390
3391 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
3392 }
3393#endif
3394
Sujithd535a422009-02-09 13:27:06 +05303395 if ((ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI) ||
3396 (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE) ||
3397 (ah->hw_version.macVersion == AR_SREV_VERSION_9160) ||
3398 (ah->hw_version.macVersion == AR_SREV_VERSION_9100) ||
3399 (ah->hw_version.macVersion == AR_SREV_VERSION_9280))
Sujithf1dc5602008-10-29 10:16:30 +05303400 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
3401 else
3402 pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
3403
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05303404 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303405 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
3406 else
3407 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
3408
Sujithd6bad492009-02-09 13:27:08 +05303409 if (ah->regulatory.current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) {
Sujithf1dc5602008-10-29 10:16:30 +05303410 pCap->reg_cap =
3411 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3412 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
3413 AR_EEPROM_EEREGCAP_EN_KK_U2 |
3414 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
3415 } else {
3416 pCap->reg_cap =
3417 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3418 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
3419 }
3420
3421 pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
3422
3423 pCap->num_antcfg_5ghz =
Sujithf74df6f2009-02-09 13:27:24 +05303424 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303425 pCap->num_antcfg_2ghz =
Sujithf74df6f2009-02-09 13:27:24 +05303426 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303427
Vasanthakumar Thiagarajan138ab2e2009-01-10 17:07:09 +05303428 if (AR_SREV_9280_10_OR_LATER(ah) && btcoex_enable) {
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303429 pCap->hw_caps |= ATH9K_HW_CAP_BT_COEX;
Sujith2660b812009-02-09 13:27:26 +05303430 ah->btactive_gpio = 6;
3431 ah->wlanactive_gpio = 5;
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303432 }
3433
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003434 return true;
3435}
3436
Sujithcbe61d82009-02-09 13:27:12 +05303437bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303438 u32 capability, u32 *result)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003439{
Sujithf1dc5602008-10-29 10:16:30 +05303440 switch (type) {
3441 case ATH9K_CAP_CIPHER:
3442 switch (capability) {
3443 case ATH9K_CIPHER_AES_CCM:
3444 case ATH9K_CIPHER_AES_OCB:
3445 case ATH9K_CIPHER_TKIP:
3446 case ATH9K_CIPHER_WEP:
3447 case ATH9K_CIPHER_MIC:
3448 case ATH9K_CIPHER_CLR:
3449 return true;
3450 default:
3451 return false;
3452 }
3453 case ATH9K_CAP_TKIP_MIC:
3454 switch (capability) {
3455 case 0:
3456 return true;
3457 case 1:
Sujith2660b812009-02-09 13:27:26 +05303458 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303459 AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
3460 false;
3461 }
3462 case ATH9K_CAP_TKIP_SPLIT:
Sujith2660b812009-02-09 13:27:26 +05303463 return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ?
Sujithf1dc5602008-10-29 10:16:30 +05303464 false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303465 case ATH9K_CAP_DIVERSITY:
3466 return (REG_READ(ah, AR_PHY_CCK_DETECT) &
3467 AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV) ?
3468 true : false;
Sujithf1dc5602008-10-29 10:16:30 +05303469 case ATH9K_CAP_MCAST_KEYSRCH:
3470 switch (capability) {
3471 case 0:
3472 return true;
3473 case 1:
3474 if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
3475 return false;
3476 } else {
Sujith2660b812009-02-09 13:27:26 +05303477 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303478 AR_STA_ID1_MCAST_KSRCH) ? true :
3479 false;
3480 }
3481 }
3482 return false;
Sujithf1dc5602008-10-29 10:16:30 +05303483 case ATH9K_CAP_TXPOW:
3484 switch (capability) {
3485 case 0:
3486 return 0;
3487 case 1:
Sujithd6bad492009-02-09 13:27:08 +05303488 *result = ah->regulatory.power_limit;
Sujithf1dc5602008-10-29 10:16:30 +05303489 return 0;
3490 case 2:
Sujithd6bad492009-02-09 13:27:08 +05303491 *result = ah->regulatory.max_power_level;
Sujithf1dc5602008-10-29 10:16:30 +05303492 return 0;
3493 case 3:
Sujithd6bad492009-02-09 13:27:08 +05303494 *result = ah->regulatory.tp_scale;
Sujithf1dc5602008-10-29 10:16:30 +05303495 return 0;
3496 }
3497 return false;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05303498 case ATH9K_CAP_DS:
3499 return (AR_SREV_9280_20_OR_LATER(ah) &&
3500 (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1))
3501 ? false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303502 default:
3503 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003504 }
Sujithf1dc5602008-10-29 10:16:30 +05303505}
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003506
Sujithcbe61d82009-02-09 13:27:12 +05303507bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303508 u32 capability, u32 setting, int *status)
3509{
Sujithf1dc5602008-10-29 10:16:30 +05303510 u32 v;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003511
Sujithf1dc5602008-10-29 10:16:30 +05303512 switch (type) {
3513 case ATH9K_CAP_TKIP_MIC:
3514 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303515 ah->sta_id1_defaults |=
Sujithf1dc5602008-10-29 10:16:30 +05303516 AR_STA_ID1_CRPT_MIC_ENABLE;
3517 else
Sujith2660b812009-02-09 13:27:26 +05303518 ah->sta_id1_defaults &=
Sujithf1dc5602008-10-29 10:16:30 +05303519 ~AR_STA_ID1_CRPT_MIC_ENABLE;
3520 return true;
3521 case ATH9K_CAP_DIVERSITY:
3522 v = REG_READ(ah, AR_PHY_CCK_DETECT);
3523 if (setting)
3524 v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3525 else
3526 v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3527 REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
3528 return true;
3529 case ATH9K_CAP_MCAST_KEYSRCH:
3530 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303531 ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303532 else
Sujith2660b812009-02-09 13:27:26 +05303533 ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303534 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303535 default:
3536 return false;
3537 }
3538}
3539
3540/****************************/
3541/* GPIO / RFKILL / Antennae */
3542/****************************/
3543
Sujithcbe61d82009-02-09 13:27:12 +05303544static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303545 u32 gpio, u32 type)
3546{
3547 int addr;
3548 u32 gpio_shift, tmp;
3549
3550 if (gpio > 11)
3551 addr = AR_GPIO_OUTPUT_MUX3;
3552 else if (gpio > 5)
3553 addr = AR_GPIO_OUTPUT_MUX2;
3554 else
3555 addr = AR_GPIO_OUTPUT_MUX1;
3556
3557 gpio_shift = (gpio % 6) * 5;
3558
3559 if (AR_SREV_9280_20_OR_LATER(ah)
3560 || (addr != AR_GPIO_OUTPUT_MUX1)) {
3561 REG_RMW(ah, addr, (type << gpio_shift),
3562 (0x1f << gpio_shift));
3563 } else {
3564 tmp = REG_READ(ah, addr);
3565 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
3566 tmp &= ~(0x1f << gpio_shift);
3567 tmp |= (type << gpio_shift);
3568 REG_WRITE(ah, addr, tmp);
3569 }
3570}
3571
Sujithcbe61d82009-02-09 13:27:12 +05303572void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303573{
3574 u32 gpio_shift;
3575
Sujith2660b812009-02-09 13:27:26 +05303576 ASSERT(gpio < ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05303577
3578 gpio_shift = gpio << 1;
3579
3580 REG_RMW(ah,
3581 AR_GPIO_OE_OUT,
3582 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
3583 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3584}
3585
Sujithcbe61d82009-02-09 13:27:12 +05303586u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303587{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303588#define MS_REG_READ(x, y) \
3589 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
3590
Sujith2660b812009-02-09 13:27:26 +05303591 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05303592 return 0xffffffff;
3593
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303594 if (AR_SREV_9285_10_OR_LATER(ah))
3595 return MS_REG_READ(AR9285, gpio) != 0;
3596 else if (AR_SREV_9280_10_OR_LATER(ah))
3597 return MS_REG_READ(AR928X, gpio) != 0;
3598 else
3599 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05303600}
3601
Sujithcbe61d82009-02-09 13:27:12 +05303602void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05303603 u32 ah_signal_type)
3604{
3605 u32 gpio_shift;
3606
3607 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
3608
3609 gpio_shift = 2 * gpio;
3610
3611 REG_RMW(ah,
3612 AR_GPIO_OE_OUT,
3613 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
3614 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3615}
3616
Sujithcbe61d82009-02-09 13:27:12 +05303617void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05303618{
3619 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
3620 AR_GPIO_BIT(gpio));
3621}
3622
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05303623#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujithcbe61d82009-02-09 13:27:12 +05303624void ath9k_enable_rfkill(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303625{
3626 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
3627 AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
3628
3629 REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2,
3630 AR_GPIO_INPUT_MUX2_RFSILENT);
3631
Sujith2660b812009-02-09 13:27:26 +05303632 ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
Sujithf1dc5602008-10-29 10:16:30 +05303633 REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);
3634}
3635#endif
3636
Sujithcbe61d82009-02-09 13:27:12 +05303637u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303638{
3639 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
3640}
3641
Sujithcbe61d82009-02-09 13:27:12 +05303642void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05303643{
3644 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
3645}
3646
Sujithcbe61d82009-02-09 13:27:12 +05303647bool ath9k_hw_setantennaswitch(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303648 enum ath9k_ant_setting settings,
3649 struct ath9k_channel *chan,
3650 u8 *tx_chainmask,
3651 u8 *rx_chainmask,
3652 u8 *antenna_cfgd)
3653{
Sujithf1dc5602008-10-29 10:16:30 +05303654 static u8 tx_chainmask_cfg, rx_chainmask_cfg;
3655
3656 if (AR_SREV_9280(ah)) {
3657 if (!tx_chainmask_cfg) {
3658
3659 tx_chainmask_cfg = *tx_chainmask;
3660 rx_chainmask_cfg = *rx_chainmask;
3661 }
3662
3663 switch (settings) {
3664 case ATH9K_ANT_FIXED_A:
3665 *tx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3666 *rx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3667 *antenna_cfgd = true;
3668 break;
3669 case ATH9K_ANT_FIXED_B:
Sujith2660b812009-02-09 13:27:26 +05303670 if (ah->caps.tx_chainmask >
Sujithf1dc5602008-10-29 10:16:30 +05303671 ATH9K_ANTENNA1_CHAINMASK) {
3672 *tx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3673 }
3674 *rx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3675 *antenna_cfgd = true;
3676 break;
3677 case ATH9K_ANT_VARIABLE:
3678 *tx_chainmask = tx_chainmask_cfg;
3679 *rx_chainmask = rx_chainmask_cfg;
3680 *antenna_cfgd = true;
3681 break;
3682 default:
3683 break;
3684 }
3685 } else {
Sujith2660b812009-02-09 13:27:26 +05303686 ah->diversity_control = settings;
Sujithf1dc5602008-10-29 10:16:30 +05303687 }
3688
3689 return true;
3690}
3691
3692/*********************/
3693/* General Operation */
3694/*********************/
3695
Sujithcbe61d82009-02-09 13:27:12 +05303696u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303697{
3698 u32 bits = REG_READ(ah, AR_RX_FILTER);
3699 u32 phybits = REG_READ(ah, AR_PHY_ERR);
3700
3701 if (phybits & AR_PHY_ERR_RADAR)
3702 bits |= ATH9K_RX_FILTER_PHYRADAR;
3703 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
3704 bits |= ATH9K_RX_FILTER_PHYERR;
3705
3706 return bits;
3707}
3708
Sujithcbe61d82009-02-09 13:27:12 +05303709void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05303710{
3711 u32 phybits;
3712
3713 REG_WRITE(ah, AR_RX_FILTER, (bits & 0xffff) | AR_RX_COMPR_BAR);
3714 phybits = 0;
3715 if (bits & ATH9K_RX_FILTER_PHYRADAR)
3716 phybits |= AR_PHY_ERR_RADAR;
3717 if (bits & ATH9K_RX_FILTER_PHYERR)
3718 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
3719 REG_WRITE(ah, AR_PHY_ERR, phybits);
3720
3721 if (phybits)
3722 REG_WRITE(ah, AR_RXCFG,
3723 REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
3724 else
3725 REG_WRITE(ah, AR_RXCFG,
3726 REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
3727}
3728
Sujithcbe61d82009-02-09 13:27:12 +05303729bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303730{
3731 return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM);
3732}
3733
Sujithcbe61d82009-02-09 13:27:12 +05303734bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303735{
3736 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
3737 return false;
3738
3739 return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD);
3740}
3741
Sujithcbe61d82009-02-09 13:27:12 +05303742bool ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
Sujithf1dc5602008-10-29 10:16:30 +05303743{
Sujith2660b812009-02-09 13:27:26 +05303744 struct ath9k_channel *chan = ah->curchan;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08003745 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05303746
Sujithd6bad492009-02-09 13:27:08 +05303747 ah->regulatory.power_limit = min(limit, (u32) MAX_RATE_POWER);
Sujithf1dc5602008-10-29 10:16:30 +05303748
Sujithf74df6f2009-02-09 13:27:24 +05303749 if (ah->eep_ops->set_txpower(ah, chan,
3750 ath9k_regd_get_ctl(ah, chan),
3751 channel->max_antenna_gain * 2,
3752 channel->max_power * 2,
3753 min((u32) MAX_RATE_POWER,
3754 (u32) ah->regulatory.power_limit)) != 0)
Sujithf1dc5602008-10-29 10:16:30 +05303755 return false;
3756
3757 return true;
3758}
3759
Sujithcbe61d82009-02-09 13:27:12 +05303760void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac)
Sujithf1dc5602008-10-29 10:16:30 +05303761{
Sujithba52da52009-02-09 13:27:10 +05303762 memcpy(ah->macaddr, mac, ETH_ALEN);
Sujithf1dc5602008-10-29 10:16:30 +05303763}
3764
Sujithcbe61d82009-02-09 13:27:12 +05303765void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303766{
Sujith2660b812009-02-09 13:27:26 +05303767 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05303768}
3769
Sujithcbe61d82009-02-09 13:27:12 +05303770void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05303771{
3772 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
3773 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
3774}
3775
Sujithba52da52009-02-09 13:27:10 +05303776void ath9k_hw_setbssidmask(struct ath_softc *sc)
Sujithf1dc5602008-10-29 10:16:30 +05303777{
Sujithba52da52009-02-09 13:27:10 +05303778 REG_WRITE(sc->sc_ah, AR_BSSMSKL, get_unaligned_le32(sc->bssidmask));
3779 REG_WRITE(sc->sc_ah, AR_BSSMSKU, get_unaligned_le16(sc->bssidmask + 4));
Sujithf1dc5602008-10-29 10:16:30 +05303780}
3781
Sujithba52da52009-02-09 13:27:10 +05303782void ath9k_hw_write_associd(struct ath_softc *sc)
Sujithf1dc5602008-10-29 10:16:30 +05303783{
Sujithba52da52009-02-09 13:27:10 +05303784 REG_WRITE(sc->sc_ah, AR_BSS_ID0, get_unaligned_le32(sc->curbssid));
3785 REG_WRITE(sc->sc_ah, AR_BSS_ID1, get_unaligned_le16(sc->curbssid + 4) |
3786 ((sc->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05303787}
3788
Sujithcbe61d82009-02-09 13:27:12 +05303789u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303790{
3791 u64 tsf;
3792
3793 tsf = REG_READ(ah, AR_TSF_U32);
3794 tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
3795
3796 return tsf;
3797}
3798
Sujithcbe61d82009-02-09 13:27:12 +05303799void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003800{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003801 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01003802 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003803}
3804
Sujithcbe61d82009-02-09 13:27:12 +05303805void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303806{
3807 int count;
3808
3809 count = 0;
3810 while (REG_READ(ah, AR_SLP32_MODE) & AR_SLP32_TSF_WRITE_STATUS) {
3811 count++;
3812 if (count > 10) {
3813 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujith04bd46382008-11-28 22:18:05 +05303814 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
Sujithf1dc5602008-10-29 10:16:30 +05303815 break;
3816 }
3817 udelay(10);
3818 }
3819 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003820}
3821
Sujithcbe61d82009-02-09 13:27:12 +05303822bool ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003823{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003824 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303825 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003826 else
Sujith2660b812009-02-09 13:27:26 +05303827 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Sujithf1dc5602008-10-29 10:16:30 +05303828
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003829 return true;
3830}
3831
Sujithcbe61d82009-02-09 13:27:12 +05303832bool ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003833{
Sujithf1dc5602008-10-29 10:16:30 +05303834 if (us < ATH9K_SLOT_TIME_9 || us > ath9k_hw_mac_to_usec(ah, 0xffff)) {
Sujith04bd46382008-11-28 22:18:05 +05303835 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "bad slot time %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05303836 ah->slottime = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05303837 return false;
3838 } else {
3839 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05303840 ah->slottime = us;
Sujithf1dc5602008-10-29 10:16:30 +05303841 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003842 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003843}
3844
Sujithcbe61d82009-02-09 13:27:12 +05303845void ath9k_hw_set11nmac2040(struct ath_hw *ah, enum ath9k_ht_macmode mode)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003846{
Sujithf1dc5602008-10-29 10:16:30 +05303847 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003848
Sujithf1dc5602008-10-29 10:16:30 +05303849 if (mode == ATH9K_HT_MACMODE_2040 &&
Sujith2660b812009-02-09 13:27:26 +05303850 !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05303851 macmode = AR_2040_JOINED_RX_CLEAR;
3852 else
3853 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003854
Sujithf1dc5602008-10-29 10:16:30 +05303855 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003856}
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303857
3858/***************************/
3859/* Bluetooth Coexistence */
3860/***************************/
3861
Sujithcbe61d82009-02-09 13:27:12 +05303862void ath9k_hw_btcoex_enable(struct ath_hw *ah)
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303863{
3864 /* connect bt_active to baseband */
3865 REG_CLR_BIT(ah, AR_GPIO_INPUT_EN_VAL,
3866 (AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_DEF |
3867 AR_GPIO_INPUT_EN_VAL_BT_FREQUENCY_DEF));
3868
3869 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
3870 AR_GPIO_INPUT_EN_VAL_BT_ACTIVE_BB);
3871
3872 /* Set input mux for bt_active to gpio pin */
3873 REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1,
3874 AR_GPIO_INPUT_MUX1_BT_ACTIVE,
Sujith2660b812009-02-09 13:27:26 +05303875 ah->btactive_gpio);
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303876
3877 /* Configure the desired gpio port for input */
Sujith2660b812009-02-09 13:27:26 +05303878 ath9k_hw_cfg_gpio_input(ah, ah->btactive_gpio);
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303879
3880 /* Configure the desired GPIO port for TX_FRAME output */
Sujith2660b812009-02-09 13:27:26 +05303881 ath9k_hw_cfg_output(ah, ah->wlanactive_gpio,
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303882 AR_GPIO_OUTPUT_MUX_AS_TX_FRAME);
3883}