blob: 3157ddeab31c792765bc5b5ef7c88e518c159bbd [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
Luis R. Rodriguezb3950e62010-04-15 17:39:03 -04002 * Copyright (c) 2008-2010 Atheros Communications Inc.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include <linux/io.h>
18#include <asm/unaligned.h>
19
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -070020#include "hw.h"
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -040021#include "hw-ops.h"
Luis R. Rodriguezcfe8cba2009-09-13 23:39:31 -070022#include "rc.h"
Luis R. Rodriguezaf01c042010-04-15 17:38:36 -040023#include "ar9002_initvals.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070024
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
Sujithcbe61d82009-02-09 13:27:12 +053029static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070030
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040031MODULE_AUTHOR("Atheros Communications");
32MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
33MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
34MODULE_LICENSE("Dual BSD/GPL");
35
36static int __init ath9k_init(void)
37{
38 return 0;
39}
40module_init(ath9k_init);
41
42static void __exit ath9k_exit(void)
43{
44 return;
45}
46module_exit(ath9k_exit);
47
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -040048/* Private hardware callbacks */
49
50static void ath9k_hw_init_cal_settings(struct ath_hw *ah)
51{
52 ath9k_hw_private_ops(ah)->init_cal_settings(ah);
53}
54
55static void ath9k_hw_init_mode_regs(struct ath_hw *ah)
56{
57 ath9k_hw_private_ops(ah)->init_mode_regs(ah);
58}
59
60static bool ath9k_hw_macversion_supported(struct ath_hw *ah)
61{
62 struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
63
64 return priv_ops->macversion_supported(ah->hw_version.macVersion);
65}
66
Luis R. Rodriguez64773962010-04-15 17:38:17 -040067static u32 ath9k_hw_compute_pll_control(struct ath_hw *ah,
68 struct ath9k_channel *chan)
69{
70 return ath9k_hw_private_ops(ah)->compute_pll_control(ah, chan);
71}
72
Sujithf1dc5602008-10-29 10:16:30 +053073/********************/
74/* Helper Functions */
75/********************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070076
Sujithcbe61d82009-02-09 13:27:12 +053077static u32 ath9k_hw_mac_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053078{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070079 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053080
Sujith2660b812009-02-09 13:27:26 +053081 if (!ah->curchan) /* should really check for CCK instead */
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080082 return usecs *ATH9K_CLOCK_RATE_CCK;
83 if (conf->channel->band == IEEE80211_BAND_2GHZ)
84 return usecs *ATH9K_CLOCK_RATE_2GHZ_OFDM;
85 return usecs *ATH9K_CLOCK_RATE_5GHZ_OFDM;
Sujithf1dc5602008-10-29 10:16:30 +053086}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070087
Sujithcbe61d82009-02-09 13:27:12 +053088static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053089{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070090 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053091
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080092 if (conf_is_ht40(conf))
Sujithf1dc5602008-10-29 10:16:30 +053093 return ath9k_hw_mac_clks(ah, usecs) * 2;
94 else
95 return ath9k_hw_mac_clks(ah, usecs);
96}
97
Sujith0caa7b12009-02-16 13:23:20 +053098bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070099{
100 int i;
101
Sujith0caa7b12009-02-16 13:23:20 +0530102 BUG_ON(timeout < AH_TIME_QUANTUM);
103
104 for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700105 if ((REG_READ(ah, reg) & mask) == val)
106 return true;
107
108 udelay(AH_TIME_QUANTUM);
109 }
Sujith04bd4632008-11-28 22:18:05 +0530110
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700111 ath_print(ath9k_hw_common(ah), ATH_DBG_ANY,
112 "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
113 timeout, reg, REG_READ(ah, reg), mask, val);
Sujithf1dc5602008-10-29 10:16:30 +0530114
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700115 return false;
116}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400117EXPORT_SYMBOL(ath9k_hw_wait);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700118
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700119u32 ath9k_hw_reverse_bits(u32 val, u32 n)
120{
121 u32 retval;
122 int i;
123
124 for (i = 0, retval = 0; i < n; i++) {
125 retval = (retval << 1) | (val & 1);
126 val >>= 1;
127 }
128 return retval;
129}
130
Sujithcbe61d82009-02-09 13:27:12 +0530131bool ath9k_get_channel_edges(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530132 u16 flags, u16 *low,
133 u16 *high)
134{
Sujith2660b812009-02-09 13:27:26 +0530135 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530136
137 if (flags & CHANNEL_5GHZ) {
138 *low = pCap->low_5ghz_chan;
139 *high = pCap->high_5ghz_chan;
140 return true;
141 }
142 if ((flags & CHANNEL_2GHZ)) {
143 *low = pCap->low_2ghz_chan;
144 *high = pCap->high_2ghz_chan;
145 return true;
146 }
147 return false;
148}
149
Sujithcbe61d82009-02-09 13:27:12 +0530150u16 ath9k_hw_computetxtime(struct ath_hw *ah,
Felix Fietkau545750d2009-11-23 22:21:01 +0100151 u8 phy, int kbps,
Sujithf1dc5602008-10-29 10:16:30 +0530152 u32 frameLen, u16 rateix,
153 bool shortPreamble)
154{
155 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
Sujithf1dc5602008-10-29 10:16:30 +0530156
157 if (kbps == 0)
158 return 0;
159
Felix Fietkau545750d2009-11-23 22:21:01 +0100160 switch (phy) {
Sujith46d14a52008-11-18 09:08:13 +0530161 case WLAN_RC_PHY_CCK:
Sujithf1dc5602008-10-29 10:16:30 +0530162 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
Felix Fietkau545750d2009-11-23 22:21:01 +0100163 if (shortPreamble)
Sujithf1dc5602008-10-29 10:16:30 +0530164 phyTime >>= 1;
165 numBits = frameLen << 3;
166 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
167 break;
Sujith46d14a52008-11-18 09:08:13 +0530168 case WLAN_RC_PHY_OFDM:
Sujith2660b812009-02-09 13:27:26 +0530169 if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530170 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
171 numBits = OFDM_PLCP_BITS + (frameLen << 3);
172 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
173 txTime = OFDM_SIFS_TIME_QUARTER
174 + OFDM_PREAMBLE_TIME_QUARTER
175 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
Sujith2660b812009-02-09 13:27:26 +0530176 } else if (ah->curchan &&
177 IS_CHAN_HALF_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530178 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
179 numBits = OFDM_PLCP_BITS + (frameLen << 3);
180 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
181 txTime = OFDM_SIFS_TIME_HALF +
182 OFDM_PREAMBLE_TIME_HALF
183 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
184 } else {
185 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
186 numBits = OFDM_PLCP_BITS + (frameLen << 3);
187 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
188 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
189 + (numSymbols * OFDM_SYMBOL_TIME);
190 }
191 break;
192 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700193 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
Felix Fietkau545750d2009-11-23 22:21:01 +0100194 "Unknown phy %u (rate ix %u)\n", phy, rateix);
Sujithf1dc5602008-10-29 10:16:30 +0530195 txTime = 0;
196 break;
197 }
198
199 return txTime;
200}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400201EXPORT_SYMBOL(ath9k_hw_computetxtime);
Sujithf1dc5602008-10-29 10:16:30 +0530202
Sujithcbe61d82009-02-09 13:27:12 +0530203void ath9k_hw_get_channel_centers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530204 struct ath9k_channel *chan,
205 struct chan_centers *centers)
206{
207 int8_t extoff;
Sujithf1dc5602008-10-29 10:16:30 +0530208
209 if (!IS_CHAN_HT40(chan)) {
210 centers->ctl_center = centers->ext_center =
211 centers->synth_center = chan->channel;
212 return;
213 }
214
215 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
216 (chan->chanmode == CHANNEL_G_HT40PLUS)) {
217 centers->synth_center =
218 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
219 extoff = 1;
220 } else {
221 centers->synth_center =
222 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
223 extoff = -1;
224 }
225
226 centers->ctl_center =
227 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700228 /* 25 MHz spacing is supported by hw but not on upper layers */
Sujithf1dc5602008-10-29 10:16:30 +0530229 centers->ext_center =
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700230 centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT);
Sujithf1dc5602008-10-29 10:16:30 +0530231}
232
233/******************/
234/* Chip Revisions */
235/******************/
236
Sujithcbe61d82009-02-09 13:27:12 +0530237static void ath9k_hw_read_revisions(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530238{
239 u32 val;
240
241 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
242
243 if (val == 0xFF) {
244 val = REG_READ(ah, AR_SREV);
Sujithd535a422009-02-09 13:27:06 +0530245 ah->hw_version.macVersion =
246 (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
247 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
Sujith2660b812009-02-09 13:27:26 +0530248 ah->is_pciexpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
Sujithf1dc5602008-10-29 10:16:30 +0530249 } else {
250 if (!AR_SREV_9100(ah))
Sujithd535a422009-02-09 13:27:06 +0530251 ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
Sujithf1dc5602008-10-29 10:16:30 +0530252
Sujithd535a422009-02-09 13:27:06 +0530253 ah->hw_version.macRev = val & AR_SREV_REVISION;
Sujithf1dc5602008-10-29 10:16:30 +0530254
Sujithd535a422009-02-09 13:27:06 +0530255 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
Sujith2660b812009-02-09 13:27:26 +0530256 ah->is_pciexpress = true;
Sujithf1dc5602008-10-29 10:16:30 +0530257 }
258}
259
Sujithcbe61d82009-02-09 13:27:12 +0530260static int ath9k_hw_get_radiorev(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530261{
262 u32 val;
263 int i;
264
265 REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
266
267 for (i = 0; i < 8; i++)
268 REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
269 val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
270 val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
271
272 return ath9k_hw_reverse_bits(val, 8);
273}
274
275/************************************/
276/* HW Attach, Detach, Init Routines */
277/************************************/
278
Sujithcbe61d82009-02-09 13:27:12 +0530279static void ath9k_hw_disablepcie(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530280{
Sujithfeed0292009-01-29 11:37:35 +0530281 if (AR_SREV_9100(ah))
Sujithf1dc5602008-10-29 10:16:30 +0530282 return;
283
284 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
285 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
286 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
287 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
288 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
289 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
290 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
291 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
292 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
293
294 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
295}
296
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400297/* This should work for all families including legacy */
Sujithcbe61d82009-02-09 13:27:12 +0530298static bool ath9k_hw_chip_test(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530299{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700300 struct ath_common *common = ath9k_hw_common(ah);
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400301 u32 regAddr[2] = { AR_STA_ID0 };
Sujithf1dc5602008-10-29 10:16:30 +0530302 u32 regHold[2];
303 u32 patternData[4] = { 0x55555555,
304 0xaaaaaaaa,
305 0x66666666,
306 0x99999999 };
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400307 int i, j, loop_max;
Sujithf1dc5602008-10-29 10:16:30 +0530308
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400309 if (!AR_SREV_9300_20_OR_LATER(ah)) {
310 loop_max = 2;
311 regAddr[1] = AR_PHY_BASE + (8 << 2);
312 } else
313 loop_max = 1;
314
315 for (i = 0; i < loop_max; i++) {
Sujithf1dc5602008-10-29 10:16:30 +0530316 u32 addr = regAddr[i];
317 u32 wrData, rdData;
318
319 regHold[i] = REG_READ(ah, addr);
320 for (j = 0; j < 0x100; j++) {
321 wrData = (j << 16) | j;
322 REG_WRITE(ah, addr, wrData);
323 rdData = REG_READ(ah, addr);
324 if (rdData != wrData) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700325 ath_print(common, ATH_DBG_FATAL,
326 "address test failed "
327 "addr: 0x%08x - wr:0x%08x != "
328 "rd:0x%08x\n",
329 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530330 return false;
331 }
332 }
333 for (j = 0; j < 4; j++) {
334 wrData = patternData[j];
335 REG_WRITE(ah, addr, wrData);
336 rdData = REG_READ(ah, addr);
337 if (wrData != rdData) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700338 ath_print(common, ATH_DBG_FATAL,
339 "address test failed "
340 "addr: 0x%08x - wr:0x%08x != "
341 "rd:0x%08x\n",
342 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530343 return false;
344 }
345 }
346 REG_WRITE(ah, regAddr[i], regHold[i]);
347 }
348 udelay(100);
Sujithcbe61d82009-02-09 13:27:12 +0530349
Sujithf1dc5602008-10-29 10:16:30 +0530350 return true;
351}
352
Luis R. Rodriguezb8b0f372009-08-03 12:24:43 -0700353static void ath9k_hw_init_config(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700354{
355 int i;
356
Sujith2660b812009-02-09 13:27:26 +0530357 ah->config.dma_beacon_response_time = 2;
358 ah->config.sw_beacon_response_time = 10;
359 ah->config.additional_swba_backoff = 0;
360 ah->config.ack_6mb = 0x0;
361 ah->config.cwm_ignore_extcca = 0;
362 ah->config.pcie_powersave_enable = 0;
Sujith2660b812009-02-09 13:27:26 +0530363 ah->config.pcie_clock_req = 0;
Sujith2660b812009-02-09 13:27:26 +0530364 ah->config.pcie_waen = 0;
365 ah->config.analog_shiftreg = 1;
Sujith2660b812009-02-09 13:27:26 +0530366 ah->config.ofdm_trig_low = 200;
367 ah->config.ofdm_trig_high = 500;
368 ah->config.cck_trig_high = 200;
369 ah->config.cck_trig_low = 100;
Luis R. Rodriguez31a0bd32010-04-15 17:38:22 -0400370
371 /*
372 * For now ANI is disabled for AR9003, it is still
373 * being tested.
374 */
375 if (!AR_SREV_9300_20_OR_LATER(ah))
376 ah->config.enable_ani = 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700377
378 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujith2660b812009-02-09 13:27:26 +0530379 ah->config.spurchans[i][0] = AR_NO_SPUR;
380 ah->config.spurchans[i][1] = AR_NO_SPUR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700381 }
382
Luis R. Rodriguez5ffaf8a2010-02-02 11:58:33 -0500383 if (ah->hw_version.devid != AR2427_DEVID_PCIE)
384 ah->config.ht_enable = 1;
385 else
386 ah->config.ht_enable = 0;
387
Sujith0ce024c2009-12-14 14:57:00 +0530388 ah->config.rx_intr_mitigation = true;
Luis R. Rodriguez61584252009-03-12 18:18:49 -0400389
390 /*
391 * We need this for PCI devices only (Cardbus, PCI, miniPCI)
392 * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
393 * This means we use it for all AR5416 devices, and the few
394 * minor PCI AR9280 devices out there.
395 *
396 * Serialization is required because these devices do not handle
397 * well the case of two concurrent reads/writes due to the latency
398 * involved. During one read/write another read/write can be issued
399 * on another CPU while the previous read/write may still be working
400 * on our hardware, if we hit this case the hardware poops in a loop.
401 * We prevent this by serializing reads and writes.
402 *
403 * This issue is not present on PCI-Express devices or pre-AR5416
404 * devices (legacy, 802.11abg).
405 */
406 if (num_possible_cpus() > 1)
David S. Miller2d6a5e92009-03-17 15:01:30 -0700407 ah->config.serialize_regmode = SER_REG_MODE_AUTO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700408}
409
Luis R. Rodriguez50aca252009-08-03 12:24:42 -0700410static void ath9k_hw_init_defaults(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700411{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700412 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
413
414 regulatory->country_code = CTRY_DEFAULT;
415 regulatory->power_limit = MAX_RATE_POWER;
416 regulatory->tp_scale = ATH9K_TP_SCALE_MAX;
417
Sujithd535a422009-02-09 13:27:06 +0530418 ah->hw_version.magic = AR5416_MAGIC;
Sujithd535a422009-02-09 13:27:06 +0530419 ah->hw_version.subvendorid = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700420
421 ah->ah_flags = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700422 if (!AR_SREV_9100(ah))
423 ah->ah_flags = AH_USE_EEPROM;
424
Sujith2660b812009-02-09 13:27:26 +0530425 ah->atim_window = 0;
Sujith2660b812009-02-09 13:27:26 +0530426 ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
427 ah->beacon_interval = 100;
428 ah->enable_32kHz_clock = DONT_USE_32KHZ;
429 ah->slottime = (u32) -1;
Sujith2660b812009-02-09 13:27:26 +0530430 ah->globaltxtimeout = (u32) -1;
Gabor Juhoscbdec972009-07-24 17:27:22 +0200431 ah->power_mode = ATH9K_PM_UNDEFINED;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700432}
433
Sujithcbe61d82009-02-09 13:27:12 +0530434static int ath9k_hw_rf_claim(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700435{
436 u32 val;
437
438 REG_WRITE(ah, AR_PHY(0), 0x00000007);
439
440 val = ath9k_hw_get_radiorev(ah);
441 switch (val & AR_RADIO_SREV_MAJOR) {
442 case 0:
443 val = AR_RAD5133_SREV_MAJOR;
444 break;
445 case AR_RAD5133_SREV_MAJOR:
446 case AR_RAD5122_SREV_MAJOR:
447 case AR_RAD2133_SREV_MAJOR:
448 case AR_RAD2122_SREV_MAJOR:
449 break;
450 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700451 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
452 "Radio Chip Rev 0x%02X not supported\n",
453 val & AR_RADIO_SREV_MAJOR);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700454 return -EOPNOTSUPP;
455 }
456
Sujithd535a422009-02-09 13:27:06 +0530457 ah->hw_version.analog5GhzRev = val;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700458
459 return 0;
460}
461
Sujithcbe61d82009-02-09 13:27:12 +0530462static int ath9k_hw_init_macaddr(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700463{
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700464 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530465 u32 sum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700466 int i;
Sujithf1dc5602008-10-29 10:16:30 +0530467 u16 eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700468
Sujithf1dc5602008-10-29 10:16:30 +0530469 sum = 0;
470 for (i = 0; i < 3; i++) {
Sujithf74df6f2009-02-09 13:27:24 +0530471 eeval = ah->eep_ops->get_eeprom(ah, AR_EEPROM_MAC(i));
Sujithf1dc5602008-10-29 10:16:30 +0530472 sum += eeval;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700473 common->macaddr[2 * i] = eeval >> 8;
474 common->macaddr[2 * i + 1] = eeval & 0xff;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700475 }
Sujithd8baa932009-03-30 15:28:25 +0530476 if (sum == 0 || sum == 0xffff * 3)
Sujithf1dc5602008-10-29 10:16:30 +0530477 return -EADDRNOTAVAIL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700478
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700479 return 0;
480}
481
Sujithcbe61d82009-02-09 13:27:12 +0530482static void ath9k_hw_init_rxgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530483{
484 u32 rxgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530485
Sujithf74df6f2009-02-09 13:27:24 +0530486 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_17) {
487 rxgain_type = ah->eep_ops->get_eeprom(ah, EEP_RXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530488
489 if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530490 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530491 ar9280Modes_backoff_13db_rxgain_9280_2,
492 ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2), 6);
493 else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530494 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530495 ar9280Modes_backoff_23db_rxgain_9280_2,
496 ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 6);
497 else
Sujith2660b812009-02-09 13:27:26 +0530498 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530499 ar9280Modes_original_rxgain_9280_2,
500 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530501 } else {
Sujith2660b812009-02-09 13:27:26 +0530502 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530503 ar9280Modes_original_rxgain_9280_2,
504 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530505 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530506}
507
Sujithcbe61d82009-02-09 13:27:12 +0530508static void ath9k_hw_init_txgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530509{
510 u32 txgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530511
Sujithf74df6f2009-02-09 13:27:24 +0530512 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_19) {
513 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530514
515 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
Sujith2660b812009-02-09 13:27:26 +0530516 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530517 ar9280Modes_high_power_tx_gain_9280_2,
518 ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 6);
519 else
Sujith2660b812009-02-09 13:27:26 +0530520 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530521 ar9280Modes_original_tx_gain_9280_2,
522 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530523 } else {
Sujith2660b812009-02-09 13:27:26 +0530524 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530525 ar9280Modes_original_tx_gain_9280_2,
526 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530527 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530528}
529
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700530static int ath9k_hw_post_init(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700531{
532 int ecode;
533
Sujith527d4852010-03-17 14:25:16 +0530534 if (!AR_SREV_9271(ah)) {
535 if (!ath9k_hw_chip_test(ah))
536 return -ENODEV;
537 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700538
539 ecode = ath9k_hw_rf_claim(ah);
540 if (ecode != 0)
541 return ecode;
542
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700543 ecode = ath9k_hw_eeprom_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700544 if (ecode != 0)
545 return ecode;
Sujith7d01b222009-03-13 08:55:55 +0530546
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700547 ath_print(ath9k_hw_common(ah), ATH_DBG_CONFIG,
548 "Eeprom VER: %d, REV: %d\n",
549 ah->eep_ops->get_eeprom_ver(ah),
550 ah->eep_ops->get_eeprom_rev(ah));
Sujith7d01b222009-03-13 08:55:55 +0530551
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400552 ecode = ath9k_hw_rf_alloc_ext_banks(ah);
553 if (ecode) {
554 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
555 "Failed allocating banks for "
556 "external radio\n");
557 return ecode;
Luis R. Rodriguez574d6b12009-10-19 02:33:37 -0400558 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700559
560 if (!AR_SREV_9100(ah)) {
561 ath9k_hw_ani_setup(ah);
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700562 ath9k_hw_ani_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700563 }
Sujithf1dc5602008-10-29 10:16:30 +0530564
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700565 return 0;
566}
567
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700568static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
569{
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530570 if (AR_SREV_9287_11_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530571 INIT_INI_ARRAY(&ah->iniModesRxGain,
572 ar9287Modes_rx_gain_9287_1_1,
573 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_1), 6);
574 else if (AR_SREV_9287_10(ah))
575 INIT_INI_ARRAY(&ah->iniModesRxGain,
576 ar9287Modes_rx_gain_9287_1_0,
577 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_0), 6);
578 else if (AR_SREV_9280_20(ah))
579 ath9k_hw_init_rxgain_ini(ah);
580
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530581 if (AR_SREV_9287_11_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530582 INIT_INI_ARRAY(&ah->iniModesTxGain,
583 ar9287Modes_tx_gain_9287_1_1,
584 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_1), 6);
585 } else if (AR_SREV_9287_10(ah)) {
586 INIT_INI_ARRAY(&ah->iniModesTxGain,
587 ar9287Modes_tx_gain_9287_1_0,
588 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_0), 6);
589 } else if (AR_SREV_9280_20(ah)) {
590 ath9k_hw_init_txgain_ini(ah);
591 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530592 u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
593
594 /* txgain table */
595 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) {
Vivek Natarajan53bc7aa2010-04-05 14:48:04 +0530596 if (AR_SREV_9285E_20(ah)) {
597 INIT_INI_ARRAY(&ah->iniModesTxGain,
598 ar9285Modes_XE2_0_high_power,
599 ARRAY_SIZE(
600 ar9285Modes_XE2_0_high_power), 6);
601 } else {
602 INIT_INI_ARRAY(&ah->iniModesTxGain,
603 ar9285Modes_high_power_tx_gain_9285_1_2,
604 ARRAY_SIZE(
605 ar9285Modes_high_power_tx_gain_9285_1_2), 6);
606 }
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530607 } else {
Vivek Natarajan53bc7aa2010-04-05 14:48:04 +0530608 if (AR_SREV_9285E_20(ah)) {
609 INIT_INI_ARRAY(&ah->iniModesTxGain,
610 ar9285Modes_XE2_0_normal_power,
611 ARRAY_SIZE(
612 ar9285Modes_XE2_0_normal_power), 6);
613 } else {
614 INIT_INI_ARRAY(&ah->iniModesTxGain,
615 ar9285Modes_original_tx_gain_9285_1_2,
616 ARRAY_SIZE(
617 ar9285Modes_original_tx_gain_9285_1_2), 6);
618 }
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530619 }
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530620 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700621}
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530622
Felix Fietkauaa8bc9e2010-01-23 20:04:18 +0100623static void ath9k_hw_init_eeprom_fix(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700624{
Pavel Roskin2eb46d92010-04-07 01:33:33 -0400625 struct base_eep_header *pBase = &(ah->eeprom.def.baseEepHeader);
626 struct ath_common *common = ath9k_hw_common(ah);
Sujith06d0f062009-02-12 10:06:45 +0530627
Pavel Roskin2eb46d92010-04-07 01:33:33 -0400628 ah->need_an_top2_fixup = (ah->hw_version.devid == AR9280_DEVID_PCI) &&
Senthil Balasubramanian939ad862010-04-15 17:38:50 -0400629 !AR_SREV_9285(ah) && !AR_SREV_9271(ah) &&
Pavel Roskin2eb46d92010-04-07 01:33:33 -0400630 ((pBase->version & 0xff) > 0x0a) &&
631 (pBase->pwdclkind == 0);
Sujith06d0f062009-02-12 10:06:45 +0530632
Pavel Roskin2eb46d92010-04-07 01:33:33 -0400633 if (ah->need_an_top2_fixup)
634 ath_print(common, ATH_DBG_EEPROM,
635 "needs fixup for AR_AN_TOP2 register\n");
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700636}
637
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400638static void ath9k_hw_attach_ops(struct ath_hw *ah)
639{
640 if (AR_SREV_9300_20_OR_LATER(ah))
641 ar9003_hw_attach_ops(ah);
642 else
643 ar9002_hw_attach_ops(ah);
644}
645
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400646/* Called for all hardware families */
647static int __ath9k_hw_init(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700648{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700649 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700650 int r = 0;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700651
Luis R. Rodriguezbab1f622010-04-15 17:38:20 -0400652 if (ah->hw_version.devid == AR5416_AR9100_DEVID)
653 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700654
655 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700656 ath_print(common, ATH_DBG_FATAL,
657 "Couldn't reset chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700658 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700659 }
660
Luis R. Rodriguezbab1f622010-04-15 17:38:20 -0400661 ath9k_hw_init_defaults(ah);
662 ath9k_hw_init_config(ah);
663
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400664 ath9k_hw_attach_ops(ah);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400665
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700666 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700667 ath_print(common, ATH_DBG_FATAL, "Couldn't wakeup chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700668 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700669 }
670
671 if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
672 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
673 (AR_SREV_9280(ah) && !ah->is_pciexpress)) {
674 ah->config.serialize_regmode =
675 SER_REG_MODE_ON;
676 } else {
677 ah->config.serialize_regmode =
678 SER_REG_MODE_OFF;
679 }
680 }
681
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700682 ath_print(common, ATH_DBG_RESET, "serialize_regmode is %d\n",
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700683 ah->config.serialize_regmode);
684
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -0500685 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
686 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD >> 1;
687 else
688 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD;
689
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400690 if (!ath9k_hw_macversion_supported(ah)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700691 ath_print(common, ATH_DBG_FATAL,
692 "Mac Chip Rev 0x%02x.%x is not supported by "
693 "this driver\n", ah->hw_version.macVersion,
694 ah->hw_version.macRev);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700695 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700696 }
697
Luis R. Rodriguez0df13da2010-04-15 17:38:59 -0400698 if (AR_SREV_9271(ah) || AR_SREV_9100(ah))
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400699 ah->is_pciexpress = false;
700
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700701 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700702 ath9k_hw_init_cal_settings(ah);
703
704 ah->ani_function = ATH9K_ANI_ALL;
Luis R. Rodriguez31a0bd32010-04-15 17:38:22 -0400705 if (AR_SREV_9280_10_OR_LATER(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700706 ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
707
708 ath9k_hw_init_mode_regs(ah);
709
710 if (ah->is_pciexpress)
Vivek Natarajan93b1b372009-09-17 09:24:58 +0530711 ath9k_hw_configpcipowersave(ah, 0, 0);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700712 else
713 ath9k_hw_disablepcie(ah);
714
Sujith193cd452009-09-18 15:04:07 +0530715 /* Support for Japan ch.14 (2484) spread */
716 if (AR_SREV_9287_11_OR_LATER(ah)) {
717 INIT_INI_ARRAY(&ah->iniCckfirNormal,
718 ar9287Common_normal_cck_fir_coeff_92871_1,
719 ARRAY_SIZE(ar9287Common_normal_cck_fir_coeff_92871_1), 2);
720 INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
721 ar9287Common_japan_2484_cck_fir_coeff_92871_1,
722 ARRAY_SIZE(ar9287Common_japan_2484_cck_fir_coeff_92871_1), 2);
723 }
724
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700725 r = ath9k_hw_post_init(ah);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700726 if (r)
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700727 return r;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700728
729 ath9k_hw_init_mode_gain_regs(ah);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +0100730 r = ath9k_hw_fill_cap_info(ah);
731 if (r)
732 return r;
733
Felix Fietkauaa8bc9e2010-01-23 20:04:18 +0100734 ath9k_hw_init_eeprom_fix(ah);
Sujithf6688cd2008-12-07 21:43:10 +0530735
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700736 r = ath9k_hw_init_macaddr(ah);
737 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700738 ath_print(common, ATH_DBG_FATAL,
739 "Failed to initialize MAC address\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700740 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700741 }
742
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400743 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
Sujith2660b812009-02-09 13:27:26 +0530744 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700745 else
Sujith2660b812009-02-09 13:27:26 +0530746 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700747
Felix Fietkau641d9922010-04-15 17:38:49 -0400748 if (AR_SREV_9300_20_OR_LATER(ah))
749 ar9003_hw_set_nf_limits(ah);
750
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700751 ath9k_init_nfcal_hist_buffer(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700752
Luis R. Rodriguez211f5852009-10-06 21:19:07 -0400753 common->state = ATH_HW_INITIALIZED;
754
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700755 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700756}
757
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400758int ath9k_hw_init(struct ath_hw *ah)
759{
760 int ret;
761 struct ath_common *common = ath9k_hw_common(ah);
762
763 /* These are all the AR5008/AR9001/AR9002 hardware family of chipsets */
764 switch (ah->hw_version.devid) {
765 case AR5416_DEVID_PCI:
766 case AR5416_DEVID_PCIE:
767 case AR5416_AR9100_DEVID:
768 case AR9160_DEVID_PCI:
769 case AR9280_DEVID_PCI:
770 case AR9280_DEVID_PCIE:
771 case AR9285_DEVID_PCIE:
Senthil Balasubramaniandb3cc532010-04-15 17:38:18 -0400772 case AR9287_DEVID_PCI:
773 case AR9287_DEVID_PCIE:
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400774 case AR2427_DEVID_PCIE:
Senthil Balasubramaniandb3cc532010-04-15 17:38:18 -0400775 case AR9300_DEVID_PCIE:
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400776 break;
777 default:
778 if (common->bus_ops->ath_bus_type == ATH_USB)
779 break;
780 ath_print(common, ATH_DBG_FATAL,
781 "Hardware device ID 0x%04x not supported\n",
782 ah->hw_version.devid);
783 return -EOPNOTSUPP;
784 }
785
786 ret = __ath9k_hw_init(ah);
787 if (ret) {
788 ath_print(common, ATH_DBG_FATAL,
789 "Unable to initialize hardware; "
790 "initialization status: %d\n", ret);
791 return ret;
792 }
793
794 return 0;
795}
796EXPORT_SYMBOL(ath9k_hw_init);
797
Sujithcbe61d82009-02-09 13:27:12 +0530798static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530799{
800 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
801 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
802
803 REG_WRITE(ah, AR_QOS_NO_ACK,
804 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
805 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
806 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
807
808 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
809 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
810 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
811 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
812 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
813}
814
Sujithcbe61d82009-02-09 13:27:12 +0530815static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530816 struct ath9k_channel *chan)
817{
Luis R. Rodriguez64773962010-04-15 17:38:17 -0400818 u32 pll = ath9k_hw_compute_pll_control(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +0530819
Gabor Juhosd03a66c2009-01-14 20:17:09 +0100820 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +0530821
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -0400822 /* Switch the core clock for ar9271 to 117Mhz */
823 if (AR_SREV_9271(ah)) {
Sujith25e2ab12010-03-17 14:25:22 +0530824 udelay(500);
825 REG_WRITE(ah, 0x50040, 0x304);
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -0400826 }
827
Sujithf1dc5602008-10-29 10:16:30 +0530828 udelay(RTC_PLL_SETTLE_DELAY);
829
830 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
831}
832
Sujithcbe61d82009-02-09 13:27:12 +0530833static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -0800834 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +0530835{
Pavel Roskin152d5302010-03-31 18:05:37 -0400836 u32 imr_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +0530837 AR_IMR_TXURN |
838 AR_IMR_RXERR |
839 AR_IMR_RXORN |
840 AR_IMR_BCNMISC;
841
Sujith0ce024c2009-12-14 14:57:00 +0530842 if (ah->config.rx_intr_mitigation)
Pavel Roskin152d5302010-03-31 18:05:37 -0400843 imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
Sujithf1dc5602008-10-29 10:16:30 +0530844 else
Pavel Roskin152d5302010-03-31 18:05:37 -0400845 imr_reg |= AR_IMR_RXOK;
Sujithf1dc5602008-10-29 10:16:30 +0530846
Pavel Roskin152d5302010-03-31 18:05:37 -0400847 imr_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +0530848
Colin McCabed97809d2008-12-01 13:38:55 -0800849 if (opmode == NL80211_IFTYPE_AP)
Pavel Roskin152d5302010-03-31 18:05:37 -0400850 imr_reg |= AR_IMR_MIB;
Sujithf1dc5602008-10-29 10:16:30 +0530851
Pavel Roskin152d5302010-03-31 18:05:37 -0400852 REG_WRITE(ah, AR_IMR, imr_reg);
Pavel Roskin74bad5c2010-02-23 18:15:27 -0500853 ah->imrs2_reg |= AR_IMR_S2_GTT;
854 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
Sujithf1dc5602008-10-29 10:16:30 +0530855
856 if (!AR_SREV_9100(ah)) {
857 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
858 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
859 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
860 }
861}
862
Felix Fietkau0005baf2010-01-15 02:33:40 +0100863static void ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +0530864{
Felix Fietkau0005baf2010-01-15 02:33:40 +0100865 u32 val = ath9k_hw_mac_to_clks(ah, us);
866 val = min(val, (u32) 0xFFFF);
867 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, val);
Sujithf1dc5602008-10-29 10:16:30 +0530868}
869
Felix Fietkau0005baf2010-01-15 02:33:40 +0100870static void ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +0530871{
Felix Fietkau0005baf2010-01-15 02:33:40 +0100872 u32 val = ath9k_hw_mac_to_clks(ah, us);
873 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_ACK));
874 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_ACK, val);
875}
876
877static void ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
878{
879 u32 val = ath9k_hw_mac_to_clks(ah, us);
880 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_CTS));
881 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_CTS, val);
Sujithf1dc5602008-10-29 10:16:30 +0530882}
883
Sujithcbe61d82009-02-09 13:27:12 +0530884static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +0530885{
Sujithf1dc5602008-10-29 10:16:30 +0530886 if (tu > 0xFFFF) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700887 ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT,
888 "bad global tx timeout %u\n", tu);
Sujith2660b812009-02-09 13:27:26 +0530889 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +0530890 return false;
891 } else {
892 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +0530893 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +0530894 return true;
895 }
896}
897
Felix Fietkau0005baf2010-01-15 02:33:40 +0100898void ath9k_hw_init_global_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530899{
Felix Fietkau0005baf2010-01-15 02:33:40 +0100900 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
901 int acktimeout;
Felix Fietkaue239d852010-01-15 02:34:58 +0100902 int slottime;
Felix Fietkau0005baf2010-01-15 02:33:40 +0100903 int sifstime;
904
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700905 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
906 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +0530907
Sujith2660b812009-02-09 13:27:26 +0530908 if (ah->misc_mode != 0)
Sujithf1dc5602008-10-29 10:16:30 +0530909 REG_WRITE(ah, AR_PCU_MISC,
Sujith2660b812009-02-09 13:27:26 +0530910 REG_READ(ah, AR_PCU_MISC) | ah->misc_mode);
Felix Fietkau0005baf2010-01-15 02:33:40 +0100911
912 if (conf->channel && conf->channel->band == IEEE80211_BAND_5GHZ)
913 sifstime = 16;
914 else
915 sifstime = 10;
916
Felix Fietkaue239d852010-01-15 02:34:58 +0100917 /* As defined by IEEE 802.11-2007 17.3.8.6 */
918 slottime = ah->slottime + 3 * ah->coverage_class;
919 acktimeout = slottime + sifstime;
Felix Fietkau42c45682010-02-11 18:07:19 +0100920
921 /*
922 * Workaround for early ACK timeouts, add an offset to match the
923 * initval's 64us ack timeout value.
924 * This was initially only meant to work around an issue with delayed
925 * BA frames in some implementations, but it has been found to fix ACK
926 * timeout issues in other cases as well.
927 */
928 if (conf->channel && conf->channel->band == IEEE80211_BAND_2GHZ)
929 acktimeout += 64 - sifstime - ah->slottime;
930
Felix Fietkaue239d852010-01-15 02:34:58 +0100931 ath9k_hw_setslottime(ah, slottime);
Felix Fietkau0005baf2010-01-15 02:33:40 +0100932 ath9k_hw_set_ack_timeout(ah, acktimeout);
933 ath9k_hw_set_cts_timeout(ah, acktimeout);
Sujith2660b812009-02-09 13:27:26 +0530934 if (ah->globaltxtimeout != (u32) -1)
935 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Sujithf1dc5602008-10-29 10:16:30 +0530936}
Felix Fietkau0005baf2010-01-15 02:33:40 +0100937EXPORT_SYMBOL(ath9k_hw_init_global_settings);
Sujithf1dc5602008-10-29 10:16:30 +0530938
Sujith285f2dd2010-01-08 10:36:07 +0530939void ath9k_hw_deinit(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700940{
Luis R. Rodriguez211f5852009-10-06 21:19:07 -0400941 struct ath_common *common = ath9k_hw_common(ah);
942
Sujith736b3a22010-03-17 14:25:24 +0530943 if (common->state < ATH_HW_INITIALIZED)
Luis R. Rodriguez211f5852009-10-06 21:19:07 -0400944 goto free_hw;
945
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700946 if (!AR_SREV_9100(ah))
Luis R. Rodrigueze70c0cf2009-08-03 12:24:51 -0700947 ath9k_hw_ani_disable(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700948
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700949 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Luis R. Rodriguez211f5852009-10-06 21:19:07 -0400950
951free_hw:
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400952 ath9k_hw_rf_free_ext_banks(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700953}
Sujith285f2dd2010-01-08 10:36:07 +0530954EXPORT_SYMBOL(ath9k_hw_deinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700955
Sujithf1dc5602008-10-29 10:16:30 +0530956/*******/
957/* INI */
958/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700959
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400960u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan)
Bob Copeland3a702e42009-03-30 22:30:29 -0400961{
962 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
963
964 if (IS_CHAN_B(chan))
965 ctl |= CTL_11B;
966 else if (IS_CHAN_G(chan))
967 ctl |= CTL_11G;
968 else
969 ctl |= CTL_11A;
970
971 return ctl;
972}
973
Sujithf1dc5602008-10-29 10:16:30 +0530974/****************************************/
975/* Reset and Channel Switching Routines */
976/****************************************/
977
Sujithcbe61d82009-02-09 13:27:12 +0530978static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530979{
980 u32 regval;
981
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400982 /*
983 * set AHB_MODE not to do cacheline prefetches
984 */
Sujithf1dc5602008-10-29 10:16:30 +0530985 regval = REG_READ(ah, AR_AHB_MODE);
986 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
987
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400988 /*
989 * let mac dma reads be in 128 byte chunks
990 */
Sujithf1dc5602008-10-29 10:16:30 +0530991 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
992 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
993
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400994 /*
995 * Restore TX Trigger Level to its pre-reset value.
996 * The initial value depends on whether aggregation is enabled, and is
997 * adjusted whenever underruns are detected.
998 */
Sujith2660b812009-02-09 13:27:26 +0530999 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +05301000
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001001 /*
1002 * let mac dma writes be in 128 byte chunks
1003 */
Sujithf1dc5602008-10-29 10:16:30 +05301004 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
1005 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
1006
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001007 /*
1008 * Setup receive FIFO threshold to hold off TX activities
1009 */
Sujithf1dc5602008-10-29 10:16:30 +05301010 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1011
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001012 /*
1013 * reduce the number of usable entries in PCU TXBUF to avoid
1014 * wrap around issues.
1015 */
Sujithf1dc5602008-10-29 10:16:30 +05301016 if (AR_SREV_9285(ah)) {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001017 /* For AR9285 the number of Fifos are reduced to half.
1018 * So set the usable tx buf size also to half to
1019 * avoid data/delimiter underruns
1020 */
Sujithf1dc5602008-10-29 10:16:30 +05301021 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1022 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001023 } else if (!AR_SREV_9271(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +05301024 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1025 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1026 }
1027}
1028
Sujithcbe61d82009-02-09 13:27:12 +05301029static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301030{
1031 u32 val;
1032
1033 val = REG_READ(ah, AR_STA_ID1);
1034 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
1035 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001036 case NL80211_IFTYPE_AP:
Sujithf1dc5602008-10-29 10:16:30 +05301037 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
1038 | AR_STA_ID1_KSRCH_MODE);
1039 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1040 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001041 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04001042 case NL80211_IFTYPE_MESH_POINT:
Sujithf1dc5602008-10-29 10:16:30 +05301043 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
1044 | AR_STA_ID1_KSRCH_MODE);
1045 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1046 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001047 case NL80211_IFTYPE_STATION:
1048 case NL80211_IFTYPE_MONITOR:
Sujithf1dc5602008-10-29 10:16:30 +05301049 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
1050 break;
1051 }
1052}
1053
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001054void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled,
1055 u32 *coef_mantissa, u32 *coef_exponent)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001056{
1057 u32 coef_exp, coef_man;
1058
1059 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1060 if ((coef_scaled >> coef_exp) & 0x1)
1061 break;
1062
1063 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1064
1065 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1066
1067 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1068 *coef_exponent = coef_exp - 16;
1069}
1070
Sujithcbe61d82009-02-09 13:27:12 +05301071static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +05301072{
1073 u32 rst_flags;
1074 u32 tmpReg;
1075
Sujith70768492009-02-16 13:23:12 +05301076 if (AR_SREV_9100(ah)) {
1077 u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK);
1078 val &= ~AR_RTC_DERIVED_CLK_PERIOD;
1079 val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD);
1080 REG_WRITE(ah, AR_RTC_DERIVED_CLK, val);
1081 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1082 }
1083
Sujithf1dc5602008-10-29 10:16:30 +05301084 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1085 AR_RTC_FORCE_WAKE_ON_INT);
1086
1087 if (AR_SREV_9100(ah)) {
1088 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1089 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1090 } else {
1091 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1092 if (tmpReg &
1093 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1094 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001095 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05301096 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001097
1098 val = AR_RC_HOSTIF;
1099 if (!AR_SREV_9300_20_OR_LATER(ah))
1100 val |= AR_RC_AHB;
1101 REG_WRITE(ah, AR_RC, val);
1102
1103 } else if (!AR_SREV_9300_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05301104 REG_WRITE(ah, AR_RC, AR_RC_AHB);
Sujithf1dc5602008-10-29 10:16:30 +05301105
1106 rst_flags = AR_RTC_RC_MAC_WARM;
1107 if (type == ATH9K_RESET_COLD)
1108 rst_flags |= AR_RTC_RC_MAC_COLD;
1109 }
1110
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001111 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujithf1dc5602008-10-29 10:16:30 +05301112 udelay(50);
1113
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001114 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301115 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001116 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1117 "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301118 return false;
1119 }
1120
1121 if (!AR_SREV_9100(ah))
1122 REG_WRITE(ah, AR_RC, 0);
1123
Sujithf1dc5602008-10-29 10:16:30 +05301124 if (AR_SREV_9100(ah))
1125 udelay(50);
1126
1127 return true;
1128}
1129
Sujithcbe61d82009-02-09 13:27:12 +05301130static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301131{
1132 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1133 AR_RTC_FORCE_WAKE_ON_INT);
1134
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001135 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301136 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1137
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001138 REG_WRITE(ah, AR_RTC_RESET, 0);
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301139
Senthil Balasubramanian84e21692010-04-15 17:38:30 -04001140 if (!AR_SREV_9300_20_OR_LATER(ah))
1141 udelay(2);
1142
1143 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301144 REG_WRITE(ah, AR_RC, 0);
1145
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001146 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301147
1148 if (!ath9k_hw_wait(ah,
1149 AR_RTC_STATUS,
1150 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301151 AR_RTC_STATUS_ON,
1152 AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001153 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1154 "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301155 return false;
1156 }
1157
1158 ath9k_hw_read_revisions(ah);
1159
1160 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1161}
1162
Sujithcbe61d82009-02-09 13:27:12 +05301163static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301164{
1165 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1166 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1167
1168 switch (type) {
1169 case ATH9K_RESET_POWER_ON:
1170 return ath9k_hw_set_reset_power_on(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301171 case ATH9K_RESET_WARM:
1172 case ATH9K_RESET_COLD:
1173 return ath9k_hw_set_reset(ah, type);
Sujithf1dc5602008-10-29 10:16:30 +05301174 default:
1175 return false;
1176 }
1177}
1178
Sujithcbe61d82009-02-09 13:27:12 +05301179static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301180 struct ath9k_channel *chan)
1181{
Vivek Natarajan42abfbe2009-09-17 09:27:59 +05301182 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) {
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301183 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
1184 return false;
1185 } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
Sujithf1dc5602008-10-29 10:16:30 +05301186 return false;
1187
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001188 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05301189 return false;
1190
Sujith2660b812009-02-09 13:27:26 +05301191 ah->chip_fullsleep = false;
Sujithf1dc5602008-10-29 10:16:30 +05301192 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301193 ath9k_hw_set_rfmode(ah, chan);
1194
1195 return true;
1196}
1197
Sujithcbe61d82009-02-09 13:27:12 +05301198static bool ath9k_hw_channel_change(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001199 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301200{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001201 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001202 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001203 struct ieee80211_channel *channel = chan->chan;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001204 u32 qnum;
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001205 int r;
Sujithf1dc5602008-10-29 10:16:30 +05301206
1207 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1208 if (ath9k_hw_numtxpending(ah, qnum)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001209 ath_print(common, ATH_DBG_QUEUE,
1210 "Transmit frames pending on "
1211 "queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301212 return false;
1213 }
1214 }
1215
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001216 if (!ath9k_hw_rfbus_req(ah)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001217 ath_print(common, ATH_DBG_FATAL,
1218 "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301219 return false;
1220 }
1221
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001222 ath9k_hw_set_channel_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301223
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001224 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001225 if (r) {
1226 ath_print(common, ATH_DBG_FATAL,
1227 "Failed to set channel\n");
1228 return false;
Sujithf1dc5602008-10-29 10:16:30 +05301229 }
1230
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001231 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001232 ath9k_regd_get_ctl(regulatory, chan),
Sujithf74df6f2009-02-09 13:27:24 +05301233 channel->max_antenna_gain * 2,
1234 channel->max_power * 2,
1235 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001236 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05301237
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001238 ath9k_hw_rfbus_done(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301239
1240 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1241 ath9k_hw_set_delta_slope(ah, chan);
1242
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001243 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301244
1245 if (!chan->oneTimeCalsDone)
1246 chan->oneTimeCalsDone = true;
1247
1248 return true;
1249}
1250
Sujithcbe61d82009-02-09 13:27:12 +05301251int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001252 bool bChannelChange)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001253{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001254 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001255 u32 saveLedState;
Sujith2660b812009-02-09 13:27:26 +05301256 struct ath9k_channel *curchan = ah->curchan;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001257 u32 saveDefAntenna;
1258 u32 macStaId1;
Sujith46fe7822009-09-17 09:25:25 +05301259 u64 tsf = 0;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001260 int i, r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001261
Luis R. Rodriguez43c27612009-09-13 21:07:07 -07001262 ah->txchainmask = common->tx_chainmask;
1263 ah->rxchainmask = common->rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001264
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001265 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001266 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001267
Vasanthakumar Thiagarajan9ebef792009-09-17 09:26:44 +05301268 if (curchan && !ah->chip_fullsleep)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001269 ath9k_hw_getnf(ah, curchan);
1270
1271 if (bChannelChange &&
Sujith2660b812009-02-09 13:27:26 +05301272 (ah->chip_fullsleep != true) &&
1273 (ah->curchan != NULL) &&
1274 (chan->channel != ah->curchan->channel) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001275 ((chan->channelFlags & CHANNEL_ALL) ==
Sujith2660b812009-02-09 13:27:26 +05301276 (ah->curchan->channelFlags & CHANNEL_ALL)) &&
Vasanthakumar Thiagarajan0a475cc2009-09-17 09:27:10 +05301277 !(AR_SREV_9280(ah) || IS_CHAN_A_5MHZ_SPACED(chan) ||
1278 IS_CHAN_A_5MHZ_SPACED(ah->curchan))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001279
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001280 if (ath9k_hw_channel_change(ah, chan)) {
Sujith2660b812009-02-09 13:27:26 +05301281 ath9k_hw_loadnf(ah, ah->curchan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001282 ath9k_hw_start_nfcal(ah);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001283 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001284 }
1285 }
1286
1287 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
1288 if (saveDefAntenna == 0)
1289 saveDefAntenna = 1;
1290
1291 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
1292
Sujith46fe7822009-09-17 09:25:25 +05301293 /* For chips on which RTC reset is done, save TSF before it gets cleared */
1294 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1295 tsf = ath9k_hw_gettsf64(ah);
1296
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001297 saveLedState = REG_READ(ah, AR_CFG_LED) &
1298 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
1299 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
1300
1301 ath9k_hw_mark_phy_inactive(ah);
1302
Sujith05020d22010-03-17 14:25:23 +05301303 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001304 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1305 REG_WRITE(ah,
1306 AR9271_RESET_POWER_DOWN_CONTROL,
1307 AR9271_RADIO_RF_RST);
1308 udelay(50);
1309 }
1310
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001311 if (!ath9k_hw_chip_reset(ah, chan)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001312 ath_print(common, ATH_DBG_FATAL, "Chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001313 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001314 }
1315
Sujith05020d22010-03-17 14:25:23 +05301316 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001317 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1318 ah->htc_reset_init = false;
1319 REG_WRITE(ah,
1320 AR9271_RESET_POWER_DOWN_CONTROL,
1321 AR9271_GATE_MAC_CTL);
1322 udelay(50);
1323 }
1324
Sujith46fe7822009-09-17 09:25:25 +05301325 /* Restore TSF */
1326 if (tsf && AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1327 ath9k_hw_settsf64(ah, tsf);
1328
Vasanthakumar Thiagarajan369391d2009-01-21 19:24:13 +05301329 if (AR_SREV_9280_10_OR_LATER(ah))
1330 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001331
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001332 r = ath9k_hw_process_ini(ah, chan);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001333 if (r)
1334 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001335
Jouni Malinen0ced0e12009-01-08 13:32:13 +02001336 /* Setup MFP options for CCMP */
1337 if (AR_SREV_9280_20_OR_LATER(ah)) {
1338 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
1339 * frames when constructing CCMP AAD. */
1340 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
1341 0xc7ff);
1342 ah->sw_mgmt_crypto = false;
1343 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1344 /* Disable hardware crypto for management frames */
1345 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
1346 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
1347 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1348 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
1349 ah->sw_mgmt_crypto = true;
1350 } else
1351 ah->sw_mgmt_crypto = true;
1352
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001353 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1354 ath9k_hw_set_delta_slope(ah, chan);
1355
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001356 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithd6509152009-03-13 08:56:05 +05301357 ah->eep_ops->set_board_values(ah, chan);
Luis R. Rodrigueza7765822009-10-19 02:33:45 -04001358
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001359 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
1360 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001361 | macStaId1
1362 | AR_STA_ID1_RTS_USE_DEF
Sujith2660b812009-02-09 13:27:26 +05301363 | (ah->config.
Sujith60b67f52008-08-07 10:52:38 +05301364 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Sujith2660b812009-02-09 13:27:26 +05301365 | ah->sta_id1_defaults);
1366 ath9k_hw_set_operating_mode(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001367
Luis R. Rodriguez13b81552009-09-10 17:52:45 -07001368 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001369
1370 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
1371
Luis R. Rodriguez3453ad82009-09-10 08:57:00 -07001372 ath9k_hw_write_associd(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001373
1374 REG_WRITE(ah, AR_ISR, ~0);
1375
1376 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
1377
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001378 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001379 if (r)
1380 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001381
1382 for (i = 0; i < AR_NUM_DCU; i++)
1383 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
1384
Sujith2660b812009-02-09 13:27:26 +05301385 ah->intr_txqs = 0;
1386 for (i = 0; i < ah->caps.total_queues; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001387 ath9k_hw_resettxqueue(ah, i);
1388
Sujith2660b812009-02-09 13:27:26 +05301389 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001390 ath9k_hw_init_qos(ah);
1391
Sujith2660b812009-02-09 13:27:26 +05301392 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301393 ath9k_enable_rfkill(ah);
Johannes Berg3b319aa2009-06-13 14:50:26 +05301394
Felix Fietkau0005baf2010-01-15 02:33:40 +01001395 ath9k_hw_init_global_settings(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001396
Vivek Natarajan326bebb2009-08-14 11:33:36 +05301397 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301398 REG_WRITE(ah, AR_D_GBL_IFS_SIFS,
1399 AR_D_GBL_IFS_SIFS_ASYNC_FIFO_DUR);
1400 REG_WRITE(ah, AR_D_GBL_IFS_SLOT,
1401 AR_D_GBL_IFS_SLOT_ASYNC_FIFO_DUR);
1402 REG_WRITE(ah, AR_D_GBL_IFS_EIFS,
1403 AR_D_GBL_IFS_EIFS_ASYNC_FIFO_DUR);
1404
1405 REG_WRITE(ah, AR_TIME_OUT, AR_TIME_OUT_ACK_CTS_ASYNC_FIFO_DUR);
1406 REG_WRITE(ah, AR_USEC, AR_USEC_ASYNC_FIFO_DUR);
1407
1408 REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
1409 AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
1410 REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
1411 AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
1412 }
Vivek Natarajan326bebb2009-08-14 11:33:36 +05301413 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301414 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1415 AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
1416 }
1417
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001418 REG_WRITE(ah, AR_STA_ID1,
1419 REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
1420
1421 ath9k_hw_set_dma(ah);
1422
1423 REG_WRITE(ah, AR_OBS, 8);
1424
Sujith0ce024c2009-12-14 14:57:00 +05301425 if (ah->config.rx_intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001426 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
1427 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
1428 }
1429
1430 ath9k_hw_init_bb(ah, chan);
1431
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001432 if (!ath9k_hw_init_cal(ah, chan))
Joe Perches6badaaf2009-06-28 09:26:32 -07001433 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001434
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001435 ath9k_hw_restore_chainmask(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001436 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
1437
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001438 /*
1439 * For big endian systems turn on swapping for descriptors
1440 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001441 if (AR_SREV_9100(ah)) {
1442 u32 mask;
1443 mask = REG_READ(ah, AR_CFG);
1444 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001445 ath_print(common, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05301446 "CFG Byte Swap Set 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001447 } else {
1448 mask =
1449 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
1450 REG_WRITE(ah, AR_CFG, mask);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001451 ath_print(common, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05301452 "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001453 }
1454 } else {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001455 /* Configure AR9271 target WLAN */
1456 if (AR_SREV_9271(ah))
1457 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001458#ifdef __BIG_ENDIAN
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001459 else
1460 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001461#endif
1462 }
1463
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001464 if (ah->btcoex_hw.enabled)
Vasanthakumar Thiagarajan42cc41e2009-08-26 21:08:45 +05301465 ath9k_hw_btcoex_enable(ah);
1466
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001467 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001468}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001469EXPORT_SYMBOL(ath9k_hw_reset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001470
Sujithf1dc5602008-10-29 10:16:30 +05301471/************************/
1472/* Key Cache Management */
1473/************************/
1474
Sujithcbe61d82009-02-09 13:27:12 +05301475bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001476{
Sujithf1dc5602008-10-29 10:16:30 +05301477 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001478
Sujith2660b812009-02-09 13:27:26 +05301479 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001480 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1481 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001482 return false;
1483 }
1484
Sujithf1dc5602008-10-29 10:16:30 +05301485 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001486
Sujithf1dc5602008-10-29 10:16:30 +05301487 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
1488 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
1489 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
1490 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
1491 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
1492 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
1493 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
1494 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
1495
1496 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
1497 u16 micentry = entry + 64;
1498
1499 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
1500 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
1501 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
1502 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
1503
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001504 }
1505
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001506 return true;
1507}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001508EXPORT_SYMBOL(ath9k_hw_keyreset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001509
Sujithcbe61d82009-02-09 13:27:12 +05301510bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001511{
Sujithf1dc5602008-10-29 10:16:30 +05301512 u32 macHi, macLo;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001513
Sujith2660b812009-02-09 13:27:26 +05301514 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001515 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1516 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001517 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001518 }
1519
Sujithf1dc5602008-10-29 10:16:30 +05301520 if (mac != NULL) {
1521 macHi = (mac[5] << 8) | mac[4];
1522 macLo = (mac[3] << 24) |
1523 (mac[2] << 16) |
1524 (mac[1] << 8) |
1525 mac[0];
1526 macLo >>= 1;
1527 macLo |= (macHi & 1) << 31;
1528 macHi >>= 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001529 } else {
Sujithf1dc5602008-10-29 10:16:30 +05301530 macLo = macHi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001531 }
Sujithf1dc5602008-10-29 10:16:30 +05301532 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
1533 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001534
1535 return true;
1536}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001537EXPORT_SYMBOL(ath9k_hw_keysetmac);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001538
Sujithcbe61d82009-02-09 13:27:12 +05301539bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
Sujithf1dc5602008-10-29 10:16:30 +05301540 const struct ath9k_keyval *k,
Jouni Malinene0caf9e2009-03-02 18:15:53 +02001541 const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001542{
Sujith2660b812009-02-09 13:27:26 +05301543 const struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001544 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301545 u32 key0, key1, key2, key3, key4;
1546 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001547
Sujithf1dc5602008-10-29 10:16:30 +05301548 if (entry >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001549 ath_print(common, ATH_DBG_FATAL,
1550 "keycache entry %u out of range\n", entry);
Sujithf1dc5602008-10-29 10:16:30 +05301551 return false;
1552 }
1553
1554 switch (k->kv_type) {
1555 case ATH9K_CIPHER_AES_OCB:
1556 keyType = AR_KEYTABLE_TYPE_AES;
1557 break;
1558 case ATH9K_CIPHER_AES_CCM:
1559 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001560 ath_print(common, ATH_DBG_ANY,
1561 "AES-CCM not supported by mac rev 0x%x\n",
1562 ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001563 return false;
1564 }
Sujithf1dc5602008-10-29 10:16:30 +05301565 keyType = AR_KEYTABLE_TYPE_CCM;
1566 break;
1567 case ATH9K_CIPHER_TKIP:
1568 keyType = AR_KEYTABLE_TYPE_TKIP;
1569 if (ATH9K_IS_MIC_ENABLED(ah)
1570 && entry + 64 >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001571 ath_print(common, ATH_DBG_ANY,
1572 "entry %u inappropriate for TKIP\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001573 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001574 }
Sujithf1dc5602008-10-29 10:16:30 +05301575 break;
1576 case ATH9K_CIPHER_WEP:
Zhu Yie31a16d2009-05-21 21:47:03 +08001577 if (k->kv_len < WLAN_KEY_LEN_WEP40) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001578 ath_print(common, ATH_DBG_ANY,
1579 "WEP key length %u too small\n", k->kv_len);
Sujithf1dc5602008-10-29 10:16:30 +05301580 return false;
1581 }
Zhu Yie31a16d2009-05-21 21:47:03 +08001582 if (k->kv_len <= WLAN_KEY_LEN_WEP40)
Sujithf1dc5602008-10-29 10:16:30 +05301583 keyType = AR_KEYTABLE_TYPE_40;
Zhu Yie31a16d2009-05-21 21:47:03 +08001584 else if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05301585 keyType = AR_KEYTABLE_TYPE_104;
1586 else
1587 keyType = AR_KEYTABLE_TYPE_128;
1588 break;
1589 case ATH9K_CIPHER_CLR:
1590 keyType = AR_KEYTABLE_TYPE_CLR;
1591 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001592 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001593 ath_print(common, ATH_DBG_FATAL,
1594 "cipher %u not supported\n", k->kv_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001595 return false;
1596 }
Sujithf1dc5602008-10-29 10:16:30 +05301597
Jouni Malinene0caf9e2009-03-02 18:15:53 +02001598 key0 = get_unaligned_le32(k->kv_val + 0);
1599 key1 = get_unaligned_le16(k->kv_val + 4);
1600 key2 = get_unaligned_le32(k->kv_val + 6);
1601 key3 = get_unaligned_le16(k->kv_val + 10);
1602 key4 = get_unaligned_le32(k->kv_val + 12);
Zhu Yie31a16d2009-05-21 21:47:03 +08001603 if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05301604 key4 &= 0xff;
1605
Jouni Malinen672903b2009-03-02 15:06:31 +02001606 /*
1607 * Note: Key cache registers access special memory area that requires
1608 * two 32-bit writes to actually update the values in the internal
1609 * memory. Consequently, the exact order and pairs used here must be
1610 * maintained.
1611 */
1612
Sujithf1dc5602008-10-29 10:16:30 +05301613 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
1614 u16 micentry = entry + 64;
1615
Jouni Malinen672903b2009-03-02 15:06:31 +02001616 /*
1617 * Write inverted key[47:0] first to avoid Michael MIC errors
1618 * on frames that could be sent or received at the same time.
1619 * The correct key will be written in the end once everything
1620 * else is ready.
1621 */
Sujithf1dc5602008-10-29 10:16:30 +05301622 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
1623 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02001624
1625 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05301626 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
1627 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02001628
1629 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05301630 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
1631 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
Jouni Malinen672903b2009-03-02 15:06:31 +02001632
1633 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05301634 (void) ath9k_hw_keysetmac(ah, entry, mac);
1635
Sujith2660b812009-02-09 13:27:26 +05301636 if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) {
Jouni Malinen672903b2009-03-02 15:06:31 +02001637 /*
1638 * TKIP uses two key cache entries:
1639 * Michael MIC TX/RX keys in the same key cache entry
1640 * (idx = main index + 64):
1641 * key0 [31:0] = RX key [31:0]
1642 * key1 [15:0] = TX key [31:16]
1643 * key1 [31:16] = reserved
1644 * key2 [31:0] = RX key [63:32]
1645 * key3 [15:0] = TX key [15:0]
1646 * key3 [31:16] = reserved
1647 * key4 [31:0] = TX key [63:32]
1648 */
Sujithf1dc5602008-10-29 10:16:30 +05301649 u32 mic0, mic1, mic2, mic3, mic4;
1650
1651 mic0 = get_unaligned_le32(k->kv_mic + 0);
1652 mic2 = get_unaligned_le32(k->kv_mic + 4);
1653 mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
1654 mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
1655 mic4 = get_unaligned_le32(k->kv_txmic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02001656
1657 /* Write RX[31:0] and TX[31:16] */
Sujithf1dc5602008-10-29 10:16:30 +05301658 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
1659 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
Jouni Malinen672903b2009-03-02 15:06:31 +02001660
1661 /* Write RX[63:32] and TX[15:0] */
Sujithf1dc5602008-10-29 10:16:30 +05301662 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
1663 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
Jouni Malinen672903b2009-03-02 15:06:31 +02001664
1665 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05301666 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
1667 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
1668 AR_KEYTABLE_TYPE_CLR);
1669
1670 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02001671 /*
1672 * TKIP uses four key cache entries (two for group
1673 * keys):
1674 * Michael MIC TX/RX keys are in different key cache
1675 * entries (idx = main index + 64 for TX and
1676 * main index + 32 + 96 for RX):
1677 * key0 [31:0] = TX/RX MIC key [31:0]
1678 * key1 [31:0] = reserved
1679 * key2 [31:0] = TX/RX MIC key [63:32]
1680 * key3 [31:0] = reserved
1681 * key4 [31:0] = reserved
1682 *
1683 * Upper layer code will call this function separately
1684 * for TX and RX keys when these registers offsets are
1685 * used.
1686 */
Sujithf1dc5602008-10-29 10:16:30 +05301687 u32 mic0, mic2;
1688
1689 mic0 = get_unaligned_le32(k->kv_mic + 0);
1690 mic2 = get_unaligned_le32(k->kv_mic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02001691
1692 /* Write MIC key[31:0] */
Sujithf1dc5602008-10-29 10:16:30 +05301693 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
1694 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02001695
1696 /* Write MIC key[63:32] */
Sujithf1dc5602008-10-29 10:16:30 +05301697 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
1698 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02001699
1700 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05301701 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
1702 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
1703 AR_KEYTABLE_TYPE_CLR);
1704 }
Jouni Malinen672903b2009-03-02 15:06:31 +02001705
1706 /* MAC address registers are reserved for the MIC entry */
Sujithf1dc5602008-10-29 10:16:30 +05301707 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
1708 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02001709
1710 /*
1711 * Write the correct (un-inverted) key[47:0] last to enable
1712 * TKIP now that all other registers are set with correct
1713 * values.
1714 */
Sujithf1dc5602008-10-29 10:16:30 +05301715 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
1716 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
1717 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02001718 /* Write key[47:0] */
Sujithf1dc5602008-10-29 10:16:30 +05301719 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
1720 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02001721
1722 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05301723 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
1724 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02001725
1726 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05301727 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
1728 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
1729
Jouni Malinen672903b2009-03-02 15:06:31 +02001730 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05301731 (void) ath9k_hw_keysetmac(ah, entry, mac);
1732 }
1733
Sujithf1dc5602008-10-29 10:16:30 +05301734 return true;
1735}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001736EXPORT_SYMBOL(ath9k_hw_set_keycache_entry);
Sujithf1dc5602008-10-29 10:16:30 +05301737
Sujithcbe61d82009-02-09 13:27:12 +05301738bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry)
Sujithf1dc5602008-10-29 10:16:30 +05301739{
Sujith2660b812009-02-09 13:27:26 +05301740 if (entry < ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05301741 u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
1742 if (val & AR_KEYTABLE_VALID)
1743 return true;
1744 }
1745 return false;
1746}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001747EXPORT_SYMBOL(ath9k_hw_keyisvalid);
Sujithf1dc5602008-10-29 10:16:30 +05301748
1749/******************************/
1750/* Power Management (Chipset) */
1751/******************************/
1752
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001753/*
1754 * Notify Power Mgt is disabled in self-generated frames.
1755 * If requested, force chip to sleep.
1756 */
Sujithcbe61d82009-02-09 13:27:12 +05301757static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05301758{
1759 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
1760 if (setChip) {
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001761 /*
1762 * Clear the RTC force wake bit to allow the
1763 * mac to go to sleep.
1764 */
Sujithf1dc5602008-10-29 10:16:30 +05301765 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
1766 AR_RTC_FORCE_WAKE_EN);
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001767 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05301768 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1769
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001770 /* Shutdown chip. Active low */
Sujith14b3af32010-03-17 14:25:18 +05301771 if (!AR_SREV_5416(ah) && !AR_SREV_9271(ah))
Sujith4921be82009-09-18 15:04:27 +05301772 REG_CLR_BIT(ah, (AR_RTC_RESET),
1773 AR_RTC_RESET_EN);
Sujithf1dc5602008-10-29 10:16:30 +05301774 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001775}
1776
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04001777/*
1778 * Notify Power Management is enabled in self-generating
1779 * frames. If request, set power mode of chip to
1780 * auto/normal. Duration in units of 128us (1/8 TU).
1781 */
Sujithcbe61d82009-02-09 13:27:12 +05301782static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001783{
Sujithf1dc5602008-10-29 10:16:30 +05301784 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
1785 if (setChip) {
Sujith2660b812009-02-09 13:27:26 +05301786 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001787
Sujithf1dc5602008-10-29 10:16:30 +05301788 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04001789 /* Set WakeOnInterrupt bit; clear ForceWake bit */
Sujithf1dc5602008-10-29 10:16:30 +05301790 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1791 AR_RTC_FORCE_WAKE_ON_INT);
1792 } else {
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04001793 /*
1794 * Clear the RTC force wake bit to allow the
1795 * mac to go to sleep.
1796 */
Sujithf1dc5602008-10-29 10:16:30 +05301797 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
1798 AR_RTC_FORCE_WAKE_EN);
1799 }
1800 }
1801}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001802
Sujithcbe61d82009-02-09 13:27:12 +05301803static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05301804{
1805 u32 val;
1806 int i;
1807
1808 if (setChip) {
1809 if ((REG_READ(ah, AR_RTC_STATUS) &
1810 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
1811 if (ath9k_hw_set_reset_reg(ah,
1812 ATH9K_RESET_POWER_ON) != true) {
1813 return false;
1814 }
Luis R. Rodrigueze0412282010-04-15 17:38:15 -04001815 if (!AR_SREV_9300_20_OR_LATER(ah))
1816 ath9k_hw_init_pll(ah, NULL);
Sujithf1dc5602008-10-29 10:16:30 +05301817 }
1818 if (AR_SREV_9100(ah))
1819 REG_SET_BIT(ah, AR_RTC_RESET,
1820 AR_RTC_RESET_EN);
1821
1822 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
1823 AR_RTC_FORCE_WAKE_EN);
1824 udelay(50);
1825
1826 for (i = POWER_UP_TIME / 50; i > 0; i--) {
1827 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
1828 if (val == AR_RTC_STATUS_ON)
1829 break;
1830 udelay(50);
1831 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
1832 AR_RTC_FORCE_WAKE_EN);
1833 }
1834 if (i == 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001835 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1836 "Failed to wakeup in %uus\n",
1837 POWER_UP_TIME / 20);
Sujithf1dc5602008-10-29 10:16:30 +05301838 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001839 }
1840 }
1841
Sujithf1dc5602008-10-29 10:16:30 +05301842 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
1843
1844 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001845}
1846
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001847bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05301848{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001849 struct ath_common *common = ath9k_hw_common(ah);
Sujithcbe61d82009-02-09 13:27:12 +05301850 int status = true, setChip = true;
Sujithf1dc5602008-10-29 10:16:30 +05301851 static const char *modes[] = {
1852 "AWAKE",
1853 "FULL-SLEEP",
1854 "NETWORK SLEEP",
1855 "UNDEFINED"
1856 };
Sujithf1dc5602008-10-29 10:16:30 +05301857
Gabor Juhoscbdec972009-07-24 17:27:22 +02001858 if (ah->power_mode == mode)
1859 return status;
1860
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001861 ath_print(common, ATH_DBG_RESET, "%s -> %s\n",
1862 modes[ah->power_mode], modes[mode]);
Sujithf1dc5602008-10-29 10:16:30 +05301863
1864 switch (mode) {
1865 case ATH9K_PM_AWAKE:
1866 status = ath9k_hw_set_power_awake(ah, setChip);
1867 break;
1868 case ATH9K_PM_FULL_SLEEP:
1869 ath9k_set_power_sleep(ah, setChip);
Sujith2660b812009-02-09 13:27:26 +05301870 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05301871 break;
1872 case ATH9K_PM_NETWORK_SLEEP:
1873 ath9k_set_power_network_sleep(ah, setChip);
1874 break;
1875 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001876 ath_print(common, ATH_DBG_FATAL,
1877 "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05301878 return false;
1879 }
Sujith2660b812009-02-09 13:27:26 +05301880 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05301881
1882 return status;
1883}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001884EXPORT_SYMBOL(ath9k_hw_setpower);
Sujithf1dc5602008-10-29 10:16:30 +05301885
Sujithf1dc5602008-10-29 10:16:30 +05301886/**********************/
1887/* Interrupt Handling */
1888/**********************/
1889
Sujithcbe61d82009-02-09 13:27:12 +05301890bool ath9k_hw_intrpend(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001891{
1892 u32 host_isr;
1893
1894 if (AR_SREV_9100(ah))
1895 return true;
1896
1897 host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
1898 if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
1899 return true;
1900
1901 host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1902 if ((host_isr & AR_INTR_SYNC_DEFAULT)
1903 && (host_isr != AR_INTR_SPURIOUS))
1904 return true;
1905
1906 return false;
1907}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001908EXPORT_SYMBOL(ath9k_hw_intrpend);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001909
Sujithcbe61d82009-02-09 13:27:12 +05301910bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001911{
1912 u32 isr = 0;
1913 u32 mask2 = 0;
Sujith2660b812009-02-09 13:27:26 +05301914 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001915 u32 sync_cause = 0;
1916 bool fatal_int = false;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001917 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001918
1919 if (!AR_SREV_9100(ah)) {
1920 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
1921 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
1922 == AR_RTC_STATUS_ON) {
1923 isr = REG_READ(ah, AR_ISR);
1924 }
1925 }
1926
Sujithf1dc5602008-10-29 10:16:30 +05301927 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
1928 AR_INTR_SYNC_DEFAULT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001929
1930 *masked = 0;
1931
1932 if (!isr && !sync_cause)
1933 return false;
1934 } else {
1935 *masked = 0;
1936 isr = REG_READ(ah, AR_ISR);
1937 }
1938
1939 if (isr) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001940 if (isr & AR_ISR_BCNMISC) {
1941 u32 isr2;
1942 isr2 = REG_READ(ah, AR_ISR_S2);
1943 if (isr2 & AR_ISR_S2_TIM)
1944 mask2 |= ATH9K_INT_TIM;
1945 if (isr2 & AR_ISR_S2_DTIM)
1946 mask2 |= ATH9K_INT_DTIM;
1947 if (isr2 & AR_ISR_S2_DTIMSYNC)
1948 mask2 |= ATH9K_INT_DTIMSYNC;
1949 if (isr2 & (AR_ISR_S2_CABEND))
1950 mask2 |= ATH9K_INT_CABEND;
1951 if (isr2 & AR_ISR_S2_GTT)
1952 mask2 |= ATH9K_INT_GTT;
1953 if (isr2 & AR_ISR_S2_CST)
1954 mask2 |= ATH9K_INT_CST;
Sujith4af9cf42009-02-12 10:06:47 +05301955 if (isr2 & AR_ISR_S2_TSFOOR)
1956 mask2 |= ATH9K_INT_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001957 }
1958
1959 isr = REG_READ(ah, AR_ISR_RAC);
1960 if (isr == 0xffffffff) {
1961 *masked = 0;
1962 return false;
1963 }
1964
1965 *masked = isr & ATH9K_INT_COMMON;
1966
Sujith0ce024c2009-12-14 14:57:00 +05301967 if (ah->config.rx_intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001968 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
1969 *masked |= ATH9K_INT_RX;
1970 }
1971
1972 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
1973 *masked |= ATH9K_INT_RX;
1974 if (isr &
1975 (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
1976 AR_ISR_TXEOL)) {
1977 u32 s0_s, s1_s;
1978
1979 *masked |= ATH9K_INT_TX;
1980
1981 s0_s = REG_READ(ah, AR_ISR_S0_S);
Sujith2660b812009-02-09 13:27:26 +05301982 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
1983 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001984
1985 s1_s = REG_READ(ah, AR_ISR_S1_S);
Sujith2660b812009-02-09 13:27:26 +05301986 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
1987 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001988 }
1989
1990 if (isr & AR_ISR_RXORN) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001991 ath_print(common, ATH_DBG_INTERRUPT,
1992 "receive FIFO overrun interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001993 }
1994
1995 if (!AR_SREV_9100(ah)) {
Sujith60b67f52008-08-07 10:52:38 +05301996 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001997 u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
1998 if (isr5 & AR_ISR_S5_TIM_TIMER)
1999 *masked |= ATH9K_INT_TIM_TIMER;
2000 }
2001 }
2002
2003 *masked |= mask2;
2004 }
Sujithf1dc5602008-10-29 10:16:30 +05302005
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002006 if (AR_SREV_9100(ah))
2007 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302008
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302009 if (isr & AR_ISR_GENTMR) {
2010 u32 s5_s;
2011
2012 s5_s = REG_READ(ah, AR_ISR_S5_S);
2013 if (isr & AR_ISR_GENTMR) {
2014 ah->intr_gen_timer_trigger =
2015 MS(s5_s, AR_ISR_S5_GENTIMER_TRIG);
2016
2017 ah->intr_gen_timer_thresh =
2018 MS(s5_s, AR_ISR_S5_GENTIMER_THRESH);
2019
2020 if (ah->intr_gen_timer_trigger)
2021 *masked |= ATH9K_INT_GENTIMER;
2022
2023 }
2024 }
2025
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002026 if (sync_cause) {
2027 fatal_int =
2028 (sync_cause &
2029 (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
2030 ? true : false;
2031
2032 if (fatal_int) {
2033 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002034 ath_print(common, ATH_DBG_ANY,
2035 "received PCI FATAL interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002036 }
2037 if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002038 ath_print(common, ATH_DBG_ANY,
2039 "received PCI PERR interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002040 }
Steven Luoa89bff92009-04-12 02:57:54 -07002041 *masked |= ATH9K_INT_FATAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002042 }
2043 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002044 ath_print(common, ATH_DBG_INTERRUPT,
2045 "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002046 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
2047 REG_WRITE(ah, AR_RC, 0);
2048 *masked |= ATH9K_INT_FATAL;
2049 }
2050 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002051 ath_print(common, ATH_DBG_INTERRUPT,
2052 "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002053 }
2054
2055 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
2056 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
2057 }
Sujithf1dc5602008-10-29 10:16:30 +05302058
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002059 return true;
2060}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002061EXPORT_SYMBOL(ath9k_hw_getisr);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002062
Sujithcbe61d82009-02-09 13:27:12 +05302063enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002064{
Pavel Roskin152d5302010-03-31 18:05:37 -04002065 enum ath9k_int omask = ah->imask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002066 u32 mask, mask2;
Sujith2660b812009-02-09 13:27:26 +05302067 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002068 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002069
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002070 ath_print(common, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002071
2072 if (omask & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002073 ath_print(common, ATH_DBG_INTERRUPT, "disable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002074 REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
2075 (void) REG_READ(ah, AR_IER);
2076 if (!AR_SREV_9100(ah)) {
2077 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
2078 (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
2079
2080 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
2081 (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
2082 }
2083 }
2084
2085 mask = ints & ATH9K_INT_COMMON;
2086 mask2 = 0;
2087
2088 if (ints & ATH9K_INT_TX) {
Sujith2660b812009-02-09 13:27:26 +05302089 if (ah->txok_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002090 mask |= AR_IMR_TXOK;
Sujith2660b812009-02-09 13:27:26 +05302091 if (ah->txdesc_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002092 mask |= AR_IMR_TXDESC;
Sujith2660b812009-02-09 13:27:26 +05302093 if (ah->txerr_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002094 mask |= AR_IMR_TXERR;
Sujith2660b812009-02-09 13:27:26 +05302095 if (ah->txeol_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002096 mask |= AR_IMR_TXEOL;
2097 }
2098 if (ints & ATH9K_INT_RX) {
2099 mask |= AR_IMR_RXERR;
Sujith0ce024c2009-12-14 14:57:00 +05302100 if (ah->config.rx_intr_mitigation)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002101 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
2102 else
2103 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
Sujith60b67f52008-08-07 10:52:38 +05302104 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002105 mask |= AR_IMR_GENTMR;
2106 }
2107
2108 if (ints & (ATH9K_INT_BMISC)) {
2109 mask |= AR_IMR_BCNMISC;
2110 if (ints & ATH9K_INT_TIM)
2111 mask2 |= AR_IMR_S2_TIM;
2112 if (ints & ATH9K_INT_DTIM)
2113 mask2 |= AR_IMR_S2_DTIM;
2114 if (ints & ATH9K_INT_DTIMSYNC)
2115 mask2 |= AR_IMR_S2_DTIMSYNC;
2116 if (ints & ATH9K_INT_CABEND)
Sujith4af9cf42009-02-12 10:06:47 +05302117 mask2 |= AR_IMR_S2_CABEND;
2118 if (ints & ATH9K_INT_TSFOOR)
2119 mask2 |= AR_IMR_S2_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002120 }
2121
2122 if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
2123 mask |= AR_IMR_BCNMISC;
2124 if (ints & ATH9K_INT_GTT)
2125 mask2 |= AR_IMR_S2_GTT;
2126 if (ints & ATH9K_INT_CST)
2127 mask2 |= AR_IMR_S2_CST;
2128 }
2129
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002130 ath_print(common, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002131 REG_WRITE(ah, AR_IMR, mask);
Pavel Roskin74bad5c2010-02-23 18:15:27 -05002132 ah->imrs2_reg &= ~(AR_IMR_S2_TIM | AR_IMR_S2_DTIM | AR_IMR_S2_DTIMSYNC |
2133 AR_IMR_S2_CABEND | AR_IMR_S2_CABTO |
2134 AR_IMR_S2_TSFOOR | AR_IMR_S2_GTT | AR_IMR_S2_CST);
2135 ah->imrs2_reg |= mask2;
2136 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002137
Sujith60b67f52008-08-07 10:52:38 +05302138 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002139 if (ints & ATH9K_INT_TIM_TIMER)
2140 REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
2141 else
2142 REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
2143 }
2144
2145 if (ints & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002146 ath_print(common, ATH_DBG_INTERRUPT, "enable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002147 REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
2148 if (!AR_SREV_9100(ah)) {
2149 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
2150 AR_INTR_MAC_IRQ);
2151 REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
2152
2153
2154 REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
2155 AR_INTR_SYNC_DEFAULT);
2156 REG_WRITE(ah, AR_INTR_SYNC_MASK,
2157 AR_INTR_SYNC_DEFAULT);
2158 }
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002159 ath_print(common, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
2160 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002161 }
2162
2163 return omask;
2164}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002165EXPORT_SYMBOL(ath9k_hw_set_interrupts);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002166
Sujithf1dc5602008-10-29 10:16:30 +05302167/*******************/
2168/* Beacon Handling */
2169/*******************/
2170
Sujithcbe61d82009-02-09 13:27:12 +05302171void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002172{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002173 int flags = 0;
2174
Sujith2660b812009-02-09 13:27:26 +05302175 ah->beacon_interval = beacon_period;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002176
Sujith2660b812009-02-09 13:27:26 +05302177 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08002178 case NL80211_IFTYPE_STATION:
2179 case NL80211_IFTYPE_MONITOR:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002180 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
2181 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
2182 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
2183 flags |= AR_TBTT_TIMER_EN;
2184 break;
Colin McCabed97809d2008-12-01 13:38:55 -08002185 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04002186 case NL80211_IFTYPE_MESH_POINT:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002187 REG_SET_BIT(ah, AR_TXCFG,
2188 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
2189 REG_WRITE(ah, AR_NEXT_NDP_TIMER,
2190 TU_TO_USEC(next_beacon +
Sujith2660b812009-02-09 13:27:26 +05302191 (ah->atim_window ? ah->
2192 atim_window : 1)));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002193 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08002194 case NL80211_IFTYPE_AP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002195 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
2196 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
2197 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05302198 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302199 dma_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002200 REG_WRITE(ah, AR_NEXT_SWBA,
2201 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05302202 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302203 sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002204 flags |=
2205 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
2206 break;
Colin McCabed97809d2008-12-01 13:38:55 -08002207 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002208 ath_print(ath9k_hw_common(ah), ATH_DBG_BEACON,
2209 "%s: unsupported opmode: %d\n",
2210 __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08002211 return;
2212 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002213 }
2214
2215 REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
2216 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
2217 REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
2218 REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
2219
2220 beacon_period &= ~ATH9K_BEACON_ENA;
2221 if (beacon_period & ATH9K_BEACON_RESET_TSF) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002222 ath9k_hw_reset_tsf(ah);
2223 }
2224
2225 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
2226}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002227EXPORT_SYMBOL(ath9k_hw_beaconinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002228
Sujithcbe61d82009-02-09 13:27:12 +05302229void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05302230 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002231{
2232 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05302233 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002234 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002235
2236 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
2237
2238 REG_WRITE(ah, AR_BEACON_PERIOD,
2239 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
2240 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
2241 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
2242
2243 REG_RMW_FIELD(ah, AR_RSSI_THR,
2244 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
2245
2246 beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
2247
2248 if (bs->bs_sleepduration > beaconintval)
2249 beaconintval = bs->bs_sleepduration;
2250
2251 dtimperiod = bs->bs_dtimperiod;
2252 if (bs->bs_sleepduration > dtimperiod)
2253 dtimperiod = bs->bs_sleepduration;
2254
2255 if (beaconintval == dtimperiod)
2256 nextTbtt = bs->bs_nextdtim;
2257 else
2258 nextTbtt = bs->bs_nexttbtt;
2259
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002260 ath_print(common, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
2261 ath_print(common, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
2262 ath_print(common, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
2263 ath_print(common, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002264
2265 REG_WRITE(ah, AR_NEXT_DTIM,
2266 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
2267 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
2268
2269 REG_WRITE(ah, AR_SLEEP1,
2270 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
2271 | AR_SLEEP1_ASSUME_DTIM);
2272
Sujith60b67f52008-08-07 10:52:38 +05302273 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002274 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
2275 else
2276 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
2277
2278 REG_WRITE(ah, AR_SLEEP2,
2279 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
2280
2281 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
2282 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
2283
2284 REG_SET_BIT(ah, AR_TIMER_MODE,
2285 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
2286 AR_DTIM_TIMER_EN);
2287
Sujith4af9cf42009-02-12 10:06:47 +05302288 /* TSF Out of Range Threshold */
2289 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002290}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002291EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002292
Sujithf1dc5602008-10-29 10:16:30 +05302293/*******************/
2294/* HW Capabilities */
2295/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002296
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002297int ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002298{
Sujith2660b812009-02-09 13:27:26 +05302299 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002300 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002301 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002302 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002303
Sujithf1dc5602008-10-29 10:16:30 +05302304 u16 capField = 0, eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002305
Sujithf74df6f2009-02-09 13:27:24 +05302306 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002307 regulatory->current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05302308
Sujithf74df6f2009-02-09 13:27:24 +05302309 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
Sujithfec0de12009-02-12 10:06:43 +05302310 if (AR_SREV_9285_10_OR_LATER(ah))
2311 eeval |= AR9285_RDEXT_DEFAULT;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002312 regulatory->current_rd_ext = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05302313
Sujithf74df6f2009-02-09 13:27:24 +05302314 capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
Sujithf1dc5602008-10-29 10:16:30 +05302315
Sujith2660b812009-02-09 13:27:26 +05302316 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05302317 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002318 if (regulatory->current_rd == 0x64 ||
2319 regulatory->current_rd == 0x65)
2320 regulatory->current_rd += 5;
2321 else if (regulatory->current_rd == 0x41)
2322 regulatory->current_rd = 0x43;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002323 ath_print(common, ATH_DBG_REGULATORY,
2324 "regdomain mapped to 0x%x\n", regulatory->current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002325 }
Sujithdc2222a2008-08-14 13:26:55 +05302326
Sujithf74df6f2009-02-09 13:27:24 +05302327 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002328 if ((eeval & (AR5416_OPFLAGS_11G | AR5416_OPFLAGS_11A)) == 0) {
2329 ath_print(common, ATH_DBG_FATAL,
2330 "no band has been marked as supported in EEPROM.\n");
2331 return -EINVAL;
2332 }
2333
Sujithf1dc5602008-10-29 10:16:30 +05302334 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002335
Sujithf1dc5602008-10-29 10:16:30 +05302336 if (eeval & AR5416_OPFLAGS_11A) {
2337 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05302338 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05302339 if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
2340 set_bit(ATH9K_MODE_11NA_HT20,
2341 pCap->wireless_modes);
2342 if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
2343 set_bit(ATH9K_MODE_11NA_HT40PLUS,
2344 pCap->wireless_modes);
2345 set_bit(ATH9K_MODE_11NA_HT40MINUS,
2346 pCap->wireless_modes);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002347 }
2348 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002349 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002350
Sujithf1dc5602008-10-29 10:16:30 +05302351 if (eeval & AR5416_OPFLAGS_11G) {
Sujithf1dc5602008-10-29 10:16:30 +05302352 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05302353 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05302354 if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
2355 set_bit(ATH9K_MODE_11NG_HT20,
2356 pCap->wireless_modes);
2357 if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
2358 set_bit(ATH9K_MODE_11NG_HT40PLUS,
2359 pCap->wireless_modes);
2360 set_bit(ATH9K_MODE_11NG_HT40MINUS,
2361 pCap->wireless_modes);
2362 }
2363 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002364 }
Sujithf1dc5602008-10-29 10:16:30 +05302365
Sujithf74df6f2009-02-09 13:27:24 +05302366 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002367 /*
2368 * For AR9271 we will temporarilly uses the rx chainmax as read from
2369 * the EEPROM.
2370 */
Sujith8147f5d2009-02-20 15:13:23 +05302371 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002372 !(eeval & AR5416_OPFLAGS_11A) &&
2373 !(AR_SREV_9271(ah)))
2374 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
Sujith8147f5d2009-02-20 15:13:23 +05302375 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
2376 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002377 /* Use rx_chainmask from EEPROM. */
Sujith8147f5d2009-02-20 15:13:23 +05302378 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05302379
Sujithd535a422009-02-09 13:27:06 +05302380 if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0)))
Sujith2660b812009-02-09 13:27:26 +05302381 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05302382
2383 pCap->low_2ghz_chan = 2312;
2384 pCap->high_2ghz_chan = 2732;
2385
2386 pCap->low_5ghz_chan = 4920;
2387 pCap->high_5ghz_chan = 6100;
2388
2389 pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
2390 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
2391 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
2392
2393 pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
2394 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
2395 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
2396
Sujith2660b812009-02-09 13:27:26 +05302397 if (ah->config.ht_enable)
Sujithf1dc5602008-10-29 10:16:30 +05302398 pCap->hw_caps |= ATH9K_HW_CAP_HT;
2399 else
2400 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
2401
2402 pCap->hw_caps |= ATH9K_HW_CAP_GTT;
2403 pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
2404 pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
2405 pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
2406
2407 if (capField & AR_EEPROM_EEPCAP_MAXQCU)
2408 pCap->total_queues =
2409 MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
2410 else
2411 pCap->total_queues = ATH9K_NUM_TX_QUEUES;
2412
2413 if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
2414 pCap->keycache_size =
2415 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
2416 else
2417 pCap->keycache_size = AR_KEYTABLE_SIZE;
2418
2419 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -05002420
2421 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
2422 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD >> 1;
2423 else
2424 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
Sujithf1dc5602008-10-29 10:16:30 +05302425
Sujith5b5fa352010-03-17 14:25:15 +05302426 if (AR_SREV_9271(ah))
2427 pCap->num_gpio_pins = AR9271_NUM_GPIO;
2428 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302429 pCap->num_gpio_pins = AR9285_NUM_GPIO;
2430 else if (AR_SREV_9280_10_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302431 pCap->num_gpio_pins = AR928X_NUM_GPIO;
2432 else
2433 pCap->num_gpio_pins = AR_NUM_GPIO;
2434
Sujithf1dc5602008-10-29 10:16:30 +05302435 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
2436 pCap->hw_caps |= ATH9K_HW_CAP_CST;
2437 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
2438 } else {
2439 pCap->rts_aggr_limit = (8 * 1024);
2440 }
2441
2442 pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
2443
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05302444#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05302445 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
2446 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
2447 ah->rfkill_gpio =
2448 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
2449 ah->rfkill_polarity =
2450 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05302451
2452 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
2453 }
2454#endif
Vivek Natarajanbde748a2010-04-05 14:48:05 +05302455 if (AR_SREV_9271(ah))
2456 pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
2457 else
2458 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
Sujithf1dc5602008-10-29 10:16:30 +05302459
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302460 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302461 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
2462 else
2463 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
2464
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002465 if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) {
Sujithf1dc5602008-10-29 10:16:30 +05302466 pCap->reg_cap =
2467 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
2468 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
2469 AR_EEPROM_EEREGCAP_EN_KK_U2 |
2470 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
2471 } else {
2472 pCap->reg_cap =
2473 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
2474 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
2475 }
2476
Senthil Balasubramanianebb90cf2009-09-18 15:07:33 +05302477 /* Advertise midband for AR5416 with FCC midband set in eeprom */
2478 if (regulatory->current_rd_ext & (1 << REG_EXT_FCC_MIDBAND) &&
2479 AR_SREV_5416(ah))
2480 pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
Sujithf1dc5602008-10-29 10:16:30 +05302481
2482 pCap->num_antcfg_5ghz =
Sujithf74df6f2009-02-09 13:27:24 +05302483 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05302484 pCap->num_antcfg_2ghz =
Sujithf74df6f2009-02-09 13:27:24 +05302485 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05302486
Vasanthakumar Thiagarajanfe129462009-09-09 15:25:50 +05302487 if (AR_SREV_9280_10_OR_LATER(ah) &&
Luis R. Rodrigueza36cfbc2009-09-09 16:05:32 -07002488 ath9k_hw_btcoex_supported(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002489 btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO;
2490 btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO;
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05302491
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302492 if (AR_SREV_9285(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002493 btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
2494 btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302495 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002496 btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302497 }
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05302498 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002499 btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE;
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05302500 }
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002501
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002502 if (AR_SREV_9300_20_OR_LATER(ah)) {
Vasanthakumar Thiagarajan1adf02f2010-04-15 17:38:24 -04002503 pCap->hw_caps |= ATH9K_HW_CAP_EDMA;
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002504 pCap->rx_hp_qdepth = ATH9K_HW_RX_HP_QDEPTH;
2505 pCap->rx_lp_qdepth = ATH9K_HW_RX_LP_QDEPTH;
2506 pCap->rx_status_len = sizeof(struct ar9003_rxs);
Vasanthakumar Thiagarajan162c3be2010-04-15 17:38:41 -04002507 pCap->tx_desc_len = sizeof(struct ar9003_txc);
2508 } else {
2509 pCap->tx_desc_len = sizeof(struct ath_desc);
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002510 }
Vasanthakumar Thiagarajan1adf02f2010-04-15 17:38:24 -04002511
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002512 return 0;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002513}
2514
Sujithcbe61d82009-02-09 13:27:12 +05302515bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05302516 u32 capability, u32 *result)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002517{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002518 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302519 switch (type) {
2520 case ATH9K_CAP_CIPHER:
2521 switch (capability) {
2522 case ATH9K_CIPHER_AES_CCM:
2523 case ATH9K_CIPHER_AES_OCB:
2524 case ATH9K_CIPHER_TKIP:
2525 case ATH9K_CIPHER_WEP:
2526 case ATH9K_CIPHER_MIC:
2527 case ATH9K_CIPHER_CLR:
2528 return true;
2529 default:
2530 return false;
2531 }
2532 case ATH9K_CAP_TKIP_MIC:
2533 switch (capability) {
2534 case 0:
2535 return true;
2536 case 1:
Sujith2660b812009-02-09 13:27:26 +05302537 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05302538 AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
2539 false;
2540 }
2541 case ATH9K_CAP_TKIP_SPLIT:
Sujith2660b812009-02-09 13:27:26 +05302542 return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ?
Sujithf1dc5602008-10-29 10:16:30 +05302543 false : true;
Sujithf1dc5602008-10-29 10:16:30 +05302544 case ATH9K_CAP_MCAST_KEYSRCH:
2545 switch (capability) {
2546 case 0:
2547 return true;
2548 case 1:
2549 if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
2550 return false;
2551 } else {
Sujith2660b812009-02-09 13:27:26 +05302552 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05302553 AR_STA_ID1_MCAST_KSRCH) ? true :
2554 false;
2555 }
2556 }
2557 return false;
Sujithf1dc5602008-10-29 10:16:30 +05302558 case ATH9K_CAP_TXPOW:
2559 switch (capability) {
2560 case 0:
2561 return 0;
2562 case 1:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002563 *result = regulatory->power_limit;
Sujithf1dc5602008-10-29 10:16:30 +05302564 return 0;
2565 case 2:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002566 *result = regulatory->max_power_level;
Sujithf1dc5602008-10-29 10:16:30 +05302567 return 0;
2568 case 3:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002569 *result = regulatory->tp_scale;
Sujithf1dc5602008-10-29 10:16:30 +05302570 return 0;
2571 }
2572 return false;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05302573 case ATH9K_CAP_DS:
2574 return (AR_SREV_9280_20_OR_LATER(ah) &&
2575 (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1))
2576 ? false : true;
Sujithf1dc5602008-10-29 10:16:30 +05302577 default:
2578 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002579 }
Sujithf1dc5602008-10-29 10:16:30 +05302580}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002581EXPORT_SYMBOL(ath9k_hw_getcapability);
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002582
Sujithcbe61d82009-02-09 13:27:12 +05302583bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05302584 u32 capability, u32 setting, int *status)
2585{
Sujithf1dc5602008-10-29 10:16:30 +05302586 switch (type) {
2587 case ATH9K_CAP_TKIP_MIC:
2588 if (setting)
Sujith2660b812009-02-09 13:27:26 +05302589 ah->sta_id1_defaults |=
Sujithf1dc5602008-10-29 10:16:30 +05302590 AR_STA_ID1_CRPT_MIC_ENABLE;
2591 else
Sujith2660b812009-02-09 13:27:26 +05302592 ah->sta_id1_defaults &=
Sujithf1dc5602008-10-29 10:16:30 +05302593 ~AR_STA_ID1_CRPT_MIC_ENABLE;
2594 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302595 case ATH9K_CAP_MCAST_KEYSRCH:
2596 if (setting)
Sujith2660b812009-02-09 13:27:26 +05302597 ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05302598 else
Sujith2660b812009-02-09 13:27:26 +05302599 ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05302600 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302601 default:
2602 return false;
2603 }
2604}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002605EXPORT_SYMBOL(ath9k_hw_setcapability);
Sujithf1dc5602008-10-29 10:16:30 +05302606
2607/****************************/
2608/* GPIO / RFKILL / Antennae */
2609/****************************/
2610
Sujithcbe61d82009-02-09 13:27:12 +05302611static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05302612 u32 gpio, u32 type)
2613{
2614 int addr;
2615 u32 gpio_shift, tmp;
2616
2617 if (gpio > 11)
2618 addr = AR_GPIO_OUTPUT_MUX3;
2619 else if (gpio > 5)
2620 addr = AR_GPIO_OUTPUT_MUX2;
2621 else
2622 addr = AR_GPIO_OUTPUT_MUX1;
2623
2624 gpio_shift = (gpio % 6) * 5;
2625
2626 if (AR_SREV_9280_20_OR_LATER(ah)
2627 || (addr != AR_GPIO_OUTPUT_MUX1)) {
2628 REG_RMW(ah, addr, (type << gpio_shift),
2629 (0x1f << gpio_shift));
2630 } else {
2631 tmp = REG_READ(ah, addr);
2632 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
2633 tmp &= ~(0x1f << gpio_shift);
2634 tmp |= (type << gpio_shift);
2635 REG_WRITE(ah, addr, tmp);
2636 }
2637}
2638
Sujithcbe61d82009-02-09 13:27:12 +05302639void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05302640{
2641 u32 gpio_shift;
2642
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07002643 BUG_ON(gpio >= ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05302644
2645 gpio_shift = gpio << 1;
2646
2647 REG_RMW(ah,
2648 AR_GPIO_OE_OUT,
2649 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
2650 (AR_GPIO_OE_OUT_DRV << gpio_shift));
2651}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002652EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
Sujithf1dc5602008-10-29 10:16:30 +05302653
Sujithcbe61d82009-02-09 13:27:12 +05302654u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05302655{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302656#define MS_REG_READ(x, y) \
2657 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
2658
Sujith2660b812009-02-09 13:27:26 +05302659 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05302660 return 0xffffffff;
2661
Felix Fietkau783dfca2010-04-15 17:38:11 -04002662 if (AR_SREV_9300_20_OR_LATER(ah))
2663 return MS_REG_READ(AR9300, gpio) != 0;
2664 else if (AR_SREV_9271(ah))
Sujith5b5fa352010-03-17 14:25:15 +05302665 return MS_REG_READ(AR9271, gpio) != 0;
2666 else if (AR_SREV_9287_10_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302667 return MS_REG_READ(AR9287, gpio) != 0;
2668 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302669 return MS_REG_READ(AR9285, gpio) != 0;
2670 else if (AR_SREV_9280_10_OR_LATER(ah))
2671 return MS_REG_READ(AR928X, gpio) != 0;
2672 else
2673 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05302674}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002675EXPORT_SYMBOL(ath9k_hw_gpio_get);
Sujithf1dc5602008-10-29 10:16:30 +05302676
Sujithcbe61d82009-02-09 13:27:12 +05302677void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05302678 u32 ah_signal_type)
2679{
2680 u32 gpio_shift;
2681
2682 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
2683
2684 gpio_shift = 2 * gpio;
2685
2686 REG_RMW(ah,
2687 AR_GPIO_OE_OUT,
2688 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
2689 (AR_GPIO_OE_OUT_DRV << gpio_shift));
2690}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002691EXPORT_SYMBOL(ath9k_hw_cfg_output);
Sujithf1dc5602008-10-29 10:16:30 +05302692
Sujithcbe61d82009-02-09 13:27:12 +05302693void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05302694{
Sujith5b5fa352010-03-17 14:25:15 +05302695 if (AR_SREV_9271(ah))
2696 val = ~val;
2697
Sujithf1dc5602008-10-29 10:16:30 +05302698 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
2699 AR_GPIO_BIT(gpio));
2700}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002701EXPORT_SYMBOL(ath9k_hw_set_gpio);
Sujithf1dc5602008-10-29 10:16:30 +05302702
Sujithcbe61d82009-02-09 13:27:12 +05302703u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302704{
2705 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
2706}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002707EXPORT_SYMBOL(ath9k_hw_getdefantenna);
Sujithf1dc5602008-10-29 10:16:30 +05302708
Sujithcbe61d82009-02-09 13:27:12 +05302709void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05302710{
2711 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
2712}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002713EXPORT_SYMBOL(ath9k_hw_setantenna);
Sujithf1dc5602008-10-29 10:16:30 +05302714
Sujithf1dc5602008-10-29 10:16:30 +05302715/*********************/
2716/* General Operation */
2717/*********************/
2718
Sujithcbe61d82009-02-09 13:27:12 +05302719u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302720{
2721 u32 bits = REG_READ(ah, AR_RX_FILTER);
2722 u32 phybits = REG_READ(ah, AR_PHY_ERR);
2723
2724 if (phybits & AR_PHY_ERR_RADAR)
2725 bits |= ATH9K_RX_FILTER_PHYRADAR;
2726 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
2727 bits |= ATH9K_RX_FILTER_PHYERR;
2728
2729 return bits;
2730}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002731EXPORT_SYMBOL(ath9k_hw_getrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05302732
Sujithcbe61d82009-02-09 13:27:12 +05302733void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05302734{
2735 u32 phybits;
2736
Sujith7ea310b2009-09-03 12:08:43 +05302737 REG_WRITE(ah, AR_RX_FILTER, bits);
2738
Sujithf1dc5602008-10-29 10:16:30 +05302739 phybits = 0;
2740 if (bits & ATH9K_RX_FILTER_PHYRADAR)
2741 phybits |= AR_PHY_ERR_RADAR;
2742 if (bits & ATH9K_RX_FILTER_PHYERR)
2743 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
2744 REG_WRITE(ah, AR_PHY_ERR, phybits);
2745
2746 if (phybits)
2747 REG_WRITE(ah, AR_RXCFG,
2748 REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
2749 else
2750 REG_WRITE(ah, AR_RXCFG,
2751 REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
2752}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002753EXPORT_SYMBOL(ath9k_hw_setrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05302754
Sujithcbe61d82009-02-09 13:27:12 +05302755bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302756{
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05302757 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
2758 return false;
2759
2760 ath9k_hw_init_pll(ah, NULL);
2761 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302762}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002763EXPORT_SYMBOL(ath9k_hw_phy_disable);
Sujithf1dc5602008-10-29 10:16:30 +05302764
Sujithcbe61d82009-02-09 13:27:12 +05302765bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302766{
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002767 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05302768 return false;
2769
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05302770 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
2771 return false;
2772
2773 ath9k_hw_init_pll(ah, NULL);
2774 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302775}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002776EXPORT_SYMBOL(ath9k_hw_disable);
Sujithf1dc5602008-10-29 10:16:30 +05302777
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07002778void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
Sujithf1dc5602008-10-29 10:16:30 +05302779{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002780 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujith2660b812009-02-09 13:27:26 +05302781 struct ath9k_channel *chan = ah->curchan;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002782 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05302783
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002784 regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER);
Sujithf1dc5602008-10-29 10:16:30 +05302785
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07002786 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002787 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07002788 channel->max_antenna_gain * 2,
2789 channel->max_power * 2,
2790 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002791 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05302792}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002793EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
Sujithf1dc5602008-10-29 10:16:30 +05302794
Sujithcbe61d82009-02-09 13:27:12 +05302795void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac)
Sujithf1dc5602008-10-29 10:16:30 +05302796{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002797 memcpy(ath9k_hw_common(ah)->macaddr, mac, ETH_ALEN);
Sujithf1dc5602008-10-29 10:16:30 +05302798}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002799EXPORT_SYMBOL(ath9k_hw_setmac);
Sujithf1dc5602008-10-29 10:16:30 +05302800
Sujithcbe61d82009-02-09 13:27:12 +05302801void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302802{
Sujith2660b812009-02-09 13:27:26 +05302803 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05302804}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002805EXPORT_SYMBOL(ath9k_hw_setopmode);
Sujithf1dc5602008-10-29 10:16:30 +05302806
Sujithcbe61d82009-02-09 13:27:12 +05302807void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05302808{
2809 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
2810 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
2811}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002812EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
Sujithf1dc5602008-10-29 10:16:30 +05302813
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07002814void ath9k_hw_write_associd(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302815{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002816 struct ath_common *common = ath9k_hw_common(ah);
2817
2818 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
2819 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
2820 ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05302821}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002822EXPORT_SYMBOL(ath9k_hw_write_associd);
Sujithf1dc5602008-10-29 10:16:30 +05302823
Sujithcbe61d82009-02-09 13:27:12 +05302824u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302825{
2826 u64 tsf;
2827
2828 tsf = REG_READ(ah, AR_TSF_U32);
2829 tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
2830
2831 return tsf;
2832}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002833EXPORT_SYMBOL(ath9k_hw_gettsf64);
Sujithf1dc5602008-10-29 10:16:30 +05302834
Sujithcbe61d82009-02-09 13:27:12 +05302835void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002836{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002837 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01002838 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002839}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002840EXPORT_SYMBOL(ath9k_hw_settsf64);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002841
Sujithcbe61d82009-02-09 13:27:12 +05302842void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302843{
Gabor Juhosf9b604f2009-06-21 00:02:15 +02002844 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
2845 AH_TSF_WRITE_TIMEOUT))
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002846 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
2847 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
Gabor Juhosf9b604f2009-06-21 00:02:15 +02002848
Sujithf1dc5602008-10-29 10:16:30 +05302849 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002850}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002851EXPORT_SYMBOL(ath9k_hw_reset_tsf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002852
Sujith54e4cec2009-08-07 09:45:09 +05302853void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002854{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002855 if (setting)
Sujith2660b812009-02-09 13:27:26 +05302856 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002857 else
Sujith2660b812009-02-09 13:27:26 +05302858 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002859}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002860EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002861
Luis R. Rodriguez30cbd422009-11-03 16:10:46 -08002862/*
2863 * Extend 15-bit time stamp from rx descriptor to
2864 * a full 64-bit TSF using the current h/w TSF.
2865*/
2866u64 ath9k_hw_extend_tsf(struct ath_hw *ah, u32 rstamp)
2867{
2868 u64 tsf;
2869
2870 tsf = ath9k_hw_gettsf64(ah);
2871 if ((tsf & 0x7fff) < rstamp)
2872 tsf -= 0x8000;
2873 return (tsf & ~0x7fff) | rstamp;
2874}
2875EXPORT_SYMBOL(ath9k_hw_extend_tsf);
2876
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002877void ath9k_hw_set11nmac2040(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002878{
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002879 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithf1dc5602008-10-29 10:16:30 +05302880 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002881
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002882 if (conf_is_ht40(conf) && !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05302883 macmode = AR_2040_JOINED_RX_CLEAR;
2884 else
2885 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002886
Sujithf1dc5602008-10-29 10:16:30 +05302887 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002888}
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302889
2890/* HW Generic timers configuration */
2891
2892static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
2893{
2894 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2895 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2896 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2897 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2898 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2899 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2900 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2901 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2902 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
2903 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
2904 AR_NDP2_TIMER_MODE, 0x0002},
2905 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
2906 AR_NDP2_TIMER_MODE, 0x0004},
2907 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
2908 AR_NDP2_TIMER_MODE, 0x0008},
2909 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
2910 AR_NDP2_TIMER_MODE, 0x0010},
2911 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
2912 AR_NDP2_TIMER_MODE, 0x0020},
2913 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
2914 AR_NDP2_TIMER_MODE, 0x0040},
2915 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
2916 AR_NDP2_TIMER_MODE, 0x0080}
2917};
2918
2919/* HW generic timer primitives */
2920
2921/* compute and clear index of rightmost 1 */
2922static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
2923{
2924 u32 b;
2925
2926 b = *mask;
2927 b &= (0-b);
2928 *mask &= ~b;
2929 b *= debruijn32;
2930 b >>= 27;
2931
2932 return timer_table->gen_timer_index[b];
2933}
2934
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05302935u32 ath9k_hw_gettsf32(struct ath_hw *ah)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302936{
2937 return REG_READ(ah, AR_TSF_L32);
2938}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002939EXPORT_SYMBOL(ath9k_hw_gettsf32);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302940
2941struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
2942 void (*trigger)(void *),
2943 void (*overflow)(void *),
2944 void *arg,
2945 u8 timer_index)
2946{
2947 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2948 struct ath_gen_timer *timer;
2949
2950 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
2951
2952 if (timer == NULL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002953 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2954 "Failed to allocate memory"
2955 "for hw timer[%d]\n", timer_index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302956 return NULL;
2957 }
2958
2959 /* allocate a hardware generic timer slot */
2960 timer_table->timers[timer_index] = timer;
2961 timer->index = timer_index;
2962 timer->trigger = trigger;
2963 timer->overflow = overflow;
2964 timer->arg = arg;
2965
2966 return timer;
2967}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002968EXPORT_SYMBOL(ath_gen_timer_alloc);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302969
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07002970void ath9k_hw_gen_timer_start(struct ath_hw *ah,
2971 struct ath_gen_timer *timer,
2972 u32 timer_next,
2973 u32 timer_period)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302974{
2975 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2976 u32 tsf;
2977
2978 BUG_ON(!timer_period);
2979
2980 set_bit(timer->index, &timer_table->timer_mask.timer_bits);
2981
2982 tsf = ath9k_hw_gettsf32(ah);
2983
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002984 ath_print(ath9k_hw_common(ah), ATH_DBG_HWTIMER,
2985 "curent tsf %x period %x"
2986 "timer_next %x\n", tsf, timer_period, timer_next);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302987
2988 /*
2989 * Pull timer_next forward if the current TSF already passed it
2990 * because of software latency
2991 */
2992 if (timer_next < tsf)
2993 timer_next = tsf + timer_period;
2994
2995 /*
2996 * Program generic timer registers
2997 */
2998 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
2999 timer_next);
3000 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
3001 timer_period);
3002 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
3003 gen_tmr_configuration[timer->index].mode_mask);
3004
3005 /* Enable both trigger and thresh interrupt masks */
3006 REG_SET_BIT(ah, AR_IMR_S5,
3007 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
3008 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303009}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003010EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303011
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07003012void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303013{
3014 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3015
3016 if ((timer->index < AR_FIRST_NDP_TIMER) ||
3017 (timer->index >= ATH_MAX_GEN_TIMER)) {
3018 return;
3019 }
3020
3021 /* Clear generic timer enable bits. */
3022 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
3023 gen_tmr_configuration[timer->index].mode_mask);
3024
3025 /* Disable both trigger and thresh interrupt masks */
3026 REG_CLR_BIT(ah, AR_IMR_S5,
3027 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
3028 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
3029
3030 clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303031}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003032EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303033
3034void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
3035{
3036 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3037
3038 /* free the hardware generic timer slot */
3039 timer_table->timers[timer->index] = NULL;
3040 kfree(timer);
3041}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003042EXPORT_SYMBOL(ath_gen_timer_free);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303043
3044/*
3045 * Generic Timer Interrupts handling
3046 */
3047void ath_gen_timer_isr(struct ath_hw *ah)
3048{
3049 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3050 struct ath_gen_timer *timer;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003051 struct ath_common *common = ath9k_hw_common(ah);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303052 u32 trigger_mask, thresh_mask, index;
3053
3054 /* get hardware generic timer interrupt status */
3055 trigger_mask = ah->intr_gen_timer_trigger;
3056 thresh_mask = ah->intr_gen_timer_thresh;
3057 trigger_mask &= timer_table->timer_mask.val;
3058 thresh_mask &= timer_table->timer_mask.val;
3059
3060 trigger_mask &= ~thresh_mask;
3061
3062 while (thresh_mask) {
3063 index = rightmost_index(timer_table, &thresh_mask);
3064 timer = timer_table->timers[index];
3065 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003066 ath_print(common, ATH_DBG_HWTIMER,
3067 "TSF overflow for Gen timer %d\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303068 timer->overflow(timer->arg);
3069 }
3070
3071 while (trigger_mask) {
3072 index = rightmost_index(timer_table, &trigger_mask);
3073 timer = timer_table->timers[index];
3074 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003075 ath_print(common, ATH_DBG_HWTIMER,
3076 "Gen timer[%d] trigger\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303077 timer->trigger(timer->arg);
3078 }
3079}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003080EXPORT_SYMBOL(ath_gen_timer_isr);
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003081
Sujith05020d22010-03-17 14:25:23 +05303082/********/
3083/* HTC */
3084/********/
3085
3086void ath9k_hw_htc_resetinit(struct ath_hw *ah)
3087{
3088 ah->htc_reset_init = true;
3089}
3090EXPORT_SYMBOL(ath9k_hw_htc_resetinit);
3091
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003092static struct {
3093 u32 version;
3094 const char * name;
3095} ath_mac_bb_names[] = {
3096 /* Devices with external radios */
3097 { AR_SREV_VERSION_5416_PCI, "5416" },
3098 { AR_SREV_VERSION_5416_PCIE, "5418" },
3099 { AR_SREV_VERSION_9100, "9100" },
3100 { AR_SREV_VERSION_9160, "9160" },
3101 /* Single-chip solutions */
3102 { AR_SREV_VERSION_9280, "9280" },
3103 { AR_SREV_VERSION_9285, "9285" },
Luis R. Rodriguez11158472009-10-27 12:59:35 -04003104 { AR_SREV_VERSION_9287, "9287" },
3105 { AR_SREV_VERSION_9271, "9271" },
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003106};
3107
3108/* For devices with external radios */
3109static struct {
3110 u16 version;
3111 const char * name;
3112} ath_rf_names[] = {
3113 { 0, "5133" },
3114 { AR_RAD5133_SREV_MAJOR, "5133" },
3115 { AR_RAD5122_SREV_MAJOR, "5122" },
3116 { AR_RAD2133_SREV_MAJOR, "2133" },
3117 { AR_RAD2122_SREV_MAJOR, "2122" }
3118};
3119
3120/*
3121 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
3122 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003123static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003124{
3125 int i;
3126
3127 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
3128 if (ath_mac_bb_names[i].version == mac_bb_version) {
3129 return ath_mac_bb_names[i].name;
3130 }
3131 }
3132
3133 return "????";
3134}
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003135
3136/*
3137 * Return the RF name. "????" is returned if the RF is unknown.
3138 * Used for devices with external radios.
3139 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003140static const char *ath9k_hw_rf_name(u16 rf_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003141{
3142 int i;
3143
3144 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
3145 if (ath_rf_names[i].version == rf_version) {
3146 return ath_rf_names[i].name;
3147 }
3148 }
3149
3150 return "????";
3151}
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003152
3153void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
3154{
3155 int used;
3156
3157 /* chipsets >= AR9280 are single-chip */
3158 if (AR_SREV_9280_10_OR_LATER(ah)) {
3159 used = snprintf(hw_name, len,
3160 "Atheros AR%s Rev:%x",
3161 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3162 ah->hw_version.macRev);
3163 }
3164 else {
3165 used = snprintf(hw_name, len,
3166 "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
3167 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3168 ah->hw_version.macRev,
3169 ath9k_hw_rf_name((ah->hw_version.analog5GhzRev &
3170 AR_RADIO_SREV_MAJOR)),
3171 ah->hw_version.phyRev);
3172 }
3173
3174 hw_name[used] = '\0';
3175}
3176EXPORT_SYMBOL(ath9k_hw_name);