blob: ffcc4f039fa2b2badeaac03978183864d447bdb3 [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. Rodriguezcfe8cba2009-09-13 23:39:31 -070021#include "rc.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070022#include "initvals.h"
23
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080024#define ATH9K_CLOCK_RATE_CCK 22
25#define ATH9K_CLOCK_RATE_5GHZ_OFDM 40
26#define ATH9K_CLOCK_RATE_2GHZ_OFDM 44
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070027
Sujithcbe61d82009-02-09 13:27:12 +053028static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type);
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -070029static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan);
Sujithcbe61d82009-02-09 13:27:12 +053030static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +053031 struct ar5416_eeprom_def *pEepData,
Sujithf1dc5602008-10-29 10:16:30 +053032 u32 reg, u32 value);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070033
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040034MODULE_AUTHOR("Atheros Communications");
35MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
36MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
37MODULE_LICENSE("Dual BSD/GPL");
38
39static int __init ath9k_init(void)
40{
41 return 0;
42}
43module_init(ath9k_init);
44
45static void __exit ath9k_exit(void)
46{
47 return;
48}
49module_exit(ath9k_exit);
50
Sujithf1dc5602008-10-29 10:16:30 +053051/********************/
52/* Helper Functions */
53/********************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070054
Sujithcbe61d82009-02-09 13:27:12 +053055static u32 ath9k_hw_mac_usec(struct ath_hw *ah, u32 clks)
Sujithf1dc5602008-10-29 10:16:30 +053056{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070057 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053058
Sujith2660b812009-02-09 13:27:26 +053059 if (!ah->curchan) /* should really check for CCK instead */
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080060 return clks / ATH9K_CLOCK_RATE_CCK;
61 if (conf->channel->band == IEEE80211_BAND_2GHZ)
62 return clks / ATH9K_CLOCK_RATE_2GHZ_OFDM;
Sujithcbe61d82009-02-09 13:27:12 +053063
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080064 return clks / ATH9K_CLOCK_RATE_5GHZ_OFDM;
Sujithf1dc5602008-10-29 10:16:30 +053065}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070066
Sujithcbe61d82009-02-09 13:27:12 +053067static u32 ath9k_hw_mac_to_usec(struct ath_hw *ah, u32 clks)
Sujithf1dc5602008-10-29 10:16:30 +053068{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070069 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053070
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080071 if (conf_is_ht40(conf))
Sujithf1dc5602008-10-29 10:16:30 +053072 return ath9k_hw_mac_usec(ah, clks) / 2;
73 else
74 return ath9k_hw_mac_usec(ah, clks);
75}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070076
Sujithcbe61d82009-02-09 13:27:12 +053077static u32 ath9k_hw_mac_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053078{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070079 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053080
Sujith2660b812009-02-09 13:27:26 +053081 if (!ah->curchan) /* should really check for CCK instead */
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080082 return usecs *ATH9K_CLOCK_RATE_CCK;
83 if (conf->channel->band == IEEE80211_BAND_2GHZ)
84 return usecs *ATH9K_CLOCK_RATE_2GHZ_OFDM;
85 return usecs *ATH9K_CLOCK_RATE_5GHZ_OFDM;
Sujithf1dc5602008-10-29 10:16:30 +053086}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070087
Sujithcbe61d82009-02-09 13:27:12 +053088static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053089{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070090 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053091
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080092 if (conf_is_ht40(conf))
Sujithf1dc5602008-10-29 10:16:30 +053093 return ath9k_hw_mac_clks(ah, usecs) * 2;
94 else
95 return ath9k_hw_mac_clks(ah, usecs);
96}
97
Sujith0caa7b12009-02-16 13:23:20 +053098bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070099{
100 int i;
101
Sujith0caa7b12009-02-16 13:23:20 +0530102 BUG_ON(timeout < AH_TIME_QUANTUM);
103
104 for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700105 if ((REG_READ(ah, reg) & mask) == val)
106 return true;
107
108 udelay(AH_TIME_QUANTUM);
109 }
Sujith04bd4632008-11-28 22:18:05 +0530110
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700111 ath_print(ath9k_hw_common(ah), ATH_DBG_ANY,
112 "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
113 timeout, reg, REG_READ(ah, reg), mask, val);
Sujithf1dc5602008-10-29 10:16:30 +0530114
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700115 return false;
116}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400117EXPORT_SYMBOL(ath9k_hw_wait);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700118
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700119u32 ath9k_hw_reverse_bits(u32 val, u32 n)
120{
121 u32 retval;
122 int i;
123
124 for (i = 0, retval = 0; i < n; i++) {
125 retval = (retval << 1) | (val & 1);
126 val >>= 1;
127 }
128 return retval;
129}
130
Sujithcbe61d82009-02-09 13:27:12 +0530131bool ath9k_get_channel_edges(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530132 u16 flags, u16 *low,
133 u16 *high)
134{
Sujith2660b812009-02-09 13:27:26 +0530135 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530136
137 if (flags & CHANNEL_5GHZ) {
138 *low = pCap->low_5ghz_chan;
139 *high = pCap->high_5ghz_chan;
140 return true;
141 }
142 if ((flags & CHANNEL_2GHZ)) {
143 *low = pCap->low_2ghz_chan;
144 *high = pCap->high_2ghz_chan;
145 return true;
146 }
147 return false;
148}
149
Sujithcbe61d82009-02-09 13:27:12 +0530150u16 ath9k_hw_computetxtime(struct ath_hw *ah,
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400151 const struct ath_rate_table *rates,
Sujithf1dc5602008-10-29 10:16:30 +0530152 u32 frameLen, u16 rateix,
153 bool shortPreamble)
154{
155 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
156 u32 kbps;
157
Sujithe63835b2008-11-18 09:07:53 +0530158 kbps = rates->info[rateix].ratekbps;
Sujithf1dc5602008-10-29 10:16:30 +0530159
160 if (kbps == 0)
161 return 0;
162
163 switch (rates->info[rateix].phy) {
Sujith46d14a52008-11-18 09:08:13 +0530164 case WLAN_RC_PHY_CCK:
Sujithf1dc5602008-10-29 10:16:30 +0530165 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
Sujithe63835b2008-11-18 09:07:53 +0530166 if (shortPreamble && rates->info[rateix].short_preamble)
Sujithf1dc5602008-10-29 10:16:30 +0530167 phyTime >>= 1;
168 numBits = frameLen << 3;
169 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
170 break;
Sujith46d14a52008-11-18 09:08:13 +0530171 case WLAN_RC_PHY_OFDM:
Sujith2660b812009-02-09 13:27:26 +0530172 if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530173 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
174 numBits = OFDM_PLCP_BITS + (frameLen << 3);
175 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
176 txTime = OFDM_SIFS_TIME_QUARTER
177 + OFDM_PREAMBLE_TIME_QUARTER
178 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
Sujith2660b812009-02-09 13:27:26 +0530179 } else if (ah->curchan &&
180 IS_CHAN_HALF_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530181 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
182 numBits = OFDM_PLCP_BITS + (frameLen << 3);
183 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
184 txTime = OFDM_SIFS_TIME_HALF +
185 OFDM_PREAMBLE_TIME_HALF
186 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
187 } else {
188 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
189 numBits = OFDM_PLCP_BITS + (frameLen << 3);
190 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
191 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
192 + (numSymbols * OFDM_SYMBOL_TIME);
193 }
194 break;
195 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700196 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
197 "Unknown phy %u (rate ix %u)\n",
198 rates->info[rateix].phy, rateix);
Sujithf1dc5602008-10-29 10:16:30 +0530199 txTime = 0;
200 break;
201 }
202
203 return txTime;
204}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400205EXPORT_SYMBOL(ath9k_hw_computetxtime);
Sujithf1dc5602008-10-29 10:16:30 +0530206
Sujithcbe61d82009-02-09 13:27:12 +0530207void ath9k_hw_get_channel_centers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530208 struct ath9k_channel *chan,
209 struct chan_centers *centers)
210{
211 int8_t extoff;
Sujithf1dc5602008-10-29 10:16:30 +0530212
213 if (!IS_CHAN_HT40(chan)) {
214 centers->ctl_center = centers->ext_center =
215 centers->synth_center = chan->channel;
216 return;
217 }
218
219 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
220 (chan->chanmode == CHANNEL_G_HT40PLUS)) {
221 centers->synth_center =
222 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
223 extoff = 1;
224 } else {
225 centers->synth_center =
226 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
227 extoff = -1;
228 }
229
230 centers->ctl_center =
231 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700232 /* 25 MHz spacing is supported by hw but not on upper layers */
Sujithf1dc5602008-10-29 10:16:30 +0530233 centers->ext_center =
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700234 centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT);
Sujithf1dc5602008-10-29 10:16:30 +0530235}
236
237/******************/
238/* Chip Revisions */
239/******************/
240
Sujithcbe61d82009-02-09 13:27:12 +0530241static void ath9k_hw_read_revisions(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530242{
243 u32 val;
244
245 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
246
247 if (val == 0xFF) {
248 val = REG_READ(ah, AR_SREV);
Sujithd535a422009-02-09 13:27:06 +0530249 ah->hw_version.macVersion =
250 (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
251 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
Sujith2660b812009-02-09 13:27:26 +0530252 ah->is_pciexpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
Sujithf1dc5602008-10-29 10:16:30 +0530253 } else {
254 if (!AR_SREV_9100(ah))
Sujithd535a422009-02-09 13:27:06 +0530255 ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
Sujithf1dc5602008-10-29 10:16:30 +0530256
Sujithd535a422009-02-09 13:27:06 +0530257 ah->hw_version.macRev = val & AR_SREV_REVISION;
Sujithf1dc5602008-10-29 10:16:30 +0530258
Sujithd535a422009-02-09 13:27:06 +0530259 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
Sujith2660b812009-02-09 13:27:26 +0530260 ah->is_pciexpress = true;
Sujithf1dc5602008-10-29 10:16:30 +0530261 }
262}
263
Sujithcbe61d82009-02-09 13:27:12 +0530264static int ath9k_hw_get_radiorev(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530265{
266 u32 val;
267 int i;
268
269 REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
270
271 for (i = 0; i < 8; i++)
272 REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
273 val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
274 val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
275
276 return ath9k_hw_reverse_bits(val, 8);
277}
278
279/************************************/
280/* HW Attach, Detach, Init Routines */
281/************************************/
282
Sujithcbe61d82009-02-09 13:27:12 +0530283static void ath9k_hw_disablepcie(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530284{
Sujithfeed0292009-01-29 11:37:35 +0530285 if (AR_SREV_9100(ah))
Sujithf1dc5602008-10-29 10:16:30 +0530286 return;
287
288 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
289 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
290 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
291 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
292 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
293 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
294 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
295 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
296 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
297
298 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
299}
300
Sujithcbe61d82009-02-09 13:27:12 +0530301static bool ath9k_hw_chip_test(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530302{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700303 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530304 u32 regAddr[2] = { AR_STA_ID0, AR_PHY_BASE + (8 << 2) };
305 u32 regHold[2];
306 u32 patternData[4] = { 0x55555555,
307 0xaaaaaaaa,
308 0x66666666,
309 0x99999999 };
310 int i, j;
311
312 for (i = 0; i < 2; i++) {
313 u32 addr = regAddr[i];
314 u32 wrData, rdData;
315
316 regHold[i] = REG_READ(ah, addr);
317 for (j = 0; j < 0x100; j++) {
318 wrData = (j << 16) | j;
319 REG_WRITE(ah, addr, wrData);
320 rdData = REG_READ(ah, addr);
321 if (rdData != wrData) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700322 ath_print(common, ATH_DBG_FATAL,
323 "address test failed "
324 "addr: 0x%08x - wr:0x%08x != "
325 "rd:0x%08x\n",
326 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530327 return false;
328 }
329 }
330 for (j = 0; j < 4; j++) {
331 wrData = patternData[j];
332 REG_WRITE(ah, addr, wrData);
333 rdData = REG_READ(ah, addr);
334 if (wrData != rdData) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700335 ath_print(common, ATH_DBG_FATAL,
336 "address test failed "
337 "addr: 0x%08x - wr:0x%08x != "
338 "rd:0x%08x\n",
339 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530340 return false;
341 }
342 }
343 REG_WRITE(ah, regAddr[i], regHold[i]);
344 }
345 udelay(100);
Sujithcbe61d82009-02-09 13:27:12 +0530346
Sujithf1dc5602008-10-29 10:16:30 +0530347 return true;
348}
349
350static const char *ath9k_hw_devname(u16 devid)
351{
352 switch (devid) {
353 case AR5416_DEVID_PCI:
Sujithf1dc5602008-10-29 10:16:30 +0530354 return "Atheros 5416";
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +0100355 case AR5416_DEVID_PCIE:
356 return "Atheros 5418";
Sujithf1dc5602008-10-29 10:16:30 +0530357 case AR9160_DEVID_PCI:
358 return "Atheros 9160";
Gabor Juhos0c1aa492009-01-14 20:17:12 +0100359 case AR5416_AR9100_DEVID:
360 return "Atheros 9100";
Sujithf1dc5602008-10-29 10:16:30 +0530361 case AR9280_DEVID_PCI:
362 case AR9280_DEVID_PCIE:
363 return "Atheros 9280";
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530364 case AR9285_DEVID_PCIE:
365 return "Atheros 9285";
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530366 case AR5416_DEVID_AR9287_PCI:
367 case AR5416_DEVID_AR9287_PCIE:
368 return "Atheros 9287";
Sujithf1dc5602008-10-29 10:16:30 +0530369 }
370
371 return NULL;
372}
373
Luis R. Rodriguezb8b0f372009-08-03 12:24:43 -0700374static void ath9k_hw_init_config(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700375{
376 int i;
377
Sujith2660b812009-02-09 13:27:26 +0530378 ah->config.dma_beacon_response_time = 2;
379 ah->config.sw_beacon_response_time = 10;
380 ah->config.additional_swba_backoff = 0;
381 ah->config.ack_6mb = 0x0;
382 ah->config.cwm_ignore_extcca = 0;
383 ah->config.pcie_powersave_enable = 0;
Sujith2660b812009-02-09 13:27:26 +0530384 ah->config.pcie_clock_req = 0;
Sujith2660b812009-02-09 13:27:26 +0530385 ah->config.pcie_waen = 0;
386 ah->config.analog_shiftreg = 1;
387 ah->config.ht_enable = 1;
388 ah->config.ofdm_trig_low = 200;
389 ah->config.ofdm_trig_high = 500;
390 ah->config.cck_trig_high = 200;
391 ah->config.cck_trig_low = 100;
392 ah->config.enable_ani = 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700393
394 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujith2660b812009-02-09 13:27:26 +0530395 ah->config.spurchans[i][0] = AR_NO_SPUR;
396 ah->config.spurchans[i][1] = AR_NO_SPUR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700397 }
398
Sujith0ef1f162009-03-30 15:28:35 +0530399 ah->config.intr_mitigation = true;
Luis R. Rodriguez61584252009-03-12 18:18:49 -0400400
401 /*
402 * We need this for PCI devices only (Cardbus, PCI, miniPCI)
403 * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
404 * This means we use it for all AR5416 devices, and the few
405 * minor PCI AR9280 devices out there.
406 *
407 * Serialization is required because these devices do not handle
408 * well the case of two concurrent reads/writes due to the latency
409 * involved. During one read/write another read/write can be issued
410 * on another CPU while the previous read/write may still be working
411 * on our hardware, if we hit this case the hardware poops in a loop.
412 * We prevent this by serializing reads and writes.
413 *
414 * This issue is not present on PCI-Express devices or pre-AR5416
415 * devices (legacy, 802.11abg).
416 */
417 if (num_possible_cpus() > 1)
David S. Miller2d6a5e92009-03-17 15:01:30 -0700418 ah->config.serialize_regmode = SER_REG_MODE_AUTO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700419}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400420EXPORT_SYMBOL(ath9k_hw_init);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700421
Luis R. Rodriguez50aca252009-08-03 12:24:42 -0700422static void ath9k_hw_init_defaults(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700423{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700424 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
425
426 regulatory->country_code = CTRY_DEFAULT;
427 regulatory->power_limit = MAX_RATE_POWER;
428 regulatory->tp_scale = ATH9K_TP_SCALE_MAX;
429
Sujithd535a422009-02-09 13:27:06 +0530430 ah->hw_version.magic = AR5416_MAGIC;
Sujithd535a422009-02-09 13:27:06 +0530431 ah->hw_version.subvendorid = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700432
433 ah->ah_flags = 0;
Luis R. Rodriguez8df5d1b2009-08-03 12:24:37 -0700434 if (ah->hw_version.devid == AR5416_AR9100_DEVID)
Sujithd535a422009-02-09 13:27:06 +0530435 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700436 if (!AR_SREV_9100(ah))
437 ah->ah_flags = AH_USE_EEPROM;
438
Sujith2660b812009-02-09 13:27:26 +0530439 ah->atim_window = 0;
Sujith2660b812009-02-09 13:27:26 +0530440 ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
441 ah->beacon_interval = 100;
442 ah->enable_32kHz_clock = DONT_USE_32KHZ;
443 ah->slottime = (u32) -1;
444 ah->acktimeout = (u32) -1;
445 ah->ctstimeout = (u32) -1;
446 ah->globaltxtimeout = (u32) -1;
Gabor Juhoscbdec972009-07-24 17:27:22 +0200447 ah->power_mode = ATH9K_PM_UNDEFINED;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700448}
449
Sujithcbe61d82009-02-09 13:27:12 +0530450static int ath9k_hw_rf_claim(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700451{
452 u32 val;
453
454 REG_WRITE(ah, AR_PHY(0), 0x00000007);
455
456 val = ath9k_hw_get_radiorev(ah);
457 switch (val & AR_RADIO_SREV_MAJOR) {
458 case 0:
459 val = AR_RAD5133_SREV_MAJOR;
460 break;
461 case AR_RAD5133_SREV_MAJOR:
462 case AR_RAD5122_SREV_MAJOR:
463 case AR_RAD2133_SREV_MAJOR:
464 case AR_RAD2122_SREV_MAJOR:
465 break;
466 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700467 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
468 "Radio Chip Rev 0x%02X not supported\n",
469 val & AR_RADIO_SREV_MAJOR);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700470 return -EOPNOTSUPP;
471 }
472
Sujithd535a422009-02-09 13:27:06 +0530473 ah->hw_version.analog5GhzRev = val;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700474
475 return 0;
476}
477
Sujithcbe61d82009-02-09 13:27:12 +0530478static int ath9k_hw_init_macaddr(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700479{
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700480 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530481 u32 sum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700482 int i;
Sujithf1dc5602008-10-29 10:16:30 +0530483 u16 eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700484
Sujithf1dc5602008-10-29 10:16:30 +0530485 sum = 0;
486 for (i = 0; i < 3; i++) {
Sujithf74df6f2009-02-09 13:27:24 +0530487 eeval = ah->eep_ops->get_eeprom(ah, AR_EEPROM_MAC(i));
Sujithf1dc5602008-10-29 10:16:30 +0530488 sum += eeval;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700489 common->macaddr[2 * i] = eeval >> 8;
490 common->macaddr[2 * i + 1] = eeval & 0xff;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700491 }
Sujithd8baa932009-03-30 15:28:25 +0530492 if (sum == 0 || sum == 0xffff * 3)
Sujithf1dc5602008-10-29 10:16:30 +0530493 return -EADDRNOTAVAIL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700494
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700495 return 0;
496}
497
Sujithcbe61d82009-02-09 13:27:12 +0530498static void ath9k_hw_init_rxgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530499{
500 u32 rxgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530501
Sujithf74df6f2009-02-09 13:27:24 +0530502 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_17) {
503 rxgain_type = ah->eep_ops->get_eeprom(ah, EEP_RXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530504
505 if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530506 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530507 ar9280Modes_backoff_13db_rxgain_9280_2,
508 ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2), 6);
509 else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530510 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530511 ar9280Modes_backoff_23db_rxgain_9280_2,
512 ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 6);
513 else
Sujith2660b812009-02-09 13:27:26 +0530514 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530515 ar9280Modes_original_rxgain_9280_2,
516 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530517 } else {
Sujith2660b812009-02-09 13:27:26 +0530518 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530519 ar9280Modes_original_rxgain_9280_2,
520 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530521 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530522}
523
Sujithcbe61d82009-02-09 13:27:12 +0530524static void ath9k_hw_init_txgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530525{
526 u32 txgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530527
Sujithf74df6f2009-02-09 13:27:24 +0530528 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_19) {
529 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530530
531 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
Sujith2660b812009-02-09 13:27:26 +0530532 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530533 ar9280Modes_high_power_tx_gain_9280_2,
534 ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 6);
535 else
Sujith2660b812009-02-09 13:27:26 +0530536 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530537 ar9280Modes_original_tx_gain_9280_2,
538 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530539 } else {
Sujith2660b812009-02-09 13:27:26 +0530540 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530541 ar9280Modes_original_tx_gain_9280_2,
542 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530543 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530544}
545
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700546static int ath9k_hw_post_init(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700547{
548 int ecode;
549
Sujithd8baa932009-03-30 15:28:25 +0530550 if (!ath9k_hw_chip_test(ah))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700551 return -ENODEV;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700552
553 ecode = ath9k_hw_rf_claim(ah);
554 if (ecode != 0)
555 return ecode;
556
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700557 ecode = ath9k_hw_eeprom_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700558 if (ecode != 0)
559 return ecode;
Sujith7d01b222009-03-13 08:55:55 +0530560
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700561 ath_print(ath9k_hw_common(ah), ATH_DBG_CONFIG,
562 "Eeprom VER: %d, REV: %d\n",
563 ah->eep_ops->get_eeprom_ver(ah),
564 ah->eep_ops->get_eeprom_rev(ah));
Sujith7d01b222009-03-13 08:55:55 +0530565
Luis R. Rodriguez574d6b12009-10-19 02:33:37 -0400566 if (!AR_SREV_9280_10_OR_LATER(ah)) {
567 ecode = ath9k_hw_rf_alloc_ext_banks(ah);
568 if (ecode) {
569 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
570 "Failed allocating banks for "
571 "external radio\n");
572 return ecode;
573 }
574 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700575
576 if (!AR_SREV_9100(ah)) {
577 ath9k_hw_ani_setup(ah);
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700578 ath9k_hw_ani_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700579 }
Sujithf1dc5602008-10-29 10:16:30 +0530580
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700581 return 0;
582}
583
Luis R. Rodriguezee2bb462009-08-03 12:24:39 -0700584static bool ath9k_hw_devid_supported(u16 devid)
585{
586 switch (devid) {
587 case AR5416_DEVID_PCI:
588 case AR5416_DEVID_PCIE:
589 case AR5416_AR9100_DEVID:
590 case AR9160_DEVID_PCI:
591 case AR9280_DEVID_PCI:
592 case AR9280_DEVID_PCIE:
593 case AR9285_DEVID_PCIE:
594 case AR5416_DEVID_AR9287_PCI:
595 case AR5416_DEVID_AR9287_PCIE:
Luis R. Rodriguez7976b422009-09-23 23:07:02 -0400596 case AR9271_USB:
Luis R. Rodriguezee2bb462009-08-03 12:24:39 -0700597 return true;
598 default:
599 break;
600 }
601 return false;
602}
603
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700604static bool ath9k_hw_macversion_supported(u32 macversion)
605{
606 switch (macversion) {
607 case AR_SREV_VERSION_5416_PCI:
608 case AR_SREV_VERSION_5416_PCIE:
609 case AR_SREV_VERSION_9160:
610 case AR_SREV_VERSION_9100:
611 case AR_SREV_VERSION_9280:
612 case AR_SREV_VERSION_9285:
613 case AR_SREV_VERSION_9287:
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400614 case AR_SREV_VERSION_9271:
Luis R. Rodriguez7976b422009-09-23 23:07:02 -0400615 return true;
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700616 default:
617 break;
618 }
619 return false;
620}
621
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700622static void ath9k_hw_init_cal_settings(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700623{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700624 if (AR_SREV_9160_10_OR_LATER(ah)) {
625 if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530626 ah->iq_caldata.calData = &iq_cal_single_sample;
627 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700628 &adc_gain_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530629 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700630 &adc_dc_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530631 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700632 &adc_init_dc_cal;
633 } else {
Sujith2660b812009-02-09 13:27:26 +0530634 ah->iq_caldata.calData = &iq_cal_multi_sample;
635 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700636 &adc_gain_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530637 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700638 &adc_dc_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530639 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700640 &adc_init_dc_cal;
641 }
Sujith2660b812009-02-09 13:27:26 +0530642 ah->supp_cals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700643 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700644}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700645
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700646static void ath9k_hw_init_mode_regs(struct ath_hw *ah)
647{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400648 if (AR_SREV_9271(ah)) {
Luis R. Rodriguez85643282009-10-19 02:33:33 -0400649 INIT_INI_ARRAY(&ah->iniModes, ar9271Modes_9271,
650 ARRAY_SIZE(ar9271Modes_9271), 6);
651 INIT_INI_ARRAY(&ah->iniCommon, ar9271Common_9271,
652 ARRAY_SIZE(ar9271Common_9271), 2);
653 INIT_INI_ARRAY(&ah->iniModes_9271_1_0_only,
654 ar9271Modes_9271_1_0_only,
655 ARRAY_SIZE(ar9271Modes_9271_1_0_only), 6);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400656 return;
657 }
658
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530659 if (AR_SREV_9287_11_OR_LATER(ah)) {
660 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_1,
661 ARRAY_SIZE(ar9287Modes_9287_1_1), 6);
662 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_1,
663 ARRAY_SIZE(ar9287Common_9287_1_1), 2);
664 if (ah->config.pcie_clock_req)
665 INIT_INI_ARRAY(&ah->iniPcieSerdes,
666 ar9287PciePhy_clkreq_off_L1_9287_1_1,
667 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_1), 2);
668 else
669 INIT_INI_ARRAY(&ah->iniPcieSerdes,
670 ar9287PciePhy_clkreq_always_on_L1_9287_1_1,
671 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_1),
672 2);
673 } else if (AR_SREV_9287_10_OR_LATER(ah)) {
674 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_0,
675 ARRAY_SIZE(ar9287Modes_9287_1_0), 6);
676 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_0,
677 ARRAY_SIZE(ar9287Common_9287_1_0), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700678
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530679 if (ah->config.pcie_clock_req)
680 INIT_INI_ARRAY(&ah->iniPcieSerdes,
681 ar9287PciePhy_clkreq_off_L1_9287_1_0,
682 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_0), 2);
683 else
684 INIT_INI_ARRAY(&ah->iniPcieSerdes,
685 ar9287PciePhy_clkreq_always_on_L1_9287_1_0,
686 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_0),
687 2);
688 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
689
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530690
Sujith2660b812009-02-09 13:27:26 +0530691 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530692 ARRAY_SIZE(ar9285Modes_9285_1_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530693 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530694 ARRAY_SIZE(ar9285Common_9285_1_2), 2);
695
Sujith2660b812009-02-09 13:27:26 +0530696 if (ah->config.pcie_clock_req) {
697 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530698 ar9285PciePhy_clkreq_off_L1_9285_1_2,
699 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2);
700 } else {
Sujith2660b812009-02-09 13:27:26 +0530701 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530702 ar9285PciePhy_clkreq_always_on_L1_9285_1_2,
703 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2),
704 2);
705 }
706 } else if (AR_SREV_9285_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530707 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530708 ARRAY_SIZE(ar9285Modes_9285), 6);
Sujith2660b812009-02-09 13:27:26 +0530709 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530710 ARRAY_SIZE(ar9285Common_9285), 2);
711
Sujith2660b812009-02-09 13:27:26 +0530712 if (ah->config.pcie_clock_req) {
713 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530714 ar9285PciePhy_clkreq_off_L1_9285,
715 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2);
716 } else {
Sujith2660b812009-02-09 13:27:26 +0530717 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530718 ar9285PciePhy_clkreq_always_on_L1_9285,
719 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285), 2);
720 }
721 } else if (AR_SREV_9280_20_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530722 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700723 ARRAY_SIZE(ar9280Modes_9280_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530724 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700725 ARRAY_SIZE(ar9280Common_9280_2), 2);
726
Sujith2660b812009-02-09 13:27:26 +0530727 if (ah->config.pcie_clock_req) {
728 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530729 ar9280PciePhy_clkreq_off_L1_9280,
730 ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700731 } else {
Sujith2660b812009-02-09 13:27:26 +0530732 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530733 ar9280PciePhy_clkreq_always_on_L1_9280,
734 ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700735 }
Sujith2660b812009-02-09 13:27:26 +0530736 INIT_INI_ARRAY(&ah->iniModesAdditional,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700737 ar9280Modes_fast_clock_9280_2,
Sujithf1dc5602008-10-29 10:16:30 +0530738 ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700739 } else if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530740 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700741 ARRAY_SIZE(ar9280Modes_9280), 6);
Sujith2660b812009-02-09 13:27:26 +0530742 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700743 ARRAY_SIZE(ar9280Common_9280), 2);
744 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530745 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700746 ARRAY_SIZE(ar5416Modes_9160), 6);
Sujith2660b812009-02-09 13:27:26 +0530747 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700748 ARRAY_SIZE(ar5416Common_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530749 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700750 ARRAY_SIZE(ar5416Bank0_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530751 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700752 ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530753 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700754 ARRAY_SIZE(ar5416Bank1_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530755 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700756 ARRAY_SIZE(ar5416Bank2_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530757 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700758 ARRAY_SIZE(ar5416Bank3_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530759 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700760 ARRAY_SIZE(ar5416Bank6_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530761 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700762 ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530763 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700764 ARRAY_SIZE(ar5416Bank7_9160), 2);
765 if (AR_SREV_9160_11(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530766 INIT_INI_ARRAY(&ah->iniAddac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700767 ar5416Addac_91601_1,
768 ARRAY_SIZE(ar5416Addac_91601_1), 2);
769 } else {
Sujith2660b812009-02-09 13:27:26 +0530770 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700771 ARRAY_SIZE(ar5416Addac_9160), 2);
772 }
773 } else if (AR_SREV_9100_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530774 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700775 ARRAY_SIZE(ar5416Modes_9100), 6);
Sujith2660b812009-02-09 13:27:26 +0530776 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700777 ARRAY_SIZE(ar5416Common_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530778 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700779 ARRAY_SIZE(ar5416Bank0_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530780 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700781 ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530782 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700783 ARRAY_SIZE(ar5416Bank1_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530784 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700785 ARRAY_SIZE(ar5416Bank2_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530786 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700787 ARRAY_SIZE(ar5416Bank3_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530788 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700789 ARRAY_SIZE(ar5416Bank6_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530790 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700791 ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530792 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700793 ARRAY_SIZE(ar5416Bank7_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530794 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700795 ARRAY_SIZE(ar5416Addac_9100), 2);
796 } else {
Sujith2660b812009-02-09 13:27:26 +0530797 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700798 ARRAY_SIZE(ar5416Modes), 6);
Sujith2660b812009-02-09 13:27:26 +0530799 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700800 ARRAY_SIZE(ar5416Common), 2);
Sujith2660b812009-02-09 13:27:26 +0530801 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700802 ARRAY_SIZE(ar5416Bank0), 2);
Sujith2660b812009-02-09 13:27:26 +0530803 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700804 ARRAY_SIZE(ar5416BB_RfGain), 3);
Sujith2660b812009-02-09 13:27:26 +0530805 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700806 ARRAY_SIZE(ar5416Bank1), 2);
Sujith2660b812009-02-09 13:27:26 +0530807 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700808 ARRAY_SIZE(ar5416Bank2), 2);
Sujith2660b812009-02-09 13:27:26 +0530809 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700810 ARRAY_SIZE(ar5416Bank3), 3);
Sujith2660b812009-02-09 13:27:26 +0530811 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700812 ARRAY_SIZE(ar5416Bank6), 3);
Sujith2660b812009-02-09 13:27:26 +0530813 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700814 ARRAY_SIZE(ar5416Bank6TPC), 3);
Sujith2660b812009-02-09 13:27:26 +0530815 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700816 ARRAY_SIZE(ar5416Bank7), 2);
Sujith2660b812009-02-09 13:27:26 +0530817 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700818 ARRAY_SIZE(ar5416Addac), 2);
819 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700820}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700821
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700822static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
823{
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530824 if (AR_SREV_9287_11_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530825 INIT_INI_ARRAY(&ah->iniModesRxGain,
826 ar9287Modes_rx_gain_9287_1_1,
827 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_1), 6);
828 else if (AR_SREV_9287_10(ah))
829 INIT_INI_ARRAY(&ah->iniModesRxGain,
830 ar9287Modes_rx_gain_9287_1_0,
831 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_0), 6);
832 else if (AR_SREV_9280_20(ah))
833 ath9k_hw_init_rxgain_ini(ah);
834
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530835 if (AR_SREV_9287_11_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530836 INIT_INI_ARRAY(&ah->iniModesTxGain,
837 ar9287Modes_tx_gain_9287_1_1,
838 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_1), 6);
839 } else if (AR_SREV_9287_10(ah)) {
840 INIT_INI_ARRAY(&ah->iniModesTxGain,
841 ar9287Modes_tx_gain_9287_1_0,
842 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_0), 6);
843 } else if (AR_SREV_9280_20(ah)) {
844 ath9k_hw_init_txgain_ini(ah);
845 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530846 u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
847
848 /* txgain table */
849 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) {
850 INIT_INI_ARRAY(&ah->iniModesTxGain,
851 ar9285Modes_high_power_tx_gain_9285_1_2,
852 ARRAY_SIZE(ar9285Modes_high_power_tx_gain_9285_1_2), 6);
853 } else {
854 INIT_INI_ARRAY(&ah->iniModesTxGain,
855 ar9285Modes_original_tx_gain_9285_1_2,
856 ARRAY_SIZE(ar9285Modes_original_tx_gain_9285_1_2), 6);
857 }
858
859 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700860}
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530861
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700862static void ath9k_hw_init_11a_eeprom_fix(struct ath_hw *ah)
863{
864 u32 i, j;
Sujith06d0f062009-02-12 10:06:45 +0530865
866 if ((ah->hw_version.devid == AR9280_DEVID_PCI) &&
867 test_bit(ATH9K_MODE_11A, ah->caps.wireless_modes)) {
868
869 /* EEPROM Fixup */
Sujith2660b812009-02-09 13:27:26 +0530870 for (i = 0; i < ah->iniModes.ia_rows; i++) {
871 u32 reg = INI_RA(&ah->iniModes, i, 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700872
Sujith2660b812009-02-09 13:27:26 +0530873 for (j = 1; j < ah->iniModes.ia_columns; j++) {
874 u32 val = INI_RA(&ah->iniModes, i, j);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700875
Sujith2660b812009-02-09 13:27:26 +0530876 INI_RA(&ah->iniModes, i, j) =
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530877 ath9k_hw_ini_fixup(ah,
Sujith2660b812009-02-09 13:27:26 +0530878 &ah->eeprom.def,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700879 reg, val);
880 }
881 }
882 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700883}
884
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700885int ath9k_hw_init(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700886{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700887 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700888 int r = 0;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700889
Luis R. Rodriguez3ca34032009-09-23 23:07:01 -0400890 if (!ath9k_hw_devid_supported(ah->hw_version.devid)) {
891 ath_print(common, ATH_DBG_FATAL,
892 "Unsupported device ID: 0x%0x\n",
893 ah->hw_version.devid);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700894 return -EOPNOTSUPP;
Luis R. Rodriguez3ca34032009-09-23 23:07:01 -0400895 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700896
897 ath9k_hw_init_defaults(ah);
898 ath9k_hw_init_config(ah);
899
900 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700901 ath_print(common, ATH_DBG_FATAL,
902 "Couldn't reset chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700903 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700904 }
905
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700906 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700907 ath_print(common, ATH_DBG_FATAL, "Couldn't wakeup chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700908 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700909 }
910
911 if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
912 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
913 (AR_SREV_9280(ah) && !ah->is_pciexpress)) {
914 ah->config.serialize_regmode =
915 SER_REG_MODE_ON;
916 } else {
917 ah->config.serialize_regmode =
918 SER_REG_MODE_OFF;
919 }
920 }
921
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700922 ath_print(common, ATH_DBG_RESET, "serialize_regmode is %d\n",
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700923 ah->config.serialize_regmode);
924
925 if (!ath9k_hw_macversion_supported(ah->hw_version.macVersion)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700926 ath_print(common, ATH_DBG_FATAL,
927 "Mac Chip Rev 0x%02x.%x is not supported by "
928 "this driver\n", ah->hw_version.macVersion,
929 ah->hw_version.macRev);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700930 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700931 }
932
933 if (AR_SREV_9100(ah)) {
934 ah->iq_caldata.calData = &iq_cal_multi_sample;
935 ah->supp_cals = IQ_MISMATCH_CAL;
936 ah->is_pciexpress = false;
937 }
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400938
939 if (AR_SREV_9271(ah))
940 ah->is_pciexpress = false;
941
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700942 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
943
944 ath9k_hw_init_cal_settings(ah);
945
946 ah->ani_function = ATH9K_ANI_ALL;
Luis R. Rodrigueze68a0602009-10-19 02:33:41 -0400947 if (AR_SREV_9280_10_OR_LATER(ah)) {
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700948 ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
Luis R. Rodrigueze68a0602009-10-19 02:33:41 -0400949 ah->ath9k_hw_rf_set_freq = &ath9k_hw_ar9280_set_channel;
Luis R. Rodriguezae478cf2009-10-19 02:33:43 -0400950 ah->ath9k_hw_spur_mitigate_freq = &ath9k_hw_9280_spur_mitigate;
951 } else {
Luis R. Rodrigueze68a0602009-10-19 02:33:41 -0400952 ah->ath9k_hw_rf_set_freq = &ath9k_hw_set_channel;
Luis R. Rodriguezae478cf2009-10-19 02:33:43 -0400953 ah->ath9k_hw_spur_mitigate_freq = &ath9k_hw_spur_mitigate;
954 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700955
956 ath9k_hw_init_mode_regs(ah);
957
958 if (ah->is_pciexpress)
Vivek Natarajan93b1b372009-09-17 09:24:58 +0530959 ath9k_hw_configpcipowersave(ah, 0, 0);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700960 else
961 ath9k_hw_disablepcie(ah);
962
Sujith193cd452009-09-18 15:04:07 +0530963 /* Support for Japan ch.14 (2484) spread */
964 if (AR_SREV_9287_11_OR_LATER(ah)) {
965 INIT_INI_ARRAY(&ah->iniCckfirNormal,
966 ar9287Common_normal_cck_fir_coeff_92871_1,
967 ARRAY_SIZE(ar9287Common_normal_cck_fir_coeff_92871_1), 2);
968 INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
969 ar9287Common_japan_2484_cck_fir_coeff_92871_1,
970 ARRAY_SIZE(ar9287Common_japan_2484_cck_fir_coeff_92871_1), 2);
971 }
972
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700973 r = ath9k_hw_post_init(ah);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700974 if (r)
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700975 return r;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700976
977 ath9k_hw_init_mode_gain_regs(ah);
978 ath9k_hw_fill_cap_info(ah);
979 ath9k_hw_init_11a_eeprom_fix(ah);
Sujithf6688cd2008-12-07 21:43:10 +0530980
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700981 r = ath9k_hw_init_macaddr(ah);
982 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700983 ath_print(common, ATH_DBG_FATAL,
984 "Failed to initialize MAC address\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700985 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700986 }
987
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400988 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
Sujith2660b812009-02-09 13:27:26 +0530989 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700990 else
Sujith2660b812009-02-09 13:27:26 +0530991 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700992
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700993 ath9k_init_nfcal_hist_buffer(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700994
Luis R. Rodriguez211f5852009-10-06 21:19:07 -0400995 common->state = ATH_HW_INITIALIZED;
996
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700997 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700998}
999
Sujithcbe61d82009-02-09 13:27:12 +05301000static void ath9k_hw_init_bb(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301001 struct ath9k_channel *chan)
1002{
1003 u32 synthDelay;
1004
1005 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +05301006 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +05301007 synthDelay = (4 * synthDelay) / 22;
1008 else
1009 synthDelay /= 10;
1010
1011 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
1012
1013 udelay(synthDelay + BASE_ACTIVATE_DELAY);
1014}
1015
Sujithcbe61d82009-02-09 13:27:12 +05301016static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301017{
1018 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
1019 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
1020
1021 REG_WRITE(ah, AR_QOS_NO_ACK,
1022 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
1023 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
1024 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
1025
1026 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
1027 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
1028 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
1029 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
1030 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
1031}
1032
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -04001033static void ath9k_hw_change_target_baud(struct ath_hw *ah, u32 freq, u32 baud)
1034{
1035 u32 lcr;
1036 u32 baud_divider = freq * 1000 * 1000 / 16 / baud;
1037
1038 lcr = REG_READ(ah , 0x5100c);
1039 lcr |= 0x80;
1040
1041 REG_WRITE(ah, 0x5100c, lcr);
1042 REG_WRITE(ah, 0x51004, (baud_divider >> 8));
1043 REG_WRITE(ah, 0x51000, (baud_divider & 0xff));
1044
1045 lcr &= ~0x80;
1046 REG_WRITE(ah, 0x5100c, lcr);
1047}
1048
Sujithcbe61d82009-02-09 13:27:12 +05301049static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301050 struct ath9k_channel *chan)
1051{
1052 u32 pll;
1053
1054 if (AR_SREV_9100(ah)) {
1055 if (chan && IS_CHAN_5GHZ(chan))
1056 pll = 0x1450;
1057 else
1058 pll = 0x1458;
1059 } else {
1060 if (AR_SREV_9280_10_OR_LATER(ah)) {
1061 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
1062
1063 if (chan && IS_CHAN_HALF_RATE(chan))
1064 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
1065 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1066 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
1067
1068 if (chan && IS_CHAN_5GHZ(chan)) {
1069 pll |= SM(0x28, AR_RTC_9160_PLL_DIV);
1070
1071
1072 if (AR_SREV_9280_20(ah)) {
1073 if (((chan->channel % 20) == 0)
1074 || ((chan->channel % 10) == 0))
1075 pll = 0x2850;
1076 else
1077 pll = 0x142c;
1078 }
1079 } else {
1080 pll |= SM(0x2c, AR_RTC_9160_PLL_DIV);
1081 }
1082
1083 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1084
1085 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
1086
1087 if (chan && IS_CHAN_HALF_RATE(chan))
1088 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
1089 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1090 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
1091
1092 if (chan && IS_CHAN_5GHZ(chan))
1093 pll |= SM(0x50, AR_RTC_9160_PLL_DIV);
1094 else
1095 pll |= SM(0x58, AR_RTC_9160_PLL_DIV);
1096 } else {
1097 pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2;
1098
1099 if (chan && IS_CHAN_HALF_RATE(chan))
1100 pll |= SM(0x1, AR_RTC_PLL_CLKSEL);
1101 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1102 pll |= SM(0x2, AR_RTC_PLL_CLKSEL);
1103
1104 if (chan && IS_CHAN_5GHZ(chan))
1105 pll |= SM(0xa, AR_RTC_PLL_DIV);
1106 else
1107 pll |= SM(0xb, AR_RTC_PLL_DIV);
1108 }
1109 }
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001110 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +05301111
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -04001112 /* Switch the core clock for ar9271 to 117Mhz */
1113 if (AR_SREV_9271(ah)) {
1114 if ((pll == 0x142c) || (pll == 0x2850) ) {
1115 udelay(500);
1116 /* set CLKOBS to output AHB clock */
1117 REG_WRITE(ah, 0x7020, 0xe);
1118 /*
1119 * 0x304: 117Mhz, ahb_ratio: 1x1
1120 * 0x306: 40Mhz, ahb_ratio: 1x1
1121 */
1122 REG_WRITE(ah, 0x50040, 0x304);
1123 /*
1124 * makes adjustments for the baud dividor to keep the
1125 * targetted baud rate based on the used core clock.
1126 */
1127 ath9k_hw_change_target_baud(ah, AR9271_CORE_CLOCK,
1128 AR9271_TARGET_BAUD_RATE);
1129 }
1130 }
1131
Sujithf1dc5602008-10-29 10:16:30 +05301132 udelay(RTC_PLL_SETTLE_DELAY);
1133
1134 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
1135}
1136
Sujithcbe61d82009-02-09 13:27:12 +05301137static void ath9k_hw_init_chain_masks(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301138{
Sujithf1dc5602008-10-29 10:16:30 +05301139 int rx_chainmask, tx_chainmask;
1140
Sujith2660b812009-02-09 13:27:26 +05301141 rx_chainmask = ah->rxchainmask;
1142 tx_chainmask = ah->txchainmask;
Sujithf1dc5602008-10-29 10:16:30 +05301143
1144 switch (rx_chainmask) {
1145 case 0x5:
1146 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1147 AR_PHY_SWAP_ALT_CHAIN);
1148 case 0x3:
Sujithd535a422009-02-09 13:27:06 +05301149 if (((ah)->hw_version.macVersion <= AR_SREV_VERSION_9160)) {
Sujithf1dc5602008-10-29 10:16:30 +05301150 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7);
1151 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7);
1152 break;
1153 }
1154 case 0x1:
1155 case 0x2:
Sujithf1dc5602008-10-29 10:16:30 +05301156 case 0x7:
1157 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
1158 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
1159 break;
1160 default:
1161 break;
1162 }
1163
1164 REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);
1165 if (tx_chainmask == 0x5) {
1166 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1167 AR_PHY_SWAP_ALT_CHAIN);
1168 }
1169 if (AR_SREV_9100(ah))
1170 REG_WRITE(ah, AR_PHY_ANALOG_SWAP,
1171 REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
1172}
1173
Sujithcbe61d82009-02-09 13:27:12 +05301174static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -08001175 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301176{
Sujith2660b812009-02-09 13:27:26 +05301177 ah->mask_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +05301178 AR_IMR_TXURN |
1179 AR_IMR_RXERR |
1180 AR_IMR_RXORN |
1181 AR_IMR_BCNMISC;
1182
Sujith0ef1f162009-03-30 15:28:35 +05301183 if (ah->config.intr_mitigation)
Sujith2660b812009-02-09 13:27:26 +05301184 ah->mask_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
Sujithf1dc5602008-10-29 10:16:30 +05301185 else
Sujith2660b812009-02-09 13:27:26 +05301186 ah->mask_reg |= AR_IMR_RXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301187
Sujith2660b812009-02-09 13:27:26 +05301188 ah->mask_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301189
Colin McCabed97809d2008-12-01 13:38:55 -08001190 if (opmode == NL80211_IFTYPE_AP)
Sujith2660b812009-02-09 13:27:26 +05301191 ah->mask_reg |= AR_IMR_MIB;
Sujithf1dc5602008-10-29 10:16:30 +05301192
Sujith2660b812009-02-09 13:27:26 +05301193 REG_WRITE(ah, AR_IMR, ah->mask_reg);
Sujithf1dc5602008-10-29 10:16:30 +05301194 REG_WRITE(ah, AR_IMR_S2, REG_READ(ah, AR_IMR_S2) | AR_IMR_S2_GTT);
1195
1196 if (!AR_SREV_9100(ah)) {
1197 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
1198 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
1199 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
1200 }
1201}
1202
Sujithcbe61d82009-02-09 13:27:12 +05301203static bool ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301204{
Sujithf1dc5602008-10-29 10:16:30 +05301205 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001206 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1207 "bad ack timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301208 ah->acktimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301209 return false;
1210 } else {
1211 REG_RMW_FIELD(ah, AR_TIME_OUT,
1212 AR_TIME_OUT_ACK, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301213 ah->acktimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301214 return true;
1215 }
1216}
1217
Sujithcbe61d82009-02-09 13:27:12 +05301218static bool ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301219{
Sujithf1dc5602008-10-29 10:16:30 +05301220 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_CTS))) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001221 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1222 "bad cts timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301223 ah->ctstimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301224 return false;
1225 } else {
1226 REG_RMW_FIELD(ah, AR_TIME_OUT,
1227 AR_TIME_OUT_CTS, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301228 ah->ctstimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301229 return true;
1230 }
1231}
1232
Sujithcbe61d82009-02-09 13:27:12 +05301233static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +05301234{
Sujithf1dc5602008-10-29 10:16:30 +05301235 if (tu > 0xFFFF) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001236 ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT,
1237 "bad global tx timeout %u\n", tu);
Sujith2660b812009-02-09 13:27:26 +05301238 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301239 return false;
1240 } else {
1241 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +05301242 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +05301243 return true;
1244 }
1245}
1246
Sujithcbe61d82009-02-09 13:27:12 +05301247static void ath9k_hw_init_user_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301248{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001249 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
1250 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +05301251
Sujith2660b812009-02-09 13:27:26 +05301252 if (ah->misc_mode != 0)
Sujithf1dc5602008-10-29 10:16:30 +05301253 REG_WRITE(ah, AR_PCU_MISC,
Sujith2660b812009-02-09 13:27:26 +05301254 REG_READ(ah, AR_PCU_MISC) | ah->misc_mode);
1255 if (ah->slottime != (u32) -1)
1256 ath9k_hw_setslottime(ah, ah->slottime);
1257 if (ah->acktimeout != (u32) -1)
1258 ath9k_hw_set_ack_timeout(ah, ah->acktimeout);
1259 if (ah->ctstimeout != (u32) -1)
1260 ath9k_hw_set_cts_timeout(ah, ah->ctstimeout);
1261 if (ah->globaltxtimeout != (u32) -1)
1262 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Sujithf1dc5602008-10-29 10:16:30 +05301263}
1264
1265const char *ath9k_hw_probe(u16 vendorid, u16 devid)
1266{
1267 return vendorid == ATHEROS_VENDOR_ID ?
1268 ath9k_hw_devname(devid) : NULL;
1269}
1270
Sujithcbe61d82009-02-09 13:27:12 +05301271void ath9k_hw_detach(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001272{
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001273 struct ath_common *common = ath9k_hw_common(ah);
1274
1275 if (common->state <= ATH_HW_INITIALIZED)
1276 goto free_hw;
1277
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001278 if (!AR_SREV_9100(ah))
Luis R. Rodrigueze70c0cf2009-08-03 12:24:51 -07001279 ath9k_hw_ani_disable(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001280
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001281 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001282
1283free_hw:
Luis R. Rodriguezdc51dd52009-10-19 02:33:39 -04001284 if (!AR_SREV_9280_10_OR_LATER(ah))
1285 ath9k_hw_rf_free_ext_banks(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001286 kfree(ah);
Luis R. Rodriguez9db6b6a2009-08-03 12:24:52 -07001287 ah = NULL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001288}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001289EXPORT_SYMBOL(ath9k_hw_detach);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001290
Sujithf1dc5602008-10-29 10:16:30 +05301291/*******/
1292/* INI */
1293/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001294
Sujithcbe61d82009-02-09 13:27:12 +05301295static void ath9k_hw_override_ini(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301296 struct ath9k_channel *chan)
1297{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001298 u32 val;
1299
1300 if (AR_SREV_9271(ah)) {
1301 /*
1302 * Enable spectral scan to solution for issues with stuck
1303 * beacons on AR9271 1.0. The beacon stuck issue is not seeon on
1304 * AR9271 1.1
1305 */
1306 if (AR_SREV_9271_10(ah)) {
Luis R. Rodriguezec11bb82009-10-27 12:59:36 -04001307 val = REG_READ(ah, AR_PHY_SPECTRAL_SCAN) |
1308 AR_PHY_SPECTRAL_SCAN_ENABLE;
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001309 REG_WRITE(ah, AR_PHY_SPECTRAL_SCAN, val);
1310 }
1311 else if (AR_SREV_9271_11(ah))
1312 /*
1313 * change AR_PHY_RF_CTL3 setting to fix MAC issue
1314 * present on AR9271 1.1
1315 */
1316 REG_WRITE(ah, AR_PHY_RF_CTL3, 0x3a020001);
1317 return;
1318 }
1319
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +05301320 /*
1321 * Set the RX_ABORT and RX_DIS and clear if off only after
1322 * RXE is set for MAC. This prevents frames with corrupted
1323 * descriptor status.
1324 */
1325 REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
1326
Vasanthakumar Thiagarajan204d7942009-09-17 09:26:14 +05301327 if (AR_SREV_9280_10_OR_LATER(ah)) {
1328 val = REG_READ(ah, AR_PCU_MISC_MODE2) &
1329 (~AR_PCU_MISC_MODE2_HWWAR1);
1330
1331 if (AR_SREV_9287_10_OR_LATER(ah))
1332 val = val & (~AR_PCU_MISC_MODE2_HWWAR2);
1333
1334 REG_WRITE(ah, AR_PCU_MISC_MODE2, val);
1335 }
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +05301336
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001337 if (!AR_SREV_5416_20_OR_LATER(ah) ||
Sujithf1dc5602008-10-29 10:16:30 +05301338 AR_SREV_9280_10_OR_LATER(ah))
1339 return;
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001340 /*
1341 * Disable BB clock gating
1342 * Necessary to avoid issues on AR5416 2.0
1343 */
Sujithf1dc5602008-10-29 10:16:30 +05301344 REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
1345}
1346
Sujithcbe61d82009-02-09 13:27:12 +05301347static u32 ath9k_hw_def_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301348 struct ar5416_eeprom_def *pEepData,
Sujithf1dc5602008-10-29 10:16:30 +05301349 u32 reg, u32 value)
1350{
1351 struct base_eep_header *pBase = &(pEepData->baseEepHeader);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001352 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301353
Sujithd535a422009-02-09 13:27:06 +05301354 switch (ah->hw_version.devid) {
Sujithf1dc5602008-10-29 10:16:30 +05301355 case AR9280_DEVID_PCI:
1356 if (reg == 0x7894) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001357 ath_print(common, ATH_DBG_EEPROM,
Sujithf1dc5602008-10-29 10:16:30 +05301358 "ini VAL: %x EEPROM: %x\n", value,
1359 (pBase->version & 0xff));
1360
1361 if ((pBase->version & 0xff) > 0x0a) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001362 ath_print(common, ATH_DBG_EEPROM,
1363 "PWDCLKIND: %d\n",
1364 pBase->pwdclkind);
Sujithf1dc5602008-10-29 10:16:30 +05301365 value &= ~AR_AN_TOP2_PWDCLKIND;
1366 value |= AR_AN_TOP2_PWDCLKIND &
1367 (pBase->pwdclkind << AR_AN_TOP2_PWDCLKIND_S);
1368 } else {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001369 ath_print(common, ATH_DBG_EEPROM,
1370 "PWDCLKIND Earlier Rev\n");
Sujithf1dc5602008-10-29 10:16:30 +05301371 }
1372
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001373 ath_print(common, ATH_DBG_EEPROM,
1374 "final ini VAL: %x\n", value);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001375 }
Sujithf1dc5602008-10-29 10:16:30 +05301376 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001377 }
1378
Sujithf1dc5602008-10-29 10:16:30 +05301379 return value;
1380}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001381
Sujithcbe61d82009-02-09 13:27:12 +05301382static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301383 struct ar5416_eeprom_def *pEepData,
1384 u32 reg, u32 value)
1385{
Sujith2660b812009-02-09 13:27:26 +05301386 if (ah->eep_map == EEP_MAP_4KBITS)
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301387 return value;
1388 else
1389 return ath9k_hw_def_ini_fixup(ah, pEepData, reg, value);
1390}
1391
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301392static void ath9k_olc_init(struct ath_hw *ah)
1393{
1394 u32 i;
1395
Vivek Natarajandb91f2e2009-08-14 11:27:16 +05301396 if (OLC_FOR_AR9287_10_LATER) {
1397 REG_SET_BIT(ah, AR_PHY_TX_PWRCTRL9,
1398 AR_PHY_TX_PWRCTRL9_RES_DC_REMOVAL);
1399 ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TXPC0,
1400 AR9287_AN_TXPC0_TXPCMODE,
1401 AR9287_AN_TXPC0_TXPCMODE_S,
1402 AR9287_AN_TXPC0_TXPCMODE_TEMPSENSE);
1403 udelay(100);
1404 } else {
1405 for (i = 0; i < AR9280_TX_GAIN_TABLE_SIZE; i++)
1406 ah->originalGain[i] =
1407 MS(REG_READ(ah, AR_PHY_TX_GAIN_TBL1 + i * 4),
1408 AR_PHY_TX_GAIN);
1409 ah->PDADCdelta = 0;
1410 }
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301411}
1412
Bob Copeland3a702e42009-03-30 22:30:29 -04001413static u32 ath9k_regd_get_ctl(struct ath_regulatory *reg,
1414 struct ath9k_channel *chan)
1415{
1416 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
1417
1418 if (IS_CHAN_B(chan))
1419 ctl |= CTL_11B;
1420 else if (IS_CHAN_G(chan))
1421 ctl |= CTL_11G;
1422 else
1423 ctl |= CTL_11A;
1424
1425 return ctl;
1426}
1427
Sujithcbe61d82009-02-09 13:27:12 +05301428static int ath9k_hw_process_ini(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001429 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301430{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001431 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301432 int i, regWrites = 0;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001433 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301434 u32 modesIndex, freqIndex;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001435
Sujithf1dc5602008-10-29 10:16:30 +05301436 switch (chan->chanmode) {
1437 case CHANNEL_A:
1438 case CHANNEL_A_HT20:
1439 modesIndex = 1;
1440 freqIndex = 1;
1441 break;
1442 case CHANNEL_A_HT40PLUS:
1443 case CHANNEL_A_HT40MINUS:
1444 modesIndex = 2;
1445 freqIndex = 1;
1446 break;
1447 case CHANNEL_G:
1448 case CHANNEL_G_HT20:
1449 case CHANNEL_B:
1450 modesIndex = 4;
1451 freqIndex = 2;
1452 break;
1453 case CHANNEL_G_HT40PLUS:
1454 case CHANNEL_G_HT40MINUS:
1455 modesIndex = 3;
1456 freqIndex = 2;
1457 break;
1458
1459 default:
1460 return -EINVAL;
1461 }
1462
1463 REG_WRITE(ah, AR_PHY(0), 0x00000007);
Sujithf1dc5602008-10-29 10:16:30 +05301464 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
Sujithf74df6f2009-02-09 13:27:24 +05301465 ah->eep_ops->set_addac(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301466
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001467 if (AR_SREV_5416_22_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +05301468 REG_WRITE_ARRAY(&ah->iniAddac, 1, regWrites);
Sujithf1dc5602008-10-29 10:16:30 +05301469 } else {
1470 struct ar5416IniArray temp;
1471 u32 addacSize =
Sujith2660b812009-02-09 13:27:26 +05301472 sizeof(u32) * ah->iniAddac.ia_rows *
1473 ah->iniAddac.ia_columns;
Sujithf1dc5602008-10-29 10:16:30 +05301474
Sujith2660b812009-02-09 13:27:26 +05301475 memcpy(ah->addac5416_21,
1476 ah->iniAddac.ia_array, addacSize);
Sujithf1dc5602008-10-29 10:16:30 +05301477
Sujith2660b812009-02-09 13:27:26 +05301478 (ah->addac5416_21)[31 * ah->iniAddac.ia_columns + 1] = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301479
Sujith2660b812009-02-09 13:27:26 +05301480 temp.ia_array = ah->addac5416_21;
1481 temp.ia_columns = ah->iniAddac.ia_columns;
1482 temp.ia_rows = ah->iniAddac.ia_rows;
Sujithf1dc5602008-10-29 10:16:30 +05301483 REG_WRITE_ARRAY(&temp, 1, regWrites);
1484 }
1485
1486 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
1487
Sujith2660b812009-02-09 13:27:26 +05301488 for (i = 0; i < ah->iniModes.ia_rows; i++) {
1489 u32 reg = INI_RA(&ah->iniModes, i, 0);
1490 u32 val = INI_RA(&ah->iniModes, i, modesIndex);
Sujithf1dc5602008-10-29 10:16:30 +05301491
Sujithf1dc5602008-10-29 10:16:30 +05301492 REG_WRITE(ah, reg, val);
1493
1494 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301495 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301496 udelay(100);
1497 }
1498
1499 DO_DELAY(regWrites);
1500 }
1501
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301502 if (AR_SREV_9280(ah) || AR_SREV_9287_10_OR_LATER(ah))
Sujith2660b812009-02-09 13:27:26 +05301503 REG_WRITE_ARRAY(&ah->iniModesRxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301504
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301505 if (AR_SREV_9280(ah) || AR_SREV_9285_12_OR_LATER(ah) ||
1506 AR_SREV_9287_10_OR_LATER(ah))
Sujith2660b812009-02-09 13:27:26 +05301507 REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301508
Sujith2660b812009-02-09 13:27:26 +05301509 for (i = 0; i < ah->iniCommon.ia_rows; i++) {
1510 u32 reg = INI_RA(&ah->iniCommon, i, 0);
1511 u32 val = INI_RA(&ah->iniCommon, i, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301512
1513 REG_WRITE(ah, reg, val);
1514
1515 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301516 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301517 udelay(100);
1518 }
1519
1520 DO_DELAY(regWrites);
1521 }
1522
Luis R. Rodriguez896ff262009-10-19 02:33:44 -04001523 ath9k_hw_write_regs(ah, freqIndex, regWrites);
Sujithf1dc5602008-10-29 10:16:30 +05301524
Luis R. Rodriguez85643282009-10-19 02:33:33 -04001525 if (AR_SREV_9271_10(ah))
1526 REG_WRITE_ARRAY(&ah->iniModes_9271_1_0_only,
1527 modesIndex, regWrites);
1528
Sujithf1dc5602008-10-29 10:16:30 +05301529 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan)) {
Sujith2660b812009-02-09 13:27:26 +05301530 REG_WRITE_ARRAY(&ah->iniModesAdditional, modesIndex,
Sujithf1dc5602008-10-29 10:16:30 +05301531 regWrites);
1532 }
1533
1534 ath9k_hw_override_ini(ah, chan);
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001535 ath9k_hw_set_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301536 ath9k_hw_init_chain_masks(ah);
1537
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301538 if (OLC_FOR_AR9280_20_LATER)
1539 ath9k_olc_init(ah);
1540
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001541 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001542 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001543 channel->max_antenna_gain * 2,
1544 channel->max_power * 2,
1545 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001546 (u32) regulatory->power_limit));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001547
Sujithf1dc5602008-10-29 10:16:30 +05301548 if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001549 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1550 "ar5416SetRfRegs failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001551 return -EIO;
1552 }
1553
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001554 return 0;
1555}
1556
Sujithf1dc5602008-10-29 10:16:30 +05301557/****************************************/
1558/* Reset and Channel Switching Routines */
1559/****************************************/
1560
Sujithcbe61d82009-02-09 13:27:12 +05301561static void ath9k_hw_set_rfmode(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301562{
1563 u32 rfMode = 0;
1564
1565 if (chan == NULL)
1566 return;
1567
1568 rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
1569 ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
1570
1571 if (!AR_SREV_9280_10_OR_LATER(ah))
1572 rfMode |= (IS_CHAN_5GHZ(chan)) ?
1573 AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ;
1574
1575 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan))
1576 rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
1577
1578 REG_WRITE(ah, AR_PHY_MODE, rfMode);
1579}
1580
Sujithcbe61d82009-02-09 13:27:12 +05301581static void ath9k_hw_mark_phy_inactive(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301582{
1583 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
1584}
1585
Sujithcbe61d82009-02-09 13:27:12 +05301586static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301587{
1588 u32 regval;
1589
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001590 /*
1591 * set AHB_MODE not to do cacheline prefetches
1592 */
Sujithf1dc5602008-10-29 10:16:30 +05301593 regval = REG_READ(ah, AR_AHB_MODE);
1594 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
1595
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001596 /*
1597 * let mac dma reads be in 128 byte chunks
1598 */
Sujithf1dc5602008-10-29 10:16:30 +05301599 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
1600 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
1601
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001602 /*
1603 * Restore TX Trigger Level to its pre-reset value.
1604 * The initial value depends on whether aggregation is enabled, and is
1605 * adjusted whenever underruns are detected.
1606 */
Sujith2660b812009-02-09 13:27:26 +05301607 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +05301608
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001609 /*
1610 * let mac dma writes be in 128 byte chunks
1611 */
Sujithf1dc5602008-10-29 10:16:30 +05301612 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
1613 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
1614
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001615 /*
1616 * Setup receive FIFO threshold to hold off TX activities
1617 */
Sujithf1dc5602008-10-29 10:16:30 +05301618 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1619
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001620 /*
1621 * reduce the number of usable entries in PCU TXBUF to avoid
1622 * wrap around issues.
1623 */
Sujithf1dc5602008-10-29 10:16:30 +05301624 if (AR_SREV_9285(ah)) {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001625 /* For AR9285 the number of Fifos are reduced to half.
1626 * So set the usable tx buf size also to half to
1627 * avoid data/delimiter underruns
1628 */
Sujithf1dc5602008-10-29 10:16:30 +05301629 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1630 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001631 } else if (!AR_SREV_9271(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +05301632 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1633 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1634 }
1635}
1636
Sujithcbe61d82009-02-09 13:27:12 +05301637static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301638{
1639 u32 val;
1640
1641 val = REG_READ(ah, AR_STA_ID1);
1642 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
1643 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001644 case NL80211_IFTYPE_AP:
Sujithf1dc5602008-10-29 10:16:30 +05301645 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
1646 | AR_STA_ID1_KSRCH_MODE);
1647 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1648 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001649 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04001650 case NL80211_IFTYPE_MESH_POINT:
Sujithf1dc5602008-10-29 10:16:30 +05301651 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
1652 | AR_STA_ID1_KSRCH_MODE);
1653 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1654 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001655 case NL80211_IFTYPE_STATION:
1656 case NL80211_IFTYPE_MONITOR:
Sujithf1dc5602008-10-29 10:16:30 +05301657 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
1658 break;
1659 }
1660}
1661
Sujithcbe61d82009-02-09 13:27:12 +05301662static inline void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001663 u32 coef_scaled,
1664 u32 *coef_mantissa,
1665 u32 *coef_exponent)
1666{
1667 u32 coef_exp, coef_man;
1668
1669 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1670 if ((coef_scaled >> coef_exp) & 0x1)
1671 break;
1672
1673 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1674
1675 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1676
1677 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1678 *coef_exponent = coef_exp - 16;
1679}
1680
Sujithcbe61d82009-02-09 13:27:12 +05301681static void ath9k_hw_set_delta_slope(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301682 struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001683{
1684 u32 coef_scaled, ds_coef_exp, ds_coef_man;
1685 u32 clockMhzScaled = 0x64000000;
1686 struct chan_centers centers;
1687
1688 if (IS_CHAN_HALF_RATE(chan))
1689 clockMhzScaled = clockMhzScaled >> 1;
1690 else if (IS_CHAN_QUARTER_RATE(chan))
1691 clockMhzScaled = clockMhzScaled >> 2;
1692
1693 ath9k_hw_get_channel_centers(ah, chan, &centers);
1694 coef_scaled = clockMhzScaled / centers.synth_center;
1695
1696 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1697 &ds_coef_exp);
1698
1699 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1700 AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
1701 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1702 AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
1703
1704 coef_scaled = (9 * coef_scaled) / 10;
1705
1706 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1707 &ds_coef_exp);
1708
1709 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1710 AR_PHY_HALFGI_DSC_MAN, ds_coef_man);
1711 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1712 AR_PHY_HALFGI_DSC_EXP, ds_coef_exp);
1713}
1714
Sujithcbe61d82009-02-09 13:27:12 +05301715static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +05301716{
1717 u32 rst_flags;
1718 u32 tmpReg;
1719
Sujith70768492009-02-16 13:23:12 +05301720 if (AR_SREV_9100(ah)) {
1721 u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK);
1722 val &= ~AR_RTC_DERIVED_CLK_PERIOD;
1723 val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD);
1724 REG_WRITE(ah, AR_RTC_DERIVED_CLK, val);
1725 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1726 }
1727
Sujithf1dc5602008-10-29 10:16:30 +05301728 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1729 AR_RTC_FORCE_WAKE_ON_INT);
1730
1731 if (AR_SREV_9100(ah)) {
1732 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1733 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1734 } else {
1735 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1736 if (tmpReg &
1737 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1738 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
1739 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
1740 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1741 } else {
1742 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1743 }
1744
1745 rst_flags = AR_RTC_RC_MAC_WARM;
1746 if (type == ATH9K_RESET_COLD)
1747 rst_flags |= AR_RTC_RC_MAC_COLD;
1748 }
1749
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001750 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujithf1dc5602008-10-29 10:16:30 +05301751 udelay(50);
1752
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001753 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301754 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001755 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1756 "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301757 return false;
1758 }
1759
1760 if (!AR_SREV_9100(ah))
1761 REG_WRITE(ah, AR_RC, 0);
1762
Sujithf1dc5602008-10-29 10:16:30 +05301763 if (AR_SREV_9100(ah))
1764 udelay(50);
1765
1766 return true;
1767}
1768
Sujithcbe61d82009-02-09 13:27:12 +05301769static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301770{
1771 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1772 AR_RTC_FORCE_WAKE_ON_INT);
1773
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301774 if (!AR_SREV_9100(ah))
1775 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1776
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001777 REG_WRITE(ah, AR_RTC_RESET, 0);
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301778 udelay(2);
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301779
1780 if (!AR_SREV_9100(ah))
1781 REG_WRITE(ah, AR_RC, 0);
1782
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001783 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301784
1785 if (!ath9k_hw_wait(ah,
1786 AR_RTC_STATUS,
1787 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301788 AR_RTC_STATUS_ON,
1789 AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001790 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1791 "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301792 return false;
1793 }
1794
1795 ath9k_hw_read_revisions(ah);
1796
1797 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1798}
1799
Sujithcbe61d82009-02-09 13:27:12 +05301800static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301801{
1802 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1803 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1804
1805 switch (type) {
1806 case ATH9K_RESET_POWER_ON:
1807 return ath9k_hw_set_reset_power_on(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301808 case ATH9K_RESET_WARM:
1809 case ATH9K_RESET_COLD:
1810 return ath9k_hw_set_reset(ah, type);
Sujithf1dc5602008-10-29 10:16:30 +05301811 default:
1812 return false;
1813 }
1814}
1815
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001816static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301817{
1818 u32 phymode;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301819 u32 enableDacFifo = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301820
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301821 if (AR_SREV_9285_10_OR_LATER(ah))
1822 enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) &
1823 AR_PHY_FC_ENABLE_DAC_FIFO);
1824
Sujithf1dc5602008-10-29 10:16:30 +05301825 phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301826 | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo;
Sujithf1dc5602008-10-29 10:16:30 +05301827
1828 if (IS_CHAN_HT40(chan)) {
1829 phymode |= AR_PHY_FC_DYN2040_EN;
1830
1831 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
1832 (chan->chanmode == CHANNEL_G_HT40PLUS))
1833 phymode |= AR_PHY_FC_DYN2040_PRI_CH;
1834
Sujithf1dc5602008-10-29 10:16:30 +05301835 }
1836 REG_WRITE(ah, AR_PHY_TURBO, phymode);
1837
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001838 ath9k_hw_set11nmac2040(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301839
1840 REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
1841 REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
1842}
1843
Sujithcbe61d82009-02-09 13:27:12 +05301844static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301845 struct ath9k_channel *chan)
1846{
Vivek Natarajan42abfbe2009-09-17 09:27:59 +05301847 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) {
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301848 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
1849 return false;
1850 } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
Sujithf1dc5602008-10-29 10:16:30 +05301851 return false;
1852
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001853 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05301854 return false;
1855
Sujith2660b812009-02-09 13:27:26 +05301856 ah->chip_fullsleep = false;
Sujithf1dc5602008-10-29 10:16:30 +05301857 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301858 ath9k_hw_set_rfmode(ah, chan);
1859
1860 return true;
1861}
1862
Sujithcbe61d82009-02-09 13:27:12 +05301863static bool ath9k_hw_channel_change(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001864 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301865{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001866 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001867 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001868 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301869 u32 synthDelay, qnum;
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001870 int r;
Sujithf1dc5602008-10-29 10:16:30 +05301871
1872 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1873 if (ath9k_hw_numtxpending(ah, qnum)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001874 ath_print(common, ATH_DBG_QUEUE,
1875 "Transmit frames pending on "
1876 "queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301877 return false;
1878 }
1879 }
1880
1881 REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
1882 if (!ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
Sujith0caa7b12009-02-16 13:23:20 +05301883 AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001884 ath_print(common, ATH_DBG_FATAL,
1885 "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301886 return false;
1887 }
1888
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001889 ath9k_hw_set_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301890
Luis R. Rodrigueze68a0602009-10-19 02:33:41 -04001891 r = ah->ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001892 if (r) {
1893 ath_print(common, ATH_DBG_FATAL,
1894 "Failed to set channel\n");
1895 return false;
Sujithf1dc5602008-10-29 10:16:30 +05301896 }
1897
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001898 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001899 ath9k_regd_get_ctl(regulatory, chan),
Sujithf74df6f2009-02-09 13:27:24 +05301900 channel->max_antenna_gain * 2,
1901 channel->max_power * 2,
1902 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001903 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05301904
1905 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +05301906 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +05301907 synthDelay = (4 * synthDelay) / 22;
1908 else
1909 synthDelay /= 10;
1910
1911 udelay(synthDelay + BASE_ACTIVATE_DELAY);
1912
1913 REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
1914
1915 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1916 ath9k_hw_set_delta_slope(ah, chan);
1917
Luis R. Rodriguezae478cf2009-10-19 02:33:43 -04001918 ah->ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301919
1920 if (!chan->oneTimeCalsDone)
1921 chan->oneTimeCalsDone = true;
1922
1923 return true;
1924}
1925
Johannes Berg3b319aa2009-06-13 14:50:26 +05301926static void ath9k_enable_rfkill(struct ath_hw *ah)
1927{
1928 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
1929 AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
1930
1931 REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2,
1932 AR_GPIO_INPUT_MUX2_RFSILENT);
1933
1934 ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
1935 REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);
1936}
1937
Sujithcbe61d82009-02-09 13:27:12 +05301938int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001939 bool bChannelChange)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001940{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001941 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001942 u32 saveLedState;
Sujith2660b812009-02-09 13:27:26 +05301943 struct ath9k_channel *curchan = ah->curchan;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001944 u32 saveDefAntenna;
1945 u32 macStaId1;
Sujith46fe7822009-09-17 09:25:25 +05301946 u64 tsf = 0;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001947 int i, rx_chainmask, r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001948
Luis R. Rodriguez43c27612009-09-13 21:07:07 -07001949 ah->txchainmask = common->tx_chainmask;
1950 ah->rxchainmask = common->rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001951
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001952 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001953 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001954
Vasanthakumar Thiagarajan9ebef792009-09-17 09:26:44 +05301955 if (curchan && !ah->chip_fullsleep)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001956 ath9k_hw_getnf(ah, curchan);
1957
1958 if (bChannelChange &&
Sujith2660b812009-02-09 13:27:26 +05301959 (ah->chip_fullsleep != true) &&
1960 (ah->curchan != NULL) &&
1961 (chan->channel != ah->curchan->channel) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001962 ((chan->channelFlags & CHANNEL_ALL) ==
Sujith2660b812009-02-09 13:27:26 +05301963 (ah->curchan->channelFlags & CHANNEL_ALL)) &&
Vasanthakumar Thiagarajan0a475cc2009-09-17 09:27:10 +05301964 !(AR_SREV_9280(ah) || IS_CHAN_A_5MHZ_SPACED(chan) ||
1965 IS_CHAN_A_5MHZ_SPACED(ah->curchan))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001966
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001967 if (ath9k_hw_channel_change(ah, chan)) {
Sujith2660b812009-02-09 13:27:26 +05301968 ath9k_hw_loadnf(ah, ah->curchan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001969 ath9k_hw_start_nfcal(ah);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001970 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001971 }
1972 }
1973
1974 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
1975 if (saveDefAntenna == 0)
1976 saveDefAntenna = 1;
1977
1978 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
1979
Sujith46fe7822009-09-17 09:25:25 +05301980 /* For chips on which RTC reset is done, save TSF before it gets cleared */
1981 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1982 tsf = ath9k_hw_gettsf64(ah);
1983
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001984 saveLedState = REG_READ(ah, AR_CFG_LED) &
1985 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
1986 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
1987
1988 ath9k_hw_mark_phy_inactive(ah);
1989
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001990 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1991 REG_WRITE(ah,
1992 AR9271_RESET_POWER_DOWN_CONTROL,
1993 AR9271_RADIO_RF_RST);
1994 udelay(50);
1995 }
1996
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001997 if (!ath9k_hw_chip_reset(ah, chan)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001998 ath_print(common, ATH_DBG_FATAL, "Chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001999 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002000 }
2001
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002002 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
2003 ah->htc_reset_init = false;
2004 REG_WRITE(ah,
2005 AR9271_RESET_POWER_DOWN_CONTROL,
2006 AR9271_GATE_MAC_CTL);
2007 udelay(50);
2008 }
2009
Sujith46fe7822009-09-17 09:25:25 +05302010 /* Restore TSF */
2011 if (tsf && AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
2012 ath9k_hw_settsf64(ah, tsf);
2013
Vasanthakumar Thiagarajan369391d2009-01-21 19:24:13 +05302014 if (AR_SREV_9280_10_OR_LATER(ah))
2015 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002016
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302017 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302018 /* Enable ASYNC FIFO */
2019 REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2020 AR_MAC_PCU_ASYNC_FIFO_REG3_DATAPATH_SEL);
2021 REG_SET_BIT(ah, AR_PHY_MODE, AR_PHY_MODE_ASYNCFIFO);
2022 REG_CLR_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2023 AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
2024 REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2025 AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
2026 }
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002027 r = ath9k_hw_process_ini(ah, chan);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002028 if (r)
2029 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002030
Jouni Malinen0ced0e12009-01-08 13:32:13 +02002031 /* Setup MFP options for CCMP */
2032 if (AR_SREV_9280_20_OR_LATER(ah)) {
2033 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
2034 * frames when constructing CCMP AAD. */
2035 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
2036 0xc7ff);
2037 ah->sw_mgmt_crypto = false;
2038 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
2039 /* Disable hardware crypto for management frames */
2040 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
2041 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
2042 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
2043 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
2044 ah->sw_mgmt_crypto = true;
2045 } else
2046 ah->sw_mgmt_crypto = true;
2047
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002048 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
2049 ath9k_hw_set_delta_slope(ah, chan);
2050
Luis R. Rodriguezae478cf2009-10-19 02:33:43 -04002051 ah->ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithd6509152009-03-13 08:56:05 +05302052 ah->eep_ops->set_board_values(ah, chan);
Luis R. Rodrigueza7765822009-10-19 02:33:45 -04002053
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002054 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
2055 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002056 | macStaId1
2057 | AR_STA_ID1_RTS_USE_DEF
Sujith2660b812009-02-09 13:27:26 +05302058 | (ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302059 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Sujith2660b812009-02-09 13:27:26 +05302060 | ah->sta_id1_defaults);
2061 ath9k_hw_set_operating_mode(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002062
Luis R. Rodriguez13b81552009-09-10 17:52:45 -07002063 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002064
2065 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
2066
Luis R. Rodriguez3453ad82009-09-10 08:57:00 -07002067 ath9k_hw_write_associd(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002068
2069 REG_WRITE(ah, AR_ISR, ~0);
2070
2071 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
2072
Luis R. Rodrigueze68a0602009-10-19 02:33:41 -04002073 r = ah->ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04002074 if (r)
2075 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002076
2077 for (i = 0; i < AR_NUM_DCU; i++)
2078 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
2079
Sujith2660b812009-02-09 13:27:26 +05302080 ah->intr_txqs = 0;
2081 for (i = 0; i < ah->caps.total_queues; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002082 ath9k_hw_resettxqueue(ah, i);
2083
Sujith2660b812009-02-09 13:27:26 +05302084 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002085 ath9k_hw_init_qos(ah);
2086
Sujith2660b812009-02-09 13:27:26 +05302087 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05302088 ath9k_enable_rfkill(ah);
Johannes Berg3b319aa2009-06-13 14:50:26 +05302089
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002090 ath9k_hw_init_user_settings(ah);
2091
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302092 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302093 REG_WRITE(ah, AR_D_GBL_IFS_SIFS,
2094 AR_D_GBL_IFS_SIFS_ASYNC_FIFO_DUR);
2095 REG_WRITE(ah, AR_D_GBL_IFS_SLOT,
2096 AR_D_GBL_IFS_SLOT_ASYNC_FIFO_DUR);
2097 REG_WRITE(ah, AR_D_GBL_IFS_EIFS,
2098 AR_D_GBL_IFS_EIFS_ASYNC_FIFO_DUR);
2099
2100 REG_WRITE(ah, AR_TIME_OUT, AR_TIME_OUT_ACK_CTS_ASYNC_FIFO_DUR);
2101 REG_WRITE(ah, AR_USEC, AR_USEC_ASYNC_FIFO_DUR);
2102
2103 REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
2104 AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
2105 REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
2106 AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
2107 }
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302108 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302109 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
2110 AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
2111 }
2112
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002113 REG_WRITE(ah, AR_STA_ID1,
2114 REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
2115
2116 ath9k_hw_set_dma(ah);
2117
2118 REG_WRITE(ah, AR_OBS, 8);
2119
Sujith0ef1f162009-03-30 15:28:35 +05302120 if (ah->config.intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002121 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
2122 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
2123 }
2124
2125 ath9k_hw_init_bb(ah, chan);
2126
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002127 if (!ath9k_hw_init_cal(ah, chan))
Joe Perches6badaaf2009-06-28 09:26:32 -07002128 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002129
Sujith2660b812009-02-09 13:27:26 +05302130 rx_chainmask = ah->rxchainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002131 if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) {
2132 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
2133 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
2134 }
2135
2136 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
2137
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002138 /*
2139 * For big endian systems turn on swapping for descriptors
2140 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002141 if (AR_SREV_9100(ah)) {
2142 u32 mask;
2143 mask = REG_READ(ah, AR_CFG);
2144 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002145 ath_print(common, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05302146 "CFG Byte Swap Set 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002147 } else {
2148 mask =
2149 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
2150 REG_WRITE(ah, AR_CFG, mask);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002151 ath_print(common, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05302152 "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002153 }
2154 } else {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002155 /* Configure AR9271 target WLAN */
2156 if (AR_SREV_9271(ah))
2157 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002158#ifdef __BIG_ENDIAN
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002159 else
2160 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002161#endif
2162 }
2163
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002164 if (ah->btcoex_hw.enabled)
Vasanthakumar Thiagarajan42cc41e2009-08-26 21:08:45 +05302165 ath9k_hw_btcoex_enable(ah);
2166
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002167 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002168}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002169EXPORT_SYMBOL(ath9k_hw_reset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002170
Sujithf1dc5602008-10-29 10:16:30 +05302171/************************/
2172/* Key Cache Management */
2173/************************/
2174
Sujithcbe61d82009-02-09 13:27:12 +05302175bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002176{
Sujithf1dc5602008-10-29 10:16:30 +05302177 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002178
Sujith2660b812009-02-09 13:27:26 +05302179 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002180 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2181 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002182 return false;
2183 }
2184
Sujithf1dc5602008-10-29 10:16:30 +05302185 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002186
Sujithf1dc5602008-10-29 10:16:30 +05302187 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
2188 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
2189 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
2190 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
2191 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
2192 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
2193 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
2194 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
2195
2196 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2197 u16 micentry = entry + 64;
2198
2199 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
2200 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
2201 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
2202 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
2203
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002204 }
2205
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002206 return true;
2207}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002208EXPORT_SYMBOL(ath9k_hw_keyreset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002209
Sujithcbe61d82009-02-09 13:27:12 +05302210bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002211{
Sujithf1dc5602008-10-29 10:16:30 +05302212 u32 macHi, macLo;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002213
Sujith2660b812009-02-09 13:27:26 +05302214 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002215 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2216 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002217 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002218 }
2219
Sujithf1dc5602008-10-29 10:16:30 +05302220 if (mac != NULL) {
2221 macHi = (mac[5] << 8) | mac[4];
2222 macLo = (mac[3] << 24) |
2223 (mac[2] << 16) |
2224 (mac[1] << 8) |
2225 mac[0];
2226 macLo >>= 1;
2227 macLo |= (macHi & 1) << 31;
2228 macHi >>= 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002229 } else {
Sujithf1dc5602008-10-29 10:16:30 +05302230 macLo = macHi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002231 }
Sujithf1dc5602008-10-29 10:16:30 +05302232 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
2233 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002234
2235 return true;
2236}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002237EXPORT_SYMBOL(ath9k_hw_keysetmac);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002238
Sujithcbe61d82009-02-09 13:27:12 +05302239bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
Sujithf1dc5602008-10-29 10:16:30 +05302240 const struct ath9k_keyval *k,
Jouni Malinene0caf9e2009-03-02 18:15:53 +02002241 const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002242{
Sujith2660b812009-02-09 13:27:26 +05302243 const struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002244 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302245 u32 key0, key1, key2, key3, key4;
2246 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002247
Sujithf1dc5602008-10-29 10:16:30 +05302248 if (entry >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002249 ath_print(common, ATH_DBG_FATAL,
2250 "keycache entry %u out of range\n", entry);
Sujithf1dc5602008-10-29 10:16:30 +05302251 return false;
2252 }
2253
2254 switch (k->kv_type) {
2255 case ATH9K_CIPHER_AES_OCB:
2256 keyType = AR_KEYTABLE_TYPE_AES;
2257 break;
2258 case ATH9K_CIPHER_AES_CCM:
2259 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002260 ath_print(common, ATH_DBG_ANY,
2261 "AES-CCM not supported by mac rev 0x%x\n",
2262 ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002263 return false;
2264 }
Sujithf1dc5602008-10-29 10:16:30 +05302265 keyType = AR_KEYTABLE_TYPE_CCM;
2266 break;
2267 case ATH9K_CIPHER_TKIP:
2268 keyType = AR_KEYTABLE_TYPE_TKIP;
2269 if (ATH9K_IS_MIC_ENABLED(ah)
2270 && entry + 64 >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002271 ath_print(common, ATH_DBG_ANY,
2272 "entry %u inappropriate for TKIP\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002273 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002274 }
Sujithf1dc5602008-10-29 10:16:30 +05302275 break;
2276 case ATH9K_CIPHER_WEP:
Zhu Yie31a16d2009-05-21 21:47:03 +08002277 if (k->kv_len < WLAN_KEY_LEN_WEP40) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002278 ath_print(common, ATH_DBG_ANY,
2279 "WEP key length %u too small\n", k->kv_len);
Sujithf1dc5602008-10-29 10:16:30 +05302280 return false;
2281 }
Zhu Yie31a16d2009-05-21 21:47:03 +08002282 if (k->kv_len <= WLAN_KEY_LEN_WEP40)
Sujithf1dc5602008-10-29 10:16:30 +05302283 keyType = AR_KEYTABLE_TYPE_40;
Zhu Yie31a16d2009-05-21 21:47:03 +08002284 else if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05302285 keyType = AR_KEYTABLE_TYPE_104;
2286 else
2287 keyType = AR_KEYTABLE_TYPE_128;
2288 break;
2289 case ATH9K_CIPHER_CLR:
2290 keyType = AR_KEYTABLE_TYPE_CLR;
2291 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002292 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002293 ath_print(common, ATH_DBG_FATAL,
2294 "cipher %u not supported\n", k->kv_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002295 return false;
2296 }
Sujithf1dc5602008-10-29 10:16:30 +05302297
Jouni Malinene0caf9e2009-03-02 18:15:53 +02002298 key0 = get_unaligned_le32(k->kv_val + 0);
2299 key1 = get_unaligned_le16(k->kv_val + 4);
2300 key2 = get_unaligned_le32(k->kv_val + 6);
2301 key3 = get_unaligned_le16(k->kv_val + 10);
2302 key4 = get_unaligned_le32(k->kv_val + 12);
Zhu Yie31a16d2009-05-21 21:47:03 +08002303 if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05302304 key4 &= 0xff;
2305
Jouni Malinen672903b2009-03-02 15:06:31 +02002306 /*
2307 * Note: Key cache registers access special memory area that requires
2308 * two 32-bit writes to actually update the values in the internal
2309 * memory. Consequently, the exact order and pairs used here must be
2310 * maintained.
2311 */
2312
Sujithf1dc5602008-10-29 10:16:30 +05302313 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2314 u16 micentry = entry + 64;
2315
Jouni Malinen672903b2009-03-02 15:06:31 +02002316 /*
2317 * Write inverted key[47:0] first to avoid Michael MIC errors
2318 * on frames that could be sent or received at the same time.
2319 * The correct key will be written in the end once everything
2320 * else is ready.
2321 */
Sujithf1dc5602008-10-29 10:16:30 +05302322 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
2323 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002324
2325 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302326 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2327 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002328
2329 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302330 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2331 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
Jouni Malinen672903b2009-03-02 15:06:31 +02002332
2333 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302334 (void) ath9k_hw_keysetmac(ah, entry, mac);
2335
Sujith2660b812009-02-09 13:27:26 +05302336 if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) {
Jouni Malinen672903b2009-03-02 15:06:31 +02002337 /*
2338 * TKIP uses two key cache entries:
2339 * Michael MIC TX/RX keys in the same key cache entry
2340 * (idx = main index + 64):
2341 * key0 [31:0] = RX key [31:0]
2342 * key1 [15:0] = TX key [31:16]
2343 * key1 [31:16] = reserved
2344 * key2 [31:0] = RX key [63:32]
2345 * key3 [15:0] = TX key [15:0]
2346 * key3 [31:16] = reserved
2347 * key4 [31:0] = TX key [63:32]
2348 */
Sujithf1dc5602008-10-29 10:16:30 +05302349 u32 mic0, mic1, mic2, mic3, mic4;
2350
2351 mic0 = get_unaligned_le32(k->kv_mic + 0);
2352 mic2 = get_unaligned_le32(k->kv_mic + 4);
2353 mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
2354 mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
2355 mic4 = get_unaligned_le32(k->kv_txmic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02002356
2357 /* Write RX[31:0] and TX[31:16] */
Sujithf1dc5602008-10-29 10:16:30 +05302358 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2359 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002360
2361 /* Write RX[63:32] and TX[15:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302362 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2363 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002364
2365 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302366 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
2367 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2368 AR_KEYTABLE_TYPE_CLR);
2369
2370 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002371 /*
2372 * TKIP uses four key cache entries (two for group
2373 * keys):
2374 * Michael MIC TX/RX keys are in different key cache
2375 * entries (idx = main index + 64 for TX and
2376 * main index + 32 + 96 for RX):
2377 * key0 [31:0] = TX/RX MIC key [31:0]
2378 * key1 [31:0] = reserved
2379 * key2 [31:0] = TX/RX MIC key [63:32]
2380 * key3 [31:0] = reserved
2381 * key4 [31:0] = reserved
2382 *
2383 * Upper layer code will call this function separately
2384 * for TX and RX keys when these registers offsets are
2385 * used.
2386 */
Sujithf1dc5602008-10-29 10:16:30 +05302387 u32 mic0, mic2;
2388
2389 mic0 = get_unaligned_le32(k->kv_mic + 0);
2390 mic2 = get_unaligned_le32(k->kv_mic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02002391
2392 /* Write MIC key[31:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302393 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2394 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002395
2396 /* Write MIC key[63:32] */
Sujithf1dc5602008-10-29 10:16:30 +05302397 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2398 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002399
2400 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302401 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
2402 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2403 AR_KEYTABLE_TYPE_CLR);
2404 }
Jouni Malinen672903b2009-03-02 15:06:31 +02002405
2406 /* MAC address registers are reserved for the MIC entry */
Sujithf1dc5602008-10-29 10:16:30 +05302407 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
2408 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002409
2410 /*
2411 * Write the correct (un-inverted) key[47:0] last to enable
2412 * TKIP now that all other registers are set with correct
2413 * values.
2414 */
Sujithf1dc5602008-10-29 10:16:30 +05302415 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2416 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
2417 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002418 /* Write key[47:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302419 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2420 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002421
2422 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302423 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2424 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002425
2426 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302427 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2428 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
2429
Jouni Malinen672903b2009-03-02 15:06:31 +02002430 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302431 (void) ath9k_hw_keysetmac(ah, entry, mac);
2432 }
2433
Sujithf1dc5602008-10-29 10:16:30 +05302434 return true;
2435}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002436EXPORT_SYMBOL(ath9k_hw_set_keycache_entry);
Sujithf1dc5602008-10-29 10:16:30 +05302437
Sujithcbe61d82009-02-09 13:27:12 +05302438bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry)
Sujithf1dc5602008-10-29 10:16:30 +05302439{
Sujith2660b812009-02-09 13:27:26 +05302440 if (entry < ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05302441 u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
2442 if (val & AR_KEYTABLE_VALID)
2443 return true;
2444 }
2445 return false;
2446}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002447EXPORT_SYMBOL(ath9k_hw_keyisvalid);
Sujithf1dc5602008-10-29 10:16:30 +05302448
2449/******************************/
2450/* Power Management (Chipset) */
2451/******************************/
2452
Sujithcbe61d82009-02-09 13:27:12 +05302453static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302454{
2455 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2456 if (setChip) {
2457 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2458 AR_RTC_FORCE_WAKE_EN);
2459 if (!AR_SREV_9100(ah))
2460 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
2461
Sujith4921be82009-09-18 15:04:27 +05302462 if(!AR_SREV_5416(ah))
2463 REG_CLR_BIT(ah, (AR_RTC_RESET),
2464 AR_RTC_RESET_EN);
Sujithf1dc5602008-10-29 10:16:30 +05302465 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002466}
2467
Sujithcbe61d82009-02-09 13:27:12 +05302468static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002469{
Sujithf1dc5602008-10-29 10:16:30 +05302470 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2471 if (setChip) {
Sujith2660b812009-02-09 13:27:26 +05302472 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002473
Sujithf1dc5602008-10-29 10:16:30 +05302474 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
2475 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2476 AR_RTC_FORCE_WAKE_ON_INT);
2477 } else {
2478 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2479 AR_RTC_FORCE_WAKE_EN);
2480 }
2481 }
2482}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002483
Sujithcbe61d82009-02-09 13:27:12 +05302484static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302485{
2486 u32 val;
2487 int i;
2488
2489 if (setChip) {
2490 if ((REG_READ(ah, AR_RTC_STATUS) &
2491 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2492 if (ath9k_hw_set_reset_reg(ah,
2493 ATH9K_RESET_POWER_ON) != true) {
2494 return false;
2495 }
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05302496 ath9k_hw_init_pll(ah, NULL);
Sujithf1dc5602008-10-29 10:16:30 +05302497 }
2498 if (AR_SREV_9100(ah))
2499 REG_SET_BIT(ah, AR_RTC_RESET,
2500 AR_RTC_RESET_EN);
2501
2502 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2503 AR_RTC_FORCE_WAKE_EN);
2504 udelay(50);
2505
2506 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2507 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2508 if (val == AR_RTC_STATUS_ON)
2509 break;
2510 udelay(50);
2511 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2512 AR_RTC_FORCE_WAKE_EN);
2513 }
2514 if (i == 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002515 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2516 "Failed to wakeup in %uus\n",
2517 POWER_UP_TIME / 20);
Sujithf1dc5602008-10-29 10:16:30 +05302518 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002519 }
2520 }
2521
Sujithf1dc5602008-10-29 10:16:30 +05302522 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2523
2524 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002525}
2526
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002527bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05302528{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002529 struct ath_common *common = ath9k_hw_common(ah);
Sujithcbe61d82009-02-09 13:27:12 +05302530 int status = true, setChip = true;
Sujithf1dc5602008-10-29 10:16:30 +05302531 static const char *modes[] = {
2532 "AWAKE",
2533 "FULL-SLEEP",
2534 "NETWORK SLEEP",
2535 "UNDEFINED"
2536 };
Sujithf1dc5602008-10-29 10:16:30 +05302537
Gabor Juhoscbdec972009-07-24 17:27:22 +02002538 if (ah->power_mode == mode)
2539 return status;
2540
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002541 ath_print(common, ATH_DBG_RESET, "%s -> %s\n",
2542 modes[ah->power_mode], modes[mode]);
Sujithf1dc5602008-10-29 10:16:30 +05302543
2544 switch (mode) {
2545 case ATH9K_PM_AWAKE:
2546 status = ath9k_hw_set_power_awake(ah, setChip);
2547 break;
2548 case ATH9K_PM_FULL_SLEEP:
2549 ath9k_set_power_sleep(ah, setChip);
Sujith2660b812009-02-09 13:27:26 +05302550 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05302551 break;
2552 case ATH9K_PM_NETWORK_SLEEP:
2553 ath9k_set_power_network_sleep(ah, setChip);
2554 break;
2555 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002556 ath_print(common, ATH_DBG_FATAL,
2557 "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05302558 return false;
2559 }
Sujith2660b812009-02-09 13:27:26 +05302560 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05302561
2562 return status;
2563}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002564EXPORT_SYMBOL(ath9k_hw_setpower);
Sujithf1dc5602008-10-29 10:16:30 +05302565
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002566/*
2567 * Helper for ASPM support.
2568 *
2569 * Disable PLL when in L0s as well as receiver clock when in L1.
2570 * This power saving option must be enabled through the SerDes.
2571 *
2572 * Programming the SerDes must go through the same 288 bit serial shift
2573 * register as the other analog registers. Hence the 9 writes.
2574 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302575void ath9k_hw_configpcipowersave(struct ath_hw *ah, int restore, int power_off)
Sujithf1dc5602008-10-29 10:16:30 +05302576{
Sujithf1dc5602008-10-29 10:16:30 +05302577 u8 i;
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302578 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05302579
Sujith2660b812009-02-09 13:27:26 +05302580 if (ah->is_pciexpress != true)
Sujithf1dc5602008-10-29 10:16:30 +05302581 return;
2582
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002583 /* Do not touch SerDes registers */
Sujith2660b812009-02-09 13:27:26 +05302584 if (ah->config.pcie_powersave_enable == 2)
Sujithf1dc5602008-10-29 10:16:30 +05302585 return;
2586
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002587 /* Nothing to do on restore for 11N */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302588 if (!restore) {
2589 if (AR_SREV_9280_20_OR_LATER(ah)) {
2590 /*
2591 * AR9280 2.0 or later chips use SerDes values from the
2592 * initvals.h initialized depending on chipset during
2593 * ath9k_hw_init()
2594 */
2595 for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
2596 REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
2597 INI_RA(&ah->iniPcieSerdes, i, 1));
2598 }
2599 } else if (AR_SREV_9280(ah) &&
2600 (ah->hw_version.macRev == AR_SREV_REVISION_9280_10)) {
2601 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
2602 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
Sujithf1dc5602008-10-29 10:16:30 +05302603
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302604 /* RX shut off when elecidle is asserted */
2605 REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
2606 REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
2607 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
2608
2609 /* Shut off CLKREQ active in L1 */
2610 if (ah->config.pcie_clock_req)
2611 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
2612 else
2613 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
2614
2615 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2616 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2617 REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
2618
2619 /* Load the new settings */
2620 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
2621
2622 } else {
2623 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
2624 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
2625
2626 /* RX shut off when elecidle is asserted */
2627 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
2628 REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
2629 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
2630
2631 /*
2632 * Ignore ah->ah_config.pcie_clock_req setting for
2633 * pre-AR9280 11n
2634 */
2635 REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
2636
2637 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2638 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2639 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
2640
2641 /* Load the new settings */
2642 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
Sujithf1dc5602008-10-29 10:16:30 +05302643 }
Sujithf1dc5602008-10-29 10:16:30 +05302644
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302645 udelay(1000);
Sujithf1dc5602008-10-29 10:16:30 +05302646
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302647 /* set bit 19 to allow forcing of pcie core into L1 state */
2648 REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
Sujithf1dc5602008-10-29 10:16:30 +05302649
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302650 /* Several PCIe massages to ensure proper behaviour */
2651 if (ah->config.pcie_waen) {
2652 val = ah->config.pcie_waen;
2653 if (!power_off)
2654 val &= (~AR_WA_D3_L1_DISABLE);
2655 } else {
2656 if (AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
2657 AR_SREV_9287(ah)) {
2658 val = AR9285_WA_DEFAULT;
2659 if (!power_off)
2660 val &= (~AR_WA_D3_L1_DISABLE);
2661 } else if (AR_SREV_9280(ah)) {
2662 /*
2663 * On AR9280 chips bit 22 of 0x4004 needs to be
2664 * set otherwise card may disappear.
2665 */
2666 val = AR9280_WA_DEFAULT;
2667 if (!power_off)
2668 val &= (~AR_WA_D3_L1_DISABLE);
2669 } else
2670 val = AR_WA_DEFAULT;
2671 }
Sujithf1dc5602008-10-29 10:16:30 +05302672
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302673 REG_WRITE(ah, AR_WA, val);
Sujithf1dc5602008-10-29 10:16:30 +05302674 }
2675
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302676 if (power_off) {
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002677 /*
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302678 * Set PCIe workaround bits
2679 * bit 14 in WA register (disable L1) should only
2680 * be set when device enters D3 and be cleared
2681 * when device comes back to D0.
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002682 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302683 if (ah->config.pcie_waen) {
2684 if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE)
2685 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
2686 } else {
2687 if (((AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
2688 AR_SREV_9287(ah)) &&
2689 (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)) ||
2690 (AR_SREV_9280(ah) &&
2691 (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE))) {
2692 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
2693 }
2694 }
Sujithf1dc5602008-10-29 10:16:30 +05302695 }
2696}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002697EXPORT_SYMBOL(ath9k_hw_configpcipowersave);
Sujithf1dc5602008-10-29 10:16:30 +05302698
2699/**********************/
2700/* Interrupt Handling */
2701/**********************/
2702
Sujithcbe61d82009-02-09 13:27:12 +05302703bool ath9k_hw_intrpend(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002704{
2705 u32 host_isr;
2706
2707 if (AR_SREV_9100(ah))
2708 return true;
2709
2710 host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
2711 if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
2712 return true;
2713
2714 host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
2715 if ((host_isr & AR_INTR_SYNC_DEFAULT)
2716 && (host_isr != AR_INTR_SPURIOUS))
2717 return true;
2718
2719 return false;
2720}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002721EXPORT_SYMBOL(ath9k_hw_intrpend);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002722
Sujithcbe61d82009-02-09 13:27:12 +05302723bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002724{
2725 u32 isr = 0;
2726 u32 mask2 = 0;
Sujith2660b812009-02-09 13:27:26 +05302727 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002728 u32 sync_cause = 0;
2729 bool fatal_int = false;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002730 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002731
2732 if (!AR_SREV_9100(ah)) {
2733 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
2734 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
2735 == AR_RTC_STATUS_ON) {
2736 isr = REG_READ(ah, AR_ISR);
2737 }
2738 }
2739
Sujithf1dc5602008-10-29 10:16:30 +05302740 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
2741 AR_INTR_SYNC_DEFAULT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002742
2743 *masked = 0;
2744
2745 if (!isr && !sync_cause)
2746 return false;
2747 } else {
2748 *masked = 0;
2749 isr = REG_READ(ah, AR_ISR);
2750 }
2751
2752 if (isr) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002753 if (isr & AR_ISR_BCNMISC) {
2754 u32 isr2;
2755 isr2 = REG_READ(ah, AR_ISR_S2);
2756 if (isr2 & AR_ISR_S2_TIM)
2757 mask2 |= ATH9K_INT_TIM;
2758 if (isr2 & AR_ISR_S2_DTIM)
2759 mask2 |= ATH9K_INT_DTIM;
2760 if (isr2 & AR_ISR_S2_DTIMSYNC)
2761 mask2 |= ATH9K_INT_DTIMSYNC;
2762 if (isr2 & (AR_ISR_S2_CABEND))
2763 mask2 |= ATH9K_INT_CABEND;
2764 if (isr2 & AR_ISR_S2_GTT)
2765 mask2 |= ATH9K_INT_GTT;
2766 if (isr2 & AR_ISR_S2_CST)
2767 mask2 |= ATH9K_INT_CST;
Sujith4af9cf42009-02-12 10:06:47 +05302768 if (isr2 & AR_ISR_S2_TSFOOR)
2769 mask2 |= ATH9K_INT_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002770 }
2771
2772 isr = REG_READ(ah, AR_ISR_RAC);
2773 if (isr == 0xffffffff) {
2774 *masked = 0;
2775 return false;
2776 }
2777
2778 *masked = isr & ATH9K_INT_COMMON;
2779
Sujith0ef1f162009-03-30 15:28:35 +05302780 if (ah->config.intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002781 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
2782 *masked |= ATH9K_INT_RX;
2783 }
2784
2785 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
2786 *masked |= ATH9K_INT_RX;
2787 if (isr &
2788 (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
2789 AR_ISR_TXEOL)) {
2790 u32 s0_s, s1_s;
2791
2792 *masked |= ATH9K_INT_TX;
2793
2794 s0_s = REG_READ(ah, AR_ISR_S0_S);
Sujith2660b812009-02-09 13:27:26 +05302795 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
2796 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002797
2798 s1_s = REG_READ(ah, AR_ISR_S1_S);
Sujith2660b812009-02-09 13:27:26 +05302799 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
2800 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002801 }
2802
2803 if (isr & AR_ISR_RXORN) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002804 ath_print(common, ATH_DBG_INTERRUPT,
2805 "receive FIFO overrun interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002806 }
2807
2808 if (!AR_SREV_9100(ah)) {
Sujith60b67f52008-08-07 10:52:38 +05302809 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002810 u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
2811 if (isr5 & AR_ISR_S5_TIM_TIMER)
2812 *masked |= ATH9K_INT_TIM_TIMER;
2813 }
2814 }
2815
2816 *masked |= mask2;
2817 }
Sujithf1dc5602008-10-29 10:16:30 +05302818
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002819 if (AR_SREV_9100(ah))
2820 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302821
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302822 if (isr & AR_ISR_GENTMR) {
2823 u32 s5_s;
2824
2825 s5_s = REG_READ(ah, AR_ISR_S5_S);
2826 if (isr & AR_ISR_GENTMR) {
2827 ah->intr_gen_timer_trigger =
2828 MS(s5_s, AR_ISR_S5_GENTIMER_TRIG);
2829
2830 ah->intr_gen_timer_thresh =
2831 MS(s5_s, AR_ISR_S5_GENTIMER_THRESH);
2832
2833 if (ah->intr_gen_timer_trigger)
2834 *masked |= ATH9K_INT_GENTIMER;
2835
2836 }
2837 }
2838
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002839 if (sync_cause) {
2840 fatal_int =
2841 (sync_cause &
2842 (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
2843 ? true : false;
2844
2845 if (fatal_int) {
2846 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002847 ath_print(common, ATH_DBG_ANY,
2848 "received PCI FATAL interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002849 }
2850 if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002851 ath_print(common, ATH_DBG_ANY,
2852 "received PCI PERR interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002853 }
Steven Luoa89bff92009-04-12 02:57:54 -07002854 *masked |= ATH9K_INT_FATAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002855 }
2856 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002857 ath_print(common, ATH_DBG_INTERRUPT,
2858 "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002859 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
2860 REG_WRITE(ah, AR_RC, 0);
2861 *masked |= ATH9K_INT_FATAL;
2862 }
2863 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002864 ath_print(common, ATH_DBG_INTERRUPT,
2865 "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002866 }
2867
2868 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
2869 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
2870 }
Sujithf1dc5602008-10-29 10:16:30 +05302871
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002872 return true;
2873}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002874EXPORT_SYMBOL(ath9k_hw_getisr);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002875
Sujithcbe61d82009-02-09 13:27:12 +05302876enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002877{
Sujith2660b812009-02-09 13:27:26 +05302878 u32 omask = ah->mask_reg;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002879 u32 mask, mask2;
Sujith2660b812009-02-09 13:27:26 +05302880 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002881 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002882
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002883 ath_print(common, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002884
2885 if (omask & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002886 ath_print(common, ATH_DBG_INTERRUPT, "disable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002887 REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
2888 (void) REG_READ(ah, AR_IER);
2889 if (!AR_SREV_9100(ah)) {
2890 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
2891 (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
2892
2893 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
2894 (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
2895 }
2896 }
2897
2898 mask = ints & ATH9K_INT_COMMON;
2899 mask2 = 0;
2900
2901 if (ints & ATH9K_INT_TX) {
Sujith2660b812009-02-09 13:27:26 +05302902 if (ah->txok_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002903 mask |= AR_IMR_TXOK;
Sujith2660b812009-02-09 13:27:26 +05302904 if (ah->txdesc_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002905 mask |= AR_IMR_TXDESC;
Sujith2660b812009-02-09 13:27:26 +05302906 if (ah->txerr_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002907 mask |= AR_IMR_TXERR;
Sujith2660b812009-02-09 13:27:26 +05302908 if (ah->txeol_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002909 mask |= AR_IMR_TXEOL;
2910 }
2911 if (ints & ATH9K_INT_RX) {
2912 mask |= AR_IMR_RXERR;
Sujith0ef1f162009-03-30 15:28:35 +05302913 if (ah->config.intr_mitigation)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002914 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
2915 else
2916 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
Sujith60b67f52008-08-07 10:52:38 +05302917 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002918 mask |= AR_IMR_GENTMR;
2919 }
2920
2921 if (ints & (ATH9K_INT_BMISC)) {
2922 mask |= AR_IMR_BCNMISC;
2923 if (ints & ATH9K_INT_TIM)
2924 mask2 |= AR_IMR_S2_TIM;
2925 if (ints & ATH9K_INT_DTIM)
2926 mask2 |= AR_IMR_S2_DTIM;
2927 if (ints & ATH9K_INT_DTIMSYNC)
2928 mask2 |= AR_IMR_S2_DTIMSYNC;
2929 if (ints & ATH9K_INT_CABEND)
Sujith4af9cf42009-02-12 10:06:47 +05302930 mask2 |= AR_IMR_S2_CABEND;
2931 if (ints & ATH9K_INT_TSFOOR)
2932 mask2 |= AR_IMR_S2_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002933 }
2934
2935 if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
2936 mask |= AR_IMR_BCNMISC;
2937 if (ints & ATH9K_INT_GTT)
2938 mask2 |= AR_IMR_S2_GTT;
2939 if (ints & ATH9K_INT_CST)
2940 mask2 |= AR_IMR_S2_CST;
2941 }
2942
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002943 ath_print(common, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002944 REG_WRITE(ah, AR_IMR, mask);
2945 mask = REG_READ(ah, AR_IMR_S2) & ~(AR_IMR_S2_TIM |
2946 AR_IMR_S2_DTIM |
2947 AR_IMR_S2_DTIMSYNC |
2948 AR_IMR_S2_CABEND |
2949 AR_IMR_S2_CABTO |
2950 AR_IMR_S2_TSFOOR |
2951 AR_IMR_S2_GTT | AR_IMR_S2_CST);
2952 REG_WRITE(ah, AR_IMR_S2, mask | mask2);
Sujith2660b812009-02-09 13:27:26 +05302953 ah->mask_reg = ints;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002954
Sujith60b67f52008-08-07 10:52:38 +05302955 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002956 if (ints & ATH9K_INT_TIM_TIMER)
2957 REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
2958 else
2959 REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
2960 }
2961
2962 if (ints & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002963 ath_print(common, ATH_DBG_INTERRUPT, "enable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002964 REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
2965 if (!AR_SREV_9100(ah)) {
2966 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
2967 AR_INTR_MAC_IRQ);
2968 REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
2969
2970
2971 REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
2972 AR_INTR_SYNC_DEFAULT);
2973 REG_WRITE(ah, AR_INTR_SYNC_MASK,
2974 AR_INTR_SYNC_DEFAULT);
2975 }
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002976 ath_print(common, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
2977 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002978 }
2979
2980 return omask;
2981}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002982EXPORT_SYMBOL(ath9k_hw_set_interrupts);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002983
Sujithf1dc5602008-10-29 10:16:30 +05302984/*******************/
2985/* Beacon Handling */
2986/*******************/
2987
Sujithcbe61d82009-02-09 13:27:12 +05302988void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002989{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002990 int flags = 0;
2991
Sujith2660b812009-02-09 13:27:26 +05302992 ah->beacon_interval = beacon_period;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002993
Sujith2660b812009-02-09 13:27:26 +05302994 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08002995 case NL80211_IFTYPE_STATION:
2996 case NL80211_IFTYPE_MONITOR:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002997 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
2998 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
2999 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
3000 flags |= AR_TBTT_TIMER_EN;
3001 break;
Colin McCabed97809d2008-12-01 13:38:55 -08003002 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04003003 case NL80211_IFTYPE_MESH_POINT:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003004 REG_SET_BIT(ah, AR_TXCFG,
3005 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
3006 REG_WRITE(ah, AR_NEXT_NDP_TIMER,
3007 TU_TO_USEC(next_beacon +
Sujith2660b812009-02-09 13:27:26 +05303008 (ah->atim_window ? ah->
3009 atim_window : 1)));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003010 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08003011 case NL80211_IFTYPE_AP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003012 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3013 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
3014 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05303015 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05303016 dma_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003017 REG_WRITE(ah, AR_NEXT_SWBA,
3018 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05303019 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05303020 sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003021 flags |=
3022 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
3023 break;
Colin McCabed97809d2008-12-01 13:38:55 -08003024 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003025 ath_print(ath9k_hw_common(ah), ATH_DBG_BEACON,
3026 "%s: unsupported opmode: %d\n",
3027 __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08003028 return;
3029 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003030 }
3031
3032 REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3033 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3034 REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
3035 REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
3036
3037 beacon_period &= ~ATH9K_BEACON_ENA;
3038 if (beacon_period & ATH9K_BEACON_RESET_TSF) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003039 ath9k_hw_reset_tsf(ah);
3040 }
3041
3042 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
3043}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003044EXPORT_SYMBOL(ath9k_hw_beaconinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003045
Sujithcbe61d82009-02-09 13:27:12 +05303046void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303047 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003048{
3049 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05303050 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003051 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003052
3053 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
3054
3055 REG_WRITE(ah, AR_BEACON_PERIOD,
3056 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3057 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
3058 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3059
3060 REG_RMW_FIELD(ah, AR_RSSI_THR,
3061 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
3062
3063 beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
3064
3065 if (bs->bs_sleepduration > beaconintval)
3066 beaconintval = bs->bs_sleepduration;
3067
3068 dtimperiod = bs->bs_dtimperiod;
3069 if (bs->bs_sleepduration > dtimperiod)
3070 dtimperiod = bs->bs_sleepduration;
3071
3072 if (beaconintval == dtimperiod)
3073 nextTbtt = bs->bs_nextdtim;
3074 else
3075 nextTbtt = bs->bs_nexttbtt;
3076
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003077 ath_print(common, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
3078 ath_print(common, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
3079 ath_print(common, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
3080 ath_print(common, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003081
3082 REG_WRITE(ah, AR_NEXT_DTIM,
3083 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
3084 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
3085
3086 REG_WRITE(ah, AR_SLEEP1,
3087 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
3088 | AR_SLEEP1_ASSUME_DTIM);
3089
Sujith60b67f52008-08-07 10:52:38 +05303090 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003091 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
3092 else
3093 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
3094
3095 REG_WRITE(ah, AR_SLEEP2,
3096 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
3097
3098 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
3099 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
3100
3101 REG_SET_BIT(ah, AR_TIMER_MODE,
3102 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
3103 AR_DTIM_TIMER_EN);
3104
Sujith4af9cf42009-02-12 10:06:47 +05303105 /* TSF Out of Range Threshold */
3106 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003107}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003108EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003109
Sujithf1dc5602008-10-29 10:16:30 +05303110/*******************/
3111/* HW Capabilities */
3112/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003113
Sujitheef7a572009-03-30 15:28:28 +05303114void ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003115{
Sujith2660b812009-02-09 13:27:26 +05303116 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003117 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003118 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003119 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003120
Sujithf1dc5602008-10-29 10:16:30 +05303121 u16 capField = 0, eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003122
Sujithf74df6f2009-02-09 13:27:24 +05303123 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003124 regulatory->current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303125
Sujithf74df6f2009-02-09 13:27:24 +05303126 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
Sujithfec0de12009-02-12 10:06:43 +05303127 if (AR_SREV_9285_10_OR_LATER(ah))
3128 eeval |= AR9285_RDEXT_DEFAULT;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003129 regulatory->current_rd_ext = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303130
Sujithf74df6f2009-02-09 13:27:24 +05303131 capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
Sujithf1dc5602008-10-29 10:16:30 +05303132
Sujith2660b812009-02-09 13:27:26 +05303133 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05303134 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003135 if (regulatory->current_rd == 0x64 ||
3136 regulatory->current_rd == 0x65)
3137 regulatory->current_rd += 5;
3138 else if (regulatory->current_rd == 0x41)
3139 regulatory->current_rd = 0x43;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003140 ath_print(common, ATH_DBG_REGULATORY,
3141 "regdomain mapped to 0x%x\n", regulatory->current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003142 }
Sujithdc2222a2008-08-14 13:26:55 +05303143
Sujithf74df6f2009-02-09 13:27:24 +05303144 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Sujithf1dc5602008-10-29 10:16:30 +05303145 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003146
Sujithf1dc5602008-10-29 10:16:30 +05303147 if (eeval & AR5416_OPFLAGS_11A) {
3148 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303149 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303150 if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
3151 set_bit(ATH9K_MODE_11NA_HT20,
3152 pCap->wireless_modes);
3153 if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
3154 set_bit(ATH9K_MODE_11NA_HT40PLUS,
3155 pCap->wireless_modes);
3156 set_bit(ATH9K_MODE_11NA_HT40MINUS,
3157 pCap->wireless_modes);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003158 }
3159 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003160 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003161
Sujithf1dc5602008-10-29 10:16:30 +05303162 if (eeval & AR5416_OPFLAGS_11G) {
Sujithf1dc5602008-10-29 10:16:30 +05303163 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303164 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303165 if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
3166 set_bit(ATH9K_MODE_11NG_HT20,
3167 pCap->wireless_modes);
3168 if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
3169 set_bit(ATH9K_MODE_11NG_HT40PLUS,
3170 pCap->wireless_modes);
3171 set_bit(ATH9K_MODE_11NG_HT40MINUS,
3172 pCap->wireless_modes);
3173 }
3174 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003175 }
Sujithf1dc5602008-10-29 10:16:30 +05303176
Sujithf74df6f2009-02-09 13:27:24 +05303177 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003178 /*
3179 * For AR9271 we will temporarilly uses the rx chainmax as read from
3180 * the EEPROM.
3181 */
Sujith8147f5d2009-02-20 15:13:23 +05303182 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003183 !(eeval & AR5416_OPFLAGS_11A) &&
3184 !(AR_SREV_9271(ah)))
3185 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
Sujith8147f5d2009-02-20 15:13:23 +05303186 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
3187 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003188 /* Use rx_chainmask from EEPROM. */
Sujith8147f5d2009-02-20 15:13:23 +05303189 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05303190
Sujithd535a422009-02-09 13:27:06 +05303191 if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0)))
Sujith2660b812009-02-09 13:27:26 +05303192 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05303193
3194 pCap->low_2ghz_chan = 2312;
3195 pCap->high_2ghz_chan = 2732;
3196
3197 pCap->low_5ghz_chan = 4920;
3198 pCap->high_5ghz_chan = 6100;
3199
3200 pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
3201 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
3202 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
3203
3204 pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
3205 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
3206 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
3207
Sujith2660b812009-02-09 13:27:26 +05303208 if (ah->config.ht_enable)
Sujithf1dc5602008-10-29 10:16:30 +05303209 pCap->hw_caps |= ATH9K_HW_CAP_HT;
3210 else
3211 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
3212
3213 pCap->hw_caps |= ATH9K_HW_CAP_GTT;
3214 pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
3215 pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
3216 pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
3217
3218 if (capField & AR_EEPROM_EEPCAP_MAXQCU)
3219 pCap->total_queues =
3220 MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
3221 else
3222 pCap->total_queues = ATH9K_NUM_TX_QUEUES;
3223
3224 if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
3225 pCap->keycache_size =
3226 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
3227 else
3228 pCap->keycache_size = AR_KEYTABLE_SIZE;
3229
3230 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
Sujithf1dc5602008-10-29 10:16:30 +05303231 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
3232
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303233 if (AR_SREV_9285_10_OR_LATER(ah))
3234 pCap->num_gpio_pins = AR9285_NUM_GPIO;
3235 else if (AR_SREV_9280_10_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303236 pCap->num_gpio_pins = AR928X_NUM_GPIO;
3237 else
3238 pCap->num_gpio_pins = AR_NUM_GPIO;
3239
Sujithf1dc5602008-10-29 10:16:30 +05303240 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
3241 pCap->hw_caps |= ATH9K_HW_CAP_CST;
3242 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
3243 } else {
3244 pCap->rts_aggr_limit = (8 * 1024);
3245 }
3246
3247 pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
3248
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05303249#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05303250 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
3251 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
3252 ah->rfkill_gpio =
3253 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
3254 ah->rfkill_polarity =
3255 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05303256
3257 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
3258 }
3259#endif
3260
Vivek Natarajana3ca95fb2009-09-17 09:29:07 +05303261 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
Sujithf1dc5602008-10-29 10:16:30 +05303262
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05303263 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303264 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
3265 else
3266 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
3267
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003268 if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) {
Sujithf1dc5602008-10-29 10:16:30 +05303269 pCap->reg_cap =
3270 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3271 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
3272 AR_EEPROM_EEREGCAP_EN_KK_U2 |
3273 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
3274 } else {
3275 pCap->reg_cap =
3276 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3277 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
3278 }
3279
Senthil Balasubramanianebb90cf2009-09-18 15:07:33 +05303280 /* Advertise midband for AR5416 with FCC midband set in eeprom */
3281 if (regulatory->current_rd_ext & (1 << REG_EXT_FCC_MIDBAND) &&
3282 AR_SREV_5416(ah))
3283 pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
Sujithf1dc5602008-10-29 10:16:30 +05303284
3285 pCap->num_antcfg_5ghz =
Sujithf74df6f2009-02-09 13:27:24 +05303286 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303287 pCap->num_antcfg_2ghz =
Sujithf74df6f2009-02-09 13:27:24 +05303288 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303289
Vasanthakumar Thiagarajanfe129462009-09-09 15:25:50 +05303290 if (AR_SREV_9280_10_OR_LATER(ah) &&
Luis R. Rodrigueza36cfbc2009-09-09 16:05:32 -07003291 ath9k_hw_btcoex_supported(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003292 btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO;
3293 btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO;
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05303294
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303295 if (AR_SREV_9285(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003296 btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
3297 btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303298 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003299 btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303300 }
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05303301 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003302 btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE;
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303303 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003304}
3305
Sujithcbe61d82009-02-09 13:27:12 +05303306bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303307 u32 capability, u32 *result)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003308{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003309 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05303310 switch (type) {
3311 case ATH9K_CAP_CIPHER:
3312 switch (capability) {
3313 case ATH9K_CIPHER_AES_CCM:
3314 case ATH9K_CIPHER_AES_OCB:
3315 case ATH9K_CIPHER_TKIP:
3316 case ATH9K_CIPHER_WEP:
3317 case ATH9K_CIPHER_MIC:
3318 case ATH9K_CIPHER_CLR:
3319 return true;
3320 default:
3321 return false;
3322 }
3323 case ATH9K_CAP_TKIP_MIC:
3324 switch (capability) {
3325 case 0:
3326 return true;
3327 case 1:
Sujith2660b812009-02-09 13:27:26 +05303328 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303329 AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
3330 false;
3331 }
3332 case ATH9K_CAP_TKIP_SPLIT:
Sujith2660b812009-02-09 13:27:26 +05303333 return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ?
Sujithf1dc5602008-10-29 10:16:30 +05303334 false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303335 case ATH9K_CAP_DIVERSITY:
3336 return (REG_READ(ah, AR_PHY_CCK_DETECT) &
3337 AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV) ?
3338 true : false;
Sujithf1dc5602008-10-29 10:16:30 +05303339 case ATH9K_CAP_MCAST_KEYSRCH:
3340 switch (capability) {
3341 case 0:
3342 return true;
3343 case 1:
3344 if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
3345 return false;
3346 } else {
Sujith2660b812009-02-09 13:27:26 +05303347 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303348 AR_STA_ID1_MCAST_KSRCH) ? true :
3349 false;
3350 }
3351 }
3352 return false;
Sujithf1dc5602008-10-29 10:16:30 +05303353 case ATH9K_CAP_TXPOW:
3354 switch (capability) {
3355 case 0:
3356 return 0;
3357 case 1:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003358 *result = regulatory->power_limit;
Sujithf1dc5602008-10-29 10:16:30 +05303359 return 0;
3360 case 2:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003361 *result = regulatory->max_power_level;
Sujithf1dc5602008-10-29 10:16:30 +05303362 return 0;
3363 case 3:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003364 *result = regulatory->tp_scale;
Sujithf1dc5602008-10-29 10:16:30 +05303365 return 0;
3366 }
3367 return false;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05303368 case ATH9K_CAP_DS:
3369 return (AR_SREV_9280_20_OR_LATER(ah) &&
3370 (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1))
3371 ? false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303372 default:
3373 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003374 }
Sujithf1dc5602008-10-29 10:16:30 +05303375}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003376EXPORT_SYMBOL(ath9k_hw_getcapability);
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003377
Sujithcbe61d82009-02-09 13:27:12 +05303378bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303379 u32 capability, u32 setting, int *status)
3380{
Sujithf1dc5602008-10-29 10:16:30 +05303381 u32 v;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003382
Sujithf1dc5602008-10-29 10:16:30 +05303383 switch (type) {
3384 case ATH9K_CAP_TKIP_MIC:
3385 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303386 ah->sta_id1_defaults |=
Sujithf1dc5602008-10-29 10:16:30 +05303387 AR_STA_ID1_CRPT_MIC_ENABLE;
3388 else
Sujith2660b812009-02-09 13:27:26 +05303389 ah->sta_id1_defaults &=
Sujithf1dc5602008-10-29 10:16:30 +05303390 ~AR_STA_ID1_CRPT_MIC_ENABLE;
3391 return true;
3392 case ATH9K_CAP_DIVERSITY:
3393 v = REG_READ(ah, AR_PHY_CCK_DETECT);
3394 if (setting)
3395 v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3396 else
3397 v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3398 REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
3399 return true;
3400 case ATH9K_CAP_MCAST_KEYSRCH:
3401 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303402 ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303403 else
Sujith2660b812009-02-09 13:27:26 +05303404 ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303405 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303406 default:
3407 return false;
3408 }
3409}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003410EXPORT_SYMBOL(ath9k_hw_setcapability);
Sujithf1dc5602008-10-29 10:16:30 +05303411
3412/****************************/
3413/* GPIO / RFKILL / Antennae */
3414/****************************/
3415
Sujithcbe61d82009-02-09 13:27:12 +05303416static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303417 u32 gpio, u32 type)
3418{
3419 int addr;
3420 u32 gpio_shift, tmp;
3421
3422 if (gpio > 11)
3423 addr = AR_GPIO_OUTPUT_MUX3;
3424 else if (gpio > 5)
3425 addr = AR_GPIO_OUTPUT_MUX2;
3426 else
3427 addr = AR_GPIO_OUTPUT_MUX1;
3428
3429 gpio_shift = (gpio % 6) * 5;
3430
3431 if (AR_SREV_9280_20_OR_LATER(ah)
3432 || (addr != AR_GPIO_OUTPUT_MUX1)) {
3433 REG_RMW(ah, addr, (type << gpio_shift),
3434 (0x1f << gpio_shift));
3435 } else {
3436 tmp = REG_READ(ah, addr);
3437 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
3438 tmp &= ~(0x1f << gpio_shift);
3439 tmp |= (type << gpio_shift);
3440 REG_WRITE(ah, addr, tmp);
3441 }
3442}
3443
Sujithcbe61d82009-02-09 13:27:12 +05303444void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303445{
3446 u32 gpio_shift;
3447
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07003448 BUG_ON(gpio >= ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05303449
3450 gpio_shift = gpio << 1;
3451
3452 REG_RMW(ah,
3453 AR_GPIO_OE_OUT,
3454 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
3455 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3456}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003457EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
Sujithf1dc5602008-10-29 10:16:30 +05303458
Sujithcbe61d82009-02-09 13:27:12 +05303459u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303460{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303461#define MS_REG_READ(x, y) \
3462 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
3463
Sujith2660b812009-02-09 13:27:26 +05303464 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05303465 return 0xffffffff;
3466
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05303467 if (AR_SREV_9287_10_OR_LATER(ah))
3468 return MS_REG_READ(AR9287, gpio) != 0;
3469 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303470 return MS_REG_READ(AR9285, gpio) != 0;
3471 else if (AR_SREV_9280_10_OR_LATER(ah))
3472 return MS_REG_READ(AR928X, gpio) != 0;
3473 else
3474 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05303475}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003476EXPORT_SYMBOL(ath9k_hw_gpio_get);
Sujithf1dc5602008-10-29 10:16:30 +05303477
Sujithcbe61d82009-02-09 13:27:12 +05303478void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05303479 u32 ah_signal_type)
3480{
3481 u32 gpio_shift;
3482
3483 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
3484
3485 gpio_shift = 2 * gpio;
3486
3487 REG_RMW(ah,
3488 AR_GPIO_OE_OUT,
3489 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
3490 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3491}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003492EXPORT_SYMBOL(ath9k_hw_cfg_output);
Sujithf1dc5602008-10-29 10:16:30 +05303493
Sujithcbe61d82009-02-09 13:27:12 +05303494void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05303495{
3496 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
3497 AR_GPIO_BIT(gpio));
3498}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003499EXPORT_SYMBOL(ath9k_hw_set_gpio);
Sujithf1dc5602008-10-29 10:16:30 +05303500
Sujithcbe61d82009-02-09 13:27:12 +05303501u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303502{
3503 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
3504}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003505EXPORT_SYMBOL(ath9k_hw_getdefantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303506
Sujithcbe61d82009-02-09 13:27:12 +05303507void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05303508{
3509 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
3510}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003511EXPORT_SYMBOL(ath9k_hw_setantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303512
Sujithf1dc5602008-10-29 10:16:30 +05303513/*********************/
3514/* General Operation */
3515/*********************/
3516
Sujithcbe61d82009-02-09 13:27:12 +05303517u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303518{
3519 u32 bits = REG_READ(ah, AR_RX_FILTER);
3520 u32 phybits = REG_READ(ah, AR_PHY_ERR);
3521
3522 if (phybits & AR_PHY_ERR_RADAR)
3523 bits |= ATH9K_RX_FILTER_PHYRADAR;
3524 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
3525 bits |= ATH9K_RX_FILTER_PHYERR;
3526
3527 return bits;
3528}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003529EXPORT_SYMBOL(ath9k_hw_getrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303530
Sujithcbe61d82009-02-09 13:27:12 +05303531void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05303532{
3533 u32 phybits;
3534
Sujith7ea310b2009-09-03 12:08:43 +05303535 REG_WRITE(ah, AR_RX_FILTER, bits);
3536
Sujithf1dc5602008-10-29 10:16:30 +05303537 phybits = 0;
3538 if (bits & ATH9K_RX_FILTER_PHYRADAR)
3539 phybits |= AR_PHY_ERR_RADAR;
3540 if (bits & ATH9K_RX_FILTER_PHYERR)
3541 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
3542 REG_WRITE(ah, AR_PHY_ERR, phybits);
3543
3544 if (phybits)
3545 REG_WRITE(ah, AR_RXCFG,
3546 REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
3547 else
3548 REG_WRITE(ah, AR_RXCFG,
3549 REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
3550}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003551EXPORT_SYMBOL(ath9k_hw_setrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303552
Sujithcbe61d82009-02-09 13:27:12 +05303553bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303554{
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05303555 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
3556 return false;
3557
3558 ath9k_hw_init_pll(ah, NULL);
3559 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303560}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003561EXPORT_SYMBOL(ath9k_hw_phy_disable);
Sujithf1dc5602008-10-29 10:16:30 +05303562
Sujithcbe61d82009-02-09 13:27:12 +05303563bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303564{
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07003565 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05303566 return false;
3567
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05303568 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
3569 return false;
3570
3571 ath9k_hw_init_pll(ah, NULL);
3572 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303573}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003574EXPORT_SYMBOL(ath9k_hw_disable);
Sujithf1dc5602008-10-29 10:16:30 +05303575
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003576void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
Sujithf1dc5602008-10-29 10:16:30 +05303577{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003578 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujith2660b812009-02-09 13:27:26 +05303579 struct ath9k_channel *chan = ah->curchan;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08003580 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05303581
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003582 regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER);
Sujithf1dc5602008-10-29 10:16:30 +05303583
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003584 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003585 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003586 channel->max_antenna_gain * 2,
3587 channel->max_power * 2,
3588 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003589 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05303590}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003591EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
Sujithf1dc5602008-10-29 10:16:30 +05303592
Sujithcbe61d82009-02-09 13:27:12 +05303593void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac)
Sujithf1dc5602008-10-29 10:16:30 +05303594{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07003595 memcpy(ath9k_hw_common(ah)->macaddr, mac, ETH_ALEN);
Sujithf1dc5602008-10-29 10:16:30 +05303596}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003597EXPORT_SYMBOL(ath9k_hw_setmac);
Sujithf1dc5602008-10-29 10:16:30 +05303598
Sujithcbe61d82009-02-09 13:27:12 +05303599void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303600{
Sujith2660b812009-02-09 13:27:26 +05303601 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05303602}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003603EXPORT_SYMBOL(ath9k_hw_setopmode);
Sujithf1dc5602008-10-29 10:16:30 +05303604
Sujithcbe61d82009-02-09 13:27:12 +05303605void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05303606{
3607 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
3608 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
3609}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003610EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303611
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07003612void ath9k_hw_write_associd(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303613{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07003614 struct ath_common *common = ath9k_hw_common(ah);
3615
3616 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
3617 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
3618 ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05303619}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003620EXPORT_SYMBOL(ath9k_hw_write_associd);
Sujithf1dc5602008-10-29 10:16:30 +05303621
Sujithcbe61d82009-02-09 13:27:12 +05303622u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303623{
3624 u64 tsf;
3625
3626 tsf = REG_READ(ah, AR_TSF_U32);
3627 tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
3628
3629 return tsf;
3630}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003631EXPORT_SYMBOL(ath9k_hw_gettsf64);
Sujithf1dc5602008-10-29 10:16:30 +05303632
Sujithcbe61d82009-02-09 13:27:12 +05303633void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003634{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003635 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01003636 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003637}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003638EXPORT_SYMBOL(ath9k_hw_settsf64);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003639
Sujithcbe61d82009-02-09 13:27:12 +05303640void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303641{
Gabor Juhosf9b604f2009-06-21 00:02:15 +02003642 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
3643 AH_TSF_WRITE_TIMEOUT))
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003644 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
3645 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
Gabor Juhosf9b604f2009-06-21 00:02:15 +02003646
Sujithf1dc5602008-10-29 10:16:30 +05303647 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003648}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003649EXPORT_SYMBOL(ath9k_hw_reset_tsf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003650
Sujith54e4cec2009-08-07 09:45:09 +05303651void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003652{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003653 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303654 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003655 else
Sujith2660b812009-02-09 13:27:26 +05303656 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003657}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003658EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003659
Luis R. Rodriguez30cbd422009-11-03 16:10:46 -08003660/*
3661 * Extend 15-bit time stamp from rx descriptor to
3662 * a full 64-bit TSF using the current h/w TSF.
3663*/
3664u64 ath9k_hw_extend_tsf(struct ath_hw *ah, u32 rstamp)
3665{
3666 u64 tsf;
3667
3668 tsf = ath9k_hw_gettsf64(ah);
3669 if ((tsf & 0x7fff) < rstamp)
3670 tsf -= 0x8000;
3671 return (tsf & ~0x7fff) | rstamp;
3672}
3673EXPORT_SYMBOL(ath9k_hw_extend_tsf);
3674
Sujithcbe61d82009-02-09 13:27:12 +05303675bool ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003676{
Sujithf1dc5602008-10-29 10:16:30 +05303677 if (us < ATH9K_SLOT_TIME_9 || us > ath9k_hw_mac_to_usec(ah, 0xffff)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003678 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
3679 "bad slot time %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05303680 ah->slottime = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05303681 return false;
3682 } else {
3683 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05303684 ah->slottime = us;
Sujithf1dc5602008-10-29 10:16:30 +05303685 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003686 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003687}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003688EXPORT_SYMBOL(ath9k_hw_setslottime);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003689
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003690void ath9k_hw_set11nmac2040(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003691{
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003692 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithf1dc5602008-10-29 10:16:30 +05303693 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003694
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003695 if (conf_is_ht40(conf) && !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05303696 macmode = AR_2040_JOINED_RX_CLEAR;
3697 else
3698 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003699
Sujithf1dc5602008-10-29 10:16:30 +05303700 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003701}
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303702
3703/* HW Generic timers configuration */
3704
3705static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
3706{
3707 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3708 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3709 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3710 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3711 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3712 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3713 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3714 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3715 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
3716 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
3717 AR_NDP2_TIMER_MODE, 0x0002},
3718 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
3719 AR_NDP2_TIMER_MODE, 0x0004},
3720 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
3721 AR_NDP2_TIMER_MODE, 0x0008},
3722 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
3723 AR_NDP2_TIMER_MODE, 0x0010},
3724 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
3725 AR_NDP2_TIMER_MODE, 0x0020},
3726 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
3727 AR_NDP2_TIMER_MODE, 0x0040},
3728 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
3729 AR_NDP2_TIMER_MODE, 0x0080}
3730};
3731
3732/* HW generic timer primitives */
3733
3734/* compute and clear index of rightmost 1 */
3735static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
3736{
3737 u32 b;
3738
3739 b = *mask;
3740 b &= (0-b);
3741 *mask &= ~b;
3742 b *= debruijn32;
3743 b >>= 27;
3744
3745 return timer_table->gen_timer_index[b];
3746}
3747
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05303748u32 ath9k_hw_gettsf32(struct ath_hw *ah)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303749{
3750 return REG_READ(ah, AR_TSF_L32);
3751}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003752EXPORT_SYMBOL(ath9k_hw_gettsf32);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303753
3754struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
3755 void (*trigger)(void *),
3756 void (*overflow)(void *),
3757 void *arg,
3758 u8 timer_index)
3759{
3760 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3761 struct ath_gen_timer *timer;
3762
3763 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
3764
3765 if (timer == NULL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003766 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
3767 "Failed to allocate memory"
3768 "for hw timer[%d]\n", timer_index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303769 return NULL;
3770 }
3771
3772 /* allocate a hardware generic timer slot */
3773 timer_table->timers[timer_index] = timer;
3774 timer->index = timer_index;
3775 timer->trigger = trigger;
3776 timer->overflow = overflow;
3777 timer->arg = arg;
3778
3779 return timer;
3780}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003781EXPORT_SYMBOL(ath_gen_timer_alloc);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303782
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07003783void ath9k_hw_gen_timer_start(struct ath_hw *ah,
3784 struct ath_gen_timer *timer,
3785 u32 timer_next,
3786 u32 timer_period)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303787{
3788 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3789 u32 tsf;
3790
3791 BUG_ON(!timer_period);
3792
3793 set_bit(timer->index, &timer_table->timer_mask.timer_bits);
3794
3795 tsf = ath9k_hw_gettsf32(ah);
3796
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003797 ath_print(ath9k_hw_common(ah), ATH_DBG_HWTIMER,
3798 "curent tsf %x period %x"
3799 "timer_next %x\n", tsf, timer_period, timer_next);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303800
3801 /*
3802 * Pull timer_next forward if the current TSF already passed it
3803 * because of software latency
3804 */
3805 if (timer_next < tsf)
3806 timer_next = tsf + timer_period;
3807
3808 /*
3809 * Program generic timer registers
3810 */
3811 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
3812 timer_next);
3813 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
3814 timer_period);
3815 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
3816 gen_tmr_configuration[timer->index].mode_mask);
3817
3818 /* Enable both trigger and thresh interrupt masks */
3819 REG_SET_BIT(ah, AR_IMR_S5,
3820 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
3821 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303822}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003823EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303824
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07003825void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303826{
3827 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3828
3829 if ((timer->index < AR_FIRST_NDP_TIMER) ||
3830 (timer->index >= ATH_MAX_GEN_TIMER)) {
3831 return;
3832 }
3833
3834 /* Clear generic timer enable bits. */
3835 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
3836 gen_tmr_configuration[timer->index].mode_mask);
3837
3838 /* Disable both trigger and thresh interrupt masks */
3839 REG_CLR_BIT(ah, AR_IMR_S5,
3840 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
3841 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
3842
3843 clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303844}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003845EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303846
3847void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
3848{
3849 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3850
3851 /* free the hardware generic timer slot */
3852 timer_table->timers[timer->index] = NULL;
3853 kfree(timer);
3854}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003855EXPORT_SYMBOL(ath_gen_timer_free);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303856
3857/*
3858 * Generic Timer Interrupts handling
3859 */
3860void ath_gen_timer_isr(struct ath_hw *ah)
3861{
3862 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3863 struct ath_gen_timer *timer;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003864 struct ath_common *common = ath9k_hw_common(ah);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303865 u32 trigger_mask, thresh_mask, index;
3866
3867 /* get hardware generic timer interrupt status */
3868 trigger_mask = ah->intr_gen_timer_trigger;
3869 thresh_mask = ah->intr_gen_timer_thresh;
3870 trigger_mask &= timer_table->timer_mask.val;
3871 thresh_mask &= timer_table->timer_mask.val;
3872
3873 trigger_mask &= ~thresh_mask;
3874
3875 while (thresh_mask) {
3876 index = rightmost_index(timer_table, &thresh_mask);
3877 timer = timer_table->timers[index];
3878 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003879 ath_print(common, ATH_DBG_HWTIMER,
3880 "TSF overflow for Gen timer %d\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303881 timer->overflow(timer->arg);
3882 }
3883
3884 while (trigger_mask) {
3885 index = rightmost_index(timer_table, &trigger_mask);
3886 timer = timer_table->timers[index];
3887 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003888 ath_print(common, ATH_DBG_HWTIMER,
3889 "Gen timer[%d] trigger\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303890 timer->trigger(timer->arg);
3891 }
3892}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003893EXPORT_SYMBOL(ath_gen_timer_isr);
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003894
3895static struct {
3896 u32 version;
3897 const char * name;
3898} ath_mac_bb_names[] = {
3899 /* Devices with external radios */
3900 { AR_SREV_VERSION_5416_PCI, "5416" },
3901 { AR_SREV_VERSION_5416_PCIE, "5418" },
3902 { AR_SREV_VERSION_9100, "9100" },
3903 { AR_SREV_VERSION_9160, "9160" },
3904 /* Single-chip solutions */
3905 { AR_SREV_VERSION_9280, "9280" },
3906 { AR_SREV_VERSION_9285, "9285" },
Luis R. Rodriguez11158472009-10-27 12:59:35 -04003907 { AR_SREV_VERSION_9287, "9287" },
3908 { AR_SREV_VERSION_9271, "9271" },
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003909};
3910
3911/* For devices with external radios */
3912static struct {
3913 u16 version;
3914 const char * name;
3915} ath_rf_names[] = {
3916 { 0, "5133" },
3917 { AR_RAD5133_SREV_MAJOR, "5133" },
3918 { AR_RAD5122_SREV_MAJOR, "5122" },
3919 { AR_RAD2133_SREV_MAJOR, "2133" },
3920 { AR_RAD2122_SREV_MAJOR, "2122" }
3921};
3922
3923/*
3924 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
3925 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003926static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003927{
3928 int i;
3929
3930 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
3931 if (ath_mac_bb_names[i].version == mac_bb_version) {
3932 return ath_mac_bb_names[i].name;
3933 }
3934 }
3935
3936 return "????";
3937}
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003938
3939/*
3940 * Return the RF name. "????" is returned if the RF is unknown.
3941 * Used for devices with external radios.
3942 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003943static const char *ath9k_hw_rf_name(u16 rf_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003944{
3945 int i;
3946
3947 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
3948 if (ath_rf_names[i].version == rf_version) {
3949 return ath_rf_names[i].name;
3950 }
3951 }
3952
3953 return "????";
3954}
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003955
3956void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
3957{
3958 int used;
3959
3960 /* chipsets >= AR9280 are single-chip */
3961 if (AR_SREV_9280_10_OR_LATER(ah)) {
3962 used = snprintf(hw_name, len,
3963 "Atheros AR%s Rev:%x",
3964 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3965 ah->hw_version.macRev);
3966 }
3967 else {
3968 used = snprintf(hw_name, len,
3969 "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
3970 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3971 ah->hw_version.macRev,
3972 ath9k_hw_rf_name((ah->hw_version.analog5GhzRev &
3973 AR_RADIO_SREV_MAJOR)),
3974 ah->hw_version.phyRev);
3975 }
3976
3977 hw_name[used] = '\0';
3978}
3979EXPORT_SYMBOL(ath9k_hw_name);