blob: 2fbadbee1aa2ac93713bbdd2b09eb9b342080308 [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);
Sujithcbe61d82009-02-09 13:27:12 +053033static void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan);
34static void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070035
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040036MODULE_AUTHOR("Atheros Communications");
37MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
38MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
39MODULE_LICENSE("Dual BSD/GPL");
40
41static int __init ath9k_init(void)
42{
43 return 0;
44}
45module_init(ath9k_init);
46
47static void __exit ath9k_exit(void)
48{
49 return;
50}
51module_exit(ath9k_exit);
52
Sujithf1dc5602008-10-29 10:16:30 +053053/********************/
54/* Helper Functions */
55/********************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070056
Sujithcbe61d82009-02-09 13:27:12 +053057static u32 ath9k_hw_mac_usec(struct ath_hw *ah, u32 clks)
Sujithf1dc5602008-10-29 10:16:30 +053058{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070059 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053060
Sujith2660b812009-02-09 13:27:26 +053061 if (!ah->curchan) /* should really check for CCK instead */
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080062 return clks / ATH9K_CLOCK_RATE_CCK;
63 if (conf->channel->band == IEEE80211_BAND_2GHZ)
64 return clks / ATH9K_CLOCK_RATE_2GHZ_OFDM;
Sujithcbe61d82009-02-09 13:27:12 +053065
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080066 return clks / ATH9K_CLOCK_RATE_5GHZ_OFDM;
Sujithf1dc5602008-10-29 10:16:30 +053067}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070068
Sujithcbe61d82009-02-09 13:27:12 +053069static u32 ath9k_hw_mac_to_usec(struct ath_hw *ah, u32 clks)
Sujithf1dc5602008-10-29 10:16:30 +053070{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070071 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053072
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080073 if (conf_is_ht40(conf))
Sujithf1dc5602008-10-29 10:16:30 +053074 return ath9k_hw_mac_usec(ah, clks) / 2;
75 else
76 return ath9k_hw_mac_usec(ah, clks);
77}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070078
Sujithcbe61d82009-02-09 13:27:12 +053079static u32 ath9k_hw_mac_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053080{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070081 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053082
Sujith2660b812009-02-09 13:27:26 +053083 if (!ah->curchan) /* should really check for CCK instead */
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080084 return usecs *ATH9K_CLOCK_RATE_CCK;
85 if (conf->channel->band == IEEE80211_BAND_2GHZ)
86 return usecs *ATH9K_CLOCK_RATE_2GHZ_OFDM;
87 return usecs *ATH9K_CLOCK_RATE_5GHZ_OFDM;
Sujithf1dc5602008-10-29 10:16:30 +053088}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070089
Sujithcbe61d82009-02-09 13:27:12 +053090static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053091{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070092 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053093
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080094 if (conf_is_ht40(conf))
Sujithf1dc5602008-10-29 10:16:30 +053095 return ath9k_hw_mac_clks(ah, usecs) * 2;
96 else
97 return ath9k_hw_mac_clks(ah, usecs);
98}
99
Sujith0caa7b12009-02-16 13:23:20 +0530100bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700101{
102 int i;
103
Sujith0caa7b12009-02-16 13:23:20 +0530104 BUG_ON(timeout < AH_TIME_QUANTUM);
105
106 for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700107 if ((REG_READ(ah, reg) & mask) == val)
108 return true;
109
110 udelay(AH_TIME_QUANTUM);
111 }
Sujith04bd4632008-11-28 22:18:05 +0530112
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700113 ath_print(ath9k_hw_common(ah), ATH_DBG_ANY,
114 "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
115 timeout, reg, REG_READ(ah, reg), mask, val);
Sujithf1dc5602008-10-29 10:16:30 +0530116
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700117 return false;
118}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400119EXPORT_SYMBOL(ath9k_hw_wait);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700120
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700121u32 ath9k_hw_reverse_bits(u32 val, u32 n)
122{
123 u32 retval;
124 int i;
125
126 for (i = 0, retval = 0; i < n; i++) {
127 retval = (retval << 1) | (val & 1);
128 val >>= 1;
129 }
130 return retval;
131}
132
Sujithcbe61d82009-02-09 13:27:12 +0530133bool ath9k_get_channel_edges(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530134 u16 flags, u16 *low,
135 u16 *high)
136{
Sujith2660b812009-02-09 13:27:26 +0530137 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530138
139 if (flags & CHANNEL_5GHZ) {
140 *low = pCap->low_5ghz_chan;
141 *high = pCap->high_5ghz_chan;
142 return true;
143 }
144 if ((flags & CHANNEL_2GHZ)) {
145 *low = pCap->low_2ghz_chan;
146 *high = pCap->high_2ghz_chan;
147 return true;
148 }
149 return false;
150}
151
Sujithcbe61d82009-02-09 13:27:12 +0530152u16 ath9k_hw_computetxtime(struct ath_hw *ah,
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400153 const struct ath_rate_table *rates,
Sujithf1dc5602008-10-29 10:16:30 +0530154 u32 frameLen, u16 rateix,
155 bool shortPreamble)
156{
157 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
158 u32 kbps;
159
Sujithe63835b2008-11-18 09:07:53 +0530160 kbps = rates->info[rateix].ratekbps;
Sujithf1dc5602008-10-29 10:16:30 +0530161
162 if (kbps == 0)
163 return 0;
164
165 switch (rates->info[rateix].phy) {
Sujith46d14a52008-11-18 09:08:13 +0530166 case WLAN_RC_PHY_CCK:
Sujithf1dc5602008-10-29 10:16:30 +0530167 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
Sujithe63835b2008-11-18 09:07:53 +0530168 if (shortPreamble && rates->info[rateix].short_preamble)
Sujithf1dc5602008-10-29 10:16:30 +0530169 phyTime >>= 1;
170 numBits = frameLen << 3;
171 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
172 break;
Sujith46d14a52008-11-18 09:08:13 +0530173 case WLAN_RC_PHY_OFDM:
Sujith2660b812009-02-09 13:27:26 +0530174 if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530175 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
176 numBits = OFDM_PLCP_BITS + (frameLen << 3);
177 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
178 txTime = OFDM_SIFS_TIME_QUARTER
179 + OFDM_PREAMBLE_TIME_QUARTER
180 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
Sujith2660b812009-02-09 13:27:26 +0530181 } else if (ah->curchan &&
182 IS_CHAN_HALF_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530183 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
184 numBits = OFDM_PLCP_BITS + (frameLen << 3);
185 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
186 txTime = OFDM_SIFS_TIME_HALF +
187 OFDM_PREAMBLE_TIME_HALF
188 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
189 } else {
190 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
191 numBits = OFDM_PLCP_BITS + (frameLen << 3);
192 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
193 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
194 + (numSymbols * OFDM_SYMBOL_TIME);
195 }
196 break;
197 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700198 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
199 "Unknown phy %u (rate ix %u)\n",
200 rates->info[rateix].phy, rateix);
Sujithf1dc5602008-10-29 10:16:30 +0530201 txTime = 0;
202 break;
203 }
204
205 return txTime;
206}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400207EXPORT_SYMBOL(ath9k_hw_computetxtime);
Sujithf1dc5602008-10-29 10:16:30 +0530208
Sujithcbe61d82009-02-09 13:27:12 +0530209void ath9k_hw_get_channel_centers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530210 struct ath9k_channel *chan,
211 struct chan_centers *centers)
212{
213 int8_t extoff;
Sujithf1dc5602008-10-29 10:16:30 +0530214
215 if (!IS_CHAN_HT40(chan)) {
216 centers->ctl_center = centers->ext_center =
217 centers->synth_center = chan->channel;
218 return;
219 }
220
221 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
222 (chan->chanmode == CHANNEL_G_HT40PLUS)) {
223 centers->synth_center =
224 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
225 extoff = 1;
226 } else {
227 centers->synth_center =
228 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
229 extoff = -1;
230 }
231
232 centers->ctl_center =
233 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700234 /* 25 MHz spacing is supported by hw but not on upper layers */
Sujithf1dc5602008-10-29 10:16:30 +0530235 centers->ext_center =
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700236 centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT);
Sujithf1dc5602008-10-29 10:16:30 +0530237}
238
239/******************/
240/* Chip Revisions */
241/******************/
242
Sujithcbe61d82009-02-09 13:27:12 +0530243static void ath9k_hw_read_revisions(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530244{
245 u32 val;
246
247 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
248
249 if (val == 0xFF) {
250 val = REG_READ(ah, AR_SREV);
Sujithd535a422009-02-09 13:27:06 +0530251 ah->hw_version.macVersion =
252 (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
253 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
Sujith2660b812009-02-09 13:27:26 +0530254 ah->is_pciexpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
Sujithf1dc5602008-10-29 10:16:30 +0530255 } else {
256 if (!AR_SREV_9100(ah))
Sujithd535a422009-02-09 13:27:06 +0530257 ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
Sujithf1dc5602008-10-29 10:16:30 +0530258
Sujithd535a422009-02-09 13:27:06 +0530259 ah->hw_version.macRev = val & AR_SREV_REVISION;
Sujithf1dc5602008-10-29 10:16:30 +0530260
Sujithd535a422009-02-09 13:27:06 +0530261 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
Sujith2660b812009-02-09 13:27:26 +0530262 ah->is_pciexpress = true;
Sujithf1dc5602008-10-29 10:16:30 +0530263 }
264}
265
Sujithcbe61d82009-02-09 13:27:12 +0530266static int ath9k_hw_get_radiorev(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530267{
268 u32 val;
269 int i;
270
271 REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
272
273 for (i = 0; i < 8; i++)
274 REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
275 val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
276 val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
277
278 return ath9k_hw_reverse_bits(val, 8);
279}
280
281/************************************/
282/* HW Attach, Detach, Init Routines */
283/************************************/
284
Sujithcbe61d82009-02-09 13:27:12 +0530285static void ath9k_hw_disablepcie(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530286{
Sujithfeed0292009-01-29 11:37:35 +0530287 if (AR_SREV_9100(ah))
Sujithf1dc5602008-10-29 10:16:30 +0530288 return;
289
290 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
291 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
292 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
293 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
294 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
295 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
296 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
297 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
298 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
299
300 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
301}
302
Sujithcbe61d82009-02-09 13:27:12 +0530303static bool ath9k_hw_chip_test(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530304{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700305 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530306 u32 regAddr[2] = { AR_STA_ID0, AR_PHY_BASE + (8 << 2) };
307 u32 regHold[2];
308 u32 patternData[4] = { 0x55555555,
309 0xaaaaaaaa,
310 0x66666666,
311 0x99999999 };
312 int i, j;
313
314 for (i = 0; i < 2; i++) {
315 u32 addr = regAddr[i];
316 u32 wrData, rdData;
317
318 regHold[i] = REG_READ(ah, addr);
319 for (j = 0; j < 0x100; j++) {
320 wrData = (j << 16) | j;
321 REG_WRITE(ah, addr, wrData);
322 rdData = REG_READ(ah, addr);
323 if (rdData != wrData) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700324 ath_print(common, ATH_DBG_FATAL,
325 "address test failed "
326 "addr: 0x%08x - wr:0x%08x != "
327 "rd:0x%08x\n",
328 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530329 return false;
330 }
331 }
332 for (j = 0; j < 4; j++) {
333 wrData = patternData[j];
334 REG_WRITE(ah, addr, wrData);
335 rdData = REG_READ(ah, addr);
336 if (wrData != rdData) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700337 ath_print(common, ATH_DBG_FATAL,
338 "address test failed "
339 "addr: 0x%08x - wr:0x%08x != "
340 "rd:0x%08x\n",
341 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530342 return false;
343 }
344 }
345 REG_WRITE(ah, regAddr[i], regHold[i]);
346 }
347 udelay(100);
Sujithcbe61d82009-02-09 13:27:12 +0530348
Sujithf1dc5602008-10-29 10:16:30 +0530349 return true;
350}
351
352static const char *ath9k_hw_devname(u16 devid)
353{
354 switch (devid) {
355 case AR5416_DEVID_PCI:
Sujithf1dc5602008-10-29 10:16:30 +0530356 return "Atheros 5416";
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +0100357 case AR5416_DEVID_PCIE:
358 return "Atheros 5418";
Sujithf1dc5602008-10-29 10:16:30 +0530359 case AR9160_DEVID_PCI:
360 return "Atheros 9160";
Gabor Juhos0c1aa492009-01-14 20:17:12 +0100361 case AR5416_AR9100_DEVID:
362 return "Atheros 9100";
Sujithf1dc5602008-10-29 10:16:30 +0530363 case AR9280_DEVID_PCI:
364 case AR9280_DEVID_PCIE:
365 return "Atheros 9280";
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530366 case AR9285_DEVID_PCIE:
367 return "Atheros 9285";
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530368 case AR5416_DEVID_AR9287_PCI:
369 case AR5416_DEVID_AR9287_PCIE:
370 return "Atheros 9287";
Sujithf1dc5602008-10-29 10:16:30 +0530371 }
372
373 return NULL;
374}
375
Luis R. Rodriguezb8b0f372009-08-03 12:24:43 -0700376static void ath9k_hw_init_config(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700377{
378 int i;
379
Sujith2660b812009-02-09 13:27:26 +0530380 ah->config.dma_beacon_response_time = 2;
381 ah->config.sw_beacon_response_time = 10;
382 ah->config.additional_swba_backoff = 0;
383 ah->config.ack_6mb = 0x0;
384 ah->config.cwm_ignore_extcca = 0;
385 ah->config.pcie_powersave_enable = 0;
Sujith2660b812009-02-09 13:27:26 +0530386 ah->config.pcie_clock_req = 0;
Sujith2660b812009-02-09 13:27:26 +0530387 ah->config.pcie_waen = 0;
388 ah->config.analog_shiftreg = 1;
389 ah->config.ht_enable = 1;
390 ah->config.ofdm_trig_low = 200;
391 ah->config.ofdm_trig_high = 500;
392 ah->config.cck_trig_high = 200;
393 ah->config.cck_trig_low = 100;
394 ah->config.enable_ani = 1;
Sujith1cf68732009-08-13 09:34:32 +0530395 ah->config.diversity_control = ATH9K_ANT_VARIABLE;
Sujith2660b812009-02-09 13:27:26 +0530396 ah->config.antenna_switch_swap = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700397
398 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujith2660b812009-02-09 13:27:26 +0530399 ah->config.spurchans[i][0] = AR_NO_SPUR;
400 ah->config.spurchans[i][1] = AR_NO_SPUR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700401 }
402
Sujith0ef1f162009-03-30 15:28:35 +0530403 ah->config.intr_mitigation = true;
Luis R. Rodriguez61584252009-03-12 18:18:49 -0400404
405 /*
406 * We need this for PCI devices only (Cardbus, PCI, miniPCI)
407 * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
408 * This means we use it for all AR5416 devices, and the few
409 * minor PCI AR9280 devices out there.
410 *
411 * Serialization is required because these devices do not handle
412 * well the case of two concurrent reads/writes due to the latency
413 * involved. During one read/write another read/write can be issued
414 * on another CPU while the previous read/write may still be working
415 * on our hardware, if we hit this case the hardware poops in a loop.
416 * We prevent this by serializing reads and writes.
417 *
418 * This issue is not present on PCI-Express devices or pre-AR5416
419 * devices (legacy, 802.11abg).
420 */
421 if (num_possible_cpus() > 1)
David S. Miller2d6a5e92009-03-17 15:01:30 -0700422 ah->config.serialize_regmode = SER_REG_MODE_AUTO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700423}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400424EXPORT_SYMBOL(ath9k_hw_init);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700425
Luis R. Rodriguez50aca252009-08-03 12:24:42 -0700426static void ath9k_hw_init_defaults(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700427{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700428 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
429
430 regulatory->country_code = CTRY_DEFAULT;
431 regulatory->power_limit = MAX_RATE_POWER;
432 regulatory->tp_scale = ATH9K_TP_SCALE_MAX;
433
Sujithd535a422009-02-09 13:27:06 +0530434 ah->hw_version.magic = AR5416_MAGIC;
Sujithd535a422009-02-09 13:27:06 +0530435 ah->hw_version.subvendorid = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700436
437 ah->ah_flags = 0;
Luis R. Rodriguez8df5d1b2009-08-03 12:24:37 -0700438 if (ah->hw_version.devid == AR5416_AR9100_DEVID)
Sujithd535a422009-02-09 13:27:06 +0530439 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700440 if (!AR_SREV_9100(ah))
441 ah->ah_flags = AH_USE_EEPROM;
442
Sujith2660b812009-02-09 13:27:26 +0530443 ah->atim_window = 0;
Sujith2660b812009-02-09 13:27:26 +0530444 ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
445 ah->beacon_interval = 100;
446 ah->enable_32kHz_clock = DONT_USE_32KHZ;
447 ah->slottime = (u32) -1;
448 ah->acktimeout = (u32) -1;
449 ah->ctstimeout = (u32) -1;
450 ah->globaltxtimeout = (u32) -1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700451
Sujith2660b812009-02-09 13:27:26 +0530452 ah->gbeacon_rate = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700453
Gabor Juhoscbdec972009-07-24 17:27:22 +0200454 ah->power_mode = ATH9K_PM_UNDEFINED;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700455}
456
Sujithcbe61d82009-02-09 13:27:12 +0530457static int ath9k_hw_rfattach(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700458{
459 bool rfStatus = false;
460 int ecode = 0;
461
462 rfStatus = ath9k_hw_init_rf(ah, &ecode);
463 if (!rfStatus) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700464 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
465 "RF setup failed, status: %u\n", ecode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700466 return ecode;
467 }
468
469 return 0;
470}
471
Sujithcbe61d82009-02-09 13:27:12 +0530472static int ath9k_hw_rf_claim(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700473{
474 u32 val;
475
476 REG_WRITE(ah, AR_PHY(0), 0x00000007);
477
478 val = ath9k_hw_get_radiorev(ah);
479 switch (val & AR_RADIO_SREV_MAJOR) {
480 case 0:
481 val = AR_RAD5133_SREV_MAJOR;
482 break;
483 case AR_RAD5133_SREV_MAJOR:
484 case AR_RAD5122_SREV_MAJOR:
485 case AR_RAD2133_SREV_MAJOR:
486 case AR_RAD2122_SREV_MAJOR:
487 break;
488 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700489 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
490 "Radio Chip Rev 0x%02X not supported\n",
491 val & AR_RADIO_SREV_MAJOR);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700492 return -EOPNOTSUPP;
493 }
494
Sujithd535a422009-02-09 13:27:06 +0530495 ah->hw_version.analog5GhzRev = val;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700496
497 return 0;
498}
499
Sujithcbe61d82009-02-09 13:27:12 +0530500static int ath9k_hw_init_macaddr(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700501{
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700502 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530503 u32 sum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700504 int i;
Sujithf1dc5602008-10-29 10:16:30 +0530505 u16 eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700506
Sujithf1dc5602008-10-29 10:16:30 +0530507 sum = 0;
508 for (i = 0; i < 3; i++) {
Sujithf74df6f2009-02-09 13:27:24 +0530509 eeval = ah->eep_ops->get_eeprom(ah, AR_EEPROM_MAC(i));
Sujithf1dc5602008-10-29 10:16:30 +0530510 sum += eeval;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700511 common->macaddr[2 * i] = eeval >> 8;
512 common->macaddr[2 * i + 1] = eeval & 0xff;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700513 }
Sujithd8baa932009-03-30 15:28:25 +0530514 if (sum == 0 || sum == 0xffff * 3)
Sujithf1dc5602008-10-29 10:16:30 +0530515 return -EADDRNOTAVAIL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700516
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700517 return 0;
518}
519
Sujithcbe61d82009-02-09 13:27:12 +0530520static void ath9k_hw_init_rxgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530521{
522 u32 rxgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530523
Sujithf74df6f2009-02-09 13:27:24 +0530524 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_17) {
525 rxgain_type = ah->eep_ops->get_eeprom(ah, EEP_RXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530526
527 if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530528 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530529 ar9280Modes_backoff_13db_rxgain_9280_2,
530 ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2), 6);
531 else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530532 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530533 ar9280Modes_backoff_23db_rxgain_9280_2,
534 ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 6);
535 else
Sujith2660b812009-02-09 13:27:26 +0530536 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530537 ar9280Modes_original_rxgain_9280_2,
538 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530539 } else {
Sujith2660b812009-02-09 13:27:26 +0530540 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530541 ar9280Modes_original_rxgain_9280_2,
542 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530543 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530544}
545
Sujithcbe61d82009-02-09 13:27:12 +0530546static void ath9k_hw_init_txgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530547{
548 u32 txgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530549
Sujithf74df6f2009-02-09 13:27:24 +0530550 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_19) {
551 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530552
553 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
Sujith2660b812009-02-09 13:27:26 +0530554 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530555 ar9280Modes_high_power_tx_gain_9280_2,
556 ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 6);
557 else
Sujith2660b812009-02-09 13:27:26 +0530558 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530559 ar9280Modes_original_tx_gain_9280_2,
560 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530561 } else {
Sujith2660b812009-02-09 13:27:26 +0530562 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530563 ar9280Modes_original_tx_gain_9280_2,
564 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530565 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530566}
567
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700568static int ath9k_hw_post_init(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700569{
570 int ecode;
571
Sujithd8baa932009-03-30 15:28:25 +0530572 if (!ath9k_hw_chip_test(ah))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700573 return -ENODEV;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700574
575 ecode = ath9k_hw_rf_claim(ah);
576 if (ecode != 0)
577 return ecode;
578
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700579 ecode = ath9k_hw_eeprom_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700580 if (ecode != 0)
581 return ecode;
Sujith7d01b222009-03-13 08:55:55 +0530582
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700583 ath_print(ath9k_hw_common(ah), ATH_DBG_CONFIG,
584 "Eeprom VER: %d, REV: %d\n",
585 ah->eep_ops->get_eeprom_ver(ah),
586 ah->eep_ops->get_eeprom_rev(ah));
Sujith7d01b222009-03-13 08:55:55 +0530587
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700588 ecode = ath9k_hw_rfattach(ah);
589 if (ecode != 0)
590 return ecode;
591
592 if (!AR_SREV_9100(ah)) {
593 ath9k_hw_ani_setup(ah);
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700594 ath9k_hw_ani_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700595 }
Sujithf1dc5602008-10-29 10:16:30 +0530596
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700597 return 0;
598}
599
Luis R. Rodriguezee2bb462009-08-03 12:24:39 -0700600static bool ath9k_hw_devid_supported(u16 devid)
601{
602 switch (devid) {
603 case AR5416_DEVID_PCI:
604 case AR5416_DEVID_PCIE:
605 case AR5416_AR9100_DEVID:
606 case AR9160_DEVID_PCI:
607 case AR9280_DEVID_PCI:
608 case AR9280_DEVID_PCIE:
609 case AR9285_DEVID_PCIE:
610 case AR5416_DEVID_AR9287_PCI:
611 case AR5416_DEVID_AR9287_PCIE:
Luis R. Rodriguez7976b422009-09-23 23:07:02 -0400612 case AR9271_USB:
Luis R. Rodriguezee2bb462009-08-03 12:24:39 -0700613 return true;
614 default:
615 break;
616 }
617 return false;
618}
619
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700620static bool ath9k_hw_macversion_supported(u32 macversion)
621{
622 switch (macversion) {
623 case AR_SREV_VERSION_5416_PCI:
624 case AR_SREV_VERSION_5416_PCIE:
625 case AR_SREV_VERSION_9160:
626 case AR_SREV_VERSION_9100:
627 case AR_SREV_VERSION_9280:
628 case AR_SREV_VERSION_9285:
629 case AR_SREV_VERSION_9287:
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400630 case AR_SREV_VERSION_9271:
Luis R. Rodriguez7976b422009-09-23 23:07:02 -0400631 return true;
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700632 default:
633 break;
634 }
635 return false;
636}
637
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700638static void ath9k_hw_init_cal_settings(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700639{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700640 if (AR_SREV_9160_10_OR_LATER(ah)) {
641 if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530642 ah->iq_caldata.calData = &iq_cal_single_sample;
643 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700644 &adc_gain_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530645 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700646 &adc_dc_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530647 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700648 &adc_init_dc_cal;
649 } else {
Sujith2660b812009-02-09 13:27:26 +0530650 ah->iq_caldata.calData = &iq_cal_multi_sample;
651 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700652 &adc_gain_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530653 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700654 &adc_dc_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530655 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700656 &adc_init_dc_cal;
657 }
Sujith2660b812009-02-09 13:27:26 +0530658 ah->supp_cals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700659 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700660}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700661
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700662static void ath9k_hw_init_mode_regs(struct ath_hw *ah)
663{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400664 if (AR_SREV_9271(ah)) {
665 INIT_INI_ARRAY(&ah->iniModes, ar9271Modes_9271_1_0,
666 ARRAY_SIZE(ar9271Modes_9271_1_0), 6);
667 INIT_INI_ARRAY(&ah->iniCommon, ar9271Common_9271_1_0,
668 ARRAY_SIZE(ar9271Common_9271_1_0), 2);
669 return;
670 }
671
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530672 if (AR_SREV_9287_11_OR_LATER(ah)) {
673 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_1,
674 ARRAY_SIZE(ar9287Modes_9287_1_1), 6);
675 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_1,
676 ARRAY_SIZE(ar9287Common_9287_1_1), 2);
677 if (ah->config.pcie_clock_req)
678 INIT_INI_ARRAY(&ah->iniPcieSerdes,
679 ar9287PciePhy_clkreq_off_L1_9287_1_1,
680 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_1), 2);
681 else
682 INIT_INI_ARRAY(&ah->iniPcieSerdes,
683 ar9287PciePhy_clkreq_always_on_L1_9287_1_1,
684 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_1),
685 2);
686 } else if (AR_SREV_9287_10_OR_LATER(ah)) {
687 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_0,
688 ARRAY_SIZE(ar9287Modes_9287_1_0), 6);
689 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_0,
690 ARRAY_SIZE(ar9287Common_9287_1_0), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700691
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530692 if (ah->config.pcie_clock_req)
693 INIT_INI_ARRAY(&ah->iniPcieSerdes,
694 ar9287PciePhy_clkreq_off_L1_9287_1_0,
695 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_0), 2);
696 else
697 INIT_INI_ARRAY(&ah->iniPcieSerdes,
698 ar9287PciePhy_clkreq_always_on_L1_9287_1_0,
699 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_0),
700 2);
701 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
702
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530703
Sujith2660b812009-02-09 13:27:26 +0530704 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530705 ARRAY_SIZE(ar9285Modes_9285_1_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530706 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530707 ARRAY_SIZE(ar9285Common_9285_1_2), 2);
708
Sujith2660b812009-02-09 13:27:26 +0530709 if (ah->config.pcie_clock_req) {
710 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530711 ar9285PciePhy_clkreq_off_L1_9285_1_2,
712 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2);
713 } else {
Sujith2660b812009-02-09 13:27:26 +0530714 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530715 ar9285PciePhy_clkreq_always_on_L1_9285_1_2,
716 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2),
717 2);
718 }
719 } else if (AR_SREV_9285_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530720 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530721 ARRAY_SIZE(ar9285Modes_9285), 6);
Sujith2660b812009-02-09 13:27:26 +0530722 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530723 ARRAY_SIZE(ar9285Common_9285), 2);
724
Sujith2660b812009-02-09 13:27:26 +0530725 if (ah->config.pcie_clock_req) {
726 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530727 ar9285PciePhy_clkreq_off_L1_9285,
728 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2);
729 } else {
Sujith2660b812009-02-09 13:27:26 +0530730 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530731 ar9285PciePhy_clkreq_always_on_L1_9285,
732 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285), 2);
733 }
734 } else if (AR_SREV_9280_20_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530735 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700736 ARRAY_SIZE(ar9280Modes_9280_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530737 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700738 ARRAY_SIZE(ar9280Common_9280_2), 2);
739
Sujith2660b812009-02-09 13:27:26 +0530740 if (ah->config.pcie_clock_req) {
741 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530742 ar9280PciePhy_clkreq_off_L1_9280,
743 ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700744 } else {
Sujith2660b812009-02-09 13:27:26 +0530745 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530746 ar9280PciePhy_clkreq_always_on_L1_9280,
747 ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700748 }
Sujith2660b812009-02-09 13:27:26 +0530749 INIT_INI_ARRAY(&ah->iniModesAdditional,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700750 ar9280Modes_fast_clock_9280_2,
Sujithf1dc5602008-10-29 10:16:30 +0530751 ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700752 } else if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530753 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700754 ARRAY_SIZE(ar9280Modes_9280), 6);
Sujith2660b812009-02-09 13:27:26 +0530755 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700756 ARRAY_SIZE(ar9280Common_9280), 2);
757 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530758 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700759 ARRAY_SIZE(ar5416Modes_9160), 6);
Sujith2660b812009-02-09 13:27:26 +0530760 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700761 ARRAY_SIZE(ar5416Common_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530762 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700763 ARRAY_SIZE(ar5416Bank0_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530764 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700765 ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530766 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700767 ARRAY_SIZE(ar5416Bank1_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530768 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700769 ARRAY_SIZE(ar5416Bank2_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530770 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700771 ARRAY_SIZE(ar5416Bank3_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530772 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700773 ARRAY_SIZE(ar5416Bank6_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530774 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700775 ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530776 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700777 ARRAY_SIZE(ar5416Bank7_9160), 2);
778 if (AR_SREV_9160_11(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530779 INIT_INI_ARRAY(&ah->iniAddac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700780 ar5416Addac_91601_1,
781 ARRAY_SIZE(ar5416Addac_91601_1), 2);
782 } else {
Sujith2660b812009-02-09 13:27:26 +0530783 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700784 ARRAY_SIZE(ar5416Addac_9160), 2);
785 }
786 } else if (AR_SREV_9100_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530787 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700788 ARRAY_SIZE(ar5416Modes_9100), 6);
Sujith2660b812009-02-09 13:27:26 +0530789 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700790 ARRAY_SIZE(ar5416Common_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530791 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700792 ARRAY_SIZE(ar5416Bank0_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530793 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700794 ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530795 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700796 ARRAY_SIZE(ar5416Bank1_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530797 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700798 ARRAY_SIZE(ar5416Bank2_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530799 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700800 ARRAY_SIZE(ar5416Bank3_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530801 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700802 ARRAY_SIZE(ar5416Bank6_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530803 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700804 ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530805 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700806 ARRAY_SIZE(ar5416Bank7_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530807 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700808 ARRAY_SIZE(ar5416Addac_9100), 2);
809 } else {
Sujith2660b812009-02-09 13:27:26 +0530810 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700811 ARRAY_SIZE(ar5416Modes), 6);
Sujith2660b812009-02-09 13:27:26 +0530812 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700813 ARRAY_SIZE(ar5416Common), 2);
Sujith2660b812009-02-09 13:27:26 +0530814 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700815 ARRAY_SIZE(ar5416Bank0), 2);
Sujith2660b812009-02-09 13:27:26 +0530816 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700817 ARRAY_SIZE(ar5416BB_RfGain), 3);
Sujith2660b812009-02-09 13:27:26 +0530818 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700819 ARRAY_SIZE(ar5416Bank1), 2);
Sujith2660b812009-02-09 13:27:26 +0530820 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700821 ARRAY_SIZE(ar5416Bank2), 2);
Sujith2660b812009-02-09 13:27:26 +0530822 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700823 ARRAY_SIZE(ar5416Bank3), 3);
Sujith2660b812009-02-09 13:27:26 +0530824 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700825 ARRAY_SIZE(ar5416Bank6), 3);
Sujith2660b812009-02-09 13:27:26 +0530826 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700827 ARRAY_SIZE(ar5416Bank6TPC), 3);
Sujith2660b812009-02-09 13:27:26 +0530828 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700829 ARRAY_SIZE(ar5416Bank7), 2);
Sujith2660b812009-02-09 13:27:26 +0530830 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700831 ARRAY_SIZE(ar5416Addac), 2);
832 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700833}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700834
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700835static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
836{
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530837 if (AR_SREV_9287_11_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530838 INIT_INI_ARRAY(&ah->iniModesRxGain,
839 ar9287Modes_rx_gain_9287_1_1,
840 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_1), 6);
841 else if (AR_SREV_9287_10(ah))
842 INIT_INI_ARRAY(&ah->iniModesRxGain,
843 ar9287Modes_rx_gain_9287_1_0,
844 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_0), 6);
845 else if (AR_SREV_9280_20(ah))
846 ath9k_hw_init_rxgain_ini(ah);
847
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530848 if (AR_SREV_9287_11_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530849 INIT_INI_ARRAY(&ah->iniModesTxGain,
850 ar9287Modes_tx_gain_9287_1_1,
851 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_1), 6);
852 } else if (AR_SREV_9287_10(ah)) {
853 INIT_INI_ARRAY(&ah->iniModesTxGain,
854 ar9287Modes_tx_gain_9287_1_0,
855 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_0), 6);
856 } else if (AR_SREV_9280_20(ah)) {
857 ath9k_hw_init_txgain_ini(ah);
858 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530859 u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
860
861 /* txgain table */
862 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) {
863 INIT_INI_ARRAY(&ah->iniModesTxGain,
864 ar9285Modes_high_power_tx_gain_9285_1_2,
865 ARRAY_SIZE(ar9285Modes_high_power_tx_gain_9285_1_2), 6);
866 } else {
867 INIT_INI_ARRAY(&ah->iniModesTxGain,
868 ar9285Modes_original_tx_gain_9285_1_2,
869 ARRAY_SIZE(ar9285Modes_original_tx_gain_9285_1_2), 6);
870 }
871
872 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700873}
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530874
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700875static void ath9k_hw_init_11a_eeprom_fix(struct ath_hw *ah)
876{
877 u32 i, j;
Sujith06d0f062009-02-12 10:06:45 +0530878
879 if ((ah->hw_version.devid == AR9280_DEVID_PCI) &&
880 test_bit(ATH9K_MODE_11A, ah->caps.wireless_modes)) {
881
882 /* EEPROM Fixup */
Sujith2660b812009-02-09 13:27:26 +0530883 for (i = 0; i < ah->iniModes.ia_rows; i++) {
884 u32 reg = INI_RA(&ah->iniModes, i, 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700885
Sujith2660b812009-02-09 13:27:26 +0530886 for (j = 1; j < ah->iniModes.ia_columns; j++) {
887 u32 val = INI_RA(&ah->iniModes, i, j);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700888
Sujith2660b812009-02-09 13:27:26 +0530889 INI_RA(&ah->iniModes, i, j) =
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530890 ath9k_hw_ini_fixup(ah,
Sujith2660b812009-02-09 13:27:26 +0530891 &ah->eeprom.def,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700892 reg, val);
893 }
894 }
895 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700896}
897
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700898int ath9k_hw_init(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700899{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700900 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700901 int r = 0;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700902
Luis R. Rodriguez3ca34032009-09-23 23:07:01 -0400903 if (!ath9k_hw_devid_supported(ah->hw_version.devid)) {
904 ath_print(common, ATH_DBG_FATAL,
905 "Unsupported device ID: 0x%0x\n",
906 ah->hw_version.devid);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700907 return -EOPNOTSUPP;
Luis R. Rodriguez3ca34032009-09-23 23:07:01 -0400908 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700909
910 ath9k_hw_init_defaults(ah);
911 ath9k_hw_init_config(ah);
912
913 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700914 ath_print(common, ATH_DBG_FATAL,
915 "Couldn't reset chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700916 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700917 }
918
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700919 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700920 ath_print(common, ATH_DBG_FATAL, "Couldn't wakeup chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700921 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700922 }
923
924 if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
925 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
926 (AR_SREV_9280(ah) && !ah->is_pciexpress)) {
927 ah->config.serialize_regmode =
928 SER_REG_MODE_ON;
929 } else {
930 ah->config.serialize_regmode =
931 SER_REG_MODE_OFF;
932 }
933 }
934
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700935 ath_print(common, ATH_DBG_RESET, "serialize_regmode is %d\n",
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700936 ah->config.serialize_regmode);
937
938 if (!ath9k_hw_macversion_supported(ah->hw_version.macVersion)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700939 ath_print(common, ATH_DBG_FATAL,
940 "Mac Chip Rev 0x%02x.%x is not supported by "
941 "this driver\n", ah->hw_version.macVersion,
942 ah->hw_version.macRev);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700943 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700944 }
945
946 if (AR_SREV_9100(ah)) {
947 ah->iq_caldata.calData = &iq_cal_multi_sample;
948 ah->supp_cals = IQ_MISMATCH_CAL;
949 ah->is_pciexpress = false;
950 }
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400951
952 if (AR_SREV_9271(ah))
953 ah->is_pciexpress = false;
954
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700955 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
956
957 ath9k_hw_init_cal_settings(ah);
958
959 ah->ani_function = ATH9K_ANI_ALL;
960 if (AR_SREV_9280_10_OR_LATER(ah))
961 ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
962
963 ath9k_hw_init_mode_regs(ah);
964
965 if (ah->is_pciexpress)
Vivek Natarajan93b1b372009-09-17 09:24:58 +0530966 ath9k_hw_configpcipowersave(ah, 0, 0);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700967 else
968 ath9k_hw_disablepcie(ah);
969
Sujith193cd452009-09-18 15:04:07 +0530970 /* Support for Japan ch.14 (2484) spread */
971 if (AR_SREV_9287_11_OR_LATER(ah)) {
972 INIT_INI_ARRAY(&ah->iniCckfirNormal,
973 ar9287Common_normal_cck_fir_coeff_92871_1,
974 ARRAY_SIZE(ar9287Common_normal_cck_fir_coeff_92871_1), 2);
975 INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
976 ar9287Common_japan_2484_cck_fir_coeff_92871_1,
977 ARRAY_SIZE(ar9287Common_japan_2484_cck_fir_coeff_92871_1), 2);
978 }
979
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700980 r = ath9k_hw_post_init(ah);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700981 if (r)
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700982 return r;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700983
984 ath9k_hw_init_mode_gain_regs(ah);
985 ath9k_hw_fill_cap_info(ah);
986 ath9k_hw_init_11a_eeprom_fix(ah);
Sujithf6688cd2008-12-07 21:43:10 +0530987
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700988 r = ath9k_hw_init_macaddr(ah);
989 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700990 ath_print(common, ATH_DBG_FATAL,
991 "Failed to initialize MAC address\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700992 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700993 }
994
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400995 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
Sujith2660b812009-02-09 13:27:26 +0530996 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700997 else
Sujith2660b812009-02-09 13:27:26 +0530998 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700999
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001000 ath9k_init_nfcal_hist_buffer(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001001
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001002 common->state = ATH_HW_INITIALIZED;
1003
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001004 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001005}
1006
Sujithcbe61d82009-02-09 13:27:12 +05301007static void ath9k_hw_init_bb(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301008 struct ath9k_channel *chan)
1009{
1010 u32 synthDelay;
1011
1012 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +05301013 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +05301014 synthDelay = (4 * synthDelay) / 22;
1015 else
1016 synthDelay /= 10;
1017
1018 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
1019
1020 udelay(synthDelay + BASE_ACTIVATE_DELAY);
1021}
1022
Sujithcbe61d82009-02-09 13:27:12 +05301023static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301024{
1025 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
1026 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
1027
1028 REG_WRITE(ah, AR_QOS_NO_ACK,
1029 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
1030 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
1031 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
1032
1033 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
1034 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
1035 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
1036 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
1037 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
1038}
1039
Sujithcbe61d82009-02-09 13:27:12 +05301040static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301041 struct ath9k_channel *chan)
1042{
1043 u32 pll;
1044
1045 if (AR_SREV_9100(ah)) {
1046 if (chan && IS_CHAN_5GHZ(chan))
1047 pll = 0x1450;
1048 else
1049 pll = 0x1458;
1050 } else {
1051 if (AR_SREV_9280_10_OR_LATER(ah)) {
1052 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
1053
1054 if (chan && IS_CHAN_HALF_RATE(chan))
1055 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
1056 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1057 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
1058
1059 if (chan && IS_CHAN_5GHZ(chan)) {
1060 pll |= SM(0x28, AR_RTC_9160_PLL_DIV);
1061
1062
1063 if (AR_SREV_9280_20(ah)) {
1064 if (((chan->channel % 20) == 0)
1065 || ((chan->channel % 10) == 0))
1066 pll = 0x2850;
1067 else
1068 pll = 0x142c;
1069 }
1070 } else {
1071 pll |= SM(0x2c, AR_RTC_9160_PLL_DIV);
1072 }
1073
1074 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1075
1076 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
1077
1078 if (chan && IS_CHAN_HALF_RATE(chan))
1079 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
1080 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1081 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
1082
1083 if (chan && IS_CHAN_5GHZ(chan))
1084 pll |= SM(0x50, AR_RTC_9160_PLL_DIV);
1085 else
1086 pll |= SM(0x58, AR_RTC_9160_PLL_DIV);
1087 } else {
1088 pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2;
1089
1090 if (chan && IS_CHAN_HALF_RATE(chan))
1091 pll |= SM(0x1, AR_RTC_PLL_CLKSEL);
1092 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1093 pll |= SM(0x2, AR_RTC_PLL_CLKSEL);
1094
1095 if (chan && IS_CHAN_5GHZ(chan))
1096 pll |= SM(0xa, AR_RTC_PLL_DIV);
1097 else
1098 pll |= SM(0xb, AR_RTC_PLL_DIV);
1099 }
1100 }
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001101 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +05301102
1103 udelay(RTC_PLL_SETTLE_DELAY);
1104
1105 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
1106}
1107
Sujithcbe61d82009-02-09 13:27:12 +05301108static void ath9k_hw_init_chain_masks(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301109{
Sujithf1dc5602008-10-29 10:16:30 +05301110 int rx_chainmask, tx_chainmask;
1111
Sujith2660b812009-02-09 13:27:26 +05301112 rx_chainmask = ah->rxchainmask;
1113 tx_chainmask = ah->txchainmask;
Sujithf1dc5602008-10-29 10:16:30 +05301114
1115 switch (rx_chainmask) {
1116 case 0x5:
1117 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1118 AR_PHY_SWAP_ALT_CHAIN);
1119 case 0x3:
Sujithd535a422009-02-09 13:27:06 +05301120 if (((ah)->hw_version.macVersion <= AR_SREV_VERSION_9160)) {
Sujithf1dc5602008-10-29 10:16:30 +05301121 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7);
1122 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7);
1123 break;
1124 }
1125 case 0x1:
1126 case 0x2:
Sujithf1dc5602008-10-29 10:16:30 +05301127 case 0x7:
1128 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
1129 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
1130 break;
1131 default:
1132 break;
1133 }
1134
1135 REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);
1136 if (tx_chainmask == 0x5) {
1137 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1138 AR_PHY_SWAP_ALT_CHAIN);
1139 }
1140 if (AR_SREV_9100(ah))
1141 REG_WRITE(ah, AR_PHY_ANALOG_SWAP,
1142 REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
1143}
1144
Sujithcbe61d82009-02-09 13:27:12 +05301145static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -08001146 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301147{
Sujith2660b812009-02-09 13:27:26 +05301148 ah->mask_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +05301149 AR_IMR_TXURN |
1150 AR_IMR_RXERR |
1151 AR_IMR_RXORN |
1152 AR_IMR_BCNMISC;
1153
Sujith0ef1f162009-03-30 15:28:35 +05301154 if (ah->config.intr_mitigation)
Sujith2660b812009-02-09 13:27:26 +05301155 ah->mask_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
Sujithf1dc5602008-10-29 10:16:30 +05301156 else
Sujith2660b812009-02-09 13:27:26 +05301157 ah->mask_reg |= AR_IMR_RXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301158
Sujith2660b812009-02-09 13:27:26 +05301159 ah->mask_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301160
Colin McCabed97809d2008-12-01 13:38:55 -08001161 if (opmode == NL80211_IFTYPE_AP)
Sujith2660b812009-02-09 13:27:26 +05301162 ah->mask_reg |= AR_IMR_MIB;
Sujithf1dc5602008-10-29 10:16:30 +05301163
Sujith2660b812009-02-09 13:27:26 +05301164 REG_WRITE(ah, AR_IMR, ah->mask_reg);
Sujithf1dc5602008-10-29 10:16:30 +05301165 REG_WRITE(ah, AR_IMR_S2, REG_READ(ah, AR_IMR_S2) | AR_IMR_S2_GTT);
1166
1167 if (!AR_SREV_9100(ah)) {
1168 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
1169 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
1170 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
1171 }
1172}
1173
Sujithcbe61d82009-02-09 13:27:12 +05301174static bool ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301175{
Sujithf1dc5602008-10-29 10:16:30 +05301176 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001177 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1178 "bad ack timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301179 ah->acktimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301180 return false;
1181 } else {
1182 REG_RMW_FIELD(ah, AR_TIME_OUT,
1183 AR_TIME_OUT_ACK, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301184 ah->acktimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301185 return true;
1186 }
1187}
1188
Sujithcbe61d82009-02-09 13:27:12 +05301189static bool ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301190{
Sujithf1dc5602008-10-29 10:16:30 +05301191 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_CTS))) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001192 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1193 "bad cts timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301194 ah->ctstimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301195 return false;
1196 } else {
1197 REG_RMW_FIELD(ah, AR_TIME_OUT,
1198 AR_TIME_OUT_CTS, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301199 ah->ctstimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301200 return true;
1201 }
1202}
1203
Sujithcbe61d82009-02-09 13:27:12 +05301204static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +05301205{
Sujithf1dc5602008-10-29 10:16:30 +05301206 if (tu > 0xFFFF) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001207 ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT,
1208 "bad global tx timeout %u\n", tu);
Sujith2660b812009-02-09 13:27:26 +05301209 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301210 return false;
1211 } else {
1212 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +05301213 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +05301214 return true;
1215 }
1216}
1217
Sujithcbe61d82009-02-09 13:27:12 +05301218static void ath9k_hw_init_user_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301219{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001220 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
1221 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +05301222
Sujith2660b812009-02-09 13:27:26 +05301223 if (ah->misc_mode != 0)
Sujithf1dc5602008-10-29 10:16:30 +05301224 REG_WRITE(ah, AR_PCU_MISC,
Sujith2660b812009-02-09 13:27:26 +05301225 REG_READ(ah, AR_PCU_MISC) | ah->misc_mode);
1226 if (ah->slottime != (u32) -1)
1227 ath9k_hw_setslottime(ah, ah->slottime);
1228 if (ah->acktimeout != (u32) -1)
1229 ath9k_hw_set_ack_timeout(ah, ah->acktimeout);
1230 if (ah->ctstimeout != (u32) -1)
1231 ath9k_hw_set_cts_timeout(ah, ah->ctstimeout);
1232 if (ah->globaltxtimeout != (u32) -1)
1233 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Sujithf1dc5602008-10-29 10:16:30 +05301234}
1235
1236const char *ath9k_hw_probe(u16 vendorid, u16 devid)
1237{
1238 return vendorid == ATHEROS_VENDOR_ID ?
1239 ath9k_hw_devname(devid) : NULL;
1240}
1241
Sujithcbe61d82009-02-09 13:27:12 +05301242void ath9k_hw_detach(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001243{
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001244 struct ath_common *common = ath9k_hw_common(ah);
1245
1246 if (common->state <= ATH_HW_INITIALIZED)
1247 goto free_hw;
1248
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001249 if (!AR_SREV_9100(ah))
Luis R. Rodrigueze70c0cf2009-08-03 12:24:51 -07001250 ath9k_hw_ani_disable(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001251
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001252 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001253
1254free_hw:
1255 ath9k_hw_rf_free(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001256 kfree(ah);
Luis R. Rodriguez9db6b6a2009-08-03 12:24:52 -07001257 ah = NULL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001258}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001259EXPORT_SYMBOL(ath9k_hw_detach);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001260
Sujithf1dc5602008-10-29 10:16:30 +05301261/*******/
1262/* INI */
1263/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001264
Sujithcbe61d82009-02-09 13:27:12 +05301265static void ath9k_hw_override_ini(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301266 struct ath9k_channel *chan)
1267{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001268 u32 val;
1269
1270 if (AR_SREV_9271(ah)) {
1271 /*
1272 * Enable spectral scan to solution for issues with stuck
1273 * beacons on AR9271 1.0. The beacon stuck issue is not seeon on
1274 * AR9271 1.1
1275 */
1276 if (AR_SREV_9271_10(ah)) {
Luis R. Rodriguezec11bb82009-10-27 12:59:36 -04001277 val = REG_READ(ah, AR_PHY_SPECTRAL_SCAN) |
1278 AR_PHY_SPECTRAL_SCAN_ENABLE;
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001279 REG_WRITE(ah, AR_PHY_SPECTRAL_SCAN, val);
1280 }
1281 else if (AR_SREV_9271_11(ah))
1282 /*
1283 * change AR_PHY_RF_CTL3 setting to fix MAC issue
1284 * present on AR9271 1.1
1285 */
1286 REG_WRITE(ah, AR_PHY_RF_CTL3, 0x3a020001);
1287 return;
1288 }
1289
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +05301290 /*
1291 * Set the RX_ABORT and RX_DIS and clear if off only after
1292 * RXE is set for MAC. This prevents frames with corrupted
1293 * descriptor status.
1294 */
1295 REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
1296
Vasanthakumar Thiagarajan204d7942009-09-17 09:26:14 +05301297 if (AR_SREV_9280_10_OR_LATER(ah)) {
1298 val = REG_READ(ah, AR_PCU_MISC_MODE2) &
1299 (~AR_PCU_MISC_MODE2_HWWAR1);
1300
1301 if (AR_SREV_9287_10_OR_LATER(ah))
1302 val = val & (~AR_PCU_MISC_MODE2_HWWAR2);
1303
1304 REG_WRITE(ah, AR_PCU_MISC_MODE2, val);
1305 }
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +05301306
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001307 if (!AR_SREV_5416_20_OR_LATER(ah) ||
Sujithf1dc5602008-10-29 10:16:30 +05301308 AR_SREV_9280_10_OR_LATER(ah))
1309 return;
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001310 /*
1311 * Disable BB clock gating
1312 * Necessary to avoid issues on AR5416 2.0
1313 */
Sujithf1dc5602008-10-29 10:16:30 +05301314 REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
1315}
1316
Sujithcbe61d82009-02-09 13:27:12 +05301317static u32 ath9k_hw_def_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301318 struct ar5416_eeprom_def *pEepData,
Sujithf1dc5602008-10-29 10:16:30 +05301319 u32 reg, u32 value)
1320{
1321 struct base_eep_header *pBase = &(pEepData->baseEepHeader);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001322 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301323
Sujithd535a422009-02-09 13:27:06 +05301324 switch (ah->hw_version.devid) {
Sujithf1dc5602008-10-29 10:16:30 +05301325 case AR9280_DEVID_PCI:
1326 if (reg == 0x7894) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001327 ath_print(common, ATH_DBG_EEPROM,
Sujithf1dc5602008-10-29 10:16:30 +05301328 "ini VAL: %x EEPROM: %x\n", value,
1329 (pBase->version & 0xff));
1330
1331 if ((pBase->version & 0xff) > 0x0a) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001332 ath_print(common, ATH_DBG_EEPROM,
1333 "PWDCLKIND: %d\n",
1334 pBase->pwdclkind);
Sujithf1dc5602008-10-29 10:16:30 +05301335 value &= ~AR_AN_TOP2_PWDCLKIND;
1336 value |= AR_AN_TOP2_PWDCLKIND &
1337 (pBase->pwdclkind << AR_AN_TOP2_PWDCLKIND_S);
1338 } else {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001339 ath_print(common, ATH_DBG_EEPROM,
1340 "PWDCLKIND Earlier Rev\n");
Sujithf1dc5602008-10-29 10:16:30 +05301341 }
1342
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001343 ath_print(common, ATH_DBG_EEPROM,
1344 "final ini VAL: %x\n", value);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001345 }
Sujithf1dc5602008-10-29 10:16:30 +05301346 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001347 }
1348
Sujithf1dc5602008-10-29 10:16:30 +05301349 return value;
1350}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001351
Sujithcbe61d82009-02-09 13:27:12 +05301352static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301353 struct ar5416_eeprom_def *pEepData,
1354 u32 reg, u32 value)
1355{
Sujith2660b812009-02-09 13:27:26 +05301356 if (ah->eep_map == EEP_MAP_4KBITS)
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301357 return value;
1358 else
1359 return ath9k_hw_def_ini_fixup(ah, pEepData, reg, value);
1360}
1361
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301362static void ath9k_olc_init(struct ath_hw *ah)
1363{
1364 u32 i;
1365
Vivek Natarajandb91f2e2009-08-14 11:27:16 +05301366 if (OLC_FOR_AR9287_10_LATER) {
1367 REG_SET_BIT(ah, AR_PHY_TX_PWRCTRL9,
1368 AR_PHY_TX_PWRCTRL9_RES_DC_REMOVAL);
1369 ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TXPC0,
1370 AR9287_AN_TXPC0_TXPCMODE,
1371 AR9287_AN_TXPC0_TXPCMODE_S,
1372 AR9287_AN_TXPC0_TXPCMODE_TEMPSENSE);
1373 udelay(100);
1374 } else {
1375 for (i = 0; i < AR9280_TX_GAIN_TABLE_SIZE; i++)
1376 ah->originalGain[i] =
1377 MS(REG_READ(ah, AR_PHY_TX_GAIN_TBL1 + i * 4),
1378 AR_PHY_TX_GAIN);
1379 ah->PDADCdelta = 0;
1380 }
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301381}
1382
Bob Copeland3a702e42009-03-30 22:30:29 -04001383static u32 ath9k_regd_get_ctl(struct ath_regulatory *reg,
1384 struct ath9k_channel *chan)
1385{
1386 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
1387
1388 if (IS_CHAN_B(chan))
1389 ctl |= CTL_11B;
1390 else if (IS_CHAN_G(chan))
1391 ctl |= CTL_11G;
1392 else
1393 ctl |= CTL_11A;
1394
1395 return ctl;
1396}
1397
Sujithcbe61d82009-02-09 13:27:12 +05301398static int ath9k_hw_process_ini(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001399 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301400{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001401 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301402 int i, regWrites = 0;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001403 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301404 u32 modesIndex, freqIndex;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001405
Sujithf1dc5602008-10-29 10:16:30 +05301406 switch (chan->chanmode) {
1407 case CHANNEL_A:
1408 case CHANNEL_A_HT20:
1409 modesIndex = 1;
1410 freqIndex = 1;
1411 break;
1412 case CHANNEL_A_HT40PLUS:
1413 case CHANNEL_A_HT40MINUS:
1414 modesIndex = 2;
1415 freqIndex = 1;
1416 break;
1417 case CHANNEL_G:
1418 case CHANNEL_G_HT20:
1419 case CHANNEL_B:
1420 modesIndex = 4;
1421 freqIndex = 2;
1422 break;
1423 case CHANNEL_G_HT40PLUS:
1424 case CHANNEL_G_HT40MINUS:
1425 modesIndex = 3;
1426 freqIndex = 2;
1427 break;
1428
1429 default:
1430 return -EINVAL;
1431 }
1432
1433 REG_WRITE(ah, AR_PHY(0), 0x00000007);
Sujithf1dc5602008-10-29 10:16:30 +05301434 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
Sujithf74df6f2009-02-09 13:27:24 +05301435 ah->eep_ops->set_addac(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301436
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001437 if (AR_SREV_5416_22_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +05301438 REG_WRITE_ARRAY(&ah->iniAddac, 1, regWrites);
Sujithf1dc5602008-10-29 10:16:30 +05301439 } else {
1440 struct ar5416IniArray temp;
1441 u32 addacSize =
Sujith2660b812009-02-09 13:27:26 +05301442 sizeof(u32) * ah->iniAddac.ia_rows *
1443 ah->iniAddac.ia_columns;
Sujithf1dc5602008-10-29 10:16:30 +05301444
Sujith2660b812009-02-09 13:27:26 +05301445 memcpy(ah->addac5416_21,
1446 ah->iniAddac.ia_array, addacSize);
Sujithf1dc5602008-10-29 10:16:30 +05301447
Sujith2660b812009-02-09 13:27:26 +05301448 (ah->addac5416_21)[31 * ah->iniAddac.ia_columns + 1] = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301449
Sujith2660b812009-02-09 13:27:26 +05301450 temp.ia_array = ah->addac5416_21;
1451 temp.ia_columns = ah->iniAddac.ia_columns;
1452 temp.ia_rows = ah->iniAddac.ia_rows;
Sujithf1dc5602008-10-29 10:16:30 +05301453 REG_WRITE_ARRAY(&temp, 1, regWrites);
1454 }
1455
1456 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
1457
Sujith2660b812009-02-09 13:27:26 +05301458 for (i = 0; i < ah->iniModes.ia_rows; i++) {
1459 u32 reg = INI_RA(&ah->iniModes, i, 0);
1460 u32 val = INI_RA(&ah->iniModes, i, modesIndex);
Sujithf1dc5602008-10-29 10:16:30 +05301461
Sujithf1dc5602008-10-29 10:16:30 +05301462 REG_WRITE(ah, reg, val);
1463
1464 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301465 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301466 udelay(100);
1467 }
1468
1469 DO_DELAY(regWrites);
1470 }
1471
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301472 if (AR_SREV_9280(ah) || AR_SREV_9287_10_OR_LATER(ah))
Sujith2660b812009-02-09 13:27:26 +05301473 REG_WRITE_ARRAY(&ah->iniModesRxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301474
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301475 if (AR_SREV_9280(ah) || AR_SREV_9285_12_OR_LATER(ah) ||
1476 AR_SREV_9287_10_OR_LATER(ah))
Sujith2660b812009-02-09 13:27:26 +05301477 REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301478
Sujith2660b812009-02-09 13:27:26 +05301479 for (i = 0; i < ah->iniCommon.ia_rows; i++) {
1480 u32 reg = INI_RA(&ah->iniCommon, i, 0);
1481 u32 val = INI_RA(&ah->iniCommon, i, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301482
1483 REG_WRITE(ah, reg, val);
1484
1485 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301486 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301487 udelay(100);
1488 }
1489
1490 DO_DELAY(regWrites);
1491 }
1492
1493 ath9k_hw_write_regs(ah, modesIndex, freqIndex, regWrites);
1494
1495 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan)) {
Sujith2660b812009-02-09 13:27:26 +05301496 REG_WRITE_ARRAY(&ah->iniModesAdditional, modesIndex,
Sujithf1dc5602008-10-29 10:16:30 +05301497 regWrites);
1498 }
1499
1500 ath9k_hw_override_ini(ah, chan);
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001501 ath9k_hw_set_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301502 ath9k_hw_init_chain_masks(ah);
1503
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301504 if (OLC_FOR_AR9280_20_LATER)
1505 ath9k_olc_init(ah);
1506
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001507 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001508 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001509 channel->max_antenna_gain * 2,
1510 channel->max_power * 2,
1511 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001512 (u32) regulatory->power_limit));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001513
Sujithf1dc5602008-10-29 10:16:30 +05301514 if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001515 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1516 "ar5416SetRfRegs failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001517 return -EIO;
1518 }
1519
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001520 return 0;
1521}
1522
Sujithf1dc5602008-10-29 10:16:30 +05301523/****************************************/
1524/* Reset and Channel Switching Routines */
1525/****************************************/
1526
Sujithcbe61d82009-02-09 13:27:12 +05301527static void ath9k_hw_set_rfmode(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301528{
1529 u32 rfMode = 0;
1530
1531 if (chan == NULL)
1532 return;
1533
1534 rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
1535 ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
1536
1537 if (!AR_SREV_9280_10_OR_LATER(ah))
1538 rfMode |= (IS_CHAN_5GHZ(chan)) ?
1539 AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ;
1540
1541 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan))
1542 rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
1543
1544 REG_WRITE(ah, AR_PHY_MODE, rfMode);
1545}
1546
Sujithcbe61d82009-02-09 13:27:12 +05301547static void ath9k_hw_mark_phy_inactive(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301548{
1549 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
1550}
1551
Sujithcbe61d82009-02-09 13:27:12 +05301552static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301553{
1554 u32 regval;
1555
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001556 /*
1557 * set AHB_MODE not to do cacheline prefetches
1558 */
Sujithf1dc5602008-10-29 10:16:30 +05301559 regval = REG_READ(ah, AR_AHB_MODE);
1560 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
1561
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001562 /*
1563 * let mac dma reads be in 128 byte chunks
1564 */
Sujithf1dc5602008-10-29 10:16:30 +05301565 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
1566 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
1567
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001568 /*
1569 * Restore TX Trigger Level to its pre-reset value.
1570 * The initial value depends on whether aggregation is enabled, and is
1571 * adjusted whenever underruns are detected.
1572 */
Sujith2660b812009-02-09 13:27:26 +05301573 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +05301574
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001575 /*
1576 * let mac dma writes be in 128 byte chunks
1577 */
Sujithf1dc5602008-10-29 10:16:30 +05301578 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
1579 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
1580
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001581 /*
1582 * Setup receive FIFO threshold to hold off TX activities
1583 */
Sujithf1dc5602008-10-29 10:16:30 +05301584 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1585
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001586 /*
1587 * reduce the number of usable entries in PCU TXBUF to avoid
1588 * wrap around issues.
1589 */
Sujithf1dc5602008-10-29 10:16:30 +05301590 if (AR_SREV_9285(ah)) {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001591 /* For AR9285 the number of Fifos are reduced to half.
1592 * So set the usable tx buf size also to half to
1593 * avoid data/delimiter underruns
1594 */
Sujithf1dc5602008-10-29 10:16:30 +05301595 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1596 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001597 } else if (!AR_SREV_9271(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +05301598 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1599 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1600 }
1601}
1602
Sujithcbe61d82009-02-09 13:27:12 +05301603static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301604{
1605 u32 val;
1606
1607 val = REG_READ(ah, AR_STA_ID1);
1608 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
1609 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001610 case NL80211_IFTYPE_AP:
Sujithf1dc5602008-10-29 10:16:30 +05301611 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
1612 | AR_STA_ID1_KSRCH_MODE);
1613 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1614 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001615 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04001616 case NL80211_IFTYPE_MESH_POINT:
Sujithf1dc5602008-10-29 10:16:30 +05301617 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
1618 | AR_STA_ID1_KSRCH_MODE);
1619 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1620 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001621 case NL80211_IFTYPE_STATION:
1622 case NL80211_IFTYPE_MONITOR:
Sujithf1dc5602008-10-29 10:16:30 +05301623 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
1624 break;
1625 }
1626}
1627
Sujithcbe61d82009-02-09 13:27:12 +05301628static inline void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001629 u32 coef_scaled,
1630 u32 *coef_mantissa,
1631 u32 *coef_exponent)
1632{
1633 u32 coef_exp, coef_man;
1634
1635 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1636 if ((coef_scaled >> coef_exp) & 0x1)
1637 break;
1638
1639 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1640
1641 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1642
1643 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1644 *coef_exponent = coef_exp - 16;
1645}
1646
Sujithcbe61d82009-02-09 13:27:12 +05301647static void ath9k_hw_set_delta_slope(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301648 struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001649{
1650 u32 coef_scaled, ds_coef_exp, ds_coef_man;
1651 u32 clockMhzScaled = 0x64000000;
1652 struct chan_centers centers;
1653
1654 if (IS_CHAN_HALF_RATE(chan))
1655 clockMhzScaled = clockMhzScaled >> 1;
1656 else if (IS_CHAN_QUARTER_RATE(chan))
1657 clockMhzScaled = clockMhzScaled >> 2;
1658
1659 ath9k_hw_get_channel_centers(ah, chan, &centers);
1660 coef_scaled = clockMhzScaled / centers.synth_center;
1661
1662 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1663 &ds_coef_exp);
1664
1665 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1666 AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
1667 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1668 AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
1669
1670 coef_scaled = (9 * coef_scaled) / 10;
1671
1672 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1673 &ds_coef_exp);
1674
1675 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1676 AR_PHY_HALFGI_DSC_MAN, ds_coef_man);
1677 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1678 AR_PHY_HALFGI_DSC_EXP, ds_coef_exp);
1679}
1680
Sujithcbe61d82009-02-09 13:27:12 +05301681static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +05301682{
1683 u32 rst_flags;
1684 u32 tmpReg;
1685
Sujith70768492009-02-16 13:23:12 +05301686 if (AR_SREV_9100(ah)) {
1687 u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK);
1688 val &= ~AR_RTC_DERIVED_CLK_PERIOD;
1689 val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD);
1690 REG_WRITE(ah, AR_RTC_DERIVED_CLK, val);
1691 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1692 }
1693
Sujithf1dc5602008-10-29 10:16:30 +05301694 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1695 AR_RTC_FORCE_WAKE_ON_INT);
1696
1697 if (AR_SREV_9100(ah)) {
1698 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1699 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1700 } else {
1701 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1702 if (tmpReg &
1703 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1704 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
1705 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
1706 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1707 } else {
1708 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1709 }
1710
1711 rst_flags = AR_RTC_RC_MAC_WARM;
1712 if (type == ATH9K_RESET_COLD)
1713 rst_flags |= AR_RTC_RC_MAC_COLD;
1714 }
1715
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001716 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujithf1dc5602008-10-29 10:16:30 +05301717 udelay(50);
1718
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001719 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301720 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001721 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1722 "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301723 return false;
1724 }
1725
1726 if (!AR_SREV_9100(ah))
1727 REG_WRITE(ah, AR_RC, 0);
1728
Sujithf1dc5602008-10-29 10:16:30 +05301729 if (AR_SREV_9100(ah))
1730 udelay(50);
1731
1732 return true;
1733}
1734
Sujithcbe61d82009-02-09 13:27:12 +05301735static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301736{
1737 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1738 AR_RTC_FORCE_WAKE_ON_INT);
1739
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301740 if (!AR_SREV_9100(ah))
1741 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1742
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001743 REG_WRITE(ah, AR_RTC_RESET, 0);
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301744 udelay(2);
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301745
1746 if (!AR_SREV_9100(ah))
1747 REG_WRITE(ah, AR_RC, 0);
1748
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001749 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301750
1751 if (!ath9k_hw_wait(ah,
1752 AR_RTC_STATUS,
1753 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301754 AR_RTC_STATUS_ON,
1755 AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001756 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1757 "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301758 return false;
1759 }
1760
1761 ath9k_hw_read_revisions(ah);
1762
1763 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1764}
1765
Sujithcbe61d82009-02-09 13:27:12 +05301766static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301767{
1768 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1769 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1770
1771 switch (type) {
1772 case ATH9K_RESET_POWER_ON:
1773 return ath9k_hw_set_reset_power_on(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301774 case ATH9K_RESET_WARM:
1775 case ATH9K_RESET_COLD:
1776 return ath9k_hw_set_reset(ah, type);
Sujithf1dc5602008-10-29 10:16:30 +05301777 default:
1778 return false;
1779 }
1780}
1781
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001782static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301783{
1784 u32 phymode;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301785 u32 enableDacFifo = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301786
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301787 if (AR_SREV_9285_10_OR_LATER(ah))
1788 enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) &
1789 AR_PHY_FC_ENABLE_DAC_FIFO);
1790
Sujithf1dc5602008-10-29 10:16:30 +05301791 phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301792 | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo;
Sujithf1dc5602008-10-29 10:16:30 +05301793
1794 if (IS_CHAN_HT40(chan)) {
1795 phymode |= AR_PHY_FC_DYN2040_EN;
1796
1797 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
1798 (chan->chanmode == CHANNEL_G_HT40PLUS))
1799 phymode |= AR_PHY_FC_DYN2040_PRI_CH;
1800
Sujithf1dc5602008-10-29 10:16:30 +05301801 }
1802 REG_WRITE(ah, AR_PHY_TURBO, phymode);
1803
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001804 ath9k_hw_set11nmac2040(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301805
1806 REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
1807 REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
1808}
1809
Sujithcbe61d82009-02-09 13:27:12 +05301810static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301811 struct ath9k_channel *chan)
1812{
Vivek Natarajan42abfbe2009-09-17 09:27:59 +05301813 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) {
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301814 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
1815 return false;
1816 } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
Sujithf1dc5602008-10-29 10:16:30 +05301817 return false;
1818
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001819 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05301820 return false;
1821
Sujith2660b812009-02-09 13:27:26 +05301822 ah->chip_fullsleep = false;
Sujithf1dc5602008-10-29 10:16:30 +05301823 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301824 ath9k_hw_set_rfmode(ah, chan);
1825
1826 return true;
1827}
1828
Sujithcbe61d82009-02-09 13:27:12 +05301829static bool ath9k_hw_channel_change(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001830 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301831{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001832 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001833 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001834 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301835 u32 synthDelay, qnum;
1836
1837 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1838 if (ath9k_hw_numtxpending(ah, qnum)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001839 ath_print(common, ATH_DBG_QUEUE,
1840 "Transmit frames pending on "
1841 "queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301842 return false;
1843 }
1844 }
1845
1846 REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
1847 if (!ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
Sujith0caa7b12009-02-16 13:23:20 +05301848 AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001849 ath_print(common, ATH_DBG_FATAL,
1850 "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301851 return false;
1852 }
1853
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001854 ath9k_hw_set_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301855
1856 if (AR_SREV_9280_10_OR_LATER(ah)) {
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001857 ath9k_hw_ar9280_set_channel(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301858 } else {
1859 if (!(ath9k_hw_set_channel(ah, chan))) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001860 ath_print(common, ATH_DBG_FATAL,
1861 "Failed to set channel\n");
Sujithf1dc5602008-10-29 10:16:30 +05301862 return false;
1863 }
1864 }
1865
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001866 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001867 ath9k_regd_get_ctl(regulatory, chan),
Sujithf74df6f2009-02-09 13:27:24 +05301868 channel->max_antenna_gain * 2,
1869 channel->max_power * 2,
1870 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001871 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05301872
1873 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +05301874 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +05301875 synthDelay = (4 * synthDelay) / 22;
1876 else
1877 synthDelay /= 10;
1878
1879 udelay(synthDelay + BASE_ACTIVATE_DELAY);
1880
1881 REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
1882
1883 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1884 ath9k_hw_set_delta_slope(ah, chan);
1885
1886 if (AR_SREV_9280_10_OR_LATER(ah))
1887 ath9k_hw_9280_spur_mitigate(ah, chan);
1888 else
1889 ath9k_hw_spur_mitigate(ah, chan);
1890
1891 if (!chan->oneTimeCalsDone)
1892 chan->oneTimeCalsDone = true;
1893
1894 return true;
1895}
1896
Sujithcbe61d82009-02-09 13:27:12 +05301897static void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001898{
1899 int bb_spur = AR_NO_SPUR;
1900 int freq;
1901 int bin, cur_bin;
1902 int bb_spur_off, spur_subchannel_sd;
1903 int spur_freq_sd;
1904 int spur_delta_phase;
1905 int denominator;
1906 int upper, lower, cur_vit_mask;
1907 int tmp, newVal;
1908 int i;
1909 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
1910 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
1911 };
1912 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
1913 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
1914 };
1915 int inc[4] = { 0, 100, 0, 0 };
1916 struct chan_centers centers;
1917
1918 int8_t mask_m[123];
1919 int8_t mask_p[123];
1920 int8_t mask_amt;
1921 int tmp_mask;
1922 int cur_bb_spur;
1923 bool is2GHz = IS_CHAN_2GHZ(chan);
1924
1925 memset(&mask_m, 0, sizeof(int8_t) * 123);
1926 memset(&mask_p, 0, sizeof(int8_t) * 123);
1927
1928 ath9k_hw_get_channel_centers(ah, chan, &centers);
1929 freq = centers.synth_center;
1930
Sujith2660b812009-02-09 13:27:26 +05301931 ah->config.spurmode = SPUR_ENABLE_EEPROM;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001932 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujithf74df6f2009-02-09 13:27:24 +05301933 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001934
1935 if (is2GHz)
1936 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_2GHZ;
1937 else
1938 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_5GHZ;
1939
1940 if (AR_NO_SPUR == cur_bb_spur)
1941 break;
1942 cur_bb_spur = cur_bb_spur - freq;
1943
1944 if (IS_CHAN_HT40(chan)) {
1945 if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT40) &&
1946 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT40)) {
1947 bb_spur = cur_bb_spur;
1948 break;
1949 }
1950 } else if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT20) &&
1951 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT20)) {
1952 bb_spur = cur_bb_spur;
1953 break;
1954 }
1955 }
1956
1957 if (AR_NO_SPUR == bb_spur) {
1958 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1959 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1960 return;
1961 } else {
1962 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1963 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1964 }
1965
1966 bin = bb_spur * 320;
1967
1968 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
1969
1970 newVal = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
1971 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
1972 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
1973 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
1974 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), newVal);
1975
1976 newVal = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
1977 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
1978 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
1979 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
1980 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
1981 REG_WRITE(ah, AR_PHY_SPUR_REG, newVal);
1982
1983 if (IS_CHAN_HT40(chan)) {
1984 if (bb_spur < 0) {
1985 spur_subchannel_sd = 1;
1986 bb_spur_off = bb_spur + 10;
1987 } else {
1988 spur_subchannel_sd = 0;
1989 bb_spur_off = bb_spur - 10;
1990 }
1991 } else {
1992 spur_subchannel_sd = 0;
1993 bb_spur_off = bb_spur;
1994 }
1995
1996 if (IS_CHAN_HT40(chan))
1997 spur_delta_phase =
1998 ((bb_spur * 262144) /
1999 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
2000 else
2001 spur_delta_phase =
2002 ((bb_spur * 524288) /
2003 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
2004
2005 denominator = IS_CHAN_2GHZ(chan) ? 44 : 40;
2006 spur_freq_sd = ((bb_spur_off * 2048) / denominator) & 0x3ff;
2007
2008 newVal = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
2009 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
2010 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
2011 REG_WRITE(ah, AR_PHY_TIMING11, newVal);
2012
2013 newVal = spur_subchannel_sd << AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S;
2014 REG_WRITE(ah, AR_PHY_SFCORR_EXT, newVal);
2015
2016 cur_bin = -6000;
2017 upper = bin + 100;
2018 lower = bin - 100;
2019
2020 for (i = 0; i < 4; i++) {
2021 int pilot_mask = 0;
2022 int chan_mask = 0;
2023 int bp = 0;
2024 for (bp = 0; bp < 30; bp++) {
2025 if ((cur_bin > lower) && (cur_bin < upper)) {
2026 pilot_mask = pilot_mask | 0x1 << bp;
2027 chan_mask = chan_mask | 0x1 << bp;
2028 }
2029 cur_bin += 100;
2030 }
2031 cur_bin += inc[i];
2032 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
2033 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
2034 }
2035
2036 cur_vit_mask = 6100;
2037 upper = bin + 120;
2038 lower = bin - 120;
2039
2040 for (i = 0; i < 123; i++) {
2041 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
Adrian Bunkb08cbcd2008-08-05 22:06:51 +03002042
2043 /* workaround for gcc bug #37014 */
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002044 volatile int tmp_v = abs(cur_vit_mask - bin);
Adrian Bunkb08cbcd2008-08-05 22:06:51 +03002045
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002046 if (tmp_v < 75)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002047 mask_amt = 1;
2048 else
2049 mask_amt = 0;
2050 if (cur_vit_mask < 0)
2051 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
2052 else
2053 mask_p[cur_vit_mask / 100] = mask_amt;
2054 }
2055 cur_vit_mask -= 100;
2056 }
2057
2058 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
2059 | (mask_m[48] << 26) | (mask_m[49] << 24)
2060 | (mask_m[50] << 22) | (mask_m[51] << 20)
2061 | (mask_m[52] << 18) | (mask_m[53] << 16)
2062 | (mask_m[54] << 14) | (mask_m[55] << 12)
2063 | (mask_m[56] << 10) | (mask_m[57] << 8)
2064 | (mask_m[58] << 6) | (mask_m[59] << 4)
2065 | (mask_m[60] << 2) | (mask_m[61] << 0);
2066 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
2067 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
2068
2069 tmp_mask = (mask_m[31] << 28)
2070 | (mask_m[32] << 26) | (mask_m[33] << 24)
2071 | (mask_m[34] << 22) | (mask_m[35] << 20)
2072 | (mask_m[36] << 18) | (mask_m[37] << 16)
2073 | (mask_m[48] << 14) | (mask_m[39] << 12)
2074 | (mask_m[40] << 10) | (mask_m[41] << 8)
2075 | (mask_m[42] << 6) | (mask_m[43] << 4)
2076 | (mask_m[44] << 2) | (mask_m[45] << 0);
2077 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
2078 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
2079
2080 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
2081 | (mask_m[18] << 26) | (mask_m[18] << 24)
2082 | (mask_m[20] << 22) | (mask_m[20] << 20)
2083 | (mask_m[22] << 18) | (mask_m[22] << 16)
2084 | (mask_m[24] << 14) | (mask_m[24] << 12)
2085 | (mask_m[25] << 10) | (mask_m[26] << 8)
2086 | (mask_m[27] << 6) | (mask_m[28] << 4)
2087 | (mask_m[29] << 2) | (mask_m[30] << 0);
2088 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
2089 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
2090
2091 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
2092 | (mask_m[2] << 26) | (mask_m[3] << 24)
2093 | (mask_m[4] << 22) | (mask_m[5] << 20)
2094 | (mask_m[6] << 18) | (mask_m[7] << 16)
2095 | (mask_m[8] << 14) | (mask_m[9] << 12)
2096 | (mask_m[10] << 10) | (mask_m[11] << 8)
2097 | (mask_m[12] << 6) | (mask_m[13] << 4)
2098 | (mask_m[14] << 2) | (mask_m[15] << 0);
2099 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
2100 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
2101
2102 tmp_mask = (mask_p[15] << 28)
2103 | (mask_p[14] << 26) | (mask_p[13] << 24)
2104 | (mask_p[12] << 22) | (mask_p[11] << 20)
2105 | (mask_p[10] << 18) | (mask_p[9] << 16)
2106 | (mask_p[8] << 14) | (mask_p[7] << 12)
2107 | (mask_p[6] << 10) | (mask_p[5] << 8)
2108 | (mask_p[4] << 6) | (mask_p[3] << 4)
2109 | (mask_p[2] << 2) | (mask_p[1] << 0);
2110 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
2111 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
2112
2113 tmp_mask = (mask_p[30] << 28)
2114 | (mask_p[29] << 26) | (mask_p[28] << 24)
2115 | (mask_p[27] << 22) | (mask_p[26] << 20)
2116 | (mask_p[25] << 18) | (mask_p[24] << 16)
2117 | (mask_p[23] << 14) | (mask_p[22] << 12)
2118 | (mask_p[21] << 10) | (mask_p[20] << 8)
2119 | (mask_p[19] << 6) | (mask_p[18] << 4)
2120 | (mask_p[17] << 2) | (mask_p[16] << 0);
2121 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
2122 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
2123
2124 tmp_mask = (mask_p[45] << 28)
2125 | (mask_p[44] << 26) | (mask_p[43] << 24)
2126 | (mask_p[42] << 22) | (mask_p[41] << 20)
2127 | (mask_p[40] << 18) | (mask_p[39] << 16)
2128 | (mask_p[38] << 14) | (mask_p[37] << 12)
2129 | (mask_p[36] << 10) | (mask_p[35] << 8)
2130 | (mask_p[34] << 6) | (mask_p[33] << 4)
2131 | (mask_p[32] << 2) | (mask_p[31] << 0);
2132 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
2133 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
2134
2135 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
2136 | (mask_p[59] << 26) | (mask_p[58] << 24)
2137 | (mask_p[57] << 22) | (mask_p[56] << 20)
2138 | (mask_p[55] << 18) | (mask_p[54] << 16)
2139 | (mask_p[53] << 14) | (mask_p[52] << 12)
2140 | (mask_p[51] << 10) | (mask_p[50] << 8)
2141 | (mask_p[49] << 6) | (mask_p[48] << 4)
2142 | (mask_p[47] << 2) | (mask_p[46] << 0);
2143 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
2144 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
2145}
2146
Sujithcbe61d82009-02-09 13:27:12 +05302147static void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002148{
2149 int bb_spur = AR_NO_SPUR;
2150 int bin, cur_bin;
2151 int spur_freq_sd;
2152 int spur_delta_phase;
2153 int denominator;
2154 int upper, lower, cur_vit_mask;
2155 int tmp, new;
2156 int i;
2157 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
2158 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
2159 };
2160 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
2161 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
2162 };
2163 int inc[4] = { 0, 100, 0, 0 };
2164
2165 int8_t mask_m[123];
2166 int8_t mask_p[123];
2167 int8_t mask_amt;
2168 int tmp_mask;
2169 int cur_bb_spur;
2170 bool is2GHz = IS_CHAN_2GHZ(chan);
2171
2172 memset(&mask_m, 0, sizeof(int8_t) * 123);
2173 memset(&mask_p, 0, sizeof(int8_t) * 123);
2174
2175 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujithf74df6f2009-02-09 13:27:24 +05302176 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002177 if (AR_NO_SPUR == cur_bb_spur)
2178 break;
2179 cur_bb_spur = cur_bb_spur - (chan->channel * 10);
2180 if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) {
2181 bb_spur = cur_bb_spur;
2182 break;
2183 }
2184 }
2185
2186 if (AR_NO_SPUR == bb_spur)
2187 return;
2188
2189 bin = bb_spur * 32;
2190
2191 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
2192 new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
2193 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
2194 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
2195 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
2196
2197 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new);
2198
2199 new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
2200 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
2201 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
2202 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
2203 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
2204 REG_WRITE(ah, AR_PHY_SPUR_REG, new);
2205
2206 spur_delta_phase = ((bb_spur * 524288) / 100) &
2207 AR_PHY_TIMING11_SPUR_DELTA_PHASE;
2208
2209 denominator = IS_CHAN_2GHZ(chan) ? 440 : 400;
2210 spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff;
2211
2212 new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
2213 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
2214 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
2215 REG_WRITE(ah, AR_PHY_TIMING11, new);
2216
2217 cur_bin = -6000;
2218 upper = bin + 100;
2219 lower = bin - 100;
2220
2221 for (i = 0; i < 4; i++) {
2222 int pilot_mask = 0;
2223 int chan_mask = 0;
2224 int bp = 0;
2225 for (bp = 0; bp < 30; bp++) {
2226 if ((cur_bin > lower) && (cur_bin < upper)) {
2227 pilot_mask = pilot_mask | 0x1 << bp;
2228 chan_mask = chan_mask | 0x1 << bp;
2229 }
2230 cur_bin += 100;
2231 }
2232 cur_bin += inc[i];
2233 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
2234 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
2235 }
2236
2237 cur_vit_mask = 6100;
2238 upper = bin + 120;
2239 lower = bin - 120;
2240
2241 for (i = 0; i < 123; i++) {
2242 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
Adrian Bunk88b9e2b2008-08-05 22:06:51 +03002243
2244 /* workaround for gcc bug #37014 */
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002245 volatile int tmp_v = abs(cur_vit_mask - bin);
Adrian Bunk88b9e2b2008-08-05 22:06:51 +03002246
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002247 if (tmp_v < 75)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002248 mask_amt = 1;
2249 else
2250 mask_amt = 0;
2251 if (cur_vit_mask < 0)
2252 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
2253 else
2254 mask_p[cur_vit_mask / 100] = mask_amt;
2255 }
2256 cur_vit_mask -= 100;
2257 }
2258
2259 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
2260 | (mask_m[48] << 26) | (mask_m[49] << 24)
2261 | (mask_m[50] << 22) | (mask_m[51] << 20)
2262 | (mask_m[52] << 18) | (mask_m[53] << 16)
2263 | (mask_m[54] << 14) | (mask_m[55] << 12)
2264 | (mask_m[56] << 10) | (mask_m[57] << 8)
2265 | (mask_m[58] << 6) | (mask_m[59] << 4)
2266 | (mask_m[60] << 2) | (mask_m[61] << 0);
2267 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
2268 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
2269
2270 tmp_mask = (mask_m[31] << 28)
2271 | (mask_m[32] << 26) | (mask_m[33] << 24)
2272 | (mask_m[34] << 22) | (mask_m[35] << 20)
2273 | (mask_m[36] << 18) | (mask_m[37] << 16)
2274 | (mask_m[48] << 14) | (mask_m[39] << 12)
2275 | (mask_m[40] << 10) | (mask_m[41] << 8)
2276 | (mask_m[42] << 6) | (mask_m[43] << 4)
2277 | (mask_m[44] << 2) | (mask_m[45] << 0);
2278 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
2279 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
2280
2281 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
2282 | (mask_m[18] << 26) | (mask_m[18] << 24)
2283 | (mask_m[20] << 22) | (mask_m[20] << 20)
2284 | (mask_m[22] << 18) | (mask_m[22] << 16)
2285 | (mask_m[24] << 14) | (mask_m[24] << 12)
2286 | (mask_m[25] << 10) | (mask_m[26] << 8)
2287 | (mask_m[27] << 6) | (mask_m[28] << 4)
2288 | (mask_m[29] << 2) | (mask_m[30] << 0);
2289 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
2290 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
2291
2292 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
2293 | (mask_m[2] << 26) | (mask_m[3] << 24)
2294 | (mask_m[4] << 22) | (mask_m[5] << 20)
2295 | (mask_m[6] << 18) | (mask_m[7] << 16)
2296 | (mask_m[8] << 14) | (mask_m[9] << 12)
2297 | (mask_m[10] << 10) | (mask_m[11] << 8)
2298 | (mask_m[12] << 6) | (mask_m[13] << 4)
2299 | (mask_m[14] << 2) | (mask_m[15] << 0);
2300 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
2301 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
2302
2303 tmp_mask = (mask_p[15] << 28)
2304 | (mask_p[14] << 26) | (mask_p[13] << 24)
2305 | (mask_p[12] << 22) | (mask_p[11] << 20)
2306 | (mask_p[10] << 18) | (mask_p[9] << 16)
2307 | (mask_p[8] << 14) | (mask_p[7] << 12)
2308 | (mask_p[6] << 10) | (mask_p[5] << 8)
2309 | (mask_p[4] << 6) | (mask_p[3] << 4)
2310 | (mask_p[2] << 2) | (mask_p[1] << 0);
2311 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
2312 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
2313
2314 tmp_mask = (mask_p[30] << 28)
2315 | (mask_p[29] << 26) | (mask_p[28] << 24)
2316 | (mask_p[27] << 22) | (mask_p[26] << 20)
2317 | (mask_p[25] << 18) | (mask_p[24] << 16)
2318 | (mask_p[23] << 14) | (mask_p[22] << 12)
2319 | (mask_p[21] << 10) | (mask_p[20] << 8)
2320 | (mask_p[19] << 6) | (mask_p[18] << 4)
2321 | (mask_p[17] << 2) | (mask_p[16] << 0);
2322 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
2323 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
2324
2325 tmp_mask = (mask_p[45] << 28)
2326 | (mask_p[44] << 26) | (mask_p[43] << 24)
2327 | (mask_p[42] << 22) | (mask_p[41] << 20)
2328 | (mask_p[40] << 18) | (mask_p[39] << 16)
2329 | (mask_p[38] << 14) | (mask_p[37] << 12)
2330 | (mask_p[36] << 10) | (mask_p[35] << 8)
2331 | (mask_p[34] << 6) | (mask_p[33] << 4)
2332 | (mask_p[32] << 2) | (mask_p[31] << 0);
2333 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
2334 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
2335
2336 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
2337 | (mask_p[59] << 26) | (mask_p[58] << 24)
2338 | (mask_p[57] << 22) | (mask_p[56] << 20)
2339 | (mask_p[55] << 18) | (mask_p[54] << 16)
2340 | (mask_p[53] << 14) | (mask_p[52] << 12)
2341 | (mask_p[51] << 10) | (mask_p[50] << 8)
2342 | (mask_p[49] << 6) | (mask_p[48] << 4)
2343 | (mask_p[47] << 2) | (mask_p[46] << 0);
2344 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
2345 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
2346}
2347
Johannes Berg3b319aa2009-06-13 14:50:26 +05302348static void ath9k_enable_rfkill(struct ath_hw *ah)
2349{
2350 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
2351 AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
2352
2353 REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2,
2354 AR_GPIO_INPUT_MUX2_RFSILENT);
2355
2356 ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
2357 REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);
2358}
2359
Sujithcbe61d82009-02-09 13:27:12 +05302360int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002361 bool bChannelChange)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002362{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002363 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002364 u32 saveLedState;
Sujith2660b812009-02-09 13:27:26 +05302365 struct ath9k_channel *curchan = ah->curchan;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002366 u32 saveDefAntenna;
2367 u32 macStaId1;
Sujith46fe7822009-09-17 09:25:25 +05302368 u64 tsf = 0;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002369 int i, rx_chainmask, r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002370
Luis R. Rodriguez43c27612009-09-13 21:07:07 -07002371 ah->txchainmask = common->tx_chainmask;
2372 ah->rxchainmask = common->rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002373
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002374 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002375 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002376
Vasanthakumar Thiagarajan9ebef792009-09-17 09:26:44 +05302377 if (curchan && !ah->chip_fullsleep)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002378 ath9k_hw_getnf(ah, curchan);
2379
2380 if (bChannelChange &&
Sujith2660b812009-02-09 13:27:26 +05302381 (ah->chip_fullsleep != true) &&
2382 (ah->curchan != NULL) &&
2383 (chan->channel != ah->curchan->channel) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002384 ((chan->channelFlags & CHANNEL_ALL) ==
Sujith2660b812009-02-09 13:27:26 +05302385 (ah->curchan->channelFlags & CHANNEL_ALL)) &&
Vasanthakumar Thiagarajan0a475cc2009-09-17 09:27:10 +05302386 !(AR_SREV_9280(ah) || IS_CHAN_A_5MHZ_SPACED(chan) ||
2387 IS_CHAN_A_5MHZ_SPACED(ah->curchan))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002388
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002389 if (ath9k_hw_channel_change(ah, chan)) {
Sujith2660b812009-02-09 13:27:26 +05302390 ath9k_hw_loadnf(ah, ah->curchan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002391 ath9k_hw_start_nfcal(ah);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002392 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002393 }
2394 }
2395
2396 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
2397 if (saveDefAntenna == 0)
2398 saveDefAntenna = 1;
2399
2400 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
2401
Sujith46fe7822009-09-17 09:25:25 +05302402 /* For chips on which RTC reset is done, save TSF before it gets cleared */
2403 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
2404 tsf = ath9k_hw_gettsf64(ah);
2405
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002406 saveLedState = REG_READ(ah, AR_CFG_LED) &
2407 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
2408 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
2409
2410 ath9k_hw_mark_phy_inactive(ah);
2411
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002412 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
2413 REG_WRITE(ah,
2414 AR9271_RESET_POWER_DOWN_CONTROL,
2415 AR9271_RADIO_RF_RST);
2416 udelay(50);
2417 }
2418
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002419 if (!ath9k_hw_chip_reset(ah, chan)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002420 ath_print(common, ATH_DBG_FATAL, "Chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002421 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002422 }
2423
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002424 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
2425 ah->htc_reset_init = false;
2426 REG_WRITE(ah,
2427 AR9271_RESET_POWER_DOWN_CONTROL,
2428 AR9271_GATE_MAC_CTL);
2429 udelay(50);
2430 }
2431
Sujith46fe7822009-09-17 09:25:25 +05302432 /* Restore TSF */
2433 if (tsf && AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
2434 ath9k_hw_settsf64(ah, tsf);
2435
Vasanthakumar Thiagarajan369391d2009-01-21 19:24:13 +05302436 if (AR_SREV_9280_10_OR_LATER(ah))
2437 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002438
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302439 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302440 /* Enable ASYNC FIFO */
2441 REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2442 AR_MAC_PCU_ASYNC_FIFO_REG3_DATAPATH_SEL);
2443 REG_SET_BIT(ah, AR_PHY_MODE, AR_PHY_MODE_ASYNCFIFO);
2444 REG_CLR_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2445 AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
2446 REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2447 AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
2448 }
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002449 r = ath9k_hw_process_ini(ah, chan);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002450 if (r)
2451 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002452
Jouni Malinen0ced0e12009-01-08 13:32:13 +02002453 /* Setup MFP options for CCMP */
2454 if (AR_SREV_9280_20_OR_LATER(ah)) {
2455 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
2456 * frames when constructing CCMP AAD. */
2457 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
2458 0xc7ff);
2459 ah->sw_mgmt_crypto = false;
2460 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
2461 /* Disable hardware crypto for management frames */
2462 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
2463 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
2464 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
2465 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
2466 ah->sw_mgmt_crypto = true;
2467 } else
2468 ah->sw_mgmt_crypto = true;
2469
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002470 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
2471 ath9k_hw_set_delta_slope(ah, chan);
2472
2473 if (AR_SREV_9280_10_OR_LATER(ah))
2474 ath9k_hw_9280_spur_mitigate(ah, chan);
2475 else
2476 ath9k_hw_spur_mitigate(ah, chan);
2477
Sujithd6509152009-03-13 08:56:05 +05302478 ah->eep_ops->set_board_values(ah, chan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002479
2480 ath9k_hw_decrease_chain_power(ah, chan);
2481
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002482 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
2483 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002484 | macStaId1
2485 | AR_STA_ID1_RTS_USE_DEF
Sujith2660b812009-02-09 13:27:26 +05302486 | (ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302487 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Sujith2660b812009-02-09 13:27:26 +05302488 | ah->sta_id1_defaults);
2489 ath9k_hw_set_operating_mode(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002490
Luis R. Rodriguez13b81552009-09-10 17:52:45 -07002491 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002492
2493 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
2494
Luis R. Rodriguez3453ad82009-09-10 08:57:00 -07002495 ath9k_hw_write_associd(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002496
2497 REG_WRITE(ah, AR_ISR, ~0);
2498
2499 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
2500
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07002501 if (AR_SREV_9280_10_OR_LATER(ah))
2502 ath9k_hw_ar9280_set_channel(ah, chan);
2503 else
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002504 if (!(ath9k_hw_set_channel(ah, chan)))
2505 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002506
2507 for (i = 0; i < AR_NUM_DCU; i++)
2508 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
2509
Sujith2660b812009-02-09 13:27:26 +05302510 ah->intr_txqs = 0;
2511 for (i = 0; i < ah->caps.total_queues; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002512 ath9k_hw_resettxqueue(ah, i);
2513
Sujith2660b812009-02-09 13:27:26 +05302514 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002515 ath9k_hw_init_qos(ah);
2516
Sujith2660b812009-02-09 13:27:26 +05302517 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05302518 ath9k_enable_rfkill(ah);
Johannes Berg3b319aa2009-06-13 14:50:26 +05302519
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002520 ath9k_hw_init_user_settings(ah);
2521
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302522 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302523 REG_WRITE(ah, AR_D_GBL_IFS_SIFS,
2524 AR_D_GBL_IFS_SIFS_ASYNC_FIFO_DUR);
2525 REG_WRITE(ah, AR_D_GBL_IFS_SLOT,
2526 AR_D_GBL_IFS_SLOT_ASYNC_FIFO_DUR);
2527 REG_WRITE(ah, AR_D_GBL_IFS_EIFS,
2528 AR_D_GBL_IFS_EIFS_ASYNC_FIFO_DUR);
2529
2530 REG_WRITE(ah, AR_TIME_OUT, AR_TIME_OUT_ACK_CTS_ASYNC_FIFO_DUR);
2531 REG_WRITE(ah, AR_USEC, AR_USEC_ASYNC_FIFO_DUR);
2532
2533 REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
2534 AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
2535 REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
2536 AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
2537 }
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302538 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302539 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
2540 AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
2541 }
2542
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002543 REG_WRITE(ah, AR_STA_ID1,
2544 REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
2545
2546 ath9k_hw_set_dma(ah);
2547
2548 REG_WRITE(ah, AR_OBS, 8);
2549
Sujith0ef1f162009-03-30 15:28:35 +05302550 if (ah->config.intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002551 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
2552 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
2553 }
2554
2555 ath9k_hw_init_bb(ah, chan);
2556
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002557 if (!ath9k_hw_init_cal(ah, chan))
Joe Perches6badaaf2009-06-28 09:26:32 -07002558 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002559
Sujith2660b812009-02-09 13:27:26 +05302560 rx_chainmask = ah->rxchainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002561 if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) {
2562 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
2563 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
2564 }
2565
2566 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
2567
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002568 /*
2569 * For big endian systems turn on swapping for descriptors
2570 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002571 if (AR_SREV_9100(ah)) {
2572 u32 mask;
2573 mask = REG_READ(ah, AR_CFG);
2574 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002575 ath_print(common, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05302576 "CFG Byte Swap Set 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002577 } else {
2578 mask =
2579 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
2580 REG_WRITE(ah, AR_CFG, mask);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002581 ath_print(common, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05302582 "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002583 }
2584 } else {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002585 /* Configure AR9271 target WLAN */
2586 if (AR_SREV_9271(ah))
2587 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002588#ifdef __BIG_ENDIAN
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002589 else
2590 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002591#endif
2592 }
2593
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002594 if (ah->btcoex_hw.enabled)
Vasanthakumar Thiagarajan42cc41e2009-08-26 21:08:45 +05302595 ath9k_hw_btcoex_enable(ah);
2596
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002597 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002598}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002599EXPORT_SYMBOL(ath9k_hw_reset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002600
Sujithf1dc5602008-10-29 10:16:30 +05302601/************************/
2602/* Key Cache Management */
2603/************************/
2604
Sujithcbe61d82009-02-09 13:27:12 +05302605bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002606{
Sujithf1dc5602008-10-29 10:16:30 +05302607 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002608
Sujith2660b812009-02-09 13:27:26 +05302609 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002610 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2611 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002612 return false;
2613 }
2614
Sujithf1dc5602008-10-29 10:16:30 +05302615 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002616
Sujithf1dc5602008-10-29 10:16:30 +05302617 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
2618 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
2619 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
2620 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
2621 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
2622 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
2623 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
2624 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
2625
2626 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2627 u16 micentry = entry + 64;
2628
2629 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
2630 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
2631 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
2632 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
2633
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002634 }
2635
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002636 return true;
2637}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002638EXPORT_SYMBOL(ath9k_hw_keyreset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002639
Sujithcbe61d82009-02-09 13:27:12 +05302640bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002641{
Sujithf1dc5602008-10-29 10:16:30 +05302642 u32 macHi, macLo;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002643
Sujith2660b812009-02-09 13:27:26 +05302644 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002645 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2646 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002647 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002648 }
2649
Sujithf1dc5602008-10-29 10:16:30 +05302650 if (mac != NULL) {
2651 macHi = (mac[5] << 8) | mac[4];
2652 macLo = (mac[3] << 24) |
2653 (mac[2] << 16) |
2654 (mac[1] << 8) |
2655 mac[0];
2656 macLo >>= 1;
2657 macLo |= (macHi & 1) << 31;
2658 macHi >>= 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002659 } else {
Sujithf1dc5602008-10-29 10:16:30 +05302660 macLo = macHi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002661 }
Sujithf1dc5602008-10-29 10:16:30 +05302662 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
2663 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002664
2665 return true;
2666}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002667EXPORT_SYMBOL(ath9k_hw_keysetmac);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002668
Sujithcbe61d82009-02-09 13:27:12 +05302669bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
Sujithf1dc5602008-10-29 10:16:30 +05302670 const struct ath9k_keyval *k,
Jouni Malinene0caf9e2009-03-02 18:15:53 +02002671 const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002672{
Sujith2660b812009-02-09 13:27:26 +05302673 const struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002674 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302675 u32 key0, key1, key2, key3, key4;
2676 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002677
Sujithf1dc5602008-10-29 10:16:30 +05302678 if (entry >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002679 ath_print(common, ATH_DBG_FATAL,
2680 "keycache entry %u out of range\n", entry);
Sujithf1dc5602008-10-29 10:16:30 +05302681 return false;
2682 }
2683
2684 switch (k->kv_type) {
2685 case ATH9K_CIPHER_AES_OCB:
2686 keyType = AR_KEYTABLE_TYPE_AES;
2687 break;
2688 case ATH9K_CIPHER_AES_CCM:
2689 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002690 ath_print(common, ATH_DBG_ANY,
2691 "AES-CCM not supported by mac rev 0x%x\n",
2692 ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002693 return false;
2694 }
Sujithf1dc5602008-10-29 10:16:30 +05302695 keyType = AR_KEYTABLE_TYPE_CCM;
2696 break;
2697 case ATH9K_CIPHER_TKIP:
2698 keyType = AR_KEYTABLE_TYPE_TKIP;
2699 if (ATH9K_IS_MIC_ENABLED(ah)
2700 && entry + 64 >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002701 ath_print(common, ATH_DBG_ANY,
2702 "entry %u inappropriate for TKIP\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002703 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002704 }
Sujithf1dc5602008-10-29 10:16:30 +05302705 break;
2706 case ATH9K_CIPHER_WEP:
Zhu Yie31a16d2009-05-21 21:47:03 +08002707 if (k->kv_len < WLAN_KEY_LEN_WEP40) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002708 ath_print(common, ATH_DBG_ANY,
2709 "WEP key length %u too small\n", k->kv_len);
Sujithf1dc5602008-10-29 10:16:30 +05302710 return false;
2711 }
Zhu Yie31a16d2009-05-21 21:47:03 +08002712 if (k->kv_len <= WLAN_KEY_LEN_WEP40)
Sujithf1dc5602008-10-29 10:16:30 +05302713 keyType = AR_KEYTABLE_TYPE_40;
Zhu Yie31a16d2009-05-21 21:47:03 +08002714 else if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05302715 keyType = AR_KEYTABLE_TYPE_104;
2716 else
2717 keyType = AR_KEYTABLE_TYPE_128;
2718 break;
2719 case ATH9K_CIPHER_CLR:
2720 keyType = AR_KEYTABLE_TYPE_CLR;
2721 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002722 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002723 ath_print(common, ATH_DBG_FATAL,
2724 "cipher %u not supported\n", k->kv_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002725 return false;
2726 }
Sujithf1dc5602008-10-29 10:16:30 +05302727
Jouni Malinene0caf9e2009-03-02 18:15:53 +02002728 key0 = get_unaligned_le32(k->kv_val + 0);
2729 key1 = get_unaligned_le16(k->kv_val + 4);
2730 key2 = get_unaligned_le32(k->kv_val + 6);
2731 key3 = get_unaligned_le16(k->kv_val + 10);
2732 key4 = get_unaligned_le32(k->kv_val + 12);
Zhu Yie31a16d2009-05-21 21:47:03 +08002733 if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05302734 key4 &= 0xff;
2735
Jouni Malinen672903b2009-03-02 15:06:31 +02002736 /*
2737 * Note: Key cache registers access special memory area that requires
2738 * two 32-bit writes to actually update the values in the internal
2739 * memory. Consequently, the exact order and pairs used here must be
2740 * maintained.
2741 */
2742
Sujithf1dc5602008-10-29 10:16:30 +05302743 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2744 u16 micentry = entry + 64;
2745
Jouni Malinen672903b2009-03-02 15:06:31 +02002746 /*
2747 * Write inverted key[47:0] first to avoid Michael MIC errors
2748 * on frames that could be sent or received at the same time.
2749 * The correct key will be written in the end once everything
2750 * else is ready.
2751 */
Sujithf1dc5602008-10-29 10:16:30 +05302752 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
2753 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002754
2755 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302756 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2757 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002758
2759 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302760 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2761 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
Jouni Malinen672903b2009-03-02 15:06:31 +02002762
2763 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302764 (void) ath9k_hw_keysetmac(ah, entry, mac);
2765
Sujith2660b812009-02-09 13:27:26 +05302766 if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) {
Jouni Malinen672903b2009-03-02 15:06:31 +02002767 /*
2768 * TKIP uses two key cache entries:
2769 * Michael MIC TX/RX keys in the same key cache entry
2770 * (idx = main index + 64):
2771 * key0 [31:0] = RX key [31:0]
2772 * key1 [15:0] = TX key [31:16]
2773 * key1 [31:16] = reserved
2774 * key2 [31:0] = RX key [63:32]
2775 * key3 [15:0] = TX key [15:0]
2776 * key3 [31:16] = reserved
2777 * key4 [31:0] = TX key [63:32]
2778 */
Sujithf1dc5602008-10-29 10:16:30 +05302779 u32 mic0, mic1, mic2, mic3, mic4;
2780
2781 mic0 = get_unaligned_le32(k->kv_mic + 0);
2782 mic2 = get_unaligned_le32(k->kv_mic + 4);
2783 mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
2784 mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
2785 mic4 = get_unaligned_le32(k->kv_txmic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02002786
2787 /* Write RX[31:0] and TX[31:16] */
Sujithf1dc5602008-10-29 10:16:30 +05302788 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2789 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002790
2791 /* Write RX[63:32] and TX[15:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302792 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2793 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002794
2795 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302796 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
2797 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2798 AR_KEYTABLE_TYPE_CLR);
2799
2800 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002801 /*
2802 * TKIP uses four key cache entries (two for group
2803 * keys):
2804 * Michael MIC TX/RX keys are in different key cache
2805 * entries (idx = main index + 64 for TX and
2806 * main index + 32 + 96 for RX):
2807 * key0 [31:0] = TX/RX MIC key [31:0]
2808 * key1 [31:0] = reserved
2809 * key2 [31:0] = TX/RX MIC key [63:32]
2810 * key3 [31:0] = reserved
2811 * key4 [31:0] = reserved
2812 *
2813 * Upper layer code will call this function separately
2814 * for TX and RX keys when these registers offsets are
2815 * used.
2816 */
Sujithf1dc5602008-10-29 10:16:30 +05302817 u32 mic0, mic2;
2818
2819 mic0 = get_unaligned_le32(k->kv_mic + 0);
2820 mic2 = get_unaligned_le32(k->kv_mic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02002821
2822 /* Write MIC key[31:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302823 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2824 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002825
2826 /* Write MIC key[63:32] */
Sujithf1dc5602008-10-29 10:16:30 +05302827 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2828 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002829
2830 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302831 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
2832 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2833 AR_KEYTABLE_TYPE_CLR);
2834 }
Jouni Malinen672903b2009-03-02 15:06:31 +02002835
2836 /* MAC address registers are reserved for the MIC entry */
Sujithf1dc5602008-10-29 10:16:30 +05302837 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
2838 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002839
2840 /*
2841 * Write the correct (un-inverted) key[47:0] last to enable
2842 * TKIP now that all other registers are set with correct
2843 * values.
2844 */
Sujithf1dc5602008-10-29 10:16:30 +05302845 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2846 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
2847 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002848 /* Write key[47:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302849 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2850 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002851
2852 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302853 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2854 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002855
2856 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302857 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2858 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
2859
Jouni Malinen672903b2009-03-02 15:06:31 +02002860 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302861 (void) ath9k_hw_keysetmac(ah, entry, mac);
2862 }
2863
Sujithf1dc5602008-10-29 10:16:30 +05302864 return true;
2865}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002866EXPORT_SYMBOL(ath9k_hw_set_keycache_entry);
Sujithf1dc5602008-10-29 10:16:30 +05302867
Sujithcbe61d82009-02-09 13:27:12 +05302868bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry)
Sujithf1dc5602008-10-29 10:16:30 +05302869{
Sujith2660b812009-02-09 13:27:26 +05302870 if (entry < ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05302871 u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
2872 if (val & AR_KEYTABLE_VALID)
2873 return true;
2874 }
2875 return false;
2876}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002877EXPORT_SYMBOL(ath9k_hw_keyisvalid);
Sujithf1dc5602008-10-29 10:16:30 +05302878
2879/******************************/
2880/* Power Management (Chipset) */
2881/******************************/
2882
Sujithcbe61d82009-02-09 13:27:12 +05302883static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302884{
2885 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2886 if (setChip) {
2887 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2888 AR_RTC_FORCE_WAKE_EN);
2889 if (!AR_SREV_9100(ah))
2890 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
2891
Sujith4921be82009-09-18 15:04:27 +05302892 if(!AR_SREV_5416(ah))
2893 REG_CLR_BIT(ah, (AR_RTC_RESET),
2894 AR_RTC_RESET_EN);
Sujithf1dc5602008-10-29 10:16:30 +05302895 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002896}
2897
Sujithcbe61d82009-02-09 13:27:12 +05302898static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002899{
Sujithf1dc5602008-10-29 10:16:30 +05302900 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2901 if (setChip) {
Sujith2660b812009-02-09 13:27:26 +05302902 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002903
Sujithf1dc5602008-10-29 10:16:30 +05302904 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
2905 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2906 AR_RTC_FORCE_WAKE_ON_INT);
2907 } else {
2908 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2909 AR_RTC_FORCE_WAKE_EN);
2910 }
2911 }
2912}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002913
Sujithcbe61d82009-02-09 13:27:12 +05302914static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302915{
2916 u32 val;
2917 int i;
2918
2919 if (setChip) {
2920 if ((REG_READ(ah, AR_RTC_STATUS) &
2921 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2922 if (ath9k_hw_set_reset_reg(ah,
2923 ATH9K_RESET_POWER_ON) != true) {
2924 return false;
2925 }
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05302926 ath9k_hw_init_pll(ah, NULL);
Sujithf1dc5602008-10-29 10:16:30 +05302927 }
2928 if (AR_SREV_9100(ah))
2929 REG_SET_BIT(ah, AR_RTC_RESET,
2930 AR_RTC_RESET_EN);
2931
2932 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2933 AR_RTC_FORCE_WAKE_EN);
2934 udelay(50);
2935
2936 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2937 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2938 if (val == AR_RTC_STATUS_ON)
2939 break;
2940 udelay(50);
2941 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2942 AR_RTC_FORCE_WAKE_EN);
2943 }
2944 if (i == 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002945 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2946 "Failed to wakeup in %uus\n",
2947 POWER_UP_TIME / 20);
Sujithf1dc5602008-10-29 10:16:30 +05302948 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002949 }
2950 }
2951
Sujithf1dc5602008-10-29 10:16:30 +05302952 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2953
2954 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002955}
2956
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002957bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05302958{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002959 struct ath_common *common = ath9k_hw_common(ah);
Sujithcbe61d82009-02-09 13:27:12 +05302960 int status = true, setChip = true;
Sujithf1dc5602008-10-29 10:16:30 +05302961 static const char *modes[] = {
2962 "AWAKE",
2963 "FULL-SLEEP",
2964 "NETWORK SLEEP",
2965 "UNDEFINED"
2966 };
Sujithf1dc5602008-10-29 10:16:30 +05302967
Gabor Juhoscbdec972009-07-24 17:27:22 +02002968 if (ah->power_mode == mode)
2969 return status;
2970
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002971 ath_print(common, ATH_DBG_RESET, "%s -> %s\n",
2972 modes[ah->power_mode], modes[mode]);
Sujithf1dc5602008-10-29 10:16:30 +05302973
2974 switch (mode) {
2975 case ATH9K_PM_AWAKE:
2976 status = ath9k_hw_set_power_awake(ah, setChip);
2977 break;
2978 case ATH9K_PM_FULL_SLEEP:
2979 ath9k_set_power_sleep(ah, setChip);
Sujith2660b812009-02-09 13:27:26 +05302980 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05302981 break;
2982 case ATH9K_PM_NETWORK_SLEEP:
2983 ath9k_set_power_network_sleep(ah, setChip);
2984 break;
2985 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002986 ath_print(common, ATH_DBG_FATAL,
2987 "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05302988 return false;
2989 }
Sujith2660b812009-02-09 13:27:26 +05302990 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05302991
2992 return status;
2993}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002994EXPORT_SYMBOL(ath9k_hw_setpower);
Sujithf1dc5602008-10-29 10:16:30 +05302995
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002996/*
2997 * Helper for ASPM support.
2998 *
2999 * Disable PLL when in L0s as well as receiver clock when in L1.
3000 * This power saving option must be enabled through the SerDes.
3001 *
3002 * Programming the SerDes must go through the same 288 bit serial shift
3003 * register as the other analog registers. Hence the 9 writes.
3004 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303005void ath9k_hw_configpcipowersave(struct ath_hw *ah, int restore, int power_off)
Sujithf1dc5602008-10-29 10:16:30 +05303006{
Sujithf1dc5602008-10-29 10:16:30 +05303007 u8 i;
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303008 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05303009
Sujith2660b812009-02-09 13:27:26 +05303010 if (ah->is_pciexpress != true)
Sujithf1dc5602008-10-29 10:16:30 +05303011 return;
3012
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08003013 /* Do not touch SerDes registers */
Sujith2660b812009-02-09 13:27:26 +05303014 if (ah->config.pcie_powersave_enable == 2)
Sujithf1dc5602008-10-29 10:16:30 +05303015 return;
3016
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08003017 /* Nothing to do on restore for 11N */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303018 if (!restore) {
3019 if (AR_SREV_9280_20_OR_LATER(ah)) {
3020 /*
3021 * AR9280 2.0 or later chips use SerDes values from the
3022 * initvals.h initialized depending on chipset during
3023 * ath9k_hw_init()
3024 */
3025 for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
3026 REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
3027 INI_RA(&ah->iniPcieSerdes, i, 1));
3028 }
3029 } else if (AR_SREV_9280(ah) &&
3030 (ah->hw_version.macRev == AR_SREV_REVISION_9280_10)) {
3031 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
3032 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
Sujithf1dc5602008-10-29 10:16:30 +05303033
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303034 /* RX shut off when elecidle is asserted */
3035 REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
3036 REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
3037 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
3038
3039 /* Shut off CLKREQ active in L1 */
3040 if (ah->config.pcie_clock_req)
3041 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
3042 else
3043 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
3044
3045 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
3046 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
3047 REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
3048
3049 /* Load the new settings */
3050 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
3051
3052 } else {
3053 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
3054 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
3055
3056 /* RX shut off when elecidle is asserted */
3057 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
3058 REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
3059 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
3060
3061 /*
3062 * Ignore ah->ah_config.pcie_clock_req setting for
3063 * pre-AR9280 11n
3064 */
3065 REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
3066
3067 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
3068 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
3069 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
3070
3071 /* Load the new settings */
3072 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
Sujithf1dc5602008-10-29 10:16:30 +05303073 }
Sujithf1dc5602008-10-29 10:16:30 +05303074
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303075 udelay(1000);
Sujithf1dc5602008-10-29 10:16:30 +05303076
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303077 /* set bit 19 to allow forcing of pcie core into L1 state */
3078 REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
Sujithf1dc5602008-10-29 10:16:30 +05303079
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303080 /* Several PCIe massages to ensure proper behaviour */
3081 if (ah->config.pcie_waen) {
3082 val = ah->config.pcie_waen;
3083 if (!power_off)
3084 val &= (~AR_WA_D3_L1_DISABLE);
3085 } else {
3086 if (AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
3087 AR_SREV_9287(ah)) {
3088 val = AR9285_WA_DEFAULT;
3089 if (!power_off)
3090 val &= (~AR_WA_D3_L1_DISABLE);
3091 } else if (AR_SREV_9280(ah)) {
3092 /*
3093 * On AR9280 chips bit 22 of 0x4004 needs to be
3094 * set otherwise card may disappear.
3095 */
3096 val = AR9280_WA_DEFAULT;
3097 if (!power_off)
3098 val &= (~AR_WA_D3_L1_DISABLE);
3099 } else
3100 val = AR_WA_DEFAULT;
3101 }
Sujithf1dc5602008-10-29 10:16:30 +05303102
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303103 REG_WRITE(ah, AR_WA, val);
Sujithf1dc5602008-10-29 10:16:30 +05303104 }
3105
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303106 if (power_off) {
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08003107 /*
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303108 * Set PCIe workaround bits
3109 * bit 14 in WA register (disable L1) should only
3110 * be set when device enters D3 and be cleared
3111 * when device comes back to D0.
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08003112 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303113 if (ah->config.pcie_waen) {
3114 if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE)
3115 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
3116 } else {
3117 if (((AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
3118 AR_SREV_9287(ah)) &&
3119 (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)) ||
3120 (AR_SREV_9280(ah) &&
3121 (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE))) {
3122 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
3123 }
3124 }
Sujithf1dc5602008-10-29 10:16:30 +05303125 }
3126}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003127EXPORT_SYMBOL(ath9k_hw_configpcipowersave);
Sujithf1dc5602008-10-29 10:16:30 +05303128
3129/**********************/
3130/* Interrupt Handling */
3131/**********************/
3132
Sujithcbe61d82009-02-09 13:27:12 +05303133bool ath9k_hw_intrpend(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003134{
3135 u32 host_isr;
3136
3137 if (AR_SREV_9100(ah))
3138 return true;
3139
3140 host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
3141 if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
3142 return true;
3143
3144 host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
3145 if ((host_isr & AR_INTR_SYNC_DEFAULT)
3146 && (host_isr != AR_INTR_SPURIOUS))
3147 return true;
3148
3149 return false;
3150}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003151EXPORT_SYMBOL(ath9k_hw_intrpend);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003152
Sujithcbe61d82009-02-09 13:27:12 +05303153bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003154{
3155 u32 isr = 0;
3156 u32 mask2 = 0;
Sujith2660b812009-02-09 13:27:26 +05303157 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003158 u32 sync_cause = 0;
3159 bool fatal_int = false;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003160 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003161
3162 if (!AR_SREV_9100(ah)) {
3163 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
3164 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
3165 == AR_RTC_STATUS_ON) {
3166 isr = REG_READ(ah, AR_ISR);
3167 }
3168 }
3169
Sujithf1dc5602008-10-29 10:16:30 +05303170 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
3171 AR_INTR_SYNC_DEFAULT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003172
3173 *masked = 0;
3174
3175 if (!isr && !sync_cause)
3176 return false;
3177 } else {
3178 *masked = 0;
3179 isr = REG_READ(ah, AR_ISR);
3180 }
3181
3182 if (isr) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003183 if (isr & AR_ISR_BCNMISC) {
3184 u32 isr2;
3185 isr2 = REG_READ(ah, AR_ISR_S2);
3186 if (isr2 & AR_ISR_S2_TIM)
3187 mask2 |= ATH9K_INT_TIM;
3188 if (isr2 & AR_ISR_S2_DTIM)
3189 mask2 |= ATH9K_INT_DTIM;
3190 if (isr2 & AR_ISR_S2_DTIMSYNC)
3191 mask2 |= ATH9K_INT_DTIMSYNC;
3192 if (isr2 & (AR_ISR_S2_CABEND))
3193 mask2 |= ATH9K_INT_CABEND;
3194 if (isr2 & AR_ISR_S2_GTT)
3195 mask2 |= ATH9K_INT_GTT;
3196 if (isr2 & AR_ISR_S2_CST)
3197 mask2 |= ATH9K_INT_CST;
Sujith4af9cf42009-02-12 10:06:47 +05303198 if (isr2 & AR_ISR_S2_TSFOOR)
3199 mask2 |= ATH9K_INT_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003200 }
3201
3202 isr = REG_READ(ah, AR_ISR_RAC);
3203 if (isr == 0xffffffff) {
3204 *masked = 0;
3205 return false;
3206 }
3207
3208 *masked = isr & ATH9K_INT_COMMON;
3209
Sujith0ef1f162009-03-30 15:28:35 +05303210 if (ah->config.intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003211 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
3212 *masked |= ATH9K_INT_RX;
3213 }
3214
3215 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
3216 *masked |= ATH9K_INT_RX;
3217 if (isr &
3218 (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
3219 AR_ISR_TXEOL)) {
3220 u32 s0_s, s1_s;
3221
3222 *masked |= ATH9K_INT_TX;
3223
3224 s0_s = REG_READ(ah, AR_ISR_S0_S);
Sujith2660b812009-02-09 13:27:26 +05303225 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
3226 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003227
3228 s1_s = REG_READ(ah, AR_ISR_S1_S);
Sujith2660b812009-02-09 13:27:26 +05303229 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
3230 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003231 }
3232
3233 if (isr & AR_ISR_RXORN) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003234 ath_print(common, ATH_DBG_INTERRUPT,
3235 "receive FIFO overrun interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003236 }
3237
3238 if (!AR_SREV_9100(ah)) {
Sujith60b67f52008-08-07 10:52:38 +05303239 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003240 u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
3241 if (isr5 & AR_ISR_S5_TIM_TIMER)
3242 *masked |= ATH9K_INT_TIM_TIMER;
3243 }
3244 }
3245
3246 *masked |= mask2;
3247 }
Sujithf1dc5602008-10-29 10:16:30 +05303248
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003249 if (AR_SREV_9100(ah))
3250 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303251
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303252 if (isr & AR_ISR_GENTMR) {
3253 u32 s5_s;
3254
3255 s5_s = REG_READ(ah, AR_ISR_S5_S);
3256 if (isr & AR_ISR_GENTMR) {
3257 ah->intr_gen_timer_trigger =
3258 MS(s5_s, AR_ISR_S5_GENTIMER_TRIG);
3259
3260 ah->intr_gen_timer_thresh =
3261 MS(s5_s, AR_ISR_S5_GENTIMER_THRESH);
3262
3263 if (ah->intr_gen_timer_trigger)
3264 *masked |= ATH9K_INT_GENTIMER;
3265
3266 }
3267 }
3268
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003269 if (sync_cause) {
3270 fatal_int =
3271 (sync_cause &
3272 (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
3273 ? true : false;
3274
3275 if (fatal_int) {
3276 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003277 ath_print(common, ATH_DBG_ANY,
3278 "received PCI FATAL interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003279 }
3280 if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003281 ath_print(common, ATH_DBG_ANY,
3282 "received PCI PERR interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003283 }
Steven Luoa89bff92009-04-12 02:57:54 -07003284 *masked |= ATH9K_INT_FATAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003285 }
3286 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003287 ath_print(common, ATH_DBG_INTERRUPT,
3288 "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003289 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
3290 REG_WRITE(ah, AR_RC, 0);
3291 *masked |= ATH9K_INT_FATAL;
3292 }
3293 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003294 ath_print(common, ATH_DBG_INTERRUPT,
3295 "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003296 }
3297
3298 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
3299 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
3300 }
Sujithf1dc5602008-10-29 10:16:30 +05303301
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003302 return true;
3303}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003304EXPORT_SYMBOL(ath9k_hw_getisr);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003305
Sujithcbe61d82009-02-09 13:27:12 +05303306enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003307{
Sujith2660b812009-02-09 13:27:26 +05303308 u32 omask = ah->mask_reg;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003309 u32 mask, mask2;
Sujith2660b812009-02-09 13:27:26 +05303310 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003311 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003312
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003313 ath_print(common, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003314
3315 if (omask & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003316 ath_print(common, ATH_DBG_INTERRUPT, "disable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003317 REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
3318 (void) REG_READ(ah, AR_IER);
3319 if (!AR_SREV_9100(ah)) {
3320 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
3321 (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
3322
3323 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
3324 (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
3325 }
3326 }
3327
3328 mask = ints & ATH9K_INT_COMMON;
3329 mask2 = 0;
3330
3331 if (ints & ATH9K_INT_TX) {
Sujith2660b812009-02-09 13:27:26 +05303332 if (ah->txok_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003333 mask |= AR_IMR_TXOK;
Sujith2660b812009-02-09 13:27:26 +05303334 if (ah->txdesc_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003335 mask |= AR_IMR_TXDESC;
Sujith2660b812009-02-09 13:27:26 +05303336 if (ah->txerr_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003337 mask |= AR_IMR_TXERR;
Sujith2660b812009-02-09 13:27:26 +05303338 if (ah->txeol_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003339 mask |= AR_IMR_TXEOL;
3340 }
3341 if (ints & ATH9K_INT_RX) {
3342 mask |= AR_IMR_RXERR;
Sujith0ef1f162009-03-30 15:28:35 +05303343 if (ah->config.intr_mitigation)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003344 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
3345 else
3346 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
Sujith60b67f52008-08-07 10:52:38 +05303347 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003348 mask |= AR_IMR_GENTMR;
3349 }
3350
3351 if (ints & (ATH9K_INT_BMISC)) {
3352 mask |= AR_IMR_BCNMISC;
3353 if (ints & ATH9K_INT_TIM)
3354 mask2 |= AR_IMR_S2_TIM;
3355 if (ints & ATH9K_INT_DTIM)
3356 mask2 |= AR_IMR_S2_DTIM;
3357 if (ints & ATH9K_INT_DTIMSYNC)
3358 mask2 |= AR_IMR_S2_DTIMSYNC;
3359 if (ints & ATH9K_INT_CABEND)
Sujith4af9cf42009-02-12 10:06:47 +05303360 mask2 |= AR_IMR_S2_CABEND;
3361 if (ints & ATH9K_INT_TSFOOR)
3362 mask2 |= AR_IMR_S2_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003363 }
3364
3365 if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
3366 mask |= AR_IMR_BCNMISC;
3367 if (ints & ATH9K_INT_GTT)
3368 mask2 |= AR_IMR_S2_GTT;
3369 if (ints & ATH9K_INT_CST)
3370 mask2 |= AR_IMR_S2_CST;
3371 }
3372
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003373 ath_print(common, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003374 REG_WRITE(ah, AR_IMR, mask);
3375 mask = REG_READ(ah, AR_IMR_S2) & ~(AR_IMR_S2_TIM |
3376 AR_IMR_S2_DTIM |
3377 AR_IMR_S2_DTIMSYNC |
3378 AR_IMR_S2_CABEND |
3379 AR_IMR_S2_CABTO |
3380 AR_IMR_S2_TSFOOR |
3381 AR_IMR_S2_GTT | AR_IMR_S2_CST);
3382 REG_WRITE(ah, AR_IMR_S2, mask | mask2);
Sujith2660b812009-02-09 13:27:26 +05303383 ah->mask_reg = ints;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003384
Sujith60b67f52008-08-07 10:52:38 +05303385 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003386 if (ints & ATH9K_INT_TIM_TIMER)
3387 REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
3388 else
3389 REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
3390 }
3391
3392 if (ints & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003393 ath_print(common, ATH_DBG_INTERRUPT, "enable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003394 REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
3395 if (!AR_SREV_9100(ah)) {
3396 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
3397 AR_INTR_MAC_IRQ);
3398 REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
3399
3400
3401 REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
3402 AR_INTR_SYNC_DEFAULT);
3403 REG_WRITE(ah, AR_INTR_SYNC_MASK,
3404 AR_INTR_SYNC_DEFAULT);
3405 }
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003406 ath_print(common, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
3407 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003408 }
3409
3410 return omask;
3411}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003412EXPORT_SYMBOL(ath9k_hw_set_interrupts);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003413
Sujithf1dc5602008-10-29 10:16:30 +05303414/*******************/
3415/* Beacon Handling */
3416/*******************/
3417
Sujithcbe61d82009-02-09 13:27:12 +05303418void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003419{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003420 int flags = 0;
3421
Sujith2660b812009-02-09 13:27:26 +05303422 ah->beacon_interval = beacon_period;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003423
Sujith2660b812009-02-09 13:27:26 +05303424 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08003425 case NL80211_IFTYPE_STATION:
3426 case NL80211_IFTYPE_MONITOR:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003427 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3428 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
3429 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
3430 flags |= AR_TBTT_TIMER_EN;
3431 break;
Colin McCabed97809d2008-12-01 13:38:55 -08003432 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04003433 case NL80211_IFTYPE_MESH_POINT:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003434 REG_SET_BIT(ah, AR_TXCFG,
3435 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
3436 REG_WRITE(ah, AR_NEXT_NDP_TIMER,
3437 TU_TO_USEC(next_beacon +
Sujith2660b812009-02-09 13:27:26 +05303438 (ah->atim_window ? ah->
3439 atim_window : 1)));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003440 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08003441 case NL80211_IFTYPE_AP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003442 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3443 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
3444 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05303445 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05303446 dma_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003447 REG_WRITE(ah, AR_NEXT_SWBA,
3448 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05303449 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05303450 sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003451 flags |=
3452 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
3453 break;
Colin McCabed97809d2008-12-01 13:38:55 -08003454 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003455 ath_print(ath9k_hw_common(ah), ATH_DBG_BEACON,
3456 "%s: unsupported opmode: %d\n",
3457 __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08003458 return;
3459 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003460 }
3461
3462 REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3463 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3464 REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
3465 REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
3466
3467 beacon_period &= ~ATH9K_BEACON_ENA;
3468 if (beacon_period & ATH9K_BEACON_RESET_TSF) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003469 ath9k_hw_reset_tsf(ah);
3470 }
3471
3472 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
3473}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003474EXPORT_SYMBOL(ath9k_hw_beaconinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003475
Sujithcbe61d82009-02-09 13:27:12 +05303476void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303477 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003478{
3479 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05303480 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003481 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003482
3483 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
3484
3485 REG_WRITE(ah, AR_BEACON_PERIOD,
3486 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3487 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
3488 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3489
3490 REG_RMW_FIELD(ah, AR_RSSI_THR,
3491 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
3492
3493 beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
3494
3495 if (bs->bs_sleepduration > beaconintval)
3496 beaconintval = bs->bs_sleepduration;
3497
3498 dtimperiod = bs->bs_dtimperiod;
3499 if (bs->bs_sleepduration > dtimperiod)
3500 dtimperiod = bs->bs_sleepduration;
3501
3502 if (beaconintval == dtimperiod)
3503 nextTbtt = bs->bs_nextdtim;
3504 else
3505 nextTbtt = bs->bs_nexttbtt;
3506
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003507 ath_print(common, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
3508 ath_print(common, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
3509 ath_print(common, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
3510 ath_print(common, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003511
3512 REG_WRITE(ah, AR_NEXT_DTIM,
3513 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
3514 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
3515
3516 REG_WRITE(ah, AR_SLEEP1,
3517 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
3518 | AR_SLEEP1_ASSUME_DTIM);
3519
Sujith60b67f52008-08-07 10:52:38 +05303520 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003521 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
3522 else
3523 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
3524
3525 REG_WRITE(ah, AR_SLEEP2,
3526 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
3527
3528 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
3529 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
3530
3531 REG_SET_BIT(ah, AR_TIMER_MODE,
3532 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
3533 AR_DTIM_TIMER_EN);
3534
Sujith4af9cf42009-02-12 10:06:47 +05303535 /* TSF Out of Range Threshold */
3536 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003537}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003538EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003539
Sujithf1dc5602008-10-29 10:16:30 +05303540/*******************/
3541/* HW Capabilities */
3542/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003543
Sujitheef7a572009-03-30 15:28:28 +05303544void ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003545{
Sujith2660b812009-02-09 13:27:26 +05303546 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003547 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003548 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003549 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003550
Sujithf1dc5602008-10-29 10:16:30 +05303551 u16 capField = 0, eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003552
Sujithf74df6f2009-02-09 13:27:24 +05303553 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003554 regulatory->current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303555
Sujithf74df6f2009-02-09 13:27:24 +05303556 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
Sujithfec0de12009-02-12 10:06:43 +05303557 if (AR_SREV_9285_10_OR_LATER(ah))
3558 eeval |= AR9285_RDEXT_DEFAULT;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003559 regulatory->current_rd_ext = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303560
Sujithf74df6f2009-02-09 13:27:24 +05303561 capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
Sujithf1dc5602008-10-29 10:16:30 +05303562
Sujith2660b812009-02-09 13:27:26 +05303563 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05303564 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003565 if (regulatory->current_rd == 0x64 ||
3566 regulatory->current_rd == 0x65)
3567 regulatory->current_rd += 5;
3568 else if (regulatory->current_rd == 0x41)
3569 regulatory->current_rd = 0x43;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003570 ath_print(common, ATH_DBG_REGULATORY,
3571 "regdomain mapped to 0x%x\n", regulatory->current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003572 }
Sujithdc2222a2008-08-14 13:26:55 +05303573
Sujithf74df6f2009-02-09 13:27:24 +05303574 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Sujithf1dc5602008-10-29 10:16:30 +05303575 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003576
Sujithf1dc5602008-10-29 10:16:30 +05303577 if (eeval & AR5416_OPFLAGS_11A) {
3578 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303579 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303580 if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
3581 set_bit(ATH9K_MODE_11NA_HT20,
3582 pCap->wireless_modes);
3583 if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
3584 set_bit(ATH9K_MODE_11NA_HT40PLUS,
3585 pCap->wireless_modes);
3586 set_bit(ATH9K_MODE_11NA_HT40MINUS,
3587 pCap->wireless_modes);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003588 }
3589 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003590 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003591
Sujithf1dc5602008-10-29 10:16:30 +05303592 if (eeval & AR5416_OPFLAGS_11G) {
Sujithf1dc5602008-10-29 10:16:30 +05303593 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303594 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303595 if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
3596 set_bit(ATH9K_MODE_11NG_HT20,
3597 pCap->wireless_modes);
3598 if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
3599 set_bit(ATH9K_MODE_11NG_HT40PLUS,
3600 pCap->wireless_modes);
3601 set_bit(ATH9K_MODE_11NG_HT40MINUS,
3602 pCap->wireless_modes);
3603 }
3604 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003605 }
Sujithf1dc5602008-10-29 10:16:30 +05303606
Sujithf74df6f2009-02-09 13:27:24 +05303607 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003608 /*
3609 * For AR9271 we will temporarilly uses the rx chainmax as read from
3610 * the EEPROM.
3611 */
Sujith8147f5d2009-02-20 15:13:23 +05303612 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003613 !(eeval & AR5416_OPFLAGS_11A) &&
3614 !(AR_SREV_9271(ah)))
3615 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
Sujith8147f5d2009-02-20 15:13:23 +05303616 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
3617 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003618 /* Use rx_chainmask from EEPROM. */
Sujith8147f5d2009-02-20 15:13:23 +05303619 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05303620
Sujithd535a422009-02-09 13:27:06 +05303621 if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0)))
Sujith2660b812009-02-09 13:27:26 +05303622 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05303623
3624 pCap->low_2ghz_chan = 2312;
3625 pCap->high_2ghz_chan = 2732;
3626
3627 pCap->low_5ghz_chan = 4920;
3628 pCap->high_5ghz_chan = 6100;
3629
3630 pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
3631 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
3632 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
3633
3634 pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
3635 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
3636 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
3637
Sujith2660b812009-02-09 13:27:26 +05303638 if (ah->config.ht_enable)
Sujithf1dc5602008-10-29 10:16:30 +05303639 pCap->hw_caps |= ATH9K_HW_CAP_HT;
3640 else
3641 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
3642
3643 pCap->hw_caps |= ATH9K_HW_CAP_GTT;
3644 pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
3645 pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
3646 pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
3647
3648 if (capField & AR_EEPROM_EEPCAP_MAXQCU)
3649 pCap->total_queues =
3650 MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
3651 else
3652 pCap->total_queues = ATH9K_NUM_TX_QUEUES;
3653
3654 if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
3655 pCap->keycache_size =
3656 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
3657 else
3658 pCap->keycache_size = AR_KEYTABLE_SIZE;
3659
3660 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
Sujithf1dc5602008-10-29 10:16:30 +05303661 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
3662
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303663 if (AR_SREV_9285_10_OR_LATER(ah))
3664 pCap->num_gpio_pins = AR9285_NUM_GPIO;
3665 else if (AR_SREV_9280_10_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303666 pCap->num_gpio_pins = AR928X_NUM_GPIO;
3667 else
3668 pCap->num_gpio_pins = AR_NUM_GPIO;
3669
Sujithf1dc5602008-10-29 10:16:30 +05303670 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
3671 pCap->hw_caps |= ATH9K_HW_CAP_CST;
3672 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
3673 } else {
3674 pCap->rts_aggr_limit = (8 * 1024);
3675 }
3676
3677 pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
3678
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05303679#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05303680 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
3681 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
3682 ah->rfkill_gpio =
3683 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
3684 ah->rfkill_polarity =
3685 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05303686
3687 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
3688 }
3689#endif
3690
Vivek Natarajana3ca95fb2009-09-17 09:29:07 +05303691 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
Sujithf1dc5602008-10-29 10:16:30 +05303692
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05303693 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303694 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
3695 else
3696 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
3697
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003698 if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) {
Sujithf1dc5602008-10-29 10:16:30 +05303699 pCap->reg_cap =
3700 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3701 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
3702 AR_EEPROM_EEREGCAP_EN_KK_U2 |
3703 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
3704 } else {
3705 pCap->reg_cap =
3706 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3707 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
3708 }
3709
Senthil Balasubramanianebb90cf2009-09-18 15:07:33 +05303710 /* Advertise midband for AR5416 with FCC midband set in eeprom */
3711 if (regulatory->current_rd_ext & (1 << REG_EXT_FCC_MIDBAND) &&
3712 AR_SREV_5416(ah))
3713 pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
Sujithf1dc5602008-10-29 10:16:30 +05303714
3715 pCap->num_antcfg_5ghz =
Sujithf74df6f2009-02-09 13:27:24 +05303716 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303717 pCap->num_antcfg_2ghz =
Sujithf74df6f2009-02-09 13:27:24 +05303718 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303719
Vasanthakumar Thiagarajanfe129462009-09-09 15:25:50 +05303720 if (AR_SREV_9280_10_OR_LATER(ah) &&
Luis R. Rodrigueza36cfbc2009-09-09 16:05:32 -07003721 ath9k_hw_btcoex_supported(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003722 btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO;
3723 btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO;
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05303724
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303725 if (AR_SREV_9285(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003726 btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
3727 btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303728 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003729 btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303730 }
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05303731 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003732 btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE;
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303733 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003734}
3735
Sujithcbe61d82009-02-09 13:27:12 +05303736bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303737 u32 capability, u32 *result)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003738{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003739 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05303740 switch (type) {
3741 case ATH9K_CAP_CIPHER:
3742 switch (capability) {
3743 case ATH9K_CIPHER_AES_CCM:
3744 case ATH9K_CIPHER_AES_OCB:
3745 case ATH9K_CIPHER_TKIP:
3746 case ATH9K_CIPHER_WEP:
3747 case ATH9K_CIPHER_MIC:
3748 case ATH9K_CIPHER_CLR:
3749 return true;
3750 default:
3751 return false;
3752 }
3753 case ATH9K_CAP_TKIP_MIC:
3754 switch (capability) {
3755 case 0:
3756 return true;
3757 case 1:
Sujith2660b812009-02-09 13:27:26 +05303758 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303759 AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
3760 false;
3761 }
3762 case ATH9K_CAP_TKIP_SPLIT:
Sujith2660b812009-02-09 13:27:26 +05303763 return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ?
Sujithf1dc5602008-10-29 10:16:30 +05303764 false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303765 case ATH9K_CAP_DIVERSITY:
3766 return (REG_READ(ah, AR_PHY_CCK_DETECT) &
3767 AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV) ?
3768 true : false;
Sujithf1dc5602008-10-29 10:16:30 +05303769 case ATH9K_CAP_MCAST_KEYSRCH:
3770 switch (capability) {
3771 case 0:
3772 return true;
3773 case 1:
3774 if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
3775 return false;
3776 } else {
Sujith2660b812009-02-09 13:27:26 +05303777 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303778 AR_STA_ID1_MCAST_KSRCH) ? true :
3779 false;
3780 }
3781 }
3782 return false;
Sujithf1dc5602008-10-29 10:16:30 +05303783 case ATH9K_CAP_TXPOW:
3784 switch (capability) {
3785 case 0:
3786 return 0;
3787 case 1:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003788 *result = regulatory->power_limit;
Sujithf1dc5602008-10-29 10:16:30 +05303789 return 0;
3790 case 2:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003791 *result = regulatory->max_power_level;
Sujithf1dc5602008-10-29 10:16:30 +05303792 return 0;
3793 case 3:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003794 *result = regulatory->tp_scale;
Sujithf1dc5602008-10-29 10:16:30 +05303795 return 0;
3796 }
3797 return false;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05303798 case ATH9K_CAP_DS:
3799 return (AR_SREV_9280_20_OR_LATER(ah) &&
3800 (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1))
3801 ? false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303802 default:
3803 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003804 }
Sujithf1dc5602008-10-29 10:16:30 +05303805}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003806EXPORT_SYMBOL(ath9k_hw_getcapability);
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003807
Sujithcbe61d82009-02-09 13:27:12 +05303808bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303809 u32 capability, u32 setting, int *status)
3810{
Sujithf1dc5602008-10-29 10:16:30 +05303811 u32 v;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003812
Sujithf1dc5602008-10-29 10:16:30 +05303813 switch (type) {
3814 case ATH9K_CAP_TKIP_MIC:
3815 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303816 ah->sta_id1_defaults |=
Sujithf1dc5602008-10-29 10:16:30 +05303817 AR_STA_ID1_CRPT_MIC_ENABLE;
3818 else
Sujith2660b812009-02-09 13:27:26 +05303819 ah->sta_id1_defaults &=
Sujithf1dc5602008-10-29 10:16:30 +05303820 ~AR_STA_ID1_CRPT_MIC_ENABLE;
3821 return true;
3822 case ATH9K_CAP_DIVERSITY:
3823 v = REG_READ(ah, AR_PHY_CCK_DETECT);
3824 if (setting)
3825 v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3826 else
3827 v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3828 REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
3829 return true;
3830 case ATH9K_CAP_MCAST_KEYSRCH:
3831 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303832 ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303833 else
Sujith2660b812009-02-09 13:27:26 +05303834 ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303835 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303836 default:
3837 return false;
3838 }
3839}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003840EXPORT_SYMBOL(ath9k_hw_setcapability);
Sujithf1dc5602008-10-29 10:16:30 +05303841
3842/****************************/
3843/* GPIO / RFKILL / Antennae */
3844/****************************/
3845
Sujithcbe61d82009-02-09 13:27:12 +05303846static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303847 u32 gpio, u32 type)
3848{
3849 int addr;
3850 u32 gpio_shift, tmp;
3851
3852 if (gpio > 11)
3853 addr = AR_GPIO_OUTPUT_MUX3;
3854 else if (gpio > 5)
3855 addr = AR_GPIO_OUTPUT_MUX2;
3856 else
3857 addr = AR_GPIO_OUTPUT_MUX1;
3858
3859 gpio_shift = (gpio % 6) * 5;
3860
3861 if (AR_SREV_9280_20_OR_LATER(ah)
3862 || (addr != AR_GPIO_OUTPUT_MUX1)) {
3863 REG_RMW(ah, addr, (type << gpio_shift),
3864 (0x1f << gpio_shift));
3865 } else {
3866 tmp = REG_READ(ah, addr);
3867 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
3868 tmp &= ~(0x1f << gpio_shift);
3869 tmp |= (type << gpio_shift);
3870 REG_WRITE(ah, addr, tmp);
3871 }
3872}
3873
Sujithcbe61d82009-02-09 13:27:12 +05303874void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303875{
3876 u32 gpio_shift;
3877
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07003878 BUG_ON(gpio >= ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05303879
3880 gpio_shift = gpio << 1;
3881
3882 REG_RMW(ah,
3883 AR_GPIO_OE_OUT,
3884 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
3885 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3886}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003887EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
Sujithf1dc5602008-10-29 10:16:30 +05303888
Sujithcbe61d82009-02-09 13:27:12 +05303889u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303890{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303891#define MS_REG_READ(x, y) \
3892 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
3893
Sujith2660b812009-02-09 13:27:26 +05303894 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05303895 return 0xffffffff;
3896
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05303897 if (AR_SREV_9287_10_OR_LATER(ah))
3898 return MS_REG_READ(AR9287, gpio) != 0;
3899 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303900 return MS_REG_READ(AR9285, gpio) != 0;
3901 else if (AR_SREV_9280_10_OR_LATER(ah))
3902 return MS_REG_READ(AR928X, gpio) != 0;
3903 else
3904 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05303905}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003906EXPORT_SYMBOL(ath9k_hw_gpio_get);
Sujithf1dc5602008-10-29 10:16:30 +05303907
Sujithcbe61d82009-02-09 13:27:12 +05303908void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05303909 u32 ah_signal_type)
3910{
3911 u32 gpio_shift;
3912
3913 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
3914
3915 gpio_shift = 2 * gpio;
3916
3917 REG_RMW(ah,
3918 AR_GPIO_OE_OUT,
3919 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
3920 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3921}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003922EXPORT_SYMBOL(ath9k_hw_cfg_output);
Sujithf1dc5602008-10-29 10:16:30 +05303923
Sujithcbe61d82009-02-09 13:27:12 +05303924void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05303925{
3926 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
3927 AR_GPIO_BIT(gpio));
3928}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003929EXPORT_SYMBOL(ath9k_hw_set_gpio);
Sujithf1dc5602008-10-29 10:16:30 +05303930
Sujithcbe61d82009-02-09 13:27:12 +05303931u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303932{
3933 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
3934}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003935EXPORT_SYMBOL(ath9k_hw_getdefantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303936
Sujithcbe61d82009-02-09 13:27:12 +05303937void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05303938{
3939 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
3940}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003941EXPORT_SYMBOL(ath9k_hw_setantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303942
Sujithcbe61d82009-02-09 13:27:12 +05303943bool ath9k_hw_setantennaswitch(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303944 enum ath9k_ant_setting settings,
3945 struct ath9k_channel *chan,
3946 u8 *tx_chainmask,
3947 u8 *rx_chainmask,
3948 u8 *antenna_cfgd)
3949{
Sujithf1dc5602008-10-29 10:16:30 +05303950 static u8 tx_chainmask_cfg, rx_chainmask_cfg;
3951
3952 if (AR_SREV_9280(ah)) {
3953 if (!tx_chainmask_cfg) {
3954
3955 tx_chainmask_cfg = *tx_chainmask;
3956 rx_chainmask_cfg = *rx_chainmask;
3957 }
3958
3959 switch (settings) {
3960 case ATH9K_ANT_FIXED_A:
3961 *tx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3962 *rx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3963 *antenna_cfgd = true;
3964 break;
3965 case ATH9K_ANT_FIXED_B:
Sujith2660b812009-02-09 13:27:26 +05303966 if (ah->caps.tx_chainmask >
Sujithf1dc5602008-10-29 10:16:30 +05303967 ATH9K_ANTENNA1_CHAINMASK) {
3968 *tx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3969 }
3970 *rx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3971 *antenna_cfgd = true;
3972 break;
3973 case ATH9K_ANT_VARIABLE:
3974 *tx_chainmask = tx_chainmask_cfg;
3975 *rx_chainmask = rx_chainmask_cfg;
3976 *antenna_cfgd = true;
3977 break;
3978 default:
3979 break;
3980 }
3981 } else {
Sujith1cf68732009-08-13 09:34:32 +05303982 ah->config.diversity_control = settings;
Sujithf1dc5602008-10-29 10:16:30 +05303983 }
3984
3985 return true;
3986}
3987
3988/*********************/
3989/* General Operation */
3990/*********************/
3991
Sujithcbe61d82009-02-09 13:27:12 +05303992u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303993{
3994 u32 bits = REG_READ(ah, AR_RX_FILTER);
3995 u32 phybits = REG_READ(ah, AR_PHY_ERR);
3996
3997 if (phybits & AR_PHY_ERR_RADAR)
3998 bits |= ATH9K_RX_FILTER_PHYRADAR;
3999 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
4000 bits |= ATH9K_RX_FILTER_PHYERR;
4001
4002 return bits;
4003}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004004EXPORT_SYMBOL(ath9k_hw_getrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05304005
Sujithcbe61d82009-02-09 13:27:12 +05304006void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05304007{
4008 u32 phybits;
4009
Sujith7ea310b2009-09-03 12:08:43 +05304010 REG_WRITE(ah, AR_RX_FILTER, bits);
4011
Sujithf1dc5602008-10-29 10:16:30 +05304012 phybits = 0;
4013 if (bits & ATH9K_RX_FILTER_PHYRADAR)
4014 phybits |= AR_PHY_ERR_RADAR;
4015 if (bits & ATH9K_RX_FILTER_PHYERR)
4016 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
4017 REG_WRITE(ah, AR_PHY_ERR, phybits);
4018
4019 if (phybits)
4020 REG_WRITE(ah, AR_RXCFG,
4021 REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
4022 else
4023 REG_WRITE(ah, AR_RXCFG,
4024 REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
4025}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004026EXPORT_SYMBOL(ath9k_hw_setrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05304027
Sujithcbe61d82009-02-09 13:27:12 +05304028bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304029{
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05304030 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
4031 return false;
4032
4033 ath9k_hw_init_pll(ah, NULL);
4034 return true;
Sujithf1dc5602008-10-29 10:16:30 +05304035}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004036EXPORT_SYMBOL(ath9k_hw_phy_disable);
Sujithf1dc5602008-10-29 10:16:30 +05304037
Sujithcbe61d82009-02-09 13:27:12 +05304038bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304039{
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07004040 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05304041 return false;
4042
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05304043 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
4044 return false;
4045
4046 ath9k_hw_init_pll(ah, NULL);
4047 return true;
Sujithf1dc5602008-10-29 10:16:30 +05304048}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004049EXPORT_SYMBOL(ath9k_hw_disable);
Sujithf1dc5602008-10-29 10:16:30 +05304050
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07004051void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
Sujithf1dc5602008-10-29 10:16:30 +05304052{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07004053 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujith2660b812009-02-09 13:27:26 +05304054 struct ath9k_channel *chan = ah->curchan;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08004055 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05304056
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07004057 regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER);
Sujithf1dc5602008-10-29 10:16:30 +05304058
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07004059 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07004060 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07004061 channel->max_antenna_gain * 2,
4062 channel->max_power * 2,
4063 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07004064 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05304065}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004066EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
Sujithf1dc5602008-10-29 10:16:30 +05304067
Sujithcbe61d82009-02-09 13:27:12 +05304068void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac)
Sujithf1dc5602008-10-29 10:16:30 +05304069{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07004070 memcpy(ath9k_hw_common(ah)->macaddr, mac, ETH_ALEN);
Sujithf1dc5602008-10-29 10:16:30 +05304071}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004072EXPORT_SYMBOL(ath9k_hw_setmac);
Sujithf1dc5602008-10-29 10:16:30 +05304073
Sujithcbe61d82009-02-09 13:27:12 +05304074void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304075{
Sujith2660b812009-02-09 13:27:26 +05304076 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05304077}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004078EXPORT_SYMBOL(ath9k_hw_setopmode);
Sujithf1dc5602008-10-29 10:16:30 +05304079
Sujithcbe61d82009-02-09 13:27:12 +05304080void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05304081{
4082 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
4083 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
4084}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004085EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
Sujithf1dc5602008-10-29 10:16:30 +05304086
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07004087void ath9k_hw_write_associd(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304088{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07004089 struct ath_common *common = ath9k_hw_common(ah);
4090
4091 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
4092 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
4093 ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05304094}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004095EXPORT_SYMBOL(ath9k_hw_write_associd);
Sujithf1dc5602008-10-29 10:16:30 +05304096
Sujithcbe61d82009-02-09 13:27:12 +05304097u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304098{
4099 u64 tsf;
4100
4101 tsf = REG_READ(ah, AR_TSF_U32);
4102 tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
4103
4104 return tsf;
4105}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004106EXPORT_SYMBOL(ath9k_hw_gettsf64);
Sujithf1dc5602008-10-29 10:16:30 +05304107
Sujithcbe61d82009-02-09 13:27:12 +05304108void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004109{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004110 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01004111 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004112}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004113EXPORT_SYMBOL(ath9k_hw_settsf64);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004114
Sujithcbe61d82009-02-09 13:27:12 +05304115void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304116{
Gabor Juhosf9b604f2009-06-21 00:02:15 +02004117 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
4118 AH_TSF_WRITE_TIMEOUT))
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004119 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
4120 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
Gabor Juhosf9b604f2009-06-21 00:02:15 +02004121
Sujithf1dc5602008-10-29 10:16:30 +05304122 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004123}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004124EXPORT_SYMBOL(ath9k_hw_reset_tsf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004125
Sujith54e4cec2009-08-07 09:45:09 +05304126void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004127{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004128 if (setting)
Sujith2660b812009-02-09 13:27:26 +05304129 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004130 else
Sujith2660b812009-02-09 13:27:26 +05304131 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004132}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004133EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004134
Sujithcbe61d82009-02-09 13:27:12 +05304135bool ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004136{
Sujithf1dc5602008-10-29 10:16:30 +05304137 if (us < ATH9K_SLOT_TIME_9 || us > ath9k_hw_mac_to_usec(ah, 0xffff)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004138 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
4139 "bad slot time %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05304140 ah->slottime = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05304141 return false;
4142 } else {
4143 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05304144 ah->slottime = us;
Sujithf1dc5602008-10-29 10:16:30 +05304145 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004146 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004147}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004148EXPORT_SYMBOL(ath9k_hw_setslottime);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004149
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07004150void ath9k_hw_set11nmac2040(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004151{
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07004152 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithf1dc5602008-10-29 10:16:30 +05304153 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004154
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07004155 if (conf_is_ht40(conf) && !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05304156 macmode = AR_2040_JOINED_RX_CLEAR;
4157 else
4158 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004159
Sujithf1dc5602008-10-29 10:16:30 +05304160 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004161}
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304162
4163/* HW Generic timers configuration */
4164
4165static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
4166{
4167 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4168 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4169 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4170 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4171 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4172 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4173 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4174 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4175 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
4176 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
4177 AR_NDP2_TIMER_MODE, 0x0002},
4178 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
4179 AR_NDP2_TIMER_MODE, 0x0004},
4180 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
4181 AR_NDP2_TIMER_MODE, 0x0008},
4182 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
4183 AR_NDP2_TIMER_MODE, 0x0010},
4184 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
4185 AR_NDP2_TIMER_MODE, 0x0020},
4186 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
4187 AR_NDP2_TIMER_MODE, 0x0040},
4188 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
4189 AR_NDP2_TIMER_MODE, 0x0080}
4190};
4191
4192/* HW generic timer primitives */
4193
4194/* compute and clear index of rightmost 1 */
4195static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
4196{
4197 u32 b;
4198
4199 b = *mask;
4200 b &= (0-b);
4201 *mask &= ~b;
4202 b *= debruijn32;
4203 b >>= 27;
4204
4205 return timer_table->gen_timer_index[b];
4206}
4207
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05304208u32 ath9k_hw_gettsf32(struct ath_hw *ah)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304209{
4210 return REG_READ(ah, AR_TSF_L32);
4211}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004212EXPORT_SYMBOL(ath9k_hw_gettsf32);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304213
4214struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
4215 void (*trigger)(void *),
4216 void (*overflow)(void *),
4217 void *arg,
4218 u8 timer_index)
4219{
4220 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4221 struct ath_gen_timer *timer;
4222
4223 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
4224
4225 if (timer == NULL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004226 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
4227 "Failed to allocate memory"
4228 "for hw timer[%d]\n", timer_index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304229 return NULL;
4230 }
4231
4232 /* allocate a hardware generic timer slot */
4233 timer_table->timers[timer_index] = timer;
4234 timer->index = timer_index;
4235 timer->trigger = trigger;
4236 timer->overflow = overflow;
4237 timer->arg = arg;
4238
4239 return timer;
4240}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004241EXPORT_SYMBOL(ath_gen_timer_alloc);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304242
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07004243void ath9k_hw_gen_timer_start(struct ath_hw *ah,
4244 struct ath_gen_timer *timer,
4245 u32 timer_next,
4246 u32 timer_period)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304247{
4248 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4249 u32 tsf;
4250
4251 BUG_ON(!timer_period);
4252
4253 set_bit(timer->index, &timer_table->timer_mask.timer_bits);
4254
4255 tsf = ath9k_hw_gettsf32(ah);
4256
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004257 ath_print(ath9k_hw_common(ah), ATH_DBG_HWTIMER,
4258 "curent tsf %x period %x"
4259 "timer_next %x\n", tsf, timer_period, timer_next);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304260
4261 /*
4262 * Pull timer_next forward if the current TSF already passed it
4263 * because of software latency
4264 */
4265 if (timer_next < tsf)
4266 timer_next = tsf + timer_period;
4267
4268 /*
4269 * Program generic timer registers
4270 */
4271 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
4272 timer_next);
4273 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
4274 timer_period);
4275 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
4276 gen_tmr_configuration[timer->index].mode_mask);
4277
4278 /* Enable both trigger and thresh interrupt masks */
4279 REG_SET_BIT(ah, AR_IMR_S5,
4280 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
4281 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304282}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004283EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304284
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07004285void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304286{
4287 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4288
4289 if ((timer->index < AR_FIRST_NDP_TIMER) ||
4290 (timer->index >= ATH_MAX_GEN_TIMER)) {
4291 return;
4292 }
4293
4294 /* Clear generic timer enable bits. */
4295 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
4296 gen_tmr_configuration[timer->index].mode_mask);
4297
4298 /* Disable both trigger and thresh interrupt masks */
4299 REG_CLR_BIT(ah, AR_IMR_S5,
4300 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
4301 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
4302
4303 clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304304}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004305EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304306
4307void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
4308{
4309 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4310
4311 /* free the hardware generic timer slot */
4312 timer_table->timers[timer->index] = NULL;
4313 kfree(timer);
4314}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004315EXPORT_SYMBOL(ath_gen_timer_free);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304316
4317/*
4318 * Generic Timer Interrupts handling
4319 */
4320void ath_gen_timer_isr(struct ath_hw *ah)
4321{
4322 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4323 struct ath_gen_timer *timer;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004324 struct ath_common *common = ath9k_hw_common(ah);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304325 u32 trigger_mask, thresh_mask, index;
4326
4327 /* get hardware generic timer interrupt status */
4328 trigger_mask = ah->intr_gen_timer_trigger;
4329 thresh_mask = ah->intr_gen_timer_thresh;
4330 trigger_mask &= timer_table->timer_mask.val;
4331 thresh_mask &= timer_table->timer_mask.val;
4332
4333 trigger_mask &= ~thresh_mask;
4334
4335 while (thresh_mask) {
4336 index = rightmost_index(timer_table, &thresh_mask);
4337 timer = timer_table->timers[index];
4338 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004339 ath_print(common, ATH_DBG_HWTIMER,
4340 "TSF overflow for Gen timer %d\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304341 timer->overflow(timer->arg);
4342 }
4343
4344 while (trigger_mask) {
4345 index = rightmost_index(timer_table, &trigger_mask);
4346 timer = timer_table->timers[index];
4347 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004348 ath_print(common, ATH_DBG_HWTIMER,
4349 "Gen timer[%d] trigger\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304350 timer->trigger(timer->arg);
4351 }
4352}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004353EXPORT_SYMBOL(ath_gen_timer_isr);
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04004354
4355static struct {
4356 u32 version;
4357 const char * name;
4358} ath_mac_bb_names[] = {
4359 /* Devices with external radios */
4360 { AR_SREV_VERSION_5416_PCI, "5416" },
4361 { AR_SREV_VERSION_5416_PCIE, "5418" },
4362 { AR_SREV_VERSION_9100, "9100" },
4363 { AR_SREV_VERSION_9160, "9160" },
4364 /* Single-chip solutions */
4365 { AR_SREV_VERSION_9280, "9280" },
4366 { AR_SREV_VERSION_9285, "9285" },
Luis R. Rodriguez11158472009-10-27 12:59:35 -04004367 { AR_SREV_VERSION_9287, "9287" },
4368 { AR_SREV_VERSION_9271, "9271" },
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04004369};
4370
4371/* For devices with external radios */
4372static struct {
4373 u16 version;
4374 const char * name;
4375} ath_rf_names[] = {
4376 { 0, "5133" },
4377 { AR_RAD5133_SREV_MAJOR, "5133" },
4378 { AR_RAD5122_SREV_MAJOR, "5122" },
4379 { AR_RAD2133_SREV_MAJOR, "2133" },
4380 { AR_RAD2122_SREV_MAJOR, "2122" }
4381};
4382
4383/*
4384 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
4385 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04004386static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04004387{
4388 int i;
4389
4390 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
4391 if (ath_mac_bb_names[i].version == mac_bb_version) {
4392 return ath_mac_bb_names[i].name;
4393 }
4394 }
4395
4396 return "????";
4397}
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04004398
4399/*
4400 * Return the RF name. "????" is returned if the RF is unknown.
4401 * Used for devices with external radios.
4402 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04004403static const char *ath9k_hw_rf_name(u16 rf_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04004404{
4405 int i;
4406
4407 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
4408 if (ath_rf_names[i].version == rf_version) {
4409 return ath_rf_names[i].name;
4410 }
4411 }
4412
4413 return "????";
4414}
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04004415
4416void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
4417{
4418 int used;
4419
4420 /* chipsets >= AR9280 are single-chip */
4421 if (AR_SREV_9280_10_OR_LATER(ah)) {
4422 used = snprintf(hw_name, len,
4423 "Atheros AR%s Rev:%x",
4424 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
4425 ah->hw_version.macRev);
4426 }
4427 else {
4428 used = snprintf(hw_name, len,
4429 "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
4430 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
4431 ah->hw_version.macRev,
4432 ath9k_hw_rf_name((ah->hw_version.analog5GhzRev &
4433 AR_RADIO_SREV_MAJOR)),
4434 ah->hw_version.phyRev);
4435 }
4436
4437 hw_name[used] = '\0';
4438}
4439EXPORT_SYMBOL(ath9k_hw_name);