blob: 65c3b9e5d9c3e026db869cc785db031a366bbf04 [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 }
Sujith04bd46382008-11-28 22:18:05 +0530113
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700114 ath_print(ath9k_hw_common(ah), ATH_DBG_ANY,
115 "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
116 timeout, reg, REG_READ(ah, reg), mask, val);
Sujithf1dc5602008-10-29 10:16:30 +0530117
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700118 return false;
119}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400120EXPORT_SYMBOL(ath9k_hw_wait);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700121
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700122u32 ath9k_hw_reverse_bits(u32 val, u32 n)
123{
124 u32 retval;
125 int i;
126
127 for (i = 0, retval = 0; i < n; i++) {
128 retval = (retval << 1) | (val & 1);
129 val >>= 1;
130 }
131 return retval;
132}
133
Sujithcbe61d82009-02-09 13:27:12 +0530134bool ath9k_get_channel_edges(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530135 u16 flags, u16 *low,
136 u16 *high)
137{
Sujith2660b812009-02-09 13:27:26 +0530138 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530139
140 if (flags & CHANNEL_5GHZ) {
141 *low = pCap->low_5ghz_chan;
142 *high = pCap->high_5ghz_chan;
143 return true;
144 }
145 if ((flags & CHANNEL_2GHZ)) {
146 *low = pCap->low_2ghz_chan;
147 *high = pCap->high_2ghz_chan;
148 return true;
149 }
150 return false;
151}
152
Sujithcbe61d82009-02-09 13:27:12 +0530153u16 ath9k_hw_computetxtime(struct ath_hw *ah,
Felix Fietkau545750d2009-11-23 22:21:01 +0100154 u8 phy, int kbps,
Sujithf1dc5602008-10-29 10:16:30 +0530155 u32 frameLen, u16 rateix,
156 bool shortPreamble)
157{
158 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
Sujithf1dc5602008-10-29 10:16:30 +0530159
160 if (kbps == 0)
161 return 0;
162
Felix Fietkau545750d2009-11-23 22:21:01 +0100163 switch (phy) {
Sujith46d14a52008-11-18 09:08:13 +0530164 case WLAN_RC_PHY_CCK:
Sujithf1dc5602008-10-29 10:16:30 +0530165 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
Felix Fietkau545750d2009-11-23 22:21:01 +0100166 if (shortPreamble)
Sujithf1dc5602008-10-29 10:16:30 +0530167 phyTime >>= 1;
168 numBits = frameLen << 3;
169 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
170 break;
Sujith46d14a52008-11-18 09:08:13 +0530171 case WLAN_RC_PHY_OFDM:
Sujith2660b812009-02-09 13:27:26 +0530172 if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530173 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
174 numBits = OFDM_PLCP_BITS + (frameLen << 3);
175 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
176 txTime = OFDM_SIFS_TIME_QUARTER
177 + OFDM_PREAMBLE_TIME_QUARTER
178 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
Sujith2660b812009-02-09 13:27:26 +0530179 } else if (ah->curchan &&
180 IS_CHAN_HALF_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530181 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
182 numBits = OFDM_PLCP_BITS + (frameLen << 3);
183 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
184 txTime = OFDM_SIFS_TIME_HALF +
185 OFDM_PREAMBLE_TIME_HALF
186 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
187 } else {
188 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
189 numBits = OFDM_PLCP_BITS + (frameLen << 3);
190 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
191 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
192 + (numSymbols * OFDM_SYMBOL_TIME);
193 }
194 break;
195 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700196 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
Felix Fietkau545750d2009-11-23 22:21:01 +0100197 "Unknown phy %u (rate ix %u)\n", phy, rateix);
Sujithf1dc5602008-10-29 10:16:30 +0530198 txTime = 0;
199 break;
200 }
201
202 return txTime;
203}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400204EXPORT_SYMBOL(ath9k_hw_computetxtime);
Sujithf1dc5602008-10-29 10:16:30 +0530205
Sujithcbe61d82009-02-09 13:27:12 +0530206void ath9k_hw_get_channel_centers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530207 struct ath9k_channel *chan,
208 struct chan_centers *centers)
209{
210 int8_t extoff;
Sujithf1dc5602008-10-29 10:16:30 +0530211
212 if (!IS_CHAN_HT40(chan)) {
213 centers->ctl_center = centers->ext_center =
214 centers->synth_center = chan->channel;
215 return;
216 }
217
218 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
219 (chan->chanmode == CHANNEL_G_HT40PLUS)) {
220 centers->synth_center =
221 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
222 extoff = 1;
223 } else {
224 centers->synth_center =
225 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
226 extoff = -1;
227 }
228
229 centers->ctl_center =
230 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700231 /* 25 MHz spacing is supported by hw but not on upper layers */
Sujithf1dc5602008-10-29 10:16:30 +0530232 centers->ext_center =
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700233 centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT);
Sujithf1dc5602008-10-29 10:16:30 +0530234}
235
236/******************/
237/* Chip Revisions */
238/******************/
239
Sujithcbe61d82009-02-09 13:27:12 +0530240static void ath9k_hw_read_revisions(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530241{
242 u32 val;
243
244 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
245
246 if (val == 0xFF) {
247 val = REG_READ(ah, AR_SREV);
Sujithd535a422009-02-09 13:27:06 +0530248 ah->hw_version.macVersion =
249 (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
250 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
Sujith2660b812009-02-09 13:27:26 +0530251 ah->is_pciexpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
Sujithf1dc5602008-10-29 10:16:30 +0530252 } else {
253 if (!AR_SREV_9100(ah))
Sujithd535a422009-02-09 13:27:06 +0530254 ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
Sujithf1dc5602008-10-29 10:16:30 +0530255
Sujithd535a422009-02-09 13:27:06 +0530256 ah->hw_version.macRev = val & AR_SREV_REVISION;
Sujithf1dc5602008-10-29 10:16:30 +0530257
Sujithd535a422009-02-09 13:27:06 +0530258 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
Sujith2660b812009-02-09 13:27:26 +0530259 ah->is_pciexpress = true;
Sujithf1dc5602008-10-29 10:16:30 +0530260 }
261}
262
Sujithcbe61d82009-02-09 13:27:12 +0530263static int ath9k_hw_get_radiorev(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530264{
265 u32 val;
266 int i;
267
268 REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
269
270 for (i = 0; i < 8; i++)
271 REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
272 val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
273 val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
274
275 return ath9k_hw_reverse_bits(val, 8);
276}
277
278/************************************/
279/* HW Attach, Detach, Init Routines */
280/************************************/
281
Sujithcbe61d82009-02-09 13:27:12 +0530282static void ath9k_hw_disablepcie(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530283{
Sujithfeed0292009-01-29 11:37:35 +0530284 if (AR_SREV_9100(ah))
Sujithf1dc5602008-10-29 10:16:30 +0530285 return;
286
287 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
288 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
289 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
290 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
291 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
292 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
293 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
294 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
295 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
296
297 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
298}
299
Sujithcbe61d82009-02-09 13:27:12 +0530300static bool ath9k_hw_chip_test(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530301{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700302 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530303 u32 regAddr[2] = { AR_STA_ID0, AR_PHY_BASE + (8 << 2) };
304 u32 regHold[2];
305 u32 patternData[4] = { 0x55555555,
306 0xaaaaaaaa,
307 0x66666666,
308 0x99999999 };
309 int i, j;
310
311 for (i = 0; i < 2; i++) {
312 u32 addr = regAddr[i];
313 u32 wrData, rdData;
314
315 regHold[i] = REG_READ(ah, addr);
316 for (j = 0; j < 0x100; j++) {
317 wrData = (j << 16) | j;
318 REG_WRITE(ah, addr, wrData);
319 rdData = REG_READ(ah, addr);
320 if (rdData != wrData) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700321 ath_print(common, ATH_DBG_FATAL,
322 "address test failed "
323 "addr: 0x%08x - wr:0x%08x != "
324 "rd:0x%08x\n",
325 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530326 return false;
327 }
328 }
329 for (j = 0; j < 4; j++) {
330 wrData = patternData[j];
331 REG_WRITE(ah, addr, wrData);
332 rdData = REG_READ(ah, addr);
333 if (wrData != rdData) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700334 ath_print(common, ATH_DBG_FATAL,
335 "address test failed "
336 "addr: 0x%08x - wr:0x%08x != "
337 "rd:0x%08x\n",
338 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530339 return false;
340 }
341 }
342 REG_WRITE(ah, regAddr[i], regHold[i]);
343 }
344 udelay(100);
Sujithcbe61d82009-02-09 13:27:12 +0530345
Sujithf1dc5602008-10-29 10:16:30 +0530346 return true;
347}
348
Luis R. Rodriguezb8b0f372009-08-03 12:24:43 -0700349static void ath9k_hw_init_config(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700350{
351 int i;
352
Sujith2660b812009-02-09 13:27:26 +0530353 ah->config.dma_beacon_response_time = 2;
354 ah->config.sw_beacon_response_time = 10;
355 ah->config.additional_swba_backoff = 0;
356 ah->config.ack_6mb = 0x0;
357 ah->config.cwm_ignore_extcca = 0;
358 ah->config.pcie_powersave_enable = 0;
Sujith2660b812009-02-09 13:27:26 +0530359 ah->config.pcie_clock_req = 0;
Sujith2660b812009-02-09 13:27:26 +0530360 ah->config.pcie_waen = 0;
361 ah->config.analog_shiftreg = 1;
Sujith2660b812009-02-09 13:27:26 +0530362 ah->config.ofdm_trig_low = 200;
363 ah->config.ofdm_trig_high = 500;
364 ah->config.cck_trig_high = 200;
365 ah->config.cck_trig_low = 100;
366 ah->config.enable_ani = 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700367
368 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujith2660b812009-02-09 13:27:26 +0530369 ah->config.spurchans[i][0] = AR_NO_SPUR;
370 ah->config.spurchans[i][1] = AR_NO_SPUR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700371 }
372
Luis R. Rodriguez5ffaf8a2010-02-02 11:58:33 -0500373 if (ah->hw_version.devid != AR2427_DEVID_PCIE)
374 ah->config.ht_enable = 1;
375 else
376 ah->config.ht_enable = 0;
377
Sujith0ce024c2009-12-14 14:57:00 +0530378 ah->config.rx_intr_mitigation = true;
Luis R. Rodriguez61584252009-03-12 18:18:49 -0400379
380 /*
381 * We need this for PCI devices only (Cardbus, PCI, miniPCI)
382 * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
383 * This means we use it for all AR5416 devices, and the few
384 * minor PCI AR9280 devices out there.
385 *
386 * Serialization is required because these devices do not handle
387 * well the case of two concurrent reads/writes due to the latency
388 * involved. During one read/write another read/write can be issued
389 * on another CPU while the previous read/write may still be working
390 * on our hardware, if we hit this case the hardware poops in a loop.
391 * We prevent this by serializing reads and writes.
392 *
393 * This issue is not present on PCI-Express devices or pre-AR5416
394 * devices (legacy, 802.11abg).
395 */
396 if (num_possible_cpus() > 1)
David S. Miller2d6a5e92009-03-17 15:01:30 -0700397 ah->config.serialize_regmode = SER_REG_MODE_AUTO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700398}
399
Luis R. Rodriguez50aca252009-08-03 12:24:42 -0700400static void ath9k_hw_init_defaults(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700401{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700402 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
403
404 regulatory->country_code = CTRY_DEFAULT;
405 regulatory->power_limit = MAX_RATE_POWER;
406 regulatory->tp_scale = ATH9K_TP_SCALE_MAX;
407
Sujithd535a422009-02-09 13:27:06 +0530408 ah->hw_version.magic = AR5416_MAGIC;
Sujithd535a422009-02-09 13:27:06 +0530409 ah->hw_version.subvendorid = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700410
411 ah->ah_flags = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700412 if (!AR_SREV_9100(ah))
413 ah->ah_flags = AH_USE_EEPROM;
414
Sujith2660b812009-02-09 13:27:26 +0530415 ah->atim_window = 0;
Sujith2660b812009-02-09 13:27:26 +0530416 ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
417 ah->beacon_interval = 100;
418 ah->enable_32kHz_clock = DONT_USE_32KHZ;
419 ah->slottime = (u32) -1;
Sujith2660b812009-02-09 13:27:26 +0530420 ah->globaltxtimeout = (u32) -1;
Gabor Juhoscbdec972009-07-24 17:27:22 +0200421 ah->power_mode = ATH9K_PM_UNDEFINED;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700422}
423
Sujithcbe61d82009-02-09 13:27:12 +0530424static int ath9k_hw_rf_claim(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700425{
426 u32 val;
427
428 REG_WRITE(ah, AR_PHY(0), 0x00000007);
429
430 val = ath9k_hw_get_radiorev(ah);
431 switch (val & AR_RADIO_SREV_MAJOR) {
432 case 0:
433 val = AR_RAD5133_SREV_MAJOR;
434 break;
435 case AR_RAD5133_SREV_MAJOR:
436 case AR_RAD5122_SREV_MAJOR:
437 case AR_RAD2133_SREV_MAJOR:
438 case AR_RAD2122_SREV_MAJOR:
439 break;
440 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700441 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
442 "Radio Chip Rev 0x%02X not supported\n",
443 val & AR_RADIO_SREV_MAJOR);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700444 return -EOPNOTSUPP;
445 }
446
Sujithd535a422009-02-09 13:27:06 +0530447 ah->hw_version.analog5GhzRev = val;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700448
449 return 0;
450}
451
Sujithcbe61d82009-02-09 13:27:12 +0530452static int ath9k_hw_init_macaddr(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700453{
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700454 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530455 u32 sum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700456 int i;
Sujithf1dc5602008-10-29 10:16:30 +0530457 u16 eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700458
Sujithf1dc5602008-10-29 10:16:30 +0530459 sum = 0;
460 for (i = 0; i < 3; i++) {
Sujithf74df6f2009-02-09 13:27:24 +0530461 eeval = ah->eep_ops->get_eeprom(ah, AR_EEPROM_MAC(i));
Sujithf1dc5602008-10-29 10:16:30 +0530462 sum += eeval;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700463 common->macaddr[2 * i] = eeval >> 8;
464 common->macaddr[2 * i + 1] = eeval & 0xff;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700465 }
Sujithd8baa932009-03-30 15:28:25 +0530466 if (sum == 0 || sum == 0xffff * 3)
Sujithf1dc5602008-10-29 10:16:30 +0530467 return -EADDRNOTAVAIL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700468
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700469 return 0;
470}
471
Sujithcbe61d82009-02-09 13:27:12 +0530472static void ath9k_hw_init_rxgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530473{
474 u32 rxgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530475
Sujithf74df6f2009-02-09 13:27:24 +0530476 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_17) {
477 rxgain_type = ah->eep_ops->get_eeprom(ah, EEP_RXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530478
479 if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530480 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530481 ar9280Modes_backoff_13db_rxgain_9280_2,
482 ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2), 6);
483 else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530484 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530485 ar9280Modes_backoff_23db_rxgain_9280_2,
486 ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 6);
487 else
Sujith2660b812009-02-09 13:27:26 +0530488 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530489 ar9280Modes_original_rxgain_9280_2,
490 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530491 } else {
Sujith2660b812009-02-09 13:27:26 +0530492 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530493 ar9280Modes_original_rxgain_9280_2,
494 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530495 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530496}
497
Sujithcbe61d82009-02-09 13:27:12 +0530498static void ath9k_hw_init_txgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530499{
500 u32 txgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530501
Sujithf74df6f2009-02-09 13:27:24 +0530502 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_19) {
503 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530504
505 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
Sujith2660b812009-02-09 13:27:26 +0530506 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530507 ar9280Modes_high_power_tx_gain_9280_2,
508 ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 6);
509 else
Sujith2660b812009-02-09 13:27:26 +0530510 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530511 ar9280Modes_original_tx_gain_9280_2,
512 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530513 } else {
Sujith2660b812009-02-09 13:27:26 +0530514 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530515 ar9280Modes_original_tx_gain_9280_2,
516 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530517 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530518}
519
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700520static int ath9k_hw_post_init(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700521{
522 int ecode;
523
Sujith527d4852010-03-17 14:25:16 +0530524 if (!AR_SREV_9271(ah)) {
525 if (!ath9k_hw_chip_test(ah))
526 return -ENODEV;
527 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700528
529 ecode = ath9k_hw_rf_claim(ah);
530 if (ecode != 0)
531 return ecode;
532
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700533 ecode = ath9k_hw_eeprom_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700534 if (ecode != 0)
535 return ecode;
Sujith7d01b222009-03-13 08:55:55 +0530536
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700537 ath_print(ath9k_hw_common(ah), ATH_DBG_CONFIG,
538 "Eeprom VER: %d, REV: %d\n",
539 ah->eep_ops->get_eeprom_ver(ah),
540 ah->eep_ops->get_eeprom_rev(ah));
Sujith7d01b222009-03-13 08:55:55 +0530541
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400542 ecode = ath9k_hw_rf_alloc_ext_banks(ah);
543 if (ecode) {
544 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
545 "Failed allocating banks for "
546 "external radio\n");
547 return ecode;
Luis R. Rodriguez574d6b12009-10-19 02:33:37 -0400548 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700549
550 if (!AR_SREV_9100(ah)) {
551 ath9k_hw_ani_setup(ah);
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700552 ath9k_hw_ani_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700553 }
Sujithf1dc5602008-10-29 10:16:30 +0530554
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700555 return 0;
556}
557
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400558static bool ar9002_hw_macversion_supported(u32 macversion)
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700559{
560 switch (macversion) {
561 case AR_SREV_VERSION_5416_PCI:
562 case AR_SREV_VERSION_5416_PCIE:
563 case AR_SREV_VERSION_9160:
564 case AR_SREV_VERSION_9100:
565 case AR_SREV_VERSION_9280:
566 case AR_SREV_VERSION_9285:
567 case AR_SREV_VERSION_9287:
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400568 case AR_SREV_VERSION_9271:
Luis R. Rodriguez7976b422009-09-23 23:07:02 -0400569 return true;
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700570 default:
571 break;
572 }
573 return false;
574}
575
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400576static void ar9002_hw_init_cal_settings(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700577{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700578 if (AR_SREV_9160_10_OR_LATER(ah)) {
579 if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530580 ah->iq_caldata.calData = &iq_cal_single_sample;
581 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700582 &adc_gain_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530583 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700584 &adc_dc_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530585 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700586 &adc_init_dc_cal;
587 } else {
Sujith2660b812009-02-09 13:27:26 +0530588 ah->iq_caldata.calData = &iq_cal_multi_sample;
589 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700590 &adc_gain_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530591 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700592 &adc_dc_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530593 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700594 &adc_init_dc_cal;
595 }
Sujith2660b812009-02-09 13:27:26 +0530596 ah->supp_cals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700597 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700598}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700599
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400600static void ar9002_hw_init_mode_regs(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700601{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400602 if (AR_SREV_9271(ah)) {
Luis R. Rodriguez85643282009-10-19 02:33:33 -0400603 INIT_INI_ARRAY(&ah->iniModes, ar9271Modes_9271,
604 ARRAY_SIZE(ar9271Modes_9271), 6);
605 INIT_INI_ARRAY(&ah->iniCommon, ar9271Common_9271,
606 ARRAY_SIZE(ar9271Common_9271), 2);
Sujith70807e92010-03-17 14:25:14 +0530607 INIT_INI_ARRAY(&ah->iniCommon_normal_cck_fir_coeff_9271,
608 ar9271Common_normal_cck_fir_coeff_9271,
609 ARRAY_SIZE(ar9271Common_normal_cck_fir_coeff_9271), 2);
610 INIT_INI_ARRAY(&ah->iniCommon_japan_2484_cck_fir_coeff_9271,
611 ar9271Common_japan_2484_cck_fir_coeff_9271,
612 ARRAY_SIZE(ar9271Common_japan_2484_cck_fir_coeff_9271), 2);
Luis R. Rodriguez85643282009-10-19 02:33:33 -0400613 INIT_INI_ARRAY(&ah->iniModes_9271_1_0_only,
614 ar9271Modes_9271_1_0_only,
615 ARRAY_SIZE(ar9271Modes_9271_1_0_only), 6);
Sujith70807e92010-03-17 14:25:14 +0530616 INIT_INI_ARRAY(&ah->iniModes_9271_ANI_reg, ar9271Modes_9271_ANI_reg,
617 ARRAY_SIZE(ar9271Modes_9271_ANI_reg), 6);
618 INIT_INI_ARRAY(&ah->iniModes_high_power_tx_gain_9271,
619 ar9271Modes_high_power_tx_gain_9271,
620 ARRAY_SIZE(ar9271Modes_high_power_tx_gain_9271), 6);
621 INIT_INI_ARRAY(&ah->iniModes_normal_power_tx_gain_9271,
622 ar9271Modes_normal_power_tx_gain_9271,
623 ARRAY_SIZE(ar9271Modes_normal_power_tx_gain_9271), 6);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400624 return;
625 }
626
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530627 if (AR_SREV_9287_11_OR_LATER(ah)) {
628 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_1,
629 ARRAY_SIZE(ar9287Modes_9287_1_1), 6);
630 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_1,
631 ARRAY_SIZE(ar9287Common_9287_1_1), 2);
632 if (ah->config.pcie_clock_req)
633 INIT_INI_ARRAY(&ah->iniPcieSerdes,
634 ar9287PciePhy_clkreq_off_L1_9287_1_1,
635 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_1), 2);
636 else
637 INIT_INI_ARRAY(&ah->iniPcieSerdes,
638 ar9287PciePhy_clkreq_always_on_L1_9287_1_1,
639 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_1),
640 2);
641 } else if (AR_SREV_9287_10_OR_LATER(ah)) {
642 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_0,
643 ARRAY_SIZE(ar9287Modes_9287_1_0), 6);
644 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_0,
645 ARRAY_SIZE(ar9287Common_9287_1_0), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700646
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530647 if (ah->config.pcie_clock_req)
648 INIT_INI_ARRAY(&ah->iniPcieSerdes,
649 ar9287PciePhy_clkreq_off_L1_9287_1_0,
650 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_0), 2);
651 else
652 INIT_INI_ARRAY(&ah->iniPcieSerdes,
653 ar9287PciePhy_clkreq_always_on_L1_9287_1_0,
654 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_0),
655 2);
656 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
657
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530658
Sujith2660b812009-02-09 13:27:26 +0530659 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530660 ARRAY_SIZE(ar9285Modes_9285_1_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530661 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530662 ARRAY_SIZE(ar9285Common_9285_1_2), 2);
663
Sujith2660b812009-02-09 13:27:26 +0530664 if (ah->config.pcie_clock_req) {
665 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530666 ar9285PciePhy_clkreq_off_L1_9285_1_2,
667 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2);
668 } else {
Sujith2660b812009-02-09 13:27:26 +0530669 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530670 ar9285PciePhy_clkreq_always_on_L1_9285_1_2,
671 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2),
672 2);
673 }
674 } else if (AR_SREV_9285_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530675 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530676 ARRAY_SIZE(ar9285Modes_9285), 6);
Sujith2660b812009-02-09 13:27:26 +0530677 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530678 ARRAY_SIZE(ar9285Common_9285), 2);
679
Sujith2660b812009-02-09 13:27:26 +0530680 if (ah->config.pcie_clock_req) {
681 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530682 ar9285PciePhy_clkreq_off_L1_9285,
683 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2);
684 } else {
Sujith2660b812009-02-09 13:27:26 +0530685 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530686 ar9285PciePhy_clkreq_always_on_L1_9285,
687 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285), 2);
688 }
689 } else if (AR_SREV_9280_20_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530690 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700691 ARRAY_SIZE(ar9280Modes_9280_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530692 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700693 ARRAY_SIZE(ar9280Common_9280_2), 2);
694
Sujith2660b812009-02-09 13:27:26 +0530695 if (ah->config.pcie_clock_req) {
696 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530697 ar9280PciePhy_clkreq_off_L1_9280,
698 ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700699 } else {
Sujith2660b812009-02-09 13:27:26 +0530700 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530701 ar9280PciePhy_clkreq_always_on_L1_9280,
702 ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700703 }
Sujith2660b812009-02-09 13:27:26 +0530704 INIT_INI_ARRAY(&ah->iniModesAdditional,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700705 ar9280Modes_fast_clock_9280_2,
Sujithf1dc5602008-10-29 10:16:30 +0530706 ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700707 } else if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530708 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700709 ARRAY_SIZE(ar9280Modes_9280), 6);
Sujith2660b812009-02-09 13:27:26 +0530710 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700711 ARRAY_SIZE(ar9280Common_9280), 2);
712 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530713 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700714 ARRAY_SIZE(ar5416Modes_9160), 6);
Sujith2660b812009-02-09 13:27:26 +0530715 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700716 ARRAY_SIZE(ar5416Common_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530717 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700718 ARRAY_SIZE(ar5416Bank0_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530719 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700720 ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530721 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700722 ARRAY_SIZE(ar5416Bank1_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530723 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700724 ARRAY_SIZE(ar5416Bank2_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530725 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700726 ARRAY_SIZE(ar5416Bank3_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530727 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700728 ARRAY_SIZE(ar5416Bank6_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530729 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700730 ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530731 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700732 ARRAY_SIZE(ar5416Bank7_9160), 2);
733 if (AR_SREV_9160_11(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530734 INIT_INI_ARRAY(&ah->iniAddac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700735 ar5416Addac_91601_1,
736 ARRAY_SIZE(ar5416Addac_91601_1), 2);
737 } else {
Sujith2660b812009-02-09 13:27:26 +0530738 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700739 ARRAY_SIZE(ar5416Addac_9160), 2);
740 }
741 } else if (AR_SREV_9100_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530742 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700743 ARRAY_SIZE(ar5416Modes_9100), 6);
Sujith2660b812009-02-09 13:27:26 +0530744 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700745 ARRAY_SIZE(ar5416Common_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530746 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700747 ARRAY_SIZE(ar5416Bank0_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530748 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700749 ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530750 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700751 ARRAY_SIZE(ar5416Bank1_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530752 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700753 ARRAY_SIZE(ar5416Bank2_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530754 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700755 ARRAY_SIZE(ar5416Bank3_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530756 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700757 ARRAY_SIZE(ar5416Bank6_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530758 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700759 ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530760 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700761 ARRAY_SIZE(ar5416Bank7_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530762 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700763 ARRAY_SIZE(ar5416Addac_9100), 2);
764 } else {
Sujith2660b812009-02-09 13:27:26 +0530765 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700766 ARRAY_SIZE(ar5416Modes), 6);
Sujith2660b812009-02-09 13:27:26 +0530767 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700768 ARRAY_SIZE(ar5416Common), 2);
Sujith2660b812009-02-09 13:27:26 +0530769 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700770 ARRAY_SIZE(ar5416Bank0), 2);
Sujith2660b812009-02-09 13:27:26 +0530771 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700772 ARRAY_SIZE(ar5416BB_RfGain), 3);
Sujith2660b812009-02-09 13:27:26 +0530773 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700774 ARRAY_SIZE(ar5416Bank1), 2);
Sujith2660b812009-02-09 13:27:26 +0530775 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700776 ARRAY_SIZE(ar5416Bank2), 2);
Sujith2660b812009-02-09 13:27:26 +0530777 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700778 ARRAY_SIZE(ar5416Bank3), 3);
Sujith2660b812009-02-09 13:27:26 +0530779 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700780 ARRAY_SIZE(ar5416Bank6), 3);
Sujith2660b812009-02-09 13:27:26 +0530781 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700782 ARRAY_SIZE(ar5416Bank6TPC), 3);
Sujith2660b812009-02-09 13:27:26 +0530783 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700784 ARRAY_SIZE(ar5416Bank7), 2);
Sujith2660b812009-02-09 13:27:26 +0530785 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700786 ARRAY_SIZE(ar5416Addac), 2);
787 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700788}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700789
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700790static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
791{
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530792 if (AR_SREV_9287_11_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530793 INIT_INI_ARRAY(&ah->iniModesRxGain,
794 ar9287Modes_rx_gain_9287_1_1,
795 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_1), 6);
796 else if (AR_SREV_9287_10(ah))
797 INIT_INI_ARRAY(&ah->iniModesRxGain,
798 ar9287Modes_rx_gain_9287_1_0,
799 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_0), 6);
800 else if (AR_SREV_9280_20(ah))
801 ath9k_hw_init_rxgain_ini(ah);
802
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530803 if (AR_SREV_9287_11_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530804 INIT_INI_ARRAY(&ah->iniModesTxGain,
805 ar9287Modes_tx_gain_9287_1_1,
806 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_1), 6);
807 } else if (AR_SREV_9287_10(ah)) {
808 INIT_INI_ARRAY(&ah->iniModesTxGain,
809 ar9287Modes_tx_gain_9287_1_0,
810 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_0), 6);
811 } else if (AR_SREV_9280_20(ah)) {
812 ath9k_hw_init_txgain_ini(ah);
813 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530814 u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
815
816 /* txgain table */
817 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) {
Vivek Natarajan53bc7aa2010-04-05 14:48:04 +0530818 if (AR_SREV_9285E_20(ah)) {
819 INIT_INI_ARRAY(&ah->iniModesTxGain,
820 ar9285Modes_XE2_0_high_power,
821 ARRAY_SIZE(
822 ar9285Modes_XE2_0_high_power), 6);
823 } else {
824 INIT_INI_ARRAY(&ah->iniModesTxGain,
825 ar9285Modes_high_power_tx_gain_9285_1_2,
826 ARRAY_SIZE(
827 ar9285Modes_high_power_tx_gain_9285_1_2), 6);
828 }
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530829 } else {
Vivek Natarajan53bc7aa2010-04-05 14:48:04 +0530830 if (AR_SREV_9285E_20(ah)) {
831 INIT_INI_ARRAY(&ah->iniModesTxGain,
832 ar9285Modes_XE2_0_normal_power,
833 ARRAY_SIZE(
834 ar9285Modes_XE2_0_normal_power), 6);
835 } else {
836 INIT_INI_ARRAY(&ah->iniModesTxGain,
837 ar9285Modes_original_tx_gain_9285_1_2,
838 ARRAY_SIZE(
839 ar9285Modes_original_tx_gain_9285_1_2), 6);
840 }
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530841 }
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530842 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700843}
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530844
Felix Fietkauaa8bc9e2010-01-23 20:04:18 +0100845static void ath9k_hw_init_eeprom_fix(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700846{
Pavel Roskin2eb46d92010-04-07 01:33:33 -0400847 struct base_eep_header *pBase = &(ah->eeprom.def.baseEepHeader);
848 struct ath_common *common = ath9k_hw_common(ah);
Sujith06d0f062009-02-12 10:06:45 +0530849
Pavel Roskin2eb46d92010-04-07 01:33:33 -0400850 ah->need_an_top2_fixup = (ah->hw_version.devid == AR9280_DEVID_PCI) &&
851 (ah->eep_map != EEP_MAP_4KBITS) &&
852 ((pBase->version & 0xff) > 0x0a) &&
853 (pBase->pwdclkind == 0);
Sujith06d0f062009-02-12 10:06:45 +0530854
Pavel Roskin2eb46d92010-04-07 01:33:33 -0400855 if (ah->need_an_top2_fixup)
856 ath_print(common, ATH_DBG_EEPROM,
857 "needs fixup for AR_AN_TOP2 register\n");
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700858}
859
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400860static void ath9k_hw_attach_ops(struct ath_hw *ah)
861{
862 if (AR_SREV_9300_20_OR_LATER(ah))
863 ar9003_hw_attach_ops(ah);
864 else
865 ar9002_hw_attach_ops(ah);
866}
867
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400868/* Called for all hardware families */
869static int __ath9k_hw_init(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700870{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700871 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700872 int r = 0;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700873
Luis R. Rodriguezbab1f622010-04-15 17:38:20 -0400874 if (ah->hw_version.devid == AR5416_AR9100_DEVID)
875 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700876
877 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700878 ath_print(common, ATH_DBG_FATAL,
879 "Couldn't reset chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700880 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700881 }
882
Luis R. Rodriguezbab1f622010-04-15 17:38:20 -0400883 ath9k_hw_init_defaults(ah);
884 ath9k_hw_init_config(ah);
885
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400886 ath9k_hw_attach_ops(ah);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400887
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700888 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700889 ath_print(common, ATH_DBG_FATAL, "Couldn't wakeup chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700890 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700891 }
892
893 if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
894 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
895 (AR_SREV_9280(ah) && !ah->is_pciexpress)) {
896 ah->config.serialize_regmode =
897 SER_REG_MODE_ON;
898 } else {
899 ah->config.serialize_regmode =
900 SER_REG_MODE_OFF;
901 }
902 }
903
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700904 ath_print(common, ATH_DBG_RESET, "serialize_regmode is %d\n",
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700905 ah->config.serialize_regmode);
906
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -0500907 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
908 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD >> 1;
909 else
910 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD;
911
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400912 if (!ath9k_hw_macversion_supported(ah)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700913 ath_print(common, ATH_DBG_FATAL,
914 "Mac Chip Rev 0x%02x.%x is not supported by "
915 "this driver\n", ah->hw_version.macVersion,
916 ah->hw_version.macRev);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700917 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700918 }
919
920 if (AR_SREV_9100(ah)) {
921 ah->iq_caldata.calData = &iq_cal_multi_sample;
922 ah->supp_cals = IQ_MISMATCH_CAL;
923 ah->is_pciexpress = false;
924 }
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400925
926 if (AR_SREV_9271(ah))
927 ah->is_pciexpress = false;
928
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700929 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700930 ath9k_hw_init_cal_settings(ah);
931
932 ah->ani_function = ATH9K_ANI_ALL;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400933 if (AR_SREV_9280_10_OR_LATER(ah))
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700934 ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
935
936 ath9k_hw_init_mode_regs(ah);
937
938 if (ah->is_pciexpress)
Vivek Natarajan93b1b372009-09-17 09:24:58 +0530939 ath9k_hw_configpcipowersave(ah, 0, 0);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700940 else
941 ath9k_hw_disablepcie(ah);
942
Sujith193cd452009-09-18 15:04:07 +0530943 /* Support for Japan ch.14 (2484) spread */
944 if (AR_SREV_9287_11_OR_LATER(ah)) {
945 INIT_INI_ARRAY(&ah->iniCckfirNormal,
946 ar9287Common_normal_cck_fir_coeff_92871_1,
947 ARRAY_SIZE(ar9287Common_normal_cck_fir_coeff_92871_1), 2);
948 INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
949 ar9287Common_japan_2484_cck_fir_coeff_92871_1,
950 ARRAY_SIZE(ar9287Common_japan_2484_cck_fir_coeff_92871_1), 2);
951 }
952
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700953 r = ath9k_hw_post_init(ah);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700954 if (r)
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700955 return r;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700956
957 ath9k_hw_init_mode_gain_regs(ah);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +0100958 r = ath9k_hw_fill_cap_info(ah);
959 if (r)
960 return r;
961
Felix Fietkauaa8bc9e2010-01-23 20:04:18 +0100962 ath9k_hw_init_eeprom_fix(ah);
Sujithf6688cd2008-12-07 21:43:10 +0530963
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700964 r = ath9k_hw_init_macaddr(ah);
965 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700966 ath_print(common, ATH_DBG_FATAL,
967 "Failed to initialize MAC address\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700968 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700969 }
970
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400971 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
Sujith2660b812009-02-09 13:27:26 +0530972 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700973 else
Sujith2660b812009-02-09 13:27:26 +0530974 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700975
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700976 ath9k_init_nfcal_hist_buffer(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700977
Luis R. Rodriguez211f5852009-10-06 21:19:07 -0400978 common->state = ATH_HW_INITIALIZED;
979
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700980 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700981}
982
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400983int ath9k_hw_init(struct ath_hw *ah)
984{
985 int ret;
986 struct ath_common *common = ath9k_hw_common(ah);
987
988 /* These are all the AR5008/AR9001/AR9002 hardware family of chipsets */
989 switch (ah->hw_version.devid) {
990 case AR5416_DEVID_PCI:
991 case AR5416_DEVID_PCIE:
992 case AR5416_AR9100_DEVID:
993 case AR9160_DEVID_PCI:
994 case AR9280_DEVID_PCI:
995 case AR9280_DEVID_PCIE:
996 case AR9285_DEVID_PCIE:
Senthil Balasubramaniandb3cc532010-04-15 17:38:18 -0400997 case AR9287_DEVID_PCI:
998 case AR9287_DEVID_PCIE:
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400999 case AR2427_DEVID_PCIE:
Senthil Balasubramaniandb3cc532010-04-15 17:38:18 -04001000 case AR9300_DEVID_PCIE:
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04001001 break;
1002 default:
1003 if (common->bus_ops->ath_bus_type == ATH_USB)
1004 break;
1005 ath_print(common, ATH_DBG_FATAL,
1006 "Hardware device ID 0x%04x not supported\n",
1007 ah->hw_version.devid);
1008 return -EOPNOTSUPP;
1009 }
1010
1011 ret = __ath9k_hw_init(ah);
1012 if (ret) {
1013 ath_print(common, ATH_DBG_FATAL,
1014 "Unable to initialize hardware; "
1015 "initialization status: %d\n", ret);
1016 return ret;
1017 }
1018
1019 return 0;
1020}
1021EXPORT_SYMBOL(ath9k_hw_init);
1022
Sujithcbe61d82009-02-09 13:27:12 +05301023static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301024{
1025 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
1026 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
1027
1028 REG_WRITE(ah, AR_QOS_NO_ACK,
1029 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
1030 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
1031 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
1032
1033 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
1034 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
1035 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
1036 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
1037 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
1038}
1039
Sujithcbe61d82009-02-09 13:27:12 +05301040static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301041 struct ath9k_channel *chan)
1042{
Luis R. Rodriguez64773962010-04-15 17:38:17 -04001043 u32 pll = ath9k_hw_compute_pll_control(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301044
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001045 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +05301046
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -04001047 /* Switch the core clock for ar9271 to 117Mhz */
1048 if (AR_SREV_9271(ah)) {
Sujith25e2ab12010-03-17 14:25:22 +05301049 udelay(500);
1050 REG_WRITE(ah, 0x50040, 0x304);
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -04001051 }
1052
Sujithf1dc5602008-10-29 10:16:30 +05301053 udelay(RTC_PLL_SETTLE_DELAY);
1054
1055 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
1056}
1057
Sujithcbe61d82009-02-09 13:27:12 +05301058static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -08001059 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301060{
Pavel Roskin152d5302010-03-31 18:05:37 -04001061 u32 imr_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +05301062 AR_IMR_TXURN |
1063 AR_IMR_RXERR |
1064 AR_IMR_RXORN |
1065 AR_IMR_BCNMISC;
1066
Sujith0ce024c2009-12-14 14:57:00 +05301067 if (ah->config.rx_intr_mitigation)
Pavel Roskin152d5302010-03-31 18:05:37 -04001068 imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
Sujithf1dc5602008-10-29 10:16:30 +05301069 else
Pavel Roskin152d5302010-03-31 18:05:37 -04001070 imr_reg |= AR_IMR_RXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301071
Pavel Roskin152d5302010-03-31 18:05:37 -04001072 imr_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301073
Colin McCabed97809d2008-12-01 13:38:55 -08001074 if (opmode == NL80211_IFTYPE_AP)
Pavel Roskin152d5302010-03-31 18:05:37 -04001075 imr_reg |= AR_IMR_MIB;
Sujithf1dc5602008-10-29 10:16:30 +05301076
Pavel Roskin152d5302010-03-31 18:05:37 -04001077 REG_WRITE(ah, AR_IMR, imr_reg);
Pavel Roskin74bad5c2010-02-23 18:15:27 -05001078 ah->imrs2_reg |= AR_IMR_S2_GTT;
1079 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
Sujithf1dc5602008-10-29 10:16:30 +05301080
1081 if (!AR_SREV_9100(ah)) {
1082 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
1083 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
1084 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
1085 }
1086}
1087
Felix Fietkau0005baf2010-01-15 02:33:40 +01001088static void ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301089{
Felix Fietkau0005baf2010-01-15 02:33:40 +01001090 u32 val = ath9k_hw_mac_to_clks(ah, us);
1091 val = min(val, (u32) 0xFFFF);
1092 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, val);
Sujithf1dc5602008-10-29 10:16:30 +05301093}
1094
Felix Fietkau0005baf2010-01-15 02:33:40 +01001095static void ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301096{
Felix Fietkau0005baf2010-01-15 02:33:40 +01001097 u32 val = ath9k_hw_mac_to_clks(ah, us);
1098 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_ACK));
1099 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_ACK, val);
1100}
1101
1102static void ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
1103{
1104 u32 val = ath9k_hw_mac_to_clks(ah, us);
1105 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_CTS));
1106 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_CTS, val);
Sujithf1dc5602008-10-29 10:16:30 +05301107}
1108
Sujithcbe61d82009-02-09 13:27:12 +05301109static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +05301110{
Sujithf1dc5602008-10-29 10:16:30 +05301111 if (tu > 0xFFFF) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001112 ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT,
1113 "bad global tx timeout %u\n", tu);
Sujith2660b812009-02-09 13:27:26 +05301114 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301115 return false;
1116 } else {
1117 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +05301118 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +05301119 return true;
1120 }
1121}
1122
Felix Fietkau0005baf2010-01-15 02:33:40 +01001123void ath9k_hw_init_global_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301124{
Felix Fietkau0005baf2010-01-15 02:33:40 +01001125 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
1126 int acktimeout;
Felix Fietkaue239d852010-01-15 02:34:58 +01001127 int slottime;
Felix Fietkau0005baf2010-01-15 02:33:40 +01001128 int sifstime;
1129
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001130 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
1131 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +05301132
Sujith2660b812009-02-09 13:27:26 +05301133 if (ah->misc_mode != 0)
Sujithf1dc5602008-10-29 10:16:30 +05301134 REG_WRITE(ah, AR_PCU_MISC,
Sujith2660b812009-02-09 13:27:26 +05301135 REG_READ(ah, AR_PCU_MISC) | ah->misc_mode);
Felix Fietkau0005baf2010-01-15 02:33:40 +01001136
1137 if (conf->channel && conf->channel->band == IEEE80211_BAND_5GHZ)
1138 sifstime = 16;
1139 else
1140 sifstime = 10;
1141
Felix Fietkaue239d852010-01-15 02:34:58 +01001142 /* As defined by IEEE 802.11-2007 17.3.8.6 */
1143 slottime = ah->slottime + 3 * ah->coverage_class;
1144 acktimeout = slottime + sifstime;
Felix Fietkau42c45682010-02-11 18:07:19 +01001145
1146 /*
1147 * Workaround for early ACK timeouts, add an offset to match the
1148 * initval's 64us ack timeout value.
1149 * This was initially only meant to work around an issue with delayed
1150 * BA frames in some implementations, but it has been found to fix ACK
1151 * timeout issues in other cases as well.
1152 */
1153 if (conf->channel && conf->channel->band == IEEE80211_BAND_2GHZ)
1154 acktimeout += 64 - sifstime - ah->slottime;
1155
Felix Fietkaue239d852010-01-15 02:34:58 +01001156 ath9k_hw_setslottime(ah, slottime);
Felix Fietkau0005baf2010-01-15 02:33:40 +01001157 ath9k_hw_set_ack_timeout(ah, acktimeout);
1158 ath9k_hw_set_cts_timeout(ah, acktimeout);
Sujith2660b812009-02-09 13:27:26 +05301159 if (ah->globaltxtimeout != (u32) -1)
1160 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Sujithf1dc5602008-10-29 10:16:30 +05301161}
Felix Fietkau0005baf2010-01-15 02:33:40 +01001162EXPORT_SYMBOL(ath9k_hw_init_global_settings);
Sujithf1dc5602008-10-29 10:16:30 +05301163
Sujith285f2dd2010-01-08 10:36:07 +05301164void ath9k_hw_deinit(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001165{
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001166 struct ath_common *common = ath9k_hw_common(ah);
1167
Sujith736b3a22010-03-17 14:25:24 +05301168 if (common->state < ATH_HW_INITIALIZED)
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001169 goto free_hw;
1170
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001171 if (!AR_SREV_9100(ah))
Luis R. Rodrigueze70c0cf2009-08-03 12:24:51 -07001172 ath9k_hw_ani_disable(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001173
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001174 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001175
1176free_hw:
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001177 ath9k_hw_rf_free_ext_banks(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001178}
Sujith285f2dd2010-01-08 10:36:07 +05301179EXPORT_SYMBOL(ath9k_hw_deinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001180
Sujithf1dc5602008-10-29 10:16:30 +05301181/*******/
1182/* INI */
1183/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001184
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001185u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan)
Bob Copeland3a702e42009-03-30 22:30:29 -04001186{
1187 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
1188
1189 if (IS_CHAN_B(chan))
1190 ctl |= CTL_11B;
1191 else if (IS_CHAN_G(chan))
1192 ctl |= CTL_11G;
1193 else
1194 ctl |= CTL_11A;
1195
1196 return ctl;
1197}
1198
Sujithf1dc5602008-10-29 10:16:30 +05301199/****************************************/
1200/* Reset and Channel Switching Routines */
1201/****************************************/
1202
Sujithcbe61d82009-02-09 13:27:12 +05301203static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301204{
1205 u32 regval;
1206
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001207 /*
1208 * set AHB_MODE not to do cacheline prefetches
1209 */
Sujithf1dc5602008-10-29 10:16:30 +05301210 regval = REG_READ(ah, AR_AHB_MODE);
1211 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
1212
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001213 /*
1214 * let mac dma reads be in 128 byte chunks
1215 */
Sujithf1dc5602008-10-29 10:16:30 +05301216 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
1217 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
1218
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001219 /*
1220 * Restore TX Trigger Level to its pre-reset value.
1221 * The initial value depends on whether aggregation is enabled, and is
1222 * adjusted whenever underruns are detected.
1223 */
Sujith2660b812009-02-09 13:27:26 +05301224 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +05301225
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001226 /*
1227 * let mac dma writes be in 128 byte chunks
1228 */
Sujithf1dc5602008-10-29 10:16:30 +05301229 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
1230 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
1231
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001232 /*
1233 * Setup receive FIFO threshold to hold off TX activities
1234 */
Sujithf1dc5602008-10-29 10:16:30 +05301235 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1236
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001237 /*
1238 * reduce the number of usable entries in PCU TXBUF to avoid
1239 * wrap around issues.
1240 */
Sujithf1dc5602008-10-29 10:16:30 +05301241 if (AR_SREV_9285(ah)) {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001242 /* For AR9285 the number of Fifos are reduced to half.
1243 * So set the usable tx buf size also to half to
1244 * avoid data/delimiter underruns
1245 */
Sujithf1dc5602008-10-29 10:16:30 +05301246 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1247 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001248 } else if (!AR_SREV_9271(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +05301249 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1250 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1251 }
1252}
1253
Sujithcbe61d82009-02-09 13:27:12 +05301254static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301255{
1256 u32 val;
1257
1258 val = REG_READ(ah, AR_STA_ID1);
1259 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
1260 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001261 case NL80211_IFTYPE_AP:
Sujithf1dc5602008-10-29 10:16:30 +05301262 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
1263 | AR_STA_ID1_KSRCH_MODE);
1264 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1265 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001266 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04001267 case NL80211_IFTYPE_MESH_POINT:
Sujithf1dc5602008-10-29 10:16:30 +05301268 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
1269 | AR_STA_ID1_KSRCH_MODE);
1270 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1271 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001272 case NL80211_IFTYPE_STATION:
1273 case NL80211_IFTYPE_MONITOR:
Sujithf1dc5602008-10-29 10:16:30 +05301274 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
1275 break;
1276 }
1277}
1278
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001279void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled,
1280 u32 *coef_mantissa, u32 *coef_exponent)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001281{
1282 u32 coef_exp, coef_man;
1283
1284 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1285 if ((coef_scaled >> coef_exp) & 0x1)
1286 break;
1287
1288 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1289
1290 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1291
1292 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1293 *coef_exponent = coef_exp - 16;
1294}
1295
Sujithcbe61d82009-02-09 13:27:12 +05301296static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +05301297{
1298 u32 rst_flags;
1299 u32 tmpReg;
1300
Sujith70768492009-02-16 13:23:12 +05301301 if (AR_SREV_9100(ah)) {
1302 u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK);
1303 val &= ~AR_RTC_DERIVED_CLK_PERIOD;
1304 val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD);
1305 REG_WRITE(ah, AR_RTC_DERIVED_CLK, val);
1306 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1307 }
1308
Sujithf1dc5602008-10-29 10:16:30 +05301309 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1310 AR_RTC_FORCE_WAKE_ON_INT);
1311
1312 if (AR_SREV_9100(ah)) {
1313 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1314 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1315 } else {
1316 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1317 if (tmpReg &
1318 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1319 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001320 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05301321 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001322
1323 val = AR_RC_HOSTIF;
1324 if (!AR_SREV_9300_20_OR_LATER(ah))
1325 val |= AR_RC_AHB;
1326 REG_WRITE(ah, AR_RC, val);
1327
1328 } else if (!AR_SREV_9300_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05301329 REG_WRITE(ah, AR_RC, AR_RC_AHB);
Sujithf1dc5602008-10-29 10:16:30 +05301330
1331 rst_flags = AR_RTC_RC_MAC_WARM;
1332 if (type == ATH9K_RESET_COLD)
1333 rst_flags |= AR_RTC_RC_MAC_COLD;
1334 }
1335
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001336 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujithf1dc5602008-10-29 10:16:30 +05301337 udelay(50);
1338
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001339 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301340 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001341 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1342 "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301343 return false;
1344 }
1345
1346 if (!AR_SREV_9100(ah))
1347 REG_WRITE(ah, AR_RC, 0);
1348
Sujithf1dc5602008-10-29 10:16:30 +05301349 if (AR_SREV_9100(ah))
1350 udelay(50);
1351
1352 return true;
1353}
1354
Sujithcbe61d82009-02-09 13:27:12 +05301355static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301356{
1357 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1358 AR_RTC_FORCE_WAKE_ON_INT);
1359
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001360 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301361 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1362
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001363 REG_WRITE(ah, AR_RTC_RESET, 0);
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301364 udelay(2);
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301365
1366 if (!AR_SREV_9100(ah))
1367 REG_WRITE(ah, AR_RC, 0);
1368
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001369 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301370
1371 if (!ath9k_hw_wait(ah,
1372 AR_RTC_STATUS,
1373 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301374 AR_RTC_STATUS_ON,
1375 AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001376 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1377 "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301378 return false;
1379 }
1380
1381 ath9k_hw_read_revisions(ah);
1382
1383 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1384}
1385
Sujithcbe61d82009-02-09 13:27:12 +05301386static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301387{
1388 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1389 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1390
1391 switch (type) {
1392 case ATH9K_RESET_POWER_ON:
1393 return ath9k_hw_set_reset_power_on(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301394 case ATH9K_RESET_WARM:
1395 case ATH9K_RESET_COLD:
1396 return ath9k_hw_set_reset(ah, type);
Sujithf1dc5602008-10-29 10:16:30 +05301397 default:
1398 return false;
1399 }
1400}
1401
Sujithcbe61d82009-02-09 13:27:12 +05301402static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301403 struct ath9k_channel *chan)
1404{
Vivek Natarajan42abfbe2009-09-17 09:27:59 +05301405 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) {
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301406 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
1407 return false;
1408 } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
Sujithf1dc5602008-10-29 10:16:30 +05301409 return false;
1410
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001411 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05301412 return false;
1413
Sujith2660b812009-02-09 13:27:26 +05301414 ah->chip_fullsleep = false;
Sujithf1dc5602008-10-29 10:16:30 +05301415 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301416 ath9k_hw_set_rfmode(ah, chan);
1417
1418 return true;
1419}
1420
Sujithcbe61d82009-02-09 13:27:12 +05301421static bool ath9k_hw_channel_change(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001422 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301423{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001424 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001425 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001426 struct ieee80211_channel *channel = chan->chan;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001427 u32 qnum;
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001428 int r;
Sujithf1dc5602008-10-29 10:16:30 +05301429
1430 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1431 if (ath9k_hw_numtxpending(ah, qnum)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001432 ath_print(common, ATH_DBG_QUEUE,
1433 "Transmit frames pending on "
1434 "queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301435 return false;
1436 }
1437 }
1438
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001439 if (!ath9k_hw_rfbus_req(ah)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001440 ath_print(common, ATH_DBG_FATAL,
1441 "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301442 return false;
1443 }
1444
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001445 ath9k_hw_set_channel_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301446
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001447 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001448 if (r) {
1449 ath_print(common, ATH_DBG_FATAL,
1450 "Failed to set channel\n");
1451 return false;
Sujithf1dc5602008-10-29 10:16:30 +05301452 }
1453
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001454 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001455 ath9k_regd_get_ctl(regulatory, chan),
Sujithf74df6f2009-02-09 13:27:24 +05301456 channel->max_antenna_gain * 2,
1457 channel->max_power * 2,
1458 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001459 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05301460
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001461 ath9k_hw_rfbus_done(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301462
1463 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1464 ath9k_hw_set_delta_slope(ah, chan);
1465
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001466 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301467
1468 if (!chan->oneTimeCalsDone)
1469 chan->oneTimeCalsDone = true;
1470
1471 return true;
1472}
1473
Sujithcbe61d82009-02-09 13:27:12 +05301474int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001475 bool bChannelChange)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001476{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001477 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001478 u32 saveLedState;
Sujith2660b812009-02-09 13:27:26 +05301479 struct ath9k_channel *curchan = ah->curchan;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001480 u32 saveDefAntenna;
1481 u32 macStaId1;
Sujith46fe7822009-09-17 09:25:25 +05301482 u64 tsf = 0;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001483 int i, r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001484
Luis R. Rodriguez43c27612009-09-13 21:07:07 -07001485 ah->txchainmask = common->tx_chainmask;
1486 ah->rxchainmask = common->rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001487
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001488 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001489 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001490
Vasanthakumar Thiagarajan9ebef7992009-09-17 09:26:44 +05301491 if (curchan && !ah->chip_fullsleep)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001492 ath9k_hw_getnf(ah, curchan);
1493
1494 if (bChannelChange &&
Sujith2660b812009-02-09 13:27:26 +05301495 (ah->chip_fullsleep != true) &&
1496 (ah->curchan != NULL) &&
1497 (chan->channel != ah->curchan->channel) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001498 ((chan->channelFlags & CHANNEL_ALL) ==
Sujith2660b812009-02-09 13:27:26 +05301499 (ah->curchan->channelFlags & CHANNEL_ALL)) &&
Vasanthakumar Thiagarajan0a475cc2009-09-17 09:27:10 +05301500 !(AR_SREV_9280(ah) || IS_CHAN_A_5MHZ_SPACED(chan) ||
1501 IS_CHAN_A_5MHZ_SPACED(ah->curchan))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001502
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001503 if (ath9k_hw_channel_change(ah, chan)) {
Sujith2660b812009-02-09 13:27:26 +05301504 ath9k_hw_loadnf(ah, ah->curchan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001505 ath9k_hw_start_nfcal(ah);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001506 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001507 }
1508 }
1509
1510 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
1511 if (saveDefAntenna == 0)
1512 saveDefAntenna = 1;
1513
1514 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
1515
Sujith46fe7822009-09-17 09:25:25 +05301516 /* For chips on which RTC reset is done, save TSF before it gets cleared */
1517 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1518 tsf = ath9k_hw_gettsf64(ah);
1519
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001520 saveLedState = REG_READ(ah, AR_CFG_LED) &
1521 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
1522 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
1523
1524 ath9k_hw_mark_phy_inactive(ah);
1525
Sujith05020d22010-03-17 14:25:23 +05301526 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001527 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1528 REG_WRITE(ah,
1529 AR9271_RESET_POWER_DOWN_CONTROL,
1530 AR9271_RADIO_RF_RST);
1531 udelay(50);
1532 }
1533
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001534 if (!ath9k_hw_chip_reset(ah, chan)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001535 ath_print(common, ATH_DBG_FATAL, "Chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001536 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001537 }
1538
Sujith05020d22010-03-17 14:25:23 +05301539 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001540 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1541 ah->htc_reset_init = false;
1542 REG_WRITE(ah,
1543 AR9271_RESET_POWER_DOWN_CONTROL,
1544 AR9271_GATE_MAC_CTL);
1545 udelay(50);
1546 }
1547
Sujith46fe7822009-09-17 09:25:25 +05301548 /* Restore TSF */
1549 if (tsf && AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1550 ath9k_hw_settsf64(ah, tsf);
1551
Vasanthakumar Thiagarajan369391d2009-01-21 19:24:13 +05301552 if (AR_SREV_9280_10_OR_LATER(ah))
1553 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001554
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001555 r = ath9k_hw_process_ini(ah, chan);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001556 if (r)
1557 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001558
Jouni Malinen0ced0e12009-01-08 13:32:13 +02001559 /* Setup MFP options for CCMP */
1560 if (AR_SREV_9280_20_OR_LATER(ah)) {
1561 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
1562 * frames when constructing CCMP AAD. */
1563 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
1564 0xc7ff);
1565 ah->sw_mgmt_crypto = false;
1566 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1567 /* Disable hardware crypto for management frames */
1568 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
1569 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
1570 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1571 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
1572 ah->sw_mgmt_crypto = true;
1573 } else
1574 ah->sw_mgmt_crypto = true;
1575
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001576 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1577 ath9k_hw_set_delta_slope(ah, chan);
1578
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001579 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithd6509152009-03-13 08:56:05 +05301580 ah->eep_ops->set_board_values(ah, chan);
Luis R. Rodrigueza7765822009-10-19 02:33:45 -04001581
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001582 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
1583 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001584 | macStaId1
1585 | AR_STA_ID1_RTS_USE_DEF
Sujith2660b812009-02-09 13:27:26 +05301586 | (ah->config.
Sujith60b67f52008-08-07 10:52:38 +05301587 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Sujith2660b812009-02-09 13:27:26 +05301588 | ah->sta_id1_defaults);
1589 ath9k_hw_set_operating_mode(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001590
Luis R. Rodriguez13b81552009-09-10 17:52:45 -07001591 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001592
1593 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
1594
Luis R. Rodriguez3453ad82009-09-10 08:57:00 -07001595 ath9k_hw_write_associd(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001596
1597 REG_WRITE(ah, AR_ISR, ~0);
1598
1599 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
1600
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001601 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001602 if (r)
1603 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001604
1605 for (i = 0; i < AR_NUM_DCU; i++)
1606 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
1607
Sujith2660b812009-02-09 13:27:26 +05301608 ah->intr_txqs = 0;
1609 for (i = 0; i < ah->caps.total_queues; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001610 ath9k_hw_resettxqueue(ah, i);
1611
Sujith2660b812009-02-09 13:27:26 +05301612 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001613 ath9k_hw_init_qos(ah);
1614
Sujith2660b812009-02-09 13:27:26 +05301615 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301616 ath9k_enable_rfkill(ah);
Johannes Berg3b319aa2009-06-13 14:50:26 +05301617
Felix Fietkau0005baf2010-01-15 02:33:40 +01001618 ath9k_hw_init_global_settings(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001619
Vivek Natarajan326bebb2009-08-14 11:33:36 +05301620 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301621 REG_WRITE(ah, AR_D_GBL_IFS_SIFS,
1622 AR_D_GBL_IFS_SIFS_ASYNC_FIFO_DUR);
1623 REG_WRITE(ah, AR_D_GBL_IFS_SLOT,
1624 AR_D_GBL_IFS_SLOT_ASYNC_FIFO_DUR);
1625 REG_WRITE(ah, AR_D_GBL_IFS_EIFS,
1626 AR_D_GBL_IFS_EIFS_ASYNC_FIFO_DUR);
1627
1628 REG_WRITE(ah, AR_TIME_OUT, AR_TIME_OUT_ACK_CTS_ASYNC_FIFO_DUR);
1629 REG_WRITE(ah, AR_USEC, AR_USEC_ASYNC_FIFO_DUR);
1630
1631 REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
1632 AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
1633 REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
1634 AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
1635 }
Vivek Natarajan326bebb2009-08-14 11:33:36 +05301636 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301637 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1638 AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
1639 }
1640
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001641 REG_WRITE(ah, AR_STA_ID1,
1642 REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
1643
1644 ath9k_hw_set_dma(ah);
1645
1646 REG_WRITE(ah, AR_OBS, 8);
1647
Sujith0ce024c2009-12-14 14:57:00 +05301648 if (ah->config.rx_intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001649 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
1650 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
1651 }
1652
1653 ath9k_hw_init_bb(ah, chan);
1654
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001655 if (!ath9k_hw_init_cal(ah, chan))
Joe Perches6badaaf2009-06-28 09:26:32 -07001656 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001657
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001658 ath9k_hw_restore_chainmask(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001659 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
1660
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001661 /*
1662 * For big endian systems turn on swapping for descriptors
1663 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001664 if (AR_SREV_9100(ah)) {
1665 u32 mask;
1666 mask = REG_READ(ah, AR_CFG);
1667 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001668 ath_print(common, ATH_DBG_RESET,
Sujith04bd46382008-11-28 22:18:05 +05301669 "CFG Byte Swap Set 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001670 } else {
1671 mask =
1672 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
1673 REG_WRITE(ah, AR_CFG, mask);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001674 ath_print(common, ATH_DBG_RESET,
Sujith04bd46382008-11-28 22:18:05 +05301675 "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001676 }
1677 } else {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001678 /* Configure AR9271 target WLAN */
1679 if (AR_SREV_9271(ah))
1680 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001681#ifdef __BIG_ENDIAN
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001682 else
1683 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001684#endif
1685 }
1686
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001687 if (ah->btcoex_hw.enabled)
Vasanthakumar Thiagarajan42cc41e2009-08-26 21:08:45 +05301688 ath9k_hw_btcoex_enable(ah);
1689
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001690 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001691}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001692EXPORT_SYMBOL(ath9k_hw_reset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001693
Sujithf1dc5602008-10-29 10:16:30 +05301694/************************/
1695/* Key Cache Management */
1696/************************/
1697
Sujithcbe61d82009-02-09 13:27:12 +05301698bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001699{
Sujithf1dc5602008-10-29 10:16:30 +05301700 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001701
Sujith2660b812009-02-09 13:27:26 +05301702 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001703 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1704 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001705 return false;
1706 }
1707
Sujithf1dc5602008-10-29 10:16:30 +05301708 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001709
Sujithf1dc5602008-10-29 10:16:30 +05301710 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
1711 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
1712 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
1713 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
1714 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
1715 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
1716 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
1717 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
1718
1719 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
1720 u16 micentry = entry + 64;
1721
1722 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
1723 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
1724 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
1725 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
1726
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001727 }
1728
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001729 return true;
1730}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001731EXPORT_SYMBOL(ath9k_hw_keyreset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001732
Sujithcbe61d82009-02-09 13:27:12 +05301733bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001734{
Sujithf1dc5602008-10-29 10:16:30 +05301735 u32 macHi, macLo;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001736
Sujith2660b812009-02-09 13:27:26 +05301737 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001738 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1739 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001740 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001741 }
1742
Sujithf1dc5602008-10-29 10:16:30 +05301743 if (mac != NULL) {
1744 macHi = (mac[5] << 8) | mac[4];
1745 macLo = (mac[3] << 24) |
1746 (mac[2] << 16) |
1747 (mac[1] << 8) |
1748 mac[0];
1749 macLo >>= 1;
1750 macLo |= (macHi & 1) << 31;
1751 macHi >>= 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001752 } else {
Sujithf1dc5602008-10-29 10:16:30 +05301753 macLo = macHi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001754 }
Sujithf1dc5602008-10-29 10:16:30 +05301755 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
1756 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001757
1758 return true;
1759}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001760EXPORT_SYMBOL(ath9k_hw_keysetmac);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001761
Sujithcbe61d82009-02-09 13:27:12 +05301762bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
Sujithf1dc5602008-10-29 10:16:30 +05301763 const struct ath9k_keyval *k,
Jouni Malinene0caf9e2009-03-02 18:15:53 +02001764 const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001765{
Sujith2660b812009-02-09 13:27:26 +05301766 const struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001767 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301768 u32 key0, key1, key2, key3, key4;
1769 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001770
Sujithf1dc5602008-10-29 10:16:30 +05301771 if (entry >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001772 ath_print(common, ATH_DBG_FATAL,
1773 "keycache entry %u out of range\n", entry);
Sujithf1dc5602008-10-29 10:16:30 +05301774 return false;
1775 }
1776
1777 switch (k->kv_type) {
1778 case ATH9K_CIPHER_AES_OCB:
1779 keyType = AR_KEYTABLE_TYPE_AES;
1780 break;
1781 case ATH9K_CIPHER_AES_CCM:
1782 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001783 ath_print(common, ATH_DBG_ANY,
1784 "AES-CCM not supported by mac rev 0x%x\n",
1785 ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001786 return false;
1787 }
Sujithf1dc5602008-10-29 10:16:30 +05301788 keyType = AR_KEYTABLE_TYPE_CCM;
1789 break;
1790 case ATH9K_CIPHER_TKIP:
1791 keyType = AR_KEYTABLE_TYPE_TKIP;
1792 if (ATH9K_IS_MIC_ENABLED(ah)
1793 && entry + 64 >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001794 ath_print(common, ATH_DBG_ANY,
1795 "entry %u inappropriate for TKIP\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001796 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001797 }
Sujithf1dc5602008-10-29 10:16:30 +05301798 break;
1799 case ATH9K_CIPHER_WEP:
Zhu Yie31a16d2009-05-21 21:47:03 +08001800 if (k->kv_len < WLAN_KEY_LEN_WEP40) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001801 ath_print(common, ATH_DBG_ANY,
1802 "WEP key length %u too small\n", k->kv_len);
Sujithf1dc5602008-10-29 10:16:30 +05301803 return false;
1804 }
Zhu Yie31a16d2009-05-21 21:47:03 +08001805 if (k->kv_len <= WLAN_KEY_LEN_WEP40)
Sujithf1dc5602008-10-29 10:16:30 +05301806 keyType = AR_KEYTABLE_TYPE_40;
Zhu Yie31a16d2009-05-21 21:47:03 +08001807 else if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05301808 keyType = AR_KEYTABLE_TYPE_104;
1809 else
1810 keyType = AR_KEYTABLE_TYPE_128;
1811 break;
1812 case ATH9K_CIPHER_CLR:
1813 keyType = AR_KEYTABLE_TYPE_CLR;
1814 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001815 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001816 ath_print(common, ATH_DBG_FATAL,
1817 "cipher %u not supported\n", k->kv_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001818 return false;
1819 }
Sujithf1dc5602008-10-29 10:16:30 +05301820
Jouni Malinene0caf9e2009-03-02 18:15:53 +02001821 key0 = get_unaligned_le32(k->kv_val + 0);
1822 key1 = get_unaligned_le16(k->kv_val + 4);
1823 key2 = get_unaligned_le32(k->kv_val + 6);
1824 key3 = get_unaligned_le16(k->kv_val + 10);
1825 key4 = get_unaligned_le32(k->kv_val + 12);
Zhu Yie31a16d2009-05-21 21:47:03 +08001826 if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05301827 key4 &= 0xff;
1828
Jouni Malinen672903b2009-03-02 15:06:31 +02001829 /*
1830 * Note: Key cache registers access special memory area that requires
1831 * two 32-bit writes to actually update the values in the internal
1832 * memory. Consequently, the exact order and pairs used here must be
1833 * maintained.
1834 */
1835
Sujithf1dc5602008-10-29 10:16:30 +05301836 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
1837 u16 micentry = entry + 64;
1838
Jouni Malinen672903b2009-03-02 15:06:31 +02001839 /*
1840 * Write inverted key[47:0] first to avoid Michael MIC errors
1841 * on frames that could be sent or received at the same time.
1842 * The correct key will be written in the end once everything
1843 * else is ready.
1844 */
Sujithf1dc5602008-10-29 10:16:30 +05301845 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
1846 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02001847
1848 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05301849 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
1850 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02001851
1852 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05301853 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
1854 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
Jouni Malinen672903b2009-03-02 15:06:31 +02001855
1856 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05301857 (void) ath9k_hw_keysetmac(ah, entry, mac);
1858
Sujith2660b812009-02-09 13:27:26 +05301859 if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) {
Jouni Malinen672903b2009-03-02 15:06:31 +02001860 /*
1861 * TKIP uses two key cache entries:
1862 * Michael MIC TX/RX keys in the same key cache entry
1863 * (idx = main index + 64):
1864 * key0 [31:0] = RX key [31:0]
1865 * key1 [15:0] = TX key [31:16]
1866 * key1 [31:16] = reserved
1867 * key2 [31:0] = RX key [63:32]
1868 * key3 [15:0] = TX key [15:0]
1869 * key3 [31:16] = reserved
1870 * key4 [31:0] = TX key [63:32]
1871 */
Sujithf1dc5602008-10-29 10:16:30 +05301872 u32 mic0, mic1, mic2, mic3, mic4;
1873
1874 mic0 = get_unaligned_le32(k->kv_mic + 0);
1875 mic2 = get_unaligned_le32(k->kv_mic + 4);
1876 mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
1877 mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
1878 mic4 = get_unaligned_le32(k->kv_txmic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02001879
1880 /* Write RX[31:0] and TX[31:16] */
Sujithf1dc5602008-10-29 10:16:30 +05301881 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
1882 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
Jouni Malinen672903b2009-03-02 15:06:31 +02001883
1884 /* Write RX[63:32] and TX[15:0] */
Sujithf1dc5602008-10-29 10:16:30 +05301885 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
1886 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
Jouni Malinen672903b2009-03-02 15:06:31 +02001887
1888 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05301889 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
1890 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
1891 AR_KEYTABLE_TYPE_CLR);
1892
1893 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02001894 /*
1895 * TKIP uses four key cache entries (two for group
1896 * keys):
1897 * Michael MIC TX/RX keys are in different key cache
1898 * entries (idx = main index + 64 for TX and
1899 * main index + 32 + 96 for RX):
1900 * key0 [31:0] = TX/RX MIC key [31:0]
1901 * key1 [31:0] = reserved
1902 * key2 [31:0] = TX/RX MIC key [63:32]
1903 * key3 [31:0] = reserved
1904 * key4 [31:0] = reserved
1905 *
1906 * Upper layer code will call this function separately
1907 * for TX and RX keys when these registers offsets are
1908 * used.
1909 */
Sujithf1dc5602008-10-29 10:16:30 +05301910 u32 mic0, mic2;
1911
1912 mic0 = get_unaligned_le32(k->kv_mic + 0);
1913 mic2 = get_unaligned_le32(k->kv_mic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02001914
1915 /* Write MIC key[31:0] */
Sujithf1dc5602008-10-29 10:16:30 +05301916 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
1917 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02001918
1919 /* Write MIC key[63:32] */
Sujithf1dc5602008-10-29 10:16:30 +05301920 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
1921 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02001922
1923 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05301924 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
1925 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
1926 AR_KEYTABLE_TYPE_CLR);
1927 }
Jouni Malinen672903b2009-03-02 15:06:31 +02001928
1929 /* MAC address registers are reserved for the MIC entry */
Sujithf1dc5602008-10-29 10:16:30 +05301930 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
1931 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02001932
1933 /*
1934 * Write the correct (un-inverted) key[47:0] last to enable
1935 * TKIP now that all other registers are set with correct
1936 * values.
1937 */
Sujithf1dc5602008-10-29 10:16:30 +05301938 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
1939 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
1940 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02001941 /* Write key[47:0] */
Sujithf1dc5602008-10-29 10:16:30 +05301942 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
1943 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02001944
1945 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05301946 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
1947 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02001948
1949 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05301950 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
1951 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
1952
Jouni Malinen672903b2009-03-02 15:06:31 +02001953 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05301954 (void) ath9k_hw_keysetmac(ah, entry, mac);
1955 }
1956
Sujithf1dc5602008-10-29 10:16:30 +05301957 return true;
1958}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001959EXPORT_SYMBOL(ath9k_hw_set_keycache_entry);
Sujithf1dc5602008-10-29 10:16:30 +05301960
Sujithcbe61d82009-02-09 13:27:12 +05301961bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry)
Sujithf1dc5602008-10-29 10:16:30 +05301962{
Sujith2660b812009-02-09 13:27:26 +05301963 if (entry < ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05301964 u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
1965 if (val & AR_KEYTABLE_VALID)
1966 return true;
1967 }
1968 return false;
1969}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001970EXPORT_SYMBOL(ath9k_hw_keyisvalid);
Sujithf1dc5602008-10-29 10:16:30 +05301971
1972/******************************/
1973/* Power Management (Chipset) */
1974/******************************/
1975
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001976/*
1977 * Notify Power Mgt is disabled in self-generated frames.
1978 * If requested, force chip to sleep.
1979 */
Sujithcbe61d82009-02-09 13:27:12 +05301980static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05301981{
1982 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
1983 if (setChip) {
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001984 /*
1985 * Clear the RTC force wake bit to allow the
1986 * mac to go to sleep.
1987 */
Sujithf1dc5602008-10-29 10:16:30 +05301988 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
1989 AR_RTC_FORCE_WAKE_EN);
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001990 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05301991 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1992
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001993 /* Shutdown chip. Active low */
Sujith14b3af32010-03-17 14:25:18 +05301994 if (!AR_SREV_5416(ah) && !AR_SREV_9271(ah))
Sujith4921be82009-09-18 15:04:27 +05301995 REG_CLR_BIT(ah, (AR_RTC_RESET),
1996 AR_RTC_RESET_EN);
Sujithf1dc5602008-10-29 10:16:30 +05301997 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001998}
1999
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04002000/*
2001 * Notify Power Management is enabled in self-generating
2002 * frames. If request, set power mode of chip to
2003 * auto/normal. Duration in units of 128us (1/8 TU).
2004 */
Sujithcbe61d82009-02-09 13:27:12 +05302005static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002006{
Sujithf1dc5602008-10-29 10:16:30 +05302007 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2008 if (setChip) {
Sujith2660b812009-02-09 13:27:26 +05302009 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002010
Sujithf1dc5602008-10-29 10:16:30 +05302011 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04002012 /* Set WakeOnInterrupt bit; clear ForceWake bit */
Sujithf1dc5602008-10-29 10:16:30 +05302013 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2014 AR_RTC_FORCE_WAKE_ON_INT);
2015 } else {
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04002016 /*
2017 * Clear the RTC force wake bit to allow the
2018 * mac to go to sleep.
2019 */
Sujithf1dc5602008-10-29 10:16:30 +05302020 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2021 AR_RTC_FORCE_WAKE_EN);
2022 }
2023 }
2024}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002025
Sujithcbe61d82009-02-09 13:27:12 +05302026static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302027{
2028 u32 val;
2029 int i;
2030
2031 if (setChip) {
2032 if ((REG_READ(ah, AR_RTC_STATUS) &
2033 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2034 if (ath9k_hw_set_reset_reg(ah,
2035 ATH9K_RESET_POWER_ON) != true) {
2036 return false;
2037 }
Luis R. Rodrigueze0412282010-04-15 17:38:15 -04002038 if (!AR_SREV_9300_20_OR_LATER(ah))
2039 ath9k_hw_init_pll(ah, NULL);
Sujithf1dc5602008-10-29 10:16:30 +05302040 }
2041 if (AR_SREV_9100(ah))
2042 REG_SET_BIT(ah, AR_RTC_RESET,
2043 AR_RTC_RESET_EN);
2044
2045 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2046 AR_RTC_FORCE_WAKE_EN);
2047 udelay(50);
2048
2049 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2050 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2051 if (val == AR_RTC_STATUS_ON)
2052 break;
2053 udelay(50);
2054 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2055 AR_RTC_FORCE_WAKE_EN);
2056 }
2057 if (i == 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002058 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2059 "Failed to wakeup in %uus\n",
2060 POWER_UP_TIME / 20);
Sujithf1dc5602008-10-29 10:16:30 +05302061 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002062 }
2063 }
2064
Sujithf1dc5602008-10-29 10:16:30 +05302065 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2066
2067 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002068}
2069
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002070bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05302071{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002072 struct ath_common *common = ath9k_hw_common(ah);
Sujithcbe61d82009-02-09 13:27:12 +05302073 int status = true, setChip = true;
Sujithf1dc5602008-10-29 10:16:30 +05302074 static const char *modes[] = {
2075 "AWAKE",
2076 "FULL-SLEEP",
2077 "NETWORK SLEEP",
2078 "UNDEFINED"
2079 };
Sujithf1dc5602008-10-29 10:16:30 +05302080
Gabor Juhoscbdec972009-07-24 17:27:22 +02002081 if (ah->power_mode == mode)
2082 return status;
2083
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002084 ath_print(common, ATH_DBG_RESET, "%s -> %s\n",
2085 modes[ah->power_mode], modes[mode]);
Sujithf1dc5602008-10-29 10:16:30 +05302086
2087 switch (mode) {
2088 case ATH9K_PM_AWAKE:
2089 status = ath9k_hw_set_power_awake(ah, setChip);
2090 break;
2091 case ATH9K_PM_FULL_SLEEP:
2092 ath9k_set_power_sleep(ah, setChip);
Sujith2660b812009-02-09 13:27:26 +05302093 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05302094 break;
2095 case ATH9K_PM_NETWORK_SLEEP:
2096 ath9k_set_power_network_sleep(ah, setChip);
2097 break;
2098 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002099 ath_print(common, ATH_DBG_FATAL,
2100 "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05302101 return false;
2102 }
Sujith2660b812009-02-09 13:27:26 +05302103 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05302104
2105 return status;
2106}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002107EXPORT_SYMBOL(ath9k_hw_setpower);
Sujithf1dc5602008-10-29 10:16:30 +05302108
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002109/*
2110 * Helper for ASPM support.
2111 *
2112 * Disable PLL when in L0s as well as receiver clock when in L1.
2113 * This power saving option must be enabled through the SerDes.
2114 *
2115 * Programming the SerDes must go through the same 288 bit serial shift
2116 * register as the other analog registers. Hence the 9 writes.
2117 */
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04002118static void ar9002_hw_configpcipowersave(struct ath_hw *ah,
2119 int restore,
2120 int power_off)
Sujithf1dc5602008-10-29 10:16:30 +05302121{
Sujithf1dc5602008-10-29 10:16:30 +05302122 u8 i;
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302123 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05302124
Sujith2660b812009-02-09 13:27:26 +05302125 if (ah->is_pciexpress != true)
Sujithf1dc5602008-10-29 10:16:30 +05302126 return;
2127
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002128 /* Do not touch SerDes registers */
Sujith2660b812009-02-09 13:27:26 +05302129 if (ah->config.pcie_powersave_enable == 2)
Sujithf1dc5602008-10-29 10:16:30 +05302130 return;
2131
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002132 /* Nothing to do on restore for 11N */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302133 if (!restore) {
2134 if (AR_SREV_9280_20_OR_LATER(ah)) {
2135 /*
2136 * AR9280 2.0 or later chips use SerDes values from the
2137 * initvals.h initialized depending on chipset during
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04002138 * __ath9k_hw_init()
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302139 */
2140 for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
2141 REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
2142 INI_RA(&ah->iniPcieSerdes, i, 1));
2143 }
2144 } else if (AR_SREV_9280(ah) &&
2145 (ah->hw_version.macRev == AR_SREV_REVISION_9280_10)) {
2146 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
2147 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
Sujithf1dc5602008-10-29 10:16:30 +05302148
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302149 /* RX shut off when elecidle is asserted */
2150 REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
2151 REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
2152 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
2153
2154 /* Shut off CLKREQ active in L1 */
2155 if (ah->config.pcie_clock_req)
2156 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
2157 else
2158 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
2159
2160 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2161 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2162 REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
2163
2164 /* Load the new settings */
2165 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
2166
2167 } else {
2168 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
2169 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
2170
2171 /* RX shut off when elecidle is asserted */
2172 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
2173 REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
2174 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
2175
2176 /*
2177 * Ignore ah->ah_config.pcie_clock_req setting for
2178 * pre-AR9280 11n
2179 */
2180 REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
2181
2182 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2183 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2184 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
2185
2186 /* Load the new settings */
2187 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
Sujithf1dc5602008-10-29 10:16:30 +05302188 }
Sujithf1dc5602008-10-29 10:16:30 +05302189
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302190 udelay(1000);
Sujithf1dc5602008-10-29 10:16:30 +05302191
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302192 /* set bit 19 to allow forcing of pcie core into L1 state */
2193 REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
Sujithf1dc5602008-10-29 10:16:30 +05302194
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302195 /* Several PCIe massages to ensure proper behaviour */
2196 if (ah->config.pcie_waen) {
2197 val = ah->config.pcie_waen;
2198 if (!power_off)
2199 val &= (~AR_WA_D3_L1_DISABLE);
2200 } else {
2201 if (AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
2202 AR_SREV_9287(ah)) {
2203 val = AR9285_WA_DEFAULT;
2204 if (!power_off)
2205 val &= (~AR_WA_D3_L1_DISABLE);
2206 } else if (AR_SREV_9280(ah)) {
2207 /*
2208 * On AR9280 chips bit 22 of 0x4004 needs to be
2209 * set otherwise card may disappear.
2210 */
2211 val = AR9280_WA_DEFAULT;
2212 if (!power_off)
2213 val &= (~AR_WA_D3_L1_DISABLE);
2214 } else
2215 val = AR_WA_DEFAULT;
2216 }
Sujithf1dc5602008-10-29 10:16:30 +05302217
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302218 REG_WRITE(ah, AR_WA, val);
Sujithf1dc5602008-10-29 10:16:30 +05302219 }
2220
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302221 if (power_off) {
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002222 /*
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302223 * Set PCIe workaround bits
2224 * bit 14 in WA register (disable L1) should only
2225 * be set when device enters D3 and be cleared
2226 * when device comes back to D0.
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002227 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302228 if (ah->config.pcie_waen) {
2229 if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE)
2230 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
2231 } else {
2232 if (((AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
2233 AR_SREV_9287(ah)) &&
2234 (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)) ||
2235 (AR_SREV_9280(ah) &&
2236 (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE))) {
2237 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
2238 }
2239 }
Sujithf1dc5602008-10-29 10:16:30 +05302240 }
2241}
2242
2243/**********************/
2244/* Interrupt Handling */
2245/**********************/
2246
Sujithcbe61d82009-02-09 13:27:12 +05302247bool ath9k_hw_intrpend(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002248{
2249 u32 host_isr;
2250
2251 if (AR_SREV_9100(ah))
2252 return true;
2253
2254 host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
2255 if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
2256 return true;
2257
2258 host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
2259 if ((host_isr & AR_INTR_SYNC_DEFAULT)
2260 && (host_isr != AR_INTR_SPURIOUS))
2261 return true;
2262
2263 return false;
2264}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002265EXPORT_SYMBOL(ath9k_hw_intrpend);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002266
Sujithcbe61d82009-02-09 13:27:12 +05302267bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002268{
2269 u32 isr = 0;
2270 u32 mask2 = 0;
Sujith2660b812009-02-09 13:27:26 +05302271 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002272 u32 sync_cause = 0;
2273 bool fatal_int = false;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002274 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002275
2276 if (!AR_SREV_9100(ah)) {
2277 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
2278 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
2279 == AR_RTC_STATUS_ON) {
2280 isr = REG_READ(ah, AR_ISR);
2281 }
2282 }
2283
Sujithf1dc5602008-10-29 10:16:30 +05302284 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
2285 AR_INTR_SYNC_DEFAULT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002286
2287 *masked = 0;
2288
2289 if (!isr && !sync_cause)
2290 return false;
2291 } else {
2292 *masked = 0;
2293 isr = REG_READ(ah, AR_ISR);
2294 }
2295
2296 if (isr) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002297 if (isr & AR_ISR_BCNMISC) {
2298 u32 isr2;
2299 isr2 = REG_READ(ah, AR_ISR_S2);
2300 if (isr2 & AR_ISR_S2_TIM)
2301 mask2 |= ATH9K_INT_TIM;
2302 if (isr2 & AR_ISR_S2_DTIM)
2303 mask2 |= ATH9K_INT_DTIM;
2304 if (isr2 & AR_ISR_S2_DTIMSYNC)
2305 mask2 |= ATH9K_INT_DTIMSYNC;
2306 if (isr2 & (AR_ISR_S2_CABEND))
2307 mask2 |= ATH9K_INT_CABEND;
2308 if (isr2 & AR_ISR_S2_GTT)
2309 mask2 |= ATH9K_INT_GTT;
2310 if (isr2 & AR_ISR_S2_CST)
2311 mask2 |= ATH9K_INT_CST;
Sujith4af9cf42009-02-12 10:06:47 +05302312 if (isr2 & AR_ISR_S2_TSFOOR)
2313 mask2 |= ATH9K_INT_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002314 }
2315
2316 isr = REG_READ(ah, AR_ISR_RAC);
2317 if (isr == 0xffffffff) {
2318 *masked = 0;
2319 return false;
2320 }
2321
2322 *masked = isr & ATH9K_INT_COMMON;
2323
Sujith0ce024c2009-12-14 14:57:00 +05302324 if (ah->config.rx_intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002325 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
2326 *masked |= ATH9K_INT_RX;
2327 }
2328
2329 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
2330 *masked |= ATH9K_INT_RX;
2331 if (isr &
2332 (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
2333 AR_ISR_TXEOL)) {
2334 u32 s0_s, s1_s;
2335
2336 *masked |= ATH9K_INT_TX;
2337
2338 s0_s = REG_READ(ah, AR_ISR_S0_S);
Sujith2660b812009-02-09 13:27:26 +05302339 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
2340 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002341
2342 s1_s = REG_READ(ah, AR_ISR_S1_S);
Sujith2660b812009-02-09 13:27:26 +05302343 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
2344 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002345 }
2346
2347 if (isr & AR_ISR_RXORN) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002348 ath_print(common, ATH_DBG_INTERRUPT,
2349 "receive FIFO overrun interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002350 }
2351
2352 if (!AR_SREV_9100(ah)) {
Sujith60b67f52008-08-07 10:52:38 +05302353 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002354 u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
2355 if (isr5 & AR_ISR_S5_TIM_TIMER)
2356 *masked |= ATH9K_INT_TIM_TIMER;
2357 }
2358 }
2359
2360 *masked |= mask2;
2361 }
Sujithf1dc5602008-10-29 10:16:30 +05302362
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002363 if (AR_SREV_9100(ah))
2364 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302365
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302366 if (isr & AR_ISR_GENTMR) {
2367 u32 s5_s;
2368
2369 s5_s = REG_READ(ah, AR_ISR_S5_S);
2370 if (isr & AR_ISR_GENTMR) {
2371 ah->intr_gen_timer_trigger =
2372 MS(s5_s, AR_ISR_S5_GENTIMER_TRIG);
2373
2374 ah->intr_gen_timer_thresh =
2375 MS(s5_s, AR_ISR_S5_GENTIMER_THRESH);
2376
2377 if (ah->intr_gen_timer_trigger)
2378 *masked |= ATH9K_INT_GENTIMER;
2379
2380 }
2381 }
2382
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002383 if (sync_cause) {
2384 fatal_int =
2385 (sync_cause &
2386 (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
2387 ? true : false;
2388
2389 if (fatal_int) {
2390 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002391 ath_print(common, ATH_DBG_ANY,
2392 "received PCI FATAL interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002393 }
2394 if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002395 ath_print(common, ATH_DBG_ANY,
2396 "received PCI PERR interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002397 }
Steven Luoa89bff92009-04-12 02:57:54 -07002398 *masked |= ATH9K_INT_FATAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002399 }
2400 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002401 ath_print(common, ATH_DBG_INTERRUPT,
2402 "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002403 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
2404 REG_WRITE(ah, AR_RC, 0);
2405 *masked |= ATH9K_INT_FATAL;
2406 }
2407 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002408 ath_print(common, ATH_DBG_INTERRUPT,
2409 "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002410 }
2411
2412 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
2413 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
2414 }
Sujithf1dc5602008-10-29 10:16:30 +05302415
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002416 return true;
2417}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002418EXPORT_SYMBOL(ath9k_hw_getisr);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002419
Sujithcbe61d82009-02-09 13:27:12 +05302420enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002421{
Pavel Roskin152d5302010-03-31 18:05:37 -04002422 enum ath9k_int omask = ah->imask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002423 u32 mask, mask2;
Sujith2660b812009-02-09 13:27:26 +05302424 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002425 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002426
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002427 ath_print(common, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002428
2429 if (omask & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002430 ath_print(common, ATH_DBG_INTERRUPT, "disable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002431 REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
2432 (void) REG_READ(ah, AR_IER);
2433 if (!AR_SREV_9100(ah)) {
2434 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
2435 (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
2436
2437 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
2438 (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
2439 }
2440 }
2441
2442 mask = ints & ATH9K_INT_COMMON;
2443 mask2 = 0;
2444
2445 if (ints & ATH9K_INT_TX) {
Sujith2660b812009-02-09 13:27:26 +05302446 if (ah->txok_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002447 mask |= AR_IMR_TXOK;
Sujith2660b812009-02-09 13:27:26 +05302448 if (ah->txdesc_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002449 mask |= AR_IMR_TXDESC;
Sujith2660b812009-02-09 13:27:26 +05302450 if (ah->txerr_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002451 mask |= AR_IMR_TXERR;
Sujith2660b812009-02-09 13:27:26 +05302452 if (ah->txeol_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002453 mask |= AR_IMR_TXEOL;
2454 }
2455 if (ints & ATH9K_INT_RX) {
2456 mask |= AR_IMR_RXERR;
Sujith0ce024c2009-12-14 14:57:00 +05302457 if (ah->config.rx_intr_mitigation)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002458 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
2459 else
2460 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
Sujith60b67f52008-08-07 10:52:38 +05302461 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002462 mask |= AR_IMR_GENTMR;
2463 }
2464
2465 if (ints & (ATH9K_INT_BMISC)) {
2466 mask |= AR_IMR_BCNMISC;
2467 if (ints & ATH9K_INT_TIM)
2468 mask2 |= AR_IMR_S2_TIM;
2469 if (ints & ATH9K_INT_DTIM)
2470 mask2 |= AR_IMR_S2_DTIM;
2471 if (ints & ATH9K_INT_DTIMSYNC)
2472 mask2 |= AR_IMR_S2_DTIMSYNC;
2473 if (ints & ATH9K_INT_CABEND)
Sujith4af9cf42009-02-12 10:06:47 +05302474 mask2 |= AR_IMR_S2_CABEND;
2475 if (ints & ATH9K_INT_TSFOOR)
2476 mask2 |= AR_IMR_S2_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002477 }
2478
2479 if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
2480 mask |= AR_IMR_BCNMISC;
2481 if (ints & ATH9K_INT_GTT)
2482 mask2 |= AR_IMR_S2_GTT;
2483 if (ints & ATH9K_INT_CST)
2484 mask2 |= AR_IMR_S2_CST;
2485 }
2486
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002487 ath_print(common, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002488 REG_WRITE(ah, AR_IMR, mask);
Pavel Roskin74bad5c2010-02-23 18:15:27 -05002489 ah->imrs2_reg &= ~(AR_IMR_S2_TIM | AR_IMR_S2_DTIM | AR_IMR_S2_DTIMSYNC |
2490 AR_IMR_S2_CABEND | AR_IMR_S2_CABTO |
2491 AR_IMR_S2_TSFOOR | AR_IMR_S2_GTT | AR_IMR_S2_CST);
2492 ah->imrs2_reg |= mask2;
2493 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002494
Sujith60b67f52008-08-07 10:52:38 +05302495 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002496 if (ints & ATH9K_INT_TIM_TIMER)
2497 REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
2498 else
2499 REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
2500 }
2501
2502 if (ints & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002503 ath_print(common, ATH_DBG_INTERRUPT, "enable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002504 REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
2505 if (!AR_SREV_9100(ah)) {
2506 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
2507 AR_INTR_MAC_IRQ);
2508 REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
2509
2510
2511 REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
2512 AR_INTR_SYNC_DEFAULT);
2513 REG_WRITE(ah, AR_INTR_SYNC_MASK,
2514 AR_INTR_SYNC_DEFAULT);
2515 }
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002516 ath_print(common, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
2517 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002518 }
2519
2520 return omask;
2521}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002522EXPORT_SYMBOL(ath9k_hw_set_interrupts);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002523
Sujithf1dc5602008-10-29 10:16:30 +05302524/*******************/
2525/* Beacon Handling */
2526/*******************/
2527
Sujithcbe61d82009-02-09 13:27:12 +05302528void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002529{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002530 int flags = 0;
2531
Sujith2660b812009-02-09 13:27:26 +05302532 ah->beacon_interval = beacon_period;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002533
Sujith2660b812009-02-09 13:27:26 +05302534 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08002535 case NL80211_IFTYPE_STATION:
2536 case NL80211_IFTYPE_MONITOR:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002537 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
2538 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
2539 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
2540 flags |= AR_TBTT_TIMER_EN;
2541 break;
Colin McCabed97809d2008-12-01 13:38:55 -08002542 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04002543 case NL80211_IFTYPE_MESH_POINT:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002544 REG_SET_BIT(ah, AR_TXCFG,
2545 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
2546 REG_WRITE(ah, AR_NEXT_NDP_TIMER,
2547 TU_TO_USEC(next_beacon +
Sujith2660b812009-02-09 13:27:26 +05302548 (ah->atim_window ? ah->
2549 atim_window : 1)));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002550 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08002551 case NL80211_IFTYPE_AP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002552 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
2553 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
2554 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05302555 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302556 dma_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002557 REG_WRITE(ah, AR_NEXT_SWBA,
2558 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05302559 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302560 sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002561 flags |=
2562 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
2563 break;
Colin McCabed97809d2008-12-01 13:38:55 -08002564 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002565 ath_print(ath9k_hw_common(ah), ATH_DBG_BEACON,
2566 "%s: unsupported opmode: %d\n",
2567 __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08002568 return;
2569 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002570 }
2571
2572 REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
2573 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
2574 REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
2575 REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
2576
2577 beacon_period &= ~ATH9K_BEACON_ENA;
2578 if (beacon_period & ATH9K_BEACON_RESET_TSF) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002579 ath9k_hw_reset_tsf(ah);
2580 }
2581
2582 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
2583}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002584EXPORT_SYMBOL(ath9k_hw_beaconinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002585
Sujithcbe61d82009-02-09 13:27:12 +05302586void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05302587 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002588{
2589 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05302590 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002591 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002592
2593 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
2594
2595 REG_WRITE(ah, AR_BEACON_PERIOD,
2596 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
2597 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
2598 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
2599
2600 REG_RMW_FIELD(ah, AR_RSSI_THR,
2601 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
2602
2603 beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
2604
2605 if (bs->bs_sleepduration > beaconintval)
2606 beaconintval = bs->bs_sleepduration;
2607
2608 dtimperiod = bs->bs_dtimperiod;
2609 if (bs->bs_sleepduration > dtimperiod)
2610 dtimperiod = bs->bs_sleepduration;
2611
2612 if (beaconintval == dtimperiod)
2613 nextTbtt = bs->bs_nextdtim;
2614 else
2615 nextTbtt = bs->bs_nexttbtt;
2616
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002617 ath_print(common, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
2618 ath_print(common, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
2619 ath_print(common, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
2620 ath_print(common, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002621
2622 REG_WRITE(ah, AR_NEXT_DTIM,
2623 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
2624 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
2625
2626 REG_WRITE(ah, AR_SLEEP1,
2627 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
2628 | AR_SLEEP1_ASSUME_DTIM);
2629
Sujith60b67f52008-08-07 10:52:38 +05302630 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002631 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
2632 else
2633 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
2634
2635 REG_WRITE(ah, AR_SLEEP2,
2636 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
2637
2638 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
2639 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
2640
2641 REG_SET_BIT(ah, AR_TIMER_MODE,
2642 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
2643 AR_DTIM_TIMER_EN);
2644
Sujith4af9cf42009-02-12 10:06:47 +05302645 /* TSF Out of Range Threshold */
2646 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002647}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002648EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002649
Sujithf1dc5602008-10-29 10:16:30 +05302650/*******************/
2651/* HW Capabilities */
2652/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002653
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002654int ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002655{
Sujith2660b812009-02-09 13:27:26 +05302656 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002657 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002658 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002659 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002660
Sujithf1dc5602008-10-29 10:16:30 +05302661 u16 capField = 0, eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002662
Sujithf74df6f2009-02-09 13:27:24 +05302663 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002664 regulatory->current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05302665
Sujithf74df6f2009-02-09 13:27:24 +05302666 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
Sujithfec0de12009-02-12 10:06:43 +05302667 if (AR_SREV_9285_10_OR_LATER(ah))
2668 eeval |= AR9285_RDEXT_DEFAULT;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002669 regulatory->current_rd_ext = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05302670
Sujithf74df6f2009-02-09 13:27:24 +05302671 capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
Sujithf1dc5602008-10-29 10:16:30 +05302672
Sujith2660b812009-02-09 13:27:26 +05302673 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05302674 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002675 if (regulatory->current_rd == 0x64 ||
2676 regulatory->current_rd == 0x65)
2677 regulatory->current_rd += 5;
2678 else if (regulatory->current_rd == 0x41)
2679 regulatory->current_rd = 0x43;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002680 ath_print(common, ATH_DBG_REGULATORY,
2681 "regdomain mapped to 0x%x\n", regulatory->current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002682 }
Sujithdc2222a2008-08-14 13:26:55 +05302683
Sujithf74df6f2009-02-09 13:27:24 +05302684 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002685 if ((eeval & (AR5416_OPFLAGS_11G | AR5416_OPFLAGS_11A)) == 0) {
2686 ath_print(common, ATH_DBG_FATAL,
2687 "no band has been marked as supported in EEPROM.\n");
2688 return -EINVAL;
2689 }
2690
Sujithf1dc5602008-10-29 10:16:30 +05302691 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002692
Sujithf1dc5602008-10-29 10:16:30 +05302693 if (eeval & AR5416_OPFLAGS_11A) {
2694 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05302695 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05302696 if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
2697 set_bit(ATH9K_MODE_11NA_HT20,
2698 pCap->wireless_modes);
2699 if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
2700 set_bit(ATH9K_MODE_11NA_HT40PLUS,
2701 pCap->wireless_modes);
2702 set_bit(ATH9K_MODE_11NA_HT40MINUS,
2703 pCap->wireless_modes);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002704 }
2705 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002706 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002707
Sujithf1dc5602008-10-29 10:16:30 +05302708 if (eeval & AR5416_OPFLAGS_11G) {
Sujithf1dc5602008-10-29 10:16:30 +05302709 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05302710 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05302711 if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
2712 set_bit(ATH9K_MODE_11NG_HT20,
2713 pCap->wireless_modes);
2714 if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
2715 set_bit(ATH9K_MODE_11NG_HT40PLUS,
2716 pCap->wireless_modes);
2717 set_bit(ATH9K_MODE_11NG_HT40MINUS,
2718 pCap->wireless_modes);
2719 }
2720 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002721 }
Sujithf1dc5602008-10-29 10:16:30 +05302722
Sujithf74df6f2009-02-09 13:27:24 +05302723 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002724 /*
2725 * For AR9271 we will temporarilly uses the rx chainmax as read from
2726 * the EEPROM.
2727 */
Sujith8147f5d2009-02-20 15:13:23 +05302728 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002729 !(eeval & AR5416_OPFLAGS_11A) &&
2730 !(AR_SREV_9271(ah)))
2731 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
Sujith8147f5d2009-02-20 15:13:23 +05302732 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
2733 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002734 /* Use rx_chainmask from EEPROM. */
Sujith8147f5d2009-02-20 15:13:23 +05302735 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05302736
Sujithd535a422009-02-09 13:27:06 +05302737 if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0)))
Sujith2660b812009-02-09 13:27:26 +05302738 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05302739
2740 pCap->low_2ghz_chan = 2312;
2741 pCap->high_2ghz_chan = 2732;
2742
2743 pCap->low_5ghz_chan = 4920;
2744 pCap->high_5ghz_chan = 6100;
2745
2746 pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
2747 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
2748 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
2749
2750 pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
2751 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
2752 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
2753
Sujith2660b812009-02-09 13:27:26 +05302754 if (ah->config.ht_enable)
Sujithf1dc5602008-10-29 10:16:30 +05302755 pCap->hw_caps |= ATH9K_HW_CAP_HT;
2756 else
2757 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
2758
2759 pCap->hw_caps |= ATH9K_HW_CAP_GTT;
2760 pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
2761 pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
2762 pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
2763
2764 if (capField & AR_EEPROM_EEPCAP_MAXQCU)
2765 pCap->total_queues =
2766 MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
2767 else
2768 pCap->total_queues = ATH9K_NUM_TX_QUEUES;
2769
2770 if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
2771 pCap->keycache_size =
2772 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
2773 else
2774 pCap->keycache_size = AR_KEYTABLE_SIZE;
2775
2776 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -05002777
2778 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
2779 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD >> 1;
2780 else
2781 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
Sujithf1dc5602008-10-29 10:16:30 +05302782
Sujith5b5fa352010-03-17 14:25:15 +05302783 if (AR_SREV_9271(ah))
2784 pCap->num_gpio_pins = AR9271_NUM_GPIO;
2785 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302786 pCap->num_gpio_pins = AR9285_NUM_GPIO;
2787 else if (AR_SREV_9280_10_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302788 pCap->num_gpio_pins = AR928X_NUM_GPIO;
2789 else
2790 pCap->num_gpio_pins = AR_NUM_GPIO;
2791
Sujithf1dc5602008-10-29 10:16:30 +05302792 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
2793 pCap->hw_caps |= ATH9K_HW_CAP_CST;
2794 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
2795 } else {
2796 pCap->rts_aggr_limit = (8 * 1024);
2797 }
2798
2799 pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
2800
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05302801#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05302802 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
2803 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
2804 ah->rfkill_gpio =
2805 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
2806 ah->rfkill_polarity =
2807 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05302808
2809 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
2810 }
2811#endif
Vivek Natarajanbde748a2010-04-05 14:48:05 +05302812 if (AR_SREV_9271(ah))
2813 pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
2814 else
2815 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
Sujithf1dc5602008-10-29 10:16:30 +05302816
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302817 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302818 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
2819 else
2820 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
2821
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002822 if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) {
Sujithf1dc5602008-10-29 10:16:30 +05302823 pCap->reg_cap =
2824 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
2825 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
2826 AR_EEPROM_EEREGCAP_EN_KK_U2 |
2827 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
2828 } else {
2829 pCap->reg_cap =
2830 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
2831 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
2832 }
2833
Senthil Balasubramanianebb90cf2009-09-18 15:07:33 +05302834 /* Advertise midband for AR5416 with FCC midband set in eeprom */
2835 if (regulatory->current_rd_ext & (1 << REG_EXT_FCC_MIDBAND) &&
2836 AR_SREV_5416(ah))
2837 pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
Sujithf1dc5602008-10-29 10:16:30 +05302838
2839 pCap->num_antcfg_5ghz =
Sujithf74df6f2009-02-09 13:27:24 +05302840 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05302841 pCap->num_antcfg_2ghz =
Sujithf74df6f2009-02-09 13:27:24 +05302842 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05302843
Vasanthakumar Thiagarajanfe129462009-09-09 15:25:50 +05302844 if (AR_SREV_9280_10_OR_LATER(ah) &&
Luis R. Rodrigueza36cfbc2009-09-09 16:05:32 -07002845 ath9k_hw_btcoex_supported(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002846 btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO;
2847 btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO;
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05302848
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302849 if (AR_SREV_9285(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002850 btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
2851 btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302852 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002853 btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302854 }
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05302855 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002856 btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE;
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05302857 }
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002858
2859 return 0;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002860}
2861
Sujithcbe61d82009-02-09 13:27:12 +05302862bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05302863 u32 capability, u32 *result)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002864{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002865 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302866 switch (type) {
2867 case ATH9K_CAP_CIPHER:
2868 switch (capability) {
2869 case ATH9K_CIPHER_AES_CCM:
2870 case ATH9K_CIPHER_AES_OCB:
2871 case ATH9K_CIPHER_TKIP:
2872 case ATH9K_CIPHER_WEP:
2873 case ATH9K_CIPHER_MIC:
2874 case ATH9K_CIPHER_CLR:
2875 return true;
2876 default:
2877 return false;
2878 }
2879 case ATH9K_CAP_TKIP_MIC:
2880 switch (capability) {
2881 case 0:
2882 return true;
2883 case 1:
Sujith2660b812009-02-09 13:27:26 +05302884 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05302885 AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
2886 false;
2887 }
2888 case ATH9K_CAP_TKIP_SPLIT:
Sujith2660b812009-02-09 13:27:26 +05302889 return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ?
Sujithf1dc5602008-10-29 10:16:30 +05302890 false : true;
Sujithf1dc5602008-10-29 10:16:30 +05302891 case ATH9K_CAP_MCAST_KEYSRCH:
2892 switch (capability) {
2893 case 0:
2894 return true;
2895 case 1:
2896 if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
2897 return false;
2898 } else {
Sujith2660b812009-02-09 13:27:26 +05302899 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05302900 AR_STA_ID1_MCAST_KSRCH) ? true :
2901 false;
2902 }
2903 }
2904 return false;
Sujithf1dc5602008-10-29 10:16:30 +05302905 case ATH9K_CAP_TXPOW:
2906 switch (capability) {
2907 case 0:
2908 return 0;
2909 case 1:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002910 *result = regulatory->power_limit;
Sujithf1dc5602008-10-29 10:16:30 +05302911 return 0;
2912 case 2:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002913 *result = regulatory->max_power_level;
Sujithf1dc5602008-10-29 10:16:30 +05302914 return 0;
2915 case 3:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002916 *result = regulatory->tp_scale;
Sujithf1dc5602008-10-29 10:16:30 +05302917 return 0;
2918 }
2919 return false;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05302920 case ATH9K_CAP_DS:
2921 return (AR_SREV_9280_20_OR_LATER(ah) &&
2922 (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1))
2923 ? false : true;
Sujithf1dc5602008-10-29 10:16:30 +05302924 default:
2925 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002926 }
Sujithf1dc5602008-10-29 10:16:30 +05302927}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002928EXPORT_SYMBOL(ath9k_hw_getcapability);
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002929
Sujithcbe61d82009-02-09 13:27:12 +05302930bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05302931 u32 capability, u32 setting, int *status)
2932{
Sujithf1dc5602008-10-29 10:16:30 +05302933 switch (type) {
2934 case ATH9K_CAP_TKIP_MIC:
2935 if (setting)
Sujith2660b812009-02-09 13:27:26 +05302936 ah->sta_id1_defaults |=
Sujithf1dc5602008-10-29 10:16:30 +05302937 AR_STA_ID1_CRPT_MIC_ENABLE;
2938 else
Sujith2660b812009-02-09 13:27:26 +05302939 ah->sta_id1_defaults &=
Sujithf1dc5602008-10-29 10:16:30 +05302940 ~AR_STA_ID1_CRPT_MIC_ENABLE;
2941 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302942 case ATH9K_CAP_MCAST_KEYSRCH:
2943 if (setting)
Sujith2660b812009-02-09 13:27:26 +05302944 ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05302945 else
Sujith2660b812009-02-09 13:27:26 +05302946 ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05302947 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302948 default:
2949 return false;
2950 }
2951}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002952EXPORT_SYMBOL(ath9k_hw_setcapability);
Sujithf1dc5602008-10-29 10:16:30 +05302953
2954/****************************/
2955/* GPIO / RFKILL / Antennae */
2956/****************************/
2957
Sujithcbe61d82009-02-09 13:27:12 +05302958static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05302959 u32 gpio, u32 type)
2960{
2961 int addr;
2962 u32 gpio_shift, tmp;
2963
2964 if (gpio > 11)
2965 addr = AR_GPIO_OUTPUT_MUX3;
2966 else if (gpio > 5)
2967 addr = AR_GPIO_OUTPUT_MUX2;
2968 else
2969 addr = AR_GPIO_OUTPUT_MUX1;
2970
2971 gpio_shift = (gpio % 6) * 5;
2972
2973 if (AR_SREV_9280_20_OR_LATER(ah)
2974 || (addr != AR_GPIO_OUTPUT_MUX1)) {
2975 REG_RMW(ah, addr, (type << gpio_shift),
2976 (0x1f << gpio_shift));
2977 } else {
2978 tmp = REG_READ(ah, addr);
2979 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
2980 tmp &= ~(0x1f << gpio_shift);
2981 tmp |= (type << gpio_shift);
2982 REG_WRITE(ah, addr, tmp);
2983 }
2984}
2985
Sujithcbe61d82009-02-09 13:27:12 +05302986void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05302987{
2988 u32 gpio_shift;
2989
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07002990 BUG_ON(gpio >= ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05302991
2992 gpio_shift = gpio << 1;
2993
2994 REG_RMW(ah,
2995 AR_GPIO_OE_OUT,
2996 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
2997 (AR_GPIO_OE_OUT_DRV << gpio_shift));
2998}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002999EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
Sujithf1dc5602008-10-29 10:16:30 +05303000
Sujithcbe61d82009-02-09 13:27:12 +05303001u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303002{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303003#define MS_REG_READ(x, y) \
3004 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
3005
Sujith2660b812009-02-09 13:27:26 +05303006 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05303007 return 0xffffffff;
3008
Felix Fietkau783dfca2010-04-15 17:38:11 -04003009 if (AR_SREV_9300_20_OR_LATER(ah))
3010 return MS_REG_READ(AR9300, gpio) != 0;
3011 else if (AR_SREV_9271(ah))
Sujith5b5fa352010-03-17 14:25:15 +05303012 return MS_REG_READ(AR9271, gpio) != 0;
3013 else if (AR_SREV_9287_10_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05303014 return MS_REG_READ(AR9287, gpio) != 0;
3015 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303016 return MS_REG_READ(AR9285, gpio) != 0;
3017 else if (AR_SREV_9280_10_OR_LATER(ah))
3018 return MS_REG_READ(AR928X, gpio) != 0;
3019 else
3020 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05303021}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003022EXPORT_SYMBOL(ath9k_hw_gpio_get);
Sujithf1dc5602008-10-29 10:16:30 +05303023
Sujithcbe61d82009-02-09 13:27:12 +05303024void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05303025 u32 ah_signal_type)
3026{
3027 u32 gpio_shift;
3028
3029 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
3030
3031 gpio_shift = 2 * gpio;
3032
3033 REG_RMW(ah,
3034 AR_GPIO_OE_OUT,
3035 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
3036 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3037}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003038EXPORT_SYMBOL(ath9k_hw_cfg_output);
Sujithf1dc5602008-10-29 10:16:30 +05303039
Sujithcbe61d82009-02-09 13:27:12 +05303040void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05303041{
Sujith5b5fa352010-03-17 14:25:15 +05303042 if (AR_SREV_9271(ah))
3043 val = ~val;
3044
Sujithf1dc5602008-10-29 10:16:30 +05303045 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
3046 AR_GPIO_BIT(gpio));
3047}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003048EXPORT_SYMBOL(ath9k_hw_set_gpio);
Sujithf1dc5602008-10-29 10:16:30 +05303049
Sujithcbe61d82009-02-09 13:27:12 +05303050u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303051{
3052 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
3053}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003054EXPORT_SYMBOL(ath9k_hw_getdefantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303055
Sujithcbe61d82009-02-09 13:27:12 +05303056void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05303057{
3058 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
3059}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003060EXPORT_SYMBOL(ath9k_hw_setantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303061
Sujithf1dc5602008-10-29 10:16:30 +05303062/*********************/
3063/* General Operation */
3064/*********************/
3065
Sujithcbe61d82009-02-09 13:27:12 +05303066u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303067{
3068 u32 bits = REG_READ(ah, AR_RX_FILTER);
3069 u32 phybits = REG_READ(ah, AR_PHY_ERR);
3070
3071 if (phybits & AR_PHY_ERR_RADAR)
3072 bits |= ATH9K_RX_FILTER_PHYRADAR;
3073 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
3074 bits |= ATH9K_RX_FILTER_PHYERR;
3075
3076 return bits;
3077}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003078EXPORT_SYMBOL(ath9k_hw_getrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303079
Sujithcbe61d82009-02-09 13:27:12 +05303080void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05303081{
3082 u32 phybits;
3083
Sujith7ea310b2009-09-03 12:08:43 +05303084 REG_WRITE(ah, AR_RX_FILTER, bits);
3085
Sujithf1dc5602008-10-29 10:16:30 +05303086 phybits = 0;
3087 if (bits & ATH9K_RX_FILTER_PHYRADAR)
3088 phybits |= AR_PHY_ERR_RADAR;
3089 if (bits & ATH9K_RX_FILTER_PHYERR)
3090 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
3091 REG_WRITE(ah, AR_PHY_ERR, phybits);
3092
3093 if (phybits)
3094 REG_WRITE(ah, AR_RXCFG,
3095 REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
3096 else
3097 REG_WRITE(ah, AR_RXCFG,
3098 REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
3099}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003100EXPORT_SYMBOL(ath9k_hw_setrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303101
Sujithcbe61d82009-02-09 13:27:12 +05303102bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303103{
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05303104 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
3105 return false;
3106
3107 ath9k_hw_init_pll(ah, NULL);
3108 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303109}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003110EXPORT_SYMBOL(ath9k_hw_phy_disable);
Sujithf1dc5602008-10-29 10:16:30 +05303111
Sujithcbe61d82009-02-09 13:27:12 +05303112bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303113{
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07003114 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05303115 return false;
3116
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05303117 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
3118 return false;
3119
3120 ath9k_hw_init_pll(ah, NULL);
3121 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303122}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003123EXPORT_SYMBOL(ath9k_hw_disable);
Sujithf1dc5602008-10-29 10:16:30 +05303124
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003125void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
Sujithf1dc5602008-10-29 10:16:30 +05303126{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003127 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujith2660b812009-02-09 13:27:26 +05303128 struct ath9k_channel *chan = ah->curchan;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08003129 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05303130
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003131 regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER);
Sujithf1dc5602008-10-29 10:16:30 +05303132
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003133 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003134 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003135 channel->max_antenna_gain * 2,
3136 channel->max_power * 2,
3137 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003138 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05303139}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003140EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
Sujithf1dc5602008-10-29 10:16:30 +05303141
Sujithcbe61d82009-02-09 13:27:12 +05303142void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac)
Sujithf1dc5602008-10-29 10:16:30 +05303143{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07003144 memcpy(ath9k_hw_common(ah)->macaddr, mac, ETH_ALEN);
Sujithf1dc5602008-10-29 10:16:30 +05303145}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003146EXPORT_SYMBOL(ath9k_hw_setmac);
Sujithf1dc5602008-10-29 10:16:30 +05303147
Sujithcbe61d82009-02-09 13:27:12 +05303148void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303149{
Sujith2660b812009-02-09 13:27:26 +05303150 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05303151}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003152EXPORT_SYMBOL(ath9k_hw_setopmode);
Sujithf1dc5602008-10-29 10:16:30 +05303153
Sujithcbe61d82009-02-09 13:27:12 +05303154void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05303155{
3156 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
3157 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
3158}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003159EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303160
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07003161void ath9k_hw_write_associd(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303162{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07003163 struct ath_common *common = ath9k_hw_common(ah);
3164
3165 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
3166 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
3167 ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05303168}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003169EXPORT_SYMBOL(ath9k_hw_write_associd);
Sujithf1dc5602008-10-29 10:16:30 +05303170
Sujithcbe61d82009-02-09 13:27:12 +05303171u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303172{
3173 u64 tsf;
3174
3175 tsf = REG_READ(ah, AR_TSF_U32);
3176 tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
3177
3178 return tsf;
3179}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003180EXPORT_SYMBOL(ath9k_hw_gettsf64);
Sujithf1dc5602008-10-29 10:16:30 +05303181
Sujithcbe61d82009-02-09 13:27:12 +05303182void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003183{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003184 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01003185 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003186}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003187EXPORT_SYMBOL(ath9k_hw_settsf64);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003188
Sujithcbe61d82009-02-09 13:27:12 +05303189void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303190{
Gabor Juhosf9b604f2009-06-21 00:02:15 +02003191 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
3192 AH_TSF_WRITE_TIMEOUT))
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003193 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
3194 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
Gabor Juhosf9b604f2009-06-21 00:02:15 +02003195
Sujithf1dc5602008-10-29 10:16:30 +05303196 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003197}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003198EXPORT_SYMBOL(ath9k_hw_reset_tsf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003199
Sujith54e4cec2009-08-07 09:45:09 +05303200void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003201{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003202 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303203 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003204 else
Sujith2660b812009-02-09 13:27:26 +05303205 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003206}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003207EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003208
Luis R. Rodriguez30cbd422009-11-03 16:10:46 -08003209/*
3210 * Extend 15-bit time stamp from rx descriptor to
3211 * a full 64-bit TSF using the current h/w TSF.
3212*/
3213u64 ath9k_hw_extend_tsf(struct ath_hw *ah, u32 rstamp)
3214{
3215 u64 tsf;
3216
3217 tsf = ath9k_hw_gettsf64(ah);
3218 if ((tsf & 0x7fff) < rstamp)
3219 tsf -= 0x8000;
3220 return (tsf & ~0x7fff) | rstamp;
3221}
3222EXPORT_SYMBOL(ath9k_hw_extend_tsf);
3223
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003224void ath9k_hw_set11nmac2040(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003225{
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003226 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithf1dc5602008-10-29 10:16:30 +05303227 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003228
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003229 if (conf_is_ht40(conf) && !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05303230 macmode = AR_2040_JOINED_RX_CLEAR;
3231 else
3232 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003233
Sujithf1dc5602008-10-29 10:16:30 +05303234 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003235}
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303236
3237/* HW Generic timers configuration */
3238
3239static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
3240{
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_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3249 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
3250 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
3251 AR_NDP2_TIMER_MODE, 0x0002},
3252 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
3253 AR_NDP2_TIMER_MODE, 0x0004},
3254 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
3255 AR_NDP2_TIMER_MODE, 0x0008},
3256 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
3257 AR_NDP2_TIMER_MODE, 0x0010},
3258 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
3259 AR_NDP2_TIMER_MODE, 0x0020},
3260 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
3261 AR_NDP2_TIMER_MODE, 0x0040},
3262 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
3263 AR_NDP2_TIMER_MODE, 0x0080}
3264};
3265
3266/* HW generic timer primitives */
3267
3268/* compute and clear index of rightmost 1 */
3269static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
3270{
3271 u32 b;
3272
3273 b = *mask;
3274 b &= (0-b);
3275 *mask &= ~b;
3276 b *= debruijn32;
3277 b >>= 27;
3278
3279 return timer_table->gen_timer_index[b];
3280}
3281
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05303282u32 ath9k_hw_gettsf32(struct ath_hw *ah)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303283{
3284 return REG_READ(ah, AR_TSF_L32);
3285}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003286EXPORT_SYMBOL(ath9k_hw_gettsf32);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303287
3288struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
3289 void (*trigger)(void *),
3290 void (*overflow)(void *),
3291 void *arg,
3292 u8 timer_index)
3293{
3294 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3295 struct ath_gen_timer *timer;
3296
3297 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
3298
3299 if (timer == NULL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003300 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
3301 "Failed to allocate memory"
3302 "for hw timer[%d]\n", timer_index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303303 return NULL;
3304 }
3305
3306 /* allocate a hardware generic timer slot */
3307 timer_table->timers[timer_index] = timer;
3308 timer->index = timer_index;
3309 timer->trigger = trigger;
3310 timer->overflow = overflow;
3311 timer->arg = arg;
3312
3313 return timer;
3314}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003315EXPORT_SYMBOL(ath_gen_timer_alloc);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303316
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07003317void ath9k_hw_gen_timer_start(struct ath_hw *ah,
3318 struct ath_gen_timer *timer,
3319 u32 timer_next,
3320 u32 timer_period)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303321{
3322 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3323 u32 tsf;
3324
3325 BUG_ON(!timer_period);
3326
3327 set_bit(timer->index, &timer_table->timer_mask.timer_bits);
3328
3329 tsf = ath9k_hw_gettsf32(ah);
3330
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003331 ath_print(ath9k_hw_common(ah), ATH_DBG_HWTIMER,
3332 "curent tsf %x period %x"
3333 "timer_next %x\n", tsf, timer_period, timer_next);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303334
3335 /*
3336 * Pull timer_next forward if the current TSF already passed it
3337 * because of software latency
3338 */
3339 if (timer_next < tsf)
3340 timer_next = tsf + timer_period;
3341
3342 /*
3343 * Program generic timer registers
3344 */
3345 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
3346 timer_next);
3347 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
3348 timer_period);
3349 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
3350 gen_tmr_configuration[timer->index].mode_mask);
3351
3352 /* Enable both trigger and thresh interrupt masks */
3353 REG_SET_BIT(ah, AR_IMR_S5,
3354 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
3355 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303356}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003357EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303358
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07003359void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303360{
3361 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3362
3363 if ((timer->index < AR_FIRST_NDP_TIMER) ||
3364 (timer->index >= ATH_MAX_GEN_TIMER)) {
3365 return;
3366 }
3367
3368 /* Clear generic timer enable bits. */
3369 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
3370 gen_tmr_configuration[timer->index].mode_mask);
3371
3372 /* Disable both trigger and thresh interrupt masks */
3373 REG_CLR_BIT(ah, AR_IMR_S5,
3374 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
3375 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
3376
3377 clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303378}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003379EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303380
3381void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
3382{
3383 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3384
3385 /* free the hardware generic timer slot */
3386 timer_table->timers[timer->index] = NULL;
3387 kfree(timer);
3388}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003389EXPORT_SYMBOL(ath_gen_timer_free);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303390
3391/*
3392 * Generic Timer Interrupts handling
3393 */
3394void ath_gen_timer_isr(struct ath_hw *ah)
3395{
3396 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3397 struct ath_gen_timer *timer;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003398 struct ath_common *common = ath9k_hw_common(ah);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303399 u32 trigger_mask, thresh_mask, index;
3400
3401 /* get hardware generic timer interrupt status */
3402 trigger_mask = ah->intr_gen_timer_trigger;
3403 thresh_mask = ah->intr_gen_timer_thresh;
3404 trigger_mask &= timer_table->timer_mask.val;
3405 thresh_mask &= timer_table->timer_mask.val;
3406
3407 trigger_mask &= ~thresh_mask;
3408
3409 while (thresh_mask) {
3410 index = rightmost_index(timer_table, &thresh_mask);
3411 timer = timer_table->timers[index];
3412 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003413 ath_print(common, ATH_DBG_HWTIMER,
3414 "TSF overflow for Gen timer %d\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303415 timer->overflow(timer->arg);
3416 }
3417
3418 while (trigger_mask) {
3419 index = rightmost_index(timer_table, &trigger_mask);
3420 timer = timer_table->timers[index];
3421 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003422 ath_print(common, ATH_DBG_HWTIMER,
3423 "Gen timer[%d] trigger\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303424 timer->trigger(timer->arg);
3425 }
3426}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003427EXPORT_SYMBOL(ath_gen_timer_isr);
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003428
Sujith05020d22010-03-17 14:25:23 +05303429/********/
3430/* HTC */
3431/********/
3432
3433void ath9k_hw_htc_resetinit(struct ath_hw *ah)
3434{
3435 ah->htc_reset_init = true;
3436}
3437EXPORT_SYMBOL(ath9k_hw_htc_resetinit);
3438
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003439static struct {
3440 u32 version;
3441 const char * name;
3442} ath_mac_bb_names[] = {
3443 /* Devices with external radios */
3444 { AR_SREV_VERSION_5416_PCI, "5416" },
3445 { AR_SREV_VERSION_5416_PCIE, "5418" },
3446 { AR_SREV_VERSION_9100, "9100" },
3447 { AR_SREV_VERSION_9160, "9160" },
3448 /* Single-chip solutions */
3449 { AR_SREV_VERSION_9280, "9280" },
3450 { AR_SREV_VERSION_9285, "9285" },
Luis R. Rodriguez11158472009-10-27 12:59:35 -04003451 { AR_SREV_VERSION_9287, "9287" },
3452 { AR_SREV_VERSION_9271, "9271" },
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003453};
3454
3455/* For devices with external radios */
3456static struct {
3457 u16 version;
3458 const char * name;
3459} ath_rf_names[] = {
3460 { 0, "5133" },
3461 { AR_RAD5133_SREV_MAJOR, "5133" },
3462 { AR_RAD5122_SREV_MAJOR, "5122" },
3463 { AR_RAD2133_SREV_MAJOR, "2133" },
3464 { AR_RAD2122_SREV_MAJOR, "2122" }
3465};
3466
3467/*
3468 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
3469 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003470static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003471{
3472 int i;
3473
3474 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
3475 if (ath_mac_bb_names[i].version == mac_bb_version) {
3476 return ath_mac_bb_names[i].name;
3477 }
3478 }
3479
3480 return "????";
3481}
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003482
3483/*
3484 * Return the RF name. "????" is returned if the RF is unknown.
3485 * Used for devices with external radios.
3486 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003487static const char *ath9k_hw_rf_name(u16 rf_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003488{
3489 int i;
3490
3491 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
3492 if (ath_rf_names[i].version == rf_version) {
3493 return ath_rf_names[i].name;
3494 }
3495 }
3496
3497 return "????";
3498}
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003499
3500void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
3501{
3502 int used;
3503
3504 /* chipsets >= AR9280 are single-chip */
3505 if (AR_SREV_9280_10_OR_LATER(ah)) {
3506 used = snprintf(hw_name, len,
3507 "Atheros AR%s Rev:%x",
3508 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3509 ah->hw_version.macRev);
3510 }
3511 else {
3512 used = snprintf(hw_name, len,
3513 "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
3514 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3515 ah->hw_version.macRev,
3516 ath9k_hw_rf_name((ah->hw_version.analog5GhzRev &
3517 AR_RADIO_SREV_MAJOR)),
3518 ah->hw_version.phyRev);
3519 }
3520
3521 hw_name[used] = '\0';
3522}
3523EXPORT_SYMBOL(ath9k_hw_name);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04003524
3525/* Sets up the AR5008/AR9001/AR9002 hardware familiy callbacks */
3526static void ar9002_hw_attach_ops(struct ath_hw *ah)
3527{
3528 struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
3529 struct ath_hw_ops *ops = ath9k_hw_ops(ah);
3530
3531 priv_ops->init_cal_settings = ar9002_hw_init_cal_settings;
3532 priv_ops->init_mode_regs = ar9002_hw_init_mode_regs;
3533 priv_ops->macversion_supported = ar9002_hw_macversion_supported;
3534
3535 ops->config_pci_powersave = ar9002_hw_configpcipowersave;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04003536
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04003537 ar5008_hw_attach_phy_ops(ah);
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04003538 if (AR_SREV_9280_10_OR_LATER(ah))
3539 ar9002_hw_attach_phy_ops(ah);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04003540}
3541
3542/* Sets up the AR9003 hardware familiy callbacks */
3543static void ar9003_hw_attach_ops(struct ath_hw *ah)
3544{
3545 ar9003_hw_attach_phy_ops(ah);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04003546}