blob: eb408831f3cff9226cc034774c7b01410616388b [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
Sujithcee075a2009-03-13 09:07:23 +05302 * Copyright (c) 2008-2009 Atheros Communications Inc.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include <linux/io.h>
18#include <asm/unaligned.h>
19
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -070020#include "hw.h"
Luis R. Rodriguezcfe8cba2009-09-13 23:39:31 -070021#include "rc.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070022#include "initvals.h"
23
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080024#define ATH9K_CLOCK_RATE_CCK 22
25#define ATH9K_CLOCK_RATE_5GHZ_OFDM 40
26#define ATH9K_CLOCK_RATE_2GHZ_OFDM 44
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070027
Sujithcbe61d82009-02-09 13:27:12 +053028static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type);
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -070029static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan);
Sujithcbe61d82009-02-09 13:27:12 +053030static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +053031 struct ar5416_eeprom_def *pEepData,
Sujithf1dc5602008-10-29 10:16:30 +053032 u32 reg, u32 value);
Sujithcbe61d82009-02-09 13:27:12 +053033static void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan);
34static void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070035
Sujithf1dc5602008-10-29 10:16:30 +053036/********************/
37/* Helper Functions */
38/********************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070039
Sujithcbe61d82009-02-09 13:27:12 +053040static u32 ath9k_hw_mac_usec(struct ath_hw *ah, u32 clks)
Sujithf1dc5602008-10-29 10:16:30 +053041{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070042 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053043
Sujith2660b812009-02-09 13:27:26 +053044 if (!ah->curchan) /* should really check for CCK instead */
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080045 return clks / ATH9K_CLOCK_RATE_CCK;
46 if (conf->channel->band == IEEE80211_BAND_2GHZ)
47 return clks / ATH9K_CLOCK_RATE_2GHZ_OFDM;
Sujithcbe61d82009-02-09 13:27:12 +053048
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080049 return clks / ATH9K_CLOCK_RATE_5GHZ_OFDM;
Sujithf1dc5602008-10-29 10:16:30 +053050}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070051
Sujithcbe61d82009-02-09 13:27:12 +053052static u32 ath9k_hw_mac_to_usec(struct ath_hw *ah, u32 clks)
Sujithf1dc5602008-10-29 10:16:30 +053053{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070054 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053055
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080056 if (conf_is_ht40(conf))
Sujithf1dc5602008-10-29 10:16:30 +053057 return ath9k_hw_mac_usec(ah, clks) / 2;
58 else
59 return ath9k_hw_mac_usec(ah, clks);
60}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070061
Sujithcbe61d82009-02-09 13:27:12 +053062static u32 ath9k_hw_mac_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053063{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070064 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053065
Sujith2660b812009-02-09 13:27:26 +053066 if (!ah->curchan) /* should really check for CCK instead */
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080067 return usecs *ATH9K_CLOCK_RATE_CCK;
68 if (conf->channel->band == IEEE80211_BAND_2GHZ)
69 return usecs *ATH9K_CLOCK_RATE_2GHZ_OFDM;
70 return usecs *ATH9K_CLOCK_RATE_5GHZ_OFDM;
Sujithf1dc5602008-10-29 10:16:30 +053071}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070072
Sujithcbe61d82009-02-09 13:27:12 +053073static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053074{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070075 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053076
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080077 if (conf_is_ht40(conf))
Sujithf1dc5602008-10-29 10:16:30 +053078 return ath9k_hw_mac_clks(ah, usecs) * 2;
79 else
80 return ath9k_hw_mac_clks(ah, usecs);
81}
82
Sujith0caa7b12009-02-16 13:23:20 +053083bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070084{
85 int i;
86
Sujith0caa7b12009-02-16 13:23:20 +053087 BUG_ON(timeout < AH_TIME_QUANTUM);
88
89 for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070090 if ((REG_READ(ah, reg) & mask) == val)
91 return true;
92
93 udelay(AH_TIME_QUANTUM);
94 }
Sujith04bd4632008-11-28 22:18:05 +053095
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070096 ath_print(ath9k_hw_common(ah), ATH_DBG_ANY,
97 "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
98 timeout, reg, REG_READ(ah, reg), mask, val);
Sujithf1dc5602008-10-29 10:16:30 +053099
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700100 return false;
101}
102
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700103u32 ath9k_hw_reverse_bits(u32 val, u32 n)
104{
105 u32 retval;
106 int i;
107
108 for (i = 0, retval = 0; i < n; i++) {
109 retval = (retval << 1) | (val & 1);
110 val >>= 1;
111 }
112 return retval;
113}
114
Sujithcbe61d82009-02-09 13:27:12 +0530115bool ath9k_get_channel_edges(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530116 u16 flags, u16 *low,
117 u16 *high)
118{
Sujith2660b812009-02-09 13:27:26 +0530119 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530120
121 if (flags & CHANNEL_5GHZ) {
122 *low = pCap->low_5ghz_chan;
123 *high = pCap->high_5ghz_chan;
124 return true;
125 }
126 if ((flags & CHANNEL_2GHZ)) {
127 *low = pCap->low_2ghz_chan;
128 *high = pCap->high_2ghz_chan;
129 return true;
130 }
131 return false;
132}
133
Sujithcbe61d82009-02-09 13:27:12 +0530134u16 ath9k_hw_computetxtime(struct ath_hw *ah,
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400135 const struct ath_rate_table *rates,
Sujithf1dc5602008-10-29 10:16:30 +0530136 u32 frameLen, u16 rateix,
137 bool shortPreamble)
138{
139 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
140 u32 kbps;
141
Sujithe63835b2008-11-18 09:07:53 +0530142 kbps = rates->info[rateix].ratekbps;
Sujithf1dc5602008-10-29 10:16:30 +0530143
144 if (kbps == 0)
145 return 0;
146
147 switch (rates->info[rateix].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;
Sujithe63835b2008-11-18 09:07:53 +0530150 if (shortPreamble && rates->info[rateix].short_preamble)
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:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700180 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
181 "Unknown phy %u (rate ix %u)\n",
182 rates->info[rateix].phy, rateix);
Sujithf1dc5602008-10-29 10:16:30 +0530183 txTime = 0;
184 break;
185 }
186
187 return txTime;
188}
189
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
202 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
203 (chan->chanmode == CHANNEL_G_HT40PLUS)) {
204 centers->synth_center =
205 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
206 extoff = 1;
207 } else {
208 centers->synth_center =
209 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
210 extoff = -1;
211 }
212
213 centers->ctl_center =
214 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700215 /* 25 MHz spacing is supported by hw but not on upper layers */
Sujithf1dc5602008-10-29 10:16:30 +0530216 centers->ext_center =
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700217 centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT);
Sujithf1dc5602008-10-29 10:16:30 +0530218}
219
220/******************/
221/* Chip Revisions */
222/******************/
223
Sujithcbe61d82009-02-09 13:27:12 +0530224static void ath9k_hw_read_revisions(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530225{
226 u32 val;
227
228 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
229
230 if (val == 0xFF) {
231 val = REG_READ(ah, AR_SREV);
Sujithd535a422009-02-09 13:27:06 +0530232 ah->hw_version.macVersion =
233 (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
234 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
Sujith2660b812009-02-09 13:27:26 +0530235 ah->is_pciexpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
Sujithf1dc5602008-10-29 10:16:30 +0530236 } else {
237 if (!AR_SREV_9100(ah))
Sujithd535a422009-02-09 13:27:06 +0530238 ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
Sujithf1dc5602008-10-29 10:16:30 +0530239
Sujithd535a422009-02-09 13:27:06 +0530240 ah->hw_version.macRev = val & AR_SREV_REVISION;
Sujithf1dc5602008-10-29 10:16:30 +0530241
Sujithd535a422009-02-09 13:27:06 +0530242 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
Sujith2660b812009-02-09 13:27:26 +0530243 ah->is_pciexpress = true;
Sujithf1dc5602008-10-29 10:16:30 +0530244 }
245}
246
Sujithcbe61d82009-02-09 13:27:12 +0530247static int ath9k_hw_get_radiorev(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530248{
249 u32 val;
250 int i;
251
252 REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
253
254 for (i = 0; i < 8; i++)
255 REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
256 val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
257 val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
258
259 return ath9k_hw_reverse_bits(val, 8);
260}
261
262/************************************/
263/* HW Attach, Detach, Init Routines */
264/************************************/
265
Sujithcbe61d82009-02-09 13:27:12 +0530266static void ath9k_hw_disablepcie(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530267{
Sujithfeed0292009-01-29 11:37:35 +0530268 if (AR_SREV_9100(ah))
Sujithf1dc5602008-10-29 10:16:30 +0530269 return;
270
271 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
272 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
273 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
274 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
275 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
276 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
277 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
278 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
279 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
280
281 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
282}
283
Sujithcbe61d82009-02-09 13:27:12 +0530284static bool ath9k_hw_chip_test(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530285{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700286 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530287 u32 regAddr[2] = { AR_STA_ID0, AR_PHY_BASE + (8 << 2) };
288 u32 regHold[2];
289 u32 patternData[4] = { 0x55555555,
290 0xaaaaaaaa,
291 0x66666666,
292 0x99999999 };
293 int i, j;
294
295 for (i = 0; i < 2; i++) {
296 u32 addr = regAddr[i];
297 u32 wrData, rdData;
298
299 regHold[i] = REG_READ(ah, addr);
300 for (j = 0; j < 0x100; j++) {
301 wrData = (j << 16) | j;
302 REG_WRITE(ah, addr, wrData);
303 rdData = REG_READ(ah, addr);
304 if (rdData != wrData) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700305 ath_print(common, ATH_DBG_FATAL,
306 "address test failed "
307 "addr: 0x%08x - wr:0x%08x != "
308 "rd:0x%08x\n",
309 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530310 return false;
311 }
312 }
313 for (j = 0; j < 4; j++) {
314 wrData = patternData[j];
315 REG_WRITE(ah, addr, wrData);
316 rdData = REG_READ(ah, addr);
317 if (wrData != rdData) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700318 ath_print(common, ATH_DBG_FATAL,
319 "address test failed "
320 "addr: 0x%08x - wr:0x%08x != "
321 "rd:0x%08x\n",
322 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530323 return false;
324 }
325 }
326 REG_WRITE(ah, regAddr[i], regHold[i]);
327 }
328 udelay(100);
Sujithcbe61d82009-02-09 13:27:12 +0530329
Sujithf1dc5602008-10-29 10:16:30 +0530330 return true;
331}
332
333static const char *ath9k_hw_devname(u16 devid)
334{
335 switch (devid) {
336 case AR5416_DEVID_PCI:
Sujithf1dc5602008-10-29 10:16:30 +0530337 return "Atheros 5416";
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +0100338 case AR5416_DEVID_PCIE:
339 return "Atheros 5418";
Sujithf1dc5602008-10-29 10:16:30 +0530340 case AR9160_DEVID_PCI:
341 return "Atheros 9160";
Gabor Juhos0c1aa492009-01-14 20:17:12 +0100342 case AR5416_AR9100_DEVID:
343 return "Atheros 9100";
Sujithf1dc5602008-10-29 10:16:30 +0530344 case AR9280_DEVID_PCI:
345 case AR9280_DEVID_PCIE:
346 return "Atheros 9280";
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530347 case AR9285_DEVID_PCIE:
348 return "Atheros 9285";
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530349 case AR5416_DEVID_AR9287_PCI:
350 case AR5416_DEVID_AR9287_PCIE:
351 return "Atheros 9287";
Sujithf1dc5602008-10-29 10:16:30 +0530352 }
353
354 return NULL;
355}
356
Luis R. Rodriguezb8b0f372009-08-03 12:24:43 -0700357static void ath9k_hw_init_config(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700358{
359 int i;
360
Sujith2660b812009-02-09 13:27:26 +0530361 ah->config.dma_beacon_response_time = 2;
362 ah->config.sw_beacon_response_time = 10;
363 ah->config.additional_swba_backoff = 0;
364 ah->config.ack_6mb = 0x0;
365 ah->config.cwm_ignore_extcca = 0;
366 ah->config.pcie_powersave_enable = 0;
Sujith2660b812009-02-09 13:27:26 +0530367 ah->config.pcie_clock_req = 0;
Sujith2660b812009-02-09 13:27:26 +0530368 ah->config.pcie_waen = 0;
369 ah->config.analog_shiftreg = 1;
370 ah->config.ht_enable = 1;
371 ah->config.ofdm_trig_low = 200;
372 ah->config.ofdm_trig_high = 500;
373 ah->config.cck_trig_high = 200;
374 ah->config.cck_trig_low = 100;
375 ah->config.enable_ani = 1;
Sujith1cf68732009-08-13 09:34:32 +0530376 ah->config.diversity_control = ATH9K_ANT_VARIABLE;
Sujith2660b812009-02-09 13:27:26 +0530377 ah->config.antenna_switch_swap = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700378
379 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujith2660b812009-02-09 13:27:26 +0530380 ah->config.spurchans[i][0] = AR_NO_SPUR;
381 ah->config.spurchans[i][1] = AR_NO_SPUR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700382 }
383
Sujith0ef1f162009-03-30 15:28:35 +0530384 ah->config.intr_mitigation = true;
Luis R. Rodriguez61584252009-03-12 18:18:49 -0400385
386 /*
387 * We need this for PCI devices only (Cardbus, PCI, miniPCI)
388 * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
389 * This means we use it for all AR5416 devices, and the few
390 * minor PCI AR9280 devices out there.
391 *
392 * Serialization is required because these devices do not handle
393 * well the case of two concurrent reads/writes due to the latency
394 * involved. During one read/write another read/write can be issued
395 * on another CPU while the previous read/write may still be working
396 * on our hardware, if we hit this case the hardware poops in a loop.
397 * We prevent this by serializing reads and writes.
398 *
399 * This issue is not present on PCI-Express devices or pre-AR5416
400 * devices (legacy, 802.11abg).
401 */
402 if (num_possible_cpus() > 1)
David S. Miller2d6a5e92009-03-17 15:01:30 -0700403 ah->config.serialize_regmode = SER_REG_MODE_AUTO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700404}
405
Luis R. Rodriguez50aca252009-08-03 12:24:42 -0700406static void ath9k_hw_init_defaults(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700407{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700408 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
409
410 regulatory->country_code = CTRY_DEFAULT;
411 regulatory->power_limit = MAX_RATE_POWER;
412 regulatory->tp_scale = ATH9K_TP_SCALE_MAX;
413
Sujithd535a422009-02-09 13:27:06 +0530414 ah->hw_version.magic = AR5416_MAGIC;
Sujithd535a422009-02-09 13:27:06 +0530415 ah->hw_version.subvendorid = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700416
417 ah->ah_flags = 0;
Luis R. Rodriguez8df5d1b2009-08-03 12:24:37 -0700418 if (ah->hw_version.devid == AR5416_AR9100_DEVID)
Sujithd535a422009-02-09 13:27:06 +0530419 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700420 if (!AR_SREV_9100(ah))
421 ah->ah_flags = AH_USE_EEPROM;
422
Sujith2660b812009-02-09 13:27:26 +0530423 ah->atim_window = 0;
Sujith2660b812009-02-09 13:27:26 +0530424 ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
425 ah->beacon_interval = 100;
426 ah->enable_32kHz_clock = DONT_USE_32KHZ;
427 ah->slottime = (u32) -1;
428 ah->acktimeout = (u32) -1;
429 ah->ctstimeout = (u32) -1;
430 ah->globaltxtimeout = (u32) -1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700431
Sujith2660b812009-02-09 13:27:26 +0530432 ah->gbeacon_rate = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700433
Gabor Juhoscbdec972009-07-24 17:27:22 +0200434 ah->power_mode = ATH9K_PM_UNDEFINED;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700435}
436
Sujithcbe61d82009-02-09 13:27:12 +0530437static int ath9k_hw_rfattach(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700438{
439 bool rfStatus = false;
440 int ecode = 0;
441
442 rfStatus = ath9k_hw_init_rf(ah, &ecode);
443 if (!rfStatus) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700444 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
445 "RF setup failed, status: %u\n", ecode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700446 return ecode;
447 }
448
449 return 0;
450}
451
Sujithcbe61d82009-02-09 13:27:12 +0530452static int ath9k_hw_rf_claim(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700453{
454 u32 val;
455
456 REG_WRITE(ah, AR_PHY(0), 0x00000007);
457
458 val = ath9k_hw_get_radiorev(ah);
459 switch (val & AR_RADIO_SREV_MAJOR) {
460 case 0:
461 val = AR_RAD5133_SREV_MAJOR;
462 break;
463 case AR_RAD5133_SREV_MAJOR:
464 case AR_RAD5122_SREV_MAJOR:
465 case AR_RAD2133_SREV_MAJOR:
466 case AR_RAD2122_SREV_MAJOR:
467 break;
468 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700469 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
470 "Radio Chip Rev 0x%02X not supported\n",
471 val & AR_RADIO_SREV_MAJOR);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700472 return -EOPNOTSUPP;
473 }
474
Sujithd535a422009-02-09 13:27:06 +0530475 ah->hw_version.analog5GhzRev = val;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700476
477 return 0;
478}
479
Sujithcbe61d82009-02-09 13:27:12 +0530480static int ath9k_hw_init_macaddr(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700481{
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700482 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530483 u32 sum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700484 int i;
Sujithf1dc5602008-10-29 10:16:30 +0530485 u16 eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700486
Sujithf1dc5602008-10-29 10:16:30 +0530487 sum = 0;
488 for (i = 0; i < 3; i++) {
Sujithf74df6f2009-02-09 13:27:24 +0530489 eeval = ah->eep_ops->get_eeprom(ah, AR_EEPROM_MAC(i));
Sujithf1dc5602008-10-29 10:16:30 +0530490 sum += eeval;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700491 common->macaddr[2 * i] = eeval >> 8;
492 common->macaddr[2 * i + 1] = eeval & 0xff;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700493 }
Sujithd8baa932009-03-30 15:28:25 +0530494 if (sum == 0 || sum == 0xffff * 3)
Sujithf1dc5602008-10-29 10:16:30 +0530495 return -EADDRNOTAVAIL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700496
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700497 return 0;
498}
499
Sujithcbe61d82009-02-09 13:27:12 +0530500static void ath9k_hw_init_rxgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530501{
502 u32 rxgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530503
Sujithf74df6f2009-02-09 13:27:24 +0530504 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_17) {
505 rxgain_type = ah->eep_ops->get_eeprom(ah, EEP_RXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530506
507 if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530508 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530509 ar9280Modes_backoff_13db_rxgain_9280_2,
510 ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2), 6);
511 else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530512 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530513 ar9280Modes_backoff_23db_rxgain_9280_2,
514 ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 6);
515 else
Sujith2660b812009-02-09 13:27:26 +0530516 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530517 ar9280Modes_original_rxgain_9280_2,
518 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530519 } else {
Sujith2660b812009-02-09 13:27:26 +0530520 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530521 ar9280Modes_original_rxgain_9280_2,
522 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530523 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530524}
525
Sujithcbe61d82009-02-09 13:27:12 +0530526static void ath9k_hw_init_txgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530527{
528 u32 txgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530529
Sujithf74df6f2009-02-09 13:27:24 +0530530 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_19) {
531 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530532
533 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
Sujith2660b812009-02-09 13:27:26 +0530534 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530535 ar9280Modes_high_power_tx_gain_9280_2,
536 ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 6);
537 else
Sujith2660b812009-02-09 13:27:26 +0530538 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530539 ar9280Modes_original_tx_gain_9280_2,
540 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530541 } else {
Sujith2660b812009-02-09 13:27:26 +0530542 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530543 ar9280Modes_original_tx_gain_9280_2,
544 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530545 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530546}
547
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700548static int ath9k_hw_post_init(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700549{
550 int ecode;
551
Sujithd8baa932009-03-30 15:28:25 +0530552 if (!ath9k_hw_chip_test(ah))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700553 return -ENODEV;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700554
555 ecode = ath9k_hw_rf_claim(ah);
556 if (ecode != 0)
557 return ecode;
558
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700559 ecode = ath9k_hw_eeprom_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700560 if (ecode != 0)
561 return ecode;
Sujith7d01b222009-03-13 08:55:55 +0530562
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700563 ath_print(ath9k_hw_common(ah), ATH_DBG_CONFIG,
564 "Eeprom VER: %d, REV: %d\n",
565 ah->eep_ops->get_eeprom_ver(ah),
566 ah->eep_ops->get_eeprom_rev(ah));
Sujith7d01b222009-03-13 08:55:55 +0530567
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700568 ecode = ath9k_hw_rfattach(ah);
569 if (ecode != 0)
570 return ecode;
571
572 if (!AR_SREV_9100(ah)) {
573 ath9k_hw_ani_setup(ah);
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700574 ath9k_hw_ani_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700575 }
Sujithf1dc5602008-10-29 10:16:30 +0530576
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700577 return 0;
578}
579
Luis R. Rodriguezee2bb462009-08-03 12:24:39 -0700580static bool ath9k_hw_devid_supported(u16 devid)
581{
582 switch (devid) {
583 case AR5416_DEVID_PCI:
584 case AR5416_DEVID_PCIE:
585 case AR5416_AR9100_DEVID:
586 case AR9160_DEVID_PCI:
587 case AR9280_DEVID_PCI:
588 case AR9280_DEVID_PCIE:
589 case AR9285_DEVID_PCIE:
590 case AR5416_DEVID_AR9287_PCI:
591 case AR5416_DEVID_AR9287_PCIE:
592 return true;
593 default:
594 break;
595 }
596 return false;
597}
598
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700599static bool ath9k_hw_macversion_supported(u32 macversion)
600{
601 switch (macversion) {
602 case AR_SREV_VERSION_5416_PCI:
603 case AR_SREV_VERSION_5416_PCIE:
604 case AR_SREV_VERSION_9160:
605 case AR_SREV_VERSION_9100:
606 case AR_SREV_VERSION_9280:
607 case AR_SREV_VERSION_9285:
608 case AR_SREV_VERSION_9287:
609 return true;
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400610 /* Not yet */
611 case AR_SREV_VERSION_9271:
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700612 default:
613 break;
614 }
615 return false;
616}
617
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700618static void ath9k_hw_init_cal_settings(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700619{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700620 if (AR_SREV_9160_10_OR_LATER(ah)) {
621 if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530622 ah->iq_caldata.calData = &iq_cal_single_sample;
623 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700624 &adc_gain_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530625 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700626 &adc_dc_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530627 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700628 &adc_init_dc_cal;
629 } else {
Sujith2660b812009-02-09 13:27:26 +0530630 ah->iq_caldata.calData = &iq_cal_multi_sample;
631 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700632 &adc_gain_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530633 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700634 &adc_dc_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530635 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700636 &adc_init_dc_cal;
637 }
Sujith2660b812009-02-09 13:27:26 +0530638 ah->supp_cals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700639 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700640}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700641
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700642static void ath9k_hw_init_mode_regs(struct ath_hw *ah)
643{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400644 if (AR_SREV_9271(ah)) {
645 INIT_INI_ARRAY(&ah->iniModes, ar9271Modes_9271_1_0,
646 ARRAY_SIZE(ar9271Modes_9271_1_0), 6);
647 INIT_INI_ARRAY(&ah->iniCommon, ar9271Common_9271_1_0,
648 ARRAY_SIZE(ar9271Common_9271_1_0), 2);
649 return;
650 }
651
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530652 if (AR_SREV_9287_11_OR_LATER(ah)) {
653 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_1,
654 ARRAY_SIZE(ar9287Modes_9287_1_1), 6);
655 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_1,
656 ARRAY_SIZE(ar9287Common_9287_1_1), 2);
657 if (ah->config.pcie_clock_req)
658 INIT_INI_ARRAY(&ah->iniPcieSerdes,
659 ar9287PciePhy_clkreq_off_L1_9287_1_1,
660 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_1), 2);
661 else
662 INIT_INI_ARRAY(&ah->iniPcieSerdes,
663 ar9287PciePhy_clkreq_always_on_L1_9287_1_1,
664 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_1),
665 2);
666 } else if (AR_SREV_9287_10_OR_LATER(ah)) {
667 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_0,
668 ARRAY_SIZE(ar9287Modes_9287_1_0), 6);
669 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_0,
670 ARRAY_SIZE(ar9287Common_9287_1_0), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700671
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530672 if (ah->config.pcie_clock_req)
673 INIT_INI_ARRAY(&ah->iniPcieSerdes,
674 ar9287PciePhy_clkreq_off_L1_9287_1_0,
675 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_0), 2);
676 else
677 INIT_INI_ARRAY(&ah->iniPcieSerdes,
678 ar9287PciePhy_clkreq_always_on_L1_9287_1_0,
679 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_0),
680 2);
681 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
682
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530683
Sujith2660b812009-02-09 13:27:26 +0530684 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530685 ARRAY_SIZE(ar9285Modes_9285_1_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530686 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530687 ARRAY_SIZE(ar9285Common_9285_1_2), 2);
688
Sujith2660b812009-02-09 13:27:26 +0530689 if (ah->config.pcie_clock_req) {
690 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530691 ar9285PciePhy_clkreq_off_L1_9285_1_2,
692 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2);
693 } else {
Sujith2660b812009-02-09 13:27:26 +0530694 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530695 ar9285PciePhy_clkreq_always_on_L1_9285_1_2,
696 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2),
697 2);
698 }
699 } else if (AR_SREV_9285_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530700 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530701 ARRAY_SIZE(ar9285Modes_9285), 6);
Sujith2660b812009-02-09 13:27:26 +0530702 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530703 ARRAY_SIZE(ar9285Common_9285), 2);
704
Sujith2660b812009-02-09 13:27:26 +0530705 if (ah->config.pcie_clock_req) {
706 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530707 ar9285PciePhy_clkreq_off_L1_9285,
708 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2);
709 } else {
Sujith2660b812009-02-09 13:27:26 +0530710 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530711 ar9285PciePhy_clkreq_always_on_L1_9285,
712 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285), 2);
713 }
714 } else if (AR_SREV_9280_20_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530715 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700716 ARRAY_SIZE(ar9280Modes_9280_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530717 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700718 ARRAY_SIZE(ar9280Common_9280_2), 2);
719
Sujith2660b812009-02-09 13:27:26 +0530720 if (ah->config.pcie_clock_req) {
721 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530722 ar9280PciePhy_clkreq_off_L1_9280,
723 ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700724 } else {
Sujith2660b812009-02-09 13:27:26 +0530725 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530726 ar9280PciePhy_clkreq_always_on_L1_9280,
727 ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700728 }
Sujith2660b812009-02-09 13:27:26 +0530729 INIT_INI_ARRAY(&ah->iniModesAdditional,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700730 ar9280Modes_fast_clock_9280_2,
Sujithf1dc5602008-10-29 10:16:30 +0530731 ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700732 } else if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530733 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700734 ARRAY_SIZE(ar9280Modes_9280), 6);
Sujith2660b812009-02-09 13:27:26 +0530735 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700736 ARRAY_SIZE(ar9280Common_9280), 2);
737 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530738 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700739 ARRAY_SIZE(ar5416Modes_9160), 6);
Sujith2660b812009-02-09 13:27:26 +0530740 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700741 ARRAY_SIZE(ar5416Common_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530742 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700743 ARRAY_SIZE(ar5416Bank0_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530744 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700745 ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530746 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700747 ARRAY_SIZE(ar5416Bank1_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530748 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700749 ARRAY_SIZE(ar5416Bank2_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530750 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700751 ARRAY_SIZE(ar5416Bank3_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530752 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700753 ARRAY_SIZE(ar5416Bank6_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530754 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700755 ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530756 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700757 ARRAY_SIZE(ar5416Bank7_9160), 2);
758 if (AR_SREV_9160_11(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530759 INIT_INI_ARRAY(&ah->iniAddac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700760 ar5416Addac_91601_1,
761 ARRAY_SIZE(ar5416Addac_91601_1), 2);
762 } else {
Sujith2660b812009-02-09 13:27:26 +0530763 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700764 ARRAY_SIZE(ar5416Addac_9160), 2);
765 }
766 } else if (AR_SREV_9100_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530767 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700768 ARRAY_SIZE(ar5416Modes_9100), 6);
Sujith2660b812009-02-09 13:27:26 +0530769 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700770 ARRAY_SIZE(ar5416Common_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530771 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700772 ARRAY_SIZE(ar5416Bank0_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530773 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700774 ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530775 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700776 ARRAY_SIZE(ar5416Bank1_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530777 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700778 ARRAY_SIZE(ar5416Bank2_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530779 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700780 ARRAY_SIZE(ar5416Bank3_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530781 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700782 ARRAY_SIZE(ar5416Bank6_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530783 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700784 ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530785 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700786 ARRAY_SIZE(ar5416Bank7_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530787 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700788 ARRAY_SIZE(ar5416Addac_9100), 2);
789 } else {
Sujith2660b812009-02-09 13:27:26 +0530790 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700791 ARRAY_SIZE(ar5416Modes), 6);
Sujith2660b812009-02-09 13:27:26 +0530792 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700793 ARRAY_SIZE(ar5416Common), 2);
Sujith2660b812009-02-09 13:27:26 +0530794 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700795 ARRAY_SIZE(ar5416Bank0), 2);
Sujith2660b812009-02-09 13:27:26 +0530796 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700797 ARRAY_SIZE(ar5416BB_RfGain), 3);
Sujith2660b812009-02-09 13:27:26 +0530798 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700799 ARRAY_SIZE(ar5416Bank1), 2);
Sujith2660b812009-02-09 13:27:26 +0530800 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700801 ARRAY_SIZE(ar5416Bank2), 2);
Sujith2660b812009-02-09 13:27:26 +0530802 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700803 ARRAY_SIZE(ar5416Bank3), 3);
Sujith2660b812009-02-09 13:27:26 +0530804 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700805 ARRAY_SIZE(ar5416Bank6), 3);
Sujith2660b812009-02-09 13:27:26 +0530806 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700807 ARRAY_SIZE(ar5416Bank6TPC), 3);
Sujith2660b812009-02-09 13:27:26 +0530808 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700809 ARRAY_SIZE(ar5416Bank7), 2);
Sujith2660b812009-02-09 13:27:26 +0530810 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700811 ARRAY_SIZE(ar5416Addac), 2);
812 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700813}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700814
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700815static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
816{
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530817 if (AR_SREV_9287_11_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530818 INIT_INI_ARRAY(&ah->iniModesRxGain,
819 ar9287Modes_rx_gain_9287_1_1,
820 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_1), 6);
821 else if (AR_SREV_9287_10(ah))
822 INIT_INI_ARRAY(&ah->iniModesRxGain,
823 ar9287Modes_rx_gain_9287_1_0,
824 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_0), 6);
825 else if (AR_SREV_9280_20(ah))
826 ath9k_hw_init_rxgain_ini(ah);
827
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530828 if (AR_SREV_9287_11_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530829 INIT_INI_ARRAY(&ah->iniModesTxGain,
830 ar9287Modes_tx_gain_9287_1_1,
831 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_1), 6);
832 } else if (AR_SREV_9287_10(ah)) {
833 INIT_INI_ARRAY(&ah->iniModesTxGain,
834 ar9287Modes_tx_gain_9287_1_0,
835 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_0), 6);
836 } else if (AR_SREV_9280_20(ah)) {
837 ath9k_hw_init_txgain_ini(ah);
838 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530839 u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
840
841 /* txgain table */
842 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) {
843 INIT_INI_ARRAY(&ah->iniModesTxGain,
844 ar9285Modes_high_power_tx_gain_9285_1_2,
845 ARRAY_SIZE(ar9285Modes_high_power_tx_gain_9285_1_2), 6);
846 } else {
847 INIT_INI_ARRAY(&ah->iniModesTxGain,
848 ar9285Modes_original_tx_gain_9285_1_2,
849 ARRAY_SIZE(ar9285Modes_original_tx_gain_9285_1_2), 6);
850 }
851
852 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700853}
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530854
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700855static void ath9k_hw_init_11a_eeprom_fix(struct ath_hw *ah)
856{
857 u32 i, j;
Sujith06d0f062009-02-12 10:06:45 +0530858
859 if ((ah->hw_version.devid == AR9280_DEVID_PCI) &&
860 test_bit(ATH9K_MODE_11A, ah->caps.wireless_modes)) {
861
862 /* EEPROM Fixup */
Sujith2660b812009-02-09 13:27:26 +0530863 for (i = 0; i < ah->iniModes.ia_rows; i++) {
864 u32 reg = INI_RA(&ah->iniModes, i, 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700865
Sujith2660b812009-02-09 13:27:26 +0530866 for (j = 1; j < ah->iniModes.ia_columns; j++) {
867 u32 val = INI_RA(&ah->iniModes, i, j);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700868
Sujith2660b812009-02-09 13:27:26 +0530869 INI_RA(&ah->iniModes, i, j) =
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530870 ath9k_hw_ini_fixup(ah,
Sujith2660b812009-02-09 13:27:26 +0530871 &ah->eeprom.def,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700872 reg, val);
873 }
874 }
875 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700876}
877
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700878int ath9k_hw_init(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700879{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700880 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700881 int r = 0;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700882
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700883 if (!ath9k_hw_devid_supported(ah->hw_version.devid))
884 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700885
886 ath9k_hw_init_defaults(ah);
887 ath9k_hw_init_config(ah);
888
889 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700890 ath_print(common, ATH_DBG_FATAL,
891 "Couldn't reset chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700892 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700893 }
894
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700895 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700896 ath_print(common, ATH_DBG_FATAL, "Couldn't wakeup chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700897 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700898 }
899
900 if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
901 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
902 (AR_SREV_9280(ah) && !ah->is_pciexpress)) {
903 ah->config.serialize_regmode =
904 SER_REG_MODE_ON;
905 } else {
906 ah->config.serialize_regmode =
907 SER_REG_MODE_OFF;
908 }
909 }
910
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700911 ath_print(common, ATH_DBG_RESET, "serialize_regmode is %d\n",
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700912 ah->config.serialize_regmode);
913
914 if (!ath9k_hw_macversion_supported(ah->hw_version.macVersion)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700915 ath_print(common, ATH_DBG_FATAL,
916 "Mac Chip Rev 0x%02x.%x is not supported by "
917 "this driver\n", ah->hw_version.macVersion,
918 ah->hw_version.macRev);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700919 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700920 }
921
922 if (AR_SREV_9100(ah)) {
923 ah->iq_caldata.calData = &iq_cal_multi_sample;
924 ah->supp_cals = IQ_MISMATCH_CAL;
925 ah->is_pciexpress = false;
926 }
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400927
928 if (AR_SREV_9271(ah))
929 ah->is_pciexpress = false;
930
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700931 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
932
933 ath9k_hw_init_cal_settings(ah);
934
935 ah->ani_function = ATH9K_ANI_ALL;
936 if (AR_SREV_9280_10_OR_LATER(ah))
937 ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
938
939 ath9k_hw_init_mode_regs(ah);
940
941 if (ah->is_pciexpress)
Vivek Natarajan93b1b372009-09-17 09:24:58 +0530942 ath9k_hw_configpcipowersave(ah, 0, 0);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700943 else
944 ath9k_hw_disablepcie(ah);
945
Sujith193cd452009-09-18 15:04:07 +0530946 /* Support for Japan ch.14 (2484) spread */
947 if (AR_SREV_9287_11_OR_LATER(ah)) {
948 INIT_INI_ARRAY(&ah->iniCckfirNormal,
949 ar9287Common_normal_cck_fir_coeff_92871_1,
950 ARRAY_SIZE(ar9287Common_normal_cck_fir_coeff_92871_1), 2);
951 INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
952 ar9287Common_japan_2484_cck_fir_coeff_92871_1,
953 ARRAY_SIZE(ar9287Common_japan_2484_cck_fir_coeff_92871_1), 2);
954 }
955
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700956 r = ath9k_hw_post_init(ah);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700957 if (r)
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700958 return r;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700959
960 ath9k_hw_init_mode_gain_regs(ah);
961 ath9k_hw_fill_cap_info(ah);
962 ath9k_hw_init_11a_eeprom_fix(ah);
Sujithf6688cd2008-12-07 21:43:10 +0530963
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700964 r = ath9k_hw_init_macaddr(ah);
965 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700966 ath_print(common, ATH_DBG_FATAL,
967 "Failed to initialize MAC address\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700968 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700969 }
970
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400971 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
Sujith2660b812009-02-09 13:27:26 +0530972 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700973 else
Sujith2660b812009-02-09 13:27:26 +0530974 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700975
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700976 ath9k_init_nfcal_hist_buffer(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700977
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700978 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700979}
980
Sujithcbe61d82009-02-09 13:27:12 +0530981static void ath9k_hw_init_bb(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530982 struct ath9k_channel *chan)
983{
984 u32 synthDelay;
985
986 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +0530987 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +0530988 synthDelay = (4 * synthDelay) / 22;
989 else
990 synthDelay /= 10;
991
992 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
993
994 udelay(synthDelay + BASE_ACTIVATE_DELAY);
995}
996
Sujithcbe61d82009-02-09 13:27:12 +0530997static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530998{
999 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
1000 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
1001
1002 REG_WRITE(ah, AR_QOS_NO_ACK,
1003 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
1004 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
1005 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
1006
1007 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
1008 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
1009 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
1010 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
1011 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
1012}
1013
Sujithcbe61d82009-02-09 13:27:12 +05301014static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301015 struct ath9k_channel *chan)
1016{
1017 u32 pll;
1018
1019 if (AR_SREV_9100(ah)) {
1020 if (chan && IS_CHAN_5GHZ(chan))
1021 pll = 0x1450;
1022 else
1023 pll = 0x1458;
1024 } else {
1025 if (AR_SREV_9280_10_OR_LATER(ah)) {
1026 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
1027
1028 if (chan && IS_CHAN_HALF_RATE(chan))
1029 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
1030 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1031 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
1032
1033 if (chan && IS_CHAN_5GHZ(chan)) {
1034 pll |= SM(0x28, AR_RTC_9160_PLL_DIV);
1035
1036
1037 if (AR_SREV_9280_20(ah)) {
1038 if (((chan->channel % 20) == 0)
1039 || ((chan->channel % 10) == 0))
1040 pll = 0x2850;
1041 else
1042 pll = 0x142c;
1043 }
1044 } else {
1045 pll |= SM(0x2c, AR_RTC_9160_PLL_DIV);
1046 }
1047
1048 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1049
1050 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
1051
1052 if (chan && IS_CHAN_HALF_RATE(chan))
1053 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
1054 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1055 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
1056
1057 if (chan && IS_CHAN_5GHZ(chan))
1058 pll |= SM(0x50, AR_RTC_9160_PLL_DIV);
1059 else
1060 pll |= SM(0x58, AR_RTC_9160_PLL_DIV);
1061 } else {
1062 pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2;
1063
1064 if (chan && IS_CHAN_HALF_RATE(chan))
1065 pll |= SM(0x1, AR_RTC_PLL_CLKSEL);
1066 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1067 pll |= SM(0x2, AR_RTC_PLL_CLKSEL);
1068
1069 if (chan && IS_CHAN_5GHZ(chan))
1070 pll |= SM(0xa, AR_RTC_PLL_DIV);
1071 else
1072 pll |= SM(0xb, AR_RTC_PLL_DIV);
1073 }
1074 }
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001075 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +05301076
1077 udelay(RTC_PLL_SETTLE_DELAY);
1078
1079 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
1080}
1081
Sujithcbe61d82009-02-09 13:27:12 +05301082static void ath9k_hw_init_chain_masks(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301083{
Sujithf1dc5602008-10-29 10:16:30 +05301084 int rx_chainmask, tx_chainmask;
1085
Sujith2660b812009-02-09 13:27:26 +05301086 rx_chainmask = ah->rxchainmask;
1087 tx_chainmask = ah->txchainmask;
Sujithf1dc5602008-10-29 10:16:30 +05301088
1089 switch (rx_chainmask) {
1090 case 0x5:
1091 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1092 AR_PHY_SWAP_ALT_CHAIN);
1093 case 0x3:
Sujithd535a422009-02-09 13:27:06 +05301094 if (((ah)->hw_version.macVersion <= AR_SREV_VERSION_9160)) {
Sujithf1dc5602008-10-29 10:16:30 +05301095 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7);
1096 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7);
1097 break;
1098 }
1099 case 0x1:
1100 case 0x2:
Sujithf1dc5602008-10-29 10:16:30 +05301101 case 0x7:
1102 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
1103 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
1104 break;
1105 default:
1106 break;
1107 }
1108
1109 REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);
1110 if (tx_chainmask == 0x5) {
1111 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1112 AR_PHY_SWAP_ALT_CHAIN);
1113 }
1114 if (AR_SREV_9100(ah))
1115 REG_WRITE(ah, AR_PHY_ANALOG_SWAP,
1116 REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
1117}
1118
Sujithcbe61d82009-02-09 13:27:12 +05301119static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -08001120 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301121{
Sujith2660b812009-02-09 13:27:26 +05301122 ah->mask_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +05301123 AR_IMR_TXURN |
1124 AR_IMR_RXERR |
1125 AR_IMR_RXORN |
1126 AR_IMR_BCNMISC;
1127
Sujith0ef1f162009-03-30 15:28:35 +05301128 if (ah->config.intr_mitigation)
Sujith2660b812009-02-09 13:27:26 +05301129 ah->mask_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
Sujithf1dc5602008-10-29 10:16:30 +05301130 else
Sujith2660b812009-02-09 13:27:26 +05301131 ah->mask_reg |= AR_IMR_RXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301132
Sujith2660b812009-02-09 13:27:26 +05301133 ah->mask_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301134
Colin McCabed97809d2008-12-01 13:38:55 -08001135 if (opmode == NL80211_IFTYPE_AP)
Sujith2660b812009-02-09 13:27:26 +05301136 ah->mask_reg |= AR_IMR_MIB;
Sujithf1dc5602008-10-29 10:16:30 +05301137
Sujith2660b812009-02-09 13:27:26 +05301138 REG_WRITE(ah, AR_IMR, ah->mask_reg);
Sujithf1dc5602008-10-29 10:16:30 +05301139 REG_WRITE(ah, AR_IMR_S2, REG_READ(ah, AR_IMR_S2) | AR_IMR_S2_GTT);
1140
1141 if (!AR_SREV_9100(ah)) {
1142 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
1143 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
1144 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
1145 }
1146}
1147
Sujithcbe61d82009-02-09 13:27:12 +05301148static bool ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301149{
Sujithf1dc5602008-10-29 10:16:30 +05301150 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001151 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1152 "bad ack timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301153 ah->acktimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301154 return false;
1155 } else {
1156 REG_RMW_FIELD(ah, AR_TIME_OUT,
1157 AR_TIME_OUT_ACK, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301158 ah->acktimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301159 return true;
1160 }
1161}
1162
Sujithcbe61d82009-02-09 13:27:12 +05301163static bool ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301164{
Sujithf1dc5602008-10-29 10:16:30 +05301165 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_CTS))) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001166 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1167 "bad cts timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301168 ah->ctstimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301169 return false;
1170 } else {
1171 REG_RMW_FIELD(ah, AR_TIME_OUT,
1172 AR_TIME_OUT_CTS, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301173 ah->ctstimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301174 return true;
1175 }
1176}
1177
Sujithcbe61d82009-02-09 13:27:12 +05301178static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +05301179{
Sujithf1dc5602008-10-29 10:16:30 +05301180 if (tu > 0xFFFF) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001181 ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT,
1182 "bad global tx timeout %u\n", tu);
Sujith2660b812009-02-09 13:27:26 +05301183 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301184 return false;
1185 } else {
1186 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +05301187 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +05301188 return true;
1189 }
1190}
1191
Sujithcbe61d82009-02-09 13:27:12 +05301192static void ath9k_hw_init_user_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301193{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001194 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
1195 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +05301196
Sujith2660b812009-02-09 13:27:26 +05301197 if (ah->misc_mode != 0)
Sujithf1dc5602008-10-29 10:16:30 +05301198 REG_WRITE(ah, AR_PCU_MISC,
Sujith2660b812009-02-09 13:27:26 +05301199 REG_READ(ah, AR_PCU_MISC) | ah->misc_mode);
1200 if (ah->slottime != (u32) -1)
1201 ath9k_hw_setslottime(ah, ah->slottime);
1202 if (ah->acktimeout != (u32) -1)
1203 ath9k_hw_set_ack_timeout(ah, ah->acktimeout);
1204 if (ah->ctstimeout != (u32) -1)
1205 ath9k_hw_set_cts_timeout(ah, ah->ctstimeout);
1206 if (ah->globaltxtimeout != (u32) -1)
1207 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Sujithf1dc5602008-10-29 10:16:30 +05301208}
1209
1210const char *ath9k_hw_probe(u16 vendorid, u16 devid)
1211{
1212 return vendorid == ATHEROS_VENDOR_ID ?
1213 ath9k_hw_devname(devid) : NULL;
1214}
1215
Sujithcbe61d82009-02-09 13:27:12 +05301216void ath9k_hw_detach(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001217{
1218 if (!AR_SREV_9100(ah))
Luis R. Rodrigueze70c0cf2009-08-03 12:24:51 -07001219 ath9k_hw_ani_disable(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001220
Luis R. Rodriguez081b35a2009-08-03 12:24:50 -07001221 ath9k_hw_rf_free(ah);
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001222 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001223 kfree(ah);
Luis R. Rodriguez9db6b6a2009-08-03 12:24:52 -07001224 ah = NULL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001225}
1226
Sujithf1dc5602008-10-29 10:16:30 +05301227/*******/
1228/* INI */
1229/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001230
Sujithcbe61d82009-02-09 13:27:12 +05301231static void ath9k_hw_override_ini(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301232 struct ath9k_channel *chan)
1233{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001234 u32 val;
1235
1236 if (AR_SREV_9271(ah)) {
1237 /*
1238 * Enable spectral scan to solution for issues with stuck
1239 * beacons on AR9271 1.0. The beacon stuck issue is not seeon on
1240 * AR9271 1.1
1241 */
1242 if (AR_SREV_9271_10(ah)) {
1243 val = REG_READ(ah, AR_PHY_SPECTRAL_SCAN) | AR_PHY_SPECTRAL_SCAN_ENABLE;
1244 REG_WRITE(ah, AR_PHY_SPECTRAL_SCAN, val);
1245 }
1246 else if (AR_SREV_9271_11(ah))
1247 /*
1248 * change AR_PHY_RF_CTL3 setting to fix MAC issue
1249 * present on AR9271 1.1
1250 */
1251 REG_WRITE(ah, AR_PHY_RF_CTL3, 0x3a020001);
1252 return;
1253 }
1254
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +05301255 /*
1256 * Set the RX_ABORT and RX_DIS and clear if off only after
1257 * RXE is set for MAC. This prevents frames with corrupted
1258 * descriptor status.
1259 */
1260 REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
1261
Vasanthakumar Thiagarajan204d7942009-09-17 09:26:14 +05301262 if (AR_SREV_9280_10_OR_LATER(ah)) {
1263 val = REG_READ(ah, AR_PCU_MISC_MODE2) &
1264 (~AR_PCU_MISC_MODE2_HWWAR1);
1265
1266 if (AR_SREV_9287_10_OR_LATER(ah))
1267 val = val & (~AR_PCU_MISC_MODE2_HWWAR2);
1268
1269 REG_WRITE(ah, AR_PCU_MISC_MODE2, val);
1270 }
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +05301271
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001272 if (!AR_SREV_5416_20_OR_LATER(ah) ||
Sujithf1dc5602008-10-29 10:16:30 +05301273 AR_SREV_9280_10_OR_LATER(ah))
1274 return;
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001275 /*
1276 * Disable BB clock gating
1277 * Necessary to avoid issues on AR5416 2.0
1278 */
Sujithf1dc5602008-10-29 10:16:30 +05301279 REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
1280}
1281
Sujithcbe61d82009-02-09 13:27:12 +05301282static u32 ath9k_hw_def_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301283 struct ar5416_eeprom_def *pEepData,
Sujithf1dc5602008-10-29 10:16:30 +05301284 u32 reg, u32 value)
1285{
1286 struct base_eep_header *pBase = &(pEepData->baseEepHeader);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001287 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301288
Sujithd535a422009-02-09 13:27:06 +05301289 switch (ah->hw_version.devid) {
Sujithf1dc5602008-10-29 10:16:30 +05301290 case AR9280_DEVID_PCI:
1291 if (reg == 0x7894) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001292 ath_print(common, ATH_DBG_EEPROM,
Sujithf1dc5602008-10-29 10:16:30 +05301293 "ini VAL: %x EEPROM: %x\n", value,
1294 (pBase->version & 0xff));
1295
1296 if ((pBase->version & 0xff) > 0x0a) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001297 ath_print(common, ATH_DBG_EEPROM,
1298 "PWDCLKIND: %d\n",
1299 pBase->pwdclkind);
Sujithf1dc5602008-10-29 10:16:30 +05301300 value &= ~AR_AN_TOP2_PWDCLKIND;
1301 value |= AR_AN_TOP2_PWDCLKIND &
1302 (pBase->pwdclkind << AR_AN_TOP2_PWDCLKIND_S);
1303 } else {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001304 ath_print(common, ATH_DBG_EEPROM,
1305 "PWDCLKIND Earlier Rev\n");
Sujithf1dc5602008-10-29 10:16:30 +05301306 }
1307
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001308 ath_print(common, ATH_DBG_EEPROM,
1309 "final ini VAL: %x\n", value);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001310 }
Sujithf1dc5602008-10-29 10:16:30 +05301311 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001312 }
1313
Sujithf1dc5602008-10-29 10:16:30 +05301314 return value;
1315}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001316
Sujithcbe61d82009-02-09 13:27:12 +05301317static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301318 struct ar5416_eeprom_def *pEepData,
1319 u32 reg, u32 value)
1320{
Sujith2660b812009-02-09 13:27:26 +05301321 if (ah->eep_map == EEP_MAP_4KBITS)
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301322 return value;
1323 else
1324 return ath9k_hw_def_ini_fixup(ah, pEepData, reg, value);
1325}
1326
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301327static void ath9k_olc_init(struct ath_hw *ah)
1328{
1329 u32 i;
1330
Vivek Natarajandb91f2e2009-08-14 11:27:16 +05301331 if (OLC_FOR_AR9287_10_LATER) {
1332 REG_SET_BIT(ah, AR_PHY_TX_PWRCTRL9,
1333 AR_PHY_TX_PWRCTRL9_RES_DC_REMOVAL);
1334 ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TXPC0,
1335 AR9287_AN_TXPC0_TXPCMODE,
1336 AR9287_AN_TXPC0_TXPCMODE_S,
1337 AR9287_AN_TXPC0_TXPCMODE_TEMPSENSE);
1338 udelay(100);
1339 } else {
1340 for (i = 0; i < AR9280_TX_GAIN_TABLE_SIZE; i++)
1341 ah->originalGain[i] =
1342 MS(REG_READ(ah, AR_PHY_TX_GAIN_TBL1 + i * 4),
1343 AR_PHY_TX_GAIN);
1344 ah->PDADCdelta = 0;
1345 }
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301346}
1347
Bob Copeland3a702e42009-03-30 22:30:29 -04001348static u32 ath9k_regd_get_ctl(struct ath_regulatory *reg,
1349 struct ath9k_channel *chan)
1350{
1351 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
1352
1353 if (IS_CHAN_B(chan))
1354 ctl |= CTL_11B;
1355 else if (IS_CHAN_G(chan))
1356 ctl |= CTL_11G;
1357 else
1358 ctl |= CTL_11A;
1359
1360 return ctl;
1361}
1362
Sujithcbe61d82009-02-09 13:27:12 +05301363static int ath9k_hw_process_ini(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001364 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301365{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001366 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301367 int i, regWrites = 0;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001368 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301369 u32 modesIndex, freqIndex;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001370
Sujithf1dc5602008-10-29 10:16:30 +05301371 switch (chan->chanmode) {
1372 case CHANNEL_A:
1373 case CHANNEL_A_HT20:
1374 modesIndex = 1;
1375 freqIndex = 1;
1376 break;
1377 case CHANNEL_A_HT40PLUS:
1378 case CHANNEL_A_HT40MINUS:
1379 modesIndex = 2;
1380 freqIndex = 1;
1381 break;
1382 case CHANNEL_G:
1383 case CHANNEL_G_HT20:
1384 case CHANNEL_B:
1385 modesIndex = 4;
1386 freqIndex = 2;
1387 break;
1388 case CHANNEL_G_HT40PLUS:
1389 case CHANNEL_G_HT40MINUS:
1390 modesIndex = 3;
1391 freqIndex = 2;
1392 break;
1393
1394 default:
1395 return -EINVAL;
1396 }
1397
1398 REG_WRITE(ah, AR_PHY(0), 0x00000007);
Sujithf1dc5602008-10-29 10:16:30 +05301399 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
Sujithf74df6f2009-02-09 13:27:24 +05301400 ah->eep_ops->set_addac(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301401
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001402 if (AR_SREV_5416_22_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +05301403 REG_WRITE_ARRAY(&ah->iniAddac, 1, regWrites);
Sujithf1dc5602008-10-29 10:16:30 +05301404 } else {
1405 struct ar5416IniArray temp;
1406 u32 addacSize =
Sujith2660b812009-02-09 13:27:26 +05301407 sizeof(u32) * ah->iniAddac.ia_rows *
1408 ah->iniAddac.ia_columns;
Sujithf1dc5602008-10-29 10:16:30 +05301409
Sujith2660b812009-02-09 13:27:26 +05301410 memcpy(ah->addac5416_21,
1411 ah->iniAddac.ia_array, addacSize);
Sujithf1dc5602008-10-29 10:16:30 +05301412
Sujith2660b812009-02-09 13:27:26 +05301413 (ah->addac5416_21)[31 * ah->iniAddac.ia_columns + 1] = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301414
Sujith2660b812009-02-09 13:27:26 +05301415 temp.ia_array = ah->addac5416_21;
1416 temp.ia_columns = ah->iniAddac.ia_columns;
1417 temp.ia_rows = ah->iniAddac.ia_rows;
Sujithf1dc5602008-10-29 10:16:30 +05301418 REG_WRITE_ARRAY(&temp, 1, regWrites);
1419 }
1420
1421 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
1422
Sujith2660b812009-02-09 13:27:26 +05301423 for (i = 0; i < ah->iniModes.ia_rows; i++) {
1424 u32 reg = INI_RA(&ah->iniModes, i, 0);
1425 u32 val = INI_RA(&ah->iniModes, i, modesIndex);
Sujithf1dc5602008-10-29 10:16:30 +05301426
Sujithf1dc5602008-10-29 10:16:30 +05301427 REG_WRITE(ah, reg, val);
1428
1429 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301430 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301431 udelay(100);
1432 }
1433
1434 DO_DELAY(regWrites);
1435 }
1436
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301437 if (AR_SREV_9280(ah) || AR_SREV_9287_10_OR_LATER(ah))
Sujith2660b812009-02-09 13:27:26 +05301438 REG_WRITE_ARRAY(&ah->iniModesRxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301439
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301440 if (AR_SREV_9280(ah) || AR_SREV_9285_12_OR_LATER(ah) ||
1441 AR_SREV_9287_10_OR_LATER(ah))
Sujith2660b812009-02-09 13:27:26 +05301442 REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301443
Sujith2660b812009-02-09 13:27:26 +05301444 for (i = 0; i < ah->iniCommon.ia_rows; i++) {
1445 u32 reg = INI_RA(&ah->iniCommon, i, 0);
1446 u32 val = INI_RA(&ah->iniCommon, i, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301447
1448 REG_WRITE(ah, reg, val);
1449
1450 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301451 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301452 udelay(100);
1453 }
1454
1455 DO_DELAY(regWrites);
1456 }
1457
1458 ath9k_hw_write_regs(ah, modesIndex, freqIndex, regWrites);
1459
1460 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan)) {
Sujith2660b812009-02-09 13:27:26 +05301461 REG_WRITE_ARRAY(&ah->iniModesAdditional, modesIndex,
Sujithf1dc5602008-10-29 10:16:30 +05301462 regWrites);
1463 }
1464
1465 ath9k_hw_override_ini(ah, chan);
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001466 ath9k_hw_set_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301467 ath9k_hw_init_chain_masks(ah);
1468
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301469 if (OLC_FOR_AR9280_20_LATER)
1470 ath9k_olc_init(ah);
1471
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001472 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001473 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001474 channel->max_antenna_gain * 2,
1475 channel->max_power * 2,
1476 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001477 (u32) regulatory->power_limit));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001478
Sujithf1dc5602008-10-29 10:16:30 +05301479 if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001480 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1481 "ar5416SetRfRegs failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001482 return -EIO;
1483 }
1484
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001485 return 0;
1486}
1487
Sujithf1dc5602008-10-29 10:16:30 +05301488/****************************************/
1489/* Reset and Channel Switching Routines */
1490/****************************************/
1491
Sujithcbe61d82009-02-09 13:27:12 +05301492static void ath9k_hw_set_rfmode(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301493{
1494 u32 rfMode = 0;
1495
1496 if (chan == NULL)
1497 return;
1498
1499 rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
1500 ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
1501
1502 if (!AR_SREV_9280_10_OR_LATER(ah))
1503 rfMode |= (IS_CHAN_5GHZ(chan)) ?
1504 AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ;
1505
1506 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan))
1507 rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
1508
1509 REG_WRITE(ah, AR_PHY_MODE, rfMode);
1510}
1511
Sujithcbe61d82009-02-09 13:27:12 +05301512static void ath9k_hw_mark_phy_inactive(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301513{
1514 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
1515}
1516
Sujithcbe61d82009-02-09 13:27:12 +05301517static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301518{
1519 u32 regval;
1520
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001521 /*
1522 * set AHB_MODE not to do cacheline prefetches
1523 */
Sujithf1dc5602008-10-29 10:16:30 +05301524 regval = REG_READ(ah, AR_AHB_MODE);
1525 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
1526
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001527 /*
1528 * let mac dma reads be in 128 byte chunks
1529 */
Sujithf1dc5602008-10-29 10:16:30 +05301530 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
1531 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
1532
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001533 /*
1534 * Restore TX Trigger Level to its pre-reset value.
1535 * The initial value depends on whether aggregation is enabled, and is
1536 * adjusted whenever underruns are detected.
1537 */
Sujith2660b812009-02-09 13:27:26 +05301538 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +05301539
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001540 /*
1541 * let mac dma writes be in 128 byte chunks
1542 */
Sujithf1dc5602008-10-29 10:16:30 +05301543 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
1544 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
1545
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001546 /*
1547 * Setup receive FIFO threshold to hold off TX activities
1548 */
Sujithf1dc5602008-10-29 10:16:30 +05301549 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1550
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001551 /*
1552 * reduce the number of usable entries in PCU TXBUF to avoid
1553 * wrap around issues.
1554 */
Sujithf1dc5602008-10-29 10:16:30 +05301555 if (AR_SREV_9285(ah)) {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001556 /* For AR9285 the number of Fifos are reduced to half.
1557 * So set the usable tx buf size also to half to
1558 * avoid data/delimiter underruns
1559 */
Sujithf1dc5602008-10-29 10:16:30 +05301560 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1561 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001562 } else if (!AR_SREV_9271(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +05301563 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1564 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1565 }
1566}
1567
Sujithcbe61d82009-02-09 13:27:12 +05301568static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301569{
1570 u32 val;
1571
1572 val = REG_READ(ah, AR_STA_ID1);
1573 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
1574 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001575 case NL80211_IFTYPE_AP:
Sujithf1dc5602008-10-29 10:16:30 +05301576 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
1577 | AR_STA_ID1_KSRCH_MODE);
1578 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1579 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001580 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04001581 case NL80211_IFTYPE_MESH_POINT:
Sujithf1dc5602008-10-29 10:16:30 +05301582 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
1583 | AR_STA_ID1_KSRCH_MODE);
1584 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1585 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001586 case NL80211_IFTYPE_STATION:
1587 case NL80211_IFTYPE_MONITOR:
Sujithf1dc5602008-10-29 10:16:30 +05301588 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
1589 break;
1590 }
1591}
1592
Sujithcbe61d82009-02-09 13:27:12 +05301593static inline void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001594 u32 coef_scaled,
1595 u32 *coef_mantissa,
1596 u32 *coef_exponent)
1597{
1598 u32 coef_exp, coef_man;
1599
1600 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1601 if ((coef_scaled >> coef_exp) & 0x1)
1602 break;
1603
1604 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1605
1606 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1607
1608 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1609 *coef_exponent = coef_exp - 16;
1610}
1611
Sujithcbe61d82009-02-09 13:27:12 +05301612static void ath9k_hw_set_delta_slope(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301613 struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001614{
1615 u32 coef_scaled, ds_coef_exp, ds_coef_man;
1616 u32 clockMhzScaled = 0x64000000;
1617 struct chan_centers centers;
1618
1619 if (IS_CHAN_HALF_RATE(chan))
1620 clockMhzScaled = clockMhzScaled >> 1;
1621 else if (IS_CHAN_QUARTER_RATE(chan))
1622 clockMhzScaled = clockMhzScaled >> 2;
1623
1624 ath9k_hw_get_channel_centers(ah, chan, &centers);
1625 coef_scaled = clockMhzScaled / centers.synth_center;
1626
1627 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1628 &ds_coef_exp);
1629
1630 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1631 AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
1632 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1633 AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
1634
1635 coef_scaled = (9 * coef_scaled) / 10;
1636
1637 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1638 &ds_coef_exp);
1639
1640 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1641 AR_PHY_HALFGI_DSC_MAN, ds_coef_man);
1642 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1643 AR_PHY_HALFGI_DSC_EXP, ds_coef_exp);
1644}
1645
Sujithcbe61d82009-02-09 13:27:12 +05301646static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +05301647{
1648 u32 rst_flags;
1649 u32 tmpReg;
1650
Sujith70768492009-02-16 13:23:12 +05301651 if (AR_SREV_9100(ah)) {
1652 u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK);
1653 val &= ~AR_RTC_DERIVED_CLK_PERIOD;
1654 val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD);
1655 REG_WRITE(ah, AR_RTC_DERIVED_CLK, val);
1656 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1657 }
1658
Sujithf1dc5602008-10-29 10:16:30 +05301659 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1660 AR_RTC_FORCE_WAKE_ON_INT);
1661
1662 if (AR_SREV_9100(ah)) {
1663 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1664 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1665 } else {
1666 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1667 if (tmpReg &
1668 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1669 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
1670 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
1671 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1672 } else {
1673 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1674 }
1675
1676 rst_flags = AR_RTC_RC_MAC_WARM;
1677 if (type == ATH9K_RESET_COLD)
1678 rst_flags |= AR_RTC_RC_MAC_COLD;
1679 }
1680
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001681 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujithf1dc5602008-10-29 10:16:30 +05301682 udelay(50);
1683
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001684 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301685 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001686 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1687 "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301688 return false;
1689 }
1690
1691 if (!AR_SREV_9100(ah))
1692 REG_WRITE(ah, AR_RC, 0);
1693
1694 ath9k_hw_init_pll(ah, NULL);
1695
1696 if (AR_SREV_9100(ah))
1697 udelay(50);
1698
1699 return true;
1700}
1701
Sujithcbe61d82009-02-09 13:27:12 +05301702static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301703{
1704 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1705 AR_RTC_FORCE_WAKE_ON_INT);
1706
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301707 if (!AR_SREV_9100(ah))
1708 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1709
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001710 REG_WRITE(ah, AR_RTC_RESET, 0);
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301711 udelay(2);
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301712
1713 if (!AR_SREV_9100(ah))
1714 REG_WRITE(ah, AR_RC, 0);
1715
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001716 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301717
1718 if (!ath9k_hw_wait(ah,
1719 AR_RTC_STATUS,
1720 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301721 AR_RTC_STATUS_ON,
1722 AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001723 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1724 "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301725 return false;
1726 }
1727
1728 ath9k_hw_read_revisions(ah);
1729
1730 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1731}
1732
Sujithcbe61d82009-02-09 13:27:12 +05301733static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301734{
1735 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1736 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1737
1738 switch (type) {
1739 case ATH9K_RESET_POWER_ON:
1740 return ath9k_hw_set_reset_power_on(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301741 case ATH9K_RESET_WARM:
1742 case ATH9K_RESET_COLD:
1743 return ath9k_hw_set_reset(ah, type);
Sujithf1dc5602008-10-29 10:16:30 +05301744 default:
1745 return false;
1746 }
1747}
1748
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001749static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301750{
1751 u32 phymode;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301752 u32 enableDacFifo = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301753
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301754 if (AR_SREV_9285_10_OR_LATER(ah))
1755 enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) &
1756 AR_PHY_FC_ENABLE_DAC_FIFO);
1757
Sujithf1dc5602008-10-29 10:16:30 +05301758 phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301759 | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo;
Sujithf1dc5602008-10-29 10:16:30 +05301760
1761 if (IS_CHAN_HT40(chan)) {
1762 phymode |= AR_PHY_FC_DYN2040_EN;
1763
1764 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
1765 (chan->chanmode == CHANNEL_G_HT40PLUS))
1766 phymode |= AR_PHY_FC_DYN2040_PRI_CH;
1767
Sujithf1dc5602008-10-29 10:16:30 +05301768 }
1769 REG_WRITE(ah, AR_PHY_TURBO, phymode);
1770
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001771 ath9k_hw_set11nmac2040(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301772
1773 REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
1774 REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
1775}
1776
Sujithcbe61d82009-02-09 13:27:12 +05301777static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301778 struct ath9k_channel *chan)
1779{
Vivek Natarajan42abfbe2009-09-17 09:27:59 +05301780 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) {
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301781 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
1782 return false;
1783 } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
Sujithf1dc5602008-10-29 10:16:30 +05301784 return false;
1785
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001786 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05301787 return false;
1788
Sujith2660b812009-02-09 13:27:26 +05301789 ah->chip_fullsleep = false;
Sujithf1dc5602008-10-29 10:16:30 +05301790 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301791 ath9k_hw_set_rfmode(ah, chan);
1792
1793 return true;
1794}
1795
Sujithcbe61d82009-02-09 13:27:12 +05301796static bool ath9k_hw_channel_change(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001797 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301798{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001799 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001800 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001801 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301802 u32 synthDelay, qnum;
1803
1804 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1805 if (ath9k_hw_numtxpending(ah, qnum)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001806 ath_print(common, ATH_DBG_QUEUE,
1807 "Transmit frames pending on "
1808 "queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301809 return false;
1810 }
1811 }
1812
1813 REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
1814 if (!ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
Sujith0caa7b12009-02-16 13:23:20 +05301815 AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001816 ath_print(common, ATH_DBG_FATAL,
1817 "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301818 return false;
1819 }
1820
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001821 ath9k_hw_set_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301822
1823 if (AR_SREV_9280_10_OR_LATER(ah)) {
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001824 ath9k_hw_ar9280_set_channel(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301825 } else {
1826 if (!(ath9k_hw_set_channel(ah, chan))) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001827 ath_print(common, ATH_DBG_FATAL,
1828 "Failed to set channel\n");
Sujithf1dc5602008-10-29 10:16:30 +05301829 return false;
1830 }
1831 }
1832
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001833 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001834 ath9k_regd_get_ctl(regulatory, chan),
Sujithf74df6f2009-02-09 13:27:24 +05301835 channel->max_antenna_gain * 2,
1836 channel->max_power * 2,
1837 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001838 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05301839
1840 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +05301841 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +05301842 synthDelay = (4 * synthDelay) / 22;
1843 else
1844 synthDelay /= 10;
1845
1846 udelay(synthDelay + BASE_ACTIVATE_DELAY);
1847
1848 REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
1849
1850 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1851 ath9k_hw_set_delta_slope(ah, chan);
1852
1853 if (AR_SREV_9280_10_OR_LATER(ah))
1854 ath9k_hw_9280_spur_mitigate(ah, chan);
1855 else
1856 ath9k_hw_spur_mitigate(ah, chan);
1857
1858 if (!chan->oneTimeCalsDone)
1859 chan->oneTimeCalsDone = true;
1860
1861 return true;
1862}
1863
Sujithcbe61d82009-02-09 13:27:12 +05301864static void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001865{
1866 int bb_spur = AR_NO_SPUR;
1867 int freq;
1868 int bin, cur_bin;
1869 int bb_spur_off, spur_subchannel_sd;
1870 int spur_freq_sd;
1871 int spur_delta_phase;
1872 int denominator;
1873 int upper, lower, cur_vit_mask;
1874 int tmp, newVal;
1875 int i;
1876 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
1877 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
1878 };
1879 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
1880 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
1881 };
1882 int inc[4] = { 0, 100, 0, 0 };
1883 struct chan_centers centers;
1884
1885 int8_t mask_m[123];
1886 int8_t mask_p[123];
1887 int8_t mask_amt;
1888 int tmp_mask;
1889 int cur_bb_spur;
1890 bool is2GHz = IS_CHAN_2GHZ(chan);
1891
1892 memset(&mask_m, 0, sizeof(int8_t) * 123);
1893 memset(&mask_p, 0, sizeof(int8_t) * 123);
1894
1895 ath9k_hw_get_channel_centers(ah, chan, &centers);
1896 freq = centers.synth_center;
1897
Sujith2660b812009-02-09 13:27:26 +05301898 ah->config.spurmode = SPUR_ENABLE_EEPROM;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001899 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujithf74df6f2009-02-09 13:27:24 +05301900 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001901
1902 if (is2GHz)
1903 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_2GHZ;
1904 else
1905 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_5GHZ;
1906
1907 if (AR_NO_SPUR == cur_bb_spur)
1908 break;
1909 cur_bb_spur = cur_bb_spur - freq;
1910
1911 if (IS_CHAN_HT40(chan)) {
1912 if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT40) &&
1913 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT40)) {
1914 bb_spur = cur_bb_spur;
1915 break;
1916 }
1917 } else if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT20) &&
1918 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT20)) {
1919 bb_spur = cur_bb_spur;
1920 break;
1921 }
1922 }
1923
1924 if (AR_NO_SPUR == bb_spur) {
1925 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1926 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1927 return;
1928 } else {
1929 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1930 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1931 }
1932
1933 bin = bb_spur * 320;
1934
1935 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
1936
1937 newVal = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
1938 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
1939 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
1940 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
1941 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), newVal);
1942
1943 newVal = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
1944 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
1945 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
1946 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
1947 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
1948 REG_WRITE(ah, AR_PHY_SPUR_REG, newVal);
1949
1950 if (IS_CHAN_HT40(chan)) {
1951 if (bb_spur < 0) {
1952 spur_subchannel_sd = 1;
1953 bb_spur_off = bb_spur + 10;
1954 } else {
1955 spur_subchannel_sd = 0;
1956 bb_spur_off = bb_spur - 10;
1957 }
1958 } else {
1959 spur_subchannel_sd = 0;
1960 bb_spur_off = bb_spur;
1961 }
1962
1963 if (IS_CHAN_HT40(chan))
1964 spur_delta_phase =
1965 ((bb_spur * 262144) /
1966 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
1967 else
1968 spur_delta_phase =
1969 ((bb_spur * 524288) /
1970 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
1971
1972 denominator = IS_CHAN_2GHZ(chan) ? 44 : 40;
1973 spur_freq_sd = ((bb_spur_off * 2048) / denominator) & 0x3ff;
1974
1975 newVal = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
1976 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
1977 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
1978 REG_WRITE(ah, AR_PHY_TIMING11, newVal);
1979
1980 newVal = spur_subchannel_sd << AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S;
1981 REG_WRITE(ah, AR_PHY_SFCORR_EXT, newVal);
1982
1983 cur_bin = -6000;
1984 upper = bin + 100;
1985 lower = bin - 100;
1986
1987 for (i = 0; i < 4; i++) {
1988 int pilot_mask = 0;
1989 int chan_mask = 0;
1990 int bp = 0;
1991 for (bp = 0; bp < 30; bp++) {
1992 if ((cur_bin > lower) && (cur_bin < upper)) {
1993 pilot_mask = pilot_mask | 0x1 << bp;
1994 chan_mask = chan_mask | 0x1 << bp;
1995 }
1996 cur_bin += 100;
1997 }
1998 cur_bin += inc[i];
1999 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
2000 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
2001 }
2002
2003 cur_vit_mask = 6100;
2004 upper = bin + 120;
2005 lower = bin - 120;
2006
2007 for (i = 0; i < 123; i++) {
2008 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
Adrian Bunkb08cbcd2008-08-05 22:06:51 +03002009
2010 /* workaround for gcc bug #37014 */
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002011 volatile int tmp_v = abs(cur_vit_mask - bin);
Adrian Bunkb08cbcd2008-08-05 22:06:51 +03002012
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002013 if (tmp_v < 75)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002014 mask_amt = 1;
2015 else
2016 mask_amt = 0;
2017 if (cur_vit_mask < 0)
2018 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
2019 else
2020 mask_p[cur_vit_mask / 100] = mask_amt;
2021 }
2022 cur_vit_mask -= 100;
2023 }
2024
2025 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
2026 | (mask_m[48] << 26) | (mask_m[49] << 24)
2027 | (mask_m[50] << 22) | (mask_m[51] << 20)
2028 | (mask_m[52] << 18) | (mask_m[53] << 16)
2029 | (mask_m[54] << 14) | (mask_m[55] << 12)
2030 | (mask_m[56] << 10) | (mask_m[57] << 8)
2031 | (mask_m[58] << 6) | (mask_m[59] << 4)
2032 | (mask_m[60] << 2) | (mask_m[61] << 0);
2033 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
2034 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
2035
2036 tmp_mask = (mask_m[31] << 28)
2037 | (mask_m[32] << 26) | (mask_m[33] << 24)
2038 | (mask_m[34] << 22) | (mask_m[35] << 20)
2039 | (mask_m[36] << 18) | (mask_m[37] << 16)
2040 | (mask_m[48] << 14) | (mask_m[39] << 12)
2041 | (mask_m[40] << 10) | (mask_m[41] << 8)
2042 | (mask_m[42] << 6) | (mask_m[43] << 4)
2043 | (mask_m[44] << 2) | (mask_m[45] << 0);
2044 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
2045 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
2046
2047 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
2048 | (mask_m[18] << 26) | (mask_m[18] << 24)
2049 | (mask_m[20] << 22) | (mask_m[20] << 20)
2050 | (mask_m[22] << 18) | (mask_m[22] << 16)
2051 | (mask_m[24] << 14) | (mask_m[24] << 12)
2052 | (mask_m[25] << 10) | (mask_m[26] << 8)
2053 | (mask_m[27] << 6) | (mask_m[28] << 4)
2054 | (mask_m[29] << 2) | (mask_m[30] << 0);
2055 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
2056 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
2057
2058 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
2059 | (mask_m[2] << 26) | (mask_m[3] << 24)
2060 | (mask_m[4] << 22) | (mask_m[5] << 20)
2061 | (mask_m[6] << 18) | (mask_m[7] << 16)
2062 | (mask_m[8] << 14) | (mask_m[9] << 12)
2063 | (mask_m[10] << 10) | (mask_m[11] << 8)
2064 | (mask_m[12] << 6) | (mask_m[13] << 4)
2065 | (mask_m[14] << 2) | (mask_m[15] << 0);
2066 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
2067 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
2068
2069 tmp_mask = (mask_p[15] << 28)
2070 | (mask_p[14] << 26) | (mask_p[13] << 24)
2071 | (mask_p[12] << 22) | (mask_p[11] << 20)
2072 | (mask_p[10] << 18) | (mask_p[9] << 16)
2073 | (mask_p[8] << 14) | (mask_p[7] << 12)
2074 | (mask_p[6] << 10) | (mask_p[5] << 8)
2075 | (mask_p[4] << 6) | (mask_p[3] << 4)
2076 | (mask_p[2] << 2) | (mask_p[1] << 0);
2077 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
2078 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
2079
2080 tmp_mask = (mask_p[30] << 28)
2081 | (mask_p[29] << 26) | (mask_p[28] << 24)
2082 | (mask_p[27] << 22) | (mask_p[26] << 20)
2083 | (mask_p[25] << 18) | (mask_p[24] << 16)
2084 | (mask_p[23] << 14) | (mask_p[22] << 12)
2085 | (mask_p[21] << 10) | (mask_p[20] << 8)
2086 | (mask_p[19] << 6) | (mask_p[18] << 4)
2087 | (mask_p[17] << 2) | (mask_p[16] << 0);
2088 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
2089 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
2090
2091 tmp_mask = (mask_p[45] << 28)
2092 | (mask_p[44] << 26) | (mask_p[43] << 24)
2093 | (mask_p[42] << 22) | (mask_p[41] << 20)
2094 | (mask_p[40] << 18) | (mask_p[39] << 16)
2095 | (mask_p[38] << 14) | (mask_p[37] << 12)
2096 | (mask_p[36] << 10) | (mask_p[35] << 8)
2097 | (mask_p[34] << 6) | (mask_p[33] << 4)
2098 | (mask_p[32] << 2) | (mask_p[31] << 0);
2099 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
2100 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
2101
2102 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
2103 | (mask_p[59] << 26) | (mask_p[58] << 24)
2104 | (mask_p[57] << 22) | (mask_p[56] << 20)
2105 | (mask_p[55] << 18) | (mask_p[54] << 16)
2106 | (mask_p[53] << 14) | (mask_p[52] << 12)
2107 | (mask_p[51] << 10) | (mask_p[50] << 8)
2108 | (mask_p[49] << 6) | (mask_p[48] << 4)
2109 | (mask_p[47] << 2) | (mask_p[46] << 0);
2110 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
2111 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
2112}
2113
Sujithcbe61d82009-02-09 13:27:12 +05302114static void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002115{
2116 int bb_spur = AR_NO_SPUR;
2117 int bin, cur_bin;
2118 int spur_freq_sd;
2119 int spur_delta_phase;
2120 int denominator;
2121 int upper, lower, cur_vit_mask;
2122 int tmp, new;
2123 int i;
2124 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
2125 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
2126 };
2127 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
2128 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
2129 };
2130 int inc[4] = { 0, 100, 0, 0 };
2131
2132 int8_t mask_m[123];
2133 int8_t mask_p[123];
2134 int8_t mask_amt;
2135 int tmp_mask;
2136 int cur_bb_spur;
2137 bool is2GHz = IS_CHAN_2GHZ(chan);
2138
2139 memset(&mask_m, 0, sizeof(int8_t) * 123);
2140 memset(&mask_p, 0, sizeof(int8_t) * 123);
2141
2142 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujithf74df6f2009-02-09 13:27:24 +05302143 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002144 if (AR_NO_SPUR == cur_bb_spur)
2145 break;
2146 cur_bb_spur = cur_bb_spur - (chan->channel * 10);
2147 if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) {
2148 bb_spur = cur_bb_spur;
2149 break;
2150 }
2151 }
2152
2153 if (AR_NO_SPUR == bb_spur)
2154 return;
2155
2156 bin = bb_spur * 32;
2157
2158 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
2159 new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
2160 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
2161 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
2162 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
2163
2164 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new);
2165
2166 new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
2167 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
2168 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
2169 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
2170 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
2171 REG_WRITE(ah, AR_PHY_SPUR_REG, new);
2172
2173 spur_delta_phase = ((bb_spur * 524288) / 100) &
2174 AR_PHY_TIMING11_SPUR_DELTA_PHASE;
2175
2176 denominator = IS_CHAN_2GHZ(chan) ? 440 : 400;
2177 spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff;
2178
2179 new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
2180 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
2181 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
2182 REG_WRITE(ah, AR_PHY_TIMING11, new);
2183
2184 cur_bin = -6000;
2185 upper = bin + 100;
2186 lower = bin - 100;
2187
2188 for (i = 0; i < 4; i++) {
2189 int pilot_mask = 0;
2190 int chan_mask = 0;
2191 int bp = 0;
2192 for (bp = 0; bp < 30; bp++) {
2193 if ((cur_bin > lower) && (cur_bin < upper)) {
2194 pilot_mask = pilot_mask | 0x1 << bp;
2195 chan_mask = chan_mask | 0x1 << bp;
2196 }
2197 cur_bin += 100;
2198 }
2199 cur_bin += inc[i];
2200 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
2201 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
2202 }
2203
2204 cur_vit_mask = 6100;
2205 upper = bin + 120;
2206 lower = bin - 120;
2207
2208 for (i = 0; i < 123; i++) {
2209 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
Adrian Bunk88b9e2b2008-08-05 22:06:51 +03002210
2211 /* workaround for gcc bug #37014 */
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002212 volatile int tmp_v = abs(cur_vit_mask - bin);
Adrian Bunk88b9e2b2008-08-05 22:06:51 +03002213
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002214 if (tmp_v < 75)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002215 mask_amt = 1;
2216 else
2217 mask_amt = 0;
2218 if (cur_vit_mask < 0)
2219 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
2220 else
2221 mask_p[cur_vit_mask / 100] = mask_amt;
2222 }
2223 cur_vit_mask -= 100;
2224 }
2225
2226 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
2227 | (mask_m[48] << 26) | (mask_m[49] << 24)
2228 | (mask_m[50] << 22) | (mask_m[51] << 20)
2229 | (mask_m[52] << 18) | (mask_m[53] << 16)
2230 | (mask_m[54] << 14) | (mask_m[55] << 12)
2231 | (mask_m[56] << 10) | (mask_m[57] << 8)
2232 | (mask_m[58] << 6) | (mask_m[59] << 4)
2233 | (mask_m[60] << 2) | (mask_m[61] << 0);
2234 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
2235 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
2236
2237 tmp_mask = (mask_m[31] << 28)
2238 | (mask_m[32] << 26) | (mask_m[33] << 24)
2239 | (mask_m[34] << 22) | (mask_m[35] << 20)
2240 | (mask_m[36] << 18) | (mask_m[37] << 16)
2241 | (mask_m[48] << 14) | (mask_m[39] << 12)
2242 | (mask_m[40] << 10) | (mask_m[41] << 8)
2243 | (mask_m[42] << 6) | (mask_m[43] << 4)
2244 | (mask_m[44] << 2) | (mask_m[45] << 0);
2245 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
2246 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
2247
2248 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
2249 | (mask_m[18] << 26) | (mask_m[18] << 24)
2250 | (mask_m[20] << 22) | (mask_m[20] << 20)
2251 | (mask_m[22] << 18) | (mask_m[22] << 16)
2252 | (mask_m[24] << 14) | (mask_m[24] << 12)
2253 | (mask_m[25] << 10) | (mask_m[26] << 8)
2254 | (mask_m[27] << 6) | (mask_m[28] << 4)
2255 | (mask_m[29] << 2) | (mask_m[30] << 0);
2256 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
2257 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
2258
2259 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
2260 | (mask_m[2] << 26) | (mask_m[3] << 24)
2261 | (mask_m[4] << 22) | (mask_m[5] << 20)
2262 | (mask_m[6] << 18) | (mask_m[7] << 16)
2263 | (mask_m[8] << 14) | (mask_m[9] << 12)
2264 | (mask_m[10] << 10) | (mask_m[11] << 8)
2265 | (mask_m[12] << 6) | (mask_m[13] << 4)
2266 | (mask_m[14] << 2) | (mask_m[15] << 0);
2267 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
2268 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
2269
2270 tmp_mask = (mask_p[15] << 28)
2271 | (mask_p[14] << 26) | (mask_p[13] << 24)
2272 | (mask_p[12] << 22) | (mask_p[11] << 20)
2273 | (mask_p[10] << 18) | (mask_p[9] << 16)
2274 | (mask_p[8] << 14) | (mask_p[7] << 12)
2275 | (mask_p[6] << 10) | (mask_p[5] << 8)
2276 | (mask_p[4] << 6) | (mask_p[3] << 4)
2277 | (mask_p[2] << 2) | (mask_p[1] << 0);
2278 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
2279 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
2280
2281 tmp_mask = (mask_p[30] << 28)
2282 | (mask_p[29] << 26) | (mask_p[28] << 24)
2283 | (mask_p[27] << 22) | (mask_p[26] << 20)
2284 | (mask_p[25] << 18) | (mask_p[24] << 16)
2285 | (mask_p[23] << 14) | (mask_p[22] << 12)
2286 | (mask_p[21] << 10) | (mask_p[20] << 8)
2287 | (mask_p[19] << 6) | (mask_p[18] << 4)
2288 | (mask_p[17] << 2) | (mask_p[16] << 0);
2289 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
2290 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
2291
2292 tmp_mask = (mask_p[45] << 28)
2293 | (mask_p[44] << 26) | (mask_p[43] << 24)
2294 | (mask_p[42] << 22) | (mask_p[41] << 20)
2295 | (mask_p[40] << 18) | (mask_p[39] << 16)
2296 | (mask_p[38] << 14) | (mask_p[37] << 12)
2297 | (mask_p[36] << 10) | (mask_p[35] << 8)
2298 | (mask_p[34] << 6) | (mask_p[33] << 4)
2299 | (mask_p[32] << 2) | (mask_p[31] << 0);
2300 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
2301 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
2302
2303 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
2304 | (mask_p[59] << 26) | (mask_p[58] << 24)
2305 | (mask_p[57] << 22) | (mask_p[56] << 20)
2306 | (mask_p[55] << 18) | (mask_p[54] << 16)
2307 | (mask_p[53] << 14) | (mask_p[52] << 12)
2308 | (mask_p[51] << 10) | (mask_p[50] << 8)
2309 | (mask_p[49] << 6) | (mask_p[48] << 4)
2310 | (mask_p[47] << 2) | (mask_p[46] << 0);
2311 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
2312 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
2313}
2314
Johannes Berg3b319aa2009-06-13 14:50:26 +05302315static void ath9k_enable_rfkill(struct ath_hw *ah)
2316{
2317 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
2318 AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
2319
2320 REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2,
2321 AR_GPIO_INPUT_MUX2_RFSILENT);
2322
2323 ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
2324 REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);
2325}
2326
Sujithcbe61d82009-02-09 13:27:12 +05302327int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002328 bool bChannelChange)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002329{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002330 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002331 u32 saveLedState;
Sujith2660b812009-02-09 13:27:26 +05302332 struct ath9k_channel *curchan = ah->curchan;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002333 u32 saveDefAntenna;
2334 u32 macStaId1;
Sujith46fe7822009-09-17 09:25:25 +05302335 u64 tsf = 0;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002336 int i, rx_chainmask, r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002337
Luis R. Rodriguez43c27612009-09-13 21:07:07 -07002338 ah->txchainmask = common->tx_chainmask;
2339 ah->rxchainmask = common->rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002340
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002341 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002342 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002343
Vasanthakumar Thiagarajan9ebef792009-09-17 09:26:44 +05302344 if (curchan && !ah->chip_fullsleep)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002345 ath9k_hw_getnf(ah, curchan);
2346
2347 if (bChannelChange &&
Sujith2660b812009-02-09 13:27:26 +05302348 (ah->chip_fullsleep != true) &&
2349 (ah->curchan != NULL) &&
2350 (chan->channel != ah->curchan->channel) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002351 ((chan->channelFlags & CHANNEL_ALL) ==
Sujith2660b812009-02-09 13:27:26 +05302352 (ah->curchan->channelFlags & CHANNEL_ALL)) &&
Vasanthakumar Thiagarajan0a475cc2009-09-17 09:27:10 +05302353 !(AR_SREV_9280(ah) || IS_CHAN_A_5MHZ_SPACED(chan) ||
2354 IS_CHAN_A_5MHZ_SPACED(ah->curchan))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002355
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002356 if (ath9k_hw_channel_change(ah, chan)) {
Sujith2660b812009-02-09 13:27:26 +05302357 ath9k_hw_loadnf(ah, ah->curchan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002358 ath9k_hw_start_nfcal(ah);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002359 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002360 }
2361 }
2362
2363 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
2364 if (saveDefAntenna == 0)
2365 saveDefAntenna = 1;
2366
2367 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
2368
Sujith46fe7822009-09-17 09:25:25 +05302369 /* For chips on which RTC reset is done, save TSF before it gets cleared */
2370 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
2371 tsf = ath9k_hw_gettsf64(ah);
2372
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002373 saveLedState = REG_READ(ah, AR_CFG_LED) &
2374 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
2375 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
2376
2377 ath9k_hw_mark_phy_inactive(ah);
2378
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002379 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
2380 REG_WRITE(ah,
2381 AR9271_RESET_POWER_DOWN_CONTROL,
2382 AR9271_RADIO_RF_RST);
2383 udelay(50);
2384 }
2385
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002386 if (!ath9k_hw_chip_reset(ah, chan)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002387 ath_print(common, ATH_DBG_FATAL, "Chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002388 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002389 }
2390
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002391 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
2392 ah->htc_reset_init = false;
2393 REG_WRITE(ah,
2394 AR9271_RESET_POWER_DOWN_CONTROL,
2395 AR9271_GATE_MAC_CTL);
2396 udelay(50);
2397 }
2398
Sujith46fe7822009-09-17 09:25:25 +05302399 /* Restore TSF */
2400 if (tsf && AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
2401 ath9k_hw_settsf64(ah, tsf);
2402
Vasanthakumar Thiagarajan369391d2009-01-21 19:24:13 +05302403 if (AR_SREV_9280_10_OR_LATER(ah))
2404 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002405
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302406 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302407 /* Enable ASYNC FIFO */
2408 REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2409 AR_MAC_PCU_ASYNC_FIFO_REG3_DATAPATH_SEL);
2410 REG_SET_BIT(ah, AR_PHY_MODE, AR_PHY_MODE_ASYNCFIFO);
2411 REG_CLR_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2412 AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
2413 REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2414 AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
2415 }
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002416 r = ath9k_hw_process_ini(ah, chan);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002417 if (r)
2418 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002419
Jouni Malinen0ced0e12009-01-08 13:32:13 +02002420 /* Setup MFP options for CCMP */
2421 if (AR_SREV_9280_20_OR_LATER(ah)) {
2422 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
2423 * frames when constructing CCMP AAD. */
2424 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
2425 0xc7ff);
2426 ah->sw_mgmt_crypto = false;
2427 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
2428 /* Disable hardware crypto for management frames */
2429 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
2430 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
2431 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
2432 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
2433 ah->sw_mgmt_crypto = true;
2434 } else
2435 ah->sw_mgmt_crypto = true;
2436
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002437 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
2438 ath9k_hw_set_delta_slope(ah, chan);
2439
2440 if (AR_SREV_9280_10_OR_LATER(ah))
2441 ath9k_hw_9280_spur_mitigate(ah, chan);
2442 else
2443 ath9k_hw_spur_mitigate(ah, chan);
2444
Sujithd6509152009-03-13 08:56:05 +05302445 ah->eep_ops->set_board_values(ah, chan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002446
2447 ath9k_hw_decrease_chain_power(ah, chan);
2448
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002449 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
2450 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002451 | macStaId1
2452 | AR_STA_ID1_RTS_USE_DEF
Sujith2660b812009-02-09 13:27:26 +05302453 | (ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302454 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Sujith2660b812009-02-09 13:27:26 +05302455 | ah->sta_id1_defaults);
2456 ath9k_hw_set_operating_mode(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002457
Luis R. Rodriguez13b81552009-09-10 17:52:45 -07002458 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002459
2460 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
2461
Luis R. Rodriguez3453ad82009-09-10 08:57:00 -07002462 ath9k_hw_write_associd(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002463
2464 REG_WRITE(ah, AR_ISR, ~0);
2465
2466 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
2467
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07002468 if (AR_SREV_9280_10_OR_LATER(ah))
2469 ath9k_hw_ar9280_set_channel(ah, chan);
2470 else
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002471 if (!(ath9k_hw_set_channel(ah, chan)))
2472 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002473
2474 for (i = 0; i < AR_NUM_DCU; i++)
2475 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
2476
Sujith2660b812009-02-09 13:27:26 +05302477 ah->intr_txqs = 0;
2478 for (i = 0; i < ah->caps.total_queues; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002479 ath9k_hw_resettxqueue(ah, i);
2480
Sujith2660b812009-02-09 13:27:26 +05302481 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002482 ath9k_hw_init_qos(ah);
2483
Sujith2660b812009-02-09 13:27:26 +05302484 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05302485 ath9k_enable_rfkill(ah);
Johannes Berg3b319aa2009-06-13 14:50:26 +05302486
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002487 ath9k_hw_init_user_settings(ah);
2488
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302489 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302490 REG_WRITE(ah, AR_D_GBL_IFS_SIFS,
2491 AR_D_GBL_IFS_SIFS_ASYNC_FIFO_DUR);
2492 REG_WRITE(ah, AR_D_GBL_IFS_SLOT,
2493 AR_D_GBL_IFS_SLOT_ASYNC_FIFO_DUR);
2494 REG_WRITE(ah, AR_D_GBL_IFS_EIFS,
2495 AR_D_GBL_IFS_EIFS_ASYNC_FIFO_DUR);
2496
2497 REG_WRITE(ah, AR_TIME_OUT, AR_TIME_OUT_ACK_CTS_ASYNC_FIFO_DUR);
2498 REG_WRITE(ah, AR_USEC, AR_USEC_ASYNC_FIFO_DUR);
2499
2500 REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
2501 AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
2502 REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
2503 AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
2504 }
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302505 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302506 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
2507 AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
2508 }
2509
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002510 REG_WRITE(ah, AR_STA_ID1,
2511 REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
2512
2513 ath9k_hw_set_dma(ah);
2514
2515 REG_WRITE(ah, AR_OBS, 8);
2516
Sujith0ef1f162009-03-30 15:28:35 +05302517 if (ah->config.intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002518 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
2519 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
2520 }
2521
2522 ath9k_hw_init_bb(ah, chan);
2523
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002524 if (!ath9k_hw_init_cal(ah, chan))
Joe Perches6badaaf2009-06-28 09:26:32 -07002525 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002526
Sujith2660b812009-02-09 13:27:26 +05302527 rx_chainmask = ah->rxchainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002528 if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) {
2529 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
2530 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
2531 }
2532
2533 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
2534
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002535 /*
2536 * For big endian systems turn on swapping for descriptors
2537 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002538 if (AR_SREV_9100(ah)) {
2539 u32 mask;
2540 mask = REG_READ(ah, AR_CFG);
2541 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002542 ath_print(common, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05302543 "CFG Byte Swap Set 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002544 } else {
2545 mask =
2546 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
2547 REG_WRITE(ah, AR_CFG, mask);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002548 ath_print(common, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05302549 "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002550 }
2551 } else {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002552 /* Configure AR9271 target WLAN */
2553 if (AR_SREV_9271(ah))
2554 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002555#ifdef __BIG_ENDIAN
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002556 else
2557 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002558#endif
2559 }
2560
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002561 if (ah->btcoex_hw.enabled)
Vasanthakumar Thiagarajan42cc41e2009-08-26 21:08:45 +05302562 ath9k_hw_btcoex_enable(ah);
2563
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002564 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002565}
2566
Sujithf1dc5602008-10-29 10:16:30 +05302567/************************/
2568/* Key Cache Management */
2569/************************/
2570
Sujithcbe61d82009-02-09 13:27:12 +05302571bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002572{
Sujithf1dc5602008-10-29 10:16:30 +05302573 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002574
Sujith2660b812009-02-09 13:27:26 +05302575 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002576 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2577 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002578 return false;
2579 }
2580
Sujithf1dc5602008-10-29 10:16:30 +05302581 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002582
Sujithf1dc5602008-10-29 10:16:30 +05302583 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
2584 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
2585 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
2586 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
2587 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
2588 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
2589 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
2590 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
2591
2592 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2593 u16 micentry = entry + 64;
2594
2595 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
2596 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
2597 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
2598 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
2599
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002600 }
2601
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002602 return true;
2603}
2604
Sujithcbe61d82009-02-09 13:27:12 +05302605bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002606{
Sujithf1dc5602008-10-29 10:16:30 +05302607 u32 macHi, macLo;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002608
Sujith2660b812009-02-09 13:27:26 +05302609 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002610 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2611 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002612 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002613 }
2614
Sujithf1dc5602008-10-29 10:16:30 +05302615 if (mac != NULL) {
2616 macHi = (mac[5] << 8) | mac[4];
2617 macLo = (mac[3] << 24) |
2618 (mac[2] << 16) |
2619 (mac[1] << 8) |
2620 mac[0];
2621 macLo >>= 1;
2622 macLo |= (macHi & 1) << 31;
2623 macHi >>= 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002624 } else {
Sujithf1dc5602008-10-29 10:16:30 +05302625 macLo = macHi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002626 }
Sujithf1dc5602008-10-29 10:16:30 +05302627 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
2628 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002629
2630 return true;
2631}
2632
Sujithcbe61d82009-02-09 13:27:12 +05302633bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
Sujithf1dc5602008-10-29 10:16:30 +05302634 const struct ath9k_keyval *k,
Jouni Malinene0caf9e2009-03-02 18:15:53 +02002635 const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002636{
Sujith2660b812009-02-09 13:27:26 +05302637 const struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002638 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302639 u32 key0, key1, key2, key3, key4;
2640 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002641
Sujithf1dc5602008-10-29 10:16:30 +05302642 if (entry >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002643 ath_print(common, ATH_DBG_FATAL,
2644 "keycache entry %u out of range\n", entry);
Sujithf1dc5602008-10-29 10:16:30 +05302645 return false;
2646 }
2647
2648 switch (k->kv_type) {
2649 case ATH9K_CIPHER_AES_OCB:
2650 keyType = AR_KEYTABLE_TYPE_AES;
2651 break;
2652 case ATH9K_CIPHER_AES_CCM:
2653 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002654 ath_print(common, ATH_DBG_ANY,
2655 "AES-CCM not supported by mac rev 0x%x\n",
2656 ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002657 return false;
2658 }
Sujithf1dc5602008-10-29 10:16:30 +05302659 keyType = AR_KEYTABLE_TYPE_CCM;
2660 break;
2661 case ATH9K_CIPHER_TKIP:
2662 keyType = AR_KEYTABLE_TYPE_TKIP;
2663 if (ATH9K_IS_MIC_ENABLED(ah)
2664 && entry + 64 >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002665 ath_print(common, ATH_DBG_ANY,
2666 "entry %u inappropriate for TKIP\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002667 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002668 }
Sujithf1dc5602008-10-29 10:16:30 +05302669 break;
2670 case ATH9K_CIPHER_WEP:
Zhu Yie31a16d2009-05-21 21:47:03 +08002671 if (k->kv_len < WLAN_KEY_LEN_WEP40) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002672 ath_print(common, ATH_DBG_ANY,
2673 "WEP key length %u too small\n", k->kv_len);
Sujithf1dc5602008-10-29 10:16:30 +05302674 return false;
2675 }
Zhu Yie31a16d2009-05-21 21:47:03 +08002676 if (k->kv_len <= WLAN_KEY_LEN_WEP40)
Sujithf1dc5602008-10-29 10:16:30 +05302677 keyType = AR_KEYTABLE_TYPE_40;
Zhu Yie31a16d2009-05-21 21:47:03 +08002678 else if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05302679 keyType = AR_KEYTABLE_TYPE_104;
2680 else
2681 keyType = AR_KEYTABLE_TYPE_128;
2682 break;
2683 case ATH9K_CIPHER_CLR:
2684 keyType = AR_KEYTABLE_TYPE_CLR;
2685 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002686 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002687 ath_print(common, ATH_DBG_FATAL,
2688 "cipher %u not supported\n", k->kv_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002689 return false;
2690 }
Sujithf1dc5602008-10-29 10:16:30 +05302691
Jouni Malinene0caf9e2009-03-02 18:15:53 +02002692 key0 = get_unaligned_le32(k->kv_val + 0);
2693 key1 = get_unaligned_le16(k->kv_val + 4);
2694 key2 = get_unaligned_le32(k->kv_val + 6);
2695 key3 = get_unaligned_le16(k->kv_val + 10);
2696 key4 = get_unaligned_le32(k->kv_val + 12);
Zhu Yie31a16d2009-05-21 21:47:03 +08002697 if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05302698 key4 &= 0xff;
2699
Jouni Malinen672903b2009-03-02 15:06:31 +02002700 /*
2701 * Note: Key cache registers access special memory area that requires
2702 * two 32-bit writes to actually update the values in the internal
2703 * memory. Consequently, the exact order and pairs used here must be
2704 * maintained.
2705 */
2706
Sujithf1dc5602008-10-29 10:16:30 +05302707 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2708 u16 micentry = entry + 64;
2709
Jouni Malinen672903b2009-03-02 15:06:31 +02002710 /*
2711 * Write inverted key[47:0] first to avoid Michael MIC errors
2712 * on frames that could be sent or received at the same time.
2713 * The correct key will be written in the end once everything
2714 * else is ready.
2715 */
Sujithf1dc5602008-10-29 10:16:30 +05302716 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
2717 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002718
2719 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302720 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2721 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002722
2723 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302724 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2725 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
Jouni Malinen672903b2009-03-02 15:06:31 +02002726
2727 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302728 (void) ath9k_hw_keysetmac(ah, entry, mac);
2729
Sujith2660b812009-02-09 13:27:26 +05302730 if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) {
Jouni Malinen672903b2009-03-02 15:06:31 +02002731 /*
2732 * TKIP uses two key cache entries:
2733 * Michael MIC TX/RX keys in the same key cache entry
2734 * (idx = main index + 64):
2735 * key0 [31:0] = RX key [31:0]
2736 * key1 [15:0] = TX key [31:16]
2737 * key1 [31:16] = reserved
2738 * key2 [31:0] = RX key [63:32]
2739 * key3 [15:0] = TX key [15:0]
2740 * key3 [31:16] = reserved
2741 * key4 [31:0] = TX key [63:32]
2742 */
Sujithf1dc5602008-10-29 10:16:30 +05302743 u32 mic0, mic1, mic2, mic3, mic4;
2744
2745 mic0 = get_unaligned_le32(k->kv_mic + 0);
2746 mic2 = get_unaligned_le32(k->kv_mic + 4);
2747 mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
2748 mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
2749 mic4 = get_unaligned_le32(k->kv_txmic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02002750
2751 /* Write RX[31:0] and TX[31:16] */
Sujithf1dc5602008-10-29 10:16:30 +05302752 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2753 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002754
2755 /* Write RX[63:32] and TX[15:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302756 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2757 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002758
2759 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302760 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
2761 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2762 AR_KEYTABLE_TYPE_CLR);
2763
2764 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002765 /*
2766 * TKIP uses four key cache entries (two for group
2767 * keys):
2768 * Michael MIC TX/RX keys are in different key cache
2769 * entries (idx = main index + 64 for TX and
2770 * main index + 32 + 96 for RX):
2771 * key0 [31:0] = TX/RX MIC key [31:0]
2772 * key1 [31:0] = reserved
2773 * key2 [31:0] = TX/RX MIC key [63:32]
2774 * key3 [31:0] = reserved
2775 * key4 [31:0] = reserved
2776 *
2777 * Upper layer code will call this function separately
2778 * for TX and RX keys when these registers offsets are
2779 * used.
2780 */
Sujithf1dc5602008-10-29 10:16:30 +05302781 u32 mic0, mic2;
2782
2783 mic0 = get_unaligned_le32(k->kv_mic + 0);
2784 mic2 = get_unaligned_le32(k->kv_mic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02002785
2786 /* Write MIC key[31:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302787 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2788 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002789
2790 /* Write MIC key[63:32] */
Sujithf1dc5602008-10-29 10:16:30 +05302791 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2792 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002793
2794 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302795 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
2796 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2797 AR_KEYTABLE_TYPE_CLR);
2798 }
Jouni Malinen672903b2009-03-02 15:06:31 +02002799
2800 /* MAC address registers are reserved for the MIC entry */
Sujithf1dc5602008-10-29 10:16:30 +05302801 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
2802 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002803
2804 /*
2805 * Write the correct (un-inverted) key[47:0] last to enable
2806 * TKIP now that all other registers are set with correct
2807 * values.
2808 */
Sujithf1dc5602008-10-29 10:16:30 +05302809 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2810 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
2811 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002812 /* Write key[47:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302813 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2814 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002815
2816 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302817 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2818 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002819
2820 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302821 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2822 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
2823
Jouni Malinen672903b2009-03-02 15:06:31 +02002824 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302825 (void) ath9k_hw_keysetmac(ah, entry, mac);
2826 }
2827
Sujithf1dc5602008-10-29 10:16:30 +05302828 return true;
2829}
2830
Sujithcbe61d82009-02-09 13:27:12 +05302831bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry)
Sujithf1dc5602008-10-29 10:16:30 +05302832{
Sujith2660b812009-02-09 13:27:26 +05302833 if (entry < ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05302834 u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
2835 if (val & AR_KEYTABLE_VALID)
2836 return true;
2837 }
2838 return false;
2839}
2840
2841/******************************/
2842/* Power Management (Chipset) */
2843/******************************/
2844
Sujithcbe61d82009-02-09 13:27:12 +05302845static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302846{
2847 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2848 if (setChip) {
2849 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2850 AR_RTC_FORCE_WAKE_EN);
2851 if (!AR_SREV_9100(ah))
2852 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
2853
Sujith4921be82009-09-18 15:04:27 +05302854 if(!AR_SREV_5416(ah))
2855 REG_CLR_BIT(ah, (AR_RTC_RESET),
2856 AR_RTC_RESET_EN);
Sujithf1dc5602008-10-29 10:16:30 +05302857 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002858}
2859
Sujithcbe61d82009-02-09 13:27:12 +05302860static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002861{
Sujithf1dc5602008-10-29 10:16:30 +05302862 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2863 if (setChip) {
Sujith2660b812009-02-09 13:27:26 +05302864 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002865
Sujithf1dc5602008-10-29 10:16:30 +05302866 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
2867 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2868 AR_RTC_FORCE_WAKE_ON_INT);
2869 } else {
2870 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2871 AR_RTC_FORCE_WAKE_EN);
2872 }
2873 }
2874}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002875
Sujithcbe61d82009-02-09 13:27:12 +05302876static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302877{
2878 u32 val;
2879 int i;
2880
2881 if (setChip) {
2882 if ((REG_READ(ah, AR_RTC_STATUS) &
2883 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2884 if (ath9k_hw_set_reset_reg(ah,
2885 ATH9K_RESET_POWER_ON) != true) {
2886 return false;
2887 }
2888 }
2889 if (AR_SREV_9100(ah))
2890 REG_SET_BIT(ah, AR_RTC_RESET,
2891 AR_RTC_RESET_EN);
2892
2893 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2894 AR_RTC_FORCE_WAKE_EN);
2895 udelay(50);
2896
2897 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2898 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2899 if (val == AR_RTC_STATUS_ON)
2900 break;
2901 udelay(50);
2902 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2903 AR_RTC_FORCE_WAKE_EN);
2904 }
2905 if (i == 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002906 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2907 "Failed to wakeup in %uus\n",
2908 POWER_UP_TIME / 20);
Sujithf1dc5602008-10-29 10:16:30 +05302909 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002910 }
2911 }
2912
Sujithf1dc5602008-10-29 10:16:30 +05302913 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2914
2915 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002916}
2917
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002918bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05302919{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002920 struct ath_common *common = ath9k_hw_common(ah);
Sujithcbe61d82009-02-09 13:27:12 +05302921 int status = true, setChip = true;
Sujithf1dc5602008-10-29 10:16:30 +05302922 static const char *modes[] = {
2923 "AWAKE",
2924 "FULL-SLEEP",
2925 "NETWORK SLEEP",
2926 "UNDEFINED"
2927 };
Sujithf1dc5602008-10-29 10:16:30 +05302928
Gabor Juhoscbdec972009-07-24 17:27:22 +02002929 if (ah->power_mode == mode)
2930 return status;
2931
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002932 ath_print(common, ATH_DBG_RESET, "%s -> %s\n",
2933 modes[ah->power_mode], modes[mode]);
Sujithf1dc5602008-10-29 10:16:30 +05302934
2935 switch (mode) {
2936 case ATH9K_PM_AWAKE:
2937 status = ath9k_hw_set_power_awake(ah, setChip);
2938 break;
2939 case ATH9K_PM_FULL_SLEEP:
2940 ath9k_set_power_sleep(ah, setChip);
Sujith2660b812009-02-09 13:27:26 +05302941 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05302942 break;
2943 case ATH9K_PM_NETWORK_SLEEP:
2944 ath9k_set_power_network_sleep(ah, setChip);
2945 break;
2946 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002947 ath_print(common, ATH_DBG_FATAL,
2948 "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05302949 return false;
2950 }
Sujith2660b812009-02-09 13:27:26 +05302951 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05302952
2953 return status;
2954}
2955
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002956/*
2957 * Helper for ASPM support.
2958 *
2959 * Disable PLL when in L0s as well as receiver clock when in L1.
2960 * This power saving option must be enabled through the SerDes.
2961 *
2962 * Programming the SerDes must go through the same 288 bit serial shift
2963 * register as the other analog registers. Hence the 9 writes.
2964 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302965void ath9k_hw_configpcipowersave(struct ath_hw *ah, int restore, int power_off)
Sujithf1dc5602008-10-29 10:16:30 +05302966{
Sujithf1dc5602008-10-29 10:16:30 +05302967 u8 i;
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302968 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05302969
Sujith2660b812009-02-09 13:27:26 +05302970 if (ah->is_pciexpress != true)
Sujithf1dc5602008-10-29 10:16:30 +05302971 return;
2972
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002973 /* Do not touch SerDes registers */
Sujith2660b812009-02-09 13:27:26 +05302974 if (ah->config.pcie_powersave_enable == 2)
Sujithf1dc5602008-10-29 10:16:30 +05302975 return;
2976
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002977 /* Nothing to do on restore for 11N */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302978 if (!restore) {
2979 if (AR_SREV_9280_20_OR_LATER(ah)) {
2980 /*
2981 * AR9280 2.0 or later chips use SerDes values from the
2982 * initvals.h initialized depending on chipset during
2983 * ath9k_hw_init()
2984 */
2985 for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
2986 REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
2987 INI_RA(&ah->iniPcieSerdes, i, 1));
2988 }
2989 } else if (AR_SREV_9280(ah) &&
2990 (ah->hw_version.macRev == AR_SREV_REVISION_9280_10)) {
2991 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
2992 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
Sujithf1dc5602008-10-29 10:16:30 +05302993
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302994 /* RX shut off when elecidle is asserted */
2995 REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
2996 REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
2997 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
2998
2999 /* Shut off CLKREQ active in L1 */
3000 if (ah->config.pcie_clock_req)
3001 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
3002 else
3003 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
3004
3005 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
3006 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
3007 REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
3008
3009 /* Load the new settings */
3010 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
3011
3012 } else {
3013 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
3014 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
3015
3016 /* RX shut off when elecidle is asserted */
3017 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
3018 REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
3019 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
3020
3021 /*
3022 * Ignore ah->ah_config.pcie_clock_req setting for
3023 * pre-AR9280 11n
3024 */
3025 REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
3026
3027 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
3028 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
3029 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
3030
3031 /* Load the new settings */
3032 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
Sujithf1dc5602008-10-29 10:16:30 +05303033 }
Sujithf1dc5602008-10-29 10:16:30 +05303034
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303035 udelay(1000);
Sujithf1dc5602008-10-29 10:16:30 +05303036
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303037 /* set bit 19 to allow forcing of pcie core into L1 state */
3038 REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
Sujithf1dc5602008-10-29 10:16:30 +05303039
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303040 /* Several PCIe massages to ensure proper behaviour */
3041 if (ah->config.pcie_waen) {
3042 val = ah->config.pcie_waen;
3043 if (!power_off)
3044 val &= (~AR_WA_D3_L1_DISABLE);
3045 } else {
3046 if (AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
3047 AR_SREV_9287(ah)) {
3048 val = AR9285_WA_DEFAULT;
3049 if (!power_off)
3050 val &= (~AR_WA_D3_L1_DISABLE);
3051 } else if (AR_SREV_9280(ah)) {
3052 /*
3053 * On AR9280 chips bit 22 of 0x4004 needs to be
3054 * set otherwise card may disappear.
3055 */
3056 val = AR9280_WA_DEFAULT;
3057 if (!power_off)
3058 val &= (~AR_WA_D3_L1_DISABLE);
3059 } else
3060 val = AR_WA_DEFAULT;
3061 }
Sujithf1dc5602008-10-29 10:16:30 +05303062
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303063 REG_WRITE(ah, AR_WA, val);
Sujithf1dc5602008-10-29 10:16:30 +05303064 }
3065
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303066 if (power_off) {
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08003067 /*
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303068 * Set PCIe workaround bits
3069 * bit 14 in WA register (disable L1) should only
3070 * be set when device enters D3 and be cleared
3071 * when device comes back to D0.
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08003072 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303073 if (ah->config.pcie_waen) {
3074 if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE)
3075 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
3076 } else {
3077 if (((AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
3078 AR_SREV_9287(ah)) &&
3079 (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)) ||
3080 (AR_SREV_9280(ah) &&
3081 (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE))) {
3082 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
3083 }
3084 }
Sujithf1dc5602008-10-29 10:16:30 +05303085 }
3086}
3087
3088/**********************/
3089/* Interrupt Handling */
3090/**********************/
3091
Sujithcbe61d82009-02-09 13:27:12 +05303092bool ath9k_hw_intrpend(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003093{
3094 u32 host_isr;
3095
3096 if (AR_SREV_9100(ah))
3097 return true;
3098
3099 host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
3100 if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
3101 return true;
3102
3103 host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
3104 if ((host_isr & AR_INTR_SYNC_DEFAULT)
3105 && (host_isr != AR_INTR_SPURIOUS))
3106 return true;
3107
3108 return false;
3109}
3110
Sujithcbe61d82009-02-09 13:27:12 +05303111bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003112{
3113 u32 isr = 0;
3114 u32 mask2 = 0;
Sujith2660b812009-02-09 13:27:26 +05303115 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003116 u32 sync_cause = 0;
3117 bool fatal_int = false;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003118 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003119
3120 if (!AR_SREV_9100(ah)) {
3121 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
3122 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
3123 == AR_RTC_STATUS_ON) {
3124 isr = REG_READ(ah, AR_ISR);
3125 }
3126 }
3127
Sujithf1dc5602008-10-29 10:16:30 +05303128 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
3129 AR_INTR_SYNC_DEFAULT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003130
3131 *masked = 0;
3132
3133 if (!isr && !sync_cause)
3134 return false;
3135 } else {
3136 *masked = 0;
3137 isr = REG_READ(ah, AR_ISR);
3138 }
3139
3140 if (isr) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003141 if (isr & AR_ISR_BCNMISC) {
3142 u32 isr2;
3143 isr2 = REG_READ(ah, AR_ISR_S2);
3144 if (isr2 & AR_ISR_S2_TIM)
3145 mask2 |= ATH9K_INT_TIM;
3146 if (isr2 & AR_ISR_S2_DTIM)
3147 mask2 |= ATH9K_INT_DTIM;
3148 if (isr2 & AR_ISR_S2_DTIMSYNC)
3149 mask2 |= ATH9K_INT_DTIMSYNC;
3150 if (isr2 & (AR_ISR_S2_CABEND))
3151 mask2 |= ATH9K_INT_CABEND;
3152 if (isr2 & AR_ISR_S2_GTT)
3153 mask2 |= ATH9K_INT_GTT;
3154 if (isr2 & AR_ISR_S2_CST)
3155 mask2 |= ATH9K_INT_CST;
Sujith4af9cf42009-02-12 10:06:47 +05303156 if (isr2 & AR_ISR_S2_TSFOOR)
3157 mask2 |= ATH9K_INT_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003158 }
3159
3160 isr = REG_READ(ah, AR_ISR_RAC);
3161 if (isr == 0xffffffff) {
3162 *masked = 0;
3163 return false;
3164 }
3165
3166 *masked = isr & ATH9K_INT_COMMON;
3167
Sujith0ef1f162009-03-30 15:28:35 +05303168 if (ah->config.intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003169 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
3170 *masked |= ATH9K_INT_RX;
3171 }
3172
3173 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
3174 *masked |= ATH9K_INT_RX;
3175 if (isr &
3176 (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
3177 AR_ISR_TXEOL)) {
3178 u32 s0_s, s1_s;
3179
3180 *masked |= ATH9K_INT_TX;
3181
3182 s0_s = REG_READ(ah, AR_ISR_S0_S);
Sujith2660b812009-02-09 13:27:26 +05303183 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
3184 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003185
3186 s1_s = REG_READ(ah, AR_ISR_S1_S);
Sujith2660b812009-02-09 13:27:26 +05303187 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
3188 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003189 }
3190
3191 if (isr & AR_ISR_RXORN) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003192 ath_print(common, ATH_DBG_INTERRUPT,
3193 "receive FIFO overrun interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003194 }
3195
3196 if (!AR_SREV_9100(ah)) {
Sujith60b67f52008-08-07 10:52:38 +05303197 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003198 u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
3199 if (isr5 & AR_ISR_S5_TIM_TIMER)
3200 *masked |= ATH9K_INT_TIM_TIMER;
3201 }
3202 }
3203
3204 *masked |= mask2;
3205 }
Sujithf1dc5602008-10-29 10:16:30 +05303206
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003207 if (AR_SREV_9100(ah))
3208 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303209
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303210 if (isr & AR_ISR_GENTMR) {
3211 u32 s5_s;
3212
3213 s5_s = REG_READ(ah, AR_ISR_S5_S);
3214 if (isr & AR_ISR_GENTMR) {
3215 ah->intr_gen_timer_trigger =
3216 MS(s5_s, AR_ISR_S5_GENTIMER_TRIG);
3217
3218 ah->intr_gen_timer_thresh =
3219 MS(s5_s, AR_ISR_S5_GENTIMER_THRESH);
3220
3221 if (ah->intr_gen_timer_trigger)
3222 *masked |= ATH9K_INT_GENTIMER;
3223
3224 }
3225 }
3226
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003227 if (sync_cause) {
3228 fatal_int =
3229 (sync_cause &
3230 (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
3231 ? true : false;
3232
3233 if (fatal_int) {
3234 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003235 ath_print(common, ATH_DBG_ANY,
3236 "received PCI FATAL interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003237 }
3238 if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003239 ath_print(common, ATH_DBG_ANY,
3240 "received PCI PERR interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003241 }
Steven Luoa89bff92009-04-12 02:57:54 -07003242 *masked |= ATH9K_INT_FATAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003243 }
3244 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003245 ath_print(common, ATH_DBG_INTERRUPT,
3246 "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003247 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
3248 REG_WRITE(ah, AR_RC, 0);
3249 *masked |= ATH9K_INT_FATAL;
3250 }
3251 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003252 ath_print(common, ATH_DBG_INTERRUPT,
3253 "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003254 }
3255
3256 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
3257 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
3258 }
Sujithf1dc5602008-10-29 10:16:30 +05303259
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003260 return true;
3261}
3262
Sujithcbe61d82009-02-09 13:27:12 +05303263enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003264{
Sujith2660b812009-02-09 13:27:26 +05303265 u32 omask = ah->mask_reg;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003266 u32 mask, mask2;
Sujith2660b812009-02-09 13:27:26 +05303267 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003268 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003269
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003270 ath_print(common, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003271
3272 if (omask & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003273 ath_print(common, ATH_DBG_INTERRUPT, "disable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003274 REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
3275 (void) REG_READ(ah, AR_IER);
3276 if (!AR_SREV_9100(ah)) {
3277 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
3278 (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
3279
3280 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
3281 (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
3282 }
3283 }
3284
3285 mask = ints & ATH9K_INT_COMMON;
3286 mask2 = 0;
3287
3288 if (ints & ATH9K_INT_TX) {
Sujith2660b812009-02-09 13:27:26 +05303289 if (ah->txok_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003290 mask |= AR_IMR_TXOK;
Sujith2660b812009-02-09 13:27:26 +05303291 if (ah->txdesc_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003292 mask |= AR_IMR_TXDESC;
Sujith2660b812009-02-09 13:27:26 +05303293 if (ah->txerr_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003294 mask |= AR_IMR_TXERR;
Sujith2660b812009-02-09 13:27:26 +05303295 if (ah->txeol_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003296 mask |= AR_IMR_TXEOL;
3297 }
3298 if (ints & ATH9K_INT_RX) {
3299 mask |= AR_IMR_RXERR;
Sujith0ef1f162009-03-30 15:28:35 +05303300 if (ah->config.intr_mitigation)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003301 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
3302 else
3303 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
Sujith60b67f52008-08-07 10:52:38 +05303304 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003305 mask |= AR_IMR_GENTMR;
3306 }
3307
3308 if (ints & (ATH9K_INT_BMISC)) {
3309 mask |= AR_IMR_BCNMISC;
3310 if (ints & ATH9K_INT_TIM)
3311 mask2 |= AR_IMR_S2_TIM;
3312 if (ints & ATH9K_INT_DTIM)
3313 mask2 |= AR_IMR_S2_DTIM;
3314 if (ints & ATH9K_INT_DTIMSYNC)
3315 mask2 |= AR_IMR_S2_DTIMSYNC;
3316 if (ints & ATH9K_INT_CABEND)
Sujith4af9cf42009-02-12 10:06:47 +05303317 mask2 |= AR_IMR_S2_CABEND;
3318 if (ints & ATH9K_INT_TSFOOR)
3319 mask2 |= AR_IMR_S2_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003320 }
3321
3322 if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
3323 mask |= AR_IMR_BCNMISC;
3324 if (ints & ATH9K_INT_GTT)
3325 mask2 |= AR_IMR_S2_GTT;
3326 if (ints & ATH9K_INT_CST)
3327 mask2 |= AR_IMR_S2_CST;
3328 }
3329
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003330 ath_print(common, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003331 REG_WRITE(ah, AR_IMR, mask);
3332 mask = REG_READ(ah, AR_IMR_S2) & ~(AR_IMR_S2_TIM |
3333 AR_IMR_S2_DTIM |
3334 AR_IMR_S2_DTIMSYNC |
3335 AR_IMR_S2_CABEND |
3336 AR_IMR_S2_CABTO |
3337 AR_IMR_S2_TSFOOR |
3338 AR_IMR_S2_GTT | AR_IMR_S2_CST);
3339 REG_WRITE(ah, AR_IMR_S2, mask | mask2);
Sujith2660b812009-02-09 13:27:26 +05303340 ah->mask_reg = ints;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003341
Sujith60b67f52008-08-07 10:52:38 +05303342 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003343 if (ints & ATH9K_INT_TIM_TIMER)
3344 REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
3345 else
3346 REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
3347 }
3348
3349 if (ints & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003350 ath_print(common, ATH_DBG_INTERRUPT, "enable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003351 REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
3352 if (!AR_SREV_9100(ah)) {
3353 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
3354 AR_INTR_MAC_IRQ);
3355 REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
3356
3357
3358 REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
3359 AR_INTR_SYNC_DEFAULT);
3360 REG_WRITE(ah, AR_INTR_SYNC_MASK,
3361 AR_INTR_SYNC_DEFAULT);
3362 }
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003363 ath_print(common, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
3364 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003365 }
3366
3367 return omask;
3368}
3369
Sujithf1dc5602008-10-29 10:16:30 +05303370/*******************/
3371/* Beacon Handling */
3372/*******************/
3373
Sujithcbe61d82009-02-09 13:27:12 +05303374void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003375{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003376 int flags = 0;
3377
Sujith2660b812009-02-09 13:27:26 +05303378 ah->beacon_interval = beacon_period;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003379
Sujith2660b812009-02-09 13:27:26 +05303380 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08003381 case NL80211_IFTYPE_STATION:
3382 case NL80211_IFTYPE_MONITOR:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003383 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3384 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
3385 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
3386 flags |= AR_TBTT_TIMER_EN;
3387 break;
Colin McCabed97809d2008-12-01 13:38:55 -08003388 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04003389 case NL80211_IFTYPE_MESH_POINT:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003390 REG_SET_BIT(ah, AR_TXCFG,
3391 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
3392 REG_WRITE(ah, AR_NEXT_NDP_TIMER,
3393 TU_TO_USEC(next_beacon +
Sujith2660b812009-02-09 13:27:26 +05303394 (ah->atim_window ? ah->
3395 atim_window : 1)));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003396 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08003397 case NL80211_IFTYPE_AP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003398 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3399 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
3400 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05303401 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05303402 dma_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003403 REG_WRITE(ah, AR_NEXT_SWBA,
3404 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05303405 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05303406 sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003407 flags |=
3408 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
3409 break;
Colin McCabed97809d2008-12-01 13:38:55 -08003410 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003411 ath_print(ath9k_hw_common(ah), ATH_DBG_BEACON,
3412 "%s: unsupported opmode: %d\n",
3413 __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08003414 return;
3415 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003416 }
3417
3418 REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3419 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3420 REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
3421 REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
3422
3423 beacon_period &= ~ATH9K_BEACON_ENA;
3424 if (beacon_period & ATH9K_BEACON_RESET_TSF) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003425 ath9k_hw_reset_tsf(ah);
3426 }
3427
3428 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
3429}
3430
Sujithcbe61d82009-02-09 13:27:12 +05303431void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303432 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003433{
3434 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05303435 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003436 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003437
3438 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
3439
3440 REG_WRITE(ah, AR_BEACON_PERIOD,
3441 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3442 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
3443 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3444
3445 REG_RMW_FIELD(ah, AR_RSSI_THR,
3446 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
3447
3448 beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
3449
3450 if (bs->bs_sleepduration > beaconintval)
3451 beaconintval = bs->bs_sleepduration;
3452
3453 dtimperiod = bs->bs_dtimperiod;
3454 if (bs->bs_sleepduration > dtimperiod)
3455 dtimperiod = bs->bs_sleepduration;
3456
3457 if (beaconintval == dtimperiod)
3458 nextTbtt = bs->bs_nextdtim;
3459 else
3460 nextTbtt = bs->bs_nexttbtt;
3461
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003462 ath_print(common, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
3463 ath_print(common, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
3464 ath_print(common, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
3465 ath_print(common, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003466
3467 REG_WRITE(ah, AR_NEXT_DTIM,
3468 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
3469 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
3470
3471 REG_WRITE(ah, AR_SLEEP1,
3472 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
3473 | AR_SLEEP1_ASSUME_DTIM);
3474
Sujith60b67f52008-08-07 10:52:38 +05303475 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003476 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
3477 else
3478 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
3479
3480 REG_WRITE(ah, AR_SLEEP2,
3481 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
3482
3483 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
3484 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
3485
3486 REG_SET_BIT(ah, AR_TIMER_MODE,
3487 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
3488 AR_DTIM_TIMER_EN);
3489
Sujith4af9cf42009-02-12 10:06:47 +05303490 /* TSF Out of Range Threshold */
3491 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003492}
3493
Sujithf1dc5602008-10-29 10:16:30 +05303494/*******************/
3495/* HW Capabilities */
3496/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003497
Sujitheef7a572009-03-30 15:28:28 +05303498void ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003499{
Sujith2660b812009-02-09 13:27:26 +05303500 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003501 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003502 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003503 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003504
Sujithf1dc5602008-10-29 10:16:30 +05303505 u16 capField = 0, eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003506
Sujithf74df6f2009-02-09 13:27:24 +05303507 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003508 regulatory->current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303509
Sujithf74df6f2009-02-09 13:27:24 +05303510 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
Sujithfec0de12009-02-12 10:06:43 +05303511 if (AR_SREV_9285_10_OR_LATER(ah))
3512 eeval |= AR9285_RDEXT_DEFAULT;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003513 regulatory->current_rd_ext = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303514
Sujithf74df6f2009-02-09 13:27:24 +05303515 capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
Sujithf1dc5602008-10-29 10:16:30 +05303516
Sujith2660b812009-02-09 13:27:26 +05303517 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05303518 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003519 if (regulatory->current_rd == 0x64 ||
3520 regulatory->current_rd == 0x65)
3521 regulatory->current_rd += 5;
3522 else if (regulatory->current_rd == 0x41)
3523 regulatory->current_rd = 0x43;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003524 ath_print(common, ATH_DBG_REGULATORY,
3525 "regdomain mapped to 0x%x\n", regulatory->current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003526 }
Sujithdc2222a2008-08-14 13:26:55 +05303527
Sujithf74df6f2009-02-09 13:27:24 +05303528 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Sujithf1dc5602008-10-29 10:16:30 +05303529 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003530
Sujithf1dc5602008-10-29 10:16:30 +05303531 if (eeval & AR5416_OPFLAGS_11A) {
3532 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303533 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303534 if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
3535 set_bit(ATH9K_MODE_11NA_HT20,
3536 pCap->wireless_modes);
3537 if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
3538 set_bit(ATH9K_MODE_11NA_HT40PLUS,
3539 pCap->wireless_modes);
3540 set_bit(ATH9K_MODE_11NA_HT40MINUS,
3541 pCap->wireless_modes);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003542 }
3543 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003544 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003545
Sujithf1dc5602008-10-29 10:16:30 +05303546 if (eeval & AR5416_OPFLAGS_11G) {
Sujithf1dc5602008-10-29 10:16:30 +05303547 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303548 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303549 if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
3550 set_bit(ATH9K_MODE_11NG_HT20,
3551 pCap->wireless_modes);
3552 if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
3553 set_bit(ATH9K_MODE_11NG_HT40PLUS,
3554 pCap->wireless_modes);
3555 set_bit(ATH9K_MODE_11NG_HT40MINUS,
3556 pCap->wireless_modes);
3557 }
3558 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003559 }
Sujithf1dc5602008-10-29 10:16:30 +05303560
Sujithf74df6f2009-02-09 13:27:24 +05303561 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003562 /*
3563 * For AR9271 we will temporarilly uses the rx chainmax as read from
3564 * the EEPROM.
3565 */
Sujith8147f5d2009-02-20 15:13:23 +05303566 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003567 !(eeval & AR5416_OPFLAGS_11A) &&
3568 !(AR_SREV_9271(ah)))
3569 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
Sujith8147f5d2009-02-20 15:13:23 +05303570 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
3571 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003572 /* Use rx_chainmask from EEPROM. */
Sujith8147f5d2009-02-20 15:13:23 +05303573 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05303574
Sujithd535a422009-02-09 13:27:06 +05303575 if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0)))
Sujith2660b812009-02-09 13:27:26 +05303576 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05303577
3578 pCap->low_2ghz_chan = 2312;
3579 pCap->high_2ghz_chan = 2732;
3580
3581 pCap->low_5ghz_chan = 4920;
3582 pCap->high_5ghz_chan = 6100;
3583
3584 pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
3585 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
3586 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
3587
3588 pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
3589 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
3590 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
3591
Sujith2660b812009-02-09 13:27:26 +05303592 if (ah->config.ht_enable)
Sujithf1dc5602008-10-29 10:16:30 +05303593 pCap->hw_caps |= ATH9K_HW_CAP_HT;
3594 else
3595 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
3596
3597 pCap->hw_caps |= ATH9K_HW_CAP_GTT;
3598 pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
3599 pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
3600 pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
3601
3602 if (capField & AR_EEPROM_EEPCAP_MAXQCU)
3603 pCap->total_queues =
3604 MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
3605 else
3606 pCap->total_queues = ATH9K_NUM_TX_QUEUES;
3607
3608 if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
3609 pCap->keycache_size =
3610 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
3611 else
3612 pCap->keycache_size = AR_KEYTABLE_SIZE;
3613
3614 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
Sujithf1dc5602008-10-29 10:16:30 +05303615 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
3616
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303617 if (AR_SREV_9285_10_OR_LATER(ah))
3618 pCap->num_gpio_pins = AR9285_NUM_GPIO;
3619 else if (AR_SREV_9280_10_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303620 pCap->num_gpio_pins = AR928X_NUM_GPIO;
3621 else
3622 pCap->num_gpio_pins = AR_NUM_GPIO;
3623
Sujithf1dc5602008-10-29 10:16:30 +05303624 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
3625 pCap->hw_caps |= ATH9K_HW_CAP_CST;
3626 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
3627 } else {
3628 pCap->rts_aggr_limit = (8 * 1024);
3629 }
3630
3631 pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
3632
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05303633#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05303634 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
3635 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
3636 ah->rfkill_gpio =
3637 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
3638 ah->rfkill_polarity =
3639 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05303640
3641 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
3642 }
3643#endif
3644
Vivek Natarajana3ca95fb2009-09-17 09:29:07 +05303645 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
Sujithf1dc5602008-10-29 10:16:30 +05303646
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05303647 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303648 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
3649 else
3650 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
3651
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003652 if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) {
Sujithf1dc5602008-10-29 10:16:30 +05303653 pCap->reg_cap =
3654 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3655 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
3656 AR_EEPROM_EEREGCAP_EN_KK_U2 |
3657 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
3658 } else {
3659 pCap->reg_cap =
3660 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3661 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
3662 }
3663
3664 pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
3665
3666 pCap->num_antcfg_5ghz =
Sujithf74df6f2009-02-09 13:27:24 +05303667 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303668 pCap->num_antcfg_2ghz =
Sujithf74df6f2009-02-09 13:27:24 +05303669 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303670
Vasanthakumar Thiagarajanfe129462009-09-09 15:25:50 +05303671 if (AR_SREV_9280_10_OR_LATER(ah) &&
Luis R. Rodrigueza36cfbc2009-09-09 16:05:32 -07003672 ath9k_hw_btcoex_supported(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003673 btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO;
3674 btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO;
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05303675
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303676 if (AR_SREV_9285(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003677 btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
3678 btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303679 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003680 btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303681 }
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05303682 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003683 btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE;
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303684 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003685}
3686
Sujithcbe61d82009-02-09 13:27:12 +05303687bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303688 u32 capability, u32 *result)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003689{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003690 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05303691 switch (type) {
3692 case ATH9K_CAP_CIPHER:
3693 switch (capability) {
3694 case ATH9K_CIPHER_AES_CCM:
3695 case ATH9K_CIPHER_AES_OCB:
3696 case ATH9K_CIPHER_TKIP:
3697 case ATH9K_CIPHER_WEP:
3698 case ATH9K_CIPHER_MIC:
3699 case ATH9K_CIPHER_CLR:
3700 return true;
3701 default:
3702 return false;
3703 }
3704 case ATH9K_CAP_TKIP_MIC:
3705 switch (capability) {
3706 case 0:
3707 return true;
3708 case 1:
Sujith2660b812009-02-09 13:27:26 +05303709 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303710 AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
3711 false;
3712 }
3713 case ATH9K_CAP_TKIP_SPLIT:
Sujith2660b812009-02-09 13:27:26 +05303714 return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ?
Sujithf1dc5602008-10-29 10:16:30 +05303715 false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303716 case ATH9K_CAP_DIVERSITY:
3717 return (REG_READ(ah, AR_PHY_CCK_DETECT) &
3718 AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV) ?
3719 true : false;
Sujithf1dc5602008-10-29 10:16:30 +05303720 case ATH9K_CAP_MCAST_KEYSRCH:
3721 switch (capability) {
3722 case 0:
3723 return true;
3724 case 1:
3725 if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
3726 return false;
3727 } else {
Sujith2660b812009-02-09 13:27:26 +05303728 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303729 AR_STA_ID1_MCAST_KSRCH) ? true :
3730 false;
3731 }
3732 }
3733 return false;
Sujithf1dc5602008-10-29 10:16:30 +05303734 case ATH9K_CAP_TXPOW:
3735 switch (capability) {
3736 case 0:
3737 return 0;
3738 case 1:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003739 *result = regulatory->power_limit;
Sujithf1dc5602008-10-29 10:16:30 +05303740 return 0;
3741 case 2:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003742 *result = regulatory->max_power_level;
Sujithf1dc5602008-10-29 10:16:30 +05303743 return 0;
3744 case 3:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003745 *result = regulatory->tp_scale;
Sujithf1dc5602008-10-29 10:16:30 +05303746 return 0;
3747 }
3748 return false;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05303749 case ATH9K_CAP_DS:
3750 return (AR_SREV_9280_20_OR_LATER(ah) &&
3751 (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1))
3752 ? false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303753 default:
3754 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003755 }
Sujithf1dc5602008-10-29 10:16:30 +05303756}
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003757
Sujithcbe61d82009-02-09 13:27:12 +05303758bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303759 u32 capability, u32 setting, int *status)
3760{
Sujithf1dc5602008-10-29 10:16:30 +05303761 u32 v;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003762
Sujithf1dc5602008-10-29 10:16:30 +05303763 switch (type) {
3764 case ATH9K_CAP_TKIP_MIC:
3765 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303766 ah->sta_id1_defaults |=
Sujithf1dc5602008-10-29 10:16:30 +05303767 AR_STA_ID1_CRPT_MIC_ENABLE;
3768 else
Sujith2660b812009-02-09 13:27:26 +05303769 ah->sta_id1_defaults &=
Sujithf1dc5602008-10-29 10:16:30 +05303770 ~AR_STA_ID1_CRPT_MIC_ENABLE;
3771 return true;
3772 case ATH9K_CAP_DIVERSITY:
3773 v = REG_READ(ah, AR_PHY_CCK_DETECT);
3774 if (setting)
3775 v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3776 else
3777 v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3778 REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
3779 return true;
3780 case ATH9K_CAP_MCAST_KEYSRCH:
3781 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303782 ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303783 else
Sujith2660b812009-02-09 13:27:26 +05303784 ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303785 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303786 default:
3787 return false;
3788 }
3789}
3790
3791/****************************/
3792/* GPIO / RFKILL / Antennae */
3793/****************************/
3794
Sujithcbe61d82009-02-09 13:27:12 +05303795static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303796 u32 gpio, u32 type)
3797{
3798 int addr;
3799 u32 gpio_shift, tmp;
3800
3801 if (gpio > 11)
3802 addr = AR_GPIO_OUTPUT_MUX3;
3803 else if (gpio > 5)
3804 addr = AR_GPIO_OUTPUT_MUX2;
3805 else
3806 addr = AR_GPIO_OUTPUT_MUX1;
3807
3808 gpio_shift = (gpio % 6) * 5;
3809
3810 if (AR_SREV_9280_20_OR_LATER(ah)
3811 || (addr != AR_GPIO_OUTPUT_MUX1)) {
3812 REG_RMW(ah, addr, (type << gpio_shift),
3813 (0x1f << gpio_shift));
3814 } else {
3815 tmp = REG_READ(ah, addr);
3816 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
3817 tmp &= ~(0x1f << gpio_shift);
3818 tmp |= (type << gpio_shift);
3819 REG_WRITE(ah, addr, tmp);
3820 }
3821}
3822
Sujithcbe61d82009-02-09 13:27:12 +05303823void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303824{
3825 u32 gpio_shift;
3826
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07003827 BUG_ON(gpio >= ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05303828
3829 gpio_shift = gpio << 1;
3830
3831 REG_RMW(ah,
3832 AR_GPIO_OE_OUT,
3833 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
3834 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3835}
3836
Sujithcbe61d82009-02-09 13:27:12 +05303837u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303838{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303839#define MS_REG_READ(x, y) \
3840 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
3841
Sujith2660b812009-02-09 13:27:26 +05303842 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05303843 return 0xffffffff;
3844
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05303845 if (AR_SREV_9287_10_OR_LATER(ah))
3846 return MS_REG_READ(AR9287, gpio) != 0;
3847 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303848 return MS_REG_READ(AR9285, gpio) != 0;
3849 else if (AR_SREV_9280_10_OR_LATER(ah))
3850 return MS_REG_READ(AR928X, gpio) != 0;
3851 else
3852 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05303853}
3854
Sujithcbe61d82009-02-09 13:27:12 +05303855void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05303856 u32 ah_signal_type)
3857{
3858 u32 gpio_shift;
3859
3860 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
3861
3862 gpio_shift = 2 * gpio;
3863
3864 REG_RMW(ah,
3865 AR_GPIO_OE_OUT,
3866 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
3867 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3868}
3869
Sujithcbe61d82009-02-09 13:27:12 +05303870void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05303871{
3872 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
3873 AR_GPIO_BIT(gpio));
3874}
3875
Sujithcbe61d82009-02-09 13:27:12 +05303876u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303877{
3878 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
3879}
3880
Sujithcbe61d82009-02-09 13:27:12 +05303881void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05303882{
3883 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
3884}
3885
Sujithcbe61d82009-02-09 13:27:12 +05303886bool ath9k_hw_setantennaswitch(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303887 enum ath9k_ant_setting settings,
3888 struct ath9k_channel *chan,
3889 u8 *tx_chainmask,
3890 u8 *rx_chainmask,
3891 u8 *antenna_cfgd)
3892{
Sujithf1dc5602008-10-29 10:16:30 +05303893 static u8 tx_chainmask_cfg, rx_chainmask_cfg;
3894
3895 if (AR_SREV_9280(ah)) {
3896 if (!tx_chainmask_cfg) {
3897
3898 tx_chainmask_cfg = *tx_chainmask;
3899 rx_chainmask_cfg = *rx_chainmask;
3900 }
3901
3902 switch (settings) {
3903 case ATH9K_ANT_FIXED_A:
3904 *tx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3905 *rx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3906 *antenna_cfgd = true;
3907 break;
3908 case ATH9K_ANT_FIXED_B:
Sujith2660b812009-02-09 13:27:26 +05303909 if (ah->caps.tx_chainmask >
Sujithf1dc5602008-10-29 10:16:30 +05303910 ATH9K_ANTENNA1_CHAINMASK) {
3911 *tx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3912 }
3913 *rx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3914 *antenna_cfgd = true;
3915 break;
3916 case ATH9K_ANT_VARIABLE:
3917 *tx_chainmask = tx_chainmask_cfg;
3918 *rx_chainmask = rx_chainmask_cfg;
3919 *antenna_cfgd = true;
3920 break;
3921 default:
3922 break;
3923 }
3924 } else {
Sujith1cf68732009-08-13 09:34:32 +05303925 ah->config.diversity_control = settings;
Sujithf1dc5602008-10-29 10:16:30 +05303926 }
3927
3928 return true;
3929}
3930
3931/*********************/
3932/* General Operation */
3933/*********************/
3934
Sujithcbe61d82009-02-09 13:27:12 +05303935u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303936{
3937 u32 bits = REG_READ(ah, AR_RX_FILTER);
3938 u32 phybits = REG_READ(ah, AR_PHY_ERR);
3939
3940 if (phybits & AR_PHY_ERR_RADAR)
3941 bits |= ATH9K_RX_FILTER_PHYRADAR;
3942 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
3943 bits |= ATH9K_RX_FILTER_PHYERR;
3944
3945 return bits;
3946}
3947
Sujithcbe61d82009-02-09 13:27:12 +05303948void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05303949{
3950 u32 phybits;
3951
Sujith7ea310b2009-09-03 12:08:43 +05303952 REG_WRITE(ah, AR_RX_FILTER, bits);
3953
Sujithf1dc5602008-10-29 10:16:30 +05303954 phybits = 0;
3955 if (bits & ATH9K_RX_FILTER_PHYRADAR)
3956 phybits |= AR_PHY_ERR_RADAR;
3957 if (bits & ATH9K_RX_FILTER_PHYERR)
3958 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
3959 REG_WRITE(ah, AR_PHY_ERR, phybits);
3960
3961 if (phybits)
3962 REG_WRITE(ah, AR_RXCFG,
3963 REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
3964 else
3965 REG_WRITE(ah, AR_RXCFG,
3966 REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
3967}
3968
Sujithcbe61d82009-02-09 13:27:12 +05303969bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303970{
3971 return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM);
3972}
3973
Sujithcbe61d82009-02-09 13:27:12 +05303974bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303975{
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07003976 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05303977 return false;
3978
3979 return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD);
3980}
3981
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003982void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
Sujithf1dc5602008-10-29 10:16:30 +05303983{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003984 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujith2660b812009-02-09 13:27:26 +05303985 struct ath9k_channel *chan = ah->curchan;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08003986 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05303987
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003988 regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER);
Sujithf1dc5602008-10-29 10:16:30 +05303989
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003990 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003991 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003992 channel->max_antenna_gain * 2,
3993 channel->max_power * 2,
3994 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003995 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05303996}
3997
Sujithcbe61d82009-02-09 13:27:12 +05303998void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac)
Sujithf1dc5602008-10-29 10:16:30 +05303999{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07004000 memcpy(ath9k_hw_common(ah)->macaddr, mac, ETH_ALEN);
Sujithf1dc5602008-10-29 10:16:30 +05304001}
4002
Sujithcbe61d82009-02-09 13:27:12 +05304003void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304004{
Sujith2660b812009-02-09 13:27:26 +05304005 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05304006}
4007
Sujithcbe61d82009-02-09 13:27:12 +05304008void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05304009{
4010 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
4011 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
4012}
4013
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07004014void ath9k_hw_write_associd(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304015{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07004016 struct ath_common *common = ath9k_hw_common(ah);
4017
4018 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
4019 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
4020 ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05304021}
4022
Sujithcbe61d82009-02-09 13:27:12 +05304023u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304024{
4025 u64 tsf;
4026
4027 tsf = REG_READ(ah, AR_TSF_U32);
4028 tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
4029
4030 return tsf;
4031}
4032
Sujithcbe61d82009-02-09 13:27:12 +05304033void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004034{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004035 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01004036 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004037}
4038
Sujithcbe61d82009-02-09 13:27:12 +05304039void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304040{
Gabor Juhosf9b604f2009-06-21 00:02:15 +02004041 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
4042 AH_TSF_WRITE_TIMEOUT))
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004043 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
4044 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
Gabor Juhosf9b604f2009-06-21 00:02:15 +02004045
Sujithf1dc5602008-10-29 10:16:30 +05304046 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004047}
4048
Sujith54e4cec2009-08-07 09:45:09 +05304049void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004050{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004051 if (setting)
Sujith2660b812009-02-09 13:27:26 +05304052 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004053 else
Sujith2660b812009-02-09 13:27:26 +05304054 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004055}
4056
Sujithcbe61d82009-02-09 13:27:12 +05304057bool ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004058{
Sujithf1dc5602008-10-29 10:16:30 +05304059 if (us < ATH9K_SLOT_TIME_9 || us > ath9k_hw_mac_to_usec(ah, 0xffff)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004060 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
4061 "bad slot time %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05304062 ah->slottime = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05304063 return false;
4064 } else {
4065 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05304066 ah->slottime = us;
Sujithf1dc5602008-10-29 10:16:30 +05304067 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004068 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004069}
4070
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07004071void ath9k_hw_set11nmac2040(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004072{
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07004073 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithf1dc5602008-10-29 10:16:30 +05304074 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004075
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07004076 if (conf_is_ht40(conf) && !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05304077 macmode = AR_2040_JOINED_RX_CLEAR;
4078 else
4079 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004080
Sujithf1dc5602008-10-29 10:16:30 +05304081 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004082}
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304083
4084/* HW Generic timers configuration */
4085
4086static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
4087{
4088 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4089 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4090 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4091 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4092 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4093 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4094 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4095 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4096 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
4097 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
4098 AR_NDP2_TIMER_MODE, 0x0002},
4099 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
4100 AR_NDP2_TIMER_MODE, 0x0004},
4101 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
4102 AR_NDP2_TIMER_MODE, 0x0008},
4103 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
4104 AR_NDP2_TIMER_MODE, 0x0010},
4105 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
4106 AR_NDP2_TIMER_MODE, 0x0020},
4107 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
4108 AR_NDP2_TIMER_MODE, 0x0040},
4109 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
4110 AR_NDP2_TIMER_MODE, 0x0080}
4111};
4112
4113/* HW generic timer primitives */
4114
4115/* compute and clear index of rightmost 1 */
4116static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
4117{
4118 u32 b;
4119
4120 b = *mask;
4121 b &= (0-b);
4122 *mask &= ~b;
4123 b *= debruijn32;
4124 b >>= 27;
4125
4126 return timer_table->gen_timer_index[b];
4127}
4128
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05304129u32 ath9k_hw_gettsf32(struct ath_hw *ah)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304130{
4131 return REG_READ(ah, AR_TSF_L32);
4132}
4133
4134struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
4135 void (*trigger)(void *),
4136 void (*overflow)(void *),
4137 void *arg,
4138 u8 timer_index)
4139{
4140 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4141 struct ath_gen_timer *timer;
4142
4143 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
4144
4145 if (timer == NULL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004146 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
4147 "Failed to allocate memory"
4148 "for hw timer[%d]\n", timer_index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304149 return NULL;
4150 }
4151
4152 /* allocate a hardware generic timer slot */
4153 timer_table->timers[timer_index] = timer;
4154 timer->index = timer_index;
4155 timer->trigger = trigger;
4156 timer->overflow = overflow;
4157 timer->arg = arg;
4158
4159 return timer;
4160}
4161
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07004162void ath9k_hw_gen_timer_start(struct ath_hw *ah,
4163 struct ath_gen_timer *timer,
4164 u32 timer_next,
4165 u32 timer_period)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304166{
4167 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4168 u32 tsf;
4169
4170 BUG_ON(!timer_period);
4171
4172 set_bit(timer->index, &timer_table->timer_mask.timer_bits);
4173
4174 tsf = ath9k_hw_gettsf32(ah);
4175
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004176 ath_print(ath9k_hw_common(ah), ATH_DBG_HWTIMER,
4177 "curent tsf %x period %x"
4178 "timer_next %x\n", tsf, timer_period, timer_next);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304179
4180 /*
4181 * Pull timer_next forward if the current TSF already passed it
4182 * because of software latency
4183 */
4184 if (timer_next < tsf)
4185 timer_next = tsf + timer_period;
4186
4187 /*
4188 * Program generic timer registers
4189 */
4190 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
4191 timer_next);
4192 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
4193 timer_period);
4194 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
4195 gen_tmr_configuration[timer->index].mode_mask);
4196
4197 /* Enable both trigger and thresh interrupt masks */
4198 REG_SET_BIT(ah, AR_IMR_S5,
4199 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
4200 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304201}
4202
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07004203void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304204{
4205 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4206
4207 if ((timer->index < AR_FIRST_NDP_TIMER) ||
4208 (timer->index >= ATH_MAX_GEN_TIMER)) {
4209 return;
4210 }
4211
4212 /* Clear generic timer enable bits. */
4213 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
4214 gen_tmr_configuration[timer->index].mode_mask);
4215
4216 /* Disable both trigger and thresh interrupt masks */
4217 REG_CLR_BIT(ah, AR_IMR_S5,
4218 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
4219 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
4220
4221 clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304222}
4223
4224void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
4225{
4226 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4227
4228 /* free the hardware generic timer slot */
4229 timer_table->timers[timer->index] = NULL;
4230 kfree(timer);
4231}
4232
4233/*
4234 * Generic Timer Interrupts handling
4235 */
4236void ath_gen_timer_isr(struct ath_hw *ah)
4237{
4238 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4239 struct ath_gen_timer *timer;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004240 struct ath_common *common = ath9k_hw_common(ah);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304241 u32 trigger_mask, thresh_mask, index;
4242
4243 /* get hardware generic timer interrupt status */
4244 trigger_mask = ah->intr_gen_timer_trigger;
4245 thresh_mask = ah->intr_gen_timer_thresh;
4246 trigger_mask &= timer_table->timer_mask.val;
4247 thresh_mask &= timer_table->timer_mask.val;
4248
4249 trigger_mask &= ~thresh_mask;
4250
4251 while (thresh_mask) {
4252 index = rightmost_index(timer_table, &thresh_mask);
4253 timer = timer_table->timers[index];
4254 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004255 ath_print(common, ATH_DBG_HWTIMER,
4256 "TSF overflow for Gen timer %d\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304257 timer->overflow(timer->arg);
4258 }
4259
4260 while (trigger_mask) {
4261 index = rightmost_index(timer_table, &trigger_mask);
4262 timer = timer_table->timers[index];
4263 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004264 ath_print(common, ATH_DBG_HWTIMER,
4265 "Gen timer[%d] trigger\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304266 timer->trigger(timer->arg);
4267 }
4268}