blob: 2ec61f08cfdbb073ea02adc1a1947ddf66336793 [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
Sujithcee075a2009-03-13 09:07:23 +05302 * Copyright (c) 2008-2009 Atheros Communications Inc.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include <linux/io.h>
18#include <asm/unaligned.h>
19
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -070020#include "hw.h"
Luis R. Rodriguezcfe8cba2009-09-13 23:39:31 -070021#include "rc.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070022#include "initvals.h"
23
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080024#define ATH9K_CLOCK_RATE_CCK 22
25#define ATH9K_CLOCK_RATE_5GHZ_OFDM 40
26#define ATH9K_CLOCK_RATE_2GHZ_OFDM 44
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070027
Sujithcbe61d82009-02-09 13:27:12 +053028static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type);
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -070029static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan);
Sujithcbe61d82009-02-09 13:27:12 +053030static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +053031 struct ar5416_eeprom_def *pEepData,
Sujithf1dc5602008-10-29 10:16:30 +053032 u32 reg, u32 value);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070033
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040034MODULE_AUTHOR("Atheros Communications");
35MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
36MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
37MODULE_LICENSE("Dual BSD/GPL");
38
39static int __init ath9k_init(void)
40{
41 return 0;
42}
43module_init(ath9k_init);
44
45static void __exit ath9k_exit(void)
46{
47 return;
48}
49module_exit(ath9k_exit);
50
Sujithf1dc5602008-10-29 10:16:30 +053051/********************/
52/* Helper Functions */
53/********************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070054
Sujithcbe61d82009-02-09 13:27:12 +053055static u32 ath9k_hw_mac_usec(struct ath_hw *ah, u32 clks)
Sujithf1dc5602008-10-29 10:16:30 +053056{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070057 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053058
Sujith2660b812009-02-09 13:27:26 +053059 if (!ah->curchan) /* should really check for CCK instead */
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080060 return clks / ATH9K_CLOCK_RATE_CCK;
61 if (conf->channel->band == IEEE80211_BAND_2GHZ)
62 return clks / ATH9K_CLOCK_RATE_2GHZ_OFDM;
Sujithcbe61d82009-02-09 13:27:12 +053063
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080064 return clks / ATH9K_CLOCK_RATE_5GHZ_OFDM;
Sujithf1dc5602008-10-29 10:16:30 +053065}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070066
Sujithcbe61d82009-02-09 13:27:12 +053067static u32 ath9k_hw_mac_to_usec(struct ath_hw *ah, u32 clks)
Sujithf1dc5602008-10-29 10:16:30 +053068{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070069 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053070
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080071 if (conf_is_ht40(conf))
Sujithf1dc5602008-10-29 10:16:30 +053072 return ath9k_hw_mac_usec(ah, clks) / 2;
73 else
74 return ath9k_hw_mac_usec(ah, clks);
75}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070076
Sujithcbe61d82009-02-09 13:27:12 +053077static u32 ath9k_hw_mac_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053078{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070079 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053080
Sujith2660b812009-02-09 13:27:26 +053081 if (!ah->curchan) /* should really check for CCK instead */
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080082 return usecs *ATH9K_CLOCK_RATE_CCK;
83 if (conf->channel->band == IEEE80211_BAND_2GHZ)
84 return usecs *ATH9K_CLOCK_RATE_2GHZ_OFDM;
85 return usecs *ATH9K_CLOCK_RATE_5GHZ_OFDM;
Sujithf1dc5602008-10-29 10:16:30 +053086}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070087
Sujithcbe61d82009-02-09 13:27:12 +053088static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053089{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070090 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053091
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080092 if (conf_is_ht40(conf))
Sujithf1dc5602008-10-29 10:16:30 +053093 return ath9k_hw_mac_clks(ah, usecs) * 2;
94 else
95 return ath9k_hw_mac_clks(ah, usecs);
96}
97
Sujith0caa7b12009-02-16 13:23:20 +053098bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070099{
100 int i;
101
Sujith0caa7b12009-02-16 13:23:20 +0530102 BUG_ON(timeout < AH_TIME_QUANTUM);
103
104 for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700105 if ((REG_READ(ah, reg) & mask) == val)
106 return true;
107
108 udelay(AH_TIME_QUANTUM);
109 }
Sujith04bd4632008-11-28 22:18:05 +0530110
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700111 ath_print(ath9k_hw_common(ah), ATH_DBG_ANY,
112 "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
113 timeout, reg, REG_READ(ah, reg), mask, val);
Sujithf1dc5602008-10-29 10:16:30 +0530114
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700115 return false;
116}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400117EXPORT_SYMBOL(ath9k_hw_wait);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700118
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700119u32 ath9k_hw_reverse_bits(u32 val, u32 n)
120{
121 u32 retval;
122 int i;
123
124 for (i = 0, retval = 0; i < n; i++) {
125 retval = (retval << 1) | (val & 1);
126 val >>= 1;
127 }
128 return retval;
129}
130
Sujithcbe61d82009-02-09 13:27:12 +0530131bool ath9k_get_channel_edges(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530132 u16 flags, u16 *low,
133 u16 *high)
134{
Sujith2660b812009-02-09 13:27:26 +0530135 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530136
137 if (flags & CHANNEL_5GHZ) {
138 *low = pCap->low_5ghz_chan;
139 *high = pCap->high_5ghz_chan;
140 return true;
141 }
142 if ((flags & CHANNEL_2GHZ)) {
143 *low = pCap->low_2ghz_chan;
144 *high = pCap->high_2ghz_chan;
145 return true;
146 }
147 return false;
148}
149
Sujithcbe61d82009-02-09 13:27:12 +0530150u16 ath9k_hw_computetxtime(struct ath_hw *ah,
Felix Fietkau545750d2009-11-23 22:21:01 +0100151 u8 phy, int kbps,
Sujithf1dc5602008-10-29 10:16:30 +0530152 u32 frameLen, u16 rateix,
153 bool shortPreamble)
154{
155 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
Sujithf1dc5602008-10-29 10:16:30 +0530156
157 if (kbps == 0)
158 return 0;
159
Felix Fietkau545750d2009-11-23 22:21:01 +0100160 switch (phy) {
Sujith46d14a52008-11-18 09:08:13 +0530161 case WLAN_RC_PHY_CCK:
Sujithf1dc5602008-10-29 10:16:30 +0530162 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
Felix Fietkau545750d2009-11-23 22:21:01 +0100163 if (shortPreamble)
Sujithf1dc5602008-10-29 10:16:30 +0530164 phyTime >>= 1;
165 numBits = frameLen << 3;
166 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
167 break;
Sujith46d14a52008-11-18 09:08:13 +0530168 case WLAN_RC_PHY_OFDM:
Sujith2660b812009-02-09 13:27:26 +0530169 if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530170 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
171 numBits = OFDM_PLCP_BITS + (frameLen << 3);
172 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
173 txTime = OFDM_SIFS_TIME_QUARTER
174 + OFDM_PREAMBLE_TIME_QUARTER
175 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
Sujith2660b812009-02-09 13:27:26 +0530176 } else if (ah->curchan &&
177 IS_CHAN_HALF_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530178 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
179 numBits = OFDM_PLCP_BITS + (frameLen << 3);
180 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
181 txTime = OFDM_SIFS_TIME_HALF +
182 OFDM_PREAMBLE_TIME_HALF
183 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
184 } else {
185 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
186 numBits = OFDM_PLCP_BITS + (frameLen << 3);
187 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
188 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
189 + (numSymbols * OFDM_SYMBOL_TIME);
190 }
191 break;
192 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700193 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
Felix Fietkau545750d2009-11-23 22:21:01 +0100194 "Unknown phy %u (rate ix %u)\n", phy, rateix);
Sujithf1dc5602008-10-29 10:16:30 +0530195 txTime = 0;
196 break;
197 }
198
199 return txTime;
200}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400201EXPORT_SYMBOL(ath9k_hw_computetxtime);
Sujithf1dc5602008-10-29 10:16:30 +0530202
Sujithcbe61d82009-02-09 13:27:12 +0530203void ath9k_hw_get_channel_centers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530204 struct ath9k_channel *chan,
205 struct chan_centers *centers)
206{
207 int8_t extoff;
Sujithf1dc5602008-10-29 10:16:30 +0530208
209 if (!IS_CHAN_HT40(chan)) {
210 centers->ctl_center = centers->ext_center =
211 centers->synth_center = chan->channel;
212 return;
213 }
214
215 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
216 (chan->chanmode == CHANNEL_G_HT40PLUS)) {
217 centers->synth_center =
218 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
219 extoff = 1;
220 } else {
221 centers->synth_center =
222 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
223 extoff = -1;
224 }
225
226 centers->ctl_center =
227 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700228 /* 25 MHz spacing is supported by hw but not on upper layers */
Sujithf1dc5602008-10-29 10:16:30 +0530229 centers->ext_center =
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700230 centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT);
Sujithf1dc5602008-10-29 10:16:30 +0530231}
232
233/******************/
234/* Chip Revisions */
235/******************/
236
Sujithcbe61d82009-02-09 13:27:12 +0530237static void ath9k_hw_read_revisions(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530238{
239 u32 val;
240
241 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
242
243 if (val == 0xFF) {
244 val = REG_READ(ah, AR_SREV);
Sujithd535a422009-02-09 13:27:06 +0530245 ah->hw_version.macVersion =
246 (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
247 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
Sujith2660b812009-02-09 13:27:26 +0530248 ah->is_pciexpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
Sujithf1dc5602008-10-29 10:16:30 +0530249 } else {
250 if (!AR_SREV_9100(ah))
Sujithd535a422009-02-09 13:27:06 +0530251 ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
Sujithf1dc5602008-10-29 10:16:30 +0530252
Sujithd535a422009-02-09 13:27:06 +0530253 ah->hw_version.macRev = val & AR_SREV_REVISION;
Sujithf1dc5602008-10-29 10:16:30 +0530254
Sujithd535a422009-02-09 13:27:06 +0530255 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
Sujith2660b812009-02-09 13:27:26 +0530256 ah->is_pciexpress = true;
Sujithf1dc5602008-10-29 10:16:30 +0530257 }
258}
259
Sujithcbe61d82009-02-09 13:27:12 +0530260static int ath9k_hw_get_radiorev(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530261{
262 u32 val;
263 int i;
264
265 REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
266
267 for (i = 0; i < 8; i++)
268 REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
269 val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
270 val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
271
272 return ath9k_hw_reverse_bits(val, 8);
273}
274
275/************************************/
276/* HW Attach, Detach, Init Routines */
277/************************************/
278
Sujithcbe61d82009-02-09 13:27:12 +0530279static void ath9k_hw_disablepcie(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530280{
Sujithfeed0292009-01-29 11:37:35 +0530281 if (AR_SREV_9100(ah))
Sujithf1dc5602008-10-29 10:16:30 +0530282 return;
283
284 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
285 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
286 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
287 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
288 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
289 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
290 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
291 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
292 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
293
294 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
295}
296
Sujithcbe61d82009-02-09 13:27:12 +0530297static bool ath9k_hw_chip_test(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530298{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700299 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530300 u32 regAddr[2] = { AR_STA_ID0, AR_PHY_BASE + (8 << 2) };
301 u32 regHold[2];
302 u32 patternData[4] = { 0x55555555,
303 0xaaaaaaaa,
304 0x66666666,
305 0x99999999 };
306 int i, j;
307
308 for (i = 0; i < 2; i++) {
309 u32 addr = regAddr[i];
310 u32 wrData, rdData;
311
312 regHold[i] = REG_READ(ah, addr);
313 for (j = 0; j < 0x100; j++) {
314 wrData = (j << 16) | j;
315 REG_WRITE(ah, addr, wrData);
316 rdData = REG_READ(ah, addr);
317 if (rdData != wrData) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700318 ath_print(common, ATH_DBG_FATAL,
319 "address test failed "
320 "addr: 0x%08x - wr:0x%08x != "
321 "rd:0x%08x\n",
322 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530323 return false;
324 }
325 }
326 for (j = 0; j < 4; j++) {
327 wrData = patternData[j];
328 REG_WRITE(ah, addr, wrData);
329 rdData = REG_READ(ah, addr);
330 if (wrData != rdData) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700331 ath_print(common, ATH_DBG_FATAL,
332 "address test failed "
333 "addr: 0x%08x - wr:0x%08x != "
334 "rd:0x%08x\n",
335 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530336 return false;
337 }
338 }
339 REG_WRITE(ah, regAddr[i], regHold[i]);
340 }
341 udelay(100);
Sujithcbe61d82009-02-09 13:27:12 +0530342
Sujithf1dc5602008-10-29 10:16:30 +0530343 return true;
344}
345
346static const char *ath9k_hw_devname(u16 devid)
347{
348 switch (devid) {
349 case AR5416_DEVID_PCI:
Sujithf1dc5602008-10-29 10:16:30 +0530350 return "Atheros 5416";
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +0100351 case AR5416_DEVID_PCIE:
352 return "Atheros 5418";
Sujithf1dc5602008-10-29 10:16:30 +0530353 case AR9160_DEVID_PCI:
354 return "Atheros 9160";
Gabor Juhos0c1aa492009-01-14 20:17:12 +0100355 case AR5416_AR9100_DEVID:
356 return "Atheros 9100";
Sujithf1dc5602008-10-29 10:16:30 +0530357 case AR9280_DEVID_PCI:
358 case AR9280_DEVID_PCIE:
359 return "Atheros 9280";
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530360 case AR9285_DEVID_PCIE:
361 return "Atheros 9285";
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530362 case AR5416_DEVID_AR9287_PCI:
363 case AR5416_DEVID_AR9287_PCIE:
364 return "Atheros 9287";
Sujithf1dc5602008-10-29 10:16:30 +0530365 }
366
367 return NULL;
368}
369
Luis R. Rodriguezb8b0f372009-08-03 12:24:43 -0700370static void ath9k_hw_init_config(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700371{
372 int i;
373
Sujith2660b812009-02-09 13:27:26 +0530374 ah->config.dma_beacon_response_time = 2;
375 ah->config.sw_beacon_response_time = 10;
376 ah->config.additional_swba_backoff = 0;
377 ah->config.ack_6mb = 0x0;
378 ah->config.cwm_ignore_extcca = 0;
379 ah->config.pcie_powersave_enable = 0;
Sujith2660b812009-02-09 13:27:26 +0530380 ah->config.pcie_clock_req = 0;
Sujith2660b812009-02-09 13:27:26 +0530381 ah->config.pcie_waen = 0;
382 ah->config.analog_shiftreg = 1;
383 ah->config.ht_enable = 1;
384 ah->config.ofdm_trig_low = 200;
385 ah->config.ofdm_trig_high = 500;
386 ah->config.cck_trig_high = 200;
387 ah->config.cck_trig_low = 100;
388 ah->config.enable_ani = 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700389
390 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujith2660b812009-02-09 13:27:26 +0530391 ah->config.spurchans[i][0] = AR_NO_SPUR;
392 ah->config.spurchans[i][1] = AR_NO_SPUR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700393 }
394
Sujith0ef1f162009-03-30 15:28:35 +0530395 ah->config.intr_mitigation = true;
Luis R. Rodriguez61584252009-03-12 18:18:49 -0400396
397 /*
398 * We need this for PCI devices only (Cardbus, PCI, miniPCI)
399 * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
400 * This means we use it for all AR5416 devices, and the few
401 * minor PCI AR9280 devices out there.
402 *
403 * Serialization is required because these devices do not handle
404 * well the case of two concurrent reads/writes due to the latency
405 * involved. During one read/write another read/write can be issued
406 * on another CPU while the previous read/write may still be working
407 * on our hardware, if we hit this case the hardware poops in a loop.
408 * We prevent this by serializing reads and writes.
409 *
410 * This issue is not present on PCI-Express devices or pre-AR5416
411 * devices (legacy, 802.11abg).
412 */
413 if (num_possible_cpus() > 1)
David S. Miller2d6a5e92009-03-17 15:01:30 -0700414 ah->config.serialize_regmode = SER_REG_MODE_AUTO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700415}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400416EXPORT_SYMBOL(ath9k_hw_init);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700417
Luis R. Rodriguez50aca252009-08-03 12:24:42 -0700418static void ath9k_hw_init_defaults(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700419{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700420 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
421
422 regulatory->country_code = CTRY_DEFAULT;
423 regulatory->power_limit = MAX_RATE_POWER;
424 regulatory->tp_scale = ATH9K_TP_SCALE_MAX;
425
Sujithd535a422009-02-09 13:27:06 +0530426 ah->hw_version.magic = AR5416_MAGIC;
Sujithd535a422009-02-09 13:27:06 +0530427 ah->hw_version.subvendorid = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700428
429 ah->ah_flags = 0;
Luis R. Rodriguez8df5d1b2009-08-03 12:24:37 -0700430 if (ah->hw_version.devid == AR5416_AR9100_DEVID)
Sujithd535a422009-02-09 13:27:06 +0530431 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700432 if (!AR_SREV_9100(ah))
433 ah->ah_flags = AH_USE_EEPROM;
434
Sujith2660b812009-02-09 13:27:26 +0530435 ah->atim_window = 0;
Sujith2660b812009-02-09 13:27:26 +0530436 ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
437 ah->beacon_interval = 100;
438 ah->enable_32kHz_clock = DONT_USE_32KHZ;
439 ah->slottime = (u32) -1;
440 ah->acktimeout = (u32) -1;
441 ah->ctstimeout = (u32) -1;
442 ah->globaltxtimeout = (u32) -1;
Gabor Juhoscbdec972009-07-24 17:27:22 +0200443 ah->power_mode = ATH9K_PM_UNDEFINED;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700444}
445
Sujithcbe61d82009-02-09 13:27:12 +0530446static int ath9k_hw_rf_claim(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700447{
448 u32 val;
449
450 REG_WRITE(ah, AR_PHY(0), 0x00000007);
451
452 val = ath9k_hw_get_radiorev(ah);
453 switch (val & AR_RADIO_SREV_MAJOR) {
454 case 0:
455 val = AR_RAD5133_SREV_MAJOR;
456 break;
457 case AR_RAD5133_SREV_MAJOR:
458 case AR_RAD5122_SREV_MAJOR:
459 case AR_RAD2133_SREV_MAJOR:
460 case AR_RAD2122_SREV_MAJOR:
461 break;
462 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700463 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
464 "Radio Chip Rev 0x%02X not supported\n",
465 val & AR_RADIO_SREV_MAJOR);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700466 return -EOPNOTSUPP;
467 }
468
Sujithd535a422009-02-09 13:27:06 +0530469 ah->hw_version.analog5GhzRev = val;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700470
471 return 0;
472}
473
Sujithcbe61d82009-02-09 13:27:12 +0530474static int ath9k_hw_init_macaddr(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700475{
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700476 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530477 u32 sum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700478 int i;
Sujithf1dc5602008-10-29 10:16:30 +0530479 u16 eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700480
Sujithf1dc5602008-10-29 10:16:30 +0530481 sum = 0;
482 for (i = 0; i < 3; i++) {
Sujithf74df6f2009-02-09 13:27:24 +0530483 eeval = ah->eep_ops->get_eeprom(ah, AR_EEPROM_MAC(i));
Sujithf1dc5602008-10-29 10:16:30 +0530484 sum += eeval;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700485 common->macaddr[2 * i] = eeval >> 8;
486 common->macaddr[2 * i + 1] = eeval & 0xff;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700487 }
Sujithd8baa932009-03-30 15:28:25 +0530488 if (sum == 0 || sum == 0xffff * 3)
Sujithf1dc5602008-10-29 10:16:30 +0530489 return -EADDRNOTAVAIL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700490
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700491 return 0;
492}
493
Sujithcbe61d82009-02-09 13:27:12 +0530494static void ath9k_hw_init_rxgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530495{
496 u32 rxgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530497
Sujithf74df6f2009-02-09 13:27:24 +0530498 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_17) {
499 rxgain_type = ah->eep_ops->get_eeprom(ah, EEP_RXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530500
501 if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530502 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530503 ar9280Modes_backoff_13db_rxgain_9280_2,
504 ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2), 6);
505 else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530506 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530507 ar9280Modes_backoff_23db_rxgain_9280_2,
508 ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 6);
509 else
Sujith2660b812009-02-09 13:27:26 +0530510 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530511 ar9280Modes_original_rxgain_9280_2,
512 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530513 } else {
Sujith2660b812009-02-09 13:27:26 +0530514 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530515 ar9280Modes_original_rxgain_9280_2,
516 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530517 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530518}
519
Sujithcbe61d82009-02-09 13:27:12 +0530520static void ath9k_hw_init_txgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530521{
522 u32 txgain_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_19) {
525 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530526
527 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
Sujith2660b812009-02-09 13:27:26 +0530528 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530529 ar9280Modes_high_power_tx_gain_9280_2,
530 ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 6);
531 else
Sujith2660b812009-02-09 13:27:26 +0530532 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530533 ar9280Modes_original_tx_gain_9280_2,
534 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530535 } else {
Sujith2660b812009-02-09 13:27:26 +0530536 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530537 ar9280Modes_original_tx_gain_9280_2,
538 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530539 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530540}
541
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700542static int ath9k_hw_post_init(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700543{
544 int ecode;
545
Sujithd8baa932009-03-30 15:28:25 +0530546 if (!ath9k_hw_chip_test(ah))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700547 return -ENODEV;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700548
549 ecode = ath9k_hw_rf_claim(ah);
550 if (ecode != 0)
551 return ecode;
552
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700553 ecode = ath9k_hw_eeprom_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700554 if (ecode != 0)
555 return ecode;
Sujith7d01b222009-03-13 08:55:55 +0530556
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700557 ath_print(ath9k_hw_common(ah), ATH_DBG_CONFIG,
558 "Eeprom VER: %d, REV: %d\n",
559 ah->eep_ops->get_eeprom_ver(ah),
560 ah->eep_ops->get_eeprom_rev(ah));
Sujith7d01b222009-03-13 08:55:55 +0530561
Luis R. Rodriguez574d6b12009-10-19 02:33:37 -0400562 if (!AR_SREV_9280_10_OR_LATER(ah)) {
563 ecode = ath9k_hw_rf_alloc_ext_banks(ah);
564 if (ecode) {
565 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
566 "Failed allocating banks for "
567 "external radio\n");
568 return ecode;
569 }
570 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700571
572 if (!AR_SREV_9100(ah)) {
573 ath9k_hw_ani_setup(ah);
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700574 ath9k_hw_ani_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700575 }
Sujithf1dc5602008-10-29 10:16:30 +0530576
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700577 return 0;
578}
579
Luis R. Rodriguezee2bb462009-08-03 12:24:39 -0700580static bool ath9k_hw_devid_supported(u16 devid)
581{
582 switch (devid) {
583 case AR5416_DEVID_PCI:
584 case AR5416_DEVID_PCIE:
585 case AR5416_AR9100_DEVID:
586 case AR9160_DEVID_PCI:
587 case AR9280_DEVID_PCI:
588 case AR9280_DEVID_PCIE:
589 case AR9285_DEVID_PCIE:
590 case AR5416_DEVID_AR9287_PCI:
591 case AR5416_DEVID_AR9287_PCIE:
Luis R. Rodriguez7976b422009-09-23 23:07:02 -0400592 case AR9271_USB:
Luis R. Rodriguezee2bb462009-08-03 12:24:39 -0700593 return true;
594 default:
595 break;
596 }
597 return false;
598}
599
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700600static bool ath9k_hw_macversion_supported(u32 macversion)
601{
602 switch (macversion) {
603 case AR_SREV_VERSION_5416_PCI:
604 case AR_SREV_VERSION_5416_PCIE:
605 case AR_SREV_VERSION_9160:
606 case AR_SREV_VERSION_9100:
607 case AR_SREV_VERSION_9280:
608 case AR_SREV_VERSION_9285:
609 case AR_SREV_VERSION_9287:
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400610 case AR_SREV_VERSION_9271:
Luis R. Rodriguez7976b422009-09-23 23:07:02 -0400611 return true;
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700612 default:
613 break;
614 }
615 return false;
616}
617
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700618static void ath9k_hw_init_cal_settings(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700619{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700620 if (AR_SREV_9160_10_OR_LATER(ah)) {
621 if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530622 ah->iq_caldata.calData = &iq_cal_single_sample;
623 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700624 &adc_gain_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530625 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700626 &adc_dc_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530627 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700628 &adc_init_dc_cal;
629 } else {
Sujith2660b812009-02-09 13:27:26 +0530630 ah->iq_caldata.calData = &iq_cal_multi_sample;
631 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700632 &adc_gain_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530633 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700634 &adc_dc_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530635 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700636 &adc_init_dc_cal;
637 }
Sujith2660b812009-02-09 13:27:26 +0530638 ah->supp_cals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700639 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700640}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700641
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700642static void ath9k_hw_init_mode_regs(struct ath_hw *ah)
643{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400644 if (AR_SREV_9271(ah)) {
Luis R. Rodriguez85643282009-10-19 02:33:33 -0400645 INIT_INI_ARRAY(&ah->iniModes, ar9271Modes_9271,
646 ARRAY_SIZE(ar9271Modes_9271), 6);
647 INIT_INI_ARRAY(&ah->iniCommon, ar9271Common_9271,
648 ARRAY_SIZE(ar9271Common_9271), 2);
649 INIT_INI_ARRAY(&ah->iniModes_9271_1_0_only,
650 ar9271Modes_9271_1_0_only,
651 ARRAY_SIZE(ar9271Modes_9271_1_0_only), 6);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400652 return;
653 }
654
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530655 if (AR_SREV_9287_11_OR_LATER(ah)) {
656 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_1,
657 ARRAY_SIZE(ar9287Modes_9287_1_1), 6);
658 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_1,
659 ARRAY_SIZE(ar9287Common_9287_1_1), 2);
660 if (ah->config.pcie_clock_req)
661 INIT_INI_ARRAY(&ah->iniPcieSerdes,
662 ar9287PciePhy_clkreq_off_L1_9287_1_1,
663 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_1), 2);
664 else
665 INIT_INI_ARRAY(&ah->iniPcieSerdes,
666 ar9287PciePhy_clkreq_always_on_L1_9287_1_1,
667 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_1),
668 2);
669 } else if (AR_SREV_9287_10_OR_LATER(ah)) {
670 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_0,
671 ARRAY_SIZE(ar9287Modes_9287_1_0), 6);
672 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_0,
673 ARRAY_SIZE(ar9287Common_9287_1_0), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700674
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530675 if (ah->config.pcie_clock_req)
676 INIT_INI_ARRAY(&ah->iniPcieSerdes,
677 ar9287PciePhy_clkreq_off_L1_9287_1_0,
678 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_0), 2);
679 else
680 INIT_INI_ARRAY(&ah->iniPcieSerdes,
681 ar9287PciePhy_clkreq_always_on_L1_9287_1_0,
682 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_0),
683 2);
684 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
685
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530686
Sujith2660b812009-02-09 13:27:26 +0530687 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530688 ARRAY_SIZE(ar9285Modes_9285_1_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530689 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530690 ARRAY_SIZE(ar9285Common_9285_1_2), 2);
691
Sujith2660b812009-02-09 13:27:26 +0530692 if (ah->config.pcie_clock_req) {
693 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530694 ar9285PciePhy_clkreq_off_L1_9285_1_2,
695 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2);
696 } else {
Sujith2660b812009-02-09 13:27:26 +0530697 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530698 ar9285PciePhy_clkreq_always_on_L1_9285_1_2,
699 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2),
700 2);
701 }
702 } else if (AR_SREV_9285_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530703 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530704 ARRAY_SIZE(ar9285Modes_9285), 6);
Sujith2660b812009-02-09 13:27:26 +0530705 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530706 ARRAY_SIZE(ar9285Common_9285), 2);
707
Sujith2660b812009-02-09 13:27:26 +0530708 if (ah->config.pcie_clock_req) {
709 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530710 ar9285PciePhy_clkreq_off_L1_9285,
711 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2);
712 } else {
Sujith2660b812009-02-09 13:27:26 +0530713 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530714 ar9285PciePhy_clkreq_always_on_L1_9285,
715 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285), 2);
716 }
717 } else if (AR_SREV_9280_20_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530718 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700719 ARRAY_SIZE(ar9280Modes_9280_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530720 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700721 ARRAY_SIZE(ar9280Common_9280_2), 2);
722
Sujith2660b812009-02-09 13:27:26 +0530723 if (ah->config.pcie_clock_req) {
724 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530725 ar9280PciePhy_clkreq_off_L1_9280,
726 ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700727 } else {
Sujith2660b812009-02-09 13:27:26 +0530728 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530729 ar9280PciePhy_clkreq_always_on_L1_9280,
730 ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700731 }
Sujith2660b812009-02-09 13:27:26 +0530732 INIT_INI_ARRAY(&ah->iniModesAdditional,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700733 ar9280Modes_fast_clock_9280_2,
Sujithf1dc5602008-10-29 10:16:30 +0530734 ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700735 } else if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530736 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700737 ARRAY_SIZE(ar9280Modes_9280), 6);
Sujith2660b812009-02-09 13:27:26 +0530738 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700739 ARRAY_SIZE(ar9280Common_9280), 2);
740 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530741 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700742 ARRAY_SIZE(ar5416Modes_9160), 6);
Sujith2660b812009-02-09 13:27:26 +0530743 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700744 ARRAY_SIZE(ar5416Common_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530745 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700746 ARRAY_SIZE(ar5416Bank0_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530747 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700748 ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530749 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700750 ARRAY_SIZE(ar5416Bank1_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530751 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700752 ARRAY_SIZE(ar5416Bank2_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530753 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700754 ARRAY_SIZE(ar5416Bank3_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530755 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700756 ARRAY_SIZE(ar5416Bank6_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530757 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700758 ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530759 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700760 ARRAY_SIZE(ar5416Bank7_9160), 2);
761 if (AR_SREV_9160_11(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530762 INIT_INI_ARRAY(&ah->iniAddac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700763 ar5416Addac_91601_1,
764 ARRAY_SIZE(ar5416Addac_91601_1), 2);
765 } else {
Sujith2660b812009-02-09 13:27:26 +0530766 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700767 ARRAY_SIZE(ar5416Addac_9160), 2);
768 }
769 } else if (AR_SREV_9100_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530770 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700771 ARRAY_SIZE(ar5416Modes_9100), 6);
Sujith2660b812009-02-09 13:27:26 +0530772 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700773 ARRAY_SIZE(ar5416Common_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530774 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700775 ARRAY_SIZE(ar5416Bank0_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530776 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700777 ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530778 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700779 ARRAY_SIZE(ar5416Bank1_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530780 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700781 ARRAY_SIZE(ar5416Bank2_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530782 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700783 ARRAY_SIZE(ar5416Bank3_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530784 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700785 ARRAY_SIZE(ar5416Bank6_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530786 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700787 ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530788 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700789 ARRAY_SIZE(ar5416Bank7_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530790 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700791 ARRAY_SIZE(ar5416Addac_9100), 2);
792 } else {
Sujith2660b812009-02-09 13:27:26 +0530793 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700794 ARRAY_SIZE(ar5416Modes), 6);
Sujith2660b812009-02-09 13:27:26 +0530795 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700796 ARRAY_SIZE(ar5416Common), 2);
Sujith2660b812009-02-09 13:27:26 +0530797 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700798 ARRAY_SIZE(ar5416Bank0), 2);
Sujith2660b812009-02-09 13:27:26 +0530799 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700800 ARRAY_SIZE(ar5416BB_RfGain), 3);
Sujith2660b812009-02-09 13:27:26 +0530801 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700802 ARRAY_SIZE(ar5416Bank1), 2);
Sujith2660b812009-02-09 13:27:26 +0530803 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700804 ARRAY_SIZE(ar5416Bank2), 2);
Sujith2660b812009-02-09 13:27:26 +0530805 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700806 ARRAY_SIZE(ar5416Bank3), 3);
Sujith2660b812009-02-09 13:27:26 +0530807 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700808 ARRAY_SIZE(ar5416Bank6), 3);
Sujith2660b812009-02-09 13:27:26 +0530809 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700810 ARRAY_SIZE(ar5416Bank6TPC), 3);
Sujith2660b812009-02-09 13:27:26 +0530811 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700812 ARRAY_SIZE(ar5416Bank7), 2);
Sujith2660b812009-02-09 13:27:26 +0530813 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700814 ARRAY_SIZE(ar5416Addac), 2);
815 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700816}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700817
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700818static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
819{
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530820 if (AR_SREV_9287_11_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530821 INIT_INI_ARRAY(&ah->iniModesRxGain,
822 ar9287Modes_rx_gain_9287_1_1,
823 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_1), 6);
824 else if (AR_SREV_9287_10(ah))
825 INIT_INI_ARRAY(&ah->iniModesRxGain,
826 ar9287Modes_rx_gain_9287_1_0,
827 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_0), 6);
828 else if (AR_SREV_9280_20(ah))
829 ath9k_hw_init_rxgain_ini(ah);
830
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530831 if (AR_SREV_9287_11_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530832 INIT_INI_ARRAY(&ah->iniModesTxGain,
833 ar9287Modes_tx_gain_9287_1_1,
834 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_1), 6);
835 } else if (AR_SREV_9287_10(ah)) {
836 INIT_INI_ARRAY(&ah->iniModesTxGain,
837 ar9287Modes_tx_gain_9287_1_0,
838 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_0), 6);
839 } else if (AR_SREV_9280_20(ah)) {
840 ath9k_hw_init_txgain_ini(ah);
841 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530842 u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
843
844 /* txgain table */
845 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) {
846 INIT_INI_ARRAY(&ah->iniModesTxGain,
847 ar9285Modes_high_power_tx_gain_9285_1_2,
848 ARRAY_SIZE(ar9285Modes_high_power_tx_gain_9285_1_2), 6);
849 } else {
850 INIT_INI_ARRAY(&ah->iniModesTxGain,
851 ar9285Modes_original_tx_gain_9285_1_2,
852 ARRAY_SIZE(ar9285Modes_original_tx_gain_9285_1_2), 6);
853 }
854
855 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700856}
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530857
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700858static void ath9k_hw_init_11a_eeprom_fix(struct ath_hw *ah)
859{
860 u32 i, j;
Sujith06d0f062009-02-12 10:06:45 +0530861
862 if ((ah->hw_version.devid == AR9280_DEVID_PCI) &&
863 test_bit(ATH9K_MODE_11A, ah->caps.wireless_modes)) {
864
865 /* EEPROM Fixup */
Sujith2660b812009-02-09 13:27:26 +0530866 for (i = 0; i < ah->iniModes.ia_rows; i++) {
867 u32 reg = INI_RA(&ah->iniModes, i, 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700868
Sujith2660b812009-02-09 13:27:26 +0530869 for (j = 1; j < ah->iniModes.ia_columns; j++) {
870 u32 val = INI_RA(&ah->iniModes, i, j);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700871
Sujith2660b812009-02-09 13:27:26 +0530872 INI_RA(&ah->iniModes, i, j) =
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530873 ath9k_hw_ini_fixup(ah,
Sujith2660b812009-02-09 13:27:26 +0530874 &ah->eeprom.def,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700875 reg, val);
876 }
877 }
878 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700879}
880
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700881int ath9k_hw_init(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700882{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700883 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700884 int r = 0;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700885
Luis R. Rodriguez3ca34032009-09-23 23:07:01 -0400886 if (!ath9k_hw_devid_supported(ah->hw_version.devid)) {
887 ath_print(common, ATH_DBG_FATAL,
888 "Unsupported device ID: 0x%0x\n",
889 ah->hw_version.devid);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700890 return -EOPNOTSUPP;
Luis R. Rodriguez3ca34032009-09-23 23:07:01 -0400891 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700892
893 ath9k_hw_init_defaults(ah);
894 ath9k_hw_init_config(ah);
895
896 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700897 ath_print(common, ATH_DBG_FATAL,
898 "Couldn't reset chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700899 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700900 }
901
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700902 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700903 ath_print(common, ATH_DBG_FATAL, "Couldn't wakeup chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700904 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700905 }
906
907 if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
908 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
909 (AR_SREV_9280(ah) && !ah->is_pciexpress)) {
910 ah->config.serialize_regmode =
911 SER_REG_MODE_ON;
912 } else {
913 ah->config.serialize_regmode =
914 SER_REG_MODE_OFF;
915 }
916 }
917
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700918 ath_print(common, ATH_DBG_RESET, "serialize_regmode is %d\n",
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700919 ah->config.serialize_regmode);
920
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -0500921 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
922 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD >> 1;
923 else
924 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD;
925
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700926 if (!ath9k_hw_macversion_supported(ah->hw_version.macVersion)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700927 ath_print(common, ATH_DBG_FATAL,
928 "Mac Chip Rev 0x%02x.%x is not supported by "
929 "this driver\n", ah->hw_version.macVersion,
930 ah->hw_version.macRev);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700931 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700932 }
933
934 if (AR_SREV_9100(ah)) {
935 ah->iq_caldata.calData = &iq_cal_multi_sample;
936 ah->supp_cals = IQ_MISMATCH_CAL;
937 ah->is_pciexpress = false;
938 }
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400939
940 if (AR_SREV_9271(ah))
941 ah->is_pciexpress = false;
942
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700943 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
944
945 ath9k_hw_init_cal_settings(ah);
946
947 ah->ani_function = ATH9K_ANI_ALL;
Luis R. Rodrigueze68a0602009-10-19 02:33:41 -0400948 if (AR_SREV_9280_10_OR_LATER(ah)) {
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700949 ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
Luis R. Rodrigueze68a0602009-10-19 02:33:41 -0400950 ah->ath9k_hw_rf_set_freq = &ath9k_hw_ar9280_set_channel;
Luis R. Rodriguezae478cf2009-10-19 02:33:43 -0400951 ah->ath9k_hw_spur_mitigate_freq = &ath9k_hw_9280_spur_mitigate;
952 } else {
Luis R. Rodrigueze68a0602009-10-19 02:33:41 -0400953 ah->ath9k_hw_rf_set_freq = &ath9k_hw_set_channel;
Luis R. Rodriguezae478cf2009-10-19 02:33:43 -0400954 ah->ath9k_hw_spur_mitigate_freq = &ath9k_hw_spur_mitigate;
955 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700956
957 ath9k_hw_init_mode_regs(ah);
958
959 if (ah->is_pciexpress)
Vivek Natarajan93b1b372009-09-17 09:24:58 +0530960 ath9k_hw_configpcipowersave(ah, 0, 0);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700961 else
962 ath9k_hw_disablepcie(ah);
963
Sujith193cd452009-09-18 15:04:07 +0530964 /* Support for Japan ch.14 (2484) spread */
965 if (AR_SREV_9287_11_OR_LATER(ah)) {
966 INIT_INI_ARRAY(&ah->iniCckfirNormal,
967 ar9287Common_normal_cck_fir_coeff_92871_1,
968 ARRAY_SIZE(ar9287Common_normal_cck_fir_coeff_92871_1), 2);
969 INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
970 ar9287Common_japan_2484_cck_fir_coeff_92871_1,
971 ARRAY_SIZE(ar9287Common_japan_2484_cck_fir_coeff_92871_1), 2);
972 }
973
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700974 r = ath9k_hw_post_init(ah);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700975 if (r)
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700976 return r;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700977
978 ath9k_hw_init_mode_gain_regs(ah);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +0100979 r = ath9k_hw_fill_cap_info(ah);
980 if (r)
981 return r;
982
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700983 ath9k_hw_init_11a_eeprom_fix(ah);
Sujithf6688cd2008-12-07 21:43:10 +0530984
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700985 r = ath9k_hw_init_macaddr(ah);
986 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700987 ath_print(common, ATH_DBG_FATAL,
988 "Failed to initialize MAC address\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700989 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700990 }
991
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400992 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
Sujith2660b812009-02-09 13:27:26 +0530993 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700994 else
Sujith2660b812009-02-09 13:27:26 +0530995 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700996
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700997 ath9k_init_nfcal_hist_buffer(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700998
Luis R. Rodriguez211f5852009-10-06 21:19:07 -0400999 common->state = ATH_HW_INITIALIZED;
1000
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001001 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001002}
1003
Sujithcbe61d82009-02-09 13:27:12 +05301004static void ath9k_hw_init_bb(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301005 struct ath9k_channel *chan)
1006{
1007 u32 synthDelay;
1008
1009 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +05301010 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +05301011 synthDelay = (4 * synthDelay) / 22;
1012 else
1013 synthDelay /= 10;
1014
1015 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
1016
1017 udelay(synthDelay + BASE_ACTIVATE_DELAY);
1018}
1019
Sujithcbe61d82009-02-09 13:27:12 +05301020static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301021{
1022 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
1023 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
1024
1025 REG_WRITE(ah, AR_QOS_NO_ACK,
1026 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
1027 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
1028 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
1029
1030 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
1031 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
1032 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
1033 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
1034 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
1035}
1036
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -04001037static void ath9k_hw_change_target_baud(struct ath_hw *ah, u32 freq, u32 baud)
1038{
1039 u32 lcr;
1040 u32 baud_divider = freq * 1000 * 1000 / 16 / baud;
1041
1042 lcr = REG_READ(ah , 0x5100c);
1043 lcr |= 0x80;
1044
1045 REG_WRITE(ah, 0x5100c, lcr);
1046 REG_WRITE(ah, 0x51004, (baud_divider >> 8));
1047 REG_WRITE(ah, 0x51000, (baud_divider & 0xff));
1048
1049 lcr &= ~0x80;
1050 REG_WRITE(ah, 0x5100c, lcr);
1051}
1052
Sujithcbe61d82009-02-09 13:27:12 +05301053static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301054 struct ath9k_channel *chan)
1055{
1056 u32 pll;
1057
1058 if (AR_SREV_9100(ah)) {
1059 if (chan && IS_CHAN_5GHZ(chan))
1060 pll = 0x1450;
1061 else
1062 pll = 0x1458;
1063 } else {
1064 if (AR_SREV_9280_10_OR_LATER(ah)) {
1065 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
1066
1067 if (chan && IS_CHAN_HALF_RATE(chan))
1068 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
1069 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1070 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
1071
1072 if (chan && IS_CHAN_5GHZ(chan)) {
1073 pll |= SM(0x28, AR_RTC_9160_PLL_DIV);
1074
1075
1076 if (AR_SREV_9280_20(ah)) {
1077 if (((chan->channel % 20) == 0)
1078 || ((chan->channel % 10) == 0))
1079 pll = 0x2850;
1080 else
1081 pll = 0x142c;
1082 }
1083 } else {
1084 pll |= SM(0x2c, AR_RTC_9160_PLL_DIV);
1085 }
1086
1087 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1088
1089 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
1090
1091 if (chan && IS_CHAN_HALF_RATE(chan))
1092 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
1093 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1094 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
1095
1096 if (chan && IS_CHAN_5GHZ(chan))
1097 pll |= SM(0x50, AR_RTC_9160_PLL_DIV);
1098 else
1099 pll |= SM(0x58, AR_RTC_9160_PLL_DIV);
1100 } else {
1101 pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2;
1102
1103 if (chan && IS_CHAN_HALF_RATE(chan))
1104 pll |= SM(0x1, AR_RTC_PLL_CLKSEL);
1105 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1106 pll |= SM(0x2, AR_RTC_PLL_CLKSEL);
1107
1108 if (chan && IS_CHAN_5GHZ(chan))
1109 pll |= SM(0xa, AR_RTC_PLL_DIV);
1110 else
1111 pll |= SM(0xb, AR_RTC_PLL_DIV);
1112 }
1113 }
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001114 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +05301115
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -04001116 /* Switch the core clock for ar9271 to 117Mhz */
1117 if (AR_SREV_9271(ah)) {
1118 if ((pll == 0x142c) || (pll == 0x2850) ) {
1119 udelay(500);
1120 /* set CLKOBS to output AHB clock */
1121 REG_WRITE(ah, 0x7020, 0xe);
1122 /*
1123 * 0x304: 117Mhz, ahb_ratio: 1x1
1124 * 0x306: 40Mhz, ahb_ratio: 1x1
1125 */
1126 REG_WRITE(ah, 0x50040, 0x304);
1127 /*
1128 * makes adjustments for the baud dividor to keep the
1129 * targetted baud rate based on the used core clock.
1130 */
1131 ath9k_hw_change_target_baud(ah, AR9271_CORE_CLOCK,
1132 AR9271_TARGET_BAUD_RATE);
1133 }
1134 }
1135
Sujithf1dc5602008-10-29 10:16:30 +05301136 udelay(RTC_PLL_SETTLE_DELAY);
1137
1138 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
1139}
1140
Sujithcbe61d82009-02-09 13:27:12 +05301141static void ath9k_hw_init_chain_masks(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301142{
Sujithf1dc5602008-10-29 10:16:30 +05301143 int rx_chainmask, tx_chainmask;
1144
Sujith2660b812009-02-09 13:27:26 +05301145 rx_chainmask = ah->rxchainmask;
1146 tx_chainmask = ah->txchainmask;
Sujithf1dc5602008-10-29 10:16:30 +05301147
1148 switch (rx_chainmask) {
1149 case 0x5:
1150 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1151 AR_PHY_SWAP_ALT_CHAIN);
1152 case 0x3:
Sujithcb53a152009-11-16 11:40:57 +05301153 if (ah->hw_version.macVersion == AR_SREV_REVISION_5416_10) {
Sujithf1dc5602008-10-29 10:16:30 +05301154 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7);
1155 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7);
1156 break;
1157 }
1158 case 0x1:
1159 case 0x2:
Sujithf1dc5602008-10-29 10:16:30 +05301160 case 0x7:
1161 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
1162 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
1163 break;
1164 default:
1165 break;
1166 }
1167
1168 REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);
1169 if (tx_chainmask == 0x5) {
1170 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1171 AR_PHY_SWAP_ALT_CHAIN);
1172 }
1173 if (AR_SREV_9100(ah))
1174 REG_WRITE(ah, AR_PHY_ANALOG_SWAP,
1175 REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
1176}
1177
Sujithcbe61d82009-02-09 13:27:12 +05301178static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -08001179 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301180{
Sujith2660b812009-02-09 13:27:26 +05301181 ah->mask_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +05301182 AR_IMR_TXURN |
1183 AR_IMR_RXERR |
1184 AR_IMR_RXORN |
1185 AR_IMR_BCNMISC;
1186
Sujith0ef1f162009-03-30 15:28:35 +05301187 if (ah->config.intr_mitigation)
Sujith2660b812009-02-09 13:27:26 +05301188 ah->mask_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
Sujithf1dc5602008-10-29 10:16:30 +05301189 else
Sujith2660b812009-02-09 13:27:26 +05301190 ah->mask_reg |= AR_IMR_RXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301191
Sujith2660b812009-02-09 13:27:26 +05301192 ah->mask_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301193
Colin McCabed97809d2008-12-01 13:38:55 -08001194 if (opmode == NL80211_IFTYPE_AP)
Sujith2660b812009-02-09 13:27:26 +05301195 ah->mask_reg |= AR_IMR_MIB;
Sujithf1dc5602008-10-29 10:16:30 +05301196
Sujith2660b812009-02-09 13:27:26 +05301197 REG_WRITE(ah, AR_IMR, ah->mask_reg);
Sujithf1dc5602008-10-29 10:16:30 +05301198 REG_WRITE(ah, AR_IMR_S2, REG_READ(ah, AR_IMR_S2) | AR_IMR_S2_GTT);
1199
1200 if (!AR_SREV_9100(ah)) {
1201 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
1202 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
1203 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
1204 }
1205}
1206
Sujithcbe61d82009-02-09 13:27:12 +05301207static bool ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301208{
Sujithf1dc5602008-10-29 10:16:30 +05301209 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001210 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1211 "bad ack timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301212 ah->acktimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301213 return false;
1214 } else {
1215 REG_RMW_FIELD(ah, AR_TIME_OUT,
1216 AR_TIME_OUT_ACK, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301217 ah->acktimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301218 return true;
1219 }
1220}
1221
Sujithcbe61d82009-02-09 13:27:12 +05301222static bool ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301223{
Sujithf1dc5602008-10-29 10:16:30 +05301224 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_CTS))) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001225 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1226 "bad cts timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301227 ah->ctstimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301228 return false;
1229 } else {
1230 REG_RMW_FIELD(ah, AR_TIME_OUT,
1231 AR_TIME_OUT_CTS, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301232 ah->ctstimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301233 return true;
1234 }
1235}
1236
Sujithcbe61d82009-02-09 13:27:12 +05301237static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +05301238{
Sujithf1dc5602008-10-29 10:16:30 +05301239 if (tu > 0xFFFF) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001240 ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT,
1241 "bad global tx timeout %u\n", tu);
Sujith2660b812009-02-09 13:27:26 +05301242 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301243 return false;
1244 } else {
1245 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +05301246 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +05301247 return true;
1248 }
1249}
1250
Sujithcbe61d82009-02-09 13:27:12 +05301251static void ath9k_hw_init_user_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301252{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001253 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
1254 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +05301255
Sujith2660b812009-02-09 13:27:26 +05301256 if (ah->misc_mode != 0)
Sujithf1dc5602008-10-29 10:16:30 +05301257 REG_WRITE(ah, AR_PCU_MISC,
Sujith2660b812009-02-09 13:27:26 +05301258 REG_READ(ah, AR_PCU_MISC) | ah->misc_mode);
1259 if (ah->slottime != (u32) -1)
1260 ath9k_hw_setslottime(ah, ah->slottime);
1261 if (ah->acktimeout != (u32) -1)
1262 ath9k_hw_set_ack_timeout(ah, ah->acktimeout);
1263 if (ah->ctstimeout != (u32) -1)
1264 ath9k_hw_set_cts_timeout(ah, ah->ctstimeout);
1265 if (ah->globaltxtimeout != (u32) -1)
1266 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Sujithf1dc5602008-10-29 10:16:30 +05301267}
1268
1269const char *ath9k_hw_probe(u16 vendorid, u16 devid)
1270{
1271 return vendorid == ATHEROS_VENDOR_ID ?
1272 ath9k_hw_devname(devid) : NULL;
1273}
1274
Sujithcbe61d82009-02-09 13:27:12 +05301275void ath9k_hw_detach(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001276{
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001277 struct ath_common *common = ath9k_hw_common(ah);
1278
1279 if (common->state <= ATH_HW_INITIALIZED)
1280 goto free_hw;
1281
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001282 if (!AR_SREV_9100(ah))
Luis R. Rodrigueze70c0cf2009-08-03 12:24:51 -07001283 ath9k_hw_ani_disable(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001284
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001285 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001286
1287free_hw:
Luis R. Rodriguezdc51dd52009-10-19 02:33:39 -04001288 if (!AR_SREV_9280_10_OR_LATER(ah))
1289 ath9k_hw_rf_free_ext_banks(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001290 kfree(ah);
Luis R. Rodriguez9db6b6a2009-08-03 12:24:52 -07001291 ah = NULL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001292}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001293EXPORT_SYMBOL(ath9k_hw_detach);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001294
Sujithf1dc5602008-10-29 10:16:30 +05301295/*******/
1296/* INI */
1297/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001298
Sujithcbe61d82009-02-09 13:27:12 +05301299static void ath9k_hw_override_ini(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301300 struct ath9k_channel *chan)
1301{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001302 u32 val;
1303
1304 if (AR_SREV_9271(ah)) {
1305 /*
1306 * Enable spectral scan to solution for issues with stuck
1307 * beacons on AR9271 1.0. The beacon stuck issue is not seeon on
1308 * AR9271 1.1
1309 */
1310 if (AR_SREV_9271_10(ah)) {
Luis R. Rodriguezec11bb82009-10-27 12:59:36 -04001311 val = REG_READ(ah, AR_PHY_SPECTRAL_SCAN) |
1312 AR_PHY_SPECTRAL_SCAN_ENABLE;
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001313 REG_WRITE(ah, AR_PHY_SPECTRAL_SCAN, val);
1314 }
1315 else if (AR_SREV_9271_11(ah))
1316 /*
1317 * change AR_PHY_RF_CTL3 setting to fix MAC issue
1318 * present on AR9271 1.1
1319 */
1320 REG_WRITE(ah, AR_PHY_RF_CTL3, 0x3a020001);
1321 return;
1322 }
1323
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +05301324 /*
1325 * Set the RX_ABORT and RX_DIS and clear if off only after
1326 * RXE is set for MAC. This prevents frames with corrupted
1327 * descriptor status.
1328 */
1329 REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
1330
Vasanthakumar Thiagarajan204d7942009-09-17 09:26:14 +05301331 if (AR_SREV_9280_10_OR_LATER(ah)) {
1332 val = REG_READ(ah, AR_PCU_MISC_MODE2) &
1333 (~AR_PCU_MISC_MODE2_HWWAR1);
1334
1335 if (AR_SREV_9287_10_OR_LATER(ah))
1336 val = val & (~AR_PCU_MISC_MODE2_HWWAR2);
1337
1338 REG_WRITE(ah, AR_PCU_MISC_MODE2, val);
1339 }
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +05301340
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001341 if (!AR_SREV_5416_20_OR_LATER(ah) ||
Sujithf1dc5602008-10-29 10:16:30 +05301342 AR_SREV_9280_10_OR_LATER(ah))
1343 return;
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001344 /*
1345 * Disable BB clock gating
1346 * Necessary to avoid issues on AR5416 2.0
1347 */
Sujithf1dc5602008-10-29 10:16:30 +05301348 REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
1349}
1350
Sujithcbe61d82009-02-09 13:27:12 +05301351static u32 ath9k_hw_def_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301352 struct ar5416_eeprom_def *pEepData,
Sujithf1dc5602008-10-29 10:16:30 +05301353 u32 reg, u32 value)
1354{
1355 struct base_eep_header *pBase = &(pEepData->baseEepHeader);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001356 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301357
Sujithd535a422009-02-09 13:27:06 +05301358 switch (ah->hw_version.devid) {
Sujithf1dc5602008-10-29 10:16:30 +05301359 case AR9280_DEVID_PCI:
1360 if (reg == 0x7894) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001361 ath_print(common, ATH_DBG_EEPROM,
Sujithf1dc5602008-10-29 10:16:30 +05301362 "ini VAL: %x EEPROM: %x\n", value,
1363 (pBase->version & 0xff));
1364
1365 if ((pBase->version & 0xff) > 0x0a) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001366 ath_print(common, ATH_DBG_EEPROM,
1367 "PWDCLKIND: %d\n",
1368 pBase->pwdclkind);
Sujithf1dc5602008-10-29 10:16:30 +05301369 value &= ~AR_AN_TOP2_PWDCLKIND;
1370 value |= AR_AN_TOP2_PWDCLKIND &
1371 (pBase->pwdclkind << AR_AN_TOP2_PWDCLKIND_S);
1372 } else {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001373 ath_print(common, ATH_DBG_EEPROM,
1374 "PWDCLKIND Earlier Rev\n");
Sujithf1dc5602008-10-29 10:16:30 +05301375 }
1376
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001377 ath_print(common, ATH_DBG_EEPROM,
1378 "final ini VAL: %x\n", value);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001379 }
Sujithf1dc5602008-10-29 10:16:30 +05301380 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001381 }
1382
Sujithf1dc5602008-10-29 10:16:30 +05301383 return value;
1384}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001385
Sujithcbe61d82009-02-09 13:27:12 +05301386static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301387 struct ar5416_eeprom_def *pEepData,
1388 u32 reg, u32 value)
1389{
Sujith2660b812009-02-09 13:27:26 +05301390 if (ah->eep_map == EEP_MAP_4KBITS)
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301391 return value;
1392 else
1393 return ath9k_hw_def_ini_fixup(ah, pEepData, reg, value);
1394}
1395
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301396static void ath9k_olc_init(struct ath_hw *ah)
1397{
1398 u32 i;
1399
Vivek Natarajandb91f2e2009-08-14 11:27:16 +05301400 if (OLC_FOR_AR9287_10_LATER) {
1401 REG_SET_BIT(ah, AR_PHY_TX_PWRCTRL9,
1402 AR_PHY_TX_PWRCTRL9_RES_DC_REMOVAL);
1403 ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TXPC0,
1404 AR9287_AN_TXPC0_TXPCMODE,
1405 AR9287_AN_TXPC0_TXPCMODE_S,
1406 AR9287_AN_TXPC0_TXPCMODE_TEMPSENSE);
1407 udelay(100);
1408 } else {
1409 for (i = 0; i < AR9280_TX_GAIN_TABLE_SIZE; i++)
1410 ah->originalGain[i] =
1411 MS(REG_READ(ah, AR_PHY_TX_GAIN_TBL1 + i * 4),
1412 AR_PHY_TX_GAIN);
1413 ah->PDADCdelta = 0;
1414 }
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301415}
1416
Bob Copeland3a702e42009-03-30 22:30:29 -04001417static u32 ath9k_regd_get_ctl(struct ath_regulatory *reg,
1418 struct ath9k_channel *chan)
1419{
1420 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
1421
1422 if (IS_CHAN_B(chan))
1423 ctl |= CTL_11B;
1424 else if (IS_CHAN_G(chan))
1425 ctl |= CTL_11G;
1426 else
1427 ctl |= CTL_11A;
1428
1429 return ctl;
1430}
1431
Sujithcbe61d82009-02-09 13:27:12 +05301432static int ath9k_hw_process_ini(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001433 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301434{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001435 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301436 int i, regWrites = 0;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001437 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301438 u32 modesIndex, freqIndex;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001439
Sujithf1dc5602008-10-29 10:16:30 +05301440 switch (chan->chanmode) {
1441 case CHANNEL_A:
1442 case CHANNEL_A_HT20:
1443 modesIndex = 1;
1444 freqIndex = 1;
1445 break;
1446 case CHANNEL_A_HT40PLUS:
1447 case CHANNEL_A_HT40MINUS:
1448 modesIndex = 2;
1449 freqIndex = 1;
1450 break;
1451 case CHANNEL_G:
1452 case CHANNEL_G_HT20:
1453 case CHANNEL_B:
1454 modesIndex = 4;
1455 freqIndex = 2;
1456 break;
1457 case CHANNEL_G_HT40PLUS:
1458 case CHANNEL_G_HT40MINUS:
1459 modesIndex = 3;
1460 freqIndex = 2;
1461 break;
1462
1463 default:
1464 return -EINVAL;
1465 }
1466
1467 REG_WRITE(ah, AR_PHY(0), 0x00000007);
Sujithf1dc5602008-10-29 10:16:30 +05301468 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
Sujithf74df6f2009-02-09 13:27:24 +05301469 ah->eep_ops->set_addac(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301470
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001471 if (AR_SREV_5416_22_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +05301472 REG_WRITE_ARRAY(&ah->iniAddac, 1, regWrites);
Sujithf1dc5602008-10-29 10:16:30 +05301473 } else {
1474 struct ar5416IniArray temp;
1475 u32 addacSize =
Sujith2660b812009-02-09 13:27:26 +05301476 sizeof(u32) * ah->iniAddac.ia_rows *
1477 ah->iniAddac.ia_columns;
Sujithf1dc5602008-10-29 10:16:30 +05301478
Sujith2660b812009-02-09 13:27:26 +05301479 memcpy(ah->addac5416_21,
1480 ah->iniAddac.ia_array, addacSize);
Sujithf1dc5602008-10-29 10:16:30 +05301481
Sujith2660b812009-02-09 13:27:26 +05301482 (ah->addac5416_21)[31 * ah->iniAddac.ia_columns + 1] = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301483
Sujith2660b812009-02-09 13:27:26 +05301484 temp.ia_array = ah->addac5416_21;
1485 temp.ia_columns = ah->iniAddac.ia_columns;
1486 temp.ia_rows = ah->iniAddac.ia_rows;
Sujithf1dc5602008-10-29 10:16:30 +05301487 REG_WRITE_ARRAY(&temp, 1, regWrites);
1488 }
1489
1490 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
1491
Sujith2660b812009-02-09 13:27:26 +05301492 for (i = 0; i < ah->iniModes.ia_rows; i++) {
1493 u32 reg = INI_RA(&ah->iniModes, i, 0);
1494 u32 val = INI_RA(&ah->iniModes, i, modesIndex);
Sujithf1dc5602008-10-29 10:16:30 +05301495
Sujithf1dc5602008-10-29 10:16:30 +05301496 REG_WRITE(ah, reg, val);
1497
1498 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301499 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301500 udelay(100);
1501 }
1502
1503 DO_DELAY(regWrites);
1504 }
1505
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301506 if (AR_SREV_9280(ah) || AR_SREV_9287_10_OR_LATER(ah))
Sujith2660b812009-02-09 13:27:26 +05301507 REG_WRITE_ARRAY(&ah->iniModesRxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301508
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301509 if (AR_SREV_9280(ah) || AR_SREV_9285_12_OR_LATER(ah) ||
1510 AR_SREV_9287_10_OR_LATER(ah))
Sujith2660b812009-02-09 13:27:26 +05301511 REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301512
Sujith2660b812009-02-09 13:27:26 +05301513 for (i = 0; i < ah->iniCommon.ia_rows; i++) {
1514 u32 reg = INI_RA(&ah->iniCommon, i, 0);
1515 u32 val = INI_RA(&ah->iniCommon, i, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301516
1517 REG_WRITE(ah, reg, val);
1518
1519 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301520 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301521 udelay(100);
1522 }
1523
1524 DO_DELAY(regWrites);
1525 }
1526
Luis R. Rodriguez896ff262009-10-19 02:33:44 -04001527 ath9k_hw_write_regs(ah, freqIndex, regWrites);
Sujithf1dc5602008-10-29 10:16:30 +05301528
Luis R. Rodriguez85643282009-10-19 02:33:33 -04001529 if (AR_SREV_9271_10(ah))
1530 REG_WRITE_ARRAY(&ah->iniModes_9271_1_0_only,
1531 modesIndex, regWrites);
1532
Sujithf1dc5602008-10-29 10:16:30 +05301533 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan)) {
Sujith2660b812009-02-09 13:27:26 +05301534 REG_WRITE_ARRAY(&ah->iniModesAdditional, modesIndex,
Sujithf1dc5602008-10-29 10:16:30 +05301535 regWrites);
1536 }
1537
1538 ath9k_hw_override_ini(ah, chan);
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001539 ath9k_hw_set_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301540 ath9k_hw_init_chain_masks(ah);
1541
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301542 if (OLC_FOR_AR9280_20_LATER)
1543 ath9k_olc_init(ah);
1544
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001545 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001546 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001547 channel->max_antenna_gain * 2,
1548 channel->max_power * 2,
1549 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001550 (u32) regulatory->power_limit));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001551
Sujithf1dc5602008-10-29 10:16:30 +05301552 if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001553 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1554 "ar5416SetRfRegs failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001555 return -EIO;
1556 }
1557
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001558 return 0;
1559}
1560
Sujithf1dc5602008-10-29 10:16:30 +05301561/****************************************/
1562/* Reset and Channel Switching Routines */
1563/****************************************/
1564
Sujithcbe61d82009-02-09 13:27:12 +05301565static void ath9k_hw_set_rfmode(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301566{
1567 u32 rfMode = 0;
1568
1569 if (chan == NULL)
1570 return;
1571
1572 rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
1573 ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
1574
1575 if (!AR_SREV_9280_10_OR_LATER(ah))
1576 rfMode |= (IS_CHAN_5GHZ(chan)) ?
1577 AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ;
1578
1579 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan))
1580 rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
1581
1582 REG_WRITE(ah, AR_PHY_MODE, rfMode);
1583}
1584
Sujithcbe61d82009-02-09 13:27:12 +05301585static void ath9k_hw_mark_phy_inactive(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301586{
1587 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
1588}
1589
Sujithcbe61d82009-02-09 13:27:12 +05301590static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301591{
1592 u32 regval;
1593
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001594 /*
1595 * set AHB_MODE not to do cacheline prefetches
1596 */
Sujithf1dc5602008-10-29 10:16:30 +05301597 regval = REG_READ(ah, AR_AHB_MODE);
1598 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
1599
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001600 /*
1601 * let mac dma reads be in 128 byte chunks
1602 */
Sujithf1dc5602008-10-29 10:16:30 +05301603 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
1604 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
1605
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001606 /*
1607 * Restore TX Trigger Level to its pre-reset value.
1608 * The initial value depends on whether aggregation is enabled, and is
1609 * adjusted whenever underruns are detected.
1610 */
Sujith2660b812009-02-09 13:27:26 +05301611 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +05301612
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001613 /*
1614 * let mac dma writes be in 128 byte chunks
1615 */
Sujithf1dc5602008-10-29 10:16:30 +05301616 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
1617 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
1618
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001619 /*
1620 * Setup receive FIFO threshold to hold off TX activities
1621 */
Sujithf1dc5602008-10-29 10:16:30 +05301622 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1623
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001624 /*
1625 * reduce the number of usable entries in PCU TXBUF to avoid
1626 * wrap around issues.
1627 */
Sujithf1dc5602008-10-29 10:16:30 +05301628 if (AR_SREV_9285(ah)) {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001629 /* For AR9285 the number of Fifos are reduced to half.
1630 * So set the usable tx buf size also to half to
1631 * avoid data/delimiter underruns
1632 */
Sujithf1dc5602008-10-29 10:16:30 +05301633 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1634 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001635 } else if (!AR_SREV_9271(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +05301636 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1637 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1638 }
1639}
1640
Sujithcbe61d82009-02-09 13:27:12 +05301641static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301642{
1643 u32 val;
1644
1645 val = REG_READ(ah, AR_STA_ID1);
1646 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
1647 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001648 case NL80211_IFTYPE_AP:
Sujithf1dc5602008-10-29 10:16:30 +05301649 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
1650 | AR_STA_ID1_KSRCH_MODE);
1651 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1652 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001653 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04001654 case NL80211_IFTYPE_MESH_POINT:
Sujithf1dc5602008-10-29 10:16:30 +05301655 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
1656 | AR_STA_ID1_KSRCH_MODE);
1657 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1658 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001659 case NL80211_IFTYPE_STATION:
1660 case NL80211_IFTYPE_MONITOR:
Sujithf1dc5602008-10-29 10:16:30 +05301661 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
1662 break;
1663 }
1664}
1665
Sujithcbe61d82009-02-09 13:27:12 +05301666static inline void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001667 u32 coef_scaled,
1668 u32 *coef_mantissa,
1669 u32 *coef_exponent)
1670{
1671 u32 coef_exp, coef_man;
1672
1673 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1674 if ((coef_scaled >> coef_exp) & 0x1)
1675 break;
1676
1677 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1678
1679 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1680
1681 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1682 *coef_exponent = coef_exp - 16;
1683}
1684
Sujithcbe61d82009-02-09 13:27:12 +05301685static void ath9k_hw_set_delta_slope(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301686 struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001687{
1688 u32 coef_scaled, ds_coef_exp, ds_coef_man;
1689 u32 clockMhzScaled = 0x64000000;
1690 struct chan_centers centers;
1691
1692 if (IS_CHAN_HALF_RATE(chan))
1693 clockMhzScaled = clockMhzScaled >> 1;
1694 else if (IS_CHAN_QUARTER_RATE(chan))
1695 clockMhzScaled = clockMhzScaled >> 2;
1696
1697 ath9k_hw_get_channel_centers(ah, chan, &centers);
1698 coef_scaled = clockMhzScaled / centers.synth_center;
1699
1700 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1701 &ds_coef_exp);
1702
1703 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1704 AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
1705 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1706 AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
1707
1708 coef_scaled = (9 * coef_scaled) / 10;
1709
1710 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1711 &ds_coef_exp);
1712
1713 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1714 AR_PHY_HALFGI_DSC_MAN, ds_coef_man);
1715 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1716 AR_PHY_HALFGI_DSC_EXP, ds_coef_exp);
1717}
1718
Sujithcbe61d82009-02-09 13:27:12 +05301719static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +05301720{
1721 u32 rst_flags;
1722 u32 tmpReg;
1723
Sujith70768492009-02-16 13:23:12 +05301724 if (AR_SREV_9100(ah)) {
1725 u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK);
1726 val &= ~AR_RTC_DERIVED_CLK_PERIOD;
1727 val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD);
1728 REG_WRITE(ah, AR_RTC_DERIVED_CLK, val);
1729 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1730 }
1731
Sujithf1dc5602008-10-29 10:16:30 +05301732 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1733 AR_RTC_FORCE_WAKE_ON_INT);
1734
1735 if (AR_SREV_9100(ah)) {
1736 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1737 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1738 } else {
1739 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1740 if (tmpReg &
1741 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1742 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
1743 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
1744 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1745 } else {
1746 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1747 }
1748
1749 rst_flags = AR_RTC_RC_MAC_WARM;
1750 if (type == ATH9K_RESET_COLD)
1751 rst_flags |= AR_RTC_RC_MAC_COLD;
1752 }
1753
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001754 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujithf1dc5602008-10-29 10:16:30 +05301755 udelay(50);
1756
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001757 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301758 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001759 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1760 "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301761 return false;
1762 }
1763
1764 if (!AR_SREV_9100(ah))
1765 REG_WRITE(ah, AR_RC, 0);
1766
Sujithf1dc5602008-10-29 10:16:30 +05301767 if (AR_SREV_9100(ah))
1768 udelay(50);
1769
1770 return true;
1771}
1772
Sujithcbe61d82009-02-09 13:27:12 +05301773static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301774{
1775 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1776 AR_RTC_FORCE_WAKE_ON_INT);
1777
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301778 if (!AR_SREV_9100(ah))
1779 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1780
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001781 REG_WRITE(ah, AR_RTC_RESET, 0);
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301782 udelay(2);
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301783
1784 if (!AR_SREV_9100(ah))
1785 REG_WRITE(ah, AR_RC, 0);
1786
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001787 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301788
1789 if (!ath9k_hw_wait(ah,
1790 AR_RTC_STATUS,
1791 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301792 AR_RTC_STATUS_ON,
1793 AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001794 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1795 "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301796 return false;
1797 }
1798
1799 ath9k_hw_read_revisions(ah);
1800
1801 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1802}
1803
Sujithcbe61d82009-02-09 13:27:12 +05301804static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301805{
1806 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1807 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1808
1809 switch (type) {
1810 case ATH9K_RESET_POWER_ON:
1811 return ath9k_hw_set_reset_power_on(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301812 case ATH9K_RESET_WARM:
1813 case ATH9K_RESET_COLD:
1814 return ath9k_hw_set_reset(ah, type);
Sujithf1dc5602008-10-29 10:16:30 +05301815 default:
1816 return false;
1817 }
1818}
1819
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001820static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301821{
1822 u32 phymode;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301823 u32 enableDacFifo = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301824
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301825 if (AR_SREV_9285_10_OR_LATER(ah))
1826 enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) &
1827 AR_PHY_FC_ENABLE_DAC_FIFO);
1828
Sujithf1dc5602008-10-29 10:16:30 +05301829 phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301830 | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo;
Sujithf1dc5602008-10-29 10:16:30 +05301831
1832 if (IS_CHAN_HT40(chan)) {
1833 phymode |= AR_PHY_FC_DYN2040_EN;
1834
1835 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
1836 (chan->chanmode == CHANNEL_G_HT40PLUS))
1837 phymode |= AR_PHY_FC_DYN2040_PRI_CH;
1838
Sujithf1dc5602008-10-29 10:16:30 +05301839 }
1840 REG_WRITE(ah, AR_PHY_TURBO, phymode);
1841
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001842 ath9k_hw_set11nmac2040(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301843
1844 REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
1845 REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
1846}
1847
Sujithcbe61d82009-02-09 13:27:12 +05301848static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301849 struct ath9k_channel *chan)
1850{
Vivek Natarajan42abfbe2009-09-17 09:27:59 +05301851 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) {
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301852 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
1853 return false;
1854 } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
Sujithf1dc5602008-10-29 10:16:30 +05301855 return false;
1856
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001857 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05301858 return false;
1859
Sujith2660b812009-02-09 13:27:26 +05301860 ah->chip_fullsleep = false;
Sujithf1dc5602008-10-29 10:16:30 +05301861 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301862 ath9k_hw_set_rfmode(ah, chan);
1863
1864 return true;
1865}
1866
Sujithcbe61d82009-02-09 13:27:12 +05301867static bool ath9k_hw_channel_change(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001868 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301869{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001870 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001871 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001872 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301873 u32 synthDelay, qnum;
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001874 int r;
Sujithf1dc5602008-10-29 10:16:30 +05301875
1876 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1877 if (ath9k_hw_numtxpending(ah, qnum)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001878 ath_print(common, ATH_DBG_QUEUE,
1879 "Transmit frames pending on "
1880 "queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301881 return false;
1882 }
1883 }
1884
1885 REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
1886 if (!ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
Sujith0caa7b12009-02-16 13:23:20 +05301887 AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001888 ath_print(common, ATH_DBG_FATAL,
1889 "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301890 return false;
1891 }
1892
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001893 ath9k_hw_set_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301894
Luis R. Rodrigueze68a0602009-10-19 02:33:41 -04001895 r = ah->ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001896 if (r) {
1897 ath_print(common, ATH_DBG_FATAL,
1898 "Failed to set channel\n");
1899 return false;
Sujithf1dc5602008-10-29 10:16:30 +05301900 }
1901
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001902 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001903 ath9k_regd_get_ctl(regulatory, chan),
Sujithf74df6f2009-02-09 13:27:24 +05301904 channel->max_antenna_gain * 2,
1905 channel->max_power * 2,
1906 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001907 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05301908
1909 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +05301910 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +05301911 synthDelay = (4 * synthDelay) / 22;
1912 else
1913 synthDelay /= 10;
1914
1915 udelay(synthDelay + BASE_ACTIVATE_DELAY);
1916
1917 REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
1918
1919 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1920 ath9k_hw_set_delta_slope(ah, chan);
1921
Luis R. Rodriguezae478cf2009-10-19 02:33:43 -04001922 ah->ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301923
1924 if (!chan->oneTimeCalsDone)
1925 chan->oneTimeCalsDone = true;
1926
1927 return true;
1928}
1929
Johannes Berg3b319aa2009-06-13 14:50:26 +05301930static void ath9k_enable_rfkill(struct ath_hw *ah)
1931{
1932 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
1933 AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
1934
1935 REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2,
1936 AR_GPIO_INPUT_MUX2_RFSILENT);
1937
1938 ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
1939 REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);
1940}
1941
Sujithcbe61d82009-02-09 13:27:12 +05301942int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001943 bool bChannelChange)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001944{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001945 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001946 u32 saveLedState;
Sujith2660b812009-02-09 13:27:26 +05301947 struct ath9k_channel *curchan = ah->curchan;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001948 u32 saveDefAntenna;
1949 u32 macStaId1;
Sujith46fe7822009-09-17 09:25:25 +05301950 u64 tsf = 0;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001951 int i, rx_chainmask, r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001952
Luis R. Rodriguez43c27612009-09-13 21:07:07 -07001953 ah->txchainmask = common->tx_chainmask;
1954 ah->rxchainmask = common->rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001955
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001956 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001957 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001958
Vasanthakumar Thiagarajan9ebef792009-09-17 09:26:44 +05301959 if (curchan && !ah->chip_fullsleep)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001960 ath9k_hw_getnf(ah, curchan);
1961
1962 if (bChannelChange &&
Sujith2660b812009-02-09 13:27:26 +05301963 (ah->chip_fullsleep != true) &&
1964 (ah->curchan != NULL) &&
1965 (chan->channel != ah->curchan->channel) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001966 ((chan->channelFlags & CHANNEL_ALL) ==
Sujith2660b812009-02-09 13:27:26 +05301967 (ah->curchan->channelFlags & CHANNEL_ALL)) &&
Vasanthakumar Thiagarajan0a475cc2009-09-17 09:27:10 +05301968 !(AR_SREV_9280(ah) || IS_CHAN_A_5MHZ_SPACED(chan) ||
1969 IS_CHAN_A_5MHZ_SPACED(ah->curchan))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001970
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001971 if (ath9k_hw_channel_change(ah, chan)) {
Sujith2660b812009-02-09 13:27:26 +05301972 ath9k_hw_loadnf(ah, ah->curchan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001973 ath9k_hw_start_nfcal(ah);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001974 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001975 }
1976 }
1977
1978 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
1979 if (saveDefAntenna == 0)
1980 saveDefAntenna = 1;
1981
1982 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
1983
Sujith46fe7822009-09-17 09:25:25 +05301984 /* For chips on which RTC reset is done, save TSF before it gets cleared */
1985 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1986 tsf = ath9k_hw_gettsf64(ah);
1987
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001988 saveLedState = REG_READ(ah, AR_CFG_LED) &
1989 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
1990 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
1991
1992 ath9k_hw_mark_phy_inactive(ah);
1993
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001994 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1995 REG_WRITE(ah,
1996 AR9271_RESET_POWER_DOWN_CONTROL,
1997 AR9271_RADIO_RF_RST);
1998 udelay(50);
1999 }
2000
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002001 if (!ath9k_hw_chip_reset(ah, chan)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002002 ath_print(common, ATH_DBG_FATAL, "Chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002003 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002004 }
2005
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002006 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
2007 ah->htc_reset_init = false;
2008 REG_WRITE(ah,
2009 AR9271_RESET_POWER_DOWN_CONTROL,
2010 AR9271_GATE_MAC_CTL);
2011 udelay(50);
2012 }
2013
Sujith46fe7822009-09-17 09:25:25 +05302014 /* Restore TSF */
2015 if (tsf && AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
2016 ath9k_hw_settsf64(ah, tsf);
2017
Vasanthakumar Thiagarajan369391d2009-01-21 19:24:13 +05302018 if (AR_SREV_9280_10_OR_LATER(ah))
2019 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002020
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302021 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302022 /* Enable ASYNC FIFO */
2023 REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2024 AR_MAC_PCU_ASYNC_FIFO_REG3_DATAPATH_SEL);
2025 REG_SET_BIT(ah, AR_PHY_MODE, AR_PHY_MODE_ASYNCFIFO);
2026 REG_CLR_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2027 AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
2028 REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2029 AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
2030 }
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002031 r = ath9k_hw_process_ini(ah, chan);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002032 if (r)
2033 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002034
Jouni Malinen0ced0e12009-01-08 13:32:13 +02002035 /* Setup MFP options for CCMP */
2036 if (AR_SREV_9280_20_OR_LATER(ah)) {
2037 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
2038 * frames when constructing CCMP AAD. */
2039 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
2040 0xc7ff);
2041 ah->sw_mgmt_crypto = false;
2042 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
2043 /* Disable hardware crypto for management frames */
2044 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
2045 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
2046 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
2047 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
2048 ah->sw_mgmt_crypto = true;
2049 } else
2050 ah->sw_mgmt_crypto = true;
2051
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002052 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
2053 ath9k_hw_set_delta_slope(ah, chan);
2054
Luis R. Rodriguezae478cf2009-10-19 02:33:43 -04002055 ah->ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithd6509152009-03-13 08:56:05 +05302056 ah->eep_ops->set_board_values(ah, chan);
Luis R. Rodrigueza7765822009-10-19 02:33:45 -04002057
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002058 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
2059 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002060 | macStaId1
2061 | AR_STA_ID1_RTS_USE_DEF
Sujith2660b812009-02-09 13:27:26 +05302062 | (ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302063 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Sujith2660b812009-02-09 13:27:26 +05302064 | ah->sta_id1_defaults);
2065 ath9k_hw_set_operating_mode(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002066
Luis R. Rodriguez13b81552009-09-10 17:52:45 -07002067 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002068
2069 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
2070
Luis R. Rodriguez3453ad82009-09-10 08:57:00 -07002071 ath9k_hw_write_associd(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002072
2073 REG_WRITE(ah, AR_ISR, ~0);
2074
2075 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
2076
Luis R. Rodrigueze68a0602009-10-19 02:33:41 -04002077 r = ah->ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04002078 if (r)
2079 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002080
2081 for (i = 0; i < AR_NUM_DCU; i++)
2082 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
2083
Sujith2660b812009-02-09 13:27:26 +05302084 ah->intr_txqs = 0;
2085 for (i = 0; i < ah->caps.total_queues; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002086 ath9k_hw_resettxqueue(ah, i);
2087
Sujith2660b812009-02-09 13:27:26 +05302088 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002089 ath9k_hw_init_qos(ah);
2090
Sujith2660b812009-02-09 13:27:26 +05302091 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05302092 ath9k_enable_rfkill(ah);
Johannes Berg3b319aa2009-06-13 14:50:26 +05302093
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002094 ath9k_hw_init_user_settings(ah);
2095
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302096 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302097 REG_WRITE(ah, AR_D_GBL_IFS_SIFS,
2098 AR_D_GBL_IFS_SIFS_ASYNC_FIFO_DUR);
2099 REG_WRITE(ah, AR_D_GBL_IFS_SLOT,
2100 AR_D_GBL_IFS_SLOT_ASYNC_FIFO_DUR);
2101 REG_WRITE(ah, AR_D_GBL_IFS_EIFS,
2102 AR_D_GBL_IFS_EIFS_ASYNC_FIFO_DUR);
2103
2104 REG_WRITE(ah, AR_TIME_OUT, AR_TIME_OUT_ACK_CTS_ASYNC_FIFO_DUR);
2105 REG_WRITE(ah, AR_USEC, AR_USEC_ASYNC_FIFO_DUR);
2106
2107 REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
2108 AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
2109 REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
2110 AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
2111 }
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302112 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302113 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
2114 AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
2115 }
2116
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002117 REG_WRITE(ah, AR_STA_ID1,
2118 REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
2119
2120 ath9k_hw_set_dma(ah);
2121
2122 REG_WRITE(ah, AR_OBS, 8);
2123
Sujith0ef1f162009-03-30 15:28:35 +05302124 if (ah->config.intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002125 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
2126 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
2127 }
2128
2129 ath9k_hw_init_bb(ah, chan);
2130
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002131 if (!ath9k_hw_init_cal(ah, chan))
Joe Perches6badaaf2009-06-28 09:26:32 -07002132 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002133
Sujith2660b812009-02-09 13:27:26 +05302134 rx_chainmask = ah->rxchainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002135 if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) {
2136 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
2137 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
2138 }
2139
2140 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
2141
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002142 /*
2143 * For big endian systems turn on swapping for descriptors
2144 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002145 if (AR_SREV_9100(ah)) {
2146 u32 mask;
2147 mask = REG_READ(ah, AR_CFG);
2148 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002149 ath_print(common, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05302150 "CFG Byte Swap Set 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002151 } else {
2152 mask =
2153 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
2154 REG_WRITE(ah, AR_CFG, mask);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002155 ath_print(common, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05302156 "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002157 }
2158 } else {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002159 /* Configure AR9271 target WLAN */
2160 if (AR_SREV_9271(ah))
2161 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002162#ifdef __BIG_ENDIAN
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002163 else
2164 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002165#endif
2166 }
2167
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002168 if (ah->btcoex_hw.enabled)
Vasanthakumar Thiagarajan42cc41e2009-08-26 21:08:45 +05302169 ath9k_hw_btcoex_enable(ah);
2170
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002171 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002172}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002173EXPORT_SYMBOL(ath9k_hw_reset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002174
Sujithf1dc5602008-10-29 10:16:30 +05302175/************************/
2176/* Key Cache Management */
2177/************************/
2178
Sujithcbe61d82009-02-09 13:27:12 +05302179bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002180{
Sujithf1dc5602008-10-29 10:16:30 +05302181 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002182
Sujith2660b812009-02-09 13:27:26 +05302183 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002184 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2185 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002186 return false;
2187 }
2188
Sujithf1dc5602008-10-29 10:16:30 +05302189 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002190
Sujithf1dc5602008-10-29 10:16:30 +05302191 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
2192 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
2193 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
2194 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
2195 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
2196 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
2197 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
2198 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
2199
2200 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2201 u16 micentry = entry + 64;
2202
2203 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
2204 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
2205 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
2206 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
2207
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002208 }
2209
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002210 return true;
2211}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002212EXPORT_SYMBOL(ath9k_hw_keyreset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002213
Sujithcbe61d82009-02-09 13:27:12 +05302214bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002215{
Sujithf1dc5602008-10-29 10:16:30 +05302216 u32 macHi, macLo;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002217
Sujith2660b812009-02-09 13:27:26 +05302218 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002219 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2220 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002221 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002222 }
2223
Sujithf1dc5602008-10-29 10:16:30 +05302224 if (mac != NULL) {
2225 macHi = (mac[5] << 8) | mac[4];
2226 macLo = (mac[3] << 24) |
2227 (mac[2] << 16) |
2228 (mac[1] << 8) |
2229 mac[0];
2230 macLo >>= 1;
2231 macLo |= (macHi & 1) << 31;
2232 macHi >>= 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002233 } else {
Sujithf1dc5602008-10-29 10:16:30 +05302234 macLo = macHi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002235 }
Sujithf1dc5602008-10-29 10:16:30 +05302236 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
2237 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002238
2239 return true;
2240}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002241EXPORT_SYMBOL(ath9k_hw_keysetmac);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002242
Sujithcbe61d82009-02-09 13:27:12 +05302243bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
Sujithf1dc5602008-10-29 10:16:30 +05302244 const struct ath9k_keyval *k,
Jouni Malinene0caf9e2009-03-02 18:15:53 +02002245 const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002246{
Sujith2660b812009-02-09 13:27:26 +05302247 const struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002248 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302249 u32 key0, key1, key2, key3, key4;
2250 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002251
Sujithf1dc5602008-10-29 10:16:30 +05302252 if (entry >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002253 ath_print(common, ATH_DBG_FATAL,
2254 "keycache entry %u out of range\n", entry);
Sujithf1dc5602008-10-29 10:16:30 +05302255 return false;
2256 }
2257
2258 switch (k->kv_type) {
2259 case ATH9K_CIPHER_AES_OCB:
2260 keyType = AR_KEYTABLE_TYPE_AES;
2261 break;
2262 case ATH9K_CIPHER_AES_CCM:
2263 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002264 ath_print(common, ATH_DBG_ANY,
2265 "AES-CCM not supported by mac rev 0x%x\n",
2266 ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002267 return false;
2268 }
Sujithf1dc5602008-10-29 10:16:30 +05302269 keyType = AR_KEYTABLE_TYPE_CCM;
2270 break;
2271 case ATH9K_CIPHER_TKIP:
2272 keyType = AR_KEYTABLE_TYPE_TKIP;
2273 if (ATH9K_IS_MIC_ENABLED(ah)
2274 && entry + 64 >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002275 ath_print(common, ATH_DBG_ANY,
2276 "entry %u inappropriate for TKIP\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002277 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002278 }
Sujithf1dc5602008-10-29 10:16:30 +05302279 break;
2280 case ATH9K_CIPHER_WEP:
Zhu Yie31a16d2009-05-21 21:47:03 +08002281 if (k->kv_len < WLAN_KEY_LEN_WEP40) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002282 ath_print(common, ATH_DBG_ANY,
2283 "WEP key length %u too small\n", k->kv_len);
Sujithf1dc5602008-10-29 10:16:30 +05302284 return false;
2285 }
Zhu Yie31a16d2009-05-21 21:47:03 +08002286 if (k->kv_len <= WLAN_KEY_LEN_WEP40)
Sujithf1dc5602008-10-29 10:16:30 +05302287 keyType = AR_KEYTABLE_TYPE_40;
Zhu Yie31a16d2009-05-21 21:47:03 +08002288 else if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05302289 keyType = AR_KEYTABLE_TYPE_104;
2290 else
2291 keyType = AR_KEYTABLE_TYPE_128;
2292 break;
2293 case ATH9K_CIPHER_CLR:
2294 keyType = AR_KEYTABLE_TYPE_CLR;
2295 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002296 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002297 ath_print(common, ATH_DBG_FATAL,
2298 "cipher %u not supported\n", k->kv_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002299 return false;
2300 }
Sujithf1dc5602008-10-29 10:16:30 +05302301
Jouni Malinene0caf9e2009-03-02 18:15:53 +02002302 key0 = get_unaligned_le32(k->kv_val + 0);
2303 key1 = get_unaligned_le16(k->kv_val + 4);
2304 key2 = get_unaligned_le32(k->kv_val + 6);
2305 key3 = get_unaligned_le16(k->kv_val + 10);
2306 key4 = get_unaligned_le32(k->kv_val + 12);
Zhu Yie31a16d2009-05-21 21:47:03 +08002307 if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05302308 key4 &= 0xff;
2309
Jouni Malinen672903b2009-03-02 15:06:31 +02002310 /*
2311 * Note: Key cache registers access special memory area that requires
2312 * two 32-bit writes to actually update the values in the internal
2313 * memory. Consequently, the exact order and pairs used here must be
2314 * maintained.
2315 */
2316
Sujithf1dc5602008-10-29 10:16:30 +05302317 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2318 u16 micentry = entry + 64;
2319
Jouni Malinen672903b2009-03-02 15:06:31 +02002320 /*
2321 * Write inverted key[47:0] first to avoid Michael MIC errors
2322 * on frames that could be sent or received at the same time.
2323 * The correct key will be written in the end once everything
2324 * else is ready.
2325 */
Sujithf1dc5602008-10-29 10:16:30 +05302326 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
2327 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002328
2329 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302330 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2331 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002332
2333 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302334 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2335 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
Jouni Malinen672903b2009-03-02 15:06:31 +02002336
2337 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302338 (void) ath9k_hw_keysetmac(ah, entry, mac);
2339
Sujith2660b812009-02-09 13:27:26 +05302340 if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) {
Jouni Malinen672903b2009-03-02 15:06:31 +02002341 /*
2342 * TKIP uses two key cache entries:
2343 * Michael MIC TX/RX keys in the same key cache entry
2344 * (idx = main index + 64):
2345 * key0 [31:0] = RX key [31:0]
2346 * key1 [15:0] = TX key [31:16]
2347 * key1 [31:16] = reserved
2348 * key2 [31:0] = RX key [63:32]
2349 * key3 [15:0] = TX key [15:0]
2350 * key3 [31:16] = reserved
2351 * key4 [31:0] = TX key [63:32]
2352 */
Sujithf1dc5602008-10-29 10:16:30 +05302353 u32 mic0, mic1, mic2, mic3, mic4;
2354
2355 mic0 = get_unaligned_le32(k->kv_mic + 0);
2356 mic2 = get_unaligned_le32(k->kv_mic + 4);
2357 mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
2358 mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
2359 mic4 = get_unaligned_le32(k->kv_txmic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02002360
2361 /* Write RX[31:0] and TX[31:16] */
Sujithf1dc5602008-10-29 10:16:30 +05302362 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2363 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002364
2365 /* Write RX[63:32] and TX[15:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302366 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2367 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002368
2369 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302370 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
2371 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2372 AR_KEYTABLE_TYPE_CLR);
2373
2374 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002375 /*
2376 * TKIP uses four key cache entries (two for group
2377 * keys):
2378 * Michael MIC TX/RX keys are in different key cache
2379 * entries (idx = main index + 64 for TX and
2380 * main index + 32 + 96 for RX):
2381 * key0 [31:0] = TX/RX MIC key [31:0]
2382 * key1 [31:0] = reserved
2383 * key2 [31:0] = TX/RX MIC key [63:32]
2384 * key3 [31:0] = reserved
2385 * key4 [31:0] = reserved
2386 *
2387 * Upper layer code will call this function separately
2388 * for TX and RX keys when these registers offsets are
2389 * used.
2390 */
Sujithf1dc5602008-10-29 10:16:30 +05302391 u32 mic0, mic2;
2392
2393 mic0 = get_unaligned_le32(k->kv_mic + 0);
2394 mic2 = get_unaligned_le32(k->kv_mic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02002395
2396 /* Write MIC key[31:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302397 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2398 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002399
2400 /* Write MIC key[63:32] */
Sujithf1dc5602008-10-29 10:16:30 +05302401 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2402 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002403
2404 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302405 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
2406 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2407 AR_KEYTABLE_TYPE_CLR);
2408 }
Jouni Malinen672903b2009-03-02 15:06:31 +02002409
2410 /* MAC address registers are reserved for the MIC entry */
Sujithf1dc5602008-10-29 10:16:30 +05302411 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
2412 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002413
2414 /*
2415 * Write the correct (un-inverted) key[47:0] last to enable
2416 * TKIP now that all other registers are set with correct
2417 * values.
2418 */
Sujithf1dc5602008-10-29 10:16:30 +05302419 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2420 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
2421 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002422 /* Write key[47:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302423 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2424 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002425
2426 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302427 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2428 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002429
2430 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302431 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2432 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
2433
Jouni Malinen672903b2009-03-02 15:06:31 +02002434 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302435 (void) ath9k_hw_keysetmac(ah, entry, mac);
2436 }
2437
Sujithf1dc5602008-10-29 10:16:30 +05302438 return true;
2439}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002440EXPORT_SYMBOL(ath9k_hw_set_keycache_entry);
Sujithf1dc5602008-10-29 10:16:30 +05302441
Sujithcbe61d82009-02-09 13:27:12 +05302442bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry)
Sujithf1dc5602008-10-29 10:16:30 +05302443{
Sujith2660b812009-02-09 13:27:26 +05302444 if (entry < ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05302445 u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
2446 if (val & AR_KEYTABLE_VALID)
2447 return true;
2448 }
2449 return false;
2450}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002451EXPORT_SYMBOL(ath9k_hw_keyisvalid);
Sujithf1dc5602008-10-29 10:16:30 +05302452
2453/******************************/
2454/* Power Management (Chipset) */
2455/******************************/
2456
Sujithcbe61d82009-02-09 13:27:12 +05302457static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302458{
2459 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2460 if (setChip) {
2461 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2462 AR_RTC_FORCE_WAKE_EN);
2463 if (!AR_SREV_9100(ah))
2464 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
2465
Sujith4921be82009-09-18 15:04:27 +05302466 if(!AR_SREV_5416(ah))
2467 REG_CLR_BIT(ah, (AR_RTC_RESET),
2468 AR_RTC_RESET_EN);
Sujithf1dc5602008-10-29 10:16:30 +05302469 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002470}
2471
Sujithcbe61d82009-02-09 13:27:12 +05302472static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002473{
Sujithf1dc5602008-10-29 10:16:30 +05302474 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2475 if (setChip) {
Sujith2660b812009-02-09 13:27:26 +05302476 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002477
Sujithf1dc5602008-10-29 10:16:30 +05302478 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
2479 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2480 AR_RTC_FORCE_WAKE_ON_INT);
2481 } else {
2482 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2483 AR_RTC_FORCE_WAKE_EN);
2484 }
2485 }
2486}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002487
Sujithcbe61d82009-02-09 13:27:12 +05302488static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302489{
2490 u32 val;
2491 int i;
2492
2493 if (setChip) {
2494 if ((REG_READ(ah, AR_RTC_STATUS) &
2495 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2496 if (ath9k_hw_set_reset_reg(ah,
2497 ATH9K_RESET_POWER_ON) != true) {
2498 return false;
2499 }
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05302500 ath9k_hw_init_pll(ah, NULL);
Sujithf1dc5602008-10-29 10:16:30 +05302501 }
2502 if (AR_SREV_9100(ah))
2503 REG_SET_BIT(ah, AR_RTC_RESET,
2504 AR_RTC_RESET_EN);
2505
2506 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2507 AR_RTC_FORCE_WAKE_EN);
2508 udelay(50);
2509
2510 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2511 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2512 if (val == AR_RTC_STATUS_ON)
2513 break;
2514 udelay(50);
2515 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2516 AR_RTC_FORCE_WAKE_EN);
2517 }
2518 if (i == 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002519 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2520 "Failed to wakeup in %uus\n",
2521 POWER_UP_TIME / 20);
Sujithf1dc5602008-10-29 10:16:30 +05302522 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002523 }
2524 }
2525
Sujithf1dc5602008-10-29 10:16:30 +05302526 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2527
2528 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002529}
2530
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002531bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05302532{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002533 struct ath_common *common = ath9k_hw_common(ah);
Sujithcbe61d82009-02-09 13:27:12 +05302534 int status = true, setChip = true;
Sujithf1dc5602008-10-29 10:16:30 +05302535 static const char *modes[] = {
2536 "AWAKE",
2537 "FULL-SLEEP",
2538 "NETWORK SLEEP",
2539 "UNDEFINED"
2540 };
Sujithf1dc5602008-10-29 10:16:30 +05302541
Gabor Juhoscbdec972009-07-24 17:27:22 +02002542 if (ah->power_mode == mode)
2543 return status;
2544
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002545 ath_print(common, ATH_DBG_RESET, "%s -> %s\n",
2546 modes[ah->power_mode], modes[mode]);
Sujithf1dc5602008-10-29 10:16:30 +05302547
2548 switch (mode) {
2549 case ATH9K_PM_AWAKE:
2550 status = ath9k_hw_set_power_awake(ah, setChip);
2551 break;
2552 case ATH9K_PM_FULL_SLEEP:
2553 ath9k_set_power_sleep(ah, setChip);
Sujith2660b812009-02-09 13:27:26 +05302554 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05302555 break;
2556 case ATH9K_PM_NETWORK_SLEEP:
2557 ath9k_set_power_network_sleep(ah, setChip);
2558 break;
2559 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002560 ath_print(common, ATH_DBG_FATAL,
2561 "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05302562 return false;
2563 }
Sujith2660b812009-02-09 13:27:26 +05302564 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05302565
2566 return status;
2567}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002568EXPORT_SYMBOL(ath9k_hw_setpower);
Sujithf1dc5602008-10-29 10:16:30 +05302569
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002570/*
2571 * Helper for ASPM support.
2572 *
2573 * Disable PLL when in L0s as well as receiver clock when in L1.
2574 * This power saving option must be enabled through the SerDes.
2575 *
2576 * Programming the SerDes must go through the same 288 bit serial shift
2577 * register as the other analog registers. Hence the 9 writes.
2578 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302579void ath9k_hw_configpcipowersave(struct ath_hw *ah, int restore, int power_off)
Sujithf1dc5602008-10-29 10:16:30 +05302580{
Sujithf1dc5602008-10-29 10:16:30 +05302581 u8 i;
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302582 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05302583
Sujith2660b812009-02-09 13:27:26 +05302584 if (ah->is_pciexpress != true)
Sujithf1dc5602008-10-29 10:16:30 +05302585 return;
2586
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002587 /* Do not touch SerDes registers */
Sujith2660b812009-02-09 13:27:26 +05302588 if (ah->config.pcie_powersave_enable == 2)
Sujithf1dc5602008-10-29 10:16:30 +05302589 return;
2590
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002591 /* Nothing to do on restore for 11N */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302592 if (!restore) {
2593 if (AR_SREV_9280_20_OR_LATER(ah)) {
2594 /*
2595 * AR9280 2.0 or later chips use SerDes values from the
2596 * initvals.h initialized depending on chipset during
2597 * ath9k_hw_init()
2598 */
2599 for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
2600 REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
2601 INI_RA(&ah->iniPcieSerdes, i, 1));
2602 }
2603 } else if (AR_SREV_9280(ah) &&
2604 (ah->hw_version.macRev == AR_SREV_REVISION_9280_10)) {
2605 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
2606 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
Sujithf1dc5602008-10-29 10:16:30 +05302607
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302608 /* RX shut off when elecidle is asserted */
2609 REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
2610 REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
2611 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
2612
2613 /* Shut off CLKREQ active in L1 */
2614 if (ah->config.pcie_clock_req)
2615 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
2616 else
2617 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
2618
2619 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2620 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2621 REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
2622
2623 /* Load the new settings */
2624 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
2625
2626 } else {
2627 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
2628 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
2629
2630 /* RX shut off when elecidle is asserted */
2631 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
2632 REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
2633 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
2634
2635 /*
2636 * Ignore ah->ah_config.pcie_clock_req setting for
2637 * pre-AR9280 11n
2638 */
2639 REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
2640
2641 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2642 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2643 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
2644
2645 /* Load the new settings */
2646 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
Sujithf1dc5602008-10-29 10:16:30 +05302647 }
Sujithf1dc5602008-10-29 10:16:30 +05302648
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302649 udelay(1000);
Sujithf1dc5602008-10-29 10:16:30 +05302650
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302651 /* set bit 19 to allow forcing of pcie core into L1 state */
2652 REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
Sujithf1dc5602008-10-29 10:16:30 +05302653
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302654 /* Several PCIe massages to ensure proper behaviour */
2655 if (ah->config.pcie_waen) {
2656 val = ah->config.pcie_waen;
2657 if (!power_off)
2658 val &= (~AR_WA_D3_L1_DISABLE);
2659 } else {
2660 if (AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
2661 AR_SREV_9287(ah)) {
2662 val = AR9285_WA_DEFAULT;
2663 if (!power_off)
2664 val &= (~AR_WA_D3_L1_DISABLE);
2665 } else if (AR_SREV_9280(ah)) {
2666 /*
2667 * On AR9280 chips bit 22 of 0x4004 needs to be
2668 * set otherwise card may disappear.
2669 */
2670 val = AR9280_WA_DEFAULT;
2671 if (!power_off)
2672 val &= (~AR_WA_D3_L1_DISABLE);
2673 } else
2674 val = AR_WA_DEFAULT;
2675 }
Sujithf1dc5602008-10-29 10:16:30 +05302676
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302677 REG_WRITE(ah, AR_WA, val);
Sujithf1dc5602008-10-29 10:16:30 +05302678 }
2679
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302680 if (power_off) {
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002681 /*
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302682 * Set PCIe workaround bits
2683 * bit 14 in WA register (disable L1) should only
2684 * be set when device enters D3 and be cleared
2685 * when device comes back to D0.
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002686 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302687 if (ah->config.pcie_waen) {
2688 if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE)
2689 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
2690 } else {
2691 if (((AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
2692 AR_SREV_9287(ah)) &&
2693 (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)) ||
2694 (AR_SREV_9280(ah) &&
2695 (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE))) {
2696 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
2697 }
2698 }
Sujithf1dc5602008-10-29 10:16:30 +05302699 }
2700}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002701EXPORT_SYMBOL(ath9k_hw_configpcipowersave);
Sujithf1dc5602008-10-29 10:16:30 +05302702
2703/**********************/
2704/* Interrupt Handling */
2705/**********************/
2706
Sujithcbe61d82009-02-09 13:27:12 +05302707bool ath9k_hw_intrpend(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002708{
2709 u32 host_isr;
2710
2711 if (AR_SREV_9100(ah))
2712 return true;
2713
2714 host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
2715 if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
2716 return true;
2717
2718 host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
2719 if ((host_isr & AR_INTR_SYNC_DEFAULT)
2720 && (host_isr != AR_INTR_SPURIOUS))
2721 return true;
2722
2723 return false;
2724}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002725EXPORT_SYMBOL(ath9k_hw_intrpend);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002726
Sujithcbe61d82009-02-09 13:27:12 +05302727bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002728{
2729 u32 isr = 0;
2730 u32 mask2 = 0;
Sujith2660b812009-02-09 13:27:26 +05302731 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002732 u32 sync_cause = 0;
2733 bool fatal_int = false;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002734 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002735
2736 if (!AR_SREV_9100(ah)) {
2737 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
2738 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
2739 == AR_RTC_STATUS_ON) {
2740 isr = REG_READ(ah, AR_ISR);
2741 }
2742 }
2743
Sujithf1dc5602008-10-29 10:16:30 +05302744 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
2745 AR_INTR_SYNC_DEFAULT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002746
2747 *masked = 0;
2748
2749 if (!isr && !sync_cause)
2750 return false;
2751 } else {
2752 *masked = 0;
2753 isr = REG_READ(ah, AR_ISR);
2754 }
2755
2756 if (isr) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002757 if (isr & AR_ISR_BCNMISC) {
2758 u32 isr2;
2759 isr2 = REG_READ(ah, AR_ISR_S2);
2760 if (isr2 & AR_ISR_S2_TIM)
2761 mask2 |= ATH9K_INT_TIM;
2762 if (isr2 & AR_ISR_S2_DTIM)
2763 mask2 |= ATH9K_INT_DTIM;
2764 if (isr2 & AR_ISR_S2_DTIMSYNC)
2765 mask2 |= ATH9K_INT_DTIMSYNC;
2766 if (isr2 & (AR_ISR_S2_CABEND))
2767 mask2 |= ATH9K_INT_CABEND;
2768 if (isr2 & AR_ISR_S2_GTT)
2769 mask2 |= ATH9K_INT_GTT;
2770 if (isr2 & AR_ISR_S2_CST)
2771 mask2 |= ATH9K_INT_CST;
Sujith4af9cf42009-02-12 10:06:47 +05302772 if (isr2 & AR_ISR_S2_TSFOOR)
2773 mask2 |= ATH9K_INT_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002774 }
2775
2776 isr = REG_READ(ah, AR_ISR_RAC);
2777 if (isr == 0xffffffff) {
2778 *masked = 0;
2779 return false;
2780 }
2781
2782 *masked = isr & ATH9K_INT_COMMON;
2783
Sujith0ef1f162009-03-30 15:28:35 +05302784 if (ah->config.intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002785 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
2786 *masked |= ATH9K_INT_RX;
2787 }
2788
2789 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
2790 *masked |= ATH9K_INT_RX;
2791 if (isr &
2792 (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
2793 AR_ISR_TXEOL)) {
2794 u32 s0_s, s1_s;
2795
2796 *masked |= ATH9K_INT_TX;
2797
2798 s0_s = REG_READ(ah, AR_ISR_S0_S);
Sujith2660b812009-02-09 13:27:26 +05302799 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
2800 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002801
2802 s1_s = REG_READ(ah, AR_ISR_S1_S);
Sujith2660b812009-02-09 13:27:26 +05302803 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
2804 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002805 }
2806
2807 if (isr & AR_ISR_RXORN) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002808 ath_print(common, ATH_DBG_INTERRUPT,
2809 "receive FIFO overrun interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002810 }
2811
2812 if (!AR_SREV_9100(ah)) {
Sujith60b67f52008-08-07 10:52:38 +05302813 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002814 u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
2815 if (isr5 & AR_ISR_S5_TIM_TIMER)
2816 *masked |= ATH9K_INT_TIM_TIMER;
2817 }
2818 }
2819
2820 *masked |= mask2;
2821 }
Sujithf1dc5602008-10-29 10:16:30 +05302822
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002823 if (AR_SREV_9100(ah))
2824 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302825
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302826 if (isr & AR_ISR_GENTMR) {
2827 u32 s5_s;
2828
2829 s5_s = REG_READ(ah, AR_ISR_S5_S);
2830 if (isr & AR_ISR_GENTMR) {
2831 ah->intr_gen_timer_trigger =
2832 MS(s5_s, AR_ISR_S5_GENTIMER_TRIG);
2833
2834 ah->intr_gen_timer_thresh =
2835 MS(s5_s, AR_ISR_S5_GENTIMER_THRESH);
2836
2837 if (ah->intr_gen_timer_trigger)
2838 *masked |= ATH9K_INT_GENTIMER;
2839
2840 }
2841 }
2842
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002843 if (sync_cause) {
2844 fatal_int =
2845 (sync_cause &
2846 (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
2847 ? true : false;
2848
2849 if (fatal_int) {
2850 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002851 ath_print(common, ATH_DBG_ANY,
2852 "received PCI FATAL interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002853 }
2854 if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002855 ath_print(common, ATH_DBG_ANY,
2856 "received PCI PERR interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002857 }
Steven Luoa89bff92009-04-12 02:57:54 -07002858 *masked |= ATH9K_INT_FATAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002859 }
2860 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002861 ath_print(common, ATH_DBG_INTERRUPT,
2862 "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002863 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
2864 REG_WRITE(ah, AR_RC, 0);
2865 *masked |= ATH9K_INT_FATAL;
2866 }
2867 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002868 ath_print(common, ATH_DBG_INTERRUPT,
2869 "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002870 }
2871
2872 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
2873 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
2874 }
Sujithf1dc5602008-10-29 10:16:30 +05302875
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002876 return true;
2877}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002878EXPORT_SYMBOL(ath9k_hw_getisr);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002879
Sujithcbe61d82009-02-09 13:27:12 +05302880enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002881{
Sujith2660b812009-02-09 13:27:26 +05302882 u32 omask = ah->mask_reg;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002883 u32 mask, mask2;
Sujith2660b812009-02-09 13:27:26 +05302884 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002885 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002886
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002887 ath_print(common, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002888
2889 if (omask & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002890 ath_print(common, ATH_DBG_INTERRUPT, "disable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002891 REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
2892 (void) REG_READ(ah, AR_IER);
2893 if (!AR_SREV_9100(ah)) {
2894 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
2895 (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
2896
2897 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
2898 (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
2899 }
2900 }
2901
2902 mask = ints & ATH9K_INT_COMMON;
2903 mask2 = 0;
2904
2905 if (ints & ATH9K_INT_TX) {
Sujith2660b812009-02-09 13:27:26 +05302906 if (ah->txok_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002907 mask |= AR_IMR_TXOK;
Sujith2660b812009-02-09 13:27:26 +05302908 if (ah->txdesc_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002909 mask |= AR_IMR_TXDESC;
Sujith2660b812009-02-09 13:27:26 +05302910 if (ah->txerr_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002911 mask |= AR_IMR_TXERR;
Sujith2660b812009-02-09 13:27:26 +05302912 if (ah->txeol_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002913 mask |= AR_IMR_TXEOL;
2914 }
2915 if (ints & ATH9K_INT_RX) {
2916 mask |= AR_IMR_RXERR;
Sujith0ef1f162009-03-30 15:28:35 +05302917 if (ah->config.intr_mitigation)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002918 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
2919 else
2920 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
Sujith60b67f52008-08-07 10:52:38 +05302921 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002922 mask |= AR_IMR_GENTMR;
2923 }
2924
2925 if (ints & (ATH9K_INT_BMISC)) {
2926 mask |= AR_IMR_BCNMISC;
2927 if (ints & ATH9K_INT_TIM)
2928 mask2 |= AR_IMR_S2_TIM;
2929 if (ints & ATH9K_INT_DTIM)
2930 mask2 |= AR_IMR_S2_DTIM;
2931 if (ints & ATH9K_INT_DTIMSYNC)
2932 mask2 |= AR_IMR_S2_DTIMSYNC;
2933 if (ints & ATH9K_INT_CABEND)
Sujith4af9cf42009-02-12 10:06:47 +05302934 mask2 |= AR_IMR_S2_CABEND;
2935 if (ints & ATH9K_INT_TSFOOR)
2936 mask2 |= AR_IMR_S2_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002937 }
2938
2939 if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
2940 mask |= AR_IMR_BCNMISC;
2941 if (ints & ATH9K_INT_GTT)
2942 mask2 |= AR_IMR_S2_GTT;
2943 if (ints & ATH9K_INT_CST)
2944 mask2 |= AR_IMR_S2_CST;
2945 }
2946
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002947 ath_print(common, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002948 REG_WRITE(ah, AR_IMR, mask);
2949 mask = REG_READ(ah, AR_IMR_S2) & ~(AR_IMR_S2_TIM |
2950 AR_IMR_S2_DTIM |
2951 AR_IMR_S2_DTIMSYNC |
2952 AR_IMR_S2_CABEND |
2953 AR_IMR_S2_CABTO |
2954 AR_IMR_S2_TSFOOR |
2955 AR_IMR_S2_GTT | AR_IMR_S2_CST);
2956 REG_WRITE(ah, AR_IMR_S2, mask | mask2);
Sujith2660b812009-02-09 13:27:26 +05302957 ah->mask_reg = ints;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002958
Sujith60b67f52008-08-07 10:52:38 +05302959 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002960 if (ints & ATH9K_INT_TIM_TIMER)
2961 REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
2962 else
2963 REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
2964 }
2965
2966 if (ints & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002967 ath_print(common, ATH_DBG_INTERRUPT, "enable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002968 REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
2969 if (!AR_SREV_9100(ah)) {
2970 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
2971 AR_INTR_MAC_IRQ);
2972 REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
2973
2974
2975 REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
2976 AR_INTR_SYNC_DEFAULT);
2977 REG_WRITE(ah, AR_INTR_SYNC_MASK,
2978 AR_INTR_SYNC_DEFAULT);
2979 }
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002980 ath_print(common, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
2981 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002982 }
2983
2984 return omask;
2985}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002986EXPORT_SYMBOL(ath9k_hw_set_interrupts);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002987
Sujithf1dc5602008-10-29 10:16:30 +05302988/*******************/
2989/* Beacon Handling */
2990/*******************/
2991
Sujithcbe61d82009-02-09 13:27:12 +05302992void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002993{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002994 int flags = 0;
2995
Sujith2660b812009-02-09 13:27:26 +05302996 ah->beacon_interval = beacon_period;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002997
Sujith2660b812009-02-09 13:27:26 +05302998 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08002999 case NL80211_IFTYPE_STATION:
3000 case NL80211_IFTYPE_MONITOR:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003001 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3002 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
3003 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
3004 flags |= AR_TBTT_TIMER_EN;
3005 break;
Colin McCabed97809d2008-12-01 13:38:55 -08003006 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04003007 case NL80211_IFTYPE_MESH_POINT:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003008 REG_SET_BIT(ah, AR_TXCFG,
3009 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
3010 REG_WRITE(ah, AR_NEXT_NDP_TIMER,
3011 TU_TO_USEC(next_beacon +
Sujith2660b812009-02-09 13:27:26 +05303012 (ah->atim_window ? ah->
3013 atim_window : 1)));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003014 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08003015 case NL80211_IFTYPE_AP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003016 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3017 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
3018 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05303019 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05303020 dma_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003021 REG_WRITE(ah, AR_NEXT_SWBA,
3022 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05303023 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05303024 sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003025 flags |=
3026 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
3027 break;
Colin McCabed97809d2008-12-01 13:38:55 -08003028 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003029 ath_print(ath9k_hw_common(ah), ATH_DBG_BEACON,
3030 "%s: unsupported opmode: %d\n",
3031 __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08003032 return;
3033 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003034 }
3035
3036 REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3037 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3038 REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
3039 REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
3040
3041 beacon_period &= ~ATH9K_BEACON_ENA;
3042 if (beacon_period & ATH9K_BEACON_RESET_TSF) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003043 ath9k_hw_reset_tsf(ah);
3044 }
3045
3046 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
3047}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003048EXPORT_SYMBOL(ath9k_hw_beaconinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003049
Sujithcbe61d82009-02-09 13:27:12 +05303050void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303051 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003052{
3053 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05303054 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003055 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003056
3057 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
3058
3059 REG_WRITE(ah, AR_BEACON_PERIOD,
3060 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3061 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
3062 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3063
3064 REG_RMW_FIELD(ah, AR_RSSI_THR,
3065 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
3066
3067 beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
3068
3069 if (bs->bs_sleepduration > beaconintval)
3070 beaconintval = bs->bs_sleepduration;
3071
3072 dtimperiod = bs->bs_dtimperiod;
3073 if (bs->bs_sleepduration > dtimperiod)
3074 dtimperiod = bs->bs_sleepduration;
3075
3076 if (beaconintval == dtimperiod)
3077 nextTbtt = bs->bs_nextdtim;
3078 else
3079 nextTbtt = bs->bs_nexttbtt;
3080
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003081 ath_print(common, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
3082 ath_print(common, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
3083 ath_print(common, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
3084 ath_print(common, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003085
3086 REG_WRITE(ah, AR_NEXT_DTIM,
3087 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
3088 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
3089
3090 REG_WRITE(ah, AR_SLEEP1,
3091 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
3092 | AR_SLEEP1_ASSUME_DTIM);
3093
Sujith60b67f52008-08-07 10:52:38 +05303094 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003095 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
3096 else
3097 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
3098
3099 REG_WRITE(ah, AR_SLEEP2,
3100 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
3101
3102 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
3103 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
3104
3105 REG_SET_BIT(ah, AR_TIMER_MODE,
3106 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
3107 AR_DTIM_TIMER_EN);
3108
Sujith4af9cf42009-02-12 10:06:47 +05303109 /* TSF Out of Range Threshold */
3110 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003111}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003112EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003113
Sujithf1dc5602008-10-29 10:16:30 +05303114/*******************/
3115/* HW Capabilities */
3116/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003117
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01003118int ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003119{
Sujith2660b812009-02-09 13:27:26 +05303120 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003121 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003122 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003123 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003124
Sujithf1dc5602008-10-29 10:16:30 +05303125 u16 capField = 0, eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003126
Sujithf74df6f2009-02-09 13:27:24 +05303127 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003128 regulatory->current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303129
Sujithf74df6f2009-02-09 13:27:24 +05303130 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
Sujithfec0de12009-02-12 10:06:43 +05303131 if (AR_SREV_9285_10_OR_LATER(ah))
3132 eeval |= AR9285_RDEXT_DEFAULT;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003133 regulatory->current_rd_ext = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303134
Sujithf74df6f2009-02-09 13:27:24 +05303135 capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
Sujithf1dc5602008-10-29 10:16:30 +05303136
Sujith2660b812009-02-09 13:27:26 +05303137 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05303138 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003139 if (regulatory->current_rd == 0x64 ||
3140 regulatory->current_rd == 0x65)
3141 regulatory->current_rd += 5;
3142 else if (regulatory->current_rd == 0x41)
3143 regulatory->current_rd = 0x43;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003144 ath_print(common, ATH_DBG_REGULATORY,
3145 "regdomain mapped to 0x%x\n", regulatory->current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003146 }
Sujithdc2222a2008-08-14 13:26:55 +05303147
Sujithf74df6f2009-02-09 13:27:24 +05303148 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01003149 if ((eeval & (AR5416_OPFLAGS_11G | AR5416_OPFLAGS_11A)) == 0) {
3150 ath_print(common, ATH_DBG_FATAL,
3151 "no band has been marked as supported in EEPROM.\n");
3152 return -EINVAL;
3153 }
3154
Sujithf1dc5602008-10-29 10:16:30 +05303155 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003156
Sujithf1dc5602008-10-29 10:16:30 +05303157 if (eeval & AR5416_OPFLAGS_11A) {
3158 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303159 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303160 if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
3161 set_bit(ATH9K_MODE_11NA_HT20,
3162 pCap->wireless_modes);
3163 if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
3164 set_bit(ATH9K_MODE_11NA_HT40PLUS,
3165 pCap->wireless_modes);
3166 set_bit(ATH9K_MODE_11NA_HT40MINUS,
3167 pCap->wireless_modes);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003168 }
3169 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003170 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003171
Sujithf1dc5602008-10-29 10:16:30 +05303172 if (eeval & AR5416_OPFLAGS_11G) {
Sujithf1dc5602008-10-29 10:16:30 +05303173 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303174 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303175 if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
3176 set_bit(ATH9K_MODE_11NG_HT20,
3177 pCap->wireless_modes);
3178 if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
3179 set_bit(ATH9K_MODE_11NG_HT40PLUS,
3180 pCap->wireless_modes);
3181 set_bit(ATH9K_MODE_11NG_HT40MINUS,
3182 pCap->wireless_modes);
3183 }
3184 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003185 }
Sujithf1dc5602008-10-29 10:16:30 +05303186
Sujithf74df6f2009-02-09 13:27:24 +05303187 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003188 /*
3189 * For AR9271 we will temporarilly uses the rx chainmax as read from
3190 * the EEPROM.
3191 */
Sujith8147f5d2009-02-20 15:13:23 +05303192 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003193 !(eeval & AR5416_OPFLAGS_11A) &&
3194 !(AR_SREV_9271(ah)))
3195 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
Sujith8147f5d2009-02-20 15:13:23 +05303196 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
3197 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003198 /* Use rx_chainmask from EEPROM. */
Sujith8147f5d2009-02-20 15:13:23 +05303199 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05303200
Sujithd535a422009-02-09 13:27:06 +05303201 if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0)))
Sujith2660b812009-02-09 13:27:26 +05303202 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05303203
3204 pCap->low_2ghz_chan = 2312;
3205 pCap->high_2ghz_chan = 2732;
3206
3207 pCap->low_5ghz_chan = 4920;
3208 pCap->high_5ghz_chan = 6100;
3209
3210 pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
3211 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
3212 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
3213
3214 pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
3215 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
3216 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
3217
Sujith2660b812009-02-09 13:27:26 +05303218 if (ah->config.ht_enable)
Sujithf1dc5602008-10-29 10:16:30 +05303219 pCap->hw_caps |= ATH9K_HW_CAP_HT;
3220 else
3221 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
3222
3223 pCap->hw_caps |= ATH9K_HW_CAP_GTT;
3224 pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
3225 pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
3226 pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
3227
3228 if (capField & AR_EEPROM_EEPCAP_MAXQCU)
3229 pCap->total_queues =
3230 MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
3231 else
3232 pCap->total_queues = ATH9K_NUM_TX_QUEUES;
3233
3234 if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
3235 pCap->keycache_size =
3236 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
3237 else
3238 pCap->keycache_size = AR_KEYTABLE_SIZE;
3239
3240 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -05003241
3242 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
3243 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD >> 1;
3244 else
3245 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
Sujithf1dc5602008-10-29 10:16:30 +05303246
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303247 if (AR_SREV_9285_10_OR_LATER(ah))
3248 pCap->num_gpio_pins = AR9285_NUM_GPIO;
3249 else if (AR_SREV_9280_10_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303250 pCap->num_gpio_pins = AR928X_NUM_GPIO;
3251 else
3252 pCap->num_gpio_pins = AR_NUM_GPIO;
3253
Sujithf1dc5602008-10-29 10:16:30 +05303254 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
3255 pCap->hw_caps |= ATH9K_HW_CAP_CST;
3256 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
3257 } else {
3258 pCap->rts_aggr_limit = (8 * 1024);
3259 }
3260
3261 pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
3262
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05303263#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05303264 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
3265 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
3266 ah->rfkill_gpio =
3267 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
3268 ah->rfkill_polarity =
3269 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05303270
3271 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
3272 }
3273#endif
3274
Vivek Natarajana3ca95fb2009-09-17 09:29:07 +05303275 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
Sujithf1dc5602008-10-29 10:16:30 +05303276
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05303277 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303278 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
3279 else
3280 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
3281
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003282 if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) {
Sujithf1dc5602008-10-29 10:16:30 +05303283 pCap->reg_cap =
3284 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3285 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
3286 AR_EEPROM_EEREGCAP_EN_KK_U2 |
3287 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
3288 } else {
3289 pCap->reg_cap =
3290 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3291 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
3292 }
3293
Senthil Balasubramanianebb90cf2009-09-18 15:07:33 +05303294 /* Advertise midband for AR5416 with FCC midband set in eeprom */
3295 if (regulatory->current_rd_ext & (1 << REG_EXT_FCC_MIDBAND) &&
3296 AR_SREV_5416(ah))
3297 pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
Sujithf1dc5602008-10-29 10:16:30 +05303298
3299 pCap->num_antcfg_5ghz =
Sujithf74df6f2009-02-09 13:27:24 +05303300 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303301 pCap->num_antcfg_2ghz =
Sujithf74df6f2009-02-09 13:27:24 +05303302 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303303
Vasanthakumar Thiagarajanfe129462009-09-09 15:25:50 +05303304 if (AR_SREV_9280_10_OR_LATER(ah) &&
Luis R. Rodrigueza36cfbc2009-09-09 16:05:32 -07003305 ath9k_hw_btcoex_supported(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003306 btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO;
3307 btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO;
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05303308
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303309 if (AR_SREV_9285(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003310 btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
3311 btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303312 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003313 btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303314 }
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05303315 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003316 btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE;
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303317 }
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01003318
3319 return 0;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003320}
3321
Sujithcbe61d82009-02-09 13:27:12 +05303322bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303323 u32 capability, u32 *result)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003324{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003325 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05303326 switch (type) {
3327 case ATH9K_CAP_CIPHER:
3328 switch (capability) {
3329 case ATH9K_CIPHER_AES_CCM:
3330 case ATH9K_CIPHER_AES_OCB:
3331 case ATH9K_CIPHER_TKIP:
3332 case ATH9K_CIPHER_WEP:
3333 case ATH9K_CIPHER_MIC:
3334 case ATH9K_CIPHER_CLR:
3335 return true;
3336 default:
3337 return false;
3338 }
3339 case ATH9K_CAP_TKIP_MIC:
3340 switch (capability) {
3341 case 0:
3342 return true;
3343 case 1:
Sujith2660b812009-02-09 13:27:26 +05303344 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303345 AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
3346 false;
3347 }
3348 case ATH9K_CAP_TKIP_SPLIT:
Sujith2660b812009-02-09 13:27:26 +05303349 return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ?
Sujithf1dc5602008-10-29 10:16:30 +05303350 false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303351 case ATH9K_CAP_DIVERSITY:
3352 return (REG_READ(ah, AR_PHY_CCK_DETECT) &
3353 AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV) ?
3354 true : false;
Sujithf1dc5602008-10-29 10:16:30 +05303355 case ATH9K_CAP_MCAST_KEYSRCH:
3356 switch (capability) {
3357 case 0:
3358 return true;
3359 case 1:
3360 if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
3361 return false;
3362 } else {
Sujith2660b812009-02-09 13:27:26 +05303363 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303364 AR_STA_ID1_MCAST_KSRCH) ? true :
3365 false;
3366 }
3367 }
3368 return false;
Sujithf1dc5602008-10-29 10:16:30 +05303369 case ATH9K_CAP_TXPOW:
3370 switch (capability) {
3371 case 0:
3372 return 0;
3373 case 1:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003374 *result = regulatory->power_limit;
Sujithf1dc5602008-10-29 10:16:30 +05303375 return 0;
3376 case 2:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003377 *result = regulatory->max_power_level;
Sujithf1dc5602008-10-29 10:16:30 +05303378 return 0;
3379 case 3:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003380 *result = regulatory->tp_scale;
Sujithf1dc5602008-10-29 10:16:30 +05303381 return 0;
3382 }
3383 return false;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05303384 case ATH9K_CAP_DS:
3385 return (AR_SREV_9280_20_OR_LATER(ah) &&
3386 (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1))
3387 ? false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303388 default:
3389 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003390 }
Sujithf1dc5602008-10-29 10:16:30 +05303391}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003392EXPORT_SYMBOL(ath9k_hw_getcapability);
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003393
Sujithcbe61d82009-02-09 13:27:12 +05303394bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303395 u32 capability, u32 setting, int *status)
3396{
Sujithf1dc5602008-10-29 10:16:30 +05303397 u32 v;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003398
Sujithf1dc5602008-10-29 10:16:30 +05303399 switch (type) {
3400 case ATH9K_CAP_TKIP_MIC:
3401 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303402 ah->sta_id1_defaults |=
Sujithf1dc5602008-10-29 10:16:30 +05303403 AR_STA_ID1_CRPT_MIC_ENABLE;
3404 else
Sujith2660b812009-02-09 13:27:26 +05303405 ah->sta_id1_defaults &=
Sujithf1dc5602008-10-29 10:16:30 +05303406 ~AR_STA_ID1_CRPT_MIC_ENABLE;
3407 return true;
3408 case ATH9K_CAP_DIVERSITY:
3409 v = REG_READ(ah, AR_PHY_CCK_DETECT);
3410 if (setting)
3411 v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3412 else
3413 v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3414 REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
3415 return true;
3416 case ATH9K_CAP_MCAST_KEYSRCH:
3417 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303418 ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303419 else
Sujith2660b812009-02-09 13:27:26 +05303420 ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303421 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303422 default:
3423 return false;
3424 }
3425}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003426EXPORT_SYMBOL(ath9k_hw_setcapability);
Sujithf1dc5602008-10-29 10:16:30 +05303427
3428/****************************/
3429/* GPIO / RFKILL / Antennae */
3430/****************************/
3431
Sujithcbe61d82009-02-09 13:27:12 +05303432static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303433 u32 gpio, u32 type)
3434{
3435 int addr;
3436 u32 gpio_shift, tmp;
3437
3438 if (gpio > 11)
3439 addr = AR_GPIO_OUTPUT_MUX3;
3440 else if (gpio > 5)
3441 addr = AR_GPIO_OUTPUT_MUX2;
3442 else
3443 addr = AR_GPIO_OUTPUT_MUX1;
3444
3445 gpio_shift = (gpio % 6) * 5;
3446
3447 if (AR_SREV_9280_20_OR_LATER(ah)
3448 || (addr != AR_GPIO_OUTPUT_MUX1)) {
3449 REG_RMW(ah, addr, (type << gpio_shift),
3450 (0x1f << gpio_shift));
3451 } else {
3452 tmp = REG_READ(ah, addr);
3453 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
3454 tmp &= ~(0x1f << gpio_shift);
3455 tmp |= (type << gpio_shift);
3456 REG_WRITE(ah, addr, tmp);
3457 }
3458}
3459
Sujithcbe61d82009-02-09 13:27:12 +05303460void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303461{
3462 u32 gpio_shift;
3463
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07003464 BUG_ON(gpio >= ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05303465
3466 gpio_shift = gpio << 1;
3467
3468 REG_RMW(ah,
3469 AR_GPIO_OE_OUT,
3470 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
3471 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3472}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003473EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
Sujithf1dc5602008-10-29 10:16:30 +05303474
Sujithcbe61d82009-02-09 13:27:12 +05303475u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303476{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303477#define MS_REG_READ(x, y) \
3478 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
3479
Sujith2660b812009-02-09 13:27:26 +05303480 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05303481 return 0xffffffff;
3482
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05303483 if (AR_SREV_9287_10_OR_LATER(ah))
3484 return MS_REG_READ(AR9287, gpio) != 0;
3485 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303486 return MS_REG_READ(AR9285, gpio) != 0;
3487 else if (AR_SREV_9280_10_OR_LATER(ah))
3488 return MS_REG_READ(AR928X, gpio) != 0;
3489 else
3490 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05303491}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003492EXPORT_SYMBOL(ath9k_hw_gpio_get);
Sujithf1dc5602008-10-29 10:16:30 +05303493
Sujithcbe61d82009-02-09 13:27:12 +05303494void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05303495 u32 ah_signal_type)
3496{
3497 u32 gpio_shift;
3498
3499 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
3500
3501 gpio_shift = 2 * gpio;
3502
3503 REG_RMW(ah,
3504 AR_GPIO_OE_OUT,
3505 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
3506 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3507}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003508EXPORT_SYMBOL(ath9k_hw_cfg_output);
Sujithf1dc5602008-10-29 10:16:30 +05303509
Sujithcbe61d82009-02-09 13:27:12 +05303510void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05303511{
3512 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
3513 AR_GPIO_BIT(gpio));
3514}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003515EXPORT_SYMBOL(ath9k_hw_set_gpio);
Sujithf1dc5602008-10-29 10:16:30 +05303516
Sujithcbe61d82009-02-09 13:27:12 +05303517u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303518{
3519 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
3520}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003521EXPORT_SYMBOL(ath9k_hw_getdefantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303522
Sujithcbe61d82009-02-09 13:27:12 +05303523void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05303524{
3525 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
3526}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003527EXPORT_SYMBOL(ath9k_hw_setantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303528
Sujithf1dc5602008-10-29 10:16:30 +05303529/*********************/
3530/* General Operation */
3531/*********************/
3532
Sujithcbe61d82009-02-09 13:27:12 +05303533u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303534{
3535 u32 bits = REG_READ(ah, AR_RX_FILTER);
3536 u32 phybits = REG_READ(ah, AR_PHY_ERR);
3537
3538 if (phybits & AR_PHY_ERR_RADAR)
3539 bits |= ATH9K_RX_FILTER_PHYRADAR;
3540 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
3541 bits |= ATH9K_RX_FILTER_PHYERR;
3542
3543 return bits;
3544}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003545EXPORT_SYMBOL(ath9k_hw_getrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303546
Sujithcbe61d82009-02-09 13:27:12 +05303547void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05303548{
3549 u32 phybits;
3550
Sujith7ea310b2009-09-03 12:08:43 +05303551 REG_WRITE(ah, AR_RX_FILTER, bits);
3552
Sujithf1dc5602008-10-29 10:16:30 +05303553 phybits = 0;
3554 if (bits & ATH9K_RX_FILTER_PHYRADAR)
3555 phybits |= AR_PHY_ERR_RADAR;
3556 if (bits & ATH9K_RX_FILTER_PHYERR)
3557 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
3558 REG_WRITE(ah, AR_PHY_ERR, phybits);
3559
3560 if (phybits)
3561 REG_WRITE(ah, AR_RXCFG,
3562 REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
3563 else
3564 REG_WRITE(ah, AR_RXCFG,
3565 REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
3566}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003567EXPORT_SYMBOL(ath9k_hw_setrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303568
Sujithcbe61d82009-02-09 13:27:12 +05303569bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303570{
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05303571 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
3572 return false;
3573
3574 ath9k_hw_init_pll(ah, NULL);
3575 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303576}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003577EXPORT_SYMBOL(ath9k_hw_phy_disable);
Sujithf1dc5602008-10-29 10:16:30 +05303578
Sujithcbe61d82009-02-09 13:27:12 +05303579bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303580{
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07003581 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05303582 return false;
3583
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05303584 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
3585 return false;
3586
3587 ath9k_hw_init_pll(ah, NULL);
3588 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303589}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003590EXPORT_SYMBOL(ath9k_hw_disable);
Sujithf1dc5602008-10-29 10:16:30 +05303591
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003592void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
Sujithf1dc5602008-10-29 10:16:30 +05303593{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003594 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujith2660b812009-02-09 13:27:26 +05303595 struct ath9k_channel *chan = ah->curchan;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08003596 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05303597
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003598 regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER);
Sujithf1dc5602008-10-29 10:16:30 +05303599
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003600 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003601 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003602 channel->max_antenna_gain * 2,
3603 channel->max_power * 2,
3604 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003605 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05303606}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003607EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
Sujithf1dc5602008-10-29 10:16:30 +05303608
Sujithcbe61d82009-02-09 13:27:12 +05303609void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac)
Sujithf1dc5602008-10-29 10:16:30 +05303610{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07003611 memcpy(ath9k_hw_common(ah)->macaddr, mac, ETH_ALEN);
Sujithf1dc5602008-10-29 10:16:30 +05303612}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003613EXPORT_SYMBOL(ath9k_hw_setmac);
Sujithf1dc5602008-10-29 10:16:30 +05303614
Sujithcbe61d82009-02-09 13:27:12 +05303615void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303616{
Sujith2660b812009-02-09 13:27:26 +05303617 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05303618}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003619EXPORT_SYMBOL(ath9k_hw_setopmode);
Sujithf1dc5602008-10-29 10:16:30 +05303620
Sujithcbe61d82009-02-09 13:27:12 +05303621void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05303622{
3623 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
3624 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
3625}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003626EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303627
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07003628void ath9k_hw_write_associd(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303629{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07003630 struct ath_common *common = ath9k_hw_common(ah);
3631
3632 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
3633 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
3634 ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05303635}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003636EXPORT_SYMBOL(ath9k_hw_write_associd);
Sujithf1dc5602008-10-29 10:16:30 +05303637
Sujithcbe61d82009-02-09 13:27:12 +05303638u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303639{
3640 u64 tsf;
3641
3642 tsf = REG_READ(ah, AR_TSF_U32);
3643 tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
3644
3645 return tsf;
3646}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003647EXPORT_SYMBOL(ath9k_hw_gettsf64);
Sujithf1dc5602008-10-29 10:16:30 +05303648
Sujithcbe61d82009-02-09 13:27:12 +05303649void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003650{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003651 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01003652 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003653}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003654EXPORT_SYMBOL(ath9k_hw_settsf64);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003655
Sujithcbe61d82009-02-09 13:27:12 +05303656void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303657{
Gabor Juhosf9b604f2009-06-21 00:02:15 +02003658 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
3659 AH_TSF_WRITE_TIMEOUT))
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003660 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
3661 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
Gabor Juhosf9b604f2009-06-21 00:02:15 +02003662
Sujithf1dc5602008-10-29 10:16:30 +05303663 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003664}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003665EXPORT_SYMBOL(ath9k_hw_reset_tsf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003666
Sujith54e4cec2009-08-07 09:45:09 +05303667void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003668{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003669 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303670 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003671 else
Sujith2660b812009-02-09 13:27:26 +05303672 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003673}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003674EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003675
Luis R. Rodriguez30cbd422009-11-03 16:10:46 -08003676/*
3677 * Extend 15-bit time stamp from rx descriptor to
3678 * a full 64-bit TSF using the current h/w TSF.
3679*/
3680u64 ath9k_hw_extend_tsf(struct ath_hw *ah, u32 rstamp)
3681{
3682 u64 tsf;
3683
3684 tsf = ath9k_hw_gettsf64(ah);
3685 if ((tsf & 0x7fff) < rstamp)
3686 tsf -= 0x8000;
3687 return (tsf & ~0x7fff) | rstamp;
3688}
3689EXPORT_SYMBOL(ath9k_hw_extend_tsf);
3690
Sujithcbe61d82009-02-09 13:27:12 +05303691bool ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003692{
Sujithf1dc5602008-10-29 10:16:30 +05303693 if (us < ATH9K_SLOT_TIME_9 || us > ath9k_hw_mac_to_usec(ah, 0xffff)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003694 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
3695 "bad slot time %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05303696 ah->slottime = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05303697 return false;
3698 } else {
3699 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05303700 ah->slottime = us;
Sujithf1dc5602008-10-29 10:16:30 +05303701 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003702 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003703}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003704EXPORT_SYMBOL(ath9k_hw_setslottime);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003705
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003706void ath9k_hw_set11nmac2040(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003707{
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003708 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithf1dc5602008-10-29 10:16:30 +05303709 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003710
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003711 if (conf_is_ht40(conf) && !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05303712 macmode = AR_2040_JOINED_RX_CLEAR;
3713 else
3714 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003715
Sujithf1dc5602008-10-29 10:16:30 +05303716 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003717}
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303718
3719/* HW Generic timers configuration */
3720
3721static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
3722{
3723 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3724 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3725 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3726 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3727 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3728 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3729 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3730 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3731 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
3732 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
3733 AR_NDP2_TIMER_MODE, 0x0002},
3734 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
3735 AR_NDP2_TIMER_MODE, 0x0004},
3736 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
3737 AR_NDP2_TIMER_MODE, 0x0008},
3738 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
3739 AR_NDP2_TIMER_MODE, 0x0010},
3740 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
3741 AR_NDP2_TIMER_MODE, 0x0020},
3742 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
3743 AR_NDP2_TIMER_MODE, 0x0040},
3744 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
3745 AR_NDP2_TIMER_MODE, 0x0080}
3746};
3747
3748/* HW generic timer primitives */
3749
3750/* compute and clear index of rightmost 1 */
3751static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
3752{
3753 u32 b;
3754
3755 b = *mask;
3756 b &= (0-b);
3757 *mask &= ~b;
3758 b *= debruijn32;
3759 b >>= 27;
3760
3761 return timer_table->gen_timer_index[b];
3762}
3763
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05303764u32 ath9k_hw_gettsf32(struct ath_hw *ah)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303765{
3766 return REG_READ(ah, AR_TSF_L32);
3767}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003768EXPORT_SYMBOL(ath9k_hw_gettsf32);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303769
3770struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
3771 void (*trigger)(void *),
3772 void (*overflow)(void *),
3773 void *arg,
3774 u8 timer_index)
3775{
3776 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3777 struct ath_gen_timer *timer;
3778
3779 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
3780
3781 if (timer == NULL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003782 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
3783 "Failed to allocate memory"
3784 "for hw timer[%d]\n", timer_index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303785 return NULL;
3786 }
3787
3788 /* allocate a hardware generic timer slot */
3789 timer_table->timers[timer_index] = timer;
3790 timer->index = timer_index;
3791 timer->trigger = trigger;
3792 timer->overflow = overflow;
3793 timer->arg = arg;
3794
3795 return timer;
3796}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003797EXPORT_SYMBOL(ath_gen_timer_alloc);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303798
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07003799void ath9k_hw_gen_timer_start(struct ath_hw *ah,
3800 struct ath_gen_timer *timer,
3801 u32 timer_next,
3802 u32 timer_period)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303803{
3804 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3805 u32 tsf;
3806
3807 BUG_ON(!timer_period);
3808
3809 set_bit(timer->index, &timer_table->timer_mask.timer_bits);
3810
3811 tsf = ath9k_hw_gettsf32(ah);
3812
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003813 ath_print(ath9k_hw_common(ah), ATH_DBG_HWTIMER,
3814 "curent tsf %x period %x"
3815 "timer_next %x\n", tsf, timer_period, timer_next);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303816
3817 /*
3818 * Pull timer_next forward if the current TSF already passed it
3819 * because of software latency
3820 */
3821 if (timer_next < tsf)
3822 timer_next = tsf + timer_period;
3823
3824 /*
3825 * Program generic timer registers
3826 */
3827 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
3828 timer_next);
3829 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
3830 timer_period);
3831 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
3832 gen_tmr_configuration[timer->index].mode_mask);
3833
3834 /* Enable both trigger and thresh interrupt masks */
3835 REG_SET_BIT(ah, AR_IMR_S5,
3836 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
3837 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303838}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003839EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303840
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07003841void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303842{
3843 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3844
3845 if ((timer->index < AR_FIRST_NDP_TIMER) ||
3846 (timer->index >= ATH_MAX_GEN_TIMER)) {
3847 return;
3848 }
3849
3850 /* Clear generic timer enable bits. */
3851 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
3852 gen_tmr_configuration[timer->index].mode_mask);
3853
3854 /* Disable both trigger and thresh interrupt masks */
3855 REG_CLR_BIT(ah, AR_IMR_S5,
3856 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
3857 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
3858
3859 clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303860}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003861EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303862
3863void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
3864{
3865 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3866
3867 /* free the hardware generic timer slot */
3868 timer_table->timers[timer->index] = NULL;
3869 kfree(timer);
3870}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003871EXPORT_SYMBOL(ath_gen_timer_free);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303872
3873/*
3874 * Generic Timer Interrupts handling
3875 */
3876void ath_gen_timer_isr(struct ath_hw *ah)
3877{
3878 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3879 struct ath_gen_timer *timer;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003880 struct ath_common *common = ath9k_hw_common(ah);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303881 u32 trigger_mask, thresh_mask, index;
3882
3883 /* get hardware generic timer interrupt status */
3884 trigger_mask = ah->intr_gen_timer_trigger;
3885 thresh_mask = ah->intr_gen_timer_thresh;
3886 trigger_mask &= timer_table->timer_mask.val;
3887 thresh_mask &= timer_table->timer_mask.val;
3888
3889 trigger_mask &= ~thresh_mask;
3890
3891 while (thresh_mask) {
3892 index = rightmost_index(timer_table, &thresh_mask);
3893 timer = timer_table->timers[index];
3894 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003895 ath_print(common, ATH_DBG_HWTIMER,
3896 "TSF overflow for Gen timer %d\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303897 timer->overflow(timer->arg);
3898 }
3899
3900 while (trigger_mask) {
3901 index = rightmost_index(timer_table, &trigger_mask);
3902 timer = timer_table->timers[index];
3903 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003904 ath_print(common, ATH_DBG_HWTIMER,
3905 "Gen timer[%d] trigger\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303906 timer->trigger(timer->arg);
3907 }
3908}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003909EXPORT_SYMBOL(ath_gen_timer_isr);
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003910
3911static struct {
3912 u32 version;
3913 const char * name;
3914} ath_mac_bb_names[] = {
3915 /* Devices with external radios */
3916 { AR_SREV_VERSION_5416_PCI, "5416" },
3917 { AR_SREV_VERSION_5416_PCIE, "5418" },
3918 { AR_SREV_VERSION_9100, "9100" },
3919 { AR_SREV_VERSION_9160, "9160" },
3920 /* Single-chip solutions */
3921 { AR_SREV_VERSION_9280, "9280" },
3922 { AR_SREV_VERSION_9285, "9285" },
Luis R. Rodriguez11158472009-10-27 12:59:35 -04003923 { AR_SREV_VERSION_9287, "9287" },
3924 { AR_SREV_VERSION_9271, "9271" },
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003925};
3926
3927/* For devices with external radios */
3928static struct {
3929 u16 version;
3930 const char * name;
3931} ath_rf_names[] = {
3932 { 0, "5133" },
3933 { AR_RAD5133_SREV_MAJOR, "5133" },
3934 { AR_RAD5122_SREV_MAJOR, "5122" },
3935 { AR_RAD2133_SREV_MAJOR, "2133" },
3936 { AR_RAD2122_SREV_MAJOR, "2122" }
3937};
3938
3939/*
3940 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
3941 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003942static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003943{
3944 int i;
3945
3946 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
3947 if (ath_mac_bb_names[i].version == mac_bb_version) {
3948 return ath_mac_bb_names[i].name;
3949 }
3950 }
3951
3952 return "????";
3953}
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003954
3955/*
3956 * Return the RF name. "????" is returned if the RF is unknown.
3957 * Used for devices with external radios.
3958 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003959static const char *ath9k_hw_rf_name(u16 rf_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003960{
3961 int i;
3962
3963 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
3964 if (ath_rf_names[i].version == rf_version) {
3965 return ath_rf_names[i].name;
3966 }
3967 }
3968
3969 return "????";
3970}
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003971
3972void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
3973{
3974 int used;
3975
3976 /* chipsets >= AR9280 are single-chip */
3977 if (AR_SREV_9280_10_OR_LATER(ah)) {
3978 used = snprintf(hw_name, len,
3979 "Atheros AR%s Rev:%x",
3980 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3981 ah->hw_version.macRev);
3982 }
3983 else {
3984 used = snprintf(hw_name, len,
3985 "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
3986 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3987 ah->hw_version.macRev,
3988 ath9k_hw_rf_name((ah->hw_version.analog5GhzRev &
3989 AR_RADIO_SREV_MAJOR)),
3990 ah->hw_version.phyRev);
3991 }
3992
3993 hw_name[used] = '\0';
3994}
3995EXPORT_SYMBOL(ath9k_hw_name);