blob: 51c4edd076592f34d2b05ba400a7493b49145d51 [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>
Felix Fietkau09d8e312013-11-18 20:14:43 +010020#include <linux/time.h>
Felix Fietkauc67ce332013-12-14 18:03:38 +010021#include <linux/bitops.h>
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070022#include <asm/unaligned.h>
23
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -070024#include "hw.h"
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -040025#include "hw-ops.h"
Luis R. Rodriguezcfe8cba2009-09-13 23:39:31 -070026#include "rc.h"
Luis R. Rodriguezb622a722010-04-15 17:39:28 -040027#include "ar9003_mac.h"
Sujith Manoharanf4701b52012-02-22 12:41:18 +053028#include "ar9003_mci.h"
Sujith Manoharan362cd032012-09-16 08:06:36 +053029#include "ar9003_phy.h"
Ben Greear462e58f2012-04-12 10:04:00 -070030#include "debug.h"
31#include "ath9k.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070032
Sujithcbe61d82009-02-09 13:27:12 +053033static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070034
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040035MODULE_AUTHOR("Atheros Communications");
36MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
37MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
38MODULE_LICENSE("Dual BSD/GPL");
39
40static int __init ath9k_init(void)
41{
42 return 0;
43}
44module_init(ath9k_init);
45
46static void __exit ath9k_exit(void)
47{
48 return;
49}
50module_exit(ath9k_exit);
51
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -040052/* Private hardware callbacks */
53
54static void ath9k_hw_init_cal_settings(struct ath_hw *ah)
55{
56 ath9k_hw_private_ops(ah)->init_cal_settings(ah);
57}
58
Luis R. Rodriguez64773962010-04-15 17:38:17 -040059static u32 ath9k_hw_compute_pll_control(struct ath_hw *ah,
60 struct ath9k_channel *chan)
61{
62 return ath9k_hw_private_ops(ah)->compute_pll_control(ah, chan);
63}
64
Luis R. Rodriguez991312d2010-04-15 17:39:05 -040065static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
66{
67 if (!ath9k_hw_private_ops(ah)->init_mode_gain_regs)
68 return;
69
70 ath9k_hw_private_ops(ah)->init_mode_gain_regs(ah);
71}
72
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -040073static void ath9k_hw_ani_cache_ini_regs(struct ath_hw *ah)
74{
75 /* You will not have this callback if using the old ANI */
76 if (!ath9k_hw_private_ops(ah)->ani_cache_ini_regs)
77 return;
78
79 ath9k_hw_private_ops(ah)->ani_cache_ini_regs(ah);
80}
81
Sujithf1dc5602008-10-29 10:16:30 +053082/********************/
83/* Helper Functions */
84/********************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070085
Ben Greear462e58f2012-04-12 10:04:00 -070086#ifdef CONFIG_ATH9K_DEBUGFS
87
Ben Greear462e58f2012-04-12 10:04:00 -070088#endif
89
90
Felix Fietkaudfdac8a2010-10-08 22:13:51 +020091static void ath9k_hw_set_clockrate(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +053092{
Felix Fietkaudfdac8a2010-10-08 22:13:51 +020093 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkaue4744ec2013-10-11 23:31:01 +020094 struct ath9k_channel *chan = ah->curchan;
Felix Fietkaudfdac8a2010-10-08 22:13:51 +020095 unsigned int clockrate;
Sujithcbe61d82009-02-09 13:27:12 +053096
Felix Fietkau087b6ff2011-07-09 11:12:49 +070097 /* AR9287 v1.3+ uses async FIFO and runs the MAC at 117 MHz */
98 if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah))
99 clockrate = 117;
Felix Fietkaue4744ec2013-10-11 23:31:01 +0200100 else if (!chan) /* should really check for CCK instead */
Felix Fietkaudfdac8a2010-10-08 22:13:51 +0200101 clockrate = ATH9K_CLOCK_RATE_CCK;
Felix Fietkaue4744ec2013-10-11 23:31:01 +0200102 else if (IS_CHAN_2GHZ(chan))
Felix Fietkaudfdac8a2010-10-08 22:13:51 +0200103 clockrate = ATH9K_CLOCK_RATE_2GHZ_OFDM;
104 else if (ah->caps.hw_caps & ATH9K_HW_CAP_FASTCLOCK)
105 clockrate = ATH9K_CLOCK_FAST_RATE_5GHZ_OFDM;
Vasanthakumar Thiagarajane5553722010-04-26 15:04:33 -0400106 else
Felix Fietkaudfdac8a2010-10-08 22:13:51 +0200107 clockrate = ATH9K_CLOCK_RATE_5GHZ_OFDM;
108
Michal Nazarewiczbeae4162013-11-29 18:06:46 +0100109 if (chan) {
110 if (IS_CHAN_HT40(chan))
111 clockrate *= 2;
Felix Fietkaue4744ec2013-10-11 23:31:01 +0200112 if (IS_CHAN_HALF_RATE(chan))
Felix Fietkau906c7202011-07-09 11:12:48 +0700113 clockrate /= 2;
Felix Fietkaue4744ec2013-10-11 23:31:01 +0200114 if (IS_CHAN_QUARTER_RATE(chan))
Felix Fietkau906c7202011-07-09 11:12:48 +0700115 clockrate /= 4;
116 }
117
Felix Fietkaudfdac8a2010-10-08 22:13:51 +0200118 common->clockrate = clockrate;
Sujithf1dc5602008-10-29 10:16:30 +0530119}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700120
Sujithcbe61d82009-02-09 13:27:12 +0530121static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +0530122{
Felix Fietkaudfdac8a2010-10-08 22:13:51 +0200123 struct ath_common *common = ath9k_hw_common(ah);
Sujithcbe61d82009-02-09 13:27:12 +0530124
Felix Fietkaudfdac8a2010-10-08 22:13:51 +0200125 return usecs * common->clockrate;
Sujithf1dc5602008-10-29 10:16:30 +0530126}
127
Sujith0caa7b12009-02-16 13:23:20 +0530128bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700129{
130 int i;
131
Sujith0caa7b12009-02-16 13:23:20 +0530132 BUG_ON(timeout < AH_TIME_QUANTUM);
133
134 for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700135 if ((REG_READ(ah, reg) & mask) == val)
136 return true;
137
138 udelay(AH_TIME_QUANTUM);
139 }
Sujith04bd46382008-11-28 22:18:05 +0530140
Joe Perchesd2182b62011-12-15 14:55:53 -0800141 ath_dbg(ath9k_hw_common(ah), ANY,
Joe Perches226afe62010-12-02 19:12:37 -0800142 "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
143 timeout, reg, REG_READ(ah, reg), mask, val);
Sujithf1dc5602008-10-29 10:16:30 +0530144
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700145 return false;
146}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400147EXPORT_SYMBOL(ath9k_hw_wait);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700148
Felix Fietkau7c5adc82012-04-19 21:18:26 +0200149void ath9k_hw_synth_delay(struct ath_hw *ah, struct ath9k_channel *chan,
150 int hw_delay)
151{
Felix Fietkau1a5e6322013-10-11 23:30:54 +0200152 hw_delay /= 10;
Felix Fietkau7c5adc82012-04-19 21:18:26 +0200153
154 if (IS_CHAN_HALF_RATE(chan))
155 hw_delay *= 2;
156 else if (IS_CHAN_QUARTER_RATE(chan))
157 hw_delay *= 4;
158
159 udelay(hw_delay + BASE_ACTIVATE_DELAY);
160}
161
Felix Fietkau0166b4b2013-01-20 18:51:55 +0100162void ath9k_hw_write_array(struct ath_hw *ah, const struct ar5416IniArray *array,
Felix Fietkaua9b6b252011-03-23 20:57:27 +0100163 int column, unsigned int *writecnt)
164{
165 int r;
166
167 ENABLE_REGWRITE_BUFFER(ah);
168 for (r = 0; r < array->ia_rows; r++) {
169 REG_WRITE(ah, INI_RA(array, r, 0),
170 INI_RA(array, r, column));
171 DO_DELAY(*writecnt);
172 }
173 REGWRITE_BUFFER_FLUSH(ah);
174}
175
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700176u32 ath9k_hw_reverse_bits(u32 val, u32 n)
177{
178 u32 retval;
179 int i;
180
181 for (i = 0, retval = 0; i < n; i++) {
182 retval = (retval << 1) | (val & 1);
183 val >>= 1;
184 }
185 return retval;
186}
187
Sujithcbe61d82009-02-09 13:27:12 +0530188u16 ath9k_hw_computetxtime(struct ath_hw *ah,
Felix Fietkau545750d2009-11-23 22:21:01 +0100189 u8 phy, int kbps,
Sujithf1dc5602008-10-29 10:16:30 +0530190 u32 frameLen, u16 rateix,
191 bool shortPreamble)
192{
193 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
Sujithf1dc5602008-10-29 10:16:30 +0530194
195 if (kbps == 0)
196 return 0;
197
Felix Fietkau545750d2009-11-23 22:21:01 +0100198 switch (phy) {
Sujith46d14a52008-11-18 09:08:13 +0530199 case WLAN_RC_PHY_CCK:
Sujithf1dc5602008-10-29 10:16:30 +0530200 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
Felix Fietkau545750d2009-11-23 22:21:01 +0100201 if (shortPreamble)
Sujithf1dc5602008-10-29 10:16:30 +0530202 phyTime >>= 1;
203 numBits = frameLen << 3;
204 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
205 break;
Sujith46d14a52008-11-18 09:08:13 +0530206 case WLAN_RC_PHY_OFDM:
Sujith2660b812009-02-09 13:27:26 +0530207 if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530208 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
209 numBits = OFDM_PLCP_BITS + (frameLen << 3);
210 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
211 txTime = OFDM_SIFS_TIME_QUARTER
212 + OFDM_PREAMBLE_TIME_QUARTER
213 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
Sujith2660b812009-02-09 13:27:26 +0530214 } else if (ah->curchan &&
215 IS_CHAN_HALF_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530216 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
217 numBits = OFDM_PLCP_BITS + (frameLen << 3);
218 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
219 txTime = OFDM_SIFS_TIME_HALF +
220 OFDM_PREAMBLE_TIME_HALF
221 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
222 } else {
223 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
224 numBits = OFDM_PLCP_BITS + (frameLen << 3);
225 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
226 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
227 + (numSymbols * OFDM_SYMBOL_TIME);
228 }
229 break;
230 default:
Joe Perches38002762010-12-02 19:12:36 -0800231 ath_err(ath9k_hw_common(ah),
232 "Unknown phy %u (rate ix %u)\n", phy, rateix);
Sujithf1dc5602008-10-29 10:16:30 +0530233 txTime = 0;
234 break;
235 }
236
237 return txTime;
238}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400239EXPORT_SYMBOL(ath9k_hw_computetxtime);
Sujithf1dc5602008-10-29 10:16:30 +0530240
Sujithcbe61d82009-02-09 13:27:12 +0530241void ath9k_hw_get_channel_centers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530242 struct ath9k_channel *chan,
243 struct chan_centers *centers)
244{
245 int8_t extoff;
Sujithf1dc5602008-10-29 10:16:30 +0530246
247 if (!IS_CHAN_HT40(chan)) {
248 centers->ctl_center = centers->ext_center =
249 centers->synth_center = chan->channel;
250 return;
251 }
252
Felix Fietkau88969342013-10-11 23:30:53 +0200253 if (IS_CHAN_HT40PLUS(chan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530254 centers->synth_center =
255 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
256 extoff = 1;
257 } else {
258 centers->synth_center =
259 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
260 extoff = -1;
261 }
262
263 centers->ctl_center =
264 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700265 /* 25 MHz spacing is supported by hw but not on upper layers */
Sujithf1dc5602008-10-29 10:16:30 +0530266 centers->ext_center =
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700267 centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT);
Sujithf1dc5602008-10-29 10:16:30 +0530268}
269
270/******************/
271/* Chip Revisions */
272/******************/
273
Sujithcbe61d82009-02-09 13:27:12 +0530274static void ath9k_hw_read_revisions(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530275{
276 u32 val;
277
Vasanthakumar Thiagarajanecb1d382011-04-19 19:29:18 +0530278 switch (ah->hw_version.devid) {
279 case AR5416_AR9100_DEVID:
280 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
281 break;
Gabor Juhos37625612011-06-21 11:23:23 +0200282 case AR9300_DEVID_AR9330:
283 ah->hw_version.macVersion = AR_SREV_VERSION_9330;
284 if (ah->get_mac_revision) {
285 ah->hw_version.macRev = ah->get_mac_revision();
286 } else {
287 val = REG_READ(ah, AR_SREV);
288 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
289 }
290 return;
Vasanthakumar Thiagarajanecb1d382011-04-19 19:29:18 +0530291 case AR9300_DEVID_AR9340:
292 ah->hw_version.macVersion = AR_SREV_VERSION_9340;
293 val = REG_READ(ah, AR_SREV);
294 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
295 return;
Gabor Juhos813831d2012-07-03 19:13:17 +0200296 case AR9300_DEVID_QCA955X:
297 ah->hw_version.macVersion = AR_SREV_VERSION_9550;
298 return;
Vasanthakumar Thiagarajanecb1d382011-04-19 19:29:18 +0530299 }
300
Sujithf1dc5602008-10-29 10:16:30 +0530301 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
302
303 if (val == 0xFF) {
304 val = REG_READ(ah, AR_SREV);
Sujithd535a422009-02-09 13:27:06 +0530305 ah->hw_version.macVersion =
306 (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
307 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
Mohammed Shafi Shajakhan76ed94b2011-09-30 11:31:28 +0530308
Sujith Manoharan77fac462012-09-11 20:09:18 +0530309 if (AR_SREV_9462(ah) || AR_SREV_9565(ah))
Mohammed Shafi Shajakhan76ed94b2011-09-30 11:31:28 +0530310 ah->is_pciexpress = true;
311 else
312 ah->is_pciexpress = (val &
313 AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
Sujithf1dc5602008-10-29 10:16:30 +0530314 } else {
315 if (!AR_SREV_9100(ah))
Sujithd535a422009-02-09 13:27:06 +0530316 ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
Sujithf1dc5602008-10-29 10:16:30 +0530317
Sujithd535a422009-02-09 13:27:06 +0530318 ah->hw_version.macRev = val & AR_SREV_REVISION;
Sujithf1dc5602008-10-29 10:16:30 +0530319
Sujithd535a422009-02-09 13:27:06 +0530320 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
Sujith2660b812009-02-09 13:27:26 +0530321 ah->is_pciexpress = true;
Sujithf1dc5602008-10-29 10:16:30 +0530322 }
323}
324
Sujithf1dc5602008-10-29 10:16:30 +0530325/************************************/
326/* HW Attach, Detach, Init Routines */
327/************************************/
328
Sujithcbe61d82009-02-09 13:27:12 +0530329static void ath9k_hw_disablepcie(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530330{
Felix Fietkau040b74f2010-12-12 00:51:07 +0100331 if (!AR_SREV_5416(ah))
Sujithf1dc5602008-10-29 10:16:30 +0530332 return;
333
334 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
335 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
336 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
337 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
338 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
339 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
340 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
341 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
342 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
343
344 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
345}
346
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400347/* This should work for all families including legacy */
Sujithcbe61d82009-02-09 13:27:12 +0530348static bool ath9k_hw_chip_test(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530349{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700350 struct ath_common *common = ath9k_hw_common(ah);
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400351 u32 regAddr[2] = { AR_STA_ID0 };
Sujithf1dc5602008-10-29 10:16:30 +0530352 u32 regHold[2];
Joe Perches07b2fa52010-11-20 18:38:53 -0800353 static const u32 patternData[4] = {
354 0x55555555, 0xaaaaaaaa, 0x66666666, 0x99999999
355 };
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400356 int i, j, loop_max;
Sujithf1dc5602008-10-29 10:16:30 +0530357
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400358 if (!AR_SREV_9300_20_OR_LATER(ah)) {
359 loop_max = 2;
360 regAddr[1] = AR_PHY_BASE + (8 << 2);
361 } else
362 loop_max = 1;
363
364 for (i = 0; i < loop_max; i++) {
Sujithf1dc5602008-10-29 10:16:30 +0530365 u32 addr = regAddr[i];
366 u32 wrData, rdData;
367
368 regHold[i] = REG_READ(ah, addr);
369 for (j = 0; j < 0x100; j++) {
370 wrData = (j << 16) | j;
371 REG_WRITE(ah, addr, wrData);
372 rdData = REG_READ(ah, addr);
373 if (rdData != wrData) {
Joe Perches38002762010-12-02 19:12:36 -0800374 ath_err(common,
375 "address test failed addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
376 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530377 return false;
378 }
379 }
380 for (j = 0; j < 4; j++) {
381 wrData = patternData[j];
382 REG_WRITE(ah, addr, wrData);
383 rdData = REG_READ(ah, addr);
384 if (wrData != rdData) {
Joe Perches38002762010-12-02 19:12:36 -0800385 ath_err(common,
386 "address test failed addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
387 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530388 return false;
389 }
390 }
391 REG_WRITE(ah, regAddr[i], regHold[i]);
392 }
393 udelay(100);
Sujithcbe61d82009-02-09 13:27:12 +0530394
Sujithf1dc5602008-10-29 10:16:30 +0530395 return true;
396}
397
Luis R. Rodriguezb8b0f372009-08-03 12:24:43 -0700398static void ath9k_hw_init_config(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700399{
Felix Fietkau689e7562012-04-12 22:35:56 +0200400 ah->config.dma_beacon_response_time = 1;
401 ah->config.sw_beacon_response_time = 6;
Sujith2660b812009-02-09 13:27:26 +0530402 ah->config.ack_6mb = 0x0;
403 ah->config.cwm_ignore_extcca = 0;
Sujith2660b812009-02-09 13:27:26 +0530404 ah->config.analog_shiftreg = 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700405
Sujith0ce024c2009-12-14 14:57:00 +0530406 ah->config.rx_intr_mitigation = true;
Luis R. Rodriguez61584252009-03-12 18:18:49 -0400407
408 /*
409 * We need this for PCI devices only (Cardbus, PCI, miniPCI)
410 * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
411 * This means we use it for all AR5416 devices, and the few
412 * minor PCI AR9280 devices out there.
413 *
414 * Serialization is required because these devices do not handle
415 * well the case of two concurrent reads/writes due to the latency
416 * involved. During one read/write another read/write can be issued
417 * on another CPU while the previous read/write may still be working
418 * on our hardware, if we hit this case the hardware poops in a loop.
419 * We prevent this by serializing reads and writes.
420 *
421 * This issue is not present on PCI-Express devices or pre-AR5416
422 * devices (legacy, 802.11abg).
423 */
424 if (num_possible_cpus() > 1)
David S. Miller2d6a5e92009-03-17 15:01:30 -0700425 ah->config.serialize_regmode = SER_REG_MODE_AUTO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700426}
427
Luis R. Rodriguez50aca252009-08-03 12:24:42 -0700428static void ath9k_hw_init_defaults(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700429{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700430 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
431
432 regulatory->country_code = CTRY_DEFAULT;
433 regulatory->power_limit = MAX_RATE_POWER;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700434
Sujithd535a422009-02-09 13:27:06 +0530435 ah->hw_version.magic = AR5416_MAGIC;
Sujithd535a422009-02-09 13:27:06 +0530436 ah->hw_version.subvendorid = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700437
Felix Fietkau16f24112010-06-12 17:22:32 +0200438 ah->sta_id1_defaults =
439 AR_STA_ID1_CRPT_MIC_ENABLE |
440 AR_STA_ID1_MCAST_KSRCH;
Felix Fietkauf1717602011-03-19 13:55:41 +0100441 if (AR_SREV_9100(ah))
442 ah->sta_id1_defaults |= AR_STA_ID1_AR9100_BA_FIX;
Rajkumar Manoharane3f2acc2011-08-27 11:22:59 +0530443 ah->slottime = ATH9K_SLOT_TIME_9;
Sujith2660b812009-02-09 13:27:26 +0530444 ah->globaltxtimeout = (u32) -1;
Gabor Juhoscbdec972009-07-24 17:27:22 +0200445 ah->power_mode = ATH9K_PM_UNDEFINED;
Felix Fietkau8efa7a82012-03-14 16:40:23 +0100446 ah->htc_reset_init = true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700447}
448
Sujithcbe61d82009-02-09 13:27:12 +0530449static int ath9k_hw_init_macaddr(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700450{
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700451 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530452 u32 sum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700453 int i;
Sujithf1dc5602008-10-29 10:16:30 +0530454 u16 eeval;
Joe Perches07b2fa52010-11-20 18:38:53 -0800455 static const u32 EEP_MAC[] = { EEP_MAC_LSW, EEP_MAC_MID, EEP_MAC_MSW };
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700456
Sujithf1dc5602008-10-29 10:16:30 +0530457 sum = 0;
458 for (i = 0; i < 3; i++) {
Luis R. Rodriguez49101672010-04-15 17:39:13 -0400459 eeval = ah->eep_ops->get_eeprom(ah, EEP_MAC[i]);
Sujithf1dc5602008-10-29 10:16:30 +0530460 sum += eeval;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700461 common->macaddr[2 * i] = eeval >> 8;
462 common->macaddr[2 * i + 1] = eeval & 0xff;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700463 }
Sujithd8baa932009-03-30 15:28:25 +0530464 if (sum == 0 || sum == 0xffff * 3)
Sujithf1dc5602008-10-29 10:16:30 +0530465 return -EADDRNOTAVAIL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700466
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700467 return 0;
468}
469
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700470static int ath9k_hw_post_init(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700471{
Sujith Manoharan6cae913d2011-01-04 13:16:37 +0530472 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700473 int ecode;
474
Sujith Manoharan6cae913d2011-01-04 13:16:37 +0530475 if (common->bus_ops->ath_bus_type != ATH_USB) {
Sujith527d4852010-03-17 14:25:16 +0530476 if (!ath9k_hw_chip_test(ah))
477 return -ENODEV;
478 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700479
Luis R. Rodriguezebd5a142010-04-15 17:39:18 -0400480 if (!AR_SREV_9300_20_OR_LATER(ah)) {
481 ecode = ar9002_hw_rf_claim(ah);
482 if (ecode != 0)
483 return ecode;
484 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700485
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700486 ecode = ath9k_hw_eeprom_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700487 if (ecode != 0)
488 return ecode;
Sujith7d01b222009-03-13 08:55:55 +0530489
Joe Perchesd2182b62011-12-15 14:55:53 -0800490 ath_dbg(ath9k_hw_common(ah), CONFIG, "Eeprom VER: %d, REV: %d\n",
Joe Perches226afe62010-12-02 19:12:37 -0800491 ah->eep_ops->get_eeprom_ver(ah),
492 ah->eep_ops->get_eeprom_rev(ah));
Sujith7d01b222009-03-13 08:55:55 +0530493
Sujith Manoharane3233002013-06-03 09:19:26 +0530494 ath9k_hw_ani_init(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530495
Sujith Manoharand3b371c2013-09-03 10:28:55 +0530496 /*
497 * EEPROM needs to be initialized before we do this.
498 * This is required for regulatory compliance.
499 */
Sujith Manoharan0c7c2bb2013-12-06 16:28:50 +0530500 if (AR_SREV_9300_20_OR_LATER(ah)) {
Sujith Manoharand3b371c2013-09-03 10:28:55 +0530501 u16 regdmn = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
502 if ((regdmn & 0xF0) == CTL_FCC) {
Sujith Manoharan0c7c2bb2013-12-06 16:28:50 +0530503 ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_FCC_2GHZ;
504 ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_FCC_5GHZ;
Sujith Manoharand3b371c2013-09-03 10:28:55 +0530505 }
506 }
507
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700508 return 0;
509}
510
Felix Fietkauc1b976d2012-12-12 13:14:23 +0100511static int ath9k_hw_attach_ops(struct ath_hw *ah)
Luis R. Rodriguezee2bb462009-08-03 12:24:39 -0700512{
Felix Fietkauc1b976d2012-12-12 13:14:23 +0100513 if (!AR_SREV_9300_20_OR_LATER(ah))
514 return ar9002_hw_attach_ops(ah);
515
516 ar9003_hw_attach_ops(ah);
517 return 0;
Luis R. Rodriguezee2bb462009-08-03 12:24:39 -0700518}
519
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400520/* Called for all hardware families */
521static int __ath9k_hw_init(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700522{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700523 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700524 int r = 0;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700525
Senthil Balasubramanianac45c122010-12-22 21:14:20 +0530526 ath9k_hw_read_revisions(ah);
527
Senthil Balasubramanian0a8d7cb2010-12-22 19:17:18 +0530528 /*
529 * Read back AR_WA into a permanent copy and set bits 14 and 17.
530 * We need to do this to avoid RMW of this register. We cannot
531 * read the reg when chip is asleep.
532 */
Sujith Manoharan27251e02013-08-27 11:34:39 +0530533 if (AR_SREV_9300_20_OR_LATER(ah)) {
534 ah->WARegVal = REG_READ(ah, AR_WA);
535 ah->WARegVal |= (AR_WA_D3_L1_DISABLE |
536 AR_WA_ASPM_TIMER_BASED_DISABLE);
537 }
Senthil Balasubramanian0a8d7cb2010-12-22 19:17:18 +0530538
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700539 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Joe Perches38002762010-12-02 19:12:36 -0800540 ath_err(common, "Couldn't reset chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700541 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700542 }
543
Sujith Manoharana4a29542012-09-10 09:20:03 +0530544 if (AR_SREV_9565(ah)) {
545 ah->WARegVal |= AR_WA_BIT22;
546 REG_WRITE(ah, AR_WA, ah->WARegVal);
547 }
548
Luis R. Rodriguezbab1f622010-04-15 17:38:20 -0400549 ath9k_hw_init_defaults(ah);
550 ath9k_hw_init_config(ah);
551
Felix Fietkauc1b976d2012-12-12 13:14:23 +0100552 r = ath9k_hw_attach_ops(ah);
553 if (r)
554 return r;
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400555
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700556 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
Joe Perches38002762010-12-02 19:12:36 -0800557 ath_err(common, "Couldn't wakeup chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700558 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700559 }
560
Felix Fietkauf3eef642012-03-14 16:40:25 +0100561 if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700562 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
Panayiotis Karabassis7508b652012-06-26 23:37:17 +0300563 ((AR_SREV_9160(ah) || AR_SREV_9280(ah) || AR_SREV_9287(ah)) &&
John W. Linville4c85ab12010-07-28 10:06:35 -0400564 !ah->is_pciexpress)) {
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700565 ah->config.serialize_regmode =
566 SER_REG_MODE_ON;
567 } else {
568 ah->config.serialize_regmode =
569 SER_REG_MODE_OFF;
570 }
571 }
572
Joe Perchesd2182b62011-12-15 14:55:53 -0800573 ath_dbg(common, RESET, "serialize_regmode is %d\n",
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700574 ah->config.serialize_regmode);
575
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -0500576 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
577 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD >> 1;
578 else
579 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD;
580
Felix Fietkau6da5a722010-12-12 00:51:12 +0100581 switch (ah->hw_version.macVersion) {
582 case AR_SREV_VERSION_5416_PCI:
583 case AR_SREV_VERSION_5416_PCIE:
584 case AR_SREV_VERSION_9160:
585 case AR_SREV_VERSION_9100:
586 case AR_SREV_VERSION_9280:
587 case AR_SREV_VERSION_9285:
588 case AR_SREV_VERSION_9287:
589 case AR_SREV_VERSION_9271:
590 case AR_SREV_VERSION_9300:
Gabor Juhos2c8e5932011-06-21 11:23:21 +0200591 case AR_SREV_VERSION_9330:
Felix Fietkau6da5a722010-12-12 00:51:12 +0100592 case AR_SREV_VERSION_9485:
Vasanthakumar Thiagarajanbca04682011-04-19 19:29:20 +0530593 case AR_SREV_VERSION_9340:
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +0530594 case AR_SREV_VERSION_9462:
Gabor Juhos2b943a32012-07-03 19:13:34 +0200595 case AR_SREV_VERSION_9550:
Sujith Manoharan77fac462012-09-11 20:09:18 +0530596 case AR_SREV_VERSION_9565:
Felix Fietkau6da5a722010-12-12 00:51:12 +0100597 break;
598 default:
Joe Perches38002762010-12-02 19:12:36 -0800599 ath_err(common,
600 "Mac Chip Rev 0x%02x.%x is not supported by this driver\n",
601 ah->hw_version.macVersion, ah->hw_version.macRev);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700602 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700603 }
604
Gabor Juhos2c8e5932011-06-21 11:23:21 +0200605 if (AR_SREV_9271(ah) || AR_SREV_9100(ah) || AR_SREV_9340(ah) ||
Gabor Juhosc95b5842012-07-03 19:13:20 +0200606 AR_SREV_9330(ah) || AR_SREV_9550(ah))
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400607 ah->is_pciexpress = false;
608
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700609 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700610 ath9k_hw_init_cal_settings(ah);
611
612 ah->ani_function = ATH9K_ANI_ALL;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400613 if (!AR_SREV_9300_20_OR_LATER(ah))
614 ah->ani_function &= ~ATH9K_ANI_MRC_CCK;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700615
Stanislaw Gruszka69ce6742011-08-05 13:10:34 +0200616 if (!ah->is_pciexpress)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700617 ath9k_hw_disablepcie(ah);
618
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700619 r = ath9k_hw_post_init(ah);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700620 if (r)
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700621 return r;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700622
623 ath9k_hw_init_mode_gain_regs(ah);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +0100624 r = ath9k_hw_fill_cap_info(ah);
625 if (r)
626 return r;
627
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700628 r = ath9k_hw_init_macaddr(ah);
629 if (r) {
Joe Perches38002762010-12-02 19:12:36 -0800630 ath_err(common, "Failed to initialize MAC address\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700631 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700632 }
633
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400634 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
Sujith2660b812009-02-09 13:27:26 +0530635 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700636 else
Sujith2660b812009-02-09 13:27:26 +0530637 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700638
Sujith Manoharan45987022013-12-24 10:44:18 +0530639 ath9k_hw_init_hang_checks(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700640
Luis R. Rodriguez211f5852009-10-06 21:19:07 -0400641 common->state = ATH_HW_INITIALIZED;
642
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700643 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700644}
645
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400646int ath9k_hw_init(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530647{
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400648 int ret;
649 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530650
Sujith Manoharan77fac462012-09-11 20:09:18 +0530651 /* These are all the AR5008/AR9001/AR9002/AR9003 hardware family of chipsets */
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400652 switch (ah->hw_version.devid) {
653 case AR5416_DEVID_PCI:
654 case AR5416_DEVID_PCIE:
655 case AR5416_AR9100_DEVID:
656 case AR9160_DEVID_PCI:
657 case AR9280_DEVID_PCI:
658 case AR9280_DEVID_PCIE:
659 case AR9285_DEVID_PCIE:
Senthil Balasubramaniandb3cc532010-04-15 17:38:18 -0400660 case AR9287_DEVID_PCI:
661 case AR9287_DEVID_PCIE:
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400662 case AR2427_DEVID_PCIE:
Senthil Balasubramaniandb3cc532010-04-15 17:38:18 -0400663 case AR9300_DEVID_PCIE:
Vasanthakumar Thiagarajan3050c912010-12-06 04:27:36 -0800664 case AR9300_DEVID_AR9485_PCIE:
Gabor Juhos999a7a82011-06-21 11:23:52 +0200665 case AR9300_DEVID_AR9330:
Vasanthakumar Thiagarajanbca04682011-04-19 19:29:20 +0530666 case AR9300_DEVID_AR9340:
Gabor Juhos2b943a32012-07-03 19:13:34 +0200667 case AR9300_DEVID_QCA955X:
Luis R. Rodriguez5a63ef02011-08-24 15:36:08 -0700668 case AR9300_DEVID_AR9580:
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +0530669 case AR9300_DEVID_AR9462:
Mohammed Shafi Shajakhand4e59792012-08-02 11:58:50 +0530670 case AR9485_DEVID_AR1111:
Sujith Manoharan77fac462012-09-11 20:09:18 +0530671 case AR9300_DEVID_AR9565:
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400672 break;
673 default:
674 if (common->bus_ops->ath_bus_type == ATH_USB)
675 break;
Joe Perches38002762010-12-02 19:12:36 -0800676 ath_err(common, "Hardware device ID 0x%04x not supported\n",
677 ah->hw_version.devid);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400678 return -EOPNOTSUPP;
679 }
Sujithf1dc5602008-10-29 10:16:30 +0530680
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400681 ret = __ath9k_hw_init(ah);
682 if (ret) {
Joe Perches38002762010-12-02 19:12:36 -0800683 ath_err(common,
684 "Unable to initialize hardware; initialization status: %d\n",
685 ret);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400686 return ret;
687 }
Sujithf1dc5602008-10-29 10:16:30 +0530688
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400689 return 0;
Sujithf1dc5602008-10-29 10:16:30 +0530690}
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400691EXPORT_SYMBOL(ath9k_hw_init);
Sujithf1dc5602008-10-29 10:16:30 +0530692
Sujithcbe61d82009-02-09 13:27:12 +0530693static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530694{
Sujith7d0d0df2010-04-16 11:53:57 +0530695 ENABLE_REGWRITE_BUFFER(ah);
696
Sujithf1dc5602008-10-29 10:16:30 +0530697 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
698 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
699
700 REG_WRITE(ah, AR_QOS_NO_ACK,
701 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
702 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
703 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
704
705 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
706 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
707 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
708 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
709 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
Sujith7d0d0df2010-04-16 11:53:57 +0530710
711 REGWRITE_BUFFER_FLUSH(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530712}
713
Senthil Balasubramanianb84628e2011-04-22 11:32:12 +0530714u32 ar9003_get_pll_sqsum_dvc(struct ath_hw *ah)
Vivek Natarajanb1415812011-01-27 14:45:07 +0530715{
Mohammed Shafi Shajakhanf18e3c62012-06-18 13:13:30 +0530716 struct ath_common *common = ath9k_hw_common(ah);
717 int i = 0;
718
Felix Fietkauca7a4de2011-03-23 20:57:26 +0100719 REG_CLR_BIT(ah, PLL3, PLL3_DO_MEAS_MASK);
720 udelay(100);
721 REG_SET_BIT(ah, PLL3, PLL3_DO_MEAS_MASK);
722
Mohammed Shafi Shajakhanf18e3c62012-06-18 13:13:30 +0530723 while ((REG_READ(ah, PLL4) & PLL4_MEAS_DONE) == 0) {
724
Vivek Natarajanb1415812011-01-27 14:45:07 +0530725 udelay(100);
Vivek Natarajanb1415812011-01-27 14:45:07 +0530726
Mohammed Shafi Shajakhanf18e3c62012-06-18 13:13:30 +0530727 if (WARN_ON_ONCE(i >= 100)) {
728 ath_err(common, "PLL4 meaurement not done\n");
729 break;
730 }
731
732 i++;
733 }
734
Felix Fietkauca7a4de2011-03-23 20:57:26 +0100735 return (REG_READ(ah, PLL3) & SQSUM_DVC_MASK) >> 3;
Vivek Natarajanb1415812011-01-27 14:45:07 +0530736}
737EXPORT_SYMBOL(ar9003_get_pll_sqsum_dvc);
738
Sujithcbe61d82009-02-09 13:27:12 +0530739static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530740 struct ath9k_channel *chan)
741{
Vasanthakumar Thiagarajand09b17f2010-12-06 04:27:44 -0800742 u32 pll;
743
Sujith Manoharana4a29542012-09-10 09:20:03 +0530744 if (AR_SREV_9485(ah) || AR_SREV_9565(ah)) {
Vasanthakumar Thiagarajan3dfd7f62011-04-11 16:39:40 +0530745 /* program BB PLL ki and kd value, ki=0x4, kd=0x40 */
746 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
747 AR_CH0_BB_DPLL2_PLL_PWD, 0x1);
748 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
749 AR_CH0_DPLL2_KD, 0x40);
750 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
751 AR_CH0_DPLL2_KI, 0x4);
Vivek Natarajan22983c32011-01-27 14:45:09 +0530752
Vasanthakumar Thiagarajan3dfd7f62011-04-11 16:39:40 +0530753 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
754 AR_CH0_BB_DPLL1_REFDIV, 0x5);
755 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
756 AR_CH0_BB_DPLL1_NINI, 0x58);
757 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
758 AR_CH0_BB_DPLL1_NFRAC, 0x0);
759
760 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
761 AR_CH0_BB_DPLL2_OUTDIV, 0x1);
762 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
763 AR_CH0_BB_DPLL2_LOCAL_PLL, 0x1);
764 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
765 AR_CH0_BB_DPLL2_EN_NEGTRIG, 0x1);
766
767 /* program BB PLL phase_shift to 0x6 */
768 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL3,
769 AR_CH0_BB_DPLL3_PHASE_SHIFT, 0x6);
770
771 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
772 AR_CH0_BB_DPLL2_PLL_PWD, 0x0);
Vivek Natarajan75e03512011-03-10 11:05:42 +0530773 udelay(1000);
Gabor Juhosa5415d62011-06-21 11:23:29 +0200774 } else if (AR_SREV_9330(ah)) {
775 u32 ddr_dpll2, pll_control2, kd;
776
777 if (ah->is_clk_25mhz) {
778 ddr_dpll2 = 0x18e82f01;
779 pll_control2 = 0xe04a3d;
780 kd = 0x1d;
781 } else {
782 ddr_dpll2 = 0x19e82f01;
783 pll_control2 = 0x886666;
784 kd = 0x3d;
785 }
786
787 /* program DDR PLL ki and kd value */
788 REG_WRITE(ah, AR_CH0_DDR_DPLL2, ddr_dpll2);
789
790 /* program DDR PLL phase_shift */
791 REG_RMW_FIELD(ah, AR_CH0_DDR_DPLL3,
792 AR_CH0_DPLL3_PHASE_SHIFT, 0x1);
793
794 REG_WRITE(ah, AR_RTC_PLL_CONTROL, 0x1142c);
795 udelay(1000);
796
797 /* program refdiv, nint, frac to RTC register */
798 REG_WRITE(ah, AR_RTC_PLL_CONTROL2, pll_control2);
799
800 /* program BB PLL kd and ki value */
801 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, AR_CH0_DPLL2_KD, kd);
802 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, AR_CH0_DPLL2_KI, 0x06);
803
804 /* program BB PLL phase_shift */
805 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL3,
806 AR_CH0_BB_DPLL3_PHASE_SHIFT, 0x1);
Gabor Juhosfc05a312012-07-03 19:13:31 +0200807 } else if (AR_SREV_9340(ah) || AR_SREV_9550(ah)) {
Vasanthakumar Thiagarajan0b488ac2011-04-20 10:26:15 +0530808 u32 regval, pll2_divint, pll2_divfrac, refdiv;
809
810 REG_WRITE(ah, AR_RTC_PLL_CONTROL, 0x1142c);
811 udelay(1000);
812
813 REG_SET_BIT(ah, AR_PHY_PLL_MODE, 0x1 << 16);
814 udelay(100);
815
816 if (ah->is_clk_25mhz) {
817 pll2_divint = 0x54;
818 pll2_divfrac = 0x1eb85;
819 refdiv = 3;
820 } else {
Gabor Juhosfc05a312012-07-03 19:13:31 +0200821 if (AR_SREV_9340(ah)) {
822 pll2_divint = 88;
823 pll2_divfrac = 0;
824 refdiv = 5;
825 } else {
826 pll2_divint = 0x11;
827 pll2_divfrac = 0x26666;
828 refdiv = 1;
829 }
Vasanthakumar Thiagarajan0b488ac2011-04-20 10:26:15 +0530830 }
831
832 regval = REG_READ(ah, AR_PHY_PLL_MODE);
833 regval |= (0x1 << 16);
834 REG_WRITE(ah, AR_PHY_PLL_MODE, regval);
835 udelay(100);
836
837 REG_WRITE(ah, AR_PHY_PLL_CONTROL, (refdiv << 27) |
838 (pll2_divint << 18) | pll2_divfrac);
839 udelay(100);
840
841 regval = REG_READ(ah, AR_PHY_PLL_MODE);
Gabor Juhosfc05a312012-07-03 19:13:31 +0200842 if (AR_SREV_9340(ah))
843 regval = (regval & 0x80071fff) | (0x1 << 30) |
844 (0x1 << 13) | (0x4 << 26) | (0x18 << 19);
845 else
846 regval = (regval & 0x80071fff) | (0x3 << 30) |
847 (0x1 << 13) | (0x4 << 26) | (0x60 << 19);
Vasanthakumar Thiagarajan0b488ac2011-04-20 10:26:15 +0530848 REG_WRITE(ah, AR_PHY_PLL_MODE, regval);
849 REG_WRITE(ah, AR_PHY_PLL_MODE,
850 REG_READ(ah, AR_PHY_PLL_MODE) & 0xfffeffff);
851 udelay(1000);
Vivek Natarajan22983c32011-01-27 14:45:09 +0530852 }
Vasanthakumar Thiagarajand09b17f2010-12-06 04:27:44 -0800853
854 pll = ath9k_hw_compute_pll_control(ah, chan);
Sujith Manoharan8565f8b2012-09-10 09:20:29 +0530855 if (AR_SREV_9565(ah))
856 pll |= 0x40000;
Gabor Juhosd03a66c2009-01-14 20:17:09 +0100857 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +0530858
Gabor Juhosfc05a312012-07-03 19:13:31 +0200859 if (AR_SREV_9485(ah) || AR_SREV_9340(ah) || AR_SREV_9330(ah) ||
860 AR_SREV_9550(ah))
Vasanthakumar Thiagarajan3dfd7f62011-04-11 16:39:40 +0530861 udelay(1000);
862
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -0400863 /* Switch the core clock for ar9271 to 117Mhz */
864 if (AR_SREV_9271(ah)) {
Sujith25e2ab12010-03-17 14:25:22 +0530865 udelay(500);
866 REG_WRITE(ah, 0x50040, 0x304);
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -0400867 }
868
Sujithf1dc5602008-10-29 10:16:30 +0530869 udelay(RTC_PLL_SETTLE_DELAY);
870
871 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
Vasanthakumar Thiagarajan0b488ac2011-04-20 10:26:15 +0530872
Gabor Juhosfc05a312012-07-03 19:13:31 +0200873 if (AR_SREV_9340(ah) || AR_SREV_9550(ah)) {
Vasanthakumar Thiagarajan0b488ac2011-04-20 10:26:15 +0530874 if (ah->is_clk_25mhz) {
875 REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x17c << 1);
876 REG_WRITE(ah, AR_SLP32_MODE, 0x0010f3d7);
877 REG_WRITE(ah, AR_SLP32_INC, 0x0001e7ae);
878 } else {
879 REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x261 << 1);
880 REG_WRITE(ah, AR_SLP32_MODE, 0x0010f400);
881 REG_WRITE(ah, AR_SLP32_INC, 0x0001e800);
882 }
883 udelay(100);
884 }
Sujithf1dc5602008-10-29 10:16:30 +0530885}
886
Sujithcbe61d82009-02-09 13:27:12 +0530887static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -0800888 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +0530889{
Vasanthakumar Thiagarajan79d1d2b2011-04-19 19:29:19 +0530890 u32 sync_default = AR_INTR_SYNC_DEFAULT;
Pavel Roskin152d5302010-03-31 18:05:37 -0400891 u32 imr_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +0530892 AR_IMR_TXURN |
893 AR_IMR_RXERR |
894 AR_IMR_RXORN |
895 AR_IMR_BCNMISC;
896
Gabor Juhos3b8a0572012-07-03 19:13:29 +0200897 if (AR_SREV_9340(ah) || AR_SREV_9550(ah))
Vasanthakumar Thiagarajan79d1d2b2011-04-19 19:29:19 +0530898 sync_default &= ~AR_INTR_SYNC_HOST1_FATAL;
899
Vasanthakumar Thiagarajan66860242010-04-15 17:39:07 -0400900 if (AR_SREV_9300_20_OR_LATER(ah)) {
901 imr_reg |= AR_IMR_RXOK_HP;
902 if (ah->config.rx_intr_mitigation)
903 imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
904 else
905 imr_reg |= AR_IMR_RXOK_LP;
Sujithf1dc5602008-10-29 10:16:30 +0530906
Vasanthakumar Thiagarajan66860242010-04-15 17:39:07 -0400907 } else {
908 if (ah->config.rx_intr_mitigation)
909 imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
910 else
911 imr_reg |= AR_IMR_RXOK;
912 }
913
914 if (ah->config.tx_intr_mitigation)
915 imr_reg |= AR_IMR_TXINTM | AR_IMR_TXMINTR;
916 else
917 imr_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +0530918
Sujith7d0d0df2010-04-16 11:53:57 +0530919 ENABLE_REGWRITE_BUFFER(ah);
920
Pavel Roskin152d5302010-03-31 18:05:37 -0400921 REG_WRITE(ah, AR_IMR, imr_reg);
Pavel Roskin74bad5c2010-02-23 18:15:27 -0500922 ah->imrs2_reg |= AR_IMR_S2_GTT;
923 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
Sujithf1dc5602008-10-29 10:16:30 +0530924
925 if (!AR_SREV_9100(ah)) {
926 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
Vasanthakumar Thiagarajan79d1d2b2011-04-19 19:29:19 +0530927 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, sync_default);
Sujithf1dc5602008-10-29 10:16:30 +0530928 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
929 }
Vasanthakumar Thiagarajan66860242010-04-15 17:39:07 -0400930
Sujith7d0d0df2010-04-16 11:53:57 +0530931 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +0530932
Vasanthakumar Thiagarajan66860242010-04-15 17:39:07 -0400933 if (AR_SREV_9300_20_OR_LATER(ah)) {
934 REG_WRITE(ah, AR_INTR_PRIO_ASYNC_ENABLE, 0);
935 REG_WRITE(ah, AR_INTR_PRIO_ASYNC_MASK, 0);
936 REG_WRITE(ah, AR_INTR_PRIO_SYNC_ENABLE, 0);
937 REG_WRITE(ah, AR_INTR_PRIO_SYNC_MASK, 0);
938 }
Sujithf1dc5602008-10-29 10:16:30 +0530939}
940
Felix Fietkaub6ba41b2011-07-09 11:12:50 +0700941static void ath9k_hw_set_sifs_time(struct ath_hw *ah, u32 us)
942{
943 u32 val = ath9k_hw_mac_to_clks(ah, us - 2);
944 val = min(val, (u32) 0xFFFF);
945 REG_WRITE(ah, AR_D_GBL_IFS_SIFS, val);
946}
947
Felix Fietkau0005baf2010-01-15 02:33:40 +0100948static void ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +0530949{
Felix Fietkau0005baf2010-01-15 02:33:40 +0100950 u32 val = ath9k_hw_mac_to_clks(ah, us);
951 val = min(val, (u32) 0xFFFF);
952 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, val);
Sujithf1dc5602008-10-29 10:16:30 +0530953}
954
Felix Fietkau0005baf2010-01-15 02:33:40 +0100955static void ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +0530956{
Felix Fietkau0005baf2010-01-15 02:33:40 +0100957 u32 val = ath9k_hw_mac_to_clks(ah, us);
958 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_ACK));
959 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_ACK, val);
960}
961
962static void ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
963{
964 u32 val = ath9k_hw_mac_to_clks(ah, us);
965 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_CTS));
966 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_CTS, val);
Sujithf1dc5602008-10-29 10:16:30 +0530967}
968
Sujithcbe61d82009-02-09 13:27:12 +0530969static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +0530970{
Sujithf1dc5602008-10-29 10:16:30 +0530971 if (tu > 0xFFFF) {
Joe Perchesd2182b62011-12-15 14:55:53 -0800972 ath_dbg(ath9k_hw_common(ah), XMIT, "bad global tx timeout %u\n",
973 tu);
Sujith2660b812009-02-09 13:27:26 +0530974 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +0530975 return false;
976 } else {
977 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +0530978 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +0530979 return true;
980 }
981}
982
Felix Fietkau0005baf2010-01-15 02:33:40 +0100983void ath9k_hw_init_global_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530984{
Felix Fietkaub6ba41b2011-07-09 11:12:50 +0700985 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkaub6ba41b2011-07-09 11:12:50 +0700986 const struct ath9k_channel *chan = ah->curchan;
Felix Fietkaue115b7e2012-04-19 21:18:23 +0200987 int acktimeout, ctstimeout, ack_offset = 0;
Felix Fietkaue239d852010-01-15 02:34:58 +0100988 int slottime;
Felix Fietkau0005baf2010-01-15 02:33:40 +0100989 int sifstime;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +0700990 int rx_lat = 0, tx_lat = 0, eifs = 0;
991 u32 reg;
Felix Fietkau0005baf2010-01-15 02:33:40 +0100992
Joe Perchesd2182b62011-12-15 14:55:53 -0800993 ath_dbg(ath9k_hw_common(ah), RESET, "ah->misc_mode 0x%x\n",
Joe Perches226afe62010-12-02 19:12:37 -0800994 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +0530995
Felix Fietkaub6ba41b2011-07-09 11:12:50 +0700996 if (!chan)
997 return;
998
Sujith2660b812009-02-09 13:27:26 +0530999 if (ah->misc_mode != 0)
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001000 REG_SET_BIT(ah, AR_PCU_MISC, ah->misc_mode);
Felix Fietkau0005baf2010-01-15 02:33:40 +01001001
Rajkumar Manoharan81a91d52011-08-31 10:47:30 +05301002 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
1003 rx_lat = 41;
1004 else
1005 rx_lat = 37;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001006 tx_lat = 54;
1007
Felix Fietkaue88e4862012-04-19 21:18:22 +02001008 if (IS_CHAN_5GHZ(chan))
1009 sifstime = 16;
1010 else
1011 sifstime = 10;
1012
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001013 if (IS_CHAN_HALF_RATE(chan)) {
1014 eifs = 175;
1015 rx_lat *= 2;
1016 tx_lat *= 2;
1017 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
1018 tx_lat += 11;
1019
Simon Wunderlich92367fe72013-08-14 08:01:30 +02001020 sifstime = 32;
Felix Fietkaue115b7e2012-04-19 21:18:23 +02001021 ack_offset = 16;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001022 slottime = 13;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001023 } else if (IS_CHAN_QUARTER_RATE(chan)) {
1024 eifs = 340;
Rajkumar Manoharan81a91d52011-08-31 10:47:30 +05301025 rx_lat = (rx_lat * 4) - 1;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001026 tx_lat *= 4;
1027 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
1028 tx_lat += 22;
1029
Simon Wunderlich92367fe72013-08-14 08:01:30 +02001030 sifstime = 64;
Felix Fietkaue115b7e2012-04-19 21:18:23 +02001031 ack_offset = 32;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001032 slottime = 21;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001033 } else {
Rajkumar Manoharana7be0392011-08-27 12:13:21 +05301034 if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah)) {
1035 eifs = AR_D_GBL_IFS_EIFS_ASYNC_FIFO;
1036 reg = AR_USEC_ASYNC_FIFO;
1037 } else {
1038 eifs = REG_READ(ah, AR_D_GBL_IFS_EIFS)/
1039 common->clockrate;
1040 reg = REG_READ(ah, AR_USEC);
1041 }
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001042 rx_lat = MS(reg, AR_USEC_RX_LAT);
1043 tx_lat = MS(reg, AR_USEC_TX_LAT);
1044
1045 slottime = ah->slottime;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001046 }
Felix Fietkau0005baf2010-01-15 02:33:40 +01001047
Felix Fietkaue239d852010-01-15 02:34:58 +01001048 /* As defined by IEEE 802.11-2007 17.3.8.6 */
Mathias Kretschmerf77f8232013-04-22 22:34:41 +02001049 slottime += 3 * ah->coverage_class;
1050 acktimeout = slottime + sifstime + ack_offset;
Felix Fietkauadb50662011-08-28 01:52:10 +02001051 ctstimeout = acktimeout;
Felix Fietkau42c45682010-02-11 18:07:19 +01001052
1053 /*
1054 * Workaround for early ACK timeouts, add an offset to match the
Felix Fietkau55a2bb42012-02-05 21:15:18 +01001055 * initval's 64us ack timeout value. Use 48us for the CTS timeout.
Felix Fietkau42c45682010-02-11 18:07:19 +01001056 * This was initially only meant to work around an issue with delayed
1057 * BA frames in some implementations, but it has been found to fix ACK
1058 * timeout issues in other cases as well.
1059 */
Felix Fietkaue4744ec2013-10-11 23:31:01 +02001060 if (IS_CHAN_2GHZ(chan) &&
Felix Fietkaue115b7e2012-04-19 21:18:23 +02001061 !IS_CHAN_HALF_RATE(chan) && !IS_CHAN_QUARTER_RATE(chan)) {
Felix Fietkau42c45682010-02-11 18:07:19 +01001062 acktimeout += 64 - sifstime - ah->slottime;
Felix Fietkau55a2bb42012-02-05 21:15:18 +01001063 ctstimeout += 48 - sifstime - ah->slottime;
1064 }
1065
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001066 ath9k_hw_set_sifs_time(ah, sifstime);
1067 ath9k_hw_setslottime(ah, slottime);
Felix Fietkau0005baf2010-01-15 02:33:40 +01001068 ath9k_hw_set_ack_timeout(ah, acktimeout);
Felix Fietkauadb50662011-08-28 01:52:10 +02001069 ath9k_hw_set_cts_timeout(ah, ctstimeout);
Sujith2660b812009-02-09 13:27:26 +05301070 if (ah->globaltxtimeout != (u32) -1)
1071 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001072
1073 REG_WRITE(ah, AR_D_GBL_IFS_EIFS, ath9k_hw_mac_to_clks(ah, eifs));
1074 REG_RMW(ah, AR_USEC,
1075 (common->clockrate - 1) |
1076 SM(rx_lat, AR_USEC_RX_LAT) |
1077 SM(tx_lat, AR_USEC_TX_LAT),
1078 AR_USEC_TX_LAT | AR_USEC_RX_LAT | AR_USEC_USEC);
1079
Sujithf1dc5602008-10-29 10:16:30 +05301080}
Felix Fietkau0005baf2010-01-15 02:33:40 +01001081EXPORT_SYMBOL(ath9k_hw_init_global_settings);
Sujithf1dc5602008-10-29 10:16:30 +05301082
Sujith285f2dd2010-01-08 10:36:07 +05301083void ath9k_hw_deinit(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001084{
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001085 struct ath_common *common = ath9k_hw_common(ah);
1086
Sujith736b3a22010-03-17 14:25:24 +05301087 if (common->state < ATH_HW_INITIALIZED)
Felix Fietkauc1b976d2012-12-12 13:14:23 +01001088 return;
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001089
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001090 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001091}
Sujith285f2dd2010-01-08 10:36:07 +05301092EXPORT_SYMBOL(ath9k_hw_deinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001093
Sujithf1dc5602008-10-29 10:16:30 +05301094/*******/
1095/* INI */
1096/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001097
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001098u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan)
Bob Copeland3a702e42009-03-30 22:30:29 -04001099{
1100 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
1101
Felix Fietkau6b21fd22013-10-11 23:30:56 +02001102 if (IS_CHAN_2GHZ(chan))
Bob Copeland3a702e42009-03-30 22:30:29 -04001103 ctl |= CTL_11G;
1104 else
1105 ctl |= CTL_11A;
1106
1107 return ctl;
1108}
1109
Sujithf1dc5602008-10-29 10:16:30 +05301110/****************************************/
1111/* Reset and Channel Switching Routines */
1112/****************************************/
1113
Sujithcbe61d82009-02-09 13:27:12 +05301114static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301115{
Felix Fietkau57b32222010-04-15 17:39:22 -04001116 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkau86c157b2013-05-23 12:20:56 +02001117 int txbuf_size;
Sujithf1dc5602008-10-29 10:16:30 +05301118
Sujith7d0d0df2010-04-16 11:53:57 +05301119 ENABLE_REGWRITE_BUFFER(ah);
1120
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001121 /*
1122 * set AHB_MODE not to do cacheline prefetches
1123 */
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001124 if (!AR_SREV_9300_20_OR_LATER(ah))
1125 REG_SET_BIT(ah, AR_AHB_MODE, AR_AHB_PREFETCH_RD_EN);
Sujithf1dc5602008-10-29 10:16:30 +05301126
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001127 /*
1128 * let mac dma reads be in 128 byte chunks
1129 */
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001130 REG_RMW(ah, AR_TXCFG, AR_TXCFG_DMASZ_128B, AR_TXCFG_DMASZ_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05301131
Sujith7d0d0df2010-04-16 11:53:57 +05301132 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301133
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001134 /*
1135 * Restore TX Trigger Level to its pre-reset value.
1136 * The initial value depends on whether aggregation is enabled, and is
1137 * adjusted whenever underruns are detected.
1138 */
Felix Fietkau57b32222010-04-15 17:39:22 -04001139 if (!AR_SREV_9300_20_OR_LATER(ah))
1140 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +05301141
Sujith7d0d0df2010-04-16 11:53:57 +05301142 ENABLE_REGWRITE_BUFFER(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301143
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001144 /*
1145 * let mac dma writes be in 128 byte chunks
1146 */
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001147 REG_RMW(ah, AR_RXCFG, AR_RXCFG_DMASZ_128B, AR_RXCFG_DMASZ_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05301148
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001149 /*
1150 * Setup receive FIFO threshold to hold off TX activities
1151 */
Sujithf1dc5602008-10-29 10:16:30 +05301152 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1153
Felix Fietkau57b32222010-04-15 17:39:22 -04001154 if (AR_SREV_9300_20_OR_LATER(ah)) {
1155 REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_HP, 0x1);
1156 REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_LP, 0x1);
1157
1158 ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize -
1159 ah->caps.rx_status_len);
1160 }
1161
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001162 /*
1163 * reduce the number of usable entries in PCU TXBUF to avoid
1164 * wrap around issues.
1165 */
Sujithf1dc5602008-10-29 10:16:30 +05301166 if (AR_SREV_9285(ah)) {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001167 /* For AR9285 the number of Fifos are reduced to half.
1168 * So set the usable tx buf size also to half to
1169 * avoid data/delimiter underruns
1170 */
Felix Fietkau86c157b2013-05-23 12:20:56 +02001171 txbuf_size = AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE;
1172 } else if (AR_SREV_9340_13_OR_LATER(ah)) {
1173 /* Uses fewer entries for AR934x v1.3+ to prevent rx overruns */
1174 txbuf_size = AR_9340_PCU_TXBUF_CTRL_USABLE_SIZE;
1175 } else {
1176 txbuf_size = AR_PCU_TXBUF_CTRL_USABLE_SIZE;
Sujithf1dc5602008-10-29 10:16:30 +05301177 }
Vasanthakumar Thiagarajan744d4022010-04-15 17:39:27 -04001178
Felix Fietkau86c157b2013-05-23 12:20:56 +02001179 if (!AR_SREV_9271(ah))
1180 REG_WRITE(ah, AR_PCU_TXBUF_CTRL, txbuf_size);
1181
Sujith7d0d0df2010-04-16 11:53:57 +05301182 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301183
Vasanthakumar Thiagarajan744d4022010-04-15 17:39:27 -04001184 if (AR_SREV_9300_20_OR_LATER(ah))
1185 ath9k_hw_reset_txstatus_ring(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301186}
1187
Sujithcbe61d82009-02-09 13:27:12 +05301188static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301189{
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001190 u32 mask = AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC;
1191 u32 set = AR_STA_ID1_KSRCH_MODE;
Sujithf1dc5602008-10-29 10:16:30 +05301192
Sujithf1dc5602008-10-29 10:16:30 +05301193 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001194 case NL80211_IFTYPE_ADHOC:
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001195 set |= AR_STA_ID1_ADHOC;
Sujithf1dc5602008-10-29 10:16:30 +05301196 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1197 break;
Thomas Pedersen2664d662013-05-08 10:16:48 -07001198 case NL80211_IFTYPE_MESH_POINT:
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001199 case NL80211_IFTYPE_AP:
1200 set |= AR_STA_ID1_STA_AP;
1201 /* fall through */
Colin McCabed97809d2008-12-01 13:38:55 -08001202 case NL80211_IFTYPE_STATION:
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001203 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
Sujithf1dc5602008-10-29 10:16:30 +05301204 break;
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +05301205 default:
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001206 if (!ah->is_monitoring)
1207 set = 0;
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +05301208 break;
Sujithf1dc5602008-10-29 10:16:30 +05301209 }
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001210 REG_RMW(ah, AR_STA_ID1, set, mask);
Sujithf1dc5602008-10-29 10:16:30 +05301211}
1212
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001213void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled,
1214 u32 *coef_mantissa, u32 *coef_exponent)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001215{
1216 u32 coef_exp, coef_man;
1217
1218 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1219 if ((coef_scaled >> coef_exp) & 0x1)
1220 break;
1221
1222 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1223
1224 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1225
1226 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1227 *coef_exponent = coef_exp - 16;
1228}
1229
Sujith Manoharand7df7a52013-12-18 09:53:27 +05301230/* AR9330 WAR:
1231 * call external reset function to reset WMAC if:
1232 * - doing a cold reset
1233 * - we have pending frames in the TX queues.
1234 */
1235static bool ath9k_hw_ar9330_reset_war(struct ath_hw *ah, int type)
1236{
1237 int i, npend = 0;
1238
1239 for (i = 0; i < AR_NUM_QCU; i++) {
1240 npend = ath9k_hw_numtxpending(ah, i);
1241 if (npend)
1242 break;
1243 }
1244
1245 if (ah->external_reset &&
1246 (npend || type == ATH9K_RESET_COLD)) {
1247 int reset_err = 0;
1248
1249 ath_dbg(ath9k_hw_common(ah), RESET,
1250 "reset MAC via external reset\n");
1251
1252 reset_err = ah->external_reset();
1253 if (reset_err) {
1254 ath_err(ath9k_hw_common(ah),
1255 "External reset failed, err=%d\n",
1256 reset_err);
1257 return false;
1258 }
1259
1260 REG_WRITE(ah, AR_RTC_RESET, 1);
1261 }
1262
1263 return true;
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);
Felix Fietkaua37a9912013-05-23 12:20:55 +02001292 if (AR_SREV_9340(ah))
1293 tmpReg &= AR9340_INTR_SYNC_LOCAL_TIMEOUT;
1294 else
1295 tmpReg &= AR_INTR_SYNC_LOCAL_TIMEOUT |
1296 AR_INTR_SYNC_RADM_CPL_TIMEOUT;
1297
1298 if (tmpReg) {
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001299 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05301300 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001301
1302 val = AR_RC_HOSTIF;
1303 if (!AR_SREV_9300_20_OR_LATER(ah))
1304 val |= AR_RC_AHB;
1305 REG_WRITE(ah, AR_RC, val);
1306
1307 } else if (!AR_SREV_9300_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05301308 REG_WRITE(ah, AR_RC, AR_RC_AHB);
Sujithf1dc5602008-10-29 10:16:30 +05301309
1310 rst_flags = AR_RTC_RC_MAC_WARM;
1311 if (type == ATH9K_RESET_COLD)
1312 rst_flags |= AR_RTC_RC_MAC_COLD;
1313 }
1314
Gabor Juhos7d95847c2011-06-21 11:23:51 +02001315 if (AR_SREV_9330(ah)) {
Sujith Manoharand7df7a52013-12-18 09:53:27 +05301316 if (!ath9k_hw_ar9330_reset_war(ah, type))
1317 return false;
Gabor Juhos7d95847c2011-06-21 11:23:51 +02001318 }
1319
Rajkumar Manoharan38634952012-06-11 12:19:32 +05301320 if (ath9k_hw_mci_is_enabled(ah))
Rajkumar Manoharan506847a2012-06-12 20:18:16 +05301321 ar9003_mci_check_gpm_offset(ah);
Rajkumar Manoharan38634952012-06-11 12:19:32 +05301322
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001323 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujith7d0d0df2010-04-16 11:53:57 +05301324
1325 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301326
Sujith Manoharan4dc78c432013-12-18 09:53:26 +05301327 if (AR_SREV_9300_20_OR_LATER(ah))
1328 udelay(50);
1329 else if (AR_SREV_9100(ah))
1330 udelay(10000);
1331 else
1332 udelay(100);
Sujithf1dc5602008-10-29 10:16:30 +05301333
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001334 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301335 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001336 ath_dbg(ath9k_hw_common(ah), RESET, "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301337 return false;
1338 }
1339
1340 if (!AR_SREV_9100(ah))
1341 REG_WRITE(ah, AR_RC, 0);
1342
Sujithf1dc5602008-10-29 10:16:30 +05301343 if (AR_SREV_9100(ah))
1344 udelay(50);
1345
1346 return true;
1347}
1348
Sujithcbe61d82009-02-09 13:27:12 +05301349static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301350{
Sujith7d0d0df2010-04-16 11:53:57 +05301351 ENABLE_REGWRITE_BUFFER(ah);
1352
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04001353 if (AR_SREV_9300_20_OR_LATER(ah)) {
1354 REG_WRITE(ah, AR_WA, ah->WARegVal);
1355 udelay(10);
1356 }
1357
Sujithf1dc5602008-10-29 10:16:30 +05301358 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1359 AR_RTC_FORCE_WAKE_ON_INT);
1360
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001361 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301362 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1363
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001364 REG_WRITE(ah, AR_RTC_RESET, 0);
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301365
Sujith7d0d0df2010-04-16 11:53:57 +05301366 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301367
Sujith Manoharanafe36532013-12-18 09:53:25 +05301368 udelay(2);
Senthil Balasubramanian84e21692010-04-15 17:38:30 -04001369
1370 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301371 REG_WRITE(ah, AR_RC, 0);
1372
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001373 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301374
1375 if (!ath9k_hw_wait(ah,
1376 AR_RTC_STATUS,
1377 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301378 AR_RTC_STATUS_ON,
1379 AH_WAIT_TIMEOUT)) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001380 ath_dbg(ath9k_hw_common(ah), RESET, "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301381 return false;
1382 }
1383
Sujithf1dc5602008-10-29 10:16:30 +05301384 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1385}
1386
Sujithcbe61d82009-02-09 13:27:12 +05301387static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301388{
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301389 bool ret = false;
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05301390
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04001391 if (AR_SREV_9300_20_OR_LATER(ah)) {
1392 REG_WRITE(ah, AR_WA, ah->WARegVal);
1393 udelay(10);
1394 }
1395
Sujithf1dc5602008-10-29 10:16:30 +05301396 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1397 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1398
Felix Fietkauceb26a62012-10-03 21:07:51 +02001399 if (!ah->reset_power_on)
1400 type = ATH9K_RESET_POWER_ON;
1401
Sujithf1dc5602008-10-29 10:16:30 +05301402 switch (type) {
1403 case ATH9K_RESET_POWER_ON:
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301404 ret = ath9k_hw_set_reset_power_on(ah);
Sujith Manoharanda8fb122012-11-17 21:20:50 +05301405 if (ret)
Felix Fietkauceb26a62012-10-03 21:07:51 +02001406 ah->reset_power_on = true;
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301407 break;
Sujithf1dc5602008-10-29 10:16:30 +05301408 case ATH9K_RESET_WARM:
1409 case ATH9K_RESET_COLD:
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301410 ret = ath9k_hw_set_reset(ah, type);
1411 break;
Sujithf1dc5602008-10-29 10:16:30 +05301412 default:
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301413 break;
Sujithf1dc5602008-10-29 10:16:30 +05301414 }
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301415
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301416 return ret;
Sujithf1dc5602008-10-29 10:16:30 +05301417}
1418
Sujithcbe61d82009-02-09 13:27:12 +05301419static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301420 struct ath9k_channel *chan)
1421{
Felix Fietkau9c083af2012-03-03 15:17:02 +01001422 int reset_type = ATH9K_RESET_WARM;
1423
1424 if (AR_SREV_9280(ah)) {
1425 if (ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1426 reset_type = ATH9K_RESET_POWER_ON;
1427 else
1428 reset_type = ATH9K_RESET_COLD;
Felix Fietkau3412f2f02013-02-25 20:51:07 +01001429 } else if (ah->chip_fullsleep || REG_READ(ah, AR_Q_TXE) ||
1430 (REG_READ(ah, AR_CR) & AR_CR_RXE))
1431 reset_type = ATH9K_RESET_COLD;
Felix Fietkau9c083af2012-03-03 15:17:02 +01001432
1433 if (!ath9k_hw_set_reset_reg(ah, reset_type))
Sujithf1dc5602008-10-29 10:16:30 +05301434 return false;
1435
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001436 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05301437 return false;
1438
Sujith2660b812009-02-09 13:27:26 +05301439 ah->chip_fullsleep = false;
Felix Fietkaubfc441a2012-05-24 14:32:22 +02001440
1441 if (AR_SREV_9330(ah))
1442 ar9003_hw_internal_regulator_apply(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301443 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301444
1445 return true;
1446}
1447
Sujithcbe61d82009-02-09 13:27:12 +05301448static bool ath9k_hw_channel_change(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001449 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301450{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001451 struct ath_common *common = ath9k_hw_common(ah);
Sujith Manoharanb840cff2013-07-16 12:03:19 +05301452 struct ath9k_hw_capabilities *pCap = &ah->caps;
1453 bool band_switch = false, mode_diff = false;
Sujith Manoharan70e89a72013-07-16 12:03:22 +05301454 u8 ini_reloaded = 0;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001455 u32 qnum;
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001456 int r;
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301457
Sujith Manoharanb840cff2013-07-16 12:03:19 +05301458 if (pCap->hw_caps & ATH9K_HW_CAP_FCC_BAND_SWITCH) {
Felix Fietkauaf02efb2013-11-18 20:14:44 +01001459 u32 flags_diff = chan->channelFlags ^ ah->curchan->channelFlags;
1460 band_switch = !!(flags_diff & CHANNEL_5GHZ);
1461 mode_diff = !!(flags_diff & ~CHANNEL_HT);
Sujith Manoharanb840cff2013-07-16 12:03:19 +05301462 }
Sujithf1dc5602008-10-29 10:16:30 +05301463
1464 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1465 if (ath9k_hw_numtxpending(ah, qnum)) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001466 ath_dbg(common, QUEUE,
Joe Perches226afe62010-12-02 19:12:37 -08001467 "Transmit frames pending on queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301468 return false;
1469 }
1470 }
1471
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001472 if (!ath9k_hw_rfbus_req(ah)) {
Joe Perches38002762010-12-02 19:12:36 -08001473 ath_err(common, "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301474 return false;
1475 }
1476
Sujith Manoharanb840cff2013-07-16 12:03:19 +05301477 if (band_switch || mode_diff) {
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301478 ath9k_hw_mark_phy_inactive(ah);
1479 udelay(5);
1480
Sujith Manoharan5f35c0f2013-07-16 12:03:20 +05301481 if (band_switch)
1482 ath9k_hw_init_pll(ah, chan);
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301483
1484 if (ath9k_hw_fast_chan_change(ah, chan, &ini_reloaded)) {
1485 ath_err(common, "Failed to do fast channel change\n");
1486 return false;
1487 }
1488 }
1489
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001490 ath9k_hw_set_channel_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301491
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001492 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001493 if (r) {
Joe Perches38002762010-12-02 19:12:36 -08001494 ath_err(common, "Failed to set channel\n");
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001495 return false;
Sujithf1dc5602008-10-29 10:16:30 +05301496 }
Felix Fietkaudfdac8a2010-10-08 22:13:51 +02001497 ath9k_hw_set_clockrate(ah);
Gabor Juhos64ea57d2012-04-15 20:38:05 +02001498 ath9k_hw_apply_txpower(ah, chan, false);
Sujithf1dc5602008-10-29 10:16:30 +05301499
Felix Fietkau81c507a2013-10-11 23:30:55 +02001500 ath9k_hw_set_delta_slope(ah, chan);
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001501 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301502
Sujith Manoharan70e89a72013-07-16 12:03:22 +05301503 if (band_switch || ini_reloaded)
1504 ah->eep_ops->set_board_values(ah, chan);
1505
1506 ath9k_hw_init_bb(ah, chan);
1507 ath9k_hw_rfbus_done(ah);
1508
1509 if (band_switch || ini_reloaded) {
Rajkumar Manoharana126ff52011-10-13 11:00:42 +05301510 ah->ah_flags |= AH_FASTCC;
Sujith Manoharan70e89a72013-07-16 12:03:22 +05301511 ath9k_hw_init_cal(ah, chan);
Rajkumar Manoharana126ff52011-10-13 11:00:42 +05301512 ah->ah_flags &= ~AH_FASTCC;
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301513 }
1514
Sujithf1dc5602008-10-29 10:16:30 +05301515 return true;
1516}
1517
Felix Fietkau691680b2011-03-19 13:55:38 +01001518static void ath9k_hw_apply_gpio_override(struct ath_hw *ah)
1519{
1520 u32 gpio_mask = ah->gpio_mask;
1521 int i;
1522
1523 for (i = 0; gpio_mask; i++, gpio_mask >>= 1) {
1524 if (!(gpio_mask & 1))
1525 continue;
1526
1527 ath9k_hw_cfg_output(ah, i, AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1528 ath9k_hw_set_gpio(ah, i, !!(ah->gpio_val & BIT(i)));
1529 }
1530}
1531
Rajkumar Manoharan01e18912012-03-15 05:34:27 +05301532static bool ath9k_hw_check_dcs(u32 dma_dbg, u32 num_dcu_states,
1533 int *hang_state, int *hang_pos)
1534{
1535 static u32 dcu_chain_state[] = {5, 6, 9}; /* DCU chain stuck states */
1536 u32 chain_state, dcs_pos, i;
1537
1538 for (dcs_pos = 0; dcs_pos < num_dcu_states; dcs_pos++) {
1539 chain_state = (dma_dbg >> (5 * dcs_pos)) & 0x1f;
1540 for (i = 0; i < 3; i++) {
1541 if (chain_state == dcu_chain_state[i]) {
1542 *hang_state = chain_state;
1543 *hang_pos = dcs_pos;
1544 return true;
1545 }
1546 }
1547 }
1548 return false;
1549}
1550
1551#define DCU_COMPLETE_STATE 1
1552#define DCU_COMPLETE_STATE_MASK 0x3
1553#define NUM_STATUS_READS 50
1554static bool ath9k_hw_detect_mac_hang(struct ath_hw *ah)
1555{
1556 u32 chain_state, comp_state, dcs_reg = AR_DMADBG_4;
1557 u32 i, hang_pos, hang_state, num_state = 6;
1558
1559 comp_state = REG_READ(ah, AR_DMADBG_6);
1560
1561 if ((comp_state & DCU_COMPLETE_STATE_MASK) != DCU_COMPLETE_STATE) {
1562 ath_dbg(ath9k_hw_common(ah), RESET,
1563 "MAC Hang signature not found at DCU complete\n");
1564 return false;
1565 }
1566
1567 chain_state = REG_READ(ah, dcs_reg);
1568 if (ath9k_hw_check_dcs(chain_state, num_state, &hang_state, &hang_pos))
1569 goto hang_check_iter;
1570
1571 dcs_reg = AR_DMADBG_5;
1572 num_state = 4;
1573 chain_state = REG_READ(ah, dcs_reg);
1574 if (ath9k_hw_check_dcs(chain_state, num_state, &hang_state, &hang_pos))
1575 goto hang_check_iter;
1576
1577 ath_dbg(ath9k_hw_common(ah), RESET,
1578 "MAC Hang signature 1 not found\n");
1579 return false;
1580
1581hang_check_iter:
1582 ath_dbg(ath9k_hw_common(ah), RESET,
1583 "DCU registers: chain %08x complete %08x Hang: state %d pos %d\n",
1584 chain_state, comp_state, hang_state, hang_pos);
1585
1586 for (i = 0; i < NUM_STATUS_READS; i++) {
1587 chain_state = REG_READ(ah, dcs_reg);
1588 chain_state = (chain_state >> (5 * hang_pos)) & 0x1f;
1589 comp_state = REG_READ(ah, AR_DMADBG_6);
1590
1591 if (((comp_state & DCU_COMPLETE_STATE_MASK) !=
1592 DCU_COMPLETE_STATE) ||
1593 (chain_state != hang_state))
1594 return false;
1595 }
1596
1597 ath_dbg(ath9k_hw_common(ah), RESET, "MAC Hang signature 1 found\n");
1598
1599 return true;
1600}
1601
Sujith Manoharan1e516ca2013-09-11 21:30:27 +05301602void ath9k_hw_check_nav(struct ath_hw *ah)
1603{
1604 struct ath_common *common = ath9k_hw_common(ah);
1605 u32 val;
1606
1607 val = REG_READ(ah, AR_NAV);
1608 if (val != 0xdeadbeef && val > 0x7fff) {
1609 ath_dbg(common, BSTUCK, "Abnormal NAV: 0x%x\n", val);
1610 REG_WRITE(ah, AR_NAV, 0);
1611 }
1612}
1613EXPORT_SYMBOL(ath9k_hw_check_nav);
1614
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001615bool ath9k_hw_check_alive(struct ath_hw *ah)
Johannes Berg3b319aa2009-06-13 14:50:26 +05301616{
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001617 int count = 50;
1618 u32 reg;
Johannes Berg3b319aa2009-06-13 14:50:26 +05301619
Rajkumar Manoharan01e18912012-03-15 05:34:27 +05301620 if (AR_SREV_9300(ah))
1621 return !ath9k_hw_detect_mac_hang(ah);
1622
Felix Fietkaue17f83e2010-09-22 12:34:53 +02001623 if (AR_SREV_9285_12_OR_LATER(ah))
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001624 return true;
Johannes Berg3b319aa2009-06-13 14:50:26 +05301625
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001626 do {
1627 reg = REG_READ(ah, AR_OBS_BUS_1);
1628
1629 if ((reg & 0x7E7FFFEF) == 0x00702400)
1630 continue;
1631
1632 switch (reg & 0x7E000B00) {
1633 case 0x1E000000:
1634 case 0x52000B00:
1635 case 0x18000B00:
1636 continue;
1637 default:
1638 return true;
1639 }
1640 } while (count-- > 0);
1641
1642 return false;
Johannes Berg3b319aa2009-06-13 14:50:26 +05301643}
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001644EXPORT_SYMBOL(ath9k_hw_check_alive);
Johannes Berg3b319aa2009-06-13 14:50:26 +05301645
Sujith Manoharan15d2b582013-03-04 12:42:53 +05301646static void ath9k_hw_init_mfp(struct ath_hw *ah)
1647{
1648 /* Setup MFP options for CCMP */
1649 if (AR_SREV_9280_20_OR_LATER(ah)) {
1650 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
1651 * frames when constructing CCMP AAD. */
1652 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
1653 0xc7ff);
1654 ah->sw_mgmt_crypto = false;
1655 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1656 /* Disable hardware crypto for management frames */
1657 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
1658 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
1659 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1660 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
1661 ah->sw_mgmt_crypto = true;
1662 } else {
1663 ah->sw_mgmt_crypto = true;
1664 }
1665}
1666
1667static void ath9k_hw_reset_opmode(struct ath_hw *ah,
1668 u32 macStaId1, u32 saveDefAntenna)
1669{
1670 struct ath_common *common = ath9k_hw_common(ah);
1671
1672 ENABLE_REGWRITE_BUFFER(ah);
1673
Felix Fietkauecbbed32013-04-16 12:51:56 +02001674 REG_RMW(ah, AR_STA_ID1, macStaId1
Sujith Manoharan15d2b582013-03-04 12:42:53 +05301675 | AR_STA_ID1_RTS_USE_DEF
1676 | (ah->config.ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Felix Fietkauecbbed32013-04-16 12:51:56 +02001677 | ah->sta_id1_defaults,
1678 ~AR_STA_ID1_SADH_MASK);
Sujith Manoharan15d2b582013-03-04 12:42:53 +05301679 ath_hw_setbssidmask(common);
1680 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
1681 ath9k_hw_write_associd(ah);
1682 REG_WRITE(ah, AR_ISR, ~0);
1683 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
1684
1685 REGWRITE_BUFFER_FLUSH(ah);
1686
1687 ath9k_hw_set_operating_mode(ah, ah->opmode);
1688}
1689
1690static void ath9k_hw_init_queues(struct ath_hw *ah)
1691{
1692 int i;
1693
1694 ENABLE_REGWRITE_BUFFER(ah);
1695
1696 for (i = 0; i < AR_NUM_DCU; i++)
1697 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
1698
1699 REGWRITE_BUFFER_FLUSH(ah);
1700
1701 ah->intr_txqs = 0;
1702 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1703 ath9k_hw_resettxqueue(ah, i);
1704}
1705
1706/*
1707 * For big endian systems turn on swapping for descriptors
1708 */
1709static void ath9k_hw_init_desc(struct ath_hw *ah)
1710{
1711 struct ath_common *common = ath9k_hw_common(ah);
1712
1713 if (AR_SREV_9100(ah)) {
1714 u32 mask;
1715 mask = REG_READ(ah, AR_CFG);
1716 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
1717 ath_dbg(common, RESET, "CFG Byte Swap Set 0x%x\n",
1718 mask);
1719 } else {
1720 mask = INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
1721 REG_WRITE(ah, AR_CFG, mask);
1722 ath_dbg(common, RESET, "Setting CFG 0x%x\n",
1723 REG_READ(ah, AR_CFG));
1724 }
1725 } else {
1726 if (common->bus_ops->ath_bus_type == ATH_USB) {
1727 /* Configure AR9271 target WLAN */
1728 if (AR_SREV_9271(ah))
1729 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
1730 else
1731 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
1732 }
1733#ifdef __BIG_ENDIAN
1734 else if (AR_SREV_9330(ah) || AR_SREV_9340(ah) ||
1735 AR_SREV_9550(ah))
1736 REG_RMW(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB, 0);
1737 else
1738 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
1739#endif
1740 }
1741}
1742
Sujith Manoharancaed6572012-03-14 14:40:46 +05301743/*
1744 * Fast channel change:
1745 * (Change synthesizer based on channel freq without resetting chip)
Sujith Manoharancaed6572012-03-14 14:40:46 +05301746 */
1747static int ath9k_hw_do_fastcc(struct ath_hw *ah, struct ath9k_channel *chan)
1748{
1749 struct ath_common *common = ath9k_hw_common(ah);
Sujith Manoharanb840cff2013-07-16 12:03:19 +05301750 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujith Manoharancaed6572012-03-14 14:40:46 +05301751 int ret;
1752
1753 if (AR_SREV_9280(ah) && common->bus_ops->ath_bus_type == ATH_PCI)
1754 goto fail;
1755
1756 if (ah->chip_fullsleep)
1757 goto fail;
1758
1759 if (!ah->curchan)
1760 goto fail;
1761
1762 if (chan->channel == ah->curchan->channel)
1763 goto fail;
1764
Felix Fietkaufeb7bc92012-04-19 21:18:28 +02001765 if ((ah->curchan->channelFlags | chan->channelFlags) &
1766 (CHANNEL_HALF | CHANNEL_QUARTER))
1767 goto fail;
1768
Sujith Manoharanb840cff2013-07-16 12:03:19 +05301769 /*
Felix Fietkau6b21fd22013-10-11 23:30:56 +02001770 * If cross-band fcc is not supoprted, bail out if channelFlags differ.
Sujith Manoharanb840cff2013-07-16 12:03:19 +05301771 */
Felix Fietkau6b21fd22013-10-11 23:30:56 +02001772 if (!(pCap->hw_caps & ATH9K_HW_CAP_FCC_BAND_SWITCH) &&
Felix Fietkauaf02efb2013-11-18 20:14:44 +01001773 ((chan->channelFlags ^ ah->curchan->channelFlags) & ~CHANNEL_HT))
Felix Fietkau6b21fd22013-10-11 23:30:56 +02001774 goto fail;
Sujith Manoharancaed6572012-03-14 14:40:46 +05301775
1776 if (!ath9k_hw_check_alive(ah))
1777 goto fail;
1778
1779 /*
1780 * For AR9462, make sure that calibration data for
1781 * re-using are present.
1782 */
Sujith Manoharan8a905552012-05-04 13:23:59 +05301783 if (AR_SREV_9462(ah) && (ah->caldata &&
Sujith Manoharan4b9b42b2013-09-11 16:36:31 +05301784 (!test_bit(TXIQCAL_DONE, &ah->caldata->cal_flags) ||
1785 !test_bit(TXCLCAL_DONE, &ah->caldata->cal_flags) ||
1786 !test_bit(RTT_DONE, &ah->caldata->cal_flags))))
Sujith Manoharancaed6572012-03-14 14:40:46 +05301787 goto fail;
1788
1789 ath_dbg(common, RESET, "FastChannelChange for %d -> %d\n",
1790 ah->curchan->channel, chan->channel);
1791
1792 ret = ath9k_hw_channel_change(ah, chan);
1793 if (!ret)
1794 goto fail;
1795
Sujith Manoharan5955b2b2012-06-04 16:27:30 +05301796 if (ath9k_hw_mci_is_enabled(ah))
Rajkumar Manoharan1bde95fa2012-06-11 12:19:33 +05301797 ar9003_mci_2g5g_switch(ah, false);
Sujith Manoharancaed6572012-03-14 14:40:46 +05301798
Rajkumar Manoharan88033312012-09-12 18:59:19 +05301799 ath9k_hw_loadnf(ah, ah->curchan);
1800 ath9k_hw_start_nfcal(ah, true);
1801
Sujith Manoharancaed6572012-03-14 14:40:46 +05301802 if (AR_SREV_9271(ah))
1803 ar9002_hw_load_ani_reg(ah, chan);
1804
1805 return 0;
1806fail:
1807 return -EINVAL;
1808}
1809
Sujithcbe61d82009-02-09 13:27:12 +05301810int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Sujith Manoharancaed6572012-03-14 14:40:46 +05301811 struct ath9k_hw_cal_data *caldata, bool fastcc)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001812{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001813 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkau09d8e312013-11-18 20:14:43 +01001814 struct timespec ts;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001815 u32 saveLedState;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001816 u32 saveDefAntenna;
1817 u32 macStaId1;
Sujith46fe7822009-09-17 09:25:25 +05301818 u64 tsf = 0;
Felix Fietkau09d8e312013-11-18 20:14:43 +01001819 s64 usec = 0;
Sujith Manoharan15d2b582013-03-04 12:42:53 +05301820 int r;
Sujith Manoharancaed6572012-03-14 14:40:46 +05301821 bool start_mci_reset = false;
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301822 bool save_fullsleep = ah->chip_fullsleep;
1823
Sujith Manoharan5955b2b2012-06-04 16:27:30 +05301824 if (ath9k_hw_mci_is_enabled(ah)) {
Sujith Manoharan528e5d32012-02-22 12:41:12 +05301825 start_mci_reset = ar9003_mci_start_reset(ah, chan);
1826 if (start_mci_reset)
1827 return 0;
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301828 }
1829
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001830 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001831 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001832
Sujith Manoharancaed6572012-03-14 14:40:46 +05301833 if (ah->curchan && !ah->chip_fullsleep)
1834 ath9k_hw_getnf(ah, ah->curchan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001835
Felix Fietkau20bd2a02010-07-31 00:12:00 +02001836 ah->caldata = caldata;
Sujith Manoharanfcb9a3d2013-03-04 12:42:52 +05301837 if (caldata && (chan->channel != caldata->channel ||
Felix Fietkau6b21fd22013-10-11 23:30:56 +02001838 chan->channelFlags != caldata->channelFlags)) {
Felix Fietkau20bd2a02010-07-31 00:12:00 +02001839 /* Operating channel changed, reset channel calibration data */
1840 memset(caldata, 0, sizeof(*caldata));
1841 ath9k_init_nfcal_hist_buffer(ah, chan);
Felix Fietkau51dea9b2012-08-27 17:00:07 +02001842 } else if (caldata) {
Sujith Manoharan4b9b42b2013-09-11 16:36:31 +05301843 clear_bit(PAPRD_PACKET_SENT, &caldata->cal_flags);
Felix Fietkau20bd2a02010-07-31 00:12:00 +02001844 }
Lorenzo Bianconi5bc225a2013-10-11 14:09:54 +02001845 ah->noise = ath9k_hw_getchan_noise(ah, chan, chan->noisefloor);
Felix Fietkau20bd2a02010-07-31 00:12:00 +02001846
Sujith Manoharancaed6572012-03-14 14:40:46 +05301847 if (fastcc) {
1848 r = ath9k_hw_do_fastcc(ah, chan);
1849 if (!r)
1850 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001851 }
1852
Sujith Manoharan5955b2b2012-06-04 16:27:30 +05301853 if (ath9k_hw_mci_is_enabled(ah))
Sujith Manoharan528e5d32012-02-22 12:41:12 +05301854 ar9003_mci_stop_bt(ah, save_fullsleep);
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301855
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001856 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
1857 if (saveDefAntenna == 0)
1858 saveDefAntenna = 1;
1859
1860 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
1861
Felix Fietkau09d8e312013-11-18 20:14:43 +01001862 /* Save TSF before chip reset, a cold reset clears it */
1863 tsf = ath9k_hw_gettsf64(ah);
1864 getrawmonotonic(&ts);
Felix Fietkaucca213f2013-12-20 17:02:24 +01001865 usec = ts.tv_sec * 1000000ULL + ts.tv_nsec / 1000;
Sujith46fe7822009-09-17 09:25:25 +05301866
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001867 saveLedState = REG_READ(ah, AR_CFG_LED) &
1868 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
1869 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
1870
1871 ath9k_hw_mark_phy_inactive(ah);
1872
Vasanthakumar Thiagarajan45ef6a02010-12-15 07:30:53 -08001873 ah->paprd_table_write_done = false;
1874
Sujith05020d22010-03-17 14:25:23 +05301875 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001876 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1877 REG_WRITE(ah,
1878 AR9271_RESET_POWER_DOWN_CONTROL,
1879 AR9271_RADIO_RF_RST);
1880 udelay(50);
1881 }
1882
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001883 if (!ath9k_hw_chip_reset(ah, chan)) {
Joe Perches38002762010-12-02 19:12:36 -08001884 ath_err(common, "Chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001885 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001886 }
1887
Sujith05020d22010-03-17 14:25:23 +05301888 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001889 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1890 ah->htc_reset_init = false;
1891 REG_WRITE(ah,
1892 AR9271_RESET_POWER_DOWN_CONTROL,
1893 AR9271_GATE_MAC_CTL);
1894 udelay(50);
1895 }
1896
Sujith46fe7822009-09-17 09:25:25 +05301897 /* Restore TSF */
Felix Fietkau09d8e312013-11-18 20:14:43 +01001898 getrawmonotonic(&ts);
Felix Fietkaucca213f2013-12-20 17:02:24 +01001899 usec = ts.tv_sec * 1000000ULL + ts.tv_nsec / 1000 - usec;
Felix Fietkau09d8e312013-11-18 20:14:43 +01001900 ath9k_hw_settsf64(ah, tsf + usec);
Sujith46fe7822009-09-17 09:25:25 +05301901
Felix Fietkau7a370812010-09-22 12:34:52 +02001902 if (AR_SREV_9280_20_OR_LATER(ah))
Vasanthakumar Thiagarajan369391d2009-01-21 19:24:13 +05301903 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001904
Sujithe9141f72010-06-01 15:14:10 +05301905 if (!AR_SREV_9300_20_OR_LATER(ah))
1906 ar9002_hw_enable_async_fifo(ah);
1907
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001908 r = ath9k_hw_process_ini(ah, chan);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001909 if (r)
1910 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001911
Lorenzo Bianconi935d00c2013-12-12 18:10:16 +01001912 ath9k_hw_set_rfmode(ah, chan);
1913
Sujith Manoharan5955b2b2012-06-04 16:27:30 +05301914 if (ath9k_hw_mci_is_enabled(ah))
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301915 ar9003_mci_reset(ah, false, IS_CHAN_2GHZ(chan), save_fullsleep);
1916
Felix Fietkauf860d522010-06-30 02:07:48 +02001917 /*
1918 * Some AR91xx SoC devices frequently fail to accept TSF writes
1919 * right after the chip reset. When that happens, write a new
1920 * value after the initvals have been applied, with an offset
1921 * based on measured time difference
1922 */
1923 if (AR_SREV_9100(ah) && (ath9k_hw_gettsf64(ah) < tsf)) {
1924 tsf += 1500;
1925 ath9k_hw_settsf64(ah, tsf);
1926 }
1927
Sujith Manoharan15d2b582013-03-04 12:42:53 +05301928 ath9k_hw_init_mfp(ah);
Jouni Malinen0ced0e12009-01-08 13:32:13 +02001929
Felix Fietkau81c507a2013-10-11 23:30:55 +02001930 ath9k_hw_set_delta_slope(ah, chan);
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001931 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithd6509152009-03-13 08:56:05 +05301932 ah->eep_ops->set_board_values(ah, chan);
Luis R. Rodrigueza7765822009-10-19 02:33:45 -04001933
Sujith Manoharan15d2b582013-03-04 12:42:53 +05301934 ath9k_hw_reset_opmode(ah, macStaId1, saveDefAntenna);
Sujith Manoharan00e00032011-01-26 21:59:05 +05301935
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001936 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001937 if (r)
1938 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001939
Felix Fietkaudfdac8a2010-10-08 22:13:51 +02001940 ath9k_hw_set_clockrate(ah);
1941
Sujith Manoharan15d2b582013-03-04 12:42:53 +05301942 ath9k_hw_init_queues(ah);
Sujith2660b812009-02-09 13:27:26 +05301943 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001944 ath9k_hw_ani_cache_ini_regs(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001945 ath9k_hw_init_qos(ah);
1946
Sujith2660b812009-02-09 13:27:26 +05301947 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Felix Fietkau55821322010-12-17 00:57:01 +01001948 ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
Johannes Berg3b319aa2009-06-13 14:50:26 +05301949
Felix Fietkau0005baf2010-01-15 02:33:40 +01001950 ath9k_hw_init_global_settings(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001951
Felix Fietkaufe2b6af2011-07-09 11:12:51 +07001952 if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah)) {
1953 REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
1954 AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
1955 REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
1956 AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
1957 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1958 AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301959 }
1960
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001961 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PRESERVE_SEQNUM);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001962
1963 ath9k_hw_set_dma(ah);
1964
Rajkumar Manoharaned6ebd82012-06-11 12:19:34 +05301965 if (!ath9k_hw_mci_is_enabled(ah))
1966 REG_WRITE(ah, AR_OBS, 8);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001967
Sujith0ce024c2009-12-14 14:57:00 +05301968 if (ah->config.rx_intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001969 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
1970 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
1971 }
1972
Vasanthakumar Thiagarajan7f62a132010-04-15 17:39:19 -04001973 if (ah->config.tx_intr_mitigation) {
1974 REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_LAST, 300);
1975 REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_FIRST, 750);
1976 }
1977
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001978 ath9k_hw_init_bb(ah, chan);
1979
Rajkumar Manoharan77a5a662011-10-13 11:00:37 +05301980 if (caldata) {
Sujith Manoharan4b9b42b2013-09-11 16:36:31 +05301981 clear_bit(TXIQCAL_DONE, &caldata->cal_flags);
1982 clear_bit(TXCLCAL_DONE, &caldata->cal_flags);
Rajkumar Manoharan77a5a662011-10-13 11:00:37 +05301983 }
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001984 if (!ath9k_hw_init_cal(ah, chan))
Joe Perches6badaaf2009-06-28 09:26:32 -07001985 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001986
Sujith Manoharan5955b2b2012-06-04 16:27:30 +05301987 if (ath9k_hw_mci_is_enabled(ah) && ar9003_mci_end_reset(ah, chan, caldata))
Sujith Manoharan528e5d32012-02-22 12:41:12 +05301988 return -EIO;
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301989
Sujith7d0d0df2010-04-16 11:53:57 +05301990 ENABLE_REGWRITE_BUFFER(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001991
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001992 ath9k_hw_restore_chainmask(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001993 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
1994
Sujith7d0d0df2010-04-16 11:53:57 +05301995 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301996
Sujith Manoharan15d2b582013-03-04 12:42:53 +05301997 ath9k_hw_init_desc(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001998
Sujith Manoharandbccdd12012-02-22 17:55:47 +05301999 if (ath9k_hw_btcoex_is_enabled(ah))
Vasanthakumar Thiagarajan42cc41e2009-08-26 21:08:45 +05302000 ath9k_hw_btcoex_enable(ah);
2001
Sujith Manoharan5955b2b2012-06-04 16:27:30 +05302002 if (ath9k_hw_mci_is_enabled(ah))
Sujith Manoharan528e5d32012-02-22 12:41:12 +05302003 ar9003_mci_check_bt(ah);
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05302004
Rajkumar Manoharan1fe860e2012-07-01 19:53:51 +05302005 ath9k_hw_loadnf(ah, chan);
2006 ath9k_hw_start_nfcal(ah, true);
2007
Rajkumar Manoharan51ac8cb2011-05-20 17:52:13 +05302008 if (AR_SREV_9300_20_OR_LATER(ah)) {
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04002009 ar9003_hw_bb_watchdog_config(ah);
Rajkumar Manoharan51ac8cb2011-05-20 17:52:13 +05302010 ar9003_hw_disable_phy_restart(ah);
2011 }
2012
Felix Fietkau691680b2011-03-19 13:55:38 +01002013 ath9k_hw_apply_gpio_override(ah);
2014
Sujith Manoharan7bdea962013-08-04 14:22:00 +05302015 if (AR_SREV_9565(ah) && common->bt_ant_diversity)
Sujith Manoharan362cd032012-09-16 08:06:36 +05302016 REG_SET_BIT(ah, AR_BTCOEX_WL_LNADIV, AR_BTCOEX_WL_LNADIV_FORCE_ON);
2017
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002018 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002019}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002020EXPORT_SYMBOL(ath9k_hw_reset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002021
Sujithf1dc5602008-10-29 10:16:30 +05302022/******************************/
2023/* Power Management (Chipset) */
2024/******************************/
2025
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04002026/*
2027 * Notify Power Mgt is disabled in self-generated frames.
2028 * If requested, force chip to sleep.
2029 */
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302030static void ath9k_set_power_sleep(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302031{
2032 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302033
Sujith Manoharana4a29542012-09-10 09:20:03 +05302034 if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
Rajkumar Manoharan153dccd2012-06-04 16:28:47 +05302035 REG_CLR_BIT(ah, AR_TIMER_MODE, 0xff);
2036 REG_CLR_BIT(ah, AR_NDP2_TIMER_MODE, 0xff);
2037 REG_CLR_BIT(ah, AR_SLP32_INC, 0xfffff);
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302038 /* xxx Required for WLAN only case ? */
2039 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_EN, 0);
2040 udelay(100);
2041 }
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302042
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302043 /*
2044 * Clear the RTC force wake bit to allow the
2045 * mac to go to sleep.
2046 */
2047 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN);
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302048
Rajkumar Manoharan153dccd2012-06-04 16:28:47 +05302049 if (ath9k_hw_mci_is_enabled(ah))
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302050 udelay(100);
Sujithf1dc5602008-10-29 10:16:30 +05302051
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302052 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
2053 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
2054
2055 /* Shutdown chip. Active low */
2056 if (!AR_SREV_5416(ah) && !AR_SREV_9271(ah)) {
2057 REG_CLR_BIT(ah, AR_RTC_RESET, AR_RTC_RESET_EN);
2058 udelay(2);
Sujithf1dc5602008-10-29 10:16:30 +05302059 }
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04002060
2061 /* Clear Bit 14 of AR_WA after putting chip into Full Sleep mode. */
Rafael J. Wysockia7322812011-11-26 23:37:43 +01002062 if (AR_SREV_9300_20_OR_LATER(ah))
2063 REG_WRITE(ah, AR_WA, ah->WARegVal & ~AR_WA_D3_L1_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002064}
2065
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04002066/*
2067 * Notify Power Management is enabled in self-generating
2068 * frames. If request, set power mode of chip to
2069 * auto/normal. Duration in units of 128us (1/8 TU).
2070 */
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302071static void ath9k_set_power_network_sleep(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002072{
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302073 struct ath9k_hw_capabilities *pCap = &ah->caps;
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302074
Sujithf1dc5602008-10-29 10:16:30 +05302075 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002076
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302077 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
2078 /* Set WakeOnInterrupt bit; clear ForceWake bit */
2079 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2080 AR_RTC_FORCE_WAKE_ON_INT);
2081 } else {
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302082
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302083 /* When chip goes into network sleep, it could be waken
2084 * up by MCI_INT interrupt caused by BT's HW messages
2085 * (LNA_xxx, CONT_xxx) which chould be in a very fast
2086 * rate (~100us). This will cause chip to leave and
2087 * re-enter network sleep mode frequently, which in
2088 * consequence will have WLAN MCI HW to generate lots of
2089 * SYS_WAKING and SYS_SLEEPING messages which will make
2090 * BT CPU to busy to process.
2091 */
Rajkumar Manoharan153dccd2012-06-04 16:28:47 +05302092 if (ath9k_hw_mci_is_enabled(ah))
2093 REG_CLR_BIT(ah, AR_MCI_INTERRUPT_RX_MSG_EN,
2094 AR_MCI_INTERRUPT_RX_HW_MSG_MASK);
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302095 /*
2096 * Clear the RTC force wake bit to allow the
2097 * mac to go to sleep.
2098 */
Rajkumar Manoharan153dccd2012-06-04 16:28:47 +05302099 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN);
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302100
Rajkumar Manoharan153dccd2012-06-04 16:28:47 +05302101 if (ath9k_hw_mci_is_enabled(ah))
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302102 udelay(30);
Sujithf1dc5602008-10-29 10:16:30 +05302103 }
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04002104
2105 /* Clear Bit 14 of AR_WA after putting chip into Net Sleep mode. */
2106 if (AR_SREV_9300_20_OR_LATER(ah))
2107 REG_WRITE(ah, AR_WA, ah->WARegVal & ~AR_WA_D3_L1_DISABLE);
Sujithf1dc5602008-10-29 10:16:30 +05302108}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002109
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302110static bool ath9k_hw_set_power_awake(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302111{
2112 u32 val;
2113 int i;
2114
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04002115 /* Set Bits 14 and 17 of AR_WA before powering on the chip. */
2116 if (AR_SREV_9300_20_OR_LATER(ah)) {
2117 REG_WRITE(ah, AR_WA, ah->WARegVal);
2118 udelay(10);
2119 }
2120
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302121 if ((REG_READ(ah, AR_RTC_STATUS) &
2122 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2123 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Sujithf1dc5602008-10-29 10:16:30 +05302124 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002125 }
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302126 if (!AR_SREV_9300_20_OR_LATER(ah))
2127 ath9k_hw_init_pll(ah, NULL);
2128 }
2129 if (AR_SREV_9100(ah))
2130 REG_SET_BIT(ah, AR_RTC_RESET,
2131 AR_RTC_RESET_EN);
2132
2133 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2134 AR_RTC_FORCE_WAKE_EN);
2135 udelay(50);
2136
2137 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2138 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2139 if (val == AR_RTC_STATUS_ON)
2140 break;
2141 udelay(50);
2142 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2143 AR_RTC_FORCE_WAKE_EN);
2144 }
2145 if (i == 0) {
2146 ath_err(ath9k_hw_common(ah),
2147 "Failed to wakeup in %uus\n",
2148 POWER_UP_TIME / 20);
2149 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002150 }
2151
Rajkumar Manoharancdbe4082012-10-25 17:16:53 +05302152 if (ath9k_hw_mci_is_enabled(ah))
2153 ar9003_mci_set_power_awake(ah);
2154
Sujithf1dc5602008-10-29 10:16:30 +05302155 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2156
2157 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002158}
2159
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002160bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05302161{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002162 struct ath_common *common = ath9k_hw_common(ah);
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302163 int status = true;
Sujithf1dc5602008-10-29 10:16:30 +05302164 static const char *modes[] = {
2165 "AWAKE",
2166 "FULL-SLEEP",
2167 "NETWORK SLEEP",
2168 "UNDEFINED"
2169 };
Sujithf1dc5602008-10-29 10:16:30 +05302170
Gabor Juhoscbdec972009-07-24 17:27:22 +02002171 if (ah->power_mode == mode)
2172 return status;
2173
Joe Perchesd2182b62011-12-15 14:55:53 -08002174 ath_dbg(common, RESET, "%s -> %s\n",
Joe Perches226afe62010-12-02 19:12:37 -08002175 modes[ah->power_mode], modes[mode]);
Sujithf1dc5602008-10-29 10:16:30 +05302176
2177 switch (mode) {
2178 case ATH9K_PM_AWAKE:
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302179 status = ath9k_hw_set_power_awake(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302180 break;
2181 case ATH9K_PM_FULL_SLEEP:
Sujith Manoharan5955b2b2012-06-04 16:27:30 +05302182 if (ath9k_hw_mci_is_enabled(ah))
Sujith Manoharand1ca8b82012-02-22 12:41:01 +05302183 ar9003_mci_set_full_sleep(ah);
Mohammed Shafi Shajakhan10109112011-11-30 10:41:24 +05302184
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302185 ath9k_set_power_sleep(ah);
Sujith2660b812009-02-09 13:27:26 +05302186 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05302187 break;
2188 case ATH9K_PM_NETWORK_SLEEP:
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302189 ath9k_set_power_network_sleep(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302190 break;
2191 default:
Joe Perches38002762010-12-02 19:12:36 -08002192 ath_err(common, "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05302193 return false;
2194 }
Sujith2660b812009-02-09 13:27:26 +05302195 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05302196
Luis R. Rodriguez69f4aab2010-12-07 15:13:23 -08002197 /*
2198 * XXX: If this warning never comes up after a while then
2199 * simply keep the ATH_DBG_WARN_ON_ONCE() but make
2200 * ath9k_hw_setpower() return type void.
2201 */
Sujith Manoharan97dcec52010-12-20 08:02:42 +05302202
2203 if (!(ah->ah_flags & AH_UNPLUGGED))
2204 ATH_DBG_WARN_ON_ONCE(!status);
Luis R. Rodriguez69f4aab2010-12-07 15:13:23 -08002205
Sujithf1dc5602008-10-29 10:16:30 +05302206 return status;
2207}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002208EXPORT_SYMBOL(ath9k_hw_setpower);
Sujithf1dc5602008-10-29 10:16:30 +05302209
Sujithf1dc5602008-10-29 10:16:30 +05302210/*******************/
2211/* Beacon Handling */
2212/*******************/
2213
Sujithcbe61d82009-02-09 13:27:12 +05302214void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002215{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002216 int flags = 0;
2217
Sujith7d0d0df2010-04-16 11:53:57 +05302218 ENABLE_REGWRITE_BUFFER(ah);
2219
Sujith2660b812009-02-09 13:27:26 +05302220 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08002221 case NL80211_IFTYPE_ADHOC:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002222 REG_SET_BIT(ah, AR_TXCFG,
2223 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
Thomas Pedersen2664d662013-05-08 10:16:48 -07002224 case NL80211_IFTYPE_MESH_POINT:
Colin McCabed97809d2008-12-01 13:38:55 -08002225 case NL80211_IFTYPE_AP:
Felix Fietkaudd347f22011-03-22 21:54:17 +01002226 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, next_beacon);
2227 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, next_beacon -
2228 TU_TO_USEC(ah->config.dma_beacon_response_time));
2229 REG_WRITE(ah, AR_NEXT_SWBA, next_beacon -
2230 TU_TO_USEC(ah->config.sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002231 flags |=
2232 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
2233 break;
Colin McCabed97809d2008-12-01 13:38:55 -08002234 default:
Joe Perchesd2182b62011-12-15 14:55:53 -08002235 ath_dbg(ath9k_hw_common(ah), BEACON,
2236 "%s: unsupported opmode: %d\n", __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08002237 return;
2238 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002239 }
2240
Felix Fietkaudd347f22011-03-22 21:54:17 +01002241 REG_WRITE(ah, AR_BEACON_PERIOD, beacon_period);
2242 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, beacon_period);
2243 REG_WRITE(ah, AR_SWBA_PERIOD, beacon_period);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002244
Sujith7d0d0df2010-04-16 11:53:57 +05302245 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05302246
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002247 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
2248}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002249EXPORT_SYMBOL(ath9k_hw_beaconinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002250
Sujithcbe61d82009-02-09 13:27:12 +05302251void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05302252 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002253{
2254 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05302255 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002256 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002257
Sujith7d0d0df2010-04-16 11:53:57 +05302258 ENABLE_REGWRITE_BUFFER(ah);
2259
Felix Fietkau4ed15762013-12-14 18:03:44 +01002260 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, bs->bs_nexttbtt);
2261 REG_WRITE(ah, AR_BEACON_PERIOD, bs->bs_intval);
2262 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, bs->bs_intval);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002263
Sujith7d0d0df2010-04-16 11:53:57 +05302264 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05302265
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002266 REG_RMW_FIELD(ah, AR_RSSI_THR,
2267 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
2268
Rajkumar Manoharanf29f5c02011-05-20 17:52:11 +05302269 beaconintval = bs->bs_intval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002270
2271 if (bs->bs_sleepduration > beaconintval)
2272 beaconintval = bs->bs_sleepduration;
2273
2274 dtimperiod = bs->bs_dtimperiod;
2275 if (bs->bs_sleepduration > dtimperiod)
2276 dtimperiod = bs->bs_sleepduration;
2277
2278 if (beaconintval == dtimperiod)
2279 nextTbtt = bs->bs_nextdtim;
2280 else
2281 nextTbtt = bs->bs_nexttbtt;
2282
Joe Perchesd2182b62011-12-15 14:55:53 -08002283 ath_dbg(common, BEACON, "next DTIM %d\n", bs->bs_nextdtim);
2284 ath_dbg(common, BEACON, "next beacon %d\n", nextTbtt);
2285 ath_dbg(common, BEACON, "beacon period %d\n", beaconintval);
2286 ath_dbg(common, BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002287
Sujith7d0d0df2010-04-16 11:53:57 +05302288 ENABLE_REGWRITE_BUFFER(ah);
2289
Felix Fietkau4ed15762013-12-14 18:03:44 +01002290 REG_WRITE(ah, AR_NEXT_DTIM, bs->bs_nextdtim - SLEEP_SLOP);
2291 REG_WRITE(ah, AR_NEXT_TIM, nextTbtt - SLEEP_SLOP);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002292
2293 REG_WRITE(ah, AR_SLEEP1,
2294 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
2295 | AR_SLEEP1_ASSUME_DTIM);
2296
Sujith60b67f52008-08-07 10:52:38 +05302297 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002298 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
2299 else
2300 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
2301
2302 REG_WRITE(ah, AR_SLEEP2,
2303 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
2304
Felix Fietkau4ed15762013-12-14 18:03:44 +01002305 REG_WRITE(ah, AR_TIM_PERIOD, beaconintval);
2306 REG_WRITE(ah, AR_DTIM_PERIOD, dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002307
Sujith7d0d0df2010-04-16 11:53:57 +05302308 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05302309
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002310 REG_SET_BIT(ah, AR_TIMER_MODE,
2311 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
2312 AR_DTIM_TIMER_EN);
2313
Sujith4af9cf42009-02-12 10:06:47 +05302314 /* TSF Out of Range Threshold */
2315 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002316}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002317EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002318
Sujithf1dc5602008-10-29 10:16:30 +05302319/*******************/
2320/* HW Capabilities */
2321/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002322
Felix Fietkau60540692011-07-19 08:46:44 +02002323static u8 fixup_chainmask(u8 chip_chainmask, u8 eeprom_chainmask)
2324{
2325 eeprom_chainmask &= chip_chainmask;
2326 if (eeprom_chainmask)
2327 return eeprom_chainmask;
2328 else
2329 return chip_chainmask;
2330}
2331
Zefir Kurtisi9a66af32011-12-14 20:16:33 -08002332/**
2333 * ath9k_hw_dfs_tested - checks if DFS has been tested with used chipset
2334 * @ah: the atheros hardware data structure
2335 *
2336 * We enable DFS support upstream on chipsets which have passed a series
2337 * of tests. The testing requirements are going to be documented. Desired
2338 * test requirements are documented at:
2339 *
2340 * http://wireless.kernel.org/en/users/Drivers/ath9k/dfs
2341 *
2342 * Once a new chipset gets properly tested an individual commit can be used
2343 * to document the testing for DFS for that chipset.
2344 */
2345static bool ath9k_hw_dfs_tested(struct ath_hw *ah)
2346{
2347
2348 switch (ah->hw_version.macVersion) {
Zefir Kurtisi73e49372013-04-03 18:31:31 +02002349 /* for temporary testing DFS with 9280 */
2350 case AR_SREV_VERSION_9280:
Zefir Kurtisi9a66af32011-12-14 20:16:33 -08002351 /* AR9580 will likely be our first target to get testing on */
2352 case AR_SREV_VERSION_9580:
Zefir Kurtisi73e49372013-04-03 18:31:31 +02002353 return true;
Zefir Kurtisi9a66af32011-12-14 20:16:33 -08002354 default:
2355 return false;
2356 }
2357}
2358
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002359int ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002360{
Sujith2660b812009-02-09 13:27:26 +05302361 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002362 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002363 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkau60540692011-07-19 08:46:44 +02002364 unsigned int chip_chainmask;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002365
Sujith Manoharan0ff2b5c2011-04-20 11:00:34 +05302366 u16 eeval;
Vasanthakumar Thiagarajan47c80de2010-12-06 04:27:43 -08002367 u8 ant_div_ctl1, tx_chainmask, rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002368
Sujithf74df6f2009-02-09 13:27:24 +05302369 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002370 regulatory->current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05302371
Sujith2660b812009-02-09 13:27:26 +05302372 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05302373 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002374 if (regulatory->current_rd == 0x64 ||
2375 regulatory->current_rd == 0x65)
2376 regulatory->current_rd += 5;
2377 else if (regulatory->current_rd == 0x41)
2378 regulatory->current_rd = 0x43;
Joe Perchesd2182b62011-12-15 14:55:53 -08002379 ath_dbg(common, REGULATORY, "regdomain mapped to 0x%x\n",
2380 regulatory->current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002381 }
Sujithdc2222a2008-08-14 13:26:55 +05302382
Sujithf74df6f2009-02-09 13:27:24 +05302383 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002384 if ((eeval & (AR5416_OPFLAGS_11G | AR5416_OPFLAGS_11A)) == 0) {
Joe Perches38002762010-12-02 19:12:36 -08002385 ath_err(common,
2386 "no band has been marked as supported in EEPROM\n");
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002387 return -EINVAL;
2388 }
2389
Felix Fietkaud4659912010-10-14 16:02:39 +02002390 if (eeval & AR5416_OPFLAGS_11A)
2391 pCap->hw_caps |= ATH9K_HW_CAP_5GHZ;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002392
Felix Fietkaud4659912010-10-14 16:02:39 +02002393 if (eeval & AR5416_OPFLAGS_11G)
2394 pCap->hw_caps |= ATH9K_HW_CAP_2GHZ;
Sujithf1dc5602008-10-29 10:16:30 +05302395
Sujith Manoharane41db612012-09-10 09:20:12 +05302396 if (AR_SREV_9485(ah) ||
2397 AR_SREV_9285(ah) ||
2398 AR_SREV_9330(ah) ||
2399 AR_SREV_9565(ah))
Felix Fietkau60540692011-07-19 08:46:44 +02002400 chip_chainmask = 1;
Mohammed Shafi Shajakhanba5736a2011-11-30 21:10:52 +05302401 else if (AR_SREV_9462(ah))
2402 chip_chainmask = 3;
Felix Fietkau60540692011-07-19 08:46:44 +02002403 else if (!AR_SREV_9280_20_OR_LATER(ah))
2404 chip_chainmask = 7;
2405 else if (!AR_SREV_9300_20_OR_LATER(ah) || AR_SREV_9340(ah))
2406 chip_chainmask = 3;
2407 else
2408 chip_chainmask = 7;
2409
Sujithf74df6f2009-02-09 13:27:24 +05302410 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002411 /*
2412 * For AR9271 we will temporarilly uses the rx chainmax as read from
2413 * the EEPROM.
2414 */
Sujith8147f5d2009-02-20 15:13:23 +05302415 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002416 !(eeval & AR5416_OPFLAGS_11A) &&
2417 !(AR_SREV_9271(ah)))
2418 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
Sujith8147f5d2009-02-20 15:13:23 +05302419 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
Felix Fietkau598cdd52011-03-19 13:55:42 +01002420 else if (AR_SREV_9100(ah))
2421 pCap->rx_chainmask = 0x7;
Sujith8147f5d2009-02-20 15:13:23 +05302422 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002423 /* Use rx_chainmask from EEPROM. */
Sujith8147f5d2009-02-20 15:13:23 +05302424 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05302425
Felix Fietkau60540692011-07-19 08:46:44 +02002426 pCap->tx_chainmask = fixup_chainmask(chip_chainmask, pCap->tx_chainmask);
2427 pCap->rx_chainmask = fixup_chainmask(chip_chainmask, pCap->rx_chainmask);
Felix Fietkau82b2d332011-09-03 01:40:23 +02002428 ah->txchainmask = pCap->tx_chainmask;
2429 ah->rxchainmask = pCap->rx_chainmask;
Felix Fietkau60540692011-07-19 08:46:44 +02002430
Felix Fietkau7a370812010-09-22 12:34:52 +02002431 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05302432
Felix Fietkau02d2ebb2010-11-22 15:39:39 +01002433 /* enable key search for every frame in an aggregate */
2434 if (AR_SREV_9300_20_OR_LATER(ah))
2435 ah->misc_mode |= AR_PCU_ALWAYS_PERFORM_KEYSEARCH;
2436
Bruno Randolfce2220d2010-09-17 11:36:25 +09002437 common->crypt_caps |= ATH_CRYPT_CAP_CIPHER_AESCCM;
2438
Felix Fietkau0db156e2011-03-23 20:57:29 +01002439 if (ah->hw_version.devid != AR2427_DEVID_PCIE)
Sujithf1dc5602008-10-29 10:16:30 +05302440 pCap->hw_caps |= ATH9K_HW_CAP_HT;
2441 else
2442 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
2443
Sujith5b5fa352010-03-17 14:25:15 +05302444 if (AR_SREV_9271(ah))
2445 pCap->num_gpio_pins = AR9271_NUM_GPIO;
Sujith88c1f4f2010-06-30 14:46:31 +05302446 else if (AR_DEVID_7010(ah))
2447 pCap->num_gpio_pins = AR7010_NUM_GPIO;
Mohammed Shafi Shajakhan6321eb02011-09-30 11:31:27 +05302448 else if (AR_SREV_9300_20_OR_LATER(ah))
2449 pCap->num_gpio_pins = AR9300_NUM_GPIO;
2450 else if (AR_SREV_9287_11_OR_LATER(ah))
2451 pCap->num_gpio_pins = AR9287_NUM_GPIO;
Felix Fietkaue17f83e2010-09-22 12:34:53 +02002452 else if (AR_SREV_9285_12_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302453 pCap->num_gpio_pins = AR9285_NUM_GPIO;
Felix Fietkau7a370812010-09-22 12:34:52 +02002454 else if (AR_SREV_9280_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302455 pCap->num_gpio_pins = AR928X_NUM_GPIO;
2456 else
2457 pCap->num_gpio_pins = AR_NUM_GPIO;
2458
Mohammed Shafi Shajakhan1b2538b2011-12-07 16:51:39 +05302459 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302460 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
Mohammed Shafi Shajakhan1b2538b2011-12-07 16:51:39 +05302461 else
Sujithf1dc5602008-10-29 10:16:30 +05302462 pCap->rts_aggr_limit = (8 * 1024);
Sujithf1dc5602008-10-29 10:16:30 +05302463
Johannes Berg74e13062013-07-03 20:55:38 +02002464#ifdef CONFIG_ATH9K_RFKILL
Sujith2660b812009-02-09 13:27:26 +05302465 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
2466 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
2467 ah->rfkill_gpio =
2468 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
2469 ah->rfkill_polarity =
2470 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05302471
2472 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
2473 }
2474#endif
Vasanthakumar Thiagarajand5d11542010-05-17 18:57:56 -07002475 if (AR_SREV_9271(ah) || AR_SREV_9300_20_OR_LATER(ah))
Vivek Natarajanbde748a2010-04-05 14:48:05 +05302476 pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
2477 else
2478 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
Sujithf1dc5602008-10-29 10:16:30 +05302479
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302480 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302481 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
2482 else
2483 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
2484
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002485 if (AR_SREV_9300_20_OR_LATER(ah)) {
Vasanthakumar Thiagarajan784ad502010-12-06 04:27:40 -08002486 pCap->hw_caps |= ATH9K_HW_CAP_EDMA | ATH9K_HW_CAP_FASTCLOCK;
Sujith Manoharana4a29542012-09-10 09:20:03 +05302487 if (!AR_SREV_9330(ah) && !AR_SREV_9485(ah) && !AR_SREV_9565(ah))
Vasanthakumar Thiagarajan784ad502010-12-06 04:27:40 -08002488 pCap->hw_caps |= ATH9K_HW_CAP_LDPC;
2489
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002490 pCap->rx_hp_qdepth = ATH9K_HW_RX_HP_QDEPTH;
2491 pCap->rx_lp_qdepth = ATH9K_HW_RX_LP_QDEPTH;
2492 pCap->rx_status_len = sizeof(struct ar9003_rxs);
Vasanthakumar Thiagarajan162c3be2010-04-15 17:38:41 -04002493 pCap->tx_desc_len = sizeof(struct ar9003_txc);
Vasanthakumar Thiagarajan5088c2f2010-04-15 17:39:34 -04002494 pCap->txs_len = sizeof(struct ar9003_txs);
Vasanthakumar Thiagarajan162c3be2010-04-15 17:38:41 -04002495 } else {
2496 pCap->tx_desc_len = sizeof(struct ath_desc);
Felix Fietkaua949b172011-07-09 11:12:47 +07002497 if (AR_SREV_9280_20(ah))
Felix Fietkau6b42e8d2010-04-26 15:04:35 -04002498 pCap->hw_caps |= ATH9K_HW_CAP_FASTCLOCK;
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002499 }
Vasanthakumar Thiagarajan1adf02f2010-04-15 17:38:24 -04002500
Vasanthakumar Thiagarajan6c84ce02010-04-15 17:39:16 -04002501 if (AR_SREV_9300_20_OR_LATER(ah))
2502 pCap->hw_caps |= ATH9K_HW_CAP_RAC_SUPPORTED;
2503
Senthil Balasubramanian6ee63f52010-11-10 05:03:16 -08002504 if (AR_SREV_9300_20_OR_LATER(ah))
2505 ah->ent_mode = REG_READ(ah, AR_ENT_OTP);
2506
Felix Fietkaua42acef2010-09-22 12:34:54 +02002507 if (AR_SREV_9287_11_OR_LATER(ah) || AR_SREV_9271(ah))
Vasanthakumar Thiagarajan6473d242010-05-13 18:42:38 -07002508 pCap->hw_caps |= ATH9K_HW_CAP_SGI_20;
2509
Sujith Manoharanf85c3372013-08-04 14:21:53 +05302510 if (AR_SREV_9285(ah)) {
Vasanthakumar Thiagarajan754dc532010-09-02 01:34:41 -07002511 if (ah->eep_ops->get_eeprom(ah, EEP_MODAL_VER) >= 3) {
2512 ant_div_ctl1 =
2513 ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
Sujith Manoharanf85c3372013-08-04 14:21:53 +05302514 if ((ant_div_ctl1 & 0x1) && ((ant_div_ctl1 >> 3) & 0x1)) {
Vasanthakumar Thiagarajan754dc532010-09-02 01:34:41 -07002515 pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB;
Sujith Manoharanf85c3372013-08-04 14:21:53 +05302516 ath_info(common, "Enable LNA combining\n");
2517 }
Vasanthakumar Thiagarajan754dc532010-09-02 01:34:41 -07002518 }
Sujith Manoharanf85c3372013-08-04 14:21:53 +05302519 }
2520
Mohammed Shafi Shajakhanea066d52010-11-23 20:42:27 +05302521 if (AR_SREV_9300_20_OR_LATER(ah)) {
2522 if (ah->eep_ops->get_eeprom(ah, EEP_CHAIN_MASK_REDUCE))
2523 pCap->hw_caps |= ATH9K_HW_CAP_APM;
2524 }
2525
Sujith Manoharan06236e52012-09-16 08:07:12 +05302526 if (AR_SREV_9330(ah) || AR_SREV_9485(ah) || AR_SREV_9565(ah)) {
Mohammed Shafi Shajakhan21d2c632011-05-13 20:29:31 +05302527 ant_div_ctl1 = ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
Sujith Manoharanf85c3372013-08-04 14:21:53 +05302528 if ((ant_div_ctl1 >> 0x6) == 0x3) {
Mohammed Shafi Shajakhan21d2c632011-05-13 20:29:31 +05302529 pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB;
Sujith Manoharanf85c3372013-08-04 14:21:53 +05302530 ath_info(common, "Enable LNA combining\n");
2531 }
Mohammed Shafi Shajakhan21d2c632011-05-13 20:29:31 +05302532 }
Vasanthakumar Thiagarajan754dc532010-09-02 01:34:41 -07002533
Zefir Kurtisi9a66af32011-12-14 20:16:33 -08002534 if (ath9k_hw_dfs_tested(ah))
2535 pCap->hw_caps |= ATH9K_HW_CAP_DFS;
2536
Vasanthakumar Thiagarajan47c80de2010-12-06 04:27:43 -08002537 tx_chainmask = pCap->tx_chainmask;
2538 rx_chainmask = pCap->rx_chainmask;
2539 while (tx_chainmask || rx_chainmask) {
2540 if (tx_chainmask & BIT(0))
2541 pCap->max_txchains++;
2542 if (rx_chainmask & BIT(0))
2543 pCap->max_rxchains++;
2544
2545 tx_chainmask >>= 1;
2546 rx_chainmask >>= 1;
2547 }
2548
Sujith Manoharana4a29542012-09-10 09:20:03 +05302549 if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
Mohammed Shafi Shajakhan3789d592012-03-09 12:01:55 +05302550 if (!(ah->ent_mode & AR_ENT_OTP_49GHZ_DISABLE))
2551 pCap->hw_caps |= ATH9K_HW_CAP_MCI;
2552
Sujith Manoharan2b5e54e2013-06-24 18:18:46 +05302553 if (AR_SREV_9462_20_OR_LATER(ah))
Mohammed Shafi Shajakhan3789d592012-03-09 12:01:55 +05302554 pCap->hw_caps |= ATH9K_HW_CAP_RTT;
Mohammed Shafi Shajakhan3789d592012-03-09 12:01:55 +05302555 }
2556
Sujith Manoharan846e4382013-06-03 09:19:24 +05302557 if (AR_SREV_9462(ah))
2558 pCap->hw_caps |= ATH9K_HW_WOW_DEVICE_CAPABLE;
Mohammed Shafi Shajakhand6878092012-07-10 14:55:17 +05302559
Sujith Manoharan0f21ee82012-12-10 07:22:37 +05302560 if (AR_SREV_9300_20_OR_LATER(ah) &&
2561 ah->eep_ops->get_eeprom(ah, EEP_PAPRD))
2562 pCap->hw_caps |= ATH9K_HW_CAP_PAPRD;
2563
Sujith Manoharan81dc75b2013-07-16 12:03:18 +05302564 /*
2565 * Fast channel change across bands is available
2566 * only for AR9462 and AR9565.
2567 */
2568 if (AR_SREV_9462(ah) || AR_SREV_9565(ah))
2569 pCap->hw_caps |= ATH9K_HW_CAP_FCC_BAND_SWITCH;
2570
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002571 return 0;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002572}
2573
Sujithf1dc5602008-10-29 10:16:30 +05302574/****************************/
2575/* GPIO / RFKILL / Antennae */
2576/****************************/
2577
Sujithcbe61d82009-02-09 13:27:12 +05302578static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05302579 u32 gpio, u32 type)
2580{
2581 int addr;
2582 u32 gpio_shift, tmp;
2583
2584 if (gpio > 11)
2585 addr = AR_GPIO_OUTPUT_MUX3;
2586 else if (gpio > 5)
2587 addr = AR_GPIO_OUTPUT_MUX2;
2588 else
2589 addr = AR_GPIO_OUTPUT_MUX1;
2590
2591 gpio_shift = (gpio % 6) * 5;
2592
2593 if (AR_SREV_9280_20_OR_LATER(ah)
2594 || (addr != AR_GPIO_OUTPUT_MUX1)) {
2595 REG_RMW(ah, addr, (type << gpio_shift),
2596 (0x1f << gpio_shift));
2597 } else {
2598 tmp = REG_READ(ah, addr);
2599 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
2600 tmp &= ~(0x1f << gpio_shift);
2601 tmp |= (type << gpio_shift);
2602 REG_WRITE(ah, addr, tmp);
2603 }
2604}
2605
Sujithcbe61d82009-02-09 13:27:12 +05302606void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05302607{
2608 u32 gpio_shift;
2609
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07002610 BUG_ON(gpio >= ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05302611
Sujith88c1f4f2010-06-30 14:46:31 +05302612 if (AR_DEVID_7010(ah)) {
2613 gpio_shift = gpio;
2614 REG_RMW(ah, AR7010_GPIO_OE,
2615 (AR7010_GPIO_OE_AS_INPUT << gpio_shift),
2616 (AR7010_GPIO_OE_MASK << gpio_shift));
2617 return;
2618 }
Sujithf1dc5602008-10-29 10:16:30 +05302619
Sujith88c1f4f2010-06-30 14:46:31 +05302620 gpio_shift = gpio << 1;
Sujithf1dc5602008-10-29 10:16:30 +05302621 REG_RMW(ah,
2622 AR_GPIO_OE_OUT,
2623 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
2624 (AR_GPIO_OE_OUT_DRV << gpio_shift));
2625}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002626EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
Sujithf1dc5602008-10-29 10:16:30 +05302627
Sujithcbe61d82009-02-09 13:27:12 +05302628u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05302629{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302630#define MS_REG_READ(x, y) \
2631 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
2632
Sujith2660b812009-02-09 13:27:26 +05302633 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05302634 return 0xffffffff;
2635
Sujith88c1f4f2010-06-30 14:46:31 +05302636 if (AR_DEVID_7010(ah)) {
2637 u32 val;
2638 val = REG_READ(ah, AR7010_GPIO_IN);
2639 return (MS(val, AR7010_GPIO_IN_VAL) & AR_GPIO_BIT(gpio)) == 0;
2640 } else if (AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan93069902010-11-30 23:24:09 -08002641 return (MS(REG_READ(ah, AR_GPIO_IN), AR9300_GPIO_IN_VAL) &
2642 AR_GPIO_BIT(gpio)) != 0;
Felix Fietkau783dfca2010-04-15 17:38:11 -04002643 else if (AR_SREV_9271(ah))
Sujith5b5fa352010-03-17 14:25:15 +05302644 return MS_REG_READ(AR9271, gpio) != 0;
Felix Fietkaua42acef2010-09-22 12:34:54 +02002645 else if (AR_SREV_9287_11_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302646 return MS_REG_READ(AR9287, gpio) != 0;
Felix Fietkaue17f83e2010-09-22 12:34:53 +02002647 else if (AR_SREV_9285_12_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302648 return MS_REG_READ(AR9285, gpio) != 0;
Felix Fietkau7a370812010-09-22 12:34:52 +02002649 else if (AR_SREV_9280_20_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302650 return MS_REG_READ(AR928X, gpio) != 0;
2651 else
2652 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05302653}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002654EXPORT_SYMBOL(ath9k_hw_gpio_get);
Sujithf1dc5602008-10-29 10:16:30 +05302655
Sujithcbe61d82009-02-09 13:27:12 +05302656void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05302657 u32 ah_signal_type)
2658{
2659 u32 gpio_shift;
2660
Sujith88c1f4f2010-06-30 14:46:31 +05302661 if (AR_DEVID_7010(ah)) {
2662 gpio_shift = gpio;
2663 REG_RMW(ah, AR7010_GPIO_OE,
2664 (AR7010_GPIO_OE_AS_OUTPUT << gpio_shift),
2665 (AR7010_GPIO_OE_MASK << gpio_shift));
2666 return;
2667 }
2668
Sujithf1dc5602008-10-29 10:16:30 +05302669 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
Sujithf1dc5602008-10-29 10:16:30 +05302670 gpio_shift = 2 * gpio;
Sujithf1dc5602008-10-29 10:16:30 +05302671 REG_RMW(ah,
2672 AR_GPIO_OE_OUT,
2673 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
2674 (AR_GPIO_OE_OUT_DRV << gpio_shift));
2675}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002676EXPORT_SYMBOL(ath9k_hw_cfg_output);
Sujithf1dc5602008-10-29 10:16:30 +05302677
Sujithcbe61d82009-02-09 13:27:12 +05302678void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05302679{
Sujith88c1f4f2010-06-30 14:46:31 +05302680 if (AR_DEVID_7010(ah)) {
2681 val = val ? 0 : 1;
2682 REG_RMW(ah, AR7010_GPIO_OUT, ((val&1) << gpio),
2683 AR_GPIO_BIT(gpio));
2684 return;
2685 }
2686
Sujith5b5fa352010-03-17 14:25:15 +05302687 if (AR_SREV_9271(ah))
2688 val = ~val;
2689
Sujithf1dc5602008-10-29 10:16:30 +05302690 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
2691 AR_GPIO_BIT(gpio));
2692}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002693EXPORT_SYMBOL(ath9k_hw_set_gpio);
Sujithf1dc5602008-10-29 10:16:30 +05302694
Sujithcbe61d82009-02-09 13:27:12 +05302695void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05302696{
2697 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
2698}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002699EXPORT_SYMBOL(ath9k_hw_setantenna);
Sujithf1dc5602008-10-29 10:16:30 +05302700
Sujithf1dc5602008-10-29 10:16:30 +05302701/*********************/
2702/* General Operation */
2703/*********************/
2704
Sujithcbe61d82009-02-09 13:27:12 +05302705u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302706{
2707 u32 bits = REG_READ(ah, AR_RX_FILTER);
2708 u32 phybits = REG_READ(ah, AR_PHY_ERR);
2709
2710 if (phybits & AR_PHY_ERR_RADAR)
2711 bits |= ATH9K_RX_FILTER_PHYRADAR;
2712 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
2713 bits |= ATH9K_RX_FILTER_PHYERR;
2714
2715 return bits;
2716}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002717EXPORT_SYMBOL(ath9k_hw_getrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05302718
Sujithcbe61d82009-02-09 13:27:12 +05302719void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05302720{
2721 u32 phybits;
2722
Sujith7d0d0df2010-04-16 11:53:57 +05302723 ENABLE_REGWRITE_BUFFER(ah);
2724
Sujith Manoharana4a29542012-09-10 09:20:03 +05302725 if (AR_SREV_9462(ah) || AR_SREV_9565(ah))
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302726 bits |= ATH9K_RX_FILTER_CONTROL_WRAPPER;
2727
Sujith7ea310b2009-09-03 12:08:43 +05302728 REG_WRITE(ah, AR_RX_FILTER, bits);
2729
Sujithf1dc5602008-10-29 10:16:30 +05302730 phybits = 0;
2731 if (bits & ATH9K_RX_FILTER_PHYRADAR)
2732 phybits |= AR_PHY_ERR_RADAR;
2733 if (bits & ATH9K_RX_FILTER_PHYERR)
2734 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
2735 REG_WRITE(ah, AR_PHY_ERR, phybits);
2736
2737 if (phybits)
Felix Fietkauca7a4de2011-03-23 20:57:26 +01002738 REG_SET_BIT(ah, AR_RXCFG, AR_RXCFG_ZLFDMA);
Sujithf1dc5602008-10-29 10:16:30 +05302739 else
Felix Fietkauca7a4de2011-03-23 20:57:26 +01002740 REG_CLR_BIT(ah, AR_RXCFG, AR_RXCFG_ZLFDMA);
Sujith7d0d0df2010-04-16 11:53:57 +05302741
2742 REGWRITE_BUFFER_FLUSH(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302743}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002744EXPORT_SYMBOL(ath9k_hw_setrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05302745
Sujithcbe61d82009-02-09 13:27:12 +05302746bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302747{
Rajkumar Manoharan99922a42012-06-04 16:28:31 +05302748 if (ath9k_hw_mci_is_enabled(ah))
2749 ar9003_mci_bt_gain_ctrl(ah);
2750
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05302751 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
2752 return false;
2753
2754 ath9k_hw_init_pll(ah, NULL);
Felix Fietkau8efa7a82012-03-14 16:40:23 +01002755 ah->htc_reset_init = true;
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05302756 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302757}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002758EXPORT_SYMBOL(ath9k_hw_phy_disable);
Sujithf1dc5602008-10-29 10:16:30 +05302759
Sujithcbe61d82009-02-09 13:27:12 +05302760bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302761{
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002762 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05302763 return false;
2764
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05302765 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
2766 return false;
2767
2768 ath9k_hw_init_pll(ah, NULL);
2769 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302770}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002771EXPORT_SYMBOL(ath9k_hw_disable);
Sujithf1dc5602008-10-29 10:16:30 +05302772
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002773static int get_antenna_gain(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05302774{
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002775 enum eeprom_param gain_param;
Felix Fietkau9c204b42011-07-27 15:01:05 +02002776
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002777 if (IS_CHAN_2GHZ(chan))
2778 gain_param = EEP_ANTENNA_GAIN_2G;
2779 else
2780 gain_param = EEP_ANTENNA_GAIN_5G;
Sujithf1dc5602008-10-29 10:16:30 +05302781
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002782 return ah->eep_ops->get_eeprom(ah, gain_param);
2783}
2784
Gabor Juhos64ea57d2012-04-15 20:38:05 +02002785void ath9k_hw_apply_txpower(struct ath_hw *ah, struct ath9k_channel *chan,
2786 bool test)
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002787{
2788 struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
2789 struct ieee80211_channel *channel;
2790 int chan_pwr, new_pwr, max_gain;
2791 int ant_gain, ant_reduction = 0;
2792
2793 if (!chan)
2794 return;
2795
2796 channel = chan->chan;
2797 chan_pwr = min_t(int, channel->max_power * 2, MAX_RATE_POWER);
2798 new_pwr = min_t(int, chan_pwr, reg->power_limit);
2799 max_gain = chan_pwr - new_pwr + channel->max_antenna_gain * 2;
2800
2801 ant_gain = get_antenna_gain(ah, chan);
2802 if (ant_gain > max_gain)
2803 ant_reduction = ant_gain - max_gain;
Sujithf1dc5602008-10-29 10:16:30 +05302804
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07002805 ah->eep_ops->set_txpower(ah, chan,
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002806 ath9k_regd_get_ctl(reg, chan),
Gabor Juhos64ea57d2012-04-15 20:38:05 +02002807 ant_reduction, new_pwr, test);
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002808}
2809
2810void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit, bool test)
2811{
2812 struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
2813 struct ath9k_channel *chan = ah->curchan;
2814 struct ieee80211_channel *channel = chan->chan;
2815
Dan Carpenter48ef5c42011-10-17 10:28:23 +03002816 reg->power_limit = min_t(u32, limit, MAX_RATE_POWER);
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002817 if (test)
2818 channel->max_power = MAX_RATE_POWER / 2;
2819
Gabor Juhos64ea57d2012-04-15 20:38:05 +02002820 ath9k_hw_apply_txpower(ah, chan, test);
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002821
2822 if (test)
2823 channel->max_power = DIV_ROUND_UP(reg->max_power_level, 2);
Sujithf1dc5602008-10-29 10:16:30 +05302824}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002825EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
Sujithf1dc5602008-10-29 10:16:30 +05302826
Sujithcbe61d82009-02-09 13:27:12 +05302827void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302828{
Sujith2660b812009-02-09 13:27:26 +05302829 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05302830}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002831EXPORT_SYMBOL(ath9k_hw_setopmode);
Sujithf1dc5602008-10-29 10:16:30 +05302832
Sujithcbe61d82009-02-09 13:27:12 +05302833void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05302834{
2835 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
2836 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
2837}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002838EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
Sujithf1dc5602008-10-29 10:16:30 +05302839
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07002840void ath9k_hw_write_associd(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302841{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002842 struct ath_common *common = ath9k_hw_common(ah);
2843
2844 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
2845 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
2846 ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05302847}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002848EXPORT_SYMBOL(ath9k_hw_write_associd);
Sujithf1dc5602008-10-29 10:16:30 +05302849
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002850#define ATH9K_MAX_TSF_READ 10
2851
Sujithcbe61d82009-02-09 13:27:12 +05302852u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302853{
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002854 u32 tsf_lower, tsf_upper1, tsf_upper2;
2855 int i;
Sujithf1dc5602008-10-29 10:16:30 +05302856
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002857 tsf_upper1 = REG_READ(ah, AR_TSF_U32);
2858 for (i = 0; i < ATH9K_MAX_TSF_READ; i++) {
2859 tsf_lower = REG_READ(ah, AR_TSF_L32);
2860 tsf_upper2 = REG_READ(ah, AR_TSF_U32);
2861 if (tsf_upper2 == tsf_upper1)
2862 break;
2863 tsf_upper1 = tsf_upper2;
2864 }
Sujithf1dc5602008-10-29 10:16:30 +05302865
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002866 WARN_ON( i == ATH9K_MAX_TSF_READ );
2867
2868 return (((u64)tsf_upper1 << 32) | tsf_lower);
Sujithf1dc5602008-10-29 10:16:30 +05302869}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002870EXPORT_SYMBOL(ath9k_hw_gettsf64);
Sujithf1dc5602008-10-29 10:16:30 +05302871
Sujithcbe61d82009-02-09 13:27:12 +05302872void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002873{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002874 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01002875 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002876}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002877EXPORT_SYMBOL(ath9k_hw_settsf64);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002878
Sujithcbe61d82009-02-09 13:27:12 +05302879void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302880{
Gabor Juhosf9b604f2009-06-21 00:02:15 +02002881 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
2882 AH_TSF_WRITE_TIMEOUT))
Joe Perchesd2182b62011-12-15 14:55:53 -08002883 ath_dbg(ath9k_hw_common(ah), RESET,
Joe Perches226afe62010-12-02 19:12:37 -08002884 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
Gabor Juhosf9b604f2009-06-21 00:02:15 +02002885
Sujithf1dc5602008-10-29 10:16:30 +05302886 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002887}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002888EXPORT_SYMBOL(ath9k_hw_reset_tsf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002889
Sujith Manoharan60ca9f82012-07-17 17:15:37 +05302890void ath9k_hw_set_tsfadjust(struct ath_hw *ah, bool set)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002891{
Sujith Manoharan60ca9f82012-07-17 17:15:37 +05302892 if (set)
Sujith2660b812009-02-09 13:27:26 +05302893 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002894 else
Sujith2660b812009-02-09 13:27:26 +05302895 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002896}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002897EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002898
Felix Fietkaue4744ec2013-10-11 23:31:01 +02002899void ath9k_hw_set11nmac2040(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002900{
Sujithf1dc5602008-10-29 10:16:30 +05302901 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002902
Felix Fietkaue4744ec2013-10-11 23:31:01 +02002903 if (IS_CHAN_HT40(chan) && !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05302904 macmode = AR_2040_JOINED_RX_CLEAR;
2905 else
2906 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002907
Sujithf1dc5602008-10-29 10:16:30 +05302908 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002909}
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302910
2911/* HW Generic timers configuration */
2912
2913static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
2914{
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_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2919 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2920 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2921 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2922 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2923 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
2924 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
2925 AR_NDP2_TIMER_MODE, 0x0002},
2926 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
2927 AR_NDP2_TIMER_MODE, 0x0004},
2928 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
2929 AR_NDP2_TIMER_MODE, 0x0008},
2930 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
2931 AR_NDP2_TIMER_MODE, 0x0010},
2932 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
2933 AR_NDP2_TIMER_MODE, 0x0020},
2934 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
2935 AR_NDP2_TIMER_MODE, 0x0040},
2936 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
2937 AR_NDP2_TIMER_MODE, 0x0080}
2938};
2939
2940/* HW generic timer primitives */
2941
Felix Fietkaudd347f22011-03-22 21:54:17 +01002942u32 ath9k_hw_gettsf32(struct ath_hw *ah)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302943{
2944 return REG_READ(ah, AR_TSF_L32);
2945}
Felix Fietkaudd347f22011-03-22 21:54:17 +01002946EXPORT_SYMBOL(ath9k_hw_gettsf32);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302947
2948struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
2949 void (*trigger)(void *),
2950 void (*overflow)(void *),
2951 void *arg,
2952 u8 timer_index)
2953{
2954 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2955 struct ath_gen_timer *timer;
2956
Felix Fietkauc67ce332013-12-14 18:03:38 +01002957 if ((timer_index < AR_FIRST_NDP_TIMER) ||
2958 (timer_index >= ATH_MAX_GEN_TIMER))
2959 return NULL;
2960
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302961 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
Joe Perches14f8dc42013-02-07 11:46:27 +00002962 if (timer == NULL)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302963 return NULL;
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302964
2965 /* allocate a hardware generic timer slot */
2966 timer_table->timers[timer_index] = timer;
2967 timer->index = timer_index;
2968 timer->trigger = trigger;
2969 timer->overflow = overflow;
2970 timer->arg = arg;
2971
2972 return timer;
2973}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002974EXPORT_SYMBOL(ath_gen_timer_alloc);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302975
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07002976void ath9k_hw_gen_timer_start(struct ath_hw *ah,
2977 struct ath_gen_timer *timer,
Felix Fietkauc67ce332013-12-14 18:03:38 +01002978 u32 timer_next,
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07002979 u32 timer_period)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302980{
2981 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
Felix Fietkauc67ce332013-12-14 18:03:38 +01002982 u32 mask = 0;
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302983
Felix Fietkauc67ce332013-12-14 18:03:38 +01002984 timer_table->timer_mask |= BIT(timer->index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302985
2986 /*
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302987 * Program generic timer registers
2988 */
2989 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
2990 timer_next);
2991 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
2992 timer_period);
2993 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
2994 gen_tmr_configuration[timer->index].mode_mask);
2995
Sujith Manoharana4a29542012-09-10 09:20:03 +05302996 if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302997 /*
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05302998 * Starting from AR9462, each generic timer can select which tsf
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302999 * to use. But we still follow the old rule, 0 - 7 use tsf and
3000 * 8 - 15 use tsf2.
3001 */
3002 if ((timer->index < AR_GEN_TIMER_BANK_1_LEN))
3003 REG_CLR_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL,
3004 (1 << timer->index));
3005 else
3006 REG_SET_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL,
3007 (1 << timer->index));
3008 }
3009
Felix Fietkauc67ce332013-12-14 18:03:38 +01003010 if (timer->trigger)
3011 mask |= SM(AR_GENTMR_BIT(timer->index),
3012 AR_IMR_S5_GENTIMER_TRIG);
3013 if (timer->overflow)
3014 mask |= SM(AR_GENTMR_BIT(timer->index),
3015 AR_IMR_S5_GENTIMER_THRESH);
3016
3017 REG_SET_BIT(ah, AR_IMR_S5, mask);
3018
3019 if ((ah->imask & ATH9K_INT_GENTIMER) == 0) {
3020 ah->imask |= ATH9K_INT_GENTIMER;
3021 ath9k_hw_set_interrupts(ah);
3022 }
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303023}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003024EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303025
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07003026void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303027{
3028 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3029
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303030 /* Clear generic timer enable bits. */
3031 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
3032 gen_tmr_configuration[timer->index].mode_mask);
3033
Sujith Manoharanb7f59762012-09-11 10:46:24 +05303034 if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
3035 /*
3036 * Need to switch back to TSF if it was using TSF2.
3037 */
3038 if ((timer->index >= AR_GEN_TIMER_BANK_1_LEN)) {
3039 REG_CLR_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL,
3040 (1 << timer->index));
3041 }
3042 }
3043
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303044 /* Disable both trigger and thresh interrupt masks */
3045 REG_CLR_BIT(ah, AR_IMR_S5,
3046 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
3047 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
3048
Felix Fietkauc67ce332013-12-14 18:03:38 +01003049 timer_table->timer_mask &= ~BIT(timer->index);
3050
3051 if (timer_table->timer_mask == 0) {
3052 ah->imask &= ~ATH9K_INT_GENTIMER;
3053 ath9k_hw_set_interrupts(ah);
3054 }
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303055}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003056EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303057
3058void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
3059{
3060 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3061
3062 /* free the hardware generic timer slot */
3063 timer_table->timers[timer->index] = NULL;
3064 kfree(timer);
3065}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003066EXPORT_SYMBOL(ath_gen_timer_free);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303067
3068/*
3069 * Generic Timer Interrupts handling
3070 */
3071void ath_gen_timer_isr(struct ath_hw *ah)
3072{
3073 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3074 struct ath_gen_timer *timer;
Felix Fietkauc67ce332013-12-14 18:03:38 +01003075 unsigned long trigger_mask, thresh_mask;
3076 unsigned int index;
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303077
3078 /* get hardware generic timer interrupt status */
3079 trigger_mask = ah->intr_gen_timer_trigger;
3080 thresh_mask = ah->intr_gen_timer_thresh;
Felix Fietkauc67ce332013-12-14 18:03:38 +01003081 trigger_mask &= timer_table->timer_mask;
3082 thresh_mask &= timer_table->timer_mask;
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303083
Felix Fietkauc67ce332013-12-14 18:03:38 +01003084 for_each_set_bit(index, &thresh_mask, ARRAY_SIZE(timer_table->timers)) {
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303085 timer = timer_table->timers[index];
Felix Fietkauc67ce332013-12-14 18:03:38 +01003086 if (!timer)
3087 continue;
3088 if (!timer->overflow)
3089 continue;
Felix Fietkaua6a172b2013-12-20 16:18:45 +01003090
3091 trigger_mask &= ~BIT(index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303092 timer->overflow(timer->arg);
3093 }
3094
Felix Fietkauc67ce332013-12-14 18:03:38 +01003095 for_each_set_bit(index, &trigger_mask, ARRAY_SIZE(timer_table->timers)) {
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303096 timer = timer_table->timers[index];
Felix Fietkauc67ce332013-12-14 18:03:38 +01003097 if (!timer)
3098 continue;
3099 if (!timer->trigger)
3100 continue;
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303101 timer->trigger(timer->arg);
3102 }
3103}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003104EXPORT_SYMBOL(ath_gen_timer_isr);
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003105
Sujith05020d22010-03-17 14:25:23 +05303106/********/
3107/* HTC */
3108/********/
3109
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003110static struct {
3111 u32 version;
3112 const char * name;
3113} ath_mac_bb_names[] = {
3114 /* Devices with external radios */
3115 { AR_SREV_VERSION_5416_PCI, "5416" },
3116 { AR_SREV_VERSION_5416_PCIE, "5418" },
3117 { AR_SREV_VERSION_9100, "9100" },
3118 { AR_SREV_VERSION_9160, "9160" },
3119 /* Single-chip solutions */
3120 { AR_SREV_VERSION_9280, "9280" },
3121 { AR_SREV_VERSION_9285, "9285" },
Luis R. Rodriguez11158472009-10-27 12:59:35 -04003122 { AR_SREV_VERSION_9287, "9287" },
3123 { AR_SREV_VERSION_9271, "9271" },
Luis R. Rodriguezec839032010-04-15 17:39:20 -04003124 { AR_SREV_VERSION_9300, "9300" },
Gabor Juhos2c8e5932011-06-21 11:23:21 +02003125 { AR_SREV_VERSION_9330, "9330" },
Florian Fainelli397e5d52011-08-25 21:33:48 +02003126 { AR_SREV_VERSION_9340, "9340" },
Senthil Balasubramanian8f06ca22011-04-01 17:16:33 +05303127 { AR_SREV_VERSION_9485, "9485" },
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05303128 { AR_SREV_VERSION_9462, "9462" },
Gabor Juhos485124c2012-07-03 19:13:19 +02003129 { AR_SREV_VERSION_9550, "9550" },
Sujith Manoharan77fac462012-09-11 20:09:18 +05303130 { AR_SREV_VERSION_9565, "9565" },
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003131};
3132
3133/* For devices with external radios */
3134static struct {
3135 u16 version;
3136 const char * name;
3137} ath_rf_names[] = {
3138 { 0, "5133" },
3139 { AR_RAD5133_SREV_MAJOR, "5133" },
3140 { AR_RAD5122_SREV_MAJOR, "5122" },
3141 { AR_RAD2133_SREV_MAJOR, "2133" },
3142 { AR_RAD2122_SREV_MAJOR, "2122" }
3143};
3144
3145/*
3146 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
3147 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003148static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003149{
3150 int i;
3151
3152 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
3153 if (ath_mac_bb_names[i].version == mac_bb_version) {
3154 return ath_mac_bb_names[i].name;
3155 }
3156 }
3157
3158 return "????";
3159}
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003160
3161/*
3162 * Return the RF name. "????" is returned if the RF is unknown.
3163 * Used for devices with external radios.
3164 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003165static const char *ath9k_hw_rf_name(u16 rf_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003166{
3167 int i;
3168
3169 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
3170 if (ath_rf_names[i].version == rf_version) {
3171 return ath_rf_names[i].name;
3172 }
3173 }
3174
3175 return "????";
3176}
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003177
3178void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
3179{
3180 int used;
3181
3182 /* chipsets >= AR9280 are single-chip */
Felix Fietkau7a370812010-09-22 12:34:52 +02003183 if (AR_SREV_9280_20_OR_LATER(ah)) {
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +02003184 used = scnprintf(hw_name, len,
3185 "Atheros AR%s Rev:%x",
3186 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3187 ah->hw_version.macRev);
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003188 }
3189 else {
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +02003190 used = scnprintf(hw_name, len,
3191 "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
3192 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3193 ah->hw_version.macRev,
3194 ath9k_hw_rf_name((ah->hw_version.analog5GhzRev
3195 & AR_RADIO_SREV_MAJOR)),
3196 ah->hw_version.phyRev);
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003197 }
3198
3199 hw_name[used] = '\0';
3200}
3201EXPORT_SYMBOL(ath9k_hw_name);