blob: 56cae95002930d1fe6b3ae10da205e240fc2f5a0 [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. Rodriguezf078f202008-08-04 00:16:41 -070023#include "initvals.h"
24
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080025#define ATH9K_CLOCK_RATE_CCK 22
26#define ATH9K_CLOCK_RATE_5GHZ_OFDM 40
27#define ATH9K_CLOCK_RATE_2GHZ_OFDM 44
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070028
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -040029static void ar9002_hw_attach_ops(struct ath_hw *ah);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -040030static void ar9003_hw_attach_ops(struct ath_hw *ah);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -040031
Sujithcbe61d82009-02-09 13:27:12 +053032static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070033
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040034MODULE_AUTHOR("Atheros Communications");
35MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
36MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
37MODULE_LICENSE("Dual BSD/GPL");
38
39static int __init ath9k_init(void)
40{
41 return 0;
42}
43module_init(ath9k_init);
44
45static void __exit ath9k_exit(void)
46{
47 return;
48}
49module_exit(ath9k_exit);
50
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -040051/* Private hardware callbacks */
52
53static void ath9k_hw_init_cal_settings(struct ath_hw *ah)
54{
55 ath9k_hw_private_ops(ah)->init_cal_settings(ah);
56}
57
58static void ath9k_hw_init_mode_regs(struct ath_hw *ah)
59{
60 ath9k_hw_private_ops(ah)->init_mode_regs(ah);
61}
62
63static bool ath9k_hw_macversion_supported(struct ath_hw *ah)
64{
65 struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
66
67 return priv_ops->macversion_supported(ah->hw_version.macVersion);
68}
69
Luis R. Rodriguez64773962010-04-15 17:38:17 -040070static u32 ath9k_hw_compute_pll_control(struct ath_hw *ah,
71 struct ath9k_channel *chan)
72{
73 return ath9k_hw_private_ops(ah)->compute_pll_control(ah, chan);
74}
75
Sujithf1dc5602008-10-29 10:16:30 +053076/********************/
77/* Helper Functions */
78/********************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070079
Sujithcbe61d82009-02-09 13:27:12 +053080static u32 ath9k_hw_mac_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053081{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070082 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053083
Sujith2660b812009-02-09 13:27:26 +053084 if (!ah->curchan) /* should really check for CCK instead */
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080085 return usecs *ATH9K_CLOCK_RATE_CCK;
86 if (conf->channel->band == IEEE80211_BAND_2GHZ)
87 return usecs *ATH9K_CLOCK_RATE_2GHZ_OFDM;
88 return usecs *ATH9K_CLOCK_RATE_5GHZ_OFDM;
Sujithf1dc5602008-10-29 10:16:30 +053089}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070090
Sujithcbe61d82009-02-09 13:27:12 +053091static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053092{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070093 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053094
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080095 if (conf_is_ht40(conf))
Sujithf1dc5602008-10-29 10:16:30 +053096 return ath9k_hw_mac_clks(ah, usecs) * 2;
97 else
98 return ath9k_hw_mac_clks(ah, usecs);
99}
100
Sujith0caa7b12009-02-16 13:23:20 +0530101bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700102{
103 int i;
104
Sujith0caa7b12009-02-16 13:23:20 +0530105 BUG_ON(timeout < AH_TIME_QUANTUM);
106
107 for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700108 if ((REG_READ(ah, reg) & mask) == val)
109 return true;
110
111 udelay(AH_TIME_QUANTUM);
112 }
Sujith04bd4632008-11-28 22:18:05 +0530113
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700114 ath_print(ath9k_hw_common(ah), ATH_DBG_ANY,
115 "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
116 timeout, reg, REG_READ(ah, reg), mask, val);
Sujithf1dc5602008-10-29 10:16:30 +0530117
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700118 return false;
119}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400120EXPORT_SYMBOL(ath9k_hw_wait);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700121
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700122u32 ath9k_hw_reverse_bits(u32 val, u32 n)
123{
124 u32 retval;
125 int i;
126
127 for (i = 0, retval = 0; i < n; i++) {
128 retval = (retval << 1) | (val & 1);
129 val >>= 1;
130 }
131 return retval;
132}
133
Sujithcbe61d82009-02-09 13:27:12 +0530134bool ath9k_get_channel_edges(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530135 u16 flags, u16 *low,
136 u16 *high)
137{
Sujith2660b812009-02-09 13:27:26 +0530138 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530139
140 if (flags & CHANNEL_5GHZ) {
141 *low = pCap->low_5ghz_chan;
142 *high = pCap->high_5ghz_chan;
143 return true;
144 }
145 if ((flags & CHANNEL_2GHZ)) {
146 *low = pCap->low_2ghz_chan;
147 *high = pCap->high_2ghz_chan;
148 return true;
149 }
150 return false;
151}
152
Sujithcbe61d82009-02-09 13:27:12 +0530153u16 ath9k_hw_computetxtime(struct ath_hw *ah,
Felix Fietkau545750d2009-11-23 22:21:01 +0100154 u8 phy, int kbps,
Sujithf1dc5602008-10-29 10:16:30 +0530155 u32 frameLen, u16 rateix,
156 bool shortPreamble)
157{
158 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
Sujithf1dc5602008-10-29 10:16:30 +0530159
160 if (kbps == 0)
161 return 0;
162
Felix Fietkau545750d2009-11-23 22:21:01 +0100163 switch (phy) {
Sujith46d14a52008-11-18 09:08:13 +0530164 case WLAN_RC_PHY_CCK:
Sujithf1dc5602008-10-29 10:16:30 +0530165 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
Felix Fietkau545750d2009-11-23 22:21:01 +0100166 if (shortPreamble)
Sujithf1dc5602008-10-29 10:16:30 +0530167 phyTime >>= 1;
168 numBits = frameLen << 3;
169 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
170 break;
Sujith46d14a52008-11-18 09:08:13 +0530171 case WLAN_RC_PHY_OFDM:
Sujith2660b812009-02-09 13:27:26 +0530172 if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530173 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
174 numBits = OFDM_PLCP_BITS + (frameLen << 3);
175 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
176 txTime = OFDM_SIFS_TIME_QUARTER
177 + OFDM_PREAMBLE_TIME_QUARTER
178 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
Sujith2660b812009-02-09 13:27:26 +0530179 } else if (ah->curchan &&
180 IS_CHAN_HALF_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530181 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
182 numBits = OFDM_PLCP_BITS + (frameLen << 3);
183 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
184 txTime = OFDM_SIFS_TIME_HALF +
185 OFDM_PREAMBLE_TIME_HALF
186 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
187 } else {
188 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
189 numBits = OFDM_PLCP_BITS + (frameLen << 3);
190 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
191 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
192 + (numSymbols * OFDM_SYMBOL_TIME);
193 }
194 break;
195 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700196 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
Felix Fietkau545750d2009-11-23 22:21:01 +0100197 "Unknown phy %u (rate ix %u)\n", phy, rateix);
Sujithf1dc5602008-10-29 10:16:30 +0530198 txTime = 0;
199 break;
200 }
201
202 return txTime;
203}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400204EXPORT_SYMBOL(ath9k_hw_computetxtime);
Sujithf1dc5602008-10-29 10:16:30 +0530205
Sujithcbe61d82009-02-09 13:27:12 +0530206void ath9k_hw_get_channel_centers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530207 struct ath9k_channel *chan,
208 struct chan_centers *centers)
209{
210 int8_t extoff;
Sujithf1dc5602008-10-29 10:16:30 +0530211
212 if (!IS_CHAN_HT40(chan)) {
213 centers->ctl_center = centers->ext_center =
214 centers->synth_center = chan->channel;
215 return;
216 }
217
218 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
219 (chan->chanmode == CHANNEL_G_HT40PLUS)) {
220 centers->synth_center =
221 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
222 extoff = 1;
223 } else {
224 centers->synth_center =
225 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
226 extoff = -1;
227 }
228
229 centers->ctl_center =
230 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700231 /* 25 MHz spacing is supported by hw but not on upper layers */
Sujithf1dc5602008-10-29 10:16:30 +0530232 centers->ext_center =
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700233 centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT);
Sujithf1dc5602008-10-29 10:16:30 +0530234}
235
236/******************/
237/* Chip Revisions */
238/******************/
239
Sujithcbe61d82009-02-09 13:27:12 +0530240static void ath9k_hw_read_revisions(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530241{
242 u32 val;
243
244 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
245
246 if (val == 0xFF) {
247 val = REG_READ(ah, AR_SREV);
Sujithd535a422009-02-09 13:27:06 +0530248 ah->hw_version.macVersion =
249 (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
250 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
Sujith2660b812009-02-09 13:27:26 +0530251 ah->is_pciexpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
Sujithf1dc5602008-10-29 10:16:30 +0530252 } else {
253 if (!AR_SREV_9100(ah))
Sujithd535a422009-02-09 13:27:06 +0530254 ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
Sujithf1dc5602008-10-29 10:16:30 +0530255
Sujithd535a422009-02-09 13:27:06 +0530256 ah->hw_version.macRev = val & AR_SREV_REVISION;
Sujithf1dc5602008-10-29 10:16:30 +0530257
Sujithd535a422009-02-09 13:27:06 +0530258 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
Sujith2660b812009-02-09 13:27:26 +0530259 ah->is_pciexpress = true;
Sujithf1dc5602008-10-29 10:16:30 +0530260 }
261}
262
Sujithcbe61d82009-02-09 13:27:12 +0530263static int ath9k_hw_get_radiorev(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530264{
265 u32 val;
266 int i;
267
268 REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
269
270 for (i = 0; i < 8; i++)
271 REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
272 val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
273 val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
274
275 return ath9k_hw_reverse_bits(val, 8);
276}
277
278/************************************/
279/* HW Attach, Detach, Init Routines */
280/************************************/
281
Sujithcbe61d82009-02-09 13:27:12 +0530282static void ath9k_hw_disablepcie(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530283{
Sujithfeed0292009-01-29 11:37:35 +0530284 if (AR_SREV_9100(ah))
Sujithf1dc5602008-10-29 10:16:30 +0530285 return;
286
287 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
288 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
289 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
290 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
291 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
292 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
293 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
294 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
295 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
296
297 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
298}
299
Sujithcbe61d82009-02-09 13:27:12 +0530300static bool ath9k_hw_chip_test(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530301{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700302 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530303 u32 regAddr[2] = { AR_STA_ID0, AR_PHY_BASE + (8 << 2) };
304 u32 regHold[2];
305 u32 patternData[4] = { 0x55555555,
306 0xaaaaaaaa,
307 0x66666666,
308 0x99999999 };
309 int i, j;
310
311 for (i = 0; i < 2; i++) {
312 u32 addr = regAddr[i];
313 u32 wrData, rdData;
314
315 regHold[i] = REG_READ(ah, addr);
316 for (j = 0; j < 0x100; j++) {
317 wrData = (j << 16) | j;
318 REG_WRITE(ah, addr, wrData);
319 rdData = REG_READ(ah, addr);
320 if (rdData != wrData) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700321 ath_print(common, ATH_DBG_FATAL,
322 "address test failed "
323 "addr: 0x%08x - wr:0x%08x != "
324 "rd:0x%08x\n",
325 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530326 return false;
327 }
328 }
329 for (j = 0; j < 4; j++) {
330 wrData = patternData[j];
331 REG_WRITE(ah, addr, wrData);
332 rdData = REG_READ(ah, addr);
333 if (wrData != rdData) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700334 ath_print(common, ATH_DBG_FATAL,
335 "address test failed "
336 "addr: 0x%08x - wr:0x%08x != "
337 "rd:0x%08x\n",
338 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530339 return false;
340 }
341 }
342 REG_WRITE(ah, regAddr[i], regHold[i]);
343 }
344 udelay(100);
Sujithcbe61d82009-02-09 13:27:12 +0530345
Sujithf1dc5602008-10-29 10:16:30 +0530346 return true;
347}
348
Luis R. Rodriguezb8b0f372009-08-03 12:24:43 -0700349static void ath9k_hw_init_config(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700350{
351 int i;
352
Sujith2660b812009-02-09 13:27:26 +0530353 ah->config.dma_beacon_response_time = 2;
354 ah->config.sw_beacon_response_time = 10;
355 ah->config.additional_swba_backoff = 0;
356 ah->config.ack_6mb = 0x0;
357 ah->config.cwm_ignore_extcca = 0;
358 ah->config.pcie_powersave_enable = 0;
Sujith2660b812009-02-09 13:27:26 +0530359 ah->config.pcie_clock_req = 0;
Sujith2660b812009-02-09 13:27:26 +0530360 ah->config.pcie_waen = 0;
361 ah->config.analog_shiftreg = 1;
Sujith2660b812009-02-09 13:27:26 +0530362 ah->config.ofdm_trig_low = 200;
363 ah->config.ofdm_trig_high = 500;
364 ah->config.cck_trig_high = 200;
365 ah->config.cck_trig_low = 100;
366 ah->config.enable_ani = 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700367
368 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujith2660b812009-02-09 13:27:26 +0530369 ah->config.spurchans[i][0] = AR_NO_SPUR;
370 ah->config.spurchans[i][1] = AR_NO_SPUR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700371 }
372
Luis R. Rodriguez5ffaf8a2010-02-02 11:58:33 -0500373 if (ah->hw_version.devid != AR2427_DEVID_PCIE)
374 ah->config.ht_enable = 1;
375 else
376 ah->config.ht_enable = 0;
377
Sujith0ce024c2009-12-14 14:57:00 +0530378 ah->config.rx_intr_mitigation = true;
Luis R. Rodriguez61584252009-03-12 18:18:49 -0400379
380 /*
381 * We need this for PCI devices only (Cardbus, PCI, miniPCI)
382 * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
383 * This means we use it for all AR5416 devices, and the few
384 * minor PCI AR9280 devices out there.
385 *
386 * Serialization is required because these devices do not handle
387 * well the case of two concurrent reads/writes due to the latency
388 * involved. During one read/write another read/write can be issued
389 * on another CPU while the previous read/write may still be working
390 * on our hardware, if we hit this case the hardware poops in a loop.
391 * We prevent this by serializing reads and writes.
392 *
393 * This issue is not present on PCI-Express devices or pre-AR5416
394 * devices (legacy, 802.11abg).
395 */
396 if (num_possible_cpus() > 1)
David S. Miller2d6a5e92009-03-17 15:01:30 -0700397 ah->config.serialize_regmode = SER_REG_MODE_AUTO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700398}
399
Luis R. Rodriguez50aca252009-08-03 12:24:42 -0700400static void ath9k_hw_init_defaults(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700401{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700402 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
403
404 regulatory->country_code = CTRY_DEFAULT;
405 regulatory->power_limit = MAX_RATE_POWER;
406 regulatory->tp_scale = ATH9K_TP_SCALE_MAX;
407
Sujithd535a422009-02-09 13:27:06 +0530408 ah->hw_version.magic = AR5416_MAGIC;
Sujithd535a422009-02-09 13:27:06 +0530409 ah->hw_version.subvendorid = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700410
411 ah->ah_flags = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700412 if (!AR_SREV_9100(ah))
413 ah->ah_flags = AH_USE_EEPROM;
414
Sujith2660b812009-02-09 13:27:26 +0530415 ah->atim_window = 0;
Sujith2660b812009-02-09 13:27:26 +0530416 ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
417 ah->beacon_interval = 100;
418 ah->enable_32kHz_clock = DONT_USE_32KHZ;
419 ah->slottime = (u32) -1;
Sujith2660b812009-02-09 13:27:26 +0530420 ah->globaltxtimeout = (u32) -1;
Gabor Juhoscbdec972009-07-24 17:27:22 +0200421 ah->power_mode = ATH9K_PM_UNDEFINED;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700422}
423
Sujithcbe61d82009-02-09 13:27:12 +0530424static int ath9k_hw_rf_claim(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700425{
426 u32 val;
427
428 REG_WRITE(ah, AR_PHY(0), 0x00000007);
429
430 val = ath9k_hw_get_radiorev(ah);
431 switch (val & AR_RADIO_SREV_MAJOR) {
432 case 0:
433 val = AR_RAD5133_SREV_MAJOR;
434 break;
435 case AR_RAD5133_SREV_MAJOR:
436 case AR_RAD5122_SREV_MAJOR:
437 case AR_RAD2133_SREV_MAJOR:
438 case AR_RAD2122_SREV_MAJOR:
439 break;
440 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700441 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
442 "Radio Chip Rev 0x%02X not supported\n",
443 val & AR_RADIO_SREV_MAJOR);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700444 return -EOPNOTSUPP;
445 }
446
Sujithd535a422009-02-09 13:27:06 +0530447 ah->hw_version.analog5GhzRev = val;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700448
449 return 0;
450}
451
Sujithcbe61d82009-02-09 13:27:12 +0530452static int ath9k_hw_init_macaddr(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700453{
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700454 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530455 u32 sum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700456 int i;
Sujithf1dc5602008-10-29 10:16:30 +0530457 u16 eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700458
Sujithf1dc5602008-10-29 10:16:30 +0530459 sum = 0;
460 for (i = 0; i < 3; i++) {
Sujithf74df6f2009-02-09 13:27:24 +0530461 eeval = ah->eep_ops->get_eeprom(ah, AR_EEPROM_MAC(i));
Sujithf1dc5602008-10-29 10:16:30 +0530462 sum += eeval;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700463 common->macaddr[2 * i] = eeval >> 8;
464 common->macaddr[2 * i + 1] = eeval & 0xff;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700465 }
Sujithd8baa932009-03-30 15:28:25 +0530466 if (sum == 0 || sum == 0xffff * 3)
Sujithf1dc5602008-10-29 10:16:30 +0530467 return -EADDRNOTAVAIL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700468
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700469 return 0;
470}
471
Sujithcbe61d82009-02-09 13:27:12 +0530472static void ath9k_hw_init_rxgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530473{
474 u32 rxgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530475
Sujithf74df6f2009-02-09 13:27:24 +0530476 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_17) {
477 rxgain_type = ah->eep_ops->get_eeprom(ah, EEP_RXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530478
479 if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530480 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530481 ar9280Modes_backoff_13db_rxgain_9280_2,
482 ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2), 6);
483 else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530484 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530485 ar9280Modes_backoff_23db_rxgain_9280_2,
486 ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 6);
487 else
Sujith2660b812009-02-09 13:27:26 +0530488 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530489 ar9280Modes_original_rxgain_9280_2,
490 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530491 } else {
Sujith2660b812009-02-09 13:27:26 +0530492 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530493 ar9280Modes_original_rxgain_9280_2,
494 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530495 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530496}
497
Sujithcbe61d82009-02-09 13:27:12 +0530498static void ath9k_hw_init_txgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530499{
500 u32 txgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530501
Sujithf74df6f2009-02-09 13:27:24 +0530502 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_19) {
503 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530504
505 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
Sujith2660b812009-02-09 13:27:26 +0530506 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530507 ar9280Modes_high_power_tx_gain_9280_2,
508 ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 6);
509 else
Sujith2660b812009-02-09 13:27:26 +0530510 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530511 ar9280Modes_original_tx_gain_9280_2,
512 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530513 } else {
Sujith2660b812009-02-09 13:27:26 +0530514 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530515 ar9280Modes_original_tx_gain_9280_2,
516 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530517 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530518}
519
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700520static int ath9k_hw_post_init(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700521{
522 int ecode;
523
Sujith527d4852010-03-17 14:25:16 +0530524 if (!AR_SREV_9271(ah)) {
525 if (!ath9k_hw_chip_test(ah))
526 return -ENODEV;
527 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700528
529 ecode = ath9k_hw_rf_claim(ah);
530 if (ecode != 0)
531 return ecode;
532
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700533 ecode = ath9k_hw_eeprom_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700534 if (ecode != 0)
535 return ecode;
Sujith7d01b222009-03-13 08:55:55 +0530536
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700537 ath_print(ath9k_hw_common(ah), ATH_DBG_CONFIG,
538 "Eeprom VER: %d, REV: %d\n",
539 ah->eep_ops->get_eeprom_ver(ah),
540 ah->eep_ops->get_eeprom_rev(ah));
Sujith7d01b222009-03-13 08:55:55 +0530541
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400542 ecode = ath9k_hw_rf_alloc_ext_banks(ah);
543 if (ecode) {
544 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
545 "Failed allocating banks for "
546 "external radio\n");
547 return ecode;
Luis R. Rodriguez574d6b12009-10-19 02:33:37 -0400548 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700549
550 if (!AR_SREV_9100(ah)) {
551 ath9k_hw_ani_setup(ah);
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700552 ath9k_hw_ani_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700553 }
Sujithf1dc5602008-10-29 10:16:30 +0530554
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700555 return 0;
556}
557
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400558static bool ar9002_hw_macversion_supported(u32 macversion)
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700559{
560 switch (macversion) {
561 case AR_SREV_VERSION_5416_PCI:
562 case AR_SREV_VERSION_5416_PCIE:
563 case AR_SREV_VERSION_9160:
564 case AR_SREV_VERSION_9100:
565 case AR_SREV_VERSION_9280:
566 case AR_SREV_VERSION_9285:
567 case AR_SREV_VERSION_9287:
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400568 case AR_SREV_VERSION_9271:
Luis R. Rodriguez7976b422009-09-23 23:07:02 -0400569 return true;
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700570 default:
571 break;
572 }
573 return false;
574}
575
Luis R. Rodriguez61accab2010-04-15 17:38:21 -0400576static bool ar9003_hw_macversion_supported(u32 macversion)
577{
578 switch (macversion) {
579 case AR_SREV_VERSION_9300:
580 return true;
581 default:
582 break;
583 }
584 return false;
585}
586
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400587static void ar9002_hw_init_cal_settings(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700588{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700589 if (AR_SREV_9160_10_OR_LATER(ah)) {
590 if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530591 ah->iq_caldata.calData = &iq_cal_single_sample;
592 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700593 &adc_gain_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530594 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700595 &adc_dc_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530596 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700597 &adc_init_dc_cal;
598 } else {
Sujith2660b812009-02-09 13:27:26 +0530599 ah->iq_caldata.calData = &iq_cal_multi_sample;
600 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700601 &adc_gain_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530602 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700603 &adc_dc_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530604 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700605 &adc_init_dc_cal;
606 }
Sujith2660b812009-02-09 13:27:26 +0530607 ah->supp_cals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700608 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700609}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700610
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400611static void ar9002_hw_init_mode_regs(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700612{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400613 if (AR_SREV_9271(ah)) {
Luis R. Rodriguez85643282009-10-19 02:33:33 -0400614 INIT_INI_ARRAY(&ah->iniModes, ar9271Modes_9271,
615 ARRAY_SIZE(ar9271Modes_9271), 6);
616 INIT_INI_ARRAY(&ah->iniCommon, ar9271Common_9271,
617 ARRAY_SIZE(ar9271Common_9271), 2);
Sujith70807e92010-03-17 14:25:14 +0530618 INIT_INI_ARRAY(&ah->iniCommon_normal_cck_fir_coeff_9271,
619 ar9271Common_normal_cck_fir_coeff_9271,
620 ARRAY_SIZE(ar9271Common_normal_cck_fir_coeff_9271), 2);
621 INIT_INI_ARRAY(&ah->iniCommon_japan_2484_cck_fir_coeff_9271,
622 ar9271Common_japan_2484_cck_fir_coeff_9271,
623 ARRAY_SIZE(ar9271Common_japan_2484_cck_fir_coeff_9271), 2);
Luis R. Rodriguez85643282009-10-19 02:33:33 -0400624 INIT_INI_ARRAY(&ah->iniModes_9271_1_0_only,
625 ar9271Modes_9271_1_0_only,
626 ARRAY_SIZE(ar9271Modes_9271_1_0_only), 6);
Sujith70807e92010-03-17 14:25:14 +0530627 INIT_INI_ARRAY(&ah->iniModes_9271_ANI_reg, ar9271Modes_9271_ANI_reg,
628 ARRAY_SIZE(ar9271Modes_9271_ANI_reg), 6);
629 INIT_INI_ARRAY(&ah->iniModes_high_power_tx_gain_9271,
630 ar9271Modes_high_power_tx_gain_9271,
631 ARRAY_SIZE(ar9271Modes_high_power_tx_gain_9271), 6);
632 INIT_INI_ARRAY(&ah->iniModes_normal_power_tx_gain_9271,
633 ar9271Modes_normal_power_tx_gain_9271,
634 ARRAY_SIZE(ar9271Modes_normal_power_tx_gain_9271), 6);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400635 return;
636 }
637
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530638 if (AR_SREV_9287_11_OR_LATER(ah)) {
639 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_1,
640 ARRAY_SIZE(ar9287Modes_9287_1_1), 6);
641 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_1,
642 ARRAY_SIZE(ar9287Common_9287_1_1), 2);
643 if (ah->config.pcie_clock_req)
644 INIT_INI_ARRAY(&ah->iniPcieSerdes,
645 ar9287PciePhy_clkreq_off_L1_9287_1_1,
646 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_1), 2);
647 else
648 INIT_INI_ARRAY(&ah->iniPcieSerdes,
649 ar9287PciePhy_clkreq_always_on_L1_9287_1_1,
650 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_1),
651 2);
652 } else if (AR_SREV_9287_10_OR_LATER(ah)) {
653 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_0,
654 ARRAY_SIZE(ar9287Modes_9287_1_0), 6);
655 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_0,
656 ARRAY_SIZE(ar9287Common_9287_1_0), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700657
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530658 if (ah->config.pcie_clock_req)
659 INIT_INI_ARRAY(&ah->iniPcieSerdes,
660 ar9287PciePhy_clkreq_off_L1_9287_1_0,
661 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_0), 2);
662 else
663 INIT_INI_ARRAY(&ah->iniPcieSerdes,
664 ar9287PciePhy_clkreq_always_on_L1_9287_1_0,
665 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_0),
666 2);
667 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
668
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530669
Sujith2660b812009-02-09 13:27:26 +0530670 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530671 ARRAY_SIZE(ar9285Modes_9285_1_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530672 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530673 ARRAY_SIZE(ar9285Common_9285_1_2), 2);
674
Sujith2660b812009-02-09 13:27:26 +0530675 if (ah->config.pcie_clock_req) {
676 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530677 ar9285PciePhy_clkreq_off_L1_9285_1_2,
678 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2);
679 } else {
Sujith2660b812009-02-09 13:27:26 +0530680 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530681 ar9285PciePhy_clkreq_always_on_L1_9285_1_2,
682 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2),
683 2);
684 }
685 } else if (AR_SREV_9285_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530686 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530687 ARRAY_SIZE(ar9285Modes_9285), 6);
Sujith2660b812009-02-09 13:27:26 +0530688 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530689 ARRAY_SIZE(ar9285Common_9285), 2);
690
Sujith2660b812009-02-09 13:27:26 +0530691 if (ah->config.pcie_clock_req) {
692 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530693 ar9285PciePhy_clkreq_off_L1_9285,
694 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2);
695 } else {
Sujith2660b812009-02-09 13:27:26 +0530696 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530697 ar9285PciePhy_clkreq_always_on_L1_9285,
698 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285), 2);
699 }
700 } else if (AR_SREV_9280_20_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530701 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700702 ARRAY_SIZE(ar9280Modes_9280_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530703 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700704 ARRAY_SIZE(ar9280Common_9280_2), 2);
705
Sujith2660b812009-02-09 13:27:26 +0530706 if (ah->config.pcie_clock_req) {
707 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530708 ar9280PciePhy_clkreq_off_L1_9280,
709 ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700710 } else {
Sujith2660b812009-02-09 13:27:26 +0530711 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530712 ar9280PciePhy_clkreq_always_on_L1_9280,
713 ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700714 }
Sujith2660b812009-02-09 13:27:26 +0530715 INIT_INI_ARRAY(&ah->iniModesAdditional,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700716 ar9280Modes_fast_clock_9280_2,
Sujithf1dc5602008-10-29 10:16:30 +0530717 ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700718 } else if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530719 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700720 ARRAY_SIZE(ar9280Modes_9280), 6);
Sujith2660b812009-02-09 13:27:26 +0530721 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700722 ARRAY_SIZE(ar9280Common_9280), 2);
723 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530724 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700725 ARRAY_SIZE(ar5416Modes_9160), 6);
Sujith2660b812009-02-09 13:27:26 +0530726 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700727 ARRAY_SIZE(ar5416Common_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530728 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700729 ARRAY_SIZE(ar5416Bank0_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530730 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700731 ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530732 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700733 ARRAY_SIZE(ar5416Bank1_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530734 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700735 ARRAY_SIZE(ar5416Bank2_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530736 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700737 ARRAY_SIZE(ar5416Bank3_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530738 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700739 ARRAY_SIZE(ar5416Bank6_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530740 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700741 ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530742 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700743 ARRAY_SIZE(ar5416Bank7_9160), 2);
744 if (AR_SREV_9160_11(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530745 INIT_INI_ARRAY(&ah->iniAddac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700746 ar5416Addac_91601_1,
747 ARRAY_SIZE(ar5416Addac_91601_1), 2);
748 } else {
Sujith2660b812009-02-09 13:27:26 +0530749 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700750 ARRAY_SIZE(ar5416Addac_9160), 2);
751 }
752 } else if (AR_SREV_9100_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530753 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700754 ARRAY_SIZE(ar5416Modes_9100), 6);
Sujith2660b812009-02-09 13:27:26 +0530755 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700756 ARRAY_SIZE(ar5416Common_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530757 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700758 ARRAY_SIZE(ar5416Bank0_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530759 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700760 ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530761 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700762 ARRAY_SIZE(ar5416Bank1_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530763 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700764 ARRAY_SIZE(ar5416Bank2_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530765 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700766 ARRAY_SIZE(ar5416Bank3_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530767 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700768 ARRAY_SIZE(ar5416Bank6_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530769 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700770 ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530771 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700772 ARRAY_SIZE(ar5416Bank7_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530773 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700774 ARRAY_SIZE(ar5416Addac_9100), 2);
775 } else {
Sujith2660b812009-02-09 13:27:26 +0530776 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700777 ARRAY_SIZE(ar5416Modes), 6);
Sujith2660b812009-02-09 13:27:26 +0530778 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700779 ARRAY_SIZE(ar5416Common), 2);
Sujith2660b812009-02-09 13:27:26 +0530780 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700781 ARRAY_SIZE(ar5416Bank0), 2);
Sujith2660b812009-02-09 13:27:26 +0530782 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700783 ARRAY_SIZE(ar5416BB_RfGain), 3);
Sujith2660b812009-02-09 13:27:26 +0530784 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700785 ARRAY_SIZE(ar5416Bank1), 2);
Sujith2660b812009-02-09 13:27:26 +0530786 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700787 ARRAY_SIZE(ar5416Bank2), 2);
Sujith2660b812009-02-09 13:27:26 +0530788 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700789 ARRAY_SIZE(ar5416Bank3), 3);
Sujith2660b812009-02-09 13:27:26 +0530790 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700791 ARRAY_SIZE(ar5416Bank6), 3);
Sujith2660b812009-02-09 13:27:26 +0530792 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700793 ARRAY_SIZE(ar5416Bank6TPC), 3);
Sujith2660b812009-02-09 13:27:26 +0530794 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700795 ARRAY_SIZE(ar5416Bank7), 2);
Sujith2660b812009-02-09 13:27:26 +0530796 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700797 ARRAY_SIZE(ar5416Addac), 2);
798 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700799}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700800
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700801static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
802{
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530803 if (AR_SREV_9287_11_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530804 INIT_INI_ARRAY(&ah->iniModesRxGain,
805 ar9287Modes_rx_gain_9287_1_1,
806 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_1), 6);
807 else if (AR_SREV_9287_10(ah))
808 INIT_INI_ARRAY(&ah->iniModesRxGain,
809 ar9287Modes_rx_gain_9287_1_0,
810 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_0), 6);
811 else if (AR_SREV_9280_20(ah))
812 ath9k_hw_init_rxgain_ini(ah);
813
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530814 if (AR_SREV_9287_11_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530815 INIT_INI_ARRAY(&ah->iniModesTxGain,
816 ar9287Modes_tx_gain_9287_1_1,
817 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_1), 6);
818 } else if (AR_SREV_9287_10(ah)) {
819 INIT_INI_ARRAY(&ah->iniModesTxGain,
820 ar9287Modes_tx_gain_9287_1_0,
821 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_0), 6);
822 } else if (AR_SREV_9280_20(ah)) {
823 ath9k_hw_init_txgain_ini(ah);
824 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530825 u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
826
827 /* txgain table */
828 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) {
Vivek Natarajan53bc7aa2010-04-05 14:48:04 +0530829 if (AR_SREV_9285E_20(ah)) {
830 INIT_INI_ARRAY(&ah->iniModesTxGain,
831 ar9285Modes_XE2_0_high_power,
832 ARRAY_SIZE(
833 ar9285Modes_XE2_0_high_power), 6);
834 } else {
835 INIT_INI_ARRAY(&ah->iniModesTxGain,
836 ar9285Modes_high_power_tx_gain_9285_1_2,
837 ARRAY_SIZE(
838 ar9285Modes_high_power_tx_gain_9285_1_2), 6);
839 }
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530840 } else {
Vivek Natarajan53bc7aa2010-04-05 14:48:04 +0530841 if (AR_SREV_9285E_20(ah)) {
842 INIT_INI_ARRAY(&ah->iniModesTxGain,
843 ar9285Modes_XE2_0_normal_power,
844 ARRAY_SIZE(
845 ar9285Modes_XE2_0_normal_power), 6);
846 } else {
847 INIT_INI_ARRAY(&ah->iniModesTxGain,
848 ar9285Modes_original_tx_gain_9285_1_2,
849 ARRAY_SIZE(
850 ar9285Modes_original_tx_gain_9285_1_2), 6);
851 }
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530852 }
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530853 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700854}
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530855
Felix Fietkauaa8bc9e2010-01-23 20:04:18 +0100856static void ath9k_hw_init_eeprom_fix(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700857{
Pavel Roskin2eb46d92010-04-07 01:33:33 -0400858 struct base_eep_header *pBase = &(ah->eeprom.def.baseEepHeader);
859 struct ath_common *common = ath9k_hw_common(ah);
Sujith06d0f062009-02-12 10:06:45 +0530860
Pavel Roskin2eb46d92010-04-07 01:33:33 -0400861 ah->need_an_top2_fixup = (ah->hw_version.devid == AR9280_DEVID_PCI) &&
862 (ah->eep_map != EEP_MAP_4KBITS) &&
863 ((pBase->version & 0xff) > 0x0a) &&
864 (pBase->pwdclkind == 0);
Sujith06d0f062009-02-12 10:06:45 +0530865
Pavel Roskin2eb46d92010-04-07 01:33:33 -0400866 if (ah->need_an_top2_fixup)
867 ath_print(common, ATH_DBG_EEPROM,
868 "needs fixup for AR_AN_TOP2 register\n");
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700869}
870
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400871static void ath9k_hw_attach_ops(struct ath_hw *ah)
872{
873 if (AR_SREV_9300_20_OR_LATER(ah))
874 ar9003_hw_attach_ops(ah);
875 else
876 ar9002_hw_attach_ops(ah);
877}
878
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400879/* Called for all hardware families */
880static int __ath9k_hw_init(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700881{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700882 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700883 int r = 0;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700884
Luis R. Rodriguezbab1f622010-04-15 17:38:20 -0400885 if (ah->hw_version.devid == AR5416_AR9100_DEVID)
886 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700887
888 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700889 ath_print(common, ATH_DBG_FATAL,
890 "Couldn't reset chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700891 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700892 }
893
Luis R. Rodriguezbab1f622010-04-15 17:38:20 -0400894 ath9k_hw_init_defaults(ah);
895 ath9k_hw_init_config(ah);
896
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400897 ath9k_hw_attach_ops(ah);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400898
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700899 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700900 ath_print(common, ATH_DBG_FATAL, "Couldn't wakeup chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700901 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700902 }
903
904 if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
905 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
906 (AR_SREV_9280(ah) && !ah->is_pciexpress)) {
907 ah->config.serialize_regmode =
908 SER_REG_MODE_ON;
909 } else {
910 ah->config.serialize_regmode =
911 SER_REG_MODE_OFF;
912 }
913 }
914
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700915 ath_print(common, ATH_DBG_RESET, "serialize_regmode is %d\n",
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700916 ah->config.serialize_regmode);
917
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -0500918 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
919 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD >> 1;
920 else
921 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD;
922
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400923 if (!ath9k_hw_macversion_supported(ah)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700924 ath_print(common, ATH_DBG_FATAL,
925 "Mac Chip Rev 0x%02x.%x is not supported by "
926 "this driver\n", ah->hw_version.macVersion,
927 ah->hw_version.macRev);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700928 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700929 }
930
931 if (AR_SREV_9100(ah)) {
932 ah->iq_caldata.calData = &iq_cal_multi_sample;
933 ah->supp_cals = IQ_MISMATCH_CAL;
934 ah->is_pciexpress = false;
935 }
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400936
937 if (AR_SREV_9271(ah))
938 ah->is_pciexpress = false;
939
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700940 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700941 ath9k_hw_init_cal_settings(ah);
942
943 ah->ani_function = ATH9K_ANI_ALL;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400944 if (AR_SREV_9280_10_OR_LATER(ah))
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700945 ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
946
947 ath9k_hw_init_mode_regs(ah);
948
949 if (ah->is_pciexpress)
Vivek Natarajan93b1b372009-09-17 09:24:58 +0530950 ath9k_hw_configpcipowersave(ah, 0, 0);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700951 else
952 ath9k_hw_disablepcie(ah);
953
Sujith193cd452009-09-18 15:04:07 +0530954 /* Support for Japan ch.14 (2484) spread */
955 if (AR_SREV_9287_11_OR_LATER(ah)) {
956 INIT_INI_ARRAY(&ah->iniCckfirNormal,
957 ar9287Common_normal_cck_fir_coeff_92871_1,
958 ARRAY_SIZE(ar9287Common_normal_cck_fir_coeff_92871_1), 2);
959 INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
960 ar9287Common_japan_2484_cck_fir_coeff_92871_1,
961 ARRAY_SIZE(ar9287Common_japan_2484_cck_fir_coeff_92871_1), 2);
962 }
963
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700964 r = ath9k_hw_post_init(ah);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700965 if (r)
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700966 return r;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700967
968 ath9k_hw_init_mode_gain_regs(ah);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +0100969 r = ath9k_hw_fill_cap_info(ah);
970 if (r)
971 return r;
972
Felix Fietkauaa8bc9e2010-01-23 20:04:18 +0100973 ath9k_hw_init_eeprom_fix(ah);
Sujithf6688cd2008-12-07 21:43:10 +0530974
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700975 r = ath9k_hw_init_macaddr(ah);
976 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700977 ath_print(common, ATH_DBG_FATAL,
978 "Failed to initialize MAC address\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700979 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700980 }
981
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400982 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
Sujith2660b812009-02-09 13:27:26 +0530983 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700984 else
Sujith2660b812009-02-09 13:27:26 +0530985 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700986
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700987 ath9k_init_nfcal_hist_buffer(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700988
Luis R. Rodriguez211f5852009-10-06 21:19:07 -0400989 common->state = ATH_HW_INITIALIZED;
990
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700991 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700992}
993
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400994int ath9k_hw_init(struct ath_hw *ah)
995{
996 int ret;
997 struct ath_common *common = ath9k_hw_common(ah);
998
999 /* These are all the AR5008/AR9001/AR9002 hardware family of chipsets */
1000 switch (ah->hw_version.devid) {
1001 case AR5416_DEVID_PCI:
1002 case AR5416_DEVID_PCIE:
1003 case AR5416_AR9100_DEVID:
1004 case AR9160_DEVID_PCI:
1005 case AR9280_DEVID_PCI:
1006 case AR9280_DEVID_PCIE:
1007 case AR9285_DEVID_PCIE:
Senthil Balasubramaniandb3cc532010-04-15 17:38:18 -04001008 case AR9287_DEVID_PCI:
1009 case AR9287_DEVID_PCIE:
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04001010 case AR2427_DEVID_PCIE:
Senthil Balasubramaniandb3cc532010-04-15 17:38:18 -04001011 case AR9300_DEVID_PCIE:
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04001012 break;
1013 default:
1014 if (common->bus_ops->ath_bus_type == ATH_USB)
1015 break;
1016 ath_print(common, ATH_DBG_FATAL,
1017 "Hardware device ID 0x%04x not supported\n",
1018 ah->hw_version.devid);
1019 return -EOPNOTSUPP;
1020 }
1021
1022 ret = __ath9k_hw_init(ah);
1023 if (ret) {
1024 ath_print(common, ATH_DBG_FATAL,
1025 "Unable to initialize hardware; "
1026 "initialization status: %d\n", ret);
1027 return ret;
1028 }
1029
1030 return 0;
1031}
1032EXPORT_SYMBOL(ath9k_hw_init);
1033
Sujithcbe61d82009-02-09 13:27:12 +05301034static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301035{
1036 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
1037 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
1038
1039 REG_WRITE(ah, AR_QOS_NO_ACK,
1040 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
1041 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
1042 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
1043
1044 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
1045 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
1046 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
1047 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
1048 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
1049}
1050
Sujithcbe61d82009-02-09 13:27:12 +05301051static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301052 struct ath9k_channel *chan)
1053{
Luis R. Rodriguez64773962010-04-15 17:38:17 -04001054 u32 pll = ath9k_hw_compute_pll_control(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301055
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001056 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +05301057
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -04001058 /* Switch the core clock for ar9271 to 117Mhz */
1059 if (AR_SREV_9271(ah)) {
Sujith25e2ab12010-03-17 14:25:22 +05301060 udelay(500);
1061 REG_WRITE(ah, 0x50040, 0x304);
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -04001062 }
1063
Sujithf1dc5602008-10-29 10:16:30 +05301064 udelay(RTC_PLL_SETTLE_DELAY);
1065
1066 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
1067}
1068
Sujithcbe61d82009-02-09 13:27:12 +05301069static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -08001070 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301071{
Pavel Roskin152d5302010-03-31 18:05:37 -04001072 u32 imr_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +05301073 AR_IMR_TXURN |
1074 AR_IMR_RXERR |
1075 AR_IMR_RXORN |
1076 AR_IMR_BCNMISC;
1077
Sujith0ce024c2009-12-14 14:57:00 +05301078 if (ah->config.rx_intr_mitigation)
Pavel Roskin152d5302010-03-31 18:05:37 -04001079 imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
Sujithf1dc5602008-10-29 10:16:30 +05301080 else
Pavel Roskin152d5302010-03-31 18:05:37 -04001081 imr_reg |= AR_IMR_RXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301082
Pavel Roskin152d5302010-03-31 18:05:37 -04001083 imr_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301084
Colin McCabed97809d2008-12-01 13:38:55 -08001085 if (opmode == NL80211_IFTYPE_AP)
Pavel Roskin152d5302010-03-31 18:05:37 -04001086 imr_reg |= AR_IMR_MIB;
Sujithf1dc5602008-10-29 10:16:30 +05301087
Pavel Roskin152d5302010-03-31 18:05:37 -04001088 REG_WRITE(ah, AR_IMR, imr_reg);
Pavel Roskin74bad5c2010-02-23 18:15:27 -05001089 ah->imrs2_reg |= AR_IMR_S2_GTT;
1090 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
Sujithf1dc5602008-10-29 10:16:30 +05301091
1092 if (!AR_SREV_9100(ah)) {
1093 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
1094 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
1095 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
1096 }
1097}
1098
Felix Fietkau0005baf2010-01-15 02:33:40 +01001099static void ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301100{
Felix Fietkau0005baf2010-01-15 02:33:40 +01001101 u32 val = ath9k_hw_mac_to_clks(ah, us);
1102 val = min(val, (u32) 0xFFFF);
1103 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, val);
Sujithf1dc5602008-10-29 10:16:30 +05301104}
1105
Felix Fietkau0005baf2010-01-15 02:33:40 +01001106static void ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301107{
Felix Fietkau0005baf2010-01-15 02:33:40 +01001108 u32 val = ath9k_hw_mac_to_clks(ah, us);
1109 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_ACK));
1110 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_ACK, val);
1111}
1112
1113static void ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
1114{
1115 u32 val = ath9k_hw_mac_to_clks(ah, us);
1116 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_CTS));
1117 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_CTS, val);
Sujithf1dc5602008-10-29 10:16:30 +05301118}
1119
Sujithcbe61d82009-02-09 13:27:12 +05301120static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +05301121{
Sujithf1dc5602008-10-29 10:16:30 +05301122 if (tu > 0xFFFF) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001123 ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT,
1124 "bad global tx timeout %u\n", tu);
Sujith2660b812009-02-09 13:27:26 +05301125 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301126 return false;
1127 } else {
1128 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +05301129 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +05301130 return true;
1131 }
1132}
1133
Felix Fietkau0005baf2010-01-15 02:33:40 +01001134void ath9k_hw_init_global_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301135{
Felix Fietkau0005baf2010-01-15 02:33:40 +01001136 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
1137 int acktimeout;
Felix Fietkaue239d852010-01-15 02:34:58 +01001138 int slottime;
Felix Fietkau0005baf2010-01-15 02:33:40 +01001139 int sifstime;
1140
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001141 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
1142 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +05301143
Sujith2660b812009-02-09 13:27:26 +05301144 if (ah->misc_mode != 0)
Sujithf1dc5602008-10-29 10:16:30 +05301145 REG_WRITE(ah, AR_PCU_MISC,
Sujith2660b812009-02-09 13:27:26 +05301146 REG_READ(ah, AR_PCU_MISC) | ah->misc_mode);
Felix Fietkau0005baf2010-01-15 02:33:40 +01001147
1148 if (conf->channel && conf->channel->band == IEEE80211_BAND_5GHZ)
1149 sifstime = 16;
1150 else
1151 sifstime = 10;
1152
Felix Fietkaue239d852010-01-15 02:34:58 +01001153 /* As defined by IEEE 802.11-2007 17.3.8.6 */
1154 slottime = ah->slottime + 3 * ah->coverage_class;
1155 acktimeout = slottime + sifstime;
Felix Fietkau42c45682010-02-11 18:07:19 +01001156
1157 /*
1158 * Workaround for early ACK timeouts, add an offset to match the
1159 * initval's 64us ack timeout value.
1160 * This was initially only meant to work around an issue with delayed
1161 * BA frames in some implementations, but it has been found to fix ACK
1162 * timeout issues in other cases as well.
1163 */
1164 if (conf->channel && conf->channel->band == IEEE80211_BAND_2GHZ)
1165 acktimeout += 64 - sifstime - ah->slottime;
1166
Felix Fietkaue239d852010-01-15 02:34:58 +01001167 ath9k_hw_setslottime(ah, slottime);
Felix Fietkau0005baf2010-01-15 02:33:40 +01001168 ath9k_hw_set_ack_timeout(ah, acktimeout);
1169 ath9k_hw_set_cts_timeout(ah, acktimeout);
Sujith2660b812009-02-09 13:27:26 +05301170 if (ah->globaltxtimeout != (u32) -1)
1171 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Sujithf1dc5602008-10-29 10:16:30 +05301172}
Felix Fietkau0005baf2010-01-15 02:33:40 +01001173EXPORT_SYMBOL(ath9k_hw_init_global_settings);
Sujithf1dc5602008-10-29 10:16:30 +05301174
Sujith285f2dd2010-01-08 10:36:07 +05301175void ath9k_hw_deinit(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001176{
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001177 struct ath_common *common = ath9k_hw_common(ah);
1178
Sujith736b3a22010-03-17 14:25:24 +05301179 if (common->state < ATH_HW_INITIALIZED)
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001180 goto free_hw;
1181
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001182 if (!AR_SREV_9100(ah))
Luis R. Rodrigueze70c0cf2009-08-03 12:24:51 -07001183 ath9k_hw_ani_disable(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001184
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001185 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001186
1187free_hw:
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001188 ath9k_hw_rf_free_ext_banks(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001189}
Sujith285f2dd2010-01-08 10:36:07 +05301190EXPORT_SYMBOL(ath9k_hw_deinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001191
Sujithf1dc5602008-10-29 10:16:30 +05301192/*******/
1193/* INI */
1194/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001195
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001196u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan)
Bob Copeland3a702e42009-03-30 22:30:29 -04001197{
1198 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
1199
1200 if (IS_CHAN_B(chan))
1201 ctl |= CTL_11B;
1202 else if (IS_CHAN_G(chan))
1203 ctl |= CTL_11G;
1204 else
1205 ctl |= CTL_11A;
1206
1207 return ctl;
1208}
1209
Sujithf1dc5602008-10-29 10:16:30 +05301210/****************************************/
1211/* Reset and Channel Switching Routines */
1212/****************************************/
1213
Sujithcbe61d82009-02-09 13:27:12 +05301214static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301215{
1216 u32 regval;
1217
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001218 /*
1219 * set AHB_MODE not to do cacheline prefetches
1220 */
Sujithf1dc5602008-10-29 10:16:30 +05301221 regval = REG_READ(ah, AR_AHB_MODE);
1222 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
1223
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001224 /*
1225 * let mac dma reads be in 128 byte chunks
1226 */
Sujithf1dc5602008-10-29 10:16:30 +05301227 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
1228 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
1229
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001230 /*
1231 * Restore TX Trigger Level to its pre-reset value.
1232 * The initial value depends on whether aggregation is enabled, and is
1233 * adjusted whenever underruns are detected.
1234 */
Sujith2660b812009-02-09 13:27:26 +05301235 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +05301236
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001237 /*
1238 * let mac dma writes be in 128 byte chunks
1239 */
Sujithf1dc5602008-10-29 10:16:30 +05301240 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
1241 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
1242
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001243 /*
1244 * Setup receive FIFO threshold to hold off TX activities
1245 */
Sujithf1dc5602008-10-29 10:16:30 +05301246 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1247
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001248 /*
1249 * reduce the number of usable entries in PCU TXBUF to avoid
1250 * wrap around issues.
1251 */
Sujithf1dc5602008-10-29 10:16:30 +05301252 if (AR_SREV_9285(ah)) {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001253 /* For AR9285 the number of Fifos are reduced to half.
1254 * So set the usable tx buf size also to half to
1255 * avoid data/delimiter underruns
1256 */
Sujithf1dc5602008-10-29 10:16:30 +05301257 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1258 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001259 } else if (!AR_SREV_9271(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +05301260 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1261 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1262 }
1263}
1264
Sujithcbe61d82009-02-09 13:27:12 +05301265static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301266{
1267 u32 val;
1268
1269 val = REG_READ(ah, AR_STA_ID1);
1270 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
1271 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001272 case NL80211_IFTYPE_AP:
Sujithf1dc5602008-10-29 10:16:30 +05301273 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
1274 | AR_STA_ID1_KSRCH_MODE);
1275 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1276 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001277 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04001278 case NL80211_IFTYPE_MESH_POINT:
Sujithf1dc5602008-10-29 10:16:30 +05301279 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
1280 | AR_STA_ID1_KSRCH_MODE);
1281 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1282 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001283 case NL80211_IFTYPE_STATION:
1284 case NL80211_IFTYPE_MONITOR:
Sujithf1dc5602008-10-29 10:16:30 +05301285 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
1286 break;
1287 }
1288}
1289
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001290void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled,
1291 u32 *coef_mantissa, u32 *coef_exponent)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001292{
1293 u32 coef_exp, coef_man;
1294
1295 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1296 if ((coef_scaled >> coef_exp) & 0x1)
1297 break;
1298
1299 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1300
1301 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1302
1303 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1304 *coef_exponent = coef_exp - 16;
1305}
1306
Sujithcbe61d82009-02-09 13:27:12 +05301307static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +05301308{
1309 u32 rst_flags;
1310 u32 tmpReg;
1311
Sujith70768492009-02-16 13:23:12 +05301312 if (AR_SREV_9100(ah)) {
1313 u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK);
1314 val &= ~AR_RTC_DERIVED_CLK_PERIOD;
1315 val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD);
1316 REG_WRITE(ah, AR_RTC_DERIVED_CLK, val);
1317 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1318 }
1319
Sujithf1dc5602008-10-29 10:16:30 +05301320 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1321 AR_RTC_FORCE_WAKE_ON_INT);
1322
1323 if (AR_SREV_9100(ah)) {
1324 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1325 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1326 } else {
1327 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1328 if (tmpReg &
1329 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1330 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001331 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05301332 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001333
1334 val = AR_RC_HOSTIF;
1335 if (!AR_SREV_9300_20_OR_LATER(ah))
1336 val |= AR_RC_AHB;
1337 REG_WRITE(ah, AR_RC, val);
1338
1339 } else if (!AR_SREV_9300_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05301340 REG_WRITE(ah, AR_RC, AR_RC_AHB);
Sujithf1dc5602008-10-29 10:16:30 +05301341
1342 rst_flags = AR_RTC_RC_MAC_WARM;
1343 if (type == ATH9K_RESET_COLD)
1344 rst_flags |= AR_RTC_RC_MAC_COLD;
1345 }
1346
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001347 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujithf1dc5602008-10-29 10:16:30 +05301348 udelay(50);
1349
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001350 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301351 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001352 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1353 "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301354 return false;
1355 }
1356
1357 if (!AR_SREV_9100(ah))
1358 REG_WRITE(ah, AR_RC, 0);
1359
Sujithf1dc5602008-10-29 10:16:30 +05301360 if (AR_SREV_9100(ah))
1361 udelay(50);
1362
1363 return true;
1364}
1365
Sujithcbe61d82009-02-09 13:27:12 +05301366static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301367{
1368 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1369 AR_RTC_FORCE_WAKE_ON_INT);
1370
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001371 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301372 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1373
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001374 REG_WRITE(ah, AR_RTC_RESET, 0);
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301375 udelay(2);
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301376
1377 if (!AR_SREV_9100(ah))
1378 REG_WRITE(ah, AR_RC, 0);
1379
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001380 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301381
1382 if (!ath9k_hw_wait(ah,
1383 AR_RTC_STATUS,
1384 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301385 AR_RTC_STATUS_ON,
1386 AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001387 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1388 "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301389 return false;
1390 }
1391
1392 ath9k_hw_read_revisions(ah);
1393
1394 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1395}
1396
Sujithcbe61d82009-02-09 13:27:12 +05301397static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301398{
1399 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1400 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1401
1402 switch (type) {
1403 case ATH9K_RESET_POWER_ON:
1404 return ath9k_hw_set_reset_power_on(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301405 case ATH9K_RESET_WARM:
1406 case ATH9K_RESET_COLD:
1407 return ath9k_hw_set_reset(ah, type);
Sujithf1dc5602008-10-29 10:16:30 +05301408 default:
1409 return false;
1410 }
1411}
1412
Sujithcbe61d82009-02-09 13:27:12 +05301413static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301414 struct ath9k_channel *chan)
1415{
Vivek Natarajan42abfbe2009-09-17 09:27:59 +05301416 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) {
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301417 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
1418 return false;
1419 } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
Sujithf1dc5602008-10-29 10:16:30 +05301420 return false;
1421
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001422 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05301423 return false;
1424
Sujith2660b812009-02-09 13:27:26 +05301425 ah->chip_fullsleep = false;
Sujithf1dc5602008-10-29 10:16:30 +05301426 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301427 ath9k_hw_set_rfmode(ah, chan);
1428
1429 return true;
1430}
1431
Sujithcbe61d82009-02-09 13:27:12 +05301432static bool ath9k_hw_channel_change(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001433 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301434{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001435 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001436 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001437 struct ieee80211_channel *channel = chan->chan;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001438 u32 qnum;
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001439 int r;
Sujithf1dc5602008-10-29 10:16:30 +05301440
1441 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1442 if (ath9k_hw_numtxpending(ah, qnum)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001443 ath_print(common, ATH_DBG_QUEUE,
1444 "Transmit frames pending on "
1445 "queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301446 return false;
1447 }
1448 }
1449
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001450 if (!ath9k_hw_rfbus_req(ah)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001451 ath_print(common, ATH_DBG_FATAL,
1452 "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301453 return false;
1454 }
1455
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001456 ath9k_hw_set_channel_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301457
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001458 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001459 if (r) {
1460 ath_print(common, ATH_DBG_FATAL,
1461 "Failed to set channel\n");
1462 return false;
Sujithf1dc5602008-10-29 10:16:30 +05301463 }
1464
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001465 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001466 ath9k_regd_get_ctl(regulatory, chan),
Sujithf74df6f2009-02-09 13:27:24 +05301467 channel->max_antenna_gain * 2,
1468 channel->max_power * 2,
1469 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001470 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05301471
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001472 ath9k_hw_rfbus_done(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301473
1474 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1475 ath9k_hw_set_delta_slope(ah, chan);
1476
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001477 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301478
1479 if (!chan->oneTimeCalsDone)
1480 chan->oneTimeCalsDone = true;
1481
1482 return true;
1483}
1484
Sujithcbe61d82009-02-09 13:27:12 +05301485int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001486 bool bChannelChange)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001487{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001488 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001489 u32 saveLedState;
Sujith2660b812009-02-09 13:27:26 +05301490 struct ath9k_channel *curchan = ah->curchan;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001491 u32 saveDefAntenna;
1492 u32 macStaId1;
Sujith46fe7822009-09-17 09:25:25 +05301493 u64 tsf = 0;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001494 int i, r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001495
Luis R. Rodriguez43c27612009-09-13 21:07:07 -07001496 ah->txchainmask = common->tx_chainmask;
1497 ah->rxchainmask = common->rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001498
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001499 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001500 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001501
Vasanthakumar Thiagarajan9ebef792009-09-17 09:26:44 +05301502 if (curchan && !ah->chip_fullsleep)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001503 ath9k_hw_getnf(ah, curchan);
1504
1505 if (bChannelChange &&
Sujith2660b812009-02-09 13:27:26 +05301506 (ah->chip_fullsleep != true) &&
1507 (ah->curchan != NULL) &&
1508 (chan->channel != ah->curchan->channel) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001509 ((chan->channelFlags & CHANNEL_ALL) ==
Sujith2660b812009-02-09 13:27:26 +05301510 (ah->curchan->channelFlags & CHANNEL_ALL)) &&
Vasanthakumar Thiagarajan0a475cc2009-09-17 09:27:10 +05301511 !(AR_SREV_9280(ah) || IS_CHAN_A_5MHZ_SPACED(chan) ||
1512 IS_CHAN_A_5MHZ_SPACED(ah->curchan))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001513
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001514 if (ath9k_hw_channel_change(ah, chan)) {
Sujith2660b812009-02-09 13:27:26 +05301515 ath9k_hw_loadnf(ah, ah->curchan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001516 ath9k_hw_start_nfcal(ah);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001517 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001518 }
1519 }
1520
1521 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
1522 if (saveDefAntenna == 0)
1523 saveDefAntenna = 1;
1524
1525 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
1526
Sujith46fe7822009-09-17 09:25:25 +05301527 /* For chips on which RTC reset is done, save TSF before it gets cleared */
1528 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1529 tsf = ath9k_hw_gettsf64(ah);
1530
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001531 saveLedState = REG_READ(ah, AR_CFG_LED) &
1532 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
1533 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
1534
1535 ath9k_hw_mark_phy_inactive(ah);
1536
Sujith05020d22010-03-17 14:25:23 +05301537 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001538 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1539 REG_WRITE(ah,
1540 AR9271_RESET_POWER_DOWN_CONTROL,
1541 AR9271_RADIO_RF_RST);
1542 udelay(50);
1543 }
1544
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001545 if (!ath9k_hw_chip_reset(ah, chan)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001546 ath_print(common, ATH_DBG_FATAL, "Chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001547 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001548 }
1549
Sujith05020d22010-03-17 14:25:23 +05301550 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001551 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1552 ah->htc_reset_init = false;
1553 REG_WRITE(ah,
1554 AR9271_RESET_POWER_DOWN_CONTROL,
1555 AR9271_GATE_MAC_CTL);
1556 udelay(50);
1557 }
1558
Sujith46fe7822009-09-17 09:25:25 +05301559 /* Restore TSF */
1560 if (tsf && AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1561 ath9k_hw_settsf64(ah, tsf);
1562
Vasanthakumar Thiagarajan369391d2009-01-21 19:24:13 +05301563 if (AR_SREV_9280_10_OR_LATER(ah))
1564 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001565
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001566 r = ath9k_hw_process_ini(ah, chan);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001567 if (r)
1568 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001569
Jouni Malinen0ced0e12009-01-08 13:32:13 +02001570 /* Setup MFP options for CCMP */
1571 if (AR_SREV_9280_20_OR_LATER(ah)) {
1572 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
1573 * frames when constructing CCMP AAD. */
1574 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
1575 0xc7ff);
1576 ah->sw_mgmt_crypto = false;
1577 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1578 /* Disable hardware crypto for management frames */
1579 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
1580 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
1581 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1582 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
1583 ah->sw_mgmt_crypto = true;
1584 } else
1585 ah->sw_mgmt_crypto = true;
1586
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001587 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1588 ath9k_hw_set_delta_slope(ah, chan);
1589
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001590 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithd6509152009-03-13 08:56:05 +05301591 ah->eep_ops->set_board_values(ah, chan);
Luis R. Rodrigueza7765822009-10-19 02:33:45 -04001592
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001593 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
1594 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001595 | macStaId1
1596 | AR_STA_ID1_RTS_USE_DEF
Sujith2660b812009-02-09 13:27:26 +05301597 | (ah->config.
Sujith60b67f52008-08-07 10:52:38 +05301598 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Sujith2660b812009-02-09 13:27:26 +05301599 | ah->sta_id1_defaults);
1600 ath9k_hw_set_operating_mode(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001601
Luis R. Rodriguez13b81552009-09-10 17:52:45 -07001602 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001603
1604 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
1605
Luis R. Rodriguez3453ad82009-09-10 08:57:00 -07001606 ath9k_hw_write_associd(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001607
1608 REG_WRITE(ah, AR_ISR, ~0);
1609
1610 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
1611
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001612 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001613 if (r)
1614 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001615
1616 for (i = 0; i < AR_NUM_DCU; i++)
1617 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
1618
Sujith2660b812009-02-09 13:27:26 +05301619 ah->intr_txqs = 0;
1620 for (i = 0; i < ah->caps.total_queues; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001621 ath9k_hw_resettxqueue(ah, i);
1622
Sujith2660b812009-02-09 13:27:26 +05301623 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001624 ath9k_hw_init_qos(ah);
1625
Sujith2660b812009-02-09 13:27:26 +05301626 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301627 ath9k_enable_rfkill(ah);
Johannes Berg3b319aa2009-06-13 14:50:26 +05301628
Felix Fietkau0005baf2010-01-15 02:33:40 +01001629 ath9k_hw_init_global_settings(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001630
Vivek Natarajan326bebb2009-08-14 11:33:36 +05301631 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301632 REG_WRITE(ah, AR_D_GBL_IFS_SIFS,
1633 AR_D_GBL_IFS_SIFS_ASYNC_FIFO_DUR);
1634 REG_WRITE(ah, AR_D_GBL_IFS_SLOT,
1635 AR_D_GBL_IFS_SLOT_ASYNC_FIFO_DUR);
1636 REG_WRITE(ah, AR_D_GBL_IFS_EIFS,
1637 AR_D_GBL_IFS_EIFS_ASYNC_FIFO_DUR);
1638
1639 REG_WRITE(ah, AR_TIME_OUT, AR_TIME_OUT_ACK_CTS_ASYNC_FIFO_DUR);
1640 REG_WRITE(ah, AR_USEC, AR_USEC_ASYNC_FIFO_DUR);
1641
1642 REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
1643 AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
1644 REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
1645 AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
1646 }
Vivek Natarajan326bebb2009-08-14 11:33:36 +05301647 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301648 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1649 AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
1650 }
1651
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001652 REG_WRITE(ah, AR_STA_ID1,
1653 REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
1654
1655 ath9k_hw_set_dma(ah);
1656
1657 REG_WRITE(ah, AR_OBS, 8);
1658
Sujith0ce024c2009-12-14 14:57:00 +05301659 if (ah->config.rx_intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001660 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
1661 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
1662 }
1663
1664 ath9k_hw_init_bb(ah, chan);
1665
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001666 if (!ath9k_hw_init_cal(ah, chan))
Joe Perches6badaaf2009-06-28 09:26:32 -07001667 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001668
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001669 ath9k_hw_restore_chainmask(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001670 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
1671
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001672 /*
1673 * For big endian systems turn on swapping for descriptors
1674 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001675 if (AR_SREV_9100(ah)) {
1676 u32 mask;
1677 mask = REG_READ(ah, AR_CFG);
1678 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001679 ath_print(common, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05301680 "CFG Byte Swap Set 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001681 } else {
1682 mask =
1683 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
1684 REG_WRITE(ah, AR_CFG, mask);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001685 ath_print(common, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05301686 "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001687 }
1688 } else {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001689 /* Configure AR9271 target WLAN */
1690 if (AR_SREV_9271(ah))
1691 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001692#ifdef __BIG_ENDIAN
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001693 else
1694 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001695#endif
1696 }
1697
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001698 if (ah->btcoex_hw.enabled)
Vasanthakumar Thiagarajan42cc41e2009-08-26 21:08:45 +05301699 ath9k_hw_btcoex_enable(ah);
1700
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001701 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001702}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001703EXPORT_SYMBOL(ath9k_hw_reset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001704
Sujithf1dc5602008-10-29 10:16:30 +05301705/************************/
1706/* Key Cache Management */
1707/************************/
1708
Sujithcbe61d82009-02-09 13:27:12 +05301709bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001710{
Sujithf1dc5602008-10-29 10:16:30 +05301711 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001712
Sujith2660b812009-02-09 13:27:26 +05301713 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001714 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1715 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001716 return false;
1717 }
1718
Sujithf1dc5602008-10-29 10:16:30 +05301719 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001720
Sujithf1dc5602008-10-29 10:16:30 +05301721 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
1722 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
1723 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
1724 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
1725 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
1726 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
1727 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
1728 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
1729
1730 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
1731 u16 micentry = entry + 64;
1732
1733 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
1734 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
1735 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
1736 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
1737
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001738 }
1739
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001740 return true;
1741}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001742EXPORT_SYMBOL(ath9k_hw_keyreset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001743
Sujithcbe61d82009-02-09 13:27:12 +05301744bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001745{
Sujithf1dc5602008-10-29 10:16:30 +05301746 u32 macHi, macLo;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001747
Sujith2660b812009-02-09 13:27:26 +05301748 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001749 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1750 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001751 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001752 }
1753
Sujithf1dc5602008-10-29 10:16:30 +05301754 if (mac != NULL) {
1755 macHi = (mac[5] << 8) | mac[4];
1756 macLo = (mac[3] << 24) |
1757 (mac[2] << 16) |
1758 (mac[1] << 8) |
1759 mac[0];
1760 macLo >>= 1;
1761 macLo |= (macHi & 1) << 31;
1762 macHi >>= 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001763 } else {
Sujithf1dc5602008-10-29 10:16:30 +05301764 macLo = macHi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001765 }
Sujithf1dc5602008-10-29 10:16:30 +05301766 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
1767 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001768
1769 return true;
1770}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001771EXPORT_SYMBOL(ath9k_hw_keysetmac);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001772
Sujithcbe61d82009-02-09 13:27:12 +05301773bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
Sujithf1dc5602008-10-29 10:16:30 +05301774 const struct ath9k_keyval *k,
Jouni Malinene0caf9e2009-03-02 18:15:53 +02001775 const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001776{
Sujith2660b812009-02-09 13:27:26 +05301777 const struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001778 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301779 u32 key0, key1, key2, key3, key4;
1780 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001781
Sujithf1dc5602008-10-29 10:16:30 +05301782 if (entry >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001783 ath_print(common, ATH_DBG_FATAL,
1784 "keycache entry %u out of range\n", entry);
Sujithf1dc5602008-10-29 10:16:30 +05301785 return false;
1786 }
1787
1788 switch (k->kv_type) {
1789 case ATH9K_CIPHER_AES_OCB:
1790 keyType = AR_KEYTABLE_TYPE_AES;
1791 break;
1792 case ATH9K_CIPHER_AES_CCM:
1793 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001794 ath_print(common, ATH_DBG_ANY,
1795 "AES-CCM not supported by mac rev 0x%x\n",
1796 ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001797 return false;
1798 }
Sujithf1dc5602008-10-29 10:16:30 +05301799 keyType = AR_KEYTABLE_TYPE_CCM;
1800 break;
1801 case ATH9K_CIPHER_TKIP:
1802 keyType = AR_KEYTABLE_TYPE_TKIP;
1803 if (ATH9K_IS_MIC_ENABLED(ah)
1804 && entry + 64 >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001805 ath_print(common, ATH_DBG_ANY,
1806 "entry %u inappropriate for TKIP\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001807 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001808 }
Sujithf1dc5602008-10-29 10:16:30 +05301809 break;
1810 case ATH9K_CIPHER_WEP:
Zhu Yie31a16d2009-05-21 21:47:03 +08001811 if (k->kv_len < WLAN_KEY_LEN_WEP40) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001812 ath_print(common, ATH_DBG_ANY,
1813 "WEP key length %u too small\n", k->kv_len);
Sujithf1dc5602008-10-29 10:16:30 +05301814 return false;
1815 }
Zhu Yie31a16d2009-05-21 21:47:03 +08001816 if (k->kv_len <= WLAN_KEY_LEN_WEP40)
Sujithf1dc5602008-10-29 10:16:30 +05301817 keyType = AR_KEYTABLE_TYPE_40;
Zhu Yie31a16d2009-05-21 21:47:03 +08001818 else if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05301819 keyType = AR_KEYTABLE_TYPE_104;
1820 else
1821 keyType = AR_KEYTABLE_TYPE_128;
1822 break;
1823 case ATH9K_CIPHER_CLR:
1824 keyType = AR_KEYTABLE_TYPE_CLR;
1825 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001826 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001827 ath_print(common, ATH_DBG_FATAL,
1828 "cipher %u not supported\n", k->kv_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001829 return false;
1830 }
Sujithf1dc5602008-10-29 10:16:30 +05301831
Jouni Malinene0caf9e2009-03-02 18:15:53 +02001832 key0 = get_unaligned_le32(k->kv_val + 0);
1833 key1 = get_unaligned_le16(k->kv_val + 4);
1834 key2 = get_unaligned_le32(k->kv_val + 6);
1835 key3 = get_unaligned_le16(k->kv_val + 10);
1836 key4 = get_unaligned_le32(k->kv_val + 12);
Zhu Yie31a16d2009-05-21 21:47:03 +08001837 if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05301838 key4 &= 0xff;
1839
Jouni Malinen672903b2009-03-02 15:06:31 +02001840 /*
1841 * Note: Key cache registers access special memory area that requires
1842 * two 32-bit writes to actually update the values in the internal
1843 * memory. Consequently, the exact order and pairs used here must be
1844 * maintained.
1845 */
1846
Sujithf1dc5602008-10-29 10:16:30 +05301847 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
1848 u16 micentry = entry + 64;
1849
Jouni Malinen672903b2009-03-02 15:06:31 +02001850 /*
1851 * Write inverted key[47:0] first to avoid Michael MIC errors
1852 * on frames that could be sent or received at the same time.
1853 * The correct key will be written in the end once everything
1854 * else is ready.
1855 */
Sujithf1dc5602008-10-29 10:16:30 +05301856 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
1857 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02001858
1859 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05301860 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
1861 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02001862
1863 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05301864 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
1865 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
Jouni Malinen672903b2009-03-02 15:06:31 +02001866
1867 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05301868 (void) ath9k_hw_keysetmac(ah, entry, mac);
1869
Sujith2660b812009-02-09 13:27:26 +05301870 if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) {
Jouni Malinen672903b2009-03-02 15:06:31 +02001871 /*
1872 * TKIP uses two key cache entries:
1873 * Michael MIC TX/RX keys in the same key cache entry
1874 * (idx = main index + 64):
1875 * key0 [31:0] = RX key [31:0]
1876 * key1 [15:0] = TX key [31:16]
1877 * key1 [31:16] = reserved
1878 * key2 [31:0] = RX key [63:32]
1879 * key3 [15:0] = TX key [15:0]
1880 * key3 [31:16] = reserved
1881 * key4 [31:0] = TX key [63:32]
1882 */
Sujithf1dc5602008-10-29 10:16:30 +05301883 u32 mic0, mic1, mic2, mic3, mic4;
1884
1885 mic0 = get_unaligned_le32(k->kv_mic + 0);
1886 mic2 = get_unaligned_le32(k->kv_mic + 4);
1887 mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
1888 mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
1889 mic4 = get_unaligned_le32(k->kv_txmic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02001890
1891 /* Write RX[31:0] and TX[31:16] */
Sujithf1dc5602008-10-29 10:16:30 +05301892 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
1893 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
Jouni Malinen672903b2009-03-02 15:06:31 +02001894
1895 /* Write RX[63:32] and TX[15:0] */
Sujithf1dc5602008-10-29 10:16:30 +05301896 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
1897 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
Jouni Malinen672903b2009-03-02 15:06:31 +02001898
1899 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05301900 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
1901 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
1902 AR_KEYTABLE_TYPE_CLR);
1903
1904 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02001905 /*
1906 * TKIP uses four key cache entries (two for group
1907 * keys):
1908 * Michael MIC TX/RX keys are in different key cache
1909 * entries (idx = main index + 64 for TX and
1910 * main index + 32 + 96 for RX):
1911 * key0 [31:0] = TX/RX MIC key [31:0]
1912 * key1 [31:0] = reserved
1913 * key2 [31:0] = TX/RX MIC key [63:32]
1914 * key3 [31:0] = reserved
1915 * key4 [31:0] = reserved
1916 *
1917 * Upper layer code will call this function separately
1918 * for TX and RX keys when these registers offsets are
1919 * used.
1920 */
Sujithf1dc5602008-10-29 10:16:30 +05301921 u32 mic0, mic2;
1922
1923 mic0 = get_unaligned_le32(k->kv_mic + 0);
1924 mic2 = get_unaligned_le32(k->kv_mic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02001925
1926 /* Write MIC key[31:0] */
Sujithf1dc5602008-10-29 10:16:30 +05301927 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
1928 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02001929
1930 /* Write MIC key[63:32] */
Sujithf1dc5602008-10-29 10:16:30 +05301931 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
1932 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02001933
1934 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05301935 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
1936 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
1937 AR_KEYTABLE_TYPE_CLR);
1938 }
Jouni Malinen672903b2009-03-02 15:06:31 +02001939
1940 /* MAC address registers are reserved for the MIC entry */
Sujithf1dc5602008-10-29 10:16:30 +05301941 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
1942 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02001943
1944 /*
1945 * Write the correct (un-inverted) key[47:0] last to enable
1946 * TKIP now that all other registers are set with correct
1947 * values.
1948 */
Sujithf1dc5602008-10-29 10:16:30 +05301949 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
1950 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
1951 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02001952 /* Write key[47:0] */
Sujithf1dc5602008-10-29 10:16:30 +05301953 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
1954 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02001955
1956 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05301957 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
1958 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02001959
1960 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05301961 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
1962 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
1963
Jouni Malinen672903b2009-03-02 15:06:31 +02001964 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05301965 (void) ath9k_hw_keysetmac(ah, entry, mac);
1966 }
1967
Sujithf1dc5602008-10-29 10:16:30 +05301968 return true;
1969}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001970EXPORT_SYMBOL(ath9k_hw_set_keycache_entry);
Sujithf1dc5602008-10-29 10:16:30 +05301971
Sujithcbe61d82009-02-09 13:27:12 +05301972bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry)
Sujithf1dc5602008-10-29 10:16:30 +05301973{
Sujith2660b812009-02-09 13:27:26 +05301974 if (entry < ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05301975 u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
1976 if (val & AR_KEYTABLE_VALID)
1977 return true;
1978 }
1979 return false;
1980}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001981EXPORT_SYMBOL(ath9k_hw_keyisvalid);
Sujithf1dc5602008-10-29 10:16:30 +05301982
1983/******************************/
1984/* Power Management (Chipset) */
1985/******************************/
1986
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001987/*
1988 * Notify Power Mgt is disabled in self-generated frames.
1989 * If requested, force chip to sleep.
1990 */
Sujithcbe61d82009-02-09 13:27:12 +05301991static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05301992{
1993 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
1994 if (setChip) {
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001995 /*
1996 * Clear the RTC force wake bit to allow the
1997 * mac to go to sleep.
1998 */
Sujithf1dc5602008-10-29 10:16:30 +05301999 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2000 AR_RTC_FORCE_WAKE_EN);
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04002001 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302002 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
2003
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04002004 /* Shutdown chip. Active low */
Sujith14b3af32010-03-17 14:25:18 +05302005 if (!AR_SREV_5416(ah) && !AR_SREV_9271(ah))
Sujith4921be82009-09-18 15:04:27 +05302006 REG_CLR_BIT(ah, (AR_RTC_RESET),
2007 AR_RTC_RESET_EN);
Sujithf1dc5602008-10-29 10:16:30 +05302008 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002009}
2010
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04002011/*
2012 * Notify Power Management is enabled in self-generating
2013 * frames. If request, set power mode of chip to
2014 * auto/normal. Duration in units of 128us (1/8 TU).
2015 */
Sujithcbe61d82009-02-09 13:27:12 +05302016static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002017{
Sujithf1dc5602008-10-29 10:16:30 +05302018 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2019 if (setChip) {
Sujith2660b812009-02-09 13:27:26 +05302020 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002021
Sujithf1dc5602008-10-29 10:16:30 +05302022 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04002023 /* Set WakeOnInterrupt bit; clear ForceWake bit */
Sujithf1dc5602008-10-29 10:16:30 +05302024 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2025 AR_RTC_FORCE_WAKE_ON_INT);
2026 } else {
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04002027 /*
2028 * Clear the RTC force wake bit to allow the
2029 * mac to go to sleep.
2030 */
Sujithf1dc5602008-10-29 10:16:30 +05302031 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2032 AR_RTC_FORCE_WAKE_EN);
2033 }
2034 }
2035}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002036
Sujithcbe61d82009-02-09 13:27:12 +05302037static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302038{
2039 u32 val;
2040 int i;
2041
2042 if (setChip) {
2043 if ((REG_READ(ah, AR_RTC_STATUS) &
2044 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2045 if (ath9k_hw_set_reset_reg(ah,
2046 ATH9K_RESET_POWER_ON) != true) {
2047 return false;
2048 }
Luis R. Rodrigueze0412282010-04-15 17:38:15 -04002049 if (!AR_SREV_9300_20_OR_LATER(ah))
2050 ath9k_hw_init_pll(ah, NULL);
Sujithf1dc5602008-10-29 10:16:30 +05302051 }
2052 if (AR_SREV_9100(ah))
2053 REG_SET_BIT(ah, AR_RTC_RESET,
2054 AR_RTC_RESET_EN);
2055
2056 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2057 AR_RTC_FORCE_WAKE_EN);
2058 udelay(50);
2059
2060 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2061 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2062 if (val == AR_RTC_STATUS_ON)
2063 break;
2064 udelay(50);
2065 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2066 AR_RTC_FORCE_WAKE_EN);
2067 }
2068 if (i == 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002069 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2070 "Failed to wakeup in %uus\n",
2071 POWER_UP_TIME / 20);
Sujithf1dc5602008-10-29 10:16:30 +05302072 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002073 }
2074 }
2075
Sujithf1dc5602008-10-29 10:16:30 +05302076 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2077
2078 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002079}
2080
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002081bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05302082{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002083 struct ath_common *common = ath9k_hw_common(ah);
Sujithcbe61d82009-02-09 13:27:12 +05302084 int status = true, setChip = true;
Sujithf1dc5602008-10-29 10:16:30 +05302085 static const char *modes[] = {
2086 "AWAKE",
2087 "FULL-SLEEP",
2088 "NETWORK SLEEP",
2089 "UNDEFINED"
2090 };
Sujithf1dc5602008-10-29 10:16:30 +05302091
Gabor Juhoscbdec972009-07-24 17:27:22 +02002092 if (ah->power_mode == mode)
2093 return status;
2094
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002095 ath_print(common, ATH_DBG_RESET, "%s -> %s\n",
2096 modes[ah->power_mode], modes[mode]);
Sujithf1dc5602008-10-29 10:16:30 +05302097
2098 switch (mode) {
2099 case ATH9K_PM_AWAKE:
2100 status = ath9k_hw_set_power_awake(ah, setChip);
2101 break;
2102 case ATH9K_PM_FULL_SLEEP:
2103 ath9k_set_power_sleep(ah, setChip);
Sujith2660b812009-02-09 13:27:26 +05302104 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05302105 break;
2106 case ATH9K_PM_NETWORK_SLEEP:
2107 ath9k_set_power_network_sleep(ah, setChip);
2108 break;
2109 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002110 ath_print(common, ATH_DBG_FATAL,
2111 "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05302112 return false;
2113 }
Sujith2660b812009-02-09 13:27:26 +05302114 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05302115
2116 return status;
2117}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002118EXPORT_SYMBOL(ath9k_hw_setpower);
Sujithf1dc5602008-10-29 10:16:30 +05302119
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002120/*
2121 * Helper for ASPM support.
2122 *
2123 * Disable PLL when in L0s as well as receiver clock when in L1.
2124 * This power saving option must be enabled through the SerDes.
2125 *
2126 * Programming the SerDes must go through the same 288 bit serial shift
2127 * register as the other analog registers. Hence the 9 writes.
2128 */
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04002129static void ar9002_hw_configpcipowersave(struct ath_hw *ah,
2130 int restore,
2131 int power_off)
Sujithf1dc5602008-10-29 10:16:30 +05302132{
Sujithf1dc5602008-10-29 10:16:30 +05302133 u8 i;
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302134 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05302135
Sujith2660b812009-02-09 13:27:26 +05302136 if (ah->is_pciexpress != true)
Sujithf1dc5602008-10-29 10:16:30 +05302137 return;
2138
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002139 /* Do not touch SerDes registers */
Sujith2660b812009-02-09 13:27:26 +05302140 if (ah->config.pcie_powersave_enable == 2)
Sujithf1dc5602008-10-29 10:16:30 +05302141 return;
2142
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002143 /* Nothing to do on restore for 11N */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302144 if (!restore) {
2145 if (AR_SREV_9280_20_OR_LATER(ah)) {
2146 /*
2147 * AR9280 2.0 or later chips use SerDes values from the
2148 * initvals.h initialized depending on chipset during
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04002149 * __ath9k_hw_init()
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302150 */
2151 for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
2152 REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
2153 INI_RA(&ah->iniPcieSerdes, i, 1));
2154 }
2155 } else if (AR_SREV_9280(ah) &&
2156 (ah->hw_version.macRev == AR_SREV_REVISION_9280_10)) {
2157 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
2158 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
Sujithf1dc5602008-10-29 10:16:30 +05302159
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302160 /* RX shut off when elecidle is asserted */
2161 REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
2162 REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
2163 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
2164
2165 /* Shut off CLKREQ active in L1 */
2166 if (ah->config.pcie_clock_req)
2167 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
2168 else
2169 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
2170
2171 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2172 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2173 REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
2174
2175 /* Load the new settings */
2176 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
2177
2178 } else {
2179 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
2180 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
2181
2182 /* RX shut off when elecidle is asserted */
2183 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
2184 REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
2185 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
2186
2187 /*
2188 * Ignore ah->ah_config.pcie_clock_req setting for
2189 * pre-AR9280 11n
2190 */
2191 REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
2192
2193 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2194 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2195 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
2196
2197 /* Load the new settings */
2198 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
Sujithf1dc5602008-10-29 10:16:30 +05302199 }
Sujithf1dc5602008-10-29 10:16:30 +05302200
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302201 udelay(1000);
Sujithf1dc5602008-10-29 10:16:30 +05302202
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302203 /* set bit 19 to allow forcing of pcie core into L1 state */
2204 REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
Sujithf1dc5602008-10-29 10:16:30 +05302205
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302206 /* Several PCIe massages to ensure proper behaviour */
2207 if (ah->config.pcie_waen) {
2208 val = ah->config.pcie_waen;
2209 if (!power_off)
2210 val &= (~AR_WA_D3_L1_DISABLE);
2211 } else {
2212 if (AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
2213 AR_SREV_9287(ah)) {
2214 val = AR9285_WA_DEFAULT;
2215 if (!power_off)
2216 val &= (~AR_WA_D3_L1_DISABLE);
2217 } else if (AR_SREV_9280(ah)) {
2218 /*
2219 * On AR9280 chips bit 22 of 0x4004 needs to be
2220 * set otherwise card may disappear.
2221 */
2222 val = AR9280_WA_DEFAULT;
2223 if (!power_off)
2224 val &= (~AR_WA_D3_L1_DISABLE);
2225 } else
2226 val = AR_WA_DEFAULT;
2227 }
Sujithf1dc5602008-10-29 10:16:30 +05302228
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302229 REG_WRITE(ah, AR_WA, val);
Sujithf1dc5602008-10-29 10:16:30 +05302230 }
2231
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302232 if (power_off) {
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002233 /*
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302234 * Set PCIe workaround bits
2235 * bit 14 in WA register (disable L1) should only
2236 * be set when device enters D3 and be cleared
2237 * when device comes back to D0.
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002238 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302239 if (ah->config.pcie_waen) {
2240 if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE)
2241 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
2242 } else {
2243 if (((AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
2244 AR_SREV_9287(ah)) &&
2245 (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)) ||
2246 (AR_SREV_9280(ah) &&
2247 (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE))) {
2248 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
2249 }
2250 }
Sujithf1dc5602008-10-29 10:16:30 +05302251 }
2252}
2253
2254/**********************/
2255/* Interrupt Handling */
2256/**********************/
2257
Sujithcbe61d82009-02-09 13:27:12 +05302258bool ath9k_hw_intrpend(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002259{
2260 u32 host_isr;
2261
2262 if (AR_SREV_9100(ah))
2263 return true;
2264
2265 host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
2266 if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
2267 return true;
2268
2269 host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
2270 if ((host_isr & AR_INTR_SYNC_DEFAULT)
2271 && (host_isr != AR_INTR_SPURIOUS))
2272 return true;
2273
2274 return false;
2275}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002276EXPORT_SYMBOL(ath9k_hw_intrpend);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002277
Sujithcbe61d82009-02-09 13:27:12 +05302278bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002279{
2280 u32 isr = 0;
2281 u32 mask2 = 0;
Sujith2660b812009-02-09 13:27:26 +05302282 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002283 u32 sync_cause = 0;
2284 bool fatal_int = false;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002285 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002286
2287 if (!AR_SREV_9100(ah)) {
2288 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
2289 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
2290 == AR_RTC_STATUS_ON) {
2291 isr = REG_READ(ah, AR_ISR);
2292 }
2293 }
2294
Sujithf1dc5602008-10-29 10:16:30 +05302295 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
2296 AR_INTR_SYNC_DEFAULT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002297
2298 *masked = 0;
2299
2300 if (!isr && !sync_cause)
2301 return false;
2302 } else {
2303 *masked = 0;
2304 isr = REG_READ(ah, AR_ISR);
2305 }
2306
2307 if (isr) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002308 if (isr & AR_ISR_BCNMISC) {
2309 u32 isr2;
2310 isr2 = REG_READ(ah, AR_ISR_S2);
2311 if (isr2 & AR_ISR_S2_TIM)
2312 mask2 |= ATH9K_INT_TIM;
2313 if (isr2 & AR_ISR_S2_DTIM)
2314 mask2 |= ATH9K_INT_DTIM;
2315 if (isr2 & AR_ISR_S2_DTIMSYNC)
2316 mask2 |= ATH9K_INT_DTIMSYNC;
2317 if (isr2 & (AR_ISR_S2_CABEND))
2318 mask2 |= ATH9K_INT_CABEND;
2319 if (isr2 & AR_ISR_S2_GTT)
2320 mask2 |= ATH9K_INT_GTT;
2321 if (isr2 & AR_ISR_S2_CST)
2322 mask2 |= ATH9K_INT_CST;
Sujith4af9cf42009-02-12 10:06:47 +05302323 if (isr2 & AR_ISR_S2_TSFOOR)
2324 mask2 |= ATH9K_INT_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002325 }
2326
2327 isr = REG_READ(ah, AR_ISR_RAC);
2328 if (isr == 0xffffffff) {
2329 *masked = 0;
2330 return false;
2331 }
2332
2333 *masked = isr & ATH9K_INT_COMMON;
2334
Sujith0ce024c2009-12-14 14:57:00 +05302335 if (ah->config.rx_intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002336 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
2337 *masked |= ATH9K_INT_RX;
2338 }
2339
2340 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
2341 *masked |= ATH9K_INT_RX;
2342 if (isr &
2343 (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
2344 AR_ISR_TXEOL)) {
2345 u32 s0_s, s1_s;
2346
2347 *masked |= ATH9K_INT_TX;
2348
2349 s0_s = REG_READ(ah, AR_ISR_S0_S);
Sujith2660b812009-02-09 13:27:26 +05302350 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
2351 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002352
2353 s1_s = REG_READ(ah, AR_ISR_S1_S);
Sujith2660b812009-02-09 13:27:26 +05302354 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
2355 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002356 }
2357
2358 if (isr & AR_ISR_RXORN) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002359 ath_print(common, ATH_DBG_INTERRUPT,
2360 "receive FIFO overrun interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002361 }
2362
2363 if (!AR_SREV_9100(ah)) {
Sujith60b67f52008-08-07 10:52:38 +05302364 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002365 u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
2366 if (isr5 & AR_ISR_S5_TIM_TIMER)
2367 *masked |= ATH9K_INT_TIM_TIMER;
2368 }
2369 }
2370
2371 *masked |= mask2;
2372 }
Sujithf1dc5602008-10-29 10:16:30 +05302373
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002374 if (AR_SREV_9100(ah))
2375 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302376
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302377 if (isr & AR_ISR_GENTMR) {
2378 u32 s5_s;
2379
2380 s5_s = REG_READ(ah, AR_ISR_S5_S);
2381 if (isr & AR_ISR_GENTMR) {
2382 ah->intr_gen_timer_trigger =
2383 MS(s5_s, AR_ISR_S5_GENTIMER_TRIG);
2384
2385 ah->intr_gen_timer_thresh =
2386 MS(s5_s, AR_ISR_S5_GENTIMER_THRESH);
2387
2388 if (ah->intr_gen_timer_trigger)
2389 *masked |= ATH9K_INT_GENTIMER;
2390
2391 }
2392 }
2393
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002394 if (sync_cause) {
2395 fatal_int =
2396 (sync_cause &
2397 (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
2398 ? true : false;
2399
2400 if (fatal_int) {
2401 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002402 ath_print(common, ATH_DBG_ANY,
2403 "received PCI FATAL interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002404 }
2405 if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002406 ath_print(common, ATH_DBG_ANY,
2407 "received PCI PERR interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002408 }
Steven Luoa89bff92009-04-12 02:57:54 -07002409 *masked |= ATH9K_INT_FATAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002410 }
2411 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002412 ath_print(common, ATH_DBG_INTERRUPT,
2413 "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002414 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
2415 REG_WRITE(ah, AR_RC, 0);
2416 *masked |= ATH9K_INT_FATAL;
2417 }
2418 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002419 ath_print(common, ATH_DBG_INTERRUPT,
2420 "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002421 }
2422
2423 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
2424 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
2425 }
Sujithf1dc5602008-10-29 10:16:30 +05302426
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002427 return true;
2428}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002429EXPORT_SYMBOL(ath9k_hw_getisr);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002430
Sujithcbe61d82009-02-09 13:27:12 +05302431enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002432{
Pavel Roskin152d5302010-03-31 18:05:37 -04002433 enum ath9k_int omask = ah->imask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002434 u32 mask, mask2;
Sujith2660b812009-02-09 13:27:26 +05302435 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002436 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002437
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002438 ath_print(common, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002439
2440 if (omask & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002441 ath_print(common, ATH_DBG_INTERRUPT, "disable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002442 REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
2443 (void) REG_READ(ah, AR_IER);
2444 if (!AR_SREV_9100(ah)) {
2445 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
2446 (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
2447
2448 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
2449 (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
2450 }
2451 }
2452
2453 mask = ints & ATH9K_INT_COMMON;
2454 mask2 = 0;
2455
2456 if (ints & ATH9K_INT_TX) {
Sujith2660b812009-02-09 13:27:26 +05302457 if (ah->txok_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002458 mask |= AR_IMR_TXOK;
Sujith2660b812009-02-09 13:27:26 +05302459 if (ah->txdesc_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002460 mask |= AR_IMR_TXDESC;
Sujith2660b812009-02-09 13:27:26 +05302461 if (ah->txerr_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002462 mask |= AR_IMR_TXERR;
Sujith2660b812009-02-09 13:27:26 +05302463 if (ah->txeol_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002464 mask |= AR_IMR_TXEOL;
2465 }
2466 if (ints & ATH9K_INT_RX) {
2467 mask |= AR_IMR_RXERR;
Sujith0ce024c2009-12-14 14:57:00 +05302468 if (ah->config.rx_intr_mitigation)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002469 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
2470 else
2471 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
Sujith60b67f52008-08-07 10:52:38 +05302472 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002473 mask |= AR_IMR_GENTMR;
2474 }
2475
2476 if (ints & (ATH9K_INT_BMISC)) {
2477 mask |= AR_IMR_BCNMISC;
2478 if (ints & ATH9K_INT_TIM)
2479 mask2 |= AR_IMR_S2_TIM;
2480 if (ints & ATH9K_INT_DTIM)
2481 mask2 |= AR_IMR_S2_DTIM;
2482 if (ints & ATH9K_INT_DTIMSYNC)
2483 mask2 |= AR_IMR_S2_DTIMSYNC;
2484 if (ints & ATH9K_INT_CABEND)
Sujith4af9cf42009-02-12 10:06:47 +05302485 mask2 |= AR_IMR_S2_CABEND;
2486 if (ints & ATH9K_INT_TSFOOR)
2487 mask2 |= AR_IMR_S2_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002488 }
2489
2490 if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
2491 mask |= AR_IMR_BCNMISC;
2492 if (ints & ATH9K_INT_GTT)
2493 mask2 |= AR_IMR_S2_GTT;
2494 if (ints & ATH9K_INT_CST)
2495 mask2 |= AR_IMR_S2_CST;
2496 }
2497
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002498 ath_print(common, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002499 REG_WRITE(ah, AR_IMR, mask);
Pavel Roskin74bad5c2010-02-23 18:15:27 -05002500 ah->imrs2_reg &= ~(AR_IMR_S2_TIM | AR_IMR_S2_DTIM | AR_IMR_S2_DTIMSYNC |
2501 AR_IMR_S2_CABEND | AR_IMR_S2_CABTO |
2502 AR_IMR_S2_TSFOOR | AR_IMR_S2_GTT | AR_IMR_S2_CST);
2503 ah->imrs2_reg |= mask2;
2504 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002505
Sujith60b67f52008-08-07 10:52:38 +05302506 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002507 if (ints & ATH9K_INT_TIM_TIMER)
2508 REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
2509 else
2510 REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
2511 }
2512
2513 if (ints & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002514 ath_print(common, ATH_DBG_INTERRUPT, "enable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002515 REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
2516 if (!AR_SREV_9100(ah)) {
2517 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
2518 AR_INTR_MAC_IRQ);
2519 REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
2520
2521
2522 REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
2523 AR_INTR_SYNC_DEFAULT);
2524 REG_WRITE(ah, AR_INTR_SYNC_MASK,
2525 AR_INTR_SYNC_DEFAULT);
2526 }
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002527 ath_print(common, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
2528 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002529 }
2530
2531 return omask;
2532}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002533EXPORT_SYMBOL(ath9k_hw_set_interrupts);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002534
Sujithf1dc5602008-10-29 10:16:30 +05302535/*******************/
2536/* Beacon Handling */
2537/*******************/
2538
Sujithcbe61d82009-02-09 13:27:12 +05302539void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002540{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002541 int flags = 0;
2542
Sujith2660b812009-02-09 13:27:26 +05302543 ah->beacon_interval = beacon_period;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002544
Sujith2660b812009-02-09 13:27:26 +05302545 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08002546 case NL80211_IFTYPE_STATION:
2547 case NL80211_IFTYPE_MONITOR:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002548 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
2549 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
2550 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
2551 flags |= AR_TBTT_TIMER_EN;
2552 break;
Colin McCabed97809d2008-12-01 13:38:55 -08002553 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04002554 case NL80211_IFTYPE_MESH_POINT:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002555 REG_SET_BIT(ah, AR_TXCFG,
2556 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
2557 REG_WRITE(ah, AR_NEXT_NDP_TIMER,
2558 TU_TO_USEC(next_beacon +
Sujith2660b812009-02-09 13:27:26 +05302559 (ah->atim_window ? ah->
2560 atim_window : 1)));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002561 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08002562 case NL80211_IFTYPE_AP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002563 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
2564 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
2565 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05302566 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302567 dma_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002568 REG_WRITE(ah, AR_NEXT_SWBA,
2569 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05302570 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302571 sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002572 flags |=
2573 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
2574 break;
Colin McCabed97809d2008-12-01 13:38:55 -08002575 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002576 ath_print(ath9k_hw_common(ah), ATH_DBG_BEACON,
2577 "%s: unsupported opmode: %d\n",
2578 __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08002579 return;
2580 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002581 }
2582
2583 REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
2584 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
2585 REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
2586 REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
2587
2588 beacon_period &= ~ATH9K_BEACON_ENA;
2589 if (beacon_period & ATH9K_BEACON_RESET_TSF) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002590 ath9k_hw_reset_tsf(ah);
2591 }
2592
2593 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
2594}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002595EXPORT_SYMBOL(ath9k_hw_beaconinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002596
Sujithcbe61d82009-02-09 13:27:12 +05302597void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05302598 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002599{
2600 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05302601 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002602 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002603
2604 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
2605
2606 REG_WRITE(ah, AR_BEACON_PERIOD,
2607 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
2608 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
2609 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
2610
2611 REG_RMW_FIELD(ah, AR_RSSI_THR,
2612 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
2613
2614 beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
2615
2616 if (bs->bs_sleepduration > beaconintval)
2617 beaconintval = bs->bs_sleepduration;
2618
2619 dtimperiod = bs->bs_dtimperiod;
2620 if (bs->bs_sleepduration > dtimperiod)
2621 dtimperiod = bs->bs_sleepduration;
2622
2623 if (beaconintval == dtimperiod)
2624 nextTbtt = bs->bs_nextdtim;
2625 else
2626 nextTbtt = bs->bs_nexttbtt;
2627
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002628 ath_print(common, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
2629 ath_print(common, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
2630 ath_print(common, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
2631 ath_print(common, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002632
2633 REG_WRITE(ah, AR_NEXT_DTIM,
2634 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
2635 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
2636
2637 REG_WRITE(ah, AR_SLEEP1,
2638 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
2639 | AR_SLEEP1_ASSUME_DTIM);
2640
Sujith60b67f52008-08-07 10:52:38 +05302641 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002642 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
2643 else
2644 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
2645
2646 REG_WRITE(ah, AR_SLEEP2,
2647 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
2648
2649 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
2650 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
2651
2652 REG_SET_BIT(ah, AR_TIMER_MODE,
2653 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
2654 AR_DTIM_TIMER_EN);
2655
Sujith4af9cf42009-02-12 10:06:47 +05302656 /* TSF Out of Range Threshold */
2657 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002658}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002659EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002660
Sujithf1dc5602008-10-29 10:16:30 +05302661/*******************/
2662/* HW Capabilities */
2663/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002664
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002665int ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002666{
Sujith2660b812009-02-09 13:27:26 +05302667 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002668 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002669 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002670 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002671
Sujithf1dc5602008-10-29 10:16:30 +05302672 u16 capField = 0, eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002673
Sujithf74df6f2009-02-09 13:27:24 +05302674 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002675 regulatory->current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05302676
Sujithf74df6f2009-02-09 13:27:24 +05302677 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
Sujithfec0de12009-02-12 10:06:43 +05302678 if (AR_SREV_9285_10_OR_LATER(ah))
2679 eeval |= AR9285_RDEXT_DEFAULT;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002680 regulatory->current_rd_ext = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05302681
Sujithf74df6f2009-02-09 13:27:24 +05302682 capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
Sujithf1dc5602008-10-29 10:16:30 +05302683
Sujith2660b812009-02-09 13:27:26 +05302684 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05302685 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002686 if (regulatory->current_rd == 0x64 ||
2687 regulatory->current_rd == 0x65)
2688 regulatory->current_rd += 5;
2689 else if (regulatory->current_rd == 0x41)
2690 regulatory->current_rd = 0x43;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002691 ath_print(common, ATH_DBG_REGULATORY,
2692 "regdomain mapped to 0x%x\n", regulatory->current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002693 }
Sujithdc2222a2008-08-14 13:26:55 +05302694
Sujithf74df6f2009-02-09 13:27:24 +05302695 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002696 if ((eeval & (AR5416_OPFLAGS_11G | AR5416_OPFLAGS_11A)) == 0) {
2697 ath_print(common, ATH_DBG_FATAL,
2698 "no band has been marked as supported in EEPROM.\n");
2699 return -EINVAL;
2700 }
2701
Sujithf1dc5602008-10-29 10:16:30 +05302702 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002703
Sujithf1dc5602008-10-29 10:16:30 +05302704 if (eeval & AR5416_OPFLAGS_11A) {
2705 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05302706 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05302707 if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
2708 set_bit(ATH9K_MODE_11NA_HT20,
2709 pCap->wireless_modes);
2710 if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
2711 set_bit(ATH9K_MODE_11NA_HT40PLUS,
2712 pCap->wireless_modes);
2713 set_bit(ATH9K_MODE_11NA_HT40MINUS,
2714 pCap->wireless_modes);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002715 }
2716 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002717 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002718
Sujithf1dc5602008-10-29 10:16:30 +05302719 if (eeval & AR5416_OPFLAGS_11G) {
Sujithf1dc5602008-10-29 10:16:30 +05302720 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05302721 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05302722 if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
2723 set_bit(ATH9K_MODE_11NG_HT20,
2724 pCap->wireless_modes);
2725 if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
2726 set_bit(ATH9K_MODE_11NG_HT40PLUS,
2727 pCap->wireless_modes);
2728 set_bit(ATH9K_MODE_11NG_HT40MINUS,
2729 pCap->wireless_modes);
2730 }
2731 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002732 }
Sujithf1dc5602008-10-29 10:16:30 +05302733
Sujithf74df6f2009-02-09 13:27:24 +05302734 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002735 /*
2736 * For AR9271 we will temporarilly uses the rx chainmax as read from
2737 * the EEPROM.
2738 */
Sujith8147f5d2009-02-20 15:13:23 +05302739 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002740 !(eeval & AR5416_OPFLAGS_11A) &&
2741 !(AR_SREV_9271(ah)))
2742 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
Sujith8147f5d2009-02-20 15:13:23 +05302743 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
2744 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002745 /* Use rx_chainmask from EEPROM. */
Sujith8147f5d2009-02-20 15:13:23 +05302746 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05302747
Sujithd535a422009-02-09 13:27:06 +05302748 if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0)))
Sujith2660b812009-02-09 13:27:26 +05302749 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05302750
2751 pCap->low_2ghz_chan = 2312;
2752 pCap->high_2ghz_chan = 2732;
2753
2754 pCap->low_5ghz_chan = 4920;
2755 pCap->high_5ghz_chan = 6100;
2756
2757 pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
2758 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
2759 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
2760
2761 pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
2762 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
2763 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
2764
Sujith2660b812009-02-09 13:27:26 +05302765 if (ah->config.ht_enable)
Sujithf1dc5602008-10-29 10:16:30 +05302766 pCap->hw_caps |= ATH9K_HW_CAP_HT;
2767 else
2768 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
2769
2770 pCap->hw_caps |= ATH9K_HW_CAP_GTT;
2771 pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
2772 pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
2773 pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
2774
2775 if (capField & AR_EEPROM_EEPCAP_MAXQCU)
2776 pCap->total_queues =
2777 MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
2778 else
2779 pCap->total_queues = ATH9K_NUM_TX_QUEUES;
2780
2781 if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
2782 pCap->keycache_size =
2783 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
2784 else
2785 pCap->keycache_size = AR_KEYTABLE_SIZE;
2786
2787 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -05002788
2789 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
2790 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD >> 1;
2791 else
2792 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
Sujithf1dc5602008-10-29 10:16:30 +05302793
Sujith5b5fa352010-03-17 14:25:15 +05302794 if (AR_SREV_9271(ah))
2795 pCap->num_gpio_pins = AR9271_NUM_GPIO;
2796 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302797 pCap->num_gpio_pins = AR9285_NUM_GPIO;
2798 else if (AR_SREV_9280_10_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302799 pCap->num_gpio_pins = AR928X_NUM_GPIO;
2800 else
2801 pCap->num_gpio_pins = AR_NUM_GPIO;
2802
Sujithf1dc5602008-10-29 10:16:30 +05302803 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
2804 pCap->hw_caps |= ATH9K_HW_CAP_CST;
2805 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
2806 } else {
2807 pCap->rts_aggr_limit = (8 * 1024);
2808 }
2809
2810 pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
2811
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05302812#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05302813 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
2814 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
2815 ah->rfkill_gpio =
2816 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
2817 ah->rfkill_polarity =
2818 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05302819
2820 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
2821 }
2822#endif
Vivek Natarajanbde748a2010-04-05 14:48:05 +05302823 if (AR_SREV_9271(ah))
2824 pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
2825 else
2826 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
Sujithf1dc5602008-10-29 10:16:30 +05302827
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302828 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302829 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
2830 else
2831 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
2832
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002833 if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) {
Sujithf1dc5602008-10-29 10:16:30 +05302834 pCap->reg_cap =
2835 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
2836 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
2837 AR_EEPROM_EEREGCAP_EN_KK_U2 |
2838 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
2839 } else {
2840 pCap->reg_cap =
2841 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
2842 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
2843 }
2844
Senthil Balasubramanianebb90cf2009-09-18 15:07:33 +05302845 /* Advertise midband for AR5416 with FCC midband set in eeprom */
2846 if (regulatory->current_rd_ext & (1 << REG_EXT_FCC_MIDBAND) &&
2847 AR_SREV_5416(ah))
2848 pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
Sujithf1dc5602008-10-29 10:16:30 +05302849
2850 pCap->num_antcfg_5ghz =
Sujithf74df6f2009-02-09 13:27:24 +05302851 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05302852 pCap->num_antcfg_2ghz =
Sujithf74df6f2009-02-09 13:27:24 +05302853 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05302854
Vasanthakumar Thiagarajanfe129462009-09-09 15:25:50 +05302855 if (AR_SREV_9280_10_OR_LATER(ah) &&
Luis R. Rodrigueza36cfbc2009-09-09 16:05:32 -07002856 ath9k_hw_btcoex_supported(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002857 btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO;
2858 btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO;
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05302859
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302860 if (AR_SREV_9285(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002861 btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
2862 btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302863 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002864 btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302865 }
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05302866 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002867 btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE;
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05302868 }
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002869
2870 return 0;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002871}
2872
Sujithcbe61d82009-02-09 13:27:12 +05302873bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05302874 u32 capability, u32 *result)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002875{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002876 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302877 switch (type) {
2878 case ATH9K_CAP_CIPHER:
2879 switch (capability) {
2880 case ATH9K_CIPHER_AES_CCM:
2881 case ATH9K_CIPHER_AES_OCB:
2882 case ATH9K_CIPHER_TKIP:
2883 case ATH9K_CIPHER_WEP:
2884 case ATH9K_CIPHER_MIC:
2885 case ATH9K_CIPHER_CLR:
2886 return true;
2887 default:
2888 return false;
2889 }
2890 case ATH9K_CAP_TKIP_MIC:
2891 switch (capability) {
2892 case 0:
2893 return true;
2894 case 1:
Sujith2660b812009-02-09 13:27:26 +05302895 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05302896 AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
2897 false;
2898 }
2899 case ATH9K_CAP_TKIP_SPLIT:
Sujith2660b812009-02-09 13:27:26 +05302900 return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ?
Sujithf1dc5602008-10-29 10:16:30 +05302901 false : true;
Sujithf1dc5602008-10-29 10:16:30 +05302902 case ATH9K_CAP_MCAST_KEYSRCH:
2903 switch (capability) {
2904 case 0:
2905 return true;
2906 case 1:
2907 if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
2908 return false;
2909 } else {
Sujith2660b812009-02-09 13:27:26 +05302910 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05302911 AR_STA_ID1_MCAST_KSRCH) ? true :
2912 false;
2913 }
2914 }
2915 return false;
Sujithf1dc5602008-10-29 10:16:30 +05302916 case ATH9K_CAP_TXPOW:
2917 switch (capability) {
2918 case 0:
2919 return 0;
2920 case 1:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002921 *result = regulatory->power_limit;
Sujithf1dc5602008-10-29 10:16:30 +05302922 return 0;
2923 case 2:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002924 *result = regulatory->max_power_level;
Sujithf1dc5602008-10-29 10:16:30 +05302925 return 0;
2926 case 3:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002927 *result = regulatory->tp_scale;
Sujithf1dc5602008-10-29 10:16:30 +05302928 return 0;
2929 }
2930 return false;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05302931 case ATH9K_CAP_DS:
2932 return (AR_SREV_9280_20_OR_LATER(ah) &&
2933 (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1))
2934 ? false : true;
Sujithf1dc5602008-10-29 10:16:30 +05302935 default:
2936 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002937 }
Sujithf1dc5602008-10-29 10:16:30 +05302938}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002939EXPORT_SYMBOL(ath9k_hw_getcapability);
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002940
Sujithcbe61d82009-02-09 13:27:12 +05302941bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05302942 u32 capability, u32 setting, int *status)
2943{
Sujithf1dc5602008-10-29 10:16:30 +05302944 switch (type) {
2945 case ATH9K_CAP_TKIP_MIC:
2946 if (setting)
Sujith2660b812009-02-09 13:27:26 +05302947 ah->sta_id1_defaults |=
Sujithf1dc5602008-10-29 10:16:30 +05302948 AR_STA_ID1_CRPT_MIC_ENABLE;
2949 else
Sujith2660b812009-02-09 13:27:26 +05302950 ah->sta_id1_defaults &=
Sujithf1dc5602008-10-29 10:16:30 +05302951 ~AR_STA_ID1_CRPT_MIC_ENABLE;
2952 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302953 case ATH9K_CAP_MCAST_KEYSRCH:
2954 if (setting)
Sujith2660b812009-02-09 13:27:26 +05302955 ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05302956 else
Sujith2660b812009-02-09 13:27:26 +05302957 ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05302958 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302959 default:
2960 return false;
2961 }
2962}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002963EXPORT_SYMBOL(ath9k_hw_setcapability);
Sujithf1dc5602008-10-29 10:16:30 +05302964
2965/****************************/
2966/* GPIO / RFKILL / Antennae */
2967/****************************/
2968
Sujithcbe61d82009-02-09 13:27:12 +05302969static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05302970 u32 gpio, u32 type)
2971{
2972 int addr;
2973 u32 gpio_shift, tmp;
2974
2975 if (gpio > 11)
2976 addr = AR_GPIO_OUTPUT_MUX3;
2977 else if (gpio > 5)
2978 addr = AR_GPIO_OUTPUT_MUX2;
2979 else
2980 addr = AR_GPIO_OUTPUT_MUX1;
2981
2982 gpio_shift = (gpio % 6) * 5;
2983
2984 if (AR_SREV_9280_20_OR_LATER(ah)
2985 || (addr != AR_GPIO_OUTPUT_MUX1)) {
2986 REG_RMW(ah, addr, (type << gpio_shift),
2987 (0x1f << gpio_shift));
2988 } else {
2989 tmp = REG_READ(ah, addr);
2990 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
2991 tmp &= ~(0x1f << gpio_shift);
2992 tmp |= (type << gpio_shift);
2993 REG_WRITE(ah, addr, tmp);
2994 }
2995}
2996
Sujithcbe61d82009-02-09 13:27:12 +05302997void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05302998{
2999 u32 gpio_shift;
3000
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07003001 BUG_ON(gpio >= ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05303002
3003 gpio_shift = gpio << 1;
3004
3005 REG_RMW(ah,
3006 AR_GPIO_OE_OUT,
3007 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
3008 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3009}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003010EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
Sujithf1dc5602008-10-29 10:16:30 +05303011
Sujithcbe61d82009-02-09 13:27:12 +05303012u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303013{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303014#define MS_REG_READ(x, y) \
3015 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
3016
Sujith2660b812009-02-09 13:27:26 +05303017 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05303018 return 0xffffffff;
3019
Felix Fietkau783dfca2010-04-15 17:38:11 -04003020 if (AR_SREV_9300_20_OR_LATER(ah))
3021 return MS_REG_READ(AR9300, gpio) != 0;
3022 else if (AR_SREV_9271(ah))
Sujith5b5fa352010-03-17 14:25:15 +05303023 return MS_REG_READ(AR9271, gpio) != 0;
3024 else if (AR_SREV_9287_10_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05303025 return MS_REG_READ(AR9287, gpio) != 0;
3026 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303027 return MS_REG_READ(AR9285, gpio) != 0;
3028 else if (AR_SREV_9280_10_OR_LATER(ah))
3029 return MS_REG_READ(AR928X, gpio) != 0;
3030 else
3031 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05303032}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003033EXPORT_SYMBOL(ath9k_hw_gpio_get);
Sujithf1dc5602008-10-29 10:16:30 +05303034
Sujithcbe61d82009-02-09 13:27:12 +05303035void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05303036 u32 ah_signal_type)
3037{
3038 u32 gpio_shift;
3039
3040 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
3041
3042 gpio_shift = 2 * gpio;
3043
3044 REG_RMW(ah,
3045 AR_GPIO_OE_OUT,
3046 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
3047 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3048}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003049EXPORT_SYMBOL(ath9k_hw_cfg_output);
Sujithf1dc5602008-10-29 10:16:30 +05303050
Sujithcbe61d82009-02-09 13:27:12 +05303051void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05303052{
Sujith5b5fa352010-03-17 14:25:15 +05303053 if (AR_SREV_9271(ah))
3054 val = ~val;
3055
Sujithf1dc5602008-10-29 10:16:30 +05303056 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
3057 AR_GPIO_BIT(gpio));
3058}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003059EXPORT_SYMBOL(ath9k_hw_set_gpio);
Sujithf1dc5602008-10-29 10:16:30 +05303060
Sujithcbe61d82009-02-09 13:27:12 +05303061u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303062{
3063 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
3064}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003065EXPORT_SYMBOL(ath9k_hw_getdefantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303066
Sujithcbe61d82009-02-09 13:27:12 +05303067void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05303068{
3069 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
3070}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003071EXPORT_SYMBOL(ath9k_hw_setantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303072
Sujithf1dc5602008-10-29 10:16:30 +05303073/*********************/
3074/* General Operation */
3075/*********************/
3076
Sujithcbe61d82009-02-09 13:27:12 +05303077u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303078{
3079 u32 bits = REG_READ(ah, AR_RX_FILTER);
3080 u32 phybits = REG_READ(ah, AR_PHY_ERR);
3081
3082 if (phybits & AR_PHY_ERR_RADAR)
3083 bits |= ATH9K_RX_FILTER_PHYRADAR;
3084 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
3085 bits |= ATH9K_RX_FILTER_PHYERR;
3086
3087 return bits;
3088}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003089EXPORT_SYMBOL(ath9k_hw_getrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303090
Sujithcbe61d82009-02-09 13:27:12 +05303091void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05303092{
3093 u32 phybits;
3094
Sujith7ea310b2009-09-03 12:08:43 +05303095 REG_WRITE(ah, AR_RX_FILTER, bits);
3096
Sujithf1dc5602008-10-29 10:16:30 +05303097 phybits = 0;
3098 if (bits & ATH9K_RX_FILTER_PHYRADAR)
3099 phybits |= AR_PHY_ERR_RADAR;
3100 if (bits & ATH9K_RX_FILTER_PHYERR)
3101 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
3102 REG_WRITE(ah, AR_PHY_ERR, phybits);
3103
3104 if (phybits)
3105 REG_WRITE(ah, AR_RXCFG,
3106 REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
3107 else
3108 REG_WRITE(ah, AR_RXCFG,
3109 REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
3110}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003111EXPORT_SYMBOL(ath9k_hw_setrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303112
Sujithcbe61d82009-02-09 13:27:12 +05303113bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303114{
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05303115 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
3116 return false;
3117
3118 ath9k_hw_init_pll(ah, NULL);
3119 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303120}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003121EXPORT_SYMBOL(ath9k_hw_phy_disable);
Sujithf1dc5602008-10-29 10:16:30 +05303122
Sujithcbe61d82009-02-09 13:27:12 +05303123bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303124{
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07003125 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05303126 return false;
3127
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05303128 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
3129 return false;
3130
3131 ath9k_hw_init_pll(ah, NULL);
3132 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303133}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003134EXPORT_SYMBOL(ath9k_hw_disable);
Sujithf1dc5602008-10-29 10:16:30 +05303135
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003136void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
Sujithf1dc5602008-10-29 10:16:30 +05303137{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003138 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujith2660b812009-02-09 13:27:26 +05303139 struct ath9k_channel *chan = ah->curchan;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08003140 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05303141
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003142 regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER);
Sujithf1dc5602008-10-29 10:16:30 +05303143
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003144 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003145 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003146 channel->max_antenna_gain * 2,
3147 channel->max_power * 2,
3148 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003149 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05303150}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003151EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
Sujithf1dc5602008-10-29 10:16:30 +05303152
Sujithcbe61d82009-02-09 13:27:12 +05303153void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac)
Sujithf1dc5602008-10-29 10:16:30 +05303154{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07003155 memcpy(ath9k_hw_common(ah)->macaddr, mac, ETH_ALEN);
Sujithf1dc5602008-10-29 10:16:30 +05303156}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003157EXPORT_SYMBOL(ath9k_hw_setmac);
Sujithf1dc5602008-10-29 10:16:30 +05303158
Sujithcbe61d82009-02-09 13:27:12 +05303159void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303160{
Sujith2660b812009-02-09 13:27:26 +05303161 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05303162}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003163EXPORT_SYMBOL(ath9k_hw_setopmode);
Sujithf1dc5602008-10-29 10:16:30 +05303164
Sujithcbe61d82009-02-09 13:27:12 +05303165void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05303166{
3167 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
3168 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
3169}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003170EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303171
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07003172void ath9k_hw_write_associd(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303173{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07003174 struct ath_common *common = ath9k_hw_common(ah);
3175
3176 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
3177 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
3178 ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05303179}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003180EXPORT_SYMBOL(ath9k_hw_write_associd);
Sujithf1dc5602008-10-29 10:16:30 +05303181
Sujithcbe61d82009-02-09 13:27:12 +05303182u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303183{
3184 u64 tsf;
3185
3186 tsf = REG_READ(ah, AR_TSF_U32);
3187 tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
3188
3189 return tsf;
3190}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003191EXPORT_SYMBOL(ath9k_hw_gettsf64);
Sujithf1dc5602008-10-29 10:16:30 +05303192
Sujithcbe61d82009-02-09 13:27:12 +05303193void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003194{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003195 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01003196 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003197}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003198EXPORT_SYMBOL(ath9k_hw_settsf64);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003199
Sujithcbe61d82009-02-09 13:27:12 +05303200void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303201{
Gabor Juhosf9b604f2009-06-21 00:02:15 +02003202 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
3203 AH_TSF_WRITE_TIMEOUT))
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003204 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
3205 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
Gabor Juhosf9b604f2009-06-21 00:02:15 +02003206
Sujithf1dc5602008-10-29 10:16:30 +05303207 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003208}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003209EXPORT_SYMBOL(ath9k_hw_reset_tsf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003210
Sujith54e4cec2009-08-07 09:45:09 +05303211void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003212{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003213 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303214 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003215 else
Sujith2660b812009-02-09 13:27:26 +05303216 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003217}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003218EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003219
Luis R. Rodriguez30cbd422009-11-03 16:10:46 -08003220/*
3221 * Extend 15-bit time stamp from rx descriptor to
3222 * a full 64-bit TSF using the current h/w TSF.
3223*/
3224u64 ath9k_hw_extend_tsf(struct ath_hw *ah, u32 rstamp)
3225{
3226 u64 tsf;
3227
3228 tsf = ath9k_hw_gettsf64(ah);
3229 if ((tsf & 0x7fff) < rstamp)
3230 tsf -= 0x8000;
3231 return (tsf & ~0x7fff) | rstamp;
3232}
3233EXPORT_SYMBOL(ath9k_hw_extend_tsf);
3234
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003235void ath9k_hw_set11nmac2040(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003236{
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003237 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithf1dc5602008-10-29 10:16:30 +05303238 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003239
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003240 if (conf_is_ht40(conf) && !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05303241 macmode = AR_2040_JOINED_RX_CLEAR;
3242 else
3243 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003244
Sujithf1dc5602008-10-29 10:16:30 +05303245 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003246}
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303247
3248/* HW Generic timers configuration */
3249
3250static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
3251{
3252 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3253 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3254 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3255 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3256 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3257 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3258 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3259 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3260 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
3261 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
3262 AR_NDP2_TIMER_MODE, 0x0002},
3263 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
3264 AR_NDP2_TIMER_MODE, 0x0004},
3265 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
3266 AR_NDP2_TIMER_MODE, 0x0008},
3267 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
3268 AR_NDP2_TIMER_MODE, 0x0010},
3269 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
3270 AR_NDP2_TIMER_MODE, 0x0020},
3271 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
3272 AR_NDP2_TIMER_MODE, 0x0040},
3273 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
3274 AR_NDP2_TIMER_MODE, 0x0080}
3275};
3276
3277/* HW generic timer primitives */
3278
3279/* compute and clear index of rightmost 1 */
3280static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
3281{
3282 u32 b;
3283
3284 b = *mask;
3285 b &= (0-b);
3286 *mask &= ~b;
3287 b *= debruijn32;
3288 b >>= 27;
3289
3290 return timer_table->gen_timer_index[b];
3291}
3292
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05303293u32 ath9k_hw_gettsf32(struct ath_hw *ah)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303294{
3295 return REG_READ(ah, AR_TSF_L32);
3296}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003297EXPORT_SYMBOL(ath9k_hw_gettsf32);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303298
3299struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
3300 void (*trigger)(void *),
3301 void (*overflow)(void *),
3302 void *arg,
3303 u8 timer_index)
3304{
3305 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3306 struct ath_gen_timer *timer;
3307
3308 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
3309
3310 if (timer == NULL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003311 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
3312 "Failed to allocate memory"
3313 "for hw timer[%d]\n", timer_index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303314 return NULL;
3315 }
3316
3317 /* allocate a hardware generic timer slot */
3318 timer_table->timers[timer_index] = timer;
3319 timer->index = timer_index;
3320 timer->trigger = trigger;
3321 timer->overflow = overflow;
3322 timer->arg = arg;
3323
3324 return timer;
3325}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003326EXPORT_SYMBOL(ath_gen_timer_alloc);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303327
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07003328void ath9k_hw_gen_timer_start(struct ath_hw *ah,
3329 struct ath_gen_timer *timer,
3330 u32 timer_next,
3331 u32 timer_period)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303332{
3333 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3334 u32 tsf;
3335
3336 BUG_ON(!timer_period);
3337
3338 set_bit(timer->index, &timer_table->timer_mask.timer_bits);
3339
3340 tsf = ath9k_hw_gettsf32(ah);
3341
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003342 ath_print(ath9k_hw_common(ah), ATH_DBG_HWTIMER,
3343 "curent tsf %x period %x"
3344 "timer_next %x\n", tsf, timer_period, timer_next);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303345
3346 /*
3347 * Pull timer_next forward if the current TSF already passed it
3348 * because of software latency
3349 */
3350 if (timer_next < tsf)
3351 timer_next = tsf + timer_period;
3352
3353 /*
3354 * Program generic timer registers
3355 */
3356 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
3357 timer_next);
3358 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
3359 timer_period);
3360 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
3361 gen_tmr_configuration[timer->index].mode_mask);
3362
3363 /* Enable both trigger and thresh interrupt masks */
3364 REG_SET_BIT(ah, AR_IMR_S5,
3365 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
3366 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303367}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003368EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303369
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07003370void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303371{
3372 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3373
3374 if ((timer->index < AR_FIRST_NDP_TIMER) ||
3375 (timer->index >= ATH_MAX_GEN_TIMER)) {
3376 return;
3377 }
3378
3379 /* Clear generic timer enable bits. */
3380 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
3381 gen_tmr_configuration[timer->index].mode_mask);
3382
3383 /* Disable both trigger and thresh interrupt masks */
3384 REG_CLR_BIT(ah, AR_IMR_S5,
3385 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
3386 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
3387
3388 clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303389}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003390EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303391
3392void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
3393{
3394 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3395
3396 /* free the hardware generic timer slot */
3397 timer_table->timers[timer->index] = NULL;
3398 kfree(timer);
3399}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003400EXPORT_SYMBOL(ath_gen_timer_free);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303401
3402/*
3403 * Generic Timer Interrupts handling
3404 */
3405void ath_gen_timer_isr(struct ath_hw *ah)
3406{
3407 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3408 struct ath_gen_timer *timer;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003409 struct ath_common *common = ath9k_hw_common(ah);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303410 u32 trigger_mask, thresh_mask, index;
3411
3412 /* get hardware generic timer interrupt status */
3413 trigger_mask = ah->intr_gen_timer_trigger;
3414 thresh_mask = ah->intr_gen_timer_thresh;
3415 trigger_mask &= timer_table->timer_mask.val;
3416 thresh_mask &= timer_table->timer_mask.val;
3417
3418 trigger_mask &= ~thresh_mask;
3419
3420 while (thresh_mask) {
3421 index = rightmost_index(timer_table, &thresh_mask);
3422 timer = timer_table->timers[index];
3423 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003424 ath_print(common, ATH_DBG_HWTIMER,
3425 "TSF overflow for Gen timer %d\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303426 timer->overflow(timer->arg);
3427 }
3428
3429 while (trigger_mask) {
3430 index = rightmost_index(timer_table, &trigger_mask);
3431 timer = timer_table->timers[index];
3432 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003433 ath_print(common, ATH_DBG_HWTIMER,
3434 "Gen timer[%d] trigger\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303435 timer->trigger(timer->arg);
3436 }
3437}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003438EXPORT_SYMBOL(ath_gen_timer_isr);
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003439
Sujith05020d22010-03-17 14:25:23 +05303440/********/
3441/* HTC */
3442/********/
3443
3444void ath9k_hw_htc_resetinit(struct ath_hw *ah)
3445{
3446 ah->htc_reset_init = true;
3447}
3448EXPORT_SYMBOL(ath9k_hw_htc_resetinit);
3449
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003450static struct {
3451 u32 version;
3452 const char * name;
3453} ath_mac_bb_names[] = {
3454 /* Devices with external radios */
3455 { AR_SREV_VERSION_5416_PCI, "5416" },
3456 { AR_SREV_VERSION_5416_PCIE, "5418" },
3457 { AR_SREV_VERSION_9100, "9100" },
3458 { AR_SREV_VERSION_9160, "9160" },
3459 /* Single-chip solutions */
3460 { AR_SREV_VERSION_9280, "9280" },
3461 { AR_SREV_VERSION_9285, "9285" },
Luis R. Rodriguez11158472009-10-27 12:59:35 -04003462 { AR_SREV_VERSION_9287, "9287" },
3463 { AR_SREV_VERSION_9271, "9271" },
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003464};
3465
3466/* For devices with external radios */
3467static struct {
3468 u16 version;
3469 const char * name;
3470} ath_rf_names[] = {
3471 { 0, "5133" },
3472 { AR_RAD5133_SREV_MAJOR, "5133" },
3473 { AR_RAD5122_SREV_MAJOR, "5122" },
3474 { AR_RAD2133_SREV_MAJOR, "2133" },
3475 { AR_RAD2122_SREV_MAJOR, "2122" }
3476};
3477
3478/*
3479 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
3480 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003481static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003482{
3483 int i;
3484
3485 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
3486 if (ath_mac_bb_names[i].version == mac_bb_version) {
3487 return ath_mac_bb_names[i].name;
3488 }
3489 }
3490
3491 return "????";
3492}
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003493
3494/*
3495 * Return the RF name. "????" is returned if the RF is unknown.
3496 * Used for devices with external radios.
3497 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003498static const char *ath9k_hw_rf_name(u16 rf_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003499{
3500 int i;
3501
3502 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
3503 if (ath_rf_names[i].version == rf_version) {
3504 return ath_rf_names[i].name;
3505 }
3506 }
3507
3508 return "????";
3509}
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003510
3511void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
3512{
3513 int used;
3514
3515 /* chipsets >= AR9280 are single-chip */
3516 if (AR_SREV_9280_10_OR_LATER(ah)) {
3517 used = snprintf(hw_name, len,
3518 "Atheros AR%s Rev:%x",
3519 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3520 ah->hw_version.macRev);
3521 }
3522 else {
3523 used = snprintf(hw_name, len,
3524 "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
3525 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3526 ah->hw_version.macRev,
3527 ath9k_hw_rf_name((ah->hw_version.analog5GhzRev &
3528 AR_RADIO_SREV_MAJOR)),
3529 ah->hw_version.phyRev);
3530 }
3531
3532 hw_name[used] = '\0';
3533}
3534EXPORT_SYMBOL(ath9k_hw_name);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04003535
3536/* Sets up the AR5008/AR9001/AR9002 hardware familiy callbacks */
3537static void ar9002_hw_attach_ops(struct ath_hw *ah)
3538{
3539 struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
3540 struct ath_hw_ops *ops = ath9k_hw_ops(ah);
3541
3542 priv_ops->init_cal_settings = ar9002_hw_init_cal_settings;
3543 priv_ops->init_mode_regs = ar9002_hw_init_mode_regs;
3544 priv_ops->macversion_supported = ar9002_hw_macversion_supported;
3545
3546 ops->config_pci_powersave = ar9002_hw_configpcipowersave;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04003547
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04003548 ar5008_hw_attach_phy_ops(ah);
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04003549 if (AR_SREV_9280_10_OR_LATER(ah))
3550 ar9002_hw_attach_phy_ops(ah);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04003551}
3552
3553/* Sets up the AR9003 hardware familiy callbacks */
3554static void ar9003_hw_attach_ops(struct ath_hw *ah)
3555{
Luis R. Rodriguez61accab2010-04-15 17:38:21 -04003556 struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
3557
3558 priv_ops->macversion_supported = ar9003_hw_macversion_supported;
3559
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04003560 ar9003_hw_attach_phy_ops(ah);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04003561}