blob: 1c02358b31f5931c418db9c60b35d2d456e10206 [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
2 * Copyright (c) 2008 Atheros Communications Inc.
3 *
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
Sujith394cf0a2009-02-09 13:26:54 +053020#include "ath9k.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070021#include "initvals.h"
22
Vasanthakumar Thiagarajan138ab2e2009-01-10 17:07:09 +053023static int btcoex_enable;
24module_param(btcoex_enable, bool, 0);
25MODULE_PARM_DESC(btcoex_enable, "Enable Bluetooth coexistence support");
26
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080027#define ATH9K_CLOCK_RATE_CCK 22
28#define ATH9K_CLOCK_RATE_5GHZ_OFDM 40
29#define ATH9K_CLOCK_RATE_2GHZ_OFDM 44
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070030
Sujithcbe61d82009-02-09 13:27:12 +053031static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type);
32static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan,
Sujithf1dc5602008-10-29 10:16:30 +053033 enum ath9k_ht_macmode macmode);
Sujithcbe61d82009-02-09 13:27:12 +053034static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +053035 struct ar5416_eeprom_def *pEepData,
Sujithf1dc5602008-10-29 10:16:30 +053036 u32 reg, u32 value);
Sujithcbe61d82009-02-09 13:27:12 +053037static void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan);
38static void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070039
Sujithf1dc5602008-10-29 10:16:30 +053040/********************/
41/* Helper Functions */
42/********************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070043
Sujithcbe61d82009-02-09 13:27:12 +053044static u32 ath9k_hw_mac_usec(struct ath_hw *ah, u32 clks)
Sujithf1dc5602008-10-29 10:16:30 +053045{
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080046 struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053047
Sujith2660b812009-02-09 13:27:26 +053048 if (!ah->curchan) /* should really check for CCK instead */
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080049 return clks / ATH9K_CLOCK_RATE_CCK;
50 if (conf->channel->band == IEEE80211_BAND_2GHZ)
51 return clks / ATH9K_CLOCK_RATE_2GHZ_OFDM;
Sujithcbe61d82009-02-09 13:27:12 +053052
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080053 return clks / ATH9K_CLOCK_RATE_5GHZ_OFDM;
Sujithf1dc5602008-10-29 10:16:30 +053054}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070055
Sujithcbe61d82009-02-09 13:27:12 +053056static u32 ath9k_hw_mac_to_usec(struct ath_hw *ah, u32 clks)
Sujithf1dc5602008-10-29 10:16:30 +053057{
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080058 struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053059
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080060 if (conf_is_ht40(conf))
Sujithf1dc5602008-10-29 10:16:30 +053061 return ath9k_hw_mac_usec(ah, clks) / 2;
62 else
63 return ath9k_hw_mac_usec(ah, clks);
64}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070065
Sujithcbe61d82009-02-09 13:27:12 +053066static u32 ath9k_hw_mac_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053067{
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080068 struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053069
Sujith2660b812009-02-09 13:27:26 +053070 if (!ah->curchan) /* should really check for CCK instead */
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080071 return usecs *ATH9K_CLOCK_RATE_CCK;
72 if (conf->channel->band == IEEE80211_BAND_2GHZ)
73 return usecs *ATH9K_CLOCK_RATE_2GHZ_OFDM;
74 return usecs *ATH9K_CLOCK_RATE_5GHZ_OFDM;
Sujithf1dc5602008-10-29 10:16:30 +053075}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070076
Sujithcbe61d82009-02-09 13:27:12 +053077static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053078{
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080079 struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053080
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080081 if (conf_is_ht40(conf))
Sujithf1dc5602008-10-29 10:16:30 +053082 return ath9k_hw_mac_clks(ah, usecs) * 2;
83 else
84 return ath9k_hw_mac_clks(ah, usecs);
85}
86
Sujithcbe61d82009-02-09 13:27:12 +053087bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070088{
89 int i;
90
91 for (i = 0; i < (AH_TIMEOUT / AH_TIME_QUANTUM); i++) {
92 if ((REG_READ(ah, reg) & mask) == val)
93 return true;
94
95 udelay(AH_TIME_QUANTUM);
96 }
Sujith04bd4632008-11-28 22:18:05 +053097
98 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
99 "timeout on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
100 reg, REG_READ(ah, reg), mask, val);
Sujithf1dc5602008-10-29 10:16:30 +0530101
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700102 return false;
103}
104
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700105u32 ath9k_hw_reverse_bits(u32 val, u32 n)
106{
107 u32 retval;
108 int i;
109
110 for (i = 0, retval = 0; i < n; i++) {
111 retval = (retval << 1) | (val & 1);
112 val >>= 1;
113 }
114 return retval;
115}
116
Sujithcbe61d82009-02-09 13:27:12 +0530117bool ath9k_get_channel_edges(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530118 u16 flags, u16 *low,
119 u16 *high)
120{
Sujith2660b812009-02-09 13:27:26 +0530121 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530122
123 if (flags & CHANNEL_5GHZ) {
124 *low = pCap->low_5ghz_chan;
125 *high = pCap->high_5ghz_chan;
126 return true;
127 }
128 if ((flags & CHANNEL_2GHZ)) {
129 *low = pCap->low_2ghz_chan;
130 *high = pCap->high_2ghz_chan;
131 return true;
132 }
133 return false;
134}
135
Sujithcbe61d82009-02-09 13:27:12 +0530136u16 ath9k_hw_computetxtime(struct ath_hw *ah,
Sujithe63835b2008-11-18 09:07:53 +0530137 struct ath_rate_table *rates,
Sujithf1dc5602008-10-29 10:16:30 +0530138 u32 frameLen, u16 rateix,
139 bool shortPreamble)
140{
141 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
142 u32 kbps;
143
Sujithe63835b2008-11-18 09:07:53 +0530144 kbps = rates->info[rateix].ratekbps;
Sujithf1dc5602008-10-29 10:16:30 +0530145
146 if (kbps == 0)
147 return 0;
148
149 switch (rates->info[rateix].phy) {
Sujith46d14a52008-11-18 09:08:13 +0530150 case WLAN_RC_PHY_CCK:
Sujithf1dc5602008-10-29 10:16:30 +0530151 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
Sujithe63835b2008-11-18 09:07:53 +0530152 if (shortPreamble && rates->info[rateix].short_preamble)
Sujithf1dc5602008-10-29 10:16:30 +0530153 phyTime >>= 1;
154 numBits = frameLen << 3;
155 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
156 break;
Sujith46d14a52008-11-18 09:08:13 +0530157 case WLAN_RC_PHY_OFDM:
Sujith2660b812009-02-09 13:27:26 +0530158 if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530159 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
160 numBits = OFDM_PLCP_BITS + (frameLen << 3);
161 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
162 txTime = OFDM_SIFS_TIME_QUARTER
163 + OFDM_PREAMBLE_TIME_QUARTER
164 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
Sujith2660b812009-02-09 13:27:26 +0530165 } else if (ah->curchan &&
166 IS_CHAN_HALF_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530167 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
168 numBits = OFDM_PLCP_BITS + (frameLen << 3);
169 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
170 txTime = OFDM_SIFS_TIME_HALF +
171 OFDM_PREAMBLE_TIME_HALF
172 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
173 } else {
174 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
175 numBits = OFDM_PLCP_BITS + (frameLen << 3);
176 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
177 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
178 + (numSymbols * OFDM_SYMBOL_TIME);
179 }
180 break;
181 default:
Sujith04bd4632008-11-28 22:18:05 +0530182 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
183 "Unknown phy %u (rate ix %u)\n",
Sujithf1dc5602008-10-29 10:16:30 +0530184 rates->info[rateix].phy, rateix);
185 txTime = 0;
186 break;
187 }
188
189 return txTime;
190}
191
Sujithcbe61d82009-02-09 13:27:12 +0530192void ath9k_hw_get_channel_centers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530193 struct ath9k_channel *chan,
194 struct chan_centers *centers)
195{
196 int8_t extoff;
Sujithf1dc5602008-10-29 10:16:30 +0530197
198 if (!IS_CHAN_HT40(chan)) {
199 centers->ctl_center = centers->ext_center =
200 centers->synth_center = chan->channel;
201 return;
202 }
203
204 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
205 (chan->chanmode == CHANNEL_G_HT40PLUS)) {
206 centers->synth_center =
207 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
208 extoff = 1;
209 } else {
210 centers->synth_center =
211 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
212 extoff = -1;
213 }
214
215 centers->ctl_center =
216 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
217 centers->ext_center =
218 centers->synth_center + (extoff *
Sujith2660b812009-02-09 13:27:26 +0530219 ((ah->extprotspacing == ATH9K_HT_EXTPROTSPACING_20) ?
Sujithf1dc5602008-10-29 10:16:30 +0530220 HT40_CHANNEL_CENTER_SHIFT : 15));
Sujithf1dc5602008-10-29 10:16:30 +0530221}
222
223/******************/
224/* Chip Revisions */
225/******************/
226
Sujithcbe61d82009-02-09 13:27:12 +0530227static void ath9k_hw_read_revisions(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530228{
229 u32 val;
230
231 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
232
233 if (val == 0xFF) {
234 val = REG_READ(ah, AR_SREV);
Sujithd535a422009-02-09 13:27:06 +0530235 ah->hw_version.macVersion =
236 (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
237 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
Sujith2660b812009-02-09 13:27:26 +0530238 ah->is_pciexpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
Sujithf1dc5602008-10-29 10:16:30 +0530239 } else {
240 if (!AR_SREV_9100(ah))
Sujithd535a422009-02-09 13:27:06 +0530241 ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
Sujithf1dc5602008-10-29 10:16:30 +0530242
Sujithd535a422009-02-09 13:27:06 +0530243 ah->hw_version.macRev = val & AR_SREV_REVISION;
Sujithf1dc5602008-10-29 10:16:30 +0530244
Sujithd535a422009-02-09 13:27:06 +0530245 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
Sujith2660b812009-02-09 13:27:26 +0530246 ah->is_pciexpress = true;
Sujithf1dc5602008-10-29 10:16:30 +0530247 }
248}
249
Sujithcbe61d82009-02-09 13:27:12 +0530250static int ath9k_hw_get_radiorev(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530251{
252 u32 val;
253 int i;
254
255 REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
256
257 for (i = 0; i < 8; i++)
258 REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
259 val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
260 val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
261
262 return ath9k_hw_reverse_bits(val, 8);
263}
264
265/************************************/
266/* HW Attach, Detach, Init Routines */
267/************************************/
268
Sujithcbe61d82009-02-09 13:27:12 +0530269static void ath9k_hw_disablepcie(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530270{
Sujithfeed0292009-01-29 11:37:35 +0530271 if (AR_SREV_9100(ah))
Sujithf1dc5602008-10-29 10:16:30 +0530272 return;
273
274 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
275 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
276 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
277 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
278 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
279 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
280 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
281 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
282 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
283
284 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
285}
286
Sujithcbe61d82009-02-09 13:27:12 +0530287static bool ath9k_hw_chip_test(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530288{
289 u32 regAddr[2] = { AR_STA_ID0, AR_PHY_BASE + (8 << 2) };
290 u32 regHold[2];
291 u32 patternData[4] = { 0x55555555,
292 0xaaaaaaaa,
293 0x66666666,
294 0x99999999 };
295 int i, j;
296
297 for (i = 0; i < 2; i++) {
298 u32 addr = regAddr[i];
299 u32 wrData, rdData;
300
301 regHold[i] = REG_READ(ah, addr);
302 for (j = 0; j < 0x100; j++) {
303 wrData = (j << 16) | j;
304 REG_WRITE(ah, addr, wrData);
305 rdData = REG_READ(ah, addr);
306 if (rdData != wrData) {
307 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
Sujith04bd4632008-11-28 22:18:05 +0530308 "address test failed "
Sujithf1dc5602008-10-29 10:16:30 +0530309 "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
Sujith04bd4632008-11-28 22:18:05 +0530310 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530311 return false;
312 }
313 }
314 for (j = 0; j < 4; j++) {
315 wrData = patternData[j];
316 REG_WRITE(ah, addr, wrData);
317 rdData = REG_READ(ah, addr);
318 if (wrData != rdData) {
319 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
Sujith04bd4632008-11-28 22:18:05 +0530320 "address test failed "
Sujithf1dc5602008-10-29 10:16:30 +0530321 "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
Sujith04bd4632008-11-28 22:18:05 +0530322 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";
Sujithf1dc5602008-10-29 10:16:30 +0530349 }
350
351 return NULL;
352}
353
Sujithcbe61d82009-02-09 13:27:12 +0530354static void ath9k_hw_set_defaults(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700355{
356 int i;
357
Sujith2660b812009-02-09 13:27:26 +0530358 ah->config.dma_beacon_response_time = 2;
359 ah->config.sw_beacon_response_time = 10;
360 ah->config.additional_swba_backoff = 0;
361 ah->config.ack_6mb = 0x0;
362 ah->config.cwm_ignore_extcca = 0;
363 ah->config.pcie_powersave_enable = 0;
364 ah->config.pcie_l1skp_enable = 0;
365 ah->config.pcie_clock_req = 0;
366 ah->config.pcie_power_reset = 0x100;
367 ah->config.pcie_restore = 0;
368 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;
376 ah->config.noise_immunity_level = 4;
377 ah->config.ofdm_weaksignal_det = 1;
378 ah->config.cck_weaksignal_thr = 0;
379 ah->config.spur_immunity_level = 2;
380 ah->config.firstep_level = 0;
381 ah->config.rssi_thr_high = 40;
382 ah->config.rssi_thr_low = 7;
383 ah->config.diversity_control = 0;
384 ah->config.antenna_switch_swap = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700385
386 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujith2660b812009-02-09 13:27:26 +0530387 ah->config.spurchans[i][0] = AR_NO_SPUR;
388 ah->config.spurchans[i][1] = AR_NO_SPUR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700389 }
390
Sujith2660b812009-02-09 13:27:26 +0530391 ah->config.intr_mitigation = 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700392}
393
Sujithcbe61d82009-02-09 13:27:12 +0530394static struct ath_hw *ath9k_hw_newstate(u16 devid, struct ath_softc *sc,
395 int *status)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700396{
Sujithcbe61d82009-02-09 13:27:12 +0530397 struct ath_hw *ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700398
Sujithcbe61d82009-02-09 13:27:12 +0530399 ah = kzalloc(sizeof(struct ath_hw), GFP_KERNEL);
400 if (ah == NULL) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700401 DPRINTF(sc, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +0530402 "Cannot allocate memory for state block\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700403 *status = -ENOMEM;
404 return NULL;
405 }
406
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700407 ah->ah_sc = sc;
Sujithd535a422009-02-09 13:27:06 +0530408 ah->hw_version.magic = AR5416_MAGIC;
Sujithd6bad492009-02-09 13:27:08 +0530409 ah->regulatory.country_code = CTRY_DEFAULT;
Sujithd535a422009-02-09 13:27:06 +0530410 ah->hw_version.devid = devid;
411 ah->hw_version.subvendorid = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700412
413 ah->ah_flags = 0;
414 if ((devid == AR5416_AR9100_DEVID))
Sujithd535a422009-02-09 13:27:06 +0530415 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700416 if (!AR_SREV_9100(ah))
417 ah->ah_flags = AH_USE_EEPROM;
418
Sujithd6bad492009-02-09 13:27:08 +0530419 ah->regulatory.power_limit = MAX_RATE_POWER;
420 ah->regulatory.tp_scale = ATH9K_TP_SCALE_MAX;
Sujith2660b812009-02-09 13:27:26 +0530421 ah->atim_window = 0;
422 ah->diversity_control = ah->config.diversity_control;
423 ah->antenna_switch_swap =
424 ah->config.antenna_switch_swap;
425 ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
426 ah->beacon_interval = 100;
427 ah->enable_32kHz_clock = DONT_USE_32KHZ;
428 ah->slottime = (u32) -1;
429 ah->acktimeout = (u32) -1;
430 ah->ctstimeout = (u32) -1;
431 ah->globaltxtimeout = (u32) -1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700432
Sujith2660b812009-02-09 13:27:26 +0530433 ah->gbeacon_rate = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700434
Sujithcbe61d82009-02-09 13:27:12 +0530435 return ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700436}
437
Sujithcbe61d82009-02-09 13:27:12 +0530438static int ath9k_hw_rfattach(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700439{
440 bool rfStatus = false;
441 int ecode = 0;
442
443 rfStatus = ath9k_hw_init_rf(ah, &ecode);
444 if (!rfStatus) {
445 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +0530446 "RF setup failed, status %u\n", ecode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700447 return ecode;
448 }
449
450 return 0;
451}
452
Sujithcbe61d82009-02-09 13:27:12 +0530453static int ath9k_hw_rf_claim(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700454{
455 u32 val;
456
457 REG_WRITE(ah, AR_PHY(0), 0x00000007);
458
459 val = ath9k_hw_get_radiorev(ah);
460 switch (val & AR_RADIO_SREV_MAJOR) {
461 case 0:
462 val = AR_RAD5133_SREV_MAJOR;
463 break;
464 case AR_RAD5133_SREV_MAJOR:
465 case AR_RAD5122_SREV_MAJOR:
466 case AR_RAD2133_SREV_MAJOR:
467 case AR_RAD2122_SREV_MAJOR:
468 break;
469 default:
470 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
Sujith04bd4632008-11-28 22:18:05 +0530471 "5G Radio Chip Rev 0x%02X is not "
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700472 "supported by this driver\n",
Sujithd535a422009-02-09 13:27:06 +0530473 ah->hw_version.analog5GhzRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700474 return -EOPNOTSUPP;
475 }
476
Sujithd535a422009-02-09 13:27:06 +0530477 ah->hw_version.analog5GhzRev = val;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700478
479 return 0;
480}
481
Sujithcbe61d82009-02-09 13:27:12 +0530482static int ath9k_hw_init_macaddr(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700483{
Sujithf1dc5602008-10-29 10:16:30 +0530484 u32 sum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700485 int i;
Sujithf1dc5602008-10-29 10:16:30 +0530486 u16 eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700487
Sujithf1dc5602008-10-29 10:16:30 +0530488 sum = 0;
489 for (i = 0; i < 3; i++) {
Sujithf74df6f2009-02-09 13:27:24 +0530490 eeval = ah->eep_ops->get_eeprom(ah, AR_EEPROM_MAC(i));
Sujithf1dc5602008-10-29 10:16:30 +0530491 sum += eeval;
Sujithba52da52009-02-09 13:27:10 +0530492 ah->macaddr[2 * i] = eeval >> 8;
493 ah->macaddr[2 * i + 1] = eeval & 0xff;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700494 }
Sujithf1dc5602008-10-29 10:16:30 +0530495 if (sum == 0 || sum == 0xffff * 3) {
496 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
Sujith04bd4632008-11-28 22:18:05 +0530497 "mac address read failed: %pM\n",
Sujithba52da52009-02-09 13:27:10 +0530498 ah->macaddr);
Sujithf1dc5602008-10-29 10:16:30 +0530499 return -EADDRNOTAVAIL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700500 }
501
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700502 return 0;
503}
504
Sujithcbe61d82009-02-09 13:27:12 +0530505static void ath9k_hw_init_rxgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530506{
507 u32 rxgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530508
Sujithf74df6f2009-02-09 13:27:24 +0530509 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_17) {
510 rxgain_type = ah->eep_ops->get_eeprom(ah, EEP_RXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530511
512 if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530513 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530514 ar9280Modes_backoff_13db_rxgain_9280_2,
515 ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2), 6);
516 else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530517 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530518 ar9280Modes_backoff_23db_rxgain_9280_2,
519 ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 6);
520 else
Sujith2660b812009-02-09 13:27:26 +0530521 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530522 ar9280Modes_original_rxgain_9280_2,
523 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530524 } else {
Sujith2660b812009-02-09 13:27:26 +0530525 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530526 ar9280Modes_original_rxgain_9280_2,
527 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530528 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530529}
530
Sujithcbe61d82009-02-09 13:27:12 +0530531static void ath9k_hw_init_txgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530532{
533 u32 txgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530534
Sujithf74df6f2009-02-09 13:27:24 +0530535 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_19) {
536 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530537
538 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
Sujith2660b812009-02-09 13:27:26 +0530539 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530540 ar9280Modes_high_power_tx_gain_9280_2,
541 ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 6);
542 else
Sujith2660b812009-02-09 13:27:26 +0530543 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530544 ar9280Modes_original_tx_gain_9280_2,
545 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530546 } else {
Sujith2660b812009-02-09 13:27:26 +0530547 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530548 ar9280Modes_original_tx_gain_9280_2,
549 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530550 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530551}
552
Sujithcbe61d82009-02-09 13:27:12 +0530553static int ath9k_hw_post_attach(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700554{
555 int ecode;
556
557 if (!ath9k_hw_chip_test(ah)) {
558 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
Sujith04bd4632008-11-28 22:18:05 +0530559 "hardware self-test failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700560 return -ENODEV;
561 }
562
563 ecode = ath9k_hw_rf_claim(ah);
564 if (ecode != 0)
565 return ecode;
566
567 ecode = ath9k_hw_eeprom_attach(ah);
568 if (ecode != 0)
569 return ecode;
570 ecode = ath9k_hw_rfattach(ah);
571 if (ecode != 0)
572 return ecode;
573
574 if (!AR_SREV_9100(ah)) {
575 ath9k_hw_ani_setup(ah);
576 ath9k_hw_ani_attach(ah);
577 }
Sujithf1dc5602008-10-29 10:16:30 +0530578
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700579 return 0;
580}
581
Sujithcbe61d82009-02-09 13:27:12 +0530582static struct ath_hw *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc,
583 int *status)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700584{
Sujithcbe61d82009-02-09 13:27:12 +0530585 struct ath_hw *ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700586 int ecode;
Sujithf6688cd2008-12-07 21:43:10 +0530587 u32 i, j;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700588
Sujithcbe61d82009-02-09 13:27:12 +0530589 ah = ath9k_hw_newstate(devid, sc, status);
590 if (ah == NULL)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700591 return NULL;
592
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700593 ath9k_hw_set_defaults(ah);
594
Sujith2660b812009-02-09 13:27:26 +0530595 if (ah->config.intr_mitigation != 0)
596 ah->intr_mitigation = true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700597
598 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Sujithcbe61d82009-02-09 13:27:12 +0530599 DPRINTF(sc, ATH_DBG_RESET, "Couldn't reset chip\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700600 ecode = -EIO;
601 goto bad;
602 }
603
604 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
Sujithcbe61d82009-02-09 13:27:12 +0530605 DPRINTF(sc, ATH_DBG_RESET, "Couldn't wakeup chip\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700606 ecode = -EIO;
607 goto bad;
608 }
609
Sujith2660b812009-02-09 13:27:26 +0530610 if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
Sujithd535a422009-02-09 13:27:06 +0530611 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI) {
Sujith2660b812009-02-09 13:27:26 +0530612 ah->config.serialize_regmode =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700613 SER_REG_MODE_ON;
614 } else {
Sujith2660b812009-02-09 13:27:26 +0530615 ah->config.serialize_regmode =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700616 SER_REG_MODE_OFF;
617 }
618 }
Sujithf1dc5602008-10-29 10:16:30 +0530619
Sujithcbe61d82009-02-09 13:27:12 +0530620 DPRINTF(sc, ATH_DBG_RESET, "serialize_regmode is %d\n",
Sujith2660b812009-02-09 13:27:26 +0530621 ah->config.serialize_regmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700622
Sujithd535a422009-02-09 13:27:06 +0530623 if ((ah->hw_version.macVersion != AR_SREV_VERSION_5416_PCI) &&
624 (ah->hw_version.macVersion != AR_SREV_VERSION_5416_PCIE) &&
625 (ah->hw_version.macVersion != AR_SREV_VERSION_9160) &&
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530626 (!AR_SREV_9100(ah)) && (!AR_SREV_9280(ah)) && (!AR_SREV_9285(ah))) {
Sujithcbe61d82009-02-09 13:27:12 +0530627 DPRINTF(sc, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +0530628 "Mac Chip Rev 0x%02x.%x is not supported by "
Sujithd535a422009-02-09 13:27:06 +0530629 "this driver\n", ah->hw_version.macVersion,
630 ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700631 ecode = -EOPNOTSUPP;
632 goto bad;
633 }
634
635 if (AR_SREV_9100(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530636 ah->iq_caldata.calData = &iq_cal_multi_sample;
637 ah->supp_cals = IQ_MISMATCH_CAL;
638 ah->is_pciexpress = false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700639 }
Sujithd535a422009-02-09 13:27:06 +0530640 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700641
642 if (AR_SREV_9160_10_OR_LATER(ah)) {
643 if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530644 ah->iq_caldata.calData = &iq_cal_single_sample;
645 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700646 &adc_gain_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530647 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700648 &adc_dc_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530649 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700650 &adc_init_dc_cal;
651 } else {
Sujith2660b812009-02-09 13:27:26 +0530652 ah->iq_caldata.calData = &iq_cal_multi_sample;
653 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700654 &adc_gain_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530655 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700656 &adc_dc_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530657 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700658 &adc_init_dc_cal;
659 }
Sujith2660b812009-02-09 13:27:26 +0530660 ah->supp_cals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700661 }
662
663 if (AR_SREV_9160(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530664 ah->config.enable_ani = 1;
665 ah->ani_function = (ATH9K_ANI_SPUR_IMMUNITY_LEVEL |
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700666 ATH9K_ANI_FIRSTEP_LEVEL);
667 } else {
Sujith2660b812009-02-09 13:27:26 +0530668 ah->ani_function = ATH9K_ANI_ALL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700669 if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530670 ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700671 }
672 }
673
Sujithcbe61d82009-02-09 13:27:12 +0530674 DPRINTF(sc, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +0530675 "This Mac Chip Rev 0x%02x.%x is \n",
Sujithd535a422009-02-09 13:27:06 +0530676 ah->hw_version.macVersion, ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700677
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530678 if (AR_SREV_9285_12_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530679 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530680 ARRAY_SIZE(ar9285Modes_9285_1_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530681 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530682 ARRAY_SIZE(ar9285Common_9285_1_2), 2);
683
Sujith2660b812009-02-09 13:27:26 +0530684 if (ah->config.pcie_clock_req) {
685 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530686 ar9285PciePhy_clkreq_off_L1_9285_1_2,
687 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2);
688 } else {
Sujith2660b812009-02-09 13:27:26 +0530689 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530690 ar9285PciePhy_clkreq_always_on_L1_9285_1_2,
691 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2),
692 2);
693 }
694 } else if (AR_SREV_9285_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530695 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530696 ARRAY_SIZE(ar9285Modes_9285), 6);
Sujith2660b812009-02-09 13:27:26 +0530697 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530698 ARRAY_SIZE(ar9285Common_9285), 2);
699
Sujith2660b812009-02-09 13:27:26 +0530700 if (ah->config.pcie_clock_req) {
701 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530702 ar9285PciePhy_clkreq_off_L1_9285,
703 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2);
704 } else {
Sujith2660b812009-02-09 13:27:26 +0530705 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530706 ar9285PciePhy_clkreq_always_on_L1_9285,
707 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285), 2);
708 }
709 } else if (AR_SREV_9280_20_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530710 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700711 ARRAY_SIZE(ar9280Modes_9280_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530712 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700713 ARRAY_SIZE(ar9280Common_9280_2), 2);
714
Sujith2660b812009-02-09 13:27:26 +0530715 if (ah->config.pcie_clock_req) {
716 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530717 ar9280PciePhy_clkreq_off_L1_9280,
718 ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700719 } else {
Sujith2660b812009-02-09 13:27:26 +0530720 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530721 ar9280PciePhy_clkreq_always_on_L1_9280,
722 ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700723 }
Sujith2660b812009-02-09 13:27:26 +0530724 INIT_INI_ARRAY(&ah->iniModesAdditional,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700725 ar9280Modes_fast_clock_9280_2,
Sujithf1dc5602008-10-29 10:16:30 +0530726 ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700727 } else if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530728 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700729 ARRAY_SIZE(ar9280Modes_9280), 6);
Sujith2660b812009-02-09 13:27:26 +0530730 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700731 ARRAY_SIZE(ar9280Common_9280), 2);
732 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530733 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700734 ARRAY_SIZE(ar5416Modes_9160), 6);
Sujith2660b812009-02-09 13:27:26 +0530735 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700736 ARRAY_SIZE(ar5416Common_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530737 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700738 ARRAY_SIZE(ar5416Bank0_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530739 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700740 ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530741 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700742 ARRAY_SIZE(ar5416Bank1_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530743 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700744 ARRAY_SIZE(ar5416Bank2_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530745 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700746 ARRAY_SIZE(ar5416Bank3_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530747 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700748 ARRAY_SIZE(ar5416Bank6_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530749 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700750 ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530751 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700752 ARRAY_SIZE(ar5416Bank7_9160), 2);
753 if (AR_SREV_9160_11(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530754 INIT_INI_ARRAY(&ah->iniAddac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700755 ar5416Addac_91601_1,
756 ARRAY_SIZE(ar5416Addac_91601_1), 2);
757 } else {
Sujith2660b812009-02-09 13:27:26 +0530758 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700759 ARRAY_SIZE(ar5416Addac_9160), 2);
760 }
761 } else if (AR_SREV_9100_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530762 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700763 ARRAY_SIZE(ar5416Modes_9100), 6);
Sujith2660b812009-02-09 13:27:26 +0530764 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700765 ARRAY_SIZE(ar5416Common_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530766 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700767 ARRAY_SIZE(ar5416Bank0_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530768 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700769 ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530770 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700771 ARRAY_SIZE(ar5416Bank1_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530772 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700773 ARRAY_SIZE(ar5416Bank2_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530774 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700775 ARRAY_SIZE(ar5416Bank3_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530776 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700777 ARRAY_SIZE(ar5416Bank6_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530778 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700779 ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530780 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700781 ARRAY_SIZE(ar5416Bank7_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530782 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700783 ARRAY_SIZE(ar5416Addac_9100), 2);
784 } else {
Sujith2660b812009-02-09 13:27:26 +0530785 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700786 ARRAY_SIZE(ar5416Modes), 6);
Sujith2660b812009-02-09 13:27:26 +0530787 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700788 ARRAY_SIZE(ar5416Common), 2);
Sujith2660b812009-02-09 13:27:26 +0530789 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700790 ARRAY_SIZE(ar5416Bank0), 2);
Sujith2660b812009-02-09 13:27:26 +0530791 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700792 ARRAY_SIZE(ar5416BB_RfGain), 3);
Sujith2660b812009-02-09 13:27:26 +0530793 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700794 ARRAY_SIZE(ar5416Bank1), 2);
Sujith2660b812009-02-09 13:27:26 +0530795 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700796 ARRAY_SIZE(ar5416Bank2), 2);
Sujith2660b812009-02-09 13:27:26 +0530797 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700798 ARRAY_SIZE(ar5416Bank3), 3);
Sujith2660b812009-02-09 13:27:26 +0530799 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700800 ARRAY_SIZE(ar5416Bank6), 3);
Sujith2660b812009-02-09 13:27:26 +0530801 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700802 ARRAY_SIZE(ar5416Bank6TPC), 3);
Sujith2660b812009-02-09 13:27:26 +0530803 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700804 ARRAY_SIZE(ar5416Bank7), 2);
Sujith2660b812009-02-09 13:27:26 +0530805 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700806 ARRAY_SIZE(ar5416Addac), 2);
807 }
808
Sujith2660b812009-02-09 13:27:26 +0530809 if (ah->is_pciexpress)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700810 ath9k_hw_configpcipowersave(ah, 0);
811 else
Sujithf1dc5602008-10-29 10:16:30 +0530812 ath9k_hw_disablepcie(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700813
814 ecode = ath9k_hw_post_attach(ah);
815 if (ecode != 0)
816 goto bad;
817
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530818 /* rxgain table */
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530819 if (AR_SREV_9280_20(ah))
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530820 ath9k_hw_init_rxgain_ini(ah);
821
822 /* txgain table */
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530823 if (AR_SREV_9280_20(ah))
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530824 ath9k_hw_init_txgain_ini(ah);
825
Sujith06d0f062009-02-12 10:06:45 +0530826 if (!ath9k_hw_fill_cap_info(ah)) {
827 DPRINTF(sc, ATH_DBG_RESET, "failed ath9k_hw_fill_cap_info\n");
828 ecode = -EINVAL;
829 goto bad;
830 }
831
832 if ((ah->hw_version.devid == AR9280_DEVID_PCI) &&
833 test_bit(ATH9K_MODE_11A, ah->caps.wireless_modes)) {
834
835 /* EEPROM Fixup */
Sujith2660b812009-02-09 13:27:26 +0530836 for (i = 0; i < ah->iniModes.ia_rows; i++) {
837 u32 reg = INI_RA(&ah->iniModes, i, 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700838
Sujith2660b812009-02-09 13:27:26 +0530839 for (j = 1; j < ah->iniModes.ia_columns; j++) {
840 u32 val = INI_RA(&ah->iniModes, i, j);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700841
Sujith2660b812009-02-09 13:27:26 +0530842 INI_RA(&ah->iniModes, i, j) =
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530843 ath9k_hw_ini_fixup(ah,
Sujith2660b812009-02-09 13:27:26 +0530844 &ah->eeprom.def,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700845 reg, val);
846 }
847 }
848 }
Sujithf6688cd2008-12-07 21:43:10 +0530849
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700850 ecode = ath9k_hw_init_macaddr(ah);
851 if (ecode != 0) {
Sujithcbe61d82009-02-09 13:27:12 +0530852 DPRINTF(sc, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +0530853 "failed initializing mac address\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700854 goto bad;
855 }
856
857 if (AR_SREV_9285(ah))
Sujith2660b812009-02-09 13:27:26 +0530858 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700859 else
Sujith2660b812009-02-09 13:27:26 +0530860 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700861
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700862 ath9k_init_nfcal_hist_buffer(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700863
864 return ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700865bad:
Sujithcbe61d82009-02-09 13:27:12 +0530866 if (ah)
867 ath9k_hw_detach(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700868 if (status)
869 *status = ecode;
Sujithf1dc5602008-10-29 10:16:30 +0530870
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700871 return NULL;
872}
873
Sujithcbe61d82009-02-09 13:27:12 +0530874static void ath9k_hw_init_bb(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530875 struct ath9k_channel *chan)
876{
877 u32 synthDelay;
878
879 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +0530880 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +0530881 synthDelay = (4 * synthDelay) / 22;
882 else
883 synthDelay /= 10;
884
885 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
886
887 udelay(synthDelay + BASE_ACTIVATE_DELAY);
888}
889
Sujithcbe61d82009-02-09 13:27:12 +0530890static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530891{
892 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
893 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
894
895 REG_WRITE(ah, AR_QOS_NO_ACK,
896 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
897 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
898 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
899
900 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
901 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
902 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
903 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
904 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
905}
906
Sujithcbe61d82009-02-09 13:27:12 +0530907static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530908 struct ath9k_channel *chan)
909{
910 u32 pll;
911
912 if (AR_SREV_9100(ah)) {
913 if (chan && IS_CHAN_5GHZ(chan))
914 pll = 0x1450;
915 else
916 pll = 0x1458;
917 } else {
918 if (AR_SREV_9280_10_OR_LATER(ah)) {
919 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
920
921 if (chan && IS_CHAN_HALF_RATE(chan))
922 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
923 else if (chan && IS_CHAN_QUARTER_RATE(chan))
924 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
925
926 if (chan && IS_CHAN_5GHZ(chan)) {
927 pll |= SM(0x28, AR_RTC_9160_PLL_DIV);
928
929
930 if (AR_SREV_9280_20(ah)) {
931 if (((chan->channel % 20) == 0)
932 || ((chan->channel % 10) == 0))
933 pll = 0x2850;
934 else
935 pll = 0x142c;
936 }
937 } else {
938 pll |= SM(0x2c, AR_RTC_9160_PLL_DIV);
939 }
940
941 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
942
943 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
944
945 if (chan && IS_CHAN_HALF_RATE(chan))
946 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
947 else if (chan && IS_CHAN_QUARTER_RATE(chan))
948 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
949
950 if (chan && IS_CHAN_5GHZ(chan))
951 pll |= SM(0x50, AR_RTC_9160_PLL_DIV);
952 else
953 pll |= SM(0x58, AR_RTC_9160_PLL_DIV);
954 } else {
955 pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2;
956
957 if (chan && IS_CHAN_HALF_RATE(chan))
958 pll |= SM(0x1, AR_RTC_PLL_CLKSEL);
959 else if (chan && IS_CHAN_QUARTER_RATE(chan))
960 pll |= SM(0x2, AR_RTC_PLL_CLKSEL);
961
962 if (chan && IS_CHAN_5GHZ(chan))
963 pll |= SM(0xa, AR_RTC_PLL_DIV);
964 else
965 pll |= SM(0xb, AR_RTC_PLL_DIV);
966 }
967 }
Gabor Juhosd03a66c2009-01-14 20:17:09 +0100968 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +0530969
970 udelay(RTC_PLL_SETTLE_DELAY);
971
972 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
973}
974
Sujithcbe61d82009-02-09 13:27:12 +0530975static void ath9k_hw_init_chain_masks(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530976{
Sujithf1dc5602008-10-29 10:16:30 +0530977 int rx_chainmask, tx_chainmask;
978
Sujith2660b812009-02-09 13:27:26 +0530979 rx_chainmask = ah->rxchainmask;
980 tx_chainmask = ah->txchainmask;
Sujithf1dc5602008-10-29 10:16:30 +0530981
982 switch (rx_chainmask) {
983 case 0x5:
984 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
985 AR_PHY_SWAP_ALT_CHAIN);
986 case 0x3:
Sujithd535a422009-02-09 13:27:06 +0530987 if (((ah)->hw_version.macVersion <= AR_SREV_VERSION_9160)) {
Sujithf1dc5602008-10-29 10:16:30 +0530988 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7);
989 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7);
990 break;
991 }
992 case 0x1:
993 case 0x2:
Sujithf1dc5602008-10-29 10:16:30 +0530994 case 0x7:
995 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
996 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
997 break;
998 default:
999 break;
1000 }
1001
1002 REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);
1003 if (tx_chainmask == 0x5) {
1004 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1005 AR_PHY_SWAP_ALT_CHAIN);
1006 }
1007 if (AR_SREV_9100(ah))
1008 REG_WRITE(ah, AR_PHY_ANALOG_SWAP,
1009 REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
1010}
1011
Sujithcbe61d82009-02-09 13:27:12 +05301012static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -08001013 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301014{
Sujith2660b812009-02-09 13:27:26 +05301015 ah->mask_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +05301016 AR_IMR_TXURN |
1017 AR_IMR_RXERR |
1018 AR_IMR_RXORN |
1019 AR_IMR_BCNMISC;
1020
Sujith2660b812009-02-09 13:27:26 +05301021 if (ah->intr_mitigation)
1022 ah->mask_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
Sujithf1dc5602008-10-29 10:16:30 +05301023 else
Sujith2660b812009-02-09 13:27:26 +05301024 ah->mask_reg |= AR_IMR_RXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301025
Sujith2660b812009-02-09 13:27:26 +05301026 ah->mask_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301027
Colin McCabed97809d2008-12-01 13:38:55 -08001028 if (opmode == NL80211_IFTYPE_AP)
Sujith2660b812009-02-09 13:27:26 +05301029 ah->mask_reg |= AR_IMR_MIB;
Sujithf1dc5602008-10-29 10:16:30 +05301030
Sujith2660b812009-02-09 13:27:26 +05301031 REG_WRITE(ah, AR_IMR, ah->mask_reg);
Sujithf1dc5602008-10-29 10:16:30 +05301032 REG_WRITE(ah, AR_IMR_S2, REG_READ(ah, AR_IMR_S2) | AR_IMR_S2_GTT);
1033
1034 if (!AR_SREV_9100(ah)) {
1035 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
1036 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
1037 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
1038 }
1039}
1040
Sujithcbe61d82009-02-09 13:27:12 +05301041static bool ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301042{
Sujithf1dc5602008-10-29 10:16:30 +05301043 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) {
Sujith04bd4632008-11-28 22:18:05 +05301044 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "bad ack timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301045 ah->acktimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301046 return false;
1047 } else {
1048 REG_RMW_FIELD(ah, AR_TIME_OUT,
1049 AR_TIME_OUT_ACK, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301050 ah->acktimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301051 return true;
1052 }
1053}
1054
Sujithcbe61d82009-02-09 13:27:12 +05301055static bool ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301056{
Sujithf1dc5602008-10-29 10:16:30 +05301057 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_CTS))) {
Sujith04bd4632008-11-28 22:18:05 +05301058 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "bad cts timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301059 ah->ctstimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301060 return false;
1061 } else {
1062 REG_RMW_FIELD(ah, AR_TIME_OUT,
1063 AR_TIME_OUT_CTS, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301064 ah->ctstimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301065 return true;
1066 }
1067}
1068
Sujithcbe61d82009-02-09 13:27:12 +05301069static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +05301070{
Sujithf1dc5602008-10-29 10:16:30 +05301071 if (tu > 0xFFFF) {
1072 DPRINTF(ah->ah_sc, ATH_DBG_XMIT,
Sujith04bd4632008-11-28 22:18:05 +05301073 "bad global tx timeout %u\n", tu);
Sujith2660b812009-02-09 13:27:26 +05301074 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301075 return false;
1076 } else {
1077 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +05301078 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +05301079 return true;
1080 }
1081}
1082
Sujithcbe61d82009-02-09 13:27:12 +05301083static void ath9k_hw_init_user_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301084{
Sujith2660b812009-02-09 13:27:26 +05301085 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
1086 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +05301087
Sujith2660b812009-02-09 13:27:26 +05301088 if (ah->misc_mode != 0)
Sujithf1dc5602008-10-29 10:16:30 +05301089 REG_WRITE(ah, AR_PCU_MISC,
Sujith2660b812009-02-09 13:27:26 +05301090 REG_READ(ah, AR_PCU_MISC) | ah->misc_mode);
1091 if (ah->slottime != (u32) -1)
1092 ath9k_hw_setslottime(ah, ah->slottime);
1093 if (ah->acktimeout != (u32) -1)
1094 ath9k_hw_set_ack_timeout(ah, ah->acktimeout);
1095 if (ah->ctstimeout != (u32) -1)
1096 ath9k_hw_set_cts_timeout(ah, ah->ctstimeout);
1097 if (ah->globaltxtimeout != (u32) -1)
1098 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Sujithf1dc5602008-10-29 10:16:30 +05301099}
1100
1101const char *ath9k_hw_probe(u16 vendorid, u16 devid)
1102{
1103 return vendorid == ATHEROS_VENDOR_ID ?
1104 ath9k_hw_devname(devid) : NULL;
1105}
1106
Sujithcbe61d82009-02-09 13:27:12 +05301107void ath9k_hw_detach(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001108{
1109 if (!AR_SREV_9100(ah))
1110 ath9k_hw_ani_detach(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001111
Sujithf1dc5602008-10-29 10:16:30 +05301112 ath9k_hw_rfdetach(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001113 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
1114 kfree(ah);
1115}
1116
Sujithcbe61d82009-02-09 13:27:12 +05301117struct ath_hw *ath9k_hw_attach(u16 devid, struct ath_softc *sc, int *error)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001118{
Sujithcbe61d82009-02-09 13:27:12 +05301119 struct ath_hw *ah = NULL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001120
Sujithf1dc5602008-10-29 10:16:30 +05301121 switch (devid) {
1122 case AR5416_DEVID_PCI:
1123 case AR5416_DEVID_PCIE:
Gabor Juhos0c1aa492009-01-14 20:17:12 +01001124 case AR5416_AR9100_DEVID:
Sujithf1dc5602008-10-29 10:16:30 +05301125 case AR9160_DEVID_PCI:
1126 case AR9280_DEVID_PCI:
1127 case AR9280_DEVID_PCIE:
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301128 case AR9285_DEVID_PCIE:
Sujithcbe61d82009-02-09 13:27:12 +05301129 ah = ath9k_hw_do_attach(devid, sc, error);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001130 break;
Sujithf1dc5602008-10-29 10:16:30 +05301131 default:
Sujithf1dc5602008-10-29 10:16:30 +05301132 *error = -ENXIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001133 break;
1134 }
1135
Sujithf1dc5602008-10-29 10:16:30 +05301136 return ah;
1137}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001138
Sujithf1dc5602008-10-29 10:16:30 +05301139/*******/
1140/* INI */
1141/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001142
Sujithcbe61d82009-02-09 13:27:12 +05301143static void ath9k_hw_override_ini(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301144 struct ath9k_channel *chan)
1145{
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +05301146 /*
1147 * Set the RX_ABORT and RX_DIS and clear if off only after
1148 * RXE is set for MAC. This prevents frames with corrupted
1149 * descriptor status.
1150 */
1151 REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
1152
1153
Sujithf1dc5602008-10-29 10:16:30 +05301154 if (!AR_SREV_5416_V20_OR_LATER(ah) ||
1155 AR_SREV_9280_10_OR_LATER(ah))
1156 return;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001157
Sujithf1dc5602008-10-29 10:16:30 +05301158 REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
1159}
1160
Sujithcbe61d82009-02-09 13:27:12 +05301161static u32 ath9k_hw_def_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301162 struct ar5416_eeprom_def *pEepData,
Sujithf1dc5602008-10-29 10:16:30 +05301163 u32 reg, u32 value)
1164{
1165 struct base_eep_header *pBase = &(pEepData->baseEepHeader);
1166
Sujithd535a422009-02-09 13:27:06 +05301167 switch (ah->hw_version.devid) {
Sujithf1dc5602008-10-29 10:16:30 +05301168 case AR9280_DEVID_PCI:
1169 if (reg == 0x7894) {
1170 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
1171 "ini VAL: %x EEPROM: %x\n", value,
1172 (pBase->version & 0xff));
1173
1174 if ((pBase->version & 0xff) > 0x0a) {
1175 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
1176 "PWDCLKIND: %d\n",
1177 pBase->pwdclkind);
1178 value &= ~AR_AN_TOP2_PWDCLKIND;
1179 value |= AR_AN_TOP2_PWDCLKIND &
1180 (pBase->pwdclkind << AR_AN_TOP2_PWDCLKIND_S);
1181 } else {
1182 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
1183 "PWDCLKIND Earlier Rev\n");
1184 }
1185
1186 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
1187 "final ini VAL: %x\n", value);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001188 }
Sujithf1dc5602008-10-29 10:16:30 +05301189 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001190 }
1191
Sujithf1dc5602008-10-29 10:16:30 +05301192 return value;
1193}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001194
Sujithcbe61d82009-02-09 13:27:12 +05301195static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301196 struct ar5416_eeprom_def *pEepData,
1197 u32 reg, u32 value)
1198{
Sujith2660b812009-02-09 13:27:26 +05301199 if (ah->eep_map == EEP_MAP_4KBITS)
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301200 return value;
1201 else
1202 return ath9k_hw_def_ini_fixup(ah, pEepData, reg, value);
1203}
1204
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301205static void ath9k_olc_init(struct ath_hw *ah)
1206{
1207 u32 i;
1208
1209 for (i = 0; i < AR9280_TX_GAIN_TABLE_SIZE; i++)
1210 ah->originalGain[i] =
1211 MS(REG_READ(ah, AR_PHY_TX_GAIN_TBL1 + i * 4),
1212 AR_PHY_TX_GAIN);
1213 ah->PDADCdelta = 0;
1214}
1215
Sujithcbe61d82009-02-09 13:27:12 +05301216static int ath9k_hw_process_ini(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301217 struct ath9k_channel *chan,
1218 enum ath9k_ht_macmode macmode)
1219{
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301220#define OLC_FOR_AR9280_20_LATER (AR_SREV_9280_20_OR_LATER(ah) && \
1221 ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
Sujithf1dc5602008-10-29 10:16:30 +05301222 int i, regWrites = 0;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001223 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301224 u32 modesIndex, freqIndex;
1225 int status;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001226
Sujithf1dc5602008-10-29 10:16:30 +05301227 switch (chan->chanmode) {
1228 case CHANNEL_A:
1229 case CHANNEL_A_HT20:
1230 modesIndex = 1;
1231 freqIndex = 1;
1232 break;
1233 case CHANNEL_A_HT40PLUS:
1234 case CHANNEL_A_HT40MINUS:
1235 modesIndex = 2;
1236 freqIndex = 1;
1237 break;
1238 case CHANNEL_G:
1239 case CHANNEL_G_HT20:
1240 case CHANNEL_B:
1241 modesIndex = 4;
1242 freqIndex = 2;
1243 break;
1244 case CHANNEL_G_HT40PLUS:
1245 case CHANNEL_G_HT40MINUS:
1246 modesIndex = 3;
1247 freqIndex = 2;
1248 break;
1249
1250 default:
1251 return -EINVAL;
1252 }
1253
1254 REG_WRITE(ah, AR_PHY(0), 0x00000007);
Sujithf1dc5602008-10-29 10:16:30 +05301255 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
Sujithf74df6f2009-02-09 13:27:24 +05301256 ah->eep_ops->set_addac(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301257
1258 if (AR_SREV_5416_V22_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +05301259 REG_WRITE_ARRAY(&ah->iniAddac, 1, regWrites);
Sujithf1dc5602008-10-29 10:16:30 +05301260 } else {
1261 struct ar5416IniArray temp;
1262 u32 addacSize =
Sujith2660b812009-02-09 13:27:26 +05301263 sizeof(u32) * ah->iniAddac.ia_rows *
1264 ah->iniAddac.ia_columns;
Sujithf1dc5602008-10-29 10:16:30 +05301265
Sujith2660b812009-02-09 13:27:26 +05301266 memcpy(ah->addac5416_21,
1267 ah->iniAddac.ia_array, addacSize);
Sujithf1dc5602008-10-29 10:16:30 +05301268
Sujith2660b812009-02-09 13:27:26 +05301269 (ah->addac5416_21)[31 * ah->iniAddac.ia_columns + 1] = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301270
Sujith2660b812009-02-09 13:27:26 +05301271 temp.ia_array = ah->addac5416_21;
1272 temp.ia_columns = ah->iniAddac.ia_columns;
1273 temp.ia_rows = ah->iniAddac.ia_rows;
Sujithf1dc5602008-10-29 10:16:30 +05301274 REG_WRITE_ARRAY(&temp, 1, regWrites);
1275 }
1276
1277 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
1278
Sujith2660b812009-02-09 13:27:26 +05301279 for (i = 0; i < ah->iniModes.ia_rows; i++) {
1280 u32 reg = INI_RA(&ah->iniModes, i, 0);
1281 u32 val = INI_RA(&ah->iniModes, i, modesIndex);
Sujithf1dc5602008-10-29 10:16:30 +05301282
Sujithf1dc5602008-10-29 10:16:30 +05301283 REG_WRITE(ah, reg, val);
1284
1285 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301286 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301287 udelay(100);
1288 }
1289
1290 DO_DELAY(regWrites);
1291 }
1292
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301293 if (AR_SREV_9280(ah))
Sujith2660b812009-02-09 13:27:26 +05301294 REG_WRITE_ARRAY(&ah->iniModesRxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301295
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301296 if (AR_SREV_9280(ah))
Sujith2660b812009-02-09 13:27:26 +05301297 REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301298
Sujith2660b812009-02-09 13:27:26 +05301299 for (i = 0; i < ah->iniCommon.ia_rows; i++) {
1300 u32 reg = INI_RA(&ah->iniCommon, i, 0);
1301 u32 val = INI_RA(&ah->iniCommon, i, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301302
1303 REG_WRITE(ah, reg, val);
1304
1305 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301306 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301307 udelay(100);
1308 }
1309
1310 DO_DELAY(regWrites);
1311 }
1312
1313 ath9k_hw_write_regs(ah, modesIndex, freqIndex, regWrites);
1314
1315 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan)) {
Sujith2660b812009-02-09 13:27:26 +05301316 REG_WRITE_ARRAY(&ah->iniModesAdditional, modesIndex,
Sujithf1dc5602008-10-29 10:16:30 +05301317 regWrites);
1318 }
1319
1320 ath9k_hw_override_ini(ah, chan);
1321 ath9k_hw_set_regs(ah, chan, macmode);
1322 ath9k_hw_init_chain_masks(ah);
1323
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301324 if (OLC_FOR_AR9280_20_LATER)
1325 ath9k_olc_init(ah);
1326
Sujithf74df6f2009-02-09 13:27:24 +05301327 status = ah->eep_ops->set_txpower(ah, chan,
1328 ath9k_regd_get_ctl(ah, chan),
1329 channel->max_antenna_gain * 2,
1330 channel->max_power * 2,
1331 min((u32) MAX_RATE_POWER,
1332 (u32) ah->regulatory.power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05301333 if (status != 0) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001334 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
Sujith04bd4632008-11-28 22:18:05 +05301335 "error init'ing transmit power\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001336 return -EIO;
1337 }
1338
Sujithf1dc5602008-10-29 10:16:30 +05301339 if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
1340 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
Sujith04bd4632008-11-28 22:18:05 +05301341 "ar5416SetRfRegs failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001342 return -EIO;
1343 }
1344
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001345 return 0;
1346}
1347
Sujithf1dc5602008-10-29 10:16:30 +05301348/****************************************/
1349/* Reset and Channel Switching Routines */
1350/****************************************/
1351
Sujithcbe61d82009-02-09 13:27:12 +05301352static void ath9k_hw_set_rfmode(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301353{
1354 u32 rfMode = 0;
1355
1356 if (chan == NULL)
1357 return;
1358
1359 rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
1360 ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
1361
1362 if (!AR_SREV_9280_10_OR_LATER(ah))
1363 rfMode |= (IS_CHAN_5GHZ(chan)) ?
1364 AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ;
1365
1366 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan))
1367 rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
1368
1369 REG_WRITE(ah, AR_PHY_MODE, rfMode);
1370}
1371
Sujithcbe61d82009-02-09 13:27:12 +05301372static void ath9k_hw_mark_phy_inactive(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301373{
1374 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
1375}
1376
Sujithcbe61d82009-02-09 13:27:12 +05301377static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301378{
1379 u32 regval;
1380
1381 regval = REG_READ(ah, AR_AHB_MODE);
1382 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
1383
1384 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
1385 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
1386
Sujith2660b812009-02-09 13:27:26 +05301387 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +05301388
1389 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
1390 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
1391
1392 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1393
1394 if (AR_SREV_9285(ah)) {
1395 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1396 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
1397 } else {
1398 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1399 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1400 }
1401}
1402
Sujithcbe61d82009-02-09 13:27:12 +05301403static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301404{
1405 u32 val;
1406
1407 val = REG_READ(ah, AR_STA_ID1);
1408 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
1409 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001410 case NL80211_IFTYPE_AP:
Sujithf1dc5602008-10-29 10:16:30 +05301411 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
1412 | AR_STA_ID1_KSRCH_MODE);
1413 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1414 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001415 case NL80211_IFTYPE_ADHOC:
Sujithf1dc5602008-10-29 10:16:30 +05301416 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
1417 | AR_STA_ID1_KSRCH_MODE);
1418 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1419 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001420 case NL80211_IFTYPE_STATION:
1421 case NL80211_IFTYPE_MONITOR:
Sujithf1dc5602008-10-29 10:16:30 +05301422 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
1423 break;
1424 }
1425}
1426
Sujithcbe61d82009-02-09 13:27:12 +05301427static inline void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001428 u32 coef_scaled,
1429 u32 *coef_mantissa,
1430 u32 *coef_exponent)
1431{
1432 u32 coef_exp, coef_man;
1433
1434 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1435 if ((coef_scaled >> coef_exp) & 0x1)
1436 break;
1437
1438 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1439
1440 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1441
1442 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1443 *coef_exponent = coef_exp - 16;
1444}
1445
Sujithcbe61d82009-02-09 13:27:12 +05301446static void ath9k_hw_set_delta_slope(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301447 struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001448{
1449 u32 coef_scaled, ds_coef_exp, ds_coef_man;
1450 u32 clockMhzScaled = 0x64000000;
1451 struct chan_centers centers;
1452
1453 if (IS_CHAN_HALF_RATE(chan))
1454 clockMhzScaled = clockMhzScaled >> 1;
1455 else if (IS_CHAN_QUARTER_RATE(chan))
1456 clockMhzScaled = clockMhzScaled >> 2;
1457
1458 ath9k_hw_get_channel_centers(ah, chan, &centers);
1459 coef_scaled = clockMhzScaled / centers.synth_center;
1460
1461 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1462 &ds_coef_exp);
1463
1464 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1465 AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
1466 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1467 AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
1468
1469 coef_scaled = (9 * coef_scaled) / 10;
1470
1471 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1472 &ds_coef_exp);
1473
1474 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1475 AR_PHY_HALFGI_DSC_MAN, ds_coef_man);
1476 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1477 AR_PHY_HALFGI_DSC_EXP, ds_coef_exp);
1478}
1479
Sujithcbe61d82009-02-09 13:27:12 +05301480static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +05301481{
1482 u32 rst_flags;
1483 u32 tmpReg;
1484
Sujith70768492009-02-16 13:23:12 +05301485 if (AR_SREV_9100(ah)) {
1486 u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK);
1487 val &= ~AR_RTC_DERIVED_CLK_PERIOD;
1488 val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD);
1489 REG_WRITE(ah, AR_RTC_DERIVED_CLK, val);
1490 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1491 }
1492
Sujithf1dc5602008-10-29 10:16:30 +05301493 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1494 AR_RTC_FORCE_WAKE_ON_INT);
1495
1496 if (AR_SREV_9100(ah)) {
1497 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1498 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1499 } else {
1500 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1501 if (tmpReg &
1502 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1503 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
1504 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
1505 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1506 } else {
1507 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1508 }
1509
1510 rst_flags = AR_RTC_RC_MAC_WARM;
1511 if (type == ATH9K_RESET_COLD)
1512 rst_flags |= AR_RTC_RC_MAC_COLD;
1513 }
1514
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001515 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujithf1dc5602008-10-29 10:16:30 +05301516 udelay(50);
1517
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001518 REG_WRITE(ah, AR_RTC_RC, 0);
1519 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0)) {
Sujithf1dc5602008-10-29 10:16:30 +05301520 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05301521 "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301522 return false;
1523 }
1524
1525 if (!AR_SREV_9100(ah))
1526 REG_WRITE(ah, AR_RC, 0);
1527
1528 ath9k_hw_init_pll(ah, NULL);
1529
1530 if (AR_SREV_9100(ah))
1531 udelay(50);
1532
1533 return true;
1534}
1535
Sujithcbe61d82009-02-09 13:27:12 +05301536static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301537{
1538 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1539 AR_RTC_FORCE_WAKE_ON_INT);
1540
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001541 REG_WRITE(ah, AR_RTC_RESET, 0);
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301542 udelay(2);
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001543 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301544
1545 if (!ath9k_hw_wait(ah,
1546 AR_RTC_STATUS,
1547 AR_RTC_STATUS_M,
1548 AR_RTC_STATUS_ON)) {
Sujith04bd4632008-11-28 22:18:05 +05301549 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301550 return false;
1551 }
1552
1553 ath9k_hw_read_revisions(ah);
1554
1555 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1556}
1557
Sujithcbe61d82009-02-09 13:27:12 +05301558static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301559{
1560 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1561 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1562
1563 switch (type) {
1564 case ATH9K_RESET_POWER_ON:
1565 return ath9k_hw_set_reset_power_on(ah);
1566 break;
1567 case ATH9K_RESET_WARM:
1568 case ATH9K_RESET_COLD:
1569 return ath9k_hw_set_reset(ah, type);
1570 break;
1571 default:
1572 return false;
1573 }
1574}
1575
Sujithcbe61d82009-02-09 13:27:12 +05301576static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan,
Sujithf1dc5602008-10-29 10:16:30 +05301577 enum ath9k_ht_macmode macmode)
1578{
1579 u32 phymode;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301580 u32 enableDacFifo = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301581
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301582 if (AR_SREV_9285_10_OR_LATER(ah))
1583 enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) &
1584 AR_PHY_FC_ENABLE_DAC_FIFO);
1585
Sujithf1dc5602008-10-29 10:16:30 +05301586 phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301587 | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo;
Sujithf1dc5602008-10-29 10:16:30 +05301588
1589 if (IS_CHAN_HT40(chan)) {
1590 phymode |= AR_PHY_FC_DYN2040_EN;
1591
1592 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
1593 (chan->chanmode == CHANNEL_G_HT40PLUS))
1594 phymode |= AR_PHY_FC_DYN2040_PRI_CH;
1595
Sujith2660b812009-02-09 13:27:26 +05301596 if (ah->extprotspacing == ATH9K_HT_EXTPROTSPACING_25)
Sujithf1dc5602008-10-29 10:16:30 +05301597 phymode |= AR_PHY_FC_DYN2040_EXT_CH;
1598 }
1599 REG_WRITE(ah, AR_PHY_TURBO, phymode);
1600
1601 ath9k_hw_set11nmac2040(ah, macmode);
1602
1603 REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
1604 REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
1605}
1606
Sujithcbe61d82009-02-09 13:27:12 +05301607static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301608 struct ath9k_channel *chan)
1609{
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301610 if (OLC_FOR_AR9280_20_LATER) {
1611 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
1612 return false;
1613 } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
Sujithf1dc5602008-10-29 10:16:30 +05301614 return false;
1615
1616 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
1617 return false;
1618
Sujith2660b812009-02-09 13:27:26 +05301619 ah->chip_fullsleep = false;
Sujithf1dc5602008-10-29 10:16:30 +05301620 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301621 ath9k_hw_set_rfmode(ah, chan);
1622
1623 return true;
1624}
1625
Sujithcbe61d82009-02-09 13:27:12 +05301626static bool ath9k_hw_channel_change(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301627 struct ath9k_channel *chan,
1628 enum ath9k_ht_macmode macmode)
1629{
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001630 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301631 u32 synthDelay, qnum;
1632
1633 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1634 if (ath9k_hw_numtxpending(ah, qnum)) {
1635 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
Sujith04bd4632008-11-28 22:18:05 +05301636 "Transmit frames pending on queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301637 return false;
1638 }
1639 }
1640
1641 REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
1642 if (!ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
1643 AR_PHY_RFBUS_GRANT_EN)) {
Sujith04bd4632008-11-28 22:18:05 +05301644 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
1645 "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301646 return false;
1647 }
1648
1649 ath9k_hw_set_regs(ah, chan, macmode);
1650
1651 if (AR_SREV_9280_10_OR_LATER(ah)) {
1652 if (!(ath9k_hw_ar9280_set_channel(ah, chan))) {
1653 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
Sujith04bd4632008-11-28 22:18:05 +05301654 "failed to set channel\n");
Sujithf1dc5602008-10-29 10:16:30 +05301655 return false;
1656 }
1657 } else {
1658 if (!(ath9k_hw_set_channel(ah, chan))) {
1659 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
Sujith04bd4632008-11-28 22:18:05 +05301660 "failed to set channel\n");
Sujithf1dc5602008-10-29 10:16:30 +05301661 return false;
1662 }
1663 }
1664
Sujithf74df6f2009-02-09 13:27:24 +05301665 if (ah->eep_ops->set_txpower(ah, chan,
1666 ath9k_regd_get_ctl(ah, chan),
1667 channel->max_antenna_gain * 2,
1668 channel->max_power * 2,
1669 min((u32) MAX_RATE_POWER,
1670 (u32) ah->regulatory.power_limit)) != 0) {
Sujithf1dc5602008-10-29 10:16:30 +05301671 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
Sujith04bd4632008-11-28 22:18:05 +05301672 "error init'ing transmit power\n");
Sujithf1dc5602008-10-29 10:16:30 +05301673 return false;
1674 }
1675
1676 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +05301677 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +05301678 synthDelay = (4 * synthDelay) / 22;
1679 else
1680 synthDelay /= 10;
1681
1682 udelay(synthDelay + BASE_ACTIVATE_DELAY);
1683
1684 REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
1685
1686 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1687 ath9k_hw_set_delta_slope(ah, chan);
1688
1689 if (AR_SREV_9280_10_OR_LATER(ah))
1690 ath9k_hw_9280_spur_mitigate(ah, chan);
1691 else
1692 ath9k_hw_spur_mitigate(ah, chan);
1693
1694 if (!chan->oneTimeCalsDone)
1695 chan->oneTimeCalsDone = true;
1696
1697 return true;
1698}
1699
Sujithcbe61d82009-02-09 13:27:12 +05301700static void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001701{
1702 int bb_spur = AR_NO_SPUR;
1703 int freq;
1704 int bin, cur_bin;
1705 int bb_spur_off, spur_subchannel_sd;
1706 int spur_freq_sd;
1707 int spur_delta_phase;
1708 int denominator;
1709 int upper, lower, cur_vit_mask;
1710 int tmp, newVal;
1711 int i;
1712 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
1713 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
1714 };
1715 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
1716 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
1717 };
1718 int inc[4] = { 0, 100, 0, 0 };
1719 struct chan_centers centers;
1720
1721 int8_t mask_m[123];
1722 int8_t mask_p[123];
1723 int8_t mask_amt;
1724 int tmp_mask;
1725 int cur_bb_spur;
1726 bool is2GHz = IS_CHAN_2GHZ(chan);
1727
1728 memset(&mask_m, 0, sizeof(int8_t) * 123);
1729 memset(&mask_p, 0, sizeof(int8_t) * 123);
1730
1731 ath9k_hw_get_channel_centers(ah, chan, &centers);
1732 freq = centers.synth_center;
1733
Sujith2660b812009-02-09 13:27:26 +05301734 ah->config.spurmode = SPUR_ENABLE_EEPROM;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001735 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujithf74df6f2009-02-09 13:27:24 +05301736 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001737
1738 if (is2GHz)
1739 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_2GHZ;
1740 else
1741 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_5GHZ;
1742
1743 if (AR_NO_SPUR == cur_bb_spur)
1744 break;
1745 cur_bb_spur = cur_bb_spur - freq;
1746
1747 if (IS_CHAN_HT40(chan)) {
1748 if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT40) &&
1749 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT40)) {
1750 bb_spur = cur_bb_spur;
1751 break;
1752 }
1753 } else if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT20) &&
1754 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT20)) {
1755 bb_spur = cur_bb_spur;
1756 break;
1757 }
1758 }
1759
1760 if (AR_NO_SPUR == bb_spur) {
1761 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1762 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1763 return;
1764 } else {
1765 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1766 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1767 }
1768
1769 bin = bb_spur * 320;
1770
1771 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
1772
1773 newVal = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
1774 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
1775 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
1776 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
1777 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), newVal);
1778
1779 newVal = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
1780 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
1781 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
1782 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
1783 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
1784 REG_WRITE(ah, AR_PHY_SPUR_REG, newVal);
1785
1786 if (IS_CHAN_HT40(chan)) {
1787 if (bb_spur < 0) {
1788 spur_subchannel_sd = 1;
1789 bb_spur_off = bb_spur + 10;
1790 } else {
1791 spur_subchannel_sd = 0;
1792 bb_spur_off = bb_spur - 10;
1793 }
1794 } else {
1795 spur_subchannel_sd = 0;
1796 bb_spur_off = bb_spur;
1797 }
1798
1799 if (IS_CHAN_HT40(chan))
1800 spur_delta_phase =
1801 ((bb_spur * 262144) /
1802 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
1803 else
1804 spur_delta_phase =
1805 ((bb_spur * 524288) /
1806 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
1807
1808 denominator = IS_CHAN_2GHZ(chan) ? 44 : 40;
1809 spur_freq_sd = ((bb_spur_off * 2048) / denominator) & 0x3ff;
1810
1811 newVal = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
1812 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
1813 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
1814 REG_WRITE(ah, AR_PHY_TIMING11, newVal);
1815
1816 newVal = spur_subchannel_sd << AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S;
1817 REG_WRITE(ah, AR_PHY_SFCORR_EXT, newVal);
1818
1819 cur_bin = -6000;
1820 upper = bin + 100;
1821 lower = bin - 100;
1822
1823 for (i = 0; i < 4; i++) {
1824 int pilot_mask = 0;
1825 int chan_mask = 0;
1826 int bp = 0;
1827 for (bp = 0; bp < 30; bp++) {
1828 if ((cur_bin > lower) && (cur_bin < upper)) {
1829 pilot_mask = pilot_mask | 0x1 << bp;
1830 chan_mask = chan_mask | 0x1 << bp;
1831 }
1832 cur_bin += 100;
1833 }
1834 cur_bin += inc[i];
1835 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
1836 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
1837 }
1838
1839 cur_vit_mask = 6100;
1840 upper = bin + 120;
1841 lower = bin - 120;
1842
1843 for (i = 0; i < 123; i++) {
1844 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
Adrian Bunkb08cbcd2008-08-05 22:06:51 +03001845
1846 /* workaround for gcc bug #37014 */
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08001847 volatile int tmp_v = abs(cur_vit_mask - bin);
Adrian Bunkb08cbcd2008-08-05 22:06:51 +03001848
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08001849 if (tmp_v < 75)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001850 mask_amt = 1;
1851 else
1852 mask_amt = 0;
1853 if (cur_vit_mask < 0)
1854 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
1855 else
1856 mask_p[cur_vit_mask / 100] = mask_amt;
1857 }
1858 cur_vit_mask -= 100;
1859 }
1860
1861 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
1862 | (mask_m[48] << 26) | (mask_m[49] << 24)
1863 | (mask_m[50] << 22) | (mask_m[51] << 20)
1864 | (mask_m[52] << 18) | (mask_m[53] << 16)
1865 | (mask_m[54] << 14) | (mask_m[55] << 12)
1866 | (mask_m[56] << 10) | (mask_m[57] << 8)
1867 | (mask_m[58] << 6) | (mask_m[59] << 4)
1868 | (mask_m[60] << 2) | (mask_m[61] << 0);
1869 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
1870 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
1871
1872 tmp_mask = (mask_m[31] << 28)
1873 | (mask_m[32] << 26) | (mask_m[33] << 24)
1874 | (mask_m[34] << 22) | (mask_m[35] << 20)
1875 | (mask_m[36] << 18) | (mask_m[37] << 16)
1876 | (mask_m[48] << 14) | (mask_m[39] << 12)
1877 | (mask_m[40] << 10) | (mask_m[41] << 8)
1878 | (mask_m[42] << 6) | (mask_m[43] << 4)
1879 | (mask_m[44] << 2) | (mask_m[45] << 0);
1880 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
1881 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
1882
1883 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
1884 | (mask_m[18] << 26) | (mask_m[18] << 24)
1885 | (mask_m[20] << 22) | (mask_m[20] << 20)
1886 | (mask_m[22] << 18) | (mask_m[22] << 16)
1887 | (mask_m[24] << 14) | (mask_m[24] << 12)
1888 | (mask_m[25] << 10) | (mask_m[26] << 8)
1889 | (mask_m[27] << 6) | (mask_m[28] << 4)
1890 | (mask_m[29] << 2) | (mask_m[30] << 0);
1891 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
1892 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
1893
1894 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
1895 | (mask_m[2] << 26) | (mask_m[3] << 24)
1896 | (mask_m[4] << 22) | (mask_m[5] << 20)
1897 | (mask_m[6] << 18) | (mask_m[7] << 16)
1898 | (mask_m[8] << 14) | (mask_m[9] << 12)
1899 | (mask_m[10] << 10) | (mask_m[11] << 8)
1900 | (mask_m[12] << 6) | (mask_m[13] << 4)
1901 | (mask_m[14] << 2) | (mask_m[15] << 0);
1902 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
1903 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
1904
1905 tmp_mask = (mask_p[15] << 28)
1906 | (mask_p[14] << 26) | (mask_p[13] << 24)
1907 | (mask_p[12] << 22) | (mask_p[11] << 20)
1908 | (mask_p[10] << 18) | (mask_p[9] << 16)
1909 | (mask_p[8] << 14) | (mask_p[7] << 12)
1910 | (mask_p[6] << 10) | (mask_p[5] << 8)
1911 | (mask_p[4] << 6) | (mask_p[3] << 4)
1912 | (mask_p[2] << 2) | (mask_p[1] << 0);
1913 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
1914 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
1915
1916 tmp_mask = (mask_p[30] << 28)
1917 | (mask_p[29] << 26) | (mask_p[28] << 24)
1918 | (mask_p[27] << 22) | (mask_p[26] << 20)
1919 | (mask_p[25] << 18) | (mask_p[24] << 16)
1920 | (mask_p[23] << 14) | (mask_p[22] << 12)
1921 | (mask_p[21] << 10) | (mask_p[20] << 8)
1922 | (mask_p[19] << 6) | (mask_p[18] << 4)
1923 | (mask_p[17] << 2) | (mask_p[16] << 0);
1924 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
1925 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
1926
1927 tmp_mask = (mask_p[45] << 28)
1928 | (mask_p[44] << 26) | (mask_p[43] << 24)
1929 | (mask_p[42] << 22) | (mask_p[41] << 20)
1930 | (mask_p[40] << 18) | (mask_p[39] << 16)
1931 | (mask_p[38] << 14) | (mask_p[37] << 12)
1932 | (mask_p[36] << 10) | (mask_p[35] << 8)
1933 | (mask_p[34] << 6) | (mask_p[33] << 4)
1934 | (mask_p[32] << 2) | (mask_p[31] << 0);
1935 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
1936 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
1937
1938 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
1939 | (mask_p[59] << 26) | (mask_p[58] << 24)
1940 | (mask_p[57] << 22) | (mask_p[56] << 20)
1941 | (mask_p[55] << 18) | (mask_p[54] << 16)
1942 | (mask_p[53] << 14) | (mask_p[52] << 12)
1943 | (mask_p[51] << 10) | (mask_p[50] << 8)
1944 | (mask_p[49] << 6) | (mask_p[48] << 4)
1945 | (mask_p[47] << 2) | (mask_p[46] << 0);
1946 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
1947 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
1948}
1949
Sujithcbe61d82009-02-09 13:27:12 +05301950static void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001951{
1952 int bb_spur = AR_NO_SPUR;
1953 int bin, cur_bin;
1954 int spur_freq_sd;
1955 int spur_delta_phase;
1956 int denominator;
1957 int upper, lower, cur_vit_mask;
1958 int tmp, new;
1959 int i;
1960 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
1961 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
1962 };
1963 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
1964 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
1965 };
1966 int inc[4] = { 0, 100, 0, 0 };
1967
1968 int8_t mask_m[123];
1969 int8_t mask_p[123];
1970 int8_t mask_amt;
1971 int tmp_mask;
1972 int cur_bb_spur;
1973 bool is2GHz = IS_CHAN_2GHZ(chan);
1974
1975 memset(&mask_m, 0, sizeof(int8_t) * 123);
1976 memset(&mask_p, 0, sizeof(int8_t) * 123);
1977
1978 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujithf74df6f2009-02-09 13:27:24 +05301979 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001980 if (AR_NO_SPUR == cur_bb_spur)
1981 break;
1982 cur_bb_spur = cur_bb_spur - (chan->channel * 10);
1983 if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) {
1984 bb_spur = cur_bb_spur;
1985 break;
1986 }
1987 }
1988
1989 if (AR_NO_SPUR == bb_spur)
1990 return;
1991
1992 bin = bb_spur * 32;
1993
1994 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
1995 new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
1996 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
1997 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
1998 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
1999
2000 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new);
2001
2002 new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
2003 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
2004 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
2005 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
2006 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
2007 REG_WRITE(ah, AR_PHY_SPUR_REG, new);
2008
2009 spur_delta_phase = ((bb_spur * 524288) / 100) &
2010 AR_PHY_TIMING11_SPUR_DELTA_PHASE;
2011
2012 denominator = IS_CHAN_2GHZ(chan) ? 440 : 400;
2013 spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff;
2014
2015 new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
2016 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
2017 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
2018 REG_WRITE(ah, AR_PHY_TIMING11, new);
2019
2020 cur_bin = -6000;
2021 upper = bin + 100;
2022 lower = bin - 100;
2023
2024 for (i = 0; i < 4; i++) {
2025 int pilot_mask = 0;
2026 int chan_mask = 0;
2027 int bp = 0;
2028 for (bp = 0; bp < 30; bp++) {
2029 if ((cur_bin > lower) && (cur_bin < upper)) {
2030 pilot_mask = pilot_mask | 0x1 << bp;
2031 chan_mask = chan_mask | 0x1 << bp;
2032 }
2033 cur_bin += 100;
2034 }
2035 cur_bin += inc[i];
2036 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
2037 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
2038 }
2039
2040 cur_vit_mask = 6100;
2041 upper = bin + 120;
2042 lower = bin - 120;
2043
2044 for (i = 0; i < 123; i++) {
2045 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
Adrian Bunk88b9e2b2008-08-05 22:06:51 +03002046
2047 /* workaround for gcc bug #37014 */
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002048 volatile int tmp_v = abs(cur_vit_mask - bin);
Adrian Bunk88b9e2b2008-08-05 22:06:51 +03002049
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002050 if (tmp_v < 75)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002051 mask_amt = 1;
2052 else
2053 mask_amt = 0;
2054 if (cur_vit_mask < 0)
2055 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
2056 else
2057 mask_p[cur_vit_mask / 100] = mask_amt;
2058 }
2059 cur_vit_mask -= 100;
2060 }
2061
2062 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
2063 | (mask_m[48] << 26) | (mask_m[49] << 24)
2064 | (mask_m[50] << 22) | (mask_m[51] << 20)
2065 | (mask_m[52] << 18) | (mask_m[53] << 16)
2066 | (mask_m[54] << 14) | (mask_m[55] << 12)
2067 | (mask_m[56] << 10) | (mask_m[57] << 8)
2068 | (mask_m[58] << 6) | (mask_m[59] << 4)
2069 | (mask_m[60] << 2) | (mask_m[61] << 0);
2070 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
2071 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
2072
2073 tmp_mask = (mask_m[31] << 28)
2074 | (mask_m[32] << 26) | (mask_m[33] << 24)
2075 | (mask_m[34] << 22) | (mask_m[35] << 20)
2076 | (mask_m[36] << 18) | (mask_m[37] << 16)
2077 | (mask_m[48] << 14) | (mask_m[39] << 12)
2078 | (mask_m[40] << 10) | (mask_m[41] << 8)
2079 | (mask_m[42] << 6) | (mask_m[43] << 4)
2080 | (mask_m[44] << 2) | (mask_m[45] << 0);
2081 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
2082 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
2083
2084 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
2085 | (mask_m[18] << 26) | (mask_m[18] << 24)
2086 | (mask_m[20] << 22) | (mask_m[20] << 20)
2087 | (mask_m[22] << 18) | (mask_m[22] << 16)
2088 | (mask_m[24] << 14) | (mask_m[24] << 12)
2089 | (mask_m[25] << 10) | (mask_m[26] << 8)
2090 | (mask_m[27] << 6) | (mask_m[28] << 4)
2091 | (mask_m[29] << 2) | (mask_m[30] << 0);
2092 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
2093 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
2094
2095 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
2096 | (mask_m[2] << 26) | (mask_m[3] << 24)
2097 | (mask_m[4] << 22) | (mask_m[5] << 20)
2098 | (mask_m[6] << 18) | (mask_m[7] << 16)
2099 | (mask_m[8] << 14) | (mask_m[9] << 12)
2100 | (mask_m[10] << 10) | (mask_m[11] << 8)
2101 | (mask_m[12] << 6) | (mask_m[13] << 4)
2102 | (mask_m[14] << 2) | (mask_m[15] << 0);
2103 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
2104 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
2105
2106 tmp_mask = (mask_p[15] << 28)
2107 | (mask_p[14] << 26) | (mask_p[13] << 24)
2108 | (mask_p[12] << 22) | (mask_p[11] << 20)
2109 | (mask_p[10] << 18) | (mask_p[9] << 16)
2110 | (mask_p[8] << 14) | (mask_p[7] << 12)
2111 | (mask_p[6] << 10) | (mask_p[5] << 8)
2112 | (mask_p[4] << 6) | (mask_p[3] << 4)
2113 | (mask_p[2] << 2) | (mask_p[1] << 0);
2114 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
2115 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
2116
2117 tmp_mask = (mask_p[30] << 28)
2118 | (mask_p[29] << 26) | (mask_p[28] << 24)
2119 | (mask_p[27] << 22) | (mask_p[26] << 20)
2120 | (mask_p[25] << 18) | (mask_p[24] << 16)
2121 | (mask_p[23] << 14) | (mask_p[22] << 12)
2122 | (mask_p[21] << 10) | (mask_p[20] << 8)
2123 | (mask_p[19] << 6) | (mask_p[18] << 4)
2124 | (mask_p[17] << 2) | (mask_p[16] << 0);
2125 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
2126 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
2127
2128 tmp_mask = (mask_p[45] << 28)
2129 | (mask_p[44] << 26) | (mask_p[43] << 24)
2130 | (mask_p[42] << 22) | (mask_p[41] << 20)
2131 | (mask_p[40] << 18) | (mask_p[39] << 16)
2132 | (mask_p[38] << 14) | (mask_p[37] << 12)
2133 | (mask_p[36] << 10) | (mask_p[35] << 8)
2134 | (mask_p[34] << 6) | (mask_p[33] << 4)
2135 | (mask_p[32] << 2) | (mask_p[31] << 0);
2136 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
2137 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
2138
2139 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
2140 | (mask_p[59] << 26) | (mask_p[58] << 24)
2141 | (mask_p[57] << 22) | (mask_p[56] << 20)
2142 | (mask_p[55] << 18) | (mask_p[54] << 16)
2143 | (mask_p[53] << 14) | (mask_p[52] << 12)
2144 | (mask_p[51] << 10) | (mask_p[50] << 8)
2145 | (mask_p[49] << 6) | (mask_p[48] << 4)
2146 | (mask_p[47] << 2) | (mask_p[46] << 0);
2147 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
2148 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
2149}
2150
Sujithcbe61d82009-02-09 13:27:12 +05302151int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002152 bool bChannelChange)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002153{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002154 u32 saveLedState;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002155 struct ath_softc *sc = ah->ah_sc;
Sujith2660b812009-02-09 13:27:26 +05302156 struct ath9k_channel *curchan = ah->curchan;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002157 u32 saveDefAntenna;
2158 u32 macStaId1;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002159 int i, rx_chainmask, r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002160
Sujith2660b812009-02-09 13:27:26 +05302161 ah->extprotspacing = sc->ht_extprotspacing;
2162 ah->txchainmask = sc->tx_chainmask;
2163 ah->rxchainmask = sc->rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002164
Senthil Balasubramanian793c5922009-01-26 20:28:14 +05302165 if (AR_SREV_9285(ah)) {
Sujith2660b812009-02-09 13:27:26 +05302166 ah->txchainmask &= 0x1;
2167 ah->rxchainmask &= 0x1;
Senthil Balasubramanian793c5922009-01-26 20:28:14 +05302168 } else if (AR_SREV_9280(ah)) {
Sujith2660b812009-02-09 13:27:26 +05302169 ah->txchainmask &= 0x3;
2170 ah->rxchainmask &= 0x3;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002171 }
2172
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002173 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
2174 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002175
2176 if (curchan)
2177 ath9k_hw_getnf(ah, curchan);
2178
2179 if (bChannelChange &&
Sujith2660b812009-02-09 13:27:26 +05302180 (ah->chip_fullsleep != true) &&
2181 (ah->curchan != NULL) &&
2182 (chan->channel != ah->curchan->channel) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002183 ((chan->channelFlags & CHANNEL_ALL) ==
Sujith2660b812009-02-09 13:27:26 +05302184 (ah->curchan->channelFlags & CHANNEL_ALL)) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002185 (!AR_SREV_9280(ah) || (!IS_CHAN_A_5MHZ_SPACED(chan) &&
Sujith2660b812009-02-09 13:27:26 +05302186 !IS_CHAN_A_5MHZ_SPACED(ah->curchan)))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002187
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002188 if (ath9k_hw_channel_change(ah, chan, sc->tx_chan_width)) {
Sujith2660b812009-02-09 13:27:26 +05302189 ath9k_hw_loadnf(ah, ah->curchan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002190 ath9k_hw_start_nfcal(ah);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002191 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002192 }
2193 }
2194
2195 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
2196 if (saveDefAntenna == 0)
2197 saveDefAntenna = 1;
2198
2199 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
2200
2201 saveLedState = REG_READ(ah, AR_CFG_LED) &
2202 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
2203 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
2204
2205 ath9k_hw_mark_phy_inactive(ah);
2206
2207 if (!ath9k_hw_chip_reset(ah, chan)) {
Sujith04bd4632008-11-28 22:18:05 +05302208 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002209 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002210 }
2211
Vasanthakumar Thiagarajan369391d2009-01-21 19:24:13 +05302212 if (AR_SREV_9280_10_OR_LATER(ah))
2213 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002214
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002215 r = ath9k_hw_process_ini(ah, chan, sc->tx_chan_width);
2216 if (r)
2217 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002218
Jouni Malinen0ced0e12009-01-08 13:32:13 +02002219 /* Setup MFP options for CCMP */
2220 if (AR_SREV_9280_20_OR_LATER(ah)) {
2221 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
2222 * frames when constructing CCMP AAD. */
2223 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
2224 0xc7ff);
2225 ah->sw_mgmt_crypto = false;
2226 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
2227 /* Disable hardware crypto for management frames */
2228 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
2229 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
2230 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
2231 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
2232 ah->sw_mgmt_crypto = true;
2233 } else
2234 ah->sw_mgmt_crypto = true;
2235
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002236 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
2237 ath9k_hw_set_delta_slope(ah, chan);
2238
2239 if (AR_SREV_9280_10_OR_LATER(ah))
2240 ath9k_hw_9280_spur_mitigate(ah, chan);
2241 else
2242 ath9k_hw_spur_mitigate(ah, chan);
2243
Sujithf74df6f2009-02-09 13:27:24 +05302244 if (!ah->eep_ops->set_board_values(ah, chan)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002245 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
Sujith04bd4632008-11-28 22:18:05 +05302246 "error setting board options\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002247 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002248 }
2249
2250 ath9k_hw_decrease_chain_power(ah, chan);
2251
Sujithba52da52009-02-09 13:27:10 +05302252 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(ah->macaddr));
2253 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(ah->macaddr + 4)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002254 | macStaId1
2255 | AR_STA_ID1_RTS_USE_DEF
Sujith2660b812009-02-09 13:27:26 +05302256 | (ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302257 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Sujith2660b812009-02-09 13:27:26 +05302258 | ah->sta_id1_defaults);
2259 ath9k_hw_set_operating_mode(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002260
Sujithba52da52009-02-09 13:27:10 +05302261 REG_WRITE(ah, AR_BSSMSKL, get_unaligned_le32(sc->bssidmask));
2262 REG_WRITE(ah, AR_BSSMSKU, get_unaligned_le16(sc->bssidmask + 4));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002263
2264 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
2265
Sujithba52da52009-02-09 13:27:10 +05302266 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(sc->curbssid));
2267 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(sc->curbssid + 4) |
2268 ((sc->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002269
2270 REG_WRITE(ah, AR_ISR, ~0);
2271
2272 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
2273
2274 if (AR_SREV_9280_10_OR_LATER(ah)) {
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002275 if (!(ath9k_hw_ar9280_set_channel(ah, chan)))
2276 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002277 } else {
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002278 if (!(ath9k_hw_set_channel(ah, chan)))
2279 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002280 }
2281
2282 for (i = 0; i < AR_NUM_DCU; i++)
2283 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
2284
Sujith2660b812009-02-09 13:27:26 +05302285 ah->intr_txqs = 0;
2286 for (i = 0; i < ah->caps.total_queues; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002287 ath9k_hw_resettxqueue(ah, i);
2288
Sujith2660b812009-02-09 13:27:26 +05302289 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002290 ath9k_hw_init_qos(ah);
2291
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05302292#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05302293 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05302294 ath9k_enable_rfkill(ah);
2295#endif
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002296 ath9k_hw_init_user_settings(ah);
2297
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002298 REG_WRITE(ah, AR_STA_ID1,
2299 REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
2300
2301 ath9k_hw_set_dma(ah);
2302
2303 REG_WRITE(ah, AR_OBS, 8);
2304
Sujith2660b812009-02-09 13:27:26 +05302305 if (ah->intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002306
2307 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
2308 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
2309 }
2310
2311 ath9k_hw_init_bb(ah, chan);
2312
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002313 if (!ath9k_hw_init_cal(ah, chan))
2314 return -EIO;;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002315
Sujith2660b812009-02-09 13:27:26 +05302316 rx_chainmask = ah->rxchainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002317 if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) {
2318 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
2319 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
2320 }
2321
2322 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
2323
2324 if (AR_SREV_9100(ah)) {
2325 u32 mask;
2326 mask = REG_READ(ah, AR_CFG);
2327 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
2328 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05302329 "CFG Byte Swap Set 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002330 } else {
2331 mask =
2332 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
2333 REG_WRITE(ah, AR_CFG, mask);
2334 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05302335 "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002336 }
2337 } else {
2338#ifdef __BIG_ENDIAN
2339 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
2340#endif
2341 }
2342
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002343 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002344}
2345
Sujithf1dc5602008-10-29 10:16:30 +05302346/************************/
2347/* Key Cache Management */
2348/************************/
2349
Sujithcbe61d82009-02-09 13:27:12 +05302350bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002351{
Sujithf1dc5602008-10-29 10:16:30 +05302352 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002353
Sujith2660b812009-02-09 13:27:26 +05302354 if (entry >= ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05302355 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
Sujith04bd4632008-11-28 22:18:05 +05302356 "entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002357 return false;
2358 }
2359
Sujithf1dc5602008-10-29 10:16:30 +05302360 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002361
Sujithf1dc5602008-10-29 10:16:30 +05302362 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
2363 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
2364 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
2365 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
2366 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
2367 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
2368 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
2369 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
2370
2371 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2372 u16 micentry = entry + 64;
2373
2374 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
2375 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
2376 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
2377 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
2378
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002379 }
2380
Sujith2660b812009-02-09 13:27:26 +05302381 if (ah->curchan == NULL)
Sujithf1dc5602008-10-29 10:16:30 +05302382 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002383
2384 return true;
2385}
2386
Sujithcbe61d82009-02-09 13:27:12 +05302387bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002388{
Sujithf1dc5602008-10-29 10:16:30 +05302389 u32 macHi, macLo;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002390
Sujith2660b812009-02-09 13:27:26 +05302391 if (entry >= ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05302392 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
Sujith04bd4632008-11-28 22:18:05 +05302393 "entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002394 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002395 }
2396
Sujithf1dc5602008-10-29 10:16:30 +05302397 if (mac != NULL) {
2398 macHi = (mac[5] << 8) | mac[4];
2399 macLo = (mac[3] << 24) |
2400 (mac[2] << 16) |
2401 (mac[1] << 8) |
2402 mac[0];
2403 macLo >>= 1;
2404 macLo |= (macHi & 1) << 31;
2405 macHi >>= 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002406 } else {
Sujithf1dc5602008-10-29 10:16:30 +05302407 macLo = macHi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002408 }
Sujithf1dc5602008-10-29 10:16:30 +05302409 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
2410 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002411
2412 return true;
2413}
2414
Sujithcbe61d82009-02-09 13:27:12 +05302415bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
Sujithf1dc5602008-10-29 10:16:30 +05302416 const struct ath9k_keyval *k,
2417 const u8 *mac, int xorKey)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002418{
Sujith2660b812009-02-09 13:27:26 +05302419 const struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +05302420 u32 key0, key1, key2, key3, key4;
2421 u32 keyType;
2422 u32 xorMask = xorKey ?
2423 (ATH9K_KEY_XOR << 24 | ATH9K_KEY_XOR << 16 | ATH9K_KEY_XOR << 8
2424 | ATH9K_KEY_XOR) : 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002425
Sujithf1dc5602008-10-29 10:16:30 +05302426 if (entry >= pCap->keycache_size) {
2427 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
Sujith04bd4632008-11-28 22:18:05 +05302428 "entry %u out of range\n", entry);
Sujithf1dc5602008-10-29 10:16:30 +05302429 return false;
2430 }
2431
2432 switch (k->kv_type) {
2433 case ATH9K_CIPHER_AES_OCB:
2434 keyType = AR_KEYTABLE_TYPE_AES;
2435 break;
2436 case ATH9K_CIPHER_AES_CCM:
2437 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
2438 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
Sujith04bd4632008-11-28 22:18:05 +05302439 "AES-CCM not supported by mac rev 0x%x\n",
Sujithd535a422009-02-09 13:27:06 +05302440 ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002441 return false;
2442 }
Sujithf1dc5602008-10-29 10:16:30 +05302443 keyType = AR_KEYTABLE_TYPE_CCM;
2444 break;
2445 case ATH9K_CIPHER_TKIP:
2446 keyType = AR_KEYTABLE_TYPE_TKIP;
2447 if (ATH9K_IS_MIC_ENABLED(ah)
2448 && entry + 64 >= pCap->keycache_size) {
2449 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
Sujith04bd4632008-11-28 22:18:05 +05302450 "entry %u inappropriate for TKIP\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002451 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002452 }
Sujithf1dc5602008-10-29 10:16:30 +05302453 break;
2454 case ATH9K_CIPHER_WEP:
2455 if (k->kv_len < LEN_WEP40) {
2456 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
Sujith04bd4632008-11-28 22:18:05 +05302457 "WEP key length %u too small\n", k->kv_len);
Sujithf1dc5602008-10-29 10:16:30 +05302458 return false;
2459 }
2460 if (k->kv_len <= LEN_WEP40)
2461 keyType = AR_KEYTABLE_TYPE_40;
2462 else if (k->kv_len <= LEN_WEP104)
2463 keyType = AR_KEYTABLE_TYPE_104;
2464 else
2465 keyType = AR_KEYTABLE_TYPE_128;
2466 break;
2467 case ATH9K_CIPHER_CLR:
2468 keyType = AR_KEYTABLE_TYPE_CLR;
2469 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002470 default:
Sujithf1dc5602008-10-29 10:16:30 +05302471 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
Sujith04bd4632008-11-28 22:18:05 +05302472 "cipher %u not supported\n", k->kv_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002473 return false;
2474 }
Sujithf1dc5602008-10-29 10:16:30 +05302475
2476 key0 = get_unaligned_le32(k->kv_val + 0) ^ xorMask;
2477 key1 = (get_unaligned_le16(k->kv_val + 4) ^ xorMask) & 0xffff;
2478 key2 = get_unaligned_le32(k->kv_val + 6) ^ xorMask;
2479 key3 = (get_unaligned_le16(k->kv_val + 10) ^ xorMask) & 0xffff;
2480 key4 = get_unaligned_le32(k->kv_val + 12) ^ xorMask;
2481 if (k->kv_len <= LEN_WEP104)
2482 key4 &= 0xff;
2483
2484 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2485 u16 micentry = entry + 64;
2486
2487 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
2488 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
2489 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2490 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
2491 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2492 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
2493 (void) ath9k_hw_keysetmac(ah, entry, mac);
2494
Sujith2660b812009-02-09 13:27:26 +05302495 if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) {
Sujithf1dc5602008-10-29 10:16:30 +05302496 u32 mic0, mic1, mic2, mic3, mic4;
2497
2498 mic0 = get_unaligned_le32(k->kv_mic + 0);
2499 mic2 = get_unaligned_le32(k->kv_mic + 4);
2500 mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
2501 mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
2502 mic4 = get_unaligned_le32(k->kv_txmic + 4);
2503 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2504 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
2505 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2506 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
2507 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
2508 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2509 AR_KEYTABLE_TYPE_CLR);
2510
2511 } else {
2512 u32 mic0, mic2;
2513
2514 mic0 = get_unaligned_le32(k->kv_mic + 0);
2515 mic2 = get_unaligned_le32(k->kv_mic + 4);
2516 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2517 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
2518 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2519 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
2520 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
2521 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2522 AR_KEYTABLE_TYPE_CLR);
2523 }
2524 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
2525 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
2526 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2527 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
2528 } else {
2529 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2530 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
2531 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2532 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
2533 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2534 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
2535
2536 (void) ath9k_hw_keysetmac(ah, entry, mac);
2537 }
2538
Sujith2660b812009-02-09 13:27:26 +05302539 if (ah->curchan == NULL)
Sujithf1dc5602008-10-29 10:16:30 +05302540 return true;
2541
2542 return true;
2543}
2544
Sujithcbe61d82009-02-09 13:27:12 +05302545bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry)
Sujithf1dc5602008-10-29 10:16:30 +05302546{
Sujith2660b812009-02-09 13:27:26 +05302547 if (entry < ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05302548 u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
2549 if (val & AR_KEYTABLE_VALID)
2550 return true;
2551 }
2552 return false;
2553}
2554
2555/******************************/
2556/* Power Management (Chipset) */
2557/******************************/
2558
Sujithcbe61d82009-02-09 13:27:12 +05302559static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302560{
2561 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2562 if (setChip) {
2563 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2564 AR_RTC_FORCE_WAKE_EN);
2565 if (!AR_SREV_9100(ah))
2566 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
2567
Gabor Juhosd03a66c2009-01-14 20:17:09 +01002568 REG_CLR_BIT(ah, (AR_RTC_RESET),
Sujithf1dc5602008-10-29 10:16:30 +05302569 AR_RTC_RESET_EN);
2570 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002571}
2572
Sujithcbe61d82009-02-09 13:27:12 +05302573static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002574{
Sujithf1dc5602008-10-29 10:16:30 +05302575 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2576 if (setChip) {
Sujith2660b812009-02-09 13:27:26 +05302577 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002578
Sujithf1dc5602008-10-29 10:16:30 +05302579 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
2580 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2581 AR_RTC_FORCE_WAKE_ON_INT);
2582 } else {
2583 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2584 AR_RTC_FORCE_WAKE_EN);
2585 }
2586 }
2587}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002588
Sujithcbe61d82009-02-09 13:27:12 +05302589static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302590{
2591 u32 val;
2592 int i;
2593
2594 if (setChip) {
2595 if ((REG_READ(ah, AR_RTC_STATUS) &
2596 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2597 if (ath9k_hw_set_reset_reg(ah,
2598 ATH9K_RESET_POWER_ON) != true) {
2599 return false;
2600 }
2601 }
2602 if (AR_SREV_9100(ah))
2603 REG_SET_BIT(ah, AR_RTC_RESET,
2604 AR_RTC_RESET_EN);
2605
2606 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2607 AR_RTC_FORCE_WAKE_EN);
2608 udelay(50);
2609
2610 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2611 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2612 if (val == AR_RTC_STATUS_ON)
2613 break;
2614 udelay(50);
2615 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2616 AR_RTC_FORCE_WAKE_EN);
2617 }
2618 if (i == 0) {
2619 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
Sujith04bd4632008-11-28 22:18:05 +05302620 "Failed to wakeup in %uus\n", POWER_UP_TIME / 20);
Sujithf1dc5602008-10-29 10:16:30 +05302621 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002622 }
2623 }
2624
Sujithf1dc5602008-10-29 10:16:30 +05302625 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2626
2627 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002628}
2629
Sujithcbe61d82009-02-09 13:27:12 +05302630bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05302631{
Sujithcbe61d82009-02-09 13:27:12 +05302632 int status = true, setChip = true;
Sujithf1dc5602008-10-29 10:16:30 +05302633 static const char *modes[] = {
2634 "AWAKE",
2635 "FULL-SLEEP",
2636 "NETWORK SLEEP",
2637 "UNDEFINED"
2638 };
Sujithf1dc5602008-10-29 10:16:30 +05302639
Sujith04bd4632008-11-28 22:18:05 +05302640 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT, "%s -> %s (%s)\n",
Sujith2660b812009-02-09 13:27:26 +05302641 modes[ah->power_mode], modes[mode],
Sujithf1dc5602008-10-29 10:16:30 +05302642 setChip ? "set chip " : "");
2643
2644 switch (mode) {
2645 case ATH9K_PM_AWAKE:
2646 status = ath9k_hw_set_power_awake(ah, setChip);
2647 break;
2648 case ATH9K_PM_FULL_SLEEP:
2649 ath9k_set_power_sleep(ah, setChip);
Sujith2660b812009-02-09 13:27:26 +05302650 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05302651 break;
2652 case ATH9K_PM_NETWORK_SLEEP:
2653 ath9k_set_power_network_sleep(ah, setChip);
2654 break;
2655 default:
2656 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
Sujith04bd4632008-11-28 22:18:05 +05302657 "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05302658 return false;
2659 }
Sujith2660b812009-02-09 13:27:26 +05302660 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05302661
2662 return status;
2663}
2664
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002665/*
2666 * Helper for ASPM support.
2667 *
2668 * Disable PLL when in L0s as well as receiver clock when in L1.
2669 * This power saving option must be enabled through the SerDes.
2670 *
2671 * Programming the SerDes must go through the same 288 bit serial shift
2672 * register as the other analog registers. Hence the 9 writes.
2673 */
Sujithcbe61d82009-02-09 13:27:12 +05302674void ath9k_hw_configpcipowersave(struct ath_hw *ah, int restore)
Sujithf1dc5602008-10-29 10:16:30 +05302675{
Sujithf1dc5602008-10-29 10:16:30 +05302676 u8 i;
2677
Sujith2660b812009-02-09 13:27:26 +05302678 if (ah->is_pciexpress != true)
Sujithf1dc5602008-10-29 10:16:30 +05302679 return;
2680
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002681 /* Do not touch SerDes registers */
Sujith2660b812009-02-09 13:27:26 +05302682 if (ah->config.pcie_powersave_enable == 2)
Sujithf1dc5602008-10-29 10:16:30 +05302683 return;
2684
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002685 /* Nothing to do on restore for 11N */
Sujithf1dc5602008-10-29 10:16:30 +05302686 if (restore)
2687 return;
2688
2689 if (AR_SREV_9280_20_OR_LATER(ah)) {
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002690 /*
2691 * AR9280 2.0 or later chips use SerDes values from the
2692 * initvals.h initialized depending on chipset during
2693 * ath9k_hw_do_attach()
2694 */
Sujith2660b812009-02-09 13:27:26 +05302695 for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
2696 REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
2697 INI_RA(&ah->iniPcieSerdes, i, 1));
Sujithf1dc5602008-10-29 10:16:30 +05302698 }
Sujithf1dc5602008-10-29 10:16:30 +05302699 } else if (AR_SREV_9280(ah) &&
Sujithd535a422009-02-09 13:27:06 +05302700 (ah->hw_version.macRev == AR_SREV_REVISION_9280_10)) {
Sujithf1dc5602008-10-29 10:16:30 +05302701 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
2702 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
2703
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002704 /* RX shut off when elecidle is asserted */
Sujithf1dc5602008-10-29 10:16:30 +05302705 REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
2706 REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
2707 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
2708
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002709 /* Shut off CLKREQ active in L1 */
Sujith2660b812009-02-09 13:27:26 +05302710 if (ah->config.pcie_clock_req)
Sujithf1dc5602008-10-29 10:16:30 +05302711 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
2712 else
2713 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
2714
2715 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2716 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2717 REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
2718
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002719 /* Load the new settings */
Sujithf1dc5602008-10-29 10:16:30 +05302720 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
2721
Sujithf1dc5602008-10-29 10:16:30 +05302722 } else {
2723 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
2724 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002725
2726 /* RX shut off when elecidle is asserted */
Sujithf1dc5602008-10-29 10:16:30 +05302727 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
2728 REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
2729 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002730
2731 /*
2732 * Ignore ah->ah_config.pcie_clock_req setting for
2733 * pre-AR9280 11n
2734 */
Sujithf1dc5602008-10-29 10:16:30 +05302735 REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002736
Sujithf1dc5602008-10-29 10:16:30 +05302737 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2738 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2739 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002740
2741 /* Load the new settings */
Sujithf1dc5602008-10-29 10:16:30 +05302742 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
2743 }
2744
Luis R. Rodriguez6d08b9b2009-02-10 15:35:27 -08002745 udelay(1000);
2746
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002747 /* set bit 19 to allow forcing of pcie core into L1 state */
Sujithf1dc5602008-10-29 10:16:30 +05302748 REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
2749
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002750 /* Several PCIe massages to ensure proper behaviour */
Sujith2660b812009-02-09 13:27:26 +05302751 if (ah->config.pcie_waen) {
2752 REG_WRITE(ah, AR_WA, ah->config.pcie_waen);
Sujithf1dc5602008-10-29 10:16:30 +05302753 } else {
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302754 if (AR_SREV_9285(ah))
2755 REG_WRITE(ah, AR_WA, AR9285_WA_DEFAULT);
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002756 /*
2757 * On AR9280 chips bit 22 of 0x4004 needs to be set to
2758 * otherwise card may disappear.
2759 */
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302760 else if (AR_SREV_9280(ah))
2761 REG_WRITE(ah, AR_WA, AR9280_WA_DEFAULT);
Sujithf1dc5602008-10-29 10:16:30 +05302762 else
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302763 REG_WRITE(ah, AR_WA, AR_WA_DEFAULT);
Sujithf1dc5602008-10-29 10:16:30 +05302764 }
2765}
2766
2767/**********************/
2768/* Interrupt Handling */
2769/**********************/
2770
Sujithcbe61d82009-02-09 13:27:12 +05302771bool ath9k_hw_intrpend(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002772{
2773 u32 host_isr;
2774
2775 if (AR_SREV_9100(ah))
2776 return true;
2777
2778 host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
2779 if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
2780 return true;
2781
2782 host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
2783 if ((host_isr & AR_INTR_SYNC_DEFAULT)
2784 && (host_isr != AR_INTR_SPURIOUS))
2785 return true;
2786
2787 return false;
2788}
2789
Sujithcbe61d82009-02-09 13:27:12 +05302790bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002791{
2792 u32 isr = 0;
2793 u32 mask2 = 0;
Sujith2660b812009-02-09 13:27:26 +05302794 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002795 u32 sync_cause = 0;
2796 bool fatal_int = false;
2797
2798 if (!AR_SREV_9100(ah)) {
2799 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
2800 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
2801 == AR_RTC_STATUS_ON) {
2802 isr = REG_READ(ah, AR_ISR);
2803 }
2804 }
2805
Sujithf1dc5602008-10-29 10:16:30 +05302806 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
2807 AR_INTR_SYNC_DEFAULT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002808
2809 *masked = 0;
2810
2811 if (!isr && !sync_cause)
2812 return false;
2813 } else {
2814 *masked = 0;
2815 isr = REG_READ(ah, AR_ISR);
2816 }
2817
2818 if (isr) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002819 if (isr & AR_ISR_BCNMISC) {
2820 u32 isr2;
2821 isr2 = REG_READ(ah, AR_ISR_S2);
2822 if (isr2 & AR_ISR_S2_TIM)
2823 mask2 |= ATH9K_INT_TIM;
2824 if (isr2 & AR_ISR_S2_DTIM)
2825 mask2 |= ATH9K_INT_DTIM;
2826 if (isr2 & AR_ISR_S2_DTIMSYNC)
2827 mask2 |= ATH9K_INT_DTIMSYNC;
2828 if (isr2 & (AR_ISR_S2_CABEND))
2829 mask2 |= ATH9K_INT_CABEND;
2830 if (isr2 & AR_ISR_S2_GTT)
2831 mask2 |= ATH9K_INT_GTT;
2832 if (isr2 & AR_ISR_S2_CST)
2833 mask2 |= ATH9K_INT_CST;
Sujith4af9cf42009-02-12 10:06:47 +05302834 if (isr2 & AR_ISR_S2_TSFOOR)
2835 mask2 |= ATH9K_INT_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002836 }
2837
2838 isr = REG_READ(ah, AR_ISR_RAC);
2839 if (isr == 0xffffffff) {
2840 *masked = 0;
2841 return false;
2842 }
2843
2844 *masked = isr & ATH9K_INT_COMMON;
2845
Sujith2660b812009-02-09 13:27:26 +05302846 if (ah->intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002847 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
2848 *masked |= ATH9K_INT_RX;
2849 }
2850
2851 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
2852 *masked |= ATH9K_INT_RX;
2853 if (isr &
2854 (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
2855 AR_ISR_TXEOL)) {
2856 u32 s0_s, s1_s;
2857
2858 *masked |= ATH9K_INT_TX;
2859
2860 s0_s = REG_READ(ah, AR_ISR_S0_S);
Sujith2660b812009-02-09 13:27:26 +05302861 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
2862 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002863
2864 s1_s = REG_READ(ah, AR_ISR_S1_S);
Sujith2660b812009-02-09 13:27:26 +05302865 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
2866 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002867 }
2868
2869 if (isr & AR_ISR_RXORN) {
2870 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
Sujith04bd4632008-11-28 22:18:05 +05302871 "receive FIFO overrun interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002872 }
2873
2874 if (!AR_SREV_9100(ah)) {
Sujith60b67f52008-08-07 10:52:38 +05302875 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002876 u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
2877 if (isr5 & AR_ISR_S5_TIM_TIMER)
2878 *masked |= ATH9K_INT_TIM_TIMER;
2879 }
2880 }
2881
2882 *masked |= mask2;
2883 }
Sujithf1dc5602008-10-29 10:16:30 +05302884
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002885 if (AR_SREV_9100(ah))
2886 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302887
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002888 if (sync_cause) {
2889 fatal_int =
2890 (sync_cause &
2891 (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
2892 ? true : false;
2893
2894 if (fatal_int) {
2895 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
2896 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
Sujith04bd4632008-11-28 22:18:05 +05302897 "received PCI FATAL interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002898 }
2899 if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
2900 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
Sujith04bd4632008-11-28 22:18:05 +05302901 "received PCI PERR interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002902 }
2903 }
2904 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
2905 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
Sujith04bd4632008-11-28 22:18:05 +05302906 "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002907 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
2908 REG_WRITE(ah, AR_RC, 0);
2909 *masked |= ATH9K_INT_FATAL;
2910 }
2911 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
2912 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
Sujith04bd4632008-11-28 22:18:05 +05302913 "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002914 }
2915
2916 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
2917 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
2918 }
Sujithf1dc5602008-10-29 10:16:30 +05302919
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002920 return true;
2921}
2922
Sujithcbe61d82009-02-09 13:27:12 +05302923enum ath9k_int ath9k_hw_intrget(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002924{
Sujith2660b812009-02-09 13:27:26 +05302925 return ah->mask_reg;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002926}
2927
Sujithcbe61d82009-02-09 13:27:12 +05302928enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002929{
Sujith2660b812009-02-09 13:27:26 +05302930 u32 omask = ah->mask_reg;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002931 u32 mask, mask2;
Sujith2660b812009-02-09 13:27:26 +05302932 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002933
Sujith04bd4632008-11-28 22:18:05 +05302934 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002935
2936 if (omask & ATH9K_INT_GLOBAL) {
Sujith04bd4632008-11-28 22:18:05 +05302937 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "disable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002938 REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
2939 (void) REG_READ(ah, AR_IER);
2940 if (!AR_SREV_9100(ah)) {
2941 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
2942 (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
2943
2944 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
2945 (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
2946 }
2947 }
2948
2949 mask = ints & ATH9K_INT_COMMON;
2950 mask2 = 0;
2951
2952 if (ints & ATH9K_INT_TX) {
Sujith2660b812009-02-09 13:27:26 +05302953 if (ah->txok_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002954 mask |= AR_IMR_TXOK;
Sujith2660b812009-02-09 13:27:26 +05302955 if (ah->txdesc_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002956 mask |= AR_IMR_TXDESC;
Sujith2660b812009-02-09 13:27:26 +05302957 if (ah->txerr_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002958 mask |= AR_IMR_TXERR;
Sujith2660b812009-02-09 13:27:26 +05302959 if (ah->txeol_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002960 mask |= AR_IMR_TXEOL;
2961 }
2962 if (ints & ATH9K_INT_RX) {
2963 mask |= AR_IMR_RXERR;
Sujith2660b812009-02-09 13:27:26 +05302964 if (ah->intr_mitigation)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002965 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
2966 else
2967 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
Sujith60b67f52008-08-07 10:52:38 +05302968 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002969 mask |= AR_IMR_GENTMR;
2970 }
2971
2972 if (ints & (ATH9K_INT_BMISC)) {
2973 mask |= AR_IMR_BCNMISC;
2974 if (ints & ATH9K_INT_TIM)
2975 mask2 |= AR_IMR_S2_TIM;
2976 if (ints & ATH9K_INT_DTIM)
2977 mask2 |= AR_IMR_S2_DTIM;
2978 if (ints & ATH9K_INT_DTIMSYNC)
2979 mask2 |= AR_IMR_S2_DTIMSYNC;
2980 if (ints & ATH9K_INT_CABEND)
Sujith4af9cf42009-02-12 10:06:47 +05302981 mask2 |= AR_IMR_S2_CABEND;
2982 if (ints & ATH9K_INT_TSFOOR)
2983 mask2 |= AR_IMR_S2_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002984 }
2985
2986 if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
2987 mask |= AR_IMR_BCNMISC;
2988 if (ints & ATH9K_INT_GTT)
2989 mask2 |= AR_IMR_S2_GTT;
2990 if (ints & ATH9K_INT_CST)
2991 mask2 |= AR_IMR_S2_CST;
2992 }
2993
Sujith04bd4632008-11-28 22:18:05 +05302994 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002995 REG_WRITE(ah, AR_IMR, mask);
2996 mask = REG_READ(ah, AR_IMR_S2) & ~(AR_IMR_S2_TIM |
2997 AR_IMR_S2_DTIM |
2998 AR_IMR_S2_DTIMSYNC |
2999 AR_IMR_S2_CABEND |
3000 AR_IMR_S2_CABTO |
3001 AR_IMR_S2_TSFOOR |
3002 AR_IMR_S2_GTT | AR_IMR_S2_CST);
3003 REG_WRITE(ah, AR_IMR_S2, mask | mask2);
Sujith2660b812009-02-09 13:27:26 +05303004 ah->mask_reg = ints;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003005
Sujith60b67f52008-08-07 10:52:38 +05303006 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003007 if (ints & ATH9K_INT_TIM_TIMER)
3008 REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
3009 else
3010 REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
3011 }
3012
3013 if (ints & ATH9K_INT_GLOBAL) {
Sujith04bd4632008-11-28 22:18:05 +05303014 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "enable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003015 REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
3016 if (!AR_SREV_9100(ah)) {
3017 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
3018 AR_INTR_MAC_IRQ);
3019 REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
3020
3021
3022 REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
3023 AR_INTR_SYNC_DEFAULT);
3024 REG_WRITE(ah, AR_INTR_SYNC_MASK,
3025 AR_INTR_SYNC_DEFAULT);
3026 }
3027 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
3028 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
3029 }
3030
3031 return omask;
3032}
3033
Sujithf1dc5602008-10-29 10:16:30 +05303034/*******************/
3035/* Beacon Handling */
3036/*******************/
3037
Sujithcbe61d82009-02-09 13:27:12 +05303038void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003039{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003040 int flags = 0;
3041
Sujith2660b812009-02-09 13:27:26 +05303042 ah->beacon_interval = beacon_period;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003043
Sujith2660b812009-02-09 13:27:26 +05303044 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08003045 case NL80211_IFTYPE_STATION:
3046 case NL80211_IFTYPE_MONITOR:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003047 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3048 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
3049 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
3050 flags |= AR_TBTT_TIMER_EN;
3051 break;
Colin McCabed97809d2008-12-01 13:38:55 -08003052 case NL80211_IFTYPE_ADHOC:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003053 REG_SET_BIT(ah, AR_TXCFG,
3054 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
3055 REG_WRITE(ah, AR_NEXT_NDP_TIMER,
3056 TU_TO_USEC(next_beacon +
Sujith2660b812009-02-09 13:27:26 +05303057 (ah->atim_window ? ah->
3058 atim_window : 1)));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003059 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08003060 case NL80211_IFTYPE_AP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003061 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3062 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
3063 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05303064 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05303065 dma_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003066 REG_WRITE(ah, AR_NEXT_SWBA,
3067 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05303068 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05303069 sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003070 flags |=
3071 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
3072 break;
Colin McCabed97809d2008-12-01 13:38:55 -08003073 default:
3074 DPRINTF(ah->ah_sc, ATH_DBG_BEACON,
3075 "%s: unsupported opmode: %d\n",
Sujith2660b812009-02-09 13:27:26 +05303076 __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08003077 return;
3078 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003079 }
3080
3081 REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3082 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3083 REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
3084 REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
3085
3086 beacon_period &= ~ATH9K_BEACON_ENA;
3087 if (beacon_period & ATH9K_BEACON_RESET_TSF) {
3088 beacon_period &= ~ATH9K_BEACON_RESET_TSF;
3089 ath9k_hw_reset_tsf(ah);
3090 }
3091
3092 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
3093}
3094
Sujithcbe61d82009-02-09 13:27:12 +05303095void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303096 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003097{
3098 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05303099 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003100
3101 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
3102
3103 REG_WRITE(ah, AR_BEACON_PERIOD,
3104 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3105 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
3106 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3107
3108 REG_RMW_FIELD(ah, AR_RSSI_THR,
3109 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
3110
3111 beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
3112
3113 if (bs->bs_sleepduration > beaconintval)
3114 beaconintval = bs->bs_sleepduration;
3115
3116 dtimperiod = bs->bs_dtimperiod;
3117 if (bs->bs_sleepduration > dtimperiod)
3118 dtimperiod = bs->bs_sleepduration;
3119
3120 if (beaconintval == dtimperiod)
3121 nextTbtt = bs->bs_nextdtim;
3122 else
3123 nextTbtt = bs->bs_nexttbtt;
3124
Sujith04bd4632008-11-28 22:18:05 +05303125 DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
3126 DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
3127 DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
3128 DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003129
3130 REG_WRITE(ah, AR_NEXT_DTIM,
3131 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
3132 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
3133
3134 REG_WRITE(ah, AR_SLEEP1,
3135 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
3136 | AR_SLEEP1_ASSUME_DTIM);
3137
Sujith60b67f52008-08-07 10:52:38 +05303138 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003139 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
3140 else
3141 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
3142
3143 REG_WRITE(ah, AR_SLEEP2,
3144 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
3145
3146 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
3147 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
3148
3149 REG_SET_BIT(ah, AR_TIMER_MODE,
3150 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
3151 AR_DTIM_TIMER_EN);
3152
Sujith4af9cf42009-02-12 10:06:47 +05303153 /* TSF Out of Range Threshold */
3154 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003155}
3156
Sujithf1dc5602008-10-29 10:16:30 +05303157/*******************/
3158/* HW Capabilities */
3159/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003160
Sujithcbe61d82009-02-09 13:27:12 +05303161bool ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003162{
Sujith2660b812009-02-09 13:27:26 +05303163 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +05303164 u16 capField = 0, eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003165
Sujithf74df6f2009-02-09 13:27:24 +05303166 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Sujithd6bad492009-02-09 13:27:08 +05303167 ah->regulatory.current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303168
Sujithf74df6f2009-02-09 13:27:24 +05303169 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
Sujithfec0de12009-02-12 10:06:43 +05303170 if (AR_SREV_9285_10_OR_LATER(ah))
3171 eeval |= AR9285_RDEXT_DEFAULT;
Sujithd6bad492009-02-09 13:27:08 +05303172 ah->regulatory.current_rd_ext = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303173
Sujithf74df6f2009-02-09 13:27:24 +05303174 capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
Sujithf1dc5602008-10-29 10:16:30 +05303175
Sujith2660b812009-02-09 13:27:26 +05303176 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05303177 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Sujithd6bad492009-02-09 13:27:08 +05303178 if (ah->regulatory.current_rd == 0x64 ||
3179 ah->regulatory.current_rd == 0x65)
3180 ah->regulatory.current_rd += 5;
3181 else if (ah->regulatory.current_rd == 0x41)
3182 ah->regulatory.current_rd = 0x43;
Sujithf1dc5602008-10-29 10:16:30 +05303183 DPRINTF(ah->ah_sc, ATH_DBG_REGULATORY,
Sujithd6bad492009-02-09 13:27:08 +05303184 "regdomain mapped to 0x%x\n", ah->regulatory.current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003185 }
Sujithdc2222a2008-08-14 13:26:55 +05303186
Sujithf74df6f2009-02-09 13:27:24 +05303187 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Sujithf1dc5602008-10-29 10:16:30 +05303188 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003189
Sujithf1dc5602008-10-29 10:16:30 +05303190 if (eeval & AR5416_OPFLAGS_11A) {
3191 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303192 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303193 if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
3194 set_bit(ATH9K_MODE_11NA_HT20,
3195 pCap->wireless_modes);
3196 if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
3197 set_bit(ATH9K_MODE_11NA_HT40PLUS,
3198 pCap->wireless_modes);
3199 set_bit(ATH9K_MODE_11NA_HT40MINUS,
3200 pCap->wireless_modes);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003201 }
3202 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003203 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003204
Sujithf1dc5602008-10-29 10:16:30 +05303205 if (eeval & AR5416_OPFLAGS_11G) {
3206 set_bit(ATH9K_MODE_11B, pCap->wireless_modes);
3207 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303208 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303209 if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
3210 set_bit(ATH9K_MODE_11NG_HT20,
3211 pCap->wireless_modes);
3212 if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
3213 set_bit(ATH9K_MODE_11NG_HT40PLUS,
3214 pCap->wireless_modes);
3215 set_bit(ATH9K_MODE_11NG_HT40MINUS,
3216 pCap->wireless_modes);
3217 }
3218 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003219 }
Sujithf1dc5602008-10-29 10:16:30 +05303220
Sujithf74df6f2009-02-09 13:27:24 +05303221 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Sujith2660b812009-02-09 13:27:26 +05303222 if ((ah->is_pciexpress)
Sujithf1dc5602008-10-29 10:16:30 +05303223 || (eeval & AR5416_OPFLAGS_11A)) {
3224 pCap->rx_chainmask =
Sujithf74df6f2009-02-09 13:27:24 +05303225 ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05303226 } else {
3227 pCap->rx_chainmask =
3228 (ath9k_hw_gpio_get(ah, 0)) ? 0x5 : 0x7;
3229 }
3230
Sujithd535a422009-02-09 13:27:06 +05303231 if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0)))
Sujith2660b812009-02-09 13:27:26 +05303232 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05303233
3234 pCap->low_2ghz_chan = 2312;
3235 pCap->high_2ghz_chan = 2732;
3236
3237 pCap->low_5ghz_chan = 4920;
3238 pCap->high_5ghz_chan = 6100;
3239
3240 pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
3241 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
3242 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
3243
3244 pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
3245 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
3246 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
3247
3248 pCap->hw_caps |= ATH9K_HW_CAP_CHAN_SPREAD;
3249
Sujith2660b812009-02-09 13:27:26 +05303250 if (ah->config.ht_enable)
Sujithf1dc5602008-10-29 10:16:30 +05303251 pCap->hw_caps |= ATH9K_HW_CAP_HT;
3252 else
3253 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
3254
3255 pCap->hw_caps |= ATH9K_HW_CAP_GTT;
3256 pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
3257 pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
3258 pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
3259
3260 if (capField & AR_EEPROM_EEPCAP_MAXQCU)
3261 pCap->total_queues =
3262 MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
3263 else
3264 pCap->total_queues = ATH9K_NUM_TX_QUEUES;
3265
3266 if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
3267 pCap->keycache_size =
3268 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
3269 else
3270 pCap->keycache_size = AR_KEYTABLE_SIZE;
3271
3272 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
3273 pCap->num_mr_retries = 4;
3274 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
3275
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303276 if (AR_SREV_9285_10_OR_LATER(ah))
3277 pCap->num_gpio_pins = AR9285_NUM_GPIO;
3278 else if (AR_SREV_9280_10_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303279 pCap->num_gpio_pins = AR928X_NUM_GPIO;
3280 else
3281 pCap->num_gpio_pins = AR_NUM_GPIO;
3282
3283 if (AR_SREV_9280_10_OR_LATER(ah)) {
3284 pCap->hw_caps |= ATH9K_HW_CAP_WOW;
3285 pCap->hw_caps |= ATH9K_HW_CAP_WOW_MATCHPATTERN_EXACT;
3286 } else {
3287 pCap->hw_caps &= ~ATH9K_HW_CAP_WOW;
3288 pCap->hw_caps &= ~ATH9K_HW_CAP_WOW_MATCHPATTERN_EXACT;
3289 }
3290
3291 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
3292 pCap->hw_caps |= ATH9K_HW_CAP_CST;
3293 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
3294 } else {
3295 pCap->rts_aggr_limit = (8 * 1024);
3296 }
3297
3298 pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
3299
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05303300#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05303301 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
3302 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
3303 ah->rfkill_gpio =
3304 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
3305 ah->rfkill_polarity =
3306 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05303307
3308 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
3309 }
3310#endif
3311
Sujithd535a422009-02-09 13:27:06 +05303312 if ((ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI) ||
3313 (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE) ||
3314 (ah->hw_version.macVersion == AR_SREV_VERSION_9160) ||
3315 (ah->hw_version.macVersion == AR_SREV_VERSION_9100) ||
3316 (ah->hw_version.macVersion == AR_SREV_VERSION_9280))
Sujithf1dc5602008-10-29 10:16:30 +05303317 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
3318 else
3319 pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
3320
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05303321 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303322 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
3323 else
3324 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
3325
Sujithd6bad492009-02-09 13:27:08 +05303326 if (ah->regulatory.current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) {
Sujithf1dc5602008-10-29 10:16:30 +05303327 pCap->reg_cap =
3328 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3329 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
3330 AR_EEPROM_EEREGCAP_EN_KK_U2 |
3331 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
3332 } else {
3333 pCap->reg_cap =
3334 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3335 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
3336 }
3337
3338 pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
3339
3340 pCap->num_antcfg_5ghz =
Sujithf74df6f2009-02-09 13:27:24 +05303341 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303342 pCap->num_antcfg_2ghz =
Sujithf74df6f2009-02-09 13:27:24 +05303343 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303344
Vasanthakumar Thiagarajan138ab2e2009-01-10 17:07:09 +05303345 if (AR_SREV_9280_10_OR_LATER(ah) && btcoex_enable) {
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303346 pCap->hw_caps |= ATH9K_HW_CAP_BT_COEX;
Sujith2660b812009-02-09 13:27:26 +05303347 ah->btactive_gpio = 6;
3348 ah->wlanactive_gpio = 5;
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303349 }
3350
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003351 return true;
3352}
3353
Sujithcbe61d82009-02-09 13:27:12 +05303354bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303355 u32 capability, u32 *result)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003356{
Sujith2660b812009-02-09 13:27:26 +05303357 const struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003358
Sujithf1dc5602008-10-29 10:16:30 +05303359 switch (type) {
3360 case ATH9K_CAP_CIPHER:
3361 switch (capability) {
3362 case ATH9K_CIPHER_AES_CCM:
3363 case ATH9K_CIPHER_AES_OCB:
3364 case ATH9K_CIPHER_TKIP:
3365 case ATH9K_CIPHER_WEP:
3366 case ATH9K_CIPHER_MIC:
3367 case ATH9K_CIPHER_CLR:
3368 return true;
3369 default:
3370 return false;
3371 }
3372 case ATH9K_CAP_TKIP_MIC:
3373 switch (capability) {
3374 case 0:
3375 return true;
3376 case 1:
Sujith2660b812009-02-09 13:27:26 +05303377 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303378 AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
3379 false;
3380 }
3381 case ATH9K_CAP_TKIP_SPLIT:
Sujith2660b812009-02-09 13:27:26 +05303382 return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ?
Sujithf1dc5602008-10-29 10:16:30 +05303383 false : true;
3384 case ATH9K_CAP_WME_TKIPMIC:
3385 return 0;
3386 case ATH9K_CAP_PHYCOUNTERS:
Sujith2660b812009-02-09 13:27:26 +05303387 return ah->has_hw_phycounters ? 0 : -ENXIO;
Sujithf1dc5602008-10-29 10:16:30 +05303388 case ATH9K_CAP_DIVERSITY:
3389 return (REG_READ(ah, AR_PHY_CCK_DETECT) &
3390 AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV) ?
3391 true : false;
3392 case ATH9K_CAP_PHYDIAG:
3393 return true;
3394 case ATH9K_CAP_MCAST_KEYSRCH:
3395 switch (capability) {
3396 case 0:
3397 return true;
3398 case 1:
3399 if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
3400 return false;
3401 } else {
Sujith2660b812009-02-09 13:27:26 +05303402 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303403 AR_STA_ID1_MCAST_KSRCH) ? true :
3404 false;
3405 }
3406 }
3407 return false;
3408 case ATH9K_CAP_TSF_ADJUST:
Sujith2660b812009-02-09 13:27:26 +05303409 return (ah->misc_mode & AR_PCU_TX_ADD_TSF) ?
Sujithf1dc5602008-10-29 10:16:30 +05303410 true : false;
3411 case ATH9K_CAP_RFSILENT:
3412 if (capability == 3)
3413 return false;
3414 case ATH9K_CAP_ANT_CFG_2GHZ:
3415 *result = pCap->num_antcfg_2ghz;
3416 return true;
3417 case ATH9K_CAP_ANT_CFG_5GHZ:
3418 *result = pCap->num_antcfg_5ghz;
3419 return true;
3420 case ATH9K_CAP_TXPOW:
3421 switch (capability) {
3422 case 0:
3423 return 0;
3424 case 1:
Sujithd6bad492009-02-09 13:27:08 +05303425 *result = ah->regulatory.power_limit;
Sujithf1dc5602008-10-29 10:16:30 +05303426 return 0;
3427 case 2:
Sujithd6bad492009-02-09 13:27:08 +05303428 *result = ah->regulatory.max_power_level;
Sujithf1dc5602008-10-29 10:16:30 +05303429 return 0;
3430 case 3:
Sujithd6bad492009-02-09 13:27:08 +05303431 *result = ah->regulatory.tp_scale;
Sujithf1dc5602008-10-29 10:16:30 +05303432 return 0;
3433 }
3434 return false;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05303435 case ATH9K_CAP_DS:
3436 return (AR_SREV_9280_20_OR_LATER(ah) &&
3437 (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1))
3438 ? false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303439 default:
3440 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003441 }
Sujithf1dc5602008-10-29 10:16:30 +05303442}
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003443
Sujithcbe61d82009-02-09 13:27:12 +05303444bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303445 u32 capability, u32 setting, int *status)
3446{
Sujithf1dc5602008-10-29 10:16:30 +05303447 u32 v;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003448
Sujithf1dc5602008-10-29 10:16:30 +05303449 switch (type) {
3450 case ATH9K_CAP_TKIP_MIC:
3451 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303452 ah->sta_id1_defaults |=
Sujithf1dc5602008-10-29 10:16:30 +05303453 AR_STA_ID1_CRPT_MIC_ENABLE;
3454 else
Sujith2660b812009-02-09 13:27:26 +05303455 ah->sta_id1_defaults &=
Sujithf1dc5602008-10-29 10:16:30 +05303456 ~AR_STA_ID1_CRPT_MIC_ENABLE;
3457 return true;
3458 case ATH9K_CAP_DIVERSITY:
3459 v = REG_READ(ah, AR_PHY_CCK_DETECT);
3460 if (setting)
3461 v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3462 else
3463 v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3464 REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
3465 return true;
3466 case ATH9K_CAP_MCAST_KEYSRCH:
3467 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303468 ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303469 else
Sujith2660b812009-02-09 13:27:26 +05303470 ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303471 return true;
3472 case ATH9K_CAP_TSF_ADJUST:
3473 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303474 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Sujithf1dc5602008-10-29 10:16:30 +05303475 else
Sujith2660b812009-02-09 13:27:26 +05303476 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Sujithf1dc5602008-10-29 10:16:30 +05303477 return true;
3478 default:
3479 return false;
3480 }
3481}
3482
3483/****************************/
3484/* GPIO / RFKILL / Antennae */
3485/****************************/
3486
Sujithcbe61d82009-02-09 13:27:12 +05303487static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303488 u32 gpio, u32 type)
3489{
3490 int addr;
3491 u32 gpio_shift, tmp;
3492
3493 if (gpio > 11)
3494 addr = AR_GPIO_OUTPUT_MUX3;
3495 else if (gpio > 5)
3496 addr = AR_GPIO_OUTPUT_MUX2;
3497 else
3498 addr = AR_GPIO_OUTPUT_MUX1;
3499
3500 gpio_shift = (gpio % 6) * 5;
3501
3502 if (AR_SREV_9280_20_OR_LATER(ah)
3503 || (addr != AR_GPIO_OUTPUT_MUX1)) {
3504 REG_RMW(ah, addr, (type << gpio_shift),
3505 (0x1f << gpio_shift));
3506 } else {
3507 tmp = REG_READ(ah, addr);
3508 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
3509 tmp &= ~(0x1f << gpio_shift);
3510 tmp |= (type << gpio_shift);
3511 REG_WRITE(ah, addr, tmp);
3512 }
3513}
3514
Sujithcbe61d82009-02-09 13:27:12 +05303515void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303516{
3517 u32 gpio_shift;
3518
Sujith2660b812009-02-09 13:27:26 +05303519 ASSERT(gpio < ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05303520
3521 gpio_shift = gpio << 1;
3522
3523 REG_RMW(ah,
3524 AR_GPIO_OE_OUT,
3525 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
3526 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3527}
3528
Sujithcbe61d82009-02-09 13:27:12 +05303529u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303530{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303531#define MS_REG_READ(x, y) \
3532 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
3533
Sujith2660b812009-02-09 13:27:26 +05303534 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05303535 return 0xffffffff;
3536
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303537 if (AR_SREV_9285_10_OR_LATER(ah))
3538 return MS_REG_READ(AR9285, gpio) != 0;
3539 else if (AR_SREV_9280_10_OR_LATER(ah))
3540 return MS_REG_READ(AR928X, gpio) != 0;
3541 else
3542 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05303543}
3544
Sujithcbe61d82009-02-09 13:27:12 +05303545void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05303546 u32 ah_signal_type)
3547{
3548 u32 gpio_shift;
3549
3550 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
3551
3552 gpio_shift = 2 * gpio;
3553
3554 REG_RMW(ah,
3555 AR_GPIO_OE_OUT,
3556 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
3557 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3558}
3559
Sujithcbe61d82009-02-09 13:27:12 +05303560void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05303561{
3562 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
3563 AR_GPIO_BIT(gpio));
3564}
3565
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05303566#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujithcbe61d82009-02-09 13:27:12 +05303567void ath9k_enable_rfkill(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303568{
3569 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
3570 AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
3571
3572 REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2,
3573 AR_GPIO_INPUT_MUX2_RFSILENT);
3574
Sujith2660b812009-02-09 13:27:26 +05303575 ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
Sujithf1dc5602008-10-29 10:16:30 +05303576 REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);
3577}
3578#endif
3579
Sujithcbe61d82009-02-09 13:27:12 +05303580u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303581{
3582 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
3583}
3584
Sujithcbe61d82009-02-09 13:27:12 +05303585void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05303586{
3587 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
3588}
3589
Sujithcbe61d82009-02-09 13:27:12 +05303590bool ath9k_hw_setantennaswitch(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303591 enum ath9k_ant_setting settings,
3592 struct ath9k_channel *chan,
3593 u8 *tx_chainmask,
3594 u8 *rx_chainmask,
3595 u8 *antenna_cfgd)
3596{
Sujithf1dc5602008-10-29 10:16:30 +05303597 static u8 tx_chainmask_cfg, rx_chainmask_cfg;
3598
3599 if (AR_SREV_9280(ah)) {
3600 if (!tx_chainmask_cfg) {
3601
3602 tx_chainmask_cfg = *tx_chainmask;
3603 rx_chainmask_cfg = *rx_chainmask;
3604 }
3605
3606 switch (settings) {
3607 case ATH9K_ANT_FIXED_A:
3608 *tx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3609 *rx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3610 *antenna_cfgd = true;
3611 break;
3612 case ATH9K_ANT_FIXED_B:
Sujith2660b812009-02-09 13:27:26 +05303613 if (ah->caps.tx_chainmask >
Sujithf1dc5602008-10-29 10:16:30 +05303614 ATH9K_ANTENNA1_CHAINMASK) {
3615 *tx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3616 }
3617 *rx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3618 *antenna_cfgd = true;
3619 break;
3620 case ATH9K_ANT_VARIABLE:
3621 *tx_chainmask = tx_chainmask_cfg;
3622 *rx_chainmask = rx_chainmask_cfg;
3623 *antenna_cfgd = true;
3624 break;
3625 default:
3626 break;
3627 }
3628 } else {
Sujith2660b812009-02-09 13:27:26 +05303629 ah->diversity_control = settings;
Sujithf1dc5602008-10-29 10:16:30 +05303630 }
3631
3632 return true;
3633}
3634
3635/*********************/
3636/* General Operation */
3637/*********************/
3638
Sujithcbe61d82009-02-09 13:27:12 +05303639u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303640{
3641 u32 bits = REG_READ(ah, AR_RX_FILTER);
3642 u32 phybits = REG_READ(ah, AR_PHY_ERR);
3643
3644 if (phybits & AR_PHY_ERR_RADAR)
3645 bits |= ATH9K_RX_FILTER_PHYRADAR;
3646 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
3647 bits |= ATH9K_RX_FILTER_PHYERR;
3648
3649 return bits;
3650}
3651
Sujithcbe61d82009-02-09 13:27:12 +05303652void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05303653{
3654 u32 phybits;
3655
3656 REG_WRITE(ah, AR_RX_FILTER, (bits & 0xffff) | AR_RX_COMPR_BAR);
3657 phybits = 0;
3658 if (bits & ATH9K_RX_FILTER_PHYRADAR)
3659 phybits |= AR_PHY_ERR_RADAR;
3660 if (bits & ATH9K_RX_FILTER_PHYERR)
3661 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
3662 REG_WRITE(ah, AR_PHY_ERR, phybits);
3663
3664 if (phybits)
3665 REG_WRITE(ah, AR_RXCFG,
3666 REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
3667 else
3668 REG_WRITE(ah, AR_RXCFG,
3669 REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
3670}
3671
Sujithcbe61d82009-02-09 13:27:12 +05303672bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303673{
3674 return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM);
3675}
3676
Sujithcbe61d82009-02-09 13:27:12 +05303677bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303678{
3679 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
3680 return false;
3681
3682 return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD);
3683}
3684
Sujithcbe61d82009-02-09 13:27:12 +05303685bool ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
Sujithf1dc5602008-10-29 10:16:30 +05303686{
Sujith2660b812009-02-09 13:27:26 +05303687 struct ath9k_channel *chan = ah->curchan;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08003688 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05303689
Sujithd6bad492009-02-09 13:27:08 +05303690 ah->regulatory.power_limit = min(limit, (u32) MAX_RATE_POWER);
Sujithf1dc5602008-10-29 10:16:30 +05303691
Sujithf74df6f2009-02-09 13:27:24 +05303692 if (ah->eep_ops->set_txpower(ah, chan,
3693 ath9k_regd_get_ctl(ah, chan),
3694 channel->max_antenna_gain * 2,
3695 channel->max_power * 2,
3696 min((u32) MAX_RATE_POWER,
3697 (u32) ah->regulatory.power_limit)) != 0)
Sujithf1dc5602008-10-29 10:16:30 +05303698 return false;
3699
3700 return true;
3701}
3702
Sujithcbe61d82009-02-09 13:27:12 +05303703void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac)
Sujithf1dc5602008-10-29 10:16:30 +05303704{
Sujithba52da52009-02-09 13:27:10 +05303705 memcpy(ah->macaddr, mac, ETH_ALEN);
Sujithf1dc5602008-10-29 10:16:30 +05303706}
3707
Sujithcbe61d82009-02-09 13:27:12 +05303708void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303709{
Sujith2660b812009-02-09 13:27:26 +05303710 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05303711}
3712
Sujithcbe61d82009-02-09 13:27:12 +05303713void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05303714{
3715 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
3716 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
3717}
3718
Sujithba52da52009-02-09 13:27:10 +05303719void ath9k_hw_setbssidmask(struct ath_softc *sc)
Sujithf1dc5602008-10-29 10:16:30 +05303720{
Sujithba52da52009-02-09 13:27:10 +05303721 REG_WRITE(sc->sc_ah, AR_BSSMSKL, get_unaligned_le32(sc->bssidmask));
3722 REG_WRITE(sc->sc_ah, AR_BSSMSKU, get_unaligned_le16(sc->bssidmask + 4));
Sujithf1dc5602008-10-29 10:16:30 +05303723}
3724
Sujithba52da52009-02-09 13:27:10 +05303725void ath9k_hw_write_associd(struct ath_softc *sc)
Sujithf1dc5602008-10-29 10:16:30 +05303726{
Sujithba52da52009-02-09 13:27:10 +05303727 REG_WRITE(sc->sc_ah, AR_BSS_ID0, get_unaligned_le32(sc->curbssid));
3728 REG_WRITE(sc->sc_ah, AR_BSS_ID1, get_unaligned_le16(sc->curbssid + 4) |
3729 ((sc->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05303730}
3731
Sujithcbe61d82009-02-09 13:27:12 +05303732u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303733{
3734 u64 tsf;
3735
3736 tsf = REG_READ(ah, AR_TSF_U32);
3737 tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
3738
3739 return tsf;
3740}
3741
Sujithcbe61d82009-02-09 13:27:12 +05303742void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003743{
3744 REG_WRITE(ah, AR_TSF_L32, 0x00000000);
3745 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
3746 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
3747}
3748
Sujithcbe61d82009-02-09 13:27:12 +05303749void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303750{
3751 int count;
3752
3753 count = 0;
3754 while (REG_READ(ah, AR_SLP32_MODE) & AR_SLP32_TSF_WRITE_STATUS) {
3755 count++;
3756 if (count > 10) {
3757 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05303758 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
Sujithf1dc5602008-10-29 10:16:30 +05303759 break;
3760 }
3761 udelay(10);
3762 }
3763 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003764}
3765
Sujithcbe61d82009-02-09 13:27:12 +05303766bool ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003767{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003768 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303769 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003770 else
Sujith2660b812009-02-09 13:27:26 +05303771 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Sujithf1dc5602008-10-29 10:16:30 +05303772
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003773 return true;
3774}
3775
Sujithcbe61d82009-02-09 13:27:12 +05303776bool ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003777{
Sujithf1dc5602008-10-29 10:16:30 +05303778 if (us < ATH9K_SLOT_TIME_9 || us > ath9k_hw_mac_to_usec(ah, 0xffff)) {
Sujith04bd4632008-11-28 22:18:05 +05303779 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "bad slot time %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05303780 ah->slottime = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05303781 return false;
3782 } else {
3783 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05303784 ah->slottime = us;
Sujithf1dc5602008-10-29 10:16:30 +05303785 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003786 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003787}
3788
Sujithcbe61d82009-02-09 13:27:12 +05303789void ath9k_hw_set11nmac2040(struct ath_hw *ah, enum ath9k_ht_macmode mode)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003790{
Sujithf1dc5602008-10-29 10:16:30 +05303791 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003792
Sujithf1dc5602008-10-29 10:16:30 +05303793 if (mode == ATH9K_HT_MACMODE_2040 &&
Sujith2660b812009-02-09 13:27:26 +05303794 !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05303795 macmode = AR_2040_JOINED_RX_CLEAR;
3796 else
3797 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003798
Sujithf1dc5602008-10-29 10:16:30 +05303799 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003800}
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303801
3802/***************************/
3803/* Bluetooth Coexistence */
3804/***************************/
3805
Sujithcbe61d82009-02-09 13:27:12 +05303806void ath9k_hw_btcoex_enable(struct ath_hw *ah)
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303807{
3808 /* connect bt_active to baseband */
3809 REG_CLR_BIT(ah, AR_GPIO_INPUT_EN_VAL,
3810 (AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_DEF |
3811 AR_GPIO_INPUT_EN_VAL_BT_FREQUENCY_DEF));
3812
3813 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
3814 AR_GPIO_INPUT_EN_VAL_BT_ACTIVE_BB);
3815
3816 /* Set input mux for bt_active to gpio pin */
3817 REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1,
3818 AR_GPIO_INPUT_MUX1_BT_ACTIVE,
Sujith2660b812009-02-09 13:27:26 +05303819 ah->btactive_gpio);
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303820
3821 /* Configure the desired gpio port for input */
Sujith2660b812009-02-09 13:27:26 +05303822 ath9k_hw_cfg_gpio_input(ah, ah->btactive_gpio);
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303823
3824 /* Configure the desired GPIO port for TX_FRAME output */
Sujith2660b812009-02-09 13:27:26 +05303825 ath9k_hw_cfg_output(ah, ah->wlanactive_gpio,
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303826 AR_GPIO_OUTPUT_MUX_AS_TX_FRAME);
3827}