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 const u8 CLOCK_RATE[] = { 40, 80, 22, 44, 88, 40 };
28 extern struct hal_percal_data iq_cal_multi_sample;
29 extern struct hal_percal_data iq_cal_single_sample;
30 extern struct hal_percal_data adc_gain_cal_multi_sample;
31 extern struct hal_percal_data adc_gain_cal_single_sample;
32 extern struct hal_percal_data adc_dc_cal_multi_sample;
33 extern struct hal_percal_data adc_dc_cal_single_sample;
34 extern struct hal_percal_data adc_init_dc_cal;
36 static bool ath9k_hw_set_reset_reg(struct ath_hal *ah, u32 type);
37 static void ath9k_hw_set_regs(struct ath_hal *ah, struct ath9k_channel *chan,
38 enum ath9k_ht_macmode macmode);
39 static u32 ath9k_hw_ini_fixup(struct ath_hal *ah,
40 struct ar5416_eeprom *pEepData,
42 static void ath9k_hw_9280_spur_mitigate(struct ath_hal *ah, struct ath9k_channel *chan);
43 static void ath9k_hw_spur_mitigate(struct ath_hal *ah, struct ath9k_channel *chan);
45 /********************/
46 /* Helper Functions */
47 /********************/
49 static u32 ath9k_hw_mac_usec(struct ath_hal *ah, u32 clks)
51 if (ah->ah_curchan != NULL)
52 return clks / CLOCK_RATE[ath9k_hw_chan2wmode(ah, ah->ah_curchan)];
54 return clks / CLOCK_RATE[ATH9K_MODE_11B];
57 static u32 ath9k_hw_mac_to_usec(struct ath_hal *ah, u32 clks)
59 struct ath9k_channel *chan = ah->ah_curchan;
61 if (chan && IS_CHAN_HT40(chan))
62 return ath9k_hw_mac_usec(ah, clks) / 2;
64 return ath9k_hw_mac_usec(ah, clks);
67 static u32 ath9k_hw_mac_clks(struct ath_hal *ah, u32 usecs)
69 if (ah->ah_curchan != NULL)
70 return usecs * CLOCK_RATE[ath9k_hw_chan2wmode(ah,
73 return usecs * CLOCK_RATE[ATH9K_MODE_11B];
76 static u32 ath9k_hw_mac_to_clks(struct ath_hal *ah, u32 usecs)
78 struct ath9k_channel *chan = ah->ah_curchan;
80 if (chan && IS_CHAN_HT40(chan))
81 return ath9k_hw_mac_clks(ah, usecs) * 2;
83 return ath9k_hw_mac_clks(ah, usecs);
86 enum wireless_mode ath9k_hw_chan2wmode(struct ath_hal *ah,
87 const struct ath9k_channel *chan)
89 if (IS_CHAN_CCK(chan))
90 return ATH9K_MODE_11A;
92 return ATH9K_MODE_11G;
93 return ATH9K_MODE_11A;
96 bool ath9k_hw_wait(struct ath_hal *ah, u32 reg, u32 mask, u32 val)
100 for (i = 0; i < (AH_TIMEOUT / AH_TIME_QUANTUM); i++) {
101 if ((REG_READ(ah, reg) & mask) == val)
104 udelay(AH_TIME_QUANTUM);
106 DPRINTF(ah->ah_sc, ATH_DBG_PHY_IO,
107 "%s: timeout on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
108 __func__, reg, REG_READ(ah, reg), mask, val);
113 u32 ath9k_hw_reverse_bits(u32 val, u32 n)
118 for (i = 0, retval = 0; i < n; i++) {
119 retval = (retval << 1) | (val & 1);
125 bool ath9k_get_channel_edges(struct ath_hal *ah,
129 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
131 if (flags & CHANNEL_5GHZ) {
132 *low = pCap->low_5ghz_chan;
133 *high = pCap->high_5ghz_chan;
136 if ((flags & CHANNEL_2GHZ)) {
137 *low = pCap->low_2ghz_chan;
138 *high = pCap->high_2ghz_chan;
144 u16 ath9k_hw_computetxtime(struct ath_hal *ah,
145 const struct ath9k_rate_table *rates,
146 u32 frameLen, u16 rateix,
149 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
152 kbps = rates->info[rateix].rateKbps;
157 switch (rates->info[rateix].phy) {
159 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
160 if (shortPreamble && rates->info[rateix].shortPreamble)
162 numBits = frameLen << 3;
163 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
166 if (ah->ah_curchan && IS_CHAN_QUARTER_RATE(ah->ah_curchan)) {
167 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
168 numBits = OFDM_PLCP_BITS + (frameLen << 3);
169 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
170 txTime = OFDM_SIFS_TIME_QUARTER
171 + OFDM_PREAMBLE_TIME_QUARTER
172 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
173 } else if (ah->ah_curchan &&
174 IS_CHAN_HALF_RATE(ah->ah_curchan)) {
175 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
176 numBits = OFDM_PLCP_BITS + (frameLen << 3);
177 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
178 txTime = OFDM_SIFS_TIME_HALF +
179 OFDM_PREAMBLE_TIME_HALF
180 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
182 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
183 numBits = OFDM_PLCP_BITS + (frameLen << 3);
184 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
185 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
186 + (numSymbols * OFDM_SYMBOL_TIME);
190 DPRINTF(ah->ah_sc, ATH_DBG_PHY_IO,
191 "%s: unknown phy %u (rate ix %u)\n", __func__,
192 rates->info[rateix].phy, rateix);
200 u32 ath9k_hw_mhz2ieee(struct ath_hal *ah, u32 freq, u32 flags)
202 if (flags & CHANNEL_2GHZ) {
206 return (freq - 2407) / 5;
208 return 15 + ((freq - 2512) / 20);
209 } else if (flags & CHANNEL_5GHZ) {
210 if (ath9k_regd_is_public_safety_sku(ah) &&
211 IS_CHAN_IN_PUBLIC_SAFETY_BAND(freq)) {
212 return ((freq * 10) +
213 (((freq % 5) == 2) ? 5 : 0) - 49400) / 5;
214 } else if ((flags & CHANNEL_A) && (freq <= 5000)) {
215 return (freq - 4000) / 5;
217 return (freq - 5000) / 5;
223 return (freq - 2407) / 5;
225 if (ath9k_regd_is_public_safety_sku(ah)
226 && IS_CHAN_IN_PUBLIC_SAFETY_BAND(freq)) {
227 return ((freq * 10) +
229 2) ? 5 : 0) - 49400) / 5;
230 } else if (freq > 4900) {
231 return (freq - 4000) / 5;
233 return 15 + ((freq - 2512) / 20);
236 return (freq - 5000) / 5;
240 void ath9k_hw_get_channel_centers(struct ath_hal *ah,
241 struct ath9k_channel *chan,
242 struct chan_centers *centers)
245 struct ath_hal_5416 *ahp = AH5416(ah);
247 if (!IS_CHAN_HT40(chan)) {
248 centers->ctl_center = centers->ext_center =
249 centers->synth_center = chan->channel;
253 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
254 (chan->chanmode == CHANNEL_G_HT40PLUS)) {
255 centers->synth_center =
256 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
259 centers->synth_center =
260 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
264 centers->ctl_center =
265 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
266 centers->ext_center =
267 centers->synth_center + (extoff *
268 ((ahp->ah_extprotspacing == ATH9K_HT_EXTPROTSPACING_20) ?
269 HT40_CHANNEL_CENTER_SHIFT : 15));
277 static void ath9k_hw_read_revisions(struct ath_hal *ah)
281 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
284 val = REG_READ(ah, AR_SREV);
285 ah->ah_macVersion = (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
286 ah->ah_macRev = MS(val, AR_SREV_REVISION2);
287 ah->ah_isPciExpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
289 if (!AR_SREV_9100(ah))
290 ah->ah_macVersion = MS(val, AR_SREV_VERSION);
292 ah->ah_macRev = val & AR_SREV_REVISION;
294 if (ah->ah_macVersion == AR_SREV_VERSION_5416_PCIE)
295 ah->ah_isPciExpress = true;
299 static int ath9k_hw_get_radiorev(struct ath_hal *ah)
304 REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
306 for (i = 0; i < 8; i++)
307 REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
308 val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
309 val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
311 return ath9k_hw_reverse_bits(val, 8);
314 /************************************/
315 /* HW Attach, Detach, Init Routines */
316 /************************************/
318 static void ath9k_hw_disablepcie(struct ath_hal *ah)
320 if (!AR_SREV_9100(ah))
323 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
324 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
325 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
326 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
327 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
328 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
329 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
330 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
331 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
333 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
336 static bool ath9k_hw_chip_test(struct ath_hal *ah)
338 u32 regAddr[2] = { AR_STA_ID0, AR_PHY_BASE + (8 << 2) };
340 u32 patternData[4] = { 0x55555555,
346 for (i = 0; i < 2; i++) {
347 u32 addr = regAddr[i];
350 regHold[i] = REG_READ(ah, addr);
351 for (j = 0; j < 0x100; j++) {
352 wrData = (j << 16) | j;
353 REG_WRITE(ah, addr, wrData);
354 rdData = REG_READ(ah, addr);
355 if (rdData != wrData) {
356 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
357 "%s: address test failed "
358 "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
359 __func__, addr, wrData, rdData);
363 for (j = 0; j < 4; j++) {
364 wrData = patternData[j];
365 REG_WRITE(ah, addr, wrData);
366 rdData = REG_READ(ah, addr);
367 if (wrData != rdData) {
368 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
369 "%s: address test failed "
370 "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
371 __func__, addr, wrData, rdData);
375 REG_WRITE(ah, regAddr[i], regHold[i]);
381 static const char *ath9k_hw_devname(u16 devid)
384 case AR5416_DEVID_PCI:
385 case AR5416_DEVID_PCIE:
386 return "Atheros 5416";
387 case AR9160_DEVID_PCI:
388 return "Atheros 9160";
389 case AR9280_DEVID_PCI:
390 case AR9280_DEVID_PCIE:
391 return "Atheros 9280";
397 static void ath9k_hw_set_defaults(struct ath_hal *ah)
401 ah->ah_config.dma_beacon_response_time = 2;
402 ah->ah_config.sw_beacon_response_time = 10;
403 ah->ah_config.additional_swba_backoff = 0;
404 ah->ah_config.ack_6mb = 0x0;
405 ah->ah_config.cwm_ignore_extcca = 0;
406 ah->ah_config.pcie_powersave_enable = 0;
407 ah->ah_config.pcie_l1skp_enable = 0;
408 ah->ah_config.pcie_clock_req = 0;
409 ah->ah_config.pcie_power_reset = 0x100;
410 ah->ah_config.pcie_restore = 0;
411 ah->ah_config.pcie_waen = 0;
412 ah->ah_config.analog_shiftreg = 1;
413 ah->ah_config.ht_enable = 1;
414 ah->ah_config.ofdm_trig_low = 200;
415 ah->ah_config.ofdm_trig_high = 500;
416 ah->ah_config.cck_trig_high = 200;
417 ah->ah_config.cck_trig_low = 100;
418 ah->ah_config.enable_ani = 1;
419 ah->ah_config.noise_immunity_level = 4;
420 ah->ah_config.ofdm_weaksignal_det = 1;
421 ah->ah_config.cck_weaksignal_thr = 0;
422 ah->ah_config.spur_immunity_level = 2;
423 ah->ah_config.firstep_level = 0;
424 ah->ah_config.rssi_thr_high = 40;
425 ah->ah_config.rssi_thr_low = 7;
426 ah->ah_config.diversity_control = 0;
427 ah->ah_config.antenna_switch_swap = 0;
429 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
430 ah->ah_config.spurchans[i][0] = AR_NO_SPUR;
431 ah->ah_config.spurchans[i][1] = AR_NO_SPUR;
434 ah->ah_config.intr_mitigation = 1;
437 static struct ath_hal_5416 *ath9k_hw_newstate(u16 devid,
438 struct ath_softc *sc,
442 static const u8 defbssidmask[ETH_ALEN] =
443 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
444 struct ath_hal_5416 *ahp;
447 ahp = kzalloc(sizeof(struct ath_hal_5416), GFP_KERNEL);
449 DPRINTF(sc, ATH_DBG_FATAL,
450 "%s: cannot allocate memory for state block\n",
459 ah->ah_magic = AR5416_MAGIC;
460 ah->ah_countryCode = CTRY_DEFAULT;
461 ah->ah_devid = devid;
462 ah->ah_subvendorid = 0;
465 if ((devid == AR5416_AR9100_DEVID))
466 ah->ah_macVersion = AR_SREV_VERSION_9100;
467 if (!AR_SREV_9100(ah))
468 ah->ah_flags = AH_USE_EEPROM;
470 ah->ah_powerLimit = MAX_RATE_POWER;
471 ah->ah_tpScale = ATH9K_TP_SCALE_MAX;
472 ahp->ah_atimWindow = 0;
473 ahp->ah_diversityControl = ah->ah_config.diversity_control;
474 ahp->ah_antennaSwitchSwap =
475 ah->ah_config.antenna_switch_swap;
476 ahp->ah_staId1Defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
477 ahp->ah_beaconInterval = 100;
478 ahp->ah_enable32kHzClock = DONT_USE_32KHZ;
479 ahp->ah_slottime = (u32) -1;
480 ahp->ah_acktimeout = (u32) -1;
481 ahp->ah_ctstimeout = (u32) -1;
482 ahp->ah_globaltxtimeout = (u32) -1;
483 memcpy(&ahp->ah_bssidmask, defbssidmask, ETH_ALEN);
485 ahp->ah_gBeaconRate = 0;
490 static int ath9k_hw_rfattach(struct ath_hal *ah)
492 bool rfStatus = false;
495 rfStatus = ath9k_hw_init_rf(ah, &ecode);
497 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
498 "%s: RF setup failed, status %u\n", __func__,
506 static int ath9k_hw_rf_claim(struct ath_hal *ah)
510 REG_WRITE(ah, AR_PHY(0), 0x00000007);
512 val = ath9k_hw_get_radiorev(ah);
513 switch (val & AR_RADIO_SREV_MAJOR) {
515 val = AR_RAD5133_SREV_MAJOR;
517 case AR_RAD5133_SREV_MAJOR:
518 case AR_RAD5122_SREV_MAJOR:
519 case AR_RAD2133_SREV_MAJOR:
520 case AR_RAD2122_SREV_MAJOR:
523 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
524 "%s: 5G Radio Chip Rev 0x%02X is not "
525 "supported by this driver\n",
526 __func__, ah->ah_analog5GhzRev);
530 ah->ah_analog5GhzRev = val;
535 static int ath9k_hw_init_macaddr(struct ath_hal *ah)
540 struct ath_hal_5416 *ahp = AH5416(ah);
543 for (i = 0; i < 3; i++) {
544 eeval = ath9k_hw_get_eeprom(ah, AR_EEPROM_MAC(i));
546 ahp->ah_macaddr[2 * i] = eeval >> 8;
547 ahp->ah_macaddr[2 * i + 1] = eeval & 0xff;
549 if (sum == 0 || sum == 0xffff * 3) {
550 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
551 "%s: mac address read failed: %pM\n", __func__,
553 return -EADDRNOTAVAIL;
559 static int ath9k_hw_post_attach(struct ath_hal *ah)
563 if (!ath9k_hw_chip_test(ah)) {
564 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
565 "%s: hardware self-test failed\n", __func__);
569 ecode = ath9k_hw_rf_claim(ah);
573 ecode = ath9k_hw_eeprom_attach(ah);
576 ecode = ath9k_hw_rfattach(ah);
580 if (!AR_SREV_9100(ah)) {
581 ath9k_hw_ani_setup(ah);
582 ath9k_hw_ani_attach(ah);
588 static struct ath_hal *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc,
589 void __iomem *mem, int *status)
591 struct ath_hal_5416 *ahp;
594 #ifndef CONFIG_SLOW_ANT_DIV
599 ahp = ath9k_hw_newstate(devid, sc, mem, status);
605 ath9k_hw_set_defaults(ah);
607 if (ah->ah_config.intr_mitigation != 0)
608 ahp->ah_intrMitigation = true;
610 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
611 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "%s: couldn't reset chip\n",
617 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
618 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "%s: couldn't wakeup chip\n",
624 if (ah->ah_config.serialize_regmode == SER_REG_MODE_AUTO) {
625 if (ah->ah_macVersion == AR_SREV_VERSION_5416_PCI) {
626 ah->ah_config.serialize_regmode =
629 ah->ah_config.serialize_regmode =
634 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
635 "%s: serialize_regmode is %d\n",
636 __func__, ah->ah_config.serialize_regmode);
638 if ((ah->ah_macVersion != AR_SREV_VERSION_5416_PCI) &&
639 (ah->ah_macVersion != AR_SREV_VERSION_5416_PCIE) &&
640 (ah->ah_macVersion != AR_SREV_VERSION_9160) &&
641 (!AR_SREV_9100(ah)) && (!AR_SREV_9280(ah))) {
642 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
643 "%s: Mac Chip Rev 0x%02x.%x is not supported by "
644 "this driver\n", __func__,
645 ah->ah_macVersion, ah->ah_macRev);
650 if (AR_SREV_9100(ah)) {
651 ahp->ah_iqCalData.calData = &iq_cal_multi_sample;
652 ahp->ah_suppCals = IQ_MISMATCH_CAL;
653 ah->ah_isPciExpress = false;
655 ah->ah_phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
657 if (AR_SREV_9160_10_OR_LATER(ah)) {
658 if (AR_SREV_9280_10_OR_LATER(ah)) {
659 ahp->ah_iqCalData.calData = &iq_cal_single_sample;
660 ahp->ah_adcGainCalData.calData =
661 &adc_gain_cal_single_sample;
662 ahp->ah_adcDcCalData.calData =
663 &adc_dc_cal_single_sample;
664 ahp->ah_adcDcCalInitData.calData =
667 ahp->ah_iqCalData.calData = &iq_cal_multi_sample;
668 ahp->ah_adcGainCalData.calData =
669 &adc_gain_cal_multi_sample;
670 ahp->ah_adcDcCalData.calData =
671 &adc_dc_cal_multi_sample;
672 ahp->ah_adcDcCalInitData.calData =
675 ahp->ah_suppCals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
678 if (AR_SREV_9160(ah)) {
679 ah->ah_config.enable_ani = 1;
680 ahp->ah_ani_function = (ATH9K_ANI_SPUR_IMMUNITY_LEVEL |
681 ATH9K_ANI_FIRSTEP_LEVEL);
683 ahp->ah_ani_function = ATH9K_ANI_ALL;
684 if (AR_SREV_9280_10_OR_LATER(ah)) {
685 ahp->ah_ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
689 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
690 "%s: This Mac Chip Rev 0x%02x.%x is \n", __func__,
691 ah->ah_macVersion, ah->ah_macRev);
693 if (AR_SREV_9280_20_OR_LATER(ah)) {
694 INIT_INI_ARRAY(&ahp->ah_iniModes, ar9280Modes_9280_2,
695 ARRAY_SIZE(ar9280Modes_9280_2), 6);
696 INIT_INI_ARRAY(&ahp->ah_iniCommon, ar9280Common_9280_2,
697 ARRAY_SIZE(ar9280Common_9280_2), 2);
699 if (ah->ah_config.pcie_clock_req) {
700 INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
701 ar9280PciePhy_clkreq_off_L1_9280,
702 ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2);
704 INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
705 ar9280PciePhy_clkreq_always_on_L1_9280,
706 ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
708 INIT_INI_ARRAY(&ahp->ah_iniModesAdditional,
709 ar9280Modes_fast_clock_9280_2,
710 ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
711 } else if (AR_SREV_9280_10_OR_LATER(ah)) {
712 INIT_INI_ARRAY(&ahp->ah_iniModes, ar9280Modes_9280,
713 ARRAY_SIZE(ar9280Modes_9280), 6);
714 INIT_INI_ARRAY(&ahp->ah_iniCommon, ar9280Common_9280,
715 ARRAY_SIZE(ar9280Common_9280), 2);
716 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
717 INIT_INI_ARRAY(&ahp->ah_iniModes, ar5416Modes_9160,
718 ARRAY_SIZE(ar5416Modes_9160), 6);
719 INIT_INI_ARRAY(&ahp->ah_iniCommon, ar5416Common_9160,
720 ARRAY_SIZE(ar5416Common_9160), 2);
721 INIT_INI_ARRAY(&ahp->ah_iniBank0, ar5416Bank0_9160,
722 ARRAY_SIZE(ar5416Bank0_9160), 2);
723 INIT_INI_ARRAY(&ahp->ah_iniBB_RfGain, ar5416BB_RfGain_9160,
724 ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
725 INIT_INI_ARRAY(&ahp->ah_iniBank1, ar5416Bank1_9160,
726 ARRAY_SIZE(ar5416Bank1_9160), 2);
727 INIT_INI_ARRAY(&ahp->ah_iniBank2, ar5416Bank2_9160,
728 ARRAY_SIZE(ar5416Bank2_9160), 2);
729 INIT_INI_ARRAY(&ahp->ah_iniBank3, ar5416Bank3_9160,
730 ARRAY_SIZE(ar5416Bank3_9160), 3);
731 INIT_INI_ARRAY(&ahp->ah_iniBank6, ar5416Bank6_9160,
732 ARRAY_SIZE(ar5416Bank6_9160), 3);
733 INIT_INI_ARRAY(&ahp->ah_iniBank6TPC, ar5416Bank6TPC_9160,
734 ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
735 INIT_INI_ARRAY(&ahp->ah_iniBank7, ar5416Bank7_9160,
736 ARRAY_SIZE(ar5416Bank7_9160), 2);
737 if (AR_SREV_9160_11(ah)) {
738 INIT_INI_ARRAY(&ahp->ah_iniAddac,
740 ARRAY_SIZE(ar5416Addac_91601_1), 2);
742 INIT_INI_ARRAY(&ahp->ah_iniAddac, ar5416Addac_9160,
743 ARRAY_SIZE(ar5416Addac_9160), 2);
745 } else if (AR_SREV_9100_OR_LATER(ah)) {
746 INIT_INI_ARRAY(&ahp->ah_iniModes, ar5416Modes_9100,
747 ARRAY_SIZE(ar5416Modes_9100), 6);
748 INIT_INI_ARRAY(&ahp->ah_iniCommon, ar5416Common_9100,
749 ARRAY_SIZE(ar5416Common_9100), 2);
750 INIT_INI_ARRAY(&ahp->ah_iniBank0, ar5416Bank0_9100,
751 ARRAY_SIZE(ar5416Bank0_9100), 2);
752 INIT_INI_ARRAY(&ahp->ah_iniBB_RfGain, ar5416BB_RfGain_9100,
753 ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
754 INIT_INI_ARRAY(&ahp->ah_iniBank1, ar5416Bank1_9100,
755 ARRAY_SIZE(ar5416Bank1_9100), 2);
756 INIT_INI_ARRAY(&ahp->ah_iniBank2, ar5416Bank2_9100,
757 ARRAY_SIZE(ar5416Bank2_9100), 2);
758 INIT_INI_ARRAY(&ahp->ah_iniBank3, ar5416Bank3_9100,
759 ARRAY_SIZE(ar5416Bank3_9100), 3);
760 INIT_INI_ARRAY(&ahp->ah_iniBank6, ar5416Bank6_9100,
761 ARRAY_SIZE(ar5416Bank6_9100), 3);
762 INIT_INI_ARRAY(&ahp->ah_iniBank6TPC, ar5416Bank6TPC_9100,
763 ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
764 INIT_INI_ARRAY(&ahp->ah_iniBank7, ar5416Bank7_9100,
765 ARRAY_SIZE(ar5416Bank7_9100), 2);
766 INIT_INI_ARRAY(&ahp->ah_iniAddac, ar5416Addac_9100,
767 ARRAY_SIZE(ar5416Addac_9100), 2);
769 INIT_INI_ARRAY(&ahp->ah_iniModes, ar5416Modes,
770 ARRAY_SIZE(ar5416Modes), 6);
771 INIT_INI_ARRAY(&ahp->ah_iniCommon, ar5416Common,
772 ARRAY_SIZE(ar5416Common), 2);
773 INIT_INI_ARRAY(&ahp->ah_iniBank0, ar5416Bank0,
774 ARRAY_SIZE(ar5416Bank0), 2);
775 INIT_INI_ARRAY(&ahp->ah_iniBB_RfGain, ar5416BB_RfGain,
776 ARRAY_SIZE(ar5416BB_RfGain), 3);
777 INIT_INI_ARRAY(&ahp->ah_iniBank1, ar5416Bank1,
778 ARRAY_SIZE(ar5416Bank1), 2);
779 INIT_INI_ARRAY(&ahp->ah_iniBank2, ar5416Bank2,
780 ARRAY_SIZE(ar5416Bank2), 2);
781 INIT_INI_ARRAY(&ahp->ah_iniBank3, ar5416Bank3,
782 ARRAY_SIZE(ar5416Bank3), 3);
783 INIT_INI_ARRAY(&ahp->ah_iniBank6, ar5416Bank6,
784 ARRAY_SIZE(ar5416Bank6), 3);
785 INIT_INI_ARRAY(&ahp->ah_iniBank6TPC, ar5416Bank6TPC,
786 ARRAY_SIZE(ar5416Bank6TPC), 3);
787 INIT_INI_ARRAY(&ahp->ah_iniBank7, ar5416Bank7,
788 ARRAY_SIZE(ar5416Bank7), 2);
789 INIT_INI_ARRAY(&ahp->ah_iniAddac, ar5416Addac,
790 ARRAY_SIZE(ar5416Addac), 2);
793 if (ah->ah_isPciExpress)
794 ath9k_hw_configpcipowersave(ah, 0);
796 ath9k_hw_disablepcie(ah);
798 ecode = ath9k_hw_post_attach(ah);
802 #ifndef CONFIG_SLOW_ANT_DIV
803 if (ah->ah_devid == AR9280_DEVID_PCI) {
804 for (i = 0; i < ahp->ah_iniModes.ia_rows; i++) {
805 u32 reg = INI_RA(&ahp->ah_iniModes, i, 0);
807 for (j = 1; j < ahp->ah_iniModes.ia_columns; j++) {
808 u32 val = INI_RA(&ahp->ah_iniModes, i, j);
810 INI_RA(&ahp->ah_iniModes, i, j) =
811 ath9k_hw_ini_fixup(ah, &ahp->ah_eeprom,
817 if (!ath9k_hw_fill_cap_info(ah)) {
818 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
819 "%s:failed ath9k_hw_fill_cap_info\n", __func__);
824 ecode = ath9k_hw_init_macaddr(ah);
826 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
827 "%s: failed initializing mac address\n",
832 if (AR_SREV_9285(ah))
833 ah->ah_txTrigLevel = (AR_FTRIG_256B >> AR_FTRIG_S);
835 ah->ah_txTrigLevel = (AR_FTRIG_512B >> AR_FTRIG_S);
837 ath9k_init_nfcal_hist_buffer(ah);
842 ath9k_hw_detach((struct ath_hal *) ahp);
849 static void ath9k_hw_init_bb(struct ath_hal *ah,
850 struct ath9k_channel *chan)
854 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
855 if (IS_CHAN_CCK(chan))
856 synthDelay = (4 * synthDelay) / 22;
860 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
862 udelay(synthDelay + BASE_ACTIVATE_DELAY);
865 static void ath9k_hw_init_qos(struct ath_hal *ah)
867 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
868 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
870 REG_WRITE(ah, AR_QOS_NO_ACK,
871 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
872 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
873 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
875 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
876 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
877 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
878 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
879 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
882 static void ath9k_hw_init_pll(struct ath_hal *ah,
883 struct ath9k_channel *chan)
887 if (AR_SREV_9100(ah)) {
888 if (chan && IS_CHAN_5GHZ(chan))
893 if (AR_SREV_9280_10_OR_LATER(ah)) {
894 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
896 if (chan && IS_CHAN_HALF_RATE(chan))
897 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
898 else if (chan && IS_CHAN_QUARTER_RATE(chan))
899 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
901 if (chan && IS_CHAN_5GHZ(chan)) {
902 pll |= SM(0x28, AR_RTC_9160_PLL_DIV);
905 if (AR_SREV_9280_20(ah)) {
906 if (((chan->channel % 20) == 0)
907 || ((chan->channel % 10) == 0))
913 pll |= SM(0x2c, AR_RTC_9160_PLL_DIV);
916 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
918 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
920 if (chan && IS_CHAN_HALF_RATE(chan))
921 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
922 else if (chan && IS_CHAN_QUARTER_RATE(chan))
923 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
925 if (chan && IS_CHAN_5GHZ(chan))
926 pll |= SM(0x50, AR_RTC_9160_PLL_DIV);
928 pll |= SM(0x58, AR_RTC_9160_PLL_DIV);
930 pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2;
932 if (chan && IS_CHAN_HALF_RATE(chan))
933 pll |= SM(0x1, AR_RTC_PLL_CLKSEL);
934 else if (chan && IS_CHAN_QUARTER_RATE(chan))
935 pll |= SM(0x2, AR_RTC_PLL_CLKSEL);
937 if (chan && IS_CHAN_5GHZ(chan))
938 pll |= SM(0xa, AR_RTC_PLL_DIV);
940 pll |= SM(0xb, AR_RTC_PLL_DIV);
943 REG_WRITE(ah, (u16) (AR_RTC_PLL_CONTROL), pll);
945 udelay(RTC_PLL_SETTLE_DELAY);
947 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
950 static void ath9k_hw_init_chain_masks(struct ath_hal *ah)
952 struct ath_hal_5416 *ahp = AH5416(ah);
953 int rx_chainmask, tx_chainmask;
955 rx_chainmask = ahp->ah_rxchainmask;
956 tx_chainmask = ahp->ah_txchainmask;
958 switch (rx_chainmask) {
960 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
961 AR_PHY_SWAP_ALT_CHAIN);
963 if (((ah)->ah_macVersion <= AR_SREV_VERSION_9160)) {
964 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7);
965 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7);
970 if (!AR_SREV_9280(ah))
973 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
974 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
980 REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);
981 if (tx_chainmask == 0x5) {
982 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
983 AR_PHY_SWAP_ALT_CHAIN);
985 if (AR_SREV_9100(ah))
986 REG_WRITE(ah, AR_PHY_ANALOG_SWAP,
987 REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
990 static void ath9k_hw_init_interrupt_masks(struct ath_hal *ah, enum ath9k_opmode opmode)
992 struct ath_hal_5416 *ahp = AH5416(ah);
994 ahp->ah_maskReg = AR_IMR_TXERR |
1000 if (ahp->ah_intrMitigation)
1001 ahp->ah_maskReg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
1003 ahp->ah_maskReg |= AR_IMR_RXOK;
1005 ahp->ah_maskReg |= AR_IMR_TXOK;
1007 if (opmode == ATH9K_M_HOSTAP)
1008 ahp->ah_maskReg |= AR_IMR_MIB;
1010 REG_WRITE(ah, AR_IMR, ahp->ah_maskReg);
1011 REG_WRITE(ah, AR_IMR_S2, REG_READ(ah, AR_IMR_S2) | AR_IMR_S2_GTT);
1013 if (!AR_SREV_9100(ah)) {
1014 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
1015 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
1016 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
1020 static bool ath9k_hw_set_ack_timeout(struct ath_hal *ah, u32 us)
1022 struct ath_hal_5416 *ahp = AH5416(ah);
1024 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) {
1025 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "%s: bad ack timeout %u\n",
1027 ahp->ah_acktimeout = (u32) -1;
1030 REG_RMW_FIELD(ah, AR_TIME_OUT,
1031 AR_TIME_OUT_ACK, ath9k_hw_mac_to_clks(ah, us));
1032 ahp->ah_acktimeout = us;
1037 static bool ath9k_hw_set_cts_timeout(struct ath_hal *ah, u32 us)
1039 struct ath_hal_5416 *ahp = AH5416(ah);
1041 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_CTS))) {
1042 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "%s: bad cts timeout %u\n",
1044 ahp->ah_ctstimeout = (u32) -1;
1047 REG_RMW_FIELD(ah, AR_TIME_OUT,
1048 AR_TIME_OUT_CTS, ath9k_hw_mac_to_clks(ah, us));
1049 ahp->ah_ctstimeout = us;
1054 static bool ath9k_hw_set_global_txtimeout(struct ath_hal *ah, u32 tu)
1056 struct ath_hal_5416 *ahp = AH5416(ah);
1059 DPRINTF(ah->ah_sc, ATH_DBG_XMIT,
1060 "%s: bad global tx timeout %u\n", __func__, tu);
1061 ahp->ah_globaltxtimeout = (u32) -1;
1064 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
1065 ahp->ah_globaltxtimeout = tu;
1070 static void ath9k_hw_init_user_settings(struct ath_hal *ah)
1072 struct ath_hal_5416 *ahp = AH5416(ah);
1074 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "--AP %s ahp->ah_miscMode 0x%x\n",
1075 __func__, ahp->ah_miscMode);
1077 if (ahp->ah_miscMode != 0)
1078 REG_WRITE(ah, AR_PCU_MISC,
1079 REG_READ(ah, AR_PCU_MISC) | ahp->ah_miscMode);
1080 if (ahp->ah_slottime != (u32) -1)
1081 ath9k_hw_setslottime(ah, ahp->ah_slottime);
1082 if (ahp->ah_acktimeout != (u32) -1)
1083 ath9k_hw_set_ack_timeout(ah, ahp->ah_acktimeout);
1084 if (ahp->ah_ctstimeout != (u32) -1)
1085 ath9k_hw_set_cts_timeout(ah, ahp->ah_ctstimeout);
1086 if (ahp->ah_globaltxtimeout != (u32) -1)
1087 ath9k_hw_set_global_txtimeout(ah, ahp->ah_globaltxtimeout);
1090 const char *ath9k_hw_probe(u16 vendorid, u16 devid)
1092 return vendorid == ATHEROS_VENDOR_ID ?
1093 ath9k_hw_devname(devid) : NULL;
1096 void ath9k_hw_detach(struct ath_hal *ah)
1098 if (!AR_SREV_9100(ah))
1099 ath9k_hw_ani_detach(ah);
1101 ath9k_hw_rfdetach(ah);
1102 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
1106 struct ath_hal *ath9k_hw_attach(u16 devid, struct ath_softc *sc,
1107 void __iomem *mem, int *error)
1109 struct ath_hal *ah = NULL;
1112 case AR5416_DEVID_PCI:
1113 case AR5416_DEVID_PCIE:
1114 case AR9160_DEVID_PCI:
1115 case AR9280_DEVID_PCI:
1116 case AR9280_DEVID_PCIE:
1117 ah = ath9k_hw_do_attach(devid, sc, mem, error);
1120 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
1121 "devid=0x%x not supported.\n", devid);
1134 static void ath9k_hw_override_ini(struct ath_hal *ah,
1135 struct ath9k_channel *chan)
1137 if (!AR_SREV_5416_V20_OR_LATER(ah) ||
1138 AR_SREV_9280_10_OR_LATER(ah))
1141 REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
1144 static u32 ath9k_hw_ini_fixup(struct ath_hal *ah,
1145 struct ar5416_eeprom *pEepData,
1148 struct base_eep_header *pBase = &(pEepData->baseEepHeader);
1150 switch (ah->ah_devid) {
1151 case AR9280_DEVID_PCI:
1152 if (reg == 0x7894) {
1153 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
1154 "ini VAL: %x EEPROM: %x\n", value,
1155 (pBase->version & 0xff));
1157 if ((pBase->version & 0xff) > 0x0a) {
1158 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
1161 value &= ~AR_AN_TOP2_PWDCLKIND;
1162 value |= AR_AN_TOP2_PWDCLKIND &
1163 (pBase->pwdclkind << AR_AN_TOP2_PWDCLKIND_S);
1165 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
1166 "PWDCLKIND Earlier Rev\n");
1169 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
1170 "final ini VAL: %x\n", value);
1178 static int ath9k_hw_process_ini(struct ath_hal *ah,
1179 struct ath9k_channel *chan,
1180 enum ath9k_ht_macmode macmode)
1182 int i, regWrites = 0;
1183 struct ath_hal_5416 *ahp = AH5416(ah);
1184 u32 modesIndex, freqIndex;
1187 switch (chan->chanmode) {
1189 case CHANNEL_A_HT20:
1193 case CHANNEL_A_HT40PLUS:
1194 case CHANNEL_A_HT40MINUS:
1199 case CHANNEL_G_HT20:
1204 case CHANNEL_G_HT40PLUS:
1205 case CHANNEL_G_HT40MINUS:
1214 REG_WRITE(ah, AR_PHY(0), 0x00000007);
1216 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
1218 ath9k_hw_set_addac(ah, chan);
1220 if (AR_SREV_5416_V22_OR_LATER(ah)) {
1221 REG_WRITE_ARRAY(&ahp->ah_iniAddac, 1, regWrites);
1223 struct ar5416IniArray temp;
1225 sizeof(u32) * ahp->ah_iniAddac.ia_rows *
1226 ahp->ah_iniAddac.ia_columns;
1228 memcpy(ahp->ah_addac5416_21,
1229 ahp->ah_iniAddac.ia_array, addacSize);
1231 (ahp->ah_addac5416_21)[31 * ahp->ah_iniAddac.ia_columns + 1] = 0;
1233 temp.ia_array = ahp->ah_addac5416_21;
1234 temp.ia_columns = ahp->ah_iniAddac.ia_columns;
1235 temp.ia_rows = ahp->ah_iniAddac.ia_rows;
1236 REG_WRITE_ARRAY(&temp, 1, regWrites);
1239 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
1241 for (i = 0; i < ahp->ah_iniModes.ia_rows; i++) {
1242 u32 reg = INI_RA(&ahp->ah_iniModes, i, 0);
1243 u32 val = INI_RA(&ahp->ah_iniModes, i, modesIndex);
1245 #ifdef CONFIG_SLOW_ANT_DIV
1246 if (ah->ah_devid == AR9280_DEVID_PCI)
1247 val = ath9k_hw_ini_fixup(ah, &ahp->ah_eeprom, reg, val);
1250 REG_WRITE(ah, reg, val);
1252 if (reg >= 0x7800 && reg < 0x78a0
1253 && ah->ah_config.analog_shiftreg) {
1257 DO_DELAY(regWrites);
1260 for (i = 0; i < ahp->ah_iniCommon.ia_rows; i++) {
1261 u32 reg = INI_RA(&ahp->ah_iniCommon, i, 0);
1262 u32 val = INI_RA(&ahp->ah_iniCommon, i, 1);
1264 REG_WRITE(ah, reg, val);
1266 if (reg >= 0x7800 && reg < 0x78a0
1267 && ah->ah_config.analog_shiftreg) {
1271 DO_DELAY(regWrites);
1274 ath9k_hw_write_regs(ah, modesIndex, freqIndex, regWrites);
1276 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan)) {
1277 REG_WRITE_ARRAY(&ahp->ah_iniModesAdditional, modesIndex,
1281 ath9k_hw_override_ini(ah, chan);
1282 ath9k_hw_set_regs(ah, chan, macmode);
1283 ath9k_hw_init_chain_masks(ah);
1285 status = ath9k_hw_set_txpower(ah, chan,
1286 ath9k_regd_get_ctl(ah, chan),
1287 ath9k_regd_get_antenna_allowed(ah,
1289 chan->maxRegTxPower * 2,
1290 min((u32) MAX_RATE_POWER,
1291 (u32) ah->ah_powerLimit));
1293 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
1294 "%s: error init'ing transmit power\n", __func__);
1298 if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
1299 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
1300 "%s: ar5416SetRfRegs failed\n", __func__);
1307 /****************************************/
1308 /* Reset and Channel Switching Routines */
1309 /****************************************/
1311 static void ath9k_hw_set_rfmode(struct ath_hal *ah, struct ath9k_channel *chan)
1318 rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
1319 ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
1321 if (!AR_SREV_9280_10_OR_LATER(ah))
1322 rfMode |= (IS_CHAN_5GHZ(chan)) ?
1323 AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ;
1325 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan))
1326 rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
1328 REG_WRITE(ah, AR_PHY_MODE, rfMode);
1331 static void ath9k_hw_mark_phy_inactive(struct ath_hal *ah)
1333 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
1336 static inline void ath9k_hw_set_dma(struct ath_hal *ah)
1340 regval = REG_READ(ah, AR_AHB_MODE);
1341 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
1343 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
1344 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
1346 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->ah_txTrigLevel);
1348 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
1349 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
1351 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1353 if (AR_SREV_9285(ah)) {
1354 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1355 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
1357 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1358 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1362 static void ath9k_hw_set_operating_mode(struct ath_hal *ah, int opmode)
1366 val = REG_READ(ah, AR_STA_ID1);
1367 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
1369 case ATH9K_M_HOSTAP:
1370 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
1371 | AR_STA_ID1_KSRCH_MODE);
1372 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1375 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
1376 | AR_STA_ID1_KSRCH_MODE);
1377 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1380 case ATH9K_M_MONITOR:
1381 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
1386 static inline void ath9k_hw_get_delta_slope_vals(struct ath_hal *ah,
1391 u32 coef_exp, coef_man;
1393 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1394 if ((coef_scaled >> coef_exp) & 0x1)
1397 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1399 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1401 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1402 *coef_exponent = coef_exp - 16;
1405 static void ath9k_hw_set_delta_slope(struct ath_hal *ah,
1406 struct ath9k_channel *chan)
1408 u32 coef_scaled, ds_coef_exp, ds_coef_man;
1409 u32 clockMhzScaled = 0x64000000;
1410 struct chan_centers centers;
1412 if (IS_CHAN_HALF_RATE(chan))
1413 clockMhzScaled = clockMhzScaled >> 1;
1414 else if (IS_CHAN_QUARTER_RATE(chan))
1415 clockMhzScaled = clockMhzScaled >> 2;
1417 ath9k_hw_get_channel_centers(ah, chan, ¢ers);
1418 coef_scaled = clockMhzScaled / centers.synth_center;
1420 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1423 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1424 AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
1425 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1426 AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
1428 coef_scaled = (9 * coef_scaled) / 10;
1430 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1433 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1434 AR_PHY_HALFGI_DSC_MAN, ds_coef_man);
1435 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1436 AR_PHY_HALFGI_DSC_EXP, ds_coef_exp);
1439 static bool ath9k_hw_set_reset(struct ath_hal *ah, int type)
1444 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1445 AR_RTC_FORCE_WAKE_ON_INT);
1447 if (AR_SREV_9100(ah)) {
1448 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1449 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1451 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1453 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1454 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
1455 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
1456 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1458 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1461 rst_flags = AR_RTC_RC_MAC_WARM;
1462 if (type == ATH9K_RESET_COLD)
1463 rst_flags |= AR_RTC_RC_MAC_COLD;
1466 REG_WRITE(ah, (u16) (AR_RTC_RC), rst_flags);
1469 REG_WRITE(ah, (u16) (AR_RTC_RC), 0);
1470 if (!ath9k_hw_wait(ah, (u16) (AR_RTC_RC), AR_RTC_RC_M, 0)) {
1471 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
1472 "%s: RTC stuck in MAC reset\n",
1477 if (!AR_SREV_9100(ah))
1478 REG_WRITE(ah, AR_RC, 0);
1480 ath9k_hw_init_pll(ah, NULL);
1482 if (AR_SREV_9100(ah))
1488 static bool ath9k_hw_set_reset_power_on(struct ath_hal *ah)
1490 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1491 AR_RTC_FORCE_WAKE_ON_INT);
1493 REG_WRITE(ah, (u16) (AR_RTC_RESET), 0);
1494 REG_WRITE(ah, (u16) (AR_RTC_RESET), 1);
1496 if (!ath9k_hw_wait(ah,
1499 AR_RTC_STATUS_ON)) {
1500 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "%s: RTC not waking up\n",
1505 ath9k_hw_read_revisions(ah);
1507 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1510 static bool ath9k_hw_set_reset_reg(struct ath_hal *ah, u32 type)
1512 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1513 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1516 case ATH9K_RESET_POWER_ON:
1517 return ath9k_hw_set_reset_power_on(ah);
1519 case ATH9K_RESET_WARM:
1520 case ATH9K_RESET_COLD:
1521 return ath9k_hw_set_reset(ah, type);
1528 static void ath9k_hw_set_regs(struct ath_hal *ah, struct ath9k_channel *chan,
1529 enum ath9k_ht_macmode macmode)
1532 struct ath_hal_5416 *ahp = AH5416(ah);
1534 phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
1535 | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH;
1537 if (IS_CHAN_HT40(chan)) {
1538 phymode |= AR_PHY_FC_DYN2040_EN;
1540 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
1541 (chan->chanmode == CHANNEL_G_HT40PLUS))
1542 phymode |= AR_PHY_FC_DYN2040_PRI_CH;
1544 if (ahp->ah_extprotspacing == ATH9K_HT_EXTPROTSPACING_25)
1545 phymode |= AR_PHY_FC_DYN2040_EXT_CH;
1547 REG_WRITE(ah, AR_PHY_TURBO, phymode);
1549 ath9k_hw_set11nmac2040(ah, macmode);
1551 REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
1552 REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
1555 static bool ath9k_hw_chip_reset(struct ath_hal *ah,
1556 struct ath9k_channel *chan)
1558 struct ath_hal_5416 *ahp = AH5416(ah);
1560 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
1563 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
1566 ahp->ah_chipFullSleep = false;
1568 ath9k_hw_init_pll(ah, chan);
1570 ath9k_hw_set_rfmode(ah, chan);
1575 static struct ath9k_channel *ath9k_hw_check_chan(struct ath_hal *ah,
1576 struct ath9k_channel *chan)
1578 if (!(IS_CHAN_2GHZ(chan) ^ IS_CHAN_5GHZ(chan))) {
1579 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
1580 "%s: invalid channel %u/0x%x; not marked as "
1581 "2GHz or 5GHz\n", __func__, chan->channel,
1582 chan->channelFlags);
1586 if (!IS_CHAN_OFDM(chan) &&
1587 !IS_CHAN_CCK(chan) &&
1588 !IS_CHAN_HT20(chan) &&
1589 !IS_CHAN_HT40(chan)) {
1590 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
1591 "%s: invalid channel %u/0x%x; not marked as "
1592 "OFDM or CCK or HT20 or HT40PLUS or HT40MINUS\n",
1593 __func__, chan->channel, chan->channelFlags);
1597 return ath9k_regd_check_channel(ah, chan);
1600 static bool ath9k_hw_channel_change(struct ath_hal *ah,
1601 struct ath9k_channel *chan,
1602 enum ath9k_ht_macmode macmode)
1604 u32 synthDelay, qnum;
1606 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1607 if (ath9k_hw_numtxpending(ah, qnum)) {
1608 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
1609 "%s: Transmit frames pending on queue %d\n",
1615 REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
1616 if (!ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
1617 AR_PHY_RFBUS_GRANT_EN)) {
1618 DPRINTF(ah->ah_sc, ATH_DBG_PHY_IO,
1619 "%s: Could not kill baseband RX\n", __func__);
1623 ath9k_hw_set_regs(ah, chan, macmode);
1625 if (AR_SREV_9280_10_OR_LATER(ah)) {
1626 if (!(ath9k_hw_ar9280_set_channel(ah, chan))) {
1627 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
1628 "%s: failed to set channel\n", __func__);
1632 if (!(ath9k_hw_set_channel(ah, chan))) {
1633 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
1634 "%s: failed to set channel\n", __func__);
1639 if (ath9k_hw_set_txpower(ah, chan,
1640 ath9k_regd_get_ctl(ah, chan),
1641 ath9k_regd_get_antenna_allowed(ah, chan),
1642 chan->maxRegTxPower * 2,
1643 min((u32) MAX_RATE_POWER,
1644 (u32) ah->ah_powerLimit)) != 0) {
1645 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
1646 "%s: error init'ing transmit power\n", __func__);
1650 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
1651 if (IS_CHAN_CCK(chan))
1652 synthDelay = (4 * synthDelay) / 22;
1656 udelay(synthDelay + BASE_ACTIVATE_DELAY);
1658 REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
1660 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1661 ath9k_hw_set_delta_slope(ah, chan);
1663 if (AR_SREV_9280_10_OR_LATER(ah))
1664 ath9k_hw_9280_spur_mitigate(ah, chan);
1666 ath9k_hw_spur_mitigate(ah, chan);
1668 if (!chan->oneTimeCalsDone)
1669 chan->oneTimeCalsDone = true;
1674 static void ath9k_hw_9280_spur_mitigate(struct ath_hal *ah, struct ath9k_channel *chan)
1676 int bb_spur = AR_NO_SPUR;
1679 int bb_spur_off, spur_subchannel_sd;
1681 int spur_delta_phase;
1683 int upper, lower, cur_vit_mask;
1686 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
1687 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
1689 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
1690 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
1692 int inc[4] = { 0, 100, 0, 0 };
1693 struct chan_centers centers;
1700 bool is2GHz = IS_CHAN_2GHZ(chan);
1702 memset(&mask_m, 0, sizeof(int8_t) * 123);
1703 memset(&mask_p, 0, sizeof(int8_t) * 123);
1705 ath9k_hw_get_channel_centers(ah, chan, ¢ers);
1706 freq = centers.synth_center;
1708 ah->ah_config.spurmode = SPUR_ENABLE_EEPROM;
1709 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
1710 cur_bb_spur = ath9k_hw_eeprom_get_spur_chan(ah, i, is2GHz);
1713 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_2GHZ;
1715 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_5GHZ;
1717 if (AR_NO_SPUR == cur_bb_spur)
1719 cur_bb_spur = cur_bb_spur - freq;
1721 if (IS_CHAN_HT40(chan)) {
1722 if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT40) &&
1723 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT40)) {
1724 bb_spur = cur_bb_spur;
1727 } else if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT20) &&
1728 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT20)) {
1729 bb_spur = cur_bb_spur;
1734 if (AR_NO_SPUR == bb_spur) {
1735 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1736 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1739 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1740 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1743 bin = bb_spur * 320;
1745 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
1747 newVal = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
1748 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
1749 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
1750 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
1751 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), newVal);
1753 newVal = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
1754 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
1755 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
1756 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
1757 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
1758 REG_WRITE(ah, AR_PHY_SPUR_REG, newVal);
1760 if (IS_CHAN_HT40(chan)) {
1762 spur_subchannel_sd = 1;
1763 bb_spur_off = bb_spur + 10;
1765 spur_subchannel_sd = 0;
1766 bb_spur_off = bb_spur - 10;
1769 spur_subchannel_sd = 0;
1770 bb_spur_off = bb_spur;
1773 if (IS_CHAN_HT40(chan))
1775 ((bb_spur * 262144) /
1776 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
1779 ((bb_spur * 524288) /
1780 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
1782 denominator = IS_CHAN_2GHZ(chan) ? 44 : 40;
1783 spur_freq_sd = ((bb_spur_off * 2048) / denominator) & 0x3ff;
1785 newVal = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
1786 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
1787 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
1788 REG_WRITE(ah, AR_PHY_TIMING11, newVal);
1790 newVal = spur_subchannel_sd << AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S;
1791 REG_WRITE(ah, AR_PHY_SFCORR_EXT, newVal);
1797 for (i = 0; i < 4; i++) {
1801 for (bp = 0; bp < 30; bp++) {
1802 if ((cur_bin > lower) && (cur_bin < upper)) {
1803 pilot_mask = pilot_mask | 0x1 << bp;
1804 chan_mask = chan_mask | 0x1 << bp;
1809 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
1810 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
1813 cur_vit_mask = 6100;
1817 for (i = 0; i < 123; i++) {
1818 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
1820 /* workaround for gcc bug #37014 */
1821 volatile int tmp = abs(cur_vit_mask - bin);
1827 if (cur_vit_mask < 0)
1828 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
1830 mask_p[cur_vit_mask / 100] = mask_amt;
1832 cur_vit_mask -= 100;
1835 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
1836 | (mask_m[48] << 26) | (mask_m[49] << 24)
1837 | (mask_m[50] << 22) | (mask_m[51] << 20)
1838 | (mask_m[52] << 18) | (mask_m[53] << 16)
1839 | (mask_m[54] << 14) | (mask_m[55] << 12)
1840 | (mask_m[56] << 10) | (mask_m[57] << 8)
1841 | (mask_m[58] << 6) | (mask_m[59] << 4)
1842 | (mask_m[60] << 2) | (mask_m[61] << 0);
1843 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
1844 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
1846 tmp_mask = (mask_m[31] << 28)
1847 | (mask_m[32] << 26) | (mask_m[33] << 24)
1848 | (mask_m[34] << 22) | (mask_m[35] << 20)
1849 | (mask_m[36] << 18) | (mask_m[37] << 16)
1850 | (mask_m[48] << 14) | (mask_m[39] << 12)
1851 | (mask_m[40] << 10) | (mask_m[41] << 8)
1852 | (mask_m[42] << 6) | (mask_m[43] << 4)
1853 | (mask_m[44] << 2) | (mask_m[45] << 0);
1854 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
1855 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
1857 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
1858 | (mask_m[18] << 26) | (mask_m[18] << 24)
1859 | (mask_m[20] << 22) | (mask_m[20] << 20)
1860 | (mask_m[22] << 18) | (mask_m[22] << 16)
1861 | (mask_m[24] << 14) | (mask_m[24] << 12)
1862 | (mask_m[25] << 10) | (mask_m[26] << 8)
1863 | (mask_m[27] << 6) | (mask_m[28] << 4)
1864 | (mask_m[29] << 2) | (mask_m[30] << 0);
1865 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
1866 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
1868 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
1869 | (mask_m[2] << 26) | (mask_m[3] << 24)
1870 | (mask_m[4] << 22) | (mask_m[5] << 20)
1871 | (mask_m[6] << 18) | (mask_m[7] << 16)
1872 | (mask_m[8] << 14) | (mask_m[9] << 12)
1873 | (mask_m[10] << 10) | (mask_m[11] << 8)
1874 | (mask_m[12] << 6) | (mask_m[13] << 4)
1875 | (mask_m[14] << 2) | (mask_m[15] << 0);
1876 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
1877 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
1879 tmp_mask = (mask_p[15] << 28)
1880 | (mask_p[14] << 26) | (mask_p[13] << 24)
1881 | (mask_p[12] << 22) | (mask_p[11] << 20)
1882 | (mask_p[10] << 18) | (mask_p[9] << 16)
1883 | (mask_p[8] << 14) | (mask_p[7] << 12)
1884 | (mask_p[6] << 10) | (mask_p[5] << 8)
1885 | (mask_p[4] << 6) | (mask_p[3] << 4)
1886 | (mask_p[2] << 2) | (mask_p[1] << 0);
1887 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
1888 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
1890 tmp_mask = (mask_p[30] << 28)
1891 | (mask_p[29] << 26) | (mask_p[28] << 24)
1892 | (mask_p[27] << 22) | (mask_p[26] << 20)
1893 | (mask_p[25] << 18) | (mask_p[24] << 16)
1894 | (mask_p[23] << 14) | (mask_p[22] << 12)
1895 | (mask_p[21] << 10) | (mask_p[20] << 8)
1896 | (mask_p[19] << 6) | (mask_p[18] << 4)
1897 | (mask_p[17] << 2) | (mask_p[16] << 0);
1898 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
1899 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
1901 tmp_mask = (mask_p[45] << 28)
1902 | (mask_p[44] << 26) | (mask_p[43] << 24)
1903 | (mask_p[42] << 22) | (mask_p[41] << 20)
1904 | (mask_p[40] << 18) | (mask_p[39] << 16)
1905 | (mask_p[38] << 14) | (mask_p[37] << 12)
1906 | (mask_p[36] << 10) | (mask_p[35] << 8)
1907 | (mask_p[34] << 6) | (mask_p[33] << 4)
1908 | (mask_p[32] << 2) | (mask_p[31] << 0);
1909 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
1910 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
1912 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
1913 | (mask_p[59] << 26) | (mask_p[58] << 24)
1914 | (mask_p[57] << 22) | (mask_p[56] << 20)
1915 | (mask_p[55] << 18) | (mask_p[54] << 16)
1916 | (mask_p[53] << 14) | (mask_p[52] << 12)
1917 | (mask_p[51] << 10) | (mask_p[50] << 8)
1918 | (mask_p[49] << 6) | (mask_p[48] << 4)
1919 | (mask_p[47] << 2) | (mask_p[46] << 0);
1920 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
1921 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
1924 static void ath9k_hw_spur_mitigate(struct ath_hal *ah, struct ath9k_channel *chan)
1926 int bb_spur = AR_NO_SPUR;
1929 int spur_delta_phase;
1931 int upper, lower, cur_vit_mask;
1934 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
1935 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
1937 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
1938 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
1940 int inc[4] = { 0, 100, 0, 0 };
1947 bool is2GHz = IS_CHAN_2GHZ(chan);
1949 memset(&mask_m, 0, sizeof(int8_t) * 123);
1950 memset(&mask_p, 0, sizeof(int8_t) * 123);
1952 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
1953 cur_bb_spur = ath9k_hw_eeprom_get_spur_chan(ah, i, is2GHz);
1954 if (AR_NO_SPUR == cur_bb_spur)
1956 cur_bb_spur = cur_bb_spur - (chan->channel * 10);
1957 if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) {
1958 bb_spur = cur_bb_spur;
1963 if (AR_NO_SPUR == bb_spur)
1968 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
1969 new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
1970 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
1971 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
1972 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
1974 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new);
1976 new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
1977 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
1978 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
1979 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
1980 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
1981 REG_WRITE(ah, AR_PHY_SPUR_REG, new);
1983 spur_delta_phase = ((bb_spur * 524288) / 100) &
1984 AR_PHY_TIMING11_SPUR_DELTA_PHASE;
1986 denominator = IS_CHAN_2GHZ(chan) ? 440 : 400;
1987 spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff;
1989 new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
1990 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
1991 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
1992 REG_WRITE(ah, AR_PHY_TIMING11, new);
1998 for (i = 0; i < 4; i++) {
2002 for (bp = 0; bp < 30; bp++) {
2003 if ((cur_bin > lower) && (cur_bin < upper)) {
2004 pilot_mask = pilot_mask | 0x1 << bp;
2005 chan_mask = chan_mask | 0x1 << bp;
2010 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
2011 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
2014 cur_vit_mask = 6100;
2018 for (i = 0; i < 123; i++) {
2019 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
2021 /* workaround for gcc bug #37014 */
2022 volatile int tmp = abs(cur_vit_mask - bin);
2028 if (cur_vit_mask < 0)
2029 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
2031 mask_p[cur_vit_mask / 100] = mask_amt;
2033 cur_vit_mask -= 100;
2036 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
2037 | (mask_m[48] << 26) | (mask_m[49] << 24)
2038 | (mask_m[50] << 22) | (mask_m[51] << 20)
2039 | (mask_m[52] << 18) | (mask_m[53] << 16)
2040 | (mask_m[54] << 14) | (mask_m[55] << 12)
2041 | (mask_m[56] << 10) | (mask_m[57] << 8)
2042 | (mask_m[58] << 6) | (mask_m[59] << 4)
2043 | (mask_m[60] << 2) | (mask_m[61] << 0);
2044 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
2045 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
2047 tmp_mask = (mask_m[31] << 28)
2048 | (mask_m[32] << 26) | (mask_m[33] << 24)
2049 | (mask_m[34] << 22) | (mask_m[35] << 20)
2050 | (mask_m[36] << 18) | (mask_m[37] << 16)
2051 | (mask_m[48] << 14) | (mask_m[39] << 12)
2052 | (mask_m[40] << 10) | (mask_m[41] << 8)
2053 | (mask_m[42] << 6) | (mask_m[43] << 4)
2054 | (mask_m[44] << 2) | (mask_m[45] << 0);
2055 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
2056 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
2058 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
2059 | (mask_m[18] << 26) | (mask_m[18] << 24)
2060 | (mask_m[20] << 22) | (mask_m[20] << 20)
2061 | (mask_m[22] << 18) | (mask_m[22] << 16)
2062 | (mask_m[24] << 14) | (mask_m[24] << 12)
2063 | (mask_m[25] << 10) | (mask_m[26] << 8)
2064 | (mask_m[27] << 6) | (mask_m[28] << 4)
2065 | (mask_m[29] << 2) | (mask_m[30] << 0);
2066 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
2067 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
2069 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
2070 | (mask_m[2] << 26) | (mask_m[3] << 24)
2071 | (mask_m[4] << 22) | (mask_m[5] << 20)
2072 | (mask_m[6] << 18) | (mask_m[7] << 16)
2073 | (mask_m[8] << 14) | (mask_m[9] << 12)
2074 | (mask_m[10] << 10) | (mask_m[11] << 8)
2075 | (mask_m[12] << 6) | (mask_m[13] << 4)
2076 | (mask_m[14] << 2) | (mask_m[15] << 0);
2077 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
2078 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
2080 tmp_mask = (mask_p[15] << 28)
2081 | (mask_p[14] << 26) | (mask_p[13] << 24)
2082 | (mask_p[12] << 22) | (mask_p[11] << 20)
2083 | (mask_p[10] << 18) | (mask_p[9] << 16)
2084 | (mask_p[8] << 14) | (mask_p[7] << 12)
2085 | (mask_p[6] << 10) | (mask_p[5] << 8)
2086 | (mask_p[4] << 6) | (mask_p[3] << 4)
2087 | (mask_p[2] << 2) | (mask_p[1] << 0);
2088 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
2089 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
2091 tmp_mask = (mask_p[30] << 28)
2092 | (mask_p[29] << 26) | (mask_p[28] << 24)
2093 | (mask_p[27] << 22) | (mask_p[26] << 20)
2094 | (mask_p[25] << 18) | (mask_p[24] << 16)
2095 | (mask_p[23] << 14) | (mask_p[22] << 12)
2096 | (mask_p[21] << 10) | (mask_p[20] << 8)
2097 | (mask_p[19] << 6) | (mask_p[18] << 4)
2098 | (mask_p[17] << 2) | (mask_p[16] << 0);
2099 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
2100 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
2102 tmp_mask = (mask_p[45] << 28)
2103 | (mask_p[44] << 26) | (mask_p[43] << 24)
2104 | (mask_p[42] << 22) | (mask_p[41] << 20)
2105 | (mask_p[40] << 18) | (mask_p[39] << 16)
2106 | (mask_p[38] << 14) | (mask_p[37] << 12)
2107 | (mask_p[36] << 10) | (mask_p[35] << 8)
2108 | (mask_p[34] << 6) | (mask_p[33] << 4)
2109 | (mask_p[32] << 2) | (mask_p[31] << 0);
2110 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
2111 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
2113 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
2114 | (mask_p[59] << 26) | (mask_p[58] << 24)
2115 | (mask_p[57] << 22) | (mask_p[56] << 20)
2116 | (mask_p[55] << 18) | (mask_p[54] << 16)
2117 | (mask_p[53] << 14) | (mask_p[52] << 12)
2118 | (mask_p[51] << 10) | (mask_p[50] << 8)
2119 | (mask_p[49] << 6) | (mask_p[48] << 4)
2120 | (mask_p[47] << 2) | (mask_p[46] << 0);
2121 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
2122 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
2125 bool ath9k_hw_reset(struct ath_hal *ah, struct ath9k_channel *chan,
2126 enum ath9k_ht_macmode macmode,
2127 u8 txchainmask, u8 rxchainmask,
2128 enum ath9k_ht_extprotspacing extprotspacing,
2129 bool bChannelChange, int *status)
2132 struct ath_hal_5416 *ahp = AH5416(ah);
2133 struct ath9k_channel *curchan = ah->ah_curchan;
2137 int i, rx_chainmask;
2139 ahp->ah_extprotspacing = extprotspacing;
2140 ahp->ah_txchainmask = txchainmask;
2141 ahp->ah_rxchainmask = rxchainmask;
2143 if (AR_SREV_9280(ah)) {
2144 ahp->ah_txchainmask &= 0x3;
2145 ahp->ah_rxchainmask &= 0x3;
2148 if (ath9k_hw_check_chan(ah, chan) == NULL) {
2149 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
2150 "%s: invalid channel %u/0x%x; no mapping\n",
2151 __func__, chan->channel, chan->channelFlags);
2156 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
2162 ath9k_hw_getnf(ah, curchan);
2164 if (bChannelChange &&
2165 (ahp->ah_chipFullSleep != true) &&
2166 (ah->ah_curchan != NULL) &&
2167 (chan->channel != ah->ah_curchan->channel) &&
2168 ((chan->channelFlags & CHANNEL_ALL) ==
2169 (ah->ah_curchan->channelFlags & CHANNEL_ALL)) &&
2170 (!AR_SREV_9280(ah) || (!IS_CHAN_A_5MHZ_SPACED(chan) &&
2171 !IS_CHAN_A_5MHZ_SPACED(ah->
2174 if (ath9k_hw_channel_change(ah, chan, macmode)) {
2175 ath9k_hw_loadnf(ah, ah->ah_curchan);
2176 ath9k_hw_start_nfcal(ah);
2181 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
2182 if (saveDefAntenna == 0)
2185 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
2187 saveLedState = REG_READ(ah, AR_CFG_LED) &
2188 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
2189 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
2191 ath9k_hw_mark_phy_inactive(ah);
2193 if (!ath9k_hw_chip_reset(ah, chan)) {
2194 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "%s: chip reset failed\n",
2200 if (AR_SREV_9280(ah)) {
2201 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
2202 AR_GPIO_JTAG_DISABLE);
2204 if (test_bit(ATH9K_MODE_11A, ah->ah_caps.wireless_modes)) {
2205 if (IS_CHAN_5GHZ(chan))
2206 ath9k_hw_set_gpio(ah, 9, 0);
2208 ath9k_hw_set_gpio(ah, 9, 1);
2210 ath9k_hw_cfg_output(ah, 9, AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
2213 ecode = ath9k_hw_process_ini(ah, chan, macmode);
2219 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
2220 ath9k_hw_set_delta_slope(ah, chan);
2222 if (AR_SREV_9280_10_OR_LATER(ah))
2223 ath9k_hw_9280_spur_mitigate(ah, chan);
2225 ath9k_hw_spur_mitigate(ah, chan);
2227 if (!ath9k_hw_eeprom_set_board_values(ah, chan)) {
2228 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
2229 "%s: error setting board options\n", __func__);
2234 ath9k_hw_decrease_chain_power(ah, chan);
2236 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(ahp->ah_macaddr));
2237 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(ahp->ah_macaddr + 4)
2239 | AR_STA_ID1_RTS_USE_DEF
2241 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
2242 | ahp->ah_staId1Defaults);
2243 ath9k_hw_set_operating_mode(ah, ah->ah_opmode);
2245 REG_WRITE(ah, AR_BSSMSKL, get_unaligned_le32(ahp->ah_bssidmask));
2246 REG_WRITE(ah, AR_BSSMSKU, get_unaligned_le16(ahp->ah_bssidmask + 4));
2248 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
2250 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(ahp->ah_bssid));
2251 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(ahp->ah_bssid + 4) |
2252 ((ahp->ah_assocId & 0x3fff) << AR_BSS_ID1_AID_S));
2254 REG_WRITE(ah, AR_ISR, ~0);
2256 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
2258 if (AR_SREV_9280_10_OR_LATER(ah)) {
2259 if (!(ath9k_hw_ar9280_set_channel(ah, chan))) {
2264 if (!(ath9k_hw_set_channel(ah, chan))) {
2270 for (i = 0; i < AR_NUM_DCU; i++)
2271 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
2273 ahp->ah_intrTxqs = 0;
2274 for (i = 0; i < ah->ah_caps.total_queues; i++)
2275 ath9k_hw_resettxqueue(ah, i);
2277 ath9k_hw_init_interrupt_masks(ah, ah->ah_opmode);
2278 ath9k_hw_init_qos(ah);
2280 #ifdef CONFIG_RFKILL
2281 if (ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
2282 ath9k_enable_rfkill(ah);
2284 ath9k_hw_init_user_settings(ah);
2286 REG_WRITE(ah, AR_STA_ID1,
2287 REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
2289 ath9k_hw_set_dma(ah);
2291 REG_WRITE(ah, AR_OBS, 8);
2293 if (ahp->ah_intrMitigation) {
2295 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
2296 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
2299 ath9k_hw_init_bb(ah, chan);
2301 if (!ath9k_hw_init_cal(ah, chan)){
2306 rx_chainmask = ahp->ah_rxchainmask;
2307 if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) {
2308 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
2309 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
2312 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
2314 if (AR_SREV_9100(ah)) {
2316 mask = REG_READ(ah, AR_CFG);
2317 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
2318 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
2319 "%s CFG Byte Swap Set 0x%x\n", __func__,
2323 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
2324 REG_WRITE(ah, AR_CFG, mask);
2325 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
2326 "%s Setting CFG 0x%x\n", __func__,
2327 REG_READ(ah, AR_CFG));
2331 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
2342 /************************/
2343 /* Key Cache Management */
2344 /************************/
2346 bool ath9k_hw_keyreset(struct ath_hal *ah, u16 entry)
2350 if (entry >= ah->ah_caps.keycache_size) {
2351 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
2352 "%s: entry %u out of range\n", __func__, entry);
2356 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
2358 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
2359 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
2360 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
2361 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
2362 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
2363 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
2364 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
2365 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
2367 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2368 u16 micentry = entry + 64;
2370 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
2371 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
2372 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
2373 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
2377 if (ah->ah_curchan == NULL)
2383 bool ath9k_hw_keysetmac(struct ath_hal *ah, u16 entry, const u8 *mac)
2387 if (entry >= ah->ah_caps.keycache_size) {
2388 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
2389 "%s: entry %u out of range\n", __func__, entry);
2394 macHi = (mac[5] << 8) | mac[4];
2395 macLo = (mac[3] << 24) |
2400 macLo |= (macHi & 1) << 31;
2405 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
2406 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
2411 bool ath9k_hw_set_keycache_entry(struct ath_hal *ah, u16 entry,
2412 const struct ath9k_keyval *k,
2413 const u8 *mac, int xorKey)
2415 const struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
2416 u32 key0, key1, key2, key3, key4;
2418 u32 xorMask = xorKey ?
2419 (ATH9K_KEY_XOR << 24 | ATH9K_KEY_XOR << 16 | ATH9K_KEY_XOR << 8
2420 | ATH9K_KEY_XOR) : 0;
2421 struct ath_hal_5416 *ahp = AH5416(ah);
2423 if (entry >= pCap->keycache_size) {
2424 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
2425 "%s: entry %u out of range\n", __func__, entry);
2429 switch (k->kv_type) {
2430 case ATH9K_CIPHER_AES_OCB:
2431 keyType = AR_KEYTABLE_TYPE_AES;
2433 case ATH9K_CIPHER_AES_CCM:
2434 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
2435 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
2436 "%s: AES-CCM not supported by "
2437 "mac rev 0x%x\n", __func__,
2441 keyType = AR_KEYTABLE_TYPE_CCM;
2443 case ATH9K_CIPHER_TKIP:
2444 keyType = AR_KEYTABLE_TYPE_TKIP;
2445 if (ATH9K_IS_MIC_ENABLED(ah)
2446 && entry + 64 >= pCap->keycache_size) {
2447 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
2448 "%s: entry %u inappropriate for TKIP\n",
2453 case ATH9K_CIPHER_WEP:
2454 if (k->kv_len < LEN_WEP40) {
2455 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
2456 "%s: WEP key length %u too small\n",
2457 __func__, k->kv_len);
2460 if (k->kv_len <= LEN_WEP40)
2461 keyType = AR_KEYTABLE_TYPE_40;
2462 else if (k->kv_len <= LEN_WEP104)
2463 keyType = AR_KEYTABLE_TYPE_104;
2465 keyType = AR_KEYTABLE_TYPE_128;
2467 case ATH9K_CIPHER_CLR:
2468 keyType = AR_KEYTABLE_TYPE_CLR;
2471 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
2472 "%s: cipher %u not supported\n", __func__,
2477 key0 = get_unaligned_le32(k->kv_val + 0) ^ xorMask;
2478 key1 = (get_unaligned_le16(k->kv_val + 4) ^ xorMask) & 0xffff;
2479 key2 = get_unaligned_le32(k->kv_val + 6) ^ xorMask;
2480 key3 = (get_unaligned_le16(k->kv_val + 10) ^ xorMask) & 0xffff;
2481 key4 = get_unaligned_le32(k->kv_val + 12) ^ xorMask;
2482 if (k->kv_len <= LEN_WEP104)
2485 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2486 u16 micentry = entry + 64;
2488 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
2489 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
2490 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2491 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
2492 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2493 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
2494 (void) ath9k_hw_keysetmac(ah, entry, mac);
2496 if (ahp->ah_miscMode & AR_PCU_MIC_NEW_LOC_ENA) {
2497 u32 mic0, mic1, mic2, mic3, mic4;
2499 mic0 = get_unaligned_le32(k->kv_mic + 0);
2500 mic2 = get_unaligned_le32(k->kv_mic + 4);
2501 mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
2502 mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
2503 mic4 = get_unaligned_le32(k->kv_txmic + 4);
2504 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2505 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
2506 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2507 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
2508 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
2509 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2510 AR_KEYTABLE_TYPE_CLR);
2515 mic0 = get_unaligned_le32(k->kv_mic + 0);
2516 mic2 = get_unaligned_le32(k->kv_mic + 4);
2517 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2518 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
2519 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2520 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
2521 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
2522 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2523 AR_KEYTABLE_TYPE_CLR);
2525 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
2526 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
2527 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2528 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
2530 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2531 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
2532 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2533 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
2534 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2535 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
2537 (void) ath9k_hw_keysetmac(ah, entry, mac);
2540 if (ah->ah_curchan == NULL)
2546 bool ath9k_hw_keyisvalid(struct ath_hal *ah, u16 entry)
2548 if (entry < ah->ah_caps.keycache_size) {
2549 u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
2550 if (val & AR_KEYTABLE_VALID)
2556 /******************************/
2557 /* Power Management (Chipset) */
2558 /******************************/
2560 static void ath9k_set_power_sleep(struct ath_hal *ah, int setChip)
2562 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2564 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2565 AR_RTC_FORCE_WAKE_EN);
2566 if (!AR_SREV_9100(ah))
2567 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
2569 REG_CLR_BIT(ah, (u16) (AR_RTC_RESET),
2574 static void ath9k_set_power_network_sleep(struct ath_hal *ah, int setChip)
2576 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2578 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
2580 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
2581 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2582 AR_RTC_FORCE_WAKE_ON_INT);
2584 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2585 AR_RTC_FORCE_WAKE_EN);
2590 static bool ath9k_hw_set_power_awake(struct ath_hal *ah,
2597 if ((REG_READ(ah, AR_RTC_STATUS) &
2598 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2599 if (ath9k_hw_set_reset_reg(ah,
2600 ATH9K_RESET_POWER_ON) != true) {
2604 if (AR_SREV_9100(ah))
2605 REG_SET_BIT(ah, AR_RTC_RESET,
2608 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2609 AR_RTC_FORCE_WAKE_EN);
2612 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2613 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2614 if (val == AR_RTC_STATUS_ON)
2617 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2618 AR_RTC_FORCE_WAKE_EN);
2621 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
2622 "%s: Failed to wakeup in %uus\n",
2623 __func__, POWER_UP_TIME / 20);
2628 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2633 bool ath9k_hw_setpower(struct ath_hal *ah,
2634 enum ath9k_power_mode mode)
2636 struct ath_hal_5416 *ahp = AH5416(ah);
2637 static const char *modes[] = {
2643 int status = true, setChip = true;
2645 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT, "%s: %s -> %s (%s)\n", __func__,
2646 modes[ahp->ah_powerMode], modes[mode],
2647 setChip ? "set chip " : "");
2650 case ATH9K_PM_AWAKE:
2651 status = ath9k_hw_set_power_awake(ah, setChip);
2653 case ATH9K_PM_FULL_SLEEP:
2654 ath9k_set_power_sleep(ah, setChip);
2655 ahp->ah_chipFullSleep = true;
2657 case ATH9K_PM_NETWORK_SLEEP:
2658 ath9k_set_power_network_sleep(ah, setChip);
2661 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
2662 "%s: unknown power mode %u\n", __func__, mode);
2665 ahp->ah_powerMode = mode;
2670 void ath9k_hw_configpcipowersave(struct ath_hal *ah, int restore)
2672 struct ath_hal_5416 *ahp = AH5416(ah);
2675 if (ah->ah_isPciExpress != true)
2678 if (ah->ah_config.pcie_powersave_enable == 2)
2684 if (AR_SREV_9280_20_OR_LATER(ah)) {
2685 for (i = 0; i < ahp->ah_iniPcieSerdes.ia_rows; i++) {
2686 REG_WRITE(ah, INI_RA(&ahp->ah_iniPcieSerdes, i, 0),
2687 INI_RA(&ahp->ah_iniPcieSerdes, i, 1));
2690 } else if (AR_SREV_9280(ah) &&
2691 (ah->ah_macRev == AR_SREV_REVISION_9280_10)) {
2692 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
2693 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
2695 REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
2696 REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
2697 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
2699 if (ah->ah_config.pcie_clock_req)
2700 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
2702 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
2704 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2705 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2706 REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
2708 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
2712 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
2713 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
2714 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
2715 REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
2716 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
2717 REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
2718 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2719 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2720 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
2721 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
2724 REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
2726 if (ah->ah_config.pcie_waen) {
2727 REG_WRITE(ah, AR_WA, ah->ah_config.pcie_waen);
2729 if (AR_SREV_9280(ah))
2730 REG_WRITE(ah, AR_WA, 0x0040073f);
2732 REG_WRITE(ah, AR_WA, 0x0000073f);
2736 /**********************/
2737 /* Interrupt Handling */
2738 /**********************/
2740 bool ath9k_hw_intrpend(struct ath_hal *ah)
2744 if (AR_SREV_9100(ah))
2747 host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
2748 if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
2751 host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
2752 if ((host_isr & AR_INTR_SYNC_DEFAULT)
2753 && (host_isr != AR_INTR_SPURIOUS))
2759 bool ath9k_hw_getisr(struct ath_hal *ah, enum ath9k_int *masked)
2763 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
2765 bool fatal_int = false;
2766 struct ath_hal_5416 *ahp = AH5416(ah);
2768 if (!AR_SREV_9100(ah)) {
2769 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
2770 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
2771 == AR_RTC_STATUS_ON) {
2772 isr = REG_READ(ah, AR_ISR);
2776 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
2777 AR_INTR_SYNC_DEFAULT;
2781 if (!isr && !sync_cause)
2785 isr = REG_READ(ah, AR_ISR);
2789 if (isr & AR_ISR_BCNMISC) {
2791 isr2 = REG_READ(ah, AR_ISR_S2);
2792 if (isr2 & AR_ISR_S2_TIM)
2793 mask2 |= ATH9K_INT_TIM;
2794 if (isr2 & AR_ISR_S2_DTIM)
2795 mask2 |= ATH9K_INT_DTIM;
2796 if (isr2 & AR_ISR_S2_DTIMSYNC)
2797 mask2 |= ATH9K_INT_DTIMSYNC;
2798 if (isr2 & (AR_ISR_S2_CABEND))
2799 mask2 |= ATH9K_INT_CABEND;
2800 if (isr2 & AR_ISR_S2_GTT)
2801 mask2 |= ATH9K_INT_GTT;
2802 if (isr2 & AR_ISR_S2_CST)
2803 mask2 |= ATH9K_INT_CST;
2806 isr = REG_READ(ah, AR_ISR_RAC);
2807 if (isr == 0xffffffff) {
2812 *masked = isr & ATH9K_INT_COMMON;
2814 if (ahp->ah_intrMitigation) {
2815 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
2816 *masked |= ATH9K_INT_RX;
2819 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
2820 *masked |= ATH9K_INT_RX;
2822 (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
2826 *masked |= ATH9K_INT_TX;
2828 s0_s = REG_READ(ah, AR_ISR_S0_S);
2829 ahp->ah_intrTxqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
2830 ahp->ah_intrTxqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
2832 s1_s = REG_READ(ah, AR_ISR_S1_S);
2833 ahp->ah_intrTxqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
2834 ahp->ah_intrTxqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
2837 if (isr & AR_ISR_RXORN) {
2838 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
2839 "%s: receive FIFO overrun interrupt\n",
2843 if (!AR_SREV_9100(ah)) {
2844 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
2845 u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
2846 if (isr5 & AR_ISR_S5_TIM_TIMER)
2847 *masked |= ATH9K_INT_TIM_TIMER;
2854 if (AR_SREV_9100(ah))
2860 (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
2864 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
2865 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
2866 "%s: received PCI FATAL interrupt\n",
2869 if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
2870 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
2871 "%s: received PCI PERR interrupt\n",
2875 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
2876 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
2877 "%s: AR_INTR_SYNC_RADM_CPL_TIMEOUT\n",
2879 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
2880 REG_WRITE(ah, AR_RC, 0);
2881 *masked |= ATH9K_INT_FATAL;
2883 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
2884 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
2885 "%s: 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, "%s: 0x%x => 0x%x\n", __func__,
2911 if (omask & ATH9K_INT_GLOBAL) {
2912 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "%s: disable IER\n",
2914 REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
2915 (void) REG_READ(ah, AR_IER);
2916 if (!AR_SREV_9100(ah)) {
2917 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
2918 (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
2920 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
2921 (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
2925 mask = ints & ATH9K_INT_COMMON;
2928 if (ints & ATH9K_INT_TX) {
2929 if (ahp->ah_txOkInterruptMask)
2930 mask |= AR_IMR_TXOK;
2931 if (ahp->ah_txDescInterruptMask)
2932 mask |= AR_IMR_TXDESC;
2933 if (ahp->ah_txErrInterruptMask)
2934 mask |= AR_IMR_TXERR;
2935 if (ahp->ah_txEolInterruptMask)
2936 mask |= AR_IMR_TXEOL;
2938 if (ints & ATH9K_INT_RX) {
2939 mask |= AR_IMR_RXERR;
2940 if (ahp->ah_intrMitigation)
2941 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
2943 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
2944 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
2945 mask |= AR_IMR_GENTMR;
2948 if (ints & (ATH9K_INT_BMISC)) {
2949 mask |= AR_IMR_BCNMISC;
2950 if (ints & ATH9K_INT_TIM)
2951 mask2 |= AR_IMR_S2_TIM;
2952 if (ints & ATH9K_INT_DTIM)
2953 mask2 |= AR_IMR_S2_DTIM;
2954 if (ints & ATH9K_INT_DTIMSYNC)
2955 mask2 |= AR_IMR_S2_DTIMSYNC;
2956 if (ints & ATH9K_INT_CABEND)
2957 mask2 |= (AR_IMR_S2_CABEND);
2960 if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
2961 mask |= AR_IMR_BCNMISC;
2962 if (ints & ATH9K_INT_GTT)
2963 mask2 |= AR_IMR_S2_GTT;
2964 if (ints & ATH9K_INT_CST)
2965 mask2 |= AR_IMR_S2_CST;
2968 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "%s: new IMR 0x%x\n", __func__,
2970 REG_WRITE(ah, AR_IMR, mask);
2971 mask = REG_READ(ah, AR_IMR_S2) & ~(AR_IMR_S2_TIM |
2973 AR_IMR_S2_DTIMSYNC |
2977 AR_IMR_S2_GTT | AR_IMR_S2_CST);
2978 REG_WRITE(ah, AR_IMR_S2, mask | mask2);
2979 ahp->ah_maskReg = ints;
2981 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
2982 if (ints & ATH9K_INT_TIM_TIMER)
2983 REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
2985 REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
2988 if (ints & ATH9K_INT_GLOBAL) {
2989 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "%s: enable IER\n",
2991 REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
2992 if (!AR_SREV_9100(ah)) {
2993 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
2995 REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
2998 REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
2999 AR_INTR_SYNC_DEFAULT);
3000 REG_WRITE(ah, AR_INTR_SYNC_MASK,
3001 AR_INTR_SYNC_DEFAULT);
3003 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
3004 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
3010 /*******************/
3011 /* Beacon Handling */
3012 /*******************/
3014 void ath9k_hw_beaconinit(struct ath_hal *ah, u32 next_beacon, u32 beacon_period)
3016 struct ath_hal_5416 *ahp = AH5416(ah);
3019 ahp->ah_beaconInterval = beacon_period;
3021 switch (ah->ah_opmode) {
3023 case ATH9K_M_MONITOR:
3024 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3025 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
3026 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
3027 flags |= AR_TBTT_TIMER_EN;
3030 REG_SET_BIT(ah, AR_TXCFG,
3031 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
3032 REG_WRITE(ah, AR_NEXT_NDP_TIMER,
3033 TU_TO_USEC(next_beacon +
3034 (ahp->ah_atimWindow ? ahp->
3035 ah_atimWindow : 1)));
3036 flags |= AR_NDP_TIMER_EN;
3037 case ATH9K_M_HOSTAP:
3038 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3039 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
3040 TU_TO_USEC(next_beacon -
3042 dma_beacon_response_time));
3043 REG_WRITE(ah, AR_NEXT_SWBA,
3044 TU_TO_USEC(next_beacon -
3046 sw_beacon_response_time));
3048 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
3052 REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3053 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3054 REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
3055 REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
3057 beacon_period &= ~ATH9K_BEACON_ENA;
3058 if (beacon_period & ATH9K_BEACON_RESET_TSF) {
3059 beacon_period &= ~ATH9K_BEACON_RESET_TSF;
3060 ath9k_hw_reset_tsf(ah);
3063 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
3066 void ath9k_hw_set_sta_beacon_timers(struct ath_hal *ah,
3067 const struct ath9k_beacon_state *bs)
3069 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
3070 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
3072 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
3074 REG_WRITE(ah, AR_BEACON_PERIOD,
3075 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3076 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
3077 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3079 REG_RMW_FIELD(ah, AR_RSSI_THR,
3080 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
3082 beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
3084 if (bs->bs_sleepduration > beaconintval)
3085 beaconintval = bs->bs_sleepduration;
3087 dtimperiod = bs->bs_dtimperiod;
3088 if (bs->bs_sleepduration > dtimperiod)
3089 dtimperiod = bs->bs_sleepduration;
3091 if (beaconintval == dtimperiod)
3092 nextTbtt = bs->bs_nextdtim;
3094 nextTbtt = bs->bs_nexttbtt;
3096 DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "%s: next DTIM %d\n", __func__,
3098 DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "%s: next beacon %d\n", __func__,
3100 DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "%s: beacon period %d\n", __func__,
3102 DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "%s: DTIM period %d\n", __func__,
3105 REG_WRITE(ah, AR_NEXT_DTIM,
3106 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
3107 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
3109 REG_WRITE(ah, AR_SLEEP1,
3110 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
3111 | AR_SLEEP1_ASSUME_DTIM);
3113 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
3114 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
3116 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
3118 REG_WRITE(ah, AR_SLEEP2,
3119 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
3121 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
3122 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
3124 REG_SET_BIT(ah, AR_TIMER_MODE,
3125 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
3134 static struct ath9k_rate_table ar5416_11a_table = {
3138 {true, PHY_OFDM, 6000, 0x0b, 0x00, (0x80 | 12), 0},
3139 {true, PHY_OFDM, 9000, 0x0f, 0x00, 18, 0},
3140 {true, PHY_OFDM, 12000, 0x0a, 0x00, (0x80 | 24), 2},
3141 {true, PHY_OFDM, 18000, 0x0e, 0x00, 36, 2},
3142 {true, PHY_OFDM, 24000, 0x09, 0x00, (0x80 | 48), 4},
3143 {true, PHY_OFDM, 36000, 0x0d, 0x00, 72, 4},
3144 {true, PHY_OFDM, 48000, 0x08, 0x00, 96, 4},
3145 {true, PHY_OFDM, 54000, 0x0c, 0x00, 108, 4}
3149 static struct ath9k_rate_table ar5416_11b_table = {
3153 {true, PHY_CCK, 1000, 0x1b, 0x00, (0x80 | 2), 0},
3154 {true, PHY_CCK, 2000, 0x1a, 0x04, (0x80 | 4), 1},
3155 {true, PHY_CCK, 5500, 0x19, 0x04, (0x80 | 11), 1},
3156 {true, PHY_CCK, 11000, 0x18, 0x04, (0x80 | 22), 1}
3160 static struct ath9k_rate_table ar5416_11g_table = {
3164 {true, PHY_CCK, 1000, 0x1b, 0x00, (0x80 | 2), 0},
3165 {true, PHY_CCK, 2000, 0x1a, 0x04, (0x80 | 4), 1},
3166 {true, PHY_CCK, 5500, 0x19, 0x04, (0x80 | 11), 2},
3167 {true, PHY_CCK, 11000, 0x18, 0x04, (0x80 | 22), 3},
3169 {false, PHY_OFDM, 6000, 0x0b, 0x00, 12, 4},
3170 {false, PHY_OFDM, 9000, 0x0f, 0x00, 18, 4},
3171 {true, PHY_OFDM, 12000, 0x0a, 0x00, 24, 6},
3172 {true, PHY_OFDM, 18000, 0x0e, 0x00, 36, 6},
3173 {true, PHY_OFDM, 24000, 0x09, 0x00, 48, 8},
3174 {true, PHY_OFDM, 36000, 0x0d, 0x00, 72, 8},
3175 {true, PHY_OFDM, 48000, 0x08, 0x00, 96, 8},
3176 {true, PHY_OFDM, 54000, 0x0c, 0x00, 108, 8}
3180 static struct ath9k_rate_table ar5416_11ng_table = {
3184 {true, PHY_CCK, 1000, 0x1b, 0x00, (0x80 | 2), 0},
3185 {true, PHY_CCK, 2000, 0x1a, 0x04, (0x80 | 4), 1},
3186 {true, PHY_CCK, 5500, 0x19, 0x04, (0x80 | 11), 2},
3187 {true, PHY_CCK, 11000, 0x18, 0x04, (0x80 | 22), 3},
3189 {false, PHY_OFDM, 6000, 0x0b, 0x00, 12, 4},
3190 {false, PHY_OFDM, 9000, 0x0f, 0x00, 18, 4},
3191 {true, PHY_OFDM, 12000, 0x0a, 0x00, 24, 6},
3192 {true, PHY_OFDM, 18000, 0x0e, 0x00, 36, 6},
3193 {true, PHY_OFDM, 24000, 0x09, 0x00, 48, 8},
3194 {true, PHY_OFDM, 36000, 0x0d, 0x00, 72, 8},
3195 {true, PHY_OFDM, 48000, 0x08, 0x00, 96, 8},
3196 {true, PHY_OFDM, 54000, 0x0c, 0x00, 108, 8},
3197 {true, PHY_HT, 6500, 0x80, 0x00, 0, 4},
3198 {true, PHY_HT, 13000, 0x81, 0x00, 1, 6},
3199 {true, PHY_HT, 19500, 0x82, 0x00, 2, 6},
3200 {true, PHY_HT, 26000, 0x83, 0x00, 3, 8},
3201 {true, PHY_HT, 39000, 0x84, 0x00, 4, 8},
3202 {true, PHY_HT, 52000, 0x85, 0x00, 5, 8},
3203 {true, PHY_HT, 58500, 0x86, 0x00, 6, 8},
3204 {true, PHY_HT, 65000, 0x87, 0x00, 7, 8},
3205 {true, PHY_HT, 13000, 0x88, 0x00, 8, 4},
3206 {true, PHY_HT, 26000, 0x89, 0x00, 9, 6},
3207 {true, PHY_HT, 39000, 0x8a, 0x00, 10, 6},
3208 {true, PHY_HT, 52000, 0x8b, 0x00, 11, 8},
3209 {true, PHY_HT, 78000, 0x8c, 0x00, 12, 8},
3210 {true, PHY_HT, 104000, 0x8d, 0x00, 13, 8},
3211 {true, PHY_HT, 117000, 0x8e, 0x00, 14, 8},
3212 {true, PHY_HT, 130000, 0x8f, 0x00, 15, 8},
3216 static struct ath9k_rate_table ar5416_11na_table = {
3220 {true, PHY_OFDM, 6000, 0x0b, 0x00, (0x80 | 12), 0},
3221 {true, PHY_OFDM, 9000, 0x0f, 0x00, 18, 0},
3222 {true, PHY_OFDM, 12000, 0x0a, 0x00, (0x80 | 24), 2},
3223 {true, PHY_OFDM, 18000, 0x0e, 0x00, 36, 2},
3224 {true, PHY_OFDM, 24000, 0x09, 0x00, (0x80 | 48), 4},
3225 {true, PHY_OFDM, 36000, 0x0d, 0x00, 72, 4},
3226 {true, PHY_OFDM, 48000, 0x08, 0x00, 96, 4},
3227 {true, PHY_OFDM, 54000, 0x0c, 0x00, 108, 4},
3228 {true, PHY_HT, 6500, 0x80, 0x00, 0, 0},
3229 {true, PHY_HT, 13000, 0x81, 0x00, 1, 2},
3230 {true, PHY_HT, 19500, 0x82, 0x00, 2, 2},
3231 {true, PHY_HT, 26000, 0x83, 0x00, 3, 4},
3232 {true, PHY_HT, 39000, 0x84, 0x00, 4, 4},
3233 {true, PHY_HT, 52000, 0x85, 0x00, 5, 4},
3234 {true, PHY_HT, 58500, 0x86, 0x00, 6, 4},
3235 {true, PHY_HT, 65000, 0x87, 0x00, 7, 4},
3236 {true, PHY_HT, 13000, 0x88, 0x00, 8, 0},
3237 {true, PHY_HT, 26000, 0x89, 0x00, 9, 2},
3238 {true, PHY_HT, 39000, 0x8a, 0x00, 10, 2},
3239 {true, PHY_HT, 52000, 0x8b, 0x00, 11, 4},
3240 {true, PHY_HT, 78000, 0x8c, 0x00, 12, 4},
3241 {true, PHY_HT, 104000, 0x8d, 0x00, 13, 4},
3242 {true, PHY_HT, 117000, 0x8e, 0x00, 14, 4},
3243 {true, PHY_HT, 130000, 0x8f, 0x00, 15, 4},
3247 static void ath9k_hw_setup_rate_table(struct ath_hal *ah,
3248 struct ath9k_rate_table *rt)
3252 if (rt->rateCodeToIndex[0] != 0)
3255 for (i = 0; i < 256; i++)
3256 rt->rateCodeToIndex[i] = (u8) -1;
3258 for (i = 0; i < rt->rateCount; i++) {
3259 u8 code = rt->info[i].rateCode;
3260 u8 cix = rt->info[i].controlRate;
3262 rt->rateCodeToIndex[code] = i;
3263 rt->rateCodeToIndex[code | rt->info[i].shortPreamble] = i;
3265 rt->info[i].lpAckDuration =
3266 ath9k_hw_computetxtime(ah, rt,
3267 WLAN_CTRL_FRAME_SIZE,
3270 rt->info[i].spAckDuration =
3271 ath9k_hw_computetxtime(ah, rt,
3272 WLAN_CTRL_FRAME_SIZE,
3278 const struct ath9k_rate_table *ath9k_hw_getratetable(struct ath_hal *ah,
3281 struct ath9k_rate_table *rt;
3284 case ATH9K_MODE_11A:
3285 rt = &ar5416_11a_table;
3287 case ATH9K_MODE_11B:
3288 rt = &ar5416_11b_table;
3290 case ATH9K_MODE_11G:
3291 rt = &ar5416_11g_table;
3293 case ATH9K_MODE_11NG_HT20:
3294 case ATH9K_MODE_11NG_HT40PLUS:
3295 case ATH9K_MODE_11NG_HT40MINUS:
3296 rt = &ar5416_11ng_table;
3298 case ATH9K_MODE_11NA_HT20:
3299 case ATH9K_MODE_11NA_HT40PLUS:
3300 case ATH9K_MODE_11NA_HT40MINUS:
3301 rt = &ar5416_11na_table;
3304 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL, "%s: invalid mode 0x%x\n",
3309 ath9k_hw_setup_rate_table(ah, rt);
3314 /*******************/
3315 /* HW Capabilities */
3316 /*******************/
3318 bool ath9k_hw_fill_cap_info(struct ath_hal *ah)
3320 struct ath_hal_5416 *ahp = AH5416(ah);
3321 struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
3322 u16 capField = 0, eeval;
3324 eeval = ath9k_hw_get_eeprom(ah, EEP_REG_0);
3326 ah->ah_currentRD = eeval;
3328 eeval = ath9k_hw_get_eeprom(ah, EEP_REG_1);
3329 ah->ah_currentRDExt = eeval;
3331 capField = ath9k_hw_get_eeprom(ah, EEP_OP_CAP);
3333 if (ah->ah_opmode != ATH9K_M_HOSTAP &&
3334 ah->ah_subvendorid == AR_SUBVENDOR_ID_NEW_A) {
3335 if (ah->ah_currentRD == 0x64 || ah->ah_currentRD == 0x65)
3336 ah->ah_currentRD += 5;
3337 else if (ah->ah_currentRD == 0x41)
3338 ah->ah_currentRD = 0x43;
3339 DPRINTF(ah->ah_sc, ATH_DBG_REGULATORY,
3340 "%s: regdomain mapped to 0x%x\n", __func__,
3344 eeval = ath9k_hw_get_eeprom(ah, EEP_OP_MODE);
3345 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
3347 if (eeval & AR5416_OPFLAGS_11A) {
3348 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
3349 if (ah->ah_config.ht_enable) {
3350 if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
3351 set_bit(ATH9K_MODE_11NA_HT20,
3352 pCap->wireless_modes);
3353 if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
3354 set_bit(ATH9K_MODE_11NA_HT40PLUS,
3355 pCap->wireless_modes);
3356 set_bit(ATH9K_MODE_11NA_HT40MINUS,
3357 pCap->wireless_modes);
3362 if (eeval & AR5416_OPFLAGS_11G) {
3363 set_bit(ATH9K_MODE_11B, pCap->wireless_modes);
3364 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
3365 if (ah->ah_config.ht_enable) {
3366 if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
3367 set_bit(ATH9K_MODE_11NG_HT20,
3368 pCap->wireless_modes);
3369 if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
3370 set_bit(ATH9K_MODE_11NG_HT40PLUS,
3371 pCap->wireless_modes);
3372 set_bit(ATH9K_MODE_11NG_HT40MINUS,
3373 pCap->wireless_modes);
3378 pCap->tx_chainmask = ath9k_hw_get_eeprom(ah, EEP_TX_MASK);
3379 if ((ah->ah_isPciExpress)