blob: f057d1ad9290d2b12c67d45eefcdff9e76dd7346 [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. Rodriguez8df5d1b2009-08-03 12:24:37 -0700412 if (ah->hw_version.devid == AR5416_AR9100_DEVID)
Sujithd535a422009-02-09 13:27:06 +0530413 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700414 if (!AR_SREV_9100(ah))
415 ah->ah_flags = AH_USE_EEPROM;
416
Sujith2660b812009-02-09 13:27:26 +0530417 ah->atim_window = 0;
Sujith2660b812009-02-09 13:27:26 +0530418 ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
419 ah->beacon_interval = 100;
420 ah->enable_32kHz_clock = DONT_USE_32KHZ;
421 ah->slottime = (u32) -1;
Sujith2660b812009-02-09 13:27:26 +0530422 ah->globaltxtimeout = (u32) -1;
Gabor Juhoscbdec972009-07-24 17:27:22 +0200423 ah->power_mode = ATH9K_PM_UNDEFINED;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700424}
425
Sujithcbe61d82009-02-09 13:27:12 +0530426static int ath9k_hw_rf_claim(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700427{
428 u32 val;
429
430 REG_WRITE(ah, AR_PHY(0), 0x00000007);
431
432 val = ath9k_hw_get_radiorev(ah);
433 switch (val & AR_RADIO_SREV_MAJOR) {
434 case 0:
435 val = AR_RAD5133_SREV_MAJOR;
436 break;
437 case AR_RAD5133_SREV_MAJOR:
438 case AR_RAD5122_SREV_MAJOR:
439 case AR_RAD2133_SREV_MAJOR:
440 case AR_RAD2122_SREV_MAJOR:
441 break;
442 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700443 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
444 "Radio Chip Rev 0x%02X not supported\n",
445 val & AR_RADIO_SREV_MAJOR);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700446 return -EOPNOTSUPP;
447 }
448
Sujithd535a422009-02-09 13:27:06 +0530449 ah->hw_version.analog5GhzRev = val;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700450
451 return 0;
452}
453
Sujithcbe61d82009-02-09 13:27:12 +0530454static int ath9k_hw_init_macaddr(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700455{
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700456 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530457 u32 sum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700458 int i;
Sujithf1dc5602008-10-29 10:16:30 +0530459 u16 eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700460
Sujithf1dc5602008-10-29 10:16:30 +0530461 sum = 0;
462 for (i = 0; i < 3; i++) {
Sujithf74df6f2009-02-09 13:27:24 +0530463 eeval = ah->eep_ops->get_eeprom(ah, AR_EEPROM_MAC(i));
Sujithf1dc5602008-10-29 10:16:30 +0530464 sum += eeval;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700465 common->macaddr[2 * i] = eeval >> 8;
466 common->macaddr[2 * i + 1] = eeval & 0xff;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700467 }
Sujithd8baa932009-03-30 15:28:25 +0530468 if (sum == 0 || sum == 0xffff * 3)
Sujithf1dc5602008-10-29 10:16:30 +0530469 return -EADDRNOTAVAIL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700470
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700471 return 0;
472}
473
Sujithcbe61d82009-02-09 13:27:12 +0530474static void ath9k_hw_init_rxgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530475{
476 u32 rxgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530477
Sujithf74df6f2009-02-09 13:27:24 +0530478 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_17) {
479 rxgain_type = ah->eep_ops->get_eeprom(ah, EEP_RXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530480
481 if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530482 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530483 ar9280Modes_backoff_13db_rxgain_9280_2,
484 ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2), 6);
485 else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530486 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530487 ar9280Modes_backoff_23db_rxgain_9280_2,
488 ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 6);
489 else
Sujith2660b812009-02-09 13:27:26 +0530490 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530491 ar9280Modes_original_rxgain_9280_2,
492 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530493 } else {
Sujith2660b812009-02-09 13:27:26 +0530494 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530495 ar9280Modes_original_rxgain_9280_2,
496 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530497 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530498}
499
Sujithcbe61d82009-02-09 13:27:12 +0530500static void ath9k_hw_init_txgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530501{
502 u32 txgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530503
Sujithf74df6f2009-02-09 13:27:24 +0530504 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_19) {
505 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530506
507 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
Sujith2660b812009-02-09 13:27:26 +0530508 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530509 ar9280Modes_high_power_tx_gain_9280_2,
510 ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 6);
511 else
Sujith2660b812009-02-09 13:27:26 +0530512 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530513 ar9280Modes_original_tx_gain_9280_2,
514 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530515 } else {
Sujith2660b812009-02-09 13:27:26 +0530516 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530517 ar9280Modes_original_tx_gain_9280_2,
518 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530519 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530520}
521
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700522static int ath9k_hw_post_init(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700523{
524 int ecode;
525
Sujith527d4852010-03-17 14:25:16 +0530526 if (!AR_SREV_9271(ah)) {
527 if (!ath9k_hw_chip_test(ah))
528 return -ENODEV;
529 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700530
531 ecode = ath9k_hw_rf_claim(ah);
532 if (ecode != 0)
533 return ecode;
534
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700535 ecode = ath9k_hw_eeprom_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700536 if (ecode != 0)
537 return ecode;
Sujith7d01b222009-03-13 08:55:55 +0530538
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700539 ath_print(ath9k_hw_common(ah), ATH_DBG_CONFIG,
540 "Eeprom VER: %d, REV: %d\n",
541 ah->eep_ops->get_eeprom_ver(ah),
542 ah->eep_ops->get_eeprom_rev(ah));
Sujith7d01b222009-03-13 08:55:55 +0530543
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400544 ecode = ath9k_hw_rf_alloc_ext_banks(ah);
545 if (ecode) {
546 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
547 "Failed allocating banks for "
548 "external radio\n");
549 return ecode;
Luis R. Rodriguez574d6b12009-10-19 02:33:37 -0400550 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700551
552 if (!AR_SREV_9100(ah)) {
553 ath9k_hw_ani_setup(ah);
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700554 ath9k_hw_ani_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700555 }
Sujithf1dc5602008-10-29 10:16:30 +0530556
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700557 return 0;
558}
559
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400560static bool ar9002_hw_macversion_supported(u32 macversion)
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700561{
562 switch (macversion) {
563 case AR_SREV_VERSION_5416_PCI:
564 case AR_SREV_VERSION_5416_PCIE:
565 case AR_SREV_VERSION_9160:
566 case AR_SREV_VERSION_9100:
567 case AR_SREV_VERSION_9280:
568 case AR_SREV_VERSION_9285:
569 case AR_SREV_VERSION_9287:
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400570 case AR_SREV_VERSION_9271:
Luis R. Rodriguez7976b422009-09-23 23:07:02 -0400571 return true;
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700572 default:
573 break;
574 }
575 return false;
576}
577
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400578static void ar9002_hw_init_cal_settings(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700579{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700580 if (AR_SREV_9160_10_OR_LATER(ah)) {
581 if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530582 ah->iq_caldata.calData = &iq_cal_single_sample;
583 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700584 &adc_gain_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530585 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700586 &adc_dc_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530587 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700588 &adc_init_dc_cal;
589 } else {
Sujith2660b812009-02-09 13:27:26 +0530590 ah->iq_caldata.calData = &iq_cal_multi_sample;
591 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700592 &adc_gain_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530593 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700594 &adc_dc_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530595 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700596 &adc_init_dc_cal;
597 }
Sujith2660b812009-02-09 13:27:26 +0530598 ah->supp_cals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700599 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700600}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700601
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400602static void ar9002_hw_init_mode_regs(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700603{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400604 if (AR_SREV_9271(ah)) {
Luis R. Rodriguez85643282009-10-19 02:33:33 -0400605 INIT_INI_ARRAY(&ah->iniModes, ar9271Modes_9271,
606 ARRAY_SIZE(ar9271Modes_9271), 6);
607 INIT_INI_ARRAY(&ah->iniCommon, ar9271Common_9271,
608 ARRAY_SIZE(ar9271Common_9271), 2);
Sujith70807e92010-03-17 14:25:14 +0530609 INIT_INI_ARRAY(&ah->iniCommon_normal_cck_fir_coeff_9271,
610 ar9271Common_normal_cck_fir_coeff_9271,
611 ARRAY_SIZE(ar9271Common_normal_cck_fir_coeff_9271), 2);
612 INIT_INI_ARRAY(&ah->iniCommon_japan_2484_cck_fir_coeff_9271,
613 ar9271Common_japan_2484_cck_fir_coeff_9271,
614 ARRAY_SIZE(ar9271Common_japan_2484_cck_fir_coeff_9271), 2);
Luis R. Rodriguez85643282009-10-19 02:33:33 -0400615 INIT_INI_ARRAY(&ah->iniModes_9271_1_0_only,
616 ar9271Modes_9271_1_0_only,
617 ARRAY_SIZE(ar9271Modes_9271_1_0_only), 6);
Sujith70807e92010-03-17 14:25:14 +0530618 INIT_INI_ARRAY(&ah->iniModes_9271_ANI_reg, ar9271Modes_9271_ANI_reg,
619 ARRAY_SIZE(ar9271Modes_9271_ANI_reg), 6);
620 INIT_INI_ARRAY(&ah->iniModes_high_power_tx_gain_9271,
621 ar9271Modes_high_power_tx_gain_9271,
622 ARRAY_SIZE(ar9271Modes_high_power_tx_gain_9271), 6);
623 INIT_INI_ARRAY(&ah->iniModes_normal_power_tx_gain_9271,
624 ar9271Modes_normal_power_tx_gain_9271,
625 ARRAY_SIZE(ar9271Modes_normal_power_tx_gain_9271), 6);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400626 return;
627 }
628
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530629 if (AR_SREV_9287_11_OR_LATER(ah)) {
630 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_1,
631 ARRAY_SIZE(ar9287Modes_9287_1_1), 6);
632 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_1,
633 ARRAY_SIZE(ar9287Common_9287_1_1), 2);
634 if (ah->config.pcie_clock_req)
635 INIT_INI_ARRAY(&ah->iniPcieSerdes,
636 ar9287PciePhy_clkreq_off_L1_9287_1_1,
637 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_1), 2);
638 else
639 INIT_INI_ARRAY(&ah->iniPcieSerdes,
640 ar9287PciePhy_clkreq_always_on_L1_9287_1_1,
641 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_1),
642 2);
643 } else if (AR_SREV_9287_10_OR_LATER(ah)) {
644 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_0,
645 ARRAY_SIZE(ar9287Modes_9287_1_0), 6);
646 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_0,
647 ARRAY_SIZE(ar9287Common_9287_1_0), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700648
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530649 if (ah->config.pcie_clock_req)
650 INIT_INI_ARRAY(&ah->iniPcieSerdes,
651 ar9287PciePhy_clkreq_off_L1_9287_1_0,
652 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_0), 2);
653 else
654 INIT_INI_ARRAY(&ah->iniPcieSerdes,
655 ar9287PciePhy_clkreq_always_on_L1_9287_1_0,
656 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_0),
657 2);
658 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
659
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530660
Sujith2660b812009-02-09 13:27:26 +0530661 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530662 ARRAY_SIZE(ar9285Modes_9285_1_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530663 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530664 ARRAY_SIZE(ar9285Common_9285_1_2), 2);
665
Sujith2660b812009-02-09 13:27:26 +0530666 if (ah->config.pcie_clock_req) {
667 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530668 ar9285PciePhy_clkreq_off_L1_9285_1_2,
669 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2);
670 } else {
Sujith2660b812009-02-09 13:27:26 +0530671 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530672 ar9285PciePhy_clkreq_always_on_L1_9285_1_2,
673 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2),
674 2);
675 }
676 } else if (AR_SREV_9285_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530677 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530678 ARRAY_SIZE(ar9285Modes_9285), 6);
Sujith2660b812009-02-09 13:27:26 +0530679 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530680 ARRAY_SIZE(ar9285Common_9285), 2);
681
Sujith2660b812009-02-09 13:27:26 +0530682 if (ah->config.pcie_clock_req) {
683 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530684 ar9285PciePhy_clkreq_off_L1_9285,
685 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2);
686 } else {
Sujith2660b812009-02-09 13:27:26 +0530687 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530688 ar9285PciePhy_clkreq_always_on_L1_9285,
689 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285), 2);
690 }
691 } else if (AR_SREV_9280_20_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530692 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700693 ARRAY_SIZE(ar9280Modes_9280_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530694 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700695 ARRAY_SIZE(ar9280Common_9280_2), 2);
696
Sujith2660b812009-02-09 13:27:26 +0530697 if (ah->config.pcie_clock_req) {
698 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530699 ar9280PciePhy_clkreq_off_L1_9280,
700 ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700701 } else {
Sujith2660b812009-02-09 13:27:26 +0530702 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530703 ar9280PciePhy_clkreq_always_on_L1_9280,
704 ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700705 }
Sujith2660b812009-02-09 13:27:26 +0530706 INIT_INI_ARRAY(&ah->iniModesAdditional,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700707 ar9280Modes_fast_clock_9280_2,
Sujithf1dc5602008-10-29 10:16:30 +0530708 ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700709 } else if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530710 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700711 ARRAY_SIZE(ar9280Modes_9280), 6);
Sujith2660b812009-02-09 13:27:26 +0530712 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700713 ARRAY_SIZE(ar9280Common_9280), 2);
714 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530715 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700716 ARRAY_SIZE(ar5416Modes_9160), 6);
Sujith2660b812009-02-09 13:27:26 +0530717 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700718 ARRAY_SIZE(ar5416Common_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530719 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700720 ARRAY_SIZE(ar5416Bank0_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530721 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700722 ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530723 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700724 ARRAY_SIZE(ar5416Bank1_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530725 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700726 ARRAY_SIZE(ar5416Bank2_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530727 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700728 ARRAY_SIZE(ar5416Bank3_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530729 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700730 ARRAY_SIZE(ar5416Bank6_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530731 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700732 ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530733 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700734 ARRAY_SIZE(ar5416Bank7_9160), 2);
735 if (AR_SREV_9160_11(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530736 INIT_INI_ARRAY(&ah->iniAddac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700737 ar5416Addac_91601_1,
738 ARRAY_SIZE(ar5416Addac_91601_1), 2);
739 } else {
Sujith2660b812009-02-09 13:27:26 +0530740 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700741 ARRAY_SIZE(ar5416Addac_9160), 2);
742 }
743 } else if (AR_SREV_9100_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530744 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700745 ARRAY_SIZE(ar5416Modes_9100), 6);
Sujith2660b812009-02-09 13:27:26 +0530746 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700747 ARRAY_SIZE(ar5416Common_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530748 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700749 ARRAY_SIZE(ar5416Bank0_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530750 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700751 ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530752 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700753 ARRAY_SIZE(ar5416Bank1_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530754 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700755 ARRAY_SIZE(ar5416Bank2_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530756 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700757 ARRAY_SIZE(ar5416Bank3_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530758 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700759 ARRAY_SIZE(ar5416Bank6_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530760 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700761 ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530762 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700763 ARRAY_SIZE(ar5416Bank7_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530764 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700765 ARRAY_SIZE(ar5416Addac_9100), 2);
766 } else {
Sujith2660b812009-02-09 13:27:26 +0530767 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700768 ARRAY_SIZE(ar5416Modes), 6);
Sujith2660b812009-02-09 13:27:26 +0530769 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700770 ARRAY_SIZE(ar5416Common), 2);
Sujith2660b812009-02-09 13:27:26 +0530771 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700772 ARRAY_SIZE(ar5416Bank0), 2);
Sujith2660b812009-02-09 13:27:26 +0530773 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700774 ARRAY_SIZE(ar5416BB_RfGain), 3);
Sujith2660b812009-02-09 13:27:26 +0530775 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700776 ARRAY_SIZE(ar5416Bank1), 2);
Sujith2660b812009-02-09 13:27:26 +0530777 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700778 ARRAY_SIZE(ar5416Bank2), 2);
Sujith2660b812009-02-09 13:27:26 +0530779 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700780 ARRAY_SIZE(ar5416Bank3), 3);
Sujith2660b812009-02-09 13:27:26 +0530781 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700782 ARRAY_SIZE(ar5416Bank6), 3);
Sujith2660b812009-02-09 13:27:26 +0530783 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700784 ARRAY_SIZE(ar5416Bank6TPC), 3);
Sujith2660b812009-02-09 13:27:26 +0530785 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700786 ARRAY_SIZE(ar5416Bank7), 2);
Sujith2660b812009-02-09 13:27:26 +0530787 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700788 ARRAY_SIZE(ar5416Addac), 2);
789 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700790}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700791
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700792static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
793{
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530794 if (AR_SREV_9287_11_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530795 INIT_INI_ARRAY(&ah->iniModesRxGain,
796 ar9287Modes_rx_gain_9287_1_1,
797 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_1), 6);
798 else if (AR_SREV_9287_10(ah))
799 INIT_INI_ARRAY(&ah->iniModesRxGain,
800 ar9287Modes_rx_gain_9287_1_0,
801 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_0), 6);
802 else if (AR_SREV_9280_20(ah))
803 ath9k_hw_init_rxgain_ini(ah);
804
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530805 if (AR_SREV_9287_11_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530806 INIT_INI_ARRAY(&ah->iniModesTxGain,
807 ar9287Modes_tx_gain_9287_1_1,
808 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_1), 6);
809 } else if (AR_SREV_9287_10(ah)) {
810 INIT_INI_ARRAY(&ah->iniModesTxGain,
811 ar9287Modes_tx_gain_9287_1_0,
812 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_0), 6);
813 } else if (AR_SREV_9280_20(ah)) {
814 ath9k_hw_init_txgain_ini(ah);
815 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530816 u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
817
818 /* txgain table */
819 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) {
Vivek Natarajan53bc7aa2010-04-05 14:48:04 +0530820 if (AR_SREV_9285E_20(ah)) {
821 INIT_INI_ARRAY(&ah->iniModesTxGain,
822 ar9285Modes_XE2_0_high_power,
823 ARRAY_SIZE(
824 ar9285Modes_XE2_0_high_power), 6);
825 } else {
826 INIT_INI_ARRAY(&ah->iniModesTxGain,
827 ar9285Modes_high_power_tx_gain_9285_1_2,
828 ARRAY_SIZE(
829 ar9285Modes_high_power_tx_gain_9285_1_2), 6);
830 }
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530831 } else {
Vivek Natarajan53bc7aa2010-04-05 14:48:04 +0530832 if (AR_SREV_9285E_20(ah)) {
833 INIT_INI_ARRAY(&ah->iniModesTxGain,
834 ar9285Modes_XE2_0_normal_power,
835 ARRAY_SIZE(
836 ar9285Modes_XE2_0_normal_power), 6);
837 } else {
838 INIT_INI_ARRAY(&ah->iniModesTxGain,
839 ar9285Modes_original_tx_gain_9285_1_2,
840 ARRAY_SIZE(
841 ar9285Modes_original_tx_gain_9285_1_2), 6);
842 }
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530843 }
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530844 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700845}
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530846
Felix Fietkauaa8bc9e2010-01-23 20:04:18 +0100847static void ath9k_hw_init_eeprom_fix(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700848{
Pavel Roskin2eb46d92010-04-07 01:33:33 -0400849 struct base_eep_header *pBase = &(ah->eeprom.def.baseEepHeader);
850 struct ath_common *common = ath9k_hw_common(ah);
Sujith06d0f062009-02-12 10:06:45 +0530851
Pavel Roskin2eb46d92010-04-07 01:33:33 -0400852 ah->need_an_top2_fixup = (ah->hw_version.devid == AR9280_DEVID_PCI) &&
853 (ah->eep_map != EEP_MAP_4KBITS) &&
854 ((pBase->version & 0xff) > 0x0a) &&
855 (pBase->pwdclkind == 0);
Sujith06d0f062009-02-12 10:06:45 +0530856
Pavel Roskin2eb46d92010-04-07 01:33:33 -0400857 if (ah->need_an_top2_fixup)
858 ath_print(common, ATH_DBG_EEPROM,
859 "needs fixup for AR_AN_TOP2 register\n");
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700860}
861
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400862static void ath9k_hw_attach_ops(struct ath_hw *ah)
863{
864 if (AR_SREV_9300_20_OR_LATER(ah))
865 ar9003_hw_attach_ops(ah);
866 else
867 ar9002_hw_attach_ops(ah);
868}
869
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400870/* Called for all hardware families */
871static int __ath9k_hw_init(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700872{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700873 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700874 int r = 0;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700875
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700876 ath9k_hw_init_defaults(ah);
877 ath9k_hw_init_config(ah);
878
879 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700880 ath_print(common, ATH_DBG_FATAL,
881 "Couldn't reset chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700882 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700883 }
884
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400885 ath9k_hw_attach_ops(ah);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400886
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700887 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700888 ath_print(common, ATH_DBG_FATAL, "Couldn't wakeup chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700889 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700890 }
891
892 if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
893 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
894 (AR_SREV_9280(ah) && !ah->is_pciexpress)) {
895 ah->config.serialize_regmode =
896 SER_REG_MODE_ON;
897 } else {
898 ah->config.serialize_regmode =
899 SER_REG_MODE_OFF;
900 }
901 }
902
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700903 ath_print(common, ATH_DBG_RESET, "serialize_regmode is %d\n",
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700904 ah->config.serialize_regmode);
905
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -0500906 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
907 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD >> 1;
908 else
909 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD;
910
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400911 if (!ath9k_hw_macversion_supported(ah)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700912 ath_print(common, ATH_DBG_FATAL,
913 "Mac Chip Rev 0x%02x.%x is not supported by "
914 "this driver\n", ah->hw_version.macVersion,
915 ah->hw_version.macRev);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700916 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700917 }
918
919 if (AR_SREV_9100(ah)) {
920 ah->iq_caldata.calData = &iq_cal_multi_sample;
921 ah->supp_cals = IQ_MISMATCH_CAL;
922 ah->is_pciexpress = false;
923 }
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400924
925 if (AR_SREV_9271(ah))
926 ah->is_pciexpress = false;
927
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700928 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700929 ath9k_hw_init_cal_settings(ah);
930
931 ah->ani_function = ATH9K_ANI_ALL;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400932 if (AR_SREV_9280_10_OR_LATER(ah))
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700933 ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
934
935 ath9k_hw_init_mode_regs(ah);
936
937 if (ah->is_pciexpress)
Vivek Natarajan93b1b372009-09-17 09:24:58 +0530938 ath9k_hw_configpcipowersave(ah, 0, 0);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700939 else
940 ath9k_hw_disablepcie(ah);
941
Sujith193cd452009-09-18 15:04:07 +0530942 /* Support for Japan ch.14 (2484) spread */
943 if (AR_SREV_9287_11_OR_LATER(ah)) {
944 INIT_INI_ARRAY(&ah->iniCckfirNormal,
945 ar9287Common_normal_cck_fir_coeff_92871_1,
946 ARRAY_SIZE(ar9287Common_normal_cck_fir_coeff_92871_1), 2);
947 INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
948 ar9287Common_japan_2484_cck_fir_coeff_92871_1,
949 ARRAY_SIZE(ar9287Common_japan_2484_cck_fir_coeff_92871_1), 2);
950 }
951
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700952 r = ath9k_hw_post_init(ah);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700953 if (r)
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700954 return r;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700955
956 ath9k_hw_init_mode_gain_regs(ah);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +0100957 r = ath9k_hw_fill_cap_info(ah);
958 if (r)
959 return r;
960
Felix Fietkauaa8bc9e2010-01-23 20:04:18 +0100961 ath9k_hw_init_eeprom_fix(ah);
Sujithf6688cd2008-12-07 21:43:10 +0530962
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700963 r = ath9k_hw_init_macaddr(ah);
964 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700965 ath_print(common, ATH_DBG_FATAL,
966 "Failed to initialize MAC address\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700967 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700968 }
969
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400970 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
Sujith2660b812009-02-09 13:27:26 +0530971 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700972 else
Sujith2660b812009-02-09 13:27:26 +0530973 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700974
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700975 ath9k_init_nfcal_hist_buffer(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700976
Luis R. Rodriguez211f5852009-10-06 21:19:07 -0400977 common->state = ATH_HW_INITIALIZED;
978
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700979 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700980}
981
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400982int ath9k_hw_init(struct ath_hw *ah)
983{
984 int ret;
985 struct ath_common *common = ath9k_hw_common(ah);
986
987 /* These are all the AR5008/AR9001/AR9002 hardware family of chipsets */
988 switch (ah->hw_version.devid) {
989 case AR5416_DEVID_PCI:
990 case AR5416_DEVID_PCIE:
991 case AR5416_AR9100_DEVID:
992 case AR9160_DEVID_PCI:
993 case AR9280_DEVID_PCI:
994 case AR9280_DEVID_PCIE:
995 case AR9285_DEVID_PCIE:
Senthil Balasubramaniandb3cc532010-04-15 17:38:18 -0400996 case AR9287_DEVID_PCI:
997 case AR9287_DEVID_PCIE:
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400998 case AR2427_DEVID_PCIE:
Senthil Balasubramaniandb3cc532010-04-15 17:38:18 -0400999 case AR9300_DEVID_PCIE:
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04001000 break;
1001 default:
1002 if (common->bus_ops->ath_bus_type == ATH_USB)
1003 break;
1004 ath_print(common, ATH_DBG_FATAL,
1005 "Hardware device ID 0x%04x not supported\n",
1006 ah->hw_version.devid);
1007 return -EOPNOTSUPP;
1008 }
1009
1010 ret = __ath9k_hw_init(ah);
1011 if (ret) {
1012 ath_print(common, ATH_DBG_FATAL,
1013 "Unable to initialize hardware; "
1014 "initialization status: %d\n", ret);
1015 return ret;
1016 }
1017
1018 return 0;
1019}
1020EXPORT_SYMBOL(ath9k_hw_init);
1021
Sujithcbe61d82009-02-09 13:27:12 +05301022static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301023{
1024 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
1025 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
1026
1027 REG_WRITE(ah, AR_QOS_NO_ACK,
1028 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
1029 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
1030 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
1031
1032 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
1033 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
1034 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
1035 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
1036 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
1037}
1038
Sujithcbe61d82009-02-09 13:27:12 +05301039static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301040 struct ath9k_channel *chan)
1041{
Luis R. Rodriguez64773962010-04-15 17:38:17 -04001042 u32 pll = ath9k_hw_compute_pll_control(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301043
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001044 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +05301045
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -04001046 /* Switch the core clock for ar9271 to 117Mhz */
1047 if (AR_SREV_9271(ah)) {
Sujith25e2ab12010-03-17 14:25:22 +05301048 udelay(500);
1049 REG_WRITE(ah, 0x50040, 0x304);
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -04001050 }
1051
Sujithf1dc5602008-10-29 10:16:30 +05301052 udelay(RTC_PLL_SETTLE_DELAY);
1053
1054 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
1055}
1056
Sujithcbe61d82009-02-09 13:27:12 +05301057static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -08001058 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301059{
Pavel Roskin152d5302010-03-31 18:05:37 -04001060 u32 imr_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +05301061 AR_IMR_TXURN |
1062 AR_IMR_RXERR |
1063 AR_IMR_RXORN |
1064 AR_IMR_BCNMISC;
1065
Sujith0ce024c2009-12-14 14:57:00 +05301066 if (ah->config.rx_intr_mitigation)
Pavel Roskin152d5302010-03-31 18:05:37 -04001067 imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
Sujithf1dc5602008-10-29 10:16:30 +05301068 else
Pavel Roskin152d5302010-03-31 18:05:37 -04001069 imr_reg |= AR_IMR_RXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301070
Pavel Roskin152d5302010-03-31 18:05:37 -04001071 imr_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301072
Colin McCabed97809d2008-12-01 13:38:55 -08001073 if (opmode == NL80211_IFTYPE_AP)
Pavel Roskin152d5302010-03-31 18:05:37 -04001074 imr_reg |= AR_IMR_MIB;
Sujithf1dc5602008-10-29 10:16:30 +05301075
Pavel Roskin152d5302010-03-31 18:05:37 -04001076 REG_WRITE(ah, AR_IMR, imr_reg);
Pavel Roskin74bad5c2010-02-23 18:15:27 -05001077 ah->imrs2_reg |= AR_IMR_S2_GTT;
1078 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
Sujithf1dc5602008-10-29 10:16:30 +05301079
1080 if (!AR_SREV_9100(ah)) {
1081 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
1082 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
1083 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
1084 }
1085}
1086
Felix Fietkau0005baf2010-01-15 02:33:40 +01001087static void ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301088{
Felix Fietkau0005baf2010-01-15 02:33:40 +01001089 u32 val = ath9k_hw_mac_to_clks(ah, us);
1090 val = min(val, (u32) 0xFFFF);
1091 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, val);
Sujithf1dc5602008-10-29 10:16:30 +05301092}
1093
Felix Fietkau0005baf2010-01-15 02:33:40 +01001094static void ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301095{
Felix Fietkau0005baf2010-01-15 02:33:40 +01001096 u32 val = ath9k_hw_mac_to_clks(ah, us);
1097 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_ACK));
1098 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_ACK, val);
1099}
1100
1101static void ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
1102{
1103 u32 val = ath9k_hw_mac_to_clks(ah, us);
1104 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_CTS));
1105 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_CTS, val);
Sujithf1dc5602008-10-29 10:16:30 +05301106}
1107
Sujithcbe61d82009-02-09 13:27:12 +05301108static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +05301109{
Sujithf1dc5602008-10-29 10:16:30 +05301110 if (tu > 0xFFFF) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001111 ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT,
1112 "bad global tx timeout %u\n", tu);
Sujith2660b812009-02-09 13:27:26 +05301113 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301114 return false;
1115 } else {
1116 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +05301117 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +05301118 return true;
1119 }
1120}
1121
Felix Fietkau0005baf2010-01-15 02:33:40 +01001122void ath9k_hw_init_global_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301123{
Felix Fietkau0005baf2010-01-15 02:33:40 +01001124 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
1125 int acktimeout;
Felix Fietkaue239d852010-01-15 02:34:58 +01001126 int slottime;
Felix Fietkau0005baf2010-01-15 02:33:40 +01001127 int sifstime;
1128
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001129 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
1130 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +05301131
Sujith2660b812009-02-09 13:27:26 +05301132 if (ah->misc_mode != 0)
Sujithf1dc5602008-10-29 10:16:30 +05301133 REG_WRITE(ah, AR_PCU_MISC,
Sujith2660b812009-02-09 13:27:26 +05301134 REG_READ(ah, AR_PCU_MISC) | ah->misc_mode);
Felix Fietkau0005baf2010-01-15 02:33:40 +01001135
1136 if (conf->channel && conf->channel->band == IEEE80211_BAND_5GHZ)
1137 sifstime = 16;
1138 else
1139 sifstime = 10;
1140
Felix Fietkaue239d852010-01-15 02:34:58 +01001141 /* As defined by IEEE 802.11-2007 17.3.8.6 */
1142 slottime = ah->slottime + 3 * ah->coverage_class;
1143 acktimeout = slottime + sifstime;
Felix Fietkau42c45682010-02-11 18:07:19 +01001144
1145 /*
1146 * Workaround for early ACK timeouts, add an offset to match the
1147 * initval's 64us ack timeout value.
1148 * This was initially only meant to work around an issue with delayed
1149 * BA frames in some implementations, but it has been found to fix ACK
1150 * timeout issues in other cases as well.
1151 */
1152 if (conf->channel && conf->channel->band == IEEE80211_BAND_2GHZ)
1153 acktimeout += 64 - sifstime - ah->slottime;
1154
Felix Fietkaue239d852010-01-15 02:34:58 +01001155 ath9k_hw_setslottime(ah, slottime);
Felix Fietkau0005baf2010-01-15 02:33:40 +01001156 ath9k_hw_set_ack_timeout(ah, acktimeout);
1157 ath9k_hw_set_cts_timeout(ah, acktimeout);
Sujith2660b812009-02-09 13:27:26 +05301158 if (ah->globaltxtimeout != (u32) -1)
1159 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Sujithf1dc5602008-10-29 10:16:30 +05301160}
Felix Fietkau0005baf2010-01-15 02:33:40 +01001161EXPORT_SYMBOL(ath9k_hw_init_global_settings);
Sujithf1dc5602008-10-29 10:16:30 +05301162
Sujith285f2dd2010-01-08 10:36:07 +05301163void ath9k_hw_deinit(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001164{
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001165 struct ath_common *common = ath9k_hw_common(ah);
1166
Sujith736b3a22010-03-17 14:25:24 +05301167 if (common->state < ATH_HW_INITIALIZED)
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001168 goto free_hw;
1169
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001170 if (!AR_SREV_9100(ah))
Luis R. Rodrigueze70c0cf2009-08-03 12:24:51 -07001171 ath9k_hw_ani_disable(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001172
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001173 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001174
1175free_hw:
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001176 ath9k_hw_rf_free_ext_banks(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001177}
Sujith285f2dd2010-01-08 10:36:07 +05301178EXPORT_SYMBOL(ath9k_hw_deinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001179
Sujithf1dc5602008-10-29 10:16:30 +05301180/*******/
1181/* INI */
1182/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001183
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001184u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan)
Bob Copeland3a702e42009-03-30 22:30:29 -04001185{
1186 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
1187
1188 if (IS_CHAN_B(chan))
1189 ctl |= CTL_11B;
1190 else if (IS_CHAN_G(chan))
1191 ctl |= CTL_11G;
1192 else
1193 ctl |= CTL_11A;
1194
1195 return ctl;
1196}
1197
Sujithf1dc5602008-10-29 10:16:30 +05301198/****************************************/
1199/* Reset and Channel Switching Routines */
1200/****************************************/
1201
Sujithcbe61d82009-02-09 13:27:12 +05301202static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301203{
1204 u32 regval;
1205
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001206 /*
1207 * set AHB_MODE not to do cacheline prefetches
1208 */
Sujithf1dc5602008-10-29 10:16:30 +05301209 regval = REG_READ(ah, AR_AHB_MODE);
1210 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
1211
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001212 /*
1213 * let mac dma reads be in 128 byte chunks
1214 */
Sujithf1dc5602008-10-29 10:16:30 +05301215 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
1216 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
1217
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001218 /*
1219 * Restore TX Trigger Level to its pre-reset value.
1220 * The initial value depends on whether aggregation is enabled, and is
1221 * adjusted whenever underruns are detected.
1222 */
Sujith2660b812009-02-09 13:27:26 +05301223 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +05301224
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001225 /*
1226 * let mac dma writes be in 128 byte chunks
1227 */
Sujithf1dc5602008-10-29 10:16:30 +05301228 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
1229 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
1230
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001231 /*
1232 * Setup receive FIFO threshold to hold off TX activities
1233 */
Sujithf1dc5602008-10-29 10:16:30 +05301234 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1235
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001236 /*
1237 * reduce the number of usable entries in PCU TXBUF to avoid
1238 * wrap around issues.
1239 */
Sujithf1dc5602008-10-29 10:16:30 +05301240 if (AR_SREV_9285(ah)) {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001241 /* For AR9285 the number of Fifos are reduced to half.
1242 * So set the usable tx buf size also to half to
1243 * avoid data/delimiter underruns
1244 */
Sujithf1dc5602008-10-29 10:16:30 +05301245 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1246 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001247 } else if (!AR_SREV_9271(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +05301248 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1249 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1250 }
1251}
1252
Sujithcbe61d82009-02-09 13:27:12 +05301253static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301254{
1255 u32 val;
1256
1257 val = REG_READ(ah, AR_STA_ID1);
1258 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
1259 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001260 case NL80211_IFTYPE_AP:
Sujithf1dc5602008-10-29 10:16:30 +05301261 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
1262 | AR_STA_ID1_KSRCH_MODE);
1263 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1264 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001265 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04001266 case NL80211_IFTYPE_MESH_POINT:
Sujithf1dc5602008-10-29 10:16:30 +05301267 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
1268 | AR_STA_ID1_KSRCH_MODE);
1269 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1270 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001271 case NL80211_IFTYPE_STATION:
1272 case NL80211_IFTYPE_MONITOR:
Sujithf1dc5602008-10-29 10:16:30 +05301273 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
1274 break;
1275 }
1276}
1277
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001278void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled,
1279 u32 *coef_mantissa, u32 *coef_exponent)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001280{
1281 u32 coef_exp, coef_man;
1282
1283 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1284 if ((coef_scaled >> coef_exp) & 0x1)
1285 break;
1286
1287 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1288
1289 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1290
1291 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1292 *coef_exponent = coef_exp - 16;
1293}
1294
Sujithcbe61d82009-02-09 13:27:12 +05301295static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +05301296{
1297 u32 rst_flags;
1298 u32 tmpReg;
1299
Sujith70768492009-02-16 13:23:12 +05301300 if (AR_SREV_9100(ah)) {
1301 u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK);
1302 val &= ~AR_RTC_DERIVED_CLK_PERIOD;
1303 val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD);
1304 REG_WRITE(ah, AR_RTC_DERIVED_CLK, val);
1305 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1306 }
1307
Sujithf1dc5602008-10-29 10:16:30 +05301308 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1309 AR_RTC_FORCE_WAKE_ON_INT);
1310
1311 if (AR_SREV_9100(ah)) {
1312 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1313 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1314 } else {
1315 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1316 if (tmpReg &
1317 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1318 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001319 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05301320 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001321
1322 val = AR_RC_HOSTIF;
1323 if (!AR_SREV_9300_20_OR_LATER(ah))
1324 val |= AR_RC_AHB;
1325 REG_WRITE(ah, AR_RC, val);
1326
1327 } else if (!AR_SREV_9300_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05301328 REG_WRITE(ah, AR_RC, AR_RC_AHB);
Sujithf1dc5602008-10-29 10:16:30 +05301329
1330 rst_flags = AR_RTC_RC_MAC_WARM;
1331 if (type == ATH9K_RESET_COLD)
1332 rst_flags |= AR_RTC_RC_MAC_COLD;
1333 }
1334
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001335 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujithf1dc5602008-10-29 10:16:30 +05301336 udelay(50);
1337
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001338 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301339 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001340 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1341 "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301342 return false;
1343 }
1344
1345 if (!AR_SREV_9100(ah))
1346 REG_WRITE(ah, AR_RC, 0);
1347
Sujithf1dc5602008-10-29 10:16:30 +05301348 if (AR_SREV_9100(ah))
1349 udelay(50);
1350
1351 return true;
1352}
1353
Sujithcbe61d82009-02-09 13:27:12 +05301354static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301355{
1356 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1357 AR_RTC_FORCE_WAKE_ON_INT);
1358
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001359 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301360 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1361
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001362 REG_WRITE(ah, AR_RTC_RESET, 0);
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301363 udelay(2);
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301364
1365 if (!AR_SREV_9100(ah))
1366 REG_WRITE(ah, AR_RC, 0);
1367
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001368 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301369
1370 if (!ath9k_hw_wait(ah,
1371 AR_RTC_STATUS,
1372 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301373 AR_RTC_STATUS_ON,
1374 AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001375 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1376 "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301377 return false;
1378 }
1379
1380 ath9k_hw_read_revisions(ah);
1381
1382 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1383}
1384
Sujithcbe61d82009-02-09 13:27:12 +05301385static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301386{
1387 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1388 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1389
1390 switch (type) {
1391 case ATH9K_RESET_POWER_ON:
1392 return ath9k_hw_set_reset_power_on(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301393 case ATH9K_RESET_WARM:
1394 case ATH9K_RESET_COLD:
1395 return ath9k_hw_set_reset(ah, type);
Sujithf1dc5602008-10-29 10:16:30 +05301396 default:
1397 return false;
1398 }
1399}
1400
Sujithcbe61d82009-02-09 13:27:12 +05301401static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301402 struct ath9k_channel *chan)
1403{
Vivek Natarajan42abfbe2009-09-17 09:27:59 +05301404 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) {
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301405 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
1406 return false;
1407 } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
Sujithf1dc5602008-10-29 10:16:30 +05301408 return false;
1409
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001410 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05301411 return false;
1412
Sujith2660b812009-02-09 13:27:26 +05301413 ah->chip_fullsleep = false;
Sujithf1dc5602008-10-29 10:16:30 +05301414 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301415 ath9k_hw_set_rfmode(ah, chan);
1416
1417 return true;
1418}
1419
Sujithcbe61d82009-02-09 13:27:12 +05301420static bool ath9k_hw_channel_change(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001421 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301422{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001423 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001424 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001425 struct ieee80211_channel *channel = chan->chan;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001426 u32 qnum;
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001427 int r;
Sujithf1dc5602008-10-29 10:16:30 +05301428
1429 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1430 if (ath9k_hw_numtxpending(ah, qnum)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001431 ath_print(common, ATH_DBG_QUEUE,
1432 "Transmit frames pending on "
1433 "queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301434 return false;
1435 }
1436 }
1437
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001438 if (!ath9k_hw_rfbus_req(ah)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001439 ath_print(common, ATH_DBG_FATAL,
1440 "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301441 return false;
1442 }
1443
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001444 ath9k_hw_set_channel_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301445
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001446 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001447 if (r) {
1448 ath_print(common, ATH_DBG_FATAL,
1449 "Failed to set channel\n");
1450 return false;
Sujithf1dc5602008-10-29 10:16:30 +05301451 }
1452
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001453 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001454 ath9k_regd_get_ctl(regulatory, chan),
Sujithf74df6f2009-02-09 13:27:24 +05301455 channel->max_antenna_gain * 2,
1456 channel->max_power * 2,
1457 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001458 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05301459
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001460 ath9k_hw_rfbus_done(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301461
1462 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1463 ath9k_hw_set_delta_slope(ah, chan);
1464
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001465 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301466
1467 if (!chan->oneTimeCalsDone)
1468 chan->oneTimeCalsDone = true;
1469
1470 return true;
1471}
1472
Sujithcbe61d82009-02-09 13:27:12 +05301473int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001474 bool bChannelChange)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001475{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001476 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001477 u32 saveLedState;
Sujith2660b812009-02-09 13:27:26 +05301478 struct ath9k_channel *curchan = ah->curchan;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001479 u32 saveDefAntenna;
1480 u32 macStaId1;
Sujith46fe7822009-09-17 09:25:25 +05301481 u64 tsf = 0;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001482 int i, r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001483
Luis R. Rodriguez43c27612009-09-13 21:07:07 -07001484 ah->txchainmask = common->tx_chainmask;
1485 ah->rxchainmask = common->rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001486
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001487 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001488 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001489
Vasanthakumar Thiagarajan9ebef792009-09-17 09:26:44 +05301490 if (curchan && !ah->chip_fullsleep)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001491 ath9k_hw_getnf(ah, curchan);
1492
1493 if (bChannelChange &&
Sujith2660b812009-02-09 13:27:26 +05301494 (ah->chip_fullsleep != true) &&
1495 (ah->curchan != NULL) &&
1496 (chan->channel != ah->curchan->channel) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001497 ((chan->channelFlags & CHANNEL_ALL) ==
Sujith2660b812009-02-09 13:27:26 +05301498 (ah->curchan->channelFlags & CHANNEL_ALL)) &&
Vasanthakumar Thiagarajan0a475cc2009-09-17 09:27:10 +05301499 !(AR_SREV_9280(ah) || IS_CHAN_A_5MHZ_SPACED(chan) ||
1500 IS_CHAN_A_5MHZ_SPACED(ah->curchan))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001501
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001502 if (ath9k_hw_channel_change(ah, chan)) {
Sujith2660b812009-02-09 13:27:26 +05301503 ath9k_hw_loadnf(ah, ah->curchan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001504 ath9k_hw_start_nfcal(ah);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001505 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001506 }
1507 }
1508
1509 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
1510 if (saveDefAntenna == 0)
1511 saveDefAntenna = 1;
1512
1513 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
1514
Sujith46fe7822009-09-17 09:25:25 +05301515 /* For chips on which RTC reset is done, save TSF before it gets cleared */
1516 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1517 tsf = ath9k_hw_gettsf64(ah);
1518
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001519 saveLedState = REG_READ(ah, AR_CFG_LED) &
1520 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
1521 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
1522
1523 ath9k_hw_mark_phy_inactive(ah);
1524
Sujith05020d22010-03-17 14:25:23 +05301525 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001526 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1527 REG_WRITE(ah,
1528 AR9271_RESET_POWER_DOWN_CONTROL,
1529 AR9271_RADIO_RF_RST);
1530 udelay(50);
1531 }
1532
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001533 if (!ath9k_hw_chip_reset(ah, chan)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001534 ath_print(common, ATH_DBG_FATAL, "Chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001535 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001536 }
1537
Sujith05020d22010-03-17 14:25:23 +05301538 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001539 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1540 ah->htc_reset_init = false;
1541 REG_WRITE(ah,
1542 AR9271_RESET_POWER_DOWN_CONTROL,
1543 AR9271_GATE_MAC_CTL);
1544 udelay(50);
1545 }
1546
Sujith46fe7822009-09-17 09:25:25 +05301547 /* Restore TSF */
1548 if (tsf && AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1549 ath9k_hw_settsf64(ah, tsf);
1550
Vasanthakumar Thiagarajan369391d2009-01-21 19:24:13 +05301551 if (AR_SREV_9280_10_OR_LATER(ah))
1552 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001553
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001554 r = ath9k_hw_process_ini(ah, chan);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001555 if (r)
1556 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001557
Jouni Malinen0ced0e12009-01-08 13:32:13 +02001558 /* Setup MFP options for CCMP */
1559 if (AR_SREV_9280_20_OR_LATER(ah)) {
1560 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
1561 * frames when constructing CCMP AAD. */
1562 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
1563 0xc7ff);
1564 ah->sw_mgmt_crypto = false;
1565 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1566 /* Disable hardware crypto for management frames */
1567 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
1568 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
1569 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1570 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
1571 ah->sw_mgmt_crypto = true;
1572 } else
1573 ah->sw_mgmt_crypto = true;
1574
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001575 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1576 ath9k_hw_set_delta_slope(ah, chan);
1577
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001578 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithd6509152009-03-13 08:56:05 +05301579 ah->eep_ops->set_board_values(ah, chan);
Luis R. Rodrigueza7765822009-10-19 02:33:45 -04001580
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001581 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
1582 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001583 | macStaId1
1584 | AR_STA_ID1_RTS_USE_DEF
Sujith2660b812009-02-09 13:27:26 +05301585 | (ah->config.
Sujith60b67f52008-08-07 10:52:38 +05301586 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Sujith2660b812009-02-09 13:27:26 +05301587 | ah->sta_id1_defaults);
1588 ath9k_hw_set_operating_mode(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001589
Luis R. Rodriguez13b81552009-09-10 17:52:45 -07001590 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001591
1592 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
1593
Luis R. Rodriguez3453ad82009-09-10 08:57:00 -07001594 ath9k_hw_write_associd(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001595
1596 REG_WRITE(ah, AR_ISR, ~0);
1597
1598 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
1599
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001600 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001601 if (r)
1602 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001603
1604 for (i = 0; i < AR_NUM_DCU; i++)
1605 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
1606
Sujith2660b812009-02-09 13:27:26 +05301607 ah->intr_txqs = 0;
1608 for (i = 0; i < ah->caps.total_queues; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001609 ath9k_hw_resettxqueue(ah, i);
1610
Sujith2660b812009-02-09 13:27:26 +05301611 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001612 ath9k_hw_init_qos(ah);
1613
Sujith2660b812009-02-09 13:27:26 +05301614 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301615 ath9k_enable_rfkill(ah);
Johannes Berg3b319aa2009-06-13 14:50:26 +05301616
Felix Fietkau0005baf2010-01-15 02:33:40 +01001617 ath9k_hw_init_global_settings(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001618
Vivek Natarajan326bebb2009-08-14 11:33:36 +05301619 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301620 REG_WRITE(ah, AR_D_GBL_IFS_SIFS,
1621 AR_D_GBL_IFS_SIFS_ASYNC_FIFO_DUR);
1622 REG_WRITE(ah, AR_D_GBL_IFS_SLOT,
1623 AR_D_GBL_IFS_SLOT_ASYNC_FIFO_DUR);
1624 REG_WRITE(ah, AR_D_GBL_IFS_EIFS,
1625 AR_D_GBL_IFS_EIFS_ASYNC_FIFO_DUR);
1626
1627 REG_WRITE(ah, AR_TIME_OUT, AR_TIME_OUT_ACK_CTS_ASYNC_FIFO_DUR);
1628 REG_WRITE(ah, AR_USEC, AR_USEC_ASYNC_FIFO_DUR);
1629
1630 REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
1631 AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
1632 REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
1633 AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
1634 }
Vivek Natarajan326bebb2009-08-14 11:33:36 +05301635 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301636 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1637 AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
1638 }
1639
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001640 REG_WRITE(ah, AR_STA_ID1,
1641 REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
1642
1643 ath9k_hw_set_dma(ah);
1644
1645 REG_WRITE(ah, AR_OBS, 8);
1646
Sujith0ce024c2009-12-14 14:57:00 +05301647 if (ah->config.rx_intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001648 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
1649 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
1650 }
1651
1652 ath9k_hw_init_bb(ah, chan);
1653
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001654 if (!ath9k_hw_init_cal(ah, chan))
Joe Perches6badaaf2009-06-28 09:26:32 -07001655 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001656
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001657 ath9k_hw_restore_chainmask(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001658 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
1659
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001660 /*
1661 * For big endian systems turn on swapping for descriptors
1662 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001663 if (AR_SREV_9100(ah)) {
1664 u32 mask;
1665 mask = REG_READ(ah, AR_CFG);
1666 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001667 ath_print(common, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05301668 "CFG Byte Swap Set 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001669 } else {
1670 mask =
1671 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
1672 REG_WRITE(ah, AR_CFG, mask);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001673 ath_print(common, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05301674 "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001675 }
1676 } else {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001677 /* Configure AR9271 target WLAN */
1678 if (AR_SREV_9271(ah))
1679 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001680#ifdef __BIG_ENDIAN
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001681 else
1682 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001683#endif
1684 }
1685
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001686 if (ah->btcoex_hw.enabled)
Vasanthakumar Thiagarajan42cc41e2009-08-26 21:08:45 +05301687 ath9k_hw_btcoex_enable(ah);
1688
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001689 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001690}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001691EXPORT_SYMBOL(ath9k_hw_reset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001692
Sujithf1dc5602008-10-29 10:16:30 +05301693/************************/
1694/* Key Cache Management */
1695/************************/
1696
Sujithcbe61d82009-02-09 13:27:12 +05301697bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001698{
Sujithf1dc5602008-10-29 10:16:30 +05301699 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001700
Sujith2660b812009-02-09 13:27:26 +05301701 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001702 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1703 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001704 return false;
1705 }
1706
Sujithf1dc5602008-10-29 10:16:30 +05301707 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001708
Sujithf1dc5602008-10-29 10:16:30 +05301709 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
1710 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
1711 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
1712 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
1713 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
1714 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
1715 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
1716 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
1717
1718 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
1719 u16 micentry = entry + 64;
1720
1721 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
1722 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
1723 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
1724 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
1725
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001726 }
1727
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001728 return true;
1729}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001730EXPORT_SYMBOL(ath9k_hw_keyreset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001731
Sujithcbe61d82009-02-09 13:27:12 +05301732bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001733{
Sujithf1dc5602008-10-29 10:16:30 +05301734 u32 macHi, macLo;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001735
Sujith2660b812009-02-09 13:27:26 +05301736 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001737 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1738 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001739 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001740 }
1741
Sujithf1dc5602008-10-29 10:16:30 +05301742 if (mac != NULL) {
1743 macHi = (mac[5] << 8) | mac[4];
1744 macLo = (mac[3] << 24) |
1745 (mac[2] << 16) |
1746 (mac[1] << 8) |
1747 mac[0];
1748 macLo >>= 1;
1749 macLo |= (macHi & 1) << 31;
1750 macHi >>= 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001751 } else {
Sujithf1dc5602008-10-29 10:16:30 +05301752 macLo = macHi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001753 }
Sujithf1dc5602008-10-29 10:16:30 +05301754 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
1755 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001756
1757 return true;
1758}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001759EXPORT_SYMBOL(ath9k_hw_keysetmac);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001760
Sujithcbe61d82009-02-09 13:27:12 +05301761bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
Sujithf1dc5602008-10-29 10:16:30 +05301762 const struct ath9k_keyval *k,
Jouni Malinene0caf9e2009-03-02 18:15:53 +02001763 const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001764{
Sujith2660b812009-02-09 13:27:26 +05301765 const struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001766 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301767 u32 key0, key1, key2, key3, key4;
1768 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001769
Sujithf1dc5602008-10-29 10:16:30 +05301770 if (entry >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001771 ath_print(common, ATH_DBG_FATAL,
1772 "keycache entry %u out of range\n", entry);
Sujithf1dc5602008-10-29 10:16:30 +05301773 return false;
1774 }
1775
1776 switch (k->kv_type) {
1777 case ATH9K_CIPHER_AES_OCB:
1778 keyType = AR_KEYTABLE_TYPE_AES;
1779 break;
1780 case ATH9K_CIPHER_AES_CCM:
1781 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001782 ath_print(common, ATH_DBG_ANY,
1783 "AES-CCM not supported by mac rev 0x%x\n",
1784 ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001785 return false;
1786 }
Sujithf1dc5602008-10-29 10:16:30 +05301787 keyType = AR_KEYTABLE_TYPE_CCM;
1788 break;
1789 case ATH9K_CIPHER_TKIP:
1790 keyType = AR_KEYTABLE_TYPE_TKIP;
1791 if (ATH9K_IS_MIC_ENABLED(ah)
1792 && entry + 64 >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001793 ath_print(common, ATH_DBG_ANY,
1794 "entry %u inappropriate for TKIP\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001795 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001796 }
Sujithf1dc5602008-10-29 10:16:30 +05301797 break;
1798 case ATH9K_CIPHER_WEP:
Zhu Yie31a16d2009-05-21 21:47:03 +08001799 if (k->kv_len < WLAN_KEY_LEN_WEP40) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001800 ath_print(common, ATH_DBG_ANY,
1801 "WEP key length %u too small\n", k->kv_len);
Sujithf1dc5602008-10-29 10:16:30 +05301802 return false;
1803 }
Zhu Yie31a16d2009-05-21 21:47:03 +08001804 if (k->kv_len <= WLAN_KEY_LEN_WEP40)
Sujithf1dc5602008-10-29 10:16:30 +05301805 keyType = AR_KEYTABLE_TYPE_40;
Zhu Yie31a16d2009-05-21 21:47:03 +08001806 else if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05301807 keyType = AR_KEYTABLE_TYPE_104;
1808 else
1809 keyType = AR_KEYTABLE_TYPE_128;
1810 break;
1811 case ATH9K_CIPHER_CLR:
1812 keyType = AR_KEYTABLE_TYPE_CLR;
1813 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001814 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001815 ath_print(common, ATH_DBG_FATAL,
1816 "cipher %u not supported\n", k->kv_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001817 return false;
1818 }
Sujithf1dc5602008-10-29 10:16:30 +05301819
Jouni Malinene0caf9e2009-03-02 18:15:53 +02001820 key0 = get_unaligned_le32(k->kv_val + 0);
1821 key1 = get_unaligned_le16(k->kv_val + 4);
1822 key2 = get_unaligned_le32(k->kv_val + 6);
1823 key3 = get_unaligned_le16(k->kv_val + 10);
1824 key4 = get_unaligned_le32(k->kv_val + 12);
Zhu Yie31a16d2009-05-21 21:47:03 +08001825 if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05301826 key4 &= 0xff;
1827
Jouni Malinen672903b2009-03-02 15:06:31 +02001828 /*
1829 * Note: Key cache registers access special memory area that requires
1830 * two 32-bit writes to actually update the values in the internal
1831 * memory. Consequently, the exact order and pairs used here must be
1832 * maintained.
1833 */
1834
Sujithf1dc5602008-10-29 10:16:30 +05301835 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
1836 u16 micentry = entry + 64;
1837
Jouni Malinen672903b2009-03-02 15:06:31 +02001838 /*
1839 * Write inverted key[47:0] first to avoid Michael MIC errors
1840 * on frames that could be sent or received at the same time.
1841 * The correct key will be written in the end once everything
1842 * else is ready.
1843 */
Sujithf1dc5602008-10-29 10:16:30 +05301844 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
1845 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02001846
1847 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05301848 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
1849 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02001850
1851 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05301852 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
1853 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
Jouni Malinen672903b2009-03-02 15:06:31 +02001854
1855 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05301856 (void) ath9k_hw_keysetmac(ah, entry, mac);
1857
Sujith2660b812009-02-09 13:27:26 +05301858 if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) {
Jouni Malinen672903b2009-03-02 15:06:31 +02001859 /*
1860 * TKIP uses two key cache entries:
1861 * Michael MIC TX/RX keys in the same key cache entry
1862 * (idx = main index + 64):
1863 * key0 [31:0] = RX key [31:0]
1864 * key1 [15:0] = TX key [31:16]
1865 * key1 [31:16] = reserved
1866 * key2 [31:0] = RX key [63:32]
1867 * key3 [15:0] = TX key [15:0]
1868 * key3 [31:16] = reserved
1869 * key4 [31:0] = TX key [63:32]
1870 */
Sujithf1dc5602008-10-29 10:16:30 +05301871 u32 mic0, mic1, mic2, mic3, mic4;
1872
1873 mic0 = get_unaligned_le32(k->kv_mic + 0);
1874 mic2 = get_unaligned_le32(k->kv_mic + 4);
1875 mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
1876 mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
1877 mic4 = get_unaligned_le32(k->kv_txmic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02001878
1879 /* Write RX[31:0] and TX[31:16] */
Sujithf1dc5602008-10-29 10:16:30 +05301880 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
1881 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
Jouni Malinen672903b2009-03-02 15:06:31 +02001882
1883 /* Write RX[63:32] and TX[15:0] */
Sujithf1dc5602008-10-29 10:16:30 +05301884 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
1885 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
Jouni Malinen672903b2009-03-02 15:06:31 +02001886
1887 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05301888 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
1889 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
1890 AR_KEYTABLE_TYPE_CLR);
1891
1892 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02001893 /*
1894 * TKIP uses four key cache entries (two for group
1895 * keys):
1896 * Michael MIC TX/RX keys are in different key cache
1897 * entries (idx = main index + 64 for TX and
1898 * main index + 32 + 96 for RX):
1899 * key0 [31:0] = TX/RX MIC key [31:0]
1900 * key1 [31:0] = reserved
1901 * key2 [31:0] = TX/RX MIC key [63:32]
1902 * key3 [31:0] = reserved
1903 * key4 [31:0] = reserved
1904 *
1905 * Upper layer code will call this function separately
1906 * for TX and RX keys when these registers offsets are
1907 * used.
1908 */
Sujithf1dc5602008-10-29 10:16:30 +05301909 u32 mic0, mic2;
1910
1911 mic0 = get_unaligned_le32(k->kv_mic + 0);
1912 mic2 = get_unaligned_le32(k->kv_mic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02001913
1914 /* Write MIC key[31:0] */
Sujithf1dc5602008-10-29 10:16:30 +05301915 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
1916 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02001917
1918 /* Write MIC key[63:32] */
Sujithf1dc5602008-10-29 10:16:30 +05301919 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
1920 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02001921
1922 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05301923 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
1924 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
1925 AR_KEYTABLE_TYPE_CLR);
1926 }
Jouni Malinen672903b2009-03-02 15:06:31 +02001927
1928 /* MAC address registers are reserved for the MIC entry */
Sujithf1dc5602008-10-29 10:16:30 +05301929 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
1930 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02001931
1932 /*
1933 * Write the correct (un-inverted) key[47:0] last to enable
1934 * TKIP now that all other registers are set with correct
1935 * values.
1936 */
Sujithf1dc5602008-10-29 10:16:30 +05301937 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
1938 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
1939 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02001940 /* Write key[47:0] */
Sujithf1dc5602008-10-29 10:16:30 +05301941 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
1942 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02001943
1944 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05301945 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
1946 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02001947
1948 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05301949 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
1950 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
1951
Jouni Malinen672903b2009-03-02 15:06:31 +02001952 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05301953 (void) ath9k_hw_keysetmac(ah, entry, mac);
1954 }
1955
Sujithf1dc5602008-10-29 10:16:30 +05301956 return true;
1957}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001958EXPORT_SYMBOL(ath9k_hw_set_keycache_entry);
Sujithf1dc5602008-10-29 10:16:30 +05301959
Sujithcbe61d82009-02-09 13:27:12 +05301960bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry)
Sujithf1dc5602008-10-29 10:16:30 +05301961{
Sujith2660b812009-02-09 13:27:26 +05301962 if (entry < ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05301963 u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
1964 if (val & AR_KEYTABLE_VALID)
1965 return true;
1966 }
1967 return false;
1968}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001969EXPORT_SYMBOL(ath9k_hw_keyisvalid);
Sujithf1dc5602008-10-29 10:16:30 +05301970
1971/******************************/
1972/* Power Management (Chipset) */
1973/******************************/
1974
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001975/*
1976 * Notify Power Mgt is disabled in self-generated frames.
1977 * If requested, force chip to sleep.
1978 */
Sujithcbe61d82009-02-09 13:27:12 +05301979static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05301980{
1981 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
1982 if (setChip) {
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001983 /*
1984 * Clear the RTC force wake bit to allow the
1985 * mac to go to sleep.
1986 */
Sujithf1dc5602008-10-29 10:16:30 +05301987 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
1988 AR_RTC_FORCE_WAKE_EN);
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001989 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05301990 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1991
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001992 /* Shutdown chip. Active low */
Sujith14b3af32010-03-17 14:25:18 +05301993 if (!AR_SREV_5416(ah) && !AR_SREV_9271(ah))
Sujith4921be82009-09-18 15:04:27 +05301994 REG_CLR_BIT(ah, (AR_RTC_RESET),
1995 AR_RTC_RESET_EN);
Sujithf1dc5602008-10-29 10:16:30 +05301996 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001997}
1998
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04001999/*
2000 * Notify Power Management is enabled in self-generating
2001 * frames. If request, set power mode of chip to
2002 * auto/normal. Duration in units of 128us (1/8 TU).
2003 */
Sujithcbe61d82009-02-09 13:27:12 +05302004static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002005{
Sujithf1dc5602008-10-29 10:16:30 +05302006 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2007 if (setChip) {
Sujith2660b812009-02-09 13:27:26 +05302008 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002009
Sujithf1dc5602008-10-29 10:16:30 +05302010 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04002011 /* Set WakeOnInterrupt bit; clear ForceWake bit */
Sujithf1dc5602008-10-29 10:16:30 +05302012 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2013 AR_RTC_FORCE_WAKE_ON_INT);
2014 } else {
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04002015 /*
2016 * Clear the RTC force wake bit to allow the
2017 * mac to go to sleep.
2018 */
Sujithf1dc5602008-10-29 10:16:30 +05302019 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2020 AR_RTC_FORCE_WAKE_EN);
2021 }
2022 }
2023}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002024
Sujithcbe61d82009-02-09 13:27:12 +05302025static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302026{
2027 u32 val;
2028 int i;
2029
2030 if (setChip) {
2031 if ((REG_READ(ah, AR_RTC_STATUS) &
2032 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2033 if (ath9k_hw_set_reset_reg(ah,
2034 ATH9K_RESET_POWER_ON) != true) {
2035 return false;
2036 }
Luis R. Rodrigueze0412282010-04-15 17:38:15 -04002037 if (!AR_SREV_9300_20_OR_LATER(ah))
2038 ath9k_hw_init_pll(ah, NULL);
Sujithf1dc5602008-10-29 10:16:30 +05302039 }
2040 if (AR_SREV_9100(ah))
2041 REG_SET_BIT(ah, AR_RTC_RESET,
2042 AR_RTC_RESET_EN);
2043
2044 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2045 AR_RTC_FORCE_WAKE_EN);
2046 udelay(50);
2047
2048 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2049 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2050 if (val == AR_RTC_STATUS_ON)
2051 break;
2052 udelay(50);
2053 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2054 AR_RTC_FORCE_WAKE_EN);
2055 }
2056 if (i == 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002057 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2058 "Failed to wakeup in %uus\n",
2059 POWER_UP_TIME / 20);
Sujithf1dc5602008-10-29 10:16:30 +05302060 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002061 }
2062 }
2063
Sujithf1dc5602008-10-29 10:16:30 +05302064 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2065
2066 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002067}
2068
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002069bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05302070{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002071 struct ath_common *common = ath9k_hw_common(ah);
Sujithcbe61d82009-02-09 13:27:12 +05302072 int status = true, setChip = true;
Sujithf1dc5602008-10-29 10:16:30 +05302073 static const char *modes[] = {
2074 "AWAKE",
2075 "FULL-SLEEP",
2076 "NETWORK SLEEP",
2077 "UNDEFINED"
2078 };
Sujithf1dc5602008-10-29 10:16:30 +05302079
Gabor Juhoscbdec972009-07-24 17:27:22 +02002080 if (ah->power_mode == mode)
2081 return status;
2082
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002083 ath_print(common, ATH_DBG_RESET, "%s -> %s\n",
2084 modes[ah->power_mode], modes[mode]);
Sujithf1dc5602008-10-29 10:16:30 +05302085
2086 switch (mode) {
2087 case ATH9K_PM_AWAKE:
2088 status = ath9k_hw_set_power_awake(ah, setChip);
2089 break;
2090 case ATH9K_PM_FULL_SLEEP:
2091 ath9k_set_power_sleep(ah, setChip);
Sujith2660b812009-02-09 13:27:26 +05302092 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05302093 break;
2094 case ATH9K_PM_NETWORK_SLEEP:
2095 ath9k_set_power_network_sleep(ah, setChip);
2096 break;
2097 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002098 ath_print(common, ATH_DBG_FATAL,
2099 "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05302100 return false;
2101 }
Sujith2660b812009-02-09 13:27:26 +05302102 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05302103
2104 return status;
2105}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002106EXPORT_SYMBOL(ath9k_hw_setpower);
Sujithf1dc5602008-10-29 10:16:30 +05302107
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002108/*
2109 * Helper for ASPM support.
2110 *
2111 * Disable PLL when in L0s as well as receiver clock when in L1.
2112 * This power saving option must be enabled through the SerDes.
2113 *
2114 * Programming the SerDes must go through the same 288 bit serial shift
2115 * register as the other analog registers. Hence the 9 writes.
2116 */
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04002117static void ar9002_hw_configpcipowersave(struct ath_hw *ah,
2118 int restore,
2119 int power_off)
Sujithf1dc5602008-10-29 10:16:30 +05302120{
Sujithf1dc5602008-10-29 10:16:30 +05302121 u8 i;
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302122 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05302123
Sujith2660b812009-02-09 13:27:26 +05302124 if (ah->is_pciexpress != true)
Sujithf1dc5602008-10-29 10:16:30 +05302125 return;
2126
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002127 /* Do not touch SerDes registers */
Sujith2660b812009-02-09 13:27:26 +05302128 if (ah->config.pcie_powersave_enable == 2)
Sujithf1dc5602008-10-29 10:16:30 +05302129 return;
2130
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002131 /* Nothing to do on restore for 11N */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302132 if (!restore) {
2133 if (AR_SREV_9280_20_OR_LATER(ah)) {
2134 /*
2135 * AR9280 2.0 or later chips use SerDes values from the
2136 * initvals.h initialized depending on chipset during
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04002137 * __ath9k_hw_init()
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302138 */
2139 for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
2140 REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
2141 INI_RA(&ah->iniPcieSerdes, i, 1));
2142 }
2143 } else if (AR_SREV_9280(ah) &&
2144 (ah->hw_version.macRev == AR_SREV_REVISION_9280_10)) {
2145 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
2146 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
Sujithf1dc5602008-10-29 10:16:30 +05302147
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302148 /* RX shut off when elecidle is asserted */
2149 REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
2150 REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
2151 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
2152
2153 /* Shut off CLKREQ active in L1 */
2154 if (ah->config.pcie_clock_req)
2155 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
2156 else
2157 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
2158
2159 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2160 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2161 REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
2162
2163 /* Load the new settings */
2164 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
2165
2166 } else {
2167 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
2168 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
2169
2170 /* RX shut off when elecidle is asserted */
2171 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
2172 REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
2173 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
2174
2175 /*
2176 * Ignore ah->ah_config.pcie_clock_req setting for
2177 * pre-AR9280 11n
2178 */
2179 REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
2180
2181 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2182 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2183 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
2184
2185 /* Load the new settings */
2186 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
Sujithf1dc5602008-10-29 10:16:30 +05302187 }
Sujithf1dc5602008-10-29 10:16:30 +05302188
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302189 udelay(1000);
Sujithf1dc5602008-10-29 10:16:30 +05302190
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302191 /* set bit 19 to allow forcing of pcie core into L1 state */
2192 REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
Sujithf1dc5602008-10-29 10:16:30 +05302193
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302194 /* Several PCIe massages to ensure proper behaviour */
2195 if (ah->config.pcie_waen) {
2196 val = ah->config.pcie_waen;
2197 if (!power_off)
2198 val &= (~AR_WA_D3_L1_DISABLE);
2199 } else {
2200 if (AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
2201 AR_SREV_9287(ah)) {
2202 val = AR9285_WA_DEFAULT;
2203 if (!power_off)
2204 val &= (~AR_WA_D3_L1_DISABLE);
2205 } else if (AR_SREV_9280(ah)) {
2206 /*
2207 * On AR9280 chips bit 22 of 0x4004 needs to be
2208 * set otherwise card may disappear.
2209 */
2210 val = AR9280_WA_DEFAULT;
2211 if (!power_off)
2212 val &= (~AR_WA_D3_L1_DISABLE);
2213 } else
2214 val = AR_WA_DEFAULT;
2215 }
Sujithf1dc5602008-10-29 10:16:30 +05302216
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302217 REG_WRITE(ah, AR_WA, val);
Sujithf1dc5602008-10-29 10:16:30 +05302218 }
2219
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302220 if (power_off) {
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002221 /*
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302222 * Set PCIe workaround bits
2223 * bit 14 in WA register (disable L1) should only
2224 * be set when device enters D3 and be cleared
2225 * when device comes back to D0.
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002226 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302227 if (ah->config.pcie_waen) {
2228 if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE)
2229 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
2230 } else {
2231 if (((AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
2232 AR_SREV_9287(ah)) &&
2233 (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)) ||
2234 (AR_SREV_9280(ah) &&
2235 (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE))) {
2236 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
2237 }
2238 }
Sujithf1dc5602008-10-29 10:16:30 +05302239 }
2240}
2241
2242/**********************/
2243/* Interrupt Handling */
2244/**********************/
2245
Sujithcbe61d82009-02-09 13:27:12 +05302246bool ath9k_hw_intrpend(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002247{
2248 u32 host_isr;
2249
2250 if (AR_SREV_9100(ah))
2251 return true;
2252
2253 host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
2254 if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
2255 return true;
2256
2257 host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
2258 if ((host_isr & AR_INTR_SYNC_DEFAULT)
2259 && (host_isr != AR_INTR_SPURIOUS))
2260 return true;
2261
2262 return false;
2263}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002264EXPORT_SYMBOL(ath9k_hw_intrpend);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002265
Sujithcbe61d82009-02-09 13:27:12 +05302266bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002267{
2268 u32 isr = 0;
2269 u32 mask2 = 0;
Sujith2660b812009-02-09 13:27:26 +05302270 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002271 u32 sync_cause = 0;
2272 bool fatal_int = false;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002273 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002274
2275 if (!AR_SREV_9100(ah)) {
2276 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
2277 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
2278 == AR_RTC_STATUS_ON) {
2279 isr = REG_READ(ah, AR_ISR);
2280 }
2281 }
2282
Sujithf1dc5602008-10-29 10:16:30 +05302283 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
2284 AR_INTR_SYNC_DEFAULT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002285
2286 *masked = 0;
2287
2288 if (!isr && !sync_cause)
2289 return false;
2290 } else {
2291 *masked = 0;
2292 isr = REG_READ(ah, AR_ISR);
2293 }
2294
2295 if (isr) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002296 if (isr & AR_ISR_BCNMISC) {
2297 u32 isr2;
2298 isr2 = REG_READ(ah, AR_ISR_S2);
2299 if (isr2 & AR_ISR_S2_TIM)
2300 mask2 |= ATH9K_INT_TIM;
2301 if (isr2 & AR_ISR_S2_DTIM)
2302 mask2 |= ATH9K_INT_DTIM;
2303 if (isr2 & AR_ISR_S2_DTIMSYNC)
2304 mask2 |= ATH9K_INT_DTIMSYNC;
2305 if (isr2 & (AR_ISR_S2_CABEND))
2306 mask2 |= ATH9K_INT_CABEND;
2307 if (isr2 & AR_ISR_S2_GTT)
2308 mask2 |= ATH9K_INT_GTT;
2309 if (isr2 & AR_ISR_S2_CST)
2310 mask2 |= ATH9K_INT_CST;
Sujith4af9cf42009-02-12 10:06:47 +05302311 if (isr2 & AR_ISR_S2_TSFOOR)
2312 mask2 |= ATH9K_INT_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002313 }
2314
2315 isr = REG_READ(ah, AR_ISR_RAC);
2316 if (isr == 0xffffffff) {
2317 *masked = 0;
2318 return false;
2319 }
2320
2321 *masked = isr & ATH9K_INT_COMMON;
2322
Sujith0ce024c2009-12-14 14:57:00 +05302323 if (ah->config.rx_intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002324 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
2325 *masked |= ATH9K_INT_RX;
2326 }
2327
2328 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
2329 *masked |= ATH9K_INT_RX;
2330 if (isr &
2331 (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
2332 AR_ISR_TXEOL)) {
2333 u32 s0_s, s1_s;
2334
2335 *masked |= ATH9K_INT_TX;
2336
2337 s0_s = REG_READ(ah, AR_ISR_S0_S);
Sujith2660b812009-02-09 13:27:26 +05302338 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
2339 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002340
2341 s1_s = REG_READ(ah, AR_ISR_S1_S);
Sujith2660b812009-02-09 13:27:26 +05302342 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
2343 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002344 }
2345
2346 if (isr & AR_ISR_RXORN) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002347 ath_print(common, ATH_DBG_INTERRUPT,
2348 "receive FIFO overrun interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002349 }
2350
2351 if (!AR_SREV_9100(ah)) {
Sujith60b67f52008-08-07 10:52:38 +05302352 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002353 u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
2354 if (isr5 & AR_ISR_S5_TIM_TIMER)
2355 *masked |= ATH9K_INT_TIM_TIMER;
2356 }
2357 }
2358
2359 *masked |= mask2;
2360 }
Sujithf1dc5602008-10-29 10:16:30 +05302361
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002362 if (AR_SREV_9100(ah))
2363 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302364
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302365 if (isr & AR_ISR_GENTMR) {
2366 u32 s5_s;
2367
2368 s5_s = REG_READ(ah, AR_ISR_S5_S);
2369 if (isr & AR_ISR_GENTMR) {
2370 ah->intr_gen_timer_trigger =
2371 MS(s5_s, AR_ISR_S5_GENTIMER_TRIG);
2372
2373 ah->intr_gen_timer_thresh =
2374 MS(s5_s, AR_ISR_S5_GENTIMER_THRESH);
2375
2376 if (ah->intr_gen_timer_trigger)
2377 *masked |= ATH9K_INT_GENTIMER;
2378
2379 }
2380 }
2381
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002382 if (sync_cause) {
2383 fatal_int =
2384 (sync_cause &
2385 (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
2386 ? true : false;
2387
2388 if (fatal_int) {
2389 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002390 ath_print(common, ATH_DBG_ANY,
2391 "received PCI FATAL interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002392 }
2393 if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002394 ath_print(common, ATH_DBG_ANY,
2395 "received PCI PERR interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002396 }
Steven Luoa89bff92009-04-12 02:57:54 -07002397 *masked |= ATH9K_INT_FATAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002398 }
2399 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002400 ath_print(common, ATH_DBG_INTERRUPT,
2401 "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002402 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
2403 REG_WRITE(ah, AR_RC, 0);
2404 *masked |= ATH9K_INT_FATAL;
2405 }
2406 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002407 ath_print(common, ATH_DBG_INTERRUPT,
2408 "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002409 }
2410
2411 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
2412 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
2413 }
Sujithf1dc5602008-10-29 10:16:30 +05302414
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002415 return true;
2416}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002417EXPORT_SYMBOL(ath9k_hw_getisr);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002418
Sujithcbe61d82009-02-09 13:27:12 +05302419enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002420{
Pavel Roskin152d5302010-03-31 18:05:37 -04002421 enum ath9k_int omask = ah->imask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002422 u32 mask, mask2;
Sujith2660b812009-02-09 13:27:26 +05302423 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002424 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002425
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002426 ath_print(common, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002427
2428 if (omask & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002429 ath_print(common, ATH_DBG_INTERRUPT, "disable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002430 REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
2431 (void) REG_READ(ah, AR_IER);
2432 if (!AR_SREV_9100(ah)) {
2433 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
2434 (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
2435
2436 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
2437 (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
2438 }
2439 }
2440
2441 mask = ints & ATH9K_INT_COMMON;
2442 mask2 = 0;
2443
2444 if (ints & ATH9K_INT_TX) {
Sujith2660b812009-02-09 13:27:26 +05302445 if (ah->txok_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002446 mask |= AR_IMR_TXOK;
Sujith2660b812009-02-09 13:27:26 +05302447 if (ah->txdesc_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002448 mask |= AR_IMR_TXDESC;
Sujith2660b812009-02-09 13:27:26 +05302449 if (ah->txerr_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002450 mask |= AR_IMR_TXERR;
Sujith2660b812009-02-09 13:27:26 +05302451 if (ah->txeol_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002452 mask |= AR_IMR_TXEOL;
2453 }
2454 if (ints & ATH9K_INT_RX) {
2455 mask |= AR_IMR_RXERR;
Sujith0ce024c2009-12-14 14:57:00 +05302456 if (ah->config.rx_intr_mitigation)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002457 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
2458 else
2459 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
Sujith60b67f52008-08-07 10:52:38 +05302460 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002461 mask |= AR_IMR_GENTMR;
2462 }
2463
2464 if (ints & (ATH9K_INT_BMISC)) {
2465 mask |= AR_IMR_BCNMISC;
2466 if (ints & ATH9K_INT_TIM)
2467 mask2 |= AR_IMR_S2_TIM;
2468 if (ints & ATH9K_INT_DTIM)
2469 mask2 |= AR_IMR_S2_DTIM;
2470 if (ints & ATH9K_INT_DTIMSYNC)
2471 mask2 |= AR_IMR_S2_DTIMSYNC;
2472 if (ints & ATH9K_INT_CABEND)
Sujith4af9cf42009-02-12 10:06:47 +05302473 mask2 |= AR_IMR_S2_CABEND;
2474 if (ints & ATH9K_INT_TSFOOR)
2475 mask2 |= AR_IMR_S2_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002476 }
2477
2478 if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
2479 mask |= AR_IMR_BCNMISC;
2480 if (ints & ATH9K_INT_GTT)
2481 mask2 |= AR_IMR_S2_GTT;
2482 if (ints & ATH9K_INT_CST)
2483 mask2 |= AR_IMR_S2_CST;
2484 }
2485
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002486 ath_print(common, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002487 REG_WRITE(ah, AR_IMR, mask);
Pavel Roskin74bad5c2010-02-23 18:15:27 -05002488 ah->imrs2_reg &= ~(AR_IMR_S2_TIM | AR_IMR_S2_DTIM | AR_IMR_S2_DTIMSYNC |
2489 AR_IMR_S2_CABEND | AR_IMR_S2_CABTO |
2490 AR_IMR_S2_TSFOOR | AR_IMR_S2_GTT | AR_IMR_S2_CST);
2491 ah->imrs2_reg |= mask2;
2492 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002493
Sujith60b67f52008-08-07 10:52:38 +05302494 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002495 if (ints & ATH9K_INT_TIM_TIMER)
2496 REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
2497 else
2498 REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
2499 }
2500
2501 if (ints & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002502 ath_print(common, ATH_DBG_INTERRUPT, "enable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002503 REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
2504 if (!AR_SREV_9100(ah)) {
2505 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
2506 AR_INTR_MAC_IRQ);
2507 REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
2508
2509
2510 REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
2511 AR_INTR_SYNC_DEFAULT);
2512 REG_WRITE(ah, AR_INTR_SYNC_MASK,
2513 AR_INTR_SYNC_DEFAULT);
2514 }
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002515 ath_print(common, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
2516 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002517 }
2518
2519 return omask;
2520}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002521EXPORT_SYMBOL(ath9k_hw_set_interrupts);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002522
Sujithf1dc5602008-10-29 10:16:30 +05302523/*******************/
2524/* Beacon Handling */
2525/*******************/
2526
Sujithcbe61d82009-02-09 13:27:12 +05302527void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002528{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002529 int flags = 0;
2530
Sujith2660b812009-02-09 13:27:26 +05302531 ah->beacon_interval = beacon_period;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002532
Sujith2660b812009-02-09 13:27:26 +05302533 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08002534 case NL80211_IFTYPE_STATION:
2535 case NL80211_IFTYPE_MONITOR:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002536 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
2537 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
2538 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
2539 flags |= AR_TBTT_TIMER_EN;
2540 break;
Colin McCabed97809d2008-12-01 13:38:55 -08002541 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04002542 case NL80211_IFTYPE_MESH_POINT:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002543 REG_SET_BIT(ah, AR_TXCFG,
2544 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
2545 REG_WRITE(ah, AR_NEXT_NDP_TIMER,
2546 TU_TO_USEC(next_beacon +
Sujith2660b812009-02-09 13:27:26 +05302547 (ah->atim_window ? ah->
2548 atim_window : 1)));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002549 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08002550 case NL80211_IFTYPE_AP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002551 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
2552 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
2553 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05302554 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302555 dma_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002556 REG_WRITE(ah, AR_NEXT_SWBA,
2557 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05302558 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302559 sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002560 flags |=
2561 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
2562 break;
Colin McCabed97809d2008-12-01 13:38:55 -08002563 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002564 ath_print(ath9k_hw_common(ah), ATH_DBG_BEACON,
2565 "%s: unsupported opmode: %d\n",
2566 __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08002567 return;
2568 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002569 }
2570
2571 REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
2572 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
2573 REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
2574 REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
2575
2576 beacon_period &= ~ATH9K_BEACON_ENA;
2577 if (beacon_period & ATH9K_BEACON_RESET_TSF) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002578 ath9k_hw_reset_tsf(ah);
2579 }
2580
2581 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
2582}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002583EXPORT_SYMBOL(ath9k_hw_beaconinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002584
Sujithcbe61d82009-02-09 13:27:12 +05302585void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05302586 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002587{
2588 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05302589 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002590 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002591
2592 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
2593
2594 REG_WRITE(ah, AR_BEACON_PERIOD,
2595 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
2596 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
2597 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
2598
2599 REG_RMW_FIELD(ah, AR_RSSI_THR,
2600 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
2601
2602 beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
2603
2604 if (bs->bs_sleepduration > beaconintval)
2605 beaconintval = bs->bs_sleepduration;
2606
2607 dtimperiod = bs->bs_dtimperiod;
2608 if (bs->bs_sleepduration > dtimperiod)
2609 dtimperiod = bs->bs_sleepduration;
2610
2611 if (beaconintval == dtimperiod)
2612 nextTbtt = bs->bs_nextdtim;
2613 else
2614 nextTbtt = bs->bs_nexttbtt;
2615
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002616 ath_print(common, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
2617 ath_print(common, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
2618 ath_print(common, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
2619 ath_print(common, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002620
2621 REG_WRITE(ah, AR_NEXT_DTIM,
2622 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
2623 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
2624
2625 REG_WRITE(ah, AR_SLEEP1,
2626 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
2627 | AR_SLEEP1_ASSUME_DTIM);
2628
Sujith60b67f52008-08-07 10:52:38 +05302629 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002630 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
2631 else
2632 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
2633
2634 REG_WRITE(ah, AR_SLEEP2,
2635 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
2636
2637 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
2638 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
2639
2640 REG_SET_BIT(ah, AR_TIMER_MODE,
2641 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
2642 AR_DTIM_TIMER_EN);
2643
Sujith4af9cf42009-02-12 10:06:47 +05302644 /* TSF Out of Range Threshold */
2645 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002646}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002647EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002648
Sujithf1dc5602008-10-29 10:16:30 +05302649/*******************/
2650/* HW Capabilities */
2651/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002652
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002653int ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002654{
Sujith2660b812009-02-09 13:27:26 +05302655 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002656 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002657 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002658 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002659
Sujithf1dc5602008-10-29 10:16:30 +05302660 u16 capField = 0, eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002661
Sujithf74df6f2009-02-09 13:27:24 +05302662 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002663 regulatory->current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05302664
Sujithf74df6f2009-02-09 13:27:24 +05302665 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
Sujithfec0de12009-02-12 10:06:43 +05302666 if (AR_SREV_9285_10_OR_LATER(ah))
2667 eeval |= AR9285_RDEXT_DEFAULT;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002668 regulatory->current_rd_ext = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05302669
Sujithf74df6f2009-02-09 13:27:24 +05302670 capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
Sujithf1dc5602008-10-29 10:16:30 +05302671
Sujith2660b812009-02-09 13:27:26 +05302672 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05302673 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002674 if (regulatory->current_rd == 0x64 ||
2675 regulatory->current_rd == 0x65)
2676 regulatory->current_rd += 5;
2677 else if (regulatory->current_rd == 0x41)
2678 regulatory->current_rd = 0x43;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002679 ath_print(common, ATH_DBG_REGULATORY,
2680 "regdomain mapped to 0x%x\n", regulatory->current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002681 }
Sujithdc2222a2008-08-14 13:26:55 +05302682
Sujithf74df6f2009-02-09 13:27:24 +05302683 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002684 if ((eeval & (AR5416_OPFLAGS_11G | AR5416_OPFLAGS_11A)) == 0) {
2685 ath_print(common, ATH_DBG_FATAL,
2686 "no band has been marked as supported in EEPROM.\n");
2687 return -EINVAL;
2688 }
2689
Sujithf1dc5602008-10-29 10:16:30 +05302690 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002691
Sujithf1dc5602008-10-29 10:16:30 +05302692 if (eeval & AR5416_OPFLAGS_11A) {
2693 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05302694 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05302695 if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
2696 set_bit(ATH9K_MODE_11NA_HT20,
2697 pCap->wireless_modes);
2698 if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
2699 set_bit(ATH9K_MODE_11NA_HT40PLUS,
2700 pCap->wireless_modes);
2701 set_bit(ATH9K_MODE_11NA_HT40MINUS,
2702 pCap->wireless_modes);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002703 }
2704 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002705 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002706
Sujithf1dc5602008-10-29 10:16:30 +05302707 if (eeval & AR5416_OPFLAGS_11G) {
Sujithf1dc5602008-10-29 10:16:30 +05302708 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05302709 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05302710 if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
2711 set_bit(ATH9K_MODE_11NG_HT20,
2712 pCap->wireless_modes);
2713 if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
2714 set_bit(ATH9K_MODE_11NG_HT40PLUS,
2715 pCap->wireless_modes);
2716 set_bit(ATH9K_MODE_11NG_HT40MINUS,
2717 pCap->wireless_modes);
2718 }
2719 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002720 }
Sujithf1dc5602008-10-29 10:16:30 +05302721
Sujithf74df6f2009-02-09 13:27:24 +05302722 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002723 /*
2724 * For AR9271 we will temporarilly uses the rx chainmax as read from
2725 * the EEPROM.
2726 */
Sujith8147f5d2009-02-20 15:13:23 +05302727 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002728 !(eeval & AR5416_OPFLAGS_11A) &&
2729 !(AR_SREV_9271(ah)))
2730 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
Sujith8147f5d2009-02-20 15:13:23 +05302731 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
2732 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002733 /* Use rx_chainmask from EEPROM. */
Sujith8147f5d2009-02-20 15:13:23 +05302734 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05302735
Sujithd535a422009-02-09 13:27:06 +05302736 if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0)))
Sujith2660b812009-02-09 13:27:26 +05302737 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05302738
2739 pCap->low_2ghz_chan = 2312;
2740 pCap->high_2ghz_chan = 2732;
2741
2742 pCap->low_5ghz_chan = 4920;
2743 pCap->high_5ghz_chan = 6100;
2744
2745 pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
2746 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
2747 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
2748
2749 pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
2750 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
2751 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
2752
Sujith2660b812009-02-09 13:27:26 +05302753 if (ah->config.ht_enable)
Sujithf1dc5602008-10-29 10:16:30 +05302754 pCap->hw_caps |= ATH9K_HW_CAP_HT;
2755 else
2756 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
2757
2758 pCap->hw_caps |= ATH9K_HW_CAP_GTT;
2759 pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
2760 pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
2761 pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
2762
2763 if (capField & AR_EEPROM_EEPCAP_MAXQCU)
2764 pCap->total_queues =
2765 MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
2766 else
2767 pCap->total_queues = ATH9K_NUM_TX_QUEUES;
2768
2769 if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
2770 pCap->keycache_size =
2771 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
2772 else
2773 pCap->keycache_size = AR_KEYTABLE_SIZE;
2774
2775 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -05002776
2777 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
2778 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD >> 1;
2779 else
2780 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
Sujithf1dc5602008-10-29 10:16:30 +05302781
Sujith5b5fa352010-03-17 14:25:15 +05302782 if (AR_SREV_9271(ah))
2783 pCap->num_gpio_pins = AR9271_NUM_GPIO;
2784 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302785 pCap->num_gpio_pins = AR9285_NUM_GPIO;
2786 else if (AR_SREV_9280_10_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302787 pCap->num_gpio_pins = AR928X_NUM_GPIO;
2788 else
2789 pCap->num_gpio_pins = AR_NUM_GPIO;
2790
Sujithf1dc5602008-10-29 10:16:30 +05302791 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
2792 pCap->hw_caps |= ATH9K_HW_CAP_CST;
2793 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
2794 } else {
2795 pCap->rts_aggr_limit = (8 * 1024);
2796 }
2797
2798 pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
2799
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05302800#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05302801 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
2802 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
2803 ah->rfkill_gpio =
2804 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
2805 ah->rfkill_polarity =
2806 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05302807
2808 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
2809 }
2810#endif
Vivek Natarajanbde748a2010-04-05 14:48:05 +05302811 if (AR_SREV_9271(ah))
2812 pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
2813 else
2814 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
Sujithf1dc5602008-10-29 10:16:30 +05302815
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302816 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302817 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
2818 else
2819 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
2820
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002821 if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) {
Sujithf1dc5602008-10-29 10:16:30 +05302822 pCap->reg_cap =
2823 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
2824 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
2825 AR_EEPROM_EEREGCAP_EN_KK_U2 |
2826 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
2827 } else {
2828 pCap->reg_cap =
2829 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
2830 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
2831 }
2832
Senthil Balasubramanianebb90cf2009-09-18 15:07:33 +05302833 /* Advertise midband for AR5416 with FCC midband set in eeprom */
2834 if (regulatory->current_rd_ext & (1 << REG_EXT_FCC_MIDBAND) &&
2835 AR_SREV_5416(ah))
2836 pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
Sujithf1dc5602008-10-29 10:16:30 +05302837
2838 pCap->num_antcfg_5ghz =
Sujithf74df6f2009-02-09 13:27:24 +05302839 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05302840 pCap->num_antcfg_2ghz =
Sujithf74df6f2009-02-09 13:27:24 +05302841 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05302842
Vasanthakumar Thiagarajanfe129462009-09-09 15:25:50 +05302843 if (AR_SREV_9280_10_OR_LATER(ah) &&
Luis R. Rodrigueza36cfbc2009-09-09 16:05:32 -07002844 ath9k_hw_btcoex_supported(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002845 btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO;
2846 btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO;
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05302847
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302848 if (AR_SREV_9285(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002849 btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
2850 btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302851 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002852 btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302853 }
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05302854 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002855 btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE;
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05302856 }
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002857
2858 return 0;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002859}
2860
Sujithcbe61d82009-02-09 13:27:12 +05302861bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05302862 u32 capability, u32 *result)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002863{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002864 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302865 switch (type) {
2866 case ATH9K_CAP_CIPHER:
2867 switch (capability) {
2868 case ATH9K_CIPHER_AES_CCM:
2869 case ATH9K_CIPHER_AES_OCB:
2870 case ATH9K_CIPHER_TKIP:
2871 case ATH9K_CIPHER_WEP:
2872 case ATH9K_CIPHER_MIC:
2873 case ATH9K_CIPHER_CLR:
2874 return true;
2875 default:
2876 return false;
2877 }
2878 case ATH9K_CAP_TKIP_MIC:
2879 switch (capability) {
2880 case 0:
2881 return true;
2882 case 1:
Sujith2660b812009-02-09 13:27:26 +05302883 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05302884 AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
2885 false;
2886 }
2887 case ATH9K_CAP_TKIP_SPLIT:
Sujith2660b812009-02-09 13:27:26 +05302888 return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ?
Sujithf1dc5602008-10-29 10:16:30 +05302889 false : true;
Sujithf1dc5602008-10-29 10:16:30 +05302890 case ATH9K_CAP_MCAST_KEYSRCH:
2891 switch (capability) {
2892 case 0:
2893 return true;
2894 case 1:
2895 if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
2896 return false;
2897 } else {
Sujith2660b812009-02-09 13:27:26 +05302898 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05302899 AR_STA_ID1_MCAST_KSRCH) ? true :
2900 false;
2901 }
2902 }
2903 return false;
Sujithf1dc5602008-10-29 10:16:30 +05302904 case ATH9K_CAP_TXPOW:
2905 switch (capability) {
2906 case 0:
2907 return 0;
2908 case 1:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002909 *result = regulatory->power_limit;
Sujithf1dc5602008-10-29 10:16:30 +05302910 return 0;
2911 case 2:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002912 *result = regulatory->max_power_level;
Sujithf1dc5602008-10-29 10:16:30 +05302913 return 0;
2914 case 3:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002915 *result = regulatory->tp_scale;
Sujithf1dc5602008-10-29 10:16:30 +05302916 return 0;
2917 }
2918 return false;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05302919 case ATH9K_CAP_DS:
2920 return (AR_SREV_9280_20_OR_LATER(ah) &&
2921 (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1))
2922 ? false : true;
Sujithf1dc5602008-10-29 10:16:30 +05302923 default:
2924 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002925 }
Sujithf1dc5602008-10-29 10:16:30 +05302926}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002927EXPORT_SYMBOL(ath9k_hw_getcapability);
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002928
Sujithcbe61d82009-02-09 13:27:12 +05302929bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05302930 u32 capability, u32 setting, int *status)
2931{
Sujithf1dc5602008-10-29 10:16:30 +05302932 switch (type) {
2933 case ATH9K_CAP_TKIP_MIC:
2934 if (setting)
Sujith2660b812009-02-09 13:27:26 +05302935 ah->sta_id1_defaults |=
Sujithf1dc5602008-10-29 10:16:30 +05302936 AR_STA_ID1_CRPT_MIC_ENABLE;
2937 else
Sujith2660b812009-02-09 13:27:26 +05302938 ah->sta_id1_defaults &=
Sujithf1dc5602008-10-29 10:16:30 +05302939 ~AR_STA_ID1_CRPT_MIC_ENABLE;
2940 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302941 case ATH9K_CAP_MCAST_KEYSRCH:
2942 if (setting)
Sujith2660b812009-02-09 13:27:26 +05302943 ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05302944 else
Sujith2660b812009-02-09 13:27:26 +05302945 ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05302946 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302947 default:
2948 return false;
2949 }
2950}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002951EXPORT_SYMBOL(ath9k_hw_setcapability);
Sujithf1dc5602008-10-29 10:16:30 +05302952
2953/****************************/
2954/* GPIO / RFKILL / Antennae */
2955/****************************/
2956
Sujithcbe61d82009-02-09 13:27:12 +05302957static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05302958 u32 gpio, u32 type)
2959{
2960 int addr;
2961 u32 gpio_shift, tmp;
2962
2963 if (gpio > 11)
2964 addr = AR_GPIO_OUTPUT_MUX3;
2965 else if (gpio > 5)
2966 addr = AR_GPIO_OUTPUT_MUX2;
2967 else
2968 addr = AR_GPIO_OUTPUT_MUX1;
2969
2970 gpio_shift = (gpio % 6) * 5;
2971
2972 if (AR_SREV_9280_20_OR_LATER(ah)
2973 || (addr != AR_GPIO_OUTPUT_MUX1)) {
2974 REG_RMW(ah, addr, (type << gpio_shift),
2975 (0x1f << gpio_shift));
2976 } else {
2977 tmp = REG_READ(ah, addr);
2978 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
2979 tmp &= ~(0x1f << gpio_shift);
2980 tmp |= (type << gpio_shift);
2981 REG_WRITE(ah, addr, tmp);
2982 }
2983}
2984
Sujithcbe61d82009-02-09 13:27:12 +05302985void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05302986{
2987 u32 gpio_shift;
2988
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07002989 BUG_ON(gpio >= ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05302990
2991 gpio_shift = gpio << 1;
2992
2993 REG_RMW(ah,
2994 AR_GPIO_OE_OUT,
2995 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
2996 (AR_GPIO_OE_OUT_DRV << gpio_shift));
2997}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002998EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
Sujithf1dc5602008-10-29 10:16:30 +05302999
Sujithcbe61d82009-02-09 13:27:12 +05303000u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303001{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303002#define MS_REG_READ(x, y) \
3003 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
3004
Sujith2660b812009-02-09 13:27:26 +05303005 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05303006 return 0xffffffff;
3007
Felix Fietkau783dfca2010-04-15 17:38:11 -04003008 if (AR_SREV_9300_20_OR_LATER(ah))
3009 return MS_REG_READ(AR9300, gpio) != 0;
3010 else if (AR_SREV_9271(ah))
Sujith5b5fa352010-03-17 14:25:15 +05303011 return MS_REG_READ(AR9271, gpio) != 0;
3012 else if (AR_SREV_9287_10_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05303013 return MS_REG_READ(AR9287, gpio) != 0;
3014 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303015 return MS_REG_READ(AR9285, gpio) != 0;
3016 else if (AR_SREV_9280_10_OR_LATER(ah))
3017 return MS_REG_READ(AR928X, gpio) != 0;
3018 else
3019 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05303020}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003021EXPORT_SYMBOL(ath9k_hw_gpio_get);
Sujithf1dc5602008-10-29 10:16:30 +05303022
Sujithcbe61d82009-02-09 13:27:12 +05303023void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05303024 u32 ah_signal_type)
3025{
3026 u32 gpio_shift;
3027
3028 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
3029
3030 gpio_shift = 2 * gpio;
3031
3032 REG_RMW(ah,
3033 AR_GPIO_OE_OUT,
3034 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
3035 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3036}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003037EXPORT_SYMBOL(ath9k_hw_cfg_output);
Sujithf1dc5602008-10-29 10:16:30 +05303038
Sujithcbe61d82009-02-09 13:27:12 +05303039void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05303040{
Sujith5b5fa352010-03-17 14:25:15 +05303041 if (AR_SREV_9271(ah))
3042 val = ~val;
3043
Sujithf1dc5602008-10-29 10:16:30 +05303044 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
3045 AR_GPIO_BIT(gpio));
3046}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003047EXPORT_SYMBOL(ath9k_hw_set_gpio);
Sujithf1dc5602008-10-29 10:16:30 +05303048
Sujithcbe61d82009-02-09 13:27:12 +05303049u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303050{
3051 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
3052}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003053EXPORT_SYMBOL(ath9k_hw_getdefantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303054
Sujithcbe61d82009-02-09 13:27:12 +05303055void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05303056{
3057 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
3058}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003059EXPORT_SYMBOL(ath9k_hw_setantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303060
Sujithf1dc5602008-10-29 10:16:30 +05303061/*********************/
3062/* General Operation */
3063/*********************/
3064
Sujithcbe61d82009-02-09 13:27:12 +05303065u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303066{
3067 u32 bits = REG_READ(ah, AR_RX_FILTER);
3068 u32 phybits = REG_READ(ah, AR_PHY_ERR);
3069
3070 if (phybits & AR_PHY_ERR_RADAR)
3071 bits |= ATH9K_RX_FILTER_PHYRADAR;
3072 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
3073 bits |= ATH9K_RX_FILTER_PHYERR;
3074
3075 return bits;
3076}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003077EXPORT_SYMBOL(ath9k_hw_getrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303078
Sujithcbe61d82009-02-09 13:27:12 +05303079void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05303080{
3081 u32 phybits;
3082
Sujith7ea310b2009-09-03 12:08:43 +05303083 REG_WRITE(ah, AR_RX_FILTER, bits);
3084
Sujithf1dc5602008-10-29 10:16:30 +05303085 phybits = 0;
3086 if (bits & ATH9K_RX_FILTER_PHYRADAR)
3087 phybits |= AR_PHY_ERR_RADAR;
3088 if (bits & ATH9K_RX_FILTER_PHYERR)
3089 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
3090 REG_WRITE(ah, AR_PHY_ERR, phybits);
3091
3092 if (phybits)
3093 REG_WRITE(ah, AR_RXCFG,
3094 REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
3095 else
3096 REG_WRITE(ah, AR_RXCFG,
3097 REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
3098}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003099EXPORT_SYMBOL(ath9k_hw_setrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303100
Sujithcbe61d82009-02-09 13:27:12 +05303101bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303102{
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05303103 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
3104 return false;
3105
3106 ath9k_hw_init_pll(ah, NULL);
3107 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303108}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003109EXPORT_SYMBOL(ath9k_hw_phy_disable);
Sujithf1dc5602008-10-29 10:16:30 +05303110
Sujithcbe61d82009-02-09 13:27:12 +05303111bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303112{
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07003113 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05303114 return false;
3115
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05303116 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
3117 return false;
3118
3119 ath9k_hw_init_pll(ah, NULL);
3120 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303121}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003122EXPORT_SYMBOL(ath9k_hw_disable);
Sujithf1dc5602008-10-29 10:16:30 +05303123
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003124void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
Sujithf1dc5602008-10-29 10:16:30 +05303125{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003126 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujith2660b812009-02-09 13:27:26 +05303127 struct ath9k_channel *chan = ah->curchan;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08003128 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05303129
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003130 regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER);
Sujithf1dc5602008-10-29 10:16:30 +05303131
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003132 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003133 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003134 channel->max_antenna_gain * 2,
3135 channel->max_power * 2,
3136 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003137 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05303138}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003139EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
Sujithf1dc5602008-10-29 10:16:30 +05303140
Sujithcbe61d82009-02-09 13:27:12 +05303141void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac)
Sujithf1dc5602008-10-29 10:16:30 +05303142{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07003143 memcpy(ath9k_hw_common(ah)->macaddr, mac, ETH_ALEN);
Sujithf1dc5602008-10-29 10:16:30 +05303144}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003145EXPORT_SYMBOL(ath9k_hw_setmac);
Sujithf1dc5602008-10-29 10:16:30 +05303146
Sujithcbe61d82009-02-09 13:27:12 +05303147void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303148{
Sujith2660b812009-02-09 13:27:26 +05303149 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05303150}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003151EXPORT_SYMBOL(ath9k_hw_setopmode);
Sujithf1dc5602008-10-29 10:16:30 +05303152
Sujithcbe61d82009-02-09 13:27:12 +05303153void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05303154{
3155 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
3156 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
3157}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003158EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303159
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07003160void ath9k_hw_write_associd(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303161{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07003162 struct ath_common *common = ath9k_hw_common(ah);
3163
3164 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
3165 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
3166 ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05303167}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003168EXPORT_SYMBOL(ath9k_hw_write_associd);
Sujithf1dc5602008-10-29 10:16:30 +05303169
Sujithcbe61d82009-02-09 13:27:12 +05303170u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303171{
3172 u64 tsf;
3173
3174 tsf = REG_READ(ah, AR_TSF_U32);
3175 tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
3176
3177 return tsf;
3178}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003179EXPORT_SYMBOL(ath9k_hw_gettsf64);
Sujithf1dc5602008-10-29 10:16:30 +05303180
Sujithcbe61d82009-02-09 13:27:12 +05303181void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003182{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003183 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01003184 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003185}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003186EXPORT_SYMBOL(ath9k_hw_settsf64);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003187
Sujithcbe61d82009-02-09 13:27:12 +05303188void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303189{
Gabor Juhosf9b604f2009-06-21 00:02:15 +02003190 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
3191 AH_TSF_WRITE_TIMEOUT))
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003192 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
3193 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
Gabor Juhosf9b604f2009-06-21 00:02:15 +02003194
Sujithf1dc5602008-10-29 10:16:30 +05303195 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003196}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003197EXPORT_SYMBOL(ath9k_hw_reset_tsf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003198
Sujith54e4cec2009-08-07 09:45:09 +05303199void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003200{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003201 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303202 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003203 else
Sujith2660b812009-02-09 13:27:26 +05303204 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003205}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003206EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003207
Luis R. Rodriguez30cbd422009-11-03 16:10:46 -08003208/*
3209 * Extend 15-bit time stamp from rx descriptor to
3210 * a full 64-bit TSF using the current h/w TSF.
3211*/
3212u64 ath9k_hw_extend_tsf(struct ath_hw *ah, u32 rstamp)
3213{
3214 u64 tsf;
3215
3216 tsf = ath9k_hw_gettsf64(ah);
3217 if ((tsf & 0x7fff) < rstamp)
3218 tsf -= 0x8000;
3219 return (tsf & ~0x7fff) | rstamp;
3220}
3221EXPORT_SYMBOL(ath9k_hw_extend_tsf);
3222
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003223void ath9k_hw_set11nmac2040(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003224{
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003225 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithf1dc5602008-10-29 10:16:30 +05303226 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003227
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003228 if (conf_is_ht40(conf) && !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05303229 macmode = AR_2040_JOINED_RX_CLEAR;
3230 else
3231 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003232
Sujithf1dc5602008-10-29 10:16:30 +05303233 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003234}
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303235
3236/* HW Generic timers configuration */
3237
3238static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
3239{
3240 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3241 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3242 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3243 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3244 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3245 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3246 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3247 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3248 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
3249 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
3250 AR_NDP2_TIMER_MODE, 0x0002},
3251 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
3252 AR_NDP2_TIMER_MODE, 0x0004},
3253 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
3254 AR_NDP2_TIMER_MODE, 0x0008},
3255 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
3256 AR_NDP2_TIMER_MODE, 0x0010},
3257 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
3258 AR_NDP2_TIMER_MODE, 0x0020},
3259 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
3260 AR_NDP2_TIMER_MODE, 0x0040},
3261 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
3262 AR_NDP2_TIMER_MODE, 0x0080}
3263};
3264
3265/* HW generic timer primitives */
3266
3267/* compute and clear index of rightmost 1 */
3268static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
3269{
3270 u32 b;
3271
3272 b = *mask;
3273 b &= (0-b);
3274 *mask &= ~b;
3275 b *= debruijn32;
3276 b >>= 27;
3277
3278 return timer_table->gen_timer_index[b];
3279}
3280
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05303281u32 ath9k_hw_gettsf32(struct ath_hw *ah)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303282{
3283 return REG_READ(ah, AR_TSF_L32);
3284}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003285EXPORT_SYMBOL(ath9k_hw_gettsf32);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303286
3287struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
3288 void (*trigger)(void *),
3289 void (*overflow)(void *),
3290 void *arg,
3291 u8 timer_index)
3292{
3293 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3294 struct ath_gen_timer *timer;
3295
3296 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
3297
3298 if (timer == NULL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003299 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
3300 "Failed to allocate memory"
3301 "for hw timer[%d]\n", timer_index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303302 return NULL;
3303 }
3304
3305 /* allocate a hardware generic timer slot */
3306 timer_table->timers[timer_index] = timer;
3307 timer->index = timer_index;
3308 timer->trigger = trigger;
3309 timer->overflow = overflow;
3310 timer->arg = arg;
3311
3312 return timer;
3313}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003314EXPORT_SYMBOL(ath_gen_timer_alloc);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303315
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07003316void ath9k_hw_gen_timer_start(struct ath_hw *ah,
3317 struct ath_gen_timer *timer,
3318 u32 timer_next,
3319 u32 timer_period)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303320{
3321 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3322 u32 tsf;
3323
3324 BUG_ON(!timer_period);
3325
3326 set_bit(timer->index, &timer_table->timer_mask.timer_bits);
3327
3328 tsf = ath9k_hw_gettsf32(ah);
3329
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003330 ath_print(ath9k_hw_common(ah), ATH_DBG_HWTIMER,
3331 "curent tsf %x period %x"
3332 "timer_next %x\n", tsf, timer_period, timer_next);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303333
3334 /*
3335 * Pull timer_next forward if the current TSF already passed it
3336 * because of software latency
3337 */
3338 if (timer_next < tsf)
3339 timer_next = tsf + timer_period;
3340
3341 /*
3342 * Program generic timer registers
3343 */
3344 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
3345 timer_next);
3346 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
3347 timer_period);
3348 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
3349 gen_tmr_configuration[timer->index].mode_mask);
3350
3351 /* Enable both trigger and thresh interrupt masks */
3352 REG_SET_BIT(ah, AR_IMR_S5,
3353 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
3354 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303355}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003356EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303357
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07003358void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303359{
3360 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3361
3362 if ((timer->index < AR_FIRST_NDP_TIMER) ||
3363 (timer->index >= ATH_MAX_GEN_TIMER)) {
3364 return;
3365 }
3366
3367 /* Clear generic timer enable bits. */
3368 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
3369 gen_tmr_configuration[timer->index].mode_mask);
3370
3371 /* Disable both trigger and thresh interrupt masks */
3372 REG_CLR_BIT(ah, AR_IMR_S5,
3373 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
3374 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
3375
3376 clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303377}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003378EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303379
3380void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
3381{
3382 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3383
3384 /* free the hardware generic timer slot */
3385 timer_table->timers[timer->index] = NULL;
3386 kfree(timer);
3387}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003388EXPORT_SYMBOL(ath_gen_timer_free);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303389
3390/*
3391 * Generic Timer Interrupts handling
3392 */
3393void ath_gen_timer_isr(struct ath_hw *ah)
3394{
3395 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3396 struct ath_gen_timer *timer;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003397 struct ath_common *common = ath9k_hw_common(ah);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303398 u32 trigger_mask, thresh_mask, index;
3399
3400 /* get hardware generic timer interrupt status */
3401 trigger_mask = ah->intr_gen_timer_trigger;
3402 thresh_mask = ah->intr_gen_timer_thresh;
3403 trigger_mask &= timer_table->timer_mask.val;
3404 thresh_mask &= timer_table->timer_mask.val;
3405
3406 trigger_mask &= ~thresh_mask;
3407
3408 while (thresh_mask) {
3409 index = rightmost_index(timer_table, &thresh_mask);
3410 timer = timer_table->timers[index];
3411 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003412 ath_print(common, ATH_DBG_HWTIMER,
3413 "TSF overflow for Gen timer %d\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303414 timer->overflow(timer->arg);
3415 }
3416
3417 while (trigger_mask) {
3418 index = rightmost_index(timer_table, &trigger_mask);
3419 timer = timer_table->timers[index];
3420 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003421 ath_print(common, ATH_DBG_HWTIMER,
3422 "Gen timer[%d] trigger\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303423 timer->trigger(timer->arg);
3424 }
3425}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003426EXPORT_SYMBOL(ath_gen_timer_isr);
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003427
Sujith05020d22010-03-17 14:25:23 +05303428/********/
3429/* HTC */
3430/********/
3431
3432void ath9k_hw_htc_resetinit(struct ath_hw *ah)
3433{
3434 ah->htc_reset_init = true;
3435}
3436EXPORT_SYMBOL(ath9k_hw_htc_resetinit);
3437
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003438static struct {
3439 u32 version;
3440 const char * name;
3441} ath_mac_bb_names[] = {
3442 /* Devices with external radios */
3443 { AR_SREV_VERSION_5416_PCI, "5416" },
3444 { AR_SREV_VERSION_5416_PCIE, "5418" },
3445 { AR_SREV_VERSION_9100, "9100" },
3446 { AR_SREV_VERSION_9160, "9160" },
3447 /* Single-chip solutions */
3448 { AR_SREV_VERSION_9280, "9280" },
3449 { AR_SREV_VERSION_9285, "9285" },
Luis R. Rodriguez11158472009-10-27 12:59:35 -04003450 { AR_SREV_VERSION_9287, "9287" },
3451 { AR_SREV_VERSION_9271, "9271" },
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003452};
3453
3454/* For devices with external radios */
3455static struct {
3456 u16 version;
3457 const char * name;
3458} ath_rf_names[] = {
3459 { 0, "5133" },
3460 { AR_RAD5133_SREV_MAJOR, "5133" },
3461 { AR_RAD5122_SREV_MAJOR, "5122" },
3462 { AR_RAD2133_SREV_MAJOR, "2133" },
3463 { AR_RAD2122_SREV_MAJOR, "2122" }
3464};
3465
3466/*
3467 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
3468 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003469static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003470{
3471 int i;
3472
3473 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
3474 if (ath_mac_bb_names[i].version == mac_bb_version) {
3475 return ath_mac_bb_names[i].name;
3476 }
3477 }
3478
3479 return "????";
3480}
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003481
3482/*
3483 * Return the RF name. "????" is returned if the RF is unknown.
3484 * Used for devices with external radios.
3485 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003486static const char *ath9k_hw_rf_name(u16 rf_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003487{
3488 int i;
3489
3490 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
3491 if (ath_rf_names[i].version == rf_version) {
3492 return ath_rf_names[i].name;
3493 }
3494 }
3495
3496 return "????";
3497}
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003498
3499void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
3500{
3501 int used;
3502
3503 /* chipsets >= AR9280 are single-chip */
3504 if (AR_SREV_9280_10_OR_LATER(ah)) {
3505 used = snprintf(hw_name, len,
3506 "Atheros AR%s Rev:%x",
3507 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3508 ah->hw_version.macRev);
3509 }
3510 else {
3511 used = snprintf(hw_name, len,
3512 "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
3513 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3514 ah->hw_version.macRev,
3515 ath9k_hw_rf_name((ah->hw_version.analog5GhzRev &
3516 AR_RADIO_SREV_MAJOR)),
3517 ah->hw_version.phyRev);
3518 }
3519
3520 hw_name[used] = '\0';
3521}
3522EXPORT_SYMBOL(ath9k_hw_name);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04003523
3524/* Sets up the AR5008/AR9001/AR9002 hardware familiy callbacks */
3525static void ar9002_hw_attach_ops(struct ath_hw *ah)
3526{
3527 struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
3528 struct ath_hw_ops *ops = ath9k_hw_ops(ah);
3529
3530 priv_ops->init_cal_settings = ar9002_hw_init_cal_settings;
3531 priv_ops->init_mode_regs = ar9002_hw_init_mode_regs;
3532 priv_ops->macversion_supported = ar9002_hw_macversion_supported;
3533
3534 ops->config_pci_powersave = ar9002_hw_configpcipowersave;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04003535
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04003536 ar5008_hw_attach_phy_ops(ah);
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04003537 if (AR_SREV_9280_10_OR_LATER(ah))
3538 ar9002_hw_attach_phy_ops(ah);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04003539}
3540
3541/* Sets up the AR9003 hardware familiy callbacks */
3542static void ar9003_hw_attach_ops(struct ath_hw *ah)
3543{
3544 ar9003_hw_attach_phy_ops(ah);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04003545}