blob: 7cee89b81fce38a2f3d6433b529ed68b201f5b91 [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)) {
Luis R. Rodriguez85643282009-10-19 02:33:33 -0400665 INIT_INI_ARRAY(&ah->iniModes, ar9271Modes_9271,
666 ARRAY_SIZE(ar9271Modes_9271), 6);
667 INIT_INI_ARRAY(&ah->iniCommon, ar9271Common_9271,
668 ARRAY_SIZE(ar9271Common_9271), 2);
669 INIT_INI_ARRAY(&ah->iniModes_9271_1_0_only,
670 ar9271Modes_9271_1_0_only,
671 ARRAY_SIZE(ar9271Modes_9271_1_0_only), 6);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400672 return;
673 }
674
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530675 if (AR_SREV_9287_11_OR_LATER(ah)) {
676 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_1,
677 ARRAY_SIZE(ar9287Modes_9287_1_1), 6);
678 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_1,
679 ARRAY_SIZE(ar9287Common_9287_1_1), 2);
680 if (ah->config.pcie_clock_req)
681 INIT_INI_ARRAY(&ah->iniPcieSerdes,
682 ar9287PciePhy_clkreq_off_L1_9287_1_1,
683 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_1), 2);
684 else
685 INIT_INI_ARRAY(&ah->iniPcieSerdes,
686 ar9287PciePhy_clkreq_always_on_L1_9287_1_1,
687 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_1),
688 2);
689 } else if (AR_SREV_9287_10_OR_LATER(ah)) {
690 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_0,
691 ARRAY_SIZE(ar9287Modes_9287_1_0), 6);
692 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_0,
693 ARRAY_SIZE(ar9287Common_9287_1_0), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700694
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530695 if (ah->config.pcie_clock_req)
696 INIT_INI_ARRAY(&ah->iniPcieSerdes,
697 ar9287PciePhy_clkreq_off_L1_9287_1_0,
698 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_0), 2);
699 else
700 INIT_INI_ARRAY(&ah->iniPcieSerdes,
701 ar9287PciePhy_clkreq_always_on_L1_9287_1_0,
702 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_0),
703 2);
704 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
705
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530706
Sujith2660b812009-02-09 13:27:26 +0530707 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530708 ARRAY_SIZE(ar9285Modes_9285_1_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530709 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530710 ARRAY_SIZE(ar9285Common_9285_1_2), 2);
711
Sujith2660b812009-02-09 13:27:26 +0530712 if (ah->config.pcie_clock_req) {
713 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530714 ar9285PciePhy_clkreq_off_L1_9285_1_2,
715 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2);
716 } else {
Sujith2660b812009-02-09 13:27:26 +0530717 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530718 ar9285PciePhy_clkreq_always_on_L1_9285_1_2,
719 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2),
720 2);
721 }
722 } else if (AR_SREV_9285_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530723 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530724 ARRAY_SIZE(ar9285Modes_9285), 6);
Sujith2660b812009-02-09 13:27:26 +0530725 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530726 ARRAY_SIZE(ar9285Common_9285), 2);
727
Sujith2660b812009-02-09 13:27:26 +0530728 if (ah->config.pcie_clock_req) {
729 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530730 ar9285PciePhy_clkreq_off_L1_9285,
731 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2);
732 } else {
Sujith2660b812009-02-09 13:27:26 +0530733 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530734 ar9285PciePhy_clkreq_always_on_L1_9285,
735 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285), 2);
736 }
737 } else if (AR_SREV_9280_20_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530738 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700739 ARRAY_SIZE(ar9280Modes_9280_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530740 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700741 ARRAY_SIZE(ar9280Common_9280_2), 2);
742
Sujith2660b812009-02-09 13:27:26 +0530743 if (ah->config.pcie_clock_req) {
744 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530745 ar9280PciePhy_clkreq_off_L1_9280,
746 ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700747 } else {
Sujith2660b812009-02-09 13:27:26 +0530748 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530749 ar9280PciePhy_clkreq_always_on_L1_9280,
750 ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700751 }
Sujith2660b812009-02-09 13:27:26 +0530752 INIT_INI_ARRAY(&ah->iniModesAdditional,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700753 ar9280Modes_fast_clock_9280_2,
Sujithf1dc5602008-10-29 10:16:30 +0530754 ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700755 } else if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530756 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700757 ARRAY_SIZE(ar9280Modes_9280), 6);
Sujith2660b812009-02-09 13:27:26 +0530758 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700759 ARRAY_SIZE(ar9280Common_9280), 2);
760 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530761 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700762 ARRAY_SIZE(ar5416Modes_9160), 6);
Sujith2660b812009-02-09 13:27:26 +0530763 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700764 ARRAY_SIZE(ar5416Common_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530765 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700766 ARRAY_SIZE(ar5416Bank0_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530767 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700768 ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530769 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700770 ARRAY_SIZE(ar5416Bank1_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530771 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700772 ARRAY_SIZE(ar5416Bank2_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530773 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700774 ARRAY_SIZE(ar5416Bank3_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530775 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700776 ARRAY_SIZE(ar5416Bank6_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530777 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700778 ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530779 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700780 ARRAY_SIZE(ar5416Bank7_9160), 2);
781 if (AR_SREV_9160_11(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530782 INIT_INI_ARRAY(&ah->iniAddac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700783 ar5416Addac_91601_1,
784 ARRAY_SIZE(ar5416Addac_91601_1), 2);
785 } else {
Sujith2660b812009-02-09 13:27:26 +0530786 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700787 ARRAY_SIZE(ar5416Addac_9160), 2);
788 }
789 } else if (AR_SREV_9100_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530790 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700791 ARRAY_SIZE(ar5416Modes_9100), 6);
Sujith2660b812009-02-09 13:27:26 +0530792 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700793 ARRAY_SIZE(ar5416Common_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530794 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700795 ARRAY_SIZE(ar5416Bank0_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530796 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700797 ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530798 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700799 ARRAY_SIZE(ar5416Bank1_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530800 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700801 ARRAY_SIZE(ar5416Bank2_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530802 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700803 ARRAY_SIZE(ar5416Bank3_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530804 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700805 ARRAY_SIZE(ar5416Bank6_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530806 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700807 ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530808 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700809 ARRAY_SIZE(ar5416Bank7_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530810 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700811 ARRAY_SIZE(ar5416Addac_9100), 2);
812 } else {
Sujith2660b812009-02-09 13:27:26 +0530813 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700814 ARRAY_SIZE(ar5416Modes), 6);
Sujith2660b812009-02-09 13:27:26 +0530815 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700816 ARRAY_SIZE(ar5416Common), 2);
Sujith2660b812009-02-09 13:27:26 +0530817 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700818 ARRAY_SIZE(ar5416Bank0), 2);
Sujith2660b812009-02-09 13:27:26 +0530819 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700820 ARRAY_SIZE(ar5416BB_RfGain), 3);
Sujith2660b812009-02-09 13:27:26 +0530821 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700822 ARRAY_SIZE(ar5416Bank1), 2);
Sujith2660b812009-02-09 13:27:26 +0530823 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700824 ARRAY_SIZE(ar5416Bank2), 2);
Sujith2660b812009-02-09 13:27:26 +0530825 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700826 ARRAY_SIZE(ar5416Bank3), 3);
Sujith2660b812009-02-09 13:27:26 +0530827 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700828 ARRAY_SIZE(ar5416Bank6), 3);
Sujith2660b812009-02-09 13:27:26 +0530829 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700830 ARRAY_SIZE(ar5416Bank6TPC), 3);
Sujith2660b812009-02-09 13:27:26 +0530831 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700832 ARRAY_SIZE(ar5416Bank7), 2);
Sujith2660b812009-02-09 13:27:26 +0530833 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700834 ARRAY_SIZE(ar5416Addac), 2);
835 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700836}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700837
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700838static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
839{
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530840 if (AR_SREV_9287_11_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530841 INIT_INI_ARRAY(&ah->iniModesRxGain,
842 ar9287Modes_rx_gain_9287_1_1,
843 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_1), 6);
844 else if (AR_SREV_9287_10(ah))
845 INIT_INI_ARRAY(&ah->iniModesRxGain,
846 ar9287Modes_rx_gain_9287_1_0,
847 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_0), 6);
848 else if (AR_SREV_9280_20(ah))
849 ath9k_hw_init_rxgain_ini(ah);
850
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530851 if (AR_SREV_9287_11_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530852 INIT_INI_ARRAY(&ah->iniModesTxGain,
853 ar9287Modes_tx_gain_9287_1_1,
854 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_1), 6);
855 } else if (AR_SREV_9287_10(ah)) {
856 INIT_INI_ARRAY(&ah->iniModesTxGain,
857 ar9287Modes_tx_gain_9287_1_0,
858 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_0), 6);
859 } else if (AR_SREV_9280_20(ah)) {
860 ath9k_hw_init_txgain_ini(ah);
861 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530862 u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
863
864 /* txgain table */
865 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) {
866 INIT_INI_ARRAY(&ah->iniModesTxGain,
867 ar9285Modes_high_power_tx_gain_9285_1_2,
868 ARRAY_SIZE(ar9285Modes_high_power_tx_gain_9285_1_2), 6);
869 } else {
870 INIT_INI_ARRAY(&ah->iniModesTxGain,
871 ar9285Modes_original_tx_gain_9285_1_2,
872 ARRAY_SIZE(ar9285Modes_original_tx_gain_9285_1_2), 6);
873 }
874
875 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700876}
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530877
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700878static void ath9k_hw_init_11a_eeprom_fix(struct ath_hw *ah)
879{
880 u32 i, j;
Sujith06d0f062009-02-12 10:06:45 +0530881
882 if ((ah->hw_version.devid == AR9280_DEVID_PCI) &&
883 test_bit(ATH9K_MODE_11A, ah->caps.wireless_modes)) {
884
885 /* EEPROM Fixup */
Sujith2660b812009-02-09 13:27:26 +0530886 for (i = 0; i < ah->iniModes.ia_rows; i++) {
887 u32 reg = INI_RA(&ah->iniModes, i, 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700888
Sujith2660b812009-02-09 13:27:26 +0530889 for (j = 1; j < ah->iniModes.ia_columns; j++) {
890 u32 val = INI_RA(&ah->iniModes, i, j);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700891
Sujith2660b812009-02-09 13:27:26 +0530892 INI_RA(&ah->iniModes, i, j) =
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530893 ath9k_hw_ini_fixup(ah,
Sujith2660b812009-02-09 13:27:26 +0530894 &ah->eeprom.def,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700895 reg, val);
896 }
897 }
898 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700899}
900
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700901int ath9k_hw_init(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700902{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700903 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700904 int r = 0;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700905
Luis R. Rodriguez3ca34032009-09-23 23:07:01 -0400906 if (!ath9k_hw_devid_supported(ah->hw_version.devid)) {
907 ath_print(common, ATH_DBG_FATAL,
908 "Unsupported device ID: 0x%0x\n",
909 ah->hw_version.devid);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700910 return -EOPNOTSUPP;
Luis R. Rodriguez3ca34032009-09-23 23:07:01 -0400911 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700912
913 ath9k_hw_init_defaults(ah);
914 ath9k_hw_init_config(ah);
915
916 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700917 ath_print(common, ATH_DBG_FATAL,
918 "Couldn't reset chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700919 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700920 }
921
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700922 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700923 ath_print(common, ATH_DBG_FATAL, "Couldn't wakeup chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700924 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700925 }
926
927 if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
928 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
929 (AR_SREV_9280(ah) && !ah->is_pciexpress)) {
930 ah->config.serialize_regmode =
931 SER_REG_MODE_ON;
932 } else {
933 ah->config.serialize_regmode =
934 SER_REG_MODE_OFF;
935 }
936 }
937
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700938 ath_print(common, ATH_DBG_RESET, "serialize_regmode is %d\n",
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700939 ah->config.serialize_regmode);
940
941 if (!ath9k_hw_macversion_supported(ah->hw_version.macVersion)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700942 ath_print(common, ATH_DBG_FATAL,
943 "Mac Chip Rev 0x%02x.%x is not supported by "
944 "this driver\n", ah->hw_version.macVersion,
945 ah->hw_version.macRev);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700946 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700947 }
948
949 if (AR_SREV_9100(ah)) {
950 ah->iq_caldata.calData = &iq_cal_multi_sample;
951 ah->supp_cals = IQ_MISMATCH_CAL;
952 ah->is_pciexpress = false;
953 }
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400954
955 if (AR_SREV_9271(ah))
956 ah->is_pciexpress = false;
957
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700958 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
959
960 ath9k_hw_init_cal_settings(ah);
961
962 ah->ani_function = ATH9K_ANI_ALL;
963 if (AR_SREV_9280_10_OR_LATER(ah))
964 ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
965
966 ath9k_hw_init_mode_regs(ah);
967
968 if (ah->is_pciexpress)
Vivek Natarajan93b1b372009-09-17 09:24:58 +0530969 ath9k_hw_configpcipowersave(ah, 0, 0);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700970 else
971 ath9k_hw_disablepcie(ah);
972
Sujith193cd452009-09-18 15:04:07 +0530973 /* Support for Japan ch.14 (2484) spread */
974 if (AR_SREV_9287_11_OR_LATER(ah)) {
975 INIT_INI_ARRAY(&ah->iniCckfirNormal,
976 ar9287Common_normal_cck_fir_coeff_92871_1,
977 ARRAY_SIZE(ar9287Common_normal_cck_fir_coeff_92871_1), 2);
978 INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
979 ar9287Common_japan_2484_cck_fir_coeff_92871_1,
980 ARRAY_SIZE(ar9287Common_japan_2484_cck_fir_coeff_92871_1), 2);
981 }
982
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700983 r = ath9k_hw_post_init(ah);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700984 if (r)
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700985 return r;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700986
987 ath9k_hw_init_mode_gain_regs(ah);
988 ath9k_hw_fill_cap_info(ah);
989 ath9k_hw_init_11a_eeprom_fix(ah);
Sujithf6688cd2008-12-07 21:43:10 +0530990
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700991 r = ath9k_hw_init_macaddr(ah);
992 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700993 ath_print(common, ATH_DBG_FATAL,
994 "Failed to initialize MAC address\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700995 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700996 }
997
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400998 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
Sujith2660b812009-02-09 13:27:26 +0530999 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001000 else
Sujith2660b812009-02-09 13:27:26 +05301001 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001002
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001003 ath9k_init_nfcal_hist_buffer(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001004
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001005 common->state = ATH_HW_INITIALIZED;
1006
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001007 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001008}
1009
Sujithcbe61d82009-02-09 13:27:12 +05301010static void ath9k_hw_init_bb(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301011 struct ath9k_channel *chan)
1012{
1013 u32 synthDelay;
1014
1015 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +05301016 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +05301017 synthDelay = (4 * synthDelay) / 22;
1018 else
1019 synthDelay /= 10;
1020
1021 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
1022
1023 udelay(synthDelay + BASE_ACTIVATE_DELAY);
1024}
1025
Sujithcbe61d82009-02-09 13:27:12 +05301026static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301027{
1028 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
1029 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
1030
1031 REG_WRITE(ah, AR_QOS_NO_ACK,
1032 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
1033 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
1034 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
1035
1036 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
1037 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
1038 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
1039 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
1040 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
1041}
1042
Sujithcbe61d82009-02-09 13:27:12 +05301043static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301044 struct ath9k_channel *chan)
1045{
1046 u32 pll;
1047
1048 if (AR_SREV_9100(ah)) {
1049 if (chan && IS_CHAN_5GHZ(chan))
1050 pll = 0x1450;
1051 else
1052 pll = 0x1458;
1053 } else {
1054 if (AR_SREV_9280_10_OR_LATER(ah)) {
1055 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
1056
1057 if (chan && IS_CHAN_HALF_RATE(chan))
1058 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
1059 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1060 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
1061
1062 if (chan && IS_CHAN_5GHZ(chan)) {
1063 pll |= SM(0x28, AR_RTC_9160_PLL_DIV);
1064
1065
1066 if (AR_SREV_9280_20(ah)) {
1067 if (((chan->channel % 20) == 0)
1068 || ((chan->channel % 10) == 0))
1069 pll = 0x2850;
1070 else
1071 pll = 0x142c;
1072 }
1073 } else {
1074 pll |= SM(0x2c, AR_RTC_9160_PLL_DIV);
1075 }
1076
1077 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1078
1079 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
1080
1081 if (chan && IS_CHAN_HALF_RATE(chan))
1082 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
1083 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1084 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
1085
1086 if (chan && IS_CHAN_5GHZ(chan))
1087 pll |= SM(0x50, AR_RTC_9160_PLL_DIV);
1088 else
1089 pll |= SM(0x58, AR_RTC_9160_PLL_DIV);
1090 } else {
1091 pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2;
1092
1093 if (chan && IS_CHAN_HALF_RATE(chan))
1094 pll |= SM(0x1, AR_RTC_PLL_CLKSEL);
1095 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1096 pll |= SM(0x2, AR_RTC_PLL_CLKSEL);
1097
1098 if (chan && IS_CHAN_5GHZ(chan))
1099 pll |= SM(0xa, AR_RTC_PLL_DIV);
1100 else
1101 pll |= SM(0xb, AR_RTC_PLL_DIV);
1102 }
1103 }
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001104 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +05301105
1106 udelay(RTC_PLL_SETTLE_DELAY);
1107
1108 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
1109}
1110
Sujithcbe61d82009-02-09 13:27:12 +05301111static void ath9k_hw_init_chain_masks(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301112{
Sujithf1dc5602008-10-29 10:16:30 +05301113 int rx_chainmask, tx_chainmask;
1114
Sujith2660b812009-02-09 13:27:26 +05301115 rx_chainmask = ah->rxchainmask;
1116 tx_chainmask = ah->txchainmask;
Sujithf1dc5602008-10-29 10:16:30 +05301117
1118 switch (rx_chainmask) {
1119 case 0x5:
1120 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1121 AR_PHY_SWAP_ALT_CHAIN);
1122 case 0x3:
Sujithd535a422009-02-09 13:27:06 +05301123 if (((ah)->hw_version.macVersion <= AR_SREV_VERSION_9160)) {
Sujithf1dc5602008-10-29 10:16:30 +05301124 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7);
1125 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7);
1126 break;
1127 }
1128 case 0x1:
1129 case 0x2:
Sujithf1dc5602008-10-29 10:16:30 +05301130 case 0x7:
1131 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
1132 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
1133 break;
1134 default:
1135 break;
1136 }
1137
1138 REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);
1139 if (tx_chainmask == 0x5) {
1140 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1141 AR_PHY_SWAP_ALT_CHAIN);
1142 }
1143 if (AR_SREV_9100(ah))
1144 REG_WRITE(ah, AR_PHY_ANALOG_SWAP,
1145 REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
1146}
1147
Sujithcbe61d82009-02-09 13:27:12 +05301148static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -08001149 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301150{
Sujith2660b812009-02-09 13:27:26 +05301151 ah->mask_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +05301152 AR_IMR_TXURN |
1153 AR_IMR_RXERR |
1154 AR_IMR_RXORN |
1155 AR_IMR_BCNMISC;
1156
Sujith0ef1f162009-03-30 15:28:35 +05301157 if (ah->config.intr_mitigation)
Sujith2660b812009-02-09 13:27:26 +05301158 ah->mask_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
Sujithf1dc5602008-10-29 10:16:30 +05301159 else
Sujith2660b812009-02-09 13:27:26 +05301160 ah->mask_reg |= AR_IMR_RXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301161
Sujith2660b812009-02-09 13:27:26 +05301162 ah->mask_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301163
Colin McCabed97809d2008-12-01 13:38:55 -08001164 if (opmode == NL80211_IFTYPE_AP)
Sujith2660b812009-02-09 13:27:26 +05301165 ah->mask_reg |= AR_IMR_MIB;
Sujithf1dc5602008-10-29 10:16:30 +05301166
Sujith2660b812009-02-09 13:27:26 +05301167 REG_WRITE(ah, AR_IMR, ah->mask_reg);
Sujithf1dc5602008-10-29 10:16:30 +05301168 REG_WRITE(ah, AR_IMR_S2, REG_READ(ah, AR_IMR_S2) | AR_IMR_S2_GTT);
1169
1170 if (!AR_SREV_9100(ah)) {
1171 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
1172 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
1173 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
1174 }
1175}
1176
Sujithcbe61d82009-02-09 13:27:12 +05301177static bool ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301178{
Sujithf1dc5602008-10-29 10:16:30 +05301179 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001180 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1181 "bad ack timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301182 ah->acktimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301183 return false;
1184 } else {
1185 REG_RMW_FIELD(ah, AR_TIME_OUT,
1186 AR_TIME_OUT_ACK, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301187 ah->acktimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301188 return true;
1189 }
1190}
1191
Sujithcbe61d82009-02-09 13:27:12 +05301192static bool ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301193{
Sujithf1dc5602008-10-29 10:16:30 +05301194 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_CTS))) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001195 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1196 "bad cts timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301197 ah->ctstimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301198 return false;
1199 } else {
1200 REG_RMW_FIELD(ah, AR_TIME_OUT,
1201 AR_TIME_OUT_CTS, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301202 ah->ctstimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301203 return true;
1204 }
1205}
1206
Sujithcbe61d82009-02-09 13:27:12 +05301207static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +05301208{
Sujithf1dc5602008-10-29 10:16:30 +05301209 if (tu > 0xFFFF) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001210 ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT,
1211 "bad global tx timeout %u\n", tu);
Sujith2660b812009-02-09 13:27:26 +05301212 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301213 return false;
1214 } else {
1215 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +05301216 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +05301217 return true;
1218 }
1219}
1220
Sujithcbe61d82009-02-09 13:27:12 +05301221static void ath9k_hw_init_user_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301222{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001223 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
1224 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +05301225
Sujith2660b812009-02-09 13:27:26 +05301226 if (ah->misc_mode != 0)
Sujithf1dc5602008-10-29 10:16:30 +05301227 REG_WRITE(ah, AR_PCU_MISC,
Sujith2660b812009-02-09 13:27:26 +05301228 REG_READ(ah, AR_PCU_MISC) | ah->misc_mode);
1229 if (ah->slottime != (u32) -1)
1230 ath9k_hw_setslottime(ah, ah->slottime);
1231 if (ah->acktimeout != (u32) -1)
1232 ath9k_hw_set_ack_timeout(ah, ah->acktimeout);
1233 if (ah->ctstimeout != (u32) -1)
1234 ath9k_hw_set_cts_timeout(ah, ah->ctstimeout);
1235 if (ah->globaltxtimeout != (u32) -1)
1236 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Sujithf1dc5602008-10-29 10:16:30 +05301237}
1238
1239const char *ath9k_hw_probe(u16 vendorid, u16 devid)
1240{
1241 return vendorid == ATHEROS_VENDOR_ID ?
1242 ath9k_hw_devname(devid) : NULL;
1243}
1244
Sujithcbe61d82009-02-09 13:27:12 +05301245void ath9k_hw_detach(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001246{
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001247 struct ath_common *common = ath9k_hw_common(ah);
1248
1249 if (common->state <= ATH_HW_INITIALIZED)
1250 goto free_hw;
1251
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001252 if (!AR_SREV_9100(ah))
Luis R. Rodrigueze70c0cf2009-08-03 12:24:51 -07001253 ath9k_hw_ani_disable(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001254
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001255 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001256
1257free_hw:
1258 ath9k_hw_rf_free(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001259 kfree(ah);
Luis R. Rodriguez9db6b6a2009-08-03 12:24:52 -07001260 ah = NULL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001261}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001262EXPORT_SYMBOL(ath9k_hw_detach);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001263
Sujithf1dc5602008-10-29 10:16:30 +05301264/*******/
1265/* INI */
1266/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001267
Sujithcbe61d82009-02-09 13:27:12 +05301268static void ath9k_hw_override_ini(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301269 struct ath9k_channel *chan)
1270{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001271 u32 val;
1272
1273 if (AR_SREV_9271(ah)) {
1274 /*
1275 * Enable spectral scan to solution for issues with stuck
1276 * beacons on AR9271 1.0. The beacon stuck issue is not seeon on
1277 * AR9271 1.1
1278 */
1279 if (AR_SREV_9271_10(ah)) {
Luis R. Rodriguezec11bb82009-10-27 12:59:36 -04001280 val = REG_READ(ah, AR_PHY_SPECTRAL_SCAN) |
1281 AR_PHY_SPECTRAL_SCAN_ENABLE;
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001282 REG_WRITE(ah, AR_PHY_SPECTRAL_SCAN, val);
1283 }
1284 else if (AR_SREV_9271_11(ah))
1285 /*
1286 * change AR_PHY_RF_CTL3 setting to fix MAC issue
1287 * present on AR9271 1.1
1288 */
1289 REG_WRITE(ah, AR_PHY_RF_CTL3, 0x3a020001);
1290 return;
1291 }
1292
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +05301293 /*
1294 * Set the RX_ABORT and RX_DIS and clear if off only after
1295 * RXE is set for MAC. This prevents frames with corrupted
1296 * descriptor status.
1297 */
1298 REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
1299
Vasanthakumar Thiagarajan204d7942009-09-17 09:26:14 +05301300 if (AR_SREV_9280_10_OR_LATER(ah)) {
1301 val = REG_READ(ah, AR_PCU_MISC_MODE2) &
1302 (~AR_PCU_MISC_MODE2_HWWAR1);
1303
1304 if (AR_SREV_9287_10_OR_LATER(ah))
1305 val = val & (~AR_PCU_MISC_MODE2_HWWAR2);
1306
1307 REG_WRITE(ah, AR_PCU_MISC_MODE2, val);
1308 }
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +05301309
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001310 if (!AR_SREV_5416_20_OR_LATER(ah) ||
Sujithf1dc5602008-10-29 10:16:30 +05301311 AR_SREV_9280_10_OR_LATER(ah))
1312 return;
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001313 /*
1314 * Disable BB clock gating
1315 * Necessary to avoid issues on AR5416 2.0
1316 */
Sujithf1dc5602008-10-29 10:16:30 +05301317 REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
1318}
1319
Sujithcbe61d82009-02-09 13:27:12 +05301320static u32 ath9k_hw_def_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301321 struct ar5416_eeprom_def *pEepData,
Sujithf1dc5602008-10-29 10:16:30 +05301322 u32 reg, u32 value)
1323{
1324 struct base_eep_header *pBase = &(pEepData->baseEepHeader);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001325 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301326
Sujithd535a422009-02-09 13:27:06 +05301327 switch (ah->hw_version.devid) {
Sujithf1dc5602008-10-29 10:16:30 +05301328 case AR9280_DEVID_PCI:
1329 if (reg == 0x7894) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001330 ath_print(common, ATH_DBG_EEPROM,
Sujithf1dc5602008-10-29 10:16:30 +05301331 "ini VAL: %x EEPROM: %x\n", value,
1332 (pBase->version & 0xff));
1333
1334 if ((pBase->version & 0xff) > 0x0a) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001335 ath_print(common, ATH_DBG_EEPROM,
1336 "PWDCLKIND: %d\n",
1337 pBase->pwdclkind);
Sujithf1dc5602008-10-29 10:16:30 +05301338 value &= ~AR_AN_TOP2_PWDCLKIND;
1339 value |= AR_AN_TOP2_PWDCLKIND &
1340 (pBase->pwdclkind << AR_AN_TOP2_PWDCLKIND_S);
1341 } else {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001342 ath_print(common, ATH_DBG_EEPROM,
1343 "PWDCLKIND Earlier Rev\n");
Sujithf1dc5602008-10-29 10:16:30 +05301344 }
1345
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001346 ath_print(common, ATH_DBG_EEPROM,
1347 "final ini VAL: %x\n", value);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001348 }
Sujithf1dc5602008-10-29 10:16:30 +05301349 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001350 }
1351
Sujithf1dc5602008-10-29 10:16:30 +05301352 return value;
1353}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001354
Sujithcbe61d82009-02-09 13:27:12 +05301355static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301356 struct ar5416_eeprom_def *pEepData,
1357 u32 reg, u32 value)
1358{
Sujith2660b812009-02-09 13:27:26 +05301359 if (ah->eep_map == EEP_MAP_4KBITS)
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301360 return value;
1361 else
1362 return ath9k_hw_def_ini_fixup(ah, pEepData, reg, value);
1363}
1364
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301365static void ath9k_olc_init(struct ath_hw *ah)
1366{
1367 u32 i;
1368
Vivek Natarajandb91f2e2009-08-14 11:27:16 +05301369 if (OLC_FOR_AR9287_10_LATER) {
1370 REG_SET_BIT(ah, AR_PHY_TX_PWRCTRL9,
1371 AR_PHY_TX_PWRCTRL9_RES_DC_REMOVAL);
1372 ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TXPC0,
1373 AR9287_AN_TXPC0_TXPCMODE,
1374 AR9287_AN_TXPC0_TXPCMODE_S,
1375 AR9287_AN_TXPC0_TXPCMODE_TEMPSENSE);
1376 udelay(100);
1377 } else {
1378 for (i = 0; i < AR9280_TX_GAIN_TABLE_SIZE; i++)
1379 ah->originalGain[i] =
1380 MS(REG_READ(ah, AR_PHY_TX_GAIN_TBL1 + i * 4),
1381 AR_PHY_TX_GAIN);
1382 ah->PDADCdelta = 0;
1383 }
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301384}
1385
Bob Copeland3a702e42009-03-30 22:30:29 -04001386static u32 ath9k_regd_get_ctl(struct ath_regulatory *reg,
1387 struct ath9k_channel *chan)
1388{
1389 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
1390
1391 if (IS_CHAN_B(chan))
1392 ctl |= CTL_11B;
1393 else if (IS_CHAN_G(chan))
1394 ctl |= CTL_11G;
1395 else
1396 ctl |= CTL_11A;
1397
1398 return ctl;
1399}
1400
Sujithcbe61d82009-02-09 13:27:12 +05301401static int ath9k_hw_process_ini(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001402 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301403{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001404 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301405 int i, regWrites = 0;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001406 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301407 u32 modesIndex, freqIndex;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001408
Sujithf1dc5602008-10-29 10:16:30 +05301409 switch (chan->chanmode) {
1410 case CHANNEL_A:
1411 case CHANNEL_A_HT20:
1412 modesIndex = 1;
1413 freqIndex = 1;
1414 break;
1415 case CHANNEL_A_HT40PLUS:
1416 case CHANNEL_A_HT40MINUS:
1417 modesIndex = 2;
1418 freqIndex = 1;
1419 break;
1420 case CHANNEL_G:
1421 case CHANNEL_G_HT20:
1422 case CHANNEL_B:
1423 modesIndex = 4;
1424 freqIndex = 2;
1425 break;
1426 case CHANNEL_G_HT40PLUS:
1427 case CHANNEL_G_HT40MINUS:
1428 modesIndex = 3;
1429 freqIndex = 2;
1430 break;
1431
1432 default:
1433 return -EINVAL;
1434 }
1435
1436 REG_WRITE(ah, AR_PHY(0), 0x00000007);
Sujithf1dc5602008-10-29 10:16:30 +05301437 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
Sujithf74df6f2009-02-09 13:27:24 +05301438 ah->eep_ops->set_addac(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301439
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001440 if (AR_SREV_5416_22_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +05301441 REG_WRITE_ARRAY(&ah->iniAddac, 1, regWrites);
Sujithf1dc5602008-10-29 10:16:30 +05301442 } else {
1443 struct ar5416IniArray temp;
1444 u32 addacSize =
Sujith2660b812009-02-09 13:27:26 +05301445 sizeof(u32) * ah->iniAddac.ia_rows *
1446 ah->iniAddac.ia_columns;
Sujithf1dc5602008-10-29 10:16:30 +05301447
Sujith2660b812009-02-09 13:27:26 +05301448 memcpy(ah->addac5416_21,
1449 ah->iniAddac.ia_array, addacSize);
Sujithf1dc5602008-10-29 10:16:30 +05301450
Sujith2660b812009-02-09 13:27:26 +05301451 (ah->addac5416_21)[31 * ah->iniAddac.ia_columns + 1] = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301452
Sujith2660b812009-02-09 13:27:26 +05301453 temp.ia_array = ah->addac5416_21;
1454 temp.ia_columns = ah->iniAddac.ia_columns;
1455 temp.ia_rows = ah->iniAddac.ia_rows;
Sujithf1dc5602008-10-29 10:16:30 +05301456 REG_WRITE_ARRAY(&temp, 1, regWrites);
1457 }
1458
1459 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
1460
Sujith2660b812009-02-09 13:27:26 +05301461 for (i = 0; i < ah->iniModes.ia_rows; i++) {
1462 u32 reg = INI_RA(&ah->iniModes, i, 0);
1463 u32 val = INI_RA(&ah->iniModes, i, modesIndex);
Sujithf1dc5602008-10-29 10:16:30 +05301464
Sujithf1dc5602008-10-29 10:16:30 +05301465 REG_WRITE(ah, reg, val);
1466
1467 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301468 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301469 udelay(100);
1470 }
1471
1472 DO_DELAY(regWrites);
1473 }
1474
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301475 if (AR_SREV_9280(ah) || AR_SREV_9287_10_OR_LATER(ah))
Sujith2660b812009-02-09 13:27:26 +05301476 REG_WRITE_ARRAY(&ah->iniModesRxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301477
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301478 if (AR_SREV_9280(ah) || AR_SREV_9285_12_OR_LATER(ah) ||
1479 AR_SREV_9287_10_OR_LATER(ah))
Sujith2660b812009-02-09 13:27:26 +05301480 REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301481
Sujith2660b812009-02-09 13:27:26 +05301482 for (i = 0; i < ah->iniCommon.ia_rows; i++) {
1483 u32 reg = INI_RA(&ah->iniCommon, i, 0);
1484 u32 val = INI_RA(&ah->iniCommon, i, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301485
1486 REG_WRITE(ah, reg, val);
1487
1488 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301489 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301490 udelay(100);
1491 }
1492
1493 DO_DELAY(regWrites);
1494 }
1495
1496 ath9k_hw_write_regs(ah, modesIndex, freqIndex, regWrites);
1497
Luis R. Rodriguez85643282009-10-19 02:33:33 -04001498 if (AR_SREV_9271_10(ah))
1499 REG_WRITE_ARRAY(&ah->iniModes_9271_1_0_only,
1500 modesIndex, regWrites);
1501
Sujithf1dc5602008-10-29 10:16:30 +05301502 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan)) {
Sujith2660b812009-02-09 13:27:26 +05301503 REG_WRITE_ARRAY(&ah->iniModesAdditional, modesIndex,
Sujithf1dc5602008-10-29 10:16:30 +05301504 regWrites);
1505 }
1506
1507 ath9k_hw_override_ini(ah, chan);
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001508 ath9k_hw_set_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301509 ath9k_hw_init_chain_masks(ah);
1510
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301511 if (OLC_FOR_AR9280_20_LATER)
1512 ath9k_olc_init(ah);
1513
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001514 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001515 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001516 channel->max_antenna_gain * 2,
1517 channel->max_power * 2,
1518 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001519 (u32) regulatory->power_limit));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001520
Sujithf1dc5602008-10-29 10:16:30 +05301521 if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001522 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1523 "ar5416SetRfRegs failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001524 return -EIO;
1525 }
1526
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001527 return 0;
1528}
1529
Sujithf1dc5602008-10-29 10:16:30 +05301530/****************************************/
1531/* Reset and Channel Switching Routines */
1532/****************************************/
1533
Sujithcbe61d82009-02-09 13:27:12 +05301534static void ath9k_hw_set_rfmode(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301535{
1536 u32 rfMode = 0;
1537
1538 if (chan == NULL)
1539 return;
1540
1541 rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
1542 ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
1543
1544 if (!AR_SREV_9280_10_OR_LATER(ah))
1545 rfMode |= (IS_CHAN_5GHZ(chan)) ?
1546 AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ;
1547
1548 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan))
1549 rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
1550
1551 REG_WRITE(ah, AR_PHY_MODE, rfMode);
1552}
1553
Sujithcbe61d82009-02-09 13:27:12 +05301554static void ath9k_hw_mark_phy_inactive(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301555{
1556 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
1557}
1558
Sujithcbe61d82009-02-09 13:27:12 +05301559static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301560{
1561 u32 regval;
1562
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001563 /*
1564 * set AHB_MODE not to do cacheline prefetches
1565 */
Sujithf1dc5602008-10-29 10:16:30 +05301566 regval = REG_READ(ah, AR_AHB_MODE);
1567 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
1568
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001569 /*
1570 * let mac dma reads be in 128 byte chunks
1571 */
Sujithf1dc5602008-10-29 10:16:30 +05301572 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
1573 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
1574
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001575 /*
1576 * Restore TX Trigger Level to its pre-reset value.
1577 * The initial value depends on whether aggregation is enabled, and is
1578 * adjusted whenever underruns are detected.
1579 */
Sujith2660b812009-02-09 13:27:26 +05301580 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +05301581
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001582 /*
1583 * let mac dma writes be in 128 byte chunks
1584 */
Sujithf1dc5602008-10-29 10:16:30 +05301585 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
1586 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
1587
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001588 /*
1589 * Setup receive FIFO threshold to hold off TX activities
1590 */
Sujithf1dc5602008-10-29 10:16:30 +05301591 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1592
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001593 /*
1594 * reduce the number of usable entries in PCU TXBUF to avoid
1595 * wrap around issues.
1596 */
Sujithf1dc5602008-10-29 10:16:30 +05301597 if (AR_SREV_9285(ah)) {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001598 /* For AR9285 the number of Fifos are reduced to half.
1599 * So set the usable tx buf size also to half to
1600 * avoid data/delimiter underruns
1601 */
Sujithf1dc5602008-10-29 10:16:30 +05301602 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1603 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001604 } else if (!AR_SREV_9271(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +05301605 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1606 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1607 }
1608}
1609
Sujithcbe61d82009-02-09 13:27:12 +05301610static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301611{
1612 u32 val;
1613
1614 val = REG_READ(ah, AR_STA_ID1);
1615 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
1616 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001617 case NL80211_IFTYPE_AP:
Sujithf1dc5602008-10-29 10:16:30 +05301618 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
1619 | AR_STA_ID1_KSRCH_MODE);
1620 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1621 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001622 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04001623 case NL80211_IFTYPE_MESH_POINT:
Sujithf1dc5602008-10-29 10:16:30 +05301624 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
1625 | AR_STA_ID1_KSRCH_MODE);
1626 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1627 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001628 case NL80211_IFTYPE_STATION:
1629 case NL80211_IFTYPE_MONITOR:
Sujithf1dc5602008-10-29 10:16:30 +05301630 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
1631 break;
1632 }
1633}
1634
Sujithcbe61d82009-02-09 13:27:12 +05301635static inline void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001636 u32 coef_scaled,
1637 u32 *coef_mantissa,
1638 u32 *coef_exponent)
1639{
1640 u32 coef_exp, coef_man;
1641
1642 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1643 if ((coef_scaled >> coef_exp) & 0x1)
1644 break;
1645
1646 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1647
1648 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1649
1650 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1651 *coef_exponent = coef_exp - 16;
1652}
1653
Sujithcbe61d82009-02-09 13:27:12 +05301654static void ath9k_hw_set_delta_slope(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301655 struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001656{
1657 u32 coef_scaled, ds_coef_exp, ds_coef_man;
1658 u32 clockMhzScaled = 0x64000000;
1659 struct chan_centers centers;
1660
1661 if (IS_CHAN_HALF_RATE(chan))
1662 clockMhzScaled = clockMhzScaled >> 1;
1663 else if (IS_CHAN_QUARTER_RATE(chan))
1664 clockMhzScaled = clockMhzScaled >> 2;
1665
1666 ath9k_hw_get_channel_centers(ah, chan, &centers);
1667 coef_scaled = clockMhzScaled / centers.synth_center;
1668
1669 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1670 &ds_coef_exp);
1671
1672 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1673 AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
1674 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1675 AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
1676
1677 coef_scaled = (9 * coef_scaled) / 10;
1678
1679 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1680 &ds_coef_exp);
1681
1682 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1683 AR_PHY_HALFGI_DSC_MAN, ds_coef_man);
1684 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1685 AR_PHY_HALFGI_DSC_EXP, ds_coef_exp);
1686}
1687
Sujithcbe61d82009-02-09 13:27:12 +05301688static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +05301689{
1690 u32 rst_flags;
1691 u32 tmpReg;
1692
Sujith70768492009-02-16 13:23:12 +05301693 if (AR_SREV_9100(ah)) {
1694 u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK);
1695 val &= ~AR_RTC_DERIVED_CLK_PERIOD;
1696 val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD);
1697 REG_WRITE(ah, AR_RTC_DERIVED_CLK, val);
1698 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1699 }
1700
Sujithf1dc5602008-10-29 10:16:30 +05301701 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1702 AR_RTC_FORCE_WAKE_ON_INT);
1703
1704 if (AR_SREV_9100(ah)) {
1705 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1706 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1707 } else {
1708 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1709 if (tmpReg &
1710 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1711 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
1712 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
1713 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1714 } else {
1715 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1716 }
1717
1718 rst_flags = AR_RTC_RC_MAC_WARM;
1719 if (type == ATH9K_RESET_COLD)
1720 rst_flags |= AR_RTC_RC_MAC_COLD;
1721 }
1722
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001723 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujithf1dc5602008-10-29 10:16:30 +05301724 udelay(50);
1725
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001726 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301727 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001728 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1729 "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301730 return false;
1731 }
1732
1733 if (!AR_SREV_9100(ah))
1734 REG_WRITE(ah, AR_RC, 0);
1735
Sujithf1dc5602008-10-29 10:16:30 +05301736 if (AR_SREV_9100(ah))
1737 udelay(50);
1738
1739 return true;
1740}
1741
Sujithcbe61d82009-02-09 13:27:12 +05301742static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301743{
1744 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1745 AR_RTC_FORCE_WAKE_ON_INT);
1746
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301747 if (!AR_SREV_9100(ah))
1748 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1749
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001750 REG_WRITE(ah, AR_RTC_RESET, 0);
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301751 udelay(2);
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301752
1753 if (!AR_SREV_9100(ah))
1754 REG_WRITE(ah, AR_RC, 0);
1755
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001756 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301757
1758 if (!ath9k_hw_wait(ah,
1759 AR_RTC_STATUS,
1760 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301761 AR_RTC_STATUS_ON,
1762 AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001763 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1764 "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301765 return false;
1766 }
1767
1768 ath9k_hw_read_revisions(ah);
1769
1770 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1771}
1772
Sujithcbe61d82009-02-09 13:27:12 +05301773static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301774{
1775 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1776 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1777
1778 switch (type) {
1779 case ATH9K_RESET_POWER_ON:
1780 return ath9k_hw_set_reset_power_on(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301781 case ATH9K_RESET_WARM:
1782 case ATH9K_RESET_COLD:
1783 return ath9k_hw_set_reset(ah, type);
Sujithf1dc5602008-10-29 10:16:30 +05301784 default:
1785 return false;
1786 }
1787}
1788
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001789static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301790{
1791 u32 phymode;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301792 u32 enableDacFifo = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301793
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301794 if (AR_SREV_9285_10_OR_LATER(ah))
1795 enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) &
1796 AR_PHY_FC_ENABLE_DAC_FIFO);
1797
Sujithf1dc5602008-10-29 10:16:30 +05301798 phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301799 | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo;
Sujithf1dc5602008-10-29 10:16:30 +05301800
1801 if (IS_CHAN_HT40(chan)) {
1802 phymode |= AR_PHY_FC_DYN2040_EN;
1803
1804 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
1805 (chan->chanmode == CHANNEL_G_HT40PLUS))
1806 phymode |= AR_PHY_FC_DYN2040_PRI_CH;
1807
Sujithf1dc5602008-10-29 10:16:30 +05301808 }
1809 REG_WRITE(ah, AR_PHY_TURBO, phymode);
1810
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001811 ath9k_hw_set11nmac2040(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301812
1813 REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
1814 REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
1815}
1816
Sujithcbe61d82009-02-09 13:27:12 +05301817static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301818 struct ath9k_channel *chan)
1819{
Vivek Natarajan42abfbe2009-09-17 09:27:59 +05301820 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) {
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301821 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
1822 return false;
1823 } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
Sujithf1dc5602008-10-29 10:16:30 +05301824 return false;
1825
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001826 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05301827 return false;
1828
Sujith2660b812009-02-09 13:27:26 +05301829 ah->chip_fullsleep = false;
Sujithf1dc5602008-10-29 10:16:30 +05301830 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301831 ath9k_hw_set_rfmode(ah, chan);
1832
1833 return true;
1834}
1835
Sujithcbe61d82009-02-09 13:27:12 +05301836static bool ath9k_hw_channel_change(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001837 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301838{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001839 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001840 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001841 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301842 u32 synthDelay, qnum;
1843
1844 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1845 if (ath9k_hw_numtxpending(ah, qnum)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001846 ath_print(common, ATH_DBG_QUEUE,
1847 "Transmit frames pending on "
1848 "queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301849 return false;
1850 }
1851 }
1852
1853 REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
1854 if (!ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
Sujith0caa7b12009-02-16 13:23:20 +05301855 AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001856 ath_print(common, ATH_DBG_FATAL,
1857 "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301858 return false;
1859 }
1860
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001861 ath9k_hw_set_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301862
1863 if (AR_SREV_9280_10_OR_LATER(ah)) {
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001864 ath9k_hw_ar9280_set_channel(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301865 } else {
1866 if (!(ath9k_hw_set_channel(ah, chan))) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001867 ath_print(common, ATH_DBG_FATAL,
1868 "Failed to set channel\n");
Sujithf1dc5602008-10-29 10:16:30 +05301869 return false;
1870 }
1871 }
1872
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001873 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001874 ath9k_regd_get_ctl(regulatory, chan),
Sujithf74df6f2009-02-09 13:27:24 +05301875 channel->max_antenna_gain * 2,
1876 channel->max_power * 2,
1877 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001878 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05301879
1880 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +05301881 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +05301882 synthDelay = (4 * synthDelay) / 22;
1883 else
1884 synthDelay /= 10;
1885
1886 udelay(synthDelay + BASE_ACTIVATE_DELAY);
1887
1888 REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
1889
1890 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1891 ath9k_hw_set_delta_slope(ah, chan);
1892
1893 if (AR_SREV_9280_10_OR_LATER(ah))
1894 ath9k_hw_9280_spur_mitigate(ah, chan);
1895 else
1896 ath9k_hw_spur_mitigate(ah, chan);
1897
1898 if (!chan->oneTimeCalsDone)
1899 chan->oneTimeCalsDone = true;
1900
1901 return true;
1902}
1903
Sujithcbe61d82009-02-09 13:27:12 +05301904static void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001905{
1906 int bb_spur = AR_NO_SPUR;
1907 int freq;
1908 int bin, cur_bin;
1909 int bb_spur_off, spur_subchannel_sd;
1910 int spur_freq_sd;
1911 int spur_delta_phase;
1912 int denominator;
1913 int upper, lower, cur_vit_mask;
1914 int tmp, newVal;
1915 int i;
1916 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
1917 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
1918 };
1919 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
1920 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
1921 };
1922 int inc[4] = { 0, 100, 0, 0 };
1923 struct chan_centers centers;
1924
1925 int8_t mask_m[123];
1926 int8_t mask_p[123];
1927 int8_t mask_amt;
1928 int tmp_mask;
1929 int cur_bb_spur;
1930 bool is2GHz = IS_CHAN_2GHZ(chan);
1931
1932 memset(&mask_m, 0, sizeof(int8_t) * 123);
1933 memset(&mask_p, 0, sizeof(int8_t) * 123);
1934
1935 ath9k_hw_get_channel_centers(ah, chan, &centers);
1936 freq = centers.synth_center;
1937
Sujith2660b812009-02-09 13:27:26 +05301938 ah->config.spurmode = SPUR_ENABLE_EEPROM;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001939 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujithf74df6f2009-02-09 13:27:24 +05301940 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001941
1942 if (is2GHz)
1943 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_2GHZ;
1944 else
1945 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_5GHZ;
1946
1947 if (AR_NO_SPUR == cur_bb_spur)
1948 break;
1949 cur_bb_spur = cur_bb_spur - freq;
1950
1951 if (IS_CHAN_HT40(chan)) {
1952 if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT40) &&
1953 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT40)) {
1954 bb_spur = cur_bb_spur;
1955 break;
1956 }
1957 } else if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT20) &&
1958 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT20)) {
1959 bb_spur = cur_bb_spur;
1960 break;
1961 }
1962 }
1963
1964 if (AR_NO_SPUR == bb_spur) {
1965 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1966 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1967 return;
1968 } else {
1969 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1970 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1971 }
1972
1973 bin = bb_spur * 320;
1974
1975 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
1976
1977 newVal = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
1978 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
1979 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
1980 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
1981 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), newVal);
1982
1983 newVal = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
1984 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
1985 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
1986 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
1987 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
1988 REG_WRITE(ah, AR_PHY_SPUR_REG, newVal);
1989
1990 if (IS_CHAN_HT40(chan)) {
1991 if (bb_spur < 0) {
1992 spur_subchannel_sd = 1;
1993 bb_spur_off = bb_spur + 10;
1994 } else {
1995 spur_subchannel_sd = 0;
1996 bb_spur_off = bb_spur - 10;
1997 }
1998 } else {
1999 spur_subchannel_sd = 0;
2000 bb_spur_off = bb_spur;
2001 }
2002
2003 if (IS_CHAN_HT40(chan))
2004 spur_delta_phase =
2005 ((bb_spur * 262144) /
2006 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
2007 else
2008 spur_delta_phase =
2009 ((bb_spur * 524288) /
2010 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
2011
2012 denominator = IS_CHAN_2GHZ(chan) ? 44 : 40;
2013 spur_freq_sd = ((bb_spur_off * 2048) / denominator) & 0x3ff;
2014
2015 newVal = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
2016 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
2017 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
2018 REG_WRITE(ah, AR_PHY_TIMING11, newVal);
2019
2020 newVal = spur_subchannel_sd << AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S;
2021 REG_WRITE(ah, AR_PHY_SFCORR_EXT, newVal);
2022
2023 cur_bin = -6000;
2024 upper = bin + 100;
2025 lower = bin - 100;
2026
2027 for (i = 0; i < 4; i++) {
2028 int pilot_mask = 0;
2029 int chan_mask = 0;
2030 int bp = 0;
2031 for (bp = 0; bp < 30; bp++) {
2032 if ((cur_bin > lower) && (cur_bin < upper)) {
2033 pilot_mask = pilot_mask | 0x1 << bp;
2034 chan_mask = chan_mask | 0x1 << bp;
2035 }
2036 cur_bin += 100;
2037 }
2038 cur_bin += inc[i];
2039 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
2040 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
2041 }
2042
2043 cur_vit_mask = 6100;
2044 upper = bin + 120;
2045 lower = bin - 120;
2046
2047 for (i = 0; i < 123; i++) {
2048 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
Adrian Bunkb08cbcd2008-08-05 22:06:51 +03002049
2050 /* workaround for gcc bug #37014 */
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002051 volatile int tmp_v = abs(cur_vit_mask - bin);
Adrian Bunkb08cbcd2008-08-05 22:06:51 +03002052
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002053 if (tmp_v < 75)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002054 mask_amt = 1;
2055 else
2056 mask_amt = 0;
2057 if (cur_vit_mask < 0)
2058 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
2059 else
2060 mask_p[cur_vit_mask / 100] = mask_amt;
2061 }
2062 cur_vit_mask -= 100;
2063 }
2064
2065 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
2066 | (mask_m[48] << 26) | (mask_m[49] << 24)
2067 | (mask_m[50] << 22) | (mask_m[51] << 20)
2068 | (mask_m[52] << 18) | (mask_m[53] << 16)
2069 | (mask_m[54] << 14) | (mask_m[55] << 12)
2070 | (mask_m[56] << 10) | (mask_m[57] << 8)
2071 | (mask_m[58] << 6) | (mask_m[59] << 4)
2072 | (mask_m[60] << 2) | (mask_m[61] << 0);
2073 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
2074 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
2075
2076 tmp_mask = (mask_m[31] << 28)
2077 | (mask_m[32] << 26) | (mask_m[33] << 24)
2078 | (mask_m[34] << 22) | (mask_m[35] << 20)
2079 | (mask_m[36] << 18) | (mask_m[37] << 16)
2080 | (mask_m[48] << 14) | (mask_m[39] << 12)
2081 | (mask_m[40] << 10) | (mask_m[41] << 8)
2082 | (mask_m[42] << 6) | (mask_m[43] << 4)
2083 | (mask_m[44] << 2) | (mask_m[45] << 0);
2084 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
2085 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
2086
2087 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
2088 | (mask_m[18] << 26) | (mask_m[18] << 24)
2089 | (mask_m[20] << 22) | (mask_m[20] << 20)
2090 | (mask_m[22] << 18) | (mask_m[22] << 16)
2091 | (mask_m[24] << 14) | (mask_m[24] << 12)
2092 | (mask_m[25] << 10) | (mask_m[26] << 8)
2093 | (mask_m[27] << 6) | (mask_m[28] << 4)
2094 | (mask_m[29] << 2) | (mask_m[30] << 0);
2095 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
2096 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
2097
2098 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
2099 | (mask_m[2] << 26) | (mask_m[3] << 24)
2100 | (mask_m[4] << 22) | (mask_m[5] << 20)
2101 | (mask_m[6] << 18) | (mask_m[7] << 16)
2102 | (mask_m[8] << 14) | (mask_m[9] << 12)
2103 | (mask_m[10] << 10) | (mask_m[11] << 8)
2104 | (mask_m[12] << 6) | (mask_m[13] << 4)
2105 | (mask_m[14] << 2) | (mask_m[15] << 0);
2106 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
2107 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
2108
2109 tmp_mask = (mask_p[15] << 28)
2110 | (mask_p[14] << 26) | (mask_p[13] << 24)
2111 | (mask_p[12] << 22) | (mask_p[11] << 20)
2112 | (mask_p[10] << 18) | (mask_p[9] << 16)
2113 | (mask_p[8] << 14) | (mask_p[7] << 12)
2114 | (mask_p[6] << 10) | (mask_p[5] << 8)
2115 | (mask_p[4] << 6) | (mask_p[3] << 4)
2116 | (mask_p[2] << 2) | (mask_p[1] << 0);
2117 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
2118 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
2119
2120 tmp_mask = (mask_p[30] << 28)
2121 | (mask_p[29] << 26) | (mask_p[28] << 24)
2122 | (mask_p[27] << 22) | (mask_p[26] << 20)
2123 | (mask_p[25] << 18) | (mask_p[24] << 16)
2124 | (mask_p[23] << 14) | (mask_p[22] << 12)
2125 | (mask_p[21] << 10) | (mask_p[20] << 8)
2126 | (mask_p[19] << 6) | (mask_p[18] << 4)
2127 | (mask_p[17] << 2) | (mask_p[16] << 0);
2128 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
2129 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
2130
2131 tmp_mask = (mask_p[45] << 28)
2132 | (mask_p[44] << 26) | (mask_p[43] << 24)
2133 | (mask_p[42] << 22) | (mask_p[41] << 20)
2134 | (mask_p[40] << 18) | (mask_p[39] << 16)
2135 | (mask_p[38] << 14) | (mask_p[37] << 12)
2136 | (mask_p[36] << 10) | (mask_p[35] << 8)
2137 | (mask_p[34] << 6) | (mask_p[33] << 4)
2138 | (mask_p[32] << 2) | (mask_p[31] << 0);
2139 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
2140 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
2141
2142 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
2143 | (mask_p[59] << 26) | (mask_p[58] << 24)
2144 | (mask_p[57] << 22) | (mask_p[56] << 20)
2145 | (mask_p[55] << 18) | (mask_p[54] << 16)
2146 | (mask_p[53] << 14) | (mask_p[52] << 12)
2147 | (mask_p[51] << 10) | (mask_p[50] << 8)
2148 | (mask_p[49] << 6) | (mask_p[48] << 4)
2149 | (mask_p[47] << 2) | (mask_p[46] << 0);
2150 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
2151 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
2152}
2153
Sujithcbe61d82009-02-09 13:27:12 +05302154static void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002155{
2156 int bb_spur = AR_NO_SPUR;
2157 int bin, cur_bin;
2158 int spur_freq_sd;
2159 int spur_delta_phase;
2160 int denominator;
2161 int upper, lower, cur_vit_mask;
2162 int tmp, new;
2163 int i;
2164 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
2165 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
2166 };
2167 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
2168 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
2169 };
2170 int inc[4] = { 0, 100, 0, 0 };
2171
2172 int8_t mask_m[123];
2173 int8_t mask_p[123];
2174 int8_t mask_amt;
2175 int tmp_mask;
2176 int cur_bb_spur;
2177 bool is2GHz = IS_CHAN_2GHZ(chan);
2178
2179 memset(&mask_m, 0, sizeof(int8_t) * 123);
2180 memset(&mask_p, 0, sizeof(int8_t) * 123);
2181
2182 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujithf74df6f2009-02-09 13:27:24 +05302183 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002184 if (AR_NO_SPUR == cur_bb_spur)
2185 break;
2186 cur_bb_spur = cur_bb_spur - (chan->channel * 10);
2187 if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) {
2188 bb_spur = cur_bb_spur;
2189 break;
2190 }
2191 }
2192
2193 if (AR_NO_SPUR == bb_spur)
2194 return;
2195
2196 bin = bb_spur * 32;
2197
2198 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
2199 new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
2200 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
2201 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
2202 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
2203
2204 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new);
2205
2206 new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
2207 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
2208 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
2209 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
2210 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
2211 REG_WRITE(ah, AR_PHY_SPUR_REG, new);
2212
2213 spur_delta_phase = ((bb_spur * 524288) / 100) &
2214 AR_PHY_TIMING11_SPUR_DELTA_PHASE;
2215
2216 denominator = IS_CHAN_2GHZ(chan) ? 440 : 400;
2217 spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff;
2218
2219 new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
2220 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
2221 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
2222 REG_WRITE(ah, AR_PHY_TIMING11, new);
2223
2224 cur_bin = -6000;
2225 upper = bin + 100;
2226 lower = bin - 100;
2227
2228 for (i = 0; i < 4; i++) {
2229 int pilot_mask = 0;
2230 int chan_mask = 0;
2231 int bp = 0;
2232 for (bp = 0; bp < 30; bp++) {
2233 if ((cur_bin > lower) && (cur_bin < upper)) {
2234 pilot_mask = pilot_mask | 0x1 << bp;
2235 chan_mask = chan_mask | 0x1 << bp;
2236 }
2237 cur_bin += 100;
2238 }
2239 cur_bin += inc[i];
2240 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
2241 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
2242 }
2243
2244 cur_vit_mask = 6100;
2245 upper = bin + 120;
2246 lower = bin - 120;
2247
2248 for (i = 0; i < 123; i++) {
2249 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
Adrian Bunk88b9e2b2008-08-05 22:06:51 +03002250
2251 /* workaround for gcc bug #37014 */
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002252 volatile int tmp_v = abs(cur_vit_mask - bin);
Adrian Bunk88b9e2b2008-08-05 22:06:51 +03002253
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002254 if (tmp_v < 75)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002255 mask_amt = 1;
2256 else
2257 mask_amt = 0;
2258 if (cur_vit_mask < 0)
2259 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
2260 else
2261 mask_p[cur_vit_mask / 100] = mask_amt;
2262 }
2263 cur_vit_mask -= 100;
2264 }
2265
2266 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
2267 | (mask_m[48] << 26) | (mask_m[49] << 24)
2268 | (mask_m[50] << 22) | (mask_m[51] << 20)
2269 | (mask_m[52] << 18) | (mask_m[53] << 16)
2270 | (mask_m[54] << 14) | (mask_m[55] << 12)
2271 | (mask_m[56] << 10) | (mask_m[57] << 8)
2272 | (mask_m[58] << 6) | (mask_m[59] << 4)
2273 | (mask_m[60] << 2) | (mask_m[61] << 0);
2274 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
2275 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
2276
2277 tmp_mask = (mask_m[31] << 28)
2278 | (mask_m[32] << 26) | (mask_m[33] << 24)
2279 | (mask_m[34] << 22) | (mask_m[35] << 20)
2280 | (mask_m[36] << 18) | (mask_m[37] << 16)
2281 | (mask_m[48] << 14) | (mask_m[39] << 12)
2282 | (mask_m[40] << 10) | (mask_m[41] << 8)
2283 | (mask_m[42] << 6) | (mask_m[43] << 4)
2284 | (mask_m[44] << 2) | (mask_m[45] << 0);
2285 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
2286 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
2287
2288 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
2289 | (mask_m[18] << 26) | (mask_m[18] << 24)
2290 | (mask_m[20] << 22) | (mask_m[20] << 20)
2291 | (mask_m[22] << 18) | (mask_m[22] << 16)
2292 | (mask_m[24] << 14) | (mask_m[24] << 12)
2293 | (mask_m[25] << 10) | (mask_m[26] << 8)
2294 | (mask_m[27] << 6) | (mask_m[28] << 4)
2295 | (mask_m[29] << 2) | (mask_m[30] << 0);
2296 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
2297 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
2298
2299 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
2300 | (mask_m[2] << 26) | (mask_m[3] << 24)
2301 | (mask_m[4] << 22) | (mask_m[5] << 20)
2302 | (mask_m[6] << 18) | (mask_m[7] << 16)
2303 | (mask_m[8] << 14) | (mask_m[9] << 12)
2304 | (mask_m[10] << 10) | (mask_m[11] << 8)
2305 | (mask_m[12] << 6) | (mask_m[13] << 4)
2306 | (mask_m[14] << 2) | (mask_m[15] << 0);
2307 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
2308 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
2309
2310 tmp_mask = (mask_p[15] << 28)
2311 | (mask_p[14] << 26) | (mask_p[13] << 24)
2312 | (mask_p[12] << 22) | (mask_p[11] << 20)
2313 | (mask_p[10] << 18) | (mask_p[9] << 16)
2314 | (mask_p[8] << 14) | (mask_p[7] << 12)
2315 | (mask_p[6] << 10) | (mask_p[5] << 8)
2316 | (mask_p[4] << 6) | (mask_p[3] << 4)
2317 | (mask_p[2] << 2) | (mask_p[1] << 0);
2318 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
2319 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
2320
2321 tmp_mask = (mask_p[30] << 28)
2322 | (mask_p[29] << 26) | (mask_p[28] << 24)
2323 | (mask_p[27] << 22) | (mask_p[26] << 20)
2324 | (mask_p[25] << 18) | (mask_p[24] << 16)
2325 | (mask_p[23] << 14) | (mask_p[22] << 12)
2326 | (mask_p[21] << 10) | (mask_p[20] << 8)
2327 | (mask_p[19] << 6) | (mask_p[18] << 4)
2328 | (mask_p[17] << 2) | (mask_p[16] << 0);
2329 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
2330 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
2331
2332 tmp_mask = (mask_p[45] << 28)
2333 | (mask_p[44] << 26) | (mask_p[43] << 24)
2334 | (mask_p[42] << 22) | (mask_p[41] << 20)
2335 | (mask_p[40] << 18) | (mask_p[39] << 16)
2336 | (mask_p[38] << 14) | (mask_p[37] << 12)
2337 | (mask_p[36] << 10) | (mask_p[35] << 8)
2338 | (mask_p[34] << 6) | (mask_p[33] << 4)
2339 | (mask_p[32] << 2) | (mask_p[31] << 0);
2340 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
2341 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
2342
2343 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
2344 | (mask_p[59] << 26) | (mask_p[58] << 24)
2345 | (mask_p[57] << 22) | (mask_p[56] << 20)
2346 | (mask_p[55] << 18) | (mask_p[54] << 16)
2347 | (mask_p[53] << 14) | (mask_p[52] << 12)
2348 | (mask_p[51] << 10) | (mask_p[50] << 8)
2349 | (mask_p[49] << 6) | (mask_p[48] << 4)
2350 | (mask_p[47] << 2) | (mask_p[46] << 0);
2351 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
2352 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
2353}
2354
Johannes Berg3b319aa2009-06-13 14:50:26 +05302355static void ath9k_enable_rfkill(struct ath_hw *ah)
2356{
2357 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
2358 AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
2359
2360 REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2,
2361 AR_GPIO_INPUT_MUX2_RFSILENT);
2362
2363 ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
2364 REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);
2365}
2366
Sujithcbe61d82009-02-09 13:27:12 +05302367int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002368 bool bChannelChange)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002369{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002370 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002371 u32 saveLedState;
Sujith2660b812009-02-09 13:27:26 +05302372 struct ath9k_channel *curchan = ah->curchan;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002373 u32 saveDefAntenna;
2374 u32 macStaId1;
Sujith46fe7822009-09-17 09:25:25 +05302375 u64 tsf = 0;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002376 int i, rx_chainmask, r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002377
Luis R. Rodriguez43c27612009-09-13 21:07:07 -07002378 ah->txchainmask = common->tx_chainmask;
2379 ah->rxchainmask = common->rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002380
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002381 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002382 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002383
Vasanthakumar Thiagarajan9ebef792009-09-17 09:26:44 +05302384 if (curchan && !ah->chip_fullsleep)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002385 ath9k_hw_getnf(ah, curchan);
2386
2387 if (bChannelChange &&
Sujith2660b812009-02-09 13:27:26 +05302388 (ah->chip_fullsleep != true) &&
2389 (ah->curchan != NULL) &&
2390 (chan->channel != ah->curchan->channel) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002391 ((chan->channelFlags & CHANNEL_ALL) ==
Sujith2660b812009-02-09 13:27:26 +05302392 (ah->curchan->channelFlags & CHANNEL_ALL)) &&
Vasanthakumar Thiagarajan0a475cc2009-09-17 09:27:10 +05302393 !(AR_SREV_9280(ah) || IS_CHAN_A_5MHZ_SPACED(chan) ||
2394 IS_CHAN_A_5MHZ_SPACED(ah->curchan))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002395
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002396 if (ath9k_hw_channel_change(ah, chan)) {
Sujith2660b812009-02-09 13:27:26 +05302397 ath9k_hw_loadnf(ah, ah->curchan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002398 ath9k_hw_start_nfcal(ah);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002399 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002400 }
2401 }
2402
2403 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
2404 if (saveDefAntenna == 0)
2405 saveDefAntenna = 1;
2406
2407 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
2408
Sujith46fe7822009-09-17 09:25:25 +05302409 /* For chips on which RTC reset is done, save TSF before it gets cleared */
2410 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
2411 tsf = ath9k_hw_gettsf64(ah);
2412
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002413 saveLedState = REG_READ(ah, AR_CFG_LED) &
2414 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
2415 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
2416
2417 ath9k_hw_mark_phy_inactive(ah);
2418
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002419 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
2420 REG_WRITE(ah,
2421 AR9271_RESET_POWER_DOWN_CONTROL,
2422 AR9271_RADIO_RF_RST);
2423 udelay(50);
2424 }
2425
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002426 if (!ath9k_hw_chip_reset(ah, chan)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002427 ath_print(common, ATH_DBG_FATAL, "Chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002428 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002429 }
2430
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002431 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
2432 ah->htc_reset_init = false;
2433 REG_WRITE(ah,
2434 AR9271_RESET_POWER_DOWN_CONTROL,
2435 AR9271_GATE_MAC_CTL);
2436 udelay(50);
2437 }
2438
Sujith46fe7822009-09-17 09:25:25 +05302439 /* Restore TSF */
2440 if (tsf && AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
2441 ath9k_hw_settsf64(ah, tsf);
2442
Vasanthakumar Thiagarajan369391d2009-01-21 19:24:13 +05302443 if (AR_SREV_9280_10_OR_LATER(ah))
2444 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002445
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302446 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302447 /* Enable ASYNC FIFO */
2448 REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2449 AR_MAC_PCU_ASYNC_FIFO_REG3_DATAPATH_SEL);
2450 REG_SET_BIT(ah, AR_PHY_MODE, AR_PHY_MODE_ASYNCFIFO);
2451 REG_CLR_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2452 AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
2453 REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2454 AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
2455 }
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002456 r = ath9k_hw_process_ini(ah, chan);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002457 if (r)
2458 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002459
Jouni Malinen0ced0e12009-01-08 13:32:13 +02002460 /* Setup MFP options for CCMP */
2461 if (AR_SREV_9280_20_OR_LATER(ah)) {
2462 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
2463 * frames when constructing CCMP AAD. */
2464 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
2465 0xc7ff);
2466 ah->sw_mgmt_crypto = false;
2467 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
2468 /* Disable hardware crypto for management frames */
2469 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
2470 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
2471 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
2472 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
2473 ah->sw_mgmt_crypto = true;
2474 } else
2475 ah->sw_mgmt_crypto = true;
2476
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002477 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
2478 ath9k_hw_set_delta_slope(ah, chan);
2479
2480 if (AR_SREV_9280_10_OR_LATER(ah))
2481 ath9k_hw_9280_spur_mitigate(ah, chan);
2482 else
2483 ath9k_hw_spur_mitigate(ah, chan);
2484
Sujithd6509152009-03-13 08:56:05 +05302485 ah->eep_ops->set_board_values(ah, chan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002486
2487 ath9k_hw_decrease_chain_power(ah, chan);
2488
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002489 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
2490 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002491 | macStaId1
2492 | AR_STA_ID1_RTS_USE_DEF
Sujith2660b812009-02-09 13:27:26 +05302493 | (ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302494 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Sujith2660b812009-02-09 13:27:26 +05302495 | ah->sta_id1_defaults);
2496 ath9k_hw_set_operating_mode(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002497
Luis R. Rodriguez13b81552009-09-10 17:52:45 -07002498 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002499
2500 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
2501
Luis R. Rodriguez3453ad82009-09-10 08:57:00 -07002502 ath9k_hw_write_associd(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002503
2504 REG_WRITE(ah, AR_ISR, ~0);
2505
2506 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
2507
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07002508 if (AR_SREV_9280_10_OR_LATER(ah))
2509 ath9k_hw_ar9280_set_channel(ah, chan);
2510 else
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002511 if (!(ath9k_hw_set_channel(ah, chan)))
2512 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002513
2514 for (i = 0; i < AR_NUM_DCU; i++)
2515 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
2516
Sujith2660b812009-02-09 13:27:26 +05302517 ah->intr_txqs = 0;
2518 for (i = 0; i < ah->caps.total_queues; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002519 ath9k_hw_resettxqueue(ah, i);
2520
Sujith2660b812009-02-09 13:27:26 +05302521 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002522 ath9k_hw_init_qos(ah);
2523
Sujith2660b812009-02-09 13:27:26 +05302524 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05302525 ath9k_enable_rfkill(ah);
Johannes Berg3b319aa2009-06-13 14:50:26 +05302526
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002527 ath9k_hw_init_user_settings(ah);
2528
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302529 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302530 REG_WRITE(ah, AR_D_GBL_IFS_SIFS,
2531 AR_D_GBL_IFS_SIFS_ASYNC_FIFO_DUR);
2532 REG_WRITE(ah, AR_D_GBL_IFS_SLOT,
2533 AR_D_GBL_IFS_SLOT_ASYNC_FIFO_DUR);
2534 REG_WRITE(ah, AR_D_GBL_IFS_EIFS,
2535 AR_D_GBL_IFS_EIFS_ASYNC_FIFO_DUR);
2536
2537 REG_WRITE(ah, AR_TIME_OUT, AR_TIME_OUT_ACK_CTS_ASYNC_FIFO_DUR);
2538 REG_WRITE(ah, AR_USEC, AR_USEC_ASYNC_FIFO_DUR);
2539
2540 REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
2541 AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
2542 REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
2543 AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
2544 }
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302545 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302546 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
2547 AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
2548 }
2549
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002550 REG_WRITE(ah, AR_STA_ID1,
2551 REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
2552
2553 ath9k_hw_set_dma(ah);
2554
2555 REG_WRITE(ah, AR_OBS, 8);
2556
Sujith0ef1f162009-03-30 15:28:35 +05302557 if (ah->config.intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002558 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
2559 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
2560 }
2561
2562 ath9k_hw_init_bb(ah, chan);
2563
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002564 if (!ath9k_hw_init_cal(ah, chan))
Joe Perches6badaaf2009-06-28 09:26:32 -07002565 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002566
Sujith2660b812009-02-09 13:27:26 +05302567 rx_chainmask = ah->rxchainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002568 if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) {
2569 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
2570 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
2571 }
2572
2573 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
2574
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002575 /*
2576 * For big endian systems turn on swapping for descriptors
2577 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002578 if (AR_SREV_9100(ah)) {
2579 u32 mask;
2580 mask = REG_READ(ah, AR_CFG);
2581 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002582 ath_print(common, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05302583 "CFG Byte Swap Set 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002584 } else {
2585 mask =
2586 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
2587 REG_WRITE(ah, AR_CFG, mask);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002588 ath_print(common, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05302589 "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002590 }
2591 } else {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002592 /* Configure AR9271 target WLAN */
2593 if (AR_SREV_9271(ah))
2594 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002595#ifdef __BIG_ENDIAN
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002596 else
2597 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002598#endif
2599 }
2600
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002601 if (ah->btcoex_hw.enabled)
Vasanthakumar Thiagarajan42cc41e2009-08-26 21:08:45 +05302602 ath9k_hw_btcoex_enable(ah);
2603
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002604 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002605}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002606EXPORT_SYMBOL(ath9k_hw_reset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002607
Sujithf1dc5602008-10-29 10:16:30 +05302608/************************/
2609/* Key Cache Management */
2610/************************/
2611
Sujithcbe61d82009-02-09 13:27:12 +05302612bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002613{
Sujithf1dc5602008-10-29 10:16:30 +05302614 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002615
Sujith2660b812009-02-09 13:27:26 +05302616 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002617 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2618 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002619 return false;
2620 }
2621
Sujithf1dc5602008-10-29 10:16:30 +05302622 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002623
Sujithf1dc5602008-10-29 10:16:30 +05302624 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
2625 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
2626 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
2627 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
2628 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
2629 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
2630 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
2631 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
2632
2633 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2634 u16 micentry = entry + 64;
2635
2636 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
2637 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
2638 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
2639 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
2640
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002641 }
2642
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002643 return true;
2644}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002645EXPORT_SYMBOL(ath9k_hw_keyreset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002646
Sujithcbe61d82009-02-09 13:27:12 +05302647bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002648{
Sujithf1dc5602008-10-29 10:16:30 +05302649 u32 macHi, macLo;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002650
Sujith2660b812009-02-09 13:27:26 +05302651 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002652 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2653 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002654 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002655 }
2656
Sujithf1dc5602008-10-29 10:16:30 +05302657 if (mac != NULL) {
2658 macHi = (mac[5] << 8) | mac[4];
2659 macLo = (mac[3] << 24) |
2660 (mac[2] << 16) |
2661 (mac[1] << 8) |
2662 mac[0];
2663 macLo >>= 1;
2664 macLo |= (macHi & 1) << 31;
2665 macHi >>= 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002666 } else {
Sujithf1dc5602008-10-29 10:16:30 +05302667 macLo = macHi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002668 }
Sujithf1dc5602008-10-29 10:16:30 +05302669 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
2670 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002671
2672 return true;
2673}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002674EXPORT_SYMBOL(ath9k_hw_keysetmac);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002675
Sujithcbe61d82009-02-09 13:27:12 +05302676bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
Sujithf1dc5602008-10-29 10:16:30 +05302677 const struct ath9k_keyval *k,
Jouni Malinene0caf9e2009-03-02 18:15:53 +02002678 const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002679{
Sujith2660b812009-02-09 13:27:26 +05302680 const struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002681 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302682 u32 key0, key1, key2, key3, key4;
2683 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002684
Sujithf1dc5602008-10-29 10:16:30 +05302685 if (entry >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002686 ath_print(common, ATH_DBG_FATAL,
2687 "keycache entry %u out of range\n", entry);
Sujithf1dc5602008-10-29 10:16:30 +05302688 return false;
2689 }
2690
2691 switch (k->kv_type) {
2692 case ATH9K_CIPHER_AES_OCB:
2693 keyType = AR_KEYTABLE_TYPE_AES;
2694 break;
2695 case ATH9K_CIPHER_AES_CCM:
2696 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002697 ath_print(common, ATH_DBG_ANY,
2698 "AES-CCM not supported by mac rev 0x%x\n",
2699 ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002700 return false;
2701 }
Sujithf1dc5602008-10-29 10:16:30 +05302702 keyType = AR_KEYTABLE_TYPE_CCM;
2703 break;
2704 case ATH9K_CIPHER_TKIP:
2705 keyType = AR_KEYTABLE_TYPE_TKIP;
2706 if (ATH9K_IS_MIC_ENABLED(ah)
2707 && entry + 64 >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002708 ath_print(common, ATH_DBG_ANY,
2709 "entry %u inappropriate for TKIP\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002710 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002711 }
Sujithf1dc5602008-10-29 10:16:30 +05302712 break;
2713 case ATH9K_CIPHER_WEP:
Zhu Yie31a16d2009-05-21 21:47:03 +08002714 if (k->kv_len < WLAN_KEY_LEN_WEP40) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002715 ath_print(common, ATH_DBG_ANY,
2716 "WEP key length %u too small\n", k->kv_len);
Sujithf1dc5602008-10-29 10:16:30 +05302717 return false;
2718 }
Zhu Yie31a16d2009-05-21 21:47:03 +08002719 if (k->kv_len <= WLAN_KEY_LEN_WEP40)
Sujithf1dc5602008-10-29 10:16:30 +05302720 keyType = AR_KEYTABLE_TYPE_40;
Zhu Yie31a16d2009-05-21 21:47:03 +08002721 else if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05302722 keyType = AR_KEYTABLE_TYPE_104;
2723 else
2724 keyType = AR_KEYTABLE_TYPE_128;
2725 break;
2726 case ATH9K_CIPHER_CLR:
2727 keyType = AR_KEYTABLE_TYPE_CLR;
2728 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002729 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002730 ath_print(common, ATH_DBG_FATAL,
2731 "cipher %u not supported\n", k->kv_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002732 return false;
2733 }
Sujithf1dc5602008-10-29 10:16:30 +05302734
Jouni Malinene0caf9e2009-03-02 18:15:53 +02002735 key0 = get_unaligned_le32(k->kv_val + 0);
2736 key1 = get_unaligned_le16(k->kv_val + 4);
2737 key2 = get_unaligned_le32(k->kv_val + 6);
2738 key3 = get_unaligned_le16(k->kv_val + 10);
2739 key4 = get_unaligned_le32(k->kv_val + 12);
Zhu Yie31a16d2009-05-21 21:47:03 +08002740 if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05302741 key4 &= 0xff;
2742
Jouni Malinen672903b2009-03-02 15:06:31 +02002743 /*
2744 * Note: Key cache registers access special memory area that requires
2745 * two 32-bit writes to actually update the values in the internal
2746 * memory. Consequently, the exact order and pairs used here must be
2747 * maintained.
2748 */
2749
Sujithf1dc5602008-10-29 10:16:30 +05302750 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2751 u16 micentry = entry + 64;
2752
Jouni Malinen672903b2009-03-02 15:06:31 +02002753 /*
2754 * Write inverted key[47:0] first to avoid Michael MIC errors
2755 * on frames that could be sent or received at the same time.
2756 * The correct key will be written in the end once everything
2757 * else is ready.
2758 */
Sujithf1dc5602008-10-29 10:16:30 +05302759 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
2760 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002761
2762 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302763 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2764 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002765
2766 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302767 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2768 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
Jouni Malinen672903b2009-03-02 15:06:31 +02002769
2770 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302771 (void) ath9k_hw_keysetmac(ah, entry, mac);
2772
Sujith2660b812009-02-09 13:27:26 +05302773 if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) {
Jouni Malinen672903b2009-03-02 15:06:31 +02002774 /*
2775 * TKIP uses two key cache entries:
2776 * Michael MIC TX/RX keys in the same key cache entry
2777 * (idx = main index + 64):
2778 * key0 [31:0] = RX key [31:0]
2779 * key1 [15:0] = TX key [31:16]
2780 * key1 [31:16] = reserved
2781 * key2 [31:0] = RX key [63:32]
2782 * key3 [15:0] = TX key [15:0]
2783 * key3 [31:16] = reserved
2784 * key4 [31:0] = TX key [63:32]
2785 */
Sujithf1dc5602008-10-29 10:16:30 +05302786 u32 mic0, mic1, mic2, mic3, mic4;
2787
2788 mic0 = get_unaligned_le32(k->kv_mic + 0);
2789 mic2 = get_unaligned_le32(k->kv_mic + 4);
2790 mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
2791 mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
2792 mic4 = get_unaligned_le32(k->kv_txmic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02002793
2794 /* Write RX[31:0] and TX[31:16] */
Sujithf1dc5602008-10-29 10:16:30 +05302795 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2796 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002797
2798 /* Write RX[63:32] and TX[15:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302799 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2800 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002801
2802 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302803 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
2804 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2805 AR_KEYTABLE_TYPE_CLR);
2806
2807 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002808 /*
2809 * TKIP uses four key cache entries (two for group
2810 * keys):
2811 * Michael MIC TX/RX keys are in different key cache
2812 * entries (idx = main index + 64 for TX and
2813 * main index + 32 + 96 for RX):
2814 * key0 [31:0] = TX/RX MIC key [31:0]
2815 * key1 [31:0] = reserved
2816 * key2 [31:0] = TX/RX MIC key [63:32]
2817 * key3 [31:0] = reserved
2818 * key4 [31:0] = reserved
2819 *
2820 * Upper layer code will call this function separately
2821 * for TX and RX keys when these registers offsets are
2822 * used.
2823 */
Sujithf1dc5602008-10-29 10:16:30 +05302824 u32 mic0, mic2;
2825
2826 mic0 = get_unaligned_le32(k->kv_mic + 0);
2827 mic2 = get_unaligned_le32(k->kv_mic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02002828
2829 /* Write MIC key[31:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302830 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2831 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002832
2833 /* Write MIC key[63:32] */
Sujithf1dc5602008-10-29 10:16:30 +05302834 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2835 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002836
2837 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302838 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
2839 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2840 AR_KEYTABLE_TYPE_CLR);
2841 }
Jouni Malinen672903b2009-03-02 15:06:31 +02002842
2843 /* MAC address registers are reserved for the MIC entry */
Sujithf1dc5602008-10-29 10:16:30 +05302844 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
2845 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002846
2847 /*
2848 * Write the correct (un-inverted) key[47:0] last to enable
2849 * TKIP now that all other registers are set with correct
2850 * values.
2851 */
Sujithf1dc5602008-10-29 10:16:30 +05302852 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2853 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
2854 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002855 /* Write key[47:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302856 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2857 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002858
2859 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302860 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2861 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002862
2863 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302864 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2865 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
2866
Jouni Malinen672903b2009-03-02 15:06:31 +02002867 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302868 (void) ath9k_hw_keysetmac(ah, entry, mac);
2869 }
2870
Sujithf1dc5602008-10-29 10:16:30 +05302871 return true;
2872}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002873EXPORT_SYMBOL(ath9k_hw_set_keycache_entry);
Sujithf1dc5602008-10-29 10:16:30 +05302874
Sujithcbe61d82009-02-09 13:27:12 +05302875bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry)
Sujithf1dc5602008-10-29 10:16:30 +05302876{
Sujith2660b812009-02-09 13:27:26 +05302877 if (entry < ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05302878 u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
2879 if (val & AR_KEYTABLE_VALID)
2880 return true;
2881 }
2882 return false;
2883}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002884EXPORT_SYMBOL(ath9k_hw_keyisvalid);
Sujithf1dc5602008-10-29 10:16:30 +05302885
2886/******************************/
2887/* Power Management (Chipset) */
2888/******************************/
2889
Sujithcbe61d82009-02-09 13:27:12 +05302890static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302891{
2892 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2893 if (setChip) {
2894 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2895 AR_RTC_FORCE_WAKE_EN);
2896 if (!AR_SREV_9100(ah))
2897 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
2898
Sujith4921be82009-09-18 15:04:27 +05302899 if(!AR_SREV_5416(ah))
2900 REG_CLR_BIT(ah, (AR_RTC_RESET),
2901 AR_RTC_RESET_EN);
Sujithf1dc5602008-10-29 10:16:30 +05302902 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002903}
2904
Sujithcbe61d82009-02-09 13:27:12 +05302905static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002906{
Sujithf1dc5602008-10-29 10:16:30 +05302907 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2908 if (setChip) {
Sujith2660b812009-02-09 13:27:26 +05302909 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002910
Sujithf1dc5602008-10-29 10:16:30 +05302911 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
2912 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2913 AR_RTC_FORCE_WAKE_ON_INT);
2914 } else {
2915 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2916 AR_RTC_FORCE_WAKE_EN);
2917 }
2918 }
2919}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002920
Sujithcbe61d82009-02-09 13:27:12 +05302921static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302922{
2923 u32 val;
2924 int i;
2925
2926 if (setChip) {
2927 if ((REG_READ(ah, AR_RTC_STATUS) &
2928 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2929 if (ath9k_hw_set_reset_reg(ah,
2930 ATH9K_RESET_POWER_ON) != true) {
2931 return false;
2932 }
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05302933 ath9k_hw_init_pll(ah, NULL);
Sujithf1dc5602008-10-29 10:16:30 +05302934 }
2935 if (AR_SREV_9100(ah))
2936 REG_SET_BIT(ah, AR_RTC_RESET,
2937 AR_RTC_RESET_EN);
2938
2939 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2940 AR_RTC_FORCE_WAKE_EN);
2941 udelay(50);
2942
2943 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2944 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2945 if (val == AR_RTC_STATUS_ON)
2946 break;
2947 udelay(50);
2948 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2949 AR_RTC_FORCE_WAKE_EN);
2950 }
2951 if (i == 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002952 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2953 "Failed to wakeup in %uus\n",
2954 POWER_UP_TIME / 20);
Sujithf1dc5602008-10-29 10:16:30 +05302955 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002956 }
2957 }
2958
Sujithf1dc5602008-10-29 10:16:30 +05302959 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2960
2961 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002962}
2963
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002964bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05302965{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002966 struct ath_common *common = ath9k_hw_common(ah);
Sujithcbe61d82009-02-09 13:27:12 +05302967 int status = true, setChip = true;
Sujithf1dc5602008-10-29 10:16:30 +05302968 static const char *modes[] = {
2969 "AWAKE",
2970 "FULL-SLEEP",
2971 "NETWORK SLEEP",
2972 "UNDEFINED"
2973 };
Sujithf1dc5602008-10-29 10:16:30 +05302974
Gabor Juhoscbdec972009-07-24 17:27:22 +02002975 if (ah->power_mode == mode)
2976 return status;
2977
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002978 ath_print(common, ATH_DBG_RESET, "%s -> %s\n",
2979 modes[ah->power_mode], modes[mode]);
Sujithf1dc5602008-10-29 10:16:30 +05302980
2981 switch (mode) {
2982 case ATH9K_PM_AWAKE:
2983 status = ath9k_hw_set_power_awake(ah, setChip);
2984 break;
2985 case ATH9K_PM_FULL_SLEEP:
2986 ath9k_set_power_sleep(ah, setChip);
Sujith2660b812009-02-09 13:27:26 +05302987 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05302988 break;
2989 case ATH9K_PM_NETWORK_SLEEP:
2990 ath9k_set_power_network_sleep(ah, setChip);
2991 break;
2992 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002993 ath_print(common, ATH_DBG_FATAL,
2994 "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05302995 return false;
2996 }
Sujith2660b812009-02-09 13:27:26 +05302997 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05302998
2999 return status;
3000}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003001EXPORT_SYMBOL(ath9k_hw_setpower);
Sujithf1dc5602008-10-29 10:16:30 +05303002
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08003003/*
3004 * Helper for ASPM support.
3005 *
3006 * Disable PLL when in L0s as well as receiver clock when in L1.
3007 * This power saving option must be enabled through the SerDes.
3008 *
3009 * Programming the SerDes must go through the same 288 bit serial shift
3010 * register as the other analog registers. Hence the 9 writes.
3011 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303012void ath9k_hw_configpcipowersave(struct ath_hw *ah, int restore, int power_off)
Sujithf1dc5602008-10-29 10:16:30 +05303013{
Sujithf1dc5602008-10-29 10:16:30 +05303014 u8 i;
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303015 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05303016
Sujith2660b812009-02-09 13:27:26 +05303017 if (ah->is_pciexpress != true)
Sujithf1dc5602008-10-29 10:16:30 +05303018 return;
3019
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08003020 /* Do not touch SerDes registers */
Sujith2660b812009-02-09 13:27:26 +05303021 if (ah->config.pcie_powersave_enable == 2)
Sujithf1dc5602008-10-29 10:16:30 +05303022 return;
3023
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08003024 /* Nothing to do on restore for 11N */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303025 if (!restore) {
3026 if (AR_SREV_9280_20_OR_LATER(ah)) {
3027 /*
3028 * AR9280 2.0 or later chips use SerDes values from the
3029 * initvals.h initialized depending on chipset during
3030 * ath9k_hw_init()
3031 */
3032 for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
3033 REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
3034 INI_RA(&ah->iniPcieSerdes, i, 1));
3035 }
3036 } else if (AR_SREV_9280(ah) &&
3037 (ah->hw_version.macRev == AR_SREV_REVISION_9280_10)) {
3038 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
3039 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
Sujithf1dc5602008-10-29 10:16:30 +05303040
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303041 /* RX shut off when elecidle is asserted */
3042 REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
3043 REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
3044 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
3045
3046 /* Shut off CLKREQ active in L1 */
3047 if (ah->config.pcie_clock_req)
3048 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
3049 else
3050 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
3051
3052 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
3053 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
3054 REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
3055
3056 /* Load the new settings */
3057 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
3058
3059 } else {
3060 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
3061 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
3062
3063 /* RX shut off when elecidle is asserted */
3064 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
3065 REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
3066 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
3067
3068 /*
3069 * Ignore ah->ah_config.pcie_clock_req setting for
3070 * pre-AR9280 11n
3071 */
3072 REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
3073
3074 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
3075 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
3076 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
3077
3078 /* Load the new settings */
3079 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
Sujithf1dc5602008-10-29 10:16:30 +05303080 }
Sujithf1dc5602008-10-29 10:16:30 +05303081
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303082 udelay(1000);
Sujithf1dc5602008-10-29 10:16:30 +05303083
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303084 /* set bit 19 to allow forcing of pcie core into L1 state */
3085 REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
Sujithf1dc5602008-10-29 10:16:30 +05303086
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303087 /* Several PCIe massages to ensure proper behaviour */
3088 if (ah->config.pcie_waen) {
3089 val = ah->config.pcie_waen;
3090 if (!power_off)
3091 val &= (~AR_WA_D3_L1_DISABLE);
3092 } else {
3093 if (AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
3094 AR_SREV_9287(ah)) {
3095 val = AR9285_WA_DEFAULT;
3096 if (!power_off)
3097 val &= (~AR_WA_D3_L1_DISABLE);
3098 } else if (AR_SREV_9280(ah)) {
3099 /*
3100 * On AR9280 chips bit 22 of 0x4004 needs to be
3101 * set otherwise card may disappear.
3102 */
3103 val = AR9280_WA_DEFAULT;
3104 if (!power_off)
3105 val &= (~AR_WA_D3_L1_DISABLE);
3106 } else
3107 val = AR_WA_DEFAULT;
3108 }
Sujithf1dc5602008-10-29 10:16:30 +05303109
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303110 REG_WRITE(ah, AR_WA, val);
Sujithf1dc5602008-10-29 10:16:30 +05303111 }
3112
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303113 if (power_off) {
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08003114 /*
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303115 * Set PCIe workaround bits
3116 * bit 14 in WA register (disable L1) should only
3117 * be set when device enters D3 and be cleared
3118 * when device comes back to D0.
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08003119 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303120 if (ah->config.pcie_waen) {
3121 if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE)
3122 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
3123 } else {
3124 if (((AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
3125 AR_SREV_9287(ah)) &&
3126 (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)) ||
3127 (AR_SREV_9280(ah) &&
3128 (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE))) {
3129 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
3130 }
3131 }
Sujithf1dc5602008-10-29 10:16:30 +05303132 }
3133}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003134EXPORT_SYMBOL(ath9k_hw_configpcipowersave);
Sujithf1dc5602008-10-29 10:16:30 +05303135
3136/**********************/
3137/* Interrupt Handling */
3138/**********************/
3139
Sujithcbe61d82009-02-09 13:27:12 +05303140bool ath9k_hw_intrpend(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003141{
3142 u32 host_isr;
3143
3144 if (AR_SREV_9100(ah))
3145 return true;
3146
3147 host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
3148 if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
3149 return true;
3150
3151 host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
3152 if ((host_isr & AR_INTR_SYNC_DEFAULT)
3153 && (host_isr != AR_INTR_SPURIOUS))
3154 return true;
3155
3156 return false;
3157}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003158EXPORT_SYMBOL(ath9k_hw_intrpend);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003159
Sujithcbe61d82009-02-09 13:27:12 +05303160bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003161{
3162 u32 isr = 0;
3163 u32 mask2 = 0;
Sujith2660b812009-02-09 13:27:26 +05303164 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003165 u32 sync_cause = 0;
3166 bool fatal_int = false;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003167 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003168
3169 if (!AR_SREV_9100(ah)) {
3170 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
3171 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
3172 == AR_RTC_STATUS_ON) {
3173 isr = REG_READ(ah, AR_ISR);
3174 }
3175 }
3176
Sujithf1dc5602008-10-29 10:16:30 +05303177 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
3178 AR_INTR_SYNC_DEFAULT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003179
3180 *masked = 0;
3181
3182 if (!isr && !sync_cause)
3183 return false;
3184 } else {
3185 *masked = 0;
3186 isr = REG_READ(ah, AR_ISR);
3187 }
3188
3189 if (isr) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003190 if (isr & AR_ISR_BCNMISC) {
3191 u32 isr2;
3192 isr2 = REG_READ(ah, AR_ISR_S2);
3193 if (isr2 & AR_ISR_S2_TIM)
3194 mask2 |= ATH9K_INT_TIM;
3195 if (isr2 & AR_ISR_S2_DTIM)
3196 mask2 |= ATH9K_INT_DTIM;
3197 if (isr2 & AR_ISR_S2_DTIMSYNC)
3198 mask2 |= ATH9K_INT_DTIMSYNC;
3199 if (isr2 & (AR_ISR_S2_CABEND))
3200 mask2 |= ATH9K_INT_CABEND;
3201 if (isr2 & AR_ISR_S2_GTT)
3202 mask2 |= ATH9K_INT_GTT;
3203 if (isr2 & AR_ISR_S2_CST)
3204 mask2 |= ATH9K_INT_CST;
Sujith4af9cf42009-02-12 10:06:47 +05303205 if (isr2 & AR_ISR_S2_TSFOOR)
3206 mask2 |= ATH9K_INT_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003207 }
3208
3209 isr = REG_READ(ah, AR_ISR_RAC);
3210 if (isr == 0xffffffff) {
3211 *masked = 0;
3212 return false;
3213 }
3214
3215 *masked = isr & ATH9K_INT_COMMON;
3216
Sujith0ef1f162009-03-30 15:28:35 +05303217 if (ah->config.intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003218 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
3219 *masked |= ATH9K_INT_RX;
3220 }
3221
3222 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
3223 *masked |= ATH9K_INT_RX;
3224 if (isr &
3225 (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
3226 AR_ISR_TXEOL)) {
3227 u32 s0_s, s1_s;
3228
3229 *masked |= ATH9K_INT_TX;
3230
3231 s0_s = REG_READ(ah, AR_ISR_S0_S);
Sujith2660b812009-02-09 13:27:26 +05303232 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
3233 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003234
3235 s1_s = REG_READ(ah, AR_ISR_S1_S);
Sujith2660b812009-02-09 13:27:26 +05303236 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
3237 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003238 }
3239
3240 if (isr & AR_ISR_RXORN) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003241 ath_print(common, ATH_DBG_INTERRUPT,
3242 "receive FIFO overrun interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003243 }
3244
3245 if (!AR_SREV_9100(ah)) {
Sujith60b67f52008-08-07 10:52:38 +05303246 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003247 u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
3248 if (isr5 & AR_ISR_S5_TIM_TIMER)
3249 *masked |= ATH9K_INT_TIM_TIMER;
3250 }
3251 }
3252
3253 *masked |= mask2;
3254 }
Sujithf1dc5602008-10-29 10:16:30 +05303255
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003256 if (AR_SREV_9100(ah))
3257 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303258
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303259 if (isr & AR_ISR_GENTMR) {
3260 u32 s5_s;
3261
3262 s5_s = REG_READ(ah, AR_ISR_S5_S);
3263 if (isr & AR_ISR_GENTMR) {
3264 ah->intr_gen_timer_trigger =
3265 MS(s5_s, AR_ISR_S5_GENTIMER_TRIG);
3266
3267 ah->intr_gen_timer_thresh =
3268 MS(s5_s, AR_ISR_S5_GENTIMER_THRESH);
3269
3270 if (ah->intr_gen_timer_trigger)
3271 *masked |= ATH9K_INT_GENTIMER;
3272
3273 }
3274 }
3275
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003276 if (sync_cause) {
3277 fatal_int =
3278 (sync_cause &
3279 (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
3280 ? true : false;
3281
3282 if (fatal_int) {
3283 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003284 ath_print(common, ATH_DBG_ANY,
3285 "received PCI FATAL interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003286 }
3287 if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003288 ath_print(common, ATH_DBG_ANY,
3289 "received PCI PERR interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003290 }
Steven Luoa89bff92009-04-12 02:57:54 -07003291 *masked |= ATH9K_INT_FATAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003292 }
3293 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003294 ath_print(common, ATH_DBG_INTERRUPT,
3295 "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003296 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
3297 REG_WRITE(ah, AR_RC, 0);
3298 *masked |= ATH9K_INT_FATAL;
3299 }
3300 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003301 ath_print(common, ATH_DBG_INTERRUPT,
3302 "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003303 }
3304
3305 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
3306 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
3307 }
Sujithf1dc5602008-10-29 10:16:30 +05303308
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003309 return true;
3310}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003311EXPORT_SYMBOL(ath9k_hw_getisr);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003312
Sujithcbe61d82009-02-09 13:27:12 +05303313enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003314{
Sujith2660b812009-02-09 13:27:26 +05303315 u32 omask = ah->mask_reg;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003316 u32 mask, mask2;
Sujith2660b812009-02-09 13:27:26 +05303317 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003318 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003319
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003320 ath_print(common, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003321
3322 if (omask & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003323 ath_print(common, ATH_DBG_INTERRUPT, "disable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003324 REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
3325 (void) REG_READ(ah, AR_IER);
3326 if (!AR_SREV_9100(ah)) {
3327 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
3328 (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
3329
3330 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
3331 (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
3332 }
3333 }
3334
3335 mask = ints & ATH9K_INT_COMMON;
3336 mask2 = 0;
3337
3338 if (ints & ATH9K_INT_TX) {
Sujith2660b812009-02-09 13:27:26 +05303339 if (ah->txok_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003340 mask |= AR_IMR_TXOK;
Sujith2660b812009-02-09 13:27:26 +05303341 if (ah->txdesc_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003342 mask |= AR_IMR_TXDESC;
Sujith2660b812009-02-09 13:27:26 +05303343 if (ah->txerr_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003344 mask |= AR_IMR_TXERR;
Sujith2660b812009-02-09 13:27:26 +05303345 if (ah->txeol_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003346 mask |= AR_IMR_TXEOL;
3347 }
3348 if (ints & ATH9K_INT_RX) {
3349 mask |= AR_IMR_RXERR;
Sujith0ef1f162009-03-30 15:28:35 +05303350 if (ah->config.intr_mitigation)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003351 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
3352 else
3353 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
Sujith60b67f52008-08-07 10:52:38 +05303354 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003355 mask |= AR_IMR_GENTMR;
3356 }
3357
3358 if (ints & (ATH9K_INT_BMISC)) {
3359 mask |= AR_IMR_BCNMISC;
3360 if (ints & ATH9K_INT_TIM)
3361 mask2 |= AR_IMR_S2_TIM;
3362 if (ints & ATH9K_INT_DTIM)
3363 mask2 |= AR_IMR_S2_DTIM;
3364 if (ints & ATH9K_INT_DTIMSYNC)
3365 mask2 |= AR_IMR_S2_DTIMSYNC;
3366 if (ints & ATH9K_INT_CABEND)
Sujith4af9cf42009-02-12 10:06:47 +05303367 mask2 |= AR_IMR_S2_CABEND;
3368 if (ints & ATH9K_INT_TSFOOR)
3369 mask2 |= AR_IMR_S2_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003370 }
3371
3372 if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
3373 mask |= AR_IMR_BCNMISC;
3374 if (ints & ATH9K_INT_GTT)
3375 mask2 |= AR_IMR_S2_GTT;
3376 if (ints & ATH9K_INT_CST)
3377 mask2 |= AR_IMR_S2_CST;
3378 }
3379
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003380 ath_print(common, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003381 REG_WRITE(ah, AR_IMR, mask);
3382 mask = REG_READ(ah, AR_IMR_S2) & ~(AR_IMR_S2_TIM |
3383 AR_IMR_S2_DTIM |
3384 AR_IMR_S2_DTIMSYNC |
3385 AR_IMR_S2_CABEND |
3386 AR_IMR_S2_CABTO |
3387 AR_IMR_S2_TSFOOR |
3388 AR_IMR_S2_GTT | AR_IMR_S2_CST);
3389 REG_WRITE(ah, AR_IMR_S2, mask | mask2);
Sujith2660b812009-02-09 13:27:26 +05303390 ah->mask_reg = ints;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003391
Sujith60b67f52008-08-07 10:52:38 +05303392 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003393 if (ints & ATH9K_INT_TIM_TIMER)
3394 REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
3395 else
3396 REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
3397 }
3398
3399 if (ints & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003400 ath_print(common, ATH_DBG_INTERRUPT, "enable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003401 REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
3402 if (!AR_SREV_9100(ah)) {
3403 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
3404 AR_INTR_MAC_IRQ);
3405 REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
3406
3407
3408 REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
3409 AR_INTR_SYNC_DEFAULT);
3410 REG_WRITE(ah, AR_INTR_SYNC_MASK,
3411 AR_INTR_SYNC_DEFAULT);
3412 }
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003413 ath_print(common, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
3414 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003415 }
3416
3417 return omask;
3418}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003419EXPORT_SYMBOL(ath9k_hw_set_interrupts);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003420
Sujithf1dc5602008-10-29 10:16:30 +05303421/*******************/
3422/* Beacon Handling */
3423/*******************/
3424
Sujithcbe61d82009-02-09 13:27:12 +05303425void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003426{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003427 int flags = 0;
3428
Sujith2660b812009-02-09 13:27:26 +05303429 ah->beacon_interval = beacon_period;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003430
Sujith2660b812009-02-09 13:27:26 +05303431 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08003432 case NL80211_IFTYPE_STATION:
3433 case NL80211_IFTYPE_MONITOR:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003434 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3435 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
3436 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
3437 flags |= AR_TBTT_TIMER_EN;
3438 break;
Colin McCabed97809d2008-12-01 13:38:55 -08003439 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04003440 case NL80211_IFTYPE_MESH_POINT:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003441 REG_SET_BIT(ah, AR_TXCFG,
3442 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
3443 REG_WRITE(ah, AR_NEXT_NDP_TIMER,
3444 TU_TO_USEC(next_beacon +
Sujith2660b812009-02-09 13:27:26 +05303445 (ah->atim_window ? ah->
3446 atim_window : 1)));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003447 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08003448 case NL80211_IFTYPE_AP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003449 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3450 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
3451 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05303452 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05303453 dma_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003454 REG_WRITE(ah, AR_NEXT_SWBA,
3455 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05303456 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05303457 sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003458 flags |=
3459 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
3460 break;
Colin McCabed97809d2008-12-01 13:38:55 -08003461 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003462 ath_print(ath9k_hw_common(ah), ATH_DBG_BEACON,
3463 "%s: unsupported opmode: %d\n",
3464 __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08003465 return;
3466 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003467 }
3468
3469 REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3470 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3471 REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
3472 REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
3473
3474 beacon_period &= ~ATH9K_BEACON_ENA;
3475 if (beacon_period & ATH9K_BEACON_RESET_TSF) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003476 ath9k_hw_reset_tsf(ah);
3477 }
3478
3479 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
3480}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003481EXPORT_SYMBOL(ath9k_hw_beaconinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003482
Sujithcbe61d82009-02-09 13:27:12 +05303483void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303484 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003485{
3486 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05303487 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003488 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003489
3490 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
3491
3492 REG_WRITE(ah, AR_BEACON_PERIOD,
3493 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3494 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
3495 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3496
3497 REG_RMW_FIELD(ah, AR_RSSI_THR,
3498 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
3499
3500 beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
3501
3502 if (bs->bs_sleepduration > beaconintval)
3503 beaconintval = bs->bs_sleepduration;
3504
3505 dtimperiod = bs->bs_dtimperiod;
3506 if (bs->bs_sleepduration > dtimperiod)
3507 dtimperiod = bs->bs_sleepduration;
3508
3509 if (beaconintval == dtimperiod)
3510 nextTbtt = bs->bs_nextdtim;
3511 else
3512 nextTbtt = bs->bs_nexttbtt;
3513
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003514 ath_print(common, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
3515 ath_print(common, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
3516 ath_print(common, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
3517 ath_print(common, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003518
3519 REG_WRITE(ah, AR_NEXT_DTIM,
3520 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
3521 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
3522
3523 REG_WRITE(ah, AR_SLEEP1,
3524 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
3525 | AR_SLEEP1_ASSUME_DTIM);
3526
Sujith60b67f52008-08-07 10:52:38 +05303527 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003528 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
3529 else
3530 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
3531
3532 REG_WRITE(ah, AR_SLEEP2,
3533 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
3534
3535 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
3536 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
3537
3538 REG_SET_BIT(ah, AR_TIMER_MODE,
3539 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
3540 AR_DTIM_TIMER_EN);
3541
Sujith4af9cf42009-02-12 10:06:47 +05303542 /* TSF Out of Range Threshold */
3543 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003544}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003545EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003546
Sujithf1dc5602008-10-29 10:16:30 +05303547/*******************/
3548/* HW Capabilities */
3549/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003550
Sujitheef7a572009-03-30 15:28:28 +05303551void ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003552{
Sujith2660b812009-02-09 13:27:26 +05303553 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003554 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003555 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003556 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003557
Sujithf1dc5602008-10-29 10:16:30 +05303558 u16 capField = 0, eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003559
Sujithf74df6f2009-02-09 13:27:24 +05303560 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003561 regulatory->current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303562
Sujithf74df6f2009-02-09 13:27:24 +05303563 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
Sujithfec0de12009-02-12 10:06:43 +05303564 if (AR_SREV_9285_10_OR_LATER(ah))
3565 eeval |= AR9285_RDEXT_DEFAULT;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003566 regulatory->current_rd_ext = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303567
Sujithf74df6f2009-02-09 13:27:24 +05303568 capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
Sujithf1dc5602008-10-29 10:16:30 +05303569
Sujith2660b812009-02-09 13:27:26 +05303570 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05303571 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003572 if (regulatory->current_rd == 0x64 ||
3573 regulatory->current_rd == 0x65)
3574 regulatory->current_rd += 5;
3575 else if (regulatory->current_rd == 0x41)
3576 regulatory->current_rd = 0x43;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003577 ath_print(common, ATH_DBG_REGULATORY,
3578 "regdomain mapped to 0x%x\n", regulatory->current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003579 }
Sujithdc2222a2008-08-14 13:26:55 +05303580
Sujithf74df6f2009-02-09 13:27:24 +05303581 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Sujithf1dc5602008-10-29 10:16:30 +05303582 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003583
Sujithf1dc5602008-10-29 10:16:30 +05303584 if (eeval & AR5416_OPFLAGS_11A) {
3585 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303586 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303587 if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
3588 set_bit(ATH9K_MODE_11NA_HT20,
3589 pCap->wireless_modes);
3590 if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
3591 set_bit(ATH9K_MODE_11NA_HT40PLUS,
3592 pCap->wireless_modes);
3593 set_bit(ATH9K_MODE_11NA_HT40MINUS,
3594 pCap->wireless_modes);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003595 }
3596 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003597 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003598
Sujithf1dc5602008-10-29 10:16:30 +05303599 if (eeval & AR5416_OPFLAGS_11G) {
Sujithf1dc5602008-10-29 10:16:30 +05303600 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303601 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303602 if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
3603 set_bit(ATH9K_MODE_11NG_HT20,
3604 pCap->wireless_modes);
3605 if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
3606 set_bit(ATH9K_MODE_11NG_HT40PLUS,
3607 pCap->wireless_modes);
3608 set_bit(ATH9K_MODE_11NG_HT40MINUS,
3609 pCap->wireless_modes);
3610 }
3611 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003612 }
Sujithf1dc5602008-10-29 10:16:30 +05303613
Sujithf74df6f2009-02-09 13:27:24 +05303614 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003615 /*
3616 * For AR9271 we will temporarilly uses the rx chainmax as read from
3617 * the EEPROM.
3618 */
Sujith8147f5d2009-02-20 15:13:23 +05303619 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003620 !(eeval & AR5416_OPFLAGS_11A) &&
3621 !(AR_SREV_9271(ah)))
3622 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
Sujith8147f5d2009-02-20 15:13:23 +05303623 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
3624 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003625 /* Use rx_chainmask from EEPROM. */
Sujith8147f5d2009-02-20 15:13:23 +05303626 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05303627
Sujithd535a422009-02-09 13:27:06 +05303628 if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0)))
Sujith2660b812009-02-09 13:27:26 +05303629 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05303630
3631 pCap->low_2ghz_chan = 2312;
3632 pCap->high_2ghz_chan = 2732;
3633
3634 pCap->low_5ghz_chan = 4920;
3635 pCap->high_5ghz_chan = 6100;
3636
3637 pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
3638 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
3639 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
3640
3641 pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
3642 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
3643 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
3644
Sujith2660b812009-02-09 13:27:26 +05303645 if (ah->config.ht_enable)
Sujithf1dc5602008-10-29 10:16:30 +05303646 pCap->hw_caps |= ATH9K_HW_CAP_HT;
3647 else
3648 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
3649
3650 pCap->hw_caps |= ATH9K_HW_CAP_GTT;
3651 pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
3652 pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
3653 pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
3654
3655 if (capField & AR_EEPROM_EEPCAP_MAXQCU)
3656 pCap->total_queues =
3657 MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
3658 else
3659 pCap->total_queues = ATH9K_NUM_TX_QUEUES;
3660
3661 if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
3662 pCap->keycache_size =
3663 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
3664 else
3665 pCap->keycache_size = AR_KEYTABLE_SIZE;
3666
3667 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
Sujithf1dc5602008-10-29 10:16:30 +05303668 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
3669
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303670 if (AR_SREV_9285_10_OR_LATER(ah))
3671 pCap->num_gpio_pins = AR9285_NUM_GPIO;
3672 else if (AR_SREV_9280_10_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303673 pCap->num_gpio_pins = AR928X_NUM_GPIO;
3674 else
3675 pCap->num_gpio_pins = AR_NUM_GPIO;
3676
Sujithf1dc5602008-10-29 10:16:30 +05303677 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
3678 pCap->hw_caps |= ATH9K_HW_CAP_CST;
3679 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
3680 } else {
3681 pCap->rts_aggr_limit = (8 * 1024);
3682 }
3683
3684 pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
3685
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05303686#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05303687 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
3688 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
3689 ah->rfkill_gpio =
3690 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
3691 ah->rfkill_polarity =
3692 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05303693
3694 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
3695 }
3696#endif
3697
Vivek Natarajana3ca95fb2009-09-17 09:29:07 +05303698 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
Sujithf1dc5602008-10-29 10:16:30 +05303699
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05303700 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303701 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
3702 else
3703 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
3704
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003705 if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) {
Sujithf1dc5602008-10-29 10:16:30 +05303706 pCap->reg_cap =
3707 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3708 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
3709 AR_EEPROM_EEREGCAP_EN_KK_U2 |
3710 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
3711 } else {
3712 pCap->reg_cap =
3713 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3714 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
3715 }
3716
Senthil Balasubramanianebb90cf2009-09-18 15:07:33 +05303717 /* Advertise midband for AR5416 with FCC midband set in eeprom */
3718 if (regulatory->current_rd_ext & (1 << REG_EXT_FCC_MIDBAND) &&
3719 AR_SREV_5416(ah))
3720 pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
Sujithf1dc5602008-10-29 10:16:30 +05303721
3722 pCap->num_antcfg_5ghz =
Sujithf74df6f2009-02-09 13:27:24 +05303723 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303724 pCap->num_antcfg_2ghz =
Sujithf74df6f2009-02-09 13:27:24 +05303725 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303726
Vasanthakumar Thiagarajanfe129462009-09-09 15:25:50 +05303727 if (AR_SREV_9280_10_OR_LATER(ah) &&
Luis R. Rodrigueza36cfbc2009-09-09 16:05:32 -07003728 ath9k_hw_btcoex_supported(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003729 btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO;
3730 btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO;
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05303731
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303732 if (AR_SREV_9285(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003733 btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
3734 btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303735 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003736 btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303737 }
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05303738 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003739 btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE;
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303740 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003741}
3742
Sujithcbe61d82009-02-09 13:27:12 +05303743bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303744 u32 capability, u32 *result)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003745{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003746 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05303747 switch (type) {
3748 case ATH9K_CAP_CIPHER:
3749 switch (capability) {
3750 case ATH9K_CIPHER_AES_CCM:
3751 case ATH9K_CIPHER_AES_OCB:
3752 case ATH9K_CIPHER_TKIP:
3753 case ATH9K_CIPHER_WEP:
3754 case ATH9K_CIPHER_MIC:
3755 case ATH9K_CIPHER_CLR:
3756 return true;
3757 default:
3758 return false;
3759 }
3760 case ATH9K_CAP_TKIP_MIC:
3761 switch (capability) {
3762 case 0:
3763 return true;
3764 case 1:
Sujith2660b812009-02-09 13:27:26 +05303765 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303766 AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
3767 false;
3768 }
3769 case ATH9K_CAP_TKIP_SPLIT:
Sujith2660b812009-02-09 13:27:26 +05303770 return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ?
Sujithf1dc5602008-10-29 10:16:30 +05303771 false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303772 case ATH9K_CAP_DIVERSITY:
3773 return (REG_READ(ah, AR_PHY_CCK_DETECT) &
3774 AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV) ?
3775 true : false;
Sujithf1dc5602008-10-29 10:16:30 +05303776 case ATH9K_CAP_MCAST_KEYSRCH:
3777 switch (capability) {
3778 case 0:
3779 return true;
3780 case 1:
3781 if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
3782 return false;
3783 } else {
Sujith2660b812009-02-09 13:27:26 +05303784 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303785 AR_STA_ID1_MCAST_KSRCH) ? true :
3786 false;
3787 }
3788 }
3789 return false;
Sujithf1dc5602008-10-29 10:16:30 +05303790 case ATH9K_CAP_TXPOW:
3791 switch (capability) {
3792 case 0:
3793 return 0;
3794 case 1:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003795 *result = regulatory->power_limit;
Sujithf1dc5602008-10-29 10:16:30 +05303796 return 0;
3797 case 2:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003798 *result = regulatory->max_power_level;
Sujithf1dc5602008-10-29 10:16:30 +05303799 return 0;
3800 case 3:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003801 *result = regulatory->tp_scale;
Sujithf1dc5602008-10-29 10:16:30 +05303802 return 0;
3803 }
3804 return false;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05303805 case ATH9K_CAP_DS:
3806 return (AR_SREV_9280_20_OR_LATER(ah) &&
3807 (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1))
3808 ? false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303809 default:
3810 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003811 }
Sujithf1dc5602008-10-29 10:16:30 +05303812}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003813EXPORT_SYMBOL(ath9k_hw_getcapability);
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003814
Sujithcbe61d82009-02-09 13:27:12 +05303815bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303816 u32 capability, u32 setting, int *status)
3817{
Sujithf1dc5602008-10-29 10:16:30 +05303818 u32 v;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003819
Sujithf1dc5602008-10-29 10:16:30 +05303820 switch (type) {
3821 case ATH9K_CAP_TKIP_MIC:
3822 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303823 ah->sta_id1_defaults |=
Sujithf1dc5602008-10-29 10:16:30 +05303824 AR_STA_ID1_CRPT_MIC_ENABLE;
3825 else
Sujith2660b812009-02-09 13:27:26 +05303826 ah->sta_id1_defaults &=
Sujithf1dc5602008-10-29 10:16:30 +05303827 ~AR_STA_ID1_CRPT_MIC_ENABLE;
3828 return true;
3829 case ATH9K_CAP_DIVERSITY:
3830 v = REG_READ(ah, AR_PHY_CCK_DETECT);
3831 if (setting)
3832 v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3833 else
3834 v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3835 REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
3836 return true;
3837 case ATH9K_CAP_MCAST_KEYSRCH:
3838 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303839 ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303840 else
Sujith2660b812009-02-09 13:27:26 +05303841 ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303842 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303843 default:
3844 return false;
3845 }
3846}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003847EXPORT_SYMBOL(ath9k_hw_setcapability);
Sujithf1dc5602008-10-29 10:16:30 +05303848
3849/****************************/
3850/* GPIO / RFKILL / Antennae */
3851/****************************/
3852
Sujithcbe61d82009-02-09 13:27:12 +05303853static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303854 u32 gpio, u32 type)
3855{
3856 int addr;
3857 u32 gpio_shift, tmp;
3858
3859 if (gpio > 11)
3860 addr = AR_GPIO_OUTPUT_MUX3;
3861 else if (gpio > 5)
3862 addr = AR_GPIO_OUTPUT_MUX2;
3863 else
3864 addr = AR_GPIO_OUTPUT_MUX1;
3865
3866 gpio_shift = (gpio % 6) * 5;
3867
3868 if (AR_SREV_9280_20_OR_LATER(ah)
3869 || (addr != AR_GPIO_OUTPUT_MUX1)) {
3870 REG_RMW(ah, addr, (type << gpio_shift),
3871 (0x1f << gpio_shift));
3872 } else {
3873 tmp = REG_READ(ah, addr);
3874 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
3875 tmp &= ~(0x1f << gpio_shift);
3876 tmp |= (type << gpio_shift);
3877 REG_WRITE(ah, addr, tmp);
3878 }
3879}
3880
Sujithcbe61d82009-02-09 13:27:12 +05303881void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303882{
3883 u32 gpio_shift;
3884
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07003885 BUG_ON(gpio >= ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05303886
3887 gpio_shift = gpio << 1;
3888
3889 REG_RMW(ah,
3890 AR_GPIO_OE_OUT,
3891 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
3892 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3893}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003894EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
Sujithf1dc5602008-10-29 10:16:30 +05303895
Sujithcbe61d82009-02-09 13:27:12 +05303896u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303897{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303898#define MS_REG_READ(x, y) \
3899 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
3900
Sujith2660b812009-02-09 13:27:26 +05303901 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05303902 return 0xffffffff;
3903
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05303904 if (AR_SREV_9287_10_OR_LATER(ah))
3905 return MS_REG_READ(AR9287, gpio) != 0;
3906 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303907 return MS_REG_READ(AR9285, gpio) != 0;
3908 else if (AR_SREV_9280_10_OR_LATER(ah))
3909 return MS_REG_READ(AR928X, gpio) != 0;
3910 else
3911 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05303912}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003913EXPORT_SYMBOL(ath9k_hw_gpio_get);
Sujithf1dc5602008-10-29 10:16:30 +05303914
Sujithcbe61d82009-02-09 13:27:12 +05303915void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05303916 u32 ah_signal_type)
3917{
3918 u32 gpio_shift;
3919
3920 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
3921
3922 gpio_shift = 2 * gpio;
3923
3924 REG_RMW(ah,
3925 AR_GPIO_OE_OUT,
3926 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
3927 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3928}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003929EXPORT_SYMBOL(ath9k_hw_cfg_output);
Sujithf1dc5602008-10-29 10:16:30 +05303930
Sujithcbe61d82009-02-09 13:27:12 +05303931void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05303932{
3933 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
3934 AR_GPIO_BIT(gpio));
3935}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003936EXPORT_SYMBOL(ath9k_hw_set_gpio);
Sujithf1dc5602008-10-29 10:16:30 +05303937
Sujithcbe61d82009-02-09 13:27:12 +05303938u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303939{
3940 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
3941}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003942EXPORT_SYMBOL(ath9k_hw_getdefantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303943
Sujithcbe61d82009-02-09 13:27:12 +05303944void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05303945{
3946 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
3947}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003948EXPORT_SYMBOL(ath9k_hw_setantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303949
Sujithcbe61d82009-02-09 13:27:12 +05303950bool ath9k_hw_setantennaswitch(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303951 enum ath9k_ant_setting settings,
3952 struct ath9k_channel *chan,
3953 u8 *tx_chainmask,
3954 u8 *rx_chainmask,
3955 u8 *antenna_cfgd)
3956{
Sujithf1dc5602008-10-29 10:16:30 +05303957 static u8 tx_chainmask_cfg, rx_chainmask_cfg;
3958
3959 if (AR_SREV_9280(ah)) {
3960 if (!tx_chainmask_cfg) {
3961
3962 tx_chainmask_cfg = *tx_chainmask;
3963 rx_chainmask_cfg = *rx_chainmask;
3964 }
3965
3966 switch (settings) {
3967 case ATH9K_ANT_FIXED_A:
3968 *tx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3969 *rx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3970 *antenna_cfgd = true;
3971 break;
3972 case ATH9K_ANT_FIXED_B:
Sujith2660b812009-02-09 13:27:26 +05303973 if (ah->caps.tx_chainmask >
Sujithf1dc5602008-10-29 10:16:30 +05303974 ATH9K_ANTENNA1_CHAINMASK) {
3975 *tx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3976 }
3977 *rx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3978 *antenna_cfgd = true;
3979 break;
3980 case ATH9K_ANT_VARIABLE:
3981 *tx_chainmask = tx_chainmask_cfg;
3982 *rx_chainmask = rx_chainmask_cfg;
3983 *antenna_cfgd = true;
3984 break;
3985 default:
3986 break;
3987 }
3988 } else {
Sujith1cf68732009-08-13 09:34:32 +05303989 ah->config.diversity_control = settings;
Sujithf1dc5602008-10-29 10:16:30 +05303990 }
3991
3992 return true;
3993}
3994
3995/*********************/
3996/* General Operation */
3997/*********************/
3998
Sujithcbe61d82009-02-09 13:27:12 +05303999u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304000{
4001 u32 bits = REG_READ(ah, AR_RX_FILTER);
4002 u32 phybits = REG_READ(ah, AR_PHY_ERR);
4003
4004 if (phybits & AR_PHY_ERR_RADAR)
4005 bits |= ATH9K_RX_FILTER_PHYRADAR;
4006 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
4007 bits |= ATH9K_RX_FILTER_PHYERR;
4008
4009 return bits;
4010}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004011EXPORT_SYMBOL(ath9k_hw_getrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05304012
Sujithcbe61d82009-02-09 13:27:12 +05304013void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05304014{
4015 u32 phybits;
4016
Sujith7ea310b2009-09-03 12:08:43 +05304017 REG_WRITE(ah, AR_RX_FILTER, bits);
4018
Sujithf1dc5602008-10-29 10:16:30 +05304019 phybits = 0;
4020 if (bits & ATH9K_RX_FILTER_PHYRADAR)
4021 phybits |= AR_PHY_ERR_RADAR;
4022 if (bits & ATH9K_RX_FILTER_PHYERR)
4023 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
4024 REG_WRITE(ah, AR_PHY_ERR, phybits);
4025
4026 if (phybits)
4027 REG_WRITE(ah, AR_RXCFG,
4028 REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
4029 else
4030 REG_WRITE(ah, AR_RXCFG,
4031 REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
4032}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004033EXPORT_SYMBOL(ath9k_hw_setrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05304034
Sujithcbe61d82009-02-09 13:27:12 +05304035bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304036{
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05304037 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
4038 return false;
4039
4040 ath9k_hw_init_pll(ah, NULL);
4041 return true;
Sujithf1dc5602008-10-29 10:16:30 +05304042}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004043EXPORT_SYMBOL(ath9k_hw_phy_disable);
Sujithf1dc5602008-10-29 10:16:30 +05304044
Sujithcbe61d82009-02-09 13:27:12 +05304045bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304046{
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07004047 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05304048 return false;
4049
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05304050 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
4051 return false;
4052
4053 ath9k_hw_init_pll(ah, NULL);
4054 return true;
Sujithf1dc5602008-10-29 10:16:30 +05304055}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004056EXPORT_SYMBOL(ath9k_hw_disable);
Sujithf1dc5602008-10-29 10:16:30 +05304057
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07004058void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
Sujithf1dc5602008-10-29 10:16:30 +05304059{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07004060 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujith2660b812009-02-09 13:27:26 +05304061 struct ath9k_channel *chan = ah->curchan;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08004062 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05304063
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07004064 regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER);
Sujithf1dc5602008-10-29 10:16:30 +05304065
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07004066 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07004067 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07004068 channel->max_antenna_gain * 2,
4069 channel->max_power * 2,
4070 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07004071 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05304072}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004073EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
Sujithf1dc5602008-10-29 10:16:30 +05304074
Sujithcbe61d82009-02-09 13:27:12 +05304075void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac)
Sujithf1dc5602008-10-29 10:16:30 +05304076{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07004077 memcpy(ath9k_hw_common(ah)->macaddr, mac, ETH_ALEN);
Sujithf1dc5602008-10-29 10:16:30 +05304078}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004079EXPORT_SYMBOL(ath9k_hw_setmac);
Sujithf1dc5602008-10-29 10:16:30 +05304080
Sujithcbe61d82009-02-09 13:27:12 +05304081void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304082{
Sujith2660b812009-02-09 13:27:26 +05304083 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05304084}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004085EXPORT_SYMBOL(ath9k_hw_setopmode);
Sujithf1dc5602008-10-29 10:16:30 +05304086
Sujithcbe61d82009-02-09 13:27:12 +05304087void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05304088{
4089 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
4090 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
4091}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004092EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
Sujithf1dc5602008-10-29 10:16:30 +05304093
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07004094void ath9k_hw_write_associd(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304095{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07004096 struct ath_common *common = ath9k_hw_common(ah);
4097
4098 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
4099 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
4100 ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05304101}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004102EXPORT_SYMBOL(ath9k_hw_write_associd);
Sujithf1dc5602008-10-29 10:16:30 +05304103
Sujithcbe61d82009-02-09 13:27:12 +05304104u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304105{
4106 u64 tsf;
4107
4108 tsf = REG_READ(ah, AR_TSF_U32);
4109 tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
4110
4111 return tsf;
4112}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004113EXPORT_SYMBOL(ath9k_hw_gettsf64);
Sujithf1dc5602008-10-29 10:16:30 +05304114
Sujithcbe61d82009-02-09 13:27:12 +05304115void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004116{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004117 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01004118 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004119}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004120EXPORT_SYMBOL(ath9k_hw_settsf64);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004121
Sujithcbe61d82009-02-09 13:27:12 +05304122void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304123{
Gabor Juhosf9b604f2009-06-21 00:02:15 +02004124 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
4125 AH_TSF_WRITE_TIMEOUT))
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004126 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
4127 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
Gabor Juhosf9b604f2009-06-21 00:02:15 +02004128
Sujithf1dc5602008-10-29 10:16:30 +05304129 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004130}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004131EXPORT_SYMBOL(ath9k_hw_reset_tsf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004132
Sujith54e4cec2009-08-07 09:45:09 +05304133void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004134{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004135 if (setting)
Sujith2660b812009-02-09 13:27:26 +05304136 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004137 else
Sujith2660b812009-02-09 13:27:26 +05304138 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004139}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004140EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004141
Sujithcbe61d82009-02-09 13:27:12 +05304142bool ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004143{
Sujithf1dc5602008-10-29 10:16:30 +05304144 if (us < ATH9K_SLOT_TIME_9 || us > ath9k_hw_mac_to_usec(ah, 0xffff)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004145 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
4146 "bad slot time %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05304147 ah->slottime = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05304148 return false;
4149 } else {
4150 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05304151 ah->slottime = us;
Sujithf1dc5602008-10-29 10:16:30 +05304152 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004153 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004154}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004155EXPORT_SYMBOL(ath9k_hw_setslottime);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004156
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07004157void ath9k_hw_set11nmac2040(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004158{
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07004159 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithf1dc5602008-10-29 10:16:30 +05304160 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004161
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07004162 if (conf_is_ht40(conf) && !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05304163 macmode = AR_2040_JOINED_RX_CLEAR;
4164 else
4165 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004166
Sujithf1dc5602008-10-29 10:16:30 +05304167 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004168}
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304169
4170/* HW Generic timers configuration */
4171
4172static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
4173{
4174 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4175 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4176 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4177 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4178 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4179 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4180 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4181 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4182 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
4183 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
4184 AR_NDP2_TIMER_MODE, 0x0002},
4185 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
4186 AR_NDP2_TIMER_MODE, 0x0004},
4187 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
4188 AR_NDP2_TIMER_MODE, 0x0008},
4189 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
4190 AR_NDP2_TIMER_MODE, 0x0010},
4191 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
4192 AR_NDP2_TIMER_MODE, 0x0020},
4193 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
4194 AR_NDP2_TIMER_MODE, 0x0040},
4195 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
4196 AR_NDP2_TIMER_MODE, 0x0080}
4197};
4198
4199/* HW generic timer primitives */
4200
4201/* compute and clear index of rightmost 1 */
4202static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
4203{
4204 u32 b;
4205
4206 b = *mask;
4207 b &= (0-b);
4208 *mask &= ~b;
4209 b *= debruijn32;
4210 b >>= 27;
4211
4212 return timer_table->gen_timer_index[b];
4213}
4214
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05304215u32 ath9k_hw_gettsf32(struct ath_hw *ah)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304216{
4217 return REG_READ(ah, AR_TSF_L32);
4218}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004219EXPORT_SYMBOL(ath9k_hw_gettsf32);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304220
4221struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
4222 void (*trigger)(void *),
4223 void (*overflow)(void *),
4224 void *arg,
4225 u8 timer_index)
4226{
4227 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4228 struct ath_gen_timer *timer;
4229
4230 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
4231
4232 if (timer == NULL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004233 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
4234 "Failed to allocate memory"
4235 "for hw timer[%d]\n", timer_index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304236 return NULL;
4237 }
4238
4239 /* allocate a hardware generic timer slot */
4240 timer_table->timers[timer_index] = timer;
4241 timer->index = timer_index;
4242 timer->trigger = trigger;
4243 timer->overflow = overflow;
4244 timer->arg = arg;
4245
4246 return timer;
4247}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004248EXPORT_SYMBOL(ath_gen_timer_alloc);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304249
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07004250void ath9k_hw_gen_timer_start(struct ath_hw *ah,
4251 struct ath_gen_timer *timer,
4252 u32 timer_next,
4253 u32 timer_period)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304254{
4255 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4256 u32 tsf;
4257
4258 BUG_ON(!timer_period);
4259
4260 set_bit(timer->index, &timer_table->timer_mask.timer_bits);
4261
4262 tsf = ath9k_hw_gettsf32(ah);
4263
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004264 ath_print(ath9k_hw_common(ah), ATH_DBG_HWTIMER,
4265 "curent tsf %x period %x"
4266 "timer_next %x\n", tsf, timer_period, timer_next);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304267
4268 /*
4269 * Pull timer_next forward if the current TSF already passed it
4270 * because of software latency
4271 */
4272 if (timer_next < tsf)
4273 timer_next = tsf + timer_period;
4274
4275 /*
4276 * Program generic timer registers
4277 */
4278 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
4279 timer_next);
4280 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
4281 timer_period);
4282 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
4283 gen_tmr_configuration[timer->index].mode_mask);
4284
4285 /* Enable both trigger and thresh interrupt masks */
4286 REG_SET_BIT(ah, AR_IMR_S5,
4287 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
4288 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304289}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004290EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304291
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07004292void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304293{
4294 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4295
4296 if ((timer->index < AR_FIRST_NDP_TIMER) ||
4297 (timer->index >= ATH_MAX_GEN_TIMER)) {
4298 return;
4299 }
4300
4301 /* Clear generic timer enable bits. */
4302 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
4303 gen_tmr_configuration[timer->index].mode_mask);
4304
4305 /* Disable both trigger and thresh interrupt masks */
4306 REG_CLR_BIT(ah, AR_IMR_S5,
4307 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
4308 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
4309
4310 clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304311}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004312EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304313
4314void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
4315{
4316 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4317
4318 /* free the hardware generic timer slot */
4319 timer_table->timers[timer->index] = NULL;
4320 kfree(timer);
4321}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004322EXPORT_SYMBOL(ath_gen_timer_free);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304323
4324/*
4325 * Generic Timer Interrupts handling
4326 */
4327void ath_gen_timer_isr(struct ath_hw *ah)
4328{
4329 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4330 struct ath_gen_timer *timer;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004331 struct ath_common *common = ath9k_hw_common(ah);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304332 u32 trigger_mask, thresh_mask, index;
4333
4334 /* get hardware generic timer interrupt status */
4335 trigger_mask = ah->intr_gen_timer_trigger;
4336 thresh_mask = ah->intr_gen_timer_thresh;
4337 trigger_mask &= timer_table->timer_mask.val;
4338 thresh_mask &= timer_table->timer_mask.val;
4339
4340 trigger_mask &= ~thresh_mask;
4341
4342 while (thresh_mask) {
4343 index = rightmost_index(timer_table, &thresh_mask);
4344 timer = timer_table->timers[index];
4345 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004346 ath_print(common, ATH_DBG_HWTIMER,
4347 "TSF overflow for Gen timer %d\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304348 timer->overflow(timer->arg);
4349 }
4350
4351 while (trigger_mask) {
4352 index = rightmost_index(timer_table, &trigger_mask);
4353 timer = timer_table->timers[index];
4354 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004355 ath_print(common, ATH_DBG_HWTIMER,
4356 "Gen timer[%d] trigger\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304357 timer->trigger(timer->arg);
4358 }
4359}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004360EXPORT_SYMBOL(ath_gen_timer_isr);
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04004361
4362static struct {
4363 u32 version;
4364 const char * name;
4365} ath_mac_bb_names[] = {
4366 /* Devices with external radios */
4367 { AR_SREV_VERSION_5416_PCI, "5416" },
4368 { AR_SREV_VERSION_5416_PCIE, "5418" },
4369 { AR_SREV_VERSION_9100, "9100" },
4370 { AR_SREV_VERSION_9160, "9160" },
4371 /* Single-chip solutions */
4372 { AR_SREV_VERSION_9280, "9280" },
4373 { AR_SREV_VERSION_9285, "9285" },
Luis R. Rodriguez11158472009-10-27 12:59:35 -04004374 { AR_SREV_VERSION_9287, "9287" },
4375 { AR_SREV_VERSION_9271, "9271" },
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04004376};
4377
4378/* For devices with external radios */
4379static struct {
4380 u16 version;
4381 const char * name;
4382} ath_rf_names[] = {
4383 { 0, "5133" },
4384 { AR_RAD5133_SREV_MAJOR, "5133" },
4385 { AR_RAD5122_SREV_MAJOR, "5122" },
4386 { AR_RAD2133_SREV_MAJOR, "2133" },
4387 { AR_RAD2122_SREV_MAJOR, "2122" }
4388};
4389
4390/*
4391 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
4392 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04004393static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04004394{
4395 int i;
4396
4397 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
4398 if (ath_mac_bb_names[i].version == mac_bb_version) {
4399 return ath_mac_bb_names[i].name;
4400 }
4401 }
4402
4403 return "????";
4404}
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04004405
4406/*
4407 * Return the RF name. "????" is returned if the RF is unknown.
4408 * Used for devices with external radios.
4409 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04004410static const char *ath9k_hw_rf_name(u16 rf_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04004411{
4412 int i;
4413
4414 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
4415 if (ath_rf_names[i].version == rf_version) {
4416 return ath_rf_names[i].name;
4417 }
4418 }
4419
4420 return "????";
4421}
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04004422
4423void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
4424{
4425 int used;
4426
4427 /* chipsets >= AR9280 are single-chip */
4428 if (AR_SREV_9280_10_OR_LATER(ah)) {
4429 used = snprintf(hw_name, len,
4430 "Atheros AR%s Rev:%x",
4431 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
4432 ah->hw_version.macRev);
4433 }
4434 else {
4435 used = snprintf(hw_name, len,
4436 "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
4437 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
4438 ah->hw_version.macRev,
4439 ath9k_hw_rf_name((ah->hw_version.analog5GhzRev &
4440 AR_RADIO_SREV_MAJOR)),
4441 ah->hw_version.phyRev);
4442 }
4443
4444 hw_name[used] = '\0';
4445}
4446EXPORT_SYMBOL(ath9k_hw_name);