blob: 4dddffd7c4038ebd87617ede8c68277bd44ef4eb [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
Sujith Manoharan5b681382011-05-17 13:36:18 +05302 * Copyright (c) 2008-2011 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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090018#include <linux/slab.h>
Paul Gortmaker9d9779e2011-07-03 15:21:01 -040019#include <linux/module.h>
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070020#include <asm/unaligned.h>
21
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -070022#include "hw.h"
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -040023#include "hw-ops.h"
Luis R. Rodriguezcfe8cba2009-09-13 23:39:31 -070024#include "rc.h"
Luis R. Rodriguezb622a722010-04-15 17:39:28 -040025#include "ar9003_mac.h"
Sujith Manoharanf4701b52012-02-22 12:41:18 +053026#include "ar9003_mci.h"
Ben Greear462e58f2012-04-12 10:04:00 -070027#include "debug.h"
28#include "ath9k.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070029
Sujithcbe61d82009-02-09 13:27:12 +053030static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070031
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040032MODULE_AUTHOR("Atheros Communications");
33MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
34MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
35MODULE_LICENSE("Dual BSD/GPL");
36
37static int __init ath9k_init(void)
38{
39 return 0;
40}
41module_init(ath9k_init);
42
43static void __exit ath9k_exit(void)
44{
45 return;
46}
47module_exit(ath9k_exit);
48
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -040049/* Private hardware callbacks */
50
51static void ath9k_hw_init_cal_settings(struct ath_hw *ah)
52{
53 ath9k_hw_private_ops(ah)->init_cal_settings(ah);
54}
55
56static void ath9k_hw_init_mode_regs(struct ath_hw *ah)
57{
58 ath9k_hw_private_ops(ah)->init_mode_regs(ah);
59}
60
Luis R. Rodriguez64773962010-04-15 17:38:17 -040061static u32 ath9k_hw_compute_pll_control(struct ath_hw *ah,
62 struct ath9k_channel *chan)
63{
64 return ath9k_hw_private_ops(ah)->compute_pll_control(ah, chan);
65}
66
Luis R. Rodriguez991312d2010-04-15 17:39:05 -040067static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
68{
69 if (!ath9k_hw_private_ops(ah)->init_mode_gain_regs)
70 return;
71
72 ath9k_hw_private_ops(ah)->init_mode_gain_regs(ah);
73}
74
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -040075static void ath9k_hw_ani_cache_ini_regs(struct ath_hw *ah)
76{
77 /* You will not have this callback if using the old ANI */
78 if (!ath9k_hw_private_ops(ah)->ani_cache_ini_regs)
79 return;
80
81 ath9k_hw_private_ops(ah)->ani_cache_ini_regs(ah);
82}
83
Sujithf1dc5602008-10-29 10:16:30 +053084/********************/
85/* Helper Functions */
86/********************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070087
Ben Greear462e58f2012-04-12 10:04:00 -070088#ifdef CONFIG_ATH9K_DEBUGFS
89
90void ath9k_debug_sync_cause(struct ath_common *common, u32 sync_cause)
91{
92 struct ath_softc *sc = common->priv;
93 if (sync_cause)
94 sc->debug.stats.istats.sync_cause_all++;
95 if (sync_cause & AR_INTR_SYNC_RTC_IRQ)
96 sc->debug.stats.istats.sync_rtc_irq++;
97 if (sync_cause & AR_INTR_SYNC_MAC_IRQ)
98 sc->debug.stats.istats.sync_mac_irq++;
99 if (sync_cause & AR_INTR_SYNC_EEPROM_ILLEGAL_ACCESS)
100 sc->debug.stats.istats.eeprom_illegal_access++;
101 if (sync_cause & AR_INTR_SYNC_APB_TIMEOUT)
102 sc->debug.stats.istats.apb_timeout++;
103 if (sync_cause & AR_INTR_SYNC_PCI_MODE_CONFLICT)
104 sc->debug.stats.istats.pci_mode_conflict++;
105 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL)
106 sc->debug.stats.istats.host1_fatal++;
107 if (sync_cause & AR_INTR_SYNC_HOST1_PERR)
108 sc->debug.stats.istats.host1_perr++;
109 if (sync_cause & AR_INTR_SYNC_TRCV_FIFO_PERR)
110 sc->debug.stats.istats.trcv_fifo_perr++;
111 if (sync_cause & AR_INTR_SYNC_RADM_CPL_EP)
112 sc->debug.stats.istats.radm_cpl_ep++;
113 if (sync_cause & AR_INTR_SYNC_RADM_CPL_DLLP_ABORT)
114 sc->debug.stats.istats.radm_cpl_dllp_abort++;
115 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TLP_ABORT)
116 sc->debug.stats.istats.radm_cpl_tlp_abort++;
117 if (sync_cause & AR_INTR_SYNC_RADM_CPL_ECRC_ERR)
118 sc->debug.stats.istats.radm_cpl_ecrc_err++;
119 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT)
120 sc->debug.stats.istats.radm_cpl_timeout++;
121 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT)
122 sc->debug.stats.istats.local_timeout++;
123 if (sync_cause & AR_INTR_SYNC_PM_ACCESS)
124 sc->debug.stats.istats.pm_access++;
125 if (sync_cause & AR_INTR_SYNC_MAC_AWAKE)
126 sc->debug.stats.istats.mac_awake++;
127 if (sync_cause & AR_INTR_SYNC_MAC_ASLEEP)
128 sc->debug.stats.istats.mac_asleep++;
129 if (sync_cause & AR_INTR_SYNC_MAC_SLEEP_ACCESS)
130 sc->debug.stats.istats.mac_sleep_access++;
131}
132#endif
133
134
Felix Fietkaudfdac8a2010-10-08 22:13:51 +0200135static void ath9k_hw_set_clockrate(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530136{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -0700137 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Felix Fietkaudfdac8a2010-10-08 22:13:51 +0200138 struct ath_common *common = ath9k_hw_common(ah);
139 unsigned int clockrate;
Sujithcbe61d82009-02-09 13:27:12 +0530140
Felix Fietkau087b6ff2011-07-09 11:12:49 +0700141 /* AR9287 v1.3+ uses async FIFO and runs the MAC at 117 MHz */
142 if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah))
143 clockrate = 117;
144 else if (!ah->curchan) /* should really check for CCK instead */
Felix Fietkaudfdac8a2010-10-08 22:13:51 +0200145 clockrate = ATH9K_CLOCK_RATE_CCK;
146 else if (conf->channel->band == IEEE80211_BAND_2GHZ)
147 clockrate = ATH9K_CLOCK_RATE_2GHZ_OFDM;
148 else if (ah->caps.hw_caps & ATH9K_HW_CAP_FASTCLOCK)
149 clockrate = ATH9K_CLOCK_FAST_RATE_5GHZ_OFDM;
Vasanthakumar Thiagarajane5553722010-04-26 15:04:33 -0400150 else
Felix Fietkaudfdac8a2010-10-08 22:13:51 +0200151 clockrate = ATH9K_CLOCK_RATE_5GHZ_OFDM;
152
153 if (conf_is_ht40(conf))
154 clockrate *= 2;
155
Felix Fietkau906c7202011-07-09 11:12:48 +0700156 if (ah->curchan) {
157 if (IS_CHAN_HALF_RATE(ah->curchan))
158 clockrate /= 2;
159 if (IS_CHAN_QUARTER_RATE(ah->curchan))
160 clockrate /= 4;
161 }
162
Felix Fietkaudfdac8a2010-10-08 22:13:51 +0200163 common->clockrate = clockrate;
Sujithf1dc5602008-10-29 10:16:30 +0530164}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700165
Sujithcbe61d82009-02-09 13:27:12 +0530166static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +0530167{
Felix Fietkaudfdac8a2010-10-08 22:13:51 +0200168 struct ath_common *common = ath9k_hw_common(ah);
Sujithcbe61d82009-02-09 13:27:12 +0530169
Felix Fietkaudfdac8a2010-10-08 22:13:51 +0200170 return usecs * common->clockrate;
Sujithf1dc5602008-10-29 10:16:30 +0530171}
172
Sujith0caa7b12009-02-16 13:23:20 +0530173bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700174{
175 int i;
176
Sujith0caa7b12009-02-16 13:23:20 +0530177 BUG_ON(timeout < AH_TIME_QUANTUM);
178
179 for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700180 if ((REG_READ(ah, reg) & mask) == val)
181 return true;
182
183 udelay(AH_TIME_QUANTUM);
184 }
Sujith04bd46382008-11-28 22:18:05 +0530185
Joe Perchesd2182b62011-12-15 14:55:53 -0800186 ath_dbg(ath9k_hw_common(ah), ANY,
Joe Perches226afe62010-12-02 19:12:37 -0800187 "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
188 timeout, reg, REG_READ(ah, reg), mask, val);
Sujithf1dc5602008-10-29 10:16:30 +0530189
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700190 return false;
191}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400192EXPORT_SYMBOL(ath9k_hw_wait);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700193
Felix Fietkaua9b6b252011-03-23 20:57:27 +0100194void ath9k_hw_write_array(struct ath_hw *ah, struct ar5416IniArray *array,
195 int column, unsigned int *writecnt)
196{
197 int r;
198
199 ENABLE_REGWRITE_BUFFER(ah);
200 for (r = 0; r < array->ia_rows; r++) {
201 REG_WRITE(ah, INI_RA(array, r, 0),
202 INI_RA(array, r, column));
203 DO_DELAY(*writecnt);
204 }
205 REGWRITE_BUFFER_FLUSH(ah);
206}
207
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700208u32 ath9k_hw_reverse_bits(u32 val, u32 n)
209{
210 u32 retval;
211 int i;
212
213 for (i = 0, retval = 0; i < n; i++) {
214 retval = (retval << 1) | (val & 1);
215 val >>= 1;
216 }
217 return retval;
218}
219
Sujithcbe61d82009-02-09 13:27:12 +0530220u16 ath9k_hw_computetxtime(struct ath_hw *ah,
Felix Fietkau545750d2009-11-23 22:21:01 +0100221 u8 phy, int kbps,
Sujithf1dc5602008-10-29 10:16:30 +0530222 u32 frameLen, u16 rateix,
223 bool shortPreamble)
224{
225 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
Sujithf1dc5602008-10-29 10:16:30 +0530226
227 if (kbps == 0)
228 return 0;
229
Felix Fietkau545750d2009-11-23 22:21:01 +0100230 switch (phy) {
Sujith46d14a52008-11-18 09:08:13 +0530231 case WLAN_RC_PHY_CCK:
Sujithf1dc5602008-10-29 10:16:30 +0530232 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
Felix Fietkau545750d2009-11-23 22:21:01 +0100233 if (shortPreamble)
Sujithf1dc5602008-10-29 10:16:30 +0530234 phyTime >>= 1;
235 numBits = frameLen << 3;
236 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
237 break;
Sujith46d14a52008-11-18 09:08:13 +0530238 case WLAN_RC_PHY_OFDM:
Sujith2660b812009-02-09 13:27:26 +0530239 if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530240 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
241 numBits = OFDM_PLCP_BITS + (frameLen << 3);
242 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
243 txTime = OFDM_SIFS_TIME_QUARTER
244 + OFDM_PREAMBLE_TIME_QUARTER
245 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
Sujith2660b812009-02-09 13:27:26 +0530246 } else if (ah->curchan &&
247 IS_CHAN_HALF_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530248 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
249 numBits = OFDM_PLCP_BITS + (frameLen << 3);
250 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
251 txTime = OFDM_SIFS_TIME_HALF +
252 OFDM_PREAMBLE_TIME_HALF
253 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
254 } else {
255 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
256 numBits = OFDM_PLCP_BITS + (frameLen << 3);
257 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
258 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
259 + (numSymbols * OFDM_SYMBOL_TIME);
260 }
261 break;
262 default:
Joe Perches38002762010-12-02 19:12:36 -0800263 ath_err(ath9k_hw_common(ah),
264 "Unknown phy %u (rate ix %u)\n", phy, rateix);
Sujithf1dc5602008-10-29 10:16:30 +0530265 txTime = 0;
266 break;
267 }
268
269 return txTime;
270}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400271EXPORT_SYMBOL(ath9k_hw_computetxtime);
Sujithf1dc5602008-10-29 10:16:30 +0530272
Sujithcbe61d82009-02-09 13:27:12 +0530273void ath9k_hw_get_channel_centers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530274 struct ath9k_channel *chan,
275 struct chan_centers *centers)
276{
277 int8_t extoff;
Sujithf1dc5602008-10-29 10:16:30 +0530278
279 if (!IS_CHAN_HT40(chan)) {
280 centers->ctl_center = centers->ext_center =
281 centers->synth_center = chan->channel;
282 return;
283 }
284
285 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
286 (chan->chanmode == CHANNEL_G_HT40PLUS)) {
287 centers->synth_center =
288 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
289 extoff = 1;
290 } else {
291 centers->synth_center =
292 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
293 extoff = -1;
294 }
295
296 centers->ctl_center =
297 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700298 /* 25 MHz spacing is supported by hw but not on upper layers */
Sujithf1dc5602008-10-29 10:16:30 +0530299 centers->ext_center =
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700300 centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT);
Sujithf1dc5602008-10-29 10:16:30 +0530301}
302
303/******************/
304/* Chip Revisions */
305/******************/
306
Sujithcbe61d82009-02-09 13:27:12 +0530307static void ath9k_hw_read_revisions(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530308{
309 u32 val;
310
Vasanthakumar Thiagarajanecb1d382011-04-19 19:29:18 +0530311 switch (ah->hw_version.devid) {
312 case AR5416_AR9100_DEVID:
313 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
314 break;
Gabor Juhos37625612011-06-21 11:23:23 +0200315 case AR9300_DEVID_AR9330:
316 ah->hw_version.macVersion = AR_SREV_VERSION_9330;
317 if (ah->get_mac_revision) {
318 ah->hw_version.macRev = ah->get_mac_revision();
319 } else {
320 val = REG_READ(ah, AR_SREV);
321 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
322 }
323 return;
Vasanthakumar Thiagarajanecb1d382011-04-19 19:29:18 +0530324 case AR9300_DEVID_AR9340:
325 ah->hw_version.macVersion = AR_SREV_VERSION_9340;
326 val = REG_READ(ah, AR_SREV);
327 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
328 return;
329 }
330
Sujithf1dc5602008-10-29 10:16:30 +0530331 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
332
333 if (val == 0xFF) {
334 val = REG_READ(ah, AR_SREV);
Sujithd535a422009-02-09 13:27:06 +0530335 ah->hw_version.macVersion =
336 (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
337 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
Mohammed Shafi Shajakhan76ed94b2011-09-30 11:31:28 +0530338
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +0530339 if (AR_SREV_9462(ah))
Mohammed Shafi Shajakhan76ed94b2011-09-30 11:31:28 +0530340 ah->is_pciexpress = true;
341 else
342 ah->is_pciexpress = (val &
343 AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
Sujithf1dc5602008-10-29 10:16:30 +0530344 } else {
345 if (!AR_SREV_9100(ah))
Sujithd535a422009-02-09 13:27:06 +0530346 ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
Sujithf1dc5602008-10-29 10:16:30 +0530347
Sujithd535a422009-02-09 13:27:06 +0530348 ah->hw_version.macRev = val & AR_SREV_REVISION;
Sujithf1dc5602008-10-29 10:16:30 +0530349
Sujithd535a422009-02-09 13:27:06 +0530350 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
Sujith2660b812009-02-09 13:27:26 +0530351 ah->is_pciexpress = true;
Sujithf1dc5602008-10-29 10:16:30 +0530352 }
353}
354
Sujithf1dc5602008-10-29 10:16:30 +0530355/************************************/
356/* HW Attach, Detach, Init Routines */
357/************************************/
358
Sujithcbe61d82009-02-09 13:27:12 +0530359static void ath9k_hw_disablepcie(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530360{
Felix Fietkau040b74f2010-12-12 00:51:07 +0100361 if (!AR_SREV_5416(ah))
Sujithf1dc5602008-10-29 10:16:30 +0530362 return;
363
364 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
365 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
366 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
367 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
368 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
369 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
370 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
371 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
372 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
373
374 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
375}
376
Stanislaw Gruszkad4930082011-07-29 15:59:08 +0200377static void ath9k_hw_aspm_init(struct ath_hw *ah)
378{
379 struct ath_common *common = ath9k_hw_common(ah);
380
381 if (common->bus_ops->aspm_init)
382 common->bus_ops->aspm_init(common);
383}
384
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400385/* This should work for all families including legacy */
Sujithcbe61d82009-02-09 13:27:12 +0530386static bool ath9k_hw_chip_test(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530387{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700388 struct ath_common *common = ath9k_hw_common(ah);
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400389 u32 regAddr[2] = { AR_STA_ID0 };
Sujithf1dc5602008-10-29 10:16:30 +0530390 u32 regHold[2];
Joe Perches07b2fa52010-11-20 18:38:53 -0800391 static const u32 patternData[4] = {
392 0x55555555, 0xaaaaaaaa, 0x66666666, 0x99999999
393 };
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400394 int i, j, loop_max;
Sujithf1dc5602008-10-29 10:16:30 +0530395
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400396 if (!AR_SREV_9300_20_OR_LATER(ah)) {
397 loop_max = 2;
398 regAddr[1] = AR_PHY_BASE + (8 << 2);
399 } else
400 loop_max = 1;
401
402 for (i = 0; i < loop_max; i++) {
Sujithf1dc5602008-10-29 10:16:30 +0530403 u32 addr = regAddr[i];
404 u32 wrData, rdData;
405
406 regHold[i] = REG_READ(ah, addr);
407 for (j = 0; j < 0x100; j++) {
408 wrData = (j << 16) | j;
409 REG_WRITE(ah, addr, wrData);
410 rdData = REG_READ(ah, addr);
411 if (rdData != wrData) {
Joe Perches38002762010-12-02 19:12:36 -0800412 ath_err(common,
413 "address test failed addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
414 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530415 return false;
416 }
417 }
418 for (j = 0; j < 4; j++) {
419 wrData = patternData[j];
420 REG_WRITE(ah, addr, wrData);
421 rdData = REG_READ(ah, addr);
422 if (wrData != rdData) {
Joe Perches38002762010-12-02 19:12:36 -0800423 ath_err(common,
424 "address test failed addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
425 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530426 return false;
427 }
428 }
429 REG_WRITE(ah, regAddr[i], regHold[i]);
430 }
431 udelay(100);
Sujithcbe61d82009-02-09 13:27:12 +0530432
Sujithf1dc5602008-10-29 10:16:30 +0530433 return true;
434}
435
Luis R. Rodriguezb8b0f372009-08-03 12:24:43 -0700436static void ath9k_hw_init_config(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700437{
438 int i;
439
Felix Fietkau689e7562012-04-12 22:35:56 +0200440 ah->config.dma_beacon_response_time = 1;
441 ah->config.sw_beacon_response_time = 6;
Sujith2660b812009-02-09 13:27:26 +0530442 ah->config.additional_swba_backoff = 0;
443 ah->config.ack_6mb = 0x0;
444 ah->config.cwm_ignore_extcca = 0;
Sujith2660b812009-02-09 13:27:26 +0530445 ah->config.pcie_clock_req = 0;
Sujith2660b812009-02-09 13:27:26 +0530446 ah->config.pcie_waen = 0;
447 ah->config.analog_shiftreg = 1;
Luis R. Rodriguez03c72512010-06-12 00:33:46 -0400448 ah->config.enable_ani = true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700449
450 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujith2660b812009-02-09 13:27:26 +0530451 ah->config.spurchans[i][0] = AR_NO_SPUR;
452 ah->config.spurchans[i][1] = AR_NO_SPUR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700453 }
454
Luis R. Rodriguez6f481012011-01-20 17:47:39 -0800455 /* PAPRD needs some more work to be enabled */
456 ah->config.paprd_disable = 1;
457
Sujith0ce024c2009-12-14 14:57:00 +0530458 ah->config.rx_intr_mitigation = true;
Luis R. Rodriguez6a0ec302010-06-21 18:38:49 -0400459 ah->config.pcieSerDesWrite = true;
Luis R. Rodriguez61584252009-03-12 18:18:49 -0400460
461 /*
462 * We need this for PCI devices only (Cardbus, PCI, miniPCI)
463 * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
464 * This means we use it for all AR5416 devices, and the few
465 * minor PCI AR9280 devices out there.
466 *
467 * Serialization is required because these devices do not handle
468 * well the case of two concurrent reads/writes due to the latency
469 * involved. During one read/write another read/write can be issued
470 * on another CPU while the previous read/write may still be working
471 * on our hardware, if we hit this case the hardware poops in a loop.
472 * We prevent this by serializing reads and writes.
473 *
474 * This issue is not present on PCI-Express devices or pre-AR5416
475 * devices (legacy, 802.11abg).
476 */
477 if (num_possible_cpus() > 1)
David S. Miller2d6a5e92009-03-17 15:01:30 -0700478 ah->config.serialize_regmode = SER_REG_MODE_AUTO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700479}
480
Luis R. Rodriguez50aca252009-08-03 12:24:42 -0700481static void ath9k_hw_init_defaults(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700482{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700483 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
484
485 regulatory->country_code = CTRY_DEFAULT;
486 regulatory->power_limit = MAX_RATE_POWER;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700487
Sujithd535a422009-02-09 13:27:06 +0530488 ah->hw_version.magic = AR5416_MAGIC;
Sujithd535a422009-02-09 13:27:06 +0530489 ah->hw_version.subvendorid = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700490
Sujith2660b812009-02-09 13:27:26 +0530491 ah->atim_window = 0;
Felix Fietkau16f24112010-06-12 17:22:32 +0200492 ah->sta_id1_defaults =
493 AR_STA_ID1_CRPT_MIC_ENABLE |
494 AR_STA_ID1_MCAST_KSRCH;
Felix Fietkauf1717602011-03-19 13:55:41 +0100495 if (AR_SREV_9100(ah))
496 ah->sta_id1_defaults |= AR_STA_ID1_AR9100_BA_FIX;
Rajkumar Manoharane3f2acc2011-08-27 11:22:59 +0530497 ah->slottime = ATH9K_SLOT_TIME_9;
Sujith2660b812009-02-09 13:27:26 +0530498 ah->globaltxtimeout = (u32) -1;
Gabor Juhoscbdec972009-07-24 17:27:22 +0200499 ah->power_mode = ATH9K_PM_UNDEFINED;
Felix Fietkau8efa7a82012-03-14 16:40:23 +0100500 ah->htc_reset_init = true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700501}
502
Sujithcbe61d82009-02-09 13:27:12 +0530503static int ath9k_hw_init_macaddr(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700504{
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700505 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530506 u32 sum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700507 int i;
Sujithf1dc5602008-10-29 10:16:30 +0530508 u16 eeval;
Joe Perches07b2fa52010-11-20 18:38:53 -0800509 static const u32 EEP_MAC[] = { EEP_MAC_LSW, EEP_MAC_MID, EEP_MAC_MSW };
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700510
Sujithf1dc5602008-10-29 10:16:30 +0530511 sum = 0;
512 for (i = 0; i < 3; i++) {
Luis R. Rodriguez49101672010-04-15 17:39:13 -0400513 eeval = ah->eep_ops->get_eeprom(ah, EEP_MAC[i]);
Sujithf1dc5602008-10-29 10:16:30 +0530514 sum += eeval;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700515 common->macaddr[2 * i] = eeval >> 8;
516 common->macaddr[2 * i + 1] = eeval & 0xff;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700517 }
Sujithd8baa932009-03-30 15:28:25 +0530518 if (sum == 0 || sum == 0xffff * 3)
Sujithf1dc5602008-10-29 10:16:30 +0530519 return -EADDRNOTAVAIL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700520
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700521 return 0;
522}
523
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700524static int ath9k_hw_post_init(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700525{
Sujith Manoharan6cae913d2011-01-04 13:16:37 +0530526 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700527 int ecode;
528
Sujith Manoharan6cae913d2011-01-04 13:16:37 +0530529 if (common->bus_ops->ath_bus_type != ATH_USB) {
Sujith527d4852010-03-17 14:25:16 +0530530 if (!ath9k_hw_chip_test(ah))
531 return -ENODEV;
532 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700533
Luis R. Rodriguezebd5a142010-04-15 17:39:18 -0400534 if (!AR_SREV_9300_20_OR_LATER(ah)) {
535 ecode = ar9002_hw_rf_claim(ah);
536 if (ecode != 0)
537 return ecode;
538 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700539
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700540 ecode = ath9k_hw_eeprom_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700541 if (ecode != 0)
542 return ecode;
Sujith7d01b222009-03-13 08:55:55 +0530543
Joe Perchesd2182b62011-12-15 14:55:53 -0800544 ath_dbg(ath9k_hw_common(ah), CONFIG, "Eeprom VER: %d, REV: %d\n",
Joe Perches226afe62010-12-02 19:12:37 -0800545 ah->eep_ops->get_eeprom_ver(ah),
546 ah->eep_ops->get_eeprom_rev(ah));
Sujith7d01b222009-03-13 08:55:55 +0530547
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400548 ecode = ath9k_hw_rf_alloc_ext_banks(ah);
549 if (ecode) {
Joe Perches38002762010-12-02 19:12:36 -0800550 ath_err(ath9k_hw_common(ah),
551 "Failed allocating banks for external radio\n");
Rajkumar Manoharan48a7c3d2010-11-08 20:40:53 +0530552 ath9k_hw_rf_free_ext_banks(ah);
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400553 return ecode;
Luis R. Rodriguez574d6b12009-10-19 02:33:37 -0400554 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700555
Nikolay Martynov42794252011-12-02 22:39:16 -0500556 if (ah->config.enable_ani) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700557 ath9k_hw_ani_setup(ah);
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700558 ath9k_hw_ani_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700559 }
Sujithf1dc5602008-10-29 10:16:30 +0530560
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700561 return 0;
562}
563
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400564static void ath9k_hw_attach_ops(struct ath_hw *ah)
Luis R. Rodriguezee2bb462009-08-03 12:24:39 -0700565{
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400566 if (AR_SREV_9300_20_OR_LATER(ah))
567 ar9003_hw_attach_ops(ah);
568 else
569 ar9002_hw_attach_ops(ah);
Luis R. Rodriguezee2bb462009-08-03 12:24:39 -0700570}
571
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400572/* Called for all hardware families */
573static int __ath9k_hw_init(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700574{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700575 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700576 int r = 0;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700577
Senthil Balasubramanianac45c122010-12-22 21:14:20 +0530578 ath9k_hw_read_revisions(ah);
579
Senthil Balasubramanian0a8d7cb2010-12-22 19:17:18 +0530580 /*
581 * Read back AR_WA into a permanent copy and set bits 14 and 17.
582 * We need to do this to avoid RMW of this register. We cannot
583 * read the reg when chip is asleep.
584 */
585 ah->WARegVal = REG_READ(ah, AR_WA);
586 ah->WARegVal |= (AR_WA_D3_L1_DISABLE |
587 AR_WA_ASPM_TIMER_BASED_DISABLE);
588
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700589 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Joe Perches38002762010-12-02 19:12:36 -0800590 ath_err(common, "Couldn't reset chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700591 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700592 }
593
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +0530594 if (AR_SREV_9462(ah))
Rajkumar Manoharaneec353c2011-10-13 10:49:13 +0530595 ah->WARegVal &= ~AR_WA_D3_L1_DISABLE;
596
Luis R. Rodriguezbab1f622010-04-15 17:38:20 -0400597 ath9k_hw_init_defaults(ah);
598 ath9k_hw_init_config(ah);
599
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400600 ath9k_hw_attach_ops(ah);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400601
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700602 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
Joe Perches38002762010-12-02 19:12:36 -0800603 ath_err(common, "Couldn't wakeup chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700604 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700605 }
606
Felix Fietkauf3eef642012-03-14 16:40:25 +0100607 if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700608 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
John W. Linville4c85ab12010-07-28 10:06:35 -0400609 ((AR_SREV_9160(ah) || AR_SREV_9280(ah)) &&
610 !ah->is_pciexpress)) {
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700611 ah->config.serialize_regmode =
612 SER_REG_MODE_ON;
613 } else {
614 ah->config.serialize_regmode =
615 SER_REG_MODE_OFF;
616 }
617 }
618
Joe Perchesd2182b62011-12-15 14:55:53 -0800619 ath_dbg(common, RESET, "serialize_regmode is %d\n",
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700620 ah->config.serialize_regmode);
621
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -0500622 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
623 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD >> 1;
624 else
625 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD;
626
Felix Fietkau6da5a722010-12-12 00:51:12 +0100627 switch (ah->hw_version.macVersion) {
628 case AR_SREV_VERSION_5416_PCI:
629 case AR_SREV_VERSION_5416_PCIE:
630 case AR_SREV_VERSION_9160:
631 case AR_SREV_VERSION_9100:
632 case AR_SREV_VERSION_9280:
633 case AR_SREV_VERSION_9285:
634 case AR_SREV_VERSION_9287:
635 case AR_SREV_VERSION_9271:
636 case AR_SREV_VERSION_9300:
Gabor Juhos2c8e5932011-06-21 11:23:21 +0200637 case AR_SREV_VERSION_9330:
Felix Fietkau6da5a722010-12-12 00:51:12 +0100638 case AR_SREV_VERSION_9485:
Vasanthakumar Thiagarajanbca04682011-04-19 19:29:20 +0530639 case AR_SREV_VERSION_9340:
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +0530640 case AR_SREV_VERSION_9462:
Felix Fietkau6da5a722010-12-12 00:51:12 +0100641 break;
642 default:
Joe Perches38002762010-12-02 19:12:36 -0800643 ath_err(common,
644 "Mac Chip Rev 0x%02x.%x is not supported by this driver\n",
645 ah->hw_version.macVersion, ah->hw_version.macRev);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700646 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700647 }
648
Gabor Juhos2c8e5932011-06-21 11:23:21 +0200649 if (AR_SREV_9271(ah) || AR_SREV_9100(ah) || AR_SREV_9340(ah) ||
650 AR_SREV_9330(ah))
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400651 ah->is_pciexpress = false;
652
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700653 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700654 ath9k_hw_init_cal_settings(ah);
655
656 ah->ani_function = ATH9K_ANI_ALL;
Felix Fietkau7a370812010-09-22 12:34:52 +0200657 if (AR_SREV_9280_20_OR_LATER(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700658 ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400659 if (!AR_SREV_9300_20_OR_LATER(ah))
660 ah->ani_function &= ~ATH9K_ANI_MRC_CCK;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700661
Nikolay Martynov4f17c482011-12-06 21:57:17 -0500662 /* disable ANI for 9340 */
663 if (AR_SREV_9340(ah))
Nikolay Martynov42794252011-12-02 22:39:16 -0500664 ah->config.enable_ani = false;
665
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700666 ath9k_hw_init_mode_regs(ah);
667
Stanislaw Gruszka69ce6742011-08-05 13:10:34 +0200668 if (!ah->is_pciexpress)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700669 ath9k_hw_disablepcie(ah);
670
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700671 r = ath9k_hw_post_init(ah);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700672 if (r)
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700673 return r;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700674
675 ath9k_hw_init_mode_gain_regs(ah);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +0100676 r = ath9k_hw_fill_cap_info(ah);
677 if (r)
678 return r;
679
Stanislaw Gruszka69ce6742011-08-05 13:10:34 +0200680 if (ah->is_pciexpress)
681 ath9k_hw_aspm_init(ah);
682
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700683 r = ath9k_hw_init_macaddr(ah);
684 if (r) {
Joe Perches38002762010-12-02 19:12:36 -0800685 ath_err(common, "Failed to initialize MAC address\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700686 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700687 }
688
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400689 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
Sujith2660b812009-02-09 13:27:26 +0530690 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700691 else
Sujith2660b812009-02-09 13:27:26 +0530692 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700693
Gabor Juhos88e641d2011-06-21 11:23:30 +0200694 if (AR_SREV_9330(ah))
695 ah->bb_watchdog_timeout_ms = 85;
696 else
697 ah->bb_watchdog_timeout_ms = 25;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700698
Luis R. Rodriguez211f5852009-10-06 21:19:07 -0400699 common->state = ATH_HW_INITIALIZED;
700
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700701 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700702}
703
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400704int ath9k_hw_init(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530705{
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400706 int ret;
707 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530708
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400709 /* These are all the AR5008/AR9001/AR9002 hardware family of chipsets */
710 switch (ah->hw_version.devid) {
711 case AR5416_DEVID_PCI:
712 case AR5416_DEVID_PCIE:
713 case AR5416_AR9100_DEVID:
714 case AR9160_DEVID_PCI:
715 case AR9280_DEVID_PCI:
716 case AR9280_DEVID_PCIE:
717 case AR9285_DEVID_PCIE:
Senthil Balasubramaniandb3cc532010-04-15 17:38:18 -0400718 case AR9287_DEVID_PCI:
719 case AR9287_DEVID_PCIE:
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400720 case AR2427_DEVID_PCIE:
Senthil Balasubramaniandb3cc532010-04-15 17:38:18 -0400721 case AR9300_DEVID_PCIE:
Vasanthakumar Thiagarajan3050c912010-12-06 04:27:36 -0800722 case AR9300_DEVID_AR9485_PCIE:
Gabor Juhos999a7a82011-06-21 11:23:52 +0200723 case AR9300_DEVID_AR9330:
Vasanthakumar Thiagarajanbca04682011-04-19 19:29:20 +0530724 case AR9300_DEVID_AR9340:
Luis R. Rodriguez5a63ef02011-08-24 15:36:08 -0700725 case AR9300_DEVID_AR9580:
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +0530726 case AR9300_DEVID_AR9462:
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400727 break;
728 default:
729 if (common->bus_ops->ath_bus_type == ATH_USB)
730 break;
Joe Perches38002762010-12-02 19:12:36 -0800731 ath_err(common, "Hardware device ID 0x%04x not supported\n",
732 ah->hw_version.devid);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400733 return -EOPNOTSUPP;
734 }
Sujithf1dc5602008-10-29 10:16:30 +0530735
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400736 ret = __ath9k_hw_init(ah);
737 if (ret) {
Joe Perches38002762010-12-02 19:12:36 -0800738 ath_err(common,
739 "Unable to initialize hardware; initialization status: %d\n",
740 ret);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400741 return ret;
742 }
Sujithf1dc5602008-10-29 10:16:30 +0530743
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400744 return 0;
Sujithf1dc5602008-10-29 10:16:30 +0530745}
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400746EXPORT_SYMBOL(ath9k_hw_init);
Sujithf1dc5602008-10-29 10:16:30 +0530747
Sujithcbe61d82009-02-09 13:27:12 +0530748static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530749{
Sujith7d0d0df2010-04-16 11:53:57 +0530750 ENABLE_REGWRITE_BUFFER(ah);
751
Sujithf1dc5602008-10-29 10:16:30 +0530752 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
753 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
754
755 REG_WRITE(ah, AR_QOS_NO_ACK,
756 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
757 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
758 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
759
760 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
761 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
762 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
763 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
764 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
Sujith7d0d0df2010-04-16 11:53:57 +0530765
766 REGWRITE_BUFFER_FLUSH(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530767}
768
Senthil Balasubramanianb84628e2011-04-22 11:32:12 +0530769u32 ar9003_get_pll_sqsum_dvc(struct ath_hw *ah)
Vivek Natarajanb1415812011-01-27 14:45:07 +0530770{
Felix Fietkauca7a4de2011-03-23 20:57:26 +0100771 REG_CLR_BIT(ah, PLL3, PLL3_DO_MEAS_MASK);
772 udelay(100);
773 REG_SET_BIT(ah, PLL3, PLL3_DO_MEAS_MASK);
774
775 while ((REG_READ(ah, PLL4) & PLL4_MEAS_DONE) == 0)
Vivek Natarajanb1415812011-01-27 14:45:07 +0530776 udelay(100);
Vivek Natarajanb1415812011-01-27 14:45:07 +0530777
Felix Fietkauca7a4de2011-03-23 20:57:26 +0100778 return (REG_READ(ah, PLL3) & SQSUM_DVC_MASK) >> 3;
Vivek Natarajanb1415812011-01-27 14:45:07 +0530779}
780EXPORT_SYMBOL(ar9003_get_pll_sqsum_dvc);
781
Sujithcbe61d82009-02-09 13:27:12 +0530782static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530783 struct ath9k_channel *chan)
784{
Vasanthakumar Thiagarajand09b17f2010-12-06 04:27:44 -0800785 u32 pll;
786
Vivek Natarajan22983c32011-01-27 14:45:09 +0530787 if (AR_SREV_9485(ah)) {
Vivek Natarajan22983c32011-01-27 14:45:09 +0530788
Vasanthakumar Thiagarajan3dfd7f62011-04-11 16:39:40 +0530789 /* program BB PLL ki and kd value, ki=0x4, kd=0x40 */
790 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
791 AR_CH0_BB_DPLL2_PLL_PWD, 0x1);
792 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
793 AR_CH0_DPLL2_KD, 0x40);
794 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
795 AR_CH0_DPLL2_KI, 0x4);
Vivek Natarajan22983c32011-01-27 14:45:09 +0530796
Vasanthakumar Thiagarajan3dfd7f62011-04-11 16:39:40 +0530797 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
798 AR_CH0_BB_DPLL1_REFDIV, 0x5);
799 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
800 AR_CH0_BB_DPLL1_NINI, 0x58);
801 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
802 AR_CH0_BB_DPLL1_NFRAC, 0x0);
803
804 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
805 AR_CH0_BB_DPLL2_OUTDIV, 0x1);
806 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
807 AR_CH0_BB_DPLL2_LOCAL_PLL, 0x1);
808 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
809 AR_CH0_BB_DPLL2_EN_NEGTRIG, 0x1);
810
811 /* program BB PLL phase_shift to 0x6 */
812 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL3,
813 AR_CH0_BB_DPLL3_PHASE_SHIFT, 0x6);
814
815 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
816 AR_CH0_BB_DPLL2_PLL_PWD, 0x0);
Vivek Natarajan75e03512011-03-10 11:05:42 +0530817 udelay(1000);
Gabor Juhosa5415d62011-06-21 11:23:29 +0200818 } else if (AR_SREV_9330(ah)) {
819 u32 ddr_dpll2, pll_control2, kd;
820
821 if (ah->is_clk_25mhz) {
822 ddr_dpll2 = 0x18e82f01;
823 pll_control2 = 0xe04a3d;
824 kd = 0x1d;
825 } else {
826 ddr_dpll2 = 0x19e82f01;
827 pll_control2 = 0x886666;
828 kd = 0x3d;
829 }
830
831 /* program DDR PLL ki and kd value */
832 REG_WRITE(ah, AR_CH0_DDR_DPLL2, ddr_dpll2);
833
834 /* program DDR PLL phase_shift */
835 REG_RMW_FIELD(ah, AR_CH0_DDR_DPLL3,
836 AR_CH0_DPLL3_PHASE_SHIFT, 0x1);
837
838 REG_WRITE(ah, AR_RTC_PLL_CONTROL, 0x1142c);
839 udelay(1000);
840
841 /* program refdiv, nint, frac to RTC register */
842 REG_WRITE(ah, AR_RTC_PLL_CONTROL2, pll_control2);
843
844 /* program BB PLL kd and ki value */
845 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, AR_CH0_DPLL2_KD, kd);
846 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, AR_CH0_DPLL2_KI, 0x06);
847
848 /* program BB PLL phase_shift */
849 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL3,
850 AR_CH0_BB_DPLL3_PHASE_SHIFT, 0x1);
Vasanthakumar Thiagarajan0b488ac2011-04-20 10:26:15 +0530851 } else if (AR_SREV_9340(ah)) {
852 u32 regval, pll2_divint, pll2_divfrac, refdiv;
853
854 REG_WRITE(ah, AR_RTC_PLL_CONTROL, 0x1142c);
855 udelay(1000);
856
857 REG_SET_BIT(ah, AR_PHY_PLL_MODE, 0x1 << 16);
858 udelay(100);
859
860 if (ah->is_clk_25mhz) {
861 pll2_divint = 0x54;
862 pll2_divfrac = 0x1eb85;
863 refdiv = 3;
864 } else {
865 pll2_divint = 88;
866 pll2_divfrac = 0;
867 refdiv = 5;
868 }
869
870 regval = REG_READ(ah, AR_PHY_PLL_MODE);
871 regval |= (0x1 << 16);
872 REG_WRITE(ah, AR_PHY_PLL_MODE, regval);
873 udelay(100);
874
875 REG_WRITE(ah, AR_PHY_PLL_CONTROL, (refdiv << 27) |
876 (pll2_divint << 18) | pll2_divfrac);
877 udelay(100);
878
879 regval = REG_READ(ah, AR_PHY_PLL_MODE);
880 regval = (regval & 0x80071fff) | (0x1 << 30) | (0x1 << 13) |
881 (0x4 << 26) | (0x18 << 19);
882 REG_WRITE(ah, AR_PHY_PLL_MODE, regval);
883 REG_WRITE(ah, AR_PHY_PLL_MODE,
884 REG_READ(ah, AR_PHY_PLL_MODE) & 0xfffeffff);
885 udelay(1000);
Vivek Natarajan22983c32011-01-27 14:45:09 +0530886 }
Vasanthakumar Thiagarajand09b17f2010-12-06 04:27:44 -0800887
888 pll = ath9k_hw_compute_pll_control(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +0530889
Gabor Juhosd03a66c2009-01-14 20:17:09 +0100890 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +0530891
Gabor Juhosa5415d62011-06-21 11:23:29 +0200892 if (AR_SREV_9485(ah) || AR_SREV_9340(ah) || AR_SREV_9330(ah))
Vasanthakumar Thiagarajan3dfd7f62011-04-11 16:39:40 +0530893 udelay(1000);
894
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -0400895 /* Switch the core clock for ar9271 to 117Mhz */
896 if (AR_SREV_9271(ah)) {
Sujith25e2ab12010-03-17 14:25:22 +0530897 udelay(500);
898 REG_WRITE(ah, 0x50040, 0x304);
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -0400899 }
900
Sujithf1dc5602008-10-29 10:16:30 +0530901 udelay(RTC_PLL_SETTLE_DELAY);
902
903 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
Vasanthakumar Thiagarajan0b488ac2011-04-20 10:26:15 +0530904
905 if (AR_SREV_9340(ah)) {
906 if (ah->is_clk_25mhz) {
907 REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x17c << 1);
908 REG_WRITE(ah, AR_SLP32_MODE, 0x0010f3d7);
909 REG_WRITE(ah, AR_SLP32_INC, 0x0001e7ae);
910 } else {
911 REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x261 << 1);
912 REG_WRITE(ah, AR_SLP32_MODE, 0x0010f400);
913 REG_WRITE(ah, AR_SLP32_INC, 0x0001e800);
914 }
915 udelay(100);
916 }
Sujithf1dc5602008-10-29 10:16:30 +0530917}
918
Sujithcbe61d82009-02-09 13:27:12 +0530919static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -0800920 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +0530921{
Vasanthakumar Thiagarajan79d1d2b2011-04-19 19:29:19 +0530922 u32 sync_default = AR_INTR_SYNC_DEFAULT;
Pavel Roskin152d5302010-03-31 18:05:37 -0400923 u32 imr_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +0530924 AR_IMR_TXURN |
925 AR_IMR_RXERR |
926 AR_IMR_RXORN |
927 AR_IMR_BCNMISC;
928
Vasanthakumar Thiagarajan79d1d2b2011-04-19 19:29:19 +0530929 if (AR_SREV_9340(ah))
930 sync_default &= ~AR_INTR_SYNC_HOST1_FATAL;
931
Vasanthakumar Thiagarajan66860242010-04-15 17:39:07 -0400932 if (AR_SREV_9300_20_OR_LATER(ah)) {
933 imr_reg |= AR_IMR_RXOK_HP;
934 if (ah->config.rx_intr_mitigation)
935 imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
936 else
937 imr_reg |= AR_IMR_RXOK_LP;
Sujithf1dc5602008-10-29 10:16:30 +0530938
Vasanthakumar Thiagarajan66860242010-04-15 17:39:07 -0400939 } else {
940 if (ah->config.rx_intr_mitigation)
941 imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
942 else
943 imr_reg |= AR_IMR_RXOK;
944 }
945
946 if (ah->config.tx_intr_mitigation)
947 imr_reg |= AR_IMR_TXINTM | AR_IMR_TXMINTR;
948 else
949 imr_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +0530950
Colin McCabed97809d2008-12-01 13:38:55 -0800951 if (opmode == NL80211_IFTYPE_AP)
Pavel Roskin152d5302010-03-31 18:05:37 -0400952 imr_reg |= AR_IMR_MIB;
Sujithf1dc5602008-10-29 10:16:30 +0530953
Sujith7d0d0df2010-04-16 11:53:57 +0530954 ENABLE_REGWRITE_BUFFER(ah);
955
Pavel Roskin152d5302010-03-31 18:05:37 -0400956 REG_WRITE(ah, AR_IMR, imr_reg);
Pavel Roskin74bad5c2010-02-23 18:15:27 -0500957 ah->imrs2_reg |= AR_IMR_S2_GTT;
958 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
Sujithf1dc5602008-10-29 10:16:30 +0530959
960 if (!AR_SREV_9100(ah)) {
961 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
Vasanthakumar Thiagarajan79d1d2b2011-04-19 19:29:19 +0530962 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, sync_default);
Sujithf1dc5602008-10-29 10:16:30 +0530963 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
964 }
Vasanthakumar Thiagarajan66860242010-04-15 17:39:07 -0400965
Sujith7d0d0df2010-04-16 11:53:57 +0530966 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +0530967
Vasanthakumar Thiagarajan66860242010-04-15 17:39:07 -0400968 if (AR_SREV_9300_20_OR_LATER(ah)) {
969 REG_WRITE(ah, AR_INTR_PRIO_ASYNC_ENABLE, 0);
970 REG_WRITE(ah, AR_INTR_PRIO_ASYNC_MASK, 0);
971 REG_WRITE(ah, AR_INTR_PRIO_SYNC_ENABLE, 0);
972 REG_WRITE(ah, AR_INTR_PRIO_SYNC_MASK, 0);
973 }
Sujithf1dc5602008-10-29 10:16:30 +0530974}
975
Felix Fietkaub6ba41b2011-07-09 11:12:50 +0700976static void ath9k_hw_set_sifs_time(struct ath_hw *ah, u32 us)
977{
978 u32 val = ath9k_hw_mac_to_clks(ah, us - 2);
979 val = min(val, (u32) 0xFFFF);
980 REG_WRITE(ah, AR_D_GBL_IFS_SIFS, val);
981}
982
Felix Fietkau0005baf2010-01-15 02:33:40 +0100983static void ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +0530984{
Felix Fietkau0005baf2010-01-15 02:33:40 +0100985 u32 val = ath9k_hw_mac_to_clks(ah, us);
986 val = min(val, (u32) 0xFFFF);
987 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, val);
Sujithf1dc5602008-10-29 10:16:30 +0530988}
989
Felix Fietkau0005baf2010-01-15 02:33:40 +0100990static void ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +0530991{
Felix Fietkau0005baf2010-01-15 02:33:40 +0100992 u32 val = ath9k_hw_mac_to_clks(ah, us);
993 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_ACK));
994 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_ACK, val);
995}
996
997static void ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
998{
999 u32 val = ath9k_hw_mac_to_clks(ah, us);
1000 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_CTS));
1001 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_CTS, val);
Sujithf1dc5602008-10-29 10:16:30 +05301002}
1003
Sujithcbe61d82009-02-09 13:27:12 +05301004static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +05301005{
Sujithf1dc5602008-10-29 10:16:30 +05301006 if (tu > 0xFFFF) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001007 ath_dbg(ath9k_hw_common(ah), XMIT, "bad global tx timeout %u\n",
1008 tu);
Sujith2660b812009-02-09 13:27:26 +05301009 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301010 return false;
1011 } else {
1012 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +05301013 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +05301014 return true;
1015 }
1016}
1017
Felix Fietkau0005baf2010-01-15 02:33:40 +01001018void ath9k_hw_init_global_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301019{
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001020 struct ath_common *common = ath9k_hw_common(ah);
1021 struct ieee80211_conf *conf = &common->hw->conf;
1022 const struct ath9k_channel *chan = ah->curchan;
Felix Fietkaue115b7e2012-04-19 21:18:23 +02001023 int acktimeout, ctstimeout, ack_offset = 0;
Felix Fietkaue239d852010-01-15 02:34:58 +01001024 int slottime;
Felix Fietkau0005baf2010-01-15 02:33:40 +01001025 int sifstime;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001026 int rx_lat = 0, tx_lat = 0, eifs = 0;
1027 u32 reg;
Felix Fietkau0005baf2010-01-15 02:33:40 +01001028
Joe Perchesd2182b62011-12-15 14:55:53 -08001029 ath_dbg(ath9k_hw_common(ah), RESET, "ah->misc_mode 0x%x\n",
Joe Perches226afe62010-12-02 19:12:37 -08001030 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +05301031
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001032 if (!chan)
1033 return;
1034
Sujith2660b812009-02-09 13:27:26 +05301035 if (ah->misc_mode != 0)
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001036 REG_SET_BIT(ah, AR_PCU_MISC, ah->misc_mode);
Felix Fietkau0005baf2010-01-15 02:33:40 +01001037
Rajkumar Manoharan81a91d52011-08-31 10:47:30 +05301038 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
1039 rx_lat = 41;
1040 else
1041 rx_lat = 37;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001042 tx_lat = 54;
1043
Felix Fietkaue88e4862012-04-19 21:18:22 +02001044 if (IS_CHAN_5GHZ(chan))
1045 sifstime = 16;
1046 else
1047 sifstime = 10;
1048
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001049 if (IS_CHAN_HALF_RATE(chan)) {
1050 eifs = 175;
1051 rx_lat *= 2;
1052 tx_lat *= 2;
1053 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
1054 tx_lat += 11;
1055
Felix Fietkaue88e4862012-04-19 21:18:22 +02001056 sifstime *= 2;
Felix Fietkaue115b7e2012-04-19 21:18:23 +02001057 ack_offset = 16;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001058 slottime = 13;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001059 } else if (IS_CHAN_QUARTER_RATE(chan)) {
1060 eifs = 340;
Rajkumar Manoharan81a91d52011-08-31 10:47:30 +05301061 rx_lat = (rx_lat * 4) - 1;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001062 tx_lat *= 4;
1063 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
1064 tx_lat += 22;
1065
Felix Fietkaue88e4862012-04-19 21:18:22 +02001066 sifstime *= 4;
Felix Fietkaue115b7e2012-04-19 21:18:23 +02001067 ack_offset = 32;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001068 slottime = 21;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001069 } else {
Rajkumar Manoharana7be0392011-08-27 12:13:21 +05301070 if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah)) {
1071 eifs = AR_D_GBL_IFS_EIFS_ASYNC_FIFO;
1072 reg = AR_USEC_ASYNC_FIFO;
1073 } else {
1074 eifs = REG_READ(ah, AR_D_GBL_IFS_EIFS)/
1075 common->clockrate;
1076 reg = REG_READ(ah, AR_USEC);
1077 }
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001078 rx_lat = MS(reg, AR_USEC_RX_LAT);
1079 tx_lat = MS(reg, AR_USEC_TX_LAT);
1080
1081 slottime = ah->slottime;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001082 }
Felix Fietkau0005baf2010-01-15 02:33:40 +01001083
Felix Fietkaue239d852010-01-15 02:34:58 +01001084 /* As defined by IEEE 802.11-2007 17.3.8.6 */
Felix Fietkaue115b7e2012-04-19 21:18:23 +02001085 acktimeout = slottime + sifstime + 3 * ah->coverage_class + ack_offset;
Felix Fietkauadb50662011-08-28 01:52:10 +02001086 ctstimeout = acktimeout;
Felix Fietkau42c45682010-02-11 18:07:19 +01001087
1088 /*
1089 * Workaround for early ACK timeouts, add an offset to match the
Felix Fietkau55a2bb42012-02-05 21:15:18 +01001090 * initval's 64us ack timeout value. Use 48us for the CTS timeout.
Felix Fietkau42c45682010-02-11 18:07:19 +01001091 * This was initially only meant to work around an issue with delayed
1092 * BA frames in some implementations, but it has been found to fix ACK
1093 * timeout issues in other cases as well.
1094 */
Felix Fietkaue115b7e2012-04-19 21:18:23 +02001095 if (conf->channel && conf->channel->band == IEEE80211_BAND_2GHZ &&
1096 !IS_CHAN_HALF_RATE(chan) && !IS_CHAN_QUARTER_RATE(chan)) {
Felix Fietkau42c45682010-02-11 18:07:19 +01001097 acktimeout += 64 - sifstime - ah->slottime;
Felix Fietkau55a2bb42012-02-05 21:15:18 +01001098 ctstimeout += 48 - sifstime - ah->slottime;
1099 }
1100
Felix Fietkau42c45682010-02-11 18:07:19 +01001101
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001102 ath9k_hw_set_sifs_time(ah, sifstime);
1103 ath9k_hw_setslottime(ah, slottime);
Felix Fietkau0005baf2010-01-15 02:33:40 +01001104 ath9k_hw_set_ack_timeout(ah, acktimeout);
Felix Fietkauadb50662011-08-28 01:52:10 +02001105 ath9k_hw_set_cts_timeout(ah, ctstimeout);
Sujith2660b812009-02-09 13:27:26 +05301106 if (ah->globaltxtimeout != (u32) -1)
1107 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001108
1109 REG_WRITE(ah, AR_D_GBL_IFS_EIFS, ath9k_hw_mac_to_clks(ah, eifs));
1110 REG_RMW(ah, AR_USEC,
1111 (common->clockrate - 1) |
1112 SM(rx_lat, AR_USEC_RX_LAT) |
1113 SM(tx_lat, AR_USEC_TX_LAT),
1114 AR_USEC_TX_LAT | AR_USEC_RX_LAT | AR_USEC_USEC);
1115
Sujithf1dc5602008-10-29 10:16:30 +05301116}
Felix Fietkau0005baf2010-01-15 02:33:40 +01001117EXPORT_SYMBOL(ath9k_hw_init_global_settings);
Sujithf1dc5602008-10-29 10:16:30 +05301118
Sujith285f2dd2010-01-08 10:36:07 +05301119void ath9k_hw_deinit(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001120{
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001121 struct ath_common *common = ath9k_hw_common(ah);
1122
Sujith736b3a22010-03-17 14:25:24 +05301123 if (common->state < ATH_HW_INITIALIZED)
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001124 goto free_hw;
1125
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001126 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001127
1128free_hw:
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001129 ath9k_hw_rf_free_ext_banks(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001130}
Sujith285f2dd2010-01-08 10:36:07 +05301131EXPORT_SYMBOL(ath9k_hw_deinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001132
Sujithf1dc5602008-10-29 10:16:30 +05301133/*******/
1134/* INI */
1135/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001136
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001137u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan)
Bob Copeland3a702e42009-03-30 22:30:29 -04001138{
1139 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
1140
1141 if (IS_CHAN_B(chan))
1142 ctl |= CTL_11B;
1143 else if (IS_CHAN_G(chan))
1144 ctl |= CTL_11G;
1145 else
1146 ctl |= CTL_11A;
1147
1148 return ctl;
1149}
1150
Sujithf1dc5602008-10-29 10:16:30 +05301151/****************************************/
1152/* Reset and Channel Switching Routines */
1153/****************************************/
1154
Sujithcbe61d82009-02-09 13:27:12 +05301155static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301156{
Felix Fietkau57b32222010-04-15 17:39:22 -04001157 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301158
Sujith7d0d0df2010-04-16 11:53:57 +05301159 ENABLE_REGWRITE_BUFFER(ah);
1160
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001161 /*
1162 * set AHB_MODE not to do cacheline prefetches
1163 */
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001164 if (!AR_SREV_9300_20_OR_LATER(ah))
1165 REG_SET_BIT(ah, AR_AHB_MODE, AR_AHB_PREFETCH_RD_EN);
Sujithf1dc5602008-10-29 10:16:30 +05301166
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001167 /*
1168 * let mac dma reads be in 128 byte chunks
1169 */
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001170 REG_RMW(ah, AR_TXCFG, AR_TXCFG_DMASZ_128B, AR_TXCFG_DMASZ_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05301171
Sujith7d0d0df2010-04-16 11:53:57 +05301172 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301173
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001174 /*
1175 * Restore TX Trigger Level to its pre-reset value.
1176 * The initial value depends on whether aggregation is enabled, and is
1177 * adjusted whenever underruns are detected.
1178 */
Felix Fietkau57b32222010-04-15 17:39:22 -04001179 if (!AR_SREV_9300_20_OR_LATER(ah))
1180 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +05301181
Sujith7d0d0df2010-04-16 11:53:57 +05301182 ENABLE_REGWRITE_BUFFER(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301183
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001184 /*
1185 * let mac dma writes be in 128 byte chunks
1186 */
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001187 REG_RMW(ah, AR_RXCFG, AR_RXCFG_DMASZ_128B, AR_RXCFG_DMASZ_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05301188
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001189 /*
1190 * Setup receive FIFO threshold to hold off TX activities
1191 */
Sujithf1dc5602008-10-29 10:16:30 +05301192 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1193
Felix Fietkau57b32222010-04-15 17:39:22 -04001194 if (AR_SREV_9300_20_OR_LATER(ah)) {
1195 REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_HP, 0x1);
1196 REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_LP, 0x1);
1197
1198 ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize -
1199 ah->caps.rx_status_len);
1200 }
1201
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001202 /*
1203 * reduce the number of usable entries in PCU TXBUF to avoid
1204 * wrap around issues.
1205 */
Sujithf1dc5602008-10-29 10:16:30 +05301206 if (AR_SREV_9285(ah)) {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001207 /* For AR9285 the number of Fifos are reduced to half.
1208 * So set the usable tx buf size also to half to
1209 * avoid data/delimiter underruns
1210 */
Sujithf1dc5602008-10-29 10:16:30 +05301211 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1212 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001213 } else if (!AR_SREV_9271(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +05301214 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1215 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1216 }
Vasanthakumar Thiagarajan744d4022010-04-15 17:39:27 -04001217
Sujith7d0d0df2010-04-16 11:53:57 +05301218 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301219
Vasanthakumar Thiagarajan744d4022010-04-15 17:39:27 -04001220 if (AR_SREV_9300_20_OR_LATER(ah))
1221 ath9k_hw_reset_txstatus_ring(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301222}
1223
Sujithcbe61d82009-02-09 13:27:12 +05301224static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301225{
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001226 u32 mask = AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC;
1227 u32 set = AR_STA_ID1_KSRCH_MODE;
Sujithf1dc5602008-10-29 10:16:30 +05301228
Sujithf1dc5602008-10-29 10:16:30 +05301229 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001230 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04001231 case NL80211_IFTYPE_MESH_POINT:
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001232 set |= AR_STA_ID1_ADHOC;
Sujithf1dc5602008-10-29 10:16:30 +05301233 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1234 break;
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001235 case NL80211_IFTYPE_AP:
1236 set |= AR_STA_ID1_STA_AP;
1237 /* fall through */
Colin McCabed97809d2008-12-01 13:38:55 -08001238 case NL80211_IFTYPE_STATION:
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001239 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
Sujithf1dc5602008-10-29 10:16:30 +05301240 break;
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +05301241 default:
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001242 if (!ah->is_monitoring)
1243 set = 0;
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +05301244 break;
Sujithf1dc5602008-10-29 10:16:30 +05301245 }
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001246 REG_RMW(ah, AR_STA_ID1, set, mask);
Sujithf1dc5602008-10-29 10:16:30 +05301247}
1248
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001249void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled,
1250 u32 *coef_mantissa, u32 *coef_exponent)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001251{
1252 u32 coef_exp, coef_man;
1253
1254 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1255 if ((coef_scaled >> coef_exp) & 0x1)
1256 break;
1257
1258 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1259
1260 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1261
1262 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1263 *coef_exponent = coef_exp - 16;
1264}
1265
Sujithcbe61d82009-02-09 13:27:12 +05301266static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +05301267{
1268 u32 rst_flags;
1269 u32 tmpReg;
1270
Sujith70768492009-02-16 13:23:12 +05301271 if (AR_SREV_9100(ah)) {
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001272 REG_RMW_FIELD(ah, AR_RTC_DERIVED_CLK,
1273 AR_RTC_DERIVED_CLK_PERIOD, 1);
Sujith70768492009-02-16 13:23:12 +05301274 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1275 }
1276
Sujith7d0d0df2010-04-16 11:53:57 +05301277 ENABLE_REGWRITE_BUFFER(ah);
1278
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04001279 if (AR_SREV_9300_20_OR_LATER(ah)) {
1280 REG_WRITE(ah, AR_WA, ah->WARegVal);
1281 udelay(10);
1282 }
1283
Sujithf1dc5602008-10-29 10:16:30 +05301284 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1285 AR_RTC_FORCE_WAKE_ON_INT);
1286
1287 if (AR_SREV_9100(ah)) {
1288 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1289 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1290 } else {
1291 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1292 if (tmpReg &
1293 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1294 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001295 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05301296 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001297
1298 val = AR_RC_HOSTIF;
1299 if (!AR_SREV_9300_20_OR_LATER(ah))
1300 val |= AR_RC_AHB;
1301 REG_WRITE(ah, AR_RC, val);
1302
1303 } else if (!AR_SREV_9300_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05301304 REG_WRITE(ah, AR_RC, AR_RC_AHB);
Sujithf1dc5602008-10-29 10:16:30 +05301305
1306 rst_flags = AR_RTC_RC_MAC_WARM;
1307 if (type == ATH9K_RESET_COLD)
1308 rst_flags |= AR_RTC_RC_MAC_COLD;
1309 }
1310
Gabor Juhos7d95847c2011-06-21 11:23:51 +02001311 if (AR_SREV_9330(ah)) {
1312 int npend = 0;
1313 int i;
1314
1315 /* AR9330 WAR:
1316 * call external reset function to reset WMAC if:
1317 * - doing a cold reset
1318 * - we have pending frames in the TX queues
1319 */
1320
1321 for (i = 0; i < AR_NUM_QCU; i++) {
1322 npend = ath9k_hw_numtxpending(ah, i);
1323 if (npend)
1324 break;
1325 }
1326
1327 if (ah->external_reset &&
1328 (npend || type == ATH9K_RESET_COLD)) {
1329 int reset_err = 0;
1330
Joe Perchesd2182b62011-12-15 14:55:53 -08001331 ath_dbg(ath9k_hw_common(ah), RESET,
Gabor Juhos7d95847c2011-06-21 11:23:51 +02001332 "reset MAC via external reset\n");
1333
1334 reset_err = ah->external_reset();
1335 if (reset_err) {
1336 ath_err(ath9k_hw_common(ah),
1337 "External reset failed, err=%d\n",
1338 reset_err);
1339 return false;
1340 }
1341
1342 REG_WRITE(ah, AR_RTC_RESET, 1);
1343 }
1344 }
1345
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001346 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujith7d0d0df2010-04-16 11:53:57 +05301347
1348 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301349
Sujithf1dc5602008-10-29 10:16:30 +05301350 udelay(50);
1351
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001352 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301353 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001354 ath_dbg(ath9k_hw_common(ah), RESET, "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301355 return false;
1356 }
1357
1358 if (!AR_SREV_9100(ah))
1359 REG_WRITE(ah, AR_RC, 0);
1360
Sujithf1dc5602008-10-29 10:16:30 +05301361 if (AR_SREV_9100(ah))
1362 udelay(50);
1363
1364 return true;
1365}
1366
Sujithcbe61d82009-02-09 13:27:12 +05301367static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301368{
Sujith7d0d0df2010-04-16 11:53:57 +05301369 ENABLE_REGWRITE_BUFFER(ah);
1370
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04001371 if (AR_SREV_9300_20_OR_LATER(ah)) {
1372 REG_WRITE(ah, AR_WA, ah->WARegVal);
1373 udelay(10);
1374 }
1375
Sujithf1dc5602008-10-29 10:16:30 +05301376 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1377 AR_RTC_FORCE_WAKE_ON_INT);
1378
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001379 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301380 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1381
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001382 REG_WRITE(ah, AR_RTC_RESET, 0);
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301383
Sujith7d0d0df2010-04-16 11:53:57 +05301384 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301385
Senthil Balasubramanian84e21692010-04-15 17:38:30 -04001386 if (!AR_SREV_9300_20_OR_LATER(ah))
1387 udelay(2);
1388
1389 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301390 REG_WRITE(ah, AR_RC, 0);
1391
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001392 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301393
1394 if (!ath9k_hw_wait(ah,
1395 AR_RTC_STATUS,
1396 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301397 AR_RTC_STATUS_ON,
1398 AH_WAIT_TIMEOUT)) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001399 ath_dbg(ath9k_hw_common(ah), RESET, "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301400 return false;
1401 }
1402
Sujithf1dc5602008-10-29 10:16:30 +05301403 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1404}
1405
Sujithcbe61d82009-02-09 13:27:12 +05301406static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301407{
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301408 bool ret = false;
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05301409
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04001410 if (AR_SREV_9300_20_OR_LATER(ah)) {
1411 REG_WRITE(ah, AR_WA, ah->WARegVal);
1412 udelay(10);
1413 }
1414
Sujithf1dc5602008-10-29 10:16:30 +05301415 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1416 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1417
1418 switch (type) {
1419 case ATH9K_RESET_POWER_ON:
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301420 ret = ath9k_hw_set_reset_power_on(ah);
1421 break;
Sujithf1dc5602008-10-29 10:16:30 +05301422 case ATH9K_RESET_WARM:
1423 case ATH9K_RESET_COLD:
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301424 ret = ath9k_hw_set_reset(ah, type);
1425 break;
Sujithf1dc5602008-10-29 10:16:30 +05301426 default:
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301427 break;
Sujithf1dc5602008-10-29 10:16:30 +05301428 }
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301429
1430 if (ah->caps.hw_caps & ATH9K_HW_CAP_MCI)
1431 REG_WRITE(ah, AR_RTC_KEEP_AWAKE, 0x2);
1432
1433 return ret;
Sujithf1dc5602008-10-29 10:16:30 +05301434}
1435
Sujithcbe61d82009-02-09 13:27:12 +05301436static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301437 struct ath9k_channel *chan)
1438{
Felix Fietkau9c083af2012-03-03 15:17:02 +01001439 int reset_type = ATH9K_RESET_WARM;
1440
1441 if (AR_SREV_9280(ah)) {
1442 if (ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1443 reset_type = ATH9K_RESET_POWER_ON;
1444 else
1445 reset_type = ATH9K_RESET_COLD;
1446 }
1447
1448 if (!ath9k_hw_set_reset_reg(ah, reset_type))
Sujithf1dc5602008-10-29 10:16:30 +05301449 return false;
1450
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001451 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05301452 return false;
1453
Sujith2660b812009-02-09 13:27:26 +05301454 ah->chip_fullsleep = false;
Sujithf1dc5602008-10-29 10:16:30 +05301455 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301456 ath9k_hw_set_rfmode(ah, chan);
1457
1458 return true;
1459}
1460
Sujithcbe61d82009-02-09 13:27:12 +05301461static bool ath9k_hw_channel_change(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001462 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301463{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001464 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001465 u32 qnum;
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001466 int r;
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301467 bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
1468 bool band_switch, mode_diff;
1469 u8 ini_reloaded;
1470
1471 band_switch = (chan->channelFlags & (CHANNEL_2GHZ | CHANNEL_5GHZ)) !=
1472 (ah->curchan->channelFlags & (CHANNEL_2GHZ |
1473 CHANNEL_5GHZ));
1474 mode_diff = (chan->chanmode != ah->curchan->chanmode);
Sujithf1dc5602008-10-29 10:16:30 +05301475
1476 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1477 if (ath9k_hw_numtxpending(ah, qnum)) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001478 ath_dbg(common, QUEUE,
Joe Perches226afe62010-12-02 19:12:37 -08001479 "Transmit frames pending on queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301480 return false;
1481 }
1482 }
1483
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001484 if (!ath9k_hw_rfbus_req(ah)) {
Joe Perches38002762010-12-02 19:12:36 -08001485 ath_err(common, "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301486 return false;
1487 }
1488
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301489 if (edma && (band_switch || mode_diff)) {
1490 ath9k_hw_mark_phy_inactive(ah);
1491 udelay(5);
1492
1493 ath9k_hw_init_pll(ah, NULL);
1494
1495 if (ath9k_hw_fast_chan_change(ah, chan, &ini_reloaded)) {
1496 ath_err(common, "Failed to do fast channel change\n");
1497 return false;
1498 }
1499 }
1500
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001501 ath9k_hw_set_channel_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301502
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001503 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001504 if (r) {
Joe Perches38002762010-12-02 19:12:36 -08001505 ath_err(common, "Failed to set channel\n");
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001506 return false;
Sujithf1dc5602008-10-29 10:16:30 +05301507 }
Felix Fietkaudfdac8a2010-10-08 22:13:51 +02001508 ath9k_hw_set_clockrate(ah);
Felix Fietkauca2c68c2011-10-08 20:06:20 +02001509 ath9k_hw_apply_txpower(ah, chan);
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001510 ath9k_hw_rfbus_done(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301511
1512 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1513 ath9k_hw_set_delta_slope(ah, chan);
1514
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001515 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301516
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301517 if (edma && (band_switch || mode_diff)) {
Rajkumar Manoharana126ff52011-10-13 11:00:42 +05301518 ah->ah_flags |= AH_FASTCC;
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301519 if (band_switch || ini_reloaded)
1520 ah->eep_ops->set_board_values(ah, chan);
1521
1522 ath9k_hw_init_bb(ah, chan);
1523
1524 if (band_switch || ini_reloaded)
1525 ath9k_hw_init_cal(ah, chan);
Rajkumar Manoharana126ff52011-10-13 11:00:42 +05301526 ah->ah_flags &= ~AH_FASTCC;
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301527 }
1528
Sujithf1dc5602008-10-29 10:16:30 +05301529 return true;
1530}
1531
Felix Fietkau691680b2011-03-19 13:55:38 +01001532static void ath9k_hw_apply_gpio_override(struct ath_hw *ah)
1533{
1534 u32 gpio_mask = ah->gpio_mask;
1535 int i;
1536
1537 for (i = 0; gpio_mask; i++, gpio_mask >>= 1) {
1538 if (!(gpio_mask & 1))
1539 continue;
1540
1541 ath9k_hw_cfg_output(ah, i, AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1542 ath9k_hw_set_gpio(ah, i, !!(ah->gpio_val & BIT(i)));
1543 }
1544}
1545
Rajkumar Manoharan01e18912012-03-15 05:34:27 +05301546static bool ath9k_hw_check_dcs(u32 dma_dbg, u32 num_dcu_states,
1547 int *hang_state, int *hang_pos)
1548{
1549 static u32 dcu_chain_state[] = {5, 6, 9}; /* DCU chain stuck states */
1550 u32 chain_state, dcs_pos, i;
1551
1552 for (dcs_pos = 0; dcs_pos < num_dcu_states; dcs_pos++) {
1553 chain_state = (dma_dbg >> (5 * dcs_pos)) & 0x1f;
1554 for (i = 0; i < 3; i++) {
1555 if (chain_state == dcu_chain_state[i]) {
1556 *hang_state = chain_state;
1557 *hang_pos = dcs_pos;
1558 return true;
1559 }
1560 }
1561 }
1562 return false;
1563}
1564
1565#define DCU_COMPLETE_STATE 1
1566#define DCU_COMPLETE_STATE_MASK 0x3
1567#define NUM_STATUS_READS 50
1568static bool ath9k_hw_detect_mac_hang(struct ath_hw *ah)
1569{
1570 u32 chain_state, comp_state, dcs_reg = AR_DMADBG_4;
1571 u32 i, hang_pos, hang_state, num_state = 6;
1572
1573 comp_state = REG_READ(ah, AR_DMADBG_6);
1574
1575 if ((comp_state & DCU_COMPLETE_STATE_MASK) != DCU_COMPLETE_STATE) {
1576 ath_dbg(ath9k_hw_common(ah), RESET,
1577 "MAC Hang signature not found at DCU complete\n");
1578 return false;
1579 }
1580
1581 chain_state = REG_READ(ah, dcs_reg);
1582 if (ath9k_hw_check_dcs(chain_state, num_state, &hang_state, &hang_pos))
1583 goto hang_check_iter;
1584
1585 dcs_reg = AR_DMADBG_5;
1586 num_state = 4;
1587 chain_state = REG_READ(ah, dcs_reg);
1588 if (ath9k_hw_check_dcs(chain_state, num_state, &hang_state, &hang_pos))
1589 goto hang_check_iter;
1590
1591 ath_dbg(ath9k_hw_common(ah), RESET,
1592 "MAC Hang signature 1 not found\n");
1593 return false;
1594
1595hang_check_iter:
1596 ath_dbg(ath9k_hw_common(ah), RESET,
1597 "DCU registers: chain %08x complete %08x Hang: state %d pos %d\n",
1598 chain_state, comp_state, hang_state, hang_pos);
1599
1600 for (i = 0; i < NUM_STATUS_READS; i++) {
1601 chain_state = REG_READ(ah, dcs_reg);
1602 chain_state = (chain_state >> (5 * hang_pos)) & 0x1f;
1603 comp_state = REG_READ(ah, AR_DMADBG_6);
1604
1605 if (((comp_state & DCU_COMPLETE_STATE_MASK) !=
1606 DCU_COMPLETE_STATE) ||
1607 (chain_state != hang_state))
1608 return false;
1609 }
1610
1611 ath_dbg(ath9k_hw_common(ah), RESET, "MAC Hang signature 1 found\n");
1612
1613 return true;
1614}
1615
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001616bool ath9k_hw_check_alive(struct ath_hw *ah)
Johannes Berg3b319aa2009-06-13 14:50:26 +05301617{
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001618 int count = 50;
1619 u32 reg;
Johannes Berg3b319aa2009-06-13 14:50:26 +05301620
Rajkumar Manoharan01e18912012-03-15 05:34:27 +05301621 if (AR_SREV_9300(ah))
1622 return !ath9k_hw_detect_mac_hang(ah);
1623
Felix Fietkaue17f83e2010-09-22 12:34:53 +02001624 if (AR_SREV_9285_12_OR_LATER(ah))
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001625 return true;
Johannes Berg3b319aa2009-06-13 14:50:26 +05301626
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001627 do {
1628 reg = REG_READ(ah, AR_OBS_BUS_1);
1629
1630 if ((reg & 0x7E7FFFEF) == 0x00702400)
1631 continue;
1632
1633 switch (reg & 0x7E000B00) {
1634 case 0x1E000000:
1635 case 0x52000B00:
1636 case 0x18000B00:
1637 continue;
1638 default:
1639 return true;
1640 }
1641 } while (count-- > 0);
1642
1643 return false;
Johannes Berg3b319aa2009-06-13 14:50:26 +05301644}
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001645EXPORT_SYMBOL(ath9k_hw_check_alive);
Johannes Berg3b319aa2009-06-13 14:50:26 +05301646
Sujith Manoharancaed6572012-03-14 14:40:46 +05301647/*
1648 * Fast channel change:
1649 * (Change synthesizer based on channel freq without resetting chip)
1650 *
1651 * Don't do FCC when
1652 * - Flag is not set
1653 * - Chip is just coming out of full sleep
1654 * - Channel to be set is same as current channel
1655 * - Channel flags are different, (eg.,moving from 2GHz to 5GHz channel)
1656 */
1657static int ath9k_hw_do_fastcc(struct ath_hw *ah, struct ath9k_channel *chan)
1658{
1659 struct ath_common *common = ath9k_hw_common(ah);
1660 int ret;
1661
1662 if (AR_SREV_9280(ah) && common->bus_ops->ath_bus_type == ATH_PCI)
1663 goto fail;
1664
1665 if (ah->chip_fullsleep)
1666 goto fail;
1667
1668 if (!ah->curchan)
1669 goto fail;
1670
1671 if (chan->channel == ah->curchan->channel)
1672 goto fail;
1673
1674 if ((chan->channelFlags & CHANNEL_ALL) !=
1675 (ah->curchan->channelFlags & CHANNEL_ALL))
1676 goto fail;
1677
1678 if (!ath9k_hw_check_alive(ah))
1679 goto fail;
1680
1681 /*
1682 * For AR9462, make sure that calibration data for
1683 * re-using are present.
1684 */
1685 if (AR_SREV_9462(ah) && (!ah->caldata ||
1686 !ah->caldata->done_txiqcal_once ||
1687 !ah->caldata->done_txclcal_once ||
1688 !ah->caldata->rtt_hist.num_readings))
1689 goto fail;
1690
1691 ath_dbg(common, RESET, "FastChannelChange for %d -> %d\n",
1692 ah->curchan->channel, chan->channel);
1693
1694 ret = ath9k_hw_channel_change(ah, chan);
1695 if (!ret)
1696 goto fail;
1697
1698 ath9k_hw_loadnf(ah, ah->curchan);
1699 ath9k_hw_start_nfcal(ah, true);
1700
1701 if ((ah->caps.hw_caps & ATH9K_HW_CAP_MCI) && ar9003_mci_is_ready(ah))
1702 ar9003_mci_2g5g_switch(ah, true);
1703
1704 if (AR_SREV_9271(ah))
1705 ar9002_hw_load_ani_reg(ah, chan);
1706
1707 return 0;
1708fail:
1709 return -EINVAL;
1710}
1711
Sujithcbe61d82009-02-09 13:27:12 +05301712int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Sujith Manoharancaed6572012-03-14 14:40:46 +05301713 struct ath9k_hw_cal_data *caldata, bool fastcc)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001714{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001715 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001716 u32 saveLedState;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001717 u32 saveDefAntenna;
1718 u32 macStaId1;
Sujith46fe7822009-09-17 09:25:25 +05301719 u64 tsf = 0;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001720 int i, r;
Sujith Manoharancaed6572012-03-14 14:40:46 +05301721 bool start_mci_reset = false;
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301722 bool mci = !!(ah->caps.hw_caps & ATH9K_HW_CAP_MCI);
1723 bool save_fullsleep = ah->chip_fullsleep;
1724
1725 if (mci) {
Sujith Manoharan528e5d32012-02-22 12:41:12 +05301726 start_mci_reset = ar9003_mci_start_reset(ah, chan);
1727 if (start_mci_reset)
1728 return 0;
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301729 }
1730
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001731 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001732 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001733
Sujith Manoharancaed6572012-03-14 14:40:46 +05301734 if (ah->curchan && !ah->chip_fullsleep)
1735 ath9k_hw_getnf(ah, ah->curchan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001736
Felix Fietkau20bd2a02010-07-31 00:12:00 +02001737 ah->caldata = caldata;
1738 if (caldata &&
1739 (chan->channel != caldata->channel ||
1740 (chan->channelFlags & ~CHANNEL_CW_INT) !=
1741 (caldata->channelFlags & ~CHANNEL_CW_INT))) {
1742 /* Operating channel changed, reset channel calibration data */
1743 memset(caldata, 0, sizeof(*caldata));
1744 ath9k_init_nfcal_hist_buffer(ah, chan);
1745 }
Felix Fietkauf23fba42011-07-28 14:08:56 +02001746 ah->noise = ath9k_hw_getchan_noise(ah, chan);
Felix Fietkau20bd2a02010-07-31 00:12:00 +02001747
Sujith Manoharancaed6572012-03-14 14:40:46 +05301748 if (fastcc) {
1749 r = ath9k_hw_do_fastcc(ah, chan);
1750 if (!r)
1751 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001752 }
1753
Sujith Manoharan528e5d32012-02-22 12:41:12 +05301754 if (mci)
1755 ar9003_mci_stop_bt(ah, save_fullsleep);
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301756
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001757 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
1758 if (saveDefAntenna == 0)
1759 saveDefAntenna = 1;
1760
1761 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
1762
Sujith46fe7822009-09-17 09:25:25 +05301763 /* For chips on which RTC reset is done, save TSF before it gets cleared */
Felix Fietkauf860d522010-06-30 02:07:48 +02001764 if (AR_SREV_9100(ah) ||
1765 (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)))
Sujith46fe7822009-09-17 09:25:25 +05301766 tsf = ath9k_hw_gettsf64(ah);
1767
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001768 saveLedState = REG_READ(ah, AR_CFG_LED) &
1769 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
1770 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
1771
1772 ath9k_hw_mark_phy_inactive(ah);
1773
Vasanthakumar Thiagarajan45ef6a02010-12-15 07:30:53 -08001774 ah->paprd_table_write_done = false;
1775
Sujith05020d22010-03-17 14:25:23 +05301776 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001777 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1778 REG_WRITE(ah,
1779 AR9271_RESET_POWER_DOWN_CONTROL,
1780 AR9271_RADIO_RF_RST);
1781 udelay(50);
1782 }
1783
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001784 if (!ath9k_hw_chip_reset(ah, chan)) {
Joe Perches38002762010-12-02 19:12:36 -08001785 ath_err(common, "Chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001786 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001787 }
1788
Sujith05020d22010-03-17 14:25:23 +05301789 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001790 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1791 ah->htc_reset_init = false;
1792 REG_WRITE(ah,
1793 AR9271_RESET_POWER_DOWN_CONTROL,
1794 AR9271_GATE_MAC_CTL);
1795 udelay(50);
1796 }
1797
Sujith46fe7822009-09-17 09:25:25 +05301798 /* Restore TSF */
Felix Fietkauf860d522010-06-30 02:07:48 +02001799 if (tsf)
Sujith46fe7822009-09-17 09:25:25 +05301800 ath9k_hw_settsf64(ah, tsf);
1801
Felix Fietkau7a370812010-09-22 12:34:52 +02001802 if (AR_SREV_9280_20_OR_LATER(ah))
Vasanthakumar Thiagarajan369391d2009-01-21 19:24:13 +05301803 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001804
Sujithe9141f72010-06-01 15:14:10 +05301805 if (!AR_SREV_9300_20_OR_LATER(ah))
1806 ar9002_hw_enable_async_fifo(ah);
1807
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001808 r = ath9k_hw_process_ini(ah, chan);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001809 if (r)
1810 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001811
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301812 if (mci)
1813 ar9003_mci_reset(ah, false, IS_CHAN_2GHZ(chan), save_fullsleep);
1814
Felix Fietkauf860d522010-06-30 02:07:48 +02001815 /*
1816 * Some AR91xx SoC devices frequently fail to accept TSF writes
1817 * right after the chip reset. When that happens, write a new
1818 * value after the initvals have been applied, with an offset
1819 * based on measured time difference
1820 */
1821 if (AR_SREV_9100(ah) && (ath9k_hw_gettsf64(ah) < tsf)) {
1822 tsf += 1500;
1823 ath9k_hw_settsf64(ah, tsf);
1824 }
1825
Jouni Malinen0ced0e12009-01-08 13:32:13 +02001826 /* Setup MFP options for CCMP */
1827 if (AR_SREV_9280_20_OR_LATER(ah)) {
1828 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
1829 * frames when constructing CCMP AAD. */
1830 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
1831 0xc7ff);
1832 ah->sw_mgmt_crypto = false;
1833 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1834 /* Disable hardware crypto for management frames */
1835 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
1836 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
1837 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1838 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
1839 ah->sw_mgmt_crypto = true;
1840 } else
1841 ah->sw_mgmt_crypto = true;
1842
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001843 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1844 ath9k_hw_set_delta_slope(ah, chan);
1845
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001846 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithd6509152009-03-13 08:56:05 +05301847 ah->eep_ops->set_board_values(ah, chan);
Luis R. Rodrigueza7765822009-10-19 02:33:45 -04001848
Sujith7d0d0df2010-04-16 11:53:57 +05301849 ENABLE_REGWRITE_BUFFER(ah);
1850
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001851 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
1852 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001853 | macStaId1
1854 | AR_STA_ID1_RTS_USE_DEF
Sujith2660b812009-02-09 13:27:26 +05301855 | (ah->config.
Sujith60b67f52008-08-07 10:52:38 +05301856 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Sujith2660b812009-02-09 13:27:26 +05301857 | ah->sta_id1_defaults);
Luis R. Rodriguez13b81552009-09-10 17:52:45 -07001858 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001859 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
Luis R. Rodriguez3453ad82009-09-10 08:57:00 -07001860 ath9k_hw_write_associd(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001861 REG_WRITE(ah, AR_ISR, ~0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001862 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
1863
Sujith7d0d0df2010-04-16 11:53:57 +05301864 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301865
Sujith Manoharan00e00032011-01-26 21:59:05 +05301866 ath9k_hw_set_operating_mode(ah, ah->opmode);
1867
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001868 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001869 if (r)
1870 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001871
Felix Fietkaudfdac8a2010-10-08 22:13:51 +02001872 ath9k_hw_set_clockrate(ah);
1873
Sujith7d0d0df2010-04-16 11:53:57 +05301874 ENABLE_REGWRITE_BUFFER(ah);
1875
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001876 for (i = 0; i < AR_NUM_DCU; i++)
1877 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
1878
Sujith7d0d0df2010-04-16 11:53:57 +05301879 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301880
Sujith2660b812009-02-09 13:27:26 +05301881 ah->intr_txqs = 0;
Felix Fietkauf4c607d2011-03-23 20:57:28 +01001882 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001883 ath9k_hw_resettxqueue(ah, i);
1884
Sujith2660b812009-02-09 13:27:26 +05301885 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001886 ath9k_hw_ani_cache_ini_regs(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001887 ath9k_hw_init_qos(ah);
1888
Sujith2660b812009-02-09 13:27:26 +05301889 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Felix Fietkau55821322010-12-17 00:57:01 +01001890 ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
Johannes Berg3b319aa2009-06-13 14:50:26 +05301891
Felix Fietkau0005baf2010-01-15 02:33:40 +01001892 ath9k_hw_init_global_settings(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001893
Felix Fietkaufe2b6af2011-07-09 11:12:51 +07001894 if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah)) {
1895 REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
1896 AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
1897 REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
1898 AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
1899 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1900 AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301901 }
1902
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001903 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PRESERVE_SEQNUM);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001904
1905 ath9k_hw_set_dma(ah);
1906
1907 REG_WRITE(ah, AR_OBS, 8);
1908
Sujith0ce024c2009-12-14 14:57:00 +05301909 if (ah->config.rx_intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001910 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
1911 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
1912 }
1913
Vasanthakumar Thiagarajan7f62a132010-04-15 17:39:19 -04001914 if (ah->config.tx_intr_mitigation) {
1915 REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_LAST, 300);
1916 REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_FIRST, 750);
1917 }
1918
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001919 ath9k_hw_init_bb(ah, chan);
1920
Rajkumar Manoharan77a5a662011-10-13 11:00:37 +05301921 if (caldata) {
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301922 caldata->done_txiqcal_once = false;
Rajkumar Manoharan77a5a662011-10-13 11:00:37 +05301923 caldata->done_txclcal_once = false;
Rajkumar Manoharan324c74a2011-10-13 11:00:41 +05301924 caldata->rtt_hist.num_readings = 0;
Rajkumar Manoharan77a5a662011-10-13 11:00:37 +05301925 }
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001926 if (!ath9k_hw_init_cal(ah, chan))
Joe Perches6badaaf2009-06-28 09:26:32 -07001927 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001928
Rajkumar Manoharan93348922011-10-25 16:47:36 +05301929 ath9k_hw_loadnf(ah, chan);
1930 ath9k_hw_start_nfcal(ah, true);
1931
Sujith Manoharan528e5d32012-02-22 12:41:12 +05301932 if (mci && ar9003_mci_end_reset(ah, chan, caldata))
1933 return -EIO;
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301934
Sujith7d0d0df2010-04-16 11:53:57 +05301935 ENABLE_REGWRITE_BUFFER(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001936
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001937 ath9k_hw_restore_chainmask(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001938 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
1939
Sujith7d0d0df2010-04-16 11:53:57 +05301940 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301941
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001942 /*
1943 * For big endian systems turn on swapping for descriptors
1944 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001945 if (AR_SREV_9100(ah)) {
1946 u32 mask;
1947 mask = REG_READ(ah, AR_CFG);
1948 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001949 ath_dbg(common, RESET, "CFG Byte Swap Set 0x%x\n",
1950 mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001951 } else {
1952 mask =
1953 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
1954 REG_WRITE(ah, AR_CFG, mask);
Joe Perchesd2182b62011-12-15 14:55:53 -08001955 ath_dbg(common, RESET, "Setting CFG 0x%x\n",
1956 REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001957 }
1958 } else {
Sujithcbba8cd2010-06-02 15:53:31 +05301959 if (common->bus_ops->ath_bus_type == ATH_USB) {
1960 /* Configure AR9271 target WLAN */
1961 if (AR_SREV_9271(ah))
1962 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
1963 else
1964 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
1965 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001966#ifdef __BIG_ENDIAN
Gabor Juhos4033bda2011-06-21 11:23:35 +02001967 else if (AR_SREV_9330(ah) || AR_SREV_9340(ah))
Vasanthakumar Thiagarajan2be7bfe2011-04-19 19:29:14 +05301968 REG_RMW(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB, 0);
1969 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001970 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001971#endif
1972 }
1973
Sujith Manoharandbccdd12012-02-22 17:55:47 +05301974 if (ath9k_hw_btcoex_is_enabled(ah))
Vasanthakumar Thiagarajan42cc41e2009-08-26 21:08:45 +05301975 ath9k_hw_btcoex_enable(ah);
1976
Sujith Manoharan528e5d32012-02-22 12:41:12 +05301977 if (mci)
1978 ar9003_mci_check_bt(ah);
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301979
Rajkumar Manoharan51ac8cb2011-05-20 17:52:13 +05301980 if (AR_SREV_9300_20_OR_LATER(ah)) {
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04001981 ar9003_hw_bb_watchdog_config(ah);
Vasanthakumar Thiagarajand8903a52010-04-15 17:39:25 -04001982
Rajkumar Manoharan51ac8cb2011-05-20 17:52:13 +05301983 ar9003_hw_disable_phy_restart(ah);
1984 }
1985
Felix Fietkau691680b2011-03-19 13:55:38 +01001986 ath9k_hw_apply_gpio_override(ah);
1987
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001988 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001989}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001990EXPORT_SYMBOL(ath9k_hw_reset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001991
Sujithf1dc5602008-10-29 10:16:30 +05301992/******************************/
1993/* Power Management (Chipset) */
1994/******************************/
1995
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001996/*
1997 * Notify Power Mgt is disabled in self-generated frames.
1998 * If requested, force chip to sleep.
1999 */
Sujithcbe61d82009-02-09 13:27:12 +05302000static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302001{
2002 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2003 if (setChip) {
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05302004 if (AR_SREV_9462(ah)) {
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302005 REG_WRITE(ah, AR_TIMER_MODE,
2006 REG_READ(ah, AR_TIMER_MODE) & 0xFFFFFF00);
2007 REG_WRITE(ah, AR_NDP2_TIMER_MODE, REG_READ(ah,
2008 AR_NDP2_TIMER_MODE) & 0xFFFFFF00);
2009 REG_WRITE(ah, AR_SLP32_INC,
2010 REG_READ(ah, AR_SLP32_INC) & 0xFFF00000);
2011 /* xxx Required for WLAN only case ? */
2012 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_EN, 0);
2013 udelay(100);
2014 }
2015
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04002016 /*
2017 * Clear the RTC force wake bit to allow the
2018 * mac to go to sleep.
2019 */
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302020 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN);
2021
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05302022 if (AR_SREV_9462(ah))
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302023 udelay(100);
2024
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04002025 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302026 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
2027
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04002028 /* Shutdown chip. Active low */
Sujith Manoharanc91ec462012-02-22 12:40:03 +05302029 if (!AR_SREV_5416(ah) && !AR_SREV_9271(ah)) {
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302030 REG_CLR_BIT(ah, AR_RTC_RESET, AR_RTC_RESET_EN);
2031 udelay(2);
2032 }
Sujithf1dc5602008-10-29 10:16:30 +05302033 }
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04002034
2035 /* Clear Bit 14 of AR_WA after putting chip into Full Sleep mode. */
Rafael J. Wysockia7322812011-11-26 23:37:43 +01002036 if (AR_SREV_9300_20_OR_LATER(ah))
2037 REG_WRITE(ah, AR_WA, ah->WARegVal & ~AR_WA_D3_L1_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002038}
2039
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04002040/*
2041 * Notify Power Management is enabled in self-generating
2042 * frames. If request, set power mode of chip to
2043 * auto/normal. Duration in units of 128us (1/8 TU).
2044 */
Sujithcbe61d82009-02-09 13:27:12 +05302045static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002046{
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302047 u32 val;
2048
Sujithf1dc5602008-10-29 10:16:30 +05302049 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2050 if (setChip) {
Sujith2660b812009-02-09 13:27:26 +05302051 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002052
Sujithf1dc5602008-10-29 10:16:30 +05302053 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04002054 /* Set WakeOnInterrupt bit; clear ForceWake bit */
Sujithf1dc5602008-10-29 10:16:30 +05302055 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2056 AR_RTC_FORCE_WAKE_ON_INT);
2057 } else {
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302058
2059 /* When chip goes into network sleep, it could be waken
2060 * up by MCI_INT interrupt caused by BT's HW messages
2061 * (LNA_xxx, CONT_xxx) which chould be in a very fast
2062 * rate (~100us). This will cause chip to leave and
2063 * re-enter network sleep mode frequently, which in
2064 * consequence will have WLAN MCI HW to generate lots of
2065 * SYS_WAKING and SYS_SLEEPING messages which will make
2066 * BT CPU to busy to process.
2067 */
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05302068 if (AR_SREV_9462(ah)) {
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302069 val = REG_READ(ah, AR_MCI_INTERRUPT_RX_MSG_EN) &
2070 ~AR_MCI_INTERRUPT_RX_HW_MSG_MASK;
2071 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_EN, val);
2072 }
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04002073 /*
2074 * Clear the RTC force wake bit to allow the
2075 * mac to go to sleep.
2076 */
Sujithf1dc5602008-10-29 10:16:30 +05302077 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2078 AR_RTC_FORCE_WAKE_EN);
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302079
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05302080 if (AR_SREV_9462(ah))
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302081 udelay(30);
Sujithf1dc5602008-10-29 10:16:30 +05302082 }
2083 }
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04002084
2085 /* Clear Bit 14 of AR_WA after putting chip into Net Sleep mode. */
2086 if (AR_SREV_9300_20_OR_LATER(ah))
2087 REG_WRITE(ah, AR_WA, ah->WARegVal & ~AR_WA_D3_L1_DISABLE);
Sujithf1dc5602008-10-29 10:16:30 +05302088}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002089
Sujithcbe61d82009-02-09 13:27:12 +05302090static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302091{
2092 u32 val;
2093 int i;
2094
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04002095 /* Set Bits 14 and 17 of AR_WA before powering on the chip. */
2096 if (AR_SREV_9300_20_OR_LATER(ah)) {
2097 REG_WRITE(ah, AR_WA, ah->WARegVal);
2098 udelay(10);
2099 }
2100
Sujithf1dc5602008-10-29 10:16:30 +05302101 if (setChip) {
2102 if ((REG_READ(ah, AR_RTC_STATUS) &
2103 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
Joe Perches23677ce2012-02-09 11:17:23 +00002104 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Sujithf1dc5602008-10-29 10:16:30 +05302105 return false;
2106 }
Luis R. Rodrigueze0412282010-04-15 17:38:15 -04002107 if (!AR_SREV_9300_20_OR_LATER(ah))
2108 ath9k_hw_init_pll(ah, NULL);
Sujithf1dc5602008-10-29 10:16:30 +05302109 }
2110 if (AR_SREV_9100(ah))
2111 REG_SET_BIT(ah, AR_RTC_RESET,
2112 AR_RTC_RESET_EN);
2113
2114 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2115 AR_RTC_FORCE_WAKE_EN);
2116 udelay(50);
2117
2118 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2119 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2120 if (val == AR_RTC_STATUS_ON)
2121 break;
2122 udelay(50);
2123 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2124 AR_RTC_FORCE_WAKE_EN);
2125 }
2126 if (i == 0) {
Joe Perches38002762010-12-02 19:12:36 -08002127 ath_err(ath9k_hw_common(ah),
2128 "Failed to wakeup in %uus\n",
2129 POWER_UP_TIME / 20);
Sujithf1dc5602008-10-29 10:16:30 +05302130 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002131 }
2132 }
2133
Sujithf1dc5602008-10-29 10:16:30 +05302134 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2135
2136 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002137}
2138
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002139bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05302140{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002141 struct ath_common *common = ath9k_hw_common(ah);
Sujithcbe61d82009-02-09 13:27:12 +05302142 int status = true, setChip = true;
Sujithf1dc5602008-10-29 10:16:30 +05302143 static const char *modes[] = {
2144 "AWAKE",
2145 "FULL-SLEEP",
2146 "NETWORK SLEEP",
2147 "UNDEFINED"
2148 };
Sujithf1dc5602008-10-29 10:16:30 +05302149
Gabor Juhoscbdec972009-07-24 17:27:22 +02002150 if (ah->power_mode == mode)
2151 return status;
2152
Joe Perchesd2182b62011-12-15 14:55:53 -08002153 ath_dbg(common, RESET, "%s -> %s\n",
Joe Perches226afe62010-12-02 19:12:37 -08002154 modes[ah->power_mode], modes[mode]);
Sujithf1dc5602008-10-29 10:16:30 +05302155
2156 switch (mode) {
2157 case ATH9K_PM_AWAKE:
2158 status = ath9k_hw_set_power_awake(ah, setChip);
Mohammed Shafi Shajakhan10109112011-11-30 10:41:24 +05302159
2160 if (ah->caps.hw_caps & ATH9K_HW_CAP_MCI)
2161 REG_WRITE(ah, AR_RTC_KEEP_AWAKE, 0x2);
2162
Sujithf1dc5602008-10-29 10:16:30 +05302163 break;
2164 case ATH9K_PM_FULL_SLEEP:
Sujith Manoharand1ca8b82012-02-22 12:41:01 +05302165 if (ah->caps.hw_caps & ATH9K_HW_CAP_MCI)
2166 ar9003_mci_set_full_sleep(ah);
Mohammed Shafi Shajakhan10109112011-11-30 10:41:24 +05302167
Sujithf1dc5602008-10-29 10:16:30 +05302168 ath9k_set_power_sleep(ah, setChip);
Sujith2660b812009-02-09 13:27:26 +05302169 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05302170 break;
2171 case ATH9K_PM_NETWORK_SLEEP:
Mohammed Shafi Shajakhan10109112011-11-30 10:41:24 +05302172
2173 if (ah->caps.hw_caps & ATH9K_HW_CAP_MCI)
2174 REG_WRITE(ah, AR_RTC_KEEP_AWAKE, 0x2);
2175
Sujithf1dc5602008-10-29 10:16:30 +05302176 ath9k_set_power_network_sleep(ah, setChip);
2177 break;
2178 default:
Joe Perches38002762010-12-02 19:12:36 -08002179 ath_err(common, "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05302180 return false;
2181 }
Sujith2660b812009-02-09 13:27:26 +05302182 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05302183
Luis R. Rodriguez69f4aab2010-12-07 15:13:23 -08002184 /*
2185 * XXX: If this warning never comes up after a while then
2186 * simply keep the ATH_DBG_WARN_ON_ONCE() but make
2187 * ath9k_hw_setpower() return type void.
2188 */
Sujith Manoharan97dcec52010-12-20 08:02:42 +05302189
2190 if (!(ah->ah_flags & AH_UNPLUGGED))
2191 ATH_DBG_WARN_ON_ONCE(!status);
Luis R. Rodriguez69f4aab2010-12-07 15:13:23 -08002192
Sujithf1dc5602008-10-29 10:16:30 +05302193 return status;
2194}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002195EXPORT_SYMBOL(ath9k_hw_setpower);
Sujithf1dc5602008-10-29 10:16:30 +05302196
Sujithf1dc5602008-10-29 10:16:30 +05302197/*******************/
2198/* Beacon Handling */
2199/*******************/
2200
Sujithcbe61d82009-02-09 13:27:12 +05302201void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002202{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002203 int flags = 0;
2204
Sujith7d0d0df2010-04-16 11:53:57 +05302205 ENABLE_REGWRITE_BUFFER(ah);
2206
Sujith2660b812009-02-09 13:27:26 +05302207 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08002208 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04002209 case NL80211_IFTYPE_MESH_POINT:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002210 REG_SET_BIT(ah, AR_TXCFG,
2211 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
Felix Fietkaudd347f22011-03-22 21:54:17 +01002212 REG_WRITE(ah, AR_NEXT_NDP_TIMER, next_beacon +
2213 TU_TO_USEC(ah->atim_window ? ah->atim_window : 1));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002214 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08002215 case NL80211_IFTYPE_AP:
Felix Fietkaudd347f22011-03-22 21:54:17 +01002216 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, next_beacon);
2217 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, next_beacon -
2218 TU_TO_USEC(ah->config.dma_beacon_response_time));
2219 REG_WRITE(ah, AR_NEXT_SWBA, next_beacon -
2220 TU_TO_USEC(ah->config.sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002221 flags |=
2222 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
2223 break;
Colin McCabed97809d2008-12-01 13:38:55 -08002224 default:
Joe Perchesd2182b62011-12-15 14:55:53 -08002225 ath_dbg(ath9k_hw_common(ah), BEACON,
2226 "%s: unsupported opmode: %d\n", __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08002227 return;
2228 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002229 }
2230
Felix Fietkaudd347f22011-03-22 21:54:17 +01002231 REG_WRITE(ah, AR_BEACON_PERIOD, beacon_period);
2232 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, beacon_period);
2233 REG_WRITE(ah, AR_SWBA_PERIOD, beacon_period);
2234 REG_WRITE(ah, AR_NDP_PERIOD, beacon_period);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002235
Sujith7d0d0df2010-04-16 11:53:57 +05302236 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05302237
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002238 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
2239}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002240EXPORT_SYMBOL(ath9k_hw_beaconinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002241
Sujithcbe61d82009-02-09 13:27:12 +05302242void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05302243 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002244{
2245 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05302246 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002247 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002248
Sujith7d0d0df2010-04-16 11:53:57 +05302249 ENABLE_REGWRITE_BUFFER(ah);
2250
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002251 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
2252
2253 REG_WRITE(ah, AR_BEACON_PERIOD,
Rajkumar Manoharanf29f5c02011-05-20 17:52:11 +05302254 TU_TO_USEC(bs->bs_intval));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002255 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
Rajkumar Manoharanf29f5c02011-05-20 17:52:11 +05302256 TU_TO_USEC(bs->bs_intval));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002257
Sujith7d0d0df2010-04-16 11:53:57 +05302258 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05302259
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002260 REG_RMW_FIELD(ah, AR_RSSI_THR,
2261 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
2262
Rajkumar Manoharanf29f5c02011-05-20 17:52:11 +05302263 beaconintval = bs->bs_intval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002264
2265 if (bs->bs_sleepduration > beaconintval)
2266 beaconintval = bs->bs_sleepduration;
2267
2268 dtimperiod = bs->bs_dtimperiod;
2269 if (bs->bs_sleepduration > dtimperiod)
2270 dtimperiod = bs->bs_sleepduration;
2271
2272 if (beaconintval == dtimperiod)
2273 nextTbtt = bs->bs_nextdtim;
2274 else
2275 nextTbtt = bs->bs_nexttbtt;
2276
Joe Perchesd2182b62011-12-15 14:55:53 -08002277 ath_dbg(common, BEACON, "next DTIM %d\n", bs->bs_nextdtim);
2278 ath_dbg(common, BEACON, "next beacon %d\n", nextTbtt);
2279 ath_dbg(common, BEACON, "beacon period %d\n", beaconintval);
2280 ath_dbg(common, BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002281
Sujith7d0d0df2010-04-16 11:53:57 +05302282 ENABLE_REGWRITE_BUFFER(ah);
2283
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002284 REG_WRITE(ah, AR_NEXT_DTIM,
2285 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
2286 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
2287
2288 REG_WRITE(ah, AR_SLEEP1,
2289 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
2290 | AR_SLEEP1_ASSUME_DTIM);
2291
Sujith60b67f52008-08-07 10:52:38 +05302292 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002293 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
2294 else
2295 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
2296
2297 REG_WRITE(ah, AR_SLEEP2,
2298 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
2299
2300 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
2301 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
2302
Sujith7d0d0df2010-04-16 11:53:57 +05302303 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05302304
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002305 REG_SET_BIT(ah, AR_TIMER_MODE,
2306 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
2307 AR_DTIM_TIMER_EN);
2308
Sujith4af9cf42009-02-12 10:06:47 +05302309 /* TSF Out of Range Threshold */
2310 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002311}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002312EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002313
Sujithf1dc5602008-10-29 10:16:30 +05302314/*******************/
2315/* HW Capabilities */
2316/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002317
Felix Fietkau60540692011-07-19 08:46:44 +02002318static u8 fixup_chainmask(u8 chip_chainmask, u8 eeprom_chainmask)
2319{
2320 eeprom_chainmask &= chip_chainmask;
2321 if (eeprom_chainmask)
2322 return eeprom_chainmask;
2323 else
2324 return chip_chainmask;
2325}
2326
Zefir Kurtisi9a66af32011-12-14 20:16:33 -08002327/**
2328 * ath9k_hw_dfs_tested - checks if DFS has been tested with used chipset
2329 * @ah: the atheros hardware data structure
2330 *
2331 * We enable DFS support upstream on chipsets which have passed a series
2332 * of tests. The testing requirements are going to be documented. Desired
2333 * test requirements are documented at:
2334 *
2335 * http://wireless.kernel.org/en/users/Drivers/ath9k/dfs
2336 *
2337 * Once a new chipset gets properly tested an individual commit can be used
2338 * to document the testing for DFS for that chipset.
2339 */
2340static bool ath9k_hw_dfs_tested(struct ath_hw *ah)
2341{
2342
2343 switch (ah->hw_version.macVersion) {
2344 /* AR9580 will likely be our first target to get testing on */
2345 case AR_SREV_VERSION_9580:
2346 default:
2347 return false;
2348 }
2349}
2350
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002351int ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002352{
Sujith2660b812009-02-09 13:27:26 +05302353 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002354 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002355 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkau60540692011-07-19 08:46:44 +02002356 unsigned int chip_chainmask;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002357
Sujith Manoharan0ff2b5c2011-04-20 11:00:34 +05302358 u16 eeval;
Vasanthakumar Thiagarajan47c80de2010-12-06 04:27:43 -08002359 u8 ant_div_ctl1, tx_chainmask, rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002360
Sujithf74df6f2009-02-09 13:27:24 +05302361 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002362 regulatory->current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05302363
Sujith2660b812009-02-09 13:27:26 +05302364 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05302365 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002366 if (regulatory->current_rd == 0x64 ||
2367 regulatory->current_rd == 0x65)
2368 regulatory->current_rd += 5;
2369 else if (regulatory->current_rd == 0x41)
2370 regulatory->current_rd = 0x43;
Joe Perchesd2182b62011-12-15 14:55:53 -08002371 ath_dbg(common, REGULATORY, "regdomain mapped to 0x%x\n",
2372 regulatory->current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002373 }
Sujithdc2222a2008-08-14 13:26:55 +05302374
Sujithf74df6f2009-02-09 13:27:24 +05302375 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002376 if ((eeval & (AR5416_OPFLAGS_11G | AR5416_OPFLAGS_11A)) == 0) {
Joe Perches38002762010-12-02 19:12:36 -08002377 ath_err(common,
2378 "no band has been marked as supported in EEPROM\n");
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002379 return -EINVAL;
2380 }
2381
Felix Fietkaud4659912010-10-14 16:02:39 +02002382 if (eeval & AR5416_OPFLAGS_11A)
2383 pCap->hw_caps |= ATH9K_HW_CAP_5GHZ;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002384
Felix Fietkaud4659912010-10-14 16:02:39 +02002385 if (eeval & AR5416_OPFLAGS_11G)
2386 pCap->hw_caps |= ATH9K_HW_CAP_2GHZ;
Sujithf1dc5602008-10-29 10:16:30 +05302387
Felix Fietkau60540692011-07-19 08:46:44 +02002388 if (AR_SREV_9485(ah) || AR_SREV_9285(ah) || AR_SREV_9330(ah))
2389 chip_chainmask = 1;
Mohammed Shafi Shajakhanba5736a2011-11-30 21:10:52 +05302390 else if (AR_SREV_9462(ah))
2391 chip_chainmask = 3;
Felix Fietkau60540692011-07-19 08:46:44 +02002392 else if (!AR_SREV_9280_20_OR_LATER(ah))
2393 chip_chainmask = 7;
2394 else if (!AR_SREV_9300_20_OR_LATER(ah) || AR_SREV_9340(ah))
2395 chip_chainmask = 3;
2396 else
2397 chip_chainmask = 7;
2398
Sujithf74df6f2009-02-09 13:27:24 +05302399 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002400 /*
2401 * For AR9271 we will temporarilly uses the rx chainmax as read from
2402 * the EEPROM.
2403 */
Sujith8147f5d2009-02-20 15:13:23 +05302404 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002405 !(eeval & AR5416_OPFLAGS_11A) &&
2406 !(AR_SREV_9271(ah)))
2407 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
Sujith8147f5d2009-02-20 15:13:23 +05302408 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
Felix Fietkau598cdd52011-03-19 13:55:42 +01002409 else if (AR_SREV_9100(ah))
2410 pCap->rx_chainmask = 0x7;
Sujith8147f5d2009-02-20 15:13:23 +05302411 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002412 /* Use rx_chainmask from EEPROM. */
Sujith8147f5d2009-02-20 15:13:23 +05302413 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05302414
Felix Fietkau60540692011-07-19 08:46:44 +02002415 pCap->tx_chainmask = fixup_chainmask(chip_chainmask, pCap->tx_chainmask);
2416 pCap->rx_chainmask = fixup_chainmask(chip_chainmask, pCap->rx_chainmask);
Felix Fietkau82b2d332011-09-03 01:40:23 +02002417 ah->txchainmask = pCap->tx_chainmask;
2418 ah->rxchainmask = pCap->rx_chainmask;
Felix Fietkau60540692011-07-19 08:46:44 +02002419
Felix Fietkau7a370812010-09-22 12:34:52 +02002420 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05302421
Felix Fietkau02d2ebb2010-11-22 15:39:39 +01002422 /* enable key search for every frame in an aggregate */
2423 if (AR_SREV_9300_20_OR_LATER(ah))
2424 ah->misc_mode |= AR_PCU_ALWAYS_PERFORM_KEYSEARCH;
2425
Bruno Randolfce2220d2010-09-17 11:36:25 +09002426 common->crypt_caps |= ATH_CRYPT_CAP_CIPHER_AESCCM;
2427
Felix Fietkau0db156e2011-03-23 20:57:29 +01002428 if (ah->hw_version.devid != AR2427_DEVID_PCIE)
Sujithf1dc5602008-10-29 10:16:30 +05302429 pCap->hw_caps |= ATH9K_HW_CAP_HT;
2430 else
2431 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
2432
Sujith5b5fa352010-03-17 14:25:15 +05302433 if (AR_SREV_9271(ah))
2434 pCap->num_gpio_pins = AR9271_NUM_GPIO;
Sujith88c1f4f2010-06-30 14:46:31 +05302435 else if (AR_DEVID_7010(ah))
2436 pCap->num_gpio_pins = AR7010_NUM_GPIO;
Mohammed Shafi Shajakhan6321eb02011-09-30 11:31:27 +05302437 else if (AR_SREV_9300_20_OR_LATER(ah))
2438 pCap->num_gpio_pins = AR9300_NUM_GPIO;
2439 else if (AR_SREV_9287_11_OR_LATER(ah))
2440 pCap->num_gpio_pins = AR9287_NUM_GPIO;
Felix Fietkaue17f83e2010-09-22 12:34:53 +02002441 else if (AR_SREV_9285_12_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302442 pCap->num_gpio_pins = AR9285_NUM_GPIO;
Felix Fietkau7a370812010-09-22 12:34:52 +02002443 else if (AR_SREV_9280_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302444 pCap->num_gpio_pins = AR928X_NUM_GPIO;
2445 else
2446 pCap->num_gpio_pins = AR_NUM_GPIO;
2447
Mohammed Shafi Shajakhan1b2538b2011-12-07 16:51:39 +05302448 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302449 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
Mohammed Shafi Shajakhan1b2538b2011-12-07 16:51:39 +05302450 else
Sujithf1dc5602008-10-29 10:16:30 +05302451 pCap->rts_aggr_limit = (8 * 1024);
Sujithf1dc5602008-10-29 10:16:30 +05302452
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05302453#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05302454 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
2455 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
2456 ah->rfkill_gpio =
2457 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
2458 ah->rfkill_polarity =
2459 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05302460
2461 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
2462 }
2463#endif
Vasanthakumar Thiagarajand5d11542010-05-17 18:57:56 -07002464 if (AR_SREV_9271(ah) || AR_SREV_9300_20_OR_LATER(ah))
Vivek Natarajanbde748a2010-04-05 14:48:05 +05302465 pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
2466 else
2467 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
Sujithf1dc5602008-10-29 10:16:30 +05302468
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302469 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302470 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
2471 else
2472 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
2473
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002474 if (AR_SREV_9300_20_OR_LATER(ah)) {
Vasanthakumar Thiagarajan784ad502010-12-06 04:27:40 -08002475 pCap->hw_caps |= ATH9K_HW_CAP_EDMA | ATH9K_HW_CAP_FASTCLOCK;
Gabor Juhos0e707a92011-06-21 11:23:31 +02002476 if (!AR_SREV_9330(ah) && !AR_SREV_9485(ah))
Vasanthakumar Thiagarajan784ad502010-12-06 04:27:40 -08002477 pCap->hw_caps |= ATH9K_HW_CAP_LDPC;
2478
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002479 pCap->rx_hp_qdepth = ATH9K_HW_RX_HP_QDEPTH;
2480 pCap->rx_lp_qdepth = ATH9K_HW_RX_LP_QDEPTH;
2481 pCap->rx_status_len = sizeof(struct ar9003_rxs);
Vasanthakumar Thiagarajan162c3be2010-04-15 17:38:41 -04002482 pCap->tx_desc_len = sizeof(struct ar9003_txc);
Vasanthakumar Thiagarajan5088c2f2010-04-15 17:39:34 -04002483 pCap->txs_len = sizeof(struct ar9003_txs);
Luis R. Rodriguez6f481012011-01-20 17:47:39 -08002484 if (!ah->config.paprd_disable &&
2485 ah->eep_ops->get_eeprom(ah, EEP_PAPRD))
Felix Fietkau49352502010-06-12 00:33:59 -04002486 pCap->hw_caps |= ATH9K_HW_CAP_PAPRD;
Vasanthakumar Thiagarajan162c3be2010-04-15 17:38:41 -04002487 } else {
2488 pCap->tx_desc_len = sizeof(struct ath_desc);
Felix Fietkaua949b172011-07-09 11:12:47 +07002489 if (AR_SREV_9280_20(ah))
Felix Fietkau6b42e8d2010-04-26 15:04:35 -04002490 pCap->hw_caps |= ATH9K_HW_CAP_FASTCLOCK;
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002491 }
Vasanthakumar Thiagarajan1adf02f2010-04-15 17:38:24 -04002492
Vasanthakumar Thiagarajan6c84ce02010-04-15 17:39:16 -04002493 if (AR_SREV_9300_20_OR_LATER(ah))
2494 pCap->hw_caps |= ATH9K_HW_CAP_RAC_SUPPORTED;
2495
Senthil Balasubramanian6ee63f52010-11-10 05:03:16 -08002496 if (AR_SREV_9300_20_OR_LATER(ah))
2497 ah->ent_mode = REG_READ(ah, AR_ENT_OTP);
2498
Felix Fietkaua42acef2010-09-22 12:34:54 +02002499 if (AR_SREV_9287_11_OR_LATER(ah) || AR_SREV_9271(ah))
Vasanthakumar Thiagarajan6473d242010-05-13 18:42:38 -07002500 pCap->hw_caps |= ATH9K_HW_CAP_SGI_20;
2501
Vasanthakumar Thiagarajan754dc532010-09-02 01:34:41 -07002502 if (AR_SREV_9285(ah))
2503 if (ah->eep_ops->get_eeprom(ah, EEP_MODAL_VER) >= 3) {
2504 ant_div_ctl1 =
2505 ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
2506 if ((ant_div_ctl1 & 0x1) && ((ant_div_ctl1 >> 3) & 0x1))
2507 pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB;
2508 }
Mohammed Shafi Shajakhanea066d52010-11-23 20:42:27 +05302509 if (AR_SREV_9300_20_OR_LATER(ah)) {
2510 if (ah->eep_ops->get_eeprom(ah, EEP_CHAIN_MASK_REDUCE))
2511 pCap->hw_caps |= ATH9K_HW_CAP_APM;
2512 }
2513
2514
Gabor Juhos431da562011-06-21 11:23:41 +02002515 if (AR_SREV_9330(ah) || AR_SREV_9485(ah)) {
Mohammed Shafi Shajakhan21d2c632011-05-13 20:29:31 +05302516 ant_div_ctl1 = ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
2517 /*
2518 * enable the diversity-combining algorithm only when
2519 * both enable_lna_div and enable_fast_div are set
2520 * Table for Diversity
2521 * ant_div_alt_lnaconf bit 0-1
2522 * ant_div_main_lnaconf bit 2-3
2523 * ant_div_alt_gaintb bit 4
2524 * ant_div_main_gaintb bit 5
2525 * enable_ant_div_lnadiv bit 6
2526 * enable_ant_fast_div bit 7
2527 */
2528 if ((ant_div_ctl1 >> 0x6) == 0x3)
2529 pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB;
2530 }
Vasanthakumar Thiagarajan754dc532010-09-02 01:34:41 -07002531
Vasanthakumar Thiagarajan8060e162010-12-06 04:27:42 -08002532 if (AR_SREV_9485_10(ah)) {
2533 pCap->pcie_lcr_extsync_en = true;
2534 pCap->pcie_lcr_offset = 0x80;
2535 }
2536
Zefir Kurtisi9a66af32011-12-14 20:16:33 -08002537 if (ath9k_hw_dfs_tested(ah))
2538 pCap->hw_caps |= ATH9K_HW_CAP_DFS;
2539
Vasanthakumar Thiagarajan47c80de2010-12-06 04:27:43 -08002540 tx_chainmask = pCap->tx_chainmask;
2541 rx_chainmask = pCap->rx_chainmask;
2542 while (tx_chainmask || rx_chainmask) {
2543 if (tx_chainmask & BIT(0))
2544 pCap->max_txchains++;
2545 if (rx_chainmask & BIT(0))
2546 pCap->max_rxchains++;
2547
2548 tx_chainmask >>= 1;
2549 rx_chainmask >>= 1;
2550 }
2551
Rajkumar Manoharan8ad74c42011-10-13 11:00:38 +05302552 if (AR_SREV_9300_20_OR_LATER(ah)) {
2553 ah->enabled_cals |= TX_IQ_CAL;
Mohammed Shafi Shajakhan6fea5932011-11-30 21:01:31 +05302554 if (AR_SREV_9485_OR_LATER(ah))
Rajkumar Manoharan8ad74c42011-10-13 11:00:38 +05302555 ah->enabled_cals |= TX_IQ_ON_AGC_CAL;
2556 }
Mohammed Shafi Shajakhan3789d592012-03-09 12:01:55 +05302557
2558 if (AR_SREV_9462(ah)) {
2559
2560 if (!(ah->ent_mode & AR_ENT_OTP_49GHZ_DISABLE))
2561 pCap->hw_caps |= ATH9K_HW_CAP_MCI;
2562
2563 if (AR_SREV_9462_20(ah))
2564 pCap->hw_caps |= ATH9K_HW_CAP_RTT;
2565
2566 }
2567
Rajkumar Manoharan324c74a2011-10-13 11:00:41 +05302568
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002569 return 0;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002570}
2571
Sujithf1dc5602008-10-29 10:16:30 +05302572/****************************/
2573/* GPIO / RFKILL / Antennae */
2574/****************************/
2575
Sujithcbe61d82009-02-09 13:27:12 +05302576static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05302577 u32 gpio, u32 type)
2578{
2579 int addr;
2580 u32 gpio_shift, tmp;
2581
2582 if (gpio > 11)
2583 addr = AR_GPIO_OUTPUT_MUX3;
2584 else if (gpio > 5)
2585 addr = AR_GPIO_OUTPUT_MUX2;
2586 else
2587 addr = AR_GPIO_OUTPUT_MUX1;
2588
2589 gpio_shift = (gpio % 6) * 5;
2590
2591 if (AR_SREV_9280_20_OR_LATER(ah)
2592 || (addr != AR_GPIO_OUTPUT_MUX1)) {
2593 REG_RMW(ah, addr, (type << gpio_shift),
2594 (0x1f << gpio_shift));
2595 } else {
2596 tmp = REG_READ(ah, addr);
2597 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
2598 tmp &= ~(0x1f << gpio_shift);
2599 tmp |= (type << gpio_shift);
2600 REG_WRITE(ah, addr, tmp);
2601 }
2602}
2603
Sujithcbe61d82009-02-09 13:27:12 +05302604void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05302605{
2606 u32 gpio_shift;
2607
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07002608 BUG_ON(gpio >= ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05302609
Sujith88c1f4f2010-06-30 14:46:31 +05302610 if (AR_DEVID_7010(ah)) {
2611 gpio_shift = gpio;
2612 REG_RMW(ah, AR7010_GPIO_OE,
2613 (AR7010_GPIO_OE_AS_INPUT << gpio_shift),
2614 (AR7010_GPIO_OE_MASK << gpio_shift));
2615 return;
2616 }
Sujithf1dc5602008-10-29 10:16:30 +05302617
Sujith88c1f4f2010-06-30 14:46:31 +05302618 gpio_shift = gpio << 1;
Sujithf1dc5602008-10-29 10:16:30 +05302619 REG_RMW(ah,
2620 AR_GPIO_OE_OUT,
2621 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
2622 (AR_GPIO_OE_OUT_DRV << gpio_shift));
2623}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002624EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
Sujithf1dc5602008-10-29 10:16:30 +05302625
Sujithcbe61d82009-02-09 13:27:12 +05302626u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05302627{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302628#define MS_REG_READ(x, y) \
2629 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
2630
Sujith2660b812009-02-09 13:27:26 +05302631 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05302632 return 0xffffffff;
2633
Sujith88c1f4f2010-06-30 14:46:31 +05302634 if (AR_DEVID_7010(ah)) {
2635 u32 val;
2636 val = REG_READ(ah, AR7010_GPIO_IN);
2637 return (MS(val, AR7010_GPIO_IN_VAL) & AR_GPIO_BIT(gpio)) == 0;
2638 } else if (AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan93069902010-11-30 23:24:09 -08002639 return (MS(REG_READ(ah, AR_GPIO_IN), AR9300_GPIO_IN_VAL) &
2640 AR_GPIO_BIT(gpio)) != 0;
Felix Fietkau783dfca2010-04-15 17:38:11 -04002641 else if (AR_SREV_9271(ah))
Sujith5b5fa352010-03-17 14:25:15 +05302642 return MS_REG_READ(AR9271, gpio) != 0;
Felix Fietkaua42acef2010-09-22 12:34:54 +02002643 else if (AR_SREV_9287_11_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302644 return MS_REG_READ(AR9287, gpio) != 0;
Felix Fietkaue17f83e2010-09-22 12:34:53 +02002645 else if (AR_SREV_9285_12_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302646 return MS_REG_READ(AR9285, gpio) != 0;
Felix Fietkau7a370812010-09-22 12:34:52 +02002647 else if (AR_SREV_9280_20_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302648 return MS_REG_READ(AR928X, gpio) != 0;
2649 else
2650 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05302651}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002652EXPORT_SYMBOL(ath9k_hw_gpio_get);
Sujithf1dc5602008-10-29 10:16:30 +05302653
Sujithcbe61d82009-02-09 13:27:12 +05302654void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05302655 u32 ah_signal_type)
2656{
2657 u32 gpio_shift;
2658
Sujith88c1f4f2010-06-30 14:46:31 +05302659 if (AR_DEVID_7010(ah)) {
2660 gpio_shift = gpio;
2661 REG_RMW(ah, AR7010_GPIO_OE,
2662 (AR7010_GPIO_OE_AS_OUTPUT << gpio_shift),
2663 (AR7010_GPIO_OE_MASK << gpio_shift));
2664 return;
2665 }
2666
Sujithf1dc5602008-10-29 10:16:30 +05302667 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
Sujithf1dc5602008-10-29 10:16:30 +05302668 gpio_shift = 2 * gpio;
Sujithf1dc5602008-10-29 10:16:30 +05302669 REG_RMW(ah,
2670 AR_GPIO_OE_OUT,
2671 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
2672 (AR_GPIO_OE_OUT_DRV << gpio_shift));
2673}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002674EXPORT_SYMBOL(ath9k_hw_cfg_output);
Sujithf1dc5602008-10-29 10:16:30 +05302675
Sujithcbe61d82009-02-09 13:27:12 +05302676void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05302677{
Sujith88c1f4f2010-06-30 14:46:31 +05302678 if (AR_DEVID_7010(ah)) {
2679 val = val ? 0 : 1;
2680 REG_RMW(ah, AR7010_GPIO_OUT, ((val&1) << gpio),
2681 AR_GPIO_BIT(gpio));
2682 return;
2683 }
2684
Sujith5b5fa352010-03-17 14:25:15 +05302685 if (AR_SREV_9271(ah))
2686 val = ~val;
2687
Sujithf1dc5602008-10-29 10:16:30 +05302688 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
2689 AR_GPIO_BIT(gpio));
2690}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002691EXPORT_SYMBOL(ath9k_hw_set_gpio);
Sujithf1dc5602008-10-29 10:16:30 +05302692
Sujithcbe61d82009-02-09 13:27:12 +05302693void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05302694{
2695 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
2696}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002697EXPORT_SYMBOL(ath9k_hw_setantenna);
Sujithf1dc5602008-10-29 10:16:30 +05302698
Sujithf1dc5602008-10-29 10:16:30 +05302699/*********************/
2700/* General Operation */
2701/*********************/
2702
Sujithcbe61d82009-02-09 13:27:12 +05302703u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302704{
2705 u32 bits = REG_READ(ah, AR_RX_FILTER);
2706 u32 phybits = REG_READ(ah, AR_PHY_ERR);
2707
2708 if (phybits & AR_PHY_ERR_RADAR)
2709 bits |= ATH9K_RX_FILTER_PHYRADAR;
2710 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
2711 bits |= ATH9K_RX_FILTER_PHYERR;
2712
2713 return bits;
2714}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002715EXPORT_SYMBOL(ath9k_hw_getrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05302716
Sujithcbe61d82009-02-09 13:27:12 +05302717void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05302718{
2719 u32 phybits;
2720
Sujith7d0d0df2010-04-16 11:53:57 +05302721 ENABLE_REGWRITE_BUFFER(ah);
2722
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05302723 if (AR_SREV_9462(ah))
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302724 bits |= ATH9K_RX_FILTER_CONTROL_WRAPPER;
2725
Sujith7ea310b2009-09-03 12:08:43 +05302726 REG_WRITE(ah, AR_RX_FILTER, bits);
2727
Sujithf1dc5602008-10-29 10:16:30 +05302728 phybits = 0;
2729 if (bits & ATH9K_RX_FILTER_PHYRADAR)
2730 phybits |= AR_PHY_ERR_RADAR;
2731 if (bits & ATH9K_RX_FILTER_PHYERR)
2732 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
2733 REG_WRITE(ah, AR_PHY_ERR, phybits);
2734
2735 if (phybits)
Felix Fietkauca7a4de2011-03-23 20:57:26 +01002736 REG_SET_BIT(ah, AR_RXCFG, AR_RXCFG_ZLFDMA);
Sujithf1dc5602008-10-29 10:16:30 +05302737 else
Felix Fietkauca7a4de2011-03-23 20:57:26 +01002738 REG_CLR_BIT(ah, AR_RXCFG, AR_RXCFG_ZLFDMA);
Sujith7d0d0df2010-04-16 11:53:57 +05302739
2740 REGWRITE_BUFFER_FLUSH(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302741}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002742EXPORT_SYMBOL(ath9k_hw_setrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05302743
Sujithcbe61d82009-02-09 13:27:12 +05302744bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302745{
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05302746 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
2747 return false;
2748
2749 ath9k_hw_init_pll(ah, NULL);
Felix Fietkau8efa7a82012-03-14 16:40:23 +01002750 ah->htc_reset_init = true;
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05302751 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302752}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002753EXPORT_SYMBOL(ath9k_hw_phy_disable);
Sujithf1dc5602008-10-29 10:16:30 +05302754
Sujithcbe61d82009-02-09 13:27:12 +05302755bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302756{
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002757 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05302758 return false;
2759
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05302760 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
2761 return false;
2762
2763 ath9k_hw_init_pll(ah, NULL);
2764 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302765}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002766EXPORT_SYMBOL(ath9k_hw_disable);
Sujithf1dc5602008-10-29 10:16:30 +05302767
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002768static int get_antenna_gain(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05302769{
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002770 enum eeprom_param gain_param;
Felix Fietkau9c204b42011-07-27 15:01:05 +02002771
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002772 if (IS_CHAN_2GHZ(chan))
2773 gain_param = EEP_ANTENNA_GAIN_2G;
2774 else
2775 gain_param = EEP_ANTENNA_GAIN_5G;
Sujithf1dc5602008-10-29 10:16:30 +05302776
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002777 return ah->eep_ops->get_eeprom(ah, gain_param);
2778}
2779
2780void ath9k_hw_apply_txpower(struct ath_hw *ah, struct ath9k_channel *chan)
2781{
2782 struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
2783 struct ieee80211_channel *channel;
2784 int chan_pwr, new_pwr, max_gain;
2785 int ant_gain, ant_reduction = 0;
2786
2787 if (!chan)
2788 return;
2789
2790 channel = chan->chan;
2791 chan_pwr = min_t(int, channel->max_power * 2, MAX_RATE_POWER);
2792 new_pwr = min_t(int, chan_pwr, reg->power_limit);
2793 max_gain = chan_pwr - new_pwr + channel->max_antenna_gain * 2;
2794
2795 ant_gain = get_antenna_gain(ah, chan);
2796 if (ant_gain > max_gain)
2797 ant_reduction = ant_gain - max_gain;
Sujithf1dc5602008-10-29 10:16:30 +05302798
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07002799 ah->eep_ops->set_txpower(ah, chan,
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002800 ath9k_regd_get_ctl(reg, chan),
2801 ant_reduction, new_pwr, false);
2802}
2803
2804void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit, bool test)
2805{
2806 struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
2807 struct ath9k_channel *chan = ah->curchan;
2808 struct ieee80211_channel *channel = chan->chan;
2809
Dan Carpenter48ef5c42011-10-17 10:28:23 +03002810 reg->power_limit = min_t(u32, limit, MAX_RATE_POWER);
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002811 if (test)
2812 channel->max_power = MAX_RATE_POWER / 2;
2813
2814 ath9k_hw_apply_txpower(ah, chan);
2815
2816 if (test)
2817 channel->max_power = DIV_ROUND_UP(reg->max_power_level, 2);
Sujithf1dc5602008-10-29 10:16:30 +05302818}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002819EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
Sujithf1dc5602008-10-29 10:16:30 +05302820
Sujithcbe61d82009-02-09 13:27:12 +05302821void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302822{
Sujith2660b812009-02-09 13:27:26 +05302823 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05302824}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002825EXPORT_SYMBOL(ath9k_hw_setopmode);
Sujithf1dc5602008-10-29 10:16:30 +05302826
Sujithcbe61d82009-02-09 13:27:12 +05302827void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05302828{
2829 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
2830 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
2831}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002832EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
Sujithf1dc5602008-10-29 10:16:30 +05302833
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07002834void ath9k_hw_write_associd(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302835{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002836 struct ath_common *common = ath9k_hw_common(ah);
2837
2838 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
2839 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
2840 ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05302841}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002842EXPORT_SYMBOL(ath9k_hw_write_associd);
Sujithf1dc5602008-10-29 10:16:30 +05302843
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002844#define ATH9K_MAX_TSF_READ 10
2845
Sujithcbe61d82009-02-09 13:27:12 +05302846u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302847{
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002848 u32 tsf_lower, tsf_upper1, tsf_upper2;
2849 int i;
Sujithf1dc5602008-10-29 10:16:30 +05302850
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002851 tsf_upper1 = REG_READ(ah, AR_TSF_U32);
2852 for (i = 0; i < ATH9K_MAX_TSF_READ; i++) {
2853 tsf_lower = REG_READ(ah, AR_TSF_L32);
2854 tsf_upper2 = REG_READ(ah, AR_TSF_U32);
2855 if (tsf_upper2 == tsf_upper1)
2856 break;
2857 tsf_upper1 = tsf_upper2;
2858 }
Sujithf1dc5602008-10-29 10:16:30 +05302859
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002860 WARN_ON( i == ATH9K_MAX_TSF_READ );
2861
2862 return (((u64)tsf_upper1 << 32) | tsf_lower);
Sujithf1dc5602008-10-29 10:16:30 +05302863}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002864EXPORT_SYMBOL(ath9k_hw_gettsf64);
Sujithf1dc5602008-10-29 10:16:30 +05302865
Sujithcbe61d82009-02-09 13:27:12 +05302866void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002867{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002868 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01002869 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002870}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002871EXPORT_SYMBOL(ath9k_hw_settsf64);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002872
Sujithcbe61d82009-02-09 13:27:12 +05302873void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302874{
Gabor Juhosf9b604f2009-06-21 00:02:15 +02002875 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
2876 AH_TSF_WRITE_TIMEOUT))
Joe Perchesd2182b62011-12-15 14:55:53 -08002877 ath_dbg(ath9k_hw_common(ah), RESET,
Joe Perches226afe62010-12-02 19:12:37 -08002878 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
Gabor Juhosf9b604f2009-06-21 00:02:15 +02002879
Sujithf1dc5602008-10-29 10:16:30 +05302880 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002881}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002882EXPORT_SYMBOL(ath9k_hw_reset_tsf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002883
Sujith54e4cec2009-08-07 09:45:09 +05302884void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002885{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002886 if (setting)
Sujith2660b812009-02-09 13:27:26 +05302887 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002888 else
Sujith2660b812009-02-09 13:27:26 +05302889 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002890}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002891EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002892
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002893void ath9k_hw_set11nmac2040(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002894{
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002895 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithf1dc5602008-10-29 10:16:30 +05302896 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002897
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002898 if (conf_is_ht40(conf) && !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05302899 macmode = AR_2040_JOINED_RX_CLEAR;
2900 else
2901 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002902
Sujithf1dc5602008-10-29 10:16:30 +05302903 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002904}
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302905
2906/* HW Generic timers configuration */
2907
2908static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
2909{
2910 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2911 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2912 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2913 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2914 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2915 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2916 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2917 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2918 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
2919 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
2920 AR_NDP2_TIMER_MODE, 0x0002},
2921 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
2922 AR_NDP2_TIMER_MODE, 0x0004},
2923 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
2924 AR_NDP2_TIMER_MODE, 0x0008},
2925 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
2926 AR_NDP2_TIMER_MODE, 0x0010},
2927 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
2928 AR_NDP2_TIMER_MODE, 0x0020},
2929 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
2930 AR_NDP2_TIMER_MODE, 0x0040},
2931 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
2932 AR_NDP2_TIMER_MODE, 0x0080}
2933};
2934
2935/* HW generic timer primitives */
2936
2937/* compute and clear index of rightmost 1 */
2938static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
2939{
2940 u32 b;
2941
2942 b = *mask;
2943 b &= (0-b);
2944 *mask &= ~b;
2945 b *= debruijn32;
2946 b >>= 27;
2947
2948 return timer_table->gen_timer_index[b];
2949}
2950
Felix Fietkaudd347f22011-03-22 21:54:17 +01002951u32 ath9k_hw_gettsf32(struct ath_hw *ah)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302952{
2953 return REG_READ(ah, AR_TSF_L32);
2954}
Felix Fietkaudd347f22011-03-22 21:54:17 +01002955EXPORT_SYMBOL(ath9k_hw_gettsf32);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302956
2957struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
2958 void (*trigger)(void *),
2959 void (*overflow)(void *),
2960 void *arg,
2961 u8 timer_index)
2962{
2963 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2964 struct ath_gen_timer *timer;
2965
2966 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
2967
2968 if (timer == NULL) {
Joe Perches38002762010-12-02 19:12:36 -08002969 ath_err(ath9k_hw_common(ah),
2970 "Failed to allocate memory for hw timer[%d]\n",
2971 timer_index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302972 return NULL;
2973 }
2974
2975 /* allocate a hardware generic timer slot */
2976 timer_table->timers[timer_index] = timer;
2977 timer->index = timer_index;
2978 timer->trigger = trigger;
2979 timer->overflow = overflow;
2980 timer->arg = arg;
2981
2982 return timer;
2983}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002984EXPORT_SYMBOL(ath_gen_timer_alloc);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302985
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07002986void ath9k_hw_gen_timer_start(struct ath_hw *ah,
2987 struct ath_gen_timer *timer,
Vasanthakumar Thiagarajan788f6872011-04-21 18:33:27 +05302988 u32 trig_timeout,
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07002989 u32 timer_period)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302990{
2991 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
Vasanthakumar Thiagarajan788f6872011-04-21 18:33:27 +05302992 u32 tsf, timer_next;
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302993
2994 BUG_ON(!timer_period);
2995
2996 set_bit(timer->index, &timer_table->timer_mask.timer_bits);
2997
2998 tsf = ath9k_hw_gettsf32(ah);
2999
Vasanthakumar Thiagarajan788f6872011-04-21 18:33:27 +05303000 timer_next = tsf + trig_timeout;
3001
Joe Perchesd2182b62011-12-15 14:55:53 -08003002 ath_dbg(ath9k_hw_common(ah), HWTIMER,
Joe Perches226afe62010-12-02 19:12:37 -08003003 "current tsf %x period %x timer_next %x\n",
3004 tsf, timer_period, timer_next);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303005
3006 /*
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303007 * Program generic timer registers
3008 */
3009 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
3010 timer_next);
3011 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
3012 timer_period);
3013 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
3014 gen_tmr_configuration[timer->index].mode_mask);
3015
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05303016 if (AR_SREV_9462(ah)) {
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05303017 /*
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05303018 * Starting from AR9462, each generic timer can select which tsf
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05303019 * to use. But we still follow the old rule, 0 - 7 use tsf and
3020 * 8 - 15 use tsf2.
3021 */
3022 if ((timer->index < AR_GEN_TIMER_BANK_1_LEN))
3023 REG_CLR_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL,
3024 (1 << timer->index));
3025 else
3026 REG_SET_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL,
3027 (1 << timer->index));
3028 }
3029
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303030 /* Enable both trigger and thresh interrupt masks */
3031 REG_SET_BIT(ah, AR_IMR_S5,
3032 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
3033 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303034}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003035EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303036
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07003037void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303038{
3039 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3040
3041 if ((timer->index < AR_FIRST_NDP_TIMER) ||
3042 (timer->index >= ATH_MAX_GEN_TIMER)) {
3043 return;
3044 }
3045
3046 /* Clear generic timer enable bits. */
3047 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
3048 gen_tmr_configuration[timer->index].mode_mask);
3049
3050 /* Disable both trigger and thresh interrupt masks */
3051 REG_CLR_BIT(ah, AR_IMR_S5,
3052 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
3053 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
3054
3055 clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303056}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003057EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303058
3059void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
3060{
3061 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3062
3063 /* free the hardware generic timer slot */
3064 timer_table->timers[timer->index] = NULL;
3065 kfree(timer);
3066}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003067EXPORT_SYMBOL(ath_gen_timer_free);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303068
3069/*
3070 * Generic Timer Interrupts handling
3071 */
3072void ath_gen_timer_isr(struct ath_hw *ah)
3073{
3074 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3075 struct ath_gen_timer *timer;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003076 struct ath_common *common = ath9k_hw_common(ah);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303077 u32 trigger_mask, thresh_mask, index;
3078
3079 /* get hardware generic timer interrupt status */
3080 trigger_mask = ah->intr_gen_timer_trigger;
3081 thresh_mask = ah->intr_gen_timer_thresh;
3082 trigger_mask &= timer_table->timer_mask.val;
3083 thresh_mask &= timer_table->timer_mask.val;
3084
3085 trigger_mask &= ~thresh_mask;
3086
3087 while (thresh_mask) {
3088 index = rightmost_index(timer_table, &thresh_mask);
3089 timer = timer_table->timers[index];
3090 BUG_ON(!timer);
Joe Perchesd2182b62011-12-15 14:55:53 -08003091 ath_dbg(common, HWTIMER, "TSF overflow for Gen timer %d\n",
3092 index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303093 timer->overflow(timer->arg);
3094 }
3095
3096 while (trigger_mask) {
3097 index = rightmost_index(timer_table, &trigger_mask);
3098 timer = timer_table->timers[index];
3099 BUG_ON(!timer);
Joe Perchesd2182b62011-12-15 14:55:53 -08003100 ath_dbg(common, HWTIMER,
Joe Perches226afe62010-12-02 19:12:37 -08003101 "Gen timer[%d] trigger\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303102 timer->trigger(timer->arg);
3103 }
3104}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003105EXPORT_SYMBOL(ath_gen_timer_isr);
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003106
Sujith05020d22010-03-17 14:25:23 +05303107/********/
3108/* HTC */
3109/********/
3110
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003111static struct {
3112 u32 version;
3113 const char * name;
3114} ath_mac_bb_names[] = {
3115 /* Devices with external radios */
3116 { AR_SREV_VERSION_5416_PCI, "5416" },
3117 { AR_SREV_VERSION_5416_PCIE, "5418" },
3118 { AR_SREV_VERSION_9100, "9100" },
3119 { AR_SREV_VERSION_9160, "9160" },
3120 /* Single-chip solutions */
3121 { AR_SREV_VERSION_9280, "9280" },
3122 { AR_SREV_VERSION_9285, "9285" },
Luis R. Rodriguez11158472009-10-27 12:59:35 -04003123 { AR_SREV_VERSION_9287, "9287" },
3124 { AR_SREV_VERSION_9271, "9271" },
Luis R. Rodriguezec839032010-04-15 17:39:20 -04003125 { AR_SREV_VERSION_9300, "9300" },
Gabor Juhos2c8e5932011-06-21 11:23:21 +02003126 { AR_SREV_VERSION_9330, "9330" },
Florian Fainelli397e5d52011-08-25 21:33:48 +02003127 { AR_SREV_VERSION_9340, "9340" },
Senthil Balasubramanian8f06ca22011-04-01 17:16:33 +05303128 { AR_SREV_VERSION_9485, "9485" },
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05303129 { AR_SREV_VERSION_9462, "9462" },
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003130};
3131
3132/* For devices with external radios */
3133static struct {
3134 u16 version;
3135 const char * name;
3136} ath_rf_names[] = {
3137 { 0, "5133" },
3138 { AR_RAD5133_SREV_MAJOR, "5133" },
3139 { AR_RAD5122_SREV_MAJOR, "5122" },
3140 { AR_RAD2133_SREV_MAJOR, "2133" },
3141 { AR_RAD2122_SREV_MAJOR, "2122" }
3142};
3143
3144/*
3145 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
3146 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003147static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003148{
3149 int i;
3150
3151 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
3152 if (ath_mac_bb_names[i].version == mac_bb_version) {
3153 return ath_mac_bb_names[i].name;
3154 }
3155 }
3156
3157 return "????";
3158}
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003159
3160/*
3161 * Return the RF name. "????" is returned if the RF is unknown.
3162 * Used for devices with external radios.
3163 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003164static const char *ath9k_hw_rf_name(u16 rf_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003165{
3166 int i;
3167
3168 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
3169 if (ath_rf_names[i].version == rf_version) {
3170 return ath_rf_names[i].name;
3171 }
3172 }
3173
3174 return "????";
3175}
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003176
3177void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
3178{
3179 int used;
3180
3181 /* chipsets >= AR9280 are single-chip */
Felix Fietkau7a370812010-09-22 12:34:52 +02003182 if (AR_SREV_9280_20_OR_LATER(ah)) {
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003183 used = snprintf(hw_name, len,
3184 "Atheros AR%s Rev:%x",
3185 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3186 ah->hw_version.macRev);
3187 }
3188 else {
3189 used = snprintf(hw_name, len,
3190 "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
3191 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3192 ah->hw_version.macRev,
3193 ath9k_hw_rf_name((ah->hw_version.analog5GhzRev &
3194 AR_RADIO_SREV_MAJOR)),
3195 ah->hw_version.phyRev);
3196 }
3197
3198 hw_name[used] = '\0';
3199}
3200EXPORT_SYMBOL(ath9k_hw_name);