blob: 22ef93f3d47c8f0aac8d8e8aac5da98235ecfbff [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
Sujithcee075a2009-03-13 09:07:23 +05302 * Copyright (c) 2008-2009 Atheros Communications Inc.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include <linux/io.h>
18#include <asm/unaligned.h>
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 }
Sujith04bd4632008-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:
Sujith04bd4632008-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,
Sujith04bd4632008-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",
Sujith04bd4632008-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,
Sujith04bd4632008-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",
Sujith04bd4632008-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;
Sujith2660b812009-02-09 13:27:26 +0530366 ah->config.pcie_clock_req = 0;
Sujith2660b812009-02-09 13:27:26 +0530367 ah->config.pcie_waen = 0;
368 ah->config.analog_shiftreg = 1;
369 ah->config.ht_enable = 1;
370 ah->config.ofdm_trig_low = 200;
371 ah->config.ofdm_trig_high = 500;
372 ah->config.cck_trig_high = 200;
373 ah->config.cck_trig_low = 100;
374 ah->config.enable_ani = 1;
Sujith2660b812009-02-09 13:27:26 +0530375 ah->config.diversity_control = 0;
376 ah->config.antenna_switch_swap = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700377
378 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujith2660b812009-02-09 13:27:26 +0530379 ah->config.spurchans[i][0] = AR_NO_SPUR;
380 ah->config.spurchans[i][1] = AR_NO_SPUR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700381 }
382
Sujith2660b812009-02-09 13:27:26 +0530383 ah->config.intr_mitigation = 1;
Luis R. Rodriguez61584252009-03-12 18:18:49 -0400384
385 /*
386 * We need this for PCI devices only (Cardbus, PCI, miniPCI)
387 * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
388 * This means we use it for all AR5416 devices, and the few
389 * minor PCI AR9280 devices out there.
390 *
391 * Serialization is required because these devices do not handle
392 * well the case of two concurrent reads/writes due to the latency
393 * involved. During one read/write another read/write can be issued
394 * on another CPU while the previous read/write may still be working
395 * on our hardware, if we hit this case the hardware poops in a loop.
396 * We prevent this by serializing reads and writes.
397 *
398 * This issue is not present on PCI-Express devices or pre-AR5416
399 * devices (legacy, 802.11abg).
400 */
401 if (num_possible_cpus() > 1)
David S. Miller2d6a5e92009-03-17 15:01:30 -0700402 ah->config.serialize_regmode = SER_REG_MODE_AUTO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700403}
404
Sujithcbe61d82009-02-09 13:27:12 +0530405static struct ath_hw *ath9k_hw_newstate(u16 devid, struct ath_softc *sc,
406 int *status)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700407{
Sujithcbe61d82009-02-09 13:27:12 +0530408 struct ath_hw *ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700409
Sujithcbe61d82009-02-09 13:27:12 +0530410 ah = kzalloc(sizeof(struct ath_hw), GFP_KERNEL);
411 if (ah == NULL) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700412 DPRINTF(sc, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +0530413 "Cannot allocate memory for state block\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700414 *status = -ENOMEM;
415 return NULL;
416 }
417
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700418 ah->ah_sc = sc;
Sujithd535a422009-02-09 13:27:06 +0530419 ah->hw_version.magic = AR5416_MAGIC;
Sujithd6bad492009-02-09 13:27:08 +0530420 ah->regulatory.country_code = CTRY_DEFAULT;
Sujithd535a422009-02-09 13:27:06 +0530421 ah->hw_version.devid = devid;
422 ah->hw_version.subvendorid = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700423
424 ah->ah_flags = 0;
425 if ((devid == AR5416_AR9100_DEVID))
Sujithd535a422009-02-09 13:27:06 +0530426 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700427 if (!AR_SREV_9100(ah))
428 ah->ah_flags = AH_USE_EEPROM;
429
Sujithd6bad492009-02-09 13:27:08 +0530430 ah->regulatory.power_limit = MAX_RATE_POWER;
431 ah->regulatory.tp_scale = ATH9K_TP_SCALE_MAX;
Sujith2660b812009-02-09 13:27:26 +0530432 ah->atim_window = 0;
433 ah->diversity_control = ah->config.diversity_control;
434 ah->antenna_switch_swap =
435 ah->config.antenna_switch_swap;
436 ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
437 ah->beacon_interval = 100;
438 ah->enable_32kHz_clock = DONT_USE_32KHZ;
439 ah->slottime = (u32) -1;
440 ah->acktimeout = (u32) -1;
441 ah->ctstimeout = (u32) -1;
442 ah->globaltxtimeout = (u32) -1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700443
Sujith2660b812009-02-09 13:27:26 +0530444 ah->gbeacon_rate = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700445
Sujithcbe61d82009-02-09 13:27:12 +0530446 return ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700447}
448
Sujithcbe61d82009-02-09 13:27:12 +0530449static int ath9k_hw_rfattach(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700450{
451 bool rfStatus = false;
452 int ecode = 0;
453
454 rfStatus = ath9k_hw_init_rf(ah, &ecode);
455 if (!rfStatus) {
456 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +0530457 "RF setup failed, status %u\n", ecode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700458 return ecode;
459 }
460
461 return 0;
462}
463
Sujithcbe61d82009-02-09 13:27:12 +0530464static int ath9k_hw_rf_claim(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700465{
466 u32 val;
467
468 REG_WRITE(ah, AR_PHY(0), 0x00000007);
469
470 val = ath9k_hw_get_radiorev(ah);
471 switch (val & AR_RADIO_SREV_MAJOR) {
472 case 0:
473 val = AR_RAD5133_SREV_MAJOR;
474 break;
475 case AR_RAD5133_SREV_MAJOR:
476 case AR_RAD5122_SREV_MAJOR:
477 case AR_RAD2133_SREV_MAJOR:
478 case AR_RAD2122_SREV_MAJOR:
479 break;
480 default:
481 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
Sujith04bd4632008-11-28 22:18:05 +0530482 "5G Radio Chip Rev 0x%02X is not "
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700483 "supported by this driver\n",
Sujithd535a422009-02-09 13:27:06 +0530484 ah->hw_version.analog5GhzRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700485 return -EOPNOTSUPP;
486 }
487
Sujithd535a422009-02-09 13:27:06 +0530488 ah->hw_version.analog5GhzRev = val;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700489
490 return 0;
491}
492
Sujithcbe61d82009-02-09 13:27:12 +0530493static int ath9k_hw_init_macaddr(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700494{
Sujithf1dc5602008-10-29 10:16:30 +0530495 u32 sum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700496 int i;
Sujithf1dc5602008-10-29 10:16:30 +0530497 u16 eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700498
Sujithf1dc5602008-10-29 10:16:30 +0530499 sum = 0;
500 for (i = 0; i < 3; i++) {
Sujithf74df6f2009-02-09 13:27:24 +0530501 eeval = ah->eep_ops->get_eeprom(ah, AR_EEPROM_MAC(i));
Sujithf1dc5602008-10-29 10:16:30 +0530502 sum += eeval;
Sujithba52da52009-02-09 13:27:10 +0530503 ah->macaddr[2 * i] = eeval >> 8;
504 ah->macaddr[2 * i + 1] = eeval & 0xff;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700505 }
Sujithf1dc5602008-10-29 10:16:30 +0530506 if (sum == 0 || sum == 0xffff * 3) {
507 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
Sujith04bd4632008-11-28 22:18:05 +0530508 "mac address read failed: %pM\n",
Sujithba52da52009-02-09 13:27:10 +0530509 ah->macaddr);
Sujithf1dc5602008-10-29 10:16:30 +0530510 return -EADDRNOTAVAIL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700511 }
512
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700513 return 0;
514}
515
Sujithcbe61d82009-02-09 13:27:12 +0530516static void ath9k_hw_init_rxgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530517{
518 u32 rxgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530519
Sujithf74df6f2009-02-09 13:27:24 +0530520 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_17) {
521 rxgain_type = ah->eep_ops->get_eeprom(ah, EEP_RXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530522
523 if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530524 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530525 ar9280Modes_backoff_13db_rxgain_9280_2,
526 ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2), 6);
527 else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530528 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530529 ar9280Modes_backoff_23db_rxgain_9280_2,
530 ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 6);
531 else
Sujith2660b812009-02-09 13:27:26 +0530532 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530533 ar9280Modes_original_rxgain_9280_2,
534 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530535 } else {
Sujith2660b812009-02-09 13:27:26 +0530536 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530537 ar9280Modes_original_rxgain_9280_2,
538 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530539 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530540}
541
Sujithcbe61d82009-02-09 13:27:12 +0530542static void ath9k_hw_init_txgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530543{
544 u32 txgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530545
Sujithf74df6f2009-02-09 13:27:24 +0530546 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_19) {
547 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530548
549 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
Sujith2660b812009-02-09 13:27:26 +0530550 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530551 ar9280Modes_high_power_tx_gain_9280_2,
552 ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 6);
553 else
Sujith2660b812009-02-09 13:27:26 +0530554 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530555 ar9280Modes_original_tx_gain_9280_2,
556 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530557 } else {
Sujith2660b812009-02-09 13:27:26 +0530558 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530559 ar9280Modes_original_tx_gain_9280_2,
560 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530561 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530562}
563
Sujithcbe61d82009-02-09 13:27:12 +0530564static int ath9k_hw_post_attach(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700565{
566 int ecode;
567
568 if (!ath9k_hw_chip_test(ah)) {
569 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
Sujith04bd4632008-11-28 22:18:05 +0530570 "hardware self-test failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700571 return -ENODEV;
572 }
573
574 ecode = ath9k_hw_rf_claim(ah);
575 if (ecode != 0)
576 return ecode;
577
578 ecode = ath9k_hw_eeprom_attach(ah);
579 if (ecode != 0)
580 return ecode;
Sujith7d01b222009-03-13 08:55:55 +0530581
582 DPRINTF(ah->ah_sc, ATH_DBG_CONFIG, "Eeprom VER: %d, REV: %d\n",
583 ah->eep_ops->get_eeprom_ver(ah), ah->eep_ops->get_eeprom_rev(ah));
584
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700585 ecode = ath9k_hw_rfattach(ah);
586 if (ecode != 0)
587 return ecode;
588
589 if (!AR_SREV_9100(ah)) {
590 ath9k_hw_ani_setup(ah);
591 ath9k_hw_ani_attach(ah);
592 }
Sujithf1dc5602008-10-29 10:16:30 +0530593
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700594 return 0;
595}
596
Sujithcbe61d82009-02-09 13:27:12 +0530597static struct ath_hw *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc,
598 int *status)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700599{
Sujithcbe61d82009-02-09 13:27:12 +0530600 struct ath_hw *ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700601 int ecode;
Sujithf6688cd2008-12-07 21:43:10 +0530602 u32 i, j;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700603
Sujithcbe61d82009-02-09 13:27:12 +0530604 ah = ath9k_hw_newstate(devid, sc, status);
605 if (ah == NULL)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700606 return NULL;
607
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700608 ath9k_hw_set_defaults(ah);
609
Sujith2660b812009-02-09 13:27:26 +0530610 if (ah->config.intr_mitigation != 0)
611 ah->intr_mitigation = true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700612
613 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Sujithcbe61d82009-02-09 13:27:12 +0530614 DPRINTF(sc, ATH_DBG_RESET, "Couldn't reset chip\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700615 ecode = -EIO;
616 goto bad;
617 }
618
619 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
Sujithcbe61d82009-02-09 13:27:12 +0530620 DPRINTF(sc, ATH_DBG_RESET, "Couldn't wakeup chip\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700621 ecode = -EIO;
622 goto bad;
623 }
624
Sujith2660b812009-02-09 13:27:26 +0530625 if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
David S. Miller2d6a5e92009-03-17 15:01:30 -0700626 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
627 (AR_SREV_9280(ah) && !ah->is_pciexpress)) {
Sujith2660b812009-02-09 13:27:26 +0530628 ah->config.serialize_regmode =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700629 SER_REG_MODE_ON;
630 } else {
Sujith2660b812009-02-09 13:27:26 +0530631 ah->config.serialize_regmode =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700632 SER_REG_MODE_OFF;
633 }
634 }
Sujithf1dc5602008-10-29 10:16:30 +0530635
Sujithcbe61d82009-02-09 13:27:12 +0530636 DPRINTF(sc, ATH_DBG_RESET, "serialize_regmode is %d\n",
Sujith2660b812009-02-09 13:27:26 +0530637 ah->config.serialize_regmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700638
Sujithd535a422009-02-09 13:27:06 +0530639 if ((ah->hw_version.macVersion != AR_SREV_VERSION_5416_PCI) &&
640 (ah->hw_version.macVersion != AR_SREV_VERSION_5416_PCIE) &&
641 (ah->hw_version.macVersion != AR_SREV_VERSION_9160) &&
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530642 (!AR_SREV_9100(ah)) && (!AR_SREV_9280(ah)) && (!AR_SREV_9285(ah))) {
Sujithcbe61d82009-02-09 13:27:12 +0530643 DPRINTF(sc, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +0530644 "Mac Chip Rev 0x%02x.%x is not supported by "
Sujithd535a422009-02-09 13:27:06 +0530645 "this driver\n", ah->hw_version.macVersion,
646 ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700647 ecode = -EOPNOTSUPP;
648 goto bad;
649 }
650
651 if (AR_SREV_9100(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530652 ah->iq_caldata.calData = &iq_cal_multi_sample;
653 ah->supp_cals = IQ_MISMATCH_CAL;
654 ah->is_pciexpress = false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700655 }
Sujithd535a422009-02-09 13:27:06 +0530656 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700657
658 if (AR_SREV_9160_10_OR_LATER(ah)) {
659 if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530660 ah->iq_caldata.calData = &iq_cal_single_sample;
661 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700662 &adc_gain_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530663 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700664 &adc_dc_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530665 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700666 &adc_init_dc_cal;
667 } else {
Sujith2660b812009-02-09 13:27:26 +0530668 ah->iq_caldata.calData = &iq_cal_multi_sample;
669 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700670 &adc_gain_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530671 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700672 &adc_dc_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530673 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700674 &adc_init_dc_cal;
675 }
Sujith2660b812009-02-09 13:27:26 +0530676 ah->supp_cals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700677 }
678
Sujith9c81e8b2009-03-09 09:31:49 +0530679 ah->ani_function = ATH9K_ANI_ALL;
680 if (AR_SREV_9280_10_OR_LATER(ah))
681 ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700682
Sujithcbe61d82009-02-09 13:27:12 +0530683 DPRINTF(sc, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +0530684 "This Mac Chip Rev 0x%02x.%x is \n",
Sujithd535a422009-02-09 13:27:06 +0530685 ah->hw_version.macVersion, ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700686
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530687 if (AR_SREV_9285_12_OR_LATER(ah)) {
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530688
Sujith2660b812009-02-09 13:27:26 +0530689 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530690 ARRAY_SIZE(ar9285Modes_9285_1_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530691 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530692 ARRAY_SIZE(ar9285Common_9285_1_2), 2);
693
Sujith2660b812009-02-09 13:27:26 +0530694 if (ah->config.pcie_clock_req) {
695 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530696 ar9285PciePhy_clkreq_off_L1_9285_1_2,
697 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2);
698 } else {
Sujith2660b812009-02-09 13:27:26 +0530699 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530700 ar9285PciePhy_clkreq_always_on_L1_9285_1_2,
701 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2),
702 2);
703 }
704 } else if (AR_SREV_9285_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530705 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530706 ARRAY_SIZE(ar9285Modes_9285), 6);
Sujith2660b812009-02-09 13:27:26 +0530707 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530708 ARRAY_SIZE(ar9285Common_9285), 2);
709
Sujith2660b812009-02-09 13:27:26 +0530710 if (ah->config.pcie_clock_req) {
711 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530712 ar9285PciePhy_clkreq_off_L1_9285,
713 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2);
714 } else {
Sujith2660b812009-02-09 13:27:26 +0530715 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530716 ar9285PciePhy_clkreq_always_on_L1_9285,
717 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285), 2);
718 }
719 } else if (AR_SREV_9280_20_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530720 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700721 ARRAY_SIZE(ar9280Modes_9280_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530722 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700723 ARRAY_SIZE(ar9280Common_9280_2), 2);
724
Sujith2660b812009-02-09 13:27:26 +0530725 if (ah->config.pcie_clock_req) {
726 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530727 ar9280PciePhy_clkreq_off_L1_9280,
728 ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700729 } else {
Sujith2660b812009-02-09 13:27:26 +0530730 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530731 ar9280PciePhy_clkreq_always_on_L1_9280,
732 ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700733 }
Sujith2660b812009-02-09 13:27:26 +0530734 INIT_INI_ARRAY(&ah->iniModesAdditional,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700735 ar9280Modes_fast_clock_9280_2,
Sujithf1dc5602008-10-29 10:16:30 +0530736 ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700737 } else if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530738 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700739 ARRAY_SIZE(ar9280Modes_9280), 6);
Sujith2660b812009-02-09 13:27:26 +0530740 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700741 ARRAY_SIZE(ar9280Common_9280), 2);
742 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530743 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700744 ARRAY_SIZE(ar5416Modes_9160), 6);
Sujith2660b812009-02-09 13:27:26 +0530745 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700746 ARRAY_SIZE(ar5416Common_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530747 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700748 ARRAY_SIZE(ar5416Bank0_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530749 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700750 ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530751 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700752 ARRAY_SIZE(ar5416Bank1_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530753 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700754 ARRAY_SIZE(ar5416Bank2_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530755 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700756 ARRAY_SIZE(ar5416Bank3_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530757 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700758 ARRAY_SIZE(ar5416Bank6_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530759 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700760 ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530761 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700762 ARRAY_SIZE(ar5416Bank7_9160), 2);
763 if (AR_SREV_9160_11(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530764 INIT_INI_ARRAY(&ah->iniAddac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700765 ar5416Addac_91601_1,
766 ARRAY_SIZE(ar5416Addac_91601_1), 2);
767 } else {
Sujith2660b812009-02-09 13:27:26 +0530768 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700769 ARRAY_SIZE(ar5416Addac_9160), 2);
770 }
771 } else if (AR_SREV_9100_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530772 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700773 ARRAY_SIZE(ar5416Modes_9100), 6);
Sujith2660b812009-02-09 13:27:26 +0530774 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700775 ARRAY_SIZE(ar5416Common_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530776 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700777 ARRAY_SIZE(ar5416Bank0_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530778 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700779 ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530780 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700781 ARRAY_SIZE(ar5416Bank1_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530782 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700783 ARRAY_SIZE(ar5416Bank2_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530784 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700785 ARRAY_SIZE(ar5416Bank3_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530786 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700787 ARRAY_SIZE(ar5416Bank6_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530788 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700789 ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530790 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700791 ARRAY_SIZE(ar5416Bank7_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530792 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700793 ARRAY_SIZE(ar5416Addac_9100), 2);
794 } else {
Sujith2660b812009-02-09 13:27:26 +0530795 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700796 ARRAY_SIZE(ar5416Modes), 6);
Sujith2660b812009-02-09 13:27:26 +0530797 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700798 ARRAY_SIZE(ar5416Common), 2);
Sujith2660b812009-02-09 13:27:26 +0530799 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700800 ARRAY_SIZE(ar5416Bank0), 2);
Sujith2660b812009-02-09 13:27:26 +0530801 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700802 ARRAY_SIZE(ar5416BB_RfGain), 3);
Sujith2660b812009-02-09 13:27:26 +0530803 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700804 ARRAY_SIZE(ar5416Bank1), 2);
Sujith2660b812009-02-09 13:27:26 +0530805 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700806 ARRAY_SIZE(ar5416Bank2), 2);
Sujith2660b812009-02-09 13:27:26 +0530807 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700808 ARRAY_SIZE(ar5416Bank3), 3);
Sujith2660b812009-02-09 13:27:26 +0530809 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700810 ARRAY_SIZE(ar5416Bank6), 3);
Sujith2660b812009-02-09 13:27:26 +0530811 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700812 ARRAY_SIZE(ar5416Bank6TPC), 3);
Sujith2660b812009-02-09 13:27:26 +0530813 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700814 ARRAY_SIZE(ar5416Bank7), 2);
Sujith2660b812009-02-09 13:27:26 +0530815 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700816 ARRAY_SIZE(ar5416Addac), 2);
817 }
818
Sujith2660b812009-02-09 13:27:26 +0530819 if (ah->is_pciexpress)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700820 ath9k_hw_configpcipowersave(ah, 0);
821 else
Sujithf1dc5602008-10-29 10:16:30 +0530822 ath9k_hw_disablepcie(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700823
824 ecode = ath9k_hw_post_attach(ah);
825 if (ecode != 0)
826 goto bad;
827
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530828 if (AR_SREV_9285_12_OR_LATER(ah)) {
829 u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
830
831 /* txgain table */
832 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) {
833 INIT_INI_ARRAY(&ah->iniModesTxGain,
834 ar9285Modes_high_power_tx_gain_9285_1_2,
835 ARRAY_SIZE(ar9285Modes_high_power_tx_gain_9285_1_2), 6);
836 } else {
837 INIT_INI_ARRAY(&ah->iniModesTxGain,
838 ar9285Modes_original_tx_gain_9285_1_2,
839 ARRAY_SIZE(ar9285Modes_original_tx_gain_9285_1_2), 6);
840 }
841
842 }
843
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530844 /* rxgain table */
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530845 if (AR_SREV_9280_20(ah))
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530846 ath9k_hw_init_rxgain_ini(ah);
847
848 /* txgain table */
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530849 if (AR_SREV_9280_20(ah))
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530850 ath9k_hw_init_txgain_ini(ah);
851
Sujith06d0f062009-02-12 10:06:45 +0530852 if (!ath9k_hw_fill_cap_info(ah)) {
853 DPRINTF(sc, ATH_DBG_RESET, "failed ath9k_hw_fill_cap_info\n");
854 ecode = -EINVAL;
855 goto bad;
856 }
857
858 if ((ah->hw_version.devid == AR9280_DEVID_PCI) &&
859 test_bit(ATH9K_MODE_11A, ah->caps.wireless_modes)) {
860
861 /* EEPROM Fixup */
Sujith2660b812009-02-09 13:27:26 +0530862 for (i = 0; i < ah->iniModes.ia_rows; i++) {
863 u32 reg = INI_RA(&ah->iniModes, i, 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700864
Sujith2660b812009-02-09 13:27:26 +0530865 for (j = 1; j < ah->iniModes.ia_columns; j++) {
866 u32 val = INI_RA(&ah->iniModes, i, j);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700867
Sujith2660b812009-02-09 13:27:26 +0530868 INI_RA(&ah->iniModes, i, j) =
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530869 ath9k_hw_ini_fixup(ah,
Sujith2660b812009-02-09 13:27:26 +0530870 &ah->eeprom.def,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700871 reg, val);
872 }
873 }
874 }
Sujithf6688cd2008-12-07 21:43:10 +0530875
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700876 ecode = ath9k_hw_init_macaddr(ah);
877 if (ecode != 0) {
Sujithcbe61d82009-02-09 13:27:12 +0530878 DPRINTF(sc, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +0530879 "failed initializing mac address\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700880 goto bad;
881 }
882
883 if (AR_SREV_9285(ah))
Sujith2660b812009-02-09 13:27:26 +0530884 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700885 else
Sujith2660b812009-02-09 13:27:26 +0530886 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700887
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700888 ath9k_init_nfcal_hist_buffer(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700889
890 return ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700891bad:
Sujithcbe61d82009-02-09 13:27:12 +0530892 if (ah)
893 ath9k_hw_detach(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700894 if (status)
895 *status = ecode;
Sujithf1dc5602008-10-29 10:16:30 +0530896
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700897 return NULL;
898}
899
Sujithcbe61d82009-02-09 13:27:12 +0530900static void ath9k_hw_init_bb(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530901 struct ath9k_channel *chan)
902{
903 u32 synthDelay;
904
905 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +0530906 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +0530907 synthDelay = (4 * synthDelay) / 22;
908 else
909 synthDelay /= 10;
910
911 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
912
913 udelay(synthDelay + BASE_ACTIVATE_DELAY);
914}
915
Sujithcbe61d82009-02-09 13:27:12 +0530916static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530917{
918 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
919 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
920
921 REG_WRITE(ah, AR_QOS_NO_ACK,
922 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
923 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
924 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
925
926 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
927 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
928 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
929 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
930 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
931}
932
Sujithcbe61d82009-02-09 13:27:12 +0530933static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530934 struct ath9k_channel *chan)
935{
936 u32 pll;
937
938 if (AR_SREV_9100(ah)) {
939 if (chan && IS_CHAN_5GHZ(chan))
940 pll = 0x1450;
941 else
942 pll = 0x1458;
943 } else {
944 if (AR_SREV_9280_10_OR_LATER(ah)) {
945 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
946
947 if (chan && IS_CHAN_HALF_RATE(chan))
948 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
949 else if (chan && IS_CHAN_QUARTER_RATE(chan))
950 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
951
952 if (chan && IS_CHAN_5GHZ(chan)) {
953 pll |= SM(0x28, AR_RTC_9160_PLL_DIV);
954
955
956 if (AR_SREV_9280_20(ah)) {
957 if (((chan->channel % 20) == 0)
958 || ((chan->channel % 10) == 0))
959 pll = 0x2850;
960 else
961 pll = 0x142c;
962 }
963 } else {
964 pll |= SM(0x2c, AR_RTC_9160_PLL_DIV);
965 }
966
967 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
968
969 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
970
971 if (chan && IS_CHAN_HALF_RATE(chan))
972 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
973 else if (chan && IS_CHAN_QUARTER_RATE(chan))
974 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
975
976 if (chan && IS_CHAN_5GHZ(chan))
977 pll |= SM(0x50, AR_RTC_9160_PLL_DIV);
978 else
979 pll |= SM(0x58, AR_RTC_9160_PLL_DIV);
980 } else {
981 pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2;
982
983 if (chan && IS_CHAN_HALF_RATE(chan))
984 pll |= SM(0x1, AR_RTC_PLL_CLKSEL);
985 else if (chan && IS_CHAN_QUARTER_RATE(chan))
986 pll |= SM(0x2, AR_RTC_PLL_CLKSEL);
987
988 if (chan && IS_CHAN_5GHZ(chan))
989 pll |= SM(0xa, AR_RTC_PLL_DIV);
990 else
991 pll |= SM(0xb, AR_RTC_PLL_DIV);
992 }
993 }
Gabor Juhosd03a66c2009-01-14 20:17:09 +0100994 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +0530995
996 udelay(RTC_PLL_SETTLE_DELAY);
997
998 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
999}
1000
Sujithcbe61d82009-02-09 13:27:12 +05301001static void ath9k_hw_init_chain_masks(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301002{
Sujithf1dc5602008-10-29 10:16:30 +05301003 int rx_chainmask, tx_chainmask;
1004
Sujith2660b812009-02-09 13:27:26 +05301005 rx_chainmask = ah->rxchainmask;
1006 tx_chainmask = ah->txchainmask;
Sujithf1dc5602008-10-29 10:16:30 +05301007
1008 switch (rx_chainmask) {
1009 case 0x5:
1010 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1011 AR_PHY_SWAP_ALT_CHAIN);
1012 case 0x3:
Sujithd535a422009-02-09 13:27:06 +05301013 if (((ah)->hw_version.macVersion <= AR_SREV_VERSION_9160)) {
Sujithf1dc5602008-10-29 10:16:30 +05301014 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7);
1015 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7);
1016 break;
1017 }
1018 case 0x1:
1019 case 0x2:
Sujithf1dc5602008-10-29 10:16:30 +05301020 case 0x7:
1021 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
1022 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
1023 break;
1024 default:
1025 break;
1026 }
1027
1028 REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);
1029 if (tx_chainmask == 0x5) {
1030 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1031 AR_PHY_SWAP_ALT_CHAIN);
1032 }
1033 if (AR_SREV_9100(ah))
1034 REG_WRITE(ah, AR_PHY_ANALOG_SWAP,
1035 REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
1036}
1037
Sujithcbe61d82009-02-09 13:27:12 +05301038static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -08001039 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301040{
Sujith2660b812009-02-09 13:27:26 +05301041 ah->mask_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +05301042 AR_IMR_TXURN |
1043 AR_IMR_RXERR |
1044 AR_IMR_RXORN |
1045 AR_IMR_BCNMISC;
1046
Sujith2660b812009-02-09 13:27:26 +05301047 if (ah->intr_mitigation)
1048 ah->mask_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
Sujithf1dc5602008-10-29 10:16:30 +05301049 else
Sujith2660b812009-02-09 13:27:26 +05301050 ah->mask_reg |= AR_IMR_RXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301051
Sujith2660b812009-02-09 13:27:26 +05301052 ah->mask_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301053
Colin McCabed97809d2008-12-01 13:38:55 -08001054 if (opmode == NL80211_IFTYPE_AP)
Sujith2660b812009-02-09 13:27:26 +05301055 ah->mask_reg |= AR_IMR_MIB;
Sujithf1dc5602008-10-29 10:16:30 +05301056
Sujith2660b812009-02-09 13:27:26 +05301057 REG_WRITE(ah, AR_IMR, ah->mask_reg);
Sujithf1dc5602008-10-29 10:16:30 +05301058 REG_WRITE(ah, AR_IMR_S2, REG_READ(ah, AR_IMR_S2) | AR_IMR_S2_GTT);
1059
1060 if (!AR_SREV_9100(ah)) {
1061 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
1062 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
1063 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
1064 }
1065}
1066
Sujithcbe61d82009-02-09 13:27:12 +05301067static bool ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301068{
Sujithf1dc5602008-10-29 10:16:30 +05301069 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) {
Sujith04bd4632008-11-28 22:18:05 +05301070 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "bad ack timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301071 ah->acktimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301072 return false;
1073 } else {
1074 REG_RMW_FIELD(ah, AR_TIME_OUT,
1075 AR_TIME_OUT_ACK, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301076 ah->acktimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301077 return true;
1078 }
1079}
1080
Sujithcbe61d82009-02-09 13:27:12 +05301081static bool ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301082{
Sujithf1dc5602008-10-29 10:16:30 +05301083 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_CTS))) {
Sujith04bd4632008-11-28 22:18:05 +05301084 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "bad cts timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301085 ah->ctstimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301086 return false;
1087 } else {
1088 REG_RMW_FIELD(ah, AR_TIME_OUT,
1089 AR_TIME_OUT_CTS, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301090 ah->ctstimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301091 return true;
1092 }
1093}
1094
Sujithcbe61d82009-02-09 13:27:12 +05301095static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +05301096{
Sujithf1dc5602008-10-29 10:16:30 +05301097 if (tu > 0xFFFF) {
1098 DPRINTF(ah->ah_sc, ATH_DBG_XMIT,
Sujith04bd4632008-11-28 22:18:05 +05301099 "bad global tx timeout %u\n", tu);
Sujith2660b812009-02-09 13:27:26 +05301100 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301101 return false;
1102 } else {
1103 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +05301104 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +05301105 return true;
1106 }
1107}
1108
Sujithcbe61d82009-02-09 13:27:12 +05301109static void ath9k_hw_init_user_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301110{
Sujith2660b812009-02-09 13:27:26 +05301111 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
1112 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +05301113
Sujith2660b812009-02-09 13:27:26 +05301114 if (ah->misc_mode != 0)
Sujithf1dc5602008-10-29 10:16:30 +05301115 REG_WRITE(ah, AR_PCU_MISC,
Sujith2660b812009-02-09 13:27:26 +05301116 REG_READ(ah, AR_PCU_MISC) | ah->misc_mode);
1117 if (ah->slottime != (u32) -1)
1118 ath9k_hw_setslottime(ah, ah->slottime);
1119 if (ah->acktimeout != (u32) -1)
1120 ath9k_hw_set_ack_timeout(ah, ah->acktimeout);
1121 if (ah->ctstimeout != (u32) -1)
1122 ath9k_hw_set_cts_timeout(ah, ah->ctstimeout);
1123 if (ah->globaltxtimeout != (u32) -1)
1124 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Sujithf1dc5602008-10-29 10:16:30 +05301125}
1126
1127const char *ath9k_hw_probe(u16 vendorid, u16 devid)
1128{
1129 return vendorid == ATHEROS_VENDOR_ID ?
1130 ath9k_hw_devname(devid) : NULL;
1131}
1132
Sujithcbe61d82009-02-09 13:27:12 +05301133void ath9k_hw_detach(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001134{
1135 if (!AR_SREV_9100(ah))
1136 ath9k_hw_ani_detach(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001137
Sujithf1dc5602008-10-29 10:16:30 +05301138 ath9k_hw_rfdetach(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001139 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
1140 kfree(ah);
1141}
1142
Sujithcbe61d82009-02-09 13:27:12 +05301143struct ath_hw *ath9k_hw_attach(u16 devid, struct ath_softc *sc, int *error)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001144{
Sujithcbe61d82009-02-09 13:27:12 +05301145 struct ath_hw *ah = NULL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001146
Sujithf1dc5602008-10-29 10:16:30 +05301147 switch (devid) {
1148 case AR5416_DEVID_PCI:
1149 case AR5416_DEVID_PCIE:
Gabor Juhos0c1aa492009-01-14 20:17:12 +01001150 case AR5416_AR9100_DEVID:
Sujithf1dc5602008-10-29 10:16:30 +05301151 case AR9160_DEVID_PCI:
1152 case AR9280_DEVID_PCI:
1153 case AR9280_DEVID_PCIE:
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301154 case AR9285_DEVID_PCIE:
Sujithcbe61d82009-02-09 13:27:12 +05301155 ah = ath9k_hw_do_attach(devid, sc, error);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001156 break;
Sujithf1dc5602008-10-29 10:16:30 +05301157 default:
Sujithf1dc5602008-10-29 10:16:30 +05301158 *error = -ENXIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001159 break;
1160 }
1161
Sujithf1dc5602008-10-29 10:16:30 +05301162 return ah;
1163}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001164
Sujithf1dc5602008-10-29 10:16:30 +05301165/*******/
1166/* INI */
1167/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001168
Sujithcbe61d82009-02-09 13:27:12 +05301169static void ath9k_hw_override_ini(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301170 struct ath9k_channel *chan)
1171{
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +05301172 /*
1173 * Set the RX_ABORT and RX_DIS and clear if off only after
1174 * RXE is set for MAC. This prevents frames with corrupted
1175 * descriptor status.
1176 */
1177 REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
1178
1179
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001180 if (!AR_SREV_5416_20_OR_LATER(ah) ||
Sujithf1dc5602008-10-29 10:16:30 +05301181 AR_SREV_9280_10_OR_LATER(ah))
1182 return;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001183
Sujithf1dc5602008-10-29 10:16:30 +05301184 REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
1185}
1186
Sujithcbe61d82009-02-09 13:27:12 +05301187static u32 ath9k_hw_def_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301188 struct ar5416_eeprom_def *pEepData,
Sujithf1dc5602008-10-29 10:16:30 +05301189 u32 reg, u32 value)
1190{
1191 struct base_eep_header *pBase = &(pEepData->baseEepHeader);
1192
Sujithd535a422009-02-09 13:27:06 +05301193 switch (ah->hw_version.devid) {
Sujithf1dc5602008-10-29 10:16:30 +05301194 case AR9280_DEVID_PCI:
1195 if (reg == 0x7894) {
1196 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
1197 "ini VAL: %x EEPROM: %x\n", value,
1198 (pBase->version & 0xff));
1199
1200 if ((pBase->version & 0xff) > 0x0a) {
1201 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
1202 "PWDCLKIND: %d\n",
1203 pBase->pwdclkind);
1204 value &= ~AR_AN_TOP2_PWDCLKIND;
1205 value |= AR_AN_TOP2_PWDCLKIND &
1206 (pBase->pwdclkind << AR_AN_TOP2_PWDCLKIND_S);
1207 } else {
1208 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
1209 "PWDCLKIND Earlier Rev\n");
1210 }
1211
1212 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
1213 "final ini VAL: %x\n", value);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001214 }
Sujithf1dc5602008-10-29 10:16:30 +05301215 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001216 }
1217
Sujithf1dc5602008-10-29 10:16:30 +05301218 return value;
1219}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001220
Sujithcbe61d82009-02-09 13:27:12 +05301221static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301222 struct ar5416_eeprom_def *pEepData,
1223 u32 reg, u32 value)
1224{
Sujith2660b812009-02-09 13:27:26 +05301225 if (ah->eep_map == EEP_MAP_4KBITS)
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301226 return value;
1227 else
1228 return ath9k_hw_def_ini_fixup(ah, pEepData, reg, value);
1229}
1230
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301231static void ath9k_olc_init(struct ath_hw *ah)
1232{
1233 u32 i;
1234
1235 for (i = 0; i < AR9280_TX_GAIN_TABLE_SIZE; i++)
1236 ah->originalGain[i] =
1237 MS(REG_READ(ah, AR_PHY_TX_GAIN_TBL1 + i * 4),
1238 AR_PHY_TX_GAIN);
1239 ah->PDADCdelta = 0;
1240}
1241
Sujithcbe61d82009-02-09 13:27:12 +05301242static int ath9k_hw_process_ini(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301243 struct ath9k_channel *chan,
1244 enum ath9k_ht_macmode macmode)
1245{
1246 int i, regWrites = 0;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001247 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301248 u32 modesIndex, freqIndex;
1249 int status;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001250
Sujithf1dc5602008-10-29 10:16:30 +05301251 switch (chan->chanmode) {
1252 case CHANNEL_A:
1253 case CHANNEL_A_HT20:
1254 modesIndex = 1;
1255 freqIndex = 1;
1256 break;
1257 case CHANNEL_A_HT40PLUS:
1258 case CHANNEL_A_HT40MINUS:
1259 modesIndex = 2;
1260 freqIndex = 1;
1261 break;
1262 case CHANNEL_G:
1263 case CHANNEL_G_HT20:
1264 case CHANNEL_B:
1265 modesIndex = 4;
1266 freqIndex = 2;
1267 break;
1268 case CHANNEL_G_HT40PLUS:
1269 case CHANNEL_G_HT40MINUS:
1270 modesIndex = 3;
1271 freqIndex = 2;
1272 break;
1273
1274 default:
1275 return -EINVAL;
1276 }
1277
1278 REG_WRITE(ah, AR_PHY(0), 0x00000007);
Sujithf1dc5602008-10-29 10:16:30 +05301279 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
Sujithf74df6f2009-02-09 13:27:24 +05301280 ah->eep_ops->set_addac(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301281
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001282 if (AR_SREV_5416_22_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +05301283 REG_WRITE_ARRAY(&ah->iniAddac, 1, regWrites);
Sujithf1dc5602008-10-29 10:16:30 +05301284 } else {
1285 struct ar5416IniArray temp;
1286 u32 addacSize =
Sujith2660b812009-02-09 13:27:26 +05301287 sizeof(u32) * ah->iniAddac.ia_rows *
1288 ah->iniAddac.ia_columns;
Sujithf1dc5602008-10-29 10:16:30 +05301289
Sujith2660b812009-02-09 13:27:26 +05301290 memcpy(ah->addac5416_21,
1291 ah->iniAddac.ia_array, addacSize);
Sujithf1dc5602008-10-29 10:16:30 +05301292
Sujith2660b812009-02-09 13:27:26 +05301293 (ah->addac5416_21)[31 * ah->iniAddac.ia_columns + 1] = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301294
Sujith2660b812009-02-09 13:27:26 +05301295 temp.ia_array = ah->addac5416_21;
1296 temp.ia_columns = ah->iniAddac.ia_columns;
1297 temp.ia_rows = ah->iniAddac.ia_rows;
Sujithf1dc5602008-10-29 10:16:30 +05301298 REG_WRITE_ARRAY(&temp, 1, regWrites);
1299 }
1300
1301 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
1302
Sujith2660b812009-02-09 13:27:26 +05301303 for (i = 0; i < ah->iniModes.ia_rows; i++) {
1304 u32 reg = INI_RA(&ah->iniModes, i, 0);
1305 u32 val = INI_RA(&ah->iniModes, i, modesIndex);
Sujithf1dc5602008-10-29 10:16:30 +05301306
Sujithf1dc5602008-10-29 10:16:30 +05301307 REG_WRITE(ah, reg, val);
1308
1309 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301310 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301311 udelay(100);
1312 }
1313
1314 DO_DELAY(regWrites);
1315 }
1316
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301317 if (AR_SREV_9280(ah))
Sujith2660b812009-02-09 13:27:26 +05301318 REG_WRITE_ARRAY(&ah->iniModesRxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301319
Senthil Balasubramanian4e845162009-03-06 11:24:10 +05301320 if (AR_SREV_9280(ah) || (AR_SREV_9285(ah) &&
1321 AR_SREV_9285_12_OR_LATER(ah)))
Sujith2660b812009-02-09 13:27:26 +05301322 REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301323
Sujith2660b812009-02-09 13:27:26 +05301324 for (i = 0; i < ah->iniCommon.ia_rows; i++) {
1325 u32 reg = INI_RA(&ah->iniCommon, i, 0);
1326 u32 val = INI_RA(&ah->iniCommon, i, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301327
1328 REG_WRITE(ah, reg, val);
1329
1330 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301331 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301332 udelay(100);
1333 }
1334
1335 DO_DELAY(regWrites);
1336 }
1337
1338 ath9k_hw_write_regs(ah, modesIndex, freqIndex, regWrites);
1339
1340 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan)) {
Sujith2660b812009-02-09 13:27:26 +05301341 REG_WRITE_ARRAY(&ah->iniModesAdditional, modesIndex,
Sujithf1dc5602008-10-29 10:16:30 +05301342 regWrites);
1343 }
1344
1345 ath9k_hw_override_ini(ah, chan);
1346 ath9k_hw_set_regs(ah, chan, macmode);
1347 ath9k_hw_init_chain_masks(ah);
1348
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301349 if (OLC_FOR_AR9280_20_LATER)
1350 ath9k_olc_init(ah);
1351
Sujithf74df6f2009-02-09 13:27:24 +05301352 status = ah->eep_ops->set_txpower(ah, chan,
1353 ath9k_regd_get_ctl(ah, chan),
1354 channel->max_antenna_gain * 2,
1355 channel->max_power * 2,
1356 min((u32) MAX_RATE_POWER,
1357 (u32) ah->regulatory.power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05301358 if (status != 0) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001359 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
Sujith04bd4632008-11-28 22:18:05 +05301360 "error init'ing transmit power\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001361 return -EIO;
1362 }
1363
Sujithf1dc5602008-10-29 10:16:30 +05301364 if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
1365 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
Sujith04bd4632008-11-28 22:18:05 +05301366 "ar5416SetRfRegs failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001367 return -EIO;
1368 }
1369
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001370 return 0;
1371}
1372
Sujithf1dc5602008-10-29 10:16:30 +05301373/****************************************/
1374/* Reset and Channel Switching Routines */
1375/****************************************/
1376
Sujithcbe61d82009-02-09 13:27:12 +05301377static void ath9k_hw_set_rfmode(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301378{
1379 u32 rfMode = 0;
1380
1381 if (chan == NULL)
1382 return;
1383
1384 rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
1385 ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
1386
1387 if (!AR_SREV_9280_10_OR_LATER(ah))
1388 rfMode |= (IS_CHAN_5GHZ(chan)) ?
1389 AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ;
1390
1391 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan))
1392 rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
1393
1394 REG_WRITE(ah, AR_PHY_MODE, rfMode);
1395}
1396
Sujithcbe61d82009-02-09 13:27:12 +05301397static void ath9k_hw_mark_phy_inactive(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301398{
1399 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
1400}
1401
Sujithcbe61d82009-02-09 13:27:12 +05301402static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301403{
1404 u32 regval;
1405
1406 regval = REG_READ(ah, AR_AHB_MODE);
1407 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
1408
1409 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
1410 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
1411
Sujith2660b812009-02-09 13:27:26 +05301412 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +05301413
1414 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
1415 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
1416
1417 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1418
1419 if (AR_SREV_9285(ah)) {
1420 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1421 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
1422 } else {
1423 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1424 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1425 }
1426}
1427
Sujithcbe61d82009-02-09 13:27:12 +05301428static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301429{
1430 u32 val;
1431
1432 val = REG_READ(ah, AR_STA_ID1);
1433 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
1434 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001435 case NL80211_IFTYPE_AP:
Sujithf1dc5602008-10-29 10:16:30 +05301436 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
1437 | AR_STA_ID1_KSRCH_MODE);
1438 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1439 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001440 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04001441 case NL80211_IFTYPE_MESH_POINT:
Sujithf1dc5602008-10-29 10:16:30 +05301442 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
1443 | AR_STA_ID1_KSRCH_MODE);
1444 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1445 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001446 case NL80211_IFTYPE_STATION:
1447 case NL80211_IFTYPE_MONITOR:
Sujithf1dc5602008-10-29 10:16:30 +05301448 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
1449 break;
1450 }
1451}
1452
Sujithcbe61d82009-02-09 13:27:12 +05301453static inline void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001454 u32 coef_scaled,
1455 u32 *coef_mantissa,
1456 u32 *coef_exponent)
1457{
1458 u32 coef_exp, coef_man;
1459
1460 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1461 if ((coef_scaled >> coef_exp) & 0x1)
1462 break;
1463
1464 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1465
1466 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1467
1468 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1469 *coef_exponent = coef_exp - 16;
1470}
1471
Sujithcbe61d82009-02-09 13:27:12 +05301472static void ath9k_hw_set_delta_slope(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301473 struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001474{
1475 u32 coef_scaled, ds_coef_exp, ds_coef_man;
1476 u32 clockMhzScaled = 0x64000000;
1477 struct chan_centers centers;
1478
1479 if (IS_CHAN_HALF_RATE(chan))
1480 clockMhzScaled = clockMhzScaled >> 1;
1481 else if (IS_CHAN_QUARTER_RATE(chan))
1482 clockMhzScaled = clockMhzScaled >> 2;
1483
1484 ath9k_hw_get_channel_centers(ah, chan, &centers);
1485 coef_scaled = clockMhzScaled / centers.synth_center;
1486
1487 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1488 &ds_coef_exp);
1489
1490 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1491 AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
1492 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1493 AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
1494
1495 coef_scaled = (9 * coef_scaled) / 10;
1496
1497 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1498 &ds_coef_exp);
1499
1500 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1501 AR_PHY_HALFGI_DSC_MAN, ds_coef_man);
1502 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1503 AR_PHY_HALFGI_DSC_EXP, ds_coef_exp);
1504}
1505
Sujithcbe61d82009-02-09 13:27:12 +05301506static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +05301507{
1508 u32 rst_flags;
1509 u32 tmpReg;
1510
Sujith70768492009-02-16 13:23:12 +05301511 if (AR_SREV_9100(ah)) {
1512 u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK);
1513 val &= ~AR_RTC_DERIVED_CLK_PERIOD;
1514 val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD);
1515 REG_WRITE(ah, AR_RTC_DERIVED_CLK, val);
1516 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1517 }
1518
Sujithf1dc5602008-10-29 10:16:30 +05301519 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1520 AR_RTC_FORCE_WAKE_ON_INT);
1521
1522 if (AR_SREV_9100(ah)) {
1523 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1524 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1525 } else {
1526 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1527 if (tmpReg &
1528 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1529 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
1530 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
1531 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1532 } else {
1533 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1534 }
1535
1536 rst_flags = AR_RTC_RC_MAC_WARM;
1537 if (type == ATH9K_RESET_COLD)
1538 rst_flags |= AR_RTC_RC_MAC_COLD;
1539 }
1540
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001541 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujithf1dc5602008-10-29 10:16:30 +05301542 udelay(50);
1543
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001544 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301545 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Sujithf1dc5602008-10-29 10:16:30 +05301546 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05301547 "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301548 return false;
1549 }
1550
1551 if (!AR_SREV_9100(ah))
1552 REG_WRITE(ah, AR_RC, 0);
1553
1554 ath9k_hw_init_pll(ah, NULL);
1555
1556 if (AR_SREV_9100(ah))
1557 udelay(50);
1558
1559 return true;
1560}
1561
Sujithcbe61d82009-02-09 13:27:12 +05301562static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301563{
1564 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1565 AR_RTC_FORCE_WAKE_ON_INT);
1566
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001567 REG_WRITE(ah, AR_RTC_RESET, 0);
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301568 udelay(2);
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001569 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301570
1571 if (!ath9k_hw_wait(ah,
1572 AR_RTC_STATUS,
1573 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301574 AR_RTC_STATUS_ON,
1575 AH_WAIT_TIMEOUT)) {
Sujith04bd4632008-11-28 22:18:05 +05301576 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301577 return false;
1578 }
1579
1580 ath9k_hw_read_revisions(ah);
1581
1582 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1583}
1584
Sujithcbe61d82009-02-09 13:27:12 +05301585static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301586{
1587 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1588 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1589
1590 switch (type) {
1591 case ATH9K_RESET_POWER_ON:
1592 return ath9k_hw_set_reset_power_on(ah);
1593 break;
1594 case ATH9K_RESET_WARM:
1595 case ATH9K_RESET_COLD:
1596 return ath9k_hw_set_reset(ah, type);
1597 break;
1598 default:
1599 return false;
1600 }
1601}
1602
Sujithcbe61d82009-02-09 13:27:12 +05301603static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan,
Sujithf1dc5602008-10-29 10:16:30 +05301604 enum ath9k_ht_macmode macmode)
1605{
1606 u32 phymode;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301607 u32 enableDacFifo = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301608
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301609 if (AR_SREV_9285_10_OR_LATER(ah))
1610 enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) &
1611 AR_PHY_FC_ENABLE_DAC_FIFO);
1612
Sujithf1dc5602008-10-29 10:16:30 +05301613 phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301614 | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo;
Sujithf1dc5602008-10-29 10:16:30 +05301615
1616 if (IS_CHAN_HT40(chan)) {
1617 phymode |= AR_PHY_FC_DYN2040_EN;
1618
1619 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
1620 (chan->chanmode == CHANNEL_G_HT40PLUS))
1621 phymode |= AR_PHY_FC_DYN2040_PRI_CH;
1622
Sujith2660b812009-02-09 13:27:26 +05301623 if (ah->extprotspacing == ATH9K_HT_EXTPROTSPACING_25)
Sujithf1dc5602008-10-29 10:16:30 +05301624 phymode |= AR_PHY_FC_DYN2040_EXT_CH;
1625 }
1626 REG_WRITE(ah, AR_PHY_TURBO, phymode);
1627
1628 ath9k_hw_set11nmac2040(ah, macmode);
1629
1630 REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
1631 REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
1632}
1633
Sujithcbe61d82009-02-09 13:27:12 +05301634static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301635 struct ath9k_channel *chan)
1636{
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301637 if (OLC_FOR_AR9280_20_LATER) {
1638 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
1639 return false;
1640 } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
Sujithf1dc5602008-10-29 10:16:30 +05301641 return false;
1642
1643 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
1644 return false;
1645
Sujith2660b812009-02-09 13:27:26 +05301646 ah->chip_fullsleep = false;
Sujithf1dc5602008-10-29 10:16:30 +05301647 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301648 ath9k_hw_set_rfmode(ah, chan);
1649
1650 return true;
1651}
1652
Sujithcbe61d82009-02-09 13:27:12 +05301653static bool ath9k_hw_channel_change(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301654 struct ath9k_channel *chan,
1655 enum ath9k_ht_macmode macmode)
1656{
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001657 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301658 u32 synthDelay, qnum;
1659
1660 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1661 if (ath9k_hw_numtxpending(ah, qnum)) {
1662 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
Sujith04bd4632008-11-28 22:18:05 +05301663 "Transmit frames pending on queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301664 return false;
1665 }
1666 }
1667
1668 REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
1669 if (!ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
Sujith0caa7b12009-02-16 13:23:20 +05301670 AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT)) {
Sujith04bd4632008-11-28 22:18:05 +05301671 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
1672 "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301673 return false;
1674 }
1675
1676 ath9k_hw_set_regs(ah, chan, macmode);
1677
1678 if (AR_SREV_9280_10_OR_LATER(ah)) {
1679 if (!(ath9k_hw_ar9280_set_channel(ah, chan))) {
1680 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
Sujith04bd4632008-11-28 22:18:05 +05301681 "failed to set channel\n");
Sujithf1dc5602008-10-29 10:16:30 +05301682 return false;
1683 }
1684 } else {
1685 if (!(ath9k_hw_set_channel(ah, chan))) {
1686 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
Sujith04bd4632008-11-28 22:18:05 +05301687 "failed to set channel\n");
Sujithf1dc5602008-10-29 10:16:30 +05301688 return false;
1689 }
1690 }
1691
Sujithf74df6f2009-02-09 13:27:24 +05301692 if (ah->eep_ops->set_txpower(ah, chan,
1693 ath9k_regd_get_ctl(ah, chan),
1694 channel->max_antenna_gain * 2,
1695 channel->max_power * 2,
1696 min((u32) MAX_RATE_POWER,
1697 (u32) ah->regulatory.power_limit)) != 0) {
Sujithf1dc5602008-10-29 10:16:30 +05301698 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
Sujith04bd4632008-11-28 22:18:05 +05301699 "error init'ing transmit power\n");
Sujithf1dc5602008-10-29 10:16:30 +05301700 return false;
1701 }
1702
1703 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +05301704 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +05301705 synthDelay = (4 * synthDelay) / 22;
1706 else
1707 synthDelay /= 10;
1708
1709 udelay(synthDelay + BASE_ACTIVATE_DELAY);
1710
1711 REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
1712
1713 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1714 ath9k_hw_set_delta_slope(ah, chan);
1715
1716 if (AR_SREV_9280_10_OR_LATER(ah))
1717 ath9k_hw_9280_spur_mitigate(ah, chan);
1718 else
1719 ath9k_hw_spur_mitigate(ah, chan);
1720
1721 if (!chan->oneTimeCalsDone)
1722 chan->oneTimeCalsDone = true;
1723
1724 return true;
1725}
1726
Sujithcbe61d82009-02-09 13:27:12 +05301727static void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001728{
1729 int bb_spur = AR_NO_SPUR;
1730 int freq;
1731 int bin, cur_bin;
1732 int bb_spur_off, spur_subchannel_sd;
1733 int spur_freq_sd;
1734 int spur_delta_phase;
1735 int denominator;
1736 int upper, lower, cur_vit_mask;
1737 int tmp, newVal;
1738 int i;
1739 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
1740 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
1741 };
1742 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
1743 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
1744 };
1745 int inc[4] = { 0, 100, 0, 0 };
1746 struct chan_centers centers;
1747
1748 int8_t mask_m[123];
1749 int8_t mask_p[123];
1750 int8_t mask_amt;
1751 int tmp_mask;
1752 int cur_bb_spur;
1753 bool is2GHz = IS_CHAN_2GHZ(chan);
1754
1755 memset(&mask_m, 0, sizeof(int8_t) * 123);
1756 memset(&mask_p, 0, sizeof(int8_t) * 123);
1757
1758 ath9k_hw_get_channel_centers(ah, chan, &centers);
1759 freq = centers.synth_center;
1760
Sujith2660b812009-02-09 13:27:26 +05301761 ah->config.spurmode = SPUR_ENABLE_EEPROM;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001762 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujithf74df6f2009-02-09 13:27:24 +05301763 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001764
1765 if (is2GHz)
1766 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_2GHZ;
1767 else
1768 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_5GHZ;
1769
1770 if (AR_NO_SPUR == cur_bb_spur)
1771 break;
1772 cur_bb_spur = cur_bb_spur - freq;
1773
1774 if (IS_CHAN_HT40(chan)) {
1775 if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT40) &&
1776 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT40)) {
1777 bb_spur = cur_bb_spur;
1778 break;
1779 }
1780 } else if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT20) &&
1781 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT20)) {
1782 bb_spur = cur_bb_spur;
1783 break;
1784 }
1785 }
1786
1787 if (AR_NO_SPUR == bb_spur) {
1788 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1789 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1790 return;
1791 } else {
1792 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1793 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1794 }
1795
1796 bin = bb_spur * 320;
1797
1798 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
1799
1800 newVal = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
1801 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
1802 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
1803 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
1804 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), newVal);
1805
1806 newVal = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
1807 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
1808 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
1809 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
1810 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
1811 REG_WRITE(ah, AR_PHY_SPUR_REG, newVal);
1812
1813 if (IS_CHAN_HT40(chan)) {
1814 if (bb_spur < 0) {
1815 spur_subchannel_sd = 1;
1816 bb_spur_off = bb_spur + 10;
1817 } else {
1818 spur_subchannel_sd = 0;
1819 bb_spur_off = bb_spur - 10;
1820 }
1821 } else {
1822 spur_subchannel_sd = 0;
1823 bb_spur_off = bb_spur;
1824 }
1825
1826 if (IS_CHAN_HT40(chan))
1827 spur_delta_phase =
1828 ((bb_spur * 262144) /
1829 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
1830 else
1831 spur_delta_phase =
1832 ((bb_spur * 524288) /
1833 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
1834
1835 denominator = IS_CHAN_2GHZ(chan) ? 44 : 40;
1836 spur_freq_sd = ((bb_spur_off * 2048) / denominator) & 0x3ff;
1837
1838 newVal = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
1839 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
1840 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
1841 REG_WRITE(ah, AR_PHY_TIMING11, newVal);
1842
1843 newVal = spur_subchannel_sd << AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S;
1844 REG_WRITE(ah, AR_PHY_SFCORR_EXT, newVal);
1845
1846 cur_bin = -6000;
1847 upper = bin + 100;
1848 lower = bin - 100;
1849
1850 for (i = 0; i < 4; i++) {
1851 int pilot_mask = 0;
1852 int chan_mask = 0;
1853 int bp = 0;
1854 for (bp = 0; bp < 30; bp++) {
1855 if ((cur_bin > lower) && (cur_bin < upper)) {
1856 pilot_mask = pilot_mask | 0x1 << bp;
1857 chan_mask = chan_mask | 0x1 << bp;
1858 }
1859 cur_bin += 100;
1860 }
1861 cur_bin += inc[i];
1862 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
1863 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
1864 }
1865
1866 cur_vit_mask = 6100;
1867 upper = bin + 120;
1868 lower = bin - 120;
1869
1870 for (i = 0; i < 123; i++) {
1871 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
Adrian Bunkb08cbcd2008-08-05 22:06:51 +03001872
1873 /* workaround for gcc bug #37014 */
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08001874 volatile int tmp_v = abs(cur_vit_mask - bin);
Adrian Bunkb08cbcd2008-08-05 22:06:51 +03001875
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08001876 if (tmp_v < 75)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001877 mask_amt = 1;
1878 else
1879 mask_amt = 0;
1880 if (cur_vit_mask < 0)
1881 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
1882 else
1883 mask_p[cur_vit_mask / 100] = mask_amt;
1884 }
1885 cur_vit_mask -= 100;
1886 }
1887
1888 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
1889 | (mask_m[48] << 26) | (mask_m[49] << 24)
1890 | (mask_m[50] << 22) | (mask_m[51] << 20)
1891 | (mask_m[52] << 18) | (mask_m[53] << 16)
1892 | (mask_m[54] << 14) | (mask_m[55] << 12)
1893 | (mask_m[56] << 10) | (mask_m[57] << 8)
1894 | (mask_m[58] << 6) | (mask_m[59] << 4)
1895 | (mask_m[60] << 2) | (mask_m[61] << 0);
1896 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
1897 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
1898
1899 tmp_mask = (mask_m[31] << 28)
1900 | (mask_m[32] << 26) | (mask_m[33] << 24)
1901 | (mask_m[34] << 22) | (mask_m[35] << 20)
1902 | (mask_m[36] << 18) | (mask_m[37] << 16)
1903 | (mask_m[48] << 14) | (mask_m[39] << 12)
1904 | (mask_m[40] << 10) | (mask_m[41] << 8)
1905 | (mask_m[42] << 6) | (mask_m[43] << 4)
1906 | (mask_m[44] << 2) | (mask_m[45] << 0);
1907 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
1908 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
1909
1910 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
1911 | (mask_m[18] << 26) | (mask_m[18] << 24)
1912 | (mask_m[20] << 22) | (mask_m[20] << 20)
1913 | (mask_m[22] << 18) | (mask_m[22] << 16)
1914 | (mask_m[24] << 14) | (mask_m[24] << 12)
1915 | (mask_m[25] << 10) | (mask_m[26] << 8)
1916 | (mask_m[27] << 6) | (mask_m[28] << 4)
1917 | (mask_m[29] << 2) | (mask_m[30] << 0);
1918 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
1919 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
1920
1921 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
1922 | (mask_m[2] << 26) | (mask_m[3] << 24)
1923 | (mask_m[4] << 22) | (mask_m[5] << 20)
1924 | (mask_m[6] << 18) | (mask_m[7] << 16)
1925 | (mask_m[8] << 14) | (mask_m[9] << 12)
1926 | (mask_m[10] << 10) | (mask_m[11] << 8)
1927 | (mask_m[12] << 6) | (mask_m[13] << 4)
1928 | (mask_m[14] << 2) | (mask_m[15] << 0);
1929 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
1930 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
1931
1932 tmp_mask = (mask_p[15] << 28)
1933 | (mask_p[14] << 26) | (mask_p[13] << 24)
1934 | (mask_p[12] << 22) | (mask_p[11] << 20)
1935 | (mask_p[10] << 18) | (mask_p[9] << 16)
1936 | (mask_p[8] << 14) | (mask_p[7] << 12)
1937 | (mask_p[6] << 10) | (mask_p[5] << 8)
1938 | (mask_p[4] << 6) | (mask_p[3] << 4)
1939 | (mask_p[2] << 2) | (mask_p[1] << 0);
1940 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
1941 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
1942
1943 tmp_mask = (mask_p[30] << 28)
1944 | (mask_p[29] << 26) | (mask_p[28] << 24)
1945 | (mask_p[27] << 22) | (mask_p[26] << 20)
1946 | (mask_p[25] << 18) | (mask_p[24] << 16)
1947 | (mask_p[23] << 14) | (mask_p[22] << 12)
1948 | (mask_p[21] << 10) | (mask_p[20] << 8)
1949 | (mask_p[19] << 6) | (mask_p[18] << 4)
1950 | (mask_p[17] << 2) | (mask_p[16] << 0);
1951 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
1952 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
1953
1954 tmp_mask = (mask_p[45] << 28)
1955 | (mask_p[44] << 26) | (mask_p[43] << 24)
1956 | (mask_p[42] << 22) | (mask_p[41] << 20)
1957 | (mask_p[40] << 18) | (mask_p[39] << 16)
1958 | (mask_p[38] << 14) | (mask_p[37] << 12)
1959 | (mask_p[36] << 10) | (mask_p[35] << 8)
1960 | (mask_p[34] << 6) | (mask_p[33] << 4)
1961 | (mask_p[32] << 2) | (mask_p[31] << 0);
1962 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
1963 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
1964
1965 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
1966 | (mask_p[59] << 26) | (mask_p[58] << 24)
1967 | (mask_p[57] << 22) | (mask_p[56] << 20)
1968 | (mask_p[55] << 18) | (mask_p[54] << 16)
1969 | (mask_p[53] << 14) | (mask_p[52] << 12)
1970 | (mask_p[51] << 10) | (mask_p[50] << 8)
1971 | (mask_p[49] << 6) | (mask_p[48] << 4)
1972 | (mask_p[47] << 2) | (mask_p[46] << 0);
1973 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
1974 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
1975}
1976
Sujithcbe61d82009-02-09 13:27:12 +05301977static void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001978{
1979 int bb_spur = AR_NO_SPUR;
1980 int bin, cur_bin;
1981 int spur_freq_sd;
1982 int spur_delta_phase;
1983 int denominator;
1984 int upper, lower, cur_vit_mask;
1985 int tmp, new;
1986 int i;
1987 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
1988 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
1989 };
1990 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
1991 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
1992 };
1993 int inc[4] = { 0, 100, 0, 0 };
1994
1995 int8_t mask_m[123];
1996 int8_t mask_p[123];
1997 int8_t mask_amt;
1998 int tmp_mask;
1999 int cur_bb_spur;
2000 bool is2GHz = IS_CHAN_2GHZ(chan);
2001
2002 memset(&mask_m, 0, sizeof(int8_t) * 123);
2003 memset(&mask_p, 0, sizeof(int8_t) * 123);
2004
2005 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujithf74df6f2009-02-09 13:27:24 +05302006 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002007 if (AR_NO_SPUR == cur_bb_spur)
2008 break;
2009 cur_bb_spur = cur_bb_spur - (chan->channel * 10);
2010 if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) {
2011 bb_spur = cur_bb_spur;
2012 break;
2013 }
2014 }
2015
2016 if (AR_NO_SPUR == bb_spur)
2017 return;
2018
2019 bin = bb_spur * 32;
2020
2021 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
2022 new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
2023 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
2024 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
2025 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
2026
2027 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new);
2028
2029 new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
2030 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
2031 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
2032 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
2033 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
2034 REG_WRITE(ah, AR_PHY_SPUR_REG, new);
2035
2036 spur_delta_phase = ((bb_spur * 524288) / 100) &
2037 AR_PHY_TIMING11_SPUR_DELTA_PHASE;
2038
2039 denominator = IS_CHAN_2GHZ(chan) ? 440 : 400;
2040 spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff;
2041
2042 new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
2043 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
2044 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
2045 REG_WRITE(ah, AR_PHY_TIMING11, new);
2046
2047 cur_bin = -6000;
2048 upper = bin + 100;
2049 lower = bin - 100;
2050
2051 for (i = 0; i < 4; i++) {
2052 int pilot_mask = 0;
2053 int chan_mask = 0;
2054 int bp = 0;
2055 for (bp = 0; bp < 30; bp++) {
2056 if ((cur_bin > lower) && (cur_bin < upper)) {
2057 pilot_mask = pilot_mask | 0x1 << bp;
2058 chan_mask = chan_mask | 0x1 << bp;
2059 }
2060 cur_bin += 100;
2061 }
2062 cur_bin += inc[i];
2063 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
2064 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
2065 }
2066
2067 cur_vit_mask = 6100;
2068 upper = bin + 120;
2069 lower = bin - 120;
2070
2071 for (i = 0; i < 123; i++) {
2072 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
Adrian Bunk88b9e2b2008-08-05 22:06:51 +03002073
2074 /* workaround for gcc bug #37014 */
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002075 volatile int tmp_v = abs(cur_vit_mask - bin);
Adrian Bunk88b9e2b2008-08-05 22:06:51 +03002076
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002077 if (tmp_v < 75)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002078 mask_amt = 1;
2079 else
2080 mask_amt = 0;
2081 if (cur_vit_mask < 0)
2082 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
2083 else
2084 mask_p[cur_vit_mask / 100] = mask_amt;
2085 }
2086 cur_vit_mask -= 100;
2087 }
2088
2089 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
2090 | (mask_m[48] << 26) | (mask_m[49] << 24)
2091 | (mask_m[50] << 22) | (mask_m[51] << 20)
2092 | (mask_m[52] << 18) | (mask_m[53] << 16)
2093 | (mask_m[54] << 14) | (mask_m[55] << 12)
2094 | (mask_m[56] << 10) | (mask_m[57] << 8)
2095 | (mask_m[58] << 6) | (mask_m[59] << 4)
2096 | (mask_m[60] << 2) | (mask_m[61] << 0);
2097 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
2098 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
2099
2100 tmp_mask = (mask_m[31] << 28)
2101 | (mask_m[32] << 26) | (mask_m[33] << 24)
2102 | (mask_m[34] << 22) | (mask_m[35] << 20)
2103 | (mask_m[36] << 18) | (mask_m[37] << 16)
2104 | (mask_m[48] << 14) | (mask_m[39] << 12)
2105 | (mask_m[40] << 10) | (mask_m[41] << 8)
2106 | (mask_m[42] << 6) | (mask_m[43] << 4)
2107 | (mask_m[44] << 2) | (mask_m[45] << 0);
2108 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
2109 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
2110
2111 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
2112 | (mask_m[18] << 26) | (mask_m[18] << 24)
2113 | (mask_m[20] << 22) | (mask_m[20] << 20)
2114 | (mask_m[22] << 18) | (mask_m[22] << 16)
2115 | (mask_m[24] << 14) | (mask_m[24] << 12)
2116 | (mask_m[25] << 10) | (mask_m[26] << 8)
2117 | (mask_m[27] << 6) | (mask_m[28] << 4)
2118 | (mask_m[29] << 2) | (mask_m[30] << 0);
2119 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
2120 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
2121
2122 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
2123 | (mask_m[2] << 26) | (mask_m[3] << 24)
2124 | (mask_m[4] << 22) | (mask_m[5] << 20)
2125 | (mask_m[6] << 18) | (mask_m[7] << 16)
2126 | (mask_m[8] << 14) | (mask_m[9] << 12)
2127 | (mask_m[10] << 10) | (mask_m[11] << 8)
2128 | (mask_m[12] << 6) | (mask_m[13] << 4)
2129 | (mask_m[14] << 2) | (mask_m[15] << 0);
2130 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
2131 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
2132
2133 tmp_mask = (mask_p[15] << 28)
2134 | (mask_p[14] << 26) | (mask_p[13] << 24)
2135 | (mask_p[12] << 22) | (mask_p[11] << 20)
2136 | (mask_p[10] << 18) | (mask_p[9] << 16)
2137 | (mask_p[8] << 14) | (mask_p[7] << 12)
2138 | (mask_p[6] << 10) | (mask_p[5] << 8)
2139 | (mask_p[4] << 6) | (mask_p[3] << 4)
2140 | (mask_p[2] << 2) | (mask_p[1] << 0);
2141 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
2142 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
2143
2144 tmp_mask = (mask_p[30] << 28)
2145 | (mask_p[29] << 26) | (mask_p[28] << 24)
2146 | (mask_p[27] << 22) | (mask_p[26] << 20)
2147 | (mask_p[25] << 18) | (mask_p[24] << 16)
2148 | (mask_p[23] << 14) | (mask_p[22] << 12)
2149 | (mask_p[21] << 10) | (mask_p[20] << 8)
2150 | (mask_p[19] << 6) | (mask_p[18] << 4)
2151 | (mask_p[17] << 2) | (mask_p[16] << 0);
2152 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
2153 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
2154
2155 tmp_mask = (mask_p[45] << 28)
2156 | (mask_p[44] << 26) | (mask_p[43] << 24)
2157 | (mask_p[42] << 22) | (mask_p[41] << 20)
2158 | (mask_p[40] << 18) | (mask_p[39] << 16)
2159 | (mask_p[38] << 14) | (mask_p[37] << 12)
2160 | (mask_p[36] << 10) | (mask_p[35] << 8)
2161 | (mask_p[34] << 6) | (mask_p[33] << 4)
2162 | (mask_p[32] << 2) | (mask_p[31] << 0);
2163 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
2164 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
2165
2166 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
2167 | (mask_p[59] << 26) | (mask_p[58] << 24)
2168 | (mask_p[57] << 22) | (mask_p[56] << 20)
2169 | (mask_p[55] << 18) | (mask_p[54] << 16)
2170 | (mask_p[53] << 14) | (mask_p[52] << 12)
2171 | (mask_p[51] << 10) | (mask_p[50] << 8)
2172 | (mask_p[49] << 6) | (mask_p[48] << 4)
2173 | (mask_p[47] << 2) | (mask_p[46] << 0);
2174 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
2175 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
2176}
2177
Sujithcbe61d82009-02-09 13:27:12 +05302178int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002179 bool bChannelChange)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002180{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002181 u32 saveLedState;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002182 struct ath_softc *sc = ah->ah_sc;
Sujith2660b812009-02-09 13:27:26 +05302183 struct ath9k_channel *curchan = ah->curchan;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002184 u32 saveDefAntenna;
2185 u32 macStaId1;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002186 int i, rx_chainmask, r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002187
Sujith2660b812009-02-09 13:27:26 +05302188 ah->extprotspacing = sc->ht_extprotspacing;
2189 ah->txchainmask = sc->tx_chainmask;
2190 ah->rxchainmask = sc->rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002191
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)) {
Sujith04bd4632008-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
Sujithd6509152009-03-13 08:56:05 +05302263 ah->eep_ops->set_board_values(ah, chan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002264
2265 ath9k_hw_decrease_chain_power(ah, chan);
2266
Sujithba52da52009-02-09 13:27:10 +05302267 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(ah->macaddr));
2268 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(ah->macaddr + 4)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002269 | macStaId1
2270 | AR_STA_ID1_RTS_USE_DEF
Sujith2660b812009-02-09 13:27:26 +05302271 | (ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302272 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Sujith2660b812009-02-09 13:27:26 +05302273 | ah->sta_id1_defaults);
2274 ath9k_hw_set_operating_mode(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002275
Sujithba52da52009-02-09 13:27:10 +05302276 REG_WRITE(ah, AR_BSSMSKL, get_unaligned_le32(sc->bssidmask));
2277 REG_WRITE(ah, AR_BSSMSKU, get_unaligned_le16(sc->bssidmask + 4));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002278
2279 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
2280
Sujithba52da52009-02-09 13:27:10 +05302281 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(sc->curbssid));
2282 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(sc->curbssid + 4) |
2283 ((sc->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002284
2285 REG_WRITE(ah, AR_ISR, ~0);
2286
2287 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
2288
2289 if (AR_SREV_9280_10_OR_LATER(ah)) {
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002290 if (!(ath9k_hw_ar9280_set_channel(ah, chan)))
2291 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002292 } else {
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002293 if (!(ath9k_hw_set_channel(ah, chan)))
2294 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002295 }
2296
2297 for (i = 0; i < AR_NUM_DCU; i++)
2298 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
2299
Sujith2660b812009-02-09 13:27:26 +05302300 ah->intr_txqs = 0;
2301 for (i = 0; i < ah->caps.total_queues; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002302 ath9k_hw_resettxqueue(ah, i);
2303
Sujith2660b812009-02-09 13:27:26 +05302304 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002305 ath9k_hw_init_qos(ah);
2306
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05302307#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05302308 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05302309 ath9k_enable_rfkill(ah);
2310#endif
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002311 ath9k_hw_init_user_settings(ah);
2312
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002313 REG_WRITE(ah, AR_STA_ID1,
2314 REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
2315
2316 ath9k_hw_set_dma(ah);
2317
2318 REG_WRITE(ah, AR_OBS, 8);
2319
Sujith2660b812009-02-09 13:27:26 +05302320 if (ah->intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002321
2322 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
2323 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
2324 }
2325
2326 ath9k_hw_init_bb(ah, chan);
2327
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002328 if (!ath9k_hw_init_cal(ah, chan))
2329 return -EIO;;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002330
Sujith2660b812009-02-09 13:27:26 +05302331 rx_chainmask = ah->rxchainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002332 if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) {
2333 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
2334 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
2335 }
2336
2337 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
2338
2339 if (AR_SREV_9100(ah)) {
2340 u32 mask;
2341 mask = REG_READ(ah, AR_CFG);
2342 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
2343 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05302344 "CFG Byte Swap Set 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002345 } else {
2346 mask =
2347 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
2348 REG_WRITE(ah, AR_CFG, mask);
2349 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05302350 "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002351 }
2352 } else {
2353#ifdef __BIG_ENDIAN
2354 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
2355#endif
2356 }
2357
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002358 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002359}
2360
Sujithf1dc5602008-10-29 10:16:30 +05302361/************************/
2362/* Key Cache Management */
2363/************************/
2364
Sujithcbe61d82009-02-09 13:27:12 +05302365bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002366{
Sujithf1dc5602008-10-29 10:16:30 +05302367 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002368
Sujith2660b812009-02-09 13:27:26 +05302369 if (entry >= ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05302370 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
Sujith04bd4632008-11-28 22:18:05 +05302371 "entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002372 return false;
2373 }
2374
Sujithf1dc5602008-10-29 10:16:30 +05302375 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002376
Sujithf1dc5602008-10-29 10:16:30 +05302377 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
2378 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
2379 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
2380 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
2381 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
2382 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
2383 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
2384 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
2385
2386 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2387 u16 micentry = entry + 64;
2388
2389 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
2390 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
2391 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
2392 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
2393
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002394 }
2395
Sujith2660b812009-02-09 13:27:26 +05302396 if (ah->curchan == NULL)
Sujithf1dc5602008-10-29 10:16:30 +05302397 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002398
2399 return true;
2400}
2401
Sujithcbe61d82009-02-09 13:27:12 +05302402bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002403{
Sujithf1dc5602008-10-29 10:16:30 +05302404 u32 macHi, macLo;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002405
Sujith2660b812009-02-09 13:27:26 +05302406 if (entry >= ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05302407 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
Sujith04bd4632008-11-28 22:18:05 +05302408 "entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002409 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002410 }
2411
Sujithf1dc5602008-10-29 10:16:30 +05302412 if (mac != NULL) {
2413 macHi = (mac[5] << 8) | mac[4];
2414 macLo = (mac[3] << 24) |
2415 (mac[2] << 16) |
2416 (mac[1] << 8) |
2417 mac[0];
2418 macLo >>= 1;
2419 macLo |= (macHi & 1) << 31;
2420 macHi >>= 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002421 } else {
Sujithf1dc5602008-10-29 10:16:30 +05302422 macLo = macHi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002423 }
Sujithf1dc5602008-10-29 10:16:30 +05302424 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
2425 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002426
2427 return true;
2428}
2429
Sujithcbe61d82009-02-09 13:27:12 +05302430bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
Sujithf1dc5602008-10-29 10:16:30 +05302431 const struct ath9k_keyval *k,
Jouni Malinene0caf9e2009-03-02 18:15:53 +02002432 const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002433{
Sujith2660b812009-02-09 13:27:26 +05302434 const struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +05302435 u32 key0, key1, key2, key3, key4;
2436 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002437
Sujithf1dc5602008-10-29 10:16:30 +05302438 if (entry >= pCap->keycache_size) {
2439 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
Sujith04bd4632008-11-28 22:18:05 +05302440 "entry %u out of range\n", entry);
Sujithf1dc5602008-10-29 10:16:30 +05302441 return false;
2442 }
2443
2444 switch (k->kv_type) {
2445 case ATH9K_CIPHER_AES_OCB:
2446 keyType = AR_KEYTABLE_TYPE_AES;
2447 break;
2448 case ATH9K_CIPHER_AES_CCM:
2449 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
2450 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
Sujith04bd4632008-11-28 22:18:05 +05302451 "AES-CCM not supported by mac rev 0x%x\n",
Sujithd535a422009-02-09 13:27:06 +05302452 ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002453 return false;
2454 }
Sujithf1dc5602008-10-29 10:16:30 +05302455 keyType = AR_KEYTABLE_TYPE_CCM;
2456 break;
2457 case ATH9K_CIPHER_TKIP:
2458 keyType = AR_KEYTABLE_TYPE_TKIP;
2459 if (ATH9K_IS_MIC_ENABLED(ah)
2460 && entry + 64 >= pCap->keycache_size) {
2461 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
Sujith04bd4632008-11-28 22:18:05 +05302462 "entry %u inappropriate for TKIP\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002463 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002464 }
Sujithf1dc5602008-10-29 10:16:30 +05302465 break;
2466 case ATH9K_CIPHER_WEP:
2467 if (k->kv_len < LEN_WEP40) {
2468 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
Sujith04bd4632008-11-28 22:18:05 +05302469 "WEP key length %u too small\n", k->kv_len);
Sujithf1dc5602008-10-29 10:16:30 +05302470 return false;
2471 }
2472 if (k->kv_len <= LEN_WEP40)
2473 keyType = AR_KEYTABLE_TYPE_40;
2474 else if (k->kv_len <= LEN_WEP104)
2475 keyType = AR_KEYTABLE_TYPE_104;
2476 else
2477 keyType = AR_KEYTABLE_TYPE_128;
2478 break;
2479 case ATH9K_CIPHER_CLR:
2480 keyType = AR_KEYTABLE_TYPE_CLR;
2481 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002482 default:
Sujithf1dc5602008-10-29 10:16:30 +05302483 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
Sujith04bd4632008-11-28 22:18:05 +05302484 "cipher %u not supported\n", k->kv_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002485 return false;
2486 }
Sujithf1dc5602008-10-29 10:16:30 +05302487
Jouni Malinene0caf9e2009-03-02 18:15:53 +02002488 key0 = get_unaligned_le32(k->kv_val + 0);
2489 key1 = get_unaligned_le16(k->kv_val + 4);
2490 key2 = get_unaligned_le32(k->kv_val + 6);
2491 key3 = get_unaligned_le16(k->kv_val + 10);
2492 key4 = get_unaligned_le32(k->kv_val + 12);
Sujithf1dc5602008-10-29 10:16:30 +05302493 if (k->kv_len <= LEN_WEP104)
2494 key4 &= 0xff;
2495
Jouni Malinen672903b2009-03-02 15:06:31 +02002496 /*
2497 * Note: Key cache registers access special memory area that requires
2498 * two 32-bit writes to actually update the values in the internal
2499 * memory. Consequently, the exact order and pairs used here must be
2500 * maintained.
2501 */
2502
Sujithf1dc5602008-10-29 10:16:30 +05302503 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2504 u16 micentry = entry + 64;
2505
Jouni Malinen672903b2009-03-02 15:06:31 +02002506 /*
2507 * Write inverted key[47:0] first to avoid Michael MIC errors
2508 * on frames that could be sent or received at the same time.
2509 * The correct key will be written in the end once everything
2510 * else is ready.
2511 */
Sujithf1dc5602008-10-29 10:16:30 +05302512 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
2513 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002514
2515 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302516 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2517 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002518
2519 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302520 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2521 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
Jouni Malinen672903b2009-03-02 15:06:31 +02002522
2523 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302524 (void) ath9k_hw_keysetmac(ah, entry, mac);
2525
Sujith2660b812009-02-09 13:27:26 +05302526 if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) {
Jouni Malinen672903b2009-03-02 15:06:31 +02002527 /*
2528 * TKIP uses two key cache entries:
2529 * Michael MIC TX/RX keys in the same key cache entry
2530 * (idx = main index + 64):
2531 * key0 [31:0] = RX key [31:0]
2532 * key1 [15:0] = TX key [31:16]
2533 * key1 [31:16] = reserved
2534 * key2 [31:0] = RX key [63:32]
2535 * key3 [15:0] = TX key [15:0]
2536 * key3 [31:16] = reserved
2537 * key4 [31:0] = TX key [63:32]
2538 */
Sujithf1dc5602008-10-29 10:16:30 +05302539 u32 mic0, mic1, mic2, mic3, mic4;
2540
2541 mic0 = get_unaligned_le32(k->kv_mic + 0);
2542 mic2 = get_unaligned_le32(k->kv_mic + 4);
2543 mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
2544 mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
2545 mic4 = get_unaligned_le32(k->kv_txmic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02002546
2547 /* Write RX[31:0] and TX[31:16] */
Sujithf1dc5602008-10-29 10:16:30 +05302548 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2549 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002550
2551 /* Write RX[63:32] and TX[15:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302552 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2553 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002554
2555 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302556 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
2557 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2558 AR_KEYTABLE_TYPE_CLR);
2559
2560 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002561 /*
2562 * TKIP uses four key cache entries (two for group
2563 * keys):
2564 * Michael MIC TX/RX keys are in different key cache
2565 * entries (idx = main index + 64 for TX and
2566 * main index + 32 + 96 for RX):
2567 * key0 [31:0] = TX/RX MIC key [31:0]
2568 * key1 [31:0] = reserved
2569 * key2 [31:0] = TX/RX MIC key [63:32]
2570 * key3 [31:0] = reserved
2571 * key4 [31:0] = reserved
2572 *
2573 * Upper layer code will call this function separately
2574 * for TX and RX keys when these registers offsets are
2575 * used.
2576 */
Sujithf1dc5602008-10-29 10:16:30 +05302577 u32 mic0, mic2;
2578
2579 mic0 = get_unaligned_le32(k->kv_mic + 0);
2580 mic2 = get_unaligned_le32(k->kv_mic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02002581
2582 /* Write MIC key[31:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302583 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2584 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002585
2586 /* Write MIC key[63:32] */
Sujithf1dc5602008-10-29 10:16:30 +05302587 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2588 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002589
2590 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302591 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
2592 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2593 AR_KEYTABLE_TYPE_CLR);
2594 }
Jouni Malinen672903b2009-03-02 15:06:31 +02002595
2596 /* MAC address registers are reserved for the MIC entry */
Sujithf1dc5602008-10-29 10:16:30 +05302597 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
2598 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002599
2600 /*
2601 * Write the correct (un-inverted) key[47:0] last to enable
2602 * TKIP now that all other registers are set with correct
2603 * values.
2604 */
Sujithf1dc5602008-10-29 10:16:30 +05302605 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2606 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
2607 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002608 /* Write key[47:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302609 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2610 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002611
2612 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302613 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2614 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002615
2616 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302617 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2618 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
2619
Jouni Malinen672903b2009-03-02 15:06:31 +02002620 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302621 (void) ath9k_hw_keysetmac(ah, entry, mac);
2622 }
2623
Sujithf1dc5602008-10-29 10:16:30 +05302624 return true;
2625}
2626
Sujithcbe61d82009-02-09 13:27:12 +05302627bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry)
Sujithf1dc5602008-10-29 10:16:30 +05302628{
Sujith2660b812009-02-09 13:27:26 +05302629 if (entry < ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05302630 u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
2631 if (val & AR_KEYTABLE_VALID)
2632 return true;
2633 }
2634 return false;
2635}
2636
2637/******************************/
2638/* Power Management (Chipset) */
2639/******************************/
2640
Sujithcbe61d82009-02-09 13:27:12 +05302641static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302642{
2643 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2644 if (setChip) {
2645 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2646 AR_RTC_FORCE_WAKE_EN);
2647 if (!AR_SREV_9100(ah))
2648 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
2649
Gabor Juhosd03a66c2009-01-14 20:17:09 +01002650 REG_CLR_BIT(ah, (AR_RTC_RESET),
Sujithf1dc5602008-10-29 10:16:30 +05302651 AR_RTC_RESET_EN);
2652 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002653}
2654
Sujithcbe61d82009-02-09 13:27:12 +05302655static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002656{
Sujithf1dc5602008-10-29 10:16:30 +05302657 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2658 if (setChip) {
Sujith2660b812009-02-09 13:27:26 +05302659 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002660
Sujithf1dc5602008-10-29 10:16:30 +05302661 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
2662 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2663 AR_RTC_FORCE_WAKE_ON_INT);
2664 } else {
2665 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2666 AR_RTC_FORCE_WAKE_EN);
2667 }
2668 }
2669}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002670
Sujithcbe61d82009-02-09 13:27:12 +05302671static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302672{
2673 u32 val;
2674 int i;
2675
2676 if (setChip) {
2677 if ((REG_READ(ah, AR_RTC_STATUS) &
2678 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2679 if (ath9k_hw_set_reset_reg(ah,
2680 ATH9K_RESET_POWER_ON) != true) {
2681 return false;
2682 }
2683 }
2684 if (AR_SREV_9100(ah))
2685 REG_SET_BIT(ah, AR_RTC_RESET,
2686 AR_RTC_RESET_EN);
2687
2688 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2689 AR_RTC_FORCE_WAKE_EN);
2690 udelay(50);
2691
2692 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2693 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2694 if (val == AR_RTC_STATUS_ON)
2695 break;
2696 udelay(50);
2697 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2698 AR_RTC_FORCE_WAKE_EN);
2699 }
2700 if (i == 0) {
2701 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
Sujith04bd4632008-11-28 22:18:05 +05302702 "Failed to wakeup in %uus\n", POWER_UP_TIME / 20);
Sujithf1dc5602008-10-29 10:16:30 +05302703 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002704 }
2705 }
2706
Sujithf1dc5602008-10-29 10:16:30 +05302707 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2708
2709 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002710}
2711
Sujithcbe61d82009-02-09 13:27:12 +05302712bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05302713{
Sujithcbe61d82009-02-09 13:27:12 +05302714 int status = true, setChip = true;
Sujithf1dc5602008-10-29 10:16:30 +05302715 static const char *modes[] = {
2716 "AWAKE",
2717 "FULL-SLEEP",
2718 "NETWORK SLEEP",
2719 "UNDEFINED"
2720 };
Sujithf1dc5602008-10-29 10:16:30 +05302721
Sujith04bd4632008-11-28 22:18:05 +05302722 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT, "%s -> %s (%s)\n",
Sujith2660b812009-02-09 13:27:26 +05302723 modes[ah->power_mode], modes[mode],
Sujithf1dc5602008-10-29 10:16:30 +05302724 setChip ? "set chip " : "");
2725
2726 switch (mode) {
2727 case ATH9K_PM_AWAKE:
2728 status = ath9k_hw_set_power_awake(ah, setChip);
2729 break;
2730 case ATH9K_PM_FULL_SLEEP:
2731 ath9k_set_power_sleep(ah, setChip);
Sujith2660b812009-02-09 13:27:26 +05302732 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05302733 break;
2734 case ATH9K_PM_NETWORK_SLEEP:
2735 ath9k_set_power_network_sleep(ah, setChip);
2736 break;
2737 default:
2738 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
Sujith04bd4632008-11-28 22:18:05 +05302739 "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05302740 return false;
2741 }
Sujith2660b812009-02-09 13:27:26 +05302742 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05302743
2744 return status;
2745}
2746
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002747/*
2748 * Helper for ASPM support.
2749 *
2750 * Disable PLL when in L0s as well as receiver clock when in L1.
2751 * This power saving option must be enabled through the SerDes.
2752 *
2753 * Programming the SerDes must go through the same 288 bit serial shift
2754 * register as the other analog registers. Hence the 9 writes.
2755 */
Sujithcbe61d82009-02-09 13:27:12 +05302756void ath9k_hw_configpcipowersave(struct ath_hw *ah, int restore)
Sujithf1dc5602008-10-29 10:16:30 +05302757{
Sujithf1dc5602008-10-29 10:16:30 +05302758 u8 i;
2759
Sujith2660b812009-02-09 13:27:26 +05302760 if (ah->is_pciexpress != true)
Sujithf1dc5602008-10-29 10:16:30 +05302761 return;
2762
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002763 /* Do not touch SerDes registers */
Sujith2660b812009-02-09 13:27:26 +05302764 if (ah->config.pcie_powersave_enable == 2)
Sujithf1dc5602008-10-29 10:16:30 +05302765 return;
2766
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002767 /* Nothing to do on restore for 11N */
Sujithf1dc5602008-10-29 10:16:30 +05302768 if (restore)
2769 return;
2770
2771 if (AR_SREV_9280_20_OR_LATER(ah)) {
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002772 /*
2773 * AR9280 2.0 or later chips use SerDes values from the
2774 * initvals.h initialized depending on chipset during
2775 * ath9k_hw_do_attach()
2776 */
Sujith2660b812009-02-09 13:27:26 +05302777 for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
2778 REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
2779 INI_RA(&ah->iniPcieSerdes, i, 1));
Sujithf1dc5602008-10-29 10:16:30 +05302780 }
Sujithf1dc5602008-10-29 10:16:30 +05302781 } else if (AR_SREV_9280(ah) &&
Sujithd535a422009-02-09 13:27:06 +05302782 (ah->hw_version.macRev == AR_SREV_REVISION_9280_10)) {
Sujithf1dc5602008-10-29 10:16:30 +05302783 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
2784 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
2785
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002786 /* RX shut off when elecidle is asserted */
Sujithf1dc5602008-10-29 10:16:30 +05302787 REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
2788 REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
2789 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
2790
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002791 /* Shut off CLKREQ active in L1 */
Sujith2660b812009-02-09 13:27:26 +05302792 if (ah->config.pcie_clock_req)
Sujithf1dc5602008-10-29 10:16:30 +05302793 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
2794 else
2795 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
2796
2797 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2798 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2799 REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
2800
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002801 /* Load the new settings */
Sujithf1dc5602008-10-29 10:16:30 +05302802 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
2803
Sujithf1dc5602008-10-29 10:16:30 +05302804 } else {
2805 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
2806 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002807
2808 /* RX shut off when elecidle is asserted */
Sujithf1dc5602008-10-29 10:16:30 +05302809 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
2810 REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
2811 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002812
2813 /*
2814 * Ignore ah->ah_config.pcie_clock_req setting for
2815 * pre-AR9280 11n
2816 */
Sujithf1dc5602008-10-29 10:16:30 +05302817 REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002818
Sujithf1dc5602008-10-29 10:16:30 +05302819 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2820 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2821 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002822
2823 /* Load the new settings */
Sujithf1dc5602008-10-29 10:16:30 +05302824 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
2825 }
2826
Luis R. Rodriguez6d08b9b2009-02-10 15:35:27 -08002827 udelay(1000);
2828
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002829 /* set bit 19 to allow forcing of pcie core into L1 state */
Sujithf1dc5602008-10-29 10:16:30 +05302830 REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
2831
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002832 /* Several PCIe massages to ensure proper behaviour */
Sujith2660b812009-02-09 13:27:26 +05302833 if (ah->config.pcie_waen) {
2834 REG_WRITE(ah, AR_WA, ah->config.pcie_waen);
Sujithf1dc5602008-10-29 10:16:30 +05302835 } else {
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302836 if (AR_SREV_9285(ah))
2837 REG_WRITE(ah, AR_WA, AR9285_WA_DEFAULT);
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002838 /*
2839 * On AR9280 chips bit 22 of 0x4004 needs to be set to
2840 * otherwise card may disappear.
2841 */
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302842 else if (AR_SREV_9280(ah))
2843 REG_WRITE(ah, AR_WA, AR9280_WA_DEFAULT);
Sujithf1dc5602008-10-29 10:16:30 +05302844 else
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302845 REG_WRITE(ah, AR_WA, AR_WA_DEFAULT);
Sujithf1dc5602008-10-29 10:16:30 +05302846 }
2847}
2848
2849/**********************/
2850/* Interrupt Handling */
2851/**********************/
2852
Sujithcbe61d82009-02-09 13:27:12 +05302853bool ath9k_hw_intrpend(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002854{
2855 u32 host_isr;
2856
2857 if (AR_SREV_9100(ah))
2858 return true;
2859
2860 host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
2861 if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
2862 return true;
2863
2864 host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
2865 if ((host_isr & AR_INTR_SYNC_DEFAULT)
2866 && (host_isr != AR_INTR_SPURIOUS))
2867 return true;
2868
2869 return false;
2870}
2871
Sujithcbe61d82009-02-09 13:27:12 +05302872bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002873{
2874 u32 isr = 0;
2875 u32 mask2 = 0;
Sujith2660b812009-02-09 13:27:26 +05302876 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002877 u32 sync_cause = 0;
2878 bool fatal_int = false;
2879
2880 if (!AR_SREV_9100(ah)) {
2881 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
2882 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
2883 == AR_RTC_STATUS_ON) {
2884 isr = REG_READ(ah, AR_ISR);
2885 }
2886 }
2887
Sujithf1dc5602008-10-29 10:16:30 +05302888 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
2889 AR_INTR_SYNC_DEFAULT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002890
2891 *masked = 0;
2892
2893 if (!isr && !sync_cause)
2894 return false;
2895 } else {
2896 *masked = 0;
2897 isr = REG_READ(ah, AR_ISR);
2898 }
2899
2900 if (isr) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002901 if (isr & AR_ISR_BCNMISC) {
2902 u32 isr2;
2903 isr2 = REG_READ(ah, AR_ISR_S2);
2904 if (isr2 & AR_ISR_S2_TIM)
2905 mask2 |= ATH9K_INT_TIM;
2906 if (isr2 & AR_ISR_S2_DTIM)
2907 mask2 |= ATH9K_INT_DTIM;
2908 if (isr2 & AR_ISR_S2_DTIMSYNC)
2909 mask2 |= ATH9K_INT_DTIMSYNC;
2910 if (isr2 & (AR_ISR_S2_CABEND))
2911 mask2 |= ATH9K_INT_CABEND;
2912 if (isr2 & AR_ISR_S2_GTT)
2913 mask2 |= ATH9K_INT_GTT;
2914 if (isr2 & AR_ISR_S2_CST)
2915 mask2 |= ATH9K_INT_CST;
Sujith4af9cf42009-02-12 10:06:47 +05302916 if (isr2 & AR_ISR_S2_TSFOOR)
2917 mask2 |= ATH9K_INT_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002918 }
2919
2920 isr = REG_READ(ah, AR_ISR_RAC);
2921 if (isr == 0xffffffff) {
2922 *masked = 0;
2923 return false;
2924 }
2925
2926 *masked = isr & ATH9K_INT_COMMON;
2927
Sujith2660b812009-02-09 13:27:26 +05302928 if (ah->intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002929 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
2930 *masked |= ATH9K_INT_RX;
2931 }
2932
2933 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
2934 *masked |= ATH9K_INT_RX;
2935 if (isr &
2936 (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
2937 AR_ISR_TXEOL)) {
2938 u32 s0_s, s1_s;
2939
2940 *masked |= ATH9K_INT_TX;
2941
2942 s0_s = REG_READ(ah, AR_ISR_S0_S);
Sujith2660b812009-02-09 13:27:26 +05302943 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
2944 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002945
2946 s1_s = REG_READ(ah, AR_ISR_S1_S);
Sujith2660b812009-02-09 13:27:26 +05302947 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
2948 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002949 }
2950
2951 if (isr & AR_ISR_RXORN) {
2952 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
Sujith04bd4632008-11-28 22:18:05 +05302953 "receive FIFO overrun interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002954 }
2955
2956 if (!AR_SREV_9100(ah)) {
Sujith60b67f52008-08-07 10:52:38 +05302957 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002958 u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
2959 if (isr5 & AR_ISR_S5_TIM_TIMER)
2960 *masked |= ATH9K_INT_TIM_TIMER;
2961 }
2962 }
2963
2964 *masked |= mask2;
2965 }
Sujithf1dc5602008-10-29 10:16:30 +05302966
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002967 if (AR_SREV_9100(ah))
2968 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302969
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002970 if (sync_cause) {
2971 fatal_int =
2972 (sync_cause &
2973 (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
2974 ? true : false;
2975
2976 if (fatal_int) {
2977 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
2978 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
Sujith04bd4632008-11-28 22:18:05 +05302979 "received PCI FATAL interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002980 }
2981 if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
2982 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
Sujith04bd4632008-11-28 22:18:05 +05302983 "received PCI PERR interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002984 }
2985 }
2986 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
2987 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
Sujith04bd4632008-11-28 22:18:05 +05302988 "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002989 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
2990 REG_WRITE(ah, AR_RC, 0);
2991 *masked |= ATH9K_INT_FATAL;
2992 }
2993 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
2994 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
Sujith04bd4632008-11-28 22:18:05 +05302995 "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002996 }
2997
2998 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
2999 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
3000 }
Sujithf1dc5602008-10-29 10:16:30 +05303001
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003002 return true;
3003}
3004
Sujithcbe61d82009-02-09 13:27:12 +05303005enum ath9k_int ath9k_hw_intrget(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003006{
Sujith2660b812009-02-09 13:27:26 +05303007 return ah->mask_reg;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003008}
3009
Sujithcbe61d82009-02-09 13:27:12 +05303010enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003011{
Sujith2660b812009-02-09 13:27:26 +05303012 u32 omask = ah->mask_reg;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003013 u32 mask, mask2;
Sujith2660b812009-02-09 13:27:26 +05303014 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003015
Sujith04bd4632008-11-28 22:18:05 +05303016 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003017
3018 if (omask & ATH9K_INT_GLOBAL) {
Sujith04bd4632008-11-28 22:18:05 +05303019 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "disable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003020 REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
3021 (void) REG_READ(ah, AR_IER);
3022 if (!AR_SREV_9100(ah)) {
3023 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
3024 (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
3025
3026 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
3027 (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
3028 }
3029 }
3030
3031 mask = ints & ATH9K_INT_COMMON;
3032 mask2 = 0;
3033
3034 if (ints & ATH9K_INT_TX) {
Sujith2660b812009-02-09 13:27:26 +05303035 if (ah->txok_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003036 mask |= AR_IMR_TXOK;
Sujith2660b812009-02-09 13:27:26 +05303037 if (ah->txdesc_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003038 mask |= AR_IMR_TXDESC;
Sujith2660b812009-02-09 13:27:26 +05303039 if (ah->txerr_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003040 mask |= AR_IMR_TXERR;
Sujith2660b812009-02-09 13:27:26 +05303041 if (ah->txeol_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003042 mask |= AR_IMR_TXEOL;
3043 }
3044 if (ints & ATH9K_INT_RX) {
3045 mask |= AR_IMR_RXERR;
Sujith2660b812009-02-09 13:27:26 +05303046 if (ah->intr_mitigation)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003047 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
3048 else
3049 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
Sujith60b67f52008-08-07 10:52:38 +05303050 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003051 mask |= AR_IMR_GENTMR;
3052 }
3053
3054 if (ints & (ATH9K_INT_BMISC)) {
3055 mask |= AR_IMR_BCNMISC;
3056 if (ints & ATH9K_INT_TIM)
3057 mask2 |= AR_IMR_S2_TIM;
3058 if (ints & ATH9K_INT_DTIM)
3059 mask2 |= AR_IMR_S2_DTIM;
3060 if (ints & ATH9K_INT_DTIMSYNC)
3061 mask2 |= AR_IMR_S2_DTIMSYNC;
3062 if (ints & ATH9K_INT_CABEND)
Sujith4af9cf42009-02-12 10:06:47 +05303063 mask2 |= AR_IMR_S2_CABEND;
3064 if (ints & ATH9K_INT_TSFOOR)
3065 mask2 |= AR_IMR_S2_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003066 }
3067
3068 if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
3069 mask |= AR_IMR_BCNMISC;
3070 if (ints & ATH9K_INT_GTT)
3071 mask2 |= AR_IMR_S2_GTT;
3072 if (ints & ATH9K_INT_CST)
3073 mask2 |= AR_IMR_S2_CST;
3074 }
3075
Sujith04bd4632008-11-28 22:18:05 +05303076 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003077 REG_WRITE(ah, AR_IMR, mask);
3078 mask = REG_READ(ah, AR_IMR_S2) & ~(AR_IMR_S2_TIM |
3079 AR_IMR_S2_DTIM |
3080 AR_IMR_S2_DTIMSYNC |
3081 AR_IMR_S2_CABEND |
3082 AR_IMR_S2_CABTO |
3083 AR_IMR_S2_TSFOOR |
3084 AR_IMR_S2_GTT | AR_IMR_S2_CST);
3085 REG_WRITE(ah, AR_IMR_S2, mask | mask2);
Sujith2660b812009-02-09 13:27:26 +05303086 ah->mask_reg = ints;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003087
Sujith60b67f52008-08-07 10:52:38 +05303088 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003089 if (ints & ATH9K_INT_TIM_TIMER)
3090 REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
3091 else
3092 REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
3093 }
3094
3095 if (ints & ATH9K_INT_GLOBAL) {
Sujith04bd4632008-11-28 22:18:05 +05303096 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "enable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003097 REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
3098 if (!AR_SREV_9100(ah)) {
3099 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
3100 AR_INTR_MAC_IRQ);
3101 REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
3102
3103
3104 REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
3105 AR_INTR_SYNC_DEFAULT);
3106 REG_WRITE(ah, AR_INTR_SYNC_MASK,
3107 AR_INTR_SYNC_DEFAULT);
3108 }
3109 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
3110 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
3111 }
3112
3113 return omask;
3114}
3115
Sujithf1dc5602008-10-29 10:16:30 +05303116/*******************/
3117/* Beacon Handling */
3118/*******************/
3119
Sujithcbe61d82009-02-09 13:27:12 +05303120void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003121{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003122 int flags = 0;
3123
Sujith2660b812009-02-09 13:27:26 +05303124 ah->beacon_interval = beacon_period;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003125
Sujith2660b812009-02-09 13:27:26 +05303126 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08003127 case NL80211_IFTYPE_STATION:
3128 case NL80211_IFTYPE_MONITOR:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003129 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3130 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
3131 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
3132 flags |= AR_TBTT_TIMER_EN;
3133 break;
Colin McCabed97809d2008-12-01 13:38:55 -08003134 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04003135 case NL80211_IFTYPE_MESH_POINT:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003136 REG_SET_BIT(ah, AR_TXCFG,
3137 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
3138 REG_WRITE(ah, AR_NEXT_NDP_TIMER,
3139 TU_TO_USEC(next_beacon +
Sujith2660b812009-02-09 13:27:26 +05303140 (ah->atim_window ? ah->
3141 atim_window : 1)));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003142 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08003143 case NL80211_IFTYPE_AP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003144 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3145 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
3146 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05303147 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05303148 dma_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003149 REG_WRITE(ah, AR_NEXT_SWBA,
3150 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05303151 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05303152 sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003153 flags |=
3154 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
3155 break;
Colin McCabed97809d2008-12-01 13:38:55 -08003156 default:
3157 DPRINTF(ah->ah_sc, ATH_DBG_BEACON,
3158 "%s: unsupported opmode: %d\n",
Sujith2660b812009-02-09 13:27:26 +05303159 __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08003160 return;
3161 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003162 }
3163
3164 REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3165 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3166 REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
3167 REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
3168
3169 beacon_period &= ~ATH9K_BEACON_ENA;
3170 if (beacon_period & ATH9K_BEACON_RESET_TSF) {
3171 beacon_period &= ~ATH9K_BEACON_RESET_TSF;
3172 ath9k_hw_reset_tsf(ah);
3173 }
3174
3175 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
3176}
3177
Sujithcbe61d82009-02-09 13:27:12 +05303178void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303179 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003180{
3181 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05303182 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003183
3184 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
3185
3186 REG_WRITE(ah, AR_BEACON_PERIOD,
3187 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3188 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
3189 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3190
3191 REG_RMW_FIELD(ah, AR_RSSI_THR,
3192 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
3193
3194 beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
3195
3196 if (bs->bs_sleepduration > beaconintval)
3197 beaconintval = bs->bs_sleepduration;
3198
3199 dtimperiod = bs->bs_dtimperiod;
3200 if (bs->bs_sleepduration > dtimperiod)
3201 dtimperiod = bs->bs_sleepduration;
3202
3203 if (beaconintval == dtimperiod)
3204 nextTbtt = bs->bs_nextdtim;
3205 else
3206 nextTbtt = bs->bs_nexttbtt;
3207
Sujith04bd4632008-11-28 22:18:05 +05303208 DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
3209 DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
3210 DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
3211 DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003212
3213 REG_WRITE(ah, AR_NEXT_DTIM,
3214 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
3215 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
3216
3217 REG_WRITE(ah, AR_SLEEP1,
3218 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
3219 | AR_SLEEP1_ASSUME_DTIM);
3220
Sujith60b67f52008-08-07 10:52:38 +05303221 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003222 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
3223 else
3224 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
3225
3226 REG_WRITE(ah, AR_SLEEP2,
3227 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
3228
3229 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
3230 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
3231
3232 REG_SET_BIT(ah, AR_TIMER_MODE,
3233 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
3234 AR_DTIM_TIMER_EN);
3235
Sujith4af9cf42009-02-12 10:06:47 +05303236 /* TSF Out of Range Threshold */
3237 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003238}
3239
Sujithf1dc5602008-10-29 10:16:30 +05303240/*******************/
3241/* HW Capabilities */
3242/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003243
Sujithcbe61d82009-02-09 13:27:12 +05303244bool ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003245{
Sujith2660b812009-02-09 13:27:26 +05303246 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +05303247 u16 capField = 0, eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003248
Sujithf74df6f2009-02-09 13:27:24 +05303249 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Sujithd6bad492009-02-09 13:27:08 +05303250 ah->regulatory.current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303251
Sujithf74df6f2009-02-09 13:27:24 +05303252 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
Sujithfec0de12009-02-12 10:06:43 +05303253 if (AR_SREV_9285_10_OR_LATER(ah))
3254 eeval |= AR9285_RDEXT_DEFAULT;
Sujithd6bad492009-02-09 13:27:08 +05303255 ah->regulatory.current_rd_ext = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303256
Sujithf74df6f2009-02-09 13:27:24 +05303257 capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
Sujithf1dc5602008-10-29 10:16:30 +05303258
Sujith2660b812009-02-09 13:27:26 +05303259 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05303260 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Sujithd6bad492009-02-09 13:27:08 +05303261 if (ah->regulatory.current_rd == 0x64 ||
3262 ah->regulatory.current_rd == 0x65)
3263 ah->regulatory.current_rd += 5;
3264 else if (ah->regulatory.current_rd == 0x41)
3265 ah->regulatory.current_rd = 0x43;
Sujithf1dc5602008-10-29 10:16:30 +05303266 DPRINTF(ah->ah_sc, ATH_DBG_REGULATORY,
Sujithd6bad492009-02-09 13:27:08 +05303267 "regdomain mapped to 0x%x\n", ah->regulatory.current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003268 }
Sujithdc2222a2008-08-14 13:26:55 +05303269
Sujithf74df6f2009-02-09 13:27:24 +05303270 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Sujithf1dc5602008-10-29 10:16:30 +05303271 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003272
Sujithf1dc5602008-10-29 10:16:30 +05303273 if (eeval & AR5416_OPFLAGS_11A) {
3274 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303275 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303276 if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
3277 set_bit(ATH9K_MODE_11NA_HT20,
3278 pCap->wireless_modes);
3279 if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
3280 set_bit(ATH9K_MODE_11NA_HT40PLUS,
3281 pCap->wireless_modes);
3282 set_bit(ATH9K_MODE_11NA_HT40MINUS,
3283 pCap->wireless_modes);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003284 }
3285 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003286 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003287
Sujithf1dc5602008-10-29 10:16:30 +05303288 if (eeval & AR5416_OPFLAGS_11G) {
3289 set_bit(ATH9K_MODE_11B, pCap->wireless_modes);
3290 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303291 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303292 if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
3293 set_bit(ATH9K_MODE_11NG_HT20,
3294 pCap->wireless_modes);
3295 if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
3296 set_bit(ATH9K_MODE_11NG_HT40PLUS,
3297 pCap->wireless_modes);
3298 set_bit(ATH9K_MODE_11NG_HT40MINUS,
3299 pCap->wireless_modes);
3300 }
3301 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003302 }
Sujithf1dc5602008-10-29 10:16:30 +05303303
Sujithf74df6f2009-02-09 13:27:24 +05303304 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Sujith8147f5d2009-02-20 15:13:23 +05303305 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
3306 !(eeval & AR5416_OPFLAGS_11A))
3307 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
3308 else
3309 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05303310
Sujithd535a422009-02-09 13:27:06 +05303311 if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0)))
Sujith2660b812009-02-09 13:27:26 +05303312 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05303313
3314 pCap->low_2ghz_chan = 2312;
3315 pCap->high_2ghz_chan = 2732;
3316
3317 pCap->low_5ghz_chan = 4920;
3318 pCap->high_5ghz_chan = 6100;
3319
3320 pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
3321 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
3322 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
3323
3324 pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
3325 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
3326 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
3327
Sujith2660b812009-02-09 13:27:26 +05303328 if (ah->config.ht_enable)
Sujithf1dc5602008-10-29 10:16:30 +05303329 pCap->hw_caps |= ATH9K_HW_CAP_HT;
3330 else
3331 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
3332
3333 pCap->hw_caps |= ATH9K_HW_CAP_GTT;
3334 pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
3335 pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
3336 pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
3337
3338 if (capField & AR_EEPROM_EEPCAP_MAXQCU)
3339 pCap->total_queues =
3340 MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
3341 else
3342 pCap->total_queues = ATH9K_NUM_TX_QUEUES;
3343
3344 if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
3345 pCap->keycache_size =
3346 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
3347 else
3348 pCap->keycache_size = AR_KEYTABLE_SIZE;
3349
3350 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
Sujithf1dc5602008-10-29 10:16:30 +05303351 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
3352
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303353 if (AR_SREV_9285_10_OR_LATER(ah))
3354 pCap->num_gpio_pins = AR9285_NUM_GPIO;
3355 else if (AR_SREV_9280_10_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303356 pCap->num_gpio_pins = AR928X_NUM_GPIO;
3357 else
3358 pCap->num_gpio_pins = AR_NUM_GPIO;
3359
Sujithf1dc5602008-10-29 10:16:30 +05303360 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
3361 pCap->hw_caps |= ATH9K_HW_CAP_CST;
3362 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
3363 } else {
3364 pCap->rts_aggr_limit = (8 * 1024);
3365 }
3366
3367 pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
3368
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05303369#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05303370 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
3371 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
3372 ah->rfkill_gpio =
3373 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
3374 ah->rfkill_polarity =
3375 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05303376
3377 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
3378 }
3379#endif
3380
Sujithd535a422009-02-09 13:27:06 +05303381 if ((ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI) ||
3382 (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE) ||
3383 (ah->hw_version.macVersion == AR_SREV_VERSION_9160) ||
3384 (ah->hw_version.macVersion == AR_SREV_VERSION_9100) ||
3385 (ah->hw_version.macVersion == AR_SREV_VERSION_9280))
Sujithf1dc5602008-10-29 10:16:30 +05303386 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
3387 else
3388 pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
3389
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05303390 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303391 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
3392 else
3393 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
3394
Sujithd6bad492009-02-09 13:27:08 +05303395 if (ah->regulatory.current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) {
Sujithf1dc5602008-10-29 10:16:30 +05303396 pCap->reg_cap =
3397 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3398 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
3399 AR_EEPROM_EEREGCAP_EN_KK_U2 |
3400 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
3401 } else {
3402 pCap->reg_cap =
3403 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3404 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
3405 }
3406
3407 pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
3408
3409 pCap->num_antcfg_5ghz =
Sujithf74df6f2009-02-09 13:27:24 +05303410 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303411 pCap->num_antcfg_2ghz =
Sujithf74df6f2009-02-09 13:27:24 +05303412 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303413
Vasanthakumar Thiagarajan138ab2e2009-01-10 17:07:09 +05303414 if (AR_SREV_9280_10_OR_LATER(ah) && btcoex_enable) {
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303415 pCap->hw_caps |= ATH9K_HW_CAP_BT_COEX;
Sujith2660b812009-02-09 13:27:26 +05303416 ah->btactive_gpio = 6;
3417 ah->wlanactive_gpio = 5;
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303418 }
3419
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003420 return true;
3421}
3422
Sujithcbe61d82009-02-09 13:27:12 +05303423bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303424 u32 capability, u32 *result)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003425{
Sujithf1dc5602008-10-29 10:16:30 +05303426 switch (type) {
3427 case ATH9K_CAP_CIPHER:
3428 switch (capability) {
3429 case ATH9K_CIPHER_AES_CCM:
3430 case ATH9K_CIPHER_AES_OCB:
3431 case ATH9K_CIPHER_TKIP:
3432 case ATH9K_CIPHER_WEP:
3433 case ATH9K_CIPHER_MIC:
3434 case ATH9K_CIPHER_CLR:
3435 return true;
3436 default:
3437 return false;
3438 }
3439 case ATH9K_CAP_TKIP_MIC:
3440 switch (capability) {
3441 case 0:
3442 return true;
3443 case 1:
Sujith2660b812009-02-09 13:27:26 +05303444 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303445 AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
3446 false;
3447 }
3448 case ATH9K_CAP_TKIP_SPLIT:
Sujith2660b812009-02-09 13:27:26 +05303449 return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ?
Sujithf1dc5602008-10-29 10:16:30 +05303450 false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303451 case ATH9K_CAP_DIVERSITY:
3452 return (REG_READ(ah, AR_PHY_CCK_DETECT) &
3453 AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV) ?
3454 true : false;
Sujithf1dc5602008-10-29 10:16:30 +05303455 case ATH9K_CAP_MCAST_KEYSRCH:
3456 switch (capability) {
3457 case 0:
3458 return true;
3459 case 1:
3460 if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
3461 return false;
3462 } else {
Sujith2660b812009-02-09 13:27:26 +05303463 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303464 AR_STA_ID1_MCAST_KSRCH) ? true :
3465 false;
3466 }
3467 }
3468 return false;
Sujithf1dc5602008-10-29 10:16:30 +05303469 case ATH9K_CAP_TXPOW:
3470 switch (capability) {
3471 case 0:
3472 return 0;
3473 case 1:
Sujithd6bad492009-02-09 13:27:08 +05303474 *result = ah->regulatory.power_limit;
Sujithf1dc5602008-10-29 10:16:30 +05303475 return 0;
3476 case 2:
Sujithd6bad492009-02-09 13:27:08 +05303477 *result = ah->regulatory.max_power_level;
Sujithf1dc5602008-10-29 10:16:30 +05303478 return 0;
3479 case 3:
Sujithd6bad492009-02-09 13:27:08 +05303480 *result = ah->regulatory.tp_scale;
Sujithf1dc5602008-10-29 10:16:30 +05303481 return 0;
3482 }
3483 return false;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05303484 case ATH9K_CAP_DS:
3485 return (AR_SREV_9280_20_OR_LATER(ah) &&
3486 (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1))
3487 ? false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303488 default:
3489 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003490 }
Sujithf1dc5602008-10-29 10:16:30 +05303491}
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003492
Sujithcbe61d82009-02-09 13:27:12 +05303493bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303494 u32 capability, u32 setting, int *status)
3495{
Sujithf1dc5602008-10-29 10:16:30 +05303496 u32 v;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003497
Sujithf1dc5602008-10-29 10:16:30 +05303498 switch (type) {
3499 case ATH9K_CAP_TKIP_MIC:
3500 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303501 ah->sta_id1_defaults |=
Sujithf1dc5602008-10-29 10:16:30 +05303502 AR_STA_ID1_CRPT_MIC_ENABLE;
3503 else
Sujith2660b812009-02-09 13:27:26 +05303504 ah->sta_id1_defaults &=
Sujithf1dc5602008-10-29 10:16:30 +05303505 ~AR_STA_ID1_CRPT_MIC_ENABLE;
3506 return true;
3507 case ATH9K_CAP_DIVERSITY:
3508 v = REG_READ(ah, AR_PHY_CCK_DETECT);
3509 if (setting)
3510 v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3511 else
3512 v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3513 REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
3514 return true;
3515 case ATH9K_CAP_MCAST_KEYSRCH:
3516 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303517 ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303518 else
Sujith2660b812009-02-09 13:27:26 +05303519 ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303520 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303521 default:
3522 return false;
3523 }
3524}
3525
3526/****************************/
3527/* GPIO / RFKILL / Antennae */
3528/****************************/
3529
Sujithcbe61d82009-02-09 13:27:12 +05303530static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303531 u32 gpio, u32 type)
3532{
3533 int addr;
3534 u32 gpio_shift, tmp;
3535
3536 if (gpio > 11)
3537 addr = AR_GPIO_OUTPUT_MUX3;
3538 else if (gpio > 5)
3539 addr = AR_GPIO_OUTPUT_MUX2;
3540 else
3541 addr = AR_GPIO_OUTPUT_MUX1;
3542
3543 gpio_shift = (gpio % 6) * 5;
3544
3545 if (AR_SREV_9280_20_OR_LATER(ah)
3546 || (addr != AR_GPIO_OUTPUT_MUX1)) {
3547 REG_RMW(ah, addr, (type << gpio_shift),
3548 (0x1f << gpio_shift));
3549 } else {
3550 tmp = REG_READ(ah, addr);
3551 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
3552 tmp &= ~(0x1f << gpio_shift);
3553 tmp |= (type << gpio_shift);
3554 REG_WRITE(ah, addr, tmp);
3555 }
3556}
3557
Sujithcbe61d82009-02-09 13:27:12 +05303558void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303559{
3560 u32 gpio_shift;
3561
Sujith2660b812009-02-09 13:27:26 +05303562 ASSERT(gpio < ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05303563
3564 gpio_shift = gpio << 1;
3565
3566 REG_RMW(ah,
3567 AR_GPIO_OE_OUT,
3568 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
3569 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3570}
3571
Sujithcbe61d82009-02-09 13:27:12 +05303572u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303573{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303574#define MS_REG_READ(x, y) \
3575 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
3576
Sujith2660b812009-02-09 13:27:26 +05303577 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05303578 return 0xffffffff;
3579
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303580 if (AR_SREV_9285_10_OR_LATER(ah))
3581 return MS_REG_READ(AR9285, gpio) != 0;
3582 else if (AR_SREV_9280_10_OR_LATER(ah))
3583 return MS_REG_READ(AR928X, gpio) != 0;
3584 else
3585 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05303586}
3587
Sujithcbe61d82009-02-09 13:27:12 +05303588void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05303589 u32 ah_signal_type)
3590{
3591 u32 gpio_shift;
3592
3593 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
3594
3595 gpio_shift = 2 * gpio;
3596
3597 REG_RMW(ah,
3598 AR_GPIO_OE_OUT,
3599 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
3600 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3601}
3602
Sujithcbe61d82009-02-09 13:27:12 +05303603void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05303604{
3605 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
3606 AR_GPIO_BIT(gpio));
3607}
3608
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05303609#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujithcbe61d82009-02-09 13:27:12 +05303610void ath9k_enable_rfkill(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303611{
3612 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
3613 AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
3614
3615 REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2,
3616 AR_GPIO_INPUT_MUX2_RFSILENT);
3617
Sujith2660b812009-02-09 13:27:26 +05303618 ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
Sujithf1dc5602008-10-29 10:16:30 +05303619 REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);
3620}
3621#endif
3622
Sujithcbe61d82009-02-09 13:27:12 +05303623u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303624{
3625 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
3626}
3627
Sujithcbe61d82009-02-09 13:27:12 +05303628void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05303629{
3630 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
3631}
3632
Sujithcbe61d82009-02-09 13:27:12 +05303633bool ath9k_hw_setantennaswitch(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303634 enum ath9k_ant_setting settings,
3635 struct ath9k_channel *chan,
3636 u8 *tx_chainmask,
3637 u8 *rx_chainmask,
3638 u8 *antenna_cfgd)
3639{
Sujithf1dc5602008-10-29 10:16:30 +05303640 static u8 tx_chainmask_cfg, rx_chainmask_cfg;
3641
3642 if (AR_SREV_9280(ah)) {
3643 if (!tx_chainmask_cfg) {
3644
3645 tx_chainmask_cfg = *tx_chainmask;
3646 rx_chainmask_cfg = *rx_chainmask;
3647 }
3648
3649 switch (settings) {
3650 case ATH9K_ANT_FIXED_A:
3651 *tx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3652 *rx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3653 *antenna_cfgd = true;
3654 break;
3655 case ATH9K_ANT_FIXED_B:
Sujith2660b812009-02-09 13:27:26 +05303656 if (ah->caps.tx_chainmask >
Sujithf1dc5602008-10-29 10:16:30 +05303657 ATH9K_ANTENNA1_CHAINMASK) {
3658 *tx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3659 }
3660 *rx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3661 *antenna_cfgd = true;
3662 break;
3663 case ATH9K_ANT_VARIABLE:
3664 *tx_chainmask = tx_chainmask_cfg;
3665 *rx_chainmask = rx_chainmask_cfg;
3666 *antenna_cfgd = true;
3667 break;
3668 default:
3669 break;
3670 }
3671 } else {
Sujith2660b812009-02-09 13:27:26 +05303672 ah->diversity_control = settings;
Sujithf1dc5602008-10-29 10:16:30 +05303673 }
3674
3675 return true;
3676}
3677
3678/*********************/
3679/* General Operation */
3680/*********************/
3681
Sujithcbe61d82009-02-09 13:27:12 +05303682u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303683{
3684 u32 bits = REG_READ(ah, AR_RX_FILTER);
3685 u32 phybits = REG_READ(ah, AR_PHY_ERR);
3686
3687 if (phybits & AR_PHY_ERR_RADAR)
3688 bits |= ATH9K_RX_FILTER_PHYRADAR;
3689 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
3690 bits |= ATH9K_RX_FILTER_PHYERR;
3691
3692 return bits;
3693}
3694
Sujithcbe61d82009-02-09 13:27:12 +05303695void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05303696{
3697 u32 phybits;
3698
3699 REG_WRITE(ah, AR_RX_FILTER, (bits & 0xffff) | AR_RX_COMPR_BAR);
3700 phybits = 0;
3701 if (bits & ATH9K_RX_FILTER_PHYRADAR)
3702 phybits |= AR_PHY_ERR_RADAR;
3703 if (bits & ATH9K_RX_FILTER_PHYERR)
3704 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
3705 REG_WRITE(ah, AR_PHY_ERR, phybits);
3706
3707 if (phybits)
3708 REG_WRITE(ah, AR_RXCFG,
3709 REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
3710 else
3711 REG_WRITE(ah, AR_RXCFG,
3712 REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
3713}
3714
Sujithcbe61d82009-02-09 13:27:12 +05303715bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303716{
3717 return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM);
3718}
3719
Sujithcbe61d82009-02-09 13:27:12 +05303720bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303721{
3722 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
3723 return false;
3724
3725 return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD);
3726}
3727
Sujithcbe61d82009-02-09 13:27:12 +05303728bool ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
Sujithf1dc5602008-10-29 10:16:30 +05303729{
Sujith2660b812009-02-09 13:27:26 +05303730 struct ath9k_channel *chan = ah->curchan;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08003731 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05303732
Sujithd6bad492009-02-09 13:27:08 +05303733 ah->regulatory.power_limit = min(limit, (u32) MAX_RATE_POWER);
Sujithf1dc5602008-10-29 10:16:30 +05303734
Sujithf74df6f2009-02-09 13:27:24 +05303735 if (ah->eep_ops->set_txpower(ah, chan,
3736 ath9k_regd_get_ctl(ah, chan),
3737 channel->max_antenna_gain * 2,
3738 channel->max_power * 2,
3739 min((u32) MAX_RATE_POWER,
3740 (u32) ah->regulatory.power_limit)) != 0)
Sujithf1dc5602008-10-29 10:16:30 +05303741 return false;
3742
3743 return true;
3744}
3745
Sujithcbe61d82009-02-09 13:27:12 +05303746void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac)
Sujithf1dc5602008-10-29 10:16:30 +05303747{
Sujithba52da52009-02-09 13:27:10 +05303748 memcpy(ah->macaddr, mac, ETH_ALEN);
Sujithf1dc5602008-10-29 10:16:30 +05303749}
3750
Sujithcbe61d82009-02-09 13:27:12 +05303751void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303752{
Sujith2660b812009-02-09 13:27:26 +05303753 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05303754}
3755
Sujithcbe61d82009-02-09 13:27:12 +05303756void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05303757{
3758 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
3759 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
3760}
3761
Sujithba52da52009-02-09 13:27:10 +05303762void ath9k_hw_setbssidmask(struct ath_softc *sc)
Sujithf1dc5602008-10-29 10:16:30 +05303763{
Sujithba52da52009-02-09 13:27:10 +05303764 REG_WRITE(sc->sc_ah, AR_BSSMSKL, get_unaligned_le32(sc->bssidmask));
3765 REG_WRITE(sc->sc_ah, AR_BSSMSKU, get_unaligned_le16(sc->bssidmask + 4));
Sujithf1dc5602008-10-29 10:16:30 +05303766}
3767
Sujithba52da52009-02-09 13:27:10 +05303768void ath9k_hw_write_associd(struct ath_softc *sc)
Sujithf1dc5602008-10-29 10:16:30 +05303769{
Sujithba52da52009-02-09 13:27:10 +05303770 REG_WRITE(sc->sc_ah, AR_BSS_ID0, get_unaligned_le32(sc->curbssid));
3771 REG_WRITE(sc->sc_ah, AR_BSS_ID1, get_unaligned_le16(sc->curbssid + 4) |
3772 ((sc->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05303773}
3774
Sujithcbe61d82009-02-09 13:27:12 +05303775u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303776{
3777 u64 tsf;
3778
3779 tsf = REG_READ(ah, AR_TSF_U32);
3780 tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
3781
3782 return tsf;
3783}
3784
Sujithcbe61d82009-02-09 13:27:12 +05303785void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003786{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003787 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01003788 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003789}
3790
Sujithcbe61d82009-02-09 13:27:12 +05303791void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303792{
3793 int count;
3794
3795 count = 0;
3796 while (REG_READ(ah, AR_SLP32_MODE) & AR_SLP32_TSF_WRITE_STATUS) {
3797 count++;
3798 if (count > 10) {
3799 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05303800 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
Sujithf1dc5602008-10-29 10:16:30 +05303801 break;
3802 }
3803 udelay(10);
3804 }
3805 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003806}
3807
Sujithcbe61d82009-02-09 13:27:12 +05303808bool ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003809{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003810 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303811 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003812 else
Sujith2660b812009-02-09 13:27:26 +05303813 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Sujithf1dc5602008-10-29 10:16:30 +05303814
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003815 return true;
3816}
3817
Sujithcbe61d82009-02-09 13:27:12 +05303818bool ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003819{
Sujithf1dc5602008-10-29 10:16:30 +05303820 if (us < ATH9K_SLOT_TIME_9 || us > ath9k_hw_mac_to_usec(ah, 0xffff)) {
Sujith04bd4632008-11-28 22:18:05 +05303821 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "bad slot time %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05303822 ah->slottime = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05303823 return false;
3824 } else {
3825 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05303826 ah->slottime = us;
Sujithf1dc5602008-10-29 10:16:30 +05303827 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003828 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003829}
3830
Sujithcbe61d82009-02-09 13:27:12 +05303831void ath9k_hw_set11nmac2040(struct ath_hw *ah, enum ath9k_ht_macmode mode)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003832{
Sujithf1dc5602008-10-29 10:16:30 +05303833 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003834
Sujithf1dc5602008-10-29 10:16:30 +05303835 if (mode == ATH9K_HT_MACMODE_2040 &&
Sujith2660b812009-02-09 13:27:26 +05303836 !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05303837 macmode = AR_2040_JOINED_RX_CLEAR;
3838 else
3839 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003840
Sujithf1dc5602008-10-29 10:16:30 +05303841 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003842}
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303843
3844/***************************/
3845/* Bluetooth Coexistence */
3846/***************************/
3847
Sujithcbe61d82009-02-09 13:27:12 +05303848void ath9k_hw_btcoex_enable(struct ath_hw *ah)
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303849{
3850 /* connect bt_active to baseband */
3851 REG_CLR_BIT(ah, AR_GPIO_INPUT_EN_VAL,
3852 (AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_DEF |
3853 AR_GPIO_INPUT_EN_VAL_BT_FREQUENCY_DEF));
3854
3855 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
3856 AR_GPIO_INPUT_EN_VAL_BT_ACTIVE_BB);
3857
3858 /* Set input mux for bt_active to gpio pin */
3859 REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1,
3860 AR_GPIO_INPUT_MUX1_BT_ACTIVE,
Sujith2660b812009-02-09 13:27:26 +05303861 ah->btactive_gpio);
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303862
3863 /* Configure the desired gpio port for input */
Sujith2660b812009-02-09 13:27:26 +05303864 ath9k_hw_cfg_gpio_input(ah, ah->btactive_gpio);
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303865
3866 /* Configure the desired GPIO port for TX_FRAME output */
Sujith2660b812009-02-09 13:27:26 +05303867 ath9k_hw_cfg_output(ah, ah->wlanactive_gpio,
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303868 AR_GPIO_OUTPUT_MUX_AS_TX_FRAME);
3869}