blob: 5d7a5b177a39eb2fb261ea66cae17188cce3767b [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
Sujithcee075a2009-03-13 09:07:23 +05302 * Copyright (c) 2008-2009 Atheros Communications Inc.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include <linux/io.h>
18#include <asm/unaligned.h>
19
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -070020#include "hw.h"
Luis R. Rodriguezcfe8cba2009-09-13 23:39:31 -070021#include "rc.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070022#include "initvals.h"
23
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080024#define ATH9K_CLOCK_RATE_CCK 22
25#define ATH9K_CLOCK_RATE_5GHZ_OFDM 40
26#define ATH9K_CLOCK_RATE_2GHZ_OFDM 44
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070027
Sujithcbe61d82009-02-09 13:27:12 +053028static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type);
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -070029static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan);
Sujithcbe61d82009-02-09 13:27:12 +053030static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +053031 struct ar5416_eeprom_def *pEepData,
Sujithf1dc5602008-10-29 10:16:30 +053032 u32 reg, u32 value);
Sujithcbe61d82009-02-09 13:27:12 +053033static void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan);
34static void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070035
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040036MODULE_AUTHOR("Atheros Communications");
37MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
38MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
39MODULE_LICENSE("Dual BSD/GPL");
40
41static int __init ath9k_init(void)
42{
43 return 0;
44}
45module_init(ath9k_init);
46
47static void __exit ath9k_exit(void)
48{
49 return;
50}
51module_exit(ath9k_exit);
52
Sujithf1dc5602008-10-29 10:16:30 +053053/********************/
54/* Helper Functions */
55/********************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070056
Sujithcbe61d82009-02-09 13:27:12 +053057static u32 ath9k_hw_mac_usec(struct ath_hw *ah, u32 clks)
Sujithf1dc5602008-10-29 10:16:30 +053058{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070059 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053060
Sujith2660b812009-02-09 13:27:26 +053061 if (!ah->curchan) /* should really check for CCK instead */
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080062 return clks / ATH9K_CLOCK_RATE_CCK;
63 if (conf->channel->band == IEEE80211_BAND_2GHZ)
64 return clks / ATH9K_CLOCK_RATE_2GHZ_OFDM;
Sujithcbe61d82009-02-09 13:27:12 +053065
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080066 return clks / ATH9K_CLOCK_RATE_5GHZ_OFDM;
Sujithf1dc5602008-10-29 10:16:30 +053067}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070068
Sujithcbe61d82009-02-09 13:27:12 +053069static u32 ath9k_hw_mac_to_usec(struct ath_hw *ah, u32 clks)
Sujithf1dc5602008-10-29 10:16:30 +053070{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070071 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053072
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080073 if (conf_is_ht40(conf))
Sujithf1dc5602008-10-29 10:16:30 +053074 return ath9k_hw_mac_usec(ah, clks) / 2;
75 else
76 return ath9k_hw_mac_usec(ah, clks);
77}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070078
Sujithcbe61d82009-02-09 13:27:12 +053079static u32 ath9k_hw_mac_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053080{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070081 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053082
Sujith2660b812009-02-09 13:27:26 +053083 if (!ah->curchan) /* should really check for CCK instead */
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080084 return usecs *ATH9K_CLOCK_RATE_CCK;
85 if (conf->channel->band == IEEE80211_BAND_2GHZ)
86 return usecs *ATH9K_CLOCK_RATE_2GHZ_OFDM;
87 return usecs *ATH9K_CLOCK_RATE_5GHZ_OFDM;
Sujithf1dc5602008-10-29 10:16:30 +053088}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070089
Sujithcbe61d82009-02-09 13:27:12 +053090static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053091{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070092 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053093
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080094 if (conf_is_ht40(conf))
Sujithf1dc5602008-10-29 10:16:30 +053095 return ath9k_hw_mac_clks(ah, usecs) * 2;
96 else
97 return ath9k_hw_mac_clks(ah, usecs);
98}
99
Sujith0caa7b12009-02-16 13:23:20 +0530100bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700101{
102 int i;
103
Sujith0caa7b12009-02-16 13:23:20 +0530104 BUG_ON(timeout < AH_TIME_QUANTUM);
105
106 for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700107 if ((REG_READ(ah, reg) & mask) == val)
108 return true;
109
110 udelay(AH_TIME_QUANTUM);
111 }
Sujith04bd4632008-11-28 22:18:05 +0530112
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700113 ath_print(ath9k_hw_common(ah), ATH_DBG_ANY,
114 "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
115 timeout, reg, REG_READ(ah, reg), mask, val);
Sujithf1dc5602008-10-29 10:16:30 +0530116
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700117 return false;
118}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400119EXPORT_SYMBOL(ath9k_hw_wait);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700120
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700121u32 ath9k_hw_reverse_bits(u32 val, u32 n)
122{
123 u32 retval;
124 int i;
125
126 for (i = 0, retval = 0; i < n; i++) {
127 retval = (retval << 1) | (val & 1);
128 val >>= 1;
129 }
130 return retval;
131}
132
Sujithcbe61d82009-02-09 13:27:12 +0530133bool ath9k_get_channel_edges(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530134 u16 flags, u16 *low,
135 u16 *high)
136{
Sujith2660b812009-02-09 13:27:26 +0530137 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530138
139 if (flags & CHANNEL_5GHZ) {
140 *low = pCap->low_5ghz_chan;
141 *high = pCap->high_5ghz_chan;
142 return true;
143 }
144 if ((flags & CHANNEL_2GHZ)) {
145 *low = pCap->low_2ghz_chan;
146 *high = pCap->high_2ghz_chan;
147 return true;
148 }
149 return false;
150}
151
Sujithcbe61d82009-02-09 13:27:12 +0530152u16 ath9k_hw_computetxtime(struct ath_hw *ah,
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400153 const struct ath_rate_table *rates,
Sujithf1dc5602008-10-29 10:16:30 +0530154 u32 frameLen, u16 rateix,
155 bool shortPreamble)
156{
157 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
158 u32 kbps;
159
Sujithe63835b2008-11-18 09:07:53 +0530160 kbps = rates->info[rateix].ratekbps;
Sujithf1dc5602008-10-29 10:16:30 +0530161
162 if (kbps == 0)
163 return 0;
164
165 switch (rates->info[rateix].phy) {
Sujith46d14a52008-11-18 09:08:13 +0530166 case WLAN_RC_PHY_CCK:
Sujithf1dc5602008-10-29 10:16:30 +0530167 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
Sujithe63835b2008-11-18 09:07:53 +0530168 if (shortPreamble && rates->info[rateix].short_preamble)
Sujithf1dc5602008-10-29 10:16:30 +0530169 phyTime >>= 1;
170 numBits = frameLen << 3;
171 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
172 break;
Sujith46d14a52008-11-18 09:08:13 +0530173 case WLAN_RC_PHY_OFDM:
Sujith2660b812009-02-09 13:27:26 +0530174 if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530175 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
176 numBits = OFDM_PLCP_BITS + (frameLen << 3);
177 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
178 txTime = OFDM_SIFS_TIME_QUARTER
179 + OFDM_PREAMBLE_TIME_QUARTER
180 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
Sujith2660b812009-02-09 13:27:26 +0530181 } else if (ah->curchan &&
182 IS_CHAN_HALF_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530183 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
184 numBits = OFDM_PLCP_BITS + (frameLen << 3);
185 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
186 txTime = OFDM_SIFS_TIME_HALF +
187 OFDM_PREAMBLE_TIME_HALF
188 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
189 } else {
190 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
191 numBits = OFDM_PLCP_BITS + (frameLen << 3);
192 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
193 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
194 + (numSymbols * OFDM_SYMBOL_TIME);
195 }
196 break;
197 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700198 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
199 "Unknown phy %u (rate ix %u)\n",
200 rates->info[rateix].phy, rateix);
Sujithf1dc5602008-10-29 10:16:30 +0530201 txTime = 0;
202 break;
203 }
204
205 return txTime;
206}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400207EXPORT_SYMBOL(ath9k_hw_computetxtime);
Sujithf1dc5602008-10-29 10:16:30 +0530208
Sujithcbe61d82009-02-09 13:27:12 +0530209void ath9k_hw_get_channel_centers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530210 struct ath9k_channel *chan,
211 struct chan_centers *centers)
212{
213 int8_t extoff;
Sujithf1dc5602008-10-29 10:16:30 +0530214
215 if (!IS_CHAN_HT40(chan)) {
216 centers->ctl_center = centers->ext_center =
217 centers->synth_center = chan->channel;
218 return;
219 }
220
221 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
222 (chan->chanmode == CHANNEL_G_HT40PLUS)) {
223 centers->synth_center =
224 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
225 extoff = 1;
226 } else {
227 centers->synth_center =
228 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
229 extoff = -1;
230 }
231
232 centers->ctl_center =
233 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700234 /* 25 MHz spacing is supported by hw but not on upper layers */
Sujithf1dc5602008-10-29 10:16:30 +0530235 centers->ext_center =
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700236 centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT);
Sujithf1dc5602008-10-29 10:16:30 +0530237}
238
239/******************/
240/* Chip Revisions */
241/******************/
242
Sujithcbe61d82009-02-09 13:27:12 +0530243static void ath9k_hw_read_revisions(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530244{
245 u32 val;
246
247 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
248
249 if (val == 0xFF) {
250 val = REG_READ(ah, AR_SREV);
Sujithd535a422009-02-09 13:27:06 +0530251 ah->hw_version.macVersion =
252 (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
253 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
Sujith2660b812009-02-09 13:27:26 +0530254 ah->is_pciexpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
Sujithf1dc5602008-10-29 10:16:30 +0530255 } else {
256 if (!AR_SREV_9100(ah))
Sujithd535a422009-02-09 13:27:06 +0530257 ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
Sujithf1dc5602008-10-29 10:16:30 +0530258
Sujithd535a422009-02-09 13:27:06 +0530259 ah->hw_version.macRev = val & AR_SREV_REVISION;
Sujithf1dc5602008-10-29 10:16:30 +0530260
Sujithd535a422009-02-09 13:27:06 +0530261 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
Sujith2660b812009-02-09 13:27:26 +0530262 ah->is_pciexpress = true;
Sujithf1dc5602008-10-29 10:16:30 +0530263 }
264}
265
Sujithcbe61d82009-02-09 13:27:12 +0530266static int ath9k_hw_get_radiorev(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530267{
268 u32 val;
269 int i;
270
271 REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
272
273 for (i = 0; i < 8; i++)
274 REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
275 val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
276 val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
277
278 return ath9k_hw_reverse_bits(val, 8);
279}
280
281/************************************/
282/* HW Attach, Detach, Init Routines */
283/************************************/
284
Sujithcbe61d82009-02-09 13:27:12 +0530285static void ath9k_hw_disablepcie(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530286{
Sujithfeed0292009-01-29 11:37:35 +0530287 if (AR_SREV_9100(ah))
Sujithf1dc5602008-10-29 10:16:30 +0530288 return;
289
290 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
291 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
292 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
293 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
294 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
295 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
296 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
297 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
298 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
299
300 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
301}
302
Sujithcbe61d82009-02-09 13:27:12 +0530303static bool ath9k_hw_chip_test(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530304{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700305 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530306 u32 regAddr[2] = { AR_STA_ID0, AR_PHY_BASE + (8 << 2) };
307 u32 regHold[2];
308 u32 patternData[4] = { 0x55555555,
309 0xaaaaaaaa,
310 0x66666666,
311 0x99999999 };
312 int i, j;
313
314 for (i = 0; i < 2; i++) {
315 u32 addr = regAddr[i];
316 u32 wrData, rdData;
317
318 regHold[i] = REG_READ(ah, addr);
319 for (j = 0; j < 0x100; j++) {
320 wrData = (j << 16) | j;
321 REG_WRITE(ah, addr, wrData);
322 rdData = REG_READ(ah, addr);
323 if (rdData != wrData) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700324 ath_print(common, ATH_DBG_FATAL,
325 "address test failed "
326 "addr: 0x%08x - wr:0x%08x != "
327 "rd:0x%08x\n",
328 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530329 return false;
330 }
331 }
332 for (j = 0; j < 4; j++) {
333 wrData = patternData[j];
334 REG_WRITE(ah, addr, wrData);
335 rdData = REG_READ(ah, addr);
336 if (wrData != rdData) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700337 ath_print(common, ATH_DBG_FATAL,
338 "address test failed "
339 "addr: 0x%08x - wr:0x%08x != "
340 "rd:0x%08x\n",
341 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530342 return false;
343 }
344 }
345 REG_WRITE(ah, regAddr[i], regHold[i]);
346 }
347 udelay(100);
Sujithcbe61d82009-02-09 13:27:12 +0530348
Sujithf1dc5602008-10-29 10:16:30 +0530349 return true;
350}
351
352static const char *ath9k_hw_devname(u16 devid)
353{
354 switch (devid) {
355 case AR5416_DEVID_PCI:
Sujithf1dc5602008-10-29 10:16:30 +0530356 return "Atheros 5416";
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +0100357 case AR5416_DEVID_PCIE:
358 return "Atheros 5418";
Sujithf1dc5602008-10-29 10:16:30 +0530359 case AR9160_DEVID_PCI:
360 return "Atheros 9160";
Gabor Juhos0c1aa492009-01-14 20:17:12 +0100361 case AR5416_AR9100_DEVID:
362 return "Atheros 9100";
Sujithf1dc5602008-10-29 10:16:30 +0530363 case AR9280_DEVID_PCI:
364 case AR9280_DEVID_PCIE:
365 return "Atheros 9280";
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530366 case AR9285_DEVID_PCIE:
367 return "Atheros 9285";
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530368 case AR5416_DEVID_AR9287_PCI:
369 case AR5416_DEVID_AR9287_PCIE:
370 return "Atheros 9287";
Sujithf1dc5602008-10-29 10:16:30 +0530371 }
372
373 return NULL;
374}
375
Luis R. Rodriguezb8b0f372009-08-03 12:24:43 -0700376static void ath9k_hw_init_config(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700377{
378 int i;
379
Sujith2660b812009-02-09 13:27:26 +0530380 ah->config.dma_beacon_response_time = 2;
381 ah->config.sw_beacon_response_time = 10;
382 ah->config.additional_swba_backoff = 0;
383 ah->config.ack_6mb = 0x0;
384 ah->config.cwm_ignore_extcca = 0;
385 ah->config.pcie_powersave_enable = 0;
Sujith2660b812009-02-09 13:27:26 +0530386 ah->config.pcie_clock_req = 0;
Sujith2660b812009-02-09 13:27:26 +0530387 ah->config.pcie_waen = 0;
388 ah->config.analog_shiftreg = 1;
389 ah->config.ht_enable = 1;
390 ah->config.ofdm_trig_low = 200;
391 ah->config.ofdm_trig_high = 500;
392 ah->config.cck_trig_high = 200;
393 ah->config.cck_trig_low = 100;
394 ah->config.enable_ani = 1;
Sujith1cf68732009-08-13 09:34:32 +0530395 ah->config.diversity_control = ATH9K_ANT_VARIABLE;
Sujith2660b812009-02-09 13:27:26 +0530396 ah->config.antenna_switch_swap = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700397
398 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujith2660b812009-02-09 13:27:26 +0530399 ah->config.spurchans[i][0] = AR_NO_SPUR;
400 ah->config.spurchans[i][1] = AR_NO_SPUR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700401 }
402
Sujith0ef1f162009-03-30 15:28:35 +0530403 ah->config.intr_mitigation = true;
Luis R. Rodriguez61584252009-03-12 18:18:49 -0400404
405 /*
406 * We need this for PCI devices only (Cardbus, PCI, miniPCI)
407 * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
408 * This means we use it for all AR5416 devices, and the few
409 * minor PCI AR9280 devices out there.
410 *
411 * Serialization is required because these devices do not handle
412 * well the case of two concurrent reads/writes due to the latency
413 * involved. During one read/write another read/write can be issued
414 * on another CPU while the previous read/write may still be working
415 * on our hardware, if we hit this case the hardware poops in a loop.
416 * We prevent this by serializing reads and writes.
417 *
418 * This issue is not present on PCI-Express devices or pre-AR5416
419 * devices (legacy, 802.11abg).
420 */
421 if (num_possible_cpus() > 1)
David S. Miller2d6a5e92009-03-17 15:01:30 -0700422 ah->config.serialize_regmode = SER_REG_MODE_AUTO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700423}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400424EXPORT_SYMBOL(ath9k_hw_init);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700425
Luis R. Rodriguez50aca252009-08-03 12:24:42 -0700426static void ath9k_hw_init_defaults(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700427{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700428 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
429
430 regulatory->country_code = CTRY_DEFAULT;
431 regulatory->power_limit = MAX_RATE_POWER;
432 regulatory->tp_scale = ATH9K_TP_SCALE_MAX;
433
Sujithd535a422009-02-09 13:27:06 +0530434 ah->hw_version.magic = AR5416_MAGIC;
Sujithd535a422009-02-09 13:27:06 +0530435 ah->hw_version.subvendorid = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700436
437 ah->ah_flags = 0;
Luis R. Rodriguez8df5d1b2009-08-03 12:24:37 -0700438 if (ah->hw_version.devid == AR5416_AR9100_DEVID)
Sujithd535a422009-02-09 13:27:06 +0530439 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700440 if (!AR_SREV_9100(ah))
441 ah->ah_flags = AH_USE_EEPROM;
442
Sujith2660b812009-02-09 13:27:26 +0530443 ah->atim_window = 0;
Sujith2660b812009-02-09 13:27:26 +0530444 ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
445 ah->beacon_interval = 100;
446 ah->enable_32kHz_clock = DONT_USE_32KHZ;
447 ah->slottime = (u32) -1;
448 ah->acktimeout = (u32) -1;
449 ah->ctstimeout = (u32) -1;
450 ah->globaltxtimeout = (u32) -1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700451
Sujith2660b812009-02-09 13:27:26 +0530452 ah->gbeacon_rate = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700453
Gabor Juhoscbdec972009-07-24 17:27:22 +0200454 ah->power_mode = ATH9K_PM_UNDEFINED;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700455}
456
Sujithcbe61d82009-02-09 13:27:12 +0530457static int ath9k_hw_rfattach(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700458{
459 bool rfStatus = false;
460 int ecode = 0;
461
462 rfStatus = ath9k_hw_init_rf(ah, &ecode);
463 if (!rfStatus) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700464 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
465 "RF setup failed, status: %u\n", ecode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700466 return ecode;
467 }
468
469 return 0;
470}
471
Sujithcbe61d82009-02-09 13:27:12 +0530472static int ath9k_hw_rf_claim(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700473{
474 u32 val;
475
476 REG_WRITE(ah, AR_PHY(0), 0x00000007);
477
478 val = ath9k_hw_get_radiorev(ah);
479 switch (val & AR_RADIO_SREV_MAJOR) {
480 case 0:
481 val = AR_RAD5133_SREV_MAJOR;
482 break;
483 case AR_RAD5133_SREV_MAJOR:
484 case AR_RAD5122_SREV_MAJOR:
485 case AR_RAD2133_SREV_MAJOR:
486 case AR_RAD2122_SREV_MAJOR:
487 break;
488 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700489 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
490 "Radio Chip Rev 0x%02X not supported\n",
491 val & AR_RADIO_SREV_MAJOR);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700492 return -EOPNOTSUPP;
493 }
494
Sujithd535a422009-02-09 13:27:06 +0530495 ah->hw_version.analog5GhzRev = val;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700496
497 return 0;
498}
499
Sujithcbe61d82009-02-09 13:27:12 +0530500static int ath9k_hw_init_macaddr(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700501{
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700502 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530503 u32 sum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700504 int i;
Sujithf1dc5602008-10-29 10:16:30 +0530505 u16 eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700506
Sujithf1dc5602008-10-29 10:16:30 +0530507 sum = 0;
508 for (i = 0; i < 3; i++) {
Sujithf74df6f2009-02-09 13:27:24 +0530509 eeval = ah->eep_ops->get_eeprom(ah, AR_EEPROM_MAC(i));
Sujithf1dc5602008-10-29 10:16:30 +0530510 sum += eeval;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700511 common->macaddr[2 * i] = eeval >> 8;
512 common->macaddr[2 * i + 1] = eeval & 0xff;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700513 }
Sujithd8baa932009-03-30 15:28:25 +0530514 if (sum == 0 || sum == 0xffff * 3)
Sujithf1dc5602008-10-29 10:16:30 +0530515 return -EADDRNOTAVAIL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700516
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700517 return 0;
518}
519
Sujithcbe61d82009-02-09 13:27:12 +0530520static void ath9k_hw_init_rxgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530521{
522 u32 rxgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530523
Sujithf74df6f2009-02-09 13:27:24 +0530524 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_17) {
525 rxgain_type = ah->eep_ops->get_eeprom(ah, EEP_RXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530526
527 if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530528 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530529 ar9280Modes_backoff_13db_rxgain_9280_2,
530 ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2), 6);
531 else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530532 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530533 ar9280Modes_backoff_23db_rxgain_9280_2,
534 ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 6);
535 else
Sujith2660b812009-02-09 13:27:26 +0530536 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530537 ar9280Modes_original_rxgain_9280_2,
538 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530539 } else {
Sujith2660b812009-02-09 13:27:26 +0530540 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530541 ar9280Modes_original_rxgain_9280_2,
542 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530543 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530544}
545
Sujithcbe61d82009-02-09 13:27:12 +0530546static void ath9k_hw_init_txgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530547{
548 u32 txgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530549
Sujithf74df6f2009-02-09 13:27:24 +0530550 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_19) {
551 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530552
553 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
Sujith2660b812009-02-09 13:27:26 +0530554 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530555 ar9280Modes_high_power_tx_gain_9280_2,
556 ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 6);
557 else
Sujith2660b812009-02-09 13:27:26 +0530558 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530559 ar9280Modes_original_tx_gain_9280_2,
560 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530561 } else {
Sujith2660b812009-02-09 13:27:26 +0530562 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530563 ar9280Modes_original_tx_gain_9280_2,
564 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530565 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530566}
567
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700568static int ath9k_hw_post_init(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700569{
570 int ecode;
571
Sujithd8baa932009-03-30 15:28:25 +0530572 if (!ath9k_hw_chip_test(ah))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700573 return -ENODEV;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700574
575 ecode = ath9k_hw_rf_claim(ah);
576 if (ecode != 0)
577 return ecode;
578
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700579 ecode = ath9k_hw_eeprom_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700580 if (ecode != 0)
581 return ecode;
Sujith7d01b222009-03-13 08:55:55 +0530582
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700583 ath_print(ath9k_hw_common(ah), ATH_DBG_CONFIG,
584 "Eeprom VER: %d, REV: %d\n",
585 ah->eep_ops->get_eeprom_ver(ah),
586 ah->eep_ops->get_eeprom_rev(ah));
Sujith7d01b222009-03-13 08:55:55 +0530587
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700588 ecode = ath9k_hw_rfattach(ah);
589 if (ecode != 0)
590 return ecode;
591
592 if (!AR_SREV_9100(ah)) {
593 ath9k_hw_ani_setup(ah);
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700594 ath9k_hw_ani_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700595 }
Sujithf1dc5602008-10-29 10:16:30 +0530596
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700597 return 0;
598}
599
Luis R. Rodriguezee2bb462009-08-03 12:24:39 -0700600static bool ath9k_hw_devid_supported(u16 devid)
601{
602 switch (devid) {
603 case AR5416_DEVID_PCI:
604 case AR5416_DEVID_PCIE:
605 case AR5416_AR9100_DEVID:
606 case AR9160_DEVID_PCI:
607 case AR9280_DEVID_PCI:
608 case AR9280_DEVID_PCIE:
609 case AR9285_DEVID_PCIE:
610 case AR5416_DEVID_AR9287_PCI:
611 case AR5416_DEVID_AR9287_PCIE:
Luis R. Rodriguez7976b422009-09-23 23:07:02 -0400612 case AR9271_USB:
Luis R. Rodriguezee2bb462009-08-03 12:24:39 -0700613 return true;
614 default:
615 break;
616 }
617 return false;
618}
619
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700620static bool ath9k_hw_macversion_supported(u32 macversion)
621{
622 switch (macversion) {
623 case AR_SREV_VERSION_5416_PCI:
624 case AR_SREV_VERSION_5416_PCIE:
625 case AR_SREV_VERSION_9160:
626 case AR_SREV_VERSION_9100:
627 case AR_SREV_VERSION_9280:
628 case AR_SREV_VERSION_9285:
629 case AR_SREV_VERSION_9287:
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400630 case AR_SREV_VERSION_9271:
Luis R. Rodriguez7976b422009-09-23 23:07:02 -0400631 return true;
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700632 default:
633 break;
634 }
635 return false;
636}
637
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700638static void ath9k_hw_init_cal_settings(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700639{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700640 if (AR_SREV_9160_10_OR_LATER(ah)) {
641 if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530642 ah->iq_caldata.calData = &iq_cal_single_sample;
643 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700644 &adc_gain_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530645 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700646 &adc_dc_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530647 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700648 &adc_init_dc_cal;
649 } else {
Sujith2660b812009-02-09 13:27:26 +0530650 ah->iq_caldata.calData = &iq_cal_multi_sample;
651 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700652 &adc_gain_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530653 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700654 &adc_dc_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530655 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700656 &adc_init_dc_cal;
657 }
Sujith2660b812009-02-09 13:27:26 +0530658 ah->supp_cals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700659 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700660}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700661
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700662static void ath9k_hw_init_mode_regs(struct ath_hw *ah)
663{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400664 if (AR_SREV_9271(ah)) {
665 INIT_INI_ARRAY(&ah->iniModes, ar9271Modes_9271_1_0,
666 ARRAY_SIZE(ar9271Modes_9271_1_0), 6);
667 INIT_INI_ARRAY(&ah->iniCommon, ar9271Common_9271_1_0,
668 ARRAY_SIZE(ar9271Common_9271_1_0), 2);
669 return;
670 }
671
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530672 if (AR_SREV_9287_11_OR_LATER(ah)) {
673 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_1,
674 ARRAY_SIZE(ar9287Modes_9287_1_1), 6);
675 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_1,
676 ARRAY_SIZE(ar9287Common_9287_1_1), 2);
677 if (ah->config.pcie_clock_req)
678 INIT_INI_ARRAY(&ah->iniPcieSerdes,
679 ar9287PciePhy_clkreq_off_L1_9287_1_1,
680 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_1), 2);
681 else
682 INIT_INI_ARRAY(&ah->iniPcieSerdes,
683 ar9287PciePhy_clkreq_always_on_L1_9287_1_1,
684 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_1),
685 2);
686 } else if (AR_SREV_9287_10_OR_LATER(ah)) {
687 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_0,
688 ARRAY_SIZE(ar9287Modes_9287_1_0), 6);
689 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_0,
690 ARRAY_SIZE(ar9287Common_9287_1_0), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700691
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530692 if (ah->config.pcie_clock_req)
693 INIT_INI_ARRAY(&ah->iniPcieSerdes,
694 ar9287PciePhy_clkreq_off_L1_9287_1_0,
695 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_0), 2);
696 else
697 INIT_INI_ARRAY(&ah->iniPcieSerdes,
698 ar9287PciePhy_clkreq_always_on_L1_9287_1_0,
699 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_0),
700 2);
701 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
702
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530703
Sujith2660b812009-02-09 13:27:26 +0530704 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530705 ARRAY_SIZE(ar9285Modes_9285_1_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530706 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530707 ARRAY_SIZE(ar9285Common_9285_1_2), 2);
708
Sujith2660b812009-02-09 13:27:26 +0530709 if (ah->config.pcie_clock_req) {
710 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530711 ar9285PciePhy_clkreq_off_L1_9285_1_2,
712 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2);
713 } else {
Sujith2660b812009-02-09 13:27:26 +0530714 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530715 ar9285PciePhy_clkreq_always_on_L1_9285_1_2,
716 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2),
717 2);
718 }
719 } else if (AR_SREV_9285_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530720 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530721 ARRAY_SIZE(ar9285Modes_9285), 6);
Sujith2660b812009-02-09 13:27:26 +0530722 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530723 ARRAY_SIZE(ar9285Common_9285), 2);
724
Sujith2660b812009-02-09 13:27:26 +0530725 if (ah->config.pcie_clock_req) {
726 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530727 ar9285PciePhy_clkreq_off_L1_9285,
728 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2);
729 } else {
Sujith2660b812009-02-09 13:27:26 +0530730 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530731 ar9285PciePhy_clkreq_always_on_L1_9285,
732 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285), 2);
733 }
734 } else if (AR_SREV_9280_20_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530735 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700736 ARRAY_SIZE(ar9280Modes_9280_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530737 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700738 ARRAY_SIZE(ar9280Common_9280_2), 2);
739
Sujith2660b812009-02-09 13:27:26 +0530740 if (ah->config.pcie_clock_req) {
741 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530742 ar9280PciePhy_clkreq_off_L1_9280,
743 ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700744 } else {
Sujith2660b812009-02-09 13:27:26 +0530745 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530746 ar9280PciePhy_clkreq_always_on_L1_9280,
747 ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700748 }
Sujith2660b812009-02-09 13:27:26 +0530749 INIT_INI_ARRAY(&ah->iniModesAdditional,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700750 ar9280Modes_fast_clock_9280_2,
Sujithf1dc5602008-10-29 10:16:30 +0530751 ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700752 } else if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530753 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700754 ARRAY_SIZE(ar9280Modes_9280), 6);
Sujith2660b812009-02-09 13:27:26 +0530755 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700756 ARRAY_SIZE(ar9280Common_9280), 2);
757 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530758 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700759 ARRAY_SIZE(ar5416Modes_9160), 6);
Sujith2660b812009-02-09 13:27:26 +0530760 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700761 ARRAY_SIZE(ar5416Common_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530762 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700763 ARRAY_SIZE(ar5416Bank0_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530764 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700765 ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530766 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700767 ARRAY_SIZE(ar5416Bank1_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530768 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700769 ARRAY_SIZE(ar5416Bank2_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530770 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700771 ARRAY_SIZE(ar5416Bank3_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530772 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700773 ARRAY_SIZE(ar5416Bank6_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530774 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700775 ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530776 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700777 ARRAY_SIZE(ar5416Bank7_9160), 2);
778 if (AR_SREV_9160_11(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530779 INIT_INI_ARRAY(&ah->iniAddac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700780 ar5416Addac_91601_1,
781 ARRAY_SIZE(ar5416Addac_91601_1), 2);
782 } else {
Sujith2660b812009-02-09 13:27:26 +0530783 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700784 ARRAY_SIZE(ar5416Addac_9160), 2);
785 }
786 } else if (AR_SREV_9100_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530787 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700788 ARRAY_SIZE(ar5416Modes_9100), 6);
Sujith2660b812009-02-09 13:27:26 +0530789 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700790 ARRAY_SIZE(ar5416Common_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530791 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700792 ARRAY_SIZE(ar5416Bank0_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530793 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700794 ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530795 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700796 ARRAY_SIZE(ar5416Bank1_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530797 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700798 ARRAY_SIZE(ar5416Bank2_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530799 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700800 ARRAY_SIZE(ar5416Bank3_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530801 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700802 ARRAY_SIZE(ar5416Bank6_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530803 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700804 ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530805 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700806 ARRAY_SIZE(ar5416Bank7_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530807 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700808 ARRAY_SIZE(ar5416Addac_9100), 2);
809 } else {
Sujith2660b812009-02-09 13:27:26 +0530810 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700811 ARRAY_SIZE(ar5416Modes), 6);
Sujith2660b812009-02-09 13:27:26 +0530812 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700813 ARRAY_SIZE(ar5416Common), 2);
Sujith2660b812009-02-09 13:27:26 +0530814 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700815 ARRAY_SIZE(ar5416Bank0), 2);
Sujith2660b812009-02-09 13:27:26 +0530816 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700817 ARRAY_SIZE(ar5416BB_RfGain), 3);
Sujith2660b812009-02-09 13:27:26 +0530818 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700819 ARRAY_SIZE(ar5416Bank1), 2);
Sujith2660b812009-02-09 13:27:26 +0530820 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700821 ARRAY_SIZE(ar5416Bank2), 2);
Sujith2660b812009-02-09 13:27:26 +0530822 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700823 ARRAY_SIZE(ar5416Bank3), 3);
Sujith2660b812009-02-09 13:27:26 +0530824 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700825 ARRAY_SIZE(ar5416Bank6), 3);
Sujith2660b812009-02-09 13:27:26 +0530826 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700827 ARRAY_SIZE(ar5416Bank6TPC), 3);
Sujith2660b812009-02-09 13:27:26 +0530828 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700829 ARRAY_SIZE(ar5416Bank7), 2);
Sujith2660b812009-02-09 13:27:26 +0530830 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700831 ARRAY_SIZE(ar5416Addac), 2);
832 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700833}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700834
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700835static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
836{
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530837 if (AR_SREV_9287_11_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530838 INIT_INI_ARRAY(&ah->iniModesRxGain,
839 ar9287Modes_rx_gain_9287_1_1,
840 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_1), 6);
841 else if (AR_SREV_9287_10(ah))
842 INIT_INI_ARRAY(&ah->iniModesRxGain,
843 ar9287Modes_rx_gain_9287_1_0,
844 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_0), 6);
845 else if (AR_SREV_9280_20(ah))
846 ath9k_hw_init_rxgain_ini(ah);
847
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530848 if (AR_SREV_9287_11_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530849 INIT_INI_ARRAY(&ah->iniModesTxGain,
850 ar9287Modes_tx_gain_9287_1_1,
851 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_1), 6);
852 } else if (AR_SREV_9287_10(ah)) {
853 INIT_INI_ARRAY(&ah->iniModesTxGain,
854 ar9287Modes_tx_gain_9287_1_0,
855 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_0), 6);
856 } else if (AR_SREV_9280_20(ah)) {
857 ath9k_hw_init_txgain_ini(ah);
858 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530859 u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
860
861 /* txgain table */
862 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) {
863 INIT_INI_ARRAY(&ah->iniModesTxGain,
864 ar9285Modes_high_power_tx_gain_9285_1_2,
865 ARRAY_SIZE(ar9285Modes_high_power_tx_gain_9285_1_2), 6);
866 } else {
867 INIT_INI_ARRAY(&ah->iniModesTxGain,
868 ar9285Modes_original_tx_gain_9285_1_2,
869 ARRAY_SIZE(ar9285Modes_original_tx_gain_9285_1_2), 6);
870 }
871
872 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700873}
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530874
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700875static void ath9k_hw_init_11a_eeprom_fix(struct ath_hw *ah)
876{
877 u32 i, j;
Sujith06d0f062009-02-12 10:06:45 +0530878
879 if ((ah->hw_version.devid == AR9280_DEVID_PCI) &&
880 test_bit(ATH9K_MODE_11A, ah->caps.wireless_modes)) {
881
882 /* EEPROM Fixup */
Sujith2660b812009-02-09 13:27:26 +0530883 for (i = 0; i < ah->iniModes.ia_rows; i++) {
884 u32 reg = INI_RA(&ah->iniModes, i, 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700885
Sujith2660b812009-02-09 13:27:26 +0530886 for (j = 1; j < ah->iniModes.ia_columns; j++) {
887 u32 val = INI_RA(&ah->iniModes, i, j);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700888
Sujith2660b812009-02-09 13:27:26 +0530889 INI_RA(&ah->iniModes, i, j) =
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530890 ath9k_hw_ini_fixup(ah,
Sujith2660b812009-02-09 13:27:26 +0530891 &ah->eeprom.def,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700892 reg, val);
893 }
894 }
895 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700896}
897
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700898int ath9k_hw_init(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700899{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700900 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700901 int r = 0;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700902
Luis R. Rodriguez3ca34032009-09-23 23:07:01 -0400903 if (!ath9k_hw_devid_supported(ah->hw_version.devid)) {
904 ath_print(common, ATH_DBG_FATAL,
905 "Unsupported device ID: 0x%0x\n",
906 ah->hw_version.devid);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700907 return -EOPNOTSUPP;
Luis R. Rodriguez3ca34032009-09-23 23:07:01 -0400908 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700909
910 ath9k_hw_init_defaults(ah);
911 ath9k_hw_init_config(ah);
912
913 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700914 ath_print(common, ATH_DBG_FATAL,
915 "Couldn't reset chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700916 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700917 }
918
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700919 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700920 ath_print(common, ATH_DBG_FATAL, "Couldn't wakeup chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700921 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700922 }
923
924 if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
925 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
926 (AR_SREV_9280(ah) && !ah->is_pciexpress)) {
927 ah->config.serialize_regmode =
928 SER_REG_MODE_ON;
929 } else {
930 ah->config.serialize_regmode =
931 SER_REG_MODE_OFF;
932 }
933 }
934
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700935 ath_print(common, ATH_DBG_RESET, "serialize_regmode is %d\n",
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700936 ah->config.serialize_regmode);
937
938 if (!ath9k_hw_macversion_supported(ah->hw_version.macVersion)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700939 ath_print(common, ATH_DBG_FATAL,
940 "Mac Chip Rev 0x%02x.%x is not supported by "
941 "this driver\n", ah->hw_version.macVersion,
942 ah->hw_version.macRev);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700943 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700944 }
945
946 if (AR_SREV_9100(ah)) {
947 ah->iq_caldata.calData = &iq_cal_multi_sample;
948 ah->supp_cals = IQ_MISMATCH_CAL;
949 ah->is_pciexpress = false;
950 }
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400951
952 if (AR_SREV_9271(ah))
953 ah->is_pciexpress = false;
954
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700955 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
956
957 ath9k_hw_init_cal_settings(ah);
958
959 ah->ani_function = ATH9K_ANI_ALL;
960 if (AR_SREV_9280_10_OR_LATER(ah))
961 ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
962
963 ath9k_hw_init_mode_regs(ah);
964
965 if (ah->is_pciexpress)
Vivek Natarajan93b1b372009-09-17 09:24:58 +0530966 ath9k_hw_configpcipowersave(ah, 0, 0);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700967 else
968 ath9k_hw_disablepcie(ah);
969
Sujith193cd452009-09-18 15:04:07 +0530970 /* Support for Japan ch.14 (2484) spread */
971 if (AR_SREV_9287_11_OR_LATER(ah)) {
972 INIT_INI_ARRAY(&ah->iniCckfirNormal,
973 ar9287Common_normal_cck_fir_coeff_92871_1,
974 ARRAY_SIZE(ar9287Common_normal_cck_fir_coeff_92871_1), 2);
975 INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
976 ar9287Common_japan_2484_cck_fir_coeff_92871_1,
977 ARRAY_SIZE(ar9287Common_japan_2484_cck_fir_coeff_92871_1), 2);
978 }
979
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700980 r = ath9k_hw_post_init(ah);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700981 if (r)
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700982 return r;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700983
984 ath9k_hw_init_mode_gain_regs(ah);
985 ath9k_hw_fill_cap_info(ah);
986 ath9k_hw_init_11a_eeprom_fix(ah);
Sujithf6688cd2008-12-07 21:43:10 +0530987
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700988 r = ath9k_hw_init_macaddr(ah);
989 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700990 ath_print(common, ATH_DBG_FATAL,
991 "Failed to initialize MAC address\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700992 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700993 }
994
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400995 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
Sujith2660b812009-02-09 13:27:26 +0530996 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700997 else
Sujith2660b812009-02-09 13:27:26 +0530998 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700999
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001000 ath9k_init_nfcal_hist_buffer(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001001
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001002 common->state = ATH_HW_INITIALIZED;
1003
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001004 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001005}
1006
Sujithcbe61d82009-02-09 13:27:12 +05301007static void ath9k_hw_init_bb(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301008 struct ath9k_channel *chan)
1009{
1010 u32 synthDelay;
1011
1012 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +05301013 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +05301014 synthDelay = (4 * synthDelay) / 22;
1015 else
1016 synthDelay /= 10;
1017
1018 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
1019
1020 udelay(synthDelay + BASE_ACTIVATE_DELAY);
1021}
1022
Sujithcbe61d82009-02-09 13:27:12 +05301023static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301024{
1025 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
1026 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
1027
1028 REG_WRITE(ah, AR_QOS_NO_ACK,
1029 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
1030 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
1031 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
1032
1033 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
1034 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
1035 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
1036 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
1037 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
1038}
1039
Sujithcbe61d82009-02-09 13:27:12 +05301040static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301041 struct ath9k_channel *chan)
1042{
1043 u32 pll;
1044
1045 if (AR_SREV_9100(ah)) {
1046 if (chan && IS_CHAN_5GHZ(chan))
1047 pll = 0x1450;
1048 else
1049 pll = 0x1458;
1050 } else {
1051 if (AR_SREV_9280_10_OR_LATER(ah)) {
1052 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
1053
1054 if (chan && IS_CHAN_HALF_RATE(chan))
1055 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
1056 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1057 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
1058
1059 if (chan && IS_CHAN_5GHZ(chan)) {
1060 pll |= SM(0x28, AR_RTC_9160_PLL_DIV);
1061
1062
1063 if (AR_SREV_9280_20(ah)) {
1064 if (((chan->channel % 20) == 0)
1065 || ((chan->channel % 10) == 0))
1066 pll = 0x2850;
1067 else
1068 pll = 0x142c;
1069 }
1070 } else {
1071 pll |= SM(0x2c, AR_RTC_9160_PLL_DIV);
1072 }
1073
1074 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1075
1076 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
1077
1078 if (chan && IS_CHAN_HALF_RATE(chan))
1079 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
1080 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1081 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
1082
1083 if (chan && IS_CHAN_5GHZ(chan))
1084 pll |= SM(0x50, AR_RTC_9160_PLL_DIV);
1085 else
1086 pll |= SM(0x58, AR_RTC_9160_PLL_DIV);
1087 } else {
1088 pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2;
1089
1090 if (chan && IS_CHAN_HALF_RATE(chan))
1091 pll |= SM(0x1, AR_RTC_PLL_CLKSEL);
1092 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1093 pll |= SM(0x2, AR_RTC_PLL_CLKSEL);
1094
1095 if (chan && IS_CHAN_5GHZ(chan))
1096 pll |= SM(0xa, AR_RTC_PLL_DIV);
1097 else
1098 pll |= SM(0xb, AR_RTC_PLL_DIV);
1099 }
1100 }
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001101 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +05301102
1103 udelay(RTC_PLL_SETTLE_DELAY);
1104
1105 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
1106}
1107
Sujithcbe61d82009-02-09 13:27:12 +05301108static void ath9k_hw_init_chain_masks(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301109{
Sujithf1dc5602008-10-29 10:16:30 +05301110 int rx_chainmask, tx_chainmask;
1111
Sujith2660b812009-02-09 13:27:26 +05301112 rx_chainmask = ah->rxchainmask;
1113 tx_chainmask = ah->txchainmask;
Sujithf1dc5602008-10-29 10:16:30 +05301114
1115 switch (rx_chainmask) {
1116 case 0x5:
1117 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1118 AR_PHY_SWAP_ALT_CHAIN);
1119 case 0x3:
Sujithd535a422009-02-09 13:27:06 +05301120 if (((ah)->hw_version.macVersion <= AR_SREV_VERSION_9160)) {
Sujithf1dc5602008-10-29 10:16:30 +05301121 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7);
1122 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7);
1123 break;
1124 }
1125 case 0x1:
1126 case 0x2:
Sujithf1dc5602008-10-29 10:16:30 +05301127 case 0x7:
1128 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
1129 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
1130 break;
1131 default:
1132 break;
1133 }
1134
1135 REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);
1136 if (tx_chainmask == 0x5) {
1137 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1138 AR_PHY_SWAP_ALT_CHAIN);
1139 }
1140 if (AR_SREV_9100(ah))
1141 REG_WRITE(ah, AR_PHY_ANALOG_SWAP,
1142 REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
1143}
1144
Sujithcbe61d82009-02-09 13:27:12 +05301145static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -08001146 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301147{
Sujith2660b812009-02-09 13:27:26 +05301148 ah->mask_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +05301149 AR_IMR_TXURN |
1150 AR_IMR_RXERR |
1151 AR_IMR_RXORN |
1152 AR_IMR_BCNMISC;
1153
Sujith0ef1f162009-03-30 15:28:35 +05301154 if (ah->config.intr_mitigation)
Sujith2660b812009-02-09 13:27:26 +05301155 ah->mask_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
Sujithf1dc5602008-10-29 10:16:30 +05301156 else
Sujith2660b812009-02-09 13:27:26 +05301157 ah->mask_reg |= AR_IMR_RXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301158
Sujith2660b812009-02-09 13:27:26 +05301159 ah->mask_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301160
Colin McCabed97809d2008-12-01 13:38:55 -08001161 if (opmode == NL80211_IFTYPE_AP)
Sujith2660b812009-02-09 13:27:26 +05301162 ah->mask_reg |= AR_IMR_MIB;
Sujithf1dc5602008-10-29 10:16:30 +05301163
Sujith2660b812009-02-09 13:27:26 +05301164 REG_WRITE(ah, AR_IMR, ah->mask_reg);
Sujithf1dc5602008-10-29 10:16:30 +05301165 REG_WRITE(ah, AR_IMR_S2, REG_READ(ah, AR_IMR_S2) | AR_IMR_S2_GTT);
1166
1167 if (!AR_SREV_9100(ah)) {
1168 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
1169 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
1170 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
1171 }
1172}
1173
Sujithcbe61d82009-02-09 13:27:12 +05301174static bool ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301175{
Sujithf1dc5602008-10-29 10:16:30 +05301176 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001177 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1178 "bad ack timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301179 ah->acktimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301180 return false;
1181 } else {
1182 REG_RMW_FIELD(ah, AR_TIME_OUT,
1183 AR_TIME_OUT_ACK, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301184 ah->acktimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301185 return true;
1186 }
1187}
1188
Sujithcbe61d82009-02-09 13:27:12 +05301189static bool ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301190{
Sujithf1dc5602008-10-29 10:16:30 +05301191 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_CTS))) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001192 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1193 "bad cts timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301194 ah->ctstimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301195 return false;
1196 } else {
1197 REG_RMW_FIELD(ah, AR_TIME_OUT,
1198 AR_TIME_OUT_CTS, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301199 ah->ctstimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301200 return true;
1201 }
1202}
1203
Sujithcbe61d82009-02-09 13:27:12 +05301204static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +05301205{
Sujithf1dc5602008-10-29 10:16:30 +05301206 if (tu > 0xFFFF) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001207 ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT,
1208 "bad global tx timeout %u\n", tu);
Sujith2660b812009-02-09 13:27:26 +05301209 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301210 return false;
1211 } else {
1212 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +05301213 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +05301214 return true;
1215 }
1216}
1217
Sujithcbe61d82009-02-09 13:27:12 +05301218static void ath9k_hw_init_user_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301219{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001220 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
1221 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +05301222
Sujith2660b812009-02-09 13:27:26 +05301223 if (ah->misc_mode != 0)
Sujithf1dc5602008-10-29 10:16:30 +05301224 REG_WRITE(ah, AR_PCU_MISC,
Sujith2660b812009-02-09 13:27:26 +05301225 REG_READ(ah, AR_PCU_MISC) | ah->misc_mode);
1226 if (ah->slottime != (u32) -1)
1227 ath9k_hw_setslottime(ah, ah->slottime);
1228 if (ah->acktimeout != (u32) -1)
1229 ath9k_hw_set_ack_timeout(ah, ah->acktimeout);
1230 if (ah->ctstimeout != (u32) -1)
1231 ath9k_hw_set_cts_timeout(ah, ah->ctstimeout);
1232 if (ah->globaltxtimeout != (u32) -1)
1233 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Sujithf1dc5602008-10-29 10:16:30 +05301234}
1235
1236const char *ath9k_hw_probe(u16 vendorid, u16 devid)
1237{
1238 return vendorid == ATHEROS_VENDOR_ID ?
1239 ath9k_hw_devname(devid) : NULL;
1240}
1241
Sujithcbe61d82009-02-09 13:27:12 +05301242void ath9k_hw_detach(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001243{
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001244 struct ath_common *common = ath9k_hw_common(ah);
1245
1246 if (common->state <= ATH_HW_INITIALIZED)
1247 goto free_hw;
1248
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001249 if (!AR_SREV_9100(ah))
Luis R. Rodrigueze70c0cf2009-08-03 12:24:51 -07001250 ath9k_hw_ani_disable(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001251
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001252 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001253
1254free_hw:
1255 ath9k_hw_rf_free(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001256 kfree(ah);
Luis R. Rodriguez9db6b6a2009-08-03 12:24:52 -07001257 ah = NULL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001258}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001259EXPORT_SYMBOL(ath9k_hw_detach);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001260
Sujithf1dc5602008-10-29 10:16:30 +05301261/*******/
1262/* INI */
1263/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001264
Sujithcbe61d82009-02-09 13:27:12 +05301265static void ath9k_hw_override_ini(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301266 struct ath9k_channel *chan)
1267{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001268 u32 val;
1269
1270 if (AR_SREV_9271(ah)) {
1271 /*
1272 * Enable spectral scan to solution for issues with stuck
1273 * beacons on AR9271 1.0. The beacon stuck issue is not seeon on
1274 * AR9271 1.1
1275 */
1276 if (AR_SREV_9271_10(ah)) {
1277 val = REG_READ(ah, AR_PHY_SPECTRAL_SCAN) | AR_PHY_SPECTRAL_SCAN_ENABLE;
1278 REG_WRITE(ah, AR_PHY_SPECTRAL_SCAN, val);
1279 }
1280 else if (AR_SREV_9271_11(ah))
1281 /*
1282 * change AR_PHY_RF_CTL3 setting to fix MAC issue
1283 * present on AR9271 1.1
1284 */
1285 REG_WRITE(ah, AR_PHY_RF_CTL3, 0x3a020001);
1286 return;
1287 }
1288
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +05301289 /*
1290 * Set the RX_ABORT and RX_DIS and clear if off only after
1291 * RXE is set for MAC. This prevents frames with corrupted
1292 * descriptor status.
1293 */
1294 REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
1295
Vasanthakumar Thiagarajan204d7942009-09-17 09:26:14 +05301296 if (AR_SREV_9280_10_OR_LATER(ah)) {
1297 val = REG_READ(ah, AR_PCU_MISC_MODE2) &
1298 (~AR_PCU_MISC_MODE2_HWWAR1);
1299
1300 if (AR_SREV_9287_10_OR_LATER(ah))
1301 val = val & (~AR_PCU_MISC_MODE2_HWWAR2);
1302
1303 REG_WRITE(ah, AR_PCU_MISC_MODE2, val);
1304 }
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +05301305
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001306 if (!AR_SREV_5416_20_OR_LATER(ah) ||
Sujithf1dc5602008-10-29 10:16:30 +05301307 AR_SREV_9280_10_OR_LATER(ah))
1308 return;
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001309 /*
1310 * Disable BB clock gating
1311 * Necessary to avoid issues on AR5416 2.0
1312 */
Sujithf1dc5602008-10-29 10:16:30 +05301313 REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
1314}
1315
Sujithcbe61d82009-02-09 13:27:12 +05301316static u32 ath9k_hw_def_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301317 struct ar5416_eeprom_def *pEepData,
Sujithf1dc5602008-10-29 10:16:30 +05301318 u32 reg, u32 value)
1319{
1320 struct base_eep_header *pBase = &(pEepData->baseEepHeader);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001321 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301322
Sujithd535a422009-02-09 13:27:06 +05301323 switch (ah->hw_version.devid) {
Sujithf1dc5602008-10-29 10:16:30 +05301324 case AR9280_DEVID_PCI:
1325 if (reg == 0x7894) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001326 ath_print(common, ATH_DBG_EEPROM,
Sujithf1dc5602008-10-29 10:16:30 +05301327 "ini VAL: %x EEPROM: %x\n", value,
1328 (pBase->version & 0xff));
1329
1330 if ((pBase->version & 0xff) > 0x0a) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001331 ath_print(common, ATH_DBG_EEPROM,
1332 "PWDCLKIND: %d\n",
1333 pBase->pwdclkind);
Sujithf1dc5602008-10-29 10:16:30 +05301334 value &= ~AR_AN_TOP2_PWDCLKIND;
1335 value |= AR_AN_TOP2_PWDCLKIND &
1336 (pBase->pwdclkind << AR_AN_TOP2_PWDCLKIND_S);
1337 } else {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001338 ath_print(common, ATH_DBG_EEPROM,
1339 "PWDCLKIND Earlier Rev\n");
Sujithf1dc5602008-10-29 10:16:30 +05301340 }
1341
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001342 ath_print(common, ATH_DBG_EEPROM,
1343 "final ini VAL: %x\n", value);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001344 }
Sujithf1dc5602008-10-29 10:16:30 +05301345 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001346 }
1347
Sujithf1dc5602008-10-29 10:16:30 +05301348 return value;
1349}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001350
Sujithcbe61d82009-02-09 13:27:12 +05301351static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301352 struct ar5416_eeprom_def *pEepData,
1353 u32 reg, u32 value)
1354{
Sujith2660b812009-02-09 13:27:26 +05301355 if (ah->eep_map == EEP_MAP_4KBITS)
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301356 return value;
1357 else
1358 return ath9k_hw_def_ini_fixup(ah, pEepData, reg, value);
1359}
1360
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301361static void ath9k_olc_init(struct ath_hw *ah)
1362{
1363 u32 i;
1364
Vivek Natarajandb91f2e2009-08-14 11:27:16 +05301365 if (OLC_FOR_AR9287_10_LATER) {
1366 REG_SET_BIT(ah, AR_PHY_TX_PWRCTRL9,
1367 AR_PHY_TX_PWRCTRL9_RES_DC_REMOVAL);
1368 ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TXPC0,
1369 AR9287_AN_TXPC0_TXPCMODE,
1370 AR9287_AN_TXPC0_TXPCMODE_S,
1371 AR9287_AN_TXPC0_TXPCMODE_TEMPSENSE);
1372 udelay(100);
1373 } else {
1374 for (i = 0; i < AR9280_TX_GAIN_TABLE_SIZE; i++)
1375 ah->originalGain[i] =
1376 MS(REG_READ(ah, AR_PHY_TX_GAIN_TBL1 + i * 4),
1377 AR_PHY_TX_GAIN);
1378 ah->PDADCdelta = 0;
1379 }
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301380}
1381
Bob Copeland3a702e42009-03-30 22:30:29 -04001382static u32 ath9k_regd_get_ctl(struct ath_regulatory *reg,
1383 struct ath9k_channel *chan)
1384{
1385 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
1386
1387 if (IS_CHAN_B(chan))
1388 ctl |= CTL_11B;
1389 else if (IS_CHAN_G(chan))
1390 ctl |= CTL_11G;
1391 else
1392 ctl |= CTL_11A;
1393
1394 return ctl;
1395}
1396
Sujithcbe61d82009-02-09 13:27:12 +05301397static int ath9k_hw_process_ini(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001398 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301399{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001400 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301401 int i, regWrites = 0;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001402 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301403 u32 modesIndex, freqIndex;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001404
Sujithf1dc5602008-10-29 10:16:30 +05301405 switch (chan->chanmode) {
1406 case CHANNEL_A:
1407 case CHANNEL_A_HT20:
1408 modesIndex = 1;
1409 freqIndex = 1;
1410 break;
1411 case CHANNEL_A_HT40PLUS:
1412 case CHANNEL_A_HT40MINUS:
1413 modesIndex = 2;
1414 freqIndex = 1;
1415 break;
1416 case CHANNEL_G:
1417 case CHANNEL_G_HT20:
1418 case CHANNEL_B:
1419 modesIndex = 4;
1420 freqIndex = 2;
1421 break;
1422 case CHANNEL_G_HT40PLUS:
1423 case CHANNEL_G_HT40MINUS:
1424 modesIndex = 3;
1425 freqIndex = 2;
1426 break;
1427
1428 default:
1429 return -EINVAL;
1430 }
1431
1432 REG_WRITE(ah, AR_PHY(0), 0x00000007);
Sujithf1dc5602008-10-29 10:16:30 +05301433 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
Sujithf74df6f2009-02-09 13:27:24 +05301434 ah->eep_ops->set_addac(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301435
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001436 if (AR_SREV_5416_22_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +05301437 REG_WRITE_ARRAY(&ah->iniAddac, 1, regWrites);
Sujithf1dc5602008-10-29 10:16:30 +05301438 } else {
1439 struct ar5416IniArray temp;
1440 u32 addacSize =
Sujith2660b812009-02-09 13:27:26 +05301441 sizeof(u32) * ah->iniAddac.ia_rows *
1442 ah->iniAddac.ia_columns;
Sujithf1dc5602008-10-29 10:16:30 +05301443
Sujith2660b812009-02-09 13:27:26 +05301444 memcpy(ah->addac5416_21,
1445 ah->iniAddac.ia_array, addacSize);
Sujithf1dc5602008-10-29 10:16:30 +05301446
Sujith2660b812009-02-09 13:27:26 +05301447 (ah->addac5416_21)[31 * ah->iniAddac.ia_columns + 1] = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301448
Sujith2660b812009-02-09 13:27:26 +05301449 temp.ia_array = ah->addac5416_21;
1450 temp.ia_columns = ah->iniAddac.ia_columns;
1451 temp.ia_rows = ah->iniAddac.ia_rows;
Sujithf1dc5602008-10-29 10:16:30 +05301452 REG_WRITE_ARRAY(&temp, 1, regWrites);
1453 }
1454
1455 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
1456
Sujith2660b812009-02-09 13:27:26 +05301457 for (i = 0; i < ah->iniModes.ia_rows; i++) {
1458 u32 reg = INI_RA(&ah->iniModes, i, 0);
1459 u32 val = INI_RA(&ah->iniModes, i, modesIndex);
Sujithf1dc5602008-10-29 10:16:30 +05301460
Sujithf1dc5602008-10-29 10:16:30 +05301461 REG_WRITE(ah, reg, val);
1462
1463 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301464 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301465 udelay(100);
1466 }
1467
1468 DO_DELAY(regWrites);
1469 }
1470
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301471 if (AR_SREV_9280(ah) || AR_SREV_9287_10_OR_LATER(ah))
Sujith2660b812009-02-09 13:27:26 +05301472 REG_WRITE_ARRAY(&ah->iniModesRxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301473
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301474 if (AR_SREV_9280(ah) || AR_SREV_9285_12_OR_LATER(ah) ||
1475 AR_SREV_9287_10_OR_LATER(ah))
Sujith2660b812009-02-09 13:27:26 +05301476 REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301477
Sujith2660b812009-02-09 13:27:26 +05301478 for (i = 0; i < ah->iniCommon.ia_rows; i++) {
1479 u32 reg = INI_RA(&ah->iniCommon, i, 0);
1480 u32 val = INI_RA(&ah->iniCommon, i, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301481
1482 REG_WRITE(ah, reg, val);
1483
1484 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301485 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301486 udelay(100);
1487 }
1488
1489 DO_DELAY(regWrites);
1490 }
1491
1492 ath9k_hw_write_regs(ah, modesIndex, freqIndex, regWrites);
1493
1494 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan)) {
Sujith2660b812009-02-09 13:27:26 +05301495 REG_WRITE_ARRAY(&ah->iniModesAdditional, modesIndex,
Sujithf1dc5602008-10-29 10:16:30 +05301496 regWrites);
1497 }
1498
1499 ath9k_hw_override_ini(ah, chan);
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001500 ath9k_hw_set_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301501 ath9k_hw_init_chain_masks(ah);
1502
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301503 if (OLC_FOR_AR9280_20_LATER)
1504 ath9k_olc_init(ah);
1505
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001506 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001507 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001508 channel->max_antenna_gain * 2,
1509 channel->max_power * 2,
1510 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001511 (u32) regulatory->power_limit));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001512
Sujithf1dc5602008-10-29 10:16:30 +05301513 if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001514 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1515 "ar5416SetRfRegs failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001516 return -EIO;
1517 }
1518
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001519 return 0;
1520}
1521
Sujithf1dc5602008-10-29 10:16:30 +05301522/****************************************/
1523/* Reset and Channel Switching Routines */
1524/****************************************/
1525
Sujithcbe61d82009-02-09 13:27:12 +05301526static void ath9k_hw_set_rfmode(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301527{
1528 u32 rfMode = 0;
1529
1530 if (chan == NULL)
1531 return;
1532
1533 rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
1534 ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
1535
1536 if (!AR_SREV_9280_10_OR_LATER(ah))
1537 rfMode |= (IS_CHAN_5GHZ(chan)) ?
1538 AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ;
1539
1540 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan))
1541 rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
1542
1543 REG_WRITE(ah, AR_PHY_MODE, rfMode);
1544}
1545
Sujithcbe61d82009-02-09 13:27:12 +05301546static void ath9k_hw_mark_phy_inactive(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301547{
1548 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
1549}
1550
Sujithcbe61d82009-02-09 13:27:12 +05301551static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301552{
1553 u32 regval;
1554
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001555 /*
1556 * set AHB_MODE not to do cacheline prefetches
1557 */
Sujithf1dc5602008-10-29 10:16:30 +05301558 regval = REG_READ(ah, AR_AHB_MODE);
1559 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
1560
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001561 /*
1562 * let mac dma reads be in 128 byte chunks
1563 */
Sujithf1dc5602008-10-29 10:16:30 +05301564 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
1565 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
1566
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001567 /*
1568 * Restore TX Trigger Level to its pre-reset value.
1569 * The initial value depends on whether aggregation is enabled, and is
1570 * adjusted whenever underruns are detected.
1571 */
Sujith2660b812009-02-09 13:27:26 +05301572 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +05301573
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001574 /*
1575 * let mac dma writes be in 128 byte chunks
1576 */
Sujithf1dc5602008-10-29 10:16:30 +05301577 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
1578 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
1579
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001580 /*
1581 * Setup receive FIFO threshold to hold off TX activities
1582 */
Sujithf1dc5602008-10-29 10:16:30 +05301583 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1584
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001585 /*
1586 * reduce the number of usable entries in PCU TXBUF to avoid
1587 * wrap around issues.
1588 */
Sujithf1dc5602008-10-29 10:16:30 +05301589 if (AR_SREV_9285(ah)) {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001590 /* For AR9285 the number of Fifos are reduced to half.
1591 * So set the usable tx buf size also to half to
1592 * avoid data/delimiter underruns
1593 */
Sujithf1dc5602008-10-29 10:16:30 +05301594 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1595 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001596 } else if (!AR_SREV_9271(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +05301597 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1598 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1599 }
1600}
1601
Sujithcbe61d82009-02-09 13:27:12 +05301602static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301603{
1604 u32 val;
1605
1606 val = REG_READ(ah, AR_STA_ID1);
1607 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
1608 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001609 case NL80211_IFTYPE_AP:
Sujithf1dc5602008-10-29 10:16:30 +05301610 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
1611 | AR_STA_ID1_KSRCH_MODE);
1612 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1613 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001614 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04001615 case NL80211_IFTYPE_MESH_POINT:
Sujithf1dc5602008-10-29 10:16:30 +05301616 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
1617 | AR_STA_ID1_KSRCH_MODE);
1618 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1619 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001620 case NL80211_IFTYPE_STATION:
1621 case NL80211_IFTYPE_MONITOR:
Sujithf1dc5602008-10-29 10:16:30 +05301622 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
1623 break;
1624 }
1625}
1626
Sujithcbe61d82009-02-09 13:27:12 +05301627static inline void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001628 u32 coef_scaled,
1629 u32 *coef_mantissa,
1630 u32 *coef_exponent)
1631{
1632 u32 coef_exp, coef_man;
1633
1634 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1635 if ((coef_scaled >> coef_exp) & 0x1)
1636 break;
1637
1638 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1639
1640 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1641
1642 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1643 *coef_exponent = coef_exp - 16;
1644}
1645
Sujithcbe61d82009-02-09 13:27:12 +05301646static void ath9k_hw_set_delta_slope(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301647 struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001648{
1649 u32 coef_scaled, ds_coef_exp, ds_coef_man;
1650 u32 clockMhzScaled = 0x64000000;
1651 struct chan_centers centers;
1652
1653 if (IS_CHAN_HALF_RATE(chan))
1654 clockMhzScaled = clockMhzScaled >> 1;
1655 else if (IS_CHAN_QUARTER_RATE(chan))
1656 clockMhzScaled = clockMhzScaled >> 2;
1657
1658 ath9k_hw_get_channel_centers(ah, chan, &centers);
1659 coef_scaled = clockMhzScaled / centers.synth_center;
1660
1661 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1662 &ds_coef_exp);
1663
1664 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1665 AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
1666 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1667 AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
1668
1669 coef_scaled = (9 * coef_scaled) / 10;
1670
1671 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1672 &ds_coef_exp);
1673
1674 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1675 AR_PHY_HALFGI_DSC_MAN, ds_coef_man);
1676 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1677 AR_PHY_HALFGI_DSC_EXP, ds_coef_exp);
1678}
1679
Sujithcbe61d82009-02-09 13:27:12 +05301680static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +05301681{
1682 u32 rst_flags;
1683 u32 tmpReg;
1684
Sujith70768492009-02-16 13:23:12 +05301685 if (AR_SREV_9100(ah)) {
1686 u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK);
1687 val &= ~AR_RTC_DERIVED_CLK_PERIOD;
1688 val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD);
1689 REG_WRITE(ah, AR_RTC_DERIVED_CLK, val);
1690 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1691 }
1692
Sujithf1dc5602008-10-29 10:16:30 +05301693 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1694 AR_RTC_FORCE_WAKE_ON_INT);
1695
1696 if (AR_SREV_9100(ah)) {
1697 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1698 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1699 } else {
1700 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1701 if (tmpReg &
1702 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1703 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
1704 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
1705 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1706 } else {
1707 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1708 }
1709
1710 rst_flags = AR_RTC_RC_MAC_WARM;
1711 if (type == ATH9K_RESET_COLD)
1712 rst_flags |= AR_RTC_RC_MAC_COLD;
1713 }
1714
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001715 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujithf1dc5602008-10-29 10:16:30 +05301716 udelay(50);
1717
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001718 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301719 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001720 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1721 "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301722 return false;
1723 }
1724
1725 if (!AR_SREV_9100(ah))
1726 REG_WRITE(ah, AR_RC, 0);
1727
Sujithf1dc5602008-10-29 10:16:30 +05301728 if (AR_SREV_9100(ah))
1729 udelay(50);
1730
1731 return true;
1732}
1733
Sujithcbe61d82009-02-09 13:27:12 +05301734static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301735{
1736 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1737 AR_RTC_FORCE_WAKE_ON_INT);
1738
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301739 if (!AR_SREV_9100(ah))
1740 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1741
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001742 REG_WRITE(ah, AR_RTC_RESET, 0);
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301743 udelay(2);
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301744
1745 if (!AR_SREV_9100(ah))
1746 REG_WRITE(ah, AR_RC, 0);
1747
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001748 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301749
1750 if (!ath9k_hw_wait(ah,
1751 AR_RTC_STATUS,
1752 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301753 AR_RTC_STATUS_ON,
1754 AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001755 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1756 "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301757 return false;
1758 }
1759
1760 ath9k_hw_read_revisions(ah);
1761
1762 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1763}
1764
Sujithcbe61d82009-02-09 13:27:12 +05301765static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301766{
1767 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1768 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1769
1770 switch (type) {
1771 case ATH9K_RESET_POWER_ON:
1772 return ath9k_hw_set_reset_power_on(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301773 case ATH9K_RESET_WARM:
1774 case ATH9K_RESET_COLD:
1775 return ath9k_hw_set_reset(ah, type);
Sujithf1dc5602008-10-29 10:16:30 +05301776 default:
1777 return false;
1778 }
1779}
1780
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001781static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301782{
1783 u32 phymode;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301784 u32 enableDacFifo = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301785
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301786 if (AR_SREV_9285_10_OR_LATER(ah))
1787 enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) &
1788 AR_PHY_FC_ENABLE_DAC_FIFO);
1789
Sujithf1dc5602008-10-29 10:16:30 +05301790 phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301791 | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo;
Sujithf1dc5602008-10-29 10:16:30 +05301792
1793 if (IS_CHAN_HT40(chan)) {
1794 phymode |= AR_PHY_FC_DYN2040_EN;
1795
1796 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
1797 (chan->chanmode == CHANNEL_G_HT40PLUS))
1798 phymode |= AR_PHY_FC_DYN2040_PRI_CH;
1799
Sujithf1dc5602008-10-29 10:16:30 +05301800 }
1801 REG_WRITE(ah, AR_PHY_TURBO, phymode);
1802
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001803 ath9k_hw_set11nmac2040(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301804
1805 REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
1806 REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
1807}
1808
Sujithcbe61d82009-02-09 13:27:12 +05301809static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301810 struct ath9k_channel *chan)
1811{
Vivek Natarajan42abfbe2009-09-17 09:27:59 +05301812 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) {
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301813 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
1814 return false;
1815 } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
Sujithf1dc5602008-10-29 10:16:30 +05301816 return false;
1817
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001818 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05301819 return false;
1820
Sujith2660b812009-02-09 13:27:26 +05301821 ah->chip_fullsleep = false;
Sujithf1dc5602008-10-29 10:16:30 +05301822 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301823 ath9k_hw_set_rfmode(ah, chan);
1824
1825 return true;
1826}
1827
Sujithcbe61d82009-02-09 13:27:12 +05301828static bool ath9k_hw_channel_change(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001829 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301830{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001831 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001832 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001833 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301834 u32 synthDelay, qnum;
1835
1836 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1837 if (ath9k_hw_numtxpending(ah, qnum)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001838 ath_print(common, ATH_DBG_QUEUE,
1839 "Transmit frames pending on "
1840 "queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301841 return false;
1842 }
1843 }
1844
1845 REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
1846 if (!ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
Sujith0caa7b12009-02-16 13:23:20 +05301847 AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001848 ath_print(common, ATH_DBG_FATAL,
1849 "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301850 return false;
1851 }
1852
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001853 ath9k_hw_set_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301854
1855 if (AR_SREV_9280_10_OR_LATER(ah)) {
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001856 ath9k_hw_ar9280_set_channel(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301857 } else {
1858 if (!(ath9k_hw_set_channel(ah, chan))) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001859 ath_print(common, ATH_DBG_FATAL,
1860 "Failed to set channel\n");
Sujithf1dc5602008-10-29 10:16:30 +05301861 return false;
1862 }
1863 }
1864
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001865 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001866 ath9k_regd_get_ctl(regulatory, chan),
Sujithf74df6f2009-02-09 13:27:24 +05301867 channel->max_antenna_gain * 2,
1868 channel->max_power * 2,
1869 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001870 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05301871
1872 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +05301873 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +05301874 synthDelay = (4 * synthDelay) / 22;
1875 else
1876 synthDelay /= 10;
1877
1878 udelay(synthDelay + BASE_ACTIVATE_DELAY);
1879
1880 REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
1881
1882 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1883 ath9k_hw_set_delta_slope(ah, chan);
1884
1885 if (AR_SREV_9280_10_OR_LATER(ah))
1886 ath9k_hw_9280_spur_mitigate(ah, chan);
1887 else
1888 ath9k_hw_spur_mitigate(ah, chan);
1889
1890 if (!chan->oneTimeCalsDone)
1891 chan->oneTimeCalsDone = true;
1892
1893 return true;
1894}
1895
Sujithcbe61d82009-02-09 13:27:12 +05301896static void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001897{
1898 int bb_spur = AR_NO_SPUR;
1899 int freq;
1900 int bin, cur_bin;
1901 int bb_spur_off, spur_subchannel_sd;
1902 int spur_freq_sd;
1903 int spur_delta_phase;
1904 int denominator;
1905 int upper, lower, cur_vit_mask;
1906 int tmp, newVal;
1907 int i;
1908 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
1909 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
1910 };
1911 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
1912 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
1913 };
1914 int inc[4] = { 0, 100, 0, 0 };
1915 struct chan_centers centers;
1916
1917 int8_t mask_m[123];
1918 int8_t mask_p[123];
1919 int8_t mask_amt;
1920 int tmp_mask;
1921 int cur_bb_spur;
1922 bool is2GHz = IS_CHAN_2GHZ(chan);
1923
1924 memset(&mask_m, 0, sizeof(int8_t) * 123);
1925 memset(&mask_p, 0, sizeof(int8_t) * 123);
1926
1927 ath9k_hw_get_channel_centers(ah, chan, &centers);
1928 freq = centers.synth_center;
1929
Sujith2660b812009-02-09 13:27:26 +05301930 ah->config.spurmode = SPUR_ENABLE_EEPROM;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001931 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujithf74df6f2009-02-09 13:27:24 +05301932 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001933
1934 if (is2GHz)
1935 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_2GHZ;
1936 else
1937 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_5GHZ;
1938
1939 if (AR_NO_SPUR == cur_bb_spur)
1940 break;
1941 cur_bb_spur = cur_bb_spur - freq;
1942
1943 if (IS_CHAN_HT40(chan)) {
1944 if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT40) &&
1945 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT40)) {
1946 bb_spur = cur_bb_spur;
1947 break;
1948 }
1949 } else if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT20) &&
1950 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT20)) {
1951 bb_spur = cur_bb_spur;
1952 break;
1953 }
1954 }
1955
1956 if (AR_NO_SPUR == bb_spur) {
1957 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1958 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1959 return;
1960 } else {
1961 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1962 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1963 }
1964
1965 bin = bb_spur * 320;
1966
1967 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
1968
1969 newVal = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
1970 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
1971 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
1972 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
1973 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), newVal);
1974
1975 newVal = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
1976 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
1977 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
1978 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
1979 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
1980 REG_WRITE(ah, AR_PHY_SPUR_REG, newVal);
1981
1982 if (IS_CHAN_HT40(chan)) {
1983 if (bb_spur < 0) {
1984 spur_subchannel_sd = 1;
1985 bb_spur_off = bb_spur + 10;
1986 } else {
1987 spur_subchannel_sd = 0;
1988 bb_spur_off = bb_spur - 10;
1989 }
1990 } else {
1991 spur_subchannel_sd = 0;
1992 bb_spur_off = bb_spur;
1993 }
1994
1995 if (IS_CHAN_HT40(chan))
1996 spur_delta_phase =
1997 ((bb_spur * 262144) /
1998 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
1999 else
2000 spur_delta_phase =
2001 ((bb_spur * 524288) /
2002 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
2003
2004 denominator = IS_CHAN_2GHZ(chan) ? 44 : 40;
2005 spur_freq_sd = ((bb_spur_off * 2048) / denominator) & 0x3ff;
2006
2007 newVal = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
2008 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
2009 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
2010 REG_WRITE(ah, AR_PHY_TIMING11, newVal);
2011
2012 newVal = spur_subchannel_sd << AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S;
2013 REG_WRITE(ah, AR_PHY_SFCORR_EXT, newVal);
2014
2015 cur_bin = -6000;
2016 upper = bin + 100;
2017 lower = bin - 100;
2018
2019 for (i = 0; i < 4; i++) {
2020 int pilot_mask = 0;
2021 int chan_mask = 0;
2022 int bp = 0;
2023 for (bp = 0; bp < 30; bp++) {
2024 if ((cur_bin > lower) && (cur_bin < upper)) {
2025 pilot_mask = pilot_mask | 0x1 << bp;
2026 chan_mask = chan_mask | 0x1 << bp;
2027 }
2028 cur_bin += 100;
2029 }
2030 cur_bin += inc[i];
2031 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
2032 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
2033 }
2034
2035 cur_vit_mask = 6100;
2036 upper = bin + 120;
2037 lower = bin - 120;
2038
2039 for (i = 0; i < 123; i++) {
2040 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
Adrian Bunkb08cbcd2008-08-05 22:06:51 +03002041
2042 /* workaround for gcc bug #37014 */
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002043 volatile int tmp_v = abs(cur_vit_mask - bin);
Adrian Bunkb08cbcd2008-08-05 22:06:51 +03002044
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002045 if (tmp_v < 75)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002046 mask_amt = 1;
2047 else
2048 mask_amt = 0;
2049 if (cur_vit_mask < 0)
2050 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
2051 else
2052 mask_p[cur_vit_mask / 100] = mask_amt;
2053 }
2054 cur_vit_mask -= 100;
2055 }
2056
2057 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
2058 | (mask_m[48] << 26) | (mask_m[49] << 24)
2059 | (mask_m[50] << 22) | (mask_m[51] << 20)
2060 | (mask_m[52] << 18) | (mask_m[53] << 16)
2061 | (mask_m[54] << 14) | (mask_m[55] << 12)
2062 | (mask_m[56] << 10) | (mask_m[57] << 8)
2063 | (mask_m[58] << 6) | (mask_m[59] << 4)
2064 | (mask_m[60] << 2) | (mask_m[61] << 0);
2065 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
2066 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
2067
2068 tmp_mask = (mask_m[31] << 28)
2069 | (mask_m[32] << 26) | (mask_m[33] << 24)
2070 | (mask_m[34] << 22) | (mask_m[35] << 20)
2071 | (mask_m[36] << 18) | (mask_m[37] << 16)
2072 | (mask_m[48] << 14) | (mask_m[39] << 12)
2073 | (mask_m[40] << 10) | (mask_m[41] << 8)
2074 | (mask_m[42] << 6) | (mask_m[43] << 4)
2075 | (mask_m[44] << 2) | (mask_m[45] << 0);
2076 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
2077 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
2078
2079 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
2080 | (mask_m[18] << 26) | (mask_m[18] << 24)
2081 | (mask_m[20] << 22) | (mask_m[20] << 20)
2082 | (mask_m[22] << 18) | (mask_m[22] << 16)
2083 | (mask_m[24] << 14) | (mask_m[24] << 12)
2084 | (mask_m[25] << 10) | (mask_m[26] << 8)
2085 | (mask_m[27] << 6) | (mask_m[28] << 4)
2086 | (mask_m[29] << 2) | (mask_m[30] << 0);
2087 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
2088 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
2089
2090 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
2091 | (mask_m[2] << 26) | (mask_m[3] << 24)
2092 | (mask_m[4] << 22) | (mask_m[5] << 20)
2093 | (mask_m[6] << 18) | (mask_m[7] << 16)
2094 | (mask_m[8] << 14) | (mask_m[9] << 12)
2095 | (mask_m[10] << 10) | (mask_m[11] << 8)
2096 | (mask_m[12] << 6) | (mask_m[13] << 4)
2097 | (mask_m[14] << 2) | (mask_m[15] << 0);
2098 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
2099 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
2100
2101 tmp_mask = (mask_p[15] << 28)
2102 | (mask_p[14] << 26) | (mask_p[13] << 24)
2103 | (mask_p[12] << 22) | (mask_p[11] << 20)
2104 | (mask_p[10] << 18) | (mask_p[9] << 16)
2105 | (mask_p[8] << 14) | (mask_p[7] << 12)
2106 | (mask_p[6] << 10) | (mask_p[5] << 8)
2107 | (mask_p[4] << 6) | (mask_p[3] << 4)
2108 | (mask_p[2] << 2) | (mask_p[1] << 0);
2109 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
2110 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
2111
2112 tmp_mask = (mask_p[30] << 28)
2113 | (mask_p[29] << 26) | (mask_p[28] << 24)
2114 | (mask_p[27] << 22) | (mask_p[26] << 20)
2115 | (mask_p[25] << 18) | (mask_p[24] << 16)
2116 | (mask_p[23] << 14) | (mask_p[22] << 12)
2117 | (mask_p[21] << 10) | (mask_p[20] << 8)
2118 | (mask_p[19] << 6) | (mask_p[18] << 4)
2119 | (mask_p[17] << 2) | (mask_p[16] << 0);
2120 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
2121 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
2122
2123 tmp_mask = (mask_p[45] << 28)
2124 | (mask_p[44] << 26) | (mask_p[43] << 24)
2125 | (mask_p[42] << 22) | (mask_p[41] << 20)
2126 | (mask_p[40] << 18) | (mask_p[39] << 16)
2127 | (mask_p[38] << 14) | (mask_p[37] << 12)
2128 | (mask_p[36] << 10) | (mask_p[35] << 8)
2129 | (mask_p[34] << 6) | (mask_p[33] << 4)
2130 | (mask_p[32] << 2) | (mask_p[31] << 0);
2131 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
2132 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
2133
2134 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
2135 | (mask_p[59] << 26) | (mask_p[58] << 24)
2136 | (mask_p[57] << 22) | (mask_p[56] << 20)
2137 | (mask_p[55] << 18) | (mask_p[54] << 16)
2138 | (mask_p[53] << 14) | (mask_p[52] << 12)
2139 | (mask_p[51] << 10) | (mask_p[50] << 8)
2140 | (mask_p[49] << 6) | (mask_p[48] << 4)
2141 | (mask_p[47] << 2) | (mask_p[46] << 0);
2142 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
2143 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
2144}
2145
Sujithcbe61d82009-02-09 13:27:12 +05302146static void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002147{
2148 int bb_spur = AR_NO_SPUR;
2149 int bin, cur_bin;
2150 int spur_freq_sd;
2151 int spur_delta_phase;
2152 int denominator;
2153 int upper, lower, cur_vit_mask;
2154 int tmp, new;
2155 int i;
2156 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
2157 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
2158 };
2159 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
2160 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
2161 };
2162 int inc[4] = { 0, 100, 0, 0 };
2163
2164 int8_t mask_m[123];
2165 int8_t mask_p[123];
2166 int8_t mask_amt;
2167 int tmp_mask;
2168 int cur_bb_spur;
2169 bool is2GHz = IS_CHAN_2GHZ(chan);
2170
2171 memset(&mask_m, 0, sizeof(int8_t) * 123);
2172 memset(&mask_p, 0, sizeof(int8_t) * 123);
2173
2174 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujithf74df6f2009-02-09 13:27:24 +05302175 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002176 if (AR_NO_SPUR == cur_bb_spur)
2177 break;
2178 cur_bb_spur = cur_bb_spur - (chan->channel * 10);
2179 if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) {
2180 bb_spur = cur_bb_spur;
2181 break;
2182 }
2183 }
2184
2185 if (AR_NO_SPUR == bb_spur)
2186 return;
2187
2188 bin = bb_spur * 32;
2189
2190 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
2191 new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
2192 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
2193 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
2194 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
2195
2196 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new);
2197
2198 new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
2199 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
2200 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
2201 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
2202 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
2203 REG_WRITE(ah, AR_PHY_SPUR_REG, new);
2204
2205 spur_delta_phase = ((bb_spur * 524288) / 100) &
2206 AR_PHY_TIMING11_SPUR_DELTA_PHASE;
2207
2208 denominator = IS_CHAN_2GHZ(chan) ? 440 : 400;
2209 spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff;
2210
2211 new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
2212 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
2213 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
2214 REG_WRITE(ah, AR_PHY_TIMING11, new);
2215
2216 cur_bin = -6000;
2217 upper = bin + 100;
2218 lower = bin - 100;
2219
2220 for (i = 0; i < 4; i++) {
2221 int pilot_mask = 0;
2222 int chan_mask = 0;
2223 int bp = 0;
2224 for (bp = 0; bp < 30; bp++) {
2225 if ((cur_bin > lower) && (cur_bin < upper)) {
2226 pilot_mask = pilot_mask | 0x1 << bp;
2227 chan_mask = chan_mask | 0x1 << bp;
2228 }
2229 cur_bin += 100;
2230 }
2231 cur_bin += inc[i];
2232 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
2233 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
2234 }
2235
2236 cur_vit_mask = 6100;
2237 upper = bin + 120;
2238 lower = bin - 120;
2239
2240 for (i = 0; i < 123; i++) {
2241 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
Adrian Bunk88b9e2b2008-08-05 22:06:51 +03002242
2243 /* workaround for gcc bug #37014 */
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002244 volatile int tmp_v = abs(cur_vit_mask - bin);
Adrian Bunk88b9e2b2008-08-05 22:06:51 +03002245
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002246 if (tmp_v < 75)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002247 mask_amt = 1;
2248 else
2249 mask_amt = 0;
2250 if (cur_vit_mask < 0)
2251 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
2252 else
2253 mask_p[cur_vit_mask / 100] = mask_amt;
2254 }
2255 cur_vit_mask -= 100;
2256 }
2257
2258 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
2259 | (mask_m[48] << 26) | (mask_m[49] << 24)
2260 | (mask_m[50] << 22) | (mask_m[51] << 20)
2261 | (mask_m[52] << 18) | (mask_m[53] << 16)
2262 | (mask_m[54] << 14) | (mask_m[55] << 12)
2263 | (mask_m[56] << 10) | (mask_m[57] << 8)
2264 | (mask_m[58] << 6) | (mask_m[59] << 4)
2265 | (mask_m[60] << 2) | (mask_m[61] << 0);
2266 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
2267 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
2268
2269 tmp_mask = (mask_m[31] << 28)
2270 | (mask_m[32] << 26) | (mask_m[33] << 24)
2271 | (mask_m[34] << 22) | (mask_m[35] << 20)
2272 | (mask_m[36] << 18) | (mask_m[37] << 16)
2273 | (mask_m[48] << 14) | (mask_m[39] << 12)
2274 | (mask_m[40] << 10) | (mask_m[41] << 8)
2275 | (mask_m[42] << 6) | (mask_m[43] << 4)
2276 | (mask_m[44] << 2) | (mask_m[45] << 0);
2277 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
2278 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
2279
2280 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
2281 | (mask_m[18] << 26) | (mask_m[18] << 24)
2282 | (mask_m[20] << 22) | (mask_m[20] << 20)
2283 | (mask_m[22] << 18) | (mask_m[22] << 16)
2284 | (mask_m[24] << 14) | (mask_m[24] << 12)
2285 | (mask_m[25] << 10) | (mask_m[26] << 8)
2286 | (mask_m[27] << 6) | (mask_m[28] << 4)
2287 | (mask_m[29] << 2) | (mask_m[30] << 0);
2288 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
2289 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
2290
2291 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
2292 | (mask_m[2] << 26) | (mask_m[3] << 24)
2293 | (mask_m[4] << 22) | (mask_m[5] << 20)
2294 | (mask_m[6] << 18) | (mask_m[7] << 16)
2295 | (mask_m[8] << 14) | (mask_m[9] << 12)
2296 | (mask_m[10] << 10) | (mask_m[11] << 8)
2297 | (mask_m[12] << 6) | (mask_m[13] << 4)
2298 | (mask_m[14] << 2) | (mask_m[15] << 0);
2299 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
2300 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
2301
2302 tmp_mask = (mask_p[15] << 28)
2303 | (mask_p[14] << 26) | (mask_p[13] << 24)
2304 | (mask_p[12] << 22) | (mask_p[11] << 20)
2305 | (mask_p[10] << 18) | (mask_p[9] << 16)
2306 | (mask_p[8] << 14) | (mask_p[7] << 12)
2307 | (mask_p[6] << 10) | (mask_p[5] << 8)
2308 | (mask_p[4] << 6) | (mask_p[3] << 4)
2309 | (mask_p[2] << 2) | (mask_p[1] << 0);
2310 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
2311 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
2312
2313 tmp_mask = (mask_p[30] << 28)
2314 | (mask_p[29] << 26) | (mask_p[28] << 24)
2315 | (mask_p[27] << 22) | (mask_p[26] << 20)
2316 | (mask_p[25] << 18) | (mask_p[24] << 16)
2317 | (mask_p[23] << 14) | (mask_p[22] << 12)
2318 | (mask_p[21] << 10) | (mask_p[20] << 8)
2319 | (mask_p[19] << 6) | (mask_p[18] << 4)
2320 | (mask_p[17] << 2) | (mask_p[16] << 0);
2321 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
2322 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
2323
2324 tmp_mask = (mask_p[45] << 28)
2325 | (mask_p[44] << 26) | (mask_p[43] << 24)
2326 | (mask_p[42] << 22) | (mask_p[41] << 20)
2327 | (mask_p[40] << 18) | (mask_p[39] << 16)
2328 | (mask_p[38] << 14) | (mask_p[37] << 12)
2329 | (mask_p[36] << 10) | (mask_p[35] << 8)
2330 | (mask_p[34] << 6) | (mask_p[33] << 4)
2331 | (mask_p[32] << 2) | (mask_p[31] << 0);
2332 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
2333 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
2334
2335 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
2336 | (mask_p[59] << 26) | (mask_p[58] << 24)
2337 | (mask_p[57] << 22) | (mask_p[56] << 20)
2338 | (mask_p[55] << 18) | (mask_p[54] << 16)
2339 | (mask_p[53] << 14) | (mask_p[52] << 12)
2340 | (mask_p[51] << 10) | (mask_p[50] << 8)
2341 | (mask_p[49] << 6) | (mask_p[48] << 4)
2342 | (mask_p[47] << 2) | (mask_p[46] << 0);
2343 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
2344 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
2345}
2346
Johannes Berg3b319aa2009-06-13 14:50:26 +05302347static void ath9k_enable_rfkill(struct ath_hw *ah)
2348{
2349 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
2350 AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
2351
2352 REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2,
2353 AR_GPIO_INPUT_MUX2_RFSILENT);
2354
2355 ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
2356 REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);
2357}
2358
Sujithcbe61d82009-02-09 13:27:12 +05302359int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002360 bool bChannelChange)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002361{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002362 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002363 u32 saveLedState;
Sujith2660b812009-02-09 13:27:26 +05302364 struct ath9k_channel *curchan = ah->curchan;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002365 u32 saveDefAntenna;
2366 u32 macStaId1;
Sujith46fe7822009-09-17 09:25:25 +05302367 u64 tsf = 0;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002368 int i, rx_chainmask, r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002369
Luis R. Rodriguez43c27612009-09-13 21:07:07 -07002370 ah->txchainmask = common->tx_chainmask;
2371 ah->rxchainmask = common->rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002372
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002373 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002374 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002375
Vasanthakumar Thiagarajan9ebef7992009-09-17 09:26:44 +05302376 if (curchan && !ah->chip_fullsleep)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002377 ath9k_hw_getnf(ah, curchan);
2378
2379 if (bChannelChange &&
Sujith2660b812009-02-09 13:27:26 +05302380 (ah->chip_fullsleep != true) &&
2381 (ah->curchan != NULL) &&
2382 (chan->channel != ah->curchan->channel) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002383 ((chan->channelFlags & CHANNEL_ALL) ==
Sujith2660b812009-02-09 13:27:26 +05302384 (ah->curchan->channelFlags & CHANNEL_ALL)) &&
Vasanthakumar Thiagarajan0a475cc2009-09-17 09:27:10 +05302385 !(AR_SREV_9280(ah) || IS_CHAN_A_5MHZ_SPACED(chan) ||
2386 IS_CHAN_A_5MHZ_SPACED(ah->curchan))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002387
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002388 if (ath9k_hw_channel_change(ah, chan)) {
Sujith2660b812009-02-09 13:27:26 +05302389 ath9k_hw_loadnf(ah, ah->curchan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002390 ath9k_hw_start_nfcal(ah);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002391 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002392 }
2393 }
2394
2395 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
2396 if (saveDefAntenna == 0)
2397 saveDefAntenna = 1;
2398
2399 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
2400
Sujith46fe7822009-09-17 09:25:25 +05302401 /* For chips on which RTC reset is done, save TSF before it gets cleared */
2402 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
2403 tsf = ath9k_hw_gettsf64(ah);
2404
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002405 saveLedState = REG_READ(ah, AR_CFG_LED) &
2406 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
2407 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
2408
2409 ath9k_hw_mark_phy_inactive(ah);
2410
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002411 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
2412 REG_WRITE(ah,
2413 AR9271_RESET_POWER_DOWN_CONTROL,
2414 AR9271_RADIO_RF_RST);
2415 udelay(50);
2416 }
2417
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002418 if (!ath9k_hw_chip_reset(ah, chan)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002419 ath_print(common, ATH_DBG_FATAL, "Chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002420 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002421 }
2422
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002423 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
2424 ah->htc_reset_init = false;
2425 REG_WRITE(ah,
2426 AR9271_RESET_POWER_DOWN_CONTROL,
2427 AR9271_GATE_MAC_CTL);
2428 udelay(50);
2429 }
2430
Sujith46fe7822009-09-17 09:25:25 +05302431 /* Restore TSF */
2432 if (tsf && AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
2433 ath9k_hw_settsf64(ah, tsf);
2434
Vasanthakumar Thiagarajan369391d2009-01-21 19:24:13 +05302435 if (AR_SREV_9280_10_OR_LATER(ah))
2436 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002437
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302438 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302439 /* Enable ASYNC FIFO */
2440 REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2441 AR_MAC_PCU_ASYNC_FIFO_REG3_DATAPATH_SEL);
2442 REG_SET_BIT(ah, AR_PHY_MODE, AR_PHY_MODE_ASYNCFIFO);
2443 REG_CLR_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2444 AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
2445 REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2446 AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
2447 }
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002448 r = ath9k_hw_process_ini(ah, chan);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002449 if (r)
2450 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002451
Jouni Malinen0ced0e12009-01-08 13:32:13 +02002452 /* Setup MFP options for CCMP */
2453 if (AR_SREV_9280_20_OR_LATER(ah)) {
2454 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
2455 * frames when constructing CCMP AAD. */
2456 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
2457 0xc7ff);
2458 ah->sw_mgmt_crypto = false;
2459 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
2460 /* Disable hardware crypto for management frames */
2461 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
2462 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
2463 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
2464 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
2465 ah->sw_mgmt_crypto = true;
2466 } else
2467 ah->sw_mgmt_crypto = true;
2468
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002469 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
2470 ath9k_hw_set_delta_slope(ah, chan);
2471
2472 if (AR_SREV_9280_10_OR_LATER(ah))
2473 ath9k_hw_9280_spur_mitigate(ah, chan);
2474 else
2475 ath9k_hw_spur_mitigate(ah, chan);
2476
Sujithd6509152009-03-13 08:56:05 +05302477 ah->eep_ops->set_board_values(ah, chan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002478
2479 ath9k_hw_decrease_chain_power(ah, chan);
2480
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002481 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
2482 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002483 | macStaId1
2484 | AR_STA_ID1_RTS_USE_DEF
Sujith2660b812009-02-09 13:27:26 +05302485 | (ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302486 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Sujith2660b812009-02-09 13:27:26 +05302487 | ah->sta_id1_defaults);
2488 ath9k_hw_set_operating_mode(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002489
Luis R. Rodriguez13b81552009-09-10 17:52:45 -07002490 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002491
2492 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
2493
Luis R. Rodriguez3453ad82009-09-10 08:57:00 -07002494 ath9k_hw_write_associd(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002495
2496 REG_WRITE(ah, AR_ISR, ~0);
2497
2498 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
2499
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07002500 if (AR_SREV_9280_10_OR_LATER(ah))
2501 ath9k_hw_ar9280_set_channel(ah, chan);
2502 else
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002503 if (!(ath9k_hw_set_channel(ah, chan)))
2504 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002505
2506 for (i = 0; i < AR_NUM_DCU; i++)
2507 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
2508
Sujith2660b812009-02-09 13:27:26 +05302509 ah->intr_txqs = 0;
2510 for (i = 0; i < ah->caps.total_queues; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002511 ath9k_hw_resettxqueue(ah, i);
2512
Sujith2660b812009-02-09 13:27:26 +05302513 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002514 ath9k_hw_init_qos(ah);
2515
Sujith2660b812009-02-09 13:27:26 +05302516 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05302517 ath9k_enable_rfkill(ah);
Johannes Berg3b319aa2009-06-13 14:50:26 +05302518
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002519 ath9k_hw_init_user_settings(ah);
2520
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302521 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302522 REG_WRITE(ah, AR_D_GBL_IFS_SIFS,
2523 AR_D_GBL_IFS_SIFS_ASYNC_FIFO_DUR);
2524 REG_WRITE(ah, AR_D_GBL_IFS_SLOT,
2525 AR_D_GBL_IFS_SLOT_ASYNC_FIFO_DUR);
2526 REG_WRITE(ah, AR_D_GBL_IFS_EIFS,
2527 AR_D_GBL_IFS_EIFS_ASYNC_FIFO_DUR);
2528
2529 REG_WRITE(ah, AR_TIME_OUT, AR_TIME_OUT_ACK_CTS_ASYNC_FIFO_DUR);
2530 REG_WRITE(ah, AR_USEC, AR_USEC_ASYNC_FIFO_DUR);
2531
2532 REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
2533 AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
2534 REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
2535 AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
2536 }
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302537 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302538 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
2539 AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
2540 }
2541
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002542 REG_WRITE(ah, AR_STA_ID1,
2543 REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
2544
2545 ath9k_hw_set_dma(ah);
2546
2547 REG_WRITE(ah, AR_OBS, 8);
2548
Sujith0ef1f162009-03-30 15:28:35 +05302549 if (ah->config.intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002550 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
2551 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
2552 }
2553
2554 ath9k_hw_init_bb(ah, chan);
2555
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002556 if (!ath9k_hw_init_cal(ah, chan))
Joe Perches6badaaf2009-06-28 09:26:32 -07002557 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002558
Sujith2660b812009-02-09 13:27:26 +05302559 rx_chainmask = ah->rxchainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002560 if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) {
2561 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
2562 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
2563 }
2564
2565 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
2566
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002567 /*
2568 * For big endian systems turn on swapping for descriptors
2569 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002570 if (AR_SREV_9100(ah)) {
2571 u32 mask;
2572 mask = REG_READ(ah, AR_CFG);
2573 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002574 ath_print(common, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05302575 "CFG Byte Swap Set 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002576 } else {
2577 mask =
2578 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
2579 REG_WRITE(ah, AR_CFG, mask);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002580 ath_print(common, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05302581 "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002582 }
2583 } else {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002584 /* Configure AR9271 target WLAN */
2585 if (AR_SREV_9271(ah))
2586 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002587#ifdef __BIG_ENDIAN
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002588 else
2589 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002590#endif
2591 }
2592
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002593 if (ah->btcoex_hw.enabled)
Vasanthakumar Thiagarajan42cc41e2009-08-26 21:08:45 +05302594 ath9k_hw_btcoex_enable(ah);
2595
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002596 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002597}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002598EXPORT_SYMBOL(ath9k_hw_reset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002599
Sujithf1dc5602008-10-29 10:16:30 +05302600/************************/
2601/* Key Cache Management */
2602/************************/
2603
Sujithcbe61d82009-02-09 13:27:12 +05302604bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002605{
Sujithf1dc5602008-10-29 10:16:30 +05302606 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002607
Sujith2660b812009-02-09 13:27:26 +05302608 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002609 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2610 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002611 return false;
2612 }
2613
Sujithf1dc5602008-10-29 10:16:30 +05302614 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002615
Sujithf1dc5602008-10-29 10:16:30 +05302616 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
2617 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
2618 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
2619 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
2620 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
2621 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
2622 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
2623 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
2624
2625 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2626 u16 micentry = entry + 64;
2627
2628 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
2629 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
2630 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
2631 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
2632
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002633 }
2634
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002635 return true;
2636}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002637EXPORT_SYMBOL(ath9k_hw_keyreset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002638
Sujithcbe61d82009-02-09 13:27:12 +05302639bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002640{
Sujithf1dc5602008-10-29 10:16:30 +05302641 u32 macHi, macLo;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002642
Sujith2660b812009-02-09 13:27:26 +05302643 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002644 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2645 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002646 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002647 }
2648
Sujithf1dc5602008-10-29 10:16:30 +05302649 if (mac != NULL) {
2650 macHi = (mac[5] << 8) | mac[4];
2651 macLo = (mac[3] << 24) |
2652 (mac[2] << 16) |
2653 (mac[1] << 8) |
2654 mac[0];
2655 macLo >>= 1;
2656 macLo |= (macHi & 1) << 31;
2657 macHi >>= 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002658 } else {
Sujithf1dc5602008-10-29 10:16:30 +05302659 macLo = macHi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002660 }
Sujithf1dc5602008-10-29 10:16:30 +05302661 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
2662 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002663
2664 return true;
2665}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002666EXPORT_SYMBOL(ath9k_hw_keysetmac);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002667
Sujithcbe61d82009-02-09 13:27:12 +05302668bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
Sujithf1dc5602008-10-29 10:16:30 +05302669 const struct ath9k_keyval *k,
Jouni Malinene0caf9e2009-03-02 18:15:53 +02002670 const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002671{
Sujith2660b812009-02-09 13:27:26 +05302672 const struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002673 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302674 u32 key0, key1, key2, key3, key4;
2675 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002676
Sujithf1dc5602008-10-29 10:16:30 +05302677 if (entry >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002678 ath_print(common, ATH_DBG_FATAL,
2679 "keycache entry %u out of range\n", entry);
Sujithf1dc5602008-10-29 10:16:30 +05302680 return false;
2681 }
2682
2683 switch (k->kv_type) {
2684 case ATH9K_CIPHER_AES_OCB:
2685 keyType = AR_KEYTABLE_TYPE_AES;
2686 break;
2687 case ATH9K_CIPHER_AES_CCM:
2688 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002689 ath_print(common, ATH_DBG_ANY,
2690 "AES-CCM not supported by mac rev 0x%x\n",
2691 ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002692 return false;
2693 }
Sujithf1dc5602008-10-29 10:16:30 +05302694 keyType = AR_KEYTABLE_TYPE_CCM;
2695 break;
2696 case ATH9K_CIPHER_TKIP:
2697 keyType = AR_KEYTABLE_TYPE_TKIP;
2698 if (ATH9K_IS_MIC_ENABLED(ah)
2699 && entry + 64 >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002700 ath_print(common, ATH_DBG_ANY,
2701 "entry %u inappropriate for TKIP\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002702 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002703 }
Sujithf1dc5602008-10-29 10:16:30 +05302704 break;
2705 case ATH9K_CIPHER_WEP:
Zhu Yie31a16d2009-05-21 21:47:03 +08002706 if (k->kv_len < WLAN_KEY_LEN_WEP40) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002707 ath_print(common, ATH_DBG_ANY,
2708 "WEP key length %u too small\n", k->kv_len);
Sujithf1dc5602008-10-29 10:16:30 +05302709 return false;
2710 }
Zhu Yie31a16d2009-05-21 21:47:03 +08002711 if (k->kv_len <= WLAN_KEY_LEN_WEP40)
Sujithf1dc5602008-10-29 10:16:30 +05302712 keyType = AR_KEYTABLE_TYPE_40;
Zhu Yie31a16d2009-05-21 21:47:03 +08002713 else if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05302714 keyType = AR_KEYTABLE_TYPE_104;
2715 else
2716 keyType = AR_KEYTABLE_TYPE_128;
2717 break;
2718 case ATH9K_CIPHER_CLR:
2719 keyType = AR_KEYTABLE_TYPE_CLR;
2720 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002721 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002722 ath_print(common, ATH_DBG_FATAL,
2723 "cipher %u not supported\n", k->kv_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002724 return false;
2725 }
Sujithf1dc5602008-10-29 10:16:30 +05302726
Jouni Malinene0caf9e2009-03-02 18:15:53 +02002727 key0 = get_unaligned_le32(k->kv_val + 0);
2728 key1 = get_unaligned_le16(k->kv_val + 4);
2729 key2 = get_unaligned_le32(k->kv_val + 6);
2730 key3 = get_unaligned_le16(k->kv_val + 10);
2731 key4 = get_unaligned_le32(k->kv_val + 12);
Zhu Yie31a16d2009-05-21 21:47:03 +08002732 if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05302733 key4 &= 0xff;
2734
Jouni Malinen672903b2009-03-02 15:06:31 +02002735 /*
2736 * Note: Key cache registers access special memory area that requires
2737 * two 32-bit writes to actually update the values in the internal
2738 * memory. Consequently, the exact order and pairs used here must be
2739 * maintained.
2740 */
2741
Sujithf1dc5602008-10-29 10:16:30 +05302742 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2743 u16 micentry = entry + 64;
2744
Jouni Malinen672903b2009-03-02 15:06:31 +02002745 /*
2746 * Write inverted key[47:0] first to avoid Michael MIC errors
2747 * on frames that could be sent or received at the same time.
2748 * The correct key will be written in the end once everything
2749 * else is ready.
2750 */
Sujithf1dc5602008-10-29 10:16:30 +05302751 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
2752 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002753
2754 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302755 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2756 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002757
2758 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302759 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2760 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
Jouni Malinen672903b2009-03-02 15:06:31 +02002761
2762 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302763 (void) ath9k_hw_keysetmac(ah, entry, mac);
2764
Sujith2660b812009-02-09 13:27:26 +05302765 if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) {
Jouni Malinen672903b2009-03-02 15:06:31 +02002766 /*
2767 * TKIP uses two key cache entries:
2768 * Michael MIC TX/RX keys in the same key cache entry
2769 * (idx = main index + 64):
2770 * key0 [31:0] = RX key [31:0]
2771 * key1 [15:0] = TX key [31:16]
2772 * key1 [31:16] = reserved
2773 * key2 [31:0] = RX key [63:32]
2774 * key3 [15:0] = TX key [15:0]
2775 * key3 [31:16] = reserved
2776 * key4 [31:0] = TX key [63:32]
2777 */
Sujithf1dc5602008-10-29 10:16:30 +05302778 u32 mic0, mic1, mic2, mic3, mic4;
2779
2780 mic0 = get_unaligned_le32(k->kv_mic + 0);
2781 mic2 = get_unaligned_le32(k->kv_mic + 4);
2782 mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
2783 mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
2784 mic4 = get_unaligned_le32(k->kv_txmic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02002785
2786 /* Write RX[31:0] and TX[31:16] */
Sujithf1dc5602008-10-29 10:16:30 +05302787 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2788 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002789
2790 /* Write RX[63:32] and TX[15:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302791 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2792 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002793
2794 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302795 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
2796 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2797 AR_KEYTABLE_TYPE_CLR);
2798
2799 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002800 /*
2801 * TKIP uses four key cache entries (two for group
2802 * keys):
2803 * Michael MIC TX/RX keys are in different key cache
2804 * entries (idx = main index + 64 for TX and
2805 * main index + 32 + 96 for RX):
2806 * key0 [31:0] = TX/RX MIC key [31:0]
2807 * key1 [31:0] = reserved
2808 * key2 [31:0] = TX/RX MIC key [63:32]
2809 * key3 [31:0] = reserved
2810 * key4 [31:0] = reserved
2811 *
2812 * Upper layer code will call this function separately
2813 * for TX and RX keys when these registers offsets are
2814 * used.
2815 */
Sujithf1dc5602008-10-29 10:16:30 +05302816 u32 mic0, mic2;
2817
2818 mic0 = get_unaligned_le32(k->kv_mic + 0);
2819 mic2 = get_unaligned_le32(k->kv_mic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02002820
2821 /* Write MIC key[31:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302822 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2823 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002824
2825 /* Write MIC key[63:32] */
Sujithf1dc5602008-10-29 10:16:30 +05302826 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2827 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002828
2829 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302830 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
2831 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2832 AR_KEYTABLE_TYPE_CLR);
2833 }
Jouni Malinen672903b2009-03-02 15:06:31 +02002834
2835 /* MAC address registers are reserved for the MIC entry */
Sujithf1dc5602008-10-29 10:16:30 +05302836 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
2837 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002838
2839 /*
2840 * Write the correct (un-inverted) key[47:0] last to enable
2841 * TKIP now that all other registers are set with correct
2842 * values.
2843 */
Sujithf1dc5602008-10-29 10:16:30 +05302844 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2845 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
2846 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002847 /* Write key[47:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302848 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2849 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002850
2851 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302852 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2853 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002854
2855 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302856 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2857 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
2858
Jouni Malinen672903b2009-03-02 15:06:31 +02002859 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302860 (void) ath9k_hw_keysetmac(ah, entry, mac);
2861 }
2862
Sujithf1dc5602008-10-29 10:16:30 +05302863 return true;
2864}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002865EXPORT_SYMBOL(ath9k_hw_set_keycache_entry);
Sujithf1dc5602008-10-29 10:16:30 +05302866
Sujithcbe61d82009-02-09 13:27:12 +05302867bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry)
Sujithf1dc5602008-10-29 10:16:30 +05302868{
Sujith2660b812009-02-09 13:27:26 +05302869 if (entry < ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05302870 u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
2871 if (val & AR_KEYTABLE_VALID)
2872 return true;
2873 }
2874 return false;
2875}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002876EXPORT_SYMBOL(ath9k_hw_keyisvalid);
Sujithf1dc5602008-10-29 10:16:30 +05302877
2878/******************************/
2879/* Power Management (Chipset) */
2880/******************************/
2881
Sujithcbe61d82009-02-09 13:27:12 +05302882static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302883{
2884 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2885 if (setChip) {
2886 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2887 AR_RTC_FORCE_WAKE_EN);
2888 if (!AR_SREV_9100(ah))
2889 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
2890
Sujith4921be82009-09-18 15:04:27 +05302891 if(!AR_SREV_5416(ah))
2892 REG_CLR_BIT(ah, (AR_RTC_RESET),
2893 AR_RTC_RESET_EN);
Sujithf1dc5602008-10-29 10:16:30 +05302894 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002895}
2896
Sujithcbe61d82009-02-09 13:27:12 +05302897static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002898{
Sujithf1dc5602008-10-29 10:16:30 +05302899 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2900 if (setChip) {
Sujith2660b812009-02-09 13:27:26 +05302901 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002902
Sujithf1dc5602008-10-29 10:16:30 +05302903 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
2904 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2905 AR_RTC_FORCE_WAKE_ON_INT);
2906 } else {
2907 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2908 AR_RTC_FORCE_WAKE_EN);
2909 }
2910 }
2911}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002912
Sujithcbe61d82009-02-09 13:27:12 +05302913static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302914{
2915 u32 val;
2916 int i;
2917
2918 if (setChip) {
2919 if ((REG_READ(ah, AR_RTC_STATUS) &
2920 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2921 if (ath9k_hw_set_reset_reg(ah,
2922 ATH9K_RESET_POWER_ON) != true) {
2923 return false;
2924 }
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05302925 ath9k_hw_init_pll(ah, NULL);
Sujithf1dc5602008-10-29 10:16:30 +05302926 }
2927 if (AR_SREV_9100(ah))
2928 REG_SET_BIT(ah, AR_RTC_RESET,
2929 AR_RTC_RESET_EN);
2930
2931 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2932 AR_RTC_FORCE_WAKE_EN);
2933 udelay(50);
2934
2935 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2936 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2937 if (val == AR_RTC_STATUS_ON)
2938 break;
2939 udelay(50);
2940 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2941 AR_RTC_FORCE_WAKE_EN);
2942 }
2943 if (i == 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002944 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2945 "Failed to wakeup in %uus\n",
2946 POWER_UP_TIME / 20);
Sujithf1dc5602008-10-29 10:16:30 +05302947 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002948 }
2949 }
2950
Sujithf1dc5602008-10-29 10:16:30 +05302951 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2952
2953 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002954}
2955
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002956bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05302957{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002958 struct ath_common *common = ath9k_hw_common(ah);
Sujithcbe61d82009-02-09 13:27:12 +05302959 int status = true, setChip = true;
Sujithf1dc5602008-10-29 10:16:30 +05302960 static const char *modes[] = {
2961 "AWAKE",
2962 "FULL-SLEEP",
2963 "NETWORK SLEEP",
2964 "UNDEFINED"
2965 };
Sujithf1dc5602008-10-29 10:16:30 +05302966
Gabor Juhoscbdec972009-07-24 17:27:22 +02002967 if (ah->power_mode == mode)
2968 return status;
2969
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002970 ath_print(common, ATH_DBG_RESET, "%s -> %s\n",
2971 modes[ah->power_mode], modes[mode]);
Sujithf1dc5602008-10-29 10:16:30 +05302972
2973 switch (mode) {
2974 case ATH9K_PM_AWAKE:
2975 status = ath9k_hw_set_power_awake(ah, setChip);
2976 break;
2977 case ATH9K_PM_FULL_SLEEP:
2978 ath9k_set_power_sleep(ah, setChip);
Sujith2660b812009-02-09 13:27:26 +05302979 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05302980 break;
2981 case ATH9K_PM_NETWORK_SLEEP:
2982 ath9k_set_power_network_sleep(ah, setChip);
2983 break;
2984 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002985 ath_print(common, ATH_DBG_FATAL,
2986 "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05302987 return false;
2988 }
Sujith2660b812009-02-09 13:27:26 +05302989 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05302990
2991 return status;
2992}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002993EXPORT_SYMBOL(ath9k_hw_setpower);
Sujithf1dc5602008-10-29 10:16:30 +05302994
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002995/*
2996 * Helper for ASPM support.
2997 *
2998 * Disable PLL when in L0s as well as receiver clock when in L1.
2999 * This power saving option must be enabled through the SerDes.
3000 *
3001 * Programming the SerDes must go through the same 288 bit serial shift
3002 * register as the other analog registers. Hence the 9 writes.
3003 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303004void ath9k_hw_configpcipowersave(struct ath_hw *ah, int restore, int power_off)
Sujithf1dc5602008-10-29 10:16:30 +05303005{
Sujithf1dc5602008-10-29 10:16:30 +05303006 u8 i;
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303007 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05303008
Sujith2660b812009-02-09 13:27:26 +05303009 if (ah->is_pciexpress != true)
Sujithf1dc5602008-10-29 10:16:30 +05303010 return;
3011
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08003012 /* Do not touch SerDes registers */
Sujith2660b812009-02-09 13:27:26 +05303013 if (ah->config.pcie_powersave_enable == 2)
Sujithf1dc5602008-10-29 10:16:30 +05303014 return;
3015
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08003016 /* Nothing to do on restore for 11N */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303017 if (!restore) {
3018 if (AR_SREV_9280_20_OR_LATER(ah)) {
3019 /*
3020 * AR9280 2.0 or later chips use SerDes values from the
3021 * initvals.h initialized depending on chipset during
3022 * ath9k_hw_init()
3023 */
3024 for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
3025 REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
3026 INI_RA(&ah->iniPcieSerdes, i, 1));
3027 }
3028 } else if (AR_SREV_9280(ah) &&
3029 (ah->hw_version.macRev == AR_SREV_REVISION_9280_10)) {
3030 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
3031 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
Sujithf1dc5602008-10-29 10:16:30 +05303032
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303033 /* RX shut off when elecidle is asserted */
3034 REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
3035 REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
3036 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
3037
3038 /* Shut off CLKREQ active in L1 */
3039 if (ah->config.pcie_clock_req)
3040 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
3041 else
3042 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
3043
3044 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
3045 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
3046 REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
3047
3048 /* Load the new settings */
3049 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
3050
3051 } else {
3052 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
3053 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
3054
3055 /* RX shut off when elecidle is asserted */
3056 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
3057 REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
3058 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
3059
3060 /*
3061 * Ignore ah->ah_config.pcie_clock_req setting for
3062 * pre-AR9280 11n
3063 */
3064 REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
3065
3066 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
3067 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
3068 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
3069
3070 /* Load the new settings */
3071 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
Sujithf1dc5602008-10-29 10:16:30 +05303072 }
Sujithf1dc5602008-10-29 10:16:30 +05303073
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303074 udelay(1000);
Sujithf1dc5602008-10-29 10:16:30 +05303075
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303076 /* set bit 19 to allow forcing of pcie core into L1 state */
3077 REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
Sujithf1dc5602008-10-29 10:16:30 +05303078
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303079 /* Several PCIe massages to ensure proper behaviour */
3080 if (ah->config.pcie_waen) {
3081 val = ah->config.pcie_waen;
3082 if (!power_off)
3083 val &= (~AR_WA_D3_L1_DISABLE);
3084 } else {
3085 if (AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
3086 AR_SREV_9287(ah)) {
3087 val = AR9285_WA_DEFAULT;
3088 if (!power_off)
3089 val &= (~AR_WA_D3_L1_DISABLE);
3090 } else if (AR_SREV_9280(ah)) {
3091 /*
3092 * On AR9280 chips bit 22 of 0x4004 needs to be
3093 * set otherwise card may disappear.
3094 */
3095 val = AR9280_WA_DEFAULT;
3096 if (!power_off)
3097 val &= (~AR_WA_D3_L1_DISABLE);
3098 } else
3099 val = AR_WA_DEFAULT;
3100 }
Sujithf1dc5602008-10-29 10:16:30 +05303101
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303102 REG_WRITE(ah, AR_WA, val);
Sujithf1dc5602008-10-29 10:16:30 +05303103 }
3104
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303105 if (power_off) {
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08003106 /*
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303107 * Set PCIe workaround bits
3108 * bit 14 in WA register (disable L1) should only
3109 * be set when device enters D3 and be cleared
3110 * when device comes back to D0.
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08003111 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303112 if (ah->config.pcie_waen) {
3113 if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE)
3114 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
3115 } else {
3116 if (((AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
3117 AR_SREV_9287(ah)) &&
3118 (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)) ||
3119 (AR_SREV_9280(ah) &&
3120 (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE))) {
3121 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
3122 }
3123 }
Sujithf1dc5602008-10-29 10:16:30 +05303124 }
3125}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003126EXPORT_SYMBOL(ath9k_hw_configpcipowersave);
Sujithf1dc5602008-10-29 10:16:30 +05303127
3128/**********************/
3129/* Interrupt Handling */
3130/**********************/
3131
Sujithcbe61d82009-02-09 13:27:12 +05303132bool ath9k_hw_intrpend(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003133{
3134 u32 host_isr;
3135
3136 if (AR_SREV_9100(ah))
3137 return true;
3138
3139 host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
3140 if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
3141 return true;
3142
3143 host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
3144 if ((host_isr & AR_INTR_SYNC_DEFAULT)
3145 && (host_isr != AR_INTR_SPURIOUS))
3146 return true;
3147
3148 return false;
3149}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003150EXPORT_SYMBOL(ath9k_hw_intrpend);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003151
Sujithcbe61d82009-02-09 13:27:12 +05303152bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003153{
3154 u32 isr = 0;
3155 u32 mask2 = 0;
Sujith2660b812009-02-09 13:27:26 +05303156 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003157 u32 sync_cause = 0;
3158 bool fatal_int = false;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003159 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003160
3161 if (!AR_SREV_9100(ah)) {
3162 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
3163 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
3164 == AR_RTC_STATUS_ON) {
3165 isr = REG_READ(ah, AR_ISR);
3166 }
3167 }
3168
Sujithf1dc5602008-10-29 10:16:30 +05303169 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
3170 AR_INTR_SYNC_DEFAULT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003171
3172 *masked = 0;
3173
3174 if (!isr && !sync_cause)
3175 return false;
3176 } else {
3177 *masked = 0;
3178 isr = REG_READ(ah, AR_ISR);
3179 }
3180
3181 if (isr) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003182 if (isr & AR_ISR_BCNMISC) {
3183 u32 isr2;
3184 isr2 = REG_READ(ah, AR_ISR_S2);
3185 if (isr2 & AR_ISR_S2_TIM)
3186 mask2 |= ATH9K_INT_TIM;
3187 if (isr2 & AR_ISR_S2_DTIM)
3188 mask2 |= ATH9K_INT_DTIM;
3189 if (isr2 & AR_ISR_S2_DTIMSYNC)
3190 mask2 |= ATH9K_INT_DTIMSYNC;
3191 if (isr2 & (AR_ISR_S2_CABEND))
3192 mask2 |= ATH9K_INT_CABEND;
3193 if (isr2 & AR_ISR_S2_GTT)
3194 mask2 |= ATH9K_INT_GTT;
3195 if (isr2 & AR_ISR_S2_CST)
3196 mask2 |= ATH9K_INT_CST;
Sujith4af9cf42009-02-12 10:06:47 +05303197 if (isr2 & AR_ISR_S2_TSFOOR)
3198 mask2 |= ATH9K_INT_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003199 }
3200
3201 isr = REG_READ(ah, AR_ISR_RAC);
3202 if (isr == 0xffffffff) {
3203 *masked = 0;
3204 return false;
3205 }
3206
3207 *masked = isr & ATH9K_INT_COMMON;
3208
Sujith0ef1f162009-03-30 15:28:35 +05303209 if (ah->config.intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003210 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
3211 *masked |= ATH9K_INT_RX;
3212 }
3213
3214 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
3215 *masked |= ATH9K_INT_RX;
3216 if (isr &
3217 (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
3218 AR_ISR_TXEOL)) {
3219 u32 s0_s, s1_s;
3220
3221 *masked |= ATH9K_INT_TX;
3222
3223 s0_s = REG_READ(ah, AR_ISR_S0_S);
Sujith2660b812009-02-09 13:27:26 +05303224 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
3225 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003226
3227 s1_s = REG_READ(ah, AR_ISR_S1_S);
Sujith2660b812009-02-09 13:27:26 +05303228 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
3229 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003230 }
3231
3232 if (isr & AR_ISR_RXORN) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003233 ath_print(common, ATH_DBG_INTERRUPT,
3234 "receive FIFO overrun interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003235 }
3236
3237 if (!AR_SREV_9100(ah)) {
Sujith60b67f52008-08-07 10:52:38 +05303238 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003239 u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
3240 if (isr5 & AR_ISR_S5_TIM_TIMER)
3241 *masked |= ATH9K_INT_TIM_TIMER;
3242 }
3243 }
3244
3245 *masked |= mask2;
3246 }
Sujithf1dc5602008-10-29 10:16:30 +05303247
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003248 if (AR_SREV_9100(ah))
3249 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303250
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303251 if (isr & AR_ISR_GENTMR) {
3252 u32 s5_s;
3253
3254 s5_s = REG_READ(ah, AR_ISR_S5_S);
3255 if (isr & AR_ISR_GENTMR) {
3256 ah->intr_gen_timer_trigger =
3257 MS(s5_s, AR_ISR_S5_GENTIMER_TRIG);
3258
3259 ah->intr_gen_timer_thresh =
3260 MS(s5_s, AR_ISR_S5_GENTIMER_THRESH);
3261
3262 if (ah->intr_gen_timer_trigger)
3263 *masked |= ATH9K_INT_GENTIMER;
3264
3265 }
3266 }
3267
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003268 if (sync_cause) {
3269 fatal_int =
3270 (sync_cause &
3271 (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
3272 ? true : false;
3273
3274 if (fatal_int) {
3275 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003276 ath_print(common, ATH_DBG_ANY,
3277 "received PCI FATAL interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003278 }
3279 if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003280 ath_print(common, ATH_DBG_ANY,
3281 "received PCI PERR interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003282 }
Steven Luoa89bff92009-04-12 02:57:54 -07003283 *masked |= ATH9K_INT_FATAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003284 }
3285 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003286 ath_print(common, ATH_DBG_INTERRUPT,
3287 "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003288 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
3289 REG_WRITE(ah, AR_RC, 0);
3290 *masked |= ATH9K_INT_FATAL;
3291 }
3292 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003293 ath_print(common, ATH_DBG_INTERRUPT,
3294 "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003295 }
3296
3297 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
3298 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
3299 }
Sujithf1dc5602008-10-29 10:16:30 +05303300
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003301 return true;
3302}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003303EXPORT_SYMBOL(ath9k_hw_getisr);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003304
Sujithcbe61d82009-02-09 13:27:12 +05303305enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003306{
Sujith2660b812009-02-09 13:27:26 +05303307 u32 omask = ah->mask_reg;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003308 u32 mask, mask2;
Sujith2660b812009-02-09 13:27:26 +05303309 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003310 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003311
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003312 ath_print(common, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003313
3314 if (omask & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003315 ath_print(common, ATH_DBG_INTERRUPT, "disable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003316 REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
3317 (void) REG_READ(ah, AR_IER);
3318 if (!AR_SREV_9100(ah)) {
3319 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
3320 (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
3321
3322 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
3323 (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
3324 }
3325 }
3326
3327 mask = ints & ATH9K_INT_COMMON;
3328 mask2 = 0;
3329
3330 if (ints & ATH9K_INT_TX) {
Sujith2660b812009-02-09 13:27:26 +05303331 if (ah->txok_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003332 mask |= AR_IMR_TXOK;
Sujith2660b812009-02-09 13:27:26 +05303333 if (ah->txdesc_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003334 mask |= AR_IMR_TXDESC;
Sujith2660b812009-02-09 13:27:26 +05303335 if (ah->txerr_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003336 mask |= AR_IMR_TXERR;
Sujith2660b812009-02-09 13:27:26 +05303337 if (ah->txeol_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003338 mask |= AR_IMR_TXEOL;
3339 }
3340 if (ints & ATH9K_INT_RX) {
3341 mask |= AR_IMR_RXERR;
Sujith0ef1f162009-03-30 15:28:35 +05303342 if (ah->config.intr_mitigation)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003343 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
3344 else
3345 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
Sujith60b67f52008-08-07 10:52:38 +05303346 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003347 mask |= AR_IMR_GENTMR;
3348 }
3349
3350 if (ints & (ATH9K_INT_BMISC)) {
3351 mask |= AR_IMR_BCNMISC;
3352 if (ints & ATH9K_INT_TIM)
3353 mask2 |= AR_IMR_S2_TIM;
3354 if (ints & ATH9K_INT_DTIM)
3355 mask2 |= AR_IMR_S2_DTIM;
3356 if (ints & ATH9K_INT_DTIMSYNC)
3357 mask2 |= AR_IMR_S2_DTIMSYNC;
3358 if (ints & ATH9K_INT_CABEND)
Sujith4af9cf42009-02-12 10:06:47 +05303359 mask2 |= AR_IMR_S2_CABEND;
3360 if (ints & ATH9K_INT_TSFOOR)
3361 mask2 |= AR_IMR_S2_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003362 }
3363
3364 if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
3365 mask |= AR_IMR_BCNMISC;
3366 if (ints & ATH9K_INT_GTT)
3367 mask2 |= AR_IMR_S2_GTT;
3368 if (ints & ATH9K_INT_CST)
3369 mask2 |= AR_IMR_S2_CST;
3370 }
3371
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003372 ath_print(common, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003373 REG_WRITE(ah, AR_IMR, mask);
3374 mask = REG_READ(ah, AR_IMR_S2) & ~(AR_IMR_S2_TIM |
3375 AR_IMR_S2_DTIM |
3376 AR_IMR_S2_DTIMSYNC |
3377 AR_IMR_S2_CABEND |
3378 AR_IMR_S2_CABTO |
3379 AR_IMR_S2_TSFOOR |
3380 AR_IMR_S2_GTT | AR_IMR_S2_CST);
3381 REG_WRITE(ah, AR_IMR_S2, mask | mask2);
Sujith2660b812009-02-09 13:27:26 +05303382 ah->mask_reg = ints;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003383
Sujith60b67f52008-08-07 10:52:38 +05303384 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003385 if (ints & ATH9K_INT_TIM_TIMER)
3386 REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
3387 else
3388 REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
3389 }
3390
3391 if (ints & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003392 ath_print(common, ATH_DBG_INTERRUPT, "enable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003393 REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
3394 if (!AR_SREV_9100(ah)) {
3395 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
3396 AR_INTR_MAC_IRQ);
3397 REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
3398
3399
3400 REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
3401 AR_INTR_SYNC_DEFAULT);
3402 REG_WRITE(ah, AR_INTR_SYNC_MASK,
3403 AR_INTR_SYNC_DEFAULT);
3404 }
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003405 ath_print(common, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
3406 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003407 }
3408
3409 return omask;
3410}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003411EXPORT_SYMBOL(ath9k_hw_set_interrupts);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003412
Sujithf1dc5602008-10-29 10:16:30 +05303413/*******************/
3414/* Beacon Handling */
3415/*******************/
3416
Sujithcbe61d82009-02-09 13:27:12 +05303417void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003418{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003419 int flags = 0;
3420
Sujith2660b812009-02-09 13:27:26 +05303421 ah->beacon_interval = beacon_period;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003422
Sujith2660b812009-02-09 13:27:26 +05303423 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08003424 case NL80211_IFTYPE_STATION:
3425 case NL80211_IFTYPE_MONITOR:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003426 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3427 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
3428 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
3429 flags |= AR_TBTT_TIMER_EN;
3430 break;
Colin McCabed97809d2008-12-01 13:38:55 -08003431 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04003432 case NL80211_IFTYPE_MESH_POINT:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003433 REG_SET_BIT(ah, AR_TXCFG,
3434 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
3435 REG_WRITE(ah, AR_NEXT_NDP_TIMER,
3436 TU_TO_USEC(next_beacon +
Sujith2660b812009-02-09 13:27:26 +05303437 (ah->atim_window ? ah->
3438 atim_window : 1)));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003439 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08003440 case NL80211_IFTYPE_AP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003441 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3442 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
3443 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05303444 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05303445 dma_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003446 REG_WRITE(ah, AR_NEXT_SWBA,
3447 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05303448 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05303449 sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003450 flags |=
3451 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
3452 break;
Colin McCabed97809d2008-12-01 13:38:55 -08003453 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003454 ath_print(ath9k_hw_common(ah), ATH_DBG_BEACON,
3455 "%s: unsupported opmode: %d\n",
3456 __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08003457 return;
3458 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003459 }
3460
3461 REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3462 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3463 REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
3464 REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
3465
3466 beacon_period &= ~ATH9K_BEACON_ENA;
3467 if (beacon_period & ATH9K_BEACON_RESET_TSF) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003468 ath9k_hw_reset_tsf(ah);
3469 }
3470
3471 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
3472}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003473EXPORT_SYMBOL(ath9k_hw_beaconinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003474
Sujithcbe61d82009-02-09 13:27:12 +05303475void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303476 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003477{
3478 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05303479 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003480 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003481
3482 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
3483
3484 REG_WRITE(ah, AR_BEACON_PERIOD,
3485 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3486 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
3487 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3488
3489 REG_RMW_FIELD(ah, AR_RSSI_THR,
3490 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
3491
3492 beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
3493
3494 if (bs->bs_sleepduration > beaconintval)
3495 beaconintval = bs->bs_sleepduration;
3496
3497 dtimperiod = bs->bs_dtimperiod;
3498 if (bs->bs_sleepduration > dtimperiod)
3499 dtimperiod = bs->bs_sleepduration;
3500
3501 if (beaconintval == dtimperiod)
3502 nextTbtt = bs->bs_nextdtim;
3503 else
3504 nextTbtt = bs->bs_nexttbtt;
3505
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003506 ath_print(common, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
3507 ath_print(common, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
3508 ath_print(common, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
3509 ath_print(common, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003510
3511 REG_WRITE(ah, AR_NEXT_DTIM,
3512 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
3513 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
3514
3515 REG_WRITE(ah, AR_SLEEP1,
3516 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
3517 | AR_SLEEP1_ASSUME_DTIM);
3518
Sujith60b67f52008-08-07 10:52:38 +05303519 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003520 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
3521 else
3522 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
3523
3524 REG_WRITE(ah, AR_SLEEP2,
3525 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
3526
3527 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
3528 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
3529
3530 REG_SET_BIT(ah, AR_TIMER_MODE,
3531 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
3532 AR_DTIM_TIMER_EN);
3533
Sujith4af9cf42009-02-12 10:06:47 +05303534 /* TSF Out of Range Threshold */
3535 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003536}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003537EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003538
Sujithf1dc5602008-10-29 10:16:30 +05303539/*******************/
3540/* HW Capabilities */
3541/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003542
Sujitheef7a572009-03-30 15:28:28 +05303543void ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003544{
Sujith2660b812009-02-09 13:27:26 +05303545 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003546 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003547 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003548 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003549
Sujithf1dc5602008-10-29 10:16:30 +05303550 u16 capField = 0, eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003551
Sujithf74df6f2009-02-09 13:27:24 +05303552 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003553 regulatory->current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303554
Sujithf74df6f2009-02-09 13:27:24 +05303555 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
Sujithfec0de12009-02-12 10:06:43 +05303556 if (AR_SREV_9285_10_OR_LATER(ah))
3557 eeval |= AR9285_RDEXT_DEFAULT;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003558 regulatory->current_rd_ext = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303559
Sujithf74df6f2009-02-09 13:27:24 +05303560 capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
Sujithf1dc5602008-10-29 10:16:30 +05303561
Sujith2660b812009-02-09 13:27:26 +05303562 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05303563 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003564 if (regulatory->current_rd == 0x64 ||
3565 regulatory->current_rd == 0x65)
3566 regulatory->current_rd += 5;
3567 else if (regulatory->current_rd == 0x41)
3568 regulatory->current_rd = 0x43;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003569 ath_print(common, ATH_DBG_REGULATORY,
3570 "regdomain mapped to 0x%x\n", regulatory->current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003571 }
Sujithdc2222a2008-08-14 13:26:55 +05303572
Sujithf74df6f2009-02-09 13:27:24 +05303573 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Sujithf1dc5602008-10-29 10:16:30 +05303574 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003575
Sujithf1dc5602008-10-29 10:16:30 +05303576 if (eeval & AR5416_OPFLAGS_11A) {
3577 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303578 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303579 if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
3580 set_bit(ATH9K_MODE_11NA_HT20,
3581 pCap->wireless_modes);
3582 if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
3583 set_bit(ATH9K_MODE_11NA_HT40PLUS,
3584 pCap->wireless_modes);
3585 set_bit(ATH9K_MODE_11NA_HT40MINUS,
3586 pCap->wireless_modes);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003587 }
3588 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003589 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003590
Sujithf1dc5602008-10-29 10:16:30 +05303591 if (eeval & AR5416_OPFLAGS_11G) {
Sujithf1dc5602008-10-29 10:16:30 +05303592 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303593 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303594 if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
3595 set_bit(ATH9K_MODE_11NG_HT20,
3596 pCap->wireless_modes);
3597 if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
3598 set_bit(ATH9K_MODE_11NG_HT40PLUS,
3599 pCap->wireless_modes);
3600 set_bit(ATH9K_MODE_11NG_HT40MINUS,
3601 pCap->wireless_modes);
3602 }
3603 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003604 }
Sujithf1dc5602008-10-29 10:16:30 +05303605
Sujithf74df6f2009-02-09 13:27:24 +05303606 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003607 /*
3608 * For AR9271 we will temporarilly uses the rx chainmax as read from
3609 * the EEPROM.
3610 */
Sujith8147f5d2009-02-20 15:13:23 +05303611 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003612 !(eeval & AR5416_OPFLAGS_11A) &&
3613 !(AR_SREV_9271(ah)))
3614 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
Sujith8147f5d2009-02-20 15:13:23 +05303615 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
3616 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003617 /* Use rx_chainmask from EEPROM. */
Sujith8147f5d2009-02-20 15:13:23 +05303618 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05303619
Sujithd535a422009-02-09 13:27:06 +05303620 if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0)))
Sujith2660b812009-02-09 13:27:26 +05303621 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05303622
3623 pCap->low_2ghz_chan = 2312;
3624 pCap->high_2ghz_chan = 2732;
3625
3626 pCap->low_5ghz_chan = 4920;
3627 pCap->high_5ghz_chan = 6100;
3628
3629 pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
3630 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
3631 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
3632
3633 pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
3634 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
3635 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
3636
Sujith2660b812009-02-09 13:27:26 +05303637 if (ah->config.ht_enable)
Sujithf1dc5602008-10-29 10:16:30 +05303638 pCap->hw_caps |= ATH9K_HW_CAP_HT;
3639 else
3640 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
3641
3642 pCap->hw_caps |= ATH9K_HW_CAP_GTT;
3643 pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
3644 pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
3645 pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
3646
3647 if (capField & AR_EEPROM_EEPCAP_MAXQCU)
3648 pCap->total_queues =
3649 MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
3650 else
3651 pCap->total_queues = ATH9K_NUM_TX_QUEUES;
3652
3653 if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
3654 pCap->keycache_size =
3655 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
3656 else
3657 pCap->keycache_size = AR_KEYTABLE_SIZE;
3658
3659 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
Sujithf1dc5602008-10-29 10:16:30 +05303660 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
3661
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303662 if (AR_SREV_9285_10_OR_LATER(ah))
3663 pCap->num_gpio_pins = AR9285_NUM_GPIO;
3664 else if (AR_SREV_9280_10_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303665 pCap->num_gpio_pins = AR928X_NUM_GPIO;
3666 else
3667 pCap->num_gpio_pins = AR_NUM_GPIO;
3668
Sujithf1dc5602008-10-29 10:16:30 +05303669 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
3670 pCap->hw_caps |= ATH9K_HW_CAP_CST;
3671 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
3672 } else {
3673 pCap->rts_aggr_limit = (8 * 1024);
3674 }
3675
3676 pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
3677
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05303678#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05303679 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
3680 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
3681 ah->rfkill_gpio =
3682 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
3683 ah->rfkill_polarity =
3684 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05303685
3686 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
3687 }
3688#endif
3689
Vivek Natarajana3ca95fb2009-09-17 09:29:07 +05303690 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
Sujithf1dc5602008-10-29 10:16:30 +05303691
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05303692 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303693 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
3694 else
3695 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
3696
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003697 if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) {
Sujithf1dc5602008-10-29 10:16:30 +05303698 pCap->reg_cap =
3699 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3700 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
3701 AR_EEPROM_EEREGCAP_EN_KK_U2 |
3702 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
3703 } else {
3704 pCap->reg_cap =
3705 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3706 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
3707 }
3708
Senthil Balasubramanianebb90cf2009-09-18 15:07:33 +05303709 /* Advertise midband for AR5416 with FCC midband set in eeprom */
3710 if (regulatory->current_rd_ext & (1 << REG_EXT_FCC_MIDBAND) &&
3711 AR_SREV_5416(ah))
3712 pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
Sujithf1dc5602008-10-29 10:16:30 +05303713
3714 pCap->num_antcfg_5ghz =
Sujithf74df6f2009-02-09 13:27:24 +05303715 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303716 pCap->num_antcfg_2ghz =
Sujithf74df6f2009-02-09 13:27:24 +05303717 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303718
Vasanthakumar Thiagarajanfe129462009-09-09 15:25:50 +05303719 if (AR_SREV_9280_10_OR_LATER(ah) &&
Luis R. Rodrigueza36cfbc2009-09-09 16:05:32 -07003720 ath9k_hw_btcoex_supported(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003721 btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO;
3722 btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO;
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05303723
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303724 if (AR_SREV_9285(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003725 btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
3726 btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303727 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003728 btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303729 }
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05303730 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003731 btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE;
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303732 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003733}
3734
Sujithcbe61d82009-02-09 13:27:12 +05303735bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303736 u32 capability, u32 *result)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003737{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003738 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05303739 switch (type) {
3740 case ATH9K_CAP_CIPHER:
3741 switch (capability) {
3742 case ATH9K_CIPHER_AES_CCM:
3743 case ATH9K_CIPHER_AES_OCB:
3744 case ATH9K_CIPHER_TKIP:
3745 case ATH9K_CIPHER_WEP:
3746 case ATH9K_CIPHER_MIC:
3747 case ATH9K_CIPHER_CLR:
3748 return true;
3749 default:
3750 return false;
3751 }
3752 case ATH9K_CAP_TKIP_MIC:
3753 switch (capability) {
3754 case 0:
3755 return true;
3756 case 1:
Sujith2660b812009-02-09 13:27:26 +05303757 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303758 AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
3759 false;
3760 }
3761 case ATH9K_CAP_TKIP_SPLIT:
Sujith2660b812009-02-09 13:27:26 +05303762 return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ?
Sujithf1dc5602008-10-29 10:16:30 +05303763 false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303764 case ATH9K_CAP_DIVERSITY:
3765 return (REG_READ(ah, AR_PHY_CCK_DETECT) &
3766 AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV) ?
3767 true : false;
Sujithf1dc5602008-10-29 10:16:30 +05303768 case ATH9K_CAP_MCAST_KEYSRCH:
3769 switch (capability) {
3770 case 0:
3771 return true;
3772 case 1:
3773 if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
3774 return false;
3775 } else {
Sujith2660b812009-02-09 13:27:26 +05303776 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303777 AR_STA_ID1_MCAST_KSRCH) ? true :
3778 false;
3779 }
3780 }
3781 return false;
Sujithf1dc5602008-10-29 10:16:30 +05303782 case ATH9K_CAP_TXPOW:
3783 switch (capability) {
3784 case 0:
3785 return 0;
3786 case 1:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003787 *result = regulatory->power_limit;
Sujithf1dc5602008-10-29 10:16:30 +05303788 return 0;
3789 case 2:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003790 *result = regulatory->max_power_level;
Sujithf1dc5602008-10-29 10:16:30 +05303791 return 0;
3792 case 3:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003793 *result = regulatory->tp_scale;
Sujithf1dc5602008-10-29 10:16:30 +05303794 return 0;
3795 }
3796 return false;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05303797 case ATH9K_CAP_DS:
3798 return (AR_SREV_9280_20_OR_LATER(ah) &&
3799 (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1))
3800 ? false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303801 default:
3802 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003803 }
Sujithf1dc5602008-10-29 10:16:30 +05303804}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003805EXPORT_SYMBOL(ath9k_hw_getcapability);
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003806
Sujithcbe61d82009-02-09 13:27:12 +05303807bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303808 u32 capability, u32 setting, int *status)
3809{
Sujithf1dc5602008-10-29 10:16:30 +05303810 u32 v;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003811
Sujithf1dc5602008-10-29 10:16:30 +05303812 switch (type) {
3813 case ATH9K_CAP_TKIP_MIC:
3814 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303815 ah->sta_id1_defaults |=
Sujithf1dc5602008-10-29 10:16:30 +05303816 AR_STA_ID1_CRPT_MIC_ENABLE;
3817 else
Sujith2660b812009-02-09 13:27:26 +05303818 ah->sta_id1_defaults &=
Sujithf1dc5602008-10-29 10:16:30 +05303819 ~AR_STA_ID1_CRPT_MIC_ENABLE;
3820 return true;
3821 case ATH9K_CAP_DIVERSITY:
3822 v = REG_READ(ah, AR_PHY_CCK_DETECT);
3823 if (setting)
3824 v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3825 else
3826 v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3827 REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
3828 return true;
3829 case ATH9K_CAP_MCAST_KEYSRCH:
3830 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303831 ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303832 else
Sujith2660b812009-02-09 13:27:26 +05303833 ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303834 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303835 default:
3836 return false;
3837 }
3838}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003839EXPORT_SYMBOL(ath9k_hw_setcapability);
Sujithf1dc5602008-10-29 10:16:30 +05303840
3841/****************************/
3842/* GPIO / RFKILL / Antennae */
3843/****************************/
3844
Sujithcbe61d82009-02-09 13:27:12 +05303845static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303846 u32 gpio, u32 type)
3847{
3848 int addr;
3849 u32 gpio_shift, tmp;
3850
3851 if (gpio > 11)
3852 addr = AR_GPIO_OUTPUT_MUX3;
3853 else if (gpio > 5)
3854 addr = AR_GPIO_OUTPUT_MUX2;
3855 else
3856 addr = AR_GPIO_OUTPUT_MUX1;
3857
3858 gpio_shift = (gpio % 6) * 5;
3859
3860 if (AR_SREV_9280_20_OR_LATER(ah)
3861 || (addr != AR_GPIO_OUTPUT_MUX1)) {
3862 REG_RMW(ah, addr, (type << gpio_shift),
3863 (0x1f << gpio_shift));
3864 } else {
3865 tmp = REG_READ(ah, addr);
3866 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
3867 tmp &= ~(0x1f << gpio_shift);
3868 tmp |= (type << gpio_shift);
3869 REG_WRITE(ah, addr, tmp);
3870 }
3871}
3872
Sujithcbe61d82009-02-09 13:27:12 +05303873void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303874{
3875 u32 gpio_shift;
3876
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07003877 BUG_ON(gpio >= ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05303878
3879 gpio_shift = gpio << 1;
3880
3881 REG_RMW(ah,
3882 AR_GPIO_OE_OUT,
3883 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
3884 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3885}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003886EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
Sujithf1dc5602008-10-29 10:16:30 +05303887
Sujithcbe61d82009-02-09 13:27:12 +05303888u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303889{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303890#define MS_REG_READ(x, y) \
3891 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
3892
Sujith2660b812009-02-09 13:27:26 +05303893 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05303894 return 0xffffffff;
3895
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05303896 if (AR_SREV_9287_10_OR_LATER(ah))
3897 return MS_REG_READ(AR9287, gpio) != 0;
3898 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303899 return MS_REG_READ(AR9285, gpio) != 0;
3900 else if (AR_SREV_9280_10_OR_LATER(ah))
3901 return MS_REG_READ(AR928X, gpio) != 0;
3902 else
3903 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05303904}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003905EXPORT_SYMBOL(ath9k_hw_gpio_get);
Sujithf1dc5602008-10-29 10:16:30 +05303906
Sujithcbe61d82009-02-09 13:27:12 +05303907void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05303908 u32 ah_signal_type)
3909{
3910 u32 gpio_shift;
3911
3912 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
3913
3914 gpio_shift = 2 * gpio;
3915
3916 REG_RMW(ah,
3917 AR_GPIO_OE_OUT,
3918 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
3919 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3920}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003921EXPORT_SYMBOL(ath9k_hw_cfg_output);
Sujithf1dc5602008-10-29 10:16:30 +05303922
Sujithcbe61d82009-02-09 13:27:12 +05303923void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05303924{
3925 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
3926 AR_GPIO_BIT(gpio));
3927}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003928EXPORT_SYMBOL(ath9k_hw_set_gpio);
Sujithf1dc5602008-10-29 10:16:30 +05303929
Sujithcbe61d82009-02-09 13:27:12 +05303930u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303931{
3932 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
3933}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003934EXPORT_SYMBOL(ath9k_hw_getdefantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303935
Sujithcbe61d82009-02-09 13:27:12 +05303936void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05303937{
3938 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
3939}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003940EXPORT_SYMBOL(ath9k_hw_setantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303941
Sujithcbe61d82009-02-09 13:27:12 +05303942bool ath9k_hw_setantennaswitch(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303943 enum ath9k_ant_setting settings,
3944 struct ath9k_channel *chan,
3945 u8 *tx_chainmask,
3946 u8 *rx_chainmask,
3947 u8 *antenna_cfgd)
3948{
Sujithf1dc5602008-10-29 10:16:30 +05303949 static u8 tx_chainmask_cfg, rx_chainmask_cfg;
3950
3951 if (AR_SREV_9280(ah)) {
3952 if (!tx_chainmask_cfg) {
3953
3954 tx_chainmask_cfg = *tx_chainmask;
3955 rx_chainmask_cfg = *rx_chainmask;
3956 }
3957
3958 switch (settings) {
3959 case ATH9K_ANT_FIXED_A:
3960 *tx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3961 *rx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3962 *antenna_cfgd = true;
3963 break;
3964 case ATH9K_ANT_FIXED_B:
Sujith2660b812009-02-09 13:27:26 +05303965 if (ah->caps.tx_chainmask >
Sujithf1dc5602008-10-29 10:16:30 +05303966 ATH9K_ANTENNA1_CHAINMASK) {
3967 *tx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3968 }
3969 *rx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3970 *antenna_cfgd = true;
3971 break;
3972 case ATH9K_ANT_VARIABLE:
3973 *tx_chainmask = tx_chainmask_cfg;
3974 *rx_chainmask = rx_chainmask_cfg;
3975 *antenna_cfgd = true;
3976 break;
3977 default:
3978 break;
3979 }
3980 } else {
Sujith1cf68732009-08-13 09:34:32 +05303981 ah->config.diversity_control = settings;
Sujithf1dc5602008-10-29 10:16:30 +05303982 }
3983
3984 return true;
3985}
3986
3987/*********************/
3988/* General Operation */
3989/*********************/
3990
Sujithcbe61d82009-02-09 13:27:12 +05303991u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303992{
3993 u32 bits = REG_READ(ah, AR_RX_FILTER);
3994 u32 phybits = REG_READ(ah, AR_PHY_ERR);
3995
3996 if (phybits & AR_PHY_ERR_RADAR)
3997 bits |= ATH9K_RX_FILTER_PHYRADAR;
3998 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
3999 bits |= ATH9K_RX_FILTER_PHYERR;
4000
4001 return bits;
4002}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004003EXPORT_SYMBOL(ath9k_hw_getrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05304004
Sujithcbe61d82009-02-09 13:27:12 +05304005void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05304006{
4007 u32 phybits;
4008
Sujith7ea310b2009-09-03 12:08:43 +05304009 REG_WRITE(ah, AR_RX_FILTER, bits);
4010
Sujithf1dc5602008-10-29 10:16:30 +05304011 phybits = 0;
4012 if (bits & ATH9K_RX_FILTER_PHYRADAR)
4013 phybits |= AR_PHY_ERR_RADAR;
4014 if (bits & ATH9K_RX_FILTER_PHYERR)
4015 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
4016 REG_WRITE(ah, AR_PHY_ERR, phybits);
4017
4018 if (phybits)
4019 REG_WRITE(ah, AR_RXCFG,
4020 REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
4021 else
4022 REG_WRITE(ah, AR_RXCFG,
4023 REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
4024}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004025EXPORT_SYMBOL(ath9k_hw_setrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05304026
Sujithcbe61d82009-02-09 13:27:12 +05304027bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304028{
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05304029 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
4030 return false;
4031
4032 ath9k_hw_init_pll(ah, NULL);
4033 return true;
Sujithf1dc5602008-10-29 10:16:30 +05304034}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004035EXPORT_SYMBOL(ath9k_hw_phy_disable);
Sujithf1dc5602008-10-29 10:16:30 +05304036
Sujithcbe61d82009-02-09 13:27:12 +05304037bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304038{
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07004039 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05304040 return false;
4041
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05304042 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
4043 return false;
4044
4045 ath9k_hw_init_pll(ah, NULL);
4046 return true;
Sujithf1dc5602008-10-29 10:16:30 +05304047}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004048EXPORT_SYMBOL(ath9k_hw_disable);
Sujithf1dc5602008-10-29 10:16:30 +05304049
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07004050void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
Sujithf1dc5602008-10-29 10:16:30 +05304051{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07004052 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujith2660b812009-02-09 13:27:26 +05304053 struct ath9k_channel *chan = ah->curchan;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08004054 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05304055
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07004056 regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER);
Sujithf1dc5602008-10-29 10:16:30 +05304057
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07004058 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07004059 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07004060 channel->max_antenna_gain * 2,
4061 channel->max_power * 2,
4062 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07004063 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05304064}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004065EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
Sujithf1dc5602008-10-29 10:16:30 +05304066
Sujithcbe61d82009-02-09 13:27:12 +05304067void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac)
Sujithf1dc5602008-10-29 10:16:30 +05304068{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07004069 memcpy(ath9k_hw_common(ah)->macaddr, mac, ETH_ALEN);
Sujithf1dc5602008-10-29 10:16:30 +05304070}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004071EXPORT_SYMBOL(ath9k_hw_setmac);
Sujithf1dc5602008-10-29 10:16:30 +05304072
Sujithcbe61d82009-02-09 13:27:12 +05304073void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304074{
Sujith2660b812009-02-09 13:27:26 +05304075 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05304076}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004077EXPORT_SYMBOL(ath9k_hw_setopmode);
Sujithf1dc5602008-10-29 10:16:30 +05304078
Sujithcbe61d82009-02-09 13:27:12 +05304079void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05304080{
4081 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
4082 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
4083}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004084EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
Sujithf1dc5602008-10-29 10:16:30 +05304085
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07004086void ath9k_hw_write_associd(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304087{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07004088 struct ath_common *common = ath9k_hw_common(ah);
4089
4090 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
4091 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
4092 ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05304093}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004094EXPORT_SYMBOL(ath9k_hw_write_associd);
Sujithf1dc5602008-10-29 10:16:30 +05304095
Sujithcbe61d82009-02-09 13:27:12 +05304096u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304097{
4098 u64 tsf;
4099
4100 tsf = REG_READ(ah, AR_TSF_U32);
4101 tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
4102
4103 return tsf;
4104}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004105EXPORT_SYMBOL(ath9k_hw_gettsf64);
Sujithf1dc5602008-10-29 10:16:30 +05304106
Sujithcbe61d82009-02-09 13:27:12 +05304107void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004108{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004109 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01004110 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004111}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004112EXPORT_SYMBOL(ath9k_hw_settsf64);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004113
Sujithcbe61d82009-02-09 13:27:12 +05304114void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304115{
Gabor Juhosf9b604f2009-06-21 00:02:15 +02004116 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
4117 AH_TSF_WRITE_TIMEOUT))
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004118 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
4119 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
Gabor Juhosf9b604f2009-06-21 00:02:15 +02004120
Sujithf1dc5602008-10-29 10:16:30 +05304121 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004122}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004123EXPORT_SYMBOL(ath9k_hw_reset_tsf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004124
Sujith54e4cec2009-08-07 09:45:09 +05304125void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004126{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004127 if (setting)
Sujith2660b812009-02-09 13:27:26 +05304128 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004129 else
Sujith2660b812009-02-09 13:27:26 +05304130 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004131}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004132EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004133
Sujithcbe61d82009-02-09 13:27:12 +05304134bool ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004135{
Sujithf1dc5602008-10-29 10:16:30 +05304136 if (us < ATH9K_SLOT_TIME_9 || us > ath9k_hw_mac_to_usec(ah, 0xffff)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004137 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
4138 "bad slot time %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05304139 ah->slottime = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05304140 return false;
4141 } else {
4142 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05304143 ah->slottime = us;
Sujithf1dc5602008-10-29 10:16:30 +05304144 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004145 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004146}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004147EXPORT_SYMBOL(ath9k_hw_setslottime);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004148
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07004149void ath9k_hw_set11nmac2040(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004150{
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07004151 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithf1dc5602008-10-29 10:16:30 +05304152 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004153
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07004154 if (conf_is_ht40(conf) && !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05304155 macmode = AR_2040_JOINED_RX_CLEAR;
4156 else
4157 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004158
Sujithf1dc5602008-10-29 10:16:30 +05304159 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004160}
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304161
4162/* HW Generic timers configuration */
4163
4164static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
4165{
4166 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4167 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4168 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4169 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4170 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4171 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4172 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4173 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4174 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
4175 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
4176 AR_NDP2_TIMER_MODE, 0x0002},
4177 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
4178 AR_NDP2_TIMER_MODE, 0x0004},
4179 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
4180 AR_NDP2_TIMER_MODE, 0x0008},
4181 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
4182 AR_NDP2_TIMER_MODE, 0x0010},
4183 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
4184 AR_NDP2_TIMER_MODE, 0x0020},
4185 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
4186 AR_NDP2_TIMER_MODE, 0x0040},
4187 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
4188 AR_NDP2_TIMER_MODE, 0x0080}
4189};
4190
4191/* HW generic timer primitives */
4192
4193/* compute and clear index of rightmost 1 */
4194static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
4195{
4196 u32 b;
4197
4198 b = *mask;
4199 b &= (0-b);
4200 *mask &= ~b;
4201 b *= debruijn32;
4202 b >>= 27;
4203
4204 return timer_table->gen_timer_index[b];
4205}
4206
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05304207u32 ath9k_hw_gettsf32(struct ath_hw *ah)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304208{
4209 return REG_READ(ah, AR_TSF_L32);
4210}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004211EXPORT_SYMBOL(ath9k_hw_gettsf32);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304212
4213struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
4214 void (*trigger)(void *),
4215 void (*overflow)(void *),
4216 void *arg,
4217 u8 timer_index)
4218{
4219 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4220 struct ath_gen_timer *timer;
4221
4222 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
4223
4224 if (timer == NULL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004225 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
4226 "Failed to allocate memory"
4227 "for hw timer[%d]\n", timer_index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304228 return NULL;
4229 }
4230
4231 /* allocate a hardware generic timer slot */
4232 timer_table->timers[timer_index] = timer;
4233 timer->index = timer_index;
4234 timer->trigger = trigger;
4235 timer->overflow = overflow;
4236 timer->arg = arg;
4237
4238 return timer;
4239}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004240EXPORT_SYMBOL(ath_gen_timer_alloc);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304241
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07004242void ath9k_hw_gen_timer_start(struct ath_hw *ah,
4243 struct ath_gen_timer *timer,
4244 u32 timer_next,
4245 u32 timer_period)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304246{
4247 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4248 u32 tsf;
4249
4250 BUG_ON(!timer_period);
4251
4252 set_bit(timer->index, &timer_table->timer_mask.timer_bits);
4253
4254 tsf = ath9k_hw_gettsf32(ah);
4255
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004256 ath_print(ath9k_hw_common(ah), ATH_DBG_HWTIMER,
4257 "curent tsf %x period %x"
4258 "timer_next %x\n", tsf, timer_period, timer_next);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304259
4260 /*
4261 * Pull timer_next forward if the current TSF already passed it
4262 * because of software latency
4263 */
4264 if (timer_next < tsf)
4265 timer_next = tsf + timer_period;
4266
4267 /*
4268 * Program generic timer registers
4269 */
4270 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
4271 timer_next);
4272 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
4273 timer_period);
4274 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
4275 gen_tmr_configuration[timer->index].mode_mask);
4276
4277 /* Enable both trigger and thresh interrupt masks */
4278 REG_SET_BIT(ah, AR_IMR_S5,
4279 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
4280 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304281}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004282EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304283
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07004284void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304285{
4286 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4287
4288 if ((timer->index < AR_FIRST_NDP_TIMER) ||
4289 (timer->index >= ATH_MAX_GEN_TIMER)) {
4290 return;
4291 }
4292
4293 /* Clear generic timer enable bits. */
4294 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
4295 gen_tmr_configuration[timer->index].mode_mask);
4296
4297 /* Disable both trigger and thresh interrupt masks */
4298 REG_CLR_BIT(ah, AR_IMR_S5,
4299 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
4300 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
4301
4302 clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304303}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004304EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304305
4306void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
4307{
4308 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4309
4310 /* free the hardware generic timer slot */
4311 timer_table->timers[timer->index] = NULL;
4312 kfree(timer);
4313}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004314EXPORT_SYMBOL(ath_gen_timer_free);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304315
4316/*
4317 * Generic Timer Interrupts handling
4318 */
4319void ath_gen_timer_isr(struct ath_hw *ah)
4320{
4321 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4322 struct ath_gen_timer *timer;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004323 struct ath_common *common = ath9k_hw_common(ah);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304324 u32 trigger_mask, thresh_mask, index;
4325
4326 /* get hardware generic timer interrupt status */
4327 trigger_mask = ah->intr_gen_timer_trigger;
4328 thresh_mask = ah->intr_gen_timer_thresh;
4329 trigger_mask &= timer_table->timer_mask.val;
4330 thresh_mask &= timer_table->timer_mask.val;
4331
4332 trigger_mask &= ~thresh_mask;
4333
4334 while (thresh_mask) {
4335 index = rightmost_index(timer_table, &thresh_mask);
4336 timer = timer_table->timers[index];
4337 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004338 ath_print(common, ATH_DBG_HWTIMER,
4339 "TSF overflow for Gen timer %d\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304340 timer->overflow(timer->arg);
4341 }
4342
4343 while (trigger_mask) {
4344 index = rightmost_index(timer_table, &trigger_mask);
4345 timer = timer_table->timers[index];
4346 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004347 ath_print(common, ATH_DBG_HWTIMER,
4348 "Gen timer[%d] trigger\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304349 timer->trigger(timer->arg);
4350 }
4351}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004352EXPORT_SYMBOL(ath_gen_timer_isr);
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04004353
4354static struct {
4355 u32 version;
4356 const char * name;
4357} ath_mac_bb_names[] = {
4358 /* Devices with external radios */
4359 { AR_SREV_VERSION_5416_PCI, "5416" },
4360 { AR_SREV_VERSION_5416_PCIE, "5418" },
4361 { AR_SREV_VERSION_9100, "9100" },
4362 { AR_SREV_VERSION_9160, "9160" },
4363 /* Single-chip solutions */
4364 { AR_SREV_VERSION_9280, "9280" },
4365 { AR_SREV_VERSION_9285, "9285" },
4366 { AR_SREV_VERSION_9287, "9287" }
4367};
4368
4369/* For devices with external radios */
4370static struct {
4371 u16 version;
4372 const char * name;
4373} ath_rf_names[] = {
4374 { 0, "5133" },
4375 { AR_RAD5133_SREV_MAJOR, "5133" },
4376 { AR_RAD5122_SREV_MAJOR, "5122" },
4377 { AR_RAD2133_SREV_MAJOR, "2133" },
4378 { AR_RAD2122_SREV_MAJOR, "2122" }
4379};
4380
4381/*
4382 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
4383 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04004384static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04004385{
4386 int i;
4387
4388 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
4389 if (ath_mac_bb_names[i].version == mac_bb_version) {
4390 return ath_mac_bb_names[i].name;
4391 }
4392 }
4393
4394 return "????";
4395}
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04004396
4397/*
4398 * Return the RF name. "????" is returned if the RF is unknown.
4399 * Used for devices with external radios.
4400 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04004401static const char *ath9k_hw_rf_name(u16 rf_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04004402{
4403 int i;
4404
4405 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
4406 if (ath_rf_names[i].version == rf_version) {
4407 return ath_rf_names[i].name;
4408 }
4409 }
4410
4411 return "????";
4412}
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04004413
4414void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
4415{
4416 int used;
4417
4418 /* chipsets >= AR9280 are single-chip */
4419 if (AR_SREV_9280_10_OR_LATER(ah)) {
4420 used = snprintf(hw_name, len,
4421 "Atheros AR%s Rev:%x",
4422 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
4423 ah->hw_version.macRev);
4424 }
4425 else {
4426 used = snprintf(hw_name, len,
4427 "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
4428 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
4429 ah->hw_version.macRev,
4430 ath9k_hw_rf_name((ah->hw_version.analog5GhzRev &
4431 AR_RADIO_SREV_MAJOR)),
4432 ah->hw_version.phyRev);
4433 }
4434
4435 hw_name[used] = '\0';
4436}
4437EXPORT_SYMBOL(ath9k_hw_name);