2 * Copyright (c) 2008 Atheros Communications Inc.
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.
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.
18 #include <asm/unaligned.h>
26 static int btcoex_enable;
27 module_param(btcoex_enable, bool, 0);
28 MODULE_PARM_DESC(btcoex_enable, "Enable Bluetooth coexistence support");
30 #define ATH9K_CLOCK_RATE_CCK 22
31 #define ATH9K_CLOCK_RATE_5GHZ_OFDM 40
32 #define ATH9K_CLOCK_RATE_2GHZ_OFDM 44
34 static bool ath9k_hw_set_reset_reg(struct ath_hal *ah, u32 type);
35 static void ath9k_hw_set_regs(struct ath_hal *ah, struct ath9k_channel *chan,
36 enum ath9k_ht_macmode macmode);
37 static u32 ath9k_hw_ini_fixup(struct ath_hal *ah,
38 struct ar5416_eeprom_def *pEepData,
40 static void ath9k_hw_9280_spur_mitigate(struct ath_hal *ah, struct ath9k_channel *chan);
41 static void ath9k_hw_spur_mitigate(struct ath_hal *ah, struct ath9k_channel *chan);
43 /********************/
44 /* Helper Functions */
45 /********************/
47 static u32 ath9k_hw_mac_usec(struct ath_hal *ah, u32 clks)
49 struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
50 if (!ah->ah_curchan) /* should really check for CCK instead */
51 return clks / ATH9K_CLOCK_RATE_CCK;
52 if (conf->channel->band == IEEE80211_BAND_2GHZ)
53 return clks / ATH9K_CLOCK_RATE_2GHZ_OFDM;
54 return clks / ATH9K_CLOCK_RATE_5GHZ_OFDM;
57 static u32 ath9k_hw_mac_to_usec(struct ath_hal *ah, u32 clks)
59 struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
60 if (conf_is_ht40(conf))
61 return ath9k_hw_mac_usec(ah, clks) / 2;
63 return ath9k_hw_mac_usec(ah, clks);
66 static u32 ath9k_hw_mac_clks(struct ath_hal *ah, u32 usecs)
68 struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
69 if (!ah->ah_curchan) /* should really check for CCK instead */
70 return usecs *ATH9K_CLOCK_RATE_CCK;
71 if (conf->channel->band == IEEE80211_BAND_2GHZ)
72 return usecs *ATH9K_CLOCK_RATE_2GHZ_OFDM;
73 return usecs *ATH9K_CLOCK_RATE_5GHZ_OFDM;
76 static u32 ath9k_hw_mac_to_clks(struct ath_hal *ah, u32 usecs)
78 struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
79 if (conf_is_ht40(conf))
80 return ath9k_hw_mac_clks(ah, usecs) * 2;
82 return ath9k_hw_mac_clks(ah, usecs);
85 bool ath9k_hw_wait(struct ath_hal *ah, u32 reg, u32 mask, u32 val)
89 for (i = 0; i < (AH_TIMEOUT / AH_TIME_QUANTUM); i++) {
90 if ((REG_READ(ah, reg) & mask) == val)
93 udelay(AH_TIME_QUANTUM);
96 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
97 "timeout on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
98 reg, REG_READ(ah, reg), mask, val);
103 u32 ath9k_hw_reverse_bits(u32 val, u32 n)
108 for (i = 0, retval = 0; i < n; i++) {
109 retval = (retval << 1) | (val & 1);
115 bool ath9k_get_channel_edges(struct ath_hal *ah,
119 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
121 if (flags & CHANNEL_5GHZ) {
122 *low = pCap->low_5ghz_chan;
123 *high = pCap->high_5ghz_chan;
126 if ((flags & CHANNEL_2GHZ)) {
127 *low = pCap->low_2ghz_chan;
128 *high = pCap->high_2ghz_chan;
134 u16 ath9k_hw_computetxtime(struct ath_hal *ah,
135 struct ath_rate_table *rates,
136 u32 frameLen, u16 rateix,
139 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
142 kbps = rates->info[rateix].ratekbps;
147 switch (rates->info[rateix].phy) {
148 case WLAN_RC_PHY_CCK:
149 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
150 if (shortPreamble && rates->info[rateix].short_preamble)
152 numBits = frameLen << 3;
153 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
155 case WLAN_RC_PHY_OFDM:
156 if (ah->ah_curchan && IS_CHAN_QUARTER_RATE(ah->ah_curchan)) {
157 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
158 numBits = OFDM_PLCP_BITS + (frameLen << 3);
159 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
160 txTime = OFDM_SIFS_TIME_QUARTER
161 + OFDM_PREAMBLE_TIME_QUARTER
162 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
163 } else if (ah->ah_curchan &&
164 IS_CHAN_HALF_RATE(ah->ah_curchan)) {
165 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
166 numBits = OFDM_PLCP_BITS + (frameLen << 3);
167 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
168 txTime = OFDM_SIFS_TIME_HALF +
169 OFDM_PREAMBLE_TIME_HALF
170 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
172 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
173 numBits = OFDM_PLCP_BITS + (frameLen << 3);
174 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
175 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
176 + (numSymbols * OFDM_SYMBOL_TIME);
180 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
181 "Unknown phy %u (rate ix %u)\n",
182 rates->info[rateix].phy, rateix);
190 void ath9k_hw_get_channel_centers(struct ath_hal *ah,
191 struct ath9k_channel *chan,
192 struct chan_centers *centers)
195 struct ath_hal_5416 *ahp = AH5416(ah);
197 if (!IS_CHAN_HT40(chan)) {
198 centers->ctl_center = centers->ext_center =
199 centers->synth_center = chan->channel;
203 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
204 (chan->chanmode == CHANNEL_G_HT40PLUS)) {
205 centers->synth_center =
206 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
209 centers->synth_center =
210 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
214 centers->ctl_center =
215 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
216 centers->ext_center =
217 centers->synth_center + (extoff *
218 ((ahp->ah_extprotspacing == ATH9K_HT_EXTPROTSPACING_20) ?
219 HT40_CHANNEL_CENTER_SHIFT : 15));
227 static void ath9k_hw_read_revisions(struct ath_hal *ah)
231 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
234 val = REG_READ(ah, AR_SREV);
235 ah->ah_macVersion = (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
236 ah->ah_macRev = MS(val, AR_SREV_REVISION2);
237 ah->ah_isPciExpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
239 if (!AR_SREV_9100(ah))
240 ah->ah_macVersion = MS(val, AR_SREV_VERSION);
242 ah->ah_macRev = val & AR_SREV_REVISION;
244 if (ah->ah_macVersion == AR_SREV_VERSION_5416_PCIE)
245 ah->ah_isPciExpress = true;
249 static int ath9k_hw_get_radiorev(struct ath_hal *ah)
254 REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
256 for (i = 0; i < 8; i++)
257 REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
258 val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
259 val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
261 return ath9k_hw_reverse_bits(val, 8);
264 /************************************/
265 /* HW Attach, Detach, Init Routines */
266 /************************************/
268 static void ath9k_hw_disablepcie(struct ath_hal *ah)
270 if (AR_SREV_9100(ah))
273 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
274 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
275 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
276 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
277 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
278 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
279 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
280 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
281 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
283 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
286 static bool ath9k_hw_chip_test(struct ath_hal *ah)
288 u32 regAddr[2] = { AR_STA_ID0, AR_PHY_BASE + (8 << 2) };
290 u32 patternData[4] = { 0x55555555,
296 for (i = 0; i < 2; i++) {
297 u32 addr = regAddr[i];
300 regHold[i] = REG_READ(ah, addr);
301 for (j = 0; j < 0x100; j++) {
302 wrData = (j << 16) | j;
303 REG_WRITE(ah, addr, wrData);
304 rdData = REG_READ(ah, addr);
305 if (rdData != wrData) {
306 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
307 "address test failed "
308 "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
309 addr, wrData, rdData);
313 for (j = 0; j < 4; j++) {
314 wrData = patternData[j];
315 REG_WRITE(ah, addr, wrData);
316 rdData = REG_READ(ah, addr);
317 if (wrData != rdData) {
318 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
319 "address test failed "
320 "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
321 addr, wrData, rdData);
325 REG_WRITE(ah, regAddr[i], regHold[i]);
331 static const char *ath9k_hw_devname(u16 devid)
334 case AR5416_DEVID_PCI:
335 return "Atheros 5416";
336 case AR5416_DEVID_PCIE:
337 return "Atheros 5418";
338 case AR9160_DEVID_PCI:
339 return "Atheros 9160";
340 case AR5416_AR9100_DEVID:
341 return "Atheros 9100";
342 case AR9280_DEVID_PCI:
343 case AR9280_DEVID_PCIE:
344 return "Atheros 9280";
345 case AR9285_DEVID_PCIE:
346 return "Atheros 9285";
352 static void ath9k_hw_set_defaults(struct ath_hal *ah)
356 ah->ah_config.dma_beacon_response_time = 2;
357 ah->ah_config.sw_beacon_response_time = 10;
358 ah->ah_config.additional_swba_backoff = 0;
359 ah->ah_config.ack_6mb = 0x0;
360 ah->ah_config.cwm_ignore_extcca = 0;
361 ah->ah_config.pcie_powersave_enable = 0;
362 ah->ah_config.pcie_l1skp_enable = 0;
363 ah->ah_config.pcie_clock_req = 0;
364 ah->ah_config.pcie_power_reset = 0x100;
365 ah->ah_config.pcie_restore = 0;
366 ah->ah_config.pcie_waen = 0;
367 ah->ah_config.analog_shiftreg = 1;
368 ah->ah_config.ht_enable = 1;
369 ah->ah_config.ofdm_trig_low = 200;
370 ah->ah_config.ofdm_trig_high = 500;
371 ah->ah_config.cck_trig_high = 200;
372 ah->ah_config.cck_trig_low = 100;
373 ah->ah_config.enable_ani = 1;
374 ah->ah_config.noise_immunity_level = 4;
375 ah->ah_config.ofdm_weaksignal_det = 1;
376 ah->ah_config.cck_weaksignal_thr = 0;
377 ah->ah_config.spur_immunity_level = 2;
378 ah->ah_config.firstep_level = 0;
379 ah->ah_config.rssi_thr_high = 40;
380 ah->ah_config.rssi_thr_low = 7;
381 ah->ah_config.diversity_control = 0;
382 ah->ah_config.antenna_switch_swap = 0;
384 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
385 ah->ah_config.spurchans[i][0] = AR_NO_SPUR;
386 ah->ah_config.spurchans[i][1] = AR_NO_SPUR;
389 ah->ah_config.intr_mitigation = 1;
392 static struct ath_hal_5416 *ath9k_hw_newstate(u16 devid,
393 struct ath_softc *sc,
397 static const u8 defbssidmask[ETH_ALEN] =
398 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
399 struct ath_hal_5416 *ahp;
402 ahp = kzalloc(sizeof(struct ath_hal_5416), GFP_KERNEL);
404 DPRINTF(sc, ATH_DBG_FATAL,
405 "Cannot allocate memory for state block\n");
413 ah->ah_magic = AR5416_MAGIC;
414 ah->ah_countryCode = CTRY_DEFAULT;
415 ah->ah_devid = devid;
416 ah->ah_subvendorid = 0;
419 if ((devid == AR5416_AR9100_DEVID))
420 ah->ah_macVersion = AR_SREV_VERSION_9100;
421 if (!AR_SREV_9100(ah))
422 ah->ah_flags = AH_USE_EEPROM;
424 ah->ah_powerLimit = MAX_RATE_POWER;
425 ah->ah_tpScale = ATH9K_TP_SCALE_MAX;
426 ahp->ah_atimWindow = 0;
427 ahp->ah_diversityControl = ah->ah_config.diversity_control;
428 ahp->ah_antennaSwitchSwap =
429 ah->ah_config.antenna_switch_swap;
430 ahp->ah_staId1Defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
431 ahp->ah_beaconInterval = 100;
432 ahp->ah_enable32kHzClock = DONT_USE_32KHZ;
433 ahp->ah_slottime = (u32) -1;
434 ahp->ah_acktimeout = (u32) -1;
435 ahp->ah_ctstimeout = (u32) -1;
436 ahp->ah_globaltxtimeout = (u32) -1;
437 memcpy(&ahp->ah_bssidmask, defbssidmask, ETH_ALEN);
439 ahp->ah_gBeaconRate = 0;
444 static int ath9k_hw_rfattach(struct ath_hal *ah)
446 bool rfStatus = false;
449 rfStatus = ath9k_hw_init_rf(ah, &ecode);
451 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
452 "RF setup failed, status %u\n", ecode);
459 static int ath9k_hw_rf_claim(struct ath_hal *ah)
463 REG_WRITE(ah, AR_PHY(0), 0x00000007);
465 val = ath9k_hw_get_radiorev(ah);
466 switch (val & AR_RADIO_SREV_MAJOR) {
468 val = AR_RAD5133_SREV_MAJOR;
470 case AR_RAD5133_SREV_MAJOR:
471 case AR_RAD5122_SREV_MAJOR:
472 case AR_RAD2133_SREV_MAJOR:
473 case AR_RAD2122_SREV_MAJOR:
476 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
477 "5G Radio Chip Rev 0x%02X is not "
478 "supported by this driver\n",
479 ah->ah_analog5GhzRev);
483 ah->ah_analog5GhzRev = val;
488 static int ath9k_hw_init_macaddr(struct ath_hal *ah)
493 struct ath_hal_5416 *ahp = AH5416(ah);
496 for (i = 0; i < 3; i++) {
497 eeval = ath9k_hw_get_eeprom(ah, AR_EEPROM_MAC(i));
499 ahp->ah_macaddr[2 * i] = eeval >> 8;
500 ahp->ah_macaddr[2 * i + 1] = eeval & 0xff;
502 if (sum == 0 || sum == 0xffff * 3) {
503 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
504 "mac address read failed: %pM\n",
506 return -EADDRNOTAVAIL;
512 static void ath9k_hw_init_rxgain_ini(struct ath_hal *ah)
515 struct ath_hal_5416 *ahp = AH5416(ah);
517 if (ath9k_hw_get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_17) {
518 rxgain_type = ath9k_hw_get_eeprom(ah, EEP_RXGAIN_TYPE);
520 if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
521 INIT_INI_ARRAY(&ahp->ah_iniModesRxGain,
522 ar9280Modes_backoff_13db_rxgain_9280_2,
523 ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2), 6);
524 else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF)
525 INIT_INI_ARRAY(&ahp->ah_iniModesRxGain,
526 ar9280Modes_backoff_23db_rxgain_9280_2,
527 ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 6);
529 INIT_INI_ARRAY(&ahp->ah_iniModesRxGain,
530 ar9280Modes_original_rxgain_9280_2,
531 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
533 INIT_INI_ARRAY(&ahp->ah_iniModesRxGain,
534 ar9280Modes_original_rxgain_9280_2,
535 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
538 static void ath9k_hw_init_txgain_ini(struct ath_hal *ah)
541 struct ath_hal_5416 *ahp = AH5416(ah);
543 if (ath9k_hw_get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_19) {
544 txgain_type = ath9k_hw_get_eeprom(ah, EEP_TXGAIN_TYPE);
546 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
547 INIT_INI_ARRAY(&ahp->ah_iniModesTxGain,
548 ar9280Modes_high_power_tx_gain_9280_2,
549 ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 6);
551 INIT_INI_ARRAY(&ahp->ah_iniModesTxGain,
552 ar9280Modes_original_tx_gain_9280_2,
553 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
555 INIT_INI_ARRAY(&ahp->ah_iniModesTxGain,
556 ar9280Modes_original_tx_gain_9280_2,
557 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
560 static int ath9k_hw_post_attach(struct ath_hal *ah)
564 if (!ath9k_hw_chip_test(ah)) {
565 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
566 "hardware self-test failed\n");
570 ecode = ath9k_hw_rf_claim(ah);
574 ecode = ath9k_hw_eeprom_attach(ah);
577 ecode = ath9k_hw_rfattach(ah);
581 if (!AR_SREV_9100(ah)) {
582 ath9k_hw_ani_setup(ah);
583 ath9k_hw_ani_attach(ah);
589 static struct ath_hal *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc,
590 void __iomem *mem, int *status)
592 struct ath_hal_5416 *ahp;
597 ahp = ath9k_hw_newstate(devid, sc, mem, status);
603 ath9k_hw_set_defaults(ah);
605 if (ah->ah_config.intr_mitigation != 0)
606 ahp->ah_intrMitigation = true;
608 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
609 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "Couldn't reset chip\n");
614 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
615 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "Couldn't wakeup chip\n");
620 if (ah->ah_config.serialize_regmode == SER_REG_MODE_AUTO) {
621 if (ah->ah_macVersion == AR_SREV_VERSION_5416_PCI) {
622 ah->ah_config.serialize_regmode =
625 ah->ah_config.serialize_regmode =
630 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
631 "serialize_regmode is %d\n",
632 ah->ah_config.serialize_regmode);
634 if ((ah->ah_macVersion != AR_SREV_VERSION_5416_PCI) &&
635 (ah->ah_macVersion != AR_SREV_VERSION_5416_PCIE) &&
636 (ah->ah_macVersion != AR_SREV_VERSION_9160) &&
637 (!AR_SREV_9100(ah)) && (!AR_SREV_9280(ah)) && (!AR_SREV_9285(ah))) {
638 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
639 "Mac Chip Rev 0x%02x.%x is not supported by "
640 "this driver\n", ah->ah_macVersion, ah->ah_macRev);
645 if (AR_SREV_9100(ah)) {
646 ahp->ah_iqCalData.calData = &iq_cal_multi_sample;
647 ahp->ah_suppCals = IQ_MISMATCH_CAL;
648 ah->ah_isPciExpress = false;
650 ah->ah_phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
652 if (AR_SREV_9160_10_OR_LATER(ah)) {
653 if (AR_SREV_9280_10_OR_LATER(ah)) {
654 ahp->ah_iqCalData.calData = &iq_cal_single_sample;
655 ahp->ah_adcGainCalData.calData =
656 &adc_gain_cal_single_sample;
657 ahp->ah_adcDcCalData.calData =
658 &adc_dc_cal_single_sample;
659 ahp->ah_adcDcCalInitData.calData =
662 ahp->ah_iqCalData.calData = &iq_cal_multi_sample;
663 ahp->ah_adcGainCalData.calData =
664 &adc_gain_cal_multi_sample;
665 ahp->ah_adcDcCalData.calData =
666 &adc_dc_cal_multi_sample;
667 ahp->ah_adcDcCalInitData.calData =
670 ahp->ah_suppCals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
673 if (AR_SREV_9160(ah)) {
674 ah->ah_config.enable_ani = 1;
675 ahp->ah_ani_function = (ATH9K_ANI_SPUR_IMMUNITY_LEVEL |
676 ATH9K_ANI_FIRSTEP_LEVEL);
678 ahp->ah_ani_function = ATH9K_ANI_ALL;
679 if (AR_SREV_9280_10_OR_LATER(ah)) {
680 ahp->ah_ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
684 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
685 "This Mac Chip Rev 0x%02x.%x is \n",
686 ah->ah_macVersion, ah->ah_macRev);
688 if (AR_SREV_9285_12_OR_LATER(ah)) {
689 INIT_INI_ARRAY(&ahp->ah_iniModes, ar9285Modes_9285_1_2,
690 ARRAY_SIZE(ar9285Modes_9285_1_2), 6);
691 INIT_INI_ARRAY(&ahp->ah_iniCommon, ar9285Common_9285_1_2,
692 ARRAY_SIZE(ar9285Common_9285_1_2), 2);
694 if (ah->ah_config.pcie_clock_req) {
695 INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
696 ar9285PciePhy_clkreq_off_L1_9285_1_2,
697 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2);
699 INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
700 ar9285PciePhy_clkreq_always_on_L1_9285_1_2,
701 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2),
704 } else if (AR_SREV_9285_10_OR_LATER(ah)) {
705 INIT_INI_ARRAY(&ahp->ah_iniModes, ar9285Modes_9285,
706 ARRAY_SIZE(ar9285Modes_9285), 6);
707 INIT_INI_ARRAY(&ahp->ah_iniCommon, ar9285Common_9285,
708 ARRAY_SIZE(ar9285Common_9285), 2);
710 if (ah->ah_config.pcie_clock_req) {
711 INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
712 ar9285PciePhy_clkreq_off_L1_9285,
713 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2);
715 INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
716 ar9285PciePhy_clkreq_always_on_L1_9285,
717 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285), 2);
719 } else if (AR_SREV_9280_20_OR_LATER(ah)) {
720 INIT_INI_ARRAY(&ahp->ah_iniModes, ar9280Modes_9280_2,
721 ARRAY_SIZE(ar9280Modes_9280_2), 6);
722 INIT_INI_ARRAY(&ahp->ah_iniCommon, ar9280Common_9280_2,
723 ARRAY_SIZE(ar9280Common_9280_2), 2);
725 if (ah->ah_config.pcie_clock_req) {
726 INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
727 ar9280PciePhy_clkreq_off_L1_9280,
728 ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2);
730 INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
731 ar9280PciePhy_clkreq_always_on_L1_9280,
732 ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
734 INIT_INI_ARRAY(&ahp->ah_iniModesAdditional,
735 ar9280Modes_fast_clock_9280_2,
736 ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
737 } else if (AR_SREV_9280_10_OR_LATER(ah)) {
738 INIT_INI_ARRAY(&ahp->ah_iniModes, ar9280Modes_9280,
739 ARRAY_SIZE(ar9280Modes_9280), 6);
740 INIT_INI_ARRAY(&ahp->ah_iniCommon, ar9280Common_9280,
741 ARRAY_SIZE(ar9280Common_9280), 2);
742 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
743 INIT_INI_ARRAY(&ahp->ah_iniModes, ar5416Modes_9160,
744 ARRAY_SIZE(ar5416Modes_9160), 6);
745 INIT_INI_ARRAY(&ahp->ah_iniCommon, ar5416Common_9160,
746 ARRAY_SIZE(ar5416Common_9160), 2);
747 INIT_INI_ARRAY(&ahp->ah_iniBank0, ar5416Bank0_9160,
748 ARRAY_SIZE(ar5416Bank0_9160), 2);
749 INIT_INI_ARRAY(&ahp->ah_iniBB_RfGain, ar5416BB_RfGain_9160,
750 ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
751 INIT_INI_ARRAY(&ahp->ah_iniBank1, ar5416Bank1_9160,
752 ARRAY_SIZE(ar5416Bank1_9160), 2);
753 INIT_INI_ARRAY(&ahp->ah_iniBank2, ar5416Bank2_9160,
754 ARRAY_SIZE(ar5416Bank2_9160), 2);
755 INIT_INI_ARRAY(&ahp->ah_iniBank3, ar5416Bank3_9160,
756 ARRAY_SIZE(ar5416Bank3_9160), 3);
757 INIT_INI_ARRAY(&ahp->ah_iniBank6, ar5416Bank6_9160,
758 ARRAY_SIZE(ar5416Bank6_9160), 3);
759 INIT_INI_ARRAY(&ahp->ah_iniBank6TPC, ar5416Bank6TPC_9160,
760 ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
761 INIT_INI_ARRAY(&ahp->ah_iniBank7, ar5416Bank7_9160,
762 ARRAY_SIZE(ar5416Bank7_9160), 2);
763 if (AR_SREV_9160_11(ah)) {
764 INIT_INI_ARRAY(&ahp->ah_iniAddac,
766 ARRAY_SIZE(ar5416Addac_91601_1), 2);
768 INIT_INI_ARRAY(&ahp->ah_iniAddac, ar5416Addac_9160,
769 ARRAY_SIZE(ar5416Addac_9160), 2);
771 } else if (AR_SREV_9100_OR_LATER(ah)) {
772 INIT_INI_ARRAY(&ahp->ah_iniModes, ar5416Modes_9100,
773 ARRAY_SIZE(ar5416Modes_9100), 6);
774 INIT_INI_ARRAY(&ahp->ah_iniCommon, ar5416Common_9100,
775 ARRAY_SIZE(ar5416Common_9100), 2);
776 INIT_INI_ARRAY(&ahp->ah_iniBank0, ar5416Bank0_9100,
777 ARRAY_SIZE(ar5416Bank0_9100), 2);
778 INIT_INI_ARRAY(&ahp->ah_iniBB_RfGain, ar5416BB_RfGain_9100,
779 ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
780 INIT_INI_ARRAY(&ahp->ah_iniBank1, ar5416Bank1_9100,
781 ARRAY_SIZE(ar5416Bank1_9100), 2);
782 INIT_INI_ARRAY(&ahp->ah_iniBank2, ar5416Bank2_9100,
783 ARRAY_SIZE(ar5416Bank2_9100), 2);
784 INIT_INI_ARRAY(&ahp->ah_iniBank3, ar5416Bank3_9100,
785 ARRAY_SIZE(ar5416Bank3_9100), 3);
786 INIT_INI_ARRAY(&ahp->ah_iniBank6, ar5416Bank6_9100,
787 ARRAY_SIZE(ar5416Bank6_9100), 3);
788 INIT_INI_ARRAY(&ahp->ah_iniBank6TPC, ar5416Bank6TPC_9100,
789 ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
790 INIT_INI_ARRAY(&ahp->ah_iniBank7, ar5416Bank7_9100,
791 ARRAY_SIZE(ar5416Bank7_9100), 2);
792 INIT_INI_ARRAY(&ahp->ah_iniAddac, ar5416Addac_9100,
793 ARRAY_SIZE(ar5416Addac_9100), 2);
795 INIT_INI_ARRAY(&ahp->ah_iniModes, ar5416Modes,
796 ARRAY_SIZE(ar5416Modes), 6);
797 INIT_INI_ARRAY(&ahp->ah_iniCommon, ar5416Common,
798 ARRAY_SIZE(ar5416Common), 2);
799 INIT_INI_ARRAY(&ahp->ah_iniBank0, ar5416Bank0,
800 ARRAY_SIZE(ar5416Bank0), 2);
801 INIT_INI_ARRAY(&ahp->ah_iniBB_RfGain, ar5416BB_RfGain,
802 ARRAY_SIZE(ar5416BB_RfGain), 3);
803 INIT_INI_ARRAY(&ahp->ah_iniBank1, ar5416Bank1,
804 ARRAY_SIZE(ar5416Bank1), 2);
805 INIT_INI_ARRAY(&ahp->ah_iniBank2, ar5416Bank2,
806 ARRAY_SIZE(ar5416Bank2), 2);
807 INIT_INI_ARRAY(&ahp->ah_iniBank3, ar5416Bank3,
808 ARRAY_SIZE(ar5416Bank3), 3);
809 INIT_INI_ARRAY(&ahp->ah_iniBank6, ar5416Bank6,
810 ARRAY_SIZE(ar5416Bank6), 3);
811 INIT_INI_ARRAY(&ahp->ah_iniBank6TPC, ar5416Bank6TPC,
812 ARRAY_SIZE(ar5416Bank6TPC), 3);
813 INIT_INI_ARRAY(&ahp->ah_iniBank7, ar5416Bank7,
814 ARRAY_SIZE(ar5416Bank7), 2);
815 INIT_INI_ARRAY(&ahp->ah_iniAddac, ar5416Addac,
816 ARRAY_SIZE(ar5416Addac), 2);
819 if (ah->ah_isPciExpress)
820 ath9k_hw_configpcipowersave(ah, 0);
822 ath9k_hw_disablepcie(ah);
824 ecode = ath9k_hw_post_attach(ah);
829 if (AR_SREV_9280_20(ah))
830 ath9k_hw_init_rxgain_ini(ah);
833 if (AR_SREV_9280_20(ah))
834 ath9k_hw_init_txgain_ini(ah);
836 if (ah->ah_devid == AR9280_DEVID_PCI) {
837 for (i = 0; i < ahp->ah_iniModes.ia_rows; i++) {
838 u32 reg = INI_RA(&ahp->ah_iniModes, i, 0);
840 for (j = 1; j < ahp->ah_iniModes.ia_columns; j++) {
841 u32 val = INI_RA(&ahp->ah_iniModes, i, j);
843 INI_RA(&ahp->ah_iniModes, i, j) =
844 ath9k_hw_ini_fixup(ah,
851 if (!ath9k_hw_fill_cap_info(ah)) {
852 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
853 "failed ath9k_hw_fill_cap_info\n");
858 ecode = ath9k_hw_init_macaddr(ah);
860 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
861 "failed initializing mac address\n");
865 if (AR_SREV_9285(ah))
866 ah->ah_txTrigLevel = (AR_FTRIG_256B >> AR_FTRIG_S);
868 ah->ah_txTrigLevel = (AR_FTRIG_512B >> AR_FTRIG_S);
870 ath9k_init_nfcal_hist_buffer(ah);
875 ath9k_hw_detach((struct ath_hal *) ahp);
882 static void ath9k_hw_init_bb(struct ath_hal *ah,
883 struct ath9k_channel *chan)
887 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
889 synthDelay = (4 * synthDelay) / 22;
893 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
895 udelay(synthDelay + BASE_ACTIVATE_DELAY);
898 static void ath9k_hw_init_qos(struct ath_hal *ah)
900 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
901 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
903 REG_WRITE(ah, AR_QOS_NO_ACK,
904 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
905 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
906 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
908 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
909 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
910 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
911 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
912 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
915 static void ath9k_hw_init_pll(struct ath_hal *ah,
916 struct ath9k_channel *chan)
920 if (AR_SREV_9100(ah)) {
921 if (chan && IS_CHAN_5GHZ(chan))
926 if (AR_SREV_9280_10_OR_LATER(ah)) {
927 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
929 if (chan && IS_CHAN_HALF_RATE(chan))
930 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
931 else if (chan && IS_CHAN_QUARTER_RATE(chan))
932 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
934 if (chan && IS_CHAN_5GHZ(chan)) {
935 pll |= SM(0x28, AR_RTC_9160_PLL_DIV);
938 if (AR_SREV_9280_20(ah)) {
939 if (((chan->channel % 20) == 0)
940 || ((chan->channel % 10) == 0))
946 pll |= SM(0x2c, AR_RTC_9160_PLL_DIV);
949 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
951 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
953 if (chan && IS_CHAN_HALF_RATE(chan))
954 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
955 else if (chan && IS_CHAN_QUARTER_RATE(chan))
956 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
958 if (chan && IS_CHAN_5GHZ(chan))
959 pll |= SM(0x50, AR_RTC_9160_PLL_DIV);
961 pll |= SM(0x58, AR_RTC_9160_PLL_DIV);
963 pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2;
965 if (chan && IS_CHAN_HALF_RATE(chan))
966 pll |= SM(0x1, AR_RTC_PLL_CLKSEL);
967 else if (chan && IS_CHAN_QUARTER_RATE(chan))
968 pll |= SM(0x2, AR_RTC_PLL_CLKSEL);
970 if (chan && IS_CHAN_5GHZ(chan))
971 pll |= SM(0xa, AR_RTC_PLL_DIV);
973 pll |= SM(0xb, AR_RTC_PLL_DIV);
976 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
978 udelay(RTC_PLL_SETTLE_DELAY);
980 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
983 static void ath9k_hw_init_chain_masks(struct ath_hal *ah)
985 struct ath_hal_5416 *ahp = AH5416(ah);
986 int rx_chainmask, tx_chainmask;
988 rx_chainmask = ahp->ah_rxchainmask;
989 tx_chainmask = ahp->ah_txchainmask;
991 switch (rx_chainmask) {
993 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
994 AR_PHY_SWAP_ALT_CHAIN);
996 if (((ah)->ah_macVersion <= AR_SREV_VERSION_9160)) {
997 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7);
998 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7);
1004 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
1005 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
1011 REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);
1012 if (tx_chainmask == 0x5) {
1013 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1014 AR_PHY_SWAP_ALT_CHAIN);
1016 if (AR_SREV_9100(ah))
1017 REG_WRITE(ah, AR_PHY_ANALOG_SWAP,
1018 REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
1021 static void ath9k_hw_init_interrupt_masks(struct ath_hal *ah,
1022 enum nl80211_iftype opmode)
1024 struct ath_hal_5416 *ahp = AH5416(ah);
1026 ahp->ah_maskReg = AR_IMR_TXERR |
1032 if (ahp->ah_intrMitigation)
1033 ahp->ah_maskReg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
1035 ahp->ah_maskReg |= AR_IMR_RXOK;
1037 ahp->ah_maskReg |= AR_IMR_TXOK;
1039 if (opmode == NL80211_IFTYPE_AP)
1040 ahp->ah_maskReg |= AR_IMR_MIB;
1042 REG_WRITE(ah, AR_IMR, ahp->ah_maskReg);
1043 REG_WRITE(ah, AR_IMR_S2, REG_READ(ah, AR_IMR_S2) | AR_IMR_S2_GTT);
1045 if (!AR_SREV_9100(ah)) {
1046 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
1047 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
1048 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
1052 static bool ath9k_hw_set_ack_timeout(struct ath_hal *ah, u32 us)
1054 struct ath_hal_5416 *ahp = AH5416(ah);
1056 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) {
1057 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "bad ack timeout %u\n", us);
1058 ahp->ah_acktimeout = (u32) -1;
1061 REG_RMW_FIELD(ah, AR_TIME_OUT,
1062 AR_TIME_OUT_ACK, ath9k_hw_mac_to_clks(ah, us));
1063 ahp->ah_acktimeout = us;
1068 static bool ath9k_hw_set_cts_timeout(struct ath_hal *ah, u32 us)
1070 struct ath_hal_5416 *ahp = AH5416(ah);
1072 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_CTS))) {
1073 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "bad cts timeout %u\n", us);
1074 ahp->ah_ctstimeout = (u32) -1;
1077 REG_RMW_FIELD(ah, AR_TIME_OUT,
1078 AR_TIME_OUT_CTS, ath9k_hw_mac_to_clks(ah, us));
1079 ahp->ah_ctstimeout = us;
1084 static bool ath9k_hw_set_global_txtimeout(struct ath_hal *ah, u32 tu)
1086 struct ath_hal_5416 *ahp = AH5416(ah);
1089 DPRINTF(ah->ah_sc, ATH_DBG_XMIT,
1090 "bad global tx timeout %u\n", tu);
1091 ahp->ah_globaltxtimeout = (u32) -1;
1094 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
1095 ahp->ah_globaltxtimeout = tu;
1100 static void ath9k_hw_init_user_settings(struct ath_hal *ah)
1102 struct ath_hal_5416 *ahp = AH5416(ah);
1104 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "ahp->ah_miscMode 0x%x\n",
1107 if (ahp->ah_miscMode != 0)
1108 REG_WRITE(ah, AR_PCU_MISC,
1109 REG_READ(ah, AR_PCU_MISC) | ahp->ah_miscMode);
1110 if (ahp->ah_slottime != (u32) -1)
1111 ath9k_hw_setslottime(ah, ahp->ah_slottime);
1112 if (ahp->ah_acktimeout != (u32) -1)
1113 ath9k_hw_set_ack_timeout(ah, ahp->ah_acktimeout);
1114 if (ahp->ah_ctstimeout != (u32) -1)
1115 ath9k_hw_set_cts_timeout(ah, ahp->ah_ctstimeout);
1116 if (ahp->ah_globaltxtimeout != (u32) -1)
1117 ath9k_hw_set_global_txtimeout(ah, ahp->ah_globaltxtimeout);
1120 const char *ath9k_hw_probe(u16 vendorid, u16 devid)
1122 return vendorid == ATHEROS_VENDOR_ID ?
1123 ath9k_hw_devname(devid) : NULL;
1126 void ath9k_hw_detach(struct ath_hal *ah)
1128 if (!AR_SREV_9100(ah))
1129 ath9k_hw_ani_detach(ah);
1131 ath9k_hw_rfdetach(ah);
1132 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
1136 struct ath_hal *ath9k_hw_attach(u16 devid, struct ath_softc *sc,
1137 void __iomem *mem, int *error)
1139 struct ath_hal *ah = NULL;
1142 case AR5416_DEVID_PCI:
1143 case AR5416_DEVID_PCIE:
1144 case AR5416_AR9100_DEVID:
1145 case AR9160_DEVID_PCI:
1146 case AR9280_DEVID_PCI:
1147 case AR9280_DEVID_PCIE:
1148 case AR9285_DEVID_PCIE:
1149 ah = ath9k_hw_do_attach(devid, sc, mem, error);
1163 static void ath9k_hw_override_ini(struct ath_hal *ah,
1164 struct ath9k_channel *chan)
1167 * Set the RX_ABORT and RX_DIS and clear if off only after
1168 * RXE is set for MAC. This prevents frames with corrupted
1169 * descriptor status.
1171 REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
1174 if (!AR_SREV_5416_V20_OR_LATER(ah) ||
1175 AR_SREV_9280_10_OR_LATER(ah))
1178 REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
1181 static u32 ath9k_hw_def_ini_fixup(struct ath_hal *ah,
1182 struct ar5416_eeprom_def *pEepData,
1185 struct base_eep_header *pBase = &(pEepData->baseEepHeader);
1187 switch (ah->ah_devid) {
1188 case AR9280_DEVID_PCI:
1189 if (reg == 0x7894) {
1190 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
1191 "ini VAL: %x EEPROM: %x\n", value,
1192 (pBase->version & 0xff));
1194 if ((pBase->version & 0xff) > 0x0a) {
1195 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
1198 value &= ~AR_AN_TOP2_PWDCLKIND;
1199 value |= AR_AN_TOP2_PWDCLKIND &
1200 (pBase->pwdclkind << AR_AN_TOP2_PWDCLKIND_S);
1202 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
1203 "PWDCLKIND Earlier Rev\n");
1206 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
1207 "final ini VAL: %x\n", value);
1215 static u32 ath9k_hw_ini_fixup(struct ath_hal *ah,
1216 struct ar5416_eeprom_def *pEepData,
1219 struct ath_hal_5416 *ahp = AH5416(ah);
1221 if (ahp->ah_eep_map == EEP_MAP_4KBITS)
1224 return ath9k_hw_def_ini_fixup(ah, pEepData, reg, value);
1227 static int ath9k_hw_process_ini(struct ath_hal *ah,
1228 struct ath9k_channel *chan,
1229 enum ath9k_ht_macmode macmode)
1231 int i, regWrites = 0;
1232 struct ath_hal_5416 *ahp = AH5416(ah);
1233 struct ieee80211_channel *channel = chan->chan;
1234 u32 modesIndex, freqIndex;
1237 switch (chan->chanmode) {
1239 case CHANNEL_A_HT20:
1243 case CHANNEL_A_HT40PLUS:
1244 case CHANNEL_A_HT40MINUS:
1249 case CHANNEL_G_HT20:
1254 case CHANNEL_G_HT40PLUS:
1255 case CHANNEL_G_HT40MINUS:
1264 REG_WRITE(ah, AR_PHY(0), 0x00000007);
1266 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
1268 ath9k_hw_set_addac(ah, chan);
1270 if (AR_SREV_5416_V22_OR_LATER(ah)) {
1271 REG_WRITE_ARRAY(&ahp->ah_iniAddac, 1, regWrites);
1273 struct ar5416IniArray temp;
1275 sizeof(u32) * ahp->ah_iniAddac.ia_rows *
1276 ahp->ah_iniAddac.ia_columns;
1278 memcpy(ahp->ah_addac5416_21,
1279 ahp->ah_iniAddac.ia_array, addacSize);
1281 (ahp->ah_addac5416_21)[31 * ahp->ah_iniAddac.ia_columns + 1] = 0;
1283 temp.ia_array = ahp->ah_addac5416_21;
1284 temp.ia_columns = ahp->ah_iniAddac.ia_columns;
1285 temp.ia_rows = ahp->ah_iniAddac.ia_rows;
1286 REG_WRITE_ARRAY(&temp, 1, regWrites);
1289 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
1291 for (i = 0; i < ahp->ah_iniModes.ia_rows; i++) {
1292 u32 reg = INI_RA(&ahp->ah_iniModes, i, 0);
1293 u32 val = INI_RA(&ahp->ah_iniModes, i, modesIndex);
1295 REG_WRITE(ah, reg, val);
1297 if (reg >= 0x7800 && reg < 0x78a0
1298 && ah->ah_config.analog_shiftreg) {
1302 DO_DELAY(regWrites);
1305 if (AR_SREV_9280(ah))
1306 REG_WRITE_ARRAY(&ahp->ah_iniModesRxGain, modesIndex, regWrites);
1308 if (AR_SREV_9280(ah))
1309 REG_WRITE_ARRAY(&ahp->ah_iniModesTxGain, modesIndex, regWrites);
1311 for (i = 0; i < ahp->ah_iniCommon.ia_rows; i++) {
1312 u32 reg = INI_RA(&ahp->ah_iniCommon, i, 0);
1313 u32 val = INI_RA(&ahp->ah_iniCommon, i, 1);
1315 REG_WRITE(ah, reg, val);
1317 if (reg >= 0x7800 && reg < 0x78a0
1318 && ah->ah_config.analog_shiftreg) {
1322 DO_DELAY(regWrites);
1325 ath9k_hw_write_regs(ah, modesIndex, freqIndex, regWrites);
1327 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan)) {
1328 REG_WRITE_ARRAY(&ahp->ah_iniModesAdditional, modesIndex,
1332 ath9k_hw_override_ini(ah, chan);
1333 ath9k_hw_set_regs(ah, chan, macmode);
1334 ath9k_hw_init_chain_masks(ah);
1336 status = ath9k_hw_set_txpower(ah, chan,
1337 ath9k_regd_get_ctl(ah, chan),
1338 channel->max_antenna_gain * 2,
1339 channel->max_power * 2,
1340 min((u32) MAX_RATE_POWER,
1341 (u32) ah->ah_powerLimit));
1343 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
1344 "error init'ing transmit power\n");
1348 if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
1349 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
1350 "ar5416SetRfRegs failed\n");
1357 /****************************************/
1358 /* Reset and Channel Switching Routines */
1359 /****************************************/
1361 static void ath9k_hw_set_rfmode(struct ath_hal *ah, struct ath9k_channel *chan)
1368 rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
1369 ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
1371 if (!AR_SREV_9280_10_OR_LATER(ah))
1372 rfMode |= (IS_CHAN_5GHZ(chan)) ?
1373 AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ;
1375 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan))
1376 rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
1378 REG_WRITE(ah, AR_PHY_MODE, rfMode);
1381 static void ath9k_hw_mark_phy_inactive(struct ath_hal *ah)
1383 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
1386 static inline void ath9k_hw_set_dma(struct ath_hal *ah)
1390 regval = REG_READ(ah, AR_AHB_MODE);
1391 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
1393 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
1394 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
1396 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->ah_txTrigLevel);
1398 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
1399 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
1401 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1403 if (AR_SREV_9285(ah)) {
1404 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1405 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
1407 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1408 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1412 static void ath9k_hw_set_operating_mode(struct ath_hal *ah, int opmode)
1416 val = REG_READ(ah, AR_STA_ID1);
1417 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
1419 case NL80211_IFTYPE_AP:
1420 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
1421 | AR_STA_ID1_KSRCH_MODE);
1422 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1424 case NL80211_IFTYPE_ADHOC:
1425 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
1426 | AR_STA_ID1_KSRCH_MODE);
1427 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1429 case NL80211_IFTYPE_STATION:
1430 case NL80211_IFTYPE_MONITOR:
1431 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
1436 static inline void ath9k_hw_get_delta_slope_vals(struct ath_hal *ah,
1441 u32 coef_exp, coef_man;
1443 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1444 if ((coef_scaled >> coef_exp) & 0x1)
1447 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1449 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1451 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1452 *coef_exponent = coef_exp - 16;
1455 static void ath9k_hw_set_delta_slope(struct ath_hal *ah,
1456 struct ath9k_channel *chan)
1458 u32 coef_scaled, ds_coef_exp, ds_coef_man;
1459 u32 clockMhzScaled = 0x64000000;
1460 struct chan_centers centers;
1462 if (IS_CHAN_HALF_RATE(chan))
1463 clockMhzScaled = clockMhzScaled >> 1;
1464 else if (IS_CHAN_QUARTER_RATE(chan))
1465 clockMhzScaled = clockMhzScaled >> 2;
1467 ath9k_hw_get_channel_centers(ah, chan, ¢ers);
1468 coef_scaled = clockMhzScaled / centers.synth_center;
1470 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1473 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1474 AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
1475 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1476 AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
1478 coef_scaled = (9 * coef_scaled) / 10;
1480 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1483 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1484 AR_PHY_HALFGI_DSC_MAN, ds_coef_man);
1485 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1486 AR_PHY_HALFGI_DSC_EXP, ds_coef_exp);
1489 static bool ath9k_hw_set_reset(struct ath_hal *ah, int type)
1494 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1495 AR_RTC_FORCE_WAKE_ON_INT);
1497 if (AR_SREV_9100(ah)) {
1498 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1499 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1501 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1503 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1504 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
1505 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
1506 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1508 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1511 rst_flags = AR_RTC_RC_MAC_WARM;
1512 if (type == ATH9K_RESET_COLD)
1513 rst_flags |= AR_RTC_RC_MAC_COLD;
1516 REG_WRITE(ah, AR_RTC_RC, rst_flags);
1519 REG_WRITE(ah, AR_RTC_RC, 0);
1520 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0)) {
1521 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
1522 "RTC stuck in MAC reset\n");
1526 if (!AR_SREV_9100(ah))
1527 REG_WRITE(ah, AR_RC, 0);
1529 ath9k_hw_init_pll(ah, NULL);
1531 if (AR_SREV_9100(ah))
1537 static bool ath9k_hw_set_reset_power_on(struct ath_hal *ah)
1539 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1540 AR_RTC_FORCE_WAKE_ON_INT);
1542 REG_WRITE(ah, AR_RTC_RESET, 0);
1543 REG_WRITE(ah, AR_RTC_RESET, 1);
1545 if (!ath9k_hw_wait(ah,
1548 AR_RTC_STATUS_ON)) {
1549 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "RTC not waking up\n");
1553 ath9k_hw_read_revisions(ah);
1555 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1558 static bool ath9k_hw_set_reset_reg(struct ath_hal *ah, u32 type)
1560 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1561 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1564 case ATH9K_RESET_POWER_ON:
1565 return ath9k_hw_set_reset_power_on(ah);
1567 case ATH9K_RESET_WARM:
1568 case ATH9K_RESET_COLD:
1569 return ath9k_hw_set_reset(ah, type);
1576 static void ath9k_hw_set_regs(struct ath_hal *ah, struct ath9k_channel *chan,
1577 enum ath9k_ht_macmode macmode)
1580 u32 enableDacFifo = 0;
1581 struct ath_hal_5416 *ahp = AH5416(ah);
1583 if (AR_SREV_9285_10_OR_LATER(ah))
1584 enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) &
1585 AR_PHY_FC_ENABLE_DAC_FIFO);
1587 phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
1588 | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo;
1590 if (IS_CHAN_HT40(chan)) {
1591 phymode |= AR_PHY_FC_DYN2040_EN;
1593 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
1594 (chan->chanmode == CHANNEL_G_HT40PLUS))
1595 phymode |= AR_PHY_FC_DYN2040_PRI_CH;
1597 if (ahp->ah_extprotspacing == ATH9K_HT_EXTPROTSPACING_25)
1598 phymode |= AR_PHY_FC_DYN2040_EXT_CH;
1600 REG_WRITE(ah, AR_PHY_TURBO, phymode);
1602 ath9k_hw_set11nmac2040(ah, macmode);
1604 REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
1605 REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
1608 static bool ath9k_hw_chip_reset(struct ath_hal *ah,
1609 struct ath9k_channel *chan)
1611 struct ath_hal_5416 *ahp = AH5416(ah);
1613 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
1616 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
1619 ahp->ah_chipFullSleep = false;
1621 ath9k_hw_init_pll(ah, chan);
1623 ath9k_hw_set_rfmode(ah, chan);
1628 static bool ath9k_hw_channel_change(struct ath_hal *ah,
1629 struct ath9k_channel *chan,
1630 enum ath9k_ht_macmode macmode)
1632 struct ieee80211_channel *channel = chan->chan;
1633 u32 synthDelay, qnum;
1635 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1636 if (ath9k_hw_numtxpending(ah, qnum)) {
1637 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
1638 "Transmit frames pending on queue %d\n", qnum);
1643 REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
1644 if (!ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
1645 AR_PHY_RFBUS_GRANT_EN)) {
1646 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
1647 "Could not kill baseband RX\n");
1651 ath9k_hw_set_regs(ah, chan, macmode);
1653 if (AR_SREV_9280_10_OR_LATER(ah)) {
1654 if (!(ath9k_hw_ar9280_set_channel(ah, chan))) {
1655 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
1656 "failed to set channel\n");
1660 if (!(ath9k_hw_set_channel(ah, chan))) {
1661 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
1662 "failed to set channel\n");
1667 if (ath9k_hw_set_txpower(ah, chan,
1668 ath9k_regd_get_ctl(ah, chan),
1669 channel->max_antenna_gain * 2,
1670 channel->max_power * 2,
1671 min((u32) MAX_RATE_POWER,
1672 (u32) ah->ah_powerLimit)) != 0) {
1673 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
1674 "error init'ing transmit power\n");
1678 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
1679 if (IS_CHAN_B(chan))
1680 synthDelay = (4 * synthDelay) / 22;
1684 udelay(synthDelay + BASE_ACTIVATE_DELAY);
1686 REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
1688 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1689 ath9k_hw_set_delta_slope(ah, chan);
1691 if (AR_SREV_9280_10_OR_LATER(ah))
1692 ath9k_hw_9280_spur_mitigate(ah, chan);
1694 ath9k_hw_spur_mitigate(ah, chan);
1696 if (!chan->oneTimeCalsDone)
1697 chan->oneTimeCalsDone = true;
1702 static void ath9k_hw_9280_spur_mitigate(struct ath_hal *ah, struct ath9k_channel *chan)
1704 int bb_spur = AR_NO_SPUR;
1707 int bb_spur_off, spur_subchannel_sd;
1709 int spur_delta_phase;
1711 int upper, lower, cur_vit_mask;
1714 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
1715 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
1717 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
1718 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
1720 int inc[4] = { 0, 100, 0, 0 };
1721 struct chan_centers centers;
1728 bool is2GHz = IS_CHAN_2GHZ(chan);
1730 memset(&mask_m, 0, sizeof(int8_t) * 123);
1731 memset(&mask_p, 0, sizeof(int8_t) * 123);
1733 ath9k_hw_get_channel_centers(ah, chan, ¢ers);
1734 freq = centers.synth_center;
1736 ah->ah_config.spurmode = SPUR_ENABLE_EEPROM;
1737 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
1738 cur_bb_spur = ath9k_hw_eeprom_get_spur_chan(ah, i, is2GHz);
1741 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_2GHZ;
1743 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_5GHZ;
1745 if (AR_NO_SPUR == cur_bb_spur)
1747 cur_bb_spur = cur_bb_spur - freq;
1749 if (IS_CHAN_HT40(chan)) {
1750 if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT40) &&
1751 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT40)) {
1752 bb_spur = cur_bb_spur;
1755 } else if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT20) &&
1756 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT20)) {
1757 bb_spur = cur_bb_spur;
1762 if (AR_NO_SPUR == bb_spur) {
1763 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1764 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1767 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1768 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1771 bin = bb_spur * 320;
1773 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
1775 newVal = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
1776 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
1777 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
1778 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
1779 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), newVal);
1781 newVal = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
1782 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
1783 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
1784 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
1785 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
1786 REG_WRITE(ah, AR_PHY_SPUR_REG, newVal);
1788 if (IS_CHAN_HT40(chan)) {
1790 spur_subchannel_sd = 1;
1791 bb_spur_off = bb_spur + 10;
1793 spur_subchannel_sd = 0;
1794 bb_spur_off = bb_spur - 10;
1797 spur_subchannel_sd = 0;
1798 bb_spur_off = bb_spur;
1801 if (IS_CHAN_HT40(chan))
1803 ((bb_spur * 262144) /
1804 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
1807 ((bb_spur * 524288) /
1808 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
1810 denominator = IS_CHAN_2GHZ(chan) ? 44 : 40;
1811 spur_freq_sd = ((bb_spur_off * 2048) / denominator) & 0x3ff;
1813 newVal = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
1814 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
1815 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
1816 REG_WRITE(ah, AR_PHY_TIMING11, newVal);
1818 newVal = spur_subchannel_sd << AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S;
1819 REG_WRITE(ah, AR_PHY_SFCORR_EXT, newVal);
1825 for (i = 0; i < 4; i++) {
1829 for (bp = 0; bp < 30; bp++) {
1830 if ((cur_bin > lower) && (cur_bin < upper)) {
1831 pilot_mask = pilot_mask | 0x1 << bp;
1832 chan_mask = chan_mask | 0x1 << bp;
1837 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
1838 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
1841 cur_vit_mask = 6100;
1845 for (i = 0; i < 123; i++) {
1846 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
1848 /* workaround for gcc bug #37014 */
1849 volatile int tmp_v = abs(cur_vit_mask - bin);
1855 if (cur_vit_mask < 0)
1856 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
1858 mask_p[cur_vit_mask / 100] = mask_amt;
1860 cur_vit_mask -= 100;
1863 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
1864 | (mask_m[48] << 26) | (mask_m[49] << 24)
1865 | (mask_m[50] << 22) | (mask_m[51] << 20)
1866 | (mask_m[52] << 18) | (mask_m[53] << 16)
1867 | (mask_m[54] << 14) | (mask_m[55] << 12)
1868 | (mask_m[56] << 10) | (mask_m[57] << 8)
1869 | (mask_m[58] << 6) | (mask_m[59] << 4)
1870 | (mask_m[60] << 2) | (mask_m[61] << 0);
1871 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
1872 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
1874 tmp_mask = (mask_m[31] << 28)
1875 | (mask_m[32] << 26) | (mask_m[33] << 24)
1876 | (mask_m[34] << 22) | (mask_m[35] << 20)
1877 | (mask_m[36] << 18) | (mask_m[37] << 16)
1878 | (mask_m[48] << 14) | (mask_m[39] << 12)
1879 | (mask_m[40] << 10) | (mask_m[41] << 8)
1880 | (mask_m[42] << 6) | (mask_m[43] << 4)
1881 | (mask_m[44] << 2) | (mask_m[45] << 0);
1882 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
1883 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
1885 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
1886 | (mask_m[18] << 26) | (mask_m[18] << 24)
1887 | (mask_m[20] << 22) | (mask_m[20] << 20)
1888 | (mask_m[22] << 18) | (mask_m[22] << 16)
1889 | (mask_m[24] << 14) | (mask_m[24] << 12)
1890 | (mask_m[25] << 10) | (mask_m[26] << 8)
1891 | (mask_m[27] << 6) | (mask_m[28] << 4)
1892 | (mask_m[29] << 2) | (mask_m[30] << 0);
1893 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
1894 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
1896 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
1897 | (mask_m[2] << 26) | (mask_m[3] << 24)
1898 | (mask_m[4] << 22) | (mask_m[5] << 20)
1899 | (mask_m[6] << 18) | (mask_m[7] << 16)
1900 | (mask_m[8] << 14) | (mask_m[9] << 12)
1901 | (mask_m[10] << 10) | (mask_m[11] << 8)
1902 | (mask_m[12] << 6) | (mask_m[13] << 4)
1903 | (mask_m[14] << 2) | (mask_m[15] << 0);
1904 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
1905 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
1907 tmp_mask = (mask_p[15] << 28)
1908 | (mask_p[14] << 26) | (mask_p[13] << 24)
1909 | (mask_p[12] << 22) | (mask_p[11] << 20)
1910 | (mask_p[10] << 18) | (mask_p[9] << 16)
1911 | (mask_p[8] << 14) | (mask_p[7] << 12)
1912 | (mask_p[6] << 10) | (mask_p[5] << 8)
1913 | (mask_p[4] << 6) | (mask_p[3] << 4)
1914 | (mask_p[2] << 2) | (mask_p[1] << 0);
1915 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
1916 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
1918 tmp_mask = (mask_p[30] << 28)
1919 | (mask_p[29] << 26) | (mask_p[28] << 24)
1920 | (mask_p[27] << 22) | (mask_p[26] << 20)
1921 | (mask_p[25] << 18) | (mask_p[24] << 16)
1922 | (mask_p[23] << 14) | (mask_p[22] << 12)
1923 | (mask_p[21] << 10) | (mask_p[20] << 8)
1924 | (mask_p[19] << 6) | (mask_p[18] << 4)
1925 | (mask_p[17] << 2) | (mask_p[16] << 0);
1926 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
1927 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
1929 tmp_mask = (mask_p[45] << 28)
1930 | (mask_p[44] << 26) | (mask_p[43] << 24)
1931 | (mask_p[42] << 22) | (mask_p[41] << 20)
1932 | (mask_p[40] << 18) | (mask_p[39] << 16)
1933 | (mask_p[38] << 14) | (mask_p[37] << 12)
1934 | (mask_p[36] << 10) | (mask_p[35] << 8)
1935 | (mask_p[34] << 6) | (mask_p[33] << 4)
1936 | (mask_p[32] << 2) | (mask_p[31] << 0);
1937 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
1938 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
1940 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
1941 | (mask_p[59] << 26) | (mask_p[58] << 24)
1942 | (mask_p[57] << 22) | (mask_p[56] << 20)
1943 | (mask_p[55] << 18) | (mask_p[54] << 16)
1944 | (mask_p[53] << 14) | (mask_p[52] << 12)
1945 | (mask_p[51] << 10) | (mask_p[50] << 8)
1946 | (mask_p[49] << 6) | (mask_p[48] << 4)
1947 | (mask_p[47] << 2) | (mask_p[46] << 0);
1948 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
1949 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
1952 static void ath9k_hw_spur_mitigate(struct ath_hal *ah, struct ath9k_channel *chan)
1954 int bb_spur = AR_NO_SPUR;
1957 int spur_delta_phase;
1959 int upper, lower, cur_vit_mask;
1962 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
1963 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
1965 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
1966 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
1968 int inc[4] = { 0, 100, 0, 0 };
1975 bool is2GHz = IS_CHAN_2GHZ(chan);
1977 memset(&mask_m, 0, sizeof(int8_t) * 123);
1978 memset(&mask_p, 0, sizeof(int8_t) * 123);
1980 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
1981 cur_bb_spur = ath9k_hw_eeprom_get_spur_chan(ah, i, is2GHz);
1982 if (AR_NO_SPUR == cur_bb_spur)
1984 cur_bb_spur = cur_bb_spur - (chan->channel * 10);
1985 if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) {
1986 bb_spur = cur_bb_spur;
1991 if (AR_NO_SPUR == bb_spur)
1996 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
1997 new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
1998 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
1999 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
2000 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
2002 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new);
2004 new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
2005 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
2006 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
2007 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
2008 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
2009 REG_WRITE(ah, AR_PHY_SPUR_REG, new);
2011 spur_delta_phase = ((bb_spur * 524288) / 100) &
2012 AR_PHY_TIMING11_SPUR_DELTA_PHASE;
2014 denominator = IS_CHAN_2GHZ(chan) ? 440 : 400;
2015 spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff;
2017 new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
2018 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
2019 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
2020 REG_WRITE(ah, AR_PHY_TIMING11, new);
2026 for (i = 0; i < 4; i++) {
2030 for (bp = 0; bp < 30; bp++) {
2031 if ((cur_bin > lower) && (cur_bin < upper)) {
2032 pilot_mask = pilot_mask | 0x1 << bp;
2033 chan_mask = chan_mask | 0x1 << bp;
2038 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
2039 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
2042 cur_vit_mask = 6100;
2046 for (i = 0; i < 123; i++) {
2047 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
2049 /* workaround for gcc bug #37014 */
2050 volatile int tmp_v = abs(cur_vit_mask - bin);
2056 if (cur_vit_mask < 0)
2057 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
2059 mask_p[cur_vit_mask / 100] = mask_amt;
2061 cur_vit_mask -= 100;
2064 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
2065 | (mask_m[48] << 26) | (mask_m[49] << 24)
2066 | (mask_m[50] << 22) | (mask_m[51] << 20)
2067 | (mask_m[52] << 18) | (mask_m[53] << 16)
2068 | (mask_m[54] << 14) | (mask_m[55] << 12)
2069 | (mask_m[56] << 10) | (mask_m[57] << 8)
2070 | (mask_m[58] << 6) | (mask_m[59] << 4)
2071 | (mask_m[60] << 2) | (mask_m[61] << 0);
2072 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
2073 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
2075 tmp_mask = (mask_m[31] << 28)
2076 | (mask_m[32] << 26) | (mask_m[33] << 24)
2077 | (mask_m[34] << 22) | (mask_m[35] << 20)
2078 | (mask_m[36] << 18) | (mask_m[37] << 16)
2079 | (mask_m[48] << 14) | (mask_m[39] << 12)
2080 | (mask_m[40] << 10) | (mask_m[41] << 8)
2081 | (mask_m[42] << 6) | (mask_m[43] << 4)
2082 | (mask_m[44] << 2) | (mask_m[45] << 0);
2083 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
2084 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
2086 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
2087 | (mask_m[18] << 26) | (mask_m[18] << 24)
2088 | (mask_m[20] << 22) | (mask_m[20] << 20)
2089 | (mask_m[22] << 18) | (mask_m[22] << 16)
2090 | (mask_m[24] << 14) | (mask_m[24] << 12)
2091 | (mask_m[25] << 10) | (mask_m[26] << 8)
2092 | (mask_m[27] << 6) | (mask_m[28] << 4)
2093 | (mask_m[29] << 2) | (mask_m[30] << 0);
2094 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
2095 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
2097 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
2098 | (mask_m[2] << 26) | (mask_m[3] << 24)
2099 | (mask_m[4] << 22) | (mask_m[5] << 20)
2100 | (mask_m[6] << 18) | (mask_m[7] << 16)
2101 | (mask_m[8] << 14) | (mask_m[9] << 12)
2102 | (mask_m[10] << 10) | (mask_m[11] << 8)
2103 | (mask_m[12] << 6) | (mask_m[13] << 4)
2104 | (mask_m[14] << 2) | (mask_m[15] << 0);
2105 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
2106 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
2108 tmp_mask = (mask_p[15] << 28)
2109 | (mask_p[14] << 26) | (mask_p[13] << 24)
2110 | (mask_p[12] << 22) | (mask_p[11] << 20)
2111 | (mask_p[10] << 18) | (mask_p[9] << 16)
2112 | (mask_p[8] << 14) | (mask_p[7] << 12)
2113 | (mask_p[6] << 10) | (mask_p[5] << 8)
2114 | (mask_p[4] << 6) | (mask_p[3] << 4)
2115 | (mask_p[2] << 2) | (mask_p[1] << 0);
2116 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
2117 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
2119 tmp_mask = (mask_p[30] << 28)
2120 | (mask_p[29] << 26) | (mask_p[28] << 24)
2121 | (mask_p[27] << 22) | (mask_p[26] << 20)
2122 | (mask_p[25] << 18) | (mask_p[24] << 16)
2123 | (mask_p[23] << 14) | (mask_p[22] << 12)
2124 | (mask_p[21] << 10) | (mask_p[20] << 8)
2125 | (mask_p[19] << 6) | (mask_p[18] << 4)
2126 | (mask_p[17] << 2) | (mask_p[16] << 0);
2127 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
2128 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
2130 tmp_mask = (mask_p[45] << 28)
2131 | (mask_p[44] << 26) | (mask_p[43] << 24)
2132 | (mask_p[42] << 22) | (mask_p[41] << 20)
2133 | (mask_p[40] << 18) | (mask_p[39] << 16)
2134 | (mask_p[38] << 14) | (mask_p[37] << 12)
2135 | (mask_p[36] << 10) | (mask_p[35] << 8)
2136 | (mask_p[34] << 6) | (mask_p[33] << 4)
2137 | (mask_p[32] << 2) | (mask_p[31] << 0);
2138 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
2139 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
2141 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
2142 | (mask_p[59] << 26) | (mask_p[58] << 24)
2143 | (mask_p[57] << 22) | (mask_p[56] << 20)
2144 | (mask_p[55] << 18) | (mask_p[54] << 16)
2145 | (mask_p[53] << 14) | (mask_p[52] << 12)
2146 | (mask_p[51] << 10) | (mask_p[50] << 8)
2147 | (mask_p[49] << 6) | (mask_p[48] << 4)
2148 | (mask_p[47] << 2) | (mask_p[46] << 0);
2149 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
2150 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
2153 int ath9k_hw_reset(struct ath_hal *ah, struct ath9k_channel *chan,
2154 bool bChannelChange)
2157 struct ath_softc *sc = ah->ah_sc;
2158 struct ath_hal_5416 *ahp = AH5416(ah);
2159 struct ath9k_channel *curchan = ah->ah_curchan;
2162 int i, rx_chainmask, r;
2164 ahp->ah_extprotspacing = sc->sc_ht_extprotspacing;
2165 ahp->ah_txchainmask = sc->sc_tx_chainmask;
2166 ahp->ah_rxchainmask = sc->sc_rx_chainmask;
2168 if (AR_SREV_9285(ah)) {
2169 ahp->ah_txchainmask &= 0x1;
2170 ahp->ah_rxchainmask &= 0x1;
2171 } else if (AR_SREV_9280(ah)) {
2172 ahp->ah_txchainmask &= 0x3;
2173 ahp->ah_rxchainmask &= 0x3;
2176 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
2180 ath9k_hw_getnf(ah, curchan);
2182 if (bChannelChange &&
2183 (ahp->ah_chipFullSleep != true) &&
2184 (ah->ah_curchan != NULL) &&
2185 (chan->channel != ah->ah_curchan->channel) &&
2186 ((chan->channelFlags & CHANNEL_ALL) ==
2187 (ah->ah_curchan->channelFlags & CHANNEL_ALL)) &&
2188 (!AR_SREV_9280(ah) || (!IS_CHAN_A_5MHZ_SPACED(chan) &&
2189 !IS_CHAN_A_5MHZ_SPACED(ah->ah_curchan)))) {
2191 if (ath9k_hw_channel_change(ah, chan, sc->tx_chan_width)) {
2192 ath9k_hw_loadnf(ah, ah->ah_curchan);
2193 ath9k_hw_start_nfcal(ah);
2198 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
2199 if (saveDefAntenna == 0)
2202 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
2204 saveLedState = REG_READ(ah, AR_CFG_LED) &
2205 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
2206 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
2208 ath9k_hw_mark_phy_inactive(ah);
2210 if (!ath9k_hw_chip_reset(ah, chan)) {
2211 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "chip reset failed\n");
2215 if (AR_SREV_9280_10_OR_LATER(ah))
2216 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
2218 r = ath9k_hw_process_ini(ah, chan, sc->tx_chan_width);
2222 /* Setup MFP options for CCMP */
2223 if (AR_SREV_9280_20_OR_LATER(ah)) {
2224 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
2225 * frames when constructing CCMP AAD. */
2226 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
2228 ah->sw_mgmt_crypto = false;
2229 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
2230 /* Disable hardware crypto for management frames */
2231 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
2232 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
2233 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
2234 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
2235 ah->sw_mgmt_crypto = true;
2237 ah->sw_mgmt_crypto = true;
2239 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
2240 ath9k_hw_set_delta_slope(ah, chan);
2242 if (AR_SREV_9280_10_OR_LATER(ah))
2243 ath9k_hw_9280_spur_mitigate(ah, chan);
2245 ath9k_hw_spur_mitigate(ah, chan);
2247 if (!ath9k_hw_eeprom_set_board_values(ah, chan)) {
2248 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
2249 "error setting board options\n");
2253 ath9k_hw_decrease_chain_power(ah, chan);
2255 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(ahp->ah_macaddr));
2256 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(ahp->ah_macaddr + 4)
2258 | AR_STA_ID1_RTS_USE_DEF
2260 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
2261 | ahp->ah_staId1Defaults);
2262 ath9k_hw_set_operating_mode(ah, ah->ah_opmode);
2264 REG_WRITE(ah, AR_BSSMSKL, get_unaligned_le32(ahp->ah_bssidmask));
2265 REG_WRITE(ah, AR_BSSMSKU, get_unaligned_le16(ahp->ah_bssidmask + 4));
2267 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
2269 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(ahp->ah_bssid));
2270 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(ahp->ah_bssid + 4) |
2271 ((ahp->ah_assocId & 0x3fff) << AR_BSS_ID1_AID_S));
2273 REG_WRITE(ah, AR_ISR, ~0);
2275 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
2277 if (AR_SREV_9280_10_OR_LATER(ah)) {
2278 if (!(ath9k_hw_ar9280_set_channel(ah, chan)))
2281 if (!(ath9k_hw_set_channel(ah, chan)))
2285 for (i = 0; i < AR_NUM_DCU; i++)
2286 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
2288 ahp->ah_intrTxqs = 0;
2289 for (i = 0; i < ah->ah_caps.total_queues; i++)
2290 ath9k_hw_resettxqueue(ah, i);
2292 ath9k_hw_init_interrupt_masks(ah, ah->ah_opmode);
2293 ath9k_hw_init_qos(ah);
2295 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
2296 if (ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
2297 ath9k_enable_rfkill(ah);
2299 ath9k_hw_init_user_settings(ah);
2301 REG_WRITE(ah, AR_STA_ID1,
2302 REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
2304 ath9k_hw_set_dma(ah);
2306 REG_WRITE(ah, AR_OBS, 8);
2308 if (ahp->ah_intrMitigation) {
2310 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
2311 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
2314 ath9k_hw_init_bb(ah, chan);
2316 if (!ath9k_hw_init_cal(ah, chan))
2319 rx_chainmask = ahp->ah_rxchainmask;
2320 if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) {
2321 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
2322 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
2325 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
2327 if (AR_SREV_9100(ah)) {
2329 mask = REG_READ(ah, AR_CFG);
2330 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
2331 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
2332 "CFG Byte Swap Set 0x%x\n", mask);
2335 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
2336 REG_WRITE(ah, AR_CFG, mask);
2337 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
2338 "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
2342 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
2349 /************************/
2350 /* Key Cache Management */
2351 /************************/
2353 bool ath9k_hw_keyreset(struct ath_hal *ah, u16 entry)
2357 if (entry >= ah->ah_caps.keycache_size) {
2358 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
2359 "entry %u out of range\n", entry);
2363 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
2365 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
2366 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
2367 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
2368 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
2369 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
2370 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
2371 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
2372 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
2374 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2375 u16 micentry = entry + 64;
2377 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
2378 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
2379 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
2380 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
2384 if (ah->ah_curchan == NULL)
2390 bool ath9k_hw_keysetmac(struct ath_hal *ah, u16 entry, const u8 *mac)
2394 if (entry >= ah->ah_caps.keycache_size) {
2395 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
2396 "entry %u out of range\n", entry);
2401 macHi = (mac[5] << 8) | mac[4];
2402 macLo = (mac[3] << 24) |
2407 macLo |= (macHi & 1) << 31;
2412 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
2413 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
2418 bool ath9k_hw_set_keycache_entry(struct ath_hal *ah, u16 entry,
2419 const struct ath9k_keyval *k,
2420 const u8 *mac, int xorKey)
2422 const struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
2423 u32 key0, key1, key2, key3, key4;
2425 u32 xorMask = xorKey ?
2426 (ATH9K_KEY_XOR << 24 | ATH9K_KEY_XOR << 16 | ATH9K_KEY_XOR << 8
2427 | ATH9K_KEY_XOR) : 0;
2428 struct ath_hal_5416 *ahp = AH5416(ah);
2430 if (entry >= pCap->keycache_size) {
2431 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
2432 "entry %u out of range\n", entry);
2436 switch (k->kv_type) {
2437 case ATH9K_CIPHER_AES_OCB:
2438 keyType = AR_KEYTABLE_TYPE_AES;
2440 case ATH9K_CIPHER_AES_CCM:
2441 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
2442 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
2443 "AES-CCM not supported by mac rev 0x%x\n",
2447 keyType = AR_KEYTABLE_TYPE_CCM;
2449 case ATH9K_CIPHER_TKIP:
2450 keyType = AR_KEYTABLE_TYPE_TKIP;
2451 if (ATH9K_IS_MIC_ENABLED(ah)
2452 && entry + 64 >= pCap->keycache_size) {
2453 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
2454 "entry %u inappropriate for TKIP\n", entry);
2458 case ATH9K_CIPHER_WEP:
2459 if (k->kv_len < LEN_WEP40) {
2460 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
2461 "WEP key length %u too small\n", k->kv_len);
2464 if (k->kv_len <= LEN_WEP40)
2465 keyType = AR_KEYTABLE_TYPE_40;
2466 else if (k->kv_len <= LEN_WEP104)
2467 keyType = AR_KEYTABLE_TYPE_104;
2469 keyType = AR_KEYTABLE_TYPE_128;
2471 case ATH9K_CIPHER_CLR:
2472 keyType = AR_KEYTABLE_TYPE_CLR;
2475 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
2476 "cipher %u not supported\n", k->kv_type);
2480 key0 = get_unaligned_le32(k->kv_val + 0) ^ xorMask;
2481 key1 = (get_unaligned_le16(k->kv_val + 4) ^ xorMask) & 0xffff;
2482 key2 = get_unaligned_le32(k->kv_val + 6) ^ xorMask;
2483 key3 = (get_unaligned_le16(k->kv_val + 10) ^ xorMask) & 0xffff;
2484 key4 = get_unaligned_le32(k->kv_val + 12) ^ xorMask;
2485 if (k->kv_len <= LEN_WEP104)
2488 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2489 u16 micentry = entry + 64;
2491 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
2492 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
2493 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2494 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
2495 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2496 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
2497 (void) ath9k_hw_keysetmac(ah, entry, mac);
2499 if (ahp->ah_miscMode & AR_PCU_MIC_NEW_LOC_ENA) {
2500 u32 mic0, mic1, mic2, mic3, mic4;
2502 mic0 = get_unaligned_le32(k->kv_mic + 0);
2503 mic2 = get_unaligned_le32(k->kv_mic + 4);
2504 mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
2505 mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
2506 mic4 = get_unaligned_le32(k->kv_txmic + 4);
2507 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2508 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
2509 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2510 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
2511 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
2512 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2513 AR_KEYTABLE_TYPE_CLR);
2518 mic0 = get_unaligned_le32(k->kv_mic + 0);
2519 mic2 = get_unaligned_le32(k->kv_mic + 4);
2520 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2521 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
2522 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2523 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
2524 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
2525 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2526 AR_KEYTABLE_TYPE_CLR);
2528 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
2529 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
2530 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2531 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
2533 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2534 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
2535 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2536 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
2537 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2538 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
2540 (void) ath9k_hw_keysetmac(ah, entry, mac);
2543 if (ah->ah_curchan == NULL)
2549 bool ath9k_hw_keyisvalid(struct ath_hal *ah, u16 entry)
2551 if (entry < ah->ah_caps.keycache_size) {
2552 u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
2553 if (val & AR_KEYTABLE_VALID)
2559 /******************************/
2560 /* Power Management (Chipset) */
2561 /******************************/
2563 static void ath9k_set_power_sleep(struct ath_hal *ah, int setChip)
2565 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2567 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2568 AR_RTC_FORCE_WAKE_EN);
2569 if (!AR_SREV_9100(ah))
2570 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
2572 REG_CLR_BIT(ah, (AR_RTC_RESET),
2577 static void ath9k_set_power_network_sleep(struct ath_hal *ah, int setChip)
2579 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2581 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
2583 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
2584 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2585 AR_RTC_FORCE_WAKE_ON_INT);
2587 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2588 AR_RTC_FORCE_WAKE_EN);
2593 static bool ath9k_hw_set_power_awake(struct ath_hal *ah,
2600 if ((REG_READ(ah, AR_RTC_STATUS) &
2601 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2602 if (ath9k_hw_set_reset_reg(ah,
2603 ATH9K_RESET_POWER_ON) != true) {
2607 if (AR_SREV_9100(ah))
2608 REG_SET_BIT(ah, AR_RTC_RESET,
2611 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2612 AR_RTC_FORCE_WAKE_EN);
2615 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2616 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2617 if (val == AR_RTC_STATUS_ON)
2620 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2621 AR_RTC_FORCE_WAKE_EN);
2624 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
2625 "Failed to wakeup in %uus\n", POWER_UP_TIME / 20);
2630 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2635 bool ath9k_hw_setpower(struct ath_hal *ah,
2636 enum ath9k_power_mode mode)
2638 struct ath_hal_5416 *ahp = AH5416(ah);
2639 static const char *modes[] = {
2645 int status = true, setChip = true;
2647 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT, "%s -> %s (%s)\n",
2648 modes[ah->ah_power_mode], modes[mode],
2649 setChip ? "set chip " : "");
2652 case ATH9K_PM_AWAKE:
2653 status = ath9k_hw_set_power_awake(ah, setChip);
2655 case ATH9K_PM_FULL_SLEEP:
2656 ath9k_set_power_sleep(ah, setChip);
2657 ahp->ah_chipFullSleep = true;
2659 case ATH9K_PM_NETWORK_SLEEP:
2660 ath9k_set_power_network_sleep(ah, setChip);
2663 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
2664 "Unknown power mode %u\n", mode);
2667 ah->ah_power_mode = mode;
2672 void ath9k_hw_configpcipowersave(struct ath_hal *ah, int restore)
2674 struct ath_hal_5416 *ahp = AH5416(ah);
2677 if (ah->ah_isPciExpress != true)
2680 if (ah->ah_config.pcie_powersave_enable == 2)
2686 if (AR_SREV_9280_20_OR_LATER(ah)) {
2687 for (i = 0; i < ahp->ah_iniPcieSerdes.ia_rows; i++) {
2688 REG_WRITE(ah, INI_RA(&ahp->ah_iniPcieSerdes, i, 0),
2689 INI_RA(&ahp->ah_iniPcieSerdes, i, 1));
2692 } else if (AR_SREV_9280(ah) &&
2693 (ah->ah_macRev == AR_SREV_REVISION_9280_10)) {
2694 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
2695 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
2697 REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
2698 REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
2699 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
2701 if (ah->ah_config.pcie_clock_req)
2702 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
2704 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
2706 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2707 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2708 REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
2710 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
2714 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
2715 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
2716 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
2717 REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
2718 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
2719 REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
2720 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2721 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2722 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
2723 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
2726 REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
2728 if (ah->ah_config.pcie_waen) {
2729 REG_WRITE(ah, AR_WA, ah->ah_config.pcie_waen);
2731 if (AR_SREV_9285(ah))
2732 REG_WRITE(ah, AR_WA, AR9285_WA_DEFAULT);
2733 else if (AR_SREV_9280(ah))
2734 REG_WRITE(ah, AR_WA, AR9280_WA_DEFAULT);
2736 REG_WRITE(ah, AR_WA, AR_WA_DEFAULT);
2741 /**********************/
2742 /* Interrupt Handling */
2743 /**********************/
2745 bool ath9k_hw_intrpend(struct ath_hal *ah)
2749 if (AR_SREV_9100(ah))
2752 host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
2753 if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
2756 host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
2757 if ((host_isr & AR_INTR_SYNC_DEFAULT)
2758 && (host_isr != AR_INTR_SPURIOUS))
2764 bool ath9k_hw_getisr(struct ath_hal *ah, enum ath9k_int *masked)
2768 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
2770 bool fatal_int = false;
2771 struct ath_hal_5416 *ahp = AH5416(ah);
2773 if (!AR_SREV_9100(ah)) {
2774 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
2775 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
2776 == AR_RTC_STATUS_ON) {
2777 isr = REG_READ(ah, AR_ISR);
2781 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
2782 AR_INTR_SYNC_DEFAULT;
2786 if (!isr && !sync_cause)
2790 isr = REG_READ(ah, AR_ISR);
2794 if (isr & AR_ISR_BCNMISC) {
2796 isr2 = REG_READ(ah, AR_ISR_S2);
2797 if (isr2 & AR_ISR_S2_TIM)
2798 mask2 |= ATH9K_INT_TIM;
2799 if (isr2 & AR_ISR_S2_DTIM)
2800 mask2 |= ATH9K_INT_DTIM;
2801 if (isr2 & AR_ISR_S2_DTIMSYNC)
2802 mask2 |= ATH9K_INT_DTIMSYNC;
2803 if (isr2 & (AR_ISR_S2_CABEND))
2804 mask2 |= ATH9K_INT_CABEND;
2805 if (isr2 & AR_ISR_S2_GTT)
2806 mask2 |= ATH9K_INT_GTT;
2807 if (isr2 & AR_ISR_S2_CST)
2808 mask2 |= ATH9K_INT_CST;
2811 isr = REG_READ(ah, AR_ISR_RAC);
2812 if (isr == 0xffffffff) {
2817 *masked = isr & ATH9K_INT_COMMON;
2819 if (ahp->ah_intrMitigation) {
2820 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
2821 *masked |= ATH9K_INT_RX;
2824 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
2825 *masked |= ATH9K_INT_RX;
2827 (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
2831 *masked |= ATH9K_INT_TX;
2833 s0_s = REG_READ(ah, AR_ISR_S0_S);
2834 ahp->ah_intrTxqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
2835 ahp->ah_intrTxqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
2837 s1_s = REG_READ(ah, AR_ISR_S1_S);
2838 ahp->ah_intrTxqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
2839 ahp->ah_intrTxqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
2842 if (isr & AR_ISR_RXORN) {
2843 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
2844 "receive FIFO overrun interrupt\n");
2847 if (!AR_SREV_9100(ah)) {
2848 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
2849 u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
2850 if (isr5 & AR_ISR_S5_TIM_TIMER)
2851 *masked |= ATH9K_INT_TIM_TIMER;
2858 if (AR_SREV_9100(ah))
2864 (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
2868 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
2869 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
2870 "received PCI FATAL interrupt\n");
2872 if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
2873 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
2874 "received PCI PERR interrupt\n");
2877 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
2878 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
2879 "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
2880 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
2881 REG_WRITE(ah, AR_RC, 0);
2882 *masked |= ATH9K_INT_FATAL;
2884 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
2885 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
2886 "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
2889 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
2890 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
2896 enum ath9k_int ath9k_hw_intrget(struct ath_hal *ah)
2898 return AH5416(ah)->ah_maskReg;
2901 enum ath9k_int ath9k_hw_set_interrupts(struct ath_hal *ah, enum ath9k_int ints)
2903 struct ath_hal_5416 *ahp = AH5416(ah);
2904 u32 omask = ahp->ah_maskReg;
2906 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
2908 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
2910 if (omask & ATH9K_INT_GLOBAL) {
2911 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "disable IER\n");
2912 REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
2913 (void) REG_READ(ah, AR_IER);
2914 if (!AR_SREV_9100(ah)) {
2915 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
2916 (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
2918 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
2919 (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
2923 mask = ints & ATH9K_INT_COMMON;
2926 if (ints & ATH9K_INT_TX) {
2927 if (ahp->ah_txOkInterruptMask)
2928 mask |= AR_IMR_TXOK;
2929 if (ahp->ah_txDescInterruptMask)
2930 mask |= AR_IMR_TXDESC;
2931 if (ahp->ah_txErrInterruptMask)
2932 mask |= AR_IMR_TXERR;
2933 if (ahp->ah_txEolInterruptMask)
2934 mask |= AR_IMR_TXEOL;
2936 if (ints & ATH9K_INT_RX) {
2937 mask |= AR_IMR_RXERR;
2938 if (ahp->ah_intrMitigation)
2939 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
2941 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
2942 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
2943 mask |= AR_IMR_GENTMR;
2946 if (ints & (ATH9K_INT_BMISC)) {
2947 mask |= AR_IMR_BCNMISC;
2948 if (ints & ATH9K_INT_TIM)
2949 mask2 |= AR_IMR_S2_TIM;
2950 if (ints & ATH9K_INT_DTIM)
2951 mask2 |= AR_IMR_S2_DTIM;
2952 if (ints & ATH9K_INT_DTIMSYNC)
2953 mask2 |= AR_IMR_S2_DTIMSYNC;
2954 if (ints & ATH9K_INT_CABEND)
2955 mask2 |= (AR_IMR_S2_CABEND);
2958 if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
2959 mask |= AR_IMR_BCNMISC;
2960 if (ints & ATH9K_INT_GTT)
2961 mask2 |= AR_IMR_S2_GTT;
2962 if (ints & ATH9K_INT_CST)
2963 mask2 |= AR_IMR_S2_CST;
2966 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
2967 REG_WRITE(ah, AR_IMR, mask);
2968 mask = REG_READ(ah, AR_IMR_S2) & ~(AR_IMR_S2_TIM |
2970 AR_IMR_S2_DTIMSYNC |
2974 AR_IMR_S2_GTT | AR_IMR_S2_CST);
2975 REG_WRITE(ah, AR_IMR_S2, mask | mask2);
2976 ahp->ah_maskReg = ints;
2978 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
2979 if (ints & ATH9K_INT_TIM_TIMER)
2980 REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
2982 REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
2985 if (ints & ATH9K_INT_GLOBAL) {
2986 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "enable IER\n");
2987 REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
2988 if (!AR_SREV_9100(ah)) {
2989 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
2991 REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
2994 REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
2995 AR_INTR_SYNC_DEFAULT);
2996 REG_WRITE(ah, AR_INTR_SYNC_MASK,
2997 AR_INTR_SYNC_DEFAULT);
2999 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
3000 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
3006 /*******************/
3007 /* Beacon Handling */
3008 /*******************/
3010 void ath9k_hw_beaconinit(struct ath_hal *ah, u32 next_beacon, u32 beacon_period)
3012 struct ath_hal_5416 *ahp = AH5416(ah);
3015 ahp->ah_beaconInterval = beacon_period;
3017 switch (ah->ah_opmode) {
3018 case NL80211_IFTYPE_STATION:
3019 case NL80211_IFTYPE_MONITOR:
3020 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3021 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
3022 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
3023 flags |= AR_TBTT_TIMER_EN;
3025 case NL80211_IFTYPE_ADHOC:
3026 REG_SET_BIT(ah, AR_TXCFG,
3027 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
3028 REG_WRITE(ah, AR_NEXT_NDP_TIMER,
3029 TU_TO_USEC(next_beacon +
3030 (ahp->ah_atimWindow ? ahp->
3031 ah_atimWindow : 1)));
3032 flags |= AR_NDP_TIMER_EN;
3033 case NL80211_IFTYPE_AP:
3034 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3035 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
3036 TU_TO_USEC(next_beacon -
3038 dma_beacon_response_time));
3039 REG_WRITE(ah, AR_NEXT_SWBA,
3040 TU_TO_USEC(next_beacon -
3042 sw_beacon_response_time));
3044 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
3047 DPRINTF(ah->ah_sc, ATH_DBG_BEACON,
3048 "%s: unsupported opmode: %d\n",
3049 __func__, ah->ah_opmode);
3054 REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3055 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3056 REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
3057 REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
3059 beacon_period &= ~ATH9K_BEACON_ENA;
3060 if (beacon_period & ATH9K_BEACON_RESET_TSF) {
3061 beacon_period &= ~ATH9K_BEACON_RESET_TSF;
3062 ath9k_hw_reset_tsf(ah);
3065 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
3068 void ath9k_hw_set_sta_beacon_timers(struct ath_hal *ah,
3069 const struct ath9k_beacon_state *bs)
3071 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
3072 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
3074 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
3076 REG_WRITE(ah, AR_BEACON_PERIOD,
3077 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3078 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
3079 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3081 REG_RMW_FIELD(ah, AR_RSSI_THR,
3082 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
3084 beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
3086 if (bs->bs_sleepduration > beaconintval)
3087 beaconintval = bs->bs_sleepduration;
3089 dtimperiod = bs->bs_dtimperiod;
3090 if (bs->bs_sleepduration > dtimperiod)
3091 dtimperiod = bs->bs_sleepduration;
3093 if (beaconintval == dtimperiod)
3094 nextTbtt = bs->bs_nextdtim;
3096 nextTbtt = bs->bs_nexttbtt;
3098 DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
3099 DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
3100 DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
3101 DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
3103 REG_WRITE(ah, AR_NEXT_DTIM,
3104 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
3105 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
3107 REG_WRITE(ah, AR_SLEEP1,
3108 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
3109 | AR_SLEEP1_ASSUME_DTIM);
3111 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
3112 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
3114 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
3116 REG_WRITE(ah, AR_SLEEP2,
3117 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
3119 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
3120 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
3122 REG_SET_BIT(ah, AR_TIMER_MODE,
3123 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
3128 /*******************/
3129 /* HW Capabilities */
3130 /*******************/
3132 bool ath9k_hw_fill_cap_info(struct ath_hal *ah)
3134 struct ath_hal_5416 *ahp = AH5416(ah);
3135 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
3136 u16 capField = 0, eeval;
3138 eeval = ath9k_hw_get_eeprom(ah, EEP_REG_0);
3140 ah->ah_currentRD = eeval;
3142 eeval = ath9k_hw_get_eeprom(ah, EEP_REG_1);
3143 ah->ah_currentRDExt = eeval;
3145 capField = ath9k_hw_get_eeprom(ah, EEP_OP_CAP);
3147 if (ah->ah_opmode != NL80211_IFTYPE_AP &&
3148 ah->ah_subvendorid == AR_SUBVENDOR_ID_NEW_A) {
3149 if (ah->ah_currentRD == 0x64 || ah->ah_currentRD == 0x65)
3150 ah->ah_currentRD += 5;
3151 else if (ah->ah_currentRD == 0x41)
3152 ah->ah_currentRD = 0x43;
3153 DPRINTF(ah->ah_sc, ATH_DBG_REGULATORY,
3154 "regdomain mapped to 0x%x\n", ah->ah_currentRD);
3157 eeval = ath9k_hw_get_eeprom(ah, EEP_OP_MODE);
3158 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
3160 if (eeval & AR5416_OPFLAGS_11A) {
3161 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
3162 if (ah->ah_config.ht_enable) {
3163 if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
3164 set_bit(ATH9K_MODE_11NA_HT20,
3165 pCap->wireless_modes);
3166 if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
3167 set_bit(ATH9K_MODE_11NA_HT40PLUS,
3168 pCap->wireless_modes);
3169 set_bit(ATH9K_MODE_11NA_HT40MINUS,
3170 pCap->wireless_modes);
3175 if (eeval & AR5416_OPFLAGS_11G) {
3176 set_bit(ATH9K_MODE_11B, pCap->wireless_modes);
3177 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
3178 if (ah->ah_config.ht_enable) {
3179 if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
3180 set_bit(ATH9K_MODE_11NG_HT20,
3181 pCap->wireless_modes);
3182 if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
3183 set_bit(ATH9K_MODE_11NG_HT40PLUS,
3184 pCap->wireless_modes);
3185 set_bit(ATH9K_MODE_11NG_HT40MINUS,
3186 pCap->wireless_modes);
3191 pCap->tx_chainmask = ath9k_hw_get_eeprom(ah, EEP_TX_MASK);
3192 if ((ah->ah_isPciExpress)
3193 || (eeval & AR5416_OPFLAGS_11A)) {
3194 pCap->rx_chainmask =
3195 ath9k_hw_get_eeprom(ah, EEP_RX_MASK);
3197 pCap->rx_chainmask =
3198 (ath9k_hw_gpio_get(ah, 0)) ? 0x5 : 0x7;
3201 if (!(AR_SREV_9280(ah) && (ah->ah_macRev == 0)))
3202 ahp->ah_miscMode |= AR_PCU_MIC_NEW_LOC_ENA;
3204 pCap->low_2ghz_chan = 2312;
3205 pCap->high_2ghz_chan = 2732;
3207 pCap->low_5ghz_chan = 4920;
3208 pCap->high_5ghz_chan = 6100;
3210 pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
3211 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
3212 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
3214 pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
3215 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
3216 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
3218 pCap->hw_caps |= ATH9K_HW_CAP_CHAN_SPREAD;
3220 if (ah->ah_config.ht_enable)
3221 pCap->hw_caps |= ATH9K_HW_CAP_HT;
3223 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
3225 pCap->hw_caps |= ATH9K_HW_CAP_GTT;
3226 pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
3227 pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
3228 pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
3230 if (capField & AR_EEPROM_EEPCAP_MAXQCU)
3231 pCap->total_queues =
3232 MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
3234 pCap->total_queues = ATH9K_NUM_TX_QUEUES;
3236 if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
3237 pCap->keycache_size =
3238 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
3240 pCap->keycache_size = AR_KEYTABLE_SIZE;
3242 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
3243 pCap->num_mr_retries = 4;
3244 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
3246 if (AR_SREV_9285_10_OR_LATER(ah))
3247 pCap->num_gpio_pins = AR9285_NUM_GPIO;
3248 else if (AR_SREV_9280_10_OR_LATER(ah))
3249 pCap->num_gpio_pins = AR928X_NUM_GPIO;
3251 pCap->num_gpio_pins = AR_NUM_GPIO;
3253 if (AR_SREV_9280_10_OR_LATER(ah)) {
3254 pCap->hw_caps |= ATH9K_HW_CAP_WOW;
3255 pCap->hw_caps |= ATH9K_HW_CAP_WOW_MATCHPATTERN_EXACT;
3257 pCap->hw_caps &= ~ATH9K_HW_CAP_WOW;
3258 pCap->hw_caps &= ~ATH9K_HW_CAP_WOW_MATCHPATTERN_EXACT;
3261 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
3262 pCap->hw_caps |= ATH9K_HW_CAP_CST;
3263 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
3265 pCap->rts_aggr_limit = (8 * 1024);
3268 pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
3270 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
3271 ah->ah_rfsilent = ath9k_hw_get_eeprom(ah, EEP_RF_SILENT);
3272 if (ah->ah_rfsilent & EEP_RFSILENT_ENABLED) {
3273 ah->ah_rfkill_gpio =
3274 MS(ah->ah_rfsilent, EEP_RFSILENT_GPIO_SEL);
3275 ah->ah_rfkill_polarity =
3276 MS(ah->ah_rfsilent, EEP_RFSILENT_POLARITY);
3278 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
3282 if ((ah->ah_macVersion == AR_SREV_VERSION_5416_PCI) ||
3283 (ah->ah_macVersion == AR_SREV_VERSION_5416_PCIE) ||
3284 (ah->ah_macVersion == AR_SREV_VERSION_9160) ||
3285 (ah->ah_macVersion == AR_SREV_VERSION_9100) ||
3286 (ah->ah_macVersion == AR_SREV_VERSION_9280))
3287 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
3289 pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
3291 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
3292 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
3294 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
3296 if (ah->ah_currentRDExt & (1 << REG_EXT_JAPAN_MIDBAND)) {
3298 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3299 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
3300 AR_EEPROM_EEREGCAP_EN_KK_U2 |
3301 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
3304 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3305 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
3308 pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
3310 pCap->num_antcfg_5ghz =
3311 ath9k_hw_get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
3312 pCap->num_antcfg_2ghz =
3313 ath9k_hw_get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
3315 if (AR_SREV_9280_10_OR_LATER(ah) && btcoex_enable) {
3316 pCap->hw_caps |= ATH9K_HW_CAP_BT_COEX;
3317 ah->ah_btactive_gpio = 6;
3318 ah->ah_wlanactive_gpio = 5;
3324 bool ath9k_hw_getcapability(struct ath_hal *ah, enum ath9k_capability_type type,
3325 u32 capability, u32 *result)
3327 struct ath_hal_5416 *ahp = AH5416(ah);
3328 const struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
3331 case ATH9K_CAP_CIPHER:
3332 switch (capability) {
3333 case ATH9K_CIPHER_AES_CCM:
3334 case ATH9K_CIPHER_AES_OCB:
3335 case ATH9K_CIPHER_TKIP:
3336 case ATH9K_CIPHER_WEP:
3337 case ATH9K_CIPHER_MIC:
3338 case ATH9K_CIPHER_CLR:
3343 case ATH9K_CAP_TKIP_MIC:
3344 switch (capability) {
3348 return (ahp->ah_staId1Defaults &
3349 AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
3352 case ATH9K_CAP_TKIP_SPLIT:
3353 return (ahp->ah_miscMode & AR_PCU_MIC_NEW_LOC_ENA) ?
3355 case ATH9K_CAP_WME_TKIPMIC:
3357 case ATH9K_CAP_PHYCOUNTERS:
3358 return ahp->ah_hasHwPhyCounters ? 0 : -ENXIO;
3359 case ATH9K_CAP_DIVERSITY:
3360 return (REG_READ(ah, AR_PHY_CCK_DETECT) &
3361 AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV) ?
3363 case ATH9K_CAP_PHYDIAG:
3365 case ATH9K_CAP_MCAST_KEYSRCH:
3366 switch (capability) {
3370 if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
3373 return (ahp->ah_staId1Defaults &
3374 AR_STA_ID1_MCAST_KSRCH) ? true :
3379 case ATH9K_CAP_TSF_ADJUST:
3380 return (ahp->ah_miscMode & AR_PCU_TX_ADD_TSF) ?
3382 case ATH9K_CAP_RFSILENT:
3383 if (capability == 3)
3385 case ATH9K_CAP_ANT_CFG_2GHZ:
3386 *result = pCap->num_antcfg_2ghz;
3388 case ATH9K_CAP_ANT_CFG_5GHZ:
3389 *result = pCap->num_antcfg_5ghz;
3391 case ATH9K_CAP_TXPOW:
3392 switch (capability) {
3396 *result = ah->ah_powerLimit;
3399 *result = ah->ah_maxPowerLevel;
3402 *result = ah->ah_tpScale;
3411 bool ath9k_hw_setcapability(struct ath_hal *ah, enum ath9k_capability_type type,
3412 u32 capability, u32 setting, int *status)
3414 struct ath_hal_5416 *ahp = AH5416(ah);
3418 case ATH9K_CAP_TKIP_MIC:
3420 ahp->ah_staId1Defaults |=
3421 AR_STA_ID1_CRPT_MIC_ENABLE;
3423 ahp->ah_staId1Defaults &=
3424 ~AR_STA_ID1_CRPT_MIC_ENABLE;
3426 case ATH9K_CAP_DIVERSITY:
3427 v = REG_READ(ah, AR_PHY_CCK_DETECT);
3429 v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3431 v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3432 REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
3434 case ATH9K_CAP_MCAST_KEYSRCH:
3436 ahp->ah_staId1Defaults |= AR_STA_ID1_MCAST_KSRCH;
3438 ahp->ah_staId1Defaults &= ~AR_STA_ID1_MCAST_KSRCH;
3440 case ATH9K_CAP_TSF_ADJUST:
3442 ahp->ah_miscMode |= AR_PCU_TX_ADD_TSF;
3444 ahp->ah_miscMode &= ~AR_PCU_TX_ADD_TSF;
3451 /****************************/
3452 /* GPIO / RFKILL / Antennae */
3453 /****************************/
3455 static void ath9k_hw_gpio_cfg_output_mux(struct ath_hal *ah,
3459 u32 gpio_shift, tmp;
3462 addr = AR_GPIO_OUTPUT_MUX3;
3464 addr = AR_GPIO_OUTPUT_MUX2;
3466 addr = AR_GPIO_OUTPUT_MUX1;
3468 gpio_shift = (gpio % 6) * 5;
3470 if (AR_SREV_9280_20_OR_LATER(ah)
3471 || (addr != AR_GPIO_OUTPUT_MUX1)) {
3472 REG_RMW(ah, addr, (type << gpio_shift),
3473 (0x1f << gpio_shift));
3475 tmp = REG_READ(ah, addr);
3476 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
3477 tmp &= ~(0x1f << gpio_shift);
3478 tmp |= (type << gpio_shift);
3479 REG_WRITE(ah, addr, tmp);
3483 void ath9k_hw_cfg_gpio_input(struct ath_hal *ah, u32 gpio)
3487 ASSERT(gpio < ah->ah_caps.num_gpio_pins);
3489 gpio_shift = gpio << 1;
3493 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
3494 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3497 u32 ath9k_hw_gpio_get(struct ath_hal *ah, u32 gpio)
3499 #define MS_REG_READ(x, y) \
3500 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
3502 if (gpio >= ah->ah_caps.num_gpio_pins)
3505 if (AR_SREV_9285_10_OR_LATER(ah))
3506 return MS_REG_READ(AR9285, gpio) != 0;
3507 else if (AR_SREV_9280_10_OR_LATER(ah))
3508 return MS_REG_READ(AR928X, gpio) != 0;
3510 return MS_REG_READ(AR, gpio) != 0;
3513 void ath9k_hw_cfg_output(struct ath_hal *ah, u32 gpio,
3518 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
3520 gpio_shift = 2 * gpio;
3524 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
3525 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3528 void ath9k_hw_set_gpio(struct ath_hal *ah, u32 gpio, u32 val)
3530 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
3534 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
3535 void ath9k_enable_rfkill(struct ath_hal *ah)
3537 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
3538 AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
3540 REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2,
3541 AR_GPIO_INPUT_MUX2_RFSILENT);
3543 ath9k_hw_cfg_gpio_input(ah, ah->ah_rfkill_gpio);
3544 REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);
3548 u32 ath9k_hw_getdefantenna(struct ath_hal *ah)
3550 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
3553 void ath9k_hw_setantenna(struct ath_hal *ah, u32 antenna)
3555 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
3558 bool ath9k_hw_setantennaswitch(struct ath_hal *ah,
3559 enum ath9k_ant_setting settings,
3560 struct ath9k_channel *chan,
3565 struct ath_hal_5416 *ahp = AH5416(ah);
3566 static u8 tx_chainmask_cfg, rx_chainmask_cfg;
3568 if (AR_SREV_9280(ah)) {
3569 if (!tx_chainmask_cfg) {
3571 tx_chainmask_cfg = *tx_chainmask;
3572 rx_chainmask_cfg = *rx_chainmask;
3576 case ATH9K_ANT_FIXED_A:
3577 *tx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3578 *rx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3579 *antenna_cfgd = true;
3581 case ATH9K_ANT_FIXED_B:
3582 if (ah->ah_caps.tx_chainmask >
3583 ATH9K_ANTENNA1_CHAINMASK) {
3584 *tx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3586 *rx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3587 *antenna_cfgd = true;
3589 case ATH9K_ANT_VARIABLE:
3590 *tx_chainmask = tx_chainmask_cfg;
3591 *rx_chainmask = rx_chainmask_cfg;
3592 *antenna_cfgd = true;
3598 ahp->ah_diversityControl = settings;
3604 /*********************/
3605 /* General Operation */
3606 /*********************/
3608 u32 ath9k_hw_getrxfilter(struct ath_hal *ah)
3610 u32 bits = REG_READ(ah, AR_RX_FILTER);
3611 u32 phybits = REG_READ(ah, AR_PHY_ERR);
3613 if (phybits & AR_PHY_ERR_RADAR)
3614 bits |= ATH9K_RX_FILTER_PHYRADAR;
3615 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
3616 bits |= ATH9K_RX_FILTER_PHYERR;
3621 void ath9k_hw_setrxfilter(struct ath_hal *ah, u32 bits)
3625 REG_WRITE(ah, AR_RX_FILTER, (bits & 0xffff) | AR_RX_COMPR_BAR);
3627 if (bits & ATH9K_RX_FILTER_PHYRADAR)
3628 phybits |= AR_PHY_ERR_RADAR;
3629 if (bits & ATH9K_RX_FILTER_PHYERR)
3630 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
3631 REG_WRITE(ah, AR_PHY_ERR, phybits);
3634 REG_WRITE(ah, AR_RXCFG,
3635 REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
3637 REG_WRITE(ah, AR_RXCFG,
3638 REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
3641 bool ath9k_hw_phy_disable(struct ath_hal *ah)
3643 return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM);
3646 bool ath9k_hw_disable(struct ath_hal *ah)
3648 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
3651 return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD);
3654 bool ath9k_hw_set_txpowerlimit(struct ath_hal *ah, u32 limit)
3656 struct ath9k_channel *chan = ah->ah_curchan;
3657 struct ieee80211_channel *channel = chan->chan;
3659 ah->ah_powerLimit = min(limit, (u32) MAX_RATE_POWER);
3661 if (ath9k_hw_set_txpower(ah, chan,
3662 ath9k_regd_get_ctl(ah, chan),
3663 channel->max_antenna_gain * 2,
3664 channel->max_power * 2,
3665 min((u32) MAX_RATE_POWER,
3666 (u32) ah->ah_powerLimit)) != 0)
3672 void ath9k_hw_getmac(struct ath_hal *ah, u8 *mac)
3674 struct ath_hal_5416 *ahp = AH5416(ah);
3676 memcpy(mac, ahp->ah_macaddr, ETH_ALEN);
3679 bool ath9k_hw_setmac(struct ath_hal *ah, const u8 *mac)
3681 struct ath_hal_5416 *ahp = AH5416(ah);
3683 memcpy(ahp->ah_macaddr, mac, ETH_ALEN);
3688 void ath9k_hw_setopmode(struct ath_hal *ah)
3690 ath9k_hw_set_operating_mode(ah, ah->ah_opmode);
3693 void ath9k_hw_setmcastfilter(struct ath_hal *ah, u32 filter0, u32 filter1)
3695 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
3696 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
3699 void ath9k_hw_getbssidmask(struct ath_hal *ah, u8 *mask)
3701 struct ath_hal_5416 *ahp = AH5416(ah);
3703 memcpy(mask, ahp->ah_bssidmask, ETH_ALEN);
3706 bool ath9k_hw_setbssidmask(struct ath_hal *ah, const u8 *mask)
3708 struct ath_hal_5416 *ahp = AH5416(ah);
3710 memcpy(ahp->ah_bssidmask, mask, ETH_ALEN);
3712 REG_WRITE(ah, AR_BSSMSKL, get_unaligned_le32(ahp->ah_bssidmask));
3713 REG_WRITE(ah, AR_BSSMSKU, get_unaligned_le16(ahp->ah_bssidmask + 4));
3718 void ath9k_hw_write_associd(struct ath_hal *ah, const u8 *bssid, u16 assocId)
3720 struct ath_hal_5416 *ahp = AH5416(ah);
3722 memcpy(ahp->ah_bssid, bssid, ETH_ALEN);
3723 ahp->ah_assocId = assocId;
3725 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(ahp->ah_bssid));
3726 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(ahp->ah_bssid + 4) |
3727 ((assocId & 0x3fff) << AR_BSS_ID1_AID_S));
3730 u64 ath9k_hw_gettsf64(struct ath_hal *ah)
3734 tsf = REG_READ(ah, AR_TSF_U32);
3735 tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
3740 void ath9k_hw_settsf64(struct ath_hal *ah, u64 tsf64)
3742 REG_WRITE(ah, AR_TSF_L32, 0x00000000);
3743 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
3744 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
3747 void ath9k_hw_reset_tsf(struct ath_hal *ah)
3752 while (REG_READ(ah, AR_SLP32_MODE) & AR_SLP32_TSF_WRITE_STATUS) {
3755 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
3756 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
3761 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
3764 bool ath9k_hw_set_tsfadjust(struct ath_hal *ah, u32 setting)
3766 struct ath_hal_5416 *ahp = AH5416(ah);
3769 ahp->ah_miscMode |= AR_PCU_TX_ADD_TSF;
3771 ahp->ah_miscMode &= ~AR_PCU_TX_ADD_TSF;
3776 bool ath9k_hw_setslottime(struct ath_hal *ah, u32 us)
3778 struct ath_hal_5416 *ahp = AH5416(ah);
3780 if (us < ATH9K_SLOT_TIME_9 || us > ath9k_hw_mac_to_usec(ah, 0xffff)) {
3781 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "bad slot time %u\n", us);
3782 ahp->ah_slottime = (u32) -1;
3785 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, ath9k_hw_mac_to_clks(ah, us));
3786 ahp->ah_slottime = us;
3791 void ath9k_hw_set11nmac2040(struct ath_hal *ah, enum ath9k_ht_macmode mode)
3795 if (mode == ATH9K_HT_MACMODE_2040 &&
3796 !ah->ah_config.cwm_ignore_extcca)
3797 macmode = AR_2040_JOINED_RX_CLEAR;
3801 REG_WRITE(ah, AR_2040_MODE, macmode);
3804 /***************************/
3805 /* Bluetooth Coexistence */
3806 /***************************/
3808 void ath9k_hw_btcoex_enable(struct ath_hal *ah)
3810 /* connect bt_active to baseband */
3811 REG_CLR_BIT(ah, AR_GPIO_INPUT_EN_VAL,
3812 (AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_DEF |
3813 AR_GPIO_INPUT_EN_VAL_BT_FREQUENCY_DEF));
3815 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
3816 AR_GPIO_INPUT_EN_VAL_BT_ACTIVE_BB);
3818 /* Set input mux for bt_active to gpio pin */
3819 REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1,
3820 AR_GPIO_INPUT_MUX1_BT_ACTIVE,
3821 ah->ah_btactive_gpio);
3823 /* Configure the desired gpio port for input */
3824 ath9k_hw_cfg_gpio_input(ah, ah->ah_btactive_gpio);
3826 /* Configure the desired GPIO port for TX_FRAME output */
3827 ath9k_hw_cfg_output(ah, ah->ah_wlanactive_gpio,
3828 AR_GPIO_OUTPUT_MUX_AS_TX_FRAME);