blob: 8f37f1c2a3802d62240dce52c24fdec729eabc71 [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. Rodriguezb622a722010-04-15 17:39:28 -040023#include "ar9003_mac.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
Vasanthakumar Thiagarajane5553722010-04-26 15:04:33 -040028#define ATH9K_CLOCK_FAST_RATE_5GHZ_OFDM 44
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070029
Sujithcbe61d82009-02-09 13:27:12 +053030static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070031
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040032MODULE_AUTHOR("Atheros Communications");
33MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
34MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
35MODULE_LICENSE("Dual BSD/GPL");
36
37static int __init ath9k_init(void)
38{
39 return 0;
40}
41module_init(ath9k_init);
42
43static void __exit ath9k_exit(void)
44{
45 return;
46}
47module_exit(ath9k_exit);
48
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -040049/* Private hardware callbacks */
50
51static void ath9k_hw_init_cal_settings(struct ath_hw *ah)
52{
53 ath9k_hw_private_ops(ah)->init_cal_settings(ah);
54}
55
56static void ath9k_hw_init_mode_regs(struct ath_hw *ah)
57{
58 ath9k_hw_private_ops(ah)->init_mode_regs(ah);
59}
60
61static bool ath9k_hw_macversion_supported(struct ath_hw *ah)
62{
63 struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
64
65 return priv_ops->macversion_supported(ah->hw_version.macVersion);
66}
67
Luis R. Rodriguez64773962010-04-15 17:38:17 -040068static u32 ath9k_hw_compute_pll_control(struct ath_hw *ah,
69 struct ath9k_channel *chan)
70{
71 return ath9k_hw_private_ops(ah)->compute_pll_control(ah, chan);
72}
73
Luis R. Rodriguez991312d2010-04-15 17:39:05 -040074static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
75{
76 if (!ath9k_hw_private_ops(ah)->init_mode_gain_regs)
77 return;
78
79 ath9k_hw_private_ops(ah)->init_mode_gain_regs(ah);
80}
81
Sujithf1dc5602008-10-29 10:16:30 +053082/********************/
83/* Helper Functions */
84/********************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070085
Sujithcbe61d82009-02-09 13:27:12 +053086static u32 ath9k_hw_mac_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053087{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070088 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053089
Sujith2660b812009-02-09 13:27:26 +053090 if (!ah->curchan) /* should really check for CCK instead */
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080091 return usecs *ATH9K_CLOCK_RATE_CCK;
92 if (conf->channel->band == IEEE80211_BAND_2GHZ)
93 return usecs *ATH9K_CLOCK_RATE_2GHZ_OFDM;
Vasanthakumar Thiagarajane5553722010-04-26 15:04:33 -040094
95 if (ah->caps.hw_caps & ATH9K_HW_CAP_FASTCLOCK)
96 return usecs * ATH9K_CLOCK_FAST_RATE_5GHZ_OFDM;
97 else
98 return usecs * ATH9K_CLOCK_RATE_5GHZ_OFDM;
Sujithf1dc5602008-10-29 10:16:30 +053099}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700100
Sujithcbe61d82009-02-09 13:27:12 +0530101static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +0530102{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -0700103 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +0530104
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -0800105 if (conf_is_ht40(conf))
Sujithf1dc5602008-10-29 10:16:30 +0530106 return ath9k_hw_mac_clks(ah, usecs) * 2;
107 else
108 return ath9k_hw_mac_clks(ah, usecs);
109}
110
Sujith0caa7b12009-02-16 13:23:20 +0530111bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700112{
113 int i;
114
Sujith0caa7b12009-02-16 13:23:20 +0530115 BUG_ON(timeout < AH_TIME_QUANTUM);
116
117 for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700118 if ((REG_READ(ah, reg) & mask) == val)
119 return true;
120
121 udelay(AH_TIME_QUANTUM);
122 }
Sujith04bd46382008-11-28 22:18:05 +0530123
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700124 ath_print(ath9k_hw_common(ah), ATH_DBG_ANY,
125 "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
126 timeout, reg, REG_READ(ah, reg), mask, val);
Sujithf1dc5602008-10-29 10:16:30 +0530127
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700128 return false;
129}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400130EXPORT_SYMBOL(ath9k_hw_wait);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700131
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700132u32 ath9k_hw_reverse_bits(u32 val, u32 n)
133{
134 u32 retval;
135 int i;
136
137 for (i = 0, retval = 0; i < n; i++) {
138 retval = (retval << 1) | (val & 1);
139 val >>= 1;
140 }
141 return retval;
142}
143
Sujithcbe61d82009-02-09 13:27:12 +0530144bool ath9k_get_channel_edges(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530145 u16 flags, u16 *low,
146 u16 *high)
147{
Sujith2660b812009-02-09 13:27:26 +0530148 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530149
150 if (flags & CHANNEL_5GHZ) {
151 *low = pCap->low_5ghz_chan;
152 *high = pCap->high_5ghz_chan;
153 return true;
154 }
155 if ((flags & CHANNEL_2GHZ)) {
156 *low = pCap->low_2ghz_chan;
157 *high = pCap->high_2ghz_chan;
158 return true;
159 }
160 return false;
161}
162
Sujithcbe61d82009-02-09 13:27:12 +0530163u16 ath9k_hw_computetxtime(struct ath_hw *ah,
Felix Fietkau545750d2009-11-23 22:21:01 +0100164 u8 phy, int kbps,
Sujithf1dc5602008-10-29 10:16:30 +0530165 u32 frameLen, u16 rateix,
166 bool shortPreamble)
167{
168 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
Sujithf1dc5602008-10-29 10:16:30 +0530169
170 if (kbps == 0)
171 return 0;
172
Felix Fietkau545750d2009-11-23 22:21:01 +0100173 switch (phy) {
Sujith46d14a52008-11-18 09:08:13 +0530174 case WLAN_RC_PHY_CCK:
Sujithf1dc5602008-10-29 10:16:30 +0530175 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
Felix Fietkau545750d2009-11-23 22:21:01 +0100176 if (shortPreamble)
Sujithf1dc5602008-10-29 10:16:30 +0530177 phyTime >>= 1;
178 numBits = frameLen << 3;
179 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
180 break;
Sujith46d14a52008-11-18 09:08:13 +0530181 case WLAN_RC_PHY_OFDM:
Sujith2660b812009-02-09 13:27:26 +0530182 if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530183 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
184 numBits = OFDM_PLCP_BITS + (frameLen << 3);
185 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
186 txTime = OFDM_SIFS_TIME_QUARTER
187 + OFDM_PREAMBLE_TIME_QUARTER
188 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
Sujith2660b812009-02-09 13:27:26 +0530189 } else if (ah->curchan &&
190 IS_CHAN_HALF_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530191 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
192 numBits = OFDM_PLCP_BITS + (frameLen << 3);
193 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
194 txTime = OFDM_SIFS_TIME_HALF +
195 OFDM_PREAMBLE_TIME_HALF
196 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
197 } else {
198 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
199 numBits = OFDM_PLCP_BITS + (frameLen << 3);
200 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
201 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
202 + (numSymbols * OFDM_SYMBOL_TIME);
203 }
204 break;
205 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700206 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
Felix Fietkau545750d2009-11-23 22:21:01 +0100207 "Unknown phy %u (rate ix %u)\n", phy, rateix);
Sujithf1dc5602008-10-29 10:16:30 +0530208 txTime = 0;
209 break;
210 }
211
212 return txTime;
213}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400214EXPORT_SYMBOL(ath9k_hw_computetxtime);
Sujithf1dc5602008-10-29 10:16:30 +0530215
Sujithcbe61d82009-02-09 13:27:12 +0530216void ath9k_hw_get_channel_centers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530217 struct ath9k_channel *chan,
218 struct chan_centers *centers)
219{
220 int8_t extoff;
Sujithf1dc5602008-10-29 10:16:30 +0530221
222 if (!IS_CHAN_HT40(chan)) {
223 centers->ctl_center = centers->ext_center =
224 centers->synth_center = chan->channel;
225 return;
226 }
227
228 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
229 (chan->chanmode == CHANNEL_G_HT40PLUS)) {
230 centers->synth_center =
231 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
232 extoff = 1;
233 } else {
234 centers->synth_center =
235 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
236 extoff = -1;
237 }
238
239 centers->ctl_center =
240 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700241 /* 25 MHz spacing is supported by hw but not on upper layers */
Sujithf1dc5602008-10-29 10:16:30 +0530242 centers->ext_center =
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700243 centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT);
Sujithf1dc5602008-10-29 10:16:30 +0530244}
245
246/******************/
247/* Chip Revisions */
248/******************/
249
Sujithcbe61d82009-02-09 13:27:12 +0530250static void ath9k_hw_read_revisions(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530251{
252 u32 val;
253
254 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
255
256 if (val == 0xFF) {
257 val = REG_READ(ah, AR_SREV);
Sujithd535a422009-02-09 13:27:06 +0530258 ah->hw_version.macVersion =
259 (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
260 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
Sujith2660b812009-02-09 13:27:26 +0530261 ah->is_pciexpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
Sujithf1dc5602008-10-29 10:16:30 +0530262 } else {
263 if (!AR_SREV_9100(ah))
Sujithd535a422009-02-09 13:27:06 +0530264 ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
Sujithf1dc5602008-10-29 10:16:30 +0530265
Sujithd535a422009-02-09 13:27:06 +0530266 ah->hw_version.macRev = val & AR_SREV_REVISION;
Sujithf1dc5602008-10-29 10:16:30 +0530267
Sujithd535a422009-02-09 13:27:06 +0530268 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
Sujith2660b812009-02-09 13:27:26 +0530269 ah->is_pciexpress = true;
Sujithf1dc5602008-10-29 10:16:30 +0530270 }
271}
272
Sujithf1dc5602008-10-29 10:16:30 +0530273/************************************/
274/* HW Attach, Detach, Init Routines */
275/************************************/
276
Sujithcbe61d82009-02-09 13:27:12 +0530277static void ath9k_hw_disablepcie(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530278{
Sujithfeed0292009-01-29 11:37:35 +0530279 if (AR_SREV_9100(ah))
Sujithf1dc5602008-10-29 10:16:30 +0530280 return;
281
Sujith7d0d0df2010-04-16 11:53:57 +0530282 ENABLE_REGWRITE_BUFFER(ah);
283
Sujithf1dc5602008-10-29 10:16:30 +0530284 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);
Sujith7d0d0df2010-04-16 11:53:57 +0530295
296 REGWRITE_BUFFER_FLUSH(ah);
297 DISABLE_REGWRITE_BUFFER(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530298}
299
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400300/* This should work for all families including legacy */
Sujithcbe61d82009-02-09 13:27:12 +0530301static bool ath9k_hw_chip_test(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530302{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700303 struct ath_common *common = ath9k_hw_common(ah);
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400304 u32 regAddr[2] = { AR_STA_ID0 };
Sujithf1dc5602008-10-29 10:16:30 +0530305 u32 regHold[2];
306 u32 patternData[4] = { 0x55555555,
307 0xaaaaaaaa,
308 0x66666666,
309 0x99999999 };
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400310 int i, j, loop_max;
Sujithf1dc5602008-10-29 10:16:30 +0530311
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400312 if (!AR_SREV_9300_20_OR_LATER(ah)) {
313 loop_max = 2;
314 regAddr[1] = AR_PHY_BASE + (8 << 2);
315 } else
316 loop_max = 1;
317
318 for (i = 0; i < loop_max; i++) {
Sujithf1dc5602008-10-29 10:16:30 +0530319 u32 addr = regAddr[i];
320 u32 wrData, rdData;
321
322 regHold[i] = REG_READ(ah, addr);
323 for (j = 0; j < 0x100; j++) {
324 wrData = (j << 16) | j;
325 REG_WRITE(ah, addr, wrData);
326 rdData = REG_READ(ah, addr);
327 if (rdData != wrData) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700328 ath_print(common, ATH_DBG_FATAL,
329 "address test failed "
330 "addr: 0x%08x - wr:0x%08x != "
331 "rd:0x%08x\n",
332 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530333 return false;
334 }
335 }
336 for (j = 0; j < 4; j++) {
337 wrData = patternData[j];
338 REG_WRITE(ah, addr, wrData);
339 rdData = REG_READ(ah, addr);
340 if (wrData != rdData) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700341 ath_print(common, ATH_DBG_FATAL,
342 "address test failed "
343 "addr: 0x%08x - wr:0x%08x != "
344 "rd:0x%08x\n",
345 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530346 return false;
347 }
348 }
349 REG_WRITE(ah, regAddr[i], regHold[i]);
350 }
351 udelay(100);
Sujithcbe61d82009-02-09 13:27:12 +0530352
Sujithf1dc5602008-10-29 10:16:30 +0530353 return true;
354}
355
Luis R. Rodriguezb8b0f372009-08-03 12:24:43 -0700356static void ath9k_hw_init_config(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700357{
358 int i;
359
Sujith2660b812009-02-09 13:27:26 +0530360 ah->config.dma_beacon_response_time = 2;
361 ah->config.sw_beacon_response_time = 10;
362 ah->config.additional_swba_backoff = 0;
363 ah->config.ack_6mb = 0x0;
364 ah->config.cwm_ignore_extcca = 0;
365 ah->config.pcie_powersave_enable = 0;
Sujith2660b812009-02-09 13:27:26 +0530366 ah->config.pcie_clock_req = 0;
Sujith2660b812009-02-09 13:27:26 +0530367 ah->config.pcie_waen = 0;
368 ah->config.analog_shiftreg = 1;
Sujith2660b812009-02-09 13:27:26 +0530369 ah->config.ofdm_trig_low = 200;
370 ah->config.ofdm_trig_high = 500;
371 ah->config.cck_trig_high = 200;
372 ah->config.cck_trig_low = 100;
Luis R. Rodriguez31a0bd32010-04-15 17:38:22 -0400373
374 /*
375 * For now ANI is disabled for AR9003, it is still
376 * being tested.
377 */
378 if (!AR_SREV_9300_20_OR_LATER(ah))
379 ah->config.enable_ani = 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700380
381 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujith2660b812009-02-09 13:27:26 +0530382 ah->config.spurchans[i][0] = AR_NO_SPUR;
383 ah->config.spurchans[i][1] = AR_NO_SPUR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700384 }
385
Luis R. Rodriguez5ffaf8a2010-02-02 11:58:33 -0500386 if (ah->hw_version.devid != AR2427_DEVID_PCIE)
387 ah->config.ht_enable = 1;
388 else
389 ah->config.ht_enable = 0;
390
Sujith0ce024c2009-12-14 14:57:00 +0530391 ah->config.rx_intr_mitigation = true;
Luis R. Rodriguez61584252009-03-12 18:18:49 -0400392
393 /*
Luis R. Rodriguezb360a882010-04-26 15:04:32 -0400394 * Tx IQ Calibration (ah->config.tx_iq_calibration) is only
395 * used by AR9003, but it is showing reliability issues.
396 * It will take a while to fix so this is currently disabled.
397 */
398
399 /*
Luis R. Rodriguez61584252009-03-12 18:18:49 -0400400 * We need this for PCI devices only (Cardbus, PCI, miniPCI)
401 * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
402 * This means we use it for all AR5416 devices, and the few
403 * minor PCI AR9280 devices out there.
404 *
405 * Serialization is required because these devices do not handle
406 * well the case of two concurrent reads/writes due to the latency
407 * involved. During one read/write another read/write can be issued
408 * on another CPU while the previous read/write may still be working
409 * on our hardware, if we hit this case the hardware poops in a loop.
410 * We prevent this by serializing reads and writes.
411 *
412 * This issue is not present on PCI-Express devices or pre-AR5416
413 * devices (legacy, 802.11abg).
414 */
415 if (num_possible_cpus() > 1)
David S. Miller2d6a5e92009-03-17 15:01:30 -0700416 ah->config.serialize_regmode = SER_REG_MODE_AUTO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700417}
418
Luis R. Rodriguez50aca252009-08-03 12:24:42 -0700419static void ath9k_hw_init_defaults(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700420{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700421 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
422
423 regulatory->country_code = CTRY_DEFAULT;
424 regulatory->power_limit = MAX_RATE_POWER;
425 regulatory->tp_scale = ATH9K_TP_SCALE_MAX;
426
Sujithd535a422009-02-09 13:27:06 +0530427 ah->hw_version.magic = AR5416_MAGIC;
Sujithd535a422009-02-09 13:27:06 +0530428 ah->hw_version.subvendorid = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700429
430 ah->ah_flags = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700431 if (!AR_SREV_9100(ah))
432 ah->ah_flags = AH_USE_EEPROM;
433
Sujith2660b812009-02-09 13:27:26 +0530434 ah->atim_window = 0;
Sujith2660b812009-02-09 13:27:26 +0530435 ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
436 ah->beacon_interval = 100;
437 ah->enable_32kHz_clock = DONT_USE_32KHZ;
438 ah->slottime = (u32) -1;
Sujith2660b812009-02-09 13:27:26 +0530439 ah->globaltxtimeout = (u32) -1;
Gabor Juhoscbdec972009-07-24 17:27:22 +0200440 ah->power_mode = ATH9K_PM_UNDEFINED;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700441}
442
Sujithcbe61d82009-02-09 13:27:12 +0530443static int ath9k_hw_init_macaddr(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700444{
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700445 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530446 u32 sum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700447 int i;
Sujithf1dc5602008-10-29 10:16:30 +0530448 u16 eeval;
Luis R. Rodriguez49101672010-04-15 17:39:13 -0400449 u32 EEP_MAC[] = { EEP_MAC_LSW, EEP_MAC_MID, EEP_MAC_MSW };
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700450
Sujithf1dc5602008-10-29 10:16:30 +0530451 sum = 0;
452 for (i = 0; i < 3; i++) {
Luis R. Rodriguez49101672010-04-15 17:39:13 -0400453 eeval = ah->eep_ops->get_eeprom(ah, EEP_MAC[i]);
Sujithf1dc5602008-10-29 10:16:30 +0530454 sum += eeval;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700455 common->macaddr[2 * i] = eeval >> 8;
456 common->macaddr[2 * i + 1] = eeval & 0xff;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700457 }
Sujithd8baa932009-03-30 15:28:25 +0530458 if (sum == 0 || sum == 0xffff * 3)
Sujithf1dc5602008-10-29 10:16:30 +0530459 return -EADDRNOTAVAIL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700460
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700461 return 0;
462}
463
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700464static int ath9k_hw_post_init(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700465{
466 int ecode;
467
Sujith527d4852010-03-17 14:25:16 +0530468 if (!AR_SREV_9271(ah)) {
469 if (!ath9k_hw_chip_test(ah))
470 return -ENODEV;
471 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700472
Luis R. Rodriguezebd5a142010-04-15 17:39:18 -0400473 if (!AR_SREV_9300_20_OR_LATER(ah)) {
474 ecode = ar9002_hw_rf_claim(ah);
475 if (ecode != 0)
476 return ecode;
477 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700478
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700479 ecode = ath9k_hw_eeprom_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700480 if (ecode != 0)
481 return ecode;
Sujith7d01b222009-03-13 08:55:55 +0530482
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700483 ath_print(ath9k_hw_common(ah), ATH_DBG_CONFIG,
484 "Eeprom VER: %d, REV: %d\n",
485 ah->eep_ops->get_eeprom_ver(ah),
486 ah->eep_ops->get_eeprom_rev(ah));
Sujith7d01b222009-03-13 08:55:55 +0530487
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400488 ecode = ath9k_hw_rf_alloc_ext_banks(ah);
489 if (ecode) {
490 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
491 "Failed allocating banks for "
492 "external radio\n");
493 return ecode;
Luis R. Rodriguez574d6b12009-10-19 02:33:37 -0400494 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700495
496 if (!AR_SREV_9100(ah)) {
497 ath9k_hw_ani_setup(ah);
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700498 ath9k_hw_ani_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700499 }
Sujithf1dc5602008-10-29 10:16:30 +0530500
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700501 return 0;
502}
503
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400504static void ath9k_hw_attach_ops(struct ath_hw *ah)
505{
506 if (AR_SREV_9300_20_OR_LATER(ah))
507 ar9003_hw_attach_ops(ah);
508 else
509 ar9002_hw_attach_ops(ah);
510}
511
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400512/* Called for all hardware families */
513static int __ath9k_hw_init(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700514{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700515 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700516 int r = 0;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700517
Luis R. Rodriguezbab1f622010-04-15 17:38:20 -0400518 if (ah->hw_version.devid == AR5416_AR9100_DEVID)
519 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700520
521 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700522 ath_print(common, ATH_DBG_FATAL,
523 "Couldn't reset chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700524 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700525 }
526
Luis R. Rodriguezbab1f622010-04-15 17:38:20 -0400527 ath9k_hw_init_defaults(ah);
528 ath9k_hw_init_config(ah);
529
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400530 ath9k_hw_attach_ops(ah);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400531
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700532 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700533 ath_print(common, ATH_DBG_FATAL, "Couldn't wakeup chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700534 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700535 }
536
537 if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
538 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
539 (AR_SREV_9280(ah) && !ah->is_pciexpress)) {
540 ah->config.serialize_regmode =
541 SER_REG_MODE_ON;
542 } else {
543 ah->config.serialize_regmode =
544 SER_REG_MODE_OFF;
545 }
546 }
547
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700548 ath_print(common, ATH_DBG_RESET, "serialize_regmode is %d\n",
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700549 ah->config.serialize_regmode);
550
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -0500551 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
552 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD >> 1;
553 else
554 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD;
555
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400556 if (!ath9k_hw_macversion_supported(ah)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700557 ath_print(common, ATH_DBG_FATAL,
558 "Mac Chip Rev 0x%02x.%x is not supported by "
559 "this driver\n", ah->hw_version.macVersion,
560 ah->hw_version.macRev);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700561 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700562 }
563
Luis R. Rodriguez0df13da2010-04-15 17:38:59 -0400564 if (AR_SREV_9271(ah) || AR_SREV_9100(ah))
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400565 ah->is_pciexpress = false;
566
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700567 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700568 ath9k_hw_init_cal_settings(ah);
569
570 ah->ani_function = ATH9K_ANI_ALL;
Luis R. Rodriguez31a0bd32010-04-15 17:38:22 -0400571 if (AR_SREV_9280_10_OR_LATER(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700572 ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
573
574 ath9k_hw_init_mode_regs(ah);
575
576 if (ah->is_pciexpress)
Vivek Natarajan93b1b372009-09-17 09:24:58 +0530577 ath9k_hw_configpcipowersave(ah, 0, 0);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700578 else
579 ath9k_hw_disablepcie(ah);
580
Luis R. Rodriguezd8f492b2010-04-15 17:39:04 -0400581 if (!AR_SREV_9300_20_OR_LATER(ah))
582 ar9002_hw_cck_chan14_spread(ah);
Sujith193cd452009-09-18 15:04:07 +0530583
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700584 r = ath9k_hw_post_init(ah);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700585 if (r)
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700586 return r;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700587
588 ath9k_hw_init_mode_gain_regs(ah);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +0100589 r = ath9k_hw_fill_cap_info(ah);
590 if (r)
591 return r;
592
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700593 r = ath9k_hw_init_macaddr(ah);
594 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700595 ath_print(common, ATH_DBG_FATAL,
596 "Failed to initialize MAC address\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700597 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700598 }
599
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400600 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
Sujith2660b812009-02-09 13:27:26 +0530601 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700602 else
Sujith2660b812009-02-09 13:27:26 +0530603 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700604
Felix Fietkau641d9922010-04-15 17:38:49 -0400605 if (AR_SREV_9300_20_OR_LATER(ah))
606 ar9003_hw_set_nf_limits(ah);
607
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700608 ath9k_init_nfcal_hist_buffer(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700609
Luis R. Rodriguez211f5852009-10-06 21:19:07 -0400610 common->state = ATH_HW_INITIALIZED;
611
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700612 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700613}
614
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400615int ath9k_hw_init(struct ath_hw *ah)
616{
617 int ret;
618 struct ath_common *common = ath9k_hw_common(ah);
619
620 /* These are all the AR5008/AR9001/AR9002 hardware family of chipsets */
621 switch (ah->hw_version.devid) {
622 case AR5416_DEVID_PCI:
623 case AR5416_DEVID_PCIE:
624 case AR5416_AR9100_DEVID:
625 case AR9160_DEVID_PCI:
626 case AR9280_DEVID_PCI:
627 case AR9280_DEVID_PCIE:
628 case AR9285_DEVID_PCIE:
Senthil Balasubramaniandb3cc532010-04-15 17:38:18 -0400629 case AR9287_DEVID_PCI:
630 case AR9287_DEVID_PCIE:
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400631 case AR2427_DEVID_PCIE:
Senthil Balasubramaniandb3cc532010-04-15 17:38:18 -0400632 case AR9300_DEVID_PCIE:
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400633 break;
634 default:
635 if (common->bus_ops->ath_bus_type == ATH_USB)
636 break;
637 ath_print(common, ATH_DBG_FATAL,
638 "Hardware device ID 0x%04x not supported\n",
639 ah->hw_version.devid);
640 return -EOPNOTSUPP;
641 }
642
643 ret = __ath9k_hw_init(ah);
644 if (ret) {
645 ath_print(common, ATH_DBG_FATAL,
646 "Unable to initialize hardware; "
647 "initialization status: %d\n", ret);
648 return ret;
649 }
650
651 return 0;
652}
653EXPORT_SYMBOL(ath9k_hw_init);
654
Sujithcbe61d82009-02-09 13:27:12 +0530655static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530656{
Sujith7d0d0df2010-04-16 11:53:57 +0530657 ENABLE_REGWRITE_BUFFER(ah);
658
Sujithf1dc5602008-10-29 10:16:30 +0530659 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
660 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
661
662 REG_WRITE(ah, AR_QOS_NO_ACK,
663 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
664 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
665 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
666
667 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
668 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
669 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
670 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
671 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
Sujith7d0d0df2010-04-16 11:53:57 +0530672
673 REGWRITE_BUFFER_FLUSH(ah);
674 DISABLE_REGWRITE_BUFFER(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530675}
676
Sujithcbe61d82009-02-09 13:27:12 +0530677static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530678 struct ath9k_channel *chan)
679{
Luis R. Rodriguez64773962010-04-15 17:38:17 -0400680 u32 pll = ath9k_hw_compute_pll_control(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +0530681
Gabor Juhosd03a66c2009-01-14 20:17:09 +0100682 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +0530683
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -0400684 /* Switch the core clock for ar9271 to 117Mhz */
685 if (AR_SREV_9271(ah)) {
Sujith25e2ab12010-03-17 14:25:22 +0530686 udelay(500);
687 REG_WRITE(ah, 0x50040, 0x304);
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -0400688 }
689
Sujithf1dc5602008-10-29 10:16:30 +0530690 udelay(RTC_PLL_SETTLE_DELAY);
691
692 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
693}
694
Sujithcbe61d82009-02-09 13:27:12 +0530695static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -0800696 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +0530697{
Pavel Roskin152d5302010-03-31 18:05:37 -0400698 u32 imr_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +0530699 AR_IMR_TXURN |
700 AR_IMR_RXERR |
701 AR_IMR_RXORN |
702 AR_IMR_BCNMISC;
703
Vasanthakumar Thiagarajan66860242010-04-15 17:39:07 -0400704 if (AR_SREV_9300_20_OR_LATER(ah)) {
705 imr_reg |= AR_IMR_RXOK_HP;
706 if (ah->config.rx_intr_mitigation)
707 imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
708 else
709 imr_reg |= AR_IMR_RXOK_LP;
Sujithf1dc5602008-10-29 10:16:30 +0530710
Vasanthakumar Thiagarajan66860242010-04-15 17:39:07 -0400711 } else {
712 if (ah->config.rx_intr_mitigation)
713 imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
714 else
715 imr_reg |= AR_IMR_RXOK;
716 }
717
718 if (ah->config.tx_intr_mitigation)
719 imr_reg |= AR_IMR_TXINTM | AR_IMR_TXMINTR;
720 else
721 imr_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +0530722
Colin McCabed97809d2008-12-01 13:38:55 -0800723 if (opmode == NL80211_IFTYPE_AP)
Pavel Roskin152d5302010-03-31 18:05:37 -0400724 imr_reg |= AR_IMR_MIB;
Sujithf1dc5602008-10-29 10:16:30 +0530725
Sujith7d0d0df2010-04-16 11:53:57 +0530726 ENABLE_REGWRITE_BUFFER(ah);
727
Pavel Roskin152d5302010-03-31 18:05:37 -0400728 REG_WRITE(ah, AR_IMR, imr_reg);
Pavel Roskin74bad5c2010-02-23 18:15:27 -0500729 ah->imrs2_reg |= AR_IMR_S2_GTT;
730 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
Sujithf1dc5602008-10-29 10:16:30 +0530731
732 if (!AR_SREV_9100(ah)) {
733 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
734 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
735 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
736 }
Vasanthakumar Thiagarajan66860242010-04-15 17:39:07 -0400737
Sujith7d0d0df2010-04-16 11:53:57 +0530738 REGWRITE_BUFFER_FLUSH(ah);
739 DISABLE_REGWRITE_BUFFER(ah);
740
Vasanthakumar Thiagarajan66860242010-04-15 17:39:07 -0400741 if (AR_SREV_9300_20_OR_LATER(ah)) {
742 REG_WRITE(ah, AR_INTR_PRIO_ASYNC_ENABLE, 0);
743 REG_WRITE(ah, AR_INTR_PRIO_ASYNC_MASK, 0);
744 REG_WRITE(ah, AR_INTR_PRIO_SYNC_ENABLE, 0);
745 REG_WRITE(ah, AR_INTR_PRIO_SYNC_MASK, 0);
746 }
Sujithf1dc5602008-10-29 10:16:30 +0530747}
748
Felix Fietkau0005baf2010-01-15 02:33:40 +0100749static void ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +0530750{
Felix Fietkau0005baf2010-01-15 02:33:40 +0100751 u32 val = ath9k_hw_mac_to_clks(ah, us);
752 val = min(val, (u32) 0xFFFF);
753 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, val);
Sujithf1dc5602008-10-29 10:16:30 +0530754}
755
Felix Fietkau0005baf2010-01-15 02:33:40 +0100756static void ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +0530757{
Felix Fietkau0005baf2010-01-15 02:33:40 +0100758 u32 val = ath9k_hw_mac_to_clks(ah, us);
759 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_ACK));
760 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_ACK, val);
761}
762
763static void ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
764{
765 u32 val = ath9k_hw_mac_to_clks(ah, us);
766 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_CTS));
767 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_CTS, val);
Sujithf1dc5602008-10-29 10:16:30 +0530768}
769
Sujithcbe61d82009-02-09 13:27:12 +0530770static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +0530771{
Sujithf1dc5602008-10-29 10:16:30 +0530772 if (tu > 0xFFFF) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700773 ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT,
774 "bad global tx timeout %u\n", tu);
Sujith2660b812009-02-09 13:27:26 +0530775 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +0530776 return false;
777 } else {
778 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +0530779 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +0530780 return true;
781 }
782}
783
Felix Fietkau0005baf2010-01-15 02:33:40 +0100784void ath9k_hw_init_global_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530785{
Felix Fietkau0005baf2010-01-15 02:33:40 +0100786 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
787 int acktimeout;
Felix Fietkaue239d852010-01-15 02:34:58 +0100788 int slottime;
Felix Fietkau0005baf2010-01-15 02:33:40 +0100789 int sifstime;
790
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700791 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
792 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +0530793
Sujith2660b812009-02-09 13:27:26 +0530794 if (ah->misc_mode != 0)
Sujithf1dc5602008-10-29 10:16:30 +0530795 REG_WRITE(ah, AR_PCU_MISC,
Sujith2660b812009-02-09 13:27:26 +0530796 REG_READ(ah, AR_PCU_MISC) | ah->misc_mode);
Felix Fietkau0005baf2010-01-15 02:33:40 +0100797
798 if (conf->channel && conf->channel->band == IEEE80211_BAND_5GHZ)
799 sifstime = 16;
800 else
801 sifstime = 10;
802
Felix Fietkaue239d852010-01-15 02:34:58 +0100803 /* As defined by IEEE 802.11-2007 17.3.8.6 */
804 slottime = ah->slottime + 3 * ah->coverage_class;
805 acktimeout = slottime + sifstime;
Felix Fietkau42c45682010-02-11 18:07:19 +0100806
807 /*
808 * Workaround for early ACK timeouts, add an offset to match the
809 * initval's 64us ack timeout value.
810 * This was initially only meant to work around an issue with delayed
811 * BA frames in some implementations, but it has been found to fix ACK
812 * timeout issues in other cases as well.
813 */
814 if (conf->channel && conf->channel->band == IEEE80211_BAND_2GHZ)
815 acktimeout += 64 - sifstime - ah->slottime;
816
Felix Fietkaue239d852010-01-15 02:34:58 +0100817 ath9k_hw_setslottime(ah, slottime);
Felix Fietkau0005baf2010-01-15 02:33:40 +0100818 ath9k_hw_set_ack_timeout(ah, acktimeout);
819 ath9k_hw_set_cts_timeout(ah, acktimeout);
Sujith2660b812009-02-09 13:27:26 +0530820 if (ah->globaltxtimeout != (u32) -1)
821 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Sujithf1dc5602008-10-29 10:16:30 +0530822}
Felix Fietkau0005baf2010-01-15 02:33:40 +0100823EXPORT_SYMBOL(ath9k_hw_init_global_settings);
Sujithf1dc5602008-10-29 10:16:30 +0530824
Sujith285f2dd2010-01-08 10:36:07 +0530825void ath9k_hw_deinit(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700826{
Luis R. Rodriguez211f5852009-10-06 21:19:07 -0400827 struct ath_common *common = ath9k_hw_common(ah);
828
Sujith736b3a22010-03-17 14:25:24 +0530829 if (common->state < ATH_HW_INITIALIZED)
Luis R. Rodriguez211f5852009-10-06 21:19:07 -0400830 goto free_hw;
831
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700832 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Luis R. Rodriguez211f5852009-10-06 21:19:07 -0400833
834free_hw:
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400835 ath9k_hw_rf_free_ext_banks(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700836}
Sujith285f2dd2010-01-08 10:36:07 +0530837EXPORT_SYMBOL(ath9k_hw_deinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700838
Sujithf1dc5602008-10-29 10:16:30 +0530839/*******/
840/* INI */
841/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700842
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400843u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan)
Bob Copeland3a702e42009-03-30 22:30:29 -0400844{
845 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
846
847 if (IS_CHAN_B(chan))
848 ctl |= CTL_11B;
849 else if (IS_CHAN_G(chan))
850 ctl |= CTL_11G;
851 else
852 ctl |= CTL_11A;
853
854 return ctl;
855}
856
Sujithf1dc5602008-10-29 10:16:30 +0530857/****************************************/
858/* Reset and Channel Switching Routines */
859/****************************************/
860
Sujithcbe61d82009-02-09 13:27:12 +0530861static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530862{
Felix Fietkau57b32222010-04-15 17:39:22 -0400863 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530864 u32 regval;
865
Sujith7d0d0df2010-04-16 11:53:57 +0530866 ENABLE_REGWRITE_BUFFER(ah);
867
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400868 /*
869 * set AHB_MODE not to do cacheline prefetches
870 */
Felix Fietkau57b32222010-04-15 17:39:22 -0400871 if (!AR_SREV_9300_20_OR_LATER(ah)) {
872 regval = REG_READ(ah, AR_AHB_MODE);
873 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
874 }
Sujithf1dc5602008-10-29 10:16:30 +0530875
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400876 /*
877 * let mac dma reads be in 128 byte chunks
878 */
Sujithf1dc5602008-10-29 10:16:30 +0530879 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
880 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
881
Sujith7d0d0df2010-04-16 11:53:57 +0530882 REGWRITE_BUFFER_FLUSH(ah);
883 DISABLE_REGWRITE_BUFFER(ah);
884
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400885 /*
886 * Restore TX Trigger Level to its pre-reset value.
887 * The initial value depends on whether aggregation is enabled, and is
888 * adjusted whenever underruns are detected.
889 */
Felix Fietkau57b32222010-04-15 17:39:22 -0400890 if (!AR_SREV_9300_20_OR_LATER(ah))
891 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +0530892
Sujith7d0d0df2010-04-16 11:53:57 +0530893 ENABLE_REGWRITE_BUFFER(ah);
894
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400895 /*
896 * let mac dma writes be in 128 byte chunks
897 */
Sujithf1dc5602008-10-29 10:16:30 +0530898 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
899 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
900
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400901 /*
902 * Setup receive FIFO threshold to hold off TX activities
903 */
Sujithf1dc5602008-10-29 10:16:30 +0530904 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
905
Felix Fietkau57b32222010-04-15 17:39:22 -0400906 if (AR_SREV_9300_20_OR_LATER(ah)) {
907 REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_HP, 0x1);
908 REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_LP, 0x1);
909
910 ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize -
911 ah->caps.rx_status_len);
912 }
913
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400914 /*
915 * reduce the number of usable entries in PCU TXBUF to avoid
916 * wrap around issues.
917 */
Sujithf1dc5602008-10-29 10:16:30 +0530918 if (AR_SREV_9285(ah)) {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400919 /* For AR9285 the number of Fifos are reduced to half.
920 * So set the usable tx buf size also to half to
921 * avoid data/delimiter underruns
922 */
Sujithf1dc5602008-10-29 10:16:30 +0530923 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
924 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400925 } else if (!AR_SREV_9271(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +0530926 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
927 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
928 }
Vasanthakumar Thiagarajan744d4022010-04-15 17:39:27 -0400929
Sujith7d0d0df2010-04-16 11:53:57 +0530930 REGWRITE_BUFFER_FLUSH(ah);
931 DISABLE_REGWRITE_BUFFER(ah);
932
Vasanthakumar Thiagarajan744d4022010-04-15 17:39:27 -0400933 if (AR_SREV_9300_20_OR_LATER(ah))
934 ath9k_hw_reset_txstatus_ring(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530935}
936
Sujithcbe61d82009-02-09 13:27:12 +0530937static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +0530938{
939 u32 val;
940
941 val = REG_READ(ah, AR_STA_ID1);
942 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
943 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -0800944 case NL80211_IFTYPE_AP:
Sujithf1dc5602008-10-29 10:16:30 +0530945 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
946 | AR_STA_ID1_KSRCH_MODE);
947 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
948 break;
Colin McCabed97809d2008-12-01 13:38:55 -0800949 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -0400950 case NL80211_IFTYPE_MESH_POINT:
Sujithf1dc5602008-10-29 10:16:30 +0530951 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
952 | AR_STA_ID1_KSRCH_MODE);
953 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
954 break;
Colin McCabed97809d2008-12-01 13:38:55 -0800955 case NL80211_IFTYPE_STATION:
956 case NL80211_IFTYPE_MONITOR:
Sujithf1dc5602008-10-29 10:16:30 +0530957 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
958 break;
959 }
960}
961
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400962void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled,
963 u32 *coef_mantissa, u32 *coef_exponent)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700964{
965 u32 coef_exp, coef_man;
966
967 for (coef_exp = 31; coef_exp > 0; coef_exp--)
968 if ((coef_scaled >> coef_exp) & 0x1)
969 break;
970
971 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
972
973 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
974
975 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
976 *coef_exponent = coef_exp - 16;
977}
978
Sujithcbe61d82009-02-09 13:27:12 +0530979static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +0530980{
981 u32 rst_flags;
982 u32 tmpReg;
983
Sujith70768492009-02-16 13:23:12 +0530984 if (AR_SREV_9100(ah)) {
985 u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK);
986 val &= ~AR_RTC_DERIVED_CLK_PERIOD;
987 val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD);
988 REG_WRITE(ah, AR_RTC_DERIVED_CLK, val);
989 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
990 }
991
Sujith7d0d0df2010-04-16 11:53:57 +0530992 ENABLE_REGWRITE_BUFFER(ah);
993
Sujithf1dc5602008-10-29 10:16:30 +0530994 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
995 AR_RTC_FORCE_WAKE_ON_INT);
996
997 if (AR_SREV_9100(ah)) {
998 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
999 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1000 } else {
1001 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1002 if (tmpReg &
1003 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1004 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001005 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05301006 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001007
1008 val = AR_RC_HOSTIF;
1009 if (!AR_SREV_9300_20_OR_LATER(ah))
1010 val |= AR_RC_AHB;
1011 REG_WRITE(ah, AR_RC, val);
1012
1013 } else if (!AR_SREV_9300_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05301014 REG_WRITE(ah, AR_RC, AR_RC_AHB);
Sujithf1dc5602008-10-29 10:16:30 +05301015
1016 rst_flags = AR_RTC_RC_MAC_WARM;
1017 if (type == ATH9K_RESET_COLD)
1018 rst_flags |= AR_RTC_RC_MAC_COLD;
1019 }
1020
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001021 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujith7d0d0df2010-04-16 11:53:57 +05301022
1023 REGWRITE_BUFFER_FLUSH(ah);
1024 DISABLE_REGWRITE_BUFFER(ah);
1025
Sujithf1dc5602008-10-29 10:16:30 +05301026 udelay(50);
1027
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001028 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301029 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001030 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1031 "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301032 return false;
1033 }
1034
1035 if (!AR_SREV_9100(ah))
1036 REG_WRITE(ah, AR_RC, 0);
1037
Sujithf1dc5602008-10-29 10:16:30 +05301038 if (AR_SREV_9100(ah))
1039 udelay(50);
1040
1041 return true;
1042}
1043
Sujithcbe61d82009-02-09 13:27:12 +05301044static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301045{
Sujith7d0d0df2010-04-16 11:53:57 +05301046 ENABLE_REGWRITE_BUFFER(ah);
1047
Sujithf1dc5602008-10-29 10:16:30 +05301048 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1049 AR_RTC_FORCE_WAKE_ON_INT);
1050
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001051 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301052 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1053
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001054 REG_WRITE(ah, AR_RTC_RESET, 0);
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301055
Sujith7d0d0df2010-04-16 11:53:57 +05301056 REGWRITE_BUFFER_FLUSH(ah);
1057 DISABLE_REGWRITE_BUFFER(ah);
1058
Senthil Balasubramanian84e21692010-04-15 17:38:30 -04001059 if (!AR_SREV_9300_20_OR_LATER(ah))
1060 udelay(2);
1061
1062 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301063 REG_WRITE(ah, AR_RC, 0);
1064
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001065 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301066
1067 if (!ath9k_hw_wait(ah,
1068 AR_RTC_STATUS,
1069 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301070 AR_RTC_STATUS_ON,
1071 AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001072 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1073 "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301074 return false;
1075 }
1076
1077 ath9k_hw_read_revisions(ah);
1078
1079 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1080}
1081
Sujithcbe61d82009-02-09 13:27:12 +05301082static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301083{
1084 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1085 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1086
1087 switch (type) {
1088 case ATH9K_RESET_POWER_ON:
1089 return ath9k_hw_set_reset_power_on(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301090 case ATH9K_RESET_WARM:
1091 case ATH9K_RESET_COLD:
1092 return ath9k_hw_set_reset(ah, type);
Sujithf1dc5602008-10-29 10:16:30 +05301093 default:
1094 return false;
1095 }
1096}
1097
Sujithcbe61d82009-02-09 13:27:12 +05301098static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301099 struct ath9k_channel *chan)
1100{
Vivek Natarajan42abfbe2009-09-17 09:27:59 +05301101 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) {
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301102 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
1103 return false;
1104 } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
Sujithf1dc5602008-10-29 10:16:30 +05301105 return false;
1106
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001107 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05301108 return false;
1109
Sujith2660b812009-02-09 13:27:26 +05301110 ah->chip_fullsleep = false;
Sujithf1dc5602008-10-29 10:16:30 +05301111 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301112 ath9k_hw_set_rfmode(ah, chan);
1113
1114 return true;
1115}
1116
Sujithcbe61d82009-02-09 13:27:12 +05301117static bool ath9k_hw_channel_change(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001118 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301119{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001120 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001121 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001122 struct ieee80211_channel *channel = chan->chan;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001123 u32 qnum;
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001124 int r;
Sujithf1dc5602008-10-29 10:16:30 +05301125
1126 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1127 if (ath9k_hw_numtxpending(ah, qnum)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001128 ath_print(common, ATH_DBG_QUEUE,
1129 "Transmit frames pending on "
1130 "queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301131 return false;
1132 }
1133 }
1134
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001135 if (!ath9k_hw_rfbus_req(ah)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001136 ath_print(common, ATH_DBG_FATAL,
1137 "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301138 return false;
1139 }
1140
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001141 ath9k_hw_set_channel_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301142
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001143 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001144 if (r) {
1145 ath_print(common, ATH_DBG_FATAL,
1146 "Failed to set channel\n");
1147 return false;
Sujithf1dc5602008-10-29 10:16:30 +05301148 }
1149
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001150 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001151 ath9k_regd_get_ctl(regulatory, chan),
Sujithf74df6f2009-02-09 13:27:24 +05301152 channel->max_antenna_gain * 2,
1153 channel->max_power * 2,
1154 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001155 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05301156
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001157 ath9k_hw_rfbus_done(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301158
1159 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1160 ath9k_hw_set_delta_slope(ah, chan);
1161
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001162 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301163
1164 if (!chan->oneTimeCalsDone)
1165 chan->oneTimeCalsDone = true;
1166
1167 return true;
1168}
1169
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001170bool ath9k_hw_check_alive(struct ath_hw *ah)
1171{
1172 int count = 50;
1173 u32 reg;
1174
1175 if (AR_SREV_9285_10_OR_LATER(ah))
1176 return true;
1177
1178 do {
1179 reg = REG_READ(ah, AR_OBS_BUS_1);
1180
1181 if ((reg & 0x7E7FFFEF) == 0x00702400)
1182 continue;
1183
1184 switch (reg & 0x7E000B00) {
1185 case 0x1E000000:
1186 case 0x52000B00:
1187 case 0x18000B00:
1188 continue;
1189 default:
1190 return true;
1191 }
1192 } while (count-- > 0);
1193
1194 return false;
1195}
1196EXPORT_SYMBOL(ath9k_hw_check_alive);
1197
Sujithcbe61d82009-02-09 13:27:12 +05301198int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001199 bool bChannelChange)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001200{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001201 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001202 u32 saveLedState;
Sujith2660b812009-02-09 13:27:26 +05301203 struct ath9k_channel *curchan = ah->curchan;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001204 u32 saveDefAntenna;
1205 u32 macStaId1;
Sujith46fe7822009-09-17 09:25:25 +05301206 u64 tsf = 0;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001207 int i, r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001208
Luis R. Rodriguez43c27612009-09-13 21:07:07 -07001209 ah->txchainmask = common->tx_chainmask;
1210 ah->rxchainmask = common->rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001211
Vasanthakumar Thiagarajan9b9cc612010-04-15 17:39:41 -04001212 if (!ah->chip_fullsleep) {
1213 ath9k_hw_abortpcurecv(ah);
1214 if (!ath9k_hw_stopdmarecv(ah))
1215 ath_print(common, ATH_DBG_XMIT,
1216 "Failed to stop receive dma\n");
1217 }
1218
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001219 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001220 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001221
Vasanthakumar Thiagarajan9ebef7992009-09-17 09:26:44 +05301222 if (curchan && !ah->chip_fullsleep)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001223 ath9k_hw_getnf(ah, curchan);
1224
1225 if (bChannelChange &&
Sujith2660b812009-02-09 13:27:26 +05301226 (ah->chip_fullsleep != true) &&
1227 (ah->curchan != NULL) &&
1228 (chan->channel != ah->curchan->channel) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001229 ((chan->channelFlags & CHANNEL_ALL) ==
Sujith2660b812009-02-09 13:27:26 +05301230 (ah->curchan->channelFlags & CHANNEL_ALL)) &&
Felix Fietkau6b42e8d2010-04-26 15:04:35 -04001231 !AR_SREV_9280(ah)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001232
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001233 if (ath9k_hw_channel_change(ah, chan)) {
Sujith2660b812009-02-09 13:27:26 +05301234 ath9k_hw_loadnf(ah, ah->curchan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001235 ath9k_hw_start_nfcal(ah);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001236 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001237 }
1238 }
1239
1240 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
1241 if (saveDefAntenna == 0)
1242 saveDefAntenna = 1;
1243
1244 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
1245
Sujith46fe7822009-09-17 09:25:25 +05301246 /* For chips on which RTC reset is done, save TSF before it gets cleared */
1247 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1248 tsf = ath9k_hw_gettsf64(ah);
1249
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001250 saveLedState = REG_READ(ah, AR_CFG_LED) &
1251 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
1252 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
1253
1254 ath9k_hw_mark_phy_inactive(ah);
1255
Sujith05020d22010-03-17 14:25:23 +05301256 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001257 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1258 REG_WRITE(ah,
1259 AR9271_RESET_POWER_DOWN_CONTROL,
1260 AR9271_RADIO_RF_RST);
1261 udelay(50);
1262 }
1263
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001264 if (!ath9k_hw_chip_reset(ah, chan)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001265 ath_print(common, ATH_DBG_FATAL, "Chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001266 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001267 }
1268
Sujith05020d22010-03-17 14:25:23 +05301269 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001270 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1271 ah->htc_reset_init = false;
1272 REG_WRITE(ah,
1273 AR9271_RESET_POWER_DOWN_CONTROL,
1274 AR9271_GATE_MAC_CTL);
1275 udelay(50);
1276 }
1277
Sujith46fe7822009-09-17 09:25:25 +05301278 /* Restore TSF */
1279 if (tsf && AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1280 ath9k_hw_settsf64(ah, tsf);
1281
Vasanthakumar Thiagarajan369391d2009-01-21 19:24:13 +05301282 if (AR_SREV_9280_10_OR_LATER(ah))
1283 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001284
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001285 r = ath9k_hw_process_ini(ah, chan);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001286 if (r)
1287 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001288
Jouni Malinen0ced0e12009-01-08 13:32:13 +02001289 /* Setup MFP options for CCMP */
1290 if (AR_SREV_9280_20_OR_LATER(ah)) {
1291 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
1292 * frames when constructing CCMP AAD. */
1293 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
1294 0xc7ff);
1295 ah->sw_mgmt_crypto = false;
1296 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1297 /* Disable hardware crypto for management frames */
1298 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
1299 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
1300 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1301 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
1302 ah->sw_mgmt_crypto = true;
1303 } else
1304 ah->sw_mgmt_crypto = true;
1305
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001306 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1307 ath9k_hw_set_delta_slope(ah, chan);
1308
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001309 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithd6509152009-03-13 08:56:05 +05301310 ah->eep_ops->set_board_values(ah, chan);
Luis R. Rodrigueza7765822009-10-19 02:33:45 -04001311
Sujith6819d572010-04-16 11:53:56 +05301312 ath9k_hw_set_operating_mode(ah, ah->opmode);
1313
Sujith7d0d0df2010-04-16 11:53:57 +05301314 ENABLE_REGWRITE_BUFFER(ah);
1315
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001316 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
1317 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001318 | macStaId1
1319 | AR_STA_ID1_RTS_USE_DEF
Sujith2660b812009-02-09 13:27:26 +05301320 | (ah->config.
Sujith60b67f52008-08-07 10:52:38 +05301321 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Sujith2660b812009-02-09 13:27:26 +05301322 | ah->sta_id1_defaults);
Luis R. Rodriguez13b81552009-09-10 17:52:45 -07001323 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001324 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
Luis R. Rodriguez3453ad82009-09-10 08:57:00 -07001325 ath9k_hw_write_associd(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001326 REG_WRITE(ah, AR_ISR, ~0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001327 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
1328
Sujith7d0d0df2010-04-16 11:53:57 +05301329 REGWRITE_BUFFER_FLUSH(ah);
1330 DISABLE_REGWRITE_BUFFER(ah);
1331
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001332 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001333 if (r)
1334 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001335
Sujith7d0d0df2010-04-16 11:53:57 +05301336 ENABLE_REGWRITE_BUFFER(ah);
1337
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001338 for (i = 0; i < AR_NUM_DCU; i++)
1339 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
1340
Sujith7d0d0df2010-04-16 11:53:57 +05301341 REGWRITE_BUFFER_FLUSH(ah);
1342 DISABLE_REGWRITE_BUFFER(ah);
1343
Sujith2660b812009-02-09 13:27:26 +05301344 ah->intr_txqs = 0;
1345 for (i = 0; i < ah->caps.total_queues; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001346 ath9k_hw_resettxqueue(ah, i);
1347
Sujith2660b812009-02-09 13:27:26 +05301348 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001349 ath9k_hw_init_qos(ah);
1350
Sujith2660b812009-02-09 13:27:26 +05301351 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301352 ath9k_enable_rfkill(ah);
Johannes Berg3b319aa2009-06-13 14:50:26 +05301353
Felix Fietkau0005baf2010-01-15 02:33:40 +01001354 ath9k_hw_init_global_settings(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001355
Luis R. Rodriguez6c94fdc2010-04-15 17:39:24 -04001356 if (!AR_SREV_9300_20_OR_LATER(ah)) {
Luis R. Rodriguez78ec2672010-04-15 17:39:23 -04001357 ar9002_hw_enable_async_fifo(ah);
Luis R. Rodriguez6c94fdc2010-04-15 17:39:24 -04001358 ar9002_hw_enable_wep_aggregation(ah);
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301359 }
1360
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001361 REG_WRITE(ah, AR_STA_ID1,
1362 REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
1363
1364 ath9k_hw_set_dma(ah);
1365
1366 REG_WRITE(ah, AR_OBS, 8);
1367
Sujith0ce024c2009-12-14 14:57:00 +05301368 if (ah->config.rx_intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001369 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
1370 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
1371 }
1372
Vasanthakumar Thiagarajan7f62a132010-04-15 17:39:19 -04001373 if (ah->config.tx_intr_mitigation) {
1374 REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_LAST, 300);
1375 REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_FIRST, 750);
1376 }
1377
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001378 ath9k_hw_init_bb(ah, chan);
1379
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001380 if (!ath9k_hw_init_cal(ah, chan))
Joe Perches6badaaf2009-06-28 09:26:32 -07001381 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001382
Sujith7d0d0df2010-04-16 11:53:57 +05301383 ENABLE_REGWRITE_BUFFER(ah);
1384
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001385 ath9k_hw_restore_chainmask(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001386 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
1387
Sujith7d0d0df2010-04-16 11:53:57 +05301388 REGWRITE_BUFFER_FLUSH(ah);
1389 DISABLE_REGWRITE_BUFFER(ah);
1390
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001391 /*
1392 * For big endian systems turn on swapping for descriptors
1393 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001394 if (AR_SREV_9100(ah)) {
1395 u32 mask;
1396 mask = REG_READ(ah, AR_CFG);
1397 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001398 ath_print(common, ATH_DBG_RESET,
Sujith04bd46382008-11-28 22:18:05 +05301399 "CFG Byte Swap Set 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001400 } else {
1401 mask =
1402 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
1403 REG_WRITE(ah, AR_CFG, mask);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001404 ath_print(common, ATH_DBG_RESET,
Sujith04bd46382008-11-28 22:18:05 +05301405 "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001406 }
1407 } else {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001408 /* Configure AR9271 target WLAN */
1409 if (AR_SREV_9271(ah))
1410 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001411#ifdef __BIG_ENDIAN
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001412 else
1413 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001414#endif
1415 }
1416
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001417 if (ah->btcoex_hw.enabled)
Vasanthakumar Thiagarajan42cc41e2009-08-26 21:08:45 +05301418 ath9k_hw_btcoex_enable(ah);
1419
Vasanthakumar Thiagarajand8903a52010-04-15 17:39:25 -04001420 if (AR_SREV_9300_20_OR_LATER(ah)) {
1421 ath9k_hw_loadnf(ah, curchan);
1422 ath9k_hw_start_nfcal(ah);
1423 }
1424
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001425 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001426}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001427EXPORT_SYMBOL(ath9k_hw_reset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001428
Sujithf1dc5602008-10-29 10:16:30 +05301429/************************/
1430/* Key Cache Management */
1431/************************/
1432
Sujithcbe61d82009-02-09 13:27:12 +05301433bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001434{
Sujithf1dc5602008-10-29 10:16:30 +05301435 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001436
Sujith2660b812009-02-09 13:27:26 +05301437 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001438 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1439 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001440 return false;
1441 }
1442
Sujithf1dc5602008-10-29 10:16:30 +05301443 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001444
Sujithf1dc5602008-10-29 10:16:30 +05301445 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
1446 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
1447 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
1448 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
1449 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
1450 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
1451 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
1452 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
1453
1454 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
1455 u16 micentry = entry + 64;
1456
1457 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
1458 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
1459 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
1460 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
1461
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001462 }
1463
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001464 return true;
1465}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001466EXPORT_SYMBOL(ath9k_hw_keyreset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001467
Sujithcbe61d82009-02-09 13:27:12 +05301468bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001469{
Sujithf1dc5602008-10-29 10:16:30 +05301470 u32 macHi, macLo;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001471
Sujith2660b812009-02-09 13:27:26 +05301472 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001473 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1474 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001475 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001476 }
1477
Sujithf1dc5602008-10-29 10:16:30 +05301478 if (mac != NULL) {
1479 macHi = (mac[5] << 8) | mac[4];
1480 macLo = (mac[3] << 24) |
1481 (mac[2] << 16) |
1482 (mac[1] << 8) |
1483 mac[0];
1484 macLo >>= 1;
1485 macLo |= (macHi & 1) << 31;
1486 macHi >>= 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001487 } else {
Sujithf1dc5602008-10-29 10:16:30 +05301488 macLo = macHi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001489 }
Sujithf1dc5602008-10-29 10:16:30 +05301490 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
1491 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001492
1493 return true;
1494}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001495EXPORT_SYMBOL(ath9k_hw_keysetmac);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001496
Sujithcbe61d82009-02-09 13:27:12 +05301497bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
Sujithf1dc5602008-10-29 10:16:30 +05301498 const struct ath9k_keyval *k,
Jouni Malinene0caf9e2009-03-02 18:15:53 +02001499 const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001500{
Sujith2660b812009-02-09 13:27:26 +05301501 const struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001502 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301503 u32 key0, key1, key2, key3, key4;
1504 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001505
Sujithf1dc5602008-10-29 10:16:30 +05301506 if (entry >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001507 ath_print(common, ATH_DBG_FATAL,
1508 "keycache entry %u out of range\n", entry);
Sujithf1dc5602008-10-29 10:16:30 +05301509 return false;
1510 }
1511
1512 switch (k->kv_type) {
1513 case ATH9K_CIPHER_AES_OCB:
1514 keyType = AR_KEYTABLE_TYPE_AES;
1515 break;
1516 case ATH9K_CIPHER_AES_CCM:
1517 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001518 ath_print(common, ATH_DBG_ANY,
1519 "AES-CCM not supported by mac rev 0x%x\n",
1520 ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001521 return false;
1522 }
Sujithf1dc5602008-10-29 10:16:30 +05301523 keyType = AR_KEYTABLE_TYPE_CCM;
1524 break;
1525 case ATH9K_CIPHER_TKIP:
1526 keyType = AR_KEYTABLE_TYPE_TKIP;
1527 if (ATH9K_IS_MIC_ENABLED(ah)
1528 && entry + 64 >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001529 ath_print(common, ATH_DBG_ANY,
1530 "entry %u inappropriate for TKIP\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001531 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001532 }
Sujithf1dc5602008-10-29 10:16:30 +05301533 break;
1534 case ATH9K_CIPHER_WEP:
Zhu Yie31a16d2009-05-21 21:47:03 +08001535 if (k->kv_len < WLAN_KEY_LEN_WEP40) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001536 ath_print(common, ATH_DBG_ANY,
1537 "WEP key length %u too small\n", k->kv_len);
Sujithf1dc5602008-10-29 10:16:30 +05301538 return false;
1539 }
Zhu Yie31a16d2009-05-21 21:47:03 +08001540 if (k->kv_len <= WLAN_KEY_LEN_WEP40)
Sujithf1dc5602008-10-29 10:16:30 +05301541 keyType = AR_KEYTABLE_TYPE_40;
Zhu Yie31a16d2009-05-21 21:47:03 +08001542 else if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05301543 keyType = AR_KEYTABLE_TYPE_104;
1544 else
1545 keyType = AR_KEYTABLE_TYPE_128;
1546 break;
1547 case ATH9K_CIPHER_CLR:
1548 keyType = AR_KEYTABLE_TYPE_CLR;
1549 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001550 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001551 ath_print(common, ATH_DBG_FATAL,
1552 "cipher %u not supported\n", k->kv_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001553 return false;
1554 }
Sujithf1dc5602008-10-29 10:16:30 +05301555
Jouni Malinene0caf9e2009-03-02 18:15:53 +02001556 key0 = get_unaligned_le32(k->kv_val + 0);
1557 key1 = get_unaligned_le16(k->kv_val + 4);
1558 key2 = get_unaligned_le32(k->kv_val + 6);
1559 key3 = get_unaligned_le16(k->kv_val + 10);
1560 key4 = get_unaligned_le32(k->kv_val + 12);
Zhu Yie31a16d2009-05-21 21:47:03 +08001561 if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05301562 key4 &= 0xff;
1563
Jouni Malinen672903b2009-03-02 15:06:31 +02001564 /*
1565 * Note: Key cache registers access special memory area that requires
1566 * two 32-bit writes to actually update the values in the internal
1567 * memory. Consequently, the exact order and pairs used here must be
1568 * maintained.
1569 */
1570
Sujithf1dc5602008-10-29 10:16:30 +05301571 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
1572 u16 micentry = entry + 64;
1573
Jouni Malinen672903b2009-03-02 15:06:31 +02001574 /*
1575 * Write inverted key[47:0] first to avoid Michael MIC errors
1576 * on frames that could be sent or received at the same time.
1577 * The correct key will be written in the end once everything
1578 * else is ready.
1579 */
Sujithf1dc5602008-10-29 10:16:30 +05301580 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
1581 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02001582
1583 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05301584 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
1585 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02001586
1587 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05301588 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
1589 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
Jouni Malinen672903b2009-03-02 15:06:31 +02001590
1591 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05301592 (void) ath9k_hw_keysetmac(ah, entry, mac);
1593
Sujith2660b812009-02-09 13:27:26 +05301594 if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) {
Jouni Malinen672903b2009-03-02 15:06:31 +02001595 /*
1596 * TKIP uses two key cache entries:
1597 * Michael MIC TX/RX keys in the same key cache entry
1598 * (idx = main index + 64):
1599 * key0 [31:0] = RX key [31:0]
1600 * key1 [15:0] = TX key [31:16]
1601 * key1 [31:16] = reserved
1602 * key2 [31:0] = RX key [63:32]
1603 * key3 [15:0] = TX key [15:0]
1604 * key3 [31:16] = reserved
1605 * key4 [31:0] = TX key [63:32]
1606 */
Sujithf1dc5602008-10-29 10:16:30 +05301607 u32 mic0, mic1, mic2, mic3, mic4;
1608
1609 mic0 = get_unaligned_le32(k->kv_mic + 0);
1610 mic2 = get_unaligned_le32(k->kv_mic + 4);
1611 mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
1612 mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
1613 mic4 = get_unaligned_le32(k->kv_txmic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02001614
1615 /* Write RX[31:0] and TX[31:16] */
Sujithf1dc5602008-10-29 10:16:30 +05301616 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
1617 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
Jouni Malinen672903b2009-03-02 15:06:31 +02001618
1619 /* Write RX[63:32] and TX[15:0] */
Sujithf1dc5602008-10-29 10:16:30 +05301620 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
1621 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
Jouni Malinen672903b2009-03-02 15:06:31 +02001622
1623 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05301624 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
1625 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
1626 AR_KEYTABLE_TYPE_CLR);
1627
1628 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02001629 /*
1630 * TKIP uses four key cache entries (two for group
1631 * keys):
1632 * Michael MIC TX/RX keys are in different key cache
1633 * entries (idx = main index + 64 for TX and
1634 * main index + 32 + 96 for RX):
1635 * key0 [31:0] = TX/RX MIC key [31:0]
1636 * key1 [31:0] = reserved
1637 * key2 [31:0] = TX/RX MIC key [63:32]
1638 * key3 [31:0] = reserved
1639 * key4 [31:0] = reserved
1640 *
1641 * Upper layer code will call this function separately
1642 * for TX and RX keys when these registers offsets are
1643 * used.
1644 */
Sujithf1dc5602008-10-29 10:16:30 +05301645 u32 mic0, mic2;
1646
1647 mic0 = get_unaligned_le32(k->kv_mic + 0);
1648 mic2 = get_unaligned_le32(k->kv_mic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02001649
1650 /* Write MIC key[31:0] */
Sujithf1dc5602008-10-29 10:16:30 +05301651 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
1652 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02001653
1654 /* Write MIC key[63:32] */
Sujithf1dc5602008-10-29 10:16:30 +05301655 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
1656 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02001657
1658 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05301659 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
1660 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
1661 AR_KEYTABLE_TYPE_CLR);
1662 }
Jouni Malinen672903b2009-03-02 15:06:31 +02001663
1664 /* MAC address registers are reserved for the MIC entry */
Sujithf1dc5602008-10-29 10:16:30 +05301665 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
1666 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02001667
1668 /*
1669 * Write the correct (un-inverted) key[47:0] last to enable
1670 * TKIP now that all other registers are set with correct
1671 * values.
1672 */
Sujithf1dc5602008-10-29 10:16:30 +05301673 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
1674 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
1675 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02001676 /* Write key[47:0] */
Sujithf1dc5602008-10-29 10:16:30 +05301677 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
1678 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02001679
1680 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05301681 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
1682 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02001683
1684 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05301685 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
1686 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
1687
Jouni Malinen672903b2009-03-02 15:06:31 +02001688 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05301689 (void) ath9k_hw_keysetmac(ah, entry, mac);
1690 }
1691
Sujithf1dc5602008-10-29 10:16:30 +05301692 return true;
1693}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001694EXPORT_SYMBOL(ath9k_hw_set_keycache_entry);
Sujithf1dc5602008-10-29 10:16:30 +05301695
Sujithcbe61d82009-02-09 13:27:12 +05301696bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry)
Sujithf1dc5602008-10-29 10:16:30 +05301697{
Sujith2660b812009-02-09 13:27:26 +05301698 if (entry < ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05301699 u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
1700 if (val & AR_KEYTABLE_VALID)
1701 return true;
1702 }
1703 return false;
1704}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001705EXPORT_SYMBOL(ath9k_hw_keyisvalid);
Sujithf1dc5602008-10-29 10:16:30 +05301706
1707/******************************/
1708/* Power Management (Chipset) */
1709/******************************/
1710
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001711/*
1712 * Notify Power Mgt is disabled in self-generated frames.
1713 * If requested, force chip to sleep.
1714 */
Sujithcbe61d82009-02-09 13:27:12 +05301715static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05301716{
1717 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
1718 if (setChip) {
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001719 /*
1720 * Clear the RTC force wake bit to allow the
1721 * mac to go to sleep.
1722 */
Sujithf1dc5602008-10-29 10:16:30 +05301723 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
1724 AR_RTC_FORCE_WAKE_EN);
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001725 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05301726 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1727
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001728 /* Shutdown chip. Active low */
Sujith14b3af32010-03-17 14:25:18 +05301729 if (!AR_SREV_5416(ah) && !AR_SREV_9271(ah))
Sujith4921be82009-09-18 15:04:27 +05301730 REG_CLR_BIT(ah, (AR_RTC_RESET),
1731 AR_RTC_RESET_EN);
Sujithf1dc5602008-10-29 10:16:30 +05301732 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001733}
1734
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04001735/*
1736 * Notify Power Management is enabled in self-generating
1737 * frames. If request, set power mode of chip to
1738 * auto/normal. Duration in units of 128us (1/8 TU).
1739 */
Sujithcbe61d82009-02-09 13:27:12 +05301740static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001741{
Sujithf1dc5602008-10-29 10:16:30 +05301742 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
1743 if (setChip) {
Sujith2660b812009-02-09 13:27:26 +05301744 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001745
Sujithf1dc5602008-10-29 10:16:30 +05301746 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04001747 /* Set WakeOnInterrupt bit; clear ForceWake bit */
Sujithf1dc5602008-10-29 10:16:30 +05301748 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1749 AR_RTC_FORCE_WAKE_ON_INT);
1750 } else {
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04001751 /*
1752 * Clear the RTC force wake bit to allow the
1753 * mac to go to sleep.
1754 */
Sujithf1dc5602008-10-29 10:16:30 +05301755 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
1756 AR_RTC_FORCE_WAKE_EN);
1757 }
1758 }
1759}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001760
Sujithcbe61d82009-02-09 13:27:12 +05301761static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05301762{
1763 u32 val;
1764 int i;
1765
1766 if (setChip) {
1767 if ((REG_READ(ah, AR_RTC_STATUS) &
1768 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
1769 if (ath9k_hw_set_reset_reg(ah,
1770 ATH9K_RESET_POWER_ON) != true) {
1771 return false;
1772 }
Luis R. Rodrigueze0412282010-04-15 17:38:15 -04001773 if (!AR_SREV_9300_20_OR_LATER(ah))
1774 ath9k_hw_init_pll(ah, NULL);
Sujithf1dc5602008-10-29 10:16:30 +05301775 }
1776 if (AR_SREV_9100(ah))
1777 REG_SET_BIT(ah, AR_RTC_RESET,
1778 AR_RTC_RESET_EN);
1779
1780 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
1781 AR_RTC_FORCE_WAKE_EN);
1782 udelay(50);
1783
1784 for (i = POWER_UP_TIME / 50; i > 0; i--) {
1785 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
1786 if (val == AR_RTC_STATUS_ON)
1787 break;
1788 udelay(50);
1789 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
1790 AR_RTC_FORCE_WAKE_EN);
1791 }
1792 if (i == 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001793 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1794 "Failed to wakeup in %uus\n",
1795 POWER_UP_TIME / 20);
Sujithf1dc5602008-10-29 10:16:30 +05301796 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001797 }
1798 }
1799
Sujithf1dc5602008-10-29 10:16:30 +05301800 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
1801
1802 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001803}
1804
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001805bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05301806{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001807 struct ath_common *common = ath9k_hw_common(ah);
Sujithcbe61d82009-02-09 13:27:12 +05301808 int status = true, setChip = true;
Sujithf1dc5602008-10-29 10:16:30 +05301809 static const char *modes[] = {
1810 "AWAKE",
1811 "FULL-SLEEP",
1812 "NETWORK SLEEP",
1813 "UNDEFINED"
1814 };
Sujithf1dc5602008-10-29 10:16:30 +05301815
Gabor Juhoscbdec972009-07-24 17:27:22 +02001816 if (ah->power_mode == mode)
1817 return status;
1818
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001819 ath_print(common, ATH_DBG_RESET, "%s -> %s\n",
1820 modes[ah->power_mode], modes[mode]);
Sujithf1dc5602008-10-29 10:16:30 +05301821
1822 switch (mode) {
1823 case ATH9K_PM_AWAKE:
1824 status = ath9k_hw_set_power_awake(ah, setChip);
1825 break;
1826 case ATH9K_PM_FULL_SLEEP:
1827 ath9k_set_power_sleep(ah, setChip);
Sujith2660b812009-02-09 13:27:26 +05301828 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05301829 break;
1830 case ATH9K_PM_NETWORK_SLEEP:
1831 ath9k_set_power_network_sleep(ah, setChip);
1832 break;
1833 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001834 ath_print(common, ATH_DBG_FATAL,
1835 "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05301836 return false;
1837 }
Sujith2660b812009-02-09 13:27:26 +05301838 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05301839
1840 return status;
1841}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001842EXPORT_SYMBOL(ath9k_hw_setpower);
Sujithf1dc5602008-10-29 10:16:30 +05301843
Sujithf1dc5602008-10-29 10:16:30 +05301844/*******************/
1845/* Beacon Handling */
1846/*******************/
1847
Sujithcbe61d82009-02-09 13:27:12 +05301848void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001849{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001850 int flags = 0;
1851
Sujith2660b812009-02-09 13:27:26 +05301852 ah->beacon_interval = beacon_period;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001853
Sujith7d0d0df2010-04-16 11:53:57 +05301854 ENABLE_REGWRITE_BUFFER(ah);
1855
Sujith2660b812009-02-09 13:27:26 +05301856 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001857 case NL80211_IFTYPE_STATION:
1858 case NL80211_IFTYPE_MONITOR:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001859 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
1860 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
1861 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
1862 flags |= AR_TBTT_TIMER_EN;
1863 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001864 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04001865 case NL80211_IFTYPE_MESH_POINT:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001866 REG_SET_BIT(ah, AR_TXCFG,
1867 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
1868 REG_WRITE(ah, AR_NEXT_NDP_TIMER,
1869 TU_TO_USEC(next_beacon +
Sujith2660b812009-02-09 13:27:26 +05301870 (ah->atim_window ? ah->
1871 atim_window : 1)));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001872 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08001873 case NL80211_IFTYPE_AP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001874 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
1875 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
1876 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05301877 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05301878 dma_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001879 REG_WRITE(ah, AR_NEXT_SWBA,
1880 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05301881 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05301882 sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001883 flags |=
1884 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
1885 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001886 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001887 ath_print(ath9k_hw_common(ah), ATH_DBG_BEACON,
1888 "%s: unsupported opmode: %d\n",
1889 __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08001890 return;
1891 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001892 }
1893
1894 REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
1895 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
1896 REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
1897 REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
1898
Sujith7d0d0df2010-04-16 11:53:57 +05301899 REGWRITE_BUFFER_FLUSH(ah);
1900 DISABLE_REGWRITE_BUFFER(ah);
1901
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001902 beacon_period &= ~ATH9K_BEACON_ENA;
1903 if (beacon_period & ATH9K_BEACON_RESET_TSF) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001904 ath9k_hw_reset_tsf(ah);
1905 }
1906
1907 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
1908}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001909EXPORT_SYMBOL(ath9k_hw_beaconinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001910
Sujithcbe61d82009-02-09 13:27:12 +05301911void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301912 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001913{
1914 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05301915 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001916 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001917
Sujith7d0d0df2010-04-16 11:53:57 +05301918 ENABLE_REGWRITE_BUFFER(ah);
1919
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001920 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
1921
1922 REG_WRITE(ah, AR_BEACON_PERIOD,
1923 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
1924 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
1925 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
1926
Sujith7d0d0df2010-04-16 11:53:57 +05301927 REGWRITE_BUFFER_FLUSH(ah);
1928 DISABLE_REGWRITE_BUFFER(ah);
1929
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001930 REG_RMW_FIELD(ah, AR_RSSI_THR,
1931 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
1932
1933 beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
1934
1935 if (bs->bs_sleepduration > beaconintval)
1936 beaconintval = bs->bs_sleepduration;
1937
1938 dtimperiod = bs->bs_dtimperiod;
1939 if (bs->bs_sleepduration > dtimperiod)
1940 dtimperiod = bs->bs_sleepduration;
1941
1942 if (beaconintval == dtimperiod)
1943 nextTbtt = bs->bs_nextdtim;
1944 else
1945 nextTbtt = bs->bs_nexttbtt;
1946
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001947 ath_print(common, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
1948 ath_print(common, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
1949 ath_print(common, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
1950 ath_print(common, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001951
Sujith7d0d0df2010-04-16 11:53:57 +05301952 ENABLE_REGWRITE_BUFFER(ah);
1953
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001954 REG_WRITE(ah, AR_NEXT_DTIM,
1955 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
1956 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
1957
1958 REG_WRITE(ah, AR_SLEEP1,
1959 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
1960 | AR_SLEEP1_ASSUME_DTIM);
1961
Sujith60b67f52008-08-07 10:52:38 +05301962 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001963 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
1964 else
1965 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
1966
1967 REG_WRITE(ah, AR_SLEEP2,
1968 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
1969
1970 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
1971 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
1972
Sujith7d0d0df2010-04-16 11:53:57 +05301973 REGWRITE_BUFFER_FLUSH(ah);
1974 DISABLE_REGWRITE_BUFFER(ah);
1975
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001976 REG_SET_BIT(ah, AR_TIMER_MODE,
1977 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
1978 AR_DTIM_TIMER_EN);
1979
Sujith4af9cf42009-02-12 10:06:47 +05301980 /* TSF Out of Range Threshold */
1981 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001982}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001983EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001984
Sujithf1dc5602008-10-29 10:16:30 +05301985/*******************/
1986/* HW Capabilities */
1987/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001988
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01001989int ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001990{
Sujith2660b812009-02-09 13:27:26 +05301991 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001992 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001993 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001994 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001995
Sujithf1dc5602008-10-29 10:16:30 +05301996 u16 capField = 0, eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001997
Sujithf74df6f2009-02-09 13:27:24 +05301998 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001999 regulatory->current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05302000
Sujithf74df6f2009-02-09 13:27:24 +05302001 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
Sujithfec0de12009-02-12 10:06:43 +05302002 if (AR_SREV_9285_10_OR_LATER(ah))
2003 eeval |= AR9285_RDEXT_DEFAULT;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002004 regulatory->current_rd_ext = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05302005
Sujithf74df6f2009-02-09 13:27:24 +05302006 capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
Sujithf1dc5602008-10-29 10:16:30 +05302007
Sujith2660b812009-02-09 13:27:26 +05302008 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05302009 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002010 if (regulatory->current_rd == 0x64 ||
2011 regulatory->current_rd == 0x65)
2012 regulatory->current_rd += 5;
2013 else if (regulatory->current_rd == 0x41)
2014 regulatory->current_rd = 0x43;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002015 ath_print(common, ATH_DBG_REGULATORY,
2016 "regdomain mapped to 0x%x\n", regulatory->current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002017 }
Sujithdc2222a2008-08-14 13:26:55 +05302018
Sujithf74df6f2009-02-09 13:27:24 +05302019 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002020 if ((eeval & (AR5416_OPFLAGS_11G | AR5416_OPFLAGS_11A)) == 0) {
2021 ath_print(common, ATH_DBG_FATAL,
2022 "no band has been marked as supported in EEPROM.\n");
2023 return -EINVAL;
2024 }
2025
Sujithf1dc5602008-10-29 10:16:30 +05302026 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002027
Sujithf1dc5602008-10-29 10:16:30 +05302028 if (eeval & AR5416_OPFLAGS_11A) {
2029 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05302030 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05302031 if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
2032 set_bit(ATH9K_MODE_11NA_HT20,
2033 pCap->wireless_modes);
2034 if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
2035 set_bit(ATH9K_MODE_11NA_HT40PLUS,
2036 pCap->wireless_modes);
2037 set_bit(ATH9K_MODE_11NA_HT40MINUS,
2038 pCap->wireless_modes);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002039 }
2040 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002041 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002042
Sujithf1dc5602008-10-29 10:16:30 +05302043 if (eeval & AR5416_OPFLAGS_11G) {
Sujithf1dc5602008-10-29 10:16:30 +05302044 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05302045 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05302046 if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
2047 set_bit(ATH9K_MODE_11NG_HT20,
2048 pCap->wireless_modes);
2049 if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
2050 set_bit(ATH9K_MODE_11NG_HT40PLUS,
2051 pCap->wireless_modes);
2052 set_bit(ATH9K_MODE_11NG_HT40MINUS,
2053 pCap->wireless_modes);
2054 }
2055 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002056 }
Sujithf1dc5602008-10-29 10:16:30 +05302057
Sujithf74df6f2009-02-09 13:27:24 +05302058 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002059 /*
2060 * For AR9271 we will temporarilly uses the rx chainmax as read from
2061 * the EEPROM.
2062 */
Sujith8147f5d2009-02-20 15:13:23 +05302063 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002064 !(eeval & AR5416_OPFLAGS_11A) &&
2065 !(AR_SREV_9271(ah)))
2066 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
Sujith8147f5d2009-02-20 15:13:23 +05302067 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
2068 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002069 /* Use rx_chainmask from EEPROM. */
Sujith8147f5d2009-02-20 15:13:23 +05302070 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05302071
Sujithd535a422009-02-09 13:27:06 +05302072 if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0)))
Sujith2660b812009-02-09 13:27:26 +05302073 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05302074
2075 pCap->low_2ghz_chan = 2312;
2076 pCap->high_2ghz_chan = 2732;
2077
2078 pCap->low_5ghz_chan = 4920;
2079 pCap->high_5ghz_chan = 6100;
2080
2081 pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
2082 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
2083 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
2084
2085 pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
2086 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
2087 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
2088
Sujith2660b812009-02-09 13:27:26 +05302089 if (ah->config.ht_enable)
Sujithf1dc5602008-10-29 10:16:30 +05302090 pCap->hw_caps |= ATH9K_HW_CAP_HT;
2091 else
2092 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
2093
2094 pCap->hw_caps |= ATH9K_HW_CAP_GTT;
2095 pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
2096 pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
2097 pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
2098
2099 if (capField & AR_EEPROM_EEPCAP_MAXQCU)
2100 pCap->total_queues =
2101 MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
2102 else
2103 pCap->total_queues = ATH9K_NUM_TX_QUEUES;
2104
2105 if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
2106 pCap->keycache_size =
2107 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
2108 else
2109 pCap->keycache_size = AR_KEYTABLE_SIZE;
2110
2111 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -05002112
2113 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
2114 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD >> 1;
2115 else
2116 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
Sujithf1dc5602008-10-29 10:16:30 +05302117
Sujith5b5fa352010-03-17 14:25:15 +05302118 if (AR_SREV_9271(ah))
2119 pCap->num_gpio_pins = AR9271_NUM_GPIO;
2120 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302121 pCap->num_gpio_pins = AR9285_NUM_GPIO;
2122 else if (AR_SREV_9280_10_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302123 pCap->num_gpio_pins = AR928X_NUM_GPIO;
2124 else
2125 pCap->num_gpio_pins = AR_NUM_GPIO;
2126
Sujithf1dc5602008-10-29 10:16:30 +05302127 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
2128 pCap->hw_caps |= ATH9K_HW_CAP_CST;
2129 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
2130 } else {
2131 pCap->rts_aggr_limit = (8 * 1024);
2132 }
2133
2134 pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
2135
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05302136#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05302137 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
2138 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
2139 ah->rfkill_gpio =
2140 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
2141 ah->rfkill_polarity =
2142 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05302143
2144 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
2145 }
2146#endif
Vivek Natarajanbde748a2010-04-05 14:48:05 +05302147 if (AR_SREV_9271(ah))
2148 pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
2149 else
2150 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
Sujithf1dc5602008-10-29 10:16:30 +05302151
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302152 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302153 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
2154 else
2155 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
2156
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002157 if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) {
Sujithf1dc5602008-10-29 10:16:30 +05302158 pCap->reg_cap =
2159 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
2160 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
2161 AR_EEPROM_EEREGCAP_EN_KK_U2 |
2162 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
2163 } else {
2164 pCap->reg_cap =
2165 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
2166 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
2167 }
2168
Senthil Balasubramanianebb90cf2009-09-18 15:07:33 +05302169 /* Advertise midband for AR5416 with FCC midband set in eeprom */
2170 if (regulatory->current_rd_ext & (1 << REG_EXT_FCC_MIDBAND) &&
2171 AR_SREV_5416(ah))
2172 pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
Sujithf1dc5602008-10-29 10:16:30 +05302173
2174 pCap->num_antcfg_5ghz =
Sujithf74df6f2009-02-09 13:27:24 +05302175 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05302176 pCap->num_antcfg_2ghz =
Sujithf74df6f2009-02-09 13:27:24 +05302177 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05302178
Vasanthakumar Thiagarajanfe129462009-09-09 15:25:50 +05302179 if (AR_SREV_9280_10_OR_LATER(ah) &&
Luis R. Rodrigueza36cfbc2009-09-09 16:05:32 -07002180 ath9k_hw_btcoex_supported(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002181 btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO;
2182 btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO;
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05302183
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302184 if (AR_SREV_9285(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002185 btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
2186 btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302187 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002188 btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302189 }
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05302190 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002191 btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE;
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05302192 }
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002193
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002194 if (AR_SREV_9300_20_OR_LATER(ah)) {
Vasanthakumar Thiagarajane5553722010-04-26 15:04:33 -04002195 pCap->hw_caps |= ATH9K_HW_CAP_EDMA | ATH9K_HW_CAP_LDPC |
2196 ATH9K_HW_CAP_FASTCLOCK;
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002197 pCap->rx_hp_qdepth = ATH9K_HW_RX_HP_QDEPTH;
2198 pCap->rx_lp_qdepth = ATH9K_HW_RX_LP_QDEPTH;
2199 pCap->rx_status_len = sizeof(struct ar9003_rxs);
Vasanthakumar Thiagarajan162c3be2010-04-15 17:38:41 -04002200 pCap->tx_desc_len = sizeof(struct ar9003_txc);
Vasanthakumar Thiagarajan5088c2f2010-04-15 17:39:34 -04002201 pCap->txs_len = sizeof(struct ar9003_txs);
Vasanthakumar Thiagarajan162c3be2010-04-15 17:38:41 -04002202 } else {
2203 pCap->tx_desc_len = sizeof(struct ath_desc);
Felix Fietkau6b42e8d2010-04-26 15:04:35 -04002204 if (AR_SREV_9280_20(ah) &&
2205 ((ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) <=
2206 AR5416_EEP_MINOR_VER_16) ||
2207 ah->eep_ops->get_eeprom(ah, EEP_FSTCLK_5G)))
2208 pCap->hw_caps |= ATH9K_HW_CAP_FASTCLOCK;
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002209 }
Vasanthakumar Thiagarajan1adf02f2010-04-15 17:38:24 -04002210
Vasanthakumar Thiagarajan6c84ce02010-04-15 17:39:16 -04002211 if (AR_SREV_9300_20_OR_LATER(ah))
2212 pCap->hw_caps |= ATH9K_HW_CAP_RAC_SUPPORTED;
2213
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002214 return 0;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002215}
2216
Sujithcbe61d82009-02-09 13:27:12 +05302217bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05302218 u32 capability, u32 *result)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002219{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002220 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302221 switch (type) {
2222 case ATH9K_CAP_CIPHER:
2223 switch (capability) {
2224 case ATH9K_CIPHER_AES_CCM:
2225 case ATH9K_CIPHER_AES_OCB:
2226 case ATH9K_CIPHER_TKIP:
2227 case ATH9K_CIPHER_WEP:
2228 case ATH9K_CIPHER_MIC:
2229 case ATH9K_CIPHER_CLR:
2230 return true;
2231 default:
2232 return false;
2233 }
2234 case ATH9K_CAP_TKIP_MIC:
2235 switch (capability) {
2236 case 0:
2237 return true;
2238 case 1:
Sujith2660b812009-02-09 13:27:26 +05302239 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05302240 AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
2241 false;
2242 }
2243 case ATH9K_CAP_TKIP_SPLIT:
Sujith2660b812009-02-09 13:27:26 +05302244 return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ?
Sujithf1dc5602008-10-29 10:16:30 +05302245 false : true;
Sujithf1dc5602008-10-29 10:16:30 +05302246 case ATH9K_CAP_MCAST_KEYSRCH:
2247 switch (capability) {
2248 case 0:
2249 return true;
2250 case 1:
2251 if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
2252 return false;
2253 } else {
Sujith2660b812009-02-09 13:27:26 +05302254 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05302255 AR_STA_ID1_MCAST_KSRCH) ? true :
2256 false;
2257 }
2258 }
2259 return false;
Sujithf1dc5602008-10-29 10:16:30 +05302260 case ATH9K_CAP_TXPOW:
2261 switch (capability) {
2262 case 0:
2263 return 0;
2264 case 1:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002265 *result = regulatory->power_limit;
Sujithf1dc5602008-10-29 10:16:30 +05302266 return 0;
2267 case 2:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002268 *result = regulatory->max_power_level;
Sujithf1dc5602008-10-29 10:16:30 +05302269 return 0;
2270 case 3:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002271 *result = regulatory->tp_scale;
Sujithf1dc5602008-10-29 10:16:30 +05302272 return 0;
2273 }
2274 return false;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05302275 case ATH9K_CAP_DS:
2276 return (AR_SREV_9280_20_OR_LATER(ah) &&
2277 (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1))
2278 ? false : true;
Sujithf1dc5602008-10-29 10:16:30 +05302279 default:
2280 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002281 }
Sujithf1dc5602008-10-29 10:16:30 +05302282}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002283EXPORT_SYMBOL(ath9k_hw_getcapability);
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002284
Sujithcbe61d82009-02-09 13:27:12 +05302285bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05302286 u32 capability, u32 setting, int *status)
2287{
Sujithf1dc5602008-10-29 10:16:30 +05302288 switch (type) {
2289 case ATH9K_CAP_TKIP_MIC:
2290 if (setting)
Sujith2660b812009-02-09 13:27:26 +05302291 ah->sta_id1_defaults |=
Sujithf1dc5602008-10-29 10:16:30 +05302292 AR_STA_ID1_CRPT_MIC_ENABLE;
2293 else
Sujith2660b812009-02-09 13:27:26 +05302294 ah->sta_id1_defaults &=
Sujithf1dc5602008-10-29 10:16:30 +05302295 ~AR_STA_ID1_CRPT_MIC_ENABLE;
2296 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302297 case ATH9K_CAP_MCAST_KEYSRCH:
2298 if (setting)
Sujith2660b812009-02-09 13:27:26 +05302299 ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05302300 else
Sujith2660b812009-02-09 13:27:26 +05302301 ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05302302 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302303 default:
2304 return false;
2305 }
2306}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002307EXPORT_SYMBOL(ath9k_hw_setcapability);
Sujithf1dc5602008-10-29 10:16:30 +05302308
2309/****************************/
2310/* GPIO / RFKILL / Antennae */
2311/****************************/
2312
Sujithcbe61d82009-02-09 13:27:12 +05302313static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05302314 u32 gpio, u32 type)
2315{
2316 int addr;
2317 u32 gpio_shift, tmp;
2318
2319 if (gpio > 11)
2320 addr = AR_GPIO_OUTPUT_MUX3;
2321 else if (gpio > 5)
2322 addr = AR_GPIO_OUTPUT_MUX2;
2323 else
2324 addr = AR_GPIO_OUTPUT_MUX1;
2325
2326 gpio_shift = (gpio % 6) * 5;
2327
2328 if (AR_SREV_9280_20_OR_LATER(ah)
2329 || (addr != AR_GPIO_OUTPUT_MUX1)) {
2330 REG_RMW(ah, addr, (type << gpio_shift),
2331 (0x1f << gpio_shift));
2332 } else {
2333 tmp = REG_READ(ah, addr);
2334 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
2335 tmp &= ~(0x1f << gpio_shift);
2336 tmp |= (type << gpio_shift);
2337 REG_WRITE(ah, addr, tmp);
2338 }
2339}
2340
Sujithcbe61d82009-02-09 13:27:12 +05302341void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05302342{
2343 u32 gpio_shift;
2344
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07002345 BUG_ON(gpio >= ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05302346
2347 gpio_shift = gpio << 1;
2348
2349 REG_RMW(ah,
2350 AR_GPIO_OE_OUT,
2351 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
2352 (AR_GPIO_OE_OUT_DRV << gpio_shift));
2353}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002354EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
Sujithf1dc5602008-10-29 10:16:30 +05302355
Sujithcbe61d82009-02-09 13:27:12 +05302356u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05302357{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302358#define MS_REG_READ(x, y) \
2359 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
2360
Sujith2660b812009-02-09 13:27:26 +05302361 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05302362 return 0xffffffff;
2363
Felix Fietkau783dfca2010-04-15 17:38:11 -04002364 if (AR_SREV_9300_20_OR_LATER(ah))
2365 return MS_REG_READ(AR9300, gpio) != 0;
2366 else if (AR_SREV_9271(ah))
Sujith5b5fa352010-03-17 14:25:15 +05302367 return MS_REG_READ(AR9271, gpio) != 0;
2368 else if (AR_SREV_9287_10_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302369 return MS_REG_READ(AR9287, gpio) != 0;
2370 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302371 return MS_REG_READ(AR9285, gpio) != 0;
2372 else if (AR_SREV_9280_10_OR_LATER(ah))
2373 return MS_REG_READ(AR928X, gpio) != 0;
2374 else
2375 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05302376}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002377EXPORT_SYMBOL(ath9k_hw_gpio_get);
Sujithf1dc5602008-10-29 10:16:30 +05302378
Sujithcbe61d82009-02-09 13:27:12 +05302379void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05302380 u32 ah_signal_type)
2381{
2382 u32 gpio_shift;
2383
2384 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
2385
2386 gpio_shift = 2 * gpio;
2387
2388 REG_RMW(ah,
2389 AR_GPIO_OE_OUT,
2390 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
2391 (AR_GPIO_OE_OUT_DRV << gpio_shift));
2392}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002393EXPORT_SYMBOL(ath9k_hw_cfg_output);
Sujithf1dc5602008-10-29 10:16:30 +05302394
Sujithcbe61d82009-02-09 13:27:12 +05302395void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05302396{
Sujith5b5fa352010-03-17 14:25:15 +05302397 if (AR_SREV_9271(ah))
2398 val = ~val;
2399
Sujithf1dc5602008-10-29 10:16:30 +05302400 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
2401 AR_GPIO_BIT(gpio));
2402}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002403EXPORT_SYMBOL(ath9k_hw_set_gpio);
Sujithf1dc5602008-10-29 10:16:30 +05302404
Sujithcbe61d82009-02-09 13:27:12 +05302405u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302406{
2407 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
2408}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002409EXPORT_SYMBOL(ath9k_hw_getdefantenna);
Sujithf1dc5602008-10-29 10:16:30 +05302410
Sujithcbe61d82009-02-09 13:27:12 +05302411void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05302412{
2413 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
2414}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002415EXPORT_SYMBOL(ath9k_hw_setantenna);
Sujithf1dc5602008-10-29 10:16:30 +05302416
Sujithf1dc5602008-10-29 10:16:30 +05302417/*********************/
2418/* General Operation */
2419/*********************/
2420
Sujithcbe61d82009-02-09 13:27:12 +05302421u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302422{
2423 u32 bits = REG_READ(ah, AR_RX_FILTER);
2424 u32 phybits = REG_READ(ah, AR_PHY_ERR);
2425
2426 if (phybits & AR_PHY_ERR_RADAR)
2427 bits |= ATH9K_RX_FILTER_PHYRADAR;
2428 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
2429 bits |= ATH9K_RX_FILTER_PHYERR;
2430
2431 return bits;
2432}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002433EXPORT_SYMBOL(ath9k_hw_getrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05302434
Sujithcbe61d82009-02-09 13:27:12 +05302435void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05302436{
2437 u32 phybits;
2438
Sujith7d0d0df2010-04-16 11:53:57 +05302439 ENABLE_REGWRITE_BUFFER(ah);
2440
Sujith7ea310b2009-09-03 12:08:43 +05302441 REG_WRITE(ah, AR_RX_FILTER, bits);
2442
Sujithf1dc5602008-10-29 10:16:30 +05302443 phybits = 0;
2444 if (bits & ATH9K_RX_FILTER_PHYRADAR)
2445 phybits |= AR_PHY_ERR_RADAR;
2446 if (bits & ATH9K_RX_FILTER_PHYERR)
2447 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
2448 REG_WRITE(ah, AR_PHY_ERR, phybits);
2449
2450 if (phybits)
2451 REG_WRITE(ah, AR_RXCFG,
2452 REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
2453 else
2454 REG_WRITE(ah, AR_RXCFG,
2455 REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
Sujith7d0d0df2010-04-16 11:53:57 +05302456
2457 REGWRITE_BUFFER_FLUSH(ah);
2458 DISABLE_REGWRITE_BUFFER(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302459}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002460EXPORT_SYMBOL(ath9k_hw_setrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05302461
Sujithcbe61d82009-02-09 13:27:12 +05302462bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302463{
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05302464 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
2465 return false;
2466
2467 ath9k_hw_init_pll(ah, NULL);
2468 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302469}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002470EXPORT_SYMBOL(ath9k_hw_phy_disable);
Sujithf1dc5602008-10-29 10:16:30 +05302471
Sujithcbe61d82009-02-09 13:27:12 +05302472bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302473{
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002474 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05302475 return false;
2476
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05302477 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
2478 return false;
2479
2480 ath9k_hw_init_pll(ah, NULL);
2481 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302482}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002483EXPORT_SYMBOL(ath9k_hw_disable);
Sujithf1dc5602008-10-29 10:16:30 +05302484
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07002485void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
Sujithf1dc5602008-10-29 10:16:30 +05302486{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002487 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujith2660b812009-02-09 13:27:26 +05302488 struct ath9k_channel *chan = ah->curchan;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002489 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05302490
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002491 regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER);
Sujithf1dc5602008-10-29 10:16:30 +05302492
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07002493 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002494 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07002495 channel->max_antenna_gain * 2,
2496 channel->max_power * 2,
2497 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002498 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05302499}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002500EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
Sujithf1dc5602008-10-29 10:16:30 +05302501
Sujithcbe61d82009-02-09 13:27:12 +05302502void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac)
Sujithf1dc5602008-10-29 10:16:30 +05302503{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002504 memcpy(ath9k_hw_common(ah)->macaddr, mac, ETH_ALEN);
Sujithf1dc5602008-10-29 10:16:30 +05302505}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002506EXPORT_SYMBOL(ath9k_hw_setmac);
Sujithf1dc5602008-10-29 10:16:30 +05302507
Sujithcbe61d82009-02-09 13:27:12 +05302508void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302509{
Sujith2660b812009-02-09 13:27:26 +05302510 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05302511}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002512EXPORT_SYMBOL(ath9k_hw_setopmode);
Sujithf1dc5602008-10-29 10:16:30 +05302513
Sujithcbe61d82009-02-09 13:27:12 +05302514void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05302515{
2516 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
2517 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
2518}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002519EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
Sujithf1dc5602008-10-29 10:16:30 +05302520
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07002521void ath9k_hw_write_associd(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302522{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002523 struct ath_common *common = ath9k_hw_common(ah);
2524
2525 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
2526 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
2527 ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05302528}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002529EXPORT_SYMBOL(ath9k_hw_write_associd);
Sujithf1dc5602008-10-29 10:16:30 +05302530
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002531#define ATH9K_MAX_TSF_READ 10
2532
Sujithcbe61d82009-02-09 13:27:12 +05302533u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302534{
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002535 u32 tsf_lower, tsf_upper1, tsf_upper2;
2536 int i;
Sujithf1dc5602008-10-29 10:16:30 +05302537
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002538 tsf_upper1 = REG_READ(ah, AR_TSF_U32);
2539 for (i = 0; i < ATH9K_MAX_TSF_READ; i++) {
2540 tsf_lower = REG_READ(ah, AR_TSF_L32);
2541 tsf_upper2 = REG_READ(ah, AR_TSF_U32);
2542 if (tsf_upper2 == tsf_upper1)
2543 break;
2544 tsf_upper1 = tsf_upper2;
2545 }
Sujithf1dc5602008-10-29 10:16:30 +05302546
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002547 WARN_ON( i == ATH9K_MAX_TSF_READ );
2548
2549 return (((u64)tsf_upper1 << 32) | tsf_lower);
Sujithf1dc5602008-10-29 10:16:30 +05302550}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002551EXPORT_SYMBOL(ath9k_hw_gettsf64);
Sujithf1dc5602008-10-29 10:16:30 +05302552
Sujithcbe61d82009-02-09 13:27:12 +05302553void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002554{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002555 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01002556 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002557}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002558EXPORT_SYMBOL(ath9k_hw_settsf64);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002559
Sujithcbe61d82009-02-09 13:27:12 +05302560void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302561{
Gabor Juhosf9b604f2009-06-21 00:02:15 +02002562 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
2563 AH_TSF_WRITE_TIMEOUT))
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002564 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
2565 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
Gabor Juhosf9b604f2009-06-21 00:02:15 +02002566
Sujithf1dc5602008-10-29 10:16:30 +05302567 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002568}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002569EXPORT_SYMBOL(ath9k_hw_reset_tsf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002570
Sujith54e4cec2009-08-07 09:45:09 +05302571void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002572{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002573 if (setting)
Sujith2660b812009-02-09 13:27:26 +05302574 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002575 else
Sujith2660b812009-02-09 13:27:26 +05302576 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002577}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002578EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002579
Luis R. Rodriguez30cbd422009-11-03 16:10:46 -08002580/*
2581 * Extend 15-bit time stamp from rx descriptor to
2582 * a full 64-bit TSF using the current h/w TSF.
2583*/
2584u64 ath9k_hw_extend_tsf(struct ath_hw *ah, u32 rstamp)
2585{
2586 u64 tsf;
2587
2588 tsf = ath9k_hw_gettsf64(ah);
2589 if ((tsf & 0x7fff) < rstamp)
2590 tsf -= 0x8000;
2591 return (tsf & ~0x7fff) | rstamp;
2592}
2593EXPORT_SYMBOL(ath9k_hw_extend_tsf);
2594
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002595void ath9k_hw_set11nmac2040(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002596{
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002597 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithf1dc5602008-10-29 10:16:30 +05302598 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002599
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002600 if (conf_is_ht40(conf) && !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05302601 macmode = AR_2040_JOINED_RX_CLEAR;
2602 else
2603 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002604
Sujithf1dc5602008-10-29 10:16:30 +05302605 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002606}
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302607
2608/* HW Generic timers configuration */
2609
2610static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
2611{
2612 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2613 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2614 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2615 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2616 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2617 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2618 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2619 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2620 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
2621 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
2622 AR_NDP2_TIMER_MODE, 0x0002},
2623 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
2624 AR_NDP2_TIMER_MODE, 0x0004},
2625 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
2626 AR_NDP2_TIMER_MODE, 0x0008},
2627 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
2628 AR_NDP2_TIMER_MODE, 0x0010},
2629 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
2630 AR_NDP2_TIMER_MODE, 0x0020},
2631 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
2632 AR_NDP2_TIMER_MODE, 0x0040},
2633 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
2634 AR_NDP2_TIMER_MODE, 0x0080}
2635};
2636
2637/* HW generic timer primitives */
2638
2639/* compute and clear index of rightmost 1 */
2640static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
2641{
2642 u32 b;
2643
2644 b = *mask;
2645 b &= (0-b);
2646 *mask &= ~b;
2647 b *= debruijn32;
2648 b >>= 27;
2649
2650 return timer_table->gen_timer_index[b];
2651}
2652
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05302653u32 ath9k_hw_gettsf32(struct ath_hw *ah)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302654{
2655 return REG_READ(ah, AR_TSF_L32);
2656}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002657EXPORT_SYMBOL(ath9k_hw_gettsf32);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302658
2659struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
2660 void (*trigger)(void *),
2661 void (*overflow)(void *),
2662 void *arg,
2663 u8 timer_index)
2664{
2665 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2666 struct ath_gen_timer *timer;
2667
2668 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
2669
2670 if (timer == NULL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002671 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2672 "Failed to allocate memory"
2673 "for hw timer[%d]\n", timer_index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302674 return NULL;
2675 }
2676
2677 /* allocate a hardware generic timer slot */
2678 timer_table->timers[timer_index] = timer;
2679 timer->index = timer_index;
2680 timer->trigger = trigger;
2681 timer->overflow = overflow;
2682 timer->arg = arg;
2683
2684 return timer;
2685}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002686EXPORT_SYMBOL(ath_gen_timer_alloc);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302687
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07002688void ath9k_hw_gen_timer_start(struct ath_hw *ah,
2689 struct ath_gen_timer *timer,
2690 u32 timer_next,
2691 u32 timer_period)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302692{
2693 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2694 u32 tsf;
2695
2696 BUG_ON(!timer_period);
2697
2698 set_bit(timer->index, &timer_table->timer_mask.timer_bits);
2699
2700 tsf = ath9k_hw_gettsf32(ah);
2701
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002702 ath_print(ath9k_hw_common(ah), ATH_DBG_HWTIMER,
2703 "curent tsf %x period %x"
2704 "timer_next %x\n", tsf, timer_period, timer_next);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302705
2706 /*
2707 * Pull timer_next forward if the current TSF already passed it
2708 * because of software latency
2709 */
2710 if (timer_next < tsf)
2711 timer_next = tsf + timer_period;
2712
2713 /*
2714 * Program generic timer registers
2715 */
2716 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
2717 timer_next);
2718 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
2719 timer_period);
2720 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
2721 gen_tmr_configuration[timer->index].mode_mask);
2722
2723 /* Enable both trigger and thresh interrupt masks */
2724 REG_SET_BIT(ah, AR_IMR_S5,
2725 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
2726 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302727}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002728EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302729
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07002730void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302731{
2732 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2733
2734 if ((timer->index < AR_FIRST_NDP_TIMER) ||
2735 (timer->index >= ATH_MAX_GEN_TIMER)) {
2736 return;
2737 }
2738
2739 /* Clear generic timer enable bits. */
2740 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
2741 gen_tmr_configuration[timer->index].mode_mask);
2742
2743 /* Disable both trigger and thresh interrupt masks */
2744 REG_CLR_BIT(ah, AR_IMR_S5,
2745 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
2746 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
2747
2748 clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302749}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002750EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302751
2752void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
2753{
2754 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2755
2756 /* free the hardware generic timer slot */
2757 timer_table->timers[timer->index] = NULL;
2758 kfree(timer);
2759}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002760EXPORT_SYMBOL(ath_gen_timer_free);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302761
2762/*
2763 * Generic Timer Interrupts handling
2764 */
2765void ath_gen_timer_isr(struct ath_hw *ah)
2766{
2767 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2768 struct ath_gen_timer *timer;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002769 struct ath_common *common = ath9k_hw_common(ah);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302770 u32 trigger_mask, thresh_mask, index;
2771
2772 /* get hardware generic timer interrupt status */
2773 trigger_mask = ah->intr_gen_timer_trigger;
2774 thresh_mask = ah->intr_gen_timer_thresh;
2775 trigger_mask &= timer_table->timer_mask.val;
2776 thresh_mask &= timer_table->timer_mask.val;
2777
2778 trigger_mask &= ~thresh_mask;
2779
2780 while (thresh_mask) {
2781 index = rightmost_index(timer_table, &thresh_mask);
2782 timer = timer_table->timers[index];
2783 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002784 ath_print(common, ATH_DBG_HWTIMER,
2785 "TSF overflow for Gen timer %d\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302786 timer->overflow(timer->arg);
2787 }
2788
2789 while (trigger_mask) {
2790 index = rightmost_index(timer_table, &trigger_mask);
2791 timer = timer_table->timers[index];
2792 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002793 ath_print(common, ATH_DBG_HWTIMER,
2794 "Gen timer[%d] trigger\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302795 timer->trigger(timer->arg);
2796 }
2797}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002798EXPORT_SYMBOL(ath_gen_timer_isr);
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04002799
Sujith05020d22010-03-17 14:25:23 +05302800/********/
2801/* HTC */
2802/********/
2803
2804void ath9k_hw_htc_resetinit(struct ath_hw *ah)
2805{
2806 ah->htc_reset_init = true;
2807}
2808EXPORT_SYMBOL(ath9k_hw_htc_resetinit);
2809
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04002810static struct {
2811 u32 version;
2812 const char * name;
2813} ath_mac_bb_names[] = {
2814 /* Devices with external radios */
2815 { AR_SREV_VERSION_5416_PCI, "5416" },
2816 { AR_SREV_VERSION_5416_PCIE, "5418" },
2817 { AR_SREV_VERSION_9100, "9100" },
2818 { AR_SREV_VERSION_9160, "9160" },
2819 /* Single-chip solutions */
2820 { AR_SREV_VERSION_9280, "9280" },
2821 { AR_SREV_VERSION_9285, "9285" },
Luis R. Rodriguez11158472009-10-27 12:59:35 -04002822 { AR_SREV_VERSION_9287, "9287" },
2823 { AR_SREV_VERSION_9271, "9271" },
Luis R. Rodriguezec839032010-04-15 17:39:20 -04002824 { AR_SREV_VERSION_9300, "9300" },
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04002825};
2826
2827/* For devices with external radios */
2828static struct {
2829 u16 version;
2830 const char * name;
2831} ath_rf_names[] = {
2832 { 0, "5133" },
2833 { AR_RAD5133_SREV_MAJOR, "5133" },
2834 { AR_RAD5122_SREV_MAJOR, "5122" },
2835 { AR_RAD2133_SREV_MAJOR, "2133" },
2836 { AR_RAD2122_SREV_MAJOR, "2122" }
2837};
2838
2839/*
2840 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
2841 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04002842static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04002843{
2844 int i;
2845
2846 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
2847 if (ath_mac_bb_names[i].version == mac_bb_version) {
2848 return ath_mac_bb_names[i].name;
2849 }
2850 }
2851
2852 return "????";
2853}
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04002854
2855/*
2856 * Return the RF name. "????" is returned if the RF is unknown.
2857 * Used for devices with external radios.
2858 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04002859static const char *ath9k_hw_rf_name(u16 rf_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04002860{
2861 int i;
2862
2863 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
2864 if (ath_rf_names[i].version == rf_version) {
2865 return ath_rf_names[i].name;
2866 }
2867 }
2868
2869 return "????";
2870}
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04002871
2872void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
2873{
2874 int used;
2875
2876 /* chipsets >= AR9280 are single-chip */
2877 if (AR_SREV_9280_10_OR_LATER(ah)) {
2878 used = snprintf(hw_name, len,
2879 "Atheros AR%s Rev:%x",
2880 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
2881 ah->hw_version.macRev);
2882 }
2883 else {
2884 used = snprintf(hw_name, len,
2885 "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
2886 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
2887 ah->hw_version.macRev,
2888 ath9k_hw_rf_name((ah->hw_version.analog5GhzRev &
2889 AR_RADIO_SREV_MAJOR)),
2890 ah->hw_version.phyRev);
2891 }
2892
2893 hw_name[used] = '\0';
2894}
2895EXPORT_SYMBOL(ath9k_hw_name);