blob: 3f9cac9231f376db9fe5119d74655155e08344b8 [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
Felix Fietkaudfdac8a2010-10-08 22:13:51 +020040static void ath9k_hw_set_clockrate(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +053041{
Felix Fietkaudfdac8a2010-10-08 22:13:51 +020042 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkaue4744ec2013-10-11 23:31:01 +020043 struct ath9k_channel *chan = ah->curchan;
Felix Fietkaudfdac8a2010-10-08 22:13:51 +020044 unsigned int clockrate;
Sujithcbe61d82009-02-09 13:27:12 +053045
Felix Fietkau087b6ff2011-07-09 11:12:49 +070046 /* AR9287 v1.3+ uses async FIFO and runs the MAC at 117 MHz */
47 if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah))
48 clockrate = 117;
Felix Fietkaue4744ec2013-10-11 23:31:01 +020049 else if (!chan) /* should really check for CCK instead */
Felix Fietkaudfdac8a2010-10-08 22:13:51 +020050 clockrate = ATH9K_CLOCK_RATE_CCK;
Felix Fietkaue4744ec2013-10-11 23:31:01 +020051 else if (IS_CHAN_2GHZ(chan))
Felix Fietkaudfdac8a2010-10-08 22:13:51 +020052 clockrate = ATH9K_CLOCK_RATE_2GHZ_OFDM;
53 else if (ah->caps.hw_caps & ATH9K_HW_CAP_FASTCLOCK)
54 clockrate = ATH9K_CLOCK_FAST_RATE_5GHZ_OFDM;
Vasanthakumar Thiagarajane5553722010-04-26 15:04:33 -040055 else
Felix Fietkaudfdac8a2010-10-08 22:13:51 +020056 clockrate = ATH9K_CLOCK_RATE_5GHZ_OFDM;
57
Michal Nazarewiczbeae4162013-11-29 18:06:46 +010058 if (chan) {
59 if (IS_CHAN_HT40(chan))
60 clockrate *= 2;
Felix Fietkaue4744ec2013-10-11 23:31:01 +020061 if (IS_CHAN_HALF_RATE(chan))
Felix Fietkau906c7202011-07-09 11:12:48 +070062 clockrate /= 2;
Felix Fietkaue4744ec2013-10-11 23:31:01 +020063 if (IS_CHAN_QUARTER_RATE(chan))
Felix Fietkau906c7202011-07-09 11:12:48 +070064 clockrate /= 4;
65 }
66
Felix Fietkaudfdac8a2010-10-08 22:13:51 +020067 common->clockrate = clockrate;
Sujithf1dc5602008-10-29 10:16:30 +053068}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070069
Sujithcbe61d82009-02-09 13:27:12 +053070static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053071{
Felix Fietkaudfdac8a2010-10-08 22:13:51 +020072 struct ath_common *common = ath9k_hw_common(ah);
Sujithcbe61d82009-02-09 13:27:12 +053073
Felix Fietkaudfdac8a2010-10-08 22:13:51 +020074 return usecs * common->clockrate;
Sujithf1dc5602008-10-29 10:16:30 +053075}
76
Sujith0caa7b12009-02-16 13:23:20 +053077bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070078{
79 int i;
80
Sujith0caa7b12009-02-16 13:23:20 +053081 BUG_ON(timeout < AH_TIME_QUANTUM);
82
83 for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070084 if ((REG_READ(ah, reg) & mask) == val)
85 return true;
86
87 udelay(AH_TIME_QUANTUM);
88 }
Sujith04bd46382008-11-28 22:18:05 +053089
Joe Perchesd2182b62011-12-15 14:55:53 -080090 ath_dbg(ath9k_hw_common(ah), ANY,
Joe Perches226afe62010-12-02 19:12:37 -080091 "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
92 timeout, reg, REG_READ(ah, reg), mask, val);
Sujithf1dc5602008-10-29 10:16:30 +053093
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070094 return false;
95}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040096EXPORT_SYMBOL(ath9k_hw_wait);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070097
Felix Fietkau7c5adc82012-04-19 21:18:26 +020098void ath9k_hw_synth_delay(struct ath_hw *ah, struct ath9k_channel *chan,
99 int hw_delay)
100{
Felix Fietkau1a5e6322013-10-11 23:30:54 +0200101 hw_delay /= 10;
Felix Fietkau7c5adc82012-04-19 21:18:26 +0200102
103 if (IS_CHAN_HALF_RATE(chan))
104 hw_delay *= 2;
105 else if (IS_CHAN_QUARTER_RATE(chan))
106 hw_delay *= 4;
107
108 udelay(hw_delay + BASE_ACTIVATE_DELAY);
109}
110
Felix Fietkau0166b4b2013-01-20 18:51:55 +0100111void ath9k_hw_write_array(struct ath_hw *ah, const struct ar5416IniArray *array,
Felix Fietkaua9b6b252011-03-23 20:57:27 +0100112 int column, unsigned int *writecnt)
113{
114 int r;
115
116 ENABLE_REGWRITE_BUFFER(ah);
117 for (r = 0; r < array->ia_rows; r++) {
118 REG_WRITE(ah, INI_RA(array, r, 0),
119 INI_RA(array, r, column));
120 DO_DELAY(*writecnt);
121 }
122 REGWRITE_BUFFER_FLUSH(ah);
123}
124
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700125u32 ath9k_hw_reverse_bits(u32 val, u32 n)
126{
127 u32 retval;
128 int i;
129
130 for (i = 0, retval = 0; i < n; i++) {
131 retval = (retval << 1) | (val & 1);
132 val >>= 1;
133 }
134 return retval;
135}
136
Sujithcbe61d82009-02-09 13:27:12 +0530137u16 ath9k_hw_computetxtime(struct ath_hw *ah,
Felix Fietkau545750d2009-11-23 22:21:01 +0100138 u8 phy, int kbps,
Sujithf1dc5602008-10-29 10:16:30 +0530139 u32 frameLen, u16 rateix,
140 bool shortPreamble)
141{
142 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
Sujithf1dc5602008-10-29 10:16:30 +0530143
144 if (kbps == 0)
145 return 0;
146
Felix Fietkau545750d2009-11-23 22:21:01 +0100147 switch (phy) {
Sujith46d14a52008-11-18 09:08:13 +0530148 case WLAN_RC_PHY_CCK:
Sujithf1dc5602008-10-29 10:16:30 +0530149 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
Felix Fietkau545750d2009-11-23 22:21:01 +0100150 if (shortPreamble)
Sujithf1dc5602008-10-29 10:16:30 +0530151 phyTime >>= 1;
152 numBits = frameLen << 3;
153 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
154 break;
Sujith46d14a52008-11-18 09:08:13 +0530155 case WLAN_RC_PHY_OFDM:
Sujith2660b812009-02-09 13:27:26 +0530156 if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530157 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
158 numBits = OFDM_PLCP_BITS + (frameLen << 3);
159 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
160 txTime = OFDM_SIFS_TIME_QUARTER
161 + OFDM_PREAMBLE_TIME_QUARTER
162 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
Sujith2660b812009-02-09 13:27:26 +0530163 } else if (ah->curchan &&
164 IS_CHAN_HALF_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530165 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
166 numBits = OFDM_PLCP_BITS + (frameLen << 3);
167 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
168 txTime = OFDM_SIFS_TIME_HALF +
169 OFDM_PREAMBLE_TIME_HALF
170 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
171 } else {
172 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
173 numBits = OFDM_PLCP_BITS + (frameLen << 3);
174 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
175 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
176 + (numSymbols * OFDM_SYMBOL_TIME);
177 }
178 break;
179 default:
Joe Perches38002762010-12-02 19:12:36 -0800180 ath_err(ath9k_hw_common(ah),
181 "Unknown phy %u (rate ix %u)\n", phy, rateix);
Sujithf1dc5602008-10-29 10:16:30 +0530182 txTime = 0;
183 break;
184 }
185
186 return txTime;
187}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400188EXPORT_SYMBOL(ath9k_hw_computetxtime);
Sujithf1dc5602008-10-29 10:16:30 +0530189
Sujithcbe61d82009-02-09 13:27:12 +0530190void ath9k_hw_get_channel_centers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530191 struct ath9k_channel *chan,
192 struct chan_centers *centers)
193{
194 int8_t extoff;
Sujithf1dc5602008-10-29 10:16:30 +0530195
196 if (!IS_CHAN_HT40(chan)) {
197 centers->ctl_center = centers->ext_center =
198 centers->synth_center = chan->channel;
199 return;
200 }
201
Felix Fietkau88969342013-10-11 23:30:53 +0200202 if (IS_CHAN_HT40PLUS(chan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530203 centers->synth_center =
204 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
205 extoff = 1;
206 } else {
207 centers->synth_center =
208 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
209 extoff = -1;
210 }
211
212 centers->ctl_center =
213 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700214 /* 25 MHz spacing is supported by hw but not on upper layers */
Sujithf1dc5602008-10-29 10:16:30 +0530215 centers->ext_center =
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700216 centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT);
Sujithf1dc5602008-10-29 10:16:30 +0530217}
218
219/******************/
220/* Chip Revisions */
221/******************/
222
Sujithcbe61d82009-02-09 13:27:12 +0530223static void ath9k_hw_read_revisions(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530224{
225 u32 val;
226
Vasanthakumar Thiagarajanecb1d382011-04-19 19:29:18 +0530227 switch (ah->hw_version.devid) {
228 case AR5416_AR9100_DEVID:
229 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
230 break;
Gabor Juhos37625612011-06-21 11:23:23 +0200231 case AR9300_DEVID_AR9330:
232 ah->hw_version.macVersion = AR_SREV_VERSION_9330;
233 if (ah->get_mac_revision) {
234 ah->hw_version.macRev = ah->get_mac_revision();
235 } else {
236 val = REG_READ(ah, AR_SREV);
237 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
238 }
239 return;
Vasanthakumar Thiagarajanecb1d382011-04-19 19:29:18 +0530240 case AR9300_DEVID_AR9340:
241 ah->hw_version.macVersion = AR_SREV_VERSION_9340;
242 val = REG_READ(ah, AR_SREV);
243 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
244 return;
Gabor Juhos813831d2012-07-03 19:13:17 +0200245 case AR9300_DEVID_QCA955X:
246 ah->hw_version.macVersion = AR_SREV_VERSION_9550;
247 return;
Vasanthakumar Thiagarajanecb1d382011-04-19 19:29:18 +0530248 }
249
Sujithf1dc5602008-10-29 10:16:30 +0530250 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
251
252 if (val == 0xFF) {
253 val = REG_READ(ah, AR_SREV);
Sujithd535a422009-02-09 13:27:06 +0530254 ah->hw_version.macVersion =
255 (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
256 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
Mohammed Shafi Shajakhan76ed94b2011-09-30 11:31:28 +0530257
Sujith Manoharan77fac462012-09-11 20:09:18 +0530258 if (AR_SREV_9462(ah) || AR_SREV_9565(ah))
Mohammed Shafi Shajakhan76ed94b2011-09-30 11:31:28 +0530259 ah->is_pciexpress = true;
260 else
261 ah->is_pciexpress = (val &
262 AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
Sujithf1dc5602008-10-29 10:16:30 +0530263 } else {
264 if (!AR_SREV_9100(ah))
Sujithd535a422009-02-09 13:27:06 +0530265 ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
Sujithf1dc5602008-10-29 10:16:30 +0530266
Sujithd535a422009-02-09 13:27:06 +0530267 ah->hw_version.macRev = val & AR_SREV_REVISION;
Sujithf1dc5602008-10-29 10:16:30 +0530268
Sujithd535a422009-02-09 13:27:06 +0530269 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
Sujith2660b812009-02-09 13:27:26 +0530270 ah->is_pciexpress = true;
Sujithf1dc5602008-10-29 10:16:30 +0530271 }
272}
273
Sujithf1dc5602008-10-29 10:16:30 +0530274/************************************/
275/* HW Attach, Detach, Init Routines */
276/************************************/
277
Sujithcbe61d82009-02-09 13:27:12 +0530278static void ath9k_hw_disablepcie(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530279{
Felix Fietkau040b74f2010-12-12 00:51:07 +0100280 if (!AR_SREV_5416(ah))
Sujithf1dc5602008-10-29 10:16:30 +0530281 return;
282
283 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
284 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
285 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
286 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
287 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
288 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
289 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
290 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
291 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
292
293 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
294}
295
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400296/* This should work for all families including legacy */
Sujithcbe61d82009-02-09 13:27:12 +0530297static bool ath9k_hw_chip_test(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530298{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700299 struct ath_common *common = ath9k_hw_common(ah);
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400300 u32 regAddr[2] = { AR_STA_ID0 };
Sujithf1dc5602008-10-29 10:16:30 +0530301 u32 regHold[2];
Joe Perches07b2fa52010-11-20 18:38:53 -0800302 static const u32 patternData[4] = {
303 0x55555555, 0xaaaaaaaa, 0x66666666, 0x99999999
304 };
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400305 int i, j, loop_max;
Sujithf1dc5602008-10-29 10:16:30 +0530306
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400307 if (!AR_SREV_9300_20_OR_LATER(ah)) {
308 loop_max = 2;
309 regAddr[1] = AR_PHY_BASE + (8 << 2);
310 } else
311 loop_max = 1;
312
313 for (i = 0; i < loop_max; i++) {
Sujithf1dc5602008-10-29 10:16:30 +0530314 u32 addr = regAddr[i];
315 u32 wrData, rdData;
316
317 regHold[i] = REG_READ(ah, addr);
318 for (j = 0; j < 0x100; j++) {
319 wrData = (j << 16) | j;
320 REG_WRITE(ah, addr, wrData);
321 rdData = REG_READ(ah, addr);
322 if (rdData != wrData) {
Joe Perches38002762010-12-02 19:12:36 -0800323 ath_err(common,
324 "address test failed addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
325 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530326 return false;
327 }
328 }
329 for (j = 0; j < 4; j++) {
330 wrData = patternData[j];
331 REG_WRITE(ah, addr, wrData);
332 rdData = REG_READ(ah, addr);
333 if (wrData != rdData) {
Joe Perches38002762010-12-02 19:12:36 -0800334 ath_err(common,
335 "address test failed addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
336 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530337 return false;
338 }
339 }
340 REG_WRITE(ah, regAddr[i], regHold[i]);
341 }
342 udelay(100);
Sujithcbe61d82009-02-09 13:27:12 +0530343
Sujithf1dc5602008-10-29 10:16:30 +0530344 return true;
345}
346
Luis R. Rodriguezb8b0f372009-08-03 12:24:43 -0700347static void ath9k_hw_init_config(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700348{
Sujith Manoharanf57cf932013-12-28 09:47:12 +0530349 struct ath_common *common = ath9k_hw_common(ah);
350
Felix Fietkau689e7562012-04-12 22:35:56 +0200351 ah->config.dma_beacon_response_time = 1;
352 ah->config.sw_beacon_response_time = 6;
Sujith2660b812009-02-09 13:27:26 +0530353 ah->config.ack_6mb = 0x0;
354 ah->config.cwm_ignore_extcca = 0;
Sujith2660b812009-02-09 13:27:26 +0530355 ah->config.analog_shiftreg = 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700356
Sujith0ce024c2009-12-14 14:57:00 +0530357 ah->config.rx_intr_mitigation = true;
Luis R. Rodriguez61584252009-03-12 18:18:49 -0400358
359 /*
360 * We need this for PCI devices only (Cardbus, PCI, miniPCI)
361 * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
362 * This means we use it for all AR5416 devices, and the few
363 * minor PCI AR9280 devices out there.
364 *
365 * Serialization is required because these devices do not handle
366 * well the case of two concurrent reads/writes due to the latency
367 * involved. During one read/write another read/write can be issued
368 * on another CPU while the previous read/write may still be working
369 * on our hardware, if we hit this case the hardware poops in a loop.
370 * We prevent this by serializing reads and writes.
371 *
372 * This issue is not present on PCI-Express devices or pre-AR5416
373 * devices (legacy, 802.11abg).
374 */
375 if (num_possible_cpus() > 1)
David S. Miller2d6a5e92009-03-17 15:01:30 -0700376 ah->config.serialize_regmode = SER_REG_MODE_AUTO;
Sujith Manoharanf57cf932013-12-28 09:47:12 +0530377
378 if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
379 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
380 ((AR_SREV_9160(ah) || AR_SREV_9280(ah) || AR_SREV_9287(ah)) &&
381 !ah->is_pciexpress)) {
382 ah->config.serialize_regmode = SER_REG_MODE_ON;
383 } else {
384 ah->config.serialize_regmode = SER_REG_MODE_OFF;
385 }
386 }
387
388 ath_dbg(common, RESET, "serialize_regmode is %d\n",
389 ah->config.serialize_regmode);
390
391 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
392 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD >> 1;
393 else
394 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700395}
396
Luis R. Rodriguez50aca252009-08-03 12:24:42 -0700397static void ath9k_hw_init_defaults(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700398{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700399 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
400
401 regulatory->country_code = CTRY_DEFAULT;
402 regulatory->power_limit = MAX_RATE_POWER;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700403
Sujithd535a422009-02-09 13:27:06 +0530404 ah->hw_version.magic = AR5416_MAGIC;
Sujithd535a422009-02-09 13:27:06 +0530405 ah->hw_version.subvendorid = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700406
Sujith Manoharanf57cf932013-12-28 09:47:12 +0530407 ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE |
408 AR_STA_ID1_MCAST_KSRCH;
Felix Fietkauf1717602011-03-19 13:55:41 +0100409 if (AR_SREV_9100(ah))
410 ah->sta_id1_defaults |= AR_STA_ID1_AR9100_BA_FIX;
Sujith Manoharanf57cf932013-12-28 09:47:12 +0530411
Rajkumar Manoharane3f2acc2011-08-27 11:22:59 +0530412 ah->slottime = ATH9K_SLOT_TIME_9;
Sujith2660b812009-02-09 13:27:26 +0530413 ah->globaltxtimeout = (u32) -1;
Gabor Juhoscbdec972009-07-24 17:27:22 +0200414 ah->power_mode = ATH9K_PM_UNDEFINED;
Felix Fietkau8efa7a82012-03-14 16:40:23 +0100415 ah->htc_reset_init = true;
Sujith Manoharanf57cf932013-12-28 09:47:12 +0530416
417 ah->ani_function = ATH9K_ANI_ALL;
418 if (!AR_SREV_9300_20_OR_LATER(ah))
419 ah->ani_function &= ~ATH9K_ANI_MRC_CCK;
420
421 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
422 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
423 else
424 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700425}
426
Sujithcbe61d82009-02-09 13:27:12 +0530427static int ath9k_hw_init_macaddr(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700428{
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700429 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530430 u32 sum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700431 int i;
Sujithf1dc5602008-10-29 10:16:30 +0530432 u16 eeval;
Joe Perches07b2fa52010-11-20 18:38:53 -0800433 static const u32 EEP_MAC[] = { EEP_MAC_LSW, EEP_MAC_MID, EEP_MAC_MSW };
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700434
Sujithf1dc5602008-10-29 10:16:30 +0530435 sum = 0;
436 for (i = 0; i < 3; i++) {
Luis R. Rodriguez49101672010-04-15 17:39:13 -0400437 eeval = ah->eep_ops->get_eeprom(ah, EEP_MAC[i]);
Sujithf1dc5602008-10-29 10:16:30 +0530438 sum += eeval;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700439 common->macaddr[2 * i] = eeval >> 8;
440 common->macaddr[2 * i + 1] = eeval & 0xff;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700441 }
Sujithd8baa932009-03-30 15:28:25 +0530442 if (sum == 0 || sum == 0xffff * 3)
Sujithf1dc5602008-10-29 10:16:30 +0530443 return -EADDRNOTAVAIL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700444
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700445 return 0;
446}
447
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700448static int ath9k_hw_post_init(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700449{
Sujith Manoharan6cae913d2011-01-04 13:16:37 +0530450 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700451 int ecode;
452
Sujith Manoharan6cae913d2011-01-04 13:16:37 +0530453 if (common->bus_ops->ath_bus_type != ATH_USB) {
Sujith527d4852010-03-17 14:25:16 +0530454 if (!ath9k_hw_chip_test(ah))
455 return -ENODEV;
456 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700457
Luis R. Rodriguezebd5a142010-04-15 17:39:18 -0400458 if (!AR_SREV_9300_20_OR_LATER(ah)) {
459 ecode = ar9002_hw_rf_claim(ah);
460 if (ecode != 0)
461 return ecode;
462 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700463
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700464 ecode = ath9k_hw_eeprom_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700465 if (ecode != 0)
466 return ecode;
Sujith7d01b222009-03-13 08:55:55 +0530467
Joe Perchesd2182b62011-12-15 14:55:53 -0800468 ath_dbg(ath9k_hw_common(ah), CONFIG, "Eeprom VER: %d, REV: %d\n",
Joe Perches226afe62010-12-02 19:12:37 -0800469 ah->eep_ops->get_eeprom_ver(ah),
470 ah->eep_ops->get_eeprom_rev(ah));
Sujith7d01b222009-03-13 08:55:55 +0530471
Sujith Manoharane3233002013-06-03 09:19:26 +0530472 ath9k_hw_ani_init(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530473
Sujith Manoharand3b371c2013-09-03 10:28:55 +0530474 /*
475 * EEPROM needs to be initialized before we do this.
476 * This is required for regulatory compliance.
477 */
Sujith Manoharan0c7c2bb2013-12-06 16:28:50 +0530478 if (AR_SREV_9300_20_OR_LATER(ah)) {
Sujith Manoharand3b371c2013-09-03 10:28:55 +0530479 u16 regdmn = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
480 if ((regdmn & 0xF0) == CTL_FCC) {
Sujith Manoharan0c7c2bb2013-12-06 16:28:50 +0530481 ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_FCC_2GHZ;
482 ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_FCC_5GHZ;
Sujith Manoharand3b371c2013-09-03 10:28:55 +0530483 }
484 }
485
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700486 return 0;
487}
488
Felix Fietkauc1b976d2012-12-12 13:14:23 +0100489static int ath9k_hw_attach_ops(struct ath_hw *ah)
Luis R. Rodriguezee2bb462009-08-03 12:24:39 -0700490{
Felix Fietkauc1b976d2012-12-12 13:14:23 +0100491 if (!AR_SREV_9300_20_OR_LATER(ah))
492 return ar9002_hw_attach_ops(ah);
493
494 ar9003_hw_attach_ops(ah);
495 return 0;
Luis R. Rodriguezee2bb462009-08-03 12:24:39 -0700496}
497
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400498/* Called for all hardware families */
499static int __ath9k_hw_init(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700500{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700501 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700502 int r = 0;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700503
Senthil Balasubramanianac45c122010-12-22 21:14:20 +0530504 ath9k_hw_read_revisions(ah);
505
Sujith Manoharande825822013-12-28 09:47:11 +0530506 switch (ah->hw_version.macVersion) {
507 case AR_SREV_VERSION_5416_PCI:
508 case AR_SREV_VERSION_5416_PCIE:
509 case AR_SREV_VERSION_9160:
510 case AR_SREV_VERSION_9100:
511 case AR_SREV_VERSION_9280:
512 case AR_SREV_VERSION_9285:
513 case AR_SREV_VERSION_9287:
514 case AR_SREV_VERSION_9271:
515 case AR_SREV_VERSION_9300:
516 case AR_SREV_VERSION_9330:
517 case AR_SREV_VERSION_9485:
518 case AR_SREV_VERSION_9340:
519 case AR_SREV_VERSION_9462:
520 case AR_SREV_VERSION_9550:
521 case AR_SREV_VERSION_9565:
522 break;
523 default:
524 ath_err(common,
525 "Mac Chip Rev 0x%02x.%x is not supported by this driver\n",
526 ah->hw_version.macVersion, ah->hw_version.macRev);
527 return -EOPNOTSUPP;
528 }
529
Senthil Balasubramanian0a8d7cb2010-12-22 19:17:18 +0530530 /*
531 * Read back AR_WA into a permanent copy and set bits 14 and 17.
532 * We need to do this to avoid RMW of this register. We cannot
533 * read the reg when chip is asleep.
534 */
Sujith Manoharan27251e02013-08-27 11:34:39 +0530535 if (AR_SREV_9300_20_OR_LATER(ah)) {
536 ah->WARegVal = REG_READ(ah, AR_WA);
537 ah->WARegVal |= (AR_WA_D3_L1_DISABLE |
538 AR_WA_ASPM_TIMER_BASED_DISABLE);
539 }
Senthil Balasubramanian0a8d7cb2010-12-22 19:17:18 +0530540
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700541 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Joe Perches38002762010-12-02 19:12:36 -0800542 ath_err(common, "Couldn't reset chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700543 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700544 }
545
Sujith Manoharana4a29542012-09-10 09:20:03 +0530546 if (AR_SREV_9565(ah)) {
547 ah->WARegVal |= AR_WA_BIT22;
548 REG_WRITE(ah, AR_WA, ah->WARegVal);
549 }
550
Luis R. Rodriguezbab1f622010-04-15 17:38:20 -0400551 ath9k_hw_init_defaults(ah);
552 ath9k_hw_init_config(ah);
553
Felix Fietkauc1b976d2012-12-12 13:14:23 +0100554 r = ath9k_hw_attach_ops(ah);
555 if (r)
556 return r;
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400557
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700558 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
Joe Perches38002762010-12-02 19:12:36 -0800559 ath_err(common, "Couldn't wakeup chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700560 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700561 }
562
Gabor Juhos2c8e5932011-06-21 11:23:21 +0200563 if (AR_SREV_9271(ah) || AR_SREV_9100(ah) || AR_SREV_9340(ah) ||
Gabor Juhosc95b5842012-07-03 19:13:20 +0200564 AR_SREV_9330(ah) || AR_SREV_9550(ah))
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400565 ah->is_pciexpress = false;
566
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700567 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700568 ath9k_hw_init_cal_settings(ah);
569
Stanislaw Gruszka69ce6742011-08-05 13:10:34 +0200570 if (!ah->is_pciexpress)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700571 ath9k_hw_disablepcie(ah);
572
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700573 r = ath9k_hw_post_init(ah);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700574 if (r)
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700575 return r;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700576
577 ath9k_hw_init_mode_gain_regs(ah);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +0100578 r = ath9k_hw_fill_cap_info(ah);
579 if (r)
580 return r;
581
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700582 r = ath9k_hw_init_macaddr(ah);
583 if (r) {
Joe Perches38002762010-12-02 19:12:36 -0800584 ath_err(common, "Failed to initialize MAC address\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700585 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700586 }
587
Sujith Manoharan45987022013-12-24 10:44:18 +0530588 ath9k_hw_init_hang_checks(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700589
Luis R. Rodriguez211f5852009-10-06 21:19:07 -0400590 common->state = ATH_HW_INITIALIZED;
591
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700592 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700593}
594
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400595int ath9k_hw_init(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530596{
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400597 int ret;
598 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530599
Sujith Manoharan77fac462012-09-11 20:09:18 +0530600 /* These are all the AR5008/AR9001/AR9002/AR9003 hardware family of chipsets */
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400601 switch (ah->hw_version.devid) {
602 case AR5416_DEVID_PCI:
603 case AR5416_DEVID_PCIE:
604 case AR5416_AR9100_DEVID:
605 case AR9160_DEVID_PCI:
606 case AR9280_DEVID_PCI:
607 case AR9280_DEVID_PCIE:
608 case AR9285_DEVID_PCIE:
Senthil Balasubramaniandb3cc532010-04-15 17:38:18 -0400609 case AR9287_DEVID_PCI:
610 case AR9287_DEVID_PCIE:
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400611 case AR2427_DEVID_PCIE:
Senthil Balasubramaniandb3cc532010-04-15 17:38:18 -0400612 case AR9300_DEVID_PCIE:
Vasanthakumar Thiagarajan3050c912010-12-06 04:27:36 -0800613 case AR9300_DEVID_AR9485_PCIE:
Gabor Juhos999a7a82011-06-21 11:23:52 +0200614 case AR9300_DEVID_AR9330:
Vasanthakumar Thiagarajanbca04682011-04-19 19:29:20 +0530615 case AR9300_DEVID_AR9340:
Gabor Juhos2b943a32012-07-03 19:13:34 +0200616 case AR9300_DEVID_QCA955X:
Luis R. Rodriguez5a63ef02011-08-24 15:36:08 -0700617 case AR9300_DEVID_AR9580:
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +0530618 case AR9300_DEVID_AR9462:
Mohammed Shafi Shajakhand4e59792012-08-02 11:58:50 +0530619 case AR9485_DEVID_AR1111:
Sujith Manoharan77fac462012-09-11 20:09:18 +0530620 case AR9300_DEVID_AR9565:
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400621 break;
622 default:
623 if (common->bus_ops->ath_bus_type == ATH_USB)
624 break;
Joe Perches38002762010-12-02 19:12:36 -0800625 ath_err(common, "Hardware device ID 0x%04x not supported\n",
626 ah->hw_version.devid);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400627 return -EOPNOTSUPP;
628 }
Sujithf1dc5602008-10-29 10:16:30 +0530629
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400630 ret = __ath9k_hw_init(ah);
631 if (ret) {
Joe Perches38002762010-12-02 19:12:36 -0800632 ath_err(common,
633 "Unable to initialize hardware; initialization status: %d\n",
634 ret);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400635 return ret;
636 }
Sujithf1dc5602008-10-29 10:16:30 +0530637
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400638 return 0;
Sujithf1dc5602008-10-29 10:16:30 +0530639}
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400640EXPORT_SYMBOL(ath9k_hw_init);
Sujithf1dc5602008-10-29 10:16:30 +0530641
Sujithcbe61d82009-02-09 13:27:12 +0530642static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530643{
Sujith7d0d0df2010-04-16 11:53:57 +0530644 ENABLE_REGWRITE_BUFFER(ah);
645
Sujithf1dc5602008-10-29 10:16:30 +0530646 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
647 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
648
649 REG_WRITE(ah, AR_QOS_NO_ACK,
650 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
651 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
652 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
653
654 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
655 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
656 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
657 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
658 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
Sujith7d0d0df2010-04-16 11:53:57 +0530659
660 REGWRITE_BUFFER_FLUSH(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530661}
662
Senthil Balasubramanianb84628e2011-04-22 11:32:12 +0530663u32 ar9003_get_pll_sqsum_dvc(struct ath_hw *ah)
Vivek Natarajanb1415812011-01-27 14:45:07 +0530664{
Mohammed Shafi Shajakhanf18e3c62012-06-18 13:13:30 +0530665 struct ath_common *common = ath9k_hw_common(ah);
666 int i = 0;
667
Felix Fietkauca7a4de2011-03-23 20:57:26 +0100668 REG_CLR_BIT(ah, PLL3, PLL3_DO_MEAS_MASK);
669 udelay(100);
670 REG_SET_BIT(ah, PLL3, PLL3_DO_MEAS_MASK);
671
Mohammed Shafi Shajakhanf18e3c62012-06-18 13:13:30 +0530672 while ((REG_READ(ah, PLL4) & PLL4_MEAS_DONE) == 0) {
673
Vivek Natarajanb1415812011-01-27 14:45:07 +0530674 udelay(100);
Vivek Natarajanb1415812011-01-27 14:45:07 +0530675
Mohammed Shafi Shajakhanf18e3c62012-06-18 13:13:30 +0530676 if (WARN_ON_ONCE(i >= 100)) {
677 ath_err(common, "PLL4 meaurement not done\n");
678 break;
679 }
680
681 i++;
682 }
683
Felix Fietkauca7a4de2011-03-23 20:57:26 +0100684 return (REG_READ(ah, PLL3) & SQSUM_DVC_MASK) >> 3;
Vivek Natarajanb1415812011-01-27 14:45:07 +0530685}
686EXPORT_SYMBOL(ar9003_get_pll_sqsum_dvc);
687
Sujithcbe61d82009-02-09 13:27:12 +0530688static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530689 struct ath9k_channel *chan)
690{
Vasanthakumar Thiagarajand09b17f2010-12-06 04:27:44 -0800691 u32 pll;
692
Sujith Manoharana4a29542012-09-10 09:20:03 +0530693 if (AR_SREV_9485(ah) || AR_SREV_9565(ah)) {
Vasanthakumar Thiagarajan3dfd7f62011-04-11 16:39:40 +0530694 /* program BB PLL ki and kd value, ki=0x4, kd=0x40 */
695 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
696 AR_CH0_BB_DPLL2_PLL_PWD, 0x1);
697 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
698 AR_CH0_DPLL2_KD, 0x40);
699 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
700 AR_CH0_DPLL2_KI, 0x4);
Vivek Natarajan22983c32011-01-27 14:45:09 +0530701
Vasanthakumar Thiagarajan3dfd7f62011-04-11 16:39:40 +0530702 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
703 AR_CH0_BB_DPLL1_REFDIV, 0x5);
704 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
705 AR_CH0_BB_DPLL1_NINI, 0x58);
706 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
707 AR_CH0_BB_DPLL1_NFRAC, 0x0);
708
709 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
710 AR_CH0_BB_DPLL2_OUTDIV, 0x1);
711 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
712 AR_CH0_BB_DPLL2_LOCAL_PLL, 0x1);
713 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
714 AR_CH0_BB_DPLL2_EN_NEGTRIG, 0x1);
715
716 /* program BB PLL phase_shift to 0x6 */
717 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL3,
718 AR_CH0_BB_DPLL3_PHASE_SHIFT, 0x6);
719
720 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
721 AR_CH0_BB_DPLL2_PLL_PWD, 0x0);
Vivek Natarajan75e03512011-03-10 11:05:42 +0530722 udelay(1000);
Gabor Juhosa5415d62011-06-21 11:23:29 +0200723 } else if (AR_SREV_9330(ah)) {
724 u32 ddr_dpll2, pll_control2, kd;
725
726 if (ah->is_clk_25mhz) {
727 ddr_dpll2 = 0x18e82f01;
728 pll_control2 = 0xe04a3d;
729 kd = 0x1d;
730 } else {
731 ddr_dpll2 = 0x19e82f01;
732 pll_control2 = 0x886666;
733 kd = 0x3d;
734 }
735
736 /* program DDR PLL ki and kd value */
737 REG_WRITE(ah, AR_CH0_DDR_DPLL2, ddr_dpll2);
738
739 /* program DDR PLL phase_shift */
740 REG_RMW_FIELD(ah, AR_CH0_DDR_DPLL3,
741 AR_CH0_DPLL3_PHASE_SHIFT, 0x1);
742
743 REG_WRITE(ah, AR_RTC_PLL_CONTROL, 0x1142c);
744 udelay(1000);
745
746 /* program refdiv, nint, frac to RTC register */
747 REG_WRITE(ah, AR_RTC_PLL_CONTROL2, pll_control2);
748
749 /* program BB PLL kd and ki value */
750 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, AR_CH0_DPLL2_KD, kd);
751 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, AR_CH0_DPLL2_KI, 0x06);
752
753 /* program BB PLL phase_shift */
754 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL3,
755 AR_CH0_BB_DPLL3_PHASE_SHIFT, 0x1);
Gabor Juhosfc05a312012-07-03 19:13:31 +0200756 } else if (AR_SREV_9340(ah) || AR_SREV_9550(ah)) {
Vasanthakumar Thiagarajan0b488ac2011-04-20 10:26:15 +0530757 u32 regval, pll2_divint, pll2_divfrac, refdiv;
758
759 REG_WRITE(ah, AR_RTC_PLL_CONTROL, 0x1142c);
760 udelay(1000);
761
762 REG_SET_BIT(ah, AR_PHY_PLL_MODE, 0x1 << 16);
763 udelay(100);
764
765 if (ah->is_clk_25mhz) {
766 pll2_divint = 0x54;
767 pll2_divfrac = 0x1eb85;
768 refdiv = 3;
769 } else {
Gabor Juhosfc05a312012-07-03 19:13:31 +0200770 if (AR_SREV_9340(ah)) {
771 pll2_divint = 88;
772 pll2_divfrac = 0;
773 refdiv = 5;
774 } else {
775 pll2_divint = 0x11;
776 pll2_divfrac = 0x26666;
777 refdiv = 1;
778 }
Vasanthakumar Thiagarajan0b488ac2011-04-20 10:26:15 +0530779 }
780
781 regval = REG_READ(ah, AR_PHY_PLL_MODE);
782 regval |= (0x1 << 16);
783 REG_WRITE(ah, AR_PHY_PLL_MODE, regval);
784 udelay(100);
785
786 REG_WRITE(ah, AR_PHY_PLL_CONTROL, (refdiv << 27) |
787 (pll2_divint << 18) | pll2_divfrac);
788 udelay(100);
789
790 regval = REG_READ(ah, AR_PHY_PLL_MODE);
Gabor Juhosfc05a312012-07-03 19:13:31 +0200791 if (AR_SREV_9340(ah))
792 regval = (regval & 0x80071fff) | (0x1 << 30) |
793 (0x1 << 13) | (0x4 << 26) | (0x18 << 19);
794 else
795 regval = (regval & 0x80071fff) | (0x3 << 30) |
796 (0x1 << 13) | (0x4 << 26) | (0x60 << 19);
Vasanthakumar Thiagarajan0b488ac2011-04-20 10:26:15 +0530797 REG_WRITE(ah, AR_PHY_PLL_MODE, regval);
798 REG_WRITE(ah, AR_PHY_PLL_MODE,
799 REG_READ(ah, AR_PHY_PLL_MODE) & 0xfffeffff);
800 udelay(1000);
Vivek Natarajan22983c32011-01-27 14:45:09 +0530801 }
Vasanthakumar Thiagarajand09b17f2010-12-06 04:27:44 -0800802
803 pll = ath9k_hw_compute_pll_control(ah, chan);
Sujith Manoharan8565f8b2012-09-10 09:20:29 +0530804 if (AR_SREV_9565(ah))
805 pll |= 0x40000;
Gabor Juhosd03a66c2009-01-14 20:17:09 +0100806 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +0530807
Gabor Juhosfc05a312012-07-03 19:13:31 +0200808 if (AR_SREV_9485(ah) || AR_SREV_9340(ah) || AR_SREV_9330(ah) ||
809 AR_SREV_9550(ah))
Vasanthakumar Thiagarajan3dfd7f62011-04-11 16:39:40 +0530810 udelay(1000);
811
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -0400812 /* Switch the core clock for ar9271 to 117Mhz */
813 if (AR_SREV_9271(ah)) {
Sujith25e2ab12010-03-17 14:25:22 +0530814 udelay(500);
815 REG_WRITE(ah, 0x50040, 0x304);
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -0400816 }
817
Sujithf1dc5602008-10-29 10:16:30 +0530818 udelay(RTC_PLL_SETTLE_DELAY);
819
820 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
Vasanthakumar Thiagarajan0b488ac2011-04-20 10:26:15 +0530821
Gabor Juhosfc05a312012-07-03 19:13:31 +0200822 if (AR_SREV_9340(ah) || AR_SREV_9550(ah)) {
Vasanthakumar Thiagarajan0b488ac2011-04-20 10:26:15 +0530823 if (ah->is_clk_25mhz) {
824 REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x17c << 1);
825 REG_WRITE(ah, AR_SLP32_MODE, 0x0010f3d7);
826 REG_WRITE(ah, AR_SLP32_INC, 0x0001e7ae);
827 } else {
828 REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x261 << 1);
829 REG_WRITE(ah, AR_SLP32_MODE, 0x0010f400);
830 REG_WRITE(ah, AR_SLP32_INC, 0x0001e800);
831 }
832 udelay(100);
833 }
Sujithf1dc5602008-10-29 10:16:30 +0530834}
835
Sujithcbe61d82009-02-09 13:27:12 +0530836static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -0800837 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +0530838{
Vasanthakumar Thiagarajan79d1d2b2011-04-19 19:29:19 +0530839 u32 sync_default = AR_INTR_SYNC_DEFAULT;
Pavel Roskin152d5302010-03-31 18:05:37 -0400840 u32 imr_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +0530841 AR_IMR_TXURN |
842 AR_IMR_RXERR |
843 AR_IMR_RXORN |
844 AR_IMR_BCNMISC;
845
Gabor Juhos3b8a0572012-07-03 19:13:29 +0200846 if (AR_SREV_9340(ah) || AR_SREV_9550(ah))
Vasanthakumar Thiagarajan79d1d2b2011-04-19 19:29:19 +0530847 sync_default &= ~AR_INTR_SYNC_HOST1_FATAL;
848
Vasanthakumar Thiagarajan66860242010-04-15 17:39:07 -0400849 if (AR_SREV_9300_20_OR_LATER(ah)) {
850 imr_reg |= AR_IMR_RXOK_HP;
851 if (ah->config.rx_intr_mitigation)
852 imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
853 else
854 imr_reg |= AR_IMR_RXOK_LP;
Sujithf1dc5602008-10-29 10:16:30 +0530855
Vasanthakumar Thiagarajan66860242010-04-15 17:39:07 -0400856 } else {
857 if (ah->config.rx_intr_mitigation)
858 imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
859 else
860 imr_reg |= AR_IMR_RXOK;
861 }
862
863 if (ah->config.tx_intr_mitigation)
864 imr_reg |= AR_IMR_TXINTM | AR_IMR_TXMINTR;
865 else
866 imr_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +0530867
Sujith7d0d0df2010-04-16 11:53:57 +0530868 ENABLE_REGWRITE_BUFFER(ah);
869
Pavel Roskin152d5302010-03-31 18:05:37 -0400870 REG_WRITE(ah, AR_IMR, imr_reg);
Pavel Roskin74bad5c2010-02-23 18:15:27 -0500871 ah->imrs2_reg |= AR_IMR_S2_GTT;
872 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
Sujithf1dc5602008-10-29 10:16:30 +0530873
874 if (!AR_SREV_9100(ah)) {
875 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
Vasanthakumar Thiagarajan79d1d2b2011-04-19 19:29:19 +0530876 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, sync_default);
Sujithf1dc5602008-10-29 10:16:30 +0530877 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
878 }
Vasanthakumar Thiagarajan66860242010-04-15 17:39:07 -0400879
Sujith7d0d0df2010-04-16 11:53:57 +0530880 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +0530881
Vasanthakumar Thiagarajan66860242010-04-15 17:39:07 -0400882 if (AR_SREV_9300_20_OR_LATER(ah)) {
883 REG_WRITE(ah, AR_INTR_PRIO_ASYNC_ENABLE, 0);
884 REG_WRITE(ah, AR_INTR_PRIO_ASYNC_MASK, 0);
885 REG_WRITE(ah, AR_INTR_PRIO_SYNC_ENABLE, 0);
886 REG_WRITE(ah, AR_INTR_PRIO_SYNC_MASK, 0);
887 }
Sujithf1dc5602008-10-29 10:16:30 +0530888}
889
Felix Fietkaub6ba41b2011-07-09 11:12:50 +0700890static void ath9k_hw_set_sifs_time(struct ath_hw *ah, u32 us)
891{
892 u32 val = ath9k_hw_mac_to_clks(ah, us - 2);
893 val = min(val, (u32) 0xFFFF);
894 REG_WRITE(ah, AR_D_GBL_IFS_SIFS, val);
895}
896
Felix Fietkau0005baf2010-01-15 02:33:40 +0100897static void ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +0530898{
Felix Fietkau0005baf2010-01-15 02:33:40 +0100899 u32 val = ath9k_hw_mac_to_clks(ah, us);
900 val = min(val, (u32) 0xFFFF);
901 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, val);
Sujithf1dc5602008-10-29 10:16:30 +0530902}
903
Felix Fietkau0005baf2010-01-15 02:33:40 +0100904static void ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +0530905{
Felix Fietkau0005baf2010-01-15 02:33:40 +0100906 u32 val = ath9k_hw_mac_to_clks(ah, us);
907 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_ACK));
908 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_ACK, val);
909}
910
911static void ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
912{
913 u32 val = ath9k_hw_mac_to_clks(ah, us);
914 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_CTS));
915 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_CTS, val);
Sujithf1dc5602008-10-29 10:16:30 +0530916}
917
Sujithcbe61d82009-02-09 13:27:12 +0530918static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +0530919{
Sujithf1dc5602008-10-29 10:16:30 +0530920 if (tu > 0xFFFF) {
Joe Perchesd2182b62011-12-15 14:55:53 -0800921 ath_dbg(ath9k_hw_common(ah), XMIT, "bad global tx timeout %u\n",
922 tu);
Sujith2660b812009-02-09 13:27:26 +0530923 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +0530924 return false;
925 } else {
926 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +0530927 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +0530928 return true;
929 }
930}
931
Felix Fietkau0005baf2010-01-15 02:33:40 +0100932void ath9k_hw_init_global_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530933{
Felix Fietkaub6ba41b2011-07-09 11:12:50 +0700934 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkaub6ba41b2011-07-09 11:12:50 +0700935 const struct ath9k_channel *chan = ah->curchan;
Felix Fietkaue115b7e2012-04-19 21:18:23 +0200936 int acktimeout, ctstimeout, ack_offset = 0;
Felix Fietkaue239d852010-01-15 02:34:58 +0100937 int slottime;
Felix Fietkau0005baf2010-01-15 02:33:40 +0100938 int sifstime;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +0700939 int rx_lat = 0, tx_lat = 0, eifs = 0;
940 u32 reg;
Felix Fietkau0005baf2010-01-15 02:33:40 +0100941
Joe Perchesd2182b62011-12-15 14:55:53 -0800942 ath_dbg(ath9k_hw_common(ah), RESET, "ah->misc_mode 0x%x\n",
Joe Perches226afe62010-12-02 19:12:37 -0800943 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +0530944
Felix Fietkaub6ba41b2011-07-09 11:12:50 +0700945 if (!chan)
946 return;
947
Sujith2660b812009-02-09 13:27:26 +0530948 if (ah->misc_mode != 0)
Felix Fietkauca7a4de2011-03-23 20:57:26 +0100949 REG_SET_BIT(ah, AR_PCU_MISC, ah->misc_mode);
Felix Fietkau0005baf2010-01-15 02:33:40 +0100950
Rajkumar Manoharan81a91d52011-08-31 10:47:30 +0530951 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
952 rx_lat = 41;
953 else
954 rx_lat = 37;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +0700955 tx_lat = 54;
956
Felix Fietkaue88e4862012-04-19 21:18:22 +0200957 if (IS_CHAN_5GHZ(chan))
958 sifstime = 16;
959 else
960 sifstime = 10;
961
Felix Fietkaub6ba41b2011-07-09 11:12:50 +0700962 if (IS_CHAN_HALF_RATE(chan)) {
963 eifs = 175;
964 rx_lat *= 2;
965 tx_lat *= 2;
966 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
967 tx_lat += 11;
968
Simon Wunderlich92367fe72013-08-14 08:01:30 +0200969 sifstime = 32;
Felix Fietkaue115b7e2012-04-19 21:18:23 +0200970 ack_offset = 16;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +0700971 slottime = 13;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +0700972 } else if (IS_CHAN_QUARTER_RATE(chan)) {
973 eifs = 340;
Rajkumar Manoharan81a91d52011-08-31 10:47:30 +0530974 rx_lat = (rx_lat * 4) - 1;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +0700975 tx_lat *= 4;
976 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
977 tx_lat += 22;
978
Simon Wunderlich92367fe72013-08-14 08:01:30 +0200979 sifstime = 64;
Felix Fietkaue115b7e2012-04-19 21:18:23 +0200980 ack_offset = 32;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +0700981 slottime = 21;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +0700982 } else {
Rajkumar Manoharana7be0392011-08-27 12:13:21 +0530983 if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah)) {
984 eifs = AR_D_GBL_IFS_EIFS_ASYNC_FIFO;
985 reg = AR_USEC_ASYNC_FIFO;
986 } else {
987 eifs = REG_READ(ah, AR_D_GBL_IFS_EIFS)/
988 common->clockrate;
989 reg = REG_READ(ah, AR_USEC);
990 }
Felix Fietkaub6ba41b2011-07-09 11:12:50 +0700991 rx_lat = MS(reg, AR_USEC_RX_LAT);
992 tx_lat = MS(reg, AR_USEC_TX_LAT);
993
994 slottime = ah->slottime;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +0700995 }
Felix Fietkau0005baf2010-01-15 02:33:40 +0100996
Felix Fietkaue239d852010-01-15 02:34:58 +0100997 /* As defined by IEEE 802.11-2007 17.3.8.6 */
Mathias Kretschmerf77f8232013-04-22 22:34:41 +0200998 slottime += 3 * ah->coverage_class;
999 acktimeout = slottime + sifstime + ack_offset;
Felix Fietkauadb50662011-08-28 01:52:10 +02001000 ctstimeout = acktimeout;
Felix Fietkau42c45682010-02-11 18:07:19 +01001001
1002 /*
1003 * Workaround for early ACK timeouts, add an offset to match the
Felix Fietkau55a2bb42012-02-05 21:15:18 +01001004 * initval's 64us ack timeout value. Use 48us for the CTS timeout.
Felix Fietkau42c45682010-02-11 18:07:19 +01001005 * This was initially only meant to work around an issue with delayed
1006 * BA frames in some implementations, but it has been found to fix ACK
1007 * timeout issues in other cases as well.
1008 */
Felix Fietkaue4744ec2013-10-11 23:31:01 +02001009 if (IS_CHAN_2GHZ(chan) &&
Felix Fietkaue115b7e2012-04-19 21:18:23 +02001010 !IS_CHAN_HALF_RATE(chan) && !IS_CHAN_QUARTER_RATE(chan)) {
Felix Fietkau42c45682010-02-11 18:07:19 +01001011 acktimeout += 64 - sifstime - ah->slottime;
Felix Fietkau55a2bb42012-02-05 21:15:18 +01001012 ctstimeout += 48 - sifstime - ah->slottime;
1013 }
1014
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001015 ath9k_hw_set_sifs_time(ah, sifstime);
1016 ath9k_hw_setslottime(ah, slottime);
Felix Fietkau0005baf2010-01-15 02:33:40 +01001017 ath9k_hw_set_ack_timeout(ah, acktimeout);
Felix Fietkauadb50662011-08-28 01:52:10 +02001018 ath9k_hw_set_cts_timeout(ah, ctstimeout);
Sujith2660b812009-02-09 13:27:26 +05301019 if (ah->globaltxtimeout != (u32) -1)
1020 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001021
1022 REG_WRITE(ah, AR_D_GBL_IFS_EIFS, ath9k_hw_mac_to_clks(ah, eifs));
1023 REG_RMW(ah, AR_USEC,
1024 (common->clockrate - 1) |
1025 SM(rx_lat, AR_USEC_RX_LAT) |
1026 SM(tx_lat, AR_USEC_TX_LAT),
1027 AR_USEC_TX_LAT | AR_USEC_RX_LAT | AR_USEC_USEC);
1028
Sujithf1dc5602008-10-29 10:16:30 +05301029}
Felix Fietkau0005baf2010-01-15 02:33:40 +01001030EXPORT_SYMBOL(ath9k_hw_init_global_settings);
Sujithf1dc5602008-10-29 10:16:30 +05301031
Sujith285f2dd2010-01-08 10:36:07 +05301032void ath9k_hw_deinit(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001033{
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001034 struct ath_common *common = ath9k_hw_common(ah);
1035
Sujith736b3a22010-03-17 14:25:24 +05301036 if (common->state < ATH_HW_INITIALIZED)
Felix Fietkauc1b976d2012-12-12 13:14:23 +01001037 return;
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001038
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001039 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001040}
Sujith285f2dd2010-01-08 10:36:07 +05301041EXPORT_SYMBOL(ath9k_hw_deinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001042
Sujithf1dc5602008-10-29 10:16:30 +05301043/*******/
1044/* INI */
1045/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001046
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001047u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan)
Bob Copeland3a702e42009-03-30 22:30:29 -04001048{
1049 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
1050
Felix Fietkau6b21fd22013-10-11 23:30:56 +02001051 if (IS_CHAN_2GHZ(chan))
Bob Copeland3a702e42009-03-30 22:30:29 -04001052 ctl |= CTL_11G;
1053 else
1054 ctl |= CTL_11A;
1055
1056 return ctl;
1057}
1058
Sujithf1dc5602008-10-29 10:16:30 +05301059/****************************************/
1060/* Reset and Channel Switching Routines */
1061/****************************************/
1062
Sujithcbe61d82009-02-09 13:27:12 +05301063static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301064{
Felix Fietkau57b32222010-04-15 17:39:22 -04001065 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkau86c157b2013-05-23 12:20:56 +02001066 int txbuf_size;
Sujithf1dc5602008-10-29 10:16:30 +05301067
Sujith7d0d0df2010-04-16 11:53:57 +05301068 ENABLE_REGWRITE_BUFFER(ah);
1069
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001070 /*
1071 * set AHB_MODE not to do cacheline prefetches
1072 */
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001073 if (!AR_SREV_9300_20_OR_LATER(ah))
1074 REG_SET_BIT(ah, AR_AHB_MODE, AR_AHB_PREFETCH_RD_EN);
Sujithf1dc5602008-10-29 10:16:30 +05301075
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001076 /*
1077 * let mac dma reads be in 128 byte chunks
1078 */
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001079 REG_RMW(ah, AR_TXCFG, AR_TXCFG_DMASZ_128B, AR_TXCFG_DMASZ_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05301080
Sujith7d0d0df2010-04-16 11:53:57 +05301081 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301082
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001083 /*
1084 * Restore TX Trigger Level to its pre-reset value.
1085 * The initial value depends on whether aggregation is enabled, and is
1086 * adjusted whenever underruns are detected.
1087 */
Felix Fietkau57b32222010-04-15 17:39:22 -04001088 if (!AR_SREV_9300_20_OR_LATER(ah))
1089 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +05301090
Sujith7d0d0df2010-04-16 11:53:57 +05301091 ENABLE_REGWRITE_BUFFER(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301092
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001093 /*
1094 * let mac dma writes be in 128 byte chunks
1095 */
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001096 REG_RMW(ah, AR_RXCFG, AR_RXCFG_DMASZ_128B, AR_RXCFG_DMASZ_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05301097
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001098 /*
1099 * Setup receive FIFO threshold to hold off TX activities
1100 */
Sujithf1dc5602008-10-29 10:16:30 +05301101 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1102
Felix Fietkau57b32222010-04-15 17:39:22 -04001103 if (AR_SREV_9300_20_OR_LATER(ah)) {
1104 REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_HP, 0x1);
1105 REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_LP, 0x1);
1106
1107 ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize -
1108 ah->caps.rx_status_len);
1109 }
1110
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001111 /*
1112 * reduce the number of usable entries in PCU TXBUF to avoid
1113 * wrap around issues.
1114 */
Sujithf1dc5602008-10-29 10:16:30 +05301115 if (AR_SREV_9285(ah)) {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001116 /* For AR9285 the number of Fifos are reduced to half.
1117 * So set the usable tx buf size also to half to
1118 * avoid data/delimiter underruns
1119 */
Felix Fietkau86c157b2013-05-23 12:20:56 +02001120 txbuf_size = AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE;
1121 } else if (AR_SREV_9340_13_OR_LATER(ah)) {
1122 /* Uses fewer entries for AR934x v1.3+ to prevent rx overruns */
1123 txbuf_size = AR_9340_PCU_TXBUF_CTRL_USABLE_SIZE;
1124 } else {
1125 txbuf_size = AR_PCU_TXBUF_CTRL_USABLE_SIZE;
Sujithf1dc5602008-10-29 10:16:30 +05301126 }
Vasanthakumar Thiagarajan744d4022010-04-15 17:39:27 -04001127
Felix Fietkau86c157b2013-05-23 12:20:56 +02001128 if (!AR_SREV_9271(ah))
1129 REG_WRITE(ah, AR_PCU_TXBUF_CTRL, txbuf_size);
1130
Sujith7d0d0df2010-04-16 11:53:57 +05301131 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301132
Vasanthakumar Thiagarajan744d4022010-04-15 17:39:27 -04001133 if (AR_SREV_9300_20_OR_LATER(ah))
1134 ath9k_hw_reset_txstatus_ring(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301135}
1136
Sujithcbe61d82009-02-09 13:27:12 +05301137static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301138{
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001139 u32 mask = AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC;
1140 u32 set = AR_STA_ID1_KSRCH_MODE;
Sujithf1dc5602008-10-29 10:16:30 +05301141
Sujithf1dc5602008-10-29 10:16:30 +05301142 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001143 case NL80211_IFTYPE_ADHOC:
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001144 set |= AR_STA_ID1_ADHOC;
Sujithf1dc5602008-10-29 10:16:30 +05301145 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1146 break;
Thomas Pedersen2664d662013-05-08 10:16:48 -07001147 case NL80211_IFTYPE_MESH_POINT:
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001148 case NL80211_IFTYPE_AP:
1149 set |= AR_STA_ID1_STA_AP;
1150 /* fall through */
Colin McCabed97809d2008-12-01 13:38:55 -08001151 case NL80211_IFTYPE_STATION:
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001152 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
Sujithf1dc5602008-10-29 10:16:30 +05301153 break;
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +05301154 default:
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001155 if (!ah->is_monitoring)
1156 set = 0;
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +05301157 break;
Sujithf1dc5602008-10-29 10:16:30 +05301158 }
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001159 REG_RMW(ah, AR_STA_ID1, set, mask);
Sujithf1dc5602008-10-29 10:16:30 +05301160}
1161
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001162void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled,
1163 u32 *coef_mantissa, u32 *coef_exponent)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001164{
1165 u32 coef_exp, coef_man;
1166
1167 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1168 if ((coef_scaled >> coef_exp) & 0x1)
1169 break;
1170
1171 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1172
1173 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1174
1175 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1176 *coef_exponent = coef_exp - 16;
1177}
1178
Sujith Manoharand7df7a52013-12-18 09:53:27 +05301179/* AR9330 WAR:
1180 * call external reset function to reset WMAC if:
1181 * - doing a cold reset
1182 * - we have pending frames in the TX queues.
1183 */
1184static bool ath9k_hw_ar9330_reset_war(struct ath_hw *ah, int type)
1185{
1186 int i, npend = 0;
1187
1188 for (i = 0; i < AR_NUM_QCU; i++) {
1189 npend = ath9k_hw_numtxpending(ah, i);
1190 if (npend)
1191 break;
1192 }
1193
1194 if (ah->external_reset &&
1195 (npend || type == ATH9K_RESET_COLD)) {
1196 int reset_err = 0;
1197
1198 ath_dbg(ath9k_hw_common(ah), RESET,
1199 "reset MAC via external reset\n");
1200
1201 reset_err = ah->external_reset();
1202 if (reset_err) {
1203 ath_err(ath9k_hw_common(ah),
1204 "External reset failed, err=%d\n",
1205 reset_err);
1206 return false;
1207 }
1208
1209 REG_WRITE(ah, AR_RTC_RESET, 1);
1210 }
1211
1212 return true;
1213}
1214
Sujithcbe61d82009-02-09 13:27:12 +05301215static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +05301216{
1217 u32 rst_flags;
1218 u32 tmpReg;
1219
Sujith70768492009-02-16 13:23:12 +05301220 if (AR_SREV_9100(ah)) {
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001221 REG_RMW_FIELD(ah, AR_RTC_DERIVED_CLK,
1222 AR_RTC_DERIVED_CLK_PERIOD, 1);
Sujith70768492009-02-16 13:23:12 +05301223 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1224 }
1225
Sujith7d0d0df2010-04-16 11:53:57 +05301226 ENABLE_REGWRITE_BUFFER(ah);
1227
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04001228 if (AR_SREV_9300_20_OR_LATER(ah)) {
1229 REG_WRITE(ah, AR_WA, ah->WARegVal);
1230 udelay(10);
1231 }
1232
Sujithf1dc5602008-10-29 10:16:30 +05301233 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1234 AR_RTC_FORCE_WAKE_ON_INT);
1235
1236 if (AR_SREV_9100(ah)) {
1237 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1238 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1239 } else {
1240 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
Felix Fietkaua37a9912013-05-23 12:20:55 +02001241 if (AR_SREV_9340(ah))
1242 tmpReg &= AR9340_INTR_SYNC_LOCAL_TIMEOUT;
1243 else
1244 tmpReg &= AR_INTR_SYNC_LOCAL_TIMEOUT |
1245 AR_INTR_SYNC_RADM_CPL_TIMEOUT;
1246
1247 if (tmpReg) {
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001248 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05301249 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001250
1251 val = AR_RC_HOSTIF;
1252 if (!AR_SREV_9300_20_OR_LATER(ah))
1253 val |= AR_RC_AHB;
1254 REG_WRITE(ah, AR_RC, val);
1255
1256 } else if (!AR_SREV_9300_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05301257 REG_WRITE(ah, AR_RC, AR_RC_AHB);
Sujithf1dc5602008-10-29 10:16:30 +05301258
1259 rst_flags = AR_RTC_RC_MAC_WARM;
1260 if (type == ATH9K_RESET_COLD)
1261 rst_flags |= AR_RTC_RC_MAC_COLD;
1262 }
1263
Gabor Juhos7d95847c2011-06-21 11:23:51 +02001264 if (AR_SREV_9330(ah)) {
Sujith Manoharand7df7a52013-12-18 09:53:27 +05301265 if (!ath9k_hw_ar9330_reset_war(ah, type))
1266 return false;
Gabor Juhos7d95847c2011-06-21 11:23:51 +02001267 }
1268
Rajkumar Manoharan38634952012-06-11 12:19:32 +05301269 if (ath9k_hw_mci_is_enabled(ah))
Rajkumar Manoharan506847a2012-06-12 20:18:16 +05301270 ar9003_mci_check_gpm_offset(ah);
Rajkumar Manoharan38634952012-06-11 12:19:32 +05301271
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001272 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujith7d0d0df2010-04-16 11:53:57 +05301273
1274 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301275
Sujith Manoharan4dc78c432013-12-18 09:53:26 +05301276 if (AR_SREV_9300_20_OR_LATER(ah))
1277 udelay(50);
1278 else if (AR_SREV_9100(ah))
1279 udelay(10000);
1280 else
1281 udelay(100);
Sujithf1dc5602008-10-29 10:16:30 +05301282
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001283 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301284 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001285 ath_dbg(ath9k_hw_common(ah), RESET, "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301286 return false;
1287 }
1288
1289 if (!AR_SREV_9100(ah))
1290 REG_WRITE(ah, AR_RC, 0);
1291
Sujithf1dc5602008-10-29 10:16:30 +05301292 if (AR_SREV_9100(ah))
1293 udelay(50);
1294
1295 return true;
1296}
1297
Sujithcbe61d82009-02-09 13:27:12 +05301298static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301299{
Sujith7d0d0df2010-04-16 11:53:57 +05301300 ENABLE_REGWRITE_BUFFER(ah);
1301
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04001302 if (AR_SREV_9300_20_OR_LATER(ah)) {
1303 REG_WRITE(ah, AR_WA, ah->WARegVal);
1304 udelay(10);
1305 }
1306
Sujithf1dc5602008-10-29 10:16:30 +05301307 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1308 AR_RTC_FORCE_WAKE_ON_INT);
1309
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001310 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301311 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1312
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001313 REG_WRITE(ah, AR_RTC_RESET, 0);
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301314
Sujith7d0d0df2010-04-16 11:53:57 +05301315 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301316
Sujith Manoharanafe36532013-12-18 09:53:25 +05301317 udelay(2);
Senthil Balasubramanian84e21692010-04-15 17:38:30 -04001318
1319 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301320 REG_WRITE(ah, AR_RC, 0);
1321
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001322 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301323
1324 if (!ath9k_hw_wait(ah,
1325 AR_RTC_STATUS,
1326 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301327 AR_RTC_STATUS_ON,
1328 AH_WAIT_TIMEOUT)) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001329 ath_dbg(ath9k_hw_common(ah), RESET, "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301330 return false;
1331 }
1332
Sujithf1dc5602008-10-29 10:16:30 +05301333 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1334}
1335
Sujithcbe61d82009-02-09 13:27:12 +05301336static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301337{
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301338 bool ret = false;
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05301339
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04001340 if (AR_SREV_9300_20_OR_LATER(ah)) {
1341 REG_WRITE(ah, AR_WA, ah->WARegVal);
1342 udelay(10);
1343 }
1344
Sujithf1dc5602008-10-29 10:16:30 +05301345 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1346 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1347
Felix Fietkauceb26a62012-10-03 21:07:51 +02001348 if (!ah->reset_power_on)
1349 type = ATH9K_RESET_POWER_ON;
1350
Sujithf1dc5602008-10-29 10:16:30 +05301351 switch (type) {
1352 case ATH9K_RESET_POWER_ON:
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301353 ret = ath9k_hw_set_reset_power_on(ah);
Sujith Manoharanda8fb122012-11-17 21:20:50 +05301354 if (ret)
Felix Fietkauceb26a62012-10-03 21:07:51 +02001355 ah->reset_power_on = true;
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301356 break;
Sujithf1dc5602008-10-29 10:16:30 +05301357 case ATH9K_RESET_WARM:
1358 case ATH9K_RESET_COLD:
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301359 ret = ath9k_hw_set_reset(ah, type);
1360 break;
Sujithf1dc5602008-10-29 10:16:30 +05301361 default:
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301362 break;
Sujithf1dc5602008-10-29 10:16:30 +05301363 }
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301364
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301365 return ret;
Sujithf1dc5602008-10-29 10:16:30 +05301366}
1367
Sujithcbe61d82009-02-09 13:27:12 +05301368static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301369 struct ath9k_channel *chan)
1370{
Felix Fietkau9c083af2012-03-03 15:17:02 +01001371 int reset_type = ATH9K_RESET_WARM;
1372
1373 if (AR_SREV_9280(ah)) {
1374 if (ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1375 reset_type = ATH9K_RESET_POWER_ON;
1376 else
1377 reset_type = ATH9K_RESET_COLD;
Felix Fietkau3412f2f02013-02-25 20:51:07 +01001378 } else if (ah->chip_fullsleep || REG_READ(ah, AR_Q_TXE) ||
1379 (REG_READ(ah, AR_CR) & AR_CR_RXE))
1380 reset_type = ATH9K_RESET_COLD;
Felix Fietkau9c083af2012-03-03 15:17:02 +01001381
1382 if (!ath9k_hw_set_reset_reg(ah, reset_type))
Sujithf1dc5602008-10-29 10:16:30 +05301383 return false;
1384
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001385 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05301386 return false;
1387
Sujith2660b812009-02-09 13:27:26 +05301388 ah->chip_fullsleep = false;
Felix Fietkaubfc441a2012-05-24 14:32:22 +02001389
1390 if (AR_SREV_9330(ah))
1391 ar9003_hw_internal_regulator_apply(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301392 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301393
1394 return true;
1395}
1396
Sujithcbe61d82009-02-09 13:27:12 +05301397static bool ath9k_hw_channel_change(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001398 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301399{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001400 struct ath_common *common = ath9k_hw_common(ah);
Sujith Manoharanb840cff2013-07-16 12:03:19 +05301401 struct ath9k_hw_capabilities *pCap = &ah->caps;
1402 bool band_switch = false, mode_diff = false;
Sujith Manoharan70e89a72013-07-16 12:03:22 +05301403 u8 ini_reloaded = 0;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001404 u32 qnum;
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001405 int r;
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301406
Sujith Manoharanb840cff2013-07-16 12:03:19 +05301407 if (pCap->hw_caps & ATH9K_HW_CAP_FCC_BAND_SWITCH) {
Felix Fietkauaf02efb2013-11-18 20:14:44 +01001408 u32 flags_diff = chan->channelFlags ^ ah->curchan->channelFlags;
1409 band_switch = !!(flags_diff & CHANNEL_5GHZ);
1410 mode_diff = !!(flags_diff & ~CHANNEL_HT);
Sujith Manoharanb840cff2013-07-16 12:03:19 +05301411 }
Sujithf1dc5602008-10-29 10:16:30 +05301412
1413 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1414 if (ath9k_hw_numtxpending(ah, qnum)) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001415 ath_dbg(common, QUEUE,
Joe Perches226afe62010-12-02 19:12:37 -08001416 "Transmit frames pending on queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301417 return false;
1418 }
1419 }
1420
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001421 if (!ath9k_hw_rfbus_req(ah)) {
Joe Perches38002762010-12-02 19:12:36 -08001422 ath_err(common, "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301423 return false;
1424 }
1425
Sujith Manoharanb840cff2013-07-16 12:03:19 +05301426 if (band_switch || mode_diff) {
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301427 ath9k_hw_mark_phy_inactive(ah);
1428 udelay(5);
1429
Sujith Manoharan5f35c0f2013-07-16 12:03:20 +05301430 if (band_switch)
1431 ath9k_hw_init_pll(ah, chan);
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301432
1433 if (ath9k_hw_fast_chan_change(ah, chan, &ini_reloaded)) {
1434 ath_err(common, "Failed to do fast channel change\n");
1435 return false;
1436 }
1437 }
1438
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001439 ath9k_hw_set_channel_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301440
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001441 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001442 if (r) {
Joe Perches38002762010-12-02 19:12:36 -08001443 ath_err(common, "Failed to set channel\n");
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001444 return false;
Sujithf1dc5602008-10-29 10:16:30 +05301445 }
Felix Fietkaudfdac8a2010-10-08 22:13:51 +02001446 ath9k_hw_set_clockrate(ah);
Gabor Juhos64ea57d2012-04-15 20:38:05 +02001447 ath9k_hw_apply_txpower(ah, chan, false);
Sujithf1dc5602008-10-29 10:16:30 +05301448
Felix Fietkau81c507a2013-10-11 23:30:55 +02001449 ath9k_hw_set_delta_slope(ah, chan);
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001450 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301451
Sujith Manoharan70e89a72013-07-16 12:03:22 +05301452 if (band_switch || ini_reloaded)
1453 ah->eep_ops->set_board_values(ah, chan);
1454
1455 ath9k_hw_init_bb(ah, chan);
1456 ath9k_hw_rfbus_done(ah);
1457
1458 if (band_switch || ini_reloaded) {
Rajkumar Manoharana126ff52011-10-13 11:00:42 +05301459 ah->ah_flags |= AH_FASTCC;
Sujith Manoharan70e89a72013-07-16 12:03:22 +05301460 ath9k_hw_init_cal(ah, chan);
Rajkumar Manoharana126ff52011-10-13 11:00:42 +05301461 ah->ah_flags &= ~AH_FASTCC;
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301462 }
1463
Sujithf1dc5602008-10-29 10:16:30 +05301464 return true;
1465}
1466
Felix Fietkau691680b2011-03-19 13:55:38 +01001467static void ath9k_hw_apply_gpio_override(struct ath_hw *ah)
1468{
1469 u32 gpio_mask = ah->gpio_mask;
1470 int i;
1471
1472 for (i = 0; gpio_mask; i++, gpio_mask >>= 1) {
1473 if (!(gpio_mask & 1))
1474 continue;
1475
1476 ath9k_hw_cfg_output(ah, i, AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1477 ath9k_hw_set_gpio(ah, i, !!(ah->gpio_val & BIT(i)));
1478 }
1479}
1480
Sujith Manoharan1e516ca2013-09-11 21:30:27 +05301481void ath9k_hw_check_nav(struct ath_hw *ah)
1482{
1483 struct ath_common *common = ath9k_hw_common(ah);
1484 u32 val;
1485
1486 val = REG_READ(ah, AR_NAV);
1487 if (val != 0xdeadbeef && val > 0x7fff) {
1488 ath_dbg(common, BSTUCK, "Abnormal NAV: 0x%x\n", val);
1489 REG_WRITE(ah, AR_NAV, 0);
1490 }
1491}
1492EXPORT_SYMBOL(ath9k_hw_check_nav);
1493
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001494bool ath9k_hw_check_alive(struct ath_hw *ah)
Johannes Berg3b319aa2009-06-13 14:50:26 +05301495{
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001496 int count = 50;
1497 u32 reg;
Johannes Berg3b319aa2009-06-13 14:50:26 +05301498
Rajkumar Manoharan01e18912012-03-15 05:34:27 +05301499 if (AR_SREV_9300(ah))
1500 return !ath9k_hw_detect_mac_hang(ah);
1501
Felix Fietkaue17f83e2010-09-22 12:34:53 +02001502 if (AR_SREV_9285_12_OR_LATER(ah))
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001503 return true;
Johannes Berg3b319aa2009-06-13 14:50:26 +05301504
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001505 do {
1506 reg = REG_READ(ah, AR_OBS_BUS_1);
1507
1508 if ((reg & 0x7E7FFFEF) == 0x00702400)
1509 continue;
1510
1511 switch (reg & 0x7E000B00) {
1512 case 0x1E000000:
1513 case 0x52000B00:
1514 case 0x18000B00:
1515 continue;
1516 default:
1517 return true;
1518 }
1519 } while (count-- > 0);
1520
1521 return false;
Johannes Berg3b319aa2009-06-13 14:50:26 +05301522}
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001523EXPORT_SYMBOL(ath9k_hw_check_alive);
Johannes Berg3b319aa2009-06-13 14:50:26 +05301524
Sujith Manoharan15d2b582013-03-04 12:42:53 +05301525static void ath9k_hw_init_mfp(struct ath_hw *ah)
1526{
1527 /* Setup MFP options for CCMP */
1528 if (AR_SREV_9280_20_OR_LATER(ah)) {
1529 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
1530 * frames when constructing CCMP AAD. */
1531 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
1532 0xc7ff);
1533 ah->sw_mgmt_crypto = false;
1534 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1535 /* Disable hardware crypto for management frames */
1536 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
1537 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
1538 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1539 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
1540 ah->sw_mgmt_crypto = true;
1541 } else {
1542 ah->sw_mgmt_crypto = true;
1543 }
1544}
1545
1546static void ath9k_hw_reset_opmode(struct ath_hw *ah,
1547 u32 macStaId1, u32 saveDefAntenna)
1548{
1549 struct ath_common *common = ath9k_hw_common(ah);
1550
1551 ENABLE_REGWRITE_BUFFER(ah);
1552
Felix Fietkauecbbed32013-04-16 12:51:56 +02001553 REG_RMW(ah, AR_STA_ID1, macStaId1
Sujith Manoharan15d2b582013-03-04 12:42:53 +05301554 | AR_STA_ID1_RTS_USE_DEF
1555 | (ah->config.ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Felix Fietkauecbbed32013-04-16 12:51:56 +02001556 | ah->sta_id1_defaults,
1557 ~AR_STA_ID1_SADH_MASK);
Sujith Manoharan15d2b582013-03-04 12:42:53 +05301558 ath_hw_setbssidmask(common);
1559 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
1560 ath9k_hw_write_associd(ah);
1561 REG_WRITE(ah, AR_ISR, ~0);
1562 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
1563
1564 REGWRITE_BUFFER_FLUSH(ah);
1565
1566 ath9k_hw_set_operating_mode(ah, ah->opmode);
1567}
1568
1569static void ath9k_hw_init_queues(struct ath_hw *ah)
1570{
1571 int i;
1572
1573 ENABLE_REGWRITE_BUFFER(ah);
1574
1575 for (i = 0; i < AR_NUM_DCU; i++)
1576 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
1577
1578 REGWRITE_BUFFER_FLUSH(ah);
1579
1580 ah->intr_txqs = 0;
1581 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1582 ath9k_hw_resettxqueue(ah, i);
1583}
1584
1585/*
1586 * For big endian systems turn on swapping for descriptors
1587 */
1588static void ath9k_hw_init_desc(struct ath_hw *ah)
1589{
1590 struct ath_common *common = ath9k_hw_common(ah);
1591
1592 if (AR_SREV_9100(ah)) {
1593 u32 mask;
1594 mask = REG_READ(ah, AR_CFG);
1595 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
1596 ath_dbg(common, RESET, "CFG Byte Swap Set 0x%x\n",
1597 mask);
1598 } else {
1599 mask = INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
1600 REG_WRITE(ah, AR_CFG, mask);
1601 ath_dbg(common, RESET, "Setting CFG 0x%x\n",
1602 REG_READ(ah, AR_CFG));
1603 }
1604 } else {
1605 if (common->bus_ops->ath_bus_type == ATH_USB) {
1606 /* Configure AR9271 target WLAN */
1607 if (AR_SREV_9271(ah))
1608 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
1609 else
1610 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
1611 }
1612#ifdef __BIG_ENDIAN
1613 else if (AR_SREV_9330(ah) || AR_SREV_9340(ah) ||
1614 AR_SREV_9550(ah))
1615 REG_RMW(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB, 0);
1616 else
1617 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
1618#endif
1619 }
1620}
1621
Sujith Manoharancaed6572012-03-14 14:40:46 +05301622/*
1623 * Fast channel change:
1624 * (Change synthesizer based on channel freq without resetting chip)
Sujith Manoharancaed6572012-03-14 14:40:46 +05301625 */
1626static int ath9k_hw_do_fastcc(struct ath_hw *ah, struct ath9k_channel *chan)
1627{
1628 struct ath_common *common = ath9k_hw_common(ah);
Sujith Manoharanb840cff2013-07-16 12:03:19 +05301629 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujith Manoharancaed6572012-03-14 14:40:46 +05301630 int ret;
1631
1632 if (AR_SREV_9280(ah) && common->bus_ops->ath_bus_type == ATH_PCI)
1633 goto fail;
1634
1635 if (ah->chip_fullsleep)
1636 goto fail;
1637
1638 if (!ah->curchan)
1639 goto fail;
1640
1641 if (chan->channel == ah->curchan->channel)
1642 goto fail;
1643
Felix Fietkaufeb7bc92012-04-19 21:18:28 +02001644 if ((ah->curchan->channelFlags | chan->channelFlags) &
1645 (CHANNEL_HALF | CHANNEL_QUARTER))
1646 goto fail;
1647
Sujith Manoharanb840cff2013-07-16 12:03:19 +05301648 /*
Felix Fietkau6b21fd22013-10-11 23:30:56 +02001649 * If cross-band fcc is not supoprted, bail out if channelFlags differ.
Sujith Manoharanb840cff2013-07-16 12:03:19 +05301650 */
Felix Fietkau6b21fd22013-10-11 23:30:56 +02001651 if (!(pCap->hw_caps & ATH9K_HW_CAP_FCC_BAND_SWITCH) &&
Felix Fietkauaf02efb2013-11-18 20:14:44 +01001652 ((chan->channelFlags ^ ah->curchan->channelFlags) & ~CHANNEL_HT))
Felix Fietkau6b21fd22013-10-11 23:30:56 +02001653 goto fail;
Sujith Manoharancaed6572012-03-14 14:40:46 +05301654
1655 if (!ath9k_hw_check_alive(ah))
1656 goto fail;
1657
1658 /*
1659 * For AR9462, make sure that calibration data for
1660 * re-using are present.
1661 */
Sujith Manoharan8a905552012-05-04 13:23:59 +05301662 if (AR_SREV_9462(ah) && (ah->caldata &&
Sujith Manoharan4b9b42b2013-09-11 16:36:31 +05301663 (!test_bit(TXIQCAL_DONE, &ah->caldata->cal_flags) ||
1664 !test_bit(TXCLCAL_DONE, &ah->caldata->cal_flags) ||
1665 !test_bit(RTT_DONE, &ah->caldata->cal_flags))))
Sujith Manoharancaed6572012-03-14 14:40:46 +05301666 goto fail;
1667
1668 ath_dbg(common, RESET, "FastChannelChange for %d -> %d\n",
1669 ah->curchan->channel, chan->channel);
1670
1671 ret = ath9k_hw_channel_change(ah, chan);
1672 if (!ret)
1673 goto fail;
1674
Sujith Manoharan5955b2b2012-06-04 16:27:30 +05301675 if (ath9k_hw_mci_is_enabled(ah))
Rajkumar Manoharan1bde95fa2012-06-11 12:19:33 +05301676 ar9003_mci_2g5g_switch(ah, false);
Sujith Manoharancaed6572012-03-14 14:40:46 +05301677
Rajkumar Manoharan88033312012-09-12 18:59:19 +05301678 ath9k_hw_loadnf(ah, ah->curchan);
1679 ath9k_hw_start_nfcal(ah, true);
1680
Sujith Manoharancaed6572012-03-14 14:40:46 +05301681 if (AR_SREV_9271(ah))
1682 ar9002_hw_load_ani_reg(ah, chan);
1683
1684 return 0;
1685fail:
1686 return -EINVAL;
1687}
1688
Sujithcbe61d82009-02-09 13:27:12 +05301689int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Sujith Manoharancaed6572012-03-14 14:40:46 +05301690 struct ath9k_hw_cal_data *caldata, bool fastcc)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001691{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001692 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkau09d8e312013-11-18 20:14:43 +01001693 struct timespec ts;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001694 u32 saveLedState;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001695 u32 saveDefAntenna;
1696 u32 macStaId1;
Sujith46fe7822009-09-17 09:25:25 +05301697 u64 tsf = 0;
Felix Fietkau09d8e312013-11-18 20:14:43 +01001698 s64 usec = 0;
Sujith Manoharan15d2b582013-03-04 12:42:53 +05301699 int r;
Sujith Manoharancaed6572012-03-14 14:40:46 +05301700 bool start_mci_reset = false;
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301701 bool save_fullsleep = ah->chip_fullsleep;
1702
Sujith Manoharan5955b2b2012-06-04 16:27:30 +05301703 if (ath9k_hw_mci_is_enabled(ah)) {
Sujith Manoharan528e5d32012-02-22 12:41:12 +05301704 start_mci_reset = ar9003_mci_start_reset(ah, chan);
1705 if (start_mci_reset)
1706 return 0;
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301707 }
1708
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001709 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001710 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001711
Sujith Manoharancaed6572012-03-14 14:40:46 +05301712 if (ah->curchan && !ah->chip_fullsleep)
1713 ath9k_hw_getnf(ah, ah->curchan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001714
Felix Fietkau20bd2a02010-07-31 00:12:00 +02001715 ah->caldata = caldata;
Sujith Manoharanfcb9a3d2013-03-04 12:42:52 +05301716 if (caldata && (chan->channel != caldata->channel ||
Felix Fietkau6b21fd22013-10-11 23:30:56 +02001717 chan->channelFlags != caldata->channelFlags)) {
Felix Fietkau20bd2a02010-07-31 00:12:00 +02001718 /* Operating channel changed, reset channel calibration data */
1719 memset(caldata, 0, sizeof(*caldata));
1720 ath9k_init_nfcal_hist_buffer(ah, chan);
Felix Fietkau51dea9b2012-08-27 17:00:07 +02001721 } else if (caldata) {
Sujith Manoharan4b9b42b2013-09-11 16:36:31 +05301722 clear_bit(PAPRD_PACKET_SENT, &caldata->cal_flags);
Felix Fietkau20bd2a02010-07-31 00:12:00 +02001723 }
Lorenzo Bianconi5bc225a2013-10-11 14:09:54 +02001724 ah->noise = ath9k_hw_getchan_noise(ah, chan, chan->noisefloor);
Felix Fietkau20bd2a02010-07-31 00:12:00 +02001725
Sujith Manoharancaed6572012-03-14 14:40:46 +05301726 if (fastcc) {
1727 r = ath9k_hw_do_fastcc(ah, chan);
1728 if (!r)
1729 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001730 }
1731
Sujith Manoharan5955b2b2012-06-04 16:27:30 +05301732 if (ath9k_hw_mci_is_enabled(ah))
Sujith Manoharan528e5d32012-02-22 12:41:12 +05301733 ar9003_mci_stop_bt(ah, save_fullsleep);
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301734
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001735 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
1736 if (saveDefAntenna == 0)
1737 saveDefAntenna = 1;
1738
1739 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
1740
Felix Fietkau09d8e312013-11-18 20:14:43 +01001741 /* Save TSF before chip reset, a cold reset clears it */
1742 tsf = ath9k_hw_gettsf64(ah);
1743 getrawmonotonic(&ts);
Felix Fietkaucca213f2013-12-20 17:02:24 +01001744 usec = ts.tv_sec * 1000000ULL + ts.tv_nsec / 1000;
Sujith46fe7822009-09-17 09:25:25 +05301745
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001746 saveLedState = REG_READ(ah, AR_CFG_LED) &
1747 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
1748 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
1749
1750 ath9k_hw_mark_phy_inactive(ah);
1751
Vasanthakumar Thiagarajan45ef6a02010-12-15 07:30:53 -08001752 ah->paprd_table_write_done = false;
1753
Sujith05020d22010-03-17 14:25:23 +05301754 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001755 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1756 REG_WRITE(ah,
1757 AR9271_RESET_POWER_DOWN_CONTROL,
1758 AR9271_RADIO_RF_RST);
1759 udelay(50);
1760 }
1761
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001762 if (!ath9k_hw_chip_reset(ah, chan)) {
Joe Perches38002762010-12-02 19:12:36 -08001763 ath_err(common, "Chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001764 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001765 }
1766
Sujith05020d22010-03-17 14:25:23 +05301767 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001768 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1769 ah->htc_reset_init = false;
1770 REG_WRITE(ah,
1771 AR9271_RESET_POWER_DOWN_CONTROL,
1772 AR9271_GATE_MAC_CTL);
1773 udelay(50);
1774 }
1775
Sujith46fe7822009-09-17 09:25:25 +05301776 /* Restore TSF */
Felix Fietkau09d8e312013-11-18 20:14:43 +01001777 getrawmonotonic(&ts);
Felix Fietkaucca213f2013-12-20 17:02:24 +01001778 usec = ts.tv_sec * 1000000ULL + ts.tv_nsec / 1000 - usec;
Felix Fietkau09d8e312013-11-18 20:14:43 +01001779 ath9k_hw_settsf64(ah, tsf + usec);
Sujith46fe7822009-09-17 09:25:25 +05301780
Felix Fietkau7a370812010-09-22 12:34:52 +02001781 if (AR_SREV_9280_20_OR_LATER(ah))
Vasanthakumar Thiagarajan369391d2009-01-21 19:24:13 +05301782 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001783
Sujithe9141f72010-06-01 15:14:10 +05301784 if (!AR_SREV_9300_20_OR_LATER(ah))
1785 ar9002_hw_enable_async_fifo(ah);
1786
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001787 r = ath9k_hw_process_ini(ah, chan);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001788 if (r)
1789 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001790
Lorenzo Bianconi935d00c2013-12-12 18:10:16 +01001791 ath9k_hw_set_rfmode(ah, chan);
1792
Sujith Manoharan5955b2b2012-06-04 16:27:30 +05301793 if (ath9k_hw_mci_is_enabled(ah))
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301794 ar9003_mci_reset(ah, false, IS_CHAN_2GHZ(chan), save_fullsleep);
1795
Felix Fietkauf860d522010-06-30 02:07:48 +02001796 /*
1797 * Some AR91xx SoC devices frequently fail to accept TSF writes
1798 * right after the chip reset. When that happens, write a new
1799 * value after the initvals have been applied, with an offset
1800 * based on measured time difference
1801 */
1802 if (AR_SREV_9100(ah) && (ath9k_hw_gettsf64(ah) < tsf)) {
1803 tsf += 1500;
1804 ath9k_hw_settsf64(ah, tsf);
1805 }
1806
Sujith Manoharan15d2b582013-03-04 12:42:53 +05301807 ath9k_hw_init_mfp(ah);
Jouni Malinen0ced0e12009-01-08 13:32:13 +02001808
Felix Fietkau81c507a2013-10-11 23:30:55 +02001809 ath9k_hw_set_delta_slope(ah, chan);
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001810 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithd6509152009-03-13 08:56:05 +05301811 ah->eep_ops->set_board_values(ah, chan);
Luis R. Rodrigueza7765822009-10-19 02:33:45 -04001812
Sujith Manoharan15d2b582013-03-04 12:42:53 +05301813 ath9k_hw_reset_opmode(ah, macStaId1, saveDefAntenna);
Sujith Manoharan00e00032011-01-26 21:59:05 +05301814
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001815 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001816 if (r)
1817 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001818
Felix Fietkaudfdac8a2010-10-08 22:13:51 +02001819 ath9k_hw_set_clockrate(ah);
1820
Sujith Manoharan15d2b582013-03-04 12:42:53 +05301821 ath9k_hw_init_queues(ah);
Sujith2660b812009-02-09 13:27:26 +05301822 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001823 ath9k_hw_ani_cache_ini_regs(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001824 ath9k_hw_init_qos(ah);
1825
Sujith2660b812009-02-09 13:27:26 +05301826 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Felix Fietkau55821322010-12-17 00:57:01 +01001827 ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
Johannes Berg3b319aa2009-06-13 14:50:26 +05301828
Felix Fietkau0005baf2010-01-15 02:33:40 +01001829 ath9k_hw_init_global_settings(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001830
Felix Fietkaufe2b6af2011-07-09 11:12:51 +07001831 if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah)) {
1832 REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
1833 AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
1834 REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
1835 AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
1836 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1837 AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301838 }
1839
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001840 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PRESERVE_SEQNUM);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001841
1842 ath9k_hw_set_dma(ah);
1843
Rajkumar Manoharaned6ebd82012-06-11 12:19:34 +05301844 if (!ath9k_hw_mci_is_enabled(ah))
1845 REG_WRITE(ah, AR_OBS, 8);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001846
Sujith0ce024c2009-12-14 14:57:00 +05301847 if (ah->config.rx_intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001848 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
1849 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
1850 }
1851
Vasanthakumar Thiagarajan7f62a132010-04-15 17:39:19 -04001852 if (ah->config.tx_intr_mitigation) {
1853 REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_LAST, 300);
1854 REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_FIRST, 750);
1855 }
1856
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001857 ath9k_hw_init_bb(ah, chan);
1858
Rajkumar Manoharan77a5a662011-10-13 11:00:37 +05301859 if (caldata) {
Sujith Manoharan4b9b42b2013-09-11 16:36:31 +05301860 clear_bit(TXIQCAL_DONE, &caldata->cal_flags);
1861 clear_bit(TXCLCAL_DONE, &caldata->cal_flags);
Rajkumar Manoharan77a5a662011-10-13 11:00:37 +05301862 }
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001863 if (!ath9k_hw_init_cal(ah, chan))
Joe Perches6badaaf2009-06-28 09:26:32 -07001864 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001865
Sujith Manoharan5955b2b2012-06-04 16:27:30 +05301866 if (ath9k_hw_mci_is_enabled(ah) && ar9003_mci_end_reset(ah, chan, caldata))
Sujith Manoharan528e5d32012-02-22 12:41:12 +05301867 return -EIO;
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301868
Sujith7d0d0df2010-04-16 11:53:57 +05301869 ENABLE_REGWRITE_BUFFER(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001870
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001871 ath9k_hw_restore_chainmask(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001872 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
1873
Sujith7d0d0df2010-04-16 11:53:57 +05301874 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301875
Sujith Manoharan15d2b582013-03-04 12:42:53 +05301876 ath9k_hw_init_desc(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001877
Sujith Manoharandbccdd12012-02-22 17:55:47 +05301878 if (ath9k_hw_btcoex_is_enabled(ah))
Vasanthakumar Thiagarajan42cc41e2009-08-26 21:08:45 +05301879 ath9k_hw_btcoex_enable(ah);
1880
Sujith Manoharan5955b2b2012-06-04 16:27:30 +05301881 if (ath9k_hw_mci_is_enabled(ah))
Sujith Manoharan528e5d32012-02-22 12:41:12 +05301882 ar9003_mci_check_bt(ah);
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301883
Rajkumar Manoharan1fe860e2012-07-01 19:53:51 +05301884 ath9k_hw_loadnf(ah, chan);
1885 ath9k_hw_start_nfcal(ah, true);
1886
Sujith Manoharana7abaf72013-12-24 10:44:21 +05301887 if (AR_SREV_9300_20_OR_LATER(ah))
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04001888 ar9003_hw_bb_watchdog_config(ah);
Sujith Manoharana7abaf72013-12-24 10:44:21 +05301889
1890 if (ah->config.hw_hang_checks & HW_PHYRESTART_CLC_WAR)
Rajkumar Manoharan51ac8cb2011-05-20 17:52:13 +05301891 ar9003_hw_disable_phy_restart(ah);
Rajkumar Manoharan51ac8cb2011-05-20 17:52:13 +05301892
Felix Fietkau691680b2011-03-19 13:55:38 +01001893 ath9k_hw_apply_gpio_override(ah);
1894
Sujith Manoharan7bdea962013-08-04 14:22:00 +05301895 if (AR_SREV_9565(ah) && common->bt_ant_diversity)
Sujith Manoharan362cd032012-09-16 08:06:36 +05301896 REG_SET_BIT(ah, AR_BTCOEX_WL_LNADIV, AR_BTCOEX_WL_LNADIV_FORCE_ON);
1897
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001898 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001899}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001900EXPORT_SYMBOL(ath9k_hw_reset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001901
Sujithf1dc5602008-10-29 10:16:30 +05301902/******************************/
1903/* Power Management (Chipset) */
1904/******************************/
1905
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001906/*
1907 * Notify Power Mgt is disabled in self-generated frames.
1908 * If requested, force chip to sleep.
1909 */
Sujith Manoharan31604cf2012-06-04 16:27:36 +05301910static void ath9k_set_power_sleep(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301911{
1912 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05301913
Sujith Manoharana4a29542012-09-10 09:20:03 +05301914 if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
Rajkumar Manoharan153dccd2012-06-04 16:28:47 +05301915 REG_CLR_BIT(ah, AR_TIMER_MODE, 0xff);
1916 REG_CLR_BIT(ah, AR_NDP2_TIMER_MODE, 0xff);
1917 REG_CLR_BIT(ah, AR_SLP32_INC, 0xfffff);
Sujith Manoharan31604cf2012-06-04 16:27:36 +05301918 /* xxx Required for WLAN only case ? */
1919 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_EN, 0);
1920 udelay(100);
1921 }
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05301922
Sujith Manoharan31604cf2012-06-04 16:27:36 +05301923 /*
1924 * Clear the RTC force wake bit to allow the
1925 * mac to go to sleep.
1926 */
1927 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN);
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05301928
Rajkumar Manoharan153dccd2012-06-04 16:28:47 +05301929 if (ath9k_hw_mci_is_enabled(ah))
Sujith Manoharan31604cf2012-06-04 16:27:36 +05301930 udelay(100);
Sujithf1dc5602008-10-29 10:16:30 +05301931
Sujith Manoharan31604cf2012-06-04 16:27:36 +05301932 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
1933 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1934
1935 /* Shutdown chip. Active low */
1936 if (!AR_SREV_5416(ah) && !AR_SREV_9271(ah)) {
1937 REG_CLR_BIT(ah, AR_RTC_RESET, AR_RTC_RESET_EN);
1938 udelay(2);
Sujithf1dc5602008-10-29 10:16:30 +05301939 }
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04001940
1941 /* Clear Bit 14 of AR_WA after putting chip into Full Sleep mode. */
Rafael J. Wysockia7322812011-11-26 23:37:43 +01001942 if (AR_SREV_9300_20_OR_LATER(ah))
1943 REG_WRITE(ah, AR_WA, ah->WARegVal & ~AR_WA_D3_L1_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001944}
1945
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04001946/*
1947 * Notify Power Management is enabled in self-generating
1948 * frames. If request, set power mode of chip to
1949 * auto/normal. Duration in units of 128us (1/8 TU).
1950 */
Sujith Manoharan31604cf2012-06-04 16:27:36 +05301951static void ath9k_set_power_network_sleep(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001952{
Sujith Manoharan31604cf2012-06-04 16:27:36 +05301953 struct ath9k_hw_capabilities *pCap = &ah->caps;
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05301954
Sujithf1dc5602008-10-29 10:16:30 +05301955 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001956
Sujith Manoharan31604cf2012-06-04 16:27:36 +05301957 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
1958 /* Set WakeOnInterrupt bit; clear ForceWake bit */
1959 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1960 AR_RTC_FORCE_WAKE_ON_INT);
1961 } else {
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05301962
Sujith Manoharan31604cf2012-06-04 16:27:36 +05301963 /* When chip goes into network sleep, it could be waken
1964 * up by MCI_INT interrupt caused by BT's HW messages
1965 * (LNA_xxx, CONT_xxx) which chould be in a very fast
1966 * rate (~100us). This will cause chip to leave and
1967 * re-enter network sleep mode frequently, which in
1968 * consequence will have WLAN MCI HW to generate lots of
1969 * SYS_WAKING and SYS_SLEEPING messages which will make
1970 * BT CPU to busy to process.
1971 */
Rajkumar Manoharan153dccd2012-06-04 16:28:47 +05301972 if (ath9k_hw_mci_is_enabled(ah))
1973 REG_CLR_BIT(ah, AR_MCI_INTERRUPT_RX_MSG_EN,
1974 AR_MCI_INTERRUPT_RX_HW_MSG_MASK);
Sujith Manoharan31604cf2012-06-04 16:27:36 +05301975 /*
1976 * Clear the RTC force wake bit to allow the
1977 * mac to go to sleep.
1978 */
Rajkumar Manoharan153dccd2012-06-04 16:28:47 +05301979 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN);
Sujith Manoharan31604cf2012-06-04 16:27:36 +05301980
Rajkumar Manoharan153dccd2012-06-04 16:28:47 +05301981 if (ath9k_hw_mci_is_enabled(ah))
Sujith Manoharan31604cf2012-06-04 16:27:36 +05301982 udelay(30);
Sujithf1dc5602008-10-29 10:16:30 +05301983 }
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04001984
1985 /* Clear Bit 14 of AR_WA after putting chip into Net Sleep mode. */
1986 if (AR_SREV_9300_20_OR_LATER(ah))
1987 REG_WRITE(ah, AR_WA, ah->WARegVal & ~AR_WA_D3_L1_DISABLE);
Sujithf1dc5602008-10-29 10:16:30 +05301988}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001989
Sujith Manoharan31604cf2012-06-04 16:27:36 +05301990static bool ath9k_hw_set_power_awake(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301991{
1992 u32 val;
1993 int i;
1994
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04001995 /* Set Bits 14 and 17 of AR_WA before powering on the chip. */
1996 if (AR_SREV_9300_20_OR_LATER(ah)) {
1997 REG_WRITE(ah, AR_WA, ah->WARegVal);
1998 udelay(10);
1999 }
2000
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302001 if ((REG_READ(ah, AR_RTC_STATUS) &
2002 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2003 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Sujithf1dc5602008-10-29 10:16:30 +05302004 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002005 }
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302006 if (!AR_SREV_9300_20_OR_LATER(ah))
2007 ath9k_hw_init_pll(ah, NULL);
2008 }
2009 if (AR_SREV_9100(ah))
2010 REG_SET_BIT(ah, AR_RTC_RESET,
2011 AR_RTC_RESET_EN);
2012
2013 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2014 AR_RTC_FORCE_WAKE_EN);
2015 udelay(50);
2016
2017 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2018 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2019 if (val == AR_RTC_STATUS_ON)
2020 break;
2021 udelay(50);
2022 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2023 AR_RTC_FORCE_WAKE_EN);
2024 }
2025 if (i == 0) {
2026 ath_err(ath9k_hw_common(ah),
2027 "Failed to wakeup in %uus\n",
2028 POWER_UP_TIME / 20);
2029 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002030 }
2031
Rajkumar Manoharancdbe4082012-10-25 17:16:53 +05302032 if (ath9k_hw_mci_is_enabled(ah))
2033 ar9003_mci_set_power_awake(ah);
2034
Sujithf1dc5602008-10-29 10:16:30 +05302035 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2036
2037 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002038}
2039
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002040bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05302041{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002042 struct ath_common *common = ath9k_hw_common(ah);
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302043 int status = true;
Sujithf1dc5602008-10-29 10:16:30 +05302044 static const char *modes[] = {
2045 "AWAKE",
2046 "FULL-SLEEP",
2047 "NETWORK SLEEP",
2048 "UNDEFINED"
2049 };
Sujithf1dc5602008-10-29 10:16:30 +05302050
Gabor Juhoscbdec972009-07-24 17:27:22 +02002051 if (ah->power_mode == mode)
2052 return status;
2053
Joe Perchesd2182b62011-12-15 14:55:53 -08002054 ath_dbg(common, RESET, "%s -> %s\n",
Joe Perches226afe62010-12-02 19:12:37 -08002055 modes[ah->power_mode], modes[mode]);
Sujithf1dc5602008-10-29 10:16:30 +05302056
2057 switch (mode) {
2058 case ATH9K_PM_AWAKE:
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302059 status = ath9k_hw_set_power_awake(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302060 break;
2061 case ATH9K_PM_FULL_SLEEP:
Sujith Manoharan5955b2b2012-06-04 16:27:30 +05302062 if (ath9k_hw_mci_is_enabled(ah))
Sujith Manoharand1ca8b82012-02-22 12:41:01 +05302063 ar9003_mci_set_full_sleep(ah);
Mohammed Shafi Shajakhan10109112011-11-30 10:41:24 +05302064
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302065 ath9k_set_power_sleep(ah);
Sujith2660b812009-02-09 13:27:26 +05302066 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05302067 break;
2068 case ATH9K_PM_NETWORK_SLEEP:
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302069 ath9k_set_power_network_sleep(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302070 break;
2071 default:
Joe Perches38002762010-12-02 19:12:36 -08002072 ath_err(common, "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05302073 return false;
2074 }
Sujith2660b812009-02-09 13:27:26 +05302075 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05302076
Luis R. Rodriguez69f4aab2010-12-07 15:13:23 -08002077 /*
2078 * XXX: If this warning never comes up after a while then
2079 * simply keep the ATH_DBG_WARN_ON_ONCE() but make
2080 * ath9k_hw_setpower() return type void.
2081 */
Sujith Manoharan97dcec52010-12-20 08:02:42 +05302082
2083 if (!(ah->ah_flags & AH_UNPLUGGED))
2084 ATH_DBG_WARN_ON_ONCE(!status);
Luis R. Rodriguez69f4aab2010-12-07 15:13:23 -08002085
Sujithf1dc5602008-10-29 10:16:30 +05302086 return status;
2087}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002088EXPORT_SYMBOL(ath9k_hw_setpower);
Sujithf1dc5602008-10-29 10:16:30 +05302089
Sujithf1dc5602008-10-29 10:16:30 +05302090/*******************/
2091/* Beacon Handling */
2092/*******************/
2093
Sujithcbe61d82009-02-09 13:27:12 +05302094void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002095{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002096 int flags = 0;
2097
Sujith7d0d0df2010-04-16 11:53:57 +05302098 ENABLE_REGWRITE_BUFFER(ah);
2099
Sujith2660b812009-02-09 13:27:26 +05302100 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08002101 case NL80211_IFTYPE_ADHOC:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002102 REG_SET_BIT(ah, AR_TXCFG,
2103 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
Thomas Pedersen2664d662013-05-08 10:16:48 -07002104 case NL80211_IFTYPE_MESH_POINT:
Colin McCabed97809d2008-12-01 13:38:55 -08002105 case NL80211_IFTYPE_AP:
Felix Fietkaudd347f22011-03-22 21:54:17 +01002106 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, next_beacon);
2107 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, next_beacon -
2108 TU_TO_USEC(ah->config.dma_beacon_response_time));
2109 REG_WRITE(ah, AR_NEXT_SWBA, next_beacon -
2110 TU_TO_USEC(ah->config.sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002111 flags |=
2112 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
2113 break;
Colin McCabed97809d2008-12-01 13:38:55 -08002114 default:
Joe Perchesd2182b62011-12-15 14:55:53 -08002115 ath_dbg(ath9k_hw_common(ah), BEACON,
2116 "%s: unsupported opmode: %d\n", __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08002117 return;
2118 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002119 }
2120
Felix Fietkaudd347f22011-03-22 21:54:17 +01002121 REG_WRITE(ah, AR_BEACON_PERIOD, beacon_period);
2122 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, beacon_period);
2123 REG_WRITE(ah, AR_SWBA_PERIOD, beacon_period);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002124
Sujith7d0d0df2010-04-16 11:53:57 +05302125 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05302126
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002127 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
2128}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002129EXPORT_SYMBOL(ath9k_hw_beaconinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002130
Sujithcbe61d82009-02-09 13:27:12 +05302131void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05302132 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002133{
2134 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05302135 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002136 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002137
Sujith7d0d0df2010-04-16 11:53:57 +05302138 ENABLE_REGWRITE_BUFFER(ah);
2139
Felix Fietkau4ed15762013-12-14 18:03:44 +01002140 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, bs->bs_nexttbtt);
2141 REG_WRITE(ah, AR_BEACON_PERIOD, bs->bs_intval);
2142 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, bs->bs_intval);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002143
Sujith7d0d0df2010-04-16 11:53:57 +05302144 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05302145
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002146 REG_RMW_FIELD(ah, AR_RSSI_THR,
2147 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
2148
Rajkumar Manoharanf29f5c02011-05-20 17:52:11 +05302149 beaconintval = bs->bs_intval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002150
2151 if (bs->bs_sleepduration > beaconintval)
2152 beaconintval = bs->bs_sleepduration;
2153
2154 dtimperiod = bs->bs_dtimperiod;
2155 if (bs->bs_sleepduration > dtimperiod)
2156 dtimperiod = bs->bs_sleepduration;
2157
2158 if (beaconintval == dtimperiod)
2159 nextTbtt = bs->bs_nextdtim;
2160 else
2161 nextTbtt = bs->bs_nexttbtt;
2162
Joe Perchesd2182b62011-12-15 14:55:53 -08002163 ath_dbg(common, BEACON, "next DTIM %d\n", bs->bs_nextdtim);
2164 ath_dbg(common, BEACON, "next beacon %d\n", nextTbtt);
2165 ath_dbg(common, BEACON, "beacon period %d\n", beaconintval);
2166 ath_dbg(common, BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002167
Sujith7d0d0df2010-04-16 11:53:57 +05302168 ENABLE_REGWRITE_BUFFER(ah);
2169
Felix Fietkau4ed15762013-12-14 18:03:44 +01002170 REG_WRITE(ah, AR_NEXT_DTIM, bs->bs_nextdtim - SLEEP_SLOP);
2171 REG_WRITE(ah, AR_NEXT_TIM, nextTbtt - SLEEP_SLOP);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002172
2173 REG_WRITE(ah, AR_SLEEP1,
2174 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
2175 | AR_SLEEP1_ASSUME_DTIM);
2176
Sujith60b67f52008-08-07 10:52:38 +05302177 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002178 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
2179 else
2180 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
2181
2182 REG_WRITE(ah, AR_SLEEP2,
2183 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
2184
Felix Fietkau4ed15762013-12-14 18:03:44 +01002185 REG_WRITE(ah, AR_TIM_PERIOD, beaconintval);
2186 REG_WRITE(ah, AR_DTIM_PERIOD, dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002187
Sujith7d0d0df2010-04-16 11:53:57 +05302188 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05302189
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002190 REG_SET_BIT(ah, AR_TIMER_MODE,
2191 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
2192 AR_DTIM_TIMER_EN);
2193
Sujith4af9cf42009-02-12 10:06:47 +05302194 /* TSF Out of Range Threshold */
2195 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002196}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002197EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002198
Sujithf1dc5602008-10-29 10:16:30 +05302199/*******************/
2200/* HW Capabilities */
2201/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002202
Felix Fietkau60540692011-07-19 08:46:44 +02002203static u8 fixup_chainmask(u8 chip_chainmask, u8 eeprom_chainmask)
2204{
2205 eeprom_chainmask &= chip_chainmask;
2206 if (eeprom_chainmask)
2207 return eeprom_chainmask;
2208 else
2209 return chip_chainmask;
2210}
2211
Zefir Kurtisi9a66af32011-12-14 20:16:33 -08002212/**
2213 * ath9k_hw_dfs_tested - checks if DFS has been tested with used chipset
2214 * @ah: the atheros hardware data structure
2215 *
2216 * We enable DFS support upstream on chipsets which have passed a series
2217 * of tests. The testing requirements are going to be documented. Desired
2218 * test requirements are documented at:
2219 *
2220 * http://wireless.kernel.org/en/users/Drivers/ath9k/dfs
2221 *
2222 * Once a new chipset gets properly tested an individual commit can be used
2223 * to document the testing for DFS for that chipset.
2224 */
2225static bool ath9k_hw_dfs_tested(struct ath_hw *ah)
2226{
2227
2228 switch (ah->hw_version.macVersion) {
Zefir Kurtisi73e49372013-04-03 18:31:31 +02002229 /* for temporary testing DFS with 9280 */
2230 case AR_SREV_VERSION_9280:
Zefir Kurtisi9a66af32011-12-14 20:16:33 -08002231 /* AR9580 will likely be our first target to get testing on */
2232 case AR_SREV_VERSION_9580:
Zefir Kurtisi73e49372013-04-03 18:31:31 +02002233 return true;
Zefir Kurtisi9a66af32011-12-14 20:16:33 -08002234 default:
2235 return false;
2236 }
2237}
2238
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002239int ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002240{
Sujith2660b812009-02-09 13:27:26 +05302241 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002242 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002243 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkau60540692011-07-19 08:46:44 +02002244 unsigned int chip_chainmask;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002245
Sujith Manoharan0ff2b5c2011-04-20 11:00:34 +05302246 u16 eeval;
Vasanthakumar Thiagarajan47c80de2010-12-06 04:27:43 -08002247 u8 ant_div_ctl1, tx_chainmask, rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002248
Sujithf74df6f2009-02-09 13:27:24 +05302249 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002250 regulatory->current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05302251
Sujith2660b812009-02-09 13:27:26 +05302252 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05302253 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002254 if (regulatory->current_rd == 0x64 ||
2255 regulatory->current_rd == 0x65)
2256 regulatory->current_rd += 5;
2257 else if (regulatory->current_rd == 0x41)
2258 regulatory->current_rd = 0x43;
Joe Perchesd2182b62011-12-15 14:55:53 -08002259 ath_dbg(common, REGULATORY, "regdomain mapped to 0x%x\n",
2260 regulatory->current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002261 }
Sujithdc2222a2008-08-14 13:26:55 +05302262
Sujithf74df6f2009-02-09 13:27:24 +05302263 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002264 if ((eeval & (AR5416_OPFLAGS_11G | AR5416_OPFLAGS_11A)) == 0) {
Joe Perches38002762010-12-02 19:12:36 -08002265 ath_err(common,
2266 "no band has been marked as supported in EEPROM\n");
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002267 return -EINVAL;
2268 }
2269
Felix Fietkaud4659912010-10-14 16:02:39 +02002270 if (eeval & AR5416_OPFLAGS_11A)
2271 pCap->hw_caps |= ATH9K_HW_CAP_5GHZ;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002272
Felix Fietkaud4659912010-10-14 16:02:39 +02002273 if (eeval & AR5416_OPFLAGS_11G)
2274 pCap->hw_caps |= ATH9K_HW_CAP_2GHZ;
Sujithf1dc5602008-10-29 10:16:30 +05302275
Sujith Manoharane41db612012-09-10 09:20:12 +05302276 if (AR_SREV_9485(ah) ||
2277 AR_SREV_9285(ah) ||
2278 AR_SREV_9330(ah) ||
2279 AR_SREV_9565(ah))
Felix Fietkau60540692011-07-19 08:46:44 +02002280 chip_chainmask = 1;
Mohammed Shafi Shajakhanba5736a2011-11-30 21:10:52 +05302281 else if (AR_SREV_9462(ah))
2282 chip_chainmask = 3;
Felix Fietkau60540692011-07-19 08:46:44 +02002283 else if (!AR_SREV_9280_20_OR_LATER(ah))
2284 chip_chainmask = 7;
2285 else if (!AR_SREV_9300_20_OR_LATER(ah) || AR_SREV_9340(ah))
2286 chip_chainmask = 3;
2287 else
2288 chip_chainmask = 7;
2289
Sujithf74df6f2009-02-09 13:27:24 +05302290 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002291 /*
2292 * For AR9271 we will temporarilly uses the rx chainmax as read from
2293 * the EEPROM.
2294 */
Sujith8147f5d2009-02-20 15:13:23 +05302295 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002296 !(eeval & AR5416_OPFLAGS_11A) &&
2297 !(AR_SREV_9271(ah)))
2298 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
Sujith8147f5d2009-02-20 15:13:23 +05302299 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
Felix Fietkau598cdd52011-03-19 13:55:42 +01002300 else if (AR_SREV_9100(ah))
2301 pCap->rx_chainmask = 0x7;
Sujith8147f5d2009-02-20 15:13:23 +05302302 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002303 /* Use rx_chainmask from EEPROM. */
Sujith8147f5d2009-02-20 15:13:23 +05302304 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05302305
Felix Fietkau60540692011-07-19 08:46:44 +02002306 pCap->tx_chainmask = fixup_chainmask(chip_chainmask, pCap->tx_chainmask);
2307 pCap->rx_chainmask = fixup_chainmask(chip_chainmask, pCap->rx_chainmask);
Felix Fietkau82b2d332011-09-03 01:40:23 +02002308 ah->txchainmask = pCap->tx_chainmask;
2309 ah->rxchainmask = pCap->rx_chainmask;
Felix Fietkau60540692011-07-19 08:46:44 +02002310
Felix Fietkau7a370812010-09-22 12:34:52 +02002311 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05302312
Felix Fietkau02d2ebb2010-11-22 15:39:39 +01002313 /* enable key search for every frame in an aggregate */
2314 if (AR_SREV_9300_20_OR_LATER(ah))
2315 ah->misc_mode |= AR_PCU_ALWAYS_PERFORM_KEYSEARCH;
2316
Bruno Randolfce2220d2010-09-17 11:36:25 +09002317 common->crypt_caps |= ATH_CRYPT_CAP_CIPHER_AESCCM;
2318
Felix Fietkau0db156e2011-03-23 20:57:29 +01002319 if (ah->hw_version.devid != AR2427_DEVID_PCIE)
Sujithf1dc5602008-10-29 10:16:30 +05302320 pCap->hw_caps |= ATH9K_HW_CAP_HT;
2321 else
2322 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
2323
Sujith5b5fa352010-03-17 14:25:15 +05302324 if (AR_SREV_9271(ah))
2325 pCap->num_gpio_pins = AR9271_NUM_GPIO;
Sujith88c1f4f2010-06-30 14:46:31 +05302326 else if (AR_DEVID_7010(ah))
2327 pCap->num_gpio_pins = AR7010_NUM_GPIO;
Mohammed Shafi Shajakhan6321eb02011-09-30 11:31:27 +05302328 else if (AR_SREV_9300_20_OR_LATER(ah))
2329 pCap->num_gpio_pins = AR9300_NUM_GPIO;
2330 else if (AR_SREV_9287_11_OR_LATER(ah))
2331 pCap->num_gpio_pins = AR9287_NUM_GPIO;
Felix Fietkaue17f83e2010-09-22 12:34:53 +02002332 else if (AR_SREV_9285_12_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302333 pCap->num_gpio_pins = AR9285_NUM_GPIO;
Felix Fietkau7a370812010-09-22 12:34:52 +02002334 else if (AR_SREV_9280_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302335 pCap->num_gpio_pins = AR928X_NUM_GPIO;
2336 else
2337 pCap->num_gpio_pins = AR_NUM_GPIO;
2338
Mohammed Shafi Shajakhan1b2538b2011-12-07 16:51:39 +05302339 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302340 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
Mohammed Shafi Shajakhan1b2538b2011-12-07 16:51:39 +05302341 else
Sujithf1dc5602008-10-29 10:16:30 +05302342 pCap->rts_aggr_limit = (8 * 1024);
Sujithf1dc5602008-10-29 10:16:30 +05302343
Johannes Berg74e13062013-07-03 20:55:38 +02002344#ifdef CONFIG_ATH9K_RFKILL
Sujith2660b812009-02-09 13:27:26 +05302345 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
2346 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
2347 ah->rfkill_gpio =
2348 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
2349 ah->rfkill_polarity =
2350 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05302351
2352 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
2353 }
2354#endif
Vasanthakumar Thiagarajand5d11542010-05-17 18:57:56 -07002355 if (AR_SREV_9271(ah) || AR_SREV_9300_20_OR_LATER(ah))
Vivek Natarajanbde748a2010-04-05 14:48:05 +05302356 pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
2357 else
2358 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
Sujithf1dc5602008-10-29 10:16:30 +05302359
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302360 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302361 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
2362 else
2363 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
2364
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002365 if (AR_SREV_9300_20_OR_LATER(ah)) {
Vasanthakumar Thiagarajan784ad502010-12-06 04:27:40 -08002366 pCap->hw_caps |= ATH9K_HW_CAP_EDMA | ATH9K_HW_CAP_FASTCLOCK;
Sujith Manoharana4a29542012-09-10 09:20:03 +05302367 if (!AR_SREV_9330(ah) && !AR_SREV_9485(ah) && !AR_SREV_9565(ah))
Vasanthakumar Thiagarajan784ad502010-12-06 04:27:40 -08002368 pCap->hw_caps |= ATH9K_HW_CAP_LDPC;
2369
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002370 pCap->rx_hp_qdepth = ATH9K_HW_RX_HP_QDEPTH;
2371 pCap->rx_lp_qdepth = ATH9K_HW_RX_LP_QDEPTH;
2372 pCap->rx_status_len = sizeof(struct ar9003_rxs);
Vasanthakumar Thiagarajan162c3be2010-04-15 17:38:41 -04002373 pCap->tx_desc_len = sizeof(struct ar9003_txc);
Vasanthakumar Thiagarajan5088c2f2010-04-15 17:39:34 -04002374 pCap->txs_len = sizeof(struct ar9003_txs);
Vasanthakumar Thiagarajan162c3be2010-04-15 17:38:41 -04002375 } else {
2376 pCap->tx_desc_len = sizeof(struct ath_desc);
Felix Fietkaua949b172011-07-09 11:12:47 +07002377 if (AR_SREV_9280_20(ah))
Felix Fietkau6b42e8d2010-04-26 15:04:35 -04002378 pCap->hw_caps |= ATH9K_HW_CAP_FASTCLOCK;
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002379 }
Vasanthakumar Thiagarajan1adf02f2010-04-15 17:38:24 -04002380
Vasanthakumar Thiagarajan6c84ce02010-04-15 17:39:16 -04002381 if (AR_SREV_9300_20_OR_LATER(ah))
2382 pCap->hw_caps |= ATH9K_HW_CAP_RAC_SUPPORTED;
2383
Senthil Balasubramanian6ee63f52010-11-10 05:03:16 -08002384 if (AR_SREV_9300_20_OR_LATER(ah))
2385 ah->ent_mode = REG_READ(ah, AR_ENT_OTP);
2386
Felix Fietkaua42acef2010-09-22 12:34:54 +02002387 if (AR_SREV_9287_11_OR_LATER(ah) || AR_SREV_9271(ah))
Vasanthakumar Thiagarajan6473d242010-05-13 18:42:38 -07002388 pCap->hw_caps |= ATH9K_HW_CAP_SGI_20;
2389
Sujith Manoharanf85c3372013-08-04 14:21:53 +05302390 if (AR_SREV_9285(ah)) {
Vasanthakumar Thiagarajan754dc532010-09-02 01:34:41 -07002391 if (ah->eep_ops->get_eeprom(ah, EEP_MODAL_VER) >= 3) {
2392 ant_div_ctl1 =
2393 ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
Sujith Manoharanf85c3372013-08-04 14:21:53 +05302394 if ((ant_div_ctl1 & 0x1) && ((ant_div_ctl1 >> 3) & 0x1)) {
Vasanthakumar Thiagarajan754dc532010-09-02 01:34:41 -07002395 pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB;
Sujith Manoharanf85c3372013-08-04 14:21:53 +05302396 ath_info(common, "Enable LNA combining\n");
2397 }
Vasanthakumar Thiagarajan754dc532010-09-02 01:34:41 -07002398 }
Sujith Manoharanf85c3372013-08-04 14:21:53 +05302399 }
2400
Mohammed Shafi Shajakhanea066d52010-11-23 20:42:27 +05302401 if (AR_SREV_9300_20_OR_LATER(ah)) {
2402 if (ah->eep_ops->get_eeprom(ah, EEP_CHAIN_MASK_REDUCE))
2403 pCap->hw_caps |= ATH9K_HW_CAP_APM;
2404 }
2405
Sujith Manoharan06236e52012-09-16 08:07:12 +05302406 if (AR_SREV_9330(ah) || AR_SREV_9485(ah) || AR_SREV_9565(ah)) {
Mohammed Shafi Shajakhan21d2c632011-05-13 20:29:31 +05302407 ant_div_ctl1 = ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
Sujith Manoharanf85c3372013-08-04 14:21:53 +05302408 if ((ant_div_ctl1 >> 0x6) == 0x3) {
Mohammed Shafi Shajakhan21d2c632011-05-13 20:29:31 +05302409 pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB;
Sujith Manoharanf85c3372013-08-04 14:21:53 +05302410 ath_info(common, "Enable LNA combining\n");
2411 }
Mohammed Shafi Shajakhan21d2c632011-05-13 20:29:31 +05302412 }
Vasanthakumar Thiagarajan754dc532010-09-02 01:34:41 -07002413
Zefir Kurtisi9a66af32011-12-14 20:16:33 -08002414 if (ath9k_hw_dfs_tested(ah))
2415 pCap->hw_caps |= ATH9K_HW_CAP_DFS;
2416
Vasanthakumar Thiagarajan47c80de2010-12-06 04:27:43 -08002417 tx_chainmask = pCap->tx_chainmask;
2418 rx_chainmask = pCap->rx_chainmask;
2419 while (tx_chainmask || rx_chainmask) {
2420 if (tx_chainmask & BIT(0))
2421 pCap->max_txchains++;
2422 if (rx_chainmask & BIT(0))
2423 pCap->max_rxchains++;
2424
2425 tx_chainmask >>= 1;
2426 rx_chainmask >>= 1;
2427 }
2428
Sujith Manoharana4a29542012-09-10 09:20:03 +05302429 if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
Mohammed Shafi Shajakhan3789d592012-03-09 12:01:55 +05302430 if (!(ah->ent_mode & AR_ENT_OTP_49GHZ_DISABLE))
2431 pCap->hw_caps |= ATH9K_HW_CAP_MCI;
2432
Sujith Manoharan2b5e54e2013-06-24 18:18:46 +05302433 if (AR_SREV_9462_20_OR_LATER(ah))
Mohammed Shafi Shajakhan3789d592012-03-09 12:01:55 +05302434 pCap->hw_caps |= ATH9K_HW_CAP_RTT;
Mohammed Shafi Shajakhan3789d592012-03-09 12:01:55 +05302435 }
2436
Sujith Manoharan846e4382013-06-03 09:19:24 +05302437 if (AR_SREV_9462(ah))
2438 pCap->hw_caps |= ATH9K_HW_WOW_DEVICE_CAPABLE;
Mohammed Shafi Shajakhand6878092012-07-10 14:55:17 +05302439
Sujith Manoharan0f21ee82012-12-10 07:22:37 +05302440 if (AR_SREV_9300_20_OR_LATER(ah) &&
2441 ah->eep_ops->get_eeprom(ah, EEP_PAPRD))
2442 pCap->hw_caps |= ATH9K_HW_CAP_PAPRD;
2443
Sujith Manoharan81dc75b2013-07-16 12:03:18 +05302444 /*
2445 * Fast channel change across bands is available
2446 * only for AR9462 and AR9565.
2447 */
2448 if (AR_SREV_9462(ah) || AR_SREV_9565(ah))
2449 pCap->hw_caps |= ATH9K_HW_CAP_FCC_BAND_SWITCH;
2450
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002451 return 0;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002452}
2453
Sujithf1dc5602008-10-29 10:16:30 +05302454/****************************/
2455/* GPIO / RFKILL / Antennae */
2456/****************************/
2457
Sujithcbe61d82009-02-09 13:27:12 +05302458static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05302459 u32 gpio, u32 type)
2460{
2461 int addr;
2462 u32 gpio_shift, tmp;
2463
2464 if (gpio > 11)
2465 addr = AR_GPIO_OUTPUT_MUX3;
2466 else if (gpio > 5)
2467 addr = AR_GPIO_OUTPUT_MUX2;
2468 else
2469 addr = AR_GPIO_OUTPUT_MUX1;
2470
2471 gpio_shift = (gpio % 6) * 5;
2472
2473 if (AR_SREV_9280_20_OR_LATER(ah)
2474 || (addr != AR_GPIO_OUTPUT_MUX1)) {
2475 REG_RMW(ah, addr, (type << gpio_shift),
2476 (0x1f << gpio_shift));
2477 } else {
2478 tmp = REG_READ(ah, addr);
2479 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
2480 tmp &= ~(0x1f << gpio_shift);
2481 tmp |= (type << gpio_shift);
2482 REG_WRITE(ah, addr, tmp);
2483 }
2484}
2485
Sujithcbe61d82009-02-09 13:27:12 +05302486void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05302487{
2488 u32 gpio_shift;
2489
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07002490 BUG_ON(gpio >= ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05302491
Sujith88c1f4f2010-06-30 14:46:31 +05302492 if (AR_DEVID_7010(ah)) {
2493 gpio_shift = gpio;
2494 REG_RMW(ah, AR7010_GPIO_OE,
2495 (AR7010_GPIO_OE_AS_INPUT << gpio_shift),
2496 (AR7010_GPIO_OE_MASK << gpio_shift));
2497 return;
2498 }
Sujithf1dc5602008-10-29 10:16:30 +05302499
Sujith88c1f4f2010-06-30 14:46:31 +05302500 gpio_shift = gpio << 1;
Sujithf1dc5602008-10-29 10:16:30 +05302501 REG_RMW(ah,
2502 AR_GPIO_OE_OUT,
2503 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
2504 (AR_GPIO_OE_OUT_DRV << gpio_shift));
2505}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002506EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
Sujithf1dc5602008-10-29 10:16:30 +05302507
Sujithcbe61d82009-02-09 13:27:12 +05302508u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05302509{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302510#define MS_REG_READ(x, y) \
2511 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
2512
Sujith2660b812009-02-09 13:27:26 +05302513 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05302514 return 0xffffffff;
2515
Sujith88c1f4f2010-06-30 14:46:31 +05302516 if (AR_DEVID_7010(ah)) {
2517 u32 val;
2518 val = REG_READ(ah, AR7010_GPIO_IN);
2519 return (MS(val, AR7010_GPIO_IN_VAL) & AR_GPIO_BIT(gpio)) == 0;
2520 } else if (AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan93069902010-11-30 23:24:09 -08002521 return (MS(REG_READ(ah, AR_GPIO_IN), AR9300_GPIO_IN_VAL) &
2522 AR_GPIO_BIT(gpio)) != 0;
Felix Fietkau783dfca2010-04-15 17:38:11 -04002523 else if (AR_SREV_9271(ah))
Sujith5b5fa352010-03-17 14:25:15 +05302524 return MS_REG_READ(AR9271, gpio) != 0;
Felix Fietkaua42acef2010-09-22 12:34:54 +02002525 else if (AR_SREV_9287_11_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302526 return MS_REG_READ(AR9287, gpio) != 0;
Felix Fietkaue17f83e2010-09-22 12:34:53 +02002527 else if (AR_SREV_9285_12_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302528 return MS_REG_READ(AR9285, gpio) != 0;
Felix Fietkau7a370812010-09-22 12:34:52 +02002529 else if (AR_SREV_9280_20_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302530 return MS_REG_READ(AR928X, gpio) != 0;
2531 else
2532 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05302533}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002534EXPORT_SYMBOL(ath9k_hw_gpio_get);
Sujithf1dc5602008-10-29 10:16:30 +05302535
Sujithcbe61d82009-02-09 13:27:12 +05302536void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05302537 u32 ah_signal_type)
2538{
2539 u32 gpio_shift;
2540
Sujith88c1f4f2010-06-30 14:46:31 +05302541 if (AR_DEVID_7010(ah)) {
2542 gpio_shift = gpio;
2543 REG_RMW(ah, AR7010_GPIO_OE,
2544 (AR7010_GPIO_OE_AS_OUTPUT << gpio_shift),
2545 (AR7010_GPIO_OE_MASK << gpio_shift));
2546 return;
2547 }
2548
Sujithf1dc5602008-10-29 10:16:30 +05302549 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
Sujithf1dc5602008-10-29 10:16:30 +05302550 gpio_shift = 2 * gpio;
Sujithf1dc5602008-10-29 10:16:30 +05302551 REG_RMW(ah,
2552 AR_GPIO_OE_OUT,
2553 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
2554 (AR_GPIO_OE_OUT_DRV << gpio_shift));
2555}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002556EXPORT_SYMBOL(ath9k_hw_cfg_output);
Sujithf1dc5602008-10-29 10:16:30 +05302557
Sujithcbe61d82009-02-09 13:27:12 +05302558void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05302559{
Sujith88c1f4f2010-06-30 14:46:31 +05302560 if (AR_DEVID_7010(ah)) {
2561 val = val ? 0 : 1;
2562 REG_RMW(ah, AR7010_GPIO_OUT, ((val&1) << gpio),
2563 AR_GPIO_BIT(gpio));
2564 return;
2565 }
2566
Sujith5b5fa352010-03-17 14:25:15 +05302567 if (AR_SREV_9271(ah))
2568 val = ~val;
2569
Sujithf1dc5602008-10-29 10:16:30 +05302570 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
2571 AR_GPIO_BIT(gpio));
2572}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002573EXPORT_SYMBOL(ath9k_hw_set_gpio);
Sujithf1dc5602008-10-29 10:16:30 +05302574
Sujithcbe61d82009-02-09 13:27:12 +05302575void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05302576{
2577 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
2578}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002579EXPORT_SYMBOL(ath9k_hw_setantenna);
Sujithf1dc5602008-10-29 10:16:30 +05302580
Sujithf1dc5602008-10-29 10:16:30 +05302581/*********************/
2582/* General Operation */
2583/*********************/
2584
Sujithcbe61d82009-02-09 13:27:12 +05302585u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302586{
2587 u32 bits = REG_READ(ah, AR_RX_FILTER);
2588 u32 phybits = REG_READ(ah, AR_PHY_ERR);
2589
2590 if (phybits & AR_PHY_ERR_RADAR)
2591 bits |= ATH9K_RX_FILTER_PHYRADAR;
2592 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
2593 bits |= ATH9K_RX_FILTER_PHYERR;
2594
2595 return bits;
2596}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002597EXPORT_SYMBOL(ath9k_hw_getrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05302598
Sujithcbe61d82009-02-09 13:27:12 +05302599void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05302600{
2601 u32 phybits;
2602
Sujith7d0d0df2010-04-16 11:53:57 +05302603 ENABLE_REGWRITE_BUFFER(ah);
2604
Sujith Manoharana4a29542012-09-10 09:20:03 +05302605 if (AR_SREV_9462(ah) || AR_SREV_9565(ah))
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302606 bits |= ATH9K_RX_FILTER_CONTROL_WRAPPER;
2607
Sujith7ea310b2009-09-03 12:08:43 +05302608 REG_WRITE(ah, AR_RX_FILTER, bits);
2609
Sujithf1dc5602008-10-29 10:16:30 +05302610 phybits = 0;
2611 if (bits & ATH9K_RX_FILTER_PHYRADAR)
2612 phybits |= AR_PHY_ERR_RADAR;
2613 if (bits & ATH9K_RX_FILTER_PHYERR)
2614 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
2615 REG_WRITE(ah, AR_PHY_ERR, phybits);
2616
2617 if (phybits)
Felix Fietkauca7a4de2011-03-23 20:57:26 +01002618 REG_SET_BIT(ah, AR_RXCFG, AR_RXCFG_ZLFDMA);
Sujithf1dc5602008-10-29 10:16:30 +05302619 else
Felix Fietkauca7a4de2011-03-23 20:57:26 +01002620 REG_CLR_BIT(ah, AR_RXCFG, AR_RXCFG_ZLFDMA);
Sujith7d0d0df2010-04-16 11:53:57 +05302621
2622 REGWRITE_BUFFER_FLUSH(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302623}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002624EXPORT_SYMBOL(ath9k_hw_setrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05302625
Sujithcbe61d82009-02-09 13:27:12 +05302626bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302627{
Rajkumar Manoharan99922a42012-06-04 16:28:31 +05302628 if (ath9k_hw_mci_is_enabled(ah))
2629 ar9003_mci_bt_gain_ctrl(ah);
2630
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05302631 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
2632 return false;
2633
2634 ath9k_hw_init_pll(ah, NULL);
Felix Fietkau8efa7a82012-03-14 16:40:23 +01002635 ah->htc_reset_init = true;
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05302636 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302637}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002638EXPORT_SYMBOL(ath9k_hw_phy_disable);
Sujithf1dc5602008-10-29 10:16:30 +05302639
Sujithcbe61d82009-02-09 13:27:12 +05302640bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302641{
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002642 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05302643 return false;
2644
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05302645 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
2646 return false;
2647
2648 ath9k_hw_init_pll(ah, NULL);
2649 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302650}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002651EXPORT_SYMBOL(ath9k_hw_disable);
Sujithf1dc5602008-10-29 10:16:30 +05302652
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002653static int get_antenna_gain(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05302654{
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002655 enum eeprom_param gain_param;
Felix Fietkau9c204b42011-07-27 15:01:05 +02002656
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002657 if (IS_CHAN_2GHZ(chan))
2658 gain_param = EEP_ANTENNA_GAIN_2G;
2659 else
2660 gain_param = EEP_ANTENNA_GAIN_5G;
Sujithf1dc5602008-10-29 10:16:30 +05302661
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002662 return ah->eep_ops->get_eeprom(ah, gain_param);
2663}
2664
Gabor Juhos64ea57d2012-04-15 20:38:05 +02002665void ath9k_hw_apply_txpower(struct ath_hw *ah, struct ath9k_channel *chan,
2666 bool test)
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002667{
2668 struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
2669 struct ieee80211_channel *channel;
2670 int chan_pwr, new_pwr, max_gain;
2671 int ant_gain, ant_reduction = 0;
2672
2673 if (!chan)
2674 return;
2675
2676 channel = chan->chan;
2677 chan_pwr = min_t(int, channel->max_power * 2, MAX_RATE_POWER);
2678 new_pwr = min_t(int, chan_pwr, reg->power_limit);
2679 max_gain = chan_pwr - new_pwr + channel->max_antenna_gain * 2;
2680
2681 ant_gain = get_antenna_gain(ah, chan);
2682 if (ant_gain > max_gain)
2683 ant_reduction = ant_gain - max_gain;
Sujithf1dc5602008-10-29 10:16:30 +05302684
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07002685 ah->eep_ops->set_txpower(ah, chan,
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002686 ath9k_regd_get_ctl(reg, chan),
Gabor Juhos64ea57d2012-04-15 20:38:05 +02002687 ant_reduction, new_pwr, test);
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002688}
2689
2690void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit, bool test)
2691{
2692 struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
2693 struct ath9k_channel *chan = ah->curchan;
2694 struct ieee80211_channel *channel = chan->chan;
2695
Dan Carpenter48ef5c42011-10-17 10:28:23 +03002696 reg->power_limit = min_t(u32, limit, MAX_RATE_POWER);
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002697 if (test)
2698 channel->max_power = MAX_RATE_POWER / 2;
2699
Gabor Juhos64ea57d2012-04-15 20:38:05 +02002700 ath9k_hw_apply_txpower(ah, chan, test);
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002701
2702 if (test)
2703 channel->max_power = DIV_ROUND_UP(reg->max_power_level, 2);
Sujithf1dc5602008-10-29 10:16:30 +05302704}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002705EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
Sujithf1dc5602008-10-29 10:16:30 +05302706
Sujithcbe61d82009-02-09 13:27:12 +05302707void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302708{
Sujith2660b812009-02-09 13:27:26 +05302709 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05302710}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002711EXPORT_SYMBOL(ath9k_hw_setopmode);
Sujithf1dc5602008-10-29 10:16:30 +05302712
Sujithcbe61d82009-02-09 13:27:12 +05302713void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05302714{
2715 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
2716 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
2717}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002718EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
Sujithf1dc5602008-10-29 10:16:30 +05302719
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07002720void ath9k_hw_write_associd(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302721{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002722 struct ath_common *common = ath9k_hw_common(ah);
2723
2724 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
2725 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
2726 ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05302727}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002728EXPORT_SYMBOL(ath9k_hw_write_associd);
Sujithf1dc5602008-10-29 10:16:30 +05302729
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002730#define ATH9K_MAX_TSF_READ 10
2731
Sujithcbe61d82009-02-09 13:27:12 +05302732u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302733{
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002734 u32 tsf_lower, tsf_upper1, tsf_upper2;
2735 int i;
Sujithf1dc5602008-10-29 10:16:30 +05302736
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002737 tsf_upper1 = REG_READ(ah, AR_TSF_U32);
2738 for (i = 0; i < ATH9K_MAX_TSF_READ; i++) {
2739 tsf_lower = REG_READ(ah, AR_TSF_L32);
2740 tsf_upper2 = REG_READ(ah, AR_TSF_U32);
2741 if (tsf_upper2 == tsf_upper1)
2742 break;
2743 tsf_upper1 = tsf_upper2;
2744 }
Sujithf1dc5602008-10-29 10:16:30 +05302745
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002746 WARN_ON( i == ATH9K_MAX_TSF_READ );
2747
2748 return (((u64)tsf_upper1 << 32) | tsf_lower);
Sujithf1dc5602008-10-29 10:16:30 +05302749}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002750EXPORT_SYMBOL(ath9k_hw_gettsf64);
Sujithf1dc5602008-10-29 10:16:30 +05302751
Sujithcbe61d82009-02-09 13:27:12 +05302752void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002753{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002754 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01002755 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002756}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002757EXPORT_SYMBOL(ath9k_hw_settsf64);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002758
Sujithcbe61d82009-02-09 13:27:12 +05302759void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302760{
Gabor Juhosf9b604f2009-06-21 00:02:15 +02002761 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
2762 AH_TSF_WRITE_TIMEOUT))
Joe Perchesd2182b62011-12-15 14:55:53 -08002763 ath_dbg(ath9k_hw_common(ah), RESET,
Joe Perches226afe62010-12-02 19:12:37 -08002764 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
Gabor Juhosf9b604f2009-06-21 00:02:15 +02002765
Sujithf1dc5602008-10-29 10:16:30 +05302766 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002767}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002768EXPORT_SYMBOL(ath9k_hw_reset_tsf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002769
Sujith Manoharan60ca9f82012-07-17 17:15:37 +05302770void ath9k_hw_set_tsfadjust(struct ath_hw *ah, bool set)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002771{
Sujith Manoharan60ca9f82012-07-17 17:15:37 +05302772 if (set)
Sujith2660b812009-02-09 13:27:26 +05302773 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002774 else
Sujith2660b812009-02-09 13:27:26 +05302775 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002776}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002777EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002778
Felix Fietkaue4744ec2013-10-11 23:31:01 +02002779void ath9k_hw_set11nmac2040(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002780{
Sujithf1dc5602008-10-29 10:16:30 +05302781 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002782
Felix Fietkaue4744ec2013-10-11 23:31:01 +02002783 if (IS_CHAN_HT40(chan) && !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05302784 macmode = AR_2040_JOINED_RX_CLEAR;
2785 else
2786 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002787
Sujithf1dc5602008-10-29 10:16:30 +05302788 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002789}
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302790
2791/* HW Generic timers configuration */
2792
2793static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
2794{
2795 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2796 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2797 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2798 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2799 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2800 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2801 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2802 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2803 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
2804 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
2805 AR_NDP2_TIMER_MODE, 0x0002},
2806 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
2807 AR_NDP2_TIMER_MODE, 0x0004},
2808 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
2809 AR_NDP2_TIMER_MODE, 0x0008},
2810 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
2811 AR_NDP2_TIMER_MODE, 0x0010},
2812 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
2813 AR_NDP2_TIMER_MODE, 0x0020},
2814 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
2815 AR_NDP2_TIMER_MODE, 0x0040},
2816 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
2817 AR_NDP2_TIMER_MODE, 0x0080}
2818};
2819
2820/* HW generic timer primitives */
2821
Felix Fietkaudd347f22011-03-22 21:54:17 +01002822u32 ath9k_hw_gettsf32(struct ath_hw *ah)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302823{
2824 return REG_READ(ah, AR_TSF_L32);
2825}
Felix Fietkaudd347f22011-03-22 21:54:17 +01002826EXPORT_SYMBOL(ath9k_hw_gettsf32);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302827
2828struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
2829 void (*trigger)(void *),
2830 void (*overflow)(void *),
2831 void *arg,
2832 u8 timer_index)
2833{
2834 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2835 struct ath_gen_timer *timer;
2836
Felix Fietkauc67ce332013-12-14 18:03:38 +01002837 if ((timer_index < AR_FIRST_NDP_TIMER) ||
2838 (timer_index >= ATH_MAX_GEN_TIMER))
2839 return NULL;
2840
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302841 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
Joe Perches14f8dc42013-02-07 11:46:27 +00002842 if (timer == NULL)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302843 return NULL;
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302844
2845 /* allocate a hardware generic timer slot */
2846 timer_table->timers[timer_index] = timer;
2847 timer->index = timer_index;
2848 timer->trigger = trigger;
2849 timer->overflow = overflow;
2850 timer->arg = arg;
2851
2852 return timer;
2853}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002854EXPORT_SYMBOL(ath_gen_timer_alloc);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302855
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07002856void ath9k_hw_gen_timer_start(struct ath_hw *ah,
2857 struct ath_gen_timer *timer,
Felix Fietkauc67ce332013-12-14 18:03:38 +01002858 u32 timer_next,
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07002859 u32 timer_period)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302860{
2861 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
Felix Fietkauc67ce332013-12-14 18:03:38 +01002862 u32 mask = 0;
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302863
Felix Fietkauc67ce332013-12-14 18:03:38 +01002864 timer_table->timer_mask |= BIT(timer->index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302865
2866 /*
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302867 * Program generic timer registers
2868 */
2869 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
2870 timer_next);
2871 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
2872 timer_period);
2873 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
2874 gen_tmr_configuration[timer->index].mode_mask);
2875
Sujith Manoharana4a29542012-09-10 09:20:03 +05302876 if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302877 /*
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05302878 * Starting from AR9462, each generic timer can select which tsf
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302879 * to use. But we still follow the old rule, 0 - 7 use tsf and
2880 * 8 - 15 use tsf2.
2881 */
2882 if ((timer->index < AR_GEN_TIMER_BANK_1_LEN))
2883 REG_CLR_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL,
2884 (1 << timer->index));
2885 else
2886 REG_SET_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL,
2887 (1 << timer->index));
2888 }
2889
Felix Fietkauc67ce332013-12-14 18:03:38 +01002890 if (timer->trigger)
2891 mask |= SM(AR_GENTMR_BIT(timer->index),
2892 AR_IMR_S5_GENTIMER_TRIG);
2893 if (timer->overflow)
2894 mask |= SM(AR_GENTMR_BIT(timer->index),
2895 AR_IMR_S5_GENTIMER_THRESH);
2896
2897 REG_SET_BIT(ah, AR_IMR_S5, mask);
2898
2899 if ((ah->imask & ATH9K_INT_GENTIMER) == 0) {
2900 ah->imask |= ATH9K_INT_GENTIMER;
2901 ath9k_hw_set_interrupts(ah);
2902 }
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302903}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002904EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302905
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07002906void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302907{
2908 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2909
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302910 /* Clear generic timer enable bits. */
2911 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
2912 gen_tmr_configuration[timer->index].mode_mask);
2913
Sujith Manoharanb7f59762012-09-11 10:46:24 +05302914 if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
2915 /*
2916 * Need to switch back to TSF if it was using TSF2.
2917 */
2918 if ((timer->index >= AR_GEN_TIMER_BANK_1_LEN)) {
2919 REG_CLR_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL,
2920 (1 << timer->index));
2921 }
2922 }
2923
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302924 /* Disable both trigger and thresh interrupt masks */
2925 REG_CLR_BIT(ah, AR_IMR_S5,
2926 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
2927 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
2928
Felix Fietkauc67ce332013-12-14 18:03:38 +01002929 timer_table->timer_mask &= ~BIT(timer->index);
2930
2931 if (timer_table->timer_mask == 0) {
2932 ah->imask &= ~ATH9K_INT_GENTIMER;
2933 ath9k_hw_set_interrupts(ah);
2934 }
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302935}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002936EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302937
2938void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
2939{
2940 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2941
2942 /* free the hardware generic timer slot */
2943 timer_table->timers[timer->index] = NULL;
2944 kfree(timer);
2945}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002946EXPORT_SYMBOL(ath_gen_timer_free);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302947
2948/*
2949 * Generic Timer Interrupts handling
2950 */
2951void ath_gen_timer_isr(struct ath_hw *ah)
2952{
2953 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2954 struct ath_gen_timer *timer;
Felix Fietkauc67ce332013-12-14 18:03:38 +01002955 unsigned long trigger_mask, thresh_mask;
2956 unsigned int index;
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302957
2958 /* get hardware generic timer interrupt status */
2959 trigger_mask = ah->intr_gen_timer_trigger;
2960 thresh_mask = ah->intr_gen_timer_thresh;
Felix Fietkauc67ce332013-12-14 18:03:38 +01002961 trigger_mask &= timer_table->timer_mask;
2962 thresh_mask &= timer_table->timer_mask;
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302963
Felix Fietkauc67ce332013-12-14 18:03:38 +01002964 for_each_set_bit(index, &thresh_mask, ARRAY_SIZE(timer_table->timers)) {
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302965 timer = timer_table->timers[index];
Felix Fietkauc67ce332013-12-14 18:03:38 +01002966 if (!timer)
2967 continue;
2968 if (!timer->overflow)
2969 continue;
Felix Fietkaua6a172b2013-12-20 16:18:45 +01002970
2971 trigger_mask &= ~BIT(index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302972 timer->overflow(timer->arg);
2973 }
2974
Felix Fietkauc67ce332013-12-14 18:03:38 +01002975 for_each_set_bit(index, &trigger_mask, ARRAY_SIZE(timer_table->timers)) {
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302976 timer = timer_table->timers[index];
Felix Fietkauc67ce332013-12-14 18:03:38 +01002977 if (!timer)
2978 continue;
2979 if (!timer->trigger)
2980 continue;
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302981 timer->trigger(timer->arg);
2982 }
2983}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002984EXPORT_SYMBOL(ath_gen_timer_isr);
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04002985
Sujith05020d22010-03-17 14:25:23 +05302986/********/
2987/* HTC */
2988/********/
2989
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04002990static struct {
2991 u32 version;
2992 const char * name;
2993} ath_mac_bb_names[] = {
2994 /* Devices with external radios */
2995 { AR_SREV_VERSION_5416_PCI, "5416" },
2996 { AR_SREV_VERSION_5416_PCIE, "5418" },
2997 { AR_SREV_VERSION_9100, "9100" },
2998 { AR_SREV_VERSION_9160, "9160" },
2999 /* Single-chip solutions */
3000 { AR_SREV_VERSION_9280, "9280" },
3001 { AR_SREV_VERSION_9285, "9285" },
Luis R. Rodriguez11158472009-10-27 12:59:35 -04003002 { AR_SREV_VERSION_9287, "9287" },
3003 { AR_SREV_VERSION_9271, "9271" },
Luis R. Rodriguezec839032010-04-15 17:39:20 -04003004 { AR_SREV_VERSION_9300, "9300" },
Gabor Juhos2c8e5932011-06-21 11:23:21 +02003005 { AR_SREV_VERSION_9330, "9330" },
Florian Fainelli397e5d52011-08-25 21:33:48 +02003006 { AR_SREV_VERSION_9340, "9340" },
Senthil Balasubramanian8f06ca22011-04-01 17:16:33 +05303007 { AR_SREV_VERSION_9485, "9485" },
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05303008 { AR_SREV_VERSION_9462, "9462" },
Gabor Juhos485124c2012-07-03 19:13:19 +02003009 { AR_SREV_VERSION_9550, "9550" },
Sujith Manoharan77fac462012-09-11 20:09:18 +05303010 { AR_SREV_VERSION_9565, "9565" },
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003011};
3012
3013/* For devices with external radios */
3014static struct {
3015 u16 version;
3016 const char * name;
3017} ath_rf_names[] = {
3018 { 0, "5133" },
3019 { AR_RAD5133_SREV_MAJOR, "5133" },
3020 { AR_RAD5122_SREV_MAJOR, "5122" },
3021 { AR_RAD2133_SREV_MAJOR, "2133" },
3022 { AR_RAD2122_SREV_MAJOR, "2122" }
3023};
3024
3025/*
3026 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
3027 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003028static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003029{
3030 int i;
3031
3032 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
3033 if (ath_mac_bb_names[i].version == mac_bb_version) {
3034 return ath_mac_bb_names[i].name;
3035 }
3036 }
3037
3038 return "????";
3039}
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003040
3041/*
3042 * Return the RF name. "????" is returned if the RF is unknown.
3043 * Used for devices with external radios.
3044 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003045static const char *ath9k_hw_rf_name(u16 rf_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003046{
3047 int i;
3048
3049 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
3050 if (ath_rf_names[i].version == rf_version) {
3051 return ath_rf_names[i].name;
3052 }
3053 }
3054
3055 return "????";
3056}
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003057
3058void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
3059{
3060 int used;
3061
3062 /* chipsets >= AR9280 are single-chip */
Felix Fietkau7a370812010-09-22 12:34:52 +02003063 if (AR_SREV_9280_20_OR_LATER(ah)) {
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +02003064 used = scnprintf(hw_name, len,
3065 "Atheros AR%s Rev:%x",
3066 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3067 ah->hw_version.macRev);
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003068 }
3069 else {
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +02003070 used = scnprintf(hw_name, len,
3071 "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
3072 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3073 ah->hw_version.macRev,
3074 ath9k_hw_rf_name((ah->hw_version.analog5GhzRev
3075 & AR_RADIO_SREV_MAJOR)),
3076 ah->hw_version.phyRev);
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003077 }
3078
3079 hw_name[used] = '\0';
3080}
3081EXPORT_SYMBOL(ath9k_hw_name);