blob: 6eef10477896cdce5b52833dc87b5510ac2f0572 [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,
40 struct ar5416_eeprom *pEepData,
41 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 }
107 DPRINTF(ah->ah_sc, ATH_DBG_PHY_IO,
Sujithf1dc5602008-10-29 10:16:30 +0530108 "%s: timeout on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
109 __func__, reg, REG_READ(ah, reg), mask, val);
110
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700111 return false;
112}
113
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700114u32 ath9k_hw_reverse_bits(u32 val, u32 n)
115{
116 u32 retval;
117 int i;
118
119 for (i = 0, retval = 0; i < n; i++) {
120 retval = (retval << 1) | (val & 1);
121 val >>= 1;
122 }
123 return retval;
124}
125
Sujithf1dc5602008-10-29 10:16:30 +0530126bool ath9k_get_channel_edges(struct ath_hal *ah,
127 u16 flags, u16 *low,
128 u16 *high)
129{
130 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
131
132 if (flags & CHANNEL_5GHZ) {
133 *low = pCap->low_5ghz_chan;
134 *high = pCap->high_5ghz_chan;
135 return true;
136 }
137 if ((flags & CHANNEL_2GHZ)) {
138 *low = pCap->low_2ghz_chan;
139 *high = pCap->high_2ghz_chan;
140 return true;
141 }
142 return false;
143}
144
145u16 ath9k_hw_computetxtime(struct ath_hal *ah,
Sujithe63835b2008-11-18 09:07:53 +0530146 struct ath_rate_table *rates,
Sujithf1dc5602008-10-29 10:16:30 +0530147 u32 frameLen, u16 rateix,
148 bool shortPreamble)
149{
150 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
151 u32 kbps;
152
Sujithe63835b2008-11-18 09:07:53 +0530153 kbps = rates->info[rateix].ratekbps;
Sujithf1dc5602008-10-29 10:16:30 +0530154
155 if (kbps == 0)
156 return 0;
157
158 switch (rates->info[rateix].phy) {
Sujith46d14a52008-11-18 09:08:13 +0530159 case WLAN_RC_PHY_CCK:
Sujithf1dc5602008-10-29 10:16:30 +0530160 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
Sujithe63835b2008-11-18 09:07:53 +0530161 if (shortPreamble && rates->info[rateix].short_preamble)
Sujithf1dc5602008-10-29 10:16:30 +0530162 phyTime >>= 1;
163 numBits = frameLen << 3;
164 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
165 break;
Sujith46d14a52008-11-18 09:08:13 +0530166 case WLAN_RC_PHY_OFDM:
Sujithf1dc5602008-10-29 10:16:30 +0530167 if (ah->ah_curchan && IS_CHAN_QUARTER_RATE(ah->ah_curchan)) {
168 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
169 numBits = OFDM_PLCP_BITS + (frameLen << 3);
170 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
171 txTime = OFDM_SIFS_TIME_QUARTER
172 + OFDM_PREAMBLE_TIME_QUARTER
173 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
174 } else if (ah->ah_curchan &&
175 IS_CHAN_HALF_RATE(ah->ah_curchan)) {
176 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
177 numBits = OFDM_PLCP_BITS + (frameLen << 3);
178 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
179 txTime = OFDM_SIFS_TIME_HALF +
180 OFDM_PREAMBLE_TIME_HALF
181 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
182 } else {
183 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
184 numBits = OFDM_PLCP_BITS + (frameLen << 3);
185 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
186 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
187 + (numSymbols * OFDM_SYMBOL_TIME);
188 }
189 break;
190 default:
191 DPRINTF(ah->ah_sc, ATH_DBG_PHY_IO,
192 "%s: unknown phy %u (rate ix %u)\n", __func__,
193 rates->info[rateix].phy, rateix);
194 txTime = 0;
195 break;
196 }
197
198 return txTime;
199}
200
201u32 ath9k_hw_mhz2ieee(struct ath_hal *ah, u32 freq, u32 flags)
202{
203 if (flags & CHANNEL_2GHZ) {
204 if (freq == 2484)
205 return 14;
206 if (freq < 2484)
207 return (freq - 2407) / 5;
208 else
209 return 15 + ((freq - 2512) / 20);
210 } else if (flags & CHANNEL_5GHZ) {
211 if (ath9k_regd_is_public_safety_sku(ah) &&
212 IS_CHAN_IN_PUBLIC_SAFETY_BAND(freq)) {
213 return ((freq * 10) +
214 (((freq % 5) == 2) ? 5 : 0) - 49400) / 5;
215 } else if ((flags & CHANNEL_A) && (freq <= 5000)) {
216 return (freq - 4000) / 5;
217 } else {
218 return (freq - 5000) / 5;
219 }
220 } else {
221 if (freq == 2484)
222 return 14;
223 if (freq < 2484)
224 return (freq - 2407) / 5;
225 if (freq < 5000) {
226 if (ath9k_regd_is_public_safety_sku(ah)
227 && IS_CHAN_IN_PUBLIC_SAFETY_BAND(freq)) {
228 return ((freq * 10) +
229 (((freq % 5) ==
230 2) ? 5 : 0) - 49400) / 5;
231 } else if (freq > 4900) {
232 return (freq - 4000) / 5;
233 } else {
234 return 15 + ((freq - 2512) / 20);
235 }
236 }
237 return (freq - 5000) / 5;
238 }
239}
240
241void ath9k_hw_get_channel_centers(struct ath_hal *ah,
242 struct ath9k_channel *chan,
243 struct chan_centers *centers)
244{
245 int8_t extoff;
246 struct ath_hal_5416 *ahp = AH5416(ah);
247
248 if (!IS_CHAN_HT40(chan)) {
249 centers->ctl_center = centers->ext_center =
250 centers->synth_center = chan->channel;
251 return;
252 }
253
254 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
255 (chan->chanmode == CHANNEL_G_HT40PLUS)) {
256 centers->synth_center =
257 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
258 extoff = 1;
259 } else {
260 centers->synth_center =
261 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
262 extoff = -1;
263 }
264
265 centers->ctl_center =
266 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
267 centers->ext_center =
268 centers->synth_center + (extoff *
269 ((ahp->ah_extprotspacing == ATH9K_HT_EXTPROTSPACING_20) ?
270 HT40_CHANNEL_CENTER_SHIFT : 15));
271
272}
273
274/******************/
275/* Chip Revisions */
276/******************/
277
278static void ath9k_hw_read_revisions(struct ath_hal *ah)
279{
280 u32 val;
281
282 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
283
284 if (val == 0xFF) {
285 val = REG_READ(ah, AR_SREV);
286 ah->ah_macVersion = (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
287 ah->ah_macRev = MS(val, AR_SREV_REVISION2);
288 ah->ah_isPciExpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
289 } else {
290 if (!AR_SREV_9100(ah))
291 ah->ah_macVersion = MS(val, AR_SREV_VERSION);
292
293 ah->ah_macRev = val & AR_SREV_REVISION;
294
295 if (ah->ah_macVersion == AR_SREV_VERSION_5416_PCIE)
296 ah->ah_isPciExpress = true;
297 }
298}
299
300static int ath9k_hw_get_radiorev(struct ath_hal *ah)
301{
302 u32 val;
303 int i;
304
305 REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
306
307 for (i = 0; i < 8; i++)
308 REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
309 val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
310 val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
311
312 return ath9k_hw_reverse_bits(val, 8);
313}
314
315/************************************/
316/* HW Attach, Detach, Init Routines */
317/************************************/
318
319static void ath9k_hw_disablepcie(struct ath_hal *ah)
320{
321 if (!AR_SREV_9100(ah))
322 return;
323
324 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
325 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
326 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
327 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
328 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
329 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
330 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
331 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
332 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
333
334 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
335}
336
337static bool ath9k_hw_chip_test(struct ath_hal *ah)
338{
339 u32 regAddr[2] = { AR_STA_ID0, AR_PHY_BASE + (8 << 2) };
340 u32 regHold[2];
341 u32 patternData[4] = { 0x55555555,
342 0xaaaaaaaa,
343 0x66666666,
344 0x99999999 };
345 int i, j;
346
347 for (i = 0; i < 2; i++) {
348 u32 addr = regAddr[i];
349 u32 wrData, rdData;
350
351 regHold[i] = REG_READ(ah, addr);
352 for (j = 0; j < 0x100; j++) {
353 wrData = (j << 16) | j;
354 REG_WRITE(ah, addr, wrData);
355 rdData = REG_READ(ah, addr);
356 if (rdData != wrData) {
357 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
358 "%s: address test failed "
359 "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
360 __func__, addr, wrData, rdData);
361 return false;
362 }
363 }
364 for (j = 0; j < 4; j++) {
365 wrData = patternData[j];
366 REG_WRITE(ah, addr, wrData);
367 rdData = REG_READ(ah, addr);
368 if (wrData != rdData) {
369 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
370 "%s: address test failed "
371 "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
372 __func__, addr, wrData, rdData);
373 return false;
374 }
375 }
376 REG_WRITE(ah, regAddr[i], regHold[i]);
377 }
378 udelay(100);
379 return true;
380}
381
382static const char *ath9k_hw_devname(u16 devid)
383{
384 switch (devid) {
385 case AR5416_DEVID_PCI:
Sujithf1dc5602008-10-29 10:16:30 +0530386 return "Atheros 5416";
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +0100387 case AR5416_DEVID_PCIE:
388 return "Atheros 5418";
Sujithf1dc5602008-10-29 10:16:30 +0530389 case AR9160_DEVID_PCI:
390 return "Atheros 9160";
391 case AR9280_DEVID_PCI:
392 case AR9280_DEVID_PCIE:
393 return "Atheros 9280";
394 }
395
396 return NULL;
397}
398
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700399static void ath9k_hw_set_defaults(struct ath_hal *ah)
400{
401 int i;
402
Sujith60b67f52008-08-07 10:52:38 +0530403 ah->ah_config.dma_beacon_response_time = 2;
404 ah->ah_config.sw_beacon_response_time = 10;
405 ah->ah_config.additional_swba_backoff = 0;
406 ah->ah_config.ack_6mb = 0x0;
407 ah->ah_config.cwm_ignore_extcca = 0;
408 ah->ah_config.pcie_powersave_enable = 0;
409 ah->ah_config.pcie_l1skp_enable = 0;
410 ah->ah_config.pcie_clock_req = 0;
411 ah->ah_config.pcie_power_reset = 0x100;
412 ah->ah_config.pcie_restore = 0;
413 ah->ah_config.pcie_waen = 0;
414 ah->ah_config.analog_shiftreg = 1;
415 ah->ah_config.ht_enable = 1;
416 ah->ah_config.ofdm_trig_low = 200;
417 ah->ah_config.ofdm_trig_high = 500;
418 ah->ah_config.cck_trig_high = 200;
419 ah->ah_config.cck_trig_low = 100;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -0700420 ah->ah_config.enable_ani = 1;
Sujith60b67f52008-08-07 10:52:38 +0530421 ah->ah_config.noise_immunity_level = 4;
422 ah->ah_config.ofdm_weaksignal_det = 1;
423 ah->ah_config.cck_weaksignal_thr = 0;
424 ah->ah_config.spur_immunity_level = 2;
425 ah->ah_config.firstep_level = 0;
426 ah->ah_config.rssi_thr_high = 40;
427 ah->ah_config.rssi_thr_low = 7;
428 ah->ah_config.diversity_control = 0;
429 ah->ah_config.antenna_switch_swap = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700430
431 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujith60b67f52008-08-07 10:52:38 +0530432 ah->ah_config.spurchans[i][0] = AR_NO_SPUR;
433 ah->ah_config.spurchans[i][1] = AR_NO_SPUR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700434 }
435
Luis R. Rodriguezf97e4002008-10-22 13:28:44 -0700436 ah->ah_config.intr_mitigation = 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700437}
438
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700439static struct ath_hal_5416 *ath9k_hw_newstate(u16 devid,
440 struct ath_softc *sc,
441 void __iomem *mem,
442 int *status)
443{
444 static const u8 defbssidmask[ETH_ALEN] =
445 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
446 struct ath_hal_5416 *ahp;
447 struct ath_hal *ah;
448
449 ahp = kzalloc(sizeof(struct ath_hal_5416), GFP_KERNEL);
450 if (ahp == NULL) {
451 DPRINTF(sc, ATH_DBG_FATAL,
Sujithf1dc5602008-10-29 10:16:30 +0530452 "%s: cannot allocate memory for state block\n",
453 __func__);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700454 *status = -ENOMEM;
455 return NULL;
456 }
457
458 ah = &ahp->ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700459 ah->ah_sc = sc;
460 ah->ah_sh = mem;
Sujithd2d80ee2008-08-11 14:04:13 +0530461 ah->ah_magic = AR5416_MAGIC;
462 ah->ah_countryCode = CTRY_DEFAULT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700463 ah->ah_devid = devid;
464 ah->ah_subvendorid = 0;
465
466 ah->ah_flags = 0;
467 if ((devid == AR5416_AR9100_DEVID))
468 ah->ah_macVersion = AR_SREV_VERSION_9100;
469 if (!AR_SREV_9100(ah))
470 ah->ah_flags = AH_USE_EEPROM;
471
472 ah->ah_powerLimit = MAX_RATE_POWER;
473 ah->ah_tpScale = ATH9K_TP_SCALE_MAX;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700474 ahp->ah_atimWindow = 0;
Sujith60b67f52008-08-07 10:52:38 +0530475 ahp->ah_diversityControl = ah->ah_config.diversity_control;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700476 ahp->ah_antennaSwitchSwap =
Sujith60b67f52008-08-07 10:52:38 +0530477 ah->ah_config.antenna_switch_swap;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700478 ahp->ah_staId1Defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
479 ahp->ah_beaconInterval = 100;
480 ahp->ah_enable32kHzClock = DONT_USE_32KHZ;
481 ahp->ah_slottime = (u32) -1;
482 ahp->ah_acktimeout = (u32) -1;
483 ahp->ah_ctstimeout = (u32) -1;
484 ahp->ah_globaltxtimeout = (u32) -1;
485 memcpy(&ahp->ah_bssidmask, defbssidmask, ETH_ALEN);
486
487 ahp->ah_gBeaconRate = 0;
488
489 return ahp;
490}
491
Sujithff9b6622008-08-14 13:27:16 +0530492static int ath9k_hw_rfattach(struct ath_hal *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700493{
494 bool rfStatus = false;
495 int ecode = 0;
496
497 rfStatus = ath9k_hw_init_rf(ah, &ecode);
498 if (!rfStatus) {
499 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujithf1dc5602008-10-29 10:16:30 +0530500 "%s: RF setup failed, status %u\n", __func__,
501 ecode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700502 return ecode;
503 }
504
505 return 0;
506}
507
508static int ath9k_hw_rf_claim(struct ath_hal *ah)
509{
510 u32 val;
511
512 REG_WRITE(ah, AR_PHY(0), 0x00000007);
513
514 val = ath9k_hw_get_radiorev(ah);
515 switch (val & AR_RADIO_SREV_MAJOR) {
516 case 0:
517 val = AR_RAD5133_SREV_MAJOR;
518 break;
519 case AR_RAD5133_SREV_MAJOR:
520 case AR_RAD5122_SREV_MAJOR:
521 case AR_RAD2133_SREV_MAJOR:
522 case AR_RAD2122_SREV_MAJOR:
523 break;
524 default:
525 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
Sujithf1dc5602008-10-29 10:16:30 +0530526 "%s: 5G Radio Chip Rev 0x%02X is not "
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700527 "supported by this driver\n",
Sujithf1dc5602008-10-29 10:16:30 +0530528 __func__, ah->ah_analog5GhzRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700529 return -EOPNOTSUPP;
530 }
531
532 ah->ah_analog5GhzRev = val;
533
534 return 0;
535}
536
Sujithf1dc5602008-10-29 10:16:30 +0530537static int ath9k_hw_init_macaddr(struct ath_hal *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700538{
Sujithf1dc5602008-10-29 10:16:30 +0530539 u32 sum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700540 int i;
Sujithf1dc5602008-10-29 10:16:30 +0530541 u16 eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700542 struct ath_hal_5416 *ahp = AH5416(ah);
543
Sujithf1dc5602008-10-29 10:16:30 +0530544 sum = 0;
545 for (i = 0; i < 3; i++) {
546 eeval = ath9k_hw_get_eeprom(ah, AR_EEPROM_MAC(i));
547 sum += eeval;
548 ahp->ah_macaddr[2 * i] = eeval >> 8;
549 ahp->ah_macaddr[2 * i + 1] = eeval & 0xff;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700550 }
Sujithf1dc5602008-10-29 10:16:30 +0530551 if (sum == 0 || sum == 0xffff * 3) {
552 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
553 "%s: mac address read failed: %pM\n", __func__,
554 ahp->ah_macaddr);
555 return -EADDRNOTAVAIL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700556 }
557
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700558 return 0;
559}
560
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530561static void ath9k_hw_init_rxgain_ini(struct ath_hal *ah)
562{
563 u32 rxgain_type;
564 struct ath_hal_5416 *ahp = AH5416(ah);
565
566 if (ath9k_hw_get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_17) {
567 rxgain_type = ath9k_hw_get_eeprom(ah, EEP_RXGAIN_TYPE);
568
569 if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
570 INIT_INI_ARRAY(&ahp->ah_iniModesRxGain,
571 ar9280Modes_backoff_13db_rxgain_9280_2,
572 ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2), 6);
573 else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF)
574 INIT_INI_ARRAY(&ahp->ah_iniModesRxGain,
575 ar9280Modes_backoff_23db_rxgain_9280_2,
576 ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 6);
577 else
578 INIT_INI_ARRAY(&ahp->ah_iniModesRxGain,
579 ar9280Modes_original_rxgain_9280_2,
580 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
581 } else
582 INIT_INI_ARRAY(&ahp->ah_iniModesRxGain,
583 ar9280Modes_original_rxgain_9280_2,
584 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
585}
586
587static void ath9k_hw_init_txgain_ini(struct ath_hal *ah)
588{
589 u32 txgain_type;
590 struct ath_hal_5416 *ahp = AH5416(ah);
591
592 if (ath9k_hw_get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_19) {
593 txgain_type = ath9k_hw_get_eeprom(ah, EEP_TXGAIN_TYPE);
594
595 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
596 INIT_INI_ARRAY(&ahp->ah_iniModesTxGain,
597 ar9280Modes_high_power_tx_gain_9280_2,
598 ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 6);
599 else
600 INIT_INI_ARRAY(&ahp->ah_iniModesTxGain,
601 ar9280Modes_original_tx_gain_9280_2,
602 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
603 } else
604 INIT_INI_ARRAY(&ahp->ah_iniModesTxGain,
605 ar9280Modes_original_tx_gain_9280_2,
606 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
607}
608
Sujithff9b6622008-08-14 13:27:16 +0530609static int ath9k_hw_post_attach(struct ath_hal *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700610{
611 int ecode;
612
613 if (!ath9k_hw_chip_test(ah)) {
614 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
Sujithf1dc5602008-10-29 10:16:30 +0530615 "%s: hardware self-test failed\n", __func__);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700616 return -ENODEV;
617 }
618
619 ecode = ath9k_hw_rf_claim(ah);
620 if (ecode != 0)
621 return ecode;
622
623 ecode = ath9k_hw_eeprom_attach(ah);
624 if (ecode != 0)
625 return ecode;
626 ecode = ath9k_hw_rfattach(ah);
627 if (ecode != 0)
628 return ecode;
629
630 if (!AR_SREV_9100(ah)) {
631 ath9k_hw_ani_setup(ah);
632 ath9k_hw_ani_attach(ah);
633 }
Sujithf1dc5602008-10-29 10:16:30 +0530634
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700635 return 0;
636}
637
Sujithf1dc5602008-10-29 10:16:30 +0530638static struct ath_hal *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc,
639 void __iomem *mem, int *status)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700640{
641 struct ath_hal_5416 *ahp;
642 struct ath_hal *ah;
643 int ecode;
644#ifndef CONFIG_SLOW_ANT_DIV
645 u32 i;
646 u32 j;
647#endif
648
649 ahp = ath9k_hw_newstate(devid, sc, mem, status);
650 if (ahp == NULL)
651 return NULL;
652
653 ah = &ahp->ah;
654
655 ath9k_hw_set_defaults(ah);
656
Sujith60b67f52008-08-07 10:52:38 +0530657 if (ah->ah_config.intr_mitigation != 0)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700658 ahp->ah_intrMitigation = true;
659
660 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
661 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "%s: couldn't reset chip\n",
662 __func__);
663 ecode = -EIO;
664 goto bad;
665 }
666
667 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
668 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "%s: couldn't wakeup chip\n",
669 __func__);
670 ecode = -EIO;
671 goto bad;
672 }
673
Sujith60b67f52008-08-07 10:52:38 +0530674 if (ah->ah_config.serialize_regmode == SER_REG_MODE_AUTO) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700675 if (ah->ah_macVersion == AR_SREV_VERSION_5416_PCI) {
Sujith60b67f52008-08-07 10:52:38 +0530676 ah->ah_config.serialize_regmode =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700677 SER_REG_MODE_ON;
678 } else {
Sujith60b67f52008-08-07 10:52:38 +0530679 ah->ah_config.serialize_regmode =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700680 SER_REG_MODE_OFF;
681 }
682 }
Sujithf1dc5602008-10-29 10:16:30 +0530683
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700684 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujith60b67f52008-08-07 10:52:38 +0530685 "%s: serialize_regmode is %d\n",
686 __func__, ah->ah_config.serialize_regmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700687
688 if ((ah->ah_macVersion != AR_SREV_VERSION_5416_PCI) &&
689 (ah->ah_macVersion != AR_SREV_VERSION_5416_PCIE) &&
690 (ah->ah_macVersion != AR_SREV_VERSION_9160) &&
691 (!AR_SREV_9100(ah)) && (!AR_SREV_9280(ah))) {
692 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujithf1dc5602008-10-29 10:16:30 +0530693 "%s: Mac Chip Rev 0x%02x.%x is not supported by "
694 "this driver\n", __func__,
695 ah->ah_macVersion, ah->ah_macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700696 ecode = -EOPNOTSUPP;
697 goto bad;
698 }
699
700 if (AR_SREV_9100(ah)) {
701 ahp->ah_iqCalData.calData = &iq_cal_multi_sample;
702 ahp->ah_suppCals = IQ_MISMATCH_CAL;
703 ah->ah_isPciExpress = false;
704 }
705 ah->ah_phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
706
707 if (AR_SREV_9160_10_OR_LATER(ah)) {
708 if (AR_SREV_9280_10_OR_LATER(ah)) {
709 ahp->ah_iqCalData.calData = &iq_cal_single_sample;
710 ahp->ah_adcGainCalData.calData =
711 &adc_gain_cal_single_sample;
712 ahp->ah_adcDcCalData.calData =
713 &adc_dc_cal_single_sample;
714 ahp->ah_adcDcCalInitData.calData =
715 &adc_init_dc_cal;
716 } else {
717 ahp->ah_iqCalData.calData = &iq_cal_multi_sample;
718 ahp->ah_adcGainCalData.calData =
719 &adc_gain_cal_multi_sample;
720 ahp->ah_adcDcCalData.calData =
721 &adc_dc_cal_multi_sample;
722 ahp->ah_adcDcCalInitData.calData =
723 &adc_init_dc_cal;
724 }
Sujithf1dc5602008-10-29 10:16:30 +0530725 ahp->ah_suppCals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700726 }
727
728 if (AR_SREV_9160(ah)) {
Sujith60b67f52008-08-07 10:52:38 +0530729 ah->ah_config.enable_ani = 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700730 ahp->ah_ani_function = (ATH9K_ANI_SPUR_IMMUNITY_LEVEL |
731 ATH9K_ANI_FIRSTEP_LEVEL);
732 } else {
733 ahp->ah_ani_function = ATH9K_ANI_ALL;
734 if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +0530735 ahp->ah_ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700736 }
737 }
738
739 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujithf1dc5602008-10-29 10:16:30 +0530740 "%s: This Mac Chip Rev 0x%02x.%x is \n", __func__,
741 ah->ah_macVersion, ah->ah_macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700742
743 if (AR_SREV_9280_20_OR_LATER(ah)) {
744 INIT_INI_ARRAY(&ahp->ah_iniModes, ar9280Modes_9280_2,
745 ARRAY_SIZE(ar9280Modes_9280_2), 6);
746 INIT_INI_ARRAY(&ahp->ah_iniCommon, ar9280Common_9280_2,
747 ARRAY_SIZE(ar9280Common_9280_2), 2);
748
Sujith60b67f52008-08-07 10:52:38 +0530749 if (ah->ah_config.pcie_clock_req) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700750 INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530751 ar9280PciePhy_clkreq_off_L1_9280,
752 ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700753 } else {
754 INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530755 ar9280PciePhy_clkreq_always_on_L1_9280,
756 ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700757 }
758 INIT_INI_ARRAY(&ahp->ah_iniModesAdditional,
759 ar9280Modes_fast_clock_9280_2,
Sujithf1dc5602008-10-29 10:16:30 +0530760 ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700761 } else if (AR_SREV_9280_10_OR_LATER(ah)) {
762 INIT_INI_ARRAY(&ahp->ah_iniModes, ar9280Modes_9280,
763 ARRAY_SIZE(ar9280Modes_9280), 6);
764 INIT_INI_ARRAY(&ahp->ah_iniCommon, ar9280Common_9280,
765 ARRAY_SIZE(ar9280Common_9280), 2);
766 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
767 INIT_INI_ARRAY(&ahp->ah_iniModes, ar5416Modes_9160,
768 ARRAY_SIZE(ar5416Modes_9160), 6);
769 INIT_INI_ARRAY(&ahp->ah_iniCommon, ar5416Common_9160,
770 ARRAY_SIZE(ar5416Common_9160), 2);
771 INIT_INI_ARRAY(&ahp->ah_iniBank0, ar5416Bank0_9160,
772 ARRAY_SIZE(ar5416Bank0_9160), 2);
773 INIT_INI_ARRAY(&ahp->ah_iniBB_RfGain, ar5416BB_RfGain_9160,
774 ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
775 INIT_INI_ARRAY(&ahp->ah_iniBank1, ar5416Bank1_9160,
776 ARRAY_SIZE(ar5416Bank1_9160), 2);
777 INIT_INI_ARRAY(&ahp->ah_iniBank2, ar5416Bank2_9160,
778 ARRAY_SIZE(ar5416Bank2_9160), 2);
779 INIT_INI_ARRAY(&ahp->ah_iniBank3, ar5416Bank3_9160,
780 ARRAY_SIZE(ar5416Bank3_9160), 3);
781 INIT_INI_ARRAY(&ahp->ah_iniBank6, ar5416Bank6_9160,
782 ARRAY_SIZE(ar5416Bank6_9160), 3);
783 INIT_INI_ARRAY(&ahp->ah_iniBank6TPC, ar5416Bank6TPC_9160,
784 ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
785 INIT_INI_ARRAY(&ahp->ah_iniBank7, ar5416Bank7_9160,
786 ARRAY_SIZE(ar5416Bank7_9160), 2);
787 if (AR_SREV_9160_11(ah)) {
788 INIT_INI_ARRAY(&ahp->ah_iniAddac,
789 ar5416Addac_91601_1,
790 ARRAY_SIZE(ar5416Addac_91601_1), 2);
791 } else {
792 INIT_INI_ARRAY(&ahp->ah_iniAddac, ar5416Addac_9160,
793 ARRAY_SIZE(ar5416Addac_9160), 2);
794 }
795 } else if (AR_SREV_9100_OR_LATER(ah)) {
796 INIT_INI_ARRAY(&ahp->ah_iniModes, ar5416Modes_9100,
797 ARRAY_SIZE(ar5416Modes_9100), 6);
798 INIT_INI_ARRAY(&ahp->ah_iniCommon, ar5416Common_9100,
799 ARRAY_SIZE(ar5416Common_9100), 2);
800 INIT_INI_ARRAY(&ahp->ah_iniBank0, ar5416Bank0_9100,
801 ARRAY_SIZE(ar5416Bank0_9100), 2);
802 INIT_INI_ARRAY(&ahp->ah_iniBB_RfGain, ar5416BB_RfGain_9100,
803 ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
804 INIT_INI_ARRAY(&ahp->ah_iniBank1, ar5416Bank1_9100,
805 ARRAY_SIZE(ar5416Bank1_9100), 2);
806 INIT_INI_ARRAY(&ahp->ah_iniBank2, ar5416Bank2_9100,
807 ARRAY_SIZE(ar5416Bank2_9100), 2);
808 INIT_INI_ARRAY(&ahp->ah_iniBank3, ar5416Bank3_9100,
809 ARRAY_SIZE(ar5416Bank3_9100), 3);
810 INIT_INI_ARRAY(&ahp->ah_iniBank6, ar5416Bank6_9100,
811 ARRAY_SIZE(ar5416Bank6_9100), 3);
812 INIT_INI_ARRAY(&ahp->ah_iniBank6TPC, ar5416Bank6TPC_9100,
813 ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
814 INIT_INI_ARRAY(&ahp->ah_iniBank7, ar5416Bank7_9100,
815 ARRAY_SIZE(ar5416Bank7_9100), 2);
816 INIT_INI_ARRAY(&ahp->ah_iniAddac, ar5416Addac_9100,
817 ARRAY_SIZE(ar5416Addac_9100), 2);
818 } else {
819 INIT_INI_ARRAY(&ahp->ah_iniModes, ar5416Modes,
820 ARRAY_SIZE(ar5416Modes), 6);
821 INIT_INI_ARRAY(&ahp->ah_iniCommon, ar5416Common,
822 ARRAY_SIZE(ar5416Common), 2);
823 INIT_INI_ARRAY(&ahp->ah_iniBank0, ar5416Bank0,
824 ARRAY_SIZE(ar5416Bank0), 2);
825 INIT_INI_ARRAY(&ahp->ah_iniBB_RfGain, ar5416BB_RfGain,
826 ARRAY_SIZE(ar5416BB_RfGain), 3);
827 INIT_INI_ARRAY(&ahp->ah_iniBank1, ar5416Bank1,
828 ARRAY_SIZE(ar5416Bank1), 2);
829 INIT_INI_ARRAY(&ahp->ah_iniBank2, ar5416Bank2,
830 ARRAY_SIZE(ar5416Bank2), 2);
831 INIT_INI_ARRAY(&ahp->ah_iniBank3, ar5416Bank3,
832 ARRAY_SIZE(ar5416Bank3), 3);
833 INIT_INI_ARRAY(&ahp->ah_iniBank6, ar5416Bank6,
834 ARRAY_SIZE(ar5416Bank6), 3);
835 INIT_INI_ARRAY(&ahp->ah_iniBank6TPC, ar5416Bank6TPC,
836 ARRAY_SIZE(ar5416Bank6TPC), 3);
837 INIT_INI_ARRAY(&ahp->ah_iniBank7, ar5416Bank7,
838 ARRAY_SIZE(ar5416Bank7), 2);
839 INIT_INI_ARRAY(&ahp->ah_iniAddac, ar5416Addac,
840 ARRAY_SIZE(ar5416Addac), 2);
841 }
842
843 if (ah->ah_isPciExpress)
844 ath9k_hw_configpcipowersave(ah, 0);
845 else
Sujithf1dc5602008-10-29 10:16:30 +0530846 ath9k_hw_disablepcie(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700847
848 ecode = ath9k_hw_post_attach(ah);
849 if (ecode != 0)
850 goto bad;
851
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530852 /* rxgain table */
853 if (AR_SREV_9280_20_OR_LATER(ah))
854 ath9k_hw_init_rxgain_ini(ah);
855
856 /* txgain table */
857 if (AR_SREV_9280_20_OR_LATER(ah))
858 ath9k_hw_init_txgain_ini(ah);
859
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700860#ifndef CONFIG_SLOW_ANT_DIV
861 if (ah->ah_devid == AR9280_DEVID_PCI) {
862 for (i = 0; i < ahp->ah_iniModes.ia_rows; i++) {
863 u32 reg = INI_RA(&ahp->ah_iniModes, i, 0);
864
865 for (j = 1; j < ahp->ah_iniModes.ia_columns; j++) {
866 u32 val = INI_RA(&ahp->ah_iniModes, i, j);
867
868 INI_RA(&ahp->ah_iniModes, i, j) =
869 ath9k_hw_ini_fixup(ah, &ahp->ah_eeprom,
870 reg, val);
871 }
872 }
873 }
874#endif
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700875 if (!ath9k_hw_fill_cap_info(ah)) {
876 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujithf1dc5602008-10-29 10:16:30 +0530877 "%s:failed ath9k_hw_fill_cap_info\n", __func__);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700878 ecode = -EINVAL;
879 goto bad;
880 }
881
882 ecode = ath9k_hw_init_macaddr(ah);
883 if (ecode != 0) {
884 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujithf1dc5602008-10-29 10:16:30 +0530885 "%s: failed initializing mac address\n",
886 __func__);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700887 goto bad;
888 }
889
890 if (AR_SREV_9285(ah))
891 ah->ah_txTrigLevel = (AR_FTRIG_256B >> AR_FTRIG_S);
892 else
893 ah->ah_txTrigLevel = (AR_FTRIG_512B >> AR_FTRIG_S);
894
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700895 ath9k_init_nfcal_hist_buffer(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700896
897 return ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700898bad:
899 if (ahp)
900 ath9k_hw_detach((struct ath_hal *) ahp);
901 if (status)
902 *status = ecode;
Sujithf1dc5602008-10-29 10:16:30 +0530903
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700904 return NULL;
905}
906
Sujithf1dc5602008-10-29 10:16:30 +0530907static void ath9k_hw_init_bb(struct ath_hal *ah,
908 struct ath9k_channel *chan)
909{
910 u32 synthDelay;
911
912 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +0530913 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +0530914 synthDelay = (4 * synthDelay) / 22;
915 else
916 synthDelay /= 10;
917
918 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
919
920 udelay(synthDelay + BASE_ACTIVATE_DELAY);
921}
922
923static void ath9k_hw_init_qos(struct ath_hal *ah)
924{
925 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
926 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
927
928 REG_WRITE(ah, AR_QOS_NO_ACK,
929 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
930 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
931 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
932
933 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
934 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
935 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
936 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
937 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
938}
939
940static void ath9k_hw_init_pll(struct ath_hal *ah,
941 struct ath9k_channel *chan)
942{
943 u32 pll;
944
945 if (AR_SREV_9100(ah)) {
946 if (chan && IS_CHAN_5GHZ(chan))
947 pll = 0x1450;
948 else
949 pll = 0x1458;
950 } else {
951 if (AR_SREV_9280_10_OR_LATER(ah)) {
952 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
953
954 if (chan && IS_CHAN_HALF_RATE(chan))
955 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
956 else if (chan && IS_CHAN_QUARTER_RATE(chan))
957 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
958
959 if (chan && IS_CHAN_5GHZ(chan)) {
960 pll |= SM(0x28, AR_RTC_9160_PLL_DIV);
961
962
963 if (AR_SREV_9280_20(ah)) {
964 if (((chan->channel % 20) == 0)
965 || ((chan->channel % 10) == 0))
966 pll = 0x2850;
967 else
968 pll = 0x142c;
969 }
970 } else {
971 pll |= SM(0x2c, AR_RTC_9160_PLL_DIV);
972 }
973
974 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
975
976 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
977
978 if (chan && IS_CHAN_HALF_RATE(chan))
979 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
980 else if (chan && IS_CHAN_QUARTER_RATE(chan))
981 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
982
983 if (chan && IS_CHAN_5GHZ(chan))
984 pll |= SM(0x50, AR_RTC_9160_PLL_DIV);
985 else
986 pll |= SM(0x58, AR_RTC_9160_PLL_DIV);
987 } else {
988 pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2;
989
990 if (chan && IS_CHAN_HALF_RATE(chan))
991 pll |= SM(0x1, AR_RTC_PLL_CLKSEL);
992 else if (chan && IS_CHAN_QUARTER_RATE(chan))
993 pll |= SM(0x2, AR_RTC_PLL_CLKSEL);
994
995 if (chan && IS_CHAN_5GHZ(chan))
996 pll |= SM(0xa, AR_RTC_PLL_DIV);
997 else
998 pll |= SM(0xb, AR_RTC_PLL_DIV);
999 }
1000 }
1001 REG_WRITE(ah, (u16) (AR_RTC_PLL_CONTROL), pll);
1002
1003 udelay(RTC_PLL_SETTLE_DELAY);
1004
1005 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
1006}
1007
1008static void ath9k_hw_init_chain_masks(struct ath_hal *ah)
1009{
1010 struct ath_hal_5416 *ahp = AH5416(ah);
1011 int rx_chainmask, tx_chainmask;
1012
1013 rx_chainmask = ahp->ah_rxchainmask;
1014 tx_chainmask = ahp->ah_txchainmask;
1015
1016 switch (rx_chainmask) {
1017 case 0x5:
1018 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1019 AR_PHY_SWAP_ALT_CHAIN);
1020 case 0x3:
1021 if (((ah)->ah_macVersion <= AR_SREV_VERSION_9160)) {
1022 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7);
1023 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7);
1024 break;
1025 }
1026 case 0x1:
1027 case 0x2:
1028 if (!AR_SREV_9280(ah))
1029 break;
1030 case 0x7:
1031 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
1032 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
1033 break;
1034 default:
1035 break;
1036 }
1037
1038 REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);
1039 if (tx_chainmask == 0x5) {
1040 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1041 AR_PHY_SWAP_ALT_CHAIN);
1042 }
1043 if (AR_SREV_9100(ah))
1044 REG_WRITE(ah, AR_PHY_ANALOG_SWAP,
1045 REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
1046}
1047
1048static void ath9k_hw_init_interrupt_masks(struct ath_hal *ah, enum ath9k_opmode opmode)
1049{
1050 struct ath_hal_5416 *ahp = AH5416(ah);
1051
1052 ahp->ah_maskReg = AR_IMR_TXERR |
1053 AR_IMR_TXURN |
1054 AR_IMR_RXERR |
1055 AR_IMR_RXORN |
1056 AR_IMR_BCNMISC;
1057
1058 if (ahp->ah_intrMitigation)
1059 ahp->ah_maskReg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
1060 else
1061 ahp->ah_maskReg |= AR_IMR_RXOK;
1062
1063 ahp->ah_maskReg |= AR_IMR_TXOK;
1064
1065 if (opmode == ATH9K_M_HOSTAP)
1066 ahp->ah_maskReg |= AR_IMR_MIB;
1067
1068 REG_WRITE(ah, AR_IMR, ahp->ah_maskReg);
1069 REG_WRITE(ah, AR_IMR_S2, REG_READ(ah, AR_IMR_S2) | AR_IMR_S2_GTT);
1070
1071 if (!AR_SREV_9100(ah)) {
1072 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
1073 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
1074 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
1075 }
1076}
1077
1078static bool ath9k_hw_set_ack_timeout(struct ath_hal *ah, u32 us)
1079{
1080 struct ath_hal_5416 *ahp = AH5416(ah);
1081
1082 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) {
1083 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "%s: bad ack timeout %u\n",
1084 __func__, us);
1085 ahp->ah_acktimeout = (u32) -1;
1086 return false;
1087 } else {
1088 REG_RMW_FIELD(ah, AR_TIME_OUT,
1089 AR_TIME_OUT_ACK, ath9k_hw_mac_to_clks(ah, us));
1090 ahp->ah_acktimeout = us;
1091 return true;
1092 }
1093}
1094
1095static bool ath9k_hw_set_cts_timeout(struct ath_hal *ah, u32 us)
1096{
1097 struct ath_hal_5416 *ahp = AH5416(ah);
1098
1099 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_CTS))) {
1100 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "%s: bad cts timeout %u\n",
1101 __func__, us);
1102 ahp->ah_ctstimeout = (u32) -1;
1103 return false;
1104 } else {
1105 REG_RMW_FIELD(ah, AR_TIME_OUT,
1106 AR_TIME_OUT_CTS, ath9k_hw_mac_to_clks(ah, us));
1107 ahp->ah_ctstimeout = us;
1108 return true;
1109 }
1110}
1111
1112static bool ath9k_hw_set_global_txtimeout(struct ath_hal *ah, u32 tu)
1113{
1114 struct ath_hal_5416 *ahp = AH5416(ah);
1115
1116 if (tu > 0xFFFF) {
1117 DPRINTF(ah->ah_sc, ATH_DBG_XMIT,
1118 "%s: bad global tx timeout %u\n", __func__, tu);
1119 ahp->ah_globaltxtimeout = (u32) -1;
1120 return false;
1121 } else {
1122 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
1123 ahp->ah_globaltxtimeout = tu;
1124 return true;
1125 }
1126}
1127
1128static void ath9k_hw_init_user_settings(struct ath_hal *ah)
1129{
1130 struct ath_hal_5416 *ahp = AH5416(ah);
1131
1132 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "--AP %s ahp->ah_miscMode 0x%x\n",
1133 __func__, ahp->ah_miscMode);
1134
1135 if (ahp->ah_miscMode != 0)
1136 REG_WRITE(ah, AR_PCU_MISC,
1137 REG_READ(ah, AR_PCU_MISC) | ahp->ah_miscMode);
1138 if (ahp->ah_slottime != (u32) -1)
1139 ath9k_hw_setslottime(ah, ahp->ah_slottime);
1140 if (ahp->ah_acktimeout != (u32) -1)
1141 ath9k_hw_set_ack_timeout(ah, ahp->ah_acktimeout);
1142 if (ahp->ah_ctstimeout != (u32) -1)
1143 ath9k_hw_set_cts_timeout(ah, ahp->ah_ctstimeout);
1144 if (ahp->ah_globaltxtimeout != (u32) -1)
1145 ath9k_hw_set_global_txtimeout(ah, ahp->ah_globaltxtimeout);
1146}
1147
1148const char *ath9k_hw_probe(u16 vendorid, u16 devid)
1149{
1150 return vendorid == ATHEROS_VENDOR_ID ?
1151 ath9k_hw_devname(devid) : NULL;
1152}
1153
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001154void ath9k_hw_detach(struct ath_hal *ah)
1155{
1156 if (!AR_SREV_9100(ah))
1157 ath9k_hw_ani_detach(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001158
Sujithf1dc5602008-10-29 10:16:30 +05301159 ath9k_hw_rfdetach(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001160 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
1161 kfree(ah);
1162}
1163
Sujithf1dc5602008-10-29 10:16:30 +05301164struct ath_hal *ath9k_hw_attach(u16 devid, struct ath_softc *sc,
1165 void __iomem *mem, int *error)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001166{
Sujithf1dc5602008-10-29 10:16:30 +05301167 struct ath_hal *ah = NULL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001168
Sujithf1dc5602008-10-29 10:16:30 +05301169 switch (devid) {
1170 case AR5416_DEVID_PCI:
1171 case AR5416_DEVID_PCIE:
1172 case AR9160_DEVID_PCI:
1173 case AR9280_DEVID_PCI:
1174 case AR9280_DEVID_PCIE:
1175 ah = ath9k_hw_do_attach(devid, sc, mem, error);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001176 break;
Sujithf1dc5602008-10-29 10:16:30 +05301177 default:
1178 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
1179 "devid=0x%x not supported.\n", devid);
1180 ah = NULL;
1181 *error = -ENXIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001182 break;
1183 }
1184
Sujithf1dc5602008-10-29 10:16:30 +05301185 return ah;
1186}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001187
Sujithf1dc5602008-10-29 10:16:30 +05301188/*******/
1189/* INI */
1190/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001191
Sujithf1dc5602008-10-29 10:16:30 +05301192static void ath9k_hw_override_ini(struct ath_hal *ah,
1193 struct ath9k_channel *chan)
1194{
1195 if (!AR_SREV_5416_V20_OR_LATER(ah) ||
1196 AR_SREV_9280_10_OR_LATER(ah))
1197 return;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001198
Sujithf1dc5602008-10-29 10:16:30 +05301199 REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
1200}
1201
1202static u32 ath9k_hw_ini_fixup(struct ath_hal *ah,
1203 struct ar5416_eeprom *pEepData,
1204 u32 reg, u32 value)
1205{
1206 struct base_eep_header *pBase = &(pEepData->baseEepHeader);
1207
1208 switch (ah->ah_devid) {
1209 case AR9280_DEVID_PCI:
1210 if (reg == 0x7894) {
1211 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
1212 "ini VAL: %x EEPROM: %x\n", value,
1213 (pBase->version & 0xff));
1214
1215 if ((pBase->version & 0xff) > 0x0a) {
1216 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
1217 "PWDCLKIND: %d\n",
1218 pBase->pwdclkind);
1219 value &= ~AR_AN_TOP2_PWDCLKIND;
1220 value |= AR_AN_TOP2_PWDCLKIND &
1221 (pBase->pwdclkind << AR_AN_TOP2_PWDCLKIND_S);
1222 } else {
1223 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
1224 "PWDCLKIND Earlier Rev\n");
1225 }
1226
1227 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
1228 "final ini VAL: %x\n", value);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001229 }
Sujithf1dc5602008-10-29 10:16:30 +05301230 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001231 }
1232
Sujithf1dc5602008-10-29 10:16:30 +05301233 return value;
1234}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001235
Sujithf1dc5602008-10-29 10:16:30 +05301236static int ath9k_hw_process_ini(struct ath_hal *ah,
1237 struct ath9k_channel *chan,
1238 enum ath9k_ht_macmode macmode)
1239{
1240 int i, regWrites = 0;
1241 struct ath_hal_5416 *ahp = AH5416(ah);
1242 u32 modesIndex, freqIndex;
1243 int status;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001244
Sujithf1dc5602008-10-29 10:16:30 +05301245 switch (chan->chanmode) {
1246 case CHANNEL_A:
1247 case CHANNEL_A_HT20:
1248 modesIndex = 1;
1249 freqIndex = 1;
1250 break;
1251 case CHANNEL_A_HT40PLUS:
1252 case CHANNEL_A_HT40MINUS:
1253 modesIndex = 2;
1254 freqIndex = 1;
1255 break;
1256 case CHANNEL_G:
1257 case CHANNEL_G_HT20:
1258 case CHANNEL_B:
1259 modesIndex = 4;
1260 freqIndex = 2;
1261 break;
1262 case CHANNEL_G_HT40PLUS:
1263 case CHANNEL_G_HT40MINUS:
1264 modesIndex = 3;
1265 freqIndex = 2;
1266 break;
1267
1268 default:
1269 return -EINVAL;
1270 }
1271
1272 REG_WRITE(ah, AR_PHY(0), 0x00000007);
1273
1274 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
1275
1276 ath9k_hw_set_addac(ah, chan);
1277
1278 if (AR_SREV_5416_V22_OR_LATER(ah)) {
1279 REG_WRITE_ARRAY(&ahp->ah_iniAddac, 1, regWrites);
1280 } else {
1281 struct ar5416IniArray temp;
1282 u32 addacSize =
1283 sizeof(u32) * ahp->ah_iniAddac.ia_rows *
1284 ahp->ah_iniAddac.ia_columns;
1285
1286 memcpy(ahp->ah_addac5416_21,
1287 ahp->ah_iniAddac.ia_array, addacSize);
1288
1289 (ahp->ah_addac5416_21)[31 * ahp->ah_iniAddac.ia_columns + 1] = 0;
1290
1291 temp.ia_array = ahp->ah_addac5416_21;
1292 temp.ia_columns = ahp->ah_iniAddac.ia_columns;
1293 temp.ia_rows = ahp->ah_iniAddac.ia_rows;
1294 REG_WRITE_ARRAY(&temp, 1, regWrites);
1295 }
1296
1297 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
1298
1299 for (i = 0; i < ahp->ah_iniModes.ia_rows; i++) {
1300 u32 reg = INI_RA(&ahp->ah_iniModes, i, 0);
1301 u32 val = INI_RA(&ahp->ah_iniModes, i, modesIndex);
1302
1303#ifdef CONFIG_SLOW_ANT_DIV
1304 if (ah->ah_devid == AR9280_DEVID_PCI)
1305 val = ath9k_hw_ini_fixup(ah, &ahp->ah_eeprom, reg, val);
1306#endif
1307
1308 REG_WRITE(ah, reg, val);
1309
1310 if (reg >= 0x7800 && reg < 0x78a0
1311 && ah->ah_config.analog_shiftreg) {
1312 udelay(100);
1313 }
1314
1315 DO_DELAY(regWrites);
1316 }
1317
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301318 if (AR_SREV_9280_20_OR_LATER(ah))
1319 REG_WRITE_ARRAY(&ahp->ah_iniModesRxGain, modesIndex, regWrites);
1320
1321 if (AR_SREV_9280_20_OR_LATER(ah))
1322 REG_WRITE_ARRAY(&ahp->ah_iniModesTxGain, modesIndex, regWrites);
1323
Sujithf1dc5602008-10-29 10:16:30 +05301324 for (i = 0; i < ahp->ah_iniCommon.ia_rows; i++) {
1325 u32 reg = INI_RA(&ahp->ah_iniCommon, i, 0);
1326 u32 val = INI_RA(&ahp->ah_iniCommon, i, 1);
1327
1328 REG_WRITE(ah, reg, val);
1329
1330 if (reg >= 0x7800 && reg < 0x78a0
1331 && ah->ah_config.analog_shiftreg) {
1332 udelay(100);
1333 }
1334
1335 DO_DELAY(regWrites);
1336 }
1337
1338 ath9k_hw_write_regs(ah, modesIndex, freqIndex, regWrites);
1339
1340 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan)) {
1341 REG_WRITE_ARRAY(&ahp->ah_iniModesAdditional, modesIndex,
1342 regWrites);
1343 }
1344
1345 ath9k_hw_override_ini(ah, chan);
1346 ath9k_hw_set_regs(ah, chan, macmode);
1347 ath9k_hw_init_chain_masks(ah);
1348
1349 status = ath9k_hw_set_txpower(ah, chan,
1350 ath9k_regd_get_ctl(ah, chan),
1351 ath9k_regd_get_antenna_allowed(ah,
1352 chan),
1353 chan->maxRegTxPower * 2,
1354 min((u32) MAX_RATE_POWER,
1355 (u32) ah->ah_powerLimit));
1356 if (status != 0) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001357 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
Sujithf1dc5602008-10-29 10:16:30 +05301358 "%s: error init'ing transmit power\n", __func__);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001359 return -EIO;
1360 }
1361
Sujithf1dc5602008-10-29 10:16:30 +05301362 if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
1363 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
1364 "%s: ar5416SetRfRegs failed\n", __func__);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001365 return -EIO;
1366 }
1367
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001368 return 0;
1369}
1370
Sujithf1dc5602008-10-29 10:16:30 +05301371/****************************************/
1372/* Reset and Channel Switching Routines */
1373/****************************************/
1374
1375static void ath9k_hw_set_rfmode(struct ath_hal *ah, struct ath9k_channel *chan)
1376{
1377 u32 rfMode = 0;
1378
1379 if (chan == NULL)
1380 return;
1381
1382 rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
1383 ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
1384
1385 if (!AR_SREV_9280_10_OR_LATER(ah))
1386 rfMode |= (IS_CHAN_5GHZ(chan)) ?
1387 AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ;
1388
1389 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan))
1390 rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
1391
1392 REG_WRITE(ah, AR_PHY_MODE, rfMode);
1393}
1394
1395static void ath9k_hw_mark_phy_inactive(struct ath_hal *ah)
1396{
1397 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
1398}
1399
1400static inline void ath9k_hw_set_dma(struct ath_hal *ah)
1401{
1402 u32 regval;
1403
1404 regval = REG_READ(ah, AR_AHB_MODE);
1405 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
1406
1407 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
1408 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
1409
1410 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->ah_txTrigLevel);
1411
1412 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
1413 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
1414
1415 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1416
1417 if (AR_SREV_9285(ah)) {
1418 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1419 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
1420 } else {
1421 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1422 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1423 }
1424}
1425
1426static void ath9k_hw_set_operating_mode(struct ath_hal *ah, int opmode)
1427{
1428 u32 val;
1429
1430 val = REG_READ(ah, AR_STA_ID1);
1431 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
1432 switch (opmode) {
1433 case ATH9K_M_HOSTAP:
1434 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
1435 | AR_STA_ID1_KSRCH_MODE);
1436 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1437 break;
1438 case ATH9K_M_IBSS:
1439 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
1440 | AR_STA_ID1_KSRCH_MODE);
1441 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1442 break;
1443 case ATH9K_M_STA:
1444 case ATH9K_M_MONITOR:
1445 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
1446 break;
1447 }
1448}
1449
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001450static inline void ath9k_hw_get_delta_slope_vals(struct ath_hal *ah,
1451 u32 coef_scaled,
1452 u32 *coef_mantissa,
1453 u32 *coef_exponent)
1454{
1455 u32 coef_exp, coef_man;
1456
1457 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1458 if ((coef_scaled >> coef_exp) & 0x1)
1459 break;
1460
1461 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1462
1463 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1464
1465 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1466 *coef_exponent = coef_exp - 16;
1467}
1468
Sujithf1dc5602008-10-29 10:16:30 +05301469static void ath9k_hw_set_delta_slope(struct ath_hal *ah,
1470 struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001471{
1472 u32 coef_scaled, ds_coef_exp, ds_coef_man;
1473 u32 clockMhzScaled = 0x64000000;
1474 struct chan_centers centers;
1475
1476 if (IS_CHAN_HALF_RATE(chan))
1477 clockMhzScaled = clockMhzScaled >> 1;
1478 else if (IS_CHAN_QUARTER_RATE(chan))
1479 clockMhzScaled = clockMhzScaled >> 2;
1480
1481 ath9k_hw_get_channel_centers(ah, chan, &centers);
1482 coef_scaled = clockMhzScaled / centers.synth_center;
1483
1484 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1485 &ds_coef_exp);
1486
1487 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1488 AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
1489 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1490 AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
1491
1492 coef_scaled = (9 * coef_scaled) / 10;
1493
1494 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1495 &ds_coef_exp);
1496
1497 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1498 AR_PHY_HALFGI_DSC_MAN, ds_coef_man);
1499 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1500 AR_PHY_HALFGI_DSC_EXP, ds_coef_exp);
1501}
1502
Sujithf1dc5602008-10-29 10:16:30 +05301503static bool ath9k_hw_set_reset(struct ath_hal *ah, int type)
1504{
1505 u32 rst_flags;
1506 u32 tmpReg;
1507
1508 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1509 AR_RTC_FORCE_WAKE_ON_INT);
1510
1511 if (AR_SREV_9100(ah)) {
1512 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1513 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1514 } else {
1515 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1516 if (tmpReg &
1517 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1518 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
1519 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
1520 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1521 } else {
1522 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1523 }
1524
1525 rst_flags = AR_RTC_RC_MAC_WARM;
1526 if (type == ATH9K_RESET_COLD)
1527 rst_flags |= AR_RTC_RC_MAC_COLD;
1528 }
1529
1530 REG_WRITE(ah, (u16) (AR_RTC_RC), rst_flags);
1531 udelay(50);
1532
1533 REG_WRITE(ah, (u16) (AR_RTC_RC), 0);
1534 if (!ath9k_hw_wait(ah, (u16) (AR_RTC_RC), AR_RTC_RC_M, 0)) {
1535 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
1536 "%s: RTC stuck in MAC reset\n",
1537 __func__);
1538 return false;
1539 }
1540
1541 if (!AR_SREV_9100(ah))
1542 REG_WRITE(ah, AR_RC, 0);
1543
1544 ath9k_hw_init_pll(ah, NULL);
1545
1546 if (AR_SREV_9100(ah))
1547 udelay(50);
1548
1549 return true;
1550}
1551
1552static bool ath9k_hw_set_reset_power_on(struct ath_hal *ah)
1553{
1554 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1555 AR_RTC_FORCE_WAKE_ON_INT);
1556
1557 REG_WRITE(ah, (u16) (AR_RTC_RESET), 0);
1558 REG_WRITE(ah, (u16) (AR_RTC_RESET), 1);
1559
1560 if (!ath9k_hw_wait(ah,
1561 AR_RTC_STATUS,
1562 AR_RTC_STATUS_M,
1563 AR_RTC_STATUS_ON)) {
1564 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "%s: RTC not waking up\n",
1565 __func__);
1566 return false;
1567 }
1568
1569 ath9k_hw_read_revisions(ah);
1570
1571 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1572}
1573
1574static bool ath9k_hw_set_reset_reg(struct ath_hal *ah, u32 type)
1575{
1576 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1577 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1578
1579 switch (type) {
1580 case ATH9K_RESET_POWER_ON:
1581 return ath9k_hw_set_reset_power_on(ah);
1582 break;
1583 case ATH9K_RESET_WARM:
1584 case ATH9K_RESET_COLD:
1585 return ath9k_hw_set_reset(ah, type);
1586 break;
1587 default:
1588 return false;
1589 }
1590}
1591
1592static void ath9k_hw_set_regs(struct ath_hal *ah, struct ath9k_channel *chan,
1593 enum ath9k_ht_macmode macmode)
1594{
1595 u32 phymode;
1596 struct ath_hal_5416 *ahp = AH5416(ah);
1597
1598 phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
1599 | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH;
1600
1601 if (IS_CHAN_HT40(chan)) {
1602 phymode |= AR_PHY_FC_DYN2040_EN;
1603
1604 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
1605 (chan->chanmode == CHANNEL_G_HT40PLUS))
1606 phymode |= AR_PHY_FC_DYN2040_PRI_CH;
1607
1608 if (ahp->ah_extprotspacing == ATH9K_HT_EXTPROTSPACING_25)
1609 phymode |= AR_PHY_FC_DYN2040_EXT_CH;
1610 }
1611 REG_WRITE(ah, AR_PHY_TURBO, phymode);
1612
1613 ath9k_hw_set11nmac2040(ah, macmode);
1614
1615 REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
1616 REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
1617}
1618
1619static bool ath9k_hw_chip_reset(struct ath_hal *ah,
1620 struct ath9k_channel *chan)
1621{
1622 struct ath_hal_5416 *ahp = AH5416(ah);
1623
1624 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
1625 return false;
1626
1627 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
1628 return false;
1629
1630 ahp->ah_chipFullSleep = false;
1631
1632 ath9k_hw_init_pll(ah, chan);
1633
1634 ath9k_hw_set_rfmode(ah, chan);
1635
1636 return true;
1637}
1638
1639static struct ath9k_channel *ath9k_hw_check_chan(struct ath_hal *ah,
1640 struct ath9k_channel *chan)
1641{
1642 if (!(IS_CHAN_2GHZ(chan) ^ IS_CHAN_5GHZ(chan))) {
1643 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
1644 "%s: invalid channel %u/0x%x; not marked as "
1645 "2GHz or 5GHz\n", __func__, chan->channel,
1646 chan->channelFlags);
1647 return NULL;
1648 }
1649
1650 if (!IS_CHAN_OFDM(chan) &&
Sujith788a3d62008-11-18 09:09:54 +05301651 !IS_CHAN_B(chan) &&
Sujithf1dc5602008-10-29 10:16:30 +05301652 !IS_CHAN_HT20(chan) &&
1653 !IS_CHAN_HT40(chan)) {
1654 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
1655 "%s: invalid channel %u/0x%x; not marked as "
1656 "OFDM or CCK or HT20 or HT40PLUS or HT40MINUS\n",
1657 __func__, chan->channel, chan->channelFlags);
1658 return NULL;
1659 }
1660
1661 return ath9k_regd_check_channel(ah, chan);
1662}
1663
1664static bool ath9k_hw_channel_change(struct ath_hal *ah,
1665 struct ath9k_channel *chan,
1666 enum ath9k_ht_macmode macmode)
1667{
1668 u32 synthDelay, qnum;
1669
1670 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1671 if (ath9k_hw_numtxpending(ah, qnum)) {
1672 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
1673 "%s: Transmit frames pending on queue %d\n",
1674 __func__, qnum);
1675 return false;
1676 }
1677 }
1678
1679 REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
1680 if (!ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
1681 AR_PHY_RFBUS_GRANT_EN)) {
1682 DPRINTF(ah->ah_sc, ATH_DBG_PHY_IO,
1683 "%s: Could not kill baseband RX\n", __func__);
1684 return false;
1685 }
1686
1687 ath9k_hw_set_regs(ah, chan, macmode);
1688
1689 if (AR_SREV_9280_10_OR_LATER(ah)) {
1690 if (!(ath9k_hw_ar9280_set_channel(ah, chan))) {
1691 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
1692 "%s: failed to set channel\n", __func__);
1693 return false;
1694 }
1695 } else {
1696 if (!(ath9k_hw_set_channel(ah, chan))) {
1697 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
1698 "%s: failed to set channel\n", __func__);
1699 return false;
1700 }
1701 }
1702
1703 if (ath9k_hw_set_txpower(ah, chan,
1704 ath9k_regd_get_ctl(ah, chan),
1705 ath9k_regd_get_antenna_allowed(ah, chan),
1706 chan->maxRegTxPower * 2,
1707 min((u32) MAX_RATE_POWER,
1708 (u32) ah->ah_powerLimit)) != 0) {
1709 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
1710 "%s: error init'ing transmit power\n", __func__);
1711 return false;
1712 }
1713
1714 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +05301715 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +05301716 synthDelay = (4 * synthDelay) / 22;
1717 else
1718 synthDelay /= 10;
1719
1720 udelay(synthDelay + BASE_ACTIVATE_DELAY);
1721
1722 REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
1723
1724 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1725 ath9k_hw_set_delta_slope(ah, chan);
1726
1727 if (AR_SREV_9280_10_OR_LATER(ah))
1728 ath9k_hw_9280_spur_mitigate(ah, chan);
1729 else
1730 ath9k_hw_spur_mitigate(ah, chan);
1731
1732 if (!chan->oneTimeCalsDone)
1733 chan->oneTimeCalsDone = true;
1734
1735 return true;
1736}
1737
1738static void ath9k_hw_9280_spur_mitigate(struct ath_hal *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001739{
1740 int bb_spur = AR_NO_SPUR;
1741 int freq;
1742 int bin, cur_bin;
1743 int bb_spur_off, spur_subchannel_sd;
1744 int spur_freq_sd;
1745 int spur_delta_phase;
1746 int denominator;
1747 int upper, lower, cur_vit_mask;
1748 int tmp, newVal;
1749 int i;
1750 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
1751 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
1752 };
1753 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
1754 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
1755 };
1756 int inc[4] = { 0, 100, 0, 0 };
1757 struct chan_centers centers;
1758
1759 int8_t mask_m[123];
1760 int8_t mask_p[123];
1761 int8_t mask_amt;
1762 int tmp_mask;
1763 int cur_bb_spur;
1764 bool is2GHz = IS_CHAN_2GHZ(chan);
1765
1766 memset(&mask_m, 0, sizeof(int8_t) * 123);
1767 memset(&mask_p, 0, sizeof(int8_t) * 123);
1768
1769 ath9k_hw_get_channel_centers(ah, chan, &centers);
1770 freq = centers.synth_center;
1771
Sujith60b67f52008-08-07 10:52:38 +05301772 ah->ah_config.spurmode = SPUR_ENABLE_EEPROM;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001773 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
1774 cur_bb_spur = ath9k_hw_eeprom_get_spur_chan(ah, i, is2GHz);
1775
1776 if (is2GHz)
1777 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_2GHZ;
1778 else
1779 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_5GHZ;
1780
1781 if (AR_NO_SPUR == cur_bb_spur)
1782 break;
1783 cur_bb_spur = cur_bb_spur - freq;
1784
1785 if (IS_CHAN_HT40(chan)) {
1786 if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT40) &&
1787 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT40)) {
1788 bb_spur = cur_bb_spur;
1789 break;
1790 }
1791 } else if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT20) &&
1792 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT20)) {
1793 bb_spur = cur_bb_spur;
1794 break;
1795 }
1796 }
1797
1798 if (AR_NO_SPUR == bb_spur) {
1799 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1800 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1801 return;
1802 } else {
1803 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1804 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1805 }
1806
1807 bin = bb_spur * 320;
1808
1809 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
1810
1811 newVal = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
1812 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
1813 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
1814 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
1815 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), newVal);
1816
1817 newVal = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
1818 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
1819 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
1820 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
1821 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
1822 REG_WRITE(ah, AR_PHY_SPUR_REG, newVal);
1823
1824 if (IS_CHAN_HT40(chan)) {
1825 if (bb_spur < 0) {
1826 spur_subchannel_sd = 1;
1827 bb_spur_off = bb_spur + 10;
1828 } else {
1829 spur_subchannel_sd = 0;
1830 bb_spur_off = bb_spur - 10;
1831 }
1832 } else {
1833 spur_subchannel_sd = 0;
1834 bb_spur_off = bb_spur;
1835 }
1836
1837 if (IS_CHAN_HT40(chan))
1838 spur_delta_phase =
1839 ((bb_spur * 262144) /
1840 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
1841 else
1842 spur_delta_phase =
1843 ((bb_spur * 524288) /
1844 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
1845
1846 denominator = IS_CHAN_2GHZ(chan) ? 44 : 40;
1847 spur_freq_sd = ((bb_spur_off * 2048) / denominator) & 0x3ff;
1848
1849 newVal = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
1850 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
1851 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
1852 REG_WRITE(ah, AR_PHY_TIMING11, newVal);
1853
1854 newVal = spur_subchannel_sd << AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S;
1855 REG_WRITE(ah, AR_PHY_SFCORR_EXT, newVal);
1856
1857 cur_bin = -6000;
1858 upper = bin + 100;
1859 lower = bin - 100;
1860
1861 for (i = 0; i < 4; i++) {
1862 int pilot_mask = 0;
1863 int chan_mask = 0;
1864 int bp = 0;
1865 for (bp = 0; bp < 30; bp++) {
1866 if ((cur_bin > lower) && (cur_bin < upper)) {
1867 pilot_mask = pilot_mask | 0x1 << bp;
1868 chan_mask = chan_mask | 0x1 << bp;
1869 }
1870 cur_bin += 100;
1871 }
1872 cur_bin += inc[i];
1873 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
1874 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
1875 }
1876
1877 cur_vit_mask = 6100;
1878 upper = bin + 120;
1879 lower = bin - 120;
1880
1881 for (i = 0; i < 123; i++) {
1882 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
Adrian Bunkb08cbcd2008-08-05 22:06:51 +03001883
1884 /* workaround for gcc bug #37014 */
1885 volatile int tmp = abs(cur_vit_mask - bin);
1886
1887 if (tmp < 75)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001888 mask_amt = 1;
1889 else
1890 mask_amt = 0;
1891 if (cur_vit_mask < 0)
1892 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
1893 else
1894 mask_p[cur_vit_mask / 100] = mask_amt;
1895 }
1896 cur_vit_mask -= 100;
1897 }
1898
1899 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
1900 | (mask_m[48] << 26) | (mask_m[49] << 24)
1901 | (mask_m[50] << 22) | (mask_m[51] << 20)
1902 | (mask_m[52] << 18) | (mask_m[53] << 16)
1903 | (mask_m[54] << 14) | (mask_m[55] << 12)
1904 | (mask_m[56] << 10) | (mask_m[57] << 8)
1905 | (mask_m[58] << 6) | (mask_m[59] << 4)
1906 | (mask_m[60] << 2) | (mask_m[61] << 0);
1907 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
1908 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
1909
1910 tmp_mask = (mask_m[31] << 28)
1911 | (mask_m[32] << 26) | (mask_m[33] << 24)
1912 | (mask_m[34] << 22) | (mask_m[35] << 20)
1913 | (mask_m[36] << 18) | (mask_m[37] << 16)
1914 | (mask_m[48] << 14) | (mask_m[39] << 12)
1915 | (mask_m[40] << 10) | (mask_m[41] << 8)
1916 | (mask_m[42] << 6) | (mask_m[43] << 4)
1917 | (mask_m[44] << 2) | (mask_m[45] << 0);
1918 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
1919 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
1920
1921 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
1922 | (mask_m[18] << 26) | (mask_m[18] << 24)
1923 | (mask_m[20] << 22) | (mask_m[20] << 20)
1924 | (mask_m[22] << 18) | (mask_m[22] << 16)
1925 | (mask_m[24] << 14) | (mask_m[24] << 12)
1926 | (mask_m[25] << 10) | (mask_m[26] << 8)
1927 | (mask_m[27] << 6) | (mask_m[28] << 4)
1928 | (mask_m[29] << 2) | (mask_m[30] << 0);
1929 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
1930 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
1931
1932 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
1933 | (mask_m[2] << 26) | (mask_m[3] << 24)
1934 | (mask_m[4] << 22) | (mask_m[5] << 20)
1935 | (mask_m[6] << 18) | (mask_m[7] << 16)
1936 | (mask_m[8] << 14) | (mask_m[9] << 12)
1937 | (mask_m[10] << 10) | (mask_m[11] << 8)
1938 | (mask_m[12] << 6) | (mask_m[13] << 4)
1939 | (mask_m[14] << 2) | (mask_m[15] << 0);
1940 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
1941 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
1942
1943 tmp_mask = (mask_p[15] << 28)
1944 | (mask_p[14] << 26) | (mask_p[13] << 24)
1945 | (mask_p[12] << 22) | (mask_p[11] << 20)
1946 | (mask_p[10] << 18) | (mask_p[9] << 16)
1947 | (mask_p[8] << 14) | (mask_p[7] << 12)
1948 | (mask_p[6] << 10) | (mask_p[5] << 8)
1949 | (mask_p[4] << 6) | (mask_p[3] << 4)
1950 | (mask_p[2] << 2) | (mask_p[1] << 0);
1951 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
1952 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
1953
1954 tmp_mask = (mask_p[30] << 28)
1955 | (mask_p[29] << 26) | (mask_p[28] << 24)
1956 | (mask_p[27] << 22) | (mask_p[26] << 20)
1957 | (mask_p[25] << 18) | (mask_p[24] << 16)
1958 | (mask_p[23] << 14) | (mask_p[22] << 12)
1959 | (mask_p[21] << 10) | (mask_p[20] << 8)
1960 | (mask_p[19] << 6) | (mask_p[18] << 4)
1961 | (mask_p[17] << 2) | (mask_p[16] << 0);
1962 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
1963 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
1964
1965 tmp_mask = (mask_p[45] << 28)
1966 | (mask_p[44] << 26) | (mask_p[43] << 24)
1967 | (mask_p[42] << 22) | (mask_p[41] << 20)
1968 | (mask_p[40] << 18) | (mask_p[39] << 16)
1969 | (mask_p[38] << 14) | (mask_p[37] << 12)
1970 | (mask_p[36] << 10) | (mask_p[35] << 8)
1971 | (mask_p[34] << 6) | (mask_p[33] << 4)
1972 | (mask_p[32] << 2) | (mask_p[31] << 0);
1973 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
1974 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
1975
1976 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
1977 | (mask_p[59] << 26) | (mask_p[58] << 24)
1978 | (mask_p[57] << 22) | (mask_p[56] << 20)
1979 | (mask_p[55] << 18) | (mask_p[54] << 16)
1980 | (mask_p[53] << 14) | (mask_p[52] << 12)
1981 | (mask_p[51] << 10) | (mask_p[50] << 8)
1982 | (mask_p[49] << 6) | (mask_p[48] << 4)
1983 | (mask_p[47] << 2) | (mask_p[46] << 0);
1984 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
1985 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
1986}
1987
Sujithf1dc5602008-10-29 10:16:30 +05301988static void ath9k_hw_spur_mitigate(struct ath_hal *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001989{
1990 int bb_spur = AR_NO_SPUR;
1991 int bin, cur_bin;
1992 int spur_freq_sd;
1993 int spur_delta_phase;
1994 int denominator;
1995 int upper, lower, cur_vit_mask;
1996 int tmp, new;
1997 int i;
1998 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
1999 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
2000 };
2001 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
2002 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
2003 };
2004 int inc[4] = { 0, 100, 0, 0 };
2005
2006 int8_t mask_m[123];
2007 int8_t mask_p[123];
2008 int8_t mask_amt;
2009 int tmp_mask;
2010 int cur_bb_spur;
2011 bool is2GHz = IS_CHAN_2GHZ(chan);
2012
2013 memset(&mask_m, 0, sizeof(int8_t) * 123);
2014 memset(&mask_p, 0, sizeof(int8_t) * 123);
2015
2016 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
2017 cur_bb_spur = ath9k_hw_eeprom_get_spur_chan(ah, i, is2GHz);
2018 if (AR_NO_SPUR == cur_bb_spur)
2019 break;
2020 cur_bb_spur = cur_bb_spur - (chan->channel * 10);
2021 if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) {
2022 bb_spur = cur_bb_spur;
2023 break;
2024 }
2025 }
2026
2027 if (AR_NO_SPUR == bb_spur)
2028 return;
2029
2030 bin = bb_spur * 32;
2031
2032 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
2033 new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
2034 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
2035 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
2036 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
2037
2038 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new);
2039
2040 new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
2041 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
2042 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
2043 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
2044 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
2045 REG_WRITE(ah, AR_PHY_SPUR_REG, new);
2046
2047 spur_delta_phase = ((bb_spur * 524288) / 100) &
2048 AR_PHY_TIMING11_SPUR_DELTA_PHASE;
2049
2050 denominator = IS_CHAN_2GHZ(chan) ? 440 : 400;
2051 spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff;
2052
2053 new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
2054 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
2055 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
2056 REG_WRITE(ah, AR_PHY_TIMING11, new);
2057
2058 cur_bin = -6000;
2059 upper = bin + 100;
2060 lower = bin - 100;
2061
2062 for (i = 0; i < 4; i++) {
2063 int pilot_mask = 0;
2064 int chan_mask = 0;
2065 int bp = 0;
2066 for (bp = 0; bp < 30; bp++) {
2067 if ((cur_bin > lower) && (cur_bin < upper)) {
2068 pilot_mask = pilot_mask | 0x1 << bp;
2069 chan_mask = chan_mask | 0x1 << bp;
2070 }
2071 cur_bin += 100;
2072 }
2073 cur_bin += inc[i];
2074 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
2075 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
2076 }
2077
2078 cur_vit_mask = 6100;
2079 upper = bin + 120;
2080 lower = bin - 120;
2081
2082 for (i = 0; i < 123; i++) {
2083 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
Adrian Bunk88b9e2b2008-08-05 22:06:51 +03002084
2085 /* workaround for gcc bug #37014 */
2086 volatile int tmp = abs(cur_vit_mask - bin);
2087
2088 if (tmp < 75)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002089 mask_amt = 1;
2090 else
2091 mask_amt = 0;
2092 if (cur_vit_mask < 0)
2093 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
2094 else
2095 mask_p[cur_vit_mask / 100] = mask_amt;
2096 }
2097 cur_vit_mask -= 100;
2098 }
2099
2100 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
2101 | (mask_m[48] << 26) | (mask_m[49] << 24)
2102 | (mask_m[50] << 22) | (mask_m[51] << 20)
2103 | (mask_m[52] << 18) | (mask_m[53] << 16)
2104 | (mask_m[54] << 14) | (mask_m[55] << 12)
2105 | (mask_m[56] << 10) | (mask_m[57] << 8)
2106 | (mask_m[58] << 6) | (mask_m[59] << 4)
2107 | (mask_m[60] << 2) | (mask_m[61] << 0);
2108 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
2109 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
2110
2111 tmp_mask = (mask_m[31] << 28)
2112 | (mask_m[32] << 26) | (mask_m[33] << 24)
2113 | (mask_m[34] << 22) | (mask_m[35] << 20)
2114 | (mask_m[36] << 18) | (mask_m[37] << 16)
2115 | (mask_m[48] << 14) | (mask_m[39] << 12)
2116 | (mask_m[40] << 10) | (mask_m[41] << 8)
2117 | (mask_m[42] << 6) | (mask_m[43] << 4)
2118 | (mask_m[44] << 2) | (mask_m[45] << 0);
2119 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
2120 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
2121
2122 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
2123 | (mask_m[18] << 26) | (mask_m[18] << 24)
2124 | (mask_m[20] << 22) | (mask_m[20] << 20)
2125 | (mask_m[22] << 18) | (mask_m[22] << 16)
2126 | (mask_m[24] << 14) | (mask_m[24] << 12)
2127 | (mask_m[25] << 10) | (mask_m[26] << 8)
2128 | (mask_m[27] << 6) | (mask_m[28] << 4)
2129 | (mask_m[29] << 2) | (mask_m[30] << 0);
2130 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
2131 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
2132
2133 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
2134 | (mask_m[2] << 26) | (mask_m[3] << 24)
2135 | (mask_m[4] << 22) | (mask_m[5] << 20)
2136 | (mask_m[6] << 18) | (mask_m[7] << 16)
2137 | (mask_m[8] << 14) | (mask_m[9] << 12)
2138 | (mask_m[10] << 10) | (mask_m[11] << 8)
2139 | (mask_m[12] << 6) | (mask_m[13] << 4)
2140 | (mask_m[14] << 2) | (mask_m[15] << 0);
2141 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
2142 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
2143
2144 tmp_mask = (mask_p[15] << 28)
2145 | (mask_p[14] << 26) | (mask_p[13] << 24)
2146 | (mask_p[12] << 22) | (mask_p[11] << 20)
2147 | (mask_p[10] << 18) | (mask_p[9] << 16)
2148 | (mask_p[8] << 14) | (mask_p[7] << 12)
2149 | (mask_p[6] << 10) | (mask_p[5] << 8)
2150 | (mask_p[4] << 6) | (mask_p[3] << 4)
2151 | (mask_p[2] << 2) | (mask_p[1] << 0);
2152 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
2153 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
2154
2155 tmp_mask = (mask_p[30] << 28)
2156 | (mask_p[29] << 26) | (mask_p[28] << 24)
2157 | (mask_p[27] << 22) | (mask_p[26] << 20)
2158 | (mask_p[25] << 18) | (mask_p[24] << 16)
2159 | (mask_p[23] << 14) | (mask_p[22] << 12)
2160 | (mask_p[21] << 10) | (mask_p[20] << 8)
2161 | (mask_p[19] << 6) | (mask_p[18] << 4)
2162 | (mask_p[17] << 2) | (mask_p[16] << 0);
2163 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
2164 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
2165
2166 tmp_mask = (mask_p[45] << 28)
2167 | (mask_p[44] << 26) | (mask_p[43] << 24)
2168 | (mask_p[42] << 22) | (mask_p[41] << 20)
2169 | (mask_p[40] << 18) | (mask_p[39] << 16)
2170 | (mask_p[38] << 14) | (mask_p[37] << 12)
2171 | (mask_p[36] << 10) | (mask_p[35] << 8)
2172 | (mask_p[34] << 6) | (mask_p[33] << 4)
2173 | (mask_p[32] << 2) | (mask_p[31] << 0);
2174 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
2175 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
2176
2177 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
2178 | (mask_p[59] << 26) | (mask_p[58] << 24)
2179 | (mask_p[57] << 22) | (mask_p[56] << 20)
2180 | (mask_p[55] << 18) | (mask_p[54] << 16)
2181 | (mask_p[53] << 14) | (mask_p[52] << 12)
2182 | (mask_p[51] << 10) | (mask_p[50] << 8)
2183 | (mask_p[49] << 6) | (mask_p[48] << 4)
2184 | (mask_p[47] << 2) | (mask_p[46] << 0);
2185 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
2186 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
2187}
2188
Sujithf1dc5602008-10-29 10:16:30 +05302189bool ath9k_hw_reset(struct ath_hal *ah, struct ath9k_channel *chan,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002190 enum ath9k_ht_macmode macmode,
2191 u8 txchainmask, u8 rxchainmask,
2192 enum ath9k_ht_extprotspacing extprotspacing,
Sujithf1dc5602008-10-29 10:16:30 +05302193 bool bChannelChange, int *status)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002194{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002195 u32 saveLedState;
2196 struct ath_hal_5416 *ahp = AH5416(ah);
2197 struct ath9k_channel *curchan = ah->ah_curchan;
2198 u32 saveDefAntenna;
2199 u32 macStaId1;
2200 int ecode;
2201 int i, rx_chainmask;
2202
2203 ahp->ah_extprotspacing = extprotspacing;
2204 ahp->ah_txchainmask = txchainmask;
2205 ahp->ah_rxchainmask = rxchainmask;
2206
2207 if (AR_SREV_9280(ah)) {
2208 ahp->ah_txchainmask &= 0x3;
2209 ahp->ah_rxchainmask &= 0x3;
2210 }
2211
2212 if (ath9k_hw_check_chan(ah, chan) == NULL) {
2213 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
Sujithf1dc5602008-10-29 10:16:30 +05302214 "%s: invalid channel %u/0x%x; no mapping\n",
2215 __func__, chan->channel, chan->channelFlags);
Luis R. Rodriguez1cf69cf2008-10-10 12:25:45 -07002216 ecode = -EINVAL;
2217 goto bad;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002218 }
2219
Luis R. Rodriguezd2a3b222008-10-10 12:26:24 -07002220 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
2221 ecode = -EIO;
2222 goto bad;
2223 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002224
2225 if (curchan)
2226 ath9k_hw_getnf(ah, curchan);
2227
2228 if (bChannelChange &&
2229 (ahp->ah_chipFullSleep != true) &&
2230 (ah->ah_curchan != NULL) &&
2231 (chan->channel != ah->ah_curchan->channel) &&
2232 ((chan->channelFlags & CHANNEL_ALL) ==
2233 (ah->ah_curchan->channelFlags & CHANNEL_ALL)) &&
2234 (!AR_SREV_9280(ah) || (!IS_CHAN_A_5MHZ_SPACED(chan) &&
Sujith99405f92008-11-24 12:08:35 +05302235 !IS_CHAN_A_5MHZ_SPACED(ah->ah_curchan)))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002236
2237 if (ath9k_hw_channel_change(ah, chan, macmode)) {
2238 ath9k_hw_loadnf(ah, ah->ah_curchan);
2239 ath9k_hw_start_nfcal(ah);
2240 return true;
2241 }
2242 }
2243
2244 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
2245 if (saveDefAntenna == 0)
2246 saveDefAntenna = 1;
2247
2248 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
2249
2250 saveLedState = REG_READ(ah, AR_CFG_LED) &
2251 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
2252 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
2253
2254 ath9k_hw_mark_phy_inactive(ah);
2255
2256 if (!ath9k_hw_chip_reset(ah, chan)) {
2257 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "%s: chip reset failed\n",
2258 __func__);
Luis R. Rodriguez1cf69cf2008-10-10 12:25:45 -07002259 ecode = -EINVAL;
2260 goto bad;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002261 }
2262
2263 if (AR_SREV_9280(ah)) {
2264 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
2265 AR_GPIO_JTAG_DISABLE);
2266
Sujith86b89ee2008-08-07 10:54:57 +05302267 if (test_bit(ATH9K_MODE_11A, ah->ah_caps.wireless_modes)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002268 if (IS_CHAN_5GHZ(chan))
2269 ath9k_hw_set_gpio(ah, 9, 0);
2270 else
2271 ath9k_hw_set_gpio(ah, 9, 1);
2272 }
Vasanthakumar Thiagarajanc83be682008-08-25 20:47:29 +05302273 ath9k_hw_cfg_output(ah, 9, AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002274 }
2275
2276 ecode = ath9k_hw_process_ini(ah, chan, macmode);
Luis R. Rodriguez1cf69cf2008-10-10 12:25:45 -07002277 if (ecode != 0) {
2278 ecode = -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002279 goto bad;
Luis R. Rodriguez1cf69cf2008-10-10 12:25:45 -07002280 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002281
2282 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
2283 ath9k_hw_set_delta_slope(ah, chan);
2284
2285 if (AR_SREV_9280_10_OR_LATER(ah))
2286 ath9k_hw_9280_spur_mitigate(ah, chan);
2287 else
2288 ath9k_hw_spur_mitigate(ah, chan);
2289
2290 if (!ath9k_hw_eeprom_set_board_values(ah, chan)) {
2291 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
Sujithf1dc5602008-10-29 10:16:30 +05302292 "%s: error setting board options\n", __func__);
Luis R. Rodriguez1cf69cf2008-10-10 12:25:45 -07002293 ecode = -EIO;
2294 goto bad;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002295 }
2296
2297 ath9k_hw_decrease_chain_power(ah, chan);
2298
2299 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(ahp->ah_macaddr));
2300 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(ahp->ah_macaddr + 4)
2301 | macStaId1
2302 | AR_STA_ID1_RTS_USE_DEF
2303 | (ah->ah_config.
Sujith60b67f52008-08-07 10:52:38 +05302304 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002305 | ahp->ah_staId1Defaults);
Sujithb4696c8b2008-08-11 14:04:52 +05302306 ath9k_hw_set_operating_mode(ah, ah->ah_opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002307
2308 REG_WRITE(ah, AR_BSSMSKL, get_unaligned_le32(ahp->ah_bssidmask));
2309 REG_WRITE(ah, AR_BSSMSKU, get_unaligned_le16(ahp->ah_bssidmask + 4));
2310
2311 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
2312
2313 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(ahp->ah_bssid));
2314 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(ahp->ah_bssid + 4) |
2315 ((ahp->ah_assocId & 0x3fff) << AR_BSS_ID1_AID_S));
2316
2317 REG_WRITE(ah, AR_ISR, ~0);
2318
2319 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
2320
2321 if (AR_SREV_9280_10_OR_LATER(ah)) {
Luis R. Rodriguez1cf69cf2008-10-10 12:25:45 -07002322 if (!(ath9k_hw_ar9280_set_channel(ah, chan))) {
2323 ecode = -EIO;
2324 goto bad;
2325 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002326 } else {
Luis R. Rodriguez1cf69cf2008-10-10 12:25:45 -07002327 if (!(ath9k_hw_set_channel(ah, chan))) {
2328 ecode = -EIO;
2329 goto bad;
2330 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002331 }
2332
2333 for (i = 0; i < AR_NUM_DCU; i++)
2334 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
2335
2336 ahp->ah_intrTxqs = 0;
Sujith60b67f52008-08-07 10:52:38 +05302337 for (i = 0; i < ah->ah_caps.total_queues; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002338 ath9k_hw_resettxqueue(ah, i);
2339
Sujithb4696c8b2008-08-11 14:04:52 +05302340 ath9k_hw_init_interrupt_masks(ah, ah->ah_opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002341 ath9k_hw_init_qos(ah);
2342
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05302343#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05302344 if (ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
2345 ath9k_enable_rfkill(ah);
2346#endif
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002347 ath9k_hw_init_user_settings(ah);
2348
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002349 REG_WRITE(ah, AR_STA_ID1,
2350 REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
2351
2352 ath9k_hw_set_dma(ah);
2353
2354 REG_WRITE(ah, AR_OBS, 8);
2355
2356 if (ahp->ah_intrMitigation) {
2357
2358 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
2359 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
2360 }
2361
2362 ath9k_hw_init_bb(ah, chan);
2363
Luis R. Rodriguez1cf69cf2008-10-10 12:25:45 -07002364 if (!ath9k_hw_init_cal(ah, chan)){
2365 ecode = -EIO;;
2366 goto bad;
2367 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002368
2369 rx_chainmask = ahp->ah_rxchainmask;
2370 if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) {
2371 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
2372 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
2373 }
2374
2375 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
2376
2377 if (AR_SREV_9100(ah)) {
2378 u32 mask;
2379 mask = REG_READ(ah, AR_CFG);
2380 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
2381 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujithf1dc5602008-10-29 10:16:30 +05302382 "%s CFG Byte Swap Set 0x%x\n", __func__,
2383 mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002384 } else {
2385 mask =
2386 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
2387 REG_WRITE(ah, AR_CFG, mask);
2388 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujithf1dc5602008-10-29 10:16:30 +05302389 "%s Setting CFG 0x%x\n", __func__,
2390 REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002391 }
2392 } else {
2393#ifdef __BIG_ENDIAN
2394 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
2395#endif
2396 }
2397
2398 return true;
2399bad:
2400 if (status)
2401 *status = ecode;
2402 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002403}
2404
Sujithf1dc5602008-10-29 10:16:30 +05302405/************************/
2406/* Key Cache Management */
2407/************************/
2408
2409bool ath9k_hw_keyreset(struct ath_hal *ah, u16 entry)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002410{
Sujithf1dc5602008-10-29 10:16:30 +05302411 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002412
Sujithf1dc5602008-10-29 10:16:30 +05302413 if (entry >= ah->ah_caps.keycache_size) {
2414 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
2415 "%s: entry %u out of range\n", __func__, entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002416 return false;
2417 }
2418
Sujithf1dc5602008-10-29 10:16:30 +05302419 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002420
Sujithf1dc5602008-10-29 10:16:30 +05302421 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
2422 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
2423 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
2424 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
2425 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
2426 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
2427 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
2428 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
2429
2430 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2431 u16 micentry = entry + 64;
2432
2433 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
2434 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
2435 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
2436 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
2437
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002438 }
2439
Sujithf1dc5602008-10-29 10:16:30 +05302440 if (ah->ah_curchan == NULL)
2441 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002442
2443 return true;
2444}
2445
Sujithf1dc5602008-10-29 10:16:30 +05302446bool ath9k_hw_keysetmac(struct ath_hal *ah, u16 entry, const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002447{
Sujithf1dc5602008-10-29 10:16:30 +05302448 u32 macHi, macLo;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002449
Sujithf1dc5602008-10-29 10:16:30 +05302450 if (entry >= ah->ah_caps.keycache_size) {
2451 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
2452 "%s: entry %u out of range\n", __func__, entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002453 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002454 }
2455
Sujithf1dc5602008-10-29 10:16:30 +05302456 if (mac != NULL) {
2457 macHi = (mac[5] << 8) | mac[4];
2458 macLo = (mac[3] << 24) |
2459 (mac[2] << 16) |
2460 (mac[1] << 8) |
2461 mac[0];
2462 macLo >>= 1;
2463 macLo |= (macHi & 1) << 31;
2464 macHi >>= 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002465 } else {
Sujithf1dc5602008-10-29 10:16:30 +05302466 macLo = macHi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002467 }
Sujithf1dc5602008-10-29 10:16:30 +05302468 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
2469 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002470
2471 return true;
2472}
2473
Sujithf1dc5602008-10-29 10:16:30 +05302474bool ath9k_hw_set_keycache_entry(struct ath_hal *ah, u16 entry,
2475 const struct ath9k_keyval *k,
2476 const u8 *mac, int xorKey)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002477{
Sujith60b67f52008-08-07 10:52:38 +05302478 const struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
Sujithf1dc5602008-10-29 10:16:30 +05302479 u32 key0, key1, key2, key3, key4;
2480 u32 keyType;
2481 u32 xorMask = xorKey ?
2482 (ATH9K_KEY_XOR << 24 | ATH9K_KEY_XOR << 16 | ATH9K_KEY_XOR << 8
2483 | ATH9K_KEY_XOR) : 0;
2484 struct ath_hal_5416 *ahp = AH5416(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002485
Sujithf1dc5602008-10-29 10:16:30 +05302486 if (entry >= pCap->keycache_size) {
2487 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
2488 "%s: entry %u out of range\n", __func__, entry);
2489 return false;
2490 }
2491
2492 switch (k->kv_type) {
2493 case ATH9K_CIPHER_AES_OCB:
2494 keyType = AR_KEYTABLE_TYPE_AES;
2495 break;
2496 case ATH9K_CIPHER_AES_CCM:
2497 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
2498 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
2499 "%s: AES-CCM not supported by "
2500 "mac rev 0x%x\n", __func__,
2501 ah->ah_macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002502 return false;
2503 }
Sujithf1dc5602008-10-29 10:16:30 +05302504 keyType = AR_KEYTABLE_TYPE_CCM;
2505 break;
2506 case ATH9K_CIPHER_TKIP:
2507 keyType = AR_KEYTABLE_TYPE_TKIP;
2508 if (ATH9K_IS_MIC_ENABLED(ah)
2509 && entry + 64 >= pCap->keycache_size) {
2510 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
2511 "%s: entry %u inappropriate for TKIP\n",
2512 __func__, entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002513 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002514 }
Sujithf1dc5602008-10-29 10:16:30 +05302515 break;
2516 case ATH9K_CIPHER_WEP:
2517 if (k->kv_len < LEN_WEP40) {
2518 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
2519 "%s: WEP key length %u too small\n",
2520 __func__, k->kv_len);
2521 return false;
2522 }
2523 if (k->kv_len <= LEN_WEP40)
2524 keyType = AR_KEYTABLE_TYPE_40;
2525 else if (k->kv_len <= LEN_WEP104)
2526 keyType = AR_KEYTABLE_TYPE_104;
2527 else
2528 keyType = AR_KEYTABLE_TYPE_128;
2529 break;
2530 case ATH9K_CIPHER_CLR:
2531 keyType = AR_KEYTABLE_TYPE_CLR;
2532 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002533 default:
Sujithf1dc5602008-10-29 10:16:30 +05302534 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
2535 "%s: cipher %u not supported\n", __func__,
2536 k->kv_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002537 return false;
2538 }
Sujithf1dc5602008-10-29 10:16:30 +05302539
2540 key0 = get_unaligned_le32(k->kv_val + 0) ^ xorMask;
2541 key1 = (get_unaligned_le16(k->kv_val + 4) ^ xorMask) & 0xffff;
2542 key2 = get_unaligned_le32(k->kv_val + 6) ^ xorMask;
2543 key3 = (get_unaligned_le16(k->kv_val + 10) ^ xorMask) & 0xffff;
2544 key4 = get_unaligned_le32(k->kv_val + 12) ^ xorMask;
2545 if (k->kv_len <= LEN_WEP104)
2546 key4 &= 0xff;
2547
2548 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2549 u16 micentry = entry + 64;
2550
2551 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
2552 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
2553 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2554 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
2555 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2556 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
2557 (void) ath9k_hw_keysetmac(ah, entry, mac);
2558
2559 if (ahp->ah_miscMode & AR_PCU_MIC_NEW_LOC_ENA) {
2560 u32 mic0, mic1, mic2, mic3, mic4;
2561
2562 mic0 = get_unaligned_le32(k->kv_mic + 0);
2563 mic2 = get_unaligned_le32(k->kv_mic + 4);
2564 mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
2565 mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
2566 mic4 = get_unaligned_le32(k->kv_txmic + 4);
2567 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2568 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
2569 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2570 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
2571 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
2572 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2573 AR_KEYTABLE_TYPE_CLR);
2574
2575 } else {
2576 u32 mic0, mic2;
2577
2578 mic0 = get_unaligned_le32(k->kv_mic + 0);
2579 mic2 = get_unaligned_le32(k->kv_mic + 4);
2580 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2581 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
2582 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2583 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
2584 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
2585 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2586 AR_KEYTABLE_TYPE_CLR);
2587 }
2588 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
2589 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
2590 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2591 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
2592 } else {
2593 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2594 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
2595 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2596 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
2597 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2598 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
2599
2600 (void) ath9k_hw_keysetmac(ah, entry, mac);
2601 }
2602
2603 if (ah->ah_curchan == NULL)
2604 return true;
2605
2606 return true;
2607}
2608
2609bool ath9k_hw_keyisvalid(struct ath_hal *ah, u16 entry)
2610{
2611 if (entry < ah->ah_caps.keycache_size) {
2612 u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
2613 if (val & AR_KEYTABLE_VALID)
2614 return true;
2615 }
2616 return false;
2617}
2618
2619/******************************/
2620/* Power Management (Chipset) */
2621/******************************/
2622
2623static void ath9k_set_power_sleep(struct ath_hal *ah, int setChip)
2624{
2625 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2626 if (setChip) {
2627 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2628 AR_RTC_FORCE_WAKE_EN);
2629 if (!AR_SREV_9100(ah))
2630 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
2631
2632 REG_CLR_BIT(ah, (u16) (AR_RTC_RESET),
2633 AR_RTC_RESET_EN);
2634 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002635}
2636
Sujithf1dc5602008-10-29 10:16:30 +05302637static void ath9k_set_power_network_sleep(struct ath_hal *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002638{
Sujithf1dc5602008-10-29 10:16:30 +05302639 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2640 if (setChip) {
2641 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002642
Sujithf1dc5602008-10-29 10:16:30 +05302643 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
2644 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2645 AR_RTC_FORCE_WAKE_ON_INT);
2646 } else {
2647 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2648 AR_RTC_FORCE_WAKE_EN);
2649 }
2650 }
2651}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002652
Sujithf1dc5602008-10-29 10:16:30 +05302653static bool ath9k_hw_set_power_awake(struct ath_hal *ah,
2654 int setChip)
2655{
2656 u32 val;
2657 int i;
2658
2659 if (setChip) {
2660 if ((REG_READ(ah, AR_RTC_STATUS) &
2661 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2662 if (ath9k_hw_set_reset_reg(ah,
2663 ATH9K_RESET_POWER_ON) != true) {
2664 return false;
2665 }
2666 }
2667 if (AR_SREV_9100(ah))
2668 REG_SET_BIT(ah, AR_RTC_RESET,
2669 AR_RTC_RESET_EN);
2670
2671 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2672 AR_RTC_FORCE_WAKE_EN);
2673 udelay(50);
2674
2675 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2676 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2677 if (val == AR_RTC_STATUS_ON)
2678 break;
2679 udelay(50);
2680 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2681 AR_RTC_FORCE_WAKE_EN);
2682 }
2683 if (i == 0) {
2684 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
2685 "%s: Failed to wakeup in %uus\n",
2686 __func__, POWER_UP_TIME / 20);
2687 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002688 }
2689 }
2690
Sujithf1dc5602008-10-29 10:16:30 +05302691 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2692
2693 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002694}
2695
Sujithf1dc5602008-10-29 10:16:30 +05302696bool ath9k_hw_setpower(struct ath_hal *ah,
2697 enum ath9k_power_mode mode)
2698{
2699 struct ath_hal_5416 *ahp = AH5416(ah);
2700 static const char *modes[] = {
2701 "AWAKE",
2702 "FULL-SLEEP",
2703 "NETWORK SLEEP",
2704 "UNDEFINED"
2705 };
2706 int status = true, setChip = true;
2707
2708 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT, "%s: %s -> %s (%s)\n", __func__,
2709 modes[ahp->ah_powerMode], modes[mode],
2710 setChip ? "set chip " : "");
2711
2712 switch (mode) {
2713 case ATH9K_PM_AWAKE:
2714 status = ath9k_hw_set_power_awake(ah, setChip);
2715 break;
2716 case ATH9K_PM_FULL_SLEEP:
2717 ath9k_set_power_sleep(ah, setChip);
2718 ahp->ah_chipFullSleep = true;
2719 break;
2720 case ATH9K_PM_NETWORK_SLEEP:
2721 ath9k_set_power_network_sleep(ah, setChip);
2722 break;
2723 default:
2724 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
2725 "%s: unknown power mode %u\n", __func__, mode);
2726 return false;
2727 }
2728 ahp->ah_powerMode = mode;
2729
2730 return status;
2731}
2732
2733void ath9k_hw_configpcipowersave(struct ath_hal *ah, int restore)
2734{
2735 struct ath_hal_5416 *ahp = AH5416(ah);
2736 u8 i;
2737
2738 if (ah->ah_isPciExpress != true)
2739 return;
2740
2741 if (ah->ah_config.pcie_powersave_enable == 2)
2742 return;
2743
2744 if (restore)
2745 return;
2746
2747 if (AR_SREV_9280_20_OR_LATER(ah)) {
2748 for (i = 0; i < ahp->ah_iniPcieSerdes.ia_rows; i++) {
2749 REG_WRITE(ah, INI_RA(&ahp->ah_iniPcieSerdes, i, 0),
2750 INI_RA(&ahp->ah_iniPcieSerdes, i, 1));
2751 }
2752 udelay(1000);
2753 } else if (AR_SREV_9280(ah) &&
2754 (ah->ah_macRev == AR_SREV_REVISION_9280_10)) {
2755 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
2756 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
2757
2758 REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
2759 REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
2760 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
2761
2762 if (ah->ah_config.pcie_clock_req)
2763 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
2764 else
2765 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
2766
2767 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2768 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2769 REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
2770
2771 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
2772
2773 udelay(1000);
2774 } else {
2775 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
2776 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
2777 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
2778 REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
2779 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
2780 REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
2781 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2782 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2783 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
2784 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
2785 }
2786
2787 REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
2788
2789 if (ah->ah_config.pcie_waen) {
2790 REG_WRITE(ah, AR_WA, ah->ah_config.pcie_waen);
2791 } else {
2792 if (AR_SREV_9280(ah))
2793 REG_WRITE(ah, AR_WA, 0x0040073f);
2794 else
2795 REG_WRITE(ah, AR_WA, 0x0000073f);
2796 }
2797}
2798
2799/**********************/
2800/* Interrupt Handling */
2801/**********************/
2802
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002803bool ath9k_hw_intrpend(struct ath_hal *ah)
2804{
2805 u32 host_isr;
2806
2807 if (AR_SREV_9100(ah))
2808 return true;
2809
2810 host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
2811 if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
2812 return true;
2813
2814 host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
2815 if ((host_isr & AR_INTR_SYNC_DEFAULT)
2816 && (host_isr != AR_INTR_SPURIOUS))
2817 return true;
2818
2819 return false;
2820}
2821
2822bool ath9k_hw_getisr(struct ath_hal *ah, enum ath9k_int *masked)
2823{
2824 u32 isr = 0;
2825 u32 mask2 = 0;
Sujith60b67f52008-08-07 10:52:38 +05302826 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002827 u32 sync_cause = 0;
2828 bool fatal_int = false;
Sujithf1dc5602008-10-29 10:16:30 +05302829 struct ath_hal_5416 *ahp = AH5416(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002830
2831 if (!AR_SREV_9100(ah)) {
2832 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
2833 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
2834 == AR_RTC_STATUS_ON) {
2835 isr = REG_READ(ah, AR_ISR);
2836 }
2837 }
2838
Sujithf1dc5602008-10-29 10:16:30 +05302839 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
2840 AR_INTR_SYNC_DEFAULT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002841
2842 *masked = 0;
2843
2844 if (!isr && !sync_cause)
2845 return false;
2846 } else {
2847 *masked = 0;
2848 isr = REG_READ(ah, AR_ISR);
2849 }
2850
2851 if (isr) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002852 if (isr & AR_ISR_BCNMISC) {
2853 u32 isr2;
2854 isr2 = REG_READ(ah, AR_ISR_S2);
2855 if (isr2 & AR_ISR_S2_TIM)
2856 mask2 |= ATH9K_INT_TIM;
2857 if (isr2 & AR_ISR_S2_DTIM)
2858 mask2 |= ATH9K_INT_DTIM;
2859 if (isr2 & AR_ISR_S2_DTIMSYNC)
2860 mask2 |= ATH9K_INT_DTIMSYNC;
2861 if (isr2 & (AR_ISR_S2_CABEND))
2862 mask2 |= ATH9K_INT_CABEND;
2863 if (isr2 & AR_ISR_S2_GTT)
2864 mask2 |= ATH9K_INT_GTT;
2865 if (isr2 & AR_ISR_S2_CST)
2866 mask2 |= ATH9K_INT_CST;
2867 }
2868
2869 isr = REG_READ(ah, AR_ISR_RAC);
2870 if (isr == 0xffffffff) {
2871 *masked = 0;
2872 return false;
2873 }
2874
2875 *masked = isr & ATH9K_INT_COMMON;
2876
2877 if (ahp->ah_intrMitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002878 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
2879 *masked |= ATH9K_INT_RX;
2880 }
2881
2882 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
2883 *masked |= ATH9K_INT_RX;
2884 if (isr &
2885 (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
2886 AR_ISR_TXEOL)) {
2887 u32 s0_s, s1_s;
2888
2889 *masked |= ATH9K_INT_TX;
2890
2891 s0_s = REG_READ(ah, AR_ISR_S0_S);
2892 ahp->ah_intrTxqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
2893 ahp->ah_intrTxqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
2894
2895 s1_s = REG_READ(ah, AR_ISR_S1_S);
2896 ahp->ah_intrTxqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
2897 ahp->ah_intrTxqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
2898 }
2899
2900 if (isr & AR_ISR_RXORN) {
2901 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
Sujithf1dc5602008-10-29 10:16:30 +05302902 "%s: receive FIFO overrun interrupt\n",
2903 __func__);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002904 }
2905
2906 if (!AR_SREV_9100(ah)) {
Sujith60b67f52008-08-07 10:52:38 +05302907 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002908 u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
2909 if (isr5 & AR_ISR_S5_TIM_TIMER)
2910 *masked |= ATH9K_INT_TIM_TIMER;
2911 }
2912 }
2913
2914 *masked |= mask2;
2915 }
Sujithf1dc5602008-10-29 10:16:30 +05302916
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002917 if (AR_SREV_9100(ah))
2918 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302919
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002920 if (sync_cause) {
2921 fatal_int =
2922 (sync_cause &
2923 (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
2924 ? true : false;
2925
2926 if (fatal_int) {
2927 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
2928 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
Sujithf1dc5602008-10-29 10:16:30 +05302929 "%s: received PCI FATAL interrupt\n",
2930 __func__);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002931 }
2932 if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
2933 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
Sujithf1dc5602008-10-29 10:16:30 +05302934 "%s: received PCI PERR interrupt\n",
2935 __func__);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002936 }
2937 }
2938 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
2939 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
Sujithf1dc5602008-10-29 10:16:30 +05302940 "%s: AR_INTR_SYNC_RADM_CPL_TIMEOUT\n",
2941 __func__);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002942 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
2943 REG_WRITE(ah, AR_RC, 0);
2944 *masked |= ATH9K_INT_FATAL;
2945 }
2946 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
2947 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
Sujithf1dc5602008-10-29 10:16:30 +05302948 "%s: AR_INTR_SYNC_LOCAL_TIMEOUT\n",
2949 __func__);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002950 }
2951
2952 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
2953 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
2954 }
Sujithf1dc5602008-10-29 10:16:30 +05302955
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002956 return true;
2957}
2958
2959enum ath9k_int ath9k_hw_intrget(struct ath_hal *ah)
2960{
2961 return AH5416(ah)->ah_maskReg;
2962}
2963
2964enum ath9k_int ath9k_hw_set_interrupts(struct ath_hal *ah, enum ath9k_int ints)
2965{
2966 struct ath_hal_5416 *ahp = AH5416(ah);
2967 u32 omask = ahp->ah_maskReg;
2968 u32 mask, mask2;
Sujith60b67f52008-08-07 10:52:38 +05302969 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002970
2971 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "%s: 0x%x => 0x%x\n", __func__,
2972 omask, ints);
2973
2974 if (omask & ATH9K_INT_GLOBAL) {
2975 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "%s: disable IER\n",
2976 __func__);
2977 REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
2978 (void) REG_READ(ah, AR_IER);
2979 if (!AR_SREV_9100(ah)) {
2980 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
2981 (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
2982
2983 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
2984 (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
2985 }
2986 }
2987
2988 mask = ints & ATH9K_INT_COMMON;
2989 mask2 = 0;
2990
2991 if (ints & ATH9K_INT_TX) {
2992 if (ahp->ah_txOkInterruptMask)
2993 mask |= AR_IMR_TXOK;
2994 if (ahp->ah_txDescInterruptMask)
2995 mask |= AR_IMR_TXDESC;
2996 if (ahp->ah_txErrInterruptMask)
2997 mask |= AR_IMR_TXERR;
2998 if (ahp->ah_txEolInterruptMask)
2999 mask |= AR_IMR_TXEOL;
3000 }
3001 if (ints & ATH9K_INT_RX) {
3002 mask |= AR_IMR_RXERR;
3003 if (ahp->ah_intrMitigation)
3004 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
3005 else
3006 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
Sujith60b67f52008-08-07 10:52:38 +05303007 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003008 mask |= AR_IMR_GENTMR;
3009 }
3010
3011 if (ints & (ATH9K_INT_BMISC)) {
3012 mask |= AR_IMR_BCNMISC;
3013 if (ints & ATH9K_INT_TIM)
3014 mask2 |= AR_IMR_S2_TIM;
3015 if (ints & ATH9K_INT_DTIM)
3016 mask2 |= AR_IMR_S2_DTIM;
3017 if (ints & ATH9K_INT_DTIMSYNC)
3018 mask2 |= AR_IMR_S2_DTIMSYNC;
3019 if (ints & ATH9K_INT_CABEND)
3020 mask2 |= (AR_IMR_S2_CABEND);
3021 }
3022
3023 if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
3024 mask |= AR_IMR_BCNMISC;
3025 if (ints & ATH9K_INT_GTT)
3026 mask2 |= AR_IMR_S2_GTT;
3027 if (ints & ATH9K_INT_CST)
3028 mask2 |= AR_IMR_S2_CST;
3029 }
3030
3031 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "%s: new IMR 0x%x\n", __func__,
3032 mask);
3033 REG_WRITE(ah, AR_IMR, mask);
3034 mask = REG_READ(ah, AR_IMR_S2) & ~(AR_IMR_S2_TIM |
3035 AR_IMR_S2_DTIM |
3036 AR_IMR_S2_DTIMSYNC |
3037 AR_IMR_S2_CABEND |
3038 AR_IMR_S2_CABTO |
3039 AR_IMR_S2_TSFOOR |
3040 AR_IMR_S2_GTT | AR_IMR_S2_CST);
3041 REG_WRITE(ah, AR_IMR_S2, mask | mask2);
3042 ahp->ah_maskReg = ints;
3043
Sujith60b67f52008-08-07 10:52:38 +05303044 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003045 if (ints & ATH9K_INT_TIM_TIMER)
3046 REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
3047 else
3048 REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
3049 }
3050
3051 if (ints & ATH9K_INT_GLOBAL) {
3052 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "%s: enable IER\n",
3053 __func__);
3054 REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
3055 if (!AR_SREV_9100(ah)) {
3056 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
3057 AR_INTR_MAC_IRQ);
3058 REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
3059
3060
3061 REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
3062 AR_INTR_SYNC_DEFAULT);
3063 REG_WRITE(ah, AR_INTR_SYNC_MASK,
3064 AR_INTR_SYNC_DEFAULT);
3065 }
3066 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
3067 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
3068 }
3069
3070 return omask;
3071}
3072
Sujithf1dc5602008-10-29 10:16:30 +05303073/*******************/
3074/* Beacon Handling */
3075/*******************/
3076
3077void ath9k_hw_beaconinit(struct ath_hal *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003078{
3079 struct ath_hal_5416 *ahp = AH5416(ah);
3080 int flags = 0;
3081
3082 ahp->ah_beaconInterval = beacon_period;
3083
3084 switch (ah->ah_opmode) {
3085 case ATH9K_M_STA:
3086 case ATH9K_M_MONITOR:
3087 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3088 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
3089 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
3090 flags |= AR_TBTT_TIMER_EN;
3091 break;
3092 case ATH9K_M_IBSS:
3093 REG_SET_BIT(ah, AR_TXCFG,
3094 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
3095 REG_WRITE(ah, AR_NEXT_NDP_TIMER,
3096 TU_TO_USEC(next_beacon +
3097 (ahp->ah_atimWindow ? ahp->
3098 ah_atimWindow : 1)));
3099 flags |= AR_NDP_TIMER_EN;
3100 case ATH9K_M_HOSTAP:
3101 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3102 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
3103 TU_TO_USEC(next_beacon -
3104 ah->ah_config.
Sujith60b67f52008-08-07 10:52:38 +05303105 dma_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003106 REG_WRITE(ah, AR_NEXT_SWBA,
3107 TU_TO_USEC(next_beacon -
3108 ah->ah_config.
Sujith60b67f52008-08-07 10:52:38 +05303109 sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003110 flags |=
3111 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
3112 break;
3113 }
3114
3115 REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3116 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3117 REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
3118 REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
3119
3120 beacon_period &= ~ATH9K_BEACON_ENA;
3121 if (beacon_period & ATH9K_BEACON_RESET_TSF) {
3122 beacon_period &= ~ATH9K_BEACON_RESET_TSF;
3123 ath9k_hw_reset_tsf(ah);
3124 }
3125
3126 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
3127}
3128
Sujithf1dc5602008-10-29 10:16:30 +05303129void ath9k_hw_set_sta_beacon_timers(struct ath_hal *ah,
3130 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003131{
3132 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith60b67f52008-08-07 10:52:38 +05303133 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003134
3135 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
3136
3137 REG_WRITE(ah, AR_BEACON_PERIOD,
3138 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3139 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
3140 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3141
3142 REG_RMW_FIELD(ah, AR_RSSI_THR,
3143 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
3144
3145 beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
3146
3147 if (bs->bs_sleepduration > beaconintval)
3148 beaconintval = bs->bs_sleepduration;
3149
3150 dtimperiod = bs->bs_dtimperiod;
3151 if (bs->bs_sleepduration > dtimperiod)
3152 dtimperiod = bs->bs_sleepduration;
3153
3154 if (beaconintval == dtimperiod)
3155 nextTbtt = bs->bs_nextdtim;
3156 else
3157 nextTbtt = bs->bs_nexttbtt;
3158
3159 DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "%s: next DTIM %d\n", __func__,
3160 bs->bs_nextdtim);
3161 DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "%s: next beacon %d\n", __func__,
3162 nextTbtt);
3163 DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "%s: beacon period %d\n", __func__,
3164 beaconintval);
3165 DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "%s: DTIM period %d\n", __func__,
3166 dtimperiod);
3167
3168 REG_WRITE(ah, AR_NEXT_DTIM,
3169 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
3170 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
3171
3172 REG_WRITE(ah, AR_SLEEP1,
3173 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
3174 | AR_SLEEP1_ASSUME_DTIM);
3175
Sujith60b67f52008-08-07 10:52:38 +05303176 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003177 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
3178 else
3179 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
3180
3181 REG_WRITE(ah, AR_SLEEP2,
3182 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
3183
3184 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
3185 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
3186
3187 REG_SET_BIT(ah, AR_TIMER_MODE,
3188 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
3189 AR_DTIM_TIMER_EN);
3190
3191}
3192
Sujithf1dc5602008-10-29 10:16:30 +05303193/*******************/
3194/* HW Capabilities */
3195/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003196
Sujithf1dc5602008-10-29 10:16:30 +05303197bool ath9k_hw_fill_cap_info(struct ath_hal *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003198{
Sujithf1dc5602008-10-29 10:16:30 +05303199 struct ath_hal_5416 *ahp = AH5416(ah);
3200 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
3201 u16 capField = 0, eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003202
Sujithf1dc5602008-10-29 10:16:30 +05303203 eeval = ath9k_hw_get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003204
Sujithf1dc5602008-10-29 10:16:30 +05303205 ah->ah_currentRD = eeval;
3206
3207 eeval = ath9k_hw_get_eeprom(ah, EEP_REG_1);
3208 ah->ah_currentRDExt = eeval;
3209
3210 capField = ath9k_hw_get_eeprom(ah, EEP_OP_CAP);
3211
3212 if (ah->ah_opmode != ATH9K_M_HOSTAP &&
3213 ah->ah_subvendorid == AR_SUBVENDOR_ID_NEW_A) {
3214 if (ah->ah_currentRD == 0x64 || ah->ah_currentRD == 0x65)
3215 ah->ah_currentRD += 5;
3216 else if (ah->ah_currentRD == 0x41)
3217 ah->ah_currentRD = 0x43;
3218 DPRINTF(ah->ah_sc, ATH_DBG_REGULATORY,
3219 "%s: regdomain mapped to 0x%x\n", __func__,
3220 ah->ah_currentRD);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003221 }
Sujithdc2222a2008-08-14 13:26:55 +05303222
Sujithf1dc5602008-10-29 10:16:30 +05303223 eeval = ath9k_hw_get_eeprom(ah, EEP_OP_MODE);
3224 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003225
Sujithf1dc5602008-10-29 10:16:30 +05303226 if (eeval & AR5416_OPFLAGS_11A) {
3227 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
3228 if (ah->ah_config.ht_enable) {
3229 if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
3230 set_bit(ATH9K_MODE_11NA_HT20,
3231 pCap->wireless_modes);
3232 if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
3233 set_bit(ATH9K_MODE_11NA_HT40PLUS,
3234 pCap->wireless_modes);
3235 set_bit(ATH9K_MODE_11NA_HT40MINUS,
3236 pCap->wireless_modes);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003237 }
3238 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003239 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003240
Sujithf1dc5602008-10-29 10:16:30 +05303241 if (eeval & AR5416_OPFLAGS_11G) {
3242 set_bit(ATH9K_MODE_11B, pCap->wireless_modes);
3243 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
3244 if (ah->ah_config.ht_enable) {
3245 if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
3246 set_bit(ATH9K_MODE_11NG_HT20,
3247 pCap->wireless_modes);
3248 if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
3249 set_bit(ATH9K_MODE_11NG_HT40PLUS,
3250 pCap->wireless_modes);
3251 set_bit(ATH9K_MODE_11NG_HT40MINUS,
3252 pCap->wireless_modes);
3253 }
3254 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003255 }
Sujithf1dc5602008-10-29 10:16:30 +05303256
3257 pCap->tx_chainmask = ath9k_hw_get_eeprom(ah, EEP_TX_MASK);
3258 if ((ah->ah_isPciExpress)
3259 || (eeval & AR5416_OPFLAGS_11A)) {
3260 pCap->rx_chainmask =
3261 ath9k_hw_get_eeprom(ah, EEP_RX_MASK);
3262 } else {
3263 pCap->rx_chainmask =
3264 (ath9k_hw_gpio_get(ah, 0)) ? 0x5 : 0x7;
3265 }
3266
3267 if (!(AR_SREV_9280(ah) && (ah->ah_macRev == 0)))
3268 ahp->ah_miscMode |= AR_PCU_MIC_NEW_LOC_ENA;
3269
3270 pCap->low_2ghz_chan = 2312;
3271 pCap->high_2ghz_chan = 2732;
3272
3273 pCap->low_5ghz_chan = 4920;
3274 pCap->high_5ghz_chan = 6100;
3275
3276 pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
3277 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
3278 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
3279
3280 pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
3281 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
3282 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
3283
3284 pCap->hw_caps |= ATH9K_HW_CAP_CHAN_SPREAD;
3285
3286 if (ah->ah_config.ht_enable)
3287 pCap->hw_caps |= ATH9K_HW_CAP_HT;
3288 else
3289 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
3290
3291 pCap->hw_caps |= ATH9K_HW_CAP_GTT;
3292 pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
3293 pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
3294 pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
3295
3296 if (capField & AR_EEPROM_EEPCAP_MAXQCU)
3297 pCap->total_queues =
3298 MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
3299 else
3300 pCap->total_queues = ATH9K_NUM_TX_QUEUES;
3301
3302 if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
3303 pCap->keycache_size =
3304 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
3305 else
3306 pCap->keycache_size = AR_KEYTABLE_SIZE;
3307
3308 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
3309 pCap->num_mr_retries = 4;
3310 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
3311
3312 if (AR_SREV_9280_10_OR_LATER(ah))
3313 pCap->num_gpio_pins = AR928X_NUM_GPIO;
3314 else
3315 pCap->num_gpio_pins = AR_NUM_GPIO;
3316
3317 if (AR_SREV_9280_10_OR_LATER(ah)) {
3318 pCap->hw_caps |= ATH9K_HW_CAP_WOW;
3319 pCap->hw_caps |= ATH9K_HW_CAP_WOW_MATCHPATTERN_EXACT;
3320 } else {
3321 pCap->hw_caps &= ~ATH9K_HW_CAP_WOW;
3322 pCap->hw_caps &= ~ATH9K_HW_CAP_WOW_MATCHPATTERN_EXACT;
3323 }
3324
3325 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
3326 pCap->hw_caps |= ATH9K_HW_CAP_CST;
3327 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
3328 } else {
3329 pCap->rts_aggr_limit = (8 * 1024);
3330 }
3331
3332 pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
3333
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05303334#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujithf1dc5602008-10-29 10:16:30 +05303335 ah->ah_rfsilent = ath9k_hw_get_eeprom(ah, EEP_RF_SILENT);
3336 if (ah->ah_rfsilent & EEP_RFSILENT_ENABLED) {
3337 ah->ah_rfkill_gpio =
3338 MS(ah->ah_rfsilent, EEP_RFSILENT_GPIO_SEL);
3339 ah->ah_rfkill_polarity =
3340 MS(ah->ah_rfsilent, EEP_RFSILENT_POLARITY);
3341
3342 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
3343 }
3344#endif
3345
3346 if ((ah->ah_macVersion == AR_SREV_VERSION_5416_PCI) ||
3347 (ah->ah_macVersion == AR_SREV_VERSION_5416_PCIE) ||
3348 (ah->ah_macVersion == AR_SREV_VERSION_9160) ||
3349 (ah->ah_macVersion == AR_SREV_VERSION_9100) ||
3350 (ah->ah_macVersion == AR_SREV_VERSION_9280))
3351 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
3352 else
3353 pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
3354
3355 if (AR_SREV_9280(ah))
3356 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
3357 else
3358 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
3359
3360 if (ah->ah_currentRDExt & (1 << REG_EXT_JAPAN_MIDBAND)) {
3361 pCap->reg_cap =
3362 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3363 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
3364 AR_EEPROM_EEREGCAP_EN_KK_U2 |
3365 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
3366 } else {
3367 pCap->reg_cap =
3368 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3369 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
3370 }
3371
3372 pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
3373
3374 pCap->num_antcfg_5ghz =
3375 ath9k_hw_get_num_ant_config(ah, IEEE80211_BAND_5GHZ);
3376 pCap->num_antcfg_2ghz =
3377 ath9k_hw_get_num_ant_config(ah, IEEE80211_BAND_2GHZ);
3378
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003379 return true;
3380}
3381
Sujithf1dc5602008-10-29 10:16:30 +05303382bool ath9k_hw_getcapability(struct ath_hal *ah, enum ath9k_capability_type type,
3383 u32 capability, u32 *result)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003384{
Sujithf1dc5602008-10-29 10:16:30 +05303385 struct ath_hal_5416 *ahp = AH5416(ah);
3386 const struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003387
Sujithf1dc5602008-10-29 10:16:30 +05303388 switch (type) {
3389 case ATH9K_CAP_CIPHER:
3390 switch (capability) {
3391 case ATH9K_CIPHER_AES_CCM:
3392 case ATH9K_CIPHER_AES_OCB:
3393 case ATH9K_CIPHER_TKIP:
3394 case ATH9K_CIPHER_WEP:
3395 case ATH9K_CIPHER_MIC:
3396 case ATH9K_CIPHER_CLR:
3397 return true;
3398 default:
3399 return false;
3400 }
3401 case ATH9K_CAP_TKIP_MIC:
3402 switch (capability) {
3403 case 0:
3404 return true;
3405 case 1:
3406 return (ahp->ah_staId1Defaults &
3407 AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
3408 false;
3409 }
3410 case ATH9K_CAP_TKIP_SPLIT:
3411 return (ahp->ah_miscMode & AR_PCU_MIC_NEW_LOC_ENA) ?
3412 false : true;
3413 case ATH9K_CAP_WME_TKIPMIC:
3414 return 0;
3415 case ATH9K_CAP_PHYCOUNTERS:
3416 return ahp->ah_hasHwPhyCounters ? 0 : -ENXIO;
3417 case ATH9K_CAP_DIVERSITY:
3418 return (REG_READ(ah, AR_PHY_CCK_DETECT) &
3419 AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV) ?
3420 true : false;
3421 case ATH9K_CAP_PHYDIAG:
3422 return true;
3423 case ATH9K_CAP_MCAST_KEYSRCH:
3424 switch (capability) {
3425 case 0:
3426 return true;
3427 case 1:
3428 if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
3429 return false;
3430 } else {
3431 return (ahp->ah_staId1Defaults &
3432 AR_STA_ID1_MCAST_KSRCH) ? true :
3433 false;
3434 }
3435 }
3436 return false;
3437 case ATH9K_CAP_TSF_ADJUST:
3438 return (ahp->ah_miscMode & AR_PCU_TX_ADD_TSF) ?
3439 true : false;
3440 case ATH9K_CAP_RFSILENT:
3441 if (capability == 3)
3442 return false;
3443 case ATH9K_CAP_ANT_CFG_2GHZ:
3444 *result = pCap->num_antcfg_2ghz;
3445 return true;
3446 case ATH9K_CAP_ANT_CFG_5GHZ:
3447 *result = pCap->num_antcfg_5ghz;
3448 return true;
3449 case ATH9K_CAP_TXPOW:
3450 switch (capability) {
3451 case 0:
3452 return 0;
3453 case 1:
3454 *result = ah->ah_powerLimit;
3455 return 0;
3456 case 2:
3457 *result = ah->ah_maxPowerLevel;
3458 return 0;
3459 case 3:
3460 *result = ah->ah_tpScale;
3461 return 0;
3462 }
3463 return false;
3464 default:
3465 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003466 }
Sujithf1dc5602008-10-29 10:16:30 +05303467}
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003468
Sujithf1dc5602008-10-29 10:16:30 +05303469bool ath9k_hw_setcapability(struct ath_hal *ah, enum ath9k_capability_type type,
3470 u32 capability, u32 setting, int *status)
3471{
3472 struct ath_hal_5416 *ahp = AH5416(ah);
3473 u32 v;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003474
Sujithf1dc5602008-10-29 10:16:30 +05303475 switch (type) {
3476 case ATH9K_CAP_TKIP_MIC:
3477 if (setting)
3478 ahp->ah_staId1Defaults |=
3479 AR_STA_ID1_CRPT_MIC_ENABLE;
3480 else
3481 ahp->ah_staId1Defaults &=
3482 ~AR_STA_ID1_CRPT_MIC_ENABLE;
3483 return true;
3484 case ATH9K_CAP_DIVERSITY:
3485 v = REG_READ(ah, AR_PHY_CCK_DETECT);
3486 if (setting)
3487 v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3488 else
3489 v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3490 REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
3491 return true;
3492 case ATH9K_CAP_MCAST_KEYSRCH:
3493 if (setting)
3494 ahp->ah_staId1Defaults |= AR_STA_ID1_MCAST_KSRCH;
3495 else
3496 ahp->ah_staId1Defaults &= ~AR_STA_ID1_MCAST_KSRCH;
3497 return true;
3498 case ATH9K_CAP_TSF_ADJUST:
3499 if (setting)
3500 ahp->ah_miscMode |= AR_PCU_TX_ADD_TSF;
3501 else
3502 ahp->ah_miscMode &= ~AR_PCU_TX_ADD_TSF;
3503 return true;
3504 default:
3505 return false;
3506 }
3507}
3508
3509/****************************/
3510/* GPIO / RFKILL / Antennae */
3511/****************************/
3512
3513static void ath9k_hw_gpio_cfg_output_mux(struct ath_hal *ah,
3514 u32 gpio, u32 type)
3515{
3516 int addr;
3517 u32 gpio_shift, tmp;
3518
3519 if (gpio > 11)
3520 addr = AR_GPIO_OUTPUT_MUX3;
3521 else if (gpio > 5)
3522 addr = AR_GPIO_OUTPUT_MUX2;
3523 else
3524 addr = AR_GPIO_OUTPUT_MUX1;
3525
3526 gpio_shift = (gpio % 6) * 5;
3527
3528 if (AR_SREV_9280_20_OR_LATER(ah)
3529 || (addr != AR_GPIO_OUTPUT_MUX1)) {
3530 REG_RMW(ah, addr, (type << gpio_shift),
3531 (0x1f << gpio_shift));
3532 } else {
3533 tmp = REG_READ(ah, addr);
3534 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
3535 tmp &= ~(0x1f << gpio_shift);
3536 tmp |= (type << gpio_shift);
3537 REG_WRITE(ah, addr, tmp);
3538 }
3539}
3540
3541void ath9k_hw_cfg_gpio_input(struct ath_hal *ah, u32 gpio)
3542{
3543 u32 gpio_shift;
3544
3545 ASSERT(gpio < ah->ah_caps.num_gpio_pins);
3546
3547 gpio_shift = gpio << 1;
3548
3549 REG_RMW(ah,
3550 AR_GPIO_OE_OUT,
3551 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
3552 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3553}
3554
3555u32 ath9k_hw_gpio_get(struct ath_hal *ah, u32 gpio)
3556{
3557 if (gpio >= ah->ah_caps.num_gpio_pins)
3558 return 0xffffffff;
3559
3560 if (AR_SREV_9280_10_OR_LATER(ah)) {
3561 return (MS
3562 (REG_READ(ah, AR_GPIO_IN_OUT),
3563 AR928X_GPIO_IN_VAL) & AR_GPIO_BIT(gpio)) != 0;
3564 } else {
3565 return (MS(REG_READ(ah, AR_GPIO_IN_OUT), AR_GPIO_IN_VAL) &
3566 AR_GPIO_BIT(gpio)) != 0;
3567 }
3568}
3569
3570void ath9k_hw_cfg_output(struct ath_hal *ah, u32 gpio,
3571 u32 ah_signal_type)
3572{
3573 u32 gpio_shift;
3574
3575 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
3576
3577 gpio_shift = 2 * gpio;
3578
3579 REG_RMW(ah,
3580 AR_GPIO_OE_OUT,
3581 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
3582 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3583}
3584
3585void ath9k_hw_set_gpio(struct ath_hal *ah, u32 gpio, u32 val)
3586{
3587 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
3588 AR_GPIO_BIT(gpio));
3589}
3590
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05303591#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujithf1dc5602008-10-29 10:16:30 +05303592void ath9k_enable_rfkill(struct ath_hal *ah)
3593{
3594 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
3595 AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
3596
3597 REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2,
3598 AR_GPIO_INPUT_MUX2_RFSILENT);
3599
3600 ath9k_hw_cfg_gpio_input(ah, ah->ah_rfkill_gpio);
3601 REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);
3602}
3603#endif
3604
3605int ath9k_hw_select_antconfig(struct ath_hal *ah, u32 cfg)
3606{
3607 struct ath9k_channel *chan = ah->ah_curchan;
3608 const struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
3609 u16 ant_config;
3610 u32 halNumAntConfig;
3611
3612 halNumAntConfig = IS_CHAN_2GHZ(chan) ?
3613 pCap->num_antcfg_2ghz : pCap->num_antcfg_5ghz;
3614
3615 if (cfg < halNumAntConfig) {
3616 if (!ath9k_hw_get_eeprom_antenna_cfg(ah, chan,
3617 cfg, &ant_config)) {
3618 REG_WRITE(ah, AR_PHY_SWITCH_COM, ant_config);
3619 return 0;
3620 }
3621 }
3622
3623 return -EINVAL;
3624}
3625
3626u32 ath9k_hw_getdefantenna(struct ath_hal *ah)
3627{
3628 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
3629}
3630
3631void ath9k_hw_setantenna(struct ath_hal *ah, u32 antenna)
3632{
3633 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
3634}
3635
3636bool ath9k_hw_setantennaswitch(struct ath_hal *ah,
3637 enum ath9k_ant_setting settings,
3638 struct ath9k_channel *chan,
3639 u8 *tx_chainmask,
3640 u8 *rx_chainmask,
3641 u8 *antenna_cfgd)
3642{
3643 struct ath_hal_5416 *ahp = AH5416(ah);
3644 static u8 tx_chainmask_cfg, rx_chainmask_cfg;
3645
3646 if (AR_SREV_9280(ah)) {
3647 if (!tx_chainmask_cfg) {
3648
3649 tx_chainmask_cfg = *tx_chainmask;
3650 rx_chainmask_cfg = *rx_chainmask;
3651 }
3652
3653 switch (settings) {
3654 case ATH9K_ANT_FIXED_A:
3655 *tx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3656 *rx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3657 *antenna_cfgd = true;
3658 break;
3659 case ATH9K_ANT_FIXED_B:
3660 if (ah->ah_caps.tx_chainmask >
3661 ATH9K_ANTENNA1_CHAINMASK) {
3662 *tx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3663 }
3664 *rx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3665 *antenna_cfgd = true;
3666 break;
3667 case ATH9K_ANT_VARIABLE:
3668 *tx_chainmask = tx_chainmask_cfg;
3669 *rx_chainmask = rx_chainmask_cfg;
3670 *antenna_cfgd = true;
3671 break;
3672 default:
3673 break;
3674 }
3675 } else {
3676 ahp->ah_diversityControl = settings;
3677 }
3678
3679 return true;
3680}
3681
3682/*********************/
3683/* General Operation */
3684/*********************/
3685
3686u32 ath9k_hw_getrxfilter(struct ath_hal *ah)
3687{
3688 u32 bits = REG_READ(ah, AR_RX_FILTER);
3689 u32 phybits = REG_READ(ah, AR_PHY_ERR);
3690
3691 if (phybits & AR_PHY_ERR_RADAR)
3692 bits |= ATH9K_RX_FILTER_PHYRADAR;
3693 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
3694 bits |= ATH9K_RX_FILTER_PHYERR;
3695
3696 return bits;
3697}
3698
3699void ath9k_hw_setrxfilter(struct ath_hal *ah, u32 bits)
3700{
3701 u32 phybits;
3702
3703 REG_WRITE(ah, AR_RX_FILTER, (bits & 0xffff) | AR_RX_COMPR_BAR);
3704 phybits = 0;
3705 if (bits & ATH9K_RX_FILTER_PHYRADAR)
3706 phybits |= AR_PHY_ERR_RADAR;
3707 if (bits & ATH9K_RX_FILTER_PHYERR)
3708 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
3709 REG_WRITE(ah, AR_PHY_ERR, phybits);
3710
3711 if (phybits)
3712 REG_WRITE(ah, AR_RXCFG,
3713 REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
3714 else
3715 REG_WRITE(ah, AR_RXCFG,
3716 REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
3717}
3718
3719bool ath9k_hw_phy_disable(struct ath_hal *ah)
3720{
3721 return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM);
3722}
3723
3724bool ath9k_hw_disable(struct ath_hal *ah)
3725{
3726 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
3727 return false;
3728
3729 return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD);
3730}
3731
3732bool ath9k_hw_set_txpowerlimit(struct ath_hal *ah, u32 limit)
3733{
3734 struct ath9k_channel *chan = ah->ah_curchan;
3735
3736 ah->ah_powerLimit = min(limit, (u32) MAX_RATE_POWER);
3737
3738 if (ath9k_hw_set_txpower(ah, chan,
3739 ath9k_regd_get_ctl(ah, chan),
3740 ath9k_regd_get_antenna_allowed(ah, chan),
3741 chan->maxRegTxPower * 2,
3742 min((u32) MAX_RATE_POWER,
3743 (u32) ah->ah_powerLimit)) != 0)
3744 return false;
3745
3746 return true;
3747}
3748
3749void ath9k_hw_getmac(struct ath_hal *ah, u8 *mac)
3750{
3751 struct ath_hal_5416 *ahp = AH5416(ah);
3752
3753 memcpy(mac, ahp->ah_macaddr, ETH_ALEN);
3754}
3755
3756bool ath9k_hw_setmac(struct ath_hal *ah, const u8 *mac)
3757{
3758 struct ath_hal_5416 *ahp = AH5416(ah);
3759
3760 memcpy(ahp->ah_macaddr, mac, ETH_ALEN);
3761
3762 return true;
3763}
3764
3765void ath9k_hw_setopmode(struct ath_hal *ah)
3766{
3767 ath9k_hw_set_operating_mode(ah, ah->ah_opmode);
3768}
3769
3770void ath9k_hw_setmcastfilter(struct ath_hal *ah, u32 filter0, u32 filter1)
3771{
3772 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
3773 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
3774}
3775
3776void ath9k_hw_getbssidmask(struct ath_hal *ah, u8 *mask)
3777{
3778 struct ath_hal_5416 *ahp = AH5416(ah);
3779
3780 memcpy(mask, ahp->ah_bssidmask, ETH_ALEN);
3781}
3782
3783bool ath9k_hw_setbssidmask(struct ath_hal *ah, const u8 *mask)
3784{
3785 struct ath_hal_5416 *ahp = AH5416(ah);
3786
3787 memcpy(ahp->ah_bssidmask, mask, ETH_ALEN);
3788
3789 REG_WRITE(ah, AR_BSSMSKL, get_unaligned_le32(ahp->ah_bssidmask));
3790 REG_WRITE(ah, AR_BSSMSKU, get_unaligned_le16(ahp->ah_bssidmask + 4));
3791
3792 return true;
3793}
3794
3795void ath9k_hw_write_associd(struct ath_hal *ah, const u8 *bssid, u16 assocId)
3796{
3797 struct ath_hal_5416 *ahp = AH5416(ah);
3798
3799 memcpy(ahp->ah_bssid, bssid, ETH_ALEN);
3800 ahp->ah_assocId = assocId;
3801
3802 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(ahp->ah_bssid));
3803 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(ahp->ah_bssid + 4) |
3804 ((assocId & 0x3fff) << AR_BSS_ID1_AID_S));
3805}
3806
3807u64 ath9k_hw_gettsf64(struct ath_hal *ah)
3808{
3809 u64 tsf;
3810
3811 tsf = REG_READ(ah, AR_TSF_U32);
3812 tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
3813
3814 return tsf;
3815}
3816
3817void ath9k_hw_reset_tsf(struct ath_hal *ah)
3818{
3819 int count;
3820
3821 count = 0;
3822 while (REG_READ(ah, AR_SLP32_MODE) & AR_SLP32_TSF_WRITE_STATUS) {
3823 count++;
3824 if (count > 10) {
3825 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
3826 "%s: AR_SLP32_TSF_WRITE_STATUS limit exceeded\n",
3827 __func__);
3828 break;
3829 }
3830 udelay(10);
3831 }
3832 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003833}
3834
3835bool ath9k_hw_set_tsfadjust(struct ath_hal *ah, u32 setting)
3836{
3837 struct ath_hal_5416 *ahp = AH5416(ah);
3838
3839 if (setting)
3840 ahp->ah_miscMode |= AR_PCU_TX_ADD_TSF;
3841 else
3842 ahp->ah_miscMode &= ~AR_PCU_TX_ADD_TSF;
Sujithf1dc5602008-10-29 10:16:30 +05303843
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003844 return true;
3845}
3846
Sujithf1dc5602008-10-29 10:16:30 +05303847bool ath9k_hw_setslottime(struct ath_hal *ah, u32 us)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003848{
3849 struct ath_hal_5416 *ahp = AH5416(ah);
3850
Sujithf1dc5602008-10-29 10:16:30 +05303851 if (us < ATH9K_SLOT_TIME_9 || us > ath9k_hw_mac_to_usec(ah, 0xffff)) {
3852 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "%s: bad slot time %u\n",
3853 __func__, us);
3854 ahp->ah_slottime = (u32) -1;
3855 return false;
3856 } else {
3857 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, ath9k_hw_mac_to_clks(ah, us));
3858 ahp->ah_slottime = us;
3859 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003860 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003861}
3862
Sujithf1dc5602008-10-29 10:16:30 +05303863void ath9k_hw_set11nmac2040(struct ath_hal *ah, enum ath9k_ht_macmode mode)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003864{
Sujithf1dc5602008-10-29 10:16:30 +05303865 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003866
Sujithf1dc5602008-10-29 10:16:30 +05303867 if (mode == ATH9K_HT_MACMODE_2040 &&
3868 !ah->ah_config.cwm_ignore_extcca)
3869 macmode = AR_2040_JOINED_RX_CLEAR;
3870 else
3871 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003872
Sujithf1dc5602008-10-29 10:16:30 +05303873 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003874}