blob: 67c2becad6622e5f4c9a2e091515f2d1a049ff5c [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. Rodriguez0df13da2010-04-15 17:38:59 -0400605 if (AR_SREV_9100(ah)) {
606 ah->iq_caldata.calData = &iq_cal_multi_sample;
607 ah->supp_cals = IQ_MISMATCH_CAL;
608 return;
609 }
610
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700611 if (AR_SREV_9160_10_OR_LATER(ah)) {
612 if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530613 ah->iq_caldata.calData = &iq_cal_single_sample;
614 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700615 &adc_gain_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530616 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700617 &adc_dc_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530618 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700619 &adc_init_dc_cal;
620 } else {
Sujith2660b812009-02-09 13:27:26 +0530621 ah->iq_caldata.calData = &iq_cal_multi_sample;
622 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700623 &adc_gain_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530624 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700625 &adc_dc_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530626 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700627 &adc_init_dc_cal;
628 }
Sujith2660b812009-02-09 13:27:26 +0530629 ah->supp_cals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700630 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700631}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700632
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400633static void ar9002_hw_init_mode_regs(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700634{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400635 if (AR_SREV_9271(ah)) {
Luis R. Rodriguez85643282009-10-19 02:33:33 -0400636 INIT_INI_ARRAY(&ah->iniModes, ar9271Modes_9271,
637 ARRAY_SIZE(ar9271Modes_9271), 6);
638 INIT_INI_ARRAY(&ah->iniCommon, ar9271Common_9271,
639 ARRAY_SIZE(ar9271Common_9271), 2);
Sujith70807e92010-03-17 14:25:14 +0530640 INIT_INI_ARRAY(&ah->iniCommon_normal_cck_fir_coeff_9271,
641 ar9271Common_normal_cck_fir_coeff_9271,
642 ARRAY_SIZE(ar9271Common_normal_cck_fir_coeff_9271), 2);
643 INIT_INI_ARRAY(&ah->iniCommon_japan_2484_cck_fir_coeff_9271,
644 ar9271Common_japan_2484_cck_fir_coeff_9271,
645 ARRAY_SIZE(ar9271Common_japan_2484_cck_fir_coeff_9271), 2);
Luis R. Rodriguez85643282009-10-19 02:33:33 -0400646 INIT_INI_ARRAY(&ah->iniModes_9271_1_0_only,
647 ar9271Modes_9271_1_0_only,
648 ARRAY_SIZE(ar9271Modes_9271_1_0_only), 6);
Sujith70807e92010-03-17 14:25:14 +0530649 INIT_INI_ARRAY(&ah->iniModes_9271_ANI_reg, ar9271Modes_9271_ANI_reg,
650 ARRAY_SIZE(ar9271Modes_9271_ANI_reg), 6);
651 INIT_INI_ARRAY(&ah->iniModes_high_power_tx_gain_9271,
652 ar9271Modes_high_power_tx_gain_9271,
653 ARRAY_SIZE(ar9271Modes_high_power_tx_gain_9271), 6);
654 INIT_INI_ARRAY(&ah->iniModes_normal_power_tx_gain_9271,
655 ar9271Modes_normal_power_tx_gain_9271,
656 ARRAY_SIZE(ar9271Modes_normal_power_tx_gain_9271), 6);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400657 return;
658 }
659
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530660 if (AR_SREV_9287_11_OR_LATER(ah)) {
661 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_1,
662 ARRAY_SIZE(ar9287Modes_9287_1_1), 6);
663 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_1,
664 ARRAY_SIZE(ar9287Common_9287_1_1), 2);
665 if (ah->config.pcie_clock_req)
666 INIT_INI_ARRAY(&ah->iniPcieSerdes,
667 ar9287PciePhy_clkreq_off_L1_9287_1_1,
668 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_1), 2);
669 else
670 INIT_INI_ARRAY(&ah->iniPcieSerdes,
671 ar9287PciePhy_clkreq_always_on_L1_9287_1_1,
672 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_1),
673 2);
674 } else if (AR_SREV_9287_10_OR_LATER(ah)) {
675 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_0,
676 ARRAY_SIZE(ar9287Modes_9287_1_0), 6);
677 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_0,
678 ARRAY_SIZE(ar9287Common_9287_1_0), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700679
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530680 if (ah->config.pcie_clock_req)
681 INIT_INI_ARRAY(&ah->iniPcieSerdes,
682 ar9287PciePhy_clkreq_off_L1_9287_1_0,
683 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_0), 2);
684 else
685 INIT_INI_ARRAY(&ah->iniPcieSerdes,
686 ar9287PciePhy_clkreq_always_on_L1_9287_1_0,
687 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_0),
688 2);
689 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
690
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530691
Sujith2660b812009-02-09 13:27:26 +0530692 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530693 ARRAY_SIZE(ar9285Modes_9285_1_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530694 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530695 ARRAY_SIZE(ar9285Common_9285_1_2), 2);
696
Sujith2660b812009-02-09 13:27:26 +0530697 if (ah->config.pcie_clock_req) {
698 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530699 ar9285PciePhy_clkreq_off_L1_9285_1_2,
700 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2);
701 } else {
Sujith2660b812009-02-09 13:27:26 +0530702 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530703 ar9285PciePhy_clkreq_always_on_L1_9285_1_2,
704 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2),
705 2);
706 }
707 } else if (AR_SREV_9285_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530708 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530709 ARRAY_SIZE(ar9285Modes_9285), 6);
Sujith2660b812009-02-09 13:27:26 +0530710 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530711 ARRAY_SIZE(ar9285Common_9285), 2);
712
Sujith2660b812009-02-09 13:27:26 +0530713 if (ah->config.pcie_clock_req) {
714 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530715 ar9285PciePhy_clkreq_off_L1_9285,
716 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2);
717 } else {
Sujith2660b812009-02-09 13:27:26 +0530718 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530719 ar9285PciePhy_clkreq_always_on_L1_9285,
720 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285), 2);
721 }
722 } else if (AR_SREV_9280_20_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530723 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700724 ARRAY_SIZE(ar9280Modes_9280_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530725 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700726 ARRAY_SIZE(ar9280Common_9280_2), 2);
727
Sujith2660b812009-02-09 13:27:26 +0530728 if (ah->config.pcie_clock_req) {
729 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530730 ar9280PciePhy_clkreq_off_L1_9280,
731 ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700732 } else {
Sujith2660b812009-02-09 13:27:26 +0530733 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530734 ar9280PciePhy_clkreq_always_on_L1_9280,
735 ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700736 }
Sujith2660b812009-02-09 13:27:26 +0530737 INIT_INI_ARRAY(&ah->iniModesAdditional,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700738 ar9280Modes_fast_clock_9280_2,
Sujithf1dc5602008-10-29 10:16:30 +0530739 ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700740 } else if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530741 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700742 ARRAY_SIZE(ar9280Modes_9280), 6);
Sujith2660b812009-02-09 13:27:26 +0530743 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700744 ARRAY_SIZE(ar9280Common_9280), 2);
745 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530746 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700747 ARRAY_SIZE(ar5416Modes_9160), 6);
Sujith2660b812009-02-09 13:27:26 +0530748 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700749 ARRAY_SIZE(ar5416Common_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530750 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700751 ARRAY_SIZE(ar5416Bank0_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530752 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700753 ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530754 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700755 ARRAY_SIZE(ar5416Bank1_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530756 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700757 ARRAY_SIZE(ar5416Bank2_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530758 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700759 ARRAY_SIZE(ar5416Bank3_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530760 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700761 ARRAY_SIZE(ar5416Bank6_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530762 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700763 ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530764 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700765 ARRAY_SIZE(ar5416Bank7_9160), 2);
766 if (AR_SREV_9160_11(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530767 INIT_INI_ARRAY(&ah->iniAddac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700768 ar5416Addac_91601_1,
769 ARRAY_SIZE(ar5416Addac_91601_1), 2);
770 } else {
Sujith2660b812009-02-09 13:27:26 +0530771 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700772 ARRAY_SIZE(ar5416Addac_9160), 2);
773 }
774 } else if (AR_SREV_9100_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530775 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700776 ARRAY_SIZE(ar5416Modes_9100), 6);
Sujith2660b812009-02-09 13:27:26 +0530777 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700778 ARRAY_SIZE(ar5416Common_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530779 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700780 ARRAY_SIZE(ar5416Bank0_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530781 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700782 ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530783 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700784 ARRAY_SIZE(ar5416Bank1_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530785 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700786 ARRAY_SIZE(ar5416Bank2_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530787 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700788 ARRAY_SIZE(ar5416Bank3_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530789 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700790 ARRAY_SIZE(ar5416Bank6_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530791 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700792 ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530793 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700794 ARRAY_SIZE(ar5416Bank7_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530795 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700796 ARRAY_SIZE(ar5416Addac_9100), 2);
797 } else {
Sujith2660b812009-02-09 13:27:26 +0530798 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700799 ARRAY_SIZE(ar5416Modes), 6);
Sujith2660b812009-02-09 13:27:26 +0530800 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700801 ARRAY_SIZE(ar5416Common), 2);
Sujith2660b812009-02-09 13:27:26 +0530802 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700803 ARRAY_SIZE(ar5416Bank0), 2);
Sujith2660b812009-02-09 13:27:26 +0530804 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700805 ARRAY_SIZE(ar5416BB_RfGain), 3);
Sujith2660b812009-02-09 13:27:26 +0530806 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700807 ARRAY_SIZE(ar5416Bank1), 2);
Sujith2660b812009-02-09 13:27:26 +0530808 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700809 ARRAY_SIZE(ar5416Bank2), 2);
Sujith2660b812009-02-09 13:27:26 +0530810 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700811 ARRAY_SIZE(ar5416Bank3), 3);
Sujith2660b812009-02-09 13:27:26 +0530812 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700813 ARRAY_SIZE(ar5416Bank6), 3);
Sujith2660b812009-02-09 13:27:26 +0530814 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700815 ARRAY_SIZE(ar5416Bank6TPC), 3);
Sujith2660b812009-02-09 13:27:26 +0530816 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700817 ARRAY_SIZE(ar5416Bank7), 2);
Sujith2660b812009-02-09 13:27:26 +0530818 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700819 ARRAY_SIZE(ar5416Addac), 2);
820 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700821}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700822
Luis R. Rodriguez13ce3e92010-04-15 17:38:37 -0400823/* AR9003 2.0 - new INI format (pre, core, post arrays per subsystem) */
824static void ar9003_hw_init_mode_regs(struct ath_hw *ah)
825{
826 /* mac */
827 INIT_INI_ARRAY(&ah->iniMac[ATH_INI_PRE], NULL, 0, 0);
828 INIT_INI_ARRAY(&ah->iniMac[ATH_INI_CORE],
829 ar9300_2p0_mac_core,
830 ARRAY_SIZE(ar9300_2p0_mac_core), 2);
831 INIT_INI_ARRAY(&ah->iniMac[ATH_INI_POST],
832 ar9300_2p0_mac_postamble,
833 ARRAY_SIZE(ar9300_2p0_mac_postamble), 5);
834
835 /* bb */
836 INIT_INI_ARRAY(&ah->iniBB[ATH_INI_PRE], NULL, 0, 0);
837 INIT_INI_ARRAY(&ah->iniBB[ATH_INI_CORE],
838 ar9300_2p0_baseband_core,
839 ARRAY_SIZE(ar9300_2p0_baseband_core), 2);
840 INIT_INI_ARRAY(&ah->iniBB[ATH_INI_POST],
841 ar9300_2p0_baseband_postamble,
842 ARRAY_SIZE(ar9300_2p0_baseband_postamble), 5);
843
844 /* radio */
845 INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_PRE], NULL, 0, 0);
846 INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_CORE],
847 ar9300_2p0_radio_core,
848 ARRAY_SIZE(ar9300_2p0_radio_core), 2);
849 INIT_INI_ARRAY(&ah->iniRadio[ATH_INI_POST],
850 ar9300_2p0_radio_postamble,
851 ARRAY_SIZE(ar9300_2p0_radio_postamble), 5);
852
853 /* soc */
854 INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_PRE],
855 ar9300_2p0_soc_preamble,
856 ARRAY_SIZE(ar9300_2p0_soc_preamble), 2);
857 INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_CORE], NULL, 0, 0);
858 INIT_INI_ARRAY(&ah->iniSOC[ATH_INI_POST],
859 ar9300_2p0_soc_postamble,
860 ARRAY_SIZE(ar9300_2p0_soc_postamble), 5);
861
862 /* rx/tx gain */
863 INIT_INI_ARRAY(&ah->iniModesRxGain,
864 ar9300Common_rx_gain_table_2p0,
865 ARRAY_SIZE(ar9300Common_rx_gain_table_2p0), 2);
866 INIT_INI_ARRAY(&ah->iniModesTxGain,
867 ar9300Modes_lowest_ob_db_tx_gain_table_2p0,
868 ARRAY_SIZE(ar9300Modes_lowest_ob_db_tx_gain_table_2p0),
869 5);
870
871 /* Load PCIE SERDES settings from INI */
872
873 /* Awake Setting */
874
875 INIT_INI_ARRAY(&ah->iniPcieSerdes,
876 ar9300PciePhy_pll_on_clkreq_disable_L1_2p0,
877 ARRAY_SIZE(ar9300PciePhy_pll_on_clkreq_disable_L1_2p0),
878 2);
879
880 /* Sleep Setting */
881
882 INIT_INI_ARRAY(&ah->iniPcieSerdesLowPower,
883 ar9300PciePhy_clkreq_enable_L1_2p0,
884 ARRAY_SIZE(ar9300PciePhy_clkreq_enable_L1_2p0),
885 2);
886
887 /* Fast clock modal settings */
888 INIT_INI_ARRAY(&ah->iniModesAdditional,
889 ar9300Modes_fast_clock_2p0,
890 ARRAY_SIZE(ar9300Modes_fast_clock_2p0),
891 3);
892}
893
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700894static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
895{
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530896 if (AR_SREV_9287_11_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530897 INIT_INI_ARRAY(&ah->iniModesRxGain,
898 ar9287Modes_rx_gain_9287_1_1,
899 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_1), 6);
900 else if (AR_SREV_9287_10(ah))
901 INIT_INI_ARRAY(&ah->iniModesRxGain,
902 ar9287Modes_rx_gain_9287_1_0,
903 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_0), 6);
904 else if (AR_SREV_9280_20(ah))
905 ath9k_hw_init_rxgain_ini(ah);
906
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530907 if (AR_SREV_9287_11_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530908 INIT_INI_ARRAY(&ah->iniModesTxGain,
909 ar9287Modes_tx_gain_9287_1_1,
910 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_1), 6);
911 } else if (AR_SREV_9287_10(ah)) {
912 INIT_INI_ARRAY(&ah->iniModesTxGain,
913 ar9287Modes_tx_gain_9287_1_0,
914 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_0), 6);
915 } else if (AR_SREV_9280_20(ah)) {
916 ath9k_hw_init_txgain_ini(ah);
917 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530918 u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
919
920 /* txgain table */
921 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) {
Vivek Natarajan53bc7aa2010-04-05 14:48:04 +0530922 if (AR_SREV_9285E_20(ah)) {
923 INIT_INI_ARRAY(&ah->iniModesTxGain,
924 ar9285Modes_XE2_0_high_power,
925 ARRAY_SIZE(
926 ar9285Modes_XE2_0_high_power), 6);
927 } else {
928 INIT_INI_ARRAY(&ah->iniModesTxGain,
929 ar9285Modes_high_power_tx_gain_9285_1_2,
930 ARRAY_SIZE(
931 ar9285Modes_high_power_tx_gain_9285_1_2), 6);
932 }
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530933 } else {
Vivek Natarajan53bc7aa2010-04-05 14:48:04 +0530934 if (AR_SREV_9285E_20(ah)) {
935 INIT_INI_ARRAY(&ah->iniModesTxGain,
936 ar9285Modes_XE2_0_normal_power,
937 ARRAY_SIZE(
938 ar9285Modes_XE2_0_normal_power), 6);
939 } else {
940 INIT_INI_ARRAY(&ah->iniModesTxGain,
941 ar9285Modes_original_tx_gain_9285_1_2,
942 ARRAY_SIZE(
943 ar9285Modes_original_tx_gain_9285_1_2), 6);
944 }
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530945 }
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530946 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700947}
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530948
Felix Fietkauaa8bc9e2010-01-23 20:04:18 +0100949static void ath9k_hw_init_eeprom_fix(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700950{
Pavel Roskin2eb46d92010-04-07 01:33:33 -0400951 struct base_eep_header *pBase = &(ah->eeprom.def.baseEepHeader);
952 struct ath_common *common = ath9k_hw_common(ah);
Sujith06d0f062009-02-12 10:06:45 +0530953
Pavel Roskin2eb46d92010-04-07 01:33:33 -0400954 ah->need_an_top2_fixup = (ah->hw_version.devid == AR9280_DEVID_PCI) &&
Senthil Balasubramanian939ad862010-04-15 17:38:50 -0400955 !AR_SREV_9285(ah) && !AR_SREV_9271(ah) &&
Pavel Roskin2eb46d92010-04-07 01:33:33 -0400956 ((pBase->version & 0xff) > 0x0a) &&
957 (pBase->pwdclkind == 0);
Sujith06d0f062009-02-12 10:06:45 +0530958
Pavel Roskin2eb46d92010-04-07 01:33:33 -0400959 if (ah->need_an_top2_fixup)
960 ath_print(common, ATH_DBG_EEPROM,
961 "needs fixup for AR_AN_TOP2 register\n");
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700962}
963
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400964static void ath9k_hw_attach_ops(struct ath_hw *ah)
965{
966 if (AR_SREV_9300_20_OR_LATER(ah))
967 ar9003_hw_attach_ops(ah);
968 else
969 ar9002_hw_attach_ops(ah);
970}
971
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400972/* Called for all hardware families */
973static int __ath9k_hw_init(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700974{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700975 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700976 int r = 0;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700977
Luis R. Rodriguezbab1f622010-04-15 17:38:20 -0400978 if (ah->hw_version.devid == AR5416_AR9100_DEVID)
979 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700980
981 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700982 ath_print(common, ATH_DBG_FATAL,
983 "Couldn't reset chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700984 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700985 }
986
Luis R. Rodriguezbab1f622010-04-15 17:38:20 -0400987 ath9k_hw_init_defaults(ah);
988 ath9k_hw_init_config(ah);
989
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400990 ath9k_hw_attach_ops(ah);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400991
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700992 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700993 ath_print(common, ATH_DBG_FATAL, "Couldn't wakeup chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700994 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700995 }
996
997 if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
998 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
999 (AR_SREV_9280(ah) && !ah->is_pciexpress)) {
1000 ah->config.serialize_regmode =
1001 SER_REG_MODE_ON;
1002 } else {
1003 ah->config.serialize_regmode =
1004 SER_REG_MODE_OFF;
1005 }
1006 }
1007
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001008 ath_print(common, ATH_DBG_RESET, "serialize_regmode is %d\n",
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -07001009 ah->config.serialize_regmode);
1010
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -05001011 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
1012 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD >> 1;
1013 else
1014 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD;
1015
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04001016 if (!ath9k_hw_macversion_supported(ah)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001017 ath_print(common, ATH_DBG_FATAL,
1018 "Mac Chip Rev 0x%02x.%x is not supported by "
1019 "this driver\n", ah->hw_version.macVersion,
1020 ah->hw_version.macRev);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -07001021 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -07001022 }
1023
Luis R. Rodriguez0df13da2010-04-15 17:38:59 -04001024 if (AR_SREV_9271(ah) || AR_SREV_9100(ah))
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001025 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
Felix Fietkau641d9922010-04-15 17:38:49 -04001074 if (AR_SREV_9300_20_OR_LATER(ah))
1075 ar9003_hw_set_nf_limits(ah);
1076
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001077 ath9k_init_nfcal_hist_buffer(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001078
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001079 common->state = ATH_HW_INITIALIZED;
1080
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001081 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001082}
1083
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04001084int ath9k_hw_init(struct ath_hw *ah)
1085{
1086 int ret;
1087 struct ath_common *common = ath9k_hw_common(ah);
1088
1089 /* These are all the AR5008/AR9001/AR9002 hardware family of chipsets */
1090 switch (ah->hw_version.devid) {
1091 case AR5416_DEVID_PCI:
1092 case AR5416_DEVID_PCIE:
1093 case AR5416_AR9100_DEVID:
1094 case AR9160_DEVID_PCI:
1095 case AR9280_DEVID_PCI:
1096 case AR9280_DEVID_PCIE:
1097 case AR9285_DEVID_PCIE:
Senthil Balasubramaniandb3cc532010-04-15 17:38:18 -04001098 case AR9287_DEVID_PCI:
1099 case AR9287_DEVID_PCIE:
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04001100 case AR2427_DEVID_PCIE:
Senthil Balasubramaniandb3cc532010-04-15 17:38:18 -04001101 case AR9300_DEVID_PCIE:
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04001102 break;
1103 default:
1104 if (common->bus_ops->ath_bus_type == ATH_USB)
1105 break;
1106 ath_print(common, ATH_DBG_FATAL,
1107 "Hardware device ID 0x%04x not supported\n",
1108 ah->hw_version.devid);
1109 return -EOPNOTSUPP;
1110 }
1111
1112 ret = __ath9k_hw_init(ah);
1113 if (ret) {
1114 ath_print(common, ATH_DBG_FATAL,
1115 "Unable to initialize hardware; "
1116 "initialization status: %d\n", ret);
1117 return ret;
1118 }
1119
1120 return 0;
1121}
1122EXPORT_SYMBOL(ath9k_hw_init);
1123
Sujithcbe61d82009-02-09 13:27:12 +05301124static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301125{
1126 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
1127 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
1128
1129 REG_WRITE(ah, AR_QOS_NO_ACK,
1130 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
1131 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
1132 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
1133
1134 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
1135 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
1136 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
1137 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
1138 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
1139}
1140
Sujithcbe61d82009-02-09 13:27:12 +05301141static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301142 struct ath9k_channel *chan)
1143{
Luis R. Rodriguez64773962010-04-15 17:38:17 -04001144 u32 pll = ath9k_hw_compute_pll_control(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301145
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001146 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +05301147
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -04001148 /* Switch the core clock for ar9271 to 117Mhz */
1149 if (AR_SREV_9271(ah)) {
Sujith25e2ab12010-03-17 14:25:22 +05301150 udelay(500);
1151 REG_WRITE(ah, 0x50040, 0x304);
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -04001152 }
1153
Sujithf1dc5602008-10-29 10:16:30 +05301154 udelay(RTC_PLL_SETTLE_DELAY);
1155
1156 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
1157}
1158
Sujithcbe61d82009-02-09 13:27:12 +05301159static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -08001160 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301161{
Pavel Roskin152d5302010-03-31 18:05:37 -04001162 u32 imr_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +05301163 AR_IMR_TXURN |
1164 AR_IMR_RXERR |
1165 AR_IMR_RXORN |
1166 AR_IMR_BCNMISC;
1167
Sujith0ce024c2009-12-14 14:57:00 +05301168 if (ah->config.rx_intr_mitigation)
Pavel Roskin152d5302010-03-31 18:05:37 -04001169 imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
Sujithf1dc5602008-10-29 10:16:30 +05301170 else
Pavel Roskin152d5302010-03-31 18:05:37 -04001171 imr_reg |= AR_IMR_RXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301172
Pavel Roskin152d5302010-03-31 18:05:37 -04001173 imr_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301174
Colin McCabed97809d2008-12-01 13:38:55 -08001175 if (opmode == NL80211_IFTYPE_AP)
Pavel Roskin152d5302010-03-31 18:05:37 -04001176 imr_reg |= AR_IMR_MIB;
Sujithf1dc5602008-10-29 10:16:30 +05301177
Pavel Roskin152d5302010-03-31 18:05:37 -04001178 REG_WRITE(ah, AR_IMR, imr_reg);
Pavel Roskin74bad5c2010-02-23 18:15:27 -05001179 ah->imrs2_reg |= AR_IMR_S2_GTT;
1180 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
Sujithf1dc5602008-10-29 10:16:30 +05301181
1182 if (!AR_SREV_9100(ah)) {
1183 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
1184 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
1185 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
1186 }
1187}
1188
Felix Fietkau0005baf2010-01-15 02:33:40 +01001189static void ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301190{
Felix Fietkau0005baf2010-01-15 02:33:40 +01001191 u32 val = ath9k_hw_mac_to_clks(ah, us);
1192 val = min(val, (u32) 0xFFFF);
1193 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, val);
Sujithf1dc5602008-10-29 10:16:30 +05301194}
1195
Felix Fietkau0005baf2010-01-15 02:33:40 +01001196static void ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301197{
Felix Fietkau0005baf2010-01-15 02:33:40 +01001198 u32 val = ath9k_hw_mac_to_clks(ah, us);
1199 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_ACK));
1200 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_ACK, val);
1201}
1202
1203static void ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
1204{
1205 u32 val = ath9k_hw_mac_to_clks(ah, us);
1206 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_CTS));
1207 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_CTS, val);
Sujithf1dc5602008-10-29 10:16:30 +05301208}
1209
Sujithcbe61d82009-02-09 13:27:12 +05301210static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +05301211{
Sujithf1dc5602008-10-29 10:16:30 +05301212 if (tu > 0xFFFF) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001213 ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT,
1214 "bad global tx timeout %u\n", tu);
Sujith2660b812009-02-09 13:27:26 +05301215 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301216 return false;
1217 } else {
1218 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +05301219 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +05301220 return true;
1221 }
1222}
1223
Felix Fietkau0005baf2010-01-15 02:33:40 +01001224void ath9k_hw_init_global_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301225{
Felix Fietkau0005baf2010-01-15 02:33:40 +01001226 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
1227 int acktimeout;
Felix Fietkaue239d852010-01-15 02:34:58 +01001228 int slottime;
Felix Fietkau0005baf2010-01-15 02:33:40 +01001229 int sifstime;
1230
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001231 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
1232 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +05301233
Sujith2660b812009-02-09 13:27:26 +05301234 if (ah->misc_mode != 0)
Sujithf1dc5602008-10-29 10:16:30 +05301235 REG_WRITE(ah, AR_PCU_MISC,
Sujith2660b812009-02-09 13:27:26 +05301236 REG_READ(ah, AR_PCU_MISC) | ah->misc_mode);
Felix Fietkau0005baf2010-01-15 02:33:40 +01001237
1238 if (conf->channel && conf->channel->band == IEEE80211_BAND_5GHZ)
1239 sifstime = 16;
1240 else
1241 sifstime = 10;
1242
Felix Fietkaue239d852010-01-15 02:34:58 +01001243 /* As defined by IEEE 802.11-2007 17.3.8.6 */
1244 slottime = ah->slottime + 3 * ah->coverage_class;
1245 acktimeout = slottime + sifstime;
Felix Fietkau42c45682010-02-11 18:07:19 +01001246
1247 /*
1248 * Workaround for early ACK timeouts, add an offset to match the
1249 * initval's 64us ack timeout value.
1250 * This was initially only meant to work around an issue with delayed
1251 * BA frames in some implementations, but it has been found to fix ACK
1252 * timeout issues in other cases as well.
1253 */
1254 if (conf->channel && conf->channel->band == IEEE80211_BAND_2GHZ)
1255 acktimeout += 64 - sifstime - ah->slottime;
1256
Felix Fietkaue239d852010-01-15 02:34:58 +01001257 ath9k_hw_setslottime(ah, slottime);
Felix Fietkau0005baf2010-01-15 02:33:40 +01001258 ath9k_hw_set_ack_timeout(ah, acktimeout);
1259 ath9k_hw_set_cts_timeout(ah, acktimeout);
Sujith2660b812009-02-09 13:27:26 +05301260 if (ah->globaltxtimeout != (u32) -1)
1261 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Sujithf1dc5602008-10-29 10:16:30 +05301262}
Felix Fietkau0005baf2010-01-15 02:33:40 +01001263EXPORT_SYMBOL(ath9k_hw_init_global_settings);
Sujithf1dc5602008-10-29 10:16:30 +05301264
Sujith285f2dd2010-01-08 10:36:07 +05301265void ath9k_hw_deinit(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001266{
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001267 struct ath_common *common = ath9k_hw_common(ah);
1268
Sujith736b3a22010-03-17 14:25:24 +05301269 if (common->state < ATH_HW_INITIALIZED)
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001270 goto free_hw;
1271
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001272 if (!AR_SREV_9100(ah))
Luis R. Rodrigueze70c0cf2009-08-03 12:24:51 -07001273 ath9k_hw_ani_disable(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001274
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001275 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001276
1277free_hw:
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001278 ath9k_hw_rf_free_ext_banks(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001279}
Sujith285f2dd2010-01-08 10:36:07 +05301280EXPORT_SYMBOL(ath9k_hw_deinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001281
Sujithf1dc5602008-10-29 10:16:30 +05301282/*******/
1283/* INI */
1284/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001285
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001286u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan)
Bob Copeland3a702e42009-03-30 22:30:29 -04001287{
1288 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
1289
1290 if (IS_CHAN_B(chan))
1291 ctl |= CTL_11B;
1292 else if (IS_CHAN_G(chan))
1293 ctl |= CTL_11G;
1294 else
1295 ctl |= CTL_11A;
1296
1297 return ctl;
1298}
1299
Sujithf1dc5602008-10-29 10:16:30 +05301300/****************************************/
1301/* Reset and Channel Switching Routines */
1302/****************************************/
1303
Sujithcbe61d82009-02-09 13:27:12 +05301304static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301305{
1306 u32 regval;
1307
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001308 /*
1309 * set AHB_MODE not to do cacheline prefetches
1310 */
Sujithf1dc5602008-10-29 10:16:30 +05301311 regval = REG_READ(ah, AR_AHB_MODE);
1312 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
1313
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001314 /*
1315 * let mac dma reads be in 128 byte chunks
1316 */
Sujithf1dc5602008-10-29 10:16:30 +05301317 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
1318 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
1319
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001320 /*
1321 * Restore TX Trigger Level to its pre-reset value.
1322 * The initial value depends on whether aggregation is enabled, and is
1323 * adjusted whenever underruns are detected.
1324 */
Sujith2660b812009-02-09 13:27:26 +05301325 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +05301326
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001327 /*
1328 * let mac dma writes be in 128 byte chunks
1329 */
Sujithf1dc5602008-10-29 10:16:30 +05301330 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
1331 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
1332
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001333 /*
1334 * Setup receive FIFO threshold to hold off TX activities
1335 */
Sujithf1dc5602008-10-29 10:16:30 +05301336 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1337
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001338 /*
1339 * reduce the number of usable entries in PCU TXBUF to avoid
1340 * wrap around issues.
1341 */
Sujithf1dc5602008-10-29 10:16:30 +05301342 if (AR_SREV_9285(ah)) {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001343 /* For AR9285 the number of Fifos are reduced to half.
1344 * So set the usable tx buf size also to half to
1345 * avoid data/delimiter underruns
1346 */
Sujithf1dc5602008-10-29 10:16:30 +05301347 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1348 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001349 } else if (!AR_SREV_9271(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +05301350 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1351 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1352 }
1353}
1354
Sujithcbe61d82009-02-09 13:27:12 +05301355static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301356{
1357 u32 val;
1358
1359 val = REG_READ(ah, AR_STA_ID1);
1360 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
1361 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001362 case NL80211_IFTYPE_AP:
Sujithf1dc5602008-10-29 10:16:30 +05301363 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
1364 | AR_STA_ID1_KSRCH_MODE);
1365 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1366 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001367 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04001368 case NL80211_IFTYPE_MESH_POINT:
Sujithf1dc5602008-10-29 10:16:30 +05301369 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
1370 | AR_STA_ID1_KSRCH_MODE);
1371 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1372 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001373 case NL80211_IFTYPE_STATION:
1374 case NL80211_IFTYPE_MONITOR:
Sujithf1dc5602008-10-29 10:16:30 +05301375 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
1376 break;
1377 }
1378}
1379
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001380void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled,
1381 u32 *coef_mantissa, u32 *coef_exponent)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001382{
1383 u32 coef_exp, coef_man;
1384
1385 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1386 if ((coef_scaled >> coef_exp) & 0x1)
1387 break;
1388
1389 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1390
1391 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1392
1393 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1394 *coef_exponent = coef_exp - 16;
1395}
1396
Sujithcbe61d82009-02-09 13:27:12 +05301397static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +05301398{
1399 u32 rst_flags;
1400 u32 tmpReg;
1401
Sujith70768492009-02-16 13:23:12 +05301402 if (AR_SREV_9100(ah)) {
1403 u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK);
1404 val &= ~AR_RTC_DERIVED_CLK_PERIOD;
1405 val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD);
1406 REG_WRITE(ah, AR_RTC_DERIVED_CLK, val);
1407 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1408 }
1409
Sujithf1dc5602008-10-29 10:16:30 +05301410 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1411 AR_RTC_FORCE_WAKE_ON_INT);
1412
1413 if (AR_SREV_9100(ah)) {
1414 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1415 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1416 } else {
1417 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1418 if (tmpReg &
1419 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1420 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001421 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05301422 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001423
1424 val = AR_RC_HOSTIF;
1425 if (!AR_SREV_9300_20_OR_LATER(ah))
1426 val |= AR_RC_AHB;
1427 REG_WRITE(ah, AR_RC, val);
1428
1429 } else if (!AR_SREV_9300_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05301430 REG_WRITE(ah, AR_RC, AR_RC_AHB);
Sujithf1dc5602008-10-29 10:16:30 +05301431
1432 rst_flags = AR_RTC_RC_MAC_WARM;
1433 if (type == ATH9K_RESET_COLD)
1434 rst_flags |= AR_RTC_RC_MAC_COLD;
1435 }
1436
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001437 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujithf1dc5602008-10-29 10:16:30 +05301438 udelay(50);
1439
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001440 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301441 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001442 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1443 "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301444 return false;
1445 }
1446
1447 if (!AR_SREV_9100(ah))
1448 REG_WRITE(ah, AR_RC, 0);
1449
Sujithf1dc5602008-10-29 10:16:30 +05301450 if (AR_SREV_9100(ah))
1451 udelay(50);
1452
1453 return true;
1454}
1455
Sujithcbe61d82009-02-09 13:27:12 +05301456static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301457{
1458 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1459 AR_RTC_FORCE_WAKE_ON_INT);
1460
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001461 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301462 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1463
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001464 REG_WRITE(ah, AR_RTC_RESET, 0);
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301465
Senthil Balasubramanian84e21692010-04-15 17:38:30 -04001466 if (!AR_SREV_9300_20_OR_LATER(ah))
1467 udelay(2);
1468
1469 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301470 REG_WRITE(ah, AR_RC, 0);
1471
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001472 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301473
1474 if (!ath9k_hw_wait(ah,
1475 AR_RTC_STATUS,
1476 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301477 AR_RTC_STATUS_ON,
1478 AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001479 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1480 "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301481 return false;
1482 }
1483
1484 ath9k_hw_read_revisions(ah);
1485
1486 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1487}
1488
Sujithcbe61d82009-02-09 13:27:12 +05301489static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301490{
1491 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1492 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1493
1494 switch (type) {
1495 case ATH9K_RESET_POWER_ON:
1496 return ath9k_hw_set_reset_power_on(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301497 case ATH9K_RESET_WARM:
1498 case ATH9K_RESET_COLD:
1499 return ath9k_hw_set_reset(ah, type);
Sujithf1dc5602008-10-29 10:16:30 +05301500 default:
1501 return false;
1502 }
1503}
1504
Sujithcbe61d82009-02-09 13:27:12 +05301505static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301506 struct ath9k_channel *chan)
1507{
Vivek Natarajan42abfbe2009-09-17 09:27:59 +05301508 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) {
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301509 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
1510 return false;
1511 } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
Sujithf1dc5602008-10-29 10:16:30 +05301512 return false;
1513
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001514 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05301515 return false;
1516
Sujith2660b812009-02-09 13:27:26 +05301517 ah->chip_fullsleep = false;
Sujithf1dc5602008-10-29 10:16:30 +05301518 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301519 ath9k_hw_set_rfmode(ah, chan);
1520
1521 return true;
1522}
1523
Sujithcbe61d82009-02-09 13:27:12 +05301524static bool ath9k_hw_channel_change(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001525 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301526{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001527 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001528 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001529 struct ieee80211_channel *channel = chan->chan;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001530 u32 qnum;
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001531 int r;
Sujithf1dc5602008-10-29 10:16:30 +05301532
1533 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1534 if (ath9k_hw_numtxpending(ah, qnum)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001535 ath_print(common, ATH_DBG_QUEUE,
1536 "Transmit frames pending on "
1537 "queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301538 return false;
1539 }
1540 }
1541
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001542 if (!ath9k_hw_rfbus_req(ah)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001543 ath_print(common, ATH_DBG_FATAL,
1544 "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301545 return false;
1546 }
1547
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001548 ath9k_hw_set_channel_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301549
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001550 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001551 if (r) {
1552 ath_print(common, ATH_DBG_FATAL,
1553 "Failed to set channel\n");
1554 return false;
Sujithf1dc5602008-10-29 10:16:30 +05301555 }
1556
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001557 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001558 ath9k_regd_get_ctl(regulatory, chan),
Sujithf74df6f2009-02-09 13:27:24 +05301559 channel->max_antenna_gain * 2,
1560 channel->max_power * 2,
1561 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001562 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05301563
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001564 ath9k_hw_rfbus_done(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301565
1566 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1567 ath9k_hw_set_delta_slope(ah, chan);
1568
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001569 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301570
1571 if (!chan->oneTimeCalsDone)
1572 chan->oneTimeCalsDone = true;
1573
1574 return true;
1575}
1576
Sujithcbe61d82009-02-09 13:27:12 +05301577int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001578 bool bChannelChange)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001579{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001580 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001581 u32 saveLedState;
Sujith2660b812009-02-09 13:27:26 +05301582 struct ath9k_channel *curchan = ah->curchan;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001583 u32 saveDefAntenna;
1584 u32 macStaId1;
Sujith46fe7822009-09-17 09:25:25 +05301585 u64 tsf = 0;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001586 int i, r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001587
Luis R. Rodriguez43c27612009-09-13 21:07:07 -07001588 ah->txchainmask = common->tx_chainmask;
1589 ah->rxchainmask = common->rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001590
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001591 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001592 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001593
Vasanthakumar Thiagarajan9ebef792009-09-17 09:26:44 +05301594 if (curchan && !ah->chip_fullsleep)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001595 ath9k_hw_getnf(ah, curchan);
1596
1597 if (bChannelChange &&
Sujith2660b812009-02-09 13:27:26 +05301598 (ah->chip_fullsleep != true) &&
1599 (ah->curchan != NULL) &&
1600 (chan->channel != ah->curchan->channel) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001601 ((chan->channelFlags & CHANNEL_ALL) ==
Sujith2660b812009-02-09 13:27:26 +05301602 (ah->curchan->channelFlags & CHANNEL_ALL)) &&
Vasanthakumar Thiagarajan0a475cc2009-09-17 09:27:10 +05301603 !(AR_SREV_9280(ah) || IS_CHAN_A_5MHZ_SPACED(chan) ||
1604 IS_CHAN_A_5MHZ_SPACED(ah->curchan))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001605
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001606 if (ath9k_hw_channel_change(ah, chan)) {
Sujith2660b812009-02-09 13:27:26 +05301607 ath9k_hw_loadnf(ah, ah->curchan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001608 ath9k_hw_start_nfcal(ah);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001609 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001610 }
1611 }
1612
1613 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
1614 if (saveDefAntenna == 0)
1615 saveDefAntenna = 1;
1616
1617 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
1618
Sujith46fe7822009-09-17 09:25:25 +05301619 /* For chips on which RTC reset is done, save TSF before it gets cleared */
1620 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1621 tsf = ath9k_hw_gettsf64(ah);
1622
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001623 saveLedState = REG_READ(ah, AR_CFG_LED) &
1624 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
1625 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
1626
1627 ath9k_hw_mark_phy_inactive(ah);
1628
Sujith05020d22010-03-17 14:25:23 +05301629 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001630 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1631 REG_WRITE(ah,
1632 AR9271_RESET_POWER_DOWN_CONTROL,
1633 AR9271_RADIO_RF_RST);
1634 udelay(50);
1635 }
1636
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001637 if (!ath9k_hw_chip_reset(ah, chan)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001638 ath_print(common, ATH_DBG_FATAL, "Chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001639 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001640 }
1641
Sujith05020d22010-03-17 14:25:23 +05301642 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001643 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1644 ah->htc_reset_init = false;
1645 REG_WRITE(ah,
1646 AR9271_RESET_POWER_DOWN_CONTROL,
1647 AR9271_GATE_MAC_CTL);
1648 udelay(50);
1649 }
1650
Sujith46fe7822009-09-17 09:25:25 +05301651 /* Restore TSF */
1652 if (tsf && AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1653 ath9k_hw_settsf64(ah, tsf);
1654
Vasanthakumar Thiagarajan369391d2009-01-21 19:24:13 +05301655 if (AR_SREV_9280_10_OR_LATER(ah))
1656 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001657
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001658 r = ath9k_hw_process_ini(ah, chan);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001659 if (r)
1660 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001661
Jouni Malinen0ced0e12009-01-08 13:32:13 +02001662 /* Setup MFP options for CCMP */
1663 if (AR_SREV_9280_20_OR_LATER(ah)) {
1664 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
1665 * frames when constructing CCMP AAD. */
1666 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
1667 0xc7ff);
1668 ah->sw_mgmt_crypto = false;
1669 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1670 /* Disable hardware crypto for management frames */
1671 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
1672 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
1673 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1674 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
1675 ah->sw_mgmt_crypto = true;
1676 } else
1677 ah->sw_mgmt_crypto = true;
1678
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001679 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1680 ath9k_hw_set_delta_slope(ah, chan);
1681
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001682 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithd6509152009-03-13 08:56:05 +05301683 ah->eep_ops->set_board_values(ah, chan);
Luis R. Rodrigueza7765822009-10-19 02:33:45 -04001684
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001685 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
1686 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001687 | macStaId1
1688 | AR_STA_ID1_RTS_USE_DEF
Sujith2660b812009-02-09 13:27:26 +05301689 | (ah->config.
Sujith60b67f52008-08-07 10:52:38 +05301690 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Sujith2660b812009-02-09 13:27:26 +05301691 | ah->sta_id1_defaults);
1692 ath9k_hw_set_operating_mode(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001693
Luis R. Rodriguez13b81552009-09-10 17:52:45 -07001694 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001695
1696 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
1697
Luis R. Rodriguez3453ad82009-09-10 08:57:00 -07001698 ath9k_hw_write_associd(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001699
1700 REG_WRITE(ah, AR_ISR, ~0);
1701
1702 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
1703
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001704 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001705 if (r)
1706 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001707
1708 for (i = 0; i < AR_NUM_DCU; i++)
1709 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
1710
Sujith2660b812009-02-09 13:27:26 +05301711 ah->intr_txqs = 0;
1712 for (i = 0; i < ah->caps.total_queues; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001713 ath9k_hw_resettxqueue(ah, i);
1714
Sujith2660b812009-02-09 13:27:26 +05301715 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001716 ath9k_hw_init_qos(ah);
1717
Sujith2660b812009-02-09 13:27:26 +05301718 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301719 ath9k_enable_rfkill(ah);
Johannes Berg3b319aa2009-06-13 14:50:26 +05301720
Felix Fietkau0005baf2010-01-15 02:33:40 +01001721 ath9k_hw_init_global_settings(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001722
Vivek Natarajan326bebb2009-08-14 11:33:36 +05301723 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301724 REG_WRITE(ah, AR_D_GBL_IFS_SIFS,
1725 AR_D_GBL_IFS_SIFS_ASYNC_FIFO_DUR);
1726 REG_WRITE(ah, AR_D_GBL_IFS_SLOT,
1727 AR_D_GBL_IFS_SLOT_ASYNC_FIFO_DUR);
1728 REG_WRITE(ah, AR_D_GBL_IFS_EIFS,
1729 AR_D_GBL_IFS_EIFS_ASYNC_FIFO_DUR);
1730
1731 REG_WRITE(ah, AR_TIME_OUT, AR_TIME_OUT_ACK_CTS_ASYNC_FIFO_DUR);
1732 REG_WRITE(ah, AR_USEC, AR_USEC_ASYNC_FIFO_DUR);
1733
1734 REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
1735 AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
1736 REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
1737 AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
1738 }
Vivek Natarajan326bebb2009-08-14 11:33:36 +05301739 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301740 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1741 AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
1742 }
1743
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001744 REG_WRITE(ah, AR_STA_ID1,
1745 REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
1746
1747 ath9k_hw_set_dma(ah);
1748
1749 REG_WRITE(ah, AR_OBS, 8);
1750
Sujith0ce024c2009-12-14 14:57:00 +05301751 if (ah->config.rx_intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001752 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
1753 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
1754 }
1755
1756 ath9k_hw_init_bb(ah, chan);
1757
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001758 if (!ath9k_hw_init_cal(ah, chan))
Joe Perches6badaaf2009-06-28 09:26:32 -07001759 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001760
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001761 ath9k_hw_restore_chainmask(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001762 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
1763
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001764 /*
1765 * For big endian systems turn on swapping for descriptors
1766 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001767 if (AR_SREV_9100(ah)) {
1768 u32 mask;
1769 mask = REG_READ(ah, AR_CFG);
1770 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001771 ath_print(common, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05301772 "CFG Byte Swap Set 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001773 } else {
1774 mask =
1775 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
1776 REG_WRITE(ah, AR_CFG, mask);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001777 ath_print(common, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05301778 "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001779 }
1780 } else {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001781 /* Configure AR9271 target WLAN */
1782 if (AR_SREV_9271(ah))
1783 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001784#ifdef __BIG_ENDIAN
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001785 else
1786 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001787#endif
1788 }
1789
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001790 if (ah->btcoex_hw.enabled)
Vasanthakumar Thiagarajan42cc41e2009-08-26 21:08:45 +05301791 ath9k_hw_btcoex_enable(ah);
1792
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001793 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001794}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001795EXPORT_SYMBOL(ath9k_hw_reset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001796
Sujithf1dc5602008-10-29 10:16:30 +05301797/************************/
1798/* Key Cache Management */
1799/************************/
1800
Sujithcbe61d82009-02-09 13:27:12 +05301801bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001802{
Sujithf1dc5602008-10-29 10:16:30 +05301803 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001804
Sujith2660b812009-02-09 13:27:26 +05301805 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001806 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1807 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001808 return false;
1809 }
1810
Sujithf1dc5602008-10-29 10:16:30 +05301811 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001812
Sujithf1dc5602008-10-29 10:16:30 +05301813 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
1814 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
1815 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
1816 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
1817 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
1818 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
1819 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
1820 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
1821
1822 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
1823 u16 micentry = entry + 64;
1824
1825 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
1826 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
1827 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
1828 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
1829
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001830 }
1831
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001832 return true;
1833}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001834EXPORT_SYMBOL(ath9k_hw_keyreset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001835
Sujithcbe61d82009-02-09 13:27:12 +05301836bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001837{
Sujithf1dc5602008-10-29 10:16:30 +05301838 u32 macHi, macLo;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001839
Sujith2660b812009-02-09 13:27:26 +05301840 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001841 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1842 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001843 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001844 }
1845
Sujithf1dc5602008-10-29 10:16:30 +05301846 if (mac != NULL) {
1847 macHi = (mac[5] << 8) | mac[4];
1848 macLo = (mac[3] << 24) |
1849 (mac[2] << 16) |
1850 (mac[1] << 8) |
1851 mac[0];
1852 macLo >>= 1;
1853 macLo |= (macHi & 1) << 31;
1854 macHi >>= 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001855 } else {
Sujithf1dc5602008-10-29 10:16:30 +05301856 macLo = macHi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001857 }
Sujithf1dc5602008-10-29 10:16:30 +05301858 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
1859 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001860
1861 return true;
1862}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001863EXPORT_SYMBOL(ath9k_hw_keysetmac);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001864
Sujithcbe61d82009-02-09 13:27:12 +05301865bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
Sujithf1dc5602008-10-29 10:16:30 +05301866 const struct ath9k_keyval *k,
Jouni Malinene0caf9e2009-03-02 18:15:53 +02001867 const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001868{
Sujith2660b812009-02-09 13:27:26 +05301869 const struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001870 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301871 u32 key0, key1, key2, key3, key4;
1872 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001873
Sujithf1dc5602008-10-29 10:16:30 +05301874 if (entry >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001875 ath_print(common, ATH_DBG_FATAL,
1876 "keycache entry %u out of range\n", entry);
Sujithf1dc5602008-10-29 10:16:30 +05301877 return false;
1878 }
1879
1880 switch (k->kv_type) {
1881 case ATH9K_CIPHER_AES_OCB:
1882 keyType = AR_KEYTABLE_TYPE_AES;
1883 break;
1884 case ATH9K_CIPHER_AES_CCM:
1885 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001886 ath_print(common, ATH_DBG_ANY,
1887 "AES-CCM not supported by mac rev 0x%x\n",
1888 ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001889 return false;
1890 }
Sujithf1dc5602008-10-29 10:16:30 +05301891 keyType = AR_KEYTABLE_TYPE_CCM;
1892 break;
1893 case ATH9K_CIPHER_TKIP:
1894 keyType = AR_KEYTABLE_TYPE_TKIP;
1895 if (ATH9K_IS_MIC_ENABLED(ah)
1896 && entry + 64 >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001897 ath_print(common, ATH_DBG_ANY,
1898 "entry %u inappropriate for TKIP\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001899 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001900 }
Sujithf1dc5602008-10-29 10:16:30 +05301901 break;
1902 case ATH9K_CIPHER_WEP:
Zhu Yie31a16d2009-05-21 21:47:03 +08001903 if (k->kv_len < WLAN_KEY_LEN_WEP40) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001904 ath_print(common, ATH_DBG_ANY,
1905 "WEP key length %u too small\n", k->kv_len);
Sujithf1dc5602008-10-29 10:16:30 +05301906 return false;
1907 }
Zhu Yie31a16d2009-05-21 21:47:03 +08001908 if (k->kv_len <= WLAN_KEY_LEN_WEP40)
Sujithf1dc5602008-10-29 10:16:30 +05301909 keyType = AR_KEYTABLE_TYPE_40;
Zhu Yie31a16d2009-05-21 21:47:03 +08001910 else if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05301911 keyType = AR_KEYTABLE_TYPE_104;
1912 else
1913 keyType = AR_KEYTABLE_TYPE_128;
1914 break;
1915 case ATH9K_CIPHER_CLR:
1916 keyType = AR_KEYTABLE_TYPE_CLR;
1917 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001918 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001919 ath_print(common, ATH_DBG_FATAL,
1920 "cipher %u not supported\n", k->kv_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001921 return false;
1922 }
Sujithf1dc5602008-10-29 10:16:30 +05301923
Jouni Malinene0caf9e2009-03-02 18:15:53 +02001924 key0 = get_unaligned_le32(k->kv_val + 0);
1925 key1 = get_unaligned_le16(k->kv_val + 4);
1926 key2 = get_unaligned_le32(k->kv_val + 6);
1927 key3 = get_unaligned_le16(k->kv_val + 10);
1928 key4 = get_unaligned_le32(k->kv_val + 12);
Zhu Yie31a16d2009-05-21 21:47:03 +08001929 if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05301930 key4 &= 0xff;
1931
Jouni Malinen672903b2009-03-02 15:06:31 +02001932 /*
1933 * Note: Key cache registers access special memory area that requires
1934 * two 32-bit writes to actually update the values in the internal
1935 * memory. Consequently, the exact order and pairs used here must be
1936 * maintained.
1937 */
1938
Sujithf1dc5602008-10-29 10:16:30 +05301939 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
1940 u16 micentry = entry + 64;
1941
Jouni Malinen672903b2009-03-02 15:06:31 +02001942 /*
1943 * Write inverted key[47:0] first to avoid Michael MIC errors
1944 * on frames that could be sent or received at the same time.
1945 * The correct key will be written in the end once everything
1946 * else is ready.
1947 */
Sujithf1dc5602008-10-29 10:16:30 +05301948 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
1949 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02001950
1951 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05301952 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
1953 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02001954
1955 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05301956 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
1957 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
Jouni Malinen672903b2009-03-02 15:06:31 +02001958
1959 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05301960 (void) ath9k_hw_keysetmac(ah, entry, mac);
1961
Sujith2660b812009-02-09 13:27:26 +05301962 if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) {
Jouni Malinen672903b2009-03-02 15:06:31 +02001963 /*
1964 * TKIP uses two key cache entries:
1965 * Michael MIC TX/RX keys in the same key cache entry
1966 * (idx = main index + 64):
1967 * key0 [31:0] = RX key [31:0]
1968 * key1 [15:0] = TX key [31:16]
1969 * key1 [31:16] = reserved
1970 * key2 [31:0] = RX key [63:32]
1971 * key3 [15:0] = TX key [15:0]
1972 * key3 [31:16] = reserved
1973 * key4 [31:0] = TX key [63:32]
1974 */
Sujithf1dc5602008-10-29 10:16:30 +05301975 u32 mic0, mic1, mic2, mic3, mic4;
1976
1977 mic0 = get_unaligned_le32(k->kv_mic + 0);
1978 mic2 = get_unaligned_le32(k->kv_mic + 4);
1979 mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
1980 mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
1981 mic4 = get_unaligned_le32(k->kv_txmic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02001982
1983 /* Write RX[31:0] and TX[31:16] */
Sujithf1dc5602008-10-29 10:16:30 +05301984 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
1985 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
Jouni Malinen672903b2009-03-02 15:06:31 +02001986
1987 /* Write RX[63:32] and TX[15:0] */
Sujithf1dc5602008-10-29 10:16:30 +05301988 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
1989 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
Jouni Malinen672903b2009-03-02 15:06:31 +02001990
1991 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05301992 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
1993 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
1994 AR_KEYTABLE_TYPE_CLR);
1995
1996 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02001997 /*
1998 * TKIP uses four key cache entries (two for group
1999 * keys):
2000 * Michael MIC TX/RX keys are in different key cache
2001 * entries (idx = main index + 64 for TX and
2002 * main index + 32 + 96 for RX):
2003 * key0 [31:0] = TX/RX MIC key [31:0]
2004 * key1 [31:0] = reserved
2005 * key2 [31:0] = TX/RX MIC key [63:32]
2006 * key3 [31:0] = reserved
2007 * key4 [31:0] = reserved
2008 *
2009 * Upper layer code will call this function separately
2010 * for TX and RX keys when these registers offsets are
2011 * used.
2012 */
Sujithf1dc5602008-10-29 10:16:30 +05302013 u32 mic0, mic2;
2014
2015 mic0 = get_unaligned_le32(k->kv_mic + 0);
2016 mic2 = get_unaligned_le32(k->kv_mic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02002017
2018 /* Write MIC key[31:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302019 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2020 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002021
2022 /* Write MIC key[63:32] */
Sujithf1dc5602008-10-29 10:16:30 +05302023 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2024 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002025
2026 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302027 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
2028 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2029 AR_KEYTABLE_TYPE_CLR);
2030 }
Jouni Malinen672903b2009-03-02 15:06:31 +02002031
2032 /* MAC address registers are reserved for the MIC entry */
Sujithf1dc5602008-10-29 10:16:30 +05302033 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
2034 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002035
2036 /*
2037 * Write the correct (un-inverted) key[47:0] last to enable
2038 * TKIP now that all other registers are set with correct
2039 * values.
2040 */
Sujithf1dc5602008-10-29 10:16:30 +05302041 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2042 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
2043 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002044 /* Write key[47:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302045 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2046 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002047
2048 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302049 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2050 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002051
2052 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302053 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2054 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
2055
Jouni Malinen672903b2009-03-02 15:06:31 +02002056 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302057 (void) ath9k_hw_keysetmac(ah, entry, mac);
2058 }
2059
Sujithf1dc5602008-10-29 10:16:30 +05302060 return true;
2061}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002062EXPORT_SYMBOL(ath9k_hw_set_keycache_entry);
Sujithf1dc5602008-10-29 10:16:30 +05302063
Sujithcbe61d82009-02-09 13:27:12 +05302064bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry)
Sujithf1dc5602008-10-29 10:16:30 +05302065{
Sujith2660b812009-02-09 13:27:26 +05302066 if (entry < ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05302067 u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
2068 if (val & AR_KEYTABLE_VALID)
2069 return true;
2070 }
2071 return false;
2072}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002073EXPORT_SYMBOL(ath9k_hw_keyisvalid);
Sujithf1dc5602008-10-29 10:16:30 +05302074
2075/******************************/
2076/* Power Management (Chipset) */
2077/******************************/
2078
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04002079/*
2080 * Notify Power Mgt is disabled in self-generated frames.
2081 * If requested, force chip to sleep.
2082 */
Sujithcbe61d82009-02-09 13:27:12 +05302083static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302084{
2085 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2086 if (setChip) {
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04002087 /*
2088 * Clear the RTC force wake bit to allow the
2089 * mac to go to sleep.
2090 */
Sujithf1dc5602008-10-29 10:16:30 +05302091 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2092 AR_RTC_FORCE_WAKE_EN);
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04002093 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302094 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
2095
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04002096 /* Shutdown chip. Active low */
Sujith14b3af32010-03-17 14:25:18 +05302097 if (!AR_SREV_5416(ah) && !AR_SREV_9271(ah))
Sujith4921be82009-09-18 15:04:27 +05302098 REG_CLR_BIT(ah, (AR_RTC_RESET),
2099 AR_RTC_RESET_EN);
Sujithf1dc5602008-10-29 10:16:30 +05302100 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002101}
2102
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04002103/*
2104 * Notify Power Management is enabled in self-generating
2105 * frames. If request, set power mode of chip to
2106 * auto/normal. Duration in units of 128us (1/8 TU).
2107 */
Sujithcbe61d82009-02-09 13:27:12 +05302108static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002109{
Sujithf1dc5602008-10-29 10:16:30 +05302110 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2111 if (setChip) {
Sujith2660b812009-02-09 13:27:26 +05302112 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002113
Sujithf1dc5602008-10-29 10:16:30 +05302114 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04002115 /* Set WakeOnInterrupt bit; clear ForceWake bit */
Sujithf1dc5602008-10-29 10:16:30 +05302116 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2117 AR_RTC_FORCE_WAKE_ON_INT);
2118 } else {
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04002119 /*
2120 * Clear the RTC force wake bit to allow the
2121 * mac to go to sleep.
2122 */
Sujithf1dc5602008-10-29 10:16:30 +05302123 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2124 AR_RTC_FORCE_WAKE_EN);
2125 }
2126 }
2127}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002128
Sujithcbe61d82009-02-09 13:27:12 +05302129static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302130{
2131 u32 val;
2132 int i;
2133
2134 if (setChip) {
2135 if ((REG_READ(ah, AR_RTC_STATUS) &
2136 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2137 if (ath9k_hw_set_reset_reg(ah,
2138 ATH9K_RESET_POWER_ON) != true) {
2139 return false;
2140 }
Luis R. Rodrigueze0412282010-04-15 17:38:15 -04002141 if (!AR_SREV_9300_20_OR_LATER(ah))
2142 ath9k_hw_init_pll(ah, NULL);
Sujithf1dc5602008-10-29 10:16:30 +05302143 }
2144 if (AR_SREV_9100(ah))
2145 REG_SET_BIT(ah, AR_RTC_RESET,
2146 AR_RTC_RESET_EN);
2147
2148 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2149 AR_RTC_FORCE_WAKE_EN);
2150 udelay(50);
2151
2152 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2153 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2154 if (val == AR_RTC_STATUS_ON)
2155 break;
2156 udelay(50);
2157 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2158 AR_RTC_FORCE_WAKE_EN);
2159 }
2160 if (i == 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002161 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2162 "Failed to wakeup in %uus\n",
2163 POWER_UP_TIME / 20);
Sujithf1dc5602008-10-29 10:16:30 +05302164 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002165 }
2166 }
2167
Sujithf1dc5602008-10-29 10:16:30 +05302168 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2169
2170 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002171}
2172
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002173bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05302174{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002175 struct ath_common *common = ath9k_hw_common(ah);
Sujithcbe61d82009-02-09 13:27:12 +05302176 int status = true, setChip = true;
Sujithf1dc5602008-10-29 10:16:30 +05302177 static const char *modes[] = {
2178 "AWAKE",
2179 "FULL-SLEEP",
2180 "NETWORK SLEEP",
2181 "UNDEFINED"
2182 };
Sujithf1dc5602008-10-29 10:16:30 +05302183
Gabor Juhoscbdec972009-07-24 17:27:22 +02002184 if (ah->power_mode == mode)
2185 return status;
2186
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002187 ath_print(common, ATH_DBG_RESET, "%s -> %s\n",
2188 modes[ah->power_mode], modes[mode]);
Sujithf1dc5602008-10-29 10:16:30 +05302189
2190 switch (mode) {
2191 case ATH9K_PM_AWAKE:
2192 status = ath9k_hw_set_power_awake(ah, setChip);
2193 break;
2194 case ATH9K_PM_FULL_SLEEP:
2195 ath9k_set_power_sleep(ah, setChip);
Sujith2660b812009-02-09 13:27:26 +05302196 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05302197 break;
2198 case ATH9K_PM_NETWORK_SLEEP:
2199 ath9k_set_power_network_sleep(ah, setChip);
2200 break;
2201 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002202 ath_print(common, ATH_DBG_FATAL,
2203 "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05302204 return false;
2205 }
Sujith2660b812009-02-09 13:27:26 +05302206 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05302207
2208 return status;
2209}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002210EXPORT_SYMBOL(ath9k_hw_setpower);
Sujithf1dc5602008-10-29 10:16:30 +05302211
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002212/*
2213 * Helper for ASPM support.
2214 *
2215 * Disable PLL when in L0s as well as receiver clock when in L1.
2216 * This power saving option must be enabled through the SerDes.
2217 *
2218 * Programming the SerDes must go through the same 288 bit serial shift
2219 * register as the other analog registers. Hence the 9 writes.
2220 */
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04002221static void ar9002_hw_configpcipowersave(struct ath_hw *ah,
2222 int restore,
2223 int power_off)
Sujithf1dc5602008-10-29 10:16:30 +05302224{
Sujithf1dc5602008-10-29 10:16:30 +05302225 u8 i;
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302226 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05302227
Sujith2660b812009-02-09 13:27:26 +05302228 if (ah->is_pciexpress != true)
Sujithf1dc5602008-10-29 10:16:30 +05302229 return;
2230
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002231 /* Do not touch SerDes registers */
Sujith2660b812009-02-09 13:27:26 +05302232 if (ah->config.pcie_powersave_enable == 2)
Sujithf1dc5602008-10-29 10:16:30 +05302233 return;
2234
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002235 /* Nothing to do on restore for 11N */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302236 if (!restore) {
2237 if (AR_SREV_9280_20_OR_LATER(ah)) {
2238 /*
2239 * AR9280 2.0 or later chips use SerDes values from the
2240 * initvals.h initialized depending on chipset during
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04002241 * __ath9k_hw_init()
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302242 */
2243 for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
2244 REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
2245 INI_RA(&ah->iniPcieSerdes, i, 1));
2246 }
2247 } else if (AR_SREV_9280(ah) &&
2248 (ah->hw_version.macRev == AR_SREV_REVISION_9280_10)) {
2249 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
2250 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
Sujithf1dc5602008-10-29 10:16:30 +05302251
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302252 /* RX shut off when elecidle is asserted */
2253 REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
2254 REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
2255 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
2256
2257 /* Shut off CLKREQ active in L1 */
2258 if (ah->config.pcie_clock_req)
2259 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
2260 else
2261 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
2262
2263 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2264 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2265 REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
2266
2267 /* Load the new settings */
2268 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
2269
2270 } else {
2271 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
2272 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
2273
2274 /* RX shut off when elecidle is asserted */
2275 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
2276 REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
2277 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
2278
2279 /*
2280 * Ignore ah->ah_config.pcie_clock_req setting for
2281 * pre-AR9280 11n
2282 */
2283 REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
2284
2285 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2286 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2287 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
2288
2289 /* Load the new settings */
2290 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
Sujithf1dc5602008-10-29 10:16:30 +05302291 }
Sujithf1dc5602008-10-29 10:16:30 +05302292
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302293 udelay(1000);
Sujithf1dc5602008-10-29 10:16:30 +05302294
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302295 /* set bit 19 to allow forcing of pcie core into L1 state */
2296 REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
Sujithf1dc5602008-10-29 10:16:30 +05302297
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302298 /* Several PCIe massages to ensure proper behaviour */
2299 if (ah->config.pcie_waen) {
2300 val = ah->config.pcie_waen;
2301 if (!power_off)
2302 val &= (~AR_WA_D3_L1_DISABLE);
2303 } else {
2304 if (AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
2305 AR_SREV_9287(ah)) {
2306 val = AR9285_WA_DEFAULT;
2307 if (!power_off)
2308 val &= (~AR_WA_D3_L1_DISABLE);
2309 } else if (AR_SREV_9280(ah)) {
2310 /*
2311 * On AR9280 chips bit 22 of 0x4004 needs to be
2312 * set otherwise card may disappear.
2313 */
2314 val = AR9280_WA_DEFAULT;
2315 if (!power_off)
2316 val &= (~AR_WA_D3_L1_DISABLE);
2317 } else
2318 val = AR_WA_DEFAULT;
2319 }
Sujithf1dc5602008-10-29 10:16:30 +05302320
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302321 REG_WRITE(ah, AR_WA, val);
Sujithf1dc5602008-10-29 10:16:30 +05302322 }
2323
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302324 if (power_off) {
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002325 /*
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302326 * Set PCIe workaround bits
2327 * bit 14 in WA register (disable L1) should only
2328 * be set when device enters D3 and be cleared
2329 * when device comes back to D0.
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002330 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302331 if (ah->config.pcie_waen) {
2332 if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE)
2333 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
2334 } else {
2335 if (((AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
2336 AR_SREV_9287(ah)) &&
2337 (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)) ||
2338 (AR_SREV_9280(ah) &&
2339 (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE))) {
2340 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
2341 }
2342 }
Sujithf1dc5602008-10-29 10:16:30 +05302343 }
2344}
2345
2346/**********************/
2347/* Interrupt Handling */
2348/**********************/
2349
Sujithcbe61d82009-02-09 13:27:12 +05302350bool ath9k_hw_intrpend(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002351{
2352 u32 host_isr;
2353
2354 if (AR_SREV_9100(ah))
2355 return true;
2356
2357 host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
2358 if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
2359 return true;
2360
2361 host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
2362 if ((host_isr & AR_INTR_SYNC_DEFAULT)
2363 && (host_isr != AR_INTR_SPURIOUS))
2364 return true;
2365
2366 return false;
2367}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002368EXPORT_SYMBOL(ath9k_hw_intrpend);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002369
Sujithcbe61d82009-02-09 13:27:12 +05302370bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002371{
2372 u32 isr = 0;
2373 u32 mask2 = 0;
Sujith2660b812009-02-09 13:27:26 +05302374 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002375 u32 sync_cause = 0;
2376 bool fatal_int = false;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002377 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002378
2379 if (!AR_SREV_9100(ah)) {
2380 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
2381 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
2382 == AR_RTC_STATUS_ON) {
2383 isr = REG_READ(ah, AR_ISR);
2384 }
2385 }
2386
Sujithf1dc5602008-10-29 10:16:30 +05302387 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
2388 AR_INTR_SYNC_DEFAULT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002389
2390 *masked = 0;
2391
2392 if (!isr && !sync_cause)
2393 return false;
2394 } else {
2395 *masked = 0;
2396 isr = REG_READ(ah, AR_ISR);
2397 }
2398
2399 if (isr) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002400 if (isr & AR_ISR_BCNMISC) {
2401 u32 isr2;
2402 isr2 = REG_READ(ah, AR_ISR_S2);
2403 if (isr2 & AR_ISR_S2_TIM)
2404 mask2 |= ATH9K_INT_TIM;
2405 if (isr2 & AR_ISR_S2_DTIM)
2406 mask2 |= ATH9K_INT_DTIM;
2407 if (isr2 & AR_ISR_S2_DTIMSYNC)
2408 mask2 |= ATH9K_INT_DTIMSYNC;
2409 if (isr2 & (AR_ISR_S2_CABEND))
2410 mask2 |= ATH9K_INT_CABEND;
2411 if (isr2 & AR_ISR_S2_GTT)
2412 mask2 |= ATH9K_INT_GTT;
2413 if (isr2 & AR_ISR_S2_CST)
2414 mask2 |= ATH9K_INT_CST;
Sujith4af9cf42009-02-12 10:06:47 +05302415 if (isr2 & AR_ISR_S2_TSFOOR)
2416 mask2 |= ATH9K_INT_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002417 }
2418
2419 isr = REG_READ(ah, AR_ISR_RAC);
2420 if (isr == 0xffffffff) {
2421 *masked = 0;
2422 return false;
2423 }
2424
2425 *masked = isr & ATH9K_INT_COMMON;
2426
Sujith0ce024c2009-12-14 14:57:00 +05302427 if (ah->config.rx_intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002428 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
2429 *masked |= ATH9K_INT_RX;
2430 }
2431
2432 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
2433 *masked |= ATH9K_INT_RX;
2434 if (isr &
2435 (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
2436 AR_ISR_TXEOL)) {
2437 u32 s0_s, s1_s;
2438
2439 *masked |= ATH9K_INT_TX;
2440
2441 s0_s = REG_READ(ah, AR_ISR_S0_S);
Sujith2660b812009-02-09 13:27:26 +05302442 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
2443 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002444
2445 s1_s = REG_READ(ah, AR_ISR_S1_S);
Sujith2660b812009-02-09 13:27:26 +05302446 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
2447 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002448 }
2449
2450 if (isr & AR_ISR_RXORN) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002451 ath_print(common, ATH_DBG_INTERRUPT,
2452 "receive FIFO overrun interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002453 }
2454
2455 if (!AR_SREV_9100(ah)) {
Sujith60b67f52008-08-07 10:52:38 +05302456 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002457 u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
2458 if (isr5 & AR_ISR_S5_TIM_TIMER)
2459 *masked |= ATH9K_INT_TIM_TIMER;
2460 }
2461 }
2462
2463 *masked |= mask2;
2464 }
Sujithf1dc5602008-10-29 10:16:30 +05302465
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002466 if (AR_SREV_9100(ah))
2467 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302468
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302469 if (isr & AR_ISR_GENTMR) {
2470 u32 s5_s;
2471
2472 s5_s = REG_READ(ah, AR_ISR_S5_S);
2473 if (isr & AR_ISR_GENTMR) {
2474 ah->intr_gen_timer_trigger =
2475 MS(s5_s, AR_ISR_S5_GENTIMER_TRIG);
2476
2477 ah->intr_gen_timer_thresh =
2478 MS(s5_s, AR_ISR_S5_GENTIMER_THRESH);
2479
2480 if (ah->intr_gen_timer_trigger)
2481 *masked |= ATH9K_INT_GENTIMER;
2482
2483 }
2484 }
2485
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002486 if (sync_cause) {
2487 fatal_int =
2488 (sync_cause &
2489 (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
2490 ? true : false;
2491
2492 if (fatal_int) {
2493 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002494 ath_print(common, ATH_DBG_ANY,
2495 "received PCI FATAL interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002496 }
2497 if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002498 ath_print(common, ATH_DBG_ANY,
2499 "received PCI PERR interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002500 }
Steven Luoa89bff92009-04-12 02:57:54 -07002501 *masked |= ATH9K_INT_FATAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002502 }
2503 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002504 ath_print(common, ATH_DBG_INTERRUPT,
2505 "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002506 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
2507 REG_WRITE(ah, AR_RC, 0);
2508 *masked |= ATH9K_INT_FATAL;
2509 }
2510 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002511 ath_print(common, ATH_DBG_INTERRUPT,
2512 "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002513 }
2514
2515 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
2516 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
2517 }
Sujithf1dc5602008-10-29 10:16:30 +05302518
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002519 return true;
2520}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002521EXPORT_SYMBOL(ath9k_hw_getisr);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002522
Sujithcbe61d82009-02-09 13:27:12 +05302523enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002524{
Pavel Roskin152d5302010-03-31 18:05:37 -04002525 enum ath9k_int omask = ah->imask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002526 u32 mask, mask2;
Sujith2660b812009-02-09 13:27:26 +05302527 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002528 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002529
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002530 ath_print(common, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002531
2532 if (omask & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002533 ath_print(common, ATH_DBG_INTERRUPT, "disable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002534 REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
2535 (void) REG_READ(ah, AR_IER);
2536 if (!AR_SREV_9100(ah)) {
2537 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
2538 (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
2539
2540 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
2541 (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
2542 }
2543 }
2544
2545 mask = ints & ATH9K_INT_COMMON;
2546 mask2 = 0;
2547
2548 if (ints & ATH9K_INT_TX) {
Sujith2660b812009-02-09 13:27:26 +05302549 if (ah->txok_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002550 mask |= AR_IMR_TXOK;
Sujith2660b812009-02-09 13:27:26 +05302551 if (ah->txdesc_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002552 mask |= AR_IMR_TXDESC;
Sujith2660b812009-02-09 13:27:26 +05302553 if (ah->txerr_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002554 mask |= AR_IMR_TXERR;
Sujith2660b812009-02-09 13:27:26 +05302555 if (ah->txeol_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002556 mask |= AR_IMR_TXEOL;
2557 }
2558 if (ints & ATH9K_INT_RX) {
2559 mask |= AR_IMR_RXERR;
Sujith0ce024c2009-12-14 14:57:00 +05302560 if (ah->config.rx_intr_mitigation)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002561 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
2562 else
2563 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
Sujith60b67f52008-08-07 10:52:38 +05302564 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002565 mask |= AR_IMR_GENTMR;
2566 }
2567
2568 if (ints & (ATH9K_INT_BMISC)) {
2569 mask |= AR_IMR_BCNMISC;
2570 if (ints & ATH9K_INT_TIM)
2571 mask2 |= AR_IMR_S2_TIM;
2572 if (ints & ATH9K_INT_DTIM)
2573 mask2 |= AR_IMR_S2_DTIM;
2574 if (ints & ATH9K_INT_DTIMSYNC)
2575 mask2 |= AR_IMR_S2_DTIMSYNC;
2576 if (ints & ATH9K_INT_CABEND)
Sujith4af9cf42009-02-12 10:06:47 +05302577 mask2 |= AR_IMR_S2_CABEND;
2578 if (ints & ATH9K_INT_TSFOOR)
2579 mask2 |= AR_IMR_S2_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002580 }
2581
2582 if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
2583 mask |= AR_IMR_BCNMISC;
2584 if (ints & ATH9K_INT_GTT)
2585 mask2 |= AR_IMR_S2_GTT;
2586 if (ints & ATH9K_INT_CST)
2587 mask2 |= AR_IMR_S2_CST;
2588 }
2589
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002590 ath_print(common, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002591 REG_WRITE(ah, AR_IMR, mask);
Pavel Roskin74bad5c2010-02-23 18:15:27 -05002592 ah->imrs2_reg &= ~(AR_IMR_S2_TIM | AR_IMR_S2_DTIM | AR_IMR_S2_DTIMSYNC |
2593 AR_IMR_S2_CABEND | AR_IMR_S2_CABTO |
2594 AR_IMR_S2_TSFOOR | AR_IMR_S2_GTT | AR_IMR_S2_CST);
2595 ah->imrs2_reg |= mask2;
2596 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002597
Sujith60b67f52008-08-07 10:52:38 +05302598 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002599 if (ints & ATH9K_INT_TIM_TIMER)
2600 REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
2601 else
2602 REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
2603 }
2604
2605 if (ints & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002606 ath_print(common, ATH_DBG_INTERRUPT, "enable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002607 REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
2608 if (!AR_SREV_9100(ah)) {
2609 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
2610 AR_INTR_MAC_IRQ);
2611 REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
2612
2613
2614 REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
2615 AR_INTR_SYNC_DEFAULT);
2616 REG_WRITE(ah, AR_INTR_SYNC_MASK,
2617 AR_INTR_SYNC_DEFAULT);
2618 }
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002619 ath_print(common, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
2620 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002621 }
2622
2623 return omask;
2624}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002625EXPORT_SYMBOL(ath9k_hw_set_interrupts);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002626
Sujithf1dc5602008-10-29 10:16:30 +05302627/*******************/
2628/* Beacon Handling */
2629/*******************/
2630
Sujithcbe61d82009-02-09 13:27:12 +05302631void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002632{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002633 int flags = 0;
2634
Sujith2660b812009-02-09 13:27:26 +05302635 ah->beacon_interval = beacon_period;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002636
Sujith2660b812009-02-09 13:27:26 +05302637 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08002638 case NL80211_IFTYPE_STATION:
2639 case NL80211_IFTYPE_MONITOR:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002640 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
2641 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
2642 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
2643 flags |= AR_TBTT_TIMER_EN;
2644 break;
Colin McCabed97809d2008-12-01 13:38:55 -08002645 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04002646 case NL80211_IFTYPE_MESH_POINT:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002647 REG_SET_BIT(ah, AR_TXCFG,
2648 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
2649 REG_WRITE(ah, AR_NEXT_NDP_TIMER,
2650 TU_TO_USEC(next_beacon +
Sujith2660b812009-02-09 13:27:26 +05302651 (ah->atim_window ? ah->
2652 atim_window : 1)));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002653 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08002654 case NL80211_IFTYPE_AP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002655 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
2656 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
2657 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05302658 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302659 dma_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002660 REG_WRITE(ah, AR_NEXT_SWBA,
2661 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05302662 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302663 sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002664 flags |=
2665 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
2666 break;
Colin McCabed97809d2008-12-01 13:38:55 -08002667 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002668 ath_print(ath9k_hw_common(ah), ATH_DBG_BEACON,
2669 "%s: unsupported opmode: %d\n",
2670 __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08002671 return;
2672 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002673 }
2674
2675 REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
2676 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
2677 REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
2678 REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
2679
2680 beacon_period &= ~ATH9K_BEACON_ENA;
2681 if (beacon_period & ATH9K_BEACON_RESET_TSF) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002682 ath9k_hw_reset_tsf(ah);
2683 }
2684
2685 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
2686}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002687EXPORT_SYMBOL(ath9k_hw_beaconinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002688
Sujithcbe61d82009-02-09 13:27:12 +05302689void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05302690 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002691{
2692 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05302693 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002694 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002695
2696 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
2697
2698 REG_WRITE(ah, AR_BEACON_PERIOD,
2699 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
2700 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
2701 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
2702
2703 REG_RMW_FIELD(ah, AR_RSSI_THR,
2704 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
2705
2706 beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
2707
2708 if (bs->bs_sleepduration > beaconintval)
2709 beaconintval = bs->bs_sleepduration;
2710
2711 dtimperiod = bs->bs_dtimperiod;
2712 if (bs->bs_sleepduration > dtimperiod)
2713 dtimperiod = bs->bs_sleepduration;
2714
2715 if (beaconintval == dtimperiod)
2716 nextTbtt = bs->bs_nextdtim;
2717 else
2718 nextTbtt = bs->bs_nexttbtt;
2719
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002720 ath_print(common, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
2721 ath_print(common, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
2722 ath_print(common, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
2723 ath_print(common, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002724
2725 REG_WRITE(ah, AR_NEXT_DTIM,
2726 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
2727 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
2728
2729 REG_WRITE(ah, AR_SLEEP1,
2730 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
2731 | AR_SLEEP1_ASSUME_DTIM);
2732
Sujith60b67f52008-08-07 10:52:38 +05302733 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002734 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
2735 else
2736 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
2737
2738 REG_WRITE(ah, AR_SLEEP2,
2739 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
2740
2741 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
2742 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
2743
2744 REG_SET_BIT(ah, AR_TIMER_MODE,
2745 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
2746 AR_DTIM_TIMER_EN);
2747
Sujith4af9cf42009-02-12 10:06:47 +05302748 /* TSF Out of Range Threshold */
2749 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002750}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002751EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002752
Sujithf1dc5602008-10-29 10:16:30 +05302753/*******************/
2754/* HW Capabilities */
2755/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002756
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002757int ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002758{
Sujith2660b812009-02-09 13:27:26 +05302759 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002760 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002761 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002762 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002763
Sujithf1dc5602008-10-29 10:16:30 +05302764 u16 capField = 0, eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002765
Sujithf74df6f2009-02-09 13:27:24 +05302766 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002767 regulatory->current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05302768
Sujithf74df6f2009-02-09 13:27:24 +05302769 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
Sujithfec0de12009-02-12 10:06:43 +05302770 if (AR_SREV_9285_10_OR_LATER(ah))
2771 eeval |= AR9285_RDEXT_DEFAULT;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002772 regulatory->current_rd_ext = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05302773
Sujithf74df6f2009-02-09 13:27:24 +05302774 capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
Sujithf1dc5602008-10-29 10:16:30 +05302775
Sujith2660b812009-02-09 13:27:26 +05302776 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05302777 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002778 if (regulatory->current_rd == 0x64 ||
2779 regulatory->current_rd == 0x65)
2780 regulatory->current_rd += 5;
2781 else if (regulatory->current_rd == 0x41)
2782 regulatory->current_rd = 0x43;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002783 ath_print(common, ATH_DBG_REGULATORY,
2784 "regdomain mapped to 0x%x\n", regulatory->current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002785 }
Sujithdc2222a2008-08-14 13:26:55 +05302786
Sujithf74df6f2009-02-09 13:27:24 +05302787 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002788 if ((eeval & (AR5416_OPFLAGS_11G | AR5416_OPFLAGS_11A)) == 0) {
2789 ath_print(common, ATH_DBG_FATAL,
2790 "no band has been marked as supported in EEPROM.\n");
2791 return -EINVAL;
2792 }
2793
Sujithf1dc5602008-10-29 10:16:30 +05302794 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002795
Sujithf1dc5602008-10-29 10:16:30 +05302796 if (eeval & AR5416_OPFLAGS_11A) {
2797 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05302798 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05302799 if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
2800 set_bit(ATH9K_MODE_11NA_HT20,
2801 pCap->wireless_modes);
2802 if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
2803 set_bit(ATH9K_MODE_11NA_HT40PLUS,
2804 pCap->wireless_modes);
2805 set_bit(ATH9K_MODE_11NA_HT40MINUS,
2806 pCap->wireless_modes);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002807 }
2808 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002809 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002810
Sujithf1dc5602008-10-29 10:16:30 +05302811 if (eeval & AR5416_OPFLAGS_11G) {
Sujithf1dc5602008-10-29 10:16:30 +05302812 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05302813 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05302814 if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
2815 set_bit(ATH9K_MODE_11NG_HT20,
2816 pCap->wireless_modes);
2817 if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
2818 set_bit(ATH9K_MODE_11NG_HT40PLUS,
2819 pCap->wireless_modes);
2820 set_bit(ATH9K_MODE_11NG_HT40MINUS,
2821 pCap->wireless_modes);
2822 }
2823 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002824 }
Sujithf1dc5602008-10-29 10:16:30 +05302825
Sujithf74df6f2009-02-09 13:27:24 +05302826 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002827 /*
2828 * For AR9271 we will temporarilly uses the rx chainmax as read from
2829 * the EEPROM.
2830 */
Sujith8147f5d2009-02-20 15:13:23 +05302831 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002832 !(eeval & AR5416_OPFLAGS_11A) &&
2833 !(AR_SREV_9271(ah)))
2834 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
Sujith8147f5d2009-02-20 15:13:23 +05302835 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
2836 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002837 /* Use rx_chainmask from EEPROM. */
Sujith8147f5d2009-02-20 15:13:23 +05302838 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05302839
Sujithd535a422009-02-09 13:27:06 +05302840 if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0)))
Sujith2660b812009-02-09 13:27:26 +05302841 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05302842
2843 pCap->low_2ghz_chan = 2312;
2844 pCap->high_2ghz_chan = 2732;
2845
2846 pCap->low_5ghz_chan = 4920;
2847 pCap->high_5ghz_chan = 6100;
2848
2849 pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
2850 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
2851 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
2852
2853 pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
2854 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
2855 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
2856
Sujith2660b812009-02-09 13:27:26 +05302857 if (ah->config.ht_enable)
Sujithf1dc5602008-10-29 10:16:30 +05302858 pCap->hw_caps |= ATH9K_HW_CAP_HT;
2859 else
2860 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
2861
2862 pCap->hw_caps |= ATH9K_HW_CAP_GTT;
2863 pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
2864 pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
2865 pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
2866
2867 if (capField & AR_EEPROM_EEPCAP_MAXQCU)
2868 pCap->total_queues =
2869 MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
2870 else
2871 pCap->total_queues = ATH9K_NUM_TX_QUEUES;
2872
2873 if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
2874 pCap->keycache_size =
2875 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
2876 else
2877 pCap->keycache_size = AR_KEYTABLE_SIZE;
2878
2879 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -05002880
2881 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
2882 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD >> 1;
2883 else
2884 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
Sujithf1dc5602008-10-29 10:16:30 +05302885
Sujith5b5fa352010-03-17 14:25:15 +05302886 if (AR_SREV_9271(ah))
2887 pCap->num_gpio_pins = AR9271_NUM_GPIO;
2888 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302889 pCap->num_gpio_pins = AR9285_NUM_GPIO;
2890 else if (AR_SREV_9280_10_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302891 pCap->num_gpio_pins = AR928X_NUM_GPIO;
2892 else
2893 pCap->num_gpio_pins = AR_NUM_GPIO;
2894
Sujithf1dc5602008-10-29 10:16:30 +05302895 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
2896 pCap->hw_caps |= ATH9K_HW_CAP_CST;
2897 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
2898 } else {
2899 pCap->rts_aggr_limit = (8 * 1024);
2900 }
2901
2902 pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
2903
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05302904#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05302905 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
2906 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
2907 ah->rfkill_gpio =
2908 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
2909 ah->rfkill_polarity =
2910 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05302911
2912 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
2913 }
2914#endif
Vivek Natarajanbde748a2010-04-05 14:48:05 +05302915 if (AR_SREV_9271(ah))
2916 pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
2917 else
2918 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
Sujithf1dc5602008-10-29 10:16:30 +05302919
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302920 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302921 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
2922 else
2923 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
2924
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002925 if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) {
Sujithf1dc5602008-10-29 10:16:30 +05302926 pCap->reg_cap =
2927 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
2928 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
2929 AR_EEPROM_EEREGCAP_EN_KK_U2 |
2930 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
2931 } else {
2932 pCap->reg_cap =
2933 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
2934 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
2935 }
2936
Senthil Balasubramanianebb90cf2009-09-18 15:07:33 +05302937 /* Advertise midband for AR5416 with FCC midband set in eeprom */
2938 if (regulatory->current_rd_ext & (1 << REG_EXT_FCC_MIDBAND) &&
2939 AR_SREV_5416(ah))
2940 pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
Sujithf1dc5602008-10-29 10:16:30 +05302941
2942 pCap->num_antcfg_5ghz =
Sujithf74df6f2009-02-09 13:27:24 +05302943 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05302944 pCap->num_antcfg_2ghz =
Sujithf74df6f2009-02-09 13:27:24 +05302945 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05302946
Vasanthakumar Thiagarajanfe129462009-09-09 15:25:50 +05302947 if (AR_SREV_9280_10_OR_LATER(ah) &&
Luis R. Rodrigueza36cfbc2009-09-09 16:05:32 -07002948 ath9k_hw_btcoex_supported(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002949 btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO;
2950 btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO;
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05302951
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302952 if (AR_SREV_9285(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002953 btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
2954 btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302955 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002956 btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302957 }
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05302958 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002959 btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE;
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05302960 }
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002961
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002962 if (AR_SREV_9300_20_OR_LATER(ah)) {
Vasanthakumar Thiagarajan1adf02f2010-04-15 17:38:24 -04002963 pCap->hw_caps |= ATH9K_HW_CAP_EDMA;
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002964 pCap->rx_hp_qdepth = ATH9K_HW_RX_HP_QDEPTH;
2965 pCap->rx_lp_qdepth = ATH9K_HW_RX_LP_QDEPTH;
2966 pCap->rx_status_len = sizeof(struct ar9003_rxs);
Vasanthakumar Thiagarajan162c3be2010-04-15 17:38:41 -04002967 pCap->tx_desc_len = sizeof(struct ar9003_txc);
2968 } else {
2969 pCap->tx_desc_len = sizeof(struct ath_desc);
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002970 }
Vasanthakumar Thiagarajan1adf02f2010-04-15 17:38:24 -04002971
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002972 return 0;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002973}
2974
Sujithcbe61d82009-02-09 13:27:12 +05302975bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05302976 u32 capability, u32 *result)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002977{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002978 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302979 switch (type) {
2980 case ATH9K_CAP_CIPHER:
2981 switch (capability) {
2982 case ATH9K_CIPHER_AES_CCM:
2983 case ATH9K_CIPHER_AES_OCB:
2984 case ATH9K_CIPHER_TKIP:
2985 case ATH9K_CIPHER_WEP:
2986 case ATH9K_CIPHER_MIC:
2987 case ATH9K_CIPHER_CLR:
2988 return true;
2989 default:
2990 return false;
2991 }
2992 case ATH9K_CAP_TKIP_MIC:
2993 switch (capability) {
2994 case 0:
2995 return true;
2996 case 1:
Sujith2660b812009-02-09 13:27:26 +05302997 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05302998 AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
2999 false;
3000 }
3001 case ATH9K_CAP_TKIP_SPLIT:
Sujith2660b812009-02-09 13:27:26 +05303002 return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ?
Sujithf1dc5602008-10-29 10:16:30 +05303003 false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303004 case ATH9K_CAP_MCAST_KEYSRCH:
3005 switch (capability) {
3006 case 0:
3007 return true;
3008 case 1:
3009 if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
3010 return false;
3011 } else {
Sujith2660b812009-02-09 13:27:26 +05303012 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303013 AR_STA_ID1_MCAST_KSRCH) ? true :
3014 false;
3015 }
3016 }
3017 return false;
Sujithf1dc5602008-10-29 10:16:30 +05303018 case ATH9K_CAP_TXPOW:
3019 switch (capability) {
3020 case 0:
3021 return 0;
3022 case 1:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003023 *result = regulatory->power_limit;
Sujithf1dc5602008-10-29 10:16:30 +05303024 return 0;
3025 case 2:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003026 *result = regulatory->max_power_level;
Sujithf1dc5602008-10-29 10:16:30 +05303027 return 0;
3028 case 3:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003029 *result = regulatory->tp_scale;
Sujithf1dc5602008-10-29 10:16:30 +05303030 return 0;
3031 }
3032 return false;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05303033 case ATH9K_CAP_DS:
3034 return (AR_SREV_9280_20_OR_LATER(ah) &&
3035 (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1))
3036 ? false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303037 default:
3038 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003039 }
Sujithf1dc5602008-10-29 10:16:30 +05303040}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003041EXPORT_SYMBOL(ath9k_hw_getcapability);
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003042
Sujithcbe61d82009-02-09 13:27:12 +05303043bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303044 u32 capability, u32 setting, int *status)
3045{
Sujithf1dc5602008-10-29 10:16:30 +05303046 switch (type) {
3047 case ATH9K_CAP_TKIP_MIC:
3048 if (setting)
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 else
Sujith2660b812009-02-09 13:27:26 +05303052 ah->sta_id1_defaults &=
Sujithf1dc5602008-10-29 10:16:30 +05303053 ~AR_STA_ID1_CRPT_MIC_ENABLE;
3054 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303055 case ATH9K_CAP_MCAST_KEYSRCH:
3056 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303057 ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303058 else
Sujith2660b812009-02-09 13:27:26 +05303059 ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303060 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303061 default:
3062 return false;
3063 }
3064}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003065EXPORT_SYMBOL(ath9k_hw_setcapability);
Sujithf1dc5602008-10-29 10:16:30 +05303066
3067/****************************/
3068/* GPIO / RFKILL / Antennae */
3069/****************************/
3070
Sujithcbe61d82009-02-09 13:27:12 +05303071static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303072 u32 gpio, u32 type)
3073{
3074 int addr;
3075 u32 gpio_shift, tmp;
3076
3077 if (gpio > 11)
3078 addr = AR_GPIO_OUTPUT_MUX3;
3079 else if (gpio > 5)
3080 addr = AR_GPIO_OUTPUT_MUX2;
3081 else
3082 addr = AR_GPIO_OUTPUT_MUX1;
3083
3084 gpio_shift = (gpio % 6) * 5;
3085
3086 if (AR_SREV_9280_20_OR_LATER(ah)
3087 || (addr != AR_GPIO_OUTPUT_MUX1)) {
3088 REG_RMW(ah, addr, (type << gpio_shift),
3089 (0x1f << gpio_shift));
3090 } else {
3091 tmp = REG_READ(ah, addr);
3092 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
3093 tmp &= ~(0x1f << gpio_shift);
3094 tmp |= (type << gpio_shift);
3095 REG_WRITE(ah, addr, tmp);
3096 }
3097}
3098
Sujithcbe61d82009-02-09 13:27:12 +05303099void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303100{
3101 u32 gpio_shift;
3102
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07003103 BUG_ON(gpio >= ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05303104
3105 gpio_shift = gpio << 1;
3106
3107 REG_RMW(ah,
3108 AR_GPIO_OE_OUT,
3109 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
3110 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3111}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003112EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
Sujithf1dc5602008-10-29 10:16:30 +05303113
Sujithcbe61d82009-02-09 13:27:12 +05303114u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303115{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303116#define MS_REG_READ(x, y) \
3117 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
3118
Sujith2660b812009-02-09 13:27:26 +05303119 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05303120 return 0xffffffff;
3121
Felix Fietkau783dfca2010-04-15 17:38:11 -04003122 if (AR_SREV_9300_20_OR_LATER(ah))
3123 return MS_REG_READ(AR9300, gpio) != 0;
3124 else if (AR_SREV_9271(ah))
Sujith5b5fa352010-03-17 14:25:15 +05303125 return MS_REG_READ(AR9271, gpio) != 0;
3126 else if (AR_SREV_9287_10_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05303127 return MS_REG_READ(AR9287, gpio) != 0;
3128 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303129 return MS_REG_READ(AR9285, gpio) != 0;
3130 else if (AR_SREV_9280_10_OR_LATER(ah))
3131 return MS_REG_READ(AR928X, gpio) != 0;
3132 else
3133 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05303134}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003135EXPORT_SYMBOL(ath9k_hw_gpio_get);
Sujithf1dc5602008-10-29 10:16:30 +05303136
Sujithcbe61d82009-02-09 13:27:12 +05303137void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05303138 u32 ah_signal_type)
3139{
3140 u32 gpio_shift;
3141
3142 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
3143
3144 gpio_shift = 2 * gpio;
3145
3146 REG_RMW(ah,
3147 AR_GPIO_OE_OUT,
3148 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
3149 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3150}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003151EXPORT_SYMBOL(ath9k_hw_cfg_output);
Sujithf1dc5602008-10-29 10:16:30 +05303152
Sujithcbe61d82009-02-09 13:27:12 +05303153void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05303154{
Sujith5b5fa352010-03-17 14:25:15 +05303155 if (AR_SREV_9271(ah))
3156 val = ~val;
3157
Sujithf1dc5602008-10-29 10:16:30 +05303158 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
3159 AR_GPIO_BIT(gpio));
3160}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003161EXPORT_SYMBOL(ath9k_hw_set_gpio);
Sujithf1dc5602008-10-29 10:16:30 +05303162
Sujithcbe61d82009-02-09 13:27:12 +05303163u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303164{
3165 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
3166}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003167EXPORT_SYMBOL(ath9k_hw_getdefantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303168
Sujithcbe61d82009-02-09 13:27:12 +05303169void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05303170{
3171 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
3172}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003173EXPORT_SYMBOL(ath9k_hw_setantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303174
Sujithf1dc5602008-10-29 10:16:30 +05303175/*********************/
3176/* General Operation */
3177/*********************/
3178
Sujithcbe61d82009-02-09 13:27:12 +05303179u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303180{
3181 u32 bits = REG_READ(ah, AR_RX_FILTER);
3182 u32 phybits = REG_READ(ah, AR_PHY_ERR);
3183
3184 if (phybits & AR_PHY_ERR_RADAR)
3185 bits |= ATH9K_RX_FILTER_PHYRADAR;
3186 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
3187 bits |= ATH9K_RX_FILTER_PHYERR;
3188
3189 return bits;
3190}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003191EXPORT_SYMBOL(ath9k_hw_getrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303192
Sujithcbe61d82009-02-09 13:27:12 +05303193void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05303194{
3195 u32 phybits;
3196
Sujith7ea310b2009-09-03 12:08:43 +05303197 REG_WRITE(ah, AR_RX_FILTER, bits);
3198
Sujithf1dc5602008-10-29 10:16:30 +05303199 phybits = 0;
3200 if (bits & ATH9K_RX_FILTER_PHYRADAR)
3201 phybits |= AR_PHY_ERR_RADAR;
3202 if (bits & ATH9K_RX_FILTER_PHYERR)
3203 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
3204 REG_WRITE(ah, AR_PHY_ERR, phybits);
3205
3206 if (phybits)
3207 REG_WRITE(ah, AR_RXCFG,
3208 REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
3209 else
3210 REG_WRITE(ah, AR_RXCFG,
3211 REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
3212}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003213EXPORT_SYMBOL(ath9k_hw_setrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303214
Sujithcbe61d82009-02-09 13:27:12 +05303215bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303216{
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05303217 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
3218 return false;
3219
3220 ath9k_hw_init_pll(ah, NULL);
3221 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303222}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003223EXPORT_SYMBOL(ath9k_hw_phy_disable);
Sujithf1dc5602008-10-29 10:16:30 +05303224
Sujithcbe61d82009-02-09 13:27:12 +05303225bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303226{
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07003227 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05303228 return false;
3229
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05303230 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
3231 return false;
3232
3233 ath9k_hw_init_pll(ah, NULL);
3234 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303235}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003236EXPORT_SYMBOL(ath9k_hw_disable);
Sujithf1dc5602008-10-29 10:16:30 +05303237
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003238void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
Sujithf1dc5602008-10-29 10:16:30 +05303239{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003240 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujith2660b812009-02-09 13:27:26 +05303241 struct ath9k_channel *chan = ah->curchan;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08003242 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05303243
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003244 regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER);
Sujithf1dc5602008-10-29 10:16:30 +05303245
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003246 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003247 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003248 channel->max_antenna_gain * 2,
3249 channel->max_power * 2,
3250 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003251 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05303252}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003253EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
Sujithf1dc5602008-10-29 10:16:30 +05303254
Sujithcbe61d82009-02-09 13:27:12 +05303255void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac)
Sujithf1dc5602008-10-29 10:16:30 +05303256{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07003257 memcpy(ath9k_hw_common(ah)->macaddr, mac, ETH_ALEN);
Sujithf1dc5602008-10-29 10:16:30 +05303258}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003259EXPORT_SYMBOL(ath9k_hw_setmac);
Sujithf1dc5602008-10-29 10:16:30 +05303260
Sujithcbe61d82009-02-09 13:27:12 +05303261void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303262{
Sujith2660b812009-02-09 13:27:26 +05303263 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05303264}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003265EXPORT_SYMBOL(ath9k_hw_setopmode);
Sujithf1dc5602008-10-29 10:16:30 +05303266
Sujithcbe61d82009-02-09 13:27:12 +05303267void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05303268{
3269 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
3270 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
3271}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003272EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303273
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07003274void ath9k_hw_write_associd(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303275{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07003276 struct ath_common *common = ath9k_hw_common(ah);
3277
3278 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
3279 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
3280 ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05303281}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003282EXPORT_SYMBOL(ath9k_hw_write_associd);
Sujithf1dc5602008-10-29 10:16:30 +05303283
Sujithcbe61d82009-02-09 13:27:12 +05303284u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303285{
3286 u64 tsf;
3287
3288 tsf = REG_READ(ah, AR_TSF_U32);
3289 tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
3290
3291 return tsf;
3292}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003293EXPORT_SYMBOL(ath9k_hw_gettsf64);
Sujithf1dc5602008-10-29 10:16:30 +05303294
Sujithcbe61d82009-02-09 13:27:12 +05303295void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003296{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003297 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01003298 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003299}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003300EXPORT_SYMBOL(ath9k_hw_settsf64);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003301
Sujithcbe61d82009-02-09 13:27:12 +05303302void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303303{
Gabor Juhosf9b604f2009-06-21 00:02:15 +02003304 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
3305 AH_TSF_WRITE_TIMEOUT))
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003306 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
3307 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
Gabor Juhosf9b604f2009-06-21 00:02:15 +02003308
Sujithf1dc5602008-10-29 10:16:30 +05303309 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003310}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003311EXPORT_SYMBOL(ath9k_hw_reset_tsf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003312
Sujith54e4cec2009-08-07 09:45:09 +05303313void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003314{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003315 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303316 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003317 else
Sujith2660b812009-02-09 13:27:26 +05303318 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003319}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003320EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003321
Luis R. Rodriguez30cbd422009-11-03 16:10:46 -08003322/*
3323 * Extend 15-bit time stamp from rx descriptor to
3324 * a full 64-bit TSF using the current h/w TSF.
3325*/
3326u64 ath9k_hw_extend_tsf(struct ath_hw *ah, u32 rstamp)
3327{
3328 u64 tsf;
3329
3330 tsf = ath9k_hw_gettsf64(ah);
3331 if ((tsf & 0x7fff) < rstamp)
3332 tsf -= 0x8000;
3333 return (tsf & ~0x7fff) | rstamp;
3334}
3335EXPORT_SYMBOL(ath9k_hw_extend_tsf);
3336
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003337void ath9k_hw_set11nmac2040(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003338{
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003339 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithf1dc5602008-10-29 10:16:30 +05303340 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003341
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003342 if (conf_is_ht40(conf) && !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05303343 macmode = AR_2040_JOINED_RX_CLEAR;
3344 else
3345 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003346
Sujithf1dc5602008-10-29 10:16:30 +05303347 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003348}
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303349
3350/* HW Generic timers configuration */
3351
3352static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
3353{
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_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3360 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3361 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3362 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
3363 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
3364 AR_NDP2_TIMER_MODE, 0x0002},
3365 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
3366 AR_NDP2_TIMER_MODE, 0x0004},
3367 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
3368 AR_NDP2_TIMER_MODE, 0x0008},
3369 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
3370 AR_NDP2_TIMER_MODE, 0x0010},
3371 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
3372 AR_NDP2_TIMER_MODE, 0x0020},
3373 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
3374 AR_NDP2_TIMER_MODE, 0x0040},
3375 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
3376 AR_NDP2_TIMER_MODE, 0x0080}
3377};
3378
3379/* HW generic timer primitives */
3380
3381/* compute and clear index of rightmost 1 */
3382static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
3383{
3384 u32 b;
3385
3386 b = *mask;
3387 b &= (0-b);
3388 *mask &= ~b;
3389 b *= debruijn32;
3390 b >>= 27;
3391
3392 return timer_table->gen_timer_index[b];
3393}
3394
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05303395u32 ath9k_hw_gettsf32(struct ath_hw *ah)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303396{
3397 return REG_READ(ah, AR_TSF_L32);
3398}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003399EXPORT_SYMBOL(ath9k_hw_gettsf32);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303400
3401struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
3402 void (*trigger)(void *),
3403 void (*overflow)(void *),
3404 void *arg,
3405 u8 timer_index)
3406{
3407 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3408 struct ath_gen_timer *timer;
3409
3410 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
3411
3412 if (timer == NULL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003413 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
3414 "Failed to allocate memory"
3415 "for hw timer[%d]\n", timer_index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303416 return NULL;
3417 }
3418
3419 /* allocate a hardware generic timer slot */
3420 timer_table->timers[timer_index] = timer;
3421 timer->index = timer_index;
3422 timer->trigger = trigger;
3423 timer->overflow = overflow;
3424 timer->arg = arg;
3425
3426 return timer;
3427}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003428EXPORT_SYMBOL(ath_gen_timer_alloc);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303429
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07003430void ath9k_hw_gen_timer_start(struct ath_hw *ah,
3431 struct ath_gen_timer *timer,
3432 u32 timer_next,
3433 u32 timer_period)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303434{
3435 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3436 u32 tsf;
3437
3438 BUG_ON(!timer_period);
3439
3440 set_bit(timer->index, &timer_table->timer_mask.timer_bits);
3441
3442 tsf = ath9k_hw_gettsf32(ah);
3443
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003444 ath_print(ath9k_hw_common(ah), ATH_DBG_HWTIMER,
3445 "curent tsf %x period %x"
3446 "timer_next %x\n", tsf, timer_period, timer_next);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303447
3448 /*
3449 * Pull timer_next forward if the current TSF already passed it
3450 * because of software latency
3451 */
3452 if (timer_next < tsf)
3453 timer_next = tsf + timer_period;
3454
3455 /*
3456 * Program generic timer registers
3457 */
3458 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
3459 timer_next);
3460 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
3461 timer_period);
3462 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
3463 gen_tmr_configuration[timer->index].mode_mask);
3464
3465 /* Enable both trigger and thresh interrupt masks */
3466 REG_SET_BIT(ah, AR_IMR_S5,
3467 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
3468 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303469}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003470EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303471
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07003472void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303473{
3474 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3475
3476 if ((timer->index < AR_FIRST_NDP_TIMER) ||
3477 (timer->index >= ATH_MAX_GEN_TIMER)) {
3478 return;
3479 }
3480
3481 /* Clear generic timer enable bits. */
3482 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
3483 gen_tmr_configuration[timer->index].mode_mask);
3484
3485 /* Disable both trigger and thresh interrupt masks */
3486 REG_CLR_BIT(ah, AR_IMR_S5,
3487 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
3488 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
3489
3490 clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303491}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003492EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303493
3494void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
3495{
3496 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3497
3498 /* free the hardware generic timer slot */
3499 timer_table->timers[timer->index] = NULL;
3500 kfree(timer);
3501}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003502EXPORT_SYMBOL(ath_gen_timer_free);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303503
3504/*
3505 * Generic Timer Interrupts handling
3506 */
3507void ath_gen_timer_isr(struct ath_hw *ah)
3508{
3509 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3510 struct ath_gen_timer *timer;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003511 struct ath_common *common = ath9k_hw_common(ah);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303512 u32 trigger_mask, thresh_mask, index;
3513
3514 /* get hardware generic timer interrupt status */
3515 trigger_mask = ah->intr_gen_timer_trigger;
3516 thresh_mask = ah->intr_gen_timer_thresh;
3517 trigger_mask &= timer_table->timer_mask.val;
3518 thresh_mask &= timer_table->timer_mask.val;
3519
3520 trigger_mask &= ~thresh_mask;
3521
3522 while (thresh_mask) {
3523 index = rightmost_index(timer_table, &thresh_mask);
3524 timer = timer_table->timers[index];
3525 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003526 ath_print(common, ATH_DBG_HWTIMER,
3527 "TSF overflow for Gen timer %d\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303528 timer->overflow(timer->arg);
3529 }
3530
3531 while (trigger_mask) {
3532 index = rightmost_index(timer_table, &trigger_mask);
3533 timer = timer_table->timers[index];
3534 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003535 ath_print(common, ATH_DBG_HWTIMER,
3536 "Gen timer[%d] trigger\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303537 timer->trigger(timer->arg);
3538 }
3539}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003540EXPORT_SYMBOL(ath_gen_timer_isr);
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003541
Sujith05020d22010-03-17 14:25:23 +05303542/********/
3543/* HTC */
3544/********/
3545
3546void ath9k_hw_htc_resetinit(struct ath_hw *ah)
3547{
3548 ah->htc_reset_init = true;
3549}
3550EXPORT_SYMBOL(ath9k_hw_htc_resetinit);
3551
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003552static struct {
3553 u32 version;
3554 const char * name;
3555} ath_mac_bb_names[] = {
3556 /* Devices with external radios */
3557 { AR_SREV_VERSION_5416_PCI, "5416" },
3558 { AR_SREV_VERSION_5416_PCIE, "5418" },
3559 { AR_SREV_VERSION_9100, "9100" },
3560 { AR_SREV_VERSION_9160, "9160" },
3561 /* Single-chip solutions */
3562 { AR_SREV_VERSION_9280, "9280" },
3563 { AR_SREV_VERSION_9285, "9285" },
Luis R. Rodriguez11158472009-10-27 12:59:35 -04003564 { AR_SREV_VERSION_9287, "9287" },
3565 { AR_SREV_VERSION_9271, "9271" },
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003566};
3567
3568/* For devices with external radios */
3569static struct {
3570 u16 version;
3571 const char * name;
3572} ath_rf_names[] = {
3573 { 0, "5133" },
3574 { AR_RAD5133_SREV_MAJOR, "5133" },
3575 { AR_RAD5122_SREV_MAJOR, "5122" },
3576 { AR_RAD2133_SREV_MAJOR, "2133" },
3577 { AR_RAD2122_SREV_MAJOR, "2122" }
3578};
3579
3580/*
3581 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
3582 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003583static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003584{
3585 int i;
3586
3587 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
3588 if (ath_mac_bb_names[i].version == mac_bb_version) {
3589 return ath_mac_bb_names[i].name;
3590 }
3591 }
3592
3593 return "????";
3594}
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003595
3596/*
3597 * Return the RF name. "????" is returned if the RF is unknown.
3598 * Used for devices with external radios.
3599 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003600static const char *ath9k_hw_rf_name(u16 rf_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003601{
3602 int i;
3603
3604 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
3605 if (ath_rf_names[i].version == rf_version) {
3606 return ath_rf_names[i].name;
3607 }
3608 }
3609
3610 return "????";
3611}
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003612
3613void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
3614{
3615 int used;
3616
3617 /* chipsets >= AR9280 are single-chip */
3618 if (AR_SREV_9280_10_OR_LATER(ah)) {
3619 used = snprintf(hw_name, len,
3620 "Atheros AR%s Rev:%x",
3621 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3622 ah->hw_version.macRev);
3623 }
3624 else {
3625 used = snprintf(hw_name, len,
3626 "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
3627 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3628 ah->hw_version.macRev,
3629 ath9k_hw_rf_name((ah->hw_version.analog5GhzRev &
3630 AR_RADIO_SREV_MAJOR)),
3631 ah->hw_version.phyRev);
3632 }
3633
3634 hw_name[used] = '\0';
3635}
3636EXPORT_SYMBOL(ath9k_hw_name);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04003637
3638/* Sets up the AR5008/AR9001/AR9002 hardware familiy callbacks */
3639static void ar9002_hw_attach_ops(struct ath_hw *ah)
3640{
3641 struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
3642 struct ath_hw_ops *ops = ath9k_hw_ops(ah);
3643
3644 priv_ops->init_cal_settings = ar9002_hw_init_cal_settings;
3645 priv_ops->init_mode_regs = ar9002_hw_init_mode_regs;
3646 priv_ops->macversion_supported = ar9002_hw_macversion_supported;
3647
3648 ops->config_pci_powersave = ar9002_hw_configpcipowersave;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04003649
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04003650 ar5008_hw_attach_phy_ops(ah);
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04003651 if (AR_SREV_9280_10_OR_LATER(ah))
3652 ar9002_hw_attach_phy_ops(ah);
Vasanthakumar Thiagarajanae3bb6d2010-04-15 17:38:27 -04003653
3654 ar9002_hw_attach_mac_ops(ah);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04003655}
3656
3657/* Sets up the AR9003 hardware familiy callbacks */
3658static void ar9003_hw_attach_ops(struct ath_hw *ah)
3659{
Luis R. Rodriguez61accab2010-04-15 17:38:21 -04003660 struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
3661
Luis R. Rodriguez13ce3e92010-04-15 17:38:37 -04003662 priv_ops->init_mode_regs = ar9003_hw_init_mode_regs;
Luis R. Rodriguez61accab2010-04-15 17:38:21 -04003663 priv_ops->macversion_supported = ar9003_hw_macversion_supported;
3664
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04003665 ar9003_hw_attach_phy_ops(ah);
Vasanthakumar Thiagarajanae3bb6d2010-04-15 17:38:27 -04003666
3667 ar9003_hw_attach_mac_ops(ah);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04003668}