blob: f45e724c841fb8753cb95a8d15bba919a1b5c32b [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_cal_settings(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700604{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700605 if (AR_SREV_9160_10_OR_LATER(ah)) {
606 if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530607 ah->iq_caldata.calData = &iq_cal_single_sample;
608 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700609 &adc_gain_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530610 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700611 &adc_dc_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530612 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700613 &adc_init_dc_cal;
614 } else {
Sujith2660b812009-02-09 13:27:26 +0530615 ah->iq_caldata.calData = &iq_cal_multi_sample;
616 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700617 &adc_gain_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530618 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700619 &adc_dc_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530620 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700621 &adc_init_dc_cal;
622 }
Sujith2660b812009-02-09 13:27:26 +0530623 ah->supp_cals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700624 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700625}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700626
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400627static void ar9002_hw_init_mode_regs(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700628{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400629 if (AR_SREV_9271(ah)) {
Luis R. Rodriguez85643282009-10-19 02:33:33 -0400630 INIT_INI_ARRAY(&ah->iniModes, ar9271Modes_9271,
631 ARRAY_SIZE(ar9271Modes_9271), 6);
632 INIT_INI_ARRAY(&ah->iniCommon, ar9271Common_9271,
633 ARRAY_SIZE(ar9271Common_9271), 2);
Sujith70807e92010-03-17 14:25:14 +0530634 INIT_INI_ARRAY(&ah->iniCommon_normal_cck_fir_coeff_9271,
635 ar9271Common_normal_cck_fir_coeff_9271,
636 ARRAY_SIZE(ar9271Common_normal_cck_fir_coeff_9271), 2);
637 INIT_INI_ARRAY(&ah->iniCommon_japan_2484_cck_fir_coeff_9271,
638 ar9271Common_japan_2484_cck_fir_coeff_9271,
639 ARRAY_SIZE(ar9271Common_japan_2484_cck_fir_coeff_9271), 2);
Luis R. Rodriguez85643282009-10-19 02:33:33 -0400640 INIT_INI_ARRAY(&ah->iniModes_9271_1_0_only,
641 ar9271Modes_9271_1_0_only,
642 ARRAY_SIZE(ar9271Modes_9271_1_0_only), 6);
Sujith70807e92010-03-17 14:25:14 +0530643 INIT_INI_ARRAY(&ah->iniModes_9271_ANI_reg, ar9271Modes_9271_ANI_reg,
644 ARRAY_SIZE(ar9271Modes_9271_ANI_reg), 6);
645 INIT_INI_ARRAY(&ah->iniModes_high_power_tx_gain_9271,
646 ar9271Modes_high_power_tx_gain_9271,
647 ARRAY_SIZE(ar9271Modes_high_power_tx_gain_9271), 6);
648 INIT_INI_ARRAY(&ah->iniModes_normal_power_tx_gain_9271,
649 ar9271Modes_normal_power_tx_gain_9271,
650 ARRAY_SIZE(ar9271Modes_normal_power_tx_gain_9271), 6);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400651 return;
652 }
653
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530654 if (AR_SREV_9287_11_OR_LATER(ah)) {
655 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_1,
656 ARRAY_SIZE(ar9287Modes_9287_1_1), 6);
657 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_1,
658 ARRAY_SIZE(ar9287Common_9287_1_1), 2);
659 if (ah->config.pcie_clock_req)
660 INIT_INI_ARRAY(&ah->iniPcieSerdes,
661 ar9287PciePhy_clkreq_off_L1_9287_1_1,
662 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_1), 2);
663 else
664 INIT_INI_ARRAY(&ah->iniPcieSerdes,
665 ar9287PciePhy_clkreq_always_on_L1_9287_1_1,
666 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_1),
667 2);
668 } else if (AR_SREV_9287_10_OR_LATER(ah)) {
669 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_0,
670 ARRAY_SIZE(ar9287Modes_9287_1_0), 6);
671 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_0,
672 ARRAY_SIZE(ar9287Common_9287_1_0), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700673
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530674 if (ah->config.pcie_clock_req)
675 INIT_INI_ARRAY(&ah->iniPcieSerdes,
676 ar9287PciePhy_clkreq_off_L1_9287_1_0,
677 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_0), 2);
678 else
679 INIT_INI_ARRAY(&ah->iniPcieSerdes,
680 ar9287PciePhy_clkreq_always_on_L1_9287_1_0,
681 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_0),
682 2);
683 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
684
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530685
Sujith2660b812009-02-09 13:27:26 +0530686 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530687 ARRAY_SIZE(ar9285Modes_9285_1_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530688 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530689 ARRAY_SIZE(ar9285Common_9285_1_2), 2);
690
Sujith2660b812009-02-09 13:27:26 +0530691 if (ah->config.pcie_clock_req) {
692 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530693 ar9285PciePhy_clkreq_off_L1_9285_1_2,
694 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2);
695 } else {
Sujith2660b812009-02-09 13:27:26 +0530696 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530697 ar9285PciePhy_clkreq_always_on_L1_9285_1_2,
698 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2),
699 2);
700 }
701 } else if (AR_SREV_9285_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530702 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530703 ARRAY_SIZE(ar9285Modes_9285), 6);
Sujith2660b812009-02-09 13:27:26 +0530704 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530705 ARRAY_SIZE(ar9285Common_9285), 2);
706
Sujith2660b812009-02-09 13:27:26 +0530707 if (ah->config.pcie_clock_req) {
708 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530709 ar9285PciePhy_clkreq_off_L1_9285,
710 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2);
711 } else {
Sujith2660b812009-02-09 13:27:26 +0530712 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530713 ar9285PciePhy_clkreq_always_on_L1_9285,
714 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285), 2);
715 }
716 } else if (AR_SREV_9280_20_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530717 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700718 ARRAY_SIZE(ar9280Modes_9280_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530719 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700720 ARRAY_SIZE(ar9280Common_9280_2), 2);
721
Sujith2660b812009-02-09 13:27:26 +0530722 if (ah->config.pcie_clock_req) {
723 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530724 ar9280PciePhy_clkreq_off_L1_9280,
725 ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700726 } else {
Sujith2660b812009-02-09 13:27:26 +0530727 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530728 ar9280PciePhy_clkreq_always_on_L1_9280,
729 ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700730 }
Sujith2660b812009-02-09 13:27:26 +0530731 INIT_INI_ARRAY(&ah->iniModesAdditional,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700732 ar9280Modes_fast_clock_9280_2,
Sujithf1dc5602008-10-29 10:16:30 +0530733 ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700734 } else if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530735 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700736 ARRAY_SIZE(ar9280Modes_9280), 6);
Sujith2660b812009-02-09 13:27:26 +0530737 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700738 ARRAY_SIZE(ar9280Common_9280), 2);
739 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530740 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700741 ARRAY_SIZE(ar5416Modes_9160), 6);
Sujith2660b812009-02-09 13:27:26 +0530742 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700743 ARRAY_SIZE(ar5416Common_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530744 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700745 ARRAY_SIZE(ar5416Bank0_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530746 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700747 ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530748 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700749 ARRAY_SIZE(ar5416Bank1_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530750 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700751 ARRAY_SIZE(ar5416Bank2_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530752 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700753 ARRAY_SIZE(ar5416Bank3_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530754 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700755 ARRAY_SIZE(ar5416Bank6_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530756 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700757 ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530758 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700759 ARRAY_SIZE(ar5416Bank7_9160), 2);
760 if (AR_SREV_9160_11(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530761 INIT_INI_ARRAY(&ah->iniAddac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700762 ar5416Addac_91601_1,
763 ARRAY_SIZE(ar5416Addac_91601_1), 2);
764 } else {
Sujith2660b812009-02-09 13:27:26 +0530765 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700766 ARRAY_SIZE(ar5416Addac_9160), 2);
767 }
768 } else if (AR_SREV_9100_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530769 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700770 ARRAY_SIZE(ar5416Modes_9100), 6);
Sujith2660b812009-02-09 13:27:26 +0530771 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700772 ARRAY_SIZE(ar5416Common_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530773 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700774 ARRAY_SIZE(ar5416Bank0_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530775 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700776 ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530777 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700778 ARRAY_SIZE(ar5416Bank1_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530779 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700780 ARRAY_SIZE(ar5416Bank2_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530781 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700782 ARRAY_SIZE(ar5416Bank3_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530783 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700784 ARRAY_SIZE(ar5416Bank6_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530785 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700786 ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530787 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700788 ARRAY_SIZE(ar5416Bank7_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530789 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700790 ARRAY_SIZE(ar5416Addac_9100), 2);
791 } else {
Sujith2660b812009-02-09 13:27:26 +0530792 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700793 ARRAY_SIZE(ar5416Modes), 6);
Sujith2660b812009-02-09 13:27:26 +0530794 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700795 ARRAY_SIZE(ar5416Common), 2);
Sujith2660b812009-02-09 13:27:26 +0530796 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700797 ARRAY_SIZE(ar5416Bank0), 2);
Sujith2660b812009-02-09 13:27:26 +0530798 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700799 ARRAY_SIZE(ar5416BB_RfGain), 3);
Sujith2660b812009-02-09 13:27:26 +0530800 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700801 ARRAY_SIZE(ar5416Bank1), 2);
Sujith2660b812009-02-09 13:27:26 +0530802 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700803 ARRAY_SIZE(ar5416Bank2), 2);
Sujith2660b812009-02-09 13:27:26 +0530804 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700805 ARRAY_SIZE(ar5416Bank3), 3);
Sujith2660b812009-02-09 13:27:26 +0530806 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700807 ARRAY_SIZE(ar5416Bank6), 3);
Sujith2660b812009-02-09 13:27:26 +0530808 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700809 ARRAY_SIZE(ar5416Bank6TPC), 3);
Sujith2660b812009-02-09 13:27:26 +0530810 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700811 ARRAY_SIZE(ar5416Bank7), 2);
Sujith2660b812009-02-09 13:27:26 +0530812 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700813 ARRAY_SIZE(ar5416Addac), 2);
814 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700815}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700816
Luis R. Rodriguez13ce3e92010-04-15 17:38:37 -0400817/* AR9003 2.0 - new INI format (pre, core, post arrays per subsystem) */
818static void ar9003_hw_init_mode_regs(struct ath_hw *ah)
819{
820 /* mac */
821 INIT_INI_ARRAY(&ah->iniMac[ATH_INI_PRE], NULL, 0, 0);
822 INIT_INI_ARRAY(&ah->iniMac[ATH_INI_CORE],
823 ar9300_2p0_mac_core,
824 ARRAY_SIZE(ar9300_2p0_mac_core), 2);
825 INIT_INI_ARRAY(&ah->iniMac[ATH_INI_POST],
826 ar9300_2p0_mac_postamble,
827 ARRAY_SIZE(ar9300_2p0_mac_postamble), 5);
828
829 /* bb */
830 INIT_INI_ARRAY(&ah->iniBB[ATH_INI_PRE], NULL, 0, 0);
831 INIT_INI_ARRAY(&ah->iniBB[ATH_INI_CORE],
832 ar9300_2p0_baseband_core,
833 ARRAY_SIZE(ar9300_2p0_baseband_core), 2);
834 INIT_INI_ARRAY(&ah->iniBB[ATH_INI_POST],
835 ar9300_2p0_baseband_postamble,
836 ARRAY_SIZE(ar9300_2p0_baseband_postamble), 5);
837
838 /* radio */
839 INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_PRE], NULL, 0, 0);
840 INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_CORE],
841 ar9300_2p0_radio_core,
842 ARRAY_SIZE(ar9300_2p0_radio_core), 2);
843 INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_POST],
844 ar9300_2p0_radio_postamble,
845 ARRAY_SIZE(ar9300_2p0_radio_postamble), 5);
846
847 /* soc */
848 INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_PRE],
849 ar9300_2p0_soc_preamble,
850 ARRAY_SIZE(ar9300_2p0_soc_preamble), 2);
851 INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_CORE], NULL, 0, 0);
852 INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_POST],
853 ar9300_2p0_soc_postamble,
854 ARRAY_SIZE(ar9300_2p0_soc_postamble), 5);
855
856 /* rx/tx gain */
857 INIT_INI_ARRAY(&ah->iniModesRxGain,
858 ar9300Common_rx_gain_table_2p0,
859 ARRAY_SIZE(ar9300Common_rx_gain_table_2p0), 2);
860 INIT_INI_ARRAY(&ah->iniModesTxGain,
861 ar9300Modes_lowest_ob_db_tx_gain_table_2p0,
862 ARRAY_SIZE(ar9300Modes_lowest_ob_db_tx_gain_table_2p0),
863 5);
864
865 /* Load PCIE SERDES settings from INI */
866
867 /* Awake Setting */
868
869 INIT_INI_ARRAY(&ah->iniPcieSerdes,
870 ar9300PciePhy_pll_on_clkreq_disable_L1_2p0,
871 ARRAY_SIZE(ar9300PciePhy_pll_on_clkreq_disable_L1_2p0),
872 2);
873
874 /* Sleep Setting */
875
876 INIT_INI_ARRAY(&ah->iniPcieSerdesLowPower,
877 ar9300PciePhy_clkreq_enable_L1_2p0,
878 ARRAY_SIZE(ar9300PciePhy_clkreq_enable_L1_2p0),
879 2);
880
881 /* Fast clock modal settings */
882 INIT_INI_ARRAY(&ah->iniModesAdditional,
883 ar9300Modes_fast_clock_2p0,
884 ARRAY_SIZE(ar9300Modes_fast_clock_2p0),
885 3);
886}
887
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700888static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
889{
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530890 if (AR_SREV_9287_11_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530891 INIT_INI_ARRAY(&ah->iniModesRxGain,
892 ar9287Modes_rx_gain_9287_1_1,
893 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_1), 6);
894 else if (AR_SREV_9287_10(ah))
895 INIT_INI_ARRAY(&ah->iniModesRxGain,
896 ar9287Modes_rx_gain_9287_1_0,
897 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_0), 6);
898 else if (AR_SREV_9280_20(ah))
899 ath9k_hw_init_rxgain_ini(ah);
900
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530901 if (AR_SREV_9287_11_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530902 INIT_INI_ARRAY(&ah->iniModesTxGain,
903 ar9287Modes_tx_gain_9287_1_1,
904 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_1), 6);
905 } else if (AR_SREV_9287_10(ah)) {
906 INIT_INI_ARRAY(&ah->iniModesTxGain,
907 ar9287Modes_tx_gain_9287_1_0,
908 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_0), 6);
909 } else if (AR_SREV_9280_20(ah)) {
910 ath9k_hw_init_txgain_ini(ah);
911 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530912 u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
913
914 /* txgain table */
915 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) {
Vivek Natarajan53bc7aa2010-04-05 14:48:04 +0530916 if (AR_SREV_9285E_20(ah)) {
917 INIT_INI_ARRAY(&ah->iniModesTxGain,
918 ar9285Modes_XE2_0_high_power,
919 ARRAY_SIZE(
920 ar9285Modes_XE2_0_high_power), 6);
921 } else {
922 INIT_INI_ARRAY(&ah->iniModesTxGain,
923 ar9285Modes_high_power_tx_gain_9285_1_2,
924 ARRAY_SIZE(
925 ar9285Modes_high_power_tx_gain_9285_1_2), 6);
926 }
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530927 } else {
Vivek Natarajan53bc7aa2010-04-05 14:48:04 +0530928 if (AR_SREV_9285E_20(ah)) {
929 INIT_INI_ARRAY(&ah->iniModesTxGain,
930 ar9285Modes_XE2_0_normal_power,
931 ARRAY_SIZE(
932 ar9285Modes_XE2_0_normal_power), 6);
933 } else {
934 INIT_INI_ARRAY(&ah->iniModesTxGain,
935 ar9285Modes_original_tx_gain_9285_1_2,
936 ARRAY_SIZE(
937 ar9285Modes_original_tx_gain_9285_1_2), 6);
938 }
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530939 }
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530940 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700941}
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530942
Felix Fietkauaa8bc9e2010-01-23 20:04:18 +0100943static void ath9k_hw_init_eeprom_fix(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700944{
Pavel Roskin2eb46d92010-04-07 01:33:33 -0400945 struct base_eep_header *pBase = &(ah->eeprom.def.baseEepHeader);
946 struct ath_common *common = ath9k_hw_common(ah);
Sujith06d0f062009-02-12 10:06:45 +0530947
Pavel Roskin2eb46d92010-04-07 01:33:33 -0400948 ah->need_an_top2_fixup = (ah->hw_version.devid == AR9280_DEVID_PCI) &&
949 (ah->eep_map != EEP_MAP_4KBITS) &&
950 ((pBase->version & 0xff) > 0x0a) &&
951 (pBase->pwdclkind == 0);
Sujith06d0f062009-02-12 10:06:45 +0530952
Pavel Roskin2eb46d92010-04-07 01:33:33 -0400953 if (ah->need_an_top2_fixup)
954 ath_print(common, ATH_DBG_EEPROM,
955 "needs fixup for AR_AN_TOP2 register\n");
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700956}
957
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400958static void ath9k_hw_attach_ops(struct ath_hw *ah)
959{
960 if (AR_SREV_9300_20_OR_LATER(ah))
961 ar9003_hw_attach_ops(ah);
962 else
963 ar9002_hw_attach_ops(ah);
964}
965
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400966/* Called for all hardware families */
967static int __ath9k_hw_init(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700968{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700969 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700970 int r = 0;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700971
Luis R. Rodriguezbab1f622010-04-15 17:38:20 -0400972 if (ah->hw_version.devid == AR5416_AR9100_DEVID)
973 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700974
975 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700976 ath_print(common, ATH_DBG_FATAL,
977 "Couldn't reset chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700978 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700979 }
980
Luis R. Rodriguezbab1f622010-04-15 17:38:20 -0400981 ath9k_hw_init_defaults(ah);
982 ath9k_hw_init_config(ah);
983
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400984 ath9k_hw_attach_ops(ah);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400985
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700986 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700987 ath_print(common, ATH_DBG_FATAL, "Couldn't wakeup chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700988 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700989 }
990
991 if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
992 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
993 (AR_SREV_9280(ah) && !ah->is_pciexpress)) {
994 ah->config.serialize_regmode =
995 SER_REG_MODE_ON;
996 } else {
997 ah->config.serialize_regmode =
998 SER_REG_MODE_OFF;
999 }
1000 }
1001
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001002 ath_print(common, ATH_DBG_RESET, "serialize_regmode is %d\n",
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -07001003 ah->config.serialize_regmode);
1004
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -05001005 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
1006 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD >> 1;
1007 else
1008 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD;
1009
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04001010 if (!ath9k_hw_macversion_supported(ah)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001011 ath_print(common, ATH_DBG_FATAL,
1012 "Mac Chip Rev 0x%02x.%x is not supported by "
1013 "this driver\n", ah->hw_version.macVersion,
1014 ah->hw_version.macRev);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -07001015 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -07001016 }
1017
1018 if (AR_SREV_9100(ah)) {
1019 ah->iq_caldata.calData = &iq_cal_multi_sample;
1020 ah->supp_cals = IQ_MISMATCH_CAL;
1021 ah->is_pciexpress = false;
1022 }
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001023
1024 if (AR_SREV_9271(ah))
1025 ah->is_pciexpress = false;
1026
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -07001027 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -07001028 ath9k_hw_init_cal_settings(ah);
1029
1030 ah->ani_function = ATH9K_ANI_ALL;
Luis R. Rodriguez31a0bd32010-04-15 17:38:22 -04001031 if (AR_SREV_9280_10_OR_LATER(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -07001032 ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
1033
1034 ath9k_hw_init_mode_regs(ah);
1035
1036 if (ah->is_pciexpress)
Vivek Natarajan93b1b372009-09-17 09:24:58 +05301037 ath9k_hw_configpcipowersave(ah, 0, 0);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -07001038 else
1039 ath9k_hw_disablepcie(ah);
1040
Sujith193cd452009-09-18 15:04:07 +05301041 /* Support for Japan ch.14 (2484) spread */
1042 if (AR_SREV_9287_11_OR_LATER(ah)) {
1043 INIT_INI_ARRAY(&ah->iniCckfirNormal,
1044 ar9287Common_normal_cck_fir_coeff_92871_1,
1045 ARRAY_SIZE(ar9287Common_normal_cck_fir_coeff_92871_1), 2);
1046 INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
1047 ar9287Common_japan_2484_cck_fir_coeff_92871_1,
1048 ARRAY_SIZE(ar9287Common_japan_2484_cck_fir_coeff_92871_1), 2);
1049 }
1050
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -07001051 r = ath9k_hw_post_init(ah);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -07001052 if (r)
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -07001053 return r;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -07001054
1055 ath9k_hw_init_mode_gain_regs(ah);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01001056 r = ath9k_hw_fill_cap_info(ah);
1057 if (r)
1058 return r;
1059
Felix Fietkauaa8bc9e2010-01-23 20:04:18 +01001060 ath9k_hw_init_eeprom_fix(ah);
Sujithf6688cd2008-12-07 21:43:10 +05301061
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001062 r = ath9k_hw_init_macaddr(ah);
1063 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001064 ath_print(common, ATH_DBG_FATAL,
1065 "Failed to initialize MAC address\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -07001066 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001067 }
1068
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001069 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
Sujith2660b812009-02-09 13:27:26 +05301070 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001071 else
Sujith2660b812009-02-09 13:27:26 +05301072 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001073
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001074 ath9k_init_nfcal_hist_buffer(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001075
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001076 common->state = ATH_HW_INITIALIZED;
1077
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001078 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001079}
1080
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04001081int ath9k_hw_init(struct ath_hw *ah)
1082{
1083 int ret;
1084 struct ath_common *common = ath9k_hw_common(ah);
1085
1086 /* These are all the AR5008/AR9001/AR9002 hardware family of chipsets */
1087 switch (ah->hw_version.devid) {
1088 case AR5416_DEVID_PCI:
1089 case AR5416_DEVID_PCIE:
1090 case AR5416_AR9100_DEVID:
1091 case AR9160_DEVID_PCI:
1092 case AR9280_DEVID_PCI:
1093 case AR9280_DEVID_PCIE:
1094 case AR9285_DEVID_PCIE:
Senthil Balasubramaniandb3cc532010-04-15 17:38:18 -04001095 case AR9287_DEVID_PCI:
1096 case AR9287_DEVID_PCIE:
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04001097 case AR2427_DEVID_PCIE:
Senthil Balasubramaniandb3cc532010-04-15 17:38:18 -04001098 case AR9300_DEVID_PCIE:
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04001099 break;
1100 default:
1101 if (common->bus_ops->ath_bus_type == ATH_USB)
1102 break;
1103 ath_print(common, ATH_DBG_FATAL,
1104 "Hardware device ID 0x%04x not supported\n",
1105 ah->hw_version.devid);
1106 return -EOPNOTSUPP;
1107 }
1108
1109 ret = __ath9k_hw_init(ah);
1110 if (ret) {
1111 ath_print(common, ATH_DBG_FATAL,
1112 "Unable to initialize hardware; "
1113 "initialization status: %d\n", ret);
1114 return ret;
1115 }
1116
1117 return 0;
1118}
1119EXPORT_SYMBOL(ath9k_hw_init);
1120
Sujithcbe61d82009-02-09 13:27:12 +05301121static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301122{
1123 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
1124 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
1125
1126 REG_WRITE(ah, AR_QOS_NO_ACK,
1127 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
1128 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
1129 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
1130
1131 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
1132 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
1133 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
1134 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
1135 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
1136}
1137
Sujithcbe61d82009-02-09 13:27:12 +05301138static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301139 struct ath9k_channel *chan)
1140{
Luis R. Rodriguez64773962010-04-15 17:38:17 -04001141 u32 pll = ath9k_hw_compute_pll_control(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301142
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001143 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +05301144
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -04001145 /* Switch the core clock for ar9271 to 117Mhz */
1146 if (AR_SREV_9271(ah)) {
Sujith25e2ab12010-03-17 14:25:22 +05301147 udelay(500);
1148 REG_WRITE(ah, 0x50040, 0x304);
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -04001149 }
1150
Sujithf1dc5602008-10-29 10:16:30 +05301151 udelay(RTC_PLL_SETTLE_DELAY);
1152
1153 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
1154}
1155
Sujithcbe61d82009-02-09 13:27:12 +05301156static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -08001157 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301158{
Pavel Roskin152d5302010-03-31 18:05:37 -04001159 u32 imr_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +05301160 AR_IMR_TXURN |
1161 AR_IMR_RXERR |
1162 AR_IMR_RXORN |
1163 AR_IMR_BCNMISC;
1164
Sujith0ce024c2009-12-14 14:57:00 +05301165 if (ah->config.rx_intr_mitigation)
Pavel Roskin152d5302010-03-31 18:05:37 -04001166 imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
Sujithf1dc5602008-10-29 10:16:30 +05301167 else
Pavel Roskin152d5302010-03-31 18:05:37 -04001168 imr_reg |= AR_IMR_RXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301169
Pavel Roskin152d5302010-03-31 18:05:37 -04001170 imr_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301171
Colin McCabed97809d2008-12-01 13:38:55 -08001172 if (opmode == NL80211_IFTYPE_AP)
Pavel Roskin152d5302010-03-31 18:05:37 -04001173 imr_reg |= AR_IMR_MIB;
Sujithf1dc5602008-10-29 10:16:30 +05301174
Pavel Roskin152d5302010-03-31 18:05:37 -04001175 REG_WRITE(ah, AR_IMR, imr_reg);
Pavel Roskin74bad5c2010-02-23 18:15:27 -05001176 ah->imrs2_reg |= AR_IMR_S2_GTT;
1177 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
Sujithf1dc5602008-10-29 10:16:30 +05301178
1179 if (!AR_SREV_9100(ah)) {
1180 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
1181 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
1182 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
1183 }
1184}
1185
Felix Fietkau0005baf2010-01-15 02:33:40 +01001186static void ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301187{
Felix Fietkau0005baf2010-01-15 02:33:40 +01001188 u32 val = ath9k_hw_mac_to_clks(ah, us);
1189 val = min(val, (u32) 0xFFFF);
1190 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, val);
Sujithf1dc5602008-10-29 10:16:30 +05301191}
1192
Felix Fietkau0005baf2010-01-15 02:33:40 +01001193static void ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301194{
Felix Fietkau0005baf2010-01-15 02:33:40 +01001195 u32 val = ath9k_hw_mac_to_clks(ah, us);
1196 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_ACK));
1197 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_ACK, val);
1198}
1199
1200static void ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
1201{
1202 u32 val = ath9k_hw_mac_to_clks(ah, us);
1203 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_CTS));
1204 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_CTS, val);
Sujithf1dc5602008-10-29 10:16:30 +05301205}
1206
Sujithcbe61d82009-02-09 13:27:12 +05301207static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +05301208{
Sujithf1dc5602008-10-29 10:16:30 +05301209 if (tu > 0xFFFF) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001210 ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT,
1211 "bad global tx timeout %u\n", tu);
Sujith2660b812009-02-09 13:27:26 +05301212 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301213 return false;
1214 } else {
1215 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +05301216 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +05301217 return true;
1218 }
1219}
1220
Felix Fietkau0005baf2010-01-15 02:33:40 +01001221void ath9k_hw_init_global_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301222{
Felix Fietkau0005baf2010-01-15 02:33:40 +01001223 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
1224 int acktimeout;
Felix Fietkaue239d852010-01-15 02:34:58 +01001225 int slottime;
Felix Fietkau0005baf2010-01-15 02:33:40 +01001226 int sifstime;
1227
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001228 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
1229 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +05301230
Sujith2660b812009-02-09 13:27:26 +05301231 if (ah->misc_mode != 0)
Sujithf1dc5602008-10-29 10:16:30 +05301232 REG_WRITE(ah, AR_PCU_MISC,
Sujith2660b812009-02-09 13:27:26 +05301233 REG_READ(ah, AR_PCU_MISC) | ah->misc_mode);
Felix Fietkau0005baf2010-01-15 02:33:40 +01001234
1235 if (conf->channel && conf->channel->band == IEEE80211_BAND_5GHZ)
1236 sifstime = 16;
1237 else
1238 sifstime = 10;
1239
Felix Fietkaue239d852010-01-15 02:34:58 +01001240 /* As defined by IEEE 802.11-2007 17.3.8.6 */
1241 slottime = ah->slottime + 3 * ah->coverage_class;
1242 acktimeout = slottime + sifstime;
Felix Fietkau42c45682010-02-11 18:07:19 +01001243
1244 /*
1245 * Workaround for early ACK timeouts, add an offset to match the
1246 * initval's 64us ack timeout value.
1247 * This was initially only meant to work around an issue with delayed
1248 * BA frames in some implementations, but it has been found to fix ACK
1249 * timeout issues in other cases as well.
1250 */
1251 if (conf->channel && conf->channel->band == IEEE80211_BAND_2GHZ)
1252 acktimeout += 64 - sifstime - ah->slottime;
1253
Felix Fietkaue239d852010-01-15 02:34:58 +01001254 ath9k_hw_setslottime(ah, slottime);
Felix Fietkau0005baf2010-01-15 02:33:40 +01001255 ath9k_hw_set_ack_timeout(ah, acktimeout);
1256 ath9k_hw_set_cts_timeout(ah, acktimeout);
Sujith2660b812009-02-09 13:27:26 +05301257 if (ah->globaltxtimeout != (u32) -1)
1258 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Sujithf1dc5602008-10-29 10:16:30 +05301259}
Felix Fietkau0005baf2010-01-15 02:33:40 +01001260EXPORT_SYMBOL(ath9k_hw_init_global_settings);
Sujithf1dc5602008-10-29 10:16:30 +05301261
Sujith285f2dd2010-01-08 10:36:07 +05301262void ath9k_hw_deinit(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001263{
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001264 struct ath_common *common = ath9k_hw_common(ah);
1265
Sujith736b3a22010-03-17 14:25:24 +05301266 if (common->state < ATH_HW_INITIALIZED)
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001267 goto free_hw;
1268
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001269 if (!AR_SREV_9100(ah))
Luis R. Rodrigueze70c0cf2009-08-03 12:24:51 -07001270 ath9k_hw_ani_disable(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001271
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001272 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001273
1274free_hw:
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001275 ath9k_hw_rf_free_ext_banks(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001276}
Sujith285f2dd2010-01-08 10:36:07 +05301277EXPORT_SYMBOL(ath9k_hw_deinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001278
Sujithf1dc5602008-10-29 10:16:30 +05301279/*******/
1280/* INI */
1281/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001282
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001283u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan)
Bob Copeland3a702e42009-03-30 22:30:29 -04001284{
1285 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
1286
1287 if (IS_CHAN_B(chan))
1288 ctl |= CTL_11B;
1289 else if (IS_CHAN_G(chan))
1290 ctl |= CTL_11G;
1291 else
1292 ctl |= CTL_11A;
1293
1294 return ctl;
1295}
1296
Sujithf1dc5602008-10-29 10:16:30 +05301297/****************************************/
1298/* Reset and Channel Switching Routines */
1299/****************************************/
1300
Sujithcbe61d82009-02-09 13:27:12 +05301301static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301302{
1303 u32 regval;
1304
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001305 /*
1306 * set AHB_MODE not to do cacheline prefetches
1307 */
Sujithf1dc5602008-10-29 10:16:30 +05301308 regval = REG_READ(ah, AR_AHB_MODE);
1309 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
1310
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001311 /*
1312 * let mac dma reads be in 128 byte chunks
1313 */
Sujithf1dc5602008-10-29 10:16:30 +05301314 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
1315 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
1316
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001317 /*
1318 * Restore TX Trigger Level to its pre-reset value.
1319 * The initial value depends on whether aggregation is enabled, and is
1320 * adjusted whenever underruns are detected.
1321 */
Sujith2660b812009-02-09 13:27:26 +05301322 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +05301323
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001324 /*
1325 * let mac dma writes be in 128 byte chunks
1326 */
Sujithf1dc5602008-10-29 10:16:30 +05301327 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
1328 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
1329
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001330 /*
1331 * Setup receive FIFO threshold to hold off TX activities
1332 */
Sujithf1dc5602008-10-29 10:16:30 +05301333 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1334
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001335 /*
1336 * reduce the number of usable entries in PCU TXBUF to avoid
1337 * wrap around issues.
1338 */
Sujithf1dc5602008-10-29 10:16:30 +05301339 if (AR_SREV_9285(ah)) {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001340 /* For AR9285 the number of Fifos are reduced to half.
1341 * So set the usable tx buf size also to half to
1342 * avoid data/delimiter underruns
1343 */
Sujithf1dc5602008-10-29 10:16:30 +05301344 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1345 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001346 } else if (!AR_SREV_9271(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +05301347 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1348 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1349 }
1350}
1351
Sujithcbe61d82009-02-09 13:27:12 +05301352static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301353{
1354 u32 val;
1355
1356 val = REG_READ(ah, AR_STA_ID1);
1357 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
1358 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001359 case NL80211_IFTYPE_AP:
Sujithf1dc5602008-10-29 10:16:30 +05301360 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
1361 | AR_STA_ID1_KSRCH_MODE);
1362 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1363 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001364 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04001365 case NL80211_IFTYPE_MESH_POINT:
Sujithf1dc5602008-10-29 10:16:30 +05301366 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
1367 | AR_STA_ID1_KSRCH_MODE);
1368 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1369 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001370 case NL80211_IFTYPE_STATION:
1371 case NL80211_IFTYPE_MONITOR:
Sujithf1dc5602008-10-29 10:16:30 +05301372 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
1373 break;
1374 }
1375}
1376
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001377void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled,
1378 u32 *coef_mantissa, u32 *coef_exponent)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001379{
1380 u32 coef_exp, coef_man;
1381
1382 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1383 if ((coef_scaled >> coef_exp) & 0x1)
1384 break;
1385
1386 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1387
1388 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1389
1390 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1391 *coef_exponent = coef_exp - 16;
1392}
1393
Sujithcbe61d82009-02-09 13:27:12 +05301394static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +05301395{
1396 u32 rst_flags;
1397 u32 tmpReg;
1398
Sujith70768492009-02-16 13:23:12 +05301399 if (AR_SREV_9100(ah)) {
1400 u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK);
1401 val &= ~AR_RTC_DERIVED_CLK_PERIOD;
1402 val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD);
1403 REG_WRITE(ah, AR_RTC_DERIVED_CLK, val);
1404 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1405 }
1406
Sujithf1dc5602008-10-29 10:16:30 +05301407 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1408 AR_RTC_FORCE_WAKE_ON_INT);
1409
1410 if (AR_SREV_9100(ah)) {
1411 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1412 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1413 } else {
1414 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1415 if (tmpReg &
1416 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1417 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001418 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05301419 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001420
1421 val = AR_RC_HOSTIF;
1422 if (!AR_SREV_9300_20_OR_LATER(ah))
1423 val |= AR_RC_AHB;
1424 REG_WRITE(ah, AR_RC, val);
1425
1426 } else if (!AR_SREV_9300_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05301427 REG_WRITE(ah, AR_RC, AR_RC_AHB);
Sujithf1dc5602008-10-29 10:16:30 +05301428
1429 rst_flags = AR_RTC_RC_MAC_WARM;
1430 if (type == ATH9K_RESET_COLD)
1431 rst_flags |= AR_RTC_RC_MAC_COLD;
1432 }
1433
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001434 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujithf1dc5602008-10-29 10:16:30 +05301435 udelay(50);
1436
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001437 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301438 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001439 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1440 "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301441 return false;
1442 }
1443
1444 if (!AR_SREV_9100(ah))
1445 REG_WRITE(ah, AR_RC, 0);
1446
Sujithf1dc5602008-10-29 10:16:30 +05301447 if (AR_SREV_9100(ah))
1448 udelay(50);
1449
1450 return true;
1451}
1452
Sujithcbe61d82009-02-09 13:27:12 +05301453static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301454{
1455 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1456 AR_RTC_FORCE_WAKE_ON_INT);
1457
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001458 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301459 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1460
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001461 REG_WRITE(ah, AR_RTC_RESET, 0);
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301462
Senthil Balasubramanian84e21692010-04-15 17:38:30 -04001463 if (!AR_SREV_9300_20_OR_LATER(ah))
1464 udelay(2);
1465
1466 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301467 REG_WRITE(ah, AR_RC, 0);
1468
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001469 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301470
1471 if (!ath9k_hw_wait(ah,
1472 AR_RTC_STATUS,
1473 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301474 AR_RTC_STATUS_ON,
1475 AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001476 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1477 "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301478 return false;
1479 }
1480
1481 ath9k_hw_read_revisions(ah);
1482
1483 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1484}
1485
Sujithcbe61d82009-02-09 13:27:12 +05301486static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301487{
1488 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1489 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1490
1491 switch (type) {
1492 case ATH9K_RESET_POWER_ON:
1493 return ath9k_hw_set_reset_power_on(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301494 case ATH9K_RESET_WARM:
1495 case ATH9K_RESET_COLD:
1496 return ath9k_hw_set_reset(ah, type);
Sujithf1dc5602008-10-29 10:16:30 +05301497 default:
1498 return false;
1499 }
1500}
1501
Sujithcbe61d82009-02-09 13:27:12 +05301502static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301503 struct ath9k_channel *chan)
1504{
Vivek Natarajan42abfbe2009-09-17 09:27:59 +05301505 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) {
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301506 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
1507 return false;
1508 } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
Sujithf1dc5602008-10-29 10:16:30 +05301509 return false;
1510
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001511 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05301512 return false;
1513
Sujith2660b812009-02-09 13:27:26 +05301514 ah->chip_fullsleep = false;
Sujithf1dc5602008-10-29 10:16:30 +05301515 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301516 ath9k_hw_set_rfmode(ah, chan);
1517
1518 return true;
1519}
1520
Sujithcbe61d82009-02-09 13:27:12 +05301521static bool ath9k_hw_channel_change(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001522 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301523{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001524 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001525 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001526 struct ieee80211_channel *channel = chan->chan;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001527 u32 qnum;
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001528 int r;
Sujithf1dc5602008-10-29 10:16:30 +05301529
1530 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1531 if (ath9k_hw_numtxpending(ah, qnum)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001532 ath_print(common, ATH_DBG_QUEUE,
1533 "Transmit frames pending on "
1534 "queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301535 return false;
1536 }
1537 }
1538
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001539 if (!ath9k_hw_rfbus_req(ah)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001540 ath_print(common, ATH_DBG_FATAL,
1541 "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301542 return false;
1543 }
1544
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001545 ath9k_hw_set_channel_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301546
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001547 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001548 if (r) {
1549 ath_print(common, ATH_DBG_FATAL,
1550 "Failed to set channel\n");
1551 return false;
Sujithf1dc5602008-10-29 10:16:30 +05301552 }
1553
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001554 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001555 ath9k_regd_get_ctl(regulatory, chan),
Sujithf74df6f2009-02-09 13:27:24 +05301556 channel->max_antenna_gain * 2,
1557 channel->max_power * 2,
1558 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001559 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05301560
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001561 ath9k_hw_rfbus_done(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301562
1563 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1564 ath9k_hw_set_delta_slope(ah, chan);
1565
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001566 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301567
1568 if (!chan->oneTimeCalsDone)
1569 chan->oneTimeCalsDone = true;
1570
1571 return true;
1572}
1573
Sujithcbe61d82009-02-09 13:27:12 +05301574int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001575 bool bChannelChange)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001576{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001577 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001578 u32 saveLedState;
Sujith2660b812009-02-09 13:27:26 +05301579 struct ath9k_channel *curchan = ah->curchan;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001580 u32 saveDefAntenna;
1581 u32 macStaId1;
Sujith46fe7822009-09-17 09:25:25 +05301582 u64 tsf = 0;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001583 int i, r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001584
Luis R. Rodriguez43c27612009-09-13 21:07:07 -07001585 ah->txchainmask = common->tx_chainmask;
1586 ah->rxchainmask = common->rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001587
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001588 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001589 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001590
Vasanthakumar Thiagarajan9ebef7992009-09-17 09:26:44 +05301591 if (curchan && !ah->chip_fullsleep)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001592 ath9k_hw_getnf(ah, curchan);
1593
1594 if (bChannelChange &&
Sujith2660b812009-02-09 13:27:26 +05301595 (ah->chip_fullsleep != true) &&
1596 (ah->curchan != NULL) &&
1597 (chan->channel != ah->curchan->channel) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001598 ((chan->channelFlags & CHANNEL_ALL) ==
Sujith2660b812009-02-09 13:27:26 +05301599 (ah->curchan->channelFlags & CHANNEL_ALL)) &&
Vasanthakumar Thiagarajan0a475cc2009-09-17 09:27:10 +05301600 !(AR_SREV_9280(ah) || IS_CHAN_A_5MHZ_SPACED(chan) ||
1601 IS_CHAN_A_5MHZ_SPACED(ah->curchan))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001602
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001603 if (ath9k_hw_channel_change(ah, chan)) {
Sujith2660b812009-02-09 13:27:26 +05301604 ath9k_hw_loadnf(ah, ah->curchan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001605 ath9k_hw_start_nfcal(ah);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001606 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001607 }
1608 }
1609
1610 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
1611 if (saveDefAntenna == 0)
1612 saveDefAntenna = 1;
1613
1614 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
1615
Sujith46fe7822009-09-17 09:25:25 +05301616 /* For chips on which RTC reset is done, save TSF before it gets cleared */
1617 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1618 tsf = ath9k_hw_gettsf64(ah);
1619
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001620 saveLedState = REG_READ(ah, AR_CFG_LED) &
1621 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
1622 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
1623
1624 ath9k_hw_mark_phy_inactive(ah);
1625
Sujith05020d22010-03-17 14:25:23 +05301626 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001627 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1628 REG_WRITE(ah,
1629 AR9271_RESET_POWER_DOWN_CONTROL,
1630 AR9271_RADIO_RF_RST);
1631 udelay(50);
1632 }
1633
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001634 if (!ath9k_hw_chip_reset(ah, chan)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001635 ath_print(common, ATH_DBG_FATAL, "Chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001636 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001637 }
1638
Sujith05020d22010-03-17 14:25:23 +05301639 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001640 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1641 ah->htc_reset_init = false;
1642 REG_WRITE(ah,
1643 AR9271_RESET_POWER_DOWN_CONTROL,
1644 AR9271_GATE_MAC_CTL);
1645 udelay(50);
1646 }
1647
Sujith46fe7822009-09-17 09:25:25 +05301648 /* Restore TSF */
1649 if (tsf && AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1650 ath9k_hw_settsf64(ah, tsf);
1651
Vasanthakumar Thiagarajan369391d2009-01-21 19:24:13 +05301652 if (AR_SREV_9280_10_OR_LATER(ah))
1653 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001654
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001655 r = ath9k_hw_process_ini(ah, chan);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001656 if (r)
1657 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001658
Jouni Malinen0ced0e12009-01-08 13:32:13 +02001659 /* Setup MFP options for CCMP */
1660 if (AR_SREV_9280_20_OR_LATER(ah)) {
1661 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
1662 * frames when constructing CCMP AAD. */
1663 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
1664 0xc7ff);
1665 ah->sw_mgmt_crypto = false;
1666 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1667 /* Disable hardware crypto for management frames */
1668 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
1669 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
1670 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1671 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
1672 ah->sw_mgmt_crypto = true;
1673 } else
1674 ah->sw_mgmt_crypto = true;
1675
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001676 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1677 ath9k_hw_set_delta_slope(ah, chan);
1678
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001679 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithd6509152009-03-13 08:56:05 +05301680 ah->eep_ops->set_board_values(ah, chan);
Luis R. Rodrigueza7765822009-10-19 02:33:45 -04001681
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001682 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
1683 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001684 | macStaId1
1685 | AR_STA_ID1_RTS_USE_DEF
Sujith2660b812009-02-09 13:27:26 +05301686 | (ah->config.
Sujith60b67f52008-08-07 10:52:38 +05301687 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Sujith2660b812009-02-09 13:27:26 +05301688 | ah->sta_id1_defaults);
1689 ath9k_hw_set_operating_mode(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001690
Luis R. Rodriguez13b81552009-09-10 17:52:45 -07001691 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001692
1693 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
1694
Luis R. Rodriguez3453ad82009-09-10 08:57:00 -07001695 ath9k_hw_write_associd(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001696
1697 REG_WRITE(ah, AR_ISR, ~0);
1698
1699 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
1700
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001701 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001702 if (r)
1703 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001704
1705 for (i = 0; i < AR_NUM_DCU; i++)
1706 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
1707
Sujith2660b812009-02-09 13:27:26 +05301708 ah->intr_txqs = 0;
1709 for (i = 0; i < ah->caps.total_queues; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001710 ath9k_hw_resettxqueue(ah, i);
1711
Sujith2660b812009-02-09 13:27:26 +05301712 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001713 ath9k_hw_init_qos(ah);
1714
Sujith2660b812009-02-09 13:27:26 +05301715 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301716 ath9k_enable_rfkill(ah);
Johannes Berg3b319aa2009-06-13 14:50:26 +05301717
Felix Fietkau0005baf2010-01-15 02:33:40 +01001718 ath9k_hw_init_global_settings(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001719
Vivek Natarajan326bebb2009-08-14 11:33:36 +05301720 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301721 REG_WRITE(ah, AR_D_GBL_IFS_SIFS,
1722 AR_D_GBL_IFS_SIFS_ASYNC_FIFO_DUR);
1723 REG_WRITE(ah, AR_D_GBL_IFS_SLOT,
1724 AR_D_GBL_IFS_SLOT_ASYNC_FIFO_DUR);
1725 REG_WRITE(ah, AR_D_GBL_IFS_EIFS,
1726 AR_D_GBL_IFS_EIFS_ASYNC_FIFO_DUR);
1727
1728 REG_WRITE(ah, AR_TIME_OUT, AR_TIME_OUT_ACK_CTS_ASYNC_FIFO_DUR);
1729 REG_WRITE(ah, AR_USEC, AR_USEC_ASYNC_FIFO_DUR);
1730
1731 REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
1732 AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
1733 REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
1734 AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
1735 }
Vivek Natarajan326bebb2009-08-14 11:33:36 +05301736 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301737 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1738 AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
1739 }
1740
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001741 REG_WRITE(ah, AR_STA_ID1,
1742 REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
1743
1744 ath9k_hw_set_dma(ah);
1745
1746 REG_WRITE(ah, AR_OBS, 8);
1747
Sujith0ce024c2009-12-14 14:57:00 +05301748 if (ah->config.rx_intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001749 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
1750 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
1751 }
1752
1753 ath9k_hw_init_bb(ah, chan);
1754
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001755 if (!ath9k_hw_init_cal(ah, chan))
Joe Perches6badaaf2009-06-28 09:26:32 -07001756 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001757
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001758 ath9k_hw_restore_chainmask(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001759 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
1760
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001761 /*
1762 * For big endian systems turn on swapping for descriptors
1763 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001764 if (AR_SREV_9100(ah)) {
1765 u32 mask;
1766 mask = REG_READ(ah, AR_CFG);
1767 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001768 ath_print(common, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05301769 "CFG Byte Swap Set 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001770 } else {
1771 mask =
1772 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
1773 REG_WRITE(ah, AR_CFG, mask);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001774 ath_print(common, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05301775 "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001776 }
1777 } else {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001778 /* Configure AR9271 target WLAN */
1779 if (AR_SREV_9271(ah))
1780 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001781#ifdef __BIG_ENDIAN
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001782 else
1783 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001784#endif
1785 }
1786
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001787 if (ah->btcoex_hw.enabled)
Vasanthakumar Thiagarajan42cc41e2009-08-26 21:08:45 +05301788 ath9k_hw_btcoex_enable(ah);
1789
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001790 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001791}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001792EXPORT_SYMBOL(ath9k_hw_reset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001793
Sujithf1dc5602008-10-29 10:16:30 +05301794/************************/
1795/* Key Cache Management */
1796/************************/
1797
Sujithcbe61d82009-02-09 13:27:12 +05301798bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001799{
Sujithf1dc5602008-10-29 10:16:30 +05301800 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001801
Sujith2660b812009-02-09 13:27:26 +05301802 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001803 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1804 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001805 return false;
1806 }
1807
Sujithf1dc5602008-10-29 10:16:30 +05301808 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001809
Sujithf1dc5602008-10-29 10:16:30 +05301810 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
1811 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
1812 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
1813 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
1814 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
1815 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
1816 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
1817 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
1818
1819 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
1820 u16 micentry = entry + 64;
1821
1822 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
1823 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
1824 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
1825 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
1826
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001827 }
1828
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001829 return true;
1830}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001831EXPORT_SYMBOL(ath9k_hw_keyreset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001832
Sujithcbe61d82009-02-09 13:27:12 +05301833bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001834{
Sujithf1dc5602008-10-29 10:16:30 +05301835 u32 macHi, macLo;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001836
Sujith2660b812009-02-09 13:27:26 +05301837 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001838 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1839 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001840 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001841 }
1842
Sujithf1dc5602008-10-29 10:16:30 +05301843 if (mac != NULL) {
1844 macHi = (mac[5] << 8) | mac[4];
1845 macLo = (mac[3] << 24) |
1846 (mac[2] << 16) |
1847 (mac[1] << 8) |
1848 mac[0];
1849 macLo >>= 1;
1850 macLo |= (macHi & 1) << 31;
1851 macHi >>= 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001852 } else {
Sujithf1dc5602008-10-29 10:16:30 +05301853 macLo = macHi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001854 }
Sujithf1dc5602008-10-29 10:16:30 +05301855 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
1856 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001857
1858 return true;
1859}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001860EXPORT_SYMBOL(ath9k_hw_keysetmac);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001861
Sujithcbe61d82009-02-09 13:27:12 +05301862bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
Sujithf1dc5602008-10-29 10:16:30 +05301863 const struct ath9k_keyval *k,
Jouni Malinene0caf9e2009-03-02 18:15:53 +02001864 const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001865{
Sujith2660b812009-02-09 13:27:26 +05301866 const struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001867 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301868 u32 key0, key1, key2, key3, key4;
1869 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001870
Sujithf1dc5602008-10-29 10:16:30 +05301871 if (entry >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001872 ath_print(common, ATH_DBG_FATAL,
1873 "keycache entry %u out of range\n", entry);
Sujithf1dc5602008-10-29 10:16:30 +05301874 return false;
1875 }
1876
1877 switch (k->kv_type) {
1878 case ATH9K_CIPHER_AES_OCB:
1879 keyType = AR_KEYTABLE_TYPE_AES;
1880 break;
1881 case ATH9K_CIPHER_AES_CCM:
1882 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001883 ath_print(common, ATH_DBG_ANY,
1884 "AES-CCM not supported by mac rev 0x%x\n",
1885 ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001886 return false;
1887 }
Sujithf1dc5602008-10-29 10:16:30 +05301888 keyType = AR_KEYTABLE_TYPE_CCM;
1889 break;
1890 case ATH9K_CIPHER_TKIP:
1891 keyType = AR_KEYTABLE_TYPE_TKIP;
1892 if (ATH9K_IS_MIC_ENABLED(ah)
1893 && entry + 64 >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001894 ath_print(common, ATH_DBG_ANY,
1895 "entry %u inappropriate for TKIP\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001896 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001897 }
Sujithf1dc5602008-10-29 10:16:30 +05301898 break;
1899 case ATH9K_CIPHER_WEP:
Zhu Yie31a16d2009-05-21 21:47:03 +08001900 if (k->kv_len < WLAN_KEY_LEN_WEP40) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001901 ath_print(common, ATH_DBG_ANY,
1902 "WEP key length %u too small\n", k->kv_len);
Sujithf1dc5602008-10-29 10:16:30 +05301903 return false;
1904 }
Zhu Yie31a16d2009-05-21 21:47:03 +08001905 if (k->kv_len <= WLAN_KEY_LEN_WEP40)
Sujithf1dc5602008-10-29 10:16:30 +05301906 keyType = AR_KEYTABLE_TYPE_40;
Zhu Yie31a16d2009-05-21 21:47:03 +08001907 else if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05301908 keyType = AR_KEYTABLE_TYPE_104;
1909 else
1910 keyType = AR_KEYTABLE_TYPE_128;
1911 break;
1912 case ATH9K_CIPHER_CLR:
1913 keyType = AR_KEYTABLE_TYPE_CLR;
1914 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001915 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001916 ath_print(common, ATH_DBG_FATAL,
1917 "cipher %u not supported\n", k->kv_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001918 return false;
1919 }
Sujithf1dc5602008-10-29 10:16:30 +05301920
Jouni Malinene0caf9e2009-03-02 18:15:53 +02001921 key0 = get_unaligned_le32(k->kv_val + 0);
1922 key1 = get_unaligned_le16(k->kv_val + 4);
1923 key2 = get_unaligned_le32(k->kv_val + 6);
1924 key3 = get_unaligned_le16(k->kv_val + 10);
1925 key4 = get_unaligned_le32(k->kv_val + 12);
Zhu Yie31a16d2009-05-21 21:47:03 +08001926 if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05301927 key4 &= 0xff;
1928
Jouni Malinen672903b2009-03-02 15:06:31 +02001929 /*
1930 * Note: Key cache registers access special memory area that requires
1931 * two 32-bit writes to actually update the values in the internal
1932 * memory. Consequently, the exact order and pairs used here must be
1933 * maintained.
1934 */
1935
Sujithf1dc5602008-10-29 10:16:30 +05301936 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
1937 u16 micentry = entry + 64;
1938
Jouni Malinen672903b2009-03-02 15:06:31 +02001939 /*
1940 * Write inverted key[47:0] first to avoid Michael MIC errors
1941 * on frames that could be sent or received at the same time.
1942 * The correct key will be written in the end once everything
1943 * else is ready.
1944 */
Sujithf1dc5602008-10-29 10:16:30 +05301945 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
1946 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02001947
1948 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05301949 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
1950 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02001951
1952 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05301953 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
1954 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
Jouni Malinen672903b2009-03-02 15:06:31 +02001955
1956 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05301957 (void) ath9k_hw_keysetmac(ah, entry, mac);
1958
Sujith2660b812009-02-09 13:27:26 +05301959 if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) {
Jouni Malinen672903b2009-03-02 15:06:31 +02001960 /*
1961 * TKIP uses two key cache entries:
1962 * Michael MIC TX/RX keys in the same key cache entry
1963 * (idx = main index + 64):
1964 * key0 [31:0] = RX key [31:0]
1965 * key1 [15:0] = TX key [31:16]
1966 * key1 [31:16] = reserved
1967 * key2 [31:0] = RX key [63:32]
1968 * key3 [15:0] = TX key [15:0]
1969 * key3 [31:16] = reserved
1970 * key4 [31:0] = TX key [63:32]
1971 */
Sujithf1dc5602008-10-29 10:16:30 +05301972 u32 mic0, mic1, mic2, mic3, mic4;
1973
1974 mic0 = get_unaligned_le32(k->kv_mic + 0);
1975 mic2 = get_unaligned_le32(k->kv_mic + 4);
1976 mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
1977 mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
1978 mic4 = get_unaligned_le32(k->kv_txmic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02001979
1980 /* Write RX[31:0] and TX[31:16] */
Sujithf1dc5602008-10-29 10:16:30 +05301981 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
1982 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
Jouni Malinen672903b2009-03-02 15:06:31 +02001983
1984 /* Write RX[63:32] and TX[15:0] */
Sujithf1dc5602008-10-29 10:16:30 +05301985 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
1986 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
Jouni Malinen672903b2009-03-02 15:06:31 +02001987
1988 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05301989 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
1990 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
1991 AR_KEYTABLE_TYPE_CLR);
1992
1993 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02001994 /*
1995 * TKIP uses four key cache entries (two for group
1996 * keys):
1997 * Michael MIC TX/RX keys are in different key cache
1998 * entries (idx = main index + 64 for TX and
1999 * main index + 32 + 96 for RX):
2000 * key0 [31:0] = TX/RX MIC key [31:0]
2001 * key1 [31:0] = reserved
2002 * key2 [31:0] = TX/RX MIC key [63:32]
2003 * key3 [31:0] = reserved
2004 * key4 [31:0] = reserved
2005 *
2006 * Upper layer code will call this function separately
2007 * for TX and RX keys when these registers offsets are
2008 * used.
2009 */
Sujithf1dc5602008-10-29 10:16:30 +05302010 u32 mic0, mic2;
2011
2012 mic0 = get_unaligned_le32(k->kv_mic + 0);
2013 mic2 = get_unaligned_le32(k->kv_mic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02002014
2015 /* Write MIC key[31:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302016 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2017 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002018
2019 /* Write MIC key[63:32] */
Sujithf1dc5602008-10-29 10:16:30 +05302020 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2021 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002022
2023 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302024 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
2025 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2026 AR_KEYTABLE_TYPE_CLR);
2027 }
Jouni Malinen672903b2009-03-02 15:06:31 +02002028
2029 /* MAC address registers are reserved for the MIC entry */
Sujithf1dc5602008-10-29 10:16:30 +05302030 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
2031 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002032
2033 /*
2034 * Write the correct (un-inverted) key[47:0] last to enable
2035 * TKIP now that all other registers are set with correct
2036 * values.
2037 */
Sujithf1dc5602008-10-29 10:16:30 +05302038 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2039 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
2040 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002041 /* Write key[47:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302042 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2043 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002044
2045 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302046 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2047 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002048
2049 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302050 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2051 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
2052
Jouni Malinen672903b2009-03-02 15:06:31 +02002053 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302054 (void) ath9k_hw_keysetmac(ah, entry, mac);
2055 }
2056
Sujithf1dc5602008-10-29 10:16:30 +05302057 return true;
2058}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002059EXPORT_SYMBOL(ath9k_hw_set_keycache_entry);
Sujithf1dc5602008-10-29 10:16:30 +05302060
Sujithcbe61d82009-02-09 13:27:12 +05302061bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry)
Sujithf1dc5602008-10-29 10:16:30 +05302062{
Sujith2660b812009-02-09 13:27:26 +05302063 if (entry < ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05302064 u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
2065 if (val & AR_KEYTABLE_VALID)
2066 return true;
2067 }
2068 return false;
2069}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002070EXPORT_SYMBOL(ath9k_hw_keyisvalid);
Sujithf1dc5602008-10-29 10:16:30 +05302071
2072/******************************/
2073/* Power Management (Chipset) */
2074/******************************/
2075
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04002076/*
2077 * Notify Power Mgt is disabled in self-generated frames.
2078 * If requested, force chip to sleep.
2079 */
Sujithcbe61d82009-02-09 13:27:12 +05302080static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302081{
2082 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2083 if (setChip) {
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04002084 /*
2085 * Clear the RTC force wake bit to allow the
2086 * mac to go to sleep.
2087 */
Sujithf1dc5602008-10-29 10:16:30 +05302088 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2089 AR_RTC_FORCE_WAKE_EN);
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04002090 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302091 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
2092
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04002093 /* Shutdown chip. Active low */
Sujith14b3af32010-03-17 14:25:18 +05302094 if (!AR_SREV_5416(ah) && !AR_SREV_9271(ah))
Sujith4921be82009-09-18 15:04:27 +05302095 REG_CLR_BIT(ah, (AR_RTC_RESET),
2096 AR_RTC_RESET_EN);
Sujithf1dc5602008-10-29 10:16:30 +05302097 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002098}
2099
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04002100/*
2101 * Notify Power Management is enabled in self-generating
2102 * frames. If request, set power mode of chip to
2103 * auto/normal. Duration in units of 128us (1/8 TU).
2104 */
Sujithcbe61d82009-02-09 13:27:12 +05302105static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002106{
Sujithf1dc5602008-10-29 10:16:30 +05302107 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2108 if (setChip) {
Sujith2660b812009-02-09 13:27:26 +05302109 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002110
Sujithf1dc5602008-10-29 10:16:30 +05302111 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04002112 /* Set WakeOnInterrupt bit; clear ForceWake bit */
Sujithf1dc5602008-10-29 10:16:30 +05302113 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2114 AR_RTC_FORCE_WAKE_ON_INT);
2115 } else {
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04002116 /*
2117 * Clear the RTC force wake bit to allow the
2118 * mac to go to sleep.
2119 */
Sujithf1dc5602008-10-29 10:16:30 +05302120 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2121 AR_RTC_FORCE_WAKE_EN);
2122 }
2123 }
2124}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002125
Sujithcbe61d82009-02-09 13:27:12 +05302126static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302127{
2128 u32 val;
2129 int i;
2130
2131 if (setChip) {
2132 if ((REG_READ(ah, AR_RTC_STATUS) &
2133 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2134 if (ath9k_hw_set_reset_reg(ah,
2135 ATH9K_RESET_POWER_ON) != true) {
2136 return false;
2137 }
Luis R. Rodrigueze0412282010-04-15 17:38:15 -04002138 if (!AR_SREV_9300_20_OR_LATER(ah))
2139 ath9k_hw_init_pll(ah, NULL);
Sujithf1dc5602008-10-29 10:16:30 +05302140 }
2141 if (AR_SREV_9100(ah))
2142 REG_SET_BIT(ah, AR_RTC_RESET,
2143 AR_RTC_RESET_EN);
2144
2145 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2146 AR_RTC_FORCE_WAKE_EN);
2147 udelay(50);
2148
2149 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2150 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2151 if (val == AR_RTC_STATUS_ON)
2152 break;
2153 udelay(50);
2154 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2155 AR_RTC_FORCE_WAKE_EN);
2156 }
2157 if (i == 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002158 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2159 "Failed to wakeup in %uus\n",
2160 POWER_UP_TIME / 20);
Sujithf1dc5602008-10-29 10:16:30 +05302161 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002162 }
2163 }
2164
Sujithf1dc5602008-10-29 10:16:30 +05302165 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2166
2167 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002168}
2169
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002170bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05302171{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002172 struct ath_common *common = ath9k_hw_common(ah);
Sujithcbe61d82009-02-09 13:27:12 +05302173 int status = true, setChip = true;
Sujithf1dc5602008-10-29 10:16:30 +05302174 static const char *modes[] = {
2175 "AWAKE",
2176 "FULL-SLEEP",
2177 "NETWORK SLEEP",
2178 "UNDEFINED"
2179 };
Sujithf1dc5602008-10-29 10:16:30 +05302180
Gabor Juhoscbdec972009-07-24 17:27:22 +02002181 if (ah->power_mode == mode)
2182 return status;
2183
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002184 ath_print(common, ATH_DBG_RESET, "%s -> %s\n",
2185 modes[ah->power_mode], modes[mode]);
Sujithf1dc5602008-10-29 10:16:30 +05302186
2187 switch (mode) {
2188 case ATH9K_PM_AWAKE:
2189 status = ath9k_hw_set_power_awake(ah, setChip);
2190 break;
2191 case ATH9K_PM_FULL_SLEEP:
2192 ath9k_set_power_sleep(ah, setChip);
Sujith2660b812009-02-09 13:27:26 +05302193 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05302194 break;
2195 case ATH9K_PM_NETWORK_SLEEP:
2196 ath9k_set_power_network_sleep(ah, setChip);
2197 break;
2198 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002199 ath_print(common, ATH_DBG_FATAL,
2200 "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05302201 return false;
2202 }
Sujith2660b812009-02-09 13:27:26 +05302203 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05302204
2205 return status;
2206}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002207EXPORT_SYMBOL(ath9k_hw_setpower);
Sujithf1dc5602008-10-29 10:16:30 +05302208
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002209/*
2210 * Helper for ASPM support.
2211 *
2212 * Disable PLL when in L0s as well as receiver clock when in L1.
2213 * This power saving option must be enabled through the SerDes.
2214 *
2215 * Programming the SerDes must go through the same 288 bit serial shift
2216 * register as the other analog registers. Hence the 9 writes.
2217 */
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04002218static void ar9002_hw_configpcipowersave(struct ath_hw *ah,
2219 int restore,
2220 int power_off)
Sujithf1dc5602008-10-29 10:16:30 +05302221{
Sujithf1dc5602008-10-29 10:16:30 +05302222 u8 i;
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302223 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05302224
Sujith2660b812009-02-09 13:27:26 +05302225 if (ah->is_pciexpress != true)
Sujithf1dc5602008-10-29 10:16:30 +05302226 return;
2227
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002228 /* Do not touch SerDes registers */
Sujith2660b812009-02-09 13:27:26 +05302229 if (ah->config.pcie_powersave_enable == 2)
Sujithf1dc5602008-10-29 10:16:30 +05302230 return;
2231
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002232 /* Nothing to do on restore for 11N */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302233 if (!restore) {
2234 if (AR_SREV_9280_20_OR_LATER(ah)) {
2235 /*
2236 * AR9280 2.0 or later chips use SerDes values from the
2237 * initvals.h initialized depending on chipset during
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04002238 * __ath9k_hw_init()
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302239 */
2240 for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
2241 REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
2242 INI_RA(&ah->iniPcieSerdes, i, 1));
2243 }
2244 } else if (AR_SREV_9280(ah) &&
2245 (ah->hw_version.macRev == AR_SREV_REVISION_9280_10)) {
2246 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
2247 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
Sujithf1dc5602008-10-29 10:16:30 +05302248
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302249 /* RX shut off when elecidle is asserted */
2250 REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
2251 REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
2252 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
2253
2254 /* Shut off CLKREQ active in L1 */
2255 if (ah->config.pcie_clock_req)
2256 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
2257 else
2258 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
2259
2260 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2261 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2262 REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
2263
2264 /* Load the new settings */
2265 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
2266
2267 } else {
2268 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
2269 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
2270
2271 /* RX shut off when elecidle is asserted */
2272 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
2273 REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
2274 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
2275
2276 /*
2277 * Ignore ah->ah_config.pcie_clock_req setting for
2278 * pre-AR9280 11n
2279 */
2280 REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
2281
2282 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2283 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2284 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
2285
2286 /* Load the new settings */
2287 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
Sujithf1dc5602008-10-29 10:16:30 +05302288 }
Sujithf1dc5602008-10-29 10:16:30 +05302289
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302290 udelay(1000);
Sujithf1dc5602008-10-29 10:16:30 +05302291
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302292 /* set bit 19 to allow forcing of pcie core into L1 state */
2293 REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
Sujithf1dc5602008-10-29 10:16:30 +05302294
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302295 /* Several PCIe massages to ensure proper behaviour */
2296 if (ah->config.pcie_waen) {
2297 val = ah->config.pcie_waen;
2298 if (!power_off)
2299 val &= (~AR_WA_D3_L1_DISABLE);
2300 } else {
2301 if (AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
2302 AR_SREV_9287(ah)) {
2303 val = AR9285_WA_DEFAULT;
2304 if (!power_off)
2305 val &= (~AR_WA_D3_L1_DISABLE);
2306 } else if (AR_SREV_9280(ah)) {
2307 /*
2308 * On AR9280 chips bit 22 of 0x4004 needs to be
2309 * set otherwise card may disappear.
2310 */
2311 val = AR9280_WA_DEFAULT;
2312 if (!power_off)
2313 val &= (~AR_WA_D3_L1_DISABLE);
2314 } else
2315 val = AR_WA_DEFAULT;
2316 }
Sujithf1dc5602008-10-29 10:16:30 +05302317
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302318 REG_WRITE(ah, AR_WA, val);
Sujithf1dc5602008-10-29 10:16:30 +05302319 }
2320
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302321 if (power_off) {
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002322 /*
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302323 * Set PCIe workaround bits
2324 * bit 14 in WA register (disable L1) should only
2325 * be set when device enters D3 and be cleared
2326 * when device comes back to D0.
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002327 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302328 if (ah->config.pcie_waen) {
2329 if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE)
2330 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
2331 } else {
2332 if (((AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
2333 AR_SREV_9287(ah)) &&
2334 (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)) ||
2335 (AR_SREV_9280(ah) &&
2336 (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE))) {
2337 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
2338 }
2339 }
Sujithf1dc5602008-10-29 10:16:30 +05302340 }
2341}
2342
2343/**********************/
2344/* Interrupt Handling */
2345/**********************/
2346
Sujithcbe61d82009-02-09 13:27:12 +05302347bool ath9k_hw_intrpend(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002348{
2349 u32 host_isr;
2350
2351 if (AR_SREV_9100(ah))
2352 return true;
2353
2354 host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
2355 if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
2356 return true;
2357
2358 host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
2359 if ((host_isr & AR_INTR_SYNC_DEFAULT)
2360 && (host_isr != AR_INTR_SPURIOUS))
2361 return true;
2362
2363 return false;
2364}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002365EXPORT_SYMBOL(ath9k_hw_intrpend);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002366
Sujithcbe61d82009-02-09 13:27:12 +05302367bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002368{
2369 u32 isr = 0;
2370 u32 mask2 = 0;
Sujith2660b812009-02-09 13:27:26 +05302371 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002372 u32 sync_cause = 0;
2373 bool fatal_int = false;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002374 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002375
2376 if (!AR_SREV_9100(ah)) {
2377 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
2378 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
2379 == AR_RTC_STATUS_ON) {
2380 isr = REG_READ(ah, AR_ISR);
2381 }
2382 }
2383
Sujithf1dc5602008-10-29 10:16:30 +05302384 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
2385 AR_INTR_SYNC_DEFAULT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002386
2387 *masked = 0;
2388
2389 if (!isr && !sync_cause)
2390 return false;
2391 } else {
2392 *masked = 0;
2393 isr = REG_READ(ah, AR_ISR);
2394 }
2395
2396 if (isr) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002397 if (isr & AR_ISR_BCNMISC) {
2398 u32 isr2;
2399 isr2 = REG_READ(ah, AR_ISR_S2);
2400 if (isr2 & AR_ISR_S2_TIM)
2401 mask2 |= ATH9K_INT_TIM;
2402 if (isr2 & AR_ISR_S2_DTIM)
2403 mask2 |= ATH9K_INT_DTIM;
2404 if (isr2 & AR_ISR_S2_DTIMSYNC)
2405 mask2 |= ATH9K_INT_DTIMSYNC;
2406 if (isr2 & (AR_ISR_S2_CABEND))
2407 mask2 |= ATH9K_INT_CABEND;
2408 if (isr2 & AR_ISR_S2_GTT)
2409 mask2 |= ATH9K_INT_GTT;
2410 if (isr2 & AR_ISR_S2_CST)
2411 mask2 |= ATH9K_INT_CST;
Sujith4af9cf42009-02-12 10:06:47 +05302412 if (isr2 & AR_ISR_S2_TSFOOR)
2413 mask2 |= ATH9K_INT_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002414 }
2415
2416 isr = REG_READ(ah, AR_ISR_RAC);
2417 if (isr == 0xffffffff) {
2418 *masked = 0;
2419 return false;
2420 }
2421
2422 *masked = isr & ATH9K_INT_COMMON;
2423
Sujith0ce024c2009-12-14 14:57:00 +05302424 if (ah->config.rx_intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002425 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
2426 *masked |= ATH9K_INT_RX;
2427 }
2428
2429 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
2430 *masked |= ATH9K_INT_RX;
2431 if (isr &
2432 (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
2433 AR_ISR_TXEOL)) {
2434 u32 s0_s, s1_s;
2435
2436 *masked |= ATH9K_INT_TX;
2437
2438 s0_s = REG_READ(ah, AR_ISR_S0_S);
Sujith2660b812009-02-09 13:27:26 +05302439 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
2440 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002441
2442 s1_s = REG_READ(ah, AR_ISR_S1_S);
Sujith2660b812009-02-09 13:27:26 +05302443 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
2444 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002445 }
2446
2447 if (isr & AR_ISR_RXORN) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002448 ath_print(common, ATH_DBG_INTERRUPT,
2449 "receive FIFO overrun interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002450 }
2451
2452 if (!AR_SREV_9100(ah)) {
Sujith60b67f52008-08-07 10:52:38 +05302453 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002454 u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
2455 if (isr5 & AR_ISR_S5_TIM_TIMER)
2456 *masked |= ATH9K_INT_TIM_TIMER;
2457 }
2458 }
2459
2460 *masked |= mask2;
2461 }
Sujithf1dc5602008-10-29 10:16:30 +05302462
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002463 if (AR_SREV_9100(ah))
2464 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302465
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302466 if (isr & AR_ISR_GENTMR) {
2467 u32 s5_s;
2468
2469 s5_s = REG_READ(ah, AR_ISR_S5_S);
2470 if (isr & AR_ISR_GENTMR) {
2471 ah->intr_gen_timer_trigger =
2472 MS(s5_s, AR_ISR_S5_GENTIMER_TRIG);
2473
2474 ah->intr_gen_timer_thresh =
2475 MS(s5_s, AR_ISR_S5_GENTIMER_THRESH);
2476
2477 if (ah->intr_gen_timer_trigger)
2478 *masked |= ATH9K_INT_GENTIMER;
2479
2480 }
2481 }
2482
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002483 if (sync_cause) {
2484 fatal_int =
2485 (sync_cause &
2486 (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
2487 ? true : false;
2488
2489 if (fatal_int) {
2490 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002491 ath_print(common, ATH_DBG_ANY,
2492 "received PCI FATAL interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002493 }
2494 if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002495 ath_print(common, ATH_DBG_ANY,
2496 "received PCI PERR interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002497 }
Steven Luoa89bff92009-04-12 02:57:54 -07002498 *masked |= ATH9K_INT_FATAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002499 }
2500 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002501 ath_print(common, ATH_DBG_INTERRUPT,
2502 "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002503 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
2504 REG_WRITE(ah, AR_RC, 0);
2505 *masked |= ATH9K_INT_FATAL;
2506 }
2507 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002508 ath_print(common, ATH_DBG_INTERRUPT,
2509 "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002510 }
2511
2512 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
2513 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
2514 }
Sujithf1dc5602008-10-29 10:16:30 +05302515
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002516 return true;
2517}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002518EXPORT_SYMBOL(ath9k_hw_getisr);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002519
Sujithcbe61d82009-02-09 13:27:12 +05302520enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002521{
Pavel Roskin152d5302010-03-31 18:05:37 -04002522 enum ath9k_int omask = ah->imask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002523 u32 mask, mask2;
Sujith2660b812009-02-09 13:27:26 +05302524 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002525 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002526
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002527 ath_print(common, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002528
2529 if (omask & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002530 ath_print(common, ATH_DBG_INTERRUPT, "disable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002531 REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
2532 (void) REG_READ(ah, AR_IER);
2533 if (!AR_SREV_9100(ah)) {
2534 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
2535 (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
2536
2537 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
2538 (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
2539 }
2540 }
2541
2542 mask = ints & ATH9K_INT_COMMON;
2543 mask2 = 0;
2544
2545 if (ints & ATH9K_INT_TX) {
Sujith2660b812009-02-09 13:27:26 +05302546 if (ah->txok_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002547 mask |= AR_IMR_TXOK;
Sujith2660b812009-02-09 13:27:26 +05302548 if (ah->txdesc_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002549 mask |= AR_IMR_TXDESC;
Sujith2660b812009-02-09 13:27:26 +05302550 if (ah->txerr_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002551 mask |= AR_IMR_TXERR;
Sujith2660b812009-02-09 13:27:26 +05302552 if (ah->txeol_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002553 mask |= AR_IMR_TXEOL;
2554 }
2555 if (ints & ATH9K_INT_RX) {
2556 mask |= AR_IMR_RXERR;
Sujith0ce024c2009-12-14 14:57:00 +05302557 if (ah->config.rx_intr_mitigation)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002558 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
2559 else
2560 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
Sujith60b67f52008-08-07 10:52:38 +05302561 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002562 mask |= AR_IMR_GENTMR;
2563 }
2564
2565 if (ints & (ATH9K_INT_BMISC)) {
2566 mask |= AR_IMR_BCNMISC;
2567 if (ints & ATH9K_INT_TIM)
2568 mask2 |= AR_IMR_S2_TIM;
2569 if (ints & ATH9K_INT_DTIM)
2570 mask2 |= AR_IMR_S2_DTIM;
2571 if (ints & ATH9K_INT_DTIMSYNC)
2572 mask2 |= AR_IMR_S2_DTIMSYNC;
2573 if (ints & ATH9K_INT_CABEND)
Sujith4af9cf42009-02-12 10:06:47 +05302574 mask2 |= AR_IMR_S2_CABEND;
2575 if (ints & ATH9K_INT_TSFOOR)
2576 mask2 |= AR_IMR_S2_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002577 }
2578
2579 if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
2580 mask |= AR_IMR_BCNMISC;
2581 if (ints & ATH9K_INT_GTT)
2582 mask2 |= AR_IMR_S2_GTT;
2583 if (ints & ATH9K_INT_CST)
2584 mask2 |= AR_IMR_S2_CST;
2585 }
2586
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002587 ath_print(common, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002588 REG_WRITE(ah, AR_IMR, mask);
Pavel Roskin74bad5c2010-02-23 18:15:27 -05002589 ah->imrs2_reg &= ~(AR_IMR_S2_TIM | AR_IMR_S2_DTIM | AR_IMR_S2_DTIMSYNC |
2590 AR_IMR_S2_CABEND | AR_IMR_S2_CABTO |
2591 AR_IMR_S2_TSFOOR | AR_IMR_S2_GTT | AR_IMR_S2_CST);
2592 ah->imrs2_reg |= mask2;
2593 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002594
Sujith60b67f52008-08-07 10:52:38 +05302595 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002596 if (ints & ATH9K_INT_TIM_TIMER)
2597 REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
2598 else
2599 REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
2600 }
2601
2602 if (ints & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002603 ath_print(common, ATH_DBG_INTERRUPT, "enable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002604 REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
2605 if (!AR_SREV_9100(ah)) {
2606 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
2607 AR_INTR_MAC_IRQ);
2608 REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
2609
2610
2611 REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
2612 AR_INTR_SYNC_DEFAULT);
2613 REG_WRITE(ah, AR_INTR_SYNC_MASK,
2614 AR_INTR_SYNC_DEFAULT);
2615 }
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002616 ath_print(common, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
2617 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002618 }
2619
2620 return omask;
2621}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002622EXPORT_SYMBOL(ath9k_hw_set_interrupts);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002623
Sujithf1dc5602008-10-29 10:16:30 +05302624/*******************/
2625/* Beacon Handling */
2626/*******************/
2627
Sujithcbe61d82009-02-09 13:27:12 +05302628void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002629{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002630 int flags = 0;
2631
Sujith2660b812009-02-09 13:27:26 +05302632 ah->beacon_interval = beacon_period;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002633
Sujith2660b812009-02-09 13:27:26 +05302634 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08002635 case NL80211_IFTYPE_STATION:
2636 case NL80211_IFTYPE_MONITOR:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002637 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
2638 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
2639 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
2640 flags |= AR_TBTT_TIMER_EN;
2641 break;
Colin McCabed97809d2008-12-01 13:38:55 -08002642 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04002643 case NL80211_IFTYPE_MESH_POINT:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002644 REG_SET_BIT(ah, AR_TXCFG,
2645 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
2646 REG_WRITE(ah, AR_NEXT_NDP_TIMER,
2647 TU_TO_USEC(next_beacon +
Sujith2660b812009-02-09 13:27:26 +05302648 (ah->atim_window ? ah->
2649 atim_window : 1)));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002650 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08002651 case NL80211_IFTYPE_AP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002652 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
2653 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
2654 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05302655 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302656 dma_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002657 REG_WRITE(ah, AR_NEXT_SWBA,
2658 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05302659 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302660 sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002661 flags |=
2662 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
2663 break;
Colin McCabed97809d2008-12-01 13:38:55 -08002664 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002665 ath_print(ath9k_hw_common(ah), ATH_DBG_BEACON,
2666 "%s: unsupported opmode: %d\n",
2667 __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08002668 return;
2669 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002670 }
2671
2672 REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
2673 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
2674 REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
2675 REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
2676
2677 beacon_period &= ~ATH9K_BEACON_ENA;
2678 if (beacon_period & ATH9K_BEACON_RESET_TSF) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002679 ath9k_hw_reset_tsf(ah);
2680 }
2681
2682 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
2683}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002684EXPORT_SYMBOL(ath9k_hw_beaconinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002685
Sujithcbe61d82009-02-09 13:27:12 +05302686void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05302687 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002688{
2689 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05302690 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002691 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002692
2693 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
2694
2695 REG_WRITE(ah, AR_BEACON_PERIOD,
2696 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
2697 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
2698 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
2699
2700 REG_RMW_FIELD(ah, AR_RSSI_THR,
2701 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
2702
2703 beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
2704
2705 if (bs->bs_sleepduration > beaconintval)
2706 beaconintval = bs->bs_sleepduration;
2707
2708 dtimperiod = bs->bs_dtimperiod;
2709 if (bs->bs_sleepduration > dtimperiod)
2710 dtimperiod = bs->bs_sleepduration;
2711
2712 if (beaconintval == dtimperiod)
2713 nextTbtt = bs->bs_nextdtim;
2714 else
2715 nextTbtt = bs->bs_nexttbtt;
2716
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002717 ath_print(common, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
2718 ath_print(common, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
2719 ath_print(common, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
2720 ath_print(common, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002721
2722 REG_WRITE(ah, AR_NEXT_DTIM,
2723 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
2724 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
2725
2726 REG_WRITE(ah, AR_SLEEP1,
2727 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
2728 | AR_SLEEP1_ASSUME_DTIM);
2729
Sujith60b67f52008-08-07 10:52:38 +05302730 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002731 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
2732 else
2733 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
2734
2735 REG_WRITE(ah, AR_SLEEP2,
2736 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
2737
2738 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
2739 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
2740
2741 REG_SET_BIT(ah, AR_TIMER_MODE,
2742 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
2743 AR_DTIM_TIMER_EN);
2744
Sujith4af9cf42009-02-12 10:06:47 +05302745 /* TSF Out of Range Threshold */
2746 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002747}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002748EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002749
Sujithf1dc5602008-10-29 10:16:30 +05302750/*******************/
2751/* HW Capabilities */
2752/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002753
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002754int ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002755{
Sujith2660b812009-02-09 13:27:26 +05302756 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002757 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002758 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002759 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002760
Sujithf1dc5602008-10-29 10:16:30 +05302761 u16 capField = 0, eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002762
Sujithf74df6f2009-02-09 13:27:24 +05302763 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002764 regulatory->current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05302765
Sujithf74df6f2009-02-09 13:27:24 +05302766 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
Sujithfec0de12009-02-12 10:06:43 +05302767 if (AR_SREV_9285_10_OR_LATER(ah))
2768 eeval |= AR9285_RDEXT_DEFAULT;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002769 regulatory->current_rd_ext = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05302770
Sujithf74df6f2009-02-09 13:27:24 +05302771 capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
Sujithf1dc5602008-10-29 10:16:30 +05302772
Sujith2660b812009-02-09 13:27:26 +05302773 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05302774 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002775 if (regulatory->current_rd == 0x64 ||
2776 regulatory->current_rd == 0x65)
2777 regulatory->current_rd += 5;
2778 else if (regulatory->current_rd == 0x41)
2779 regulatory->current_rd = 0x43;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002780 ath_print(common, ATH_DBG_REGULATORY,
2781 "regdomain mapped to 0x%x\n", regulatory->current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002782 }
Sujithdc2222a2008-08-14 13:26:55 +05302783
Sujithf74df6f2009-02-09 13:27:24 +05302784 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002785 if ((eeval & (AR5416_OPFLAGS_11G | AR5416_OPFLAGS_11A)) == 0) {
2786 ath_print(common, ATH_DBG_FATAL,
2787 "no band has been marked as supported in EEPROM.\n");
2788 return -EINVAL;
2789 }
2790
Sujithf1dc5602008-10-29 10:16:30 +05302791 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002792
Sujithf1dc5602008-10-29 10:16:30 +05302793 if (eeval & AR5416_OPFLAGS_11A) {
2794 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05302795 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05302796 if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
2797 set_bit(ATH9K_MODE_11NA_HT20,
2798 pCap->wireless_modes);
2799 if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
2800 set_bit(ATH9K_MODE_11NA_HT40PLUS,
2801 pCap->wireless_modes);
2802 set_bit(ATH9K_MODE_11NA_HT40MINUS,
2803 pCap->wireless_modes);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002804 }
2805 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002806 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002807
Sujithf1dc5602008-10-29 10:16:30 +05302808 if (eeval & AR5416_OPFLAGS_11G) {
Sujithf1dc5602008-10-29 10:16:30 +05302809 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05302810 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05302811 if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
2812 set_bit(ATH9K_MODE_11NG_HT20,
2813 pCap->wireless_modes);
2814 if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
2815 set_bit(ATH9K_MODE_11NG_HT40PLUS,
2816 pCap->wireless_modes);
2817 set_bit(ATH9K_MODE_11NG_HT40MINUS,
2818 pCap->wireless_modes);
2819 }
2820 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002821 }
Sujithf1dc5602008-10-29 10:16:30 +05302822
Sujithf74df6f2009-02-09 13:27:24 +05302823 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002824 /*
2825 * For AR9271 we will temporarilly uses the rx chainmax as read from
2826 * the EEPROM.
2827 */
Sujith8147f5d2009-02-20 15:13:23 +05302828 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002829 !(eeval & AR5416_OPFLAGS_11A) &&
2830 !(AR_SREV_9271(ah)))
2831 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
Sujith8147f5d2009-02-20 15:13:23 +05302832 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
2833 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002834 /* Use rx_chainmask from EEPROM. */
Sujith8147f5d2009-02-20 15:13:23 +05302835 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05302836
Sujithd535a422009-02-09 13:27:06 +05302837 if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0)))
Sujith2660b812009-02-09 13:27:26 +05302838 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05302839
2840 pCap->low_2ghz_chan = 2312;
2841 pCap->high_2ghz_chan = 2732;
2842
2843 pCap->low_5ghz_chan = 4920;
2844 pCap->high_5ghz_chan = 6100;
2845
2846 pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
2847 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
2848 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
2849
2850 pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
2851 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
2852 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
2853
Sujith2660b812009-02-09 13:27:26 +05302854 if (ah->config.ht_enable)
Sujithf1dc5602008-10-29 10:16:30 +05302855 pCap->hw_caps |= ATH9K_HW_CAP_HT;
2856 else
2857 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
2858
2859 pCap->hw_caps |= ATH9K_HW_CAP_GTT;
2860 pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
2861 pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
2862 pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
2863
2864 if (capField & AR_EEPROM_EEPCAP_MAXQCU)
2865 pCap->total_queues =
2866 MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
2867 else
2868 pCap->total_queues = ATH9K_NUM_TX_QUEUES;
2869
2870 if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
2871 pCap->keycache_size =
2872 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
2873 else
2874 pCap->keycache_size = AR_KEYTABLE_SIZE;
2875
2876 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -05002877
2878 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
2879 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD >> 1;
2880 else
2881 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
Sujithf1dc5602008-10-29 10:16:30 +05302882
Sujith5b5fa352010-03-17 14:25:15 +05302883 if (AR_SREV_9271(ah))
2884 pCap->num_gpio_pins = AR9271_NUM_GPIO;
2885 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302886 pCap->num_gpio_pins = AR9285_NUM_GPIO;
2887 else if (AR_SREV_9280_10_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302888 pCap->num_gpio_pins = AR928X_NUM_GPIO;
2889 else
2890 pCap->num_gpio_pins = AR_NUM_GPIO;
2891
Sujithf1dc5602008-10-29 10:16:30 +05302892 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
2893 pCap->hw_caps |= ATH9K_HW_CAP_CST;
2894 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
2895 } else {
2896 pCap->rts_aggr_limit = (8 * 1024);
2897 }
2898
2899 pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
2900
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05302901#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05302902 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
2903 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
2904 ah->rfkill_gpio =
2905 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
2906 ah->rfkill_polarity =
2907 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05302908
2909 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
2910 }
2911#endif
Vivek Natarajanbde748a2010-04-05 14:48:05 +05302912 if (AR_SREV_9271(ah))
2913 pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
2914 else
2915 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
Sujithf1dc5602008-10-29 10:16:30 +05302916
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302917 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302918 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
2919 else
2920 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
2921
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002922 if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) {
Sujithf1dc5602008-10-29 10:16:30 +05302923 pCap->reg_cap =
2924 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
2925 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
2926 AR_EEPROM_EEREGCAP_EN_KK_U2 |
2927 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
2928 } else {
2929 pCap->reg_cap =
2930 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
2931 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
2932 }
2933
Senthil Balasubramanianebb90cf2009-09-18 15:07:33 +05302934 /* Advertise midband for AR5416 with FCC midband set in eeprom */
2935 if (regulatory->current_rd_ext & (1 << REG_EXT_FCC_MIDBAND) &&
2936 AR_SREV_5416(ah))
2937 pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
Sujithf1dc5602008-10-29 10:16:30 +05302938
2939 pCap->num_antcfg_5ghz =
Sujithf74df6f2009-02-09 13:27:24 +05302940 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05302941 pCap->num_antcfg_2ghz =
Sujithf74df6f2009-02-09 13:27:24 +05302942 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05302943
Vasanthakumar Thiagarajanfe129462009-09-09 15:25:50 +05302944 if (AR_SREV_9280_10_OR_LATER(ah) &&
Luis R. Rodrigueza36cfbc2009-09-09 16:05:32 -07002945 ath9k_hw_btcoex_supported(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002946 btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO;
2947 btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO;
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05302948
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302949 if (AR_SREV_9285(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002950 btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
2951 btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302952 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002953 btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302954 }
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05302955 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002956 btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE;
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05302957 }
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002958
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002959 if (AR_SREV_9300_20_OR_LATER(ah)) {
Vasanthakumar Thiagarajan1adf02f2010-04-15 17:38:24 -04002960 pCap->hw_caps |= ATH9K_HW_CAP_EDMA;
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002961 pCap->rx_hp_qdepth = ATH9K_HW_RX_HP_QDEPTH;
2962 pCap->rx_lp_qdepth = ATH9K_HW_RX_LP_QDEPTH;
2963 pCap->rx_status_len = sizeof(struct ar9003_rxs);
Vasanthakumar Thiagarajan162c3be2010-04-15 17:38:41 -04002964 pCap->tx_desc_len = sizeof(struct ar9003_txc);
2965 } else {
2966 pCap->tx_desc_len = sizeof(struct ath_desc);
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002967 }
Vasanthakumar Thiagarajan1adf02f2010-04-15 17:38:24 -04002968
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002969 return 0;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002970}
2971
Sujithcbe61d82009-02-09 13:27:12 +05302972bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05302973 u32 capability, u32 *result)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002974{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002975 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302976 switch (type) {
2977 case ATH9K_CAP_CIPHER:
2978 switch (capability) {
2979 case ATH9K_CIPHER_AES_CCM:
2980 case ATH9K_CIPHER_AES_OCB:
2981 case ATH9K_CIPHER_TKIP:
2982 case ATH9K_CIPHER_WEP:
2983 case ATH9K_CIPHER_MIC:
2984 case ATH9K_CIPHER_CLR:
2985 return true;
2986 default:
2987 return false;
2988 }
2989 case ATH9K_CAP_TKIP_MIC:
2990 switch (capability) {
2991 case 0:
2992 return true;
2993 case 1:
Sujith2660b812009-02-09 13:27:26 +05302994 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05302995 AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
2996 false;
2997 }
2998 case ATH9K_CAP_TKIP_SPLIT:
Sujith2660b812009-02-09 13:27:26 +05302999 return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ?
Sujithf1dc5602008-10-29 10:16:30 +05303000 false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303001 case ATH9K_CAP_MCAST_KEYSRCH:
3002 switch (capability) {
3003 case 0:
3004 return true;
3005 case 1:
3006 if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
3007 return false;
3008 } else {
Sujith2660b812009-02-09 13:27:26 +05303009 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303010 AR_STA_ID1_MCAST_KSRCH) ? true :
3011 false;
3012 }
3013 }
3014 return false;
Sujithf1dc5602008-10-29 10:16:30 +05303015 case ATH9K_CAP_TXPOW:
3016 switch (capability) {
3017 case 0:
3018 return 0;
3019 case 1:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003020 *result = regulatory->power_limit;
Sujithf1dc5602008-10-29 10:16:30 +05303021 return 0;
3022 case 2:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003023 *result = regulatory->max_power_level;
Sujithf1dc5602008-10-29 10:16:30 +05303024 return 0;
3025 case 3:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003026 *result = regulatory->tp_scale;
Sujithf1dc5602008-10-29 10:16:30 +05303027 return 0;
3028 }
3029 return false;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05303030 case ATH9K_CAP_DS:
3031 return (AR_SREV_9280_20_OR_LATER(ah) &&
3032 (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1))
3033 ? false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303034 default:
3035 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003036 }
Sujithf1dc5602008-10-29 10:16:30 +05303037}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003038EXPORT_SYMBOL(ath9k_hw_getcapability);
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003039
Sujithcbe61d82009-02-09 13:27:12 +05303040bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303041 u32 capability, u32 setting, int *status)
3042{
Sujithf1dc5602008-10-29 10:16:30 +05303043 switch (type) {
3044 case ATH9K_CAP_TKIP_MIC:
3045 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303046 ah->sta_id1_defaults |=
Sujithf1dc5602008-10-29 10:16:30 +05303047 AR_STA_ID1_CRPT_MIC_ENABLE;
3048 else
Sujith2660b812009-02-09 13:27:26 +05303049 ah->sta_id1_defaults &=
Sujithf1dc5602008-10-29 10:16:30 +05303050 ~AR_STA_ID1_CRPT_MIC_ENABLE;
3051 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303052 case ATH9K_CAP_MCAST_KEYSRCH:
3053 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303054 ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303055 else
Sujith2660b812009-02-09 13:27:26 +05303056 ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303057 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303058 default:
3059 return false;
3060 }
3061}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003062EXPORT_SYMBOL(ath9k_hw_setcapability);
Sujithf1dc5602008-10-29 10:16:30 +05303063
3064/****************************/
3065/* GPIO / RFKILL / Antennae */
3066/****************************/
3067
Sujithcbe61d82009-02-09 13:27:12 +05303068static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303069 u32 gpio, u32 type)
3070{
3071 int addr;
3072 u32 gpio_shift, tmp;
3073
3074 if (gpio > 11)
3075 addr = AR_GPIO_OUTPUT_MUX3;
3076 else if (gpio > 5)
3077 addr = AR_GPIO_OUTPUT_MUX2;
3078 else
3079 addr = AR_GPIO_OUTPUT_MUX1;
3080
3081 gpio_shift = (gpio % 6) * 5;
3082
3083 if (AR_SREV_9280_20_OR_LATER(ah)
3084 || (addr != AR_GPIO_OUTPUT_MUX1)) {
3085 REG_RMW(ah, addr, (type << gpio_shift),
3086 (0x1f << gpio_shift));
3087 } else {
3088 tmp = REG_READ(ah, addr);
3089 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
3090 tmp &= ~(0x1f << gpio_shift);
3091 tmp |= (type << gpio_shift);
3092 REG_WRITE(ah, addr, tmp);
3093 }
3094}
3095
Sujithcbe61d82009-02-09 13:27:12 +05303096void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303097{
3098 u32 gpio_shift;
3099
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07003100 BUG_ON(gpio >= ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05303101
3102 gpio_shift = gpio << 1;
3103
3104 REG_RMW(ah,
3105 AR_GPIO_OE_OUT,
3106 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
3107 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3108}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003109EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
Sujithf1dc5602008-10-29 10:16:30 +05303110
Sujithcbe61d82009-02-09 13:27:12 +05303111u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303112{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303113#define MS_REG_READ(x, y) \
3114 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
3115
Sujith2660b812009-02-09 13:27:26 +05303116 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05303117 return 0xffffffff;
3118
Felix Fietkau783dfca2010-04-15 17:38:11 -04003119 if (AR_SREV_9300_20_OR_LATER(ah))
3120 return MS_REG_READ(AR9300, gpio) != 0;
3121 else if (AR_SREV_9271(ah))
Sujith5b5fa352010-03-17 14:25:15 +05303122 return MS_REG_READ(AR9271, gpio) != 0;
3123 else if (AR_SREV_9287_10_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05303124 return MS_REG_READ(AR9287, gpio) != 0;
3125 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303126 return MS_REG_READ(AR9285, gpio) != 0;
3127 else if (AR_SREV_9280_10_OR_LATER(ah))
3128 return MS_REG_READ(AR928X, gpio) != 0;
3129 else
3130 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05303131}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003132EXPORT_SYMBOL(ath9k_hw_gpio_get);
Sujithf1dc5602008-10-29 10:16:30 +05303133
Sujithcbe61d82009-02-09 13:27:12 +05303134void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05303135 u32 ah_signal_type)
3136{
3137 u32 gpio_shift;
3138
3139 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
3140
3141 gpio_shift = 2 * gpio;
3142
3143 REG_RMW(ah,
3144 AR_GPIO_OE_OUT,
3145 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
3146 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3147}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003148EXPORT_SYMBOL(ath9k_hw_cfg_output);
Sujithf1dc5602008-10-29 10:16:30 +05303149
Sujithcbe61d82009-02-09 13:27:12 +05303150void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05303151{
Sujith5b5fa352010-03-17 14:25:15 +05303152 if (AR_SREV_9271(ah))
3153 val = ~val;
3154
Sujithf1dc5602008-10-29 10:16:30 +05303155 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
3156 AR_GPIO_BIT(gpio));
3157}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003158EXPORT_SYMBOL(ath9k_hw_set_gpio);
Sujithf1dc5602008-10-29 10:16:30 +05303159
Sujithcbe61d82009-02-09 13:27:12 +05303160u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303161{
3162 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
3163}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003164EXPORT_SYMBOL(ath9k_hw_getdefantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303165
Sujithcbe61d82009-02-09 13:27:12 +05303166void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05303167{
3168 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
3169}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003170EXPORT_SYMBOL(ath9k_hw_setantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303171
Sujithf1dc5602008-10-29 10:16:30 +05303172/*********************/
3173/* General Operation */
3174/*********************/
3175
Sujithcbe61d82009-02-09 13:27:12 +05303176u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303177{
3178 u32 bits = REG_READ(ah, AR_RX_FILTER);
3179 u32 phybits = REG_READ(ah, AR_PHY_ERR);
3180
3181 if (phybits & AR_PHY_ERR_RADAR)
3182 bits |= ATH9K_RX_FILTER_PHYRADAR;
3183 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
3184 bits |= ATH9K_RX_FILTER_PHYERR;
3185
3186 return bits;
3187}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003188EXPORT_SYMBOL(ath9k_hw_getrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303189
Sujithcbe61d82009-02-09 13:27:12 +05303190void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05303191{
3192 u32 phybits;
3193
Sujith7ea310b2009-09-03 12:08:43 +05303194 REG_WRITE(ah, AR_RX_FILTER, bits);
3195
Sujithf1dc5602008-10-29 10:16:30 +05303196 phybits = 0;
3197 if (bits & ATH9K_RX_FILTER_PHYRADAR)
3198 phybits |= AR_PHY_ERR_RADAR;
3199 if (bits & ATH9K_RX_FILTER_PHYERR)
3200 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
3201 REG_WRITE(ah, AR_PHY_ERR, phybits);
3202
3203 if (phybits)
3204 REG_WRITE(ah, AR_RXCFG,
3205 REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
3206 else
3207 REG_WRITE(ah, AR_RXCFG,
3208 REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
3209}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003210EXPORT_SYMBOL(ath9k_hw_setrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303211
Sujithcbe61d82009-02-09 13:27:12 +05303212bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303213{
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05303214 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
3215 return false;
3216
3217 ath9k_hw_init_pll(ah, NULL);
3218 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303219}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003220EXPORT_SYMBOL(ath9k_hw_phy_disable);
Sujithf1dc5602008-10-29 10:16:30 +05303221
Sujithcbe61d82009-02-09 13:27:12 +05303222bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303223{
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07003224 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05303225 return false;
3226
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05303227 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
3228 return false;
3229
3230 ath9k_hw_init_pll(ah, NULL);
3231 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303232}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003233EXPORT_SYMBOL(ath9k_hw_disable);
Sujithf1dc5602008-10-29 10:16:30 +05303234
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003235void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
Sujithf1dc5602008-10-29 10:16:30 +05303236{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003237 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujith2660b812009-02-09 13:27:26 +05303238 struct ath9k_channel *chan = ah->curchan;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08003239 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05303240
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003241 regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER);
Sujithf1dc5602008-10-29 10:16:30 +05303242
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003243 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003244 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003245 channel->max_antenna_gain * 2,
3246 channel->max_power * 2,
3247 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003248 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05303249}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003250EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
Sujithf1dc5602008-10-29 10:16:30 +05303251
Sujithcbe61d82009-02-09 13:27:12 +05303252void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac)
Sujithf1dc5602008-10-29 10:16:30 +05303253{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07003254 memcpy(ath9k_hw_common(ah)->macaddr, mac, ETH_ALEN);
Sujithf1dc5602008-10-29 10:16:30 +05303255}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003256EXPORT_SYMBOL(ath9k_hw_setmac);
Sujithf1dc5602008-10-29 10:16:30 +05303257
Sujithcbe61d82009-02-09 13:27:12 +05303258void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303259{
Sujith2660b812009-02-09 13:27:26 +05303260 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05303261}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003262EXPORT_SYMBOL(ath9k_hw_setopmode);
Sujithf1dc5602008-10-29 10:16:30 +05303263
Sujithcbe61d82009-02-09 13:27:12 +05303264void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05303265{
3266 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
3267 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
3268}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003269EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303270
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07003271void ath9k_hw_write_associd(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303272{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07003273 struct ath_common *common = ath9k_hw_common(ah);
3274
3275 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
3276 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
3277 ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05303278}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003279EXPORT_SYMBOL(ath9k_hw_write_associd);
Sujithf1dc5602008-10-29 10:16:30 +05303280
Sujithcbe61d82009-02-09 13:27:12 +05303281u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303282{
3283 u64 tsf;
3284
3285 tsf = REG_READ(ah, AR_TSF_U32);
3286 tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
3287
3288 return tsf;
3289}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003290EXPORT_SYMBOL(ath9k_hw_gettsf64);
Sujithf1dc5602008-10-29 10:16:30 +05303291
Sujithcbe61d82009-02-09 13:27:12 +05303292void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003293{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003294 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01003295 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003296}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003297EXPORT_SYMBOL(ath9k_hw_settsf64);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003298
Sujithcbe61d82009-02-09 13:27:12 +05303299void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303300{
Gabor Juhosf9b604f2009-06-21 00:02:15 +02003301 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
3302 AH_TSF_WRITE_TIMEOUT))
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003303 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
3304 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
Gabor Juhosf9b604f2009-06-21 00:02:15 +02003305
Sujithf1dc5602008-10-29 10:16:30 +05303306 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003307}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003308EXPORT_SYMBOL(ath9k_hw_reset_tsf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003309
Sujith54e4cec2009-08-07 09:45:09 +05303310void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003311{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003312 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303313 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003314 else
Sujith2660b812009-02-09 13:27:26 +05303315 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003316}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003317EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003318
Luis R. Rodriguez30cbd422009-11-03 16:10:46 -08003319/*
3320 * Extend 15-bit time stamp from rx descriptor to
3321 * a full 64-bit TSF using the current h/w TSF.
3322*/
3323u64 ath9k_hw_extend_tsf(struct ath_hw *ah, u32 rstamp)
3324{
3325 u64 tsf;
3326
3327 tsf = ath9k_hw_gettsf64(ah);
3328 if ((tsf & 0x7fff) < rstamp)
3329 tsf -= 0x8000;
3330 return (tsf & ~0x7fff) | rstamp;
3331}
3332EXPORT_SYMBOL(ath9k_hw_extend_tsf);
3333
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003334void ath9k_hw_set11nmac2040(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003335{
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003336 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithf1dc5602008-10-29 10:16:30 +05303337 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003338
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003339 if (conf_is_ht40(conf) && !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05303340 macmode = AR_2040_JOINED_RX_CLEAR;
3341 else
3342 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003343
Sujithf1dc5602008-10-29 10:16:30 +05303344 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003345}
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303346
3347/* HW Generic timers configuration */
3348
3349static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
3350{
3351 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3352 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3353 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3354 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3355 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3356 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3357 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3358 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3359 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
3360 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
3361 AR_NDP2_TIMER_MODE, 0x0002},
3362 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
3363 AR_NDP2_TIMER_MODE, 0x0004},
3364 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
3365 AR_NDP2_TIMER_MODE, 0x0008},
3366 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
3367 AR_NDP2_TIMER_MODE, 0x0010},
3368 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
3369 AR_NDP2_TIMER_MODE, 0x0020},
3370 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
3371 AR_NDP2_TIMER_MODE, 0x0040},
3372 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
3373 AR_NDP2_TIMER_MODE, 0x0080}
3374};
3375
3376/* HW generic timer primitives */
3377
3378/* compute and clear index of rightmost 1 */
3379static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
3380{
3381 u32 b;
3382
3383 b = *mask;
3384 b &= (0-b);
3385 *mask &= ~b;
3386 b *= debruijn32;
3387 b >>= 27;
3388
3389 return timer_table->gen_timer_index[b];
3390}
3391
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05303392u32 ath9k_hw_gettsf32(struct ath_hw *ah)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303393{
3394 return REG_READ(ah, AR_TSF_L32);
3395}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003396EXPORT_SYMBOL(ath9k_hw_gettsf32);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303397
3398struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
3399 void (*trigger)(void *),
3400 void (*overflow)(void *),
3401 void *arg,
3402 u8 timer_index)
3403{
3404 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3405 struct ath_gen_timer *timer;
3406
3407 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
3408
3409 if (timer == NULL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003410 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
3411 "Failed to allocate memory"
3412 "for hw timer[%d]\n", timer_index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303413 return NULL;
3414 }
3415
3416 /* allocate a hardware generic timer slot */
3417 timer_table->timers[timer_index] = timer;
3418 timer->index = timer_index;
3419 timer->trigger = trigger;
3420 timer->overflow = overflow;
3421 timer->arg = arg;
3422
3423 return timer;
3424}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003425EXPORT_SYMBOL(ath_gen_timer_alloc);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303426
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07003427void ath9k_hw_gen_timer_start(struct ath_hw *ah,
3428 struct ath_gen_timer *timer,
3429 u32 timer_next,
3430 u32 timer_period)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303431{
3432 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3433 u32 tsf;
3434
3435 BUG_ON(!timer_period);
3436
3437 set_bit(timer->index, &timer_table->timer_mask.timer_bits);
3438
3439 tsf = ath9k_hw_gettsf32(ah);
3440
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003441 ath_print(ath9k_hw_common(ah), ATH_DBG_HWTIMER,
3442 "curent tsf %x period %x"
3443 "timer_next %x\n", tsf, timer_period, timer_next);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303444
3445 /*
3446 * Pull timer_next forward if the current TSF already passed it
3447 * because of software latency
3448 */
3449 if (timer_next < tsf)
3450 timer_next = tsf + timer_period;
3451
3452 /*
3453 * Program generic timer registers
3454 */
3455 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
3456 timer_next);
3457 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
3458 timer_period);
3459 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
3460 gen_tmr_configuration[timer->index].mode_mask);
3461
3462 /* Enable both trigger and thresh interrupt masks */
3463 REG_SET_BIT(ah, AR_IMR_S5,
3464 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
3465 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303466}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003467EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303468
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07003469void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303470{
3471 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3472
3473 if ((timer->index < AR_FIRST_NDP_TIMER) ||
3474 (timer->index >= ATH_MAX_GEN_TIMER)) {
3475 return;
3476 }
3477
3478 /* Clear generic timer enable bits. */
3479 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
3480 gen_tmr_configuration[timer->index].mode_mask);
3481
3482 /* Disable both trigger and thresh interrupt masks */
3483 REG_CLR_BIT(ah, AR_IMR_S5,
3484 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
3485 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
3486
3487 clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303488}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003489EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303490
3491void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
3492{
3493 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3494
3495 /* free the hardware generic timer slot */
3496 timer_table->timers[timer->index] = NULL;
3497 kfree(timer);
3498}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003499EXPORT_SYMBOL(ath_gen_timer_free);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303500
3501/*
3502 * Generic Timer Interrupts handling
3503 */
3504void ath_gen_timer_isr(struct ath_hw *ah)
3505{
3506 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3507 struct ath_gen_timer *timer;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003508 struct ath_common *common = ath9k_hw_common(ah);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303509 u32 trigger_mask, thresh_mask, index;
3510
3511 /* get hardware generic timer interrupt status */
3512 trigger_mask = ah->intr_gen_timer_trigger;
3513 thresh_mask = ah->intr_gen_timer_thresh;
3514 trigger_mask &= timer_table->timer_mask.val;
3515 thresh_mask &= timer_table->timer_mask.val;
3516
3517 trigger_mask &= ~thresh_mask;
3518
3519 while (thresh_mask) {
3520 index = rightmost_index(timer_table, &thresh_mask);
3521 timer = timer_table->timers[index];
3522 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003523 ath_print(common, ATH_DBG_HWTIMER,
3524 "TSF overflow for Gen timer %d\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303525 timer->overflow(timer->arg);
3526 }
3527
3528 while (trigger_mask) {
3529 index = rightmost_index(timer_table, &trigger_mask);
3530 timer = timer_table->timers[index];
3531 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003532 ath_print(common, ATH_DBG_HWTIMER,
3533 "Gen timer[%d] trigger\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303534 timer->trigger(timer->arg);
3535 }
3536}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003537EXPORT_SYMBOL(ath_gen_timer_isr);
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003538
Sujith05020d22010-03-17 14:25:23 +05303539/********/
3540/* HTC */
3541/********/
3542
3543void ath9k_hw_htc_resetinit(struct ath_hw *ah)
3544{
3545 ah->htc_reset_init = true;
3546}
3547EXPORT_SYMBOL(ath9k_hw_htc_resetinit);
3548
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003549static struct {
3550 u32 version;
3551 const char * name;
3552} ath_mac_bb_names[] = {
3553 /* Devices with external radios */
3554 { AR_SREV_VERSION_5416_PCI, "5416" },
3555 { AR_SREV_VERSION_5416_PCIE, "5418" },
3556 { AR_SREV_VERSION_9100, "9100" },
3557 { AR_SREV_VERSION_9160, "9160" },
3558 /* Single-chip solutions */
3559 { AR_SREV_VERSION_9280, "9280" },
3560 { AR_SREV_VERSION_9285, "9285" },
Luis R. Rodriguez11158472009-10-27 12:59:35 -04003561 { AR_SREV_VERSION_9287, "9287" },
3562 { AR_SREV_VERSION_9271, "9271" },
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003563};
3564
3565/* For devices with external radios */
3566static struct {
3567 u16 version;
3568 const char * name;
3569} ath_rf_names[] = {
3570 { 0, "5133" },
3571 { AR_RAD5133_SREV_MAJOR, "5133" },
3572 { AR_RAD5122_SREV_MAJOR, "5122" },
3573 { AR_RAD2133_SREV_MAJOR, "2133" },
3574 { AR_RAD2122_SREV_MAJOR, "2122" }
3575};
3576
3577/*
3578 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
3579 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003580static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003581{
3582 int i;
3583
3584 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
3585 if (ath_mac_bb_names[i].version == mac_bb_version) {
3586 return ath_mac_bb_names[i].name;
3587 }
3588 }
3589
3590 return "????";
3591}
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003592
3593/*
3594 * Return the RF name. "????" is returned if the RF is unknown.
3595 * Used for devices with external radios.
3596 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003597static const char *ath9k_hw_rf_name(u16 rf_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003598{
3599 int i;
3600
3601 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
3602 if (ath_rf_names[i].version == rf_version) {
3603 return ath_rf_names[i].name;
3604 }
3605 }
3606
3607 return "????";
3608}
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003609
3610void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
3611{
3612 int used;
3613
3614 /* chipsets >= AR9280 are single-chip */
3615 if (AR_SREV_9280_10_OR_LATER(ah)) {
3616 used = snprintf(hw_name, len,
3617 "Atheros AR%s Rev:%x",
3618 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3619 ah->hw_version.macRev);
3620 }
3621 else {
3622 used = snprintf(hw_name, len,
3623 "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
3624 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3625 ah->hw_version.macRev,
3626 ath9k_hw_rf_name((ah->hw_version.analog5GhzRev &
3627 AR_RADIO_SREV_MAJOR)),
3628 ah->hw_version.phyRev);
3629 }
3630
3631 hw_name[used] = '\0';
3632}
3633EXPORT_SYMBOL(ath9k_hw_name);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04003634
3635/* Sets up the AR5008/AR9001/AR9002 hardware familiy callbacks */
3636static void ar9002_hw_attach_ops(struct ath_hw *ah)
3637{
3638 struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
3639 struct ath_hw_ops *ops = ath9k_hw_ops(ah);
3640
3641 priv_ops->init_cal_settings = ar9002_hw_init_cal_settings;
3642 priv_ops->init_mode_regs = ar9002_hw_init_mode_regs;
3643 priv_ops->macversion_supported = ar9002_hw_macversion_supported;
3644
3645 ops->config_pci_powersave = ar9002_hw_configpcipowersave;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04003646
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04003647 ar5008_hw_attach_phy_ops(ah);
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04003648 if (AR_SREV_9280_10_OR_LATER(ah))
3649 ar9002_hw_attach_phy_ops(ah);
Vasanthakumar Thiagarajanae3bb6d2010-04-15 17:38:27 -04003650
3651 ar9002_hw_attach_mac_ops(ah);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04003652}
3653
3654/* Sets up the AR9003 hardware familiy callbacks */
3655static void ar9003_hw_attach_ops(struct ath_hw *ah)
3656{
Luis R. Rodriguez61accab2010-04-15 17:38:21 -04003657 struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
3658
Luis R. Rodriguez13ce3e92010-04-15 17:38:37 -04003659 priv_ops->init_mode_regs = ar9003_hw_init_mode_regs;
Luis R. Rodriguez61accab2010-04-15 17:38:21 -04003660 priv_ops->macversion_supported = ar9003_hw_macversion_supported;
3661
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04003662 ar9003_hw_attach_phy_ops(ah);
Vasanthakumar Thiagarajanae3bb6d2010-04-15 17:38:27 -04003663
3664 ar9003_hw_attach_mac_ops(ah);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04003665}