blob: 5c870436fc5f85a5879445a663788bdefd06d367 [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
20#include "core.h"
21#include "hw.h"
22#include "reg.h"
23#include "phy.h"
24#include "initvals.h"
25
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070026static const u8 CLOCK_RATE[] = { 40, 80, 22, 44, 88, 40 };
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070027
Sujithf1dc5602008-10-29 10:16:30 +053028extern struct hal_percal_data iq_cal_multi_sample;
29extern struct hal_percal_data iq_cal_single_sample;
30extern struct hal_percal_data adc_gain_cal_multi_sample;
31extern struct hal_percal_data adc_gain_cal_single_sample;
32extern struct hal_percal_data adc_dc_cal_multi_sample;
33extern struct hal_percal_data adc_dc_cal_single_sample;
34extern struct hal_percal_data adc_init_dc_cal;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070035
Sujithf1dc5602008-10-29 10:16:30 +053036static bool ath9k_hw_set_reset_reg(struct ath_hal *ah, u32 type);
37static void ath9k_hw_set_regs(struct ath_hal *ah, struct ath9k_channel *chan,
38 enum ath9k_ht_macmode macmode);
39static u32 ath9k_hw_ini_fixup(struct ath_hal *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +053040 struct ar5416_eeprom_def *pEepData,
Sujithf1dc5602008-10-29 10:16:30 +053041 u32 reg, u32 value);
42static void ath9k_hw_9280_spur_mitigate(struct ath_hal *ah, struct ath9k_channel *chan);
43static void ath9k_hw_spur_mitigate(struct ath_hal *ah, struct ath9k_channel *chan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070044
Sujithf1dc5602008-10-29 10:16:30 +053045/********************/
46/* Helper Functions */
47/********************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070048
Sujithf1dc5602008-10-29 10:16:30 +053049static u32 ath9k_hw_mac_usec(struct ath_hal *ah, u32 clks)
50{
51 if (ah->ah_curchan != NULL)
52 return clks / CLOCK_RATE[ath9k_hw_chan2wmode(ah, ah->ah_curchan)];
53 else
54 return clks / CLOCK_RATE[ATH9K_MODE_11B];
55}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070056
Sujithf1dc5602008-10-29 10:16:30 +053057static u32 ath9k_hw_mac_to_usec(struct ath_hal *ah, u32 clks)
58{
59 struct ath9k_channel *chan = ah->ah_curchan;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070060
Sujithf1dc5602008-10-29 10:16:30 +053061 if (chan && IS_CHAN_HT40(chan))
62 return ath9k_hw_mac_usec(ah, clks) / 2;
63 else
64 return ath9k_hw_mac_usec(ah, clks);
65}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070066
Sujithf1dc5602008-10-29 10:16:30 +053067static u32 ath9k_hw_mac_clks(struct ath_hal *ah, u32 usecs)
68{
69 if (ah->ah_curchan != NULL)
70 return usecs * CLOCK_RATE[ath9k_hw_chan2wmode(ah,
71 ah->ah_curchan)];
72 else
73 return usecs * CLOCK_RATE[ATH9K_MODE_11B];
74}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070075
Sujithf1dc5602008-10-29 10:16:30 +053076static u32 ath9k_hw_mac_to_clks(struct ath_hal *ah, u32 usecs)
77{
78 struct ath9k_channel *chan = ah->ah_curchan;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070079
Sujithf1dc5602008-10-29 10:16:30 +053080 if (chan && IS_CHAN_HT40(chan))
81 return ath9k_hw_mac_clks(ah, usecs) * 2;
82 else
83 return ath9k_hw_mac_clks(ah, usecs);
84}
85
86enum wireless_mode ath9k_hw_chan2wmode(struct ath_hal *ah,
87 const struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070088{
Sujith788a3d62008-11-18 09:09:54 +053089 if (IS_CHAN_B(chan))
90 return ATH9K_MODE_11B;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070091 if (IS_CHAN_G(chan))
Sujith86b89ee2008-08-07 10:54:57 +053092 return ATH9K_MODE_11G;
Sujith788a3d62008-11-18 09:09:54 +053093
Sujith86b89ee2008-08-07 10:54:57 +053094 return ATH9K_MODE_11A;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070095}
96
Sujithf1dc5602008-10-29 10:16:30 +053097bool ath9k_hw_wait(struct ath_hal *ah, u32 reg, u32 mask, u32 val)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070098{
99 int i;
100
101 for (i = 0; i < (AH_TIMEOUT / AH_TIME_QUANTUM); i++) {
102 if ((REG_READ(ah, reg) & mask) == val)
103 return true;
104
105 udelay(AH_TIME_QUANTUM);
106 }
Sujith04bd4632008-11-28 22:18:05 +0530107
108 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
109 "timeout on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
110 reg, REG_READ(ah, reg), mask, val);
Sujithf1dc5602008-10-29 10:16:30 +0530111
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700112 return false;
113}
114
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700115u32 ath9k_hw_reverse_bits(u32 val, u32 n)
116{
117 u32 retval;
118 int i;
119
120 for (i = 0, retval = 0; i < n; i++) {
121 retval = (retval << 1) | (val & 1);
122 val >>= 1;
123 }
124 return retval;
125}
126
Sujithf1dc5602008-10-29 10:16:30 +0530127bool ath9k_get_channel_edges(struct ath_hal *ah,
128 u16 flags, u16 *low,
129 u16 *high)
130{
131 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
132
133 if (flags & CHANNEL_5GHZ) {
134 *low = pCap->low_5ghz_chan;
135 *high = pCap->high_5ghz_chan;
136 return true;
137 }
138 if ((flags & CHANNEL_2GHZ)) {
139 *low = pCap->low_2ghz_chan;
140 *high = pCap->high_2ghz_chan;
141 return true;
142 }
143 return false;
144}
145
146u16 ath9k_hw_computetxtime(struct ath_hal *ah,
Sujithe63835b2008-11-18 09:07:53 +0530147 struct ath_rate_table *rates,
Sujithf1dc5602008-10-29 10:16:30 +0530148 u32 frameLen, u16 rateix,
149 bool shortPreamble)
150{
151 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
152 u32 kbps;
153
Sujithe63835b2008-11-18 09:07:53 +0530154 kbps = rates->info[rateix].ratekbps;
Sujithf1dc5602008-10-29 10:16:30 +0530155
156 if (kbps == 0)
157 return 0;
158
159 switch (rates->info[rateix].phy) {
Sujith46d14a52008-11-18 09:08:13 +0530160 case WLAN_RC_PHY_CCK:
Sujithf1dc5602008-10-29 10:16:30 +0530161 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
Sujithe63835b2008-11-18 09:07:53 +0530162 if (shortPreamble && rates->info[rateix].short_preamble)
Sujithf1dc5602008-10-29 10:16:30 +0530163 phyTime >>= 1;
164 numBits = frameLen << 3;
165 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
166 break;
Sujith46d14a52008-11-18 09:08:13 +0530167 case WLAN_RC_PHY_OFDM:
Sujithf1dc5602008-10-29 10:16:30 +0530168 if (ah->ah_curchan && IS_CHAN_QUARTER_RATE(ah->ah_curchan)) {
169 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
170 numBits = OFDM_PLCP_BITS + (frameLen << 3);
171 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
172 txTime = OFDM_SIFS_TIME_QUARTER
173 + OFDM_PREAMBLE_TIME_QUARTER
174 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
175 } else if (ah->ah_curchan &&
176 IS_CHAN_HALF_RATE(ah->ah_curchan)) {
177 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
178 numBits = OFDM_PLCP_BITS + (frameLen << 3);
179 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
180 txTime = OFDM_SIFS_TIME_HALF +
181 OFDM_PREAMBLE_TIME_HALF
182 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
183 } else {
184 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
185 numBits = OFDM_PLCP_BITS + (frameLen << 3);
186 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
187 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
188 + (numSymbols * OFDM_SYMBOL_TIME);
189 }
190 break;
191 default:
Sujith04bd4632008-11-28 22:18:05 +0530192 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
193 "Unknown phy %u (rate ix %u)\n",
Sujithf1dc5602008-10-29 10:16:30 +0530194 rates->info[rateix].phy, rateix);
195 txTime = 0;
196 break;
197 }
198
199 return txTime;
200}
201
202u32 ath9k_hw_mhz2ieee(struct ath_hal *ah, u32 freq, u32 flags)
203{
204 if (flags & CHANNEL_2GHZ) {
205 if (freq == 2484)
206 return 14;
207 if (freq < 2484)
208 return (freq - 2407) / 5;
209 else
210 return 15 + ((freq - 2512) / 20);
211 } else if (flags & CHANNEL_5GHZ) {
212 if (ath9k_regd_is_public_safety_sku(ah) &&
213 IS_CHAN_IN_PUBLIC_SAFETY_BAND(freq)) {
214 return ((freq * 10) +
215 (((freq % 5) == 2) ? 5 : 0) - 49400) / 5;
216 } else if ((flags & CHANNEL_A) && (freq <= 5000)) {
217 return (freq - 4000) / 5;
218 } else {
219 return (freq - 5000) / 5;
220 }
221 } else {
222 if (freq == 2484)
223 return 14;
224 if (freq < 2484)
225 return (freq - 2407) / 5;
226 if (freq < 5000) {
227 if (ath9k_regd_is_public_safety_sku(ah)
228 && IS_CHAN_IN_PUBLIC_SAFETY_BAND(freq)) {
229 return ((freq * 10) +
230 (((freq % 5) ==
231 2) ? 5 : 0) - 49400) / 5;
232 } else if (freq > 4900) {
233 return (freq - 4000) / 5;
234 } else {
235 return 15 + ((freq - 2512) / 20);
236 }
237 }
238 return (freq - 5000) / 5;
239 }
240}
241
242void ath9k_hw_get_channel_centers(struct ath_hal *ah,
243 struct ath9k_channel *chan,
244 struct chan_centers *centers)
245{
246 int8_t extoff;
247 struct ath_hal_5416 *ahp = AH5416(ah);
248
249 if (!IS_CHAN_HT40(chan)) {
250 centers->ctl_center = centers->ext_center =
251 centers->synth_center = chan->channel;
252 return;
253 }
254
255 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
256 (chan->chanmode == CHANNEL_G_HT40PLUS)) {
257 centers->synth_center =
258 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
259 extoff = 1;
260 } else {
261 centers->synth_center =
262 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
263 extoff = -1;
264 }
265
266 centers->ctl_center =
267 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
268 centers->ext_center =
269 centers->synth_center + (extoff *
270 ((ahp->ah_extprotspacing == ATH9K_HT_EXTPROTSPACING_20) ?
271 HT40_CHANNEL_CENTER_SHIFT : 15));
272
273}
274
275/******************/
276/* Chip Revisions */
277/******************/
278
279static void ath9k_hw_read_revisions(struct ath_hal *ah)
280{
281 u32 val;
282
283 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
284
285 if (val == 0xFF) {
286 val = REG_READ(ah, AR_SREV);
287 ah->ah_macVersion = (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
288 ah->ah_macRev = MS(val, AR_SREV_REVISION2);
289 ah->ah_isPciExpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
290 } else {
291 if (!AR_SREV_9100(ah))
292 ah->ah_macVersion = MS(val, AR_SREV_VERSION);
293
294 ah->ah_macRev = val & AR_SREV_REVISION;
295
296 if (ah->ah_macVersion == AR_SREV_VERSION_5416_PCIE)
297 ah->ah_isPciExpress = true;
298 }
299}
300
301static int ath9k_hw_get_radiorev(struct ath_hal *ah)
302{
303 u32 val;
304 int i;
305
306 REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
307
308 for (i = 0; i < 8; i++)
309 REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
310 val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
311 val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
312
313 return ath9k_hw_reverse_bits(val, 8);
314}
315
316/************************************/
317/* HW Attach, Detach, Init Routines */
318/************************************/
319
320static void ath9k_hw_disablepcie(struct ath_hal *ah)
321{
322 if (!AR_SREV_9100(ah))
323 return;
324
325 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
326 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
327 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
328 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
329 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
330 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
331 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
332 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
333 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
334
335 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
336}
337
338static bool ath9k_hw_chip_test(struct ath_hal *ah)
339{
340 u32 regAddr[2] = { AR_STA_ID0, AR_PHY_BASE + (8 << 2) };
341 u32 regHold[2];
342 u32 patternData[4] = { 0x55555555,
343 0xaaaaaaaa,
344 0x66666666,
345 0x99999999 };
346 int i, j;
347
348 for (i = 0; i < 2; i++) {
349 u32 addr = regAddr[i];
350 u32 wrData, rdData;
351
352 regHold[i] = REG_READ(ah, addr);
353 for (j = 0; j < 0x100; j++) {
354 wrData = (j << 16) | j;
355 REG_WRITE(ah, addr, wrData);
356 rdData = REG_READ(ah, addr);
357 if (rdData != wrData) {
358 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
Sujith04bd4632008-11-28 22:18:05 +0530359 "address test failed "
Sujithf1dc5602008-10-29 10:16:30 +0530360 "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
Sujith04bd4632008-11-28 22:18:05 +0530361 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530362 return false;
363 }
364 }
365 for (j = 0; j < 4; j++) {
366 wrData = patternData[j];
367 REG_WRITE(ah, addr, wrData);
368 rdData = REG_READ(ah, addr);
369 if (wrData != rdData) {
370 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
Sujith04bd4632008-11-28 22:18:05 +0530371 "address test failed "
Sujithf1dc5602008-10-29 10:16:30 +0530372 "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
Sujith04bd4632008-11-28 22:18:05 +0530373 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530374 return false;
375 }
376 }
377 REG_WRITE(ah, regAddr[i], regHold[i]);
378 }
379 udelay(100);
380 return true;
381}
382
383static const char *ath9k_hw_devname(u16 devid)
384{
385 switch (devid) {
386 case AR5416_DEVID_PCI:
Sujithf1dc5602008-10-29 10:16:30 +0530387 return "Atheros 5416";
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +0100388 case AR5416_DEVID_PCIE:
389 return "Atheros 5418";
Sujithf1dc5602008-10-29 10:16:30 +0530390 case AR9160_DEVID_PCI:
391 return "Atheros 9160";
392 case AR9280_DEVID_PCI:
393 case AR9280_DEVID_PCIE:
394 return "Atheros 9280";
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530395 case AR9285_DEVID_PCIE:
396 return "Atheros 9285";
Sujithf1dc5602008-10-29 10:16:30 +0530397 }
398
399 return NULL;
400}
401
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700402static void ath9k_hw_set_defaults(struct ath_hal *ah)
403{
404 int i;
405
Sujith60b67f52008-08-07 10:52:38 +0530406 ah->ah_config.dma_beacon_response_time = 2;
407 ah->ah_config.sw_beacon_response_time = 10;
408 ah->ah_config.additional_swba_backoff = 0;
409 ah->ah_config.ack_6mb = 0x0;
410 ah->ah_config.cwm_ignore_extcca = 0;
411 ah->ah_config.pcie_powersave_enable = 0;
412 ah->ah_config.pcie_l1skp_enable = 0;
413 ah->ah_config.pcie_clock_req = 0;
414 ah->ah_config.pcie_power_reset = 0x100;
415 ah->ah_config.pcie_restore = 0;
416 ah->ah_config.pcie_waen = 0;
417 ah->ah_config.analog_shiftreg = 1;
418 ah->ah_config.ht_enable = 1;
419 ah->ah_config.ofdm_trig_low = 200;
420 ah->ah_config.ofdm_trig_high = 500;
421 ah->ah_config.cck_trig_high = 200;
422 ah->ah_config.cck_trig_low = 100;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -0700423 ah->ah_config.enable_ani = 1;
Sujith60b67f52008-08-07 10:52:38 +0530424 ah->ah_config.noise_immunity_level = 4;
425 ah->ah_config.ofdm_weaksignal_det = 1;
426 ah->ah_config.cck_weaksignal_thr = 0;
427 ah->ah_config.spur_immunity_level = 2;
428 ah->ah_config.firstep_level = 0;
429 ah->ah_config.rssi_thr_high = 40;
430 ah->ah_config.rssi_thr_low = 7;
431 ah->ah_config.diversity_control = 0;
432 ah->ah_config.antenna_switch_swap = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700433
434 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujith60b67f52008-08-07 10:52:38 +0530435 ah->ah_config.spurchans[i][0] = AR_NO_SPUR;
436 ah->ah_config.spurchans[i][1] = AR_NO_SPUR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700437 }
438
Luis R. Rodriguezf97e4002008-10-22 13:28:44 -0700439 ah->ah_config.intr_mitigation = 1;
Luis R. Rodriguez61584252009-03-12 18:18:49 -0400440
441 /*
442 * We need this for PCI devices only (Cardbus, PCI, miniPCI)
443 * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
444 * This means we use it for all AR5416 devices, and the few
445 * minor PCI AR9280 devices out there.
446 *
447 * Serialization is required because these devices do not handle
448 * well the case of two concurrent reads/writes due to the latency
449 * involved. During one read/write another read/write can be issued
450 * on another CPU while the previous read/write may still be working
451 * on our hardware, if we hit this case the hardware poops in a loop.
452 * We prevent this by serializing reads and writes.
453 *
454 * This issue is not present on PCI-Express devices or pre-AR5416
455 * devices (legacy, 802.11abg).
456 */
457 if (num_possible_cpus() > 1)
458 ah->ah_config.serialize_regmode = SER_REG_MODE_AUTO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700459}
460
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700461static struct ath_hal_5416 *ath9k_hw_newstate(u16 devid,
462 struct ath_softc *sc,
463 void __iomem *mem,
464 int *status)
465{
466 static const u8 defbssidmask[ETH_ALEN] =
467 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
468 struct ath_hal_5416 *ahp;
469 struct ath_hal *ah;
470
471 ahp = kzalloc(sizeof(struct ath_hal_5416), GFP_KERNEL);
472 if (ahp == NULL) {
473 DPRINTF(sc, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +0530474 "Cannot allocate memory for state block\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700475 *status = -ENOMEM;
476 return NULL;
477 }
478
479 ah = &ahp->ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700480 ah->ah_sc = sc;
481 ah->ah_sh = mem;
Sujithd2d80ee2008-08-11 14:04:13 +0530482 ah->ah_magic = AR5416_MAGIC;
483 ah->ah_countryCode = CTRY_DEFAULT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700484 ah->ah_devid = devid;
485 ah->ah_subvendorid = 0;
486
487 ah->ah_flags = 0;
488 if ((devid == AR5416_AR9100_DEVID))
489 ah->ah_macVersion = AR_SREV_VERSION_9100;
490 if (!AR_SREV_9100(ah))
491 ah->ah_flags = AH_USE_EEPROM;
492
493 ah->ah_powerLimit = MAX_RATE_POWER;
494 ah->ah_tpScale = ATH9K_TP_SCALE_MAX;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700495 ahp->ah_atimWindow = 0;
Sujith60b67f52008-08-07 10:52:38 +0530496 ahp->ah_diversityControl = ah->ah_config.diversity_control;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700497 ahp->ah_antennaSwitchSwap =
Sujith60b67f52008-08-07 10:52:38 +0530498 ah->ah_config.antenna_switch_swap;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700499 ahp->ah_staId1Defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
500 ahp->ah_beaconInterval = 100;
501 ahp->ah_enable32kHzClock = DONT_USE_32KHZ;
502 ahp->ah_slottime = (u32) -1;
503 ahp->ah_acktimeout = (u32) -1;
504 ahp->ah_ctstimeout = (u32) -1;
505 ahp->ah_globaltxtimeout = (u32) -1;
506 memcpy(&ahp->ah_bssidmask, defbssidmask, ETH_ALEN);
507
508 ahp->ah_gBeaconRate = 0;
509
510 return ahp;
511}
512
Sujithff9b6622008-08-14 13:27:16 +0530513static int ath9k_hw_rfattach(struct ath_hal *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700514{
515 bool rfStatus = false;
516 int ecode = 0;
517
518 rfStatus = ath9k_hw_init_rf(ah, &ecode);
519 if (!rfStatus) {
520 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +0530521 "RF setup failed, status %u\n", ecode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700522 return ecode;
523 }
524
525 return 0;
526}
527
528static int ath9k_hw_rf_claim(struct ath_hal *ah)
529{
530 u32 val;
531
532 REG_WRITE(ah, AR_PHY(0), 0x00000007);
533
534 val = ath9k_hw_get_radiorev(ah);
535 switch (val & AR_RADIO_SREV_MAJOR) {
536 case 0:
537 val = AR_RAD5133_SREV_MAJOR;
538 break;
539 case AR_RAD5133_SREV_MAJOR:
540 case AR_RAD5122_SREV_MAJOR:
541 case AR_RAD2133_SREV_MAJOR:
542 case AR_RAD2122_SREV_MAJOR:
543 break;
544 default:
545 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
Sujith04bd4632008-11-28 22:18:05 +0530546 "5G Radio Chip Rev 0x%02X is not "
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700547 "supported by this driver\n",
Sujith04bd4632008-11-28 22:18:05 +0530548 ah->ah_analog5GhzRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700549 return -EOPNOTSUPP;
550 }
551
552 ah->ah_analog5GhzRev = val;
553
554 return 0;
555}
556
Sujithf1dc5602008-10-29 10:16:30 +0530557static int ath9k_hw_init_macaddr(struct ath_hal *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700558{
Sujithf1dc5602008-10-29 10:16:30 +0530559 u32 sum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700560 int i;
Sujithf1dc5602008-10-29 10:16:30 +0530561 u16 eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700562 struct ath_hal_5416 *ahp = AH5416(ah);
563
Sujithf1dc5602008-10-29 10:16:30 +0530564 sum = 0;
565 for (i = 0; i < 3; i++) {
566 eeval = ath9k_hw_get_eeprom(ah, AR_EEPROM_MAC(i));
567 sum += eeval;
568 ahp->ah_macaddr[2 * i] = eeval >> 8;
569 ahp->ah_macaddr[2 * i + 1] = eeval & 0xff;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700570 }
Sujithf1dc5602008-10-29 10:16:30 +0530571 if (sum == 0 || sum == 0xffff * 3) {
572 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
Sujith04bd4632008-11-28 22:18:05 +0530573 "mac address read failed: %pM\n",
Sujithf1dc5602008-10-29 10:16:30 +0530574 ahp->ah_macaddr);
575 return -EADDRNOTAVAIL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700576 }
577
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700578 return 0;
579}
580
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530581static void ath9k_hw_init_rxgain_ini(struct ath_hal *ah)
582{
583 u32 rxgain_type;
584 struct ath_hal_5416 *ahp = AH5416(ah);
585
586 if (ath9k_hw_get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_17) {
587 rxgain_type = ath9k_hw_get_eeprom(ah, EEP_RXGAIN_TYPE);
588
589 if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
590 INIT_INI_ARRAY(&ahp->ah_iniModesRxGain,
591 ar9280Modes_backoff_13db_rxgain_9280_2,
592 ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2), 6);
593 else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF)
594 INIT_INI_ARRAY(&ahp->ah_iniModesRxGain,
595 ar9280Modes_backoff_23db_rxgain_9280_2,
596 ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 6);
597 else
598 INIT_INI_ARRAY(&ahp->ah_iniModesRxGain,
599 ar9280Modes_original_rxgain_9280_2,
600 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
601 } else
602 INIT_INI_ARRAY(&ahp->ah_iniModesRxGain,
603 ar9280Modes_original_rxgain_9280_2,
604 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
605}
606
607static void ath9k_hw_init_txgain_ini(struct ath_hal *ah)
608{
609 u32 txgain_type;
610 struct ath_hal_5416 *ahp = AH5416(ah);
611
612 if (ath9k_hw_get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_19) {
613 txgain_type = ath9k_hw_get_eeprom(ah, EEP_TXGAIN_TYPE);
614
615 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
616 INIT_INI_ARRAY(&ahp->ah_iniModesTxGain,
617 ar9280Modes_high_power_tx_gain_9280_2,
618 ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 6);
619 else
620 INIT_INI_ARRAY(&ahp->ah_iniModesTxGain,
621 ar9280Modes_original_tx_gain_9280_2,
622 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
623 } else
624 INIT_INI_ARRAY(&ahp->ah_iniModesTxGain,
625 ar9280Modes_original_tx_gain_9280_2,
626 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
627}
628
Sujithff9b6622008-08-14 13:27:16 +0530629static int ath9k_hw_post_attach(struct ath_hal *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700630{
631 int ecode;
632
633 if (!ath9k_hw_chip_test(ah)) {
634 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
Sujith04bd4632008-11-28 22:18:05 +0530635 "hardware self-test failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700636 return -ENODEV;
637 }
638
639 ecode = ath9k_hw_rf_claim(ah);
640 if (ecode != 0)
641 return ecode;
642
643 ecode = ath9k_hw_eeprom_attach(ah);
644 if (ecode != 0)
645 return ecode;
646 ecode = ath9k_hw_rfattach(ah);
647 if (ecode != 0)
648 return ecode;
649
650 if (!AR_SREV_9100(ah)) {
651 ath9k_hw_ani_setup(ah);
652 ath9k_hw_ani_attach(ah);
653 }
Sujithf1dc5602008-10-29 10:16:30 +0530654
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700655 return 0;
656}
657
Sujithf1dc5602008-10-29 10:16:30 +0530658static struct ath_hal *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc,
659 void __iomem *mem, int *status)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700660{
661 struct ath_hal_5416 *ahp;
662 struct ath_hal *ah;
663 int ecode;
Sujithf6688cd2008-12-07 21:43:10 +0530664 u32 i, j;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700665
666 ahp = ath9k_hw_newstate(devid, sc, mem, status);
667 if (ahp == NULL)
668 return NULL;
669
670 ah = &ahp->ah;
671
672 ath9k_hw_set_defaults(ah);
673
Sujith60b67f52008-08-07 10:52:38 +0530674 if (ah->ah_config.intr_mitigation != 0)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700675 ahp->ah_intrMitigation = true;
676
677 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Sujith04bd4632008-11-28 22:18:05 +0530678 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "Couldn't reset chip\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700679 ecode = -EIO;
680 goto bad;
681 }
682
683 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
Sujith04bd4632008-11-28 22:18:05 +0530684 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "Couldn't wakeup chip\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700685 ecode = -EIO;
686 goto bad;
687 }
688
Sujith60b67f52008-08-07 10:52:38 +0530689 if (ah->ah_config.serialize_regmode == SER_REG_MODE_AUTO) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700690 if (ah->ah_macVersion == AR_SREV_VERSION_5416_PCI) {
Sujith60b67f52008-08-07 10:52:38 +0530691 ah->ah_config.serialize_regmode =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700692 SER_REG_MODE_ON;
693 } else {
Sujith60b67f52008-08-07 10:52:38 +0530694 ah->ah_config.serialize_regmode =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700695 SER_REG_MODE_OFF;
696 }
697 }
Sujithf1dc5602008-10-29 10:16:30 +0530698
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700699 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +0530700 "serialize_regmode is %d\n",
701 ah->ah_config.serialize_regmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700702
703 if ((ah->ah_macVersion != AR_SREV_VERSION_5416_PCI) &&
704 (ah->ah_macVersion != AR_SREV_VERSION_5416_PCIE) &&
705 (ah->ah_macVersion != AR_SREV_VERSION_9160) &&
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530706 (!AR_SREV_9100(ah)) && (!AR_SREV_9280(ah)) && (!AR_SREV_9285(ah))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700707 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +0530708 "Mac Chip Rev 0x%02x.%x is not supported by "
709 "this driver\n", ah->ah_macVersion, ah->ah_macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700710 ecode = -EOPNOTSUPP;
711 goto bad;
712 }
713
714 if (AR_SREV_9100(ah)) {
715 ahp->ah_iqCalData.calData = &iq_cal_multi_sample;
716 ahp->ah_suppCals = IQ_MISMATCH_CAL;
717 ah->ah_isPciExpress = false;
718 }
719 ah->ah_phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
720
721 if (AR_SREV_9160_10_OR_LATER(ah)) {
722 if (AR_SREV_9280_10_OR_LATER(ah)) {
723 ahp->ah_iqCalData.calData = &iq_cal_single_sample;
724 ahp->ah_adcGainCalData.calData =
725 &adc_gain_cal_single_sample;
726 ahp->ah_adcDcCalData.calData =
727 &adc_dc_cal_single_sample;
728 ahp->ah_adcDcCalInitData.calData =
729 &adc_init_dc_cal;
730 } else {
731 ahp->ah_iqCalData.calData = &iq_cal_multi_sample;
732 ahp->ah_adcGainCalData.calData =
733 &adc_gain_cal_multi_sample;
734 ahp->ah_adcDcCalData.calData =
735 &adc_dc_cal_multi_sample;
736 ahp->ah_adcDcCalInitData.calData =
737 &adc_init_dc_cal;
738 }
Sujithf1dc5602008-10-29 10:16:30 +0530739 ahp->ah_suppCals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700740 }
741
742 if (AR_SREV_9160(ah)) {
Sujith60b67f52008-08-07 10:52:38 +0530743 ah->ah_config.enable_ani = 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700744 ahp->ah_ani_function = (ATH9K_ANI_SPUR_IMMUNITY_LEVEL |
745 ATH9K_ANI_FIRSTEP_LEVEL);
746 } else {
747 ahp->ah_ani_function = ATH9K_ANI_ALL;
748 if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +0530749 ahp->ah_ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700750 }
751 }
752
753 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +0530754 "This Mac Chip Rev 0x%02x.%x is \n",
Sujithf1dc5602008-10-29 10:16:30 +0530755 ah->ah_macVersion, ah->ah_macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700756
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530757 if (AR_SREV_9285_12_OR_LATER(ah)) {
758 INIT_INI_ARRAY(&ahp->ah_iniModes, ar9285Modes_9285_1_2,
759 ARRAY_SIZE(ar9285Modes_9285_1_2), 6);
760 INIT_INI_ARRAY(&ahp->ah_iniCommon, ar9285Common_9285_1_2,
761 ARRAY_SIZE(ar9285Common_9285_1_2), 2);
762
763 if (ah->ah_config.pcie_clock_req) {
764 INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
765 ar9285PciePhy_clkreq_off_L1_9285_1_2,
766 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2);
767 } else {
768 INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
769 ar9285PciePhy_clkreq_always_on_L1_9285_1_2,
770 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2),
771 2);
772 }
773 } else if (AR_SREV_9285_10_OR_LATER(ah)) {
774 INIT_INI_ARRAY(&ahp->ah_iniModes, ar9285Modes_9285,
775 ARRAY_SIZE(ar9285Modes_9285), 6);
776 INIT_INI_ARRAY(&ahp->ah_iniCommon, ar9285Common_9285,
777 ARRAY_SIZE(ar9285Common_9285), 2);
778
779 if (ah->ah_config.pcie_clock_req) {
780 INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
781 ar9285PciePhy_clkreq_off_L1_9285,
782 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2);
783 } else {
784 INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
785 ar9285PciePhy_clkreq_always_on_L1_9285,
786 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285), 2);
787 }
788 } else if (AR_SREV_9280_20_OR_LATER(ah)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700789 INIT_INI_ARRAY(&ahp->ah_iniModes, ar9280Modes_9280_2,
790 ARRAY_SIZE(ar9280Modes_9280_2), 6);
791 INIT_INI_ARRAY(&ahp->ah_iniCommon, ar9280Common_9280_2,
792 ARRAY_SIZE(ar9280Common_9280_2), 2);
793
Sujith60b67f52008-08-07 10:52:38 +0530794 if (ah->ah_config.pcie_clock_req) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700795 INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530796 ar9280PciePhy_clkreq_off_L1_9280,
797 ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700798 } else {
799 INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530800 ar9280PciePhy_clkreq_always_on_L1_9280,
801 ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700802 }
803 INIT_INI_ARRAY(&ahp->ah_iniModesAdditional,
804 ar9280Modes_fast_clock_9280_2,
Sujithf1dc5602008-10-29 10:16:30 +0530805 ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700806 } else if (AR_SREV_9280_10_OR_LATER(ah)) {
807 INIT_INI_ARRAY(&ahp->ah_iniModes, ar9280Modes_9280,
808 ARRAY_SIZE(ar9280Modes_9280), 6);
809 INIT_INI_ARRAY(&ahp->ah_iniCommon, ar9280Common_9280,
810 ARRAY_SIZE(ar9280Common_9280), 2);
811 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
812 INIT_INI_ARRAY(&ahp->ah_iniModes, ar5416Modes_9160,
813 ARRAY_SIZE(ar5416Modes_9160), 6);
814 INIT_INI_ARRAY(&ahp->ah_iniCommon, ar5416Common_9160,
815 ARRAY_SIZE(ar5416Common_9160), 2);
816 INIT_INI_ARRAY(&ahp->ah_iniBank0, ar5416Bank0_9160,
817 ARRAY_SIZE(ar5416Bank0_9160), 2);
818 INIT_INI_ARRAY(&ahp->ah_iniBB_RfGain, ar5416BB_RfGain_9160,
819 ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
820 INIT_INI_ARRAY(&ahp->ah_iniBank1, ar5416Bank1_9160,
821 ARRAY_SIZE(ar5416Bank1_9160), 2);
822 INIT_INI_ARRAY(&ahp->ah_iniBank2, ar5416Bank2_9160,
823 ARRAY_SIZE(ar5416Bank2_9160), 2);
824 INIT_INI_ARRAY(&ahp->ah_iniBank3, ar5416Bank3_9160,
825 ARRAY_SIZE(ar5416Bank3_9160), 3);
826 INIT_INI_ARRAY(&ahp->ah_iniBank6, ar5416Bank6_9160,
827 ARRAY_SIZE(ar5416Bank6_9160), 3);
828 INIT_INI_ARRAY(&ahp->ah_iniBank6TPC, ar5416Bank6TPC_9160,
829 ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
830 INIT_INI_ARRAY(&ahp->ah_iniBank7, ar5416Bank7_9160,
831 ARRAY_SIZE(ar5416Bank7_9160), 2);
832 if (AR_SREV_9160_11(ah)) {
833 INIT_INI_ARRAY(&ahp->ah_iniAddac,
834 ar5416Addac_91601_1,
835 ARRAY_SIZE(ar5416Addac_91601_1), 2);
836 } else {
837 INIT_INI_ARRAY(&ahp->ah_iniAddac, ar5416Addac_9160,
838 ARRAY_SIZE(ar5416Addac_9160), 2);
839 }
840 } else if (AR_SREV_9100_OR_LATER(ah)) {
841 INIT_INI_ARRAY(&ahp->ah_iniModes, ar5416Modes_9100,
842 ARRAY_SIZE(ar5416Modes_9100), 6);
843 INIT_INI_ARRAY(&ahp->ah_iniCommon, ar5416Common_9100,
844 ARRAY_SIZE(ar5416Common_9100), 2);
845 INIT_INI_ARRAY(&ahp->ah_iniBank0, ar5416Bank0_9100,
846 ARRAY_SIZE(ar5416Bank0_9100), 2);
847 INIT_INI_ARRAY(&ahp->ah_iniBB_RfGain, ar5416BB_RfGain_9100,
848 ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
849 INIT_INI_ARRAY(&ahp->ah_iniBank1, ar5416Bank1_9100,
850 ARRAY_SIZE(ar5416Bank1_9100), 2);
851 INIT_INI_ARRAY(&ahp->ah_iniBank2, ar5416Bank2_9100,
852 ARRAY_SIZE(ar5416Bank2_9100), 2);
853 INIT_INI_ARRAY(&ahp->ah_iniBank3, ar5416Bank3_9100,
854 ARRAY_SIZE(ar5416Bank3_9100), 3);
855 INIT_INI_ARRAY(&ahp->ah_iniBank6, ar5416Bank6_9100,
856 ARRAY_SIZE(ar5416Bank6_9100), 3);
857 INIT_INI_ARRAY(&ahp->ah_iniBank6TPC, ar5416Bank6TPC_9100,
858 ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
859 INIT_INI_ARRAY(&ahp->ah_iniBank7, ar5416Bank7_9100,
860 ARRAY_SIZE(ar5416Bank7_9100), 2);
861 INIT_INI_ARRAY(&ahp->ah_iniAddac, ar5416Addac_9100,
862 ARRAY_SIZE(ar5416Addac_9100), 2);
863 } else {
864 INIT_INI_ARRAY(&ahp->ah_iniModes, ar5416Modes,
865 ARRAY_SIZE(ar5416Modes), 6);
866 INIT_INI_ARRAY(&ahp->ah_iniCommon, ar5416Common,
867 ARRAY_SIZE(ar5416Common), 2);
868 INIT_INI_ARRAY(&ahp->ah_iniBank0, ar5416Bank0,
869 ARRAY_SIZE(ar5416Bank0), 2);
870 INIT_INI_ARRAY(&ahp->ah_iniBB_RfGain, ar5416BB_RfGain,
871 ARRAY_SIZE(ar5416BB_RfGain), 3);
872 INIT_INI_ARRAY(&ahp->ah_iniBank1, ar5416Bank1,
873 ARRAY_SIZE(ar5416Bank1), 2);
874 INIT_INI_ARRAY(&ahp->ah_iniBank2, ar5416Bank2,
875 ARRAY_SIZE(ar5416Bank2), 2);
876 INIT_INI_ARRAY(&ahp->ah_iniBank3, ar5416Bank3,
877 ARRAY_SIZE(ar5416Bank3), 3);
878 INIT_INI_ARRAY(&ahp->ah_iniBank6, ar5416Bank6,
879 ARRAY_SIZE(ar5416Bank6), 3);
880 INIT_INI_ARRAY(&ahp->ah_iniBank6TPC, ar5416Bank6TPC,
881 ARRAY_SIZE(ar5416Bank6TPC), 3);
882 INIT_INI_ARRAY(&ahp->ah_iniBank7, ar5416Bank7,
883 ARRAY_SIZE(ar5416Bank7), 2);
884 INIT_INI_ARRAY(&ahp->ah_iniAddac, ar5416Addac,
885 ARRAY_SIZE(ar5416Addac), 2);
886 }
887
888 if (ah->ah_isPciExpress)
889 ath9k_hw_configpcipowersave(ah, 0);
890 else
Sujithf1dc5602008-10-29 10:16:30 +0530891 ath9k_hw_disablepcie(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700892
893 ecode = ath9k_hw_post_attach(ah);
894 if (ecode != 0)
895 goto bad;
896
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530897 /* rxgain table */
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530898 if (AR_SREV_9280_20(ah))
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530899 ath9k_hw_init_rxgain_ini(ah);
900
901 /* txgain table */
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530902 if (AR_SREV_9280_20(ah))
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530903 ath9k_hw_init_txgain_ini(ah);
904
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700905 if (ah->ah_devid == AR9280_DEVID_PCI) {
906 for (i = 0; i < ahp->ah_iniModes.ia_rows; i++) {
907 u32 reg = INI_RA(&ahp->ah_iniModes, i, 0);
908
909 for (j = 1; j < ahp->ah_iniModes.ia_columns; j++) {
910 u32 val = INI_RA(&ahp->ah_iniModes, i, j);
911
912 INI_RA(&ahp->ah_iniModes, i, j) =
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530913 ath9k_hw_ini_fixup(ah,
914 &ahp->ah_eeprom.def,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700915 reg, val);
916 }
917 }
918 }
Sujithf6688cd2008-12-07 21:43:10 +0530919
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700920 if (!ath9k_hw_fill_cap_info(ah)) {
921 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +0530922 "failed ath9k_hw_fill_cap_info\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700923 ecode = -EINVAL;
924 goto bad;
925 }
926
927 ecode = ath9k_hw_init_macaddr(ah);
928 if (ecode != 0) {
929 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +0530930 "failed initializing mac address\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700931 goto bad;
932 }
933
934 if (AR_SREV_9285(ah))
935 ah->ah_txTrigLevel = (AR_FTRIG_256B >> AR_FTRIG_S);
936 else
937 ah->ah_txTrigLevel = (AR_FTRIG_512B >> AR_FTRIG_S);
938
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700939 ath9k_init_nfcal_hist_buffer(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700940
941 return ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700942bad:
943 if (ahp)
944 ath9k_hw_detach((struct ath_hal *) ahp);
945 if (status)
946 *status = ecode;
Sujithf1dc5602008-10-29 10:16:30 +0530947
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700948 return NULL;
949}
950
Sujithf1dc5602008-10-29 10:16:30 +0530951static void ath9k_hw_init_bb(struct ath_hal *ah,
952 struct ath9k_channel *chan)
953{
954 u32 synthDelay;
955
956 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +0530957 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +0530958 synthDelay = (4 * synthDelay) / 22;
959 else
960 synthDelay /= 10;
961
962 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
963
964 udelay(synthDelay + BASE_ACTIVATE_DELAY);
965}
966
967static void ath9k_hw_init_qos(struct ath_hal *ah)
968{
969 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
970 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
971
972 REG_WRITE(ah, AR_QOS_NO_ACK,
973 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
974 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
975 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
976
977 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
978 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
979 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
980 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
981 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
982}
983
984static void ath9k_hw_init_pll(struct ath_hal *ah,
985 struct ath9k_channel *chan)
986{
987 u32 pll;
988
989 if (AR_SREV_9100(ah)) {
990 if (chan && IS_CHAN_5GHZ(chan))
991 pll = 0x1450;
992 else
993 pll = 0x1458;
994 } else {
995 if (AR_SREV_9280_10_OR_LATER(ah)) {
996 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
997
998 if (chan && IS_CHAN_HALF_RATE(chan))
999 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
1000 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1001 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
1002
1003 if (chan && IS_CHAN_5GHZ(chan)) {
1004 pll |= SM(0x28, AR_RTC_9160_PLL_DIV);
1005
1006
1007 if (AR_SREV_9280_20(ah)) {
1008 if (((chan->channel % 20) == 0)
1009 || ((chan->channel % 10) == 0))
1010 pll = 0x2850;
1011 else
1012 pll = 0x142c;
1013 }
1014 } else {
1015 pll |= SM(0x2c, AR_RTC_9160_PLL_DIV);
1016 }
1017
1018 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1019
1020 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
1021
1022 if (chan && IS_CHAN_HALF_RATE(chan))
1023 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
1024 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1025 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
1026
1027 if (chan && IS_CHAN_5GHZ(chan))
1028 pll |= SM(0x50, AR_RTC_9160_PLL_DIV);
1029 else
1030 pll |= SM(0x58, AR_RTC_9160_PLL_DIV);
1031 } else {
1032 pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2;
1033
1034 if (chan && IS_CHAN_HALF_RATE(chan))
1035 pll |= SM(0x1, AR_RTC_PLL_CLKSEL);
1036 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1037 pll |= SM(0x2, AR_RTC_PLL_CLKSEL);
1038
1039 if (chan && IS_CHAN_5GHZ(chan))
1040 pll |= SM(0xa, AR_RTC_PLL_DIV);
1041 else
1042 pll |= SM(0xb, AR_RTC_PLL_DIV);
1043 }
1044 }
1045 REG_WRITE(ah, (u16) (AR_RTC_PLL_CONTROL), pll);
1046
1047 udelay(RTC_PLL_SETTLE_DELAY);
1048
1049 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
1050}
1051
1052static void ath9k_hw_init_chain_masks(struct ath_hal *ah)
1053{
1054 struct ath_hal_5416 *ahp = AH5416(ah);
1055 int rx_chainmask, tx_chainmask;
1056
1057 rx_chainmask = ahp->ah_rxchainmask;
1058 tx_chainmask = ahp->ah_txchainmask;
1059
1060 switch (rx_chainmask) {
1061 case 0x5:
1062 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1063 AR_PHY_SWAP_ALT_CHAIN);
1064 case 0x3:
1065 if (((ah)->ah_macVersion <= AR_SREV_VERSION_9160)) {
1066 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7);
1067 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7);
1068 break;
1069 }
1070 case 0x1:
1071 case 0x2:
Sujithf1dc5602008-10-29 10:16:30 +05301072 case 0x7:
1073 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
1074 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
1075 break;
1076 default:
1077 break;
1078 }
1079
1080 REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);
1081 if (tx_chainmask == 0x5) {
1082 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1083 AR_PHY_SWAP_ALT_CHAIN);
1084 }
1085 if (AR_SREV_9100(ah))
1086 REG_WRITE(ah, AR_PHY_ANALOG_SWAP,
1087 REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
1088}
1089
Colin McCabed97809d2008-12-01 13:38:55 -08001090static void ath9k_hw_init_interrupt_masks(struct ath_hal *ah,
1091 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301092{
1093 struct ath_hal_5416 *ahp = AH5416(ah);
1094
1095 ahp->ah_maskReg = AR_IMR_TXERR |
1096 AR_IMR_TXURN |
1097 AR_IMR_RXERR |
1098 AR_IMR_RXORN |
1099 AR_IMR_BCNMISC;
1100
1101 if (ahp->ah_intrMitigation)
1102 ahp->ah_maskReg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
1103 else
1104 ahp->ah_maskReg |= AR_IMR_RXOK;
1105
1106 ahp->ah_maskReg |= AR_IMR_TXOK;
1107
Colin McCabed97809d2008-12-01 13:38:55 -08001108 if (opmode == NL80211_IFTYPE_AP)
Sujithf1dc5602008-10-29 10:16:30 +05301109 ahp->ah_maskReg |= AR_IMR_MIB;
1110
1111 REG_WRITE(ah, AR_IMR, ahp->ah_maskReg);
1112 REG_WRITE(ah, AR_IMR_S2, REG_READ(ah, AR_IMR_S2) | AR_IMR_S2_GTT);
1113
1114 if (!AR_SREV_9100(ah)) {
1115 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
1116 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
1117 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
1118 }
1119}
1120
1121static bool ath9k_hw_set_ack_timeout(struct ath_hal *ah, u32 us)
1122{
1123 struct ath_hal_5416 *ahp = AH5416(ah);
1124
1125 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) {
Sujith04bd4632008-11-28 22:18:05 +05301126 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "bad ack timeout %u\n", us);
Sujithf1dc5602008-10-29 10:16:30 +05301127 ahp->ah_acktimeout = (u32) -1;
1128 return false;
1129 } else {
1130 REG_RMW_FIELD(ah, AR_TIME_OUT,
1131 AR_TIME_OUT_ACK, ath9k_hw_mac_to_clks(ah, us));
1132 ahp->ah_acktimeout = us;
1133 return true;
1134 }
1135}
1136
1137static bool ath9k_hw_set_cts_timeout(struct ath_hal *ah, u32 us)
1138{
1139 struct ath_hal_5416 *ahp = AH5416(ah);
1140
1141 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_CTS))) {
Sujith04bd4632008-11-28 22:18:05 +05301142 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "bad cts timeout %u\n", us);
Sujithf1dc5602008-10-29 10:16:30 +05301143 ahp->ah_ctstimeout = (u32) -1;
1144 return false;
1145 } else {
1146 REG_RMW_FIELD(ah, AR_TIME_OUT,
1147 AR_TIME_OUT_CTS, ath9k_hw_mac_to_clks(ah, us));
1148 ahp->ah_ctstimeout = us;
1149 return true;
1150 }
1151}
1152
1153static bool ath9k_hw_set_global_txtimeout(struct ath_hal *ah, u32 tu)
1154{
1155 struct ath_hal_5416 *ahp = AH5416(ah);
1156
1157 if (tu > 0xFFFF) {
1158 DPRINTF(ah->ah_sc, ATH_DBG_XMIT,
Sujith04bd4632008-11-28 22:18:05 +05301159 "bad global tx timeout %u\n", tu);
Sujithf1dc5602008-10-29 10:16:30 +05301160 ahp->ah_globaltxtimeout = (u32) -1;
1161 return false;
1162 } else {
1163 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
1164 ahp->ah_globaltxtimeout = tu;
1165 return true;
1166 }
1167}
1168
1169static void ath9k_hw_init_user_settings(struct ath_hal *ah)
1170{
1171 struct ath_hal_5416 *ahp = AH5416(ah);
1172
Sujith04bd4632008-11-28 22:18:05 +05301173 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "ahp->ah_miscMode 0x%x\n",
1174 ahp->ah_miscMode);
Sujithf1dc5602008-10-29 10:16:30 +05301175
1176 if (ahp->ah_miscMode != 0)
1177 REG_WRITE(ah, AR_PCU_MISC,
1178 REG_READ(ah, AR_PCU_MISC) | ahp->ah_miscMode);
1179 if (ahp->ah_slottime != (u32) -1)
1180 ath9k_hw_setslottime(ah, ahp->ah_slottime);
1181 if (ahp->ah_acktimeout != (u32) -1)
1182 ath9k_hw_set_ack_timeout(ah, ahp->ah_acktimeout);
1183 if (ahp->ah_ctstimeout != (u32) -1)
1184 ath9k_hw_set_cts_timeout(ah, ahp->ah_ctstimeout);
1185 if (ahp->ah_globaltxtimeout != (u32) -1)
1186 ath9k_hw_set_global_txtimeout(ah, ahp->ah_globaltxtimeout);
1187}
1188
1189const char *ath9k_hw_probe(u16 vendorid, u16 devid)
1190{
1191 return vendorid == ATHEROS_VENDOR_ID ?
1192 ath9k_hw_devname(devid) : NULL;
1193}
1194
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001195void ath9k_hw_detach(struct ath_hal *ah)
1196{
1197 if (!AR_SREV_9100(ah))
1198 ath9k_hw_ani_detach(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001199
Sujithf1dc5602008-10-29 10:16:30 +05301200 ath9k_hw_rfdetach(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001201 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
1202 kfree(ah);
1203}
1204
Sujithf1dc5602008-10-29 10:16:30 +05301205struct ath_hal *ath9k_hw_attach(u16 devid, struct ath_softc *sc,
1206 void __iomem *mem, int *error)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001207{
Sujithf1dc5602008-10-29 10:16:30 +05301208 struct ath_hal *ah = NULL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001209
Sujithf1dc5602008-10-29 10:16:30 +05301210 switch (devid) {
1211 case AR5416_DEVID_PCI:
1212 case AR5416_DEVID_PCIE:
1213 case AR9160_DEVID_PCI:
1214 case AR9280_DEVID_PCI:
1215 case AR9280_DEVID_PCIE:
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301216 case AR9285_DEVID_PCIE:
Sujithf1dc5602008-10-29 10:16:30 +05301217 ah = ath9k_hw_do_attach(devid, sc, mem, error);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001218 break;
Sujithf1dc5602008-10-29 10:16:30 +05301219 default:
Sujithf1dc5602008-10-29 10:16:30 +05301220 *error = -ENXIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001221 break;
1222 }
1223
Sujithf1dc5602008-10-29 10:16:30 +05301224 return ah;
1225}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001226
Sujithf1dc5602008-10-29 10:16:30 +05301227/*******/
1228/* INI */
1229/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001230
Sujithf1dc5602008-10-29 10:16:30 +05301231static void ath9k_hw_override_ini(struct ath_hal *ah,
1232 struct ath9k_channel *chan)
1233{
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +05301234 /*
1235 * Set the RX_ABORT and RX_DIS and clear if off only after
1236 * RXE is set for MAC. This prevents frames with corrupted
1237 * descriptor status.
1238 */
1239 REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
1240
1241
Sujithf1dc5602008-10-29 10:16:30 +05301242 if (!AR_SREV_5416_V20_OR_LATER(ah) ||
1243 AR_SREV_9280_10_OR_LATER(ah))
1244 return;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001245
Sujithf1dc5602008-10-29 10:16:30 +05301246 REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
1247}
1248
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301249static u32 ath9k_hw_def_ini_fixup(struct ath_hal *ah,
1250 struct ar5416_eeprom_def *pEepData,
Sujithf1dc5602008-10-29 10:16:30 +05301251 u32 reg, u32 value)
1252{
1253 struct base_eep_header *pBase = &(pEepData->baseEepHeader);
1254
1255 switch (ah->ah_devid) {
1256 case AR9280_DEVID_PCI:
1257 if (reg == 0x7894) {
1258 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
1259 "ini VAL: %x EEPROM: %x\n", value,
1260 (pBase->version & 0xff));
1261
1262 if ((pBase->version & 0xff) > 0x0a) {
1263 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
1264 "PWDCLKIND: %d\n",
1265 pBase->pwdclkind);
1266 value &= ~AR_AN_TOP2_PWDCLKIND;
1267 value |= AR_AN_TOP2_PWDCLKIND &
1268 (pBase->pwdclkind << AR_AN_TOP2_PWDCLKIND_S);
1269 } else {
1270 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
1271 "PWDCLKIND Earlier Rev\n");
1272 }
1273
1274 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
1275 "final ini VAL: %x\n", value);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001276 }
Sujithf1dc5602008-10-29 10:16:30 +05301277 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001278 }
1279
Sujithf1dc5602008-10-29 10:16:30 +05301280 return value;
1281}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001282
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301283static u32 ath9k_hw_ini_fixup(struct ath_hal *ah,
1284 struct ar5416_eeprom_def *pEepData,
1285 u32 reg, u32 value)
1286{
1287 struct ath_hal_5416 *ahp = AH5416(ah);
1288
1289 if (ahp->ah_eep_map == EEP_MAP_4KBITS)
1290 return value;
1291 else
1292 return ath9k_hw_def_ini_fixup(ah, pEepData, reg, value);
1293}
1294
Sujithf1dc5602008-10-29 10:16:30 +05301295static int ath9k_hw_process_ini(struct ath_hal *ah,
1296 struct ath9k_channel *chan,
1297 enum ath9k_ht_macmode macmode)
1298{
1299 int i, regWrites = 0;
1300 struct ath_hal_5416 *ahp = AH5416(ah);
1301 u32 modesIndex, freqIndex;
1302 int status;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001303
Sujithf1dc5602008-10-29 10:16:30 +05301304 switch (chan->chanmode) {
1305 case CHANNEL_A:
1306 case CHANNEL_A_HT20:
1307 modesIndex = 1;
1308 freqIndex = 1;
1309 break;
1310 case CHANNEL_A_HT40PLUS:
1311 case CHANNEL_A_HT40MINUS:
1312 modesIndex = 2;
1313 freqIndex = 1;
1314 break;
1315 case CHANNEL_G:
1316 case CHANNEL_G_HT20:
1317 case CHANNEL_B:
1318 modesIndex = 4;
1319 freqIndex = 2;
1320 break;
1321 case CHANNEL_G_HT40PLUS:
1322 case CHANNEL_G_HT40MINUS:
1323 modesIndex = 3;
1324 freqIndex = 2;
1325 break;
1326
1327 default:
1328 return -EINVAL;
1329 }
1330
1331 REG_WRITE(ah, AR_PHY(0), 0x00000007);
1332
1333 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
1334
1335 ath9k_hw_set_addac(ah, chan);
1336
1337 if (AR_SREV_5416_V22_OR_LATER(ah)) {
1338 REG_WRITE_ARRAY(&ahp->ah_iniAddac, 1, regWrites);
1339 } else {
1340 struct ar5416IniArray temp;
1341 u32 addacSize =
1342 sizeof(u32) * ahp->ah_iniAddac.ia_rows *
1343 ahp->ah_iniAddac.ia_columns;
1344
1345 memcpy(ahp->ah_addac5416_21,
1346 ahp->ah_iniAddac.ia_array, addacSize);
1347
1348 (ahp->ah_addac5416_21)[31 * ahp->ah_iniAddac.ia_columns + 1] = 0;
1349
1350 temp.ia_array = ahp->ah_addac5416_21;
1351 temp.ia_columns = ahp->ah_iniAddac.ia_columns;
1352 temp.ia_rows = ahp->ah_iniAddac.ia_rows;
1353 REG_WRITE_ARRAY(&temp, 1, regWrites);
1354 }
1355
1356 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
1357
1358 for (i = 0; i < ahp->ah_iniModes.ia_rows; i++) {
1359 u32 reg = INI_RA(&ahp->ah_iniModes, i, 0);
1360 u32 val = INI_RA(&ahp->ah_iniModes, i, modesIndex);
1361
Sujithf1dc5602008-10-29 10:16:30 +05301362 REG_WRITE(ah, reg, val);
1363
1364 if (reg >= 0x7800 && reg < 0x78a0
1365 && ah->ah_config.analog_shiftreg) {
1366 udelay(100);
1367 }
1368
1369 DO_DELAY(regWrites);
1370 }
1371
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301372 if (AR_SREV_9280(ah))
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301373 REG_WRITE_ARRAY(&ahp->ah_iniModesRxGain, modesIndex, regWrites);
1374
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301375 if (AR_SREV_9280(ah))
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301376 REG_WRITE_ARRAY(&ahp->ah_iniModesTxGain, modesIndex, regWrites);
1377
Sujithf1dc5602008-10-29 10:16:30 +05301378 for (i = 0; i < ahp->ah_iniCommon.ia_rows; i++) {
1379 u32 reg = INI_RA(&ahp->ah_iniCommon, i, 0);
1380 u32 val = INI_RA(&ahp->ah_iniCommon, i, 1);
1381
1382 REG_WRITE(ah, reg, val);
1383
1384 if (reg >= 0x7800 && reg < 0x78a0
1385 && ah->ah_config.analog_shiftreg) {
1386 udelay(100);
1387 }
1388
1389 DO_DELAY(regWrites);
1390 }
1391
1392 ath9k_hw_write_regs(ah, modesIndex, freqIndex, regWrites);
1393
1394 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan)) {
1395 REG_WRITE_ARRAY(&ahp->ah_iniModesAdditional, modesIndex,
1396 regWrites);
1397 }
1398
1399 ath9k_hw_override_ini(ah, chan);
1400 ath9k_hw_set_regs(ah, chan, macmode);
1401 ath9k_hw_init_chain_masks(ah);
1402
1403 status = ath9k_hw_set_txpower(ah, chan,
1404 ath9k_regd_get_ctl(ah, chan),
1405 ath9k_regd_get_antenna_allowed(ah,
1406 chan),
1407 chan->maxRegTxPower * 2,
1408 min((u32) MAX_RATE_POWER,
1409 (u32) ah->ah_powerLimit));
1410 if (status != 0) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001411 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
Sujith04bd4632008-11-28 22:18:05 +05301412 "error init'ing transmit power\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001413 return -EIO;
1414 }
1415
Sujithf1dc5602008-10-29 10:16:30 +05301416 if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
1417 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
Sujith04bd4632008-11-28 22:18:05 +05301418 "ar5416SetRfRegs failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001419 return -EIO;
1420 }
1421
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001422 return 0;
1423}
1424
Sujithf1dc5602008-10-29 10:16:30 +05301425/****************************************/
1426/* Reset and Channel Switching Routines */
1427/****************************************/
1428
1429static void ath9k_hw_set_rfmode(struct ath_hal *ah, struct ath9k_channel *chan)
1430{
1431 u32 rfMode = 0;
1432
1433 if (chan == NULL)
1434 return;
1435
1436 rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
1437 ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
1438
1439 if (!AR_SREV_9280_10_OR_LATER(ah))
1440 rfMode |= (IS_CHAN_5GHZ(chan)) ?
1441 AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ;
1442
1443 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan))
1444 rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
1445
1446 REG_WRITE(ah, AR_PHY_MODE, rfMode);
1447}
1448
1449static void ath9k_hw_mark_phy_inactive(struct ath_hal *ah)
1450{
1451 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
1452}
1453
1454static inline void ath9k_hw_set_dma(struct ath_hal *ah)
1455{
1456 u32 regval;
1457
1458 regval = REG_READ(ah, AR_AHB_MODE);
1459 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
1460
1461 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
1462 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
1463
1464 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->ah_txTrigLevel);
1465
1466 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
1467 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
1468
1469 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1470
1471 if (AR_SREV_9285(ah)) {
1472 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1473 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
1474 } else {
1475 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1476 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1477 }
1478}
1479
1480static void ath9k_hw_set_operating_mode(struct ath_hal *ah, int opmode)
1481{
1482 u32 val;
1483
1484 val = REG_READ(ah, AR_STA_ID1);
1485 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
1486 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001487 case NL80211_IFTYPE_AP:
Sujithf1dc5602008-10-29 10:16:30 +05301488 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
1489 | AR_STA_ID1_KSRCH_MODE);
1490 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1491 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001492 case NL80211_IFTYPE_ADHOC:
Sujithf1dc5602008-10-29 10:16:30 +05301493 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
1494 | AR_STA_ID1_KSRCH_MODE);
1495 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1496 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001497 case NL80211_IFTYPE_STATION:
1498 case NL80211_IFTYPE_MONITOR:
Sujithf1dc5602008-10-29 10:16:30 +05301499 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
1500 break;
1501 }
1502}
1503
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001504static inline void ath9k_hw_get_delta_slope_vals(struct ath_hal *ah,
1505 u32 coef_scaled,
1506 u32 *coef_mantissa,
1507 u32 *coef_exponent)
1508{
1509 u32 coef_exp, coef_man;
1510
1511 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1512 if ((coef_scaled >> coef_exp) & 0x1)
1513 break;
1514
1515 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1516
1517 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1518
1519 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1520 *coef_exponent = coef_exp - 16;
1521}
1522
Sujithf1dc5602008-10-29 10:16:30 +05301523static void ath9k_hw_set_delta_slope(struct ath_hal *ah,
1524 struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001525{
1526 u32 coef_scaled, ds_coef_exp, ds_coef_man;
1527 u32 clockMhzScaled = 0x64000000;
1528 struct chan_centers centers;
1529
1530 if (IS_CHAN_HALF_RATE(chan))
1531 clockMhzScaled = clockMhzScaled >> 1;
1532 else if (IS_CHAN_QUARTER_RATE(chan))
1533 clockMhzScaled = clockMhzScaled >> 2;
1534
1535 ath9k_hw_get_channel_centers(ah, chan, &centers);
1536 coef_scaled = clockMhzScaled / centers.synth_center;
1537
1538 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1539 &ds_coef_exp);
1540
1541 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1542 AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
1543 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1544 AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
1545
1546 coef_scaled = (9 * coef_scaled) / 10;
1547
1548 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1549 &ds_coef_exp);
1550
1551 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1552 AR_PHY_HALFGI_DSC_MAN, ds_coef_man);
1553 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1554 AR_PHY_HALFGI_DSC_EXP, ds_coef_exp);
1555}
1556
Sujithf1dc5602008-10-29 10:16:30 +05301557static bool ath9k_hw_set_reset(struct ath_hal *ah, int type)
1558{
1559 u32 rst_flags;
1560 u32 tmpReg;
1561
1562 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1563 AR_RTC_FORCE_WAKE_ON_INT);
1564
1565 if (AR_SREV_9100(ah)) {
1566 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1567 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1568 } else {
1569 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1570 if (tmpReg &
1571 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1572 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
1573 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
1574 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1575 } else {
1576 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1577 }
1578
1579 rst_flags = AR_RTC_RC_MAC_WARM;
1580 if (type == ATH9K_RESET_COLD)
1581 rst_flags |= AR_RTC_RC_MAC_COLD;
1582 }
1583
1584 REG_WRITE(ah, (u16) (AR_RTC_RC), rst_flags);
1585 udelay(50);
1586
1587 REG_WRITE(ah, (u16) (AR_RTC_RC), 0);
1588 if (!ath9k_hw_wait(ah, (u16) (AR_RTC_RC), AR_RTC_RC_M, 0)) {
1589 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05301590 "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301591 return false;
1592 }
1593
1594 if (!AR_SREV_9100(ah))
1595 REG_WRITE(ah, AR_RC, 0);
1596
1597 ath9k_hw_init_pll(ah, NULL);
1598
1599 if (AR_SREV_9100(ah))
1600 udelay(50);
1601
1602 return true;
1603}
1604
1605static bool ath9k_hw_set_reset_power_on(struct ath_hal *ah)
1606{
1607 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1608 AR_RTC_FORCE_WAKE_ON_INT);
1609
1610 REG_WRITE(ah, (u16) (AR_RTC_RESET), 0);
1611 REG_WRITE(ah, (u16) (AR_RTC_RESET), 1);
1612
1613 if (!ath9k_hw_wait(ah,
1614 AR_RTC_STATUS,
1615 AR_RTC_STATUS_M,
1616 AR_RTC_STATUS_ON)) {
Sujith04bd4632008-11-28 22:18:05 +05301617 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301618 return false;
1619 }
1620
1621 ath9k_hw_read_revisions(ah);
1622
1623 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1624}
1625
1626static bool ath9k_hw_set_reset_reg(struct ath_hal *ah, u32 type)
1627{
1628 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1629 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1630
1631 switch (type) {
1632 case ATH9K_RESET_POWER_ON:
1633 return ath9k_hw_set_reset_power_on(ah);
1634 break;
1635 case ATH9K_RESET_WARM:
1636 case ATH9K_RESET_COLD:
1637 return ath9k_hw_set_reset(ah, type);
1638 break;
1639 default:
1640 return false;
1641 }
1642}
1643
1644static void ath9k_hw_set_regs(struct ath_hal *ah, struct ath9k_channel *chan,
1645 enum ath9k_ht_macmode macmode)
1646{
1647 u32 phymode;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301648 u32 enableDacFifo = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301649 struct ath_hal_5416 *ahp = AH5416(ah);
1650
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301651 if (AR_SREV_9285_10_OR_LATER(ah))
1652 enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) &
1653 AR_PHY_FC_ENABLE_DAC_FIFO);
1654
Sujithf1dc5602008-10-29 10:16:30 +05301655 phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301656 | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo;
Sujithf1dc5602008-10-29 10:16:30 +05301657
1658 if (IS_CHAN_HT40(chan)) {
1659 phymode |= AR_PHY_FC_DYN2040_EN;
1660
1661 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
1662 (chan->chanmode == CHANNEL_G_HT40PLUS))
1663 phymode |= AR_PHY_FC_DYN2040_PRI_CH;
1664
1665 if (ahp->ah_extprotspacing == ATH9K_HT_EXTPROTSPACING_25)
1666 phymode |= AR_PHY_FC_DYN2040_EXT_CH;
1667 }
1668 REG_WRITE(ah, AR_PHY_TURBO, phymode);
1669
1670 ath9k_hw_set11nmac2040(ah, macmode);
1671
1672 REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
1673 REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
1674}
1675
1676static bool ath9k_hw_chip_reset(struct ath_hal *ah,
1677 struct ath9k_channel *chan)
1678{
1679 struct ath_hal_5416 *ahp = AH5416(ah);
1680
1681 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
1682 return false;
1683
1684 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
1685 return false;
1686
1687 ahp->ah_chipFullSleep = false;
1688
1689 ath9k_hw_init_pll(ah, chan);
1690
1691 ath9k_hw_set_rfmode(ah, chan);
1692
1693 return true;
1694}
1695
1696static struct ath9k_channel *ath9k_hw_check_chan(struct ath_hal *ah,
1697 struct ath9k_channel *chan)
1698{
1699 if (!(IS_CHAN_2GHZ(chan) ^ IS_CHAN_5GHZ(chan))) {
1700 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
Sujith04bd4632008-11-28 22:18:05 +05301701 "invalid channel %u/0x%x; not marked as "
1702 "2GHz or 5GHz\n", chan->channel, chan->channelFlags);
Sujithf1dc5602008-10-29 10:16:30 +05301703 return NULL;
1704 }
1705
1706 if (!IS_CHAN_OFDM(chan) &&
Sujith788a3d62008-11-18 09:09:54 +05301707 !IS_CHAN_B(chan) &&
Sujithf1dc5602008-10-29 10:16:30 +05301708 !IS_CHAN_HT20(chan) &&
1709 !IS_CHAN_HT40(chan)) {
1710 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
Sujith04bd4632008-11-28 22:18:05 +05301711 "invalid channel %u/0x%x; not marked as "
Sujithf1dc5602008-10-29 10:16:30 +05301712 "OFDM or CCK or HT20 or HT40PLUS or HT40MINUS\n",
Sujith04bd4632008-11-28 22:18:05 +05301713 chan->channel, chan->channelFlags);
Sujithf1dc5602008-10-29 10:16:30 +05301714 return NULL;
1715 }
1716
1717 return ath9k_regd_check_channel(ah, chan);
1718}
1719
1720static bool ath9k_hw_channel_change(struct ath_hal *ah,
1721 struct ath9k_channel *chan,
1722 enum ath9k_ht_macmode macmode)
1723{
1724 u32 synthDelay, qnum;
1725
1726 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1727 if (ath9k_hw_numtxpending(ah, qnum)) {
1728 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
Sujith04bd4632008-11-28 22:18:05 +05301729 "Transmit frames pending on queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301730 return false;
1731 }
1732 }
1733
1734 REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
1735 if (!ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
1736 AR_PHY_RFBUS_GRANT_EN)) {
Sujith04bd4632008-11-28 22:18:05 +05301737 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
1738 "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301739 return false;
1740 }
1741
1742 ath9k_hw_set_regs(ah, chan, macmode);
1743
1744 if (AR_SREV_9280_10_OR_LATER(ah)) {
1745 if (!(ath9k_hw_ar9280_set_channel(ah, chan))) {
1746 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
Sujith04bd4632008-11-28 22:18:05 +05301747 "failed to set channel\n");
Sujithf1dc5602008-10-29 10:16:30 +05301748 return false;
1749 }
1750 } else {
1751 if (!(ath9k_hw_set_channel(ah, chan))) {
1752 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
Sujith04bd4632008-11-28 22:18:05 +05301753 "failed to set channel\n");
Sujithf1dc5602008-10-29 10:16:30 +05301754 return false;
1755 }
1756 }
1757
1758 if (ath9k_hw_set_txpower(ah, chan,
1759 ath9k_regd_get_ctl(ah, chan),
1760 ath9k_regd_get_antenna_allowed(ah, chan),
1761 chan->maxRegTxPower * 2,
1762 min((u32) MAX_RATE_POWER,
1763 (u32) ah->ah_powerLimit)) != 0) {
1764 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
Sujith04bd4632008-11-28 22:18:05 +05301765 "error init'ing transmit power\n");
Sujithf1dc5602008-10-29 10:16:30 +05301766 return false;
1767 }
1768
1769 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +05301770 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +05301771 synthDelay = (4 * synthDelay) / 22;
1772 else
1773 synthDelay /= 10;
1774
1775 udelay(synthDelay + BASE_ACTIVATE_DELAY);
1776
1777 REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
1778
1779 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1780 ath9k_hw_set_delta_slope(ah, chan);
1781
1782 if (AR_SREV_9280_10_OR_LATER(ah))
1783 ath9k_hw_9280_spur_mitigate(ah, chan);
1784 else
1785 ath9k_hw_spur_mitigate(ah, chan);
1786
1787 if (!chan->oneTimeCalsDone)
1788 chan->oneTimeCalsDone = true;
1789
1790 return true;
1791}
1792
1793static void ath9k_hw_9280_spur_mitigate(struct ath_hal *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001794{
1795 int bb_spur = AR_NO_SPUR;
1796 int freq;
1797 int bin, cur_bin;
1798 int bb_spur_off, spur_subchannel_sd;
1799 int spur_freq_sd;
1800 int spur_delta_phase;
1801 int denominator;
1802 int upper, lower, cur_vit_mask;
1803 int tmp, newVal;
1804 int i;
1805 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
1806 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
1807 };
1808 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
1809 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
1810 };
1811 int inc[4] = { 0, 100, 0, 0 };
1812 struct chan_centers centers;
1813
1814 int8_t mask_m[123];
1815 int8_t mask_p[123];
1816 int8_t mask_amt;
1817 int tmp_mask;
1818 int cur_bb_spur;
1819 bool is2GHz = IS_CHAN_2GHZ(chan);
1820
1821 memset(&mask_m, 0, sizeof(int8_t) * 123);
1822 memset(&mask_p, 0, sizeof(int8_t) * 123);
1823
1824 ath9k_hw_get_channel_centers(ah, chan, &centers);
1825 freq = centers.synth_center;
1826
Sujith60b67f52008-08-07 10:52:38 +05301827 ah->ah_config.spurmode = SPUR_ENABLE_EEPROM;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001828 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
1829 cur_bb_spur = ath9k_hw_eeprom_get_spur_chan(ah, i, is2GHz);
1830
1831 if (is2GHz)
1832 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_2GHZ;
1833 else
1834 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_5GHZ;
1835
1836 if (AR_NO_SPUR == cur_bb_spur)
1837 break;
1838 cur_bb_spur = cur_bb_spur - freq;
1839
1840 if (IS_CHAN_HT40(chan)) {
1841 if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT40) &&
1842 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT40)) {
1843 bb_spur = cur_bb_spur;
1844 break;
1845 }
1846 } else if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT20) &&
1847 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT20)) {
1848 bb_spur = cur_bb_spur;
1849 break;
1850 }
1851 }
1852
1853 if (AR_NO_SPUR == bb_spur) {
1854 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1855 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1856 return;
1857 } else {
1858 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1859 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1860 }
1861
1862 bin = bb_spur * 320;
1863
1864 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
1865
1866 newVal = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
1867 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
1868 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
1869 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
1870 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), newVal);
1871
1872 newVal = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
1873 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
1874 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
1875 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
1876 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
1877 REG_WRITE(ah, AR_PHY_SPUR_REG, newVal);
1878
1879 if (IS_CHAN_HT40(chan)) {
1880 if (bb_spur < 0) {
1881 spur_subchannel_sd = 1;
1882 bb_spur_off = bb_spur + 10;
1883 } else {
1884 spur_subchannel_sd = 0;
1885 bb_spur_off = bb_spur - 10;
1886 }
1887 } else {
1888 spur_subchannel_sd = 0;
1889 bb_spur_off = bb_spur;
1890 }
1891
1892 if (IS_CHAN_HT40(chan))
1893 spur_delta_phase =
1894 ((bb_spur * 262144) /
1895 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
1896 else
1897 spur_delta_phase =
1898 ((bb_spur * 524288) /
1899 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
1900
1901 denominator = IS_CHAN_2GHZ(chan) ? 44 : 40;
1902 spur_freq_sd = ((bb_spur_off * 2048) / denominator) & 0x3ff;
1903
1904 newVal = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
1905 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
1906 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
1907 REG_WRITE(ah, AR_PHY_TIMING11, newVal);
1908
1909 newVal = spur_subchannel_sd << AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S;
1910 REG_WRITE(ah, AR_PHY_SFCORR_EXT, newVal);
1911
1912 cur_bin = -6000;
1913 upper = bin + 100;
1914 lower = bin - 100;
1915
1916 for (i = 0; i < 4; i++) {
1917 int pilot_mask = 0;
1918 int chan_mask = 0;
1919 int bp = 0;
1920 for (bp = 0; bp < 30; bp++) {
1921 if ((cur_bin > lower) && (cur_bin < upper)) {
1922 pilot_mask = pilot_mask | 0x1 << bp;
1923 chan_mask = chan_mask | 0x1 << bp;
1924 }
1925 cur_bin += 100;
1926 }
1927 cur_bin += inc[i];
1928 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
1929 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
1930 }
1931
1932 cur_vit_mask = 6100;
1933 upper = bin + 120;
1934 lower = bin - 120;
1935
1936 for (i = 0; i < 123; i++) {
1937 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
Adrian Bunkb08cbcd2008-08-05 22:06:51 +03001938
1939 /* workaround for gcc bug #37014 */
1940 volatile int tmp = abs(cur_vit_mask - bin);
1941
1942 if (tmp < 75)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001943 mask_amt = 1;
1944 else
1945 mask_amt = 0;
1946 if (cur_vit_mask < 0)
1947 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
1948 else
1949 mask_p[cur_vit_mask / 100] = mask_amt;
1950 }
1951 cur_vit_mask -= 100;
1952 }
1953
1954 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
1955 | (mask_m[48] << 26) | (mask_m[49] << 24)
1956 | (mask_m[50] << 22) | (mask_m[51] << 20)
1957 | (mask_m[52] << 18) | (mask_m[53] << 16)
1958 | (mask_m[54] << 14) | (mask_m[55] << 12)
1959 | (mask_m[56] << 10) | (mask_m[57] << 8)
1960 | (mask_m[58] << 6) | (mask_m[59] << 4)
1961 | (mask_m[60] << 2) | (mask_m[61] << 0);
1962 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
1963 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
1964
1965 tmp_mask = (mask_m[31] << 28)
1966 | (mask_m[32] << 26) | (mask_m[33] << 24)
1967 | (mask_m[34] << 22) | (mask_m[35] << 20)
1968 | (mask_m[36] << 18) | (mask_m[37] << 16)
1969 | (mask_m[48] << 14) | (mask_m[39] << 12)
1970 | (mask_m[40] << 10) | (mask_m[41] << 8)
1971 | (mask_m[42] << 6) | (mask_m[43] << 4)
1972 | (mask_m[44] << 2) | (mask_m[45] << 0);
1973 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
1974 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
1975
1976 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
1977 | (mask_m[18] << 26) | (mask_m[18] << 24)
1978 | (mask_m[20] << 22) | (mask_m[20] << 20)
1979 | (mask_m[22] << 18) | (mask_m[22] << 16)
1980 | (mask_m[24] << 14) | (mask_m[24] << 12)
1981 | (mask_m[25] << 10) | (mask_m[26] << 8)
1982 | (mask_m[27] << 6) | (mask_m[28] << 4)
1983 | (mask_m[29] << 2) | (mask_m[30] << 0);
1984 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
1985 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
1986
1987 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
1988 | (mask_m[2] << 26) | (mask_m[3] << 24)
1989 | (mask_m[4] << 22) | (mask_m[5] << 20)
1990 | (mask_m[6] << 18) | (mask_m[7] << 16)
1991 | (mask_m[8] << 14) | (mask_m[9] << 12)
1992 | (mask_m[10] << 10) | (mask_m[11] << 8)
1993 | (mask_m[12] << 6) | (mask_m[13] << 4)
1994 | (mask_m[14] << 2) | (mask_m[15] << 0);
1995 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
1996 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
1997
1998 tmp_mask = (mask_p[15] << 28)
1999 | (mask_p[14] << 26) | (mask_p[13] << 24)
2000 | (mask_p[12] << 22) | (mask_p[11] << 20)
2001 | (mask_p[10] << 18) | (mask_p[9] << 16)
2002 | (mask_p[8] << 14) | (mask_p[7] << 12)
2003 | (mask_p[6] << 10) | (mask_p[5] << 8)
2004 | (mask_p[4] << 6) | (mask_p[3] << 4)
2005 | (mask_p[2] << 2) | (mask_p[1] << 0);
2006 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
2007 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
2008
2009 tmp_mask = (mask_p[30] << 28)
2010 | (mask_p[29] << 26) | (mask_p[28] << 24)
2011 | (mask_p[27] << 22) | (mask_p[26] << 20)
2012 | (mask_p[25] << 18) | (mask_p[24] << 16)
2013 | (mask_p[23] << 14) | (mask_p[22] << 12)
2014 | (mask_p[21] << 10) | (mask_p[20] << 8)
2015 | (mask_p[19] << 6) | (mask_p[18] << 4)
2016 | (mask_p[17] << 2) | (mask_p[16] << 0);
2017 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
2018 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
2019
2020 tmp_mask = (mask_p[45] << 28)
2021 | (mask_p[44] << 26) | (mask_p[43] << 24)
2022 | (mask_p[42] << 22) | (mask_p[41] << 20)
2023 | (mask_p[40] << 18) | (mask_p[39] << 16)
2024 | (mask_p[38] << 14) | (mask_p[37] << 12)
2025 | (mask_p[36] << 10) | (mask_p[35] << 8)
2026 | (mask_p[34] << 6) | (mask_p[33] << 4)
2027 | (mask_p[32] << 2) | (mask_p[31] << 0);
2028 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
2029 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
2030
2031 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
2032 | (mask_p[59] << 26) | (mask_p[58] << 24)
2033 | (mask_p[57] << 22) | (mask_p[56] << 20)
2034 | (mask_p[55] << 18) | (mask_p[54] << 16)
2035 | (mask_p[53] << 14) | (mask_p[52] << 12)
2036 | (mask_p[51] << 10) | (mask_p[50] << 8)
2037 | (mask_p[49] << 6) | (mask_p[48] << 4)
2038 | (mask_p[47] << 2) | (mask_p[46] << 0);
2039 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
2040 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
2041}
2042
Sujithf1dc5602008-10-29 10:16:30 +05302043static void ath9k_hw_spur_mitigate(struct ath_hal *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002044{
2045 int bb_spur = AR_NO_SPUR;
2046 int bin, cur_bin;
2047 int spur_freq_sd;
2048 int spur_delta_phase;
2049 int denominator;
2050 int upper, lower, cur_vit_mask;
2051 int tmp, new;
2052 int i;
2053 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
2054 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
2055 };
2056 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
2057 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
2058 };
2059 int inc[4] = { 0, 100, 0, 0 };
2060
2061 int8_t mask_m[123];
2062 int8_t mask_p[123];
2063 int8_t mask_amt;
2064 int tmp_mask;
2065 int cur_bb_spur;
2066 bool is2GHz = IS_CHAN_2GHZ(chan);
2067
2068 memset(&mask_m, 0, sizeof(int8_t) * 123);
2069 memset(&mask_p, 0, sizeof(int8_t) * 123);
2070
2071 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
2072 cur_bb_spur = ath9k_hw_eeprom_get_spur_chan(ah, i, is2GHz);
2073 if (AR_NO_SPUR == cur_bb_spur)
2074 break;
2075 cur_bb_spur = cur_bb_spur - (chan->channel * 10);
2076 if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) {
2077 bb_spur = cur_bb_spur;
2078 break;
2079 }
2080 }
2081
2082 if (AR_NO_SPUR == bb_spur)
2083 return;
2084
2085 bin = bb_spur * 32;
2086
2087 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
2088 new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
2089 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
2090 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
2091 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
2092
2093 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new);
2094
2095 new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
2096 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
2097 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
2098 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
2099 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
2100 REG_WRITE(ah, AR_PHY_SPUR_REG, new);
2101
2102 spur_delta_phase = ((bb_spur * 524288) / 100) &
2103 AR_PHY_TIMING11_SPUR_DELTA_PHASE;
2104
2105 denominator = IS_CHAN_2GHZ(chan) ? 440 : 400;
2106 spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff;
2107
2108 new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
2109 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
2110 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
2111 REG_WRITE(ah, AR_PHY_TIMING11, new);
2112
2113 cur_bin = -6000;
2114 upper = bin + 100;
2115 lower = bin - 100;
2116
2117 for (i = 0; i < 4; i++) {
2118 int pilot_mask = 0;
2119 int chan_mask = 0;
2120 int bp = 0;
2121 for (bp = 0; bp < 30; bp++) {
2122 if ((cur_bin > lower) && (cur_bin < upper)) {
2123 pilot_mask = pilot_mask | 0x1 << bp;
2124 chan_mask = chan_mask | 0x1 << bp;
2125 }
2126 cur_bin += 100;
2127 }
2128 cur_bin += inc[i];
2129 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
2130 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
2131 }
2132
2133 cur_vit_mask = 6100;
2134 upper = bin + 120;
2135 lower = bin - 120;
2136
2137 for (i = 0; i < 123; i++) {
2138 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
Adrian Bunk88b9e2b2008-08-05 22:06:51 +03002139
2140 /* workaround for gcc bug #37014 */
2141 volatile int tmp = abs(cur_vit_mask - bin);
2142
2143 if (tmp < 75)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002144 mask_amt = 1;
2145 else
2146 mask_amt = 0;
2147 if (cur_vit_mask < 0)
2148 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
2149 else
2150 mask_p[cur_vit_mask / 100] = mask_amt;
2151 }
2152 cur_vit_mask -= 100;
2153 }
2154
2155 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
2156 | (mask_m[48] << 26) | (mask_m[49] << 24)
2157 | (mask_m[50] << 22) | (mask_m[51] << 20)
2158 | (mask_m[52] << 18) | (mask_m[53] << 16)
2159 | (mask_m[54] << 14) | (mask_m[55] << 12)
2160 | (mask_m[56] << 10) | (mask_m[57] << 8)
2161 | (mask_m[58] << 6) | (mask_m[59] << 4)
2162 | (mask_m[60] << 2) | (mask_m[61] << 0);
2163 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
2164 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
2165
2166 tmp_mask = (mask_m[31] << 28)
2167 | (mask_m[32] << 26) | (mask_m[33] << 24)
2168 | (mask_m[34] << 22) | (mask_m[35] << 20)
2169 | (mask_m[36] << 18) | (mask_m[37] << 16)
2170 | (mask_m[48] << 14) | (mask_m[39] << 12)
2171 | (mask_m[40] << 10) | (mask_m[41] << 8)
2172 | (mask_m[42] << 6) | (mask_m[43] << 4)
2173 | (mask_m[44] << 2) | (mask_m[45] << 0);
2174 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
2175 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
2176
2177 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
2178 | (mask_m[18] << 26) | (mask_m[18] << 24)
2179 | (mask_m[20] << 22) | (mask_m[20] << 20)
2180 | (mask_m[22] << 18) | (mask_m[22] << 16)
2181 | (mask_m[24] << 14) | (mask_m[24] << 12)
2182 | (mask_m[25] << 10) | (mask_m[26] << 8)
2183 | (mask_m[27] << 6) | (mask_m[28] << 4)
2184 | (mask_m[29] << 2) | (mask_m[30] << 0);
2185 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
2186 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
2187
2188 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
2189 | (mask_m[2] << 26) | (mask_m[3] << 24)
2190 | (mask_m[4] << 22) | (mask_m[5] << 20)
2191 | (mask_m[6] << 18) | (mask_m[7] << 16)
2192 | (mask_m[8] << 14) | (mask_m[9] << 12)
2193 | (mask_m[10] << 10) | (mask_m[11] << 8)
2194 | (mask_m[12] << 6) | (mask_m[13] << 4)
2195 | (mask_m[14] << 2) | (mask_m[15] << 0);
2196 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
2197 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
2198
2199 tmp_mask = (mask_p[15] << 28)
2200 | (mask_p[14] << 26) | (mask_p[13] << 24)
2201 | (mask_p[12] << 22) | (mask_p[11] << 20)
2202 | (mask_p[10] << 18) | (mask_p[9] << 16)
2203 | (mask_p[8] << 14) | (mask_p[7] << 12)
2204 | (mask_p[6] << 10) | (mask_p[5] << 8)
2205 | (mask_p[4] << 6) | (mask_p[3] << 4)
2206 | (mask_p[2] << 2) | (mask_p[1] << 0);
2207 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
2208 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
2209
2210 tmp_mask = (mask_p[30] << 28)
2211 | (mask_p[29] << 26) | (mask_p[28] << 24)
2212 | (mask_p[27] << 22) | (mask_p[26] << 20)
2213 | (mask_p[25] << 18) | (mask_p[24] << 16)
2214 | (mask_p[23] << 14) | (mask_p[22] << 12)
2215 | (mask_p[21] << 10) | (mask_p[20] << 8)
2216 | (mask_p[19] << 6) | (mask_p[18] << 4)
2217 | (mask_p[17] << 2) | (mask_p[16] << 0);
2218 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
2219 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
2220
2221 tmp_mask = (mask_p[45] << 28)
2222 | (mask_p[44] << 26) | (mask_p[43] << 24)
2223 | (mask_p[42] << 22) | (mask_p[41] << 20)
2224 | (mask_p[40] << 18) | (mask_p[39] << 16)
2225 | (mask_p[38] << 14) | (mask_p[37] << 12)
2226 | (mask_p[36] << 10) | (mask_p[35] << 8)
2227 | (mask_p[34] << 6) | (mask_p[33] << 4)
2228 | (mask_p[32] << 2) | (mask_p[31] << 0);
2229 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
2230 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
2231
2232 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
2233 | (mask_p[59] << 26) | (mask_p[58] << 24)
2234 | (mask_p[57] << 22) | (mask_p[56] << 20)
2235 | (mask_p[55] << 18) | (mask_p[54] << 16)
2236 | (mask_p[53] << 14) | (mask_p[52] << 12)
2237 | (mask_p[51] << 10) | (mask_p[50] << 8)
2238 | (mask_p[49] << 6) | (mask_p[48] << 4)
2239 | (mask_p[47] << 2) | (mask_p[46] << 0);
2240 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
2241 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
2242}
2243
Sujithf1dc5602008-10-29 10:16:30 +05302244bool ath9k_hw_reset(struct ath_hal *ah, struct ath9k_channel *chan,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002245 enum ath9k_ht_macmode macmode,
2246 u8 txchainmask, u8 rxchainmask,
2247 enum ath9k_ht_extprotspacing extprotspacing,
Sujithf1dc5602008-10-29 10:16:30 +05302248 bool bChannelChange, int *status)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002249{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002250 u32 saveLedState;
2251 struct ath_hal_5416 *ahp = AH5416(ah);
2252 struct ath9k_channel *curchan = ah->ah_curchan;
2253 u32 saveDefAntenna;
2254 u32 macStaId1;
2255 int ecode;
2256 int i, rx_chainmask;
2257
2258 ahp->ah_extprotspacing = extprotspacing;
2259 ahp->ah_txchainmask = txchainmask;
2260 ahp->ah_rxchainmask = rxchainmask;
2261
2262 if (AR_SREV_9280(ah)) {
2263 ahp->ah_txchainmask &= 0x3;
2264 ahp->ah_rxchainmask &= 0x3;
2265 }
2266
2267 if (ath9k_hw_check_chan(ah, chan) == NULL) {
2268 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
Sujith04bd4632008-11-28 22:18:05 +05302269 "invalid channel %u/0x%x; no mapping\n",
2270 chan->channel, chan->channelFlags);
Luis R. Rodriguez1cf69cf2008-10-10 12:25:45 -07002271 ecode = -EINVAL;
2272 goto bad;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002273 }
2274
Luis R. Rodriguezd2a3b222008-10-10 12:26:24 -07002275 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
2276 ecode = -EIO;
2277 goto bad;
2278 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002279
2280 if (curchan)
2281 ath9k_hw_getnf(ah, curchan);
2282
2283 if (bChannelChange &&
2284 (ahp->ah_chipFullSleep != true) &&
2285 (ah->ah_curchan != NULL) &&
2286 (chan->channel != ah->ah_curchan->channel) &&
2287 ((chan->channelFlags & CHANNEL_ALL) ==
2288 (ah->ah_curchan->channelFlags & CHANNEL_ALL)) &&
2289 (!AR_SREV_9280(ah) || (!IS_CHAN_A_5MHZ_SPACED(chan) &&
Sujith99405f92008-11-24 12:08:35 +05302290 !IS_CHAN_A_5MHZ_SPACED(ah->ah_curchan)))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002291
2292 if (ath9k_hw_channel_change(ah, chan, macmode)) {
2293 ath9k_hw_loadnf(ah, ah->ah_curchan);
2294 ath9k_hw_start_nfcal(ah);
2295 return true;
2296 }
2297 }
2298
2299 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
2300 if (saveDefAntenna == 0)
2301 saveDefAntenna = 1;
2302
2303 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
2304
2305 saveLedState = REG_READ(ah, AR_CFG_LED) &
2306 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
2307 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
2308
2309 ath9k_hw_mark_phy_inactive(ah);
2310
2311 if (!ath9k_hw_chip_reset(ah, chan)) {
Sujith04bd4632008-11-28 22:18:05 +05302312 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "chip reset failed\n");
Luis R. Rodriguez1cf69cf2008-10-10 12:25:45 -07002313 ecode = -EINVAL;
2314 goto bad;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002315 }
2316
2317 if (AR_SREV_9280(ah)) {
2318 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
2319 AR_GPIO_JTAG_DISABLE);
2320
Sujith86b89ee2008-08-07 10:54:57 +05302321 if (test_bit(ATH9K_MODE_11A, ah->ah_caps.wireless_modes)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002322 if (IS_CHAN_5GHZ(chan))
2323 ath9k_hw_set_gpio(ah, 9, 0);
2324 else
2325 ath9k_hw_set_gpio(ah, 9, 1);
2326 }
Vasanthakumar Thiagarajanc83be682008-08-25 20:47:29 +05302327 ath9k_hw_cfg_output(ah, 9, AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002328 }
2329
2330 ecode = ath9k_hw_process_ini(ah, chan, macmode);
Luis R. Rodriguez1cf69cf2008-10-10 12:25:45 -07002331 if (ecode != 0) {
2332 ecode = -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002333 goto bad;
Luis R. Rodriguez1cf69cf2008-10-10 12:25:45 -07002334 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002335
2336 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
2337 ath9k_hw_set_delta_slope(ah, chan);
2338
2339 if (AR_SREV_9280_10_OR_LATER(ah))
2340 ath9k_hw_9280_spur_mitigate(ah, chan);
2341 else
2342 ath9k_hw_spur_mitigate(ah, chan);
2343
2344 if (!ath9k_hw_eeprom_set_board_values(ah, chan)) {
2345 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
Sujith04bd4632008-11-28 22:18:05 +05302346 "error setting board options\n");
Luis R. Rodriguez1cf69cf2008-10-10 12:25:45 -07002347 ecode = -EIO;
2348 goto bad;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002349 }
2350
2351 ath9k_hw_decrease_chain_power(ah, chan);
2352
2353 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(ahp->ah_macaddr));
2354 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(ahp->ah_macaddr + 4)
2355 | macStaId1
2356 | AR_STA_ID1_RTS_USE_DEF
2357 | (ah->ah_config.
Sujith60b67f52008-08-07 10:52:38 +05302358 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002359 | ahp->ah_staId1Defaults);
Sujithb4696c8b2008-08-11 14:04:52 +05302360 ath9k_hw_set_operating_mode(ah, ah->ah_opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002361
2362 REG_WRITE(ah, AR_BSSMSKL, get_unaligned_le32(ahp->ah_bssidmask));
2363 REG_WRITE(ah, AR_BSSMSKU, get_unaligned_le16(ahp->ah_bssidmask + 4));
2364
2365 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
2366
2367 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(ahp->ah_bssid));
2368 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(ahp->ah_bssid + 4) |
2369 ((ahp->ah_assocId & 0x3fff) << AR_BSS_ID1_AID_S));
2370
2371 REG_WRITE(ah, AR_ISR, ~0);
2372
2373 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
2374
2375 if (AR_SREV_9280_10_OR_LATER(ah)) {
Luis R. Rodriguez1cf69cf2008-10-10 12:25:45 -07002376 if (!(ath9k_hw_ar9280_set_channel(ah, chan))) {
2377 ecode = -EIO;
2378 goto bad;
2379 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002380 } else {
Luis R. Rodriguez1cf69cf2008-10-10 12:25:45 -07002381 if (!(ath9k_hw_set_channel(ah, chan))) {
2382 ecode = -EIO;
2383 goto bad;
2384 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002385 }
2386
2387 for (i = 0; i < AR_NUM_DCU; i++)
2388 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
2389
2390 ahp->ah_intrTxqs = 0;
Sujith60b67f52008-08-07 10:52:38 +05302391 for (i = 0; i < ah->ah_caps.total_queues; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002392 ath9k_hw_resettxqueue(ah, i);
2393
Sujithb4696c8b2008-08-11 14:04:52 +05302394 ath9k_hw_init_interrupt_masks(ah, ah->ah_opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002395 ath9k_hw_init_qos(ah);
2396
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05302397#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05302398 if (ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
2399 ath9k_enable_rfkill(ah);
2400#endif
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002401 ath9k_hw_init_user_settings(ah);
2402
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002403 REG_WRITE(ah, AR_STA_ID1,
2404 REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
2405
2406 ath9k_hw_set_dma(ah);
2407
2408 REG_WRITE(ah, AR_OBS, 8);
2409
2410 if (ahp->ah_intrMitigation) {
2411
2412 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
2413 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
2414 }
2415
2416 ath9k_hw_init_bb(ah, chan);
2417
Luis R. Rodriguez1cf69cf2008-10-10 12:25:45 -07002418 if (!ath9k_hw_init_cal(ah, chan)){
2419 ecode = -EIO;;
2420 goto bad;
2421 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002422
2423 rx_chainmask = ahp->ah_rxchainmask;
2424 if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) {
2425 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
2426 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
2427 }
2428
2429 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
2430
2431 if (AR_SREV_9100(ah)) {
2432 u32 mask;
2433 mask = REG_READ(ah, AR_CFG);
2434 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
2435 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05302436 "CFG Byte Swap Set 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002437 } else {
2438 mask =
2439 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
2440 REG_WRITE(ah, AR_CFG, mask);
2441 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05302442 "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002443 }
2444 } else {
2445#ifdef __BIG_ENDIAN
2446 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
2447#endif
2448 }
2449
2450 return true;
2451bad:
2452 if (status)
2453 *status = ecode;
2454 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002455}
2456
Sujithf1dc5602008-10-29 10:16:30 +05302457/************************/
2458/* Key Cache Management */
2459/************************/
2460
2461bool ath9k_hw_keyreset(struct ath_hal *ah, u16 entry)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002462{
Sujithf1dc5602008-10-29 10:16:30 +05302463 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002464
Sujithf1dc5602008-10-29 10:16:30 +05302465 if (entry >= ah->ah_caps.keycache_size) {
2466 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
Sujith04bd4632008-11-28 22:18:05 +05302467 "entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002468 return false;
2469 }
2470
Sujithf1dc5602008-10-29 10:16:30 +05302471 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002472
Sujithf1dc5602008-10-29 10:16:30 +05302473 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
2474 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
2475 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
2476 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
2477 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
2478 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
2479 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
2480 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
2481
2482 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2483 u16 micentry = entry + 64;
2484
2485 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
2486 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
2487 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
2488 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
2489
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002490 }
2491
Sujithf1dc5602008-10-29 10:16:30 +05302492 if (ah->ah_curchan == NULL)
2493 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002494
2495 return true;
2496}
2497
Sujithf1dc5602008-10-29 10:16:30 +05302498bool ath9k_hw_keysetmac(struct ath_hal *ah, u16 entry, const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002499{
Sujithf1dc5602008-10-29 10:16:30 +05302500 u32 macHi, macLo;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002501
Sujithf1dc5602008-10-29 10:16:30 +05302502 if (entry >= ah->ah_caps.keycache_size) {
2503 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
Sujith04bd4632008-11-28 22:18:05 +05302504 "entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002505 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002506 }
2507
Sujithf1dc5602008-10-29 10:16:30 +05302508 if (mac != NULL) {
2509 macHi = (mac[5] << 8) | mac[4];
2510 macLo = (mac[3] << 24) |
2511 (mac[2] << 16) |
2512 (mac[1] << 8) |
2513 mac[0];
2514 macLo >>= 1;
2515 macLo |= (macHi & 1) << 31;
2516 macHi >>= 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002517 } else {
Sujithf1dc5602008-10-29 10:16:30 +05302518 macLo = macHi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002519 }
Sujithf1dc5602008-10-29 10:16:30 +05302520 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
2521 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002522
2523 return true;
2524}
2525
Sujithf1dc5602008-10-29 10:16:30 +05302526bool ath9k_hw_set_keycache_entry(struct ath_hal *ah, u16 entry,
2527 const struct ath9k_keyval *k,
2528 const u8 *mac, int xorKey)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002529{
Sujith60b67f52008-08-07 10:52:38 +05302530 const struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
Sujithf1dc5602008-10-29 10:16:30 +05302531 u32 key0, key1, key2, key3, key4;
2532 u32 keyType;
2533 u32 xorMask = xorKey ?
2534 (ATH9K_KEY_XOR << 24 | ATH9K_KEY_XOR << 16 | ATH9K_KEY_XOR << 8
2535 | ATH9K_KEY_XOR) : 0;
2536 struct ath_hal_5416 *ahp = AH5416(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002537
Sujithf1dc5602008-10-29 10:16:30 +05302538 if (entry >= pCap->keycache_size) {
2539 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
Sujith04bd4632008-11-28 22:18:05 +05302540 "entry %u out of range\n", entry);
Sujithf1dc5602008-10-29 10:16:30 +05302541 return false;
2542 }
2543
2544 switch (k->kv_type) {
2545 case ATH9K_CIPHER_AES_OCB:
2546 keyType = AR_KEYTABLE_TYPE_AES;
2547 break;
2548 case ATH9K_CIPHER_AES_CCM:
2549 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
2550 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
Sujith04bd4632008-11-28 22:18:05 +05302551 "AES-CCM not supported by mac rev 0x%x\n",
Sujithf1dc5602008-10-29 10:16:30 +05302552 ah->ah_macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002553 return false;
2554 }
Sujithf1dc5602008-10-29 10:16:30 +05302555 keyType = AR_KEYTABLE_TYPE_CCM;
2556 break;
2557 case ATH9K_CIPHER_TKIP:
2558 keyType = AR_KEYTABLE_TYPE_TKIP;
2559 if (ATH9K_IS_MIC_ENABLED(ah)
2560 && entry + 64 >= pCap->keycache_size) {
2561 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
Sujith04bd4632008-11-28 22:18:05 +05302562 "entry %u inappropriate for TKIP\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002563 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002564 }
Sujithf1dc5602008-10-29 10:16:30 +05302565 break;
2566 case ATH9K_CIPHER_WEP:
2567 if (k->kv_len < LEN_WEP40) {
2568 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
Sujith04bd4632008-11-28 22:18:05 +05302569 "WEP key length %u too small\n", k->kv_len);
Sujithf1dc5602008-10-29 10:16:30 +05302570 return false;
2571 }
2572 if (k->kv_len <= LEN_WEP40)
2573 keyType = AR_KEYTABLE_TYPE_40;
2574 else if (k->kv_len <= LEN_WEP104)
2575 keyType = AR_KEYTABLE_TYPE_104;
2576 else
2577 keyType = AR_KEYTABLE_TYPE_128;
2578 break;
2579 case ATH9K_CIPHER_CLR:
2580 keyType = AR_KEYTABLE_TYPE_CLR;
2581 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002582 default:
Sujithf1dc5602008-10-29 10:16:30 +05302583 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
Sujith04bd4632008-11-28 22:18:05 +05302584 "cipher %u not supported\n", k->kv_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002585 return false;
2586 }
Sujithf1dc5602008-10-29 10:16:30 +05302587
2588 key0 = get_unaligned_le32(k->kv_val + 0) ^ xorMask;
2589 key1 = (get_unaligned_le16(k->kv_val + 4) ^ xorMask) & 0xffff;
2590 key2 = get_unaligned_le32(k->kv_val + 6) ^ xorMask;
2591 key3 = (get_unaligned_le16(k->kv_val + 10) ^ xorMask) & 0xffff;
2592 key4 = get_unaligned_le32(k->kv_val + 12) ^ xorMask;
2593 if (k->kv_len <= LEN_WEP104)
2594 key4 &= 0xff;
2595
2596 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2597 u16 micentry = entry + 64;
2598
2599 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
2600 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
2601 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2602 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
2603 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2604 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
2605 (void) ath9k_hw_keysetmac(ah, entry, mac);
2606
2607 if (ahp->ah_miscMode & AR_PCU_MIC_NEW_LOC_ENA) {
2608 u32 mic0, mic1, mic2, mic3, mic4;
2609
2610 mic0 = get_unaligned_le32(k->kv_mic + 0);
2611 mic2 = get_unaligned_le32(k->kv_mic + 4);
2612 mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
2613 mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
2614 mic4 = get_unaligned_le32(k->kv_txmic + 4);
2615 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2616 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
2617 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2618 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
2619 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
2620 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2621 AR_KEYTABLE_TYPE_CLR);
2622
2623 } else {
2624 u32 mic0, mic2;
2625
2626 mic0 = get_unaligned_le32(k->kv_mic + 0);
2627 mic2 = get_unaligned_le32(k->kv_mic + 4);
2628 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2629 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
2630 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2631 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
2632 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
2633 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2634 AR_KEYTABLE_TYPE_CLR);
2635 }
2636 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
2637 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
2638 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2639 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
2640 } else {
2641 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2642 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
2643 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2644 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
2645 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2646 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
2647
2648 (void) ath9k_hw_keysetmac(ah, entry, mac);
2649 }
2650
2651 if (ah->ah_curchan == NULL)
2652 return true;
2653
2654 return true;
2655}
2656
2657bool ath9k_hw_keyisvalid(struct ath_hal *ah, u16 entry)
2658{
2659 if (entry < ah->ah_caps.keycache_size) {
2660 u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
2661 if (val & AR_KEYTABLE_VALID)
2662 return true;
2663 }
2664 return false;
2665}
2666
2667/******************************/
2668/* Power Management (Chipset) */
2669/******************************/
2670
2671static void ath9k_set_power_sleep(struct ath_hal *ah, int setChip)
2672{
2673 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2674 if (setChip) {
2675 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2676 AR_RTC_FORCE_WAKE_EN);
2677 if (!AR_SREV_9100(ah))
2678 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
2679
2680 REG_CLR_BIT(ah, (u16) (AR_RTC_RESET),
2681 AR_RTC_RESET_EN);
2682 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002683}
2684
Sujithf1dc5602008-10-29 10:16:30 +05302685static void ath9k_set_power_network_sleep(struct ath_hal *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002686{
Sujithf1dc5602008-10-29 10:16:30 +05302687 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2688 if (setChip) {
2689 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002690
Sujithf1dc5602008-10-29 10:16:30 +05302691 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
2692 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2693 AR_RTC_FORCE_WAKE_ON_INT);
2694 } else {
2695 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2696 AR_RTC_FORCE_WAKE_EN);
2697 }
2698 }
2699}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002700
Sujithf1dc5602008-10-29 10:16:30 +05302701static bool ath9k_hw_set_power_awake(struct ath_hal *ah,
2702 int setChip)
2703{
2704 u32 val;
2705 int i;
2706
2707 if (setChip) {
2708 if ((REG_READ(ah, AR_RTC_STATUS) &
2709 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2710 if (ath9k_hw_set_reset_reg(ah,
2711 ATH9K_RESET_POWER_ON) != true) {
2712 return false;
2713 }
2714 }
2715 if (AR_SREV_9100(ah))
2716 REG_SET_BIT(ah, AR_RTC_RESET,
2717 AR_RTC_RESET_EN);
2718
2719 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2720 AR_RTC_FORCE_WAKE_EN);
2721 udelay(50);
2722
2723 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2724 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2725 if (val == AR_RTC_STATUS_ON)
2726 break;
2727 udelay(50);
2728 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2729 AR_RTC_FORCE_WAKE_EN);
2730 }
2731 if (i == 0) {
2732 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
Sujith04bd4632008-11-28 22:18:05 +05302733 "Failed to wakeup in %uus\n", POWER_UP_TIME / 20);
Sujithf1dc5602008-10-29 10:16:30 +05302734 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002735 }
2736 }
2737
Sujithf1dc5602008-10-29 10:16:30 +05302738 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2739
2740 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002741}
2742
Sujithf1dc5602008-10-29 10:16:30 +05302743bool ath9k_hw_setpower(struct ath_hal *ah,
2744 enum ath9k_power_mode mode)
2745{
2746 struct ath_hal_5416 *ahp = AH5416(ah);
2747 static const char *modes[] = {
2748 "AWAKE",
2749 "FULL-SLEEP",
2750 "NETWORK SLEEP",
2751 "UNDEFINED"
2752 };
2753 int status = true, setChip = true;
2754
Sujith04bd4632008-11-28 22:18:05 +05302755 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT, "%s -> %s (%s)\n",
Sujithf1dc5602008-10-29 10:16:30 +05302756 modes[ahp->ah_powerMode], modes[mode],
2757 setChip ? "set chip " : "");
2758
2759 switch (mode) {
2760 case ATH9K_PM_AWAKE:
2761 status = ath9k_hw_set_power_awake(ah, setChip);
2762 break;
2763 case ATH9K_PM_FULL_SLEEP:
2764 ath9k_set_power_sleep(ah, setChip);
2765 ahp->ah_chipFullSleep = true;
2766 break;
2767 case ATH9K_PM_NETWORK_SLEEP:
2768 ath9k_set_power_network_sleep(ah, setChip);
2769 break;
2770 default:
2771 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
Sujith04bd4632008-11-28 22:18:05 +05302772 "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05302773 return false;
2774 }
2775 ahp->ah_powerMode = mode;
2776
2777 return status;
2778}
2779
2780void ath9k_hw_configpcipowersave(struct ath_hal *ah, int restore)
2781{
2782 struct ath_hal_5416 *ahp = AH5416(ah);
2783 u8 i;
2784
2785 if (ah->ah_isPciExpress != true)
2786 return;
2787
2788 if (ah->ah_config.pcie_powersave_enable == 2)
2789 return;
2790
2791 if (restore)
2792 return;
2793
2794 if (AR_SREV_9280_20_OR_LATER(ah)) {
2795 for (i = 0; i < ahp->ah_iniPcieSerdes.ia_rows; i++) {
2796 REG_WRITE(ah, INI_RA(&ahp->ah_iniPcieSerdes, i, 0),
2797 INI_RA(&ahp->ah_iniPcieSerdes, i, 1));
2798 }
2799 udelay(1000);
2800 } else if (AR_SREV_9280(ah) &&
2801 (ah->ah_macRev == AR_SREV_REVISION_9280_10)) {
2802 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
2803 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
2804
2805 REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
2806 REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
2807 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
2808
2809 if (ah->ah_config.pcie_clock_req)
2810 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
2811 else
2812 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
2813
2814 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2815 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2816 REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
2817
2818 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
2819
2820 udelay(1000);
2821 } else {
2822 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
2823 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
2824 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
2825 REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
2826 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
2827 REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
2828 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2829 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2830 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
2831 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
2832 }
2833
2834 REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
2835
2836 if (ah->ah_config.pcie_waen) {
2837 REG_WRITE(ah, AR_WA, ah->ah_config.pcie_waen);
2838 } else {
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302839 if (AR_SREV_9285(ah))
2840 REG_WRITE(ah, AR_WA, AR9285_WA_DEFAULT);
2841 else if (AR_SREV_9280(ah))
2842 REG_WRITE(ah, AR_WA, AR9280_WA_DEFAULT);
Sujithf1dc5602008-10-29 10:16:30 +05302843 else
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302844 REG_WRITE(ah, AR_WA, AR_WA_DEFAULT);
Sujithf1dc5602008-10-29 10:16:30 +05302845 }
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302846
Sujithf1dc5602008-10-29 10:16:30 +05302847}
2848
2849/**********************/
2850/* Interrupt Handling */
2851/**********************/
2852
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002853bool ath9k_hw_intrpend(struct ath_hal *ah)
2854{
2855 u32 host_isr;
2856
2857 if (AR_SREV_9100(ah))
2858 return true;
2859
2860 host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
2861 if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
2862 return true;
2863
2864 host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
2865 if ((host_isr & AR_INTR_SYNC_DEFAULT)
2866 && (host_isr != AR_INTR_SPURIOUS))
2867 return true;
2868
2869 return false;
2870}
2871
2872bool ath9k_hw_getisr(struct ath_hal *ah, enum ath9k_int *masked)
2873{
2874 u32 isr = 0;
2875 u32 mask2 = 0;
Sujith60b67f52008-08-07 10:52:38 +05302876 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002877 u32 sync_cause = 0;
2878 bool fatal_int = false;
Sujithf1dc5602008-10-29 10:16:30 +05302879 struct ath_hal_5416 *ahp = AH5416(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002880
2881 if (!AR_SREV_9100(ah)) {
2882 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
2883 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
2884 == AR_RTC_STATUS_ON) {
2885 isr = REG_READ(ah, AR_ISR);
2886 }
2887 }
2888
Sujithf1dc5602008-10-29 10:16:30 +05302889 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
2890 AR_INTR_SYNC_DEFAULT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002891
2892 *masked = 0;
2893
2894 if (!isr && !sync_cause)
2895 return false;
2896 } else {
2897 *masked = 0;
2898 isr = REG_READ(ah, AR_ISR);
2899 }
2900
2901 if (isr) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002902 if (isr & AR_ISR_BCNMISC) {
2903 u32 isr2;
2904 isr2 = REG_READ(ah, AR_ISR_S2);
2905 if (isr2 & AR_ISR_S2_TIM)
2906 mask2 |= ATH9K_INT_TIM;
2907 if (isr2 & AR_ISR_S2_DTIM)
2908 mask2 |= ATH9K_INT_DTIM;
2909 if (isr2 & AR_ISR_S2_DTIMSYNC)
2910 mask2 |= ATH9K_INT_DTIMSYNC;
2911 if (isr2 & (AR_ISR_S2_CABEND))
2912 mask2 |= ATH9K_INT_CABEND;
2913 if (isr2 & AR_ISR_S2_GTT)
2914 mask2 |= ATH9K_INT_GTT;
2915 if (isr2 & AR_ISR_S2_CST)
2916 mask2 |= ATH9K_INT_CST;
2917 }
2918
2919 isr = REG_READ(ah, AR_ISR_RAC);
2920 if (isr == 0xffffffff) {
2921 *masked = 0;
2922 return false;
2923 }
2924
2925 *masked = isr & ATH9K_INT_COMMON;
2926
2927 if (ahp->ah_intrMitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002928 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
2929 *masked |= ATH9K_INT_RX;
2930 }
2931
2932 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
2933 *masked |= ATH9K_INT_RX;
2934 if (isr &
2935 (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
2936 AR_ISR_TXEOL)) {
2937 u32 s0_s, s1_s;
2938
2939 *masked |= ATH9K_INT_TX;
2940
2941 s0_s = REG_READ(ah, AR_ISR_S0_S);
2942 ahp->ah_intrTxqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
2943 ahp->ah_intrTxqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
2944
2945 s1_s = REG_READ(ah, AR_ISR_S1_S);
2946 ahp->ah_intrTxqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
2947 ahp->ah_intrTxqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
2948 }
2949
2950 if (isr & AR_ISR_RXORN) {
2951 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
Sujith04bd4632008-11-28 22:18:05 +05302952 "receive FIFO overrun interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002953 }
2954
2955 if (!AR_SREV_9100(ah)) {
Sujith60b67f52008-08-07 10:52:38 +05302956 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002957 u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
2958 if (isr5 & AR_ISR_S5_TIM_TIMER)
2959 *masked |= ATH9K_INT_TIM_TIMER;
2960 }
2961 }
2962
2963 *masked |= mask2;
2964 }
Sujithf1dc5602008-10-29 10:16:30 +05302965
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002966 if (AR_SREV_9100(ah))
2967 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302968
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002969 if (sync_cause) {
2970 fatal_int =
2971 (sync_cause &
2972 (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
2973 ? true : false;
2974
2975 if (fatal_int) {
2976 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
2977 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
Sujith04bd4632008-11-28 22:18:05 +05302978 "received PCI FATAL interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002979 }
2980 if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
2981 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
Sujith04bd4632008-11-28 22:18:05 +05302982 "received PCI PERR interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002983 }
2984 }
2985 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
2986 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
Sujith04bd4632008-11-28 22:18:05 +05302987 "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002988 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
2989 REG_WRITE(ah, AR_RC, 0);
2990 *masked |= ATH9K_INT_FATAL;
2991 }
2992 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
2993 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
Sujith04bd4632008-11-28 22:18:05 +05302994 "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002995 }
2996
2997 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
2998 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
2999 }
Sujithf1dc5602008-10-29 10:16:30 +05303000
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003001 return true;
3002}
3003
3004enum ath9k_int ath9k_hw_intrget(struct ath_hal *ah)
3005{
3006 return AH5416(ah)->ah_maskReg;
3007}
3008
3009enum ath9k_int ath9k_hw_set_interrupts(struct ath_hal *ah, enum ath9k_int ints)
3010{
3011 struct ath_hal_5416 *ahp = AH5416(ah);
3012 u32 omask = ahp->ah_maskReg;
3013 u32 mask, mask2;
Sujith60b67f52008-08-07 10:52:38 +05303014 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003015
Sujith04bd4632008-11-28 22:18:05 +05303016 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003017
3018 if (omask & ATH9K_INT_GLOBAL) {
Sujith04bd4632008-11-28 22:18:05 +05303019 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "disable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003020 REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
3021 (void) REG_READ(ah, AR_IER);
3022 if (!AR_SREV_9100(ah)) {
3023 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
3024 (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
3025
3026 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
3027 (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
3028 }
3029 }
3030
3031 mask = ints & ATH9K_INT_COMMON;
3032 mask2 = 0;
3033
3034 if (ints & ATH9K_INT_TX) {
3035 if (ahp->ah_txOkInterruptMask)
3036 mask |= AR_IMR_TXOK;
3037 if (ahp->ah_txDescInterruptMask)
3038 mask |= AR_IMR_TXDESC;
3039 if (ahp->ah_txErrInterruptMask)
3040 mask |= AR_IMR_TXERR;
3041 if (ahp->ah_txEolInterruptMask)
3042 mask |= AR_IMR_TXEOL;
3043 }
3044 if (ints & ATH9K_INT_RX) {
3045 mask |= AR_IMR_RXERR;
3046 if (ahp->ah_intrMitigation)
3047 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
3048 else
3049 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
Sujith60b67f52008-08-07 10:52:38 +05303050 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003051 mask |= AR_IMR_GENTMR;
3052 }
3053
3054 if (ints & (ATH9K_INT_BMISC)) {
3055 mask |= AR_IMR_BCNMISC;
3056 if (ints & ATH9K_INT_TIM)
3057 mask2 |= AR_IMR_S2_TIM;
3058 if (ints & ATH9K_INT_DTIM)
3059 mask2 |= AR_IMR_S2_DTIM;
3060 if (ints & ATH9K_INT_DTIMSYNC)
3061 mask2 |= AR_IMR_S2_DTIMSYNC;
3062 if (ints & ATH9K_INT_CABEND)
3063 mask2 |= (AR_IMR_S2_CABEND);
3064 }
3065
3066 if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
3067 mask |= AR_IMR_BCNMISC;
3068 if (ints & ATH9K_INT_GTT)
3069 mask2 |= AR_IMR_S2_GTT;
3070 if (ints & ATH9K_INT_CST)
3071 mask2 |= AR_IMR_S2_CST;
3072 }
3073
Sujith04bd4632008-11-28 22:18:05 +05303074 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003075 REG_WRITE(ah, AR_IMR, mask);
3076 mask = REG_READ(ah, AR_IMR_S2) & ~(AR_IMR_S2_TIM |
3077 AR_IMR_S2_DTIM |
3078 AR_IMR_S2_DTIMSYNC |
3079 AR_IMR_S2_CABEND |
3080 AR_IMR_S2_CABTO |
3081 AR_IMR_S2_TSFOOR |
3082 AR_IMR_S2_GTT | AR_IMR_S2_CST);
3083 REG_WRITE(ah, AR_IMR_S2, mask | mask2);
3084 ahp->ah_maskReg = ints;
3085
Sujith60b67f52008-08-07 10:52:38 +05303086 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003087 if (ints & ATH9K_INT_TIM_TIMER)
3088 REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
3089 else
3090 REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
3091 }
3092
3093 if (ints & ATH9K_INT_GLOBAL) {
Sujith04bd4632008-11-28 22:18:05 +05303094 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "enable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003095 REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
3096 if (!AR_SREV_9100(ah)) {
3097 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
3098 AR_INTR_MAC_IRQ);
3099 REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
3100
3101
3102 REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
3103 AR_INTR_SYNC_DEFAULT);
3104 REG_WRITE(ah, AR_INTR_SYNC_MASK,
3105 AR_INTR_SYNC_DEFAULT);
3106 }
3107 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
3108 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
3109 }
3110
3111 return omask;
3112}
3113
Sujithf1dc5602008-10-29 10:16:30 +05303114/*******************/
3115/* Beacon Handling */
3116/*******************/
3117
3118void ath9k_hw_beaconinit(struct ath_hal *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003119{
3120 struct ath_hal_5416 *ahp = AH5416(ah);
3121 int flags = 0;
3122
3123 ahp->ah_beaconInterval = beacon_period;
3124
3125 switch (ah->ah_opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08003126 case NL80211_IFTYPE_STATION:
3127 case NL80211_IFTYPE_MONITOR:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003128 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3129 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
3130 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
3131 flags |= AR_TBTT_TIMER_EN;
3132 break;
Colin McCabed97809d2008-12-01 13:38:55 -08003133 case NL80211_IFTYPE_ADHOC:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003134 REG_SET_BIT(ah, AR_TXCFG,
3135 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
3136 REG_WRITE(ah, AR_NEXT_NDP_TIMER,
3137 TU_TO_USEC(next_beacon +
3138 (ahp->ah_atimWindow ? ahp->
3139 ah_atimWindow : 1)));
3140 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08003141 case NL80211_IFTYPE_AP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003142 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3143 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
3144 TU_TO_USEC(next_beacon -
3145 ah->ah_config.
Sujith60b67f52008-08-07 10:52:38 +05303146 dma_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003147 REG_WRITE(ah, AR_NEXT_SWBA,
3148 TU_TO_USEC(next_beacon -
3149 ah->ah_config.
Sujith60b67f52008-08-07 10:52:38 +05303150 sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003151 flags |=
3152 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
3153 break;
Colin McCabed97809d2008-12-01 13:38:55 -08003154 default:
3155 DPRINTF(ah->ah_sc, ATH_DBG_BEACON,
3156 "%s: unsupported opmode: %d\n",
3157 __func__, ah->ah_opmode);
3158 return;
3159 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003160 }
3161
3162 REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3163 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3164 REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
3165 REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
3166
3167 beacon_period &= ~ATH9K_BEACON_ENA;
3168 if (beacon_period & ATH9K_BEACON_RESET_TSF) {
3169 beacon_period &= ~ATH9K_BEACON_RESET_TSF;
3170 ath9k_hw_reset_tsf(ah);
3171 }
3172
3173 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
3174}
3175
Sujithf1dc5602008-10-29 10:16:30 +05303176void ath9k_hw_set_sta_beacon_timers(struct ath_hal *ah,
3177 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003178{
3179 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith60b67f52008-08-07 10:52:38 +05303180 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003181
3182 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
3183
3184 REG_WRITE(ah, AR_BEACON_PERIOD,
3185 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3186 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
3187 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3188
3189 REG_RMW_FIELD(ah, AR_RSSI_THR,
3190 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
3191
3192 beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
3193
3194 if (bs->bs_sleepduration > beaconintval)
3195 beaconintval = bs->bs_sleepduration;
3196
3197 dtimperiod = bs->bs_dtimperiod;
3198 if (bs->bs_sleepduration > dtimperiod)
3199 dtimperiod = bs->bs_sleepduration;
3200
3201 if (beaconintval == dtimperiod)
3202 nextTbtt = bs->bs_nextdtim;
3203 else
3204 nextTbtt = bs->bs_nexttbtt;
3205
Sujith04bd4632008-11-28 22:18:05 +05303206 DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
3207 DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
3208 DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
3209 DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003210
3211 REG_WRITE(ah, AR_NEXT_DTIM,
3212 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
3213 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
3214
3215 REG_WRITE(ah, AR_SLEEP1,
3216 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
3217 | AR_SLEEP1_ASSUME_DTIM);
3218
Sujith60b67f52008-08-07 10:52:38 +05303219 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003220 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
3221 else
3222 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
3223
3224 REG_WRITE(ah, AR_SLEEP2,
3225 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
3226
3227 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
3228 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
3229
3230 REG_SET_BIT(ah, AR_TIMER_MODE,
3231 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
3232 AR_DTIM_TIMER_EN);
3233
3234}
3235
Sujithf1dc5602008-10-29 10:16:30 +05303236/*******************/
3237/* HW Capabilities */
3238/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003239
Sujithf1dc5602008-10-29 10:16:30 +05303240bool ath9k_hw_fill_cap_info(struct ath_hal *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003241{
Sujithf1dc5602008-10-29 10:16:30 +05303242 struct ath_hal_5416 *ahp = AH5416(ah);
3243 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
3244 u16 capField = 0, eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003245
Sujithf1dc5602008-10-29 10:16:30 +05303246 eeval = ath9k_hw_get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003247
Sujithf1dc5602008-10-29 10:16:30 +05303248 ah->ah_currentRD = eeval;
3249
3250 eeval = ath9k_hw_get_eeprom(ah, EEP_REG_1);
3251 ah->ah_currentRDExt = eeval;
3252
3253 capField = ath9k_hw_get_eeprom(ah, EEP_OP_CAP);
3254
Colin McCabed97809d2008-12-01 13:38:55 -08003255 if (ah->ah_opmode != NL80211_IFTYPE_AP &&
Sujithf1dc5602008-10-29 10:16:30 +05303256 ah->ah_subvendorid == AR_SUBVENDOR_ID_NEW_A) {
3257 if (ah->ah_currentRD == 0x64 || ah->ah_currentRD == 0x65)
3258 ah->ah_currentRD += 5;
3259 else if (ah->ah_currentRD == 0x41)
3260 ah->ah_currentRD = 0x43;
3261 DPRINTF(ah->ah_sc, ATH_DBG_REGULATORY,
Sujith04bd4632008-11-28 22:18:05 +05303262 "regdomain mapped to 0x%x\n", ah->ah_currentRD);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003263 }
Sujithdc2222a2008-08-14 13:26:55 +05303264
Sujithf1dc5602008-10-29 10:16:30 +05303265 eeval = ath9k_hw_get_eeprom(ah, EEP_OP_MODE);
3266 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003267
Sujithf1dc5602008-10-29 10:16:30 +05303268 if (eeval & AR5416_OPFLAGS_11A) {
3269 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
3270 if (ah->ah_config.ht_enable) {
3271 if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
3272 set_bit(ATH9K_MODE_11NA_HT20,
3273 pCap->wireless_modes);
3274 if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
3275 set_bit(ATH9K_MODE_11NA_HT40PLUS,
3276 pCap->wireless_modes);
3277 set_bit(ATH9K_MODE_11NA_HT40MINUS,
3278 pCap->wireless_modes);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003279 }
3280 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003281 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003282
Sujithf1dc5602008-10-29 10:16:30 +05303283 if (eeval & AR5416_OPFLAGS_11G) {
3284 set_bit(ATH9K_MODE_11B, pCap->wireless_modes);
3285 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
3286 if (ah->ah_config.ht_enable) {
3287 if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
3288 set_bit(ATH9K_MODE_11NG_HT20,
3289 pCap->wireless_modes);
3290 if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
3291 set_bit(ATH9K_MODE_11NG_HT40PLUS,
3292 pCap->wireless_modes);
3293 set_bit(ATH9K_MODE_11NG_HT40MINUS,
3294 pCap->wireless_modes);
3295 }
3296 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003297 }
Sujithf1dc5602008-10-29 10:16:30 +05303298
3299 pCap->tx_chainmask = ath9k_hw_get_eeprom(ah, EEP_TX_MASK);
3300 if ((ah->ah_isPciExpress)
3301 || (eeval & AR5416_OPFLAGS_11A)) {
3302 pCap->rx_chainmask =
3303 ath9k_hw_get_eeprom(ah, EEP_RX_MASK);
3304 } else {
3305 pCap->rx_chainmask =
3306 (ath9k_hw_gpio_get(ah, 0)) ? 0x5 : 0x7;
3307 }
3308
3309 if (!(AR_SREV_9280(ah) && (ah->ah_macRev == 0)))
3310 ahp->ah_miscMode |= AR_PCU_MIC_NEW_LOC_ENA;
3311
3312 pCap->low_2ghz_chan = 2312;
3313 pCap->high_2ghz_chan = 2732;
3314
3315 pCap->low_5ghz_chan = 4920;
3316 pCap->high_5ghz_chan = 6100;
3317
3318 pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
3319 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
3320 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
3321
3322 pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
3323 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
3324 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
3325
3326 pCap->hw_caps |= ATH9K_HW_CAP_CHAN_SPREAD;
3327
3328 if (ah->ah_config.ht_enable)
3329 pCap->hw_caps |= ATH9K_HW_CAP_HT;
3330 else
3331 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
3332
3333 pCap->hw_caps |= ATH9K_HW_CAP_GTT;
3334 pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
3335 pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
3336 pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
3337
3338 if (capField & AR_EEPROM_EEPCAP_MAXQCU)
3339 pCap->total_queues =
3340 MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
3341 else
3342 pCap->total_queues = ATH9K_NUM_TX_QUEUES;
3343
3344 if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
3345 pCap->keycache_size =
3346 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
3347 else
3348 pCap->keycache_size = AR_KEYTABLE_SIZE;
3349
3350 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
3351 pCap->num_mr_retries = 4;
3352 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
3353
3354 if (AR_SREV_9280_10_OR_LATER(ah))
3355 pCap->num_gpio_pins = AR928X_NUM_GPIO;
3356 else
3357 pCap->num_gpio_pins = AR_NUM_GPIO;
3358
3359 if (AR_SREV_9280_10_OR_LATER(ah)) {
3360 pCap->hw_caps |= ATH9K_HW_CAP_WOW;
3361 pCap->hw_caps |= ATH9K_HW_CAP_WOW_MATCHPATTERN_EXACT;
3362 } else {
3363 pCap->hw_caps &= ~ATH9K_HW_CAP_WOW;
3364 pCap->hw_caps &= ~ATH9K_HW_CAP_WOW_MATCHPATTERN_EXACT;
3365 }
3366
3367 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
3368 pCap->hw_caps |= ATH9K_HW_CAP_CST;
3369 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
3370 } else {
3371 pCap->rts_aggr_limit = (8 * 1024);
3372 }
3373
3374 pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
3375
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05303376#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujithf1dc5602008-10-29 10:16:30 +05303377 ah->ah_rfsilent = ath9k_hw_get_eeprom(ah, EEP_RF_SILENT);
3378 if (ah->ah_rfsilent & EEP_RFSILENT_ENABLED) {
3379 ah->ah_rfkill_gpio =
3380 MS(ah->ah_rfsilent, EEP_RFSILENT_GPIO_SEL);
3381 ah->ah_rfkill_polarity =
3382 MS(ah->ah_rfsilent, EEP_RFSILENT_POLARITY);
3383
3384 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
3385 }
3386#endif
3387
3388 if ((ah->ah_macVersion == AR_SREV_VERSION_5416_PCI) ||
3389 (ah->ah_macVersion == AR_SREV_VERSION_5416_PCIE) ||
3390 (ah->ah_macVersion == AR_SREV_VERSION_9160) ||
3391 (ah->ah_macVersion == AR_SREV_VERSION_9100) ||
3392 (ah->ah_macVersion == AR_SREV_VERSION_9280))
3393 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
3394 else
3395 pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
3396
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05303397 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303398 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
3399 else
3400 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
3401
3402 if (ah->ah_currentRDExt & (1 << REG_EXT_JAPAN_MIDBAND)) {
3403 pCap->reg_cap =
3404 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3405 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
3406 AR_EEPROM_EEREGCAP_EN_KK_U2 |
3407 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
3408 } else {
3409 pCap->reg_cap =
3410 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3411 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
3412 }
3413
3414 pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
3415
3416 pCap->num_antcfg_5ghz =
Senthil Balasubramanian2df1bff2008-12-08 19:43:49 +05303417 ath9k_hw_get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303418 pCap->num_antcfg_2ghz =
Senthil Balasubramanian2df1bff2008-12-08 19:43:49 +05303419 ath9k_hw_get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303420
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003421 return true;
3422}
3423
Sujithf1dc5602008-10-29 10:16:30 +05303424bool ath9k_hw_getcapability(struct ath_hal *ah, enum ath9k_capability_type type,
3425 u32 capability, u32 *result)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003426{
Sujithf1dc5602008-10-29 10:16:30 +05303427 struct ath_hal_5416 *ahp = AH5416(ah);
3428 const struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003429
Sujithf1dc5602008-10-29 10:16:30 +05303430 switch (type) {
3431 case ATH9K_CAP_CIPHER:
3432 switch (capability) {
3433 case ATH9K_CIPHER_AES_CCM:
3434 case ATH9K_CIPHER_AES_OCB:
3435 case ATH9K_CIPHER_TKIP:
3436 case ATH9K_CIPHER_WEP:
3437 case ATH9K_CIPHER_MIC:
3438 case ATH9K_CIPHER_CLR:
3439 return true;
3440 default:
3441 return false;
3442 }
3443 case ATH9K_CAP_TKIP_MIC:
3444 switch (capability) {
3445 case 0:
3446 return true;
3447 case 1:
3448 return (ahp->ah_staId1Defaults &
3449 AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
3450 false;
3451 }
3452 case ATH9K_CAP_TKIP_SPLIT:
3453 return (ahp->ah_miscMode & AR_PCU_MIC_NEW_LOC_ENA) ?
3454 false : true;
3455 case ATH9K_CAP_WME_TKIPMIC:
3456 return 0;
3457 case ATH9K_CAP_PHYCOUNTERS:
3458 return ahp->ah_hasHwPhyCounters ? 0 : -ENXIO;
3459 case ATH9K_CAP_DIVERSITY:
3460 return (REG_READ(ah, AR_PHY_CCK_DETECT) &
3461 AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV) ?
3462 true : false;
3463 case ATH9K_CAP_PHYDIAG:
3464 return true;
3465 case ATH9K_CAP_MCAST_KEYSRCH:
3466 switch (capability) {
3467 case 0:
3468 return true;
3469 case 1:
3470 if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
3471 return false;
3472 } else {
3473 return (ahp->ah_staId1Defaults &
3474 AR_STA_ID1_MCAST_KSRCH) ? true :
3475 false;
3476 }
3477 }
3478 return false;
3479 case ATH9K_CAP_TSF_ADJUST:
3480 return (ahp->ah_miscMode & AR_PCU_TX_ADD_TSF) ?
3481 true : false;
3482 case ATH9K_CAP_RFSILENT:
3483 if (capability == 3)
3484 return false;
3485 case ATH9K_CAP_ANT_CFG_2GHZ:
3486 *result = pCap->num_antcfg_2ghz;
3487 return true;
3488 case ATH9K_CAP_ANT_CFG_5GHZ:
3489 *result = pCap->num_antcfg_5ghz;
3490 return true;
3491 case ATH9K_CAP_TXPOW:
3492 switch (capability) {
3493 case 0:
3494 return 0;
3495 case 1:
3496 *result = ah->ah_powerLimit;
3497 return 0;
3498 case 2:
3499 *result = ah->ah_maxPowerLevel;
3500 return 0;
3501 case 3:
3502 *result = ah->ah_tpScale;
3503 return 0;
3504 }
3505 return false;
3506 default:
3507 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003508 }
Sujithf1dc5602008-10-29 10:16:30 +05303509}
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003510
Sujithf1dc5602008-10-29 10:16:30 +05303511bool ath9k_hw_setcapability(struct ath_hal *ah, enum ath9k_capability_type type,
3512 u32 capability, u32 setting, int *status)
3513{
3514 struct ath_hal_5416 *ahp = AH5416(ah);
3515 u32 v;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003516
Sujithf1dc5602008-10-29 10:16:30 +05303517 switch (type) {
3518 case ATH9K_CAP_TKIP_MIC:
3519 if (setting)
3520 ahp->ah_staId1Defaults |=
3521 AR_STA_ID1_CRPT_MIC_ENABLE;
3522 else
3523 ahp->ah_staId1Defaults &=
3524 ~AR_STA_ID1_CRPT_MIC_ENABLE;
3525 return true;
3526 case ATH9K_CAP_DIVERSITY:
3527 v = REG_READ(ah, AR_PHY_CCK_DETECT);
3528 if (setting)
3529 v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3530 else
3531 v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3532 REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
3533 return true;
3534 case ATH9K_CAP_MCAST_KEYSRCH:
3535 if (setting)
3536 ahp->ah_staId1Defaults |= AR_STA_ID1_MCAST_KSRCH;
3537 else
3538 ahp->ah_staId1Defaults &= ~AR_STA_ID1_MCAST_KSRCH;
3539 return true;
3540 case ATH9K_CAP_TSF_ADJUST:
3541 if (setting)
3542 ahp->ah_miscMode |= AR_PCU_TX_ADD_TSF;
3543 else
3544 ahp->ah_miscMode &= ~AR_PCU_TX_ADD_TSF;
3545 return true;
3546 default:
3547 return false;
3548 }
3549}
3550
3551/****************************/
3552/* GPIO / RFKILL / Antennae */
3553/****************************/
3554
3555static void ath9k_hw_gpio_cfg_output_mux(struct ath_hal *ah,
3556 u32 gpio, u32 type)
3557{
3558 int addr;
3559 u32 gpio_shift, tmp;
3560
3561 if (gpio > 11)
3562 addr = AR_GPIO_OUTPUT_MUX3;
3563 else if (gpio > 5)
3564 addr = AR_GPIO_OUTPUT_MUX2;
3565 else
3566 addr = AR_GPIO_OUTPUT_MUX1;
3567
3568 gpio_shift = (gpio % 6) * 5;
3569
3570 if (AR_SREV_9280_20_OR_LATER(ah)
3571 || (addr != AR_GPIO_OUTPUT_MUX1)) {
3572 REG_RMW(ah, addr, (type << gpio_shift),
3573 (0x1f << gpio_shift));
3574 } else {
3575 tmp = REG_READ(ah, addr);
3576 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
3577 tmp &= ~(0x1f << gpio_shift);
3578 tmp |= (type << gpio_shift);
3579 REG_WRITE(ah, addr, tmp);
3580 }
3581}
3582
3583void ath9k_hw_cfg_gpio_input(struct ath_hal *ah, u32 gpio)
3584{
3585 u32 gpio_shift;
3586
3587 ASSERT(gpio < ah->ah_caps.num_gpio_pins);
3588
3589 gpio_shift = gpio << 1;
3590
3591 REG_RMW(ah,
3592 AR_GPIO_OE_OUT,
3593 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
3594 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3595}
3596
3597u32 ath9k_hw_gpio_get(struct ath_hal *ah, u32 gpio)
3598{
3599 if (gpio >= ah->ah_caps.num_gpio_pins)
3600 return 0xffffffff;
3601
3602 if (AR_SREV_9280_10_OR_LATER(ah)) {
3603 return (MS
3604 (REG_READ(ah, AR_GPIO_IN_OUT),
3605 AR928X_GPIO_IN_VAL) & AR_GPIO_BIT(gpio)) != 0;
3606 } else {
3607 return (MS(REG_READ(ah, AR_GPIO_IN_OUT), AR_GPIO_IN_VAL) &
3608 AR_GPIO_BIT(gpio)) != 0;
3609 }
3610}
3611
3612void ath9k_hw_cfg_output(struct ath_hal *ah, u32 gpio,
3613 u32 ah_signal_type)
3614{
3615 u32 gpio_shift;
3616
3617 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
3618
3619 gpio_shift = 2 * gpio;
3620
3621 REG_RMW(ah,
3622 AR_GPIO_OE_OUT,
3623 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
3624 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3625}
3626
3627void ath9k_hw_set_gpio(struct ath_hal *ah, u32 gpio, u32 val)
3628{
3629 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
3630 AR_GPIO_BIT(gpio));
3631}
3632
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05303633#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujithf1dc5602008-10-29 10:16:30 +05303634void ath9k_enable_rfkill(struct ath_hal *ah)
3635{
3636 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
3637 AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
3638
3639 REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2,
3640 AR_GPIO_INPUT_MUX2_RFSILENT);
3641
3642 ath9k_hw_cfg_gpio_input(ah, ah->ah_rfkill_gpio);
3643 REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);
3644}
3645#endif
3646
3647int ath9k_hw_select_antconfig(struct ath_hal *ah, u32 cfg)
3648{
3649 struct ath9k_channel *chan = ah->ah_curchan;
3650 const struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
3651 u16 ant_config;
3652 u32 halNumAntConfig;
3653
3654 halNumAntConfig = IS_CHAN_2GHZ(chan) ?
3655 pCap->num_antcfg_2ghz : pCap->num_antcfg_5ghz;
3656
3657 if (cfg < halNumAntConfig) {
3658 if (!ath9k_hw_get_eeprom_antenna_cfg(ah, chan,
3659 cfg, &ant_config)) {
3660 REG_WRITE(ah, AR_PHY_SWITCH_COM, ant_config);
3661 return 0;
3662 }
3663 }
3664
3665 return -EINVAL;
3666}
3667
3668u32 ath9k_hw_getdefantenna(struct ath_hal *ah)
3669{
3670 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
3671}
3672
3673void ath9k_hw_setantenna(struct ath_hal *ah, u32 antenna)
3674{
3675 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
3676}
3677
3678bool ath9k_hw_setantennaswitch(struct ath_hal *ah,
3679 enum ath9k_ant_setting settings,
3680 struct ath9k_channel *chan,
3681 u8 *tx_chainmask,
3682 u8 *rx_chainmask,
3683 u8 *antenna_cfgd)
3684{
3685 struct ath_hal_5416 *ahp = AH5416(ah);
3686 static u8 tx_chainmask_cfg, rx_chainmask_cfg;
3687
3688 if (AR_SREV_9280(ah)) {
3689 if (!tx_chainmask_cfg) {
3690
3691 tx_chainmask_cfg = *tx_chainmask;
3692 rx_chainmask_cfg = *rx_chainmask;
3693 }
3694
3695 switch (settings) {
3696 case ATH9K_ANT_FIXED_A:
3697 *tx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3698 *rx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3699 *antenna_cfgd = true;
3700 break;
3701 case ATH9K_ANT_FIXED_B:
3702 if (ah->ah_caps.tx_chainmask >
3703 ATH9K_ANTENNA1_CHAINMASK) {
3704 *tx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3705 }
3706 *rx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3707 *antenna_cfgd = true;
3708 break;
3709 case ATH9K_ANT_VARIABLE:
3710 *tx_chainmask = tx_chainmask_cfg;
3711 *rx_chainmask = rx_chainmask_cfg;
3712 *antenna_cfgd = true;
3713 break;
3714 default:
3715 break;
3716 }
3717 } else {
3718 ahp->ah_diversityControl = settings;
3719 }
3720
3721 return true;
3722}
3723
3724/*********************/
3725/* General Operation */
3726/*********************/
3727
3728u32 ath9k_hw_getrxfilter(struct ath_hal *ah)
3729{
3730 u32 bits = REG_READ(ah, AR_RX_FILTER);
3731 u32 phybits = REG_READ(ah, AR_PHY_ERR);
3732
3733 if (phybits & AR_PHY_ERR_RADAR)
3734 bits |= ATH9K_RX_FILTER_PHYRADAR;
3735 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
3736 bits |= ATH9K_RX_FILTER_PHYERR;
3737
3738 return bits;
3739}
3740
3741void ath9k_hw_setrxfilter(struct ath_hal *ah, u32 bits)
3742{
3743 u32 phybits;
3744
3745 REG_WRITE(ah, AR_RX_FILTER, (bits & 0xffff) | AR_RX_COMPR_BAR);
3746 phybits = 0;
3747 if (bits & ATH9K_RX_FILTER_PHYRADAR)
3748 phybits |= AR_PHY_ERR_RADAR;
3749 if (bits & ATH9K_RX_FILTER_PHYERR)
3750 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
3751 REG_WRITE(ah, AR_PHY_ERR, phybits);
3752
3753 if (phybits)
3754 REG_WRITE(ah, AR_RXCFG,
3755 REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
3756 else
3757 REG_WRITE(ah, AR_RXCFG,
3758 REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
3759}
3760
3761bool ath9k_hw_phy_disable(struct ath_hal *ah)
3762{
3763 return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM);
3764}
3765
3766bool ath9k_hw_disable(struct ath_hal *ah)
3767{
3768 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
3769 return false;
3770
3771 return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD);
3772}
3773
3774bool ath9k_hw_set_txpowerlimit(struct ath_hal *ah, u32 limit)
3775{
3776 struct ath9k_channel *chan = ah->ah_curchan;
3777
3778 ah->ah_powerLimit = min(limit, (u32) MAX_RATE_POWER);
3779
3780 if (ath9k_hw_set_txpower(ah, chan,
3781 ath9k_regd_get_ctl(ah, chan),
3782 ath9k_regd_get_antenna_allowed(ah, chan),
3783 chan->maxRegTxPower * 2,
3784 min((u32) MAX_RATE_POWER,
3785 (u32) ah->ah_powerLimit)) != 0)
3786 return false;
3787
3788 return true;
3789}
3790
3791void ath9k_hw_getmac(struct ath_hal *ah, u8 *mac)
3792{
3793 struct ath_hal_5416 *ahp = AH5416(ah);
3794
3795 memcpy(mac, ahp->ah_macaddr, ETH_ALEN);
3796}
3797
3798bool ath9k_hw_setmac(struct ath_hal *ah, const u8 *mac)
3799{
3800 struct ath_hal_5416 *ahp = AH5416(ah);
3801
3802 memcpy(ahp->ah_macaddr, mac, ETH_ALEN);
3803
3804 return true;
3805}
3806
3807void ath9k_hw_setopmode(struct ath_hal *ah)
3808{
3809 ath9k_hw_set_operating_mode(ah, ah->ah_opmode);
3810}
3811
3812void ath9k_hw_setmcastfilter(struct ath_hal *ah, u32 filter0, u32 filter1)
3813{
3814 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
3815 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
3816}
3817
3818void ath9k_hw_getbssidmask(struct ath_hal *ah, u8 *mask)
3819{
3820 struct ath_hal_5416 *ahp = AH5416(ah);
3821
3822 memcpy(mask, ahp->ah_bssidmask, ETH_ALEN);
3823}
3824
3825bool ath9k_hw_setbssidmask(struct ath_hal *ah, const u8 *mask)
3826{
3827 struct ath_hal_5416 *ahp = AH5416(ah);
3828
3829 memcpy(ahp->ah_bssidmask, mask, ETH_ALEN);
3830
3831 REG_WRITE(ah, AR_BSSMSKL, get_unaligned_le32(ahp->ah_bssidmask));
3832 REG_WRITE(ah, AR_BSSMSKU, get_unaligned_le16(ahp->ah_bssidmask + 4));
3833
3834 return true;
3835}
3836
3837void ath9k_hw_write_associd(struct ath_hal *ah, const u8 *bssid, u16 assocId)
3838{
3839 struct ath_hal_5416 *ahp = AH5416(ah);
3840
3841 memcpy(ahp->ah_bssid, bssid, ETH_ALEN);
3842 ahp->ah_assocId = assocId;
3843
3844 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(ahp->ah_bssid));
3845 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(ahp->ah_bssid + 4) |
3846 ((assocId & 0x3fff) << AR_BSS_ID1_AID_S));
3847}
3848
3849u64 ath9k_hw_gettsf64(struct ath_hal *ah)
3850{
3851 u64 tsf;
3852
3853 tsf = REG_READ(ah, AR_TSF_U32);
3854 tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
3855
3856 return tsf;
3857}
3858
3859void ath9k_hw_reset_tsf(struct ath_hal *ah)
3860{
3861 int count;
3862
3863 count = 0;
3864 while (REG_READ(ah, AR_SLP32_MODE) & AR_SLP32_TSF_WRITE_STATUS) {
3865 count++;
3866 if (count > 10) {
3867 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05303868 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
Sujithf1dc5602008-10-29 10:16:30 +05303869 break;
3870 }
3871 udelay(10);
3872 }
3873 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003874}
3875
3876bool ath9k_hw_set_tsfadjust(struct ath_hal *ah, u32 setting)
3877{
3878 struct ath_hal_5416 *ahp = AH5416(ah);
3879
3880 if (setting)
3881 ahp->ah_miscMode |= AR_PCU_TX_ADD_TSF;
3882 else
3883 ahp->ah_miscMode &= ~AR_PCU_TX_ADD_TSF;
Sujithf1dc5602008-10-29 10:16:30 +05303884
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003885 return true;
3886}
3887
Sujithf1dc5602008-10-29 10:16:30 +05303888bool ath9k_hw_setslottime(struct ath_hal *ah, u32 us)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003889{
3890 struct ath_hal_5416 *ahp = AH5416(ah);
3891
Sujithf1dc5602008-10-29 10:16:30 +05303892 if (us < ATH9K_SLOT_TIME_9 || us > ath9k_hw_mac_to_usec(ah, 0xffff)) {
Sujith04bd4632008-11-28 22:18:05 +05303893 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "bad slot time %u\n", us);
Sujithf1dc5602008-10-29 10:16:30 +05303894 ahp->ah_slottime = (u32) -1;
3895 return false;
3896 } else {
3897 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, ath9k_hw_mac_to_clks(ah, us));
3898 ahp->ah_slottime = us;
3899 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003900 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003901}
3902
Sujithf1dc5602008-10-29 10:16:30 +05303903void ath9k_hw_set11nmac2040(struct ath_hal *ah, enum ath9k_ht_macmode mode)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003904{
Sujithf1dc5602008-10-29 10:16:30 +05303905 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003906
Sujithf1dc5602008-10-29 10:16:30 +05303907 if (mode == ATH9K_HT_MACMODE_2040 &&
3908 !ah->ah_config.cwm_ignore_extcca)
3909 macmode = AR_2040_JOINED_RX_CLEAR;
3910 else
3911 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003912
Sujithf1dc5602008-10-29 10:16:30 +05303913 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003914}