blob: 349cffdbdea6daac1a884c918361ff193fd3ac83 [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
Sujithcee075a2009-03-13 09:07:23 +05302 * Copyright (c) 2008-2009 Atheros Communications Inc.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include <linux/io.h>
18#include <asm/unaligned.h>
19
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -070020#include "hw.h"
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -040021#include "hw-ops.h"
Luis R. Rodriguezcfe8cba2009-09-13 23:39:31 -070022#include "rc.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070023#include "initvals.h"
24
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080025#define ATH9K_CLOCK_RATE_CCK 22
26#define ATH9K_CLOCK_RATE_5GHZ_OFDM 40
27#define ATH9K_CLOCK_RATE_2GHZ_OFDM 44
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070028
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -040029static void ar9002_hw_attach_ops(struct ath_hw *ah);
30
Sujithcbe61d82009-02-09 13:27:12 +053031static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070032
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040033MODULE_AUTHOR("Atheros Communications");
34MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
35MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
36MODULE_LICENSE("Dual BSD/GPL");
37
38static int __init ath9k_init(void)
39{
40 return 0;
41}
42module_init(ath9k_init);
43
44static void __exit ath9k_exit(void)
45{
46 return;
47}
48module_exit(ath9k_exit);
49
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -040050/* Private hardware callbacks */
51
52static void ath9k_hw_init_cal_settings(struct ath_hw *ah)
53{
54 ath9k_hw_private_ops(ah)->init_cal_settings(ah);
55}
56
57static void ath9k_hw_init_mode_regs(struct ath_hw *ah)
58{
59 ath9k_hw_private_ops(ah)->init_mode_regs(ah);
60}
61
62static bool ath9k_hw_macversion_supported(struct ath_hw *ah)
63{
64 struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
65
66 return priv_ops->macversion_supported(ah->hw_version.macVersion);
67}
68
Luis R. Rodriguez64773962010-04-15 17:38:17 -040069static u32 ath9k_hw_compute_pll_control(struct ath_hw *ah,
70 struct ath9k_channel *chan)
71{
72 return ath9k_hw_private_ops(ah)->compute_pll_control(ah, chan);
73}
74
Sujithf1dc5602008-10-29 10:16:30 +053075/********************/
76/* Helper Functions */
77/********************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070078
Sujithcbe61d82009-02-09 13:27:12 +053079static u32 ath9k_hw_mac_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053080{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070081 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053082
Sujith2660b812009-02-09 13:27:26 +053083 if (!ah->curchan) /* should really check for CCK instead */
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080084 return usecs *ATH9K_CLOCK_RATE_CCK;
85 if (conf->channel->band == IEEE80211_BAND_2GHZ)
86 return usecs *ATH9K_CLOCK_RATE_2GHZ_OFDM;
87 return usecs *ATH9K_CLOCK_RATE_5GHZ_OFDM;
Sujithf1dc5602008-10-29 10:16:30 +053088}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070089
Sujithcbe61d82009-02-09 13:27:12 +053090static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053091{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070092 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053093
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080094 if (conf_is_ht40(conf))
Sujithf1dc5602008-10-29 10:16:30 +053095 return ath9k_hw_mac_clks(ah, usecs) * 2;
96 else
97 return ath9k_hw_mac_clks(ah, usecs);
98}
99
Sujith0caa7b12009-02-16 13:23:20 +0530100bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700101{
102 int i;
103
Sujith0caa7b12009-02-16 13:23:20 +0530104 BUG_ON(timeout < AH_TIME_QUANTUM);
105
106 for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700107 if ((REG_READ(ah, reg) & mask) == val)
108 return true;
109
110 udelay(AH_TIME_QUANTUM);
111 }
Sujith04bd46382008-11-28 22:18:05 +0530112
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700113 ath_print(ath9k_hw_common(ah), ATH_DBG_ANY,
114 "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
115 timeout, reg, REG_READ(ah, reg), mask, val);
Sujithf1dc5602008-10-29 10:16:30 +0530116
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700117 return false;
118}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400119EXPORT_SYMBOL(ath9k_hw_wait);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700120
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700121u32 ath9k_hw_reverse_bits(u32 val, u32 n)
122{
123 u32 retval;
124 int i;
125
126 for (i = 0, retval = 0; i < n; i++) {
127 retval = (retval << 1) | (val & 1);
128 val >>= 1;
129 }
130 return retval;
131}
132
Sujithcbe61d82009-02-09 13:27:12 +0530133bool ath9k_get_channel_edges(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530134 u16 flags, u16 *low,
135 u16 *high)
136{
Sujith2660b812009-02-09 13:27:26 +0530137 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530138
139 if (flags & CHANNEL_5GHZ) {
140 *low = pCap->low_5ghz_chan;
141 *high = pCap->high_5ghz_chan;
142 return true;
143 }
144 if ((flags & CHANNEL_2GHZ)) {
145 *low = pCap->low_2ghz_chan;
146 *high = pCap->high_2ghz_chan;
147 return true;
148 }
149 return false;
150}
151
Sujithcbe61d82009-02-09 13:27:12 +0530152u16 ath9k_hw_computetxtime(struct ath_hw *ah,
Felix Fietkau545750d2009-11-23 22:21:01 +0100153 u8 phy, int kbps,
Sujithf1dc5602008-10-29 10:16:30 +0530154 u32 frameLen, u16 rateix,
155 bool shortPreamble)
156{
157 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
Sujithf1dc5602008-10-29 10:16:30 +0530158
159 if (kbps == 0)
160 return 0;
161
Felix Fietkau545750d2009-11-23 22:21:01 +0100162 switch (phy) {
Sujith46d14a52008-11-18 09:08:13 +0530163 case WLAN_RC_PHY_CCK:
Sujithf1dc5602008-10-29 10:16:30 +0530164 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
Felix Fietkau545750d2009-11-23 22:21:01 +0100165 if (shortPreamble)
Sujithf1dc5602008-10-29 10:16:30 +0530166 phyTime >>= 1;
167 numBits = frameLen << 3;
168 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
169 break;
Sujith46d14a52008-11-18 09:08:13 +0530170 case WLAN_RC_PHY_OFDM:
Sujith2660b812009-02-09 13:27:26 +0530171 if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530172 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
173 numBits = OFDM_PLCP_BITS + (frameLen << 3);
174 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
175 txTime = OFDM_SIFS_TIME_QUARTER
176 + OFDM_PREAMBLE_TIME_QUARTER
177 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
Sujith2660b812009-02-09 13:27:26 +0530178 } else if (ah->curchan &&
179 IS_CHAN_HALF_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530180 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
181 numBits = OFDM_PLCP_BITS + (frameLen << 3);
182 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
183 txTime = OFDM_SIFS_TIME_HALF +
184 OFDM_PREAMBLE_TIME_HALF
185 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
186 } else {
187 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
188 numBits = OFDM_PLCP_BITS + (frameLen << 3);
189 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
190 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
191 + (numSymbols * OFDM_SYMBOL_TIME);
192 }
193 break;
194 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700195 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
Felix Fietkau545750d2009-11-23 22:21:01 +0100196 "Unknown phy %u (rate ix %u)\n", phy, rateix);
Sujithf1dc5602008-10-29 10:16:30 +0530197 txTime = 0;
198 break;
199 }
200
201 return txTime;
202}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400203EXPORT_SYMBOL(ath9k_hw_computetxtime);
Sujithf1dc5602008-10-29 10:16:30 +0530204
Sujithcbe61d82009-02-09 13:27:12 +0530205void ath9k_hw_get_channel_centers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530206 struct ath9k_channel *chan,
207 struct chan_centers *centers)
208{
209 int8_t extoff;
Sujithf1dc5602008-10-29 10:16:30 +0530210
211 if (!IS_CHAN_HT40(chan)) {
212 centers->ctl_center = centers->ext_center =
213 centers->synth_center = chan->channel;
214 return;
215 }
216
217 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
218 (chan->chanmode == CHANNEL_G_HT40PLUS)) {
219 centers->synth_center =
220 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
221 extoff = 1;
222 } else {
223 centers->synth_center =
224 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
225 extoff = -1;
226 }
227
228 centers->ctl_center =
229 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700230 /* 25 MHz spacing is supported by hw but not on upper layers */
Sujithf1dc5602008-10-29 10:16:30 +0530231 centers->ext_center =
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700232 centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT);
Sujithf1dc5602008-10-29 10:16:30 +0530233}
234
235/******************/
236/* Chip Revisions */
237/******************/
238
Sujithcbe61d82009-02-09 13:27:12 +0530239static void ath9k_hw_read_revisions(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530240{
241 u32 val;
242
243 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
244
245 if (val == 0xFF) {
246 val = REG_READ(ah, AR_SREV);
Sujithd535a422009-02-09 13:27:06 +0530247 ah->hw_version.macVersion =
248 (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
249 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
Sujith2660b812009-02-09 13:27:26 +0530250 ah->is_pciexpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
Sujithf1dc5602008-10-29 10:16:30 +0530251 } else {
252 if (!AR_SREV_9100(ah))
Sujithd535a422009-02-09 13:27:06 +0530253 ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
Sujithf1dc5602008-10-29 10:16:30 +0530254
Sujithd535a422009-02-09 13:27:06 +0530255 ah->hw_version.macRev = val & AR_SREV_REVISION;
Sujithf1dc5602008-10-29 10:16:30 +0530256
Sujithd535a422009-02-09 13:27:06 +0530257 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
Sujith2660b812009-02-09 13:27:26 +0530258 ah->is_pciexpress = true;
Sujithf1dc5602008-10-29 10:16:30 +0530259 }
260}
261
Sujithcbe61d82009-02-09 13:27:12 +0530262static int ath9k_hw_get_radiorev(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530263{
264 u32 val;
265 int i;
266
267 REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
268
269 for (i = 0; i < 8; i++)
270 REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
271 val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
272 val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
273
274 return ath9k_hw_reverse_bits(val, 8);
275}
276
277/************************************/
278/* HW Attach, Detach, Init Routines */
279/************************************/
280
Sujithcbe61d82009-02-09 13:27:12 +0530281static void ath9k_hw_disablepcie(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530282{
Sujithfeed0292009-01-29 11:37:35 +0530283 if (AR_SREV_9100(ah))
Sujithf1dc5602008-10-29 10:16:30 +0530284 return;
285
286 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
287 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
288 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
289 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
290 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
291 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
292 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
293 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
294 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
295
296 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
297}
298
Sujithcbe61d82009-02-09 13:27:12 +0530299static bool ath9k_hw_chip_test(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530300{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700301 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530302 u32 regAddr[2] = { AR_STA_ID0, AR_PHY_BASE + (8 << 2) };
303 u32 regHold[2];
304 u32 patternData[4] = { 0x55555555,
305 0xaaaaaaaa,
306 0x66666666,
307 0x99999999 };
308 int i, j;
309
310 for (i = 0; i < 2; i++) {
311 u32 addr = regAddr[i];
312 u32 wrData, rdData;
313
314 regHold[i] = REG_READ(ah, addr);
315 for (j = 0; j < 0x100; j++) {
316 wrData = (j << 16) | j;
317 REG_WRITE(ah, addr, wrData);
318 rdData = REG_READ(ah, addr);
319 if (rdData != wrData) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700320 ath_print(common, ATH_DBG_FATAL,
321 "address test failed "
322 "addr: 0x%08x - wr:0x%08x != "
323 "rd:0x%08x\n",
324 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530325 return false;
326 }
327 }
328 for (j = 0; j < 4; j++) {
329 wrData = patternData[j];
330 REG_WRITE(ah, addr, wrData);
331 rdData = REG_READ(ah, addr);
332 if (wrData != rdData) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700333 ath_print(common, ATH_DBG_FATAL,
334 "address test failed "
335 "addr: 0x%08x - wr:0x%08x != "
336 "rd:0x%08x\n",
337 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530338 return false;
339 }
340 }
341 REG_WRITE(ah, regAddr[i], regHold[i]);
342 }
343 udelay(100);
Sujithcbe61d82009-02-09 13:27:12 +0530344
Sujithf1dc5602008-10-29 10:16:30 +0530345 return true;
346}
347
Luis R. Rodriguezb8b0f372009-08-03 12:24:43 -0700348static void ath9k_hw_init_config(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700349{
350 int i;
351
Sujith2660b812009-02-09 13:27:26 +0530352 ah->config.dma_beacon_response_time = 2;
353 ah->config.sw_beacon_response_time = 10;
354 ah->config.additional_swba_backoff = 0;
355 ah->config.ack_6mb = 0x0;
356 ah->config.cwm_ignore_extcca = 0;
357 ah->config.pcie_powersave_enable = 0;
Sujith2660b812009-02-09 13:27:26 +0530358 ah->config.pcie_clock_req = 0;
Sujith2660b812009-02-09 13:27:26 +0530359 ah->config.pcie_waen = 0;
360 ah->config.analog_shiftreg = 1;
Sujith2660b812009-02-09 13:27:26 +0530361 ah->config.ofdm_trig_low = 200;
362 ah->config.ofdm_trig_high = 500;
363 ah->config.cck_trig_high = 200;
364 ah->config.cck_trig_low = 100;
365 ah->config.enable_ani = 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700366
367 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujith2660b812009-02-09 13:27:26 +0530368 ah->config.spurchans[i][0] = AR_NO_SPUR;
369 ah->config.spurchans[i][1] = AR_NO_SPUR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700370 }
371
Luis R. Rodriguez5ffaf8a2010-02-02 11:58:33 -0500372 if (ah->hw_version.devid != AR2427_DEVID_PCIE)
373 ah->config.ht_enable = 1;
374 else
375 ah->config.ht_enable = 0;
376
Sujith0ce024c2009-12-14 14:57:00 +0530377 ah->config.rx_intr_mitigation = true;
Luis R. Rodriguez61584252009-03-12 18:18:49 -0400378
379 /*
380 * We need this for PCI devices only (Cardbus, PCI, miniPCI)
381 * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
382 * This means we use it for all AR5416 devices, and the few
383 * minor PCI AR9280 devices out there.
384 *
385 * Serialization is required because these devices do not handle
386 * well the case of two concurrent reads/writes due to the latency
387 * involved. During one read/write another read/write can be issued
388 * on another CPU while the previous read/write may still be working
389 * on our hardware, if we hit this case the hardware poops in a loop.
390 * We prevent this by serializing reads and writes.
391 *
392 * This issue is not present on PCI-Express devices or pre-AR5416
393 * devices (legacy, 802.11abg).
394 */
395 if (num_possible_cpus() > 1)
David S. Miller2d6a5e92009-03-17 15:01:30 -0700396 ah->config.serialize_regmode = SER_REG_MODE_AUTO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700397}
398
Luis R. Rodriguez50aca252009-08-03 12:24:42 -0700399static void ath9k_hw_init_defaults(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700400{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700401 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
402
403 regulatory->country_code = CTRY_DEFAULT;
404 regulatory->power_limit = MAX_RATE_POWER;
405 regulatory->tp_scale = ATH9K_TP_SCALE_MAX;
406
Sujithd535a422009-02-09 13:27:06 +0530407 ah->hw_version.magic = AR5416_MAGIC;
Sujithd535a422009-02-09 13:27:06 +0530408 ah->hw_version.subvendorid = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700409
410 ah->ah_flags = 0;
Luis R. Rodriguez8df5d1b2009-08-03 12:24:37 -0700411 if (ah->hw_version.devid == AR5416_AR9100_DEVID)
Sujithd535a422009-02-09 13:27:06 +0530412 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700413 if (!AR_SREV_9100(ah))
414 ah->ah_flags = AH_USE_EEPROM;
415
Sujith2660b812009-02-09 13:27:26 +0530416 ah->atim_window = 0;
Sujith2660b812009-02-09 13:27:26 +0530417 ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
418 ah->beacon_interval = 100;
419 ah->enable_32kHz_clock = DONT_USE_32KHZ;
420 ah->slottime = (u32) -1;
Sujith2660b812009-02-09 13:27:26 +0530421 ah->globaltxtimeout = (u32) -1;
Gabor Juhoscbdec972009-07-24 17:27:22 +0200422 ah->power_mode = ATH9K_PM_UNDEFINED;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700423}
424
Sujithcbe61d82009-02-09 13:27:12 +0530425static int ath9k_hw_rf_claim(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700426{
427 u32 val;
428
429 REG_WRITE(ah, AR_PHY(0), 0x00000007);
430
431 val = ath9k_hw_get_radiorev(ah);
432 switch (val & AR_RADIO_SREV_MAJOR) {
433 case 0:
434 val = AR_RAD5133_SREV_MAJOR;
435 break;
436 case AR_RAD5133_SREV_MAJOR:
437 case AR_RAD5122_SREV_MAJOR:
438 case AR_RAD2133_SREV_MAJOR:
439 case AR_RAD2122_SREV_MAJOR:
440 break;
441 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700442 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
443 "Radio Chip Rev 0x%02X not supported\n",
444 val & AR_RADIO_SREV_MAJOR);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700445 return -EOPNOTSUPP;
446 }
447
Sujithd535a422009-02-09 13:27:06 +0530448 ah->hw_version.analog5GhzRev = val;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700449
450 return 0;
451}
452
Sujithcbe61d82009-02-09 13:27:12 +0530453static int ath9k_hw_init_macaddr(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700454{
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700455 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530456 u32 sum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700457 int i;
Sujithf1dc5602008-10-29 10:16:30 +0530458 u16 eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700459
Sujithf1dc5602008-10-29 10:16:30 +0530460 sum = 0;
461 for (i = 0; i < 3; i++) {
Sujithf74df6f2009-02-09 13:27:24 +0530462 eeval = ah->eep_ops->get_eeprom(ah, AR_EEPROM_MAC(i));
Sujithf1dc5602008-10-29 10:16:30 +0530463 sum += eeval;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700464 common->macaddr[2 * i] = eeval >> 8;
465 common->macaddr[2 * i + 1] = eeval & 0xff;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700466 }
Sujithd8baa932009-03-30 15:28:25 +0530467 if (sum == 0 || sum == 0xffff * 3)
Sujithf1dc5602008-10-29 10:16:30 +0530468 return -EADDRNOTAVAIL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700469
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700470 return 0;
471}
472
Sujithcbe61d82009-02-09 13:27:12 +0530473static void ath9k_hw_init_rxgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530474{
475 u32 rxgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530476
Sujithf74df6f2009-02-09 13:27:24 +0530477 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_17) {
478 rxgain_type = ah->eep_ops->get_eeprom(ah, EEP_RXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530479
480 if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530481 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530482 ar9280Modes_backoff_13db_rxgain_9280_2,
483 ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2), 6);
484 else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530485 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530486 ar9280Modes_backoff_23db_rxgain_9280_2,
487 ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 6);
488 else
Sujith2660b812009-02-09 13:27:26 +0530489 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530490 ar9280Modes_original_rxgain_9280_2,
491 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530492 } else {
Sujith2660b812009-02-09 13:27:26 +0530493 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530494 ar9280Modes_original_rxgain_9280_2,
495 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530496 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530497}
498
Sujithcbe61d82009-02-09 13:27:12 +0530499static void ath9k_hw_init_txgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530500{
501 u32 txgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530502
Sujithf74df6f2009-02-09 13:27:24 +0530503 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_19) {
504 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530505
506 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
Sujith2660b812009-02-09 13:27:26 +0530507 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530508 ar9280Modes_high_power_tx_gain_9280_2,
509 ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 6);
510 else
Sujith2660b812009-02-09 13:27:26 +0530511 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530512 ar9280Modes_original_tx_gain_9280_2,
513 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530514 } else {
Sujith2660b812009-02-09 13:27:26 +0530515 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530516 ar9280Modes_original_tx_gain_9280_2,
517 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530518 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530519}
520
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700521static int ath9k_hw_post_init(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700522{
523 int ecode;
524
Sujith527d4852010-03-17 14:25:16 +0530525 if (!AR_SREV_9271(ah)) {
526 if (!ath9k_hw_chip_test(ah))
527 return -ENODEV;
528 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700529
530 ecode = ath9k_hw_rf_claim(ah);
531 if (ecode != 0)
532 return ecode;
533
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700534 ecode = ath9k_hw_eeprom_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700535 if (ecode != 0)
536 return ecode;
Sujith7d01b222009-03-13 08:55:55 +0530537
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700538 ath_print(ath9k_hw_common(ah), ATH_DBG_CONFIG,
539 "Eeprom VER: %d, REV: %d\n",
540 ah->eep_ops->get_eeprom_ver(ah),
541 ah->eep_ops->get_eeprom_rev(ah));
Sujith7d01b222009-03-13 08:55:55 +0530542
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400543 ecode = ath9k_hw_rf_alloc_ext_banks(ah);
544 if (ecode) {
545 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
546 "Failed allocating banks for "
547 "external radio\n");
548 return ecode;
Luis R. Rodriguez574d6b12009-10-19 02:33:37 -0400549 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700550
551 if (!AR_SREV_9100(ah)) {
552 ath9k_hw_ani_setup(ah);
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700553 ath9k_hw_ani_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700554 }
Sujithf1dc5602008-10-29 10:16:30 +0530555
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700556 return 0;
557}
558
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400559static bool ar9002_hw_macversion_supported(u32 macversion)
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700560{
561 switch (macversion) {
562 case AR_SREV_VERSION_5416_PCI:
563 case AR_SREV_VERSION_5416_PCIE:
564 case AR_SREV_VERSION_9160:
565 case AR_SREV_VERSION_9100:
566 case AR_SREV_VERSION_9280:
567 case AR_SREV_VERSION_9285:
568 case AR_SREV_VERSION_9287:
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400569 case AR_SREV_VERSION_9271:
Luis R. Rodriguez7976b422009-09-23 23:07:02 -0400570 return true;
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700571 default:
572 break;
573 }
574 return false;
575}
576
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400577static void ar9002_hw_init_cal_settings(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700578{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700579 if (AR_SREV_9160_10_OR_LATER(ah)) {
580 if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530581 ah->iq_caldata.calData = &iq_cal_single_sample;
582 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700583 &adc_gain_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530584 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700585 &adc_dc_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530586 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700587 &adc_init_dc_cal;
588 } else {
Sujith2660b812009-02-09 13:27:26 +0530589 ah->iq_caldata.calData = &iq_cal_multi_sample;
590 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700591 &adc_gain_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530592 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700593 &adc_dc_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530594 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700595 &adc_init_dc_cal;
596 }
Sujith2660b812009-02-09 13:27:26 +0530597 ah->supp_cals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700598 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700599}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700600
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400601static void ar9002_hw_init_mode_regs(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700602{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400603 if (AR_SREV_9271(ah)) {
Luis R. Rodriguez85643282009-10-19 02:33:33 -0400604 INIT_INI_ARRAY(&ah->iniModes, ar9271Modes_9271,
605 ARRAY_SIZE(ar9271Modes_9271), 6);
606 INIT_INI_ARRAY(&ah->iniCommon, ar9271Common_9271,
607 ARRAY_SIZE(ar9271Common_9271), 2);
Sujith70807e92010-03-17 14:25:14 +0530608 INIT_INI_ARRAY(&ah->iniCommon_normal_cck_fir_coeff_9271,
609 ar9271Common_normal_cck_fir_coeff_9271,
610 ARRAY_SIZE(ar9271Common_normal_cck_fir_coeff_9271), 2);
611 INIT_INI_ARRAY(&ah->iniCommon_japan_2484_cck_fir_coeff_9271,
612 ar9271Common_japan_2484_cck_fir_coeff_9271,
613 ARRAY_SIZE(ar9271Common_japan_2484_cck_fir_coeff_9271), 2);
Luis R. Rodriguez85643282009-10-19 02:33:33 -0400614 INIT_INI_ARRAY(&ah->iniModes_9271_1_0_only,
615 ar9271Modes_9271_1_0_only,
616 ARRAY_SIZE(ar9271Modes_9271_1_0_only), 6);
Sujith70807e92010-03-17 14:25:14 +0530617 INIT_INI_ARRAY(&ah->iniModes_9271_ANI_reg, ar9271Modes_9271_ANI_reg,
618 ARRAY_SIZE(ar9271Modes_9271_ANI_reg), 6);
619 INIT_INI_ARRAY(&ah->iniModes_high_power_tx_gain_9271,
620 ar9271Modes_high_power_tx_gain_9271,
621 ARRAY_SIZE(ar9271Modes_high_power_tx_gain_9271), 6);
622 INIT_INI_ARRAY(&ah->iniModes_normal_power_tx_gain_9271,
623 ar9271Modes_normal_power_tx_gain_9271,
624 ARRAY_SIZE(ar9271Modes_normal_power_tx_gain_9271), 6);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400625 return;
626 }
627
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530628 if (AR_SREV_9287_11_OR_LATER(ah)) {
629 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_1,
630 ARRAY_SIZE(ar9287Modes_9287_1_1), 6);
631 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_1,
632 ARRAY_SIZE(ar9287Common_9287_1_1), 2);
633 if (ah->config.pcie_clock_req)
634 INIT_INI_ARRAY(&ah->iniPcieSerdes,
635 ar9287PciePhy_clkreq_off_L1_9287_1_1,
636 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_1), 2);
637 else
638 INIT_INI_ARRAY(&ah->iniPcieSerdes,
639 ar9287PciePhy_clkreq_always_on_L1_9287_1_1,
640 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_1),
641 2);
642 } else if (AR_SREV_9287_10_OR_LATER(ah)) {
643 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_0,
644 ARRAY_SIZE(ar9287Modes_9287_1_0), 6);
645 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_0,
646 ARRAY_SIZE(ar9287Common_9287_1_0), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700647
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530648 if (ah->config.pcie_clock_req)
649 INIT_INI_ARRAY(&ah->iniPcieSerdes,
650 ar9287PciePhy_clkreq_off_L1_9287_1_0,
651 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_0), 2);
652 else
653 INIT_INI_ARRAY(&ah->iniPcieSerdes,
654 ar9287PciePhy_clkreq_always_on_L1_9287_1_0,
655 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_0),
656 2);
657 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
658
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530659
Sujith2660b812009-02-09 13:27:26 +0530660 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530661 ARRAY_SIZE(ar9285Modes_9285_1_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530662 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530663 ARRAY_SIZE(ar9285Common_9285_1_2), 2);
664
Sujith2660b812009-02-09 13:27:26 +0530665 if (ah->config.pcie_clock_req) {
666 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530667 ar9285PciePhy_clkreq_off_L1_9285_1_2,
668 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2);
669 } else {
Sujith2660b812009-02-09 13:27:26 +0530670 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530671 ar9285PciePhy_clkreq_always_on_L1_9285_1_2,
672 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2),
673 2);
674 }
675 } else if (AR_SREV_9285_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530676 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530677 ARRAY_SIZE(ar9285Modes_9285), 6);
Sujith2660b812009-02-09 13:27:26 +0530678 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530679 ARRAY_SIZE(ar9285Common_9285), 2);
680
Sujith2660b812009-02-09 13:27:26 +0530681 if (ah->config.pcie_clock_req) {
682 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530683 ar9285PciePhy_clkreq_off_L1_9285,
684 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2);
685 } else {
Sujith2660b812009-02-09 13:27:26 +0530686 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530687 ar9285PciePhy_clkreq_always_on_L1_9285,
688 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285), 2);
689 }
690 } else if (AR_SREV_9280_20_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530691 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700692 ARRAY_SIZE(ar9280Modes_9280_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530693 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700694 ARRAY_SIZE(ar9280Common_9280_2), 2);
695
Sujith2660b812009-02-09 13:27:26 +0530696 if (ah->config.pcie_clock_req) {
697 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530698 ar9280PciePhy_clkreq_off_L1_9280,
699 ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700700 } else {
Sujith2660b812009-02-09 13:27:26 +0530701 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530702 ar9280PciePhy_clkreq_always_on_L1_9280,
703 ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700704 }
Sujith2660b812009-02-09 13:27:26 +0530705 INIT_INI_ARRAY(&ah->iniModesAdditional,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700706 ar9280Modes_fast_clock_9280_2,
Sujithf1dc5602008-10-29 10:16:30 +0530707 ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700708 } else if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530709 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700710 ARRAY_SIZE(ar9280Modes_9280), 6);
Sujith2660b812009-02-09 13:27:26 +0530711 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700712 ARRAY_SIZE(ar9280Common_9280), 2);
713 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530714 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700715 ARRAY_SIZE(ar5416Modes_9160), 6);
Sujith2660b812009-02-09 13:27:26 +0530716 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700717 ARRAY_SIZE(ar5416Common_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530718 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700719 ARRAY_SIZE(ar5416Bank0_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530720 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700721 ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530722 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700723 ARRAY_SIZE(ar5416Bank1_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530724 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700725 ARRAY_SIZE(ar5416Bank2_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530726 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700727 ARRAY_SIZE(ar5416Bank3_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530728 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700729 ARRAY_SIZE(ar5416Bank6_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530730 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700731 ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530732 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700733 ARRAY_SIZE(ar5416Bank7_9160), 2);
734 if (AR_SREV_9160_11(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530735 INIT_INI_ARRAY(&ah->iniAddac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700736 ar5416Addac_91601_1,
737 ARRAY_SIZE(ar5416Addac_91601_1), 2);
738 } else {
Sujith2660b812009-02-09 13:27:26 +0530739 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700740 ARRAY_SIZE(ar5416Addac_9160), 2);
741 }
742 } else if (AR_SREV_9100_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530743 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700744 ARRAY_SIZE(ar5416Modes_9100), 6);
Sujith2660b812009-02-09 13:27:26 +0530745 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700746 ARRAY_SIZE(ar5416Common_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530747 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700748 ARRAY_SIZE(ar5416Bank0_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530749 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700750 ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530751 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700752 ARRAY_SIZE(ar5416Bank1_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530753 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700754 ARRAY_SIZE(ar5416Bank2_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530755 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700756 ARRAY_SIZE(ar5416Bank3_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530757 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700758 ARRAY_SIZE(ar5416Bank6_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530759 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700760 ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530761 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700762 ARRAY_SIZE(ar5416Bank7_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530763 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700764 ARRAY_SIZE(ar5416Addac_9100), 2);
765 } else {
Sujith2660b812009-02-09 13:27:26 +0530766 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700767 ARRAY_SIZE(ar5416Modes), 6);
Sujith2660b812009-02-09 13:27:26 +0530768 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700769 ARRAY_SIZE(ar5416Common), 2);
Sujith2660b812009-02-09 13:27:26 +0530770 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700771 ARRAY_SIZE(ar5416Bank0), 2);
Sujith2660b812009-02-09 13:27:26 +0530772 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700773 ARRAY_SIZE(ar5416BB_RfGain), 3);
Sujith2660b812009-02-09 13:27:26 +0530774 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700775 ARRAY_SIZE(ar5416Bank1), 2);
Sujith2660b812009-02-09 13:27:26 +0530776 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700777 ARRAY_SIZE(ar5416Bank2), 2);
Sujith2660b812009-02-09 13:27:26 +0530778 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700779 ARRAY_SIZE(ar5416Bank3), 3);
Sujith2660b812009-02-09 13:27:26 +0530780 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700781 ARRAY_SIZE(ar5416Bank6), 3);
Sujith2660b812009-02-09 13:27:26 +0530782 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700783 ARRAY_SIZE(ar5416Bank6TPC), 3);
Sujith2660b812009-02-09 13:27:26 +0530784 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700785 ARRAY_SIZE(ar5416Bank7), 2);
Sujith2660b812009-02-09 13:27:26 +0530786 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700787 ARRAY_SIZE(ar5416Addac), 2);
788 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700789}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700790
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700791static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
792{
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530793 if (AR_SREV_9287_11_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530794 INIT_INI_ARRAY(&ah->iniModesRxGain,
795 ar9287Modes_rx_gain_9287_1_1,
796 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_1), 6);
797 else if (AR_SREV_9287_10(ah))
798 INIT_INI_ARRAY(&ah->iniModesRxGain,
799 ar9287Modes_rx_gain_9287_1_0,
800 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_0), 6);
801 else if (AR_SREV_9280_20(ah))
802 ath9k_hw_init_rxgain_ini(ah);
803
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530804 if (AR_SREV_9287_11_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530805 INIT_INI_ARRAY(&ah->iniModesTxGain,
806 ar9287Modes_tx_gain_9287_1_1,
807 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_1), 6);
808 } else if (AR_SREV_9287_10(ah)) {
809 INIT_INI_ARRAY(&ah->iniModesTxGain,
810 ar9287Modes_tx_gain_9287_1_0,
811 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_0), 6);
812 } else if (AR_SREV_9280_20(ah)) {
813 ath9k_hw_init_txgain_ini(ah);
814 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530815 u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
816
817 /* txgain table */
818 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) {
Vivek Natarajan53bc7aa2010-04-05 14:48:04 +0530819 if (AR_SREV_9285E_20(ah)) {
820 INIT_INI_ARRAY(&ah->iniModesTxGain,
821 ar9285Modes_XE2_0_high_power,
822 ARRAY_SIZE(
823 ar9285Modes_XE2_0_high_power), 6);
824 } else {
825 INIT_INI_ARRAY(&ah->iniModesTxGain,
826 ar9285Modes_high_power_tx_gain_9285_1_2,
827 ARRAY_SIZE(
828 ar9285Modes_high_power_tx_gain_9285_1_2), 6);
829 }
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530830 } else {
Vivek Natarajan53bc7aa2010-04-05 14:48:04 +0530831 if (AR_SREV_9285E_20(ah)) {
832 INIT_INI_ARRAY(&ah->iniModesTxGain,
833 ar9285Modes_XE2_0_normal_power,
834 ARRAY_SIZE(
835 ar9285Modes_XE2_0_normal_power), 6);
836 } else {
837 INIT_INI_ARRAY(&ah->iniModesTxGain,
838 ar9285Modes_original_tx_gain_9285_1_2,
839 ARRAY_SIZE(
840 ar9285Modes_original_tx_gain_9285_1_2), 6);
841 }
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530842 }
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530843 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700844}
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530845
Felix Fietkauaa8bc9e2010-01-23 20:04:18 +0100846static void ath9k_hw_init_eeprom_fix(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700847{
Pavel Roskin2eb46d92010-04-07 01:33:33 -0400848 struct base_eep_header *pBase = &(ah->eeprom.def.baseEepHeader);
849 struct ath_common *common = ath9k_hw_common(ah);
Sujith06d0f062009-02-12 10:06:45 +0530850
Pavel Roskin2eb46d92010-04-07 01:33:33 -0400851 ah->need_an_top2_fixup = (ah->hw_version.devid == AR9280_DEVID_PCI) &&
852 (ah->eep_map != EEP_MAP_4KBITS) &&
853 ((pBase->version & 0xff) > 0x0a) &&
854 (pBase->pwdclkind == 0);
Sujith06d0f062009-02-12 10:06:45 +0530855
Pavel Roskin2eb46d92010-04-07 01:33:33 -0400856 if (ah->need_an_top2_fixup)
857 ath_print(common, ATH_DBG_EEPROM,
858 "needs fixup for AR_AN_TOP2 register\n");
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700859}
860
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400861/* Called for all hardware families */
862static int __ath9k_hw_init(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700863{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700864 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700865 int r = 0;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700866
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700867 ath9k_hw_init_defaults(ah);
868 ath9k_hw_init_config(ah);
869
870 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700871 ath_print(common, ATH_DBG_FATAL,
872 "Couldn't reset chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700873 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700874 }
875
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400876 ar9002_hw_attach_ops(ah);
877
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700878 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700879 ath_print(common, ATH_DBG_FATAL, "Couldn't wakeup chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700880 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700881 }
882
883 if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
884 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
885 (AR_SREV_9280(ah) && !ah->is_pciexpress)) {
886 ah->config.serialize_regmode =
887 SER_REG_MODE_ON;
888 } else {
889 ah->config.serialize_regmode =
890 SER_REG_MODE_OFF;
891 }
892 }
893
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700894 ath_print(common, ATH_DBG_RESET, "serialize_regmode is %d\n",
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700895 ah->config.serialize_regmode);
896
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -0500897 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
898 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD >> 1;
899 else
900 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD;
901
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400902 if (!ath9k_hw_macversion_supported(ah)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700903 ath_print(common, ATH_DBG_FATAL,
904 "Mac Chip Rev 0x%02x.%x is not supported by "
905 "this driver\n", ah->hw_version.macVersion,
906 ah->hw_version.macRev);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700907 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700908 }
909
910 if (AR_SREV_9100(ah)) {
911 ah->iq_caldata.calData = &iq_cal_multi_sample;
912 ah->supp_cals = IQ_MISMATCH_CAL;
913 ah->is_pciexpress = false;
914 }
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400915
916 if (AR_SREV_9271(ah))
917 ah->is_pciexpress = false;
918
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700919 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700920 ath9k_hw_init_cal_settings(ah);
921
922 ah->ani_function = ATH9K_ANI_ALL;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400923 if (AR_SREV_9280_10_OR_LATER(ah))
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700924 ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
925
926 ath9k_hw_init_mode_regs(ah);
927
928 if (ah->is_pciexpress)
Vivek Natarajan93b1b372009-09-17 09:24:58 +0530929 ath9k_hw_configpcipowersave(ah, 0, 0);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700930 else
931 ath9k_hw_disablepcie(ah);
932
Sujith193cd452009-09-18 15:04:07 +0530933 /* Support for Japan ch.14 (2484) spread */
934 if (AR_SREV_9287_11_OR_LATER(ah)) {
935 INIT_INI_ARRAY(&ah->iniCckfirNormal,
936 ar9287Common_normal_cck_fir_coeff_92871_1,
937 ARRAY_SIZE(ar9287Common_normal_cck_fir_coeff_92871_1), 2);
938 INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
939 ar9287Common_japan_2484_cck_fir_coeff_92871_1,
940 ARRAY_SIZE(ar9287Common_japan_2484_cck_fir_coeff_92871_1), 2);
941 }
942
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700943 r = ath9k_hw_post_init(ah);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700944 if (r)
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700945 return r;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700946
947 ath9k_hw_init_mode_gain_regs(ah);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +0100948 r = ath9k_hw_fill_cap_info(ah);
949 if (r)
950 return r;
951
Felix Fietkauaa8bc9e2010-01-23 20:04:18 +0100952 ath9k_hw_init_eeprom_fix(ah);
Sujithf6688cd2008-12-07 21:43:10 +0530953
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700954 r = ath9k_hw_init_macaddr(ah);
955 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700956 ath_print(common, ATH_DBG_FATAL,
957 "Failed to initialize MAC address\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700958 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700959 }
960
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400961 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
Sujith2660b812009-02-09 13:27:26 +0530962 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700963 else
Sujith2660b812009-02-09 13:27:26 +0530964 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700965
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700966 ath9k_init_nfcal_hist_buffer(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700967
Luis R. Rodriguez211f5852009-10-06 21:19:07 -0400968 common->state = ATH_HW_INITIALIZED;
969
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700970 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700971}
972
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400973int ath9k_hw_init(struct ath_hw *ah)
974{
975 int ret;
976 struct ath_common *common = ath9k_hw_common(ah);
977
978 /* These are all the AR5008/AR9001/AR9002 hardware family of chipsets */
979 switch (ah->hw_version.devid) {
980 case AR5416_DEVID_PCI:
981 case AR5416_DEVID_PCIE:
982 case AR5416_AR9100_DEVID:
983 case AR9160_DEVID_PCI:
984 case AR9280_DEVID_PCI:
985 case AR9280_DEVID_PCIE:
986 case AR9285_DEVID_PCIE:
987 case AR5416_DEVID_AR9287_PCI:
988 case AR5416_DEVID_AR9287_PCIE:
989 case AR2427_DEVID_PCIE:
990 break;
991 default:
992 if (common->bus_ops->ath_bus_type == ATH_USB)
993 break;
994 ath_print(common, ATH_DBG_FATAL,
995 "Hardware device ID 0x%04x not supported\n",
996 ah->hw_version.devid);
997 return -EOPNOTSUPP;
998 }
999
1000 ret = __ath9k_hw_init(ah);
1001 if (ret) {
1002 ath_print(common, ATH_DBG_FATAL,
1003 "Unable to initialize hardware; "
1004 "initialization status: %d\n", ret);
1005 return ret;
1006 }
1007
1008 return 0;
1009}
1010EXPORT_SYMBOL(ath9k_hw_init);
1011
Sujithcbe61d82009-02-09 13:27:12 +05301012static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301013{
1014 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
1015 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
1016
1017 REG_WRITE(ah, AR_QOS_NO_ACK,
1018 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
1019 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
1020 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
1021
1022 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
1023 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
1024 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
1025 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
1026 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
1027}
1028
Sujithcbe61d82009-02-09 13:27:12 +05301029static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301030 struct ath9k_channel *chan)
1031{
Luis R. Rodriguez64773962010-04-15 17:38:17 -04001032 u32 pll = ath9k_hw_compute_pll_control(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301033
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001034 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +05301035
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -04001036 /* Switch the core clock for ar9271 to 117Mhz */
1037 if (AR_SREV_9271(ah)) {
Sujith25e2ab12010-03-17 14:25:22 +05301038 udelay(500);
1039 REG_WRITE(ah, 0x50040, 0x304);
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -04001040 }
1041
Sujithf1dc5602008-10-29 10:16:30 +05301042 udelay(RTC_PLL_SETTLE_DELAY);
1043
1044 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
1045}
1046
Sujithcbe61d82009-02-09 13:27:12 +05301047static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -08001048 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301049{
Pavel Roskin152d5302010-03-31 18:05:37 -04001050 u32 imr_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +05301051 AR_IMR_TXURN |
1052 AR_IMR_RXERR |
1053 AR_IMR_RXORN |
1054 AR_IMR_BCNMISC;
1055
Sujith0ce024c2009-12-14 14:57:00 +05301056 if (ah->config.rx_intr_mitigation)
Pavel Roskin152d5302010-03-31 18:05:37 -04001057 imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
Sujithf1dc5602008-10-29 10:16:30 +05301058 else
Pavel Roskin152d5302010-03-31 18:05:37 -04001059 imr_reg |= AR_IMR_RXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301060
Pavel Roskin152d5302010-03-31 18:05:37 -04001061 imr_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301062
Colin McCabed97809d2008-12-01 13:38:55 -08001063 if (opmode == NL80211_IFTYPE_AP)
Pavel Roskin152d5302010-03-31 18:05:37 -04001064 imr_reg |= AR_IMR_MIB;
Sujithf1dc5602008-10-29 10:16:30 +05301065
Pavel Roskin152d5302010-03-31 18:05:37 -04001066 REG_WRITE(ah, AR_IMR, imr_reg);
Pavel Roskin74bad5c2010-02-23 18:15:27 -05001067 ah->imrs2_reg |= AR_IMR_S2_GTT;
1068 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
Sujithf1dc5602008-10-29 10:16:30 +05301069
1070 if (!AR_SREV_9100(ah)) {
1071 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
1072 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
1073 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
1074 }
1075}
1076
Felix Fietkau0005baf2010-01-15 02:33:40 +01001077static void ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301078{
Felix Fietkau0005baf2010-01-15 02:33:40 +01001079 u32 val = ath9k_hw_mac_to_clks(ah, us);
1080 val = min(val, (u32) 0xFFFF);
1081 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, val);
Sujithf1dc5602008-10-29 10:16:30 +05301082}
1083
Felix Fietkau0005baf2010-01-15 02:33:40 +01001084static void ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301085{
Felix Fietkau0005baf2010-01-15 02:33:40 +01001086 u32 val = ath9k_hw_mac_to_clks(ah, us);
1087 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_ACK));
1088 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_ACK, val);
1089}
1090
1091static void ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
1092{
1093 u32 val = ath9k_hw_mac_to_clks(ah, us);
1094 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_CTS));
1095 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_CTS, val);
Sujithf1dc5602008-10-29 10:16:30 +05301096}
1097
Sujithcbe61d82009-02-09 13:27:12 +05301098static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +05301099{
Sujithf1dc5602008-10-29 10:16:30 +05301100 if (tu > 0xFFFF) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001101 ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT,
1102 "bad global tx timeout %u\n", tu);
Sujith2660b812009-02-09 13:27:26 +05301103 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301104 return false;
1105 } else {
1106 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +05301107 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +05301108 return true;
1109 }
1110}
1111
Felix Fietkau0005baf2010-01-15 02:33:40 +01001112void ath9k_hw_init_global_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301113{
Felix Fietkau0005baf2010-01-15 02:33:40 +01001114 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
1115 int acktimeout;
Felix Fietkaue239d852010-01-15 02:34:58 +01001116 int slottime;
Felix Fietkau0005baf2010-01-15 02:33:40 +01001117 int sifstime;
1118
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001119 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
1120 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +05301121
Sujith2660b812009-02-09 13:27:26 +05301122 if (ah->misc_mode != 0)
Sujithf1dc5602008-10-29 10:16:30 +05301123 REG_WRITE(ah, AR_PCU_MISC,
Sujith2660b812009-02-09 13:27:26 +05301124 REG_READ(ah, AR_PCU_MISC) | ah->misc_mode);
Felix Fietkau0005baf2010-01-15 02:33:40 +01001125
1126 if (conf->channel && conf->channel->band == IEEE80211_BAND_5GHZ)
1127 sifstime = 16;
1128 else
1129 sifstime = 10;
1130
Felix Fietkaue239d852010-01-15 02:34:58 +01001131 /* As defined by IEEE 802.11-2007 17.3.8.6 */
1132 slottime = ah->slottime + 3 * ah->coverage_class;
1133 acktimeout = slottime + sifstime;
Felix Fietkau42c45682010-02-11 18:07:19 +01001134
1135 /*
1136 * Workaround for early ACK timeouts, add an offset to match the
1137 * initval's 64us ack timeout value.
1138 * This was initially only meant to work around an issue with delayed
1139 * BA frames in some implementations, but it has been found to fix ACK
1140 * timeout issues in other cases as well.
1141 */
1142 if (conf->channel && conf->channel->band == IEEE80211_BAND_2GHZ)
1143 acktimeout += 64 - sifstime - ah->slottime;
1144
Felix Fietkaue239d852010-01-15 02:34:58 +01001145 ath9k_hw_setslottime(ah, slottime);
Felix Fietkau0005baf2010-01-15 02:33:40 +01001146 ath9k_hw_set_ack_timeout(ah, acktimeout);
1147 ath9k_hw_set_cts_timeout(ah, acktimeout);
Sujith2660b812009-02-09 13:27:26 +05301148 if (ah->globaltxtimeout != (u32) -1)
1149 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Sujithf1dc5602008-10-29 10:16:30 +05301150}
Felix Fietkau0005baf2010-01-15 02:33:40 +01001151EXPORT_SYMBOL(ath9k_hw_init_global_settings);
Sujithf1dc5602008-10-29 10:16:30 +05301152
Sujith285f2dd2010-01-08 10:36:07 +05301153void ath9k_hw_deinit(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001154{
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001155 struct ath_common *common = ath9k_hw_common(ah);
1156
Sujith736b3a22010-03-17 14:25:24 +05301157 if (common->state < ATH_HW_INITIALIZED)
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001158 goto free_hw;
1159
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001160 if (!AR_SREV_9100(ah))
Luis R. Rodrigueze70c0cf2009-08-03 12:24:51 -07001161 ath9k_hw_ani_disable(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001162
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001163 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001164
1165free_hw:
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001166 ath9k_hw_rf_free_ext_banks(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001167}
Sujith285f2dd2010-01-08 10:36:07 +05301168EXPORT_SYMBOL(ath9k_hw_deinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001169
Sujithf1dc5602008-10-29 10:16:30 +05301170/*******/
1171/* INI */
1172/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001173
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001174u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan)
Bob Copeland3a702e42009-03-30 22:30:29 -04001175{
1176 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
1177
1178 if (IS_CHAN_B(chan))
1179 ctl |= CTL_11B;
1180 else if (IS_CHAN_G(chan))
1181 ctl |= CTL_11G;
1182 else
1183 ctl |= CTL_11A;
1184
1185 return ctl;
1186}
1187
Sujithf1dc5602008-10-29 10:16:30 +05301188/****************************************/
1189/* Reset and Channel Switching Routines */
1190/****************************************/
1191
Sujithcbe61d82009-02-09 13:27:12 +05301192static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301193{
1194 u32 regval;
1195
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001196 /*
1197 * set AHB_MODE not to do cacheline prefetches
1198 */
Sujithf1dc5602008-10-29 10:16:30 +05301199 regval = REG_READ(ah, AR_AHB_MODE);
1200 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
1201
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001202 /*
1203 * let mac dma reads be in 128 byte chunks
1204 */
Sujithf1dc5602008-10-29 10:16:30 +05301205 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
1206 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
1207
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001208 /*
1209 * Restore TX Trigger Level to its pre-reset value.
1210 * The initial value depends on whether aggregation is enabled, and is
1211 * adjusted whenever underruns are detected.
1212 */
Sujith2660b812009-02-09 13:27:26 +05301213 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +05301214
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001215 /*
1216 * let mac dma writes be in 128 byte chunks
1217 */
Sujithf1dc5602008-10-29 10:16:30 +05301218 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
1219 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
1220
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001221 /*
1222 * Setup receive FIFO threshold to hold off TX activities
1223 */
Sujithf1dc5602008-10-29 10:16:30 +05301224 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1225
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001226 /*
1227 * reduce the number of usable entries in PCU TXBUF to avoid
1228 * wrap around issues.
1229 */
Sujithf1dc5602008-10-29 10:16:30 +05301230 if (AR_SREV_9285(ah)) {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001231 /* For AR9285 the number of Fifos are reduced to half.
1232 * So set the usable tx buf size also to half to
1233 * avoid data/delimiter underruns
1234 */
Sujithf1dc5602008-10-29 10:16:30 +05301235 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1236 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001237 } else if (!AR_SREV_9271(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +05301238 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1239 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1240 }
1241}
1242
Sujithcbe61d82009-02-09 13:27:12 +05301243static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301244{
1245 u32 val;
1246
1247 val = REG_READ(ah, AR_STA_ID1);
1248 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
1249 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001250 case NL80211_IFTYPE_AP:
Sujithf1dc5602008-10-29 10:16:30 +05301251 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
1252 | AR_STA_ID1_KSRCH_MODE);
1253 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1254 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001255 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04001256 case NL80211_IFTYPE_MESH_POINT:
Sujithf1dc5602008-10-29 10:16:30 +05301257 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
1258 | AR_STA_ID1_KSRCH_MODE);
1259 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1260 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001261 case NL80211_IFTYPE_STATION:
1262 case NL80211_IFTYPE_MONITOR:
Sujithf1dc5602008-10-29 10:16:30 +05301263 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
1264 break;
1265 }
1266}
1267
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001268void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled,
1269 u32 *coef_mantissa, u32 *coef_exponent)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001270{
1271 u32 coef_exp, coef_man;
1272
1273 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1274 if ((coef_scaled >> coef_exp) & 0x1)
1275 break;
1276
1277 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1278
1279 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1280
1281 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1282 *coef_exponent = coef_exp - 16;
1283}
1284
Sujithcbe61d82009-02-09 13:27:12 +05301285static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +05301286{
1287 u32 rst_flags;
1288 u32 tmpReg;
1289
Sujith70768492009-02-16 13:23:12 +05301290 if (AR_SREV_9100(ah)) {
1291 u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK);
1292 val &= ~AR_RTC_DERIVED_CLK_PERIOD;
1293 val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD);
1294 REG_WRITE(ah, AR_RTC_DERIVED_CLK, val);
1295 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1296 }
1297
Sujithf1dc5602008-10-29 10:16:30 +05301298 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1299 AR_RTC_FORCE_WAKE_ON_INT);
1300
1301 if (AR_SREV_9100(ah)) {
1302 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1303 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1304 } else {
1305 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1306 if (tmpReg &
1307 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1308 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001309 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05301310 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001311
1312 val = AR_RC_HOSTIF;
1313 if (!AR_SREV_9300_20_OR_LATER(ah))
1314 val |= AR_RC_AHB;
1315 REG_WRITE(ah, AR_RC, val);
1316
1317 } else if (!AR_SREV_9300_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05301318 REG_WRITE(ah, AR_RC, AR_RC_AHB);
Sujithf1dc5602008-10-29 10:16:30 +05301319
1320 rst_flags = AR_RTC_RC_MAC_WARM;
1321 if (type == ATH9K_RESET_COLD)
1322 rst_flags |= AR_RTC_RC_MAC_COLD;
1323 }
1324
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001325 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujithf1dc5602008-10-29 10:16:30 +05301326 udelay(50);
1327
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001328 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301329 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001330 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1331 "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301332 return false;
1333 }
1334
1335 if (!AR_SREV_9100(ah))
1336 REG_WRITE(ah, AR_RC, 0);
1337
Sujithf1dc5602008-10-29 10:16:30 +05301338 if (AR_SREV_9100(ah))
1339 udelay(50);
1340
1341 return true;
1342}
1343
Sujithcbe61d82009-02-09 13:27:12 +05301344static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301345{
1346 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1347 AR_RTC_FORCE_WAKE_ON_INT);
1348
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001349 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301350 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1351
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001352 REG_WRITE(ah, AR_RTC_RESET, 0);
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301353 udelay(2);
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301354
1355 if (!AR_SREV_9100(ah))
1356 REG_WRITE(ah, AR_RC, 0);
1357
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001358 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301359
1360 if (!ath9k_hw_wait(ah,
1361 AR_RTC_STATUS,
1362 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301363 AR_RTC_STATUS_ON,
1364 AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001365 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1366 "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301367 return false;
1368 }
1369
1370 ath9k_hw_read_revisions(ah);
1371
1372 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1373}
1374
Sujithcbe61d82009-02-09 13:27:12 +05301375static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301376{
1377 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1378 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1379
1380 switch (type) {
1381 case ATH9K_RESET_POWER_ON:
1382 return ath9k_hw_set_reset_power_on(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301383 case ATH9K_RESET_WARM:
1384 case ATH9K_RESET_COLD:
1385 return ath9k_hw_set_reset(ah, type);
Sujithf1dc5602008-10-29 10:16:30 +05301386 default:
1387 return false;
1388 }
1389}
1390
Sujithcbe61d82009-02-09 13:27:12 +05301391static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301392 struct ath9k_channel *chan)
1393{
Vivek Natarajan42abfbe2009-09-17 09:27:59 +05301394 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) {
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301395 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
1396 return false;
1397 } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
Sujithf1dc5602008-10-29 10:16:30 +05301398 return false;
1399
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001400 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05301401 return false;
1402
Sujith2660b812009-02-09 13:27:26 +05301403 ah->chip_fullsleep = false;
Sujithf1dc5602008-10-29 10:16:30 +05301404 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301405 ath9k_hw_set_rfmode(ah, chan);
1406
1407 return true;
1408}
1409
Sujithcbe61d82009-02-09 13:27:12 +05301410static bool ath9k_hw_channel_change(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001411 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301412{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001413 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001414 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001415 struct ieee80211_channel *channel = chan->chan;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001416 u32 qnum;
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001417 int r;
Sujithf1dc5602008-10-29 10:16:30 +05301418
1419 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1420 if (ath9k_hw_numtxpending(ah, qnum)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001421 ath_print(common, ATH_DBG_QUEUE,
1422 "Transmit frames pending on "
1423 "queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301424 return false;
1425 }
1426 }
1427
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001428 if (!ath9k_hw_rfbus_req(ah)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001429 ath_print(common, ATH_DBG_FATAL,
1430 "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301431 return false;
1432 }
1433
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001434 ath9k_hw_set_channel_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301435
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001436 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001437 if (r) {
1438 ath_print(common, ATH_DBG_FATAL,
1439 "Failed to set channel\n");
1440 return false;
Sujithf1dc5602008-10-29 10:16:30 +05301441 }
1442
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001443 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001444 ath9k_regd_get_ctl(regulatory, chan),
Sujithf74df6f2009-02-09 13:27:24 +05301445 channel->max_antenna_gain * 2,
1446 channel->max_power * 2,
1447 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001448 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05301449
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001450 ath9k_hw_rfbus_done(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301451
1452 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1453 ath9k_hw_set_delta_slope(ah, chan);
1454
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001455 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301456
1457 if (!chan->oneTimeCalsDone)
1458 chan->oneTimeCalsDone = true;
1459
1460 return true;
1461}
1462
Sujithcbe61d82009-02-09 13:27:12 +05301463int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001464 bool bChannelChange)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001465{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001466 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001467 u32 saveLedState;
Sujith2660b812009-02-09 13:27:26 +05301468 struct ath9k_channel *curchan = ah->curchan;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001469 u32 saveDefAntenna;
1470 u32 macStaId1;
Sujith46fe7822009-09-17 09:25:25 +05301471 u64 tsf = 0;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001472 int i, r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001473
Luis R. Rodriguez43c27612009-09-13 21:07:07 -07001474 ah->txchainmask = common->tx_chainmask;
1475 ah->rxchainmask = common->rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001476
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001477 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001478 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001479
Vasanthakumar Thiagarajan9ebef7992009-09-17 09:26:44 +05301480 if (curchan && !ah->chip_fullsleep)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001481 ath9k_hw_getnf(ah, curchan);
1482
1483 if (bChannelChange &&
Sujith2660b812009-02-09 13:27:26 +05301484 (ah->chip_fullsleep != true) &&
1485 (ah->curchan != NULL) &&
1486 (chan->channel != ah->curchan->channel) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001487 ((chan->channelFlags & CHANNEL_ALL) ==
Sujith2660b812009-02-09 13:27:26 +05301488 (ah->curchan->channelFlags & CHANNEL_ALL)) &&
Vasanthakumar Thiagarajan0a475cc2009-09-17 09:27:10 +05301489 !(AR_SREV_9280(ah) || IS_CHAN_A_5MHZ_SPACED(chan) ||
1490 IS_CHAN_A_5MHZ_SPACED(ah->curchan))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001491
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001492 if (ath9k_hw_channel_change(ah, chan)) {
Sujith2660b812009-02-09 13:27:26 +05301493 ath9k_hw_loadnf(ah, ah->curchan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001494 ath9k_hw_start_nfcal(ah);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001495 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001496 }
1497 }
1498
1499 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
1500 if (saveDefAntenna == 0)
1501 saveDefAntenna = 1;
1502
1503 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
1504
Sujith46fe7822009-09-17 09:25:25 +05301505 /* For chips on which RTC reset is done, save TSF before it gets cleared */
1506 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1507 tsf = ath9k_hw_gettsf64(ah);
1508
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001509 saveLedState = REG_READ(ah, AR_CFG_LED) &
1510 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
1511 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
1512
1513 ath9k_hw_mark_phy_inactive(ah);
1514
Sujith05020d22010-03-17 14:25:23 +05301515 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001516 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1517 REG_WRITE(ah,
1518 AR9271_RESET_POWER_DOWN_CONTROL,
1519 AR9271_RADIO_RF_RST);
1520 udelay(50);
1521 }
1522
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001523 if (!ath9k_hw_chip_reset(ah, chan)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001524 ath_print(common, ATH_DBG_FATAL, "Chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001525 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001526 }
1527
Sujith05020d22010-03-17 14:25:23 +05301528 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001529 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1530 ah->htc_reset_init = false;
1531 REG_WRITE(ah,
1532 AR9271_RESET_POWER_DOWN_CONTROL,
1533 AR9271_GATE_MAC_CTL);
1534 udelay(50);
1535 }
1536
Sujith46fe7822009-09-17 09:25:25 +05301537 /* Restore TSF */
1538 if (tsf && AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1539 ath9k_hw_settsf64(ah, tsf);
1540
Vasanthakumar Thiagarajan369391d2009-01-21 19:24:13 +05301541 if (AR_SREV_9280_10_OR_LATER(ah))
1542 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001543
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001544 r = ath9k_hw_process_ini(ah, chan);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001545 if (r)
1546 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001547
Jouni Malinen0ced0e12009-01-08 13:32:13 +02001548 /* Setup MFP options for CCMP */
1549 if (AR_SREV_9280_20_OR_LATER(ah)) {
1550 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
1551 * frames when constructing CCMP AAD. */
1552 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
1553 0xc7ff);
1554 ah->sw_mgmt_crypto = false;
1555 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1556 /* Disable hardware crypto for management frames */
1557 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
1558 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
1559 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1560 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
1561 ah->sw_mgmt_crypto = true;
1562 } else
1563 ah->sw_mgmt_crypto = true;
1564
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001565 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1566 ath9k_hw_set_delta_slope(ah, chan);
1567
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001568 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithd6509152009-03-13 08:56:05 +05301569 ah->eep_ops->set_board_values(ah, chan);
Luis R. Rodrigueza7765822009-10-19 02:33:45 -04001570
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001571 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
1572 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001573 | macStaId1
1574 | AR_STA_ID1_RTS_USE_DEF
Sujith2660b812009-02-09 13:27:26 +05301575 | (ah->config.
Sujith60b67f52008-08-07 10:52:38 +05301576 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Sujith2660b812009-02-09 13:27:26 +05301577 | ah->sta_id1_defaults);
1578 ath9k_hw_set_operating_mode(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001579
Luis R. Rodriguez13b81552009-09-10 17:52:45 -07001580 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001581
1582 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
1583
Luis R. Rodriguez3453ad82009-09-10 08:57:00 -07001584 ath9k_hw_write_associd(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001585
1586 REG_WRITE(ah, AR_ISR, ~0);
1587
1588 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
1589
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001590 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001591 if (r)
1592 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001593
1594 for (i = 0; i < AR_NUM_DCU; i++)
1595 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
1596
Sujith2660b812009-02-09 13:27:26 +05301597 ah->intr_txqs = 0;
1598 for (i = 0; i < ah->caps.total_queues; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001599 ath9k_hw_resettxqueue(ah, i);
1600
Sujith2660b812009-02-09 13:27:26 +05301601 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001602 ath9k_hw_init_qos(ah);
1603
Sujith2660b812009-02-09 13:27:26 +05301604 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301605 ath9k_enable_rfkill(ah);
Johannes Berg3b319aa2009-06-13 14:50:26 +05301606
Felix Fietkau0005baf2010-01-15 02:33:40 +01001607 ath9k_hw_init_global_settings(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001608
Vivek Natarajan326bebb2009-08-14 11:33:36 +05301609 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301610 REG_WRITE(ah, AR_D_GBL_IFS_SIFS,
1611 AR_D_GBL_IFS_SIFS_ASYNC_FIFO_DUR);
1612 REG_WRITE(ah, AR_D_GBL_IFS_SLOT,
1613 AR_D_GBL_IFS_SLOT_ASYNC_FIFO_DUR);
1614 REG_WRITE(ah, AR_D_GBL_IFS_EIFS,
1615 AR_D_GBL_IFS_EIFS_ASYNC_FIFO_DUR);
1616
1617 REG_WRITE(ah, AR_TIME_OUT, AR_TIME_OUT_ACK_CTS_ASYNC_FIFO_DUR);
1618 REG_WRITE(ah, AR_USEC, AR_USEC_ASYNC_FIFO_DUR);
1619
1620 REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
1621 AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
1622 REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
1623 AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
1624 }
Vivek Natarajan326bebb2009-08-14 11:33:36 +05301625 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301626 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1627 AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
1628 }
1629
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001630 REG_WRITE(ah, AR_STA_ID1,
1631 REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
1632
1633 ath9k_hw_set_dma(ah);
1634
1635 REG_WRITE(ah, AR_OBS, 8);
1636
Sujith0ce024c2009-12-14 14:57:00 +05301637 if (ah->config.rx_intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001638 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
1639 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
1640 }
1641
1642 ath9k_hw_init_bb(ah, chan);
1643
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001644 if (!ath9k_hw_init_cal(ah, chan))
Joe Perches6badaaf2009-06-28 09:26:32 -07001645 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001646
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001647 ath9k_hw_restore_chainmask(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001648 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
1649
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001650 /*
1651 * For big endian systems turn on swapping for descriptors
1652 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001653 if (AR_SREV_9100(ah)) {
1654 u32 mask;
1655 mask = REG_READ(ah, AR_CFG);
1656 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001657 ath_print(common, ATH_DBG_RESET,
Sujith04bd46382008-11-28 22:18:05 +05301658 "CFG Byte Swap Set 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001659 } else {
1660 mask =
1661 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
1662 REG_WRITE(ah, AR_CFG, mask);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001663 ath_print(common, ATH_DBG_RESET,
Sujith04bd46382008-11-28 22:18:05 +05301664 "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001665 }
1666 } else {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001667 /* Configure AR9271 target WLAN */
1668 if (AR_SREV_9271(ah))
1669 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001670#ifdef __BIG_ENDIAN
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001671 else
1672 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001673#endif
1674 }
1675
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001676 if (ah->btcoex_hw.enabled)
Vasanthakumar Thiagarajan42cc41e2009-08-26 21:08:45 +05301677 ath9k_hw_btcoex_enable(ah);
1678
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001679 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001680}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001681EXPORT_SYMBOL(ath9k_hw_reset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001682
Sujithf1dc5602008-10-29 10:16:30 +05301683/************************/
1684/* Key Cache Management */
1685/************************/
1686
Sujithcbe61d82009-02-09 13:27:12 +05301687bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001688{
Sujithf1dc5602008-10-29 10:16:30 +05301689 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001690
Sujith2660b812009-02-09 13:27:26 +05301691 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001692 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1693 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001694 return false;
1695 }
1696
Sujithf1dc5602008-10-29 10:16:30 +05301697 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001698
Sujithf1dc5602008-10-29 10:16:30 +05301699 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
1700 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
1701 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
1702 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
1703 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
1704 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
1705 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
1706 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
1707
1708 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
1709 u16 micentry = entry + 64;
1710
1711 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
1712 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
1713 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
1714 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
1715
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001716 }
1717
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001718 return true;
1719}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001720EXPORT_SYMBOL(ath9k_hw_keyreset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001721
Sujithcbe61d82009-02-09 13:27:12 +05301722bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001723{
Sujithf1dc5602008-10-29 10:16:30 +05301724 u32 macHi, macLo;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001725
Sujith2660b812009-02-09 13:27:26 +05301726 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001727 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1728 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001729 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001730 }
1731
Sujithf1dc5602008-10-29 10:16:30 +05301732 if (mac != NULL) {
1733 macHi = (mac[5] << 8) | mac[4];
1734 macLo = (mac[3] << 24) |
1735 (mac[2] << 16) |
1736 (mac[1] << 8) |
1737 mac[0];
1738 macLo >>= 1;
1739 macLo |= (macHi & 1) << 31;
1740 macHi >>= 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001741 } else {
Sujithf1dc5602008-10-29 10:16:30 +05301742 macLo = macHi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001743 }
Sujithf1dc5602008-10-29 10:16:30 +05301744 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
1745 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001746
1747 return true;
1748}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001749EXPORT_SYMBOL(ath9k_hw_keysetmac);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001750
Sujithcbe61d82009-02-09 13:27:12 +05301751bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
Sujithf1dc5602008-10-29 10:16:30 +05301752 const struct ath9k_keyval *k,
Jouni Malinene0caf9e2009-03-02 18:15:53 +02001753 const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001754{
Sujith2660b812009-02-09 13:27:26 +05301755 const struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001756 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301757 u32 key0, key1, key2, key3, key4;
1758 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001759
Sujithf1dc5602008-10-29 10:16:30 +05301760 if (entry >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001761 ath_print(common, ATH_DBG_FATAL,
1762 "keycache entry %u out of range\n", entry);
Sujithf1dc5602008-10-29 10:16:30 +05301763 return false;
1764 }
1765
1766 switch (k->kv_type) {
1767 case ATH9K_CIPHER_AES_OCB:
1768 keyType = AR_KEYTABLE_TYPE_AES;
1769 break;
1770 case ATH9K_CIPHER_AES_CCM:
1771 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001772 ath_print(common, ATH_DBG_ANY,
1773 "AES-CCM not supported by mac rev 0x%x\n",
1774 ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001775 return false;
1776 }
Sujithf1dc5602008-10-29 10:16:30 +05301777 keyType = AR_KEYTABLE_TYPE_CCM;
1778 break;
1779 case ATH9K_CIPHER_TKIP:
1780 keyType = AR_KEYTABLE_TYPE_TKIP;
1781 if (ATH9K_IS_MIC_ENABLED(ah)
1782 && entry + 64 >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001783 ath_print(common, ATH_DBG_ANY,
1784 "entry %u inappropriate for TKIP\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001785 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001786 }
Sujithf1dc5602008-10-29 10:16:30 +05301787 break;
1788 case ATH9K_CIPHER_WEP:
Zhu Yie31a16d2009-05-21 21:47:03 +08001789 if (k->kv_len < WLAN_KEY_LEN_WEP40) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001790 ath_print(common, ATH_DBG_ANY,
1791 "WEP key length %u too small\n", k->kv_len);
Sujithf1dc5602008-10-29 10:16:30 +05301792 return false;
1793 }
Zhu Yie31a16d2009-05-21 21:47:03 +08001794 if (k->kv_len <= WLAN_KEY_LEN_WEP40)
Sujithf1dc5602008-10-29 10:16:30 +05301795 keyType = AR_KEYTABLE_TYPE_40;
Zhu Yie31a16d2009-05-21 21:47:03 +08001796 else if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05301797 keyType = AR_KEYTABLE_TYPE_104;
1798 else
1799 keyType = AR_KEYTABLE_TYPE_128;
1800 break;
1801 case ATH9K_CIPHER_CLR:
1802 keyType = AR_KEYTABLE_TYPE_CLR;
1803 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001804 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001805 ath_print(common, ATH_DBG_FATAL,
1806 "cipher %u not supported\n", k->kv_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001807 return false;
1808 }
Sujithf1dc5602008-10-29 10:16:30 +05301809
Jouni Malinene0caf9e2009-03-02 18:15:53 +02001810 key0 = get_unaligned_le32(k->kv_val + 0);
1811 key1 = get_unaligned_le16(k->kv_val + 4);
1812 key2 = get_unaligned_le32(k->kv_val + 6);
1813 key3 = get_unaligned_le16(k->kv_val + 10);
1814 key4 = get_unaligned_le32(k->kv_val + 12);
Zhu Yie31a16d2009-05-21 21:47:03 +08001815 if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05301816 key4 &= 0xff;
1817
Jouni Malinen672903b2009-03-02 15:06:31 +02001818 /*
1819 * Note: Key cache registers access special memory area that requires
1820 * two 32-bit writes to actually update the values in the internal
1821 * memory. Consequently, the exact order and pairs used here must be
1822 * maintained.
1823 */
1824
Sujithf1dc5602008-10-29 10:16:30 +05301825 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
1826 u16 micentry = entry + 64;
1827
Jouni Malinen672903b2009-03-02 15:06:31 +02001828 /*
1829 * Write inverted key[47:0] first to avoid Michael MIC errors
1830 * on frames that could be sent or received at the same time.
1831 * The correct key will be written in the end once everything
1832 * else is ready.
1833 */
Sujithf1dc5602008-10-29 10:16:30 +05301834 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
1835 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02001836
1837 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05301838 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
1839 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02001840
1841 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05301842 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
1843 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
Jouni Malinen672903b2009-03-02 15:06:31 +02001844
1845 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05301846 (void) ath9k_hw_keysetmac(ah, entry, mac);
1847
Sujith2660b812009-02-09 13:27:26 +05301848 if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) {
Jouni Malinen672903b2009-03-02 15:06:31 +02001849 /*
1850 * TKIP uses two key cache entries:
1851 * Michael MIC TX/RX keys in the same key cache entry
1852 * (idx = main index + 64):
1853 * key0 [31:0] = RX key [31:0]
1854 * key1 [15:0] = TX key [31:16]
1855 * key1 [31:16] = reserved
1856 * key2 [31:0] = RX key [63:32]
1857 * key3 [15:0] = TX key [15:0]
1858 * key3 [31:16] = reserved
1859 * key4 [31:0] = TX key [63:32]
1860 */
Sujithf1dc5602008-10-29 10:16:30 +05301861 u32 mic0, mic1, mic2, mic3, mic4;
1862
1863 mic0 = get_unaligned_le32(k->kv_mic + 0);
1864 mic2 = get_unaligned_le32(k->kv_mic + 4);
1865 mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
1866 mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
1867 mic4 = get_unaligned_le32(k->kv_txmic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02001868
1869 /* Write RX[31:0] and TX[31:16] */
Sujithf1dc5602008-10-29 10:16:30 +05301870 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
1871 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
Jouni Malinen672903b2009-03-02 15:06:31 +02001872
1873 /* Write RX[63:32] and TX[15:0] */
Sujithf1dc5602008-10-29 10:16:30 +05301874 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
1875 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
Jouni Malinen672903b2009-03-02 15:06:31 +02001876
1877 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05301878 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
1879 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
1880 AR_KEYTABLE_TYPE_CLR);
1881
1882 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02001883 /*
1884 * TKIP uses four key cache entries (two for group
1885 * keys):
1886 * Michael MIC TX/RX keys are in different key cache
1887 * entries (idx = main index + 64 for TX and
1888 * main index + 32 + 96 for RX):
1889 * key0 [31:0] = TX/RX MIC key [31:0]
1890 * key1 [31:0] = reserved
1891 * key2 [31:0] = TX/RX MIC key [63:32]
1892 * key3 [31:0] = reserved
1893 * key4 [31:0] = reserved
1894 *
1895 * Upper layer code will call this function separately
1896 * for TX and RX keys when these registers offsets are
1897 * used.
1898 */
Sujithf1dc5602008-10-29 10:16:30 +05301899 u32 mic0, mic2;
1900
1901 mic0 = get_unaligned_le32(k->kv_mic + 0);
1902 mic2 = get_unaligned_le32(k->kv_mic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02001903
1904 /* Write MIC key[31:0] */
Sujithf1dc5602008-10-29 10:16:30 +05301905 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
1906 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02001907
1908 /* Write MIC key[63:32] */
Sujithf1dc5602008-10-29 10:16:30 +05301909 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
1910 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02001911
1912 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05301913 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
1914 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
1915 AR_KEYTABLE_TYPE_CLR);
1916 }
Jouni Malinen672903b2009-03-02 15:06:31 +02001917
1918 /* MAC address registers are reserved for the MIC entry */
Sujithf1dc5602008-10-29 10:16:30 +05301919 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
1920 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02001921
1922 /*
1923 * Write the correct (un-inverted) key[47:0] last to enable
1924 * TKIP now that all other registers are set with correct
1925 * values.
1926 */
Sujithf1dc5602008-10-29 10:16:30 +05301927 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
1928 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
1929 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02001930 /* Write key[47:0] */
Sujithf1dc5602008-10-29 10:16:30 +05301931 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
1932 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02001933
1934 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05301935 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
1936 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02001937
1938 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05301939 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
1940 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
1941
Jouni Malinen672903b2009-03-02 15:06:31 +02001942 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05301943 (void) ath9k_hw_keysetmac(ah, entry, mac);
1944 }
1945
Sujithf1dc5602008-10-29 10:16:30 +05301946 return true;
1947}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001948EXPORT_SYMBOL(ath9k_hw_set_keycache_entry);
Sujithf1dc5602008-10-29 10:16:30 +05301949
Sujithcbe61d82009-02-09 13:27:12 +05301950bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry)
Sujithf1dc5602008-10-29 10:16:30 +05301951{
Sujith2660b812009-02-09 13:27:26 +05301952 if (entry < ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05301953 u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
1954 if (val & AR_KEYTABLE_VALID)
1955 return true;
1956 }
1957 return false;
1958}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001959EXPORT_SYMBOL(ath9k_hw_keyisvalid);
Sujithf1dc5602008-10-29 10:16:30 +05301960
1961/******************************/
1962/* Power Management (Chipset) */
1963/******************************/
1964
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001965/*
1966 * Notify Power Mgt is disabled in self-generated frames.
1967 * If requested, force chip to sleep.
1968 */
Sujithcbe61d82009-02-09 13:27:12 +05301969static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05301970{
1971 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
1972 if (setChip) {
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001973 /*
1974 * Clear the RTC force wake bit to allow the
1975 * mac to go to sleep.
1976 */
Sujithf1dc5602008-10-29 10:16:30 +05301977 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
1978 AR_RTC_FORCE_WAKE_EN);
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001979 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05301980 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1981
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001982 /* Shutdown chip. Active low */
Sujith14b3af32010-03-17 14:25:18 +05301983 if (!AR_SREV_5416(ah) && !AR_SREV_9271(ah))
Sujith4921be82009-09-18 15:04:27 +05301984 REG_CLR_BIT(ah, (AR_RTC_RESET),
1985 AR_RTC_RESET_EN);
Sujithf1dc5602008-10-29 10:16:30 +05301986 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001987}
1988
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04001989/*
1990 * Notify Power Management is enabled in self-generating
1991 * frames. If request, set power mode of chip to
1992 * auto/normal. Duration in units of 128us (1/8 TU).
1993 */
Sujithcbe61d82009-02-09 13:27:12 +05301994static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001995{
Sujithf1dc5602008-10-29 10:16:30 +05301996 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
1997 if (setChip) {
Sujith2660b812009-02-09 13:27:26 +05301998 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001999
Sujithf1dc5602008-10-29 10:16:30 +05302000 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04002001 /* Set WakeOnInterrupt bit; clear ForceWake bit */
Sujithf1dc5602008-10-29 10:16:30 +05302002 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2003 AR_RTC_FORCE_WAKE_ON_INT);
2004 } else {
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04002005 /*
2006 * Clear the RTC force wake bit to allow the
2007 * mac to go to sleep.
2008 */
Sujithf1dc5602008-10-29 10:16:30 +05302009 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2010 AR_RTC_FORCE_WAKE_EN);
2011 }
2012 }
2013}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002014
Sujithcbe61d82009-02-09 13:27:12 +05302015static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302016{
2017 u32 val;
2018 int i;
2019
2020 if (setChip) {
2021 if ((REG_READ(ah, AR_RTC_STATUS) &
2022 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2023 if (ath9k_hw_set_reset_reg(ah,
2024 ATH9K_RESET_POWER_ON) != true) {
2025 return false;
2026 }
Luis R. Rodrigueze0412282010-04-15 17:38:15 -04002027 if (!AR_SREV_9300_20_OR_LATER(ah))
2028 ath9k_hw_init_pll(ah, NULL);
Sujithf1dc5602008-10-29 10:16:30 +05302029 }
2030 if (AR_SREV_9100(ah))
2031 REG_SET_BIT(ah, AR_RTC_RESET,
2032 AR_RTC_RESET_EN);
2033
2034 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2035 AR_RTC_FORCE_WAKE_EN);
2036 udelay(50);
2037
2038 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2039 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2040 if (val == AR_RTC_STATUS_ON)
2041 break;
2042 udelay(50);
2043 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2044 AR_RTC_FORCE_WAKE_EN);
2045 }
2046 if (i == 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002047 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2048 "Failed to wakeup in %uus\n",
2049 POWER_UP_TIME / 20);
Sujithf1dc5602008-10-29 10:16:30 +05302050 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002051 }
2052 }
2053
Sujithf1dc5602008-10-29 10:16:30 +05302054 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2055
2056 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002057}
2058
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002059bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05302060{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002061 struct ath_common *common = ath9k_hw_common(ah);
Sujithcbe61d82009-02-09 13:27:12 +05302062 int status = true, setChip = true;
Sujithf1dc5602008-10-29 10:16:30 +05302063 static const char *modes[] = {
2064 "AWAKE",
2065 "FULL-SLEEP",
2066 "NETWORK SLEEP",
2067 "UNDEFINED"
2068 };
Sujithf1dc5602008-10-29 10:16:30 +05302069
Gabor Juhoscbdec972009-07-24 17:27:22 +02002070 if (ah->power_mode == mode)
2071 return status;
2072
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002073 ath_print(common, ATH_DBG_RESET, "%s -> %s\n",
2074 modes[ah->power_mode], modes[mode]);
Sujithf1dc5602008-10-29 10:16:30 +05302075
2076 switch (mode) {
2077 case ATH9K_PM_AWAKE:
2078 status = ath9k_hw_set_power_awake(ah, setChip);
2079 break;
2080 case ATH9K_PM_FULL_SLEEP:
2081 ath9k_set_power_sleep(ah, setChip);
Sujith2660b812009-02-09 13:27:26 +05302082 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05302083 break;
2084 case ATH9K_PM_NETWORK_SLEEP:
2085 ath9k_set_power_network_sleep(ah, setChip);
2086 break;
2087 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002088 ath_print(common, ATH_DBG_FATAL,
2089 "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05302090 return false;
2091 }
Sujith2660b812009-02-09 13:27:26 +05302092 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05302093
2094 return status;
2095}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002096EXPORT_SYMBOL(ath9k_hw_setpower);
Sujithf1dc5602008-10-29 10:16:30 +05302097
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002098/*
2099 * Helper for ASPM support.
2100 *
2101 * Disable PLL when in L0s as well as receiver clock when in L1.
2102 * This power saving option must be enabled through the SerDes.
2103 *
2104 * Programming the SerDes must go through the same 288 bit serial shift
2105 * register as the other analog registers. Hence the 9 writes.
2106 */
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04002107static void ar9002_hw_configpcipowersave(struct ath_hw *ah,
2108 int restore,
2109 int power_off)
Sujithf1dc5602008-10-29 10:16:30 +05302110{
Sujithf1dc5602008-10-29 10:16:30 +05302111 u8 i;
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302112 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05302113
Sujith2660b812009-02-09 13:27:26 +05302114 if (ah->is_pciexpress != true)
Sujithf1dc5602008-10-29 10:16:30 +05302115 return;
2116
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002117 /* Do not touch SerDes registers */
Sujith2660b812009-02-09 13:27:26 +05302118 if (ah->config.pcie_powersave_enable == 2)
Sujithf1dc5602008-10-29 10:16:30 +05302119 return;
2120
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002121 /* Nothing to do on restore for 11N */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302122 if (!restore) {
2123 if (AR_SREV_9280_20_OR_LATER(ah)) {
2124 /*
2125 * AR9280 2.0 or later chips use SerDes values from the
2126 * initvals.h initialized depending on chipset during
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04002127 * __ath9k_hw_init()
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302128 */
2129 for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
2130 REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
2131 INI_RA(&ah->iniPcieSerdes, i, 1));
2132 }
2133 } else if (AR_SREV_9280(ah) &&
2134 (ah->hw_version.macRev == AR_SREV_REVISION_9280_10)) {
2135 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
2136 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
Sujithf1dc5602008-10-29 10:16:30 +05302137
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302138 /* RX shut off when elecidle is asserted */
2139 REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
2140 REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
2141 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
2142
2143 /* Shut off CLKREQ active in L1 */
2144 if (ah->config.pcie_clock_req)
2145 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
2146 else
2147 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
2148
2149 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2150 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2151 REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
2152
2153 /* Load the new settings */
2154 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
2155
2156 } else {
2157 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
2158 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
2159
2160 /* RX shut off when elecidle is asserted */
2161 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
2162 REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
2163 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
2164
2165 /*
2166 * Ignore ah->ah_config.pcie_clock_req setting for
2167 * pre-AR9280 11n
2168 */
2169 REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
2170
2171 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2172 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2173 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
2174
2175 /* Load the new settings */
2176 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
Sujithf1dc5602008-10-29 10:16:30 +05302177 }
Sujithf1dc5602008-10-29 10:16:30 +05302178
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302179 udelay(1000);
Sujithf1dc5602008-10-29 10:16:30 +05302180
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302181 /* set bit 19 to allow forcing of pcie core into L1 state */
2182 REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
Sujithf1dc5602008-10-29 10:16:30 +05302183
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302184 /* Several PCIe massages to ensure proper behaviour */
2185 if (ah->config.pcie_waen) {
2186 val = ah->config.pcie_waen;
2187 if (!power_off)
2188 val &= (~AR_WA_D3_L1_DISABLE);
2189 } else {
2190 if (AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
2191 AR_SREV_9287(ah)) {
2192 val = AR9285_WA_DEFAULT;
2193 if (!power_off)
2194 val &= (~AR_WA_D3_L1_DISABLE);
2195 } else if (AR_SREV_9280(ah)) {
2196 /*
2197 * On AR9280 chips bit 22 of 0x4004 needs to be
2198 * set otherwise card may disappear.
2199 */
2200 val = AR9280_WA_DEFAULT;
2201 if (!power_off)
2202 val &= (~AR_WA_D3_L1_DISABLE);
2203 } else
2204 val = AR_WA_DEFAULT;
2205 }
Sujithf1dc5602008-10-29 10:16:30 +05302206
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302207 REG_WRITE(ah, AR_WA, val);
Sujithf1dc5602008-10-29 10:16:30 +05302208 }
2209
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302210 if (power_off) {
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002211 /*
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302212 * Set PCIe workaround bits
2213 * bit 14 in WA register (disable L1) should only
2214 * be set when device enters D3 and be cleared
2215 * when device comes back to D0.
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002216 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302217 if (ah->config.pcie_waen) {
2218 if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE)
2219 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
2220 } else {
2221 if (((AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
2222 AR_SREV_9287(ah)) &&
2223 (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)) ||
2224 (AR_SREV_9280(ah) &&
2225 (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE))) {
2226 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
2227 }
2228 }
Sujithf1dc5602008-10-29 10:16:30 +05302229 }
2230}
2231
2232/**********************/
2233/* Interrupt Handling */
2234/**********************/
2235
Sujithcbe61d82009-02-09 13:27:12 +05302236bool ath9k_hw_intrpend(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002237{
2238 u32 host_isr;
2239
2240 if (AR_SREV_9100(ah))
2241 return true;
2242
2243 host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
2244 if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
2245 return true;
2246
2247 host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
2248 if ((host_isr & AR_INTR_SYNC_DEFAULT)
2249 && (host_isr != AR_INTR_SPURIOUS))
2250 return true;
2251
2252 return false;
2253}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002254EXPORT_SYMBOL(ath9k_hw_intrpend);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002255
Sujithcbe61d82009-02-09 13:27:12 +05302256bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002257{
2258 u32 isr = 0;
2259 u32 mask2 = 0;
Sujith2660b812009-02-09 13:27:26 +05302260 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002261 u32 sync_cause = 0;
2262 bool fatal_int = false;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002263 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002264
2265 if (!AR_SREV_9100(ah)) {
2266 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
2267 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
2268 == AR_RTC_STATUS_ON) {
2269 isr = REG_READ(ah, AR_ISR);
2270 }
2271 }
2272
Sujithf1dc5602008-10-29 10:16:30 +05302273 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
2274 AR_INTR_SYNC_DEFAULT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002275
2276 *masked = 0;
2277
2278 if (!isr && !sync_cause)
2279 return false;
2280 } else {
2281 *masked = 0;
2282 isr = REG_READ(ah, AR_ISR);
2283 }
2284
2285 if (isr) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002286 if (isr & AR_ISR_BCNMISC) {
2287 u32 isr2;
2288 isr2 = REG_READ(ah, AR_ISR_S2);
2289 if (isr2 & AR_ISR_S2_TIM)
2290 mask2 |= ATH9K_INT_TIM;
2291 if (isr2 & AR_ISR_S2_DTIM)
2292 mask2 |= ATH9K_INT_DTIM;
2293 if (isr2 & AR_ISR_S2_DTIMSYNC)
2294 mask2 |= ATH9K_INT_DTIMSYNC;
2295 if (isr2 & (AR_ISR_S2_CABEND))
2296 mask2 |= ATH9K_INT_CABEND;
2297 if (isr2 & AR_ISR_S2_GTT)
2298 mask2 |= ATH9K_INT_GTT;
2299 if (isr2 & AR_ISR_S2_CST)
2300 mask2 |= ATH9K_INT_CST;
Sujith4af9cf42009-02-12 10:06:47 +05302301 if (isr2 & AR_ISR_S2_TSFOOR)
2302 mask2 |= ATH9K_INT_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002303 }
2304
2305 isr = REG_READ(ah, AR_ISR_RAC);
2306 if (isr == 0xffffffff) {
2307 *masked = 0;
2308 return false;
2309 }
2310
2311 *masked = isr & ATH9K_INT_COMMON;
2312
Sujith0ce024c2009-12-14 14:57:00 +05302313 if (ah->config.rx_intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002314 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
2315 *masked |= ATH9K_INT_RX;
2316 }
2317
2318 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
2319 *masked |= ATH9K_INT_RX;
2320 if (isr &
2321 (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
2322 AR_ISR_TXEOL)) {
2323 u32 s0_s, s1_s;
2324
2325 *masked |= ATH9K_INT_TX;
2326
2327 s0_s = REG_READ(ah, AR_ISR_S0_S);
Sujith2660b812009-02-09 13:27:26 +05302328 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
2329 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002330
2331 s1_s = REG_READ(ah, AR_ISR_S1_S);
Sujith2660b812009-02-09 13:27:26 +05302332 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
2333 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002334 }
2335
2336 if (isr & AR_ISR_RXORN) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002337 ath_print(common, ATH_DBG_INTERRUPT,
2338 "receive FIFO overrun interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002339 }
2340
2341 if (!AR_SREV_9100(ah)) {
Sujith60b67f52008-08-07 10:52:38 +05302342 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002343 u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
2344 if (isr5 & AR_ISR_S5_TIM_TIMER)
2345 *masked |= ATH9K_INT_TIM_TIMER;
2346 }
2347 }
2348
2349 *masked |= mask2;
2350 }
Sujithf1dc5602008-10-29 10:16:30 +05302351
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002352 if (AR_SREV_9100(ah))
2353 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302354
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302355 if (isr & AR_ISR_GENTMR) {
2356 u32 s5_s;
2357
2358 s5_s = REG_READ(ah, AR_ISR_S5_S);
2359 if (isr & AR_ISR_GENTMR) {
2360 ah->intr_gen_timer_trigger =
2361 MS(s5_s, AR_ISR_S5_GENTIMER_TRIG);
2362
2363 ah->intr_gen_timer_thresh =
2364 MS(s5_s, AR_ISR_S5_GENTIMER_THRESH);
2365
2366 if (ah->intr_gen_timer_trigger)
2367 *masked |= ATH9K_INT_GENTIMER;
2368
2369 }
2370 }
2371
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002372 if (sync_cause) {
2373 fatal_int =
2374 (sync_cause &
2375 (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
2376 ? true : false;
2377
2378 if (fatal_int) {
2379 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002380 ath_print(common, ATH_DBG_ANY,
2381 "received PCI FATAL interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002382 }
2383 if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002384 ath_print(common, ATH_DBG_ANY,
2385 "received PCI PERR interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002386 }
Steven Luoa89bff92009-04-12 02:57:54 -07002387 *masked |= ATH9K_INT_FATAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002388 }
2389 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002390 ath_print(common, ATH_DBG_INTERRUPT,
2391 "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002392 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
2393 REG_WRITE(ah, AR_RC, 0);
2394 *masked |= ATH9K_INT_FATAL;
2395 }
2396 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002397 ath_print(common, ATH_DBG_INTERRUPT,
2398 "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002399 }
2400
2401 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
2402 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
2403 }
Sujithf1dc5602008-10-29 10:16:30 +05302404
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002405 return true;
2406}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002407EXPORT_SYMBOL(ath9k_hw_getisr);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002408
Sujithcbe61d82009-02-09 13:27:12 +05302409enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002410{
Pavel Roskin152d5302010-03-31 18:05:37 -04002411 enum ath9k_int omask = ah->imask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002412 u32 mask, mask2;
Sujith2660b812009-02-09 13:27:26 +05302413 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002414 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002415
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002416 ath_print(common, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002417
2418 if (omask & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002419 ath_print(common, ATH_DBG_INTERRUPT, "disable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002420 REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
2421 (void) REG_READ(ah, AR_IER);
2422 if (!AR_SREV_9100(ah)) {
2423 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
2424 (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
2425
2426 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
2427 (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
2428 }
2429 }
2430
2431 mask = ints & ATH9K_INT_COMMON;
2432 mask2 = 0;
2433
2434 if (ints & ATH9K_INT_TX) {
Sujith2660b812009-02-09 13:27:26 +05302435 if (ah->txok_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002436 mask |= AR_IMR_TXOK;
Sujith2660b812009-02-09 13:27:26 +05302437 if (ah->txdesc_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002438 mask |= AR_IMR_TXDESC;
Sujith2660b812009-02-09 13:27:26 +05302439 if (ah->txerr_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002440 mask |= AR_IMR_TXERR;
Sujith2660b812009-02-09 13:27:26 +05302441 if (ah->txeol_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002442 mask |= AR_IMR_TXEOL;
2443 }
2444 if (ints & ATH9K_INT_RX) {
2445 mask |= AR_IMR_RXERR;
Sujith0ce024c2009-12-14 14:57:00 +05302446 if (ah->config.rx_intr_mitigation)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002447 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
2448 else
2449 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
Sujith60b67f52008-08-07 10:52:38 +05302450 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002451 mask |= AR_IMR_GENTMR;
2452 }
2453
2454 if (ints & (ATH9K_INT_BMISC)) {
2455 mask |= AR_IMR_BCNMISC;
2456 if (ints & ATH9K_INT_TIM)
2457 mask2 |= AR_IMR_S2_TIM;
2458 if (ints & ATH9K_INT_DTIM)
2459 mask2 |= AR_IMR_S2_DTIM;
2460 if (ints & ATH9K_INT_DTIMSYNC)
2461 mask2 |= AR_IMR_S2_DTIMSYNC;
2462 if (ints & ATH9K_INT_CABEND)
Sujith4af9cf42009-02-12 10:06:47 +05302463 mask2 |= AR_IMR_S2_CABEND;
2464 if (ints & ATH9K_INT_TSFOOR)
2465 mask2 |= AR_IMR_S2_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002466 }
2467
2468 if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
2469 mask |= AR_IMR_BCNMISC;
2470 if (ints & ATH9K_INT_GTT)
2471 mask2 |= AR_IMR_S2_GTT;
2472 if (ints & ATH9K_INT_CST)
2473 mask2 |= AR_IMR_S2_CST;
2474 }
2475
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002476 ath_print(common, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002477 REG_WRITE(ah, AR_IMR, mask);
Pavel Roskin74bad5c2010-02-23 18:15:27 -05002478 ah->imrs2_reg &= ~(AR_IMR_S2_TIM | AR_IMR_S2_DTIM | AR_IMR_S2_DTIMSYNC |
2479 AR_IMR_S2_CABEND | AR_IMR_S2_CABTO |
2480 AR_IMR_S2_TSFOOR | AR_IMR_S2_GTT | AR_IMR_S2_CST);
2481 ah->imrs2_reg |= mask2;
2482 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002483
Sujith60b67f52008-08-07 10:52:38 +05302484 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002485 if (ints & ATH9K_INT_TIM_TIMER)
2486 REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
2487 else
2488 REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
2489 }
2490
2491 if (ints & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002492 ath_print(common, ATH_DBG_INTERRUPT, "enable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002493 REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
2494 if (!AR_SREV_9100(ah)) {
2495 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
2496 AR_INTR_MAC_IRQ);
2497 REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
2498
2499
2500 REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
2501 AR_INTR_SYNC_DEFAULT);
2502 REG_WRITE(ah, AR_INTR_SYNC_MASK,
2503 AR_INTR_SYNC_DEFAULT);
2504 }
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002505 ath_print(common, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
2506 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002507 }
2508
2509 return omask;
2510}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002511EXPORT_SYMBOL(ath9k_hw_set_interrupts);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002512
Sujithf1dc5602008-10-29 10:16:30 +05302513/*******************/
2514/* Beacon Handling */
2515/*******************/
2516
Sujithcbe61d82009-02-09 13:27:12 +05302517void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002518{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002519 int flags = 0;
2520
Sujith2660b812009-02-09 13:27:26 +05302521 ah->beacon_interval = beacon_period;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002522
Sujith2660b812009-02-09 13:27:26 +05302523 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08002524 case NL80211_IFTYPE_STATION:
2525 case NL80211_IFTYPE_MONITOR:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002526 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
2527 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
2528 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
2529 flags |= AR_TBTT_TIMER_EN;
2530 break;
Colin McCabed97809d2008-12-01 13:38:55 -08002531 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04002532 case NL80211_IFTYPE_MESH_POINT:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002533 REG_SET_BIT(ah, AR_TXCFG,
2534 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
2535 REG_WRITE(ah, AR_NEXT_NDP_TIMER,
2536 TU_TO_USEC(next_beacon +
Sujith2660b812009-02-09 13:27:26 +05302537 (ah->atim_window ? ah->
2538 atim_window : 1)));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002539 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08002540 case NL80211_IFTYPE_AP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002541 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
2542 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
2543 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05302544 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302545 dma_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002546 REG_WRITE(ah, AR_NEXT_SWBA,
2547 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05302548 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302549 sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002550 flags |=
2551 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
2552 break;
Colin McCabed97809d2008-12-01 13:38:55 -08002553 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002554 ath_print(ath9k_hw_common(ah), ATH_DBG_BEACON,
2555 "%s: unsupported opmode: %d\n",
2556 __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08002557 return;
2558 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002559 }
2560
2561 REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
2562 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
2563 REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
2564 REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
2565
2566 beacon_period &= ~ATH9K_BEACON_ENA;
2567 if (beacon_period & ATH9K_BEACON_RESET_TSF) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002568 ath9k_hw_reset_tsf(ah);
2569 }
2570
2571 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
2572}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002573EXPORT_SYMBOL(ath9k_hw_beaconinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002574
Sujithcbe61d82009-02-09 13:27:12 +05302575void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05302576 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002577{
2578 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05302579 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002580 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002581
2582 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
2583
2584 REG_WRITE(ah, AR_BEACON_PERIOD,
2585 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
2586 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
2587 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
2588
2589 REG_RMW_FIELD(ah, AR_RSSI_THR,
2590 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
2591
2592 beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
2593
2594 if (bs->bs_sleepduration > beaconintval)
2595 beaconintval = bs->bs_sleepduration;
2596
2597 dtimperiod = bs->bs_dtimperiod;
2598 if (bs->bs_sleepduration > dtimperiod)
2599 dtimperiod = bs->bs_sleepduration;
2600
2601 if (beaconintval == dtimperiod)
2602 nextTbtt = bs->bs_nextdtim;
2603 else
2604 nextTbtt = bs->bs_nexttbtt;
2605
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002606 ath_print(common, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
2607 ath_print(common, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
2608 ath_print(common, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
2609 ath_print(common, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002610
2611 REG_WRITE(ah, AR_NEXT_DTIM,
2612 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
2613 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
2614
2615 REG_WRITE(ah, AR_SLEEP1,
2616 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
2617 | AR_SLEEP1_ASSUME_DTIM);
2618
Sujith60b67f52008-08-07 10:52:38 +05302619 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002620 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
2621 else
2622 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
2623
2624 REG_WRITE(ah, AR_SLEEP2,
2625 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
2626
2627 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
2628 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
2629
2630 REG_SET_BIT(ah, AR_TIMER_MODE,
2631 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
2632 AR_DTIM_TIMER_EN);
2633
Sujith4af9cf42009-02-12 10:06:47 +05302634 /* TSF Out of Range Threshold */
2635 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002636}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002637EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002638
Sujithf1dc5602008-10-29 10:16:30 +05302639/*******************/
2640/* HW Capabilities */
2641/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002642
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002643int ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002644{
Sujith2660b812009-02-09 13:27:26 +05302645 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002646 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002647 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002648 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002649
Sujithf1dc5602008-10-29 10:16:30 +05302650 u16 capField = 0, eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002651
Sujithf74df6f2009-02-09 13:27:24 +05302652 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002653 regulatory->current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05302654
Sujithf74df6f2009-02-09 13:27:24 +05302655 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
Sujithfec0de12009-02-12 10:06:43 +05302656 if (AR_SREV_9285_10_OR_LATER(ah))
2657 eeval |= AR9285_RDEXT_DEFAULT;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002658 regulatory->current_rd_ext = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05302659
Sujithf74df6f2009-02-09 13:27:24 +05302660 capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
Sujithf1dc5602008-10-29 10:16:30 +05302661
Sujith2660b812009-02-09 13:27:26 +05302662 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05302663 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002664 if (regulatory->current_rd == 0x64 ||
2665 regulatory->current_rd == 0x65)
2666 regulatory->current_rd += 5;
2667 else if (regulatory->current_rd == 0x41)
2668 regulatory->current_rd = 0x43;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002669 ath_print(common, ATH_DBG_REGULATORY,
2670 "regdomain mapped to 0x%x\n", regulatory->current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002671 }
Sujithdc2222a2008-08-14 13:26:55 +05302672
Sujithf74df6f2009-02-09 13:27:24 +05302673 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002674 if ((eeval & (AR5416_OPFLAGS_11G | AR5416_OPFLAGS_11A)) == 0) {
2675 ath_print(common, ATH_DBG_FATAL,
2676 "no band has been marked as supported in EEPROM.\n");
2677 return -EINVAL;
2678 }
2679
Sujithf1dc5602008-10-29 10:16:30 +05302680 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002681
Sujithf1dc5602008-10-29 10:16:30 +05302682 if (eeval & AR5416_OPFLAGS_11A) {
2683 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05302684 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05302685 if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
2686 set_bit(ATH9K_MODE_11NA_HT20,
2687 pCap->wireless_modes);
2688 if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
2689 set_bit(ATH9K_MODE_11NA_HT40PLUS,
2690 pCap->wireless_modes);
2691 set_bit(ATH9K_MODE_11NA_HT40MINUS,
2692 pCap->wireless_modes);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002693 }
2694 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002695 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002696
Sujithf1dc5602008-10-29 10:16:30 +05302697 if (eeval & AR5416_OPFLAGS_11G) {
Sujithf1dc5602008-10-29 10:16:30 +05302698 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05302699 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05302700 if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
2701 set_bit(ATH9K_MODE_11NG_HT20,
2702 pCap->wireless_modes);
2703 if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
2704 set_bit(ATH9K_MODE_11NG_HT40PLUS,
2705 pCap->wireless_modes);
2706 set_bit(ATH9K_MODE_11NG_HT40MINUS,
2707 pCap->wireless_modes);
2708 }
2709 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002710 }
Sujithf1dc5602008-10-29 10:16:30 +05302711
Sujithf74df6f2009-02-09 13:27:24 +05302712 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002713 /*
2714 * For AR9271 we will temporarilly uses the rx chainmax as read from
2715 * the EEPROM.
2716 */
Sujith8147f5d2009-02-20 15:13:23 +05302717 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002718 !(eeval & AR5416_OPFLAGS_11A) &&
2719 !(AR_SREV_9271(ah)))
2720 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
Sujith8147f5d2009-02-20 15:13:23 +05302721 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
2722 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002723 /* Use rx_chainmask from EEPROM. */
Sujith8147f5d2009-02-20 15:13:23 +05302724 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05302725
Sujithd535a422009-02-09 13:27:06 +05302726 if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0)))
Sujith2660b812009-02-09 13:27:26 +05302727 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05302728
2729 pCap->low_2ghz_chan = 2312;
2730 pCap->high_2ghz_chan = 2732;
2731
2732 pCap->low_5ghz_chan = 4920;
2733 pCap->high_5ghz_chan = 6100;
2734
2735 pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
2736 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
2737 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
2738
2739 pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
2740 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
2741 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
2742
Sujith2660b812009-02-09 13:27:26 +05302743 if (ah->config.ht_enable)
Sujithf1dc5602008-10-29 10:16:30 +05302744 pCap->hw_caps |= ATH9K_HW_CAP_HT;
2745 else
2746 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
2747
2748 pCap->hw_caps |= ATH9K_HW_CAP_GTT;
2749 pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
2750 pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
2751 pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
2752
2753 if (capField & AR_EEPROM_EEPCAP_MAXQCU)
2754 pCap->total_queues =
2755 MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
2756 else
2757 pCap->total_queues = ATH9K_NUM_TX_QUEUES;
2758
2759 if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
2760 pCap->keycache_size =
2761 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
2762 else
2763 pCap->keycache_size = AR_KEYTABLE_SIZE;
2764
2765 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -05002766
2767 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
2768 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD >> 1;
2769 else
2770 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
Sujithf1dc5602008-10-29 10:16:30 +05302771
Sujith5b5fa352010-03-17 14:25:15 +05302772 if (AR_SREV_9271(ah))
2773 pCap->num_gpio_pins = AR9271_NUM_GPIO;
2774 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302775 pCap->num_gpio_pins = AR9285_NUM_GPIO;
2776 else if (AR_SREV_9280_10_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302777 pCap->num_gpio_pins = AR928X_NUM_GPIO;
2778 else
2779 pCap->num_gpio_pins = AR_NUM_GPIO;
2780
Sujithf1dc5602008-10-29 10:16:30 +05302781 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
2782 pCap->hw_caps |= ATH9K_HW_CAP_CST;
2783 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
2784 } else {
2785 pCap->rts_aggr_limit = (8 * 1024);
2786 }
2787
2788 pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
2789
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05302790#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05302791 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
2792 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
2793 ah->rfkill_gpio =
2794 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
2795 ah->rfkill_polarity =
2796 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05302797
2798 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
2799 }
2800#endif
Vivek Natarajanbde748a2010-04-05 14:48:05 +05302801 if (AR_SREV_9271(ah))
2802 pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
2803 else
2804 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
Sujithf1dc5602008-10-29 10:16:30 +05302805
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302806 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302807 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
2808 else
2809 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
2810
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002811 if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) {
Sujithf1dc5602008-10-29 10:16:30 +05302812 pCap->reg_cap =
2813 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
2814 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
2815 AR_EEPROM_EEREGCAP_EN_KK_U2 |
2816 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
2817 } else {
2818 pCap->reg_cap =
2819 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
2820 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
2821 }
2822
Senthil Balasubramanianebb90cf2009-09-18 15:07:33 +05302823 /* Advertise midband for AR5416 with FCC midband set in eeprom */
2824 if (regulatory->current_rd_ext & (1 << REG_EXT_FCC_MIDBAND) &&
2825 AR_SREV_5416(ah))
2826 pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
Sujithf1dc5602008-10-29 10:16:30 +05302827
2828 pCap->num_antcfg_5ghz =
Sujithf74df6f2009-02-09 13:27:24 +05302829 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05302830 pCap->num_antcfg_2ghz =
Sujithf74df6f2009-02-09 13:27:24 +05302831 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05302832
Vasanthakumar Thiagarajanfe129462009-09-09 15:25:50 +05302833 if (AR_SREV_9280_10_OR_LATER(ah) &&
Luis R. Rodrigueza36cfbc2009-09-09 16:05:32 -07002834 ath9k_hw_btcoex_supported(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002835 btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO;
2836 btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO;
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05302837
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302838 if (AR_SREV_9285(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002839 btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
2840 btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302841 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002842 btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302843 }
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05302844 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002845 btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE;
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05302846 }
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002847
2848 return 0;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002849}
2850
Sujithcbe61d82009-02-09 13:27:12 +05302851bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05302852 u32 capability, u32 *result)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002853{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002854 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302855 switch (type) {
2856 case ATH9K_CAP_CIPHER:
2857 switch (capability) {
2858 case ATH9K_CIPHER_AES_CCM:
2859 case ATH9K_CIPHER_AES_OCB:
2860 case ATH9K_CIPHER_TKIP:
2861 case ATH9K_CIPHER_WEP:
2862 case ATH9K_CIPHER_MIC:
2863 case ATH9K_CIPHER_CLR:
2864 return true;
2865 default:
2866 return false;
2867 }
2868 case ATH9K_CAP_TKIP_MIC:
2869 switch (capability) {
2870 case 0:
2871 return true;
2872 case 1:
Sujith2660b812009-02-09 13:27:26 +05302873 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05302874 AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
2875 false;
2876 }
2877 case ATH9K_CAP_TKIP_SPLIT:
Sujith2660b812009-02-09 13:27:26 +05302878 return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ?
Sujithf1dc5602008-10-29 10:16:30 +05302879 false : true;
Sujithf1dc5602008-10-29 10:16:30 +05302880 case ATH9K_CAP_MCAST_KEYSRCH:
2881 switch (capability) {
2882 case 0:
2883 return true;
2884 case 1:
2885 if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
2886 return false;
2887 } else {
Sujith2660b812009-02-09 13:27:26 +05302888 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05302889 AR_STA_ID1_MCAST_KSRCH) ? true :
2890 false;
2891 }
2892 }
2893 return false;
Sujithf1dc5602008-10-29 10:16:30 +05302894 case ATH9K_CAP_TXPOW:
2895 switch (capability) {
2896 case 0:
2897 return 0;
2898 case 1:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002899 *result = regulatory->power_limit;
Sujithf1dc5602008-10-29 10:16:30 +05302900 return 0;
2901 case 2:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002902 *result = regulatory->max_power_level;
Sujithf1dc5602008-10-29 10:16:30 +05302903 return 0;
2904 case 3:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002905 *result = regulatory->tp_scale;
Sujithf1dc5602008-10-29 10:16:30 +05302906 return 0;
2907 }
2908 return false;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05302909 case ATH9K_CAP_DS:
2910 return (AR_SREV_9280_20_OR_LATER(ah) &&
2911 (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1))
2912 ? false : true;
Sujithf1dc5602008-10-29 10:16:30 +05302913 default:
2914 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002915 }
Sujithf1dc5602008-10-29 10:16:30 +05302916}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002917EXPORT_SYMBOL(ath9k_hw_getcapability);
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002918
Sujithcbe61d82009-02-09 13:27:12 +05302919bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05302920 u32 capability, u32 setting, int *status)
2921{
Sujithf1dc5602008-10-29 10:16:30 +05302922 switch (type) {
2923 case ATH9K_CAP_TKIP_MIC:
2924 if (setting)
Sujith2660b812009-02-09 13:27:26 +05302925 ah->sta_id1_defaults |=
Sujithf1dc5602008-10-29 10:16:30 +05302926 AR_STA_ID1_CRPT_MIC_ENABLE;
2927 else
Sujith2660b812009-02-09 13:27:26 +05302928 ah->sta_id1_defaults &=
Sujithf1dc5602008-10-29 10:16:30 +05302929 ~AR_STA_ID1_CRPT_MIC_ENABLE;
2930 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302931 case ATH9K_CAP_MCAST_KEYSRCH:
2932 if (setting)
Sujith2660b812009-02-09 13:27:26 +05302933 ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05302934 else
Sujith2660b812009-02-09 13:27:26 +05302935 ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05302936 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302937 default:
2938 return false;
2939 }
2940}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002941EXPORT_SYMBOL(ath9k_hw_setcapability);
Sujithf1dc5602008-10-29 10:16:30 +05302942
2943/****************************/
2944/* GPIO / RFKILL / Antennae */
2945/****************************/
2946
Sujithcbe61d82009-02-09 13:27:12 +05302947static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05302948 u32 gpio, u32 type)
2949{
2950 int addr;
2951 u32 gpio_shift, tmp;
2952
2953 if (gpio > 11)
2954 addr = AR_GPIO_OUTPUT_MUX3;
2955 else if (gpio > 5)
2956 addr = AR_GPIO_OUTPUT_MUX2;
2957 else
2958 addr = AR_GPIO_OUTPUT_MUX1;
2959
2960 gpio_shift = (gpio % 6) * 5;
2961
2962 if (AR_SREV_9280_20_OR_LATER(ah)
2963 || (addr != AR_GPIO_OUTPUT_MUX1)) {
2964 REG_RMW(ah, addr, (type << gpio_shift),
2965 (0x1f << gpio_shift));
2966 } else {
2967 tmp = REG_READ(ah, addr);
2968 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
2969 tmp &= ~(0x1f << gpio_shift);
2970 tmp |= (type << gpio_shift);
2971 REG_WRITE(ah, addr, tmp);
2972 }
2973}
2974
Sujithcbe61d82009-02-09 13:27:12 +05302975void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05302976{
2977 u32 gpio_shift;
2978
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07002979 BUG_ON(gpio >= ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05302980
2981 gpio_shift = gpio << 1;
2982
2983 REG_RMW(ah,
2984 AR_GPIO_OE_OUT,
2985 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
2986 (AR_GPIO_OE_OUT_DRV << gpio_shift));
2987}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002988EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
Sujithf1dc5602008-10-29 10:16:30 +05302989
Sujithcbe61d82009-02-09 13:27:12 +05302990u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05302991{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302992#define MS_REG_READ(x, y) \
2993 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
2994
Sujith2660b812009-02-09 13:27:26 +05302995 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05302996 return 0xffffffff;
2997
Felix Fietkau783dfca2010-04-15 17:38:11 -04002998 if (AR_SREV_9300_20_OR_LATER(ah))
2999 return MS_REG_READ(AR9300, gpio) != 0;
3000 else if (AR_SREV_9271(ah))
Sujith5b5fa352010-03-17 14:25:15 +05303001 return MS_REG_READ(AR9271, gpio) != 0;
3002 else if (AR_SREV_9287_10_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05303003 return MS_REG_READ(AR9287, gpio) != 0;
3004 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303005 return MS_REG_READ(AR9285, gpio) != 0;
3006 else if (AR_SREV_9280_10_OR_LATER(ah))
3007 return MS_REG_READ(AR928X, gpio) != 0;
3008 else
3009 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05303010}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003011EXPORT_SYMBOL(ath9k_hw_gpio_get);
Sujithf1dc5602008-10-29 10:16:30 +05303012
Sujithcbe61d82009-02-09 13:27:12 +05303013void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05303014 u32 ah_signal_type)
3015{
3016 u32 gpio_shift;
3017
3018 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
3019
3020 gpio_shift = 2 * gpio;
3021
3022 REG_RMW(ah,
3023 AR_GPIO_OE_OUT,
3024 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
3025 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3026}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003027EXPORT_SYMBOL(ath9k_hw_cfg_output);
Sujithf1dc5602008-10-29 10:16:30 +05303028
Sujithcbe61d82009-02-09 13:27:12 +05303029void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05303030{
Sujith5b5fa352010-03-17 14:25:15 +05303031 if (AR_SREV_9271(ah))
3032 val = ~val;
3033
Sujithf1dc5602008-10-29 10:16:30 +05303034 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
3035 AR_GPIO_BIT(gpio));
3036}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003037EXPORT_SYMBOL(ath9k_hw_set_gpio);
Sujithf1dc5602008-10-29 10:16:30 +05303038
Sujithcbe61d82009-02-09 13:27:12 +05303039u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303040{
3041 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
3042}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003043EXPORT_SYMBOL(ath9k_hw_getdefantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303044
Sujithcbe61d82009-02-09 13:27:12 +05303045void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05303046{
3047 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
3048}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003049EXPORT_SYMBOL(ath9k_hw_setantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303050
Sujithf1dc5602008-10-29 10:16:30 +05303051/*********************/
3052/* General Operation */
3053/*********************/
3054
Sujithcbe61d82009-02-09 13:27:12 +05303055u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303056{
3057 u32 bits = REG_READ(ah, AR_RX_FILTER);
3058 u32 phybits = REG_READ(ah, AR_PHY_ERR);
3059
3060 if (phybits & AR_PHY_ERR_RADAR)
3061 bits |= ATH9K_RX_FILTER_PHYRADAR;
3062 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
3063 bits |= ATH9K_RX_FILTER_PHYERR;
3064
3065 return bits;
3066}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003067EXPORT_SYMBOL(ath9k_hw_getrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303068
Sujithcbe61d82009-02-09 13:27:12 +05303069void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05303070{
3071 u32 phybits;
3072
Sujith7ea310b2009-09-03 12:08:43 +05303073 REG_WRITE(ah, AR_RX_FILTER, bits);
3074
Sujithf1dc5602008-10-29 10:16:30 +05303075 phybits = 0;
3076 if (bits & ATH9K_RX_FILTER_PHYRADAR)
3077 phybits |= AR_PHY_ERR_RADAR;
3078 if (bits & ATH9K_RX_FILTER_PHYERR)
3079 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
3080 REG_WRITE(ah, AR_PHY_ERR, phybits);
3081
3082 if (phybits)
3083 REG_WRITE(ah, AR_RXCFG,
3084 REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
3085 else
3086 REG_WRITE(ah, AR_RXCFG,
3087 REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
3088}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003089EXPORT_SYMBOL(ath9k_hw_setrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303090
Sujithcbe61d82009-02-09 13:27:12 +05303091bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303092{
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05303093 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
3094 return false;
3095
3096 ath9k_hw_init_pll(ah, NULL);
3097 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303098}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003099EXPORT_SYMBOL(ath9k_hw_phy_disable);
Sujithf1dc5602008-10-29 10:16:30 +05303100
Sujithcbe61d82009-02-09 13:27:12 +05303101bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303102{
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07003103 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05303104 return false;
3105
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05303106 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
3107 return false;
3108
3109 ath9k_hw_init_pll(ah, NULL);
3110 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303111}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003112EXPORT_SYMBOL(ath9k_hw_disable);
Sujithf1dc5602008-10-29 10:16:30 +05303113
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003114void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
Sujithf1dc5602008-10-29 10:16:30 +05303115{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003116 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujith2660b812009-02-09 13:27:26 +05303117 struct ath9k_channel *chan = ah->curchan;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08003118 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05303119
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003120 regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER);
Sujithf1dc5602008-10-29 10:16:30 +05303121
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003122 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003123 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003124 channel->max_antenna_gain * 2,
3125 channel->max_power * 2,
3126 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003127 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05303128}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003129EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
Sujithf1dc5602008-10-29 10:16:30 +05303130
Sujithcbe61d82009-02-09 13:27:12 +05303131void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac)
Sujithf1dc5602008-10-29 10:16:30 +05303132{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07003133 memcpy(ath9k_hw_common(ah)->macaddr, mac, ETH_ALEN);
Sujithf1dc5602008-10-29 10:16:30 +05303134}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003135EXPORT_SYMBOL(ath9k_hw_setmac);
Sujithf1dc5602008-10-29 10:16:30 +05303136
Sujithcbe61d82009-02-09 13:27:12 +05303137void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303138{
Sujith2660b812009-02-09 13:27:26 +05303139 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05303140}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003141EXPORT_SYMBOL(ath9k_hw_setopmode);
Sujithf1dc5602008-10-29 10:16:30 +05303142
Sujithcbe61d82009-02-09 13:27:12 +05303143void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05303144{
3145 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
3146 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
3147}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003148EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303149
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07003150void ath9k_hw_write_associd(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303151{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07003152 struct ath_common *common = ath9k_hw_common(ah);
3153
3154 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
3155 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
3156 ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05303157}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003158EXPORT_SYMBOL(ath9k_hw_write_associd);
Sujithf1dc5602008-10-29 10:16:30 +05303159
Sujithcbe61d82009-02-09 13:27:12 +05303160u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303161{
3162 u64 tsf;
3163
3164 tsf = REG_READ(ah, AR_TSF_U32);
3165 tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
3166
3167 return tsf;
3168}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003169EXPORT_SYMBOL(ath9k_hw_gettsf64);
Sujithf1dc5602008-10-29 10:16:30 +05303170
Sujithcbe61d82009-02-09 13:27:12 +05303171void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003172{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003173 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01003174 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003175}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003176EXPORT_SYMBOL(ath9k_hw_settsf64);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003177
Sujithcbe61d82009-02-09 13:27:12 +05303178void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303179{
Gabor Juhosf9b604f2009-06-21 00:02:15 +02003180 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
3181 AH_TSF_WRITE_TIMEOUT))
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003182 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
3183 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
Gabor Juhosf9b604f2009-06-21 00:02:15 +02003184
Sujithf1dc5602008-10-29 10:16:30 +05303185 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003186}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003187EXPORT_SYMBOL(ath9k_hw_reset_tsf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003188
Sujith54e4cec2009-08-07 09:45:09 +05303189void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003190{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003191 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303192 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003193 else
Sujith2660b812009-02-09 13:27:26 +05303194 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003195}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003196EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003197
Luis R. Rodriguez30cbd422009-11-03 16:10:46 -08003198/*
3199 * Extend 15-bit time stamp from rx descriptor to
3200 * a full 64-bit TSF using the current h/w TSF.
3201*/
3202u64 ath9k_hw_extend_tsf(struct ath_hw *ah, u32 rstamp)
3203{
3204 u64 tsf;
3205
3206 tsf = ath9k_hw_gettsf64(ah);
3207 if ((tsf & 0x7fff) < rstamp)
3208 tsf -= 0x8000;
3209 return (tsf & ~0x7fff) | rstamp;
3210}
3211EXPORT_SYMBOL(ath9k_hw_extend_tsf);
3212
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003213void ath9k_hw_set11nmac2040(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003214{
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003215 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithf1dc5602008-10-29 10:16:30 +05303216 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003217
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003218 if (conf_is_ht40(conf) && !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05303219 macmode = AR_2040_JOINED_RX_CLEAR;
3220 else
3221 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003222
Sujithf1dc5602008-10-29 10:16:30 +05303223 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003224}
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303225
3226/* HW Generic timers configuration */
3227
3228static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
3229{
3230 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3231 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3232 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3233 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3234 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3235 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3236 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3237 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3238 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
3239 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
3240 AR_NDP2_TIMER_MODE, 0x0002},
3241 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
3242 AR_NDP2_TIMER_MODE, 0x0004},
3243 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
3244 AR_NDP2_TIMER_MODE, 0x0008},
3245 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
3246 AR_NDP2_TIMER_MODE, 0x0010},
3247 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
3248 AR_NDP2_TIMER_MODE, 0x0020},
3249 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
3250 AR_NDP2_TIMER_MODE, 0x0040},
3251 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
3252 AR_NDP2_TIMER_MODE, 0x0080}
3253};
3254
3255/* HW generic timer primitives */
3256
3257/* compute and clear index of rightmost 1 */
3258static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
3259{
3260 u32 b;
3261
3262 b = *mask;
3263 b &= (0-b);
3264 *mask &= ~b;
3265 b *= debruijn32;
3266 b >>= 27;
3267
3268 return timer_table->gen_timer_index[b];
3269}
3270
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05303271u32 ath9k_hw_gettsf32(struct ath_hw *ah)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303272{
3273 return REG_READ(ah, AR_TSF_L32);
3274}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003275EXPORT_SYMBOL(ath9k_hw_gettsf32);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303276
3277struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
3278 void (*trigger)(void *),
3279 void (*overflow)(void *),
3280 void *arg,
3281 u8 timer_index)
3282{
3283 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3284 struct ath_gen_timer *timer;
3285
3286 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
3287
3288 if (timer == NULL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003289 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
3290 "Failed to allocate memory"
3291 "for hw timer[%d]\n", timer_index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303292 return NULL;
3293 }
3294
3295 /* allocate a hardware generic timer slot */
3296 timer_table->timers[timer_index] = timer;
3297 timer->index = timer_index;
3298 timer->trigger = trigger;
3299 timer->overflow = overflow;
3300 timer->arg = arg;
3301
3302 return timer;
3303}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003304EXPORT_SYMBOL(ath_gen_timer_alloc);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303305
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07003306void ath9k_hw_gen_timer_start(struct ath_hw *ah,
3307 struct ath_gen_timer *timer,
3308 u32 timer_next,
3309 u32 timer_period)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303310{
3311 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3312 u32 tsf;
3313
3314 BUG_ON(!timer_period);
3315
3316 set_bit(timer->index, &timer_table->timer_mask.timer_bits);
3317
3318 tsf = ath9k_hw_gettsf32(ah);
3319
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003320 ath_print(ath9k_hw_common(ah), ATH_DBG_HWTIMER,
3321 "curent tsf %x period %x"
3322 "timer_next %x\n", tsf, timer_period, timer_next);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303323
3324 /*
3325 * Pull timer_next forward if the current TSF already passed it
3326 * because of software latency
3327 */
3328 if (timer_next < tsf)
3329 timer_next = tsf + timer_period;
3330
3331 /*
3332 * Program generic timer registers
3333 */
3334 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
3335 timer_next);
3336 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
3337 timer_period);
3338 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
3339 gen_tmr_configuration[timer->index].mode_mask);
3340
3341 /* Enable both trigger and thresh interrupt masks */
3342 REG_SET_BIT(ah, AR_IMR_S5,
3343 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
3344 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303345}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003346EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303347
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07003348void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303349{
3350 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3351
3352 if ((timer->index < AR_FIRST_NDP_TIMER) ||
3353 (timer->index >= ATH_MAX_GEN_TIMER)) {
3354 return;
3355 }
3356
3357 /* Clear generic timer enable bits. */
3358 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
3359 gen_tmr_configuration[timer->index].mode_mask);
3360
3361 /* Disable both trigger and thresh interrupt masks */
3362 REG_CLR_BIT(ah, AR_IMR_S5,
3363 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
3364 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
3365
3366 clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303367}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003368EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303369
3370void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
3371{
3372 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3373
3374 /* free the hardware generic timer slot */
3375 timer_table->timers[timer->index] = NULL;
3376 kfree(timer);
3377}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003378EXPORT_SYMBOL(ath_gen_timer_free);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303379
3380/*
3381 * Generic Timer Interrupts handling
3382 */
3383void ath_gen_timer_isr(struct ath_hw *ah)
3384{
3385 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3386 struct ath_gen_timer *timer;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003387 struct ath_common *common = ath9k_hw_common(ah);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303388 u32 trigger_mask, thresh_mask, index;
3389
3390 /* get hardware generic timer interrupt status */
3391 trigger_mask = ah->intr_gen_timer_trigger;
3392 thresh_mask = ah->intr_gen_timer_thresh;
3393 trigger_mask &= timer_table->timer_mask.val;
3394 thresh_mask &= timer_table->timer_mask.val;
3395
3396 trigger_mask &= ~thresh_mask;
3397
3398 while (thresh_mask) {
3399 index = rightmost_index(timer_table, &thresh_mask);
3400 timer = timer_table->timers[index];
3401 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003402 ath_print(common, ATH_DBG_HWTIMER,
3403 "TSF overflow for Gen timer %d\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303404 timer->overflow(timer->arg);
3405 }
3406
3407 while (trigger_mask) {
3408 index = rightmost_index(timer_table, &trigger_mask);
3409 timer = timer_table->timers[index];
3410 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003411 ath_print(common, ATH_DBG_HWTIMER,
3412 "Gen timer[%d] trigger\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303413 timer->trigger(timer->arg);
3414 }
3415}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003416EXPORT_SYMBOL(ath_gen_timer_isr);
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003417
Sujith05020d22010-03-17 14:25:23 +05303418/********/
3419/* HTC */
3420/********/
3421
3422void ath9k_hw_htc_resetinit(struct ath_hw *ah)
3423{
3424 ah->htc_reset_init = true;
3425}
3426EXPORT_SYMBOL(ath9k_hw_htc_resetinit);
3427
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003428static struct {
3429 u32 version;
3430 const char * name;
3431} ath_mac_bb_names[] = {
3432 /* Devices with external radios */
3433 { AR_SREV_VERSION_5416_PCI, "5416" },
3434 { AR_SREV_VERSION_5416_PCIE, "5418" },
3435 { AR_SREV_VERSION_9100, "9100" },
3436 { AR_SREV_VERSION_9160, "9160" },
3437 /* Single-chip solutions */
3438 { AR_SREV_VERSION_9280, "9280" },
3439 { AR_SREV_VERSION_9285, "9285" },
Luis R. Rodriguez11158472009-10-27 12:59:35 -04003440 { AR_SREV_VERSION_9287, "9287" },
3441 { AR_SREV_VERSION_9271, "9271" },
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003442};
3443
3444/* For devices with external radios */
3445static struct {
3446 u16 version;
3447 const char * name;
3448} ath_rf_names[] = {
3449 { 0, "5133" },
3450 { AR_RAD5133_SREV_MAJOR, "5133" },
3451 { AR_RAD5122_SREV_MAJOR, "5122" },
3452 { AR_RAD2133_SREV_MAJOR, "2133" },
3453 { AR_RAD2122_SREV_MAJOR, "2122" }
3454};
3455
3456/*
3457 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
3458 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003459static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003460{
3461 int i;
3462
3463 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
3464 if (ath_mac_bb_names[i].version == mac_bb_version) {
3465 return ath_mac_bb_names[i].name;
3466 }
3467 }
3468
3469 return "????";
3470}
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003471
3472/*
3473 * Return the RF name. "????" is returned if the RF is unknown.
3474 * Used for devices with external radios.
3475 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003476static const char *ath9k_hw_rf_name(u16 rf_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003477{
3478 int i;
3479
3480 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
3481 if (ath_rf_names[i].version == rf_version) {
3482 return ath_rf_names[i].name;
3483 }
3484 }
3485
3486 return "????";
3487}
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003488
3489void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
3490{
3491 int used;
3492
3493 /* chipsets >= AR9280 are single-chip */
3494 if (AR_SREV_9280_10_OR_LATER(ah)) {
3495 used = snprintf(hw_name, len,
3496 "Atheros AR%s Rev:%x",
3497 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3498 ah->hw_version.macRev);
3499 }
3500 else {
3501 used = snprintf(hw_name, len,
3502 "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
3503 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3504 ah->hw_version.macRev,
3505 ath9k_hw_rf_name((ah->hw_version.analog5GhzRev &
3506 AR_RADIO_SREV_MAJOR)),
3507 ah->hw_version.phyRev);
3508 }
3509
3510 hw_name[used] = '\0';
3511}
3512EXPORT_SYMBOL(ath9k_hw_name);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04003513
3514/* Sets up the AR5008/AR9001/AR9002 hardware familiy callbacks */
3515static void ar9002_hw_attach_ops(struct ath_hw *ah)
3516{
3517 struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
3518 struct ath_hw_ops *ops = ath9k_hw_ops(ah);
3519
3520 priv_ops->init_cal_settings = ar9002_hw_init_cal_settings;
3521 priv_ops->init_mode_regs = ar9002_hw_init_mode_regs;
3522 priv_ops->macversion_supported = ar9002_hw_macversion_supported;
3523
3524 ops->config_pci_powersave = ar9002_hw_configpcipowersave;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04003525
3526 if (AR_SREV_9280_10_OR_LATER(ah))
3527 ar9002_hw_attach_phy_ops(ah);
3528 else
3529 ar5008_hw_attach_phy_ops(ah);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -04003530}