blob: f2d0389a66c0b80f5b7ae848f4c8a0d685a2efd4 [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 }
Sujith04bd4632008-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
Luis R. Rodriguez5efa3a62010-05-07 18:23:22 -0400576 /*
577 * Configire PCIE after Ini init. SERDES values now come from ini file
578 * This enables PCIe low power mode.
579 */
580 if (AR_SREV_9300_20_OR_LATER(ah)) {
581 u32 regval;
582 unsigned int i;
583
584 /* Set Bits 16 and 17 in the AR_WA register. */
585 regval = REG_READ(ah, AR_WA);
586 regval |= 0x00030000;
587 REG_WRITE(ah, AR_WA, regval);
588
589 for (i = 0; i < ah->iniPcieSerdesLowPower.ia_rows; i++) {
590 REG_WRITE(ah,
591 INI_RA(&ah->iniPcieSerdesLowPower, i, 0),
592 INI_RA(&ah->iniPcieSerdesLowPower, i, 1));
593 }
594 }
595
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700596 if (ah->is_pciexpress)
Vivek Natarajan93b1b372009-09-17 09:24:58 +0530597 ath9k_hw_configpcipowersave(ah, 0, 0);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700598 else
599 ath9k_hw_disablepcie(ah);
600
Luis R. Rodriguezd8f492b2010-04-15 17:39:04 -0400601 if (!AR_SREV_9300_20_OR_LATER(ah))
602 ar9002_hw_cck_chan14_spread(ah);
Sujith193cd452009-09-18 15:04:07 +0530603
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700604 r = ath9k_hw_post_init(ah);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700605 if (r)
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700606 return r;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700607
608 ath9k_hw_init_mode_gain_regs(ah);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +0100609 r = ath9k_hw_fill_cap_info(ah);
610 if (r)
611 return r;
612
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700613 r = ath9k_hw_init_macaddr(ah);
614 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700615 ath_print(common, ATH_DBG_FATAL,
616 "Failed to initialize MAC address\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700617 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700618 }
619
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400620 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
Sujith2660b812009-02-09 13:27:26 +0530621 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700622 else
Sujith2660b812009-02-09 13:27:26 +0530623 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700624
Felix Fietkau641d9922010-04-15 17:38:49 -0400625 if (AR_SREV_9300_20_OR_LATER(ah))
626 ar9003_hw_set_nf_limits(ah);
627
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700628 ath9k_init_nfcal_hist_buffer(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700629
Luis R. Rodriguez211f5852009-10-06 21:19:07 -0400630 common->state = ATH_HW_INITIALIZED;
631
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700632 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700633}
634
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400635int ath9k_hw_init(struct ath_hw *ah)
636{
637 int ret;
638 struct ath_common *common = ath9k_hw_common(ah);
639
640 /* These are all the AR5008/AR9001/AR9002 hardware family of chipsets */
641 switch (ah->hw_version.devid) {
642 case AR5416_DEVID_PCI:
643 case AR5416_DEVID_PCIE:
644 case AR5416_AR9100_DEVID:
645 case AR9160_DEVID_PCI:
646 case AR9280_DEVID_PCI:
647 case AR9280_DEVID_PCIE:
648 case AR9285_DEVID_PCIE:
Senthil Balasubramaniandb3cc532010-04-15 17:38:18 -0400649 case AR9287_DEVID_PCI:
650 case AR9287_DEVID_PCIE:
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400651 case AR2427_DEVID_PCIE:
Senthil Balasubramaniandb3cc532010-04-15 17:38:18 -0400652 case AR9300_DEVID_PCIE:
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400653 break;
654 default:
655 if (common->bus_ops->ath_bus_type == ATH_USB)
656 break;
657 ath_print(common, ATH_DBG_FATAL,
658 "Hardware device ID 0x%04x not supported\n",
659 ah->hw_version.devid);
660 return -EOPNOTSUPP;
661 }
662
663 ret = __ath9k_hw_init(ah);
664 if (ret) {
665 ath_print(common, ATH_DBG_FATAL,
666 "Unable to initialize hardware; "
667 "initialization status: %d\n", ret);
668 return ret;
669 }
670
671 return 0;
672}
673EXPORT_SYMBOL(ath9k_hw_init);
674
Sujithcbe61d82009-02-09 13:27:12 +0530675static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530676{
Sujith7d0d0df2010-04-16 11:53:57 +0530677 ENABLE_REGWRITE_BUFFER(ah);
678
Sujithf1dc5602008-10-29 10:16:30 +0530679 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
680 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
681
682 REG_WRITE(ah, AR_QOS_NO_ACK,
683 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
684 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
685 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
686
687 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
688 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
689 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
690 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
691 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
Sujith7d0d0df2010-04-16 11:53:57 +0530692
693 REGWRITE_BUFFER_FLUSH(ah);
694 DISABLE_REGWRITE_BUFFER(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530695}
696
Sujithcbe61d82009-02-09 13:27:12 +0530697static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530698 struct ath9k_channel *chan)
699{
Luis R. Rodriguez64773962010-04-15 17:38:17 -0400700 u32 pll = ath9k_hw_compute_pll_control(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +0530701
Gabor Juhosd03a66c2009-01-14 20:17:09 +0100702 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +0530703
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -0400704 /* Switch the core clock for ar9271 to 117Mhz */
705 if (AR_SREV_9271(ah)) {
Sujith25e2ab12010-03-17 14:25:22 +0530706 udelay(500);
707 REG_WRITE(ah, 0x50040, 0x304);
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -0400708 }
709
Sujithf1dc5602008-10-29 10:16:30 +0530710 udelay(RTC_PLL_SETTLE_DELAY);
711
712 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
713}
714
Sujithcbe61d82009-02-09 13:27:12 +0530715static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -0800716 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +0530717{
Pavel Roskin152d5302010-03-31 18:05:37 -0400718 u32 imr_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +0530719 AR_IMR_TXURN |
720 AR_IMR_RXERR |
721 AR_IMR_RXORN |
722 AR_IMR_BCNMISC;
723
Vasanthakumar Thiagarajan66860242010-04-15 17:39:07 -0400724 if (AR_SREV_9300_20_OR_LATER(ah)) {
725 imr_reg |= AR_IMR_RXOK_HP;
726 if (ah->config.rx_intr_mitigation)
727 imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
728 else
729 imr_reg |= AR_IMR_RXOK_LP;
Sujithf1dc5602008-10-29 10:16:30 +0530730
Vasanthakumar Thiagarajan66860242010-04-15 17:39:07 -0400731 } else {
732 if (ah->config.rx_intr_mitigation)
733 imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
734 else
735 imr_reg |= AR_IMR_RXOK;
736 }
737
738 if (ah->config.tx_intr_mitigation)
739 imr_reg |= AR_IMR_TXINTM | AR_IMR_TXMINTR;
740 else
741 imr_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +0530742
Colin McCabed97809d2008-12-01 13:38:55 -0800743 if (opmode == NL80211_IFTYPE_AP)
Pavel Roskin152d5302010-03-31 18:05:37 -0400744 imr_reg |= AR_IMR_MIB;
Sujithf1dc5602008-10-29 10:16:30 +0530745
Sujith7d0d0df2010-04-16 11:53:57 +0530746 ENABLE_REGWRITE_BUFFER(ah);
747
Pavel Roskin152d5302010-03-31 18:05:37 -0400748 REG_WRITE(ah, AR_IMR, imr_reg);
Pavel Roskin74bad5c2010-02-23 18:15:27 -0500749 ah->imrs2_reg |= AR_IMR_S2_GTT;
750 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
Sujithf1dc5602008-10-29 10:16:30 +0530751
752 if (!AR_SREV_9100(ah)) {
753 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
754 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
755 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
756 }
Vasanthakumar Thiagarajan66860242010-04-15 17:39:07 -0400757
Sujith7d0d0df2010-04-16 11:53:57 +0530758 REGWRITE_BUFFER_FLUSH(ah);
759 DISABLE_REGWRITE_BUFFER(ah);
760
Vasanthakumar Thiagarajan66860242010-04-15 17:39:07 -0400761 if (AR_SREV_9300_20_OR_LATER(ah)) {
762 REG_WRITE(ah, AR_INTR_PRIO_ASYNC_ENABLE, 0);
763 REG_WRITE(ah, AR_INTR_PRIO_ASYNC_MASK, 0);
764 REG_WRITE(ah, AR_INTR_PRIO_SYNC_ENABLE, 0);
765 REG_WRITE(ah, AR_INTR_PRIO_SYNC_MASK, 0);
766 }
Sujithf1dc5602008-10-29 10:16:30 +0530767}
768
Felix Fietkau0005baf2010-01-15 02:33:40 +0100769static void ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +0530770{
Felix Fietkau0005baf2010-01-15 02:33:40 +0100771 u32 val = ath9k_hw_mac_to_clks(ah, us);
772 val = min(val, (u32) 0xFFFF);
773 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, val);
Sujithf1dc5602008-10-29 10:16:30 +0530774}
775
Felix Fietkau0005baf2010-01-15 02:33:40 +0100776static void ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +0530777{
Felix Fietkau0005baf2010-01-15 02:33:40 +0100778 u32 val = ath9k_hw_mac_to_clks(ah, us);
779 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_ACK));
780 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_ACK, val);
781}
782
783static void ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
784{
785 u32 val = ath9k_hw_mac_to_clks(ah, us);
786 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_CTS));
787 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_CTS, val);
Sujithf1dc5602008-10-29 10:16:30 +0530788}
789
Sujithcbe61d82009-02-09 13:27:12 +0530790static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +0530791{
Sujithf1dc5602008-10-29 10:16:30 +0530792 if (tu > 0xFFFF) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700793 ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT,
794 "bad global tx timeout %u\n", tu);
Sujith2660b812009-02-09 13:27:26 +0530795 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +0530796 return false;
797 } else {
798 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +0530799 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +0530800 return true;
801 }
802}
803
Felix Fietkau0005baf2010-01-15 02:33:40 +0100804void ath9k_hw_init_global_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530805{
Felix Fietkau0005baf2010-01-15 02:33:40 +0100806 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
807 int acktimeout;
Felix Fietkaue239d852010-01-15 02:34:58 +0100808 int slottime;
Felix Fietkau0005baf2010-01-15 02:33:40 +0100809 int sifstime;
810
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700811 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
812 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +0530813
Sujith2660b812009-02-09 13:27:26 +0530814 if (ah->misc_mode != 0)
Sujithf1dc5602008-10-29 10:16:30 +0530815 REG_WRITE(ah, AR_PCU_MISC,
Sujith2660b812009-02-09 13:27:26 +0530816 REG_READ(ah, AR_PCU_MISC) | ah->misc_mode);
Felix Fietkau0005baf2010-01-15 02:33:40 +0100817
818 if (conf->channel && conf->channel->band == IEEE80211_BAND_5GHZ)
819 sifstime = 16;
820 else
821 sifstime = 10;
822
Felix Fietkaue239d852010-01-15 02:34:58 +0100823 /* As defined by IEEE 802.11-2007 17.3.8.6 */
824 slottime = ah->slottime + 3 * ah->coverage_class;
825 acktimeout = slottime + sifstime;
Felix Fietkau42c45682010-02-11 18:07:19 +0100826
827 /*
828 * Workaround for early ACK timeouts, add an offset to match the
829 * initval's 64us ack timeout value.
830 * This was initially only meant to work around an issue with delayed
831 * BA frames in some implementations, but it has been found to fix ACK
832 * timeout issues in other cases as well.
833 */
834 if (conf->channel && conf->channel->band == IEEE80211_BAND_2GHZ)
835 acktimeout += 64 - sifstime - ah->slottime;
836
Felix Fietkaue239d852010-01-15 02:34:58 +0100837 ath9k_hw_setslottime(ah, slottime);
Felix Fietkau0005baf2010-01-15 02:33:40 +0100838 ath9k_hw_set_ack_timeout(ah, acktimeout);
839 ath9k_hw_set_cts_timeout(ah, acktimeout);
Sujith2660b812009-02-09 13:27:26 +0530840 if (ah->globaltxtimeout != (u32) -1)
841 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Sujithf1dc5602008-10-29 10:16:30 +0530842}
Felix Fietkau0005baf2010-01-15 02:33:40 +0100843EXPORT_SYMBOL(ath9k_hw_init_global_settings);
Sujithf1dc5602008-10-29 10:16:30 +0530844
Sujith285f2dd2010-01-08 10:36:07 +0530845void ath9k_hw_deinit(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700846{
Luis R. Rodriguez211f5852009-10-06 21:19:07 -0400847 struct ath_common *common = ath9k_hw_common(ah);
848
Sujith736b3a22010-03-17 14:25:24 +0530849 if (common->state < ATH_HW_INITIALIZED)
Luis R. Rodriguez211f5852009-10-06 21:19:07 -0400850 goto free_hw;
851
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700852 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Luis R. Rodriguez211f5852009-10-06 21:19:07 -0400853
854free_hw:
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400855 ath9k_hw_rf_free_ext_banks(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700856}
Sujith285f2dd2010-01-08 10:36:07 +0530857EXPORT_SYMBOL(ath9k_hw_deinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700858
Sujithf1dc5602008-10-29 10:16:30 +0530859/*******/
860/* INI */
861/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700862
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400863u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan)
Bob Copeland3a702e42009-03-30 22:30:29 -0400864{
865 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
866
867 if (IS_CHAN_B(chan))
868 ctl |= CTL_11B;
869 else if (IS_CHAN_G(chan))
870 ctl |= CTL_11G;
871 else
872 ctl |= CTL_11A;
873
874 return ctl;
875}
876
Sujithf1dc5602008-10-29 10:16:30 +0530877/****************************************/
878/* Reset and Channel Switching Routines */
879/****************************************/
880
Sujithcbe61d82009-02-09 13:27:12 +0530881static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530882{
Felix Fietkau57b32222010-04-15 17:39:22 -0400883 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530884 u32 regval;
885
Sujith7d0d0df2010-04-16 11:53:57 +0530886 ENABLE_REGWRITE_BUFFER(ah);
887
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400888 /*
889 * set AHB_MODE not to do cacheline prefetches
890 */
Felix Fietkau57b32222010-04-15 17:39:22 -0400891 if (!AR_SREV_9300_20_OR_LATER(ah)) {
892 regval = REG_READ(ah, AR_AHB_MODE);
893 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
894 }
Sujithf1dc5602008-10-29 10:16:30 +0530895
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400896 /*
897 * let mac dma reads be in 128 byte chunks
898 */
Sujithf1dc5602008-10-29 10:16:30 +0530899 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
900 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
901
Sujith7d0d0df2010-04-16 11:53:57 +0530902 REGWRITE_BUFFER_FLUSH(ah);
903 DISABLE_REGWRITE_BUFFER(ah);
904
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400905 /*
906 * Restore TX Trigger Level to its pre-reset value.
907 * The initial value depends on whether aggregation is enabled, and is
908 * adjusted whenever underruns are detected.
909 */
Felix Fietkau57b32222010-04-15 17:39:22 -0400910 if (!AR_SREV_9300_20_OR_LATER(ah))
911 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +0530912
Sujith7d0d0df2010-04-16 11:53:57 +0530913 ENABLE_REGWRITE_BUFFER(ah);
914
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400915 /*
916 * let mac dma writes be in 128 byte chunks
917 */
Sujithf1dc5602008-10-29 10:16:30 +0530918 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
919 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
920
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400921 /*
922 * Setup receive FIFO threshold to hold off TX activities
923 */
Sujithf1dc5602008-10-29 10:16:30 +0530924 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
925
Felix Fietkau57b32222010-04-15 17:39:22 -0400926 if (AR_SREV_9300_20_OR_LATER(ah)) {
927 REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_HP, 0x1);
928 REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_LP, 0x1);
929
930 ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize -
931 ah->caps.rx_status_len);
932 }
933
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400934 /*
935 * reduce the number of usable entries in PCU TXBUF to avoid
936 * wrap around issues.
937 */
Sujithf1dc5602008-10-29 10:16:30 +0530938 if (AR_SREV_9285(ah)) {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400939 /* For AR9285 the number of Fifos are reduced to half.
940 * So set the usable tx buf size also to half to
941 * avoid data/delimiter underruns
942 */
Sujithf1dc5602008-10-29 10:16:30 +0530943 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
944 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400945 } else if (!AR_SREV_9271(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +0530946 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
947 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
948 }
Vasanthakumar Thiagarajan744d4022010-04-15 17:39:27 -0400949
Sujith7d0d0df2010-04-16 11:53:57 +0530950 REGWRITE_BUFFER_FLUSH(ah);
951 DISABLE_REGWRITE_BUFFER(ah);
952
Vasanthakumar Thiagarajan744d4022010-04-15 17:39:27 -0400953 if (AR_SREV_9300_20_OR_LATER(ah))
954 ath9k_hw_reset_txstatus_ring(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530955}
956
Sujithcbe61d82009-02-09 13:27:12 +0530957static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +0530958{
959 u32 val;
960
961 val = REG_READ(ah, AR_STA_ID1);
962 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
963 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -0800964 case NL80211_IFTYPE_AP:
Sujithf1dc5602008-10-29 10:16:30 +0530965 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
966 | AR_STA_ID1_KSRCH_MODE);
967 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
968 break;
Colin McCabed97809d2008-12-01 13:38:55 -0800969 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -0400970 case NL80211_IFTYPE_MESH_POINT:
Sujithf1dc5602008-10-29 10:16:30 +0530971 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
972 | AR_STA_ID1_KSRCH_MODE);
973 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
974 break;
Colin McCabed97809d2008-12-01 13:38:55 -0800975 case NL80211_IFTYPE_STATION:
976 case NL80211_IFTYPE_MONITOR:
Sujithf1dc5602008-10-29 10:16:30 +0530977 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
978 break;
979 }
980}
981
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400982void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled,
983 u32 *coef_mantissa, u32 *coef_exponent)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700984{
985 u32 coef_exp, coef_man;
986
987 for (coef_exp = 31; coef_exp > 0; coef_exp--)
988 if ((coef_scaled >> coef_exp) & 0x1)
989 break;
990
991 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
992
993 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
994
995 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
996 *coef_exponent = coef_exp - 16;
997}
998
Sujithcbe61d82009-02-09 13:27:12 +0530999static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +05301000{
1001 u32 rst_flags;
1002 u32 tmpReg;
1003
Sujith70768492009-02-16 13:23:12 +05301004 if (AR_SREV_9100(ah)) {
1005 u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK);
1006 val &= ~AR_RTC_DERIVED_CLK_PERIOD;
1007 val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD);
1008 REG_WRITE(ah, AR_RTC_DERIVED_CLK, val);
1009 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1010 }
1011
Sujith7d0d0df2010-04-16 11:53:57 +05301012 ENABLE_REGWRITE_BUFFER(ah);
1013
Sujithf1dc5602008-10-29 10:16:30 +05301014 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1015 AR_RTC_FORCE_WAKE_ON_INT);
1016
1017 if (AR_SREV_9100(ah)) {
1018 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1019 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1020 } else {
1021 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1022 if (tmpReg &
1023 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1024 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001025 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05301026 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001027
1028 val = AR_RC_HOSTIF;
1029 if (!AR_SREV_9300_20_OR_LATER(ah))
1030 val |= AR_RC_AHB;
1031 REG_WRITE(ah, AR_RC, val);
1032
1033 } else if (!AR_SREV_9300_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05301034 REG_WRITE(ah, AR_RC, AR_RC_AHB);
Sujithf1dc5602008-10-29 10:16:30 +05301035
1036 rst_flags = AR_RTC_RC_MAC_WARM;
1037 if (type == ATH9K_RESET_COLD)
1038 rst_flags |= AR_RTC_RC_MAC_COLD;
1039 }
1040
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001041 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujith7d0d0df2010-04-16 11:53:57 +05301042
1043 REGWRITE_BUFFER_FLUSH(ah);
1044 DISABLE_REGWRITE_BUFFER(ah);
1045
Sujithf1dc5602008-10-29 10:16:30 +05301046 udelay(50);
1047
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001048 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301049 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001050 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1051 "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301052 return false;
1053 }
1054
1055 if (!AR_SREV_9100(ah))
1056 REG_WRITE(ah, AR_RC, 0);
1057
Sujithf1dc5602008-10-29 10:16:30 +05301058 if (AR_SREV_9100(ah))
1059 udelay(50);
1060
1061 return true;
1062}
1063
Sujithcbe61d82009-02-09 13:27:12 +05301064static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301065{
Sujith7d0d0df2010-04-16 11:53:57 +05301066 ENABLE_REGWRITE_BUFFER(ah);
1067
Sujithf1dc5602008-10-29 10:16:30 +05301068 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1069 AR_RTC_FORCE_WAKE_ON_INT);
1070
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001071 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301072 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1073
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001074 REG_WRITE(ah, AR_RTC_RESET, 0);
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301075
Sujith7d0d0df2010-04-16 11:53:57 +05301076 REGWRITE_BUFFER_FLUSH(ah);
1077 DISABLE_REGWRITE_BUFFER(ah);
1078
Senthil Balasubramanian84e21692010-04-15 17:38:30 -04001079 if (!AR_SREV_9300_20_OR_LATER(ah))
1080 udelay(2);
1081
1082 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301083 REG_WRITE(ah, AR_RC, 0);
1084
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001085 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301086
1087 if (!ath9k_hw_wait(ah,
1088 AR_RTC_STATUS,
1089 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301090 AR_RTC_STATUS_ON,
1091 AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001092 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1093 "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301094 return false;
1095 }
1096
1097 ath9k_hw_read_revisions(ah);
1098
1099 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1100}
1101
Sujithcbe61d82009-02-09 13:27:12 +05301102static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301103{
1104 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1105 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1106
1107 switch (type) {
1108 case ATH9K_RESET_POWER_ON:
1109 return ath9k_hw_set_reset_power_on(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301110 case ATH9K_RESET_WARM:
1111 case ATH9K_RESET_COLD:
1112 return ath9k_hw_set_reset(ah, type);
Sujithf1dc5602008-10-29 10:16:30 +05301113 default:
1114 return false;
1115 }
1116}
1117
Sujithcbe61d82009-02-09 13:27:12 +05301118static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301119 struct ath9k_channel *chan)
1120{
Vivek Natarajan42abfbe2009-09-17 09:27:59 +05301121 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) {
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301122 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
1123 return false;
1124 } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
Sujithf1dc5602008-10-29 10:16:30 +05301125 return false;
1126
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001127 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05301128 return false;
1129
Sujith2660b812009-02-09 13:27:26 +05301130 ah->chip_fullsleep = false;
Sujithf1dc5602008-10-29 10:16:30 +05301131 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301132 ath9k_hw_set_rfmode(ah, chan);
1133
1134 return true;
1135}
1136
Sujithcbe61d82009-02-09 13:27:12 +05301137static bool ath9k_hw_channel_change(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001138 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301139{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001140 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001141 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001142 struct ieee80211_channel *channel = chan->chan;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001143 u32 qnum;
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001144 int r;
Sujithf1dc5602008-10-29 10:16:30 +05301145
1146 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1147 if (ath9k_hw_numtxpending(ah, qnum)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001148 ath_print(common, ATH_DBG_QUEUE,
1149 "Transmit frames pending on "
1150 "queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301151 return false;
1152 }
1153 }
1154
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001155 if (!ath9k_hw_rfbus_req(ah)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001156 ath_print(common, ATH_DBG_FATAL,
1157 "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301158 return false;
1159 }
1160
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001161 ath9k_hw_set_channel_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301162
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001163 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001164 if (r) {
1165 ath_print(common, ATH_DBG_FATAL,
1166 "Failed to set channel\n");
1167 return false;
Sujithf1dc5602008-10-29 10:16:30 +05301168 }
1169
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001170 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001171 ath9k_regd_get_ctl(regulatory, chan),
Sujithf74df6f2009-02-09 13:27:24 +05301172 channel->max_antenna_gain * 2,
1173 channel->max_power * 2,
1174 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001175 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05301176
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001177 ath9k_hw_rfbus_done(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301178
1179 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1180 ath9k_hw_set_delta_slope(ah, chan);
1181
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001182 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301183
1184 if (!chan->oneTimeCalsDone)
1185 chan->oneTimeCalsDone = true;
1186
1187 return true;
1188}
1189
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001190bool ath9k_hw_check_alive(struct ath_hw *ah)
1191{
1192 int count = 50;
1193 u32 reg;
1194
1195 if (AR_SREV_9285_10_OR_LATER(ah))
1196 return true;
1197
1198 do {
1199 reg = REG_READ(ah, AR_OBS_BUS_1);
1200
1201 if ((reg & 0x7E7FFFEF) == 0x00702400)
1202 continue;
1203
1204 switch (reg & 0x7E000B00) {
1205 case 0x1E000000:
1206 case 0x52000B00:
1207 case 0x18000B00:
1208 continue;
1209 default:
1210 return true;
1211 }
1212 } while (count-- > 0);
1213
1214 return false;
1215}
1216EXPORT_SYMBOL(ath9k_hw_check_alive);
1217
Sujithcbe61d82009-02-09 13:27:12 +05301218int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001219 bool bChannelChange)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001220{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001221 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001222 u32 saveLedState;
Sujith2660b812009-02-09 13:27:26 +05301223 struct ath9k_channel *curchan = ah->curchan;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001224 u32 saveDefAntenna;
1225 u32 macStaId1;
Sujith46fe7822009-09-17 09:25:25 +05301226 u64 tsf = 0;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001227 int i, r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001228
Luis R. Rodriguez43c27612009-09-13 21:07:07 -07001229 ah->txchainmask = common->tx_chainmask;
1230 ah->rxchainmask = common->rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001231
Vasanthakumar Thiagarajan9b9cc612010-04-15 17:39:41 -04001232 if (!ah->chip_fullsleep) {
1233 ath9k_hw_abortpcurecv(ah);
1234 if (!ath9k_hw_stopdmarecv(ah))
1235 ath_print(common, ATH_DBG_XMIT,
1236 "Failed to stop receive dma\n");
1237 }
1238
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001239 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001240 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001241
Vasanthakumar Thiagarajan9ebef792009-09-17 09:26:44 +05301242 if (curchan && !ah->chip_fullsleep)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001243 ath9k_hw_getnf(ah, curchan);
1244
1245 if (bChannelChange &&
Sujith2660b812009-02-09 13:27:26 +05301246 (ah->chip_fullsleep != true) &&
1247 (ah->curchan != NULL) &&
1248 (chan->channel != ah->curchan->channel) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001249 ((chan->channelFlags & CHANNEL_ALL) ==
Sujith2660b812009-02-09 13:27:26 +05301250 (ah->curchan->channelFlags & CHANNEL_ALL)) &&
Felix Fietkau6b42e8d2010-04-26 15:04:35 -04001251 !AR_SREV_9280(ah)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001252
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001253 if (ath9k_hw_channel_change(ah, chan)) {
Sujith2660b812009-02-09 13:27:26 +05301254 ath9k_hw_loadnf(ah, ah->curchan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001255 ath9k_hw_start_nfcal(ah);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001256 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001257 }
1258 }
1259
1260 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
1261 if (saveDefAntenna == 0)
1262 saveDefAntenna = 1;
1263
1264 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
1265
Sujith46fe7822009-09-17 09:25:25 +05301266 /* For chips on which RTC reset is done, save TSF before it gets cleared */
1267 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1268 tsf = ath9k_hw_gettsf64(ah);
1269
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001270 saveLedState = REG_READ(ah, AR_CFG_LED) &
1271 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
1272 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
1273
1274 ath9k_hw_mark_phy_inactive(ah);
1275
Sujith05020d22010-03-17 14:25:23 +05301276 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001277 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1278 REG_WRITE(ah,
1279 AR9271_RESET_POWER_DOWN_CONTROL,
1280 AR9271_RADIO_RF_RST);
1281 udelay(50);
1282 }
1283
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001284 if (!ath9k_hw_chip_reset(ah, chan)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001285 ath_print(common, ATH_DBG_FATAL, "Chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001286 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001287 }
1288
Sujith05020d22010-03-17 14:25:23 +05301289 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001290 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1291 ah->htc_reset_init = false;
1292 REG_WRITE(ah,
1293 AR9271_RESET_POWER_DOWN_CONTROL,
1294 AR9271_GATE_MAC_CTL);
1295 udelay(50);
1296 }
1297
Sujith46fe7822009-09-17 09:25:25 +05301298 /* Restore TSF */
1299 if (tsf && AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1300 ath9k_hw_settsf64(ah, tsf);
1301
Vasanthakumar Thiagarajan369391d2009-01-21 19:24:13 +05301302 if (AR_SREV_9280_10_OR_LATER(ah))
1303 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001304
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001305 r = ath9k_hw_process_ini(ah, chan);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001306 if (r)
1307 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001308
Jouni Malinen0ced0e12009-01-08 13:32:13 +02001309 /* Setup MFP options for CCMP */
1310 if (AR_SREV_9280_20_OR_LATER(ah)) {
1311 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
1312 * frames when constructing CCMP AAD. */
1313 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
1314 0xc7ff);
1315 ah->sw_mgmt_crypto = false;
1316 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1317 /* Disable hardware crypto for management frames */
1318 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
1319 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
1320 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1321 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
1322 ah->sw_mgmt_crypto = true;
1323 } else
1324 ah->sw_mgmt_crypto = true;
1325
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001326 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1327 ath9k_hw_set_delta_slope(ah, chan);
1328
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001329 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithd6509152009-03-13 08:56:05 +05301330 ah->eep_ops->set_board_values(ah, chan);
Luis R. Rodrigueza7765822009-10-19 02:33:45 -04001331
Sujith6819d572010-04-16 11:53:56 +05301332 ath9k_hw_set_operating_mode(ah, ah->opmode);
1333
Sujith7d0d0df2010-04-16 11:53:57 +05301334 ENABLE_REGWRITE_BUFFER(ah);
1335
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001336 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
1337 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001338 | macStaId1
1339 | AR_STA_ID1_RTS_USE_DEF
Sujith2660b812009-02-09 13:27:26 +05301340 | (ah->config.
Sujith60b67f52008-08-07 10:52:38 +05301341 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Sujith2660b812009-02-09 13:27:26 +05301342 | ah->sta_id1_defaults);
Luis R. Rodriguez13b81552009-09-10 17:52:45 -07001343 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001344 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
Luis R. Rodriguez3453ad82009-09-10 08:57:00 -07001345 ath9k_hw_write_associd(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001346 REG_WRITE(ah, AR_ISR, ~0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001347 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
1348
Sujith7d0d0df2010-04-16 11:53:57 +05301349 REGWRITE_BUFFER_FLUSH(ah);
1350 DISABLE_REGWRITE_BUFFER(ah);
1351
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001352 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001353 if (r)
1354 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001355
Sujith7d0d0df2010-04-16 11:53:57 +05301356 ENABLE_REGWRITE_BUFFER(ah);
1357
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001358 for (i = 0; i < AR_NUM_DCU; i++)
1359 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
1360
Sujith7d0d0df2010-04-16 11:53:57 +05301361 REGWRITE_BUFFER_FLUSH(ah);
1362 DISABLE_REGWRITE_BUFFER(ah);
1363
Sujith2660b812009-02-09 13:27:26 +05301364 ah->intr_txqs = 0;
1365 for (i = 0; i < ah->caps.total_queues; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001366 ath9k_hw_resettxqueue(ah, i);
1367
Sujith2660b812009-02-09 13:27:26 +05301368 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001369 ath9k_hw_init_qos(ah);
1370
Sujith2660b812009-02-09 13:27:26 +05301371 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301372 ath9k_enable_rfkill(ah);
Johannes Berg3b319aa2009-06-13 14:50:26 +05301373
Felix Fietkau0005baf2010-01-15 02:33:40 +01001374 ath9k_hw_init_global_settings(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001375
Luis R. Rodriguez6c94fdc2010-04-15 17:39:24 -04001376 if (!AR_SREV_9300_20_OR_LATER(ah)) {
Luis R. Rodriguez78ec2672010-04-15 17:39:23 -04001377 ar9002_hw_enable_async_fifo(ah);
Luis R. Rodriguez6c94fdc2010-04-15 17:39:24 -04001378 ar9002_hw_enable_wep_aggregation(ah);
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301379 }
1380
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001381 REG_WRITE(ah, AR_STA_ID1,
1382 REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
1383
1384 ath9k_hw_set_dma(ah);
1385
1386 REG_WRITE(ah, AR_OBS, 8);
1387
Sujith0ce024c2009-12-14 14:57:00 +05301388 if (ah->config.rx_intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001389 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
1390 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
1391 }
1392
Vasanthakumar Thiagarajan7f62a132010-04-15 17:39:19 -04001393 if (ah->config.tx_intr_mitigation) {
1394 REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_LAST, 300);
1395 REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_FIRST, 750);
1396 }
1397
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001398 ath9k_hw_init_bb(ah, chan);
1399
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001400 if (!ath9k_hw_init_cal(ah, chan))
Joe Perches6badaaf2009-06-28 09:26:32 -07001401 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001402
Sujith7d0d0df2010-04-16 11:53:57 +05301403 ENABLE_REGWRITE_BUFFER(ah);
1404
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001405 ath9k_hw_restore_chainmask(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001406 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
1407
Sujith7d0d0df2010-04-16 11:53:57 +05301408 REGWRITE_BUFFER_FLUSH(ah);
1409 DISABLE_REGWRITE_BUFFER(ah);
1410
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001411 /*
1412 * For big endian systems turn on swapping for descriptors
1413 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001414 if (AR_SREV_9100(ah)) {
1415 u32 mask;
1416 mask = REG_READ(ah, AR_CFG);
1417 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001418 ath_print(common, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05301419 "CFG Byte Swap Set 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001420 } else {
1421 mask =
1422 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
1423 REG_WRITE(ah, AR_CFG, mask);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001424 ath_print(common, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05301425 "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001426 }
1427 } else {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001428 /* Configure AR9271 target WLAN */
1429 if (AR_SREV_9271(ah))
1430 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001431#ifdef __BIG_ENDIAN
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001432 else
1433 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001434#endif
1435 }
1436
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001437 if (ah->btcoex_hw.enabled)
Vasanthakumar Thiagarajan42cc41e2009-08-26 21:08:45 +05301438 ath9k_hw_btcoex_enable(ah);
1439
Vasanthakumar Thiagarajand8903a52010-04-15 17:39:25 -04001440 if (AR_SREV_9300_20_OR_LATER(ah)) {
1441 ath9k_hw_loadnf(ah, curchan);
1442 ath9k_hw_start_nfcal(ah);
1443 }
1444
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001445 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001446}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001447EXPORT_SYMBOL(ath9k_hw_reset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001448
Sujithf1dc5602008-10-29 10:16:30 +05301449/************************/
1450/* Key Cache Management */
1451/************************/
1452
Sujithcbe61d82009-02-09 13:27:12 +05301453bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001454{
Sujithf1dc5602008-10-29 10:16:30 +05301455 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001456
Sujith2660b812009-02-09 13:27:26 +05301457 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001458 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1459 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001460 return false;
1461 }
1462
Sujithf1dc5602008-10-29 10:16:30 +05301463 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001464
Sujithf1dc5602008-10-29 10:16:30 +05301465 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
1466 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
1467 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
1468 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
1469 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
1470 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
1471 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
1472 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
1473
1474 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
1475 u16 micentry = entry + 64;
1476
1477 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
1478 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
1479 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
1480 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
1481
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001482 }
1483
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001484 return true;
1485}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001486EXPORT_SYMBOL(ath9k_hw_keyreset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001487
Sujithcbe61d82009-02-09 13:27:12 +05301488bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001489{
Sujithf1dc5602008-10-29 10:16:30 +05301490 u32 macHi, macLo;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001491
Sujith2660b812009-02-09 13:27:26 +05301492 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001493 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1494 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001495 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001496 }
1497
Sujithf1dc5602008-10-29 10:16:30 +05301498 if (mac != NULL) {
1499 macHi = (mac[5] << 8) | mac[4];
1500 macLo = (mac[3] << 24) |
1501 (mac[2] << 16) |
1502 (mac[1] << 8) |
1503 mac[0];
1504 macLo >>= 1;
1505 macLo |= (macHi & 1) << 31;
1506 macHi >>= 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001507 } else {
Sujithf1dc5602008-10-29 10:16:30 +05301508 macLo = macHi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001509 }
Sujithf1dc5602008-10-29 10:16:30 +05301510 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
1511 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001512
1513 return true;
1514}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001515EXPORT_SYMBOL(ath9k_hw_keysetmac);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001516
Sujithcbe61d82009-02-09 13:27:12 +05301517bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
Sujithf1dc5602008-10-29 10:16:30 +05301518 const struct ath9k_keyval *k,
Jouni Malinene0caf9e2009-03-02 18:15:53 +02001519 const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001520{
Sujith2660b812009-02-09 13:27:26 +05301521 const struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001522 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301523 u32 key0, key1, key2, key3, key4;
1524 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001525
Sujithf1dc5602008-10-29 10:16:30 +05301526 if (entry >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001527 ath_print(common, ATH_DBG_FATAL,
1528 "keycache entry %u out of range\n", entry);
Sujithf1dc5602008-10-29 10:16:30 +05301529 return false;
1530 }
1531
1532 switch (k->kv_type) {
1533 case ATH9K_CIPHER_AES_OCB:
1534 keyType = AR_KEYTABLE_TYPE_AES;
1535 break;
1536 case ATH9K_CIPHER_AES_CCM:
1537 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001538 ath_print(common, ATH_DBG_ANY,
1539 "AES-CCM not supported by mac rev 0x%x\n",
1540 ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001541 return false;
1542 }
Sujithf1dc5602008-10-29 10:16:30 +05301543 keyType = AR_KEYTABLE_TYPE_CCM;
1544 break;
1545 case ATH9K_CIPHER_TKIP:
1546 keyType = AR_KEYTABLE_TYPE_TKIP;
1547 if (ATH9K_IS_MIC_ENABLED(ah)
1548 && entry + 64 >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001549 ath_print(common, ATH_DBG_ANY,
1550 "entry %u inappropriate for TKIP\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001551 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001552 }
Sujithf1dc5602008-10-29 10:16:30 +05301553 break;
1554 case ATH9K_CIPHER_WEP:
Zhu Yie31a16d2009-05-21 21:47:03 +08001555 if (k->kv_len < WLAN_KEY_LEN_WEP40) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001556 ath_print(common, ATH_DBG_ANY,
1557 "WEP key length %u too small\n", k->kv_len);
Sujithf1dc5602008-10-29 10:16:30 +05301558 return false;
1559 }
Zhu Yie31a16d2009-05-21 21:47:03 +08001560 if (k->kv_len <= WLAN_KEY_LEN_WEP40)
Sujithf1dc5602008-10-29 10:16:30 +05301561 keyType = AR_KEYTABLE_TYPE_40;
Zhu Yie31a16d2009-05-21 21:47:03 +08001562 else if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05301563 keyType = AR_KEYTABLE_TYPE_104;
1564 else
1565 keyType = AR_KEYTABLE_TYPE_128;
1566 break;
1567 case ATH9K_CIPHER_CLR:
1568 keyType = AR_KEYTABLE_TYPE_CLR;
1569 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001570 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001571 ath_print(common, ATH_DBG_FATAL,
1572 "cipher %u not supported\n", k->kv_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001573 return false;
1574 }
Sujithf1dc5602008-10-29 10:16:30 +05301575
Jouni Malinene0caf9e2009-03-02 18:15:53 +02001576 key0 = get_unaligned_le32(k->kv_val + 0);
1577 key1 = get_unaligned_le16(k->kv_val + 4);
1578 key2 = get_unaligned_le32(k->kv_val + 6);
1579 key3 = get_unaligned_le16(k->kv_val + 10);
1580 key4 = get_unaligned_le32(k->kv_val + 12);
Zhu Yie31a16d2009-05-21 21:47:03 +08001581 if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05301582 key4 &= 0xff;
1583
Jouni Malinen672903b2009-03-02 15:06:31 +02001584 /*
1585 * Note: Key cache registers access special memory area that requires
1586 * two 32-bit writes to actually update the values in the internal
1587 * memory. Consequently, the exact order and pairs used here must be
1588 * maintained.
1589 */
1590
Sujithf1dc5602008-10-29 10:16:30 +05301591 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
1592 u16 micentry = entry + 64;
1593
Jouni Malinen672903b2009-03-02 15:06:31 +02001594 /*
1595 * Write inverted key[47:0] first to avoid Michael MIC errors
1596 * on frames that could be sent or received at the same time.
1597 * The correct key will be written in the end once everything
1598 * else is ready.
1599 */
Sujithf1dc5602008-10-29 10:16:30 +05301600 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
1601 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02001602
1603 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05301604 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
1605 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02001606
1607 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05301608 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
1609 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
Jouni Malinen672903b2009-03-02 15:06:31 +02001610
1611 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05301612 (void) ath9k_hw_keysetmac(ah, entry, mac);
1613
Sujith2660b812009-02-09 13:27:26 +05301614 if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) {
Jouni Malinen672903b2009-03-02 15:06:31 +02001615 /*
1616 * TKIP uses two key cache entries:
1617 * Michael MIC TX/RX keys in the same key cache entry
1618 * (idx = main index + 64):
1619 * key0 [31:0] = RX key [31:0]
1620 * key1 [15:0] = TX key [31:16]
1621 * key1 [31:16] = reserved
1622 * key2 [31:0] = RX key [63:32]
1623 * key3 [15:0] = TX key [15:0]
1624 * key3 [31:16] = reserved
1625 * key4 [31:0] = TX key [63:32]
1626 */
Sujithf1dc5602008-10-29 10:16:30 +05301627 u32 mic0, mic1, mic2, mic3, mic4;
1628
1629 mic0 = get_unaligned_le32(k->kv_mic + 0);
1630 mic2 = get_unaligned_le32(k->kv_mic + 4);
1631 mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
1632 mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
1633 mic4 = get_unaligned_le32(k->kv_txmic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02001634
1635 /* Write RX[31:0] and TX[31:16] */
Sujithf1dc5602008-10-29 10:16:30 +05301636 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
1637 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
Jouni Malinen672903b2009-03-02 15:06:31 +02001638
1639 /* Write RX[63:32] and TX[15:0] */
Sujithf1dc5602008-10-29 10:16:30 +05301640 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
1641 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
Jouni Malinen672903b2009-03-02 15:06:31 +02001642
1643 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05301644 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
1645 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
1646 AR_KEYTABLE_TYPE_CLR);
1647
1648 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02001649 /*
1650 * TKIP uses four key cache entries (two for group
1651 * keys):
1652 * Michael MIC TX/RX keys are in different key cache
1653 * entries (idx = main index + 64 for TX and
1654 * main index + 32 + 96 for RX):
1655 * key0 [31:0] = TX/RX MIC key [31:0]
1656 * key1 [31:0] = reserved
1657 * key2 [31:0] = TX/RX MIC key [63:32]
1658 * key3 [31:0] = reserved
1659 * key4 [31:0] = reserved
1660 *
1661 * Upper layer code will call this function separately
1662 * for TX and RX keys when these registers offsets are
1663 * used.
1664 */
Sujithf1dc5602008-10-29 10:16:30 +05301665 u32 mic0, mic2;
1666
1667 mic0 = get_unaligned_le32(k->kv_mic + 0);
1668 mic2 = get_unaligned_le32(k->kv_mic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02001669
1670 /* Write MIC key[31:0] */
Sujithf1dc5602008-10-29 10:16:30 +05301671 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
1672 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02001673
1674 /* Write MIC key[63:32] */
Sujithf1dc5602008-10-29 10:16:30 +05301675 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
1676 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02001677
1678 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05301679 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
1680 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
1681 AR_KEYTABLE_TYPE_CLR);
1682 }
Jouni Malinen672903b2009-03-02 15:06:31 +02001683
1684 /* MAC address registers are reserved for the MIC entry */
Sujithf1dc5602008-10-29 10:16:30 +05301685 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
1686 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02001687
1688 /*
1689 * Write the correct (un-inverted) key[47:0] last to enable
1690 * TKIP now that all other registers are set with correct
1691 * values.
1692 */
Sujithf1dc5602008-10-29 10:16:30 +05301693 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
1694 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
1695 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02001696 /* Write key[47:0] */
Sujithf1dc5602008-10-29 10:16:30 +05301697 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
1698 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02001699
1700 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05301701 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
1702 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02001703
1704 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05301705 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
1706 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
1707
Jouni Malinen672903b2009-03-02 15:06:31 +02001708 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05301709 (void) ath9k_hw_keysetmac(ah, entry, mac);
1710 }
1711
Sujithf1dc5602008-10-29 10:16:30 +05301712 return true;
1713}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001714EXPORT_SYMBOL(ath9k_hw_set_keycache_entry);
Sujithf1dc5602008-10-29 10:16:30 +05301715
Sujithcbe61d82009-02-09 13:27:12 +05301716bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry)
Sujithf1dc5602008-10-29 10:16:30 +05301717{
Sujith2660b812009-02-09 13:27:26 +05301718 if (entry < ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05301719 u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
1720 if (val & AR_KEYTABLE_VALID)
1721 return true;
1722 }
1723 return false;
1724}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001725EXPORT_SYMBOL(ath9k_hw_keyisvalid);
Sujithf1dc5602008-10-29 10:16:30 +05301726
1727/******************************/
1728/* Power Management (Chipset) */
1729/******************************/
1730
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001731/*
1732 * Notify Power Mgt is disabled in self-generated frames.
1733 * If requested, force chip to sleep.
1734 */
Sujithcbe61d82009-02-09 13:27:12 +05301735static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05301736{
1737 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
1738 if (setChip) {
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001739 /*
1740 * Clear the RTC force wake bit to allow the
1741 * mac to go to sleep.
1742 */
Sujithf1dc5602008-10-29 10:16:30 +05301743 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
1744 AR_RTC_FORCE_WAKE_EN);
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001745 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05301746 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1747
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001748 /* Shutdown chip. Active low */
Sujith14b3af32010-03-17 14:25:18 +05301749 if (!AR_SREV_5416(ah) && !AR_SREV_9271(ah))
Sujith4921be82009-09-18 15:04:27 +05301750 REG_CLR_BIT(ah, (AR_RTC_RESET),
1751 AR_RTC_RESET_EN);
Sujithf1dc5602008-10-29 10:16:30 +05301752 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001753}
1754
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04001755/*
1756 * Notify Power Management is enabled in self-generating
1757 * frames. If request, set power mode of chip to
1758 * auto/normal. Duration in units of 128us (1/8 TU).
1759 */
Sujithcbe61d82009-02-09 13:27:12 +05301760static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001761{
Sujithf1dc5602008-10-29 10:16:30 +05301762 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
1763 if (setChip) {
Sujith2660b812009-02-09 13:27:26 +05301764 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001765
Sujithf1dc5602008-10-29 10:16:30 +05301766 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04001767 /* Set WakeOnInterrupt bit; clear ForceWake bit */
Sujithf1dc5602008-10-29 10:16:30 +05301768 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1769 AR_RTC_FORCE_WAKE_ON_INT);
1770 } else {
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04001771 /*
1772 * Clear the RTC force wake bit to allow the
1773 * mac to go to sleep.
1774 */
Sujithf1dc5602008-10-29 10:16:30 +05301775 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
1776 AR_RTC_FORCE_WAKE_EN);
1777 }
1778 }
1779}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001780
Sujithcbe61d82009-02-09 13:27:12 +05301781static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05301782{
1783 u32 val;
1784 int i;
1785
1786 if (setChip) {
1787 if ((REG_READ(ah, AR_RTC_STATUS) &
1788 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
1789 if (ath9k_hw_set_reset_reg(ah,
1790 ATH9K_RESET_POWER_ON) != true) {
1791 return false;
1792 }
Luis R. Rodrigueze0412282010-04-15 17:38:15 -04001793 if (!AR_SREV_9300_20_OR_LATER(ah))
1794 ath9k_hw_init_pll(ah, NULL);
Sujithf1dc5602008-10-29 10:16:30 +05301795 }
1796 if (AR_SREV_9100(ah))
1797 REG_SET_BIT(ah, AR_RTC_RESET,
1798 AR_RTC_RESET_EN);
1799
1800 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
1801 AR_RTC_FORCE_WAKE_EN);
1802 udelay(50);
1803
1804 for (i = POWER_UP_TIME / 50; i > 0; i--) {
1805 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
1806 if (val == AR_RTC_STATUS_ON)
1807 break;
1808 udelay(50);
1809 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
1810 AR_RTC_FORCE_WAKE_EN);
1811 }
1812 if (i == 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001813 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1814 "Failed to wakeup in %uus\n",
1815 POWER_UP_TIME / 20);
Sujithf1dc5602008-10-29 10:16:30 +05301816 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001817 }
1818 }
1819
Sujithf1dc5602008-10-29 10:16:30 +05301820 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
1821
1822 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001823}
1824
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001825bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05301826{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001827 struct ath_common *common = ath9k_hw_common(ah);
Sujithcbe61d82009-02-09 13:27:12 +05301828 int status = true, setChip = true;
Sujithf1dc5602008-10-29 10:16:30 +05301829 static const char *modes[] = {
1830 "AWAKE",
1831 "FULL-SLEEP",
1832 "NETWORK SLEEP",
1833 "UNDEFINED"
1834 };
Sujithf1dc5602008-10-29 10:16:30 +05301835
Gabor Juhoscbdec972009-07-24 17:27:22 +02001836 if (ah->power_mode == mode)
1837 return status;
1838
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001839 ath_print(common, ATH_DBG_RESET, "%s -> %s\n",
1840 modes[ah->power_mode], modes[mode]);
Sujithf1dc5602008-10-29 10:16:30 +05301841
1842 switch (mode) {
1843 case ATH9K_PM_AWAKE:
1844 status = ath9k_hw_set_power_awake(ah, setChip);
1845 break;
1846 case ATH9K_PM_FULL_SLEEP:
1847 ath9k_set_power_sleep(ah, setChip);
Sujith2660b812009-02-09 13:27:26 +05301848 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05301849 break;
1850 case ATH9K_PM_NETWORK_SLEEP:
1851 ath9k_set_power_network_sleep(ah, setChip);
1852 break;
1853 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001854 ath_print(common, ATH_DBG_FATAL,
1855 "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05301856 return false;
1857 }
Sujith2660b812009-02-09 13:27:26 +05301858 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05301859
1860 return status;
1861}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001862EXPORT_SYMBOL(ath9k_hw_setpower);
Sujithf1dc5602008-10-29 10:16:30 +05301863
Sujithf1dc5602008-10-29 10:16:30 +05301864/*******************/
1865/* Beacon Handling */
1866/*******************/
1867
Sujithcbe61d82009-02-09 13:27:12 +05301868void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001869{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001870 int flags = 0;
1871
Sujith2660b812009-02-09 13:27:26 +05301872 ah->beacon_interval = beacon_period;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001873
Sujith7d0d0df2010-04-16 11:53:57 +05301874 ENABLE_REGWRITE_BUFFER(ah);
1875
Sujith2660b812009-02-09 13:27:26 +05301876 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001877 case NL80211_IFTYPE_STATION:
1878 case NL80211_IFTYPE_MONITOR:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001879 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
1880 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
1881 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
1882 flags |= AR_TBTT_TIMER_EN;
1883 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001884 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04001885 case NL80211_IFTYPE_MESH_POINT:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001886 REG_SET_BIT(ah, AR_TXCFG,
1887 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
1888 REG_WRITE(ah, AR_NEXT_NDP_TIMER,
1889 TU_TO_USEC(next_beacon +
Sujith2660b812009-02-09 13:27:26 +05301890 (ah->atim_window ? ah->
1891 atim_window : 1)));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001892 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08001893 case NL80211_IFTYPE_AP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001894 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
1895 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
1896 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05301897 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05301898 dma_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001899 REG_WRITE(ah, AR_NEXT_SWBA,
1900 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05301901 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05301902 sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001903 flags |=
1904 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
1905 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001906 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001907 ath_print(ath9k_hw_common(ah), ATH_DBG_BEACON,
1908 "%s: unsupported opmode: %d\n",
1909 __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08001910 return;
1911 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001912 }
1913
1914 REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
1915 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
1916 REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
1917 REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
1918
Sujith7d0d0df2010-04-16 11:53:57 +05301919 REGWRITE_BUFFER_FLUSH(ah);
1920 DISABLE_REGWRITE_BUFFER(ah);
1921
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001922 beacon_period &= ~ATH9K_BEACON_ENA;
1923 if (beacon_period & ATH9K_BEACON_RESET_TSF) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001924 ath9k_hw_reset_tsf(ah);
1925 }
1926
1927 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
1928}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001929EXPORT_SYMBOL(ath9k_hw_beaconinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001930
Sujithcbe61d82009-02-09 13:27:12 +05301931void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301932 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001933{
1934 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05301935 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001936 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001937
Sujith7d0d0df2010-04-16 11:53:57 +05301938 ENABLE_REGWRITE_BUFFER(ah);
1939
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001940 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
1941
1942 REG_WRITE(ah, AR_BEACON_PERIOD,
1943 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
1944 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
1945 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
1946
Sujith7d0d0df2010-04-16 11:53:57 +05301947 REGWRITE_BUFFER_FLUSH(ah);
1948 DISABLE_REGWRITE_BUFFER(ah);
1949
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001950 REG_RMW_FIELD(ah, AR_RSSI_THR,
1951 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
1952
1953 beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
1954
1955 if (bs->bs_sleepduration > beaconintval)
1956 beaconintval = bs->bs_sleepduration;
1957
1958 dtimperiod = bs->bs_dtimperiod;
1959 if (bs->bs_sleepduration > dtimperiod)
1960 dtimperiod = bs->bs_sleepduration;
1961
1962 if (beaconintval == dtimperiod)
1963 nextTbtt = bs->bs_nextdtim;
1964 else
1965 nextTbtt = bs->bs_nexttbtt;
1966
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001967 ath_print(common, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
1968 ath_print(common, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
1969 ath_print(common, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
1970 ath_print(common, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001971
Sujith7d0d0df2010-04-16 11:53:57 +05301972 ENABLE_REGWRITE_BUFFER(ah);
1973
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001974 REG_WRITE(ah, AR_NEXT_DTIM,
1975 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
1976 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
1977
1978 REG_WRITE(ah, AR_SLEEP1,
1979 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
1980 | AR_SLEEP1_ASSUME_DTIM);
1981
Sujith60b67f52008-08-07 10:52:38 +05301982 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001983 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
1984 else
1985 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
1986
1987 REG_WRITE(ah, AR_SLEEP2,
1988 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
1989
1990 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
1991 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
1992
Sujith7d0d0df2010-04-16 11:53:57 +05301993 REGWRITE_BUFFER_FLUSH(ah);
1994 DISABLE_REGWRITE_BUFFER(ah);
1995
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001996 REG_SET_BIT(ah, AR_TIMER_MODE,
1997 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
1998 AR_DTIM_TIMER_EN);
1999
Sujith4af9cf42009-02-12 10:06:47 +05302000 /* TSF Out of Range Threshold */
2001 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002002}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002003EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002004
Sujithf1dc5602008-10-29 10:16:30 +05302005/*******************/
2006/* HW Capabilities */
2007/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002008
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002009int ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002010{
Sujith2660b812009-02-09 13:27:26 +05302011 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002012 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002013 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002014 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002015
Sujithf1dc5602008-10-29 10:16:30 +05302016 u16 capField = 0, eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002017
Sujithf74df6f2009-02-09 13:27:24 +05302018 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002019 regulatory->current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05302020
Sujithf74df6f2009-02-09 13:27:24 +05302021 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
Sujithfec0de12009-02-12 10:06:43 +05302022 if (AR_SREV_9285_10_OR_LATER(ah))
2023 eeval |= AR9285_RDEXT_DEFAULT;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002024 regulatory->current_rd_ext = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05302025
Sujithf74df6f2009-02-09 13:27:24 +05302026 capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
Sujithf1dc5602008-10-29 10:16:30 +05302027
Sujith2660b812009-02-09 13:27:26 +05302028 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05302029 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002030 if (regulatory->current_rd == 0x64 ||
2031 regulatory->current_rd == 0x65)
2032 regulatory->current_rd += 5;
2033 else if (regulatory->current_rd == 0x41)
2034 regulatory->current_rd = 0x43;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002035 ath_print(common, ATH_DBG_REGULATORY,
2036 "regdomain mapped to 0x%x\n", regulatory->current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002037 }
Sujithdc2222a2008-08-14 13:26:55 +05302038
Sujithf74df6f2009-02-09 13:27:24 +05302039 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002040 if ((eeval & (AR5416_OPFLAGS_11G | AR5416_OPFLAGS_11A)) == 0) {
2041 ath_print(common, ATH_DBG_FATAL,
2042 "no band has been marked as supported in EEPROM.\n");
2043 return -EINVAL;
2044 }
2045
Sujithf1dc5602008-10-29 10:16:30 +05302046 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002047
Sujithf1dc5602008-10-29 10:16:30 +05302048 if (eeval & AR5416_OPFLAGS_11A) {
2049 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05302050 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05302051 if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
2052 set_bit(ATH9K_MODE_11NA_HT20,
2053 pCap->wireless_modes);
2054 if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
2055 set_bit(ATH9K_MODE_11NA_HT40PLUS,
2056 pCap->wireless_modes);
2057 set_bit(ATH9K_MODE_11NA_HT40MINUS,
2058 pCap->wireless_modes);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002059 }
2060 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002061 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002062
Sujithf1dc5602008-10-29 10:16:30 +05302063 if (eeval & AR5416_OPFLAGS_11G) {
Sujithf1dc5602008-10-29 10:16:30 +05302064 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05302065 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05302066 if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
2067 set_bit(ATH9K_MODE_11NG_HT20,
2068 pCap->wireless_modes);
2069 if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
2070 set_bit(ATH9K_MODE_11NG_HT40PLUS,
2071 pCap->wireless_modes);
2072 set_bit(ATH9K_MODE_11NG_HT40MINUS,
2073 pCap->wireless_modes);
2074 }
2075 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002076 }
Sujithf1dc5602008-10-29 10:16:30 +05302077
Sujithf74df6f2009-02-09 13:27:24 +05302078 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002079 /*
2080 * For AR9271 we will temporarilly uses the rx chainmax as read from
2081 * the EEPROM.
2082 */
Sujith8147f5d2009-02-20 15:13:23 +05302083 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002084 !(eeval & AR5416_OPFLAGS_11A) &&
2085 !(AR_SREV_9271(ah)))
2086 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
Sujith8147f5d2009-02-20 15:13:23 +05302087 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
2088 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002089 /* Use rx_chainmask from EEPROM. */
Sujith8147f5d2009-02-20 15:13:23 +05302090 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05302091
Sujithd535a422009-02-09 13:27:06 +05302092 if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0)))
Sujith2660b812009-02-09 13:27:26 +05302093 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05302094
2095 pCap->low_2ghz_chan = 2312;
2096 pCap->high_2ghz_chan = 2732;
2097
2098 pCap->low_5ghz_chan = 4920;
2099 pCap->high_5ghz_chan = 6100;
2100
2101 pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
2102 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
2103 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
2104
2105 pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
2106 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
2107 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
2108
Sujith2660b812009-02-09 13:27:26 +05302109 if (ah->config.ht_enable)
Sujithf1dc5602008-10-29 10:16:30 +05302110 pCap->hw_caps |= ATH9K_HW_CAP_HT;
2111 else
2112 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
2113
2114 pCap->hw_caps |= ATH9K_HW_CAP_GTT;
2115 pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
2116 pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
2117 pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
2118
2119 if (capField & AR_EEPROM_EEPCAP_MAXQCU)
2120 pCap->total_queues =
2121 MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
2122 else
2123 pCap->total_queues = ATH9K_NUM_TX_QUEUES;
2124
2125 if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
2126 pCap->keycache_size =
2127 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
2128 else
2129 pCap->keycache_size = AR_KEYTABLE_SIZE;
2130
2131 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -05002132
2133 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
2134 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD >> 1;
2135 else
2136 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
Sujithf1dc5602008-10-29 10:16:30 +05302137
Sujith5b5fa352010-03-17 14:25:15 +05302138 if (AR_SREV_9271(ah))
2139 pCap->num_gpio_pins = AR9271_NUM_GPIO;
2140 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302141 pCap->num_gpio_pins = AR9285_NUM_GPIO;
2142 else if (AR_SREV_9280_10_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302143 pCap->num_gpio_pins = AR928X_NUM_GPIO;
2144 else
2145 pCap->num_gpio_pins = AR_NUM_GPIO;
2146
Sujithf1dc5602008-10-29 10:16:30 +05302147 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
2148 pCap->hw_caps |= ATH9K_HW_CAP_CST;
2149 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
2150 } else {
2151 pCap->rts_aggr_limit = (8 * 1024);
2152 }
2153
2154 pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
2155
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05302156#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05302157 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
2158 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
2159 ah->rfkill_gpio =
2160 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
2161 ah->rfkill_polarity =
2162 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05302163
2164 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
2165 }
2166#endif
Vivek Natarajanbde748a2010-04-05 14:48:05 +05302167 if (AR_SREV_9271(ah))
2168 pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
2169 else
2170 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
Sujithf1dc5602008-10-29 10:16:30 +05302171
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302172 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302173 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
2174 else
2175 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
2176
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002177 if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) {
Sujithf1dc5602008-10-29 10:16:30 +05302178 pCap->reg_cap =
2179 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
2180 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
2181 AR_EEPROM_EEREGCAP_EN_KK_U2 |
2182 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
2183 } else {
2184 pCap->reg_cap =
2185 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
2186 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
2187 }
2188
Senthil Balasubramanianebb90cf2009-09-18 15:07:33 +05302189 /* Advertise midband for AR5416 with FCC midband set in eeprom */
2190 if (regulatory->current_rd_ext & (1 << REG_EXT_FCC_MIDBAND) &&
2191 AR_SREV_5416(ah))
2192 pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
Sujithf1dc5602008-10-29 10:16:30 +05302193
2194 pCap->num_antcfg_5ghz =
Sujithf74df6f2009-02-09 13:27:24 +05302195 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05302196 pCap->num_antcfg_2ghz =
Sujithf74df6f2009-02-09 13:27:24 +05302197 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05302198
Vasanthakumar Thiagarajanfe129462009-09-09 15:25:50 +05302199 if (AR_SREV_9280_10_OR_LATER(ah) &&
Luis R. Rodrigueza36cfbc2009-09-09 16:05:32 -07002200 ath9k_hw_btcoex_supported(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002201 btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO;
2202 btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO;
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05302203
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302204 if (AR_SREV_9285(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002205 btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
2206 btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302207 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002208 btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302209 }
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05302210 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002211 btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE;
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05302212 }
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002213
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002214 if (AR_SREV_9300_20_OR_LATER(ah)) {
Vasanthakumar Thiagarajane5553722010-04-26 15:04:33 -04002215 pCap->hw_caps |= ATH9K_HW_CAP_EDMA | ATH9K_HW_CAP_LDPC |
2216 ATH9K_HW_CAP_FASTCLOCK;
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002217 pCap->rx_hp_qdepth = ATH9K_HW_RX_HP_QDEPTH;
2218 pCap->rx_lp_qdepth = ATH9K_HW_RX_LP_QDEPTH;
2219 pCap->rx_status_len = sizeof(struct ar9003_rxs);
Vasanthakumar Thiagarajan162c3be2010-04-15 17:38:41 -04002220 pCap->tx_desc_len = sizeof(struct ar9003_txc);
Vasanthakumar Thiagarajan5088c2f2010-04-15 17:39:34 -04002221 pCap->txs_len = sizeof(struct ar9003_txs);
Vasanthakumar Thiagarajan162c3be2010-04-15 17:38:41 -04002222 } else {
2223 pCap->tx_desc_len = sizeof(struct ath_desc);
Felix Fietkau6b42e8d2010-04-26 15:04:35 -04002224 if (AR_SREV_9280_20(ah) &&
2225 ((ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) <=
2226 AR5416_EEP_MINOR_VER_16) ||
2227 ah->eep_ops->get_eeprom(ah, EEP_FSTCLK_5G)))
2228 pCap->hw_caps |= ATH9K_HW_CAP_FASTCLOCK;
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002229 }
Vasanthakumar Thiagarajan1adf02f2010-04-15 17:38:24 -04002230
Vasanthakumar Thiagarajan6c84ce02010-04-15 17:39:16 -04002231 if (AR_SREV_9300_20_OR_LATER(ah))
2232 pCap->hw_caps |= ATH9K_HW_CAP_RAC_SUPPORTED;
2233
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002234 return 0;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002235}
2236
Sujithcbe61d82009-02-09 13:27:12 +05302237bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05302238 u32 capability, u32 *result)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002239{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002240 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302241 switch (type) {
2242 case ATH9K_CAP_CIPHER:
2243 switch (capability) {
2244 case ATH9K_CIPHER_AES_CCM:
2245 case ATH9K_CIPHER_AES_OCB:
2246 case ATH9K_CIPHER_TKIP:
2247 case ATH9K_CIPHER_WEP:
2248 case ATH9K_CIPHER_MIC:
2249 case ATH9K_CIPHER_CLR:
2250 return true;
2251 default:
2252 return false;
2253 }
2254 case ATH9K_CAP_TKIP_MIC:
2255 switch (capability) {
2256 case 0:
2257 return true;
2258 case 1:
Sujith2660b812009-02-09 13:27:26 +05302259 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05302260 AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
2261 false;
2262 }
2263 case ATH9K_CAP_TKIP_SPLIT:
Sujith2660b812009-02-09 13:27:26 +05302264 return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ?
Sujithf1dc5602008-10-29 10:16:30 +05302265 false : true;
Sujithf1dc5602008-10-29 10:16:30 +05302266 case ATH9K_CAP_MCAST_KEYSRCH:
2267 switch (capability) {
2268 case 0:
2269 return true;
2270 case 1:
2271 if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
2272 return false;
2273 } else {
Sujith2660b812009-02-09 13:27:26 +05302274 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05302275 AR_STA_ID1_MCAST_KSRCH) ? true :
2276 false;
2277 }
2278 }
2279 return false;
Sujithf1dc5602008-10-29 10:16:30 +05302280 case ATH9K_CAP_TXPOW:
2281 switch (capability) {
2282 case 0:
2283 return 0;
2284 case 1:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002285 *result = regulatory->power_limit;
Sujithf1dc5602008-10-29 10:16:30 +05302286 return 0;
2287 case 2:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002288 *result = regulatory->max_power_level;
Sujithf1dc5602008-10-29 10:16:30 +05302289 return 0;
2290 case 3:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002291 *result = regulatory->tp_scale;
Sujithf1dc5602008-10-29 10:16:30 +05302292 return 0;
2293 }
2294 return false;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05302295 case ATH9K_CAP_DS:
2296 return (AR_SREV_9280_20_OR_LATER(ah) &&
2297 (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1))
2298 ? false : true;
Sujithf1dc5602008-10-29 10:16:30 +05302299 default:
2300 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002301 }
Sujithf1dc5602008-10-29 10:16:30 +05302302}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002303EXPORT_SYMBOL(ath9k_hw_getcapability);
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002304
Sujithcbe61d82009-02-09 13:27:12 +05302305bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05302306 u32 capability, u32 setting, int *status)
2307{
Sujithf1dc5602008-10-29 10:16:30 +05302308 switch (type) {
2309 case ATH9K_CAP_TKIP_MIC:
2310 if (setting)
Sujith2660b812009-02-09 13:27:26 +05302311 ah->sta_id1_defaults |=
Sujithf1dc5602008-10-29 10:16:30 +05302312 AR_STA_ID1_CRPT_MIC_ENABLE;
2313 else
Sujith2660b812009-02-09 13:27:26 +05302314 ah->sta_id1_defaults &=
Sujithf1dc5602008-10-29 10:16:30 +05302315 ~AR_STA_ID1_CRPT_MIC_ENABLE;
2316 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302317 case ATH9K_CAP_MCAST_KEYSRCH:
2318 if (setting)
Sujith2660b812009-02-09 13:27:26 +05302319 ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05302320 else
Sujith2660b812009-02-09 13:27:26 +05302321 ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05302322 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302323 default:
2324 return false;
2325 }
2326}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002327EXPORT_SYMBOL(ath9k_hw_setcapability);
Sujithf1dc5602008-10-29 10:16:30 +05302328
2329/****************************/
2330/* GPIO / RFKILL / Antennae */
2331/****************************/
2332
Sujithcbe61d82009-02-09 13:27:12 +05302333static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05302334 u32 gpio, u32 type)
2335{
2336 int addr;
2337 u32 gpio_shift, tmp;
2338
2339 if (gpio > 11)
2340 addr = AR_GPIO_OUTPUT_MUX3;
2341 else if (gpio > 5)
2342 addr = AR_GPIO_OUTPUT_MUX2;
2343 else
2344 addr = AR_GPIO_OUTPUT_MUX1;
2345
2346 gpio_shift = (gpio % 6) * 5;
2347
2348 if (AR_SREV_9280_20_OR_LATER(ah)
2349 || (addr != AR_GPIO_OUTPUT_MUX1)) {
2350 REG_RMW(ah, addr, (type << gpio_shift),
2351 (0x1f << gpio_shift));
2352 } else {
2353 tmp = REG_READ(ah, addr);
2354 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
2355 tmp &= ~(0x1f << gpio_shift);
2356 tmp |= (type << gpio_shift);
2357 REG_WRITE(ah, addr, tmp);
2358 }
2359}
2360
Sujithcbe61d82009-02-09 13:27:12 +05302361void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05302362{
2363 u32 gpio_shift;
2364
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07002365 BUG_ON(gpio >= ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05302366
2367 gpio_shift = gpio << 1;
2368
2369 REG_RMW(ah,
2370 AR_GPIO_OE_OUT,
2371 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
2372 (AR_GPIO_OE_OUT_DRV << gpio_shift));
2373}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002374EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
Sujithf1dc5602008-10-29 10:16:30 +05302375
Sujithcbe61d82009-02-09 13:27:12 +05302376u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05302377{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302378#define MS_REG_READ(x, y) \
2379 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
2380
Sujith2660b812009-02-09 13:27:26 +05302381 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05302382 return 0xffffffff;
2383
Felix Fietkau783dfca2010-04-15 17:38:11 -04002384 if (AR_SREV_9300_20_OR_LATER(ah))
2385 return MS_REG_READ(AR9300, gpio) != 0;
2386 else if (AR_SREV_9271(ah))
Sujith5b5fa352010-03-17 14:25:15 +05302387 return MS_REG_READ(AR9271, gpio) != 0;
2388 else if (AR_SREV_9287_10_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302389 return MS_REG_READ(AR9287, gpio) != 0;
2390 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302391 return MS_REG_READ(AR9285, gpio) != 0;
2392 else if (AR_SREV_9280_10_OR_LATER(ah))
2393 return MS_REG_READ(AR928X, gpio) != 0;
2394 else
2395 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05302396}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002397EXPORT_SYMBOL(ath9k_hw_gpio_get);
Sujithf1dc5602008-10-29 10:16:30 +05302398
Sujithcbe61d82009-02-09 13:27:12 +05302399void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05302400 u32 ah_signal_type)
2401{
2402 u32 gpio_shift;
2403
2404 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
2405
2406 gpio_shift = 2 * gpio;
2407
2408 REG_RMW(ah,
2409 AR_GPIO_OE_OUT,
2410 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
2411 (AR_GPIO_OE_OUT_DRV << gpio_shift));
2412}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002413EXPORT_SYMBOL(ath9k_hw_cfg_output);
Sujithf1dc5602008-10-29 10:16:30 +05302414
Sujithcbe61d82009-02-09 13:27:12 +05302415void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05302416{
Sujith5b5fa352010-03-17 14:25:15 +05302417 if (AR_SREV_9271(ah))
2418 val = ~val;
2419
Sujithf1dc5602008-10-29 10:16:30 +05302420 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
2421 AR_GPIO_BIT(gpio));
2422}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002423EXPORT_SYMBOL(ath9k_hw_set_gpio);
Sujithf1dc5602008-10-29 10:16:30 +05302424
Sujithcbe61d82009-02-09 13:27:12 +05302425u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302426{
2427 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
2428}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002429EXPORT_SYMBOL(ath9k_hw_getdefantenna);
Sujithf1dc5602008-10-29 10:16:30 +05302430
Sujithcbe61d82009-02-09 13:27:12 +05302431void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05302432{
2433 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
2434}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002435EXPORT_SYMBOL(ath9k_hw_setantenna);
Sujithf1dc5602008-10-29 10:16:30 +05302436
Sujithf1dc5602008-10-29 10:16:30 +05302437/*********************/
2438/* General Operation */
2439/*********************/
2440
Sujithcbe61d82009-02-09 13:27:12 +05302441u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302442{
2443 u32 bits = REG_READ(ah, AR_RX_FILTER);
2444 u32 phybits = REG_READ(ah, AR_PHY_ERR);
2445
2446 if (phybits & AR_PHY_ERR_RADAR)
2447 bits |= ATH9K_RX_FILTER_PHYRADAR;
2448 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
2449 bits |= ATH9K_RX_FILTER_PHYERR;
2450
2451 return bits;
2452}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002453EXPORT_SYMBOL(ath9k_hw_getrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05302454
Sujithcbe61d82009-02-09 13:27:12 +05302455void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05302456{
2457 u32 phybits;
2458
Sujith7d0d0df2010-04-16 11:53:57 +05302459 ENABLE_REGWRITE_BUFFER(ah);
2460
Sujith7ea310b2009-09-03 12:08:43 +05302461 REG_WRITE(ah, AR_RX_FILTER, bits);
2462
Sujithf1dc5602008-10-29 10:16:30 +05302463 phybits = 0;
2464 if (bits & ATH9K_RX_FILTER_PHYRADAR)
2465 phybits |= AR_PHY_ERR_RADAR;
2466 if (bits & ATH9K_RX_FILTER_PHYERR)
2467 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
2468 REG_WRITE(ah, AR_PHY_ERR, phybits);
2469
2470 if (phybits)
2471 REG_WRITE(ah, AR_RXCFG,
2472 REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
2473 else
2474 REG_WRITE(ah, AR_RXCFG,
2475 REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
Sujith7d0d0df2010-04-16 11:53:57 +05302476
2477 REGWRITE_BUFFER_FLUSH(ah);
2478 DISABLE_REGWRITE_BUFFER(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302479}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002480EXPORT_SYMBOL(ath9k_hw_setrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05302481
Sujithcbe61d82009-02-09 13:27:12 +05302482bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302483{
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05302484 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
2485 return false;
2486
2487 ath9k_hw_init_pll(ah, NULL);
2488 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302489}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002490EXPORT_SYMBOL(ath9k_hw_phy_disable);
Sujithf1dc5602008-10-29 10:16:30 +05302491
Sujithcbe61d82009-02-09 13:27:12 +05302492bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302493{
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002494 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05302495 return false;
2496
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05302497 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
2498 return false;
2499
2500 ath9k_hw_init_pll(ah, NULL);
2501 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302502}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002503EXPORT_SYMBOL(ath9k_hw_disable);
Sujithf1dc5602008-10-29 10:16:30 +05302504
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07002505void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
Sujithf1dc5602008-10-29 10:16:30 +05302506{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002507 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujith2660b812009-02-09 13:27:26 +05302508 struct ath9k_channel *chan = ah->curchan;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002509 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05302510
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002511 regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER);
Sujithf1dc5602008-10-29 10:16:30 +05302512
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07002513 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002514 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07002515 channel->max_antenna_gain * 2,
2516 channel->max_power * 2,
2517 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002518 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05302519}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002520EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
Sujithf1dc5602008-10-29 10:16:30 +05302521
Sujithcbe61d82009-02-09 13:27:12 +05302522void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac)
Sujithf1dc5602008-10-29 10:16:30 +05302523{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002524 memcpy(ath9k_hw_common(ah)->macaddr, mac, ETH_ALEN);
Sujithf1dc5602008-10-29 10:16:30 +05302525}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002526EXPORT_SYMBOL(ath9k_hw_setmac);
Sujithf1dc5602008-10-29 10:16:30 +05302527
Sujithcbe61d82009-02-09 13:27:12 +05302528void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302529{
Sujith2660b812009-02-09 13:27:26 +05302530 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05302531}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002532EXPORT_SYMBOL(ath9k_hw_setopmode);
Sujithf1dc5602008-10-29 10:16:30 +05302533
Sujithcbe61d82009-02-09 13:27:12 +05302534void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05302535{
2536 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
2537 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
2538}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002539EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
Sujithf1dc5602008-10-29 10:16:30 +05302540
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07002541void ath9k_hw_write_associd(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302542{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002543 struct ath_common *common = ath9k_hw_common(ah);
2544
2545 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
2546 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
2547 ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05302548}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002549EXPORT_SYMBOL(ath9k_hw_write_associd);
Sujithf1dc5602008-10-29 10:16:30 +05302550
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002551#define ATH9K_MAX_TSF_READ 10
2552
Sujithcbe61d82009-02-09 13:27:12 +05302553u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302554{
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002555 u32 tsf_lower, tsf_upper1, tsf_upper2;
2556 int i;
Sujithf1dc5602008-10-29 10:16:30 +05302557
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002558 tsf_upper1 = REG_READ(ah, AR_TSF_U32);
2559 for (i = 0; i < ATH9K_MAX_TSF_READ; i++) {
2560 tsf_lower = REG_READ(ah, AR_TSF_L32);
2561 tsf_upper2 = REG_READ(ah, AR_TSF_U32);
2562 if (tsf_upper2 == tsf_upper1)
2563 break;
2564 tsf_upper1 = tsf_upper2;
2565 }
Sujithf1dc5602008-10-29 10:16:30 +05302566
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002567 WARN_ON( i == ATH9K_MAX_TSF_READ );
2568
2569 return (((u64)tsf_upper1 << 32) | tsf_lower);
Sujithf1dc5602008-10-29 10:16:30 +05302570}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002571EXPORT_SYMBOL(ath9k_hw_gettsf64);
Sujithf1dc5602008-10-29 10:16:30 +05302572
Sujithcbe61d82009-02-09 13:27:12 +05302573void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002574{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002575 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01002576 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002577}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002578EXPORT_SYMBOL(ath9k_hw_settsf64);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002579
Sujithcbe61d82009-02-09 13:27:12 +05302580void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302581{
Gabor Juhosf9b604f2009-06-21 00:02:15 +02002582 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
2583 AH_TSF_WRITE_TIMEOUT))
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002584 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
2585 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
Gabor Juhosf9b604f2009-06-21 00:02:15 +02002586
Sujithf1dc5602008-10-29 10:16:30 +05302587 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002588}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002589EXPORT_SYMBOL(ath9k_hw_reset_tsf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002590
Sujith54e4cec2009-08-07 09:45:09 +05302591void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002592{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002593 if (setting)
Sujith2660b812009-02-09 13:27:26 +05302594 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002595 else
Sujith2660b812009-02-09 13:27:26 +05302596 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002597}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002598EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002599
Luis R. Rodriguez30cbd422009-11-03 16:10:46 -08002600/*
2601 * Extend 15-bit time stamp from rx descriptor to
2602 * a full 64-bit TSF using the current h/w TSF.
2603*/
2604u64 ath9k_hw_extend_tsf(struct ath_hw *ah, u32 rstamp)
2605{
2606 u64 tsf;
2607
2608 tsf = ath9k_hw_gettsf64(ah);
2609 if ((tsf & 0x7fff) < rstamp)
2610 tsf -= 0x8000;
2611 return (tsf & ~0x7fff) | rstamp;
2612}
2613EXPORT_SYMBOL(ath9k_hw_extend_tsf);
2614
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002615void ath9k_hw_set11nmac2040(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002616{
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002617 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithf1dc5602008-10-29 10:16:30 +05302618 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002619
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002620 if (conf_is_ht40(conf) && !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05302621 macmode = AR_2040_JOINED_RX_CLEAR;
2622 else
2623 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002624
Sujithf1dc5602008-10-29 10:16:30 +05302625 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002626}
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302627
2628/* HW Generic timers configuration */
2629
2630static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
2631{
2632 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2633 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2634 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2635 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2636 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2637 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2638 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2639 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2640 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
2641 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
2642 AR_NDP2_TIMER_MODE, 0x0002},
2643 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
2644 AR_NDP2_TIMER_MODE, 0x0004},
2645 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
2646 AR_NDP2_TIMER_MODE, 0x0008},
2647 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
2648 AR_NDP2_TIMER_MODE, 0x0010},
2649 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
2650 AR_NDP2_TIMER_MODE, 0x0020},
2651 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
2652 AR_NDP2_TIMER_MODE, 0x0040},
2653 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
2654 AR_NDP2_TIMER_MODE, 0x0080}
2655};
2656
2657/* HW generic timer primitives */
2658
2659/* compute and clear index of rightmost 1 */
2660static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
2661{
2662 u32 b;
2663
2664 b = *mask;
2665 b &= (0-b);
2666 *mask &= ~b;
2667 b *= debruijn32;
2668 b >>= 27;
2669
2670 return timer_table->gen_timer_index[b];
2671}
2672
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05302673u32 ath9k_hw_gettsf32(struct ath_hw *ah)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302674{
2675 return REG_READ(ah, AR_TSF_L32);
2676}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002677EXPORT_SYMBOL(ath9k_hw_gettsf32);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302678
2679struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
2680 void (*trigger)(void *),
2681 void (*overflow)(void *),
2682 void *arg,
2683 u8 timer_index)
2684{
2685 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2686 struct ath_gen_timer *timer;
2687
2688 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
2689
2690 if (timer == NULL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002691 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2692 "Failed to allocate memory"
2693 "for hw timer[%d]\n", timer_index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302694 return NULL;
2695 }
2696
2697 /* allocate a hardware generic timer slot */
2698 timer_table->timers[timer_index] = timer;
2699 timer->index = timer_index;
2700 timer->trigger = trigger;
2701 timer->overflow = overflow;
2702 timer->arg = arg;
2703
2704 return timer;
2705}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002706EXPORT_SYMBOL(ath_gen_timer_alloc);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302707
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07002708void ath9k_hw_gen_timer_start(struct ath_hw *ah,
2709 struct ath_gen_timer *timer,
2710 u32 timer_next,
2711 u32 timer_period)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302712{
2713 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2714 u32 tsf;
2715
2716 BUG_ON(!timer_period);
2717
2718 set_bit(timer->index, &timer_table->timer_mask.timer_bits);
2719
2720 tsf = ath9k_hw_gettsf32(ah);
2721
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002722 ath_print(ath9k_hw_common(ah), ATH_DBG_HWTIMER,
2723 "curent tsf %x period %x"
2724 "timer_next %x\n", tsf, timer_period, timer_next);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302725
2726 /*
2727 * Pull timer_next forward if the current TSF already passed it
2728 * because of software latency
2729 */
2730 if (timer_next < tsf)
2731 timer_next = tsf + timer_period;
2732
2733 /*
2734 * Program generic timer registers
2735 */
2736 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
2737 timer_next);
2738 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
2739 timer_period);
2740 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
2741 gen_tmr_configuration[timer->index].mode_mask);
2742
2743 /* Enable both trigger and thresh interrupt masks */
2744 REG_SET_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)));
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302747}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002748EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302749
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07002750void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302751{
2752 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2753
2754 if ((timer->index < AR_FIRST_NDP_TIMER) ||
2755 (timer->index >= ATH_MAX_GEN_TIMER)) {
2756 return;
2757 }
2758
2759 /* Clear generic timer enable bits. */
2760 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
2761 gen_tmr_configuration[timer->index].mode_mask);
2762
2763 /* Disable both trigger and thresh interrupt masks */
2764 REG_CLR_BIT(ah, AR_IMR_S5,
2765 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
2766 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
2767
2768 clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302769}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002770EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302771
2772void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
2773{
2774 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2775
2776 /* free the hardware generic timer slot */
2777 timer_table->timers[timer->index] = NULL;
2778 kfree(timer);
2779}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002780EXPORT_SYMBOL(ath_gen_timer_free);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302781
2782/*
2783 * Generic Timer Interrupts handling
2784 */
2785void ath_gen_timer_isr(struct ath_hw *ah)
2786{
2787 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2788 struct ath_gen_timer *timer;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002789 struct ath_common *common = ath9k_hw_common(ah);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302790 u32 trigger_mask, thresh_mask, index;
2791
2792 /* get hardware generic timer interrupt status */
2793 trigger_mask = ah->intr_gen_timer_trigger;
2794 thresh_mask = ah->intr_gen_timer_thresh;
2795 trigger_mask &= timer_table->timer_mask.val;
2796 thresh_mask &= timer_table->timer_mask.val;
2797
2798 trigger_mask &= ~thresh_mask;
2799
2800 while (thresh_mask) {
2801 index = rightmost_index(timer_table, &thresh_mask);
2802 timer = timer_table->timers[index];
2803 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002804 ath_print(common, ATH_DBG_HWTIMER,
2805 "TSF overflow for Gen timer %d\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302806 timer->overflow(timer->arg);
2807 }
2808
2809 while (trigger_mask) {
2810 index = rightmost_index(timer_table, &trigger_mask);
2811 timer = timer_table->timers[index];
2812 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002813 ath_print(common, ATH_DBG_HWTIMER,
2814 "Gen timer[%d] trigger\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302815 timer->trigger(timer->arg);
2816 }
2817}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002818EXPORT_SYMBOL(ath_gen_timer_isr);
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04002819
Sujith05020d22010-03-17 14:25:23 +05302820/********/
2821/* HTC */
2822/********/
2823
2824void ath9k_hw_htc_resetinit(struct ath_hw *ah)
2825{
2826 ah->htc_reset_init = true;
2827}
2828EXPORT_SYMBOL(ath9k_hw_htc_resetinit);
2829
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04002830static struct {
2831 u32 version;
2832 const char * name;
2833} ath_mac_bb_names[] = {
2834 /* Devices with external radios */
2835 { AR_SREV_VERSION_5416_PCI, "5416" },
2836 { AR_SREV_VERSION_5416_PCIE, "5418" },
2837 { AR_SREV_VERSION_9100, "9100" },
2838 { AR_SREV_VERSION_9160, "9160" },
2839 /* Single-chip solutions */
2840 { AR_SREV_VERSION_9280, "9280" },
2841 { AR_SREV_VERSION_9285, "9285" },
Luis R. Rodriguez11158472009-10-27 12:59:35 -04002842 { AR_SREV_VERSION_9287, "9287" },
2843 { AR_SREV_VERSION_9271, "9271" },
Luis R. Rodriguezec839032010-04-15 17:39:20 -04002844 { AR_SREV_VERSION_9300, "9300" },
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04002845};
2846
2847/* For devices with external radios */
2848static struct {
2849 u16 version;
2850 const char * name;
2851} ath_rf_names[] = {
2852 { 0, "5133" },
2853 { AR_RAD5133_SREV_MAJOR, "5133" },
2854 { AR_RAD5122_SREV_MAJOR, "5122" },
2855 { AR_RAD2133_SREV_MAJOR, "2133" },
2856 { AR_RAD2122_SREV_MAJOR, "2122" }
2857};
2858
2859/*
2860 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
2861 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04002862static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04002863{
2864 int i;
2865
2866 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
2867 if (ath_mac_bb_names[i].version == mac_bb_version) {
2868 return ath_mac_bb_names[i].name;
2869 }
2870 }
2871
2872 return "????";
2873}
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04002874
2875/*
2876 * Return the RF name. "????" is returned if the RF is unknown.
2877 * Used for devices with external radios.
2878 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04002879static const char *ath9k_hw_rf_name(u16 rf_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04002880{
2881 int i;
2882
2883 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
2884 if (ath_rf_names[i].version == rf_version) {
2885 return ath_rf_names[i].name;
2886 }
2887 }
2888
2889 return "????";
2890}
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04002891
2892void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
2893{
2894 int used;
2895
2896 /* chipsets >= AR9280 are single-chip */
2897 if (AR_SREV_9280_10_OR_LATER(ah)) {
2898 used = snprintf(hw_name, len,
2899 "Atheros AR%s Rev:%x",
2900 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
2901 ah->hw_version.macRev);
2902 }
2903 else {
2904 used = snprintf(hw_name, len,
2905 "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
2906 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
2907 ah->hw_version.macRev,
2908 ath9k_hw_rf_name((ah->hw_version.analog5GhzRev &
2909 AR_RADIO_SREV_MAJOR)),
2910 ah->hw_version.phyRev);
2911 }
2912
2913 hw_name[used] = '\0';
2914}
2915EXPORT_SYMBOL(ath9k_hw_name);