blob: 8949debeb0feaee19ba383c813f220120b6ba80a [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
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -070020#include "hw.h"
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -040021#include "hw-ops.h"
Luis R. Rodriguezcfe8cba2009-09-13 23:39:31 -070022#include "rc.h"
Luis R. Rodriguezaf01c042010-04-15 17:38:36 -040023#include "ar5008_initvals.h"
24#include "ar9001_initvals.h"
25#include "ar9002_initvals.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070026
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
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -040031static void ar9002_hw_attach_ops(struct ath_hw *ah);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -040032static void ar9003_hw_attach_ops(struct ath_hw *ah);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -040033
Sujithcbe61d82009-02-09 13:27:12 +053034static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070035
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040036MODULE_AUTHOR("Atheros Communications");
37MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
38MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
39MODULE_LICENSE("Dual BSD/GPL");
40
41static int __init ath9k_init(void)
42{
43 return 0;
44}
45module_init(ath9k_init);
46
47static void __exit ath9k_exit(void)
48{
49 return;
50}
51module_exit(ath9k_exit);
52
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -040053/* Private hardware callbacks */
54
55static void ath9k_hw_init_cal_settings(struct ath_hw *ah)
56{
57 ath9k_hw_private_ops(ah)->init_cal_settings(ah);
58}
59
60static void ath9k_hw_init_mode_regs(struct ath_hw *ah)
61{
62 ath9k_hw_private_ops(ah)->init_mode_regs(ah);
63}
64
65static bool ath9k_hw_macversion_supported(struct ath_hw *ah)
66{
67 struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
68
69 return priv_ops->macversion_supported(ah->hw_version.macVersion);
70}
71
Luis R. Rodriguez64773962010-04-15 17:38:17 -040072static u32 ath9k_hw_compute_pll_control(struct ath_hw *ah,
73 struct ath9k_channel *chan)
74{
75 return ath9k_hw_private_ops(ah)->compute_pll_control(ah, chan);
76}
77
Sujithf1dc5602008-10-29 10:16:30 +053078/********************/
79/* Helper Functions */
80/********************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070081
Sujithcbe61d82009-02-09 13:27:12 +053082static u32 ath9k_hw_mac_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053083{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070084 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053085
Sujith2660b812009-02-09 13:27:26 +053086 if (!ah->curchan) /* should really check for CCK instead */
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080087 return usecs *ATH9K_CLOCK_RATE_CCK;
88 if (conf->channel->band == IEEE80211_BAND_2GHZ)
89 return usecs *ATH9K_CLOCK_RATE_2GHZ_OFDM;
90 return usecs *ATH9K_CLOCK_RATE_5GHZ_OFDM;
Sujithf1dc5602008-10-29 10:16:30 +053091}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070092
Sujithcbe61d82009-02-09 13:27:12 +053093static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053094{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070095 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053096
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080097 if (conf_is_ht40(conf))
Sujithf1dc5602008-10-29 10:16:30 +053098 return ath9k_hw_mac_clks(ah, usecs) * 2;
99 else
100 return ath9k_hw_mac_clks(ah, usecs);
101}
102
Sujith0caa7b12009-02-16 13:23:20 +0530103bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700104{
105 int i;
106
Sujith0caa7b12009-02-16 13:23:20 +0530107 BUG_ON(timeout < AH_TIME_QUANTUM);
108
109 for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700110 if ((REG_READ(ah, reg) & mask) == val)
111 return true;
112
113 udelay(AH_TIME_QUANTUM);
114 }
Sujith04bd4632008-11-28 22:18:05 +0530115
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700116 ath_print(ath9k_hw_common(ah), ATH_DBG_ANY,
117 "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
118 timeout, reg, REG_READ(ah, reg), mask, val);
Sujithf1dc5602008-10-29 10:16:30 +0530119
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700120 return false;
121}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400122EXPORT_SYMBOL(ath9k_hw_wait);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700123
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700124u32 ath9k_hw_reverse_bits(u32 val, u32 n)
125{
126 u32 retval;
127 int i;
128
129 for (i = 0, retval = 0; i < n; i++) {
130 retval = (retval << 1) | (val & 1);
131 val >>= 1;
132 }
133 return retval;
134}
135
Sujithcbe61d82009-02-09 13:27:12 +0530136bool ath9k_get_channel_edges(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530137 u16 flags, u16 *low,
138 u16 *high)
139{
Sujith2660b812009-02-09 13:27:26 +0530140 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530141
142 if (flags & CHANNEL_5GHZ) {
143 *low = pCap->low_5ghz_chan;
144 *high = pCap->high_5ghz_chan;
145 return true;
146 }
147 if ((flags & CHANNEL_2GHZ)) {
148 *low = pCap->low_2ghz_chan;
149 *high = pCap->high_2ghz_chan;
150 return true;
151 }
152 return false;
153}
154
Sujithcbe61d82009-02-09 13:27:12 +0530155u16 ath9k_hw_computetxtime(struct ath_hw *ah,
Felix Fietkau545750d2009-11-23 22:21:01 +0100156 u8 phy, int kbps,
Sujithf1dc5602008-10-29 10:16:30 +0530157 u32 frameLen, u16 rateix,
158 bool shortPreamble)
159{
160 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
Sujithf1dc5602008-10-29 10:16:30 +0530161
162 if (kbps == 0)
163 return 0;
164
Felix Fietkau545750d2009-11-23 22:21:01 +0100165 switch (phy) {
Sujith46d14a52008-11-18 09:08:13 +0530166 case WLAN_RC_PHY_CCK:
Sujithf1dc5602008-10-29 10:16:30 +0530167 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
Felix Fietkau545750d2009-11-23 22:21:01 +0100168 if (shortPreamble)
Sujithf1dc5602008-10-29 10:16:30 +0530169 phyTime >>= 1;
170 numBits = frameLen << 3;
171 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
172 break;
Sujith46d14a52008-11-18 09:08:13 +0530173 case WLAN_RC_PHY_OFDM:
Sujith2660b812009-02-09 13:27:26 +0530174 if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530175 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
176 numBits = OFDM_PLCP_BITS + (frameLen << 3);
177 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
178 txTime = OFDM_SIFS_TIME_QUARTER
179 + OFDM_PREAMBLE_TIME_QUARTER
180 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
Sujith2660b812009-02-09 13:27:26 +0530181 } else if (ah->curchan &&
182 IS_CHAN_HALF_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530183 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
184 numBits = OFDM_PLCP_BITS + (frameLen << 3);
185 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
186 txTime = OFDM_SIFS_TIME_HALF +
187 OFDM_PREAMBLE_TIME_HALF
188 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
189 } else {
190 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
191 numBits = OFDM_PLCP_BITS + (frameLen << 3);
192 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
193 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
194 + (numSymbols * OFDM_SYMBOL_TIME);
195 }
196 break;
197 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700198 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
Felix Fietkau545750d2009-11-23 22:21:01 +0100199 "Unknown phy %u (rate ix %u)\n", phy, rateix);
Sujithf1dc5602008-10-29 10:16:30 +0530200 txTime = 0;
201 break;
202 }
203
204 return txTime;
205}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400206EXPORT_SYMBOL(ath9k_hw_computetxtime);
Sujithf1dc5602008-10-29 10:16:30 +0530207
Sujithcbe61d82009-02-09 13:27:12 +0530208void ath9k_hw_get_channel_centers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530209 struct ath9k_channel *chan,
210 struct chan_centers *centers)
211{
212 int8_t extoff;
Sujithf1dc5602008-10-29 10:16:30 +0530213
214 if (!IS_CHAN_HT40(chan)) {
215 centers->ctl_center = centers->ext_center =
216 centers->synth_center = chan->channel;
217 return;
218 }
219
220 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
221 (chan->chanmode == CHANNEL_G_HT40PLUS)) {
222 centers->synth_center =
223 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
224 extoff = 1;
225 } else {
226 centers->synth_center =
227 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
228 extoff = -1;
229 }
230
231 centers->ctl_center =
232 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700233 /* 25 MHz spacing is supported by hw but not on upper layers */
Sujithf1dc5602008-10-29 10:16:30 +0530234 centers->ext_center =
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700235 centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT);
Sujithf1dc5602008-10-29 10:16:30 +0530236}
237
238/******************/
239/* Chip Revisions */
240/******************/
241
Sujithcbe61d82009-02-09 13:27:12 +0530242static void ath9k_hw_read_revisions(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530243{
244 u32 val;
245
246 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
247
248 if (val == 0xFF) {
249 val = REG_READ(ah, AR_SREV);
Sujithd535a422009-02-09 13:27:06 +0530250 ah->hw_version.macVersion =
251 (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
252 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
Sujith2660b812009-02-09 13:27:26 +0530253 ah->is_pciexpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
Sujithf1dc5602008-10-29 10:16:30 +0530254 } else {
255 if (!AR_SREV_9100(ah))
Sujithd535a422009-02-09 13:27:06 +0530256 ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
Sujithf1dc5602008-10-29 10:16:30 +0530257
Sujithd535a422009-02-09 13:27:06 +0530258 ah->hw_version.macRev = val & AR_SREV_REVISION;
Sujithf1dc5602008-10-29 10:16:30 +0530259
Sujithd535a422009-02-09 13:27:06 +0530260 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
Sujith2660b812009-02-09 13:27:26 +0530261 ah->is_pciexpress = true;
Sujithf1dc5602008-10-29 10:16:30 +0530262 }
263}
264
Sujithcbe61d82009-02-09 13:27:12 +0530265static int ath9k_hw_get_radiorev(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530266{
267 u32 val;
268 int i;
269
270 REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
271
272 for (i = 0; i < 8; i++)
273 REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
274 val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
275 val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
276
277 return ath9k_hw_reverse_bits(val, 8);
278}
279
280/************************************/
281/* HW Attach, Detach, Init Routines */
282/************************************/
283
Sujithcbe61d82009-02-09 13:27:12 +0530284static void ath9k_hw_disablepcie(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530285{
Sujithfeed0292009-01-29 11:37:35 +0530286 if (AR_SREV_9100(ah))
Sujithf1dc5602008-10-29 10:16:30 +0530287 return;
288
289 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
290 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
291 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
292 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
293 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
294 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
295 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
296 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
297 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
298
299 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
300}
301
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400302/* This should work for all families including legacy */
Sujithcbe61d82009-02-09 13:27:12 +0530303static bool ath9k_hw_chip_test(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530304{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700305 struct ath_common *common = ath9k_hw_common(ah);
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400306 u32 regAddr[2] = { AR_STA_ID0 };
Sujithf1dc5602008-10-29 10:16:30 +0530307 u32 regHold[2];
308 u32 patternData[4] = { 0x55555555,
309 0xaaaaaaaa,
310 0x66666666,
311 0x99999999 };
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400312 int i, j, loop_max;
Sujithf1dc5602008-10-29 10:16:30 +0530313
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400314 if (!AR_SREV_9300_20_OR_LATER(ah)) {
315 loop_max = 2;
316 regAddr[1] = AR_PHY_BASE + (8 << 2);
317 } else
318 loop_max = 1;
319
320 for (i = 0; i < loop_max; i++) {
Sujithf1dc5602008-10-29 10:16:30 +0530321 u32 addr = regAddr[i];
322 u32 wrData, rdData;
323
324 regHold[i] = REG_READ(ah, addr);
325 for (j = 0; j < 0x100; j++) {
326 wrData = (j << 16) | j;
327 REG_WRITE(ah, addr, wrData);
328 rdData = REG_READ(ah, addr);
329 if (rdData != wrData) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700330 ath_print(common, ATH_DBG_FATAL,
331 "address test failed "
332 "addr: 0x%08x - wr:0x%08x != "
333 "rd:0x%08x\n",
334 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530335 return false;
336 }
337 }
338 for (j = 0; j < 4; j++) {
339 wrData = patternData[j];
340 REG_WRITE(ah, addr, wrData);
341 rdData = REG_READ(ah, addr);
342 if (wrData != rdData) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700343 ath_print(common, ATH_DBG_FATAL,
344 "address test failed "
345 "addr: 0x%08x - wr:0x%08x != "
346 "rd:0x%08x\n",
347 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530348 return false;
349 }
350 }
351 REG_WRITE(ah, regAddr[i], regHold[i]);
352 }
353 udelay(100);
Sujithcbe61d82009-02-09 13:27:12 +0530354
Sujithf1dc5602008-10-29 10:16:30 +0530355 return true;
356}
357
Luis R. Rodriguezb8b0f372009-08-03 12:24:43 -0700358static void ath9k_hw_init_config(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700359{
360 int i;
361
Sujith2660b812009-02-09 13:27:26 +0530362 ah->config.dma_beacon_response_time = 2;
363 ah->config.sw_beacon_response_time = 10;
364 ah->config.additional_swba_backoff = 0;
365 ah->config.ack_6mb = 0x0;
366 ah->config.cwm_ignore_extcca = 0;
367 ah->config.pcie_powersave_enable = 0;
Sujith2660b812009-02-09 13:27:26 +0530368 ah->config.pcie_clock_req = 0;
Sujith2660b812009-02-09 13:27:26 +0530369 ah->config.pcie_waen = 0;
370 ah->config.analog_shiftreg = 1;
Sujith2660b812009-02-09 13:27:26 +0530371 ah->config.ofdm_trig_low = 200;
372 ah->config.ofdm_trig_high = 500;
373 ah->config.cck_trig_high = 200;
374 ah->config.cck_trig_low = 100;
Luis R. Rodriguez31a0bd32010-04-15 17:38:22 -0400375
376 /*
377 * For now ANI is disabled for AR9003, it is still
378 * being tested.
379 */
380 if (!AR_SREV_9300_20_OR_LATER(ah))
381 ah->config.enable_ani = 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700382
383 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujith2660b812009-02-09 13:27:26 +0530384 ah->config.spurchans[i][0] = AR_NO_SPUR;
385 ah->config.spurchans[i][1] = AR_NO_SPUR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700386 }
387
Luis R. Rodriguez5ffaf8a2010-02-02 11:58:33 -0500388 if (ah->hw_version.devid != AR2427_DEVID_PCIE)
389 ah->config.ht_enable = 1;
390 else
391 ah->config.ht_enable = 0;
392
Sujith0ce024c2009-12-14 14:57:00 +0530393 ah->config.rx_intr_mitigation = true;
Luis R. Rodriguez61584252009-03-12 18:18:49 -0400394
395 /*
396 * We need this for PCI devices only (Cardbus, PCI, miniPCI)
397 * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
398 * This means we use it for all AR5416 devices, and the few
399 * minor PCI AR9280 devices out there.
400 *
401 * Serialization is required because these devices do not handle
402 * well the case of two concurrent reads/writes due to the latency
403 * involved. During one read/write another read/write can be issued
404 * on another CPU while the previous read/write may still be working
405 * on our hardware, if we hit this case the hardware poops in a loop.
406 * We prevent this by serializing reads and writes.
407 *
408 * This issue is not present on PCI-Express devices or pre-AR5416
409 * devices (legacy, 802.11abg).
410 */
411 if (num_possible_cpus() > 1)
David S. Miller2d6a5e92009-03-17 15:01:30 -0700412 ah->config.serialize_regmode = SER_REG_MODE_AUTO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700413}
414
Luis R. Rodriguez50aca252009-08-03 12:24:42 -0700415static void ath9k_hw_init_defaults(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700416{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700417 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
418
419 regulatory->country_code = CTRY_DEFAULT;
420 regulatory->power_limit = MAX_RATE_POWER;
421 regulatory->tp_scale = ATH9K_TP_SCALE_MAX;
422
Sujithd535a422009-02-09 13:27:06 +0530423 ah->hw_version.magic = AR5416_MAGIC;
Sujithd535a422009-02-09 13:27:06 +0530424 ah->hw_version.subvendorid = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700425
426 ah->ah_flags = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700427 if (!AR_SREV_9100(ah))
428 ah->ah_flags = AH_USE_EEPROM;
429
Sujith2660b812009-02-09 13:27:26 +0530430 ah->atim_window = 0;
Sujith2660b812009-02-09 13:27:26 +0530431 ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
432 ah->beacon_interval = 100;
433 ah->enable_32kHz_clock = DONT_USE_32KHZ;
434 ah->slottime = (u32) -1;
Sujith2660b812009-02-09 13:27:26 +0530435 ah->globaltxtimeout = (u32) -1;
Gabor Juhoscbdec972009-07-24 17:27:22 +0200436 ah->power_mode = ATH9K_PM_UNDEFINED;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700437}
438
Sujithcbe61d82009-02-09 13:27:12 +0530439static int ath9k_hw_rf_claim(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700440{
441 u32 val;
442
443 REG_WRITE(ah, AR_PHY(0), 0x00000007);
444
445 val = ath9k_hw_get_radiorev(ah);
446 switch (val & AR_RADIO_SREV_MAJOR) {
447 case 0:
448 val = AR_RAD5133_SREV_MAJOR;
449 break;
450 case AR_RAD5133_SREV_MAJOR:
451 case AR_RAD5122_SREV_MAJOR:
452 case AR_RAD2133_SREV_MAJOR:
453 case AR_RAD2122_SREV_MAJOR:
454 break;
455 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700456 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
457 "Radio Chip Rev 0x%02X not supported\n",
458 val & AR_RADIO_SREV_MAJOR);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700459 return -EOPNOTSUPP;
460 }
461
Sujithd535a422009-02-09 13:27:06 +0530462 ah->hw_version.analog5GhzRev = val;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700463
464 return 0;
465}
466
Sujithcbe61d82009-02-09 13:27:12 +0530467static int ath9k_hw_init_macaddr(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700468{
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700469 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530470 u32 sum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700471 int i;
Sujithf1dc5602008-10-29 10:16:30 +0530472 u16 eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700473
Sujithf1dc5602008-10-29 10:16:30 +0530474 sum = 0;
475 for (i = 0; i < 3; i++) {
Sujithf74df6f2009-02-09 13:27:24 +0530476 eeval = ah->eep_ops->get_eeprom(ah, AR_EEPROM_MAC(i));
Sujithf1dc5602008-10-29 10:16:30 +0530477 sum += eeval;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700478 common->macaddr[2 * i] = eeval >> 8;
479 common->macaddr[2 * i + 1] = eeval & 0xff;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700480 }
Sujithd8baa932009-03-30 15:28:25 +0530481 if (sum == 0 || sum == 0xffff * 3)
Sujithf1dc5602008-10-29 10:16:30 +0530482 return -EADDRNOTAVAIL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700483
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700484 return 0;
485}
486
Sujithcbe61d82009-02-09 13:27:12 +0530487static void ath9k_hw_init_rxgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530488{
489 u32 rxgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530490
Sujithf74df6f2009-02-09 13:27:24 +0530491 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_17) {
492 rxgain_type = ah->eep_ops->get_eeprom(ah, EEP_RXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530493
494 if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530495 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530496 ar9280Modes_backoff_13db_rxgain_9280_2,
497 ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2), 6);
498 else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530499 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530500 ar9280Modes_backoff_23db_rxgain_9280_2,
501 ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 6);
502 else
Sujith2660b812009-02-09 13:27:26 +0530503 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530504 ar9280Modes_original_rxgain_9280_2,
505 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530506 } else {
Sujith2660b812009-02-09 13:27:26 +0530507 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530508 ar9280Modes_original_rxgain_9280_2,
509 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530510 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530511}
512
Sujithcbe61d82009-02-09 13:27:12 +0530513static void ath9k_hw_init_txgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530514{
515 u32 txgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530516
Sujithf74df6f2009-02-09 13:27:24 +0530517 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_19) {
518 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530519
520 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
Sujith2660b812009-02-09 13:27:26 +0530521 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530522 ar9280Modes_high_power_tx_gain_9280_2,
523 ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 6);
524 else
Sujith2660b812009-02-09 13:27:26 +0530525 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530526 ar9280Modes_original_tx_gain_9280_2,
527 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530528 } else {
Sujith2660b812009-02-09 13:27:26 +0530529 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530530 ar9280Modes_original_tx_gain_9280_2,
531 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530532 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530533}
534
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700535static int ath9k_hw_post_init(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700536{
537 int ecode;
538
Sujith527d4852010-03-17 14:25:16 +0530539 if (!AR_SREV_9271(ah)) {
540 if (!ath9k_hw_chip_test(ah))
541 return -ENODEV;
542 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700543
544 ecode = ath9k_hw_rf_claim(ah);
545 if (ecode != 0)
546 return ecode;
547
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700548 ecode = ath9k_hw_eeprom_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700549 if (ecode != 0)
550 return ecode;
Sujith7d01b222009-03-13 08:55:55 +0530551
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700552 ath_print(ath9k_hw_common(ah), ATH_DBG_CONFIG,
553 "Eeprom VER: %d, REV: %d\n",
554 ah->eep_ops->get_eeprom_ver(ah),
555 ah->eep_ops->get_eeprom_rev(ah));
Sujith7d01b222009-03-13 08:55:55 +0530556
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400557 ecode = ath9k_hw_rf_alloc_ext_banks(ah);
558 if (ecode) {
559 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
560 "Failed allocating banks for "
561 "external radio\n");
562 return ecode;
Luis R. Rodriguez574d6b12009-10-19 02:33:37 -0400563 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700564
565 if (!AR_SREV_9100(ah)) {
566 ath9k_hw_ani_setup(ah);
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700567 ath9k_hw_ani_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700568 }
Sujithf1dc5602008-10-29 10:16:30 +0530569
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700570 return 0;
571}
572
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400573static bool ar9002_hw_macversion_supported(u32 macversion)
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700574{
575 switch (macversion) {
576 case AR_SREV_VERSION_5416_PCI:
577 case AR_SREV_VERSION_5416_PCIE:
578 case AR_SREV_VERSION_9160:
579 case AR_SREV_VERSION_9100:
580 case AR_SREV_VERSION_9280:
581 case AR_SREV_VERSION_9285:
582 case AR_SREV_VERSION_9287:
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400583 case AR_SREV_VERSION_9271:
Luis R. Rodriguez7976b422009-09-23 23:07:02 -0400584 return true;
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700585 default:
586 break;
587 }
588 return false;
589}
590
Luis R. Rodriguez61accab2010-04-15 17:38:21 -0400591static bool ar9003_hw_macversion_supported(u32 macversion)
592{
593 switch (macversion) {
594 case AR_SREV_VERSION_9300:
595 return true;
596 default:
597 break;
598 }
599 return false;
600}
601
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400602static void ar9002_hw_init_cal_settings(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700603{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700604 if (AR_SREV_9160_10_OR_LATER(ah)) {
605 if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530606 ah->iq_caldata.calData = &iq_cal_single_sample;
607 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700608 &adc_gain_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530609 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700610 &adc_dc_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530611 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700612 &adc_init_dc_cal;
613 } else {
Sujith2660b812009-02-09 13:27:26 +0530614 ah->iq_caldata.calData = &iq_cal_multi_sample;
615 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700616 &adc_gain_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530617 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700618 &adc_dc_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530619 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700620 &adc_init_dc_cal;
621 }
Sujith2660b812009-02-09 13:27:26 +0530622 ah->supp_cals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700623 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700624}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700625
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400626static void ar9002_hw_init_mode_regs(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700627{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400628 if (AR_SREV_9271(ah)) {
Luis R. Rodriguez85643282009-10-19 02:33:33 -0400629 INIT_INI_ARRAY(&ah->iniModes, ar9271Modes_9271,
630 ARRAY_SIZE(ar9271Modes_9271), 6);
631 INIT_INI_ARRAY(&ah->iniCommon, ar9271Common_9271,
632 ARRAY_SIZE(ar9271Common_9271), 2);
Sujith70807e92010-03-17 14:25:14 +0530633 INIT_INI_ARRAY(&ah->iniCommon_normal_cck_fir_coeff_9271,
634 ar9271Common_normal_cck_fir_coeff_9271,
635 ARRAY_SIZE(ar9271Common_normal_cck_fir_coeff_9271), 2);
636 INIT_INI_ARRAY(&ah->iniCommon_japan_2484_cck_fir_coeff_9271,
637 ar9271Common_japan_2484_cck_fir_coeff_9271,
638 ARRAY_SIZE(ar9271Common_japan_2484_cck_fir_coeff_9271), 2);
Luis R. Rodriguez85643282009-10-19 02:33:33 -0400639 INIT_INI_ARRAY(&ah->iniModes_9271_1_0_only,
640 ar9271Modes_9271_1_0_only,
641 ARRAY_SIZE(ar9271Modes_9271_1_0_only), 6);
Sujith70807e92010-03-17 14:25:14 +0530642 INIT_INI_ARRAY(&ah->iniModes_9271_ANI_reg, ar9271Modes_9271_ANI_reg,
643 ARRAY_SIZE(ar9271Modes_9271_ANI_reg), 6);
644 INIT_INI_ARRAY(&ah->iniModes_high_power_tx_gain_9271,
645 ar9271Modes_high_power_tx_gain_9271,
646 ARRAY_SIZE(ar9271Modes_high_power_tx_gain_9271), 6);
647 INIT_INI_ARRAY(&ah->iniModes_normal_power_tx_gain_9271,
648 ar9271Modes_normal_power_tx_gain_9271,
649 ARRAY_SIZE(ar9271Modes_normal_power_tx_gain_9271), 6);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400650 return;
651 }
652
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530653 if (AR_SREV_9287_11_OR_LATER(ah)) {
654 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_1,
655 ARRAY_SIZE(ar9287Modes_9287_1_1), 6);
656 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_1,
657 ARRAY_SIZE(ar9287Common_9287_1_1), 2);
658 if (ah->config.pcie_clock_req)
659 INIT_INI_ARRAY(&ah->iniPcieSerdes,
660 ar9287PciePhy_clkreq_off_L1_9287_1_1,
661 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_1), 2);
662 else
663 INIT_INI_ARRAY(&ah->iniPcieSerdes,
664 ar9287PciePhy_clkreq_always_on_L1_9287_1_1,
665 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_1),
666 2);
667 } else if (AR_SREV_9287_10_OR_LATER(ah)) {
668 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_0,
669 ARRAY_SIZE(ar9287Modes_9287_1_0), 6);
670 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_0,
671 ARRAY_SIZE(ar9287Common_9287_1_0), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700672
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530673 if (ah->config.pcie_clock_req)
674 INIT_INI_ARRAY(&ah->iniPcieSerdes,
675 ar9287PciePhy_clkreq_off_L1_9287_1_0,
676 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_0), 2);
677 else
678 INIT_INI_ARRAY(&ah->iniPcieSerdes,
679 ar9287PciePhy_clkreq_always_on_L1_9287_1_0,
680 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_0),
681 2);
682 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
683
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530684
Sujith2660b812009-02-09 13:27:26 +0530685 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530686 ARRAY_SIZE(ar9285Modes_9285_1_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530687 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530688 ARRAY_SIZE(ar9285Common_9285_1_2), 2);
689
Sujith2660b812009-02-09 13:27:26 +0530690 if (ah->config.pcie_clock_req) {
691 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530692 ar9285PciePhy_clkreq_off_L1_9285_1_2,
693 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2);
694 } else {
Sujith2660b812009-02-09 13:27:26 +0530695 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530696 ar9285PciePhy_clkreq_always_on_L1_9285_1_2,
697 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2),
698 2);
699 }
700 } else if (AR_SREV_9285_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530701 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530702 ARRAY_SIZE(ar9285Modes_9285), 6);
Sujith2660b812009-02-09 13:27:26 +0530703 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530704 ARRAY_SIZE(ar9285Common_9285), 2);
705
Sujith2660b812009-02-09 13:27:26 +0530706 if (ah->config.pcie_clock_req) {
707 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530708 ar9285PciePhy_clkreq_off_L1_9285,
709 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2);
710 } else {
Sujith2660b812009-02-09 13:27:26 +0530711 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530712 ar9285PciePhy_clkreq_always_on_L1_9285,
713 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285), 2);
714 }
715 } else if (AR_SREV_9280_20_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530716 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700717 ARRAY_SIZE(ar9280Modes_9280_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530718 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700719 ARRAY_SIZE(ar9280Common_9280_2), 2);
720
Sujith2660b812009-02-09 13:27:26 +0530721 if (ah->config.pcie_clock_req) {
722 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530723 ar9280PciePhy_clkreq_off_L1_9280,
724 ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700725 } else {
Sujith2660b812009-02-09 13:27:26 +0530726 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530727 ar9280PciePhy_clkreq_always_on_L1_9280,
728 ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700729 }
Sujith2660b812009-02-09 13:27:26 +0530730 INIT_INI_ARRAY(&ah->iniModesAdditional,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700731 ar9280Modes_fast_clock_9280_2,
Sujithf1dc5602008-10-29 10:16:30 +0530732 ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700733 } else if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530734 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700735 ARRAY_SIZE(ar9280Modes_9280), 6);
Sujith2660b812009-02-09 13:27:26 +0530736 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700737 ARRAY_SIZE(ar9280Common_9280), 2);
738 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530739 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700740 ARRAY_SIZE(ar5416Modes_9160), 6);
Sujith2660b812009-02-09 13:27:26 +0530741 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700742 ARRAY_SIZE(ar5416Common_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530743 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700744 ARRAY_SIZE(ar5416Bank0_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530745 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700746 ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530747 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700748 ARRAY_SIZE(ar5416Bank1_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530749 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700750 ARRAY_SIZE(ar5416Bank2_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530751 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700752 ARRAY_SIZE(ar5416Bank3_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530753 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700754 ARRAY_SIZE(ar5416Bank6_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530755 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700756 ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530757 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700758 ARRAY_SIZE(ar5416Bank7_9160), 2);
759 if (AR_SREV_9160_11(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530760 INIT_INI_ARRAY(&ah->iniAddac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700761 ar5416Addac_91601_1,
762 ARRAY_SIZE(ar5416Addac_91601_1), 2);
763 } else {
Sujith2660b812009-02-09 13:27:26 +0530764 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700765 ARRAY_SIZE(ar5416Addac_9160), 2);
766 }
767 } else if (AR_SREV_9100_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530768 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700769 ARRAY_SIZE(ar5416Modes_9100), 6);
Sujith2660b812009-02-09 13:27:26 +0530770 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700771 ARRAY_SIZE(ar5416Common_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530772 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700773 ARRAY_SIZE(ar5416Bank0_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530774 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700775 ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530776 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700777 ARRAY_SIZE(ar5416Bank1_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530778 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700779 ARRAY_SIZE(ar5416Bank2_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530780 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700781 ARRAY_SIZE(ar5416Bank3_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530782 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700783 ARRAY_SIZE(ar5416Bank6_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530784 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700785 ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530786 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700787 ARRAY_SIZE(ar5416Bank7_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530788 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700789 ARRAY_SIZE(ar5416Addac_9100), 2);
790 } else {
Sujith2660b812009-02-09 13:27:26 +0530791 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700792 ARRAY_SIZE(ar5416Modes), 6);
Sujith2660b812009-02-09 13:27:26 +0530793 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700794 ARRAY_SIZE(ar5416Common), 2);
Sujith2660b812009-02-09 13:27:26 +0530795 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700796 ARRAY_SIZE(ar5416Bank0), 2);
Sujith2660b812009-02-09 13:27:26 +0530797 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700798 ARRAY_SIZE(ar5416BB_RfGain), 3);
Sujith2660b812009-02-09 13:27:26 +0530799 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700800 ARRAY_SIZE(ar5416Bank1), 2);
Sujith2660b812009-02-09 13:27:26 +0530801 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700802 ARRAY_SIZE(ar5416Bank2), 2);
Sujith2660b812009-02-09 13:27:26 +0530803 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700804 ARRAY_SIZE(ar5416Bank3), 3);
Sujith2660b812009-02-09 13:27:26 +0530805 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700806 ARRAY_SIZE(ar5416Bank6), 3);
Sujith2660b812009-02-09 13:27:26 +0530807 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700808 ARRAY_SIZE(ar5416Bank6TPC), 3);
Sujith2660b812009-02-09 13:27:26 +0530809 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700810 ARRAY_SIZE(ar5416Bank7), 2);
Sujith2660b812009-02-09 13:27:26 +0530811 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700812 ARRAY_SIZE(ar5416Addac), 2);
813 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700814}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700815
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700816static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
817{
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530818 if (AR_SREV_9287_11_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530819 INIT_INI_ARRAY(&ah->iniModesRxGain,
820 ar9287Modes_rx_gain_9287_1_1,
821 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_1), 6);
822 else if (AR_SREV_9287_10(ah))
823 INIT_INI_ARRAY(&ah->iniModesRxGain,
824 ar9287Modes_rx_gain_9287_1_0,
825 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_0), 6);
826 else if (AR_SREV_9280_20(ah))
827 ath9k_hw_init_rxgain_ini(ah);
828
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530829 if (AR_SREV_9287_11_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530830 INIT_INI_ARRAY(&ah->iniModesTxGain,
831 ar9287Modes_tx_gain_9287_1_1,
832 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_1), 6);
833 } else if (AR_SREV_9287_10(ah)) {
834 INIT_INI_ARRAY(&ah->iniModesTxGain,
835 ar9287Modes_tx_gain_9287_1_0,
836 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_0), 6);
837 } else if (AR_SREV_9280_20(ah)) {
838 ath9k_hw_init_txgain_ini(ah);
839 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530840 u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
841
842 /* txgain table */
843 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) {
Vivek Natarajan53bc7aa2010-04-05 14:48:04 +0530844 if (AR_SREV_9285E_20(ah)) {
845 INIT_INI_ARRAY(&ah->iniModesTxGain,
846 ar9285Modes_XE2_0_high_power,
847 ARRAY_SIZE(
848 ar9285Modes_XE2_0_high_power), 6);
849 } else {
850 INIT_INI_ARRAY(&ah->iniModesTxGain,
851 ar9285Modes_high_power_tx_gain_9285_1_2,
852 ARRAY_SIZE(
853 ar9285Modes_high_power_tx_gain_9285_1_2), 6);
854 }
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530855 } else {
Vivek Natarajan53bc7aa2010-04-05 14:48:04 +0530856 if (AR_SREV_9285E_20(ah)) {
857 INIT_INI_ARRAY(&ah->iniModesTxGain,
858 ar9285Modes_XE2_0_normal_power,
859 ARRAY_SIZE(
860 ar9285Modes_XE2_0_normal_power), 6);
861 } else {
862 INIT_INI_ARRAY(&ah->iniModesTxGain,
863 ar9285Modes_original_tx_gain_9285_1_2,
864 ARRAY_SIZE(
865 ar9285Modes_original_tx_gain_9285_1_2), 6);
866 }
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530867 }
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530868 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700869}
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530870
Felix Fietkauaa8bc9e2010-01-23 20:04:18 +0100871static void ath9k_hw_init_eeprom_fix(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700872{
Pavel Roskin2eb46d92010-04-07 01:33:33 -0400873 struct base_eep_header *pBase = &(ah->eeprom.def.baseEepHeader);
874 struct ath_common *common = ath9k_hw_common(ah);
Sujith06d0f062009-02-12 10:06:45 +0530875
Pavel Roskin2eb46d92010-04-07 01:33:33 -0400876 ah->need_an_top2_fixup = (ah->hw_version.devid == AR9280_DEVID_PCI) &&
877 (ah->eep_map != EEP_MAP_4KBITS) &&
878 ((pBase->version & 0xff) > 0x0a) &&
879 (pBase->pwdclkind == 0);
Sujith06d0f062009-02-12 10:06:45 +0530880
Pavel Roskin2eb46d92010-04-07 01:33:33 -0400881 if (ah->need_an_top2_fixup)
882 ath_print(common, ATH_DBG_EEPROM,
883 "needs fixup for AR_AN_TOP2 register\n");
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700884}
885
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400886static void ath9k_hw_attach_ops(struct ath_hw *ah)
887{
888 if (AR_SREV_9300_20_OR_LATER(ah))
889 ar9003_hw_attach_ops(ah);
890 else
891 ar9002_hw_attach_ops(ah);
892}
893
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400894/* Called for all hardware families */
895static int __ath9k_hw_init(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700896{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700897 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700898 int r = 0;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700899
Luis R. Rodriguezbab1f622010-04-15 17:38:20 -0400900 if (ah->hw_version.devid == AR5416_AR9100_DEVID)
901 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700902
903 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700904 ath_print(common, ATH_DBG_FATAL,
905 "Couldn't reset chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700906 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700907 }
908
Luis R. Rodriguezbab1f622010-04-15 17:38:20 -0400909 ath9k_hw_init_defaults(ah);
910 ath9k_hw_init_config(ah);
911
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400912 ath9k_hw_attach_ops(ah);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400913
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700914 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700915 ath_print(common, ATH_DBG_FATAL, "Couldn't wakeup chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700916 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700917 }
918
919 if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
920 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
921 (AR_SREV_9280(ah) && !ah->is_pciexpress)) {
922 ah->config.serialize_regmode =
923 SER_REG_MODE_ON;
924 } else {
925 ah->config.serialize_regmode =
926 SER_REG_MODE_OFF;
927 }
928 }
929
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700930 ath_print(common, ATH_DBG_RESET, "serialize_regmode is %d\n",
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700931 ah->config.serialize_regmode);
932
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -0500933 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
934 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD >> 1;
935 else
936 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD;
937
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400938 if (!ath9k_hw_macversion_supported(ah)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700939 ath_print(common, ATH_DBG_FATAL,
940 "Mac Chip Rev 0x%02x.%x is not supported by "
941 "this driver\n", ah->hw_version.macVersion,
942 ah->hw_version.macRev);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700943 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700944 }
945
946 if (AR_SREV_9100(ah)) {
947 ah->iq_caldata.calData = &iq_cal_multi_sample;
948 ah->supp_cals = IQ_MISMATCH_CAL;
949 ah->is_pciexpress = false;
950 }
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400951
952 if (AR_SREV_9271(ah))
953 ah->is_pciexpress = false;
954
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700955 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700956 ath9k_hw_init_cal_settings(ah);
957
958 ah->ani_function = ATH9K_ANI_ALL;
Luis R. Rodriguez31a0bd32010-04-15 17:38:22 -0400959 if (AR_SREV_9280_10_OR_LATER(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700960 ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
961
962 ath9k_hw_init_mode_regs(ah);
963
964 if (ah->is_pciexpress)
Vivek Natarajan93b1b372009-09-17 09:24:58 +0530965 ath9k_hw_configpcipowersave(ah, 0, 0);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700966 else
967 ath9k_hw_disablepcie(ah);
968
Sujith193cd452009-09-18 15:04:07 +0530969 /* Support for Japan ch.14 (2484) spread */
970 if (AR_SREV_9287_11_OR_LATER(ah)) {
971 INIT_INI_ARRAY(&ah->iniCckfirNormal,
972 ar9287Common_normal_cck_fir_coeff_92871_1,
973 ARRAY_SIZE(ar9287Common_normal_cck_fir_coeff_92871_1), 2);
974 INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
975 ar9287Common_japan_2484_cck_fir_coeff_92871_1,
976 ARRAY_SIZE(ar9287Common_japan_2484_cck_fir_coeff_92871_1), 2);
977 }
978
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700979 r = ath9k_hw_post_init(ah);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700980 if (r)
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700981 return r;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700982
983 ath9k_hw_init_mode_gain_regs(ah);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +0100984 r = ath9k_hw_fill_cap_info(ah);
985 if (r)
986 return r;
987
Felix Fietkauaa8bc9e2010-01-23 20:04:18 +0100988 ath9k_hw_init_eeprom_fix(ah);
Sujithf6688cd2008-12-07 21:43:10 +0530989
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700990 r = ath9k_hw_init_macaddr(ah);
991 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700992 ath_print(common, ATH_DBG_FATAL,
993 "Failed to initialize MAC address\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700994 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700995 }
996
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400997 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
Sujith2660b812009-02-09 13:27:26 +0530998 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700999 else
Sujith2660b812009-02-09 13:27:26 +05301000 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001001
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001002 ath9k_init_nfcal_hist_buffer(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001003
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001004 common->state = ATH_HW_INITIALIZED;
1005
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001006 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001007}
1008
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04001009int ath9k_hw_init(struct ath_hw *ah)
1010{
1011 int ret;
1012 struct ath_common *common = ath9k_hw_common(ah);
1013
1014 /* These are all the AR5008/AR9001/AR9002 hardware family of chipsets */
1015 switch (ah->hw_version.devid) {
1016 case AR5416_DEVID_PCI:
1017 case AR5416_DEVID_PCIE:
1018 case AR5416_AR9100_DEVID:
1019 case AR9160_DEVID_PCI:
1020 case AR9280_DEVID_PCI:
1021 case AR9280_DEVID_PCIE:
1022 case AR9285_DEVID_PCIE:
Senthil Balasubramaniandb3cc532010-04-15 17:38:18 -04001023 case AR9287_DEVID_PCI:
1024 case AR9287_DEVID_PCIE:
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04001025 case AR2427_DEVID_PCIE:
Senthil Balasubramaniandb3cc532010-04-15 17:38:18 -04001026 case AR9300_DEVID_PCIE:
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04001027 break;
1028 default:
1029 if (common->bus_ops->ath_bus_type == ATH_USB)
1030 break;
1031 ath_print(common, ATH_DBG_FATAL,
1032 "Hardware device ID 0x%04x not supported\n",
1033 ah->hw_version.devid);
1034 return -EOPNOTSUPP;
1035 }
1036
1037 ret = __ath9k_hw_init(ah);
1038 if (ret) {
1039 ath_print(common, ATH_DBG_FATAL,
1040 "Unable to initialize hardware; "
1041 "initialization status: %d\n", ret);
1042 return ret;
1043 }
1044
1045 return 0;
1046}
1047EXPORT_SYMBOL(ath9k_hw_init);
1048
Sujithcbe61d82009-02-09 13:27:12 +05301049static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301050{
1051 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
1052 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
1053
1054 REG_WRITE(ah, AR_QOS_NO_ACK,
1055 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
1056 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
1057 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
1058
1059 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
1060 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
1061 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
1062 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
1063 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
1064}
1065
Sujithcbe61d82009-02-09 13:27:12 +05301066static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301067 struct ath9k_channel *chan)
1068{
Luis R. Rodriguez64773962010-04-15 17:38:17 -04001069 u32 pll = ath9k_hw_compute_pll_control(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301070
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001071 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +05301072
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -04001073 /* Switch the core clock for ar9271 to 117Mhz */
1074 if (AR_SREV_9271(ah)) {
Sujith25e2ab12010-03-17 14:25:22 +05301075 udelay(500);
1076 REG_WRITE(ah, 0x50040, 0x304);
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -04001077 }
1078
Sujithf1dc5602008-10-29 10:16:30 +05301079 udelay(RTC_PLL_SETTLE_DELAY);
1080
1081 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
1082}
1083
Sujithcbe61d82009-02-09 13:27:12 +05301084static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -08001085 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301086{
Pavel Roskin152d5302010-03-31 18:05:37 -04001087 u32 imr_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +05301088 AR_IMR_TXURN |
1089 AR_IMR_RXERR |
1090 AR_IMR_RXORN |
1091 AR_IMR_BCNMISC;
1092
Sujith0ce024c2009-12-14 14:57:00 +05301093 if (ah->config.rx_intr_mitigation)
Pavel Roskin152d5302010-03-31 18:05:37 -04001094 imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
Sujithf1dc5602008-10-29 10:16:30 +05301095 else
Pavel Roskin152d5302010-03-31 18:05:37 -04001096 imr_reg |= AR_IMR_RXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301097
Pavel Roskin152d5302010-03-31 18:05:37 -04001098 imr_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301099
Colin McCabed97809d2008-12-01 13:38:55 -08001100 if (opmode == NL80211_IFTYPE_AP)
Pavel Roskin152d5302010-03-31 18:05:37 -04001101 imr_reg |= AR_IMR_MIB;
Sujithf1dc5602008-10-29 10:16:30 +05301102
Pavel Roskin152d5302010-03-31 18:05:37 -04001103 REG_WRITE(ah, AR_IMR, imr_reg);
Pavel Roskin74bad5c2010-02-23 18:15:27 -05001104 ah->imrs2_reg |= AR_IMR_S2_GTT;
1105 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
Sujithf1dc5602008-10-29 10:16:30 +05301106
1107 if (!AR_SREV_9100(ah)) {
1108 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
1109 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
1110 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
1111 }
1112}
1113
Felix Fietkau0005baf2010-01-15 02:33:40 +01001114static void ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301115{
Felix Fietkau0005baf2010-01-15 02:33:40 +01001116 u32 val = ath9k_hw_mac_to_clks(ah, us);
1117 val = min(val, (u32) 0xFFFF);
1118 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, val);
Sujithf1dc5602008-10-29 10:16:30 +05301119}
1120
Felix Fietkau0005baf2010-01-15 02:33:40 +01001121static void ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301122{
Felix Fietkau0005baf2010-01-15 02:33:40 +01001123 u32 val = ath9k_hw_mac_to_clks(ah, us);
1124 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_ACK));
1125 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_ACK, val);
1126}
1127
1128static void ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
1129{
1130 u32 val = ath9k_hw_mac_to_clks(ah, us);
1131 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_CTS));
1132 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_CTS, val);
Sujithf1dc5602008-10-29 10:16:30 +05301133}
1134
Sujithcbe61d82009-02-09 13:27:12 +05301135static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +05301136{
Sujithf1dc5602008-10-29 10:16:30 +05301137 if (tu > 0xFFFF) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001138 ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT,
1139 "bad global tx timeout %u\n", tu);
Sujith2660b812009-02-09 13:27:26 +05301140 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301141 return false;
1142 } else {
1143 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +05301144 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +05301145 return true;
1146 }
1147}
1148
Felix Fietkau0005baf2010-01-15 02:33:40 +01001149void ath9k_hw_init_global_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301150{
Felix Fietkau0005baf2010-01-15 02:33:40 +01001151 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
1152 int acktimeout;
Felix Fietkaue239d852010-01-15 02:34:58 +01001153 int slottime;
Felix Fietkau0005baf2010-01-15 02:33:40 +01001154 int sifstime;
1155
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001156 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
1157 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +05301158
Sujith2660b812009-02-09 13:27:26 +05301159 if (ah->misc_mode != 0)
Sujithf1dc5602008-10-29 10:16:30 +05301160 REG_WRITE(ah, AR_PCU_MISC,
Sujith2660b812009-02-09 13:27:26 +05301161 REG_READ(ah, AR_PCU_MISC) | ah->misc_mode);
Felix Fietkau0005baf2010-01-15 02:33:40 +01001162
1163 if (conf->channel && conf->channel->band == IEEE80211_BAND_5GHZ)
1164 sifstime = 16;
1165 else
1166 sifstime = 10;
1167
Felix Fietkaue239d852010-01-15 02:34:58 +01001168 /* As defined by IEEE 802.11-2007 17.3.8.6 */
1169 slottime = ah->slottime + 3 * ah->coverage_class;
1170 acktimeout = slottime + sifstime;
Felix Fietkau42c45682010-02-11 18:07:19 +01001171
1172 /*
1173 * Workaround for early ACK timeouts, add an offset to match the
1174 * initval's 64us ack timeout value.
1175 * This was initially only meant to work around an issue with delayed
1176 * BA frames in some implementations, but it has been found to fix ACK
1177 * timeout issues in other cases as well.
1178 */
1179 if (conf->channel && conf->channel->band == IEEE80211_BAND_2GHZ)
1180 acktimeout += 64 - sifstime - ah->slottime;
1181
Felix Fietkaue239d852010-01-15 02:34:58 +01001182 ath9k_hw_setslottime(ah, slottime);
Felix Fietkau0005baf2010-01-15 02:33:40 +01001183 ath9k_hw_set_ack_timeout(ah, acktimeout);
1184 ath9k_hw_set_cts_timeout(ah, acktimeout);
Sujith2660b812009-02-09 13:27:26 +05301185 if (ah->globaltxtimeout != (u32) -1)
1186 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Sujithf1dc5602008-10-29 10:16:30 +05301187}
Felix Fietkau0005baf2010-01-15 02:33:40 +01001188EXPORT_SYMBOL(ath9k_hw_init_global_settings);
Sujithf1dc5602008-10-29 10:16:30 +05301189
Sujith285f2dd2010-01-08 10:36:07 +05301190void ath9k_hw_deinit(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001191{
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001192 struct ath_common *common = ath9k_hw_common(ah);
1193
Sujith736b3a22010-03-17 14:25:24 +05301194 if (common->state < ATH_HW_INITIALIZED)
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001195 goto free_hw;
1196
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001197 if (!AR_SREV_9100(ah))
Luis R. Rodrigueze70c0cf2009-08-03 12:24:51 -07001198 ath9k_hw_ani_disable(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001199
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001200 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001201
1202free_hw:
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001203 ath9k_hw_rf_free_ext_banks(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001204}
Sujith285f2dd2010-01-08 10:36:07 +05301205EXPORT_SYMBOL(ath9k_hw_deinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001206
Sujithf1dc5602008-10-29 10:16:30 +05301207/*******/
1208/* INI */
1209/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001210
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001211u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan)
Bob Copeland3a702e42009-03-30 22:30:29 -04001212{
1213 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
1214
1215 if (IS_CHAN_B(chan))
1216 ctl |= CTL_11B;
1217 else if (IS_CHAN_G(chan))
1218 ctl |= CTL_11G;
1219 else
1220 ctl |= CTL_11A;
1221
1222 return ctl;
1223}
1224
Sujithf1dc5602008-10-29 10:16:30 +05301225/****************************************/
1226/* Reset and Channel Switching Routines */
1227/****************************************/
1228
Sujithcbe61d82009-02-09 13:27:12 +05301229static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301230{
1231 u32 regval;
1232
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001233 /*
1234 * set AHB_MODE not to do cacheline prefetches
1235 */
Sujithf1dc5602008-10-29 10:16:30 +05301236 regval = REG_READ(ah, AR_AHB_MODE);
1237 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
1238
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001239 /*
1240 * let mac dma reads be in 128 byte chunks
1241 */
Sujithf1dc5602008-10-29 10:16:30 +05301242 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
1243 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
1244
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001245 /*
1246 * Restore TX Trigger Level to its pre-reset value.
1247 * The initial value depends on whether aggregation is enabled, and is
1248 * adjusted whenever underruns are detected.
1249 */
Sujith2660b812009-02-09 13:27:26 +05301250 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +05301251
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001252 /*
1253 * let mac dma writes be in 128 byte chunks
1254 */
Sujithf1dc5602008-10-29 10:16:30 +05301255 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
1256 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
1257
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001258 /*
1259 * Setup receive FIFO threshold to hold off TX activities
1260 */
Sujithf1dc5602008-10-29 10:16:30 +05301261 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1262
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001263 /*
1264 * reduce the number of usable entries in PCU TXBUF to avoid
1265 * wrap around issues.
1266 */
Sujithf1dc5602008-10-29 10:16:30 +05301267 if (AR_SREV_9285(ah)) {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001268 /* For AR9285 the number of Fifos are reduced to half.
1269 * So set the usable tx buf size also to half to
1270 * avoid data/delimiter underruns
1271 */
Sujithf1dc5602008-10-29 10:16:30 +05301272 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1273 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001274 } else if (!AR_SREV_9271(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +05301275 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1276 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1277 }
1278}
1279
Sujithcbe61d82009-02-09 13:27:12 +05301280static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301281{
1282 u32 val;
1283
1284 val = REG_READ(ah, AR_STA_ID1);
1285 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
1286 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001287 case NL80211_IFTYPE_AP:
Sujithf1dc5602008-10-29 10:16:30 +05301288 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
1289 | AR_STA_ID1_KSRCH_MODE);
1290 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1291 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001292 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04001293 case NL80211_IFTYPE_MESH_POINT:
Sujithf1dc5602008-10-29 10:16:30 +05301294 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
1295 | AR_STA_ID1_KSRCH_MODE);
1296 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1297 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001298 case NL80211_IFTYPE_STATION:
1299 case NL80211_IFTYPE_MONITOR:
Sujithf1dc5602008-10-29 10:16:30 +05301300 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
1301 break;
1302 }
1303}
1304
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001305void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled,
1306 u32 *coef_mantissa, u32 *coef_exponent)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001307{
1308 u32 coef_exp, coef_man;
1309
1310 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1311 if ((coef_scaled >> coef_exp) & 0x1)
1312 break;
1313
1314 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1315
1316 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1317
1318 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1319 *coef_exponent = coef_exp - 16;
1320}
1321
Sujithcbe61d82009-02-09 13:27:12 +05301322static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +05301323{
1324 u32 rst_flags;
1325 u32 tmpReg;
1326
Sujith70768492009-02-16 13:23:12 +05301327 if (AR_SREV_9100(ah)) {
1328 u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK);
1329 val &= ~AR_RTC_DERIVED_CLK_PERIOD;
1330 val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD);
1331 REG_WRITE(ah, AR_RTC_DERIVED_CLK, val);
1332 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1333 }
1334
Sujithf1dc5602008-10-29 10:16:30 +05301335 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1336 AR_RTC_FORCE_WAKE_ON_INT);
1337
1338 if (AR_SREV_9100(ah)) {
1339 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1340 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1341 } else {
1342 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1343 if (tmpReg &
1344 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1345 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001346 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05301347 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001348
1349 val = AR_RC_HOSTIF;
1350 if (!AR_SREV_9300_20_OR_LATER(ah))
1351 val |= AR_RC_AHB;
1352 REG_WRITE(ah, AR_RC, val);
1353
1354 } else if (!AR_SREV_9300_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05301355 REG_WRITE(ah, AR_RC, AR_RC_AHB);
Sujithf1dc5602008-10-29 10:16:30 +05301356
1357 rst_flags = AR_RTC_RC_MAC_WARM;
1358 if (type == ATH9K_RESET_COLD)
1359 rst_flags |= AR_RTC_RC_MAC_COLD;
1360 }
1361
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001362 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujithf1dc5602008-10-29 10:16:30 +05301363 udelay(50);
1364
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001365 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301366 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001367 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1368 "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301369 return false;
1370 }
1371
1372 if (!AR_SREV_9100(ah))
1373 REG_WRITE(ah, AR_RC, 0);
1374
Sujithf1dc5602008-10-29 10:16:30 +05301375 if (AR_SREV_9100(ah))
1376 udelay(50);
1377
1378 return true;
1379}
1380
Sujithcbe61d82009-02-09 13:27:12 +05301381static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301382{
1383 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1384 AR_RTC_FORCE_WAKE_ON_INT);
1385
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001386 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301387 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1388
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001389 REG_WRITE(ah, AR_RTC_RESET, 0);
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301390
Senthil Balasubramanian84e21692010-04-15 17:38:30 -04001391 if (!AR_SREV_9300_20_OR_LATER(ah))
1392 udelay(2);
1393
1394 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301395 REG_WRITE(ah, AR_RC, 0);
1396
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001397 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301398
1399 if (!ath9k_hw_wait(ah,
1400 AR_RTC_STATUS,
1401 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301402 AR_RTC_STATUS_ON,
1403 AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001404 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1405 "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301406 return false;
1407 }
1408
1409 ath9k_hw_read_revisions(ah);
1410
1411 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1412}
1413
Sujithcbe61d82009-02-09 13:27:12 +05301414static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301415{
1416 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1417 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1418
1419 switch (type) {
1420 case ATH9K_RESET_POWER_ON:
1421 return ath9k_hw_set_reset_power_on(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301422 case ATH9K_RESET_WARM:
1423 case ATH9K_RESET_COLD:
1424 return ath9k_hw_set_reset(ah, type);
Sujithf1dc5602008-10-29 10:16:30 +05301425 default:
1426 return false;
1427 }
1428}
1429
Sujithcbe61d82009-02-09 13:27:12 +05301430static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301431 struct ath9k_channel *chan)
1432{
Vivek Natarajan42abfbe2009-09-17 09:27:59 +05301433 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) {
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301434 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
1435 return false;
1436 } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
Sujithf1dc5602008-10-29 10:16:30 +05301437 return false;
1438
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001439 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05301440 return false;
1441
Sujith2660b812009-02-09 13:27:26 +05301442 ah->chip_fullsleep = false;
Sujithf1dc5602008-10-29 10:16:30 +05301443 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301444 ath9k_hw_set_rfmode(ah, chan);
1445
1446 return true;
1447}
1448
Sujithcbe61d82009-02-09 13:27:12 +05301449static bool ath9k_hw_channel_change(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001450 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301451{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001452 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001453 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001454 struct ieee80211_channel *channel = chan->chan;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001455 u32 qnum;
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001456 int r;
Sujithf1dc5602008-10-29 10:16:30 +05301457
1458 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1459 if (ath9k_hw_numtxpending(ah, qnum)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001460 ath_print(common, ATH_DBG_QUEUE,
1461 "Transmit frames pending on "
1462 "queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301463 return false;
1464 }
1465 }
1466
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001467 if (!ath9k_hw_rfbus_req(ah)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001468 ath_print(common, ATH_DBG_FATAL,
1469 "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301470 return false;
1471 }
1472
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001473 ath9k_hw_set_channel_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301474
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001475 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001476 if (r) {
1477 ath_print(common, ATH_DBG_FATAL,
1478 "Failed to set channel\n");
1479 return false;
Sujithf1dc5602008-10-29 10:16:30 +05301480 }
1481
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001482 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001483 ath9k_regd_get_ctl(regulatory, chan),
Sujithf74df6f2009-02-09 13:27:24 +05301484 channel->max_antenna_gain * 2,
1485 channel->max_power * 2,
1486 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001487 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05301488
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001489 ath9k_hw_rfbus_done(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301490
1491 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1492 ath9k_hw_set_delta_slope(ah, chan);
1493
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001494 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301495
1496 if (!chan->oneTimeCalsDone)
1497 chan->oneTimeCalsDone = true;
1498
1499 return true;
1500}
1501
Sujithcbe61d82009-02-09 13:27:12 +05301502int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001503 bool bChannelChange)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001504{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001505 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001506 u32 saveLedState;
Sujith2660b812009-02-09 13:27:26 +05301507 struct ath9k_channel *curchan = ah->curchan;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001508 u32 saveDefAntenna;
1509 u32 macStaId1;
Sujith46fe7822009-09-17 09:25:25 +05301510 u64 tsf = 0;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001511 int i, r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001512
Luis R. Rodriguez43c27612009-09-13 21:07:07 -07001513 ah->txchainmask = common->tx_chainmask;
1514 ah->rxchainmask = common->rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001515
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001516 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001517 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001518
Vasanthakumar Thiagarajan9ebef792009-09-17 09:26:44 +05301519 if (curchan && !ah->chip_fullsleep)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001520 ath9k_hw_getnf(ah, curchan);
1521
1522 if (bChannelChange &&
Sujith2660b812009-02-09 13:27:26 +05301523 (ah->chip_fullsleep != true) &&
1524 (ah->curchan != NULL) &&
1525 (chan->channel != ah->curchan->channel) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001526 ((chan->channelFlags & CHANNEL_ALL) ==
Sujith2660b812009-02-09 13:27:26 +05301527 (ah->curchan->channelFlags & CHANNEL_ALL)) &&
Vasanthakumar Thiagarajan0a475cc2009-09-17 09:27:10 +05301528 !(AR_SREV_9280(ah) || IS_CHAN_A_5MHZ_SPACED(chan) ||
1529 IS_CHAN_A_5MHZ_SPACED(ah->curchan))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001530
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001531 if (ath9k_hw_channel_change(ah, chan)) {
Sujith2660b812009-02-09 13:27:26 +05301532 ath9k_hw_loadnf(ah, ah->curchan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001533 ath9k_hw_start_nfcal(ah);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001534 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001535 }
1536 }
1537
1538 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
1539 if (saveDefAntenna == 0)
1540 saveDefAntenna = 1;
1541
1542 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
1543
Sujith46fe7822009-09-17 09:25:25 +05301544 /* For chips on which RTC reset is done, save TSF before it gets cleared */
1545 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1546 tsf = ath9k_hw_gettsf64(ah);
1547
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001548 saveLedState = REG_READ(ah, AR_CFG_LED) &
1549 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
1550 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
1551
1552 ath9k_hw_mark_phy_inactive(ah);
1553
Sujith05020d22010-03-17 14:25:23 +05301554 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001555 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1556 REG_WRITE(ah,
1557 AR9271_RESET_POWER_DOWN_CONTROL,
1558 AR9271_RADIO_RF_RST);
1559 udelay(50);
1560 }
1561
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001562 if (!ath9k_hw_chip_reset(ah, chan)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001563 ath_print(common, ATH_DBG_FATAL, "Chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001564 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001565 }
1566
Sujith05020d22010-03-17 14:25:23 +05301567 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001568 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1569 ah->htc_reset_init = false;
1570 REG_WRITE(ah,
1571 AR9271_RESET_POWER_DOWN_CONTROL,
1572 AR9271_GATE_MAC_CTL);
1573 udelay(50);
1574 }
1575
Sujith46fe7822009-09-17 09:25:25 +05301576 /* Restore TSF */
1577 if (tsf && AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1578 ath9k_hw_settsf64(ah, tsf);
1579
Vasanthakumar Thiagarajan369391d2009-01-21 19:24:13 +05301580 if (AR_SREV_9280_10_OR_LATER(ah))
1581 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001582
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001583 r = ath9k_hw_process_ini(ah, chan);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001584 if (r)
1585 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001586
Jouni Malinen0ced0e12009-01-08 13:32:13 +02001587 /* Setup MFP options for CCMP */
1588 if (AR_SREV_9280_20_OR_LATER(ah)) {
1589 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
1590 * frames when constructing CCMP AAD. */
1591 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
1592 0xc7ff);
1593 ah->sw_mgmt_crypto = false;
1594 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1595 /* Disable hardware crypto for management frames */
1596 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
1597 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
1598 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1599 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
1600 ah->sw_mgmt_crypto = true;
1601 } else
1602 ah->sw_mgmt_crypto = true;
1603
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001604 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1605 ath9k_hw_set_delta_slope(ah, chan);
1606
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001607 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithd6509152009-03-13 08:56:05 +05301608 ah->eep_ops->set_board_values(ah, chan);
Luis R. Rodrigueza7765822009-10-19 02:33:45 -04001609
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001610 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
1611 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001612 | macStaId1
1613 | AR_STA_ID1_RTS_USE_DEF
Sujith2660b812009-02-09 13:27:26 +05301614 | (ah->config.
Sujith60b67f52008-08-07 10:52:38 +05301615 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Sujith2660b812009-02-09 13:27:26 +05301616 | ah->sta_id1_defaults);
1617 ath9k_hw_set_operating_mode(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001618
Luis R. Rodriguez13b81552009-09-10 17:52:45 -07001619 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001620
1621 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
1622
Luis R. Rodriguez3453ad82009-09-10 08:57:00 -07001623 ath9k_hw_write_associd(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001624
1625 REG_WRITE(ah, AR_ISR, ~0);
1626
1627 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
1628
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001629 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001630 if (r)
1631 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001632
1633 for (i = 0; i < AR_NUM_DCU; i++)
1634 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
1635
Sujith2660b812009-02-09 13:27:26 +05301636 ah->intr_txqs = 0;
1637 for (i = 0; i < ah->caps.total_queues; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001638 ath9k_hw_resettxqueue(ah, i);
1639
Sujith2660b812009-02-09 13:27:26 +05301640 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001641 ath9k_hw_init_qos(ah);
1642
Sujith2660b812009-02-09 13:27:26 +05301643 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301644 ath9k_enable_rfkill(ah);
Johannes Berg3b319aa2009-06-13 14:50:26 +05301645
Felix Fietkau0005baf2010-01-15 02:33:40 +01001646 ath9k_hw_init_global_settings(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001647
Vivek Natarajan326bebb2009-08-14 11:33:36 +05301648 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301649 REG_WRITE(ah, AR_D_GBL_IFS_SIFS,
1650 AR_D_GBL_IFS_SIFS_ASYNC_FIFO_DUR);
1651 REG_WRITE(ah, AR_D_GBL_IFS_SLOT,
1652 AR_D_GBL_IFS_SLOT_ASYNC_FIFO_DUR);
1653 REG_WRITE(ah, AR_D_GBL_IFS_EIFS,
1654 AR_D_GBL_IFS_EIFS_ASYNC_FIFO_DUR);
1655
1656 REG_WRITE(ah, AR_TIME_OUT, AR_TIME_OUT_ACK_CTS_ASYNC_FIFO_DUR);
1657 REG_WRITE(ah, AR_USEC, AR_USEC_ASYNC_FIFO_DUR);
1658
1659 REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
1660 AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
1661 REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
1662 AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
1663 }
Vivek Natarajan326bebb2009-08-14 11:33:36 +05301664 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301665 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1666 AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
1667 }
1668
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001669 REG_WRITE(ah, AR_STA_ID1,
1670 REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
1671
1672 ath9k_hw_set_dma(ah);
1673
1674 REG_WRITE(ah, AR_OBS, 8);
1675
Sujith0ce024c2009-12-14 14:57:00 +05301676 if (ah->config.rx_intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001677 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
1678 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
1679 }
1680
1681 ath9k_hw_init_bb(ah, chan);
1682
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001683 if (!ath9k_hw_init_cal(ah, chan))
Joe Perches6badaaf2009-06-28 09:26:32 -07001684 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001685
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001686 ath9k_hw_restore_chainmask(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001687 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
1688
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001689 /*
1690 * For big endian systems turn on swapping for descriptors
1691 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001692 if (AR_SREV_9100(ah)) {
1693 u32 mask;
1694 mask = REG_READ(ah, AR_CFG);
1695 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001696 ath_print(common, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05301697 "CFG Byte Swap Set 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001698 } else {
1699 mask =
1700 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
1701 REG_WRITE(ah, AR_CFG, mask);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001702 ath_print(common, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05301703 "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001704 }
1705 } else {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001706 /* Configure AR9271 target WLAN */
1707 if (AR_SREV_9271(ah))
1708 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001709#ifdef __BIG_ENDIAN
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001710 else
1711 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001712#endif
1713 }
1714
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001715 if (ah->btcoex_hw.enabled)
Vasanthakumar Thiagarajan42cc41e2009-08-26 21:08:45 +05301716 ath9k_hw_btcoex_enable(ah);
1717
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001718 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001719}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001720EXPORT_SYMBOL(ath9k_hw_reset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001721
Sujithf1dc5602008-10-29 10:16:30 +05301722/************************/
1723/* Key Cache Management */
1724/************************/
1725
Sujithcbe61d82009-02-09 13:27:12 +05301726bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001727{
Sujithf1dc5602008-10-29 10:16:30 +05301728 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001729
Sujith2660b812009-02-09 13:27:26 +05301730 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001731 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1732 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001733 return false;
1734 }
1735
Sujithf1dc5602008-10-29 10:16:30 +05301736 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001737
Sujithf1dc5602008-10-29 10:16:30 +05301738 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
1739 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
1740 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
1741 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
1742 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
1743 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
1744 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
1745 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
1746
1747 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
1748 u16 micentry = entry + 64;
1749
1750 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
1751 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
1752 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
1753 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
1754
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001755 }
1756
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001757 return true;
1758}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001759EXPORT_SYMBOL(ath9k_hw_keyreset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001760
Sujithcbe61d82009-02-09 13:27:12 +05301761bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001762{
Sujithf1dc5602008-10-29 10:16:30 +05301763 u32 macHi, macLo;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001764
Sujith2660b812009-02-09 13:27:26 +05301765 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001766 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1767 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001768 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001769 }
1770
Sujithf1dc5602008-10-29 10:16:30 +05301771 if (mac != NULL) {
1772 macHi = (mac[5] << 8) | mac[4];
1773 macLo = (mac[3] << 24) |
1774 (mac[2] << 16) |
1775 (mac[1] << 8) |
1776 mac[0];
1777 macLo >>= 1;
1778 macLo |= (macHi & 1) << 31;
1779 macHi >>= 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001780 } else {
Sujithf1dc5602008-10-29 10:16:30 +05301781 macLo = macHi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001782 }
Sujithf1dc5602008-10-29 10:16:30 +05301783 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
1784 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001785
1786 return true;
1787}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001788EXPORT_SYMBOL(ath9k_hw_keysetmac);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001789
Sujithcbe61d82009-02-09 13:27:12 +05301790bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
Sujithf1dc5602008-10-29 10:16:30 +05301791 const struct ath9k_keyval *k,
Jouni Malinene0caf9e2009-03-02 18:15:53 +02001792 const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001793{
Sujith2660b812009-02-09 13:27:26 +05301794 const struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001795 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301796 u32 key0, key1, key2, key3, key4;
1797 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001798
Sujithf1dc5602008-10-29 10:16:30 +05301799 if (entry >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001800 ath_print(common, ATH_DBG_FATAL,
1801 "keycache entry %u out of range\n", entry);
Sujithf1dc5602008-10-29 10:16:30 +05301802 return false;
1803 }
1804
1805 switch (k->kv_type) {
1806 case ATH9K_CIPHER_AES_OCB:
1807 keyType = AR_KEYTABLE_TYPE_AES;
1808 break;
1809 case ATH9K_CIPHER_AES_CCM:
1810 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001811 ath_print(common, ATH_DBG_ANY,
1812 "AES-CCM not supported by mac rev 0x%x\n",
1813 ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001814 return false;
1815 }
Sujithf1dc5602008-10-29 10:16:30 +05301816 keyType = AR_KEYTABLE_TYPE_CCM;
1817 break;
1818 case ATH9K_CIPHER_TKIP:
1819 keyType = AR_KEYTABLE_TYPE_TKIP;
1820 if (ATH9K_IS_MIC_ENABLED(ah)
1821 && entry + 64 >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001822 ath_print(common, ATH_DBG_ANY,
1823 "entry %u inappropriate for TKIP\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001824 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001825 }
Sujithf1dc5602008-10-29 10:16:30 +05301826 break;
1827 case ATH9K_CIPHER_WEP:
Zhu Yie31a16d2009-05-21 21:47:03 +08001828 if (k->kv_len < WLAN_KEY_LEN_WEP40) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001829 ath_print(common, ATH_DBG_ANY,
1830 "WEP key length %u too small\n", k->kv_len);
Sujithf1dc5602008-10-29 10:16:30 +05301831 return false;
1832 }
Zhu Yie31a16d2009-05-21 21:47:03 +08001833 if (k->kv_len <= WLAN_KEY_LEN_WEP40)
Sujithf1dc5602008-10-29 10:16:30 +05301834 keyType = AR_KEYTABLE_TYPE_40;
Zhu Yie31a16d2009-05-21 21:47:03 +08001835 else if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05301836 keyType = AR_KEYTABLE_TYPE_104;
1837 else
1838 keyType = AR_KEYTABLE_TYPE_128;
1839 break;
1840 case ATH9K_CIPHER_CLR:
1841 keyType = AR_KEYTABLE_TYPE_CLR;
1842 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001843 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001844 ath_print(common, ATH_DBG_FATAL,
1845 "cipher %u not supported\n", k->kv_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001846 return false;
1847 }
Sujithf1dc5602008-10-29 10:16:30 +05301848
Jouni Malinene0caf9e2009-03-02 18:15:53 +02001849 key0 = get_unaligned_le32(k->kv_val + 0);
1850 key1 = get_unaligned_le16(k->kv_val + 4);
1851 key2 = get_unaligned_le32(k->kv_val + 6);
1852 key3 = get_unaligned_le16(k->kv_val + 10);
1853 key4 = get_unaligned_le32(k->kv_val + 12);
Zhu Yie31a16d2009-05-21 21:47:03 +08001854 if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05301855 key4 &= 0xff;
1856
Jouni Malinen672903b2009-03-02 15:06:31 +02001857 /*
1858 * Note: Key cache registers access special memory area that requires
1859 * two 32-bit writes to actually update the values in the internal
1860 * memory. Consequently, the exact order and pairs used here must be
1861 * maintained.
1862 */
1863
Sujithf1dc5602008-10-29 10:16:30 +05301864 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
1865 u16 micentry = entry + 64;
1866
Jouni Malinen672903b2009-03-02 15:06:31 +02001867 /*
1868 * Write inverted key[47:0] first to avoid Michael MIC errors
1869 * on frames that could be sent or received at the same time.
1870 * The correct key will be written in the end once everything
1871 * else is ready.
1872 */
Sujithf1dc5602008-10-29 10:16:30 +05301873 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
1874 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02001875
1876 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05301877 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
1878 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02001879
1880 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05301881 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
1882 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
Jouni Malinen672903b2009-03-02 15:06:31 +02001883
1884 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05301885 (void) ath9k_hw_keysetmac(ah, entry, mac);
1886
Sujith2660b812009-02-09 13:27:26 +05301887 if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) {
Jouni Malinen672903b2009-03-02 15:06:31 +02001888 /*
1889 * TKIP uses two key cache entries:
1890 * Michael MIC TX/RX keys in the same key cache entry
1891 * (idx = main index + 64):
1892 * key0 [31:0] = RX key [31:0]
1893 * key1 [15:0] = TX key [31:16]
1894 * key1 [31:16] = reserved
1895 * key2 [31:0] = RX key [63:32]
1896 * key3 [15:0] = TX key [15:0]
1897 * key3 [31:16] = reserved
1898 * key4 [31:0] = TX key [63:32]
1899 */
Sujithf1dc5602008-10-29 10:16:30 +05301900 u32 mic0, mic1, mic2, mic3, mic4;
1901
1902 mic0 = get_unaligned_le32(k->kv_mic + 0);
1903 mic2 = get_unaligned_le32(k->kv_mic + 4);
1904 mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
1905 mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
1906 mic4 = get_unaligned_le32(k->kv_txmic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02001907
1908 /* Write RX[31:0] and TX[31:16] */
Sujithf1dc5602008-10-29 10:16:30 +05301909 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
1910 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
Jouni Malinen672903b2009-03-02 15:06:31 +02001911
1912 /* Write RX[63:32] and TX[15:0] */
Sujithf1dc5602008-10-29 10:16:30 +05301913 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
1914 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
Jouni Malinen672903b2009-03-02 15:06:31 +02001915
1916 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05301917 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
1918 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
1919 AR_KEYTABLE_TYPE_CLR);
1920
1921 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02001922 /*
1923 * TKIP uses four key cache entries (two for group
1924 * keys):
1925 * Michael MIC TX/RX keys are in different key cache
1926 * entries (idx = main index + 64 for TX and
1927 * main index + 32 + 96 for RX):
1928 * key0 [31:0] = TX/RX MIC key [31:0]
1929 * key1 [31:0] = reserved
1930 * key2 [31:0] = TX/RX MIC key [63:32]
1931 * key3 [31:0] = reserved
1932 * key4 [31:0] = reserved
1933 *
1934 * Upper layer code will call this function separately
1935 * for TX and RX keys when these registers offsets are
1936 * used.
1937 */
Sujithf1dc5602008-10-29 10:16:30 +05301938 u32 mic0, mic2;
1939
1940 mic0 = get_unaligned_le32(k->kv_mic + 0);
1941 mic2 = get_unaligned_le32(k->kv_mic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02001942
1943 /* Write MIC key[31:0] */
Sujithf1dc5602008-10-29 10:16:30 +05301944 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
1945 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02001946
1947 /* Write MIC key[63:32] */
Sujithf1dc5602008-10-29 10:16:30 +05301948 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
1949 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02001950
1951 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05301952 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
1953 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
1954 AR_KEYTABLE_TYPE_CLR);
1955 }
Jouni Malinen672903b2009-03-02 15:06:31 +02001956
1957 /* MAC address registers are reserved for the MIC entry */
Sujithf1dc5602008-10-29 10:16:30 +05301958 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
1959 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02001960
1961 /*
1962 * Write the correct (un-inverted) key[47:0] last to enable
1963 * TKIP now that all other registers are set with correct
1964 * values.
1965 */
Sujithf1dc5602008-10-29 10:16:30 +05301966 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
1967 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
1968 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02001969 /* Write key[47:0] */
Sujithf1dc5602008-10-29 10:16:30 +05301970 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
1971 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02001972
1973 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05301974 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
1975 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02001976
1977 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05301978 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
1979 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
1980
Jouni Malinen672903b2009-03-02 15:06:31 +02001981 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05301982 (void) ath9k_hw_keysetmac(ah, entry, mac);
1983 }
1984
Sujithf1dc5602008-10-29 10:16:30 +05301985 return true;
1986}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001987EXPORT_SYMBOL(ath9k_hw_set_keycache_entry);
Sujithf1dc5602008-10-29 10:16:30 +05301988
Sujithcbe61d82009-02-09 13:27:12 +05301989bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry)
Sujithf1dc5602008-10-29 10:16:30 +05301990{
Sujith2660b812009-02-09 13:27:26 +05301991 if (entry < ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05301992 u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
1993 if (val & AR_KEYTABLE_VALID)
1994 return true;
1995 }
1996 return false;
1997}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001998EXPORT_SYMBOL(ath9k_hw_keyisvalid);
Sujithf1dc5602008-10-29 10:16:30 +05301999
2000/******************************/
2001/* Power Management (Chipset) */
2002/******************************/
2003
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04002004/*
2005 * Notify Power Mgt is disabled in self-generated frames.
2006 * If requested, force chip to sleep.
2007 */
Sujithcbe61d82009-02-09 13:27:12 +05302008static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302009{
2010 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2011 if (setChip) {
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04002012 /*
2013 * Clear the RTC force wake bit to allow the
2014 * mac to go to sleep.
2015 */
Sujithf1dc5602008-10-29 10:16:30 +05302016 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2017 AR_RTC_FORCE_WAKE_EN);
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04002018 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302019 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
2020
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04002021 /* Shutdown chip. Active low */
Sujith14b3af32010-03-17 14:25:18 +05302022 if (!AR_SREV_5416(ah) && !AR_SREV_9271(ah))
Sujith4921be82009-09-18 15:04:27 +05302023 REG_CLR_BIT(ah, (AR_RTC_RESET),
2024 AR_RTC_RESET_EN);
Sujithf1dc5602008-10-29 10:16:30 +05302025 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002026}
2027
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04002028/*
2029 * Notify Power Management is enabled in self-generating
2030 * frames. If request, set power mode of chip to
2031 * auto/normal. Duration in units of 128us (1/8 TU).
2032 */
Sujithcbe61d82009-02-09 13:27:12 +05302033static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002034{
Sujithf1dc5602008-10-29 10:16:30 +05302035 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2036 if (setChip) {
Sujith2660b812009-02-09 13:27:26 +05302037 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002038
Sujithf1dc5602008-10-29 10:16:30 +05302039 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04002040 /* Set WakeOnInterrupt bit; clear ForceWake bit */
Sujithf1dc5602008-10-29 10:16:30 +05302041 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2042 AR_RTC_FORCE_WAKE_ON_INT);
2043 } else {
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04002044 /*
2045 * Clear the RTC force wake bit to allow the
2046 * mac to go to sleep.
2047 */
Sujithf1dc5602008-10-29 10:16:30 +05302048 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2049 AR_RTC_FORCE_WAKE_EN);
2050 }
2051 }
2052}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002053
Sujithcbe61d82009-02-09 13:27:12 +05302054static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302055{
2056 u32 val;
2057 int i;
2058
2059 if (setChip) {
2060 if ((REG_READ(ah, AR_RTC_STATUS) &
2061 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2062 if (ath9k_hw_set_reset_reg(ah,
2063 ATH9K_RESET_POWER_ON) != true) {
2064 return false;
2065 }
Luis R. Rodrigueze0412282010-04-15 17:38:15 -04002066 if (!AR_SREV_9300_20_OR_LATER(ah))
2067 ath9k_hw_init_pll(ah, NULL);
Sujithf1dc5602008-10-29 10:16:30 +05302068 }
2069 if (AR_SREV_9100(ah))
2070 REG_SET_BIT(ah, AR_RTC_RESET,
2071 AR_RTC_RESET_EN);
2072
2073 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2074 AR_RTC_FORCE_WAKE_EN);
2075 udelay(50);
2076
2077 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2078 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2079 if (val == AR_RTC_STATUS_ON)
2080 break;
2081 udelay(50);
2082 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2083 AR_RTC_FORCE_WAKE_EN);
2084 }
2085 if (i == 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002086 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2087 "Failed to wakeup in %uus\n",
2088 POWER_UP_TIME / 20);
Sujithf1dc5602008-10-29 10:16:30 +05302089 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002090 }
2091 }
2092
Sujithf1dc5602008-10-29 10:16:30 +05302093 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2094
2095 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002096}
2097
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002098bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05302099{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002100 struct ath_common *common = ath9k_hw_common(ah);
Sujithcbe61d82009-02-09 13:27:12 +05302101 int status = true, setChip = true;
Sujithf1dc5602008-10-29 10:16:30 +05302102 static const char *modes[] = {
2103 "AWAKE",
2104 "FULL-SLEEP",
2105 "NETWORK SLEEP",
2106 "UNDEFINED"
2107 };
Sujithf1dc5602008-10-29 10:16:30 +05302108
Gabor Juhoscbdec972009-07-24 17:27:22 +02002109 if (ah->power_mode == mode)
2110 return status;
2111
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002112 ath_print(common, ATH_DBG_RESET, "%s -> %s\n",
2113 modes[ah->power_mode], modes[mode]);
Sujithf1dc5602008-10-29 10:16:30 +05302114
2115 switch (mode) {
2116 case ATH9K_PM_AWAKE:
2117 status = ath9k_hw_set_power_awake(ah, setChip);
2118 break;
2119 case ATH9K_PM_FULL_SLEEP:
2120 ath9k_set_power_sleep(ah, setChip);
Sujith2660b812009-02-09 13:27:26 +05302121 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05302122 break;
2123 case ATH9K_PM_NETWORK_SLEEP:
2124 ath9k_set_power_network_sleep(ah, setChip);
2125 break;
2126 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002127 ath_print(common, ATH_DBG_FATAL,
2128 "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05302129 return false;
2130 }
Sujith2660b812009-02-09 13:27:26 +05302131 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05302132
2133 return status;
2134}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002135EXPORT_SYMBOL(ath9k_hw_setpower);
Sujithf1dc5602008-10-29 10:16:30 +05302136
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002137/*
2138 * Helper for ASPM support.
2139 *
2140 * Disable PLL when in L0s as well as receiver clock when in L1.
2141 * This power saving option must be enabled through the SerDes.
2142 *
2143 * Programming the SerDes must go through the same 288 bit serial shift
2144 * register as the other analog registers. Hence the 9 writes.
2145 */
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04002146static void ar9002_hw_configpcipowersave(struct ath_hw *ah,
2147 int restore,
2148 int power_off)
Sujithf1dc5602008-10-29 10:16:30 +05302149{
Sujithf1dc5602008-10-29 10:16:30 +05302150 u8 i;
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302151 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05302152
Sujith2660b812009-02-09 13:27:26 +05302153 if (ah->is_pciexpress != true)
Sujithf1dc5602008-10-29 10:16:30 +05302154 return;
2155
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002156 /* Do not touch SerDes registers */
Sujith2660b812009-02-09 13:27:26 +05302157 if (ah->config.pcie_powersave_enable == 2)
Sujithf1dc5602008-10-29 10:16:30 +05302158 return;
2159
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002160 /* Nothing to do on restore for 11N */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302161 if (!restore) {
2162 if (AR_SREV_9280_20_OR_LATER(ah)) {
2163 /*
2164 * AR9280 2.0 or later chips use SerDes values from the
2165 * initvals.h initialized depending on chipset during
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04002166 * __ath9k_hw_init()
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302167 */
2168 for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
2169 REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
2170 INI_RA(&ah->iniPcieSerdes, i, 1));
2171 }
2172 } else if (AR_SREV_9280(ah) &&
2173 (ah->hw_version.macRev == AR_SREV_REVISION_9280_10)) {
2174 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
2175 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
Sujithf1dc5602008-10-29 10:16:30 +05302176
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302177 /* RX shut off when elecidle is asserted */
2178 REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
2179 REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
2180 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
2181
2182 /* Shut off CLKREQ active in L1 */
2183 if (ah->config.pcie_clock_req)
2184 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
2185 else
2186 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
2187
2188 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2189 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2190 REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
2191
2192 /* Load the new settings */
2193 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
2194
2195 } else {
2196 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
2197 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
2198
2199 /* RX shut off when elecidle is asserted */
2200 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
2201 REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
2202 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
2203
2204 /*
2205 * Ignore ah->ah_config.pcie_clock_req setting for
2206 * pre-AR9280 11n
2207 */
2208 REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
2209
2210 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2211 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2212 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
2213
2214 /* Load the new settings */
2215 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
Sujithf1dc5602008-10-29 10:16:30 +05302216 }
Sujithf1dc5602008-10-29 10:16:30 +05302217
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302218 udelay(1000);
Sujithf1dc5602008-10-29 10:16:30 +05302219
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302220 /* set bit 19 to allow forcing of pcie core into L1 state */
2221 REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
Sujithf1dc5602008-10-29 10:16:30 +05302222
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302223 /* Several PCIe massages to ensure proper behaviour */
2224 if (ah->config.pcie_waen) {
2225 val = ah->config.pcie_waen;
2226 if (!power_off)
2227 val &= (~AR_WA_D3_L1_DISABLE);
2228 } else {
2229 if (AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
2230 AR_SREV_9287(ah)) {
2231 val = AR9285_WA_DEFAULT;
2232 if (!power_off)
2233 val &= (~AR_WA_D3_L1_DISABLE);
2234 } else if (AR_SREV_9280(ah)) {
2235 /*
2236 * On AR9280 chips bit 22 of 0x4004 needs to be
2237 * set otherwise card may disappear.
2238 */
2239 val = AR9280_WA_DEFAULT;
2240 if (!power_off)
2241 val &= (~AR_WA_D3_L1_DISABLE);
2242 } else
2243 val = AR_WA_DEFAULT;
2244 }
Sujithf1dc5602008-10-29 10:16:30 +05302245
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302246 REG_WRITE(ah, AR_WA, val);
Sujithf1dc5602008-10-29 10:16:30 +05302247 }
2248
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302249 if (power_off) {
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002250 /*
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302251 * Set PCIe workaround bits
2252 * bit 14 in WA register (disable L1) should only
2253 * be set when device enters D3 and be cleared
2254 * when device comes back to D0.
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002255 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302256 if (ah->config.pcie_waen) {
2257 if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE)
2258 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
2259 } else {
2260 if (((AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
2261 AR_SREV_9287(ah)) &&
2262 (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)) ||
2263 (AR_SREV_9280(ah) &&
2264 (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE))) {
2265 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
2266 }
2267 }
Sujithf1dc5602008-10-29 10:16:30 +05302268 }
2269}
2270
2271/**********************/
2272/* Interrupt Handling */
2273/**********************/
2274
Sujithcbe61d82009-02-09 13:27:12 +05302275bool ath9k_hw_intrpend(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002276{
2277 u32 host_isr;
2278
2279 if (AR_SREV_9100(ah))
2280 return true;
2281
2282 host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
2283 if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
2284 return true;
2285
2286 host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
2287 if ((host_isr & AR_INTR_SYNC_DEFAULT)
2288 && (host_isr != AR_INTR_SPURIOUS))
2289 return true;
2290
2291 return false;
2292}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002293EXPORT_SYMBOL(ath9k_hw_intrpend);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002294
Sujithcbe61d82009-02-09 13:27:12 +05302295bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002296{
2297 u32 isr = 0;
2298 u32 mask2 = 0;
Sujith2660b812009-02-09 13:27:26 +05302299 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002300 u32 sync_cause = 0;
2301 bool fatal_int = false;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002302 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002303
2304 if (!AR_SREV_9100(ah)) {
2305 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
2306 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
2307 == AR_RTC_STATUS_ON) {
2308 isr = REG_READ(ah, AR_ISR);
2309 }
2310 }
2311
Sujithf1dc5602008-10-29 10:16:30 +05302312 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
2313 AR_INTR_SYNC_DEFAULT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002314
2315 *masked = 0;
2316
2317 if (!isr && !sync_cause)
2318 return false;
2319 } else {
2320 *masked = 0;
2321 isr = REG_READ(ah, AR_ISR);
2322 }
2323
2324 if (isr) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002325 if (isr & AR_ISR_BCNMISC) {
2326 u32 isr2;
2327 isr2 = REG_READ(ah, AR_ISR_S2);
2328 if (isr2 & AR_ISR_S2_TIM)
2329 mask2 |= ATH9K_INT_TIM;
2330 if (isr2 & AR_ISR_S2_DTIM)
2331 mask2 |= ATH9K_INT_DTIM;
2332 if (isr2 & AR_ISR_S2_DTIMSYNC)
2333 mask2 |= ATH9K_INT_DTIMSYNC;
2334 if (isr2 & (AR_ISR_S2_CABEND))
2335 mask2 |= ATH9K_INT_CABEND;
2336 if (isr2 & AR_ISR_S2_GTT)
2337 mask2 |= ATH9K_INT_GTT;
2338 if (isr2 & AR_ISR_S2_CST)
2339 mask2 |= ATH9K_INT_CST;
Sujith4af9cf42009-02-12 10:06:47 +05302340 if (isr2 & AR_ISR_S2_TSFOOR)
2341 mask2 |= ATH9K_INT_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002342 }
2343
2344 isr = REG_READ(ah, AR_ISR_RAC);
2345 if (isr == 0xffffffff) {
2346 *masked = 0;
2347 return false;
2348 }
2349
2350 *masked = isr & ATH9K_INT_COMMON;
2351
Sujith0ce024c2009-12-14 14:57:00 +05302352 if (ah->config.rx_intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002353 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
2354 *masked |= ATH9K_INT_RX;
2355 }
2356
2357 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
2358 *masked |= ATH9K_INT_RX;
2359 if (isr &
2360 (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
2361 AR_ISR_TXEOL)) {
2362 u32 s0_s, s1_s;
2363
2364 *masked |= ATH9K_INT_TX;
2365
2366 s0_s = REG_READ(ah, AR_ISR_S0_S);
Sujith2660b812009-02-09 13:27:26 +05302367 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
2368 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002369
2370 s1_s = REG_READ(ah, AR_ISR_S1_S);
Sujith2660b812009-02-09 13:27:26 +05302371 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
2372 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002373 }
2374
2375 if (isr & AR_ISR_RXORN) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002376 ath_print(common, ATH_DBG_INTERRUPT,
2377 "receive FIFO overrun interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002378 }
2379
2380 if (!AR_SREV_9100(ah)) {
Sujith60b67f52008-08-07 10:52:38 +05302381 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002382 u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
2383 if (isr5 & AR_ISR_S5_TIM_TIMER)
2384 *masked |= ATH9K_INT_TIM_TIMER;
2385 }
2386 }
2387
2388 *masked |= mask2;
2389 }
Sujithf1dc5602008-10-29 10:16:30 +05302390
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002391 if (AR_SREV_9100(ah))
2392 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302393
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302394 if (isr & AR_ISR_GENTMR) {
2395 u32 s5_s;
2396
2397 s5_s = REG_READ(ah, AR_ISR_S5_S);
2398 if (isr & AR_ISR_GENTMR) {
2399 ah->intr_gen_timer_trigger =
2400 MS(s5_s, AR_ISR_S5_GENTIMER_TRIG);
2401
2402 ah->intr_gen_timer_thresh =
2403 MS(s5_s, AR_ISR_S5_GENTIMER_THRESH);
2404
2405 if (ah->intr_gen_timer_trigger)
2406 *masked |= ATH9K_INT_GENTIMER;
2407
2408 }
2409 }
2410
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002411 if (sync_cause) {
2412 fatal_int =
2413 (sync_cause &
2414 (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
2415 ? true : false;
2416
2417 if (fatal_int) {
2418 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002419 ath_print(common, ATH_DBG_ANY,
2420 "received PCI FATAL interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002421 }
2422 if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002423 ath_print(common, ATH_DBG_ANY,
2424 "received PCI PERR interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002425 }
Steven Luoa89bff92009-04-12 02:57:54 -07002426 *masked |= ATH9K_INT_FATAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002427 }
2428 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002429 ath_print(common, ATH_DBG_INTERRUPT,
2430 "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002431 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
2432 REG_WRITE(ah, AR_RC, 0);
2433 *masked |= ATH9K_INT_FATAL;
2434 }
2435 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002436 ath_print(common, ATH_DBG_INTERRUPT,
2437 "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002438 }
2439
2440 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
2441 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
2442 }
Sujithf1dc5602008-10-29 10:16:30 +05302443
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002444 return true;
2445}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002446EXPORT_SYMBOL(ath9k_hw_getisr);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002447
Sujithcbe61d82009-02-09 13:27:12 +05302448enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002449{
Pavel Roskin152d5302010-03-31 18:05:37 -04002450 enum ath9k_int omask = ah->imask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002451 u32 mask, mask2;
Sujith2660b812009-02-09 13:27:26 +05302452 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002453 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002454
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002455 ath_print(common, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002456
2457 if (omask & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002458 ath_print(common, ATH_DBG_INTERRUPT, "disable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002459 REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
2460 (void) REG_READ(ah, AR_IER);
2461 if (!AR_SREV_9100(ah)) {
2462 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
2463 (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
2464
2465 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
2466 (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
2467 }
2468 }
2469
2470 mask = ints & ATH9K_INT_COMMON;
2471 mask2 = 0;
2472
2473 if (ints & ATH9K_INT_TX) {
Sujith2660b812009-02-09 13:27:26 +05302474 if (ah->txok_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002475 mask |= AR_IMR_TXOK;
Sujith2660b812009-02-09 13:27:26 +05302476 if (ah->txdesc_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002477 mask |= AR_IMR_TXDESC;
Sujith2660b812009-02-09 13:27:26 +05302478 if (ah->txerr_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002479 mask |= AR_IMR_TXERR;
Sujith2660b812009-02-09 13:27:26 +05302480 if (ah->txeol_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002481 mask |= AR_IMR_TXEOL;
2482 }
2483 if (ints & ATH9K_INT_RX) {
2484 mask |= AR_IMR_RXERR;
Sujith0ce024c2009-12-14 14:57:00 +05302485 if (ah->config.rx_intr_mitigation)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002486 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
2487 else
2488 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
Sujith60b67f52008-08-07 10:52:38 +05302489 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002490 mask |= AR_IMR_GENTMR;
2491 }
2492
2493 if (ints & (ATH9K_INT_BMISC)) {
2494 mask |= AR_IMR_BCNMISC;
2495 if (ints & ATH9K_INT_TIM)
2496 mask2 |= AR_IMR_S2_TIM;
2497 if (ints & ATH9K_INT_DTIM)
2498 mask2 |= AR_IMR_S2_DTIM;
2499 if (ints & ATH9K_INT_DTIMSYNC)
2500 mask2 |= AR_IMR_S2_DTIMSYNC;
2501 if (ints & ATH9K_INT_CABEND)
Sujith4af9cf42009-02-12 10:06:47 +05302502 mask2 |= AR_IMR_S2_CABEND;
2503 if (ints & ATH9K_INT_TSFOOR)
2504 mask2 |= AR_IMR_S2_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002505 }
2506
2507 if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
2508 mask |= AR_IMR_BCNMISC;
2509 if (ints & ATH9K_INT_GTT)
2510 mask2 |= AR_IMR_S2_GTT;
2511 if (ints & ATH9K_INT_CST)
2512 mask2 |= AR_IMR_S2_CST;
2513 }
2514
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002515 ath_print(common, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002516 REG_WRITE(ah, AR_IMR, mask);
Pavel Roskin74bad5c2010-02-23 18:15:27 -05002517 ah->imrs2_reg &= ~(AR_IMR_S2_TIM | AR_IMR_S2_DTIM | AR_IMR_S2_DTIMSYNC |
2518 AR_IMR_S2_CABEND | AR_IMR_S2_CABTO |
2519 AR_IMR_S2_TSFOOR | AR_IMR_S2_GTT | AR_IMR_S2_CST);
2520 ah->imrs2_reg |= mask2;
2521 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002522
Sujith60b67f52008-08-07 10:52:38 +05302523 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002524 if (ints & ATH9K_INT_TIM_TIMER)
2525 REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
2526 else
2527 REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
2528 }
2529
2530 if (ints & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002531 ath_print(common, ATH_DBG_INTERRUPT, "enable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002532 REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
2533 if (!AR_SREV_9100(ah)) {
2534 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
2535 AR_INTR_MAC_IRQ);
2536 REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
2537
2538
2539 REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
2540 AR_INTR_SYNC_DEFAULT);
2541 REG_WRITE(ah, AR_INTR_SYNC_MASK,
2542 AR_INTR_SYNC_DEFAULT);
2543 }
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002544 ath_print(common, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
2545 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002546 }
2547
2548 return omask;
2549}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002550EXPORT_SYMBOL(ath9k_hw_set_interrupts);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002551
Sujithf1dc5602008-10-29 10:16:30 +05302552/*******************/
2553/* Beacon Handling */
2554/*******************/
2555
Sujithcbe61d82009-02-09 13:27:12 +05302556void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002557{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002558 int flags = 0;
2559
Sujith2660b812009-02-09 13:27:26 +05302560 ah->beacon_interval = beacon_period;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002561
Sujith2660b812009-02-09 13:27:26 +05302562 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08002563 case NL80211_IFTYPE_STATION:
2564 case NL80211_IFTYPE_MONITOR:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002565 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
2566 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
2567 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
2568 flags |= AR_TBTT_TIMER_EN;
2569 break;
Colin McCabed97809d2008-12-01 13:38:55 -08002570 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04002571 case NL80211_IFTYPE_MESH_POINT:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002572 REG_SET_BIT(ah, AR_TXCFG,
2573 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
2574 REG_WRITE(ah, AR_NEXT_NDP_TIMER,
2575 TU_TO_USEC(next_beacon +
Sujith2660b812009-02-09 13:27:26 +05302576 (ah->atim_window ? ah->
2577 atim_window : 1)));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002578 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08002579 case NL80211_IFTYPE_AP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002580 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
2581 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
2582 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05302583 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302584 dma_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002585 REG_WRITE(ah, AR_NEXT_SWBA,
2586 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05302587 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302588 sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002589 flags |=
2590 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
2591 break;
Colin McCabed97809d2008-12-01 13:38:55 -08002592 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002593 ath_print(ath9k_hw_common(ah), ATH_DBG_BEACON,
2594 "%s: unsupported opmode: %d\n",
2595 __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08002596 return;
2597 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002598 }
2599
2600 REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
2601 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
2602 REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
2603 REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
2604
2605 beacon_period &= ~ATH9K_BEACON_ENA;
2606 if (beacon_period & ATH9K_BEACON_RESET_TSF) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002607 ath9k_hw_reset_tsf(ah);
2608 }
2609
2610 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
2611}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002612EXPORT_SYMBOL(ath9k_hw_beaconinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002613
Sujithcbe61d82009-02-09 13:27:12 +05302614void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05302615 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002616{
2617 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05302618 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002619 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002620
2621 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
2622
2623 REG_WRITE(ah, AR_BEACON_PERIOD,
2624 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
2625 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
2626 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
2627
2628 REG_RMW_FIELD(ah, AR_RSSI_THR,
2629 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
2630
2631 beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
2632
2633 if (bs->bs_sleepduration > beaconintval)
2634 beaconintval = bs->bs_sleepduration;
2635
2636 dtimperiod = bs->bs_dtimperiod;
2637 if (bs->bs_sleepduration > dtimperiod)
2638 dtimperiod = bs->bs_sleepduration;
2639
2640 if (beaconintval == dtimperiod)
2641 nextTbtt = bs->bs_nextdtim;
2642 else
2643 nextTbtt = bs->bs_nexttbtt;
2644
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002645 ath_print(common, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
2646 ath_print(common, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
2647 ath_print(common, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
2648 ath_print(common, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002649
2650 REG_WRITE(ah, AR_NEXT_DTIM,
2651 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
2652 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
2653
2654 REG_WRITE(ah, AR_SLEEP1,
2655 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
2656 | AR_SLEEP1_ASSUME_DTIM);
2657
Sujith60b67f52008-08-07 10:52:38 +05302658 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002659 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
2660 else
2661 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
2662
2663 REG_WRITE(ah, AR_SLEEP2,
2664 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
2665
2666 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
2667 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
2668
2669 REG_SET_BIT(ah, AR_TIMER_MODE,
2670 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
2671 AR_DTIM_TIMER_EN);
2672
Sujith4af9cf42009-02-12 10:06:47 +05302673 /* TSF Out of Range Threshold */
2674 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002675}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002676EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002677
Sujithf1dc5602008-10-29 10:16:30 +05302678/*******************/
2679/* HW Capabilities */
2680/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002681
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002682int ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002683{
Sujith2660b812009-02-09 13:27:26 +05302684 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002685 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002686 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002687 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002688
Sujithf1dc5602008-10-29 10:16:30 +05302689 u16 capField = 0, eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002690
Sujithf74df6f2009-02-09 13:27:24 +05302691 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002692 regulatory->current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05302693
Sujithf74df6f2009-02-09 13:27:24 +05302694 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
Sujithfec0de12009-02-12 10:06:43 +05302695 if (AR_SREV_9285_10_OR_LATER(ah))
2696 eeval |= AR9285_RDEXT_DEFAULT;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002697 regulatory->current_rd_ext = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05302698
Sujithf74df6f2009-02-09 13:27:24 +05302699 capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
Sujithf1dc5602008-10-29 10:16:30 +05302700
Sujith2660b812009-02-09 13:27:26 +05302701 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05302702 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002703 if (regulatory->current_rd == 0x64 ||
2704 regulatory->current_rd == 0x65)
2705 regulatory->current_rd += 5;
2706 else if (regulatory->current_rd == 0x41)
2707 regulatory->current_rd = 0x43;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002708 ath_print(common, ATH_DBG_REGULATORY,
2709 "regdomain mapped to 0x%x\n", regulatory->current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002710 }
Sujithdc2222a2008-08-14 13:26:55 +05302711
Sujithf74df6f2009-02-09 13:27:24 +05302712 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002713 if ((eeval & (AR5416_OPFLAGS_11G | AR5416_OPFLAGS_11A)) == 0) {
2714 ath_print(common, ATH_DBG_FATAL,
2715 "no band has been marked as supported in EEPROM.\n");
2716 return -EINVAL;
2717 }
2718
Sujithf1dc5602008-10-29 10:16:30 +05302719 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002720
Sujithf1dc5602008-10-29 10:16:30 +05302721 if (eeval & AR5416_OPFLAGS_11A) {
2722 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05302723 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05302724 if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
2725 set_bit(ATH9K_MODE_11NA_HT20,
2726 pCap->wireless_modes);
2727 if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
2728 set_bit(ATH9K_MODE_11NA_HT40PLUS,
2729 pCap->wireless_modes);
2730 set_bit(ATH9K_MODE_11NA_HT40MINUS,
2731 pCap->wireless_modes);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002732 }
2733 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002734 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002735
Sujithf1dc5602008-10-29 10:16:30 +05302736 if (eeval & AR5416_OPFLAGS_11G) {
Sujithf1dc5602008-10-29 10:16:30 +05302737 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05302738 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05302739 if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
2740 set_bit(ATH9K_MODE_11NG_HT20,
2741 pCap->wireless_modes);
2742 if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
2743 set_bit(ATH9K_MODE_11NG_HT40PLUS,
2744 pCap->wireless_modes);
2745 set_bit(ATH9K_MODE_11NG_HT40MINUS,
2746 pCap->wireless_modes);
2747 }
2748 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002749 }
Sujithf1dc5602008-10-29 10:16:30 +05302750
Sujithf74df6f2009-02-09 13:27:24 +05302751 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002752 /*
2753 * For AR9271 we will temporarilly uses the rx chainmax as read from
2754 * the EEPROM.
2755 */
Sujith8147f5d2009-02-20 15:13:23 +05302756 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002757 !(eeval & AR5416_OPFLAGS_11A) &&
2758 !(AR_SREV_9271(ah)))
2759 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
Sujith8147f5d2009-02-20 15:13:23 +05302760 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
2761 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002762 /* Use rx_chainmask from EEPROM. */
Sujith8147f5d2009-02-20 15:13:23 +05302763 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05302764
Sujithd535a422009-02-09 13:27:06 +05302765 if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0)))
Sujith2660b812009-02-09 13:27:26 +05302766 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05302767
2768 pCap->low_2ghz_chan = 2312;
2769 pCap->high_2ghz_chan = 2732;
2770
2771 pCap->low_5ghz_chan = 4920;
2772 pCap->high_5ghz_chan = 6100;
2773
2774 pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
2775 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
2776 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
2777
2778 pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
2779 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
2780 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
2781
Sujith2660b812009-02-09 13:27:26 +05302782 if (ah->config.ht_enable)
Sujithf1dc5602008-10-29 10:16:30 +05302783 pCap->hw_caps |= ATH9K_HW_CAP_HT;
2784 else
2785 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
2786
2787 pCap->hw_caps |= ATH9K_HW_CAP_GTT;
2788 pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
2789 pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
2790 pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
2791
2792 if (capField & AR_EEPROM_EEPCAP_MAXQCU)
2793 pCap->total_queues =
2794 MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
2795 else
2796 pCap->total_queues = ATH9K_NUM_TX_QUEUES;
2797
2798 if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
2799 pCap->keycache_size =
2800 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
2801 else
2802 pCap->keycache_size = AR_KEYTABLE_SIZE;
2803
2804 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -05002805
2806 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
2807 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD >> 1;
2808 else
2809 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
Sujithf1dc5602008-10-29 10:16:30 +05302810
Sujith5b5fa352010-03-17 14:25:15 +05302811 if (AR_SREV_9271(ah))
2812 pCap->num_gpio_pins = AR9271_NUM_GPIO;
2813 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302814 pCap->num_gpio_pins = AR9285_NUM_GPIO;
2815 else if (AR_SREV_9280_10_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302816 pCap->num_gpio_pins = AR928X_NUM_GPIO;
2817 else
2818 pCap->num_gpio_pins = AR_NUM_GPIO;
2819
Sujithf1dc5602008-10-29 10:16:30 +05302820 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
2821 pCap->hw_caps |= ATH9K_HW_CAP_CST;
2822 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
2823 } else {
2824 pCap->rts_aggr_limit = (8 * 1024);
2825 }
2826
2827 pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
2828
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05302829#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05302830 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
2831 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
2832 ah->rfkill_gpio =
2833 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
2834 ah->rfkill_polarity =
2835 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05302836
2837 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
2838 }
2839#endif
Vivek Natarajanbde748a2010-04-05 14:48:05 +05302840 if (AR_SREV_9271(ah))
2841 pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
2842 else
2843 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
Sujithf1dc5602008-10-29 10:16:30 +05302844
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302845 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302846 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
2847 else
2848 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
2849
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002850 if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) {
Sujithf1dc5602008-10-29 10:16:30 +05302851 pCap->reg_cap =
2852 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
2853 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
2854 AR_EEPROM_EEREGCAP_EN_KK_U2 |
2855 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
2856 } else {
2857 pCap->reg_cap =
2858 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
2859 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
2860 }
2861
Senthil Balasubramanianebb90cf2009-09-18 15:07:33 +05302862 /* Advertise midband for AR5416 with FCC midband set in eeprom */
2863 if (regulatory->current_rd_ext & (1 << REG_EXT_FCC_MIDBAND) &&
2864 AR_SREV_5416(ah))
2865 pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
Sujithf1dc5602008-10-29 10:16:30 +05302866
2867 pCap->num_antcfg_5ghz =
Sujithf74df6f2009-02-09 13:27:24 +05302868 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05302869 pCap->num_antcfg_2ghz =
Sujithf74df6f2009-02-09 13:27:24 +05302870 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05302871
Vasanthakumar Thiagarajanfe129462009-09-09 15:25:50 +05302872 if (AR_SREV_9280_10_OR_LATER(ah) &&
Luis R. Rodrigueza36cfbc2009-09-09 16:05:32 -07002873 ath9k_hw_btcoex_supported(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002874 btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO;
2875 btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO;
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05302876
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302877 if (AR_SREV_9285(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002878 btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
2879 btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302880 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002881 btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302882 }
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05302883 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002884 btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE;
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05302885 }
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002886
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002887 if (AR_SREV_9300_20_OR_LATER(ah)) {
Vasanthakumar Thiagarajan1adf02f2010-04-15 17:38:24 -04002888 pCap->hw_caps |= ATH9K_HW_CAP_EDMA;
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002889 pCap->rx_hp_qdepth = ATH9K_HW_RX_HP_QDEPTH;
2890 pCap->rx_lp_qdepth = ATH9K_HW_RX_LP_QDEPTH;
2891 pCap->rx_status_len = sizeof(struct ar9003_rxs);
2892 }
Vasanthakumar Thiagarajan1adf02f2010-04-15 17:38:24 -04002893
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002894 return 0;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002895}
2896
Sujithcbe61d82009-02-09 13:27:12 +05302897bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05302898 u32 capability, u32 *result)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002899{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002900 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302901 switch (type) {
2902 case ATH9K_CAP_CIPHER:
2903 switch (capability) {
2904 case ATH9K_CIPHER_AES_CCM:
2905 case ATH9K_CIPHER_AES_OCB:
2906 case ATH9K_CIPHER_TKIP:
2907 case ATH9K_CIPHER_WEP:
2908 case ATH9K_CIPHER_MIC:
2909 case ATH9K_CIPHER_CLR:
2910 return true;
2911 default:
2912 return false;
2913 }
2914 case ATH9K_CAP_TKIP_MIC:
2915 switch (capability) {
2916 case 0:
2917 return true;
2918 case 1:
Sujith2660b812009-02-09 13:27:26 +05302919 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05302920 AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
2921 false;
2922 }
2923 case ATH9K_CAP_TKIP_SPLIT:
Sujith2660b812009-02-09 13:27:26 +05302924 return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ?
Sujithf1dc5602008-10-29 10:16:30 +05302925 false : true;
Sujithf1dc5602008-10-29 10:16:30 +05302926 case ATH9K_CAP_MCAST_KEYSRCH:
2927 switch (capability) {
2928 case 0:
2929 return true;
2930 case 1:
2931 if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
2932 return false;
2933 } else {
Sujith2660b812009-02-09 13:27:26 +05302934 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05302935 AR_STA_ID1_MCAST_KSRCH) ? true :
2936 false;
2937 }
2938 }
2939 return false;
Sujithf1dc5602008-10-29 10:16:30 +05302940 case ATH9K_CAP_TXPOW:
2941 switch (capability) {
2942 case 0:
2943 return 0;
2944 case 1:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002945 *result = regulatory->power_limit;
Sujithf1dc5602008-10-29 10:16:30 +05302946 return 0;
2947 case 2:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002948 *result = regulatory->max_power_level;
Sujithf1dc5602008-10-29 10:16:30 +05302949 return 0;
2950 case 3:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002951 *result = regulatory->tp_scale;
Sujithf1dc5602008-10-29 10:16:30 +05302952 return 0;
2953 }
2954 return false;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05302955 case ATH9K_CAP_DS:
2956 return (AR_SREV_9280_20_OR_LATER(ah) &&
2957 (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1))
2958 ? false : true;
Sujithf1dc5602008-10-29 10:16:30 +05302959 default:
2960 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002961 }
Sujithf1dc5602008-10-29 10:16:30 +05302962}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002963EXPORT_SYMBOL(ath9k_hw_getcapability);
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002964
Sujithcbe61d82009-02-09 13:27:12 +05302965bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05302966 u32 capability, u32 setting, int *status)
2967{
Sujithf1dc5602008-10-29 10:16:30 +05302968 switch (type) {
2969 case ATH9K_CAP_TKIP_MIC:
2970 if (setting)
Sujith2660b812009-02-09 13:27:26 +05302971 ah->sta_id1_defaults |=
Sujithf1dc5602008-10-29 10:16:30 +05302972 AR_STA_ID1_CRPT_MIC_ENABLE;
2973 else
Sujith2660b812009-02-09 13:27:26 +05302974 ah->sta_id1_defaults &=
Sujithf1dc5602008-10-29 10:16:30 +05302975 ~AR_STA_ID1_CRPT_MIC_ENABLE;
2976 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302977 case ATH9K_CAP_MCAST_KEYSRCH:
2978 if (setting)
Sujith2660b812009-02-09 13:27:26 +05302979 ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05302980 else
Sujith2660b812009-02-09 13:27:26 +05302981 ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05302982 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302983 default:
2984 return false;
2985 }
2986}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002987EXPORT_SYMBOL(ath9k_hw_setcapability);
Sujithf1dc5602008-10-29 10:16:30 +05302988
2989/****************************/
2990/* GPIO / RFKILL / Antennae */
2991/****************************/
2992
Sujithcbe61d82009-02-09 13:27:12 +05302993static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05302994 u32 gpio, u32 type)
2995{
2996 int addr;
2997 u32 gpio_shift, tmp;
2998
2999 if (gpio > 11)
3000 addr = AR_GPIO_OUTPUT_MUX3;
3001 else if (gpio > 5)
3002 addr = AR_GPIO_OUTPUT_MUX2;
3003 else
3004 addr = AR_GPIO_OUTPUT_MUX1;
3005
3006 gpio_shift = (gpio % 6) * 5;
3007
3008 if (AR_SREV_9280_20_OR_LATER(ah)
3009 || (addr != AR_GPIO_OUTPUT_MUX1)) {
3010 REG_RMW(ah, addr, (type << gpio_shift),
3011 (0x1f << gpio_shift));
3012 } else {
3013 tmp = REG_READ(ah, addr);
3014 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
3015 tmp &= ~(0x1f << gpio_shift);
3016 tmp |= (type << gpio_shift);
3017 REG_WRITE(ah, addr, tmp);
3018 }
3019}
3020
Sujithcbe61d82009-02-09 13:27:12 +05303021void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303022{
3023 u32 gpio_shift;
3024
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07003025 BUG_ON(gpio >= ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05303026
3027 gpio_shift = gpio << 1;
3028
3029 REG_RMW(ah,
3030 AR_GPIO_OE_OUT,
3031 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
3032 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3033}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003034EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
Sujithf1dc5602008-10-29 10:16:30 +05303035
Sujithcbe61d82009-02-09 13:27:12 +05303036u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303037{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303038#define MS_REG_READ(x, y) \
3039 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
3040
Sujith2660b812009-02-09 13:27:26 +05303041 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05303042 return 0xffffffff;
3043
Felix Fietkau783dfca2010-04-15 17:38:11 -04003044 if (AR_SREV_9300_20_OR_LATER(ah))
3045 return MS_REG_READ(AR9300, gpio) != 0;
3046 else if (AR_SREV_9271(ah))
Sujith5b5fa352010-03-17 14:25:15 +05303047 return MS_REG_READ(AR9271, gpio) != 0;
3048 else if (AR_SREV_9287_10_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05303049 return MS_REG_READ(AR9287, gpio) != 0;
3050 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303051 return MS_REG_READ(AR9285, gpio) != 0;
3052 else if (AR_SREV_9280_10_OR_LATER(ah))
3053 return MS_REG_READ(AR928X, gpio) != 0;
3054 else
3055 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05303056}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003057EXPORT_SYMBOL(ath9k_hw_gpio_get);
Sujithf1dc5602008-10-29 10:16:30 +05303058
Sujithcbe61d82009-02-09 13:27:12 +05303059void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05303060 u32 ah_signal_type)
3061{
3062 u32 gpio_shift;
3063
3064 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
3065
3066 gpio_shift = 2 * gpio;
3067
3068 REG_RMW(ah,
3069 AR_GPIO_OE_OUT,
3070 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
3071 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3072}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003073EXPORT_SYMBOL(ath9k_hw_cfg_output);
Sujithf1dc5602008-10-29 10:16:30 +05303074
Sujithcbe61d82009-02-09 13:27:12 +05303075void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05303076{
Sujith5b5fa352010-03-17 14:25:15 +05303077 if (AR_SREV_9271(ah))
3078 val = ~val;
3079
Sujithf1dc5602008-10-29 10:16:30 +05303080 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
3081 AR_GPIO_BIT(gpio));
3082}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003083EXPORT_SYMBOL(ath9k_hw_set_gpio);
Sujithf1dc5602008-10-29 10:16:30 +05303084
Sujithcbe61d82009-02-09 13:27:12 +05303085u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303086{
3087 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
3088}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003089EXPORT_SYMBOL(ath9k_hw_getdefantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303090
Sujithcbe61d82009-02-09 13:27:12 +05303091void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05303092{
3093 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
3094}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003095EXPORT_SYMBOL(ath9k_hw_setantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303096
Sujithf1dc5602008-10-29 10:16:30 +05303097/*********************/
3098/* General Operation */
3099/*********************/
3100
Sujithcbe61d82009-02-09 13:27:12 +05303101u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303102{
3103 u32 bits = REG_READ(ah, AR_RX_FILTER);
3104 u32 phybits = REG_READ(ah, AR_PHY_ERR);
3105
3106 if (phybits & AR_PHY_ERR_RADAR)
3107 bits |= ATH9K_RX_FILTER_PHYRADAR;
3108 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
3109 bits |= ATH9K_RX_FILTER_PHYERR;
3110
3111 return bits;
3112}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003113EXPORT_SYMBOL(ath9k_hw_getrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303114
Sujithcbe61d82009-02-09 13:27:12 +05303115void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05303116{
3117 u32 phybits;
3118
Sujith7ea310b2009-09-03 12:08:43 +05303119 REG_WRITE(ah, AR_RX_FILTER, bits);
3120
Sujithf1dc5602008-10-29 10:16:30 +05303121 phybits = 0;
3122 if (bits & ATH9K_RX_FILTER_PHYRADAR)
3123 phybits |= AR_PHY_ERR_RADAR;
3124 if (bits & ATH9K_RX_FILTER_PHYERR)
3125 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
3126 REG_WRITE(ah, AR_PHY_ERR, phybits);
3127
3128 if (phybits)
3129 REG_WRITE(ah, AR_RXCFG,
3130 REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
3131 else
3132 REG_WRITE(ah, AR_RXCFG,
3133 REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
3134}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003135EXPORT_SYMBOL(ath9k_hw_setrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303136
Sujithcbe61d82009-02-09 13:27:12 +05303137bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303138{
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05303139 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
3140 return false;
3141
3142 ath9k_hw_init_pll(ah, NULL);
3143 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303144}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003145EXPORT_SYMBOL(ath9k_hw_phy_disable);
Sujithf1dc5602008-10-29 10:16:30 +05303146
Sujithcbe61d82009-02-09 13:27:12 +05303147bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303148{
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07003149 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05303150 return false;
3151
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05303152 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
3153 return false;
3154
3155 ath9k_hw_init_pll(ah, NULL);
3156 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303157}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003158EXPORT_SYMBOL(ath9k_hw_disable);
Sujithf1dc5602008-10-29 10:16:30 +05303159
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003160void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
Sujithf1dc5602008-10-29 10:16:30 +05303161{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003162 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujith2660b812009-02-09 13:27:26 +05303163 struct ath9k_channel *chan = ah->curchan;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08003164 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05303165
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003166 regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER);
Sujithf1dc5602008-10-29 10:16:30 +05303167
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003168 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003169 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003170 channel->max_antenna_gain * 2,
3171 channel->max_power * 2,
3172 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003173 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05303174}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003175EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
Sujithf1dc5602008-10-29 10:16:30 +05303176
Sujithcbe61d82009-02-09 13:27:12 +05303177void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac)
Sujithf1dc5602008-10-29 10:16:30 +05303178{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07003179 memcpy(ath9k_hw_common(ah)->macaddr, mac, ETH_ALEN);
Sujithf1dc5602008-10-29 10:16:30 +05303180}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003181EXPORT_SYMBOL(ath9k_hw_setmac);
Sujithf1dc5602008-10-29 10:16:30 +05303182
Sujithcbe61d82009-02-09 13:27:12 +05303183void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303184{
Sujith2660b812009-02-09 13:27:26 +05303185 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05303186}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003187EXPORT_SYMBOL(ath9k_hw_setopmode);
Sujithf1dc5602008-10-29 10:16:30 +05303188
Sujithcbe61d82009-02-09 13:27:12 +05303189void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05303190{
3191 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
3192 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
3193}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003194EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303195
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07003196void ath9k_hw_write_associd(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303197{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07003198 struct ath_common *common = ath9k_hw_common(ah);
3199
3200 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
3201 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
3202 ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05303203}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003204EXPORT_SYMBOL(ath9k_hw_write_associd);
Sujithf1dc5602008-10-29 10:16:30 +05303205
Sujithcbe61d82009-02-09 13:27:12 +05303206u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303207{
3208 u64 tsf;
3209
3210 tsf = REG_READ(ah, AR_TSF_U32);
3211 tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
3212
3213 return tsf;
3214}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003215EXPORT_SYMBOL(ath9k_hw_gettsf64);
Sujithf1dc5602008-10-29 10:16:30 +05303216
Sujithcbe61d82009-02-09 13:27:12 +05303217void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003218{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003219 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01003220 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003221}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003222EXPORT_SYMBOL(ath9k_hw_settsf64);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003223
Sujithcbe61d82009-02-09 13:27:12 +05303224void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303225{
Gabor Juhosf9b604f2009-06-21 00:02:15 +02003226 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
3227 AH_TSF_WRITE_TIMEOUT))
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003228 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
3229 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
Gabor Juhosf9b604f2009-06-21 00:02:15 +02003230
Sujithf1dc5602008-10-29 10:16:30 +05303231 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003232}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003233EXPORT_SYMBOL(ath9k_hw_reset_tsf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003234
Sujith54e4cec2009-08-07 09:45:09 +05303235void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003236{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003237 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303238 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003239 else
Sujith2660b812009-02-09 13:27:26 +05303240 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003241}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003242EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003243
Luis R. Rodriguez30cbd422009-11-03 16:10:46 -08003244/*
3245 * Extend 15-bit time stamp from rx descriptor to
3246 * a full 64-bit TSF using the current h/w TSF.
3247*/
3248u64 ath9k_hw_extend_tsf(struct ath_hw *ah, u32 rstamp)
3249{
3250 u64 tsf;
3251
3252 tsf = ath9k_hw_gettsf64(ah);
3253 if ((tsf & 0x7fff) < rstamp)
3254 tsf -= 0x8000;
3255 return (tsf & ~0x7fff) | rstamp;
3256}
3257EXPORT_SYMBOL(ath9k_hw_extend_tsf);
3258
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003259void ath9k_hw_set11nmac2040(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003260{
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003261 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithf1dc5602008-10-29 10:16:30 +05303262 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003263
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003264 if (conf_is_ht40(conf) && !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05303265 macmode = AR_2040_JOINED_RX_CLEAR;
3266 else
3267 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003268
Sujithf1dc5602008-10-29 10:16:30 +05303269 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003270}
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303271
3272/* HW Generic timers configuration */
3273
3274static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
3275{
3276 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3277 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3278 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3279 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3280 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3281 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3282 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3283 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3284 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
3285 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
3286 AR_NDP2_TIMER_MODE, 0x0002},
3287 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
3288 AR_NDP2_TIMER_MODE, 0x0004},
3289 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
3290 AR_NDP2_TIMER_MODE, 0x0008},
3291 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
3292 AR_NDP2_TIMER_MODE, 0x0010},
3293 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
3294 AR_NDP2_TIMER_MODE, 0x0020},
3295 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
3296 AR_NDP2_TIMER_MODE, 0x0040},
3297 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
3298 AR_NDP2_TIMER_MODE, 0x0080}
3299};
3300
3301/* HW generic timer primitives */
3302
3303/* compute and clear index of rightmost 1 */
3304static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
3305{
3306 u32 b;
3307
3308 b = *mask;
3309 b &= (0-b);
3310 *mask &= ~b;
3311 b *= debruijn32;
3312 b >>= 27;
3313
3314 return timer_table->gen_timer_index[b];
3315}
3316
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05303317u32 ath9k_hw_gettsf32(struct ath_hw *ah)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303318{
3319 return REG_READ(ah, AR_TSF_L32);
3320}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003321EXPORT_SYMBOL(ath9k_hw_gettsf32);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303322
3323struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
3324 void (*trigger)(void *),
3325 void (*overflow)(void *),
3326 void *arg,
3327 u8 timer_index)
3328{
3329 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3330 struct ath_gen_timer *timer;
3331
3332 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
3333
3334 if (timer == NULL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003335 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
3336 "Failed to allocate memory"
3337 "for hw timer[%d]\n", timer_index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303338 return NULL;
3339 }
3340
3341 /* allocate a hardware generic timer slot */
3342 timer_table->timers[timer_index] = timer;
3343 timer->index = timer_index;
3344 timer->trigger = trigger;
3345 timer->overflow = overflow;
3346 timer->arg = arg;
3347
3348 return timer;
3349}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003350EXPORT_SYMBOL(ath_gen_timer_alloc);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303351
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07003352void ath9k_hw_gen_timer_start(struct ath_hw *ah,
3353 struct ath_gen_timer *timer,
3354 u32 timer_next,
3355 u32 timer_period)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303356{
3357 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3358 u32 tsf;
3359
3360 BUG_ON(!timer_period);
3361
3362 set_bit(timer->index, &timer_table->timer_mask.timer_bits);
3363
3364 tsf = ath9k_hw_gettsf32(ah);
3365
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003366 ath_print(ath9k_hw_common(ah), ATH_DBG_HWTIMER,
3367 "curent tsf %x period %x"
3368 "timer_next %x\n", tsf, timer_period, timer_next);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303369
3370 /*
3371 * Pull timer_next forward if the current TSF already passed it
3372 * because of software latency
3373 */
3374 if (timer_next < tsf)
3375 timer_next = tsf + timer_period;
3376
3377 /*
3378 * Program generic timer registers
3379 */
3380 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
3381 timer_next);
3382 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
3383 timer_period);
3384 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
3385 gen_tmr_configuration[timer->index].mode_mask);
3386
3387 /* Enable both trigger and thresh interrupt masks */
3388 REG_SET_BIT(ah, AR_IMR_S5,
3389 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
3390 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303391}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003392EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303393
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07003394void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303395{
3396 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3397
3398 if ((timer->index < AR_FIRST_NDP_TIMER) ||
3399 (timer->index >= ATH_MAX_GEN_TIMER)) {
3400 return;
3401 }
3402
3403 /* Clear generic timer enable bits. */
3404 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
3405 gen_tmr_configuration[timer->index].mode_mask);
3406
3407 /* Disable both trigger and thresh interrupt masks */
3408 REG_CLR_BIT(ah, AR_IMR_S5,
3409 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
3410 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
3411
3412 clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303413}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003414EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303415
3416void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
3417{
3418 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3419
3420 /* free the hardware generic timer slot */
3421 timer_table->timers[timer->index] = NULL;
3422 kfree(timer);
3423}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003424EXPORT_SYMBOL(ath_gen_timer_free);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303425
3426/*
3427 * Generic Timer Interrupts handling
3428 */
3429void ath_gen_timer_isr(struct ath_hw *ah)
3430{
3431 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3432 struct ath_gen_timer *timer;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003433 struct ath_common *common = ath9k_hw_common(ah);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303434 u32 trigger_mask, thresh_mask, index;
3435
3436 /* get hardware generic timer interrupt status */
3437 trigger_mask = ah->intr_gen_timer_trigger;
3438 thresh_mask = ah->intr_gen_timer_thresh;
3439 trigger_mask &= timer_table->timer_mask.val;
3440 thresh_mask &= timer_table->timer_mask.val;
3441
3442 trigger_mask &= ~thresh_mask;
3443
3444 while (thresh_mask) {
3445 index = rightmost_index(timer_table, &thresh_mask);
3446 timer = timer_table->timers[index];
3447 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003448 ath_print(common, ATH_DBG_HWTIMER,
3449 "TSF overflow for Gen timer %d\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303450 timer->overflow(timer->arg);
3451 }
3452
3453 while (trigger_mask) {
3454 index = rightmost_index(timer_table, &trigger_mask);
3455 timer = timer_table->timers[index];
3456 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003457 ath_print(common, ATH_DBG_HWTIMER,
3458 "Gen timer[%d] trigger\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303459 timer->trigger(timer->arg);
3460 }
3461}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003462EXPORT_SYMBOL(ath_gen_timer_isr);
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003463
Sujith05020d22010-03-17 14:25:23 +05303464/********/
3465/* HTC */
3466/********/
3467
3468void ath9k_hw_htc_resetinit(struct ath_hw *ah)
3469{
3470 ah->htc_reset_init = true;
3471}
3472EXPORT_SYMBOL(ath9k_hw_htc_resetinit);
3473
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003474static struct {
3475 u32 version;
3476 const char * name;
3477} ath_mac_bb_names[] = {
3478 /* Devices with external radios */
3479 { AR_SREV_VERSION_5416_PCI, "5416" },
3480 { AR_SREV_VERSION_5416_PCIE, "5418" },
3481 { AR_SREV_VERSION_9100, "9100" },
3482 { AR_SREV_VERSION_9160, "9160" },
3483 /* Single-chip solutions */
3484 { AR_SREV_VERSION_9280, "9280" },
3485 { AR_SREV_VERSION_9285, "9285" },
Luis R. Rodriguez11158472009-10-27 12:59:35 -04003486 { AR_SREV_VERSION_9287, "9287" },
3487 { AR_SREV_VERSION_9271, "9271" },
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003488};
3489
3490/* For devices with external radios */
3491static struct {
3492 u16 version;
3493 const char * name;
3494} ath_rf_names[] = {
3495 { 0, "5133" },
3496 { AR_RAD5133_SREV_MAJOR, "5133" },
3497 { AR_RAD5122_SREV_MAJOR, "5122" },
3498 { AR_RAD2133_SREV_MAJOR, "2133" },
3499 { AR_RAD2122_SREV_MAJOR, "2122" }
3500};
3501
3502/*
3503 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
3504 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003505static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003506{
3507 int i;
3508
3509 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
3510 if (ath_mac_bb_names[i].version == mac_bb_version) {
3511 return ath_mac_bb_names[i].name;
3512 }
3513 }
3514
3515 return "????";
3516}
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003517
3518/*
3519 * Return the RF name. "????" is returned if the RF is unknown.
3520 * Used for devices with external radios.
3521 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003522static const char *ath9k_hw_rf_name(u16 rf_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003523{
3524 int i;
3525
3526 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
3527 if (ath_rf_names[i].version == rf_version) {
3528 return ath_rf_names[i].name;
3529 }
3530 }
3531
3532 return "????";
3533}
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003534
3535void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
3536{
3537 int used;
3538
3539 /* chipsets >= AR9280 are single-chip */
3540 if (AR_SREV_9280_10_OR_LATER(ah)) {
3541 used = snprintf(hw_name, len,
3542 "Atheros AR%s Rev:%x",
3543 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3544 ah->hw_version.macRev);
3545 }
3546 else {
3547 used = snprintf(hw_name, len,
3548 "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
3549 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3550 ah->hw_version.macRev,
3551 ath9k_hw_rf_name((ah->hw_version.analog5GhzRev &
3552 AR_RADIO_SREV_MAJOR)),
3553 ah->hw_version.phyRev);
3554 }
3555
3556 hw_name[used] = '\0';
3557}
3558EXPORT_SYMBOL(ath9k_hw_name);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04003559
3560/* Sets up the AR5008/AR9001/AR9002 hardware familiy callbacks */
3561static void ar9002_hw_attach_ops(struct ath_hw *ah)
3562{
3563 struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
3564 struct ath_hw_ops *ops = ath9k_hw_ops(ah);
3565
3566 priv_ops->init_cal_settings = ar9002_hw_init_cal_settings;
3567 priv_ops->init_mode_regs = ar9002_hw_init_mode_regs;
3568 priv_ops->macversion_supported = ar9002_hw_macversion_supported;
3569
3570 ops->config_pci_powersave = ar9002_hw_configpcipowersave;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04003571
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04003572 ar5008_hw_attach_phy_ops(ah);
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04003573 if (AR_SREV_9280_10_OR_LATER(ah))
3574 ar9002_hw_attach_phy_ops(ah);
Vasanthakumar Thiagarajanae3bb6d2010-04-15 17:38:27 -04003575
3576 ar9002_hw_attach_mac_ops(ah);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04003577}
3578
3579/* Sets up the AR9003 hardware familiy callbacks */
3580static void ar9003_hw_attach_ops(struct ath_hw *ah)
3581{
Luis R. Rodriguez61accab2010-04-15 17:38:21 -04003582 struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
3583
3584 priv_ops->macversion_supported = ar9003_hw_macversion_supported;
3585
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04003586 ar9003_hw_attach_phy_ops(ah);
Vasanthakumar Thiagarajanae3bb6d2010-04-15 17:38:27 -04003587
3588 ar9003_hw_attach_mac_ops(ah);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04003589}