blob: e6d4c4c8a3df146081ae5276fa95e186dd74e811 [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. Rodriguez13ce3e92010-04-15 17:38:37 -040026#include "ar9003_initvals.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070027
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080028#define ATH9K_CLOCK_RATE_CCK 22
29#define ATH9K_CLOCK_RATE_5GHZ_OFDM 40
30#define ATH9K_CLOCK_RATE_2GHZ_OFDM 44
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070031
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -040032static void ar9002_hw_attach_ops(struct ath_hw *ah);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -040033static void ar9003_hw_attach_ops(struct ath_hw *ah);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -040034
Sujithcbe61d82009-02-09 13:27:12 +053035static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070036
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040037MODULE_AUTHOR("Atheros Communications");
38MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
39MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
40MODULE_LICENSE("Dual BSD/GPL");
41
42static int __init ath9k_init(void)
43{
44 return 0;
45}
46module_init(ath9k_init);
47
48static void __exit ath9k_exit(void)
49{
50 return;
51}
52module_exit(ath9k_exit);
53
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -040054/* Private hardware callbacks */
55
56static void ath9k_hw_init_cal_settings(struct ath_hw *ah)
57{
58 ath9k_hw_private_ops(ah)->init_cal_settings(ah);
59}
60
61static void ath9k_hw_init_mode_regs(struct ath_hw *ah)
62{
63 ath9k_hw_private_ops(ah)->init_mode_regs(ah);
64}
65
66static bool ath9k_hw_macversion_supported(struct ath_hw *ah)
67{
68 struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
69
70 return priv_ops->macversion_supported(ah->hw_version.macVersion);
71}
72
Luis R. Rodriguez64773962010-04-15 17:38:17 -040073static u32 ath9k_hw_compute_pll_control(struct ath_hw *ah,
74 struct ath9k_channel *chan)
75{
76 return ath9k_hw_private_ops(ah)->compute_pll_control(ah, chan);
77}
78
Sujithf1dc5602008-10-29 10:16:30 +053079/********************/
80/* Helper Functions */
81/********************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070082
Sujithcbe61d82009-02-09 13:27:12 +053083static u32 ath9k_hw_mac_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053084{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070085 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053086
Sujith2660b812009-02-09 13:27:26 +053087 if (!ah->curchan) /* should really check for CCK instead */
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080088 return usecs *ATH9K_CLOCK_RATE_CCK;
89 if (conf->channel->band == IEEE80211_BAND_2GHZ)
90 return usecs *ATH9K_CLOCK_RATE_2GHZ_OFDM;
91 return usecs *ATH9K_CLOCK_RATE_5GHZ_OFDM;
Sujithf1dc5602008-10-29 10:16:30 +053092}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070093
Sujithcbe61d82009-02-09 13:27:12 +053094static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053095{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070096 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053097
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080098 if (conf_is_ht40(conf))
Sujithf1dc5602008-10-29 10:16:30 +053099 return ath9k_hw_mac_clks(ah, usecs) * 2;
100 else
101 return ath9k_hw_mac_clks(ah, usecs);
102}
103
Sujith0caa7b12009-02-16 13:23:20 +0530104bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700105{
106 int i;
107
Sujith0caa7b12009-02-16 13:23:20 +0530108 BUG_ON(timeout < AH_TIME_QUANTUM);
109
110 for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700111 if ((REG_READ(ah, reg) & mask) == val)
112 return true;
113
114 udelay(AH_TIME_QUANTUM);
115 }
Sujith04bd4632008-11-28 22:18:05 +0530116
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700117 ath_print(ath9k_hw_common(ah), ATH_DBG_ANY,
118 "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
119 timeout, reg, REG_READ(ah, reg), mask, val);
Sujithf1dc5602008-10-29 10:16:30 +0530120
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700121 return false;
122}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400123EXPORT_SYMBOL(ath9k_hw_wait);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700124
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700125u32 ath9k_hw_reverse_bits(u32 val, u32 n)
126{
127 u32 retval;
128 int i;
129
130 for (i = 0, retval = 0; i < n; i++) {
131 retval = (retval << 1) | (val & 1);
132 val >>= 1;
133 }
134 return retval;
135}
136
Sujithcbe61d82009-02-09 13:27:12 +0530137bool ath9k_get_channel_edges(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530138 u16 flags, u16 *low,
139 u16 *high)
140{
Sujith2660b812009-02-09 13:27:26 +0530141 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530142
143 if (flags & CHANNEL_5GHZ) {
144 *low = pCap->low_5ghz_chan;
145 *high = pCap->high_5ghz_chan;
146 return true;
147 }
148 if ((flags & CHANNEL_2GHZ)) {
149 *low = pCap->low_2ghz_chan;
150 *high = pCap->high_2ghz_chan;
151 return true;
152 }
153 return false;
154}
155
Sujithcbe61d82009-02-09 13:27:12 +0530156u16 ath9k_hw_computetxtime(struct ath_hw *ah,
Felix Fietkau545750d2009-11-23 22:21:01 +0100157 u8 phy, int kbps,
Sujithf1dc5602008-10-29 10:16:30 +0530158 u32 frameLen, u16 rateix,
159 bool shortPreamble)
160{
161 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
Sujithf1dc5602008-10-29 10:16:30 +0530162
163 if (kbps == 0)
164 return 0;
165
Felix Fietkau545750d2009-11-23 22:21:01 +0100166 switch (phy) {
Sujith46d14a52008-11-18 09:08:13 +0530167 case WLAN_RC_PHY_CCK:
Sujithf1dc5602008-10-29 10:16:30 +0530168 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
Felix Fietkau545750d2009-11-23 22:21:01 +0100169 if (shortPreamble)
Sujithf1dc5602008-10-29 10:16:30 +0530170 phyTime >>= 1;
171 numBits = frameLen << 3;
172 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
173 break;
Sujith46d14a52008-11-18 09:08:13 +0530174 case WLAN_RC_PHY_OFDM:
Sujith2660b812009-02-09 13:27:26 +0530175 if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530176 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
177 numBits = OFDM_PLCP_BITS + (frameLen << 3);
178 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
179 txTime = OFDM_SIFS_TIME_QUARTER
180 + OFDM_PREAMBLE_TIME_QUARTER
181 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
Sujith2660b812009-02-09 13:27:26 +0530182 } else if (ah->curchan &&
183 IS_CHAN_HALF_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530184 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
185 numBits = OFDM_PLCP_BITS + (frameLen << 3);
186 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
187 txTime = OFDM_SIFS_TIME_HALF +
188 OFDM_PREAMBLE_TIME_HALF
189 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
190 } else {
191 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
192 numBits = OFDM_PLCP_BITS + (frameLen << 3);
193 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
194 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
195 + (numSymbols * OFDM_SYMBOL_TIME);
196 }
197 break;
198 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700199 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
Felix Fietkau545750d2009-11-23 22:21:01 +0100200 "Unknown phy %u (rate ix %u)\n", phy, rateix);
Sujithf1dc5602008-10-29 10:16:30 +0530201 txTime = 0;
202 break;
203 }
204
205 return txTime;
206}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400207EXPORT_SYMBOL(ath9k_hw_computetxtime);
Sujithf1dc5602008-10-29 10:16:30 +0530208
Sujithcbe61d82009-02-09 13:27:12 +0530209void ath9k_hw_get_channel_centers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530210 struct ath9k_channel *chan,
211 struct chan_centers *centers)
212{
213 int8_t extoff;
Sujithf1dc5602008-10-29 10:16:30 +0530214
215 if (!IS_CHAN_HT40(chan)) {
216 centers->ctl_center = centers->ext_center =
217 centers->synth_center = chan->channel;
218 return;
219 }
220
221 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
222 (chan->chanmode == CHANNEL_G_HT40PLUS)) {
223 centers->synth_center =
224 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
225 extoff = 1;
226 } else {
227 centers->synth_center =
228 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
229 extoff = -1;
230 }
231
232 centers->ctl_center =
233 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700234 /* 25 MHz spacing is supported by hw but not on upper layers */
Sujithf1dc5602008-10-29 10:16:30 +0530235 centers->ext_center =
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700236 centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT);
Sujithf1dc5602008-10-29 10:16:30 +0530237}
238
239/******************/
240/* Chip Revisions */
241/******************/
242
Sujithcbe61d82009-02-09 13:27:12 +0530243static void ath9k_hw_read_revisions(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530244{
245 u32 val;
246
247 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
248
249 if (val == 0xFF) {
250 val = REG_READ(ah, AR_SREV);
Sujithd535a422009-02-09 13:27:06 +0530251 ah->hw_version.macVersion =
252 (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
253 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
Sujith2660b812009-02-09 13:27:26 +0530254 ah->is_pciexpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
Sujithf1dc5602008-10-29 10:16:30 +0530255 } else {
256 if (!AR_SREV_9100(ah))
Sujithd535a422009-02-09 13:27:06 +0530257 ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
Sujithf1dc5602008-10-29 10:16:30 +0530258
Sujithd535a422009-02-09 13:27:06 +0530259 ah->hw_version.macRev = val & AR_SREV_REVISION;
Sujithf1dc5602008-10-29 10:16:30 +0530260
Sujithd535a422009-02-09 13:27:06 +0530261 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
Sujith2660b812009-02-09 13:27:26 +0530262 ah->is_pciexpress = true;
Sujithf1dc5602008-10-29 10:16:30 +0530263 }
264}
265
Sujithcbe61d82009-02-09 13:27:12 +0530266static int ath9k_hw_get_radiorev(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530267{
268 u32 val;
269 int i;
270
271 REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
272
273 for (i = 0; i < 8; i++)
274 REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
275 val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
276 val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
277
278 return ath9k_hw_reverse_bits(val, 8);
279}
280
281/************************************/
282/* HW Attach, Detach, Init Routines */
283/************************************/
284
Sujithcbe61d82009-02-09 13:27:12 +0530285static void ath9k_hw_disablepcie(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530286{
Sujithfeed0292009-01-29 11:37:35 +0530287 if (AR_SREV_9100(ah))
Sujithf1dc5602008-10-29 10:16:30 +0530288 return;
289
290 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
291 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
292 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
293 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
294 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
295 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
296 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
297 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
298 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
299
300 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
301}
302
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400303/* This should work for all families including legacy */
Sujithcbe61d82009-02-09 13:27:12 +0530304static bool ath9k_hw_chip_test(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530305{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700306 struct ath_common *common = ath9k_hw_common(ah);
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400307 u32 regAddr[2] = { AR_STA_ID0 };
Sujithf1dc5602008-10-29 10:16:30 +0530308 u32 regHold[2];
309 u32 patternData[4] = { 0x55555555,
310 0xaaaaaaaa,
311 0x66666666,
312 0x99999999 };
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400313 int i, j, loop_max;
Sujithf1dc5602008-10-29 10:16:30 +0530314
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400315 if (!AR_SREV_9300_20_OR_LATER(ah)) {
316 loop_max = 2;
317 regAddr[1] = AR_PHY_BASE + (8 << 2);
318 } else
319 loop_max = 1;
320
321 for (i = 0; i < loop_max; i++) {
Sujithf1dc5602008-10-29 10:16:30 +0530322 u32 addr = regAddr[i];
323 u32 wrData, rdData;
324
325 regHold[i] = REG_READ(ah, addr);
326 for (j = 0; j < 0x100; j++) {
327 wrData = (j << 16) | j;
328 REG_WRITE(ah, addr, wrData);
329 rdData = REG_READ(ah, addr);
330 if (rdData != wrData) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700331 ath_print(common, ATH_DBG_FATAL,
332 "address test failed "
333 "addr: 0x%08x - wr:0x%08x != "
334 "rd:0x%08x\n",
335 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530336 return false;
337 }
338 }
339 for (j = 0; j < 4; j++) {
340 wrData = patternData[j];
341 REG_WRITE(ah, addr, wrData);
342 rdData = REG_READ(ah, addr);
343 if (wrData != rdData) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700344 ath_print(common, ATH_DBG_FATAL,
345 "address test failed "
346 "addr: 0x%08x - wr:0x%08x != "
347 "rd:0x%08x\n",
348 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530349 return false;
350 }
351 }
352 REG_WRITE(ah, regAddr[i], regHold[i]);
353 }
354 udelay(100);
Sujithcbe61d82009-02-09 13:27:12 +0530355
Sujithf1dc5602008-10-29 10:16:30 +0530356 return true;
357}
358
Luis R. Rodriguezb8b0f372009-08-03 12:24:43 -0700359static void ath9k_hw_init_config(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700360{
361 int i;
362
Sujith2660b812009-02-09 13:27:26 +0530363 ah->config.dma_beacon_response_time = 2;
364 ah->config.sw_beacon_response_time = 10;
365 ah->config.additional_swba_backoff = 0;
366 ah->config.ack_6mb = 0x0;
367 ah->config.cwm_ignore_extcca = 0;
368 ah->config.pcie_powersave_enable = 0;
Sujith2660b812009-02-09 13:27:26 +0530369 ah->config.pcie_clock_req = 0;
Sujith2660b812009-02-09 13:27:26 +0530370 ah->config.pcie_waen = 0;
371 ah->config.analog_shiftreg = 1;
Sujith2660b812009-02-09 13:27:26 +0530372 ah->config.ofdm_trig_low = 200;
373 ah->config.ofdm_trig_high = 500;
374 ah->config.cck_trig_high = 200;
375 ah->config.cck_trig_low = 100;
Luis R. Rodriguez31a0bd32010-04-15 17:38:22 -0400376
377 /*
378 * For now ANI is disabled for AR9003, it is still
379 * being tested.
380 */
381 if (!AR_SREV_9300_20_OR_LATER(ah))
382 ah->config.enable_ani = 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700383
384 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujith2660b812009-02-09 13:27:26 +0530385 ah->config.spurchans[i][0] = AR_NO_SPUR;
386 ah->config.spurchans[i][1] = AR_NO_SPUR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700387 }
388
Luis R. Rodriguez5ffaf8a2010-02-02 11:58:33 -0500389 if (ah->hw_version.devid != AR2427_DEVID_PCIE)
390 ah->config.ht_enable = 1;
391 else
392 ah->config.ht_enable = 0;
393
Sujith0ce024c2009-12-14 14:57:00 +0530394 ah->config.rx_intr_mitigation = true;
Luis R. Rodriguez61584252009-03-12 18:18:49 -0400395
396 /*
397 * We need this for PCI devices only (Cardbus, PCI, miniPCI)
398 * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
399 * This means we use it for all AR5416 devices, and the few
400 * minor PCI AR9280 devices out there.
401 *
402 * Serialization is required because these devices do not handle
403 * well the case of two concurrent reads/writes due to the latency
404 * involved. During one read/write another read/write can be issued
405 * on another CPU while the previous read/write may still be working
406 * on our hardware, if we hit this case the hardware poops in a loop.
407 * We prevent this by serializing reads and writes.
408 *
409 * This issue is not present on PCI-Express devices or pre-AR5416
410 * devices (legacy, 802.11abg).
411 */
412 if (num_possible_cpus() > 1)
David S. Miller2d6a5e92009-03-17 15:01:30 -0700413 ah->config.serialize_regmode = SER_REG_MODE_AUTO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700414}
415
Luis R. Rodriguez50aca252009-08-03 12:24:42 -0700416static void ath9k_hw_init_defaults(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700417{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700418 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
419
420 regulatory->country_code = CTRY_DEFAULT;
421 regulatory->power_limit = MAX_RATE_POWER;
422 regulatory->tp_scale = ATH9K_TP_SCALE_MAX;
423
Sujithd535a422009-02-09 13:27:06 +0530424 ah->hw_version.magic = AR5416_MAGIC;
Sujithd535a422009-02-09 13:27:06 +0530425 ah->hw_version.subvendorid = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700426
427 ah->ah_flags = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700428 if (!AR_SREV_9100(ah))
429 ah->ah_flags = AH_USE_EEPROM;
430
Sujith2660b812009-02-09 13:27:26 +0530431 ah->atim_window = 0;
Sujith2660b812009-02-09 13:27:26 +0530432 ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
433 ah->beacon_interval = 100;
434 ah->enable_32kHz_clock = DONT_USE_32KHZ;
435 ah->slottime = (u32) -1;
Sujith2660b812009-02-09 13:27:26 +0530436 ah->globaltxtimeout = (u32) -1;
Gabor Juhoscbdec972009-07-24 17:27:22 +0200437 ah->power_mode = ATH9K_PM_UNDEFINED;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700438}
439
Sujithcbe61d82009-02-09 13:27:12 +0530440static int ath9k_hw_rf_claim(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700441{
442 u32 val;
443
444 REG_WRITE(ah, AR_PHY(0), 0x00000007);
445
446 val = ath9k_hw_get_radiorev(ah);
447 switch (val & AR_RADIO_SREV_MAJOR) {
448 case 0:
449 val = AR_RAD5133_SREV_MAJOR;
450 break;
451 case AR_RAD5133_SREV_MAJOR:
452 case AR_RAD5122_SREV_MAJOR:
453 case AR_RAD2133_SREV_MAJOR:
454 case AR_RAD2122_SREV_MAJOR:
455 break;
456 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700457 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
458 "Radio Chip Rev 0x%02X not supported\n",
459 val & AR_RADIO_SREV_MAJOR);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700460 return -EOPNOTSUPP;
461 }
462
Sujithd535a422009-02-09 13:27:06 +0530463 ah->hw_version.analog5GhzRev = val;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700464
465 return 0;
466}
467
Sujithcbe61d82009-02-09 13:27:12 +0530468static int ath9k_hw_init_macaddr(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700469{
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700470 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530471 u32 sum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700472 int i;
Sujithf1dc5602008-10-29 10:16:30 +0530473 u16 eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700474
Sujithf1dc5602008-10-29 10:16:30 +0530475 sum = 0;
476 for (i = 0; i < 3; i++) {
Sujithf74df6f2009-02-09 13:27:24 +0530477 eeval = ah->eep_ops->get_eeprom(ah, AR_EEPROM_MAC(i));
Sujithf1dc5602008-10-29 10:16:30 +0530478 sum += eeval;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700479 common->macaddr[2 * i] = eeval >> 8;
480 common->macaddr[2 * i + 1] = eeval & 0xff;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700481 }
Sujithd8baa932009-03-30 15:28:25 +0530482 if (sum == 0 || sum == 0xffff * 3)
Sujithf1dc5602008-10-29 10:16:30 +0530483 return -EADDRNOTAVAIL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700484
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700485 return 0;
486}
487
Sujithcbe61d82009-02-09 13:27:12 +0530488static void ath9k_hw_init_rxgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530489{
490 u32 rxgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530491
Sujithf74df6f2009-02-09 13:27:24 +0530492 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_17) {
493 rxgain_type = ah->eep_ops->get_eeprom(ah, EEP_RXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530494
495 if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530496 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530497 ar9280Modes_backoff_13db_rxgain_9280_2,
498 ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2), 6);
499 else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530500 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530501 ar9280Modes_backoff_23db_rxgain_9280_2,
502 ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 6);
503 else
Sujith2660b812009-02-09 13:27:26 +0530504 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530505 ar9280Modes_original_rxgain_9280_2,
506 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530507 } else {
Sujith2660b812009-02-09 13:27:26 +0530508 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530509 ar9280Modes_original_rxgain_9280_2,
510 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530511 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530512}
513
Sujithcbe61d82009-02-09 13:27:12 +0530514static void ath9k_hw_init_txgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530515{
516 u32 txgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530517
Sujithf74df6f2009-02-09 13:27:24 +0530518 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_19) {
519 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530520
521 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
Sujith2660b812009-02-09 13:27:26 +0530522 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530523 ar9280Modes_high_power_tx_gain_9280_2,
524 ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 6);
525 else
Sujith2660b812009-02-09 13:27:26 +0530526 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530527 ar9280Modes_original_tx_gain_9280_2,
528 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530529 } else {
Sujith2660b812009-02-09 13:27:26 +0530530 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530531 ar9280Modes_original_tx_gain_9280_2,
532 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530533 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530534}
535
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700536static int ath9k_hw_post_init(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700537{
538 int ecode;
539
Sujith527d4852010-03-17 14:25:16 +0530540 if (!AR_SREV_9271(ah)) {
541 if (!ath9k_hw_chip_test(ah))
542 return -ENODEV;
543 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700544
545 ecode = ath9k_hw_rf_claim(ah);
546 if (ecode != 0)
547 return ecode;
548
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700549 ecode = ath9k_hw_eeprom_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700550 if (ecode != 0)
551 return ecode;
Sujith7d01b222009-03-13 08:55:55 +0530552
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700553 ath_print(ath9k_hw_common(ah), ATH_DBG_CONFIG,
554 "Eeprom VER: %d, REV: %d\n",
555 ah->eep_ops->get_eeprom_ver(ah),
556 ah->eep_ops->get_eeprom_rev(ah));
Sujith7d01b222009-03-13 08:55:55 +0530557
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400558 ecode = ath9k_hw_rf_alloc_ext_banks(ah);
559 if (ecode) {
560 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
561 "Failed allocating banks for "
562 "external radio\n");
563 return ecode;
Luis R. Rodriguez574d6b12009-10-19 02:33:37 -0400564 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700565
566 if (!AR_SREV_9100(ah)) {
567 ath9k_hw_ani_setup(ah);
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700568 ath9k_hw_ani_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700569 }
Sujithf1dc5602008-10-29 10:16:30 +0530570
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700571 return 0;
572}
573
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400574static bool ar9002_hw_macversion_supported(u32 macversion)
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700575{
576 switch (macversion) {
577 case AR_SREV_VERSION_5416_PCI:
578 case AR_SREV_VERSION_5416_PCIE:
579 case AR_SREV_VERSION_9160:
580 case AR_SREV_VERSION_9100:
581 case AR_SREV_VERSION_9280:
582 case AR_SREV_VERSION_9285:
583 case AR_SREV_VERSION_9287:
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400584 case AR_SREV_VERSION_9271:
Luis R. Rodriguez7976b422009-09-23 23:07:02 -0400585 return true;
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700586 default:
587 break;
588 }
589 return false;
590}
591
Luis R. Rodriguez61accab2010-04-15 17:38:21 -0400592static bool ar9003_hw_macversion_supported(u32 macversion)
593{
594 switch (macversion) {
595 case AR_SREV_VERSION_9300:
596 return true;
597 default:
598 break;
599 }
600 return false;
601}
602
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400603static void ar9002_hw_init_mode_regs(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700604{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400605 if (AR_SREV_9271(ah)) {
Luis R. Rodriguez85643282009-10-19 02:33:33 -0400606 INIT_INI_ARRAY(&ah->iniModes, ar9271Modes_9271,
607 ARRAY_SIZE(ar9271Modes_9271), 6);
608 INIT_INI_ARRAY(&ah->iniCommon, ar9271Common_9271,
609 ARRAY_SIZE(ar9271Common_9271), 2);
Sujith70807e92010-03-17 14:25:14 +0530610 INIT_INI_ARRAY(&ah->iniCommon_normal_cck_fir_coeff_9271,
611 ar9271Common_normal_cck_fir_coeff_9271,
612 ARRAY_SIZE(ar9271Common_normal_cck_fir_coeff_9271), 2);
613 INIT_INI_ARRAY(&ah->iniCommon_japan_2484_cck_fir_coeff_9271,
614 ar9271Common_japan_2484_cck_fir_coeff_9271,
615 ARRAY_SIZE(ar9271Common_japan_2484_cck_fir_coeff_9271), 2);
Luis R. Rodriguez85643282009-10-19 02:33:33 -0400616 INIT_INI_ARRAY(&ah->iniModes_9271_1_0_only,
617 ar9271Modes_9271_1_0_only,
618 ARRAY_SIZE(ar9271Modes_9271_1_0_only), 6);
Sujith70807e92010-03-17 14:25:14 +0530619 INIT_INI_ARRAY(&ah->iniModes_9271_ANI_reg, ar9271Modes_9271_ANI_reg,
620 ARRAY_SIZE(ar9271Modes_9271_ANI_reg), 6);
621 INIT_INI_ARRAY(&ah->iniModes_high_power_tx_gain_9271,
622 ar9271Modes_high_power_tx_gain_9271,
623 ARRAY_SIZE(ar9271Modes_high_power_tx_gain_9271), 6);
624 INIT_INI_ARRAY(&ah->iniModes_normal_power_tx_gain_9271,
625 ar9271Modes_normal_power_tx_gain_9271,
626 ARRAY_SIZE(ar9271Modes_normal_power_tx_gain_9271), 6);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400627 return;
628 }
629
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530630 if (AR_SREV_9287_11_OR_LATER(ah)) {
631 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_1,
632 ARRAY_SIZE(ar9287Modes_9287_1_1), 6);
633 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_1,
634 ARRAY_SIZE(ar9287Common_9287_1_1), 2);
635 if (ah->config.pcie_clock_req)
636 INIT_INI_ARRAY(&ah->iniPcieSerdes,
637 ar9287PciePhy_clkreq_off_L1_9287_1_1,
638 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_1), 2);
639 else
640 INIT_INI_ARRAY(&ah->iniPcieSerdes,
641 ar9287PciePhy_clkreq_always_on_L1_9287_1_1,
642 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_1),
643 2);
644 } else if (AR_SREV_9287_10_OR_LATER(ah)) {
645 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_0,
646 ARRAY_SIZE(ar9287Modes_9287_1_0), 6);
647 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_0,
648 ARRAY_SIZE(ar9287Common_9287_1_0), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700649
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530650 if (ah->config.pcie_clock_req)
651 INIT_INI_ARRAY(&ah->iniPcieSerdes,
652 ar9287PciePhy_clkreq_off_L1_9287_1_0,
653 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_0), 2);
654 else
655 INIT_INI_ARRAY(&ah->iniPcieSerdes,
656 ar9287PciePhy_clkreq_always_on_L1_9287_1_0,
657 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_0),
658 2);
659 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
660
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530661
Sujith2660b812009-02-09 13:27:26 +0530662 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530663 ARRAY_SIZE(ar9285Modes_9285_1_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530664 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530665 ARRAY_SIZE(ar9285Common_9285_1_2), 2);
666
Sujith2660b812009-02-09 13:27:26 +0530667 if (ah->config.pcie_clock_req) {
668 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530669 ar9285PciePhy_clkreq_off_L1_9285_1_2,
670 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2);
671 } else {
Sujith2660b812009-02-09 13:27:26 +0530672 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530673 ar9285PciePhy_clkreq_always_on_L1_9285_1_2,
674 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2),
675 2);
676 }
677 } else if (AR_SREV_9285_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530678 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530679 ARRAY_SIZE(ar9285Modes_9285), 6);
Sujith2660b812009-02-09 13:27:26 +0530680 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530681 ARRAY_SIZE(ar9285Common_9285), 2);
682
Sujith2660b812009-02-09 13:27:26 +0530683 if (ah->config.pcie_clock_req) {
684 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530685 ar9285PciePhy_clkreq_off_L1_9285,
686 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2);
687 } else {
Sujith2660b812009-02-09 13:27:26 +0530688 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530689 ar9285PciePhy_clkreq_always_on_L1_9285,
690 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285), 2);
691 }
692 } else if (AR_SREV_9280_20_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530693 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700694 ARRAY_SIZE(ar9280Modes_9280_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530695 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700696 ARRAY_SIZE(ar9280Common_9280_2), 2);
697
Sujith2660b812009-02-09 13:27:26 +0530698 if (ah->config.pcie_clock_req) {
699 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530700 ar9280PciePhy_clkreq_off_L1_9280,
701 ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700702 } else {
Sujith2660b812009-02-09 13:27:26 +0530703 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530704 ar9280PciePhy_clkreq_always_on_L1_9280,
705 ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700706 }
Sujith2660b812009-02-09 13:27:26 +0530707 INIT_INI_ARRAY(&ah->iniModesAdditional,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700708 ar9280Modes_fast_clock_9280_2,
Sujithf1dc5602008-10-29 10:16:30 +0530709 ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700710 } else if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530711 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700712 ARRAY_SIZE(ar9280Modes_9280), 6);
Sujith2660b812009-02-09 13:27:26 +0530713 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700714 ARRAY_SIZE(ar9280Common_9280), 2);
715 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530716 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700717 ARRAY_SIZE(ar5416Modes_9160), 6);
Sujith2660b812009-02-09 13:27:26 +0530718 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700719 ARRAY_SIZE(ar5416Common_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530720 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700721 ARRAY_SIZE(ar5416Bank0_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530722 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700723 ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530724 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700725 ARRAY_SIZE(ar5416Bank1_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530726 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700727 ARRAY_SIZE(ar5416Bank2_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530728 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700729 ARRAY_SIZE(ar5416Bank3_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530730 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700731 ARRAY_SIZE(ar5416Bank6_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530732 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700733 ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530734 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700735 ARRAY_SIZE(ar5416Bank7_9160), 2);
736 if (AR_SREV_9160_11(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530737 INIT_INI_ARRAY(&ah->iniAddac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700738 ar5416Addac_91601_1,
739 ARRAY_SIZE(ar5416Addac_91601_1), 2);
740 } else {
Sujith2660b812009-02-09 13:27:26 +0530741 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700742 ARRAY_SIZE(ar5416Addac_9160), 2);
743 }
744 } else if (AR_SREV_9100_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530745 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700746 ARRAY_SIZE(ar5416Modes_9100), 6);
Sujith2660b812009-02-09 13:27:26 +0530747 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700748 ARRAY_SIZE(ar5416Common_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530749 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700750 ARRAY_SIZE(ar5416Bank0_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530751 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700752 ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530753 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700754 ARRAY_SIZE(ar5416Bank1_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530755 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700756 ARRAY_SIZE(ar5416Bank2_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530757 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700758 ARRAY_SIZE(ar5416Bank3_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530759 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700760 ARRAY_SIZE(ar5416Bank6_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530761 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700762 ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530763 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700764 ARRAY_SIZE(ar5416Bank7_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530765 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700766 ARRAY_SIZE(ar5416Addac_9100), 2);
767 } else {
Sujith2660b812009-02-09 13:27:26 +0530768 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700769 ARRAY_SIZE(ar5416Modes), 6);
Sujith2660b812009-02-09 13:27:26 +0530770 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700771 ARRAY_SIZE(ar5416Common), 2);
Sujith2660b812009-02-09 13:27:26 +0530772 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700773 ARRAY_SIZE(ar5416Bank0), 2);
Sujith2660b812009-02-09 13:27:26 +0530774 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700775 ARRAY_SIZE(ar5416BB_RfGain), 3);
Sujith2660b812009-02-09 13:27:26 +0530776 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700777 ARRAY_SIZE(ar5416Bank1), 2);
Sujith2660b812009-02-09 13:27:26 +0530778 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700779 ARRAY_SIZE(ar5416Bank2), 2);
Sujith2660b812009-02-09 13:27:26 +0530780 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700781 ARRAY_SIZE(ar5416Bank3), 3);
Sujith2660b812009-02-09 13:27:26 +0530782 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700783 ARRAY_SIZE(ar5416Bank6), 3);
Sujith2660b812009-02-09 13:27:26 +0530784 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700785 ARRAY_SIZE(ar5416Bank6TPC), 3);
Sujith2660b812009-02-09 13:27:26 +0530786 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700787 ARRAY_SIZE(ar5416Bank7), 2);
Sujith2660b812009-02-09 13:27:26 +0530788 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700789 ARRAY_SIZE(ar5416Addac), 2);
790 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700791}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700792
Luis R. Rodriguez13ce3e92010-04-15 17:38:37 -0400793/* AR9003 2.0 - new INI format (pre, core, post arrays per subsystem) */
794static void ar9003_hw_init_mode_regs(struct ath_hw *ah)
795{
796 /* mac */
797 INIT_INI_ARRAY(&ah->iniMac[ATH_INI_PRE], NULL, 0, 0);
798 INIT_INI_ARRAY(&ah->iniMac[ATH_INI_CORE],
799 ar9300_2p0_mac_core,
800 ARRAY_SIZE(ar9300_2p0_mac_core), 2);
801 INIT_INI_ARRAY(&ah->iniMac[ATH_INI_POST],
802 ar9300_2p0_mac_postamble,
803 ARRAY_SIZE(ar9300_2p0_mac_postamble), 5);
804
805 /* bb */
806 INIT_INI_ARRAY(&ah->iniBB[ATH_INI_PRE], NULL, 0, 0);
807 INIT_INI_ARRAY(&ah->iniBB[ATH_INI_CORE],
808 ar9300_2p0_baseband_core,
809 ARRAY_SIZE(ar9300_2p0_baseband_core), 2);
810 INIT_INI_ARRAY(&ah->iniBB[ATH_INI_POST],
811 ar9300_2p0_baseband_postamble,
812 ARRAY_SIZE(ar9300_2p0_baseband_postamble), 5);
813
814 /* radio */
815 INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_PRE], NULL, 0, 0);
816 INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_CORE],
817 ar9300_2p0_radio_core,
818 ARRAY_SIZE(ar9300_2p0_radio_core), 2);
819 INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_POST],
820 ar9300_2p0_radio_postamble,
821 ARRAY_SIZE(ar9300_2p0_radio_postamble), 5);
822
823 /* soc */
824 INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_PRE],
825 ar9300_2p0_soc_preamble,
826 ARRAY_SIZE(ar9300_2p0_soc_preamble), 2);
827 INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_CORE], NULL, 0, 0);
828 INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_POST],
829 ar9300_2p0_soc_postamble,
830 ARRAY_SIZE(ar9300_2p0_soc_postamble), 5);
831
832 /* rx/tx gain */
833 INIT_INI_ARRAY(&ah->iniModesRxGain,
834 ar9300Common_rx_gain_table_2p0,
835 ARRAY_SIZE(ar9300Common_rx_gain_table_2p0), 2);
836 INIT_INI_ARRAY(&ah->iniModesTxGain,
837 ar9300Modes_lowest_ob_db_tx_gain_table_2p0,
838 ARRAY_SIZE(ar9300Modes_lowest_ob_db_tx_gain_table_2p0),
839 5);
840
841 /* Load PCIE SERDES settings from INI */
842
843 /* Awake Setting */
844
845 INIT_INI_ARRAY(&ah->iniPcieSerdes,
846 ar9300PciePhy_pll_on_clkreq_disable_L1_2p0,
847 ARRAY_SIZE(ar9300PciePhy_pll_on_clkreq_disable_L1_2p0),
848 2);
849
850 /* Sleep Setting */
851
852 INIT_INI_ARRAY(&ah->iniPcieSerdesLowPower,
853 ar9300PciePhy_clkreq_enable_L1_2p0,
854 ARRAY_SIZE(ar9300PciePhy_clkreq_enable_L1_2p0),
855 2);
856
857 /* Fast clock modal settings */
858 INIT_INI_ARRAY(&ah->iniModesAdditional,
859 ar9300Modes_fast_clock_2p0,
860 ARRAY_SIZE(ar9300Modes_fast_clock_2p0),
861 3);
862}
863
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700864static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
865{
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530866 if (AR_SREV_9287_11_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530867 INIT_INI_ARRAY(&ah->iniModesRxGain,
868 ar9287Modes_rx_gain_9287_1_1,
869 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_1), 6);
870 else if (AR_SREV_9287_10(ah))
871 INIT_INI_ARRAY(&ah->iniModesRxGain,
872 ar9287Modes_rx_gain_9287_1_0,
873 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_0), 6);
874 else if (AR_SREV_9280_20(ah))
875 ath9k_hw_init_rxgain_ini(ah);
876
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530877 if (AR_SREV_9287_11_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530878 INIT_INI_ARRAY(&ah->iniModesTxGain,
879 ar9287Modes_tx_gain_9287_1_1,
880 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_1), 6);
881 } else if (AR_SREV_9287_10(ah)) {
882 INIT_INI_ARRAY(&ah->iniModesTxGain,
883 ar9287Modes_tx_gain_9287_1_0,
884 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_0), 6);
885 } else if (AR_SREV_9280_20(ah)) {
886 ath9k_hw_init_txgain_ini(ah);
887 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530888 u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
889
890 /* txgain table */
891 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) {
Vivek Natarajan53bc7aa2010-04-05 14:48:04 +0530892 if (AR_SREV_9285E_20(ah)) {
893 INIT_INI_ARRAY(&ah->iniModesTxGain,
894 ar9285Modes_XE2_0_high_power,
895 ARRAY_SIZE(
896 ar9285Modes_XE2_0_high_power), 6);
897 } else {
898 INIT_INI_ARRAY(&ah->iniModesTxGain,
899 ar9285Modes_high_power_tx_gain_9285_1_2,
900 ARRAY_SIZE(
901 ar9285Modes_high_power_tx_gain_9285_1_2), 6);
902 }
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530903 } else {
Vivek Natarajan53bc7aa2010-04-05 14:48:04 +0530904 if (AR_SREV_9285E_20(ah)) {
905 INIT_INI_ARRAY(&ah->iniModesTxGain,
906 ar9285Modes_XE2_0_normal_power,
907 ARRAY_SIZE(
908 ar9285Modes_XE2_0_normal_power), 6);
909 } else {
910 INIT_INI_ARRAY(&ah->iniModesTxGain,
911 ar9285Modes_original_tx_gain_9285_1_2,
912 ARRAY_SIZE(
913 ar9285Modes_original_tx_gain_9285_1_2), 6);
914 }
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530915 }
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530916 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700917}
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530918
Felix Fietkauaa8bc9e2010-01-23 20:04:18 +0100919static void ath9k_hw_init_eeprom_fix(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700920{
Pavel Roskin2eb46d92010-04-07 01:33:33 -0400921 struct base_eep_header *pBase = &(ah->eeprom.def.baseEepHeader);
922 struct ath_common *common = ath9k_hw_common(ah);
Sujith06d0f062009-02-12 10:06:45 +0530923
Pavel Roskin2eb46d92010-04-07 01:33:33 -0400924 ah->need_an_top2_fixup = (ah->hw_version.devid == AR9280_DEVID_PCI) &&
Senthil Balasubramanian939ad862010-04-15 17:38:50 -0400925 !AR_SREV_9285(ah) && !AR_SREV_9271(ah) &&
Pavel Roskin2eb46d92010-04-07 01:33:33 -0400926 ((pBase->version & 0xff) > 0x0a) &&
927 (pBase->pwdclkind == 0);
Sujith06d0f062009-02-12 10:06:45 +0530928
Pavel Roskin2eb46d92010-04-07 01:33:33 -0400929 if (ah->need_an_top2_fixup)
930 ath_print(common, ATH_DBG_EEPROM,
931 "needs fixup for AR_AN_TOP2 register\n");
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700932}
933
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400934static void ath9k_hw_attach_ops(struct ath_hw *ah)
935{
936 if (AR_SREV_9300_20_OR_LATER(ah))
937 ar9003_hw_attach_ops(ah);
938 else
939 ar9002_hw_attach_ops(ah);
940}
941
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400942/* Called for all hardware families */
943static int __ath9k_hw_init(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700944{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700945 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700946 int r = 0;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700947
Luis R. Rodriguezbab1f622010-04-15 17:38:20 -0400948 if (ah->hw_version.devid == AR5416_AR9100_DEVID)
949 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700950
951 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700952 ath_print(common, ATH_DBG_FATAL,
953 "Couldn't reset chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700954 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700955 }
956
Luis R. Rodriguezbab1f622010-04-15 17:38:20 -0400957 ath9k_hw_init_defaults(ah);
958 ath9k_hw_init_config(ah);
959
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400960 ath9k_hw_attach_ops(ah);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400961
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700962 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700963 ath_print(common, ATH_DBG_FATAL, "Couldn't wakeup chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700964 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700965 }
966
967 if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
968 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
969 (AR_SREV_9280(ah) && !ah->is_pciexpress)) {
970 ah->config.serialize_regmode =
971 SER_REG_MODE_ON;
972 } else {
973 ah->config.serialize_regmode =
974 SER_REG_MODE_OFF;
975 }
976 }
977
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700978 ath_print(common, ATH_DBG_RESET, "serialize_regmode is %d\n",
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700979 ah->config.serialize_regmode);
980
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -0500981 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
982 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD >> 1;
983 else
984 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD;
985
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400986 if (!ath9k_hw_macversion_supported(ah)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700987 ath_print(common, ATH_DBG_FATAL,
988 "Mac Chip Rev 0x%02x.%x is not supported by "
989 "this driver\n", ah->hw_version.macVersion,
990 ah->hw_version.macRev);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700991 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700992 }
993
Luis R. Rodriguez0df13da2010-04-15 17:38:59 -0400994 if (AR_SREV_9271(ah) || AR_SREV_9100(ah))
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400995 ah->is_pciexpress = false;
996
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700997 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700998 ath9k_hw_init_cal_settings(ah);
999
1000 ah->ani_function = ATH9K_ANI_ALL;
Luis R. Rodriguez31a0bd32010-04-15 17:38:22 -04001001 if (AR_SREV_9280_10_OR_LATER(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -07001002 ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
1003
1004 ath9k_hw_init_mode_regs(ah);
1005
1006 if (ah->is_pciexpress)
Vivek Natarajan93b1b372009-09-17 09:24:58 +05301007 ath9k_hw_configpcipowersave(ah, 0, 0);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -07001008 else
1009 ath9k_hw_disablepcie(ah);
1010
Sujith193cd452009-09-18 15:04:07 +05301011 /* Support for Japan ch.14 (2484) spread */
1012 if (AR_SREV_9287_11_OR_LATER(ah)) {
1013 INIT_INI_ARRAY(&ah->iniCckfirNormal,
1014 ar9287Common_normal_cck_fir_coeff_92871_1,
1015 ARRAY_SIZE(ar9287Common_normal_cck_fir_coeff_92871_1), 2);
1016 INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
1017 ar9287Common_japan_2484_cck_fir_coeff_92871_1,
1018 ARRAY_SIZE(ar9287Common_japan_2484_cck_fir_coeff_92871_1), 2);
1019 }
1020
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -07001021 r = ath9k_hw_post_init(ah);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -07001022 if (r)
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -07001023 return r;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -07001024
1025 ath9k_hw_init_mode_gain_regs(ah);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01001026 r = ath9k_hw_fill_cap_info(ah);
1027 if (r)
1028 return r;
1029
Felix Fietkauaa8bc9e2010-01-23 20:04:18 +01001030 ath9k_hw_init_eeprom_fix(ah);
Sujithf6688cd2008-12-07 21:43:10 +05301031
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001032 r = ath9k_hw_init_macaddr(ah);
1033 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001034 ath_print(common, ATH_DBG_FATAL,
1035 "Failed to initialize MAC address\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -07001036 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001037 }
1038
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001039 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
Sujith2660b812009-02-09 13:27:26 +05301040 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001041 else
Sujith2660b812009-02-09 13:27:26 +05301042 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001043
Felix Fietkau641d9922010-04-15 17:38:49 -04001044 if (AR_SREV_9300_20_OR_LATER(ah))
1045 ar9003_hw_set_nf_limits(ah);
1046
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001047 ath9k_init_nfcal_hist_buffer(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001048
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001049 common->state = ATH_HW_INITIALIZED;
1050
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001051 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001052}
1053
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04001054int ath9k_hw_init(struct ath_hw *ah)
1055{
1056 int ret;
1057 struct ath_common *common = ath9k_hw_common(ah);
1058
1059 /* These are all the AR5008/AR9001/AR9002 hardware family of chipsets */
1060 switch (ah->hw_version.devid) {
1061 case AR5416_DEVID_PCI:
1062 case AR5416_DEVID_PCIE:
1063 case AR5416_AR9100_DEVID:
1064 case AR9160_DEVID_PCI:
1065 case AR9280_DEVID_PCI:
1066 case AR9280_DEVID_PCIE:
1067 case AR9285_DEVID_PCIE:
Senthil Balasubramaniandb3cc532010-04-15 17:38:18 -04001068 case AR9287_DEVID_PCI:
1069 case AR9287_DEVID_PCIE:
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04001070 case AR2427_DEVID_PCIE:
Senthil Balasubramaniandb3cc532010-04-15 17:38:18 -04001071 case AR9300_DEVID_PCIE:
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04001072 break;
1073 default:
1074 if (common->bus_ops->ath_bus_type == ATH_USB)
1075 break;
1076 ath_print(common, ATH_DBG_FATAL,
1077 "Hardware device ID 0x%04x not supported\n",
1078 ah->hw_version.devid);
1079 return -EOPNOTSUPP;
1080 }
1081
1082 ret = __ath9k_hw_init(ah);
1083 if (ret) {
1084 ath_print(common, ATH_DBG_FATAL,
1085 "Unable to initialize hardware; "
1086 "initialization status: %d\n", ret);
1087 return ret;
1088 }
1089
1090 return 0;
1091}
1092EXPORT_SYMBOL(ath9k_hw_init);
1093
Sujithcbe61d82009-02-09 13:27:12 +05301094static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301095{
1096 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
1097 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
1098
1099 REG_WRITE(ah, AR_QOS_NO_ACK,
1100 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
1101 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
1102 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
1103
1104 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
1105 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
1106 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
1107 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
1108 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
1109}
1110
Sujithcbe61d82009-02-09 13:27:12 +05301111static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301112 struct ath9k_channel *chan)
1113{
Luis R. Rodriguez64773962010-04-15 17:38:17 -04001114 u32 pll = ath9k_hw_compute_pll_control(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301115
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001116 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +05301117
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -04001118 /* Switch the core clock for ar9271 to 117Mhz */
1119 if (AR_SREV_9271(ah)) {
Sujith25e2ab12010-03-17 14:25:22 +05301120 udelay(500);
1121 REG_WRITE(ah, 0x50040, 0x304);
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -04001122 }
1123
Sujithf1dc5602008-10-29 10:16:30 +05301124 udelay(RTC_PLL_SETTLE_DELAY);
1125
1126 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
1127}
1128
Sujithcbe61d82009-02-09 13:27:12 +05301129static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -08001130 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301131{
Pavel Roskin152d5302010-03-31 18:05:37 -04001132 u32 imr_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +05301133 AR_IMR_TXURN |
1134 AR_IMR_RXERR |
1135 AR_IMR_RXORN |
1136 AR_IMR_BCNMISC;
1137
Sujith0ce024c2009-12-14 14:57:00 +05301138 if (ah->config.rx_intr_mitigation)
Pavel Roskin152d5302010-03-31 18:05:37 -04001139 imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
Sujithf1dc5602008-10-29 10:16:30 +05301140 else
Pavel Roskin152d5302010-03-31 18:05:37 -04001141 imr_reg |= AR_IMR_RXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301142
Pavel Roskin152d5302010-03-31 18:05:37 -04001143 imr_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301144
Colin McCabed97809d2008-12-01 13:38:55 -08001145 if (opmode == NL80211_IFTYPE_AP)
Pavel Roskin152d5302010-03-31 18:05:37 -04001146 imr_reg |= AR_IMR_MIB;
Sujithf1dc5602008-10-29 10:16:30 +05301147
Pavel Roskin152d5302010-03-31 18:05:37 -04001148 REG_WRITE(ah, AR_IMR, imr_reg);
Pavel Roskin74bad5c2010-02-23 18:15:27 -05001149 ah->imrs2_reg |= AR_IMR_S2_GTT;
1150 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
Sujithf1dc5602008-10-29 10:16:30 +05301151
1152 if (!AR_SREV_9100(ah)) {
1153 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
1154 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
1155 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
1156 }
1157}
1158
Felix Fietkau0005baf2010-01-15 02:33:40 +01001159static void ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301160{
Felix Fietkau0005baf2010-01-15 02:33:40 +01001161 u32 val = ath9k_hw_mac_to_clks(ah, us);
1162 val = min(val, (u32) 0xFFFF);
1163 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, val);
Sujithf1dc5602008-10-29 10:16:30 +05301164}
1165
Felix Fietkau0005baf2010-01-15 02:33:40 +01001166static void ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301167{
Felix Fietkau0005baf2010-01-15 02:33:40 +01001168 u32 val = ath9k_hw_mac_to_clks(ah, us);
1169 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_ACK));
1170 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_ACK, val);
1171}
1172
1173static void ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
1174{
1175 u32 val = ath9k_hw_mac_to_clks(ah, us);
1176 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_CTS));
1177 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_CTS, val);
Sujithf1dc5602008-10-29 10:16:30 +05301178}
1179
Sujithcbe61d82009-02-09 13:27:12 +05301180static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +05301181{
Sujithf1dc5602008-10-29 10:16:30 +05301182 if (tu > 0xFFFF) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001183 ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT,
1184 "bad global tx timeout %u\n", tu);
Sujith2660b812009-02-09 13:27:26 +05301185 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301186 return false;
1187 } else {
1188 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +05301189 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +05301190 return true;
1191 }
1192}
1193
Felix Fietkau0005baf2010-01-15 02:33:40 +01001194void ath9k_hw_init_global_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301195{
Felix Fietkau0005baf2010-01-15 02:33:40 +01001196 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
1197 int acktimeout;
Felix Fietkaue239d852010-01-15 02:34:58 +01001198 int slottime;
Felix Fietkau0005baf2010-01-15 02:33:40 +01001199 int sifstime;
1200
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001201 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
1202 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +05301203
Sujith2660b812009-02-09 13:27:26 +05301204 if (ah->misc_mode != 0)
Sujithf1dc5602008-10-29 10:16:30 +05301205 REG_WRITE(ah, AR_PCU_MISC,
Sujith2660b812009-02-09 13:27:26 +05301206 REG_READ(ah, AR_PCU_MISC) | ah->misc_mode);
Felix Fietkau0005baf2010-01-15 02:33:40 +01001207
1208 if (conf->channel && conf->channel->band == IEEE80211_BAND_5GHZ)
1209 sifstime = 16;
1210 else
1211 sifstime = 10;
1212
Felix Fietkaue239d852010-01-15 02:34:58 +01001213 /* As defined by IEEE 802.11-2007 17.3.8.6 */
1214 slottime = ah->slottime + 3 * ah->coverage_class;
1215 acktimeout = slottime + sifstime;
Felix Fietkau42c45682010-02-11 18:07:19 +01001216
1217 /*
1218 * Workaround for early ACK timeouts, add an offset to match the
1219 * initval's 64us ack timeout value.
1220 * This was initially only meant to work around an issue with delayed
1221 * BA frames in some implementations, but it has been found to fix ACK
1222 * timeout issues in other cases as well.
1223 */
1224 if (conf->channel && conf->channel->band == IEEE80211_BAND_2GHZ)
1225 acktimeout += 64 - sifstime - ah->slottime;
1226
Felix Fietkaue239d852010-01-15 02:34:58 +01001227 ath9k_hw_setslottime(ah, slottime);
Felix Fietkau0005baf2010-01-15 02:33:40 +01001228 ath9k_hw_set_ack_timeout(ah, acktimeout);
1229 ath9k_hw_set_cts_timeout(ah, acktimeout);
Sujith2660b812009-02-09 13:27:26 +05301230 if (ah->globaltxtimeout != (u32) -1)
1231 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Sujithf1dc5602008-10-29 10:16:30 +05301232}
Felix Fietkau0005baf2010-01-15 02:33:40 +01001233EXPORT_SYMBOL(ath9k_hw_init_global_settings);
Sujithf1dc5602008-10-29 10:16:30 +05301234
Sujith285f2dd2010-01-08 10:36:07 +05301235void ath9k_hw_deinit(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001236{
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001237 struct ath_common *common = ath9k_hw_common(ah);
1238
Sujith736b3a22010-03-17 14:25:24 +05301239 if (common->state < ATH_HW_INITIALIZED)
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001240 goto free_hw;
1241
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001242 if (!AR_SREV_9100(ah))
Luis R. Rodrigueze70c0cf2009-08-03 12:24:51 -07001243 ath9k_hw_ani_disable(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001244
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001245 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001246
1247free_hw:
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001248 ath9k_hw_rf_free_ext_banks(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001249}
Sujith285f2dd2010-01-08 10:36:07 +05301250EXPORT_SYMBOL(ath9k_hw_deinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001251
Sujithf1dc5602008-10-29 10:16:30 +05301252/*******/
1253/* INI */
1254/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001255
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001256u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan)
Bob Copeland3a702e42009-03-30 22:30:29 -04001257{
1258 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
1259
1260 if (IS_CHAN_B(chan))
1261 ctl |= CTL_11B;
1262 else if (IS_CHAN_G(chan))
1263 ctl |= CTL_11G;
1264 else
1265 ctl |= CTL_11A;
1266
1267 return ctl;
1268}
1269
Sujithf1dc5602008-10-29 10:16:30 +05301270/****************************************/
1271/* Reset and Channel Switching Routines */
1272/****************************************/
1273
Sujithcbe61d82009-02-09 13:27:12 +05301274static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301275{
1276 u32 regval;
1277
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001278 /*
1279 * set AHB_MODE not to do cacheline prefetches
1280 */
Sujithf1dc5602008-10-29 10:16:30 +05301281 regval = REG_READ(ah, AR_AHB_MODE);
1282 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
1283
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001284 /*
1285 * let mac dma reads be in 128 byte chunks
1286 */
Sujithf1dc5602008-10-29 10:16:30 +05301287 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
1288 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
1289
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001290 /*
1291 * Restore TX Trigger Level to its pre-reset value.
1292 * The initial value depends on whether aggregation is enabled, and is
1293 * adjusted whenever underruns are detected.
1294 */
Sujith2660b812009-02-09 13:27:26 +05301295 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +05301296
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001297 /*
1298 * let mac dma writes be in 128 byte chunks
1299 */
Sujithf1dc5602008-10-29 10:16:30 +05301300 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
1301 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
1302
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001303 /*
1304 * Setup receive FIFO threshold to hold off TX activities
1305 */
Sujithf1dc5602008-10-29 10:16:30 +05301306 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1307
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001308 /*
1309 * reduce the number of usable entries in PCU TXBUF to avoid
1310 * wrap around issues.
1311 */
Sujithf1dc5602008-10-29 10:16:30 +05301312 if (AR_SREV_9285(ah)) {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001313 /* For AR9285 the number of Fifos are reduced to half.
1314 * So set the usable tx buf size also to half to
1315 * avoid data/delimiter underruns
1316 */
Sujithf1dc5602008-10-29 10:16:30 +05301317 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1318 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001319 } else if (!AR_SREV_9271(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +05301320 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1321 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1322 }
1323}
1324
Sujithcbe61d82009-02-09 13:27:12 +05301325static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301326{
1327 u32 val;
1328
1329 val = REG_READ(ah, AR_STA_ID1);
1330 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
1331 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001332 case NL80211_IFTYPE_AP:
Sujithf1dc5602008-10-29 10:16:30 +05301333 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
1334 | AR_STA_ID1_KSRCH_MODE);
1335 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1336 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001337 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04001338 case NL80211_IFTYPE_MESH_POINT:
Sujithf1dc5602008-10-29 10:16:30 +05301339 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
1340 | AR_STA_ID1_KSRCH_MODE);
1341 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1342 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001343 case NL80211_IFTYPE_STATION:
1344 case NL80211_IFTYPE_MONITOR:
Sujithf1dc5602008-10-29 10:16:30 +05301345 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
1346 break;
1347 }
1348}
1349
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001350void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled,
1351 u32 *coef_mantissa, u32 *coef_exponent)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001352{
1353 u32 coef_exp, coef_man;
1354
1355 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1356 if ((coef_scaled >> coef_exp) & 0x1)
1357 break;
1358
1359 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1360
1361 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1362
1363 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1364 *coef_exponent = coef_exp - 16;
1365}
1366
Sujithcbe61d82009-02-09 13:27:12 +05301367static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +05301368{
1369 u32 rst_flags;
1370 u32 tmpReg;
1371
Sujith70768492009-02-16 13:23:12 +05301372 if (AR_SREV_9100(ah)) {
1373 u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK);
1374 val &= ~AR_RTC_DERIVED_CLK_PERIOD;
1375 val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD);
1376 REG_WRITE(ah, AR_RTC_DERIVED_CLK, val);
1377 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1378 }
1379
Sujithf1dc5602008-10-29 10:16:30 +05301380 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1381 AR_RTC_FORCE_WAKE_ON_INT);
1382
1383 if (AR_SREV_9100(ah)) {
1384 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1385 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1386 } else {
1387 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1388 if (tmpReg &
1389 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1390 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001391 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05301392 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001393
1394 val = AR_RC_HOSTIF;
1395 if (!AR_SREV_9300_20_OR_LATER(ah))
1396 val |= AR_RC_AHB;
1397 REG_WRITE(ah, AR_RC, val);
1398
1399 } else if (!AR_SREV_9300_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05301400 REG_WRITE(ah, AR_RC, AR_RC_AHB);
Sujithf1dc5602008-10-29 10:16:30 +05301401
1402 rst_flags = AR_RTC_RC_MAC_WARM;
1403 if (type == ATH9K_RESET_COLD)
1404 rst_flags |= AR_RTC_RC_MAC_COLD;
1405 }
1406
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001407 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujithf1dc5602008-10-29 10:16:30 +05301408 udelay(50);
1409
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001410 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301411 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001412 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1413 "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301414 return false;
1415 }
1416
1417 if (!AR_SREV_9100(ah))
1418 REG_WRITE(ah, AR_RC, 0);
1419
Sujithf1dc5602008-10-29 10:16:30 +05301420 if (AR_SREV_9100(ah))
1421 udelay(50);
1422
1423 return true;
1424}
1425
Sujithcbe61d82009-02-09 13:27:12 +05301426static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301427{
1428 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1429 AR_RTC_FORCE_WAKE_ON_INT);
1430
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001431 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301432 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1433
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001434 REG_WRITE(ah, AR_RTC_RESET, 0);
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301435
Senthil Balasubramanian84e21692010-04-15 17:38:30 -04001436 if (!AR_SREV_9300_20_OR_LATER(ah))
1437 udelay(2);
1438
1439 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301440 REG_WRITE(ah, AR_RC, 0);
1441
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001442 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301443
1444 if (!ath9k_hw_wait(ah,
1445 AR_RTC_STATUS,
1446 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301447 AR_RTC_STATUS_ON,
1448 AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001449 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1450 "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301451 return false;
1452 }
1453
1454 ath9k_hw_read_revisions(ah);
1455
1456 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1457}
1458
Sujithcbe61d82009-02-09 13:27:12 +05301459static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301460{
1461 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1462 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1463
1464 switch (type) {
1465 case ATH9K_RESET_POWER_ON:
1466 return ath9k_hw_set_reset_power_on(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301467 case ATH9K_RESET_WARM:
1468 case ATH9K_RESET_COLD:
1469 return ath9k_hw_set_reset(ah, type);
Sujithf1dc5602008-10-29 10:16:30 +05301470 default:
1471 return false;
1472 }
1473}
1474
Sujithcbe61d82009-02-09 13:27:12 +05301475static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301476 struct ath9k_channel *chan)
1477{
Vivek Natarajan42abfbe2009-09-17 09:27:59 +05301478 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) {
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301479 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
1480 return false;
1481 } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
Sujithf1dc5602008-10-29 10:16:30 +05301482 return false;
1483
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001484 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05301485 return false;
1486
Sujith2660b812009-02-09 13:27:26 +05301487 ah->chip_fullsleep = false;
Sujithf1dc5602008-10-29 10:16:30 +05301488 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301489 ath9k_hw_set_rfmode(ah, chan);
1490
1491 return true;
1492}
1493
Sujithcbe61d82009-02-09 13:27:12 +05301494static bool ath9k_hw_channel_change(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001495 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301496{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001497 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001498 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001499 struct ieee80211_channel *channel = chan->chan;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001500 u32 qnum;
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001501 int r;
Sujithf1dc5602008-10-29 10:16:30 +05301502
1503 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1504 if (ath9k_hw_numtxpending(ah, qnum)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001505 ath_print(common, ATH_DBG_QUEUE,
1506 "Transmit frames pending on "
1507 "queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301508 return false;
1509 }
1510 }
1511
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001512 if (!ath9k_hw_rfbus_req(ah)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001513 ath_print(common, ATH_DBG_FATAL,
1514 "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301515 return false;
1516 }
1517
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001518 ath9k_hw_set_channel_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301519
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001520 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001521 if (r) {
1522 ath_print(common, ATH_DBG_FATAL,
1523 "Failed to set channel\n");
1524 return false;
Sujithf1dc5602008-10-29 10:16:30 +05301525 }
1526
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001527 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001528 ath9k_regd_get_ctl(regulatory, chan),
Sujithf74df6f2009-02-09 13:27:24 +05301529 channel->max_antenna_gain * 2,
1530 channel->max_power * 2,
1531 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001532 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05301533
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001534 ath9k_hw_rfbus_done(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301535
1536 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1537 ath9k_hw_set_delta_slope(ah, chan);
1538
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001539 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301540
1541 if (!chan->oneTimeCalsDone)
1542 chan->oneTimeCalsDone = true;
1543
1544 return true;
1545}
1546
Sujithcbe61d82009-02-09 13:27:12 +05301547int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001548 bool bChannelChange)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001549{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001550 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001551 u32 saveLedState;
Sujith2660b812009-02-09 13:27:26 +05301552 struct ath9k_channel *curchan = ah->curchan;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001553 u32 saveDefAntenna;
1554 u32 macStaId1;
Sujith46fe7822009-09-17 09:25:25 +05301555 u64 tsf = 0;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001556 int i, r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001557
Luis R. Rodriguez43c27612009-09-13 21:07:07 -07001558 ah->txchainmask = common->tx_chainmask;
1559 ah->rxchainmask = common->rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001560
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001561 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001562 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001563
Vasanthakumar Thiagarajan9ebef792009-09-17 09:26:44 +05301564 if (curchan && !ah->chip_fullsleep)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001565 ath9k_hw_getnf(ah, curchan);
1566
1567 if (bChannelChange &&
Sujith2660b812009-02-09 13:27:26 +05301568 (ah->chip_fullsleep != true) &&
1569 (ah->curchan != NULL) &&
1570 (chan->channel != ah->curchan->channel) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001571 ((chan->channelFlags & CHANNEL_ALL) ==
Sujith2660b812009-02-09 13:27:26 +05301572 (ah->curchan->channelFlags & CHANNEL_ALL)) &&
Vasanthakumar Thiagarajan0a475cc2009-09-17 09:27:10 +05301573 !(AR_SREV_9280(ah) || IS_CHAN_A_5MHZ_SPACED(chan) ||
1574 IS_CHAN_A_5MHZ_SPACED(ah->curchan))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001575
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001576 if (ath9k_hw_channel_change(ah, chan)) {
Sujith2660b812009-02-09 13:27:26 +05301577 ath9k_hw_loadnf(ah, ah->curchan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001578 ath9k_hw_start_nfcal(ah);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001579 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001580 }
1581 }
1582
1583 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
1584 if (saveDefAntenna == 0)
1585 saveDefAntenna = 1;
1586
1587 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
1588
Sujith46fe7822009-09-17 09:25:25 +05301589 /* For chips on which RTC reset is done, save TSF before it gets cleared */
1590 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1591 tsf = ath9k_hw_gettsf64(ah);
1592
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001593 saveLedState = REG_READ(ah, AR_CFG_LED) &
1594 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
1595 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
1596
1597 ath9k_hw_mark_phy_inactive(ah);
1598
Sujith05020d22010-03-17 14:25:23 +05301599 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001600 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1601 REG_WRITE(ah,
1602 AR9271_RESET_POWER_DOWN_CONTROL,
1603 AR9271_RADIO_RF_RST);
1604 udelay(50);
1605 }
1606
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001607 if (!ath9k_hw_chip_reset(ah, chan)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001608 ath_print(common, ATH_DBG_FATAL, "Chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001609 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001610 }
1611
Sujith05020d22010-03-17 14:25:23 +05301612 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001613 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1614 ah->htc_reset_init = false;
1615 REG_WRITE(ah,
1616 AR9271_RESET_POWER_DOWN_CONTROL,
1617 AR9271_GATE_MAC_CTL);
1618 udelay(50);
1619 }
1620
Sujith46fe7822009-09-17 09:25:25 +05301621 /* Restore TSF */
1622 if (tsf && AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1623 ath9k_hw_settsf64(ah, tsf);
1624
Vasanthakumar Thiagarajan369391d2009-01-21 19:24:13 +05301625 if (AR_SREV_9280_10_OR_LATER(ah))
1626 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001627
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001628 r = ath9k_hw_process_ini(ah, chan);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001629 if (r)
1630 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001631
Jouni Malinen0ced0e12009-01-08 13:32:13 +02001632 /* Setup MFP options for CCMP */
1633 if (AR_SREV_9280_20_OR_LATER(ah)) {
1634 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
1635 * frames when constructing CCMP AAD. */
1636 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
1637 0xc7ff);
1638 ah->sw_mgmt_crypto = false;
1639 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1640 /* Disable hardware crypto for management frames */
1641 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
1642 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
1643 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1644 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
1645 ah->sw_mgmt_crypto = true;
1646 } else
1647 ah->sw_mgmt_crypto = true;
1648
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001649 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1650 ath9k_hw_set_delta_slope(ah, chan);
1651
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001652 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithd6509152009-03-13 08:56:05 +05301653 ah->eep_ops->set_board_values(ah, chan);
Luis R. Rodrigueza7765822009-10-19 02:33:45 -04001654
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001655 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
1656 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001657 | macStaId1
1658 | AR_STA_ID1_RTS_USE_DEF
Sujith2660b812009-02-09 13:27:26 +05301659 | (ah->config.
Sujith60b67f52008-08-07 10:52:38 +05301660 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Sujith2660b812009-02-09 13:27:26 +05301661 | ah->sta_id1_defaults);
1662 ath9k_hw_set_operating_mode(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001663
Luis R. Rodriguez13b81552009-09-10 17:52:45 -07001664 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001665
1666 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
1667
Luis R. Rodriguez3453ad82009-09-10 08:57:00 -07001668 ath9k_hw_write_associd(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001669
1670 REG_WRITE(ah, AR_ISR, ~0);
1671
1672 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
1673
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001674 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001675 if (r)
1676 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001677
1678 for (i = 0; i < AR_NUM_DCU; i++)
1679 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
1680
Sujith2660b812009-02-09 13:27:26 +05301681 ah->intr_txqs = 0;
1682 for (i = 0; i < ah->caps.total_queues; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001683 ath9k_hw_resettxqueue(ah, i);
1684
Sujith2660b812009-02-09 13:27:26 +05301685 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001686 ath9k_hw_init_qos(ah);
1687
Sujith2660b812009-02-09 13:27:26 +05301688 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301689 ath9k_enable_rfkill(ah);
Johannes Berg3b319aa2009-06-13 14:50:26 +05301690
Felix Fietkau0005baf2010-01-15 02:33:40 +01001691 ath9k_hw_init_global_settings(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001692
Vivek Natarajan326bebb2009-08-14 11:33:36 +05301693 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301694 REG_WRITE(ah, AR_D_GBL_IFS_SIFS,
1695 AR_D_GBL_IFS_SIFS_ASYNC_FIFO_DUR);
1696 REG_WRITE(ah, AR_D_GBL_IFS_SLOT,
1697 AR_D_GBL_IFS_SLOT_ASYNC_FIFO_DUR);
1698 REG_WRITE(ah, AR_D_GBL_IFS_EIFS,
1699 AR_D_GBL_IFS_EIFS_ASYNC_FIFO_DUR);
1700
1701 REG_WRITE(ah, AR_TIME_OUT, AR_TIME_OUT_ACK_CTS_ASYNC_FIFO_DUR);
1702 REG_WRITE(ah, AR_USEC, AR_USEC_ASYNC_FIFO_DUR);
1703
1704 REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
1705 AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
1706 REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
1707 AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
1708 }
Vivek Natarajan326bebb2009-08-14 11:33:36 +05301709 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301710 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1711 AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
1712 }
1713
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001714 REG_WRITE(ah, AR_STA_ID1,
1715 REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
1716
1717 ath9k_hw_set_dma(ah);
1718
1719 REG_WRITE(ah, AR_OBS, 8);
1720
Sujith0ce024c2009-12-14 14:57:00 +05301721 if (ah->config.rx_intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001722 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
1723 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
1724 }
1725
1726 ath9k_hw_init_bb(ah, chan);
1727
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001728 if (!ath9k_hw_init_cal(ah, chan))
Joe Perches6badaaf2009-06-28 09:26:32 -07001729 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001730
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001731 ath9k_hw_restore_chainmask(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001732 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
1733
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001734 /*
1735 * For big endian systems turn on swapping for descriptors
1736 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001737 if (AR_SREV_9100(ah)) {
1738 u32 mask;
1739 mask = REG_READ(ah, AR_CFG);
1740 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001741 ath_print(common, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05301742 "CFG Byte Swap Set 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001743 } else {
1744 mask =
1745 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
1746 REG_WRITE(ah, AR_CFG, mask);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001747 ath_print(common, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05301748 "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001749 }
1750 } else {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001751 /* Configure AR9271 target WLAN */
1752 if (AR_SREV_9271(ah))
1753 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001754#ifdef __BIG_ENDIAN
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001755 else
1756 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001757#endif
1758 }
1759
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001760 if (ah->btcoex_hw.enabled)
Vasanthakumar Thiagarajan42cc41e2009-08-26 21:08:45 +05301761 ath9k_hw_btcoex_enable(ah);
1762
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001763 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001764}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001765EXPORT_SYMBOL(ath9k_hw_reset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001766
Sujithf1dc5602008-10-29 10:16:30 +05301767/************************/
1768/* Key Cache Management */
1769/************************/
1770
Sujithcbe61d82009-02-09 13:27:12 +05301771bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001772{
Sujithf1dc5602008-10-29 10:16:30 +05301773 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001774
Sujith2660b812009-02-09 13:27:26 +05301775 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001776 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1777 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001778 return false;
1779 }
1780
Sujithf1dc5602008-10-29 10:16:30 +05301781 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001782
Sujithf1dc5602008-10-29 10:16:30 +05301783 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
1784 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
1785 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
1786 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
1787 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
1788 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
1789 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
1790 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
1791
1792 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
1793 u16 micentry = entry + 64;
1794
1795 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
1796 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
1797 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
1798 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
1799
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001800 }
1801
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001802 return true;
1803}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001804EXPORT_SYMBOL(ath9k_hw_keyreset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001805
Sujithcbe61d82009-02-09 13:27:12 +05301806bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001807{
Sujithf1dc5602008-10-29 10:16:30 +05301808 u32 macHi, macLo;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001809
Sujith2660b812009-02-09 13:27:26 +05301810 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001811 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1812 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001813 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001814 }
1815
Sujithf1dc5602008-10-29 10:16:30 +05301816 if (mac != NULL) {
1817 macHi = (mac[5] << 8) | mac[4];
1818 macLo = (mac[3] << 24) |
1819 (mac[2] << 16) |
1820 (mac[1] << 8) |
1821 mac[0];
1822 macLo >>= 1;
1823 macLo |= (macHi & 1) << 31;
1824 macHi >>= 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001825 } else {
Sujithf1dc5602008-10-29 10:16:30 +05301826 macLo = macHi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001827 }
Sujithf1dc5602008-10-29 10:16:30 +05301828 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
1829 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001830
1831 return true;
1832}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001833EXPORT_SYMBOL(ath9k_hw_keysetmac);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001834
Sujithcbe61d82009-02-09 13:27:12 +05301835bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
Sujithf1dc5602008-10-29 10:16:30 +05301836 const struct ath9k_keyval *k,
Jouni Malinene0caf9e2009-03-02 18:15:53 +02001837 const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001838{
Sujith2660b812009-02-09 13:27:26 +05301839 const struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001840 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301841 u32 key0, key1, key2, key3, key4;
1842 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001843
Sujithf1dc5602008-10-29 10:16:30 +05301844 if (entry >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001845 ath_print(common, ATH_DBG_FATAL,
1846 "keycache entry %u out of range\n", entry);
Sujithf1dc5602008-10-29 10:16:30 +05301847 return false;
1848 }
1849
1850 switch (k->kv_type) {
1851 case ATH9K_CIPHER_AES_OCB:
1852 keyType = AR_KEYTABLE_TYPE_AES;
1853 break;
1854 case ATH9K_CIPHER_AES_CCM:
1855 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001856 ath_print(common, ATH_DBG_ANY,
1857 "AES-CCM not supported by mac rev 0x%x\n",
1858 ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001859 return false;
1860 }
Sujithf1dc5602008-10-29 10:16:30 +05301861 keyType = AR_KEYTABLE_TYPE_CCM;
1862 break;
1863 case ATH9K_CIPHER_TKIP:
1864 keyType = AR_KEYTABLE_TYPE_TKIP;
1865 if (ATH9K_IS_MIC_ENABLED(ah)
1866 && entry + 64 >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001867 ath_print(common, ATH_DBG_ANY,
1868 "entry %u inappropriate for TKIP\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001869 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001870 }
Sujithf1dc5602008-10-29 10:16:30 +05301871 break;
1872 case ATH9K_CIPHER_WEP:
Zhu Yie31a16d2009-05-21 21:47:03 +08001873 if (k->kv_len < WLAN_KEY_LEN_WEP40) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001874 ath_print(common, ATH_DBG_ANY,
1875 "WEP key length %u too small\n", k->kv_len);
Sujithf1dc5602008-10-29 10:16:30 +05301876 return false;
1877 }
Zhu Yie31a16d2009-05-21 21:47:03 +08001878 if (k->kv_len <= WLAN_KEY_LEN_WEP40)
Sujithf1dc5602008-10-29 10:16:30 +05301879 keyType = AR_KEYTABLE_TYPE_40;
Zhu Yie31a16d2009-05-21 21:47:03 +08001880 else if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05301881 keyType = AR_KEYTABLE_TYPE_104;
1882 else
1883 keyType = AR_KEYTABLE_TYPE_128;
1884 break;
1885 case ATH9K_CIPHER_CLR:
1886 keyType = AR_KEYTABLE_TYPE_CLR;
1887 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001888 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001889 ath_print(common, ATH_DBG_FATAL,
1890 "cipher %u not supported\n", k->kv_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001891 return false;
1892 }
Sujithf1dc5602008-10-29 10:16:30 +05301893
Jouni Malinene0caf9e2009-03-02 18:15:53 +02001894 key0 = get_unaligned_le32(k->kv_val + 0);
1895 key1 = get_unaligned_le16(k->kv_val + 4);
1896 key2 = get_unaligned_le32(k->kv_val + 6);
1897 key3 = get_unaligned_le16(k->kv_val + 10);
1898 key4 = get_unaligned_le32(k->kv_val + 12);
Zhu Yie31a16d2009-05-21 21:47:03 +08001899 if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05301900 key4 &= 0xff;
1901
Jouni Malinen672903b2009-03-02 15:06:31 +02001902 /*
1903 * Note: Key cache registers access special memory area that requires
1904 * two 32-bit writes to actually update the values in the internal
1905 * memory. Consequently, the exact order and pairs used here must be
1906 * maintained.
1907 */
1908
Sujithf1dc5602008-10-29 10:16:30 +05301909 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
1910 u16 micentry = entry + 64;
1911
Jouni Malinen672903b2009-03-02 15:06:31 +02001912 /*
1913 * Write inverted key[47:0] first to avoid Michael MIC errors
1914 * on frames that could be sent or received at the same time.
1915 * The correct key will be written in the end once everything
1916 * else is ready.
1917 */
Sujithf1dc5602008-10-29 10:16:30 +05301918 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
1919 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02001920
1921 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05301922 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
1923 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02001924
1925 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05301926 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
1927 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
Jouni Malinen672903b2009-03-02 15:06:31 +02001928
1929 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05301930 (void) ath9k_hw_keysetmac(ah, entry, mac);
1931
Sujith2660b812009-02-09 13:27:26 +05301932 if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) {
Jouni Malinen672903b2009-03-02 15:06:31 +02001933 /*
1934 * TKIP uses two key cache entries:
1935 * Michael MIC TX/RX keys in the same key cache entry
1936 * (idx = main index + 64):
1937 * key0 [31:0] = RX key [31:0]
1938 * key1 [15:0] = TX key [31:16]
1939 * key1 [31:16] = reserved
1940 * key2 [31:0] = RX key [63:32]
1941 * key3 [15:0] = TX key [15:0]
1942 * key3 [31:16] = reserved
1943 * key4 [31:0] = TX key [63:32]
1944 */
Sujithf1dc5602008-10-29 10:16:30 +05301945 u32 mic0, mic1, mic2, mic3, mic4;
1946
1947 mic0 = get_unaligned_le32(k->kv_mic + 0);
1948 mic2 = get_unaligned_le32(k->kv_mic + 4);
1949 mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
1950 mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
1951 mic4 = get_unaligned_le32(k->kv_txmic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02001952
1953 /* Write RX[31:0] and TX[31:16] */
Sujithf1dc5602008-10-29 10:16:30 +05301954 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
1955 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
Jouni Malinen672903b2009-03-02 15:06:31 +02001956
1957 /* Write RX[63:32] and TX[15:0] */
Sujithf1dc5602008-10-29 10:16:30 +05301958 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
1959 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
Jouni Malinen672903b2009-03-02 15:06:31 +02001960
1961 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05301962 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
1963 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
1964 AR_KEYTABLE_TYPE_CLR);
1965
1966 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02001967 /*
1968 * TKIP uses four key cache entries (two for group
1969 * keys):
1970 * Michael MIC TX/RX keys are in different key cache
1971 * entries (idx = main index + 64 for TX and
1972 * main index + 32 + 96 for RX):
1973 * key0 [31:0] = TX/RX MIC key [31:0]
1974 * key1 [31:0] = reserved
1975 * key2 [31:0] = TX/RX MIC key [63:32]
1976 * key3 [31:0] = reserved
1977 * key4 [31:0] = reserved
1978 *
1979 * Upper layer code will call this function separately
1980 * for TX and RX keys when these registers offsets are
1981 * used.
1982 */
Sujithf1dc5602008-10-29 10:16:30 +05301983 u32 mic0, mic2;
1984
1985 mic0 = get_unaligned_le32(k->kv_mic + 0);
1986 mic2 = get_unaligned_le32(k->kv_mic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02001987
1988 /* Write MIC key[31:0] */
Sujithf1dc5602008-10-29 10:16:30 +05301989 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
1990 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02001991
1992 /* Write MIC key[63:32] */
Sujithf1dc5602008-10-29 10:16:30 +05301993 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
1994 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02001995
1996 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05301997 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
1998 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
1999 AR_KEYTABLE_TYPE_CLR);
2000 }
Jouni Malinen672903b2009-03-02 15:06:31 +02002001
2002 /* MAC address registers are reserved for the MIC entry */
Sujithf1dc5602008-10-29 10:16:30 +05302003 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
2004 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002005
2006 /*
2007 * Write the correct (un-inverted) key[47:0] last to enable
2008 * TKIP now that all other registers are set with correct
2009 * values.
2010 */
Sujithf1dc5602008-10-29 10:16:30 +05302011 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2012 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
2013 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002014 /* Write key[47:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302015 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2016 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002017
2018 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302019 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2020 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002021
2022 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302023 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2024 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
2025
Jouni Malinen672903b2009-03-02 15:06:31 +02002026 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302027 (void) ath9k_hw_keysetmac(ah, entry, mac);
2028 }
2029
Sujithf1dc5602008-10-29 10:16:30 +05302030 return true;
2031}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002032EXPORT_SYMBOL(ath9k_hw_set_keycache_entry);
Sujithf1dc5602008-10-29 10:16:30 +05302033
Sujithcbe61d82009-02-09 13:27:12 +05302034bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry)
Sujithf1dc5602008-10-29 10:16:30 +05302035{
Sujith2660b812009-02-09 13:27:26 +05302036 if (entry < ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05302037 u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
2038 if (val & AR_KEYTABLE_VALID)
2039 return true;
2040 }
2041 return false;
2042}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002043EXPORT_SYMBOL(ath9k_hw_keyisvalid);
Sujithf1dc5602008-10-29 10:16:30 +05302044
2045/******************************/
2046/* Power Management (Chipset) */
2047/******************************/
2048
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04002049/*
2050 * Notify Power Mgt is disabled in self-generated frames.
2051 * If requested, force chip to sleep.
2052 */
Sujithcbe61d82009-02-09 13:27:12 +05302053static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302054{
2055 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2056 if (setChip) {
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04002057 /*
2058 * Clear the RTC force wake bit to allow the
2059 * mac to go to sleep.
2060 */
Sujithf1dc5602008-10-29 10:16:30 +05302061 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2062 AR_RTC_FORCE_WAKE_EN);
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04002063 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302064 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
2065
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04002066 /* Shutdown chip. Active low */
Sujith14b3af32010-03-17 14:25:18 +05302067 if (!AR_SREV_5416(ah) && !AR_SREV_9271(ah))
Sujith4921be82009-09-18 15:04:27 +05302068 REG_CLR_BIT(ah, (AR_RTC_RESET),
2069 AR_RTC_RESET_EN);
Sujithf1dc5602008-10-29 10:16:30 +05302070 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002071}
2072
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04002073/*
2074 * Notify Power Management is enabled in self-generating
2075 * frames. If request, set power mode of chip to
2076 * auto/normal. Duration in units of 128us (1/8 TU).
2077 */
Sujithcbe61d82009-02-09 13:27:12 +05302078static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002079{
Sujithf1dc5602008-10-29 10:16:30 +05302080 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2081 if (setChip) {
Sujith2660b812009-02-09 13:27:26 +05302082 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002083
Sujithf1dc5602008-10-29 10:16:30 +05302084 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04002085 /* Set WakeOnInterrupt bit; clear ForceWake bit */
Sujithf1dc5602008-10-29 10:16:30 +05302086 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2087 AR_RTC_FORCE_WAKE_ON_INT);
2088 } else {
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04002089 /*
2090 * Clear the RTC force wake bit to allow the
2091 * mac to go to sleep.
2092 */
Sujithf1dc5602008-10-29 10:16:30 +05302093 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2094 AR_RTC_FORCE_WAKE_EN);
2095 }
2096 }
2097}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002098
Sujithcbe61d82009-02-09 13:27:12 +05302099static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302100{
2101 u32 val;
2102 int i;
2103
2104 if (setChip) {
2105 if ((REG_READ(ah, AR_RTC_STATUS) &
2106 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2107 if (ath9k_hw_set_reset_reg(ah,
2108 ATH9K_RESET_POWER_ON) != true) {
2109 return false;
2110 }
Luis R. Rodrigueze0412282010-04-15 17:38:15 -04002111 if (!AR_SREV_9300_20_OR_LATER(ah))
2112 ath9k_hw_init_pll(ah, NULL);
Sujithf1dc5602008-10-29 10:16:30 +05302113 }
2114 if (AR_SREV_9100(ah))
2115 REG_SET_BIT(ah, AR_RTC_RESET,
2116 AR_RTC_RESET_EN);
2117
2118 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2119 AR_RTC_FORCE_WAKE_EN);
2120 udelay(50);
2121
2122 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2123 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2124 if (val == AR_RTC_STATUS_ON)
2125 break;
2126 udelay(50);
2127 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2128 AR_RTC_FORCE_WAKE_EN);
2129 }
2130 if (i == 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002131 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2132 "Failed to wakeup in %uus\n",
2133 POWER_UP_TIME / 20);
Sujithf1dc5602008-10-29 10:16:30 +05302134 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002135 }
2136 }
2137
Sujithf1dc5602008-10-29 10:16:30 +05302138 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2139
2140 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002141}
2142
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002143bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05302144{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002145 struct ath_common *common = ath9k_hw_common(ah);
Sujithcbe61d82009-02-09 13:27:12 +05302146 int status = true, setChip = true;
Sujithf1dc5602008-10-29 10:16:30 +05302147 static const char *modes[] = {
2148 "AWAKE",
2149 "FULL-SLEEP",
2150 "NETWORK SLEEP",
2151 "UNDEFINED"
2152 };
Sujithf1dc5602008-10-29 10:16:30 +05302153
Gabor Juhoscbdec972009-07-24 17:27:22 +02002154 if (ah->power_mode == mode)
2155 return status;
2156
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002157 ath_print(common, ATH_DBG_RESET, "%s -> %s\n",
2158 modes[ah->power_mode], modes[mode]);
Sujithf1dc5602008-10-29 10:16:30 +05302159
2160 switch (mode) {
2161 case ATH9K_PM_AWAKE:
2162 status = ath9k_hw_set_power_awake(ah, setChip);
2163 break;
2164 case ATH9K_PM_FULL_SLEEP:
2165 ath9k_set_power_sleep(ah, setChip);
Sujith2660b812009-02-09 13:27:26 +05302166 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05302167 break;
2168 case ATH9K_PM_NETWORK_SLEEP:
2169 ath9k_set_power_network_sleep(ah, setChip);
2170 break;
2171 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002172 ath_print(common, ATH_DBG_FATAL,
2173 "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05302174 return false;
2175 }
Sujith2660b812009-02-09 13:27:26 +05302176 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05302177
2178 return status;
2179}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002180EXPORT_SYMBOL(ath9k_hw_setpower);
Sujithf1dc5602008-10-29 10:16:30 +05302181
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002182/*
2183 * Helper for ASPM support.
2184 *
2185 * Disable PLL when in L0s as well as receiver clock when in L1.
2186 * This power saving option must be enabled through the SerDes.
2187 *
2188 * Programming the SerDes must go through the same 288 bit serial shift
2189 * register as the other analog registers. Hence the 9 writes.
2190 */
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04002191static void ar9002_hw_configpcipowersave(struct ath_hw *ah,
2192 int restore,
2193 int power_off)
Sujithf1dc5602008-10-29 10:16:30 +05302194{
Sujithf1dc5602008-10-29 10:16:30 +05302195 u8 i;
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302196 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05302197
Sujith2660b812009-02-09 13:27:26 +05302198 if (ah->is_pciexpress != true)
Sujithf1dc5602008-10-29 10:16:30 +05302199 return;
2200
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002201 /* Do not touch SerDes registers */
Sujith2660b812009-02-09 13:27:26 +05302202 if (ah->config.pcie_powersave_enable == 2)
Sujithf1dc5602008-10-29 10:16:30 +05302203 return;
2204
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002205 /* Nothing to do on restore for 11N */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302206 if (!restore) {
2207 if (AR_SREV_9280_20_OR_LATER(ah)) {
2208 /*
2209 * AR9280 2.0 or later chips use SerDes values from the
2210 * initvals.h initialized depending on chipset during
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04002211 * __ath9k_hw_init()
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302212 */
2213 for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
2214 REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
2215 INI_RA(&ah->iniPcieSerdes, i, 1));
2216 }
2217 } else if (AR_SREV_9280(ah) &&
2218 (ah->hw_version.macRev == AR_SREV_REVISION_9280_10)) {
2219 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
2220 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
Sujithf1dc5602008-10-29 10:16:30 +05302221
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302222 /* RX shut off when elecidle is asserted */
2223 REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
2224 REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
2225 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
2226
2227 /* Shut off CLKREQ active in L1 */
2228 if (ah->config.pcie_clock_req)
2229 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
2230 else
2231 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
2232
2233 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2234 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2235 REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
2236
2237 /* Load the new settings */
2238 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
2239
2240 } else {
2241 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
2242 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
2243
2244 /* RX shut off when elecidle is asserted */
2245 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
2246 REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
2247 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
2248
2249 /*
2250 * Ignore ah->ah_config.pcie_clock_req setting for
2251 * pre-AR9280 11n
2252 */
2253 REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
2254
2255 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2256 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2257 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
2258
2259 /* Load the new settings */
2260 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
Sujithf1dc5602008-10-29 10:16:30 +05302261 }
Sujithf1dc5602008-10-29 10:16:30 +05302262
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302263 udelay(1000);
Sujithf1dc5602008-10-29 10:16:30 +05302264
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302265 /* set bit 19 to allow forcing of pcie core into L1 state */
2266 REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
Sujithf1dc5602008-10-29 10:16:30 +05302267
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302268 /* Several PCIe massages to ensure proper behaviour */
2269 if (ah->config.pcie_waen) {
2270 val = ah->config.pcie_waen;
2271 if (!power_off)
2272 val &= (~AR_WA_D3_L1_DISABLE);
2273 } else {
2274 if (AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
2275 AR_SREV_9287(ah)) {
2276 val = AR9285_WA_DEFAULT;
2277 if (!power_off)
2278 val &= (~AR_WA_D3_L1_DISABLE);
2279 } else if (AR_SREV_9280(ah)) {
2280 /*
2281 * On AR9280 chips bit 22 of 0x4004 needs to be
2282 * set otherwise card may disappear.
2283 */
2284 val = AR9280_WA_DEFAULT;
2285 if (!power_off)
2286 val &= (~AR_WA_D3_L1_DISABLE);
2287 } else
2288 val = AR_WA_DEFAULT;
2289 }
Sujithf1dc5602008-10-29 10:16:30 +05302290
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302291 REG_WRITE(ah, AR_WA, val);
Sujithf1dc5602008-10-29 10:16:30 +05302292 }
2293
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302294 if (power_off) {
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002295 /*
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302296 * Set PCIe workaround bits
2297 * bit 14 in WA register (disable L1) should only
2298 * be set when device enters D3 and be cleared
2299 * when device comes back to D0.
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002300 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302301 if (ah->config.pcie_waen) {
2302 if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE)
2303 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
2304 } else {
2305 if (((AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
2306 AR_SREV_9287(ah)) &&
2307 (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)) ||
2308 (AR_SREV_9280(ah) &&
2309 (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE))) {
2310 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
2311 }
2312 }
Sujithf1dc5602008-10-29 10:16:30 +05302313 }
2314}
2315
2316/**********************/
2317/* Interrupt Handling */
2318/**********************/
2319
Sujithcbe61d82009-02-09 13:27:12 +05302320bool ath9k_hw_intrpend(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002321{
2322 u32 host_isr;
2323
2324 if (AR_SREV_9100(ah))
2325 return true;
2326
2327 host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
2328 if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
2329 return true;
2330
2331 host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
2332 if ((host_isr & AR_INTR_SYNC_DEFAULT)
2333 && (host_isr != AR_INTR_SPURIOUS))
2334 return true;
2335
2336 return false;
2337}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002338EXPORT_SYMBOL(ath9k_hw_intrpend);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002339
Sujithcbe61d82009-02-09 13:27:12 +05302340bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002341{
2342 u32 isr = 0;
2343 u32 mask2 = 0;
Sujith2660b812009-02-09 13:27:26 +05302344 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002345 u32 sync_cause = 0;
2346 bool fatal_int = false;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002347 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002348
2349 if (!AR_SREV_9100(ah)) {
2350 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
2351 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
2352 == AR_RTC_STATUS_ON) {
2353 isr = REG_READ(ah, AR_ISR);
2354 }
2355 }
2356
Sujithf1dc5602008-10-29 10:16:30 +05302357 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
2358 AR_INTR_SYNC_DEFAULT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002359
2360 *masked = 0;
2361
2362 if (!isr && !sync_cause)
2363 return false;
2364 } else {
2365 *masked = 0;
2366 isr = REG_READ(ah, AR_ISR);
2367 }
2368
2369 if (isr) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002370 if (isr & AR_ISR_BCNMISC) {
2371 u32 isr2;
2372 isr2 = REG_READ(ah, AR_ISR_S2);
2373 if (isr2 & AR_ISR_S2_TIM)
2374 mask2 |= ATH9K_INT_TIM;
2375 if (isr2 & AR_ISR_S2_DTIM)
2376 mask2 |= ATH9K_INT_DTIM;
2377 if (isr2 & AR_ISR_S2_DTIMSYNC)
2378 mask2 |= ATH9K_INT_DTIMSYNC;
2379 if (isr2 & (AR_ISR_S2_CABEND))
2380 mask2 |= ATH9K_INT_CABEND;
2381 if (isr2 & AR_ISR_S2_GTT)
2382 mask2 |= ATH9K_INT_GTT;
2383 if (isr2 & AR_ISR_S2_CST)
2384 mask2 |= ATH9K_INT_CST;
Sujith4af9cf42009-02-12 10:06:47 +05302385 if (isr2 & AR_ISR_S2_TSFOOR)
2386 mask2 |= ATH9K_INT_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002387 }
2388
2389 isr = REG_READ(ah, AR_ISR_RAC);
2390 if (isr == 0xffffffff) {
2391 *masked = 0;
2392 return false;
2393 }
2394
2395 *masked = isr & ATH9K_INT_COMMON;
2396
Sujith0ce024c2009-12-14 14:57:00 +05302397 if (ah->config.rx_intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002398 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
2399 *masked |= ATH9K_INT_RX;
2400 }
2401
2402 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
2403 *masked |= ATH9K_INT_RX;
2404 if (isr &
2405 (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
2406 AR_ISR_TXEOL)) {
2407 u32 s0_s, s1_s;
2408
2409 *masked |= ATH9K_INT_TX;
2410
2411 s0_s = REG_READ(ah, AR_ISR_S0_S);
Sujith2660b812009-02-09 13:27:26 +05302412 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
2413 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002414
2415 s1_s = REG_READ(ah, AR_ISR_S1_S);
Sujith2660b812009-02-09 13:27:26 +05302416 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
2417 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002418 }
2419
2420 if (isr & AR_ISR_RXORN) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002421 ath_print(common, ATH_DBG_INTERRUPT,
2422 "receive FIFO overrun interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002423 }
2424
2425 if (!AR_SREV_9100(ah)) {
Sujith60b67f52008-08-07 10:52:38 +05302426 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002427 u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
2428 if (isr5 & AR_ISR_S5_TIM_TIMER)
2429 *masked |= ATH9K_INT_TIM_TIMER;
2430 }
2431 }
2432
2433 *masked |= mask2;
2434 }
Sujithf1dc5602008-10-29 10:16:30 +05302435
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002436 if (AR_SREV_9100(ah))
2437 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302438
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302439 if (isr & AR_ISR_GENTMR) {
2440 u32 s5_s;
2441
2442 s5_s = REG_READ(ah, AR_ISR_S5_S);
2443 if (isr & AR_ISR_GENTMR) {
2444 ah->intr_gen_timer_trigger =
2445 MS(s5_s, AR_ISR_S5_GENTIMER_TRIG);
2446
2447 ah->intr_gen_timer_thresh =
2448 MS(s5_s, AR_ISR_S5_GENTIMER_THRESH);
2449
2450 if (ah->intr_gen_timer_trigger)
2451 *masked |= ATH9K_INT_GENTIMER;
2452
2453 }
2454 }
2455
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002456 if (sync_cause) {
2457 fatal_int =
2458 (sync_cause &
2459 (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
2460 ? true : false;
2461
2462 if (fatal_int) {
2463 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002464 ath_print(common, ATH_DBG_ANY,
2465 "received PCI FATAL interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002466 }
2467 if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002468 ath_print(common, ATH_DBG_ANY,
2469 "received PCI PERR interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002470 }
Steven Luoa89bff92009-04-12 02:57:54 -07002471 *masked |= ATH9K_INT_FATAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002472 }
2473 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002474 ath_print(common, ATH_DBG_INTERRUPT,
2475 "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002476 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
2477 REG_WRITE(ah, AR_RC, 0);
2478 *masked |= ATH9K_INT_FATAL;
2479 }
2480 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002481 ath_print(common, ATH_DBG_INTERRUPT,
2482 "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002483 }
2484
2485 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
2486 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
2487 }
Sujithf1dc5602008-10-29 10:16:30 +05302488
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002489 return true;
2490}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002491EXPORT_SYMBOL(ath9k_hw_getisr);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002492
Sujithcbe61d82009-02-09 13:27:12 +05302493enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002494{
Pavel Roskin152d5302010-03-31 18:05:37 -04002495 enum ath9k_int omask = ah->imask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002496 u32 mask, mask2;
Sujith2660b812009-02-09 13:27:26 +05302497 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002498 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002499
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002500 ath_print(common, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002501
2502 if (omask & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002503 ath_print(common, ATH_DBG_INTERRUPT, "disable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002504 REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
2505 (void) REG_READ(ah, AR_IER);
2506 if (!AR_SREV_9100(ah)) {
2507 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
2508 (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
2509
2510 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
2511 (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
2512 }
2513 }
2514
2515 mask = ints & ATH9K_INT_COMMON;
2516 mask2 = 0;
2517
2518 if (ints & ATH9K_INT_TX) {
Sujith2660b812009-02-09 13:27:26 +05302519 if (ah->txok_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002520 mask |= AR_IMR_TXOK;
Sujith2660b812009-02-09 13:27:26 +05302521 if (ah->txdesc_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002522 mask |= AR_IMR_TXDESC;
Sujith2660b812009-02-09 13:27:26 +05302523 if (ah->txerr_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002524 mask |= AR_IMR_TXERR;
Sujith2660b812009-02-09 13:27:26 +05302525 if (ah->txeol_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002526 mask |= AR_IMR_TXEOL;
2527 }
2528 if (ints & ATH9K_INT_RX) {
2529 mask |= AR_IMR_RXERR;
Sujith0ce024c2009-12-14 14:57:00 +05302530 if (ah->config.rx_intr_mitigation)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002531 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
2532 else
2533 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
Sujith60b67f52008-08-07 10:52:38 +05302534 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002535 mask |= AR_IMR_GENTMR;
2536 }
2537
2538 if (ints & (ATH9K_INT_BMISC)) {
2539 mask |= AR_IMR_BCNMISC;
2540 if (ints & ATH9K_INT_TIM)
2541 mask2 |= AR_IMR_S2_TIM;
2542 if (ints & ATH9K_INT_DTIM)
2543 mask2 |= AR_IMR_S2_DTIM;
2544 if (ints & ATH9K_INT_DTIMSYNC)
2545 mask2 |= AR_IMR_S2_DTIMSYNC;
2546 if (ints & ATH9K_INT_CABEND)
Sujith4af9cf42009-02-12 10:06:47 +05302547 mask2 |= AR_IMR_S2_CABEND;
2548 if (ints & ATH9K_INT_TSFOOR)
2549 mask2 |= AR_IMR_S2_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002550 }
2551
2552 if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
2553 mask |= AR_IMR_BCNMISC;
2554 if (ints & ATH9K_INT_GTT)
2555 mask2 |= AR_IMR_S2_GTT;
2556 if (ints & ATH9K_INT_CST)
2557 mask2 |= AR_IMR_S2_CST;
2558 }
2559
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002560 ath_print(common, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002561 REG_WRITE(ah, AR_IMR, mask);
Pavel Roskin74bad5c2010-02-23 18:15:27 -05002562 ah->imrs2_reg &= ~(AR_IMR_S2_TIM | AR_IMR_S2_DTIM | AR_IMR_S2_DTIMSYNC |
2563 AR_IMR_S2_CABEND | AR_IMR_S2_CABTO |
2564 AR_IMR_S2_TSFOOR | AR_IMR_S2_GTT | AR_IMR_S2_CST);
2565 ah->imrs2_reg |= mask2;
2566 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002567
Sujith60b67f52008-08-07 10:52:38 +05302568 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002569 if (ints & ATH9K_INT_TIM_TIMER)
2570 REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
2571 else
2572 REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
2573 }
2574
2575 if (ints & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002576 ath_print(common, ATH_DBG_INTERRUPT, "enable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002577 REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
2578 if (!AR_SREV_9100(ah)) {
2579 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
2580 AR_INTR_MAC_IRQ);
2581 REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
2582
2583
2584 REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
2585 AR_INTR_SYNC_DEFAULT);
2586 REG_WRITE(ah, AR_INTR_SYNC_MASK,
2587 AR_INTR_SYNC_DEFAULT);
2588 }
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002589 ath_print(common, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
2590 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002591 }
2592
2593 return omask;
2594}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002595EXPORT_SYMBOL(ath9k_hw_set_interrupts);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002596
Sujithf1dc5602008-10-29 10:16:30 +05302597/*******************/
2598/* Beacon Handling */
2599/*******************/
2600
Sujithcbe61d82009-02-09 13:27:12 +05302601void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002602{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002603 int flags = 0;
2604
Sujith2660b812009-02-09 13:27:26 +05302605 ah->beacon_interval = beacon_period;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002606
Sujith2660b812009-02-09 13:27:26 +05302607 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08002608 case NL80211_IFTYPE_STATION:
2609 case NL80211_IFTYPE_MONITOR:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002610 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
2611 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
2612 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
2613 flags |= AR_TBTT_TIMER_EN;
2614 break;
Colin McCabed97809d2008-12-01 13:38:55 -08002615 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04002616 case NL80211_IFTYPE_MESH_POINT:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002617 REG_SET_BIT(ah, AR_TXCFG,
2618 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
2619 REG_WRITE(ah, AR_NEXT_NDP_TIMER,
2620 TU_TO_USEC(next_beacon +
Sujith2660b812009-02-09 13:27:26 +05302621 (ah->atim_window ? ah->
2622 atim_window : 1)));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002623 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08002624 case NL80211_IFTYPE_AP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002625 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
2626 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
2627 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05302628 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302629 dma_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002630 REG_WRITE(ah, AR_NEXT_SWBA,
2631 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05302632 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302633 sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002634 flags |=
2635 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
2636 break;
Colin McCabed97809d2008-12-01 13:38:55 -08002637 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002638 ath_print(ath9k_hw_common(ah), ATH_DBG_BEACON,
2639 "%s: unsupported opmode: %d\n",
2640 __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08002641 return;
2642 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002643 }
2644
2645 REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
2646 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
2647 REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
2648 REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
2649
2650 beacon_period &= ~ATH9K_BEACON_ENA;
2651 if (beacon_period & ATH9K_BEACON_RESET_TSF) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002652 ath9k_hw_reset_tsf(ah);
2653 }
2654
2655 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
2656}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002657EXPORT_SYMBOL(ath9k_hw_beaconinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002658
Sujithcbe61d82009-02-09 13:27:12 +05302659void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05302660 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002661{
2662 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05302663 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002664 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002665
2666 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
2667
2668 REG_WRITE(ah, AR_BEACON_PERIOD,
2669 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
2670 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
2671 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
2672
2673 REG_RMW_FIELD(ah, AR_RSSI_THR,
2674 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
2675
2676 beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
2677
2678 if (bs->bs_sleepduration > beaconintval)
2679 beaconintval = bs->bs_sleepduration;
2680
2681 dtimperiod = bs->bs_dtimperiod;
2682 if (bs->bs_sleepduration > dtimperiod)
2683 dtimperiod = bs->bs_sleepduration;
2684
2685 if (beaconintval == dtimperiod)
2686 nextTbtt = bs->bs_nextdtim;
2687 else
2688 nextTbtt = bs->bs_nexttbtt;
2689
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002690 ath_print(common, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
2691 ath_print(common, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
2692 ath_print(common, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
2693 ath_print(common, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002694
2695 REG_WRITE(ah, AR_NEXT_DTIM,
2696 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
2697 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
2698
2699 REG_WRITE(ah, AR_SLEEP1,
2700 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
2701 | AR_SLEEP1_ASSUME_DTIM);
2702
Sujith60b67f52008-08-07 10:52:38 +05302703 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002704 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
2705 else
2706 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
2707
2708 REG_WRITE(ah, AR_SLEEP2,
2709 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
2710
2711 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
2712 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
2713
2714 REG_SET_BIT(ah, AR_TIMER_MODE,
2715 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
2716 AR_DTIM_TIMER_EN);
2717
Sujith4af9cf42009-02-12 10:06:47 +05302718 /* TSF Out of Range Threshold */
2719 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002720}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002721EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002722
Sujithf1dc5602008-10-29 10:16:30 +05302723/*******************/
2724/* HW Capabilities */
2725/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002726
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002727int ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002728{
Sujith2660b812009-02-09 13:27:26 +05302729 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002730 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002731 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002732 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002733
Sujithf1dc5602008-10-29 10:16:30 +05302734 u16 capField = 0, eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002735
Sujithf74df6f2009-02-09 13:27:24 +05302736 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002737 regulatory->current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05302738
Sujithf74df6f2009-02-09 13:27:24 +05302739 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
Sujithfec0de12009-02-12 10:06:43 +05302740 if (AR_SREV_9285_10_OR_LATER(ah))
2741 eeval |= AR9285_RDEXT_DEFAULT;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002742 regulatory->current_rd_ext = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05302743
Sujithf74df6f2009-02-09 13:27:24 +05302744 capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
Sujithf1dc5602008-10-29 10:16:30 +05302745
Sujith2660b812009-02-09 13:27:26 +05302746 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05302747 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002748 if (regulatory->current_rd == 0x64 ||
2749 regulatory->current_rd == 0x65)
2750 regulatory->current_rd += 5;
2751 else if (regulatory->current_rd == 0x41)
2752 regulatory->current_rd = 0x43;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002753 ath_print(common, ATH_DBG_REGULATORY,
2754 "regdomain mapped to 0x%x\n", regulatory->current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002755 }
Sujithdc2222a2008-08-14 13:26:55 +05302756
Sujithf74df6f2009-02-09 13:27:24 +05302757 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002758 if ((eeval & (AR5416_OPFLAGS_11G | AR5416_OPFLAGS_11A)) == 0) {
2759 ath_print(common, ATH_DBG_FATAL,
2760 "no band has been marked as supported in EEPROM.\n");
2761 return -EINVAL;
2762 }
2763
Sujithf1dc5602008-10-29 10:16:30 +05302764 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002765
Sujithf1dc5602008-10-29 10:16:30 +05302766 if (eeval & AR5416_OPFLAGS_11A) {
2767 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05302768 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05302769 if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
2770 set_bit(ATH9K_MODE_11NA_HT20,
2771 pCap->wireless_modes);
2772 if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
2773 set_bit(ATH9K_MODE_11NA_HT40PLUS,
2774 pCap->wireless_modes);
2775 set_bit(ATH9K_MODE_11NA_HT40MINUS,
2776 pCap->wireless_modes);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002777 }
2778 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002779 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002780
Sujithf1dc5602008-10-29 10:16:30 +05302781 if (eeval & AR5416_OPFLAGS_11G) {
Sujithf1dc5602008-10-29 10:16:30 +05302782 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05302783 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05302784 if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
2785 set_bit(ATH9K_MODE_11NG_HT20,
2786 pCap->wireless_modes);
2787 if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
2788 set_bit(ATH9K_MODE_11NG_HT40PLUS,
2789 pCap->wireless_modes);
2790 set_bit(ATH9K_MODE_11NG_HT40MINUS,
2791 pCap->wireless_modes);
2792 }
2793 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002794 }
Sujithf1dc5602008-10-29 10:16:30 +05302795
Sujithf74df6f2009-02-09 13:27:24 +05302796 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002797 /*
2798 * For AR9271 we will temporarilly uses the rx chainmax as read from
2799 * the EEPROM.
2800 */
Sujith8147f5d2009-02-20 15:13:23 +05302801 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002802 !(eeval & AR5416_OPFLAGS_11A) &&
2803 !(AR_SREV_9271(ah)))
2804 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
Sujith8147f5d2009-02-20 15:13:23 +05302805 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
2806 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002807 /* Use rx_chainmask from EEPROM. */
Sujith8147f5d2009-02-20 15:13:23 +05302808 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05302809
Sujithd535a422009-02-09 13:27:06 +05302810 if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0)))
Sujith2660b812009-02-09 13:27:26 +05302811 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05302812
2813 pCap->low_2ghz_chan = 2312;
2814 pCap->high_2ghz_chan = 2732;
2815
2816 pCap->low_5ghz_chan = 4920;
2817 pCap->high_5ghz_chan = 6100;
2818
2819 pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
2820 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
2821 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
2822
2823 pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
2824 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
2825 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
2826
Sujith2660b812009-02-09 13:27:26 +05302827 if (ah->config.ht_enable)
Sujithf1dc5602008-10-29 10:16:30 +05302828 pCap->hw_caps |= ATH9K_HW_CAP_HT;
2829 else
2830 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
2831
2832 pCap->hw_caps |= ATH9K_HW_CAP_GTT;
2833 pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
2834 pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
2835 pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
2836
2837 if (capField & AR_EEPROM_EEPCAP_MAXQCU)
2838 pCap->total_queues =
2839 MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
2840 else
2841 pCap->total_queues = ATH9K_NUM_TX_QUEUES;
2842
2843 if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
2844 pCap->keycache_size =
2845 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
2846 else
2847 pCap->keycache_size = AR_KEYTABLE_SIZE;
2848
2849 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -05002850
2851 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
2852 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD >> 1;
2853 else
2854 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
Sujithf1dc5602008-10-29 10:16:30 +05302855
Sujith5b5fa352010-03-17 14:25:15 +05302856 if (AR_SREV_9271(ah))
2857 pCap->num_gpio_pins = AR9271_NUM_GPIO;
2858 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302859 pCap->num_gpio_pins = AR9285_NUM_GPIO;
2860 else if (AR_SREV_9280_10_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302861 pCap->num_gpio_pins = AR928X_NUM_GPIO;
2862 else
2863 pCap->num_gpio_pins = AR_NUM_GPIO;
2864
Sujithf1dc5602008-10-29 10:16:30 +05302865 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
2866 pCap->hw_caps |= ATH9K_HW_CAP_CST;
2867 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
2868 } else {
2869 pCap->rts_aggr_limit = (8 * 1024);
2870 }
2871
2872 pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
2873
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05302874#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05302875 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
2876 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
2877 ah->rfkill_gpio =
2878 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
2879 ah->rfkill_polarity =
2880 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05302881
2882 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
2883 }
2884#endif
Vivek Natarajanbde748a2010-04-05 14:48:05 +05302885 if (AR_SREV_9271(ah))
2886 pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
2887 else
2888 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
Sujithf1dc5602008-10-29 10:16:30 +05302889
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302890 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302891 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
2892 else
2893 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
2894
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002895 if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) {
Sujithf1dc5602008-10-29 10:16:30 +05302896 pCap->reg_cap =
2897 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
2898 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
2899 AR_EEPROM_EEREGCAP_EN_KK_U2 |
2900 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
2901 } else {
2902 pCap->reg_cap =
2903 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
2904 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
2905 }
2906
Senthil Balasubramanianebb90cf2009-09-18 15:07:33 +05302907 /* Advertise midband for AR5416 with FCC midband set in eeprom */
2908 if (regulatory->current_rd_ext & (1 << REG_EXT_FCC_MIDBAND) &&
2909 AR_SREV_5416(ah))
2910 pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
Sujithf1dc5602008-10-29 10:16:30 +05302911
2912 pCap->num_antcfg_5ghz =
Sujithf74df6f2009-02-09 13:27:24 +05302913 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05302914 pCap->num_antcfg_2ghz =
Sujithf74df6f2009-02-09 13:27:24 +05302915 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05302916
Vasanthakumar Thiagarajanfe129462009-09-09 15:25:50 +05302917 if (AR_SREV_9280_10_OR_LATER(ah) &&
Luis R. Rodrigueza36cfbc2009-09-09 16:05:32 -07002918 ath9k_hw_btcoex_supported(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002919 btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO;
2920 btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO;
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05302921
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302922 if (AR_SREV_9285(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002923 btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
2924 btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302925 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002926 btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302927 }
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05302928 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002929 btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE;
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05302930 }
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002931
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002932 if (AR_SREV_9300_20_OR_LATER(ah)) {
Vasanthakumar Thiagarajan1adf02f2010-04-15 17:38:24 -04002933 pCap->hw_caps |= ATH9K_HW_CAP_EDMA;
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002934 pCap->rx_hp_qdepth = ATH9K_HW_RX_HP_QDEPTH;
2935 pCap->rx_lp_qdepth = ATH9K_HW_RX_LP_QDEPTH;
2936 pCap->rx_status_len = sizeof(struct ar9003_rxs);
Vasanthakumar Thiagarajan162c3be2010-04-15 17:38:41 -04002937 pCap->tx_desc_len = sizeof(struct ar9003_txc);
2938 } else {
2939 pCap->tx_desc_len = sizeof(struct ath_desc);
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002940 }
Vasanthakumar Thiagarajan1adf02f2010-04-15 17:38:24 -04002941
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002942 return 0;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002943}
2944
Sujithcbe61d82009-02-09 13:27:12 +05302945bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05302946 u32 capability, u32 *result)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002947{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002948 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302949 switch (type) {
2950 case ATH9K_CAP_CIPHER:
2951 switch (capability) {
2952 case ATH9K_CIPHER_AES_CCM:
2953 case ATH9K_CIPHER_AES_OCB:
2954 case ATH9K_CIPHER_TKIP:
2955 case ATH9K_CIPHER_WEP:
2956 case ATH9K_CIPHER_MIC:
2957 case ATH9K_CIPHER_CLR:
2958 return true;
2959 default:
2960 return false;
2961 }
2962 case ATH9K_CAP_TKIP_MIC:
2963 switch (capability) {
2964 case 0:
2965 return true;
2966 case 1:
Sujith2660b812009-02-09 13:27:26 +05302967 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05302968 AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
2969 false;
2970 }
2971 case ATH9K_CAP_TKIP_SPLIT:
Sujith2660b812009-02-09 13:27:26 +05302972 return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ?
Sujithf1dc5602008-10-29 10:16:30 +05302973 false : true;
Sujithf1dc5602008-10-29 10:16:30 +05302974 case ATH9K_CAP_MCAST_KEYSRCH:
2975 switch (capability) {
2976 case 0:
2977 return true;
2978 case 1:
2979 if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
2980 return false;
2981 } else {
Sujith2660b812009-02-09 13:27:26 +05302982 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05302983 AR_STA_ID1_MCAST_KSRCH) ? true :
2984 false;
2985 }
2986 }
2987 return false;
Sujithf1dc5602008-10-29 10:16:30 +05302988 case ATH9K_CAP_TXPOW:
2989 switch (capability) {
2990 case 0:
2991 return 0;
2992 case 1:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002993 *result = regulatory->power_limit;
Sujithf1dc5602008-10-29 10:16:30 +05302994 return 0;
2995 case 2:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002996 *result = regulatory->max_power_level;
Sujithf1dc5602008-10-29 10:16:30 +05302997 return 0;
2998 case 3:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002999 *result = regulatory->tp_scale;
Sujithf1dc5602008-10-29 10:16:30 +05303000 return 0;
3001 }
3002 return false;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05303003 case ATH9K_CAP_DS:
3004 return (AR_SREV_9280_20_OR_LATER(ah) &&
3005 (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1))
3006 ? false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303007 default:
3008 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003009 }
Sujithf1dc5602008-10-29 10:16:30 +05303010}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003011EXPORT_SYMBOL(ath9k_hw_getcapability);
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003012
Sujithcbe61d82009-02-09 13:27:12 +05303013bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303014 u32 capability, u32 setting, int *status)
3015{
Sujithf1dc5602008-10-29 10:16:30 +05303016 switch (type) {
3017 case ATH9K_CAP_TKIP_MIC:
3018 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303019 ah->sta_id1_defaults |=
Sujithf1dc5602008-10-29 10:16:30 +05303020 AR_STA_ID1_CRPT_MIC_ENABLE;
3021 else
Sujith2660b812009-02-09 13:27:26 +05303022 ah->sta_id1_defaults &=
Sujithf1dc5602008-10-29 10:16:30 +05303023 ~AR_STA_ID1_CRPT_MIC_ENABLE;
3024 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303025 case ATH9K_CAP_MCAST_KEYSRCH:
3026 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303027 ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303028 else
Sujith2660b812009-02-09 13:27:26 +05303029 ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303030 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303031 default:
3032 return false;
3033 }
3034}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003035EXPORT_SYMBOL(ath9k_hw_setcapability);
Sujithf1dc5602008-10-29 10:16:30 +05303036
3037/****************************/
3038/* GPIO / RFKILL / Antennae */
3039/****************************/
3040
Sujithcbe61d82009-02-09 13:27:12 +05303041static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303042 u32 gpio, u32 type)
3043{
3044 int addr;
3045 u32 gpio_shift, tmp;
3046
3047 if (gpio > 11)
3048 addr = AR_GPIO_OUTPUT_MUX3;
3049 else if (gpio > 5)
3050 addr = AR_GPIO_OUTPUT_MUX2;
3051 else
3052 addr = AR_GPIO_OUTPUT_MUX1;
3053
3054 gpio_shift = (gpio % 6) * 5;
3055
3056 if (AR_SREV_9280_20_OR_LATER(ah)
3057 || (addr != AR_GPIO_OUTPUT_MUX1)) {
3058 REG_RMW(ah, addr, (type << gpio_shift),
3059 (0x1f << gpio_shift));
3060 } else {
3061 tmp = REG_READ(ah, addr);
3062 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
3063 tmp &= ~(0x1f << gpio_shift);
3064 tmp |= (type << gpio_shift);
3065 REG_WRITE(ah, addr, tmp);
3066 }
3067}
3068
Sujithcbe61d82009-02-09 13:27:12 +05303069void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303070{
3071 u32 gpio_shift;
3072
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07003073 BUG_ON(gpio >= ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05303074
3075 gpio_shift = gpio << 1;
3076
3077 REG_RMW(ah,
3078 AR_GPIO_OE_OUT,
3079 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
3080 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3081}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003082EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
Sujithf1dc5602008-10-29 10:16:30 +05303083
Sujithcbe61d82009-02-09 13:27:12 +05303084u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303085{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303086#define MS_REG_READ(x, y) \
3087 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
3088
Sujith2660b812009-02-09 13:27:26 +05303089 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05303090 return 0xffffffff;
3091
Felix Fietkau783dfca2010-04-15 17:38:11 -04003092 if (AR_SREV_9300_20_OR_LATER(ah))
3093 return MS_REG_READ(AR9300, gpio) != 0;
3094 else if (AR_SREV_9271(ah))
Sujith5b5fa352010-03-17 14:25:15 +05303095 return MS_REG_READ(AR9271, gpio) != 0;
3096 else if (AR_SREV_9287_10_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05303097 return MS_REG_READ(AR9287, gpio) != 0;
3098 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303099 return MS_REG_READ(AR9285, gpio) != 0;
3100 else if (AR_SREV_9280_10_OR_LATER(ah))
3101 return MS_REG_READ(AR928X, gpio) != 0;
3102 else
3103 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05303104}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003105EXPORT_SYMBOL(ath9k_hw_gpio_get);
Sujithf1dc5602008-10-29 10:16:30 +05303106
Sujithcbe61d82009-02-09 13:27:12 +05303107void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05303108 u32 ah_signal_type)
3109{
3110 u32 gpio_shift;
3111
3112 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
3113
3114 gpio_shift = 2 * gpio;
3115
3116 REG_RMW(ah,
3117 AR_GPIO_OE_OUT,
3118 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
3119 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3120}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003121EXPORT_SYMBOL(ath9k_hw_cfg_output);
Sujithf1dc5602008-10-29 10:16:30 +05303122
Sujithcbe61d82009-02-09 13:27:12 +05303123void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05303124{
Sujith5b5fa352010-03-17 14:25:15 +05303125 if (AR_SREV_9271(ah))
3126 val = ~val;
3127
Sujithf1dc5602008-10-29 10:16:30 +05303128 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
3129 AR_GPIO_BIT(gpio));
3130}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003131EXPORT_SYMBOL(ath9k_hw_set_gpio);
Sujithf1dc5602008-10-29 10:16:30 +05303132
Sujithcbe61d82009-02-09 13:27:12 +05303133u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303134{
3135 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
3136}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003137EXPORT_SYMBOL(ath9k_hw_getdefantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303138
Sujithcbe61d82009-02-09 13:27:12 +05303139void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05303140{
3141 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
3142}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003143EXPORT_SYMBOL(ath9k_hw_setantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303144
Sujithf1dc5602008-10-29 10:16:30 +05303145/*********************/
3146/* General Operation */
3147/*********************/
3148
Sujithcbe61d82009-02-09 13:27:12 +05303149u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303150{
3151 u32 bits = REG_READ(ah, AR_RX_FILTER);
3152 u32 phybits = REG_READ(ah, AR_PHY_ERR);
3153
3154 if (phybits & AR_PHY_ERR_RADAR)
3155 bits |= ATH9K_RX_FILTER_PHYRADAR;
3156 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
3157 bits |= ATH9K_RX_FILTER_PHYERR;
3158
3159 return bits;
3160}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003161EXPORT_SYMBOL(ath9k_hw_getrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303162
Sujithcbe61d82009-02-09 13:27:12 +05303163void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05303164{
3165 u32 phybits;
3166
Sujith7ea310b2009-09-03 12:08:43 +05303167 REG_WRITE(ah, AR_RX_FILTER, bits);
3168
Sujithf1dc5602008-10-29 10:16:30 +05303169 phybits = 0;
3170 if (bits & ATH9K_RX_FILTER_PHYRADAR)
3171 phybits |= AR_PHY_ERR_RADAR;
3172 if (bits & ATH9K_RX_FILTER_PHYERR)
3173 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
3174 REG_WRITE(ah, AR_PHY_ERR, phybits);
3175
3176 if (phybits)
3177 REG_WRITE(ah, AR_RXCFG,
3178 REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
3179 else
3180 REG_WRITE(ah, AR_RXCFG,
3181 REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
3182}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003183EXPORT_SYMBOL(ath9k_hw_setrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303184
Sujithcbe61d82009-02-09 13:27:12 +05303185bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303186{
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05303187 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
3188 return false;
3189
3190 ath9k_hw_init_pll(ah, NULL);
3191 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303192}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003193EXPORT_SYMBOL(ath9k_hw_phy_disable);
Sujithf1dc5602008-10-29 10:16:30 +05303194
Sujithcbe61d82009-02-09 13:27:12 +05303195bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303196{
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07003197 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05303198 return false;
3199
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05303200 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
3201 return false;
3202
3203 ath9k_hw_init_pll(ah, NULL);
3204 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303205}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003206EXPORT_SYMBOL(ath9k_hw_disable);
Sujithf1dc5602008-10-29 10:16:30 +05303207
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003208void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
Sujithf1dc5602008-10-29 10:16:30 +05303209{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003210 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujith2660b812009-02-09 13:27:26 +05303211 struct ath9k_channel *chan = ah->curchan;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08003212 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05303213
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003214 regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER);
Sujithf1dc5602008-10-29 10:16:30 +05303215
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003216 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003217 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003218 channel->max_antenna_gain * 2,
3219 channel->max_power * 2,
3220 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003221 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05303222}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003223EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
Sujithf1dc5602008-10-29 10:16:30 +05303224
Sujithcbe61d82009-02-09 13:27:12 +05303225void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac)
Sujithf1dc5602008-10-29 10:16:30 +05303226{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07003227 memcpy(ath9k_hw_common(ah)->macaddr, mac, ETH_ALEN);
Sujithf1dc5602008-10-29 10:16:30 +05303228}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003229EXPORT_SYMBOL(ath9k_hw_setmac);
Sujithf1dc5602008-10-29 10:16:30 +05303230
Sujithcbe61d82009-02-09 13:27:12 +05303231void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303232{
Sujith2660b812009-02-09 13:27:26 +05303233 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05303234}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003235EXPORT_SYMBOL(ath9k_hw_setopmode);
Sujithf1dc5602008-10-29 10:16:30 +05303236
Sujithcbe61d82009-02-09 13:27:12 +05303237void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05303238{
3239 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
3240 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
3241}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003242EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303243
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07003244void ath9k_hw_write_associd(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303245{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07003246 struct ath_common *common = ath9k_hw_common(ah);
3247
3248 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
3249 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
3250 ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05303251}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003252EXPORT_SYMBOL(ath9k_hw_write_associd);
Sujithf1dc5602008-10-29 10:16:30 +05303253
Sujithcbe61d82009-02-09 13:27:12 +05303254u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303255{
3256 u64 tsf;
3257
3258 tsf = REG_READ(ah, AR_TSF_U32);
3259 tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
3260
3261 return tsf;
3262}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003263EXPORT_SYMBOL(ath9k_hw_gettsf64);
Sujithf1dc5602008-10-29 10:16:30 +05303264
Sujithcbe61d82009-02-09 13:27:12 +05303265void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003266{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003267 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01003268 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003269}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003270EXPORT_SYMBOL(ath9k_hw_settsf64);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003271
Sujithcbe61d82009-02-09 13:27:12 +05303272void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303273{
Gabor Juhosf9b604f2009-06-21 00:02:15 +02003274 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
3275 AH_TSF_WRITE_TIMEOUT))
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003276 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
3277 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
Gabor Juhosf9b604f2009-06-21 00:02:15 +02003278
Sujithf1dc5602008-10-29 10:16:30 +05303279 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003280}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003281EXPORT_SYMBOL(ath9k_hw_reset_tsf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003282
Sujith54e4cec2009-08-07 09:45:09 +05303283void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003284{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003285 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303286 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003287 else
Sujith2660b812009-02-09 13:27:26 +05303288 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003289}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003290EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003291
Luis R. Rodriguez30cbd422009-11-03 16:10:46 -08003292/*
3293 * Extend 15-bit time stamp from rx descriptor to
3294 * a full 64-bit TSF using the current h/w TSF.
3295*/
3296u64 ath9k_hw_extend_tsf(struct ath_hw *ah, u32 rstamp)
3297{
3298 u64 tsf;
3299
3300 tsf = ath9k_hw_gettsf64(ah);
3301 if ((tsf & 0x7fff) < rstamp)
3302 tsf -= 0x8000;
3303 return (tsf & ~0x7fff) | rstamp;
3304}
3305EXPORT_SYMBOL(ath9k_hw_extend_tsf);
3306
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003307void ath9k_hw_set11nmac2040(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003308{
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003309 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithf1dc5602008-10-29 10:16:30 +05303310 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003311
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003312 if (conf_is_ht40(conf) && !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05303313 macmode = AR_2040_JOINED_RX_CLEAR;
3314 else
3315 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003316
Sujithf1dc5602008-10-29 10:16:30 +05303317 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003318}
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303319
3320/* HW Generic timers configuration */
3321
3322static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
3323{
3324 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3325 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3326 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3327 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3328 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3329 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3330 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3331 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3332 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
3333 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
3334 AR_NDP2_TIMER_MODE, 0x0002},
3335 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
3336 AR_NDP2_TIMER_MODE, 0x0004},
3337 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
3338 AR_NDP2_TIMER_MODE, 0x0008},
3339 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
3340 AR_NDP2_TIMER_MODE, 0x0010},
3341 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
3342 AR_NDP2_TIMER_MODE, 0x0020},
3343 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
3344 AR_NDP2_TIMER_MODE, 0x0040},
3345 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
3346 AR_NDP2_TIMER_MODE, 0x0080}
3347};
3348
3349/* HW generic timer primitives */
3350
3351/* compute and clear index of rightmost 1 */
3352static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
3353{
3354 u32 b;
3355
3356 b = *mask;
3357 b &= (0-b);
3358 *mask &= ~b;
3359 b *= debruijn32;
3360 b >>= 27;
3361
3362 return timer_table->gen_timer_index[b];
3363}
3364
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05303365u32 ath9k_hw_gettsf32(struct ath_hw *ah)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303366{
3367 return REG_READ(ah, AR_TSF_L32);
3368}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003369EXPORT_SYMBOL(ath9k_hw_gettsf32);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303370
3371struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
3372 void (*trigger)(void *),
3373 void (*overflow)(void *),
3374 void *arg,
3375 u8 timer_index)
3376{
3377 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3378 struct ath_gen_timer *timer;
3379
3380 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
3381
3382 if (timer == NULL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003383 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
3384 "Failed to allocate memory"
3385 "for hw timer[%d]\n", timer_index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303386 return NULL;
3387 }
3388
3389 /* allocate a hardware generic timer slot */
3390 timer_table->timers[timer_index] = timer;
3391 timer->index = timer_index;
3392 timer->trigger = trigger;
3393 timer->overflow = overflow;
3394 timer->arg = arg;
3395
3396 return timer;
3397}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003398EXPORT_SYMBOL(ath_gen_timer_alloc);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303399
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07003400void ath9k_hw_gen_timer_start(struct ath_hw *ah,
3401 struct ath_gen_timer *timer,
3402 u32 timer_next,
3403 u32 timer_period)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303404{
3405 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3406 u32 tsf;
3407
3408 BUG_ON(!timer_period);
3409
3410 set_bit(timer->index, &timer_table->timer_mask.timer_bits);
3411
3412 tsf = ath9k_hw_gettsf32(ah);
3413
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003414 ath_print(ath9k_hw_common(ah), ATH_DBG_HWTIMER,
3415 "curent tsf %x period %x"
3416 "timer_next %x\n", tsf, timer_period, timer_next);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303417
3418 /*
3419 * Pull timer_next forward if the current TSF already passed it
3420 * because of software latency
3421 */
3422 if (timer_next < tsf)
3423 timer_next = tsf + timer_period;
3424
3425 /*
3426 * Program generic timer registers
3427 */
3428 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
3429 timer_next);
3430 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
3431 timer_period);
3432 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
3433 gen_tmr_configuration[timer->index].mode_mask);
3434
3435 /* Enable both trigger and thresh interrupt masks */
3436 REG_SET_BIT(ah, AR_IMR_S5,
3437 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
3438 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303439}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003440EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303441
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07003442void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303443{
3444 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3445
3446 if ((timer->index < AR_FIRST_NDP_TIMER) ||
3447 (timer->index >= ATH_MAX_GEN_TIMER)) {
3448 return;
3449 }
3450
3451 /* Clear generic timer enable bits. */
3452 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
3453 gen_tmr_configuration[timer->index].mode_mask);
3454
3455 /* Disable both trigger and thresh interrupt masks */
3456 REG_CLR_BIT(ah, AR_IMR_S5,
3457 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
3458 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
3459
3460 clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303461}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003462EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303463
3464void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
3465{
3466 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3467
3468 /* free the hardware generic timer slot */
3469 timer_table->timers[timer->index] = NULL;
3470 kfree(timer);
3471}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003472EXPORT_SYMBOL(ath_gen_timer_free);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303473
3474/*
3475 * Generic Timer Interrupts handling
3476 */
3477void ath_gen_timer_isr(struct ath_hw *ah)
3478{
3479 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3480 struct ath_gen_timer *timer;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003481 struct ath_common *common = ath9k_hw_common(ah);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303482 u32 trigger_mask, thresh_mask, index;
3483
3484 /* get hardware generic timer interrupt status */
3485 trigger_mask = ah->intr_gen_timer_trigger;
3486 thresh_mask = ah->intr_gen_timer_thresh;
3487 trigger_mask &= timer_table->timer_mask.val;
3488 thresh_mask &= timer_table->timer_mask.val;
3489
3490 trigger_mask &= ~thresh_mask;
3491
3492 while (thresh_mask) {
3493 index = rightmost_index(timer_table, &thresh_mask);
3494 timer = timer_table->timers[index];
3495 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003496 ath_print(common, ATH_DBG_HWTIMER,
3497 "TSF overflow for Gen timer %d\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303498 timer->overflow(timer->arg);
3499 }
3500
3501 while (trigger_mask) {
3502 index = rightmost_index(timer_table, &trigger_mask);
3503 timer = timer_table->timers[index];
3504 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003505 ath_print(common, ATH_DBG_HWTIMER,
3506 "Gen timer[%d] trigger\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303507 timer->trigger(timer->arg);
3508 }
3509}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003510EXPORT_SYMBOL(ath_gen_timer_isr);
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003511
Sujith05020d22010-03-17 14:25:23 +05303512/********/
3513/* HTC */
3514/********/
3515
3516void ath9k_hw_htc_resetinit(struct ath_hw *ah)
3517{
3518 ah->htc_reset_init = true;
3519}
3520EXPORT_SYMBOL(ath9k_hw_htc_resetinit);
3521
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003522static struct {
3523 u32 version;
3524 const char * name;
3525} ath_mac_bb_names[] = {
3526 /* Devices with external radios */
3527 { AR_SREV_VERSION_5416_PCI, "5416" },
3528 { AR_SREV_VERSION_5416_PCIE, "5418" },
3529 { AR_SREV_VERSION_9100, "9100" },
3530 { AR_SREV_VERSION_9160, "9160" },
3531 /* Single-chip solutions */
3532 { AR_SREV_VERSION_9280, "9280" },
3533 { AR_SREV_VERSION_9285, "9285" },
Luis R. Rodriguez11158472009-10-27 12:59:35 -04003534 { AR_SREV_VERSION_9287, "9287" },
3535 { AR_SREV_VERSION_9271, "9271" },
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003536};
3537
3538/* For devices with external radios */
3539static struct {
3540 u16 version;
3541 const char * name;
3542} ath_rf_names[] = {
3543 { 0, "5133" },
3544 { AR_RAD5133_SREV_MAJOR, "5133" },
3545 { AR_RAD5122_SREV_MAJOR, "5122" },
3546 { AR_RAD2133_SREV_MAJOR, "2133" },
3547 { AR_RAD2122_SREV_MAJOR, "2122" }
3548};
3549
3550/*
3551 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
3552 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003553static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003554{
3555 int i;
3556
3557 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
3558 if (ath_mac_bb_names[i].version == mac_bb_version) {
3559 return ath_mac_bb_names[i].name;
3560 }
3561 }
3562
3563 return "????";
3564}
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003565
3566/*
3567 * Return the RF name. "????" is returned if the RF is unknown.
3568 * Used for devices with external radios.
3569 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003570static const char *ath9k_hw_rf_name(u16 rf_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003571{
3572 int i;
3573
3574 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
3575 if (ath_rf_names[i].version == rf_version) {
3576 return ath_rf_names[i].name;
3577 }
3578 }
3579
3580 return "????";
3581}
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003582
3583void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
3584{
3585 int used;
3586
3587 /* chipsets >= AR9280 are single-chip */
3588 if (AR_SREV_9280_10_OR_LATER(ah)) {
3589 used = snprintf(hw_name, len,
3590 "Atheros AR%s Rev:%x",
3591 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3592 ah->hw_version.macRev);
3593 }
3594 else {
3595 used = snprintf(hw_name, len,
3596 "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
3597 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3598 ah->hw_version.macRev,
3599 ath9k_hw_rf_name((ah->hw_version.analog5GhzRev &
3600 AR_RADIO_SREV_MAJOR)),
3601 ah->hw_version.phyRev);
3602 }
3603
3604 hw_name[used] = '\0';
3605}
3606EXPORT_SYMBOL(ath9k_hw_name);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04003607
3608/* Sets up the AR5008/AR9001/AR9002 hardware familiy callbacks */
3609static void ar9002_hw_attach_ops(struct ath_hw *ah)
3610{
3611 struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
3612 struct ath_hw_ops *ops = ath9k_hw_ops(ah);
3613
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04003614 priv_ops->init_mode_regs = ar9002_hw_init_mode_regs;
3615 priv_ops->macversion_supported = ar9002_hw_macversion_supported;
3616
3617 ops->config_pci_powersave = ar9002_hw_configpcipowersave;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04003618
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04003619 ar5008_hw_attach_phy_ops(ah);
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04003620 if (AR_SREV_9280_10_OR_LATER(ah))
3621 ar9002_hw_attach_phy_ops(ah);
Vasanthakumar Thiagarajanae3bb6d2010-04-15 17:38:27 -04003622
Luis R. Rodriguez795f5e22010-04-15 17:39:00 -04003623 ar9002_hw_attach_calib_ops(ah);
Vasanthakumar Thiagarajanae3bb6d2010-04-15 17:38:27 -04003624 ar9002_hw_attach_mac_ops(ah);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04003625}
3626
3627/* Sets up the AR9003 hardware familiy callbacks */
3628static void ar9003_hw_attach_ops(struct ath_hw *ah)
3629{
Luis R. Rodriguez61accab2010-04-15 17:38:21 -04003630 struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
3631
Luis R. Rodriguez13ce3e92010-04-15 17:38:37 -04003632 priv_ops->init_mode_regs = ar9003_hw_init_mode_regs;
Luis R. Rodriguez61accab2010-04-15 17:38:21 -04003633 priv_ops->macversion_supported = ar9003_hw_macversion_supported;
3634
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04003635 ar9003_hw_attach_phy_ops(ah);
Luis R. Rodriguez795f5e22010-04-15 17:39:00 -04003636 ar9003_hw_attach_calib_ops(ah);
Vasanthakumar Thiagarajanae3bb6d2010-04-15 17:38:27 -04003637 ar9003_hw_attach_mac_ops(ah);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04003638}