blob: 626667c3101cb41a6f2136e8f7e25262e34a831e [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
Sujithcee075a2009-03-13 09:07:23 +05302 * Copyright (c) 2008-2009 Atheros Communications Inc.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include <linux/io.h>
18#include <asm/unaligned.h>
19
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -070020#include "hw.h"
Luis R. Rodriguezcfe8cba2009-09-13 23:39:31 -070021#include "rc.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070022#include "initvals.h"
23
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080024#define ATH9K_CLOCK_RATE_CCK 22
25#define ATH9K_CLOCK_RATE_5GHZ_OFDM 40
26#define ATH9K_CLOCK_RATE_2GHZ_OFDM 44
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070027
Sujithcbe61d82009-02-09 13:27:12 +053028static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type);
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -070029static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan);
Sujithcbe61d82009-02-09 13:27:12 +053030static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +053031 struct ar5416_eeprom_def *pEepData,
Sujithf1dc5602008-10-29 10:16:30 +053032 u32 reg, u32 value);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070033
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040034MODULE_AUTHOR("Atheros Communications");
35MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
36MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
37MODULE_LICENSE("Dual BSD/GPL");
38
39static int __init ath9k_init(void)
40{
41 return 0;
42}
43module_init(ath9k_init);
44
45static void __exit ath9k_exit(void)
46{
47 return;
48}
49module_exit(ath9k_exit);
50
Sujithf1dc5602008-10-29 10:16:30 +053051/********************/
52/* Helper Functions */
53/********************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070054
Sujithcbe61d82009-02-09 13:27:12 +053055static u32 ath9k_hw_mac_usec(struct ath_hw *ah, u32 clks)
Sujithf1dc5602008-10-29 10:16:30 +053056{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070057 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053058
Sujith2660b812009-02-09 13:27:26 +053059 if (!ah->curchan) /* should really check for CCK instead */
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080060 return clks / ATH9K_CLOCK_RATE_CCK;
61 if (conf->channel->band == IEEE80211_BAND_2GHZ)
62 return clks / ATH9K_CLOCK_RATE_2GHZ_OFDM;
Sujithcbe61d82009-02-09 13:27:12 +053063
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080064 return clks / ATH9K_CLOCK_RATE_5GHZ_OFDM;
Sujithf1dc5602008-10-29 10:16:30 +053065}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070066
Sujithcbe61d82009-02-09 13:27:12 +053067static u32 ath9k_hw_mac_to_usec(struct ath_hw *ah, u32 clks)
Sujithf1dc5602008-10-29 10:16:30 +053068{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070069 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053070
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080071 if (conf_is_ht40(conf))
Sujithf1dc5602008-10-29 10:16:30 +053072 return ath9k_hw_mac_usec(ah, clks) / 2;
73 else
74 return ath9k_hw_mac_usec(ah, clks);
75}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070076
Sujithcbe61d82009-02-09 13:27:12 +053077static u32 ath9k_hw_mac_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053078{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070079 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053080
Sujith2660b812009-02-09 13:27:26 +053081 if (!ah->curchan) /* should really check for CCK instead */
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080082 return usecs *ATH9K_CLOCK_RATE_CCK;
83 if (conf->channel->band == IEEE80211_BAND_2GHZ)
84 return usecs *ATH9K_CLOCK_RATE_2GHZ_OFDM;
85 return usecs *ATH9K_CLOCK_RATE_5GHZ_OFDM;
Sujithf1dc5602008-10-29 10:16:30 +053086}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070087
Sujithcbe61d82009-02-09 13:27:12 +053088static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053089{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070090 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053091
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080092 if (conf_is_ht40(conf))
Sujithf1dc5602008-10-29 10:16:30 +053093 return ath9k_hw_mac_clks(ah, usecs) * 2;
94 else
95 return ath9k_hw_mac_clks(ah, usecs);
96}
97
Sujith0caa7b12009-02-16 13:23:20 +053098bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070099{
100 int i;
101
Sujith0caa7b12009-02-16 13:23:20 +0530102 BUG_ON(timeout < AH_TIME_QUANTUM);
103
104 for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700105 if ((REG_READ(ah, reg) & mask) == val)
106 return true;
107
108 udelay(AH_TIME_QUANTUM);
109 }
Sujith04bd4632008-11-28 22:18:05 +0530110
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700111 ath_print(ath9k_hw_common(ah), ATH_DBG_ANY,
112 "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
113 timeout, reg, REG_READ(ah, reg), mask, val);
Sujithf1dc5602008-10-29 10:16:30 +0530114
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700115 return false;
116}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400117EXPORT_SYMBOL(ath9k_hw_wait);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700118
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700119u32 ath9k_hw_reverse_bits(u32 val, u32 n)
120{
121 u32 retval;
122 int i;
123
124 for (i = 0, retval = 0; i < n; i++) {
125 retval = (retval << 1) | (val & 1);
126 val >>= 1;
127 }
128 return retval;
129}
130
Sujithcbe61d82009-02-09 13:27:12 +0530131bool ath9k_get_channel_edges(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530132 u16 flags, u16 *low,
133 u16 *high)
134{
Sujith2660b812009-02-09 13:27:26 +0530135 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530136
137 if (flags & CHANNEL_5GHZ) {
138 *low = pCap->low_5ghz_chan;
139 *high = pCap->high_5ghz_chan;
140 return true;
141 }
142 if ((flags & CHANNEL_2GHZ)) {
143 *low = pCap->low_2ghz_chan;
144 *high = pCap->high_2ghz_chan;
145 return true;
146 }
147 return false;
148}
149
Sujithcbe61d82009-02-09 13:27:12 +0530150u16 ath9k_hw_computetxtime(struct ath_hw *ah,
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400151 const struct ath_rate_table *rates,
Sujithf1dc5602008-10-29 10:16:30 +0530152 u32 frameLen, u16 rateix,
153 bool shortPreamble)
154{
155 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
156 u32 kbps;
157
Sujithe63835b2008-11-18 09:07:53 +0530158 kbps = rates->info[rateix].ratekbps;
Sujithf1dc5602008-10-29 10:16:30 +0530159
160 if (kbps == 0)
161 return 0;
162
163 switch (rates->info[rateix].phy) {
Sujith46d14a52008-11-18 09:08:13 +0530164 case WLAN_RC_PHY_CCK:
Sujithf1dc5602008-10-29 10:16:30 +0530165 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
Sujithe63835b2008-11-18 09:07:53 +0530166 if (shortPreamble && rates->info[rateix].short_preamble)
Sujithf1dc5602008-10-29 10:16:30 +0530167 phyTime >>= 1;
168 numBits = frameLen << 3;
169 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
170 break;
Sujith46d14a52008-11-18 09:08:13 +0530171 case WLAN_RC_PHY_OFDM:
Sujith2660b812009-02-09 13:27:26 +0530172 if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530173 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
174 numBits = OFDM_PLCP_BITS + (frameLen << 3);
175 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
176 txTime = OFDM_SIFS_TIME_QUARTER
177 + OFDM_PREAMBLE_TIME_QUARTER
178 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
Sujith2660b812009-02-09 13:27:26 +0530179 } else if (ah->curchan &&
180 IS_CHAN_HALF_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530181 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
182 numBits = OFDM_PLCP_BITS + (frameLen << 3);
183 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
184 txTime = OFDM_SIFS_TIME_HALF +
185 OFDM_PREAMBLE_TIME_HALF
186 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
187 } else {
188 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
189 numBits = OFDM_PLCP_BITS + (frameLen << 3);
190 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
191 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
192 + (numSymbols * OFDM_SYMBOL_TIME);
193 }
194 break;
195 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700196 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
197 "Unknown phy %u (rate ix %u)\n",
198 rates->info[rateix].phy, rateix);
Sujithf1dc5602008-10-29 10:16:30 +0530199 txTime = 0;
200 break;
201 }
202
203 return txTime;
204}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400205EXPORT_SYMBOL(ath9k_hw_computetxtime);
Sujithf1dc5602008-10-29 10:16:30 +0530206
Sujithcbe61d82009-02-09 13:27:12 +0530207void ath9k_hw_get_channel_centers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530208 struct ath9k_channel *chan,
209 struct chan_centers *centers)
210{
211 int8_t extoff;
Sujithf1dc5602008-10-29 10:16:30 +0530212
213 if (!IS_CHAN_HT40(chan)) {
214 centers->ctl_center = centers->ext_center =
215 centers->synth_center = chan->channel;
216 return;
217 }
218
219 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
220 (chan->chanmode == CHANNEL_G_HT40PLUS)) {
221 centers->synth_center =
222 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
223 extoff = 1;
224 } else {
225 centers->synth_center =
226 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
227 extoff = -1;
228 }
229
230 centers->ctl_center =
231 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700232 /* 25 MHz spacing is supported by hw but not on upper layers */
Sujithf1dc5602008-10-29 10:16:30 +0530233 centers->ext_center =
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700234 centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT);
Sujithf1dc5602008-10-29 10:16:30 +0530235}
236
237/******************/
238/* Chip Revisions */
239/******************/
240
Sujithcbe61d82009-02-09 13:27:12 +0530241static void ath9k_hw_read_revisions(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530242{
243 u32 val;
244
245 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
246
247 if (val == 0xFF) {
248 val = REG_READ(ah, AR_SREV);
Sujithd535a422009-02-09 13:27:06 +0530249 ah->hw_version.macVersion =
250 (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
251 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
Sujith2660b812009-02-09 13:27:26 +0530252 ah->is_pciexpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
Sujithf1dc5602008-10-29 10:16:30 +0530253 } else {
254 if (!AR_SREV_9100(ah))
Sujithd535a422009-02-09 13:27:06 +0530255 ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
Sujithf1dc5602008-10-29 10:16:30 +0530256
Sujithd535a422009-02-09 13:27:06 +0530257 ah->hw_version.macRev = val & AR_SREV_REVISION;
Sujithf1dc5602008-10-29 10:16:30 +0530258
Sujithd535a422009-02-09 13:27:06 +0530259 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
Sujith2660b812009-02-09 13:27:26 +0530260 ah->is_pciexpress = true;
Sujithf1dc5602008-10-29 10:16:30 +0530261 }
262}
263
Sujithcbe61d82009-02-09 13:27:12 +0530264static int ath9k_hw_get_radiorev(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530265{
266 u32 val;
267 int i;
268
269 REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
270
271 for (i = 0; i < 8; i++)
272 REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
273 val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
274 val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
275
276 return ath9k_hw_reverse_bits(val, 8);
277}
278
279/************************************/
280/* HW Attach, Detach, Init Routines */
281/************************************/
282
Sujithcbe61d82009-02-09 13:27:12 +0530283static void ath9k_hw_disablepcie(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530284{
Sujithfeed0292009-01-29 11:37:35 +0530285 if (AR_SREV_9100(ah))
Sujithf1dc5602008-10-29 10:16:30 +0530286 return;
287
288 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
289 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
290 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
291 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
292 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
293 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
294 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
295 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
296 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
297
298 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
299}
300
Sujithcbe61d82009-02-09 13:27:12 +0530301static bool ath9k_hw_chip_test(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530302{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700303 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530304 u32 regAddr[2] = { AR_STA_ID0, AR_PHY_BASE + (8 << 2) };
305 u32 regHold[2];
306 u32 patternData[4] = { 0x55555555,
307 0xaaaaaaaa,
308 0x66666666,
309 0x99999999 };
310 int i, j;
311
312 for (i = 0; i < 2; i++) {
313 u32 addr = regAddr[i];
314 u32 wrData, rdData;
315
316 regHold[i] = REG_READ(ah, addr);
317 for (j = 0; j < 0x100; j++) {
318 wrData = (j << 16) | j;
319 REG_WRITE(ah, addr, wrData);
320 rdData = REG_READ(ah, addr);
321 if (rdData != wrData) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700322 ath_print(common, ATH_DBG_FATAL,
323 "address test failed "
324 "addr: 0x%08x - wr:0x%08x != "
325 "rd:0x%08x\n",
326 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530327 return false;
328 }
329 }
330 for (j = 0; j < 4; j++) {
331 wrData = patternData[j];
332 REG_WRITE(ah, addr, wrData);
333 rdData = REG_READ(ah, addr);
334 if (wrData != rdData) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700335 ath_print(common, ATH_DBG_FATAL,
336 "address test failed "
337 "addr: 0x%08x - wr:0x%08x != "
338 "rd:0x%08x\n",
339 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530340 return false;
341 }
342 }
343 REG_WRITE(ah, regAddr[i], regHold[i]);
344 }
345 udelay(100);
Sujithcbe61d82009-02-09 13:27:12 +0530346
Sujithf1dc5602008-10-29 10:16:30 +0530347 return true;
348}
349
350static const char *ath9k_hw_devname(u16 devid)
351{
352 switch (devid) {
353 case AR5416_DEVID_PCI:
Sujithf1dc5602008-10-29 10:16:30 +0530354 return "Atheros 5416";
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +0100355 case AR5416_DEVID_PCIE:
356 return "Atheros 5418";
Sujithf1dc5602008-10-29 10:16:30 +0530357 case AR9160_DEVID_PCI:
358 return "Atheros 9160";
Gabor Juhos0c1aa492009-01-14 20:17:12 +0100359 case AR5416_AR9100_DEVID:
360 return "Atheros 9100";
Sujithf1dc5602008-10-29 10:16:30 +0530361 case AR9280_DEVID_PCI:
362 case AR9280_DEVID_PCIE:
363 return "Atheros 9280";
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530364 case AR9285_DEVID_PCIE:
365 return "Atheros 9285";
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530366 case AR5416_DEVID_AR9287_PCI:
367 case AR5416_DEVID_AR9287_PCIE:
368 return "Atheros 9287";
Sujithf1dc5602008-10-29 10:16:30 +0530369 }
370
371 return NULL;
372}
373
Luis R. Rodriguezb8b0f372009-08-03 12:24:43 -0700374static void ath9k_hw_init_config(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700375{
376 int i;
377
Sujith2660b812009-02-09 13:27:26 +0530378 ah->config.dma_beacon_response_time = 2;
379 ah->config.sw_beacon_response_time = 10;
380 ah->config.additional_swba_backoff = 0;
381 ah->config.ack_6mb = 0x0;
382 ah->config.cwm_ignore_extcca = 0;
383 ah->config.pcie_powersave_enable = 0;
Sujith2660b812009-02-09 13:27:26 +0530384 ah->config.pcie_clock_req = 0;
Sujith2660b812009-02-09 13:27:26 +0530385 ah->config.pcie_waen = 0;
386 ah->config.analog_shiftreg = 1;
387 ah->config.ht_enable = 1;
388 ah->config.ofdm_trig_low = 200;
389 ah->config.ofdm_trig_high = 500;
390 ah->config.cck_trig_high = 200;
391 ah->config.cck_trig_low = 100;
392 ah->config.enable_ani = 1;
Sujith1cf68732009-08-13 09:34:32 +0530393 ah->config.diversity_control = ATH9K_ANT_VARIABLE;
Sujith2660b812009-02-09 13:27:26 +0530394 ah->config.antenna_switch_swap = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700395
396 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujith2660b812009-02-09 13:27:26 +0530397 ah->config.spurchans[i][0] = AR_NO_SPUR;
398 ah->config.spurchans[i][1] = AR_NO_SPUR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700399 }
400
Sujith0ef1f162009-03-30 15:28:35 +0530401 ah->config.intr_mitigation = true;
Luis R. Rodriguez61584252009-03-12 18:18:49 -0400402
403 /*
404 * We need this for PCI devices only (Cardbus, PCI, miniPCI)
405 * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
406 * This means we use it for all AR5416 devices, and the few
407 * minor PCI AR9280 devices out there.
408 *
409 * Serialization is required because these devices do not handle
410 * well the case of two concurrent reads/writes due to the latency
411 * involved. During one read/write another read/write can be issued
412 * on another CPU while the previous read/write may still be working
413 * on our hardware, if we hit this case the hardware poops in a loop.
414 * We prevent this by serializing reads and writes.
415 *
416 * This issue is not present on PCI-Express devices or pre-AR5416
417 * devices (legacy, 802.11abg).
418 */
419 if (num_possible_cpus() > 1)
David S. Miller2d6a5e92009-03-17 15:01:30 -0700420 ah->config.serialize_regmode = SER_REG_MODE_AUTO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700421}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400422EXPORT_SYMBOL(ath9k_hw_init);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700423
Luis R. Rodriguez50aca252009-08-03 12:24:42 -0700424static void ath9k_hw_init_defaults(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700425{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700426 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
427
428 regulatory->country_code = CTRY_DEFAULT;
429 regulatory->power_limit = MAX_RATE_POWER;
430 regulatory->tp_scale = ATH9K_TP_SCALE_MAX;
431
Sujithd535a422009-02-09 13:27:06 +0530432 ah->hw_version.magic = AR5416_MAGIC;
Sujithd535a422009-02-09 13:27:06 +0530433 ah->hw_version.subvendorid = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700434
435 ah->ah_flags = 0;
Luis R. Rodriguez8df5d1b2009-08-03 12:24:37 -0700436 if (ah->hw_version.devid == AR5416_AR9100_DEVID)
Sujithd535a422009-02-09 13:27:06 +0530437 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700438 if (!AR_SREV_9100(ah))
439 ah->ah_flags = AH_USE_EEPROM;
440
Sujith2660b812009-02-09 13:27:26 +0530441 ah->atim_window = 0;
Sujith2660b812009-02-09 13:27:26 +0530442 ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
443 ah->beacon_interval = 100;
444 ah->enable_32kHz_clock = DONT_USE_32KHZ;
445 ah->slottime = (u32) -1;
446 ah->acktimeout = (u32) -1;
447 ah->ctstimeout = (u32) -1;
448 ah->globaltxtimeout = (u32) -1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700449
Sujith2660b812009-02-09 13:27:26 +0530450 ah->gbeacon_rate = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700451
Gabor Juhoscbdec972009-07-24 17:27:22 +0200452 ah->power_mode = ATH9K_PM_UNDEFINED;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700453}
454
Sujithcbe61d82009-02-09 13:27:12 +0530455static int ath9k_hw_rf_claim(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700456{
457 u32 val;
458
459 REG_WRITE(ah, AR_PHY(0), 0x00000007);
460
461 val = ath9k_hw_get_radiorev(ah);
462 switch (val & AR_RADIO_SREV_MAJOR) {
463 case 0:
464 val = AR_RAD5133_SREV_MAJOR;
465 break;
466 case AR_RAD5133_SREV_MAJOR:
467 case AR_RAD5122_SREV_MAJOR:
468 case AR_RAD2133_SREV_MAJOR:
469 case AR_RAD2122_SREV_MAJOR:
470 break;
471 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700472 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
473 "Radio Chip Rev 0x%02X not supported\n",
474 val & AR_RADIO_SREV_MAJOR);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700475 return -EOPNOTSUPP;
476 }
477
Sujithd535a422009-02-09 13:27:06 +0530478 ah->hw_version.analog5GhzRev = val;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700479
480 return 0;
481}
482
Sujithcbe61d82009-02-09 13:27:12 +0530483static int ath9k_hw_init_macaddr(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700484{
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700485 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530486 u32 sum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700487 int i;
Sujithf1dc5602008-10-29 10:16:30 +0530488 u16 eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700489
Sujithf1dc5602008-10-29 10:16:30 +0530490 sum = 0;
491 for (i = 0; i < 3; i++) {
Sujithf74df6f2009-02-09 13:27:24 +0530492 eeval = ah->eep_ops->get_eeprom(ah, AR_EEPROM_MAC(i));
Sujithf1dc5602008-10-29 10:16:30 +0530493 sum += eeval;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700494 common->macaddr[2 * i] = eeval >> 8;
495 common->macaddr[2 * i + 1] = eeval & 0xff;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700496 }
Sujithd8baa932009-03-30 15:28:25 +0530497 if (sum == 0 || sum == 0xffff * 3)
Sujithf1dc5602008-10-29 10:16:30 +0530498 return -EADDRNOTAVAIL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700499
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700500 return 0;
501}
502
Sujithcbe61d82009-02-09 13:27:12 +0530503static void ath9k_hw_init_rxgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530504{
505 u32 rxgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530506
Sujithf74df6f2009-02-09 13:27:24 +0530507 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_17) {
508 rxgain_type = ah->eep_ops->get_eeprom(ah, EEP_RXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530509
510 if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530511 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530512 ar9280Modes_backoff_13db_rxgain_9280_2,
513 ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2), 6);
514 else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530515 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530516 ar9280Modes_backoff_23db_rxgain_9280_2,
517 ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 6);
518 else
Sujith2660b812009-02-09 13:27:26 +0530519 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530520 ar9280Modes_original_rxgain_9280_2,
521 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530522 } else {
Sujith2660b812009-02-09 13:27:26 +0530523 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530524 ar9280Modes_original_rxgain_9280_2,
525 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530526 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530527}
528
Sujithcbe61d82009-02-09 13:27:12 +0530529static void ath9k_hw_init_txgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530530{
531 u32 txgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530532
Sujithf74df6f2009-02-09 13:27:24 +0530533 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_19) {
534 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530535
536 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
Sujith2660b812009-02-09 13:27:26 +0530537 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530538 ar9280Modes_high_power_tx_gain_9280_2,
539 ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 6);
540 else
Sujith2660b812009-02-09 13:27:26 +0530541 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530542 ar9280Modes_original_tx_gain_9280_2,
543 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530544 } else {
Sujith2660b812009-02-09 13:27:26 +0530545 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530546 ar9280Modes_original_tx_gain_9280_2,
547 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530548 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530549}
550
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700551static int ath9k_hw_post_init(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700552{
553 int ecode;
554
Sujithd8baa932009-03-30 15:28:25 +0530555 if (!ath9k_hw_chip_test(ah))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700556 return -ENODEV;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700557
558 ecode = ath9k_hw_rf_claim(ah);
559 if (ecode != 0)
560 return ecode;
561
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700562 ecode = ath9k_hw_eeprom_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700563 if (ecode != 0)
564 return ecode;
Sujith7d01b222009-03-13 08:55:55 +0530565
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700566 ath_print(ath9k_hw_common(ah), ATH_DBG_CONFIG,
567 "Eeprom VER: %d, REV: %d\n",
568 ah->eep_ops->get_eeprom_ver(ah),
569 ah->eep_ops->get_eeprom_rev(ah));
Sujith7d01b222009-03-13 08:55:55 +0530570
Luis R. Rodriguez574d6b12009-10-19 02:33:37 -0400571 if (!AR_SREV_9280_10_OR_LATER(ah)) {
572 ecode = ath9k_hw_rf_alloc_ext_banks(ah);
573 if (ecode) {
574 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
575 "Failed allocating banks for "
576 "external radio\n");
577 return ecode;
578 }
579 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700580
581 if (!AR_SREV_9100(ah)) {
582 ath9k_hw_ani_setup(ah);
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700583 ath9k_hw_ani_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700584 }
Sujithf1dc5602008-10-29 10:16:30 +0530585
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700586 return 0;
587}
588
Luis R. Rodriguezee2bb462009-08-03 12:24:39 -0700589static bool ath9k_hw_devid_supported(u16 devid)
590{
591 switch (devid) {
592 case AR5416_DEVID_PCI:
593 case AR5416_DEVID_PCIE:
594 case AR5416_AR9100_DEVID:
595 case AR9160_DEVID_PCI:
596 case AR9280_DEVID_PCI:
597 case AR9280_DEVID_PCIE:
598 case AR9285_DEVID_PCIE:
599 case AR5416_DEVID_AR9287_PCI:
600 case AR5416_DEVID_AR9287_PCIE:
Luis R. Rodriguez7976b422009-09-23 23:07:02 -0400601 case AR9271_USB:
Luis R. Rodriguezee2bb462009-08-03 12:24:39 -0700602 return true;
603 default:
604 break;
605 }
606 return false;
607}
608
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700609static bool ath9k_hw_macversion_supported(u32 macversion)
610{
611 switch (macversion) {
612 case AR_SREV_VERSION_5416_PCI:
613 case AR_SREV_VERSION_5416_PCIE:
614 case AR_SREV_VERSION_9160:
615 case AR_SREV_VERSION_9100:
616 case AR_SREV_VERSION_9280:
617 case AR_SREV_VERSION_9285:
618 case AR_SREV_VERSION_9287:
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400619 case AR_SREV_VERSION_9271:
Luis R. Rodriguez7976b422009-09-23 23:07:02 -0400620 return true;
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700621 default:
622 break;
623 }
624 return false;
625}
626
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700627static void ath9k_hw_init_cal_settings(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700628{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700629 if (AR_SREV_9160_10_OR_LATER(ah)) {
630 if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530631 ah->iq_caldata.calData = &iq_cal_single_sample;
632 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700633 &adc_gain_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530634 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700635 &adc_dc_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530636 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700637 &adc_init_dc_cal;
638 } else {
Sujith2660b812009-02-09 13:27:26 +0530639 ah->iq_caldata.calData = &iq_cal_multi_sample;
640 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700641 &adc_gain_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530642 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700643 &adc_dc_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530644 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700645 &adc_init_dc_cal;
646 }
Sujith2660b812009-02-09 13:27:26 +0530647 ah->supp_cals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700648 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700649}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700650
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700651static void ath9k_hw_init_mode_regs(struct ath_hw *ah)
652{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400653 if (AR_SREV_9271(ah)) {
Luis R. Rodriguez85643282009-10-19 02:33:33 -0400654 INIT_INI_ARRAY(&ah->iniModes, ar9271Modes_9271,
655 ARRAY_SIZE(ar9271Modes_9271), 6);
656 INIT_INI_ARRAY(&ah->iniCommon, ar9271Common_9271,
657 ARRAY_SIZE(ar9271Common_9271), 2);
658 INIT_INI_ARRAY(&ah->iniModes_9271_1_0_only,
659 ar9271Modes_9271_1_0_only,
660 ARRAY_SIZE(ar9271Modes_9271_1_0_only), 6);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400661 return;
662 }
663
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530664 if (AR_SREV_9287_11_OR_LATER(ah)) {
665 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_1,
666 ARRAY_SIZE(ar9287Modes_9287_1_1), 6);
667 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_1,
668 ARRAY_SIZE(ar9287Common_9287_1_1), 2);
669 if (ah->config.pcie_clock_req)
670 INIT_INI_ARRAY(&ah->iniPcieSerdes,
671 ar9287PciePhy_clkreq_off_L1_9287_1_1,
672 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_1), 2);
673 else
674 INIT_INI_ARRAY(&ah->iniPcieSerdes,
675 ar9287PciePhy_clkreq_always_on_L1_9287_1_1,
676 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_1),
677 2);
678 } else if (AR_SREV_9287_10_OR_LATER(ah)) {
679 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_0,
680 ARRAY_SIZE(ar9287Modes_9287_1_0), 6);
681 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_0,
682 ARRAY_SIZE(ar9287Common_9287_1_0), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700683
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530684 if (ah->config.pcie_clock_req)
685 INIT_INI_ARRAY(&ah->iniPcieSerdes,
686 ar9287PciePhy_clkreq_off_L1_9287_1_0,
687 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_0), 2);
688 else
689 INIT_INI_ARRAY(&ah->iniPcieSerdes,
690 ar9287PciePhy_clkreq_always_on_L1_9287_1_0,
691 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_0),
692 2);
693 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
694
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530695
Sujith2660b812009-02-09 13:27:26 +0530696 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530697 ARRAY_SIZE(ar9285Modes_9285_1_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530698 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530699 ARRAY_SIZE(ar9285Common_9285_1_2), 2);
700
Sujith2660b812009-02-09 13:27:26 +0530701 if (ah->config.pcie_clock_req) {
702 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530703 ar9285PciePhy_clkreq_off_L1_9285_1_2,
704 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2);
705 } else {
Sujith2660b812009-02-09 13:27:26 +0530706 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530707 ar9285PciePhy_clkreq_always_on_L1_9285_1_2,
708 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2),
709 2);
710 }
711 } else if (AR_SREV_9285_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530712 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530713 ARRAY_SIZE(ar9285Modes_9285), 6);
Sujith2660b812009-02-09 13:27:26 +0530714 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530715 ARRAY_SIZE(ar9285Common_9285), 2);
716
Sujith2660b812009-02-09 13:27:26 +0530717 if (ah->config.pcie_clock_req) {
718 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530719 ar9285PciePhy_clkreq_off_L1_9285,
720 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2);
721 } else {
Sujith2660b812009-02-09 13:27:26 +0530722 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530723 ar9285PciePhy_clkreq_always_on_L1_9285,
724 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285), 2);
725 }
726 } else if (AR_SREV_9280_20_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530727 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700728 ARRAY_SIZE(ar9280Modes_9280_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530729 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700730 ARRAY_SIZE(ar9280Common_9280_2), 2);
731
Sujith2660b812009-02-09 13:27:26 +0530732 if (ah->config.pcie_clock_req) {
733 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530734 ar9280PciePhy_clkreq_off_L1_9280,
735 ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700736 } else {
Sujith2660b812009-02-09 13:27:26 +0530737 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530738 ar9280PciePhy_clkreq_always_on_L1_9280,
739 ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700740 }
Sujith2660b812009-02-09 13:27:26 +0530741 INIT_INI_ARRAY(&ah->iniModesAdditional,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700742 ar9280Modes_fast_clock_9280_2,
Sujithf1dc5602008-10-29 10:16:30 +0530743 ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700744 } else if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530745 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700746 ARRAY_SIZE(ar9280Modes_9280), 6);
Sujith2660b812009-02-09 13:27:26 +0530747 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700748 ARRAY_SIZE(ar9280Common_9280), 2);
749 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530750 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700751 ARRAY_SIZE(ar5416Modes_9160), 6);
Sujith2660b812009-02-09 13:27:26 +0530752 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700753 ARRAY_SIZE(ar5416Common_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530754 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700755 ARRAY_SIZE(ar5416Bank0_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530756 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700757 ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530758 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700759 ARRAY_SIZE(ar5416Bank1_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530760 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700761 ARRAY_SIZE(ar5416Bank2_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530762 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700763 ARRAY_SIZE(ar5416Bank3_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530764 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700765 ARRAY_SIZE(ar5416Bank6_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530766 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700767 ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530768 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700769 ARRAY_SIZE(ar5416Bank7_9160), 2);
770 if (AR_SREV_9160_11(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530771 INIT_INI_ARRAY(&ah->iniAddac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700772 ar5416Addac_91601_1,
773 ARRAY_SIZE(ar5416Addac_91601_1), 2);
774 } else {
Sujith2660b812009-02-09 13:27:26 +0530775 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700776 ARRAY_SIZE(ar5416Addac_9160), 2);
777 }
778 } else if (AR_SREV_9100_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530779 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700780 ARRAY_SIZE(ar5416Modes_9100), 6);
Sujith2660b812009-02-09 13:27:26 +0530781 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700782 ARRAY_SIZE(ar5416Common_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530783 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700784 ARRAY_SIZE(ar5416Bank0_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530785 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700786 ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530787 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700788 ARRAY_SIZE(ar5416Bank1_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530789 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700790 ARRAY_SIZE(ar5416Bank2_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530791 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700792 ARRAY_SIZE(ar5416Bank3_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530793 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700794 ARRAY_SIZE(ar5416Bank6_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530795 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700796 ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530797 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700798 ARRAY_SIZE(ar5416Bank7_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530799 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700800 ARRAY_SIZE(ar5416Addac_9100), 2);
801 } else {
Sujith2660b812009-02-09 13:27:26 +0530802 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700803 ARRAY_SIZE(ar5416Modes), 6);
Sujith2660b812009-02-09 13:27:26 +0530804 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700805 ARRAY_SIZE(ar5416Common), 2);
Sujith2660b812009-02-09 13:27:26 +0530806 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700807 ARRAY_SIZE(ar5416Bank0), 2);
Sujith2660b812009-02-09 13:27:26 +0530808 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700809 ARRAY_SIZE(ar5416BB_RfGain), 3);
Sujith2660b812009-02-09 13:27:26 +0530810 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700811 ARRAY_SIZE(ar5416Bank1), 2);
Sujith2660b812009-02-09 13:27:26 +0530812 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700813 ARRAY_SIZE(ar5416Bank2), 2);
Sujith2660b812009-02-09 13:27:26 +0530814 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700815 ARRAY_SIZE(ar5416Bank3), 3);
Sujith2660b812009-02-09 13:27:26 +0530816 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700817 ARRAY_SIZE(ar5416Bank6), 3);
Sujith2660b812009-02-09 13:27:26 +0530818 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700819 ARRAY_SIZE(ar5416Bank6TPC), 3);
Sujith2660b812009-02-09 13:27:26 +0530820 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700821 ARRAY_SIZE(ar5416Bank7), 2);
Sujith2660b812009-02-09 13:27:26 +0530822 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700823 ARRAY_SIZE(ar5416Addac), 2);
824 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700825}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700826
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700827static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
828{
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530829 if (AR_SREV_9287_11_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530830 INIT_INI_ARRAY(&ah->iniModesRxGain,
831 ar9287Modes_rx_gain_9287_1_1,
832 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_1), 6);
833 else if (AR_SREV_9287_10(ah))
834 INIT_INI_ARRAY(&ah->iniModesRxGain,
835 ar9287Modes_rx_gain_9287_1_0,
836 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_0), 6);
837 else if (AR_SREV_9280_20(ah))
838 ath9k_hw_init_rxgain_ini(ah);
839
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530840 if (AR_SREV_9287_11_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530841 INIT_INI_ARRAY(&ah->iniModesTxGain,
842 ar9287Modes_tx_gain_9287_1_1,
843 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_1), 6);
844 } else if (AR_SREV_9287_10(ah)) {
845 INIT_INI_ARRAY(&ah->iniModesTxGain,
846 ar9287Modes_tx_gain_9287_1_0,
847 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_0), 6);
848 } else if (AR_SREV_9280_20(ah)) {
849 ath9k_hw_init_txgain_ini(ah);
850 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530851 u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
852
853 /* txgain table */
854 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) {
855 INIT_INI_ARRAY(&ah->iniModesTxGain,
856 ar9285Modes_high_power_tx_gain_9285_1_2,
857 ARRAY_SIZE(ar9285Modes_high_power_tx_gain_9285_1_2), 6);
858 } else {
859 INIT_INI_ARRAY(&ah->iniModesTxGain,
860 ar9285Modes_original_tx_gain_9285_1_2,
861 ARRAY_SIZE(ar9285Modes_original_tx_gain_9285_1_2), 6);
862 }
863
864 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700865}
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530866
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700867static void ath9k_hw_init_11a_eeprom_fix(struct ath_hw *ah)
868{
869 u32 i, j;
Sujith06d0f062009-02-12 10:06:45 +0530870
871 if ((ah->hw_version.devid == AR9280_DEVID_PCI) &&
872 test_bit(ATH9K_MODE_11A, ah->caps.wireless_modes)) {
873
874 /* EEPROM Fixup */
Sujith2660b812009-02-09 13:27:26 +0530875 for (i = 0; i < ah->iniModes.ia_rows; i++) {
876 u32 reg = INI_RA(&ah->iniModes, i, 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700877
Sujith2660b812009-02-09 13:27:26 +0530878 for (j = 1; j < ah->iniModes.ia_columns; j++) {
879 u32 val = INI_RA(&ah->iniModes, i, j);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700880
Sujith2660b812009-02-09 13:27:26 +0530881 INI_RA(&ah->iniModes, i, j) =
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530882 ath9k_hw_ini_fixup(ah,
Sujith2660b812009-02-09 13:27:26 +0530883 &ah->eeprom.def,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700884 reg, val);
885 }
886 }
887 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700888}
889
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700890int ath9k_hw_init(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700891{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700892 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700893 int r = 0;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700894
Luis R. Rodriguez3ca34032009-09-23 23:07:01 -0400895 if (!ath9k_hw_devid_supported(ah->hw_version.devid)) {
896 ath_print(common, ATH_DBG_FATAL,
897 "Unsupported device ID: 0x%0x\n",
898 ah->hw_version.devid);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700899 return -EOPNOTSUPP;
Luis R. Rodriguez3ca34032009-09-23 23:07:01 -0400900 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700901
902 ath9k_hw_init_defaults(ah);
903 ath9k_hw_init_config(ah);
904
905 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700906 ath_print(common, ATH_DBG_FATAL,
907 "Couldn't reset chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700908 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700909 }
910
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700911 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700912 ath_print(common, ATH_DBG_FATAL, "Couldn't wakeup chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700913 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700914 }
915
916 if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
917 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
918 (AR_SREV_9280(ah) && !ah->is_pciexpress)) {
919 ah->config.serialize_regmode =
920 SER_REG_MODE_ON;
921 } else {
922 ah->config.serialize_regmode =
923 SER_REG_MODE_OFF;
924 }
925 }
926
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700927 ath_print(common, ATH_DBG_RESET, "serialize_regmode is %d\n",
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700928 ah->config.serialize_regmode);
929
930 if (!ath9k_hw_macversion_supported(ah->hw_version.macVersion)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700931 ath_print(common, ATH_DBG_FATAL,
932 "Mac Chip Rev 0x%02x.%x is not supported by "
933 "this driver\n", ah->hw_version.macVersion,
934 ah->hw_version.macRev);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700935 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700936 }
937
938 if (AR_SREV_9100(ah)) {
939 ah->iq_caldata.calData = &iq_cal_multi_sample;
940 ah->supp_cals = IQ_MISMATCH_CAL;
941 ah->is_pciexpress = false;
942 }
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400943
944 if (AR_SREV_9271(ah))
945 ah->is_pciexpress = false;
946
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700947 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
948
949 ath9k_hw_init_cal_settings(ah);
950
951 ah->ani_function = ATH9K_ANI_ALL;
Luis R. Rodrigueze68a0602009-10-19 02:33:41 -0400952 if (AR_SREV_9280_10_OR_LATER(ah)) {
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700953 ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
Luis R. Rodrigueze68a0602009-10-19 02:33:41 -0400954 ah->ath9k_hw_rf_set_freq = &ath9k_hw_ar9280_set_channel;
955 } else
956 ah->ath9k_hw_rf_set_freq = &ath9k_hw_set_channel;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700957
958 ath9k_hw_init_mode_regs(ah);
959
960 if (ah->is_pciexpress)
Vivek Natarajan93b1b372009-09-17 09:24:58 +0530961 ath9k_hw_configpcipowersave(ah, 0, 0);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700962 else
963 ath9k_hw_disablepcie(ah);
964
Sujith193cd452009-09-18 15:04:07 +0530965 /* Support for Japan ch.14 (2484) spread */
966 if (AR_SREV_9287_11_OR_LATER(ah)) {
967 INIT_INI_ARRAY(&ah->iniCckfirNormal,
968 ar9287Common_normal_cck_fir_coeff_92871_1,
969 ARRAY_SIZE(ar9287Common_normal_cck_fir_coeff_92871_1), 2);
970 INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
971 ar9287Common_japan_2484_cck_fir_coeff_92871_1,
972 ARRAY_SIZE(ar9287Common_japan_2484_cck_fir_coeff_92871_1), 2);
973 }
974
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700975 r = ath9k_hw_post_init(ah);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700976 if (r)
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700977 return r;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700978
979 ath9k_hw_init_mode_gain_regs(ah);
980 ath9k_hw_fill_cap_info(ah);
981 ath9k_hw_init_11a_eeprom_fix(ah);
Sujithf6688cd2008-12-07 21:43:10 +0530982
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700983 r = ath9k_hw_init_macaddr(ah);
984 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700985 ath_print(common, ATH_DBG_FATAL,
986 "Failed to initialize MAC address\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700987 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700988 }
989
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400990 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
Sujith2660b812009-02-09 13:27:26 +0530991 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700992 else
Sujith2660b812009-02-09 13:27:26 +0530993 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700994
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700995 ath9k_init_nfcal_hist_buffer(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700996
Luis R. Rodriguez211f5852009-10-06 21:19:07 -0400997 common->state = ATH_HW_INITIALIZED;
998
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700999 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001000}
1001
Sujithcbe61d82009-02-09 13:27:12 +05301002static void ath9k_hw_init_bb(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301003 struct ath9k_channel *chan)
1004{
1005 u32 synthDelay;
1006
1007 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +05301008 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +05301009 synthDelay = (4 * synthDelay) / 22;
1010 else
1011 synthDelay /= 10;
1012
1013 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
1014
1015 udelay(synthDelay + BASE_ACTIVATE_DELAY);
1016}
1017
Sujithcbe61d82009-02-09 13:27:12 +05301018static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301019{
1020 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
1021 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
1022
1023 REG_WRITE(ah, AR_QOS_NO_ACK,
1024 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
1025 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
1026 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
1027
1028 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
1029 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
1030 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
1031 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
1032 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
1033}
1034
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -04001035static void ath9k_hw_change_target_baud(struct ath_hw *ah, u32 freq, u32 baud)
1036{
1037 u32 lcr;
1038 u32 baud_divider = freq * 1000 * 1000 / 16 / baud;
1039
1040 lcr = REG_READ(ah , 0x5100c);
1041 lcr |= 0x80;
1042
1043 REG_WRITE(ah, 0x5100c, lcr);
1044 REG_WRITE(ah, 0x51004, (baud_divider >> 8));
1045 REG_WRITE(ah, 0x51000, (baud_divider & 0xff));
1046
1047 lcr &= ~0x80;
1048 REG_WRITE(ah, 0x5100c, lcr);
1049}
1050
Sujithcbe61d82009-02-09 13:27:12 +05301051static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301052 struct ath9k_channel *chan)
1053{
1054 u32 pll;
1055
1056 if (AR_SREV_9100(ah)) {
1057 if (chan && IS_CHAN_5GHZ(chan))
1058 pll = 0x1450;
1059 else
1060 pll = 0x1458;
1061 } else {
1062 if (AR_SREV_9280_10_OR_LATER(ah)) {
1063 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
1064
1065 if (chan && IS_CHAN_HALF_RATE(chan))
1066 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
1067 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1068 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
1069
1070 if (chan && IS_CHAN_5GHZ(chan)) {
1071 pll |= SM(0x28, AR_RTC_9160_PLL_DIV);
1072
1073
1074 if (AR_SREV_9280_20(ah)) {
1075 if (((chan->channel % 20) == 0)
1076 || ((chan->channel % 10) == 0))
1077 pll = 0x2850;
1078 else
1079 pll = 0x142c;
1080 }
1081 } else {
1082 pll |= SM(0x2c, AR_RTC_9160_PLL_DIV);
1083 }
1084
1085 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1086
1087 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
1088
1089 if (chan && IS_CHAN_HALF_RATE(chan))
1090 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
1091 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1092 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
1093
1094 if (chan && IS_CHAN_5GHZ(chan))
1095 pll |= SM(0x50, AR_RTC_9160_PLL_DIV);
1096 else
1097 pll |= SM(0x58, AR_RTC_9160_PLL_DIV);
1098 } else {
1099 pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2;
1100
1101 if (chan && IS_CHAN_HALF_RATE(chan))
1102 pll |= SM(0x1, AR_RTC_PLL_CLKSEL);
1103 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1104 pll |= SM(0x2, AR_RTC_PLL_CLKSEL);
1105
1106 if (chan && IS_CHAN_5GHZ(chan))
1107 pll |= SM(0xa, AR_RTC_PLL_DIV);
1108 else
1109 pll |= SM(0xb, AR_RTC_PLL_DIV);
1110 }
1111 }
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001112 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +05301113
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -04001114 /* Switch the core clock for ar9271 to 117Mhz */
1115 if (AR_SREV_9271(ah)) {
1116 if ((pll == 0x142c) || (pll == 0x2850) ) {
1117 udelay(500);
1118 /* set CLKOBS to output AHB clock */
1119 REG_WRITE(ah, 0x7020, 0xe);
1120 /*
1121 * 0x304: 117Mhz, ahb_ratio: 1x1
1122 * 0x306: 40Mhz, ahb_ratio: 1x1
1123 */
1124 REG_WRITE(ah, 0x50040, 0x304);
1125 /*
1126 * makes adjustments for the baud dividor to keep the
1127 * targetted baud rate based on the used core clock.
1128 */
1129 ath9k_hw_change_target_baud(ah, AR9271_CORE_CLOCK,
1130 AR9271_TARGET_BAUD_RATE);
1131 }
1132 }
1133
Sujithf1dc5602008-10-29 10:16:30 +05301134 udelay(RTC_PLL_SETTLE_DELAY);
1135
1136 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
1137}
1138
Sujithcbe61d82009-02-09 13:27:12 +05301139static void ath9k_hw_init_chain_masks(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301140{
Sujithf1dc5602008-10-29 10:16:30 +05301141 int rx_chainmask, tx_chainmask;
1142
Sujith2660b812009-02-09 13:27:26 +05301143 rx_chainmask = ah->rxchainmask;
1144 tx_chainmask = ah->txchainmask;
Sujithf1dc5602008-10-29 10:16:30 +05301145
1146 switch (rx_chainmask) {
1147 case 0x5:
1148 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1149 AR_PHY_SWAP_ALT_CHAIN);
1150 case 0x3:
Sujithd535a422009-02-09 13:27:06 +05301151 if (((ah)->hw_version.macVersion <= AR_SREV_VERSION_9160)) {
Sujithf1dc5602008-10-29 10:16:30 +05301152 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7);
1153 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7);
1154 break;
1155 }
1156 case 0x1:
1157 case 0x2:
Sujithf1dc5602008-10-29 10:16:30 +05301158 case 0x7:
1159 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
1160 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
1161 break;
1162 default:
1163 break;
1164 }
1165
1166 REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);
1167 if (tx_chainmask == 0x5) {
1168 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1169 AR_PHY_SWAP_ALT_CHAIN);
1170 }
1171 if (AR_SREV_9100(ah))
1172 REG_WRITE(ah, AR_PHY_ANALOG_SWAP,
1173 REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
1174}
1175
Sujithcbe61d82009-02-09 13:27:12 +05301176static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -08001177 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301178{
Sujith2660b812009-02-09 13:27:26 +05301179 ah->mask_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +05301180 AR_IMR_TXURN |
1181 AR_IMR_RXERR |
1182 AR_IMR_RXORN |
1183 AR_IMR_BCNMISC;
1184
Sujith0ef1f162009-03-30 15:28:35 +05301185 if (ah->config.intr_mitigation)
Sujith2660b812009-02-09 13:27:26 +05301186 ah->mask_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
Sujithf1dc5602008-10-29 10:16:30 +05301187 else
Sujith2660b812009-02-09 13:27:26 +05301188 ah->mask_reg |= AR_IMR_RXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301189
Sujith2660b812009-02-09 13:27:26 +05301190 ah->mask_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301191
Colin McCabed97809d2008-12-01 13:38:55 -08001192 if (opmode == NL80211_IFTYPE_AP)
Sujith2660b812009-02-09 13:27:26 +05301193 ah->mask_reg |= AR_IMR_MIB;
Sujithf1dc5602008-10-29 10:16:30 +05301194
Sujith2660b812009-02-09 13:27:26 +05301195 REG_WRITE(ah, AR_IMR, ah->mask_reg);
Sujithf1dc5602008-10-29 10:16:30 +05301196 REG_WRITE(ah, AR_IMR_S2, REG_READ(ah, AR_IMR_S2) | AR_IMR_S2_GTT);
1197
1198 if (!AR_SREV_9100(ah)) {
1199 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
1200 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
1201 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
1202 }
1203}
1204
Sujithcbe61d82009-02-09 13:27:12 +05301205static bool ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301206{
Sujithf1dc5602008-10-29 10:16:30 +05301207 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001208 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1209 "bad ack timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301210 ah->acktimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301211 return false;
1212 } else {
1213 REG_RMW_FIELD(ah, AR_TIME_OUT,
1214 AR_TIME_OUT_ACK, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301215 ah->acktimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301216 return true;
1217 }
1218}
1219
Sujithcbe61d82009-02-09 13:27:12 +05301220static bool ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301221{
Sujithf1dc5602008-10-29 10:16:30 +05301222 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_CTS))) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001223 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1224 "bad cts timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301225 ah->ctstimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301226 return false;
1227 } else {
1228 REG_RMW_FIELD(ah, AR_TIME_OUT,
1229 AR_TIME_OUT_CTS, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301230 ah->ctstimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301231 return true;
1232 }
1233}
1234
Sujithcbe61d82009-02-09 13:27:12 +05301235static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +05301236{
Sujithf1dc5602008-10-29 10:16:30 +05301237 if (tu > 0xFFFF) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001238 ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT,
1239 "bad global tx timeout %u\n", tu);
Sujith2660b812009-02-09 13:27:26 +05301240 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301241 return false;
1242 } else {
1243 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +05301244 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +05301245 return true;
1246 }
1247}
1248
Sujithcbe61d82009-02-09 13:27:12 +05301249static void ath9k_hw_init_user_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301250{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001251 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
1252 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +05301253
Sujith2660b812009-02-09 13:27:26 +05301254 if (ah->misc_mode != 0)
Sujithf1dc5602008-10-29 10:16:30 +05301255 REG_WRITE(ah, AR_PCU_MISC,
Sujith2660b812009-02-09 13:27:26 +05301256 REG_READ(ah, AR_PCU_MISC) | ah->misc_mode);
1257 if (ah->slottime != (u32) -1)
1258 ath9k_hw_setslottime(ah, ah->slottime);
1259 if (ah->acktimeout != (u32) -1)
1260 ath9k_hw_set_ack_timeout(ah, ah->acktimeout);
1261 if (ah->ctstimeout != (u32) -1)
1262 ath9k_hw_set_cts_timeout(ah, ah->ctstimeout);
1263 if (ah->globaltxtimeout != (u32) -1)
1264 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Sujithf1dc5602008-10-29 10:16:30 +05301265}
1266
1267const char *ath9k_hw_probe(u16 vendorid, u16 devid)
1268{
1269 return vendorid == ATHEROS_VENDOR_ID ?
1270 ath9k_hw_devname(devid) : NULL;
1271}
1272
Sujithcbe61d82009-02-09 13:27:12 +05301273void ath9k_hw_detach(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001274{
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001275 struct ath_common *common = ath9k_hw_common(ah);
1276
1277 if (common->state <= ATH_HW_INITIALIZED)
1278 goto free_hw;
1279
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001280 if (!AR_SREV_9100(ah))
Luis R. Rodrigueze70c0cf2009-08-03 12:24:51 -07001281 ath9k_hw_ani_disable(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001282
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001283 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001284
1285free_hw:
Luis R. Rodriguezdc51dd52009-10-19 02:33:39 -04001286 if (!AR_SREV_9280_10_OR_LATER(ah))
1287 ath9k_hw_rf_free_ext_banks(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001288 kfree(ah);
Luis R. Rodriguez9db6b6a2009-08-03 12:24:52 -07001289 ah = NULL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001290}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001291EXPORT_SYMBOL(ath9k_hw_detach);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001292
Sujithf1dc5602008-10-29 10:16:30 +05301293/*******/
1294/* INI */
1295/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001296
Sujithcbe61d82009-02-09 13:27:12 +05301297static void ath9k_hw_override_ini(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301298 struct ath9k_channel *chan)
1299{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001300 u32 val;
1301
1302 if (AR_SREV_9271(ah)) {
1303 /*
1304 * Enable spectral scan to solution for issues with stuck
1305 * beacons on AR9271 1.0. The beacon stuck issue is not seeon on
1306 * AR9271 1.1
1307 */
1308 if (AR_SREV_9271_10(ah)) {
Luis R. Rodriguezec11bb82009-10-27 12:59:36 -04001309 val = REG_READ(ah, AR_PHY_SPECTRAL_SCAN) |
1310 AR_PHY_SPECTRAL_SCAN_ENABLE;
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001311 REG_WRITE(ah, AR_PHY_SPECTRAL_SCAN, val);
1312 }
1313 else if (AR_SREV_9271_11(ah))
1314 /*
1315 * change AR_PHY_RF_CTL3 setting to fix MAC issue
1316 * present on AR9271 1.1
1317 */
1318 REG_WRITE(ah, AR_PHY_RF_CTL3, 0x3a020001);
1319 return;
1320 }
1321
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +05301322 /*
1323 * Set the RX_ABORT and RX_DIS and clear if off only after
1324 * RXE is set for MAC. This prevents frames with corrupted
1325 * descriptor status.
1326 */
1327 REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
1328
Vasanthakumar Thiagarajan204d7942009-09-17 09:26:14 +05301329 if (AR_SREV_9280_10_OR_LATER(ah)) {
1330 val = REG_READ(ah, AR_PCU_MISC_MODE2) &
1331 (~AR_PCU_MISC_MODE2_HWWAR1);
1332
1333 if (AR_SREV_9287_10_OR_LATER(ah))
1334 val = val & (~AR_PCU_MISC_MODE2_HWWAR2);
1335
1336 REG_WRITE(ah, AR_PCU_MISC_MODE2, val);
1337 }
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +05301338
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001339 if (!AR_SREV_5416_20_OR_LATER(ah) ||
Sujithf1dc5602008-10-29 10:16:30 +05301340 AR_SREV_9280_10_OR_LATER(ah))
1341 return;
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001342 /*
1343 * Disable BB clock gating
1344 * Necessary to avoid issues on AR5416 2.0
1345 */
Sujithf1dc5602008-10-29 10:16:30 +05301346 REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
1347}
1348
Sujithcbe61d82009-02-09 13:27:12 +05301349static u32 ath9k_hw_def_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301350 struct ar5416_eeprom_def *pEepData,
Sujithf1dc5602008-10-29 10:16:30 +05301351 u32 reg, u32 value)
1352{
1353 struct base_eep_header *pBase = &(pEepData->baseEepHeader);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001354 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301355
Sujithd535a422009-02-09 13:27:06 +05301356 switch (ah->hw_version.devid) {
Sujithf1dc5602008-10-29 10:16:30 +05301357 case AR9280_DEVID_PCI:
1358 if (reg == 0x7894) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001359 ath_print(common, ATH_DBG_EEPROM,
Sujithf1dc5602008-10-29 10:16:30 +05301360 "ini VAL: %x EEPROM: %x\n", value,
1361 (pBase->version & 0xff));
1362
1363 if ((pBase->version & 0xff) > 0x0a) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001364 ath_print(common, ATH_DBG_EEPROM,
1365 "PWDCLKIND: %d\n",
1366 pBase->pwdclkind);
Sujithf1dc5602008-10-29 10:16:30 +05301367 value &= ~AR_AN_TOP2_PWDCLKIND;
1368 value |= AR_AN_TOP2_PWDCLKIND &
1369 (pBase->pwdclkind << AR_AN_TOP2_PWDCLKIND_S);
1370 } else {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001371 ath_print(common, ATH_DBG_EEPROM,
1372 "PWDCLKIND Earlier Rev\n");
Sujithf1dc5602008-10-29 10:16:30 +05301373 }
1374
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001375 ath_print(common, ATH_DBG_EEPROM,
1376 "final ini VAL: %x\n", value);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001377 }
Sujithf1dc5602008-10-29 10:16:30 +05301378 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001379 }
1380
Sujithf1dc5602008-10-29 10:16:30 +05301381 return value;
1382}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001383
Sujithcbe61d82009-02-09 13:27:12 +05301384static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301385 struct ar5416_eeprom_def *pEepData,
1386 u32 reg, u32 value)
1387{
Sujith2660b812009-02-09 13:27:26 +05301388 if (ah->eep_map == EEP_MAP_4KBITS)
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301389 return value;
1390 else
1391 return ath9k_hw_def_ini_fixup(ah, pEepData, reg, value);
1392}
1393
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301394static void ath9k_olc_init(struct ath_hw *ah)
1395{
1396 u32 i;
1397
Vivek Natarajandb91f2e2009-08-14 11:27:16 +05301398 if (OLC_FOR_AR9287_10_LATER) {
1399 REG_SET_BIT(ah, AR_PHY_TX_PWRCTRL9,
1400 AR_PHY_TX_PWRCTRL9_RES_DC_REMOVAL);
1401 ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TXPC0,
1402 AR9287_AN_TXPC0_TXPCMODE,
1403 AR9287_AN_TXPC0_TXPCMODE_S,
1404 AR9287_AN_TXPC0_TXPCMODE_TEMPSENSE);
1405 udelay(100);
1406 } else {
1407 for (i = 0; i < AR9280_TX_GAIN_TABLE_SIZE; i++)
1408 ah->originalGain[i] =
1409 MS(REG_READ(ah, AR_PHY_TX_GAIN_TBL1 + i * 4),
1410 AR_PHY_TX_GAIN);
1411 ah->PDADCdelta = 0;
1412 }
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301413}
1414
Bob Copeland3a702e42009-03-30 22:30:29 -04001415static u32 ath9k_regd_get_ctl(struct ath_regulatory *reg,
1416 struct ath9k_channel *chan)
1417{
1418 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
1419
1420 if (IS_CHAN_B(chan))
1421 ctl |= CTL_11B;
1422 else if (IS_CHAN_G(chan))
1423 ctl |= CTL_11G;
1424 else
1425 ctl |= CTL_11A;
1426
1427 return ctl;
1428}
1429
Sujithcbe61d82009-02-09 13:27:12 +05301430static int ath9k_hw_process_ini(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001431 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301432{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001433 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301434 int i, regWrites = 0;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001435 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301436 u32 modesIndex, freqIndex;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001437
Sujithf1dc5602008-10-29 10:16:30 +05301438 switch (chan->chanmode) {
1439 case CHANNEL_A:
1440 case CHANNEL_A_HT20:
1441 modesIndex = 1;
1442 freqIndex = 1;
1443 break;
1444 case CHANNEL_A_HT40PLUS:
1445 case CHANNEL_A_HT40MINUS:
1446 modesIndex = 2;
1447 freqIndex = 1;
1448 break;
1449 case CHANNEL_G:
1450 case CHANNEL_G_HT20:
1451 case CHANNEL_B:
1452 modesIndex = 4;
1453 freqIndex = 2;
1454 break;
1455 case CHANNEL_G_HT40PLUS:
1456 case CHANNEL_G_HT40MINUS:
1457 modesIndex = 3;
1458 freqIndex = 2;
1459 break;
1460
1461 default:
1462 return -EINVAL;
1463 }
1464
1465 REG_WRITE(ah, AR_PHY(0), 0x00000007);
Sujithf1dc5602008-10-29 10:16:30 +05301466 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
Sujithf74df6f2009-02-09 13:27:24 +05301467 ah->eep_ops->set_addac(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301468
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001469 if (AR_SREV_5416_22_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +05301470 REG_WRITE_ARRAY(&ah->iniAddac, 1, regWrites);
Sujithf1dc5602008-10-29 10:16:30 +05301471 } else {
1472 struct ar5416IniArray temp;
1473 u32 addacSize =
Sujith2660b812009-02-09 13:27:26 +05301474 sizeof(u32) * ah->iniAddac.ia_rows *
1475 ah->iniAddac.ia_columns;
Sujithf1dc5602008-10-29 10:16:30 +05301476
Sujith2660b812009-02-09 13:27:26 +05301477 memcpy(ah->addac5416_21,
1478 ah->iniAddac.ia_array, addacSize);
Sujithf1dc5602008-10-29 10:16:30 +05301479
Sujith2660b812009-02-09 13:27:26 +05301480 (ah->addac5416_21)[31 * ah->iniAddac.ia_columns + 1] = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301481
Sujith2660b812009-02-09 13:27:26 +05301482 temp.ia_array = ah->addac5416_21;
1483 temp.ia_columns = ah->iniAddac.ia_columns;
1484 temp.ia_rows = ah->iniAddac.ia_rows;
Sujithf1dc5602008-10-29 10:16:30 +05301485 REG_WRITE_ARRAY(&temp, 1, regWrites);
1486 }
1487
1488 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
1489
Sujith2660b812009-02-09 13:27:26 +05301490 for (i = 0; i < ah->iniModes.ia_rows; i++) {
1491 u32 reg = INI_RA(&ah->iniModes, i, 0);
1492 u32 val = INI_RA(&ah->iniModes, i, modesIndex);
Sujithf1dc5602008-10-29 10:16:30 +05301493
Sujithf1dc5602008-10-29 10:16:30 +05301494 REG_WRITE(ah, reg, val);
1495
1496 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301497 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301498 udelay(100);
1499 }
1500
1501 DO_DELAY(regWrites);
1502 }
1503
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301504 if (AR_SREV_9280(ah) || AR_SREV_9287_10_OR_LATER(ah))
Sujith2660b812009-02-09 13:27:26 +05301505 REG_WRITE_ARRAY(&ah->iniModesRxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301506
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301507 if (AR_SREV_9280(ah) || AR_SREV_9285_12_OR_LATER(ah) ||
1508 AR_SREV_9287_10_OR_LATER(ah))
Sujith2660b812009-02-09 13:27:26 +05301509 REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301510
Sujith2660b812009-02-09 13:27:26 +05301511 for (i = 0; i < ah->iniCommon.ia_rows; i++) {
1512 u32 reg = INI_RA(&ah->iniCommon, i, 0);
1513 u32 val = INI_RA(&ah->iniCommon, i, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301514
1515 REG_WRITE(ah, reg, val);
1516
1517 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301518 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301519 udelay(100);
1520 }
1521
1522 DO_DELAY(regWrites);
1523 }
1524
1525 ath9k_hw_write_regs(ah, modesIndex, freqIndex, regWrites);
1526
Luis R. Rodriguez85643282009-10-19 02:33:33 -04001527 if (AR_SREV_9271_10(ah))
1528 REG_WRITE_ARRAY(&ah->iniModes_9271_1_0_only,
1529 modesIndex, regWrites);
1530
Sujithf1dc5602008-10-29 10:16:30 +05301531 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan)) {
Sujith2660b812009-02-09 13:27:26 +05301532 REG_WRITE_ARRAY(&ah->iniModesAdditional, modesIndex,
Sujithf1dc5602008-10-29 10:16:30 +05301533 regWrites);
1534 }
1535
1536 ath9k_hw_override_ini(ah, chan);
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001537 ath9k_hw_set_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301538 ath9k_hw_init_chain_masks(ah);
1539
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301540 if (OLC_FOR_AR9280_20_LATER)
1541 ath9k_olc_init(ah);
1542
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001543 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001544 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001545 channel->max_antenna_gain * 2,
1546 channel->max_power * 2,
1547 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001548 (u32) regulatory->power_limit));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001549
Sujithf1dc5602008-10-29 10:16:30 +05301550 if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001551 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1552 "ar5416SetRfRegs failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001553 return -EIO;
1554 }
1555
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001556 return 0;
1557}
1558
Sujithf1dc5602008-10-29 10:16:30 +05301559/****************************************/
1560/* Reset and Channel Switching Routines */
1561/****************************************/
1562
Sujithcbe61d82009-02-09 13:27:12 +05301563static void ath9k_hw_set_rfmode(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301564{
1565 u32 rfMode = 0;
1566
1567 if (chan == NULL)
1568 return;
1569
1570 rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
1571 ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
1572
1573 if (!AR_SREV_9280_10_OR_LATER(ah))
1574 rfMode |= (IS_CHAN_5GHZ(chan)) ?
1575 AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ;
1576
1577 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan))
1578 rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
1579
1580 REG_WRITE(ah, AR_PHY_MODE, rfMode);
1581}
1582
Sujithcbe61d82009-02-09 13:27:12 +05301583static void ath9k_hw_mark_phy_inactive(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301584{
1585 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
1586}
1587
Sujithcbe61d82009-02-09 13:27:12 +05301588static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301589{
1590 u32 regval;
1591
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001592 /*
1593 * set AHB_MODE not to do cacheline prefetches
1594 */
Sujithf1dc5602008-10-29 10:16:30 +05301595 regval = REG_READ(ah, AR_AHB_MODE);
1596 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
1597
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001598 /*
1599 * let mac dma reads be in 128 byte chunks
1600 */
Sujithf1dc5602008-10-29 10:16:30 +05301601 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
1602 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
1603
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001604 /*
1605 * Restore TX Trigger Level to its pre-reset value.
1606 * The initial value depends on whether aggregation is enabled, and is
1607 * adjusted whenever underruns are detected.
1608 */
Sujith2660b812009-02-09 13:27:26 +05301609 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +05301610
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001611 /*
1612 * let mac dma writes be in 128 byte chunks
1613 */
Sujithf1dc5602008-10-29 10:16:30 +05301614 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
1615 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
1616
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001617 /*
1618 * Setup receive FIFO threshold to hold off TX activities
1619 */
Sujithf1dc5602008-10-29 10:16:30 +05301620 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1621
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001622 /*
1623 * reduce the number of usable entries in PCU TXBUF to avoid
1624 * wrap around issues.
1625 */
Sujithf1dc5602008-10-29 10:16:30 +05301626 if (AR_SREV_9285(ah)) {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001627 /* For AR9285 the number of Fifos are reduced to half.
1628 * So set the usable tx buf size also to half to
1629 * avoid data/delimiter underruns
1630 */
Sujithf1dc5602008-10-29 10:16:30 +05301631 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1632 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001633 } else if (!AR_SREV_9271(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +05301634 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1635 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1636 }
1637}
1638
Sujithcbe61d82009-02-09 13:27:12 +05301639static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301640{
1641 u32 val;
1642
1643 val = REG_READ(ah, AR_STA_ID1);
1644 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
1645 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001646 case NL80211_IFTYPE_AP:
Sujithf1dc5602008-10-29 10:16:30 +05301647 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
1648 | AR_STA_ID1_KSRCH_MODE);
1649 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1650 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001651 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04001652 case NL80211_IFTYPE_MESH_POINT:
Sujithf1dc5602008-10-29 10:16:30 +05301653 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
1654 | AR_STA_ID1_KSRCH_MODE);
1655 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1656 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001657 case NL80211_IFTYPE_STATION:
1658 case NL80211_IFTYPE_MONITOR:
Sujithf1dc5602008-10-29 10:16:30 +05301659 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
1660 break;
1661 }
1662}
1663
Sujithcbe61d82009-02-09 13:27:12 +05301664static inline void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001665 u32 coef_scaled,
1666 u32 *coef_mantissa,
1667 u32 *coef_exponent)
1668{
1669 u32 coef_exp, coef_man;
1670
1671 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1672 if ((coef_scaled >> coef_exp) & 0x1)
1673 break;
1674
1675 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1676
1677 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1678
1679 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1680 *coef_exponent = coef_exp - 16;
1681}
1682
Sujithcbe61d82009-02-09 13:27:12 +05301683static void ath9k_hw_set_delta_slope(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301684 struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001685{
1686 u32 coef_scaled, ds_coef_exp, ds_coef_man;
1687 u32 clockMhzScaled = 0x64000000;
1688 struct chan_centers centers;
1689
1690 if (IS_CHAN_HALF_RATE(chan))
1691 clockMhzScaled = clockMhzScaled >> 1;
1692 else if (IS_CHAN_QUARTER_RATE(chan))
1693 clockMhzScaled = clockMhzScaled >> 2;
1694
1695 ath9k_hw_get_channel_centers(ah, chan, &centers);
1696 coef_scaled = clockMhzScaled / centers.synth_center;
1697
1698 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1699 &ds_coef_exp);
1700
1701 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1702 AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
1703 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1704 AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
1705
1706 coef_scaled = (9 * coef_scaled) / 10;
1707
1708 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1709 &ds_coef_exp);
1710
1711 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1712 AR_PHY_HALFGI_DSC_MAN, ds_coef_man);
1713 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1714 AR_PHY_HALFGI_DSC_EXP, ds_coef_exp);
1715}
1716
Sujithcbe61d82009-02-09 13:27:12 +05301717static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +05301718{
1719 u32 rst_flags;
1720 u32 tmpReg;
1721
Sujith70768492009-02-16 13:23:12 +05301722 if (AR_SREV_9100(ah)) {
1723 u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK);
1724 val &= ~AR_RTC_DERIVED_CLK_PERIOD;
1725 val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD);
1726 REG_WRITE(ah, AR_RTC_DERIVED_CLK, val);
1727 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1728 }
1729
Sujithf1dc5602008-10-29 10:16:30 +05301730 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1731 AR_RTC_FORCE_WAKE_ON_INT);
1732
1733 if (AR_SREV_9100(ah)) {
1734 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1735 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1736 } else {
1737 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1738 if (tmpReg &
1739 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1740 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
1741 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
1742 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1743 } else {
1744 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1745 }
1746
1747 rst_flags = AR_RTC_RC_MAC_WARM;
1748 if (type == ATH9K_RESET_COLD)
1749 rst_flags |= AR_RTC_RC_MAC_COLD;
1750 }
1751
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001752 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujithf1dc5602008-10-29 10:16:30 +05301753 udelay(50);
1754
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001755 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301756 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001757 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1758 "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301759 return false;
1760 }
1761
1762 if (!AR_SREV_9100(ah))
1763 REG_WRITE(ah, AR_RC, 0);
1764
Sujithf1dc5602008-10-29 10:16:30 +05301765 if (AR_SREV_9100(ah))
1766 udelay(50);
1767
1768 return true;
1769}
1770
Sujithcbe61d82009-02-09 13:27:12 +05301771static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301772{
1773 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1774 AR_RTC_FORCE_WAKE_ON_INT);
1775
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301776 if (!AR_SREV_9100(ah))
1777 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1778
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001779 REG_WRITE(ah, AR_RTC_RESET, 0);
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301780 udelay(2);
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301781
1782 if (!AR_SREV_9100(ah))
1783 REG_WRITE(ah, AR_RC, 0);
1784
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001785 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301786
1787 if (!ath9k_hw_wait(ah,
1788 AR_RTC_STATUS,
1789 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301790 AR_RTC_STATUS_ON,
1791 AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001792 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1793 "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301794 return false;
1795 }
1796
1797 ath9k_hw_read_revisions(ah);
1798
1799 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1800}
1801
Sujithcbe61d82009-02-09 13:27:12 +05301802static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301803{
1804 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1805 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1806
1807 switch (type) {
1808 case ATH9K_RESET_POWER_ON:
1809 return ath9k_hw_set_reset_power_on(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301810 case ATH9K_RESET_WARM:
1811 case ATH9K_RESET_COLD:
1812 return ath9k_hw_set_reset(ah, type);
Sujithf1dc5602008-10-29 10:16:30 +05301813 default:
1814 return false;
1815 }
1816}
1817
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001818static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301819{
1820 u32 phymode;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301821 u32 enableDacFifo = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301822
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301823 if (AR_SREV_9285_10_OR_LATER(ah))
1824 enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) &
1825 AR_PHY_FC_ENABLE_DAC_FIFO);
1826
Sujithf1dc5602008-10-29 10:16:30 +05301827 phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301828 | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo;
Sujithf1dc5602008-10-29 10:16:30 +05301829
1830 if (IS_CHAN_HT40(chan)) {
1831 phymode |= AR_PHY_FC_DYN2040_EN;
1832
1833 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
1834 (chan->chanmode == CHANNEL_G_HT40PLUS))
1835 phymode |= AR_PHY_FC_DYN2040_PRI_CH;
1836
Sujithf1dc5602008-10-29 10:16:30 +05301837 }
1838 REG_WRITE(ah, AR_PHY_TURBO, phymode);
1839
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001840 ath9k_hw_set11nmac2040(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301841
1842 REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
1843 REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
1844}
1845
Sujithcbe61d82009-02-09 13:27:12 +05301846static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301847 struct ath9k_channel *chan)
1848{
Vivek Natarajan42abfbe2009-09-17 09:27:59 +05301849 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) {
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301850 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
1851 return false;
1852 } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
Sujithf1dc5602008-10-29 10:16:30 +05301853 return false;
1854
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001855 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05301856 return false;
1857
Sujith2660b812009-02-09 13:27:26 +05301858 ah->chip_fullsleep = false;
Sujithf1dc5602008-10-29 10:16:30 +05301859 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301860 ath9k_hw_set_rfmode(ah, chan);
1861
1862 return true;
1863}
1864
Sujithcbe61d82009-02-09 13:27:12 +05301865static bool ath9k_hw_channel_change(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001866 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301867{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001868 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001869 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001870 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301871 u32 synthDelay, qnum;
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001872 int r;
Sujithf1dc5602008-10-29 10:16:30 +05301873
1874 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1875 if (ath9k_hw_numtxpending(ah, qnum)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001876 ath_print(common, ATH_DBG_QUEUE,
1877 "Transmit frames pending on "
1878 "queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301879 return false;
1880 }
1881 }
1882
1883 REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
1884 if (!ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
Sujith0caa7b12009-02-16 13:23:20 +05301885 AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001886 ath_print(common, ATH_DBG_FATAL,
1887 "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301888 return false;
1889 }
1890
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001891 ath9k_hw_set_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301892
Luis R. Rodrigueze68a0602009-10-19 02:33:41 -04001893 r = ah->ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001894 if (r) {
1895 ath_print(common, ATH_DBG_FATAL,
1896 "Failed to set channel\n");
1897 return false;
Sujithf1dc5602008-10-29 10:16:30 +05301898 }
1899
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001900 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001901 ath9k_regd_get_ctl(regulatory, chan),
Sujithf74df6f2009-02-09 13:27:24 +05301902 channel->max_antenna_gain * 2,
1903 channel->max_power * 2,
1904 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001905 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05301906
1907 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +05301908 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +05301909 synthDelay = (4 * synthDelay) / 22;
1910 else
1911 synthDelay /= 10;
1912
1913 udelay(synthDelay + BASE_ACTIVATE_DELAY);
1914
1915 REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
1916
1917 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1918 ath9k_hw_set_delta_slope(ah, chan);
1919
1920 if (AR_SREV_9280_10_OR_LATER(ah))
1921 ath9k_hw_9280_spur_mitigate(ah, chan);
1922 else
1923 ath9k_hw_spur_mitigate(ah, chan);
1924
1925 if (!chan->oneTimeCalsDone)
1926 chan->oneTimeCalsDone = true;
1927
1928 return true;
1929}
1930
Johannes Berg3b319aa2009-06-13 14:50:26 +05301931static void ath9k_enable_rfkill(struct ath_hw *ah)
1932{
1933 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
1934 AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
1935
1936 REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2,
1937 AR_GPIO_INPUT_MUX2_RFSILENT);
1938
1939 ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
1940 REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);
1941}
1942
Sujithcbe61d82009-02-09 13:27:12 +05301943int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001944 bool bChannelChange)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001945{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001946 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001947 u32 saveLedState;
Sujith2660b812009-02-09 13:27:26 +05301948 struct ath9k_channel *curchan = ah->curchan;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001949 u32 saveDefAntenna;
1950 u32 macStaId1;
Sujith46fe7822009-09-17 09:25:25 +05301951 u64 tsf = 0;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001952 int i, rx_chainmask, r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001953
Luis R. Rodriguez43c27612009-09-13 21:07:07 -07001954 ah->txchainmask = common->tx_chainmask;
1955 ah->rxchainmask = common->rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001956
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001957 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001958 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001959
Vasanthakumar Thiagarajan9ebef792009-09-17 09:26:44 +05301960 if (curchan && !ah->chip_fullsleep)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001961 ath9k_hw_getnf(ah, curchan);
1962
1963 if (bChannelChange &&
Sujith2660b812009-02-09 13:27:26 +05301964 (ah->chip_fullsleep != true) &&
1965 (ah->curchan != NULL) &&
1966 (chan->channel != ah->curchan->channel) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001967 ((chan->channelFlags & CHANNEL_ALL) ==
Sujith2660b812009-02-09 13:27:26 +05301968 (ah->curchan->channelFlags & CHANNEL_ALL)) &&
Vasanthakumar Thiagarajan0a475cc2009-09-17 09:27:10 +05301969 !(AR_SREV_9280(ah) || IS_CHAN_A_5MHZ_SPACED(chan) ||
1970 IS_CHAN_A_5MHZ_SPACED(ah->curchan))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001971
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001972 if (ath9k_hw_channel_change(ah, chan)) {
Sujith2660b812009-02-09 13:27:26 +05301973 ath9k_hw_loadnf(ah, ah->curchan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001974 ath9k_hw_start_nfcal(ah);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001975 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001976 }
1977 }
1978
1979 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
1980 if (saveDefAntenna == 0)
1981 saveDefAntenna = 1;
1982
1983 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
1984
Sujith46fe7822009-09-17 09:25:25 +05301985 /* For chips on which RTC reset is done, save TSF before it gets cleared */
1986 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1987 tsf = ath9k_hw_gettsf64(ah);
1988
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001989 saveLedState = REG_READ(ah, AR_CFG_LED) &
1990 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
1991 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
1992
1993 ath9k_hw_mark_phy_inactive(ah);
1994
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001995 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1996 REG_WRITE(ah,
1997 AR9271_RESET_POWER_DOWN_CONTROL,
1998 AR9271_RADIO_RF_RST);
1999 udelay(50);
2000 }
2001
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002002 if (!ath9k_hw_chip_reset(ah, chan)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002003 ath_print(common, ATH_DBG_FATAL, "Chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002004 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002005 }
2006
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002007 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
2008 ah->htc_reset_init = false;
2009 REG_WRITE(ah,
2010 AR9271_RESET_POWER_DOWN_CONTROL,
2011 AR9271_GATE_MAC_CTL);
2012 udelay(50);
2013 }
2014
Sujith46fe7822009-09-17 09:25:25 +05302015 /* Restore TSF */
2016 if (tsf && AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
2017 ath9k_hw_settsf64(ah, tsf);
2018
Vasanthakumar Thiagarajan369391d2009-01-21 19:24:13 +05302019 if (AR_SREV_9280_10_OR_LATER(ah))
2020 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002021
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302022 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302023 /* Enable ASYNC FIFO */
2024 REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2025 AR_MAC_PCU_ASYNC_FIFO_REG3_DATAPATH_SEL);
2026 REG_SET_BIT(ah, AR_PHY_MODE, AR_PHY_MODE_ASYNCFIFO);
2027 REG_CLR_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2028 AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
2029 REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2030 AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
2031 }
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002032 r = ath9k_hw_process_ini(ah, chan);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002033 if (r)
2034 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002035
Jouni Malinen0ced0e12009-01-08 13:32:13 +02002036 /* Setup MFP options for CCMP */
2037 if (AR_SREV_9280_20_OR_LATER(ah)) {
2038 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
2039 * frames when constructing CCMP AAD. */
2040 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
2041 0xc7ff);
2042 ah->sw_mgmt_crypto = false;
2043 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
2044 /* Disable hardware crypto for management frames */
2045 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
2046 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
2047 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
2048 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
2049 ah->sw_mgmt_crypto = true;
2050 } else
2051 ah->sw_mgmt_crypto = true;
2052
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002053 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
2054 ath9k_hw_set_delta_slope(ah, chan);
2055
2056 if (AR_SREV_9280_10_OR_LATER(ah))
2057 ath9k_hw_9280_spur_mitigate(ah, chan);
2058 else
2059 ath9k_hw_spur_mitigate(ah, chan);
2060
Sujithd6509152009-03-13 08:56:05 +05302061 ah->eep_ops->set_board_values(ah, chan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002062
2063 ath9k_hw_decrease_chain_power(ah, chan);
2064
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002065 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
2066 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002067 | macStaId1
2068 | AR_STA_ID1_RTS_USE_DEF
Sujith2660b812009-02-09 13:27:26 +05302069 | (ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302070 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Sujith2660b812009-02-09 13:27:26 +05302071 | ah->sta_id1_defaults);
2072 ath9k_hw_set_operating_mode(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002073
Luis R. Rodriguez13b81552009-09-10 17:52:45 -07002074 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002075
2076 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
2077
Luis R. Rodriguez3453ad82009-09-10 08:57:00 -07002078 ath9k_hw_write_associd(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002079
2080 REG_WRITE(ah, AR_ISR, ~0);
2081
2082 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
2083
Luis R. Rodrigueze68a0602009-10-19 02:33:41 -04002084 r = ah->ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04002085 if (r)
2086 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002087
2088 for (i = 0; i < AR_NUM_DCU; i++)
2089 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
2090
Sujith2660b812009-02-09 13:27:26 +05302091 ah->intr_txqs = 0;
2092 for (i = 0; i < ah->caps.total_queues; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002093 ath9k_hw_resettxqueue(ah, i);
2094
Sujith2660b812009-02-09 13:27:26 +05302095 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002096 ath9k_hw_init_qos(ah);
2097
Sujith2660b812009-02-09 13:27:26 +05302098 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05302099 ath9k_enable_rfkill(ah);
Johannes Berg3b319aa2009-06-13 14:50:26 +05302100
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002101 ath9k_hw_init_user_settings(ah);
2102
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302103 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302104 REG_WRITE(ah, AR_D_GBL_IFS_SIFS,
2105 AR_D_GBL_IFS_SIFS_ASYNC_FIFO_DUR);
2106 REG_WRITE(ah, AR_D_GBL_IFS_SLOT,
2107 AR_D_GBL_IFS_SLOT_ASYNC_FIFO_DUR);
2108 REG_WRITE(ah, AR_D_GBL_IFS_EIFS,
2109 AR_D_GBL_IFS_EIFS_ASYNC_FIFO_DUR);
2110
2111 REG_WRITE(ah, AR_TIME_OUT, AR_TIME_OUT_ACK_CTS_ASYNC_FIFO_DUR);
2112 REG_WRITE(ah, AR_USEC, AR_USEC_ASYNC_FIFO_DUR);
2113
2114 REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
2115 AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
2116 REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
2117 AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
2118 }
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302119 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302120 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
2121 AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
2122 }
2123
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002124 REG_WRITE(ah, AR_STA_ID1,
2125 REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
2126
2127 ath9k_hw_set_dma(ah);
2128
2129 REG_WRITE(ah, AR_OBS, 8);
2130
Sujith0ef1f162009-03-30 15:28:35 +05302131 if (ah->config.intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002132 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
2133 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
2134 }
2135
2136 ath9k_hw_init_bb(ah, chan);
2137
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002138 if (!ath9k_hw_init_cal(ah, chan))
Joe Perches6badaaf2009-06-28 09:26:32 -07002139 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002140
Sujith2660b812009-02-09 13:27:26 +05302141 rx_chainmask = ah->rxchainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002142 if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) {
2143 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
2144 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
2145 }
2146
2147 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
2148
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002149 /*
2150 * For big endian systems turn on swapping for descriptors
2151 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002152 if (AR_SREV_9100(ah)) {
2153 u32 mask;
2154 mask = REG_READ(ah, AR_CFG);
2155 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002156 ath_print(common, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05302157 "CFG Byte Swap Set 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002158 } else {
2159 mask =
2160 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
2161 REG_WRITE(ah, AR_CFG, mask);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002162 ath_print(common, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05302163 "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002164 }
2165 } else {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002166 /* Configure AR9271 target WLAN */
2167 if (AR_SREV_9271(ah))
2168 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002169#ifdef __BIG_ENDIAN
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002170 else
2171 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002172#endif
2173 }
2174
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002175 if (ah->btcoex_hw.enabled)
Vasanthakumar Thiagarajan42cc41e2009-08-26 21:08:45 +05302176 ath9k_hw_btcoex_enable(ah);
2177
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002178 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002179}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002180EXPORT_SYMBOL(ath9k_hw_reset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002181
Sujithf1dc5602008-10-29 10:16:30 +05302182/************************/
2183/* Key Cache Management */
2184/************************/
2185
Sujithcbe61d82009-02-09 13:27:12 +05302186bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002187{
Sujithf1dc5602008-10-29 10:16:30 +05302188 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002189
Sujith2660b812009-02-09 13:27:26 +05302190 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002191 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2192 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002193 return false;
2194 }
2195
Sujithf1dc5602008-10-29 10:16:30 +05302196 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002197
Sujithf1dc5602008-10-29 10:16:30 +05302198 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
2199 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
2200 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
2201 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
2202 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
2203 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
2204 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
2205 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
2206
2207 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2208 u16 micentry = entry + 64;
2209
2210 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
2211 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
2212 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
2213 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
2214
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002215 }
2216
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002217 return true;
2218}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002219EXPORT_SYMBOL(ath9k_hw_keyreset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002220
Sujithcbe61d82009-02-09 13:27:12 +05302221bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002222{
Sujithf1dc5602008-10-29 10:16:30 +05302223 u32 macHi, macLo;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002224
Sujith2660b812009-02-09 13:27:26 +05302225 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002226 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2227 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002228 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002229 }
2230
Sujithf1dc5602008-10-29 10:16:30 +05302231 if (mac != NULL) {
2232 macHi = (mac[5] << 8) | mac[4];
2233 macLo = (mac[3] << 24) |
2234 (mac[2] << 16) |
2235 (mac[1] << 8) |
2236 mac[0];
2237 macLo >>= 1;
2238 macLo |= (macHi & 1) << 31;
2239 macHi >>= 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002240 } else {
Sujithf1dc5602008-10-29 10:16:30 +05302241 macLo = macHi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002242 }
Sujithf1dc5602008-10-29 10:16:30 +05302243 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
2244 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002245
2246 return true;
2247}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002248EXPORT_SYMBOL(ath9k_hw_keysetmac);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002249
Sujithcbe61d82009-02-09 13:27:12 +05302250bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
Sujithf1dc5602008-10-29 10:16:30 +05302251 const struct ath9k_keyval *k,
Jouni Malinene0caf9e2009-03-02 18:15:53 +02002252 const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002253{
Sujith2660b812009-02-09 13:27:26 +05302254 const struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002255 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302256 u32 key0, key1, key2, key3, key4;
2257 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002258
Sujithf1dc5602008-10-29 10:16:30 +05302259 if (entry >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002260 ath_print(common, ATH_DBG_FATAL,
2261 "keycache entry %u out of range\n", entry);
Sujithf1dc5602008-10-29 10:16:30 +05302262 return false;
2263 }
2264
2265 switch (k->kv_type) {
2266 case ATH9K_CIPHER_AES_OCB:
2267 keyType = AR_KEYTABLE_TYPE_AES;
2268 break;
2269 case ATH9K_CIPHER_AES_CCM:
2270 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002271 ath_print(common, ATH_DBG_ANY,
2272 "AES-CCM not supported by mac rev 0x%x\n",
2273 ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002274 return false;
2275 }
Sujithf1dc5602008-10-29 10:16:30 +05302276 keyType = AR_KEYTABLE_TYPE_CCM;
2277 break;
2278 case ATH9K_CIPHER_TKIP:
2279 keyType = AR_KEYTABLE_TYPE_TKIP;
2280 if (ATH9K_IS_MIC_ENABLED(ah)
2281 && entry + 64 >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002282 ath_print(common, ATH_DBG_ANY,
2283 "entry %u inappropriate for TKIP\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002284 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002285 }
Sujithf1dc5602008-10-29 10:16:30 +05302286 break;
2287 case ATH9K_CIPHER_WEP:
Zhu Yie31a16d2009-05-21 21:47:03 +08002288 if (k->kv_len < WLAN_KEY_LEN_WEP40) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002289 ath_print(common, ATH_DBG_ANY,
2290 "WEP key length %u too small\n", k->kv_len);
Sujithf1dc5602008-10-29 10:16:30 +05302291 return false;
2292 }
Zhu Yie31a16d2009-05-21 21:47:03 +08002293 if (k->kv_len <= WLAN_KEY_LEN_WEP40)
Sujithf1dc5602008-10-29 10:16:30 +05302294 keyType = AR_KEYTABLE_TYPE_40;
Zhu Yie31a16d2009-05-21 21:47:03 +08002295 else if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05302296 keyType = AR_KEYTABLE_TYPE_104;
2297 else
2298 keyType = AR_KEYTABLE_TYPE_128;
2299 break;
2300 case ATH9K_CIPHER_CLR:
2301 keyType = AR_KEYTABLE_TYPE_CLR;
2302 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002303 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002304 ath_print(common, ATH_DBG_FATAL,
2305 "cipher %u not supported\n", k->kv_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002306 return false;
2307 }
Sujithf1dc5602008-10-29 10:16:30 +05302308
Jouni Malinene0caf9e2009-03-02 18:15:53 +02002309 key0 = get_unaligned_le32(k->kv_val + 0);
2310 key1 = get_unaligned_le16(k->kv_val + 4);
2311 key2 = get_unaligned_le32(k->kv_val + 6);
2312 key3 = get_unaligned_le16(k->kv_val + 10);
2313 key4 = get_unaligned_le32(k->kv_val + 12);
Zhu Yie31a16d2009-05-21 21:47:03 +08002314 if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05302315 key4 &= 0xff;
2316
Jouni Malinen672903b2009-03-02 15:06:31 +02002317 /*
2318 * Note: Key cache registers access special memory area that requires
2319 * two 32-bit writes to actually update the values in the internal
2320 * memory. Consequently, the exact order and pairs used here must be
2321 * maintained.
2322 */
2323
Sujithf1dc5602008-10-29 10:16:30 +05302324 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2325 u16 micentry = entry + 64;
2326
Jouni Malinen672903b2009-03-02 15:06:31 +02002327 /*
2328 * Write inverted key[47:0] first to avoid Michael MIC errors
2329 * on frames that could be sent or received at the same time.
2330 * The correct key will be written in the end once everything
2331 * else is ready.
2332 */
Sujithf1dc5602008-10-29 10:16:30 +05302333 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
2334 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002335
2336 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302337 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2338 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002339
2340 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302341 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2342 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
Jouni Malinen672903b2009-03-02 15:06:31 +02002343
2344 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302345 (void) ath9k_hw_keysetmac(ah, entry, mac);
2346
Sujith2660b812009-02-09 13:27:26 +05302347 if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) {
Jouni Malinen672903b2009-03-02 15:06:31 +02002348 /*
2349 * TKIP uses two key cache entries:
2350 * Michael MIC TX/RX keys in the same key cache entry
2351 * (idx = main index + 64):
2352 * key0 [31:0] = RX key [31:0]
2353 * key1 [15:0] = TX key [31:16]
2354 * key1 [31:16] = reserved
2355 * key2 [31:0] = RX key [63:32]
2356 * key3 [15:0] = TX key [15:0]
2357 * key3 [31:16] = reserved
2358 * key4 [31:0] = TX key [63:32]
2359 */
Sujithf1dc5602008-10-29 10:16:30 +05302360 u32 mic0, mic1, mic2, mic3, mic4;
2361
2362 mic0 = get_unaligned_le32(k->kv_mic + 0);
2363 mic2 = get_unaligned_le32(k->kv_mic + 4);
2364 mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
2365 mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
2366 mic4 = get_unaligned_le32(k->kv_txmic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02002367
2368 /* Write RX[31:0] and TX[31:16] */
Sujithf1dc5602008-10-29 10:16:30 +05302369 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2370 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002371
2372 /* Write RX[63:32] and TX[15:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302373 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2374 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002375
2376 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302377 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
2378 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2379 AR_KEYTABLE_TYPE_CLR);
2380
2381 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002382 /*
2383 * TKIP uses four key cache entries (two for group
2384 * keys):
2385 * Michael MIC TX/RX keys are in different key cache
2386 * entries (idx = main index + 64 for TX and
2387 * main index + 32 + 96 for RX):
2388 * key0 [31:0] = TX/RX MIC key [31:0]
2389 * key1 [31:0] = reserved
2390 * key2 [31:0] = TX/RX MIC key [63:32]
2391 * key3 [31:0] = reserved
2392 * key4 [31:0] = reserved
2393 *
2394 * Upper layer code will call this function separately
2395 * for TX and RX keys when these registers offsets are
2396 * used.
2397 */
Sujithf1dc5602008-10-29 10:16:30 +05302398 u32 mic0, mic2;
2399
2400 mic0 = get_unaligned_le32(k->kv_mic + 0);
2401 mic2 = get_unaligned_le32(k->kv_mic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02002402
2403 /* Write MIC key[31:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302404 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2405 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002406
2407 /* Write MIC key[63:32] */
Sujithf1dc5602008-10-29 10:16:30 +05302408 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2409 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002410
2411 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302412 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
2413 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2414 AR_KEYTABLE_TYPE_CLR);
2415 }
Jouni Malinen672903b2009-03-02 15:06:31 +02002416
2417 /* MAC address registers are reserved for the MIC entry */
Sujithf1dc5602008-10-29 10:16:30 +05302418 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
2419 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002420
2421 /*
2422 * Write the correct (un-inverted) key[47:0] last to enable
2423 * TKIP now that all other registers are set with correct
2424 * values.
2425 */
Sujithf1dc5602008-10-29 10:16:30 +05302426 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2427 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
2428 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002429 /* Write key[47:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302430 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2431 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002432
2433 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302434 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2435 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002436
2437 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302438 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2439 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
2440
Jouni Malinen672903b2009-03-02 15:06:31 +02002441 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302442 (void) ath9k_hw_keysetmac(ah, entry, mac);
2443 }
2444
Sujithf1dc5602008-10-29 10:16:30 +05302445 return true;
2446}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002447EXPORT_SYMBOL(ath9k_hw_set_keycache_entry);
Sujithf1dc5602008-10-29 10:16:30 +05302448
Sujithcbe61d82009-02-09 13:27:12 +05302449bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry)
Sujithf1dc5602008-10-29 10:16:30 +05302450{
Sujith2660b812009-02-09 13:27:26 +05302451 if (entry < ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05302452 u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
2453 if (val & AR_KEYTABLE_VALID)
2454 return true;
2455 }
2456 return false;
2457}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002458EXPORT_SYMBOL(ath9k_hw_keyisvalid);
Sujithf1dc5602008-10-29 10:16:30 +05302459
2460/******************************/
2461/* Power Management (Chipset) */
2462/******************************/
2463
Sujithcbe61d82009-02-09 13:27:12 +05302464static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302465{
2466 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2467 if (setChip) {
2468 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2469 AR_RTC_FORCE_WAKE_EN);
2470 if (!AR_SREV_9100(ah))
2471 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
2472
Sujith4921be82009-09-18 15:04:27 +05302473 if(!AR_SREV_5416(ah))
2474 REG_CLR_BIT(ah, (AR_RTC_RESET),
2475 AR_RTC_RESET_EN);
Sujithf1dc5602008-10-29 10:16:30 +05302476 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002477}
2478
Sujithcbe61d82009-02-09 13:27:12 +05302479static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002480{
Sujithf1dc5602008-10-29 10:16:30 +05302481 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2482 if (setChip) {
Sujith2660b812009-02-09 13:27:26 +05302483 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002484
Sujithf1dc5602008-10-29 10:16:30 +05302485 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
2486 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2487 AR_RTC_FORCE_WAKE_ON_INT);
2488 } else {
2489 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2490 AR_RTC_FORCE_WAKE_EN);
2491 }
2492 }
2493}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002494
Sujithcbe61d82009-02-09 13:27:12 +05302495static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302496{
2497 u32 val;
2498 int i;
2499
2500 if (setChip) {
2501 if ((REG_READ(ah, AR_RTC_STATUS) &
2502 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2503 if (ath9k_hw_set_reset_reg(ah,
2504 ATH9K_RESET_POWER_ON) != true) {
2505 return false;
2506 }
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05302507 ath9k_hw_init_pll(ah, NULL);
Sujithf1dc5602008-10-29 10:16:30 +05302508 }
2509 if (AR_SREV_9100(ah))
2510 REG_SET_BIT(ah, AR_RTC_RESET,
2511 AR_RTC_RESET_EN);
2512
2513 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2514 AR_RTC_FORCE_WAKE_EN);
2515 udelay(50);
2516
2517 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2518 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2519 if (val == AR_RTC_STATUS_ON)
2520 break;
2521 udelay(50);
2522 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2523 AR_RTC_FORCE_WAKE_EN);
2524 }
2525 if (i == 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002526 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2527 "Failed to wakeup in %uus\n",
2528 POWER_UP_TIME / 20);
Sujithf1dc5602008-10-29 10:16:30 +05302529 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002530 }
2531 }
2532
Sujithf1dc5602008-10-29 10:16:30 +05302533 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2534
2535 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002536}
2537
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002538bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05302539{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002540 struct ath_common *common = ath9k_hw_common(ah);
Sujithcbe61d82009-02-09 13:27:12 +05302541 int status = true, setChip = true;
Sujithf1dc5602008-10-29 10:16:30 +05302542 static const char *modes[] = {
2543 "AWAKE",
2544 "FULL-SLEEP",
2545 "NETWORK SLEEP",
2546 "UNDEFINED"
2547 };
Sujithf1dc5602008-10-29 10:16:30 +05302548
Gabor Juhoscbdec972009-07-24 17:27:22 +02002549 if (ah->power_mode == mode)
2550 return status;
2551
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002552 ath_print(common, ATH_DBG_RESET, "%s -> %s\n",
2553 modes[ah->power_mode], modes[mode]);
Sujithf1dc5602008-10-29 10:16:30 +05302554
2555 switch (mode) {
2556 case ATH9K_PM_AWAKE:
2557 status = ath9k_hw_set_power_awake(ah, setChip);
2558 break;
2559 case ATH9K_PM_FULL_SLEEP:
2560 ath9k_set_power_sleep(ah, setChip);
Sujith2660b812009-02-09 13:27:26 +05302561 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05302562 break;
2563 case ATH9K_PM_NETWORK_SLEEP:
2564 ath9k_set_power_network_sleep(ah, setChip);
2565 break;
2566 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002567 ath_print(common, ATH_DBG_FATAL,
2568 "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05302569 return false;
2570 }
Sujith2660b812009-02-09 13:27:26 +05302571 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05302572
2573 return status;
2574}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002575EXPORT_SYMBOL(ath9k_hw_setpower);
Sujithf1dc5602008-10-29 10:16:30 +05302576
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002577/*
2578 * Helper for ASPM support.
2579 *
2580 * Disable PLL when in L0s as well as receiver clock when in L1.
2581 * This power saving option must be enabled through the SerDes.
2582 *
2583 * Programming the SerDes must go through the same 288 bit serial shift
2584 * register as the other analog registers. Hence the 9 writes.
2585 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302586void ath9k_hw_configpcipowersave(struct ath_hw *ah, int restore, int power_off)
Sujithf1dc5602008-10-29 10:16:30 +05302587{
Sujithf1dc5602008-10-29 10:16:30 +05302588 u8 i;
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302589 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05302590
Sujith2660b812009-02-09 13:27:26 +05302591 if (ah->is_pciexpress != true)
Sujithf1dc5602008-10-29 10:16:30 +05302592 return;
2593
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002594 /* Do not touch SerDes registers */
Sujith2660b812009-02-09 13:27:26 +05302595 if (ah->config.pcie_powersave_enable == 2)
Sujithf1dc5602008-10-29 10:16:30 +05302596 return;
2597
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002598 /* Nothing to do on restore for 11N */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302599 if (!restore) {
2600 if (AR_SREV_9280_20_OR_LATER(ah)) {
2601 /*
2602 * AR9280 2.0 or later chips use SerDes values from the
2603 * initvals.h initialized depending on chipset during
2604 * ath9k_hw_init()
2605 */
2606 for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
2607 REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
2608 INI_RA(&ah->iniPcieSerdes, i, 1));
2609 }
2610 } else if (AR_SREV_9280(ah) &&
2611 (ah->hw_version.macRev == AR_SREV_REVISION_9280_10)) {
2612 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
2613 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
Sujithf1dc5602008-10-29 10:16:30 +05302614
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302615 /* RX shut off when elecidle is asserted */
2616 REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
2617 REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
2618 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
2619
2620 /* Shut off CLKREQ active in L1 */
2621 if (ah->config.pcie_clock_req)
2622 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
2623 else
2624 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
2625
2626 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2627 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2628 REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
2629
2630 /* Load the new settings */
2631 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
2632
2633 } else {
2634 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
2635 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
2636
2637 /* RX shut off when elecidle is asserted */
2638 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
2639 REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
2640 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
2641
2642 /*
2643 * Ignore ah->ah_config.pcie_clock_req setting for
2644 * pre-AR9280 11n
2645 */
2646 REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
2647
2648 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2649 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2650 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
2651
2652 /* Load the new settings */
2653 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
Sujithf1dc5602008-10-29 10:16:30 +05302654 }
Sujithf1dc5602008-10-29 10:16:30 +05302655
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302656 udelay(1000);
Sujithf1dc5602008-10-29 10:16:30 +05302657
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302658 /* set bit 19 to allow forcing of pcie core into L1 state */
2659 REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
Sujithf1dc5602008-10-29 10:16:30 +05302660
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302661 /* Several PCIe massages to ensure proper behaviour */
2662 if (ah->config.pcie_waen) {
2663 val = ah->config.pcie_waen;
2664 if (!power_off)
2665 val &= (~AR_WA_D3_L1_DISABLE);
2666 } else {
2667 if (AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
2668 AR_SREV_9287(ah)) {
2669 val = AR9285_WA_DEFAULT;
2670 if (!power_off)
2671 val &= (~AR_WA_D3_L1_DISABLE);
2672 } else if (AR_SREV_9280(ah)) {
2673 /*
2674 * On AR9280 chips bit 22 of 0x4004 needs to be
2675 * set otherwise card may disappear.
2676 */
2677 val = AR9280_WA_DEFAULT;
2678 if (!power_off)
2679 val &= (~AR_WA_D3_L1_DISABLE);
2680 } else
2681 val = AR_WA_DEFAULT;
2682 }
Sujithf1dc5602008-10-29 10:16:30 +05302683
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302684 REG_WRITE(ah, AR_WA, val);
Sujithf1dc5602008-10-29 10:16:30 +05302685 }
2686
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302687 if (power_off) {
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002688 /*
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302689 * Set PCIe workaround bits
2690 * bit 14 in WA register (disable L1) should only
2691 * be set when device enters D3 and be cleared
2692 * when device comes back to D0.
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002693 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302694 if (ah->config.pcie_waen) {
2695 if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE)
2696 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
2697 } else {
2698 if (((AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
2699 AR_SREV_9287(ah)) &&
2700 (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)) ||
2701 (AR_SREV_9280(ah) &&
2702 (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE))) {
2703 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
2704 }
2705 }
Sujithf1dc5602008-10-29 10:16:30 +05302706 }
2707}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002708EXPORT_SYMBOL(ath9k_hw_configpcipowersave);
Sujithf1dc5602008-10-29 10:16:30 +05302709
2710/**********************/
2711/* Interrupt Handling */
2712/**********************/
2713
Sujithcbe61d82009-02-09 13:27:12 +05302714bool ath9k_hw_intrpend(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002715{
2716 u32 host_isr;
2717
2718 if (AR_SREV_9100(ah))
2719 return true;
2720
2721 host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
2722 if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
2723 return true;
2724
2725 host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
2726 if ((host_isr & AR_INTR_SYNC_DEFAULT)
2727 && (host_isr != AR_INTR_SPURIOUS))
2728 return true;
2729
2730 return false;
2731}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002732EXPORT_SYMBOL(ath9k_hw_intrpend);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002733
Sujithcbe61d82009-02-09 13:27:12 +05302734bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002735{
2736 u32 isr = 0;
2737 u32 mask2 = 0;
Sujith2660b812009-02-09 13:27:26 +05302738 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002739 u32 sync_cause = 0;
2740 bool fatal_int = false;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002741 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002742
2743 if (!AR_SREV_9100(ah)) {
2744 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
2745 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
2746 == AR_RTC_STATUS_ON) {
2747 isr = REG_READ(ah, AR_ISR);
2748 }
2749 }
2750
Sujithf1dc5602008-10-29 10:16:30 +05302751 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
2752 AR_INTR_SYNC_DEFAULT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002753
2754 *masked = 0;
2755
2756 if (!isr && !sync_cause)
2757 return false;
2758 } else {
2759 *masked = 0;
2760 isr = REG_READ(ah, AR_ISR);
2761 }
2762
2763 if (isr) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002764 if (isr & AR_ISR_BCNMISC) {
2765 u32 isr2;
2766 isr2 = REG_READ(ah, AR_ISR_S2);
2767 if (isr2 & AR_ISR_S2_TIM)
2768 mask2 |= ATH9K_INT_TIM;
2769 if (isr2 & AR_ISR_S2_DTIM)
2770 mask2 |= ATH9K_INT_DTIM;
2771 if (isr2 & AR_ISR_S2_DTIMSYNC)
2772 mask2 |= ATH9K_INT_DTIMSYNC;
2773 if (isr2 & (AR_ISR_S2_CABEND))
2774 mask2 |= ATH9K_INT_CABEND;
2775 if (isr2 & AR_ISR_S2_GTT)
2776 mask2 |= ATH9K_INT_GTT;
2777 if (isr2 & AR_ISR_S2_CST)
2778 mask2 |= ATH9K_INT_CST;
Sujith4af9cf42009-02-12 10:06:47 +05302779 if (isr2 & AR_ISR_S2_TSFOOR)
2780 mask2 |= ATH9K_INT_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002781 }
2782
2783 isr = REG_READ(ah, AR_ISR_RAC);
2784 if (isr == 0xffffffff) {
2785 *masked = 0;
2786 return false;
2787 }
2788
2789 *masked = isr & ATH9K_INT_COMMON;
2790
Sujith0ef1f162009-03-30 15:28:35 +05302791 if (ah->config.intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002792 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
2793 *masked |= ATH9K_INT_RX;
2794 }
2795
2796 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
2797 *masked |= ATH9K_INT_RX;
2798 if (isr &
2799 (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
2800 AR_ISR_TXEOL)) {
2801 u32 s0_s, s1_s;
2802
2803 *masked |= ATH9K_INT_TX;
2804
2805 s0_s = REG_READ(ah, AR_ISR_S0_S);
Sujith2660b812009-02-09 13:27:26 +05302806 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
2807 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002808
2809 s1_s = REG_READ(ah, AR_ISR_S1_S);
Sujith2660b812009-02-09 13:27:26 +05302810 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
2811 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002812 }
2813
2814 if (isr & AR_ISR_RXORN) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002815 ath_print(common, ATH_DBG_INTERRUPT,
2816 "receive FIFO overrun interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002817 }
2818
2819 if (!AR_SREV_9100(ah)) {
Sujith60b67f52008-08-07 10:52:38 +05302820 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002821 u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
2822 if (isr5 & AR_ISR_S5_TIM_TIMER)
2823 *masked |= ATH9K_INT_TIM_TIMER;
2824 }
2825 }
2826
2827 *masked |= mask2;
2828 }
Sujithf1dc5602008-10-29 10:16:30 +05302829
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002830 if (AR_SREV_9100(ah))
2831 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302832
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302833 if (isr & AR_ISR_GENTMR) {
2834 u32 s5_s;
2835
2836 s5_s = REG_READ(ah, AR_ISR_S5_S);
2837 if (isr & AR_ISR_GENTMR) {
2838 ah->intr_gen_timer_trigger =
2839 MS(s5_s, AR_ISR_S5_GENTIMER_TRIG);
2840
2841 ah->intr_gen_timer_thresh =
2842 MS(s5_s, AR_ISR_S5_GENTIMER_THRESH);
2843
2844 if (ah->intr_gen_timer_trigger)
2845 *masked |= ATH9K_INT_GENTIMER;
2846
2847 }
2848 }
2849
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002850 if (sync_cause) {
2851 fatal_int =
2852 (sync_cause &
2853 (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
2854 ? true : false;
2855
2856 if (fatal_int) {
2857 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002858 ath_print(common, ATH_DBG_ANY,
2859 "received PCI FATAL interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002860 }
2861 if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002862 ath_print(common, ATH_DBG_ANY,
2863 "received PCI PERR interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002864 }
Steven Luoa89bff92009-04-12 02:57:54 -07002865 *masked |= ATH9K_INT_FATAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002866 }
2867 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002868 ath_print(common, ATH_DBG_INTERRUPT,
2869 "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002870 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
2871 REG_WRITE(ah, AR_RC, 0);
2872 *masked |= ATH9K_INT_FATAL;
2873 }
2874 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002875 ath_print(common, ATH_DBG_INTERRUPT,
2876 "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002877 }
2878
2879 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
2880 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
2881 }
Sujithf1dc5602008-10-29 10:16:30 +05302882
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002883 return true;
2884}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002885EXPORT_SYMBOL(ath9k_hw_getisr);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002886
Sujithcbe61d82009-02-09 13:27:12 +05302887enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002888{
Sujith2660b812009-02-09 13:27:26 +05302889 u32 omask = ah->mask_reg;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002890 u32 mask, mask2;
Sujith2660b812009-02-09 13:27:26 +05302891 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002892 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002893
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002894 ath_print(common, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002895
2896 if (omask & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002897 ath_print(common, ATH_DBG_INTERRUPT, "disable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002898 REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
2899 (void) REG_READ(ah, AR_IER);
2900 if (!AR_SREV_9100(ah)) {
2901 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
2902 (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
2903
2904 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
2905 (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
2906 }
2907 }
2908
2909 mask = ints & ATH9K_INT_COMMON;
2910 mask2 = 0;
2911
2912 if (ints & ATH9K_INT_TX) {
Sujith2660b812009-02-09 13:27:26 +05302913 if (ah->txok_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002914 mask |= AR_IMR_TXOK;
Sujith2660b812009-02-09 13:27:26 +05302915 if (ah->txdesc_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002916 mask |= AR_IMR_TXDESC;
Sujith2660b812009-02-09 13:27:26 +05302917 if (ah->txerr_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002918 mask |= AR_IMR_TXERR;
Sujith2660b812009-02-09 13:27:26 +05302919 if (ah->txeol_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002920 mask |= AR_IMR_TXEOL;
2921 }
2922 if (ints & ATH9K_INT_RX) {
2923 mask |= AR_IMR_RXERR;
Sujith0ef1f162009-03-30 15:28:35 +05302924 if (ah->config.intr_mitigation)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002925 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
2926 else
2927 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
Sujith60b67f52008-08-07 10:52:38 +05302928 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002929 mask |= AR_IMR_GENTMR;
2930 }
2931
2932 if (ints & (ATH9K_INT_BMISC)) {
2933 mask |= AR_IMR_BCNMISC;
2934 if (ints & ATH9K_INT_TIM)
2935 mask2 |= AR_IMR_S2_TIM;
2936 if (ints & ATH9K_INT_DTIM)
2937 mask2 |= AR_IMR_S2_DTIM;
2938 if (ints & ATH9K_INT_DTIMSYNC)
2939 mask2 |= AR_IMR_S2_DTIMSYNC;
2940 if (ints & ATH9K_INT_CABEND)
Sujith4af9cf42009-02-12 10:06:47 +05302941 mask2 |= AR_IMR_S2_CABEND;
2942 if (ints & ATH9K_INT_TSFOOR)
2943 mask2 |= AR_IMR_S2_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002944 }
2945
2946 if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
2947 mask |= AR_IMR_BCNMISC;
2948 if (ints & ATH9K_INT_GTT)
2949 mask2 |= AR_IMR_S2_GTT;
2950 if (ints & ATH9K_INT_CST)
2951 mask2 |= AR_IMR_S2_CST;
2952 }
2953
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002954 ath_print(common, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002955 REG_WRITE(ah, AR_IMR, mask);
2956 mask = REG_READ(ah, AR_IMR_S2) & ~(AR_IMR_S2_TIM |
2957 AR_IMR_S2_DTIM |
2958 AR_IMR_S2_DTIMSYNC |
2959 AR_IMR_S2_CABEND |
2960 AR_IMR_S2_CABTO |
2961 AR_IMR_S2_TSFOOR |
2962 AR_IMR_S2_GTT | AR_IMR_S2_CST);
2963 REG_WRITE(ah, AR_IMR_S2, mask | mask2);
Sujith2660b812009-02-09 13:27:26 +05302964 ah->mask_reg = ints;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002965
Sujith60b67f52008-08-07 10:52:38 +05302966 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002967 if (ints & ATH9K_INT_TIM_TIMER)
2968 REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
2969 else
2970 REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
2971 }
2972
2973 if (ints & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002974 ath_print(common, ATH_DBG_INTERRUPT, "enable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002975 REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
2976 if (!AR_SREV_9100(ah)) {
2977 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
2978 AR_INTR_MAC_IRQ);
2979 REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
2980
2981
2982 REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
2983 AR_INTR_SYNC_DEFAULT);
2984 REG_WRITE(ah, AR_INTR_SYNC_MASK,
2985 AR_INTR_SYNC_DEFAULT);
2986 }
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002987 ath_print(common, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
2988 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002989 }
2990
2991 return omask;
2992}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002993EXPORT_SYMBOL(ath9k_hw_set_interrupts);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002994
Sujithf1dc5602008-10-29 10:16:30 +05302995/*******************/
2996/* Beacon Handling */
2997/*******************/
2998
Sujithcbe61d82009-02-09 13:27:12 +05302999void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003000{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003001 int flags = 0;
3002
Sujith2660b812009-02-09 13:27:26 +05303003 ah->beacon_interval = beacon_period;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003004
Sujith2660b812009-02-09 13:27:26 +05303005 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08003006 case NL80211_IFTYPE_STATION:
3007 case NL80211_IFTYPE_MONITOR:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003008 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3009 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
3010 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
3011 flags |= AR_TBTT_TIMER_EN;
3012 break;
Colin McCabed97809d2008-12-01 13:38:55 -08003013 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04003014 case NL80211_IFTYPE_MESH_POINT:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003015 REG_SET_BIT(ah, AR_TXCFG,
3016 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
3017 REG_WRITE(ah, AR_NEXT_NDP_TIMER,
3018 TU_TO_USEC(next_beacon +
Sujith2660b812009-02-09 13:27:26 +05303019 (ah->atim_window ? ah->
3020 atim_window : 1)));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003021 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08003022 case NL80211_IFTYPE_AP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003023 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3024 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
3025 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05303026 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05303027 dma_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003028 REG_WRITE(ah, AR_NEXT_SWBA,
3029 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05303030 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05303031 sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003032 flags |=
3033 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
3034 break;
Colin McCabed97809d2008-12-01 13:38:55 -08003035 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003036 ath_print(ath9k_hw_common(ah), ATH_DBG_BEACON,
3037 "%s: unsupported opmode: %d\n",
3038 __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08003039 return;
3040 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003041 }
3042
3043 REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3044 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3045 REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
3046 REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
3047
3048 beacon_period &= ~ATH9K_BEACON_ENA;
3049 if (beacon_period & ATH9K_BEACON_RESET_TSF) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003050 ath9k_hw_reset_tsf(ah);
3051 }
3052
3053 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
3054}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003055EXPORT_SYMBOL(ath9k_hw_beaconinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003056
Sujithcbe61d82009-02-09 13:27:12 +05303057void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303058 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003059{
3060 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05303061 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003062 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003063
3064 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
3065
3066 REG_WRITE(ah, AR_BEACON_PERIOD,
3067 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3068 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
3069 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3070
3071 REG_RMW_FIELD(ah, AR_RSSI_THR,
3072 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
3073
3074 beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
3075
3076 if (bs->bs_sleepduration > beaconintval)
3077 beaconintval = bs->bs_sleepduration;
3078
3079 dtimperiod = bs->bs_dtimperiod;
3080 if (bs->bs_sleepduration > dtimperiod)
3081 dtimperiod = bs->bs_sleepduration;
3082
3083 if (beaconintval == dtimperiod)
3084 nextTbtt = bs->bs_nextdtim;
3085 else
3086 nextTbtt = bs->bs_nexttbtt;
3087
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003088 ath_print(common, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
3089 ath_print(common, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
3090 ath_print(common, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
3091 ath_print(common, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003092
3093 REG_WRITE(ah, AR_NEXT_DTIM,
3094 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
3095 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
3096
3097 REG_WRITE(ah, AR_SLEEP1,
3098 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
3099 | AR_SLEEP1_ASSUME_DTIM);
3100
Sujith60b67f52008-08-07 10:52:38 +05303101 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003102 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
3103 else
3104 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
3105
3106 REG_WRITE(ah, AR_SLEEP2,
3107 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
3108
3109 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
3110 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
3111
3112 REG_SET_BIT(ah, AR_TIMER_MODE,
3113 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
3114 AR_DTIM_TIMER_EN);
3115
Sujith4af9cf42009-02-12 10:06:47 +05303116 /* TSF Out of Range Threshold */
3117 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003118}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003119EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003120
Sujithf1dc5602008-10-29 10:16:30 +05303121/*******************/
3122/* HW Capabilities */
3123/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003124
Sujitheef7a572009-03-30 15:28:28 +05303125void ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003126{
Sujith2660b812009-02-09 13:27:26 +05303127 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003128 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003129 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003130 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003131
Sujithf1dc5602008-10-29 10:16:30 +05303132 u16 capField = 0, eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003133
Sujithf74df6f2009-02-09 13:27:24 +05303134 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003135 regulatory->current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303136
Sujithf74df6f2009-02-09 13:27:24 +05303137 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
Sujithfec0de12009-02-12 10:06:43 +05303138 if (AR_SREV_9285_10_OR_LATER(ah))
3139 eeval |= AR9285_RDEXT_DEFAULT;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003140 regulatory->current_rd_ext = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303141
Sujithf74df6f2009-02-09 13:27:24 +05303142 capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
Sujithf1dc5602008-10-29 10:16:30 +05303143
Sujith2660b812009-02-09 13:27:26 +05303144 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05303145 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003146 if (regulatory->current_rd == 0x64 ||
3147 regulatory->current_rd == 0x65)
3148 regulatory->current_rd += 5;
3149 else if (regulatory->current_rd == 0x41)
3150 regulatory->current_rd = 0x43;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003151 ath_print(common, ATH_DBG_REGULATORY,
3152 "regdomain mapped to 0x%x\n", regulatory->current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003153 }
Sujithdc2222a2008-08-14 13:26:55 +05303154
Sujithf74df6f2009-02-09 13:27:24 +05303155 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Sujithf1dc5602008-10-29 10:16:30 +05303156 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003157
Sujithf1dc5602008-10-29 10:16:30 +05303158 if (eeval & AR5416_OPFLAGS_11A) {
3159 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303160 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303161 if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
3162 set_bit(ATH9K_MODE_11NA_HT20,
3163 pCap->wireless_modes);
3164 if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
3165 set_bit(ATH9K_MODE_11NA_HT40PLUS,
3166 pCap->wireless_modes);
3167 set_bit(ATH9K_MODE_11NA_HT40MINUS,
3168 pCap->wireless_modes);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003169 }
3170 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003171 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003172
Sujithf1dc5602008-10-29 10:16:30 +05303173 if (eeval & AR5416_OPFLAGS_11G) {
Sujithf1dc5602008-10-29 10:16:30 +05303174 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303175 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303176 if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
3177 set_bit(ATH9K_MODE_11NG_HT20,
3178 pCap->wireless_modes);
3179 if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
3180 set_bit(ATH9K_MODE_11NG_HT40PLUS,
3181 pCap->wireless_modes);
3182 set_bit(ATH9K_MODE_11NG_HT40MINUS,
3183 pCap->wireless_modes);
3184 }
3185 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003186 }
Sujithf1dc5602008-10-29 10:16:30 +05303187
Sujithf74df6f2009-02-09 13:27:24 +05303188 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003189 /*
3190 * For AR9271 we will temporarilly uses the rx chainmax as read from
3191 * the EEPROM.
3192 */
Sujith8147f5d2009-02-20 15:13:23 +05303193 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003194 !(eeval & AR5416_OPFLAGS_11A) &&
3195 !(AR_SREV_9271(ah)))
3196 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
Sujith8147f5d2009-02-20 15:13:23 +05303197 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
3198 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003199 /* Use rx_chainmask from EEPROM. */
Sujith8147f5d2009-02-20 15:13:23 +05303200 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05303201
Sujithd535a422009-02-09 13:27:06 +05303202 if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0)))
Sujith2660b812009-02-09 13:27:26 +05303203 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05303204
3205 pCap->low_2ghz_chan = 2312;
3206 pCap->high_2ghz_chan = 2732;
3207
3208 pCap->low_5ghz_chan = 4920;
3209 pCap->high_5ghz_chan = 6100;
3210
3211 pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
3212 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
3213 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
3214
3215 pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
3216 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
3217 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
3218
Sujith2660b812009-02-09 13:27:26 +05303219 if (ah->config.ht_enable)
Sujithf1dc5602008-10-29 10:16:30 +05303220 pCap->hw_caps |= ATH9K_HW_CAP_HT;
3221 else
3222 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
3223
3224 pCap->hw_caps |= ATH9K_HW_CAP_GTT;
3225 pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
3226 pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
3227 pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
3228
3229 if (capField & AR_EEPROM_EEPCAP_MAXQCU)
3230 pCap->total_queues =
3231 MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
3232 else
3233 pCap->total_queues = ATH9K_NUM_TX_QUEUES;
3234
3235 if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
3236 pCap->keycache_size =
3237 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
3238 else
3239 pCap->keycache_size = AR_KEYTABLE_SIZE;
3240
3241 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
Sujithf1dc5602008-10-29 10:16:30 +05303242 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
3243
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303244 if (AR_SREV_9285_10_OR_LATER(ah))
3245 pCap->num_gpio_pins = AR9285_NUM_GPIO;
3246 else if (AR_SREV_9280_10_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303247 pCap->num_gpio_pins = AR928X_NUM_GPIO;
3248 else
3249 pCap->num_gpio_pins = AR_NUM_GPIO;
3250
Sujithf1dc5602008-10-29 10:16:30 +05303251 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
3252 pCap->hw_caps |= ATH9K_HW_CAP_CST;
3253 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
3254 } else {
3255 pCap->rts_aggr_limit = (8 * 1024);
3256 }
3257
3258 pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
3259
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05303260#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05303261 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
3262 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
3263 ah->rfkill_gpio =
3264 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
3265 ah->rfkill_polarity =
3266 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05303267
3268 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
3269 }
3270#endif
3271
Vivek Natarajana3ca95fb2009-09-17 09:29:07 +05303272 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
Sujithf1dc5602008-10-29 10:16:30 +05303273
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05303274 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303275 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
3276 else
3277 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
3278
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003279 if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) {
Sujithf1dc5602008-10-29 10:16:30 +05303280 pCap->reg_cap =
3281 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3282 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
3283 AR_EEPROM_EEREGCAP_EN_KK_U2 |
3284 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
3285 } else {
3286 pCap->reg_cap =
3287 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3288 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
3289 }
3290
Senthil Balasubramanianebb90cf2009-09-18 15:07:33 +05303291 /* Advertise midband for AR5416 with FCC midband set in eeprom */
3292 if (regulatory->current_rd_ext & (1 << REG_EXT_FCC_MIDBAND) &&
3293 AR_SREV_5416(ah))
3294 pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
Sujithf1dc5602008-10-29 10:16:30 +05303295
3296 pCap->num_antcfg_5ghz =
Sujithf74df6f2009-02-09 13:27:24 +05303297 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303298 pCap->num_antcfg_2ghz =
Sujithf74df6f2009-02-09 13:27:24 +05303299 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303300
Vasanthakumar Thiagarajanfe129462009-09-09 15:25:50 +05303301 if (AR_SREV_9280_10_OR_LATER(ah) &&
Luis R. Rodrigueza36cfbc2009-09-09 16:05:32 -07003302 ath9k_hw_btcoex_supported(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003303 btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO;
3304 btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO;
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05303305
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303306 if (AR_SREV_9285(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003307 btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
3308 btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303309 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003310 btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303311 }
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05303312 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003313 btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE;
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303314 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003315}
3316
Sujithcbe61d82009-02-09 13:27:12 +05303317bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303318 u32 capability, u32 *result)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003319{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003320 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05303321 switch (type) {
3322 case ATH9K_CAP_CIPHER:
3323 switch (capability) {
3324 case ATH9K_CIPHER_AES_CCM:
3325 case ATH9K_CIPHER_AES_OCB:
3326 case ATH9K_CIPHER_TKIP:
3327 case ATH9K_CIPHER_WEP:
3328 case ATH9K_CIPHER_MIC:
3329 case ATH9K_CIPHER_CLR:
3330 return true;
3331 default:
3332 return false;
3333 }
3334 case ATH9K_CAP_TKIP_MIC:
3335 switch (capability) {
3336 case 0:
3337 return true;
3338 case 1:
Sujith2660b812009-02-09 13:27:26 +05303339 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303340 AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
3341 false;
3342 }
3343 case ATH9K_CAP_TKIP_SPLIT:
Sujith2660b812009-02-09 13:27:26 +05303344 return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ?
Sujithf1dc5602008-10-29 10:16:30 +05303345 false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303346 case ATH9K_CAP_DIVERSITY:
3347 return (REG_READ(ah, AR_PHY_CCK_DETECT) &
3348 AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV) ?
3349 true : false;
Sujithf1dc5602008-10-29 10:16:30 +05303350 case ATH9K_CAP_MCAST_KEYSRCH:
3351 switch (capability) {
3352 case 0:
3353 return true;
3354 case 1:
3355 if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
3356 return false;
3357 } else {
Sujith2660b812009-02-09 13:27:26 +05303358 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303359 AR_STA_ID1_MCAST_KSRCH) ? true :
3360 false;
3361 }
3362 }
3363 return false;
Sujithf1dc5602008-10-29 10:16:30 +05303364 case ATH9K_CAP_TXPOW:
3365 switch (capability) {
3366 case 0:
3367 return 0;
3368 case 1:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003369 *result = regulatory->power_limit;
Sujithf1dc5602008-10-29 10:16:30 +05303370 return 0;
3371 case 2:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003372 *result = regulatory->max_power_level;
Sujithf1dc5602008-10-29 10:16:30 +05303373 return 0;
3374 case 3:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003375 *result = regulatory->tp_scale;
Sujithf1dc5602008-10-29 10:16:30 +05303376 return 0;
3377 }
3378 return false;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05303379 case ATH9K_CAP_DS:
3380 return (AR_SREV_9280_20_OR_LATER(ah) &&
3381 (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1))
3382 ? false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303383 default:
3384 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003385 }
Sujithf1dc5602008-10-29 10:16:30 +05303386}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003387EXPORT_SYMBOL(ath9k_hw_getcapability);
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003388
Sujithcbe61d82009-02-09 13:27:12 +05303389bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303390 u32 capability, u32 setting, int *status)
3391{
Sujithf1dc5602008-10-29 10:16:30 +05303392 u32 v;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003393
Sujithf1dc5602008-10-29 10:16:30 +05303394 switch (type) {
3395 case ATH9K_CAP_TKIP_MIC:
3396 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303397 ah->sta_id1_defaults |=
Sujithf1dc5602008-10-29 10:16:30 +05303398 AR_STA_ID1_CRPT_MIC_ENABLE;
3399 else
Sujith2660b812009-02-09 13:27:26 +05303400 ah->sta_id1_defaults &=
Sujithf1dc5602008-10-29 10:16:30 +05303401 ~AR_STA_ID1_CRPT_MIC_ENABLE;
3402 return true;
3403 case ATH9K_CAP_DIVERSITY:
3404 v = REG_READ(ah, AR_PHY_CCK_DETECT);
3405 if (setting)
3406 v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3407 else
3408 v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3409 REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
3410 return true;
3411 case ATH9K_CAP_MCAST_KEYSRCH:
3412 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303413 ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303414 else
Sujith2660b812009-02-09 13:27:26 +05303415 ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303416 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303417 default:
3418 return false;
3419 }
3420}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003421EXPORT_SYMBOL(ath9k_hw_setcapability);
Sujithf1dc5602008-10-29 10:16:30 +05303422
3423/****************************/
3424/* GPIO / RFKILL / Antennae */
3425/****************************/
3426
Sujithcbe61d82009-02-09 13:27:12 +05303427static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303428 u32 gpio, u32 type)
3429{
3430 int addr;
3431 u32 gpio_shift, tmp;
3432
3433 if (gpio > 11)
3434 addr = AR_GPIO_OUTPUT_MUX3;
3435 else if (gpio > 5)
3436 addr = AR_GPIO_OUTPUT_MUX2;
3437 else
3438 addr = AR_GPIO_OUTPUT_MUX1;
3439
3440 gpio_shift = (gpio % 6) * 5;
3441
3442 if (AR_SREV_9280_20_OR_LATER(ah)
3443 || (addr != AR_GPIO_OUTPUT_MUX1)) {
3444 REG_RMW(ah, addr, (type << gpio_shift),
3445 (0x1f << gpio_shift));
3446 } else {
3447 tmp = REG_READ(ah, addr);
3448 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
3449 tmp &= ~(0x1f << gpio_shift);
3450 tmp |= (type << gpio_shift);
3451 REG_WRITE(ah, addr, tmp);
3452 }
3453}
3454
Sujithcbe61d82009-02-09 13:27:12 +05303455void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303456{
3457 u32 gpio_shift;
3458
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07003459 BUG_ON(gpio >= ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05303460
3461 gpio_shift = gpio << 1;
3462
3463 REG_RMW(ah,
3464 AR_GPIO_OE_OUT,
3465 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
3466 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3467}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003468EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
Sujithf1dc5602008-10-29 10:16:30 +05303469
Sujithcbe61d82009-02-09 13:27:12 +05303470u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303471{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303472#define MS_REG_READ(x, y) \
3473 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
3474
Sujith2660b812009-02-09 13:27:26 +05303475 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05303476 return 0xffffffff;
3477
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05303478 if (AR_SREV_9287_10_OR_LATER(ah))
3479 return MS_REG_READ(AR9287, gpio) != 0;
3480 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303481 return MS_REG_READ(AR9285, gpio) != 0;
3482 else if (AR_SREV_9280_10_OR_LATER(ah))
3483 return MS_REG_READ(AR928X, gpio) != 0;
3484 else
3485 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05303486}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003487EXPORT_SYMBOL(ath9k_hw_gpio_get);
Sujithf1dc5602008-10-29 10:16:30 +05303488
Sujithcbe61d82009-02-09 13:27:12 +05303489void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05303490 u32 ah_signal_type)
3491{
3492 u32 gpio_shift;
3493
3494 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
3495
3496 gpio_shift = 2 * gpio;
3497
3498 REG_RMW(ah,
3499 AR_GPIO_OE_OUT,
3500 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
3501 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3502}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003503EXPORT_SYMBOL(ath9k_hw_cfg_output);
Sujithf1dc5602008-10-29 10:16:30 +05303504
Sujithcbe61d82009-02-09 13:27:12 +05303505void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05303506{
3507 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
3508 AR_GPIO_BIT(gpio));
3509}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003510EXPORT_SYMBOL(ath9k_hw_set_gpio);
Sujithf1dc5602008-10-29 10:16:30 +05303511
Sujithcbe61d82009-02-09 13:27:12 +05303512u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303513{
3514 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
3515}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003516EXPORT_SYMBOL(ath9k_hw_getdefantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303517
Sujithcbe61d82009-02-09 13:27:12 +05303518void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05303519{
3520 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
3521}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003522EXPORT_SYMBOL(ath9k_hw_setantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303523
Sujithcbe61d82009-02-09 13:27:12 +05303524bool ath9k_hw_setantennaswitch(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303525 enum ath9k_ant_setting settings,
3526 struct ath9k_channel *chan,
3527 u8 *tx_chainmask,
3528 u8 *rx_chainmask,
3529 u8 *antenna_cfgd)
3530{
Sujithf1dc5602008-10-29 10:16:30 +05303531 static u8 tx_chainmask_cfg, rx_chainmask_cfg;
3532
3533 if (AR_SREV_9280(ah)) {
3534 if (!tx_chainmask_cfg) {
3535
3536 tx_chainmask_cfg = *tx_chainmask;
3537 rx_chainmask_cfg = *rx_chainmask;
3538 }
3539
3540 switch (settings) {
3541 case ATH9K_ANT_FIXED_A:
3542 *tx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3543 *rx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3544 *antenna_cfgd = true;
3545 break;
3546 case ATH9K_ANT_FIXED_B:
Sujith2660b812009-02-09 13:27:26 +05303547 if (ah->caps.tx_chainmask >
Sujithf1dc5602008-10-29 10:16:30 +05303548 ATH9K_ANTENNA1_CHAINMASK) {
3549 *tx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3550 }
3551 *rx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3552 *antenna_cfgd = true;
3553 break;
3554 case ATH9K_ANT_VARIABLE:
3555 *tx_chainmask = tx_chainmask_cfg;
3556 *rx_chainmask = rx_chainmask_cfg;
3557 *antenna_cfgd = true;
3558 break;
3559 default:
3560 break;
3561 }
3562 } else {
Sujith1cf68732009-08-13 09:34:32 +05303563 ah->config.diversity_control = settings;
Sujithf1dc5602008-10-29 10:16:30 +05303564 }
3565
3566 return true;
3567}
3568
3569/*********************/
3570/* General Operation */
3571/*********************/
3572
Sujithcbe61d82009-02-09 13:27:12 +05303573u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303574{
3575 u32 bits = REG_READ(ah, AR_RX_FILTER);
3576 u32 phybits = REG_READ(ah, AR_PHY_ERR);
3577
3578 if (phybits & AR_PHY_ERR_RADAR)
3579 bits |= ATH9K_RX_FILTER_PHYRADAR;
3580 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
3581 bits |= ATH9K_RX_FILTER_PHYERR;
3582
3583 return bits;
3584}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003585EXPORT_SYMBOL(ath9k_hw_getrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303586
Sujithcbe61d82009-02-09 13:27:12 +05303587void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05303588{
3589 u32 phybits;
3590
Sujith7ea310b2009-09-03 12:08:43 +05303591 REG_WRITE(ah, AR_RX_FILTER, bits);
3592
Sujithf1dc5602008-10-29 10:16:30 +05303593 phybits = 0;
3594 if (bits & ATH9K_RX_FILTER_PHYRADAR)
3595 phybits |= AR_PHY_ERR_RADAR;
3596 if (bits & ATH9K_RX_FILTER_PHYERR)
3597 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
3598 REG_WRITE(ah, AR_PHY_ERR, phybits);
3599
3600 if (phybits)
3601 REG_WRITE(ah, AR_RXCFG,
3602 REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
3603 else
3604 REG_WRITE(ah, AR_RXCFG,
3605 REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
3606}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003607EXPORT_SYMBOL(ath9k_hw_setrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303608
Sujithcbe61d82009-02-09 13:27:12 +05303609bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303610{
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05303611 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
3612 return false;
3613
3614 ath9k_hw_init_pll(ah, NULL);
3615 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303616}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003617EXPORT_SYMBOL(ath9k_hw_phy_disable);
Sujithf1dc5602008-10-29 10:16:30 +05303618
Sujithcbe61d82009-02-09 13:27:12 +05303619bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303620{
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07003621 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05303622 return false;
3623
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05303624 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
3625 return false;
3626
3627 ath9k_hw_init_pll(ah, NULL);
3628 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303629}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003630EXPORT_SYMBOL(ath9k_hw_disable);
Sujithf1dc5602008-10-29 10:16:30 +05303631
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003632void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
Sujithf1dc5602008-10-29 10:16:30 +05303633{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003634 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujith2660b812009-02-09 13:27:26 +05303635 struct ath9k_channel *chan = ah->curchan;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08003636 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05303637
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003638 regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER);
Sujithf1dc5602008-10-29 10:16:30 +05303639
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003640 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003641 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003642 channel->max_antenna_gain * 2,
3643 channel->max_power * 2,
3644 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003645 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05303646}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003647EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
Sujithf1dc5602008-10-29 10:16:30 +05303648
Sujithcbe61d82009-02-09 13:27:12 +05303649void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac)
Sujithf1dc5602008-10-29 10:16:30 +05303650{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07003651 memcpy(ath9k_hw_common(ah)->macaddr, mac, ETH_ALEN);
Sujithf1dc5602008-10-29 10:16:30 +05303652}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003653EXPORT_SYMBOL(ath9k_hw_setmac);
Sujithf1dc5602008-10-29 10:16:30 +05303654
Sujithcbe61d82009-02-09 13:27:12 +05303655void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303656{
Sujith2660b812009-02-09 13:27:26 +05303657 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05303658}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003659EXPORT_SYMBOL(ath9k_hw_setopmode);
Sujithf1dc5602008-10-29 10:16:30 +05303660
Sujithcbe61d82009-02-09 13:27:12 +05303661void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05303662{
3663 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
3664 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
3665}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003666EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303667
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07003668void ath9k_hw_write_associd(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303669{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07003670 struct ath_common *common = ath9k_hw_common(ah);
3671
3672 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
3673 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
3674 ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05303675}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003676EXPORT_SYMBOL(ath9k_hw_write_associd);
Sujithf1dc5602008-10-29 10:16:30 +05303677
Sujithcbe61d82009-02-09 13:27:12 +05303678u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303679{
3680 u64 tsf;
3681
3682 tsf = REG_READ(ah, AR_TSF_U32);
3683 tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
3684
3685 return tsf;
3686}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003687EXPORT_SYMBOL(ath9k_hw_gettsf64);
Sujithf1dc5602008-10-29 10:16:30 +05303688
Sujithcbe61d82009-02-09 13:27:12 +05303689void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003690{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003691 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01003692 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003693}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003694EXPORT_SYMBOL(ath9k_hw_settsf64);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003695
Sujithcbe61d82009-02-09 13:27:12 +05303696void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303697{
Gabor Juhosf9b604f2009-06-21 00:02:15 +02003698 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
3699 AH_TSF_WRITE_TIMEOUT))
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003700 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
3701 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
Gabor Juhosf9b604f2009-06-21 00:02:15 +02003702
Sujithf1dc5602008-10-29 10:16:30 +05303703 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003704}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003705EXPORT_SYMBOL(ath9k_hw_reset_tsf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003706
Sujith54e4cec2009-08-07 09:45:09 +05303707void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003708{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003709 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303710 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003711 else
Sujith2660b812009-02-09 13:27:26 +05303712 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003713}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003714EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003715
Sujithcbe61d82009-02-09 13:27:12 +05303716bool ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003717{
Sujithf1dc5602008-10-29 10:16:30 +05303718 if (us < ATH9K_SLOT_TIME_9 || us > ath9k_hw_mac_to_usec(ah, 0xffff)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003719 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
3720 "bad slot time %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05303721 ah->slottime = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05303722 return false;
3723 } else {
3724 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05303725 ah->slottime = us;
Sujithf1dc5602008-10-29 10:16:30 +05303726 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003727 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003728}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003729EXPORT_SYMBOL(ath9k_hw_setslottime);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003730
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003731void ath9k_hw_set11nmac2040(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003732{
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003733 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithf1dc5602008-10-29 10:16:30 +05303734 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003735
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003736 if (conf_is_ht40(conf) && !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05303737 macmode = AR_2040_JOINED_RX_CLEAR;
3738 else
3739 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003740
Sujithf1dc5602008-10-29 10:16:30 +05303741 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003742}
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303743
3744/* HW Generic timers configuration */
3745
3746static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
3747{
3748 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3749 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3750 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3751 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3752 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3753 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3754 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3755 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3756 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
3757 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
3758 AR_NDP2_TIMER_MODE, 0x0002},
3759 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
3760 AR_NDP2_TIMER_MODE, 0x0004},
3761 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
3762 AR_NDP2_TIMER_MODE, 0x0008},
3763 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
3764 AR_NDP2_TIMER_MODE, 0x0010},
3765 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
3766 AR_NDP2_TIMER_MODE, 0x0020},
3767 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
3768 AR_NDP2_TIMER_MODE, 0x0040},
3769 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
3770 AR_NDP2_TIMER_MODE, 0x0080}
3771};
3772
3773/* HW generic timer primitives */
3774
3775/* compute and clear index of rightmost 1 */
3776static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
3777{
3778 u32 b;
3779
3780 b = *mask;
3781 b &= (0-b);
3782 *mask &= ~b;
3783 b *= debruijn32;
3784 b >>= 27;
3785
3786 return timer_table->gen_timer_index[b];
3787}
3788
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05303789u32 ath9k_hw_gettsf32(struct ath_hw *ah)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303790{
3791 return REG_READ(ah, AR_TSF_L32);
3792}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003793EXPORT_SYMBOL(ath9k_hw_gettsf32);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303794
3795struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
3796 void (*trigger)(void *),
3797 void (*overflow)(void *),
3798 void *arg,
3799 u8 timer_index)
3800{
3801 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3802 struct ath_gen_timer *timer;
3803
3804 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
3805
3806 if (timer == NULL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003807 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
3808 "Failed to allocate memory"
3809 "for hw timer[%d]\n", timer_index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303810 return NULL;
3811 }
3812
3813 /* allocate a hardware generic timer slot */
3814 timer_table->timers[timer_index] = timer;
3815 timer->index = timer_index;
3816 timer->trigger = trigger;
3817 timer->overflow = overflow;
3818 timer->arg = arg;
3819
3820 return timer;
3821}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003822EXPORT_SYMBOL(ath_gen_timer_alloc);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303823
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07003824void ath9k_hw_gen_timer_start(struct ath_hw *ah,
3825 struct ath_gen_timer *timer,
3826 u32 timer_next,
3827 u32 timer_period)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303828{
3829 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3830 u32 tsf;
3831
3832 BUG_ON(!timer_period);
3833
3834 set_bit(timer->index, &timer_table->timer_mask.timer_bits);
3835
3836 tsf = ath9k_hw_gettsf32(ah);
3837
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003838 ath_print(ath9k_hw_common(ah), ATH_DBG_HWTIMER,
3839 "curent tsf %x period %x"
3840 "timer_next %x\n", tsf, timer_period, timer_next);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303841
3842 /*
3843 * Pull timer_next forward if the current TSF already passed it
3844 * because of software latency
3845 */
3846 if (timer_next < tsf)
3847 timer_next = tsf + timer_period;
3848
3849 /*
3850 * Program generic timer registers
3851 */
3852 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
3853 timer_next);
3854 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
3855 timer_period);
3856 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
3857 gen_tmr_configuration[timer->index].mode_mask);
3858
3859 /* Enable both trigger and thresh interrupt masks */
3860 REG_SET_BIT(ah, AR_IMR_S5,
3861 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
3862 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303863}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003864EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303865
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07003866void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303867{
3868 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3869
3870 if ((timer->index < AR_FIRST_NDP_TIMER) ||
3871 (timer->index >= ATH_MAX_GEN_TIMER)) {
3872 return;
3873 }
3874
3875 /* Clear generic timer enable bits. */
3876 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
3877 gen_tmr_configuration[timer->index].mode_mask);
3878
3879 /* Disable both trigger and thresh interrupt masks */
3880 REG_CLR_BIT(ah, AR_IMR_S5,
3881 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
3882 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
3883
3884 clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303885}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003886EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303887
3888void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
3889{
3890 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3891
3892 /* free the hardware generic timer slot */
3893 timer_table->timers[timer->index] = NULL;
3894 kfree(timer);
3895}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003896EXPORT_SYMBOL(ath_gen_timer_free);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303897
3898/*
3899 * Generic Timer Interrupts handling
3900 */
3901void ath_gen_timer_isr(struct ath_hw *ah)
3902{
3903 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3904 struct ath_gen_timer *timer;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003905 struct ath_common *common = ath9k_hw_common(ah);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303906 u32 trigger_mask, thresh_mask, index;
3907
3908 /* get hardware generic timer interrupt status */
3909 trigger_mask = ah->intr_gen_timer_trigger;
3910 thresh_mask = ah->intr_gen_timer_thresh;
3911 trigger_mask &= timer_table->timer_mask.val;
3912 thresh_mask &= timer_table->timer_mask.val;
3913
3914 trigger_mask &= ~thresh_mask;
3915
3916 while (thresh_mask) {
3917 index = rightmost_index(timer_table, &thresh_mask);
3918 timer = timer_table->timers[index];
3919 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003920 ath_print(common, ATH_DBG_HWTIMER,
3921 "TSF overflow for Gen timer %d\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303922 timer->overflow(timer->arg);
3923 }
3924
3925 while (trigger_mask) {
3926 index = rightmost_index(timer_table, &trigger_mask);
3927 timer = timer_table->timers[index];
3928 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003929 ath_print(common, ATH_DBG_HWTIMER,
3930 "Gen timer[%d] trigger\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303931 timer->trigger(timer->arg);
3932 }
3933}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003934EXPORT_SYMBOL(ath_gen_timer_isr);
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003935
3936static struct {
3937 u32 version;
3938 const char * name;
3939} ath_mac_bb_names[] = {
3940 /* Devices with external radios */
3941 { AR_SREV_VERSION_5416_PCI, "5416" },
3942 { AR_SREV_VERSION_5416_PCIE, "5418" },
3943 { AR_SREV_VERSION_9100, "9100" },
3944 { AR_SREV_VERSION_9160, "9160" },
3945 /* Single-chip solutions */
3946 { AR_SREV_VERSION_9280, "9280" },
3947 { AR_SREV_VERSION_9285, "9285" },
Luis R. Rodriguez11158472009-10-27 12:59:35 -04003948 { AR_SREV_VERSION_9287, "9287" },
3949 { AR_SREV_VERSION_9271, "9271" },
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003950};
3951
3952/* For devices with external radios */
3953static struct {
3954 u16 version;
3955 const char * name;
3956} ath_rf_names[] = {
3957 { 0, "5133" },
3958 { AR_RAD5133_SREV_MAJOR, "5133" },
3959 { AR_RAD5122_SREV_MAJOR, "5122" },
3960 { AR_RAD2133_SREV_MAJOR, "2133" },
3961 { AR_RAD2122_SREV_MAJOR, "2122" }
3962};
3963
3964/*
3965 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
3966 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003967static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003968{
3969 int i;
3970
3971 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
3972 if (ath_mac_bb_names[i].version == mac_bb_version) {
3973 return ath_mac_bb_names[i].name;
3974 }
3975 }
3976
3977 return "????";
3978}
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003979
3980/*
3981 * Return the RF name. "????" is returned if the RF is unknown.
3982 * Used for devices with external radios.
3983 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003984static const char *ath9k_hw_rf_name(u16 rf_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003985{
3986 int i;
3987
3988 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
3989 if (ath_rf_names[i].version == rf_version) {
3990 return ath_rf_names[i].name;
3991 }
3992 }
3993
3994 return "????";
3995}
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003996
3997void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
3998{
3999 int used;
4000
4001 /* chipsets >= AR9280 are single-chip */
4002 if (AR_SREV_9280_10_OR_LATER(ah)) {
4003 used = snprintf(hw_name, len,
4004 "Atheros AR%s Rev:%x",
4005 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
4006 ah->hw_version.macRev);
4007 }
4008 else {
4009 used = snprintf(hw_name, len,
4010 "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
4011 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
4012 ah->hw_version.macRev,
4013 ath9k_hw_rf_name((ah->hw_version.analog5GhzRev &
4014 AR_RADIO_SREV_MAJOR)),
4015 ah->hw_version.phyRev);
4016 }
4017
4018 hw_name[used] = '\0';
4019}
4020EXPORT_SYMBOL(ath9k_hw_name);